From 2d8d681b5ee34663aa87f0583f7b1a012b17d5b4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 30 Apr 2021 11:07:31 -0700 Subject: stage2: un-tangle memory management of Decl and Namespace Before there was this "top_decl" and "tmp_namespace" stack values that were kludgy and buggy. Now Sema is slightly reworked so that files which are structs are analyzed with their own Decl and Namespace already set up. After this commit there are no memory leaks for a successful build-obj. --- src/value.zig | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/value.zig') diff --git a/src/value.zig b/src/value.zig index d2d7be3007..04608878c0 100644 --- a/src/value.zig +++ b/src/value.zig @@ -593,6 +593,14 @@ pub const Value = extern union { unreachable; } + /// Returns null if not a type or if the type has no namespace. + pub fn getTypeNamespace(self: Value) ?*Module.Scope.Namespace { + return switch (self.tag()) { + .ty => self.castTag(.ty).?.data.getNamespace(), + else => null, + }; + } + /// Asserts that the value is representable as a type. pub fn toType(self: Value, allocator: *Allocator) !Type { return switch (self.tag()) { -- cgit v1.2.3