26#include "llvm/ADT/ArrayRef.h"
27#include "llvm/ADT/StringSwitch.h"
36 Token &FirstToken)
override;
40 explicit PragmaGCCVisibilityHandler() :
PragmaHandler(
"visibility") {}
42 Token &FirstToken)
override;
48 Token &FirstToken)
override;
54 Token &FirstToken)
override;
58 explicit PragmaClangSectionHandler(
Sema &S)
61 Token &FirstToken)
override;
68 explicit PragmaMSStructHandler() :
PragmaHandler(
"ms_struct") {}
70 Token &FirstToken)
override;
76 Token &FirstToken)
override;
82 Token &FirstToken)
override;
86 explicit PragmaRedefineExtnameHandler() :
PragmaHandler(
"redefine_extname") {}
88 Token &FirstToken)
override;
92 PragmaOpenCLExtensionHandler() :
PragmaHandler(
"EXTENSION") {}
94 Token &FirstToken)
override;
101 Token &FirstToken)
override;
108 PragmaSTDC_FENV_ACCESSHandler() :
PragmaHandler(
"FENV_ACCESS") {}
111 Token &Tok)
override {
112 Token PragmaName = Tok;
124 Toks[0].startToken();
125 Toks[0].setKind(tok::annot_pragma_fenv_access);
128 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
130 PP.EnterTokenStream(Toks,
true,
136struct PragmaSTDC_CX_LIMITED_RANGEHandler :
public PragmaHandler {
137 PragmaSTDC_CX_LIMITED_RANGEHandler() :
PragmaHandler(
"CX_LIMITED_RANGE") {}
140 Token &Tok)
override {
148 Toks[0].startToken();
149 Toks[0].setKind(tok::annot_pragma_cx_limited_range);
152 Toks[0].setAnnotationValue(
153 reinterpret_cast<void *
>(
static_cast<uintptr_t>(OOS)));
154 PP.EnterTokenStream(Toks,
true,
161 PragmaSTDC_FENV_ROUNDHandler() :
PragmaHandler(
"FENV_ROUND") {}
164 Token &Tok)
override;
169 PragmaSTDC_UnknownHandler() =
default;
172 Token &UnknownTok)
override {
174 PP.
Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
181 Token &FirstToken)
override;
187template <diag::kind IgnoredDiag>
189 PragmaNoSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
191 Token &FirstToken)
override;
194struct PragmaNoOpenMPHandler
195 :
public PragmaNoSupportHandler<diag::warn_pragma_omp_ignored> {
196 PragmaNoOpenMPHandler() : PragmaNoSupportHandler(
"omp") {}
199struct PragmaNoOpenACCHandler
200 :
public PragmaNoSupportHandler<diag::warn_pragma_acc_ignored> {
201 PragmaNoOpenACCHandler() : PragmaNoSupportHandler(
"acc") {}
210 PragmaSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
212 Token &FirstToken)
override;
215struct PragmaOpenMPHandler
216 :
public PragmaSupportHandler<tok::annot_pragma_openmp,
217 tok::annot_pragma_openmp_end,
218 diag::err_omp_unexpected_directive> {
219 PragmaOpenMPHandler() : PragmaSupportHandler(
"omp") {}
222struct PragmaOpenACCHandler
223 :
public PragmaSupportHandler<tok::annot_pragma_openacc,
224 tok::annot_pragma_openacc_end,
225 diag::err_acc_unexpected_directive> {
226 PragmaOpenACCHandler() : PragmaSupportHandler(
"acc") {}
231 PragmaCommentHandler(
Sema &Actions)
234 Token &FirstToken)
override;
241 PragmaDetectMismatchHandler(
Sema &Actions)
244 Token &FirstToken)
override;
251 PragmaFloatControlHandler(
Sema &Actions)
254 Token &FirstToken)
override;
258 explicit PragmaMSPointersToMembers() :
PragmaHandler(
"pointers_to_members") {}
260 Token &FirstToken)
override;
266 Token &FirstToken)
override;
272 Token &FirstToken)
override;
277 PragmaOptimizeHandler(
Sema &S)
280 Token &FirstToken)
override;
289 Token &FirstToken)
override;
295 Token &FirstToken)
override;
305 Token &FirstToken)
override;
310 PragmaMSFenvAccessHandler() :
PragmaHandler(
"fenv_access") {}
312 Token &FirstToken)
override {
322 if (Tok.
isNot(tok::l_paren)) {
328 if (Tok.
isNot(tok::identifier)) {
334 if (II->
isStr(
"on")) {
337 }
else if (II->
isStr(
"off")) {
344 if (Tok.
isNot(tok::r_paren)) {
351 if (Tok.
isNot(tok::eod)) {
359 Toks[0].startToken();
360 Toks[0].setKind(tok::annot_pragma_fenv_access_ms);
363 Toks[0].setAnnotationValue(
364 reinterpret_cast<void*
>(
static_cast<uintptr_t>(OOS)));
365 PP.EnterTokenStream(Toks,
true,
370struct PragmaForceCUDAHostDeviceHandler :
public PragmaHandler {
371 PragmaForceCUDAHostDeviceHandler(
Sema &Actions)
372 :
PragmaHandler(
"force_cuda_host_device"), Actions(Actions) {}
374 Token &FirstToken)
override;
383 :
PragmaHandler(
"attribute"), AttributesForPragmaAttribute(AttrFactory) {}
385 Token &FirstToken)
override;
392 PragmaMaxTokensHereHandler() :
PragmaHandler(
"max_tokens_here") {}
394 Token &FirstToken)
override;
398 PragmaMaxTokensTotalHandler() :
PragmaHandler(
"max_tokens_total") {}
400 Token &FirstToken)
override;
404 PragmaRISCVHandler(
Sema &Actions)
407 Token &FirstToken)
override;
419void Parser::initializePragmaHandlers() {
420 AlignHandler = std::make_unique<PragmaAlignHandler>();
423 GCCVisibilityHandler = std::make_unique<PragmaGCCVisibilityHandler>();
426 OptionsHandler = std::make_unique<PragmaOptionsHandler>();
429 PackHandler = std::make_unique<PragmaPackHandler>();
432 MSStructHandler = std::make_unique<PragmaMSStructHandler>();
435 UnusedHandler = std::make_unique<PragmaUnusedHandler>();
438 WeakHandler = std::make_unique<PragmaWeakHandler>();
441 RedefineExtnameHandler = std::make_unique<PragmaRedefineExtnameHandler>();
444 FPContractHandler = std::make_unique<PragmaFPContractHandler>();
447 STDCFenvAccessHandler = std::make_unique<PragmaSTDC_FENV_ACCESSHandler>();
450 STDCFenvRoundHandler = std::make_unique<PragmaSTDC_FENV_ROUNDHandler>();
453 STDCCXLIMITHandler = std::make_unique<PragmaSTDC_CX_LIMITED_RANGEHandler>();
456 STDCUnknownHandler = std::make_unique<PragmaSTDC_UnknownHandler>();
459 PCSectionHandler = std::make_unique<PragmaClangSectionHandler>(Actions);
463 OpenCLExtensionHandler = std::make_unique<PragmaOpenCLExtensionHandler>();
469 OpenMPHandler = std::make_unique<PragmaOpenMPHandler>();
471 OpenMPHandler = std::make_unique<PragmaNoOpenMPHandler>();
475 OpenACCHandler = std::make_unique<PragmaOpenACCHandler>();
477 OpenACCHandler = std::make_unique<PragmaNoOpenACCHandler>();
482 MSCommentHandler = std::make_unique<PragmaCommentHandler>(Actions);
486 FloatControlHandler = std::make_unique<PragmaFloatControlHandler>(Actions);
489 MSDetectMismatchHandler =
490 std::make_unique<PragmaDetectMismatchHandler>(Actions);
492 MSPointersToMembers = std::make_unique<PragmaMSPointersToMembers>();
494 MSVtorDisp = std::make_unique<PragmaMSVtorDisp>();
496 MSInitSeg = std::make_unique<PragmaMSPragma>(
"init_seg");
498 MSDataSeg = std::make_unique<PragmaMSPragma>(
"data_seg");
500 MSBSSSeg = std::make_unique<PragmaMSPragma>(
"bss_seg");
502 MSConstSeg = std::make_unique<PragmaMSPragma>(
"const_seg");
504 MSCodeSeg = std::make_unique<PragmaMSPragma>(
"code_seg");
506 MSSection = std::make_unique<PragmaMSPragma>(
"section");
508 MSStrictGuardStackCheck =
509 std::make_unique<PragmaMSPragma>(
"strict_gs_check");
511 MSFunction = std::make_unique<PragmaMSPragma>(
"function");
513 MSAllocText = std::make_unique<PragmaMSPragma>(
"alloc_text");
515 MSOptimize = std::make_unique<PragmaMSPragma>(
"optimize");
517 MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
519 MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>();
521 MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
526 CUDAForceHostDeviceHandler =
527 std::make_unique<PragmaForceCUDAHostDeviceHandler>(Actions);
531 OptimizeHandler = std::make_unique<PragmaOptimizeHandler>(Actions);
534 LoopHintHandler = std::make_unique<PragmaLoopHintHandler>();
537 UnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"unroll");
541 NoUnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"nounroll");
545 UnrollAndJamHintHandler =
546 std::make_unique<PragmaUnrollHintHandler>(
"unroll_and_jam");
549 NoUnrollAndJamHintHandler =
550 std::make_unique<PragmaUnrollHintHandler>(
"nounroll_and_jam");
553 FPHandler = std::make_unique<PragmaFPHandler>();
556 AttributePragmaHandler =
557 std::make_unique<PragmaAttributeHandler>(AttrFactory);
560 MaxTokensHerePragmaHandler = std::make_unique<PragmaMaxTokensHereHandler>();
563 MaxTokensTotalPragmaHandler = std::make_unique<PragmaMaxTokensTotalHandler>();
567 RISCVPragmaHandler = std::make_unique<PragmaRISCVHandler>(Actions);
572void Parser::resetPragmaHandlers() {
575 AlignHandler.reset();
577 GCCVisibilityHandler.reset();
579 OptionsHandler.reset();
583 MSStructHandler.reset();
585 UnusedHandler.reset();
589 RedefineExtnameHandler.reset();
593 OpenCLExtensionHandler.reset();
597 OpenMPHandler.reset();
600 OpenACCHandler.reset();
605 MSCommentHandler.reset();
609 PCSectionHandler.reset();
612 FloatControlHandler.reset();
615 MSDetectMismatchHandler.reset();
617 MSPointersToMembers.reset();
633 MSStrictGuardStackCheck.reset();
639 MSRuntimeChecks.reset();
645 MSFenvAccess.reset();
650 CUDAForceHostDeviceHandler.reset();
654 FPContractHandler.reset();
657 STDCFenvAccessHandler.reset();
660 STDCFenvRoundHandler.reset();
663 STDCCXLIMITHandler.reset();
666 STDCUnknownHandler.reset();
669 OptimizeHandler.reset();
672 LoopHintHandler.reset();
676 UnrollHintHandler.reset();
680 NoUnrollHintHandler.reset();
683 UnrollAndJamHintHandler.reset();
686 NoUnrollAndJamHintHandler.reset();
692 AttributePragmaHandler.reset();
695 MaxTokensHerePragmaHandler.reset();
698 MaxTokensTotalPragmaHandler.reset();
702 RISCVPragmaHandler.reset();
711void Parser::HandlePragmaUnused() {
712 assert(Tok.
is(tok::annot_pragma_unused));
718void Parser::HandlePragmaVisibility() {
719 assert(Tok.
is(tok::annot_pragma_vis));
726void Parser::HandlePragmaPack() {
727 assert(Tok.
is(tok::annot_pragma_pack));
735 ConsumeAnnotationToken();
743 ConsumeAnnotationToken();
746void Parser::HandlePragmaMSStruct() {
747 assert(Tok.
is(tok::annot_pragma_msstruct));
751 ConsumeAnnotationToken();
754void Parser::HandlePragmaAlign() {
755 assert(Tok.
is(tok::annot_pragma_align));
762 ConsumeAnnotationToken();
765void Parser::HandlePragmaDump() {
766 assert(Tok.
is(tok::annot_pragma_dump));
767 ConsumeAnnotationToken();
768 if (Tok.
is(tok::eod)) {
769 PP.
Diag(Tok, diag::warn_pragma_debug_missing_argument) <<
"dump";
771 if (Tok.
isNot(tok::identifier)) {
772 PP.
Diag(Tok, diag::warn_pragma_debug_unexpected_argument);
774 ExpectAndConsume(tok::eod);
788 PP.
Diag(StartLoc, diag::warn_pragma_debug_dependent_argument)
796 ExpectAndConsume(tok::eod);
799void Parser::HandlePragmaWeak() {
800 assert(Tok.
is(tok::annot_pragma_weak));
807void Parser::HandlePragmaWeakAlias() {
808 assert(Tok.
is(tok::annot_pragma_weakalias));
817 WeakNameLoc, AliasNameLoc);
821void Parser::HandlePragmaRedefineExtname() {
822 assert(Tok.
is(tok::annot_pragma_redefine_extname));
831 RedefNameLoc, AliasNameLoc);
834void Parser::HandlePragmaFPContract() {
835 assert(Tok.
is(tok::annot_pragma_fp_contract));
862void Parser::HandlePragmaFloatControl() {
863 assert(Tok.
is(tok::annot_pragma_float_control));
878void Parser::HandlePragmaFEnvAccess() {
879 assert(Tok.
is(tok::annot_pragma_fenv_access) ||
880 Tok.
is(tok::annot_pragma_fenv_access_ms));
902void Parser::HandlePragmaFEnvRound() {
903 assert(Tok.
is(tok::annot_pragma_fenv_round));
904 auto RM =
static_cast<llvm::RoundingMode
>(
911void Parser::HandlePragmaCXLimitedRange() {
912 assert(Tok.
is(tok::annot_pragma_cx_limited_range));
938 assert(Tok.
is(tok::annot_pragma_captured));
939 ConsumeAnnotationToken();
941 if (Tok.
isNot(tok::l_brace)) {
942 PP.
Diag(Tok, diag::err_expected) << tok::l_brace;
954 CapturedRegionScope.Exit();
965 enum OpenCLExtState :
char {
966 Disable, Enable,
Begin, End
968 typedef std::pair<const IdentifierInfo *, OpenCLExtState> OpenCLExtData;
971void Parser::HandlePragmaOpenCLExtension() {
972 assert(Tok.
is(tok::annot_pragma_opencl_extension));
974 auto State =
Data->second;
975 auto Ident =
Data->first;
977 ConsumeAnnotationToken();
980 auto Name = Ident->getName();
985 if (State == Disable)
988 PP.
Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
989 }
else if (State ==
Begin) {
990 if (!Opt.isKnown(Name) || !Opt.isSupported(Name,
getLangOpts())) {
994 Opt.acceptsPragma(Name);
996 }
else if (State == End) {
999 }
else if (!Opt.isKnown(Name) || !Opt.isWithPragma(Name))
1000 PP.
Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
1001 else if (Opt.isSupportedExtension(Name,
getLangOpts()))
1002 Opt.enable(Name, State == Enable);
1003 else if (Opt.isSupportedCoreOrOptionalCore(Name,
getLangOpts()))
1004 PP.
Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
1006 PP.
Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;
1009void Parser::HandlePragmaMSPointersToMembers() {
1010 assert(Tok.
is(tok::annot_pragma_ms_pointers_to_members));
1018void Parser::HandlePragmaMSVtorDisp() {
1019 assert(Tok.
is(tok::annot_pragma_ms_vtordisp));
1028void Parser::HandlePragmaMSPragma() {
1029 assert(Tok.
is(tok::annot_pragma_ms_pragma));
1033 PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second,
true,
1044 llvm::StringSwitch<PragmaHandler>(PragmaName)
1045 .Case(
"data_seg", &Parser::HandlePragmaMSSegment)
1046 .Case(
"bss_seg", &Parser::HandlePragmaMSSegment)
1047 .Case(
"const_seg", &Parser::HandlePragmaMSSegment)
1048 .Case(
"code_seg", &Parser::HandlePragmaMSSegment)
1049 .Case(
"section", &Parser::HandlePragmaMSSection)
1050 .Case(
"init_seg", &Parser::HandlePragmaMSInitSeg)
1051 .Case(
"strict_gs_check", &Parser::HandlePragmaMSStrictGuardStackCheck)
1052 .Case(
"function", &Parser::HandlePragmaMSFunction)
1053 .Case(
"alloc_text", &Parser::HandlePragmaMSAllocText)
1054 .Case(
"optimize", &Parser::HandlePragmaMSOptimize);
1056 if (!(this->*Handler)(PragmaName, PragmaLocation)) {
1059 while (Tok.
isNot(tok::eof))
1065bool Parser::HandlePragmaMSSection(StringRef PragmaName,
1067 if (Tok.
isNot(tok::l_paren)) {
1068 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1073 if (Tok.
isNot(tok::string_literal)) {
1074 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1083 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1088 bool SectionFlagsAreDefault =
true;
1089 while (Tok.
is(tok::comma)) {
1094 if (Tok.
is(tok::kw_long) || Tok.
is(tok::kw_short)) {
1100 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
1105 llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
1118 ? diag::warn_pragma_invalid_specific_action
1119 : diag::warn_pragma_unsupported_action)
1123 SectionFlags |= Flag;
1124 SectionFlagsAreDefault =
false;
1129 if (SectionFlagsAreDefault)
1131 if (Tok.
isNot(tok::r_paren)) {
1132 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1136 if (Tok.
isNot(tok::eof)) {
1137 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1146bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
1148 if (Tok.
isNot(tok::l_paren)) {
1149 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1154 StringRef SlotLabel;
1157 if (PushPop ==
"push")
1159 else if (PushPop ==
"pop")
1162 PP.
Diag(PragmaLocation,
1163 diag::warn_pragma_expected_section_push_pop_or_name)
1169 if (Tok.
is(tok::comma)) {
1175 if (Tok.
is(tok::comma))
1177 else if (Tok.
isNot(tok::r_paren)) {
1178 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc)
1183 }
else if (Tok.
isNot(tok::r_paren)) {
1184 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
1191 if (Tok.
isNot(tok::r_paren)) {
1192 if (Tok.
isNot(tok::string_literal)) {
1194 diag::warn_pragma_expected_section_name :
1195 diag::warn_pragma_expected_section_label_or_name :
1196 diag::warn_pragma_expected_section_push_pop_or_name;
1197 PP.
Diag(PragmaLocation, DiagID) << PragmaName;
1203 SegmentName = cast<StringLiteral>(StringResult.
get());
1205 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1213 if (Tok.
isNot(tok::r_paren)) {
1214 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1218 if (Tok.
isNot(tok::eof)) {
1219 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1225 SegmentName, PragmaName);
1230bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
1232 if (
getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
1233 PP.
Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
1237 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1245 StringRef Section = llvm::StringSwitch<StringRef>(II->
getName())
1246 .Case(
"compiler",
"\".CRT$XCC\"")
1247 .Case(
"lib",
"\".CRT$XCL\"")
1248 .Case(
"user",
"\".CRT$XCU\"")
1251 if (!Section.empty()) {
1255 Toks[0].
setKind(tok::string_literal);
1263 }
else if (Tok.
is(tok::string_literal)) {
1267 SegmentName = cast<StringLiteral>(StringResult.
get());
1269 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1277 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
1281 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1283 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1294bool Parser::HandlePragmaMSStrictGuardStackCheck(
1296 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1301 if (Tok.
is(tok::identifier)) {
1303 if (PushPop ==
"push") {
1306 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
1309 }
else if (PushPop ==
"pop") {
1318 if (II && II->
isStr(
"off")) {
1321 }
else if (II && II->
isStr(
"on")) {
1332 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1336 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1344bool Parser::HandlePragmaMSAllocText(StringRef PragmaName,
1346 Token FirstTok = Tok;
1347 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1352 if (Tok.
is(tok::string_literal)) {
1358 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1363 }
else if (Tok.
is(tok::identifier)) {
1367 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1372 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
1378 if (Tok.
isNot(tok::identifier)) {
1388 if (Tok.
isNot(tok::comma))
1393 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1395 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1405 std::string ClangLoopStr(
"clang loop ");
1408 return std::string(llvm::StringSwitch<StringRef>(Str)
1409 .Case(
"loop", ClangLoopStr)
1410 .Case(
"unroll_and_jam", Str)
1411 .Case(
"unroll", Str)
1415bool Parser::HandlePragmaLoopHint(
LoopHint &Hint) {
1416 assert(Tok.
is(tok::annot_pragma_loop_hint));
1436 auto IsLoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->
getName())
1437 .Cases(
"unroll",
"nounroll",
"unroll_and_jam",
1438 "nounroll_and_jam",
true)
1441 if (Toks.empty() && IsLoopHint) {
1442 ConsumeAnnotationToken();
1449 assert(!Toks.empty() &&
1450 "PragmaLoopHintInfo::Toks must contain at least one token.");
1453 bool OptionUnroll =
false;
1454 bool OptionUnrollAndJam =
false;
1455 bool OptionDistribute =
false;
1456 bool OptionPipelineDisabled =
false;
1457 bool StateOption =
false;
1459 OptionUnroll = OptionInfo->
isStr(
"unroll");
1460 OptionUnrollAndJam = OptionInfo->
isStr(
"unroll_and_jam");
1461 OptionDistribute = OptionInfo->
isStr(
"distribute");
1462 OptionPipelineDisabled = OptionInfo->
isStr(
"pipeline");
1463 StateOption = llvm::StringSwitch<bool>(OptionInfo->
getName())
1464 .Case(
"vectorize",
true)
1465 .Case(
"interleave",
true)
1466 .Case(
"vectorize_predicate",
true)
1468 OptionUnroll || OptionUnrollAndJam || OptionDistribute ||
1469 OptionPipelineDisabled;
1472 bool AssumeSafetyArg = !OptionUnroll && !OptionUnrollAndJam &&
1473 !OptionDistribute && !OptionPipelineDisabled;
1475 if (Toks[0].is(tok::eof)) {
1476 ConsumeAnnotationToken();
1477 Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
1479 << (OptionUnroll || OptionUnrollAndJam)
1486 ConsumeAnnotationToken();
1490 bool Valid = StateInfo &&
1491 llvm::StringSwitch<bool>(StateInfo->
getName())
1492 .Case(
"disable",
true)
1493 .Case(
"enable", !OptionPipelineDisabled)
1494 .Case(
"full", OptionUnroll || OptionUnrollAndJam)
1495 .Case(
"assume_safety", AssumeSafetyArg)
1498 if (OptionPipelineDisabled) {
1499 Diag(Toks[0].getLocation(), diag::err_pragma_pipeline_invalid_keyword);
1501 Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
1502 << (OptionUnroll || OptionUnrollAndJam)
1507 if (Toks.size() > 2)
1511 }
else if (OptionInfo && OptionInfo->
getName() ==
"vectorize_width") {
1512 PP.EnterTokenStream(Toks,
false,
1514 ConsumeAnnotationToken();
1518 StringRef IsScalableStr = StateInfo ? StateInfo->
getName() :
"";
1521 if (IsScalableStr ==
"scalable" || IsScalableStr ==
"fixed") {
1524 if (Toks.size() > 2) {
1527 while (Tok.
isNot(tok::eof))
1540 Diag(Toks[0].getLocation(),
1541 diag::note_pragma_loop_invalid_vectorize_option);
1543 bool Arg2Error =
false;
1544 if (Tok.
is(tok::comma)) {
1548 IsScalableStr = StateInfo->
getName();
1550 if (IsScalableStr !=
"scalable" && IsScalableStr !=
"fixed") {
1552 diag::err_pragma_loop_invalid_vectorize_option);
1563 if (Tok.
isNot(tok::eof)) {
1566 while (Tok.
isNot(tok::eof))
1582 PP.EnterTokenStream(Toks,
false,
1584 ConsumeAnnotationToken();
1589 if (Tok.
isNot(tok::eof)) {
1592 while (Tok.
isNot(tok::eof))
1608 Info->
Toks.back().getLocation());
1613struct PragmaAttributeInfo {
1614 enum ActionType { Push,
Pop, Attribute };
1620 PragmaAttributeInfo(
ParsedAttributes &Attributes) : Attributes(Attributes) {}
1623#include "clang/Parse/AttrSubMatchRulesParserStringSwitches.inc"
1628 if (Tok.
is(tok::identifier))
1637 using namespace attr;
1639#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) \
1642#include "clang/Basic/AttrSubMatchRulesList.inc"
1644 llvm_unreachable(
"Invalid attribute subject match rule");
1652 PRef.
Diag(SubRuleLoc,
1653 diag::err_pragma_attribute_expected_subject_sub_identifier)
1655 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1666 PRef.
Diag(SubRuleLoc, diag::err_pragma_attribute_unknown_subject_sub_rule)
1667 << SubRuleName << PrimaryRuleName;
1668 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1674bool Parser::ParsePragmaAttributeSubjectMatchRuleSet(
1682 if (AnyParens.expectAndConsume())
1690 Diag(Tok, diag::err_pragma_attribute_expected_subject_identifier);
1693 std::pair<std::optional<attr::SubjectMatchRule>,
1694 std::optional<attr::SubjectMatchRule> (*)(StringRef,
bool)>
1695 Rule = isAttributeSubjectMatchRule(Name);
1697 Diag(Tok, diag::err_pragma_attribute_unknown_subject_rule) << Name;
1705 if (
Parens.expectAndConsume())
1707 }
else if (
Parens.consumeOpen()) {
1708 if (!SubjectMatchRules
1710 std::make_pair(PrimaryRule,
SourceRange(RuleLoc, RuleLoc)))
1712 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1715 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleLoc));
1716 LastMatchRuleEndLoc = RuleLoc;
1722 if (SubRuleName.empty()) {
1728 if (SubRuleName ==
"unless") {
1731 if (
Parens.expectAndConsume())
1734 if (SubRuleName.empty()) {
1739 auto SubRuleOrNone = Rule.second(SubRuleName,
true);
1740 if (!SubRuleOrNone) {
1741 std::string SubRuleUnlessName =
"unless(" + SubRuleName.str() +
")";
1743 SubRuleUnlessName, SubRuleLoc);
1746 SubRule = *SubRuleOrNone;
1748 if (
Parens.consumeClose())
1751 auto SubRuleOrNone = Rule.second(SubRuleName,
false);
1752 if (!SubRuleOrNone) {
1757 SubRule = *SubRuleOrNone;
1761 LastMatchRuleEndLoc = RuleEndLoc;
1762 if (
Parens.consumeClose())
1764 if (!SubjectMatchRules
1765 .insert(std::make_pair(SubRule,
SourceRange(RuleLoc, RuleEndLoc)))
1767 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1770 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleEndLoc));
1776 if (AnyParens.consumeClose())
1785enum class MissingAttributeSubjectRulesRecoveryPoint {
1793MissingAttributeSubjectRulesRecoveryPoint
1794getAttributeSubjectRulesRecoveryPointForToken(
const Token &Tok) {
1796 if (II->
isStr(
"apply_to"))
1797 return MissingAttributeSubjectRulesRecoveryPoint::ApplyTo;
1798 if (II->
isStr(
"any"))
1799 return MissingAttributeSubjectRulesRecoveryPoint::Any;
1801 if (Tok.
is(tok::equal))
1802 return MissingAttributeSubjectRulesRecoveryPoint::Equals;
1803 return MissingAttributeSubjectRulesRecoveryPoint::None;
1811 MissingAttributeSubjectRulesRecoveryPoint Point,
Parser &PRef) {
1817 MissingAttributeSubjectRulesRecoveryPoint EndPoint =
1818 getAttributeSubjectRulesRecoveryPointForToken(PRef.
getCurToken());
1819 if (Point == MissingAttributeSubjectRulesRecoveryPoint::Comma)
1821 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::ApplyTo &&
1822 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::ApplyTo)
1823 FixIt +=
"apply_to";
1824 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::Equals &&
1825 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::Equals)
1828 if (EndPoint == MissingAttributeSubjectRulesRecoveryPoint::None) {
1835 Attribute.getMatchRules(PRef.
getLangOpts(), MatchRules);
1837 for (
const auto &Rule : MatchRules) {
1842 IsSupported[Rule.first] =
true;
1844 IsMatchRuleAvailable &= IsSupported;
1846 if (IsMatchRuleAvailable.count() == 0) {
1852 bool NeedsComma =
false;
1854 if (!IsMatchRuleAvailable[I])
1868 if (FixItRange.getBegin() == FixItRange.getEnd())
1878void Parser::HandlePragmaAttribute() {
1879 assert(Tok.
is(tok::annot_pragma_attribute) &&
1880 "Expected #pragma attribute annotation token");
1883 if (Info->Action == PragmaAttributeInfo::Pop) {
1884 ConsumeAnnotationToken();
1889 assert((Info->Action == PragmaAttributeInfo::Push ||
1890 Info->Action == PragmaAttributeInfo::Attribute) &&
1891 "Unexpected #pragma attribute command");
1893 if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) {
1894 ConsumeAnnotationToken();
1899 PP.EnterTokenStream(Info->Tokens,
false,
1901 ConsumeAnnotationToken();
1906 auto SkipToEnd = [
this]() {
1911 if ((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1914 ParseCXX11AttributeSpecifier(Attrs);
1915 }
else if (Tok.
is(tok::kw___attribute)) {
1917 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
1920 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"("))
1925 if (Tok.
is(tok::code_completion)) {
1935 if (Tok.
isNot(tok::identifier)) {
1936 Diag(Tok, diag::err_pragma_attribute_expected_attribute_name);
1943 if (Tok.
isNot(tok::l_paren))
1944 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1945 ParsedAttr::Form::GNU());
1947 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs,
nullptr,
1950 ParsedAttr::Form::GNU(),
1954 if (ExpectAndConsume(tok::r_paren))
1956 if (ExpectAndConsume(tok::r_paren))
1958 }
else if (Tok.
is(tok::kw___declspec)) {
1959 ParseMicrosoftDeclSpecs(Attrs);
1961 Diag(Tok, diag::err_pragma_attribute_expected_attribute_syntax);
1970 if (Tok.
is(tok::l_paren)) {
1973 if (Tok.
isNot(tok::r_paren))
1976 Diag(Tok, diag::note_pragma_attribute_use_attribute_kw)
1985 if (Attrs.
empty() || Attrs.
begin()->isInvalid()) {
1991 if (!Attribute.isSupportedByPragmaAttribute()) {
1992 Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute)
2001 createExpectedAttributeSubjectRulesTokenDiagnostic(
2002 diag::err_expected, Attrs,
2003 MissingAttributeSubjectRulesRecoveryPoint::Comma, *
this)
2009 if (Tok.
isNot(tok::identifier)) {
2010 createExpectedAttributeSubjectRulesTokenDiagnostic(
2011 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2012 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2017 if (!II->
isStr(
"apply_to")) {
2018 createExpectedAttributeSubjectRulesTokenDiagnostic(
2019 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2020 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2027 createExpectedAttributeSubjectRulesTokenDiagnostic(
2028 diag::err_expected, Attrs,
2029 MissingAttributeSubjectRulesRecoveryPoint::Equals, *
this)
2037 if (ParsePragmaAttributeSubjectMatchRuleSet(SubjectMatchRules, AnyLoc,
2038 LastMatchRuleEndLoc)) {
2045 if (Tok.
isNot(tok::eof)) {
2046 Diag(Tok, diag::err_pragma_attribute_extra_tokens_after_attribute);
2055 if (Info->Action == PragmaAttributeInfo::Push)
2067void PragmaGCCVisibilityHandler::HandlePragma(
Preprocessor &PP,
2078 if (PushPop && PushPop->
isStr(
"pop")) {
2080 }
else if (PushPop && PushPop->
isStr(
"push")) {
2082 if (Tok.
isNot(tok::l_paren)) {
2095 if (Tok.
isNot(tok::r_paren)) {
2107 if (Tok.
isNot(tok::eod)) {
2113 auto Toks = std::make_unique<Token[]>(1);
2114 Toks[0].startToken();
2115 Toks[0].setKind(tok::annot_pragma_vis);
2116 Toks[0].setLocation(VisLoc);
2117 Toks[0].setAnnotationEndLoc(EndLoc);
2118 Toks[0].setAnnotationValue(
2119 const_cast<void *
>(
static_cast<const void *
>(VisType)));
2120 PP.EnterTokenStream(std::move(Toks), 1,
true,
2135 if (Tok.
isNot(tok::l_paren)) {
2136 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
2141 StringRef SlotLabel;
2145 if (Tok.
is(tok::numeric_constant)) {
2156 }
else if (Tok.
is(tok::identifier)) {
2158 if (II->
isStr(
"show")) {
2162 if (II->
isStr(
"push")) {
2164 }
else if (II->
isStr(
"pop")) {
2167 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
2172 if (Tok.
is(tok::comma)) {
2175 if (Tok.
is(tok::numeric_constant)) {
2180 }
else if (Tok.
is(tok::identifier)) {
2184 if (Tok.
is(tok::comma)) {
2187 if (Tok.
isNot(tok::numeric_constant)) {
2212 if (Tok.
isNot(tok::r_paren)) {
2213 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
2219 if (Tok.
isNot(tok::eod)) {
2220 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
2232 Toks[0].startToken();
2233 Toks[0].setKind(tok::annot_pragma_pack);
2234 Toks[0].setLocation(PackLoc);
2235 Toks[0].setAnnotationEndLoc(RParenLoc);
2236 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2237 PP.EnterTokenStream(Toks,
true,
2243void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
2245 Token &MSStructTok) {
2250 if (Tok.
isNot(tok::identifier)) {
2256 if (II->
isStr(
"on")) {
2260 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
2267 if (Tok.
isNot(tok::eod)) {
2275 Toks[0].startToken();
2276 Toks[0].setKind(tok::annot_pragma_msstruct);
2278 Toks[0].setAnnotationEndLoc(EndLoc);
2279 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2281 PP.EnterTokenStream(Toks,
true,
2286void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
2288 Token &FirstToken) {
2294 while (Tok.
isNot(tok::eod)) {
2295 if (Tok.
isNot(tok::identifier)) {
2296 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2301 if (SecType->
isStr(
"bss"))
2303 else if (SecType->
isStr(
"data"))
2305 else if (SecType->
isStr(
"rodata"))
2307 else if (SecType->
isStr(
"relro"))
2309 else if (SecType->
isStr(
"text"))
2312 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2318 if (Tok.
isNot(tok::equal)) {
2319 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal) << SecKind;
2323 std::string SecName;
2327 Actions.ActOnPragmaClangSection(
2344 if (Tok.
isNot(tok::identifier) ||
2353 if (Tok.
isNot(tok::l_paren)) {
2354 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"align";
2357 }
else if (Tok.
isNot(tok::equal)) {
2364 if (Tok.
isNot(tok::identifier)) {
2366 << (IsOptions ?
"options" :
"align");
2372 if (II->
isStr(
"native"))
2374 else if (II->
isStr(
"natural"))
2376 else if (II->
isStr(
"packed"))
2378 else if (II->
isStr(
"power"))
2380 else if (II->
isStr(
"mac68k"))
2382 else if (II->
isStr(
"reset"))
2392 if (Tok.
isNot(tok::r_paren)) {
2393 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"align";
2400 if (Tok.
isNot(tok::eod)) {
2402 << (IsOptions ?
"options" :
"align");
2408 Toks[0].startToken();
2409 Toks[0].setKind(tok::annot_pragma_align);
2411 Toks[0].setAnnotationEndLoc(EndLoc);
2412 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2414 PP.EnterTokenStream(Toks,
true,
2424void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
2426 Token &OptionsTok) {
2431void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
2440 if (Tok.
isNot(tok::l_paren)) {
2441 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
2454 if (Tok.
is(tok::identifier)) {
2455 Identifiers.push_back(Tok);
2466 if (Tok.
is(tok::comma)) {
2471 if (Tok.
is(tok::r_paren)) {
2477 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
2482 if (Tok.
isNot(tok::eod)) {
2489 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
2490 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
2499 2 * Identifiers.size());
2500 for (
unsigned i=0; i != Identifiers.size(); i++) {
2501 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
2503 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
2505 idTok = Identifiers[i];
2507 PP.EnterTokenStream(Toks,
true,
2520 if (Tok.
isNot(tok::identifier)) {
2521 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
2525 Token WeakName = Tok;
2526 bool HasAlias =
false;
2530 if (Tok.
is(tok::equal)) {
2533 if (Tok.
isNot(tok::identifier)) {
2542 if (Tok.
isNot(tok::eod)) {
2543 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
2550 Token &pragmaUnusedTok = Toks[0];
2552 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
2556 Toks[2] = AliasName;
2557 PP.EnterTokenStream(Toks,
true,
2562 Token &pragmaUnusedTok = Toks[0];
2564 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
2568 PP.EnterTokenStream(Toks,
true,
2574void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
2576 Token &RedefToken) {
2581 if (Tok.
isNot(tok::identifier)) {
2587 Token RedefName = Tok;
2590 if (Tok.
isNot(tok::identifier)) {
2592 <<
"redefine_extname";
2596 Token AliasName = Tok;
2599 if (Tok.
isNot(tok::eod)) {
2607 Token &pragmaRedefTok = Toks[0];
2609 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
2612 Toks[1] = RedefName;
2613 Toks[2] = AliasName;
2614 PP.EnterTokenStream(Toks,
true,
2618void PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
2627 Toks[0].startToken();
2628 Toks[0].setKind(tok::annot_pragma_fp_contract);
2631 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2633 PP.EnterTokenStream(Toks,
true,
2637void PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
2641 if (Tok.
isNot(tok::identifier)) {
2650 if (Tok.
isNot(tok::colon)) {
2656 if (Tok.
isNot(tok::identifier)) {
2657 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
2662 OpenCLExtState State;
2663 if (Pred->
isStr(
"enable")) {
2665 }
else if (Pred->
isStr(
"disable")) {
2667 }
else if (Pred->
isStr(
"begin"))
2669 else if (Pred->
isStr(
"end"))
2673 << Ext->
isStr(
"all");
2679 if (Tok.
isNot(tok::eod)) {
2687 Info->second = State;
2690 Toks[0].startToken();
2691 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2692 Toks[0].setLocation(NameLoc);
2693 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2694 Toks[0].setAnnotationEndLoc(StateLoc);
2695 PP.EnterTokenStream(Toks,
true,
2705template <diag::kind IgnoredDiag>
2706void PragmaNoSupportHandler<IgnoredDiag>::HandlePragma(
2709 PP.
Diag(FirstTok, IgnoredDiag);
2720void PragmaSupportHandler<StartTok, EndTok, UnexpectedDiag>::HandlePragma(
2728 while (Tok.
isNot(tok::eod) && Tok.
isNot(tok::eof)) {
2729 Pragma.push_back(Tok);
2731 if (Tok.
is(StartTok)) {
2732 PP.
Diag(Tok, UnexpectedDiag) << 0;
2733 unsigned InnerPragmaCnt = 1;
2734 while (InnerPragmaCnt != 0) {
2736 if (Tok.
is(StartTok))
2738 else if (Tok.
is(EndTok))
2748 Pragma.push_back(Tok);
2750 auto Toks = std::make_unique<Token[]>(Pragma.size());
2751 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2752 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2764void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2769 if (Tok.
isNot(tok::l_paren)) {
2770 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2771 <<
"pointers_to_members";
2778 <<
"pointers_to_members";
2784 if (Arg->
isStr(
"best_case")) {
2787 if (Arg->
isStr(
"full_generality")) {
2788 if (Tok.
is(tok::comma)) {
2794 diag::err_pragma_pointers_to_members_unknown_kind)
2799 }
else if (Tok.
is(tok::r_paren)) {
2806 <<
"full_generality";
2812 if (Arg->
isStr(
"single_inheritance")) {
2813 RepresentationMethod =
2815 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2816 RepresentationMethod =
2818 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2819 RepresentationMethod =
2823 diag::err_pragma_pointers_to_members_unknown_kind)
2830 if (Tok.
isNot(tok::r_paren)) {
2832 << (Arg ? Arg->
getName() :
"full_generality");
2838 if (Tok.
isNot(tok::eod)) {
2840 <<
"pointers_to_members";
2846 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2850 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RepresentationMethod)));
2866 if (Tok.
isNot(tok::l_paren)) {
2867 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2875 if (II->
isStr(
"push")) {
2878 if (Tok.
isNot(tok::comma)) {
2879 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2885 }
else if (II->
isStr(
"pop")) {
2892 if (Tok.
is(tok::r_paren)) {
2902 if (II && II->
isStr(
"off")) {
2905 }
else if (II && II->
isStr(
"on")) {
2908 }
else if (Tok.
is(tok::numeric_constant) &&
2912 << 0 << 2 <<
"vtordisp";
2923 if (Tok.
isNot(tok::r_paren)) {
2924 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2929 if (Tok.
isNot(tok::eod)) {
2938 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2950 Token EoF, AnnotTok;
2954 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2959 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2960 TokenVector.push_back(Tok);
2964 TokenVector.push_back(EoF);
2967 markAsReinjectedForRelexing(TokenVector);
2968 auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
2969 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2971 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2972 TokenVector.size());
2988void PragmaFloatControlHandler::HandlePragma(
Preprocessor &PP,
2993 Token PragmaName = Tok;
3000 if (Tok.
isNot(tok::l_paren)) {
3001 PP.
Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
3007 if (Tok.
isNot(tok::identifier)) {
3015 llvm::StringSwitch<PragmaFloatControlKind>(II->
getName())
3026 if (Tok.
isNot(tok::r_paren)) {
3033 if (Tok.
is(tok::r_paren))
3036 else if (Tok.
isNot(tok::comma)) {
3046 if (PushOnOff ==
"on")
3049 else if (PushOnOff ==
"off") {
3054 }
else if (PushOnOff ==
"push") {
3061 if (Tok.
is(tok::comma)) {
3068 if (ExpectedPush ==
"push") {
3076 if (Tok.
isNot(tok::r_paren)) {
3084 if (Tok.
isNot(tok::eod)) {
3093 auto TokenArray = std::make_unique<Token[]>(1);
3094 TokenArray[0].startToken();
3095 TokenArray[0].setKind(tok::annot_pragma_float_control);
3096 TokenArray[0].setLocation(FloatControlLoc);
3097 TokenArray[0].setAnnotationEndLoc(EndLoc);
3100 TokenArray[0].setAnnotationValue(
reinterpret_cast<void *
>(
3101 static_cast<uintptr_t>((Action << 16) | (Kind & 0xFFFF))));
3102 PP.EnterTokenStream(std::move(TokenArray), 1,
3116void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
3121 if (Tok.
isNot(tok::l_paren)) {
3122 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
3127 std::string NameString;
3129 "pragma detect_mismatch",
3134 std::string ValueString;
3135 if (Tok.
isNot(tok::comma)) {
3136 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3144 if (Tok.
isNot(tok::r_paren)) {
3150 if (Tok.
isNot(tok::eod)) {
3151 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3160 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
3172void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
3177 if (Tok.
isNot(tok::l_paren)) {
3178 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3184 if (Tok.
isNot(tok::identifier)) {
3185 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3192 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
3212 std::string ArgumentString;
3225 if (Tok.
isNot(tok::r_paren)) {
3231 if (Tok.
isNot(tok::eod)) {
3240 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
3245void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
3247 Token &FirstToken) {
3250 if (Tok.
is(tok::eod)) {
3252 <<
"clang optimize" <<
true <<
"'on' or 'off'";
3255 if (Tok.
isNot(tok::identifier)) {
3256 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3263 if (II->
isStr(
"on")) {
3265 }
else if (!II->
isStr(
"off")) {
3266 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3272 if (Tok.
isNot(tok::eod)) {
3278 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
3283struct TokFPAnnotValue {
3284 enum FlagValues { On, Off, Fast };
3286 std::optional<LangOptions::FPModeKind> ContractValue;
3287 std::optional<LangOptions::FPModeKind> ReassociateValue;
3288 std::optional<LangOptions::FPModeKind> ReciprocalValue;
3289 std::optional<LangOptions::FPExceptionModeKind> ExceptionsValue;
3290 std::optional<LangOptions::FPEvalMethodKind> EvalMethodValue;
3297 Token PragmaName = Tok;
3301 if (Tok.
isNot(tok::identifier)) {
3308 while (Tok.
is(tok::identifier)) {
3312 llvm::StringSwitch<std::optional<PragmaFPKind>>(OptionInfo->
getName())
3318 .Default(std::nullopt);
3321 <<
false << OptionInfo;
3327 if (Tok.
isNot(tok::l_paren)) {
3332 bool isEvalMethodDouble =
3336 if (Tok.
isNot(tok::identifier) && !isEvalMethodDouble) {
3339 <<
static_cast<int>(*FlagKind);
3345 AnnotValue->ContractValue =
3346 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3351 .Default(std::nullopt);
3352 if (!AnnotValue->ContractValue) {
3359 : AnnotValue->ReciprocalValue;
3360 Value = llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3364 .Default(std::nullopt);
3371 AnnotValue->ExceptionsValue =
3372 llvm::StringSwitch<std::optional<LangOptions::FPExceptionModeKind>>(
3377 .Default(std::nullopt);
3378 if (!AnnotValue->ExceptionsValue) {
3384 AnnotValue->EvalMethodValue =
3385 llvm::StringSwitch<std::optional<LangOptions::FPEvalMethodKind>>(
3390 .Default(std::nullopt);
3391 if (!AnnotValue->EvalMethodValue) {
3400 if (Tok.
isNot(tok::r_paren)) {
3407 if (Tok.
isNot(tok::eod)) {
3415 FPTok.
setKind(tok::annot_pragma_fp);
3419 TokenList.push_back(FPTok);
3421 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3422 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3424 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3428void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(
Preprocessor &PP,
3431 Token PragmaName = Tok;
3440 if (Tok.
isNot(tok::identifier)) {
3448 llvm::StringSwitch<llvm::RoundingMode>(II->
getName())
3449 .Case(
"FE_TOWARDZERO", llvm::RoundingMode::TowardZero)
3450 .Case(
"FE_TONEAREST", llvm::RoundingMode::NearestTiesToEven)
3451 .Case(
"FE_UPWARD", llvm::RoundingMode::TowardPositive)
3452 .Case(
"FE_DOWNWARD", llvm::RoundingMode::TowardNegative)
3453 .Case(
"FE_TONEARESTFROMZERO", llvm::RoundingMode::NearestTiesToAway)
3454 .Case(
"FE_DYNAMIC", llvm::RoundingMode::Dynamic)
3455 .Default(llvm::RoundingMode::Invalid);
3456 if (RM == llvm::RoundingMode::Invalid) {
3462 if (Tok.
isNot(tok::eod)) {
3464 <<
"STDC FENV_ROUND";
3473 Toks[0].startToken();
3474 Toks[0].setKind(tok::annot_pragma_fenv_round);
3477 Toks[0].setAnnotationValue(
3478 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RM)));
3479 PP.EnterTokenStream(Toks,
true,
3483void Parser::HandlePragmaFP() {
3484 assert(Tok.
is(tok::annot_pragma_fp));
3488 if (AnnotValue->ReassociateValue)
3493 if (AnnotValue->ReciprocalValue)
3498 if (AnnotValue->ContractValue)
3500 *AnnotValue->ContractValue);
3501 if (AnnotValue->ExceptionsValue)
3503 *AnnotValue->ExceptionsValue);
3504 if (AnnotValue->EvalMethodValue)
3506 *AnnotValue->EvalMethodValue);
3507 ConsumeAnnotationToken();
3512 Token Option,
bool ValueInParens,
3515 int OpenParens = ValueInParens ? 1 : 0;
3517 while (Tok.
isNot(tok::eod)) {
3518 if (Tok.
is(tok::l_paren))
3520 else if (Tok.
is(tok::r_paren)) {
3522 if (OpenParens == 0 && ValueInParens)
3530 if (ValueInParens) {
3532 if (Tok.
isNot(tok::r_paren)) {
3601void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
3605 Token PragmaName = Tok;
3610 if (Tok.
isNot(tok::identifier)) {
3616 while (Tok.
is(tok::identifier)) {
3620 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
3621 .Case(
"vectorize",
true)
3622 .Case(
"interleave",
true)
3623 .Case(
"unroll",
true)
3624 .Case(
"distribute",
true)
3625 .Case(
"vectorize_predicate",
true)
3626 .Case(
"vectorize_width",
true)
3627 .Case(
"interleave_count",
true)
3628 .Case(
"unroll_count",
true)
3629 .Case(
"pipeline",
true)
3630 .Case(
"pipeline_initiation_interval",
true)
3634 <<
false << OptionInfo;
3640 if (Tok.
isNot(tok::l_paren)) {
3654 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
3658 TokenList.push_back(LoopHintTok);
3661 if (Tok.
isNot(tok::eod)) {
3667 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3668 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3670 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3695void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
3700 Token PragmaName = Tok;
3703 if (Tok.
is(tok::eod)) {
3705 Info->PragmaName = PragmaName;
3706 Info->Option.startToken();
3716 bool ValueInParens = Tok.
is(tok::l_paren);
3728 PP.
Diag(Info->Toks[0].getLocation(),
3729 diag::warn_pragma_unroll_cuda_value_in_parens);
3731 if (Tok.
isNot(tok::eod)) {
3739 auto TokenArray = std::make_unique<Token[]>(1);
3740 TokenArray[0].startToken();
3741 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
3742 TokenArray[0].setLocation(Introducer.
Loc);
3743 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
3744 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3745 PP.EnterTokenStream(std::move(TokenArray), 1,
3761void PragmaMSIntrinsicHandler::HandlePragma(
Preprocessor &PP,
3766 if (Tok.
isNot(tok::l_paren)) {
3775 while (Tok.
is(tok::identifier)) {
3779 << II << SuggestIntrinH;
3782 if (Tok.
isNot(tok::comma))
3787 if (Tok.
isNot(tok::r_paren)) {
3794 if (Tok.
isNot(tok::eod))
3799bool Parser::HandlePragmaMSFunction(StringRef PragmaName,
3801 Token FirstTok = Tok;
3803 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3810 while (Tok.
is(tok::identifier)) {
3814 << II << SuggestIntrinH;
3816 NoBuiltins.emplace_back(II->
getName());
3819 if (Tok.
isNot(tok::comma))
3824 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3826 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3835bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3837 Token FirstTok = Tok;
3838 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3842 if (Tok.
isNot(tok::string_literal)) {
3843 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_string) << PragmaName;
3851 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
3856 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
3860 if (Tok.
is(tok::eof) || Tok.
is(tok::r_paren)) {
3861 PP.
Diag(PragmaLocation, diag::warn_pragma_missing_argument)
3862 << PragmaName <<
true <<
"'on' or 'off'";
3866 if (!II || (!II->
isStr(
"on") && !II->
isStr(
"off"))) {
3867 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3872 bool IsOn = II->
isStr(
"on");
3875 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3880 if (!OptimizationList->
getString().empty()) {
3881 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3882 << OptimizationList->
getString() << PragmaName <<
true
3887 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3895void PragmaForceCUDAHostDeviceHandler::HandlePragma(
3897 Token FirstTok = Tok;
3901 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
3903 diag::warn_pragma_force_cuda_host_device_bad_arg);
3907 if (Info->
isStr(
"begin"))
3908 Actions.CUDA().PushForceHostDevice();
3909 else if (!Actions.CUDA().PopForceHostDevice())
3911 diag::err_pragma_cannot_end_force_cuda_host_device);
3914 if (!Tok.
is(tok::eod))
3916 diag::warn_pragma_force_cuda_host_device_bad_arg);
3946void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
3948 Token &FirstToken) {
3952 PragmaAttributeInfo(AttributesForPragmaAttribute);
3955 if (Tok.
is(tok::identifier)) {
3957 if (!II->
isStr(
"push") && !II->
isStr(
"pop")) {
3958 Info->Namespace = II;
3961 if (!Tok.
is(tok::period)) {
3962 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_period)
3970 if (!Tok.
isOneOf(tok::identifier, tok::l_paren)) {
3972 diag::err_pragma_attribute_expected_push_pop_paren);
3977 if (Tok.
is(tok::l_paren)) {
3978 if (Info->Namespace) {
3980 diag::err_pragma_attribute_namespace_on_attribute);
3982 diag::note_pragma_attribute_namespace_on_attribute);
3985 Info->Action = PragmaAttributeInfo::Attribute;
3988 if (II->
isStr(
"push"))
3989 Info->Action = PragmaAttributeInfo::Push;
3991 Info->Action = PragmaAttributeInfo::Pop;
3993 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
4002 if ((Info->Action == PragmaAttributeInfo::Push && Tok.
isNot(tok::eod)) ||
4003 Info->Action == PragmaAttributeInfo::Attribute) {
4004 if (Tok.
isNot(tok::l_paren)) {
4013 while (Tok.
isNot(tok::eod)) {
4014 if (Tok.
is(tok::l_paren))
4016 else if (Tok.
is(tok::r_paren)) {
4018 if (OpenParens == 0)
4022 AttributeTokens.push_back(Tok);
4026 if (AttributeTokens.empty()) {
4027 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
4030 if (Tok.
isNot(tok::r_paren)) {
4042 AttributeTokens.push_back(EOFTok);
4044 markAsReinjectedForRelexing(AttributeTokens);
4049 if (Tok.
isNot(tok::eod))
4051 <<
"clang attribute";
4054 auto TokenArray = std::make_unique<Token[]>(1);
4055 TokenArray[0].startToken();
4056 TokenArray[0].setKind(tok::annot_pragma_attribute);
4057 TokenArray[0].setLocation(FirstToken.
getLocation());
4058 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
4059 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
4060 PP.EnterTokenStream(std::move(TokenArray), 1,
4065void PragmaMaxTokensHereHandler::HandlePragma(
Preprocessor &PP,
4069 if (Tok.
is(tok::eod)) {
4071 <<
"clang max_tokens_here" <<
true <<
"integer";
4077 if (Tok.
isNot(tok::numeric_constant) ||
4080 <<
"clang max_tokens_here";
4084 if (Tok.
isNot(tok::eod)) {
4086 <<
"clang max_tokens_here";
4091 PP.
Diag(
Loc, diag::warn_max_tokens)
4097void PragmaMaxTokensTotalHandler::HandlePragma(
Preprocessor &PP,
4101 if (Tok.
is(tok::eod)) {
4103 <<
"clang max_tokens_total" <<
true <<
"integer";
4109 if (Tok.
isNot(tok::numeric_constant) ||
4112 <<
"clang max_tokens_total";
4116 if (Tok.
isNot(tok::eod)) {
4118 <<
"clang max_tokens_total";
4129 Token &FirstToken) {
4134 if (!II || !II->
isStr(
"intrinsic")) {
4136 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'intrinsic'";
4142 if (!II || !(II->
isStr(
"vector") || II->
isStr(
"sifive_vector"))) {
4145 <<
"'vector' or 'sifive_vector'";
4150 if (Tok.
isNot(tok::eod)) {
4152 <<
"clang riscv intrinsic";
4156 if (II->
isStr(
"vector"))
4157 Actions.DeclareRISCVVBuiltins =
true;
4158 else if (II->
isStr(
"sifive_vector"))
4159 Actions.DeclareRISCVSiFiveVectorBuiltins =
true;
Defines the clang::ASTContext interface.
static void ParseAlignPragma(Preprocessor &PP, Token &FirstTok, bool IsOptions)
static void diagnoseUnknownAttributeSubjectSubRule(Parser &PRef, attr::SubjectMatchRule PrimaryRule, StringRef PrimaryRuleName, StringRef SubRuleName, SourceLocation SubRuleLoc)
static bool ParseLoopHintValue(Preprocessor &PP, Token &Tok, Token PragmaName, Token Option, bool ValueInParens, PragmaLoopHintInfo &Info)
Parses loop or unroll pragma hint value and fills in Info.
static void diagnoseExpectedAttributeSubjectSubRule(Parser &PRef, attr::SubjectMatchRule PrimaryRule, StringRef PrimaryRuleName, SourceLocation SubRuleLoc)
static bool isAbstractAttrMatcherRule(attr::SubjectMatchRule Rule)
static StringRef getIdentifier(const Token &Tok)
static std::string PragmaLoopHintString(Token PragmaName, Token Option)
Defines the clang::Preprocessor interface.
ArrayRef< SVal > ValueList
This file declares semantic analysis for CUDA constructs.
This file declares facilities that support code completion.
Kind getParsedKind() const
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
static CharSourceRange getCharRange(SourceRange R)
A little helper class used to produce diagnostics.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
void setSeverity(diag::kind Diag, diag::Severity Map, SourceLocation Loc)
This allows the client to specify that certain warnings are ignored.
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
EmptyPragmaHandler - A pragma handler which takes no action, which can be used to ignore particular p...
RAII object that enters a new expression evaluation context.
bool isTypeDependent() const
Determines whether the type of this expression depends on.
bool containsErrors() const
Whether this expression contains subexpressions which had errors, e.g.
ExprDependence getDependence() const
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
StringRef getName() const
Return the actual identifier string.
ComplexRangeKind
Controls the various implementations for complex multiplication and.
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
@ FEM_Extended
Use extended type for fp arithmetic.
@ FEM_Double
Use the type double for fp arithmetic.
@ FEM_Source
Use the declared type for fp arithmetic.
PragmaMSPointersToMembersKind
@ PPTMK_FullGeneralityMultipleInheritance
@ PPTMK_FullGeneralityVirtualInheritance
@ PPTMK_FullGeneralitySingleInheritance
@ FPE_Strict
Strictly preserve the floating-point exception semantics.
@ FPE_MayTrap
Transformations do not cause new exceptions but may hide some.
@ FPE_Ignore
Assume that floating-point exceptions are masked.
virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str)
Callback invoked when a #pragma comment directive is read.
virtual void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, SourceLocation StateLoc, unsigned State)
Called when an OpenCL extension is either disabled or enabled with a pragma.
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
Callback invoked when a #pragma detect_mismatch directive is read.
ParsedAttr - Represents a syntactic attribute.
ParsedAttributes - A collection of parsed attributes.
ParsedAttr * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, ParsedAttr::Form form, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
Parser - This implements a parser for the C family of languages.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
ExprResult ParseConstantExpression()
bool TryConsumeToken(tok::TokenKind Expected)
Scope * getCurScope() const
SourceLocation getEndOfPreviousToken()
const TargetInfo & getTargetInfo() const
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
const Token & getCurToken() const
const LangOptions & getLangOpts() const
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
ExprResult ParseStringLiteralExpression(bool AllowUserDefinedLiteral=false)
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
virtual void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, Token &FirstToken)=0
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
PPCallbacks * getPPCallbacks() const
void overrideMaxTokens(unsigned Value, SourceLocation Loc)
void Lex(Token &Result)
Lex the next token for this preprocessor.
bool LexOnOffSwitch(tok::OnOffSwitch &Result)
Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD.
bool isMacroDefined(StringRef Id)
unsigned getTokenCount() const
Get the number of tokens processed so far.
const TargetInfo & getTargetInfo() const
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Add the specified pragma handler to this preprocessor.
llvm::BumpPtrAllocator & getPreprocessorAllocator()
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 ...
SourceRange DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found.
const LangOptions & getLangOpts() const
DiagnosticsEngine & getDiagnostics() const
void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Remove the specific pragma handler from this preprocessor.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
bool LexStringLiteral(Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
Lex a string literal, which may be the concatenation of multiple string literals and may even come fr...
@ CompoundStmtScope
This is a compound statement scope.
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
@ DeclScope
This is a scope that can contain a declaration.
void CodeCompleteAttribute(AttributeCommonInfo::Syntax Syntax, AttributeCompletion Completion=AttributeCompletion::Attribute, const IdentifierInfo *Scope=nullptr)
Sema - This implements semantic analysis and AST building for C.
void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn)
#pragma optimize("[optimization-list]", on | off).
void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
void ActOnPragmaAttributePop(SourceLocation PragmaLoc, const IdentifierInfo *Namespace)
Called on well-formed '#pragma clang attribute pop'.
void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode)
Called to set constant rounding mode for floating point operations.
void ActOnPragmaMSSeg(SourceLocation PragmaLocation, PragmaMsStackAction Action, llvm::StringRef StackSlotLabel, StringLiteral *SegmentName, llvm::StringRef PragmaName)
Called on well formed #pragma bss_seg/data_seg/const_seg/code_seg.
void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, PragmaFloatControlKind Value)
ActOnPragmaFloatControl - Call on well-formed #pragma float_control.
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
void ActOnCapturedRegionError()
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
void ActOnPragmaMSAllocText(SourceLocation PragmaLocation, StringRef Section, const SmallVector< std::tuple< IdentifierInfo *, SourceLocation > > &Functions)
Called on well-formed #pragma alloc_text().
void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
void ActOnPragmaCXLimitedRange(SourceLocation Loc, LangOptions::ComplexRangeKind Range)
ActOnPragmaCXLimitedRange - Called on well formed #pragma STDC CX_LIMITED_RANGE.
void ActOnPragmaFPExceptions(SourceLocation Loc, LangOptions::FPExceptionModeKind)
Called on well formed '#pragma clang fp' that has option 'exceptions'.
void ActOnPragmaFPEvalMethod(SourceLocation Loc, LangOptions::FPEvalMethodKind Value)
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispMode Value)
Called on well formed #pragma vtordisp().
SemaCodeCompletion & CodeCompletion()
void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, CapturedRegionKind Kind, unsigned NumParams)
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc, bool AllowZero)
void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc)
ActOnPragmaWeakID - Called on well formed #pragma weak ident.
void ActOnPragmaMSFunction(SourceLocation Loc, const llvm::SmallVectorImpl< StringRef > &NoBuiltins)
Call on well formed #pragma function.
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
StmtResult ActOnCapturedRegionEnd(Stmt *S)
void ActOnPragmaFPValueChangingOption(SourceLocation Loc, PragmaFPKind Kind, bool IsEnabled)
Called on well formed #pragma clang fp reassociate or #pragma clang fp reciprocal.
void ActOnPragmaRedefineExtname(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaRedefineExtname - Called on well formed #pragma redefine_extname oldname newname.
ExprResult ActOnStringLiteral(ArrayRef< Token > StringToks, Scope *UDLScope=nullptr)
ActOnStringLiteral - The specified tokens were lexed as pasted string fragments (e....
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
OpenCLOptions & getOpenCLOptions()
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, PragmaMsStackAction Action, bool Value)
ActOnPragmaMSStrictGuardStackCheck - Called on well formed #pragma strict_gs_check.
ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope=nullptr)
void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
void ActOnPragmaWeakAlias(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II)
Called on #pragma clang __debug dump II.
void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled)
ActOnPragmaFenvAccess - Called on well formed #pragma STDC FENV_ACCESS.
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
StringLiteral - This represents a string literal expression, e.g.
unsigned getLength() const
StringRef getString() const
unsigned getCharByteWidth() const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
virtual bool hasStrictFP() const
Determine whether constrained floating point is supported on this target.
Token - This structure provides full information about a lexed token.
IdentifierInfo * getIdentifierInfo() const
void setLiteralData(const char *Ptr)
bool isAnyIdentifier() const
Return true if this is a raw identifier (when lexing in raw mode) or a non-keyword identifier (when l...
SourceLocation getEndLoc() const
void setAnnotationEndLoc(SourceLocation L)
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
void setLength(unsigned Len)
void setKind(tok::TokenKind K)
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 * getAnnotationValue() const
tok::TokenKind getKind() const
bool isRegularKeywordAttribute() const
Return true if the token is a keyword that is parsed in the same position as a standard attribute,...
void setLocation(SourceLocation L)
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool isNot(tok::TokenKind K) const
void setAnnotationValue(void *val)
void startToken()
Reset all flags to cleared.
Defines the clang::TargetInfo interface.
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
SubjectMatchRule
A list of all the recognized kinds of attributes.
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
@ Ignored
Do not present this diagnostic, ignore it.
@ FixIt
Parse and apply any fixits to the source.
bool Pop(InterpState &S, CodePtr OpPC)
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
MSVtorDispMode
In the Microsoft ABI, this controls the placement of virtual displacement members used to implement v...
const FunctionProtoType * T
@ None
The alignment was not explicit in code.
@ Parens
New-expression has a C++98 paren-delimited initializer.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
Loop optimization hint for loop and unroll pragmas.
IdentifierLoc * OptionLoc
IdentifierLoc * PragmaNameLoc
Describes how and where the pragma was introduced.
PragmaMsStackAction Action