diff options
| author | Andrea Orru <andrea@orru.io> | 2018-03-13 16:16:22 -0700 |
|---|---|---|
| committer | Andrea Orru <andrea@orru.io> | 2018-03-13 16:16:22 -0700 |
| commit | 2a6ad23b52aa128dfbfc1fe975fadc38714850b4 (patch) | |
| tree | 7a7b3d03a76f7b39674cc9b286feab4f78fa650f /src/analyze.cpp | |
| parent | 2cdd50c9b266ea828274578481e0c37dc0b19956 (diff) | |
| parent | 7f7823e23cfd82739401f43a329106bee0748b10 (diff) | |
| download | zig-2a6ad23b52aa128dfbfc1fe975fadc38714850b4.tar.gz zig-2a6ad23b52aa128dfbfc1fe975fadc38714850b4.zip | |
Merge branch 'master' of https://github.com/zig-lang/zig
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 35ef5df7da..395df229cd 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4451,6 +4451,10 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { case TypeTableEntryIdArgTuple: return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 + (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768; + case TypeTableEntryIdFn: + assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst); + assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); + return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry); case TypeTableEntryIdPointer: { uint32_t hash_val = 0; @@ -4490,6 +4494,10 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { case ConstPtrSpecialDiscard: hash_val += 2010123162; return hash_val; + case ConstPtrSpecialFunction: + hash_val += (uint32_t)2590901619; + hash_val += hash_ptr(const_val->data.x_ptr.data.fn.fn_entry); + return hash_val; } zig_unreachable(); } @@ -4521,8 +4529,6 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { case TypeTableEntryIdErrorSet: assert(const_val->data.x_err_set != nullptr); return const_val->data.x_err_set->value ^ 2630160122; - case TypeTableEntryIdFn: - return 4133894920 ^ hash_ptr(const_val->data.x_fn.fn_entry); case TypeTableEntryIdNamespace: return hash_ptr(const_val->data.x_import); case TypeTableEntryIdBlock: @@ -5154,8 +5160,6 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { return true; case TypeTableEntryIdErrorSet: return a->data.x_err_set->value == b->data.x_err_set->value; - case TypeTableEntryIdFn: - return a->data.x_fn.fn_entry == b->data.x_fn.fn_entry; case TypeTableEntryIdBool: return a->data.x_bool == b->data.x_bool; case TypeTableEntryIdFloat: @@ -5176,6 +5180,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { case TypeTableEntryIdNumLitInt: return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ; case TypeTableEntryIdPointer: + case TypeTableEntryIdFn: if (a->data.x_ptr.special != b->data.x_ptr.special) return false; if (a->data.x_ptr.mut != b->data.x_ptr.mut) @@ -5215,6 +5220,8 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { return true; case ConstPtrSpecialDiscard: return true; + case ConstPtrSpecialFunction: + return a->data.x_ptr.data.fn.fn_entry == b->data.x_ptr.data.fn.fn_entry; } zig_unreachable(); case TypeTableEntryIdArray: @@ -5375,6 +5382,14 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { buf_appendf(buf, "%s", value); return; } + case TypeTableEntryIdFn: + { + assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst); + assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); + FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry; + buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name)); + return; + } case TypeTableEntryIdPointer: switch (const_val->data.x_ptr.special) { case ConstPtrSpecialInvalid: @@ -5400,14 +5415,14 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { case ConstPtrSpecialDiscard: buf_append_str(buf, "&_"); return; + case ConstPtrSpecialFunction: + { + FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry; + buf_appendf(buf, "@ptrCast(%s, %s)", buf_ptr(&const_val->type->name), buf_ptr(&fn_entry->symbol_name)); + return; + } } zig_unreachable(); - case TypeTableEntryIdFn: - { - FnTableEntry *fn_entry = const_val->data.x_fn.fn_entry; - buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name)); - return; - } case TypeTableEntryIdBlock: { AstNode *node = const_val->data.x_block->source_node; |
