clang  14.0.0git
Pragma.cpp
Go to the documentation of this file.
1 //===- Pragma.cpp - Pragma registration and handling ----------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the PragmaHandler/PragmaTable interfaces and implements
10 // pragma related methods of the Preprocessor class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/Lex/Pragma.h"
15 #include "clang/Basic/CLWarnings.h"
16 #include "clang/Basic/Diagnostic.h"
20 #include "clang/Basic/LLVM.h"
22 #include "clang/Basic/Module.h"
25 #include "clang/Basic/TokenKinds.h"
26 #include "clang/Lex/HeaderSearch.h"
28 #include "clang/Lex/Lexer.h"
30 #include "clang/Lex/MacroInfo.h"
31 #include "clang/Lex/ModuleLoader.h"
32 #include "clang/Lex/PPCallbacks.h"
33 #include "clang/Lex/Preprocessor.h"
36 #include "clang/Lex/Token.h"
37 #include "clang/Lex/TokenLexer.h"
38 #include "llvm/ADT/ArrayRef.h"
39 #include "llvm/ADT/DenseMap.h"
40 #include "llvm/ADT/Optional.h"
41 #include "llvm/ADT/STLExtras.h"
42 #include "llvm/ADT/SmallString.h"
43 #include "llvm/ADT/SmallVector.h"
44 #include "llvm/ADT/StringRef.h"
45 #include "llvm/ADT/StringSwitch.h"
46 #include "llvm/Support/Compiler.h"
47 #include "llvm/Support/ErrorHandling.h"
48 #include "llvm/Support/Timer.h"
49 #include <algorithm>
50 #include <cassert>
51 #include <cstddef>
52 #include <cstdint>
53 #include <limits>
54 #include <string>
55 #include <utility>
56 #include <vector>
57 
58 using namespace clang;
59 
60 // Out-of-line destructor to provide a home for the class.
62 
63 //===----------------------------------------------------------------------===//
64 // EmptyPragmaHandler Implementation.
65 //===----------------------------------------------------------------------===//
66 
68 
70  PragmaIntroducer Introducer,
71  Token &FirstToken) {}
72 
73 //===----------------------------------------------------------------------===//
74 // PragmaNamespace Implementation.
75 //===----------------------------------------------------------------------===//
76 
77 /// FindHandler - Check to see if there is already a handler for the
78 /// specified name. If not, return the handler for the null identifier if it
79 /// exists, otherwise return null. If IgnoreNull is true (the default) then
80 /// the null handler isn't returned on failure to match.
82  bool IgnoreNull) const {
83  auto I = Handlers.find(Name);
84  if (I != Handlers.end())
85  return I->getValue().get();
86  if (IgnoreNull)
87  return nullptr;
88  I = Handlers.find(StringRef());
89  if (I != Handlers.end())
90  return I->getValue().get();
91  return nullptr;
92 }
93 
95  assert(!Handlers.count(Handler->getName()) &&
96  "A handler with this name is already registered in this namespace");
97  Handlers[Handler->getName()].reset(Handler);
98 }
99 
101  auto I = Handlers.find(Handler->getName());
102  assert(I != Handlers.end() &&
103  "Handler not registered in this namespace");
104  // Release ownership back to the caller.
105  I->getValue().release();
106  Handlers.erase(I);
107 }
108 
110  PragmaIntroducer Introducer, Token &Tok) {
111  // Read the 'namespace' that the directive is in, e.g. STDC. Do not macro
112  // expand it, the user can have a STDC #define, that should not affect this.
113  PP.LexUnexpandedToken(Tok);
114 
115  // Get the handler for this token. If there is no handler, ignore the pragma.
116  PragmaHandler *Handler
118  : StringRef(),
119  /*IgnoreNull=*/false);
120  if (!Handler) {
121  PP.Diag(Tok, diag::warn_pragma_ignored);
122  return;
123  }
124 
125  // Otherwise, pass it down.
126  Handler->HandlePragma(PP, Introducer, Tok);
127 }
128 
129 //===----------------------------------------------------------------------===//
130 // Preprocessor Pragma Directive Handling.
131 //===----------------------------------------------------------------------===//
132 
133 namespace {
134 // TokenCollector provides the option to collect tokens that were "read"
135 // and return them to the stream to be read later.
136 // Currently used when reading _Pragma/__pragma directives.
137 struct TokenCollector {
138  Preprocessor &Self;
139  bool Collect;
140  SmallVector<Token, 3> Tokens;
141  Token &Tok;
142 
143  void lex() {
144  if (Collect)
145  Tokens.push_back(Tok);
146  Self.Lex(Tok);
147  }
148 
149  void revert() {
150  assert(Collect && "did not collect tokens");
151  assert(!Tokens.empty() && "collected unexpected number of tokens");
152 
153  // Push the ( "string" ) tokens into the token stream.
154  auto Toks = std::make_unique<Token[]>(Tokens.size());
155  std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get());
156  Toks[Tokens.size() - 1] = Tok;
157  Self.EnterTokenStream(std::move(Toks), Tokens.size(),
158  /*DisableMacroExpansion*/ true,
159  /*IsReinject*/ true);
160 
161  // ... and return the pragma token unchanged.
162  Tok = *Tokens.begin();
163  }
164 };
165 } // namespace
166 
167 /// HandlePragmaDirective - The "\#pragma" directive has been parsed. Lex the
168 /// rest of the pragma, passing it to the registered pragma handlers.
169 void Preprocessor::HandlePragmaDirective(PragmaIntroducer Introducer) {
170  if (Callbacks)
171  Callbacks->PragmaDirective(Introducer.Loc, Introducer.Kind);
172 
173  if (!PragmasEnabled)
174  return;
175 
176  ++NumPragma;
177 
178  // Invoke the first level of pragma handlers which reads the namespace id.
179  Token Tok;
180  PragmaHandlers->HandlePragma(*this, Introducer, Tok);
181 
182  // If the pragma handler didn't read the rest of the line, consume it now.
183  if ((CurTokenLexer && CurTokenLexer->isParsingPreprocessorDirective())
184  || (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective))
186 }
187 
188 /// Handle_Pragma - Read a _Pragma directive, slice it up, process it, then
189 /// return the first token after the directive. The _Pragma token has just
190 /// been read into 'Tok'.
191 void Preprocessor::Handle_Pragma(Token &Tok) {
192  // C11 6.10.3.4/3:
193  // all pragma unary operator expressions within [a completely
194  // macro-replaced preprocessing token sequence] are [...] processed [after
195  // rescanning is complete]
196  //
197  // This means that we execute _Pragma operators in two cases:
198  //
199  // 1) on token sequences that would otherwise be produced as the output of
200  // phase 4 of preprocessing, and
201  // 2) on token sequences formed as the macro-replaced token sequence of a
202  // macro argument
203  //
204  // Case #2 appears to be a wording bug: only _Pragmas that would survive to
205  // the end of phase 4 should actually be executed. Discussion on the WG14
206  // mailing list suggests that a _Pragma operator is notionally checked early,
207  // but only pragmas that survive to the end of phase 4 should be executed.
208  //
209  // In Case #2, we check the syntax now, but then put the tokens back into the
210  // token stream for later consumption.
211 
212  TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
213 
214  // Remember the pragma token location.
215  SourceLocation PragmaLoc = Tok.getLocation();
216 
217  // Read the '('.
218  Toks.lex();
219  if (Tok.isNot(tok::l_paren)) {
220  Diag(PragmaLoc, diag::err__Pragma_malformed);
221  return;
222  }
223 
224  // Read the '"..."'.
225  Toks.lex();
226  if (!tok::isStringLiteral(Tok.getKind())) {
227  Diag(PragmaLoc, diag::err__Pragma_malformed);
228  // Skip bad tokens, and the ')', if present.
229  if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof))
230  Lex(Tok);
231  while (Tok.isNot(tok::r_paren) &&
232  !Tok.isAtStartOfLine() &&
233  Tok.isNot(tok::eof))
234  Lex(Tok);
235  if (Tok.is(tok::r_paren))
236  Lex(Tok);
237  return;
238  }
239 
240  if (Tok.hasUDSuffix()) {
241  Diag(Tok, diag::err_invalid_string_udl);
242  // Skip this token, and the ')', if present.
243  Lex(Tok);
244  if (Tok.is(tok::r_paren))
245  Lex(Tok);
246  return;
247  }
248 
249  // Remember the string.
250  Token StrTok = Tok;
251 
252  // Read the ')'.
253  Toks.lex();
254  if (Tok.isNot(tok::r_paren)) {
255  Diag(PragmaLoc, diag::err__Pragma_malformed);
256  return;
257  }
258 
259  // If we're expanding a macro argument, put the tokens back.
260  if (InMacroArgPreExpansion) {
261  Toks.revert();
262  return;
263  }
264 
265  SourceLocation RParenLoc = Tok.getLocation();
266  std::string StrVal = getSpelling(StrTok);
267 
268  // The _Pragma is lexically sound. Destringize according to C11 6.10.9.1:
269  // "The string literal is destringized by deleting any encoding prefix,
270  // deleting the leading and trailing double-quotes, replacing each escape
271  // sequence \" by a double-quote, and replacing each escape sequence \\ by a
272  // single backslash."
273  if (StrVal[0] == 'L' || StrVal[0] == 'U' ||
274  (StrVal[0] == 'u' && StrVal[1] != '8'))
275  StrVal.erase(StrVal.begin());
276  else if (StrVal[0] == 'u')
277  StrVal.erase(StrVal.begin(), StrVal.begin() + 2);
278 
279  if (StrVal[0] == 'R') {
280  // FIXME: C++11 does not specify how to handle raw-string-literals here.
281  // We strip off the 'R', the quotes, the d-char-sequences, and the parens.
282  assert(StrVal[1] == '"' && StrVal[StrVal.size() - 1] == '"' &&
283  "Invalid raw string token!");
284 
285  // Measure the length of the d-char-sequence.
286  unsigned NumDChars = 0;
287  while (StrVal[2 + NumDChars] != '(') {
288  assert(NumDChars < (StrVal.size() - 5) / 2 &&
289  "Invalid raw string token!");
290  ++NumDChars;
291  }
292  assert(StrVal[StrVal.size() - 2 - NumDChars] == ')');
293 
294  // Remove 'R " d-char-sequence' and 'd-char-sequence "'. We'll replace the
295  // parens below.
296  StrVal.erase(0, 2 + NumDChars);
297  StrVal.erase(StrVal.size() - 1 - NumDChars);
298  } else {
299  assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' &&
300  "Invalid string token!");
301 
302  // Remove escaped quotes and escapes.
303  unsigned ResultPos = 1;
304  for (size_t i = 1, e = StrVal.size() - 1; i != e; ++i) {
305  // Skip escapes. \\ -> '\' and \" -> '"'.
306  if (StrVal[i] == '\\' && i + 1 < e &&
307  (StrVal[i + 1] == '\\' || StrVal[i + 1] == '"'))
308  ++i;
309  StrVal[ResultPos++] = StrVal[i];
310  }
311  StrVal.erase(StrVal.begin() + ResultPos, StrVal.end() - 1);
312  }
313 
314  // Remove the front quote, replacing it with a space, so that the pragma
315  // contents appear to have a space before them.
316  StrVal[0] = ' ';
317 
318  // Replace the terminating quote with a \n.
319  StrVal[StrVal.size()-1] = '\n';
320 
321  // Plop the string (including the newline and trailing null) into a buffer
322  // where we can lex it.
323  Token TmpTok;
324  TmpTok.startToken();
325  CreateString(StrVal, TmpTok);
326  SourceLocation TokLoc = TmpTok.getLocation();
327 
328  // Make and enter a lexer object so that we lex and expand the tokens just
329  // like any others.
330  Lexer *TL = Lexer::Create_PragmaLexer(TokLoc, PragmaLoc, RParenLoc,
331  StrVal.size(), *this);
332 
333  EnterSourceFileWithLexer(TL, nullptr);
334 
335  // With everything set up, lex this as a #pragma directive.
336  HandlePragmaDirective({PIK__Pragma, PragmaLoc});
337 
338  // Finally, return whatever came after the pragma directive.
339  return Lex(Tok);
340 }
341 
342 /// HandleMicrosoft__pragma - Like Handle_Pragma except the pragma text
343 /// is not enclosed within a string literal.
344 void Preprocessor::HandleMicrosoft__pragma(Token &Tok) {
345  // During macro pre-expansion, check the syntax now but put the tokens back
346  // into the token stream for later consumption. Same as Handle_Pragma.
347  TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
348 
349  // Remember the pragma token location.
350  SourceLocation PragmaLoc = Tok.getLocation();
351 
352  // Read the '('.
353  Toks.lex();
354  if (Tok.isNot(tok::l_paren)) {
355  Diag(PragmaLoc, diag::err__Pragma_malformed);
356  return;
357  }
358 
359  // Get the tokens enclosed within the __pragma(), as well as the final ')'.
360  SmallVector<Token, 32> PragmaToks;
361  int NumParens = 0;
362  Toks.lex();
363  while (Tok.isNot(tok::eof)) {
364  PragmaToks.push_back(Tok);
365  if (Tok.is(tok::l_paren))
366  NumParens++;
367  else if (Tok.is(tok::r_paren) && NumParens-- == 0)
368  break;
369  Toks.lex();
370  }
371 
372  if (Tok.is(tok::eof)) {
373  Diag(PragmaLoc, diag::err_unterminated___pragma);
374  return;
375  }
376 
377  // If we're expanding a macro argument, put the tokens back.
378  if (InMacroArgPreExpansion) {
379  Toks.revert();
380  return;
381  }
382 
383  PragmaToks.front().setFlag(Token::LeadingSpace);
384 
385  // Replace the ')' with an EOD to mark the end of the pragma.
386  PragmaToks.back().setKind(tok::eod);
387 
388  Token *TokArray = new Token[PragmaToks.size()];
389  std::copy(PragmaToks.begin(), PragmaToks.end(), TokArray);
390 
391  // Push the tokens onto the stack.
392  EnterTokenStream(TokArray, PragmaToks.size(), true, true,
393  /*IsReinject*/ false);
394 
395  // With everything set up, lex this as a #pragma directive.
396  HandlePragmaDirective({PIK___pragma, PragmaLoc});
397 
398  // Finally, return whatever came after the pragma directive.
399  return Lex(Tok);
400 }
401 
402 /// HandlePragmaOnce - Handle \#pragma once. OnceTok is the 'once'.
404  // Don't honor the 'once' when handling the primary source file, unless
405  // this is a prefix to a TU, which indicates we're generating a PCH file, or
406  // when the main file is a header (e.g. when -xc-header is provided on the
407  // commandline).
409  Diag(OnceTok, diag::pp_pragma_once_in_main_file);
410  return;
411  }
412 
413  // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc.
414  // Mark the file as a once-only file now.
415  HeaderInfo.MarkFileIncludeOnce(getCurrentFileLexer()->getFileEntry());
416 }
417 
419  assert(CurPPLexer && "No current lexer?");
420 
421  SmallString<64> Buffer;
422  CurLexer->ReadToEndOfLine(&Buffer);
423  if (Callbacks)
424  Callbacks->PragmaMark(MarkTok.getLocation(), Buffer);
425 }
426 
427 /// HandlePragmaPoison - Handle \#pragma GCC poison. PoisonTok is the 'poison'.
429  Token Tok;
430 
431  while (true) {
432  // Read the next token to poison. While doing this, pretend that we are
433  // skipping while reading the identifier to poison.
434  // This avoids errors on code like:
435  // #pragma GCC poison X
436  // #pragma GCC poison X
437  if (CurPPLexer) CurPPLexer->LexingRawMode = true;
438  LexUnexpandedToken(Tok);
439  if (CurPPLexer) CurPPLexer->LexingRawMode = false;
440 
441  // If we reached the end of line, we're done.
442  if (Tok.is(tok::eod)) return;
443 
444  // Can only poison identifiers.
445  if (Tok.isNot(tok::raw_identifier)) {
446  Diag(Tok, diag::err_pp_invalid_poison);
447  return;
448  }
449 
450  // Look up the identifier info for the token. We disabled identifier lookup
451  // by saying we're skipping contents, so we need to do this manually.
453 
454  // Already poisoned.
455  if (II->isPoisoned()) continue;
456 
457  // If this is a macro identifier, emit a warning.
458  if (isMacroDefined(II))
459  Diag(Tok, diag::pp_poisoning_existing_macro);
460 
461  // Finally, poison it!
462  II->setIsPoisoned();
463  if (II->isFromAST())
465  }
466 }
467 
468 /// HandlePragmaSystemHeader - Implement \#pragma GCC system_header. We know
469 /// that the whole directive has been parsed.
471  if (isInPrimaryFile()) {
472  Diag(SysHeaderTok, diag::pp_pragma_sysheader_in_main_file);
473  return;
474  }
475 
476  // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc.
478 
479  // Mark the file as a system header.
480  HeaderInfo.MarkFileSystemHeader(TheLexer->getFileEntry());
481 
482  PresumedLoc PLoc = SourceMgr.getPresumedLoc(SysHeaderTok.getLocation());
483  if (PLoc.isInvalid())
484  return;
485 
486  unsigned FilenameID = SourceMgr.getLineTableFilenameID(PLoc.getFilename());
487 
488  // Notify the client, if desired, that we are in a new source file.
489  if (Callbacks)
490  Callbacks->FileChanged(SysHeaderTok.getLocation(),
492 
493  // Emit a line marker. This will change any source locations from this point
494  // forward to realize they are in a system header.
495  // Create a line note with this information.
496  SourceMgr.AddLineNote(SysHeaderTok.getLocation(), PLoc.getLine() + 1,
497  FilenameID, /*IsEntry=*/false, /*IsExit=*/false,
499 }
500 
503  bool SuppressIncludeNotFoundError) {
504  Token FilenameTok;
505  if (PP.LexHeaderName(FilenameTok, /*AllowConcatenation*/ false))
506  return llvm::None;
507 
508  // If the next token wasn't a header-name, diagnose the error.
509  if (FilenameTok.isNot(tok::header_name)) {
510  PP.Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename);
511  return llvm::None;
512  }
513 
514  // Reserve a buffer to get the spelling.
515  SmallString<128> FilenameBuffer;
516  bool Invalid = false;
517  StringRef Filename = PP.getSpelling(FilenameTok, FilenameBuffer, &Invalid);
518  if (Invalid)
519  return llvm::None;
520 
521  bool isAngled =
523  // If GetIncludeFilenameSpelling set the start ptr to null, there was an
524  // error.
525  if (Filename.empty())
526  return llvm::None;
527 
528  // Search include directories for this file.
529  File = PP.LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr,
530  nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
531  nullptr);
532  if (!File) {
533  if (!SuppressIncludeNotFoundError)
534  PP.Diag(FilenameTok, diag::err_pp_file_not_found) << Filename;
535  return llvm::None;
536  }
537 
538  return FilenameTok;
539 }
540 
541 /// HandlePragmaIncludeInstead - Handle \#pragma clang include_instead(header).
543  // Get the current file lexer we're looking at. Ignore _Pragma 'files' etc.
545 
546  if (!SourceMgr.isInSystemHeader(Tok.getLocation())) {
547  Diag(Tok, diag::err_pragma_include_instead_not_sysheader);
548  return;
549  }
550 
551  Lex(Tok);
552  if (Tok.isNot(tok::l_paren)) {
553  Diag(Tok, diag::err_expected) << "(";
554  return;
555  }
556 
558  llvm::Optional<Token> FilenameTok =
559  LexHeader(*this, File, SuppressIncludeNotFoundError);
560  if (!FilenameTok)
561  return;
562 
563  Lex(Tok);
564  if (Tok.isNot(tok::r_paren)) {
565  Diag(Tok, diag::err_expected) << ")";
566  return;
567  }
568 
569  SmallString<128> FilenameBuffer;
570  StringRef Filename = getSpelling(*FilenameTok, FilenameBuffer);
571  HeaderInfo.AddFileAlias(TheLexer->getFileEntry(), Filename);
572 }
573 
574 /// HandlePragmaDependency - Handle \#pragma GCC dependency "foo" blah.
577  llvm::Optional<Token> FilenameTok =
578  LexHeader(*this, File, SuppressIncludeNotFoundError);
579  if (!FilenameTok)
580  return;
581 
582  const FileEntry *CurFile = getCurrentFileLexer()->getFileEntry();
583 
584  // If this file is older than the file it depends on, emit a diagnostic.
585  if (CurFile && CurFile->getModificationTime() < File->getModificationTime()) {
586  // Lex tokens at the end of the message and include them in the message.
587  std::string Message;
588  Lex(DependencyTok);
589  while (DependencyTok.isNot(tok::eod)) {
590  Message += getSpelling(DependencyTok) + " ";
591  Lex(DependencyTok);
592  }
593 
594  // Remove the trailing ' ' if present.
595  if (!Message.empty())
596  Message.erase(Message.end()-1);
597  Diag(*FilenameTok, diag::pp_out_of_date_dependency) << Message;
598  }
599 }
600 
601 /// ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
602 /// Return the IdentifierInfo* associated with the macro to push or pop.
604  // Remember the pragma token location.
605  Token PragmaTok = Tok;
606 
607  // Read the '('.
608  Lex(Tok);
609  if (Tok.isNot(tok::l_paren)) {
610  Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
611  << getSpelling(PragmaTok);
612  return nullptr;
613  }
614 
615  // Read the macro name string.
616  Lex(Tok);
617  if (Tok.isNot(tok::string_literal)) {
618  Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
619  << getSpelling(PragmaTok);
620  return nullptr;
621  }
622 
623  if (Tok.hasUDSuffix()) {
624  Diag(Tok, diag::err_invalid_string_udl);
625  return nullptr;
626  }
627 
628  // Remember the macro string.
629  std::string StrVal = getSpelling(Tok);
630 
631  // Read the ')'.
632  Lex(Tok);
633  if (Tok.isNot(tok::r_paren)) {
634  Diag(PragmaTok.getLocation(), diag::err_pragma_push_pop_macro_malformed)
635  << getSpelling(PragmaTok);
636  return nullptr;
637  }
638 
639  assert(StrVal[0] == '"' && StrVal[StrVal.size()-1] == '"' &&
640  "Invalid string token!");
641 
642  // Create a Token from the string.
643  Token MacroTok;
644  MacroTok.startToken();
645  MacroTok.setKind(tok::raw_identifier);
646  CreateString(StringRef(&StrVal[1], StrVal.size() - 2), MacroTok);
647 
648  // Get the IdentifierInfo of MacroToPushTok.
649  return LookUpIdentifierInfo(MacroTok);
650 }
651 
652 /// Handle \#pragma push_macro.
653 ///
654 /// The syntax is:
655 /// \code
656 /// #pragma push_macro("macro")
657 /// \endcode
659  // Parse the pragma directive and get the macro IdentifierInfo*.
660  IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PushMacroTok);
661  if (!IdentInfo) return;
662 
663  // Get the MacroInfo associated with IdentInfo.
664  MacroInfo *MI = getMacroInfo(IdentInfo);
665 
666  if (MI) {
667  // Allow the original MacroInfo to be redefined later.
669  }
670 
671  // Push the cloned MacroInfo so we can retrieve it later.
672  PragmaPushMacroInfo[IdentInfo].push_back(MI);
673 }
674 
675 /// Handle \#pragma pop_macro.
676 ///
677 /// The syntax is:
678 /// \code
679 /// #pragma pop_macro("macro")
680 /// \endcode
682  SourceLocation MessageLoc = PopMacroTok.getLocation();
683 
684  // Parse the pragma directive and get the macro IdentifierInfo*.
685  IdentifierInfo *IdentInfo = ParsePragmaPushOrPopMacro(PopMacroTok);
686  if (!IdentInfo) return;
687 
688  // Find the vector<MacroInfo*> associated with the macro.
689  llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>>::iterator iter =
690  PragmaPushMacroInfo.find(IdentInfo);
691  if (iter != PragmaPushMacroInfo.end()) {
692  // Forget the MacroInfo currently associated with IdentInfo.
693  if (MacroInfo *MI = getMacroInfo(IdentInfo)) {
694  if (MI->isWarnIfUnused())
695  WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
696  appendMacroDirective(IdentInfo, AllocateUndefMacroDirective(MessageLoc));
697  }
698 
699  // Get the MacroInfo we want to reinstall.
700  MacroInfo *MacroToReInstall = iter->second.back();
701 
702  if (MacroToReInstall)
703  // Reinstall the previously pushed macro.
704  appendDefMacroDirective(IdentInfo, MacroToReInstall, MessageLoc);
705 
706  // Pop PragmaPushMacroInfo stack.
707  iter->second.pop_back();
708  if (iter->second.empty())
709  PragmaPushMacroInfo.erase(iter);
710  } else {
711  Diag(MessageLoc, diag::warn_pragma_pop_macro_no_push)
712  << IdentInfo->getName();
713  }
714 }
715 
717  // We will either get a quoted filename or a bracketed filename, and we
718  // have to track which we got. The first filename is the source name,
719  // and the second name is the mapped filename. If the first is quoted,
720  // the second must be as well (cannot mix and match quotes and brackets).
721 
722  // Get the open paren
723  Lex(Tok);
724  if (Tok.isNot(tok::l_paren)) {
725  Diag(Tok, diag::warn_pragma_include_alias_expected) << "(";
726  return;
727  }
728 
729  // We expect either a quoted string literal, or a bracketed name
730  Token SourceFilenameTok;
731  if (LexHeaderName(SourceFilenameTok))
732  return;
733 
734  StringRef SourceFileName;
735  SmallString<128> FileNameBuffer;
736  if (SourceFilenameTok.is(tok::header_name)) {
737  SourceFileName = getSpelling(SourceFilenameTok, FileNameBuffer);
738  } else {
739  Diag(Tok, diag::warn_pragma_include_alias_expected_filename);
740  return;
741  }
742  FileNameBuffer.clear();
743 
744  // Now we expect a comma, followed by another include name
745  Lex(Tok);
746  if (Tok.isNot(tok::comma)) {
747  Diag(Tok, diag::warn_pragma_include_alias_expected) << ",";
748  return;
749  }
750 
751  Token ReplaceFilenameTok;
752  if (LexHeaderName(ReplaceFilenameTok))
753  return;
754 
755  StringRef ReplaceFileName;
756  if (ReplaceFilenameTok.is(tok::header_name)) {
757  ReplaceFileName = getSpelling(ReplaceFilenameTok, FileNameBuffer);
758  } else {
759  Diag(Tok, diag::warn_pragma_include_alias_expected_filename);
760  return;
761  }
762 
763  // Finally, we expect the closing paren
764  Lex(Tok);
765  if (Tok.isNot(tok::r_paren)) {
766  Diag(Tok, diag::warn_pragma_include_alias_expected) << ")";
767  return;
768  }
769 
770  // Now that we have the source and target filenames, we need to make sure
771  // they're both of the same type (angled vs non-angled)
772  StringRef OriginalSource = SourceFileName;
773 
774  bool SourceIsAngled =
775  GetIncludeFilenameSpelling(SourceFilenameTok.getLocation(),
776  SourceFileName);
777  bool ReplaceIsAngled =
778  GetIncludeFilenameSpelling(ReplaceFilenameTok.getLocation(),
779  ReplaceFileName);
780  if (!SourceFileName.empty() && !ReplaceFileName.empty() &&
781  (SourceIsAngled != ReplaceIsAngled)) {
782  unsigned int DiagID;
783  if (SourceIsAngled)
784  DiagID = diag::warn_pragma_include_alias_mismatch_angle;
785  else
786  DiagID = diag::warn_pragma_include_alias_mismatch_quote;
787 
788  Diag(SourceFilenameTok.getLocation(), DiagID)
789  << SourceFileName
790  << ReplaceFileName;
791 
792  return;
793  }
794 
795  // Now we can let the include handler know about this mapping
796  getHeaderSearchInfo().AddIncludeAlias(OriginalSource, ReplaceFileName);
797 }
798 
799 // Lex a component of a module name: either an identifier or a string literal;
800 // for components that can be expressed both ways, the two forms are equivalent.
802  Preprocessor &PP, Token &Tok,
803  std::pair<IdentifierInfo *, SourceLocation> &ModuleNameComponent,
804  bool First) {
805  PP.LexUnexpandedToken(Tok);
806  if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) {
807  StringLiteralParser Literal(Tok, PP);
808  if (Literal.hadError)
809  return true;
810  ModuleNameComponent = std::make_pair(
811  PP.getIdentifierInfo(Literal.GetString()), Tok.getLocation());
812  } else if (!Tok.isAnnotation() && Tok.getIdentifierInfo()) {
813  ModuleNameComponent =
814  std::make_pair(Tok.getIdentifierInfo(), Tok.getLocation());
815  } else {
816  PP.Diag(Tok.getLocation(), diag::err_pp_expected_module_name) << First;
817  return true;
818  }
819  return false;
820 }
821 
822 static bool LexModuleName(
823  Preprocessor &PP, Token &Tok,
824  llvm::SmallVectorImpl<std::pair<IdentifierInfo *, SourceLocation>>
825  &ModuleName) {
826  while (true) {
827  std::pair<IdentifierInfo*, SourceLocation> NameComponent;
828  if (LexModuleNameComponent(PP, Tok, NameComponent, ModuleName.empty()))
829  return true;
830  ModuleName.push_back(NameComponent);
831 
832  PP.LexUnexpandedToken(Tok);
833  if (Tok.isNot(tok::period))
834  return false;
835  }
836 }
837 
839  SourceLocation Loc = Tok.getLocation();
840 
841  std::pair<IdentifierInfo *, SourceLocation> ModuleNameLoc;
842  if (LexModuleNameComponent(*this, Tok, ModuleNameLoc, true))
843  return;
844  IdentifierInfo *ModuleName = ModuleNameLoc.first;
845 
846  LexUnexpandedToken(Tok);
847  if (Tok.isNot(tok::eod)) {
848  Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
850  }
851 
852  CurLexer->LexingRawMode = true;
853 
854  auto TryConsumeIdentifier = [&](StringRef Ident) -> bool {
855  if (Tok.getKind() != tok::raw_identifier ||
856  Tok.getRawIdentifier() != Ident)
857  return false;
858  CurLexer->Lex(Tok);
859  return true;
860  };
861 
862  // Scan forward looking for the end of the module.
863  const char *Start = CurLexer->getBufferLocation();
864  const char *End = nullptr;
865  unsigned NestingLevel = 1;
866  while (true) {
867  End = CurLexer->getBufferLocation();
868  CurLexer->Lex(Tok);
869 
870  if (Tok.is(tok::eof)) {
871  Diag(Loc, diag::err_pp_module_build_missing_end);
872  break;
873  }
874 
875  if (Tok.isNot(tok::hash) || !Tok.isAtStartOfLine()) {
876  // Token was part of module; keep going.
877  continue;
878  }
879 
880  // We hit something directive-shaped; check to see if this is the end
881  // of the module build.
882  CurLexer->ParsingPreprocessorDirective = true;
883  CurLexer->Lex(Tok);
884  if (TryConsumeIdentifier("pragma") && TryConsumeIdentifier("clang") &&
885  TryConsumeIdentifier("module")) {
886  if (TryConsumeIdentifier("build"))
887  // #pragma clang module build -> entering a nested module build.
888  ++NestingLevel;
889  else if (TryConsumeIdentifier("endbuild")) {
890  // #pragma clang module endbuild -> leaving a module build.
891  if (--NestingLevel == 0)
892  break;
893  }
894  // We should either be looking at the EOD or more of the current directive
895  // preceding the EOD. Either way we can ignore this token and keep going.
896  assert(Tok.getKind() != tok::eof && "missing EOD before EOF");
897  }
898  }
899 
900  CurLexer->LexingRawMode = false;
901 
902  // Load the extracted text as a preprocessed module.
903  assert(CurLexer->getBuffer().begin() <= Start &&
904  Start <= CurLexer->getBuffer().end() &&
905  CurLexer->getBuffer().begin() <= End &&
906  End <= CurLexer->getBuffer().end() &&
907  "module source range not contained within same file buffer");
908  TheModuleLoader.createModuleFromSource(Loc, ModuleName->getName(),
909  StringRef(Start, End - Start));
910 }
911 
913  Lex(Tok);
914  if (Tok.is(tok::l_paren)) {
915  Diag(Tok.getLocation(), diag::warn_pp_hdrstop_filename_ignored);
916 
917  std::string FileName;
918  if (!LexStringLiteral(Tok, FileName, "pragma hdrstop", false))
919  return;
920 
921  if (Tok.isNot(tok::r_paren)) {
922  Diag(Tok, diag::err_expected) << tok::r_paren;
923  return;
924  }
925  Lex(Tok);
926  }
927  if (Tok.isNot(tok::eod))
928  Diag(Tok.getLocation(), diag::ext_pp_extra_tokens_at_eol)
929  << "pragma hdrstop";
930 
932  SourceMgr.isInMainFile(Tok.getLocation())) {
933  assert(CurLexer && "no lexer for #pragma hdrstop processing");
934  Token &Result = Tok;
935  Result.startToken();
936  CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
937  CurLexer->cutOffLexing();
938  }
940  SkippingUntilPragmaHdrStop = false;
941 }
942 
943 /// AddPragmaHandler - Add the specified pragma handler to the preprocessor.
944 /// If 'Namespace' is non-null, then it is a token required to exist on the
945 /// pragma line before the pragma string starts, e.g. "STDC" or "GCC".
946 void Preprocessor::AddPragmaHandler(StringRef Namespace,
947  PragmaHandler *Handler) {
948  PragmaNamespace *InsertNS = PragmaHandlers.get();
949 
950  // If this is specified to be in a namespace, step down into it.
951  if (!Namespace.empty()) {
952  // If there is already a pragma handler with the name of this namespace,
953  // we either have an error (directive with the same name as a namespace) or
954  // we already have the namespace to insert into.
955  if (PragmaHandler *Existing = PragmaHandlers->FindHandler(Namespace)) {
956  InsertNS = Existing->getIfNamespace();
957  assert(InsertNS != nullptr && "Cannot have a pragma namespace and pragma"
958  " handler with the same name!");
959  } else {
960  // Otherwise, this namespace doesn't exist yet, create and insert the
961  // handler for it.
962  InsertNS = new PragmaNamespace(Namespace);
963  PragmaHandlers->AddPragma(InsertNS);
964  }
965  }
966 
967  // Check to make sure we don't already have a pragma for this identifier.
968  assert(!InsertNS->FindHandler(Handler->getName()) &&
969  "Pragma handler already exists for this identifier!");
970  InsertNS->AddPragma(Handler);
971 }
972 
973 /// RemovePragmaHandler - Remove the specific pragma handler from the
974 /// preprocessor. If \arg Namespace is non-null, then it should be the
975 /// namespace that \arg Handler was added to. It is an error to remove
976 /// a handler that has not been registered.
977 void Preprocessor::RemovePragmaHandler(StringRef Namespace,
978  PragmaHandler *Handler) {
979  PragmaNamespace *NS = PragmaHandlers.get();
980 
981  // If this is specified to be in a namespace, step down into it.
982  if (!Namespace.empty()) {
983  PragmaHandler *Existing = PragmaHandlers->FindHandler(Namespace);
984  assert(Existing && "Namespace containing handler does not exist!");
985 
986  NS = Existing->getIfNamespace();
987  assert(NS && "Invalid namespace, registered as a regular pragma handler!");
988  }
989 
990  NS->RemovePragmaHandler(Handler);
991 
992  // If this is a non-default namespace and it is now empty, remove it.
993  if (NS != PragmaHandlers.get() && NS->IsEmpty()) {
994  PragmaHandlers->RemovePragmaHandler(NS);
995  delete NS;
996  }
997 }
998 
1000  Token Tok;
1001  LexUnexpandedToken(Tok);
1002 
1003  if (Tok.isNot(tok::identifier)) {
1004  Diag(Tok, diag::ext_on_off_switch_syntax);
1005  return true;
1006  }
1007  IdentifierInfo *II = Tok.getIdentifierInfo();
1008  if (II->isStr("ON"))
1009  Result = tok::OOS_ON;
1010  else if (II->isStr("OFF"))
1011  Result = tok::OOS_OFF;
1012  else if (II->isStr("DEFAULT"))
1013  Result = tok::OOS_DEFAULT;
1014  else {
1015  Diag(Tok, diag::ext_on_off_switch_syntax);
1016  return true;
1017  }
1018 
1019  // Verify that this is followed by EOD.
1020  LexUnexpandedToken(Tok);
1021  if (Tok.isNot(tok::eod))
1022  Diag(Tok, diag::ext_pragma_syntax_eod);
1023  return false;
1024 }
1025 
1026 namespace {
1027 
1028 /// PragmaOnceHandler - "\#pragma once" marks the file as atomically included.
1029 struct PragmaOnceHandler : public PragmaHandler {
1030  PragmaOnceHandler() : PragmaHandler("once") {}
1031 
1032  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1033  Token &OnceTok) override {
1034  PP.CheckEndOfDirective("pragma once");
1035  PP.HandlePragmaOnce(OnceTok);
1036  }
1037 };
1038 
1039 /// PragmaMarkHandler - "\#pragma mark ..." is ignored by the compiler, and the
1040 /// rest of the line is not lexed.
1041 struct PragmaMarkHandler : public PragmaHandler {
1042  PragmaMarkHandler() : PragmaHandler("mark") {}
1043 
1044  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1045  Token &MarkTok) override {
1046  PP.HandlePragmaMark(MarkTok);
1047  }
1048 };
1049 
1050 /// PragmaPoisonHandler - "\#pragma poison x" marks x as not usable.
1051 struct PragmaPoisonHandler : public PragmaHandler {
1052  PragmaPoisonHandler() : PragmaHandler("poison") {}
1053 
1054  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1055  Token &PoisonTok) override {
1056  PP.HandlePragmaPoison();
1057  }
1058 };
1059 
1060 /// PragmaSystemHeaderHandler - "\#pragma system_header" marks the current file
1061 /// as a system header, which silences warnings in it.
1062 struct PragmaSystemHeaderHandler : public PragmaHandler {
1063  PragmaSystemHeaderHandler() : PragmaHandler("system_header") {}
1064 
1065  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1066  Token &SHToken) override {
1067  PP.HandlePragmaSystemHeader(SHToken);
1068  PP.CheckEndOfDirective("pragma");
1069  }
1070 };
1071 
1072 /// PragmaIncludeInsteadHandler - "\#pragma clang include_instead(header)" marks
1073 /// the current file as non-includable if the including header is not a system
1074 /// header.
1075 struct PragmaIncludeInsteadHandler : public PragmaHandler {
1076  PragmaIncludeInsteadHandler() : PragmaHandler("include_instead") {}
1077 
1078  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1079  Token &IIToken) override {
1080  PP.HandlePragmaIncludeInstead(IIToken);
1081  }
1082 };
1083 
1084 struct PragmaDependencyHandler : public PragmaHandler {
1085  PragmaDependencyHandler() : PragmaHandler("dependency") {}
1086 
1087  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1088  Token &DepToken) override {
1089  PP.HandlePragmaDependency(DepToken);
1090  }
1091 };
1092 
1093 struct PragmaDebugHandler : public PragmaHandler {
1094  PragmaDebugHandler() : PragmaHandler("__debug") {}
1095 
1096  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1097  Token &DebugToken) override {
1098  Token Tok;
1099  PP.LexUnexpandedToken(Tok);
1100  if (Tok.isNot(tok::identifier)) {
1101  PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
1102  return;
1103  }
1104  IdentifierInfo *II = Tok.getIdentifierInfo();
1105 
1106  if (II->isStr("assert")) {
1108  llvm_unreachable("This is an assertion!");
1109  } else if (II->isStr("crash")) {
1110  llvm::Timer T("crash", "pragma crash");
1111  llvm::TimeRegion R(&T);
1113  LLVM_BUILTIN_TRAP;
1114  } else if (II->isStr("parser_crash")) {
1116  Token Crasher;
1117  Crasher.startToken();
1118  Crasher.setKind(tok::annot_pragma_parser_crash);
1119  Crasher.setAnnotationRange(SourceRange(Tok.getLocation()));
1120  PP.EnterToken(Crasher, /*IsReinject*/ false);
1121  }
1122  } else if (II->isStr("dump")) {
1123  Token Identifier;
1125  if (auto *DumpII = Identifier.getIdentifierInfo()) {
1126  Token DumpAnnot;
1127  DumpAnnot.startToken();
1128  DumpAnnot.setKind(tok::annot_pragma_dump);
1129  DumpAnnot.setAnnotationRange(
1130  SourceRange(Tok.getLocation(), Identifier.getLocation()));
1131  DumpAnnot.setAnnotationValue(DumpII);
1133  PP.EnterToken(DumpAnnot, /*IsReinject*/false);
1134  } else {
1135  PP.Diag(Identifier, diag::warn_pragma_debug_missing_argument)
1136  << II->getName();
1137  }
1138  } else if (II->isStr("diag_mapping")) {
1139  Token DiagName;
1140  PP.LexUnexpandedToken(DiagName);
1141  if (DiagName.is(tok::eod))
1142  PP.getDiagnostics().dump();
1143  else if (DiagName.is(tok::string_literal) && !DiagName.hasUDSuffix()) {
1144  StringLiteralParser Literal(DiagName, PP);
1145  if (Literal.hadError)
1146  return;
1147  PP.getDiagnostics().dump(Literal.GetString());
1148  } else {
1149  PP.Diag(DiagName, diag::warn_pragma_debug_missing_argument)
1150  << II->getName();
1151  }
1152  } else if (II->isStr("llvm_fatal_error")) {
1154  llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error");
1155  } else if (II->isStr("llvm_unreachable")) {
1157  llvm_unreachable("#pragma clang __debug llvm_unreachable");
1158  } else if (II->isStr("macro")) {
1159  Token MacroName;
1160  PP.LexUnexpandedToken(MacroName);
1161  auto *MacroII = MacroName.getIdentifierInfo();
1162  if (MacroII)
1163  PP.dumpMacroInfo(MacroII);
1164  else
1165  PP.Diag(MacroName, diag::warn_pragma_debug_missing_argument)
1166  << II->getName();
1167  } else if (II->isStr("module_map")) {
1169  ModuleName;
1170  if (LexModuleName(PP, Tok, ModuleName))
1171  return;
1173  Module *M = nullptr;
1174  for (auto IIAndLoc : ModuleName) {
1175  M = MM.lookupModuleQualified(IIAndLoc.first->getName(), M);
1176  if (!M) {
1177  PP.Diag(IIAndLoc.second, diag::warn_pragma_debug_unknown_module)
1178  << IIAndLoc.first;
1179  return;
1180  }
1181  }
1182  M->dump();
1183  } else if (II->isStr("overflow_stack")) {
1185  DebugOverflowStack();
1186  } else if (II->isStr("captured")) {
1187  HandleCaptured(PP);
1188  } else if (II->isStr("modules")) {
1189  struct ModuleVisitor {
1190  Preprocessor &PP;
1191  void visit(Module *M, bool VisibleOnly) {
1192  SourceLocation ImportLoc = PP.getModuleImportLoc(M);
1193  if (!VisibleOnly || ImportLoc.isValid()) {
1194  llvm::errs() << M->getFullModuleName() << " ";
1195  if (ImportLoc.isValid()) {
1196  llvm::errs() << M << " visible ";
1197  ImportLoc.print(llvm::errs(), PP.getSourceManager());
1198  }
1199  llvm::errs() << "\n";
1200  }
1201  for (Module *Sub : M->submodules()) {
1202  if (!VisibleOnly || ImportLoc.isInvalid() || Sub->IsExplicit)
1203  visit(Sub, VisibleOnly);
1204  }
1205  }
1206  void visitAll(bool VisibleOnly) {
1207  for (auto &NameAndMod :
1209  visit(NameAndMod.second, VisibleOnly);
1210  }
1211  } Visitor{PP};
1212 
1213  Token Kind;
1215  auto *DumpII = Kind.getIdentifierInfo();
1216  if (!DumpII) {
1217  PP.Diag(Kind, diag::warn_pragma_debug_missing_argument)
1218  << II->getName();
1219  } else if (DumpII->isStr("all")) {
1220  Visitor.visitAll(false);
1221  } else if (DumpII->isStr("visible")) {
1222  Visitor.visitAll(true);
1223  } else if (DumpII->isStr("building")) {
1224  for (auto &Building : PP.getBuildingSubmodules()) {
1225  llvm::errs() << "in " << Building.M->getFullModuleName();
1226  if (Building.ImportLoc.isValid()) {
1227  llvm::errs() << " imported ";
1228  if (Building.IsPragma)
1229  llvm::errs() << "via pragma ";
1230  llvm::errs() << "at ";
1231  Building.ImportLoc.print(llvm::errs(), PP.getSourceManager());
1232  llvm::errs() << "\n";
1233  }
1234  }
1235  } else {
1236  PP.Diag(Tok, diag::warn_pragma_debug_unexpected_command)
1237  << DumpII->getName();
1238  }
1239  } else {
1240  PP.Diag(Tok, diag::warn_pragma_debug_unexpected_command)
1241  << II->getName();
1242  }
1243 
1244  PPCallbacks *Callbacks = PP.getPPCallbacks();
1245  if (Callbacks)
1246  Callbacks->PragmaDebug(Tok.getLocation(), II->getName());
1247  }
1248 
1249  void HandleCaptured(Preprocessor &PP) {
1250  Token Tok;
1251  PP.LexUnexpandedToken(Tok);
1252 
1253  if (Tok.isNot(tok::eod)) {
1254  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol)
1255  << "pragma clang __debug captured";
1256  return;
1257  }
1258 
1259  SourceLocation NameLoc = Tok.getLocation();
1261  PP.getPreprocessorAllocator().Allocate<Token>(1), 1);
1262  Toks[0].startToken();
1263  Toks[0].setKind(tok::annot_pragma_captured);
1264  Toks[0].setLocation(NameLoc);
1265 
1266  PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true,
1267  /*IsReinject=*/false);
1268  }
1269 
1270 // Disable MSVC warning about runtime stack overflow.
1271 #ifdef _MSC_VER
1272  #pragma warning(disable : 4717)
1273 #endif
1274  static void DebugOverflowStack(void (*P)() = nullptr) {
1275  void (*volatile Self)(void(*P)()) = DebugOverflowStack;
1276  Self(reinterpret_cast<void(*)()>(Self));
1277  }
1278 #ifdef _MSC_VER
1279  #pragma warning(default : 4717)
1280 #endif
1281 };
1282 
1283 /// PragmaDiagnosticHandler - e.g. '\#pragma GCC diagnostic ignored "-Wformat"'
1284 struct PragmaDiagnosticHandler : public PragmaHandler {
1285 private:
1286  const char *Namespace;
1287 
1288 public:
1289  explicit PragmaDiagnosticHandler(const char *NS)
1290  : PragmaHandler("diagnostic"), Namespace(NS) {}
1291 
1292  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1293  Token &DiagToken) override {
1294  SourceLocation DiagLoc = DiagToken.getLocation();
1295  Token Tok;
1296  PP.LexUnexpandedToken(Tok);
1297  if (Tok.isNot(tok::identifier)) {
1298  PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
1299  return;
1300  }
1301  IdentifierInfo *II = Tok.getIdentifierInfo();
1302  PPCallbacks *Callbacks = PP.getPPCallbacks();
1303 
1304  if (II->isStr("pop")) {
1305  if (!PP.getDiagnostics().popMappings(DiagLoc))
1306  PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop);
1307  else if (Callbacks)
1308  Callbacks->PragmaDiagnosticPop(DiagLoc, Namespace);
1309  return;
1310  } else if (II->isStr("push")) {
1311  PP.getDiagnostics().pushMappings(DiagLoc);
1312  if (Callbacks)
1313  Callbacks->PragmaDiagnosticPush(DiagLoc, Namespace);
1314  return;
1315  }
1316 
1317  diag::Severity SV = llvm::StringSwitch<diag::Severity>(II->getName())
1318  .Case("ignored", diag::Severity::Ignored)
1319  .Case("warning", diag::Severity::Warning)
1320  .Case("error", diag::Severity::Error)
1321  .Case("fatal", diag::Severity::Fatal)
1322  .Default(diag::Severity());
1323 
1324  if (SV == diag::Severity()) {
1325  PP.Diag(Tok, diag::warn_pragma_diagnostic_invalid);
1326  return;
1327  }
1328 
1329  PP.LexUnexpandedToken(Tok);
1330  SourceLocation StringLoc = Tok.getLocation();
1331 
1332  std::string WarningName;
1333  if (!PP.FinishLexStringLiteral(Tok, WarningName, "pragma diagnostic",
1334  /*AllowMacroExpansion=*/false))
1335  return;
1336 
1337  if (Tok.isNot(tok::eod)) {
1338  PP.Diag(Tok.getLocation(), diag::warn_pragma_diagnostic_invalid_token);
1339  return;
1340  }
1341 
1342  if (WarningName.size() < 3 || WarningName[0] != '-' ||
1343  (WarningName[1] != 'W' && WarningName[1] != 'R')) {
1344  PP.Diag(StringLoc, diag::warn_pragma_diagnostic_invalid_option);
1345  return;
1346  }
1347 
1348  diag::Flavor Flavor = WarningName[1] == 'W' ? diag::Flavor::WarningOrError
1350  StringRef Group = StringRef(WarningName).substr(2);
1351  bool unknownDiag = false;
1352  if (Group == "everything") {
1353  // Special handling for pragma clang diagnostic ... "-Weverything".
1354  // There is no formal group named "everything", so there has to be a
1355  // special case for it.
1356  PP.getDiagnostics().setSeverityForAll(Flavor, SV, DiagLoc);
1357  } else
1358  unknownDiag = PP.getDiagnostics().setSeverityForGroup(Flavor, Group, SV,
1359  DiagLoc);
1360  if (unknownDiag)
1361  PP.Diag(StringLoc, diag::warn_pragma_diagnostic_unknown_warning)
1362  << WarningName;
1363  else if (Callbacks)
1364  Callbacks->PragmaDiagnostic(DiagLoc, Namespace, SV, WarningName);
1365  }
1366 };
1367 
1368 /// "\#pragma hdrstop [<header-name-string>]"
1369 struct PragmaHdrstopHandler : public PragmaHandler {
1370  PragmaHdrstopHandler() : PragmaHandler("hdrstop") {}
1371  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1372  Token &DepToken) override {
1373  PP.HandlePragmaHdrstop(DepToken);
1374  }
1375 };
1376 
1377 /// "\#pragma warning(...)". MSVC's diagnostics do not map cleanly to clang's
1378 /// diagnostics, so we don't really implement this pragma. We parse it and
1379 /// ignore it to avoid -Wunknown-pragma warnings.
1380 struct PragmaWarningHandler : public PragmaHandler {
1381  PragmaWarningHandler() : PragmaHandler("warning") {}
1382 
1383  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1384  Token &Tok) override {
1385  // Parse things like:
1386  // warning(push, 1)
1387  // warning(pop)
1388  // warning(disable : 1 2 3 ; error : 4 5 6 ; suppress : 7 8 9)
1389  SourceLocation DiagLoc = Tok.getLocation();
1390  PPCallbacks *Callbacks = PP.getPPCallbacks();
1391 
1392  PP.Lex(Tok);
1393  if (Tok.isNot(tok::l_paren)) {
1394  PP.Diag(Tok, diag::warn_pragma_warning_expected) << "(";
1395  return;
1396  }
1397 
1398  PP.Lex(Tok);
1399  IdentifierInfo *II = Tok.getIdentifierInfo();
1400 
1401  if (II && II->isStr("push")) {
1402  // #pragma warning( push[ ,n ] )
1403  int Level = -1;
1404  PP.Lex(Tok);
1405  if (Tok.is(tok::comma)) {
1406  PP.Lex(Tok);
1407  uint64_t Value;
1408  if (Tok.is(tok::numeric_constant) &&
1410  Level = int(Value);
1411  if (Level < 0 || Level > 4) {
1412  PP.Diag(Tok, diag::warn_pragma_warning_push_level);
1413  return;
1414  }
1415  }
1416  PP.getDiagnostics().pushMappings(DiagLoc);
1417  if (Callbacks)
1418  Callbacks->PragmaWarningPush(DiagLoc, Level);
1419  } else if (II && II->isStr("pop")) {
1420  // #pragma warning( pop )
1421  PP.Lex(Tok);
1422  if (!PP.getDiagnostics().popMappings(DiagLoc))
1423  PP.Diag(Tok, diag::warn_pragma_diagnostic_cannot_pop);
1424  else if (Callbacks)
1425  Callbacks->PragmaWarningPop(DiagLoc);
1426  } else {
1427  // #pragma warning( warning-specifier : warning-number-list
1428  // [; warning-specifier : warning-number-list...] )
1429  while (true) {
1430  II = Tok.getIdentifierInfo();
1431  if (!II && !Tok.is(tok::numeric_constant)) {
1432  PP.Diag(Tok, diag::warn_pragma_warning_spec_invalid);
1433  return;
1434  }
1435 
1436  // Figure out which warning specifier this is.
1437  bool SpecifierValid;
1439  if (II) {
1440  int SpecifierInt = llvm::StringSwitch<int>(II->getName())
1441  .Case("default", PPCallbacks::PWS_Default)
1442  .Case("disable", PPCallbacks::PWS_Disable)
1443  .Case("error", PPCallbacks::PWS_Error)
1444  .Case("once", PPCallbacks::PWS_Once)
1445  .Case("suppress", PPCallbacks::PWS_Suppress)
1446  .Default(-1);
1447  if ((SpecifierValid = SpecifierInt != -1))
1448  Specifier =
1449  static_cast<PPCallbacks::PragmaWarningSpecifier>(SpecifierInt);
1450 
1451  // If we read a correct specifier, snatch next token (that should be
1452  // ":", checked later).
1453  if (SpecifierValid)
1454  PP.Lex(Tok);
1455  } else {
1456  // Token is a numeric constant. It should be either 1, 2, 3 or 4.
1457  uint64_t Value;
1458  if (PP.parseSimpleIntegerLiteral(Tok, Value)) {
1459  if ((SpecifierValid = (Value >= 1) && (Value <= 4)))
1462  } else
1463  SpecifierValid = false;
1464  // Next token already snatched by parseSimpleIntegerLiteral.
1465  }
1466 
1467  if (!SpecifierValid) {
1468  PP.Diag(Tok, diag::warn_pragma_warning_spec_invalid);
1469  return;
1470  }
1471  if (Tok.isNot(tok::colon)) {
1472  PP.Diag(Tok, diag::warn_pragma_warning_expected) << ":";
1473  return;
1474  }
1475 
1476  // Collect the warning ids.
1477  SmallVector<int, 4> Ids;
1478  PP.Lex(Tok);
1479  while (Tok.is(tok::numeric_constant)) {
1480  uint64_t Value;
1481  if (!PP.parseSimpleIntegerLiteral(Tok, Value) || Value == 0 ||
1482  Value > INT_MAX) {
1483  PP.Diag(Tok, diag::warn_pragma_warning_expected_number);
1484  return;
1485  }
1486  Ids.push_back(int(Value));
1487  }
1488 
1489  // Only act on disable for now.
1493  if (SV != diag::Severity())
1494  for (int Id : Ids) {
1495  if (auto Group = diagGroupFromCLWarningID(Id)) {
1496  bool unknownDiag = PP.getDiagnostics().setSeverityForGroup(
1497  diag::Flavor::WarningOrError, *Group, SV, DiagLoc);
1498  assert(!unknownDiag &&
1499  "wd table should only contain known diags");
1500  (void)unknownDiag;
1501  }
1502  }
1503 
1504  if (Callbacks)
1505  Callbacks->PragmaWarning(DiagLoc, Specifier, Ids);
1506 
1507  // Parse the next specifier if there is a semicolon.
1508  if (Tok.isNot(tok::semi))
1509  break;
1510  PP.Lex(Tok);
1511  }
1512  }
1513 
1514  if (Tok.isNot(tok::r_paren)) {
1515  PP.Diag(Tok, diag::warn_pragma_warning_expected) << ")";
1516  return;
1517  }
1518 
1519  PP.Lex(Tok);
1520  if (Tok.isNot(tok::eod))
1521  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma warning";
1522  }
1523 };
1524 
1525 /// "\#pragma execution_character_set(...)". MSVC supports this pragma only
1526 /// for "UTF-8". We parse it and ignore it if UTF-8 is provided and warn
1527 /// otherwise to avoid -Wunknown-pragma warnings.
1528 struct PragmaExecCharsetHandler : public PragmaHandler {
1529  PragmaExecCharsetHandler() : PragmaHandler("execution_character_set") {}
1530 
1531  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1532  Token &Tok) override {
1533  // Parse things like:
1534  // execution_character_set(push, "UTF-8")
1535  // execution_character_set(pop)
1536  SourceLocation DiagLoc = Tok.getLocation();
1537  PPCallbacks *Callbacks = PP.getPPCallbacks();
1538 
1539  PP.Lex(Tok);
1540  if (Tok.isNot(tok::l_paren)) {
1541  PP.Diag(Tok, diag::warn_pragma_exec_charset_expected) << "(";
1542  return;
1543  }
1544 
1545  PP.Lex(Tok);
1546  IdentifierInfo *II = Tok.getIdentifierInfo();
1547 
1548  if (II && II->isStr("push")) {
1549  // #pragma execution_character_set( push[ , string ] )
1550  PP.Lex(Tok);
1551  if (Tok.is(tok::comma)) {
1552  PP.Lex(Tok);
1553 
1554  std::string ExecCharset;
1555  if (!PP.FinishLexStringLiteral(Tok, ExecCharset,
1556  "pragma execution_character_set",
1557  /*AllowMacroExpansion=*/false))
1558  return;
1559 
1560  // MSVC supports either of these, but nothing else.
1561  if (ExecCharset != "UTF-8" && ExecCharset != "utf-8") {
1562  PP.Diag(Tok, diag::warn_pragma_exec_charset_push_invalid) << ExecCharset;
1563  return;
1564  }
1565  }
1566  if (Callbacks)
1567  Callbacks->PragmaExecCharsetPush(DiagLoc, "UTF-8");
1568  } else if (II && II->isStr("pop")) {
1569  // #pragma execution_character_set( pop )
1570  PP.Lex(Tok);
1571  if (Callbacks)
1572  Callbacks->PragmaExecCharsetPop(DiagLoc);
1573  } else {
1574  PP.Diag(Tok, diag::warn_pragma_exec_charset_spec_invalid);
1575  return;
1576  }
1577 
1578  if (Tok.isNot(tok::r_paren)) {
1579  PP.Diag(Tok, diag::warn_pragma_exec_charset_expected) << ")";
1580  return;
1581  }
1582 
1583  PP.Lex(Tok);
1584  if (Tok.isNot(tok::eod))
1585  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma execution_character_set";
1586  }
1587 };
1588 
1589 /// PragmaIncludeAliasHandler - "\#pragma include_alias("...")".
1590 struct PragmaIncludeAliasHandler : public PragmaHandler {
1591  PragmaIncludeAliasHandler() : PragmaHandler("include_alias") {}
1592 
1593  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1594  Token &IncludeAliasTok) override {
1595  PP.HandlePragmaIncludeAlias(IncludeAliasTok);
1596  }
1597 };
1598 
1599 /// PragmaMessageHandler - Handle the microsoft and gcc \#pragma message
1600 /// extension. The syntax is:
1601 /// \code
1602 /// #pragma message(string)
1603 /// \endcode
1604 /// OR, in GCC mode:
1605 /// \code
1606 /// #pragma message string
1607 /// \endcode
1608 /// string is a string, which is fully macro expanded, and permits string
1609 /// concatenation, embedded escape characters, etc... See MSDN for more details.
1610 /// Also handles \#pragma GCC warning and \#pragma GCC error which take the same
1611 /// form as \#pragma message.
1612 struct PragmaMessageHandler : public PragmaHandler {
1613 private:
1615  const StringRef Namespace;
1616 
1617  static const char* PragmaKind(PPCallbacks::PragmaMessageKind Kind,
1618  bool PragmaNameOnly = false) {
1619  switch (Kind) {
1621  return PragmaNameOnly ? "message" : "pragma message";
1623  return PragmaNameOnly ? "warning" : "pragma warning";
1625  return PragmaNameOnly ? "error" : "pragma error";
1626  }
1627  llvm_unreachable("Unknown PragmaMessageKind!");
1628  }
1629 
1630 public:
1631  PragmaMessageHandler(PPCallbacks::PragmaMessageKind Kind,
1632  StringRef Namespace = StringRef())
1633  : PragmaHandler(PragmaKind(Kind, true)), Kind(Kind),
1634  Namespace(Namespace) {}
1635 
1636  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1637  Token &Tok) override {
1638  SourceLocation MessageLoc = Tok.getLocation();
1639  PP.Lex(Tok);
1640  bool ExpectClosingParen = false;
1641  switch (Tok.getKind()) {
1642  case tok::l_paren:
1643  // We have a MSVC style pragma message.
1644  ExpectClosingParen = true;
1645  // Read the string.
1646  PP.Lex(Tok);
1647  break;
1648  case tok::string_literal:
1649  // We have a GCC style pragma message, and we just read the string.
1650  break;
1651  default:
1652  PP.Diag(MessageLoc, diag::err_pragma_message_malformed) << Kind;
1653  return;
1654  }
1655 
1656  std::string MessageString;
1657  if (!PP.FinishLexStringLiteral(Tok, MessageString, PragmaKind(Kind),
1658  /*AllowMacroExpansion=*/true))
1659  return;
1660 
1661  if (ExpectClosingParen) {
1662  if (Tok.isNot(tok::r_paren)) {
1663  PP.Diag(Tok.getLocation(), diag::err_pragma_message_malformed) << Kind;
1664  return;
1665  }
1666  PP.Lex(Tok); // eat the r_paren.
1667  }
1668 
1669  if (Tok.isNot(tok::eod)) {
1670  PP.Diag(Tok.getLocation(), diag::err_pragma_message_malformed) << Kind;
1671  return;
1672  }
1673 
1674  // Output the message.
1675  PP.Diag(MessageLoc, (Kind == PPCallbacks::PMK_Error)
1676  ? diag::err_pragma_message
1677  : diag::warn_pragma_message) << MessageString;
1678 
1679  // If the pragma is lexically sound, notify any interested PPCallbacks.
1680  if (PPCallbacks *Callbacks = PP.getPPCallbacks())
1681  Callbacks->PragmaMessage(MessageLoc, Namespace, Kind, MessageString);
1682  }
1683 };
1684 
1685 /// Handle the clang \#pragma module import extension. The syntax is:
1686 /// \code
1687 /// #pragma clang module import some.module.name
1688 /// \endcode
1689 struct PragmaModuleImportHandler : public PragmaHandler {
1690  PragmaModuleImportHandler() : PragmaHandler("import") {}
1691 
1692  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1693  Token &Tok) override {
1694  SourceLocation ImportLoc = Tok.getLocation();
1695 
1696  // Read the module name.
1698  ModuleName;
1699  if (LexModuleName(PP, Tok, ModuleName))
1700  return;
1701 
1702  if (Tok.isNot(tok::eod))
1703  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1704 
1705  // If we have a non-empty module path, load the named module.
1706  Module *Imported =
1707  PP.getModuleLoader().loadModule(ImportLoc, ModuleName, Module::Hidden,
1708  /*IsInclusionDirective=*/false);
1709  if (!Imported)
1710  return;
1711 
1712  PP.makeModuleVisible(Imported, ImportLoc);
1713  PP.EnterAnnotationToken(SourceRange(ImportLoc, ModuleName.back().second),
1714  tok::annot_module_include, Imported);
1715  if (auto *CB = PP.getPPCallbacks())
1716  CB->moduleImport(ImportLoc, ModuleName, Imported);
1717  }
1718 };
1719 
1720 /// Handle the clang \#pragma module begin extension. The syntax is:
1721 /// \code
1722 /// #pragma clang module begin some.module.name
1723 /// ...
1724 /// #pragma clang module end
1725 /// \endcode
1726 struct PragmaModuleBeginHandler : public PragmaHandler {
1727  PragmaModuleBeginHandler() : PragmaHandler("begin") {}
1728 
1729  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1730  Token &Tok) override {
1731  SourceLocation BeginLoc = Tok.getLocation();
1732 
1733  // Read the module name.
1735  ModuleName;
1736  if (LexModuleName(PP, Tok, ModuleName))
1737  return;
1738 
1739  if (Tok.isNot(tok::eod))
1740  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1741 
1742  // We can only enter submodules of the current module.
1743  StringRef Current = PP.getLangOpts().CurrentModule;
1744  if (ModuleName.front().first->getName() != Current) {
1745  PP.Diag(ModuleName.front().second, diag::err_pp_module_begin_wrong_module)
1746  << ModuleName.front().first << (ModuleName.size() > 1)
1747  << Current.empty() << Current;
1748  return;
1749  }
1750 
1751  // Find the module we're entering. We require that a module map for it
1752  // be loaded or implicitly loadable.
1753  auto &HSI = PP.getHeaderSearchInfo();
1754  Module *M = HSI.lookupModule(Current, ModuleName.front().second);
1755  if (!M) {
1756  PP.Diag(ModuleName.front().second,
1757  diag::err_pp_module_begin_no_module_map) << Current;
1758  return;
1759  }
1760  for (unsigned I = 1; I != ModuleName.size(); ++I) {
1761  auto *NewM = M->findOrInferSubmodule(ModuleName[I].first->getName());
1762  if (!NewM) {
1763  PP.Diag(ModuleName[I].second, diag::err_pp_module_begin_no_submodule)
1764  << M->getFullModuleName() << ModuleName[I].first;
1765  return;
1766  }
1767  M = NewM;
1768  }
1769 
1770  // If the module isn't available, it doesn't make sense to enter it.
1772  PP.getLangOpts(), PP.getTargetInfo(), PP.getDiagnostics(), M)) {
1773  PP.Diag(BeginLoc, diag::note_pp_module_begin_here)
1774  << M->getTopLevelModuleName();
1775  return;
1776  }
1777 
1778  // Enter the scope of the submodule.
1779  PP.EnterSubmodule(M, BeginLoc, /*ForPragma*/true);
1780  PP.EnterAnnotationToken(SourceRange(BeginLoc, ModuleName.back().second),
1781  tok::annot_module_begin, M);
1782  }
1783 };
1784 
1785 /// Handle the clang \#pragma module end extension.
1786 struct PragmaModuleEndHandler : public PragmaHandler {
1787  PragmaModuleEndHandler() : PragmaHandler("end") {}
1788 
1789  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1790  Token &Tok) override {
1791  SourceLocation Loc = Tok.getLocation();
1792 
1793  PP.LexUnexpandedToken(Tok);
1794  if (Tok.isNot(tok::eod))
1795  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1796 
1797  Module *M = PP.LeaveSubmodule(/*ForPragma*/true);
1798  if (M)
1799  PP.EnterAnnotationToken(SourceRange(Loc), tok::annot_module_end, M);
1800  else
1801  PP.Diag(Loc, diag::err_pp_module_end_without_module_begin);
1802  }
1803 };
1804 
1805 /// Handle the clang \#pragma module build extension.
1806 struct PragmaModuleBuildHandler : public PragmaHandler {
1807  PragmaModuleBuildHandler() : PragmaHandler("build") {}
1808 
1809  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1810  Token &Tok) override {
1811  PP.HandlePragmaModuleBuild(Tok);
1812  }
1813 };
1814 
1815 /// Handle the clang \#pragma module load extension.
1816 struct PragmaModuleLoadHandler : public PragmaHandler {
1817  PragmaModuleLoadHandler() : PragmaHandler("load") {}
1818 
1819  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1820  Token &Tok) override {
1821  SourceLocation Loc = Tok.getLocation();
1822 
1823  // Read the module name.
1825  ModuleName;
1826  if (LexModuleName(PP, Tok, ModuleName))
1827  return;
1828 
1829  if (Tok.isNot(tok::eod))
1830  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1831 
1832  // Load the module, don't make it visible.
1833  PP.getModuleLoader().loadModule(Loc, ModuleName, Module::Hidden,
1834  /*IsInclusionDirective=*/false);
1835  }
1836 };
1837 
1838 /// PragmaPushMacroHandler - "\#pragma push_macro" saves the value of the
1839 /// macro on the top of the stack.
1840 struct PragmaPushMacroHandler : public PragmaHandler {
1841  PragmaPushMacroHandler() : PragmaHandler("push_macro") {}
1842 
1843  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1844  Token &PushMacroTok) override {
1845  PP.HandlePragmaPushMacro(PushMacroTok);
1846  }
1847 };
1848 
1849 /// PragmaPopMacroHandler - "\#pragma pop_macro" sets the value of the
1850 /// macro to the value on the top of the stack.
1851 struct PragmaPopMacroHandler : public PragmaHandler {
1852  PragmaPopMacroHandler() : PragmaHandler("pop_macro") {}
1853 
1854  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1855  Token &PopMacroTok) override {
1856  PP.HandlePragmaPopMacro(PopMacroTok);
1857  }
1858 };
1859 
1860 /// PragmaARCCFCodeAuditedHandler -
1861 /// \#pragma clang arc_cf_code_audited begin/end
1862 struct PragmaARCCFCodeAuditedHandler : public PragmaHandler {
1863  PragmaARCCFCodeAuditedHandler() : PragmaHandler("arc_cf_code_audited") {}
1864 
1865  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1866  Token &NameTok) override {
1867  SourceLocation Loc = NameTok.getLocation();
1868  bool IsBegin;
1869 
1870  Token Tok;
1871 
1872  // Lex the 'begin' or 'end'.
1873  PP.LexUnexpandedToken(Tok);
1874  const IdentifierInfo *BeginEnd = Tok.getIdentifierInfo();
1875  if (BeginEnd && BeginEnd->isStr("begin")) {
1876  IsBegin = true;
1877  } else if (BeginEnd && BeginEnd->isStr("end")) {
1878  IsBegin = false;
1879  } else {
1880  PP.Diag(Tok.getLocation(), diag::err_pp_arc_cf_code_audited_syntax);
1881  return;
1882  }
1883 
1884  // Verify that this is followed by EOD.
1885  PP.LexUnexpandedToken(Tok);
1886  if (Tok.isNot(tok::eod))
1887  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1888 
1889  // The start location of the active audit.
1890  SourceLocation BeginLoc = PP.getPragmaARCCFCodeAuditedInfo().second;
1891 
1892  // The start location we want after processing this.
1893  SourceLocation NewLoc;
1894 
1895  if (IsBegin) {
1896  // Complain about attempts to re-enter an audit.
1897  if (BeginLoc.isValid()) {
1898  PP.Diag(Loc, diag::err_pp_double_begin_of_arc_cf_code_audited);
1899  PP.Diag(BeginLoc, diag::note_pragma_entered_here);
1900  }
1901  NewLoc = Loc;
1902  } else {
1903  // Complain about attempts to leave an audit that doesn't exist.
1904  if (!BeginLoc.isValid()) {
1905  PP.Diag(Loc, diag::err_pp_unmatched_end_of_arc_cf_code_audited);
1906  return;
1907  }
1908  NewLoc = SourceLocation();
1909  }
1910 
1911  PP.setPragmaARCCFCodeAuditedInfo(NameTok.getIdentifierInfo(), NewLoc);
1912  }
1913 };
1914 
1915 /// PragmaAssumeNonNullHandler -
1916 /// \#pragma clang assume_nonnull begin/end
1917 struct PragmaAssumeNonNullHandler : public PragmaHandler {
1918  PragmaAssumeNonNullHandler() : PragmaHandler("assume_nonnull") {}
1919 
1920  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1921  Token &NameTok) override {
1922  SourceLocation Loc = NameTok.getLocation();
1923  bool IsBegin;
1924 
1925  Token Tok;
1926 
1927  // Lex the 'begin' or 'end'.
1928  PP.LexUnexpandedToken(Tok);
1929  const IdentifierInfo *BeginEnd = Tok.getIdentifierInfo();
1930  if (BeginEnd && BeginEnd->isStr("begin")) {
1931  IsBegin = true;
1932  } else if (BeginEnd && BeginEnd->isStr("end")) {
1933  IsBegin = false;
1934  } else {
1935  PP.Diag(Tok.getLocation(), diag::err_pp_assume_nonnull_syntax);
1936  return;
1937  }
1938 
1939  // Verify that this is followed by EOD.
1940  PP.LexUnexpandedToken(Tok);
1941  if (Tok.isNot(tok::eod))
1942  PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma";
1943 
1944  // The start location of the active audit.
1945  SourceLocation BeginLoc = PP.getPragmaAssumeNonNullLoc();
1946 
1947  // The start location we want after processing this.
1948  SourceLocation NewLoc;
1949  PPCallbacks *Callbacks = PP.getPPCallbacks();
1950 
1951  if (IsBegin) {
1952  // Complain about attempts to re-enter an audit.
1953  if (BeginLoc.isValid()) {
1954  PP.Diag(Loc, diag::err_pp_double_begin_of_assume_nonnull);
1955  PP.Diag(BeginLoc, diag::note_pragma_entered_here);
1956  }
1957  NewLoc = Loc;
1958  if (Callbacks)
1959  Callbacks->PragmaAssumeNonNullBegin(NewLoc);
1960  } else {
1961  // Complain about attempts to leave an audit that doesn't exist.
1962  if (!BeginLoc.isValid()) {
1963  PP.Diag(Loc, diag::err_pp_unmatched_end_of_assume_nonnull);
1964  return;
1965  }
1966  NewLoc = SourceLocation();
1967  if (Callbacks)
1968  Callbacks->PragmaAssumeNonNullEnd(NewLoc);
1969  }
1970 
1971  PP.setPragmaAssumeNonNullLoc(NewLoc);
1972  }
1973 };
1974 
1975 /// Handle "\#pragma region [...]"
1976 ///
1977 /// The syntax is
1978 /// \code
1979 /// #pragma region [optional name]
1980 /// #pragma endregion [optional comment]
1981 /// \endcode
1982 ///
1983 /// \note This is
1984 /// <a href="http://msdn.microsoft.com/en-us/library/b6xkz944(v=vs.80).aspx">editor-only</a>
1985 /// pragma, just skipped by compiler.
1986 struct PragmaRegionHandler : public PragmaHandler {
1987  PragmaRegionHandler(const char *pragma) : PragmaHandler(pragma) {}
1988 
1989  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
1990  Token &NameTok) override {
1991  // #pragma region: endregion matches can be verified
1992  // __pragma(region): no sense, but ignored by msvc
1993  // _Pragma is not valid for MSVC, but there isn't any point
1994  // to handle a _Pragma differently.
1995  }
1996 };
1997 
1998 /// This handles parsing pragmas that take a macro name and optional message
1999 static IdentifierInfo *HandleMacroAnnotationPragma(Preprocessor &PP, Token &Tok,
2000  const char *Pragma,
2001  std::string &MessageString) {
2003 
2004  PP.Lex(Tok);
2005  if (Tok.isNot(tok::l_paren)) {
2006  PP.Diag(Tok, diag::err_expected) << "(";
2007  return nullptr;
2008  }
2009 
2010  PP.LexUnexpandedToken(Tok);
2011  if (!Tok.is(tok::identifier)) {
2012  PP.Diag(Tok, diag::err_expected) << tok::identifier;
2013  return nullptr;
2014  }
2015  IdentifierInfo *II = Tok.getIdentifierInfo();
2016 
2017  if (!II->hasMacroDefinition()) {
2018  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II;
2019  return nullptr;
2020  }
2021 
2022  PP.Lex(Tok);
2023  if (Tok.is(tok::comma)) {
2024  PP.Lex(Tok);
2025  if (!PP.FinishLexStringLiteral(Tok, MessageString, Pragma,
2026  /*AllowMacroExpansion=*/true))
2027  return nullptr;
2028  }
2029 
2030  if (Tok.isNot(tok::r_paren)) {
2031  PP.Diag(Tok, diag::err_expected) << ")";
2032  return nullptr;
2033  }
2034  return II;
2035 }
2036 
2037 /// "\#pragma clang deprecated(...)"
2038 ///
2039 /// The syntax is
2040 /// \code
2041 /// #pragma clang deprecate(MACRO_NAME [, Message])
2042 /// \endcode
2043 struct PragmaDeprecatedHandler : public PragmaHandler {
2044  PragmaDeprecatedHandler() : PragmaHandler("deprecated") {}
2045 
2046  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
2047  Token &Tok) override {
2048  std::string MessageString;
2049 
2050  if (IdentifierInfo *II = HandleMacroAnnotationPragma(
2051  PP, Tok, "#pragma clang deprecated", MessageString)) {
2052  II->setIsDeprecatedMacro(true);
2053  PP.addMacroDeprecationMsg(II, std::move(MessageString),
2054  Tok.getLocation());
2055  }
2056  }
2057 };
2058 
2059 /// "\#pragma clang restrict_expansion(...)"
2060 ///
2061 /// The syntax is
2062 /// \code
2063 /// #pragma clang restrict_expansion(MACRO_NAME [, Message])
2064 /// \endcode
2065 struct PragmaRestrictExpansionHandler : public PragmaHandler {
2066  PragmaRestrictExpansionHandler() : PragmaHandler("restrict_expansion") {}
2067 
2068  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
2069  Token &Tok) override {
2070  std::string MessageString;
2071 
2072  if (IdentifierInfo *II = HandleMacroAnnotationPragma(
2073  PP, Tok, "#pragma clang restrict_expansion", MessageString)) {
2074  II->setIsRestrictExpansion(true);
2075  PP.addRestrictExpansionMsg(II, std::move(MessageString),
2076  Tok.getLocation());
2077  }
2078  }
2079 };
2080 
2081 /// "\#pragma clang final(...)"
2082 ///
2083 /// The syntax is
2084 /// \code
2085 /// #pragma clang final(MACRO_NAME)
2086 /// \endcode
2087 struct PragmaFinalHandler : public PragmaHandler {
2088  PragmaFinalHandler() : PragmaHandler("final") {}
2089 
2090  void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer,
2091  Token &Tok) override {
2093 
2094  PP.Lex(Tok);
2095  if (Tok.isNot(tok::l_paren)) {
2096  PP.Diag(Tok, diag::err_expected) << "(";
2097  return;
2098  }
2099 
2100  PP.LexUnexpandedToken(Tok);
2101  if (!Tok.is(tok::identifier)) {
2102  PP.Diag(Tok, diag::err_expected) << tok::identifier;
2103  return;
2104  }
2105  IdentifierInfo *II = Tok.getIdentifierInfo();
2106 
2107  if (!II->hasMacroDefinition()) {
2108  PP.Diag(Tok, diag::err_pp_visibility_non_macro) << II;
2109  return;
2110  }
2111 
2112  PP.Lex(Tok);
2113  if (Tok.isNot(tok::r_paren)) {
2114  PP.Diag(Tok, diag::err_expected) << ")";
2115  return;
2116  }
2117  II->setIsFinal(true);
2118  PP.addFinalLoc(II, Tok.getLocation());
2119  }
2120 };
2121 
2122 } // namespace
2123 
2124 /// RegisterBuiltinPragmas - Install the standard preprocessor pragmas:
2125 /// \#pragma GCC poison/system_header/dependency and \#pragma once.
2126 void Preprocessor::RegisterBuiltinPragmas() {
2127  AddPragmaHandler(new PragmaOnceHandler());
2128  AddPragmaHandler(new PragmaMarkHandler());
2129  AddPragmaHandler(new PragmaPushMacroHandler());
2130  AddPragmaHandler(new PragmaPopMacroHandler());
2131  AddPragmaHandler(new PragmaMessageHandler(PPCallbacks::PMK_Message));
2132 
2133  // #pragma GCC ...
2134  AddPragmaHandler("GCC", new PragmaPoisonHandler());
2135  AddPragmaHandler("GCC", new PragmaSystemHeaderHandler());
2136  AddPragmaHandler("GCC", new PragmaDependencyHandler());
2137  AddPragmaHandler("GCC", new PragmaDiagnosticHandler("GCC"));
2138  AddPragmaHandler("GCC", new PragmaMessageHandler(PPCallbacks::PMK_Warning,
2139  "GCC"));
2140  AddPragmaHandler("GCC", new PragmaMessageHandler(PPCallbacks::PMK_Error,
2141  "GCC"));
2142  // #pragma clang ...
2143  AddPragmaHandler("clang", new PragmaPoisonHandler());
2144  AddPragmaHandler("clang", new PragmaSystemHeaderHandler());
2145  AddPragmaHandler("clang", new PragmaIncludeInsteadHandler());
2146  AddPragmaHandler("clang", new PragmaDebugHandler());
2147  AddPragmaHandler("clang", new PragmaDependencyHandler());
2148  AddPragmaHandler("clang", new PragmaDiagnosticHandler("clang"));
2149  AddPragmaHandler("clang", new PragmaARCCFCodeAuditedHandler());
2150  AddPragmaHandler("clang", new PragmaAssumeNonNullHandler());
2151  AddPragmaHandler("clang", new PragmaDeprecatedHandler());
2152  AddPragmaHandler("clang", new PragmaRestrictExpansionHandler());
2153  AddPragmaHandler("clang", new PragmaFinalHandler());
2154 
2155  // #pragma clang module ...
2156  auto *ModuleHandler = new PragmaNamespace("module");
2157  AddPragmaHandler("clang", ModuleHandler);
2158  ModuleHandler->AddPragma(new PragmaModuleImportHandler());
2159  ModuleHandler->AddPragma(new PragmaModuleBeginHandler());
2160  ModuleHandler->AddPragma(new PragmaModuleEndHandler());
2161  ModuleHandler->AddPragma(new PragmaModuleBuildHandler());
2162  ModuleHandler->AddPragma(new PragmaModuleLoadHandler());
2163 
2164  // Add region pragmas.
2165  AddPragmaHandler(new PragmaRegionHandler("region"));
2166  AddPragmaHandler(new PragmaRegionHandler("endregion"));
2167 
2168  // MS extensions.
2169  if (LangOpts.MicrosoftExt) {
2170  AddPragmaHandler(new PragmaWarningHandler());
2171  AddPragmaHandler(new PragmaExecCharsetHandler());
2172  AddPragmaHandler(new PragmaIncludeAliasHandler());
2173  AddPragmaHandler(new PragmaHdrstopHandler());
2174  AddPragmaHandler(new PragmaSystemHeaderHandler());
2175  }
2176 
2177  // Pragmas added by plugins
2178  for (const PragmaHandlerRegistry::entry &handler :
2179  PragmaHandlerRegistry::entries()) {
2180  AddPragmaHandler(handler.instantiate().release());
2181  }
2182 }
2183 
2184 /// Ignore all pragmas, useful for modes such as -Eonly which would otherwise
2185 /// warn about those pragmas being unknown.
2188  // Also ignore all pragmas in all namespaces created
2189  // in Preprocessor::RegisterBuiltinPragmas().
2190  AddPragmaHandler("GCC", new EmptyPragmaHandler());
2191  AddPragmaHandler("clang", new EmptyPragmaHandler());
2192 }
clang::ModuleMap::modules
llvm::iterator_range< module_iterator > modules() const
Definition: ModuleMap.h:704
clang::ModuleLoader::createModuleFromSource
virtual void createModuleFromSource(SourceLocation Loc, StringRef ModuleName, StringRef Source)=0
Attempt to create the given module from the specified source buffer.
clang::PPCallbacks::PWS_Once
@ PWS_Once
Definition: PPCallbacks.h:259
clang::Token::startToken
void startToken()
Reset all flags to cleared.
Definition: Token.h:171
PreprocessorLexer.h
clang::diag::Severity
Severity
Enum values that allow the client to map NOTEs, WARNINGs, and EXTENSIONs to either Ignore (nothing),...
Definition: DiagnosticIDs.h:82
clang::LangOptions::CurrentModule
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:344
clang::Preprocessor::HandlePragmaPopMacro
void HandlePragmaPopMacro(Token &Tok)
Handle #pragma pop_macro.
Definition: Pragma.cpp:681
clang::IdentifierInfo::hasMacroDefinition
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
Definition: IdentifierTable.h:201
clang::Preprocessor::HandlePragmaSystemHeader
void HandlePragmaSystemHeader(Token &SysHeaderTok)
HandlePragmaSystemHeader - Implement #pragma GCC system_header.
Definition: Pragma.cpp:470
clang::PPCallbacks::PragmaAssumeNonNullBegin
virtual void PragmaAssumeNonNullBegin(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull begin directive is read.
Definition: PPCallbacks.h:288
clang::Preprocessor::CreateString
void CreateString(StringRef Str, Token &Tok, SourceLocation ExpansionLocStart=SourceLocation(), SourceLocation ExpansionLocEnd=SourceLocation())
Plop the specified string into a scratch buffer and set the specified token's location and length to ...
Definition: Preprocessor.cpp:481
clang::Preprocessor::RemovePragmaHandler
void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Remove the specific pragma handler from this preprocessor.
Definition: Pragma.cpp:977
clang::PPCallbacks::PragmaDebug
virtual void PragmaDebug(SourceLocation Loc, StringRef DebugType)
Callback invoked when a #pragma clang __debug directive is read.
Definition: PPCallbacks.h:207
clang::Preprocessor::getPreprocessorAllocator
llvm::BumpPtrAllocator & getPreprocessorAllocator()
Definition: Preprocessor.h:971
clang::Preprocessor::setPragmaAssumeNonNullLoc
void setPragmaAssumeNonNullLoc(SourceLocation Loc)
Set the location of the currently-active #pragma clang assume_nonnull begin.
Definition: Preprocessor.h:1720
clang::diag::Severity::Error
@ Error
Present this diagnostic as an error.
clang::Preprocessor::FinishLexStringLiteral
bool FinishLexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Complete the lexing of a string literal where the first token has already been lexed (see LexStringLi...
Definition: Preprocessor.cpp:1322
clang::IdentifierInfo::setChangedSinceDeserialization
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
Definition: IdentifierTable.h:396
clang::PragmaHandler::~PragmaHandler
virtual ~PragmaHandler()
clang::DeclaratorContext::File
@ File
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::PPCallbacks::PragmaAssumeNonNullEnd
virtual void PragmaAssumeNonNullEnd(SourceLocation Loc)
Callback invoked when a #pragma clang assume_nonnull end directive is read.
Definition: PPCallbacks.h:292
LexModuleName
static bool LexModuleName(Preprocessor &PP, Token &Tok, llvm::SmallVectorImpl< std::pair< IdentifierInfo *, SourceLocation >> &ModuleName)
Definition: Pragma.cpp:822
clang::PresumedLoc::getLine
unsigned getLine() const
Return the presumed line number of this location.
Definition: SourceLocation.h:337
clang::Preprocessor::HandlePragmaMark
void HandlePragmaMark(Token &MarkTok)
Definition: Pragma.cpp:418
clang::Preprocessor::getPPCallbacks
PPCallbacks * getPPCallbacks() const
Definition: Preprocessor.h:1057
clang::Preprocessor::Lex
void Lex(Token &Result)
Lex the next token for this preprocessor.
Definition: Preprocessor.cpp:887
clang::DiagnosticsEngine::popMappings
bool popMappings(SourceLocation Loc)
Pops the current DiagMappings off the top of the stack, causing the new top of the stack to be the ac...
Definition: Diagnostic.cpp:121
clang::SourceManager::isInMainFile
bool isInMainFile(SourceLocation Loc) const
Returns whether the PresumedLoc for a given SourceLocation is in the main file.
Definition: SourceManager.cpp:1591
clang::PPCallbacks::PWS_Disable
@ PWS_Disable
Definition: PPCallbacks.h:257
clang::HeaderSearch::AddFileAlias
void AddFileAlias(const FileEntry *File, StringRef Alias)
Definition: HeaderSearch.h:463
clang::Preprocessor::LexHeaderName
bool LexHeaderName(Token &Result, bool AllowMacroExpansion=true)
Lex a token, forming a header-name token if possible.
Definition: Preprocessor.cpp:987
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::Preprocessor::TUKind
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
Definition: Preprocessor.h:270
clang::Module::getFullModuleName
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:219
clang::PPCallbacks::PMK_Error
@ PMK_Error
#pragma GCC error has been invoked.
Definition: PPCallbacks.h:219
clang::PPCallbacks
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:35
clang::Preprocessor::IgnorePragmas
void IgnorePragmas()
Install empty handlers for all pragmas (making them ignored).
Definition: Pragma.cpp:2186
INT_MAX
#define INT_MAX
Definition: limits.h:46
clang::PreprocessorLexer
Definition: PreprocessorLexer.h:31
clang::IdentifierInfo::setIsFinal
void setIsFinal(bool Val)
Definition: IdentifierTable.h:256
clang::Lexer::Create_PragmaLexer
static Lexer * Create_PragmaLexer(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLen, Preprocessor &PP)
Create_PragmaLexer: Lexer constructor - Create a new lexer object for _Pragma expansion.
Definition: Lexer.cpp:193
clang::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:179
Filename
StringRef Filename
Definition: Format.cpp:2431
CLWarnings.h
int
__device__ int
Definition: __clang_hip_libdevice_declares.h:63
Module.h
clang::Token::isAtStartOfLine
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
Definition: Token.h:268
clang::diagGroupFromCLWarningID
llvm::Optional< diag::Group > diagGroupFromCLWarningID(unsigned)
For cl.exe warning IDs that cleany map to clang diagnostic groups, returns the corresponding group.
Definition: CLWarnings.cpp:19
llvm::Optional
Definition: LLVM.h:40
clang::ComparisonCategoryType::First
@ First
clang::PPCallbacks::PragmaDiagnosticPush
virtual void PragmaDiagnosticPush(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic push directive is read.
Definition: PPCallbacks.h:233
clang::StringLiteralParser::hadError
bool hadError
Definition: LiteralSupport.h:239
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
SourceManager.h
clang::SourceManager::getPresumedLoc
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
Definition: SourceManager.cpp:1515
clang::PragmaNamespace::getIfNamespace
PragmaNamespace * getIfNamespace() override
getIfNamespace - If this is a namespace, return it.
Definition: Pragma.h:123
clang::DiagnosticsEngine::setSeverityForGroup
bool setSeverityForGroup(diag::Flavor Flavor, StringRef Group, diag::Severity Map, SourceLocation Loc=SourceLocation())
Change an entire diagnostic group (e.g.
Definition: Diagnostic.cpp:402
clang::Preprocessor::EnterToken
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
Definition: Preprocessor.h:1558
clang::PreprocessorLexer::LexingRawMode
bool LexingRawMode
True if in raw mode.
Definition: PreprocessorLexer.h:69
LexModuleNameComponent
static bool LexModuleNameComponent(Preprocessor &PP, Token &Tok, std::pair< IdentifierInfo *, SourceLocation > &ModuleNameComponent, bool First)
Definition: Pragma.cpp:801
clang::PragmaNamespace::IsEmpty
bool IsEmpty() const
Definition: Pragma.h:118
clang::Token::setAnnotationRange
void setAnnotationRange(SourceRange R)
Definition: Token.h:163
clang::SourceManager::AddLineNote
void AddLineNote(SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)
Add a line note to the line table for the FileID and offset specified by Loc.
Definition: SourceManager.cpp:272
clang::PPCallbacks::PWS_Suppress
@ PWS_Suppress
Definition: PPCallbacks.h:260
clang::index::SymbolKind::Macro
@ Macro
clang::IdentifierInfo::isFromAST
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
Definition: IdentifierTable.h:384
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
clang::Preprocessor::getCurrentFileLexer
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
Definition: PPLexerChange.cpp:50
Identifier
StringRef Identifier
Definition: Format.cpp:2439
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::tok::isStringLiteral
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.
Definition: TokenKinds.h:78
LiteralSupport.h
clang::Preprocessor::AddPragmaHandler
void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Add the specified pragma handler to this preprocessor.
Definition: Pragma.cpp:946
End
SourceLocation End
Definition: USRLocFinder.cpp:167
TokenLexer.h
clang::Preprocessor::addFinalLoc
void addFinalLoc(const IdentifierInfo *II, SourceLocation AnnotationLoc)
Definition: Preprocessor.h:2452
clang::PreprocessorOptions::DisablePragmaDebugCrash
bool DisablePragmaDebugCrash
Prevents intended crashes when using #pragma clang __debug. For testing.
Definition: PreprocessorOptions.h:214
clang::EmptyPragmaHandler::HandlePragma
void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &FirstToken) override
Definition: Pragma.cpp:69
clang::Preprocessor::getLangOpts
const LangOptions & getLangOpts() const
Definition: Preprocessor.h:960
Preprocessor.h
clang::ModuleLoader::loadModule
virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective)=0
Attempt to load the given module.
clang::Preprocessor::creatingPCHWithPragmaHdrStop
bool creatingPCHWithPragmaHdrStop()
True if creating a PCH with a #pragma hdrstop.
Definition: Preprocessor.cpp:612
clang::TU_Prefix
@ TU_Prefix
The translation unit is a prefix to a translation unit, and is not complete.
Definition: LangOptions.h:710
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition: Lexer.h:76
clang::Preprocessor::LookupFile
Optional< FileEntryRef > LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const FileEntry *FromFile, const DirectoryLookup **CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false)
Given a "foo" or <foo> reference, look up the indicated file.
Definition: PPDirectives.cpp:818
clang::HeaderSearch::MarkFileIncludeOnce
void MarkFileIncludeOnce(const FileEntry *File)
Mark the specified file as a "once only" file due to #pragma once.
Definition: HeaderSearch.h:452
clang::index::SymbolKind::Namespace
@ Namespace
TokenKinds.h
clang::Preprocessor::GetIncludeFilenameSpelling
bool GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Buffer)
Turn the specified lexer token into a fully checked and spelled filename, e.g.
Definition: PPDirectives.cpp:1608
clang::IdentifierInfo::isStr
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
Definition: IdentifierTable.h:176
llvm::MutableArrayRef
Definition: LLVM.h:35
clang::diag::Severity::Ignored
@ Ignored
Do not present this diagnostic, ignore it.
clang::Preprocessor::HandlePragmaOnce
void HandlePragmaOnce(Token &OnceTok)
HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.
Definition: Pragma.cpp:403
clang::SourceLocation::print
void print(raw_ostream &OS, const SourceManager &SM) const
Definition: SourceLocation.cpp:62
clang::PIK___pragma
@ PIK___pragma
The pragma was introduced via the Microsoft __pragma(token-string).
Definition: Pragma.h:47
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::Module::Hidden
@ Hidden
All of the names in this module are hidden.
Definition: Module.h:318
clang::Module::findOrInferSubmodule
Module * findOrInferSubmodule(StringRef Name)
Definition: Module.cpp:336
clang::Preprocessor::getBuildingSubmodules
ArrayRef< BuildingSubmoduleInfo > getBuildingSubmodules() const
Get the list of submodules that we're currently building.
Definition: Preprocessor.h:1205
clang::Preprocessor::ParsePragmaPushOrPopMacro
IdentifierInfo * ParsePragmaPushOrPopMacro(Token &Tok)
ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
Definition: Pragma.cpp:603
clang::diag::Flavor::WarningOrError
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
clang::PragmaNamespace::RemovePragmaHandler
void RemovePragmaHandler(PragmaHandler *Handler)
RemovePragmaHandler - Remove the given handler from the namespace.
Definition: Pragma.cpp:100
Id
int Id
Definition: ASTDiff.cpp:191
Pragma.h
clang::PresumedLoc::getFilename
const char * getFilename() const
Return the presumed filename of this location.
Definition: SourceLocation.h:324
clang::PragmaNamespace::HandlePragma
void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &Tok) override
Definition: Pragma.cpp:109
LexHeader
static llvm::Optional< Token > LexHeader(Preprocessor &PP, Optional< FileEntryRef > &File, bool SuppressIncludeNotFoundError)
Definition: Pragma.cpp:501
clang::SourceManager::getLineTableFilenameID
unsigned getLineTableFilenameID(StringRef Str)
Return the uniqued ID for the specified filename.
Definition: SourceManager.cpp:265
clang::Module::getTopLevelModuleName
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition: Module.h:533
clang::diag::Severity::Fatal
@ Fatal
Present this diagnostic as a fatal error.
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:92
clang::IdentifierInfo::setIsPoisoned
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
Definition: IdentifierTable.h:345
LangOptions.h
clang::PPCallbacks::PragmaExecCharsetPush
virtual void PragmaExecCharsetPush(SourceLocation Loc, StringRef Str)
Callback invoked when a #pragma execution_character_set(push) directive is read.
Definition: PPCallbacks.h:280
Diagnostic.h
LexDiagnostic.h
clang::PragmaHandler::getIfNamespace
virtual PragmaNamespace * getIfNamespace()
getIfNamespace - If this is a namespace, return it.
Definition: Pragma.h:79
clang::PragmaIntroducer::Kind
PragmaIntroducerKind Kind
Definition: Pragma.h:52
clang::PPCallbacks::PragmaWarning
virtual void PragmaWarning(SourceLocation Loc, PragmaWarningSpecifier WarningSpec, ArrayRef< int > Ids)
Definition: PPCallbacks.h:266
clang::PragmaHandler::getName
StringRef getName() const
Definition: Pragma.h:73
clang::PPCallbacks::PragmaMessage
virtual void PragmaMessage(SourceLocation Loc, StringRef Namespace, PragmaMessageKind Kind, StringRef Str)
Callback invoked when a #pragma message directive is read.
Definition: PPCallbacks.h:227
clang::Preprocessor::Diag
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
Definition: Preprocessor.h:1744
ModuleLoader.h
clang::Token::is
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
Definition: Token.h:97
clang::Preprocessor::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition: Preprocessor.h:961
clang::Preprocessor::isMacroDefined
bool isMacroDefined(StringRef Id)
Definition: Preprocessor.h:1088
IdentifierTable.h
clang::Preprocessor::EnterSubmodule
void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
Definition: PPLexerChange.cpp:689
clang::Token::setAnnotationValue
void setAnnotationValue(void *val)
Definition: Token.h:230
llvm::SmallString
Definition: LLVM.h:37
clang::PreprocessorLexer::ParsingPreprocessorDirective
bool ParsingPreprocessorDirective
True when parsing #XXX; turns '\n' into a tok::eod token.
Definition: PreprocessorLexer.h:51
clang::Preprocessor::HandlePragmaPushMacro
void HandlePragmaPushMacro(Token &Tok)
Handle #pragma push_macro.
Definition: Pragma.cpp:658
clang::Preprocessor::getMacroInfo
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
Definition: Preprocessor.h:1153
clang::PragmaIntroducer
Describes how and where the pragma was introduced.
Definition: Pragma.h:51
clang::tok::OOS_DEFAULT
@ OOS_DEFAULT
Definition: TokenKinds.h:49
clang::PPCallbacks::PMK_Warning
@ PMK_Warning
#pragma GCC warning has been invoked.
Definition: PPCallbacks.h:216
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:98
clang::PPCallbacks::PMK_Message
@ PMK_Message
#pragma message has been invoked.
Definition: PPCallbacks.h:213
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:331
clang::ModuleMap
Definition: ModuleMap.h:75
clang::tok::OOS_ON
@ OOS_ON
Definition: TokenKinds.h:49
clang::Token::getRawIdentifier
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode),...
Definition: Token.h:205
clang::Token::LeadingSpace
@ LeadingSpace
Definition: Token.h:75
clang::PragmaHandler
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
Definition: Pragma.h:65
clang::IdentifierInfo::setIsDeprecatedMacro
void setIsDeprecatedMacro(bool Val)
Definition: IdentifierTable.h:232
clang::Module::submodules
llvm::iterator_range< submodule_iterator > submodules()
Definition: Module.h:632
clang::diag::Severity::Warning
@ Warning
Present this diagnostic as a warning.
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:964
clang::Preprocessor::HandlePragmaModuleBuild
void HandlePragmaModuleBuild(Token &Tok)
Definition: Pragma.cpp:838
IsHeaderFile
static bool IsHeaderFile(const std::string &Filename)
Definition: RewriteModernObjC.cpp:628
clang::PPCallbacks::PWS_Level1
@ PWS_Level1
Definition: PPCallbacks.h:261
clang::Preprocessor::LexOnOffSwitch
bool LexOnOffSwitch(tok::OnOffSwitch &Result)
Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD.
Definition: Pragma.cpp:999
clang::PresumedLoc::isInvalid
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Definition: SourceLocation.h:318
clang::Preprocessor::getSpelling
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
Definition: Preprocessor.h:1759
SourceLocation.h
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::Preprocessor::HandlePragmaPoison
void HandlePragmaPoison()
HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'.
Definition: Pragma.cpp:428
clang::MacroInfo::setIsAllowRedefinitionsWithoutWarning
void setIsAllowRedefinitionsWithoutWarning(bool Val)
Set the value of the IsAllowRedefinitionsWithoutWarning flag.
Definition: MacroInfo.h:155
clang::PPCallbacks::SystemHeaderPragma
@ SystemHeaderPragma
Definition: PPCallbacks.h:40
clang::PragmaNamespace::AddPragma
void AddPragma(PragmaHandler *Handler)
AddPragma - Add a pragma to this namespace.
Definition: Pragma.cpp:94
clang::Preprocessor::usingPCHWithPragmaHdrStop
bool usingPCHWithPragmaHdrStop()
True if using a PCH with a #pragma hdrstop.
Definition: Preprocessor.cpp:616
clang::IdentifierInfo::isPoisoned
bool isPoisoned() const
Return true if this token has been poisoned.
Definition: IdentifierTable.h:354
clang::Preprocessor::getPragmaARCCFCodeAuditedInfo
std::pair< IdentifierInfo *, SourceLocation > getPragmaARCCFCodeAuditedInfo() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
Definition: Preprocessor.h:1699
clang::EmptyPragmaHandler
EmptyPragmaHandler - A pragma handler which takes no action, which can be used to ignore particular p...
Definition: Pragma.h:84
clang::Preprocessor::dumpMacroInfo
void dumpMacroInfo(const IdentifierInfo *II)
Definition: PPMacroExpansion.cpp:258
Specifier
const NestedNameSpecifier * Specifier
Definition: USRLocFinder.cpp:173
Lexer.h
Value
Value
Definition: UninitializedValues.cpp:102
HeaderSearch.h
clang::Preprocessor::getPragmaAssumeNonNullLoc
SourceLocation getPragmaAssumeNonNullLoc() const
The location of the currently-active #pragma clang assume_nonnull begin.
Definition: Preprocessor.h:1714
clang::StringLiteralParser::GetString
StringRef GetString() const
Definition: LiteralSupport.h:242
clang::Preprocessor::appendDefMacroDirective
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
Definition: Preprocessor.h:1174
LLVM.h
clang::ModuleMap::lookupModuleQualified
Module * lookupModuleQualified(StringRef Name, Module *Context) const
Retrieve a module with the given name within the given context, using direct (qualified) name lookup.
Definition: ModuleMap.cpp:808
clang::EmptyPragmaHandler::EmptyPragmaHandler
EmptyPragmaHandler(StringRef Name=StringRef())
Definition: Pragma.cpp:67
clang::IdentifierInfo::setIsRestrictExpansion
void setIsRestrictExpansion(bool Val)
Definition: IdentifierTable.h:244
clang::diag::Flavor
Flavor
Flavors of diagnostics we can emit.
Definition: DiagnosticIDs.h:93
clang::PPCallbacks::PragmaDiagnosticPop
virtual void PragmaDiagnosticPop(SourceLocation Loc, StringRef Namespace)
Callback invoked when a #pragma gcc diagnostic pop directive is read.
Definition: PPCallbacks.h:239
clang::PPCallbacks::PragmaWarningSpecifier
PragmaWarningSpecifier
Callback invoked when a #pragma warning directive is read.
Definition: PPCallbacks.h:255
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:126
clang::Preprocessor::LexStringLiteral
bool LexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Lex a string literal, which may be the concatenation of multiple string literals and may even come fr...
Definition: Preprocessor.h:1464
clang::diag::Flavor::Remark
@ Remark
A diagnostic that indicates normal progress through compilation.
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::Token::isAnnotation
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Definition: Token.h:120
clang::Preprocessor::getModuleImportLoc
SourceLocation getModuleImportLoc(Module *M) const
Definition: Preprocessor.h:1457
clang::Preprocessor::getPreprocessorOpts
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
Definition: Preprocessor.h:955
clang::Preprocessor::getModuleLoader
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with this preprocessor.
Definition: Preprocessor.h:982
clang::PragmaHandler::HandlePragma
virtual void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &FirstToken)=0
clang::HeaderSearch::MarkFileSystemHeader
void MarkFileSystemHeader(const FileEntry *File)
Mark the specified file as a system header, e.g.
Definition: HeaderSearch.h:459
clang::PPCallbacks::PWS_Default
@ PWS_Default
Definition: PPCallbacks.h:256
clang::DiagnosticsEngine::dump
LLVM_DUMP_METHOD void dump() const
Definition: Diagnostic.cpp:103
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:195
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang::Preprocessor::CheckEndOfDirective
SourceLocation CheckEndOfDirective(const char *DirType, bool EnableMacros=false)
Ensure that the next token is a tok::eod token.
Definition: PPDirectives.cpp:370
clang
Definition: CalledOnceCheck.h:17
clang::Preprocessor::HandlePragmaIncludeInstead
void HandlePragmaIncludeInstead(Token &Tok)
HandlePragmaIncludeInstead - Handle #pragma clang include_instead(header).
Definition: Pragma.cpp:542
PPCallbacks.h
clang::FileEntry::getModificationTime
time_t getModificationTime() const
Definition: FileEntry.h:372
clang::Preprocessor::LookUpIdentifierInfo
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
Given a tok::raw_identifier token, look up the identifier information for the token and install it in...
Definition: Preprocessor.cpp:695
MacroInfo.h
clang::PPCallbacks::PragmaMessageKind
PragmaMessageKind
Determines the kind of #pragma invoking a call to PragmaMessage.
Definition: PPCallbacks.h:211
clang::tok::OOS_OFF
@ OOS_OFF
Definition: TokenKinds.h:49
clang::Preprocessor::HandlePragmaHdrstop
void HandlePragmaHdrstop(Token &Tok)
Definition: Pragma.cpp:912
clang::Preprocessor::getDiagnostics
DiagnosticsEngine & getDiagnostics() const
Definition: Preprocessor.h:957
clang::PragmaIntroducer::Loc
SourceLocation Loc
Definition: Pragma.h:53
clang::Preprocessor::addRestrictExpansionMsg
void addRestrictExpansionMsg(const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
Definition: Preprocessor.h:2440
clang::SourceManager::isInSystemHeader
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
Definition: SourceManager.h:1488
clang::Preprocessor::DiscardUntilEndOfDirective
SourceRange DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found.
Definition: PPDirectives.cpp:82
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26
clang::tok::OnOffSwitch
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
Definition: TokenKinds.h:48
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::Preprocessor::isInPrimaryFile
bool isInPrimaryFile() const
Return true if we're in the top-level file, not in a #include.
Definition: PPLexerChange.cpp:35
clang::Module::dump
void dump() const
Dump the contents of this module to the given output stream.
Definition: APINotesYAMLCompiler.cpp:577
clang::Token::setKind
void setKind(tok::TokenKind K)
Definition: Token.h:93
clang::Preprocessor::makeModuleVisible
void makeModuleVisible(Module *M, SourceLocation Loc)
Definition: Preprocessor.cpp:1305
clang::PPCallbacks::PragmaExecCharsetPop
virtual void PragmaExecCharsetPop(SourceLocation Loc)
Callback invoked when a #pragma execution_character_set(pop) directive is read.
Definition: PPCallbacks.h:284
clang::HeaderSearch::AddIncludeAlias
void AddIncludeAlias(StringRef Source, StringRef Dest)
Map the source include name to the dest include name.
Definition: HeaderSearch.h:313
clang::Preprocessor::addMacroDeprecationMsg
void addMacroDeprecationMsg(const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
Definition: Preprocessor.h:2428
clang::Preprocessor::HandlePragmaDependency
void HandlePragmaDependency(Token &DependencyTok)
HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
Definition: Pragma.cpp:575
clang::Preprocessor::HandlePragmaIncludeAlias
void HandlePragmaIncludeAlias(Token &Tok)
Definition: Pragma.cpp:716
clang::DiagnosticsEngine::setSeverityForAll
void setSeverityForAll(diag::Flavor Flavor, diag::Severity Map, SourceLocation Loc=SourceLocation())
Add the specified mapping to all diagnostics of the specified flavor.
Definition: Diagnostic.cpp:486
clang::Preprocessor::setPragmaARCCFCodeAuditedInfo
void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident, SourceLocation Loc)
Set the location of the currently-active #pragma clang arc_cf_code_audited begin.
Definition: Preprocessor.h:1705
clang::DiagnosticsEngine::pushMappings
void pushMappings(SourceLocation Loc)
Copies the current DiagMappings and pushes the new copy onto the top of the stack.
Definition: Diagnostic.cpp:117
clang::Preprocessor::LeaveSubmodule
Module * LeaveSubmodule(bool ForPragma)
Definition: PPLexerChange.cpp:766
clang::comments::tok::eof
@ eof
Definition: CommentLexer.h:33
clang::PresumedLoc
Represents an unpacked "presumed" location which can be presented to the user.
Definition: SourceLocation.h:302
clang::Preprocessor::checkModuleIsAvailable
static bool checkModuleIsAvailable(const LangOptions &LangOpts, const TargetInfo &TargetInfo, DiagnosticsEngine &Diags, Module *M)
Check that the given module is available, producing a diagnostic if not.
Definition: PPDirectives.cpp:1755
DiagnosticLex.h
llvm::SmallVectorImpl
Definition: LLVM.h:39
FileManager.h
clang::SrcMgr::C_System
@ C_System
Definition: SourceManager.h:80
clang::PragmaNamespace
PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas, allowing hierarchical pragm...
Definition: Pragma.h:96
true
#define true
Definition: stdbool.h:16
clang::Preprocessor::LexUnexpandedToken
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
Definition: Preprocessor.h:1492
clang::PIK__Pragma
@ PIK__Pragma
The pragma was introduced via the C99 _Pragma(string-literal).
Definition: Pragma.h:41
PreprocessorOptions.h
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:130
clang::Preprocessor::appendMacroDirective
void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD)
Add a directive to the macro directive history for this identifier.
Definition: PPMacroExpansion.cpp:71
clang::Preprocessor::getHeaderSearchInfo
HeaderSearch & getHeaderSearchInfo() const
Definition: Preprocessor.h:965
Token.h
clang::PragmaNamespace::FindHandler
PragmaHandler * FindHandler(StringRef Name, bool IgnoreNull=true) const
FindHandler - Check to see if there is already a handler for the specified name.
Definition: Pragma.cpp:81
clang::StringLiteralParser
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
Definition: LiteralSupport.h:210
clang::PreprocessorLexer::getFileEntry
const FileEntry * getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
Definition: PreprocessorLexer.cpp:50
clang::Preprocessor::EnterAnnotationToken
void EnterAnnotationToken(SourceRange Range, tok::TokenKind Kind, void *AnnotationVal)
Enter an annotation token into the token stream.
Definition: PPDirectives.cpp:1656
clang::PPCallbacks::PragmaWarningPush
virtual void PragmaWarningPush(SourceLocation Loc, int Level)
Callback invoked when a #pragma warning(push) directive is read.
Definition: PPCallbacks.h:271
clang::HeaderSearch::getModuleMap
ModuleMap & getModuleMap()
Retrieve the module map.
Definition: HeaderSearch.h:723
clang::interp::Sub
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:142
clang::PPCallbacks::PragmaWarningPop
virtual void PragmaWarningPop(SourceLocation Loc)
Callback invoked when a #pragma warning(pop) directive is read.
Definition: PPCallbacks.h:275
clang::Preprocessor::getIdentifierInfo
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Definition: Preprocessor.h:1243
clang::Preprocessor::parseSimpleIntegerLiteral
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
Definition: Preprocessor.cpp:1363
clang::PPCallbacks::PragmaDiagnostic
virtual void PragmaDiagnostic(SourceLocation Loc, StringRef Namespace, diag::Severity mapping, StringRef Str)
Callback invoked when a #pragma gcc diagnostic directive is read.
Definition: PPCallbacks.h:244
clang::Token::hasUDSuffix
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix.
Definition: Token.h:293
clang::PPCallbacks::PWS_Error
@ PWS_Error
Definition: PPCallbacks.h:258