blob: 18b46ad6116bf37025f6b795b35100865be64e51 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- Pragma.cpp - Pragma registration and handling --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PragmaHandler/PragmaTable interfaces and implements
11// pragma related methods of the Preprocessor class.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Lex/Pragma.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000016#include "clang/Lex/HeaderSearch.h"
Chris Lattnera9d91452009-01-16 18:59:23 +000017#include "clang/Lex/LiteralSupport.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000018#include "clang/Lex/Preprocessor.h"
Chris Lattner500d3292009-01-29 05:15:15 +000019#include "clang/Lex/LexDiagnostic.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "clang/Basic/FileManager.h"
21#include "clang/Basic/SourceManager.h"
Douglas Gregor2e222532009-07-02 17:08:52 +000022#include <algorithm>
Reid Spencer5f016e22007-07-11 17:01:13 +000023using namespace clang;
24
25// Out-of-line destructor to provide a home for the class.
26PragmaHandler::~PragmaHandler() {
27}
28
29//===----------------------------------------------------------------------===//
Daniel Dunbarc72cc502010-06-11 20:10:12 +000030// EmptyPragmaHandler Implementation.
31//===----------------------------------------------------------------------===//
32
33EmptyPragmaHandler::EmptyPragmaHandler() : PragmaHandler(0) {}
34
35void EmptyPragmaHandler::HandlePragma(Preprocessor &PP, Token &FirstToken) {}
36
37//===----------------------------------------------------------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +000038// PragmaNamespace Implementation.
39//===----------------------------------------------------------------------===//
40
41
42PragmaNamespace::~PragmaNamespace() {
43 for (unsigned i = 0, e = Handlers.size(); i != e; ++i)
44 delete Handlers[i];
45}
46
47/// FindHandler - Check to see if there is already a handler for the
48/// specified name. If not, return the handler for the null identifier if it
49/// exists, otherwise return null. If IgnoreNull is true (the default) then
50/// the null handler isn't returned on failure to match.
51PragmaHandler *PragmaNamespace::FindHandler(const IdentifierInfo *Name,
52 bool IgnoreNull) const {
53 PragmaHandler *NullHandler = 0;
54 for (unsigned i = 0, e = Handlers.size(); i != e; ++i) {
Mike Stump1eb44332009-09-09 15:08:12 +000055 if (Handlers[i]->getName() == Name)
Reid Spencer5f016e22007-07-11 17:01:13 +000056 return Handlers[i];
Mike Stump1eb44332009-09-09 15:08:12 +000057
Reid Spencer5f016e22007-07-11 17:01:13 +000058 if (Handlers[i]->getName() == 0)
59 NullHandler = Handlers[i];
60 }
61 return IgnoreNull ? 0 : NullHandler;
62}
63
Daniel Dunbar40950802008-10-04 19:17:46 +000064void PragmaNamespace::RemovePragmaHandler(PragmaHandler *Handler) {
65 for (unsigned i = 0, e = Handlers.size(); i != e; ++i) {
66 if (Handlers[i] == Handler) {
67 Handlers[i] = Handlers.back();
68 Handlers.pop_back();
69 return;
70 }
71 }
72 assert(0 && "Handler not registered in this namespace");
73}
74
Chris Lattnerd2177732007-07-20 16:59:19 +000075void PragmaNamespace::HandlePragma(Preprocessor &PP, Token &Tok) {
Reid Spencer5f016e22007-07-11 17:01:13 +000076 // Read the 'namespace' that the directive is in, e.g. STDC. Do not macro
77 // expand it, the user can have a STDC #define, that should not affect this.
78 PP.LexUnexpandedToken(Tok);
Mike Stump1eb44332009-09-09 15:08:12 +000079
Reid Spencer5f016e22007-07-11 17:01:13 +000080 // Get the handler for this token. If there is no handler, ignore the pragma.
81 PragmaHandler *Handler = FindHandler(Tok.getIdentifierInfo(), false);
Chris Lattneraf7cdf42009-04-19 21:10:26 +000082 if (Handler == 0) {
83 PP.Diag(Tok, diag::warn_pragma_ignored);
84 return;
85 }
Mike Stump1eb44332009-09-09 15:08:12 +000086
Reid Spencer5f016e22007-07-11 17:01:13 +000087 // Otherwise, pass it down.
88 Handler->HandlePragma(PP, Tok);
89}
90
91//===----------------------------------------------------------------------===//
92// Preprocessor Pragma Directive Handling.
93//===----------------------------------------------------------------------===//
94
95/// HandlePragmaDirective - The "#pragma" directive has been parsed. Lex the
96/// rest of the pragma, passing it to the registered pragma handlers.
97void Preprocessor::HandlePragmaDirective() {
98 ++NumPragma;
Mike Stump1eb44332009-09-09 15:08:12 +000099
Reid Spencer5f016e22007-07-11 17:01:13 +0000100 // Invoke the first level of pragma handlers which reads the namespace id.
Chris Lattnerd2177732007-07-20 16:59:19 +0000101 Token Tok;
Reid Spencer5f016e22007-07-11 17:01:13 +0000102 PragmaHandlers->HandlePragma(*this, Tok);
Mike Stump1eb44332009-09-09 15:08:12 +0000103
Reid Spencer5f016e22007-07-11 17:01:13 +0000104 // If the pragma handler didn't read the rest of the line, consume it now.
Chris Lattner027cff62009-06-18 05:55:53 +0000105 if (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective)
Reid Spencer5f016e22007-07-11 17:01:13 +0000106 DiscardUntilEndOfDirective();
107}
108
109/// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then
110/// return the first token after the directive. The _Pragma token has just
111/// been read into 'Tok'.
Chris Lattnerd2177732007-07-20 16:59:19 +0000112void Preprocessor::Handle_Pragma(Token &Tok) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000113 // Remember the pragma token location.
114 SourceLocation PragmaLoc = Tok.getLocation();
Mike Stump1eb44332009-09-09 15:08:12 +0000115
Reid Spencer5f016e22007-07-11 17:01:13 +0000116 // Read the '('.
117 Lex(Tok);
Chris Lattner3692b092008-11-18 07:59:24 +0000118 if (Tok.isNot(tok::l_paren)) {
119 Diag(PragmaLoc, diag::err__Pragma_malformed);
120 return;
121 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000122
123 // Read the '"..."'.
124 Lex(Tok);
Chris Lattner3692b092008-11-18 07:59:24 +0000125 if (Tok.isNot(tok::string_literal) && Tok.isNot(tok::wide_string_literal)) {
126 Diag(PragmaLoc, diag::err__Pragma_malformed);
127 return;
128 }
Mike Stump1eb44332009-09-09 15:08:12 +0000129
Reid Spencer5f016e22007-07-11 17:01:13 +0000130 // Remember the string.
131 std::string StrVal = getSpelling(Tok);
Reid Spencer5f016e22007-07-11 17:01:13 +0000132
133 // Read the ')'.
134 Lex(Tok);
Chris Lattner3692b092008-11-18 07:59:24 +0000135 if (Tok.isNot(tok::r_paren)) {
136 Diag(PragmaLoc, diag::err__Pragma_malformed);
137 return;
138 }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Chris Lattnere7fb4842009-02-15 20:52:18 +0000140 SourceLocation RParenLoc = Tok.getLocation();
Mike Stump1eb44332009-09-09 15:08:12 +0000141
Chris Lattnera9d91452009-01-16 18:59:23 +0000142 // The _Pragma is lexically sound. Destringize according to C99 6.10.9.1:
143 // "The string literal is destringized by deleting the L prefix, if present,
144 // deleting the leading and trailing double-quotes, replacing each escape
145 // sequence \" by a double-quote, and replacing each escape sequence \\ by a
146 // single backslash."
Reid Spencer5f016e22007-07-11 17:01:13 +0000147 if (StrVal[0] == 'L') // Remove L prefix.
148 StrVal.erase(StrVal.begin());
149 assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' &&
150 "Invalid string token!");
Mike Stump1eb44332009-09-09 15:08:12 +0000151
Reid Spencer5f016e22007-07-11 17:01:13 +0000152 // Remove the front quote, replacing it with a space, so that the pragma
153 // contents appear to have a space before them.
154 StrVal[0] = ' ';
Mike Stump1eb44332009-09-09 15:08:12 +0000155
Chris Lattner1fa49532009-03-08 08:08:45 +0000156 // Replace the terminating quote with a \n.
Reid Spencer5f016e22007-07-11 17:01:13 +0000157 StrVal[StrVal.size()-1] = '\n';
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Reid Spencer5f016e22007-07-11 17:01:13 +0000159 // Remove escaped quotes and escapes.
160 for (unsigned i = 0, e = StrVal.size(); i != e-1; ++i) {
161 if (StrVal[i] == '\\' &&
162 (StrVal[i+1] == '\\' || StrVal[i+1] == '"')) {
163 // \\ -> '\' and \" -> '"'.
164 StrVal.erase(StrVal.begin()+i);
165 --e;
166 }
167 }
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Reid Spencer5f016e22007-07-11 17:01:13 +0000169 // Plop the string (including the newline and trailing null) into a buffer
170 // where we can lex it.
Chris Lattner47246be2009-01-26 19:29:26 +0000171 Token TmpTok;
172 TmpTok.startToken();
173 CreateString(&StrVal[0], StrVal.size(), TmpTok);
174 SourceLocation TokLoc = TmpTok.getLocation();
Reid Spencer5f016e22007-07-11 17:01:13 +0000175
Reid Spencer5f016e22007-07-11 17:01:13 +0000176 // Make and enter a lexer object so that we lex and expand the tokens just
177 // like any others.
Chris Lattnere7fb4842009-02-15 20:52:18 +0000178 Lexer *TL = Lexer::Create_PragmaLexer(TokLoc, PragmaLoc, RParenLoc,
Chris Lattner1fa49532009-03-08 08:08:45 +0000179 StrVal.size(), *this);
Reid Spencer5f016e22007-07-11 17:01:13 +0000180
181 EnterSourceFileWithLexer(TL, 0);
182
183 // With everything set up, lex this as a #pragma directive.
184 HandlePragmaDirective();
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Reid Spencer5f016e22007-07-11 17:01:13 +0000186 // Finally, return whatever came after the pragma directive.
187 return Lex(Tok);
188}
189
190
191
192/// HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.
193///
Chris Lattnerd2177732007-07-20 16:59:19 +0000194void Preprocessor::HandlePragmaOnce(Token &OnceTok) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000195 if (isInPrimaryFile()) {
196 Diag(OnceTok, diag::pp_pragma_once_in_main_file);
197 return;
198 }
Mike Stump1eb44332009-09-09 15:08:12 +0000199
Reid Spencer5f016e22007-07-11 17:01:13 +0000200 // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc.
Reid Spencer5f016e22007-07-11 17:01:13 +0000201 // Mark the file as a once-only file now.
Chris Lattner2b2453a2009-01-17 06:22:33 +0000202 HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry());
Reid Spencer5f016e22007-07-11 17:01:13 +0000203}
204
Chris Lattner22434492007-12-19 19:38:36 +0000205void Preprocessor::HandlePragmaMark() {
Ted Kremenek17ff58a2008-11-19 22:21:33 +0000206 assert(CurPPLexer && "No current lexer?");
Chris Lattner6896a372009-06-15 05:02:34 +0000207 if (CurLexer)
208 CurLexer->ReadToEndOfLine();
209 else
210 CurPTHLexer->DiscardToEndOfLine();
Chris Lattner22434492007-12-19 19:38:36 +0000211}
212
213
Reid Spencer5f016e22007-07-11 17:01:13 +0000214/// HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'.
215///
Chris Lattnerd2177732007-07-20 16:59:19 +0000216void Preprocessor::HandlePragmaPoison(Token &PoisonTok) {
217 Token Tok;
Reid Spencer5f016e22007-07-11 17:01:13 +0000218
219 while (1) {
220 // Read the next token to poison. While doing this, pretend that we are
221 // skipping while reading the identifier to poison.
222 // This avoids errors on code like:
223 // #pragma GCC poison X
224 // #pragma GCC poison X
Ted Kremenek68a91d52008-11-18 01:12:54 +0000225 if (CurPPLexer) CurPPLexer->LexingRawMode = true;
Reid Spencer5f016e22007-07-11 17:01:13 +0000226 LexUnexpandedToken(Tok);
Ted Kremenek68a91d52008-11-18 01:12:54 +0000227 if (CurPPLexer) CurPPLexer->LexingRawMode = false;
Mike Stump1eb44332009-09-09 15:08:12 +0000228
Reid Spencer5f016e22007-07-11 17:01:13 +0000229 // If we reached the end of line, we're done.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000230 if (Tok.is(tok::eom)) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000231
Reid Spencer5f016e22007-07-11 17:01:13 +0000232 // Can only poison identifiers.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000233 if (Tok.isNot(tok::identifier)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000234 Diag(Tok, diag::err_pp_invalid_poison);
235 return;
236 }
Mike Stump1eb44332009-09-09 15:08:12 +0000237
Reid Spencer5f016e22007-07-11 17:01:13 +0000238 // Look up the identifier info for the token. We disabled identifier lookup
239 // by saying we're skipping contents, so we need to do this manually.
240 IdentifierInfo *II = LookUpIdentifierInfo(Tok);
Mike Stump1eb44332009-09-09 15:08:12 +0000241
Reid Spencer5f016e22007-07-11 17:01:13 +0000242 // Already poisoned.
243 if (II->isPoisoned()) continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000244
Reid Spencer5f016e22007-07-11 17:01:13 +0000245 // If this is a macro identifier, emit a warning.
Chris Lattner0edde552007-10-07 08:04:56 +0000246 if (II->hasMacroDefinition())
Reid Spencer5f016e22007-07-11 17:01:13 +0000247 Diag(Tok, diag::pp_poisoning_existing_macro);
Mike Stump1eb44332009-09-09 15:08:12 +0000248
Reid Spencer5f016e22007-07-11 17:01:13 +0000249 // Finally, poison it!
250 II->setIsPoisoned();
251 }
252}
253
254/// HandlePragmaSystemHeader - Implement #pragma GCC system_header. We know
255/// that the whole directive has been parsed.
Chris Lattnerd2177732007-07-20 16:59:19 +0000256void Preprocessor::HandlePragmaSystemHeader(Token &SysHeaderTok) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000257 if (isInPrimaryFile()) {
258 Diag(SysHeaderTok, diag::pp_pragma_sysheader_in_main_file);
259 return;
260 }
Mike Stump1eb44332009-09-09 15:08:12 +0000261
Reid Spencer5f016e22007-07-11 17:01:13 +0000262 // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc.
Ted Kremenek35c10c22008-11-20 01:45:11 +0000263 PreprocessorLexer *TheLexer = getCurrentFileLexer();
Mike Stump1eb44332009-09-09 15:08:12 +0000264
Reid Spencer5f016e22007-07-11 17:01:13 +0000265 // Mark the file as a system header.
Chris Lattner2b2453a2009-01-17 06:22:33 +0000266 HeaderInfo.MarkFileSystemHeader(TheLexer->getFileEntry());
Mike Stump1eb44332009-09-09 15:08:12 +0000267
268
Chris Lattner6896a372009-06-15 05:02:34 +0000269 PresumedLoc PLoc = SourceMgr.getPresumedLoc(SysHeaderTok.getLocation());
270 unsigned FilenameLen = strlen(PLoc.getFilename());
271 unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename(),
272 FilenameLen);
Mike Stump1eb44332009-09-09 15:08:12 +0000273
Chris Lattner6896a372009-06-15 05:02:34 +0000274 // Emit a line marker. This will change any source locations from this point
275 // forward to realize they are in a system header.
276 // Create a line note with this information.
277 SourceMgr.AddLineNote(SysHeaderTok.getLocation(), PLoc.getLine(), FilenameID,
278 false, false, true, false);
Mike Stump1eb44332009-09-09 15:08:12 +0000279
Reid Spencer5f016e22007-07-11 17:01:13 +0000280 // Notify the client, if desired, that we are in a new source file.
281 if (Callbacks)
Ted Kremenek35c10c22008-11-20 01:45:11 +0000282 Callbacks->FileChanged(SysHeaderTok.getLocation(),
Chris Lattner0b9e7362008-09-26 21:18:42 +0000283 PPCallbacks::SystemHeaderPragma, SrcMgr::C_System);
Reid Spencer5f016e22007-07-11 17:01:13 +0000284}
285
286/// HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
287///
Chris Lattnerd2177732007-07-20 16:59:19 +0000288void Preprocessor::HandlePragmaDependency(Token &DependencyTok) {
289 Token FilenameTok;
Ted Kremenek68a91d52008-11-18 01:12:54 +0000290 CurPPLexer->LexIncludeFilename(FilenameTok);
Reid Spencer5f016e22007-07-11 17:01:13 +0000291
292 // If the token kind is EOM, the error has already been diagnosed.
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000293 if (FilenameTok.is(tok::eom))
Reid Spencer5f016e22007-07-11 17:01:13 +0000294 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000295
Reid Spencer5f016e22007-07-11 17:01:13 +0000296 // Reserve a buffer to get the spelling.
Chris Lattnera1394812010-01-10 01:35:12 +0000297 llvm::SmallString<128> FilenameBuffer;
Douglas Gregor453091c2010-03-16 22:30:13 +0000298 bool Invalid = false;
299 llvm::StringRef Filename = getSpelling(FilenameTok, FilenameBuffer, &Invalid);
300 if (Invalid)
301 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Chris Lattnera1394812010-01-10 01:35:12 +0000303 bool isAngled =
304 GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename);
Reid Spencer5f016e22007-07-11 17:01:13 +0000305 // If GetIncludeFilenameSpelling set the start ptr to null, there was an
306 // error.
Chris Lattnera1394812010-01-10 01:35:12 +0000307 if (Filename.empty())
Reid Spencer5f016e22007-07-11 17:01:13 +0000308 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000309
Reid Spencer5f016e22007-07-11 17:01:13 +0000310 // Search include directories for this file.
311 const DirectoryLookup *CurDir;
Chris Lattnerf45b6462010-01-22 00:14:44 +0000312 const FileEntry *File = LookupFile(Filename, isAngled, 0, CurDir);
Chris Lattner56b05c82008-11-18 08:02:48 +0000313 if (File == 0) {
Chris Lattnera1394812010-01-10 01:35:12 +0000314 Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
Chris Lattner56b05c82008-11-18 08:02:48 +0000315 return;
316 }
Mike Stump1eb44332009-09-09 15:08:12 +0000317
Chris Lattner2b2453a2009-01-17 06:22:33 +0000318 const FileEntry *CurFile = getCurrentFileLexer()->getFileEntry();
Reid Spencer5f016e22007-07-11 17:01:13 +0000319
320 // If this file is older than the file it depends on, emit a diagnostic.
321 if (CurFile && CurFile->getModificationTime() < File->getModificationTime()) {
322 // Lex tokens at the end of the message and include them in the message.
323 std::string Message;
324 Lex(DependencyTok);
Chris Lattner22f6bbc2007-10-09 18:02:16 +0000325 while (DependencyTok.isNot(tok::eom)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000326 Message += getSpelling(DependencyTok) + " ";
327 Lex(DependencyTok);
328 }
Mike Stump1eb44332009-09-09 15:08:12 +0000329
Reid Spencer5f016e22007-07-11 17:01:13 +0000330 Message.erase(Message.end()-1);
Chris Lattner56b05c82008-11-18 08:02:48 +0000331 Diag(FilenameTok, diag::pp_out_of_date_dependency) << Message;
Reid Spencer5f016e22007-07-11 17:01:13 +0000332 }
333}
334
Chris Lattner636c5ef2009-01-16 08:21:25 +0000335/// HandlePragmaComment - Handle the microsoft #pragma comment extension. The
336/// syntax is:
337/// #pragma comment(linker, "foo")
338/// 'linker' is one of five identifiers: compiler, exestr, lib, linker, user.
339/// "foo" is a string, which is fully macro expanded, and permits string
Gabor Greifd7ee3492009-03-17 11:39:38 +0000340/// concatenation, embedded escape characters etc. See MSDN for more details.
Chris Lattner636c5ef2009-01-16 08:21:25 +0000341void Preprocessor::HandlePragmaComment(Token &Tok) {
342 SourceLocation CommentLoc = Tok.getLocation();
343 Lex(Tok);
344 if (Tok.isNot(tok::l_paren)) {
345 Diag(CommentLoc, diag::err_pragma_comment_malformed);
346 return;
347 }
Mike Stump1eb44332009-09-09 15:08:12 +0000348
Chris Lattner636c5ef2009-01-16 08:21:25 +0000349 // Read the identifier.
350 Lex(Tok);
351 if (Tok.isNot(tok::identifier)) {
352 Diag(CommentLoc, diag::err_pragma_comment_malformed);
353 return;
354 }
Mike Stump1eb44332009-09-09 15:08:12 +0000355
Chris Lattner636c5ef2009-01-16 08:21:25 +0000356 // Verify that this is one of the 5 whitelisted options.
357 // FIXME: warn that 'exestr' is deprecated.
358 const IdentifierInfo *II = Tok.getIdentifierInfo();
Mike Stump1eb44332009-09-09 15:08:12 +0000359 if (!II->isStr("compiler") && !II->isStr("exestr") && !II->isStr("lib") &&
Chris Lattner636c5ef2009-01-16 08:21:25 +0000360 !II->isStr("linker") && !II->isStr("user")) {
361 Diag(Tok.getLocation(), diag::err_pragma_comment_unknown_kind);
362 return;
363 }
Mike Stump1eb44332009-09-09 15:08:12 +0000364
Chris Lattnera9d91452009-01-16 18:59:23 +0000365 // Read the optional string if present.
Chris Lattner636c5ef2009-01-16 08:21:25 +0000366 Lex(Tok);
Chris Lattnera9d91452009-01-16 18:59:23 +0000367 std::string ArgumentString;
Chris Lattner636c5ef2009-01-16 08:21:25 +0000368 if (Tok.is(tok::comma)) {
Chris Lattnera9d91452009-01-16 18:59:23 +0000369 Lex(Tok); // eat the comma.
Chris Lattner636c5ef2009-01-16 08:21:25 +0000370
371 // We need at least one string.
Chris Lattneredaf8772009-04-19 23:16:58 +0000372 if (Tok.isNot(tok::string_literal)) {
Chris Lattner636c5ef2009-01-16 08:21:25 +0000373 Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
374 return;
375 }
376
377 // String concatenation allows multiple strings, which can even come from
378 // macro expansion.
379 // "foo " "bar" "Baz"
Chris Lattnera9d91452009-01-16 18:59:23 +0000380 llvm::SmallVector<Token, 4> StrToks;
Chris Lattneredaf8772009-04-19 23:16:58 +0000381 while (Tok.is(tok::string_literal)) {
Chris Lattnera9d91452009-01-16 18:59:23 +0000382 StrToks.push_back(Tok);
Chris Lattner636c5ef2009-01-16 08:21:25 +0000383 Lex(Tok);
Chris Lattnera9d91452009-01-16 18:59:23 +0000384 }
385
386 // Concatenate and parse the strings.
387 StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this);
388 assert(!Literal.AnyWide && "Didn't allow wide strings in");
389 if (Literal.hadError)
390 return;
391 if (Literal.Pascal) {
392 Diag(StrToks[0].getLocation(), diag::err_pragma_comment_malformed);
393 return;
394 }
395
396 ArgumentString = std::string(Literal.GetString(),
397 Literal.GetString()+Literal.GetStringLength());
Chris Lattner636c5ef2009-01-16 08:21:25 +0000398 }
Mike Stump1eb44332009-09-09 15:08:12 +0000399
Chris Lattnera9d91452009-01-16 18:59:23 +0000400 // FIXME: If the kind is "compiler" warn if the string is present (it is
401 // ignored).
402 // FIXME: 'lib' requires a comment string.
403 // FIXME: 'linker' requires a comment string, and has a specific list of
404 // things that are allowable.
Mike Stump1eb44332009-09-09 15:08:12 +0000405
Chris Lattner636c5ef2009-01-16 08:21:25 +0000406 if (Tok.isNot(tok::r_paren)) {
407 Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
408 return;
409 }
Chris Lattnera9d91452009-01-16 18:59:23 +0000410 Lex(Tok); // eat the r_paren.
Chris Lattner636c5ef2009-01-16 08:21:25 +0000411
412 if (Tok.isNot(tok::eom)) {
413 Diag(Tok.getLocation(), diag::err_pragma_comment_malformed);
414 return;
415 }
Mike Stump1eb44332009-09-09 15:08:12 +0000416
Chris Lattnera9d91452009-01-16 18:59:23 +0000417 // If the pragma is lexically sound, notify any interested PPCallbacks.
Chris Lattner172e3362009-01-16 19:01:46 +0000418 if (Callbacks)
419 Callbacks->PragmaComment(CommentLoc, II, ArgumentString);
Chris Lattner636c5ef2009-01-16 08:21:25 +0000420}
421
Chris Lattnerabfe0942010-06-26 17:11:39 +0000422/// HandlePragmaMessage - Handle the microsoft #pragma message extension. The
423/// syntax is:
424/// #pragma message(messagestring)
425/// messagestring is a string, which is fully macro expanded, and permits string
426/// concatenation, embedded escape characters etc. See MSDN for more details.
427void Preprocessor::HandlePragmaMessage(Token &Tok) {
428 SourceLocation MessageLoc = Tok.getLocation();
429 Lex(Tok);
430 if (Tok.isNot(tok::l_paren)) {
431 Diag(MessageLoc, diag::err_pragma_message_malformed);
432 return;
433 }
Chris Lattner636c5ef2009-01-16 08:21:25 +0000434
Chris Lattnerabfe0942010-06-26 17:11:39 +0000435 // Read the string.
436 Lex(Tok);
437
438
439 // We need at least one string.
440 if (Tok.isNot(tok::string_literal)) {
441 Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
442 return;
443 }
444
445 // String concatenation allows multiple strings, which can even come from
446 // macro expansion.
447 // "foo " "bar" "Baz"
448 llvm::SmallVector<Token, 4> StrToks;
449 while (Tok.is(tok::string_literal)) {
450 StrToks.push_back(Tok);
451 Lex(Tok);
452 }
453
454 // Concatenate and parse the strings.
455 StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this);
456 assert(!Literal.AnyWide && "Didn't allow wide strings in");
457 if (Literal.hadError)
458 return;
459 if (Literal.Pascal) {
460 Diag(StrToks[0].getLocation(), diag::err_pragma_message_malformed);
461 return;
462 }
463
464 llvm::StringRef MessageString(Literal.GetString(), Literal.GetStringLength());
465
466 if (Tok.isNot(tok::r_paren)) {
467 Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
468 return;
469 }
470 Lex(Tok); // eat the r_paren.
471
472 if (Tok.isNot(tok::eom)) {
473 Diag(Tok.getLocation(), diag::err_pragma_message_malformed);
474 return;
475 }
476
477 // Output the message.
478 Diag(MessageLoc, diag::warn_pragma_message) << MessageString;
479
480 // If the pragma is lexically sound, notify any interested PPCallbacks.
481 if (Callbacks)
482 Callbacks->PragmaMessage(MessageLoc, MessageString);
483}
Chris Lattner636c5ef2009-01-16 08:21:25 +0000484
Reid Spencer5f016e22007-07-11 17:01:13 +0000485
486/// AddPragmaHandler - Add the specified pragma handler to the preprocessor.
487/// If 'Namespace' is non-null, then it is a token required to exist on the
488/// pragma line before the pragma string starts, e.g. "STDC" or "GCC".
Mike Stump1eb44332009-09-09 15:08:12 +0000489void Preprocessor::AddPragmaHandler(const char *Namespace,
Reid Spencer5f016e22007-07-11 17:01:13 +0000490 PragmaHandler *Handler) {
491 PragmaNamespace *InsertNS = PragmaHandlers;
Mike Stump1eb44332009-09-09 15:08:12 +0000492
Reid Spencer5f016e22007-07-11 17:01:13 +0000493 // If this is specified to be in a namespace, step down into it.
494 if (Namespace) {
495 IdentifierInfo *NSID = getIdentifierInfo(Namespace);
Mike Stump1eb44332009-09-09 15:08:12 +0000496
Reid Spencer5f016e22007-07-11 17:01:13 +0000497 // If there is already a pragma handler with the name of this namespace,
498 // we either have an error (directive with the same name as a namespace) or
499 // we already have the namespace to insert into.
500 if (PragmaHandler *Existing = PragmaHandlers->FindHandler(NSID)) {
501 InsertNS = Existing->getIfNamespace();
502 assert(InsertNS != 0 && "Cannot have a pragma namespace and pragma"
503 " handler with the same name!");
504 } else {
505 // Otherwise, this namespace doesn't exist yet, create and insert the
506 // handler for it.
507 InsertNS = new PragmaNamespace(NSID);
508 PragmaHandlers->AddPragma(InsertNS);
509 }
510 }
Mike Stump1eb44332009-09-09 15:08:12 +0000511
Reid Spencer5f016e22007-07-11 17:01:13 +0000512 // Check to make sure we don't already have a pragma for this identifier.
513 assert(!InsertNS->FindHandler(Handler->getName()) &&
514 "Pragma handler already exists for this identifier!");
515 InsertNS->AddPragma(Handler);
516}
517
Daniel Dunbar40950802008-10-04 19:17:46 +0000518/// RemovePragmaHandler - Remove the specific pragma handler from the
519/// preprocessor. If \arg Namespace is non-null, then it should be the
520/// namespace that \arg Handler was added to. It is an error to remove
521/// a handler that has not been registered.
522void Preprocessor::RemovePragmaHandler(const char *Namespace,
523 PragmaHandler *Handler) {
524 PragmaNamespace *NS = PragmaHandlers;
Mike Stump1eb44332009-09-09 15:08:12 +0000525
Daniel Dunbar40950802008-10-04 19:17:46 +0000526 // If this is specified to be in a namespace, step down into it.
527 if (Namespace) {
528 IdentifierInfo *NSID = getIdentifierInfo(Namespace);
529 PragmaHandler *Existing = PragmaHandlers->FindHandler(NSID);
530 assert(Existing && "Namespace containing handler does not exist!");
531
532 NS = Existing->getIfNamespace();
533 assert(NS && "Invalid namespace, registered as a regular pragma handler!");
534 }
535
536 NS->RemovePragmaHandler(Handler);
Mike Stump1eb44332009-09-09 15:08:12 +0000537
Daniel Dunbar40950802008-10-04 19:17:46 +0000538 // If this is a non-default namespace and it is now empty, remove
539 // it.
540 if (NS != PragmaHandlers && NS->IsEmpty())
541 PragmaHandlers->RemovePragmaHandler(NS);
542}
543
Reid Spencer5f016e22007-07-11 17:01:13 +0000544namespace {
Chris Lattner22434492007-12-19 19:38:36 +0000545/// PragmaOnceHandler - "#pragma once" marks the file as atomically included.
Reid Spencer5f016e22007-07-11 17:01:13 +0000546struct PragmaOnceHandler : public PragmaHandler {
547 PragmaOnceHandler(const IdentifierInfo *OnceID) : PragmaHandler(OnceID) {}
Chris Lattnerd2177732007-07-20 16:59:19 +0000548 virtual void HandlePragma(Preprocessor &PP, Token &OnceTok) {
Chris Lattner35410d52009-04-14 05:07:49 +0000549 PP.CheckEndOfDirective("pragma once");
Reid Spencer5f016e22007-07-11 17:01:13 +0000550 PP.HandlePragmaOnce(OnceTok);
551 }
552};
553
Chris Lattner22434492007-12-19 19:38:36 +0000554/// PragmaMarkHandler - "#pragma mark ..." is ignored by the compiler, and the
555/// rest of the line is not lexed.
556struct PragmaMarkHandler : public PragmaHandler {
557 PragmaMarkHandler(const IdentifierInfo *MarkID) : PragmaHandler(MarkID) {}
558 virtual void HandlePragma(Preprocessor &PP, Token &MarkTok) {
559 PP.HandlePragmaMark();
560 }
561};
562
563/// PragmaPoisonHandler - "#pragma poison x" marks x as not usable.
Reid Spencer5f016e22007-07-11 17:01:13 +0000564struct PragmaPoisonHandler : public PragmaHandler {
565 PragmaPoisonHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
Chris Lattnerd2177732007-07-20 16:59:19 +0000566 virtual void HandlePragma(Preprocessor &PP, Token &PoisonTok) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000567 PP.HandlePragmaPoison(PoisonTok);
568 }
569};
570
Chris Lattner22434492007-12-19 19:38:36 +0000571/// PragmaSystemHeaderHandler - "#pragma system_header" marks the current file
572/// as a system header, which silences warnings in it.
Reid Spencer5f016e22007-07-11 17:01:13 +0000573struct PragmaSystemHeaderHandler : public PragmaHandler {
574 PragmaSystemHeaderHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
Chris Lattnerd2177732007-07-20 16:59:19 +0000575 virtual void HandlePragma(Preprocessor &PP, Token &SHToken) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000576 PP.HandlePragmaSystemHeader(SHToken);
Chris Lattner35410d52009-04-14 05:07:49 +0000577 PP.CheckEndOfDirective("pragma");
Reid Spencer5f016e22007-07-11 17:01:13 +0000578 }
579};
580struct PragmaDependencyHandler : public PragmaHandler {
581 PragmaDependencyHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
Chris Lattnerd2177732007-07-20 16:59:19 +0000582 virtual void HandlePragma(Preprocessor &PP, Token &DepToken) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000583 PP.HandlePragmaDependency(DepToken);
584 }
585};
Mike Stump1eb44332009-09-09 15:08:12 +0000586
Chris Lattneredaf8772009-04-19 23:16:58 +0000587/// PragmaDiagnosticHandler - e.g. '#pragma GCC diagnostic ignored "-Wformat"'
Chris Lattner04ae2df2009-07-12 21:18:45 +0000588/// Since clang's diagnostic supports extended functionality beyond GCC's
589/// the constructor takes a clangMode flag to tell it whether or not to allow
590/// clang's extended functionality, or whether to reject it.
Chris Lattneredaf8772009-04-19 23:16:58 +0000591struct PragmaDiagnosticHandler : public PragmaHandler {
Chris Lattner04ae2df2009-07-12 21:18:45 +0000592private:
593 const bool ClangMode;
594public:
595 PragmaDiagnosticHandler(const IdentifierInfo *ID,
596 const bool clangMode) : PragmaHandler(ID),
597 ClangMode(clangMode) {}
Chris Lattneredaf8772009-04-19 23:16:58 +0000598 virtual void HandlePragma(Preprocessor &PP, Token &DiagToken) {
599 Token Tok;
600 PP.LexUnexpandedToken(Tok);
601 if (Tok.isNot(tok::identifier)) {
Chris Lattner04ae2df2009-07-12 21:18:45 +0000602 unsigned Diag = ClangMode ? diag::warn_pragma_diagnostic_clang_invalid
603 : diag::warn_pragma_diagnostic_gcc_invalid;
604 PP.Diag(Tok, Diag);
Chris Lattneredaf8772009-04-19 23:16:58 +0000605 return;
606 }
607 IdentifierInfo *II = Tok.getIdentifierInfo();
Mike Stump1eb44332009-09-09 15:08:12 +0000608
Chris Lattneredaf8772009-04-19 23:16:58 +0000609 diag::Mapping Map;
610 if (II->isStr("warning"))
611 Map = diag::MAP_WARNING;
612 else if (II->isStr("error"))
613 Map = diag::MAP_ERROR;
614 else if (II->isStr("ignored"))
615 Map = diag::MAP_IGNORE;
616 else if (II->isStr("fatal"))
617 Map = diag::MAP_FATAL;
Chris Lattner04ae2df2009-07-12 21:18:45 +0000618 else if (ClangMode) {
619 if (II->isStr("pop")) {
Mike Stump1eb44332009-09-09 15:08:12 +0000620 if (!PP.getDiagnostics().popMappings())
Chris Lattner04ae2df2009-07-12 21:18:45 +0000621 PP.Diag(Tok, diag::warn_pragma_diagnostic_clang_cannot_ppp);
622 return;
623 }
624
625 if (II->isStr("push")) {
626 PP.getDiagnostics().pushMappings();
Mike Stump1eb44332009-09-09 15:08:12 +0000627 return;
Chris Lattner04ae2df2009-07-12 21:18:45 +0000628 }
629
630 PP.Diag(Tok, diag::warn_pragma_diagnostic_clang_invalid);
631 return;
632 } else {
633 PP.Diag(Tok, diag::warn_pragma_diagnostic_gcc_invalid);
Chris Lattneredaf8772009-04-19 23:16:58 +0000634 return;
635 }
Mike Stump1eb44332009-09-09 15:08:12 +0000636
Chris Lattneredaf8772009-04-19 23:16:58 +0000637 PP.LexUnexpandedToken(Tok);
638
639 // We need at least one string.
640 if (Tok.isNot(tok::string_literal)) {
641 PP.Diag(Tok.getLocation(), diag::warn_pragma_diagnostic_invalid_token);
642 return;
643 }
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Chris Lattneredaf8772009-04-19 23:16:58 +0000645 // String concatenation allows multiple strings, which can even come from
646 // macro expansion.
647 // "foo " "bar" "Baz"
648 llvm::SmallVector<Token, 4> StrToks;
649 while (Tok.is(tok::string_literal)) {
650 StrToks.push_back(Tok);
651 PP.LexUnexpandedToken(Tok);
652 }
Mike Stump1eb44332009-09-09 15:08:12 +0000653
Chris Lattneredaf8772009-04-19 23:16:58 +0000654 if (Tok.isNot(tok::eom)) {
655 PP.Diag(Tok.getLocation(), diag::warn_pragma_diagnostic_invalid_token);
656 return;
657 }
Mike Stump1eb44332009-09-09 15:08:12 +0000658
Chris Lattneredaf8772009-04-19 23:16:58 +0000659 // Concatenate and parse the strings.
660 StringLiteralParser Literal(&StrToks[0], StrToks.size(), PP);
661 assert(!Literal.AnyWide && "Didn't allow wide strings in");
662 if (Literal.hadError)
663 return;
664 if (Literal.Pascal) {
Chris Lattner04ae2df2009-07-12 21:18:45 +0000665 unsigned Diag = ClangMode ? diag::warn_pragma_diagnostic_clang_invalid
666 : diag::warn_pragma_diagnostic_gcc_invalid;
667 PP.Diag(Tok, Diag);
Chris Lattneredaf8772009-04-19 23:16:58 +0000668 return;
669 }
Chris Lattner04ae2df2009-07-12 21:18:45 +0000670
Chris Lattneredaf8772009-04-19 23:16:58 +0000671 std::string WarningName(Literal.GetString(),
672 Literal.GetString()+Literal.GetStringLength());
673
674 if (WarningName.size() < 3 || WarningName[0] != '-' ||
675 WarningName[1] != 'W') {
676 PP.Diag(StrToks[0].getLocation(),
677 diag::warn_pragma_diagnostic_invalid_option);
678 return;
679 }
Mike Stump1eb44332009-09-09 15:08:12 +0000680
Chris Lattneredaf8772009-04-19 23:16:58 +0000681 if (PP.getDiagnostics().setDiagnosticGroupMapping(WarningName.c_str()+2,
682 Map))
683 PP.Diag(StrToks[0].getLocation(),
684 diag::warn_pragma_diagnostic_unknown_warning) << WarningName;
685 }
686};
Mike Stump1eb44332009-09-09 15:08:12 +0000687
Chris Lattner636c5ef2009-01-16 08:21:25 +0000688/// PragmaCommentHandler - "#pragma comment ...".
689struct PragmaCommentHandler : public PragmaHandler {
690 PragmaCommentHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
691 virtual void HandlePragma(Preprocessor &PP, Token &CommentTok) {
692 PP.HandlePragmaComment(CommentTok);
693 }
694};
Mike Stump1eb44332009-09-09 15:08:12 +0000695
Chris Lattnerabfe0942010-06-26 17:11:39 +0000696/// PragmaMessageHandler - "#pragma message("...")".
697struct PragmaMessageHandler : public PragmaHandler {
698 PragmaMessageHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
699 virtual void HandlePragma(Preprocessor &PP, Token &CommentTok) {
700 PP.HandlePragmaMessage(CommentTok);
701 }
702};
703
Chris Lattner062f2322009-04-19 21:20:35 +0000704// Pragma STDC implementations.
Chris Lattner6c5cf4a2009-04-19 21:50:08 +0000705
706enum STDCSetting {
707 STDC_ON, STDC_OFF, STDC_DEFAULT, STDC_INVALID
708};
Mike Stump1eb44332009-09-09 15:08:12 +0000709
Chris Lattner6c5cf4a2009-04-19 21:50:08 +0000710static STDCSetting LexOnOffSwitch(Preprocessor &PP) {
711 Token Tok;
712 PP.LexUnexpandedToken(Tok);
713
714 if (Tok.isNot(tok::identifier)) {
715 PP.Diag(Tok, diag::ext_stdc_pragma_syntax);
716 return STDC_INVALID;
717 }
718 IdentifierInfo *II = Tok.getIdentifierInfo();
719 STDCSetting Result;
720 if (II->isStr("ON"))
721 Result = STDC_ON;
722 else if (II->isStr("OFF"))
723 Result = STDC_OFF;
724 else if (II->isStr("DEFAULT"))
725 Result = STDC_DEFAULT;
726 else {
727 PP.Diag(Tok, diag::ext_stdc_pragma_syntax);
728 return STDC_INVALID;
729 }
730
731 // Verify that this is followed by EOM.
732 PP.LexUnexpandedToken(Tok);
733 if (Tok.isNot(tok::eom))
734 PP.Diag(Tok, diag::ext_stdc_pragma_syntax_eom);
735 return Result;
736}
Mike Stump1eb44332009-09-09 15:08:12 +0000737
Chris Lattner062f2322009-04-19 21:20:35 +0000738/// PragmaSTDC_FP_CONTRACTHandler - "#pragma STDC FP_CONTRACT ...".
739struct PragmaSTDC_FP_CONTRACTHandler : public PragmaHandler {
740 PragmaSTDC_FP_CONTRACTHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
Chris Lattnerf545be52009-04-19 21:25:37 +0000741 virtual void HandlePragma(Preprocessor &PP, Token &Tok) {
Chris Lattner6c5cf4a2009-04-19 21:50:08 +0000742 // We just ignore the setting of FP_CONTRACT. Since we don't do contractions
743 // at all, our default is OFF and setting it to ON is an optimization hint
744 // we can safely ignore. When we support -ffma or something, we would need
745 // to diagnose that we are ignoring FMA.
746 LexOnOffSwitch(PP);
Chris Lattner062f2322009-04-19 21:20:35 +0000747 }
748};
Mike Stump1eb44332009-09-09 15:08:12 +0000749
Chris Lattner062f2322009-04-19 21:20:35 +0000750/// PragmaSTDC_FENV_ACCESSHandler - "#pragma STDC FENV_ACCESS ...".
751struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler {
752 PragmaSTDC_FENV_ACCESSHandler(const IdentifierInfo *ID) : PragmaHandler(ID) {}
Chris Lattnerf545be52009-04-19 21:25:37 +0000753 virtual void HandlePragma(Preprocessor &PP, Token &Tok) {
Chris Lattner4d8aac32009-04-19 21:55:32 +0000754 if (LexOnOffSwitch(PP) == STDC_ON)
755 PP.Diag(Tok, diag::warn_stdc_fenv_access_not_supported);
Chris Lattner062f2322009-04-19 21:20:35 +0000756 }
757};
Mike Stump1eb44332009-09-09 15:08:12 +0000758
Chris Lattner062f2322009-04-19 21:20:35 +0000759/// PragmaSTDC_CX_LIMITED_RANGEHandler - "#pragma STDC CX_LIMITED_RANGE ...".
760struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler {
761 PragmaSTDC_CX_LIMITED_RANGEHandler(const IdentifierInfo *ID)
762 : PragmaHandler(ID) {}
Chris Lattnerf545be52009-04-19 21:25:37 +0000763 virtual void HandlePragma(Preprocessor &PP, Token &Tok) {
Chris Lattner6c5cf4a2009-04-19 21:50:08 +0000764 LexOnOffSwitch(PP);
Chris Lattner062f2322009-04-19 21:20:35 +0000765 }
766};
Mike Stump1eb44332009-09-09 15:08:12 +0000767
Chris Lattner062f2322009-04-19 21:20:35 +0000768/// PragmaSTDC_UnknownHandler - "#pragma STDC ...".
769struct PragmaSTDC_UnknownHandler : public PragmaHandler {
770 PragmaSTDC_UnknownHandler() : PragmaHandler(0) {}
Chris Lattnerf545be52009-04-19 21:25:37 +0000771 virtual void HandlePragma(Preprocessor &PP, Token &UnknownTok) {
Chris Lattner6c5cf4a2009-04-19 21:50:08 +0000772 // C99 6.10.6p2, unknown forms are not allowed.
Chris Lattnerf545be52009-04-19 21:25:37 +0000773 PP.Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
Chris Lattner062f2322009-04-19 21:20:35 +0000774 }
775};
Mike Stump1eb44332009-09-09 15:08:12 +0000776
Reid Spencer5f016e22007-07-11 17:01:13 +0000777} // end anonymous namespace
778
779
780/// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
781/// #pragma GCC poison/system_header/dependency and #pragma once.
782void Preprocessor::RegisterBuiltinPragmas() {
783 AddPragmaHandler(0, new PragmaOnceHandler(getIdentifierInfo("once")));
Chris Lattner22434492007-12-19 19:38:36 +0000784 AddPragmaHandler(0, new PragmaMarkHandler(getIdentifierInfo("mark")));
Mike Stump1eb44332009-09-09 15:08:12 +0000785
Chris Lattnere8fa06e2009-05-12 18:21:11 +0000786 // #pragma GCC ...
Reid Spencer5f016e22007-07-11 17:01:13 +0000787 AddPragmaHandler("GCC", new PragmaPoisonHandler(getIdentifierInfo("poison")));
788 AddPragmaHandler("GCC", new PragmaSystemHeaderHandler(
789 getIdentifierInfo("system_header")));
790 AddPragmaHandler("GCC", new PragmaDependencyHandler(
791 getIdentifierInfo("dependency")));
Chris Lattneredaf8772009-04-19 23:16:58 +0000792 AddPragmaHandler("GCC", new PragmaDiagnosticHandler(
Chris Lattner04ae2df2009-07-12 21:18:45 +0000793 getIdentifierInfo("diagnostic"),
794 false));
Chris Lattnere8fa06e2009-05-12 18:21:11 +0000795 // #pragma clang ...
796 AddPragmaHandler("clang", new PragmaPoisonHandler(
797 getIdentifierInfo("poison")));
798 AddPragmaHandler("clang", new PragmaSystemHeaderHandler(
799 getIdentifierInfo("system_header")));
800 AddPragmaHandler("clang", new PragmaDependencyHandler(
801 getIdentifierInfo("dependency")));
802 AddPragmaHandler("clang", new PragmaDiagnosticHandler(
Chris Lattner04ae2df2009-07-12 21:18:45 +0000803 getIdentifierInfo("diagnostic"),
804 true));
Chris Lattnere8fa06e2009-05-12 18:21:11 +0000805
Chris Lattner062f2322009-04-19 21:20:35 +0000806 AddPragmaHandler("STDC", new PragmaSTDC_FP_CONTRACTHandler(
807 getIdentifierInfo("FP_CONTRACT")));
808 AddPragmaHandler("STDC", new PragmaSTDC_FENV_ACCESSHandler(
809 getIdentifierInfo("FENV_ACCESS")));
810 AddPragmaHandler("STDC", new PragmaSTDC_CX_LIMITED_RANGEHandler(
811 getIdentifierInfo("CX_LIMITED_RANGE")));
812 AddPragmaHandler("STDC", new PragmaSTDC_UnknownHandler());
Mike Stump1eb44332009-09-09 15:08:12 +0000813
Chris Lattner636c5ef2009-01-16 08:21:25 +0000814 // MS extensions.
Chris Lattnerabfe0942010-06-26 17:11:39 +0000815 if (Features.Microsoft) {
Chris Lattner636c5ef2009-01-16 08:21:25 +0000816 AddPragmaHandler(0, new PragmaCommentHandler(getIdentifierInfo("comment")));
Chris Lattnerabfe0942010-06-26 17:11:39 +0000817 AddPragmaHandler(0, new PragmaMessageHandler(getIdentifierInfo("message")));
818 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000819}