aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-01-11 20:58:28 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-01-11 21:02:30 -0500
commit3268276b58d8b65cb295b738d7c14174005bd84e (patch)
treec52b5524962c7ab37129318b5aba31b9d83820f6 /src/analyze.cpp
parent465e75bc5a41aa899b673c0a3ff59d6da871fbe6 (diff)
downloadzig-3268276b58d8b65cb295b738d7c14174005bd84e.tar.gz
zig-3268276b58d8b65cb295b738d7c14174005bd84e.zip
the same string literal codegens to the same constant
this makes it so that you can send the same string literal as a comptime slice and get the same type
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 2c6f0f209e..7e4a861f0f 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -4370,6 +4370,12 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {
}
void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
+ auto entry = g->string_literals_table.maybe_get(str);
+ if (entry != nullptr) {
+ *const_val = *entry->value;
+ return;
+ }
+
const_val->special = ConstValSpecialStatic;
const_val->type = get_array_type(g, g->builtin_types.entry_u8, buf_len(str));
const_val->data.x_array.s_none.elements = create_const_vals(buf_len(str));
@@ -4380,6 +4386,8 @@ void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str) {
this_char->type = g->builtin_types.entry_u8;
bigint_init_unsigned(&this_char->data.x_bigint, (uint8_t)buf_ptr(str)[i]);
}
+
+ g->string_literals_table.put(str, const_val);
}
ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str) {