14 #ifndef LLVM_CLANG_LEX_PREPROCESSOR_H 15 #define LLVM_CLANG_LEX_PREPROCESSOR_H 33 #include "llvm/ADT/ArrayRef.h" 34 #include "llvm/ADT/DenseMap.h" 35 #include "llvm/ADT/FoldingSet.h" 36 #include "llvm/ADT/None.h" 37 #include "llvm/ADT/Optional.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" 59 template<
unsigned InternalLen>
class SmallString;
65 class CodeCompletionHandler;
68 class DirectoryLookup;
69 class ExternalPreprocessorSource;
74 class MemoryBufferCache;
76 class PragmaNamespace;
77 class PreprocessingRecord;
78 class PreprocessorLexer;
79 class PreprocessorOptions;
91 assert(Kind != tok::raw_identifier &&
"Raw identifiers are not supported.");
92 assert(Kind != tok::identifier &&
93 "Identifiers should be created by TokenValue(IdentifierInfo *)");
101 return Tok.
getKind() == Kind &&
128 std::shared_ptr<PreprocessorOptions> PPOpts;
136 std::unique_ptr<ScratchBuffer> ScratchBuf;
145 llvm::BumpPtrAllocator BP;
182 unsigned CounterValue = 0;
186 MaxAllowedIncludeStackDepth = 200
190 bool KeepComments : 1;
191 bool KeepMacroComments : 1;
192 bool SuppressIncludeNotFoundError : 1;
195 bool InMacroArgs : 1;
198 bool OwnsHeaderSearch : 1;
201 bool DisableMacroExpansion : 1;
205 bool MacroExpansionInDirectivesOverride : 1;
210 mutable bool ReadMacrosFromExternalSource : 1;
213 bool PragmasEnabled : 1;
216 bool PreprocessedOutput : 1;
219 bool ParsingIfOrElifDirective;
222 bool InMacroArgPreExpansion;
244 std::unique_ptr<PragmaNamespace> PragmaHandlers;
248 std::unique_ptr<PragmaNamespace> PragmaHandlersBackup;
252 std::vector<CommentHandler *> CommentHandlers;
256 bool IncrementalProcessing =
false;
265 const FileEntry *CodeCompletionFile =
nullptr;
268 unsigned CodeCompletionOffset = 0;
288 bool LastTokenWasAt =
false;
292 bool ModuleImportExpectsIdentifier =
false;
303 bool CodeCompletionReached =
false;
322 std::pair<int, bool> SkipMainFilePreamble;
326 bool HasReachedMaxIncludeDepth =
false;
337 bool FoundNonSkipPortion,
bool FoundElse,
339 : HashTokenLoc(HashTokenLoc), IfTokenLoc(IfTokenLoc),
340 FoundNonSkipPortion(FoundNonSkipPortion), FoundElse(FoundElse),
348 class PreambleConditionalStackStore {
356 PreambleConditionalStackStore() =
default;
358 void startRecording() { ConditionalStackState = Recording; }
359 void startReplaying() { ConditionalStackState = Replaying; }
360 bool isRecording()
const {
return ConditionalStackState == Recording; }
361 bool isReplaying()
const {
return ConditionalStackState == Replaying; }
364 return ConditionalStack;
367 void doneReplaying() {
368 ConditionalStack.clear();
369 ConditionalStackState = Off;
373 if (!isRecording() && !isReplaying())
375 ConditionalStack.clear();
376 ConditionalStack.append(s.begin(), s.end());
379 bool hasRecordedPreamble()
const {
return !ConditionalStack.empty(); }
381 bool reachedEOFWhileSkipping()
const {
return SkipInfo.hasValue(); }
383 void clearSkipInfo() { SkipInfo.reset(); }
389 State ConditionalStackState = Off;
390 } PreambleConditionalStack;
396 std::unique_ptr<Lexer> CurLexer;
414 std::unique_ptr<TokenLexer> CurTokenLexer;
421 CLK_LexAfterModuleImport
422 } CurLexerKind = CLK_Lexer;
426 Module *CurLexerSubmodule =
nullptr;
431 struct IncludeStackInfo {
432 enum CurLexerKind CurLexerKind;
434 std::unique_ptr<Lexer> TheLexer;
436 std::unique_ptr<TokenLexer> TheTokenLexer;
441 IncludeStackInfo(
enum CurLexerKind CurLexerKind,
Module *TheSubmodule,
442 std::unique_ptr<Lexer> &&TheLexer,
444 std::unique_ptr<TokenLexer> &&TheTokenLexer,
446 : CurLexerKind(
std::move(CurLexerKind)),
447 TheSubmodule(
std::move(TheSubmodule)), TheLexer(
std::move(TheLexer)),
448 ThePPLexer(
std::move(ThePPLexer)),
449 TheTokenLexer(
std::move(TheTokenLexer)),
450 TheDirLookup(
std::move(TheDirLookup)) {}
452 std::vector<IncludeStackInfo> IncludeMacroStack;
456 std::unique_ptr<PPCallbacks> Callbacks;
458 struct MacroExpandsInfo {
464 : Tok(Tok), MD(MD), Range(Range) {}
469 struct ModuleMacroInfo {
474 llvm::TinyPtrVector<ModuleMacro *> ActiveModuleMacros;
478 unsigned ActiveModuleMacrosGeneration = 0;
481 bool IsAmbiguous =
false;
484 llvm::TinyPtrVector<ModuleMacro *> OverriddenMacros;
491 mutable llvm::PointerUnion<MacroDirective *, ModuleMacroInfo *>
State;
496 PP.updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
502 !PP.CurSubmoduleState->VisibleModules.getGeneration())
505 auto *Info = State.dyn_cast<ModuleMacroInfo*>();
512 if (PP.CurSubmoduleState->VisibleModules.getGeneration() !=
513 Info->ActiveModuleMacrosGeneration)
514 PP.updateModuleMacroInfo(II, *Info);
519 MacroState() : MacroState(nullptr) {}
522 MacroState(MacroState &&O) noexcept :
State(O.State) {
526 MacroState &operator=(MacroState &&O) noexcept {
534 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
535 Info->~ModuleMacroInfo();
539 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
545 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
552 auto *Info = getModuleInfo(PP, II);
553 return Info ? Info->IsAmbiguous :
false;
558 if (
auto *Info = getModuleInfo(PP, II))
559 return Info->ActiveModuleMacros;
566 if (
auto *Latest = getLatest())
567 return Latest->findDirectiveAtLoc(Loc, SourceMgr);
572 if (
auto *Info = getModuleInfo(PP, II)) {
573 Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
574 Info->ActiveModuleMacros.begin(),
575 Info->ActiveModuleMacros.end());
576 Info->ActiveModuleMacros.clear();
577 Info->IsAmbiguous =
false;
582 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
583 return Info->OverriddenMacros;
589 auto *Info = State.dyn_cast<ModuleMacroInfo*>();
591 if (Overrides.empty())
597 Info->OverriddenMacros.clear();
598 Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
599 Overrides.begin(), Overrides.end());
600 Info->ActiveModuleMacrosGeneration = 0;
609 using MacroMap = llvm::DenseMap<const IdentifierInfo *, MacroState>;
611 struct SubmoduleState;
614 struct BuildingSubmoduleInfo {
625 SubmoduleState *OuterSubmoduleState;
628 unsigned OuterPendingModuleMacroNames;
631 SubmoduleState *OuterSubmoduleState,
632 unsigned OuterPendingModuleMacroNames)
633 : M(M), ImportLoc(ImportLoc), IsPragma(IsPragma),
634 OuterSubmoduleState(OuterSubmoduleState),
635 OuterPendingModuleMacroNames(OuterPendingModuleMacroNames) {}
640 struct SubmoduleState {
650 std::map<Module *, SubmoduleState> Submodules;
653 SubmoduleState NullSubmoduleState;
657 SubmoduleState *CurSubmoduleState;
660 llvm::FoldingSet<ModuleMacro> ModuleMacros;
667 llvm::DenseMap<const IdentifierInfo *, llvm::TinyPtrVector<ModuleMacro *>>
679 using WarnUnusedMacroLocsTy = llvm::SmallPtrSet<SourceLocation, 32>;
680 WarnUnusedMacroLocsTy WarnUnusedMacroLocs;
688 llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>>
692 unsigned NumDirectives = 0;
693 unsigned NumDefined = 0;
694 unsigned NumUndefined = 0;
695 unsigned NumPragma = 0;
697 unsigned NumElse = 0;
698 unsigned NumEndif = 0;
699 unsigned NumEnteredSourceFiles = 0;
700 unsigned MaxIncludeStackDepth = 0;
701 unsigned NumMacroExpanded = 0;
702 unsigned NumFnMacroExpanded = 0;
703 unsigned NumBuiltinMacroExpanded = 0;
704 unsigned NumFastMacroExpanded = 0;
705 unsigned NumTokenPaste = 0;
706 unsigned NumFastTokenPaste = 0;
707 unsigned NumSkipped = 0;
711 std::string Predefines;
717 FileID PCHThroughHeaderFileID;
720 bool SkippingUntilPragmaHdrStop =
false;
723 bool SkippingUntilPCHThroughHeader =
false;
727 enum { TokenLexerCacheSize = 8 };
728 unsigned NumCachedTokenLexers;
729 std::unique_ptr<TokenLexer> TokenLexerCache[TokenLexerCacheSize];
738 std::vector<std::pair<TokenLexer *, size_t>> MacroExpandingLexersStack;
759 CachedTokensTy::size_type CachedLexPos = 0;
766 std::vector<CachedTokensTy::size_type> BacktrackPositions;
768 struct MacroInfoChain {
770 MacroInfoChain *Next;
775 MacroInfoChain *MIChainHead =
nullptr;
780 Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
785 bool OwnsHeaderSearch =
false,
805 void InitializeForModelFile();
808 void FinalizeForModelFile();
832 ExternalSource = Source;
836 return ExternalSource;
848 return ParsingIfOrElifDirective;
853 this->KeepComments = KeepComments | KeepMacroComments;
854 this->KeepMacroComments = KeepMacroComments;
863 SuppressIncludeNotFoundError = Suppress;
867 return SuppressIncludeNotFoundError;
873 PreprocessedOutput = IsPreprocessedOutput;
882 return CurPPLexer == L;
912 C = llvm::make_unique<PPChainedCallbacks>(std::move(C),
913 std::move(Callbacks));
914 Callbacks = std::move(C);
923 (!getLangOpts().Modules || (
bool)getMacroDefinition(II));
932 auto I = Submodules.find(M);
933 if (I == Submodules.end())
935 auto J = I->second.Macros.find(II);
936 if (J == I->second.Macros.end())
938 auto *MD = J->second.getLatest();
946 MacroState &S = CurSubmoduleState->Macros[II];
947 auto *MD = S.getLatest();
948 while (MD && isa<VisibilityMacroDirective>(MD))
951 S.getActiveModuleMacros(*
this, II),
952 S.isAmbiguous(*
this, II));
960 MacroState &S = CurSubmoduleState->Macros[II];
962 if (
auto *MD = S.getLatest())
966 S.getActiveModuleMacros(*
this, II),
967 S.isAmbiguous(*
this, II));
976 auto *MD = getLocalMacroDirectiveHistory(II);
984 return const_cast<Preprocessor*
>(
this)->getMacroInfo(II);
990 if (
auto MD = getMacroDefinition(II))
1007 appendMacroDirective(II, MD);
1027 updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
1028 auto I = LeafModuleMacros.find(II);
1029 if (I != LeafModuleMacros.end())
1040 macro_iterator macro_begin(
bool IncludeExternalMacros =
true)
const;
1041 macro_iterator macro_end(
bool IncludeExternalMacros =
true)
const;
1043 llvm::iterator_range<macro_iterator>
1044 macros(
bool IncludeExternalMacros =
true)
const {
1047 return llvm::make_range(begin, end);
1069 return &Identifiers.
get(Name);
1076 void AddPragmaHandler(StringRef Namespace,
PragmaHandler *Handler);
1078 AddPragmaHandler(StringRef(), Handler);
1086 void RemovePragmaHandler(StringRef Namespace,
PragmaHandler *Handler);
1088 RemovePragmaHandler(StringRef(), Handler);
1092 void IgnorePragmas();
1104 CodeComplete = &Handler;
1109 return CodeComplete;
1114 CodeComplete =
nullptr;
1119 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled);
1123 void CodeCompleteNaturalLanguage();
1127 CodeCompletionII =
Filter;
1134 CodeCompletionTokenRange = {Start, End};
1137 return CodeCompletionTokenRange;
1142 if (CodeCompletionII)
1143 return CodeCompletionII->
getName();
1153 void createPreprocessingRecord();
1156 bool isPCHThroughHeader(
const FileEntry *FE);
1159 bool creatingPCHWithThroughHeader();
1162 bool usingPCHWithThroughHeader();
1165 bool creatingPCHWithPragmaHdrStop();
1168 bool usingPCHWithPragmaHdrStop();
1172 void SkipTokensWhileUsingPCH();
1176 void HandleSkippedDirectiveWhileUsingPCH(
Token &Result,
1181 void EnterMainSourceFile();
1184 void EndSourceFile();
1214 void EnterTokenStream(
const Token *Toks,
unsigned NumToks,
1215 bool DisableMacroExpansion,
bool OwnsTokens);
1219 bool DisableMacroExpansion) {
1220 EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion,
true);
1224 EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion,
false);
1231 void RemoveTopOfLexerStack();
1246 void EnableBacktrackAtThisPos();
1249 void CommitBacktrackedTokens();
1278 void Lex(
Token &Result);
1280 void LexAfterModuleImport(
Token &Result);
1285 return CurSubmoduleState->VisibleModules.getImportLoc(M);
1292 const char *DiagnosticTag,
bool AllowMacroExpansion) {
1293 if (AllowMacroExpansion)
1296 LexUnexpandedToken(Result);
1297 return FinishLexStringLiteral(Result, String, DiagnosticTag,
1298 AllowMacroExpansion);
1303 bool FinishLexStringLiteral(
Token &Result, std::string &String,
1304 const char *DiagnosticTag,
1305 bool AllowMacroExpansion);
1315 while (Result.
getKind() == tok::comment);
1321 bool OldVal = DisableMacroExpansion;
1322 DisableMacroExpansion =
true;
1327 DisableMacroExpansion = OldVal;
1334 LexUnexpandedToken(Result);
1335 while (Result.
getKind() == tok::comment);
1341 bool parseSimpleIntegerLiteral(
Token &Tok, uint64_t &
Value);
1345 DisableMacroExpansion =
true;
1346 MacroExpansionInDirectivesOverride =
true;
1357 if (CachedLexPos + N < CachedTokens.size())
1358 return CachedTokens[CachedLexPos+N];
1360 return PeekAhead(N+1);
1369 assert(isBacktrackEnabled() &&
1370 "Should only be called when tokens are cached for backtracking");
1371 assert(
signed(CachedLexPos) -
signed(N) >=
signed(BacktrackPositions.back())
1372 &&
"Should revert tokens up to the last backtrack position, not more");
1373 assert(
signed(CachedLexPos) -
signed(N) >= 0 &&
1374 "Corrupted backtrack positions ?");
1383 EnterCachingLexMode();
1384 CachedTokens.insert(CachedTokens.begin()+CachedLexPos,
Tok);
1396 assert(Tok.
isAnnotation() &&
"Expected annotation token");
1397 if (CachedLexPos != 0 && isBacktrackEnabled())
1398 AnnotatePreviousCachedTokens(Tok);
1404 assert(CachedLexPos != 0);
1405 return CachedTokens[CachedLexPos-1].getLastLoc();
1410 bool IsPreviousCachedToken(
const Token &Tok)
const;
1428 assert(Tok.
isAnnotation() &&
"Expected annotation token");
1429 if (CachedLexPos != 0 && isBacktrackEnabled())
1430 CachedTokens[CachedLexPos-1] = Tok;
1435 void *AnnotationVal);
1441 if (CachedLexPos != 0 && isBacktrackEnabled())
1442 CachedTokens[CachedLexPos-1] = Tok;
1447 void recomputeCurLexerKind();
1454 IncrementalProcessing = value;
1471 bool SetCodeCompletionPoint(
const FileEntry *File,
1472 unsigned Line,
unsigned Column);
1488 return CodeCompletionFileLoc;
1497 assert(isCodeCompletionEnabled() &&
"Code-completion not enabled!");
1498 CodeCompletionReached =
true;
1500 getDiagnostics().setSuppressAllDiagnostics(
true);
1508 return PragmaARCCFCodeAuditedLoc;
1514 PragmaARCCFCodeAuditedLoc = Loc;
1522 return PragmaAssumeNonNullLoc;
1528 PragmaAssumeNonNullLoc = Loc;
1544 SkipMainFilePreamble.first = Bytes;
1545 SkipMainFilePreamble.second = StartOfLine;
1552 return Diags->
Report(Loc, DiagID);
1568 bool *invalid =
nullptr)
const {
1569 return Lexer::getSpelling(loc, buffer, SourceMgr, LangOpts, invalid);
1581 return Lexer::getSpelling(Tok, SourceMgr, LangOpts, Invalid);
1597 bool *Invalid =
nullptr)
const {
1598 return Lexer::getSpelling(Tok, Buffer, SourceMgr, LangOpts, Invalid);
1605 StringRef getSpelling(
const Token &Tok,
1607 bool *Invalid =
nullptr)
const;
1612 bool IgnoreWhiteSpace =
false) {
1613 return Lexer::getRawToken(Loc, Result, SourceMgr, LangOpts, IgnoreWhiteSpace);
1620 bool *Invalid =
nullptr)
const {
1621 assert(Tok.
is(tok::numeric_constant) &&
1622 Tok.
getLength() == 1 &&
"Called on unsupported token");
1623 assert(!Tok.
needsCleaning() &&
"Token can't need cleaning with length 1");
1643 return Lexer::getImmediateMacroName(Loc, SourceMgr, getLangOpts());
1651 void CreateString(StringRef Str,
Token &Tok,
1676 return Lexer::getLocForEndOfToken(Loc,
Offset, SourceMgr, LangOpts);
1686 return Lexer::isAtStartOfMacroExpansion(loc, SourceMgr, LangOpts,
1697 return Lexer::isAtEndOfMacroExpansion(loc, SourceMgr, LangOpts, MacroEnd);
1701 void DumpToken(
const Token &Tok,
bool DumpFlags =
false)
const;
1703 void DumpMacro(
const MacroInfo &MI)
const;
1709 unsigned Char)
const {
1710 return Lexer::AdvanceToTokenCharacter(TokStart, Char, SourceMgr, LangOpts);
1719 ++NumFastTokenPaste;
1726 size_t getTotalMemory()
const;
1731 void HandleMicrosoftCommentPaste(
Token &Tok);
1743 llvm::DenseMap<IdentifierInfo*,unsigned> PoisonReasons;
1753 void HandlePoisonedIdentifier(
Token & Identifier);
1758 HandlePoisonedIdentifier(Identifier);
1768 *Ident___exception_code,
1769 *Ident_GetExceptionCode;
1772 *Ident___exception_info,
1773 *Ident_GetExceptionInfo;
1776 *Ident___abnormal_termination,
1777 *Ident_AbnormalTermination;
1779 const char *getCurLexerEndPos();
1780 void diagnoseMissingHeaderInUmbrellaDir(
const Module &Mod);
1783 void PoisonSEHIdentifiers(
bool Poison =
true);
1793 bool HandleIdentifier(
Token &Identifier);
1800 bool HandleEndOfFile(
Token &Result,
bool isEndOfMacro =
false);
1804 bool HandleEndOfTokenLexer(
Token &Result);
1811 void HandleDirective(
Token &Result);
1818 void CheckEndOfDirective(
const char *DirType,
bool EnableMacros =
false);
1833 Module *getCurrentModule();
1847 bool GetIncludeFilenameSpelling(
SourceLocation Loc,StringRef &Buffer);
1860 bool *IsMapped,
bool *IsFrameworkFound,
1861 bool SkipCache =
false);
1871 bool isInPrimaryFile()
const;
1893 bool CheckMacroName(
Token &MacroNameTok,
MacroUse isDefineUndef,
1894 bool *ShadowFlag =
nullptr);
1897 Module *LeaveSubmodule(
bool ForPragma);
1900 friend void TokenLexer::ExpandFunctionArguments();
1902 void PushIncludeMacroStack() {
1903 assert(CurLexerKind != CLK_CachingLexer &&
"cannot push a caching lexer");
1904 IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
1905 std::move(CurLexer), CurPPLexer,
1906 std::move(CurTokenLexer), CurDirLookup);
1907 CurPPLexer =
nullptr;
1910 void PopIncludeMacroStack() {
1911 CurLexer = std::move(IncludeMacroStack.back().TheLexer);
1912 CurPPLexer = IncludeMacroStack.back().ThePPLexer;
1913 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
1914 CurDirLookup = IncludeMacroStack.back().TheDirLookup;
1915 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
1916 CurLexerKind = IncludeMacroStack.back().CurLexerKind;
1917 IncludeMacroStack.pop_back();
1920 void PropagateLineStartLeadingSpaceInfo(
Token &Result);
1924 bool needModuleMacros()
const;
1928 void updateModuleMacroInfo(
const IdentifierInfo *II, ModuleMacroInfo &Info);
1947 bool *ShadowFlag =
nullptr);
1958 MacroInfo *ReadOptionalMacroParameterListAndBody(
1959 const Token &MacroNameTok,
bool ImmediatelyAfterHeaderGuard);
1977 bool FoundNonSkipPortion,
bool FoundElse,
1982 struct DirectiveEvalResult {
1987 bool IncludedUndefinedIds;
1997 DirectiveEvalResult EvaluateDirectiveExpression(
IdentifierInfo *&IfNDefMacro);
2001 void RegisterBuiltinPragmas();
2004 void RegisterBuiltinMacros();
2019 void removeCachedMacroExpandedTokensOfLastLexer();
2024 bool isNextPPTokenLParen();
2033 void ExpandBuiltinMacro(
Token &Tok);
2038 void Handle_Pragma(
Token &Tok);
2042 void HandleMicrosoft__pragma(
Token &Tok);
2049 void setPredefinesFileID(
FileID FID) {
2050 assert(PredefinesFileID.
isInvalid() &&
"PredefinesFileID already set!");
2051 PredefinesFileID = FID;
2055 void setPCHThroughHeaderFileID(
FileID FID);
2063 static bool IsFileLexer(
const IncludeStackInfo& I) {
2064 return IsFileLexer(I.TheLexer.get(), I.ThePPLexer);
2067 bool IsFileLexer()
const {
2068 return IsFileLexer(CurLexer.get(), CurPPLexer);
2073 void CachingLex(
Token &Result);
2075 bool InCachingLexMode()
const {
2078 return !CurPPLexer && !CurTokenLexer && !IncludeMacroStack.empty();
2081 void EnterCachingLexMode();
2083 void ExitCachingLexMode() {
2084 if (InCachingLexMode())
2085 RemoveTopOfLexerStack();
2088 const Token &PeekAhead(
unsigned N);
2089 void AnnotatePreviousCachedTokens(
const Token &Tok);
2095 void HandleLineDirective();
2096 void HandleDigitDirective(
Token &Tok);
2097 void HandleUserDiagnosticDirective(
Token &Tok,
bool isWarning);
2098 void HandleIdentSCCSDirective(
Token &Tok);
2099 void HandleMacroPublicDirective(
Token &Tok);
2100 void HandleMacroPrivateDirective();
2106 const FileEntry *LookupFromFile =
nullptr,
2107 bool isImport =
false);
2111 void HandleMicrosoftImportDirective(
Token &Tok);
2117 static bool checkModuleIsAvailable(
const LangOptions &LangOpts,
2143 return PreambleConditionalStack.isRecording();
2147 return PreambleConditionalStack.hasRecordedPreamble();
2151 return PreambleConditionalStack.getStack();
2155 PreambleConditionalStack.setStack(s);
2160 PreambleConditionalStack.startReplaying();
2161 PreambleConditionalStack.setStack(s);
2162 PreambleConditionalStack.SkipInfo = SkipInfo;
2166 return PreambleConditionalStack.SkipInfo;
2172 void replayPreambleConditionalStack();
2175 void HandleDefineDirective(
Token &Tok,
bool ImmediatelyAfterHeaderGuard);
2176 void HandleUndefDirective();
2179 void HandleIfdefDirective(
Token &Result,
const Token &HashToken,
2180 bool isIfndef,
bool ReadAnyTokensBeforeDirective);
2181 void HandleIfDirective(
Token &IfToken,
const Token &HashToken,
2182 bool ReadAnyTokensBeforeDirective);
2183 void HandleEndifDirective(
Token &EndifToken);
2184 void HandleElseDirective(
Token &Result,
const Token &HashToken);
2185 void HandleElifDirective(
Token &ElifToken,
const Token &HashToken);
2192 void HandlePragmaOnce(
Token &OnceTok);
2193 void HandlePragmaMark();
2194 void HandlePragmaPoison();
2195 void HandlePragmaSystemHeader(
Token &SysHeaderTok);
2196 void HandlePragmaDependency(
Token &DependencyTok);
2197 void HandlePragmaPushMacro(
Token &Tok);
2198 void HandlePragmaPopMacro(
Token &Tok);
2199 void HandlePragmaIncludeAlias(
Token &Tok);
2200 void HandlePragmaModuleBuild(
Token &Tok);
2201 void HandlePragmaHdrstop(
Token &Tok);
2229 #endif // LLVM_CLANG_LEX_PREPROCESSOR_H PreambleSkipInfo(SourceLocation HashTokenLoc, SourceLocation IfTokenLoc, bool FoundNonSkipPortion, bool FoundElse, SourceLocation ElseLoc)
CachedTokensTy::size_type End
A set of visible modules.
llvm::BumpPtrAllocator & getPreprocessorAllocator()
void setCodeCompletionTokenRange(const SourceLocation Start, const SourceLocation End)
Set the code completion token range for detecting replacement range later on.
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
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'...
const DefInfo findDirectiveAtLoc(SourceLocation L, const SourceManager &SM) const
Find macro definition active in the specified source location.
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)
SourceRange getCodeCompletionTokenRange() const
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)
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...
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)