[cfe-commits] r86827 - in /cfe/trunk: include/clang/Frontend/PreprocessorOutputOptions.h include/clang/Frontend/Utils.h lib/Frontend/PrintPreprocessedOutput.cpp tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Wed Nov 11 02:07:24 PST 2009


Author: ddunbar
Date: Wed Nov 11 04:07:22 2009
New Revision: 86827

URL: http://llvm.org/viewvc/llvm-project?rev=86827&view=rev
Log:
Add PreprocessorOutputOptions, for things like -dM, -C, -CC which control -E
mode.

Added:
    cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h
Modified:
    cfe/trunk/include/clang/Frontend/Utils.h
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Added: cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h?rev=86827&view=auto

==============================================================================
--- cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h (added)
+++ cfe/trunk/include/clang/Frontend/PreprocessorOutputOptions.h Wed Nov 11 04:07:22 2009
@@ -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

Modified: cfe/trunk/include/clang/Frontend/Utils.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/Utils.h?rev=86827&r1=86826&r2=86827&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/Utils.h (original)
+++ cfe/trunk/include/clang/Frontend/Utils.h Wed Nov 11 04:07:22 2009
@@ -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 MinimalAction;
 class Preprocessor;
 class PreprocessorOptions;
+class PreprocessorOutputOptions;
 class SourceManager;
 class Stmt;
 class TargetInfo;
@@ -56,15 +57,9 @@
                            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);

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=86827&r1=86826&r2=86827&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Wed Nov 11 04:07:22 2009
@@ -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 @@
   };
 }
 
-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 @@
 /// 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));

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=86827&r1=86826&r2=86827&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Nov 11 04:07:22 2009
@@ -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 @@
 
   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;
   }
 





More information about the cfe-commits mailing list