forked from OSchip/llvm-project
clang-cc: Factor out code for creating one of the standard AST consumer actions.
llvm-svn: 82106
This commit is contained in:
parent
d112f103e7
commit
691b9337a6
|
@ -1734,55 +1734,36 @@ static llvm::raw_ostream *ComputeOutFile(const std::string &InFile,
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ProcessInputFile - Process a single input file with the specified state.
|
static ASTConsumer *CreateConsumerAction(Preprocessor &PP,
|
||||||
///
|
const std::string &InFile,
|
||||||
static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
|
ProgActions PA,
|
||||||
const std::string &InFile, ProgActions PA,
|
llvm::OwningPtr<llvm::raw_ostream> &OS,
|
||||||
const llvm::StringMap<bool> &Features,
|
llvm::sys::Path &OutPath,
|
||||||
llvm::LLVMContext& Context) {
|
const llvm::StringMap<bool> &Features,
|
||||||
llvm::OwningPtr<llvm::raw_ostream> OS;
|
llvm::LLVMContext& Context) {
|
||||||
llvm::OwningPtr<ASTConsumer> Consumer;
|
|
||||||
bool ClearSourceMgr = false;
|
|
||||||
FixItRewriter *FixItRewrite = 0;
|
|
||||||
bool CompleteTranslationUnit = true;
|
|
||||||
llvm::sys::Path OutPath;
|
|
||||||
|
|
||||||
switch (PA) {
|
switch (PA) {
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Unexpected program action!\n");
|
return 0;
|
||||||
HadErrors = true;
|
|
||||||
return;
|
|
||||||
|
|
||||||
case ASTPrint:
|
case ASTPrint:
|
||||||
OS.reset(ComputeOutFile(InFile, 0, false, OutPath));
|
OS.reset(ComputeOutFile(InFile, 0, false, OutPath));
|
||||||
Consumer.reset(CreateASTPrinter(OS.get()));
|
return CreateASTPrinter(OS.get());
|
||||||
break;
|
|
||||||
|
|
||||||
case ASTPrintXML:
|
case ASTPrintXML:
|
||||||
OS.reset(ComputeOutFile(InFile, "xml", false, OutPath));
|
OS.reset(ComputeOutFile(InFile, "xml", false, OutPath));
|
||||||
Consumer.reset(CreateASTPrinterXML(OS.get()));
|
return CreateASTPrinterXML(OS.get());
|
||||||
break;
|
|
||||||
|
|
||||||
case ASTDump:
|
case ASTDump:
|
||||||
Consumer.reset(CreateASTDumper());
|
return CreateASTDumper();
|
||||||
break;
|
|
||||||
|
|
||||||
case ASTView:
|
case ASTView:
|
||||||
Consumer.reset(CreateASTViewer());
|
return CreateASTViewer();
|
||||||
break;
|
|
||||||
|
|
||||||
case PrintDeclContext:
|
case PrintDeclContext:
|
||||||
Consumer.reset(CreateDeclContextPrinter());
|
return CreateDeclContextPrinter();
|
||||||
break;
|
|
||||||
|
|
||||||
case EmitHTML:
|
|
||||||
OS.reset(ComputeOutFile(InFile, 0, true, OutPath));
|
|
||||||
Consumer.reset(CreateHTMLPrinter(OS.get(), PP.getDiagnostics(), &PP, &PPF));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case InheritanceView:
|
case InheritanceView:
|
||||||
Consumer.reset(CreateInheritanceViewer(InheritanceViewCls));
|
return CreateInheritanceViewer(InheritanceViewCls);
|
||||||
break;
|
|
||||||
|
|
||||||
case EmitAssembly:
|
case EmitAssembly:
|
||||||
case EmitLLVM:
|
case EmitLLVM:
|
||||||
|
@ -1804,12 +1785,58 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
|
||||||
|
|
||||||
CompileOptions Opts;
|
CompileOptions Opts;
|
||||||
InitializeCompileOptions(Opts, PP.getLangOptions(), Features);
|
InitializeCompileOptions(Opts, PP.getLangOptions(), Features);
|
||||||
Consumer.reset(CreateBackendConsumer(Act, PP.getDiagnostics(),
|
return CreateBackendConsumer(Act, PP.getDiagnostics(), PP.getLangOptions(),
|
||||||
PP.getLangOptions(), Opts, InFile,
|
Opts, InFile, OS.get(), Context);
|
||||||
OS.get(), Context));
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case RewriteObjC:
|
||||||
|
OS.reset(ComputeOutFile(InFile, "cpp", true, OutPath));
|
||||||
|
return CreateObjCRewriter(InFile, OS.get(), PP.getDiagnostics(),
|
||||||
|
PP.getLangOptions(), SilenceRewriteMacroWarning);
|
||||||
|
|
||||||
|
case RewriteBlocks:
|
||||||
|
return CreateBlockRewriter(InFile, PP.getDiagnostics(),
|
||||||
|
PP.getLangOptions());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ProcessInputFile - Process a single input file with the specified state.
|
||||||
|
///
|
||||||
|
static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
|
||||||
|
const std::string &InFile, ProgActions PA,
|
||||||
|
const llvm::StringMap<bool> &Features,
|
||||||
|
llvm::LLVMContext& Context) {
|
||||||
|
llvm::OwningPtr<llvm::raw_ostream> OS;
|
||||||
|
llvm::OwningPtr<ASTConsumer> Consumer;
|
||||||
|
bool ClearSourceMgr = false;
|
||||||
|
FixItRewriter *FixItRewrite = 0;
|
||||||
|
bool CompleteTranslationUnit = true;
|
||||||
|
llvm::sys::Path OutPath;
|
||||||
|
|
||||||
|
switch (PA) {
|
||||||
|
default:
|
||||||
|
Consumer.reset(CreateConsumerAction(PP, InFile, PA, OS, OutPath,
|
||||||
|
Features, Context));
|
||||||
|
|
||||||
|
if (!Consumer.get()) {
|
||||||
|
fprintf(stderr, "Unexpected program action!\n");
|
||||||
|
HadErrors = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;;
|
||||||
|
|
||||||
|
case EmitHTML:
|
||||||
|
OS.reset(ComputeOutFile(InFile, 0, true, OutPath));
|
||||||
|
Consumer.reset(CreateHTMLPrinter(OS.get(), PP.getDiagnostics(), &PP, &PPF));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case RunAnalysis:
|
||||||
|
Consumer.reset(CreateAnalysisConsumer(PP.getDiagnostics(), &PP, &PPF,
|
||||||
|
PP.getLangOptions(), OutputFile,
|
||||||
|
ReadAnalyzerOptions()));
|
||||||
|
break;
|
||||||
|
|
||||||
case GeneratePCH:
|
case GeneratePCH:
|
||||||
if (RelocatablePCH.getValue() && !isysroot.getNumOccurrences()) {
|
if (RelocatablePCH.getValue() && !isysroot.getNumOccurrences()) {
|
||||||
PP.Diag(SourceLocation(), diag::err_relocatable_without_without_isysroot);
|
PP.Diag(SourceLocation(), diag::err_relocatable_without_without_isysroot);
|
||||||
|
@ -1824,25 +1851,6 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
|
||||||
CompleteTranslationUnit = false;
|
CompleteTranslationUnit = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RewriteObjC:
|
|
||||||
OS.reset(ComputeOutFile(InFile, "cpp", true, OutPath));
|
|
||||||
Consumer.reset(CreateObjCRewriter(InFile, OS.get(), PP.getDiagnostics(),
|
|
||||||
PP.getLangOptions(),
|
|
||||||
SilenceRewriteMacroWarning));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RewriteBlocks:
|
|
||||||
Consumer.reset(CreateBlockRewriter(InFile, PP.getDiagnostics(),
|
|
||||||
PP.getLangOptions()));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RunAnalysis: {
|
|
||||||
Consumer.reset(CreateAnalysisConsumer(PP.getDiagnostics(), &PP, &PPF,
|
|
||||||
PP.getLangOptions(), OutputFile,
|
|
||||||
ReadAnalyzerOptions()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case DumpRawTokens: {
|
case DumpRawTokens: {
|
||||||
llvm::TimeRegion Timer(ClangFrontendTimer);
|
llvm::TimeRegion Timer(ClangFrontendTimer);
|
||||||
SourceManager &SM = PP.getSourceManager();
|
SourceManager &SM = PP.getSourceManager();
|
||||||
|
|
Loading…
Reference in New Issue