Expr *new_expr_alignof_type(SrcPos pos, Typespec *type) { Expr *e = new_expr(EXPR_ALIGNOF_TYPE, pos); e->alignof_type = type; return(e); }
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_expr(SrcPos pos, Expr *expr) { Expr *e = new_expr(EXPR_ALIGNOF_EXPR, pos); e->alignof_expr = expr; return(e); }
Expr *new_expr_sizeof_type(SrcPos pos, Typespec *type) { var e = new_expr(EXPR_SIZEOF_TYPE, pos); e->sizeof_type = type; return(e); }
Expr *new_expr_typeof_expr(SrcPos pos, Expr *expr) { Expr *e = new_expr(EXPR_TYPEOF_EXPR, pos); e->typeof_expr = expr; return(e); }
Expr *new_expr_sizeof_expr(SrcPos pos, Expr *expr) { var e = new_expr(EXPR_SIZEOF_EXPR, pos); e->sizeof_expr = expr; return(e); }
Expr *new_expr_paren(SrcPos pos, Expr *expr) { Expr *e = new_expr(EXPR_PAREN, pos); e->paren.expr = expr; return(e); }
Decl *new_decl_note(SrcPos pos, Note note) { Decl *d = new_decl(DECL_NOTE, pos, null); d->note = note; return(d); }
Expr *new_expr_name(SrcPos pos, char *name) { var e = new_expr(EXPR_NAME, pos); e->name = name; return(e); }
Stmt *new_stmt_note(SrcPos pos, Note note) { Stmt *s = new_stmt(STMT_NOTE, pos); s->note = note; return(s); }
Decl *parse_decl_enum(SrcPos pos) { char *name = null; if (is_token(TOKEN_NAME)) { name = parse_name(); } Typespec *type = null; if (match_token(TOKEN_ASSIGN)) { type = parse_type(); } expect_token(TOKEN_LBRACE); EnumItem *items = null; var buf = Buffer <EnumItem> .Create(16); while (!is_token(TOKEN_RBRACE)) { buf.Add(parse_decl_enum_item()); if (!match_token(TOKEN_COMMA)) { break; } } expect_token(TOKEN_RBRACE); return(new_decl_enum(pos, name, type, buf._begin, buf.count)); }
Stmt *new_stmt_return(SrcPos pos, Expr *expr) { var s = new_stmt(STMT_RETURN, pos); s->expr = expr; return(s); }
Typespec *new_typespec_const(SrcPos pos, Typespec * @base) { Typespec *t = new_typespec(TYPESPEC_CONST, pos); t->@base = @base; return(t); }
StmtList stmt_list(SrcPos pos, Stmt **stmts, int num_stmts) { return(new StmtList { pos = pos, stmts = stmts, num_stmts = num_stmts }); }
Decl *parse_decl_var(SrcPos pos) { var name = parse_name(); if (match_token(TOKEN_ASSIGN)) { Expr *expr = parse_expr(); expect_token(TOKEN_SEMICOLON); return(new_decl_var(pos, name, null, expr)); } else if (match_token(TOKEN_COLON)) { Typespec *type = parse_type(); Expr * expr = null; if (match_token(TOKEN_ASSIGN)) { expr = parse_expr(); } expect_token(TOKEN_SEMICOLON); return(new_decl_var(pos, name, type, expr)); } else { fatal_error_here("Expected : or = after var, got {0}", token_info()); return(null); } }
Stmt *new_stmt_goto(SrcPos pos, char *label) { Stmt *s = new_stmt(STMT_GOTO, pos); s->label = label; return(s); }
Stmt *new_stmt_expr(SrcPos pos, Expr *expr) { var s = new_stmt(STMT_EXPR, pos); s->expr = expr; return(s); }
Stmt *new_stmt_decl(SrcPos pos, Decl *decl) { var s = new_stmt(STMT_DECL, pos); s->decl = decl; return(s); }
Stmt *new_stmt_label(SrcPos pos, char *label) { Stmt *s = new_stmt(STMT_LABEL, pos); s->label = label; return(s); }
Decl *new_decl_typedef(SrcPos pos, char *name, Typespec *type) { var d = new_decl(DECL_TYPEDEF, pos, name); d->typedef_decl.type = type; return(d); }
Stmt *parse_stmt_for(SrcPos pos) { Stmt *init = null; Expr *cond = null; Stmt *next = null; if (!is_token(TOKEN_LBRACE)) { expect_token(TOKEN_LPAREN); if (!is_token(TOKEN_SEMICOLON)) { init = parse_simple_stmt(); } if (match_token(TOKEN_SEMICOLON)) { if (!is_token(TOKEN_SEMICOLON)) { cond = parse_expr(); } if (match_token(TOKEN_SEMICOLON)) { if (!is_token(TOKEN_RPAREN)) { next = parse_simple_stmt(); if (next->kind == STMT_INIT) { error_here("Init statements not allowed in for-statement's next clause"); } } } } } expect_token(TOKEN_RPAREN); return(new_stmt_for(pos, init, cond, next, parse_stmt_block())); }
Stmt *new_stmt_block(SrcPos pos, StmtList block) { var s = new_stmt(STMT_BLOCK, pos); s->block = block; return(s); }
Typespec *new_typespec_name(SrcPos pos, char **names, int num_names) { var t = new_typespec(TYPESPEC_NAME, pos); t->names = (char **)ast_dup(names, num_names * sizeof(char **)); t->num_names = num_names; return(t); }
Typespec *new_typespec(TypespecKind kind, SrcPos pos) { var t = (Typespec *)ast_alloc(sizeof(Typespec)); t->pos = pos; t->kind = kind; return(t); }
Stmt *new_stmt_do_while(SrcPos pos, Expr *cond, StmtList block) { var s = new_stmt(STMT_DO_WHILE, pos); s->while_stmt.cond = cond; s->while_stmt.block = block; return(s); }
Expr *new_expr_unary(SrcPos pos, TokenKind op, Expr *expr) { var e = new_expr(EXPR_UNARY, pos); e->unary.op = op; e->unary.expr = expr; return(e); }
Expr *new_expr_index(SrcPos pos, Expr *expr, Expr *index) { var e = new_expr(EXPR_INDEX, pos); e->index.expr = expr; e->index.index = index; return(e); }
Stmt *new_stmt(StmtKind kind, SrcPos pos) { var s = (Stmt *)ast_alloc(sizeof(Stmt)); s->pos = pos; s->kind = kind; return(s); }
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_field(SrcPos pos, Expr *expr, char *name) { var e = new_expr(EXPR_FIELD, pos); e->field.expr = expr; e->field.name = name; return(e); }