diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-02 19:47:36 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-02 19:47:36 -0700 |
| commit | 187d00ca835d2c923cbc0a3ab9e861e82888d403 (patch) | |
| tree | 923b224c44e801b3d6bb9e8a2432d216c1f7e6d6 /src/analyze.cpp | |
| parent | 968b85ad77892da945d478799d4e775222248f1f (diff) | |
| download | zig-187d00ca835d2c923cbc0a3ab9e861e82888d403.tar.gz zig-187d00ca835d2c923cbc0a3ab9e861e82888d403.zip | |
ability to access pointers with array indexing syntax
closes #40
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index e30c0c29b6..4ebf10a5b6 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1057,6 +1057,8 @@ static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *i if (array_type->id == TypeTableEntryIdArray) { return_type = array_type->data.array.child_type; + } else if (array_type->id == TypeTableEntryIdPointer) { + return_type = array_type->data.pointer.child_type; } else { if (array_type->id != TypeTableEntryIdInvalid) { add_node_error(g, node, buf_sprintf("array access of non-array")); @@ -1064,14 +1066,7 @@ static TypeTableEntry *analyze_array_access_expr(CodeGen *g, ImportTableEntry *i return_type = g->builtin_types.entry_invalid; } - TypeTableEntry *subscript_type = analyze_expression(g, import, context, nullptr, - node->data.array_access_expr.subscript); - if (subscript_type->id != TypeTableEntryIdInt && - subscript_type->id != TypeTableEntryIdInvalid) - { - add_node_error(g, node, - buf_sprintf("array subscripts must be integers")); - } + analyze_expression(g, import, context, g->builtin_types.entry_usize, node->data.array_access_expr.subscript); return return_type; } @@ -1150,7 +1145,7 @@ static TypeTableEntry *analyze_cast_expr(CodeGen *g, ImportTableEntry *import, B cast_node->after_type = wanted_type; // special casing this for now, TODO think about casting and do a general solution - if (wanted_type == g->builtin_types.entry_isize && + if ((wanted_type == g->builtin_types.entry_isize || wanted_type == g->builtin_types.entry_usize) && actual_type->id == TypeTableEntryIdPointer) { cast_node->op = CastOpPtrToInt; |
