Fix the destruction "properly" in the sense that we actually destroy the
ASTs. This is a hack, but I haven't considered how we really want to do this. llvm-svn: 51364
This commit is contained in:
parent
0883bfb541
commit
b158b4a47b
|
@ -44,7 +44,10 @@ public:
|
|||
~SerializationTest();
|
||||
|
||||
virtual void Initialize(ASTContext& context) {
|
||||
if (!TU) TU.reset(new TranslationUnit(context, lopts));
|
||||
if (!TU) {
|
||||
TU.reset(new TranslationUnit(context, lopts));
|
||||
TU->SetOwnsDecls(false);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void HandleTopLevelDecl(Decl *D) {
|
||||
|
|
|
@ -35,13 +35,18 @@ class TranslationUnit {
|
|||
ASTContext* Context;
|
||||
std::vector<Decl*> TopLevelDecls;
|
||||
bool OwnsMetaData;
|
||||
bool OwnsDecls;
|
||||
|
||||
// The default ctor is only invoked during deserialization.
|
||||
explicit TranslationUnit() : Context(NULL), OwnsMetaData(true) {}
|
||||
explicit TranslationUnit() : Context(NULL), OwnsMetaData(true),
|
||||
OwnsDecls(true) {}
|
||||
|
||||
public:
|
||||
explicit TranslationUnit(ASTContext& Ctx, const LangOptions& lopt)
|
||||
: LangOpts(lopt), Context(&Ctx), OwnsMetaData(false) {}
|
||||
: LangOpts(lopt), Context(&Ctx), OwnsMetaData(false),
|
||||
OwnsDecls(true) {}
|
||||
|
||||
void SetOwnsDecls(bool val) { OwnsDecls = val; }
|
||||
|
||||
~TranslationUnit();
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ enum { BasicMetadataBlock = 1,
|
|||
DeclsBlock = 3 };
|
||||
|
||||
TranslationUnit::~TranslationUnit() {
|
||||
if (OwnsMetaData && Context) {
|
||||
if (OwnsDecls) {
|
||||
llvm::DenseSet<Decl*> Killed;
|
||||
for (iterator I=begin(), E=end(); I!=E; ++I) {
|
||||
if (Killed.count(*I)) continue;
|
||||
|
@ -39,10 +39,13 @@ TranslationUnit::~TranslationUnit() {
|
|||
Killed.insert(*I);
|
||||
(*I)->Destroy(*Context);
|
||||
}
|
||||
}
|
||||
|
||||
if (OwnsMetaData && Context) {
|
||||
// The ASTContext object has the sole references to the IdentifierTable
|
||||
// Selectors, and the Target information. Go and delete them, since
|
||||
// the TranslationUnit effectively owns them.
|
||||
|
||||
delete &(Context->Idents);
|
||||
delete &(Context->Selectors);
|
||||
delete &(Context->Target);
|
||||
|
|
Loading…
Reference in New Issue