diff options
| author | Daniele Cocca <daniele.cocca@gmail.com> | 2022-03-19 12:00:07 +0000 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-03-30 11:57:15 +0300 |
| commit | 5d5282b5f18b33489187a9a9e23a1aa2d301b4e8 (patch) | |
| tree | c69a668a6a63c09f3e4cc35652c02477cf501d63 /src/AstGen.zig | |
| parent | c21f046a8b019c42aa0dbb0fb9c592b590edf977 (diff) | |
| download | zig-5d5282b5f18b33489187a9a9e23a1aa2d301b4e8.tar.gz zig-5d5282b5f18b33489187a9a9e23a1aa2d301b4e8.zip | |
AstGen: support local var references for outputs
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 50 |
1 files changed, 16 insertions, 34 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index ed6c9f86ce..296eb80e7c 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -6423,7 +6423,6 @@ fn identifier( const astgen = gz.astgen; const tree = astgen.tree; - const gpa = astgen.gpa; const main_tokens = tree.nodes.items(.main_token); const ident_token = main_tokens[ident]; @@ -6467,6 +6466,19 @@ fn identifier( } // Local variables, including function parameters. + return localVarRef(gz, scope, rl, ident, ident_token); +} + +fn localVarRef( + gz: *GenZir, + scope: *Scope, + rl: ResultLoc, + ident: Ast.Node.Index, + ident_token: Ast.Node.Index, +) InnerError!Zir.Inst.Ref { + const astgen = gz.astgen; + const gpa = astgen.gpa; + const name_str_index = try astgen.identAsString(ident_token); var s = scope; var found_already: ?Ast.Node.Index = null; // we have found a decl with the same name already @@ -6808,43 +6820,13 @@ fn asmExpr( }; } else { const ident_token = symbolic_name + 4; - const str_index = try astgen.identAsString(ident_token); - // TODO this needs extra code for local variables. Have a look at #215 and related - // issues and decide how to handle outputs. Do we want this to be identifiers? + // TODO have a look at #215 and related issues and decide how to + // handle outputs. Do we want this to be identifiers? // Or maybe we want to force this to be expressions with a pointer type. - // Until that is figured out this is only hooked up for referencing Decls. - // TODO we have put this as an identifier lookup just so that we don't get - // unused vars for outputs. We need to check if this is correct in the future ^^ - // so we just put in this simple lookup. This is a workaround. - { - var s = scope; - while (true) switch (s.tag) { - .local_val => { - const local_val = s.cast(Scope.LocalVal).?; - if (local_val.name == str_index) { - local_val.used = true; - break; - } - s = local_val.parent; - }, - .local_ptr => { - const local_ptr = s.cast(Scope.LocalPtr).?; - if (local_ptr.name == str_index) { - local_ptr.used = true; - break; - } - s = local_ptr.parent; - }, - .gen_zir => s = s.cast(GenZir).?.parent, - .defer_normal, .defer_error => s = s.cast(Scope.Defer).?.parent, - .namespace, .top => break, - }; - } - const operand = try gz.addStrTok(.decl_ref, str_index, ident_token); outputs[i] = .{ .name = name, .constraint = constraint, - .operand = operand, + .operand = try localVarRef(gz, scope, rl, node, ident_token), }; } } |
