Lines Matching +full:docs +full:- +full:clang +full:- +full:man

1 //===--- PPDirectives.cpp - Directive Handling for Preprocessor -----------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
14 #include "clang/Basic/AttributeCommonInfo.h"
15 #include "clang/Basic/Attributes.h"
16 #include "clang/Basic/CharInfo.h"
17 #include "clang/Basic/DirectoryEntry.h"
18 #include "clang/Basic/FileManager.h"
19 #include "clang/Basic/IdentifierTable.h"
20 #include "clang/Basic/LangOptions.h"
21 #include "clang/Basic/Module.h"
22 #include "clang/Basic/SourceLocation.h"
23 #include "clang/Basic/SourceManager.h"
24 #include "clang/Basic/TargetInfo.h"
25 #include "clang/Basic/TokenKinds.h"
26 #include "clang/Lex/CodeCompletionHandler.h"
27 #include "clang/Lex/HeaderSearch.h"
28 #include "clang/Lex/LexDiagnostic.h"
29 #include "clang/Lex/LiteralSupport.h"
30 #include "clang/Lex/MacroInfo.h"
31 #include "clang/Lex/ModuleLoader.h"
32 #include "clang/Lex/ModuleMap.h"
33 #include "clang/Lex/PPCallbacks.h"
34 #include "clang/Lex/Pragma.h"
35 #include "clang/Lex/Preprocessor.h"
36 #include "clang/Lex/PreprocessorOptions.h"
37 #include "clang/Lex/Token.h"
38 #include "clang/Lex/VariadicMacroSupport.h"
56 using namespace clang;
58 //===----------------------------------------------------------------------===//
60 //===----------------------------------------------------------------------===//
117 // * https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc-160
118 // * man 7 feature_test_macros
160 if (MI->isBuiltinMacro())
163 if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc()))
172 // C++ defines various feature-test macros starting with __cpp
175 // Anything else isn't language-defined
197 StringRef Text = II->getName();
198 if (isReservedInAllContexts(II->isReserved(Lang)))
200 if (II->isKeyword(Lang))
212 if (isReservedInAllContexts(II->isReserved(Lang)))
227 if (::llvm::sys::path::begin(Include)->equals_insensitive("boost"))
244 Ch += 'a' - 'A';
308 // We need to check if `Candidates` has the exact case-insensitive string
320 size_t MaxDist = Length < 3 ? Length - 1 : Length / 3;
329 } else if (CurDist < SimilarStr->second) {
337 return SimilarStr->first;
353 if (II->isCPlusPlusOperatorKeyword()) {
364 if ((isDefineUndef != MU_Other) && II->getPPKeywordID() == tok::pp_defined) {
375 (SourceMgr.getBufferName(MacroNameLoc) != "<built-in>")) {
393 << II->getName();
416 CodeComplete->CodeCompleteMacroName(isDefineUndef == MU_Define);
451 while (Tmp.is(tok::comment)) // Skip comments in -C mode.
457 // Add a fixit in GNU/C99/C++ mode. Don't offer a fixit for strict-C89,
458 // or if this is a macro-style preprocessing directive, because it is more
471 // If this is a `.S` file, treat unknown # directives as non-preprocessor
494 /// SkipExcludedConditionalBlock - We just read a \#if or related directive and
527 CurPPLexer->pushConditionalLevel(IfTokenLoc, /*isSkipping*/ false,
532 CurPPLexer->LexingRawMode = true;
537 /// range if the same block is re-visited.
552 BeginPtr = PP.CurLexer->getBufferLocation();
555 PP.CurLexer->seek(PP.CurLexer->getCurrentBufferOffset() + *SkipRangePtr,
563 assert(PP.CurLexer->isDependencyDirectivesLexer());
569 *SkipRangePtr = Hashptr - BeginPtr;
571 assert(*SkipRangePtr == unsigned(Hashptr - BeginPtr));
578 if (CurLexer->isDependencyDirectivesLexer()) {
579 CurLexer->LexDependencyDirectiveTokenWhileSkipping(Tok);
583 CurLexer->Lex(Tok);
588 CodeComplete->CodeCompleteInConditionalExclusion();
617 CurPPLexer->ParsingPreprocessorDirective = true;
618 if (CurLexer) CurLexer->SetKeepWhitespaceMode(false);
621 const char *Hashptr = CurLexer->getBufferLocation() - Tok.getLength();
622 assert(CurLexer->getSourceLocation(Hashptr) == Tok.getLocation());
630 CurPPLexer->ParsingPreprocessorDirective = false;
632 if (CurLexer) CurLexer->resetExtendedTokenMode();
646 CurPPLexer->ParsingPreprocessorDirective = false;
648 if (CurLexer) CurLexer->resetExtendedTokenMode();
663 CurPPLexer->ParsingPreprocessorDirective = false;
665 if (CurLexer) CurLexer->resetExtendedTokenMode();
680 CurPPLexer->pushConditionalLevel(Tok.getLocation(), /*wasskipping*/true,
691 bool InCond = CurPPLexer->popConditionalLevel(CondInfo);
692 (void)InCond; // Silence warning in no-asserts mode.
700 CurPPLexer->LexingRawMode = false;
702 CurPPLexer->LexingRawMode = true;
704 Callbacks->Endif(Tok.getLocation(), CondInfo.IfLoc);
712 // as a non-skipping conditional.
713 PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel();
731 CurPPLexer->LexingRawMode = false;
733 CurPPLexer->LexingRawMode = true;
735 Callbacks->Else(Tok.getLocation(), CondInfo.IfLoc);
741 PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel();
754 // condition to verify that it is well-formed. The current state
761 assert(CurPPLexer->LexingRawMode && "We have to be skipping here!");
762 CurPPLexer->LexingRawMode = false;
769 CurPPLexer->LexingRawMode = true;
771 Callbacks->Elif(
785 PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel();
811 // condition to verify that it is well-formed. The current state
818 assert(CurPPLexer->LexingRawMode && "We have to be skipping here!");
819 CurPPLexer->LexingRawMode = false;
822 CurPPLexer->LexingRawMode = true;
842 Callbacks->Elifdef(DirectiveToken.getLocation(), MacroNameTok,
845 Callbacks->Elifndef(DirectiveToken.getLocation(), MacroNameTok,
862 CurPPLexer->ParsingPreprocessorDirective = false;
864 if (CurLexer) CurLexer->resetExtendedTokenMode();
870 CurPPLexer->LexingRawMode = false;
875 Callbacks->SourceRangeSkipped(
878 : CurPPLexer->getSourceLocation()),
910 // until we hit a non-textual header that we can #include. (We assume textual
911 // headers of a module with non-textual headers aren't meant to be used to
922 HeaderInfo.hasModuleMap(FE->getName(), /*Root*/ nullptr,
929 // FIXME: If there's a public header in some module that re-exports it,
941 // include-guarded.
951 // If this is an accessible, non-textual header of M's top-level module
992 FileID FID = getCurrentFileLexer()->getFileID();
1001 // from the -include command line argument) from the current working
1015 BuildSystemModule = getCurrentModule()->IsSystem;
1022 Includers.push_back(std::make_pair(*FileEnt, FileEnt->getDir()));
1027 // See: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx
1031 if ((FileEnt = ISEntry.ThePPLexer->getFileEntry()))
1032 Includers.push_back(std::make_pair(*FileEnt, FileEnt->getDir()));
1052 if (&FE->getFileEntry() == FromFile) {
1074 if ((CurFileEnt = CurPPLexer->getFileEntry())) {
1085 if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
1102 FileManager &FM = this->getFileManager();
1125 // Non-angled lookup
1128 // Use file-based lookup.
1129 StringRef FullFileDir = LookupFromFile->tryGetRealPathName();
1157 for (const auto &Entry : PPOpts->EmbedEntries) {
1169 //===----------------------------------------------------------------------===//
1171 //===----------------------------------------------------------------------===//
1176 : PP(pp), save(pp->DisableMacroExpansion) {
1177 if (pp->MacroExpansionInDirectivesOverride)
1178 pp->DisableMacroExpansion = false;
1182 PP->DisableMacroExpansion = save;
1199 if (II->getPPKeywordID() == tok::pp_define) {
1204 II->getPPKeywordID() == tok::pp_include) {
1207 if (SkippingUntilPragmaHdrStop && II->getPPKeywordID() == tok::pp_pragma) {
1210 if (II && II->getName() == "hdrstop")
1217 /// HandleDirective - This callback is invoked when the lexer sees a # token
1227 CurPPLexer->ParsingPreprocessorDirective = true;
1228 if (CurLexer) CurLexer->SetKeepWhitespaceMode(false);
1231 CurPPLexer->MIOpt.getImmediatelyAfterTopLevelIfndef();
1232 CurPPLexer->MIOpt.resetImmediatelyAfterTopLevelIfndef();
1236 // We are about to read a token. For the multiple-include optimization FA to
1238 // pp-directive.
1239 bool ReadAnyTokensBeforeDirective =CurPPLexer->MIOpt.getHasReadAnyTokensVal();
1254 // not support this for #include-like directives, since that can result in
1258 switch (II->getPPKeywordID()) {
1265 Diag(Result, diag::err_embedded_directive) << II->getName();
1267 << ArgMacro->getIdentifierInfo();
1286 // Ignore the null directive with regards to the multiple-include
1288 // include guard and still enable the multiple-include optimization.
1289 CurPPLexer->MIOpt.SetReadToken(ReadAnyTokensBeforeDirective);
1294 CodeComplete->CodeCompleteDirective(
1295 CurPPLexer->getConditionalStackDepth() > 0);
1310 switch (II->getPPKeywordID()) {
1312 // C99 6.10.1 - Conditional Inclusion.
1324 return HandleElifFamilyDirective(Result, SavedHash, II->getPPKeywordID());
1331 // C99 6.10.2 - Source File Inclusion.
1336 // Handle -imacros.
1339 // C99 6.10.3 - Macro Replacement.
1345 // C99 6.10.4 - Line Control.
1349 // C99 6.10.5 - Error Directive.
1353 // C99 6.10.6 - Pragma Directive.
1382 ? *getCurrentFileLexer()->getFileEntry()
1404 // If this is a .S file, treat unknown # directives as non-preprocessor
1406 // various pseudo-ops. Just return the # token and push back the following
1419 // Enter this token stream so that we re-lex the tokens. Make sure to
1436 /// GetLineValue - Convert a numeric token into an unsigned value, emitting
1457 // Verify that we have a simple digit-sequence, and compute the value. This
1463 // Optional separating single quotes in a digit-sequence are ignored
1474 unsigned NextVal = Val*10+(DigitTokBegin[i]-'0');
1494 /// # line digit-sequence
1495 /// # line digit-sequence "s-char-sequence"
1521 int FilenameID = -1;
1560 // file. This is visible in GCC's pre-processed output, which rewrites #line
1569 Callbacks->FileChanged(CurPPLexer->getSourceLocation(),
1573 /// ReadLineMarkerFlags - Parse and validate any flags at the end of a GNU line
1652 /// HandleDigitDirective - Handle a GNU line marker directive, whose syntax is
1661 // line # limit other than it fit in 32-bits.
1671 int FilenameID = -1;
1710 // FilenameID as -1 in that case.
1720 // change. This is used so that the line marker comes out in -E mode for
1729 Callbacks->FileChanged(CurPPLexer->getSourceLocation(), Reason, FileKind);
1733 /// HandleUserDiagnosticDirective - Handle a #warning or #error directive.
1743 CurLexer->ReadToEndOfLine(&Message);
1745 // Find the first non-whitespace character, so that we can make the
1755 /// HandleIdentSCCSDirective - Handle a #ident/#sccs directive.
1787 Callbacks->Ident(Tok.getLocation(), Str);
1845 //===----------------------------------------------------------------------===//
1847 //===----------------------------------------------------------------------===//
1849 /// GetIncludeFilenameSpelling - Turn the specified lexer token into a fully
1863 // If `"`, `'`, `\`, `/*`, or `//` appears in a header-name, then
1865 // in C++: program is conditionally-supported with implementation-defined
1898 Buffer = Buffer.substr(1, Buffer.size()-2);
1927 PathString += Path[I].first->getName();
1931 switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) {
1957 // path to the file, build a properly-cased replacement in the vector,
1972 // Below is a best-effort to handle ".." in paths. It is admittedly
1979 --Cnt;
1983 // If these non-separator path components differ by more than just case,
1987 RealPathComponentIter->equals_insensitive(Component);
2014 Diags.Report(ShadowingModule->DefinitionLoc,
2045 if (auto FE = CurPPLexer->getFileEntry())
2062 /// HandleIncludeDirective - The "\#include" tokens have just been read, read
2084 // this falls into the category of "#include pp-tokens new-line" specified
2087 CheckEndOfDirective(IncludeTok.getIdentifierInfo()->getNameStart(), true);
2112 CurLexer->cutOffLexing();
2149 if (Callbacks && Callbacks->FileNotFound(Filename))
2174 // Check for likely typos due to leading or trailing non-isAlphanumeric
2179 // trailing non-isAlphanumeric characters.
2226 << CacheEntry.Directory->getName();
2232 /// Handle either a #include-like directive or an import declaration that names
2238 /// \param FilenameTok The header-name token.
2275 // Complain about attempts to #include files in an assume-nonnull pragma.
2305 // Normalize slashes when compiling with -fms-extensions on non-Windows. This
2322 if (File && isPCHThroughHeader(&File->getFileEntry()))
2328 // known to have no effect beyond its effect on module visibility -- that is,
2333 // [cpp.include]/7 If the header identified by the header-name denotes an
2334 // importable header, it is implementation-defined whether the #include
2344 if (PPOpts->SingleFileParseMode)
2354 // FIXME: We do not have a good way to disambiguate C++ clang modules from
2355 // C++ standard modules (other than use/non-use of Header Units).
2360 !ModuleToImport->isForBuilding(getLangOpts());
2365 ModuleToImport->isHeaderUnit()) {
2369 // This is a Header Unit that we do not include-translate
2373 // Maybe a usable clang header module.
2376 ModuleToImport && !ModuleToImport->isHeaderUnit();
2390 << ModuleToImport->getTopLevelModuleName();
2398 for (Module *Mod = ModuleToImport; Mod; Mod = Mod->Parent)
2399 Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name),
2421 static_cast<Module *>(Imported)->getTopLevelModule());
2437 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
2438 CurLexer->cutOffLexing();
2452 // If this is a '#import' or an import-declaration, don't re-enter the file.
2459 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import;
2471 // clang modules:
2491 SourceMgr.isMainFile(File->getFileEntry())) {
2499 // FIXME: Use a different callback for a pp-import?
2500 Callbacks->InclusionDirective(HashLoc, IncludeTok, LookupFilename, isAngled,
2505 Callbacks->FileSkipped(*File, FilenameTok, FileCharacter);
2511 // If this is a C++20 pp-import declaration, diagnose if we didn't find any
2515 << OriginalFilename << File->getName();
2522 !IsMapped && !File->getFileEntry().tryGetRealPathName().empty();
2533 StringRef RealPathName = File->getFileEntry().tryGetRealPathName();
2537 // -Wnonportable-include-path is designed to diagnose includes using
2538 // case even on systems with a case-insensitive file system.
2539 // On Windows, RealPathName always starts with an upper-case drive
2542 // ("foo" will always have on-disk case, no matter which case was
2545 // with upper- or lower-case drive letters, always consider the
2574 // clang currently cannot process absolute paths in #include lines that
2591 assert(IsSep(NameWithoriginalSlashes[Path.size()-1]));
2593 Path.push_back(NameWithoriginalSlashes[Path.size()-1]);
2595 IsSep(NameWithoriginalSlashes[Path.size()-1]));
2633 if (IncludeTok.getIdentifierInfo()->getPPKeywordID() ==
2645 if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) {
2674 if (ModuleToImport && !ModuleToImport->isHeaderUnit()) {
2675 if (ModuleToImport->getTopLevelModule()->ShadowingModule) {
2678 Diag(ModuleToImport->DefinitionLoc,
2680 << ModuleToImport->getFullModuleName();
2681 Diag(ModuleToImport->getTopLevelModule()->ShadowingModule->DefinitionLoc,
2685 // When building a pch, -fmodule-name tells the compiler to textually
2694 ModuleToImport->isForBuilding(getLangOpts()))
2715 /// HandleIncludeNextDirective - Implements \#include_next.
2729 /// HandleMicrosoftImportDirective - Implements \#import for Microsoft Mode
2732 // files from it, and includes those. This is beyond the scope of what clang
2743 /// HandleImportDirective - Implements \#import.
2755 /// HandleIncludeMacrosDirective - The -imacros command line option turns into a
2764 if (SourceMgr.getBufferName(Loc) != "<built-in>") {
2778 assert(TmpTok.isNot(tok::eof) && "Didn't find end of -imacros!");
2782 //===----------------------------------------------------------------------===//
2784 //===----------------------------------------------------------------------===//
2786 /// ReadMacroParameterList - The ( starting a parameter list of a macro
2803 case tok::ellipsis: // #define X(... -> C99 varargs
2822 MI->setIsC99Varargs();
2823 MI->setParameterList(Parameters, BP);
2856 MI->setParameterList(Parameters, BP);
2860 case tok::ellipsis: // #define X(A... -> GCC extension
2871 MI->setIsGNUVarargs();
2872 MI->setParameterList(Parameters, BP);
2881 if (MI->getNumTokens() == 1) {
2882 const Token &Value = MI->getReplacementToken(0);
2893 StringRef MacroText = MacroName.getIdentifierInfo()->getName();
2895 if (!II->isKeyword(LOptions))
2897 StringRef ValueText = II->getName();
2918 MI->getNumTokens() == 0;
2921 // ReadOptionalMacroParameterListAndBody - This consumes all (i.e. the
2924 // - # (stringization) is followed by a macro parameter
2942 if (CurLexer->ParsingPreprocessorDirective)
2946 // Used to un-poison and then re-poison identifiers of the __VA_ARGS__ ilk
2950 // If this is a function-like macro definition, parse the argument list,
2956 CurPPLexer->MIOpt.SetDefinedMacro(MacroNameTok.getIdentifierInfo(),
2965 // This is a function-like macro definition. Read the argument list.
2966 MI->setIsFunctionLike();
2970 // If this is a definition of an ISO C/C++ variadic function-like macro (not
2972 // which un-poisons and re-poisons certain identifiers (e.g. __VA_ARGS__)
2975 if (MI->isC99Varargs()) {
2986 // C90 6.8 TC1 says: "In the definition of an object-like macro, if the
2988 // subclause 5.2.1, then there shall be white-space separation between the
2990 // "A-Za-z0-9!"#%&'()*+,_./:;<=>?[\]^_{|}~" as well as whitespace, which
3013 if (MI->isObjectLike()) {
3014 // Object-like macros are very simple, just read their body.
3022 // Otherwise, read the body of a function-like macro. While we are at it,
3024 // parameters in function-like macro expansions.
3060 if (Tokens[Tokens.size() - 2].is(tok::hashhash)) {
3074 // If we're in -traditional mode, then we should ignore stringification
3100 Tokens[Tokens.size() - 1].is(tok::comma))
3101 MI->setHasCommaPasting();
3115 MI->getParameterNum(Tok.getIdentifierInfo()) == -1)) {
3117 // If this is assembler-with-cpp mode, we accept random gibberish after
3154 MI->setDefinitionEndLoc(LastTok.getLocation());
3156 MI->setTokens(Tokens, BP);
3161 return II->isStr("__strong") || II->isStr("__weak") ||
3162 II->isStr("__unsafe_unretained") || II->isStr("__autoreleasing");
3165 /// HandleDefineDirective - Implements \#define. This consumes the entire macro
3182 if (!II->hasMacroDefinition() && II->hadMacroDefinition() && II->isFinal())
3187 if (CurLexer) CurLexer->SetCommentRetentionState(KeepMacroComments);
3200 unsigned NumTokens = MI->getNumTokens();
3202 if (MI->getReplacementToken(0).is(tok::hashhash)) {
3203 Diag(MI->getReplacementToken(0), diag::err_paste_at_start);
3206 if (MI->getReplacementToken(NumTokens-1).is(tok::hashhash)) {
3207 Diag(MI->getReplacementToken(NumTokens-1), diag::err_paste_at_end);
3215 if (!OtherMI || !MI->isIdenticalTo(*OtherMI, *this,
3217 Diag(MI->getDefinitionLoc(), diag::warn_pp_macro_def_mismatch_with_pch)
3227 // Final macros are hard-mode: they always warn. Even if the bodies are
3230 if (MacroNameTok.getIdentifierInfo()->isFinal())
3233 // In Objective-C, ignore attempts to directly redefine the builtin
3237 SourceMgr.getFileID(OtherMI->getDefinitionLoc()) ==
3243 !MI->isIdenticalTo(*OtherMI, *this,
3245 Diag(MI->getDefinitionLoc(), diag::warn_pp_objc_macro_redef_ignored);
3247 assert(!OtherMI->isWarnIfUnused());
3257 if (!OtherMI->isUsed() && OtherMI->isWarnIfUnused())
3258 Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used);
3262 if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName()))
3266 else if (!OtherMI->isAllowRedefinitionsWithoutWarning() &&
3267 !MI->isIdenticalTo(*OtherMI, *this, /*Syntactic=*/LangOpts.MicrosoftExt)) {
3268 Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef)
3270 Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition);
3273 if (OtherMI->isWarnIfUnused())
3274 WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc());
3280 assert(!MI->isUsed());
3282 // warn-because-unused-macro set. If it gets used it will be removed from set.
3283 if (getSourceManager().isInMainFile(MI->getDefinitionLoc()) &&
3284 !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc()) &&
3286 getSourceManager().getFileID(MI->getDefinitionLoc()) !=
3288 MI->setIsWarnIfUnused(true);
3289 WarnUnusedMacroLocs.insert(MI->getDefinitionLoc());
3294 Callbacks->MacroDefined(MacroNameTok, MD);
3301 MacroNameTok.getIdentifierInfo()->isStr("assert") &&
3309 MI->setTokens({Tok}, BP);
3314 /// HandleUndefDirective - Implements \#undef.
3334 if (II->isFinal())
3339 if (!MI->isUsed() && MI->isWarnIfUnused())
3340 Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used);
3344 if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName()))
3347 if (MI->isWarnIfUnused())
3348 WarnUnusedMacroLocs.erase(MI->getDefinitionLoc());
3356 Callbacks->MacroUndefined(MacroNameTok, MD, Undef);
3362 //===----------------------------------------------------------------------===//
3364 //===----------------------------------------------------------------------===//
3366 /// HandleIfdefDirective - Implements the \#ifdef/\#ifndef directive. isIfndef
3368 /// true if any tokens have been returned or pp-directives activated before this
3400 if (CurPPLexer->getConditionalStackDepth() == 0) {
3401 // If the start of a top-level #ifdef and if the macro is not defined,
3407 CurPPLexer->MIOpt.EnterTopLevelIfndef(MII, MacroNameTok.getLocation());
3409 CurPPLexer->MIOpt.EnterTopLevelConditional();
3418 Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok, MD);
3420 Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD);
3423 bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
3427 if (PPOpts->SingleFileParseMode && !MI) {
3428 // In 'single-file-parse mode' undefined identifiers trigger parsing of all
3430 CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
3435 CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(),
3447 /// HandleIfDirective - Implements the \#if directive.
3464 // directive seen, handle it for the multiple-include optimization.
3465 if (CurPPLexer->getConditionalStackDepth() == 0) {
3468 CurPPLexer->MIOpt.EnterTopLevelIfndef(IfNDefMacro, IfToken.getLocation());
3470 CurPPLexer->MIOpt.EnterTopLevelConditional();
3474 Callbacks->If(
3478 bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
3482 if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) {
3483 // In 'single-file-parse mode' undefined identifiers trigger parsing of all
3485 CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
3489 CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false,
3499 /// HandleEndifDirective - Implements the \#endif directive.
3508 if (CurPPLexer->popConditionalLevel(CondInfo)) {
3514 // If this the end of a top-level #endif, inform MIOpt.
3515 if (CurPPLexer->getConditionalStackDepth() == 0)
3516 CurPPLexer->MIOpt.ExitTopLevelConditional();
3518 assert(!CondInfo.WasSkipping && !CurPPLexer->LexingRawMode &&
3519 "This code should only be reachable in the non-skipping case!");
3522 Callbacks->Endif(EndifToken.getLocation(), CondInfo.IfLoc);
3525 /// HandleElseDirective - Implements the \#else directive.
3530 // #else directive in a non-skipping conditional... start skipping.
3534 if (CurPPLexer->popConditionalLevel(CI)) {
3539 // If this is a top-level #else, inform the MIOpt.
3540 if (CurPPLexer->getConditionalStackDepth() == 0)
3541 CurPPLexer->MIOpt.EnterTopLevelConditional();
3547 Callbacks->Else(Result.getLocation(), CI.IfLoc);
3549 bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
3552 if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
3553 // In 'single-file-parse mode' undefined identifiers trigger parsing of all
3555 CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false,
3592 // #elif directive in a non-skipping conditional... start skipping.
3598 if (CurPPLexer->popConditionalLevel(CI)) {
3603 // If this is a top-level #elif, inform the MIOpt.
3604 if (CurPPLexer->getConditionalStackDepth() == 0)
3605 CurPPLexer->MIOpt.EnterTopLevelConditional();
3614 Callbacks->Elif(ElifToken.getLocation(), ConditionRange,
3618 Callbacks->Elifdef(ElifToken.getLocation(), ConditionRange, CI.IfLoc);
3621 Callbacks->Elifndef(ElifToken.getLocation(), ConditionRange, CI.IfLoc);
3629 bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks &&
3632 if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) {
3633 // In 'single-file-parse mode' undefined identifiers trigger parsing of all
3635 CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false,
3672 // pp-parameter-name:
3673 // pp-standard-parameter
3674 // pp-prefixed-parameter
3676 // pp-standard-parameter:
3679 // pp-prefixed-parameter:
3681 auto LexPPParameterName = [&]() -> std::optional<std::string> {
3702 return (llvm::Twine(Prefix->getName()) + "::" + Suffix->getName()).str();
3704 return Prefix->getName().str();
3713 return Name.substr(2, Name.size() - 4);
3717 auto LexParenthesizedIntegerExpr = [&]() -> std::optional<size_t> {
3788 default: // Shutting up diagnostics about not fully-covered switch.
3844 } else if (Parameter == "clang::offset") {
3909 ArrayRef<Token> Toks = Params.MaybeIfEmptyParam->Tokens;
3926 llvm::copy(Params.MaybePrefixParam->Tokens, &Toks[CurIdx]);
3931 Data->BinaryData = BinaryContents;
3940 llvm::copy(Params.MaybeSuffixParam->Tokens, &Toks[CurIdx]);
3955 << (LangOpts.CPlusPlus ? /*Clang*/ 1 : /*C23*/ 0);
3970 // directive-parameters:
3971 // identifier parameter-name-list[opt] directive-argument-list[opt]
3972 // directive-argument-list:
3973 // '(' balanced-token-sequence ')'
3974 // parameter-name-list:
3975 // '::' identifier parameter-name-list[opt]
3995 this->LookupEmbedFile(Filename, isAngled, true, LookupFromFile);
3998 if (Callbacks && Callbacks->EmbedFileNotFound(OriginalFilename)) {
4012 StringRef BinaryContents = MaybeFile->getBuffer();
4017 if (Params->MaybeOffsetParam) {
4022 BinaryContents = BinaryContents.substr(Params->MaybeOffsetParam->Offset);
4025 if (Params->MaybeLimitParam) {
4026 // FIXME: just like with the clang::offset() and if_empty() parameters,
4029 BinaryContents = BinaryContents.substr(0, Params->MaybeLimitParam->Limit);
4033 Callbacks->EmbedDirective(HashLoc, Filename, isAngled, MaybeFileRef,