aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorMichael Dusan <michael.dusan@gmail.com>2019-10-09 14:46:12 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-10-09 17:36:13 -0400
commit42f2814d9acc014c84034468b2923195aa547ce1 (patch)
tree0825a836f09dbc1de025dda44929cef9419869a8 /src/analyze.cpp
parente0ab685467567f6da02be865654a2c4dc5f8c3a9 (diff)
downloadzig-42f2814d9acc014c84034468b2923195aa547ce1.tar.gz
zig-42f2814d9acc014c84034468b2923195aa547ce1.zip
stage1: fix root top-level-struct typename
- during diagnostics the string representation for root was empty and now is `(root)` - retrofitted all other namespace-qualified type naming to elide prefixing with root closes #2032
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 82b09175d3..baeaedf8d9 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -999,7 +999,12 @@ static ZigType *get_root_container_type(CodeGen *g, const char *full_name, Buf *
entry->data.structure.root_struct = root_struct;
entry->data.structure.layout = ContainerLayoutAuto;
- buf_init_from_str(&entry->name, full_name);
+ if (full_name[0] == '\0') {
+ buf_init_from_str(&entry->name, "(root)");
+ } else {
+ buf_init_from_str(&entry->name, full_name);
+ }
+
return entry;
}
@@ -3156,7 +3161,13 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
return ErrorNone;
}
-static void get_fully_qualified_decl_name(Buf *buf, Tld *tld, bool is_test) {
+void append_namespace_qualification(CodeGen *g, Buf *buf, ZigType *container_type) {
+ if (g->root_import == container_type || buf_len(&container_type->name) == 0) return;
+ buf_append_buf(buf, &container_type->name);
+ buf_append_char(buf, NAMESPACE_SEP_CHAR);
+}
+
+static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool is_test) {
buf_resize(buf, 0);
Scope *scope = tld->parent_scope;
@@ -3164,8 +3175,7 @@ static void get_fully_qualified_decl_name(Buf *buf, Tld *tld, bool is_test) {
scope = scope->parent;
}
ScopeDecls *decls_scope = reinterpret_cast<ScopeDecls *>(scope);
- buf_append_buf(buf, &decls_scope->container_type->name);
- if (buf_len(buf) != 0) buf_append_char(buf, NAMESPACE_SEP_CHAR);
+ append_namespace_qualification(g, buf, decls_scope->container_type);
if (is_test) {
buf_append_str(buf, "test \"");
buf_append_buf(buf, tld->name);
@@ -3288,7 +3298,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
if (fn_proto->is_export || is_extern) {
buf_init_from_buf(&fn_table_entry->symbol_name, tld_fn->base.name);
} else {
- get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, false);
+ get_fully_qualified_decl_name(g, &fn_table_entry->symbol_name, &tld_fn->base, false);
}
if (fn_proto->is_export) {
@@ -3352,7 +3362,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
} else if (source_node->type == NodeTypeTestDecl) {
ZigFn *fn_table_entry = create_fn_raw(g, FnInlineAuto);
- get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, true);
+ get_fully_qualified_decl_name(g, &fn_table_entry->symbol_name, &tld_fn->base, true);
tld_fn->fn_entry = fn_table_entry;