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;
383 Ident__MODULE__ =
nullptr;
394 if (!II)
return true;
404 if (ExpansionMI->isEnabled() &&
421 bool Preprocessor::isNextPPTokenLParen() {
425 Val = CurLexer->isNextPPTokenLParen();
426 else if (CurPTHLexer)
427 Val = CurPTHLexer->isNextPPTokenLParen();
429 Val = CurTokenLexer->isNextTokenLParen();
437 for (
const IncludeStackInfo &Entry : llvm::reverse(IncludeMacroStack)) {
439 Val = Entry.TheLexer->isNextPPTokenLParen();
440 else if (Entry.ThePTHLexer)
441 Val = Entry.ThePTHLexer->isNextPPTokenLParen();
443 Val = Entry.TheTokenLexer->isNextTokenLParen();
449 if (Entry.ThePPLexer)
462 bool Preprocessor::HandleMacroExpandedIdentifier(
Token &Identifier,
474 Callbacks->MacroExpands(Identifier, M, Identifier.
getLocation(),
476 ExpandBuiltinMacro(Identifier);
495 Args = ReadMacroCallArgumentList(Identifier, MI, ExpansionEnd);
501 if (!Args)
return true;
503 ++NumFnMacroExpanded;
513 SourceRange ExpansionRange(ExpandLoc, ExpansionEnd);
521 DelayedMacroExpandsCallbacks.push_back(
522 MacroExpandsInfo(Identifier, M, ExpansionRange));
524 Callbacks->MacroExpands(Identifier, M, ExpansionRange, Args);
525 if (!DelayedMacroExpandsCallbacks.empty()) {
526 for (
const MacroExpandsInfo &Info : DelayedMacroExpandsCallbacks) {
528 Callbacks->MacroExpands(Info.Tok, Info.MD, Info.Range,
531 DelayedMacroExpandsCallbacks.clear();
538 Diag(Identifier, diag::warn_pp_ambiguous_macro)
555 if (Args) Args->
destroy(*
this);
560 PropagateLineStartLeadingSpaceInfo(Identifier);
561 ++NumFastMacroExpanded;
571 if (Args) Args->
destroy(*
this);
596 if (!NewMI->isEnabled() || NewMI == MI) {
601 Diag(Identifier, diag::pp_disabled_macro_expansion);
607 ++NumFastMacroExpanded;
612 EnterMacro(Identifier, ExpansionEnd, MI, Args);
628 if (
I->is(tok::l_paren)) {
629 Brackets.push_back(
Paren);
630 }
else if (
I->is(tok::r_paren)) {
631 if (Brackets.empty() || Brackets.back() ==
Brace)
634 }
else if (
I->is(tok::l_brace)) {
635 Brackets.push_back(
Brace);
636 }
else if (
I->is(tok::r_brace)) {
637 if (Brackets.empty() || Brackets.back() ==
Paren)
642 return Brackets.empty();
676 bool FoundSeparatorToken =
false;
680 if (
I->is(tok::l_brace)) {
682 }
else if (
I->is(tok::r_brace)) {
684 if (Braces == 0 && ClosingBrace ==
E && FoundSeparatorToken)
691 FoundSeparatorToken =
true;
692 I->setKind(tok::comma);
700 if (FoundSeparatorToken && ArgStartIterator->is(tok::l_brace)) {
708 if (FoundSeparatorToken) {
710 TempToken.
setKind(tok::l_paren);
711 TempToken.
setLocation(ArgStartIterator->getLocation());
713 NewTokens.push_back(TempToken);
717 NewTokens.insert(NewTokens.end(), ArgStartIterator,
I);
720 if (FoundSeparatorToken) {
723 TempToken.
setKind(tok::r_paren);
726 NewTokens.push_back(TempToken);
727 ParenHints.push_back(
SourceRange(ArgStartIterator->getLocation(),
732 NewTokens.push_back(*
I);
735 ArgStartIterator =
I + 1;
736 FoundSeparatorToken =
false;
741 return !ParenHints.empty() && InitLists.empty();
748 MacroArgs *Preprocessor::ReadMacroCallArgumentList(
Token &MacroName,
761 assert(Tok.
is(tok::l_paren) &&
"Error computing l-paren-ness?");
767 bool ContainsCodeCompletionTok =
false;
768 bool FoundElidedComma =
false;
772 unsigned NumActuals = 0;
773 while (Tok.
isNot(tok::r_paren)) {
777 assert(Tok.
isOneOf(tok::l_paren, tok::comma) &&
778 "only expect argument separators here");
780 size_t ArgTokenStart = ArgTokens.size();
785 unsigned NumParens = 0;
793 if (!ContainsCodeCompletionTok) {
794 Diag(MacroName, diag::err_unterm_macro_invoc);
802 auto Toks = llvm::make_unique<Token[]>(1);
804 EnterTokenStream(std::move(Toks), 1,
true);
806 }
else if (Tok.
is(tok::r_paren)) {
808 if (NumParens-- == 0) {
810 if (!ArgTokens.empty() &&
811 ArgTokens.back().commaAfterElided()) {
812 FoundElidedComma =
true;
816 }
else if (Tok.
is(tok::l_paren)) {
818 }
else if (Tok.
is(tok::comma) && NumParens == 0 &&
827 if (!isVariadic)
break;
828 if (NumFixedArgsLeft > 1)
830 }
else if (Tok.
is(tok::comment) && !KeepMacroComments) {
844 }
else if (Tok.
is(tok::code_completion)) {
845 ContainsCodeCompletionTok =
true;
854 ArgTokens.push_back(Tok);
859 if (ArgTokens.empty() && Tok.
getKind() == tok::r_paren)
864 if (!isVariadic && NumFixedArgsLeft == 0 && TooManyArgsLoc.
isInvalid()) {
865 if (ArgTokens.size() != ArgTokenStart)
866 TooManyArgsLoc = ArgTokens[ArgTokenStart].getLocation();
868 TooManyArgsLoc = ArgStartLoc;
873 if (ArgTokens.size() == ArgTokenStart && !LangOpts.C99)
874 Diag(Tok, LangOpts.CPlusPlus11 ?
875 diag::warn_cxx98_compat_empty_fnmacro_arg :
876 diag::ext_empty_fnmacro_arg);
884 ArgTokens.push_back(EOFTok);
886 if (!ContainsCodeCompletionTok && NumFixedArgsLeft != 0)
896 if (!isVariadic && NumActuals > MinArgsExpected &&
897 !ContainsCodeCompletionTok) {
900 Diag(TooManyArgsLoc, diag::err_too_many_args_in_macro_invoc);
910 unsigned FixedNumArgs = 0;
913 ParenHints, InitLists)) {
914 if (!InitLists.empty()) {
917 diag::note_init_list_at_beginning_of_macro_argument);
923 if (FixedNumArgs != MinArgsExpected)
931 ArgTokens.swap(FixedArgTokens);
932 NumActuals = FixedNumArgs;
936 bool isVarargsElided =
false;
938 if (ContainsCodeCompletionTok) {
945 for (; NumActuals < MinArgsExpected; ++NumActuals)
946 ArgTokens.push_back(EOFTok);
949 if (NumActuals < MinArgsExpected) {
951 if (NumActuals == 0 && MinArgsExpected == 1) {
958 }
else if ((FoundElidedComma || MI->
isVariadic()) &&
959 (NumActuals+1 == MinArgsExpected ||
960 (NumActuals == 0 && MinArgsExpected == 2))) {
968 Diag(Tok, diag::ext_missing_varargs_arg);
979 isVarargsElided =
true;
980 }
else if (!ContainsCodeCompletionTok) {
982 Diag(Tok, diag::err_too_few_args_in_macro_invoc);
994 ArgTokens.push_back(Tok);
997 if (NumActuals == 0 && MinArgsExpected == 2)
998 ArgTokens.push_back(Tok);
1000 }
else if (NumActuals > MinArgsExpected && !MI->
isVariadic() &&
1001 !ContainsCodeCompletionTok) {
1004 Diag(MacroName, diag::err_too_many_args_in_macro_invoc);
1024 size_t newIndex = MacroExpandedTokens.size();
1025 bool cacheNeedsToGrow = tokens.size() >
1026 MacroExpandedTokens.capacity()-MacroExpandedTokens.size();
1027 MacroExpandedTokens.append(tokens.begin(), tokens.end());
1029 if (cacheNeedsToGrow) {
1032 for (
const auto &
Lexer : MacroExpandingLexersStack) {
1035 std::tie(prevLexer, tokIndex) =
Lexer;
1036 prevLexer->Tokens = MacroExpandedTokens.data() + tokIndex;
1040 MacroExpandingLexersStack.push_back(std::make_pair(tokLexer, newIndex));
1041 return MacroExpandedTokens.data() + newIndex;
1044 void Preprocessor::removeCachedMacroExpandedTokensOfLastLexer() {
1045 assert(!MacroExpandingLexersStack.empty());
1046 size_t tokIndex = MacroExpandingLexersStack.back().second;
1047 assert(tokIndex < MacroExpandedTokens.size());
1049 MacroExpandedTokens.resize(tokIndex);
1050 MacroExpandingLexersStack.pop_back();
1058 time_t TT = time(
nullptr);
1059 struct tm *TM = localtime(&TT);
1061 static const char *
const Months[] = {
1062 "Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
1067 llvm::raw_svector_ostream TmpStream(TmpBuffer);
1068 TmpStream << llvm::format(
"\"%s %2d %4d\"", Months[TM->tm_mon],
1069 TM->tm_mday, TM->tm_year + 1900);
1078 llvm::raw_svector_ostream TmpStream(TmpBuffer);
1079 TmpStream << llvm::format(
"\"%02d:%02d:%02d\"",
1080 TM->tm_hour, TM->tm_min, TM->tm_sec);
1094 if (Feature.startswith(
"__") && Feature.endswith(
"__") && Feature.size() >= 4)
1095 Feature = Feature.substr(2, Feature.size() - 4);
1097 return llvm::StringSwitch<bool>(Feature)
1098 .Case(
"address_sanitizer",
1100 SanitizerKind::KernelAddress))
1101 .Case(
"assume_nonnull",
true)
1102 .Case(
"attribute_analyzer_noreturn",
true)
1103 .Case(
"attribute_availability",
true)
1104 .Case(
"attribute_availability_with_message",
true)
1105 .Case(
"attribute_availability_app_extension",
true)
1106 .Case(
"attribute_availability_with_version_underscores",
true)
1107 .Case(
"attribute_availability_tvos",
true)
1108 .Case(
"attribute_availability_watchos",
true)
1109 .Case(
"attribute_availability_with_strict",
true)
1110 .Case(
"attribute_availability_with_replacement",
true)
1111 .Case(
"attribute_availability_in_templates",
true)
1112 .Case(
"attribute_cf_returns_not_retained",
true)
1113 .Case(
"attribute_cf_returns_retained",
true)
1114 .Case(
"attribute_cf_returns_on_parameters",
true)
1115 .Case(
"attribute_deprecated_with_message",
true)
1116 .Case(
"attribute_deprecated_with_replacement",
true)
1117 .Case(
"attribute_ext_vector_type",
true)
1118 .Case(
"attribute_ns_returns_not_retained",
true)
1119 .Case(
"attribute_ns_returns_retained",
true)
1120 .Case(
"attribute_ns_consumes_self",
true)
1121 .Case(
"attribute_ns_consumed",
true)
1122 .Case(
"attribute_cf_consumed",
true)
1123 .Case(
"attribute_objc_ivar_unused",
true)
1124 .Case(
"attribute_objc_method_family",
true)
1125 .Case(
"attribute_overloadable",
true)
1126 .Case(
"attribute_unavailable_with_message",
true)
1127 .Case(
"attribute_unused_on_fields",
true)
1128 .Case(
"attribute_diagnose_if_objc",
true)
1129 .Case(
"blocks", LangOpts.Blocks)
1130 .Case(
"c_thread_safety_attributes",
true)
1131 .Case(
"cxx_exceptions", LangOpts.CXXExceptions)
1132 .Case(
"cxx_rtti", LangOpts.RTTI && LangOpts.RTTIData)
1133 .Case(
"enumerator_attributes",
true)
1134 .Case(
"nullability",
true)
1135 .Case(
"nullability_on_arrays",
true)
1136 .Case(
"memory_sanitizer", LangOpts.
Sanitize.
has(SanitizerKind::Memory))
1137 .Case(
"thread_sanitizer", LangOpts.
Sanitize.
has(SanitizerKind::Thread))
1138 .Case(
"dataflow_sanitizer", LangOpts.
Sanitize.
has(SanitizerKind::DataFlow))
1139 .Case(
"efficiency_sanitizer",
1142 .Case(
"objc_arr", LangOpts.ObjCAutoRefCount)
1143 .Case(
"objc_arc", LangOpts.ObjCAutoRefCount)
1144 .Case(
"objc_arc_weak", LangOpts.ObjCWeak)
1145 .Case(
"objc_default_synthesize_properties", LangOpts.ObjC2)
1146 .Case(
"objc_fixed_enum", LangOpts.ObjC2)
1147 .Case(
"objc_instancetype", LangOpts.ObjC2)
1148 .Case(
"objc_kindof", LangOpts.ObjC2)
1149 .Case(
"objc_modules", LangOpts.ObjC2 && LangOpts.Modules)
1151 .Case(
"objc_property_explicit_atomic",
1153 .Case(
"objc_protocol_qualifier_mangling",
true)
1155 .Case(
"ownership_holds",
true)
1156 .Case(
"ownership_returns",
true)
1157 .Case(
"ownership_takes",
true)
1158 .Case(
"objc_bool",
true)
1160 .Case(
"objc_array_literals", LangOpts.ObjC2)
1161 .Case(
"objc_dictionary_literals", LangOpts.ObjC2)
1162 .Case(
"objc_boxed_expressions", LangOpts.ObjC2)
1163 .Case(
"objc_boxed_nsvalue_expressions", LangOpts.ObjC2)
1164 .Case(
"arc_cf_code_audited",
true)
1165 .Case(
"objc_bridge_id",
true)
1166 .Case(
"objc_bridge_id_on_typedefs",
true)
1167 .Case(
"objc_generics", LangOpts.ObjC2)
1168 .Case(
"objc_generics_variance", LangOpts.ObjC2)
1169 .Case(
"objc_class_property", LangOpts.ObjC2)
1171 .Case(
"c_alignas", LangOpts.C11)
1172 .Case(
"c_alignof", LangOpts.C11)
1173 .Case(
"c_atomic", LangOpts.C11)
1174 .Case(
"c_generic_selections", LangOpts.C11)
1175 .Case(
"c_static_assert", LangOpts.C11)
1176 .Case(
"c_thread_local",
1179 .Case(
"cxx_access_control_sfinae", LangOpts.CPlusPlus11)
1180 .Case(
"cxx_alias_templates", LangOpts.CPlusPlus11)
1181 .Case(
"cxx_alignas", LangOpts.CPlusPlus11)
1182 .Case(
"cxx_alignof", LangOpts.CPlusPlus11)
1183 .Case(
"cxx_atomic", LangOpts.CPlusPlus11)
1184 .Case(
"cxx_attributes", LangOpts.CPlusPlus11)
1185 .Case(
"cxx_auto_type", LangOpts.CPlusPlus11)
1186 .Case(
"cxx_constexpr", LangOpts.CPlusPlus11)
1187 .Case(
"cxx_constexpr_string_builtins", LangOpts.CPlusPlus11)
1188 .Case(
"cxx_decltype", LangOpts.CPlusPlus11)
1189 .Case(
"cxx_decltype_incomplete_return_types", LangOpts.CPlusPlus11)
1190 .Case(
"cxx_default_function_template_args", LangOpts.CPlusPlus11)
1191 .Case(
"cxx_defaulted_functions", LangOpts.CPlusPlus11)
1192 .Case(
"cxx_delegating_constructors", LangOpts.CPlusPlus11)
1193 .Case(
"cxx_deleted_functions", LangOpts.CPlusPlus11)
1194 .Case(
"cxx_explicit_conversions", LangOpts.CPlusPlus11)
1195 .Case(
"cxx_generalized_initializers", LangOpts.CPlusPlus11)
1196 .Case(
"cxx_implicit_moves", LangOpts.CPlusPlus11)
1197 .Case(
"cxx_inheriting_constructors", LangOpts.CPlusPlus11)
1198 .Case(
"cxx_inline_namespaces", LangOpts.CPlusPlus11)
1199 .Case(
"cxx_lambdas", LangOpts.CPlusPlus11)
1200 .Case(
"cxx_local_type_template_args", LangOpts.CPlusPlus11)
1201 .Case(
"cxx_nonstatic_member_init", LangOpts.CPlusPlus11)
1202 .Case(
"cxx_noexcept", LangOpts.CPlusPlus11)
1203 .Case(
"cxx_nullptr", LangOpts.CPlusPlus11)
1204 .Case(
"cxx_override_control", LangOpts.CPlusPlus11)
1205 .Case(
"cxx_range_for", LangOpts.CPlusPlus11)
1206 .Case(
"cxx_raw_string_literals", LangOpts.CPlusPlus11)
1207 .Case(
"cxx_reference_qualified_functions", LangOpts.CPlusPlus11)
1208 .Case(
"cxx_rvalue_references", LangOpts.CPlusPlus11)
1209 .Case(
"cxx_strong_enums", LangOpts.CPlusPlus11)
1210 .Case(
"cxx_static_assert", LangOpts.CPlusPlus11)
1211 .Case(
"cxx_thread_local",
1213 .Case(
"cxx_trailing_return", LangOpts.CPlusPlus11)
1214 .Case(
"cxx_unicode_literals", LangOpts.CPlusPlus11)
1215 .Case(
"cxx_unrestricted_unions", LangOpts.CPlusPlus11)
1216 .Case(
"cxx_user_literals", LangOpts.CPlusPlus11)
1217 .Case(
"cxx_variadic_templates", LangOpts.CPlusPlus11)
1219 .Case(
"cxx_aggregate_nsdmi", LangOpts.CPlusPlus14)
1220 .Case(
"cxx_binary_literals", LangOpts.CPlusPlus14)
1221 .Case(
"cxx_contextual_conversions", LangOpts.CPlusPlus14)
1222 .Case(
"cxx_decltype_auto", LangOpts.CPlusPlus14)
1223 .Case(
"cxx_generic_lambdas", LangOpts.CPlusPlus14)
1224 .Case(
"cxx_init_captures", LangOpts.CPlusPlus14)
1225 .Case(
"cxx_relaxed_constexpr", LangOpts.CPlusPlus14)
1226 .Case(
"cxx_return_type_deduction", LangOpts.CPlusPlus14)
1227 .Case(
"cxx_variable_templates", LangOpts.CPlusPlus14)
1239 .Case(
"has_nothrow_assign", LangOpts.CPlusPlus)
1240 .Case(
"has_nothrow_copy", LangOpts.CPlusPlus)
1241 .Case(
"has_nothrow_constructor", LangOpts.CPlusPlus)
1242 .Case(
"has_trivial_assign", LangOpts.CPlusPlus)
1243 .Case(
"has_trivial_copy", LangOpts.CPlusPlus)
1244 .Case(
"has_trivial_constructor", LangOpts.CPlusPlus)
1245 .Case(
"has_trivial_destructor", LangOpts.CPlusPlus)
1246 .Case(
"has_virtual_destructor", LangOpts.CPlusPlus)
1247 .Case(
"is_abstract", LangOpts.CPlusPlus)
1248 .Case(
"is_base_of", LangOpts.CPlusPlus)
1249 .Case(
"is_class", LangOpts.CPlusPlus)
1250 .Case(
"is_constructible", LangOpts.CPlusPlus)
1251 .Case(
"is_convertible_to", LangOpts.CPlusPlus)
1252 .Case(
"is_empty", LangOpts.CPlusPlus)
1253 .Case(
"is_enum", LangOpts.CPlusPlus)
1254 .Case(
"is_final", LangOpts.CPlusPlus)
1255 .Case(
"is_literal", LangOpts.CPlusPlus)
1256 .Case(
"is_standard_layout", LangOpts.CPlusPlus)
1257 .Case(
"is_pod", LangOpts.CPlusPlus)
1258 .Case(
"is_polymorphic", LangOpts.CPlusPlus)
1259 .Case(
"is_sealed", LangOpts.CPlusPlus && LangOpts.MicrosoftExt)
1260 .Case(
"is_trivial", LangOpts.CPlusPlus)
1261 .Case(
"is_trivially_assignable", LangOpts.CPlusPlus)
1262 .Case(
"is_trivially_constructible", LangOpts.CPlusPlus)
1263 .Case(
"is_trivially_copyable", LangOpts.CPlusPlus)
1264 .Case(
"is_union", LangOpts.CPlusPlus)
1265 .Case(
"modules", LangOpts.Modules)
1266 .Case(
"safe_stack", LangOpts.
Sanitize.
has(SanitizerKind::SafeStack))
1268 .Case(
"underlying_type", LangOpts.CPlusPlus)
1288 if (Extension.startswith(
"__") && Extension.endswith(
"__") &&
1289 Extension.size() >= 4)
1290 Extension = Extension.substr(2, Extension.size() - 4);
1294 return llvm::StringSwitch<bool>(Extension)
1296 .Case(
"c_alignas",
true)
1297 .Case(
"c_alignof",
true)
1298 .Case(
"c_atomic",
true)
1299 .Case(
"c_generic_selections",
true)
1300 .Case(
"c_static_assert",
true)
1303 .Case(
"cxx_atomic", LangOpts.CPlusPlus)
1304 .Case(
"cxx_deleted_functions", LangOpts.CPlusPlus)
1305 .Case(
"cxx_explicit_conversions", LangOpts.CPlusPlus)
1306 .Case(
"cxx_inline_namespaces", LangOpts.CPlusPlus)
1307 .Case(
"cxx_local_type_template_args", LangOpts.CPlusPlus)
1308 .Case(
"cxx_nonstatic_member_init", LangOpts.CPlusPlus)
1309 .Case(
"cxx_override_control", LangOpts.CPlusPlus)
1310 .Case(
"cxx_range_for", LangOpts.CPlusPlus)
1311 .Case(
"cxx_reference_qualified_functions", LangOpts.CPlusPlus)
1312 .Case(
"cxx_rvalue_references", LangOpts.CPlusPlus)
1313 .Case(
"cxx_variadic_templates", LangOpts.CPlusPlus)
1315 .Case(
"cxx_binary_literals",
true)
1316 .Case(
"cxx_init_captures", LangOpts.CPlusPlus11)
1317 .Case(
"cxx_variable_templates", LangOpts.CPlusPlus)
1319 .Case(
"overloadable_unmarked",
true)
1336 PP.
Diag(LParenLoc, diag::err_pp_directive_required) << II->
getName();
1338 assert(Tok.
is(tok::identifier));
1347 if (Tok.
isNot(tok::l_paren)) {
1350 PP.
Diag(LParenLoc, diag::err_pp_expected_after) << II << tok::l_paren;
1353 if (!Tok.
is(tok::angle_string_literal) && !Tok.
is(tok::string_literal) &&
1380 case tok::angle_string_literal:
1381 case tok::string_literal: {
1382 bool Invalid =
false;
1383 Filename = PP.
getSpelling(Tok, FilenameBuffer, &Invalid);
1392 FilenameBuffer.push_back(
'<');
1398 Filename = FilenameBuffer;
1411 if (Tok.
isNot(tok::r_paren)) {
1413 << II << tok::r_paren;
1414 PP.
Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1421 if (Filename.empty())
1427 PP.
LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile,
1428 CurDir,
nullptr,
nullptr,
nullptr,
nullptr);
1431 return File !=
nullptr;
1451 const FileEntry *LookupFromFile =
nullptr;
1458 PP.
Diag(Tok, diag::pp_include_next_in_primary);
1465 }
else if (!Lookup) {
1466 PP.
Diag(Tok, diag::pp_include_next_absolute_path);
1482 bool &HasLexedNextTok)> Op) {
1485 if (Tok.
isNot(tok::l_paren)) {
1492 Tok.
setKind(tok::numeric_constant);
1497 unsigned ParenDepth = 1;
1502 bool SuppressDiagnostic =
false;
1517 if (!SuppressDiagnostic) {
1519 SuppressDiagnostic =
true;
1525 if (Result.hasValue())
1527 if (!SuppressDiagnostic) {
1529 SuppressDiagnostic =
true;
1534 if (--ParenDepth > 0)
1539 if (Result.hasValue())
1540 OS << Result.getValue();
1543 if (!SuppressDiagnostic)
1546 Tok.
setKind(tok::numeric_constant);
1551 if (Result.hasValue())
1554 bool HasLexedNextToken =
false;
1555 Result = Op(Tok, HasLexedNextToken);
1557 if (HasLexedNextToken)
1564 if (!SuppressDiagnostic) {
1572 PP.
Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1573 SuppressDiagnostic =
true;
1593 void Preprocessor::ExpandBuiltinMacro(
Token &Tok) {
1596 assert(II &&
"Can't be a macro without id info!");
1600 if (II == Ident_Pragma)
1601 return Handle_Pragma(Tok);
1602 else if (II == Ident__pragma)
1603 return HandleMicrosoft__pragma(Tok);
1605 ++NumBuiltinMacroExpanded;
1608 llvm::raw_svector_ostream OS(TmpBuffer);
1614 if (II == Ident__LINE__) {
1629 Loc =
SourceMgr.getExpansionRange(Loc).second;
1634 Tok.
setKind(tok::numeric_constant);
1635 }
else if (II == Ident__FILE__ || II == Ident__BASE_FILE__) {
1642 if (II == Ident__BASE_FILE__ && PLoc.
isValid()) {
1645 PLoc =
SourceMgr.getPresumedLoc(NextLoc);
1658 OS <<
'"' << FN <<
'"';
1660 Tok.
setKind(tok::string_literal);
1661 }
else if (II == Ident__DATE__) {
1665 Tok.
setKind(tok::string_literal);
1666 Tok.
setLength(strlen(
"\"Mmm dd yyyy\""));
1671 }
else if (II == Ident__TIME__) {
1675 Tok.
setKind(tok::string_literal);
1681 }
else if (II == Ident__INCLUDE_LEVEL__) {
1695 Tok.
setKind(tok::numeric_constant);
1696 }
else if (II == Ident__TIMESTAMP__) {
1711 time_t TT = CurFile->getModificationTime();
1712 struct tm *TM = localtime(&TT);
1713 Result = asctime(TM);
1715 Result =
"??? ??? ?? ??:??:?? ????\n";
1718 OS <<
'"' << StringRef(Result).drop_back() <<
'"';
1719 Tok.
setKind(tok::string_literal);
1720 }
else if (II == Ident__COUNTER__) {
1722 OS << CounterValue++;
1723 Tok.
setKind(tok::numeric_constant);
1724 }
else if (II == Ident__has_feature) {
1726 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1728 diag::err_feature_check_malformed);
1731 }
else if (II == Ident__has_extension) {
1733 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1735 diag::err_feature_check_malformed);
1738 }
else if (II == Ident__has_builtin) {
1740 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1742 diag::err_feature_check_malformed);
1749 return llvm::StringSwitch<bool>(II->
getName())
1750 .Case(
"__make_integer_seq", LangOpts.CPlusPlus)
1751 .Case(
"__type_pack_element", LangOpts.CPlusPlus)
1752 .Case(
"__builtin_available",
true)
1756 }
else if (II == Ident__is_identifier) {
1758 [](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1759 return Tok.
is(tok::identifier);
1761 }
else if (II == Ident__has_attribute) {
1763 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1765 diag::err_feature_check_malformed);
1769 }
else if (II == Ident__has_declspec) {
1771 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1773 diag::err_feature_check_malformed);
1777 }
else if (II == Ident__has_cpp_attribute) {
1779 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1782 diag::err_feature_check_malformed);
1789 if (Tok.
isNot(tok::coloncolon))
1790 HasLexedNextToken =
true;
1795 diag::err_feature_check_malformed);
1801 }
else if (II == Ident__has_include ||
1802 II == Ident__has_include_next) {
1807 if (II == Ident__has_include)
1812 if (Tok.
isNot(tok::r_paren))
1815 Tok.
setKind(tok::numeric_constant);
1816 }
else if (II == Ident__has_warning) {
1819 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1820 std::string WarningName;
1823 HasLexedNextToken = Tok.
is(tok::string_literal);
1830 if (WarningName.size() < 3 || WarningName[0] !=
'-' ||
1831 WarningName[1] !=
'W') {
1832 Diag(StrStartLoc, diag::warn_has_warning_invalid_option);
1843 WarningName.substr(2), Diags);
1845 }
else if (II == Ident__building_module) {
1850 [
this](
Token &Tok,
bool &HasLexedNextToken) ->
int {
1852 diag::err_expected_id_building_module);
1856 }
else if (II == Ident__MODULE__) {
1862 }
else if (II == Ident__identifier) {
1868 if (Tok.
isNot(tok::l_paren)) {
1871 << II << tok::l_paren;
1894 if (RParen.
isNot(tok::r_paren)) {
1896 << Tok.
getKind() << tok::r_paren;
1897 Diag(LParenLoc, diag::note_matching) << tok::l_paren;
1901 llvm_unreachable(
"Unknown identifier!");
A diagnostic that indicates a problem or potential problem.
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
static IdentifierInfo * RegisterBuiltinMacro(Preprocessor &PP, const char *Name)
RegisterBuiltinMacro - Register the specified identifier in the identifier table and mark it as a bui...
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.
static bool CheckMatchedBrackets(const SmallVectorImpl< Token > &Tokens)
CheckMatchedBrackets - Returns true if the braces and parentheses in the token vector are properly ne...
ExternalPreprocessorSource * getExternalSource() const
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.
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.
param_iterator param_begin() const
void setFlagValue(TokenFlags Flag, bool Val)
Set a flag to either true or false.
Defines the clang::FileManager interface and associated types.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
SanitizerSet Sanitize
Set of enabled sanitizers.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
void dumpMacroInfo(const IdentifierInfo *II)
Is the identifier known as a __declspec-style attribute?
bool isObjectLike() const
Module * getCurrentLexerSubmodule() const
Return the submodule owning the file being lexed.
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)
EvaluateHasIncludeCommon - Process a '__has_include("path")' or '__has_include_next("path")' expr...
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?
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...
void setFlag(TokenFlags Flag)
Set the specified flag.
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.
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
Return the 'spelling' of the token at the given location; does not go up to the spelling location or ...
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)
One of these records is kept for each identifier that is lexed.
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.
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)
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...
const MacroInfo * getMacroInfo(const IdentifierInfo *II) const
const LangOptions & getLangOpts() const
Token - This structure provides full information about a lexed token.
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)
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.
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...
static ModuleMacro * create(Preprocessor &PP, Module *OwningModule, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides)
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.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void LexNonComment(Token &Result)
Lex a token.
tok::TokenKind getTokenID() const
If this is a source-language token (e.g.
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
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.
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...
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...
const IntrusiveRefCntPtr< DiagnosticIDs > & getDiagnosticIDs() const
tok::TokenKind getKind() const
unsigned getNumParams() const
const TargetInfo & getTargetInfo() const
unsigned getLine() const
Return the presumed line number of this location.
const FileEntry * getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
detail::InMemoryDirectory::const_iterator I
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
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.
param_iterator param_end() const
diag::Severity getExtensionHandlingBehavior() const
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.
bool hasWeakClassImport() const
Does this runtime support weakly importing classes?
ModuleMacro * addModuleMacro(Module *Mod, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides, bool &IsNew)
Register an exported macro for a module and identifier.
Defines the clang::LangOptions interface.
StringRef getName() const
Return the actual identifier string.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
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.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
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.
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...
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 ...
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.
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)
isTrivialSingleTokenExpansion - Return true if MI, which has a single token in its expansion...
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)
EvaluateHasIncludeNext - Process '__has_include_next("path")' expression.
Cached information about one file (either on disk or in the virtual file system). ...
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.
ArrayRef< FormatToken * > Tokens
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 isAmbiguous() const
true if the definition is ambiguous, false otherwise.
const Token & getReplacementToken(unsigned Tok) const
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)) {...
DiagnosticsEngine & getDiagnostics() const
unsigned getFlags() const
Return the internal represtation of the flags.
detail::InMemoryDirectory::const_iterator E
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i...
PreprocessorLexer * getCurrentFileLexer() const
Return the current file lexer being lexed from.
bool isFunctionLike() const
Encapsulates the data about a macro definition (e.g.
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.
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.
Defines the clang::SourceLocation class and associated facilities.
ModuleMacro * getModuleMacro(Module *Mod, IdentifierInfo *II)
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...
Defines the clang::TargetInfo interface.
void setPrevious(MacroDirective *Prev)
Set previous definition of the macro with the same name.
bool isCompilingModule() const
Are we compiling a module interface (.cppm or module map)?
unsigned getLength() const
void setLocation(SourceLocation L)
bool hadMacroDefinition() const
Returns true if this identifier was #defined to some value at any moment.
A trivial tuple used to represent a source range.
void clearFlag(TokenFlags Flag)
Unset the specified flag.
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.
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)
Stringify - Convert the specified string into a C string by escaping '\' and " characters. This does not add surrounding ""'s to the string.
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