aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-03-10 11:21:41 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-03-10 11:21:41 -0500
commit434f017aeefc392bcf524732940e2f2b908222f3 (patch)
treeff7f935dbaca2093a88f4e1a1411c6699157952e /src/analyze.cpp
parentc78dc5043bb8f0fa3ff2fec876bcab4ee499972c (diff)
downloadzig-434f017aeefc392bcf524732940e2f2b908222f3.tar.gz
zig-434f017aeefc392bcf524732940e2f2b908222f3.zip
codegen nullable void the same way as bool
See #104
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index b1753af264..870f06dfe8 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -397,7 +397,10 @@ TypeTableEntry *get_maybe_type(CodeGen *g, TypeTableEntry *child_type) {
buf_resize(&entry->name, 0);
buf_appendf(&entry->name, "?%s", buf_ptr(&child_type->name));
- if (child_type->id == TypeTableEntryIdPointer ||
+ if (child_type->zero_bits) {
+ entry->type_ref = LLVMInt1Type();
+ entry->di_type = g->builtin_types.entry_bool->di_type;
+ } else if (child_type->id == TypeTableEntryIdPointer ||
child_type->id == TypeTableEntryIdFn)
{
// this is an optimization but also is necessary for calling C
@@ -2958,7 +2961,8 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
assert(type_entry->data.enumeration.complete);
return type_entry->data.enumeration.gen_field_count != 0;
case TypeTableEntryIdMaybe:
- return type_entry->data.maybe.child_type->id != TypeTableEntryIdPointer &&
+ return !type_entry->data.maybe.child_type->zero_bits &&
+ type_entry->data.maybe.child_type->id != TypeTableEntryIdPointer &&
type_entry->data.maybe.child_type->id != TypeTableEntryIdFn;
case TypeTableEntryIdTypeDecl:
return handle_is_ptr(type_entry->data.type_decl.canonical_type);
@@ -3632,7 +3636,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
case TypeTableEntryIdNullLit:
zig_panic("TODO");
case TypeTableEntryIdMaybe:
- zig_panic("TODO");
+ if (a->data.x_maybe == nullptr || b->data.x_maybe == nullptr) {
+ return (a->data.x_maybe == nullptr && b->data.x_maybe == nullptr);
+ } else {
+ return const_values_equal(a->data.x_maybe, b->data.x_maybe);
+ }
case TypeTableEntryIdErrorUnion:
zig_panic("TODO");
case TypeTableEntryIdTypeDecl: