diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2015-11-24 13:00:38 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2015-11-24 13:00:38 -0700 |
| commit | c2e5d50027779468c66608f445f3ab0f77d34c15 (patch) | |
| tree | 0d4bce1559548e7b6762a8a93fb551ccf642e126 /src/parser.cpp | |
| parent | e112818e25b710199f5c757c17717499356d516e (diff) | |
| download | zig-c2e5d50027779468c66608f445f3ab0f77d34c15.tar.gz zig-c2e5d50027779468c66608f445f3ab0f77d34c15.zip | |
write object file and fix void return type
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index cd90e8e97a..72052e414a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2015 Andrew Kelley + * + * This file is part of zig, which is MIT licensed. + * See http://opensource.org/licenses/MIT + */ + #include "parser.hpp" #include <stdarg.h> @@ -168,6 +175,13 @@ static AstNode *ast_create_node_with_node(NodeType type, AstNode *other_node) { return node; } +static AstNode *ast_create_void_type_node(ParseContext *pc, Token *token) { + AstNode *node = ast_create_node(NodeTypeType, token); + node->data.type.type = AstNodeTypeTypePrimitive; + buf_init_from_str(&node->data.type.primitive_name, "void"); + return node; +} + static void ast_buf_from_token(ParseContext *pc, Token *token, Buf *buf) { buf_init_from_mem(buf, buf_ptr(pc->buf) + token->start_pos, token->end_pos - token->start_pos); } @@ -468,13 +482,11 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int token_index, int *new_t ast_parse_param_decl_list(pc, token_index, &token_index, &node->data.fn_proto.params); Token *arrow = &pc->tokens->at(token_index); - token_index += 1; if (arrow->id == TokenIdArrow) { + token_index += 1; node->data.fn_proto.return_type = ast_parse_type(pc, token_index, &token_index); - } else if (arrow->id == TokenIdLBrace) { - node->data.fn_proto.return_type = nullptr; } else { - ast_invalid_token_error(pc, arrow); + node->data.fn_proto.return_type = ast_create_void_type_node(pc, arrow); } *new_token_index = token_index; |
