]> granicus.if.org Git - clang/commitdiff
Move options for -E mode from PrintPreprocessedOutput.cpp to
authorEli Friedman <eli.friedman@gmail.com>
Tue, 19 May 2009 03:06:47 +0000 (03:06 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 19 May 2009 03:06:47 +0000 (03:06 +0000)
clang-cc.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72095 91177308-0d34-0410-b5e6-96231b3b80d8

tools/clang-cc/PrintPreprocessedOutput.cpp
tools/clang-cc/clang-cc.cpp
tools/clang-cc/clang-cc.h

index 23a728c0b041b47458d8f280d093f21a7b9621ce..429b8296490f00f2b0dc66a918ef96a2c4252c0a 100644 (file)
@@ -81,22 +81,6 @@ static void PrintMacroDefinition(const IdentifierInfo &II, const MacroInfo &MI,
 // Preprocessed token printer
 //===----------------------------------------------------------------------===//
 
-static llvm::cl::opt<bool>
-DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
-static llvm::cl::opt<bool>
-EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
-static llvm::cl::opt<bool>
-EnableMacroCommentOutput("CC",
-                         llvm::cl::desc("Enable comment output in -E mode, "
-                                        "even from macro expansions"));
-static llvm::cl::opt<bool>
-DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
-                                " normal output"));
-
-static llvm::cl::opt<bool>
-DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
-                                "addition to normal output"));
-
 namespace {
 class PrintPPOutputPPCallbacks : public PPCallbacks {
   Preprocessor &PP;
@@ -109,9 +93,13 @@ private:
   SrcMgr::CharacteristicKind FileType;
   llvm::SmallString<512> CurFilename;
   bool Initialized;
+  bool DisableLineMarkers;
+  bool DumpDefines;
 public:
-  PrintPPOutputPPCallbacks(Preprocessor &pp, llvm::raw_ostream &os)
-     : PP(pp), ConcatInfo(PP), OS(os) {
+  PrintPPOutputPPCallbacks(Preprocessor &pp, llvm::raw_ostream &os,
+                           bool lineMarkers, bool defines)
+     : PP(pp), ConcatInfo(PP), OS(os), DisableLineMarkers(lineMarkers),
+       DumpDefines(defines) {
     CurLine = 0;
     CurFilename += "<uninit>";
     EmittedTokensOnThisLine = false;
@@ -441,19 +429,19 @@ void clang::DoPrintMacros(Preprocessor &PP, llvm::raw_ostream *OS) {
 
 /// DoPrintPreprocessedInput - This implements -E mode.
 ///
-void clang::DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream *OS) {
-  if (DumpMacros) {
-    DoPrintMacros(PP, OS);
-    return;
-  }
-
+void clang::DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream *OS,
+                                     bool EnableCommentOutput,
+                                     bool EnableMacroCommentOutput,
+                                     bool DisableLineMarkers,
+                                     bool DumpDefines) {
   // Inform the preprocessor whether we want it to retain comments or not, due
   // to -C or -CC.
   PP.SetCommentRetentionState(EnableCommentOutput, EnableMacroCommentOutput);
 
   OS->SetBufferSize(64*1024);
 
-  PrintPPOutputPPCallbacks *Callbacks = new PrintPPOutputPPCallbacks(PP, *OS);
+  PrintPPOutputPPCallbacks *Callbacks =
+      new PrintPPOutputPPCallbacks(PP, *OS, DisableLineMarkers, DumpDefines);
   PP.AddPragmaHandler(0, new UnknownPragmaHandler("#pragma", Callbacks));
   PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC",
                                                       Callbacks));
index 81a819e38d2c7358984ecffd78b3b1a9c1d64014..669c47815e3b14a4674c987c8339f99124b05cec 100644 (file)
@@ -1510,6 +1510,23 @@ static llvm::cl::opt<bool> OptPedantic("pedantic");
 static llvm::cl::opt<bool> OptPedanticErrors("pedantic-errors");
 static llvm::cl::opt<bool> OptNoWarnings("w");
 
+//===----------------------------------------------------------------------===//
+// Preprocessing (-E mode) Options
+//===----------------------------------------------------------------------===//
+static llvm::cl::opt<bool>
+DisableLineMarkers("P", llvm::cl::desc("Disable linemarker output in -E mode"));
+static llvm::cl::opt<bool>
+EnableCommentOutput("C", llvm::cl::desc("Enable comment output in -E mode"));
+static llvm::cl::opt<bool>
+EnableMacroCommentOutput("CC",
+                         llvm::cl::desc("Enable comment output in -E mode, "
+                                        "even from macro expansions"));
+static llvm::cl::opt<bool>
+DumpMacros("dM", llvm::cl::desc("Print macro definitions in -E mode instead of"
+                                " normal output"));
+static llvm::cl::opt<bool>
+DumpDefines("dD", llvm::cl::desc("Print macro definitions in -E mode in "
+                                "addition to normal output"));
 //===----------------------------------------------------------------------===//
 // -dump-build-information Stuff
 //===----------------------------------------------------------------------===//
@@ -1930,7 +1947,12 @@ static void ProcessInputFile(Preprocessor &PP, PreprocessorFactory &PPF,
     ClearSourceMgr = true;
   } else if (PA == PrintPreprocessedInput){  // -E mode.
     llvm::TimeRegion Timer(ClangFrontendTimer);
-    DoPrintPreprocessedInput(PP, OS.get());
+    if (DumpMacros)
+      DoPrintMacros(PP, OS.get());
+    else
+      DoPrintPreprocessedInput(PP, OS.get(), EnableCommentOutput,
+                               EnableMacroCommentOutput,
+                               DisableLineMarkers, DumpDefines);
     ClearSourceMgr = true;
   }
   
index b9c0f11811b76d179e759f7feef1aaaef821d0d7..0322d2e905abdeacf08ab83c2625a1c6b0df9624 100644 (file)
@@ -44,7 +44,11 @@ bool ProcessWarningOptions(Diagnostic &Diags,
 void DoPrintMacros(Preprocessor &PP, llvm::raw_ostream* OS);
 
 /// DoPrintPreprocessedInput - Implement -E mode.
-void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS);
+void DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream* OS,
+                              bool EnableCommentOutput,
+                              bool EnableMacroCommentOutput,
+                              bool DisableLineMarkers,
+                              bool DumpDefines);
 
 /// RewriteMacrosInInput - Implement -rewrite-macros mode.
 void RewriteMacrosInInput(Preprocessor &PP, llvm::raw_ostream* OS);