15 #ifndef LLVM_CLANG_LEX_PREPROCESSOR_H 16 #define LLVM_CLANG_LEX_PREPROCESSOR_H 35 #include "llvm/ADT/ArrayRef.h" 36 #include "llvm/ADT/DenseMap.h" 37 #include "llvm/ADT/FoldingSet.h" 38 #include "llvm/ADT/None.h" 39 #include "llvm/ADT/Optional.h" 40 #include "llvm/ADT/PointerUnion.h" 41 #include "llvm/ADT/STLExtras.h" 42 #include "llvm/ADT/SmallPtrSet.h" 43 #include "llvm/ADT/SmallVector.h" 44 #include "llvm/ADT/StringRef.h" 45 #include "llvm/ADT/TinyPtrVector.h" 46 #include "llvm/ADT/iterator_range.h" 47 #include "llvm/Support/Allocator.h" 48 #include "llvm/Support/Casting.h" 49 #include "llvm/Support/Registry.h" 61 template<
unsigned InternalLen>
class SmallString;
67 class CodeCompletionHandler;
70 class DirectoryLookup;
71 class ExternalPreprocessorSource;
76 class MemoryBufferCache;
78 class PragmaNamespace;
79 class PreprocessingRecord;
80 class PreprocessorLexer;
81 class PreprocessorOptions;
94 assert(Kind != tok::raw_identifier &&
"Raw identifiers are not supported.");
95 assert(Kind != tok::identifier &&
96 "Identifiers should be created by TokenValue(IdentifierInfo *)");
104 return Tok.
getKind() == Kind &&
131 std::shared_ptr<PreprocessorOptions> PPOpts;
139 std::unique_ptr<ScratchBuffer> ScratchBuf;
148 std::unique_ptr<PTHManager> PTH;
152 llvm::BumpPtrAllocator BP;
186 unsigned CounterValue = 0;
190 MaxAllowedIncludeStackDepth = 200
194 bool KeepComments : 1;
195 bool KeepMacroComments : 1;
196 bool SuppressIncludeNotFoundError : 1;
199 bool InMacroArgs : 1;
202 bool OwnsHeaderSearch : 1;
205 bool DisableMacroExpansion : 1;
209 bool MacroExpansionInDirectivesOverride : 1;
214 mutable bool ReadMacrosFromExternalSource : 1;
217 bool PragmasEnabled : 1;
220 bool PreprocessedOutput : 1;
223 bool ParsingIfOrElifDirective;
226 bool InMacroArgPreExpansion;
248 std::unique_ptr<PragmaNamespace> PragmaHandlers;
252 std::unique_ptr<PragmaNamespace> PragmaHandlersBackup;
256 std::vector<CommentHandler *> CommentHandlers;
260 bool IncrementalProcessing =
false;
269 const FileEntry *CodeCompletionFile =
nullptr;
272 unsigned CodeCompletionOffset = 0;
292 bool LastTokenWasAt =
false;
296 bool ModuleImportExpectsIdentifier =
false;
307 bool CodeCompletionReached =
false;
323 std::pair<int, bool> SkipMainFilePreamble;
334 bool FoundNonSkipPortion,
bool FoundElse,
336 : HashTokenLoc(HashTokenLoc), IfTokenLoc(IfTokenLoc),
337 FoundNonSkipPortion(FoundNonSkipPortion), FoundElse(FoundElse),
345 class PreambleConditionalStackStore {
353 PreambleConditionalStackStore() =
default;
355 void startRecording() { ConditionalStackState = Recording; }
356 void startReplaying() { ConditionalStackState = Replaying; }
357 bool isRecording()
const {
return ConditionalStackState == Recording; }
358 bool isReplaying()
const {
return ConditionalStackState == Replaying; }
361 return ConditionalStack;
364 void doneReplaying() {
365 ConditionalStack.clear();
366 ConditionalStackState = Off;
370 if (!isRecording() && !isReplaying())
372 ConditionalStack.clear();
373 ConditionalStack.append(s.begin(), s.end());
376 bool hasRecordedPreamble()
const {
return !ConditionalStack.empty(); }
378 bool reachedEOFWhileSkipping()
const {
return SkipInfo.hasValue(); }
380 void clearSkipInfo() { SkipInfo.reset(); }
386 State ConditionalStackState = Off;
387 } PreambleConditionalStack;
393 std::unique_ptr<Lexer> CurLexer;
399 std::unique_ptr<PTHLexer> CurPTHLexer;
417 std::unique_ptr<TokenLexer> CurTokenLexer;
425 CLK_LexAfterModuleImport
426 } CurLexerKind = CLK_Lexer;
430 Module *CurLexerSubmodule =
nullptr;
435 struct IncludeStackInfo {
436 enum CurLexerKind CurLexerKind;
438 std::unique_ptr<Lexer> TheLexer;
439 std::unique_ptr<PTHLexer> ThePTHLexer;
441 std::unique_ptr<TokenLexer> TheTokenLexer;
446 IncludeStackInfo(
enum CurLexerKind CurLexerKind,
Module *TheSubmodule,
447 std::unique_ptr<Lexer> &&TheLexer,
448 std::unique_ptr<PTHLexer> &&ThePTHLexer,
450 std::unique_ptr<TokenLexer> &&TheTokenLexer,
452 : CurLexerKind(
std::move(CurLexerKind)),
453 TheSubmodule(
std::move(TheSubmodule)), TheLexer(
std::move(TheLexer)),
454 ThePTHLexer(
std::move(ThePTHLexer)),
455 ThePPLexer(
std::move(ThePPLexer)),
456 TheTokenLexer(
std::move(TheTokenLexer)),
457 TheDirLookup(
std::move(TheDirLookup)) {}
459 std::vector<IncludeStackInfo> IncludeMacroStack;
463 std::unique_ptr<PPCallbacks> Callbacks;
465 struct MacroExpandsInfo {
471 : Tok(Tok), MD(MD), Range(Range) {}
476 struct ModuleMacroInfo {
481 llvm::TinyPtrVector<ModuleMacro *> ActiveModuleMacros;
485 unsigned ActiveModuleMacrosGeneration = 0;
488 bool IsAmbiguous =
false;
491 llvm::TinyPtrVector<ModuleMacro *> OverriddenMacros;
498 mutable llvm::PointerUnion<MacroDirective *, ModuleMacroInfo *>
State;
503 PP.updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
509 !PP.CurSubmoduleState->VisibleModules.getGeneration())
512 auto *Info = State.dyn_cast<ModuleMacroInfo*>();
519 if (PP.CurSubmoduleState->VisibleModules.getGeneration() !=
520 Info->ActiveModuleMacrosGeneration)
521 PP.updateModuleMacroInfo(II, *Info);
526 MacroState() : MacroState(nullptr) {}
529 MacroState(MacroState &&O) noexcept :
State(O.State) {
533 MacroState &operator=(MacroState &&O) noexcept {
541 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
542 Info->~ModuleMacroInfo();
546 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
552 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
559 auto *Info = getModuleInfo(PP, II);
560 return Info ? Info->IsAmbiguous :
false;
565 if (
auto *Info = getModuleInfo(PP, II))
566 return Info->ActiveModuleMacros;
573 if (
auto *Latest = getLatest())
574 return Latest->findDirectiveAtLoc(Loc, SourceMgr);
579 if (
auto *Info = getModuleInfo(PP, II)) {
580 Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
581 Info->ActiveModuleMacros.begin(),
582 Info->ActiveModuleMacros.end());
583 Info->ActiveModuleMacros.clear();
584 Info->IsAmbiguous =
false;
589 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
590 return Info->OverriddenMacros;
596 auto *Info = State.dyn_cast<ModuleMacroInfo*>();
598 if (Overrides.empty())
604 Info->OverriddenMacros.clear();
605 Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
606 Overrides.begin(), Overrides.end());
607 Info->ActiveModuleMacrosGeneration = 0;
616 using MacroMap = llvm::DenseMap<const IdentifierInfo *, MacroState>;
618 struct SubmoduleState;
621 struct BuildingSubmoduleInfo {
632 SubmoduleState *OuterSubmoduleState;
635 unsigned OuterPendingModuleMacroNames;
638 SubmoduleState *OuterSubmoduleState,
639 unsigned OuterPendingModuleMacroNames)
640 : M(M), ImportLoc(ImportLoc), IsPragma(IsPragma),
641 OuterSubmoduleState(OuterSubmoduleState),
642 OuterPendingModuleMacroNames(OuterPendingModuleMacroNames) {}
647 struct SubmoduleState {
657 std::map<Module *, SubmoduleState> Submodules;
660 SubmoduleState NullSubmoduleState;
664 SubmoduleState *CurSubmoduleState;
667 llvm::FoldingSet<ModuleMacro> ModuleMacros;
674 llvm::DenseMap<const IdentifierInfo *, llvm::TinyPtrVector<ModuleMacro *>>
686 using WarnUnusedMacroLocsTy = llvm::SmallPtrSet<SourceLocation, 32>;
687 WarnUnusedMacroLocsTy WarnUnusedMacroLocs;
695 llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>>
699 unsigned NumDirectives = 0;
700 unsigned NumDefined = 0;
701 unsigned NumUndefined = 0;
702 unsigned NumPragma = 0;
704 unsigned NumElse = 0;
705 unsigned NumEndif = 0;
706 unsigned NumEnteredSourceFiles = 0;
707 unsigned MaxIncludeStackDepth = 0;
708 unsigned NumMacroExpanded = 0;
709 unsigned NumFnMacroExpanded = 0;
710 unsigned NumBuiltinMacroExpanded = 0;
711 unsigned NumFastMacroExpanded = 0;
712 unsigned NumTokenPaste = 0;
713 unsigned NumFastTokenPaste = 0;
714 unsigned NumSkipped = 0;
718 std::string Predefines;
724 FileID PCHThroughHeaderFileID;
727 bool SkippingUntilPCHThroughHeader =
false;
731 enum { TokenLexerCacheSize = 8 };
732 unsigned NumCachedTokenLexers;
733 std::unique_ptr<TokenLexer> TokenLexerCache[TokenLexerCacheSize];
742 std::vector<std::pair<TokenLexer *, size_t>> MacroExpandingLexersStack;
763 CachedTokensTy::size_type CachedLexPos = 0;
770 std::vector<CachedTokensTy::size_type> BacktrackPositions;
772 struct MacroInfoChain {
774 MacroInfoChain *Next;
779 MacroInfoChain *MIChainHead =
nullptr;
784 Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
789 bool OwnsHeaderSearch =
false,
809 void InitializeForModelFile();
812 void FinalizeForModelFile();
840 ExternalSource = Source;
844 return ExternalSource;
856 return ParsingIfOrElifDirective;
861 this->KeepComments = KeepComments | KeepMacroComments;
862 this->KeepMacroComments = KeepMacroComments;
871 SuppressIncludeNotFoundError = Suppress;
875 return SuppressIncludeNotFoundError;
881 PreprocessedOutput = IsPreprocessedOutput;
890 return CurPPLexer == L;
920 C = llvm::make_unique<PPChainedCallbacks>(std::move(C),
921 std::move(Callbacks));
922 Callbacks = std::move(C);
931 (!getLangOpts().Modules || (
bool)getMacroDefinition(II));
940 auto I = Submodules.find(M);
941 if (I == Submodules.end())
943 auto J = I->second.Macros.find(II);
944 if (J == I->second.Macros.end())
946 auto *MD = J->second.getLatest();
954 MacroState &S = CurSubmoduleState->Macros[II];
955 auto *MD = S.getLatest();
956 while (MD && isa<VisibilityMacroDirective>(MD))
959 S.getActiveModuleMacros(*
this, II),
960 S.isAmbiguous(*
this, II));
968 MacroState &S = CurSubmoduleState->Macros[II];
970 if (
auto *MD = S.getLatest())
974 S.getActiveModuleMacros(*
this, II),
975 S.isAmbiguous(*
this, II));
984 auto *MD = getLocalMacroDirectiveHistory(II);
992 return const_cast<Preprocessor*
>(
this)->getMacroInfo(II);
998 if (
auto MD = getMacroDefinition(II))
1015 appendMacroDirective(II, MD);
1035 updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
1036 auto I = LeafModuleMacros.find(II);
1037 if (I != LeafModuleMacros.end())
1048 macro_iterator macro_begin(
bool IncludeExternalMacros =
true)
const;
1049 macro_iterator macro_end(
bool IncludeExternalMacros =
true)
const;
1051 llvm::iterator_range<macro_iterator>
1052 macros(
bool IncludeExternalMacros =
true)
const {
1055 return llvm::make_range(begin, end);
1077 return &Identifiers.
get(Name);
1084 void AddPragmaHandler(StringRef Namespace,
PragmaHandler *Handler);
1086 AddPragmaHandler(StringRef(), Handler);
1094 void RemovePragmaHandler(StringRef Namespace,
PragmaHandler *Handler);
1096 RemovePragmaHandler(StringRef(), Handler);
1100 void IgnorePragmas();
1112 CodeComplete = &Handler;
1117 return CodeComplete;
1122 CodeComplete =
nullptr;
1127 void CodeCompleteNaturalLanguage();
1131 CodeCompletionII = Filter;
1136 if (CodeCompletionII)
1137 return CodeCompletionII->
getName();
1147 void createPreprocessingRecord();
1150 bool isPCHThroughHeader(
const FileEntry *File);
1153 bool creatingPCHWithThroughHeader();
1156 bool usingPCHWithThroughHeader();
1159 void SkipTokensUntilPCHThroughHeader();
1162 void HandleSkippedThroughHeaderDirective(
Token &Result,
1167 void EnterMainSourceFile();
1170 void EndSourceFile();
1200 void EnterTokenStream(
const Token *Toks,
unsigned NumToks,
1201 bool DisableMacroExpansion,
bool OwnsTokens);
1205 bool DisableMacroExpansion) {
1206 EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion,
true);
1210 EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion,
false);
1217 void RemoveTopOfLexerStack();
1232 void EnableBacktrackAtThisPos();
1235 void CommitBacktrackedTokens();
1264 void Lex(
Token &Result);
1266 void LexAfterModuleImport(
Token &Result);
1271 return CurSubmoduleState->VisibleModules.getImportLoc(M);
1278 const char *DiagnosticTag,
bool AllowMacroExpansion) {
1279 if (AllowMacroExpansion)
1282 LexUnexpandedToken(Result);
1283 return FinishLexStringLiteral(Result, String, DiagnosticTag,
1284 AllowMacroExpansion);
1289 bool FinishLexStringLiteral(
Token &Result, std::string &String,
1290 const char *DiagnosticTag,
1291 bool AllowMacroExpansion);
1301 while (Result.
getKind() == tok::comment);
1307 bool OldVal = DisableMacroExpansion;
1308 DisableMacroExpansion =
true;
1313 DisableMacroExpansion = OldVal;
1320 LexUnexpandedToken(Result);
1321 while (Result.
getKind() == tok::comment);
1327 bool parseSimpleIntegerLiteral(
Token &
Tok, uint64_t &
Value);
1331 DisableMacroExpansion =
true;
1332 MacroExpansionInDirectivesOverride =
true;
1343 if (CachedLexPos + N < CachedTokens.size())
1344 return CachedTokens[CachedLexPos+N];
1346 return PeekAhead(N+1);
1355 assert(isBacktrackEnabled() &&
1356 "Should only be called when tokens are cached for backtracking");
1357 assert(
signed(CachedLexPos) -
signed(N) >=
signed(BacktrackPositions.back())
1358 &&
"Should revert tokens up to the last backtrack position, not more");
1359 assert(
signed(CachedLexPos) -
signed(N) >= 0 &&
1360 "Corrupted backtrack positions ?");
1369 EnterCachingLexMode();
1370 CachedTokens.insert(CachedTokens.begin()+CachedLexPos,
Tok);
1382 assert(Tok.
isAnnotation() &&
"Expected annotation token");
1383 if (CachedLexPos != 0 && isBacktrackEnabled())
1384 AnnotatePreviousCachedTokens(Tok);
1390 assert(CachedLexPos != 0);
1391 return CachedTokens[CachedLexPos-1].getLastLoc();
1396 bool IsPreviousCachedToken(
const Token &Tok)
const;
1414 assert(Tok.
isAnnotation() &&
"Expected annotation token");
1415 if (CachedLexPos != 0 && isBacktrackEnabled())
1416 CachedTokens[CachedLexPos-1] = Tok;
1421 void *AnnotationVal);
1427 if (CachedLexPos != 0 && isBacktrackEnabled())
1428 CachedTokens[CachedLexPos-1] = Tok;
1433 void recomputeCurLexerKind();
1440 IncrementalProcessing = value;
1457 bool SetCodeCompletionPoint(
const FileEntry *File,
1458 unsigned Line,
unsigned Column);
1474 return CodeCompletionFileLoc;
1483 assert(isCodeCompletionEnabled() &&
"Code-completion not enabled!");
1484 CodeCompletionReached =
true;
1486 getDiagnostics().setSuppressAllDiagnostics(
true);
1494 return PragmaARCCFCodeAuditedLoc;
1500 PragmaARCCFCodeAuditedLoc = Loc;
1508 return PragmaAssumeNonNullLoc;
1514 PragmaAssumeNonNullLoc = Loc;
1530 SkipMainFilePreamble.first = Bytes;
1531 SkipMainFilePreamble.second = StartOfLine;
1538 return Diags->
Report(Loc, DiagID);
1554 bool *invalid =
nullptr)
const {
1555 return Lexer::getSpelling(loc, buffer, SourceMgr, LangOpts, invalid);
1567 return Lexer::getSpelling(Tok, SourceMgr, LangOpts, Invalid);
1583 bool *Invalid =
nullptr)
const {
1584 return Lexer::getSpelling(Tok, Buffer, SourceMgr, LangOpts, Invalid);
1591 StringRef getSpelling(
const Token &Tok,
1593 bool *Invalid =
nullptr)
const;
1598 bool IgnoreWhiteSpace =
false) {
1599 return Lexer::getRawToken(Loc, Result, SourceMgr, LangOpts, IgnoreWhiteSpace);
1606 bool *Invalid =
nullptr)
const {
1607 assert(Tok.
is(tok::numeric_constant) &&
1608 Tok.
getLength() == 1 &&
"Called on unsupported token");
1609 assert(!Tok.
needsCleaning() &&
"Token can't need cleaning with length 1");
1629 return Lexer::getImmediateMacroName(Loc, SourceMgr, getLangOpts());
1637 void CreateString(StringRef Str,
Token &Tok,
1662 return Lexer::getLocForEndOfToken(Loc,
Offset, SourceMgr, LangOpts);
1672 return Lexer::isAtStartOfMacroExpansion(loc, SourceMgr, LangOpts,
1683 return Lexer::isAtEndOfMacroExpansion(loc, SourceMgr, LangOpts, MacroEnd);
1687 void DumpToken(
const Token &Tok,
bool DumpFlags =
false)
const;
1689 void DumpMacro(
const MacroInfo &MI)
const;
1695 unsigned Char)
const {
1696 return Lexer::AdvanceToTokenCharacter(TokStart, Char, SourceMgr, LangOpts);
1705 ++NumFastTokenPaste;
1712 size_t getTotalMemory()
const;
1717 void HandleMicrosoftCommentPaste(
Token &Tok);
1729 llvm::DenseMap<IdentifierInfo*,unsigned> PoisonReasons;
1739 void HandlePoisonedIdentifier(
Token & Tok);
1744 HandlePoisonedIdentifier(Identifier);
1754 *Ident___exception_code,
1755 *Ident_GetExceptionCode;
1758 *Ident___exception_info,
1759 *Ident_GetExceptionInfo;
1762 *Ident___abnormal_termination,
1763 *Ident_AbnormalTermination;
1765 const char *getCurLexerEndPos();
1766 void diagnoseMissingHeaderInUmbrellaDir(
const Module &Mod);
1769 void PoisonSEHIdentifiers(
bool Poison =
true);
1779 bool HandleIdentifier(
Token &Identifier);
1786 bool HandleEndOfFile(
Token &Result,
bool isEndOfMacro =
false);
1790 bool HandleEndOfTokenLexer(
Token &Result);
1797 void HandleDirective(
Token &Result);
1804 void CheckEndOfDirective(
const char *
Directive,
bool EnableMacros =
false);
1808 void DiscardUntilEndOfDirective();
1819 Module *getCurrentModule();
1846 bool *IsMapped,
bool SkipCache =
false);
1856 bool isInPrimaryFile()
const;
1878 bool CheckMacroName(
Token &MacroNameTok,
MacroUse isDefineUndef,
1879 bool *ShadowFlag =
nullptr);
1882 Module *LeaveSubmodule(
bool ForPragma);
1885 friend void TokenLexer::ExpandFunctionArguments();
1887 void PushIncludeMacroStack() {
1888 assert(CurLexerKind != CLK_CachingLexer &&
"cannot push a caching lexer");
1889 IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
1890 std::move(CurLexer), std::move(CurPTHLexer),
1891 CurPPLexer, std::move(CurTokenLexer),
1893 CurPPLexer =
nullptr;
1896 void PopIncludeMacroStack() {
1897 CurLexer = std::move(IncludeMacroStack.back().TheLexer);
1898 CurPTHLexer = std::move(IncludeMacroStack.back().ThePTHLexer);
1899 CurPPLexer = IncludeMacroStack.back().ThePPLexer;
1900 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
1901 CurDirLookup = IncludeMacroStack.back().TheDirLookup;
1902 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
1903 CurLexerKind = IncludeMacroStack.back().CurLexerKind;
1904 IncludeMacroStack.pop_back();
1907 void PropagateLineStartLeadingSpaceInfo(
Token &Result);
1911 bool needModuleMacros()
const;
1915 void updateModuleMacroInfo(
const IdentifierInfo *II, ModuleMacroInfo &Info);
1934 bool *ShadowFlag =
nullptr);
1945 MacroInfo *ReadOptionalMacroParameterListAndBody(
1946 const Token &MacroNameTok,
bool ImmediatelyAfterHeaderGuard);
1964 bool FoundNonSkipPortion,
bool FoundElse,
1968 void PTHSkipExcludedConditionalBlock();
1972 struct DirectiveEvalResult {
1977 bool IncludedUndefinedIds;
1984 DirectiveEvalResult EvaluateDirectiveExpression(
IdentifierInfo *&IfNDefMacro);
1988 void RegisterBuiltinPragmas();
1991 void RegisterBuiltinMacros();
2006 void removeCachedMacroExpandedTokensOfLastLexer();
2011 bool isNextPPTokenLParen();
2020 void ExpandBuiltinMacro(
Token &Tok);
2025 void Handle_Pragma(
Token &Tok);
2029 void HandleMicrosoft__pragma(
Token &Tok);
2040 void setPredefinesFileID(
FileID FID) {
2041 assert(PredefinesFileID.
isInvalid() &&
"PredefinesFileID already set!");
2042 PredefinesFileID = FID;
2046 void setPCHThroughHeaderFileID(
FileID FID);
2054 static bool IsFileLexer(
const IncludeStackInfo& I) {
2055 return IsFileLexer(I.TheLexer.get(), I.ThePPLexer);
2058 bool IsFileLexer()
const {
2059 return IsFileLexer(CurLexer.get(), CurPPLexer);
2064 void CachingLex(
Token &Result);
2066 bool InCachingLexMode()
const {
2069 return !CurPPLexer && !CurTokenLexer && !CurPTHLexer &&
2070 !IncludeMacroStack.empty();
2073 void EnterCachingLexMode();
2075 void ExitCachingLexMode() {
2076 if (InCachingLexMode())
2077 RemoveTopOfLexerStack();
2080 const Token &PeekAhead(
unsigned N);
2081 void AnnotatePreviousCachedTokens(
const Token &Tok);
2087 void HandleLineDirective();
2088 void HandleDigitDirective(
Token &Tok);
2089 void HandleUserDiagnosticDirective(
Token &Tok,
bool isWarning);
2090 void HandleIdentSCCSDirective(
Token &Tok);
2091 void HandleMacroPublicDirective(
Token &Tok);
2092 void HandleMacroPrivateDirective();
2098 const FileEntry *LookupFromFile =
nullptr,
2099 bool isImport =
false);
2103 void HandleMicrosoftImportDirective(
Token &Tok);
2109 static bool checkModuleIsAvailable(
const LangOptions &LangOpts,
2135 return PreambleConditionalStack.isRecording();
2139 return PreambleConditionalStack.hasRecordedPreamble();
2143 return PreambleConditionalStack.getStack();
2147 PreambleConditionalStack.setStack(s);
2152 PreambleConditionalStack.startReplaying();
2153 PreambleConditionalStack.setStack(s);
2154 PreambleConditionalStack.SkipInfo = SkipInfo;
2158 return PreambleConditionalStack.SkipInfo;
2164 void replayPreambleConditionalStack();
2167 void HandleDefineDirective(
Token &Tok,
bool ImmediatelyAfterTopLevelIfndef);
2168 void HandleUndefDirective();
2171 void HandleIfdefDirective(
Token &Tok,
const Token &HashToken,
2172 bool isIfndef,
bool ReadAnyTokensBeforeDirective);
2173 void HandleIfDirective(
Token &Tok,
const Token &HashToken,
2174 bool ReadAnyTokensBeforeDirective);
2175 void HandleEndifDirective(
Token &Tok);
2176 void HandleElseDirective(
Token &Tok,
const Token &HashToken);
2177 void HandleElifDirective(
Token &Tok,
const Token &HashToken);
2184 void HandlePragmaOnce(
Token &OnceTok);
2185 void HandlePragmaMark();
2186 void HandlePragmaPoison();
2187 void HandlePragmaSystemHeader(
Token &SysHeaderTok);
2188 void HandlePragmaDependency(
Token &DependencyTok);
2189 void HandlePragmaPushMacro(
Token &Tok);
2190 void HandlePragmaPopMacro(
Token &Tok);
2191 void HandlePragmaIncludeAlias(
Token &Tok);
2192 void HandlePragmaModuleBuild(
Token &Tok);
2220 #endif // LLVM_CLANG_LEX_PREPROCESSOR_H IdentifierInfo * get(StringRef Name) override
get - Return the identifier token info for the specified named identifier.
PreambleSkipInfo(SourceLocation HashTokenLoc, SourceLocation IfTokenLoc, bool FoundNonSkipPortion, bool FoundElse, SourceLocation ElseLoc)
CachedTokensTy::size_type End
A set of visible modules.
llvm::BumpPtrAllocator & getPreprocessorAllocator()
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
SelectorTable & getSelectorTable()
Holds information about both target-independent and target-specific builtins, allowing easy queries b...
Implements support for file system lookup, file system caching, and directory search management...
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
std::string getSpelling(const Token &Tok, bool *Invalid=nullptr) const
Return the 'spelling' of the Tok token.
MemoryBufferCache & getPCMCache() const
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
void MaybeHandlePoisonedIdentifier(Token &Identifier)
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)) {...
Defines the SourceManager interface.
static const Builtin::Info BuiltinInfo[]
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...
FileManager & getFileManager() const
Defines the clang::Module class, which describes a module in the source code.
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
SourceLocation getPragmaARCCFCodeAuditedLoc() const
The location of the currently-active #pragma clang arc_cf_code_audited begin.
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
Defines the clang::MacroInfo and clang::MacroDirective classes.
A description of the current definition of a macro.
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
A directive for an undefined macro.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
void setCodeCompletionIdentifierInfo(IdentifierInfo *Filter)
Set the code completion token for filtering purposes.
void setCodeCompletionReached()
Note that we hit the code-completion point.
bool hadModuleLoaderFatalFailure() const
const DefInfo findDirectiveAtLoc(SourceLocation L, SourceManager &SM) const
Find macro definition active in the specified source location.
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
Manage memory buffers across multiple users.
bool getRawToken(SourceLocation Loc, Token &Result, bool IgnoreWhiteSpace=false)
Relex the token at the specified location.
bool operator==(const Token &Tok) const
Builtin::Context & getBuiltinInfo()
void setPredefines(const char *P)
Set the predefines for this Preprocessor.
SourceLocation getCodeCompletionFileLoc() const
Returns the start location of the file of code-completion point.
char getSpellingOfSingleCharacterNumericConstant(const Token &Tok, bool *Invalid=nullptr) const
Given a Token Tok that is a numeric constant with length 1, return the character. ...
This interface provides a way to observe the actions of the preprocessor as it does its thing...
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
tok::TokenKind getKind() const
TokenValue(tok::TokenKind Kind)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
One of these records is kept for each identifier that is lexed.
ArrayRef< PPConditionalInfo > getPreambleConditionalStack() const
Represents a macro directive exported by a module.
A directive for a defined macro or a macro imported from a module.
This table allows us to fully hide how we implement multi-keyword caching.
const TargetInfo & getTargetInfo() const
Token - This structure provides full information about a lexed token.
void SetCommentRetentionState(bool KeepComments, bool KeepMacroComments)
Control whether the preprocessor retains comments in output.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const LangOptions & getLangOpts() const
Describes a module or submodule.
bool isPragmaLexer() const
isPragmaLexer - Returns true if this Lexer is being used to lex a pragma.
A directive for setting the module visibility of a macro.
void SetSuppressIncludeNotFoundError(bool Suppress)
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...
MacroUse
Context in which macro name is used.
llvm::Registry< PragmaHandler > PragmaHandlerRegistry
Registry of pragma handlers added by plugins.
Module * getCurrentLexerSubmodule() const
Return the submodule owning the file being lexed.
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 ...
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
HeaderSearch & getHeaderSearchInfo() const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void LexNonComment(Token &Result)
Lex a token.
Concrete class used by the front-end to report problems and issues.
bool isMacroDefined(const IdentifierInfo *II)
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...
Defines the Diagnostic-related interfaces.
const TargetInfo * getAuxTargetInfo() const
TokenLexer - This implements a lexer that returns tokens from a macro body or token stream instead of...
void setCodeCompletionHandler(CodeCompletionHandler &Handler)
Set the code completion handler to the given object.
void setPreprocessedOutput(bool IsPreprocessedOutput)
Sets whether the preprocessor is responsible for producing output or if it is producing tokens to be ...
PragmaIntroducerKind
Describes how the pragma was introduced, e.g., with #pragma, _Pragma, or __pragma.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
A little helper class used to produce diagnostics.
void clearCodeCompletionHandler()
Clear out the code completion handler.
Provides lookups to, and iteration over, IdentiferInfo objects.
Exposes information about the current target.
const IdentifierTable & getIdentifierTable() const
bool isCodeCompletionEnabled() const
Determine if we are performing code completion.
Abstract interface for external sources of preprocessor information.
Defines the clang::LangOptions interface.
unsigned getCounterValue() const
const DefMacroDirective * getDirective() const
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
const AnnotatedLine * Line
SourceLocation HashTokenLoc
void SetMacroExpansionOnlyInDirectives()
Disables macro expansion everywhere except for preprocessor directives.
bool isCurrentLexer(const PreprocessorLexer *L) const
Return true if we are lexing directly from the specified lexer.
Implements an efficient mapping from strings to IdentifierInfo nodes.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
A class for tracking whether we're inside a VA_OPT during a traversal of the tokens of a variadic mac...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
DefInfo getDefinition()
Traverses the macro directives history and returns the next macro definition directive along with inf...
void IncrementPasteCounter(bool isFast)
Increment the counters for the number of token paste operations performed.
Stores token information for comparing actual tokens with predefined values.
llvm::Optional< PreambleSkipInfo > getPreambleSkipInfo() const
DiagnosticBuilder Diag(const Token &Tok, unsigned DiagID) const
void setPragmaAssumeNonNullLoc(SourceLocation Loc)
Set the location of the currently-active #pragma clang assume_nonnull begin.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
bool getCommentRetentionState() const
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
TokenValue(IdentifierInfo *II)
PPCallbacks * getPPCallbacks() const
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
bool isRecordingPreamble() const
const DirectoryLookup * GetCurDirLookup()
Get the DirectoryLookup structure used to find the current FileEntry, if CurLexer is non-null and if ...
SourceManager & getSourceManager() const
MacroDirective * getLocalMacroDirective(const IdentifierInfo *II) const
Given an identifier, return its latest non-imported MacroDirective if it is #define'd and not #undef'...
ExternalPreprocessorSource * getExternalSource() const
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
void TypoCorrectToken(const Token &Tok)
Update the current token to represent the provided identifier, in order to cache an action performed ...
void setExternalSource(ExternalPreprocessorSource *Source)
Encodes a location in the source.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
bool isAnnotation(TokenKind K)
Return true if this is any of tok::annot_* kinds.
void setPragmaARCCFCodeAuditedLoc(SourceLocation Loc)
Set the location of the currently-active #pragma clang arc_cf_code_audited begin. ...
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
IdentifierInfo * getIdentifierInfo() const
IdentifierTable & getIdentifierTable()
void setPragmasEnabled(bool Enabled)
Cached information about one file (either on disk or in the virtual file system). ...
CodeCompletionHandler * getCodeCompletionHandler() const
Retrieve the current code-completion handler.
bool isAtStartOfMacroExpansion(SourceLocation loc, SourceLocation *MacroBegin=nullptr) const
Returns true if the given MacroID location points at the first token of the macro expansion...
bool isLiteral(TokenKind K)
Return true if this is a "literal" kind, like a numeric constant, string, etc.
bool isPoisoned() const
Return true if this token has been poisoned.
bool SawDateOrTime() const
Returns true if the preprocessor has seen a use of DATE or TIME in the file so far.
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
void enableIncrementalProcessing(bool value=true)
Enables the incremental processing.
MacroDefinition getMacroDefinitionAtLoc(const IdentifierInfo *II, SourceLocation Loc)
PreprocessorLexer * getCurrentLexer() const
Return the current lexer being lexed from.
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 ReplaceLastTokenWithAnnotation(const Token &Tok)
Replace the last token with an annotation token.
SourceLocation getPragmaAssumeNonNullLoc() const
The location of the currently-active #pragma clang assume_nonnull begin.
SourceLocation getCodeCompletionLoc() const
Returns the location of the code-completion point.
const MacroInfo * getMacroInfo() const
StringRef getName() const
Return the actual identifier string.
bool isMacroDefined(StringRef Id)
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isBacktrackEnabled() const
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
Dataflow Directional Tag Classes.
SourceLocation IfTokenLoc
void EnterTokenStream(ArrayRef< Token > Toks, bool DisableMacroExpansion)
SmallVector< Token, 4 > CachedTokens
A set of tokens that has been cached for later parsing.
void EnterTokenStream(std::unique_ptr< Token[]> Toks, unsigned NumToks, bool DisableMacroExpansion)
PreprocessingRecord * getPreprocessingRecord() const
Retrieve the preprocessing record, or NULL if there is no preprocessing record.
Reads an AST files chain containing the contents of a translation unit.
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
llvm::iterator_range< macro_iterator > macros(bool IncludeExternalMacros=true) const
SourceLocation getLastCachedTokenLocation() const
Get the location of the last cached token, suitable for setting the end location of an annotation tok...
StringRef getCodeCompletionFilter()
Get the code completion token for filtering purposes.
Abstract interface for a module loader.
unsigned getLength() const
Encapsulates the data about a macro definition (e.g.
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
const char * getLiteralData() const
getLiteralData - For a literal token (numeric constant, string, etc), this returns a pointer to the s...
bool getPragmasEnabled() const
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.
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
ModuleLoader & getModuleLoader() const
Retrieve the module loader associated with this preprocessor.
void LexUnexpandedNonComment(Token &Result)
Like LexNonComment, but this disables macro expansion of identifier tokens.
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
Cached information about one directory (either on disk or in the virtual file system).
Defines the PPCallbacks interface.
Defines the clang::TokenKind enum and support functions.
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI)
SourceLocation getModuleImportLoc(Module *M) const
Defines the clang::SourceLocation class and associated facilities.
void RemovePragmaHandler(PragmaHandler *Handler)
FileID getPredefinesFileID() const
Returns the FileID for the preprocessor predefines.
DiagnosticsEngine & getDiagnostics() const
void setMainFileDir(const DirectoryEntry *Dir)
Set the directory in which the main file should be considered to have been found, if it is not a real...
static bool isMacroDefined(const Sema &S, SourceLocation Loc, StringRef Name)
TranslationUnitKind
Describes the kind of translation unit being processed.
bool hasRecordedPreamble() const
const std::string & getPredefines() const
bool needsCleaning() const
Return true if this token has trigraphs or escaped newlines in it.
void setPredefines(StringRef P)
ArrayRef< ModuleMacro * > getLeafModuleMacros(const IdentifierInfo *II) const
Get the list of leaf (non-overridden) module macros for a name.
bool isIncrementalProcessingEnabled() const
Returns true if incremental processing is enabled.
The translation unit is a complete translation unit.
StringRef getImmediateMacroName(SourceLocation Loc)
Retrieve the name of the immediate macro expansion.
MacroMap::const_iterator macro_iterator
void setCounterValue(unsigned V)
bool isParsingIfOrElifDirective() const
True if we are currently preprocessing a if or #elif directive.
void setSkipMainFilePreamble(unsigned Bytes, bool StartOfLine)
Instruct the preprocessor to skip part of the main source file.
A trivial tuple used to represent a source range.
bool GetSuppressIncludeNotFoundError()
void setReplayablePreambleConditionalStack(ArrayRef< PPConditionalInfo > s, llvm::Optional< PreambleSkipInfo > SkipInfo)
Directive - Abstract class representing a parsed verify directive.
MacroInfo * getMacroInfo(const IdentifierInfo *II)
Callback handler that receives notifications when performing code completion within the preprocessor...
bool isPreprocessedOutput() const
Returns true if the preprocessor is responsible for generating output, false if it is producing token...
PTHManager * getPTHManager()
bool hasMacroDefinition() const
Return true if this identifier is #defined to some other value.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
void setRecordedPreambleConditionalStack(ArrayRef< PPConditionalInfo > s)
This class handles loading and caching of source files into memory.
Defines enum values for all the target-independent builtin functions.
An RAII class that tracks when the Preprocessor starts and stops lexing the definition of a (ISO C/C+...
void AddPragmaHandler(PragmaHandler *Handler)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void setDiagnostics(DiagnosticsEngine &D)