| ... | @@ -6423,7 +6423,6 @@ fn identifier( | ... | @@ -6423,7 +6423,6 @@ fn identifier( |
| 6423 | | 6423 | |
| 6424 | const astgen = gz.astgen; | 6424 | const astgen = gz.astgen; |
| 6425 | const tree = astgen.tree; | 6425 | const tree = astgen.tree; |
| 6426 | const gpa = astgen.gpa; | | |
| 6427 | const main_tokens = tree.nodes.items(.main_token); | 6426 | const main_tokens = tree.nodes.items(.main_token); |
| 6428 | | 6427 | |
| 6429 | const ident_token = main_tokens[ident]; | 6428 | const ident_token = main_tokens[ident]; |
| ... | @@ -6467,6 +6466,19 @@ fn identifier( | ... | @@ -6467,6 +6466,19 @@ fn identifier( |
| 6467 | } | 6466 | } |
| 6468 | | 6467 | |
| 6469 | // Local variables, including function parameters. | 6468 | // Local variables, including function parameters. |
| | 6469 | return localVarRef(gz, scope, rl, ident, ident_token); |
| | 6470 | } |
| | 6471 | |
| | 6472 | fn localVarRef( |
| | 6473 | gz: *GenZir, |
| | 6474 | scope: *Scope, |
| | 6475 | rl: ResultLoc, |
| | 6476 | ident: Ast.Node.Index, |
| | 6477 | ident_token: Ast.Node.Index, |
| | 6478 | ) InnerError!Zir.Inst.Ref { |
| | 6479 | const astgen = gz.astgen; |
| | 6480 | const gpa = astgen.gpa; |
| | 6481 | |
| 6470 | const name_str_index = try astgen.identAsString(ident_token); | 6482 | const name_str_index = try astgen.identAsString(ident_token); |
| 6471 | var s = scope; | 6483 | var s = scope; |
| 6472 | var found_already: ?Ast.Node.Index = null; // we have found a decl with the same name already | 6484 | var found_already: ?Ast.Node.Index = null; // we have found a decl with the same name already |
| ... | @@ -6808,43 +6820,13 @@ fn asmExpr( | ... | @@ -6808,43 +6820,13 @@ fn asmExpr( |
| 6808 | }; | 6820 | }; |
| 6809 | } else { | 6821 | } else { |
| 6810 | const ident_token = symbolic_name + 4; | 6822 | const ident_token = symbolic_name + 4; |
| 6811 | const str_index = try astgen.identAsString(ident_token); | 6823 | // TODO have a look at #215 and related issues and decide how to |
| 6812 | // TODO this needs extra code for local variables. Have a look at #215 and related | 6824 | // handle outputs. Do we want this to be identifiers? |
| 6813 | // issues and decide how to handle outputs. Do we want this to be identifiers? | | |
| 6814 | // Or maybe we want to force this to be expressions with a pointer type. | 6825 | // Or maybe we want to force this to be expressions with a pointer type. |
| 6815 | // Until that is figured out this is only hooked up for referencing Decls. | | |
| 6816 | // TODO we have put this as an identifier lookup just so that we don't get | | |
| 6817 | // unused vars for outputs. We need to check if this is correct in the future ^^ | | |
| 6818 | // so we just put in this simple lookup. This is a workaround. | | |
| 6819 | { | | |
| 6820 | var s = scope; | | |
| 6821 | while (true) switch (s.tag) { | | |
| 6822 | .local_val => { | | |
| 6823 | const local_val = s.cast(Scope.LocalVal).?; | | |
| 6824 | if (local_val.name == str_index) { | | |
| 6825 | local_val.used = true; | | |
| 6826 | break; | | |
| 6827 | } | | |
| 6828 | s = local_val.parent; | | |
| 6829 | }, | | |
| 6830 | .local_ptr => { | | |
| 6831 | const local_ptr = s.cast(Scope.LocalPtr).?; | | |
| 6832 | if (local_ptr.name == str_index) { | | |
| 6833 | local_ptr.used = true; | | |
| 6834 | break; | | |
| 6835 | } | | |
| 6836 | s = local_ptr.parent; | | |
| 6837 | }, | | |
| 6838 | .gen_zir => s = s.cast(GenZir).?.parent, | | |
| 6839 | .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent, | | |
| 6840 | .namespace, .top => break, | | |
| 6841 | }; | | |
| 6842 | } | | |
| 6843 | const operand = try gz.addStrTok(.decl_ref, str_index, ident_token); | | |
| 6844 | outputs[i] = .{ | 6826 | outputs[i] = .{ |
| 6845 | .name = name, | 6827 | .name = name, |
| 6846 | .constraint = constraint, | 6828 | .constraint = constraint, |
| 6847 | .operand = operand, | 6829 | .operand = try localVarRef(gz, scope, rl, node, ident_token), |
| 6848 | }; | 6830 | }; |
| 6849 | } | 6831 | } |
| 6850 | } | 6832 | } |