Esempio n. 1
0
        Expr *new_expr_alignof_type(SrcPos pos, Typespec *type)
        {
            Expr *e = new_expr(EXPR_ALIGNOF_TYPE, pos);

            e->alignof_type = type;
            return(e);
        }
Esempio n. 2
0
        Expr *new_expr_typeof_type(SrcPos pos, Typespec *type)
        {
            Expr *e = new_expr(EXPR_TYPEOF_TYPE, pos);

            e->typeof_type = type;
            return(e);
        }
Esempio n. 3
0
        Expr *new_expr_alignof_expr(SrcPos pos, Expr *expr)
        {
            Expr *e = new_expr(EXPR_ALIGNOF_EXPR, pos);

            e->alignof_expr = expr;
            return(e);
        }
Esempio n. 4
0
        Expr *new_expr_sizeof_type(SrcPos pos, Typespec *type)
        {
            var e = new_expr(EXPR_SIZEOF_TYPE, pos);

            e->sizeof_type = type;
            return(e);
        }
Esempio n. 5
0
        Expr *new_expr_typeof_expr(SrcPos pos, Expr *expr)
        {
            Expr *e = new_expr(EXPR_TYPEOF_EXPR, pos);

            e->typeof_expr = expr;
            return(e);
        }
Esempio n. 6
0
        Expr *new_expr_sizeof_expr(SrcPos pos, Expr *expr)
        {
            var e = new_expr(EXPR_SIZEOF_EXPR, pos);

            e->sizeof_expr = expr;
            return(e);
        }
Esempio n. 7
0
        Expr *new_expr_paren(SrcPos pos, Expr *expr)
        {
            Expr *e = new_expr(EXPR_PAREN, pos);

            e->paren.expr = expr;
            return(e);
        }
Esempio n. 8
0
        Decl *new_decl_note(SrcPos pos, Note note)
        {
            Decl *d = new_decl(DECL_NOTE, pos, null);

            d->note = note;
            return(d);
        }
Esempio n. 9
0
        Expr *new_expr_name(SrcPos pos, char *name)
        {
            var e = new_expr(EXPR_NAME, pos);

            e->name = name;
            return(e);
        }
Esempio n. 10
0
        Stmt *new_stmt_note(SrcPos pos, Note note)
        {
            Stmt *s = new_stmt(STMT_NOTE, pos);

            s->note = note;
            return(s);
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
0
        Stmt *new_stmt_return(SrcPos pos, Expr *expr)
        {
            var s = new_stmt(STMT_RETURN, pos);

            s->expr = expr;
            return(s);
        }
Esempio n. 13
0
        Typespec *new_typespec_const(SrcPos pos, Typespec * @base)
        {
            Typespec *t = new_typespec(TYPESPEC_CONST, pos);

            t->@base = @base;
            return(t);
        }
Esempio n. 14
0
 StmtList stmt_list(SrcPos pos, Stmt **stmts, int num_stmts)
 {
     return(new StmtList
     {
         pos = pos, stmts = stmts, num_stmts = num_stmts
     });
 }
Esempio n. 15
0
        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);
            }
        }
Esempio n. 16
0
        Stmt *new_stmt_goto(SrcPos pos, char *label)
        {
            Stmt *s = new_stmt(STMT_GOTO, pos);

            s->label = label;
            return(s);
        }
Esempio n. 17
0
        Stmt *new_stmt_expr(SrcPos pos, Expr *expr)
        {
            var s = new_stmt(STMT_EXPR, pos);

            s->expr = expr;
            return(s);
        }
Esempio n. 18
0
        Stmt *new_stmt_decl(SrcPos pos, Decl *decl)
        {
            var s = new_stmt(STMT_DECL, pos);

            s->decl = decl;
            return(s);
        }
Esempio n. 19
0
        Stmt *new_stmt_label(SrcPos pos, char *label)
        {
            Stmt *s = new_stmt(STMT_LABEL, pos);

            s->label = label;
            return(s);
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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()));
        }
Esempio n. 22
0
        Stmt *new_stmt_block(SrcPos pos, StmtList block)
        {
            var s = new_stmt(STMT_BLOCK, pos);

            s->block = block;
            return(s);
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
        Typespec *new_typespec(TypespecKind kind, SrcPos pos)
        {
            var t = (Typespec *)ast_alloc(sizeof(Typespec));

            t->pos  = pos;
            t->kind = kind;
            return(t);
        }
Esempio n. 25
0
        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);
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        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);
        }
Esempio n. 28
0
        Stmt *new_stmt(StmtKind kind, SrcPos pos)
        {
            var s = (Stmt *)ast_alloc(sizeof(Stmt));

            s->pos  = pos;
            s->kind = kind;
            return(s);
        }
Esempio n. 29
0
        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);
        }
Esempio n. 30
0
        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);
        }