[cfe-commits] r114814 - in /cfe/trunk: lib/Lex/Pragma.cpp test/Lexer/pragma-message.c
Michael J. Spencer
bigcheesegs at gmail.com
Sun Sep 26 23:19:02 PDT 2010
Author: mspencer
Date: Mon Sep 27 01:19:02 2010
New Revision: 114814
URL: http://llvm.org/viewvc/llvm-project?rev=114814&view=rev
Log:
Lexer: Implement GCC's version of pragma message.
Added:
cfe/trunk/test/Lexer/pragma-message.c
Modified:
cfe/trunk/lib/Lex/Pragma.cpp
Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=114814&r1=114813&r2=114814&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Mon Sep 27 01:19:02 2010
@@ -483,23 +483,32 @@
Callbacks->PragmaComment(CommentLoc, II, ArgumentString);
}
-/// HandlePragmaMessage - Handle the microsoft #pragma message extension. The
-/// syntax is:
-/// #pragma message(messagestring)
-/// messagestring is a string, which is fully macro expanded, and permits string
-/// concatenation, embedded escape characters etc. See MSDN for more details.
+/// HandlePragmaMessage - Handle the microsoft and gcc #pragma message
+/// extension. The syntax is:
+/// #pragma message(string)
+/// OR, in GCC mode:
+/// #pragma message string
+/// string is a string, which is fully macro expanded, and permits string
+/// concatenation, embedded escape characters, etc... See MSDN for more details.
void Preprocessor::HandlePragmaMessage(Token &Tok) {
SourceLocation MessageLoc = Tok.getLocation();
Lex(Tok);
- if (Tok.isNot(tok::l_paren)) {
+ bool ExpectClosingParen = false;
+ switch(Tok.getKind()) {
+ case tok::l_paren:
+ // We have a MSVC style pragma message.
+ ExpectClosingParen = true;
+ // Read the string.
+ Lex(Tok);
+ break;
+ case tok::string_literal:
+ // We have a GCC style pragma message, and we just read the string.
+ break;
+ default:
Diag(MessageLoc, diag::err_pragma_message_malformed);
return;
}
- // Read the string.
- Lex(Tok);
-
-
// We need at least one string.
if (Tok.isNot(tok::string_literal)) {
Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
@@ -527,11 +536,13 @@
llvm::StringRef MessageString(Literal.GetString(), Literal.GetStringLength());
- if (Tok.isNot(tok::r_paren)) {
- Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
- return;
+ if (ExpectClosingParen) {
+ if (Tok.isNot(tok::r_paren)) {
+ Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
+ return;
+ }
+ Lex(Tok); // eat the r_paren.
}
- Lex(Tok); // eat the r_paren.
if (Tok.isNot(tok::eom)) {
Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
@@ -1001,6 +1012,7 @@
AddPragmaHandler(new PragmaMarkHandler());
AddPragmaHandler(new PragmaPushMacroHandler());
AddPragmaHandler(new PragmaPopMacroHandler());
+ AddPragmaHandler(new PragmaMessageHandler());
// #pragma GCC ...
AddPragmaHandler("GCC", new PragmaPoisonHandler());
@@ -1022,6 +1034,5 @@
// MS extensions.
if (Features.Microsoft) {
AddPragmaHandler(new PragmaCommentHandler());
- AddPragmaHandler(new PragmaMessageHandler());
}
}
Added: cfe/trunk/test/Lexer/pragma-message.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/pragma-message.c?rev=114814&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/pragma-message.c (added)
+++ cfe/trunk/test/Lexer/pragma-message.c Mon Sep 27 01:19:02 2010
@@ -0,0 +1,14 @@
+/* Test pragma message directive from
+ http://msdn.microsoft.com/en-us/library/x7dkzch2.aspx */
+
+// message: Sends a string literal to the standard output without terminating
+// the compilation.
+// #pragma message(messagestring)
+// OR
+// #pragma message messagestring
+//
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+#define STRING2(x) #x
+#define STRING(x) STRING2(x)
+#pragma message(":O I'm a message! " STRING(__LINE__)) // expected-warning {{:O I'm a message! 13}}
+#pragma message ":O gcc accepts this! " STRING(__LINE__) // expected-warning {{:O gcc accepts this! 14}}
More information about the cfe-commits
mailing list