diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-08-31 10:38:18 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-08-31 11:00:31 -0400 |
| commit | a2230639232c069e4052a2e994dd5c0bd4e2517f (patch) | |
| tree | e8bdb0438078f740d1509ded7e4b67162e7ac8e8 /src/analyze.cpp | |
| parent | 6ab8b2aab4b146a7d1d882686199eace19989011 (diff) | |
| download | zig-a2230639232c069e4052a2e994dd5c0bd4e2517f.tar.gz zig-a2230639232c069e4052a2e994dd5c0bd4e2517f.zip | |
`@typeOf` now guarantees no runtime side effects
related: #1627
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 43c8d499db..df5b27784a 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -197,6 +197,12 @@ Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent) { return &scope->base; } +Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent) { + ScopeTypeOf *scope = allocate<ScopeTypeOf>(1); + init_scope(g, &scope->base, ScopeIdTypeOf, node, parent); + return &scope->base; +} + ZigType *get_scope_import(Scope *scope) { while (scope) { if (scope->id == ScopeIdDecls) { @@ -209,6 +215,22 @@ ZigType *get_scope_import(Scope *scope) { zig_unreachable(); } +ScopeTypeOf *get_scope_typeof(Scope *scope) { + while (scope) { + switch (scope->id) { + case ScopeIdTypeOf: + return reinterpret_cast<ScopeTypeOf *>(scope); + case ScopeIdFnDef: + case ScopeIdDecls: + return nullptr; + default: + scope = scope->parent; + continue; + } + } + zig_unreachable(); +} + static ZigType *new_container_type_entry(CodeGen *g, ZigTypeId id, AstNode *source_node, Scope *parent_scope, Buf *bare_name) { |
