diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-05-20 04:49:55 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-05-20 04:49:55 +0000 |
commit | d1ac17ae7d61a9244ee5e658d6f63b8fa3da3127 (patch) | |
tree | 68c6c66d893d473e1b664ed7fa7b63121030df90 /lib/AST/Decl.cpp | |
parent | f809e3bd0c3d063f22ba34981072dae306ca9272 (diff) |
Reclaim memory from chains of ScopedDecls, and reclaim memory for the initializers of EnumConstantDecls.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51299 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index c75fb8b674..02d86a32fc 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -226,6 +226,15 @@ NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC, return new (Mem) NamespaceDecl(DC, L, Id); } +void NamespaceDecl::Destroy(ASTContext& C) { + // NamespaceDecl uses "NextDeclarator" to chain namespace declarations + // together. They are all top-level Decls. + + this->~Decl(); + C.getAllocator().Deallocate((void *)this); +} + + VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, @@ -267,6 +276,11 @@ EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD, return new (Mem) EnumConstantDecl(CD, L, Id, T, E, V, PrevDecl); } +void EnumConstantDecl::Destroy(ASTContext& C) { + if (Init) Init->Destroy(C); + Decl::Destroy(C); +} + TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L, IdentifierInfo *Id, QualType T, @@ -289,6 +303,12 @@ RecordDecl *RecordDecl::Create(ASTContext &C, Kind DK, DeclContext *DC, return new (Mem) RecordDecl(DK, DC, L, Id, PrevDecl); } +void EnumDecl::Destroy(ASTContext& C) { + if (ElementList) ElementList->Destroy(C); + Decl::Destroy(C); +} + + FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, SourceLocation L, StringLiteral *Str) { @@ -370,6 +390,23 @@ void Decl::swapAttrs(Decl *RHS) { void Decl::Destroy(ASTContext& C) { + + if (ScopedDecl* SD = dyn_cast<ScopedDecl>(this)) { + + // Observe the unrolled recursion. By setting N->NextDeclarator = 0x0 + // within the loop, only the Destroy method for the first ScopedDecl + // will deallocate all of the ScopedDecls in a chain. + + ScopedDecl* N = SD->getNextDeclarator(); + + while (N) { + ScopedDecl* Tmp = N->getNextDeclarator(); + N->NextDeclarator = 0x0; + N->Destroy(C); + N = Tmp; + } + } + this->~Decl(); C.getAllocator().Deallocate((void *)this); } |