From a2230639232c069e4052a2e994dd5c0bd4e2517f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 31 Aug 2019 10:38:18 -0400 Subject: `@typeOf` now guarantees no runtime side effects related: #1627 --- src/analyze.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/analyze.cpp') 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(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(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) { -- cgit v1.2.3