27#include "llvm/ADT/ArrayRef.h"
28#include "llvm/ADT/StringSwitch.h"
37 Token &FirstToken)
override;
41 explicit PragmaGCCVisibilityHandler() :
PragmaHandler(
"visibility") {}
43 Token &FirstToken)
override;
49 Token &FirstToken)
override;
55 Token &FirstToken)
override;
59 explicit PragmaClangSectionHandler(
Sema &S)
62 Token &FirstToken)
override;
69 explicit PragmaMSStructHandler() :
PragmaHandler(
"ms_struct") {}
71 Token &FirstToken)
override;
77 Token &FirstToken)
override;
83 Token &FirstToken)
override;
87 explicit PragmaRedefineExtnameHandler() :
PragmaHandler(
"redefine_extname") {}
89 Token &FirstToken)
override;
93 PragmaOpenCLExtensionHandler() :
PragmaHandler(
"EXTENSION") {}
95 Token &FirstToken)
override;
102 Token &FirstToken)
override;
109 PragmaSTDC_FENV_ACCESSHandler() :
PragmaHandler(
"FENV_ACCESS") {}
112 Token &Tok)
override {
113 Token PragmaName = Tok;
125 Toks[0].startToken();
126 Toks[0].setKind(tok::annot_pragma_fenv_access);
129 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
131 PP.EnterTokenStream(Toks,
true,
137struct PragmaSTDC_CX_LIMITED_RANGEHandler :
public PragmaHandler {
138 PragmaSTDC_CX_LIMITED_RANGEHandler() :
PragmaHandler(
"CX_LIMITED_RANGE") {}
141 Token &Tok)
override {
149 Toks[0].startToken();
150 Toks[0].setKind(tok::annot_pragma_cx_limited_range);
153 Toks[0].setAnnotationValue(
154 reinterpret_cast<void *
>(
static_cast<uintptr_t>(OOS)));
155 PP.EnterTokenStream(Toks,
true,
162 PragmaSTDC_FENV_ROUNDHandler() :
PragmaHandler(
"FENV_ROUND") {}
165 Token &Tok)
override;
170 PragmaSTDC_UnknownHandler() =
default;
173 Token &UnknownTok)
override {
175 PP.
Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
182 Token &FirstToken)
override;
188template <diag::kind IgnoredDiag>
190 PragmaNoSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
192 Token &FirstToken)
override;
195struct PragmaNoOpenMPHandler
196 :
public PragmaNoSupportHandler<diag::warn_pragma_omp_ignored> {
197 PragmaNoOpenMPHandler() : PragmaNoSupportHandler(
"omp") {}
200struct PragmaNoOpenACCHandler
201 :
public PragmaNoSupportHandler<diag::warn_pragma_acc_ignored> {
202 PragmaNoOpenACCHandler() : PragmaNoSupportHandler(
"acc") {}
211 PragmaSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
213 Token &FirstToken)
override;
216struct PragmaOpenMPHandler
217 :
public PragmaSupportHandler<tok::annot_pragma_openmp,
218 tok::annot_pragma_openmp_end,
219 diag::err_omp_unexpected_directive> {
220 PragmaOpenMPHandler() : PragmaSupportHandler(
"omp") {}
223struct PragmaOpenACCHandler
224 :
public PragmaSupportHandler<tok::annot_pragma_openacc,
225 tok::annot_pragma_openacc_end,
226 diag::err_acc_unexpected_directive> {
227 PragmaOpenACCHandler() : PragmaSupportHandler(
"acc") {}
232 PragmaCommentHandler(
Sema &Actions)
235 Token &FirstToken)
override;
242 PragmaDetectMismatchHandler(
Sema &Actions)
245 Token &FirstToken)
override;
252 PragmaFloatControlHandler(
Sema &Actions)
255 Token &FirstToken)
override;
259 explicit PragmaMSPointersToMembers() :
PragmaHandler(
"pointers_to_members") {}
261 Token &FirstToken)
override;
267 Token &FirstToken)
override;
273 Token &FirstToken)
override;
278 PragmaOptimizeHandler(
Sema &S)
281 Token &FirstToken)
override;
290 Token &FirstToken)
override;
296 Token &FirstToken)
override;
306 Token &FirstToken)
override;
311 PragmaMSFenvAccessHandler() :
PragmaHandler(
"fenv_access") {}
313 Token &FirstToken)
override {
323 if (Tok.
isNot(tok::l_paren)) {
329 if (Tok.
isNot(tok::identifier)) {
335 if (II->
isStr(
"on")) {
338 }
else if (II->
isStr(
"off")) {
345 if (Tok.
isNot(tok::r_paren)) {
352 if (Tok.
isNot(tok::eod)) {
360 Toks[0].startToken();
361 Toks[0].setKind(tok::annot_pragma_fenv_access_ms);
364 Toks[0].setAnnotationValue(
365 reinterpret_cast<void*
>(
static_cast<uintptr_t>(OOS)));
366 PP.EnterTokenStream(Toks,
true,
371struct PragmaForceCUDAHostDeviceHandler :
public PragmaHandler {
372 PragmaForceCUDAHostDeviceHandler(
Sema &Actions)
373 :
PragmaHandler(
"force_cuda_host_device"), Actions(Actions) {}
375 Token &FirstToken)
override;
384 :
PragmaHandler(
"attribute"), AttributesForPragmaAttribute(AttrFactory) {}
386 Token &FirstToken)
override;
393 PragmaMaxTokensHereHandler() :
PragmaHandler(
"max_tokens_here") {}
395 Token &FirstToken)
override;
399 PragmaMaxTokensTotalHandler() :
PragmaHandler(
"max_tokens_total") {}
401 Token &FirstToken)
override;
405 PragmaRISCVHandler(
Sema &Actions)
408 Token &FirstToken)
override;
420void Parser::initializePragmaHandlers() {
421 AlignHandler = std::make_unique<PragmaAlignHandler>();
424 GCCVisibilityHandler = std::make_unique<PragmaGCCVisibilityHandler>();
427 OptionsHandler = std::make_unique<PragmaOptionsHandler>();
430 PackHandler = std::make_unique<PragmaPackHandler>();
433 MSStructHandler = std::make_unique<PragmaMSStructHandler>();
436 UnusedHandler = std::make_unique<PragmaUnusedHandler>();
439 WeakHandler = std::make_unique<PragmaWeakHandler>();
442 RedefineExtnameHandler = std::make_unique<PragmaRedefineExtnameHandler>();
445 FPContractHandler = std::make_unique<PragmaFPContractHandler>();
448 STDCFenvAccessHandler = std::make_unique<PragmaSTDC_FENV_ACCESSHandler>();
451 STDCFenvRoundHandler = std::make_unique<PragmaSTDC_FENV_ROUNDHandler>();
454 STDCCXLIMITHandler = std::make_unique<PragmaSTDC_CX_LIMITED_RANGEHandler>();
457 STDCUnknownHandler = std::make_unique<PragmaSTDC_UnknownHandler>();
460 PCSectionHandler = std::make_unique<PragmaClangSectionHandler>(Actions);
464 OpenCLExtensionHandler = std::make_unique<PragmaOpenCLExtensionHandler>();
470 OpenMPHandler = std::make_unique<PragmaOpenMPHandler>();
472 OpenMPHandler = std::make_unique<PragmaNoOpenMPHandler>();
476 OpenACCHandler = std::make_unique<PragmaOpenACCHandler>();
478 OpenACCHandler = std::make_unique<PragmaNoOpenACCHandler>();
483 MSCommentHandler = std::make_unique<PragmaCommentHandler>(Actions);
487 FloatControlHandler = std::make_unique<PragmaFloatControlHandler>(Actions);
490 MSDetectMismatchHandler =
491 std::make_unique<PragmaDetectMismatchHandler>(Actions);
493 MSPointersToMembers = std::make_unique<PragmaMSPointersToMembers>();
495 MSVtorDisp = std::make_unique<PragmaMSVtorDisp>();
497 MSInitSeg = std::make_unique<PragmaMSPragma>(
"init_seg");
499 MSDataSeg = std::make_unique<PragmaMSPragma>(
"data_seg");
501 MSBSSSeg = std::make_unique<PragmaMSPragma>(
"bss_seg");
503 MSConstSeg = std::make_unique<PragmaMSPragma>(
"const_seg");
505 MSCodeSeg = std::make_unique<PragmaMSPragma>(
"code_seg");
507 MSSection = std::make_unique<PragmaMSPragma>(
"section");
509 MSStrictGuardStackCheck =
510 std::make_unique<PragmaMSPragma>(
"strict_gs_check");
512 MSFunction = std::make_unique<PragmaMSPragma>(
"function");
514 MSAllocText = std::make_unique<PragmaMSPragma>(
"alloc_text");
516 MSOptimize = std::make_unique<PragmaMSPragma>(
"optimize");
518 MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
520 MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>();
522 MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
527 CUDAForceHostDeviceHandler =
528 std::make_unique<PragmaForceCUDAHostDeviceHandler>(Actions);
532 OptimizeHandler = std::make_unique<PragmaOptimizeHandler>(Actions);
535 LoopHintHandler = std::make_unique<PragmaLoopHintHandler>();
538 UnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"unroll");
542 NoUnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"nounroll");
546 UnrollAndJamHintHandler =
547 std::make_unique<PragmaUnrollHintHandler>(
"unroll_and_jam");
550 NoUnrollAndJamHintHandler =
551 std::make_unique<PragmaUnrollHintHandler>(
"nounroll_and_jam");
554 FPHandler = std::make_unique<PragmaFPHandler>();
557 AttributePragmaHandler =
558 std::make_unique<PragmaAttributeHandler>(AttrFactory);
561 MaxTokensHerePragmaHandler = std::make_unique<PragmaMaxTokensHereHandler>();
564 MaxTokensTotalPragmaHandler = std::make_unique<PragmaMaxTokensTotalHandler>();
568 RISCVPragmaHandler = std::make_unique<PragmaRISCVHandler>(Actions);
573void Parser::resetPragmaHandlers() {
576 AlignHandler.reset();
578 GCCVisibilityHandler.reset();
580 OptionsHandler.reset();
584 MSStructHandler.reset();
586 UnusedHandler.reset();
590 RedefineExtnameHandler.reset();
594 OpenCLExtensionHandler.reset();
598 OpenMPHandler.reset();
601 OpenACCHandler.reset();
606 MSCommentHandler.reset();
610 PCSectionHandler.reset();
613 FloatControlHandler.reset();
616 MSDetectMismatchHandler.reset();
618 MSPointersToMembers.reset();
634 MSStrictGuardStackCheck.reset();
640 MSRuntimeChecks.reset();
646 MSFenvAccess.reset();
651 CUDAForceHostDeviceHandler.reset();
655 FPContractHandler.reset();
658 STDCFenvAccessHandler.reset();
661 STDCFenvRoundHandler.reset();
664 STDCCXLIMITHandler.reset();
667 STDCUnknownHandler.reset();
670 OptimizeHandler.reset();
673 LoopHintHandler.reset();
677 UnrollHintHandler.reset();
681 NoUnrollHintHandler.reset();
684 UnrollAndJamHintHandler.reset();
687 NoUnrollAndJamHintHandler.reset();
693 AttributePragmaHandler.reset();
696 MaxTokensHerePragmaHandler.reset();
699 MaxTokensTotalPragmaHandler.reset();
703 RISCVPragmaHandler.reset();
712void Parser::HandlePragmaUnused() {
713 assert(Tok.
is(tok::annot_pragma_unused));
719void Parser::HandlePragmaVisibility() {
720 assert(Tok.
is(tok::annot_pragma_vis));
727void Parser::HandlePragmaPack() {
728 assert(Tok.
is(tok::annot_pragma_pack));
736 ConsumeAnnotationToken();
744 ConsumeAnnotationToken();
747void Parser::HandlePragmaMSStruct() {
748 assert(Tok.
is(tok::annot_pragma_msstruct));
752 ConsumeAnnotationToken();
755void Parser::HandlePragmaAlign() {
756 assert(Tok.
is(tok::annot_pragma_align));
763 ConsumeAnnotationToken();
766void Parser::HandlePragmaDump() {
767 assert(Tok.
is(tok::annot_pragma_dump));
768 ConsumeAnnotationToken();
769 if (Tok.
is(tok::eod)) {
770 PP.
Diag(Tok, diag::warn_pragma_debug_missing_argument) <<
"dump";
772 if (Tok.
isNot(tok::identifier)) {
773 PP.
Diag(Tok, diag::warn_pragma_debug_unexpected_argument);
775 ExpectAndConsume(tok::eod);
789 PP.
Diag(StartLoc, diag::warn_pragma_debug_dependent_argument)
797 ExpectAndConsume(tok::eod);
800void Parser::HandlePragmaWeak() {
801 assert(Tok.
is(tok::annot_pragma_weak));
808void Parser::HandlePragmaWeakAlias() {
809 assert(Tok.
is(tok::annot_pragma_weakalias));
818 WeakNameLoc, AliasNameLoc);
822void Parser::HandlePragmaRedefineExtname() {
823 assert(Tok.
is(tok::annot_pragma_redefine_extname));
832 RedefNameLoc, AliasNameLoc);
835void Parser::HandlePragmaFPContract() {
836 assert(Tok.
is(tok::annot_pragma_fp_contract));
863void Parser::HandlePragmaFloatControl() {
864 assert(Tok.
is(tok::annot_pragma_float_control));
879void Parser::HandlePragmaFEnvAccess() {
880 assert(Tok.
is(tok::annot_pragma_fenv_access) ||
881 Tok.
is(tok::annot_pragma_fenv_access_ms));
903void Parser::HandlePragmaFEnvRound() {
904 assert(Tok.
is(tok::annot_pragma_fenv_round));
905 auto RM =
static_cast<llvm::RoundingMode
>(
912void Parser::HandlePragmaCXLimitedRange() {
913 assert(Tok.
is(tok::annot_pragma_cx_limited_range));
939 assert(Tok.
is(tok::annot_pragma_captured));
940 ConsumeAnnotationToken();
942 if (Tok.
isNot(tok::l_brace)) {
943 PP.
Diag(Tok, diag::err_expected) << tok::l_brace;
955 CapturedRegionScope.Exit();
966 enum OpenCLExtState :
char {
967 Disable, Enable,
Begin, End
969 typedef std::pair<const IdentifierInfo *, OpenCLExtState> OpenCLExtData;
972void Parser::HandlePragmaOpenCLExtension() {
973 assert(Tok.
is(tok::annot_pragma_opencl_extension));
975 auto State =
Data->second;
976 auto Ident =
Data->first;
978 ConsumeAnnotationToken();
981 auto Name = Ident->getName();
986 if (State == Disable)
989 PP.
Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
990 }
else if (State ==
Begin) {
991 if (!Opt.isKnown(Name) || !Opt.isSupported(Name,
getLangOpts())) {
995 Opt.acceptsPragma(Name);
997 }
else if (State == End) {
1000 }
else if (!Opt.isKnown(Name) || !Opt.isWithPragma(Name))
1001 PP.
Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
1002 else if (Opt.isSupportedExtension(Name,
getLangOpts()))
1003 Opt.enable(Name, State == Enable);
1004 else if (Opt.isSupportedCoreOrOptionalCore(Name,
getLangOpts()))
1005 PP.
Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
1007 PP.
Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;
1010void Parser::HandlePragmaMSPointersToMembers() {
1011 assert(Tok.
is(tok::annot_pragma_ms_pointers_to_members));
1019void Parser::HandlePragmaMSVtorDisp() {
1020 assert(Tok.
is(tok::annot_pragma_ms_vtordisp));
1029void Parser::HandlePragmaMSPragma() {
1030 assert(Tok.
is(tok::annot_pragma_ms_pragma));
1034 PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second,
true,
1045 llvm::StringSwitch<PragmaHandler>(PragmaName)
1046 .Case(
"data_seg", &Parser::HandlePragmaMSSegment)
1047 .Case(
"bss_seg", &Parser::HandlePragmaMSSegment)
1048 .Case(
"const_seg", &Parser::HandlePragmaMSSegment)
1049 .Case(
"code_seg", &Parser::HandlePragmaMSSegment)
1050 .Case(
"section", &Parser::HandlePragmaMSSection)
1051 .Case(
"init_seg", &Parser::HandlePragmaMSInitSeg)
1052 .Case(
"strict_gs_check", &Parser::HandlePragmaMSStrictGuardStackCheck)
1053 .Case(
"function", &Parser::HandlePragmaMSFunction)
1054 .Case(
"alloc_text", &Parser::HandlePragmaMSAllocText)
1055 .Case(
"optimize", &Parser::HandlePragmaMSOptimize);
1057 if (!(this->*Handler)(PragmaName, PragmaLocation)) {
1060 while (Tok.
isNot(tok::eof))
1066bool Parser::HandlePragmaMSSection(StringRef PragmaName,
1068 if (Tok.
isNot(tok::l_paren)) {
1069 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1074 if (Tok.
isNot(tok::string_literal)) {
1075 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1084 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1089 bool SectionFlagsAreDefault =
true;
1090 while (Tok.
is(tok::comma)) {
1095 if (Tok.
is(tok::kw_long) || Tok.
is(tok::kw_short)) {
1101 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
1106 llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
1119 ? diag::warn_pragma_invalid_specific_action
1120 : diag::warn_pragma_unsupported_action)
1124 SectionFlags |= Flag;
1125 SectionFlagsAreDefault =
false;
1130 if (SectionFlagsAreDefault)
1132 if (Tok.
isNot(tok::r_paren)) {
1133 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1137 if (Tok.
isNot(tok::eof)) {
1138 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1147bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
1149 if (Tok.
isNot(tok::l_paren)) {
1150 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1155 StringRef SlotLabel;
1158 if (PushPop ==
"push")
1160 else if (PushPop ==
"pop")
1163 PP.
Diag(PragmaLocation,
1164 diag::warn_pragma_expected_section_push_pop_or_name)
1170 if (Tok.
is(tok::comma)) {
1176 if (Tok.
is(tok::comma))
1178 else if (Tok.
isNot(tok::r_paren)) {
1179 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc)
1184 }
else if (Tok.
isNot(tok::r_paren)) {
1185 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
1192 if (Tok.
isNot(tok::r_paren)) {
1193 if (Tok.
isNot(tok::string_literal)) {
1195 diag::warn_pragma_expected_section_name :
1196 diag::warn_pragma_expected_section_label_or_name :
1197 diag::warn_pragma_expected_section_push_pop_or_name;
1198 PP.
Diag(PragmaLocation, DiagID) << PragmaName;
1204 SegmentName = cast<StringLiteral>(StringResult.
get());
1206 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1214 if (Tok.
isNot(tok::r_paren)) {
1215 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1219 if (Tok.
isNot(tok::eof)) {
1220 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1226 SegmentName, PragmaName);
1231bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
1233 if (
getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
1234 PP.
Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
1238 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1246 StringRef Section = llvm::StringSwitch<StringRef>(II->
getName())
1247 .Case(
"compiler",
"\".CRT$XCC\"")
1248 .Case(
"lib",
"\".CRT$XCL\"")
1249 .Case(
"user",
"\".CRT$XCU\"")
1252 if (!Section.empty()) {
1256 Toks[0].
setKind(tok::string_literal);
1264 }
else if (Tok.
is(tok::string_literal)) {
1268 SegmentName = cast<StringLiteral>(StringResult.
get());
1270 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1278 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
1282 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1284 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1295bool Parser::HandlePragmaMSStrictGuardStackCheck(
1297 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1302 if (Tok.
is(tok::identifier)) {
1304 if (PushPop ==
"push") {
1307 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
1310 }
else if (PushPop ==
"pop") {
1319 if (II && II->
isStr(
"off")) {
1322 }
else if (II && II->
isStr(
"on")) {
1333 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1337 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1345bool Parser::HandlePragmaMSAllocText(StringRef PragmaName,
1347 Token FirstTok = Tok;
1348 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1353 if (Tok.
is(tok::string_literal)) {
1359 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1364 }
else if (Tok.
is(tok::identifier)) {
1368 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1373 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
1379 if (Tok.
isNot(tok::identifier)) {
1389 if (Tok.
isNot(tok::comma))
1394 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1396 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1406 std::string ClangLoopStr(
"clang loop ");
1409 return std::string(llvm::StringSwitch<StringRef>(Str)
1410 .Case(
"loop", ClangLoopStr)
1411 .Case(
"unroll_and_jam", Str)
1412 .Case(
"unroll", Str)
1416bool Parser::HandlePragmaLoopHint(
LoopHint &Hint) {
1417 assert(Tok.
is(tok::annot_pragma_loop_hint));
1437 auto IsLoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->
getName())
1438 .Cases(
"unroll",
"nounroll",
"unroll_and_jam",
1439 "nounroll_and_jam",
true)
1442 if (Toks.empty() && IsLoopHint) {
1443 ConsumeAnnotationToken();
1450 assert(!Toks.empty() &&
1451 "PragmaLoopHintInfo::Toks must contain at least one token.");
1454 bool OptionUnroll =
false;
1455 bool OptionUnrollAndJam =
false;
1456 bool OptionDistribute =
false;
1457 bool OptionPipelineDisabled =
false;
1458 bool StateOption =
false;
1460 OptionUnroll = OptionInfo->
isStr(
"unroll");
1461 OptionUnrollAndJam = OptionInfo->
isStr(
"unroll_and_jam");
1462 OptionDistribute = OptionInfo->
isStr(
"distribute");
1463 OptionPipelineDisabled = OptionInfo->
isStr(
"pipeline");
1464 StateOption = llvm::StringSwitch<bool>(OptionInfo->
getName())
1465 .Case(
"vectorize",
true)
1466 .Case(
"interleave",
true)
1467 .Case(
"vectorize_predicate",
true)
1469 OptionUnroll || OptionUnrollAndJam || OptionDistribute ||
1470 OptionPipelineDisabled;
1473 bool AssumeSafetyArg = !OptionUnroll && !OptionUnrollAndJam &&
1474 !OptionDistribute && !OptionPipelineDisabled;
1476 if (Toks[0].is(tok::eof)) {
1477 ConsumeAnnotationToken();
1478 Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
1480 << (OptionUnroll || OptionUnrollAndJam)
1487 ConsumeAnnotationToken();
1491 bool Valid = StateInfo &&
1492 llvm::StringSwitch<bool>(StateInfo->
getName())
1493 .Case(
"disable",
true)
1494 .Case(
"enable", !OptionPipelineDisabled)
1495 .Case(
"full", OptionUnroll || OptionUnrollAndJam)
1496 .Case(
"assume_safety", AssumeSafetyArg)
1499 if (OptionPipelineDisabled) {
1500 Diag(Toks[0].getLocation(), diag::err_pragma_pipeline_invalid_keyword);
1502 Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
1503 << (OptionUnroll || OptionUnrollAndJam)
1508 if (Toks.size() > 2)
1512 }
else if (OptionInfo && OptionInfo->
getName() ==
"vectorize_width") {
1513 PP.EnterTokenStream(Toks,
false,
1515 ConsumeAnnotationToken();
1519 StringRef IsScalableStr = StateInfo ? StateInfo->
getName() :
"";
1522 if (IsScalableStr ==
"scalable" || IsScalableStr ==
"fixed") {
1525 if (Toks.size() > 2) {
1528 while (Tok.
isNot(tok::eof))
1541 Diag(Toks[0].getLocation(),
1542 diag::note_pragma_loop_invalid_vectorize_option);
1544 bool Arg2Error =
false;
1545 if (Tok.
is(tok::comma)) {
1549 IsScalableStr = StateInfo->
getName();
1551 if (IsScalableStr !=
"scalable" && IsScalableStr !=
"fixed") {
1553 diag::err_pragma_loop_invalid_vectorize_option);
1564 if (Tok.
isNot(tok::eof)) {
1567 while (Tok.
isNot(tok::eof))
1583 PP.EnterTokenStream(Toks,
false,
1585 ConsumeAnnotationToken();
1590 if (Tok.
isNot(tok::eof)) {
1593 while (Tok.
isNot(tok::eof))
1609 Info->
Toks.back().getLocation());
1614struct PragmaAttributeInfo {
1615 enum ActionType { Push,
Pop, Attribute };
1621 PragmaAttributeInfo(
ParsedAttributes &Attributes) : Attributes(Attributes) {}
1624#include "clang/Parse/AttrSubMatchRulesParserStringSwitches.inc"
1629 if (Tok.
is(tok::identifier))
1638 using namespace attr;
1640#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) \
1643#include "clang/Basic/AttrSubMatchRulesList.inc"
1645 llvm_unreachable(
"Invalid attribute subject match rule");
1653 PRef.
Diag(SubRuleLoc,
1654 diag::err_pragma_attribute_expected_subject_sub_identifier)
1656 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1667 PRef.
Diag(SubRuleLoc, diag::err_pragma_attribute_unknown_subject_sub_rule)
1668 << SubRuleName << PrimaryRuleName;
1669 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1675bool Parser::ParsePragmaAttributeSubjectMatchRuleSet(
1683 if (AnyParens.expectAndConsume())
1691 Diag(Tok, diag::err_pragma_attribute_expected_subject_identifier);
1694 std::pair<std::optional<attr::SubjectMatchRule>,
1695 std::optional<attr::SubjectMatchRule> (*)(StringRef,
bool)>
1696 Rule = isAttributeSubjectMatchRule(Name);
1698 Diag(Tok, diag::err_pragma_attribute_unknown_subject_rule) << Name;
1706 if (
Parens.expectAndConsume())
1708 }
else if (
Parens.consumeOpen()) {
1709 if (!SubjectMatchRules
1711 std::make_pair(PrimaryRule,
SourceRange(RuleLoc, RuleLoc)))
1713 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1716 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleLoc));
1717 LastMatchRuleEndLoc = RuleLoc;
1723 if (SubRuleName.empty()) {
1729 if (SubRuleName ==
"unless") {
1732 if (
Parens.expectAndConsume())
1735 if (SubRuleName.empty()) {
1740 auto SubRuleOrNone =
Rule.second(SubRuleName,
true);
1741 if (!SubRuleOrNone) {
1742 std::string SubRuleUnlessName =
"unless(" + SubRuleName.str() +
")";
1744 SubRuleUnlessName, SubRuleLoc);
1747 SubRule = *SubRuleOrNone;
1749 if (
Parens.consumeClose())
1752 auto SubRuleOrNone =
Rule.second(SubRuleName,
false);
1753 if (!SubRuleOrNone) {
1758 SubRule = *SubRuleOrNone;
1762 LastMatchRuleEndLoc = RuleEndLoc;
1763 if (
Parens.consumeClose())
1765 if (!SubjectMatchRules
1766 .insert(std::make_pair(SubRule,
SourceRange(RuleLoc, RuleEndLoc)))
1768 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1771 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleEndLoc));
1777 if (AnyParens.consumeClose())
1786enum class MissingAttributeSubjectRulesRecoveryPoint {
1794MissingAttributeSubjectRulesRecoveryPoint
1795getAttributeSubjectRulesRecoveryPointForToken(
const Token &Tok) {
1797 if (II->
isStr(
"apply_to"))
1798 return MissingAttributeSubjectRulesRecoveryPoint::ApplyTo;
1799 if (II->
isStr(
"any"))
1800 return MissingAttributeSubjectRulesRecoveryPoint::Any;
1802 if (Tok.
is(tok::equal))
1803 return MissingAttributeSubjectRulesRecoveryPoint::Equals;
1804 return MissingAttributeSubjectRulesRecoveryPoint::None;
1812 MissingAttributeSubjectRulesRecoveryPoint Point,
Parser &PRef) {
1818 MissingAttributeSubjectRulesRecoveryPoint EndPoint =
1819 getAttributeSubjectRulesRecoveryPointForToken(PRef.
getCurToken());
1820 if (Point == MissingAttributeSubjectRulesRecoveryPoint::Comma)
1822 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::ApplyTo &&
1823 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::ApplyTo)
1824 FixIt +=
"apply_to";
1825 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::Equals &&
1826 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::Equals)
1829 if (EndPoint == MissingAttributeSubjectRulesRecoveryPoint::None) {
1836 Attribute.getMatchRules(PRef.
getLangOpts(), MatchRules);
1838 for (
const auto &Rule : MatchRules) {
1843 IsSupported[
Rule.first] =
true;
1845 IsMatchRuleAvailable &= IsSupported;
1847 if (IsMatchRuleAvailable.count() == 0) {
1853 bool NeedsComma =
false;
1855 if (!IsMatchRuleAvailable[I])
1869 if (FixItRange.getBegin() == FixItRange.getEnd())
1879void Parser::HandlePragmaAttribute() {
1880 assert(Tok.
is(tok::annot_pragma_attribute) &&
1881 "Expected #pragma attribute annotation token");
1884 if (Info->Action == PragmaAttributeInfo::Pop) {
1885 ConsumeAnnotationToken();
1890 assert((Info->Action == PragmaAttributeInfo::Push ||
1891 Info->Action == PragmaAttributeInfo::Attribute) &&
1892 "Unexpected #pragma attribute command");
1894 if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) {
1895 ConsumeAnnotationToken();
1900 PP.EnterTokenStream(Info->Tokens,
false,
1902 ConsumeAnnotationToken();
1907 auto SkipToEnd = [
this]() {
1912 if ((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1915 ParseCXX11AttributeSpecifier(Attrs);
1916 }
else if (Tok.
is(tok::kw___attribute)) {
1918 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
1921 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"("))
1926 if (Tok.
is(tok::code_completion)) {
1936 if (Tok.
isNot(tok::identifier)) {
1937 Diag(Tok, diag::err_pragma_attribute_expected_attribute_name);
1944 if (Tok.
isNot(tok::l_paren))
1945 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1946 ParsedAttr::Form::GNU());
1948 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs,
nullptr,
1951 ParsedAttr::Form::GNU(),
1955 if (ExpectAndConsume(tok::r_paren))
1957 if (ExpectAndConsume(tok::r_paren))
1959 }
else if (Tok.
is(tok::kw___declspec)) {
1960 ParseMicrosoftDeclSpecs(Attrs);
1962 Diag(Tok, diag::err_pragma_attribute_expected_attribute_syntax);
1971 if (Tok.
is(tok::l_paren)) {
1974 if (Tok.
isNot(tok::r_paren))
1977 Diag(Tok, diag::note_pragma_attribute_use_attribute_kw)
1986 if (Attrs.
empty() || Attrs.
begin()->isInvalid()) {
1992 if (!Attribute.isSupportedByPragmaAttribute()) {
1993 Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute)
2002 createExpectedAttributeSubjectRulesTokenDiagnostic(
2003 diag::err_expected, Attrs,
2004 MissingAttributeSubjectRulesRecoveryPoint::Comma, *
this)
2010 if (Tok.
isNot(tok::identifier)) {
2011 createExpectedAttributeSubjectRulesTokenDiagnostic(
2012 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2013 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2018 if (!II->
isStr(
"apply_to")) {
2019 createExpectedAttributeSubjectRulesTokenDiagnostic(
2020 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2021 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2028 createExpectedAttributeSubjectRulesTokenDiagnostic(
2029 diag::err_expected, Attrs,
2030 MissingAttributeSubjectRulesRecoveryPoint::Equals, *
this)
2038 if (ParsePragmaAttributeSubjectMatchRuleSet(SubjectMatchRules, AnyLoc,
2039 LastMatchRuleEndLoc)) {
2046 if (Tok.
isNot(tok::eof)) {
2047 Diag(Tok, diag::err_pragma_attribute_extra_tokens_after_attribute);
2056 if (Info->Action == PragmaAttributeInfo::Push)
2068void PragmaGCCVisibilityHandler::HandlePragma(
Preprocessor &PP,
2079 if (PushPop && PushPop->
isStr(
"pop")) {
2081 }
else if (PushPop && PushPop->
isStr(
"push")) {
2083 if (Tok.
isNot(tok::l_paren)) {
2096 if (Tok.
isNot(tok::r_paren)) {
2108 if (Tok.
isNot(tok::eod)) {
2114 auto Toks = std::make_unique<Token[]>(1);
2115 Toks[0].startToken();
2116 Toks[0].setKind(tok::annot_pragma_vis);
2117 Toks[0].setLocation(VisLoc);
2118 Toks[0].setAnnotationEndLoc(EndLoc);
2119 Toks[0].setAnnotationValue(
2120 const_cast<void *
>(
static_cast<const void *
>(VisType)));
2121 PP.EnterTokenStream(std::move(Toks), 1,
true,
2137 if (Tok.
isNot(tok::l_paren)) {
2138 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
2143 StringRef SlotLabel;
2147 if (Tok.
is(tok::numeric_constant)) {
2158 }
else if (Tok.
is(tok::identifier)) {
2160 auto MapPack = [&](
const char *
Literal) {
2163 Alignment.
setKind(tok::numeric_constant);
2169 if (II->
isStr(
"show")) {
2189 if (II->
isStr(
"push")) {
2191 }
else if (II->
isStr(
"pop")) {
2194 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
2199 if (Tok.
is(tok::comma)) {
2202 if (Tok.
is(tok::numeric_constant)) {
2207 }
else if (Tok.
is(tok::identifier)) {
2211 if (Tok.
is(tok::comma)) {
2214 if (Tok.
isNot(tok::numeric_constant)) {
2239 if (Tok.
isNot(tok::r_paren)) {
2240 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
2246 if (Tok.
isNot(tok::eod)) {
2247 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
2259 Toks[0].startToken();
2260 Toks[0].setKind(tok::annot_pragma_pack);
2261 Toks[0].setLocation(PackLoc);
2262 Toks[0].setAnnotationEndLoc(RParenLoc);
2263 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2264 PP.EnterTokenStream(Toks,
true,
2270void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
2272 Token &MSStructTok) {
2277 if (Tok.
isNot(tok::identifier)) {
2283 if (II->
isStr(
"on")) {
2287 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
2294 if (Tok.
isNot(tok::eod)) {
2302 Toks[0].startToken();
2303 Toks[0].setKind(tok::annot_pragma_msstruct);
2305 Toks[0].setAnnotationEndLoc(EndLoc);
2306 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2308 PP.EnterTokenStream(Toks,
true,
2313void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
2315 Token &FirstToken) {
2321 while (Tok.
isNot(tok::eod)) {
2322 if (Tok.
isNot(tok::identifier)) {
2323 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2328 if (SecType->
isStr(
"bss"))
2330 else if (SecType->
isStr(
"data"))
2332 else if (SecType->
isStr(
"rodata"))
2334 else if (SecType->
isStr(
"relro"))
2336 else if (SecType->
isStr(
"text"))
2339 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2345 if (Tok.
isNot(tok::equal)) {
2346 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal) << SecKind;
2350 std::string SecName;
2354 Actions.ActOnPragmaClangSection(
2371 if (Tok.
isNot(tok::identifier) ||
2380 if (Tok.
isNot(tok::l_paren)) {
2381 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"align";
2384 }
else if (Tok.
isNot(tok::equal)) {
2391 if (Tok.
isNot(tok::identifier)) {
2393 << (IsOptions ?
"options" :
"align");
2399 if (II->
isStr(
"native"))
2401 else if (II->
isStr(
"natural"))
2403 else if (II->
isStr(
"packed"))
2405 else if (II->
isStr(
"power"))
2407 else if (II->
isStr(
"mac68k"))
2409 else if (II->
isStr(
"reset"))
2419 if (Tok.
isNot(tok::r_paren)) {
2420 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"align";
2427 if (Tok.
isNot(tok::eod)) {
2429 << (IsOptions ?
"options" :
"align");
2435 Toks[0].startToken();
2436 Toks[0].setKind(tok::annot_pragma_align);
2438 Toks[0].setAnnotationEndLoc(EndLoc);
2439 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2441 PP.EnterTokenStream(Toks,
true,
2451void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
2453 Token &OptionsTok) {
2458void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
2467 if (Tok.
isNot(tok::l_paren)) {
2468 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
2481 if (Tok.
is(tok::identifier)) {
2482 Identifiers.push_back(Tok);
2493 if (Tok.
is(tok::comma)) {
2498 if (Tok.
is(tok::r_paren)) {
2504 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
2509 if (Tok.
isNot(tok::eod)) {
2516 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
2517 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
2526 2 * Identifiers.size());
2527 for (
unsigned i=0; i != Identifiers.size(); i++) {
2528 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
2530 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
2532 idTok = Identifiers[i];
2534 PP.EnterTokenStream(Toks,
true,
2547 if (Tok.
isNot(tok::identifier)) {
2548 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
2552 Token WeakName = Tok;
2553 bool HasAlias =
false;
2557 if (Tok.
is(tok::equal)) {
2560 if (Tok.
isNot(tok::identifier)) {
2569 if (Tok.
isNot(tok::eod)) {
2570 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
2577 Token &pragmaUnusedTok = Toks[0];
2579 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
2583 Toks[2] = AliasName;
2584 PP.EnterTokenStream(Toks,
true,
2589 Token &pragmaUnusedTok = Toks[0];
2591 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
2595 PP.EnterTokenStream(Toks,
true,
2601void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
2603 Token &RedefToken) {
2608 if (Tok.
isNot(tok::identifier)) {
2614 Token RedefName = Tok;
2617 if (Tok.
isNot(tok::identifier)) {
2619 <<
"redefine_extname";
2623 Token AliasName = Tok;
2626 if (Tok.
isNot(tok::eod)) {
2634 Token &pragmaRedefTok = Toks[0];
2636 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
2639 Toks[1] = RedefName;
2640 Toks[2] = AliasName;
2641 PP.EnterTokenStream(Toks,
true,
2645void PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
2654 Toks[0].startToken();
2655 Toks[0].setKind(tok::annot_pragma_fp_contract);
2658 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2660 PP.EnterTokenStream(Toks,
true,
2664void PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
2668 if (Tok.
isNot(tok::identifier)) {
2677 if (Tok.
isNot(tok::colon)) {
2683 if (Tok.
isNot(tok::identifier)) {
2684 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
2689 OpenCLExtState State;
2690 if (Pred->
isStr(
"enable")) {
2692 }
else if (Pred->
isStr(
"disable")) {
2694 }
else if (Pred->
isStr(
"begin"))
2696 else if (Pred->
isStr(
"end"))
2700 << Ext->
isStr(
"all");
2706 if (Tok.
isNot(tok::eod)) {
2714 Info->second = State;
2717 Toks[0].startToken();
2718 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2719 Toks[0].setLocation(NameLoc);
2720 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2721 Toks[0].setAnnotationEndLoc(StateLoc);
2722 PP.EnterTokenStream(Toks,
true,
2732template <diag::kind IgnoredDiag>
2733void PragmaNoSupportHandler<IgnoredDiag>::HandlePragma(
2736 PP.
Diag(FirstTok, IgnoredDiag);
2747void PragmaSupportHandler<StartTok, EndTok, UnexpectedDiag>::HandlePragma(
2755 while (Tok.
isNot(tok::eod) && Tok.
isNot(tok::eof)) {
2756 Pragma.push_back(Tok);
2758 if (Tok.
is(StartTok)) {
2759 PP.
Diag(Tok, UnexpectedDiag) << 0;
2760 unsigned InnerPragmaCnt = 1;
2761 while (InnerPragmaCnt != 0) {
2763 if (Tok.
is(StartTok))
2765 else if (Tok.
is(EndTok))
2775 Pragma.push_back(Tok);
2777 auto Toks = std::make_unique<Token[]>(Pragma.size());
2778 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2779 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2791void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2796 if (Tok.
isNot(tok::l_paren)) {
2797 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2798 <<
"pointers_to_members";
2805 <<
"pointers_to_members";
2811 if (Arg->
isStr(
"best_case")) {
2814 if (Arg->
isStr(
"full_generality")) {
2815 if (Tok.
is(tok::comma)) {
2821 diag::err_pragma_pointers_to_members_unknown_kind)
2826 }
else if (Tok.
is(tok::r_paren)) {
2833 <<
"full_generality";
2839 if (Arg->
isStr(
"single_inheritance")) {
2840 RepresentationMethod =
2842 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2843 RepresentationMethod =
2845 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2846 RepresentationMethod =
2850 diag::err_pragma_pointers_to_members_unknown_kind)
2857 if (Tok.
isNot(tok::r_paren)) {
2859 << (Arg ? Arg->
getName() :
"full_generality");
2865 if (Tok.
isNot(tok::eod)) {
2867 <<
"pointers_to_members";
2873 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2877 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RepresentationMethod)));
2893 if (Tok.
isNot(tok::l_paren)) {
2894 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2902 if (II->
isStr(
"push")) {
2905 if (Tok.
isNot(tok::comma)) {
2906 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2912 }
else if (II->
isStr(
"pop")) {
2919 if (Tok.
is(tok::r_paren)) {
2929 if (II && II->
isStr(
"off")) {
2932 }
else if (II && II->
isStr(
"on")) {
2935 }
else if (Tok.
is(tok::numeric_constant) &&
2939 << 0 << 2 <<
"vtordisp";
2950 if (Tok.
isNot(tok::r_paren)) {
2951 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2956 if (Tok.
isNot(tok::eod)) {
2965 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2977 Token EoF, AnnotTok;
2981 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2986 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2987 TokenVector.push_back(Tok);
2991 TokenVector.push_back(EoF);
2994 markAsReinjectedForRelexing(TokenVector);
2995 auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
2996 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2998 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2999 TokenVector.size());
3015void PragmaFloatControlHandler::HandlePragma(
Preprocessor &PP,
3020 Token PragmaName = Tok;
3027 if (Tok.
isNot(tok::l_paren)) {
3028 PP.
Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
3034 if (Tok.
isNot(tok::identifier)) {
3042 llvm::StringSwitch<PragmaFloatControlKind>(II->
getName())
3053 if (Tok.
isNot(tok::r_paren)) {
3060 if (Tok.
is(tok::r_paren))
3063 else if (Tok.
isNot(tok::comma)) {
3073 if (PushOnOff ==
"on")
3076 else if (PushOnOff ==
"off") {
3081 }
else if (PushOnOff ==
"push") {
3088 if (Tok.
is(tok::comma)) {
3095 if (ExpectedPush ==
"push") {
3103 if (Tok.
isNot(tok::r_paren)) {
3111 if (Tok.
isNot(tok::eod)) {
3120 auto TokenArray = std::make_unique<Token[]>(1);
3121 TokenArray[0].startToken();
3122 TokenArray[0].setKind(tok::annot_pragma_float_control);
3123 TokenArray[0].setLocation(FloatControlLoc);
3124 TokenArray[0].setAnnotationEndLoc(EndLoc);
3127 TokenArray[0].setAnnotationValue(
reinterpret_cast<void *
>(
3128 static_cast<uintptr_t>((Action << 16) | (Kind & 0xFFFF))));
3129 PP.EnterTokenStream(std::move(TokenArray), 1,
3143void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
3148 if (Tok.
isNot(tok::l_paren)) {
3149 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
3154 std::string NameString;
3156 "pragma detect_mismatch",
3161 std::string ValueString;
3162 if (Tok.
isNot(tok::comma)) {
3163 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3171 if (Tok.
isNot(tok::r_paren)) {
3177 if (Tok.
isNot(tok::eod)) {
3178 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3187 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
3199void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
3204 if (Tok.
isNot(tok::l_paren)) {
3205 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3211 if (Tok.
isNot(tok::identifier)) {
3212 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3219 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
3239 std::string ArgumentString;
3252 if (Tok.
isNot(tok::r_paren)) {
3258 if (Tok.
isNot(tok::eod)) {
3267 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
3272void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
3274 Token &FirstToken) {
3277 if (Tok.
is(tok::eod)) {
3279 <<
"clang optimize" <<
true <<
"'on' or 'off'";
3282 if (Tok.
isNot(tok::identifier)) {
3283 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3290 if (II->
isStr(
"on")) {
3292 }
else if (!II->
isStr(
"off")) {
3293 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3299 if (Tok.
isNot(tok::eod)) {
3305 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
3310struct TokFPAnnotValue {
3311 enum FlagValues { On, Off, Fast };
3313 std::optional<LangOptions::FPModeKind> ContractValue;
3314 std::optional<LangOptions::FPModeKind> ReassociateValue;
3315 std::optional<LangOptions::FPModeKind> ReciprocalValue;
3316 std::optional<LangOptions::FPExceptionModeKind> ExceptionsValue;
3317 std::optional<LangOptions::FPEvalMethodKind> EvalMethodValue;
3324 Token PragmaName = Tok;
3328 if (Tok.
isNot(tok::identifier)) {
3335 while (Tok.
is(tok::identifier)) {
3339 llvm::StringSwitch<std::optional<PragmaFPKind>>(OptionInfo->
getName())
3345 .Default(std::nullopt);
3348 <<
false << OptionInfo;
3354 if (Tok.
isNot(tok::l_paren)) {
3359 bool isEvalMethodDouble =
3363 if (Tok.
isNot(tok::identifier) && !isEvalMethodDouble) {
3366 <<
static_cast<int>(*FlagKind);
3372 AnnotValue->ContractValue =
3373 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3378 .Default(std::nullopt);
3379 if (!AnnotValue->ContractValue) {
3386 : AnnotValue->ReciprocalValue;
3387 Value = llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3391 .Default(std::nullopt);
3398 AnnotValue->ExceptionsValue =
3399 llvm::StringSwitch<std::optional<LangOptions::FPExceptionModeKind>>(
3404 .Default(std::nullopt);
3405 if (!AnnotValue->ExceptionsValue) {
3411 AnnotValue->EvalMethodValue =
3412 llvm::StringSwitch<std::optional<LangOptions::FPEvalMethodKind>>(
3417 .Default(std::nullopt);
3418 if (!AnnotValue->EvalMethodValue) {
3427 if (Tok.
isNot(tok::r_paren)) {
3434 if (Tok.
isNot(tok::eod)) {
3442 FPTok.
setKind(tok::annot_pragma_fp);
3446 TokenList.push_back(FPTok);
3448 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3449 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3451 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3455void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(
Preprocessor &PP,
3458 Token PragmaName = Tok;
3467 if (Tok.
isNot(tok::identifier)) {
3475 llvm::StringSwitch<llvm::RoundingMode>(II->
getName())
3476 .Case(
"FE_TOWARDZERO", llvm::RoundingMode::TowardZero)
3477 .Case(
"FE_TONEAREST", llvm::RoundingMode::NearestTiesToEven)
3478 .Case(
"FE_UPWARD", llvm::RoundingMode::TowardPositive)
3479 .Case(
"FE_DOWNWARD", llvm::RoundingMode::TowardNegative)
3480 .Case(
"FE_TONEARESTFROMZERO", llvm::RoundingMode::NearestTiesToAway)
3481 .Case(
"FE_DYNAMIC", llvm::RoundingMode::Dynamic)
3482 .Default(llvm::RoundingMode::Invalid);
3483 if (RM == llvm::RoundingMode::Invalid) {
3489 if (Tok.
isNot(tok::eod)) {
3491 <<
"STDC FENV_ROUND";
3500 Toks[0].startToken();
3501 Toks[0].setKind(tok::annot_pragma_fenv_round);
3504 Toks[0].setAnnotationValue(
3505 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RM)));
3506 PP.EnterTokenStream(Toks,
true,
3510void Parser::HandlePragmaFP() {
3511 assert(Tok.
is(tok::annot_pragma_fp));
3515 if (AnnotValue->ReassociateValue)
3520 if (AnnotValue->ReciprocalValue)
3525 if (AnnotValue->ContractValue)
3527 *AnnotValue->ContractValue);
3528 if (AnnotValue->ExceptionsValue)
3530 *AnnotValue->ExceptionsValue);
3531 if (AnnotValue->EvalMethodValue)
3533 *AnnotValue->EvalMethodValue);
3534 ConsumeAnnotationToken();
3539 Token Option,
bool ValueInParens,
3542 int OpenParens = ValueInParens ? 1 : 0;
3544 while (Tok.
isNot(tok::eod)) {
3545 if (Tok.
is(tok::l_paren))
3547 else if (Tok.
is(tok::r_paren)) {
3549 if (OpenParens == 0 && ValueInParens)
3557 if (ValueInParens) {
3559 if (Tok.
isNot(tok::r_paren)) {
3628void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
3632 Token PragmaName = Tok;
3637 if (Tok.
isNot(tok::identifier)) {
3643 while (Tok.
is(tok::identifier)) {
3647 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
3648 .Case(
"vectorize",
true)
3649 .Case(
"interleave",
true)
3650 .Case(
"unroll",
true)
3651 .Case(
"distribute",
true)
3652 .Case(
"vectorize_predicate",
true)
3653 .Case(
"vectorize_width",
true)
3654 .Case(
"interleave_count",
true)
3655 .Case(
"unroll_count",
true)
3656 .Case(
"pipeline",
true)
3657 .Case(
"pipeline_initiation_interval",
true)
3661 <<
false << OptionInfo;
3667 if (Tok.
isNot(tok::l_paren)) {
3681 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
3685 TokenList.push_back(LoopHintTok);
3688 if (Tok.
isNot(tok::eod)) {
3694 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3695 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3697 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3722void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
3727 Token PragmaName = Tok;
3730 if (Tok.
is(tok::eod)) {
3732 Info->PragmaName = PragmaName;
3733 Info->Option.startToken();
3743 bool ValueInParens = Tok.
is(tok::l_paren);
3755 PP.
Diag(Info->Toks[0].getLocation(),
3756 diag::warn_pragma_unroll_cuda_value_in_parens);
3758 if (Tok.
isNot(tok::eod)) {
3766 auto TokenArray = std::make_unique<Token[]>(1);
3767 TokenArray[0].startToken();
3768 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
3769 TokenArray[0].setLocation(Introducer.
Loc);
3770 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
3771 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3772 PP.EnterTokenStream(std::move(TokenArray), 1,
3788void PragmaMSIntrinsicHandler::HandlePragma(
Preprocessor &PP,
3793 if (Tok.
isNot(tok::l_paren)) {
3802 while (Tok.
is(tok::identifier)) {
3806 << II << SuggestIntrinH;
3809 if (Tok.
isNot(tok::comma))
3814 if (Tok.
isNot(tok::r_paren)) {
3821 if (Tok.
isNot(tok::eod))
3826bool Parser::HandlePragmaMSFunction(StringRef PragmaName,
3828 Token FirstTok = Tok;
3830 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3837 while (Tok.
is(tok::identifier)) {
3841 << II << SuggestIntrinH;
3843 NoBuiltins.emplace_back(II->
getName());
3846 if (Tok.
isNot(tok::comma))
3851 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3853 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3862bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3864 Token FirstTok = Tok;
3865 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3869 if (Tok.
isNot(tok::string_literal)) {
3870 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_string) << PragmaName;
3878 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
3883 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
3887 if (Tok.
is(tok::eof) || Tok.
is(tok::r_paren)) {
3888 PP.
Diag(PragmaLocation, diag::warn_pragma_missing_argument)
3889 << PragmaName <<
true <<
"'on' or 'off'";
3893 if (!II || (!II->
isStr(
"on") && !II->
isStr(
"off"))) {
3894 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3899 bool IsOn = II->
isStr(
"on");
3902 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3907 if (!OptimizationList->
getString().empty()) {
3908 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3909 << OptimizationList->
getString() << PragmaName <<
true
3914 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3922void PragmaForceCUDAHostDeviceHandler::HandlePragma(
3924 Token FirstTok = Tok;
3928 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
3930 diag::warn_pragma_force_cuda_host_device_bad_arg);
3934 if (Info->
isStr(
"begin"))
3935 Actions.CUDA().PushForceHostDevice();
3936 else if (!Actions.CUDA().PopForceHostDevice())
3938 diag::err_pragma_cannot_end_force_cuda_host_device);
3941 if (!Tok.
is(tok::eod))
3943 diag::warn_pragma_force_cuda_host_device_bad_arg);
3973void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
3975 Token &FirstToken) {
3979 PragmaAttributeInfo(AttributesForPragmaAttribute);
3982 if (Tok.
is(tok::identifier)) {
3984 if (!II->
isStr(
"push") && !II->
isStr(
"pop")) {
3985 Info->Namespace = II;
3988 if (!Tok.
is(tok::period)) {
3989 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_period)
3997 if (!Tok.
isOneOf(tok::identifier, tok::l_paren)) {
3999 diag::err_pragma_attribute_expected_push_pop_paren);
4004 if (Tok.
is(tok::l_paren)) {
4005 if (Info->Namespace) {
4007 diag::err_pragma_attribute_namespace_on_attribute);
4009 diag::note_pragma_attribute_namespace_on_attribute);
4012 Info->Action = PragmaAttributeInfo::Attribute;
4015 if (II->
isStr(
"push"))
4016 Info->Action = PragmaAttributeInfo::Push;
4018 Info->Action = PragmaAttributeInfo::Pop;
4020 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
4029 if ((Info->Action == PragmaAttributeInfo::Push && Tok.
isNot(tok::eod)) ||
4030 Info->Action == PragmaAttributeInfo::Attribute) {
4031 if (Tok.
isNot(tok::l_paren)) {
4040 while (Tok.
isNot(tok::eod)) {
4041 if (Tok.
is(tok::l_paren))
4043 else if (Tok.
is(tok::r_paren)) {
4045 if (OpenParens == 0)
4049 AttributeTokens.push_back(Tok);
4053 if (AttributeTokens.empty()) {
4054 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
4057 if (Tok.
isNot(tok::r_paren)) {
4069 AttributeTokens.push_back(EOFTok);
4071 markAsReinjectedForRelexing(AttributeTokens);
4076 if (Tok.
isNot(tok::eod))
4078 <<
"clang attribute";
4081 auto TokenArray = std::make_unique<Token[]>(1);
4082 TokenArray[0].startToken();
4083 TokenArray[0].setKind(tok::annot_pragma_attribute);
4084 TokenArray[0].setLocation(FirstToken.
getLocation());
4085 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
4086 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
4087 PP.EnterTokenStream(std::move(TokenArray), 1,
4092void PragmaMaxTokensHereHandler::HandlePragma(
Preprocessor &PP,
4096 if (Tok.
is(tok::eod)) {
4098 <<
"clang max_tokens_here" <<
true <<
"integer";
4104 if (Tok.
isNot(tok::numeric_constant) ||
4107 <<
"clang max_tokens_here";
4111 if (Tok.
isNot(tok::eod)) {
4113 <<
"clang max_tokens_here";
4118 PP.
Diag(
Loc, diag::warn_max_tokens)
4124void PragmaMaxTokensTotalHandler::HandlePragma(
Preprocessor &PP,
4128 if (Tok.
is(tok::eod)) {
4130 <<
"clang max_tokens_total" <<
true <<
"integer";
4136 if (Tok.
isNot(tok::numeric_constant) ||
4139 <<
"clang max_tokens_total";
4143 if (Tok.
isNot(tok::eod)) {
4145 <<
"clang max_tokens_total";
4156 Token &FirstToken) {
4161 if (!II || !II->
isStr(
"intrinsic")) {
4163 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'intrinsic'";
4169 if (!II || !(II->
isStr(
"vector") || II->
isStr(
"sifive_vector"))) {
4172 <<
"'vector' or 'sifive_vector'";
4177 if (Tok.
isNot(tok::eod)) {
4179 <<
"clang riscv intrinsic";
4183 if (II->
isStr(
"vector"))
4184 Actions.RISCV().DeclareRVVBuiltins =
true;
4185 else if (II->
isStr(
"sifive_vector"))
4186 Actions.RISCV().DeclareSiFiveVectorBuiltins =
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.
This file declares semantic analysis functions specific to RISC-V.
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 a...
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.
SourceRange DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found.
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 ...
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)
uint32_t Literal
Literals are represented as positive integers.
@ Ignored
Do not present this diagnostic, ignore it.
@ FixIt
Parse and apply any fixits to the source.
const Regex Rule("(.+)/(.+)\\.framework/")
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