authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-23 16:52:13-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-23 16:52:13-05:00
log3075d8aee728d10b1b8428ead070ba47856e78c3
treeaa1fa35d29fd3c9fc87a11d944d9606314b53839
parentfe3063e58cf81287a26219903f2720439dfeb7e6

fix use decls not always working


3 files changed, 17 insertions(+), 19 deletions(-)

src/analyze.cpp+12-2
...@@ -2110,7 +2110,7 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent...@@ -2110,7 +2110,7 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent
2110 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));2110 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
2111 variable_entry->value.type = g->builtin_types.entry_invalid;2111 variable_entry->value.type = g->builtin_types.entry_invalid;
2112 } else {2112 } else {
2113 Tld *tld = find_decl(parent_scope, name);2113 Tld *tld = find_decl(g, parent_scope, name);
2114 if (tld && tld->id != TldIdVar) {2114 if (tld && tld->id != TldIdVar) {
2115 ErrorMsg *msg = add_node_error(g, source_node,2115 ErrorMsg *msg = add_node_error(g, source_node,
2116 buf_sprintf("redefinition of '%s'", buf_ptr(name)));2116 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
...@@ -2357,7 +2357,17 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *...@@ -2357,7 +2357,17 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
2357 return false;2357 return false;
2358}2358}
23592359
2360Tld *find_decl(Scope *scope, Buf *name) {2360Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) {
2361 // we must resolve all the use decls
2362 ImportTableEntry *import = get_scope_import(scope);
2363 for (size_t i = 0; i < import->use_decls.length; i += 1) {
2364 AstNode *use_decl_node = import->use_decls.at(i);
2365 if (use_decl_node->data.use.resolution == TldResolutionUnresolved) {
2366 preview_use_decl(g, use_decl_node);
2367 }
2368 resolve_use_decl(g, use_decl_node);
2369 }
2370
2361 while (scope) {2371 while (scope) {
2362 if (scope->id == ScopeIdDecls) {2372 if (scope->id == ScopeIdDecls) {
2363 ScopeDecls *decls_scope = (ScopeDecls *)scope;2373 ScopeDecls *decls_scope = (ScopeDecls *)scope;
src/analyze.hpp+1-1
...@@ -49,7 +49,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,...@@ -49,7 +49,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package,
49// TODO move these over, these used to be static49// TODO move these over, these used to be static
50bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);50bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);
51VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);51VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
52Tld *find_decl(Scope *scope, Buf *name);52Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
53void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only);53void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only);
54bool type_is_codegen_pointer(TypeTableEntry *type);54bool type_is_codegen_pointer(TypeTableEntry *type);
55TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry);55TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry);
src/ir.cpp+4-16
...@@ -3180,7 +3180,7 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco...@@ -3180,7 +3180,7 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco
3180 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));3180 buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name)));
3181 variable_entry->value.type = codegen->builtin_types.entry_invalid;3181 variable_entry->value.type = codegen->builtin_types.entry_invalid;
3182 } else {3182 } else {
3183 Tld *tld = find_decl(parent_scope, name);3183 Tld *tld = find_decl(codegen, parent_scope, name);
3184 if (tld && tld->id != TldIdVar) {3184 if (tld && tld->id != TldIdVar) {
3185 ErrorMsg *msg = add_node_error(codegen, node,3185 ErrorMsg *msg = add_node_error(codegen, node,
3186 buf_sprintf("redefinition of '%s'", buf_ptr(name)));3186 buf_sprintf("redefinition of '%s'", buf_ptr(name)));
...@@ -3676,7 +3676,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -3676,7 +3676,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
3676 return ir_build_load_ptr(irb, scope, node, var_ptr);3676 return ir_build_load_ptr(irb, scope, node, var_ptr);
3677 }3677 }
36783678
3679 Tld *tld = find_decl(scope, variable_name);3679 Tld *tld = find_decl(irb->codegen, scope, variable_name);
3680 if (tld)3680 if (tld)
3681 return ir_gen_decl_ref(irb, node, tld, lval, scope);3681 return ir_gen_decl_ref(irb, node, tld, lval, scope);
36823682
...@@ -4210,7 +4210,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4210,7 +4210,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4210 return irb->codegen->invalid_instruction;4210 return irb->codegen->invalid_instruction;
4211 }4211 }
4212 Buf *variable_name = arg0_node->data.symbol_expr.symbol;4212 Buf *variable_name = arg0_node->data.symbol_expr.symbol;
4213 Tld *tld = find_decl(scope, variable_name);4213 Tld *tld = find_decl(irb->codegen, scope, variable_name);
4214 if (!tld) {4214 if (!tld) {
4215 add_node_error(irb->codegen, node, buf_sprintf("use of undeclared identifier '%s'",4215 add_node_error(irb->codegen, node, buf_sprintf("use of undeclared identifier '%s'",
4216 buf_ptr(variable_name)));4216 buf_ptr(variable_name)));
...@@ -9333,19 +9333,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -9333,19 +9333,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
93339333
9334 ImportTableEntry *namespace_import = namespace_val->data.x_import;9334 ImportTableEntry *namespace_import = namespace_val->data.x_import;
93359335
9336 Tld *tld = find_decl(&namespace_import->decls_scope->base, field_name);9336 Tld *tld = find_decl(ira->codegen, &namespace_import->decls_scope->base, field_name);
9337 if (!tld) {
9338 // we must now resolve all the use decls
9339 // TODO move this check to find_decl?
9340 for (size_t i = 0; i < namespace_import->use_decls.length; i += 1) {
9341 AstNode *use_decl_node = namespace_import->use_decls.at(i);
9342 if (use_decl_node->data.use.resolution == TldResolutionUnresolved) {
9343 preview_use_decl(ira->codegen, use_decl_node);
9344 }
9345 resolve_use_decl(ira->codegen, use_decl_node);
9346 }
9347 tld = find_decl(&namespace_import->decls_scope->base, field_name);
9348 }
9349 if (tld) {9337 if (tld) {
9350 if (tld->visib_mod == VisibModPrivate &&9338 if (tld->visib_mod == VisibModPrivate &&
9351 tld->import != source_node->owner)9339 tld->import != source_node->owner)