Expr new_expr_sizeof_type(SrcPos pos, Typespec type) { var e = new_expr(EXPR_SIZEOF_TYPE, pos); e.sizeof_type = type; return(e); }
Typespec new_typespec_const(SrcPos pos, Typespec @base) { Typespec t = new_typespec(TYPESPEC_CONST, pos); t.@base = @base; return(t); }
Expr new_expr_typeof_type(SrcPos pos, Typespec type) { Expr e = new_expr(EXPR_TYPEOF_TYPE, pos); e.typeof_type = type; return(e); }
Expr new_expr_alignof_type(SrcPos pos, Typespec type) { Expr e = new_expr(EXPR_ALIGNOF_TYPE, pos); e.alignof_type = type; return(e); }
Decl new_decl_typedef(SrcPos pos, string name, Typespec type) { var d = new_decl(DECL_TYPEDEF, pos, name); d.typedef_decl.type = type; return(d); }
Typespec new_typespec(TypespecKind kind, SrcPos pos) { var t = new Typespec(); t.pos = pos; t.kind = kind; return(t); }
Expr new_expr_cast(SrcPos pos, Typespec type, Expr expr) { var e = new_expr(EXPR_CAST, pos); e.cast.type = type; e.cast.expr = expr; return(e); }
Expr new_expr_offsetof(SrcPos pos, Typespec type, string name) { Expr e = new_expr(EXPR_OFFSETOF, pos); e.offsetof_field.type = type; e.offsetof_field.name = name; return(e); }
Typespec new_typespec_tuple(SrcPos pos, Typespec[] fields, int num_fields) { Typespec t = new_typespec(TYPESPEC_TUPLE, pos); t.tuple.fields = fields; t.tuple.num_fields = num_fields; return(t); }
Decl new_decl_const(SrcPos pos, string name, Typespec type, Expr expr) { var d = new_decl(DECL_CONST, pos, name); d.const_decl.type = type; d.const_decl.expr = expr; return(d); }
Typespec new_typespec_array(SrcPos pos, Typespec @base, Expr num_elems) { var t = new_typespec(TYPESPEC_ARRAY, pos); t.@base = @base; t.num_elems = num_elems; return(t); }
Decl new_decl_var(SrcPos pos, string name, Typespec type, Expr expr) { var d = new_decl(DECL_VAR, pos, name); d.var.type = type; d.var.expr = expr; return(d); }
Typespec new_typespec_ptr(SrcPos pos, Typespec @base) { var t = new_typespec(TYPESPEC_PTR, pos); t.@base = @base; t.@base = @base; return(t); }
Expr new_expr_compound(SrcPos pos, Typespec type, CompoundField[] fields, int num_fields) { var e = new_expr(EXPR_COMPOUND, pos); e.compound.type = type; e.compound.fields = fields; e.compound.num_fields = num_fields; return(e); }
Decl new_decl_enum(SrcPos pos, string name, Typespec type, EnumItem[] items, int num_items) { var d = new_decl(DECL_ENUM, pos, name); d.enum_decl.items = items; d.enum_decl.type = type; d.enum_decl.num_items = num_items; return(d); }
void print_typespec(Typespec type) { var t = type; switch (t.kind) { case TYPESPEC_NAME: printf("{0}", (t.names)); break; case TYPESPEC_FUNC: printf("(func ("); foreach (var it in t.func.args) { printf(" "); print_typespec(it); } printf(" ) "); if (t.func.ret != null) { print_typespec(t.func.ret); } else { printf("void"); } printf(")"); break; case TYPESPEC_ARRAY: printf("(array "); print_typespec(t.@base); printf(" "); if (t.num_elems != null) { print_expr(t.num_elems); } else { printf("nil"); } printf(")"); break; case TYPESPEC_PTR: printf("(ptr "); print_typespec(t.@base); printf(")"); break; default: assert(false); break; } }
Typespec new_typespec_func(SrcPos pos, Typespec[] args, int num_args, Typespec ret, bool has_varargs) { var t = new_typespec(TYPESPEC_FUNC, pos); t.func.args = args; t.func.num_args = num_args; t.func.ret = ret; t.func.has_varargs = has_varargs; return(t); }
Stmt new_stmt_init(SrcPos pos, string name, Typespec type, Expr expr, bool is_undef) { var s = new_stmt(STMT_INIT, pos); s.init.name = name; s.init.type = type; s.init.expr = expr; s.init.is_undef = is_undef; return(s); }
Decl new_decl_func(SrcPos pos, string name, FuncParam[] @params, int num_params, Typespec ret_type, bool has_varargs, Typespec varargs_type, StmtList block) { var d = new_decl(DECL_FUNC, pos, name); d.func.@params = @params; d.func.num_params = num_params; d.func.ret_type = ret_type; d.func.has_varargs = has_varargs; d.func.varargs_type = varargs_type; d.func.block = block; return(d); }