33 #include "llvm/ADT/ArrayRef.h" 34 #include "llvm/ADT/DenseMap.h" 35 #include "llvm/ADT/DenseSet.h" 36 #include "llvm/ADT/FoldingSet.h" 37 #include "llvm/ADT/None.h" 38 #include "llvm/ADT/Optional.h" 39 #include "llvm/ADT/SmallString.h" 40 #include "llvm/ADT/SmallVector.h" 41 #include "llvm/ADT/STLExtras.h" 42 #include "llvm/ADT/StringRef.h" 43 #include "llvm/ADT/StringSwitch.h" 44 #include "llvm/Config/llvm-config.h" 45 #include "llvm/Support/Casting.h" 46 #include "llvm/Support/ErrorHandling.h" 47 #include "llvm/Support/Format.h" 48 #include "llvm/Support/raw_ostream.h" 58 using namespace clang;
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.find(II) == LeafModuleMacros.end())
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.find(II) == LeafModuleMacros.end())
134 llvm::FoldingSetNodeID
ID;
138 if (
auto *MM = ModuleMacros.FindNodeOrInsertPos(ID, InsertPos)) {
144 ModuleMacros.InsertNode(MM, InsertPos);
148 for (
auto *O : Overrides) {
149 HidAny |= (O->NumOverriddenBy == 0);
150 ++O->NumOverriddenBy;
154 auto &LeafMacros = LeafModuleMacros[II];
156 LeafMacros.erase(std::remove_if(LeafMacros.begin(), LeafMacros.end(),
158 return MM->NumOverriddenBy != 0;
164 LeafMacros.push_back(MM);
173 llvm::FoldingSetNodeID
ID;
177 return ModuleMacros.FindNodeOrInsertPos(ID, InsertPos);
180 void Preprocessor::updateModuleMacroInfo(
const IdentifierInfo *II,
181 ModuleMacroInfo &Info) {
182 assert(Info.ActiveModuleMacrosGeneration !=
183 CurSubmoduleState->VisibleModules.getGeneration() &&
184 "don't need to update this macro name info");
185 Info.ActiveModuleMacrosGeneration =
186 CurSubmoduleState->VisibleModules.getGeneration();
188 auto Leaf = LeafModuleMacros.find(II);
189 if (Leaf == LeafModuleMacros.end()) {
194 Info.ActiveModuleMacros.clear();
197 llvm::DenseMap<ModuleMacro *, int> NumHiddenOverrides;
198 for (
auto *O : Info.OverriddenMacros)
199 NumHiddenOverrides[O] = -1;
203 for (
auto *LeafMM : Leaf->second) {
204 assert(LeafMM->getNumOverridingMacros() == 0 &&
"leaf macro overridden");
205 if (NumHiddenOverrides.lookup(LeafMM) == 0)
206 Worklist.push_back(LeafMM);
208 while (!Worklist.empty()) {
209 auto *MM = Worklist.pop_back_val();
210 if (CurSubmoduleState->VisibleModules.isVisible(MM->getOwningModule())) {
213 if (MM->getMacroInfo())
214 Info.ActiveModuleMacros.push_back(MM);
216 for (
auto *O : MM->overrides())
217 if ((
unsigned)++NumHiddenOverrides[O] == O->getNumOverridingMacros())
218 Worklist.push_back(O);
222 std::reverse(Info.ActiveModuleMacros.begin(), Info.ActiveModuleMacros.end());
226 bool IsSystemMacro =
true;
227 bool IsAmbiguous =
false;
228 if (
auto *MD = Info.MD) {
229 while (MD && isa<VisibilityMacroDirective>(MD))
230 MD = MD->getPrevious();
231 if (
auto *DMD = dyn_cast_or_null<DefMacroDirective>(MD)) {
236 for (
auto *Active : Info.ActiveModuleMacros) {
237 auto *NewMI = Active->getMacroInfo();
248 if (MI && NewMI != MI &&
249 !MI->isIdenticalTo(*NewMI, *
this,
true))
251 IsSystemMacro &= Active->getOwningModule()->IsSystem ||
255 Info.IsAmbiguous = IsAmbiguous && !IsSystemMacro;
260 auto LeafIt = LeafModuleMacros.find(II);
261 if (LeafIt != LeafModuleMacros.end())
262 Leaf = LeafIt->second;
263 const MacroState *
State =
nullptr;
264 auto Pos = CurSubmoduleState->Macros.find(II);
265 if (Pos != CurSubmoduleState->Macros.end())
266 State = &Pos->second;
270 llvm::errs() <<
" ambiguous";
271 if (
State && !
State->getOverriddenMacros().empty()) {
272 llvm::errs() <<
" overrides";
273 for (
auto *O :
State->getOverriddenMacros())
274 llvm::errs() <<
" " << O->getOwningModule()->getFullModuleName();
276 llvm::errs() <<
"\n";
279 for (
auto *MD =
State ?
State->getLatest() :
nullptr; MD;
280 MD = MD->getPrevious()) {
287 for (
auto *MM :
State ?
State->getActiveModuleMacros(*
this, II) :
None)
291 while (!Worklist.empty()) {
292 auto *MM = Worklist.pop_back_val();
293 llvm::errs() <<
" ModuleMacro " << MM <<
" " 294 << MM->getOwningModule()->getFullModuleName();
295 if (!MM->getMacroInfo())
296 llvm::errs() <<
" undef";
298 if (Active.count(MM))
299 llvm::errs() <<
" active";
300 else if (!CurSubmoduleState->VisibleModules.isVisible(
301 MM->getOwningModule()))
302 llvm::errs() <<
" hidden";
303 else if (MM->getMacroInfo())
304 llvm::errs() <<
" overridden";
306 if (!MM->overrides().empty()) {
307 llvm::errs() <<
" overrides";
308 for (
auto *O : MM->overrides()) {
309 llvm::errs() <<
" " << O->getOwningModule()->getFullModuleName();
310 if (Visited.insert(O).second)
311 Worklist.push_back(O);
314 llvm::errs() <<
"\n";
315 if (
auto *MI = MM->getMacroInfo()) {
318 llvm::errs() <<
"\n";
338 void Preprocessor::RegisterBuiltinMacros() {
347 if (LangOpts.CPlusPlus)
348 Ident__has_cpp_attribute =
351 Ident__has_cpp_attribute =
nullptr;
359 if (LangOpts.MicrosoftExt) {
363 Ident__identifier =
nullptr;
364 Ident__pragma =
nullptr;
381 Ident__is_target_environment =
389 Ident__MODULE__ =
nullptr;
400 if (!II)
return true;
410 if (ExpansionMI->isEnabled() &&
427 bool Preprocessor::isNextPPTokenLParen() {
431 Val = CurLexer->isNextPPTokenLParen();
432 else if (CurPTHLexer)
433 Val = CurPTHLexer->isNextPPTokenLParen();
435 Val = CurTokenLexer->isNextTokenLParen();
443 for (
const IncludeStackInfo &Entry : llvm::reverse(IncludeMacroStack)) {
445 Val = Entry.TheLexer->isNextPPTokenLParen();
446 else if (Entry.ThePTHLexer)
447 Val = Entry.ThePTHLexer->isNextPPTokenLParen();
449 Val = Entry.TheTokenLexer->isNextTokenLParen();
455 if (Entry.ThePPLexer)
468 bool Preprocessor::HandleMacroExpandedIdentifier(
Token &Identifier,
480 Callbacks->MacroExpands(Identifier, M, Identifier.
getLocation(),
482 ExpandBuiltinMacro(Identifier);
501 Args = ReadMacroCallArgumentList(Identifier, MI, ExpansionEnd);
507 if (!Args)
return true;
509 ++NumFnMacroExpanded;
519 SourceRange ExpansionRange(ExpandLoc, ExpansionEnd);
527 DelayedMacroExpandsCallbacks.push_back(
528 MacroExpandsInfo(Identifier, M, ExpansionRange));
530 Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args);
531 if (!DelayedMacroExpandsCallbacks.empty()) {
532 for (
const MacroExpandsInfo &Info : DelayedMacroExpandsCallbacks) {
534 Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range,
537 DelayedMacroExpandsCallbacks.clear();
544 Diag(Identifier, diag::warn_pp_ambiguous_macro)
561 if (Args) Args->
destroy(*
this);
566 PropagateLineStartLeadingSpaceInfo(Identifier);
567 ++NumFastMacroExpanded;
577 if (Args) Args->
destroy(*
this);
602 if (!NewMI->isEnabled() || NewMI == MI) {
607 Diag(Identifier, diag::pp_disabled_macro_expansion);
613 ++NumFastMacroExpanded;
618 EnterMacro(Identifier, ExpansionEnd, MI, Args);
634 if (I->is(tok::l_paren)) {
635 Brackets.push_back(
Paren);
636 }
else if (I->is(tok::r_paren)) {
637 if (Brackets.empty() || Brackets.back() ==
Brace)
640 }
else if (I->is(tok::l_brace)) {
641 Brackets.push_back(
Brace);
642 }
else if (I->is(tok::r_brace)) {
643 if (Brackets.empty() || Brackets.back() ==
Paren)
648 return Brackets.empty();
682 bool FoundSeparatorToken =
false;
686 if (I->is(tok::l_brace)) {
688 }
else if (I->is(tok::r_brace)) {
690 if (Braces == 0 && ClosingBrace == E && FoundSeparatorToken)
697 FoundSeparatorToken =
true;
698 I->setKind(tok::comma);
706 if (FoundSeparatorToken && ArgStartIterator->is(tok::l_brace)) {
714 if (FoundSeparatorToken) {
716 TempToken.
setKind(tok::l_paren);
717 TempToken.
setLocation(ArgStartIterator->getLocation());
719 NewTokens.push_back(TempToken);
723 NewTokens.insert(NewTokens.end(), ArgStartIterator, I);
726 if (FoundSeparatorToken) {
729 TempToken.
setKind(tok::r_paren);
732 NewTokens.push_back(TempToken);
733 ParenHints.push_back(
SourceRange(ArgStartIterator->getLocation(),
738 NewTokens.push_back(*I);
741 ArgStartIterator = I + 1;
742 FoundSeparatorToken =
false;
747 return !ParenHints.empty() && InitLists.empty();
754 MacroArgs *Preprocessor::ReadMacroCallArgumentList(
Token &MacroName,
767 assert(Tok.
is(tok::l_paren) &&
"Error computing l-paren-ness?");
773 bool ContainsCodeCompletionTok =
false;
774 bool FoundElidedComma =
false;
778 unsigned NumActuals = 0;
779 while (Tok.
isNot(tok::r_paren)) {
783 assert(Tok.
isOneOf(tok::l_paren, tok::comma) &&
784 "only expect argument separators here");
786 size_t ArgTokenStart = ArgTokens.size();
791 unsigned NumParens = 0;
799 if (!ContainsCodeCompletionTok) {
800 Diag(MacroName, diag::err_unterm_macro_invoc);
808 auto Toks = llvm::make_unique<Token[]>(1);
810 EnterTokenStream(std::move(Toks), 1,
true);
812 }
else if (Tok.
is(tok::r_paren)) {
814 if (NumParens-- == 0) {
816 if (!ArgTokens.empty() &&
817 ArgTokens.back().commaAfterElided()) {
818 FoundElidedComma =
true;
822 }
else if (Tok.
is(tok::l_paren)) {
824 }
else if (Tok.
is(tok::comma) && NumParens == 0 &&
833 if (!isVariadic)
break;
834 if (NumFixedArgsLeft > 1)
836 }
else if (Tok.
is(tok::comment) && !KeepMacroComments) {
850 }
else if (Tok.
is(tok::code_completion)) {
851 ContainsCodeCompletionTok =
true;
860 ArgTokens.push_back(Tok);
865 if (ArgTokens.empty() && Tok.
getKind() == tok::r_paren)
870 if (!isVariadic && NumFixedArgsLeft == 0 && TooManyArgsLoc.
isInvalid()) {
871 if (ArgTokens.size() != ArgTokenStart)
872 TooManyArgsLoc = ArgTokens[ArgTokenStart].getLocation();
874 TooManyArgsLoc = ArgStartLoc;
879 if (ArgTokens.size() == ArgTokenStart && !LangOpts.C99)
880 Diag(Tok, LangOpts.CPlusPlus11 ?
881 diag::warn_cxx98_compat_empty_fnmacro_arg :
882 diag::ext_empty_fnmacro_arg);
890 ArgTokens.push_back(EOFTok);
892 if (!ContainsCodeCompletionTok && NumFixedArgsLeft != 0)
902 if (!isVariadic && NumActuals > MinArgsExpected &&
903 !ContainsCodeCompletionTok) {
906 Diag(TooManyArgsLoc, diag::err_too_many_args_in_macro_invoc);
916 unsigned FixedNumArgs = 0;
919 ParenHints, InitLists)) {
920 if (!InitLists.empty()) {
923 diag::note_init_list_at_beginning_of_macro_argument);
929 if (FixedNumArgs != MinArgsExpected)
937 ArgTokens.swap(FixedArgTokens);
938 NumActuals = FixedNumArgs;
942 bool isVarargsElided =
false;
944 if (ContainsCodeCompletionTok) {
951 for (; NumActuals < MinArgsExpected; ++NumActuals)
952 ArgTokens.push_back(EOFTok);
955 if (NumActuals < MinArgsExpected) {
957 if (NumActuals == 0 && MinArgsExpected == 1) {
964 }
else if ((FoundElidedComma || MI->
isVariadic()) &&
965 (NumActuals+1 == MinArgsExpected ||
966 (NumActuals == 0 && MinArgsExpected == 2))) {
974 Diag(Tok, diag::ext_missing_varargs_arg);
985 isVarargsElided =
true;
986 }
else if (!ContainsCodeCompletionTok) {
988 Diag(Tok, diag::err_too_few_args_in_macro_invoc);
1000 ArgTokens.push_back(Tok);
1003 if (NumActuals == 0 && MinArgsExpected == 2)
1004 ArgTokens.push_back(Tok);
1006 }
else if (NumActuals > MinArgsExpected && !MI->
isVariadic() &&
1007 !ContainsCodeCompletionTok) {
1010 Diag(MacroName, diag::err_too_many_args_in_macro_invoc);
1030 size_t newIndex = MacroExpandedTokens.size();
1031 bool cacheNeedsToGrow = tokens.size() >
1032 MacroExpandedTokens.capacity()-MacroExpandedTokens.size();
1033 MacroExpandedTokens.append(tokens.begin(), tokens.end());
1035 if (cacheNeedsToGrow) {
1038 for (
const auto &
Lexer : MacroExpandingLexersStack) {
1041 std::tie(prevLexer, tokIndex) =
Lexer;
1042 prevLexer->Tokens = MacroExpandedTokens.data() + tokIndex;
1046 MacroExpandingLexersStack.push_back(std::make_pair(tokLexer, newIndex));
1047 return MacroExpandedTokens.data() + newIndex;
1050 void Preprocessor::removeCachedMacroExpandedTokensOfLastLexer() {
1051 assert(!MacroExpandingLexersStack.empty());
1052 size_t tokIndex = MacroExpandingLexersStack.back().second;
1053 assert(tokIndex < MacroExpandedTokens.size());
1055 MacroExpandedTokens.resize(tokIndex);
1056 MacroExpandingLexersStack.pop_back();
1064 time_t TT = time(
nullptr);
1065 struct tm *TM = localtime(&TT);
1067 static const char *
const Months[] = {
1068 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" 1073 llvm::raw_svector_ostream TmpStream(TmpBuffer);
1074 TmpStream << llvm::format(
"\"%s %2d %4d\"", Months[TM->tm_mon],
1075 TM->tm_mday, TM->tm_year + 1900);
1084 llvm::raw_svector_ostream TmpStream(TmpBuffer);
1085 TmpStream << llvm::format(
"\"%02d:%02d:%02d\"",
1086 TM->tm_hour, TM->tm_min, TM->tm_sec);
1100 if (Feature.startswith(
"__") && Feature.endswith(
"__") && Feature.size() >= 4)
1101 Feature = Feature.substr(2, Feature.size() - 4);
1103 return llvm::StringSwitch<bool>(Feature)
1104 .Case(
"address_sanitizer",
1106 SanitizerKind::KernelAddress))
1107 .Case(
"hwaddress_sanitizer",
1109 .Case(
"assume_nonnull",
true)
1110 .Case(
"attribute_analyzer_noreturn",
true)
1111 .Case(
"attribute_availability",
true)
1112 .Case(
"attribute_availability_with_message",
true)
1113 .Case(
"attribute_availability_app_extension",
true)
1114 .Case(
"attribute_availability_with_version_underscores",
true)
1115 .Case(
"attribute_availability_tvos",
true)
1116 .Case(
"attribute_availability_watchos",
true)
1117 .Case(
"attribute_availability_with_strict",
true)
1118 .Case(
"attribute_availability_with_replacement",
true)
1119 .Case(
"attribute_availability_in_templates",
true)
1120 .Case(
"attribute_cf_returns_not_retained",
true)
1121 .Case(
"attribute_cf_returns_retained",
true)
1122 .Case(
"attribute_cf_returns_on_parameters",
true)
1123 .Case(
"attribute_deprecated_with_message",
true)
1124 .Case(
"attribute_deprecated_with_replacement",
true)
1125 .Case(
"attribute_ext_vector_type",
true)
1126 .Case(
"attribute_ns_returns_not_retained",
true)
1127 .Case(
"attribute_ns_returns_retained",
true)
1128 .Case(
"attribute_ns_consumes_self",
true)
1129 .Case(
"attribute_ns_consumed",
true)
1130 .Case(
"attribute_cf_consumed",
true)
1131 .Case(
"attribute_objc_ivar_unused",
true)
1132 .Case(
"attribute_objc_method_family",
true)
1133 .Case(
"attribute_overloadable",
true)
1134 .Case(
"attribute_unavailable_with_message",
true)
1135 .Case(
"attribute_unused_on_fields",
true)
1136 .Case(
"attribute_diagnose_if_objc",
true)
1137 .Case(
"blocks", LangOpts.Blocks)
1138 .Case(
"c_thread_safety_attributes",
true)
1139 .Case(
"cxx_exceptions", LangOpts.CXXExceptions)
1140 .Case(
"cxx_rtti", LangOpts.RTTI && LangOpts.RTTIData)
1141 .Case(
"enumerator_attributes",
true)
1142 .Case(
"nullability",
true)
1143 .Case(
"nullability_on_arrays",
true)
1144 .Case(
"memory_sanitizer", LangOpts.
Sanitize.
has(SanitizerKind::Memory))
1145 .Case(
"thread_sanitizer", LangOpts.
Sanitize.
has(SanitizerKind::Thread))
1146 .Case(
"dataflow_sanitizer",
1148 .Case(
"efficiency_sanitizer",
1152 .Case(
"objc_arr", LangOpts.ObjCAutoRefCount)
1153 .Case(
"objc_arc", LangOpts.ObjCAutoRefCount)
1154 .Case(
"objc_arc_weak", LangOpts.ObjCWeak)
1155 .Case(
"objc_default_synthesize_properties", LangOpts.ObjC2)
1156 .Case(
"objc_fixed_enum", LangOpts.ObjC2)
1157 .Case(
"objc_instancetype", LangOpts.ObjC2)
1158 .Case(
"objc_kindof", LangOpts.ObjC2)
1159 .Case(
"objc_modules", LangOpts.ObjC2 && LangOpts.Modules)
1161 .Case(
"objc_property_explicit_atomic",
1163 .Case(
"objc_protocol_qualifier_mangling",
true)
1165 .Case(
"ownership_holds",
true)
1166 .Case(
"ownership_returns",
true)
1167 .Case(
"ownership_takes",
true)
1168 .Case(
"objc_bool",
true)
1170 .Case(
"objc_array_literals", LangOpts.ObjC2)
1171 .Case(
"objc_dictionary_literals", LangOpts.ObjC2)
1172 .Case(
"objc_boxed_expressions", LangOpts.ObjC2)
1173 .Case(
"objc_boxed_nsvalue_expressions", LangOpts.ObjC2)
1174 .Case(
"arc_cf_code_audited",
true)
1175 .Case(
"objc_bridge_id",
true)
1176 .Case(
"objc_bridge_id_on_typedefs",
true)
1177 .Case(
"objc_generics", LangOpts.ObjC2)
1178 .Case(
"objc_generics_variance", LangOpts.ObjC2)
1179 .Case(
"objc_class_property", LangOpts.ObjC2)
1181 .Case(
"c_alignas", LangOpts.C11)
1182 .Case(
"c_alignof", LangOpts.C11)
1183 .Case(
"c_atomic", LangOpts.C11)
1184 .Case(
"c_generic_selections", LangOpts.C11)
1185 .Case(
"c_static_assert", LangOpts.C11)
1186 .Case(
"c_thread_local",
1189 .Case(
"cxx_access_control_sfinae", LangOpts.CPlusPlus11)
1190 .Case(
"cxx_alias_templates", LangOpts.CPlusPlus11)
1191 .Case(
"cxx_alignas", LangOpts.CPlusPlus11)
1192 .Case(
"cxx_alignof", LangOpts.CPlusPlus11)
1193 .Case(
"cxx_atomic", LangOpts.CPlusPlus11)
1194 .Case(
"cxx_attributes", LangOpts.CPlusPlus11)
1195 .Case(
"cxx_auto_type", LangOpts.CPlusPlus11)
1196 .Case(
"cxx_constexpr", LangOpts.CPlusPlus11)
1197 .Case(
"cxx_constexpr_string_builtins", LangOpts.CPlusPlus11)
1198 .Case(
"cxx_decltype", LangOpts.CPlusPlus11)
1199 .Case(
"cxx_decltype_incomplete_return_types", LangOpts.CPlusPlus11)
1200 .Case(
"cxx_default_function_template_args", LangOpts.CPlusPlus11)
1201 .Case(
"cxx_defaulted_functions", LangOpts.CPlusPlus11)
1202 .Case(
"cxx_delegating_constructors", LangOpts.CPlusPlus11)
1203 .Case(
"cxx_deleted_functions", LangOpts.CPlusPlus11)
1204 .Case(
"cxx_explicit_conversions", LangOpts.CPlusPlus11)
1205 .Case(
"cxx_generalized_initializers", LangOpts.CPlusPlus11)
1206 .Case(
"cxx_implicit_moves", LangOpts.CPlusPlus11)
1207 .Case(
"cxx_inheriting_constructors", LangOpts.CPlusPlus11)
1208 .Case(
"cxx_inline_namespaces", LangOpts.CPlusPlus11)
1209 .Case(
"cxx_lambdas", LangOpts.CPlusPlus11)
1210 .Case(
"cxx_local_type_template_args", LangOpts.CPlusPlus11)
1211 .Case(
"cxx_nonstatic_member_init", LangOpts.CPlusPlus11)
1212 .Case(
"cxx_noexcept", LangOpts.CPlusPlus11)
1213 .Case(
"cxx_nullptr", LangOpts.CPlusPlus11)
1214 .Case(
"cxx_override_control", LangOpts.CPlusPlus11)
1215 .Case(
"cxx_range_for", LangOpts.CPlusPlus11)
1216 .Case(
"cxx_raw_string_literals", LangOpts.CPlusPlus11)
1217 .Case(
"cxx_reference_qualified_functions", LangOpts.CPlusPlus11)
1218 .Case(
"cxx_rvalue_references", LangOpts.CPlusPlus11)
1219 .Case(
"cxx_strong_enums", LangOpts.CPlusPlus11)
1220 .Case(
"cxx_static_assert", LangOpts.CPlusPlus11)
1221 .Case(
"cxx_thread_local",
1223 .Case(
"cxx_trailing_return", LangOpts.CPlusPlus11)
1224 .Case(
"cxx_unicode_literals", LangOpts.CPlusPlus11)
1225 .Case(
"cxx_unrestricted_unions", LangOpts.CPlusPlus11)
1226 .Case(
"cxx_user_literals", LangOpts.CPlusPlus11)
1227 .Case(
"cxx_variadic_templates", LangOpts.CPlusPlus11)
1229 .Case(
"cxx_aggregate_nsdmi", LangOpts.CPlusPlus14)
1230 .Case(
"cxx_binary_literals", LangOpts.CPlusPlus14)
1231 .Case(
"cxx_contextual_conversions", LangOpts.CPlusPlus14)
1232 .Case(
"cxx_decltype_auto", LangOpts.CPlusPlus14)
1233 .Case(
"cxx_generic_lambdas", LangOpts.CPlusPlus14)
1234 .Case(
"cxx_init_captures", LangOpts.CPlusPlus14)
1235 .Case(
"cxx_relaxed_constexpr", LangOpts.CPlusPlus14)
1236 .Case(
"cxx_return_type_deduction", LangOpts.CPlusPlus14)
1237 .Case(
"cxx_variable_templates", LangOpts.CPlusPlus14)
1249 .Case(
"has_nothrow_assign", LangOpts.CPlusPlus)
1250 .Case(
"has_nothrow_copy", LangOpts.CPlusPlus)
1251 .Case(
"has_nothrow_constructor", LangOpts.CPlusPlus)
1252 .Case(
"has_trivial_assign", LangOpts.CPlusPlus)
1253 .Case(
"has_trivial_copy", LangOpts.CPlusPlus)
1254 .Case(
"has_trivial_constructor", LangOpts.CPlusPlus)
1255 .Case(
"has_trivial_destructor", LangOpts.CPlusPlus)
1256 .Case(
"has_virtual_destructor", LangOpts.CPlusPlus)
1257 .Case(
"is_abstract", LangOpts.CPlusPlus)
1258 .Case(
"is_base_of", LangOpts.CPlusPlus)
1259 .Case(
"is_class", LangOpts.CPlusPlus)
1260 .Case(
"is_constructible", LangOpts.CPlusPlus)
1261 .Case(
"is_convertible_to", LangOpts.CPlusPlus)
1262 .Case(
"is_empty", LangOpts.CPlusPlus)
1263 .Case(
"is_enum", LangOpts.CPlusPlus)
1264 .Case(
"is_final", LangOpts.CPlusPlus)
1265 .Case(
"is_literal", LangOpts.CPlusPlus)
1266 .Case(
"is_standard_layout", LangOpts.CPlusPlus)
1267 .Case(
"is_pod", LangOpts.CPlusPlus)
1268 .Case(
"is_polymorphic", LangOpts.CPlusPlus)
1269 .Case(
"is_sealed", LangOpts.CPlusPlus && LangOpts.MicrosoftExt)
1270 .Case(
"is_trivial", LangOpts.CPlusPlus)
1271 .Case(
"is_trivially_assignable", LangOpts.CPlusPlus)
1272 .Case(
"is_trivially_constructible", LangOpts.CPlusPlus)
1273 .Case(
"is_trivially_copyable", LangOpts.CPlusPlus)
1274 .Case(
"is_union", LangOpts.CPlusPlus)
1275 .Case(
"modules", LangOpts.Modules)
1276 .Case(
"safe_stack", LangOpts.
Sanitize.
has(SanitizerKind::SafeStack))
1278 .Case(
"underlying_type", LangOpts.CPlusPlus)
1298 if (Extension.startswith(
"__") && Extension.endswith(
"__") &&
1299 Extension.size() >= 4)
1300 Extension = Extension.substr(2, Extension.size() - 4);
1304 return llvm::StringSwitch<bool>(Extension)
1306 .Case(
"c_alignas",
true)
1307 .Case(
"c_alignof",
true)
1308 .Case(
"c_atomic",
true)
1309 .Case(
"c_generic_selections",
true)
1310 .Case(
"c_static_assert",
true)
1313 .Case(
"cxx_atomic", LangOpts.CPlusPlus)
1314 .Case(
"cxx_deleted_functions", LangOpts.CPlusPlus)
1315 .Case(
"cxx_explicit_conversions", LangOpts.CPlusPlus)
1316 .Case(
"cxx_inline_namespaces", LangOpts.CPlusPlus)
1317 .Case(
"cxx_local_type_template_args", LangOpts.CPlusPlus)
1318 .Case(
"cxx_nonstatic_member_init", LangOpts.CPlusPlus)
1319 .Case(
"cxx_override_control", LangOpts.CPlusPlus)
1320 .Case(
"cxx_range_for", LangOpts.CPlusPlus)
1321 .Case(
"cxx_reference_qualified_functions", LangOpts.CPlusPlus)
1322 .Case(
"cxx_rvalue_references", LangOpts.CPlusPlus)
1323 .Case(
"cxx_variadic_templates", LangOpts.CPlusPlus)
1325 .Case(
"cxx_binary_literals",
true)
1326 .Case(
"cxx_init_captures", LangOpts.CPlusPlus11)
1327 .Case(
"cxx_variable_templates", LangOpts.CPlusPlus)
1329 .Case(
"overloadable_unmarked",
true)
1346 PP.
Diag(LParenLoc, diag::err_pp_directive_required) << II->
getName();
1348 assert(Tok.
is(tok::identifier));
1357 if (Tok.
isNot(tok::l_paren)) {
1360 PP.
Diag(LParenLoc, diag::err_pp_expected_after) << II << tok::l_paren;
1363 if (!Tok.
is(tok::angle_string_literal) && !Tok.
is(tok::string_literal) &&
1390 case tok::angle_string_literal:
1391 case tok::string_literal: {
1392 bool Invalid =
false;
1393 Filename = PP.
getSpelling(Tok, FilenameBuffer, &Invalid);
1402 FilenameBuffer.push_back(
'<');
1408 Filename = FilenameBuffer;
1421 if (Tok.
isNot(tok::r_paren)) {
1423 << II << tok::r_paren;
1424 PP.
Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1431 if (Filename.empty())
1437 PP.
LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile,
1438 CurDir,
nullptr,
nullptr,
nullptr,
nullptr);
1441 return File !=
nullptr;
1461 const FileEntry *LookupFromFile =
nullptr;
1468 PP.
Diag(Tok, diag::pp_include_next_in_primary);
1475 }
else if (!Lookup) {
1476 PP.
Diag(Tok, diag::pp_include_next_absolute_path);
1492 bool &HasLexedNextTok)> Op) {
1495 if (Tok.
isNot(tok::l_paren)) {
1502 Tok.
setKind(tok::numeric_constant);
1507 unsigned ParenDepth = 1;
1512 bool SuppressDiagnostic =
false;
1527 if (!SuppressDiagnostic) {
1529 SuppressDiagnostic =
true;
1535 if (Result.hasValue())
1537 if (!SuppressDiagnostic) {
1539 SuppressDiagnostic =
true;
1544 if (--ParenDepth > 0)
1549 if (Result.hasValue())
1550 OS << Result.getValue();
1553 if (!SuppressDiagnostic)
1556 Tok.
setKind(tok::numeric_constant);
1561 if (Result.hasValue())
1564 bool HasLexedNextToken =
false;
1565 Result = Op(Tok, HasLexedNextToken);
1567 if (HasLexedNextToken)
1574 if (!SuppressDiagnostic) {
1582 PP.
Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1583 SuppressDiagnostic =
true;
1603 std::string ArchName = II->
getName().lower() +
"--";
1604 llvm::Triple Arch(ArchName);
1605 const llvm::Triple &TT = TI.
getTriple();
1608 if ((Arch.getSubArch() == llvm::Triple::NoSubArch ||
1609 Arch.getSubArch() == TT.getSubArch()) &&
1610 ((TT.getArch() == llvm::Triple::thumb &&
1611 Arch.getArch() == llvm::Triple::arm) ||
1612 (TT.getArch() == llvm::Triple::thumbeb &&
1613 Arch.getArch() == llvm::Triple::armeb)))
1618 return (Arch.getSubArch() == llvm::Triple::NoSubArch ||
1619 Arch.getSubArch() == TT.getSubArch()) &&
1620 Arch.getArch() == TT.getArch();
1625 StringRef VendorName = TI.
getTriple().getVendorName();
1626 if (VendorName.empty())
1627 VendorName =
"unknown";
1628 return VendorName.equals_lower(II->
getName());
1633 std::string OSName =
1634 (llvm::Twine(
"unknown-unknown-") + II->
getName().lower()).str();
1635 llvm::Triple OS(OSName);
1636 if (OS.getOS() == llvm::Triple::Darwin) {
1640 return TI.
getTriple().getOS() == OS.getOS();
1646 std::string EnvName = (llvm::Twine(
"---") + II->
getName().lower()).str();
1647 llvm::Triple Env(EnvName);
1648 return TI.
getTriple().getEnvironment() == Env.getEnvironment();
1653 void Preprocessor::ExpandBuiltinMacro(
Token &Tok) {
1656 assert(II &&
"Can't be a macro without id info!");
1660 if (II == Ident_Pragma)
1661 return Handle_Pragma(Tok);
1662 else if (II == Ident__pragma)
1663 return HandleMicrosoft__pragma(Tok);
1665 ++NumBuiltinMacroExpanded;
1668 llvm::raw_svector_ostream OS(TmpBuffer);
1674 if (II == Ident__LINE__) {
1694 Tok.
setKind(tok::numeric_constant);
1695 }
else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
1702 if (II == Ident__BASE_FILE__ && PLoc.
isValid()) {
1718 OS <<
'"' << FN <<
'"';
1720 Tok.
setKind(tok::string_literal);
1721 }
else if (II == Ident__DATE__) {
1725 Tok.
setKind(tok::string_literal);
1726 Tok.
setLength(strlen(
"\"Mmm dd yyyy\""));
1731 }
else if (II == Ident__TIME__) {
1735 Tok.
setKind(tok::string_literal);
1741 }
else if (II == Ident__INCLUDE_LEVEL__) {
1755 Tok.
setKind(tok::numeric_constant);
1756 }
else if (II == Ident__TIMESTAMP__) {
1771 time_t TT = CurFile->getModificationTime();
1772 struct tm *TM = localtime(&TT);
1773 Result = asctime(TM);
1775 Result =
"??? ??? ?? ??:??:?? ????\n";
1778 OS <<
'"' << StringRef(Result).drop_back() <<
'"';
1779 Tok.
setKind(tok::string_literal);
1780 }
else if (II == Ident__COUNTER__) {
1782 OS << CounterValue++;
1783 Tok.
setKind(tok::numeric_constant);
1784 }
else if (II == Ident__has_feature) {
1786 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1788 diag::err_feature_check_malformed);
1791 }
else if (II == Ident__has_extension) {
1793 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1795 diag::err_feature_check_malformed);
1798 }
else if (II == Ident__has_builtin) {
1800 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1802 diag::err_feature_check_malformed);
1809 return llvm::StringSwitch<bool>(II->
getName())
1810 .Case(
"__make_integer_seq", LangOpts.CPlusPlus)
1811 .Case(
"__type_pack_element", LangOpts.CPlusPlus)
1812 .Case(
"__builtin_available",
true)
1813 .Case(
"__is_target_arch",
true)
1814 .Case(
"__is_target_vendor",
true)
1815 .Case(
"__is_target_os",
true)
1816 .Case(
"__is_target_environment",
true)
1820 }
else if (II == Ident__is_identifier) {
1822 [](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1823 return Tok.
is(tok::identifier);
1825 }
else if (II == Ident__has_attribute) {
1827 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1829 diag::err_feature_check_malformed);
1833 }
else if (II == Ident__has_declspec) {
1835 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1837 diag::err_feature_check_malformed);
1841 }
else if (II == Ident__has_cpp_attribute ||
1842 II == Ident__has_c_attribute) {
1843 bool IsCXX = II == Ident__has_cpp_attribute;
1845 OS, Tok, II, *
this, [&](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1848 Tok, *
this, diag::err_feature_check_malformed);
1855 if (Tok.
isNot(tok::coloncolon))
1856 HasLexedNextToken =
true;
1861 diag::err_feature_check_malformed);
1869 }
else if (II == Ident__has_include ||
1870 II == Ident__has_include_next) {
1875 if (II == Ident__has_include)
1880 if (Tok.
isNot(tok::r_paren))
1883 Tok.
setKind(tok::numeric_constant);
1884 }
else if (II == Ident__has_warning) {
1887 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1888 std::string WarningName;
1891 HasLexedNextToken = Tok.
is(tok::string_literal);
1898 if (WarningName.size() < 3 || WarningName[0] !=
'-' ||
1899 WarningName[1] !=
'W') {
1900 Diag(StrStartLoc, diag::warn_has_warning_invalid_option);
1911 WarningName.substr(2), Diags);
1913 }
else if (II == Ident__building_module) {
1918 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1920 diag::err_expected_id_building_module);
1924 }
else if (II == Ident__MODULE__) {
1930 }
else if (II == Ident__identifier) {
1936 if (Tok.
isNot(tok::l_paren)) {
1939 << II << tok::l_paren;
1962 if (RParen.
isNot(tok::r_paren)) {
1964 << Tok.
getKind() << tok::r_paren;
1965 Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1968 }
else if (II == Ident__is_target_arch) {
1970 OS, Tok, II, *
this, [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1972 Tok, *
this, diag::err_feature_check_malformed);
1975 }
else if (II == Ident__is_target_vendor) {
1977 OS, Tok, II, *
this, [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1979 Tok, *
this, diag::err_feature_check_malformed);
1982 }
else if (II == Ident__is_target_os) {
1984 OS, Tok, II, *
this, [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1986 Tok, *
this, diag::err_feature_check_malformed);
1989 }
else if (II == Ident__is_target_environment) {
1991 OS, Tok, II, *
this, [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1993 Tok, *
this, diag::err_feature_check_malformed);
1997 llvm_unreachable(
"Unknown identifier!");
A diagnostic that indicates a problem or potential problem.
static IdentifierInfo * RegisterBuiltinMacro(Preprocessor &PP, const char *Name)
RegisterBuiltinMacro - Register the specified identifier in the identifier table and mark it as a bui...
static bool CheckMatchedBrackets(const SmallVectorImpl< Token > &Tokens)
CheckMatchedBrackets - Returns true if the braces and parentheses in the token vector are properly ne...
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens...
MacroInfo * AllocateMacroInfo(SourceLocation L)
Allocate a new MacroInfo object with the provided SourceLocation.
param_iterator param_begin() const
bool ConcatenateIncludeName(SmallString< 128 > &FilenameBuffer, SourceLocation &End)
Handle cases where the #include name is expanded from a macro as multiple tokens, which need to be gl...
void setChangedSinceDeserialization()
Note that this identifier has changed since it was loaded from an AST file.
void markMacroAsUsed(MacroInfo *MI)
A macro is used, update information about macros that need unused warnings.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
void setFlagValue(TokenFlags Flag, bool Val)
Set a flag to either true or false.
Defines the clang::FileManager interface and associated types.
SanitizerSet Sanitize
Set of enabled sanitizers.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
ModuleMacro * addModuleMacro(Module *Mod, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro *> Overrides, bool &IsNew)
Register an exported macro for a module and identifier.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
void dumpMacroInfo(const IdentifierInfo *II)
bool isEnabled() const
Return true if this macro is enabled.
Is the identifier known as a __declspec-style attribute?
bool isInPrimaryFile() const
Return true if we're in the top-level file, not in a #include.
static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II, Preprocessor &PP, const DirectoryLookup *LookupFrom, const FileEntry *LookupFromFile)
EvaluateHasIncludeCommon - Process a '__has_include("path")' or '__has_include_next("path")' expressi...
Defines the clang::MacroInfo and clang::MacroDirective classes.
Is the identifier known as a GNU-style attribute?
Defines types useful for describing an Objective-C runtime.
A description of the current definition of a macro.
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...
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
static bool isTargetEnvironment(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_environment builtin macro.
void setFlag(TokenFlags Flag)
Set the specified flag.
bool isCompilingModule() const
Are we compiling a module interface (.cppm or module map)?
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
diag::Severity getExtensionHandlingBehavior() const
const FileEntry * LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const FileEntry *FromFile, const DirectoryLookup *&CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool SkipCache=false)
Given a "foo" or <foo> reference, look up the indicated file.
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
tok::TokenKind getKind() const
bool hasWeakClassImport() const
Does this runtime support weakly importing classes?
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
DefMacroDirective * appendDefMacroDirective(IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
One of these records is kept for each identifier that is lexed.
Represents a macro directive exported by a module.
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...
void setHasMacroDefinition(bool Val)
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
static bool isTargetOS(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_os builtin macro.
static bool getDiagnosticsInGroup(diag::Flavor Flavor, const WarningOption *Group, SmallVectorImpl< diag::kind > &Diags)
Return true if any diagnostics were found in this group, even if they were filtered out due to having...
bool hasCommaPasting() const
const TargetInfo & getTargetInfo() const
Token - This structure provides full information about a lexed token.
void setKind(tok::TokenKind K)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const LangOptions & getLangOpts() const
Describes a module or submodule.
static void ComputeDATE_TIME(SourceLocation &DATELoc, SourceLocation &TIMELoc, Preprocessor &PP)
ComputeDATE_TIME - Compute the current time, enter it into the specified scratch buffer, then return DATELoc/TIMELoc locations with the position of the identifier tokens inserted.
param_iterator param_end() const
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...
Module * getCurrentLexerSubmodule() const
Return the submodule owning the file being lexed.
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
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...
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 ...
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
static void EvaluateFeatureLikeBuiltinMacro(llvm::raw_svector_ostream &OS, Token &Tok, IdentifierInfo *II, Preprocessor &PP, llvm::function_ref< int(Token &Tok, bool &HasLexedNextTok)> Op)
Process single-argument builtin feature-like macros that return integer values.
const Token & getReplacementToken(unsigned Tok) const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void LexNonComment(Token &Result)
Lex a token.
void ExpandedMacro()
ExpandedMacro - When a macro is expanded with this lexer as the current buffer, this method is called...
static bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II, Preprocessor &PP)
EvaluateHasInclude - Process a '__has_include("path")' expression.
void destroy(Preprocessor &PP)
destroy - Destroy and deallocate the memory for this object.
TokenLexer - This implements a lexer that returns tokens from a macro body or token stream instead of...
Present this diagnostic as an error.
int hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, const IdentifierInfo *Attr, const TargetInfo &Target, const LangOptions &LangOpts)
Return the version number associated with the attribute if we recognize and implement the attribute s...
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used. ...
void appendMacroDirective(IdentifierInfo *II, MacroDirective *MD)
Add a directive to the macro directive history for this identifier.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
A little helper class used to produce diagnostics.
std::string CurrentModule
The name of the current module, of which the main source file is a part.
unsigned getNumParams() const
Exposes information about the current target.
Defines the clang::LangOptions interface.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
static bool isTargetVendor(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_vendor builtin macro.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
unsigned getLine() const
Return the presumed line number of this location.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::Preprocessor interface.
MultipleIncludeOpt MIOpt
A state machine that detects the #ifndef-wrapping a file idiom for the multiple-include optimization...
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
clang::ObjCRuntime ObjCRuntime
Represents an unpacked "presumed" location which can be presented to the user.
SourceLocation createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, int LoadedID=0, unsigned LoadedOffset=0)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
bool isObjectLike() const
The result type of a method or function.
static bool HasExtension(const Preprocessor &PP, StringRef Extension)
HasExtension - Return true if we recognize and implement the feature specified by the identifier...
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
const DirectoryLookup * GetCurDirLookup()
Get the DirectoryLookup structure used to find the current FileEntry, if CurLexer is non-null and if ...
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
const char * getFilename() const
Return the presumed filename of this location.
ExternalPreprocessorSource * getExternalSource() const
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Encodes a location in the source.
static bool isTargetArch(const TargetInfo &TI, const IdentifierInfo *II)
Implements the __is_target_arch 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...
void setLength(unsigned Len)
MacroDirective * getLocalMacroDirectiveHistory(const IdentifierInfo *II) const
Given an identifier, return the latest non-imported macro directive for that identifier.
static bool EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II, Preprocessor &PP)
EvaluateHasIncludeNext - Process '__has_include_next("path")' expression.
IdentifierInfo * getIdentifierInfo() const
Cached information about one file (either on disk or in the virtual file system). ...
void setIdentifierInfo(IdentifierInfo *II)
void setIsBuiltinMacro(bool Val=true)
Set or clear the isBuiltinMacro flag.
void Lex(Token &Result)
Lex the next token for this preprocessor.
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD)
Set a MacroDirective that was loaded from a PCH file.
void EnterMacro(Token &Identifier, 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...
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
PreprocessorLexer * getCurrentLexer() const
Return the current lexer being lexed from.
StringRef getName() const
Return the actual identifier string.
bool isNot(tok::TokenKind K) const
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
Dataflow Directional Tag Classes.
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
bool isFunctionLike() const
const FileEntry * getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
std::pair< SourceLocation, SourceLocation > getExpansionRange(SourceLocation Loc) const
Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate fi...
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i...
unsigned getLength() const
Encapsulates the data about a macro definition (e.g.
static ModuleMacro * create(Preprocessor &PP, Module *OwningModule, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro *> Overrides)
bool GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Filename)
Turn the specified lexer token into a fully checked and spelled filename, e.g.
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...
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)=0
Update an out-of-date identifier.
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 ...
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.
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
void LexIncludeFilename(Token &Result)
After the preprocessor has parsed a #include, lex and (potentially) macro expand the filename...
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
Defines the clang::SourceLocation class and associated facilities.
ModuleMacro * getModuleMacro(Module *Mod, IdentifierInfo *II)
DiagnosticsEngine & getDiagnostics() const
bool isAmbiguous() const
true if the definition is ambiguous, false otherwise.
bool isTLSSupported() const
Whether the target supports thread-local storage.
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...
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
Defines the clang::TargetInfo interface.
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
void forAllDefinitions(Fn F) const
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
void setLocation(SourceLocation L)
bool isParsingIfOrElifDirective() const
True if we are currently preprocessing a if or #elif directive.
A trivial tuple used to represent a source range.
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
unsigned getFlags() const
Return the internal represtation of the flags.
void clearFlag(TokenFlags Flag)
Unset the specified flag.
SourceLocation getIncludeLoc() const
Return the presumed include location of this location.
Defines the PreprocessorLexer interface.
virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned ArgumentIndex)
Callback invoked when performing code completion inside a function-like macro argument.
void Profile(llvm::FoldingSetNodeID &ID) const
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
void startToken()
Reset all flags to cleared.
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) ...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.