aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-02-15 23:30:05 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-02-16 16:41:56 -0700
commit77ffb5075bd550893b9f6ac99f151b1d55a8040e (patch)
treed7cde8b3527f2458f216562f42b5957fefc477e9 /src/parser.cpp
parent91101f08c24a931e8e0ecbe46d80df759135332c (diff)
downloadzig-77ffb5075bd550893b9f6ac99f151b1d55a8040e.tar.gz
zig-77ffb5075bd550893b9f6ac99f151b1d55a8040e.zip
update bootstrap to work for macos too
* Directives can have arbitrary expressions as parameters * Fix switch statement not generating code sometimes * Rename "main" fn in bootstrap.zig to "zig_user_main" to avoid name collisions * codegen: fix badref when unreachable is last thing in an expression * support #condition directive on exported functions
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp29
1 files changed, 8 insertions, 21 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 5d22105bff..1a5cc503cd 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -499,6 +499,7 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, boo
static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory,
ZigList<AstNode*> *directives, VisibMod visib_mod);
static AstNode *ast_parse_return_expr(ParseContext *pc, int *token_index);
+static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool mandatory);
static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {
if (token->id == token_id) {
@@ -517,33 +518,19 @@ static Token *ast_eat_token(ParseContext *pc, int *token_index, TokenId token_id
return token;
}
-
+/*
+Directive = "#" "Symbol" "(" Expression ")"
+*/
static AstNode *ast_parse_directive(ParseContext *pc, int *token_index) {
- Token *number_sign = &pc->tokens->at(*token_index);
- *token_index += 1;
- ast_expect_token(pc, number_sign, TokenIdNumberSign);
+ Token *number_sign = ast_eat_token(pc, token_index, TokenIdNumberSign);
AstNode *node = ast_create_node(pc, NodeTypeDirective, number_sign);
- Token *name_symbol = &pc->tokens->at(*token_index);
- *token_index += 1;
- ast_expect_token(pc, name_symbol, TokenIdSymbol);
+ Token *name_symbol = ast_eat_token(pc, token_index, TokenIdSymbol);
ast_buf_from_token(pc, name_symbol, &node->data.directive.name);
- Token *l_paren = &pc->tokens->at(*token_index);
- *token_index += 1;
- ast_expect_token(pc, l_paren, TokenIdLParen);
-
- Token *param_str = &pc->tokens->at(*token_index);
- *token_index += 1;
- ast_expect_token(pc, param_str, TokenIdStringLiteral);
-
- parse_string_literal(pc, param_str, &node->data.directive.param, nullptr, nullptr);
-
- Token *r_paren = &pc->tokens->at(*token_index);
- *token_index += 1;
- ast_expect_token(pc, r_paren, TokenIdRParen);
+ node->data.directive.expr = ast_parse_grouped_expr(pc, token_index, true);
normalize_parent_ptrs(node);
return node;
@@ -2741,7 +2728,7 @@ void normalize_parent_ptrs(AstNode *node) {
set_list_fields(&node->data.block.statements);
break;
case NodeTypeDirective:
- // none
+ set_field(&node->data.directive.expr);
break;
case NodeTypeReturnExpr:
set_field(&node->data.return_expr.expr);