[cfe-commits] r45212 - in /cfe/trunk: Lex/Pragma.cpp include/clang/Lex/Preprocessor.h test/Lexer/pragma-mark.c
Chris Lattner
sabre at nondot.org
Wed Dec 19 11:38:37 PST 2007
Author: lattner
Date: Wed Dec 19 13:38:36 2007
New Revision: 45212
URL: http://llvm.org/viewvc/llvm-project?rev=45212&view=rev
Log:
Add support for #pragma mark, which shouldn't warn about bogus tokens.
Added:
cfe/trunk/test/Lexer/pragma-mark.c
Modified:
cfe/trunk/Lex/Pragma.cpp
cfe/trunk/include/clang/Lex/Preprocessor.h
Modified: cfe/trunk/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Pragma.cpp?rev=45212&r1=45211&r2=45212&view=diff
==============================================================================
--- cfe/trunk/Lex/Pragma.cpp (original)
+++ cfe/trunk/Lex/Pragma.cpp Wed Dec 19 13:38:36 2007
@@ -177,6 +177,12 @@
HeaderInfo.MarkFileIncludeOnce(SourceMgr.getFileEntryForLoc(FileLoc));
}
+void Preprocessor::HandlePragmaMark() {
+ assert(CurLexer && "No current lexer?");
+ CurLexer->ReadToEndOfLine();
+}
+
+
/// HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'.
///
void Preprocessor::HandlePragmaPoison(Token &PoisonTok) {
@@ -323,6 +329,7 @@
}
namespace {
+/// PragmaOnceHandler - "#pragma once" marks the file as atomically included.
struct PragmaOnceHandler : public PragmaHandler {
PragmaOnceHandler(const IdentifierInfo *OnceID) : PragmaHandler(OnceID) {}
virtual void HandlePragma(Preprocessor &PP, Token &OnceTok) {
@@ -331,6 +338,16 @@
}
};
+/// PragmaMarkHandler - "#pragma mark ..." is ignored by the compiler, and the
+/// rest of the line is not lexed.
+struct PragmaMarkHandler : public PragmaHandler {
+ PragmaMarkHandler(const IdentifierInfo *MarkID) : PragmaHandler(MarkID) {}
+ virtual void HandlePragma(Preprocessor &PP, Token &MarkTok) {
+ PP.HandlePragmaMark();
+ }
+};
+
+/// PragmaPoisonHandler - "#pragma poison x" marks x as not usable.
struct PragmaPoisonHandler : public PragmaHandler {
PragmaPoisonHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
virtual void HandlePragma(Preprocessor &PP, Token &PoisonTok) {
@@ -338,6 +355,8 @@
}
};
+/// PragmaSystemHeaderHandler - "#pragma system_header" marks the current file
+/// as a system header, which silences warnings in it.
struct PragmaSystemHeaderHandler : public PragmaHandler {
PragmaSystemHeaderHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
virtual void HandlePragma(Preprocessor &PP, Token &SHToken) {
@@ -358,6 +377,7 @@
/// #pragma GCC poison/system_header/dependency and #pragma once.
void Preprocessor::RegisterBuiltinPragmas() {
AddPragmaHandler(0, new PragmaOnceHandler(getIdentifierInfo("once")));
+ AddPragmaHandler(0, new PragmaMarkHandler(getIdentifierInfo("mark")));
AddPragmaHandler("GCC", new PragmaPoisonHandler(getIdentifierInfo("poison")));
AddPragmaHandler("GCC", new PragmaSystemHeaderHandler(
getIdentifierInfo("system_header")));
Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=45212&r1=45211&r2=45212&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Wed Dec 19 13:38:36 2007
@@ -494,6 +494,7 @@
void HandlePragmaDirective();
public:
void HandlePragmaOnce(Token &OnceTok);
+ void HandlePragmaMark();
void HandlePragmaPoison(Token &PoisonTok);
void HandlePragmaSystemHeader(Token &SysHeaderTok);
void HandlePragmaDependency(Token &DependencyTok);
Added: cfe/trunk/test/Lexer/pragma-mark.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/pragma-mark.c?rev=45212&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/pragma-mark.c (added)
+++ cfe/trunk/test/Lexer/pragma-mark.c Wed Dec 19 13:38:36 2007
@@ -0,0 +1,11 @@
+// RUN: clang %s -fsyntax-only -verify
+
+// Lexer diagnostics shouldn't be included in #pragma mark.
+#pragma mark Mike's world
+_Pragma("mark foo ' bar")
+
+#define X(S) _Pragma(S)
+X("mark foo ' bar")
+
+int i;
+
More information about the cfe-commits
mailing list