diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-31 01:51:33 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-31 01:51:33 -0700 |
| commit | 55c9ae119382add2b840ae6526884bc9d99c9994 (patch) | |
| tree | cfb3d6c0e89ca756c50ec6113b55c3c2bf068f3c /src/parser.cpp | |
| parent | 3c2093fec64c38b2895fb162b7fe58e6ec232bc6 (diff) | |
| download | zig-55c9ae119382add2b840ae6526884bc9d99c9994.tar.gz zig-55c9ae119382add2b840ae6526884bc9d99c9994.zip | |
codegen extern global variables correctly
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 67d2c21312..f81206357f 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2256,7 +2256,7 @@ static AstNode *ast_parse_fn_def(ParseContext *pc, int *token_index, bool mandat } /* -ExternDecl : "extern" FnProto ";" +ExternDecl = "extern" (FnProto | VariableDeclaration) ";" */ static AstNode *ast_parse_extern_decl(ParseContext *pc, int *token_index, bool mandatory, ZigList<AstNode *> *directives, VisibMod visib_mod) @@ -2271,13 +2271,28 @@ static AstNode *ast_parse_extern_decl(ParseContext *pc, int *token_index, bool m } *token_index += 1; - AstNode *node = ast_parse_fn_proto(pc, token_index, true, directives, visib_mod); + AstNode *fn_proto_node = ast_parse_fn_proto(pc, token_index, false, directives, visib_mod); + if (fn_proto_node) { + ast_eat_token(pc, token_index, TokenIdSemicolon); - ast_eat_token(pc, token_index, TokenIdSemicolon); + fn_proto_node->data.fn_proto.is_extern = true; - node->data.fn_proto.is_extern = true; - normalize_parent_ptrs(node); - return node; + normalize_parent_ptrs(fn_proto_node); + return fn_proto_node; + } + + AstNode *var_decl_node = ast_parse_variable_declaration_expr(pc, token_index, false, directives, visib_mod); + if (var_decl_node) { + ast_eat_token(pc, token_index, TokenIdSemicolon); + + var_decl_node->data.variable_declaration.is_extern = true; + + normalize_parent_ptrs(var_decl_node); + return var_decl_node; + } + + Token *token = &pc->tokens->at(*token_index); + ast_invalid_token_error(pc, token); } /* |
