From d8a0a69a443588e8f2c0341278a78def5473084e Mon Sep 17 00:00:00 2001 From: Jerome St-Louis Date: Tue, 16 Jun 2015 04:12:30 -0400 Subject: [PATCH] ide/designer/CodeEditor: Clean up de-duplications - This may also fix memory leaks? --- ide/src/designer/CodeEditor.ec | 83 ++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 47 deletions(-) diff --git a/ide/src/designer/CodeEditor.ec b/ide/src/designer/CodeEditor.ec index 3405eb0..1518338 100644 --- a/ide/src/designer/CodeEditor.ec +++ b/ide/src/designer/CodeEditor.ec @@ -2185,9 +2185,6 @@ class CodeEditor : Window classes.Delete(oClass); } - if(windowClass && windowClass.data) - UnapplySkin(windowClass); - FreeParser(); if(sheet.codeEditor == this) @@ -2626,19 +2623,25 @@ class CodeEditor : Window ****************************************************************************/ void FreeParser() { + { + Class windowClass = eSystem_FindClass(privateModule, "ecere::gui::Window"); + if(windowClass && windowClass.data) + UnapplySkin(windowClass); + } + SetCurrentNameSpace(null); - if(ast != null) + if(ast) { FreeASTTree(ast); ast = null; } - this.defines.Free(FreeModuleDefine); - this.imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created + defines.Free(FreeModuleDefine); + imports.Free(FreeModuleImport); // Moved this after FreeAST because Debug printing causes ModuleImports to be created - FreeExcludedSymbols(this.excludedSymbols); - FreeContext(this.globalContext); + FreeExcludedSymbols(excludedSymbols); + FreeContext(globalContext); FreeIncludeFiles(); - FreeGlobalData(&this.globalData); + FreeGlobalData(&globalData); FindCtx_Terminate(); FindParams_Terminate(); @@ -2654,11 +2657,26 @@ class CodeEditor : Window SetPrivateModule(null); } + // Note: This code should probably be merged with FreeParser() + if(ast) + { + FreeASTTree(ast); + ast = null; + //SetAST(null); + } + defines.Free(FreeModuleDefine); + imports.Free(FreeModuleImport); + + FreeContext(this.globalContext); + FreeExcludedSymbols(this.excludedSymbols); + + FreeIncludeFiles(); + FreeGlobalData(&this.globalData); + if(this.privateModule) { FreeTypeData(this.privateModule); delete this.privateModule; - this.privateModule = null; } } @@ -2721,18 +2739,6 @@ class CodeEditor : Window editBox.GetSelPos(&l1, &y1, &x1, &l2, &y2, &x2, false); - FindCtx_Terminate(); - FindParams_Terminate(); - - SetGlobalData(&globalData); - SetGlobalContext(globalContext); - SetExcludedSymbols(&excludedSymbols); - SetTopContext(globalContext); - SetCurrentContext(globalContext); - SetDefines(&defines); - SetImports(&imports); - SetCurrentNameSpace(null); - /* sprintf(command, "C:\\Program Files\\Microsoft Visual Studio\\VC98\\Bin\\cl " "/nologo /D \"MSC\" /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /D \"_MBCS\" " @@ -2821,38 +2827,21 @@ class CodeEditor : Window this.oClass = null; } - { - Class windowClass = eSystem_FindClass(this.privateModule, "ecere::gui::Window"); - if(windowClass && windowClass.data) - UnapplySkin(windowClass); - } - designer = backDesigner; SetEchoOn(true); fileInput = editFile = EditBoxStream { editBox = editBox }; SetFileInput(fileInput); - if(ast) - { - FreeASTTree(ast); - ast = null; - //SetAST(null); - } - defines.Free(FreeModuleDefine); - imports.Free(FreeModuleImport); - - FreeContext(this.globalContext); - FreeExcludedSymbols(this.excludedSymbols); - - FreeIncludeFiles(); - FreeGlobalData(&this.globalData); + FreeParser(); - if(this.privateModule) - { - FreeTypeData(this.privateModule); - delete this.privateModule; - } + SetGlobalData(&globalData); + SetGlobalContext(globalContext); + SetExcludedSymbols(&excludedSymbols); + SetTopContext(globalContext); + SetCurrentContext(globalContext); + SetDefines(&defines); + SetImports(&imports); #ifdef _TIMINGS startTime = GetTime(); -- 1.8.3.1