~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) {
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();
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;
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);