clang-cc: Refactor ParseInputFollow to clearly split on the two primary cases,

when we are running an AST consumer and when we are just running the
preprocessor or parser alone.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86937 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar 2009-11-12 02:53:27 +00:00
Родитель 975790e8f8
Коммит d1e7a964c6
1 изменённых файлов: 110 добавлений и 100 удалений

Просмотреть файл

@ -756,7 +756,7 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
llvm::OwningPtr<ExternalASTSource> Source;
const std::string &ImplicitPCHInclude =
CompOpts.getPreprocessorOpts().getImplicitPCHInclude();
if (Consumer)
if (Consumer) {
ContextOwner.reset(new ASTContext(PP.getLangOptions(),
PP.getSourceManager(),
PP.getTargetInfo(),
@ -765,14 +765,20 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
PP.getBuiltinInfo(),
/* FreeMemory = */ !DisableFree,
/* size_reserve = */0));
if (Consumer && !ImplicitPCHInclude.empty()) {
Source.reset(ReadPCHFile(ImplicitPCHInclude, CompOpts, PP, *ContextOwner));
if (!ImplicitPCHInclude.empty()) {
Source.reset(ReadPCHFile(ImplicitPCHInclude, CompOpts, PP,
*ContextOwner));
if (!Source)
return;
// 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.
ContextOwner->setExternalSource(Source);
} else {
// Initialize builtin info when not using PCH.
PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
PP.getLangOptions().NoBuiltin);
}
// Initialize the main file entry. This needs to be delayed until after PCH
@ -780,13 +786,6 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
if (InitializeSourceManager(PP, InFile))
return;
// Initialize builtin info unless we are using PCH.
if (!Consumer || ImplicitPCHInclude.empty())
PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
PP.getLangOptions().NoBuiltin);
// If we have an ASTConsumer, run the parser with it.
if (Consumer) {
CodeCompleteConsumer *(*CreateCodeCompleter)(Sema &, void *) = 0;
void *CreateCodeCompleterData = 0;
@ -807,14 +806,24 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
}
}
// Run the AST consumer action.
ParseAST(PP, Consumer.get(), *ContextOwner.get(), Stats,
CompleteTranslationUnit,
CreateCodeCompleter, CreateCodeCompleterData);
}
} else {
// Initialize builtin info.
PP.getBuiltinInfo().InitializeBuiltins(PP.getIdentifierTable(),
PP.getLangOptions().NoBuiltin);
// Perform post processing actions and actions which don't use a consumer.
// Initialize the main file entry. This needs to be delayed until after PCH
// has loaded.
if (InitializeSourceManager(PP, InFile))
return;
// Run the preprocessor actions.
switch (PA) {
default: break;
default:
assert(0 && "unexpected program action");
case DumpRawTokens: {
llvm::TimeRegion Timer(ClangFrontendTimer);
@ -904,6 +913,7 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
}
}
}
if (FixItRewrite)
FixItRewrite->WriteFixedFile(InFile, CompOpts.getOutputFile());