25 #include "llvm/ADT/STLExtras.h"
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/ADT/StringSwitch.h"
28 #include "llvm/Config/llvm-config.h"
29 #include "llvm/Support/ErrorHandling.h"
30 #include "llvm/Support/Format.h"
31 #include "llvm/Support/raw_ostream.h"
34 using namespace clang;
40 auto Pos = CurSubmoduleState->Macros.find(II);
41 return Pos == CurSubmoduleState->Macros.end() ?
nullptr
42 : Pos->second.getLatest();
46 assert(MD &&
"MacroDirective should be non-zero!");
47 assert(!MD->
getPrevious() &&
"Already attached to a MacroDirective history.");
49 MacroState &StoredMD = CurSubmoduleState->Macros[II];
50 auto *OldMD = StoredMD.getLatest();
52 StoredMD.setLatest(MD);
53 StoredMD.overrideActiveModuleMacros(*
this, II);
57 if (!MD->
isDefined() && LeafModuleMacros.find(II) == LeafModuleMacros.end())
66 MacroState &StoredMD = CurSubmoduleState->Macros[II];
67 assert(!StoredMD.getLatest() &&
68 "the macro history was modified before initializing it from a pch");
72 if (!MD->
isDefined() && LeafModuleMacros.find(II) == LeafModuleMacros.end())
80 llvm::FoldingSetNodeID
ID;
84 if (
auto *MM = ModuleMacros.FindNodeOrInsertPos(ID, InsertPos)) {
90 ModuleMacros.InsertNode(MM, InsertPos);
94 for (
auto *O : Overrides) {
95 HidAny |= (O->NumOverriddenBy == 0);
100 auto &LeafMacros = LeafModuleMacros[II];
102 LeafMacros.erase(std::remove_if(LeafMacros.begin(), LeafMacros.end(),
104 return MM->NumOverriddenBy != 0;
110 LeafMacros.push_back(MM);
119 llvm::FoldingSetNodeID
ID;
123 return ModuleMacros.FindNodeOrInsertPos(ID, InsertPos);
126 void Preprocessor::updateModuleMacroInfo(
const IdentifierInfo *II,
127 ModuleMacroInfo &Info) {
128 assert(Info.ActiveModuleMacrosGeneration !=
129 CurSubmoduleState->VisibleModules.getGeneration() &&
130 "don't need to update this macro name info");
131 Info.ActiveModuleMacrosGeneration =
132 CurSubmoduleState->VisibleModules.getGeneration();
134 auto Leaf = LeafModuleMacros.find(II);
135 if (Leaf == LeafModuleMacros.end()) {
140 Info.ActiveModuleMacros.clear();
143 llvm::DenseMap<ModuleMacro *, int> NumHiddenOverrides;
144 for (
auto *O : Info.OverriddenMacros)
145 NumHiddenOverrides[O] = -1;
150 while (!Worklist.empty()) {
151 auto *MM = Worklist.pop_back_val();
152 if (CurSubmoduleState->VisibleModules.isVisible(MM->getOwningModule())) {
155 if (MM->getMacroInfo())
156 Info.ActiveModuleMacros.push_back(MM);
158 for (
auto *O : MM->overrides())
159 if ((
unsigned)++NumHiddenOverrides[O] == O->getNumOverridingMacros())
160 Worklist.push_back(O);
164 std::reverse(Info.ActiveModuleMacros.begin(), Info.ActiveModuleMacros.end());
168 bool IsSystemMacro =
true;
169 bool IsAmbiguous =
false;
170 if (
auto *MD = Info.MD) {
171 while (MD && isa<VisibilityMacroDirective>(MD))
172 MD = MD->getPrevious();
173 if (
auto *DMD = dyn_cast_or_null<DefMacroDirective>(MD)) {
178 for (
auto *Active : Info.ActiveModuleMacros) {
179 auto *NewMI = Active->getMacroInfo();
190 if (MI && NewMI != MI &&
191 !MI->isIdenticalTo(*NewMI, *
this,
true))
193 IsSystemMacro &= Active->getOwningModule()->IsSystem ||
197 Info.IsAmbiguous = IsAmbiguous && !IsSystemMacro;
202 auto LeafIt = LeafModuleMacros.find(II);
203 if (LeafIt != LeafModuleMacros.end())
204 Leaf = LeafIt->second;
205 const MacroState *
State =
nullptr;
206 auto Pos = CurSubmoduleState->Macros.find(II);
207 if (Pos != CurSubmoduleState->Macros.end())
208 State = &Pos->second;
212 llvm::errs() <<
" ambiguous";
213 if (
State && !
State->getOverriddenMacros().empty()) {
214 llvm::errs() <<
" overrides";
215 for (
auto *O :
State->getOverriddenMacros())
216 llvm::errs() <<
" " << O->getOwningModule()->getFullModuleName();
218 llvm::errs() <<
"\n";
221 for (
auto *MD =
State ?
State->getLatest() :
nullptr; MD;
222 MD = MD->getPrevious()) {
229 for (
auto *MM :
State ?
State->getActiveModuleMacros(*
this, II) :
None)
233 while (!Worklist.empty()) {
234 auto *MM = Worklist.pop_back_val();
235 llvm::errs() <<
" ModuleMacro " << MM <<
" "
236 << MM->getOwningModule()->getFullModuleName();
237 if (!MM->getMacroInfo())
238 llvm::errs() <<
" undef";
240 if (Active.count(MM))
241 llvm::errs() <<
" active";
242 else if (!CurSubmoduleState->VisibleModules.isVisible(
243 MM->getOwningModule()))
244 llvm::errs() <<
" hidden";
245 else if (MM->getMacroInfo())
246 llvm::errs() <<
" overridden";
248 if (!MM->overrides().empty()) {
249 llvm::errs() <<
" overrides";
250 for (
auto *O : MM->overrides()) {
251 llvm::errs() <<
" " << O->getOwningModule()->getFullModuleName();
252 if (Visited.insert(O).second)
253 Worklist.push_back(O);
256 llvm::errs() <<
"\n";
257 if (
auto *MI = MM->getMacroInfo()) {
260 llvm::errs() <<
"\n";
281 void Preprocessor::RegisterBuiltinMacros() {
290 if (LangOpts.CPlusPlus)
291 Ident__has_cpp_attribute =
294 Ident__has_cpp_attribute =
nullptr;
302 if (LangOpts.MicrosoftExt) {
306 Ident__identifier =
nullptr;
307 Ident__pragma =
nullptr;
322 if (LangOpts.Modules) {
329 Ident__MODULE__ =
nullptr;
331 Ident__building_module =
nullptr;
332 Ident__MODULE__ =
nullptr;
344 if (!II)
return true;
354 if (ExpansionMI->isEnabled() &&
373 bool Preprocessor::isNextPPTokenLParen() {
377 Val = CurLexer->isNextPPTokenLParen();
378 else if (CurPTHLexer)
379 Val = CurPTHLexer->isNextPPTokenLParen();
381 Val = CurTokenLexer->isNextTokenLParen();
389 for (
unsigned i = IncludeMacroStack.size(); i != 0; --i) {
390 IncludeStackInfo &Entry = IncludeMacroStack[i-1];
392 Val = Entry.TheLexer->isNextPPTokenLParen();
393 else if (Entry.ThePTHLexer)
394 Val = Entry.ThePTHLexer->isNextPPTokenLParen();
396 Val = Entry.TheTokenLexer->isNextTokenLParen();
402 if (Entry.ThePPLexer)
415 bool Preprocessor::HandleMacroExpandedIdentifier(
Token &Identifier,
427 Callbacks->MacroExpands(Identifier, M, Identifier.
getLocation(),
429 ExpandBuiltinMacro(Identifier);
448 Args = ReadFunctionLikeMacroArgs(Identifier, MI, ExpansionEnd);
454 if (!Args)
return true;
456 ++NumFnMacroExpanded;
466 SourceRange ExpansionRange(ExpandLoc, ExpansionEnd);
474 DelayedMacroExpandsCallbacks.push_back(
475 MacroExpandsInfo(Identifier, M, ExpansionRange));
477 Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args);
478 if (!DelayedMacroExpandsCallbacks.empty()) {
479 for (
unsigned i=0, e = DelayedMacroExpandsCallbacks.size(); i!=e; ++i) {
480 MacroExpandsInfo &Info = DelayedMacroExpandsCallbacks[i];
482 Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range,
485 DelayedMacroExpandsCallbacks.clear();
492 Diag(Identifier, diag::warn_pp_ambiguous_macro)
509 if (Args) Args->
destroy(*
this);
514 PropagateLineStartLeadingSpaceInfo(Identifier);
515 ++NumFastMacroExpanded;
525 if (Args) Args->
destroy(*
this);
550 if (!NewMI->isEnabled() || NewMI == MI) {
555 Diag(Identifier, diag::pp_disabled_macro_expansion);
561 ++NumFastMacroExpanded;
566 EnterMacro(Identifier, ExpansionEnd, MI, Args);
582 if (I->is(tok::l_paren)) {
583 Brackets.push_back(
Paren);
584 }
else if (I->is(tok::r_paren)) {
585 if (Brackets.empty() || Brackets.back() ==
Brace)
588 }
else if (I->is(tok::l_brace)) {
589 Brackets.push_back(
Brace);
590 }
else if (I->is(tok::r_brace)) {
591 if (Brackets.empty() || Brackets.back() ==
Paren)
596 if (!Brackets.empty())
632 bool FoundSeparatorToken =
false;
636 if (I->is(tok::l_brace)) {
638 }
else if (I->is(tok::r_brace)) {
640 if (Braces == 0 && ClosingBrace == E && FoundSeparatorToken)
647 FoundSeparatorToken =
true;
648 I->setKind(tok::comma);
656 if (FoundSeparatorToken && ArgStartIterator->is(tok::l_brace)) {
664 if (FoundSeparatorToken) {
666 TempToken.
setKind(tok::l_paren);
667 TempToken.
setLocation(ArgStartIterator->getLocation());
669 NewTokens.push_back(TempToken);
673 NewTokens.insert(NewTokens.end(), ArgStartIterator, I);
676 if (FoundSeparatorToken) {
679 TempToken.
setKind(tok::r_paren);
682 NewTokens.push_back(TempToken);
683 ParenHints.push_back(
SourceRange(ArgStartIterator->getLocation(),
688 NewTokens.push_back(*I);
691 ArgStartIterator = I + 1;
692 FoundSeparatorToken =
false;
697 return !ParenHints.empty() && InitLists.empty();
704 MacroArgs *Preprocessor::ReadFunctionLikeMacroArgs(
Token &MacroName,
717 assert(Tok.
is(tok::l_paren) &&
"Error computing l-paren-ness?");
723 bool ContainsCodeCompletionTok =
false;
727 unsigned NumActuals = 0;
728 while (Tok.
isNot(tok::r_paren)) {
732 assert(Tok.
isOneOf(tok::l_paren, tok::comma) &&
733 "only expect argument separators here");
735 unsigned ArgTokenStart = ArgTokens.size();
740 unsigned NumParens = 0;
748 if (!ContainsCodeCompletionTok) {
749 Diag(MacroName, diag::err_unterm_macro_invoc);
762 }
else if (Tok.
is(tok::r_paren)) {
764 if (NumParens-- == 0) {
768 }
else if (Tok.
is(tok::l_paren)) {
770 }
else if (Tok.
is(tok::comma) && NumParens == 0 &&
779 if (!isVariadic)
break;
780 if (NumFixedArgsLeft > 1)
782 }
else if (Tok.
is(tok::comment) && !KeepMacroComments) {
796 }
else if (Tok.
is(tok::code_completion)) {
797 ContainsCodeCompletionTok =
true;
806 ArgTokens.push_back(Tok);
811 if (ArgTokens.empty() && Tok.
getKind() == tok::r_paren)
816 if (!isVariadic && NumFixedArgsLeft == 0 && TooManyArgsLoc.
isInvalid()) {
817 if (ArgTokens.size() != ArgTokenStart)
818 TooManyArgsLoc = ArgTokens[ArgTokenStart].getLocation();
820 TooManyArgsLoc = ArgStartLoc;
825 if (ArgTokens.size() == ArgTokenStart && !LangOpts.C99)
826 Diag(Tok, LangOpts.CPlusPlus11 ?
827 diag::warn_cxx98_compat_empty_fnmacro_arg :
828 diag::ext_empty_fnmacro_arg);
836 ArgTokens.push_back(EOFTok);
838 if (!ContainsCodeCompletionTok && NumFixedArgsLeft != 0)
848 if (!isVariadic && NumActuals > MinArgsExpected &&
849 !ContainsCodeCompletionTok) {
852 Diag(TooManyArgsLoc, diag::err_too_many_args_in_macro_invoc);
862 unsigned FixedNumArgs = 0;
865 ParenHints, InitLists)) {
866 if (!InitLists.empty()) {
869 diag::note_init_list_at_beginning_of_macro_argument);
875 if (FixedNumArgs != MinArgsExpected)
879 for (
const SourceRange &ParenLocation : ParenHints) {
883 ArgTokens.swap(FixedArgTokens);
884 NumActuals = FixedNumArgs;
888 bool isVarargsElided =
false;
890 if (ContainsCodeCompletionTok) {
897 for (; NumActuals < MinArgsExpected; ++NumActuals)
898 ArgTokens.push_back(EOFTok);
901 if (NumActuals < MinArgsExpected) {
903 if (NumActuals == 0 && MinArgsExpected == 1) {
911 (NumActuals+1 == MinArgsExpected ||
912 (NumActuals == 0 && MinArgsExpected == 2))) {
920 Diag(Tok, diag::ext_missing_varargs_arg);
931 isVarargsElided =
true;
932 }
else if (!ContainsCodeCompletionTok) {
934 Diag(Tok, diag::err_too_few_args_in_macro_invoc);
946 ArgTokens.push_back(Tok);
949 if (NumActuals == 0 && MinArgsExpected == 2)
950 ArgTokens.push_back(Tok);
952 }
else if (NumActuals > MinArgsExpected && !MI->
isVariadic() &&
953 !ContainsCodeCompletionTok) {
956 Diag(MacroName, diag::err_too_many_args_in_macro_invoc);
976 size_t newIndex = MacroExpandedTokens.size();
977 bool cacheNeedsToGrow = tokens.size() >
978 MacroExpandedTokens.capacity()-MacroExpandedTokens.size();
979 MacroExpandedTokens.append(tokens.begin(), tokens.end());
981 if (cacheNeedsToGrow) {
984 for (
unsigned i = 0, e = MacroExpandingLexersStack.size(); i != e; ++i) {
987 std::tie(prevLexer, tokIndex) = MacroExpandingLexersStack[i];
988 prevLexer->Tokens = MacroExpandedTokens.data() + tokIndex;
992 MacroExpandingLexersStack.push_back(std::make_pair(tokLexer, newIndex));
993 return MacroExpandedTokens.data() + newIndex;
996 void Preprocessor::removeCachedMacroExpandedTokensOfLastLexer() {
997 assert(!MacroExpandingLexersStack.empty());
998 size_t tokIndex = MacroExpandingLexersStack.back().second;
999 assert(tokIndex < MacroExpandedTokens.size());
1001 MacroExpandedTokens.resize(tokIndex);
1002 MacroExpandingLexersStack.pop_back();
1010 time_t TT = time(
nullptr);
1011 struct tm *TM = localtime(&TT);
1013 static const char *
const Months[] = {
1014 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
1019 llvm::raw_svector_ostream TmpStream(TmpBuffer);
1020 TmpStream << llvm::format(
"\"%s %2d %4d\"", Months[TM->tm_mon],
1021 TM->tm_mday, TM->tm_year + 1900);
1030 llvm::raw_svector_ostream TmpStream(TmpBuffer);
1031 TmpStream << llvm::format(
"\"%02d:%02d:%02d\"",
1032 TM->tm_hour, TM->tm_min, TM->tm_sec);
1045 StringRef Feature = II->
getName();
1048 if (Feature.startswith(
"__") && Feature.endswith(
"__") && Feature.size() >= 4)
1049 Feature = Feature.substr(2, Feature.size() - 4);
1051 return llvm::StringSwitch<bool>(Feature)
1052 .Case(
"address_sanitizer",
1054 SanitizerKind::KernelAddress))
1055 .Case(
"assume_nonnull",
true)
1056 .Case(
"attribute_analyzer_noreturn",
true)
1057 .Case(
"attribute_availability",
true)
1058 .Case(
"attribute_availability_with_message",
true)
1059 .Case(
"attribute_availability_app_extension",
true)
1060 .Case(
"attribute_cf_returns_not_retained",
true)
1061 .Case(
"attribute_cf_returns_retained",
true)
1062 .Case(
"attribute_cf_returns_on_parameters",
true)
1063 .Case(
"attribute_deprecated_with_message",
true)
1064 .Case(
"attribute_ext_vector_type",
true)
1065 .Case(
"attribute_ns_returns_not_retained",
true)
1066 .Case(
"attribute_ns_returns_retained",
true)
1067 .Case(
"attribute_ns_consumes_self",
true)
1068 .Case(
"attribute_ns_consumed",
true)
1069 .Case(
"attribute_cf_consumed",
true)
1070 .Case(
"attribute_objc_ivar_unused",
true)
1071 .Case(
"attribute_objc_method_family",
true)
1072 .Case(
"attribute_overloadable",
true)
1073 .Case(
"attribute_unavailable_with_message",
true)
1074 .Case(
"attribute_unused_on_fields",
true)
1075 .Case(
"blocks", LangOpts.Blocks)
1076 .Case(
"c_thread_safety_attributes",
true)
1077 .Case(
"cxx_exceptions", LangOpts.CXXExceptions)
1078 .Case(
"cxx_rtti", LangOpts.RTTI)
1079 .Case(
"enumerator_attributes",
true)
1080 .Case(
"nullability",
true)
1081 .Case(
"memory_sanitizer", LangOpts.
Sanitize.
has(SanitizerKind::Memory))
1082 .Case(
"thread_sanitizer", LangOpts.
Sanitize.
has(SanitizerKind::Thread))
1083 .Case(
"dataflow_sanitizer", LangOpts.
Sanitize.
has(SanitizerKind::DataFlow))
1085 .Case(
"objc_arr", LangOpts.ObjCAutoRefCount)
1086 .Case(
"objc_arc", LangOpts.ObjCAutoRefCount)
1087 .Case(
"objc_arc_weak", LangOpts.ObjCARCWeak)
1088 .Case(
"objc_default_synthesize_properties", LangOpts.ObjC2)
1089 .Case(
"objc_fixed_enum", LangOpts.ObjC2)
1090 .Case(
"objc_instancetype", LangOpts.ObjC2)
1091 .Case(
"objc_kindof", LangOpts.ObjC2)
1092 .Case(
"objc_modules", LangOpts.ObjC2 && LangOpts.Modules)
1094 .Case(
"objc_property_explicit_atomic",
1096 .Case(
"objc_protocol_qualifier_mangling",
true)
1098 .Case(
"ownership_holds",
true)
1099 .Case(
"ownership_returns",
true)
1100 .Case(
"ownership_takes",
true)
1101 .Case(
"objc_bool",
true)
1103 .Case(
"objc_array_literals", LangOpts.ObjC2)
1104 .Case(
"objc_dictionary_literals", LangOpts.ObjC2)
1105 .Case(
"objc_boxed_expressions", LangOpts.ObjC2)
1106 .Case(
"objc_boxed_nsvalue_expressions", LangOpts.ObjC2)
1107 .Case(
"arc_cf_code_audited",
true)
1108 .Case(
"objc_bridge_id",
true)
1109 .Case(
"objc_bridge_id_on_typedefs",
true)
1110 .Case(
"objc_generics", LangOpts.ObjC2)
1111 .Case(
"objc_generics_variance", LangOpts.ObjC2)
1113 .Case(
"c_alignas", LangOpts.C11)
1114 .Case(
"c_alignof", LangOpts.C11)
1115 .Case(
"c_atomic", LangOpts.C11)
1116 .Case(
"c_generic_selections", LangOpts.C11)
1117 .Case(
"c_static_assert", LangOpts.C11)
1118 .Case(
"c_thread_local",
1121 .Case(
"cxx_access_control_sfinae", LangOpts.CPlusPlus11)
1122 .Case(
"cxx_alias_templates", LangOpts.CPlusPlus11)
1123 .Case(
"cxx_alignas", LangOpts.CPlusPlus11)
1124 .Case(
"cxx_alignof", LangOpts.CPlusPlus11)
1125 .Case(
"cxx_atomic", LangOpts.CPlusPlus11)
1126 .Case(
"cxx_attributes", LangOpts.CPlusPlus11)
1127 .Case(
"cxx_auto_type", LangOpts.CPlusPlus11)
1128 .Case(
"cxx_constexpr", LangOpts.CPlusPlus11)
1129 .Case(
"cxx_decltype", LangOpts.CPlusPlus11)
1130 .Case(
"cxx_decltype_incomplete_return_types", LangOpts.CPlusPlus11)
1131 .Case(
"cxx_default_function_template_args", LangOpts.CPlusPlus11)
1132 .Case(
"cxx_defaulted_functions", LangOpts.CPlusPlus11)
1133 .Case(
"cxx_delegating_constructors", LangOpts.CPlusPlus11)
1134 .Case(
"cxx_deleted_functions", LangOpts.CPlusPlus11)
1135 .Case(
"cxx_explicit_conversions", LangOpts.CPlusPlus11)
1136 .Case(
"cxx_generalized_initializers", LangOpts.CPlusPlus11)
1137 .Case(
"cxx_implicit_moves", LangOpts.CPlusPlus11)
1138 .Case(
"cxx_inheriting_constructors", LangOpts.CPlusPlus11)
1139 .Case(
"cxx_inline_namespaces", LangOpts.CPlusPlus11)
1140 .Case(
"cxx_lambdas", LangOpts.CPlusPlus11)
1141 .Case(
"cxx_local_type_template_args", LangOpts.CPlusPlus11)
1142 .Case(
"cxx_nonstatic_member_init", LangOpts.CPlusPlus11)
1143 .Case(
"cxx_noexcept", LangOpts.CPlusPlus11)
1144 .Case(
"cxx_nullptr", LangOpts.CPlusPlus11)
1145 .Case(
"cxx_override_control", LangOpts.CPlusPlus11)
1146 .Case(
"cxx_range_for", LangOpts.CPlusPlus11)
1147 .Case(
"cxx_raw_string_literals", LangOpts.CPlusPlus11)
1148 .Case(
"cxx_reference_qualified_functions", LangOpts.CPlusPlus11)
1149 .Case(
"cxx_rvalue_references", LangOpts.CPlusPlus11)
1150 .Case(
"cxx_strong_enums", LangOpts.CPlusPlus11)
1151 .Case(
"cxx_static_assert", LangOpts.CPlusPlus11)
1152 .Case(
"cxx_thread_local",
1154 .Case(
"cxx_trailing_return", LangOpts.CPlusPlus11)
1155 .Case(
"cxx_unicode_literals", LangOpts.CPlusPlus11)
1156 .Case(
"cxx_unrestricted_unions", LangOpts.CPlusPlus11)
1157 .Case(
"cxx_user_literals", LangOpts.CPlusPlus11)
1158 .Case(
"cxx_variadic_templates", LangOpts.CPlusPlus11)
1160 .Case(
"cxx_aggregate_nsdmi", LangOpts.CPlusPlus14)
1161 .Case(
"cxx_binary_literals", LangOpts.CPlusPlus14)
1162 .Case(
"cxx_contextual_conversions", LangOpts.CPlusPlus14)
1163 .Case(
"cxx_decltype_auto", LangOpts.CPlusPlus14)
1164 .Case(
"cxx_generic_lambdas", LangOpts.CPlusPlus14)
1165 .Case(
"cxx_init_captures", LangOpts.CPlusPlus14)
1166 .Case(
"cxx_relaxed_constexpr", LangOpts.CPlusPlus14)
1167 .Case(
"cxx_return_type_deduction", LangOpts.CPlusPlus14)
1168 .Case(
"cxx_variable_templates", LangOpts.CPlusPlus14)
1175 .Case(
"has_nothrow_assign", LangOpts.CPlusPlus)
1176 .Case(
"has_nothrow_copy", LangOpts.CPlusPlus)
1177 .Case(
"has_nothrow_constructor", LangOpts.CPlusPlus)
1178 .Case(
"has_trivial_assign", LangOpts.CPlusPlus)
1179 .Case(
"has_trivial_copy", LangOpts.CPlusPlus)
1180 .Case(
"has_trivial_constructor", LangOpts.CPlusPlus)
1181 .Case(
"has_trivial_destructor", LangOpts.CPlusPlus)
1182 .Case(
"has_virtual_destructor", LangOpts.CPlusPlus)
1183 .Case(
"is_abstract", LangOpts.CPlusPlus)
1184 .Case(
"is_base_of", LangOpts.CPlusPlus)
1185 .Case(
"is_class", LangOpts.CPlusPlus)
1186 .Case(
"is_constructible", LangOpts.CPlusPlus)
1187 .Case(
"is_convertible_to", LangOpts.CPlusPlus)
1188 .Case(
"is_empty", LangOpts.CPlusPlus)
1189 .Case(
"is_enum", LangOpts.CPlusPlus)
1190 .Case(
"is_final", LangOpts.CPlusPlus)
1191 .Case(
"is_literal", LangOpts.CPlusPlus)
1192 .Case(
"is_standard_layout", LangOpts.CPlusPlus)
1193 .Case(
"is_pod", LangOpts.CPlusPlus)
1194 .Case(
"is_polymorphic", LangOpts.CPlusPlus)
1195 .Case(
"is_sealed", LangOpts.MicrosoftExt)
1196 .Case(
"is_trivial", LangOpts.CPlusPlus)
1197 .Case(
"is_trivially_assignable", LangOpts.CPlusPlus)
1198 .Case(
"is_trivially_constructible", LangOpts.CPlusPlus)
1199 .Case(
"is_trivially_copyable", LangOpts.CPlusPlus)
1200 .Case(
"is_union", LangOpts.CPlusPlus)
1201 .Case(
"modules", LangOpts.Modules)
1202 .Case(
"safe_stack", LangOpts.
Sanitize.
has(SanitizerKind::SafeStack))
1204 .Case(
"underlying_type", LangOpts.CPlusPlus)
1222 StringRef Extension = II->
getName();
1225 if (Extension.startswith(
"__") && Extension.endswith(
"__") &&
1226 Extension.size() >= 4)
1227 Extension = Extension.substr(2, Extension.size() - 4);
1231 return llvm::StringSwitch<bool>(Extension)
1233 .Case(
"c_alignas",
true)
1234 .Case(
"c_alignof",
true)
1235 .Case(
"c_atomic",
true)
1236 .Case(
"c_generic_selections",
true)
1237 .Case(
"c_static_assert",
true)
1240 .Case(
"cxx_atomic", LangOpts.CPlusPlus)
1241 .Case(
"cxx_deleted_functions", LangOpts.CPlusPlus)
1242 .Case(
"cxx_explicit_conversions", LangOpts.CPlusPlus)
1243 .Case(
"cxx_inline_namespaces", LangOpts.CPlusPlus)
1244 .Case(
"cxx_local_type_template_args", LangOpts.CPlusPlus)
1245 .Case(
"cxx_nonstatic_member_init", LangOpts.CPlusPlus)
1246 .Case(
"cxx_override_control", LangOpts.CPlusPlus)
1247 .Case(
"cxx_range_for", LangOpts.CPlusPlus)
1248 .Case(
"cxx_reference_qualified_functions", LangOpts.CPlusPlus)
1249 .Case(
"cxx_rvalue_references", LangOpts.CPlusPlus)
1250 .Case(
"cxx_variadic_templates", LangOpts.CPlusPlus)
1252 .Case(
"cxx_binary_literals",
true)
1253 .Case(
"cxx_init_captures", LangOpts.CPlusPlus11)
1254 .Case(
"cxx_variable_templates", LangOpts.CPlusPlus)
1271 PP.
Diag(LParenLoc, diag::err_pp_directive_required) << II->
getName();
1273 assert(Tok.
is(tok::identifier));
1282 if (Tok.
isNot(tok::l_paren)) {
1285 PP.
Diag(LParenLoc, diag::err_pp_expected_after) << II << tok::l_paren;
1288 if (!Tok.
is(tok::angle_string_literal) && !Tok.
is(tok::string_literal) &&
1315 case tok::angle_string_literal:
1316 case tok::string_literal: {
1317 bool Invalid =
false;
1318 Filename = PP.
getSpelling(Tok, FilenameBuffer, &Invalid);
1327 FilenameBuffer.push_back(
'<');
1333 Filename = FilenameBuffer;
1346 if (Tok.
isNot(tok::r_paren)) {
1348 << II << tok::r_paren;
1349 PP.
Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1356 if (Filename.empty())
1362 PP.
LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile,
1363 CurDir,
nullptr,
nullptr,
nullptr);
1366 return File !=
nullptr;
1386 const FileEntry *LookupFromFile =
nullptr;
1389 PP.
Diag(Tok, diag::pp_include_next_in_primary);
1396 }
else if (!Lookup) {
1397 PP.
Diag(Tok, diag::pp_include_next_absolute_path);
1414 if (Tok.
isNot(tok::l_paren)) {
1427 if (Tok.
isNot(tok::identifier)) {
1439 if (Tok.
isNot(tok::r_paren)) {
1442 PP.
Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1451 void Preprocessor::ExpandBuiltinMacro(
Token &Tok) {
1454 assert(II &&
"Can't be a macro without id info!");
1458 if (II == Ident_Pragma)
1459 return Handle_Pragma(Tok);
1460 else if (II == Ident__pragma)
1461 return HandleMicrosoft__pragma(Tok);
1463 ++NumBuiltinMacroExpanded;
1466 llvm::raw_svector_ostream OS(TmpBuffer);
1472 if (II == Ident__LINE__) {
1492 Tok.
setKind(tok::numeric_constant);
1493 }
else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
1500 if (II == Ident__BASE_FILE__ && PLoc.
isValid()) {
1516 OS <<
'"' << FN <<
'"';
1518 Tok.
setKind(tok::string_literal);
1519 }
else if (II == Ident__DATE__) {
1523 Tok.
setKind(tok::string_literal);
1524 Tok.
setLength(strlen(
"\"Mmm dd yyyy\""));
1529 }
else if (II == Ident__TIME__) {
1533 Tok.
setKind(tok::string_literal);
1539 }
else if (II == Ident__INCLUDE_LEVEL__) {
1553 Tok.
setKind(tok::numeric_constant);
1554 }
else if (II == Ident__TIMESTAMP__) {
1569 time_t TT = CurFile->getModificationTime();
1570 struct tm *TM = localtime(&TT);
1571 Result = asctime(TM);
1573 Result =
"??? ??? ?? ??:??:?? ????\n";
1576 OS <<
'"' << StringRef(Result).drop_back() <<
'"';
1577 Tok.
setKind(tok::string_literal);
1578 }
else if (II == Ident__COUNTER__) {
1580 OS << CounterValue++;
1581 Tok.
setKind(tok::numeric_constant);
1582 }
else if (II == Ident__has_feature ||
1583 II == Ident__has_extension ||
1584 II == Ident__has_builtin ||
1585 II == Ident__is_identifier ||
1586 II == Ident__has_attribute ||
1587 II == Ident__has_declspec ||
1588 II == Ident__has_cpp_attribute) {
1592 bool IsValid =
false;
1598 if (Tok.
is(tok::l_paren)) {
1605 bool IsScopeValid =
true;
1606 if (II == Ident__has_cpp_attribute && Tok.
is(tok::coloncolon)) {
1609 ScopeII = FeatureII;
1613 IsScopeValid =
false;
1616 if (IsScopeValid && Tok.
is(tok::r_paren))
1620 while (Tok.
isNot(tok::r_paren) && Tok.
isNot(tok::eod) &&
1627 Diag(StartLoc, diag::err_feature_check_malformed);
1628 else if (II == Ident__is_identifier)
1629 Value = FeatureII->
getTokenID() == tok::identifier;
1630 else if (II == Ident__has_builtin) {
1633 }
else if (II == Ident__has_attribute)
1636 else if (II == Ident__has_cpp_attribute)
1639 else if (II == Ident__has_declspec)
1642 else if (II == Ident__has_extension)
1645 assert(II == Ident__has_feature &&
"Must be feature check");
1652 Tok.
setKind(tok::numeric_constant);
1653 }
else if (II == Ident__has_include ||
1654 II == Ident__has_include_next) {
1659 if (II == Ident__has_include)
1664 if (Tok.
isNot(tok::r_paren))
1667 Tok.
setKind(tok::numeric_constant);
1668 }
else if (II == Ident__has_warning) {
1672 bool IsValid =
false;
1677 if (Tok.
isNot(tok::l_paren)) {
1678 Diag(StartLoc, diag::err_warning_check_malformed);
1683 std::string WarningName;
1688 while (Tok.
isNot(tok::r_paren) && Tok.
isNot(tok::eod) &&
1695 if (!(IsValid = Tok.
is(tok::r_paren))) {
1696 Diag(StartLoc, diag::err_warning_check_malformed);
1702 if (WarningName.size() < 3 || WarningName[0] !=
'-' ||
1703 WarningName[1] !=
'W') {
1704 Diag(StrStartLoc, diag::warn_has_warning_invalid_option);
1715 WarningName.substr(2), Diags);
1721 Tok.
setKind(tok::numeric_constant);
1722 }
else if (II == Ident__building_module) {
1727 Tok.
setKind(tok::numeric_constant);
1728 }
else if (II == Ident__MODULE__) {
1734 }
else if (II == Ident__identifier) {
1740 if (Tok.
isNot(tok::l_paren)) {
1743 << II << tok::l_paren;
1766 if (RParen.
isNot(tok::r_paren)) {
1768 << Tok.
getKind() << tok::r_paren;
1769 Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1773 llvm_unreachable(
"Unknown identifier!");
bool isAtStartOfLine() const
static IdentifierInfo * RegisterBuiltinMacro(Preprocessor &PP, const char *Name)
static bool CheckMatchedBrackets(const SmallVectorImpl< Token > &Tokens)
ExternalPreprocessorSource * getExternalSource() const
MacroInfo * AllocateMacroInfo(SourceLocation L)
Allocate a new MacroInfo object with the provided SourceLocation.
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.
void setFlagValue(TokenFlags Flag, bool Val)
Set a flag to either true or false.
Defines the clang::FileManager interface and associated types.
Module * getCurrentSubmodule() const
Return the submodule owning the file being lexed.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
SanitizerSet Sanitize
Set of enabled sanitizers.
Defines the SourceManager interface.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
void dumpMacroInfo(const IdentifierInfo *II)
Is the identifier known as a __declspec-style attribute?
bool isObjectLike() const
bool hasCommaPasting() const
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II, Preprocessor &PP, const DirectoryLookup *LookupFrom, const FileEntry *LookupFromFile)
Defines the clang::MacroInfo and clang::MacroDirective classes.
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
Is the identifier known as a GNU-style attribute?
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)
void setFlag(TokenFlags Flag)
Set the specified flag.
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
bool isInPrimaryFile() const
Return true if we're in the top-level file, not in a #include.
StringRef getSpelling(SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
void Profile(llvm::FoldingSetNodeID &ID) const
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)
Represents a macro directive exported by a module.
bool isEnabled() const
Return true if this macro is enabled.
bool isFromAST() const
Return true if the identifier in its current state was loaded from an AST file.
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...
void setHasMacroDefinition(bool Val)
static bool getDiagnosticsInGroup(diag::Flavor Flavor, const WarningOption *Group, SmallVectorImpl< diag::kind > &Diags)
int hasAttribute(AttrSyntax Syntax, const IdentifierInfo *Scope, const IdentifierInfo *Attr, const llvm::Triple &T, const LangOptions &LangOpts)
Return the version number associated with the attribute if we recognize and implement the attribute s...
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
const LangOptions & getLangOpts() const
bool isWarnIfUnused() const
Return true if we should emit a warning if the macro is unused.
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...
Describes a module or submodule.
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
bool isParsingIfOrElifDirective() const
True if we are currently preprocessing a if or #elif directive.
static void ComputeDATE_TIME(SourceLocation &DATELoc, SourceLocation &TIMELoc, Preprocessor &PP)
static ModuleMacro * create(Preprocessor &PP, Module *OwningModule, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides)
void LexNonComment(Token &Result)
Lex a token. If it's a comment, keep lexing until we get something not a comment. ...
tok::TokenKind getTokenID() const
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
static bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II, Preprocessor &PP)
void destroy(Preprocessor &PP)
Present this diagnostic as an error.
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...
void setLoadedMacroDirective(IdentifierInfo *II, MacroDirective *MD)
Set a MacroDirective that was loaded from a PCH file.
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
tok::TokenKind getKind() const
const TargetInfo & getTargetInfo() const
unsigned getLine() const
Return the presumed line number of this location.
const FileEntry * getFileEntry() const
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
SourceLocation getIncludeLoc() const
Return the presumed include location of this location.
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.
diag::Severity getExtensionHandlingBehavior() const
A little helper class used to produce diagnostics.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
std::string CurrentModule
The name of the current module.
bool hasWeakClassImport() const
Does this runtime support weakly importing classes?
ID
Defines the set of possible language-specific address spaces.
ModuleMacro * addModuleMacro(Module *Mod, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides, bool &IsNew)
Register an exported macro for a module and identifier.
StringRef getName() const
Return the actual identifier string.
unsigned getNumArgs() const
Defines the clang::Preprocessor interface.
MultipleIncludeOpt MIOpt
A state machine that detects the #ifndef-wrapping a file idiom for the multiple-include optimization...
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
static bool EvaluateBuildingModule(Token &Tok, IdentifierInfo *II, Preprocessor &PP)
Process __building_module(identifier) expression.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
bool isNot(tok::TokenKind K) const
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
clang::ObjCRuntime ObjCRuntime
Represents an unpacked "presumed" location which can be presented to the user.
arg_iterator arg_end() const
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...
static bool HasFeature(const Preprocessor &PP, const IdentifierInfo *II)
The result type of a method or function.
const DirectoryLookup * GetCurDirLookup()
Get the DirectoryLookup structure used to find the current FileEntry, if CurLexer is non-null and if ...
void setIsUsed(bool Val)
Set the value of the IsUsed flag.
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
const char * getFilename() const
Return the presumed filename of this location.
Encodes a location in the source. The SourceManager can decode this to get at the full include stack...
const char * getNameStart() const
Return the beginning of the actual null-terminated string for this identifier.
static bool isTrivialSingleTokenExpansion(const MacroInfo *MI, const IdentifierInfo *MacroIdent, Preprocessor &PP)
PreprocessorLexer * getCurrentLexer() const
Return the current lexer being lexed from.
void setLength(unsigned Len)
bool isValid() const
Return true if this is a valid SourceLocation object.
static bool EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II, Preprocessor &PP)
Cached information about one file (either on disk or in the virtual file system). ...
void EnterTokenStream(const Token *Toks, unsigned NumToks, bool DisableMacroExpansion, bool OwnsTokens)
Add a "macro" context to the top of the include stack, which will cause the lexer to start returning ...
void forAllDefinitions(Fn F) const
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.
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 isAmbiguous() const
true if the definition is ambiguous, false otherwise.
const Token & getReplacementToken(unsigned Tok) const
bool is(tok::TokenKind K) const
DiagnosticsEngine & getDiagnostics() const
static bool HasExtension(const Preprocessor &PP, const IdentifierInfo *II)
unsigned getFlags() const
Return the internal represtation of the flags.
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
bool isFunctionLike() const
Encapsulates the data about a macro definition (e.g. its tokens).
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool GetIncludeFilenameSpelling(SourceLocation Loc, StringRef &Filename)
Turn the specified lexer token into a fully checked and spelled filename, e.g. as an operand of #incl...
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...
MacroDirective * getLocalMacroDirectiveHistory(const IdentifierInfo *II) const
Given an identifier, return the latest non-imported macro directive for that identifier.
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 ...
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
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.
void LexIncludeFilename(Token &Result)
After the preprocessor has parsed a #include, lex and (potentially) macro expand the filename...
bool isTLSSupported() const
Whether the target supports thread-local storage.
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 SkipCache=false)
Given a "foo" or <foo> reference, look up the indicated file.
ModuleMacro * getModuleMacro(Module *Mod, IdentifierInfo *II)
static MacroArgs * create(const MacroInfo *MI, ArrayRef< Token > UnexpArgTokens, bool VarargsElided, Preprocessor &PP)
MacroArgs ctor function - This destroys the vector passed in.
Defines the clang::TargetInfo interface.
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
unsigned getLength() const
void setLocation(SourceLocation L)
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment. In this case there should b...
arg_iterator arg_begin() const
A trivial tuple used to represent a source range.
void clearFlag(TokenFlags Flag)
Unset the specified flag.
virtual void CodeCompleteMacroArgument(IdentifierInfo *Macro, MacroInfo *MacroInfo, unsigned ArgumentIndex)
Callback invoked when performing code completion inside a function-like macro argument.
bool isAnnotation() const
Return true if this is any of tok::annot_* kind tokens.
void startToken()
Reset all flags to cleared.
const MacroDirective * getPrevious() const
Get previous definition of the macro with the same name.
static std::string Stringify(StringRef Str, bool Charify=false)
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
bool isUsed() const
Return false if this macro is defined in the main file and has not yet been used. ...
IdentifierInfo * getIdentifierInfo() const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.