aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/ASTUnit.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-09-02 00:18:52 +0000
committerDouglas Gregor <dgregor@apple.com>2011-09-02 00:18:52 +0000
commitbcfd1f55bfbb3e5944cd5e03d07b343e280838c4 (patch)
tree838fe1b34f86ca6cbebba50b771d5f6556988440 /lib/Frontend/ASTUnit.cpp
parent998b3d3e8528ebd9d2c5d78d3a82edd90a8953a4 (diff)
Extend the ASTContext constructor to delay the initialization of
builtin types (When requested). This is another step toward making ASTUnit build the ASTContext as needed when loading an AST file, rather than doing so after the fact. No actual functionality change (yet). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138985 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/ASTUnit.cpp')
-rw-r--r--lib/Frontend/ASTUnit.cpp47
1 files changed, 25 insertions, 22 deletions
diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 370e1a9b14..34a6dabf64 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -377,6 +377,7 @@ namespace {
/// a Preprocessor.
class ASTInfoCollector : public ASTReaderListener {
Preprocessor &PP;
+ ASTContext &Context;
LangOptions &LangOpt;
HeaderSearch &HSI;
llvm::IntrusiveRefCntPtr<TargetInfo> &Target;
@@ -385,26 +386,30 @@ class ASTInfoCollector : public ASTReaderListener {
unsigned NumHeaderInfos;
- bool InitializedPreprocessor;
+ bool InitializedLanguage;
public:
- ASTInfoCollector(Preprocessor &PP,
- LangOptions &LangOpt, HeaderSearch &HSI,
+ ASTInfoCollector(Preprocessor &PP, ASTContext &Context, LangOptions &LangOpt,
+ HeaderSearch &HSI,
llvm::IntrusiveRefCntPtr<TargetInfo> &Target,
std::string &Predefines,
unsigned &Counter)
- : PP(PP), LangOpt(LangOpt), HSI(HSI), Target(Target),
+ : PP(PP), Context(Context), LangOpt(LangOpt), HSI(HSI), Target(Target),
Predefines(Predefines), Counter(Counter), NumHeaderInfos(0),
- InitializedPreprocessor(false) {}
+ InitializedLanguage(false) {}
virtual bool ReadLanguageOptions(const LangOptions &LangOpts) {
- if (InitializedPreprocessor)
+ if (InitializedLanguage)
return false;
LangOpt = LangOpts;
// Initialize the preprocessor.
PP.Initialize(*Target);
- InitializedPreprocessor = true;
+
+ // Initialize the ASTContext
+ Context.InitBuiltinTypes(*Target);
+
+ InitializedLanguage = true;
return false;
}
@@ -607,6 +612,17 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
/*IILookup=*/0,
/*OwnsHeaderSearch=*/false,
/*DelayInitialization=*/true);
+ Preprocessor &PP = *AST->PP;
+
+ AST->Ctx = new ASTContext(AST->ASTFileLangOpts,
+ AST->getSourceManager(),
+ /*Target=*/0,
+ PP.getIdentifierTable(),
+ PP.getSelectorTable(),
+ PP.getBuiltinInfo(),
+ /* size_reserve = */0,
+ /*DelayInitialization=*/true);
+ ASTContext &Context = *AST->Ctx;
Reader.reset(new ASTReader(AST->getSourceManager(), AST->getFileManager(),
AST->getDiagnostics()));
@@ -615,7 +631,7 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
llvm::CrashRecoveryContextCleanupRegistrar<ASTReader>
ReaderCleanup(Reader.get());
- Reader->setListener(new ASTInfoCollector(*AST->PP,
+ Reader->setListener(new ASTInfoCollector(*AST->PP, Context,
AST->ASTFileLangOpts, HeaderInfo,
AST->Target, Predefines, Counter));
@@ -631,26 +647,13 @@ ASTUnit *ASTUnit::LoadFromASTFile(const std::string &Filename,
AST->OriginalSourceFile = Reader->getOriginalSourceFile();
- // AST file loaded successfully. Now create the preprocessor.
- Preprocessor &PP = *AST->PP;
-
PP.setPredefines(Reader->getSuggestedPredefines());
PP.setCounterValue(Counter);
Reader->setPreprocessor(PP);
// Create and initialize the ASTContext.
-
- AST->Ctx = new ASTContext(AST->ASTFileLangOpts,
- AST->getSourceManager(),
- *AST->Target,
- PP.getIdentifierTable(),
- PP.getSelectorTable(),
- PP.getBuiltinInfo(),
- /* size_reserve = */0);
- ASTContext &Context = *AST->Ctx;
-
Reader->InitializeContext(Context);
-
+
// Attach the AST reader to the AST context as an external AST
// source, so that declarations will be deserialized from the
// AST file as needed.