forked from OSchip/llvm-project
Add PreprocessorOutputOptions, for things like -dM, -C, -CC which control -E
mode. llvm-svn: 86827
This commit is contained in:
parent
979586e755
commit
531f6c662b
|
@ -0,0 +1,40 @@
|
|||
//===--- PreprocessorOutputOptions.h ----------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_CLANG_FRONTEND_PREPROCESSOROUTPUTOPTIONS_H
|
||||
#define LLVM_CLANG_FRONTEND_PREPROCESSOROUTPUTOPTIONS_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace clang {
|
||||
|
||||
/// PreprocessorOutputOptions - Options for controlling the C preprocessor
|
||||
/// output (e.g., -E).
|
||||
class PreprocessorOutputOptions {
|
||||
public:
|
||||
unsigned ShowCPP : 1; ///< Print normal preprocessed output.
|
||||
unsigned ShowMacros : 1; ///< Print macro definitions.
|
||||
unsigned ShowLineMarkers : 1; ///< Show #line markers.
|
||||
unsigned ShowComments : 1; /// Show comments.
|
||||
unsigned ShowMacroComments : 1; /// Show comments, even in macros.
|
||||
|
||||
public:
|
||||
PreprocessorOutputOptions() {
|
||||
ShowCPP = 1;
|
||||
ShowMacros = 0;
|
||||
ShowLineMarkers = 1;
|
||||
ShowComments = 0;
|
||||
ShowMacroComments = 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace clang
|
||||
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
//===--- Utils.h - Misc utilities for the front-end------------------------===//
|
||||
//===--- Utils.h - Misc utilities for the front-end -------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
|
@ -34,6 +34,7 @@ class LangOptions;
|
|||
class MinimalAction;
|
||||
class Preprocessor;
|
||||
class PreprocessorOptions;
|
||||
class PreprocessorOutputOptions;
|
||||
class SourceManager;
|
||||
class Stmt;
|
||||
class TargetInfo;
|
||||
|
@ -56,15 +57,9 @@ bool ProcessWarningOptions(Diagnostic &Diags,
|
|||
bool Pedantic, bool PedanticErrors,
|
||||
bool NoWarnings);
|
||||
|
||||
/// DoPrintPreprocessedInput - Implement -E -dM mode.
|
||||
void DoPrintMacros(Preprocessor &PP, llvm::raw_ostream* OS);
|
||||
|
||||
/// DoPrintPreprocessedInput - Implement -E mode.
|
||||
void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS,
|
||||
bool EnableCommentOutput,
|
||||
bool EnableMacroCommentOutput,
|
||||
bool DisableLineMarkers,
|
||||
bool DumpDefines);
|
||||
PreprocessorOutputOptions &Opts);
|
||||
|
||||
/// RewriteMacrosInInput - Implement -rewrite-macros mode.
|
||||
void RewriteMacrosInInput(Preprocessor &PP, llvm::raw_ostream* OS);
|
||||
|
|
|
@ -13,13 +13,14 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "clang/Frontend/Utils.h"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Frontend/PreprocessorOutputOptions.h"
|
||||
#include "clang/Lex/MacroInfo.h"
|
||||
#include "clang/Lex/PPCallbacks.h"
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
#include "clang/Lex/Pragma.h"
|
||||
#include "clang/Lex/Preprocessor.h"
|
||||
#include "clang/Lex/TokenConcatenation.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Basic/Diagnostic.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Config/config.h"
|
||||
|
@ -439,7 +440,7 @@ namespace {
|
|||
};
|
||||
}
|
||||
|
||||
void clang::DoPrintMacros(Preprocessor &PP, llvm::raw_ostream *OS) {
|
||||
static void DoPrintMacros(Preprocessor &PP, llvm::raw_ostream *OS) {
|
||||
// -dM mode just scans and ignores all tokens in the files, then dumps out
|
||||
// the macro table at the end.
|
||||
PP.EnterMainSourceFile();
|
||||
|
@ -467,18 +468,23 @@ void clang::DoPrintMacros(Preprocessor &PP, llvm::raw_ostream *OS) {
|
|||
/// DoPrintPreprocessedInput - This implements -E mode.
|
||||
///
|
||||
void clang::DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream *OS,
|
||||
bool EnableCommentOutput,
|
||||
bool EnableMacroCommentOutput,
|
||||
bool DisableLineMarkers,
|
||||
bool DumpDefines) {
|
||||
PreprocessorOutputOptions &Opts) {
|
||||
// Show macros with no output is handled specially.
|
||||
if (!Opts.ShowCPP) {
|
||||
assert(Opts.ShowMacros && "Not yet implemented!");
|
||||
DoPrintMacros(PP, OS);
|
||||
return;
|
||||
}
|
||||
|
||||
// Inform the preprocessor whether we want it to retain comments or not, due
|
||||
// to -C or -CC.
|
||||
PP.SetCommentRetentionState(EnableCommentOutput, EnableMacroCommentOutput);
|
||||
PP.SetCommentRetentionState(Opts.ShowComments, Opts.ShowMacroComments);
|
||||
|
||||
OS->SetBufferSize(64*1024);
|
||||
|
||||
PrintPPOutputPPCallbacks *Callbacks =
|
||||
new PrintPPOutputPPCallbacks(PP, *OS, DisableLineMarkers, DumpDefines);
|
||||
new PrintPPOutputPPCallbacks(PP, *OS, !Opts.ShowLineMarkers,
|
||||
Opts.ShowMacros);
|
||||
PP.AddPragmaHandler(0, new UnknownPragmaHandler("#pragma", Callbacks));
|
||||
PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC",
|
||||
Callbacks));
|
||||
|
|
|
@ -16,36 +16,37 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "Options.h"
|
||||
#include "clang/Frontend/AnalysisConsumer.h"
|
||||
#include "clang/AST/ASTConsumer.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/AST/DeclGroup.h"
|
||||
#include "clang/Analysis/PathDiagnostic.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Basic/TargetInfo.h"
|
||||
#include "clang/Basic/Version.h"
|
||||
#include "clang/CodeGen/ModuleBuilder.h"
|
||||
#include "clang/Frontend/ASTConsumers.h"
|
||||
#include "clang/Frontend/ASTUnit.h"
|
||||
#include "clang/Frontend/AnalysisConsumer.h"
|
||||
#include "clang/Frontend/ChainedDiagnosticClient.h"
|
||||
#include "clang/Frontend/CommandLineSourceLoc.h"
|
||||
#include "clang/Frontend/CompilerInvocation.h"
|
||||
#include "clang/Frontend/FixItRewriter.h"
|
||||
#include "clang/Frontend/FrontendDiagnostic.h"
|
||||
#include "clang/Frontend/PCHReader.h"
|
||||
#include "clang/Frontend/PathDiagnosticClients.h"
|
||||
#include "clang/Frontend/PreprocessorOptions.h"
|
||||
#include "clang/Frontend/PreprocessorOutputOptions.h"
|
||||
#include "clang/Frontend/TextDiagnosticBuffer.h"
|
||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
||||
#include "clang/Frontend/CommandLineSourceLoc.h"
|
||||
#include "clang/Frontend/Utils.h"
|
||||
#include "clang/Analysis/PathDiagnostic.h"
|
||||
#include "clang/CodeGen/ModuleBuilder.h"
|
||||
#include "clang/Lex/HeaderSearch.h"
|
||||
#include "clang/Lex/LexDiagnostic.h"
|
||||
#include "clang/Parse/Parser.h"
|
||||
#include "clang/Sema/CodeCompleteConsumer.h"
|
||||
#include "clang/Sema/ParseAST.h"
|
||||
#include "clang/Sema/SemaDiagnostic.h"
|
||||
#include "clang/AST/ASTConsumer.h"
|
||||
#include "clang/AST/ASTContext.h"
|
||||
#include "clang/AST/Decl.h"
|
||||
#include "clang/AST/DeclGroup.h"
|
||||
#include "clang/Parse/Parser.h"
|
||||
#include "clang/Lex/HeaderSearch.h"
|
||||
#include "clang/Lex/LexDiagnostic.h"
|
||||
#include "clang/Basic/FileManager.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Basic/TargetInfo.h"
|
||||
#include "clang/Basic/Version.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
|
@ -919,12 +920,13 @@ static void ProcessInputFile(const CompilerInvocation &CompOpts,
|
|||
|
||||
case PrintPreprocessedInput: {
|
||||
llvm::TimeRegion Timer(ClangFrontendTimer);
|
||||
if (DumpMacros)
|
||||
DoPrintMacros(PP, OS.get());
|
||||
else
|
||||
DoPrintPreprocessedInput(PP, OS.get(), EnableCommentOutput,
|
||||
EnableMacroCommentOutput,
|
||||
DisableLineMarkers, DumpDefines);
|
||||
PreprocessorOutputOptions Opts;
|
||||
Opts.ShowCPP = !DumpMacros;
|
||||
Opts.ShowMacros = DumpMacros || DumpDefines;
|
||||
Opts.ShowLineMarkers = !DisableLineMarkers;
|
||||
Opts.ShowComments = EnableCommentOutput;
|
||||
Opts.ShowMacroComments = EnableMacroCommentOutput;
|
||||
DoPrintPreprocessedInput(PP, OS.get(), Opts);
|
||||
ClearSourceMgr = true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue