<commit_before>#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

#include "../util/where.h"
#include "../util/util.h"
#include "../util/platform.h"

#include "expr.h"
#include "sue.h"
#include "type.h"
#include "type_nav.h"
#include "decl.h"
#include "const.h"
#include "funcargs.h"

#include "type_is.h"

static type *type_next_1(type *r)
{
	if(r->type == type_tdef){
		/* typedef - jump to its typeof */
		struct type_tdef *tdef = &r->bits.tdef;
		decl *preferred = tdef->decl;

		r = preferred ? preferred->ref : tdef->type_of->tree_type;

		UCC_ASSERT(r, "unfolded typeof()");

		return r;
	}

	return r->ref;
}

enum type_skippage
{
	STOP_AT_TDEF = 1 << 0,
	STOP_AT_CAST = 1 << 1,
	STOP_AT_ATTR = 1 << 2,
	STOP_AT_WHERE = 1 << 3,
};
static type *type_skip(type *t, enum type_skippage skippage)
{
	while(t){
		switch(t->type){
			case type_tdef:
				if(skippage & STOP_AT_TDEF)
					goto fin;
				break;
			case type_cast:
				if(skippage & STOP_AT_CAST)
					goto fin;
				break;
			case type_attr:
				if(skippage & STOP_AT_ATTR)
					goto fin;
				break;
			case type_where:
				if(skippage & STOP_AT_WHERE)
					goto fin;
				break;
			default:
				goto fin;
		}
		t = type_next_1(t);
	}

fin:
	return t;
}

type *type_skip_all(type *t)
{
	return type_skip(t, 0);
}

type *type_skip_non_tdefs(type *t)
{
	return type_skip(t, STOP_AT_TDEF);
}

type *type_skip_non_casts(type *t)
{
	return type_skip(t, STOP_AT_CAST);
}

type *type_skip_wheres(type *t)
{
	return type_skip(t, ~0 & ~STOP_AT_WHERE);
}

type *type_skip_non_wheres(type *t)
{
	return type_skip(t, STOP_AT_WHERE);
}

decl *type_is_tdef(type *r)
{
	if(r && r->type == type_tdef)
		return r->bits.tdef.decl;

	return NULL;
}
<commit_msg>Fixed type_is_tdef()<commit_after>#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

#include "../util/where.h"
#include "../util/util.h"
#include "../util/platform.h"

#include "expr.h"
#include "sue.h"
#include "type.h"
#include "type_nav.h"
#include "decl.h"
#include "const.h"
#include "funcargs.h"

#include "type_is.h"

static type *type_next_1(type *r)
{
	if(r->type == type_tdef){
		/* typedef - jump to its typeof */
		struct type_tdef *tdef = &r->bits.tdef;
		decl *preferred = tdef->decl;

		r = preferred ? preferred->ref : tdef->type_of->tree_type;

		UCC_ASSERT(r, "unfolded typeof()");

		return r;
	}

	return r->ref;
}

enum type_skippage
{
	STOP_AT_TDEF = 1 << 0,
	STOP_AT_CAST = 1 << 1,
	STOP_AT_ATTR = 1 << 2,
	STOP_AT_WHERE = 1 << 3,
};
static type *type_skip(type *t, enum type_skippage skippage)
{
	while(t){
		switch(t->type){
			case type_tdef:
				if(skippage & STOP_AT_TDEF)
					goto fin;
				break;
			case type_cast:
				if(skippage & STOP_AT_CAST)
					goto fin;
				break;
			case type_attr:
				if(skippage & STOP_AT_ATTR)
					goto fin;
				break;
			case type_where:
				if(skippage & STOP_AT_WHERE)
					goto fin;
				break;
			default:
				goto fin;
		}
		t = type_next_1(t);
	}

fin:
	return t;
}

type *type_skip_all(type *t)
{
	return type_skip(t, 0);
}

type *type_skip_non_tdefs(type *t)
{
	return type_skip(t, STOP_AT_TDEF);
}

type *type_skip_non_casts(type *t)
{
	return type_skip(t, STOP_AT_CAST);
}

type *type_skip_wheres(type *t)
{
	return type_skip(t, ~0 & ~STOP_AT_WHERE);
}

type *type_skip_non_wheres(type *t)
{
	return type_skip(t, STOP_AT_WHERE);
}

decl *type_is_tdef(type *t)
{
	t = type_skip_non_tdefs(t);

	if(t && t->type == type_tdef)
		return t->bits.tdef.decl;

	return NULL;
}

{'fraction_non_alphanumeric': 0.1547790932717297, 'fraction_numerical': 0.006930407161420733, 'mean_word_length': 3.6372155287817938, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '185622', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1531, 'n_words': 317}