diff --git a/src/analysis/run.d b/src/analysis/run.d index 06ce9e3..291c8e2 100644 --- a/src/analysis/run.d +++ b/src/analysis/run.d @@ -199,18 +199,21 @@ const(Module) parseModule(string fileName, ubyte[] code, RollbackAllocator* p, MessageSet analyze(string fileName, const Module m, const StaticAnalysisConfig analysisConfig, ref ModuleCache moduleCache, const(Token)[] tokens, bool staticAnalyze = true) { + import dsymbol.symbol : DSymbol; + if (!staticAnalyze) return null; - auto symbolAllocator = new ASTAllocator; + auto symbolAllocator = scoped!ASTAllocator(); auto first = scoped!FirstPass(m, internString(fileName), symbolAllocator, symbolAllocator, true, &moduleCache, null); first.run(); secondPass(first.rootSymbol, first.moduleScope, moduleCache); - typeid(SemanticSymbol).destroy(first.rootSymbol); - const(Scope)* moduleScope = first.moduleScope; - + auto moduleScope = first.moduleScope; + scope(exit) typeid(DSymbol).destroy(first.rootSymbol.acSymbol); + scope(exit) typeid(SemanticSymbol).destroy(first.rootSymbol); + scope(exit) typeid(Scope).destroy(first.moduleScope); BaseAnalyzer[] checks; if (analysisConfig.asm_style_check) diff --git a/src/main.d b/src/main.d index 756f8fc..c418ec6 100644 --- a/src/main.d +++ b/src/main.d @@ -14,6 +14,7 @@ import std.path; import std.stdio; import std.range; import std.experimental.lexer; +import std.typecons : scoped; import dparse.lexer; import dparse.parser; import dparse.rollback_allocator; @@ -138,7 +139,8 @@ else const(string[]) absImportPaths = importPaths.map!(a => a.absolutePath() .buildNormalizedPath()).array(); - auto moduleCache = ModuleCache(new dsymbol.modulecache.ASTAllocator); + auto alloc = scoped!(dsymbol.modulecache.ASTAllocator)(); + auto moduleCache = ModuleCache(alloc); if (absImportPaths.length) moduleCache.addImportPaths(absImportPaths);