diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2015-12-31 16:04:13 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2015-12-31 16:04:13 -0700 |
| commit | b3ac5c16ecc8dd9da661dcb9d15a6c36a8e4167b (patch) | |
| tree | 4539ac7b88906ef03540639f19e2f37ce0bf319f /src/analyze.cpp | |
| parent | 7ba99e9715c1fa3cd00fe6d9ac74b9a15eeac706 (diff) | |
| download | zig-b3ac5c16ecc8dd9da661dcb9d15a6c36a8e4167b.tar.gz zig-b3ac5c16ecc8dd9da661dcb9d15a6c36a8e4167b.zip | |
block expressions require parens
closes #39
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 2be84ffa5b..7801cac201 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -132,6 +132,26 @@ TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool } } +static TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) { + if (child_type->maybe_parent) { + return child_type->maybe_parent; + } else { + TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMaybe); + // TODO entry->type_ref + buf_resize(&entry->name, 0); + buf_appendf(&entry->name, "?%s", buf_ptr(&child_type->name)); + // TODO entry->size_in_bits + // TODO entry->align_in_bits + assert(child_type->di_type); + // TODO entry->di_type + entry->data.maybe.child_type = child_type; + + g->type_table.put(&entry->name, entry); + child_type->maybe_parent = entry; + return entry; + } +} + static TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size) { auto existing_entry = child_type->arrays_by_size.maybe_get(array_size); if (existing_entry) { @@ -208,6 +228,20 @@ static TypeTableEntry *resolve_type(CodeGen *g, AstNode *node) { } return type_node->entry; } + case AstNodeTypeTypeMaybe: + { + resolve_type(g, node->data.type.child_type); + TypeTableEntry *child_type = node->data.type.child_type->codegen_node->data.type_node.entry; + assert(child_type); + if (child_type->id == TypeTableEntryIdUnreachable) { + add_node_error(g, node, + buf_create_from_str("maybe unreachable type not allowed")); + } else if (child_type->id == TypeTableEntryIdInvalid) { + return child_type; + } + type_node->entry = get_maybe_type(g, child_type); + return type_node->entry; + } } zig_unreachable(); } |
