19 .visibility = eVisiblePrivate
41 self->attrib = &kDefaultAttrib;
44 self->eval_model = eEvalRuntime;
62 self->diagnostic = diagnostic;
70 va_start(args, message);
71 tree_t *
self = error_vformat(node, diagnostic, message, args);
79 va_start(args, message);
80 tree_t *
self = error_vformat(node, diagnostic, message, args);
95 return kind_has_tag(kind, eTagIsType) || (kind == eTreeError);
104 case eTreeTypePointer:
106 case eTreeTypeReference:
114 #define EXPECT_TYPE(TYPE) CTASSERTF(is_type(tree_get_kind(TYPE)), "expected type, found %s", tree_to_string(TYPE))
116 #define EXPECT_LOAD_TYPE(TYPE) CTASSERTF(is_load_type(tree_get_kind(TYPE)), "expected load type, found %s", tree_to_string(TYPE))
120 return tree_decl(eTreeTypeUnit, node, NULL, name, eQualNone);
125 return tree_decl(eTreeTypeUnit, node, NULL, name, eQualNone);
130 return tree_decl(eTreeTypeBool, node, NULL, name, eQualNone);
135 return tree_decl(eTreeTypeOpaque, node, NULL, name, eQualNone);
152 for (
size_t i = 0; i < len; i++)
158 tree_t *
self =
tree_decl(eTreeTypeClosure, node, NULL, name, eQualNone);
159 self->return_type = result;
169 tree_t *
self =
tree_decl(eTreeTypePointer, node, NULL, name, eQualNone);
189 tree_t *
self =
tree_decl(eTreeTypeReference, node, NULL, name, eQualNone);
190 self->ptr = reference;
200 return tree_new(eTreeExprEmpty, node, type);
205 return tree_new(eTreeExprUnit, node, type);
213 self->bool_value = value;
222 mpz_init_set(self->digit_value, value);
229 mpz_init_set_si(val, value);
249 #define TREE_EXPECT_ADDRESS(TYPE) CTASSERTF(tree_is(TYPE, eTreeTypePointer) || tree_is(TYPE, eTreeTypeReference) || tree_is(TYPE, eTreeTypeOpaque) || tree_is(TYPE, eTreeError), "expected reference or pointer, found %s", tree_to_string(TYPE))
273 if (
tree_is(ty, eTreeTypeReference) ||
tree_is(ty, eTreeTypePointer))
294 self->operand = expr;
301 self->binary = binary;
313 self->compare = compare;
322 const tree_t *ty = get_ref_inner(outer);
328 self->object = object;
339 self->object = object;
350 self->callee = callee;
393 return stmt_assign_inner(node, dst, src,
false);
398 return stmt_assign_inner(node, dst, src,
true);
CT_PUREFN CT_TREE_API const node_t * tree_get_node(const tree_t *tree)
CT_PUREFN CT_TREE_API const char * tree_get_name(const tree_t *tree)
CT_PUREFN CT_TREE_API const tree_t * tree_get_type(const tree_t *tree)
CT_PUREFN CT_TREE_API bool tree_is(const tree_t *self, tree_kind_t kind)
CT_PUREFN CT_TREE_API bool tree_ty_is_address(const tree_t *type)
CT_TREE_API const char * tree_to_string(const tree_t *self)
CT_PUREFN CT_TREE_API const tree_t * tree_fn_get_return(const tree_t *self)
CT_BEGIN_API CT_TREE_API const char * tree_kind_to_string(tree_kind_t kind)
CT_PUREFN CT_TREE_API const tree_t * tree_ty_load_type(const tree_t *self)
get the type of a type after it has been loaded
CT_CONSTFN CT_LOCAL bool kind_has_tag(tree_kind_t kind, tree_tags_t tags)
#define TREE_EXPECT(SELF, KIND)
#define EXPECT_LOAD_TYPE(TYPE)
#define EXPECT_TYPE(TYPE)
#define TREE_EXPECT_ADDRESS(TYPE)
must be either storage or a pointer
tree_t * tree_decl(tree_kind_t kind, const node_t *node, const tree_t *type, const char *name, tree_quals_t quals)
tree_t * tree_new(tree_kind_t kind, const node_t *node, const tree_t *type)
#define CT_CONSTFN
mark a function as const, has no side effects and always returns the same value for the same argument...
CT_CONSTFN CT_BASE_API text_view_t text_view_make(STA_READS(length) const char *text, size_t length)
create a new non-owning text array text must be at least length bytes long
CT_MEMORY_API arena_t * get_global_arena(void)
get the global memory arena
#define ARENA_RENAME(arena, ptr, name)
rename a pointer in a custom allocator
#define ARENA_MALLOC(size, name, parent, arena)
allocate memory from a custom allocator
CT_NOTIFY_API event_builder_t msg_notify(INOUT_NOTNULL logger_t *logs, const diagnostic_t *diagnostic, const node_t *node, STA_FORMAT_STRING const char *fmt,...)
notify the logger of a new message
#define CTASSERT(expr)
assert a condition, prints the condition as a message
#define CTASSERTF(expr,...)
assert a condition with a message and optional format arguments
CT_NODISCARD STA_FORMAT_STRING const char CT_NODISCARD CT_STD_API char * str_vformat(arena_t *arena, const char *fmt, va_list args)
format a string
tree_jump_t
the type of jump
tree_t * tree_expr_unit(const node_t *node, const tree_t *type)
tree_t * tree_stmt_jump(const node_t *node, tree_t *label, tree_jump_t jump)
tree_t * tree_type_reference(const node_t *node, const char *name, const tree_t *reference)
create a reference type
void tree_report(logger_t *reports, const tree_t *error)
tree_t * tree_expr_field(const node_t *node, const tree_t *type, tree_t *object, tree_t *field)
tree_t * tree_stmt_loop(const node_t *node, tree_t *cond, tree_t *body, tree_t *other)
tree_t * tree_expr_offset(const node_t *node, const tree_t *type, tree_t *object, tree_t *offset)
tree_t * tree_type_closure(const node_t *node, const char *name, const tree_t *result, const vector_t *params, tree_arity_t arity)
create a function pointer type
tree_t * tree_type_empty(const node_t *node, const char *name)
create an empty type, this is a type that has no values and can never be created in a well defined pr...
tree_t * tree_expr_digit(const node_t *node, const tree_t *type, const mpz_t value)
tree_t * tree_expr_cast(const node_t *node, const tree_t *type, const tree_t *expr, tree_cast_t cast)
create a cast expression
tree_t * tree_type_bool(const node_t *node, const char *name)
create a bool type, this is a type that has only two values, true and false
tree_quals_t
all type qualifiers
tree_t * tree_expr_unary(const node_t *node, unary_t unary, tree_t *expr)
tree_t * tree_stmt_init(const node_t *node, tree_t *dst, tree_t *src)
tree_t * tree_stmt_return(const node_t *node, const tree_t *value)
create a return statement
tree_t * tree_error(const node_t *node, const diagnostic_t *diagnostic, const char *message,...)
tree_t * tree_expr_compare(const node_t *node, const tree_t *type, compare_t compare, const tree_t *lhs, const tree_t *rhs)
tree_t * tree_type_pointer(const node_t *node, const char *name, const tree_t *pointer, size_t length)
create a pointer type
tree_t * tree_type_opaque(const node_t *node, const char *name)
create an opaque pointer type
binary_t
all binary operators
tree_t * tree_raise(const node_t *node, logger_t *reports, const diagnostic_t *diagnostic, const char *message,...)
tree_t * tree_expr_call(const node_t *node, const tree_t *callee, const vector_t *args)
tree_t * tree_expr_string(const node_t *node, const tree_t *type, const char *value, size_t length)
create a string expression
tree_t * tree_expr_digit_int(const node_t *node, const tree_t *type, int value)
tree_t * tree_expr_bool(const node_t *node, const tree_t *type, bool value)
tree_t * tree_expr_binary(const node_t *node, const tree_t *type, binary_t binary, const tree_t *lhs, const tree_t *rhs)
tree_t * tree_expr_load(const node_t *node, tree_t *expr)
load a value from a pointer or storage
tree_kind_t
all tree node types
tree_t * tree_expr_address(const node_t *node, tree_t *expr)
create a reference to an object
tree_t * tree_type_digit(const node_t *node, const char *name, digit_t digit, sign_t sign)
create a digit type
unary_t
all unary operators
tree_t * tree_stmt_assign(const node_t *node, tree_t *dst, const tree_t *src)
tree_t * tree_stmt_block(const node_t *node, const vector_t *stmts)
create a block statement
tree_t * tree_type_unit(const node_t *node, const char *name)
create a unit type, this is a type that has only one value. equivilent to void
compare_t
all comparison operators
tree_t * tree_stmt_branch(const node_t *node, tree_t *cond, tree_t *then, tree_t *other)
tree_t * tree_type_array(const node_t *node, const char *name, const tree_t *array, size_t length)
create a new array type
tree_t * tree_expr_empty(const node_t *node, const tree_t *type)
CT_NODISCARD CT_PUREFN CT_STD_API void * vector_get(const vector_t *vector, size_t index)
get a value from a vector
CT_NODISCARD CT_PUREFN CT_STD_API size_t vector_len(const vector_t *vector)
get the length of a vector
a position in a source file
tree_linkage_t link
the link type of the declaration
const diagnostic_t * diagnostic
a generic vector of pointers