Lines Matching +full:current +full:- +full:boost +full:- +full:limit

1 //===--- PPDirectives.cpp - Directive Handling for Preprocessor -----------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
60 //===----------------------------------------------------------------------===//
62 //===----------------------------------------------------------------------===//
85 /// Read and discard all tokens remaining on the current line until
118 …// * https://docs.microsoft.com/en-us/cpp/c-runtime-library/security-features-in-the-crt?view=msvc in isFeatureTestMacro()
161 if (MI->isBuiltinMacro()) in isLanguageDefinedBuiltin()
164 if (!SourceMgr.isWrittenInBuiltinFile(MI->getDefinitionLoc())) in isLanguageDefinedBuiltin()
173 // C++ defines various feature-test macros starting with __cpp in isLanguageDefinedBuiltin()
176 // Anything else isn't language-defined in isLanguageDefinedBuiltin()
182 StringRef Text = II->getName(); in shouldWarnOnMacroDef()
183 if (isReservedInAllContexts(II->isReserved(Lang))) in shouldWarnOnMacroDef()
185 if (II->isKeyword(Lang)) in shouldWarnOnMacroDef()
195 if (isReservedInAllContexts(II->isReserved(Lang))) in shouldWarnOnMacroUndef()
203 // and Boost headers. Improper case for these #includes is a
206 // If the first component of the path is "boost", treat this like a standard header in warnByDefaultOnWrongCase()
208 if (::llvm::sys::path::begin(Include)->equals_insensitive("boost")) in warnByDefaultOnWrongCase()
225 Ch += 'a' - 'A'; in warnByDefaultOnWrongCase()
289 // We need to check if `Candidates` has the exact case-insensitive string in findSimilarStr()
301 size_t MaxDist = Length < 3 ? Length - 1 : Length / 3; in findSimilarStr()
310 } else if (CurDist < SimilarStr->second) { in findSimilarStr()
318 return SimilarStr->first; in findSimilarStr()
334 if (II->isCPlusPlusOperatorKeyword()) { in CheckMacroName()
345 if ((isDefineUndef != MU_Other) && II->getPPKeywordID() == tok::pp_defined) { in CheckMacroName()
356 (SourceMgr.getBufferName(MacroNameLoc) != "<built-in>")) { in CheckMacroName()
394 CodeComplete->CodeCompleteMacroName(isDefineUndef == MU_Define); in ReadMacroName()
429 while (Tmp.is(tok::comment)) // Skip comments in -C mode. in CheckEndOfDirective()
435 // Add a fixit in GNU/C99/C++ mode. Don't offer a fixit for strict-C89, in CheckEndOfDirective()
436 // or if this is a macro-style preprocessing directive, because it is more in CheckEndOfDirective()
449 // If this is a `.S` file, treat unknown # directives as non-preprocessor in SuggestTypoedDirective()
472 /// SkipExcludedConditionalBlock - We just read a \#if or related directive and
500 assert(CurLexer && "Conditional PP block but no current lexer set!"); in SkipExcludedConditionalBlock()
505 CurPPLexer->pushConditionalLevel(IfTokenLoc, /*isSkipping*/ false, in SkipExcludedConditionalBlock()
510 CurPPLexer->LexingRawMode = true; in SkipExcludedConditionalBlock()
515 /// range if the same block is re-visited. in SkipExcludedConditionalBlock()
530 BeginPtr = PP.CurLexer->getBufferLocation(); in SkipExcludedConditionalBlock()
533 PP.CurLexer->seek(PP.CurLexer->getCurrentBufferOffset() + *SkipRangePtr, in SkipExcludedConditionalBlock()
541 assert(PP.CurLexer->isDependencyDirectivesLexer()); in SkipExcludedConditionalBlock()
547 *SkipRangePtr = Hashptr - BeginPtr; in SkipExcludedConditionalBlock()
549 assert(*SkipRangePtr == unsigned(Hashptr - BeginPtr)); in SkipExcludedConditionalBlock()
556 if (CurLexer->isDependencyDirectivesLexer()) { in SkipExcludedConditionalBlock()
557 CurLexer->LexDependencyDirectiveTokenWhileSkipping(Tok); in SkipExcludedConditionalBlock()
561 CurLexer->Lex(Tok); in SkipExcludedConditionalBlock()
566 CodeComplete->CodeCompleteInConditionalExclusion(); in SkipExcludedConditionalBlock()
595 CurPPLexer->ParsingPreprocessorDirective = true; in SkipExcludedConditionalBlock()
596 if (CurLexer) CurLexer->SetKeepWhitespaceMode(false); in SkipExcludedConditionalBlock()
599 const char *Hashptr = CurLexer->getBufferLocation() - Tok.getLength(); in SkipExcludedConditionalBlock()
600 assert(CurLexer->getSourceLocation(Hashptr) == Tok.getLocation()); in SkipExcludedConditionalBlock()
608 CurPPLexer->ParsingPreprocessorDirective = false; in SkipExcludedConditionalBlock()
610 if (CurLexer) CurLexer->resetExtendedTokenMode(); in SkipExcludedConditionalBlock()
624 CurPPLexer->ParsingPreprocessorDirective = false; in SkipExcludedConditionalBlock()
626 if (CurLexer) CurLexer->resetExtendedTokenMode(); in SkipExcludedConditionalBlock()
641 CurPPLexer->ParsingPreprocessorDirective = false; in SkipExcludedConditionalBlock()
643 if (CurLexer) CurLexer->resetExtendedTokenMode(); in SkipExcludedConditionalBlock()
658 CurPPLexer->pushConditionalLevel(Tok.getLocation(), /*wasskipping*/true, in SkipExcludedConditionalBlock()
669 bool InCond = CurPPLexer->popConditionalLevel(CondInfo); in SkipExcludedConditionalBlock()
670 (void)InCond; // Silence warning in no-asserts mode. in SkipExcludedConditionalBlock()
678 CurPPLexer->LexingRawMode = false; in SkipExcludedConditionalBlock()
680 CurPPLexer->LexingRawMode = true; in SkipExcludedConditionalBlock()
682 Callbacks->Endif(Tok.getLocation(), CondInfo.IfLoc); in SkipExcludedConditionalBlock()
690 // as a non-skipping conditional. in SkipExcludedConditionalBlock()
691 PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel(); in SkipExcludedConditionalBlock()
709 CurPPLexer->LexingRawMode = false; in SkipExcludedConditionalBlock()
711 CurPPLexer->LexingRawMode = true; in SkipExcludedConditionalBlock()
713 Callbacks->Else(Tok.getLocation(), CondInfo.IfLoc); in SkipExcludedConditionalBlock()
719 PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel(); in SkipExcludedConditionalBlock()
732 // condition to verify that it is well-formed. The current state in SkipExcludedConditionalBlock()
739 assert(CurPPLexer->LexingRawMode && "We have to be skipping here!"); in SkipExcludedConditionalBlock()
740 CurPPLexer->LexingRawMode = false; in SkipExcludedConditionalBlock()
747 CurPPLexer->LexingRawMode = true; in SkipExcludedConditionalBlock()
749 Callbacks->Elif( in SkipExcludedConditionalBlock()
763 PPConditionalInfo &CondInfo = CurPPLexer->peekConditionalLevel(); in SkipExcludedConditionalBlock()
789 // condition to verify that it is well-formed. The current state in SkipExcludedConditionalBlock()
796 assert(CurPPLexer->LexingRawMode && "We have to be skipping here!"); in SkipExcludedConditionalBlock()
797 CurPPLexer->LexingRawMode = false; in SkipExcludedConditionalBlock()
800 CurPPLexer->LexingRawMode = true; in SkipExcludedConditionalBlock()
820 Callbacks->Elifdef(DirectiveToken.getLocation(), MacroNameTok, in SkipExcludedConditionalBlock()
823 Callbacks->Elifndef(DirectiveToken.getLocation(), MacroNameTok, in SkipExcludedConditionalBlock()
840 CurPPLexer->ParsingPreprocessorDirective = false; in SkipExcludedConditionalBlock()
842 if (CurLexer) CurLexer->resetExtendedTokenMode(); in SkipExcludedConditionalBlock()
848 CurPPLexer->LexingRawMode = false; in SkipExcludedConditionalBlock()
853 Callbacks->SourceRangeSkipped( in SkipExcludedConditionalBlock()
856 : CurPPLexer->getSourceLocation()), in SkipExcludedConditionalBlock()
875 // to the current module, if there is one. in getModuleForLocation()
888 // until we hit a non-textual header that we can #include. (We assume textual in getHeaderToIncludeForDiagnostics()
889 // headers of a module with non-textual headers aren't meant to be used to in getHeaderToIncludeForDiagnostics()
900 HeaderInfo.hasModuleMap(FE->getName(), /*Root*/ nullptr, in getHeaderToIncludeForDiagnostics()
907 // FIXME: If there's a public header in some module that re-exports it, in getHeaderToIncludeForDiagnostics()
919 // include-guarded. in getHeaderToIncludeForDiagnostics()
929 // If this is an accessible, non-textual header of M's top-level module in getHeaderToIncludeForDiagnostics()
965 // If the header lookup mechanism may be relative to the current inclusion in LookupFile()
970 FileID FID = getCurrentFileLexer()->getFileID(); in LookupFile()
979 // from the -include command line argument) from the current working in LookupFile()
993 BuildSystemModule = getCurrentModule()->IsSystem; in LookupFile()
1000 Includers.push_back(std::make_pair(*FileEnt, FileEnt->getDir())); in LookupFile()
1003 // MSVC searches the current include stack from top to bottom for in LookupFile()
1005 // See: http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx in LookupFile()
1009 if ((FileEnt = ISEntry.ThePPLexer->getFileEntry())) in LookupFile()
1010 Includers.push_back(std::make_pair(*FileEnt, FileEnt->getDir())); in LookupFile()
1030 if (&FE->getFileEntry() == FromFile) { in LookupFile()
1049 // to one of the headers on the #include stack. Walk the list of the current in LookupFile()
1052 if ((CurFileEnt = CurPPLexer->getFileEntry())) { in LookupFile()
1063 if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) { in LookupFile()
1080 FileManager &FM = this->getFileManager(); in LookupEmbedFile()
1103 // Non-angled lookup in LookupEmbedFile()
1106 // Use file-based lookup. in LookupEmbedFile()
1107 StringRef FullFileDir = LookupFromFile->tryGetRealPathName(); in LookupEmbedFile()
1135 for (const auto &Entry : PPOpts->EmbedEntries) { in LookupEmbedFile()
1147 //===----------------------------------------------------------------------===//
1149 //===----------------------------------------------------------------------===//
1154 : PP(pp), save(pp->DisableMacroExpansion) { in ResetMacroExpansionHelper()
1155 if (pp->MacroExpansionInDirectivesOverride) in ResetMacroExpansionHelper()
1156 pp->DisableMacroExpansion = false; in ResetMacroExpansionHelper()
1160 PP->DisableMacroExpansion = save; in ~ResetMacroExpansionHelper()
1177 if (II->getPPKeywordID() == tok::pp_define) { in HandleSkippedDirectiveWhileUsingPCH()
1182 II->getPPKeywordID() == tok::pp_include) { in HandleSkippedDirectiveWhileUsingPCH()
1185 if (SkippingUntilPragmaHdrStop && II->getPPKeywordID() == tok::pp_pragma) { in HandleSkippedDirectiveWhileUsingPCH()
1188 if (II && II->getName() == "hdrstop") in HandleSkippedDirectiveWhileUsingPCH()
1195 /// HandleDirective - This callback is invoked when the lexer sees a # token
1205 CurPPLexer->ParsingPreprocessorDirective = true; in HandleDirective()
1206 if (CurLexer) CurLexer->SetKeepWhitespaceMode(false); in HandleDirective()
1209 CurPPLexer->MIOpt.getImmediatelyAfterTopLevelIfndef(); in HandleDirective()
1210 CurPPLexer->MIOpt.resetImmediatelyAfterTopLevelIfndef(); in HandleDirective()
1214 // We are about to read a token. For the multiple-include optimization FA to in HandleDirective()
1216 // pp-directive. in HandleDirective()
1217 bool ReadAnyTokensBeforeDirective =CurPPLexer->MIOpt.getHasReadAnyTokensVal(); in HandleDirective()
1232 // not support this for #include-like directives, since that can result in in HandleDirective()
1236 switch (II->getPPKeywordID()) { in HandleDirective()
1243 Diag(Result, diag::err_embedded_directive) << II->getName(); in HandleDirective()
1245 << ArgMacro->getIdentifierInfo(); in HandleDirective()
1264 // Ignore the null directive with regards to the multiple-include in HandleDirective()
1266 // include guard and still enable the multiple-include optimization. in HandleDirective()
1267 CurPPLexer->MIOpt.SetReadToken(ReadAnyTokensBeforeDirective); in HandleDirective()
1272 CodeComplete->CodeCompleteDirective( in HandleDirective()
1273 CurPPLexer->getConditionalStackDepth() > 0); in HandleDirective()
1288 switch (II->getPPKeywordID()) { in HandleDirective()
1290 // C99 6.10.1 - Conditional Inclusion. in HandleDirective()
1302 return HandleElifFamilyDirective(Result, SavedHash, II->getPPKeywordID()); in HandleDirective()
1309 // C99 6.10.2 - Source File Inclusion. in HandleDirective()
1314 // Handle -imacros. in HandleDirective()
1317 // C99 6.10.3 - Macro Replacement. in HandleDirective()
1323 // C99 6.10.4 - Line Control. in HandleDirective()
1327 // C99 6.10.5 - Error Directive. in HandleDirective()
1331 // C99 6.10.6 - Pragma Directive. in HandleDirective()
1360 ? *getCurrentFileLexer()->getFileEntry() in HandleDirective()
1382 // If this is a .S file, treat unknown # directives as non-preprocessor in HandleDirective()
1384 // various pseudo-ops. Just return the # token and push back the following in HandleDirective()
1397 // Enter this token stream so that we re-lex the tokens. Make sure to in HandleDirective()
1414 /// GetLineValue - Convert a numeric token into an unsigned value, emitting
1435 // Verify that we have a simple digit-sequence, and compute the value. This in GetLineValue()
1441 // Optional separating single quotes in a digit-sequence are ignored in GetLineValue()
1452 unsigned NextVal = Val*10+(DigitTokBegin[i]-'0'); in GetLineValue()
1472 /// # line digit-sequence
1473 /// # line digit-sequence "s-char-sequence"
1499 int FilenameID = -1; in HandleLineDirective()
1537 // the new file should generally be classified the same way as the current in HandleLineDirective()
1538 // file. This is visible in GCC's pre-processed output, which rewrites #line in HandleLineDirective()
1547 Callbacks->FileChanged(CurPPLexer->getSourceLocation(), in HandleLineDirective()
1551 /// ReadLineMarkerFlags - Parse and validate any flags at the end of a GNU line
1574 // If we are leaving the current presumed file, check to make sure the in ReadLineMarkerFlags()
1630 /// HandleDigitDirective - Handle a GNU line marker directive, whose syntax is
1639 // line # limit other than it fit in 32-bits. in HandleDigitDirective()
1649 int FilenameID = -1; in HandleDigitDirective()
1688 // FilenameID as -1 in that case. in HandleDigitDirective()
1698 // change. This is used so that the line marker comes out in -E mode for in HandleDigitDirective()
1707 Callbacks->FileChanged(CurPPLexer->getSourceLocation(), Reason, FileKind); in HandleDigitDirective()
1711 /// HandleUserDiagnosticDirective - Handle a #warning or #error directive.
1721 CurLexer->ReadToEndOfLine(&Message); in HandleUserDiagnosticDirective()
1723 // Find the first non-whitespace character, so that we can make the in HandleUserDiagnosticDirective()
1733 /// HandleIdentSCCSDirective - Handle a #ident/#sccs directive.
1765 Callbacks->Ident(Tok.getLocation(), Str); in HandleIdentSCCSDirective()
1823 //===----------------------------------------------------------------------===//
1825 //===----------------------------------------------------------------------===//
1827 /// GetIncludeFilenameSpelling - Turn the specified lexer token into a fully
1841 // If `"`, `'`, `\`, `/*`, or `//` appears in a header-name, then in GetIncludeFilenameSpelling()
1843 // in C++: program is conditionally-supported with implementation-defined in GetIncludeFilenameSpelling()
1876 Buffer = Buffer.substr(1, Buffer.size()-2); in GetIncludeFilenameSpelling()
1884 // FIXME: Produce this as the current token directly, rather than in EnterAnnotationToken()
1905 PathString += Path[I].first->getName(); in diagnoseAutoModuleImport()
1909 switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) { in diagnoseAutoModuleImport()
1935 // path to the file, build a properly-cased replacement in the vector,
1950 // Below is a best-effort to handle ".." in paths. It is admittedly in trySimplifyPath()
1957 --Cnt; in trySimplifyPath()
1961 // If these non-separator path components differ by more than just case, in trySimplifyPath()
1965 RealPathComponentIter->equals_insensitive(Component); in trySimplifyPath()
1992 Diags.Report(ShadowingModule->DefinitionLoc, in checkModuleIsAvailable()
2007 // the current found directory. If we can't do this, issue a in getIncludeNextStart()
2020 // Start looking up in the directory *after* the one in which the current in getIncludeNextStart()
2023 if (auto FE = CurPPLexer->getFileEntry()) in getIncludeNextStart()
2027 // The current file was not found by walking the include path. Either it in getIncludeNextStart()
2040 /// HandleIncludeDirective - The "\#include" tokens have just been read, read
2062 // this falls into the category of "#include pp-tokens new-line" specified in HandleIncludeDirective()
2065 CheckEndOfDirective(IncludeTok.getIdentifierInfo()->getNameStart(), true); in HandleIncludeDirective()
2090 CurLexer->cutOffLexing(); in HandleIncludeDirective()
2127 if (Callbacks && Callbacks->FileNotFound(Filename)) in LookupHeaderIncludeOrImport()
2152 // Check for likely typos due to leading or trailing non-isAlphanumeric in LookupHeaderIncludeOrImport()
2157 // trailing non-isAlphanumeric characters. in LookupHeaderIncludeOrImport()
2204 << CacheEntry.Directory->getName(); in LookupHeaderIncludeOrImport()
2210 /// Handle either a #include-like directive or an import declaration that names
2216 /// \param FilenameTok The header-name token.
2253 // Complain about attempts to #include files in an assume-nonnull pragma. in HandleHeaderIncludeOrImport()
2283 // Normalize slashes when compiling with -fms-extensions on non-Windows. This in HandleHeaderIncludeOrImport()
2300 if (File && isPCHThroughHeader(&File->getFileEntry())) in HandleHeaderIncludeOrImport()
2306 // known to have no effect beyond its effect on module visibility -- that is, in HandleHeaderIncludeOrImport()
2311 // [cpp.include]/7 If the header identified by the header-name denotes an in HandleHeaderIncludeOrImport()
2312 // importable header, it is implementation-defined whether the #include in HandleHeaderIncludeOrImport()
2322 if (PPOpts->SingleFileParseMode) in HandleHeaderIncludeOrImport()
2333 // C++ standard modules (other than use/non-use of Header Units). in HandleHeaderIncludeOrImport()
2338 !ModuleToImport->isForBuilding(getLangOpts()); in HandleHeaderIncludeOrImport()
2343 ModuleToImport->isHeaderUnit()) { in HandleHeaderIncludeOrImport()
2347 // This is a Header Unit that we do not include-translate in HandleHeaderIncludeOrImport()
2354 ModuleToImport && !ModuleToImport->isHeaderUnit(); in HandleHeaderIncludeOrImport()
2368 << ModuleToImport->getTopLevelModuleName(); in HandleHeaderIncludeOrImport()
2376 for (Module *Mod = ModuleToImport; Mod; Mod = Mod->Parent) in HandleHeaderIncludeOrImport()
2377 Path.push_back(std::make_pair(getIdentifierInfo(Mod->Name), in HandleHeaderIncludeOrImport()
2399 static_cast<Module *>(Imported)->getTopLevelModule()); in HandleHeaderIncludeOrImport()
2413 assert(CurLexer && "#include but no current lexer set!"); in HandleHeaderIncludeOrImport()
2415 CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof); in HandleHeaderIncludeOrImport()
2416 CurLexer->cutOffLexing(); in HandleHeaderIncludeOrImport()
2430 // If this is a '#import' or an import-declaration, don't re-enter the file. in HandleHeaderIncludeOrImport()
2437 IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import; in HandleHeaderIncludeOrImport()
2469 SourceMgr.isMainFile(File->getFileEntry())) { in HandleHeaderIncludeOrImport()
2477 // FIXME: Use a different callback for a pp-import? in HandleHeaderIncludeOrImport()
2478 Callbacks->InclusionDirective(HashLoc, IncludeTok, LookupFilename, isAngled, in HandleHeaderIncludeOrImport()
2483 Callbacks->FileSkipped(*File, FilenameTok, FileCharacter); in HandleHeaderIncludeOrImport()
2489 // If this is a C++20 pp-import declaration, diagnose if we didn't find any in HandleHeaderIncludeOrImport()
2493 << OriginalFilename << File->getName(); in HandleHeaderIncludeOrImport()
2500 !IsMapped && !File->getFileEntry().tryGetRealPathName().empty(); in HandleHeaderIncludeOrImport()
2511 StringRef RealPathName = File->getFileEntry().tryGetRealPathName(); in HandleHeaderIncludeOrImport()
2515 // -Wnonportable-include-path is designed to diagnose includes using in HandleHeaderIncludeOrImport()
2516 // case even on systems with a case-insensitive file system. in HandleHeaderIncludeOrImport()
2517 // On Windows, RealPathName always starts with an upper-case drive in HandleHeaderIncludeOrImport()
2520 // ("foo" will always have on-disk case, no matter which case was in HandleHeaderIncludeOrImport()
2523 // with upper- or lower-case drive letters, always consider the in HandleHeaderIncludeOrImport()
2569 assert(IsSep(NameWithoriginalSlashes[Path.size()-1])); in HandleHeaderIncludeOrImport()
2571 Path.push_back(NameWithoriginalSlashes[Path.size()-1]); in HandleHeaderIncludeOrImport()
2573 IsSep(NameWithoriginalSlashes[Path.size()-1])); in HandleHeaderIncludeOrImport()
2601 // If we reached our include limit and don't want to enter any more files, in HandleHeaderIncludeOrImport()
2611 if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == in HandleHeaderIncludeOrImport()
2623 if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) { in HandleHeaderIncludeOrImport()
2652 if (ModuleToImport && !ModuleToImport->isHeaderUnit()) { in HandleHeaderIncludeOrImport()
2653 if (ModuleToImport->getTopLevelModule()->ShadowingModule) { in HandleHeaderIncludeOrImport()
2656 Diag(ModuleToImport->DefinitionLoc, in HandleHeaderIncludeOrImport()
2658 << ModuleToImport->getFullModuleName(); in HandleHeaderIncludeOrImport()
2659 Diag(ModuleToImport->getTopLevelModule()->ShadowingModule->DefinitionLoc, in HandleHeaderIncludeOrImport()
2663 // When building a pch, -fmodule-name tells the compiler to textually in HandleHeaderIncludeOrImport()
2672 ModuleToImport->isForBuilding(getLangOpts())) in HandleHeaderIncludeOrImport()
2693 /// HandleIncludeNextDirective - Implements \#include_next.
2707 /// HandleMicrosoftImportDirective - Implements \#import for Microsoft Mode
2721 /// HandleImportDirective - Implements \#import.
2733 /// HandleIncludeMacrosDirective - The -imacros command line option turns into a
2742 if (SourceMgr.getBufferName(Loc) != "<built-in>") { in HandleIncludeMacrosDirective()
2756 assert(TmpTok.isNot(tok::eof) && "Didn't find end of -imacros!"); in HandleIncludeMacrosDirective()
2760 //===----------------------------------------------------------------------===//
2762 //===----------------------------------------------------------------------===//
2764 /// ReadMacroParameterList - The ( starting a parameter list of a macro
2781 case tok::ellipsis: // #define X(... -> C99 varargs in ReadMacroParameterList()
2800 MI->setIsC99Varargs(); in ReadMacroParameterList()
2801 MI->setParameterList(Parameters, BP); in ReadMacroParameterList()
2834 MI->setParameterList(Parameters, BP); in ReadMacroParameterList()
2838 case tok::ellipsis: // #define X(A... -> GCC extension in ReadMacroParameterList()
2849 MI->setIsGNUVarargs(); in ReadMacroParameterList()
2850 MI->setParameterList(Parameters, BP); in ReadMacroParameterList()
2859 if (MI->getNumTokens() == 1) { in isConfigurationPattern()
2860 const Token &Value = MI->getReplacementToken(0); in isConfigurationPattern()
2871 StringRef MacroText = MacroName.getIdentifierInfo()->getName(); in isConfigurationPattern()
2873 if (!II->isKeyword(LOptions)) in isConfigurationPattern()
2875 StringRef ValueText = II->getName(); in isConfigurationPattern()
2896 MI->getNumTokens() == 0; in isConfigurationPattern()
2899 // ReadOptionalMacroParameterListAndBody - This consumes all (i.e. the
2902 // - # (stringization) is followed by a macro parameter
2920 if (CurLexer->ParsingPreprocessorDirective) in ReadOptionalMacroParameterListAndBody()
2924 // Used to un-poison and then re-poison identifiers of the __VA_ARGS__ ilk in ReadOptionalMacroParameterListAndBody()
2928 // If this is a function-like macro definition, parse the argument list, in ReadOptionalMacroParameterListAndBody()
2934 CurPPLexer->MIOpt.SetDefinedMacro(MacroNameTok.getIdentifierInfo(), in ReadOptionalMacroParameterListAndBody()
2943 // This is a function-like macro definition. Read the argument list. in ReadOptionalMacroParameterListAndBody()
2944 MI->setIsFunctionLike(); in ReadOptionalMacroParameterListAndBody()
2948 // If this is a definition of an ISO C/C++ variadic function-like macro (not in ReadOptionalMacroParameterListAndBody()
2950 // which un-poisons and re-poisons certain identifiers (e.g. __VA_ARGS__) in ReadOptionalMacroParameterListAndBody()
2953 if (MI->isC99Varargs()) { in ReadOptionalMacroParameterListAndBody()
2964 // C90 6.8 TC1 says: "In the definition of an object-like macro, if the in ReadOptionalMacroParameterListAndBody()
2966 // subclause 5.2.1, then there shall be white-space separation between the in ReadOptionalMacroParameterListAndBody()
2968 // "A-Za-z0-9!"#%&'()*+,_./:;<=>?[\]^_{|}~" as well as whitespace, which in ReadOptionalMacroParameterListAndBody()
2991 if (MI->isObjectLike()) { in ReadOptionalMacroParameterListAndBody()
2992 // Object-like macros are very simple, just read their body. in ReadOptionalMacroParameterListAndBody()
3000 // Otherwise, read the body of a function-like macro. While we are at it, in ReadOptionalMacroParameterListAndBody()
3002 // parameters in function-like macro expansions. in ReadOptionalMacroParameterListAndBody()
3038 if (Tokens[Tokens.size() - 2].is(tok::hashhash)) { in ReadOptionalMacroParameterListAndBody()
3052 // If we're in -traditional mode, then we should ignore stringification in ReadOptionalMacroParameterListAndBody()
3078 Tokens[Tokens.size() - 1].is(tok::comma)) in ReadOptionalMacroParameterListAndBody()
3079 MI->setHasCommaPasting(); in ReadOptionalMacroParameterListAndBody()
3093 MI->getParameterNum(Tok.getIdentifierInfo()) == -1)) { in ReadOptionalMacroParameterListAndBody()
3095 // If this is assembler-with-cpp mode, we accept random gibberish after in ReadOptionalMacroParameterListAndBody()
3132 MI->setDefinitionEndLoc(LastTok.getLocation()); in ReadOptionalMacroParameterListAndBody()
3134 MI->setTokens(Tokens, BP); in ReadOptionalMacroParameterListAndBody()
3139 return II->isStr("__strong") || II->isStr("__weak") || in isObjCProtectedMacro()
3140 II->isStr("__unsafe_unretained") || II->isStr("__autoreleasing"); in isObjCProtectedMacro()
3143 /// HandleDefineDirective - Implements \#define. This consumes the entire macro
3160 if (!II->hasMacroDefinition() && II->hadMacroDefinition() && II->isFinal()) in HandleDefineDirective()
3165 if (CurLexer) CurLexer->SetCommentRetentionState(KeepMacroComments); in HandleDefineDirective()
3178 unsigned NumTokens = MI->getNumTokens(); in HandleDefineDirective()
3180 if (MI->getReplacementToken(0).is(tok::hashhash)) { in HandleDefineDirective()
3181 Diag(MI->getReplacementToken(0), diag::err_paste_at_start); in HandleDefineDirective()
3184 if (MI->getReplacementToken(NumTokens-1).is(tok::hashhash)) { in HandleDefineDirective()
3185 Diag(MI->getReplacementToken(NumTokens-1), diag::err_paste_at_end); in HandleDefineDirective()
3193 if (!OtherMI || !MI->isIdenticalTo(*OtherMI, *this, in HandleDefineDirective()
3195 Diag(MI->getDefinitionLoc(), diag::warn_pp_macro_def_mismatch_with_pch) in HandleDefineDirective()
3205 // Final macros are hard-mode: they always warn. Even if the bodies are in HandleDefineDirective()
3208 if (MacroNameTok.getIdentifierInfo()->isFinal()) in HandleDefineDirective()
3211 // In Objective-C, ignore attempts to directly redefine the builtin in HandleDefineDirective()
3215 SourceMgr.getFileID(OtherMI->getDefinitionLoc()) == in HandleDefineDirective()
3221 !MI->isIdenticalTo(*OtherMI, *this, in HandleDefineDirective()
3223 Diag(MI->getDefinitionLoc(), diag::warn_pp_objc_macro_redef_ignored); in HandleDefineDirective()
3225 assert(!OtherMI->isWarnIfUnused()); in HandleDefineDirective()
3235 if (!OtherMI->isUsed() && OtherMI->isWarnIfUnused()) in HandleDefineDirective()
3236 Diag(OtherMI->getDefinitionLoc(), diag::pp_macro_not_used); in HandleDefineDirective()
3240 if (isLanguageDefinedBuiltin(SourceMgr, OtherMI, II->getName())) in HandleDefineDirective()
3244 else if (!OtherMI->isAllowRedefinitionsWithoutWarning() && in HandleDefineDirective()
3245 !MI->isIdenticalTo(*OtherMI, *this, /*Syntactic=*/LangOpts.MicrosoftExt)) { in HandleDefineDirective()
3246 Diag(MI->getDefinitionLoc(), diag::ext_pp_macro_redef) in HandleDefineDirective()
3248 Diag(OtherMI->getDefinitionLoc(), diag::note_previous_definition); in HandleDefineDirective()
3251 if (OtherMI->isWarnIfUnused()) in HandleDefineDirective()
3252 WarnUnusedMacroLocs.erase(OtherMI->getDefinitionLoc()); in HandleDefineDirective()
3258 assert(!MI->isUsed()); in HandleDefineDirective()
3260 // warn-because-unused-macro set. If it gets used it will be removed from set. in HandleDefineDirective()
3261 if (getSourceManager().isInMainFile(MI->getDefinitionLoc()) && in HandleDefineDirective()
3262 !Diags->isIgnored(diag::pp_macro_not_used, MI->getDefinitionLoc()) && in HandleDefineDirective()
3264 getSourceManager().getFileID(MI->getDefinitionLoc()) != in HandleDefineDirective()
3266 MI->setIsWarnIfUnused(true); in HandleDefineDirective()
3267 WarnUnusedMacroLocs.insert(MI->getDefinitionLoc()); in HandleDefineDirective()
3272 Callbacks->MacroDefined(MacroNameTok, MD); in HandleDefineDirective()
3279 MacroNameTok.getIdentifierInfo()->isStr("assert") && in HandleDefineDirective()
3287 MI->setTokens({Tok}, BP); in HandleDefineDirective()
3292 /// HandleUndefDirective - Implements \#undef.
3312 if (II->isFinal()) in HandleUndefDirective()
3317 if (!MI->isUsed() && MI->isWarnIfUnused()) in HandleUndefDirective()
3318 Diag(MI->getDefinitionLoc(), diag::pp_macro_not_used); in HandleUndefDirective()
3322 if (isLanguageDefinedBuiltin(SourceMgr, MI, II->getName())) in HandleUndefDirective()
3325 if (MI->isWarnIfUnused()) in HandleUndefDirective()
3326 WarnUnusedMacroLocs.erase(MI->getDefinitionLoc()); in HandleUndefDirective()
3334 Callbacks->MacroUndefined(MacroNameTok, MD, Undef); in HandleUndefDirective()
3340 //===----------------------------------------------------------------------===//
3342 //===----------------------------------------------------------------------===//
3344 /// HandleIfdefDirective - Implements the \#ifdef/\#ifndef directive. isIfndef
3346 /// true if any tokens have been returned or pp-directives activated before this
3378 if (CurPPLexer->getConditionalStackDepth() == 0) { in HandleIfdefDirective()
3379 // If the start of a top-level #ifdef and if the macro is not defined, in HandleIfdefDirective()
3385 CurPPLexer->MIOpt.EnterTopLevelIfndef(MII, MacroNameTok.getLocation()); in HandleIfdefDirective()
3387 CurPPLexer->MIOpt.EnterTopLevelConditional(); in HandleIfdefDirective()
3396 Callbacks->Ifndef(DirectiveTok.getLocation(), MacroNameTok, MD); in HandleIfdefDirective()
3398 Callbacks->Ifdef(DirectiveTok.getLocation(), MacroNameTok, MD); in HandleIfdefDirective()
3401 bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks && in HandleIfdefDirective()
3405 if (PPOpts->SingleFileParseMode && !MI) { in HandleIfdefDirective()
3406 // In 'single-file-parse mode' undefined identifiers trigger parsing of all in HandleIfdefDirective()
3408 CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(), in HandleIfdefDirective()
3413 CurPPLexer->pushConditionalLevel(DirectiveTok.getLocation(), in HandleIfdefDirective()
3425 /// HandleIfDirective - Implements the \#if directive.
3442 // directive seen, handle it for the multiple-include optimization. in HandleIfDirective()
3443 if (CurPPLexer->getConditionalStackDepth() == 0) { in HandleIfDirective()
3446 CurPPLexer->MIOpt.EnterTopLevelIfndef(IfNDefMacro, IfToken.getLocation()); in HandleIfDirective()
3448 CurPPLexer->MIOpt.EnterTopLevelConditional(); in HandleIfDirective()
3452 Callbacks->If( in HandleIfDirective()
3456 bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks && in HandleIfDirective()
3460 if (PPOpts->SingleFileParseMode && DER.IncludedUndefinedIds) { in HandleIfDirective()
3461 // In 'single-file-parse mode' undefined identifiers trigger parsing of all in HandleIfDirective()
3463 CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false, in HandleIfDirective()
3467 CurPPLexer->pushConditionalLevel(IfToken.getLocation(), /*wasskip*/false, in HandleIfDirective()
3477 /// HandleEndifDirective - Implements the \#endif directive.
3486 if (CurPPLexer->popConditionalLevel(CondInfo)) { in HandleEndifDirective()
3492 // If this the end of a top-level #endif, inform MIOpt. in HandleEndifDirective()
3493 if (CurPPLexer->getConditionalStackDepth() == 0) in HandleEndifDirective()
3494 CurPPLexer->MIOpt.ExitTopLevelConditional(); in HandleEndifDirective()
3496 assert(!CondInfo.WasSkipping && !CurPPLexer->LexingRawMode && in HandleEndifDirective()
3497 "This code should only be reachable in the non-skipping case!"); in HandleEndifDirective()
3500 Callbacks->Endif(EndifToken.getLocation(), CondInfo.IfLoc); in HandleEndifDirective()
3503 /// HandleElseDirective - Implements the \#else directive.
3508 // #else directive in a non-skipping conditional... start skipping. in HandleElseDirective()
3512 if (CurPPLexer->popConditionalLevel(CI)) { in HandleElseDirective()
3517 // If this is a top-level #else, inform the MIOpt. in HandleElseDirective()
3518 if (CurPPLexer->getConditionalStackDepth() == 0) in HandleElseDirective()
3519 CurPPLexer->MIOpt.EnterTopLevelConditional(); in HandleElseDirective()
3525 Callbacks->Else(Result.getLocation(), CI.IfLoc); in HandleElseDirective()
3527 bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks && in HandleElseDirective()
3530 if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) { in HandleElseDirective()
3531 // In 'single-file-parse mode' undefined identifiers trigger parsing of all in HandleElseDirective()
3533 CurPPLexer->pushConditionalLevel(CI.IfLoc, /*wasskip*/false, in HandleElseDirective()
3570 // #elif directive in a non-skipping conditional... start skipping. in HandleElifFamilyDirective()
3576 if (CurPPLexer->popConditionalLevel(CI)) { in HandleElifFamilyDirective()
3581 // If this is a top-level #elif, inform the MIOpt. in HandleElifFamilyDirective()
3582 if (CurPPLexer->getConditionalStackDepth() == 0) in HandleElifFamilyDirective()
3583 CurPPLexer->MIOpt.EnterTopLevelConditional(); in HandleElifFamilyDirective()
3592 Callbacks->Elif(ElifToken.getLocation(), ConditionRange, in HandleElifFamilyDirective()
3596 Callbacks->Elifdef(ElifToken.getLocation(), ConditionRange, CI.IfLoc); in HandleElifFamilyDirective()
3599 Callbacks->Elifndef(ElifToken.getLocation(), ConditionRange, CI.IfLoc); in HandleElifFamilyDirective()
3607 bool RetainExcludedCB = PPOpts->RetainExcludedConditionalBlocks && in HandleElifFamilyDirective()
3610 if ((PPOpts->SingleFileParseMode && !CI.FoundNonSkip) || RetainExcludedCB) { in HandleElifFamilyDirective()
3611 // In 'single-file-parse mode' undefined identifiers trigger parsing of all in HandleElifFamilyDirective()
3613 CurPPLexer->pushConditionalLevel(ElifToken.getLocation(), /*wasskip*/false, in HandleElifFamilyDirective()
3650 // pp-parameter-name: in LexEmbedParameters()
3651 // pp-standard-parameter in LexEmbedParameters()
3652 // pp-prefixed-parameter in LexEmbedParameters()
3654 // pp-standard-parameter: in LexEmbedParameters()
3657 // pp-prefixed-parameter: in LexEmbedParameters()
3659 auto LexPPParameterName = [&]() -> std::optional<std::string> { in LexEmbedParameters()
3660 // We expect the current token to be an identifier; if it's not, things in LexEmbedParameters()
3680 return (llvm::Twine(Prefix->getName()) + "::" + Suffix->getName()).str(); in LexEmbedParameters()
3682 return Prefix->getName().str(); in LexEmbedParameters()
3691 return Name.substr(2, Name.size() - 4); in LexEmbedParameters()
3695 auto LexParenthesizedIntegerExpr = [&]() -> std::optional<size_t> { in LexEmbedParameters()
3696 // we have a limit parameter and its internals are processed using in LexEmbedParameters()
3757 // We expect the current token to be a left paren. in LexEmbedParameters()
3766 default: // Shutting up diagnostics about not fully-covered switch. in LexEmbedParameters()
3813 if (Parameter == "limit") { in LexEmbedParameters()
3817 std::optional<size_t> Limit = LexParenthesizedIntegerExpr(); in LexEmbedParameters() local
3818 if (!Limit) in LexEmbedParameters()
3821 PPEmbedParameterLimit{*Limit, {ParamStartLoc, CurTok.getLocation()}}; in LexEmbedParameters()
3887 ArrayRef<Token> Toks = Params.MaybeIfEmptyParam->Tokens; in HandleEmbedDirectiveImpl()
3904 llvm::copy(Params.MaybePrefixParam->Tokens, &Toks[CurIdx]); in HandleEmbedDirectiveImpl()
3909 Data->BinaryData = BinaryContents; in HandleEmbedDirectiveImpl()
3918 llvm::copy(Params.MaybeSuffixParam->Tokens, &Toks[CurIdx]); in HandleEmbedDirectiveImpl()
3948 // directive-parameters: in HandleEmbedDirective()
3949 // identifier parameter-name-list[opt] directive-argument-list[opt] in HandleEmbedDirective()
3950 // directive-argument-list: in HandleEmbedDirective()
3951 // '(' balanced-token-sequence ')' in HandleEmbedDirective()
3952 // parameter-name-list: in HandleEmbedDirective()
3953 // '::' identifier parameter-name-list[opt] in HandleEmbedDirective()
3973 this->LookupEmbedFile(Filename, isAngled, true, LookupFromFile); in HandleEmbedDirective()
3976 if (Callbacks && Callbacks->EmbedFileNotFound(OriginalFilename)) { in HandleEmbedDirective()
3990 StringRef BinaryContents = MaybeFile->getBuffer(); in HandleEmbedDirective()
3992 // The order is important between 'offset' and 'limit'; we want to offset in HandleEmbedDirective()
3993 // first and then limit second; otherwise we may reduce the notional resource in HandleEmbedDirective()
3995 if (Params->MaybeOffsetParam) { in HandleEmbedDirective()
3996 // FIXME: just like with the limit() and if_empty() parameters, this loses in HandleEmbedDirective()
4000 BinaryContents = BinaryContents.substr(Params->MaybeOffsetParam->Offset); in HandleEmbedDirective()
4003 if (Params->MaybeLimitParam) { in HandleEmbedDirective()
4005 // this loses source fidelity in the AST; it has no idea there was a limit in HandleEmbedDirective()
4007 BinaryContents = BinaryContents.substr(0, Params->MaybeLimitParam->Limit); in HandleEmbedDirective()
4011 Callbacks->EmbedDirective(HashLoc, Filename, isAngled, MaybeFileRef, in HandleEmbedDirective()