[cfe-commits] r38570 - /cfe/cfe/trunk/Driver/clang.cpp

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:22:48 PDT 2007


Author: sabre
Date: Wed Jul 11 11:22:48 2007
New Revision: 38570

URL: http://llvm.org/viewvc/llvm-project?rev=38570&view=rev
Log:
Print out unknown pragmas in -E mode.

Modified:
    cfe/cfe/trunk/Driver/clang.cpp

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=38570&r1=38569&r2=38570&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:22:48 2007
@@ -23,6 +23,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Pragma.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/SourceBuffer.h"
@@ -699,6 +700,27 @@
     std::cout << ' ';
 }
 
+struct UnknownPragmaHandler : public PragmaHandler {
+  const char *Prefix;
+  UnknownPragmaHandler(const char *prefix) : PragmaHandler(0), Prefix(prefix) {}
+  virtual void HandlePragma(Preprocessor &PP, LexerToken &PragmaTok) {
+    // Figure out what line we went to and insert the appropriate number of
+    // newline characters.
+    MoveToLine(PP.getSourceManager().getLineNumber(PragmaTok.getLocation()));
+    std::cout << Prefix;
+    
+    // Read and print all of the pragma tokens.
+    while (PragmaTok.getKind() != tok::eom) {
+      if (PragmaTok.hasLeadingSpace())
+        std::cout << ' ';
+      std::cout << PP.getSpelling(PragmaTok);
+      PP.Lex(PragmaTok);
+    }
+    std::cout << "\n";
+  }
+};
+
+
 /// DoPrintPreprocessedInput - This implements -E mode.
 void DoPrintPreprocessedInput(Preprocessor &PP) {
   LexerToken Tok;
@@ -709,6 +731,8 @@
   EModePP = &PP;
   EmodeEmittedTokensOnThisLine = false;
   
+  PP.AddPragmaHandler(0, new UnknownPragmaHandler("#pragma"));
+  PP.AddPragmaHandler("GCC", new UnknownPragmaHandler("#pragma GCC"));
   do {
     PP.Lex(Tok);
 





More information about the cfe-commits mailing list