diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-22 22:02:07 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-22 22:02:07 -0700 |
| commit | 523e3b86af44b97bcf68e3eb0956ef297421ee10 (patch) | |
| tree | 61b3743aced3715ebc8f811cc3477fca45d0ad20 /src/analyze.cpp | |
| parent | 21fc5a6402c527675900397ea60f107730985f1c (diff) | |
| download | zig-523e3b86af44b97bcf68e3eb0956ef297421ee10.tar.gz zig-523e3b86af44b97bcf68e3eb0956ef297421ee10.zip | |
support statically initialized array literal
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 56eb138a65..cc061a6b85 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -34,8 +34,6 @@ static AstNode *first_executing_node(AstNode *node) { return first_executing_node(node->data.field_access_expr.struct_expr); case NodeTypeSwitchRange: return first_executing_node(node->data.switch_range.start); - case NodeTypeContainerInitExpr: - return first_executing_node(node->data.container_init_expr.type); case NodeTypeRoot: case NodeTypeRootExportDecl: case NodeTypeFnProto: @@ -72,6 +70,7 @@ static AstNode *first_executing_node(AstNode *node) { case NodeTypeSwitchExpr: case NodeTypeSwitchProng: case NodeTypeArrayType: + case NodeTypeContainerInitExpr: return node; } zig_unreachable(); @@ -1586,9 +1585,22 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry assert(pointer_type->id == TypeTableEntryIdPointer); TypeTableEntry *child_type = pointer_type->data.pointer.child_type; + ConstExprValue *const_val = &get_resolved_expr(node)->const_val; + const_val->ok = true; + const_val->data.x_array.fields = allocate<ConstExprValue*>(elem_count); + for (int i = 0; i < elem_count; i += 1) { - AstNode *elem_node = container_init_expr->entries.at(i); - analyze_expression(g, import, context, child_type, elem_node); + AstNode **elem_node = &container_init_expr->entries.at(i); + analyze_expression(g, import, context, child_type, *elem_node); + + if (const_val->ok) { + ConstExprValue *elem_const_val = &get_resolved_expr(*elem_node)->const_val; + if (elem_const_val->ok) { + const_val->data.x_array.fields[i] = elem_const_val; + } else { + const_val->ok = false; + } + } } TypeTableEntry *fixed_size_array_type = get_array_type(g, child_type, elem_count); |
