summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-05-21 16:38:54 +0000
committerTed Kremenek <kremenek@apple.com>2008-05-21 16:38:54 +0000
commita2157719becedb8df0b344110b790de47cde79d8 (patch)
treed7eaf632b29f77360c4554b2d1898047d0cd1063 /clang
parent8f83fc4d9b8161717f939f27cf824dc094d26e6c (diff)
downloadbcm5719-llvm-a2157719becedb8df0b344110b790de47cde79d8.tar.gz
bcm5719-llvm-a2157719becedb8df0b344110b790de47cde79d8.zip
Add Destroy method to Types, making there destruction more harmonious with
the destruction of Decls and Stmts. llvm-svn: 51385
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/Type.h8
-rw-r--r--clang/lib/AST/ASTContext.cpp8
-rw-r--r--clang/lib/AST/Type.cpp13
3 files changed, 20 insertions, 9 deletions
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 65863666253..431eec03e02 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -244,7 +244,8 @@ protected:
Type(TypeClass tc, QualType Canonical)
: CanonicalType(Canonical.isNull() ? QualType(this_(), 0) : Canonical),
TC(tc) {}
- virtual ~Type();
+ virtual ~Type() {};
+ virtual void Destroy(ASTContext& C);
friend class ASTContext;
void EmitTypeInternal(llvm::Serializer& S) const;
@@ -722,6 +723,8 @@ class VariableArrayType : public ArrayType {
ArraySizeModifier sm, unsigned tq)
: ArrayType(VariableArray, et, can, sm, tq), SizeExpr(e) {}
friend class ASTContext; // ASTContext creates these.
+ virtual void Destroy(ASTContext& C);
+
public:
const Expr *getSizeExpr() const { return SizeExpr; }
Expr *getSizeExpr() { return SizeExpr; }
@@ -916,7 +919,10 @@ class FunctionTypeProto : public FunctionType, public llvm::FoldingSetNode {
/// ArgInfo - There is an variable size array after the class in memory that
/// holds the argument types.
+
friend class ASTContext; // ASTContext creates these.
+ virtual void Destroy(ASTContext& C);
+
public:
unsigned getNumArgs() const { return NumArgs; }
QualType getArgType(unsigned i) const {
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 3165ad065b2..923aab291db 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -29,13 +29,7 @@ enum FloatingRank {
ASTContext::~ASTContext() {
// Deallocate all the types.
while (!Types.empty()) {
- if (FunctionTypeProto *FT = dyn_cast<FunctionTypeProto>(Types.back())) {
- // Destroy the object, but don't call delete. These are malloc'd.
- FT->~FunctionTypeProto();
- free(FT);
- } else {
- delete Types.back();
- }
+ Types.back()->Destroy(*this);
Types.pop_back();
}
}
diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp
index 741d59bc766..e561a1074ce 100644
--- a/clang/lib/AST/Type.cpp
+++ b/clang/lib/AST/Type.cpp
@@ -22,7 +22,18 @@
#include <sstream>
using namespace clang;
-Type::~Type() {}
+void Type::Destroy(ASTContext& C) { delete this; }
+
+void FunctionTypeProto::Destroy(ASTContext& C) {
+ // Destroy the object, but don't call delete. These are malloc'd.
+ this->~FunctionTypeProto();
+ free(this);
+}
+
+void VariableArrayType::Destroy(ASTContext& C) {
+ SizeExpr->Destroy(C);
+ delete this;
+}
/// isVoidType - Helper method to determine if this is the 'void' type.
bool Type::isVoidType() const {
OpenPOWER on IntegriCloud