]> granicus.if.org Git - clang/commitdiff
Make -E mode propagate #pragma comment's into the output.
authorChris Lattner <sabre@nondot.org>
Fri, 16 Jan 2009 19:25:54 +0000 (19:25 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 16 Jan 2009 19:25:54 +0000 (19:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62339 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/PrintPreprocessedOutput.cpp
test/Preprocessor/pragma_microsoft.c

index f5bde7c7c6dc9f283e5551c4beaa3665809cb9c3..9fc37d9f51f1f668d9479456958c8dc8ad4be40a 100644 (file)
@@ -67,7 +67,9 @@ public:
   virtual void FileChanged(SourceLocation Loc, FileChangeReason Reason,
                            SrcMgr::CharacteristicKind FileType);
   virtual void Ident(SourceLocation Loc, const std::string &str);
-  
+  virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, 
+                             const std::string &Str);
+
 
   bool HandleFirstTokOnLine(Token &Tok);
   bool MoveToLine(SourceLocation Loc);
@@ -186,7 +188,7 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
   }
 }
 
-/// HandleIdent - Handle #ident directives when read by the preprocessor.
+/// Ident - Handle #ident directives when read by the preprocessor.
 ///
 void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, const std::string &S) {
   MoveToLine(Loc);
@@ -196,6 +198,33 @@ void PrintPPOutputPPCallbacks::Ident(SourceLocation Loc, const std::string &S) {
   EmittedTokensOnThisLine = true;
 }
 
+void PrintPPOutputPPCallbacks::PragmaComment(SourceLocation Loc,
+                                             const IdentifierInfo *Kind, 
+                                             const std::string &Str) {
+  MoveToLine(Loc);
+  OS << "#pragma comment(" << Kind->getName();
+  
+  if (!Str.empty()) {
+    OS << ", \"";
+    
+    for (unsigned i = 0, e = Str.size(); i != e; ++i) {
+      unsigned char Char = Str[i];
+      if (isprint(Char) && Char != '\\')
+        OS << (char)Char;
+      else  // Output anything hard as an octal escape.
+        OS << '\\'
+           << (char)('0'+ ((Char >> 6) & 7))
+           << (char)('0'+ ((Char >> 3) & 7))
+           << (char)('0'+ ((Char >> 0) & 7));
+    }
+    OS << '"';
+  }
+  
+  OS << ')';
+  EmittedTokensOnThisLine = true;
+}
+
+
 /// HandleFirstTokOnLine - When emitting a preprocessed file in -E mode, this
 /// is called for the first token on each new line.  If this really is the start
 /// of a new logical line, handle it and return true, otherwise return false.
index 7a05bbcfcfc5e553b917e590a354ebcc73be708c..e05126d0dd7891d2e58d98baa0aea48e1d9cbf58 100644 (file)
@@ -13,6 +13,8 @@
 #pragma comment(foo)    // expected-error {{unknown kind of pragma comment}}
 #pragma comment(compiler,)     // expected-error {{pragma comment requires}}
 #define foo compiler
-#pragma comment(foo)   // macro expand kind?
+#pragma comment(foo)   // macro expand kind.
 #pragma comment(foo) x // expected-error {{pragma comment requires}}
 
+#pragma comment(user, "foo\abar\nbaz\tsome     thing")
+