From 100158a3eaa2134b7802e19408f8c9cf9d2d49ba Mon Sep 17 00:00:00 2001 From: Dimitar Dobrev Date: Sun, 20 Dec 2015 00:12:50 +0200 Subject: [PATCH] Fixed minor memory leaks. Signed-off-by: Dimitar Dobrev --- src/Core/Parser/ASTConverter.cs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Core/Parser/ASTConverter.cs b/src/Core/Parser/ASTConverter.cs index ef9cab1e..707a354f 100644 --- a/src/Core/Parser/ASTConverter.cs +++ b/src/Core/Parser/ASTConverter.cs @@ -653,6 +653,8 @@ namespace CppSharp readonly CommentConverter commentConverter; readonly Dictionary Declarations; + readonly Dictionary PreprocessedEntities; + readonly Dictionary FunctionTemplateSpecializations; public DeclConverter(TypeConverter type, CommentConverter comment) { @@ -660,6 +662,8 @@ namespace CppSharp typeConverter = type; commentConverter = comment; Declarations = new Dictionary(); + PreprocessedEntities = new Dictionary(); + FunctionTemplateSpecializations = new Dictionary(); } public HashSet NativeObjects { get; private set; } @@ -957,7 +961,7 @@ namespace CppSharp expression = new AST.BuiltinTypeExpression(); break; } - expression.Declaration = typeConverter.declConverter.Visit(statement.Decl); + expression.Declaration = Visit(statement.Decl); expression.String = statement.String; return expression; @@ -1540,6 +1544,9 @@ namespace CppSharp private AST.FunctionTemplateSpecialization VisitFunctionTemplateSpecialization(FunctionTemplateSpecialization spec) { + if (FunctionTemplateSpecializations.ContainsKey(spec.__Instance)) + return FunctionTemplateSpecializations[spec.__Instance]; + var _spec = new AST.FunctionTemplateSpecialization(); _spec.Template = (AST.FunctionTemplate)Visit(spec.Template); _spec.SpecializedFunction = (AST.Function)Visit(spec.SpecializedFunction); @@ -1549,12 +1556,22 @@ namespace CppSharp var _arg = VisitTemplateArgument(spec.getArguments(i)); _spec.Arguments.Add(_arg); } + FunctionTemplateSpecializations.Add(spec.__Instance, _spec); + NativeObjects.Add(spec); return _spec; } void VisitPreprocessedEntity(PreprocessedEntity entity, AST.PreprocessedEntity _entity) { + if (PreprocessedEntities.ContainsKey(entity.__Instance)) + { + _entity.MacroLocation = PreprocessedEntities[entity.__Instance].MacroLocation; + return; + } + _entity.MacroLocation = VisitMacroLocation(entity.MacroLocation); + PreprocessedEntities.Add(entity.__Instance, _entity); + NativeObjects.Add(entity); } private AST.PreprocessedEntity VisitPreprocessedEntity(PreprocessedEntity entity) @@ -1563,11 +1580,9 @@ namespace CppSharp { case DeclarationKind.MacroDefinition: var macroDefinition = MacroDefinition.__CreateInstance(entity.__Instance); - NativeObjects.Add(macroDefinition); return VisitMacroDefinition(macroDefinition); case DeclarationKind.MacroExpansion: var macroExpansion = MacroExpansion.__CreateInstance(entity.__Instance); - NativeObjects.Add(macroExpansion); return VisitMacroExpansion(macroExpansion); default: throw new ArgumentOutOfRangeException("entity");