Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Pragma.cpp - Pragma registration and handling --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 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 Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include "clang/Lex/HeaderSearch.h" |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 17 | #include "clang/Lex/LiteralSupport.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include "clang/Lex/Preprocessor.h" |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 19 | #include "clang/Lex/MacroInfo.h" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 20 | #include "clang/Lex/LexDiagnostic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 21 | #include "clang/Basic/FileManager.h" |
| 22 | #include "clang/Basic/SourceManager.h" |
Daniel Dunbar | ff759a6 | 2010-08-18 23:09:23 +0000 | [diff] [blame] | 23 | #include "llvm/Support/CrashRecoveryContext.h" |
Daniel Dunbar | 5505413 | 2010-08-17 22:32:48 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
Douglas Gregor | 2e22253 | 2009-07-02 17:08:52 +0000 | [diff] [blame] | 25 | #include <algorithm> |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 26 | using namespace clang; |
| 27 | |
| 28 | // Out-of-line destructor to provide a home for the class. |
| 29 | PragmaHandler::~PragmaHandler() { |
| 30 | } |
| 31 | |
| 32 | //===----------------------------------------------------------------------===// |
Daniel Dunbar | c72cc50 | 2010-06-11 20:10:12 +0000 | [diff] [blame] | 33 | // EmptyPragmaHandler Implementation. |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 36 | EmptyPragmaHandler::EmptyPragmaHandler() {} |
Daniel Dunbar | c72cc50 | 2010-06-11 20:10:12 +0000 | [diff] [blame] | 37 | |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 38 | void EmptyPragmaHandler::HandlePragma(Preprocessor &PP, |
| 39 | PragmaIntroducerKind Introducer, |
| 40 | Token &FirstToken) {} |
Daniel Dunbar | c72cc50 | 2010-06-11 20:10:12 +0000 | [diff] [blame] | 41 | |
| 42 | //===----------------------------------------------------------------------===// |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 43 | // PragmaNamespace Implementation. |
| 44 | //===----------------------------------------------------------------------===// |
| 45 | |
| 46 | |
| 47 | PragmaNamespace::~PragmaNamespace() { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 48 | for (llvm::StringMap<PragmaHandler*>::iterator |
| 49 | I = Handlers.begin(), E = Handlers.end(); I != E; ++I) |
| 50 | delete I->second; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /// FindHandler - Check to see if there is already a handler for the |
| 54 | /// specified name. If not, return the handler for the null identifier if it |
| 55 | /// exists, otherwise return null. If IgnoreNull is true (the default) then |
| 56 | /// the null handler isn't returned on failure to match. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 57 | PragmaHandler *PragmaNamespace::FindHandler(StringRef Name, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 58 | bool IgnoreNull) const { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 59 | if (PragmaHandler *Handler = Handlers.lookup(Name)) |
| 60 | return Handler; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 61 | return IgnoreNull ? 0 : Handlers.lookup(StringRef()); |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 62 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 64 | void PragmaNamespace::AddPragma(PragmaHandler *Handler) { |
| 65 | assert(!Handlers.lookup(Handler->getName()) && |
| 66 | "A handler with this name is already registered in this namespace"); |
| 67 | llvm::StringMapEntry<PragmaHandler *> &Entry = |
| 68 | Handlers.GetOrCreateValue(Handler->getName()); |
| 69 | Entry.setValue(Handler); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 72 | void PragmaNamespace::RemovePragmaHandler(PragmaHandler *Handler) { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 73 | assert(Handlers.lookup(Handler->getName()) && |
| 74 | "Handler not registered in this namespace"); |
| 75 | Handlers.erase(Handler->getName()); |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 78 | void PragmaNamespace::HandlePragma(Preprocessor &PP, |
| 79 | PragmaIntroducerKind Introducer, |
| 80 | Token &Tok) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 81 | // Read the 'namespace' that the directive is in, e.g. STDC. Do not macro |
| 82 | // expand it, the user can have a STDC #define, that should not affect this. |
| 83 | PP.LexUnexpandedToken(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 84 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 85 | // Get the handler for this token. If there is no handler, ignore the pragma. |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 86 | PragmaHandler *Handler |
| 87 | = FindHandler(Tok.getIdentifierInfo() ? Tok.getIdentifierInfo()->getName() |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 88 | : StringRef(), |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 89 | /*IgnoreNull=*/false); |
Chris Lattner | af7cdf4 | 2009-04-19 21:10:26 +0000 | [diff] [blame] | 90 | if (Handler == 0) { |
| 91 | PP.Diag(Tok, diag::warn_pragma_ignored); |
| 92 | return; |
| 93 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 94 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 95 | // Otherwise, pass it down. |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 96 | Handler->HandlePragma(PP, Introducer, Tok); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | //===----------------------------------------------------------------------===// |
| 100 | // Preprocessor Pragma Directive Handling. |
| 101 | //===----------------------------------------------------------------------===// |
| 102 | |
| 103 | /// HandlePragmaDirective - The "#pragma" directive has been parsed. Lex the |
| 104 | /// rest of the pragma, passing it to the registered pragma handlers. |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 105 | void Preprocessor::HandlePragmaDirective(unsigned Introducer) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 106 | ++NumPragma; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 107 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 108 | // Invoke the first level of pragma handlers which reads the namespace id. |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 109 | Token Tok; |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 110 | PragmaHandlers->HandlePragma(*this, PragmaIntroducerKind(Introducer), Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 111 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 112 | // If the pragma handler didn't read the rest of the line, consume it now. |
Peter Collingbourne | b2eb53d | 2011-02-22 13:49:00 +0000 | [diff] [blame] | 113 | if ((CurTokenLexer && CurTokenLexer->isParsingPreprocessorDirective()) |
| 114 | || (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 115 | DiscardUntilEndOfDirective(); |
| 116 | } |
| 117 | |
| 118 | /// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then |
| 119 | /// return the first token after the directive. The _Pragma token has just |
| 120 | /// been read into 'Tok'. |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 121 | void Preprocessor::Handle_Pragma(Token &Tok) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 122 | // Remember the pragma token location. |
| 123 | SourceLocation PragmaLoc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 124 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 125 | // Read the '('. |
| 126 | Lex(Tok); |
Chris Lattner | 3692b09 | 2008-11-18 07:59:24 +0000 | [diff] [blame] | 127 | if (Tok.isNot(tok::l_paren)) { |
| 128 | Diag(PragmaLoc, diag::err__Pragma_malformed); |
| 129 | return; |
| 130 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 131 | |
| 132 | // Read the '"..."'. |
| 133 | Lex(Tok); |
Chris Lattner | 3692b09 | 2008-11-18 07:59:24 +0000 | [diff] [blame] | 134 | if (Tok.isNot(tok::string_literal) && Tok.isNot(tok::wide_string_literal)) { |
| 135 | Diag(PragmaLoc, diag::err__Pragma_malformed); |
| 136 | return; |
| 137 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 138 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 139 | // Remember the string. |
| 140 | std::string StrVal = getSpelling(Tok); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 141 | |
| 142 | // Read the ')'. |
| 143 | Lex(Tok); |
Chris Lattner | 3692b09 | 2008-11-18 07:59:24 +0000 | [diff] [blame] | 144 | if (Tok.isNot(tok::r_paren)) { |
| 145 | Diag(PragmaLoc, diag::err__Pragma_malformed); |
| 146 | return; |
| 147 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Chris Lattner | e7fb484 | 2009-02-15 20:52:18 +0000 | [diff] [blame] | 149 | SourceLocation RParenLoc = Tok.getLocation(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 150 | |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 151 | // The _Pragma is lexically sound. Destringize according to C99 6.10.9.1: |
| 152 | // "The string literal is destringized by deleting the L prefix, if present, |
| 153 | // deleting the leading and trailing double-quotes, replacing each escape |
| 154 | // sequence \" by a double-quote, and replacing each escape sequence \\ by a |
| 155 | // single backslash." |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 156 | if (StrVal[0] == 'L') // Remove L prefix. |
| 157 | StrVal.erase(StrVal.begin()); |
| 158 | assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' && |
| 159 | "Invalid string token!"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 161 | // Remove the front quote, replacing it with a space, so that the pragma |
| 162 | // contents appear to have a space before them. |
| 163 | StrVal[0] = ' '; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 164 | |
Chris Lattner | 1fa4953 | 2009-03-08 08:08:45 +0000 | [diff] [blame] | 165 | // Replace the terminating quote with a \n. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 166 | StrVal[StrVal.size()-1] = '\n'; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 167 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 168 | // Remove escaped quotes and escapes. |
| 169 | for (unsigned i = 0, e = StrVal.size(); i != e-1; ++i) { |
| 170 | if (StrVal[i] == '\\' && |
| 171 | (StrVal[i+1] == '\\' || StrVal[i+1] == '"')) { |
| 172 | // \\ -> '\' and \" -> '"'. |
| 173 | StrVal.erase(StrVal.begin()+i); |
| 174 | --e; |
| 175 | } |
| 176 | } |
John McCall | 1ef8a2e | 2010-08-28 22:34:47 +0000 | [diff] [blame] | 177 | |
Peter Collingbourne | a5ef584 | 2011-02-22 13:49:06 +0000 | [diff] [blame] | 178 | // Plop the string (including the newline and trailing null) into a buffer |
| 179 | // where we can lex it. |
| 180 | Token TmpTok; |
| 181 | TmpTok.startToken(); |
| 182 | CreateString(&StrVal[0], StrVal.size(), TmpTok); |
| 183 | SourceLocation TokLoc = TmpTok.getLocation(); |
| 184 | |
| 185 | // Make and enter a lexer object so that we lex and expand the tokens just |
| 186 | // like any others. |
| 187 | Lexer *TL = Lexer::Create_PragmaLexer(TokLoc, PragmaLoc, RParenLoc, |
| 188 | StrVal.size(), *this); |
| 189 | |
| 190 | EnterSourceFileWithLexer(TL, 0); |
| 191 | |
| 192 | // With everything set up, lex this as a #pragma directive. |
| 193 | HandlePragmaDirective(PIK__Pragma); |
John McCall | 1ef8a2e | 2010-08-28 22:34:47 +0000 | [diff] [blame] | 194 | |
| 195 | // Finally, return whatever came after the pragma directive. |
| 196 | return Lex(Tok); |
| 197 | } |
| 198 | |
| 199 | /// HandleMicrosoft__pragma - Like Handle_Pragma except the pragma text |
| 200 | /// is not enclosed within a string literal. |
| 201 | void Preprocessor::HandleMicrosoft__pragma(Token &Tok) { |
| 202 | // Remember the pragma token location. |
| 203 | SourceLocation PragmaLoc = Tok.getLocation(); |
| 204 | |
| 205 | // Read the '('. |
| 206 | Lex(Tok); |
| 207 | if (Tok.isNot(tok::l_paren)) { |
| 208 | Diag(PragmaLoc, diag::err__Pragma_malformed); |
| 209 | return; |
| 210 | } |
| 211 | |
Peter Collingbourne | a5ef584 | 2011-02-22 13:49:06 +0000 | [diff] [blame] | 212 | // Get the tokens enclosed within the __pragma(), as well as the final ')'. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 213 | SmallVector<Token, 32> PragmaToks; |
John McCall | 1ef8a2e | 2010-08-28 22:34:47 +0000 | [diff] [blame] | 214 | int NumParens = 0; |
| 215 | Lex(Tok); |
| 216 | while (Tok.isNot(tok::eof)) { |
Peter Collingbourne | a5ef584 | 2011-02-22 13:49:06 +0000 | [diff] [blame] | 217 | PragmaToks.push_back(Tok); |
John McCall | 1ef8a2e | 2010-08-28 22:34:47 +0000 | [diff] [blame] | 218 | if (Tok.is(tok::l_paren)) |
| 219 | NumParens++; |
| 220 | else if (Tok.is(tok::r_paren) && NumParens-- == 0) |
| 221 | break; |
John McCall | 1ef8a2e | 2010-08-28 22:34:47 +0000 | [diff] [blame] | 222 | Lex(Tok); |
| 223 | } |
| 224 | |
John McCall | 3da92a9 | 2010-08-29 01:09:54 +0000 | [diff] [blame] | 225 | if (Tok.is(tok::eof)) { |
| 226 | Diag(PragmaLoc, diag::err_unterminated___pragma); |
| 227 | return; |
| 228 | } |
| 229 | |
Peter Collingbourne | a5ef584 | 2011-02-22 13:49:06 +0000 | [diff] [blame] | 230 | PragmaToks.front().setFlag(Token::LeadingSpace); |
John McCall | 1ef8a2e | 2010-08-28 22:34:47 +0000 | [diff] [blame] | 231 | |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 232 | // Replace the ')' with an EOD to mark the end of the pragma. |
| 233 | PragmaToks.back().setKind(tok::eod); |
Peter Collingbourne | a5ef584 | 2011-02-22 13:49:06 +0000 | [diff] [blame] | 234 | |
| 235 | Token *TokArray = new Token[PragmaToks.size()]; |
| 236 | std::copy(PragmaToks.begin(), PragmaToks.end(), TokArray); |
| 237 | |
| 238 | // Push the tokens onto the stack. |
| 239 | EnterTokenStream(TokArray, PragmaToks.size(), true, true); |
| 240 | |
| 241 | // With everything set up, lex this as a #pragma directive. |
| 242 | HandlePragmaDirective(PIK___pragma); |
John McCall | 1ef8a2e | 2010-08-28 22:34:47 +0000 | [diff] [blame] | 243 | |
| 244 | // Finally, return whatever came after the pragma directive. |
| 245 | return Lex(Tok); |
| 246 | } |
| 247 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 248 | /// HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'. |
| 249 | /// |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 250 | void Preprocessor::HandlePragmaOnce(Token &OnceTok) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 251 | if (isInPrimaryFile()) { |
| 252 | Diag(OnceTok, diag::pp_pragma_once_in_main_file); |
| 253 | return; |
| 254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 255 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 256 | // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 257 | // Mark the file as a once-only file now. |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 258 | HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Chris Lattner | 2243449 | 2007-12-19 19:38:36 +0000 | [diff] [blame] | 261 | void Preprocessor::HandlePragmaMark() { |
Ted Kremenek | 17ff58a | 2008-11-19 22:21:33 +0000 | [diff] [blame] | 262 | assert(CurPPLexer && "No current lexer?"); |
Chris Lattner | 6896a37 | 2009-06-15 05:02:34 +0000 | [diff] [blame] | 263 | if (CurLexer) |
| 264 | CurLexer->ReadToEndOfLine(); |
| 265 | else |
| 266 | CurPTHLexer->DiscardToEndOfLine(); |
Chris Lattner | 2243449 | 2007-12-19 19:38:36 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 270 | /// HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'. |
| 271 | /// |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 272 | void Preprocessor::HandlePragmaPoison(Token &PoisonTok) { |
| 273 | Token Tok; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 274 | |
| 275 | while (1) { |
| 276 | // Read the next token to poison. While doing this, pretend that we are |
| 277 | // skipping while reading the identifier to poison. |
| 278 | // This avoids errors on code like: |
| 279 | // #pragma GCC poison X |
| 280 | // #pragma GCC poison X |
Ted Kremenek | 68a91d5 | 2008-11-18 01:12:54 +0000 | [diff] [blame] | 281 | if (CurPPLexer) CurPPLexer->LexingRawMode = true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 282 | LexUnexpandedToken(Tok); |
Ted Kremenek | 68a91d5 | 2008-11-18 01:12:54 +0000 | [diff] [blame] | 283 | if (CurPPLexer) CurPPLexer->LexingRawMode = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 284 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 285 | // If we reached the end of line, we're done. |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 286 | if (Tok.is(tok::eod)) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 287 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 288 | // Can only poison identifiers. |
Abramo Bagnara | c4bf2b9 | 2010-12-22 08:23:18 +0000 | [diff] [blame] | 289 | if (Tok.isNot(tok::raw_identifier)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 290 | Diag(Tok, diag::err_pp_invalid_poison); |
| 291 | return; |
| 292 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 294 | // Look up the identifier info for the token. We disabled identifier lookup |
| 295 | // by saying we're skipping contents, so we need to do this manually. |
| 296 | IdentifierInfo *II = LookUpIdentifierInfo(Tok); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 297 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 298 | // Already poisoned. |
| 299 | if (II->isPoisoned()) continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 300 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 301 | // If this is a macro identifier, emit a warning. |
Chris Lattner | 0edde55 | 2007-10-07 08:04:56 +0000 | [diff] [blame] | 302 | if (II->hasMacroDefinition()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 303 | Diag(Tok, diag::pp_poisoning_existing_macro); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 305 | // Finally, poison it! |
| 306 | II->setIsPoisoned(); |
Douglas Gregor | eee242f | 2011-10-27 09:33:13 +0000 | [diff] [blame] | 307 | if (II->isFromAST()) |
| 308 | II->setChangedSinceDeserialization(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | /// HandlePragmaSystemHeader - Implement #pragma GCC system_header. We know |
| 313 | /// that the whole directive has been parsed. |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 314 | void Preprocessor::HandlePragmaSystemHeader(Token &SysHeaderTok) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 315 | if (isInPrimaryFile()) { |
| 316 | Diag(SysHeaderTok, diag::pp_pragma_sysheader_in_main_file); |
| 317 | return; |
| 318 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 319 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 320 | // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc. |
Ted Kremenek | 35c10c2 | 2008-11-20 01:45:11 +0000 | [diff] [blame] | 321 | PreprocessorLexer *TheLexer = getCurrentFileLexer(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 323 | // Mark the file as a system header. |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 324 | HeaderInfo.MarkFileSystemHeader(TheLexer->getFileEntry()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 325 | |
| 326 | |
Chris Lattner | 6896a37 | 2009-06-15 05:02:34 +0000 | [diff] [blame] | 327 | PresumedLoc PLoc = SourceMgr.getPresumedLoc(SysHeaderTok.getLocation()); |
Douglas Gregor | cb7b1e1 | 2010-11-12 07:15:47 +0000 | [diff] [blame] | 328 | if (PLoc.isInvalid()) |
| 329 | return; |
| 330 | |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 331 | unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Chris Lattner | 784c257 | 2011-05-22 22:10:16 +0000 | [diff] [blame] | 333 | // Notify the client, if desired, that we are in a new source file. |
| 334 | if (Callbacks) |
| 335 | Callbacks->FileChanged(SysHeaderTok.getLocation(), |
| 336 | PPCallbacks::SystemHeaderPragma, SrcMgr::C_System); |
| 337 | |
Chris Lattner | 6896a37 | 2009-06-15 05:02:34 +0000 | [diff] [blame] | 338 | // Emit a line marker. This will change any source locations from this point |
| 339 | // forward to realize they are in a system header. |
| 340 | // Create a line note with this information. |
| 341 | SourceMgr.AddLineNote(SysHeaderTok.getLocation(), PLoc.getLine(), FilenameID, |
| 342 | false, false, true, false); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /// HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah. |
| 346 | /// |
Chris Lattner | d217773 | 2007-07-20 16:59:19 +0000 | [diff] [blame] | 347 | void Preprocessor::HandlePragmaDependency(Token &DependencyTok) { |
| 348 | Token FilenameTok; |
Ted Kremenek | 68a91d5 | 2008-11-18 01:12:54 +0000 | [diff] [blame] | 349 | CurPPLexer->LexIncludeFilename(FilenameTok); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 350 | |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 351 | // If the token kind is EOD, the error has already been diagnosed. |
| 352 | if (FilenameTok.is(tok::eod)) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 353 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 354 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 355 | // Reserve a buffer to get the spelling. |
Chris Lattner | a139481 | 2010-01-10 01:35:12 +0000 | [diff] [blame] | 356 | llvm::SmallString<128> FilenameBuffer; |
Douglas Gregor | 453091c | 2010-03-16 22:30:13 +0000 | [diff] [blame] | 357 | bool Invalid = false; |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 358 | StringRef Filename = getSpelling(FilenameTok, FilenameBuffer, &Invalid); |
Douglas Gregor | 453091c | 2010-03-16 22:30:13 +0000 | [diff] [blame] | 359 | if (Invalid) |
| 360 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 361 | |
Chris Lattner | a139481 | 2010-01-10 01:35:12 +0000 | [diff] [blame] | 362 | bool isAngled = |
| 363 | GetIncludeFilenameSpelling(FilenameTok.getLocation(), Filename); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 364 | // If GetIncludeFilenameSpelling set the start ptr to null, there was an |
| 365 | // error. |
Chris Lattner | a139481 | 2010-01-10 01:35:12 +0000 | [diff] [blame] | 366 | if (Filename.empty()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 367 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 368 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 369 | // Search include directories for this file. |
| 370 | const DirectoryLookup *CurDir; |
Douglas Gregor | fba18aa | 2011-09-15 22:00:41 +0000 | [diff] [blame] | 371 | const FileEntry *File = LookupFile(Filename, isAngled, 0, CurDir, NULL, NULL, |
| 372 | NULL); |
Chris Lattner | 56b05c8 | 2008-11-18 08:02:48 +0000 | [diff] [blame] | 373 | if (File == 0) { |
Eli Friedman | f84139a | 2011-08-30 23:07:51 +0000 | [diff] [blame] | 374 | if (!SuppressIncludeNotFoundError) |
| 375 | Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; |
Chris Lattner | 56b05c8 | 2008-11-18 08:02:48 +0000 | [diff] [blame] | 376 | return; |
| 377 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 379 | const FileEntry *CurFile = getCurrentFileLexer()->getFileEntry(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 380 | |
| 381 | // If this file is older than the file it depends on, emit a diagnostic. |
| 382 | if (CurFile && CurFile->getModificationTime() < File->getModificationTime()) { |
| 383 | // Lex tokens at the end of the message and include them in the message. |
| 384 | std::string Message; |
| 385 | Lex(DependencyTok); |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 386 | while (DependencyTok.isNot(tok::eod)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 387 | Message += getSpelling(DependencyTok) + " "; |
| 388 | Lex(DependencyTok); |
| 389 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | |
Chris Lattner | 96de259 | 2010-09-05 23:16:09 +0000 | [diff] [blame] | 391 | // Remove the trailing ' ' if present. |
| 392 | if (!Message.empty()) |
| 393 | Message.erase(Message.end()-1); |
Chris Lattner | 56b05c8 | 2008-11-18 08:02:48 +0000 | [diff] [blame] | 394 | Diag(FilenameTok, diag::pp_out_of_date_dependency) << Message; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 395 | } |
| 396 | } |
| 397 | |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 398 | /// HandlePragmaComment - Handle the microsoft #pragma comment extension. The |
| 399 | /// syntax is: |
| 400 | /// #pragma comment(linker, "foo") |
| 401 | /// 'linker' is one of five identifiers: compiler, exestr, lib, linker, user. |
| 402 | /// "foo" is a string, which is fully macro expanded, and permits string |
Gabor Greif | d7ee349 | 2009-03-17 11:39:38 +0000 | [diff] [blame] | 403 | /// concatenation, embedded escape characters etc. See MSDN for more details. |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 404 | void Preprocessor::HandlePragmaComment(Token &Tok) { |
| 405 | SourceLocation CommentLoc = Tok.getLocation(); |
| 406 | Lex(Tok); |
| 407 | if (Tok.isNot(tok::l_paren)) { |
| 408 | Diag(CommentLoc, diag::err_pragma_comment_malformed); |
| 409 | return; |
| 410 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 411 | |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 412 | // Read the identifier. |
| 413 | Lex(Tok); |
| 414 | if (Tok.isNot(tok::identifier)) { |
| 415 | Diag(CommentLoc, diag::err_pragma_comment_malformed); |
| 416 | return; |
| 417 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 418 | |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 419 | // Verify that this is one of the 5 whitelisted options. |
| 420 | // FIXME: warn that 'exestr' is deprecated. |
| 421 | const IdentifierInfo *II = Tok.getIdentifierInfo(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 422 | if (!II->isStr("compiler") && !II->isStr("exestr") && !II->isStr("lib") && |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 423 | !II->isStr("linker") && !II->isStr("user")) { |
| 424 | Diag(Tok.getLocation(), diag::err_pragma_comment_unknown_kind); |
| 425 | return; |
| 426 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 427 | |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 428 | // Read the optional string if present. |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 429 | Lex(Tok); |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 430 | std::string ArgumentString; |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 431 | if (Tok.is(tok::comma)) { |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 432 | Lex(Tok); // eat the comma. |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 433 | |
| 434 | // We need at least one string. |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 435 | if (Tok.isNot(tok::string_literal)) { |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 436 | Diag(Tok.getLocation(), diag::err_pragma_comment_malformed); |
| 437 | return; |
| 438 | } |
| 439 | |
| 440 | // String concatenation allows multiple strings, which can even come from |
| 441 | // macro expansion. |
| 442 | // "foo " "bar" "Baz" |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 443 | SmallVector<Token, 4> StrToks; |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 444 | while (Tok.is(tok::string_literal)) { |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 445 | StrToks.push_back(Tok); |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 446 | Lex(Tok); |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | // Concatenate and parse the strings. |
| 450 | StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this); |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 451 | assert(Literal.isAscii() && "Didn't allow wide strings in"); |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 452 | if (Literal.hadError) |
| 453 | return; |
| 454 | if (Literal.Pascal) { |
| 455 | Diag(StrToks[0].getLocation(), diag::err_pragma_comment_malformed); |
| 456 | return; |
| 457 | } |
| 458 | |
Jay Foad | 65aa688 | 2011-06-21 15:13:30 +0000 | [diff] [blame] | 459 | ArgumentString = Literal.GetString(); |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 461 | |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 462 | // FIXME: If the kind is "compiler" warn if the string is present (it is |
| 463 | // ignored). |
| 464 | // FIXME: 'lib' requires a comment string. |
| 465 | // FIXME: 'linker' requires a comment string, and has a specific list of |
| 466 | // things that are allowable. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 467 | |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 468 | if (Tok.isNot(tok::r_paren)) { |
| 469 | Diag(Tok.getLocation(), diag::err_pragma_comment_malformed); |
| 470 | return; |
| 471 | } |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 472 | Lex(Tok); // eat the r_paren. |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 473 | |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 474 | if (Tok.isNot(tok::eod)) { |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 475 | Diag(Tok.getLocation(), diag::err_pragma_comment_malformed); |
| 476 | return; |
| 477 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 478 | |
Chris Lattner | a9d9145 | 2009-01-16 18:59:23 +0000 | [diff] [blame] | 479 | // If the pragma is lexically sound, notify any interested PPCallbacks. |
Chris Lattner | 172e336 | 2009-01-16 19:01:46 +0000 | [diff] [blame] | 480 | if (Callbacks) |
| 481 | Callbacks->PragmaComment(CommentLoc, II, ArgumentString); |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 482 | } |
| 483 | |
Michael J. Spencer | 301669b | 2010-09-27 06:19:02 +0000 | [diff] [blame] | 484 | /// HandlePragmaMessage - Handle the microsoft and gcc #pragma message |
| 485 | /// extension. The syntax is: |
| 486 | /// #pragma message(string) |
| 487 | /// OR, in GCC mode: |
| 488 | /// #pragma message string |
| 489 | /// string is a string, which is fully macro expanded, and permits string |
| 490 | /// concatenation, embedded escape characters, etc... See MSDN for more details. |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 491 | void Preprocessor::HandlePragmaMessage(Token &Tok) { |
| 492 | SourceLocation MessageLoc = Tok.getLocation(); |
| 493 | Lex(Tok); |
Michael J. Spencer | 301669b | 2010-09-27 06:19:02 +0000 | [diff] [blame] | 494 | bool ExpectClosingParen = false; |
Michael J. Spencer | d83fc54 | 2010-09-27 06:34:47 +0000 | [diff] [blame] | 495 | switch (Tok.getKind()) { |
Michael J. Spencer | 301669b | 2010-09-27 06:19:02 +0000 | [diff] [blame] | 496 | case tok::l_paren: |
| 497 | // We have a MSVC style pragma message. |
| 498 | ExpectClosingParen = true; |
| 499 | // Read the string. |
| 500 | Lex(Tok); |
| 501 | break; |
| 502 | case tok::string_literal: |
| 503 | // We have a GCC style pragma message, and we just read the string. |
| 504 | break; |
| 505 | default: |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 506 | Diag(MessageLoc, diag::err_pragma_message_malformed); |
| 507 | return; |
| 508 | } |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 509 | |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 510 | // We need at least one string. |
| 511 | if (Tok.isNot(tok::string_literal)) { |
| 512 | Diag(Tok.getLocation(), diag::err_pragma_message_malformed); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | // String concatenation allows multiple strings, which can even come from |
| 517 | // macro expansion. |
| 518 | // "foo " "bar" "Baz" |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 519 | SmallVector<Token, 4> StrToks; |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 520 | while (Tok.is(tok::string_literal)) { |
| 521 | StrToks.push_back(Tok); |
| 522 | Lex(Tok); |
| 523 | } |
| 524 | |
| 525 | // Concatenate and parse the strings. |
| 526 | StringLiteralParser Literal(&StrToks[0], StrToks.size(), *this); |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 527 | assert(Literal.isAscii() && "Didn't allow wide strings in"); |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 528 | if (Literal.hadError) |
| 529 | return; |
| 530 | if (Literal.Pascal) { |
| 531 | Diag(StrToks[0].getLocation(), diag::err_pragma_message_malformed); |
| 532 | return; |
| 533 | } |
| 534 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 535 | StringRef MessageString(Literal.GetString()); |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 536 | |
Michael J. Spencer | 301669b | 2010-09-27 06:19:02 +0000 | [diff] [blame] | 537 | if (ExpectClosingParen) { |
| 538 | if (Tok.isNot(tok::r_paren)) { |
| 539 | Diag(Tok.getLocation(), diag::err_pragma_message_malformed); |
| 540 | return; |
| 541 | } |
| 542 | Lex(Tok); // eat the r_paren. |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 543 | } |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 544 | |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 545 | if (Tok.isNot(tok::eod)) { |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 546 | Diag(Tok.getLocation(), diag::err_pragma_message_malformed); |
| 547 | return; |
| 548 | } |
| 549 | |
| 550 | // Output the message. |
| 551 | Diag(MessageLoc, diag::warn_pragma_message) << MessageString; |
| 552 | |
| 553 | // If the pragma is lexically sound, notify any interested PPCallbacks. |
| 554 | if (Callbacks) |
| 555 | Callbacks->PragmaMessage(MessageLoc, MessageString); |
| 556 | } |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 557 | |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 558 | /// ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro. |
| 559 | /// Return the IdentifierInfo* associated with the macro to push or pop. |
| 560 | IdentifierInfo *Preprocessor::ParsePragmaPushOrPopMacro(Token &Tok) { |
| 561 | // Remember the pragma token location. |
| 562 | Token PragmaTok = Tok; |
| 563 | |
| 564 | // Read the '('. |
| 565 | Lex(Tok); |
| 566 | if (Tok.isNot(tok::l_paren)) { |
| 567 | Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed) |
| 568 | << getSpelling(PragmaTok); |
| 569 | return 0; |
| 570 | } |
| 571 | |
| 572 | // Read the macro name string. |
| 573 | Lex(Tok); |
| 574 | if (Tok.isNot(tok::string_literal)) { |
| 575 | Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed) |
| 576 | << getSpelling(PragmaTok); |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | // Remember the macro string. |
| 581 | std::string StrVal = getSpelling(Tok); |
| 582 | |
| 583 | // Read the ')'. |
| 584 | Lex(Tok); |
| 585 | if (Tok.isNot(tok::r_paren)) { |
| 586 | Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed) |
| 587 | << getSpelling(PragmaTok); |
| 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' && |
| 592 | "Invalid string token!"); |
| 593 | |
| 594 | // Create a Token from the string. |
| 595 | Token MacroTok; |
| 596 | MacroTok.startToken(); |
Abramo Bagnara | c4bf2b9 | 2010-12-22 08:23:18 +0000 | [diff] [blame] | 597 | MacroTok.setKind(tok::raw_identifier); |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 598 | CreateString(&StrVal[1], StrVal.size() - 2, MacroTok); |
| 599 | |
| 600 | // Get the IdentifierInfo of MacroToPushTok. |
| 601 | return LookUpIdentifierInfo(MacroTok); |
| 602 | } |
| 603 | |
| 604 | /// HandlePragmaPushMacro - Handle #pragma push_macro. |
| 605 | /// The syntax is: |
| 606 | /// #pragma push_macro("macro") |
| 607 | void Preprocessor::HandlePragmaPushMacro(Token &PushMacroTok) { |
| 608 | // Parse the pragma directive and get the macro IdentifierInfo*. |
| 609 | IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PushMacroTok); |
| 610 | if (!IdentInfo) return; |
| 611 | |
| 612 | // Get the MacroInfo associated with IdentInfo. |
| 613 | MacroInfo *MI = getMacroInfo(IdentInfo); |
| 614 | |
| 615 | MacroInfo *MacroCopyToPush = 0; |
| 616 | if (MI) { |
| 617 | // Make a clone of MI. |
| 618 | MacroCopyToPush = CloneMacroInfo(*MI); |
| 619 | |
| 620 | // Allow the original MacroInfo to be redefined later. |
| 621 | MI->setIsAllowRedefinitionsWithoutWarning(true); |
| 622 | } |
| 623 | |
| 624 | // Push the cloned MacroInfo so we can retrieve it later. |
| 625 | PragmaPushMacroInfo[IdentInfo].push_back(MacroCopyToPush); |
| 626 | } |
| 627 | |
Ted Kremenek | b275e3d | 2010-10-19 17:40:50 +0000 | [diff] [blame] | 628 | /// HandlePragmaPopMacro - Handle #pragma pop_macro. |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 629 | /// The syntax is: |
| 630 | /// #pragma pop_macro("macro") |
| 631 | void Preprocessor::HandlePragmaPopMacro(Token &PopMacroTok) { |
| 632 | SourceLocation MessageLoc = PopMacroTok.getLocation(); |
| 633 | |
| 634 | // Parse the pragma directive and get the macro IdentifierInfo*. |
| 635 | IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PopMacroTok); |
| 636 | if (!IdentInfo) return; |
| 637 | |
| 638 | // Find the vector<MacroInfo*> associated with the macro. |
| 639 | llvm::DenseMap<IdentifierInfo*, std::vector<MacroInfo*> >::iterator iter = |
| 640 | PragmaPushMacroInfo.find(IdentInfo); |
| 641 | if (iter != PragmaPushMacroInfo.end()) { |
| 642 | // Release the MacroInfo currently associated with IdentInfo. |
| 643 | MacroInfo *CurrentMI = getMacroInfo(IdentInfo); |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 644 | if (CurrentMI) { |
| 645 | if (CurrentMI->isWarnIfUnused()) |
| 646 | WarnUnusedMacroLocs.erase(CurrentMI->getDefinitionLoc()); |
| 647 | ReleaseMacroInfo(CurrentMI); |
| 648 | } |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 649 | |
| 650 | // Get the MacroInfo we want to reinstall. |
| 651 | MacroInfo *MacroToReInstall = iter->second.back(); |
| 652 | |
| 653 | // Reinstall the previously pushed macro. |
| 654 | setMacroInfo(IdentInfo, MacroToReInstall); |
| 655 | |
| 656 | // Pop PragmaPushMacroInfo stack. |
| 657 | iter->second.pop_back(); |
| 658 | if (iter->second.size() == 0) |
| 659 | PragmaPushMacroInfo.erase(iter); |
| 660 | } else { |
| 661 | Diag(MessageLoc, diag::warn_pragma_pop_macro_no_push) |
| 662 | << IdentInfo->getName(); |
| 663 | } |
| 664 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 665 | |
| 666 | /// AddPragmaHandler - Add the specified pragma handler to the preprocessor. |
| 667 | /// If 'Namespace' is non-null, then it is a token required to exist on the |
| 668 | /// pragma line before the pragma string starts, e.g. "STDC" or "GCC". |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 669 | void Preprocessor::AddPragmaHandler(StringRef Namespace, |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 670 | PragmaHandler *Handler) { |
| 671 | PragmaNamespace *InsertNS = PragmaHandlers; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 672 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 673 | // If this is specified to be in a namespace, step down into it. |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 674 | if (!Namespace.empty()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 675 | // If there is already a pragma handler with the name of this namespace, |
| 676 | // we either have an error (directive with the same name as a namespace) or |
| 677 | // we already have the namespace to insert into. |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 678 | if (PragmaHandler *Existing = PragmaHandlers->FindHandler(Namespace)) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 679 | InsertNS = Existing->getIfNamespace(); |
| 680 | assert(InsertNS != 0 && "Cannot have a pragma namespace and pragma" |
| 681 | " handler with the same name!"); |
| 682 | } else { |
| 683 | // Otherwise, this namespace doesn't exist yet, create and insert the |
| 684 | // handler for it. |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 685 | InsertNS = new PragmaNamespace(Namespace); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 686 | PragmaHandlers->AddPragma(InsertNS); |
| 687 | } |
| 688 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 689 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 690 | // Check to make sure we don't already have a pragma for this identifier. |
| 691 | assert(!InsertNS->FindHandler(Handler->getName()) && |
| 692 | "Pragma handler already exists for this identifier!"); |
| 693 | InsertNS->AddPragma(Handler); |
| 694 | } |
| 695 | |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 696 | /// RemovePragmaHandler - Remove the specific pragma handler from the |
| 697 | /// preprocessor. If \arg Namespace is non-null, then it should be the |
| 698 | /// namespace that \arg Handler was added to. It is an error to remove |
| 699 | /// a handler that has not been registered. |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 700 | void Preprocessor::RemovePragmaHandler(StringRef Namespace, |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 701 | PragmaHandler *Handler) { |
| 702 | PragmaNamespace *NS = PragmaHandlers; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 703 | |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 704 | // If this is specified to be in a namespace, step down into it. |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 705 | if (!Namespace.empty()) { |
| 706 | PragmaHandler *Existing = PragmaHandlers->FindHandler(Namespace); |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 707 | assert(Existing && "Namespace containing handler does not exist!"); |
| 708 | |
| 709 | NS = Existing->getIfNamespace(); |
| 710 | assert(NS && "Invalid namespace, registered as a regular pragma handler!"); |
| 711 | } |
| 712 | |
| 713 | NS->RemovePragmaHandler(Handler); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 714 | |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 715 | // If this is a non-default namespace and it is now empty, remove |
| 716 | // it. |
Argyrios Kyrtzidis | ce52bb3 | 2012-01-06 00:22:09 +0000 | [diff] [blame^] | 717 | if (NS != PragmaHandlers && NS->IsEmpty()) { |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 718 | PragmaHandlers->RemovePragmaHandler(NS); |
Argyrios Kyrtzidis | ce52bb3 | 2012-01-06 00:22:09 +0000 | [diff] [blame^] | 719 | delete NS; |
| 720 | } |
Daniel Dunbar | 4095080 | 2008-10-04 19:17:46 +0000 | [diff] [blame] | 721 | } |
| 722 | |
Peter Collingbourne | 9d3f5f7 | 2011-02-14 01:42:24 +0000 | [diff] [blame] | 723 | bool Preprocessor::LexOnOffSwitch(tok::OnOffSwitch &Result) { |
| 724 | Token Tok; |
| 725 | LexUnexpandedToken(Tok); |
| 726 | |
| 727 | if (Tok.isNot(tok::identifier)) { |
| 728 | Diag(Tok, diag::ext_on_off_switch_syntax); |
| 729 | return true; |
| 730 | } |
| 731 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 732 | if (II->isStr("ON")) |
| 733 | Result = tok::OOS_ON; |
| 734 | else if (II->isStr("OFF")) |
| 735 | Result = tok::OOS_OFF; |
| 736 | else if (II->isStr("DEFAULT")) |
| 737 | Result = tok::OOS_DEFAULT; |
| 738 | else { |
| 739 | Diag(Tok, diag::ext_on_off_switch_syntax); |
| 740 | return true; |
| 741 | } |
| 742 | |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 743 | // Verify that this is followed by EOD. |
Peter Collingbourne | 9d3f5f7 | 2011-02-14 01:42:24 +0000 | [diff] [blame] | 744 | LexUnexpandedToken(Tok); |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 745 | if (Tok.isNot(tok::eod)) |
| 746 | Diag(Tok, diag::ext_pragma_syntax_eod); |
Peter Collingbourne | 9d3f5f7 | 2011-02-14 01:42:24 +0000 | [diff] [blame] | 747 | return false; |
| 748 | } |
| 749 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 750 | namespace { |
Chris Lattner | 2243449 | 2007-12-19 19:38:36 +0000 | [diff] [blame] | 751 | /// PragmaOnceHandler - "#pragma once" marks the file as atomically included. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 752 | struct PragmaOnceHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 753 | PragmaOnceHandler() : PragmaHandler("once") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 754 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 755 | Token &OnceTok) { |
Chris Lattner | 35410d5 | 2009-04-14 05:07:49 +0000 | [diff] [blame] | 756 | PP.CheckEndOfDirective("pragma once"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 757 | PP.HandlePragmaOnce(OnceTok); |
| 758 | } |
| 759 | }; |
| 760 | |
Chris Lattner | 2243449 | 2007-12-19 19:38:36 +0000 | [diff] [blame] | 761 | /// PragmaMarkHandler - "#pragma mark ..." is ignored by the compiler, and the |
| 762 | /// rest of the line is not lexed. |
| 763 | struct PragmaMarkHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 764 | PragmaMarkHandler() : PragmaHandler("mark") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 765 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 766 | Token &MarkTok) { |
Chris Lattner | 2243449 | 2007-12-19 19:38:36 +0000 | [diff] [blame] | 767 | PP.HandlePragmaMark(); |
| 768 | } |
| 769 | }; |
| 770 | |
| 771 | /// PragmaPoisonHandler - "#pragma poison x" marks x as not usable. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 772 | struct PragmaPoisonHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 773 | PragmaPoisonHandler() : PragmaHandler("poison") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 774 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 775 | Token &PoisonTok) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 776 | PP.HandlePragmaPoison(PoisonTok); |
| 777 | } |
| 778 | }; |
| 779 | |
Chris Lattner | 2243449 | 2007-12-19 19:38:36 +0000 | [diff] [blame] | 780 | /// PragmaSystemHeaderHandler - "#pragma system_header" marks the current file |
| 781 | /// as a system header, which silences warnings in it. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 782 | struct PragmaSystemHeaderHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 783 | PragmaSystemHeaderHandler() : PragmaHandler("system_header") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 784 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 785 | Token &SHToken) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 786 | PP.HandlePragmaSystemHeader(SHToken); |
Chris Lattner | 35410d5 | 2009-04-14 05:07:49 +0000 | [diff] [blame] | 787 | PP.CheckEndOfDirective("pragma"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 788 | } |
| 789 | }; |
| 790 | struct PragmaDependencyHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 791 | PragmaDependencyHandler() : PragmaHandler("dependency") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 792 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 793 | Token &DepToken) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 794 | PP.HandlePragmaDependency(DepToken); |
| 795 | } |
| 796 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 797 | |
Daniel Dunbar | abf7b72 | 2010-07-28 15:40:33 +0000 | [diff] [blame] | 798 | struct PragmaDebugHandler : public PragmaHandler { |
| 799 | PragmaDebugHandler() : PragmaHandler("__debug") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 800 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 801 | Token &DepToken) { |
Daniel Dunbar | abf7b72 | 2010-07-28 15:40:33 +0000 | [diff] [blame] | 802 | Token Tok; |
| 803 | PP.LexUnexpandedToken(Tok); |
| 804 | if (Tok.isNot(tok::identifier)) { |
Douglas Gregor | 6493a4d | 2010-08-30 15:15:34 +0000 | [diff] [blame] | 805 | PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid); |
Daniel Dunbar | abf7b72 | 2010-07-28 15:40:33 +0000 | [diff] [blame] | 806 | return; |
| 807 | } |
| 808 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 809 | |
Daniel Dunbar | 5505413 | 2010-08-17 22:32:48 +0000 | [diff] [blame] | 810 | if (II->isStr("assert")) { |
David Blaikie | b219cfc | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 811 | llvm_unreachable("This is an assertion!"); |
Daniel Dunbar | abf7b72 | 2010-07-28 15:40:33 +0000 | [diff] [blame] | 812 | } else if (II->isStr("crash")) { |
Daniel Dunbar | 5505413 | 2010-08-17 22:32:48 +0000 | [diff] [blame] | 813 | *(volatile int*) 0x11 = 0; |
| 814 | } else if (II->isStr("llvm_fatal_error")) { |
| 815 | llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error"); |
| 816 | } else if (II->isStr("llvm_unreachable")) { |
| 817 | llvm_unreachable("#pragma clang __debug llvm_unreachable"); |
| 818 | } else if (II->isStr("overflow_stack")) { |
| 819 | DebugOverflowStack(); |
Daniel Dunbar | ff759a6 | 2010-08-18 23:09:23 +0000 | [diff] [blame] | 820 | } else if (II->isStr("handle_crash")) { |
| 821 | llvm::CrashRecoveryContext *CRC =llvm::CrashRecoveryContext::GetCurrent(); |
| 822 | if (CRC) |
| 823 | CRC->HandleCrash(); |
Daniel Dunbar | 5505413 | 2010-08-17 22:32:48 +0000 | [diff] [blame] | 824 | } else { |
| 825 | PP.Diag(Tok, diag::warn_pragma_debug_unexpected_command) |
| 826 | << II->getName(); |
Daniel Dunbar | abf7b72 | 2010-07-28 15:40:33 +0000 | [diff] [blame] | 827 | } |
| 828 | } |
| 829 | |
Francois Pichet | 1066c6c | 2011-05-25 16:15:03 +0000 | [diff] [blame] | 830 | // Disable MSVC warning about runtime stack overflow. |
| 831 | #ifdef _MSC_VER |
| 832 | #pragma warning(disable : 4717) |
| 833 | #endif |
Daniel Dunbar | abf7b72 | 2010-07-28 15:40:33 +0000 | [diff] [blame] | 834 | void DebugOverflowStack() { |
| 835 | DebugOverflowStack(); |
| 836 | } |
Francois Pichet | 1066c6c | 2011-05-25 16:15:03 +0000 | [diff] [blame] | 837 | #ifdef _MSC_VER |
| 838 | #pragma warning(default : 4717) |
| 839 | #endif |
| 840 | |
Daniel Dunbar | abf7b72 | 2010-07-28 15:40:33 +0000 | [diff] [blame] | 841 | }; |
| 842 | |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 843 | /// PragmaDiagnosticHandler - e.g. '#pragma GCC diagnostic ignored "-Wformat"' |
| 844 | struct PragmaDiagnosticHandler : public PragmaHandler { |
Douglas Gregor | c09ce12 | 2011-06-22 19:41:48 +0000 | [diff] [blame] | 845 | private: |
| 846 | const char *Namespace; |
Chris Lattner | 04ae2df | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 847 | public: |
Douglas Gregor | c09ce12 | 2011-06-22 19:41:48 +0000 | [diff] [blame] | 848 | explicit PragmaDiagnosticHandler(const char *NS) : |
| 849 | PragmaHandler("diagnostic"), Namespace(NS) {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 850 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 851 | Token &DiagToken) { |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 852 | SourceLocation DiagLoc = DiagToken.getLocation(); |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 853 | Token Tok; |
| 854 | PP.LexUnexpandedToken(Tok); |
| 855 | if (Tok.isNot(tok::identifier)) { |
Douglas Gregor | 6493a4d | 2010-08-30 15:15:34 +0000 | [diff] [blame] | 856 | PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid); |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 857 | return; |
| 858 | } |
| 859 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
Douglas Gregor | c09ce12 | 2011-06-22 19:41:48 +0000 | [diff] [blame] | 860 | PPCallbacks *Callbacks = PP.getPPCallbacks(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 861 | |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 862 | diag::Mapping Map; |
| 863 | if (II->isStr("warning")) |
| 864 | Map = diag::MAP_WARNING; |
| 865 | else if (II->isStr("error")) |
| 866 | Map = diag::MAP_ERROR; |
| 867 | else if (II->isStr("ignored")) |
| 868 | Map = diag::MAP_IGNORE; |
| 869 | else if (II->isStr("fatal")) |
| 870 | Map = diag::MAP_FATAL; |
Douglas Gregor | 6493a4d | 2010-08-30 15:15:34 +0000 | [diff] [blame] | 871 | else if (II->isStr("pop")) { |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 872 | if (!PP.getDiagnostics().popMappings(DiagLoc)) |
Douglas Gregor | 6493a4d | 2010-08-30 15:15:34 +0000 | [diff] [blame] | 873 | PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop); |
Douglas Gregor | c09ce12 | 2011-06-22 19:41:48 +0000 | [diff] [blame] | 874 | else if (Callbacks) |
| 875 | Callbacks->PragmaDiagnosticPop(DiagLoc, Namespace); |
Douglas Gregor | 6493a4d | 2010-08-30 15:15:34 +0000 | [diff] [blame] | 876 | return; |
| 877 | } else if (II->isStr("push")) { |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 878 | PP.getDiagnostics().pushMappings(DiagLoc); |
Douglas Gregor | c09ce12 | 2011-06-22 19:41:48 +0000 | [diff] [blame] | 879 | if (Callbacks) |
| 880 | Callbacks->PragmaDiagnosticPush(DiagLoc, Namespace); |
Chris Lattner | 04ae2df | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 881 | return; |
| 882 | } else { |
Douglas Gregor | 6493a4d | 2010-08-30 15:15:34 +0000 | [diff] [blame] | 883 | PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid); |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 884 | return; |
| 885 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 886 | |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 887 | PP.LexUnexpandedToken(Tok); |
| 888 | |
| 889 | // We need at least one string. |
| 890 | if (Tok.isNot(tok::string_literal)) { |
| 891 | PP.Diag(Tok.getLocation(), diag::warn_pragma_diagnostic_invalid_token); |
| 892 | return; |
| 893 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 894 | |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 895 | // String concatenation allows multiple strings, which can even come from |
| 896 | // macro expansion. |
| 897 | // "foo " "bar" "Baz" |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 898 | SmallVector<Token, 4> StrToks; |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 899 | while (Tok.is(tok::string_literal)) { |
| 900 | StrToks.push_back(Tok); |
| 901 | PP.LexUnexpandedToken(Tok); |
| 902 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 903 | |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 904 | if (Tok.isNot(tok::eod)) { |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 905 | PP.Diag(Tok.getLocation(), diag::warn_pragma_diagnostic_invalid_token); |
| 906 | return; |
| 907 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 908 | |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 909 | // Concatenate and parse the strings. |
| 910 | StringLiteralParser Literal(&StrToks[0], StrToks.size(), PP); |
Douglas Gregor | 5cee119 | 2011-07-27 05:40:30 +0000 | [diff] [blame] | 911 | assert(Literal.isAscii() && "Didn't allow wide strings in"); |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 912 | if (Literal.hadError) |
| 913 | return; |
| 914 | if (Literal.Pascal) { |
Douglas Gregor | 6493a4d | 2010-08-30 15:15:34 +0000 | [diff] [blame] | 915 | PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid); |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 916 | return; |
| 917 | } |
Chris Lattner | 04ae2df | 2009-07-12 21:18:45 +0000 | [diff] [blame] | 918 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 919 | StringRef WarningName(Literal.GetString()); |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 920 | |
| 921 | if (WarningName.size() < 3 || WarningName[0] != '-' || |
| 922 | WarningName[1] != 'W') { |
| 923 | PP.Diag(StrToks[0].getLocation(), |
| 924 | diag::warn_pragma_diagnostic_invalid_option); |
| 925 | return; |
| 926 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 927 | |
Argyrios Kyrtzidis | 477aab6 | 2011-05-25 05:05:01 +0000 | [diff] [blame] | 928 | if (PP.getDiagnostics().setDiagnosticGroupMapping(WarningName.substr(2), |
Argyrios Kyrtzidis | 0827408 | 2010-12-15 18:44:22 +0000 | [diff] [blame] | 929 | Map, DiagLoc)) |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 930 | PP.Diag(StrToks[0].getLocation(), |
| 931 | diag::warn_pragma_diagnostic_unknown_warning) << WarningName; |
Douglas Gregor | c09ce12 | 2011-06-22 19:41:48 +0000 | [diff] [blame] | 932 | else if (Callbacks) |
| 933 | Callbacks->PragmaDiagnostic(DiagLoc, Namespace, Map, WarningName); |
Chris Lattner | edaf877 | 2009-04-19 23:16:58 +0000 | [diff] [blame] | 934 | } |
| 935 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 936 | |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 937 | /// PragmaCommentHandler - "#pragma comment ...". |
| 938 | struct PragmaCommentHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 939 | PragmaCommentHandler() : PragmaHandler("comment") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 940 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 941 | Token &CommentTok) { |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 942 | PP.HandlePragmaComment(CommentTok); |
| 943 | } |
| 944 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 945 | |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 946 | /// PragmaMessageHandler - "#pragma message("...")". |
| 947 | struct PragmaMessageHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 948 | PragmaMessageHandler() : PragmaHandler("message") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 949 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 950 | Token &CommentTok) { |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 951 | PP.HandlePragmaMessage(CommentTok); |
| 952 | } |
| 953 | }; |
| 954 | |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 955 | /// PragmaPushMacroHandler - "#pragma push_macro" saves the value of the |
| 956 | /// macro on the top of the stack. |
| 957 | struct PragmaPushMacroHandler : public PragmaHandler { |
| 958 | PragmaPushMacroHandler() : PragmaHandler("push_macro") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 959 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 960 | Token &PushMacroTok) { |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 961 | PP.HandlePragmaPushMacro(PushMacroTok); |
| 962 | } |
| 963 | }; |
| 964 | |
| 965 | |
| 966 | /// PragmaPopMacroHandler - "#pragma pop_macro" sets the value of the |
| 967 | /// macro to the value on the top of the stack. |
| 968 | struct PragmaPopMacroHandler : public PragmaHandler { |
| 969 | PragmaPopMacroHandler() : PragmaHandler("pop_macro") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 970 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 971 | Token &PopMacroTok) { |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 972 | PP.HandlePragmaPopMacro(PopMacroTok); |
| 973 | } |
| 974 | }; |
| 975 | |
Chris Lattner | 062f232 | 2009-04-19 21:20:35 +0000 | [diff] [blame] | 976 | // Pragma STDC implementations. |
Chris Lattner | 6c5cf4a | 2009-04-19 21:50:08 +0000 | [diff] [blame] | 977 | |
Chris Lattner | 062f232 | 2009-04-19 21:20:35 +0000 | [diff] [blame] | 978 | /// PragmaSTDC_FENV_ACCESSHandler - "#pragma STDC FENV_ACCESS ...". |
| 979 | struct PragmaSTDC_FENV_ACCESSHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 980 | PragmaSTDC_FENV_ACCESSHandler() : PragmaHandler("FENV_ACCESS") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 981 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 982 | Token &Tok) { |
Peter Collingbourne | 9d3f5f7 | 2011-02-14 01:42:24 +0000 | [diff] [blame] | 983 | tok::OnOffSwitch OOS; |
| 984 | if (PP.LexOnOffSwitch(OOS)) |
| 985 | return; |
| 986 | if (OOS == tok::OOS_ON) |
Chris Lattner | 4d8aac3 | 2009-04-19 21:55:32 +0000 | [diff] [blame] | 987 | PP.Diag(Tok, diag::warn_stdc_fenv_access_not_supported); |
Chris Lattner | 062f232 | 2009-04-19 21:20:35 +0000 | [diff] [blame] | 988 | } |
| 989 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 990 | |
Chris Lattner | 062f232 | 2009-04-19 21:20:35 +0000 | [diff] [blame] | 991 | /// PragmaSTDC_CX_LIMITED_RANGEHandler - "#pragma STDC CX_LIMITED_RANGE ...". |
| 992 | struct PragmaSTDC_CX_LIMITED_RANGEHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 993 | PragmaSTDC_CX_LIMITED_RANGEHandler() |
| 994 | : PragmaHandler("CX_LIMITED_RANGE") {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 995 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 996 | Token &Tok) { |
Peter Collingbourne | 9d3f5f7 | 2011-02-14 01:42:24 +0000 | [diff] [blame] | 997 | tok::OnOffSwitch OOS; |
| 998 | PP.LexOnOffSwitch(OOS); |
Chris Lattner | 062f232 | 2009-04-19 21:20:35 +0000 | [diff] [blame] | 999 | } |
| 1000 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1001 | |
Chris Lattner | 062f232 | 2009-04-19 21:20:35 +0000 | [diff] [blame] | 1002 | /// PragmaSTDC_UnknownHandler - "#pragma STDC ...". |
| 1003 | struct PragmaSTDC_UnknownHandler : public PragmaHandler { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 1004 | PragmaSTDC_UnknownHandler() {} |
Douglas Gregor | 80c60f7 | 2010-09-09 22:45:38 +0000 | [diff] [blame] | 1005 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 1006 | Token &UnknownTok) { |
Chris Lattner | 6c5cf4a | 2009-04-19 21:50:08 +0000 | [diff] [blame] | 1007 | // C99 6.10.6p2, unknown forms are not allowed. |
Chris Lattner | f545be5 | 2009-04-19 21:25:37 +0000 | [diff] [blame] | 1008 | PP.Diag(UnknownTok, diag::ext_stdc_pragma_ignored); |
Chris Lattner | 062f232 | 2009-04-19 21:20:35 +0000 | [diff] [blame] | 1009 | } |
| 1010 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1011 | |
John McCall | 8dfac0b | 2011-09-30 05:12:12 +0000 | [diff] [blame] | 1012 | /// PragmaARCCFCodeAuditedHandler - |
| 1013 | /// #pragma clang arc_cf_code_audited begin/end |
| 1014 | struct PragmaARCCFCodeAuditedHandler : public PragmaHandler { |
| 1015 | PragmaARCCFCodeAuditedHandler() : PragmaHandler("arc_cf_code_audited") {} |
| 1016 | virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, |
| 1017 | Token &NameTok) { |
| 1018 | SourceLocation Loc = NameTok.getLocation(); |
| 1019 | bool IsBegin; |
| 1020 | |
| 1021 | Token Tok; |
| 1022 | |
| 1023 | // Lex the 'begin' or 'end'. |
| 1024 | PP.LexUnexpandedToken(Tok); |
| 1025 | const IdentifierInfo *BeginEnd = Tok.getIdentifierInfo(); |
| 1026 | if (BeginEnd && BeginEnd->isStr("begin")) { |
| 1027 | IsBegin = true; |
| 1028 | } else if (BeginEnd && BeginEnd->isStr("end")) { |
| 1029 | IsBegin = false; |
| 1030 | } else { |
| 1031 | PP.Diag(Tok.getLocation(), diag::err_pp_arc_cf_code_audited_syntax); |
| 1032 | return; |
| 1033 | } |
| 1034 | |
| 1035 | // Verify that this is followed by EOD. |
| 1036 | PP.LexUnexpandedToken(Tok); |
| 1037 | if (Tok.isNot(tok::eod)) |
| 1038 | PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma"; |
| 1039 | |
| 1040 | // The start location of the active audit. |
| 1041 | SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedLoc(); |
| 1042 | |
| 1043 | // The start location we want after processing this. |
| 1044 | SourceLocation NewLoc; |
| 1045 | |
| 1046 | if (IsBegin) { |
| 1047 | // Complain about attempts to re-enter an audit. |
| 1048 | if (BeginLoc.isValid()) { |
| 1049 | PP.Diag(Loc, diag::err_pp_double_begin_of_arc_cf_code_audited); |
| 1050 | PP.Diag(BeginLoc, diag::note_pragma_entered_here); |
| 1051 | } |
| 1052 | NewLoc = Loc; |
| 1053 | } else { |
| 1054 | // Complain about attempts to leave an audit that doesn't exist. |
| 1055 | if (!BeginLoc.isValid()) { |
| 1056 | PP.Diag(Loc, diag::err_pp_unmatched_end_of_arc_cf_code_audited); |
| 1057 | return; |
| 1058 | } |
| 1059 | NewLoc = SourceLocation(); |
| 1060 | } |
| 1061 | |
| 1062 | PP.setPragmaARCCFCodeAuditedLoc(NewLoc); |
| 1063 | } |
| 1064 | }; |
| 1065 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1066 | } // end anonymous namespace |
| 1067 | |
| 1068 | |
| 1069 | /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas: |
| 1070 | /// #pragma GCC poison/system_header/dependency and #pragma once. |
| 1071 | void Preprocessor::RegisterBuiltinPragmas() { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 1072 | AddPragmaHandler(new PragmaOnceHandler()); |
| 1073 | AddPragmaHandler(new PragmaMarkHandler()); |
Chris Lattner | f47724b | 2010-08-17 15:55:45 +0000 | [diff] [blame] | 1074 | AddPragmaHandler(new PragmaPushMacroHandler()); |
| 1075 | AddPragmaHandler(new PragmaPopMacroHandler()); |
Michael J. Spencer | 301669b | 2010-09-27 06:19:02 +0000 | [diff] [blame] | 1076 | AddPragmaHandler(new PragmaMessageHandler()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1077 | |
Chris Lattner | e8fa06e | 2009-05-12 18:21:11 +0000 | [diff] [blame] | 1078 | // #pragma GCC ... |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 1079 | AddPragmaHandler("GCC", new PragmaPoisonHandler()); |
| 1080 | AddPragmaHandler("GCC", new PragmaSystemHeaderHandler()); |
| 1081 | AddPragmaHandler("GCC", new PragmaDependencyHandler()); |
Douglas Gregor | c09ce12 | 2011-06-22 19:41:48 +0000 | [diff] [blame] | 1082 | AddPragmaHandler("GCC", new PragmaDiagnosticHandler("GCC")); |
Chris Lattner | e8fa06e | 2009-05-12 18:21:11 +0000 | [diff] [blame] | 1083 | // #pragma clang ... |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 1084 | AddPragmaHandler("clang", new PragmaPoisonHandler()); |
| 1085 | AddPragmaHandler("clang", new PragmaSystemHeaderHandler()); |
Daniel Dunbar | abf7b72 | 2010-07-28 15:40:33 +0000 | [diff] [blame] | 1086 | AddPragmaHandler("clang", new PragmaDebugHandler()); |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 1087 | AddPragmaHandler("clang", new PragmaDependencyHandler()); |
Douglas Gregor | c09ce12 | 2011-06-22 19:41:48 +0000 | [diff] [blame] | 1088 | AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang")); |
John McCall | 8dfac0b | 2011-09-30 05:12:12 +0000 | [diff] [blame] | 1089 | AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler()); |
Chris Lattner | e8fa06e | 2009-05-12 18:21:11 +0000 | [diff] [blame] | 1090 | |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 1091 | AddPragmaHandler("STDC", new PragmaSTDC_FENV_ACCESSHandler()); |
| 1092 | AddPragmaHandler("STDC", new PragmaSTDC_CX_LIMITED_RANGEHandler()); |
Chris Lattner | 062f232 | 2009-04-19 21:20:35 +0000 | [diff] [blame] | 1093 | AddPragmaHandler("STDC", new PragmaSTDC_UnknownHandler()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Chris Lattner | 636c5ef | 2009-01-16 08:21:25 +0000 | [diff] [blame] | 1095 | // MS extensions. |
Francois Pichet | 62ec1f2 | 2011-09-17 17:15:52 +0000 | [diff] [blame] | 1096 | if (Features.MicrosoftExt) { |
Argyrios Kyrtzidis | 9b36c3f | 2010-07-13 09:07:17 +0000 | [diff] [blame] | 1097 | AddPragmaHandler(new PragmaCommentHandler()); |
Chris Lattner | abfe094 | 2010-06-26 17:11:39 +0000 | [diff] [blame] | 1098 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1099 | } |