diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2015-12-08 14:47:17 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2015-12-08 14:47:17 -0700 |
| commit | 6e0c3dc173507b92fc04515659454044f918efbb (patch) | |
| tree | a1e12b910b101293f2e6b6ee0213cd201f82fe29 /src/analyze.cpp | |
| parent | 75efc313299af89c69c5f2b4a7c2758753ed36c3 (diff) | |
| download | zig-6e0c3dc173507b92fc04515659454044f918efbb.tar.gz zig-6e0c3dc173507b92fc04515659454044f918efbb.zip | |
array access support
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 3351041db9..c6f50ff5d3 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -124,6 +124,7 @@ static TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, in entry->align_in_bits = child_type->align_in_bits; entry->di_type = LLVMZigCreateDebugArrayType(g->dbuilder, entry->size_in_bits, entry->align_in_bits, child_type->di_type, array_size); + entry->data.array.child_type = child_type; g->type_table.put(&entry->name, entry); child_type->arrays_by_size.put(array_size, entry); @@ -185,7 +186,7 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node) { size = parse_int(&size_node->data.number); } - type_node->entry = get_array_type(g, child_type, size); // TODO + type_node->entry = get_array_type(g, child_type, size); return type_node->entry; } } @@ -737,12 +738,19 @@ static TypeTableEntry * analyze_expression(CodeGen *g, ImportTableEntry *import, case NodeTypeArrayAccessExpr: { // here we are always reading the array - TypeTableEntry *lhs_type = analyze_expression(g, import, context, nullptr, + TypeTableEntry *array_type = analyze_expression(g, import, context, nullptr, node->data.array_access_expr.array_ref_expr); - if (lhs_type->id == TypeTableEntryIdArray) { - zig_panic("TODO"); + if (array_type->id == TypeTableEntryIdArray) { + TypeTableEntry *subscript_type = analyze_expression(g, import, context, + nullptr, node->data.array_access_expr.subscript); + if (subscript_type->id != TypeTableEntryIdInt) { + add_node_error(g, node, + buf_sprintf("array subscripts must be integers")); + } + return_type = array_type->data.array.child_type; } else { add_node_error(g, node, buf_sprintf("array access of non-array")); + return_type = g->builtin_types.entry_invalid; } break; |
