From 77ffb5075bd550893b9f6ac99f151b1d55a8040e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 15 Feb 2016 23:30:05 -0700 Subject: 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 --- src/parser.cpp | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'src/parser.cpp') 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 *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); -- cgit v1.2.3