15 #ifndef LLVM_CLANG_LEX_PREPROCESSOR_H 16 #define LLVM_CLANG_LEX_PREPROCESSOR_H 34 #include "llvm/ADT/ArrayRef.h" 35 #include "llvm/ADT/DenseMap.h" 36 #include "llvm/ADT/FoldingSet.h" 37 #include "llvm/ADT/None.h" 38 #include "llvm/ADT/Optional.h" 39 #include "llvm/ADT/PointerUnion.h" 40 #include "llvm/ADT/STLExtras.h" 41 #include "llvm/ADT/SmallPtrSet.h" 42 #include "llvm/ADT/SmallVector.h" 43 #include "llvm/ADT/StringRef.h" 44 #include "llvm/ADT/TinyPtrVector.h" 45 #include "llvm/ADT/iterator_range.h" 46 #include "llvm/Support/Allocator.h" 47 #include "llvm/Support/Casting.h" 48 #include "llvm/Support/Registry.h" 60 template<
unsigned InternalLen>
class SmallString;
66 class CodeCompletionHandler;
69 class DirectoryLookup;
70 class ExternalPreprocessorSource;
75 class MemoryBufferCache;
77 class PragmaNamespace;
78 class PreprocessingRecord;
79 class PreprocessorLexer;
80 class PreprocessorOptions;
92 assert(Kind != tok::raw_identifier &&
"Raw identifiers are not supported.");
93 assert(Kind != tok::identifier &&
94 "Identifiers should be created by TokenValue(IdentifierInfo *)");
102 return Tok.
getKind() == Kind &&
129 std::shared_ptr<PreprocessorOptions> PPOpts;
137 std::unique_ptr<ScratchBuffer> ScratchBuf;
146 llvm::BumpPtrAllocator BP;
180 unsigned CounterValue = 0;
184 MaxAllowedIncludeStackDepth = 200
188 bool KeepComments : 1;
189 bool KeepMacroComments : 1;
190 bool SuppressIncludeNotFoundError : 1;
193 bool InMacroArgs : 1;
196 bool OwnsHeaderSearch : 1;
199 bool DisableMacroExpansion : 1;
203 bool MacroExpansionInDirectivesOverride : 1;
208 mutable bool ReadMacrosFromExternalSource : 1;
211 bool PragmasEnabled : 1;
214 bool PreprocessedOutput : 1;
217 bool ParsingIfOrElifDirective;
220 bool InMacroArgPreExpansion;
242 std::unique_ptr<PragmaNamespace> PragmaHandlers;
246 std::unique_ptr<PragmaNamespace> PragmaHandlersBackup;
250 std::vector<CommentHandler *> CommentHandlers;
254 bool IncrementalProcessing =
false;
263 const FileEntry *CodeCompletionFile =
nullptr;
266 unsigned CodeCompletionOffset = 0;
286 bool LastTokenWasAt =
false;
290 bool ModuleImportExpectsIdentifier =
false;
301 bool CodeCompletionReached =
false;
320 std::pair<int, bool> SkipMainFilePreamble;
324 bool HasReachedMaxIncludeDepth =
false;
335 bool FoundNonSkipPortion,
bool FoundElse,
337 : HashTokenLoc(HashTokenLoc), IfTokenLoc(IfTokenLoc),
338 FoundNonSkipPortion(FoundNonSkipPortion), FoundElse(FoundElse),
346 class PreambleConditionalStackStore {
354 PreambleConditionalStackStore() =
default;
356 void startRecording() { ConditionalStackState = Recording; }
357 void startReplaying() { ConditionalStackState = Replaying; }
358 bool isRecording()
const {
return ConditionalStackState == Recording; }
359 bool isReplaying()
const {
return ConditionalStackState == Replaying; }
362 return ConditionalStack;
365 void doneReplaying() {
366 ConditionalStack.clear();
367 ConditionalStackState = Off;
371 if (!isRecording() && !isReplaying())
373 ConditionalStack.clear();
374 ConditionalStack.append(s.begin(), s.end());
377 bool hasRecordedPreamble()
const {
return !ConditionalStack.empty(); }
379 bool reachedEOFWhileSkipping()
const {
return SkipInfo.hasValue(); }
381 void clearSkipInfo() { SkipInfo.reset(); }
387 State ConditionalStackState = Off;
388 } PreambleConditionalStack;
394 std::unique_ptr<Lexer> CurLexer;
412 std::unique_ptr<TokenLexer> CurTokenLexer;
419 CLK_LexAfterModuleImport
420 } CurLexerKind = CLK_Lexer;
424 Module *CurLexerSubmodule =
nullptr;
429 struct IncludeStackInfo {
430 enum CurLexerKind CurLexerKind;
432 std::unique_ptr<Lexer> TheLexer;
434 std::unique_ptr<TokenLexer> TheTokenLexer;
439 IncludeStackInfo(
enum CurLexerKind CurLexerKind,
Module *TheSubmodule,
440 std::unique_ptr<Lexer> &&TheLexer,
442 std::unique_ptr<TokenLexer> &&TheTokenLexer,
444 : CurLexerKind(
std::move(CurLexerKind)),
445 TheSubmodule(
std::move(TheSubmodule)), TheLexer(
std::move(TheLexer)),
446 ThePPLexer(
std::move(ThePPLexer)),
447 TheTokenLexer(
std::move(TheTokenLexer)),
448 TheDirLookup(
std::move(TheDirLookup)) {}
450 std::vector<IncludeStackInfo> IncludeMacroStack;
454 std::unique_ptr<PPCallbacks> Callbacks;
456 struct MacroExpandsInfo {
462 : Tok(Tok), MD(MD), Range(Range) {}
467 struct ModuleMacroInfo {
472 llvm::TinyPtrVector<ModuleMacro *> ActiveModuleMacros;
476 unsigned ActiveModuleMacrosGeneration = 0;
479 bool IsAmbiguous =
false;
482 llvm::TinyPtrVector<ModuleMacro *> OverriddenMacros;
489 mutable llvm::PointerUnion<MacroDirective *, ModuleMacroInfo *>
State;
494 PP.updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
500 !PP.CurSubmoduleState->VisibleModules.getGeneration())
503 auto *Info = State.dyn_cast<ModuleMacroInfo*>();
510 if (PP.CurSubmoduleState->VisibleModules.getGeneration() !=
511 Info->ActiveModuleMacrosGeneration)
512 PP.updateModuleMacroInfo(II, *Info);
517 MacroState() : MacroState(nullptr) {}
520 MacroState(MacroState &&O) noexcept :
State(O.State) {
524 MacroState &operator=(MacroState &&O) noexcept {
532 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
533 Info->~ModuleMacroInfo();
537 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
543 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
550 auto *Info = getModuleInfo(PP, II);
551 return Info ? Info->IsAmbiguous :
false;
556 if (
auto *Info = getModuleInfo(PP, II))
557 return Info->ActiveModuleMacros;
564 if (
auto *Latest = getLatest())
565 return Latest->findDirectiveAtLoc(Loc, SourceMgr);
570 if (
auto *Info = getModuleInfo(PP, II)) {
571 Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
572 Info->ActiveModuleMacros.begin(),
573 Info->ActiveModuleMacros.end());
574 Info->ActiveModuleMacros.clear();
575 Info->IsAmbiguous =
false;
580 if (
auto *Info = State.dyn_cast<ModuleMacroInfo*>())
581 return Info->OverriddenMacros;
587 auto *Info = State.dyn_cast<ModuleMacroInfo*>();
589 if (Overrides.empty())
595 Info->OverriddenMacros.clear();
596 Info->OverriddenMacros.insert(Info->OverriddenMacros.end(),
597 Overrides.begin(), Overrides.end());
598 Info->ActiveModuleMacrosGeneration = 0;
607 using MacroMap = llvm::DenseMap<const IdentifierInfo *, MacroState>;
609 struct SubmoduleState;
612 struct BuildingSubmoduleInfo {
623 SubmoduleState *OuterSubmoduleState;
626 unsigned OuterPendingModuleMacroNames;
629 SubmoduleState *OuterSubmoduleState,
630 unsigned OuterPendingModuleMacroNames)
631 : M(M), ImportLoc(ImportLoc), IsPragma(IsPragma),
632 OuterSubmoduleState(OuterSubmoduleState),
633 OuterPendingModuleMacroNames(OuterPendingModuleMacroNames) {}
638 struct SubmoduleState {
648 std::map<Module *, SubmoduleState> Submodules;
651 SubmoduleState NullSubmoduleState;
655 SubmoduleState *CurSubmoduleState;
658 llvm::FoldingSet<ModuleMacro> ModuleMacros;
665 llvm::DenseMap<const IdentifierInfo *, llvm::TinyPtrVector<ModuleMacro *>>
677 using WarnUnusedMacroLocsTy = llvm::SmallPtrSet<SourceLocation, 32>;
678 WarnUnusedMacroLocsTy WarnUnusedMacroLocs;
686 llvm::DenseMap<IdentifierInfo *, std::vector<MacroInfo *>>
690 unsigned NumDirectives = 0;
691 unsigned NumDefined = 0;
692 unsigned NumUndefined = 0;
693 unsigned NumPragma = 0;
695 unsigned NumElse = 0;
696 unsigned NumEndif = 0;
697 unsigned NumEnteredSourceFiles = 0;
698 unsigned MaxIncludeStackDepth = 0;
699 unsigned NumMacroExpanded = 0;
700 unsigned NumFnMacroExpanded = 0;
701 unsigned NumBuiltinMacroExpanded = 0;
702 unsigned NumFastMacroExpanded = 0;
703 unsigned NumTokenPaste = 0;
704 unsigned NumFastTokenPaste = 0;
705 unsigned NumSkipped = 0;
709 std::string Predefines;
715 FileID PCHThroughHeaderFileID;
718 bool SkippingUntilPragmaHdrStop =
false;
721 bool SkippingUntilPCHThroughHeader =
false;
725 enum { TokenLexerCacheSize = 8 };
726 unsigned NumCachedTokenLexers;
727 std::unique_ptr<TokenLexer> TokenLexerCache[TokenLexerCacheSize];
736 std::vector<std::pair<TokenLexer *, size_t>> MacroExpandingLexersStack;
757 CachedTokensTy::size_type CachedLexPos = 0;
764 std::vector<CachedTokensTy::size_type> BacktrackPositions;
766 struct MacroInfoChain {
768 MacroInfoChain *Next;
773 MacroInfoChain *MIChainHead =
nullptr;
778 Preprocessor(std::shared_ptr<PreprocessorOptions> PPOpts,
783 bool OwnsHeaderSearch =
false,
803 void InitializeForModelFile();
806 void FinalizeForModelFile();
830 ExternalSource = Source;
834 return ExternalSource;
846 return ParsingIfOrElifDirective;
851 this->KeepComments = KeepComments | KeepMacroComments;
852 this->KeepMacroComments = KeepMacroComments;
861 SuppressIncludeNotFoundError = Suppress;
865 return SuppressIncludeNotFoundError;
871 PreprocessedOutput = IsPreprocessedOutput;
880 return CurPPLexer == L;
910 C = llvm::make_unique<PPChainedCallbacks>(std::move(C),
911 std::move(Callbacks));
912 Callbacks = std::move(C);
921 (!getLangOpts().Modules || (
bool)getMacroDefinition(II));
930 auto I = Submodules.find(M);
931 if (I == Submodules.end())
933 auto J = I->second.Macros.find(II);
934 if (J == I->second.Macros.end())
936 auto *MD = J->second.getLatest();
944 MacroState &S = CurSubmoduleState->Macros[II];
945 auto *MD = S.getLatest();
946 while (MD && isa<VisibilityMacroDirective>(MD))
949 S.getActiveModuleMacros(*
this, II),
950 S.isAmbiguous(*
this, II));
958 MacroState &S = CurSubmoduleState->Macros[II];
960 if (
auto *MD = S.getLatest())
964 S.getActiveModuleMacros(*
this, II),
965 S.isAmbiguous(*
this, II));
974 auto *MD = getLocalMacroDirectiveHistory(II);
982 return const_cast<Preprocessor*
>(
this)->getMacroInfo(II);
988 if (
auto MD = getMacroDefinition(II))
1005 appendMacroDirective(II, MD);
1025 updateOutOfDateIdentifier(const_cast<IdentifierInfo&>(*II));
1026 auto I = LeafModuleMacros.find(II);
1027 if (I != LeafModuleMacros.end())
1038 macro_iterator macro_begin(
bool IncludeExternalMacros =
true)
const;
1039 macro_iterator macro_end(
bool IncludeExternalMacros =
true)
const;
1041 llvm::iterator_range<macro_iterator>
1042 macros(
bool IncludeExternalMacros =
true)
const {
1045 return llvm::make_range(begin, end);
1067 return &Identifiers.
get(Name);
1074 void AddPragmaHandler(StringRef Namespace,
PragmaHandler *Handler);
1076 AddPragmaHandler(StringRef(), Handler);
1084 void RemovePragmaHandler(StringRef Namespace,
PragmaHandler *Handler);
1086 RemovePragmaHandler(StringRef(), Handler);
1090 void IgnorePragmas();
1102 CodeComplete = &Handler;
1107 return CodeComplete;
1112 CodeComplete =
nullptr;
1117 void CodeCompleteIncludedFile(llvm::StringRef Dir,
bool IsAngled);
1121 void CodeCompleteNaturalLanguage();
1125 CodeCompletionII =
Filter;
1132 CodeCompletionTokenRange = {Start, End};
1135 return CodeCompletionTokenRange;
1140 if (CodeCompletionII)
1141 return CodeCompletionII->
getName();
1151 void createPreprocessingRecord();
1154 bool isPCHThroughHeader(
const FileEntry *FE);
1157 bool creatingPCHWithThroughHeader();
1160 bool usingPCHWithThroughHeader();
1163 bool creatingPCHWithPragmaHdrStop();
1166 bool usingPCHWithPragmaHdrStop();
1170 void SkipTokensWhileUsingPCH();
1174 void HandleSkippedDirectiveWhileUsingPCH(
Token &Result,
1179 void EnterMainSourceFile();
1182 void EndSourceFile();
1212 void EnterTokenStream(
const Token *Toks,
unsigned NumToks,
1213 bool DisableMacroExpansion,
bool OwnsTokens);
1217 bool DisableMacroExpansion) {
1218 EnterTokenStream(Toks.release(), NumToks, DisableMacroExpansion,
true);
1222 EnterTokenStream(Toks.data(), Toks.size(), DisableMacroExpansion,
false);
1229 void RemoveTopOfLexerStack();
1244 void EnableBacktrackAtThisPos();
1247 void CommitBacktrackedTokens();
1276 void Lex(
Token &Result);
1278 void LexAfterModuleImport(
Token &Result);
1283 return CurSubmoduleState->VisibleModules.getImportLoc(M);
1290 const char *DiagnosticTag,
bool AllowMacroExpansion) {
1291 if (AllowMacroExpansion)
1294 LexUnexpandedToken(Result);
1295 return FinishLexStringLiteral(Result, String, DiagnosticTag,
1296 AllowMacroExpansion);
1301 bool FinishLexStringLiteral(
Token &Result, std::string &String,
1302 const char *DiagnosticTag,
1303 bool AllowMacroExpansion);
1313 while (Result.
getKind() == tok::comment);
1319 bool OldVal = DisableMacroExpansion;
1320 DisableMacroExpansion =
true;
1325 DisableMacroExpansion = OldVal;
1332 LexUnexpandedToken(Result);
1333 while (Result.
getKind() == tok::comment);
1339 bool parseSimpleIntegerLiteral(
Token &Tok, uint64_t &
Value);
1343 DisableMacroExpansion =
true;
1344 MacroExpansionInDirectivesOverride =
true;
1355 if (CachedLexPos + N < CachedTokens.size())
1356 return CachedTokens[CachedLexPos+N];
1358 return PeekAhead(N+1);
1367 assert(isBacktrackEnabled() &&
1368 "Should only be called when tokens are cached for backtracking");
1369 assert(
signed(CachedLexPos) -
signed(N) >=
signed(BacktrackPositions.back())
1370 &&
"Should revert tokens up to the last backtrack position, not more");
1371 assert(
signed(CachedLexPos) -
signed(N) >= 0 &&
1372 "Corrupted backtrack positions ?");
1381 EnterCachingLexMode();
1382 CachedTokens.insert(CachedTokens.begin()+CachedLexPos,
Tok);
1394 assert(Tok.
isAnnotation() &&
"Expected annotation token");
1395 if (CachedLexPos != 0 && isBacktrackEnabled())
1396 AnnotatePreviousCachedTokens(Tok);
1402 assert(CachedLexPos != 0);
1403 return CachedTokens[CachedLexPos-1].getLastLoc();
1408 bool IsPreviousCachedToken(
const Token &Tok)
const;
1426 assert(Tok.
isAnnotation() &&
"Expected annotation token");
1427 if (CachedLexPos != 0 && isBacktrackEnabled())
1428 CachedTokens[CachedLexPos-1] = Tok;
1433 void *AnnotationVal);
1439 if (CachedLexPos != 0 && isBacktrackEnabled())
1440 CachedTokens[CachedLexPos-1] = Tok;
1445 void recomputeCurLexerKind();
1452 IncrementalProcessing = value;
1469 bool SetCodeCompletionPoint(
const FileEntry *File,
1470 unsigned Line,
unsigned Column);
1486 return CodeCompletionFileLoc;
1495 assert(isCodeCompletionEnabled() &&
"Code-completion not enabled!");
1496 CodeCompletionReached =
true;
1498 getDiagnostics().setSuppressAllDiagnostics(
true);
1506 return PragmaARCCFCodeAuditedLoc;
1512 PragmaARCCFCodeAuditedLoc = Loc;
1520 return PragmaAssumeNonNullLoc;
1526 PragmaAssumeNonNullLoc = Loc;
1542 SkipMainFilePreamble.first = Bytes;
1543 SkipMainFilePreamble.second = StartOfLine;
1550 return Diags->
Report(Loc, DiagID);
1566 bool *invalid =
nullptr)
const {
1567 return Lexer::getSpelling(loc, buffer, SourceMgr, LangOpts, invalid);
1579 return Lexer::getSpelling(Tok, SourceMgr, LangOpts, Invalid);
1595 bool *Invalid =
nullptr)
const {
1596 return Lexer::getSpelling(Tok, Buffer, SourceMgr, LangOpts, Invalid);
1603 StringRef getSpelling(
const Token &Tok,
1605 bool *Invalid =
nullptr)
const;
1610 bool IgnoreWhiteSpace =
false) {
1611 return Lexer::getRawToken(Loc, Result, SourceMgr, LangOpts, IgnoreWhiteSpace);
1618 bool *Invalid =
nullptr)
const {
1619 assert(Tok.
is(tok::numeric_constant) &&
1620 Tok.
getLength() == 1 &&
"Called on unsupported token");
1621 assert(!Tok.
needsCleaning() &&
"Token can't need cleaning with length 1");
1641 return Lexer::getImmediateMacroName(Loc, SourceMgr, getLangOpts());
1649 void CreateString(StringRef Str,
Token &Tok,
1674 return Lexer::getLocForEndOfToken(Loc,
Offset, SourceMgr, LangOpts);
1684 return Lexer::isAtStartOfMacroExpansion(loc, SourceMgr, LangOpts,
1695 return Lexer::isAtEndOfMacroExpansion(loc, SourceMgr, LangOpts, MacroEnd);
1699 void DumpToken(
const Token &Tok,
bool DumpFlags =
false)
const;
1701 void DumpMacro(
const MacroInfo &MI)
const;
1707 unsigned Char)
const {
1708 return Lexer::AdvanceToTokenCharacter(TokStart, Char, SourceMgr, LangOpts);
1717 ++NumFastTokenPaste;
1724 size_t getTotalMemory()
const;
1729 void HandleMicrosoftCommentPaste(
Token &Tok);
1741 llvm::DenseMap<IdentifierInfo*,unsigned> PoisonReasons;
1751 void HandlePoisonedIdentifier(
Token & Identifier);
1756 HandlePoisonedIdentifier(Identifier);
1766 *Ident___exception_code,
1767 *Ident_GetExceptionCode;
1770 *Ident___exception_info,
1771 *Ident_GetExceptionInfo;
1774 *Ident___abnormal_termination,
1775 *Ident_AbnormalTermination;
1777 const char *getCurLexerEndPos();
1778 void diagnoseMissingHeaderInUmbrellaDir(
const Module &Mod);
1781 void PoisonSEHIdentifiers(
bool Poison =
true);
1791 bool HandleIdentifier(
Token &Identifier);
1798 bool HandleEndOfFile(
Token &Result,
bool isEndOfMacro =
false);
1802 bool HandleEndOfTokenLexer(
Token &Result);
1809 void HandleDirective(
Token &Result);
1816 void CheckEndOfDirective(
const char *DirType,
bool EnableMacros =
false);
1820 void DiscardUntilEndOfDirective();
1831 Module *getCurrentModule();
1845 bool GetIncludeFilenameSpelling(
SourceLocation Loc,StringRef &Buffer);
1858 bool *IsMapped,
bool SkipCache =
false);
1868 bool isInPrimaryFile()
const;
1890 bool CheckMacroName(
Token &MacroNameTok,
MacroUse isDefineUndef,
1891 bool *ShadowFlag =
nullptr);
1894 Module *LeaveSubmodule(
bool ForPragma);
1897 friend void TokenLexer::ExpandFunctionArguments();
1899 void PushIncludeMacroStack() {
1900 assert(CurLexerKind != CLK_CachingLexer &&
"cannot push a caching lexer");
1901 IncludeMacroStack.emplace_back(CurLexerKind, CurLexerSubmodule,
1902 std::move(CurLexer), CurPPLexer,
1903 std::move(CurTokenLexer), CurDirLookup);
1904 CurPPLexer =
nullptr;
1907 void PopIncludeMacroStack() {
1908 CurLexer = std::move(IncludeMacroStack.back().TheLexer);
1909 CurPPLexer = IncludeMacroStack.back().ThePPLexer;
1910 CurTokenLexer = std::move(IncludeMacroStack.back().TheTokenLexer);
1911 CurDirLookup = IncludeMacroStack.back().TheDirLookup;
1912 CurLexerSubmodule = IncludeMacroStack.back().TheSubmodule;
1913 CurLexerKind = IncludeMacroStack.back().CurLexerKind;
1914 IncludeMacroStack.pop_back();
1917 void PropagateLineStartLeadingSpaceInfo(
Token &Result);
1921 bool needModuleMacros()
const;
1925 void updateModuleMacroInfo(
const IdentifierInfo *II, ModuleMacroInfo &Info);
1944 bool *ShadowFlag =
nullptr);
1955 MacroInfo *ReadOptionalMacroParameterListAndBody(
1956 const Token &MacroNameTok,
bool ImmediatelyAfterHeaderGuard);
1974 bool FoundNonSkipPortion,
bool FoundElse,
1979 struct DirectiveEvalResult {
1984 bool IncludedUndefinedIds;
1991 DirectiveEvalResult EvaluateDirectiveExpression(
IdentifierInfo *&IfNDefMacro);
1995 void RegisterBuiltinPragmas();
1998 void RegisterBuiltinMacros();
2013 void removeCachedMacroExpandedTokensOfLastLexer();
2018 bool isNextPPTokenLParen();
2027 void ExpandBuiltinMacro(
Token &Tok);
2032 void Handle_Pragma(
Token &Tok);
2036 void HandleMicrosoft__pragma(
Token &Tok);
2043 void setPredefinesFileID(
FileID FID) {
2044 assert(PredefinesFileID.
isInvalid() &&
"PredefinesFileID already set!");
2045 PredefinesFileID = FID;
2049 void setPCHThroughHeaderFileID(
FileID FID);
2057 static bool IsFileLexer(
const IncludeStackInfo& I) {
2058 return IsFileLexer(I.TheLexer.get(), I.ThePPLexer);
2061 bool IsFileLexer()
const {
2062 return IsFileLexer(CurLexer.get(), CurPPLexer);
2067 void CachingLex(
Token &Result);
2069 bool InCachingLexMode()
const {
2072 return !CurPPLexer && !CurTokenLexer && !IncludeMacroStack.empty();
2075 void EnterCachingLexMode();
2077 void ExitCachingLexMode() {
2078 if (InCachingLexMode())
2079 RemoveTopOfLexerStack();
2082 const Token &PeekAhead(
unsigned N);
2083 void AnnotatePreviousCachedTokens(
const Token &Tok);
2089 void HandleLineDirective();
2090 void HandleDigitDirective(
Token &Tok);
2091 void HandleUserDiagnosticDirective(
Token &Tok,
bool isWarning);
2092 void HandleIdentSCCSDirective(
Token &Tok);
2093 void HandleMacroPublicDirective(
Token &Tok);
2094 void HandleMacroPrivateDirective();
2100 const FileEntry *LookupFromFile =
nullptr,
2101 bool isImport =
false);
2105 void HandleMicrosoftImportDirective(
Token &Tok);
2111 static bool checkModuleIsAvailable(
const LangOptions &LangOpts,
2137 return PreambleConditionalStack.isRecording();
2141 return PreambleConditionalStack.hasRecordedPreamble();
2145 return PreambleConditionalStack.getStack();
2149 PreambleConditionalStack.setStack(s);
2154 PreambleConditionalStack.startReplaying();
2155 PreambleConditionalStack.setStack(s);
2156 PreambleConditionalStack.SkipInfo = SkipInfo;
2160 return PreambleConditionalStack.SkipInfo;
2166 void replayPreambleConditionalStack();
2169 void HandleDefineDirective(
Token &Tok,
bool ImmediatelyAfterHeaderGuard);
2170 void HandleUndefDirective();
2173 void HandleIfdefDirective(
Token &Result,
const Token &HashToken,
2174 bool isIfndef,
bool ReadAnyTokensBeforeDirective);
2175 void HandleIfDirective(
Token &IfToken,
const Token &HashToken,
2176 bool ReadAnyTokensBeforeDirective);
2177 void HandleEndifDirective(
Token &EndifToken);
2178 void HandleElseDirective(
Token &Result,
const Token &HashToken);
2179 void HandleElifDirective(
Token &ElifToken,
const Token &HashToken);
2186 void HandlePragmaOnce(
Token &OnceTok);
2187 void HandlePragmaMark();
2188 void HandlePragmaPoison();
2189 void HandlePragmaSystemHeader(
Token &SysHeaderTok);
2190 void HandlePragmaDependency(
Token &DependencyTok);
2191 void HandlePragmaPushMacro(
Token &Tok);
2192 void HandlePragmaPopMacro(
Token &Tok);
2193 void HandlePragmaIncludeAlias(
Token &Tok);
2194 void HandlePragmaModuleBuild(
Token &Tok);
2195 void HandlePragmaHdrstop(
Token &Tok);
2223 #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)