comptime ({}) should not get an implicit semicolon

closes #292.
master
Josh Wolfe 2017-04-14 16:09:01 -07:00
parent 5fdefe58e4
commit 3e93796e24
5 changed files with 18 additions and 2 deletions

View File

@ -320,6 +320,7 @@ enum NodeType {
NodeTypeFnDecl,
NodeTypeParamDecl,
NodeTypeBlock,
NodeTypeGroupedExpr,
NodeTypeReturnExpr,
NodeTypeDefer,
NodeTypeVariableDeclaration,
@ -793,6 +794,7 @@ struct AstNode {
AstNodeFnProto fn_proto;
AstNodeParamDecl param_decl;
AstNodeBlock block;
AstNode * grouped_expr;
AstNodeReturnExpr return_expr;
AstNodeDefer defer;
AstNodeVariableDeclaration variable_declaration;

View File

@ -2076,6 +2076,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
case NodeTypeReturnExpr:
case NodeTypeDefer:
case NodeTypeBlock:
case NodeTypeGroupedExpr:
case NodeTypeBinOpExpr:
case NodeTypeUnwrapErrorExpr:
case NodeTypeFnCallExpr:

View File

@ -150,6 +150,8 @@ static const char *node_type_str(NodeType node_type) {
return "ParamDecl";
case NodeTypeBlock:
return "Block";
case NodeTypeGroupedExpr:
return "Parens";
case NodeTypeBinOpExpr:
return "BinOpExpr";
case NodeTypeUnwrapErrorExpr:
@ -469,6 +471,11 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
print_indent(ar);
fprintf(ar->f, "}");
break;
case NodeTypeGroupedExpr:
fprintf(ar->f, "(");
render_node_ungrouped(ar, node->data.grouped_expr);
fprintf(ar->f, ")");
break;
case NodeTypeReturnExpr:
{
const char *return_str = return_string(node->data.return_expr.kind);

View File

@ -5574,6 +5574,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
zig_unreachable();
case NodeTypeBlock:
return ir_lval_wrap(irb, scope, ir_gen_block(irb, scope, node), lval);
case NodeTypeGroupedExpr:
return ir_gen_node_raw(irb, node->data.grouped_expr, scope, lval);
case NodeTypeBinOpExpr:
return ir_lval_wrap(irb, scope, ir_gen_bin_op(irb, scope, node), lval);
case NodeTypeNumberLiteral:

View File

@ -363,10 +363,11 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, size_t *token_index, bo
return nullptr;
}
}
*token_index += 1;
AstNode *node = ast_parse_expression(pc, token_index, true);
AstNode *node = ast_create_node(pc, NodeTypeGroupedExpr, l_paren);
node->data.grouped_expr = ast_parse_expression(pc, token_index, true);
Token *r_paren = &pc->tokens->at(*token_index);
*token_index += 1;
@ -2605,6 +2606,9 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
case NodeTypeBlock:
visit_node_list(&node->data.block.statements, visit, context);
break;
case NodeTypeGroupedExpr:
visit_field(&node->data.grouped_expr, visit, context);
break;
case NodeTypeReturnExpr:
visit_field(&node->data.return_expr.expr, visit, context);
break;