34#include "llvm/ADT/ArrayRef.h"
35#include "llvm/ADT/DenseMap.h"
36#include "llvm/ADT/DenseSet.h"
37#include "llvm/ADT/FoldingSet.h"
38#include "llvm/ADT/STLExtras.h"
39#include "llvm/ADT/SmallVector.h"
40#include "llvm/ADT/StringRef.h"
41#include "llvm/ADT/StringSwitch.h"
42#include "llvm/Support/ErrorHandling.h"
43#include "llvm/Support/Format.h"
44#include "llvm/Support/Path.h"
45#include "llvm/Support/raw_ostream.h"
64 auto Pos = CurSubmoduleState->Macros.find(II);
65 return Pos == CurSubmoduleState->Macros.end() ?
nullptr
66 : Pos->second.getLatest();
70 assert(MD &&
"MacroDirective should be non-zero!");
71 assert(!MD->
getPrevious() &&
"Already attached to a MacroDirective history.");
73 MacroState &StoredMD = CurSubmoduleState->Macros[II];
74 auto *OldMD = StoredMD.getLatest();
76 StoredMD.setLatest(MD);
77 StoredMD.overrideActiveModuleMacros(*
this, II);
79 if (needModuleMacros()) {
83 PendingModuleMacroNames.push_back(II);
88 if (!MD->
isDefined() && !LeafModuleMacros.contains(II))
107 MacroState &StoredMD = CurSubmoduleState->Macros[II];
109 if (
auto *OldMD = StoredMD.getLatest()) {
115 assert(OldMD->getMacroInfo()->isBuiltinMacro() &&
116 "only built-ins should have an entry here");
117 assert(!OldMD->getPrevious() &&
"builtin should only have a single entry");
119 StoredMD.setLatest(MD);
126 if (!MD->
isDefined() && !LeafModuleMacros.contains(II))
134 llvm::FoldingSetInsertToken InsertToken;
135 if (
auto *MM = ModuleMacros.lookup({Mod, II}, InsertToken)) {
141 ModuleMacros.insert(MM, InsertToken);
145 for (
auto *O : Overrides) {
146 HidAny |= (O->NumOverriddenBy == 0);
147 ++O->NumOverriddenBy;
151 auto &LeafMacros = LeafModuleMacros[II];
153 llvm::erase_if(LeafMacros,
154 [](
ModuleMacro *MM) {
return MM->NumOverriddenBy != 0; });
158 LeafMacros.push_back(MM);
168 llvm::FoldingSetInsertToken InsertToken;
169 return ModuleMacros.lookup({Mod, II}, InsertToken);
173 FullModuleMacroInfo &Info) {
174 assert(Info.ActiveModuleMacrosGeneration !=
176 "don't need to update this macro name info");
177 Info.ActiveModuleMacrosGeneration =
180 auto Leaf = LeafModuleMacros.find(II);
181 if (Leaf == LeafModuleMacros.end()) {
186 Info.ActiveModuleMacros.clear();
189 llvm::DenseMap<ModuleMacro *, int> NumHiddenOverrides;
190 for (
auto *O : Info.OverriddenMacros)
191 NumHiddenOverrides[O] = -1;
195 for (
auto *LeafMM : Leaf->second) {
196 assert(LeafMM->getNumOverridingMacros() == 0 &&
"leaf macro overridden");
197 if (NumHiddenOverrides.lookup(LeafMM) == 0)
198 Worklist.push_back(LeafMM);
200 while (!Worklist.empty()) {
201 auto *MM = Worklist.pop_back_val();
202 if (CurSubmoduleState->VisibleModules.isVisible(MM->getOwningModule())) {
205 if (MM->getMacroInfo())
206 Info.ActiveModuleMacros.push_back(MM);
208 for (
auto *O : MM->overrides())
209 if ((
unsigned)++NumHiddenOverrides[O] == O->getNumOverridingMacros())
210 Worklist.push_back(O);
214 std::reverse(Info.ActiveModuleMacros.begin(), Info.ActiveModuleMacros.end());
217 MacroInfo *MI =
nullptr;
218 bool IsSystemMacro =
true;
219 bool IsAmbiguous =
false;
220 if (
auto *MD = Info.MD) {
221 while (isa_and_nonnull<VisibilityMacroDirective>(MD))
222 MD = MD->getPrevious();
223 if (
auto *DMD = dyn_cast_or_null<DefMacroDirective>(MD)) {
225 IsSystemMacro &= SourceMgr.isInSystemHeader(DMD->getLocation());
228 for (
auto *Active : Info.ActiveModuleMacros) {
229 auto *NewMI = Active->getMacroInfo();
240 if (MI && NewMI != MI &&
243 IsSystemMacro &= Active->getOwningModule()->IsSystem ||
244 SourceMgr.isInSystemHeader(NewMI->getDefinitionLoc());
247 Info.IsAmbiguous = IsAmbiguous && !IsSystemMacro;
252 auto LeafIt = LeafModuleMacros.find(II);
253 if (LeafIt != LeafModuleMacros.end())
254 Leaf = LeafIt->second;
255 const MacroState *State =
nullptr;
256 auto Pos = CurSubmoduleState->Macros.find(II);
257 if (Pos != CurSubmoduleState->Macros.end())
258 State = &Pos->second;
260 llvm::errs() <<
"MacroState " << State <<
" " << II->
getNameStart();
261 const auto ModuleInfo =
263 if (ModuleInfo.IsAmbiguous)
264 llvm::errs() <<
" ambiguous";
265 if (State && !State->getOverriddenMacros().empty()) {
266 llvm::errs() <<
" overrides";
267 for (
auto *O : State->getOverriddenMacros())
268 llvm::errs() <<
" " << O->getOwningModule()->getFullModuleName();
270 llvm::errs() <<
"\n";
273 for (
auto *MD = State ? State->getLatest() :
nullptr; MD;
274 MD = MD->getPrevious()) {
280 llvm::DenseSet<ModuleMacro *> Active(llvm::from_range,
281 ModuleInfo.ActiveModuleMacros);
282 llvm::DenseSet<ModuleMacro*> Visited;
284 while (!Worklist.empty()) {
285 auto *MM = Worklist.pop_back_val();
286 llvm::errs() <<
" ModuleMacro " << MM <<
" "
287 << MM->getOwningModule()->getFullModuleName();
288 if (!MM->getMacroInfo())
289 llvm::errs() <<
" undef";
291 if (Active.count(MM))
292 llvm::errs() <<
" active";
293 else if (!CurSubmoduleState->VisibleModules.isVisible(
294 MM->getOwningModule()))
295 llvm::errs() <<
" hidden";
296 else if (MM->getMacroInfo())
297 llvm::errs() <<
" overridden";
299 if (!MM->overrides().empty()) {
300 llvm::errs() <<
" overrides";
301 for (
auto *O : MM->overrides()) {
302 llvm::errs() <<
" " << O->getOwningModule()->getFullModuleName();
303 if (Visited.insert(O).second)
304 Worklist.push_back(O);
307 llvm::errs() <<
"\n";
308 if (
auto *MI = MM->getMacroInfo()) {
311 llvm::errs() <<
"\n";
318void Preprocessor::RegisterBuiltinMacros() {
319 Ident__LINE__ = RegisterBuiltinMacro(
"__LINE__");
320 Ident__FILE__ = RegisterBuiltinMacro(
"__FILE__");
324 Ident__DATE__ = RegisterBuiltinMacro(
"__DATE__");
325 Ident__TIME__ = RegisterBuiltinMacro(
"__TIME__");
327 Ident__DATE__ =
nullptr;
328 Ident__TIME__ =
nullptr;
330 Ident__COUNTER__ = RegisterBuiltinMacro(
"__COUNTER__");
331 Ident_Pragma = RegisterBuiltinMacro(
"_Pragma");
332 Ident__FLT_EVAL_METHOD__ = RegisterBuiltinMacro(
"__FLT_EVAL_METHOD__");
336 Ident__has_cpp_attribute = RegisterBuiltinMacro(
"__has_cpp_attribute");
338 Ident__has_cpp_attribute =
nullptr;
341 Ident__BASE_FILE__ = RegisterBuiltinMacro(
"__BASE_FILE__");
342 Ident__INCLUDE_LEVEL__ = RegisterBuiltinMacro(
"__INCLUDE_LEVEL__");
344 Ident__TIMESTAMP__ = RegisterBuiltinMacro(
"__TIMESTAMP__");
346 Ident__TIMESTAMP__ =
nullptr;
350 Ident__identifier = RegisterBuiltinMacro(
"__identifier");
351 Ident__pragma = RegisterBuiltinMacro(
"__pragma");
353 Ident__identifier =
nullptr;
354 Ident__pragma =
nullptr;
358 Ident__FILE_NAME__ = RegisterBuiltinMacro(
"__FILE_NAME__");
359 Ident__has_feature = RegisterBuiltinMacro(
"__has_feature");
360 Ident__has_extension = RegisterBuiltinMacro(
"__has_extension");
361 Ident__has_builtin = RegisterBuiltinMacro(
"__has_builtin");
362 Ident__has_constexpr_builtin =
363 RegisterBuiltinMacro(
"__has_constexpr_builtin");
364 Ident__has_attribute = RegisterBuiltinMacro(
"__has_attribute");
366 Ident__has_c_attribute = RegisterBuiltinMacro(
"__has_c_attribute");
368 Ident__has_c_attribute =
nullptr;
370 Ident__has_declspec = RegisterBuiltinMacro(
"__has_declspec_attribute");
371 Ident__has_embed = RegisterBuiltinMacro(
"__has_embed");
372 Ident__has_include = RegisterBuiltinMacro(
"__has_include");
373 Ident__has_include_next = RegisterBuiltinMacro(
"__has_include_next");
374 Ident__has_warning = RegisterBuiltinMacro(
"__has_warning");
375 Ident__is_identifier = RegisterBuiltinMacro(
"__is_identifier");
376 Ident__is_target_arch = RegisterBuiltinMacro(
"__is_target_arch");
377 Ident__is_target_vendor = RegisterBuiltinMacro(
"__is_target_vendor");
378 Ident__is_target_os = RegisterBuiltinMacro(
"__is_target_os");
379 Ident__is_target_environment =
380 RegisterBuiltinMacro(
"__is_target_environment");
381 Ident__is_target_variant_os = RegisterBuiltinMacro(
"__is_target_variant_os");
382 Ident__is_target_variant_environment =
383 RegisterBuiltinMacro(
"__is_target_variant_environment");
386 Ident__building_module = RegisterBuiltinMacro(
"__building_module");
388 Ident__MODULE__ = RegisterBuiltinMacro(
"__MODULE__");
390 Ident__MODULE__ =
nullptr;
401 if (!II)
return true;
411 if (ExpansionMI->isEnabled() &&
422 return !llvm::is_contained(MI->
params(), II);
427bool Preprocessor::HandleMacroExpandedIdentifier(
Token &Identifier,
436 if (CurPPLexer) CurPPLexer->MIOpt.ExpandedMacro();
441 Callbacks->MacroExpands(Identifier, M, Identifier.
getLocation(),
443 ExpandBuiltinMacro(Identifier);
454 SourceLocation ExpansionEnd = Identifier.
getLocation();
462 ArgMacro = &Identifier;
464 Args = ReadMacroCallArgumentList(Identifier, MI, ExpansionEnd);
471 if (!Args)
return true;
473 ++NumFnMacroExpanded;
482 SourceLocation ExpandLoc = Identifier.
getLocation();
483 SourceRange ExpansionRange(ExpandLoc, ExpansionEnd);
491 DelayedMacroExpandsCallbacks.push_back(
492 MacroExpandsInfo(Identifier, M, ExpansionRange));
494 Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args);
495 if (!DelayedMacroExpandsCallbacks.empty()) {
496 for (
const MacroExpandsInfo &Info : DelayedMacroExpandsCallbacks) {
498 Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range,
501 DelayedMacroExpandsCallbacks.clear();
508 Diag(Identifier, diag::warn_pp_ambiguous_macro)
525 if (Args) Args->
destroy(*
this);
530 PropagateLineStartLeadingSpaceInfo(Identifier);
531 ++NumFastMacroExpanded;
541 if (Args) Args->
destroy(*
this);
558 SourceMgr.createExpansionLoc(Identifier.
getLocation(), ExpandLoc,
566 if (!NewMI->isEnabled() || NewMI == MI) {
571 Diag(Identifier, diag::pp_disabled_macro_expansion);
577 ++NumFastMacroExpanded;
582 EnterMacro(Identifier, ExpansionEnd, MI, Args);
598 if (I->is(tok::l_paren)) {
599 Brackets.push_back(
Paren);
600 }
else if (I->is(tok::r_paren)) {
601 if (Brackets.empty() || Brackets.back() ==
Brace)
604 }
else if (I->is(tok::l_brace)) {
605 Brackets.push_back(
Brace);
606 }
else if (I->is(tok::r_brace)) {
607 if (Brackets.empty() || Brackets.back() ==
Paren)
612 return Brackets.empty();
646 bool FoundSeparatorToken =
false;
650 if (I->is(tok::l_brace)) {
652 }
else if (I->is(tok::r_brace)) {
654 if (
Braces == 0 && ClosingBrace == E && FoundSeparatorToken)
656 }
else if (I->is(tok::eof)) {
661 FoundSeparatorToken =
true;
662 I->setKind(tok::comma);
670 if (FoundSeparatorToken && ArgStartIterator->is(tok::l_brace)) {
678 if (FoundSeparatorToken) {
680 Token::create(tok::l_paren, ArgStartIterator->getLocation());
681 NewTokens.push_back(TempToken);
685 NewTokens.insert(NewTokens.end(), ArgStartIterator, I);
688 if (FoundSeparatorToken) {
691 NewTokens.push_back(TempToken);
692 ParenHints.push_back(
SourceRange(ArgStartIterator->getLocation(),
697 NewTokens.push_back(*I);
700 ArgStartIterator = I + 1;
701 FoundSeparatorToken =
false;
706 return !ParenHints.empty() && InitLists.empty();
713MacroArgs *Preprocessor::ReadMacroCallArgumentList(
Token &MacroName,
726 assert(
Tok.
is(tok::l_paren) &&
"Error computing l-paren-ness?");
731 SmallVector<Token, 64> ArgTokens;
732 bool ContainsCodeCompletionTok =
false;
733 bool FoundElidedComma =
false;
735 SourceLocation TooManyArgsLoc;
737 unsigned NumActuals = 0;
739 if (ContainsCodeCompletionTok &&
Tok.
isOneOf(tok::eof, tok::eod))
742 assert(
Tok.
isOneOf(tok::l_paren, tok::comma) &&
743 "only expect argument separators here");
745 size_t ArgTokenStart = ArgTokens.size();
750 unsigned NumParens = 0;
758 if (!ContainsCodeCompletionTok) {
759 Diag(MacroName, diag::err_unterm_macro_invoc);
767 auto Toks = std::make_unique<Token[]>(1);
769 EnterTokenStream(std::move(Toks), 1,
true,
false);
771 }
else if (
Tok.
is(tok::r_paren)) {
773 if (NumParens-- == 0) {
775 if (!ArgTokens.empty() &&
776 ArgTokens.back().commaAfterElided()) {
777 FoundElidedComma =
true;
781 }
else if (
Tok.
is(tok::l_paren)) {
783 }
else if (
Tok.
is(tok::comma)) {
794 }
else if (NumParens == 0) {
800 if (NumFixedArgsLeft > 1)
803 }
else if (
Tok.
is(tok::comment) && !KeepMacroComments) {
817 }
else if (
Tok.
is(tok::code_completion)) {
818 ContainsCodeCompletionTok =
true;
827 ArgTokens.push_back(
Tok);
832 if (ArgTokens.empty() &&
Tok.
getKind() == tok::r_paren)
837 if (!isVariadic && NumFixedArgsLeft == 0 && TooManyArgsLoc.
isInvalid()) {
838 if (ArgTokens.size() != ArgTokenStart)
839 TooManyArgsLoc = ArgTokens[ArgTokenStart].getLocation();
841 TooManyArgsLoc = ArgStartLoc;
850 Diag(
Tok, diag::ext_empty_fnmacro_arg);
855 ArgTokens.push_back(EOFTok);
857 if (!ContainsCodeCompletionTok && NumFixedArgsLeft != 0)
867 if (!isVariadic && NumActuals > MinArgsExpected &&
868 !ContainsCodeCompletionTok) {
871 Diag(TooManyArgsLoc, diag::err_too_many_args_in_macro_invoc);
880 SmallVector<Token, 4> FixedArgTokens;
881 unsigned FixedNumArgs = 0;
882 SmallVector<SourceRange, 4> ParenHints, InitLists;
884 ParenHints, InitLists)) {
885 if (!InitLists.empty()) {
886 DiagnosticBuilder DB =
888 diag::note_init_list_at_beginning_of_macro_argument);
889 for (SourceRange Range : InitLists)
894 if (FixedNumArgs != MinArgsExpected)
897 DiagnosticBuilder DB =
Diag(MacroName, diag::note_suggest_parens_for_macro);
898 for (SourceRange ParenLocation : ParenHints) {
902 ArgTokens.swap(FixedArgTokens);
903 NumActuals = FixedNumArgs;
907 bool isVarargsElided =
false;
909 if (ContainsCodeCompletionTok) {
912 for (; NumActuals < MinArgsExpected; ++NumActuals)
913 ArgTokens.push_back(EOFTok);
916 if (NumActuals < MinArgsExpected) {
918 if (NumActuals == 0 && MinArgsExpected == 1) {
925 }
else if ((FoundElidedComma || MI->
isVariadic()) &&
926 (NumActuals+1 == MinArgsExpected ||
927 (NumActuals == 0 && MinArgsExpected == 2))) {
941 ID = diag::warn_cxx17_compat_missing_varargs_arg;
943 ID = diag::ext_cxx_missing_varargs_arg;
945 ID = diag::warn_c17_compat_missing_varargs_arg;
947 ID = diag::ext_c_missing_varargs_arg;
959 isVarargsElided =
true;
960 }
else if (!ContainsCodeCompletionTok) {
962 Diag(
Tok, diag::err_too_few_args_in_macro_invoc);
971 ArgTokens.push_back(
Tok);
974 if (NumActuals == 0 && MinArgsExpected == 2)
975 ArgTokens.push_back(
Tok);
977 }
else if (NumActuals > MinArgsExpected && !MI->
isVariadic() &&
978 !ContainsCodeCompletionTok) {
981 Diag(MacroName, diag::err_too_many_args_in_macro_invoc);
1001 size_t newIndex = MacroExpandedTokens.size();
1002 bool cacheNeedsToGrow = tokens.size() >
1003 MacroExpandedTokens.capacity()-MacroExpandedTokens.size();
1004 MacroExpandedTokens.append(tokens.begin(), tokens.end());
1006 if (cacheNeedsToGrow) {
1009 for (
const auto &Lexer : MacroExpandingLexersStack) {
1010 TokenLexer *prevLexer;
1012 std::tie(prevLexer, tokIndex) = Lexer;
1013 prevLexer->Tokens = MacroExpandedTokens.data() + tokIndex;
1017 MacroExpandingLexersStack.push_back(std::make_pair(tokLexer, newIndex));
1018 return MacroExpandedTokens.data() + newIndex;
1021void Preprocessor::removeCachedMacroExpandedTokensOfLastLexer() {
1022 assert(!MacroExpandingLexersStack.empty());
1023 size_t tokIndex = MacroExpandingLexersStack.back().second;
1024 assert(tokIndex < MacroExpandedTokens.size());
1026 MacroExpandedTokens.resize(tokIndex);
1027 MacroExpandingLexersStack.pop_back();
1046 DATETokLen = strlen(
"\"1\"");
1054 TIMETokLen = strlen(
"\"1\"");
1063 TM = std::gmtime(&TT);
1065 TT = std::time(
nullptr);
1066 TM = std::localtime(&TT);
1069 static const char *
const Months[] = {
1070 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
1075 llvm::raw_svector_ostream TmpStream(TmpBuffer);
1077 TmpStream << llvm::format(
"\"%s %2d %4d\"", Months[TM->tm_mon],
1078 TM->tm_mday, TM->tm_year + 1900);
1080 TmpStream <<
"??? ?? ????";
1086 DATETokLen = strlen(
"\"Mmm dd yyyy\"");
1090 llvm::raw_svector_ostream TmpStream(TmpBuffer);
1092 TmpStream << llvm::format(
"\"%02d:%02d:%02d\"", TM->tm_hour, TM->tm_min,
1095 TmpStream <<
"??:??:??";
1101 TIMETokLen = strlen(
"\"hh:mm:ss\"");
1114#define FEATURE(Name, Predicate) .Case(#Name, Predicate)
1115 return llvm::StringSwitch<bool>(
Feature)
1116#include "clang/Basic/Features.def"
1137 if (Extension.starts_with(
"__") && Extension.ends_with(
"__") &&
1138 Extension.size() >= 4)
1139 Extension = Extension.substr(2, Extension.size() - 4);
1143#define EXTENSION(Name, Predicate) .Case(#Name, Predicate)
1144 return llvm::StringSwitch<bool>(Extension)
1145#include "clang/Basic/Features.def"
1163 PP.
Diag(LParenLoc, diag::err_pp_directive_required) << II;
1165 assert(
Tok.is(tok::identifier));
1166 Tok.setIdentifierInfo(II);
1174 }
while (
Tok.getKind() == tok::comment);
1177 if (
Tok.isNot(tok::l_paren)) {
1180 PP.
Diag(LParenLoc, diag::err_pp_expected_after) << II << tok::l_paren;
1183 if (
Tok.isNot(tok::header_name))
1187 LParenLoc =
Tok.getLocation();
1192 if (
Tok.isNot(tok::header_name)) {
1193 PP.
Diag(
Tok.getLocation(), diag::err_pp_expects_filename);
1210 if (
Tok.isNot(tok::r_paren)) {
1212 << II << tok::r_paren;
1213 PP.
Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1220 if (Filename.empty())
1230 PP.
LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile,
1231 nullptr,
nullptr,
nullptr, &KH,
nullptr,
nullptr);
1237 Callbacks->HasInclude(FilenameLoc, Filename, isAngled,
File,
FileType);
1241 return File.has_value();
1249 Diag(
Tok, diag::err_pp_directive_required) << II;
1251 assert(
Tok.
is(tok::identifier));
1259 Diag(
Tok, diag::err_pp_expected_after) << II << tok::l_paren;
1277 Token FilenameTok =
Tok;
1279 std::optional<LexEmbedParametersResult> Params =
1287 << II << tok::r_paren;
1288 Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1294 if (Params->UnrecognizedParams > 0)
1297 SmallString<128> FilenameBuffer;
1298 StringRef Filename = this->
getSpelling(FilenameTok, FilenameBuffer);
1299 if (Filename.empty())
1309 Callbacks->HasEmbed(LParenLoc, Filename, isAngled, MaybeFileEntry);
1311 if (!MaybeFileEntry)
1314 size_t FileSize = MaybeFileEntry->
getSize();
1317 if (Params->MaybeOffsetParam) {
1318 if (Params->MaybeOffsetParam->Offset > FileSize)
1321 FileSize -= Params->MaybeOffsetParam->Offset;
1326 if (Params->MaybeLimitParam) {
1327 if (Params->MaybeLimitParam->Limit > FileSize)
1330 FileSize = Params->MaybeLimitParam->Limit;
1346 const FileEntry *LookupFromFile;
1347 std::tie(Lookup, LookupFromFile) = getIncludeNextStart(
Tok);
1359 bool &HasLexedNextTok)> Op) {
1362 if (
Tok.isNot(tok::l_paren)) {
1363 PP.
Diag(
Tok.getLocation(), diag::err_pp_expected_after) << II
1367 if (!
Tok.isOneOf(tok::eof, tok::eod)) {
1369 Tok.setKind(tok::numeric_constant);
1374 unsigned ParenDepth = 1;
1376 std::optional<int>
Result;
1379 bool SuppressDiagnostic =
false;
1380 while (
Tok.isNoneOf(tok::eod, tok::eof)) {
1388 switch (
Tok.getKind()) {
1393 PP.
Diag(
Tok.getLocation(), diag::err_unterm_macro_invoc);
1397 if (!SuppressDiagnostic) {
1398 PP.
Diag(
Tok.getLocation(), diag::err_too_many_args_in_macro_invoc);
1399 SuppressDiagnostic =
true;
1407 if (!SuppressDiagnostic) {
1408 PP.
Diag(
Tok.getLocation(), diag::err_pp_nested_paren) << II;
1409 SuppressDiagnostic =
true;
1414 if (--ParenDepth > 0)
1427 if (!SuppressDiagnostic)
1428 PP.
Diag(
Tok.getLocation(), diag::err_too_few_args_in_macro_invoc);
1430 Tok.setKind(tok::numeric_constant);
1438 bool HasLexedNextToken =
false;
1441 if (HasLexedNextToken)
1448 if (!SuppressDiagnostic) {
1449 if (
auto Diag = PP.
Diag(
Tok.getLocation(), diag::err_pp_expected_after)) {
1456 PP.
Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1457 SuppressDiagnostic =
true;
1468 if (!
Tok.isAnnotation() && (II =
Tok.getIdentifierInfo()))
1471 PP.
Diag(
Tok.getLocation(), DiagID);
1478 const llvm::Triple &TT = TI.
getTriple();
1481 if ((
Arch.getSubArch() == llvm::Triple::NoSubArch ||
1482 Arch.getSubArch() == TT.getSubArch()) &&
1483 ((TT.getArch() == llvm::Triple::thumb &&
1484 Arch.getArch() == llvm::Triple::arm) ||
1485 (TT.getArch() == llvm::Triple::thumbeb &&
1486 Arch.getArch() == llvm::Triple::armeb)))
1491 return (
Arch.getSubArch() == llvm::Triple::NoSubArch ||
1492 Arch.getSubArch() == TT.getSubArch()) &&
1493 Arch.getArch() == TT.getArch();
1498 StringRef VendorName = TI.
getTriple().getVendorName();
1499 if (VendorName.empty())
1500 VendorName =
"unknown";
1501 return VendorName.equals_insensitive(II->
getName());
1506 llvm::Triple OS(llvm::Twine(
"unknown-unknown-") + II->
getName().lower());
1507 if (OS.getOS() == llvm::Triple::Darwin) {
1511 return TI.
getTriple().getOS() == OS.getOS();
1517 llvm::Triple Env(llvm::Twine(
"---") + II->
getName().lower());
1520 if (Env.getEnvironment() == llvm::Triple::UnknownEnvironment &&
1521 Env.getEnvironmentName() !=
"unknown")
1523 return TI.
getTriple().getEnvironment() == Env.getEnvironment();
1533 llvm::Triple OS(llvm::Twine(
"unknown-unknown-") + II->
getName().lower());
1534 if (OS.getOS() == llvm::Triple::Darwin) {
1536 return VariantTriple->isOSDarwin();
1538 return VariantTriple->getOS() == OS.getOS();
1550 llvm::Triple Env(llvm::Twine(
"---") + II->
getName().lower());
1551 return VariantTriple->getEnvironment() == Env.getEnvironment();
1556#if defined(__sun__) && defined(__svr4__) && defined(__clang__) && \
1562asm(
"_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
1563 "RSt8ios_basecPKSt2tmPKcSB_ = "
1564 "_ZNKSt8time_putIcSt19ostreambuf_iteratorIcSt11char_traitsIcEEE3putES3_"
1565 "RSt8ios_basecPK2tmPKcSB_");
1570#define TYPE_TRAIT_1(Spelling, Name, Key) \
1571 case tok::kw_##Spelling: \
1573#define TYPE_TRAIT_2(Spelling, Name, Key) \
1574 case tok::kw_##Spelling: \
1576#define TYPE_TRAIT_N(Spelling, Name, Key) \
1577 case tok::kw_##Spelling: \
1579#define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
1580 case tok::kw_##Spelling: \
1582#define EXPRESSION_TRAIT(Spelling, Name, Key) \
1583 case tok::kw_##Spelling: \
1585#define TRANSFORM_TYPE_TRAIT_DEF(K, Spelling) \
1586 case tok::kw___##Spelling: \
1589 switch (
Tok.getKind()) {
1592#include "clang/Basic/BuiltinTraits.inc"
1598void Preprocessor::ExpandBuiltinMacro(
Token &
Tok) {
1601 assert(II &&
"Can't be a macro without id info!");
1606 if (II == Ident_Pragma)
1607 return Handle_Pragma(
Tok);
1608 else if (II == Ident__pragma)
1609 return HandleMicrosoft__pragma(
Tok);
1611 ++NumBuiltinMacroExpanded;
1613 SmallString<128> TmpBuffer;
1614 llvm::raw_svector_ostream
OS(TmpBuffer);
1622 if (II == Ident__LINE__) {
1637 Loc = SourceMgr.getExpansionRange(Loc).getEnd();
1638 PresumedLoc PLoc = SourceMgr.getPresumedLoc(Loc);
1643 }
else if (II == Ident__FILE__ || II == Ident__BASE_FILE__ ||
1644 II == Ident__FILE_NAME__) {
1651 if (II == Ident__BASE_FILE__ && PLoc.
isValid()) {
1654 PLoc = SourceMgr.getPresumedLoc(NextLoc);
1663 SmallString<256> FN;
1667 if (II == Ident__FILE_NAME__) {
1674 OS <<
'"' << FN <<
'"';
1677 }
else if (II == Ident__DATE__) {
1680 size_t TIMETokLen = 0, DATETokLen = 0;
1688 }
else if (II == Ident__TIME__) {
1691 size_t TIMETokLen = 0, DATETokLen = 0;
1699 }
else if (II == Ident__INCLUDE_LEVEL__) {
1707 for (; PLoc.
isValid(); ++Depth)
1714 }
else if (II == Ident__TIMESTAMP__) {
1718 std::string
Result =
"1";
1719 std::stringstream TmpStream;
1723 TmpStream.imbue(std::locale(
"C"));
1726 std::tm *TM = std::gmtime(&TT);
1727 TmpStream << std::put_time(TM,
"%a %b %e %T %Y");
1731 const FileEntry *CurFile =
nullptr;
1733 CurFile = SourceMgr.getFileEntryForID(TheLexer->getFileID());
1736 struct tm *TM = localtime(&TT);
1737 TmpStream << std::put_time(TM,
"%a %b %e %T %Y");
1740 Result = TmpStream.str();
1742 Result =
"??? ??? ?? ??:??:?? ????";
1746 }
else if (II == Ident__FLT_EVAL_METHOD__) {
1754 Diag(
Tok, diag::err_illegal_use_of_flt_eval_macro);
1757 }
else if (II == Ident__COUNTER__) {
1762 constexpr uint32_t MaxPosValue = std::numeric_limits<int32_t>::max();
1763 if (CounterValue > MaxPosValue) {
1769 CounterValue = MaxPosValue;
1771 OS << CounterValue++;
1773 }
else if (II == Ident__has_feature) {
1775 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1777 diag::err_feature_check_malformed);
1780 }
else if (II == Ident__has_extension) {
1782 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1784 diag::err_feature_check_malformed);
1787 }
else if (II == Ident__has_builtin) {
1789 OS,
Tok, II, *
this,
false,
1790 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1792 Tok, *
this, diag::err_feature_check_malformed);
1796 if (BuiltinID != 0) {
1798 case Builtin::BI__builtin_cpu_is:
1800 case Builtin::BI__builtin_cpu_init:
1802 case Builtin::BI__builtin_cpu_supports:
1804 case Builtin::BI__builtin_operator_new:
1805 case Builtin::BI__builtin_operator_delete:
1820 }
else if (II->
getTokenID() != tok::identifier &&
1821 II->
getName().starts_with(
"__builtin_")) {
1824 return llvm::StringSwitch<bool>(II->
getName())
1826#define BuiltinTemplate(BTName) .Case(#BTName, getLangOpts().CPlusPlus)
1827#include "clang/Basic/BuiltinTemplates.inc"
1831 .Case(
"__is_target_arch",
true)
1832 .Case(
"__is_target_vendor",
true)
1833 .Case(
"__is_target_os",
true)
1834 .Case(
"__is_target_environment",
true)
1835 .Case(
"__is_target_variant_os",
true)
1836 .Case(
"__is_target_variant_environment",
true)
1840 }
else if (II == Ident__has_constexpr_builtin) {
1842 OS,
Tok, II, *
this,
false,
1843 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1845 Tok, *
this, diag::err_feature_check_malformed);
1849 return BuiltinOp != 0 &&
1852 }
else if (II == Ident__is_identifier) {
1854 [](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1855 return Tok.
is(tok::identifier);
1857 }
else if (II == Ident__has_attribute) {
1859 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1861 diag::err_feature_check_malformed);
1866 }
else if (II == Ident__has_declspec) {
1868 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1870 diag::err_feature_check_malformed);
1873 return LangOpts.DeclSpecKeyword &&
1880 }
else if (II == Ident__has_cpp_attribute ||
1881 II == Ident__has_c_attribute) {
1882 bool IsCXX = II == Ident__has_cpp_attribute;
1884 [&](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1885 IdentifierInfo *ScopeII =
nullptr;
1887 Tok, *
this, diag::err_feature_check_malformed);
1895 HasLexedNextToken =
true;
1901 diag::err_feature_check_malformed);
1911 }
else if (II == Ident__has_include ||
1912 II == Ident__has_include_next) {
1917 if (II == Ident__has_include)
1918 Value = EvaluateHasInclude(
Tok, II);
1920 Value = EvaluateHasIncludeNext(
Tok, II);
1926 }
else if (II == Ident__has_embed) {
1936 OS << static_cast<int>(
Value);
1937 }
else if (II == Ident__has_warning) {
1940 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1941 std::string WarningName;
1944 HasLexedNextToken =
Tok.
is(tok::string_literal);
1951 if (WarningName.size() < 3 || WarningName[0] !=
'-' ||
1952 WarningName[1] !=
'W') {
1953 Diag(StrStartLoc, diag::warn_has_warning_invalid_option);
1961 SmallVector<diag::kind, 10> Diags;
1964 WarningName.substr(2), Diags);
1966 }
else if (II == Ident__building_module) {
1971 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
1973 diag::err_expected_id_building_module);
1977 }
else if (II == Ident__MODULE__) {
1983 }
else if (II == Ident__identifier) {
1992 << II << tok::l_paren;
2023 if (RParen.
isNot(tok::r_paren)) {
2026 Diag(LParenLoc, diag::note_matching) << tok::l_paren;
2029 }
else if (II == Ident__is_target_arch) {
2031 OS,
Tok, II, *
this,
false,
2032 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
2034 Tok, *
this, diag::err_feature_check_malformed);
2037 }
else if (II == Ident__is_target_vendor) {
2039 OS,
Tok, II, *
this,
false,
2040 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
2042 Tok, *
this, diag::err_feature_check_malformed);
2045 }
else if (II == Ident__is_target_os) {
2047 OS,
Tok, II, *
this,
false,
2048 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
2050 Tok, *
this, diag::err_feature_check_malformed);
2053 }
else if (II == Ident__is_target_environment) {
2055 OS,
Tok, II, *
this,
false,
2056 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
2058 Tok, *
this, diag::err_feature_check_malformed);
2061 }
else if (II == Ident__is_target_variant_os) {
2063 OS,
Tok, II, *
this,
false,
2064 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
2066 Tok, *
this, diag::err_feature_check_malformed);
2069 }
else if (II == Ident__is_target_variant_environment) {
2071 OS,
Tok, II, *
this,
false,
2072 [
this](Token &
Tok,
bool &HasLexedNextToken) ->
int {
2074 Tok, *
this, diag::err_feature_check_malformed);
2078 llvm_unreachable(
"Unknown identifier!");
2097 LangOpts.remapPathPrefix(Path);
2098 if (LangOpts.UseTargetPathSeparator) {
2100 llvm::sys::path::remove_dots(Path,
false,
2101 llvm::sys::path::Style::windows_backslash);
2103 llvm::sys::path::remove_dots(Path,
false, llvm::sys::path::Style::posix);
2113 StringRef PLFileName = llvm::sys::path::filename(PLoc.
getFilename());
2114 if (PLFileName.empty())
2116 FileName.append(PLFileName.begin(), PLFileName.end());
Defines enum values for all the target-independent builtin functions.
static bool getDiagnosticsInGroup(diag::Flavor Flavor, const WarningOption *Group, SmallVectorImpl< diag::kind > &Diags, diag::CustomDiagInfo *CustomDiagInfo)
Return true if any diagnostics were found in this group, even if they were filtered out due to having...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Result
Implement __builtin_bit_cast and related operations.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::FileType FileType
Defines the clang::MacroInfo and clang::MacroDirective classes.
static bool HasExtension(const Preprocessor &PP, StringRef Extension)
HasExtension - Return true if we recognize and implement the feature specified by the identifier,...
static bool CheckMatchedBrackets(const SmallVectorImpl< Token > &Tokens)
CheckMatchedBrackets - Returns true if the braces and parentheses in the token vector are properly ne...
static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II, Preprocessor &PP, ConstSearchDirIterator LookupFrom, const FileEntry *LookupFromFile)
EvaluateHasIncludeCommon - Process a '__has_include("path")' or '__has_include_next("path")' expressi...
static bool GenerateNewArgTokens(Preprocessor &PP, SmallVectorImpl< Token > &OldTokens, SmallVectorImpl< Token > &NewTokens, unsigned &NumArgs, SmallVectorImpl< SourceRange > &ParenHints, SmallVectorImpl< SourceRange > &InitLists)
GenerateNewArgTokens - Returns true if OldTokens can be converted to a new vector of tokens in NewTok...
static bool isTargetVariantOS(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_variant_os builtin macro.
static bool isTrivialSingleTokenExpansion(const MacroInfo *MI, const IdentifierInfo *MacroIdent, Preprocessor &PP)
isTrivialSingleTokenExpansion - Return true if MI, which has a single token in its expansion,...
static bool isTargetArch(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_arch builtin macro.
static bool isTargetVariantEnvironment(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_variant_environment builtin macro.
static bool isTargetEnvironment(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_environment builtin macro.
static bool IsBuiltinTrait(Token &Tok)
static bool isTargetOS(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_os builtin macro.
static bool isTargetVendor(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_vendor builtin macro.
static void ComputeDATE_TIME(SourceLocation &DATELoc, size_t &DATETokLen, SourceLocation &TIMELoc, size_t &TIMETokLen, Preprocessor &PP)
ComputeDATE_TIME - Compute the current time, enter it into the specified scratch buffer,...
static void EvaluateFeatureLikeBuiltinMacro(llvm::raw_svector_ostream &OS, Token &Tok, IdentifierInfo *II, Preprocessor &PP, bool ExpandArgs, llvm::function_ref< int(Token &Tok, bool &HasLexedNextTok)> Op)
Process single-argument builtin feature-like macros that return integer values.
static bool HasFeature(const Preprocessor &PP, StringRef Feature)
HasFeature - Return true if we recognize and implement the feature specified by the identifier as a s...
static IdentifierInfo * ExpectFeatureIdentifierInfo(Token &Tok, Preprocessor &PP, signed DiagID)
Helper function to return the IdentifierInfo structure of a Token or generate a diagnostic if none av...
Defines the PreprocessorLexer interface.
Defines the clang::Preprocessor interface.
Defines the clang::SourceLocation class and associated facilities.
Syntax
The style used to specify an attribute.
@ AS_Declspec
__declspec(...)
bool isConstantEvaluated(unsigned ID) const
Return true if this function can be constant evaluated by Clang frontend.
diag::Severity getExtensionHandlingBehavior() const
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
virtual void updateOutOfDateIdentifier(const IdentifierInfo &II)=0
Update an out-of-date identifier.
Cached information about one file (either on disk or in the virtual file system).
time_t getModificationTime() const
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
void setHasMacroDefinition(bool Val)
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
StringRef getName() const
Return the actual identifier string.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool isCompilingModule() const
Are we compiling a module?
std::string CurrentModule
The name of the current module, of which the main source file is a part.
static std::string Stringify(StringRef Str, bool Charify=false)
Stringify - Convert the specified string into a C string by i) escaping '\' and " characters and ii) ...
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
static MacroArgs * create(const MacroInfo *MI, ArrayRef< Token > UnexpArgTokens, bool VarargsElided, Preprocessor &PP)
MacroArgs ctor function - Create a new MacroArgs object with the specified macro and argument info.
void destroy(Preprocessor &PP)
destroy - Destroy and deallocate the memory for this object.
A description of the current definition of a macro.
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
void forAllDefinitions(Fn F) const
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
Encapsulates the data about a macro definition (e.g.
bool isIdenticalTo(const MacroInfo &Other, Preprocessor &PP, bool Syntactically) const
Return true if the specified macro definition is equal to this macro in spelling, arguments,...
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used.
bool isFunctionLike() const
ArrayRef< const IdentifierInfo * > params() const
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
unsigned getNumParams() const
const Token & getReplacementToken(unsigned Tok) const
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
bool hasCommaPasting() const
bool isObjectLike() const
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
bool isEnabled() const
Return true if this macro is enabled.
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
Represents a macro directive exported by a module.
static ModuleMacro * create(Preprocessor &PP, Module *OwningModule, const IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides)
Describes a module or submodule.
This interface provides a way to observe the actions of the preprocessor as it does its thing.
DateTimeInitKind InitDateTimeMacros
Specify initialization kind for DATE, TIME and TIMESTAMP macros.
std::optional< uint64_t > SourceDateEpoch
If set, the UNIX timestamp specified by SOURCE_DATE_EPOCH.
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
SourceLocation getLastFPEvalPragmaLocation() const
bool FinishLexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Complete the lexing of a string literal where the first token has already been lexed (see LexStringLi...
void dumpMacroInfo(const IdentifierInfo *II)
ModuleMacro * addModuleMacro(Module *Mod, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides, bool &IsNew)
Register an exported macro for a module and identifier.
void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD)
Set a MacroDirective that was loaded from a PCH file.
PPCallbacks * getPPCallbacks() const
SourceRange DiscardUntilEndOfDirective(SmallVectorImpl< Token > *DiscardedToks=nullptr)
Read and discard all tokens remaining on the current line until the tok::eod token is found.
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
DiagnosticBuilder DiagCompat(SourceLocation Loc, unsigned CompatDiagID) const
void CreateString(StringRef Str, Token &Tok, SourceLocation ExpansionLocStart=SourceLocation(), SourceLocation ExpansionLocEnd=SourceLocation())
Plop the specified string into a scratch buffer and set the specified token's location and length to ...
void markMacroAsUsed(MacroInfo *MI)
A macro is used, update information about macros that need unused warnings.
MacroDirective * getLocalMacroDirectiveHistory(const IdentifierInfo *II) const
Given an identifier, return the latest non-imported macro directive for that identifier.
void Lex(Token &Result)
Lex the next token for this preprocessor.
bool isParsingIfOrElifDirective() const
True if we are currently preprocessing a if or elif directive.
void LexNonComment(Token &Result)
Lex a token.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
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...
OptionalFileEntryRef LookupEmbedFile(StringRef Filename, bool isAngled, bool OpenFile)
Given a "Filename" or <Filename> reference, look up the indicated embed resource.
static void processPathToFileName(SmallVectorImpl< char > &FileName, const PresumedLoc &PLoc, const LangOptions &LangOpts, const TargetInfo &TI)
const TargetInfo & getTargetInfo() const
bool LexHeaderName(Token &Result, bool AllowMacroExpansion=true)
Lex a token, forming a header-name token if possible.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
ModuleMacro * getModuleMacro(Module *Mod, const IdentifierInfo *II)
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 ...
bool GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Buffer)
Turn the specified lexer token into a fully checked and spelled filename, e.g.
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
HeaderSearch & getHeaderSearchInfo() const
void emitMacroExpansionWarnings(const Token &Identifier, bool IsIfnDef=false) const
ExternalPreprocessorSource * getExternalSource() const
OptionalFileEntryRef LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false, bool OpenFile=true, bool CacheFailures=true)
Given a "foo" or <foo> reference, look up the indicated file.
Builtin::Context & getBuiltinInfo()
const PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
LangOptions::FPEvalMethodKind getTUFPEvalMethod() const
const LangOptions & getLangOpts() const
static void processPathForFileMacro(SmallVectorImpl< char > &Path, const LangOptions &LangOpts, const TargetInfo &TI)
DiagnosticsEngine & getDiagnostics() const
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
std::optional< LexEmbedParametersResult > LexEmbedParameters(Token &Current, bool ForHasEmbed)
Lex the parameters for an embed directive, returns nullopt on error.
void EnterMacro(Token &Tok, SourceLocation ILEnd, MacroInfo *Macro, MacroArgs *Args)
Add a Macro to the top of the include stack and start lexing tokens from it instead of the current bu...
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD)
Add a directive to the macro directive history for this identifier.
Represents an unpacked "presumed" location which can be presented to the user.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
SourceLocation getIncludeLoc() const
Return the presumed include location of this location.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
Exposes information about the current target.
virtual bool supportsCpuSupports() const
virtual bool supportsCpuInit() const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
const llvm::Triple * getDarwinTargetVariantTriple() const
Returns the darwin target variant triple, the variant of the deployment target for which the code is ...
virtual bool supportsCpuIs() const
TokenLexer - This implements a lexer that returns tokens from a macro body or token stream instead of...
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
unsigned getFlags() const
Return the internal represtation of the flags.
void clearFlag(TokenFlags Flag)
Unset the specified flag.
static Token create(tok::TokenKind Kind, SourceLocation Loc, unsigned Length=0)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
unsigned getLength() const
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
static Token createEof(SourceLocation Loc=SourceLocation(), const void *Data=nullptr)
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)) {....
tok::TokenKind getKind() const
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
bool isOneOf(Ts... Ks) const
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
void setLocation(SourceLocation L)
bool isNot(tok::TokenKind K) const
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix.
void startToken()
Reset all flags to cleared.
void setIdentifierInfo(IdentifierInfo *II)
void setFlagValue(TokenFlags Flag, bool Val)
Set a flag to either true or false.
void setFlag(TokenFlags Flag)
Set the specified flag.
unsigned getGeneration() const
Get the current visibility generation.
Defines the clang::TargetInfo interface.
bool evaluateRequiredTargetFeatures(llvm::StringRef RequiredFatures, const llvm::StringMap< bool > &TargetFetureMap)
Returns true if the required target features of a builtin function are enabled.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
uint32_t Literal
Literals are represented as positive integers.
@ WarningOrError
A diagnostic that indicates a problem or potential problem.
@ Error
Present this diagnostic as an error.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
Top level wrappers for InstallAPI frontend operations.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
int hasAttribute(AttributeCommonInfo::Syntax Syntax, llvm::StringRef ScopeName, llvm::StringRef AttrName, const TargetInfo &Target, const LangOptions &LangOpts, bool CheckPlugins)
Return the version number associated with the attribute if we recognize and implement the attribute s...
detail::SearchDirIteratorImpl< true > ConstSearchDirIterator
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Default
Set to the current date and time.
@ Undefined
Keep undefined.
@ LiteralOne
Set to literal string "1".
@ Result
The result type of a method or function.
@ Braces
New-expression has a C++11 list-initializer.