aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-08-13 03:15:25 +0000
committerDouglas Gregor <dgregor@apple.com>2010-08-13 03:15:25 +0000
commit914ed9d30e9abf829a62aa996b083b1e47c19ff6 (patch)
treec4b14f63594026cdb22db9e0927c6c7be7027743 /lib/Frontend/ASTUnit.cpp
parent40db2991d746a2901d6441cee261552a20a4a48a (diff)
Teach ASTUnit to hold on to the Sema object and ASTConsumer that are
used when parsing (or re-parsing) a file. Also, when loading a precompiled header into ASTUnit, create a Sema object that holds onto semantic-analysis information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@111003 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTUnit.cpp')
-rw-r--r--lib/Frontend/ASTUnit.cpp17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index bbe2ec5bea..b56a0d83a8 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -204,7 +204,7 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
AST->FileMgr.reset(new FileManager);
AST->SourceMgr.reset(new SourceManager(AST->getDiagnostics()));
AST->HeaderInfo.reset(new HeaderSearch(AST->getFileManager()));
-
+
// If requested, capture diagnostics in the ASTUnit.
CaptureDroppedDiagnostics Capture(CaptureDiagnostics, AST->getDiagnostics(),
AST->StoredDiagnostics);
@@ -237,7 +237,6 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
unsigned Counter;
llvm::OwningPtr<PCHReader> Reader;
- llvm::OwningPtr<ExternalASTSource> Source;
Reader.reset(new PCHReader(AST->getSourceManager(), AST->getFileManager(),
AST->getDiagnostics()));
@@ -294,9 +293,18 @@ ASTUnit *ASTUnit::LoadFromPCHFile(const std::string &Filename,
// Attach the PCH reader to the AST context as an external AST
// source, so that declarations will be deserialized from the
// PCH file as needed.
- Source.reset(Reader.take());
+ PCHReader *ReaderPtr = Reader.get();
+ llvm::OwningPtr<ExternalASTSource> Source(Reader.take());
Context.setExternalSource(Source);
+ // Create an AST consumer, even though it isn't used.
+ AST->Consumer.reset(new ASTConsumer);
+
+ // Create a semantic analysis object and tell the PCH reader about it.
+ AST->TheSema.reset(new Sema(PP, Context, *AST->Consumer));
+ AST->TheSema->Initialize();
+ ReaderPtr->InitializeSema(*AST->TheSema);
+
return AST.take();
}
@@ -458,6 +466,7 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
// FIXME: Should we retain the previous file manager?
FileMgr.reset(new FileManager);
SourceMgr.reset(new SourceManager(getDiagnostics()));
+ TheSema.reset();
Ctx.reset();
PP.reset();
@@ -513,6 +522,8 @@ bool ASTUnit::Parse(llvm::MemoryBuffer *OverrideMainBuffer) {
// Steal the created target, context, and preprocessor, and take back the
// source and file managers.
+ TheSema.reset(Clang.takeSema());
+ Consumer.reset(Clang.takeASTConsumer());
Ctx.reset(Clang.takeASTContext());
PP.reset(Clang.takePreprocessor());
Clang.takeSourceManager();