diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-06-12 11:48:12 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-06-12 11:48:12 +0100 |
| commit | 8fafdb185cefee691e1c2e1990abf8cd3c97ddf4 (patch) | |
| tree | 8422ecb57d2d4f830ca6b76f54f0ad1a2f19f2a7 /src | |
| parent | c2c935ba818167a7056da5ac61687ecd2d97cc59 (diff) | |
Remove := with var and :: with const
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_stmt.cpp | 2 | ||||
| -rw-r--r-- | src/checker.cpp | 2 | ||||
| -rw-r--r-- | src/ir.cpp | 2 | ||||
| -rw-r--r-- | src/parser.cpp | 67 | ||||
| -rw-r--r-- | src/ssa.cpp | 2 | ||||
| -rw-r--r-- | src/tokenizer.cpp | 3 |
6 files changed, 52 insertions, 26 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 80233a38f..9aa5fd211 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1538,7 +1538,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) { case_ast_node(vd, ValueDecl, node); GB_ASSERT(!c->context.scope->is_file); - if (!vd->is_var) { + if (vd->token.kind != Token_var) { // NOTE(bill): Handled elsewhere } else { Entity **entities = gb_alloc_array(c->allocator, Entity *, vd->names.count); diff --git a/src/checker.cpp b/src/checker.cpp index 05503c608..169f900dc 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1451,7 +1451,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco case_end; case_ast_node(vd, ValueDecl, decl); - if (vd->is_var) { + if (vd->token.kind == Token_var) { if (!c->context.scope->is_file) { // NOTE(bill): local scope -> handle later and in order break; diff --git a/src/ir.cpp b/src/ir.cpp index e48e1d0ca..1170c40b1 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -5813,7 +5813,7 @@ void ir_build_stmt_internal(irProcedure *proc, AstNode *node) { case_end; case_ast_node(vd, ValueDecl, node); - if (vd->is_var) { + if (vd->token.kind == Token_var) { irModule *m = proc->module; gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena); diff --git a/src/parser.cpp b/src/parser.cpp index 8971ca7ad..4eb3dfacc 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -298,11 +298,11 @@ AST_NODE_KIND(_StmtEnd, "", i32) \ AST_NODE_KIND(_DeclBegin, "", i32) \ AST_NODE_KIND(BadDecl, "bad declaration", struct { Token begin, end; }) \ AST_NODE_KIND(ValueDecl, "value declaration", struct { \ - bool is_var; \ + Token token; \ Array<AstNode *> names; \ - AstNode * type; \ + AstNode * type; \ Array<AstNode *> values; \ - u32 flags; \ + u32 flags; \ }) \ AST_NODE_KIND(ImportDecl, "import declaration", struct { \ Token token; \ @@ -525,10 +525,10 @@ Token ast_node_token(AstNode *node) { case AstNode_PushContext: return node->PushContext.token; case AstNode_BadDecl: return node->BadDecl.begin; - case AstNode_ValueDecl: return ast_node_token(node->ValueDecl.names[0]); + case AstNode_ValueDecl: return node->ValueDecl.token; case AstNode_ImportDecl: return node->ImportDecl.token; case AstNode_ForeignLibrary: return node->ForeignLibrary.token; - case AstNode_Label: return node->Label.token; + case AstNode_Label: return node->Label.token; case AstNode_Field: @@ -1412,9 +1412,9 @@ AstNode *ast_map_type(AstFile *f, Token token, AstNode *count, AstNode *key, Ast } -AstNode *ast_value_decl(AstFile *f, bool is_var, Array<AstNode *> names, AstNode *type, Array<AstNode *> values) { +AstNode *ast_value_decl(AstFile *f, Token token, Array<AstNode *> names, AstNode *type, Array<AstNode *> values) { AstNode *result = make_ast_node(f, AstNode_ValueDecl); - result->ValueDecl.is_var = is_var; + result->ValueDecl.token = token; result->ValueDecl.names = names; result->ValueDecl.type = type; result->ValueDecl.values = values; @@ -1646,7 +1646,7 @@ bool is_semicolon_optional_for_node(AstFile *f, AstNode *s) { return s->ProcLit.body != NULL; case AstNode_ValueDecl: - if (!s->ValueDecl.is_var) { + if (s->ValueDecl.token.kind != Token_var) { if (s->ValueDecl.values.count > 0) { AstNode *last = s->ValueDecl.values[s->ValueDecl.values.count-1]; return is_semicolon_optional_for_node(f, last); @@ -2023,6 +2023,11 @@ AstNode *parse_operand(AstFile *f, bool lhs) { return ast_paren_expr(f, operand, open, close); } + case Token_type: { + Token token = expect_token(f, Token_type); + return ast_helper_type(f, token, parse_type(f)); + } + case Token_Hash: { Token token = expect_token(f, Token_Hash); Token name = expect_token(f, Token_Ident); @@ -2037,7 +2042,6 @@ AstNode *parse_operand(AstFile *f, bool lhs) { } else if (name.string == "file") { return ast_basic_directive(f, token, name.string); } else if (name.string == "line") { return ast_basic_directive(f, token, name.string); } else if (name.string == "procedure") { return ast_basic_directive(f, token, name.string); - } else if (name.string == "type") { return ast_helper_type(f, token, parse_type(f)); } else if (!lhs && name.string == "alias") { return ast_alias(f, token, parse_expr(f, false)); } else { operand = ast_tag_expr(f, token, name, parse_expr(f, false)); @@ -2476,13 +2480,14 @@ AstNode *parse_type(AstFile *f) { } -AstNode *parse_value_decl(AstFile *f, Array<AstNode *> lhs) { +AstNode *parse_value_decl(AstFile *f, Token token) { + Array<AstNode *> lhs = parse_lhs_expr_list(f); AstNode *type = NULL; Array<AstNode *> values = {}; - bool is_mutable = true; + bool is_mutable = token.kind == Token_var; if (allow_token(f, Token_Colon)) { - type = parse_type_attempt(f); + type = parse_type(f); } else if (f->curr_token.kind != Token_Eq && f->curr_token.kind != Token_Semicolon) { syntax_error(f->curr_token, "Expected a type separator `:` or `=`"); @@ -2490,9 +2495,6 @@ AstNode *parse_value_decl(AstFile *f, Array<AstNode *> lhs) { switch (f->curr_token.kind) { - case Token_Colon: - is_mutable = false; - /*fallthrough*/ case Token_Eq: next_token(f); values = parse_rhs_expr_list(f); @@ -2524,14 +2526,25 @@ AstNode *parse_value_decl(AstFile *f, Array<AstNode *> lhs) { Array<AstNode *> specs = {}; array_init(&specs, heap_allocator(), 1); - return ast_value_decl(f, is_mutable, lhs, type, values); + // Token token = ast_node_token(lhs[0]); + // token.kind = is_mutable ? Token_var : Token_const; + // token.string = is_mutable ? str_lit("var") : str_lit("const"); + return ast_value_decl(f, token, lhs, type, values); } AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) { - Array<AstNode *> lhs = parse_lhs_expr_list(f); Token token = f->curr_token; + switch (f->curr_token.kind) { + case Token_var: + case Token_const: + next_token(f); + return parse_value_decl(f, token); + } + + Array<AstNode *> lhs = parse_lhs_expr_list(f); + token = f->curr_token; switch (token.kind) { case Token_Eq: case Token_AddEq: @@ -2604,7 +2617,7 @@ AstNode *parse_simple_stmt(AstFile *f, StmtAllowFlag flags) { } } - return parse_value_decl(f, lhs); + // return parse_value_decl(f, lhs); } if (lhs.count > 1) { @@ -3621,6 +3634,13 @@ AstNode *parse_stmt(AstFile *f) { expect_semicolon(f, s); return s; + case Token_var: + case Token_const: + s = parse_simple_stmt(f, StmtAllowFlag_None); + expect_semicolon(f, s); + return s; + + case Token_if: return parse_if_stmt(f); case Token_when: return parse_when_stmt(f); case Token_for: return parse_for_stmt(f); @@ -3659,12 +3679,15 @@ AstNode *parse_stmt(AstFile *f) { return ast_using_stmt(f, token, list); } - AstNode *decl = parse_value_decl(f, list); + Token var = ast_node_token(list[0]); + var.kind = Token_var; + var.string = str_lit("var"); + AstNode *decl = parse_value_decl(f, var); expect_semicolon(f, decl); if (decl->kind == AstNode_ValueDecl) { #if 1 - if (!decl->ValueDecl.is_var) { + if (decl->ValueDecl.token.kind != Token_var) { syntax_error(token, "`using` may not be applied to constant declarations"); return decl; } @@ -3689,7 +3712,7 @@ AstNode *parse_stmt(AstFile *f) { AstNode *node = parse_stmt(f); if (node->kind == AstNode_ValueDecl) { - if (!node->ValueDecl.is_var) { + if (node->ValueDecl.token.kind != Token_var) { syntax_error(token, "`immutable` may not be applied to constant declarations"); } else { node->ValueDecl.flags |= VarDeclFlag_immutable; @@ -3861,7 +3884,7 @@ AstNode *parse_stmt(AstFile *f) { AstNode *s = parse_stmt(f); if (s->kind == AstNode_ValueDecl) { - if (!s->ValueDecl.is_var) { + if (s->ValueDecl.token.kind != Token_var) { syntax_error(token, "`thread_local` may not be applied to constant declarations"); } if (f->curr_proc != NULL) { diff --git a/src/ssa.cpp b/src/ssa.cpp index f3c187222..dd12832be 100644 --- a/src/ssa.cpp +++ b/src/ssa.cpp @@ -1969,7 +1969,7 @@ void ssa_build_stmt_internal(ssaProc *p, AstNode *node) { case_end; case_ast_node(vd, ValueDecl, node); - if (vd->is_var) { + if (vd->token.kind == Token_var) { ssaModule *m = p->module; gbTempArenaMemory tmp = gb_temp_arena_memory_begin(&m->tmp_arena); if (vd->values.count == 0) { diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 38026deeb..425cd6a1d 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -82,6 +82,9 @@ TOKEN_KIND(Token__ComparisonEnd, "_ComparisonEnd"), \ TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \ \ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \ + TOKEN_KIND(Token_var, "var"), \ + TOKEN_KIND(Token_const, "const"), \ + TOKEN_KIND(Token_type, "type"), \ TOKEN_KIND(Token_when, "when"), \ TOKEN_KIND(Token_if, "if"), \ TOKEN_KIND(Token_else, "else"), \ |