From b3ac5c16ecc8dd9da661dcb9d15a6c36a8e4167b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 31 Dec 2015 16:04:13 -0700 Subject: block expressions require parens closes #39 --- src/analyze.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/analyze.cpp') 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(); } -- cgit v1.2.3