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,
2136 if (Tok.
isNot(tok::l_paren)) {
2137 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
2142 StringRef SlotLabel;
2146 if (Tok.
is(tok::numeric_constant)) {
2157 }
else if (Tok.
is(tok::identifier)) {
2159 if (II->
isStr(
"show")) {
2163 if (II->
isStr(
"push")) {
2165 }
else if (II->
isStr(
"pop")) {
2168 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
2173 if (Tok.
is(tok::comma)) {
2176 if (Tok.
is(tok::numeric_constant)) {
2181 }
else if (Tok.
is(tok::identifier)) {
2185 if (Tok.
is(tok::comma)) {
2188 if (Tok.
isNot(tok::numeric_constant)) {
2213 if (Tok.
isNot(tok::r_paren)) {
2214 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
2220 if (Tok.
isNot(tok::eod)) {
2221 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
2233 Toks[0].startToken();
2234 Toks[0].setKind(tok::annot_pragma_pack);
2235 Toks[0].setLocation(PackLoc);
2236 Toks[0].setAnnotationEndLoc(RParenLoc);
2237 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2238 PP.EnterTokenStream(Toks,
true,
2244void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
2246 Token &MSStructTok) {
2251 if (Tok.
isNot(tok::identifier)) {
2257 if (II->
isStr(
"on")) {
2261 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
2268 if (Tok.
isNot(tok::eod)) {
2276 Toks[0].startToken();
2277 Toks[0].setKind(tok::annot_pragma_msstruct);
2279 Toks[0].setAnnotationEndLoc(EndLoc);
2280 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2282 PP.EnterTokenStream(Toks,
true,
2287void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
2289 Token &FirstToken) {
2295 while (Tok.
isNot(tok::eod)) {
2296 if (Tok.
isNot(tok::identifier)) {
2297 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2302 if (SecType->
isStr(
"bss"))
2304 else if (SecType->
isStr(
"data"))
2306 else if (SecType->
isStr(
"rodata"))
2308 else if (SecType->
isStr(
"relro"))
2310 else if (SecType->
isStr(
"text"))
2313 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2319 if (Tok.
isNot(tok::equal)) {
2320 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal) << SecKind;
2324 std::string SecName;
2328 Actions.ActOnPragmaClangSection(
2345 if (Tok.
isNot(tok::identifier) ||
2354 if (Tok.
isNot(tok::l_paren)) {
2355 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"align";
2358 }
else if (Tok.
isNot(tok::equal)) {
2365 if (Tok.
isNot(tok::identifier)) {
2367 << (IsOptions ?
"options" :
"align");
2373 if (II->
isStr(
"native"))
2375 else if (II->
isStr(
"natural"))
2377 else if (II->
isStr(
"packed"))
2379 else if (II->
isStr(
"power"))
2381 else if (II->
isStr(
"mac68k"))
2383 else if (II->
isStr(
"reset"))
2393 if (Tok.
isNot(tok::r_paren)) {
2394 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"align";
2401 if (Tok.
isNot(tok::eod)) {
2403 << (IsOptions ?
"options" :
"align");
2409 Toks[0].startToken();
2410 Toks[0].setKind(tok::annot_pragma_align);
2412 Toks[0].setAnnotationEndLoc(EndLoc);
2413 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2415 PP.EnterTokenStream(Toks,
true,
2425void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
2427 Token &OptionsTok) {
2432void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
2441 if (Tok.
isNot(tok::l_paren)) {
2442 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
2455 if (Tok.
is(tok::identifier)) {
2456 Identifiers.push_back(Tok);
2467 if (Tok.
is(tok::comma)) {
2472 if (Tok.
is(tok::r_paren)) {
2478 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
2483 if (Tok.
isNot(tok::eod)) {
2490 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
2491 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
2500 2 * Identifiers.size());
2501 for (
unsigned i=0; i != Identifiers.size(); i++) {
2502 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
2504 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
2506 idTok = Identifiers[i];
2508 PP.EnterTokenStream(Toks,
true,
2521 if (Tok.
isNot(tok::identifier)) {
2522 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
2526 Token WeakName = Tok;
2527 bool HasAlias =
false;
2531 if (Tok.
is(tok::equal)) {
2534 if (Tok.
isNot(tok::identifier)) {
2543 if (Tok.
isNot(tok::eod)) {
2544 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
2551 Token &pragmaUnusedTok = Toks[0];
2553 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
2557 Toks[2] = AliasName;
2558 PP.EnterTokenStream(Toks,
true,
2563 Token &pragmaUnusedTok = Toks[0];
2565 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
2569 PP.EnterTokenStream(Toks,
true,
2575void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
2577 Token &RedefToken) {
2582 if (Tok.
isNot(tok::identifier)) {
2588 Token RedefName = Tok;
2591 if (Tok.
isNot(tok::identifier)) {
2593 <<
"redefine_extname";
2597 Token AliasName = Tok;
2600 if (Tok.
isNot(tok::eod)) {
2608 Token &pragmaRedefTok = Toks[0];
2610 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
2613 Toks[1] = RedefName;
2614 Toks[2] = AliasName;
2615 PP.EnterTokenStream(Toks,
true,
2619void PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
2628 Toks[0].startToken();
2629 Toks[0].setKind(tok::annot_pragma_fp_contract);
2632 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2634 PP.EnterTokenStream(Toks,
true,
2638void PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
2642 if (Tok.
isNot(tok::identifier)) {
2651 if (Tok.
isNot(tok::colon)) {
2657 if (Tok.
isNot(tok::identifier)) {
2658 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
2663 OpenCLExtState State;
2664 if (Pred->
isStr(
"enable")) {
2666 }
else if (Pred->
isStr(
"disable")) {
2668 }
else if (Pred->
isStr(
"begin"))
2670 else if (Pred->
isStr(
"end"))
2674 << Ext->
isStr(
"all");
2680 if (Tok.
isNot(tok::eod)) {
2688 Info->second = State;
2691 Toks[0].startToken();
2692 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2693 Toks[0].setLocation(NameLoc);
2694 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2695 Toks[0].setAnnotationEndLoc(StateLoc);
2696 PP.EnterTokenStream(Toks,
true,
2706template <diag::kind IgnoredDiag>
2707void PragmaNoSupportHandler<IgnoredDiag>::HandlePragma(
2710 PP.
Diag(FirstTok, IgnoredDiag);
2721void PragmaSupportHandler<StartTok, EndTok, UnexpectedDiag>::HandlePragma(
2729 while (Tok.
isNot(tok::eod) && Tok.
isNot(tok::eof)) {
2730 Pragma.push_back(Tok);
2732 if (Tok.
is(StartTok)) {
2733 PP.
Diag(Tok, UnexpectedDiag) << 0;
2734 unsigned InnerPragmaCnt = 1;
2735 while (InnerPragmaCnt != 0) {
2737 if (Tok.
is(StartTok))
2739 else if (Tok.
is(EndTok))
2749 Pragma.push_back(Tok);
2751 auto Toks = std::make_unique<Token[]>(Pragma.size());
2752 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2753 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2765void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2770 if (Tok.
isNot(tok::l_paren)) {
2771 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2772 <<
"pointers_to_members";
2779 <<
"pointers_to_members";
2785 if (Arg->
isStr(
"best_case")) {
2788 if (Arg->
isStr(
"full_generality")) {
2789 if (Tok.
is(tok::comma)) {
2795 diag::err_pragma_pointers_to_members_unknown_kind)
2800 }
else if (Tok.
is(tok::r_paren)) {
2807 <<
"full_generality";
2813 if (Arg->
isStr(
"single_inheritance")) {
2814 RepresentationMethod =
2816 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2817 RepresentationMethod =
2819 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2820 RepresentationMethod =
2824 diag::err_pragma_pointers_to_members_unknown_kind)
2831 if (Tok.
isNot(tok::r_paren)) {
2833 << (Arg ? Arg->
getName() :
"full_generality");
2839 if (Tok.
isNot(tok::eod)) {
2841 <<
"pointers_to_members";
2847 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2851 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RepresentationMethod)));
2867 if (Tok.
isNot(tok::l_paren)) {
2868 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2876 if (II->
isStr(
"push")) {
2879 if (Tok.
isNot(tok::comma)) {
2880 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2886 }
else if (II->
isStr(
"pop")) {
2893 if (Tok.
is(tok::r_paren)) {
2903 if (II && II->
isStr(
"off")) {
2906 }
else if (II && II->
isStr(
"on")) {
2909 }
else if (Tok.
is(tok::numeric_constant) &&
2913 << 0 << 2 <<
"vtordisp";
2924 if (Tok.
isNot(tok::r_paren)) {
2925 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2930 if (Tok.
isNot(tok::eod)) {
2939 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2951 Token EoF, AnnotTok;
2955 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2960 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2961 TokenVector.push_back(Tok);
2965 TokenVector.push_back(EoF);
2968 markAsReinjectedForRelexing(TokenVector);
2969 auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
2970 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2972 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2973 TokenVector.size());
2989void PragmaFloatControlHandler::HandlePragma(
Preprocessor &PP,
2994 Token PragmaName = Tok;
3001 if (Tok.
isNot(tok::l_paren)) {
3002 PP.
Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
3008 if (Tok.
isNot(tok::identifier)) {
3016 llvm::StringSwitch<PragmaFloatControlKind>(II->
getName())
3027 if (Tok.
isNot(tok::r_paren)) {
3034 if (Tok.
is(tok::r_paren))
3037 else if (Tok.
isNot(tok::comma)) {
3047 if (PushOnOff ==
"on")
3050 else if (PushOnOff ==
"off") {
3055 }
else if (PushOnOff ==
"push") {
3062 if (Tok.
is(tok::comma)) {
3069 if (ExpectedPush ==
"push") {
3077 if (Tok.
isNot(tok::r_paren)) {
3085 if (Tok.
isNot(tok::eod)) {
3094 auto TokenArray = std::make_unique<Token[]>(1);
3095 TokenArray[0].startToken();
3096 TokenArray[0].setKind(tok::annot_pragma_float_control);
3097 TokenArray[0].setLocation(FloatControlLoc);
3098 TokenArray[0].setAnnotationEndLoc(EndLoc);
3101 TokenArray[0].setAnnotationValue(
reinterpret_cast<void *
>(
3102 static_cast<uintptr_t>((Action << 16) | (Kind & 0xFFFF))));
3103 PP.EnterTokenStream(std::move(TokenArray), 1,
3117void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
3122 if (Tok.
isNot(tok::l_paren)) {
3123 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
3128 std::string NameString;
3130 "pragma detect_mismatch",
3135 std::string ValueString;
3136 if (Tok.
isNot(tok::comma)) {
3137 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3145 if (Tok.
isNot(tok::r_paren)) {
3151 if (Tok.
isNot(tok::eod)) {
3152 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3161 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
3173void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
3178 if (Tok.
isNot(tok::l_paren)) {
3179 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3185 if (Tok.
isNot(tok::identifier)) {
3186 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3193 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
3213 std::string ArgumentString;
3226 if (Tok.
isNot(tok::r_paren)) {
3232 if (Tok.
isNot(tok::eod)) {
3241 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
3246void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
3248 Token &FirstToken) {
3251 if (Tok.
is(tok::eod)) {
3253 <<
"clang optimize" <<
true <<
"'on' or 'off'";
3256 if (Tok.
isNot(tok::identifier)) {
3257 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3264 if (II->
isStr(
"on")) {
3266 }
else if (!II->
isStr(
"off")) {
3267 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3273 if (Tok.
isNot(tok::eod)) {
3279 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
3284struct TokFPAnnotValue {
3285 enum FlagValues { On, Off, Fast };
3287 std::optional<LangOptions::FPModeKind> ContractValue;
3288 std::optional<LangOptions::FPModeKind> ReassociateValue;
3289 std::optional<LangOptions::FPModeKind> ReciprocalValue;
3290 std::optional<LangOptions::FPExceptionModeKind> ExceptionsValue;
3291 std::optional<LangOptions::FPEvalMethodKind> EvalMethodValue;
3298 Token PragmaName = Tok;
3302 if (Tok.
isNot(tok::identifier)) {
3309 while (Tok.
is(tok::identifier)) {
3313 llvm::StringSwitch<std::optional<PragmaFPKind>>(OptionInfo->
getName())
3319 .Default(std::nullopt);
3322 <<
false << OptionInfo;
3328 if (Tok.
isNot(tok::l_paren)) {
3333 bool isEvalMethodDouble =
3337 if (Tok.
isNot(tok::identifier) && !isEvalMethodDouble) {
3340 <<
static_cast<int>(*FlagKind);
3346 AnnotValue->ContractValue =
3347 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3352 .Default(std::nullopt);
3353 if (!AnnotValue->ContractValue) {
3360 : AnnotValue->ReciprocalValue;
3361 Value = llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3365 .Default(std::nullopt);
3372 AnnotValue->ExceptionsValue =
3373 llvm::StringSwitch<std::optional<LangOptions::FPExceptionModeKind>>(
3378 .Default(std::nullopt);
3379 if (!AnnotValue->ExceptionsValue) {
3385 AnnotValue->EvalMethodValue =
3386 llvm::StringSwitch<std::optional<LangOptions::FPEvalMethodKind>>(
3391 .Default(std::nullopt);
3392 if (!AnnotValue->EvalMethodValue) {
3401 if (Tok.
isNot(tok::r_paren)) {
3408 if (Tok.
isNot(tok::eod)) {
3416 FPTok.
setKind(tok::annot_pragma_fp);
3420 TokenList.push_back(FPTok);
3422 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3423 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3425 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3429void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(
Preprocessor &PP,
3432 Token PragmaName = Tok;
3441 if (Tok.
isNot(tok::identifier)) {
3449 llvm::StringSwitch<llvm::RoundingMode>(II->
getName())
3450 .Case(
"FE_TOWARDZERO", llvm::RoundingMode::TowardZero)
3451 .Case(
"FE_TONEAREST", llvm::RoundingMode::NearestTiesToEven)
3452 .Case(
"FE_UPWARD", llvm::RoundingMode::TowardPositive)
3453 .Case(
"FE_DOWNWARD", llvm::RoundingMode::TowardNegative)
3454 .Case(
"FE_TONEARESTFROMZERO", llvm::RoundingMode::NearestTiesToAway)
3455 .Case(
"FE_DYNAMIC", llvm::RoundingMode::Dynamic)
3456 .Default(llvm::RoundingMode::Invalid);
3457 if (RM == llvm::RoundingMode::Invalid) {
3463 if (Tok.
isNot(tok::eod)) {
3465 <<
"STDC FENV_ROUND";
3474 Toks[0].startToken();
3475 Toks[0].setKind(tok::annot_pragma_fenv_round);
3478 Toks[0].setAnnotationValue(
3479 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RM)));
3480 PP.EnterTokenStream(Toks,
true,
3484void Parser::HandlePragmaFP() {
3485 assert(Tok.
is(tok::annot_pragma_fp));
3489 if (AnnotValue->ReassociateValue)
3494 if (AnnotValue->ReciprocalValue)
3499 if (AnnotValue->ContractValue)
3501 *AnnotValue->ContractValue);
3502 if (AnnotValue->ExceptionsValue)
3504 *AnnotValue->ExceptionsValue);
3505 if (AnnotValue->EvalMethodValue)
3507 *AnnotValue->EvalMethodValue);
3508 ConsumeAnnotationToken();
3513 Token Option,
bool ValueInParens,
3516 int OpenParens = ValueInParens ? 1 : 0;
3518 while (Tok.
isNot(tok::eod)) {
3519 if (Tok.
is(tok::l_paren))
3521 else if (Tok.
is(tok::r_paren)) {
3523 if (OpenParens == 0 && ValueInParens)
3531 if (ValueInParens) {
3533 if (Tok.
isNot(tok::r_paren)) {
3602void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
3606 Token PragmaName = Tok;
3611 if (Tok.
isNot(tok::identifier)) {
3617 while (Tok.
is(tok::identifier)) {
3621 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
3622 .Case(
"vectorize",
true)
3623 .Case(
"interleave",
true)
3624 .Case(
"unroll",
true)
3625 .Case(
"distribute",
true)
3626 .Case(
"vectorize_predicate",
true)
3627 .Case(
"vectorize_width",
true)
3628 .Case(
"interleave_count",
true)
3629 .Case(
"unroll_count",
true)
3630 .Case(
"pipeline",
true)
3631 .Case(
"pipeline_initiation_interval",
true)
3635 <<
false << OptionInfo;
3641 if (Tok.
isNot(tok::l_paren)) {
3655 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
3659 TokenList.push_back(LoopHintTok);
3662 if (Tok.
isNot(tok::eod)) {
3668 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3669 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3671 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3696void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
3701 Token PragmaName = Tok;
3704 if (Tok.
is(tok::eod)) {
3706 Info->PragmaName = PragmaName;
3707 Info->Option.startToken();
3717 bool ValueInParens = Tok.
is(tok::l_paren);
3729 PP.
Diag(Info->Toks[0].getLocation(),
3730 diag::warn_pragma_unroll_cuda_value_in_parens);
3732 if (Tok.
isNot(tok::eod)) {
3740 auto TokenArray = std::make_unique<Token[]>(1);
3741 TokenArray[0].startToken();
3742 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
3743 TokenArray[0].setLocation(Introducer.
Loc);
3744 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
3745 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3746 PP.EnterTokenStream(std::move(TokenArray), 1,
3762void PragmaMSIntrinsicHandler::HandlePragma(
Preprocessor &PP,
3767 if (Tok.
isNot(tok::l_paren)) {
3776 while (Tok.
is(tok::identifier)) {
3780 << II << SuggestIntrinH;
3783 if (Tok.
isNot(tok::comma))
3788 if (Tok.
isNot(tok::r_paren)) {
3795 if (Tok.
isNot(tok::eod))
3800bool Parser::HandlePragmaMSFunction(StringRef PragmaName,
3802 Token FirstTok = Tok;
3804 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3811 while (Tok.
is(tok::identifier)) {
3815 << II << SuggestIntrinH;
3817 NoBuiltins.emplace_back(II->
getName());
3820 if (Tok.
isNot(tok::comma))
3825 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3827 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3836bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3838 Token FirstTok = Tok;
3839 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3843 if (Tok.
isNot(tok::string_literal)) {
3844 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_string) << PragmaName;
3852 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
3857 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
3861 if (Tok.
is(tok::eof) || Tok.
is(tok::r_paren)) {
3862 PP.
Diag(PragmaLocation, diag::warn_pragma_missing_argument)
3863 << PragmaName <<
true <<
"'on' or 'off'";
3867 if (!II || (!II->
isStr(
"on") && !II->
isStr(
"off"))) {
3868 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3873 bool IsOn = II->
isStr(
"on");
3876 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3881 if (!OptimizationList->
getString().empty()) {
3882 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3883 << OptimizationList->
getString() << PragmaName <<
true
3888 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3896void PragmaForceCUDAHostDeviceHandler::HandlePragma(
3898 Token FirstTok = Tok;
3902 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
3904 diag::warn_pragma_force_cuda_host_device_bad_arg);
3908 if (Info->
isStr(
"begin"))
3909 Actions.CUDA().PushForceHostDevice();
3910 else if (!Actions.CUDA().PopForceHostDevice())
3912 diag::err_pragma_cannot_end_force_cuda_host_device);
3915 if (!Tok.
is(tok::eod))
3917 diag::warn_pragma_force_cuda_host_device_bad_arg);
3947void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
3949 Token &FirstToken) {
3953 PragmaAttributeInfo(AttributesForPragmaAttribute);
3956 if (Tok.
is(tok::identifier)) {
3958 if (!II->
isStr(
"push") && !II->
isStr(
"pop")) {
3959 Info->Namespace = II;
3962 if (!Tok.
is(tok::period)) {
3963 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_period)
3971 if (!Tok.
isOneOf(tok::identifier, tok::l_paren)) {
3973 diag::err_pragma_attribute_expected_push_pop_paren);
3978 if (Tok.
is(tok::l_paren)) {
3979 if (Info->Namespace) {
3981 diag::err_pragma_attribute_namespace_on_attribute);
3983 diag::note_pragma_attribute_namespace_on_attribute);
3986 Info->Action = PragmaAttributeInfo::Attribute;
3989 if (II->
isStr(
"push"))
3990 Info->Action = PragmaAttributeInfo::Push;
3992 Info->Action = PragmaAttributeInfo::Pop;
3994 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
4003 if ((Info->Action == PragmaAttributeInfo::Push && Tok.
isNot(tok::eod)) ||
4004 Info->Action == PragmaAttributeInfo::Attribute) {
4005 if (Tok.
isNot(tok::l_paren)) {
4014 while (Tok.
isNot(tok::eod)) {
4015 if (Tok.
is(tok::l_paren))
4017 else if (Tok.
is(tok::r_paren)) {
4019 if (OpenParens == 0)
4023 AttributeTokens.push_back(Tok);
4027 if (AttributeTokens.empty()) {
4028 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
4031 if (Tok.
isNot(tok::r_paren)) {
4043 AttributeTokens.push_back(EOFTok);
4045 markAsReinjectedForRelexing(AttributeTokens);
4050 if (Tok.
isNot(tok::eod))
4052 <<
"clang attribute";
4055 auto TokenArray = std::make_unique<Token[]>(1);
4056 TokenArray[0].startToken();
4057 TokenArray[0].setKind(tok::annot_pragma_attribute);
4058 TokenArray[0].setLocation(FirstToken.
getLocation());
4059 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
4060 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
4061 PP.EnterTokenStream(std::move(TokenArray), 1,
4066void PragmaMaxTokensHereHandler::HandlePragma(
Preprocessor &PP,
4070 if (Tok.
is(tok::eod)) {
4072 <<
"clang max_tokens_here" <<
true <<
"integer";
4078 if (Tok.
isNot(tok::numeric_constant) ||
4081 <<
"clang max_tokens_here";
4085 if (Tok.
isNot(tok::eod)) {
4087 <<
"clang max_tokens_here";
4092 PP.
Diag(
Loc, diag::warn_max_tokens)
4098void PragmaMaxTokensTotalHandler::HandlePragma(
Preprocessor &PP,
4102 if (Tok.
is(tok::eod)) {
4104 <<
"clang max_tokens_total" <<
true <<
"integer";
4110 if (Tok.
isNot(tok::numeric_constant) ||
4113 <<
"clang max_tokens_total";
4117 if (Tok.
isNot(tok::eod)) {
4119 <<
"clang max_tokens_total";
4130 Token &FirstToken) {
4135 if (!II || !II->
isStr(
"intrinsic")) {
4137 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'intrinsic'";
4143 if (!II || !(II->
isStr(
"vector") || II->
isStr(
"sifive_vector"))) {
4146 <<
"'vector' or 'sifive_vector'";
4151 if (Tok.
isNot(tok::eod)) {
4153 <<
"clang riscv intrinsic";
4157 if (II->
isStr(
"vector"))
4158 Actions.RISCV().DeclareRVVBuiltins =
true;
4159 else if (II->
isStr(
"sifive_vector"))
4160 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) ...
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)
@ 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