Fix link_name overriding

This commit is contained in:
gingerBill
2017-11-09 23:36:10 +00:00
parent e5c39fb2a9
commit ae3672608d
3 changed files with 20 additions and 12 deletions
+4 -4
View File
@@ -429,9 +429,9 @@ void init_entity_foreign_library(Checker *c, Entity *e) {
} }
} }
String handle_link_name(Checker *c, Token token, String link_name, String link_prefix, bool link_prefix_overridden) { String handle_link_name(Checker *c, Token token, String link_name, String link_prefix) {
if (link_prefix.len > 0) { if (link_prefix.len > 0) {
if (link_name.len > 0 && !link_prefix_overridden) { if (link_name.len > 0) {
error(token, "`link_name` and `link_prefix` cannot be used together"); error(token, "`link_name` and `link_prefix` cannot be used together");
} else { } else {
isize len = link_prefix.len + token.string.len; isize len = link_prefix.len + token.string.len;
@@ -485,7 +485,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d) {
} }
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix, ac.link_prefix_overridden); ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
if (d->scope->file != nullptr && e->token.string == "main") { if (d->scope->file != nullptr && e->token.string == "main") {
if (pt->param_count != 0 || if (pt->param_count != 0 ||
@@ -635,7 +635,7 @@ void check_var_decl(Checker *c, Entity *e, Entity **entities, isize entity_count
check_decl_attributes(c, decl->attributes, var_decl_attribute, &ac); check_decl_attributes(c, decl->attributes, var_decl_attribute, &ac);
} }
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix, ac.link_prefix_overridden); ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
e->Variable.thread_local_model = ac.thread_local_model; e->Variable.thread_local_model = ac.thread_local_model;
String context_name = str_lit("variable declaration"); String context_name = str_lit("variable declaration");
+1 -1
View File
@@ -1762,7 +1762,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
if (e->type == nullptr) { if (e->type == nullptr) {
e->type = init_type; e->type = init_type;
} }
ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix, ac.link_prefix_overridden); ac.link_name = handle_link_name(c, e->token, ac.link_name, ac.link_prefix);
e->Variable.thread_local_model = ac.thread_local_model; e->Variable.thread_local_model = ac.thread_local_model;
if (ac.link_name.len > 0) { if (ac.link_name.len > 0) {
+15 -7
View File
@@ -1862,7 +1862,6 @@ void check_procedure_overloading(Checker *c, Entity *e) {
struct AttributeContext { struct AttributeContext {
String link_name; String link_name;
String link_prefix; String link_prefix;
bool link_prefix_overridden;
isize init_expr_list_count; isize init_expr_list_count;
String thread_local_model; String thread_local_model;
}; };
@@ -1922,9 +1921,6 @@ DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
return true; return true;
} else if (name == "link_prefix") { } else if (name == "link_prefix") {
if (value.kind == ExactValue_String) { if (value.kind == ExactValue_String) {
if (ac->link_prefix.len > 0) {
ac->link_prefix_overridden = true;
}
ac->link_prefix = value.value_string; ac->link_prefix = value.value_string;
if (!is_foreign_name_valid(ac->link_prefix)) { if (!is_foreign_name_valid(ac->link_prefix)) {
error(elem, "Invalid link prefix: %.*s", LIT(ac->link_prefix)); error(elem, "Invalid link prefix: %.*s", LIT(ac->link_prefix));
@@ -1955,9 +1951,6 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) {
return true; return true;
} else if (name == "link_prefix") { } else if (name == "link_prefix") {
if (value.kind == ExactValue_String) { if (value.kind == ExactValue_String) {
if (ac->link_prefix.len > 0) {
ac->link_prefix_overridden = true;
}
ac->link_prefix = value.value_string; ac->link_prefix = value.value_string;
if (!is_foreign_name_valid(ac->link_prefix)) { if (!is_foreign_name_valid(ac->link_prefix)) {
error(elem, "Invalid link prefix: %.*s", LIT(ac->link_prefix)); error(elem, "Invalid link prefix: %.*s", LIT(ac->link_prefix));
@@ -2002,6 +1995,12 @@ DECL_ATTRIBUTE_PROC(var_decl_attribute) {
void check_decl_attributes(Checker *c, Array<AstNode *> attributes, DeclAttributeProc *proc, AttributeContext *ac) { void check_decl_attributes(Checker *c, Array<AstNode *> attributes, DeclAttributeProc *proc, AttributeContext *ac) {
if (attributes.count == 0) return; if (attributes.count == 0) return;
String original_link_prefix = {};
if (ac) {
original_link_prefix = ac->link_prefix;
}
StringSet set = {}; StringSet set = {};
string_set_init(&set, heap_allocator()); string_set_init(&set, heap_allocator());
defer (string_set_destroy(&set)); defer (string_set_destroy(&set));
@@ -2051,6 +2050,15 @@ void check_decl_attributes(Checker *c, Array<AstNode *> attributes, DeclAttribut
} }
} }
} }
if (ac) {
if (ac->link_prefix.text == original_link_prefix.text) {
if (ac->link_name.len > 0) {
ac->link_prefix.text = nullptr;
ac->link_prefix.len = 0;
}
}
}
} }