clang 18.0.0git
Preprocessor.h
Go to the documentation of this file.
1//===- Preprocessor.h - C Language Family Preprocessor ----------*- C++ -*-===//
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/// \file
10/// Defines the clang::Preprocessor interface.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LEX_PREPROCESSOR_H
15#define LLVM_CLANG_LEX_PREPROCESSOR_H
16
20#include "clang/Basic/LLVM.h"
22#include "clang/Basic/Module.h"
27#include "clang/Lex/Lexer.h"
28#include "clang/Lex/MacroInfo.h"
30#include "clang/Lex/ModuleMap.h"
32#include "clang/Lex/Token.h"
34#include "llvm/ADT/ArrayRef.h"
35#include "llvm/ADT/DenseMap.h"
36#include "llvm/ADT/FoldingSet.h"
37#include "llvm/ADT/FunctionExtras.h"
38#include "llvm/ADT/PointerUnion.h"
39#include "llvm/ADT/STLExtras.h"
40#include "llvm/ADT/SmallPtrSet.h"
41#include "llvm/ADT/SmallVector.h"
42#include "llvm/ADT/StringRef.h"
43#include "llvm/ADT/TinyPtrVector.h"
44#include "llvm/ADT/iterator_range.h"
45#include "llvm/Support/Allocator.h"
46#include "llvm/Support/Casting.h"
47#include "llvm/Support/Registry.h"
48#include <cassert>
49#include <cstddef>
50#include <cstdint>
51#include <map>
52#include <memory>
53#include <optional>
54#include <string>
55#include <utility>
56#include <vector>
57
58namespace llvm {
59
60template<unsigned InternalLen> class SmallString;
61
62} // namespace llvm
63
64namespace clang {
65
66class CodeCompletionHandler;
67class CommentHandler;
68class DirectoryEntry;
69class EmptylineHandler;
70class ExternalPreprocessorSource;
71class FileEntry;
72class FileManager;
73class HeaderSearch;
74class MacroArgs;
75class PragmaHandler;
76class PragmaNamespace;
77class PreprocessingRecord;
78class PreprocessorLexer;
79class PreprocessorOptions;
80class ScratchBuffer;
81class TargetInfo;
82
83namespace Builtin {
84class Context;
85}
86
87/// Stores token information for comparing actual tokens with
88/// predefined values. Only handles simple tokens and identifiers.
90 tok::TokenKind Kind;
92
93public:
94 TokenValue(tok::TokenKind Kind) : Kind(Kind), II(nullptr) {
95 assert(Kind != tok::raw_identifier && "Raw identifiers are not supported.");
96 assert(Kind != tok::identifier &&
97 "Identifiers should be created by TokenValue(IdentifierInfo *)");
98 assert(!tok::isLiteral(Kind) && "Literals are not supported.");
99 assert(!tok::isAnnotation(Kind) && "Annotations are not supported.");
100 }
101
102 TokenValue(IdentifierInfo *II) : Kind(tok::identifier), II(II) {}
103
104 bool operator==(const Token &Tok) const {
105 return Tok.getKind() == Kind &&
106 (!II || II == Tok.getIdentifierInfo());
107 }
108};
109
110/// Context in which macro name is used.
112 // other than #define or #undef
114
115 // macro name specified in #define
117
118 // macro name specified in #undef
119 MU_Undef = 2
121
122/// Engages in a tight little dance with the lexer to efficiently
123/// preprocess tokens.
124///
125/// Lexers know only about tokens within a single source file, and don't
126/// know anything about preprocessor-level issues like the \#include stack,
127/// token expansion, etc.
131
132 llvm::unique_function<void(const clang::Token &)> OnToken;
133 std::shared_ptr<PreprocessorOptions> PPOpts;
134 DiagnosticsEngine *Diags;
135 const LangOptions &LangOpts;
136 const TargetInfo *Target = nullptr;
137 const TargetInfo *AuxTarget = nullptr;
138 FileManager &FileMgr;
139 SourceManager &SourceMgr;
140 std::unique_ptr<ScratchBuffer> ScratchBuf;
141 HeaderSearch &HeaderInfo;
142 ModuleLoader &TheModuleLoader;
143
144 /// External source of macros.
146
147 /// A BumpPtrAllocator object used to quickly allocate and release
148 /// objects internal to the Preprocessor.
149 llvm::BumpPtrAllocator BP;
150
151 /// Identifiers for builtin macros and other builtins.
152 IdentifierInfo *Ident__LINE__, *Ident__FILE__; // __LINE__, __FILE__
153 IdentifierInfo *Ident__DATE__, *Ident__TIME__; // __DATE__, __TIME__
154 IdentifierInfo *Ident__INCLUDE_LEVEL__; // __INCLUDE_LEVEL__
155 IdentifierInfo *Ident__BASE_FILE__; // __BASE_FILE__
156 IdentifierInfo *Ident__FILE_NAME__; // __FILE_NAME__
157 IdentifierInfo *Ident__TIMESTAMP__; // __TIMESTAMP__
158 IdentifierInfo *Ident__COUNTER__; // __COUNTER__
159 IdentifierInfo *Ident_Pragma, *Ident__pragma; // _Pragma, __pragma
160 IdentifierInfo *Ident__identifier; // __identifier
161 IdentifierInfo *Ident__VA_ARGS__; // __VA_ARGS__
162 IdentifierInfo *Ident__VA_OPT__; // __VA_OPT__
163 IdentifierInfo *Ident__has_feature; // __has_feature
164 IdentifierInfo *Ident__has_extension; // __has_extension
165 IdentifierInfo *Ident__has_builtin; // __has_builtin
166 IdentifierInfo *Ident__has_constexpr_builtin; // __has_constexpr_builtin
167 IdentifierInfo *Ident__has_attribute; // __has_attribute
168 IdentifierInfo *Ident__has_include; // __has_include
169 IdentifierInfo *Ident__has_include_next; // __has_include_next
170 IdentifierInfo *Ident__has_warning; // __has_warning
171 IdentifierInfo *Ident__is_identifier; // __is_identifier
172 IdentifierInfo *Ident__building_module; // __building_module
173 IdentifierInfo *Ident__MODULE__; // __MODULE__
174 IdentifierInfo *Ident__has_cpp_attribute; // __has_cpp_attribute
175 IdentifierInfo *Ident__has_c_attribute; // __has_c_attribute
176 IdentifierInfo *Ident__has_declspec; // __has_declspec_attribute
177 IdentifierInfo *Ident__is_target_arch; // __is_target_arch
178 IdentifierInfo *Ident__is_target_vendor; // __is_target_vendor
179 IdentifierInfo *Ident__is_target_os; // __is_target_os
180 IdentifierInfo *Ident__is_target_environment; // __is_target_environment
181 IdentifierInfo *Ident__is_target_variant_os;
182 IdentifierInfo *Ident__is_target_variant_environment;
183 IdentifierInfo *Ident__FLT_EVAL_METHOD__; // __FLT_EVAL_METHOD
184
185 // Weak, only valid (and set) while InMacroArgs is true.
186 Token* ArgMacro;
187
188 SourceLocation DATELoc, TIMELoc;
189
190 // FEM_UnsetOnCommandLine means that an explicit evaluation method was
191 // not specified on the command line. The target is queried to set the
192 // default evaluation method.
193 LangOptions::FPEvalMethodKind CurrentFPEvalMethod =
195
196 // The most recent pragma location where the floating point evaluation
197 // method was modified. This is used to determine whether the
198 // 'pragma clang fp eval_method' was used whithin the current scope.
199 SourceLocation LastFPEvalPragmaLocation;
200
201 LangOptions::FPEvalMethodKind TUFPEvalMethod =
203
204 // Next __COUNTER__ value, starts at 0.
205 unsigned CounterValue = 0;
206
207 enum {
208 /// Maximum depth of \#includes.
209 MaxAllowedIncludeStackDepth = 200
210 };
211
212 // State that is set before the preprocessor begins.
213 bool KeepComments : 1;
214 bool KeepMacroComments : 1;
215 bool SuppressIncludeNotFoundError : 1;
216
217 // State that changes while the preprocessor runs:
218 bool InMacroArgs : 1; // True if parsing fn macro invocation args.
219
220 /// Whether the preprocessor owns the header search object.
221 bool OwnsHeaderSearch : 1;
222
223 /// True if macro expansion is disabled.
224 bool DisableMacroExpansion : 1;
225
226 /// Temporarily disables DisableMacroExpansion (i.e. enables expansion)
227 /// when parsing preprocessor directives.
228 bool MacroExpansionInDirectivesOverride : 1;
229
230 class ResetMacroExpansionHelper;
231
232 /// Whether we have already loaded macros from the external source.
233 mutable bool ReadMacrosFromExternalSource : 1;
234
235 /// True if pragmas are enabled.
236 bool PragmasEnabled : 1;
237
238 /// True if the current build action is a preprocessing action.
239 bool PreprocessedOutput : 1;
240
241 /// True if we are currently preprocessing a #if or #elif directive
242 bool ParsingIfOrElifDirective;
243
244 /// True if we are pre-expanding macro arguments.
245 bool InMacroArgPreExpansion;
246
247 /// Mapping/lookup information for all identifiers in
248 /// the program, including program keywords.
249 mutable IdentifierTable Identifiers;
250
251 /// This table contains all the selectors in the program.
252 ///
253 /// Unlike IdentifierTable above, this table *isn't* populated by the
254 /// preprocessor. It is declared/expanded here because its role/lifetime is
255 /// conceptually similar to the IdentifierTable. In addition, the current
256 /// control flow (in clang::ParseAST()), make it convenient to put here.
257 ///
258 /// FIXME: Make sure the lifetime of Identifiers/Selectors *isn't* tied to
259 /// the lifetime of the preprocessor.
260 SelectorTable Selectors;
261
262 /// Information about builtins.
263 std::unique_ptr<Builtin::Context> BuiltinInfo;
264
265 /// Tracks all of the pragmas that the client registered
266 /// with this preprocessor.
267 std::unique_ptr<PragmaNamespace> PragmaHandlers;
268
269 /// Pragma handlers of the original source is stored here during the
270 /// parsing of a model file.
271 std::unique_ptr<PragmaNamespace> PragmaHandlersBackup;
272
273 /// Tracks all of the comment handlers that the client registered
274 /// with this preprocessor.
275 std::vector<CommentHandler *> CommentHandlers;
276
277 /// Empty line handler.
278 EmptylineHandler *Emptyline = nullptr;
279
280 /// True to avoid tearing down the lexer etc on EOF
281 bool IncrementalProcessing = false;
282
283public:
284 /// The kind of translation unit we are processing.
286
287private:
288 /// The code-completion handler.
289 CodeCompletionHandler *CodeComplete = nullptr;
290
291 /// The file that we're performing code-completion for, if any.
292 const FileEntry *CodeCompletionFile = nullptr;
293
294 /// The offset in file for the code-completion point.
295 unsigned CodeCompletionOffset = 0;
296
297 /// The location for the code-completion point. This gets instantiated
298 /// when the CodeCompletionFile gets \#include'ed for preprocessing.
299 SourceLocation CodeCompletionLoc;
300
301 /// The start location for the file of the code-completion point.
302 ///
303 /// This gets instantiated when the CodeCompletionFile gets \#include'ed
304 /// for preprocessing.
305 SourceLocation CodeCompletionFileLoc;
306
307 /// The source location of the \c import contextual keyword we just
308 /// lexed, if any.
309 SourceLocation ModuleImportLoc;
310
311 /// The import path for named module that we're currently processing.
313
314 /// Whether the import is an `@import` or a standard c++ modules import.
315 bool IsAtImport = false;
316
317 /// Whether the last token we lexed was an '@'.
318 bool LastTokenWasAt = false;
319
320 /// A position within a C++20 import-seq.
321 class StdCXXImportSeq {
322 public:
323 enum State : int {
324 // Positive values represent a number of unclosed brackets.
325 AtTopLevel = 0,
326 AfterTopLevelTokenSeq = -1,
327 AfterExport = -2,
328 AfterImportSeq = -3,
329 };
330
331 StdCXXImportSeq(State S) : S(S) {}
332
333 /// Saw any kind of open bracket.
334 void handleOpenBracket() {
335 S = static_cast<State>(std::max<int>(S, 0) + 1);
336 }
337 /// Saw any kind of close bracket other than '}'.
338 void handleCloseBracket() {
339 S = static_cast<State>(std::max<int>(S, 1) - 1);
340 }
341 /// Saw a close brace.
342 void handleCloseBrace() {
343 handleCloseBracket();
344 if (S == AtTopLevel && !AfterHeaderName)
345 S = AfterTopLevelTokenSeq;
346 }
347 /// Saw a semicolon.
348 void handleSemi() {
349 if (atTopLevel()) {
350 S = AfterTopLevelTokenSeq;
351 AfterHeaderName = false;
352 }
353 }
354
355 /// Saw an 'export' identifier.
356 void handleExport() {
357 if (S == AfterTopLevelTokenSeq)
358 S = AfterExport;
359 else if (S <= 0)
360 S = AtTopLevel;
361 }
362 /// Saw an 'import' identifier.
363 void handleImport() {
364 if (S == AfterTopLevelTokenSeq || S == AfterExport)
365 S = AfterImportSeq;
366 else if (S <= 0)
367 S = AtTopLevel;
368 }
369
370 /// Saw a 'header-name' token; do not recognize any more 'import' tokens
371 /// until we reach a top-level semicolon.
372 void handleHeaderName() {
373 if (S == AfterImportSeq)
374 AfterHeaderName = true;
375 handleMisc();
376 }
377
378 /// Saw any other token.
379 void handleMisc() {
380 if (S <= 0)
381 S = AtTopLevel;
382 }
383
384 bool atTopLevel() { return S <= 0; }
385 bool afterImportSeq() { return S == AfterImportSeq; }
386 bool afterTopLevelSeq() { return S == AfterTopLevelTokenSeq; }
387
388 private:
389 State S;
390 /// Whether we're in the pp-import-suffix following the header-name in a
391 /// pp-import. If so, a close-brace is not sufficient to end the
392 /// top-level-token-seq of an import-seq.
393 bool AfterHeaderName = false;
394 };
395
396 /// Our current position within a C++20 import-seq.
397 StdCXXImportSeq StdCXXImportSeqState = StdCXXImportSeq::AfterTopLevelTokenSeq;
398
399 /// Track whether we are in a Global Module Fragment
400 class TrackGMF {
401 public:
402 enum GMFState : int {
403 GMFActive = 1,
404 MaybeGMF = 0,
405 BeforeGMFIntroducer = -1,
406 GMFAbsentOrEnded = -2,
407 };
408
409 TrackGMF(GMFState S) : S(S) {}
410
411 /// Saw a semicolon.
412 void handleSemi() {
413 // If it is immediately after the first instance of the module keyword,
414 // then that introduces the GMF.
415 if (S == MaybeGMF)
416 S = GMFActive;
417 }
418
419 /// Saw an 'export' identifier.
420 void handleExport() {
421 // The presence of an 'export' keyword always ends or excludes a GMF.
422 S = GMFAbsentOrEnded;
423 }
424
425 /// Saw an 'import' identifier.
426 void handleImport(bool AfterTopLevelTokenSeq) {
427 // If we see this before any 'module' kw, then we have no GMF.
428 if (AfterTopLevelTokenSeq && S == BeforeGMFIntroducer)
429 S = GMFAbsentOrEnded;
430 }
431
432 /// Saw a 'module' identifier.
433 void handleModule(bool AfterTopLevelTokenSeq) {
434 // This was the first module identifier and not preceded by any token
435 // that would exclude a GMF. It could begin a GMF, but only if directly
436 // followed by a semicolon.
437 if (AfterTopLevelTokenSeq && S == BeforeGMFIntroducer)
438 S = MaybeGMF;
439 else
440 S = GMFAbsentOrEnded;
441 }
442
443 /// Saw any other token.
444 void handleMisc() {
445 // We saw something other than ; after the 'module' kw, so not a GMF.
446 if (S == MaybeGMF)
447 S = GMFAbsentOrEnded;
448 }
449
450 bool inGMF() { return S == GMFActive; }
451
452 private:
453 /// Track the transitions into and out of a Global Module Fragment,
454 /// if one is present.
455 GMFState S;
456 };
457
458 TrackGMF TrackGMFState = TrackGMF::BeforeGMFIntroducer;
459
460 /// Track the status of the c++20 module decl.
461 ///
462 /// module-declaration:
463 /// 'export'[opt] 'module' module-name module-partition[opt]
464 /// attribute-specifier-seq[opt] ';'
465 ///
466 /// module-name:
467 /// module-name-qualifier[opt] identifier
468 ///
469 /// module-partition:
470 /// ':' module-name-qualifier[opt] identifier
471 ///
472 /// module-name-qualifier:
473 /// identifier '.'
474 /// module-name-qualifier identifier '.'
475 ///
476 /// Transition state:
477 ///
478 /// NotAModuleDecl --- export ---> FoundExport
479 /// NotAModuleDecl --- module ---> ImplementationCandidate
480 /// FoundExport --- module ---> InterfaceCandidate
481 /// ImplementationCandidate --- Identifier ---> ImplementationCandidate
482 /// ImplementationCandidate --- period ---> ImplementationCandidate
483 /// ImplementationCandidate --- colon ---> ImplementationCandidate
484 /// InterfaceCandidate --- Identifier ---> InterfaceCandidate
485 /// InterfaceCandidate --- period ---> InterfaceCandidate
486 /// InterfaceCandidate --- colon ---> InterfaceCandidate
487 /// ImplementationCandidate --- Semi ---> NamedModuleImplementation
488 /// NamedModuleInterface --- Semi ---> NamedModuleInterface
489 /// NamedModuleImplementation --- Anything ---> NamedModuleImplementation
490 /// NamedModuleInterface --- Anything ---> NamedModuleInterface
491 ///
492 /// FIXME: We haven't handle attribute-specifier-seq here. It may not be bad
493 /// soon since we don't support any module attributes yet.
494 class ModuleDeclSeq {
495 enum ModuleDeclState : int {
496 NotAModuleDecl,
497 FoundExport,
498 InterfaceCandidate,
499 ImplementationCandidate,
500 NamedModuleInterface,
501 NamedModuleImplementation,
502 };
503
504 public:
505 ModuleDeclSeq() = default;
506
507 void handleExport() {
508 if (State == NotAModuleDecl)
509 State = FoundExport;
510 else if (!isNamedModule())
511 reset();
512 }
513
514 void handleModule() {
515 if (State == FoundExport)
516 State = InterfaceCandidate;
517 else if (State == NotAModuleDecl)
518 State = ImplementationCandidate;
519 else if (!isNamedModule())
520 reset();
521 }
522
523 void handleIdentifier(IdentifierInfo *Identifier) {
524 if (isModuleCandidate() && Identifier)
525 Name += Identifier->getName().str();
526 else if (!isNamedModule())
527 reset();
528 }
529
530 void handleColon() {
531 if (isModuleCandidate())
532 Name += ":";
533 else if (!isNamedModule())
534 reset();
535 }
536
537 void handlePeriod() {
538 if (isModuleCandidate())
539 Name += ".";
540 else if (!isNamedModule())
541 reset();
542 }
543
544 void handleSemi() {
545 if (!Name.empty() && isModuleCandidate()) {
546 if (State == InterfaceCandidate)
547 State = NamedModuleInterface;
548 else if (State == ImplementationCandidate)
549 State = NamedModuleImplementation;
550 else
551 llvm_unreachable("Unimaged ModuleDeclState.");
552 } else if (!isNamedModule())
553 reset();
554 }
555
556 void handleMisc() {
557 if (!isNamedModule())
558 reset();
559 }
560
561 bool isModuleCandidate() const {
562 return State == InterfaceCandidate || State == ImplementationCandidate;
563 }
564
565 bool isNamedModule() const {
566 return State == NamedModuleInterface ||
567 State == NamedModuleImplementation;
568 }
569
570 bool isNamedInterface() const { return State == NamedModuleInterface; }
571
572 bool isImplementationUnit() const {
573 return State == NamedModuleImplementation && !getName().contains(':');
574 }
575
576 StringRef getName() const {
577 assert(isNamedModule() && "Can't get name from a non named module");
578 return Name;
579 }
580
581 StringRef getPrimaryName() const {
582 assert(isNamedModule() && "Can't get name from a non named module");
583 return getName().split(':').first;
584 }
585
586 void reset() {
587 Name.clear();
588 State = NotAModuleDecl;
589 }
590
591 private:
592 ModuleDeclState State = NotAModuleDecl;
593 std::string Name;
594 };
595
596 ModuleDeclSeq ModuleDeclState;
597
598 /// Whether the module import expects an identifier next. Otherwise,
599 /// it expects a '.' or ';'.
600 bool ModuleImportExpectsIdentifier = false;
601
602 /// The identifier and source location of the currently-active
603 /// \#pragma clang arc_cf_code_audited begin.
604 std::pair<IdentifierInfo *, SourceLocation> PragmaARCCFCodeAuditedInfo;
605
606 /// The source location of the currently-active
607 /// \#pragma clang assume_nonnull begin.
608 SourceLocation PragmaAssumeNonNullLoc;
609
610 /// Set only for preambles which end with an active
611 /// \#pragma clang assume_nonnull begin.
612 ///
613 /// When the preamble is loaded into the main file,
614 /// `PragmaAssumeNonNullLoc` will be set to this to
615 /// replay the unterminated assume_nonnull.
616 SourceLocation PreambleRecordedPragmaAssumeNonNullLoc;
617
618 /// True if we hit the code-completion point.
619 bool CodeCompletionReached = false;
620
621 /// The code completion token containing the information
622 /// on the stem that is to be code completed.
623 IdentifierInfo *CodeCompletionII = nullptr;
624
625 /// Range for the code completion token.
626 SourceRange CodeCompletionTokenRange;
627
628 /// The directory that the main file should be considered to occupy,
629 /// if it does not correspond to a real file (as happens when building a
630 /// module).
631 OptionalDirectoryEntryRef MainFileDir;
632
633 /// The number of bytes that we will initially skip when entering the
634 /// main file, along with a flag that indicates whether skipping this number
635 /// of bytes will place the lexer at the start of a line.
636 ///
637 /// This is used when loading a precompiled preamble.
638 std::pair<int, bool> SkipMainFilePreamble;
639
640 /// Whether we hit an error due to reaching max allowed include depth. Allows
641 /// to avoid hitting the same error over and over again.
642 bool HasReachedMaxIncludeDepth = false;
643
644 /// The number of currently-active calls to Lex.
645 ///
646 /// Lex is reentrant, and asking for an (end-of-phase-4) token can often
647 /// require asking for multiple additional tokens. This counter makes it
648 /// possible for Lex to detect whether it's producing a token for the end
649 /// of phase 4 of translation or for some other situation.
650 unsigned LexLevel = 0;
651
652 /// The number of (LexLevel 0) preprocessor tokens.
653 unsigned TokenCount = 0;
654
655 /// Preprocess every token regardless of LexLevel.
656 bool PreprocessToken = false;
657
658 /// The maximum number of (LexLevel 0) tokens before issuing a -Wmax-tokens
659 /// warning, or zero for unlimited.
660 unsigned MaxTokens = 0;
661 SourceLocation MaxTokensOverrideLoc;
662
663public:
670
676 ElseLoc(ElseLoc) {}
677 };
678
680
681private:
682 friend class ASTReader;
683 friend class MacroArgs;
684
685 class PreambleConditionalStackStore {
686 enum State {
687 Off = 0,
688 Recording = 1,
689 Replaying = 2,
690 };
691
692 public:
693 PreambleConditionalStackStore() = default;
694
695 void startRecording() { ConditionalStackState = Recording; }
696 void startReplaying() { ConditionalStackState = Replaying; }
697 bool isRecording() const { return ConditionalStackState == Recording; }
698 bool isReplaying() const { return ConditionalStackState == Replaying; }
699
700 ArrayRef<PPConditionalInfo> getStack() const {
701 return ConditionalStack;
702 }
703
704 void doneReplaying() {
705 ConditionalStack.clear();
706 ConditionalStackState = Off;
707 }
708
709 void setStack(ArrayRef<PPConditionalInfo> s) {
710 if (!isRecording() && !isReplaying())
711 return;
712 ConditionalStack.clear();
713 ConditionalStack.append(s.begin(), s.end());
714 }
715
716 bool hasRecordedPreamble() const { return !ConditionalStack.empty(); }
717
718 bool reachedEOFWhileSkipping() const { return SkipInfo.has_value(); }
719
720 void clearSkipInfo() { SkipInfo.reset(); }
721
722 std::optional<PreambleSkipInfo> SkipInfo;
723
724 private:
725 SmallVector<PPConditionalInfo, 4> ConditionalStack;
726 State ConditionalStackState = Off;
727 } PreambleConditionalStack;
728
729 /// The current top of the stack that we're lexing from if
730 /// not expanding a macro and we are lexing directly from source code.
731 ///
732 /// Only one of CurLexer, or CurTokenLexer will be non-null.
733 std::unique_ptr<Lexer> CurLexer;
734
735 /// The current top of the stack that we're lexing from
736 /// if not expanding a macro.
737 ///
738 /// This is an alias for CurLexer.
739 PreprocessorLexer *CurPPLexer = nullptr;
740
741 /// Used to find the current FileEntry, if CurLexer is non-null
742 /// and if applicable.
743 ///
744 /// This allows us to implement \#include_next and find directory-specific
745 /// properties.
746 ConstSearchDirIterator CurDirLookup = nullptr;
747
748 /// The current macro we are expanding, if we are expanding a macro.
749 ///
750 /// One of CurLexer and CurTokenLexer must be null.
751 std::unique_ptr<TokenLexer> CurTokenLexer;
752
753 /// The kind of lexer we're currently working with.
754 enum CurLexerKind {
755 CLK_Lexer,
756 CLK_TokenLexer,
757 CLK_CachingLexer,
758 CLK_DependencyDirectivesLexer,
759 CLK_LexAfterModuleImport
760 } CurLexerKind = CLK_Lexer;
761
762 /// If the current lexer is for a submodule that is being built, this
763 /// is that submodule.
764 Module *CurLexerSubmodule = nullptr;
765
766 /// Keeps track of the stack of files currently
767 /// \#included, and macros currently being expanded from, not counting
768 /// CurLexer/CurTokenLexer.
769 struct IncludeStackInfo {
770 enum CurLexerKind CurLexerKind;
771 Module *TheSubmodule;
772 std::unique_ptr<Lexer> TheLexer;
773 PreprocessorLexer *ThePPLexer;
774 std::unique_ptr<TokenLexer> TheTokenLexer;
775 ConstSearchDirIterator TheDirLookup;
776
777 // The following constructors are completely useless copies of the default
778 // versions, only needed to pacify MSVC.
779 IncludeStackInfo(enum CurLexerKind CurLexerKind, Module *TheSubmodule,
780 std::unique_ptr<Lexer> &&TheLexer,
781 PreprocessorLexer *ThePPLexer,
782 std::unique_ptr<TokenLexer> &&TheTokenLexer,
783 ConstSearchDirIterator TheDirLookup)
784 : CurLexerKind(std::move(CurLexerKind)),
785 TheSubmodule(std::move(TheSubmodule)), TheLexer(std::move(TheLexer)),
786 ThePPLexer(std::move(ThePPLexer)),
787 TheTokenLexer(std::move(TheTokenLexer)),
788 TheDirLookup(std::move(TheDirLookup)) {}
789 };
790 std::vector<IncludeStackInfo> IncludeMacroStack;
791
792 /// Actions invoked when some preprocessor activity is
793 /// encountered (e.g. a file is \#included, etc).
794 std::unique_ptr<PPCallbacks> Callbacks;
795
796 struct MacroExpandsInfo {
797 Token Tok;
798 MacroDefinition MD;
799 SourceRange Range;
800
801 MacroExpandsInfo(Token Tok, MacroDefinition MD, SourceRange Range)
802 : Tok(Tok), MD(MD), Range(Range) {}
803 };
804 SmallVector<MacroExpandsInfo, 2> DelayedMacroExpandsCallbacks;
805
806 /// Information about a name that has been used to define a module macro.
807 struct ModuleMacroInfo {
808 /// The most recent macro directive for this identifier.
809 MacroDirective *MD;
810
811 /// The active module macros for this identifier.
812 llvm::TinyPtrVector<ModuleMacro *> ActiveModuleMacros;
813
814 /// The generation number at which we last updated ActiveModuleMacros.
815 /// \see Preprocessor::VisibleModules.
816 unsigned ActiveModuleMacrosGeneration = 0;
817
818 /// Whether this macro name is ambiguous.
819 bool IsAmbiguous = false;
820
821 /// The module macros that are overridden by this macro.
822 llvm::TinyPtrVector<ModuleMacro *> OverriddenMacros;
823
824 ModuleMacroInfo(MacroDirective *MD) : MD(MD) {}
825 };
826
827 /// The state of a macro for an identifier.
828 class MacroState {
829 mutable llvm::PointerUnion<MacroDirective *, ModuleMacroInfo *> State;
830
831 ModuleMacroInfo *getModuleInfo(Preprocessor &PP,
832 const IdentifierInfo *II) const {
833 if (II->isOutOfDate())
834 PP.updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
835 // FIXME: Find a spare bit on IdentifierInfo and store a
836 // HasModuleMacros flag.
837 if (!II->hasMacroDefinition() ||
838 (!PP.getLangOpts().Modules &&
839 !PP.getLangOpts().ModulesLocalVisibility) ||
840 !PP.CurSubmoduleState->VisibleModules.getGeneration())
841 return nullptr;
842
843 auto *Info = State.dyn_cast<ModuleMacroInfo*>();
844 if (!Info) {
845 Info = new (PP.getPreprocessorAllocator())
846 ModuleMacroInfo(State.get<MacroDirective *>());
847 State = Info;
848 }
849
850 if (PP.CurSubmoduleState->VisibleModules.getGeneration() !=
851 Info->ActiveModuleMacrosGeneration)
852 PP.updateModuleMacroInfo(II, *Info);
853 return Info;
854 }
855
856 public:
857 MacroState() : MacroState(nullptr) {}
858 MacroState(MacroDirective *MD) : State(MD) {}
859
860 MacroState(MacroState &&O) noexcept : State(O.State) {
861 O.State = (MacroDirective *)nullptr;
862 }
863
864 MacroState &operator=(MacroState &&O) noexcept {
865 auto S = O.State;
866 O.State = (MacroDirective *)nullptr;
867 State = S;
868 return *this;
869 }
870
871 ~MacroState() {
872 if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
873 Info->~ModuleMacroInfo();
874 }
875
876 MacroDirective *getLatest() const {
877 if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
878 return Info->MD;
879 return State.get<MacroDirective*>();
880 }
881
882 void setLatest(MacroDirective *MD) {
883 if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
884 Info->MD = MD;
885 else
886 State = MD;
887 }
888
889 bool isAmbiguous(Preprocessor &PP, const IdentifierInfo *II) const {
890 auto *Info = getModuleInfo(PP, II);
891 return Info ? Info->IsAmbiguous : false;
892 }
893
894 ArrayRef<ModuleMacro *>
895 getActiveModuleMacros(Preprocessor &PP, const IdentifierInfo *II) const {
896 if (auto *Info = getModuleInfo(PP, II))
897 return Info->ActiveModuleMacros;
898 return std::nullopt;
899 }
900
901 MacroDirective::DefInfo findDirectiveAtLoc(SourceLocation Loc,
902 SourceManager &SourceMgr) const {
903 // FIXME: Incorporate module macros into the result of this.
904 if (auto *Latest = getLatest())
905 return Latest->findDirectiveAtLoc(Loc, SourceMgr);
906 return {};
907 }
908
909 void overrideActiveModuleMacros(Preprocessor &PP, IdentifierInfo *II) {
910 if (auto *Info = getModuleInfo(PP, II)) {
911 Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
912 Info->ActiveModuleMacros.begin(),
913 Info->ActiveModuleMacros.end());
914 Info->ActiveModuleMacros.clear();
915 Info->IsAmbiguous = false;
916 }
917 }
918
919 ArrayRef<ModuleMacro*> getOverriddenMacros() const {
920 if (auto *Info = State.dyn_cast<ModuleMacroInfo*>())
921 return Info->OverriddenMacros;
922 return std::nullopt;
923 }
924
925 void setOverriddenMacros(Preprocessor &PP,
926 ArrayRef<ModuleMacro *> Overrides) {
927 auto *Info = State.dyn_cast<ModuleMacroInfo*>();
928 if (!Info) {
929 if (Overrides.empty())
930 return;
931 Info = new (PP.getPreprocessorAllocator())
932 ModuleMacroInfo(State.get<MacroDirective *>());
933 State = Info;
934 }
935 Info->OverriddenMacros.clear();
936 Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
937 Overrides.begin(), Overrides.end());
938 Info->ActiveModuleMacrosGeneration = 0;
939 }
940 };
941
942 /// For each IdentifierInfo that was associated with a macro, we
943 /// keep a mapping to the history of all macro definitions and #undefs in
944 /// the reverse order (the latest one is in the head of the list).
945 ///
946 /// This mapping lives within the \p CurSubmoduleState.
947 using MacroMap = llvm::DenseMap<const IdentifierInfo *, MacroState>;
948
949 struct SubmoduleState;
950
951 /// Information about a submodule that we're currently building.
952 struct BuildingSubmoduleInfo {
953 /// The module that we are building.
954 Module *M;
955
956 /// The location at which the module was included.
957 SourceLocation ImportLoc;
958
959 /// Whether we entered this submodule via a pragma.
960 bool IsPragma;
961
962 /// The previous SubmoduleState.
963 SubmoduleState *OuterSubmoduleState;
964
965 /// The number of pending module macro names when we started building this.
966 unsigned OuterPendingModuleMacroNames;
967
968 BuildingSubmoduleInfo(Module *M, SourceLocation ImportLoc, bool IsPragma,
969 SubmoduleState *OuterSubmoduleState,
970 unsigned OuterPendingModuleMacroNames)
971 : M(M), ImportLoc(ImportLoc), IsPragma(IsPragma),
972 OuterSubmoduleState(OuterSubmoduleState),
973 OuterPendingModuleMacroNames(OuterPendingModuleMacroNames) {}
974 };
975 SmallVector<BuildingSubmoduleInfo, 8> BuildingSubmoduleStack;
976
977 /// Information about a submodule's preprocessor state.
978 struct SubmoduleState {
979 /// The macros for the submodule.
980 MacroMap Macros;
981
982 /// The set of modules that are visible within the submodule.
983 VisibleModuleSet VisibleModules;
984
985 // FIXME: CounterValue?
986 // FIXME: PragmaPushMacroInfo?
987 };
988 std::map<Module *, SubmoduleState> Submodules;
989
990 /// The preprocessor state for preprocessing outside of any submodule.
991 SubmoduleState NullSubmoduleState;
992
993 /// The current submodule state. Will be \p NullSubmoduleState if we're not
994 /// in a submodule.
995 SubmoduleState *CurSubmoduleState;
996
997 /// The files that have been included.
998 IncludedFilesSet IncludedFiles;
999
1000 /// The set of top-level modules that affected preprocessing, but were not
1001 /// imported.
1002 llvm::SmallSetVector<Module *, 2> AffectingClangModules;
1003
1004 /// The set of known macros exported from modules.
1005 llvm::FoldingSet<ModuleMacro> ModuleMacros;
1006
1007 /// The names of potential module macros that we've not yet processed.
1008 llvm::SmallVector<const IdentifierInfo *, 32> PendingModuleMacroNames;
1009
1010 /// The list of module macros, for each identifier, that are not overridden by
1011 /// any other module macro.
1012 llvm::DenseMap<const IdentifierInfo *, llvm::TinyPtrVector<ModuleMacro *>>
1013 LeafModuleMacros;
1014
1015 /// Macros that we want to warn because they are not used at the end
1016 /// of the translation unit.
1017 ///
1018 /// We store just their SourceLocations instead of
1019 /// something like MacroInfo*. The benefit of this is that when we are
1020 /// deserializing from PCH, we don't need to deserialize identifier & macros
1021 /// just so that we can report that they are unused, we just warn using
1022 /// the SourceLocations of this set (that will be filled by the ASTReader).
1023 using WarnUnusedMacroLocsTy = llvm::SmallDenseSet<SourceLocation, 32>;
1024 WarnUnusedMacroLocsTy WarnUnusedMacroLocs;
1025
1026 /// This is a pair of an optional message and source location used for pragmas
1027 /// that annotate macros like pragma clang restrict_expansion and pragma clang
1028 /// deprecated. This pair stores the optional message and the location of the
1029 /// annotation pragma for use producing diagnostics and notes.
1030 using MsgLocationPair = std::pair<std::string, SourceLocation>;
1031
1032 struct MacroAnnotationInfo {
1033 SourceLocation Location;
1034 std::string Message;
1035 };
1036
1037 struct MacroAnnotations {
1038 std::optional<MacroAnnotationInfo> DeprecationInfo;
1039 std::optional<MacroAnnotationInfo> RestrictExpansionInfo;
1040 std::optional<SourceLocation> FinalAnnotationLoc;
1041
1042 static MacroAnnotations makeDeprecation(SourceLocation Loc,
1043 std::string Msg) {
1044 return MacroAnnotations{MacroAnnotationInfo{Loc, std::move(Msg)},
1045 std::nullopt, std::nullopt};
1046 }
1047
1048 static MacroAnnotations makeRestrictExpansion(SourceLocation Loc,
1049 std::string Msg) {
1050 return MacroAnnotations{
1051 std::nullopt, MacroAnnotationInfo{Loc, std::move(Msg)}, std::nullopt};
1052 }
1053
1054 static MacroAnnotations makeFinal(SourceLocation Loc) {
1055 return MacroAnnotations{std::nullopt, std::nullopt, Loc};
1056 }
1057 };
1058
1059 /// Warning information for macro annotations.
1060 llvm::DenseMap<const IdentifierInfo *, MacroAnnotations> AnnotationInfos;
1061
1062 /// A "freelist" of MacroArg objects that can be
1063 /// reused for quick allocation.
1064 MacroArgs *MacroArgCache = nullptr;
1065
1066 /// For each IdentifierInfo used in a \#pragma push_macro directive,
1067 /// we keep a MacroInfo stack used to restore the previous macro value.
1068 llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>>
1069 PragmaPushMacroInfo;
1070
1071 // Various statistics we track for performance analysis.
1072 unsigned NumDirectives = 0;
1073 unsigned NumDefined = 0;
1074 unsigned NumUndefined = 0;
1075 unsigned NumPragma = 0;
1076 unsigned NumIf = 0;
1077 unsigned NumElse = 0;
1078 unsigned NumEndif = 0;
1079 unsigned NumEnteredSourceFiles = 0;
1080 unsigned MaxIncludeStackDepth = 0;
1081 unsigned NumMacroExpanded = 0;
1082 unsigned NumFnMacroExpanded = 0;
1083 unsigned NumBuiltinMacroExpanded = 0;
1084 unsigned NumFastMacroExpanded = 0;
1085 unsigned NumTokenPaste = 0;
1086 unsigned NumFastTokenPaste = 0;
1087 unsigned NumSkipped = 0;
1088
1089 /// The predefined macros that preprocessor should use from the
1090 /// command line etc.
1091 std::string Predefines;
1092
1093 /// The file ID for the preprocessor predefines.
1094 FileID PredefinesFileID;
1095
1096 /// The file ID for the PCH through header.
1097 FileID PCHThroughHeaderFileID;
1098
1099 /// Whether tokens are being skipped until a #pragma hdrstop is seen.
1100 bool SkippingUntilPragmaHdrStop = false;
1101
1102 /// Whether tokens are being skipped until the through header is seen.
1103 bool SkippingUntilPCHThroughHeader = false;
1104
1105 /// \{
1106 /// Cache of macro expanders to reduce malloc traffic.
1107 enum { TokenLexerCacheSize = 8 };
1108 unsigned NumCachedTokenLexers;
1109 std::unique_ptr<TokenLexer> TokenLexerCache[TokenLexerCacheSize];
1110 /// \}
1111
1112 /// Keeps macro expanded tokens for TokenLexers.
1113 //
1114 /// Works like a stack; a TokenLexer adds the macro expanded tokens that is
1115 /// going to lex in the cache and when it finishes the tokens are removed
1116 /// from the end of the cache.
1117 SmallVector<Token, 16> MacroExpandedTokens;
1118 std::vector<std::pair<TokenLexer *, size_t>> MacroExpandingLexersStack;
1119
1120 /// A record of the macro definitions and expansions that
1121 /// occurred during preprocessing.
1122 ///
1123 /// This is an optional side structure that can be enabled with
1124 /// \c createPreprocessingRecord() prior to preprocessing.
1125 PreprocessingRecord *Record = nullptr;
1126
1127 /// Cached tokens state.
1128 using CachedTokensTy = SmallVector<Token, 1>;
1129
1130 /// Cached tokens are stored here when we do backtracking or
1131 /// lookahead. They are "lexed" by the CachingLex() method.
1132 CachedTokensTy CachedTokens;
1133
1134 /// The position of the cached token that CachingLex() should
1135 /// "lex" next.
1136 ///
1137 /// If it points beyond the CachedTokens vector, it means that a normal
1138 /// Lex() should be invoked.
1139 CachedTokensTy::size_type CachedLexPos = 0;
1140
1141 /// Stack of backtrack positions, allowing nested backtracks.
1142 ///
1143 /// The EnableBacktrackAtThisPos() method pushes a position to
1144 /// indicate where CachedLexPos should be set when the BackTrack() method is
1145 /// invoked (at which point the last position is popped).
1146 std::vector<CachedTokensTy::size_type> BacktrackPositions;
1147
1148 /// True if \p Preprocessor::SkipExcludedConditionalBlock() is running.
1149 /// This is used to guard against calling this function recursively.
1150 ///
1151 /// See comments at the use-site for more context about why it is needed.
1152 bool SkippingExcludedConditionalBlock = false;
1153
1154 /// Keeps track of skipped range mappings that were recorded while skipping
1155 /// excluded conditional directives. It maps the source buffer pointer at
1156 /// the beginning of a skipped block, to the number of bytes that should be
1157 /// skipped.
1158 llvm::DenseMap<const char *, unsigned> RecordedSkippedRanges;
1159
1160 void updateOutOfDateIdentifier(IdentifierInfo &II) const;
1161
1162public:
1163 Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
1164 DiagnosticsEngine &diags, const LangOptions &LangOpts,
1165 SourceManager &SM, HeaderSearch &Headers,
1166 ModuleLoader &TheModuleLoader,
1167 IdentifierInfoLookup *IILookup = nullptr,
1168 bool OwnsHeaderSearch = false,
1170
1171 ~Preprocessor();
1172
1173 /// Initialize the preprocessor using information about the target.
1174 ///
1175 /// \param Target is owned by the caller and must remain valid for the
1176 /// lifetime of the preprocessor.
1177 /// \param AuxTarget is owned by the caller and must remain valid for
1178 /// the lifetime of the preprocessor.
1179 void Initialize(const TargetInfo &Target,
1180 const TargetInfo *AuxTarget = nullptr);
1181
1182 /// Initialize the preprocessor to parse a model file
1183 ///
1184 /// To parse model files the preprocessor of the original source is reused to
1185 /// preserver the identifier table. However to avoid some duplicate
1186 /// information in the preprocessor some cleanup is needed before it is used
1187 /// to parse model files. This method does that cleanup.
1189
1190 /// Cleanup after model file parsing
1191 void FinalizeForModelFile();
1192
1193 /// Retrieve the preprocessor options used to initialize this
1194 /// preprocessor.
1195 PreprocessorOptions &getPreprocessorOpts() const { return *PPOpts; }
1196
1197 DiagnosticsEngine &getDiagnostics() const { return *Diags; }
1198 void setDiagnostics(DiagnosticsEngine &D) { Diags = &D; }
1199
1200 const LangOptions &getLangOpts() const { return LangOpts; }
1201 const TargetInfo &getTargetInfo() const { return *Target; }
1202 const TargetInfo *getAuxTargetInfo() const { return AuxTarget; }
1203 FileManager &getFileManager() const { return FileMgr; }
1204 SourceManager &getSourceManager() const { return SourceMgr; }
1205 HeaderSearch &getHeaderSearchInfo() const { return HeaderInfo; }
1206
1207 IdentifierTable &getIdentifierTable() { return Identifiers; }
1208 const IdentifierTable &getIdentifierTable() const { return Identifiers; }
1209 SelectorTable &getSelectorTable() { return Selectors; }
1210 Builtin::Context &getBuiltinInfo() { return *BuiltinInfo; }
1211 llvm::BumpPtrAllocator &getPreprocessorAllocator() { return BP; }
1212
1214 ExternalSource = Source;
1215 }
1216
1218 return ExternalSource;
1219 }
1220
1221 /// Retrieve the module loader associated with this preprocessor.
1222 ModuleLoader &getModuleLoader() const { return TheModuleLoader; }
1223
1225 return TheModuleLoader.HadFatalFailure;
1226 }
1227
1228 /// Retrieve the number of Directives that have been processed by the
1229 /// Preprocessor.
1230 unsigned getNumDirectives() const {
1231 return NumDirectives;
1232 }
1233
1234 /// True if we are currently preprocessing a #if or #elif directive
1236 return ParsingIfOrElifDirective;
1237 }
1238
1239 /// Control whether the preprocessor retains comments in output.
1240 void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments) {
1241 this->KeepComments = KeepComments | KeepMacroComments;
1242 this->KeepMacroComments = KeepMacroComments;
1243 }
1244
1245 bool getCommentRetentionState() const { return KeepComments; }
1246
1247 void setPragmasEnabled(bool Enabled) { PragmasEnabled = Enabled; }
1248 bool getPragmasEnabled() const { return PragmasEnabled; }
1249
1251 SuppressIncludeNotFoundError = Suppress;
1252 }
1253
1255 return SuppressIncludeNotFoundError;
1256 }
1257
1258 /// Sets whether the preprocessor is responsible for producing output or if
1259 /// it is producing tokens to be consumed by Parse and Sema.
1260 void setPreprocessedOutput(bool IsPreprocessedOutput) {
1261 PreprocessedOutput = IsPreprocessedOutput;
1262 }
1263
1264 /// Returns true if the preprocessor is responsible for generating output,
1265 /// false if it is producing tokens to be consumed by Parse and Sema.
1266 bool isPreprocessedOutput() const { return PreprocessedOutput; }
1267
1268 /// Return true if we are lexing directly from the specified lexer.
1269 bool isCurrentLexer(const PreprocessorLexer *L) const {
1270 return CurPPLexer == L;
1271 }
1272
1273 /// Return the current lexer being lexed from.
1274 ///
1275 /// Note that this ignores any potentially active macro expansions and _Pragma
1276 /// expansions going on at the time.
1277 PreprocessorLexer *getCurrentLexer() const { return CurPPLexer; }
1278
1279 /// Return the current file lexer being lexed from.
1280 ///
1281 /// Note that this ignores any potentially active macro expansions and _Pragma
1282 /// expansions going on at the time.
1284
1285 /// Return the submodule owning the file being lexed. This may not be
1286 /// the current module if we have changed modules since entering the file.
1287 Module *getCurrentLexerSubmodule() const { return CurLexerSubmodule; }
1288
1289 /// Returns the FileID for the preprocessor predefines.
1290 FileID getPredefinesFileID() const { return PredefinesFileID; }
1291
1292 /// \{
1293 /// Accessors for preprocessor callbacks.
1294 ///
1295 /// Note that this class takes ownership of any PPCallbacks object given to
1296 /// it.
1297 PPCallbacks *getPPCallbacks() const { return Callbacks.get(); }
1298 void addPPCallbacks(std::unique_ptr<PPCallbacks> C) {
1299 if (Callbacks)
1300 C = std::make_unique<PPChainedCallbacks>(std::move(C),
1301 std::move(Callbacks));
1302 Callbacks = std::move(C);
1303 }
1304 /// \}
1305
1306 /// Get the number of tokens processed so far.
1307 unsigned getTokenCount() const { return TokenCount; }
1308
1309 /// Get the max number of tokens before issuing a -Wmax-tokens warning.
1310 unsigned getMaxTokens() const { return MaxTokens; }
1311
1313 MaxTokens = Value;
1314 MaxTokensOverrideLoc = Loc;
1315 };
1316
1317 SourceLocation getMaxTokensOverrideLoc() const { return MaxTokensOverrideLoc; }
1318
1319 /// Register a function that would be called on each token in the final
1320 /// expanded token stream.
1321 /// This also reports annotation tokens produced by the parser.
1322 void setTokenWatcher(llvm::unique_function<void(const clang::Token &)> F) {
1323 OnToken = std::move(F);
1324 }
1325
1326 void setPreprocessToken(bool Preprocess) { PreprocessToken = Preprocess; }
1327
1328 bool isMacroDefined(StringRef Id) {
1329 return isMacroDefined(&Identifiers.get(Id));
1330 }
1332 return II->hasMacroDefinition() &&
1333 (!getLangOpts().Modules || (bool)getMacroDefinition(II));
1334 }
1335
1336 /// Determine whether II is defined as a macro within the module M,
1337 /// if that is a module that we've already preprocessed. Does not check for
1338 /// macros imported into M.
1340 if (!II->hasMacroDefinition())
1341 return false;
1342 auto I = Submodules.find(M);
1343 if (I == Submodules.end())
1344 return false;
1345 auto J = I->second.Macros.find(II);
1346 if (J == I->second.Macros.end())
1347 return false;
1348 auto *MD = J->second.getLatest();
1349 return MD && MD->isDefined();
1350 }
1351
1353 if (!II->hasMacroDefinition())
1354 return {};
1355
1356 MacroState &S = CurSubmoduleState->Macros[II];
1357 auto *MD = S.getLatest();
1358 while (MD && isa<VisibilityMacroDirective>(MD))
1359 MD = MD->getPrevious();
1360 return MacroDefinition(dyn_cast_or_null<DefMacroDirective>(MD),
1361 S.getActiveModuleMacros(*this, II),
1362 S.isAmbiguous(*this, II));
1363 }
1364
1366 SourceLocation Loc) {
1367 if (!II->hadMacroDefinition())
1368 return {};
1369
1370 MacroState &S = CurSubmoduleState->Macros[II];
1372 if (auto *MD = S.getLatest())
1373 DI = MD->findDirectiveAtLoc(Loc, getSourceManager());
1374 // FIXME: Compute the set of active module macros at the specified location.
1375 return MacroDefinition(DI.getDirective(),
1376 S.getActiveModuleMacros(*this, II),
1377 S.isAmbiguous(*this, II));
1378 }
1379
1380 /// Given an identifier, return its latest non-imported MacroDirective
1381 /// if it is \#define'd and not \#undef'd, or null if it isn't \#define'd.
1383 if (!II->hasMacroDefinition())
1384 return nullptr;
1385
1386 auto *MD = getLocalMacroDirectiveHistory(II);
1387 if (!MD || MD->getDefinition().isUndefined())
1388 return nullptr;
1389
1390 return MD;
1391 }
1392
1393 const MacroInfo *getMacroInfo(const IdentifierInfo *II) const {
1394 return const_cast<Preprocessor*>(this)->getMacroInfo(II);
1395 }
1396
1398 if (!II->hasMacroDefinition())
1399 return nullptr;
1400 if (auto MD = getMacroDefinition(II))
1401 return MD.getMacroInfo();
1402 return nullptr;
1403 }
1404
1405 /// Given an identifier, return the latest non-imported macro
1406 /// directive for that identifier.
1407 ///
1408 /// One can iterate over all previous macro directives from the most recent
1409 /// one.
1411
1412 /// Add a directive to the macro directive history for this identifier.
1415 SourceLocation Loc) {
1416 DefMacroDirective *MD = AllocateDefMacroDirective(MI, Loc);
1417 appendMacroDirective(II, MD);
1418 return MD;
1419 }
1421 MacroInfo *MI) {
1422 return appendDefMacroDirective(II, MI, MI->getDefinitionLoc());
1423 }
1424
1425 /// Set a MacroDirective that was loaded from a PCH file.
1427 MacroDirective *MD);
1428
1429 /// Register an exported macro for a module and identifier.
1431 ArrayRef<ModuleMacro *> Overrides, bool &IsNew);
1433
1434 /// Get the list of leaf (non-overridden) module macros for a name.
1436 if (II->isOutOfDate())
1437 updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
1438 auto I = LeafModuleMacros.find(II);
1439 if (I != LeafModuleMacros.end())
1440 return I->second;
1441 return std::nullopt;
1442 }
1443
1444 /// Get the list of submodules that we're currently building.
1446 return BuildingSubmoduleStack;
1447 }
1448
1449 /// \{
1450 /// Iterators for the macro history table. Currently defined macros have
1451 /// IdentifierInfo::hasMacroDefinition() set and an empty
1452 /// MacroInfo::getUndefLoc() at the head of the list.
1453 using macro_iterator = MacroMap::const_iterator;
1454
1455 macro_iterator macro_begin(bool IncludeExternalMacros = true) const;
1456 macro_iterator macro_end(bool IncludeExternalMacros = true) const;
1457
1458 llvm::iterator_range<macro_iterator>
1459 macros(bool IncludeExternalMacros = true) const {
1460 macro_iterator begin = macro_begin(IncludeExternalMacros);
1461 macro_iterator end = macro_end(IncludeExternalMacros);
1462 return llvm::make_range(begin, end);
1463 }
1464
1465 /// \}
1466
1467 /// Mark the given clang module as affecting the current clang module or translation unit.
1469 assert(M->isModuleMapModule());
1470 if (!BuildingSubmoduleStack.empty()) {
1471 if (M != BuildingSubmoduleStack.back().M)
1472 BuildingSubmoduleStack.back().M->AffectingClangModules.insert(M);
1473 } else {
1474 AffectingClangModules.insert(M);
1475 }
1476 }
1477
1478 /// Get the set of top-level clang modules that affected preprocessing, but were not
1479 /// imported.
1481 return AffectingClangModules;
1482 }
1483
1484 /// Mark the file as included.
1485 /// Returns true if this is the first time the file was included.
1487 HeaderInfo.getFileInfo(File);
1488 return IncludedFiles.insert(File).second;
1489 }
1490
1491 /// Return true if this header has already been included.
1493 HeaderInfo.getFileInfo(File);
1494 return IncludedFiles.count(File);
1495 }
1496
1497 /// Get the set of included files.
1498 IncludedFilesSet &getIncludedFiles() { return IncludedFiles; }
1499 const IncludedFilesSet &getIncludedFiles() const { return IncludedFiles; }
1500
1501 /// Return the name of the macro defined before \p Loc that has
1502 /// spelling \p Tokens. If there are multiple macros with same spelling,
1503 /// return the last one defined.
1505 ArrayRef<TokenValue> Tokens) const;
1506
1507 /// Get the predefines for this processor.
1508 /// Used by some third-party tools to inspect and add predefines (see
1509 /// https://github.com/llvm/llvm-project/issues/57483).
1510 const std::string &getPredefines() const { return Predefines; }
1511
1512 /// Set the predefines for this Preprocessor.
1513 ///
1514 /// These predefines are automatically injected when parsing the main file.
1515 void setPredefines(std::string P) { Predefines = std::move(P); }
1516
1517 /// Return information about the specified preprocessor
1518 /// identifier token.
1519 IdentifierInfo *getIdentifierInfo(StringRef Name) const {
1520 return &Identifiers.get(Name);
1521 }
1522
1523 /// Add the specified pragma handler to this preprocessor.
1524 ///
1525 /// If \p Namespace is non-null, then it is a token required to exist on the
1526 /// pragma line before the pragma string starts, e.g. "STDC" or "GCC".
1527 void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler);
1529 AddPragmaHandler(StringRef(), Handler);
1530 }
1531
1532 /// Remove the specific pragma handler from this preprocessor.
1533 ///
1534 /// If \p Namespace is non-null, then it should be the namespace that
1535 /// \p Handler was added to. It is an error to remove a handler that
1536 /// has not been registered.
1537 void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler);
1539 RemovePragmaHandler(StringRef(), Handler);
1540 }
1541
1542 /// Install empty handlers for all pragmas (making them ignored).
1543 void IgnorePragmas();
1544
1545 /// Set empty line handler.
1546 void setEmptylineHandler(EmptylineHandler *Handler) { Emptyline = Handler; }
1547
1548 EmptylineHandler *getEmptylineHandler() const { return Emptyline; }
1549
1550 /// Add the specified comment handler to the preprocessor.
1551 void addCommentHandler(CommentHandler *Handler);
1552
1553 /// Remove the specified comment handler.
1554 ///
1555 /// It is an error to remove a handler that has not been registered.
1556 void removeCommentHandler(CommentHandler *Handler);
1557
1558 /// Set the code completion handler to the given object.
1560 CodeComplete = &Handler;
1561 }
1562
1563 /// Retrieve the current code-completion handler.
1565 return CodeComplete;
1566 }
1567
1568 /// Clear out the code completion handler.
1570 CodeComplete = nullptr;
1571 }
1572
1573 /// Hook used by the lexer to invoke the "included file" code
1574 /// completion point.
1575 void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled);
1576
1577 /// Hook used by the lexer to invoke the "natural language" code
1578 /// completion point.
1580
1581 /// Set the code completion token for filtering purposes.
1583 CodeCompletionII = Filter;
1584 }
1585
1586 /// Set the code completion token range for detecting replacement range later
1587 /// on.
1589 const SourceLocation End) {
1590 CodeCompletionTokenRange = {Start, End};
1591 }
1593 return CodeCompletionTokenRange;
1594 }
1595
1596 /// Get the code completion token for filtering purposes.
1598 if (CodeCompletionII)
1599 return CodeCompletionII->getName();
1600 return {};
1601 }
1602
1603 /// Retrieve the preprocessing record, or NULL if there is no
1604 /// preprocessing record.
1606
1607 /// Create a new preprocessing record, which will keep track of
1608 /// all macro expansions, macro definitions, etc.
1610
1611 /// Returns true if the FileEntry is the PCH through header.
1612 bool isPCHThroughHeader(const FileEntry *FE);
1613
1614 /// True if creating a PCH with a through header.
1616
1617 /// True if using a PCH with a through header.
1619
1620 /// True if creating a PCH with a #pragma hdrstop.
1622
1623 /// True if using a PCH with a #pragma hdrstop.
1625
1626 /// Skip tokens until after the #include of the through header or
1627 /// until after a #pragma hdrstop.
1629
1630 /// Process directives while skipping until the through header or
1631 /// #pragma hdrstop is found.
1633 SourceLocation HashLoc);
1634
1635 /// Enter the specified FileID as the main source file,
1636 /// which implicitly adds the builtin defines etc.
1637 void EnterMainSourceFile();
1638
1639 /// Inform the preprocessor callbacks that processing is complete.
1640 void EndSourceFile();
1641
1642 /// Add a source file to the top of the include stack and
1643 /// start lexing tokens from it instead of the current buffer.
1644 ///
1645 /// Emits a diagnostic, doesn't enter the file, and returns true on error.
1647 SourceLocation Loc, bool IsFirstIncludeOfFile = true);
1648
1649 /// Add a Macro to the top of the include stack and start lexing
1650 /// tokens from it instead of the current buffer.
1651 ///
1652 /// \param Args specifies the tokens input to a function-like macro.
1653 /// \param ILEnd specifies the location of the ')' for a function-like macro
1654 /// or the identifier for an object-like macro.
1655 void EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro,
1656 MacroArgs *Args);
1657
1658private:
1659 /// Add a "macro" context to the top of the include stack,
1660 /// which will cause the lexer to start returning the specified tokens.
1661 ///
1662 /// If \p DisableMacroExpansion is true, tokens lexed from the token stream
1663 /// will not be subject to further macro expansion. Otherwise, these tokens
1664 /// will be re-macro-expanded when/if expansion is enabled.
1665 ///
1666 /// If \p OwnsTokens is false, this method assumes that the specified stream
1667 /// of tokens has a permanent owner somewhere, so they do not need to be
1668 /// copied. If it is true, it assumes the array of tokens is allocated with
1669 /// \c new[] and the Preprocessor will delete[] it.
1670 ///
1671 /// If \p IsReinject the resulting tokens will have Token::IsReinjected flag
1672 /// set, see the flag documentation for details.
1673 void EnterTokenStream(const Token *Toks, unsigned NumToks,
1674 bool DisableMacroExpansion, bool OwnsTokens,
1675 bool IsReinject);
1676
1677public:
1678 void EnterTokenStream(std::unique_ptr<Token[]> Toks, unsigned NumToks,
1679 bool DisableMacroExpansion, bool IsReinject) {
1680 EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion, true,
1681 IsReinject);
1682 }
1683
1684 void EnterTokenStream(ArrayRef<Token> Toks, bool DisableMacroExpansion,
1685 bool IsReinject) {
1686 EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion, false,
1687 IsReinject);
1688 }
1689
1690 /// Pop the current lexer/macro exp off the top of the lexer stack.
1691 ///
1692 /// This should only be used in situations where the current state of the
1693 /// top-of-stack lexer is known.
1694 void RemoveTopOfLexerStack();
1695
1696 /// From the point that this method is called, and until
1697 /// CommitBacktrackedTokens() or Backtrack() is called, the Preprocessor
1698 /// keeps track of the lexed tokens so that a subsequent Backtrack() call will
1699 /// make the Preprocessor re-lex the same tokens.
1700 ///
1701 /// Nested backtracks are allowed, meaning that EnableBacktrackAtThisPos can
1702 /// be called multiple times and CommitBacktrackedTokens/Backtrack calls will
1703 /// be combined with the EnableBacktrackAtThisPos calls in reverse order.
1704 ///
1705 /// NOTE: *DO NOT* forget to call either CommitBacktrackedTokens or Backtrack
1706 /// at some point after EnableBacktrackAtThisPos. If you don't, caching of
1707 /// tokens will continue indefinitely.
1708 ///
1710
1711 /// Disable the last EnableBacktrackAtThisPos call.
1713
1714 /// Make Preprocessor re-lex the tokens that were lexed since
1715 /// EnableBacktrackAtThisPos() was previously called.
1716 void Backtrack();
1717
1718 /// True if EnableBacktrackAtThisPos() was called and
1719 /// caching of tokens is on.
1720 bool isBacktrackEnabled() const { return !BacktrackPositions.empty(); }
1721
1722 /// Lex the next token for this preprocessor.
1723 void Lex(Token &Result);
1724
1725 /// Lex a token, forming a header-name token if possible.
1726 bool LexHeaderName(Token &Result, bool AllowMacroExpansion = true);
1727
1730
1732
1734 return CurSubmoduleState->VisibleModules.getImportLoc(M);
1735 }
1736
1737 /// Lex a string literal, which may be the concatenation of multiple
1738 /// string literals and may even come from macro expansion.
1739 /// \returns true on success, false if a error diagnostic has been generated.
1740 bool LexStringLiteral(Token &Result, std::string &String,
1741 const char *DiagnosticTag, bool AllowMacroExpansion) {
1742 if (AllowMacroExpansion)
1743 Lex(Result);
1744 else
1746 return FinishLexStringLiteral(Result, String, DiagnosticTag,
1747 AllowMacroExpansion);
1748 }
1749
1750 /// Complete the lexing of a string literal where the first token has
1751 /// already been lexed (see LexStringLiteral).
1752 bool FinishLexStringLiteral(Token &Result, std::string &String,
1753 const char *DiagnosticTag,
1754 bool AllowMacroExpansion);
1755
1756 /// Lex a token. If it's a comment, keep lexing until we get
1757 /// something not a comment.
1758 ///
1759 /// This is useful in -E -C mode where comments would foul up preprocessor
1760 /// directive handling.
1762 do
1763 Lex(Result);
1764 while (Result.getKind() == tok::comment);
1765 }
1766
1767 /// Just like Lex, but disables macro expansion of identifier tokens.
1769 // Disable macro expansion.
1770 bool OldVal = DisableMacroExpansion;
1771 DisableMacroExpansion = true;
1772 // Lex the token.
1773 Lex(Result);
1774
1775 // Reenable it.
1776 DisableMacroExpansion = OldVal;
1777 }
1778
1779 /// Like LexNonComment, but this disables macro expansion of
1780 /// identifier tokens.
1782 do
1784 while (Result.getKind() == tok::comment);
1785 }
1786
1787 /// Parses a simple integer literal to get its numeric value. Floating
1788 /// point literals and user defined literals are rejected. Used primarily to
1789 /// handle pragmas that accept integer arguments.
1790 bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value);
1791
1792 /// Disables macro expansion everywhere except for preprocessor directives.
1794 DisableMacroExpansion = true;
1795 MacroExpansionInDirectivesOverride = true;
1796 }
1797
1798 /// Peeks ahead N tokens and returns that token without consuming any
1799 /// tokens.
1800 ///
1801 /// LookAhead(0) returns the next token that would be returned by Lex(),
1802 /// LookAhead(1) returns the token after it, etc. This returns normal
1803 /// tokens after phase 5. As such, it is equivalent to using
1804 /// 'Lex', not 'LexUnexpandedToken'.
1805 const Token &LookAhead(unsigned N) {
1806 assert(LexLevel == 0 && "cannot use lookahead while lexing");
1807 if (CachedLexPos + N < CachedTokens.size())
1808 return CachedTokens[CachedLexPos+N];
1809 else
1810 return PeekAhead(N+1);
1811 }
1812
1813 /// When backtracking is enabled and tokens are cached,
1814 /// this allows to revert a specific number of tokens.
1815 ///
1816 /// Note that the number of tokens being reverted should be up to the last
1817 /// backtrack position, not more.
1818 void RevertCachedTokens(unsigned N) {
1819 assert(isBacktrackEnabled() &&
1820 "Should only be called when tokens are cached for backtracking");
1821 assert(signed(CachedLexPos) - signed(N) >= signed(BacktrackPositions.back())
1822 && "Should revert tokens up to the last backtrack position, not more");
1823 assert(signed(CachedLexPos) - signed(N) >= 0 &&
1824 "Corrupted backtrack positions ?");
1825 CachedLexPos -= N;
1826 }
1827
1828 /// Enters a token in the token stream to be lexed next.
1829 ///
1830 /// If BackTrack() is called afterwards, the token will remain at the
1831 /// insertion point.
1832 /// If \p IsReinject is true, resulting token will have Token::IsReinjected
1833 /// flag set. See the flag documentation for details.
1834 void EnterToken(const Token &Tok, bool IsReinject) {
1835 if (LexLevel) {
1836 // It's not correct in general to enter caching lex mode while in the
1837 // middle of a nested lexing action.
1838 auto TokCopy = std::make_unique<Token[]>(1);
1839 TokCopy[0] = Tok;
1840 EnterTokenStream(std::move(TokCopy), 1, true, IsReinject);
1841 } else {
1842 EnterCachingLexMode();
1843 assert(IsReinject && "new tokens in the middle of cached stream");
1844 CachedTokens.insert(CachedTokens.begin()+CachedLexPos, Tok);
1845 }
1846 }
1847
1848 /// We notify the Preprocessor that if it is caching tokens (because
1849 /// backtrack is enabled) it should replace the most recent cached tokens
1850 /// with the given annotation token. This function has no effect if
1851 /// backtracking is not enabled.
1852 ///
1853 /// Note that the use of this function is just for optimization, so that the
1854 /// cached tokens doesn't get re-parsed and re-resolved after a backtrack is
1855 /// invoked.
1856 void AnnotateCachedTokens(const Token &Tok) {
1857 assert(Tok.isAnnotation() && "Expected annotation token");
1858 if (CachedLexPos != 0 && isBacktrackEnabled())
1859 AnnotatePreviousCachedTokens(Tok);
1860 }
1861
1862 /// Get the location of the last cached token, suitable for setting the end
1863 /// location of an annotation token.
1865 assert(CachedLexPos != 0);
1866 return CachedTokens[CachedLexPos-1].getLastLoc();
1867 }
1868
1869 /// Whether \p Tok is the most recent token (`CachedLexPos - 1`) in
1870 /// CachedTokens.
1871 bool IsPreviousCachedToken(const Token &Tok) const;
1872
1873 /// Replace token in `CachedLexPos - 1` in CachedTokens by the tokens
1874 /// in \p NewToks.
1875 ///
1876 /// Useful when a token needs to be split in smaller ones and CachedTokens
1877 /// most recent token must to be updated to reflect that.
1879
1880 /// Replace the last token with an annotation token.
1881 ///
1882 /// Like AnnotateCachedTokens(), this routine replaces an
1883 /// already-parsed (and resolved) token with an annotation
1884 /// token. However, this routine only replaces the last token with
1885 /// the annotation token; it does not affect any other cached
1886 /// tokens. This function has no effect if backtracking is not
1887 /// enabled.
1889 assert(Tok.isAnnotation() && "Expected annotation token");
1890 if (CachedLexPos != 0 && isBacktrackEnabled())
1891 CachedTokens[CachedLexPos-1] = Tok;
1892 }
1893
1894 /// Enter an annotation token into the token stream.
1896 void *AnnotationVal);
1897
1898 /// Determine whether it's possible for a future call to Lex to produce an
1899 /// annotation token created by a previous call to EnterAnnotationToken.
1901 return CurLexerKind != CLK_Lexer;
1902 }
1903
1904 /// Update the current token to represent the provided
1905 /// identifier, in order to cache an action performed by typo correction.
1906 void TypoCorrectToken(const Token &Tok) {
1907 assert(Tok.getIdentifierInfo() && "Expected identifier token");
1908 if (CachedLexPos != 0 && isBacktrackEnabled())
1909 CachedTokens[CachedLexPos-1] = Tok;
1910 }
1911
1912 /// Recompute the current lexer kind based on the CurLexer/
1913 /// CurTokenLexer pointers.
1914 void recomputeCurLexerKind();
1915
1916 /// Returns true if incremental processing is enabled
1917 bool isIncrementalProcessingEnabled() const { return IncrementalProcessing; }
1918
1919 /// Enables the incremental processing
1920 void enableIncrementalProcessing(bool value = true) {
1921 IncrementalProcessing = value;
1922 }
1923
1924 /// Specify the point at which code-completion will be performed.
1925 ///
1926 /// \param File the file in which code completion should occur. If
1927 /// this file is included multiple times, code-completion will
1928 /// perform completion the first time it is included. If NULL, this
1929 /// function clears out the code-completion point.
1930 ///
1931 /// \param Line the line at which code completion should occur
1932 /// (1-based).
1933 ///
1934 /// \param Column the column at which code completion should occur
1935 /// (1-based).
1936 ///
1937 /// \returns true if an error occurred, false otherwise.
1938 bool SetCodeCompletionPoint(FileEntryRef File, unsigned Line,
1939 unsigned Column);
1940
1941 /// Determine if we are performing code completion.
1942 bool isCodeCompletionEnabled() const { return CodeCompletionFile != nullptr; }
1943
1944 /// Returns the location of the code-completion point.
1945 ///
1946 /// Returns an invalid location if code-completion is not enabled or the file
1947 /// containing the code-completion point has not been lexed yet.
1948 SourceLocation getCodeCompletionLoc() const { return CodeCompletionLoc; }
1949
1950 /// Returns the start location of the file of code-completion point.
1951 ///
1952 /// Returns an invalid location if code-completion is not enabled or the file
1953 /// containing the code-completion point has not been lexed yet.
1955 return CodeCompletionFileLoc;
1956 }
1957
1958 /// Returns true if code-completion is enabled and we have hit the
1959 /// code-completion point.
1960 bool isCodeCompletionReached() const { return CodeCompletionReached; }
1961
1962 /// Note that we hit the code-completion point.
1964 assert(isCodeCompletionEnabled() && "Code-completion not enabled!");
1965 CodeCompletionReached = true;
1966 // Silence any diagnostics that occur after we hit the code-completion.
1968 }
1969
1970 /// The location of the currently-active \#pragma clang
1971 /// arc_cf_code_audited begin.
1972 ///
1973 /// Returns an invalid location if there is no such pragma active.
1974 std::pair<IdentifierInfo *, SourceLocation>
1976 return PragmaARCCFCodeAuditedInfo;
1977 }
1978
1979 /// Set the location of the currently-active \#pragma clang
1980 /// arc_cf_code_audited begin. An invalid location ends the pragma.
1982 SourceLocation Loc) {
1983 PragmaARCCFCodeAuditedInfo = {Ident, Loc};
1984 }
1985
1986 /// The location of the currently-active \#pragma clang
1987 /// assume_nonnull begin.
1988 ///
1989 /// Returns an invalid location if there is no such pragma active.
1991 return PragmaAssumeNonNullLoc;
1992 }
1993
1994 /// Set the location of the currently-active \#pragma clang
1995 /// assume_nonnull begin. An invalid location ends the pragma.
1997 PragmaAssumeNonNullLoc = Loc;
1998 }
1999
2000 /// Get the location of the recorded unterminated \#pragma clang
2001 /// assume_nonnull begin in the preamble, if one exists.
2002 ///
2003 /// Returns an invalid location if the premable did not end with
2004 /// such a pragma active or if there is no recorded preamble.
2006 return PreambleRecordedPragmaAssumeNonNullLoc;
2007 }
2008
2009 /// Record the location of the unterminated \#pragma clang
2010 /// assume_nonnull begin in the preamble.
2012 PreambleRecordedPragmaAssumeNonNullLoc = Loc;
2013 }
2014
2015 /// Set the directory in which the main file should be considered
2016 /// to have been found, if it is not a real file.
2017 void setMainFileDir(DirectoryEntryRef Dir) { MainFileDir = Dir; }
2018
2019 /// Instruct the preprocessor to skip part of the main source file.
2020 ///
2021 /// \param Bytes The number of bytes in the preamble to skip.
2022 ///
2023 /// \param StartOfLine Whether skipping these bytes puts the lexer at the
2024 /// start of a line.
2025 void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine) {
2026 SkipMainFilePreamble.first = Bytes;
2027 SkipMainFilePreamble.second = StartOfLine;
2028 }
2029
2030 /// Forwarding function for diagnostics. This emits a diagnostic at
2031 /// the specified Token's location, translating the token's start
2032 /// position in the current buffer into a SourcePosition object for rendering.
2033 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const {
2034 return Diags->Report(Loc, DiagID);
2035 }
2036
2037 DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) const {
2038 return Diags->Report(Tok.getLocation(), DiagID);
2039 }
2040
2041 /// Return the 'spelling' of the token at the given
2042 /// location; does not go up to the spelling location or down to the
2043 /// expansion location.
2044 ///
2045 /// \param buffer A buffer which will be used only if the token requires
2046 /// "cleaning", e.g. if it contains trigraphs or escaped newlines
2047 /// \param invalid If non-null, will be set \c true if an error occurs.
2049 SmallVectorImpl<char> &buffer,
2050 bool *invalid = nullptr) const {
2051 return Lexer::getSpelling(loc, buffer, SourceMgr, LangOpts, invalid);
2052 }
2053
2054 /// Return the 'spelling' of the Tok token.
2055 ///
2056 /// The spelling of a token is the characters used to represent the token in
2057 /// the source file after trigraph expansion and escaped-newline folding. In
2058 /// particular, this wants to get the true, uncanonicalized, spelling of
2059 /// things like digraphs, UCNs, etc.
2060 ///
2061 /// \param Invalid If non-null, will be set \c true if an error occurs.
2062 std::string getSpelling(const Token &Tok, bool *Invalid = nullptr) const {
2063 return Lexer::getSpelling(Tok, SourceMgr, LangOpts, Invalid);
2064 }
2065
2066 /// Get the spelling of a token into a preallocated buffer, instead
2067 /// of as an std::string.
2068 ///
2069 /// The caller is required to allocate enough space for the token, which is
2070 /// guaranteed to be at least Tok.getLength() bytes long. The length of the
2071 /// actual result is returned.
2072 ///
2073 /// Note that this method may do two possible things: it may either fill in
2074 /// the buffer specified with characters, or it may *change the input pointer*
2075 /// to point to a constant buffer with the data already in it (avoiding a
2076 /// copy). The caller is not allowed to modify the returned buffer pointer
2077 /// if an internal buffer is returned.
2078 unsigned getSpelling(const Token &Tok, const char *&Buffer,
2079 bool *Invalid = nullptr) const {
2080 return Lexer::getSpelling(Tok, Buffer, SourceMgr, LangOpts, Invalid);
2081 }
2082
2083 /// Get the spelling of a token into a SmallVector.
2084 ///
2085 /// Note that the returned StringRef may not point to the
2086 /// supplied buffer if a copy can be avoided.
2087 StringRef getSpelling(const Token &Tok,
2088 SmallVectorImpl<char> &Buffer,
2089 bool *Invalid = nullptr) const;
2090
2091 /// Relex the token at the specified location.
2092 /// \returns true if there was a failure, false on success.
2094 bool IgnoreWhiteSpace = false) {
2095 return Lexer::getRawToken(Loc, Result, SourceMgr, LangOpts, IgnoreWhiteSpace);
2096 }
2097
2098 /// Given a Token \p Tok that is a numeric constant with length 1,
2099 /// return the character.
2100 char
2102 bool *Invalid = nullptr) const {
2103 assert(Tok.is(tok::numeric_constant) &&
2104 Tok.getLength() == 1 && "Called on unsupported token");
2105 assert(!Tok.needsCleaning() && "Token can't need cleaning with length 1");
2106
2107 // If the token is carrying a literal data pointer, just use it.
2108 if (const char *D = Tok.getLiteralData())
2109 return *D;
2110
2111 // Otherwise, fall back on getCharacterData, which is slower, but always
2112 // works.
2113 return *SourceMgr.getCharacterData(Tok.getLocation(), Invalid);
2114 }
2115
2116 /// Retrieve the name of the immediate macro expansion.
2117 ///
2118 /// This routine starts from a source location, and finds the name of the
2119 /// macro responsible for its immediate expansion. It looks through any
2120 /// intervening macro argument expansions to compute this. It returns a
2121 /// StringRef that refers to the SourceManager-owned buffer of the source
2122 /// where that macro name is spelled. Thus, the result shouldn't out-live
2123 /// the SourceManager.
2125 return Lexer::getImmediateMacroName(Loc, SourceMgr, getLangOpts());
2126 }
2127
2128 /// Plop the specified string into a scratch buffer and set the
2129 /// specified token's location and length to it.
2130 ///
2131 /// If specified, the source location provides a location of the expansion
2132 /// point of the token.
2133 void CreateString(StringRef Str, Token &Tok,
2134 SourceLocation ExpansionLocStart = SourceLocation(),
2135 SourceLocation ExpansionLocEnd = SourceLocation());
2136
2137 /// Split the first Length characters out of the token starting at TokLoc
2138 /// and return a location pointing to the split token. Re-lexing from the
2139 /// split token will return the split token rather than the original.
2140 SourceLocation SplitToken(SourceLocation TokLoc, unsigned Length);
2141
2142 /// Computes the source location just past the end of the
2143 /// token at this source location.
2144 ///
2145 /// This routine can be used to produce a source location that
2146 /// points just past the end of the token referenced by \p Loc, and
2147 /// is generally used when a diagnostic needs to point just after a
2148 /// token where it expected something different that it received. If
2149 /// the returned source location would not be meaningful (e.g., if
2150 /// it points into a macro), this routine returns an invalid
2151 /// source location.
2152 ///
2153 /// \param Offset an offset from the end of the token, where the source
2154 /// location should refer to. The default offset (0) produces a source
2155 /// location pointing just past the end of the token; an offset of 1 produces
2156 /// a source location pointing to the last character in the token, etc.
2158 return Lexer::getLocForEndOfToken(Loc, Offset, SourceMgr, LangOpts);
2159 }
2160
2161 /// Returns true if the given MacroID location points at the first
2162 /// token of the macro expansion.
2163 ///
2164 /// \param MacroBegin If non-null and function returns true, it is set to
2165 /// begin location of the macro.
2167 SourceLocation *MacroBegin = nullptr) const {
2168 return Lexer::isAtStartOfMacroExpansion(loc, SourceMgr, LangOpts,
2169 MacroBegin);
2170 }
2171
2172 /// Returns true if the given MacroID location points at the last
2173 /// token of the macro expansion.
2174 ///
2175 /// \param MacroEnd If non-null and function returns true, it is set to
2176 /// end location of the macro.
2178 SourceLocation *MacroEnd = nullptr) const {
2179 return Lexer::isAtEndOfMacroExpansion(loc, SourceMgr, LangOpts, MacroEnd);
2180 }
2181
2182 /// Print the token to stderr, used for debugging.
2183 void DumpToken(const Token &Tok, bool DumpFlags = false) const;
2184 void DumpLocation(SourceLocation Loc) const;
2185 void DumpMacro(const MacroInfo &MI) const;
2186 void dumpMacroInfo(const IdentifierInfo *II);
2187
2188 /// Given a location that specifies the start of a
2189 /// token, return a new location that specifies a character within the token.
2191 unsigned Char) const {
2192 return Lexer::AdvanceToTokenCharacter(TokStart, Char, SourceMgr, LangOpts);
2193 }
2194
2195 /// Increment the counters for the number of token paste operations
2196 /// performed.
2197 ///
2198 /// If fast was specified, this is a 'fast paste' case we handled.
2199 void IncrementPasteCounter(bool isFast) {
2200 if (isFast)
2201 ++NumFastTokenPaste;
2202 else
2203 ++NumTokenPaste;
2204 }
2205
2206 void PrintStats();
2207
2208 size_t getTotalMemory() const;
2209
2210 /// When the macro expander pastes together a comment (/##/) in Microsoft
2211 /// mode, this method handles updating the current state, returning the
2212 /// token on the next source line.
2214
2215 //===--------------------------------------------------------------------===//
2216 // Preprocessor callback methods. These are invoked by a lexer as various
2217 // directives and events are found.
2218
2219 /// Given a tok::raw_identifier token, look up the
2220 /// identifier information for the token and install it into the token,
2221 /// updating the token kind accordingly.
2223
2224private:
2225 llvm::DenseMap<IdentifierInfo*,unsigned> PoisonReasons;
2226
2227public:
2228 /// Specifies the reason for poisoning an identifier.
2229 ///
2230 /// If that identifier is accessed while poisoned, then this reason will be
2231 /// used instead of the default "poisoned" diagnostic.
2232 void SetPoisonReason(IdentifierInfo *II, unsigned DiagID);
2233
2234 /// Display reason for poisoned identifier.
2236
2238 if(IdentifierInfo * II = Identifier.getIdentifierInfo()) {
2239 if(II->isPoisoned()) {
2241 }
2242 }
2243 }
2244
2245private:
2246 /// Identifiers used for SEH handling in Borland. These are only
2247 /// allowed in particular circumstances
2248 // __except block
2249 IdentifierInfo *Ident__exception_code,
2250 *Ident___exception_code,
2251 *Ident_GetExceptionCode;
2252 // __except filter expression
2253 IdentifierInfo *Ident__exception_info,
2254 *Ident___exception_info,
2255 *Ident_GetExceptionInfo;
2256 // __finally
2257 IdentifierInfo *Ident__abnormal_termination,
2258 *Ident___abnormal_termination,
2259 *Ident_AbnormalTermination;
2260
2261 const char *getCurLexerEndPos();
2262 void diagnoseMissingHeaderInUmbrellaDir(const Module &Mod);
2263
2264public:
2265 void PoisonSEHIdentifiers(bool Poison = true); // Borland
2266
2267 /// Callback invoked when the lexer reads an identifier and has
2268 /// filled in the tokens IdentifierInfo member.
2269 ///
2270 /// This callback potentially macro expands it or turns it into a named
2271 /// token (like 'for').
2272 ///
2273 /// \returns true if we actually computed a token, false if we need to
2274 /// lex again.
2276
2277 /// Callback invoked when the lexer hits the end of the current file.
2278 ///
2279 /// This either returns the EOF token and returns true, or
2280 /// pops a level off the include stack and returns false, at which point the
2281 /// client should call lex again.
2282 bool HandleEndOfFile(Token &Result, bool isEndOfMacro = false);
2283
2284 /// Callback invoked when the current TokenLexer hits the end of its
2285 /// token stream.
2287
2288 /// Callback invoked when the lexer sees a # token at the start of a
2289 /// line.
2290 ///
2291 /// This consumes the directive, modifies the lexer/preprocessor state, and
2292 /// advances the lexer(s) so that the next token read is the correct one.
2294
2295 /// Ensure that the next token is a tok::eod token.
2296 ///
2297 /// If not, emit a diagnostic and consume up until the eod.
2298 /// If \p EnableMacros is true, then we consider macros that expand to zero
2299 /// tokens as being ok.
2300 ///
2301 /// \return The location of the end of the directive (the terminating
2302 /// newline).
2303 SourceLocation CheckEndOfDirective(const char *DirType,
2304 bool EnableMacros = false);
2305
2306 /// Read and discard all tokens remaining on the current line until
2307 /// the tok::eod token is found. Returns the range of the skipped tokens.
2309
2310 /// Returns true if the preprocessor has seen a use of
2311 /// __DATE__ or __TIME__ in the file so far.
2312 bool SawDateOrTime() const {
2313 return DATELoc != SourceLocation() || TIMELoc != SourceLocation();
2314 }
2315 unsigned getCounterValue() const { return CounterValue; }
2316 void setCounterValue(unsigned V) { CounterValue = V; }
2317
2319 assert(CurrentFPEvalMethod != LangOptions::FEM_UnsetOnCommandLine &&
2320 "FPEvalMethod should be set either from command line or from the "
2321 "target info");
2322 return CurrentFPEvalMethod;
2323 }
2324
2326 return TUFPEvalMethod;
2327 }
2328
2330 return LastFPEvalPragmaLocation;
2331 }
2332
2336 "FPEvalMethod should never be set to FEM_UnsetOnCommandLine");
2337 // This is the location of the '#pragma float_control" where the
2338 // execution state is modifed.
2339 LastFPEvalPragmaLocation = PragmaLoc;
2340 CurrentFPEvalMethod = Val;
2341 TUFPEvalMethod = Val;
2342 }
2343
2346 "TUPEvalMethod should never be set to FEM_UnsetOnCommandLine");
2347 TUFPEvalMethod = Val;
2348 }
2349
2350 /// Retrieves the module that we're currently building, if any.
2352
2353 /// Retrieves the module whose implementation we're current compiling, if any.
2355
2356 /// If we are preprocessing a named module.
2357 bool isInNamedModule() const { return ModuleDeclState.isNamedModule(); }
2358
2359 /// If we are proprocessing a named interface unit.
2360 /// Note that a module implementation partition is not considered as an
2361 /// named interface unit here although it is importable
2362 /// to ease the parsing.
2364 return ModuleDeclState.isNamedInterface();
2365 }
2366
2367 /// Get the named module name we're preprocessing.
2368 /// Requires we're preprocessing a named module.
2369 StringRef getNamedModuleName() const { return ModuleDeclState.getName(); }
2370
2371 /// If we are implementing an implementation module unit.
2372 /// Note that the module implementation partition is not considered as an
2373 /// implementation unit.
2375 return ModuleDeclState.isImplementationUnit();
2376 }
2377
2378 /// If we're importing a standard C++20 Named Modules.
2380 // NamedModuleImportPath will be non-empty only if we're importing
2381 // Standard C++ named modules.
2382 return !NamedModuleImportPath.empty() && getLangOpts().CPlusPlusModules &&
2383 !IsAtImport;
2384 }
2385
2386 /// Allocate a new MacroInfo object with the provided SourceLocation.
2388
2389 /// Turn the specified lexer token into a fully checked and spelled
2390 /// filename, e.g. as an operand of \#include.
2391 ///
2392 /// The caller is expected to provide a buffer that is large enough to hold
2393 /// the spelling of the filename, but is also expected to handle the case
2394 /// when this method decides to use a different buffer.
2395 ///
2396 /// \returns true if the input filename was in <>'s or false if it was
2397 /// in ""'s.
2398 bool GetIncludeFilenameSpelling(SourceLocation Loc,StringRef &Buffer);
2399
2400 /// Given a "foo" or <foo> reference, look up the indicated file.
2401 ///
2402 /// Returns std::nullopt on failure. \p isAngled indicates whether the file
2403 /// reference is for system \#include's or not (i.e. using <> instead of "").
2405 LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled,
2406 ConstSearchDirIterator FromDir, const FileEntry *FromFile,
2407 ConstSearchDirIterator *CurDir, SmallVectorImpl<char> *SearchPath,
2408 SmallVectorImpl<char> *RelativePath,
2409 ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped,
2410 bool *IsFrameworkFound, bool SkipCache = false,
2411 bool OpenFile = true, bool CacheFailures = true);
2412
2413 /// Return true if we're in the top-level file, not in a \#include.
2414 bool isInPrimaryFile() const;
2415
2416 /// Lex an on-off-switch (C99 6.10.6p2) and verify that it is
2417 /// followed by EOD. Return true if the token is not a valid on-off-switch.
2419
2420 bool CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef,
2421 bool *ShadowFlag = nullptr);
2422
2423 void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma);
2424 Module *LeaveSubmodule(bool ForPragma);
2425
2426private:
2428
2429 void PushIncludeMacroStack() {
2430 assert(CurLexerKind != CLK_CachingLexer && "cannot push a caching lexer");
2431 IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
2432 std::move(CurLexer), CurPPLexer,
2433 std::move(CurTokenLexer), CurDirLookup);
2434 CurPPLexer = nullptr;
2435 }
2436
2437 void PopIncludeMacroStack() {
2438 CurLexer = std::move(IncludeMacroStack.back().TheLexer);
2439 CurPPLexer = IncludeMacroStack.back().ThePPLexer;
2440 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
2441 CurDirLookup = IncludeMacroStack.back().TheDirLookup;
2442 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
2443 CurLexerKind = IncludeMacroStack.back().CurLexerKind;
2444 IncludeMacroStack.pop_back();
2445 }
2446
2447 void PropagateLineStartLeadingSpaceInfo(Token &Result);
2448
2449 /// Determine whether we need to create module macros for #defines in the
2450 /// current context.
2451 bool needModuleMacros() const;
2452
2453 /// Update the set of active module macros and ambiguity flag for a module
2454 /// macro name.
2455 void updateModuleMacroInfo(const IdentifierInfo *II, ModuleMacroInfo &Info);
2456
2457 DefMacroDirective *AllocateDefMacroDirective(MacroInfo *MI,
2458 SourceLocation Loc);
2459 UndefMacroDirective *AllocateUndefMacroDirective(SourceLocation UndefLoc);
2460 VisibilityMacroDirective *AllocateVisibilityMacroDirective(SourceLocation Loc,
2461 bool isPublic);
2462
2463 /// Lex and validate a macro name, which occurs after a
2464 /// \#define or \#undef.
2465 ///
2466 /// \param MacroNameTok Token that represents the name defined or undefined.
2467 /// \param IsDefineUndef Kind if preprocessor directive.
2468 /// \param ShadowFlag Points to flag that is set if macro name shadows
2469 /// a keyword.
2470 ///
2471 /// This emits a diagnostic, sets the token kind to eod,
2472 /// and discards the rest of the macro line if the macro name is invalid.
2473 void ReadMacroName(Token &MacroNameTok, MacroUse IsDefineUndef = MU_Other,
2474 bool *ShadowFlag = nullptr);
2475
2476 /// ReadOptionalMacroParameterListAndBody - This consumes all (i.e. the
2477 /// entire line) of the macro's tokens and adds them to MacroInfo, and while
2478 /// doing so performs certain validity checks including (but not limited to):
2479 /// - # (stringization) is followed by a macro parameter
2480 /// \param MacroNameTok - Token that represents the macro name
2481 /// \param ImmediatelyAfterHeaderGuard - Macro follows an #ifdef header guard
2482 ///
2483 /// Either returns a pointer to a MacroInfo object OR emits a diagnostic and
2484 /// returns a nullptr if an invalid sequence of tokens is encountered.
2485 MacroInfo *ReadOptionalMacroParameterListAndBody(
2486 const Token &MacroNameTok, bool ImmediatelyAfterHeaderGuard);
2487
2488 /// The ( starting an argument list of a macro definition has just been read.
2489 /// Lex the rest of the parameters and the closing ), updating \p MI with
2490 /// what we learn and saving in \p LastTok the last token read.
2491 /// Return true if an error occurs parsing the arg list.
2492 bool ReadMacroParameterList(MacroInfo *MI, Token& LastTok);
2493
2494 /// Provide a suggestion for a typoed directive. If there is no typo, then
2495 /// just skip suggesting.
2496 ///
2497 /// \param Tok - Token that represents the directive
2498 /// \param Directive - String reference for the directive name
2499 void SuggestTypoedDirective(const Token &Tok, StringRef Directive) const;
2500
2501 /// We just read a \#if or related directive and decided that the
2502 /// subsequent tokens are in the \#if'd out portion of the
2503 /// file. Lex the rest of the file, until we see an \#endif. If \p
2504 /// FoundNonSkipPortion is true, then we have already emitted code for part of
2505 /// this \#if directive, so \#else/\#elif blocks should never be entered. If
2506 /// \p FoundElse is false, then \#else directives are ok, if not, then we have
2507 /// already seen one so a \#else directive is a duplicate. When this returns,
2508 /// the caller can lex the first valid token.
2509 void SkipExcludedConditionalBlock(SourceLocation HashTokenLoc,
2510 SourceLocation IfTokenLoc,
2511 bool FoundNonSkipPortion, bool FoundElse,
2512 SourceLocation ElseLoc = SourceLocation());
2513
2514 /// Information about the result for evaluating an expression for a
2515 /// preprocessor directive.
2516 struct DirectiveEvalResult {
2517 /// Whether the expression was evaluated as true or not.
2518 bool Conditional;
2519
2520 /// True if the expression contained identifiers that were undefined.
2521 bool IncludedUndefinedIds;
2522
2523 /// The source range for the expression.
2524 SourceRange ExprRange;
2525 };
2526
2527 /// Evaluate an integer constant expression that may occur after a
2528 /// \#if or \#elif directive and return a \p DirectiveEvalResult object.
2529 ///
2530 /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro.
2531 DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro);
2532
2533 /// Process a '__has_include("path")' expression.
2534 ///
2535 /// Returns true if successful.
2536 bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II);
2537
2538 /// Process '__has_include_next("path")' expression.
2539 ///
2540 /// Returns true if successful.
2541 bool EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II);
2542
2543 /// Get the directory and file from which to start \#include_next lookup.
2544 std::pair<ConstSearchDirIterator, const FileEntry *>
2545 getIncludeNextStart(const Token &IncludeNextTok) const;
2546
2547 /// Install the standard preprocessor pragmas:
2548 /// \#pragma GCC poison/system_header/dependency and \#pragma once.
2549 void RegisterBuiltinPragmas();
2550
2551 /// Register builtin macros such as __LINE__ with the identifier table.
2552 void RegisterBuiltinMacros();
2553
2554 /// If an identifier token is read that is to be expanded as a macro, handle
2555 /// it and return the next token as 'Tok'. If we lexed a token, return true;
2556 /// otherwise the caller should lex again.
2557 bool HandleMacroExpandedIdentifier(Token &Identifier, const MacroDefinition &MD);
2558
2559 /// Cache macro expanded tokens for TokenLexers.
2560 //
2561 /// Works like a stack; a TokenLexer adds the macro expanded tokens that is
2562 /// going to lex in the cache and when it finishes the tokens are removed
2563 /// from the end of the cache.
2564 Token *cacheMacroExpandedTokens(TokenLexer *tokLexer,
2565 ArrayRef<Token> tokens);
2566
2567 void removeCachedMacroExpandedTokensOfLastLexer();
2568
2569 /// Determine whether the next preprocessor token to be
2570 /// lexed is a '('. If so, consume the token and return true, if not, this
2571 /// method should have no observable side-effect on the lexed tokens.
2572 bool isNextPPTokenLParen();
2573
2574 /// After reading "MACRO(", this method is invoked to read all of the formal
2575 /// arguments specified for the macro invocation. Returns null on error.
2576 MacroArgs *ReadMacroCallArgumentList(Token &MacroName, MacroInfo *MI,
2577 SourceLocation &MacroEnd);
2578
2579 /// If an identifier token is read that is to be expanded
2580 /// as a builtin macro, handle it and return the next token as 'Tok'.
2581 void ExpandBuiltinMacro(Token &Tok);
2582
2583 /// Read a \c _Pragma directive, slice it up, process it, then
2584 /// return the first token after the directive.
2585 /// This assumes that the \c _Pragma token has just been read into \p Tok.
2586 void Handle_Pragma(Token &Tok);
2587
2588 /// Like Handle_Pragma except the pragma text is not enclosed within
2589 /// a string literal.
2590 void HandleMicrosoft__pragma(Token &Tok);
2591
2592 /// Add a lexer to the top of the include stack and
2593 /// start lexing tokens from it instead of the current buffer.
2594 void EnterSourceFileWithLexer(Lexer *TheLexer, ConstSearchDirIterator Dir);
2595
2596 /// Set the FileID for the preprocessor predefines.
2597 void setPredefinesFileID(FileID FID) {
2598 assert(PredefinesFileID.isInvalid() && "PredefinesFileID already set!");
2599 PredefinesFileID = FID;
2600 }
2601
2602 /// Set the FileID for the PCH through header.
2603 void setPCHThroughHeaderFileID(FileID FID);
2604
2605 /// Returns true if we are lexing from a file and not a
2606 /// pragma or a macro.
2607 static bool IsFileLexer(const Lexer* L, const PreprocessorLexer* P) {
2608 return L ? !L->isPragmaLexer() : P != nullptr;
2609 }
2610
2611 static bool IsFileLexer(const IncludeStackInfo& I) {
2612 return IsFileLexer(I.TheLexer.get(), I.ThePPLexer);
2613 }
2614
2615 bool IsFileLexer() const {
2616 return IsFileLexer(CurLexer.get(), CurPPLexer);
2617 }
2618
2619 //===--------------------------------------------------------------------===//
2620 // Caching stuff.
2621 void CachingLex(Token &Result);
2622
2623 bool InCachingLexMode() const {
2624 // If the Lexer pointers are 0 and IncludeMacroStack is empty, it means
2625 // that we are past EOF, not that we are in CachingLex mode.
2626 return !CurPPLexer && !CurTokenLexer && !IncludeMacroStack.empty();
2627 }
2628
2629 void EnterCachingLexMode();
2630 void EnterCachingLexModeUnchecked();
2631
2632 void ExitCachingLexMode() {
2633 if (InCachingLexMode())
2635 }
2636
2637 const Token &PeekAhead(unsigned N);
2638 void AnnotatePreviousCachedTokens(const Token &Tok);
2639
2640 //===--------------------------------------------------------------------===//
2641 /// Handle*Directive - implement the various preprocessor directives. These
2642 /// should side-effect the current preprocessor object so that the next call
2643 /// to Lex() will return the appropriate token next.
2644 void HandleLineDirective();
2645 void HandleDigitDirective(Token &Tok);
2646 void HandleUserDiagnosticDirective(Token &Tok, bool isWarning);
2647 void HandleIdentSCCSDirective(Token &Tok);
2648 void HandleMacroPublicDirective(Token &Tok);
2649 void HandleMacroPrivateDirective();
2650
2651 /// An additional notification that can be produced by a header inclusion or
2652 /// import to tell the parser what happened.
2653 struct ImportAction {
2654 enum ActionKind {
2655 None,
2656 ModuleBegin,
2657 ModuleImport,
2658 HeaderUnitImport,
2659 SkippedModuleImport,
2660 Failure,
2661 } Kind;
2662 Module *ModuleForHeader = nullptr;
2663
2664 ImportAction(ActionKind AK, Module *Mod = nullptr)
2665 : Kind(AK), ModuleForHeader(Mod) {
2666 assert((AK == None || Mod || AK == Failure) &&
2667 "no module for module action");
2668 }
2669 };
2670
2671 OptionalFileEntryRef LookupHeaderIncludeOrImport(
2672 ConstSearchDirIterator *CurDir, StringRef &Filename,
2673 SourceLocation FilenameLoc, CharSourceRange FilenameRange,
2674 const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl,
2675 bool &IsMapped, ConstSearchDirIterator LookupFrom,
2676 const FileEntry *LookupFromFile, StringRef &LookupFilename,
2677 SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath,
2678 ModuleMap::KnownHeader &SuggestedModule, bool isAngled);
2679
2680 // File inclusion.
2681 void HandleIncludeDirective(SourceLocation HashLoc, Token &Tok,
2682 ConstSearchDirIterator LookupFrom = nullptr,
2683 const FileEntry *LookupFromFile = nullptr);
2684 ImportAction
2685 HandleHeaderIncludeOrImport(SourceLocation HashLoc, Token &IncludeTok,
2686 Token &FilenameTok, SourceLocation EndLoc,
2687 ConstSearchDirIterator LookupFrom = nullptr,
2688 const FileEntry *LookupFromFile = nullptr);
2689 void HandleIncludeNextDirective(SourceLocation HashLoc, Token &Tok);
2690 void HandleIncludeMacrosDirective(SourceLocation HashLoc, Token &Tok);
2691 void HandleImportDirective(SourceLocation HashLoc, Token &Tok);
2692 void HandleMicrosoftImportDirective(Token &Tok);
2693
2694public:
2695 /// Check that the given module is available, producing a diagnostic if not.
2696 /// \return \c true if the check failed (because the module is not available).
2697 /// \c false if the module appears to be usable.
2698 static bool checkModuleIsAvailable(const LangOptions &LangOpts,
2699 const TargetInfo &TargetInfo,
2700 DiagnosticsEngine &Diags, Module *M);
2701
2702 // Module inclusion testing.
2703 /// Find the module that owns the source or header file that
2704 /// \p Loc points to. If the location is in a file that was included
2705 /// into a module, or is outside any module, returns nullptr.
2706 Module *getModuleForLocation(SourceLocation Loc, bool AllowTextual);
2707
2708 /// We want to produce a diagnostic at location IncLoc concerning an
2709 /// unreachable effect at location MLoc (eg, where a desired entity was
2710 /// declared or defined). Determine whether the right way to make MLoc
2711 /// reachable is by #include, and if so, what header should be included.
2712 ///
2713 /// This is not necessarily fast, and might load unexpected module maps, so
2714 /// should only be called by code that intends to produce an error.
2715 ///
2716 /// \param IncLoc The location at which the missing effect was detected.
2717 /// \param MLoc A location within an unimported module at which the desired
2718 /// effect occurred.
2719 /// \return A file that can be #included to provide the desired effect. Null
2720 /// if no such file could be determined or if a #include is not
2721 /// appropriate (eg, if a module should be imported instead).
2723 SourceLocation MLoc);
2724
2725 bool isRecordingPreamble() const {
2726 return PreambleConditionalStack.isRecording();
2727 }
2728
2729 bool hasRecordedPreamble() const {
2730 return PreambleConditionalStack.hasRecordedPreamble();
2731 }
2732
2734 return PreambleConditionalStack.getStack();
2735 }
2736
2738 PreambleConditionalStack.setStack(s);
2739 }
2740
2742 ArrayRef<PPConditionalInfo> s, std::optional<PreambleSkipInfo> SkipInfo) {
2743 PreambleConditionalStack.startReplaying();
2744 PreambleConditionalStack.setStack(s);
2745 PreambleConditionalStack.SkipInfo = SkipInfo;
2746 }
2747
2748 std::optional<PreambleSkipInfo> getPreambleSkipInfo() const {
2749 return PreambleConditionalStack.SkipInfo;
2750 }
2751
2752private:
2753 /// After processing predefined file, initialize the conditional stack from
2754 /// the preamble.
2755 void replayPreambleConditionalStack();
2756
2757 // Macro handling.
2758 void HandleDefineDirective(Token &Tok, bool ImmediatelyAfterHeaderGuard);
2759 void HandleUndefDirective();
2760
2761 // Conditional Inclusion.
2762 void HandleIfdefDirective(Token &Result, const Token &HashToken,
2763 bool isIfndef, bool ReadAnyTokensBeforeDirective);
2764 void HandleIfDirective(Token &IfToken, const Token &HashToken,
2765 bool ReadAnyTokensBeforeDirective);
2766 void HandleEndifDirective(Token &EndifToken);
2767 void HandleElseDirective(Token &Result, const Token &HashToken);
2768 void HandleElifFamilyDirective(Token &ElifToken, const Token &HashToken,
2769 tok::PPKeywordKind Kind);
2770
2771 // Pragmas.
2772 void HandlePragmaDirective(PragmaIntroducer Introducer);
2773
2774public:
2775 void HandlePragmaOnce(Token &OnceTok);
2776 void HandlePragmaMark(Token &MarkTok);
2777 void HandlePragmaPoison();
2778 void HandlePragmaSystemHeader(Token &SysHeaderTok);
2779 void HandlePragmaDependency(Token &DependencyTok);
2780 void HandlePragmaPushMacro(Token &Tok);
2781 void HandlePragmaPopMacro(Token &Tok);
2783 void HandlePragmaModuleBuild(Token &Tok);
2784 void HandlePragmaHdrstop(Token &Tok);
2786
2787 // Return true and store the first token only if any CommentHandler
2788 // has inserted some tokens and getCommentRetentionState() is false.
2789 bool HandleComment(Token &result, SourceRange Comment);
2790
2791 /// A macro is used, update information about macros that need unused
2792 /// warnings.
2793 void markMacroAsUsed(MacroInfo *MI);
2794
2795 void addMacroDeprecationMsg(const IdentifierInfo *II, std::string Msg,
2796 SourceLocation AnnotationLoc) {
2797 auto Annotations = AnnotationInfos.find(II);
2798 if (Annotations == AnnotationInfos.end())
2799 AnnotationInfos.insert(std::make_pair(
2800 II,
2801 MacroAnnotations::makeDeprecation(AnnotationLoc, std::move(Msg))));
2802 else
2803 Annotations->second.DeprecationInfo =
2804 MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
2805 }
2806
2807 void addRestrictExpansionMsg(const IdentifierInfo *II, std::string Msg,
2808 SourceLocation AnnotationLoc) {
2809 auto Annotations = AnnotationInfos.find(II);
2810 if (Annotations == AnnotationInfos.end())
2811 AnnotationInfos.insert(
2812 std::make_pair(II, MacroAnnotations::makeRestrictExpansion(
2813 AnnotationLoc, std::move(Msg))));
2814 else
2815 Annotations->second.RestrictExpansionInfo =
2816 MacroAnnotationInfo{AnnotationLoc, std::move(Msg)};
2817 }
2818
2819 void addFinalLoc(const IdentifierInfo *II, SourceLocation AnnotationLoc) {
2820 auto Annotations = AnnotationInfos.find(II);
2821 if (Annotations == AnnotationInfos.end())
2822 AnnotationInfos.insert(
2823 std::make_pair(II, MacroAnnotations::makeFinal(AnnotationLoc)));
2824 else
2825 Annotations->second.FinalAnnotationLoc = AnnotationLoc;
2826 }
2827
2828 const MacroAnnotations &getMacroAnnotations(const IdentifierInfo *II) const {
2829 return AnnotationInfos.find(II)->second;
2830 }
2831
2833 if (Identifier.getIdentifierInfo()->isDeprecatedMacro())
2834 emitMacroDeprecationWarning(Identifier);
2835
2836 if (Identifier.getIdentifierInfo()->isRestrictExpansion() &&
2837 !SourceMgr.isInMainFile(Identifier.getLocation()))
2838 emitRestrictExpansionWarning(Identifier);
2839 }
2840
2842 const LangOptions &LangOpts,
2843 const TargetInfo &TI);
2844
2845 static void processPathToFileName(SmallVectorImpl<char> &FileName,
2846 const PresumedLoc &PLoc,
2847 const LangOptions &LangOpts,
2848 const TargetInfo &TI);
2849
2850private:
2851 void emitMacroDeprecationWarning(const Token &Identifier) const;
2852 void emitRestrictExpansionWarning(const Token &Identifier) const;
2853 void emitFinalMacroWarning(const Token &Identifier, bool IsUndef) const;
2854
2855 /// This boolean state keeps track if the current scanned token (by this PP)
2856 /// is in an "-Wunsafe-buffer-usage" opt-out region. Assuming PP scans a
2857 /// translation unit in a linear order.
2858 bool InSafeBufferOptOutRegion = false;
2859
2860 /// Hold the start location of the current "-Wunsafe-buffer-usage" opt-out
2861 /// region if PP is currently in such a region. Hold undefined value
2862 /// otherwise.
2863 SourceLocation CurrentSafeBufferOptOutStart; // It is used to report the start location of an never-closed region.
2864
2865 // An ordered sequence of "-Wunsafe-buffer-usage" opt-out regions in one
2866 // translation unit. Each region is represented by a pair of start and end
2867 // locations. A region is "open" if its' start and end locations are
2868 // identical.
2870
2871public:
2872 /// \return true iff the given `Loc` is in a "-Wunsafe-buffer-usage" opt-out
2873 /// region. This `Loc` must be a source location that has been pre-processed.
2874 bool isSafeBufferOptOut(const SourceManager&SourceMgr, const SourceLocation &Loc) const;
2875
2876 /// Alter the state of whether this PP currently is in a
2877 /// "-Wunsafe-buffer-usage" opt-out region.
2878 ///
2879 /// \param isEnter: true if this PP is entering a region; otherwise, this PP
2880 /// is exiting a region
2881 /// \param Loc: the location of the entry or exit of a
2882 /// region
2883 /// \return true iff it is INVALID to enter or exit a region, i.e.,
2884 /// attempt to enter a region before exiting a previous region, or exiting a
2885 /// region that PP is not currently in.
2886 bool enterOrExitSafeBufferOptOutRegion(bool isEnter,
2887 const SourceLocation &Loc);
2888
2889 /// \return true iff this PP is currently in a "-Wunsafe-buffer-usage"
2890 /// opt-out region
2892
2893 /// \param StartLoc: output argument. It will be set to the start location of
2894 /// the current "-Wunsafe-buffer-usage" opt-out region iff this function
2895 /// returns true.
2896 /// \return true iff this PP is currently in a "-Wunsafe-buffer-usage"
2897 /// opt-out region
2899};
2900
2901/// Abstract base class that describes a handler that will receive
2902/// source ranges for each of the comments encountered in the source file.
2904public:
2906
2907 // The handler shall return true if it has pushed any tokens
2908 // to be read using e.g. EnterToken or EnterTokenStream.
2909 virtual bool HandleComment(Preprocessor &PP, SourceRange Comment) = 0;
2910};
2911
2912/// Abstract base class that describes a handler that will receive
2913/// source ranges for empty lines encountered in the source file.
2915public:
2917
2918 // The handler handles empty lines.
2919 virtual void HandleEmptyline(SourceRange Range) = 0;
2920};
2921
2922/// Registry of pragma handlers added by plugins
2923using PragmaHandlerRegistry = llvm::Registry<PragmaHandler>;
2924
2925} // namespace clang
2926
2927#endif // LLVM_CLANG_LEX_PREPROCESSOR_H
#define V(N, I)
Definition: ASTContext.h:3233
int Id
Definition: ASTDiff.cpp:190
StringRef P
#define SM(sm)
Definition: Cuda.cpp:80
Defines the Diagnostic-related interfaces.
static constexpr Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:32
Defines the Diagnostic IDs-related interfaces.
StringRef Filename
Definition: Format.cpp:2936
StringRef Identifier
Definition: Format.cpp:2944
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
Defines the clang::MacroInfo and clang::MacroDirective classes.
Defines the clang::Module class, which describes a module in the source code.
Defines the PPCallbacks interface.
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines the clang::TokenKind enum and support functions.
__device__ __2f16 float __ockl_bool s
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:369
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
Definition: Builtins.h:85
Callback handler that receives notifications when performing code completion within the preprocessor.
Abstract base class that describes a handler that will receive source ranges for each of the comments...
virtual bool HandleComment(Preprocessor &PP, SourceRange Comment)=0
A directive for a defined macro or a macro imported from a module.
Definition: MacroInfo.h:429
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1266
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1542
void setSuppressAllDiagnostics(bool Val)
Suppress all diagnostics, to silence the front end when we know that we don't want any more diagnosti...
Definition: Diagnostic.h:692
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
Abstract base class that describes a handler that will receive source ranges for empty lines encounte...
virtual void HandleEmptyline(SourceRange Range)=0
Abstract interface for external sources of preprocessor information.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition: FileEntry.h:57
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:397
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
Definition: HeaderSearch.h:223
HeaderFileInfo & getFileInfo(FileEntryRef FE)
Return the HeaderFileInfo structure for the specified FileEntry, in preparation for updating it in so...
One of these records is kept for each identifier that is lexed.
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
Implements an efficient mapping from strings to IdentifierInfo nodes.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:83
FPEvalMethodKind
Possible float expression evaluation method choices.
Definition: LangOptions.h:292
@ FEM_UnsetOnCommandLine
Used only for FE option processing; this is only used to indicate that the user did not specify an ex...
Definition: LangOptions.h:306
static StringRef getImmediateMacroName(SourceLocation Loc, const SourceManager &SM, const LangOptions &LangOpts)
Retrieve the name of the immediate macro expansion.
Definition: Lexer.cpp:1012
static bool isAtStartOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroBegin=nullptr)
Returns true if the given MacroID location points at the first token of the macro expansion.
Definition: Lexer.cpp:824
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
Definition: Lexer.h:399
static bool isAtEndOfMacroExpansion(SourceLocation loc, const SourceManager &SM, const LangOptions &LangOpts, SourceLocation *MacroEnd=nullptr)
Returns true if the given MacroID location points at the last token of the macro expansion.
Definition: Lexer.cpp:846
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer,...
Definition: Lexer.cpp:403
static bool getRawToken(SourceLocation Loc, Token &Result, const SourceManager &SM, const LangOptions &LangOpts, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
Definition: Lexer.cpp:461
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Definition: Lexer.cpp:802
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:30
A description of the current definition of a macro.
Definition: MacroInfo.h:587
const DefMacroDirective * getDirective() const
Definition: MacroInfo.h:372
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
Definition: MacroInfo.h:125
Abstract interface for a module loader.
Definition: ModuleLoader.h:82
Represents a macro directive exported by a module.
Definition: MacroInfo.h:511
A header that is known to reside within a given module, whether it was included or excluded.
Definition: ModuleMap.h:159
Describes a module or submodule.
Definition: Module.h:104
bool isModuleMapModule() const
Definition: Module.h:209
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:35
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
Definition: Pragma.h:65
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:128
SourceLocation getLastFPEvalPragmaLocation() const
bool isMacroDefined(const IdentifierInfo *II)
MacroDirective * getLocalMacroDirective(const IdentifierInfo *II) const
Given an identifier, return its latest non-imported MacroDirective if it is #define'd and not #undef'...
bool markIncluded(FileEntryRef File)
Mark the file as included.
void HandlePragmaPushMacro(Token &Tok)
Handle #pragma push_macro.
Definition: Pragma.cpp:627
void FinalizeForModelFile()
Cleanup after model file parsing.
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...
void HandlePragmaPoison()
HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'.
Definition: Pragma.cpp:442
void setCodeCompletionHandler(CodeCompletionHandler &Handler)
Set the code completion handler to the given object.
void dumpMacroInfo(const IdentifierInfo *II)
std::pair< IdentifierInfo *, SourceLocation > getPragmaARCCFCodeAuditedInfo() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
void HandlePragmaSystemHeader(Token &SysHeaderTok)
HandlePragmaSystemHeader - Implement #pragma GCC system_header.
Definition: Pragma.cpp:484
bool creatingPCHWithThroughHeader()
True if creating a PCH with a through header.
void DumpToken(const Token &Tok, bool DumpFlags=false) const
Print the token to stderr, used for debugging.
void MaybeHandlePoisonedIdentifier(Token &Identifier)
ModuleMacro * addModuleMacro(Module *Mod, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides, bool &IsNew)
Register an exported macro for a module and identifier.
void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD)
Set a MacroDirective that was loaded from a PCH file.
MacroDefinition getMacroDefinitionAtLoc(const IdentifierInfo *II, SourceLocation Loc)
void markClangModuleAsAffecting(Module *M)
Mark the given clang module as affecting the current clang module or translation unit.
void setPragmaARCCFCodeAuditedInfo(IdentifierInfo *Ident, SourceLocation Loc)
Set the location of the currently-active #pragma clang arc_cf_code_audited begin.
void HandlePragmaModuleBuild(Token &Tok)
Definition: Pragma.cpp:807
void InitializeForModelFile()
Initialize the preprocessor to parse a model file.
SourceLocation getCodeCompletionLoc() const
Returns the location of the code-completion point.
ArrayRef< ModuleMacro * > getLeafModuleMacros(const IdentifierInfo *II) const
Get the list of leaf (non-overridden) module macros for a name.
void CollectPpImportSuffix(SmallVectorImpl< Token > &Toks)
Collect the tokens of a C++20 pp-import-suffix.
bool isIncrementalProcessingEnabled() const
Returns true if incremental processing is enabled.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
void IgnorePragmas()
Install empty handlers for all pragmas (making them ignored).
Definition: Pragma.cpp:2195
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI)
PPCallbacks * getPPCallbacks() const
bool isInNamedInterfaceUnit() const
If we are proprocessing a named interface unit.
ArrayRef< PPConditionalInfo > getPreambleConditionalStack() const
void setPreambleRecordedPragmaAssumeNonNullLoc(SourceLocation Loc)
Record the location of the unterminated #pragma clang assume_nonnull begin in the preamble.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
ArrayRef< BuildingSubmoduleInfo > getBuildingSubmodules() const
Get the list of submodules that we're currently building.
SourceLocation getCodeCompletionFileLoc() const
Returns the start location of the file of code-completion point.
DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) const
SourceRange getCodeCompletionTokenRange() const
SourceLocation getModuleImportLoc(Module *M) const
void overrideMaxTokens(unsigned Value, SourceLocation Loc)
void setCodeCompletionTokenRange(const SourceLocation Start, const SourceLocation End)
Set the code completion token range for detecting replacement range later on.
bool isRecordingPreamble() const
void HandleSkippedDirectiveWhileUsingPCH(Token &Result, SourceLocation HashLoc)
Process directives while skipping until the through header or #pragma hdrstop is found.
void setRecordedPreambleConditionalStack(ArrayRef< PPConditionalInfo > s)
void enableIncrementalProcessing(bool value=true)
Enables the incremental processing.
bool LexAfterModuleImport(Token &Result)
Lex a token following the 'import' contextual keyword.
void TypoCorrectToken(const Token &Tok)
Update the current token to represent the provided identifier, in order to cache an action performed ...
bool GetSuppressIncludeNotFoundError()
bool isMacroDefinedInLocalModule(const IdentifierInfo *II, Module *M)
Determine whether II is defined as a macro within the module M, if that is a module that we've alread...
void setPragmaAssumeNonNullLoc(SourceLocation Loc)
Set the location of the currently-active #pragma clang assume_nonnull begin.
bool isInPrimaryFile() const
Return true if we're in the top-level file, not in a #include.
macro_iterator macro_begin(bool IncludeExternalMacros=true) const
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 ...
void markMacroAsUsed(MacroInfo *MI)
A macro is used, update information about macros that need unused warnings.
LangOptions::FPEvalMethodKind getCurrentFPEvalMethod() const
void EnterSubmodule(Module *M, SourceLocation ImportLoc, bool ForPragma)
bool isSafeBufferOptOut(const SourceManager &SourceMgr, const SourceLocation &Loc) const
void addMacroDeprecationMsg(const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
void addRestrictExpansionMsg(const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
Given a tok::raw_identifier token, look up the identifier information for the token and install it in...
MacroDirective * getLocalMacroDirectiveHistory(const IdentifierInfo *II) const
Given an identifier, return the latest non-imported macro directive for that identifier.
void setPreprocessedOutput(bool IsPreprocessedOutput)
Sets whether the preprocessor is responsible for producing output or if it is producing tokens to be ...
void addFinalLoc(const IdentifierInfo *II, SourceLocation AnnotationLoc)
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
Definition: PPCaching.cpp:139
bool SawDateOrTime() const
Returns true if the preprocessor has seen a use of DATE or TIME in the file so far.
const TargetInfo * getAuxTargetInfo() const
void CommitBacktrackedTokens()
Disable the last EnableBacktrackAtThisPos call.
Definition: PPCaching.cpp:32
friend class MacroArgs
Definition: Preprocessor.h:683
void DumpMacro(const MacroInfo &MI) const
bool HandleEndOfTokenLexer(Token &Result)
Callback invoked when the current TokenLexer hits the end of its token stream.
void setDiagnostics(DiagnosticsEngine &D)
IncludedFilesSet & getIncludedFiles()
Get the set of included files.
friend void TokenLexer::ExpandFunctionArguments()
void setCodeCompletionReached()
Note that we hit the code-completion point.
bool SetCodeCompletionPoint(FileEntryRef File, unsigned Line, unsigned Column)
Specify the point at which code-completion will be performed.
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
bool isPreprocessedOutput() const
Returns true if the preprocessor is responsible for generating output, false if it is producing token...
StringRef getNamedModuleName() const
Get the named module name we're preprocessing.
void makeModuleVisible(Module *M, SourceLocation Loc)
unsigned getCounterValue() const
bool mightHavePendingAnnotationTokens()
Determine whether it's possible for a future call to Lex to produce an annotation token created by a ...
bool isInImportingCXXNamedModules() const
If we're importing a standard C++20 Named Modules.
void Lex(Token &Result)
Lex the next token for this preprocessor.
void EnterTokenStream(ArrayRef< Token > Toks, bool DisableMacroExpansion, bool IsReinject)
const TranslationUnitKind TUKind
The kind of translation unit we are processing.
Definition: Preprocessor.h:285
bool EnterSourceFile(FileID FID, ConstSearchDirIterator Dir, SourceLocation Loc, bool IsFirstIncludeOfFile=true)
Add a source file to the top of the include stack and start lexing tokens from it instead of the curr...
bool isParsingIfOrElifDirective() const
True if we are currently preprocessing a if or #elif directive.
unsigned getNumDirectives() const
Retrieve the number of Directives that have been processed by the Preprocessor.
bool isInImplementationUnit() const
If we are implementing an implementation module unit.
void addCommentHandler(CommentHandler *Handler)
Add the specified comment handler to the preprocessor.
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with this preprocessor.
void LexNonComment(Token &Result)
Lex a token.
void removeCommentHandler(CommentHandler *Handler)
Remove the specified comment handler.
PreprocessorLexer * getCurrentLexer() const
Return the current lexer being lexed from.
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:968
StringRef getCodeCompletionFilter()
Get the code completion token for filtering purposes.
void setMainFileDir(DirectoryEntryRef Dir)
Set the directory in which the main file should be considered to have been found, if it is not a real...
const IdentifierTable & getIdentifierTable() const
void HandlePragmaDependency(Token &DependencyTok)
HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
Definition: Pragma.cpp:516
SourceLocation CheckEndOfDirective(const char *DirType, bool EnableMacros=false)
Ensure that the next token is a tok::eod token.
void HandlePoisonedIdentifier(Token &Identifier)
Display reason for poisoned identifier.
void Backtrack()
Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously c...
Definition: PPCaching.cpp:40
bool isCurrentLexer(const PreprocessorLexer *L) const
Return true if we are lexing directly from the specified lexer.
bool HandleIdentifier(Token &Identifier)
Callback invoked when the lexer reads an identifier and has filled in the tokens IdentifierInfo membe...
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
bool enterOrExitSafeBufferOptOutRegion(bool isEnter, const SourceLocation &Loc)
Alter the state of whether this PP currently is in a "-Wunsafe-buffer-usage" opt-out region.
void IncrementPasteCounter(bool isFast)
Increment the counters for the number of token paste operations performed.
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
void setReplayablePreambleConditionalStack(ArrayRef< PPConditionalInfo > s, std::optional< PreambleSkipInfo > SkipInfo)
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
const MacroAnnotations & getMacroAnnotations(const IdentifierInfo *II) const
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
macro_iterator macro_end(bool IncludeExternalMacros=true) const
SourceManager & getSourceManager() const
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
bool CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef, bool *ShadowFlag=nullptr)
std::optional< PreambleSkipInfo > getPreambleSkipInfo() const
void setPreprocessToken(bool Preprocess)
void SetPoisonReason(IdentifierInfo *II, unsigned DiagID)
Specifies the reason for poisoning an identifier.
void HandlePragmaOnce(Token &OnceTok)
HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.
Definition: Pragma.cpp:417
EmptylineHandler * getEmptylineHandler() const
bool getCommentRetentionState() const
bool isMacroDefined(StringRef Id)
Module * getCurrentModuleImplementation()
Retrieves the module whose implementation we're current compiling, if any.
void SetMacroExpansionOnlyInDirectives()
Disables macro expansion everywhere except for preprocessor directives.
bool hasRecordedPreamble() const
SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Char) const
Given a location that specifies the start of a token, return a new location that specifies a characte...
SourceLocation getPragmaAssumeNonNullLoc() const
The location of the currently-active #pragma clang assume_nonnull begin.
MacroMap::const_iterator macro_iterator
void createPreprocessingRecord()
Create a new preprocessing record, which will keep track of all macro expansions, macro definitions,...
SourceLocation SplitToken(SourceLocation TokLoc, unsigned Length)
Split the first Length characters out of the token starting at TokLoc and return a location pointing ...
void EnterTokenStream(std::unique_ptr< Token[]> Toks, unsigned NumToks, bool DisableMacroExpansion, bool IsReinject)
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
Module * getCurrentModule()
Retrieves the module that we're currently building, if any.
void RemovePragmaHandler(PragmaHandler *Handler)
bool isPPInSafeBufferOptOutRegion()
unsigned getTokenCount() const
Get the number of tokens processed so far.
unsigned getMaxTokens() const
Get the max number of tokens before issuing a -Wmax-tokens warning.
SourceLocation getMaxTokensOverrideLoc() const
void emitMacroExpansionWarnings(const Token &Identifier) const
bool hadModuleLoaderFatalFailure() const
static void processPathToFileName(SmallVectorImpl< char > &FileName, const PresumedLoc &PLoc, const LangOptions &LangOpts, const TargetInfo &TI)
void setCurrentFPEvalMethod(SourceLocation PragmaLoc, LangOptions::FPEvalMethodKind Val)
const TargetInfo & getTargetInfo() const
FileManager & getFileManager() const
bool LexHeaderName(Token &Result, bool AllowMacroExpansion=true)
Lex a token, forming a header-name token if possible.
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
std::string getSpelling(const Token &Tok, bool *Invalid=nullptr) const
Return the 'spelling' of the Tok token.
bool isPCHThroughHeader(const FileEntry *FE)
Returns true if the FileEntry is the PCH through header.
void DumpLocation(SourceLocation Loc) const
Module * getCurrentLexerSubmodule() const
Return the submodule owning the file being lexed.
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
MacroInfo * AllocateMacroInfo(SourceLocation L)
Allocate a new MacroInfo object with the provided SourceLocation.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
StringRef getImmediateMacroName(SourceLocation Loc)
Retrieve the name of the immediate macro expansion.
bool creatingPCHWithPragmaHdrStop()
True if creating a PCH with a #pragma hdrstop.
bool alreadyIncluded(FileEntryRef File) const
Return true if this header has already been included.
llvm::iterator_range< macro_iterator > macros(bool IncludeExternalMacros=true) const
void Initialize(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize the preprocessor using information about the target.
FileID getPredefinesFileID() const
Returns the FileID for the preprocessor predefines.
void LexUnexpandedNonComment(Token &Result)
Like LexNonComment, but this disables macro expansion of identifier tokens.
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.
char getSpellingOfSingleCharacterNumericConstant(const Token &Tok, bool *Invalid=nullptr) const
Given a Token Tok that is a numeric constant with length 1, return the character.
void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Add the specified pragma handler to this preprocessor.
Definition: Pragma.cpp:915
llvm::BumpPtrAllocator & getPreprocessorAllocator()
ModuleMacro * getModuleMacro(Module *Mod, const IdentifierInfo *II)
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 ...
bool HandleComment(Token &result, SourceRange Comment)
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
bool GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Buffer)
Turn the specified lexer token into a fully checked and spelled filename, e.g.
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
HeaderSearch & getHeaderSearchInfo() const
void HandlePragmaPopMacro(Token &Tok)
Handle #pragma pop_macro.
Definition: Pragma.cpp:650
void ReplaceLastTokenWithAnnotation(const Token &Tok)
Replace the last token with an annotation token.
ExternalPreprocessorSource * getExternalSource() const
Module * LeaveSubmodule(bool ForPragma)
SourceRange DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found.
const std::string & getPredefines() const
Get the predefines for this processor.
void HandleDirective(Token &Result)
Callback invoked when the lexer sees a # token at the start of a line.
CodeCompletionHandler * getCodeCompletionHandler() const
Retrieve the current code-completion handler.
void recomputeCurLexerKind()
Recompute the current lexer kind based on the CurLexer/ CurTokenLexer pointers.
void EnterAnnotationToken(SourceRange Range, tok::TokenKind Kind, void *AnnotationVal)
Enter an annotation token into the token stream.
void setTokenWatcher(llvm::unique_function< void(const clang::Token &)> F)
Register a function that would be called on each token in the final expanded token stream.
Preprocessor(std::shared_ptr< PreprocessorOptions > PPOpts, DiagnosticsEngine &diags, const LangOptions &LangOpts, SourceManager &SM, HeaderSearch &Headers, ModuleLoader &TheModuleLoader, IdentifierInfoLookup *IILookup=nullptr, bool OwnsHeaderSearch=false, TranslationUnitKind TUKind=TU_Complete)
MacroInfo * getMacroInfo(const IdentifierInfo *II)
void setPredefines(std::string P)
Set the predefines for this Preprocessor.
OptionalFileEntryRef LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false, bool OpenFile=true, bool CacheFailures=true)
Given a "foo" or <foo> reference, look up the indicated file.
IdentifierTable & getIdentifierTable()
Builtin::Context & getBuiltinInfo()
void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine)
Instruct the preprocessor to skip part of the main source file.
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
Definition: PPCaching.cpp:157
LangOptions::FPEvalMethodKind getTUFPEvalMethod() const
const LangOptions & getLangOpts() const
void setTUFPEvalMethod(LangOptions::FPEvalMethodKind Val)
void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled)
Hook used by the lexer to invoke the "included file" code completion point.
void SetSuppressIncludeNotFoundError(bool Suppress)
static void processPathForFileMacro(SmallVectorImpl< char > &Path, const LangOptions &LangOpts, const TargetInfo &TI)
bool isInNamedModule() const
If we are preprocessing a named module.
void RemoveTopOfLexerStack()
Pop the current lexer/macro exp off the top of the lexer stack.
void PoisonSEHIdentifiers(bool Poison=true)
bool isAtStartOfMacroExpansion(SourceLocation loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the first token of the macro expansion.
size_t getTotalMemory() const
void setExternalSource(ExternalPreprocessorSource *Source)
void clearCodeCompletionHandler()
Clear out the code completion handler.
void AddPragmaHandler(PragmaHandler *Handler)
OptionalFileEntryRef getHeaderToIncludeForDiagnostics(SourceLocation IncLoc, SourceLocation MLoc)
We want to produce a diagnostic at location IncLoc concerning an unreachable effect at location MLoc ...
void setCounterValue(unsigned V)
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
IdentifierInfo * ParsePragmaPushOrPopMacro(Token &Tok)
ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
Definition: Pragma.cpp:572
bool getRawToken(SourceLocation Loc, Token &Result, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
bool usingPCHWithPragmaHdrStop()
True if using a PCH with a #pragma hdrstop.
void CodeCompleteNaturalLanguage()
Hook used by the lexer to invoke the "natural language" code completion point.
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
bool HandleEndOfFile(Token &Result, bool isEndOfMacro=false)
Callback invoked when the lexer hits the end of the current file.
void setPragmasEnabled(bool Enabled)
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments)
Control whether the preprocessor retains comments in output.
bool isAtEndOfMacroExpansion(SourceLocation loc, SourceLocation *MacroEnd=nullptr) const
Returns true if the given MacroID location points at the last token of the macro expansion.
void HandlePragmaMark(Token &MarkTok)
Definition: Pragma.cpp:432
bool getPragmasEnabled() const
void HandlePragmaHdrstop(Token &Tok)
Definition: Pragma.cpp:881
PreprocessingRecord * getPreprocessingRecord() const
Retrieve the preprocessing record, or NULL if there is no preprocessing record.
void setEmptylineHandler(EmptylineHandler *Handler)
Set empty line handler.
DiagnosticsEngine & getDiagnostics() const
SourceLocation getLastCachedTokenLocation() const
Get the location of the last cached token, suitable for setting the end location of an annotation tok...
llvm::DenseSet< const FileEntry * > IncludedFilesSet
Definition: Preprocessor.h:679
unsigned getSpelling(const Token &Tok, const char *&Buffer, bool *Invalid=nullptr) const
Get the spelling of a token into a preallocated buffer, instead of as an std::string.
SelectorTable & getSelectorTable()
void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Remove the specific pragma handler from this preprocessor.
Definition: Pragma.cpp:946
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
const llvm::SmallSetVector< Module *, 2 > & getAffectingClangModules() const
Get the set of top-level clang modules that affected preprocessing, but were not imported.
const IncludedFilesSet & getIncludedFiles() const
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
void HandlePragmaIncludeAlias(Token &Tok)
Definition: Pragma.cpp:685
Module * getModuleForLocation(SourceLocation Loc, bool AllowTextual)
Find the module that owns the source or header file that Loc points to.
void setCodeCompletionIdentifierInfo(IdentifierInfo *Filter)
Set the code completion token for filtering purposes.
SourceLocation getPreambleRecordedPragmaAssumeNonNullLoc() const
Get the location of the recorded unterminated #pragma clang assume_nonnull begin in the preamble,...
void EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro, MacroArgs *Args)
Add a Macro to the top of the include stack and start lexing tokens from it instead of the current bu...
void EnableBacktrackAtThisPos()
From the point that this method is called, and until CommitBacktrackedTokens() or Backtrack() is call...
Definition: PPCaching.cpp:25
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
void SkipTokensWhileUsingPCH()
Skip tokens until after the #include of the through header or until after a #pragma hdrstop.
bool usingPCHWithThroughHeader()
True if using a PCH with a through header.
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...
void HandleMicrosoftCommentPaste(Token &Tok)
When the macro expander pastes together a comment (/##/) in Microsoft mode, this method handles updat...
void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD)
Add a directive to the macro directive history for this identifier.
Represents an unpacked "presumed" location which can be presented to the user.
This table allows us to fully hide how we implement multi-keyword caching.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Exposes information about the current target.
Definition: TargetInfo.h:207
Stores token information for comparing actual tokens with predefined values.
Definition: Preprocessor.h:89
TokenValue(IdentifierInfo *II)
Definition: Preprocessor.h:102
TokenValue(tok::TokenKind Kind)
Definition: Preprocessor.h:94
bool operator==(const Token &Tok) const
Definition: Preprocessor.h:104
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:186
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:131
unsigned getLength() const
Definition: Token.h:134
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:98
tok::TokenKind getKind() const
Definition: Token.h:93
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
Definition: Token.h:120
bool needsCleaning() const
Return true if this token has trigraphs or escaped newlines in it.
Definition: Token.h:292
const char * getLiteralData() const
getLiteralData - For a literal token (numeric constant, string, etc), this returns a pointer to the s...
Definition: Token.h:224
A class for tracking whether we're inside a VA_OPT during a traversal of the tokens of a variadic mac...
An RAII class that tracks when the Preprocessor starts and stops lexing the definition of a (ISO C/C+...
Directive - Abstract class representing a parsed verify directive.
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
Definition: TokenKinds.h:56
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
Definition: TokenKinds.h:97
PPKeywordKind
Provides a namespace for preprocessor keywords which start with a '#' at the beginning of the line.
Definition: TokenKinds.h:33
bool isAnnotation(TokenKind K)
Return true if this is any of tok::annot_* kinds.
Definition: TokenKinds.cpp:58
CustomizableOptional< DirectoryEntryRef > OptionalDirectoryEntryRef
detail::SearchDirIteratorImpl< true > ConstSearchDirIterator
Definition: HeaderSearch.h:215
MacroUse
Context in which macro name is used.
Definition: Preprocessor.h:111
@ MU_Undef
Definition: Preprocessor.h:119
@ MU_Other
Definition: Preprocessor.h:113
@ MU_Define
Definition: Preprocessor.h:116
llvm::Registry< PragmaHandler > PragmaHandlerRegistry
Registry of pragma handlers added by plugins.
@ C
Languages that the frontend can parse and compile.
@ Result
The result type of a method or function.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
Definition: FileEntry.h:202
TranslationUnitKind
Describes the kind of translation unit being processed.
Definition: LangOptions.h:932
@ TU_Complete
The translation unit is a complete translation unit.
Definition: LangOptions.h:934
YAML serialization mapping.
Definition: Dominators.h:30
Definition: Format.h:5078
#define bool
Definition: stdbool.h:20
Describes how and where the pragma was introduced.
Definition: Pragma.h:51
PreambleSkipInfo(SourceLocation HashTokenLoc, SourceLocation IfTokenLoc, bool FoundNonSkipPortion, bool FoundElse, SourceLocation ElseLoc)
Definition: Preprocessor.h:671