28#include "llvm/ADT/ArrayRef.h"
29#include "llvm/ADT/StringSwitch.h"
38 Token &FirstToken)
override;
42 explicit PragmaGCCVisibilityHandler() :
PragmaHandler(
"visibility") {}
44 Token &FirstToken)
override;
50 Token &FirstToken)
override;
56 Token &FirstToken)
override;
60 explicit PragmaClangSectionHandler(
Sema &S)
63 Token &FirstToken)
override;
70 explicit PragmaMSStructHandler() :
PragmaHandler(
"ms_struct") {}
72 Token &FirstToken)
override;
78 Token &FirstToken)
override;
84 Token &FirstToken)
override;
88 explicit PragmaRedefineExtnameHandler() :
PragmaHandler(
"redefine_extname") {}
90 Token &FirstToken)
override;
94 PragmaOpenCLExtensionHandler() :
PragmaHandler(
"EXTENSION") {}
96 Token &FirstToken)
override;
103 Token &FirstToken)
override;
110 PragmaSTDC_FENV_ACCESSHandler() :
PragmaHandler(
"FENV_ACCESS") {}
113 Token &Tok)
override {
114 Token PragmaName = Tok;
126 Toks[0].startToken();
127 Toks[0].setKind(tok::annot_pragma_fenv_access);
130 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
132 PP.EnterTokenStream(Toks,
true,
138struct PragmaSTDC_CX_LIMITED_RANGEHandler :
public PragmaHandler {
139 PragmaSTDC_CX_LIMITED_RANGEHandler() :
PragmaHandler(
"CX_LIMITED_RANGE") {}
142 Token &Tok)
override {
150 Toks[0].startToken();
151 Toks[0].setKind(tok::annot_pragma_cx_limited_range);
154 Toks[0].setAnnotationValue(
155 reinterpret_cast<void *
>(
static_cast<uintptr_t>(OOS)));
156 PP.EnterTokenStream(Toks,
true,
163 PragmaSTDC_FENV_ROUNDHandler() :
PragmaHandler(
"FENV_ROUND") {}
166 Token &Tok)
override;
171 PragmaSTDC_UnknownHandler() =
default;
174 Token &UnknownTok)
override {
176 PP.
Diag(UnknownTok, diag::ext_stdc_pragma_ignored);
183 Token &FirstToken)
override;
189template <diag::kind IgnoredDiag>
191 PragmaNoSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
193 Token &FirstToken)
override;
196struct PragmaNoOpenMPHandler
197 :
public PragmaNoSupportHandler<diag::warn_pragma_omp_ignored> {
198 PragmaNoOpenMPHandler() : PragmaNoSupportHandler(
"omp") {}
201struct PragmaNoOpenACCHandler
202 :
public PragmaNoSupportHandler<diag::warn_pragma_acc_ignored> {
203 PragmaNoOpenACCHandler() : PragmaNoSupportHandler(
"acc") {}
212 PragmaSupportHandler(StringRef Name) :
PragmaHandler(Name) {}
214 Token &FirstToken)
override;
217struct PragmaOpenMPHandler
218 :
public PragmaSupportHandler<tok::annot_pragma_openmp,
219 tok::annot_pragma_openmp_end,
220 diag::err_omp_unexpected_directive> {
221 PragmaOpenMPHandler() : PragmaSupportHandler(
"omp") {}
224struct PragmaOpenACCHandler
225 :
public PragmaSupportHandler<tok::annot_pragma_openacc,
226 tok::annot_pragma_openacc_end,
227 diag::err_acc_unexpected_directive> {
228 PragmaOpenACCHandler() : PragmaSupportHandler(
"acc") {}
233 PragmaCommentHandler(
Sema &Actions)
236 Token &FirstToken)
override;
243 PragmaDetectMismatchHandler(
Sema &Actions)
246 Token &FirstToken)
override;
253 PragmaFloatControlHandler(
Sema &Actions)
256 Token &FirstToken)
override;
260 explicit PragmaMSPointersToMembers() :
PragmaHandler(
"pointers_to_members") {}
262 Token &FirstToken)
override;
268 Token &FirstToken)
override;
274 Token &FirstToken)
override;
279 PragmaOptimizeHandler(
Sema &S)
282 Token &FirstToken)
override;
291 Token &FirstToken)
override;
297 Token &FirstToken)
override;
307 Token &FirstToken)
override;
312 PragmaMSFenvAccessHandler() :
PragmaHandler(
"fenv_access") {}
314 Token &FirstToken)
override {
324 if (Tok.
isNot(tok::l_paren)) {
330 if (Tok.
isNot(tok::identifier)) {
336 if (II->
isStr(
"on")) {
339 }
else if (II->
isStr(
"off")) {
346 if (Tok.
isNot(tok::r_paren)) {
353 if (Tok.
isNot(tok::eod)) {
361 Toks[0].startToken();
362 Toks[0].setKind(tok::annot_pragma_fenv_access_ms);
365 Toks[0].setAnnotationValue(
366 reinterpret_cast<void*
>(
static_cast<uintptr_t>(OOS)));
367 PP.EnterTokenStream(Toks,
true,
372struct PragmaForceCUDAHostDeviceHandler :
public PragmaHandler {
373 PragmaForceCUDAHostDeviceHandler(
Sema &Actions)
374 :
PragmaHandler(
"force_cuda_host_device"), Actions(Actions) {}
376 Token &FirstToken)
override;
385 :
PragmaHandler(
"attribute"), AttributesForPragmaAttribute(AttrFactory) {}
387 Token &FirstToken)
override;
394 PragmaMaxTokensHereHandler() :
PragmaHandler(
"max_tokens_here") {}
396 Token &FirstToken)
override;
400 PragmaMaxTokensTotalHandler() :
PragmaHandler(
"max_tokens_total") {}
402 Token &FirstToken)
override;
406 PragmaRISCVHandler(
Sema &Actions)
409 Token &FirstToken)
override;
416 PragmaMCFuncHandler(
bool ReportError)
419 Token &Tok)
override {
421 PP.
Diag(Tok, diag::err_pragma_mc_func_not_supported);
425 bool ReportError =
false;
434void Parser::initializePragmaHandlers() {
435 AlignHandler = std::make_unique<PragmaAlignHandler>();
438 GCCVisibilityHandler = std::make_unique<PragmaGCCVisibilityHandler>();
441 OptionsHandler = std::make_unique<PragmaOptionsHandler>();
444 PackHandler = std::make_unique<PragmaPackHandler>();
447 MSStructHandler = std::make_unique<PragmaMSStructHandler>();
450 UnusedHandler = std::make_unique<PragmaUnusedHandler>();
453 WeakHandler = std::make_unique<PragmaWeakHandler>();
456 RedefineExtnameHandler = std::make_unique<PragmaRedefineExtnameHandler>();
459 FPContractHandler = std::make_unique<PragmaFPContractHandler>();
462 STDCFenvAccessHandler = std::make_unique<PragmaSTDC_FENV_ACCESSHandler>();
465 STDCFenvRoundHandler = std::make_unique<PragmaSTDC_FENV_ROUNDHandler>();
468 STDCCXLIMITHandler = std::make_unique<PragmaSTDC_CX_LIMITED_RANGEHandler>();
471 STDCUnknownHandler = std::make_unique<PragmaSTDC_UnknownHandler>();
474 PCSectionHandler = std::make_unique<PragmaClangSectionHandler>(Actions);
478 OpenCLExtensionHandler = std::make_unique<PragmaOpenCLExtensionHandler>();
484 OpenMPHandler = std::make_unique<PragmaOpenMPHandler>();
486 OpenMPHandler = std::make_unique<PragmaNoOpenMPHandler>();
490 OpenACCHandler = std::make_unique<PragmaOpenACCHandler>();
492 OpenACCHandler = std::make_unique<PragmaNoOpenACCHandler>();
497 MSCommentHandler = std::make_unique<PragmaCommentHandler>(Actions);
501 FloatControlHandler = std::make_unique<PragmaFloatControlHandler>(Actions);
504 MSDetectMismatchHandler =
505 std::make_unique<PragmaDetectMismatchHandler>(Actions);
507 MSPointersToMembers = std::make_unique<PragmaMSPointersToMembers>();
509 MSVtorDisp = std::make_unique<PragmaMSVtorDisp>();
511 MSInitSeg = std::make_unique<PragmaMSPragma>(
"init_seg");
513 MSDataSeg = std::make_unique<PragmaMSPragma>(
"data_seg");
515 MSBSSSeg = std::make_unique<PragmaMSPragma>(
"bss_seg");
517 MSConstSeg = std::make_unique<PragmaMSPragma>(
"const_seg");
519 MSCodeSeg = std::make_unique<PragmaMSPragma>(
"code_seg");
521 MSSection = std::make_unique<PragmaMSPragma>(
"section");
523 MSStrictGuardStackCheck =
524 std::make_unique<PragmaMSPragma>(
"strict_gs_check");
526 MSFunction = std::make_unique<PragmaMSPragma>(
"function");
528 MSAllocText = std::make_unique<PragmaMSPragma>(
"alloc_text");
530 MSOptimize = std::make_unique<PragmaMSPragma>(
"optimize");
532 MSRuntimeChecks = std::make_unique<PragmaMSRuntimeChecksHandler>();
534 MSIntrinsic = std::make_unique<PragmaMSIntrinsicHandler>();
536 MSFenvAccess = std::make_unique<PragmaMSFenvAccessHandler>();
541 CUDAForceHostDeviceHandler =
542 std::make_unique<PragmaForceCUDAHostDeviceHandler>(Actions);
546 OptimizeHandler = std::make_unique<PragmaOptimizeHandler>(Actions);
549 LoopHintHandler = std::make_unique<PragmaLoopHintHandler>();
552 UnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"unroll");
556 NoUnrollHintHandler = std::make_unique<PragmaUnrollHintHandler>(
"nounroll");
560 UnrollAndJamHintHandler =
561 std::make_unique<PragmaUnrollHintHandler>(
"unroll_and_jam");
564 NoUnrollAndJamHintHandler =
565 std::make_unique<PragmaUnrollHintHandler>(
"nounroll_and_jam");
568 FPHandler = std::make_unique<PragmaFPHandler>();
571 AttributePragmaHandler =
572 std::make_unique<PragmaAttributeHandler>(AttrFactory);
575 MaxTokensHerePragmaHandler = std::make_unique<PragmaMaxTokensHereHandler>();
578 MaxTokensTotalPragmaHandler = std::make_unique<PragmaMaxTokensTotalHandler>();
582 RISCVPragmaHandler = std::make_unique<PragmaRISCVHandler>(Actions);
587 MCFuncPragmaHandler = std::make_unique<PragmaMCFuncHandler>(
593void Parser::resetPragmaHandlers() {
596 AlignHandler.reset();
598 GCCVisibilityHandler.reset();
600 OptionsHandler.reset();
604 MSStructHandler.reset();
606 UnusedHandler.reset();
610 RedefineExtnameHandler.reset();
614 OpenCLExtensionHandler.reset();
618 OpenMPHandler.reset();
621 OpenACCHandler.reset();
626 MSCommentHandler.reset();
630 PCSectionHandler.reset();
633 FloatControlHandler.reset();
636 MSDetectMismatchHandler.reset();
638 MSPointersToMembers.reset();
654 MSStrictGuardStackCheck.reset();
660 MSRuntimeChecks.reset();
666 MSFenvAccess.reset();
671 CUDAForceHostDeviceHandler.reset();
675 FPContractHandler.reset();
678 STDCFenvAccessHandler.reset();
681 STDCFenvRoundHandler.reset();
684 STDCCXLIMITHandler.reset();
687 STDCUnknownHandler.reset();
690 OptimizeHandler.reset();
693 LoopHintHandler.reset();
697 UnrollHintHandler.reset();
701 NoUnrollHintHandler.reset();
704 UnrollAndJamHintHandler.reset();
707 NoUnrollAndJamHintHandler.reset();
713 AttributePragmaHandler.reset();
716 MaxTokensHerePragmaHandler.reset();
719 MaxTokensTotalPragmaHandler.reset();
723 RISCVPragmaHandler.reset();
728 MCFuncPragmaHandler.reset();
737void Parser::HandlePragmaUnused() {
738 assert(Tok.
is(tok::annot_pragma_unused));
744void Parser::HandlePragmaVisibility() {
745 assert(Tok.
is(tok::annot_pragma_vis));
752void Parser::HandlePragmaPack() {
753 assert(Tok.
is(tok::annot_pragma_pack));
761 ConsumeAnnotationToken();
769 ConsumeAnnotationToken();
772void Parser::HandlePragmaMSStruct() {
773 assert(Tok.
is(tok::annot_pragma_msstruct));
777 ConsumeAnnotationToken();
780void Parser::HandlePragmaAlign() {
781 assert(Tok.
is(tok::annot_pragma_align));
788 ConsumeAnnotationToken();
791void Parser::HandlePragmaDump() {
792 assert(Tok.
is(tok::annot_pragma_dump));
793 ConsumeAnnotationToken();
794 if (Tok.
is(tok::eod)) {
795 PP.
Diag(Tok, diag::warn_pragma_debug_missing_argument) <<
"dump";
797 if (Tok.
isNot(tok::identifier)) {
798 PP.
Diag(Tok, diag::warn_pragma_debug_unexpected_argument);
800 ExpectAndConsume(tok::eod);
814 PP.
Diag(StartLoc, diag::warn_pragma_debug_dependent_argument)
822 ExpectAndConsume(tok::eod);
825void Parser::HandlePragmaWeak() {
826 assert(Tok.
is(tok::annot_pragma_weak));
833void Parser::HandlePragmaWeakAlias() {
834 assert(Tok.
is(tok::annot_pragma_weakalias));
843 WeakNameLoc, AliasNameLoc);
847void Parser::HandlePragmaRedefineExtname() {
848 assert(Tok.
is(tok::annot_pragma_redefine_extname));
857 RedefNameLoc, AliasNameLoc);
860void Parser::HandlePragmaFPContract() {
861 assert(Tok.
is(tok::annot_pragma_fp_contract));
888void Parser::HandlePragmaFloatControl() {
889 assert(Tok.
is(tok::annot_pragma_float_control));
904void Parser::HandlePragmaFEnvAccess() {
905 assert(Tok.
is(tok::annot_pragma_fenv_access) ||
906 Tok.
is(tok::annot_pragma_fenv_access_ms));
928void Parser::HandlePragmaFEnvRound() {
929 assert(Tok.
is(tok::annot_pragma_fenv_round));
930 auto RM =
static_cast<llvm::RoundingMode
>(
937void Parser::HandlePragmaCXLimitedRange() {
938 assert(Tok.
is(tok::annot_pragma_cx_limited_range));
964 assert(Tok.
is(tok::annot_pragma_captured));
965 ConsumeAnnotationToken();
967 if (Tok.
isNot(tok::l_brace)) {
968 PP.
Diag(Tok, diag::err_expected) << tok::l_brace;
980 CapturedRegionScope.Exit();
991 enum OpenCLExtState :
char {
992 Disable, Enable,
Begin, End
994 typedef std::pair<const IdentifierInfo *, OpenCLExtState> OpenCLExtData;
997void Parser::HandlePragmaOpenCLExtension() {
998 assert(Tok.
is(tok::annot_pragma_opencl_extension));
1000 auto State =
Data->second;
1001 auto Ident =
Data->first;
1003 ConsumeAnnotationToken();
1006 auto Name = Ident->getName();
1010 if (Name ==
"all") {
1011 if (State == Disable)
1014 PP.
Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
1015 }
else if (State ==
Begin) {
1016 if (!Opt.isKnown(Name) || !Opt.isSupported(Name,
getLangOpts())) {
1020 Opt.acceptsPragma(Name);
1022 }
else if (State == End) {
1025 }
else if (!Opt.isKnown(Name) || !Opt.isWithPragma(Name))
1026 PP.
Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
1027 else if (Opt.isSupportedExtension(Name,
getLangOpts()))
1028 Opt.enable(Name, State == Enable);
1029 else if (Opt.isSupportedCoreOrOptionalCore(Name,
getLangOpts()))
1030 PP.
Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
1032 PP.
Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;
1035void Parser::HandlePragmaMSPointersToMembers() {
1036 assert(Tok.
is(tok::annot_pragma_ms_pointers_to_members));
1044void Parser::HandlePragmaMSVtorDisp() {
1045 assert(Tok.
is(tok::annot_pragma_ms_vtordisp));
1054void Parser::HandlePragmaMSPragma() {
1055 assert(Tok.
is(tok::annot_pragma_ms_pragma));
1059 PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second,
true,
1070 llvm::StringSwitch<PragmaHandler>(PragmaName)
1071 .Case(
"data_seg", &Parser::HandlePragmaMSSegment)
1072 .Case(
"bss_seg", &Parser::HandlePragmaMSSegment)
1073 .Case(
"const_seg", &Parser::HandlePragmaMSSegment)
1074 .Case(
"code_seg", &Parser::HandlePragmaMSSegment)
1075 .Case(
"section", &Parser::HandlePragmaMSSection)
1076 .Case(
"init_seg", &Parser::HandlePragmaMSInitSeg)
1077 .Case(
"strict_gs_check", &Parser::HandlePragmaMSStrictGuardStackCheck)
1078 .Case(
"function", &Parser::HandlePragmaMSFunction)
1079 .Case(
"alloc_text", &Parser::HandlePragmaMSAllocText)
1080 .Case(
"optimize", &Parser::HandlePragmaMSOptimize);
1082 if (!(this->*Handler)(PragmaName, PragmaLocation)) {
1085 while (Tok.
isNot(tok::eof))
1091bool Parser::HandlePragmaMSSection(StringRef PragmaName,
1093 if (Tok.
isNot(tok::l_paren)) {
1094 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1099 if (Tok.
isNot(tok::string_literal)) {
1100 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1109 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1114 bool SectionFlagsAreDefault =
true;
1115 while (Tok.
is(tok::comma)) {
1120 if (Tok.
is(tok::kw_long) || Tok.
is(tok::kw_short)) {
1126 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
1131 llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
1144 ? diag::warn_pragma_invalid_specific_action
1145 : diag::warn_pragma_unsupported_action)
1149 SectionFlags |= Flag;
1150 SectionFlagsAreDefault =
false;
1155 if (SectionFlagsAreDefault)
1157 if (Tok.
isNot(tok::r_paren)) {
1158 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1162 if (Tok.
isNot(tok::eof)) {
1163 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1172bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
1174 if (Tok.
isNot(tok::l_paren)) {
1175 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
1180 StringRef SlotLabel;
1183 if (PushPop ==
"push")
1185 else if (PushPop ==
"pop")
1188 PP.
Diag(PragmaLocation,
1189 diag::warn_pragma_expected_section_push_pop_or_name)
1195 if (Tok.
is(tok::comma)) {
1201 if (Tok.
is(tok::comma))
1203 else if (Tok.
isNot(tok::r_paren)) {
1204 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc)
1209 }
else if (Tok.
isNot(tok::r_paren)) {
1210 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
1217 if (Tok.
isNot(tok::r_paren)) {
1218 if (Tok.
isNot(tok::string_literal)) {
1220 diag::warn_pragma_expected_section_name :
1221 diag::warn_pragma_expected_section_label_or_name :
1222 diag::warn_pragma_expected_section_push_pop_or_name;
1223 PP.
Diag(PragmaLocation, DiagID) << PragmaName;
1229 SegmentName = cast<StringLiteral>(StringResult.
get());
1231 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1239 if (Tok.
isNot(tok::r_paren)) {
1240 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
1244 if (Tok.
isNot(tok::eof)) {
1245 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
1251 SegmentName, PragmaName);
1256bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
1258 if (
getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
1259 PP.
Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
1263 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1271 StringRef Section = llvm::StringSwitch<StringRef>(II->
getName())
1272 .Case(
"compiler",
"\".CRT$XCC\"")
1273 .Case(
"lib",
"\".CRT$XCL\"")
1274 .Case(
"user",
"\".CRT$XCU\"")
1277 if (!Section.empty()) {
1281 Toks[0].
setKind(tok::string_literal);
1289 }
else if (Tok.
is(tok::string_literal)) {
1293 SegmentName = cast<StringLiteral>(StringResult.
get());
1295 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1303 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
1307 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1309 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1320bool Parser::HandlePragmaMSStrictGuardStackCheck(
1322 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1327 if (Tok.
is(tok::identifier)) {
1329 if (PushPop ==
"push") {
1332 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_punc,
1335 }
else if (PushPop ==
"pop") {
1344 if (II && II->
isStr(
"off")) {
1347 }
else if (II && II->
isStr(
"on")) {
1358 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1362 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1370bool Parser::HandlePragmaMSAllocText(StringRef PragmaName,
1372 Token FirstTok = Tok;
1373 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
1378 if (Tok.
is(tok::string_literal)) {
1384 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
1389 }
else if (Tok.
is(tok::identifier)) {
1393 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
1398 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
1404 if (Tok.
isNot(tok::identifier)) {
1414 if (Tok.
isNot(tok::comma))
1419 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
1421 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
1431 std::string ClangLoopStr(
"clang loop ");
1434 return std::string(llvm::StringSwitch<StringRef>(Str)
1435 .Case(
"loop", ClangLoopStr)
1436 .Case(
"unroll_and_jam", Str)
1437 .Case(
"unroll", Str)
1441bool Parser::HandlePragmaLoopHint(
LoopHint &Hint) {
1442 assert(Tok.
is(tok::annot_pragma_loop_hint));
1462 auto IsLoopHint = llvm::StringSwitch<bool>(PragmaNameInfo->
getName())
1463 .Cases(
"unroll",
"nounroll",
"unroll_and_jam",
1464 "nounroll_and_jam",
true)
1467 if (Toks.empty() && IsLoopHint) {
1468 ConsumeAnnotationToken();
1475 assert(!Toks.empty() &&
1476 "PragmaLoopHintInfo::Toks must contain at least one token.");
1479 bool OptionUnroll =
false;
1480 bool OptionUnrollAndJam =
false;
1481 bool OptionDistribute =
false;
1482 bool OptionPipelineDisabled =
false;
1483 bool StateOption =
false;
1485 OptionUnroll = OptionInfo->
isStr(
"unroll");
1486 OptionUnrollAndJam = OptionInfo->
isStr(
"unroll_and_jam");
1487 OptionDistribute = OptionInfo->
isStr(
"distribute");
1488 OptionPipelineDisabled = OptionInfo->
isStr(
"pipeline");
1489 StateOption = llvm::StringSwitch<bool>(OptionInfo->
getName())
1490 .Case(
"vectorize",
true)
1491 .Case(
"interleave",
true)
1492 .Case(
"vectorize_predicate",
true)
1494 OptionUnroll || OptionUnrollAndJam || OptionDistribute ||
1495 OptionPipelineDisabled;
1498 bool AssumeSafetyArg = !OptionUnroll && !OptionUnrollAndJam &&
1499 !OptionDistribute && !OptionPipelineDisabled;
1501 if (Toks[0].is(tok::eof)) {
1502 ConsumeAnnotationToken();
1503 Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
1505 << (OptionUnroll || OptionUnrollAndJam)
1512 ConsumeAnnotationToken();
1516 bool Valid = StateInfo &&
1517 llvm::StringSwitch<bool>(StateInfo->
getName())
1518 .Case(
"disable",
true)
1519 .Case(
"enable", !OptionPipelineDisabled)
1520 .Case(
"full", OptionUnroll || OptionUnrollAndJam)
1521 .Case(
"assume_safety", AssumeSafetyArg)
1524 if (OptionPipelineDisabled) {
1525 Diag(Toks[0].getLocation(), diag::err_pragma_pipeline_invalid_keyword);
1527 Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
1528 << (OptionUnroll || OptionUnrollAndJam)
1533 if (Toks.size() > 2)
1537 }
else if (OptionInfo && OptionInfo->
getName() ==
"vectorize_width") {
1538 PP.EnterTokenStream(Toks,
false,
1540 ConsumeAnnotationToken();
1544 StringRef IsScalableStr = StateInfo ? StateInfo->
getName() :
"";
1547 if (IsScalableStr ==
"scalable" || IsScalableStr ==
"fixed") {
1550 if (Toks.size() > 2) {
1553 while (Tok.
isNot(tok::eof))
1566 Diag(Toks[0].getLocation(),
1567 diag::note_pragma_loop_invalid_vectorize_option);
1569 bool Arg2Error =
false;
1570 if (Tok.
is(tok::comma)) {
1574 IsScalableStr = StateInfo->
getName();
1576 if (IsScalableStr !=
"scalable" && IsScalableStr !=
"fixed") {
1578 diag::err_pragma_loop_invalid_vectorize_option);
1589 if (Tok.
isNot(tok::eof)) {
1592 while (Tok.
isNot(tok::eof))
1608 PP.EnterTokenStream(Toks,
false,
1610 ConsumeAnnotationToken();
1615 if (Tok.
isNot(tok::eof)) {
1618 while (Tok.
isNot(tok::eof))
1634 Info->
Toks.back().getLocation());
1639struct PragmaAttributeInfo {
1640 enum ActionType { Push,
Pop, Attribute };
1646 PragmaAttributeInfo(
ParsedAttributes &Attributes) : Attributes(Attributes) {}
1649#include "clang/Parse/AttrSubMatchRulesParserStringSwitches.inc"
1654 if (Tok.
is(tok::identifier))
1663 using namespace attr;
1665#define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) \
1668#include "clang/Basic/AttrSubMatchRulesList.inc"
1670 llvm_unreachable(
"Invalid attribute subject match rule");
1678 PRef.
Diag(SubRuleLoc,
1679 diag::err_pragma_attribute_expected_subject_sub_identifier)
1681 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1692 PRef.
Diag(SubRuleLoc, diag::err_pragma_attribute_unknown_subject_sub_rule)
1693 << SubRuleName << PrimaryRuleName;
1694 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1700bool Parser::ParsePragmaAttributeSubjectMatchRuleSet(
1708 if (AnyParens.expectAndConsume())
1716 Diag(Tok, diag::err_pragma_attribute_expected_subject_identifier);
1719 std::pair<std::optional<attr::SubjectMatchRule>,
1720 std::optional<attr::SubjectMatchRule> (*)(StringRef,
bool)>
1721 Rule = isAttributeSubjectMatchRule(Name);
1723 Diag(Tok, diag::err_pragma_attribute_unknown_subject_rule) << Name;
1731 if (
Parens.expectAndConsume())
1733 }
else if (
Parens.consumeOpen()) {
1734 if (!SubjectMatchRules
1736 std::make_pair(PrimaryRule,
SourceRange(RuleLoc, RuleLoc)))
1738 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1741 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleLoc));
1742 LastMatchRuleEndLoc = RuleLoc;
1748 if (SubRuleName.empty()) {
1754 if (SubRuleName ==
"unless") {
1757 if (
Parens.expectAndConsume())
1760 if (SubRuleName.empty()) {
1765 auto SubRuleOrNone =
Rule.second(SubRuleName,
true);
1766 if (!SubRuleOrNone) {
1767 std::string SubRuleUnlessName =
"unless(" + SubRuleName.str() +
")";
1769 SubRuleUnlessName, SubRuleLoc);
1772 SubRule = *SubRuleOrNone;
1774 if (
Parens.consumeClose())
1777 auto SubRuleOrNone =
Rule.second(SubRuleName,
false);
1778 if (!SubRuleOrNone) {
1783 SubRule = *SubRuleOrNone;
1787 LastMatchRuleEndLoc = RuleEndLoc;
1788 if (
Parens.consumeClose())
1790 if (!SubjectMatchRules
1791 .insert(std::make_pair(SubRule,
SourceRange(RuleLoc, RuleEndLoc)))
1793 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1796 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleEndLoc));
1802 if (AnyParens.consumeClose())
1811enum class MissingAttributeSubjectRulesRecoveryPoint {
1819MissingAttributeSubjectRulesRecoveryPoint
1820getAttributeSubjectRulesRecoveryPointForToken(
const Token &Tok) {
1822 if (II->
isStr(
"apply_to"))
1823 return MissingAttributeSubjectRulesRecoveryPoint::ApplyTo;
1824 if (II->
isStr(
"any"))
1825 return MissingAttributeSubjectRulesRecoveryPoint::Any;
1827 if (Tok.
is(tok::equal))
1828 return MissingAttributeSubjectRulesRecoveryPoint::Equals;
1829 return MissingAttributeSubjectRulesRecoveryPoint::None;
1837 MissingAttributeSubjectRulesRecoveryPoint Point,
Parser &PRef) {
1843 MissingAttributeSubjectRulesRecoveryPoint EndPoint =
1844 getAttributeSubjectRulesRecoveryPointForToken(PRef.
getCurToken());
1845 if (Point == MissingAttributeSubjectRulesRecoveryPoint::Comma)
1847 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::ApplyTo &&
1848 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::ApplyTo)
1849 FixIt +=
"apply_to";
1850 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::Equals &&
1851 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::Equals)
1854 if (EndPoint == MissingAttributeSubjectRulesRecoveryPoint::None) {
1861 Attribute.getMatchRules(PRef.
getLangOpts(), MatchRules);
1863 for (
const auto &Rule : MatchRules) {
1868 IsSupported[
Rule.first] =
true;
1870 IsMatchRuleAvailable &= IsSupported;
1872 if (IsMatchRuleAvailable.count() == 0) {
1878 bool NeedsComma =
false;
1880 if (!IsMatchRuleAvailable[I])
1894 if (FixItRange.getBegin() == FixItRange.getEnd())
1904void Parser::HandlePragmaAttribute() {
1905 assert(Tok.
is(tok::annot_pragma_attribute) &&
1906 "Expected #pragma attribute annotation token");
1909 if (Info->Action == PragmaAttributeInfo::Pop) {
1910 ConsumeAnnotationToken();
1915 assert((Info->Action == PragmaAttributeInfo::Push ||
1916 Info->Action == PragmaAttributeInfo::Attribute) &&
1917 "Unexpected #pragma attribute command");
1919 if (Info->Action == PragmaAttributeInfo::Push && Info->Tokens.empty()) {
1920 ConsumeAnnotationToken();
1925 PP.EnterTokenStream(Info->Tokens,
false,
1927 ConsumeAnnotationToken();
1932 auto SkipToEnd = [
this]() {
1937 if ((Tok.
is(tok::l_square) &&
NextToken().is(tok::l_square)) ||
1940 ParseCXX11AttributeSpecifier(Attrs);
1941 }
else if (Tok.
is(tok::kw___attribute)) {
1943 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
1946 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"("))
1951 if (Tok.
is(tok::code_completion)) {
1961 if (Tok.
isNot(tok::identifier)) {
1962 Diag(Tok, diag::err_pragma_attribute_expected_attribute_name);
1969 if (Tok.
isNot(tok::l_paren))
1970 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1971 ParsedAttr::Form::GNU());
1973 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs,
nullptr,
1976 ParsedAttr::Form::GNU(),
1980 if (ExpectAndConsume(tok::r_paren))
1982 if (ExpectAndConsume(tok::r_paren))
1984 }
else if (Tok.
is(tok::kw___declspec)) {
1985 ParseMicrosoftDeclSpecs(Attrs);
1987 Diag(Tok, diag::err_pragma_attribute_expected_attribute_syntax);
1996 if (Tok.
is(tok::l_paren)) {
1999 if (Tok.
isNot(tok::r_paren))
2002 Diag(Tok, diag::note_pragma_attribute_use_attribute_kw)
2011 if (Attrs.
empty() || Attrs.
begin()->isInvalid()) {
2017 if (!Attribute.isSupportedByPragmaAttribute()) {
2018 Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute)
2027 createExpectedAttributeSubjectRulesTokenDiagnostic(
2028 diag::err_expected, Attrs,
2029 MissingAttributeSubjectRulesRecoveryPoint::Comma, *
this)
2035 if (Tok.
isNot(tok::identifier)) {
2036 createExpectedAttributeSubjectRulesTokenDiagnostic(
2037 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2038 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2043 if (!II->
isStr(
"apply_to")) {
2044 createExpectedAttributeSubjectRulesTokenDiagnostic(
2045 diag::err_pragma_attribute_invalid_subject_set_specifier, Attrs,
2046 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
2053 createExpectedAttributeSubjectRulesTokenDiagnostic(
2054 diag::err_expected, Attrs,
2055 MissingAttributeSubjectRulesRecoveryPoint::Equals, *
this)
2063 if (ParsePragmaAttributeSubjectMatchRuleSet(SubjectMatchRules, AnyLoc,
2064 LastMatchRuleEndLoc)) {
2071 if (Tok.
isNot(tok::eof)) {
2072 Diag(Tok, diag::err_pragma_attribute_extra_tokens_after_attribute);
2081 if (Info->Action == PragmaAttributeInfo::Push)
2093void PragmaGCCVisibilityHandler::HandlePragma(
Preprocessor &PP,
2104 if (PushPop && PushPop->
isStr(
"pop")) {
2106 }
else if (PushPop && PushPop->
isStr(
"push")) {
2108 if (Tok.
isNot(tok::l_paren)) {
2121 if (Tok.
isNot(tok::r_paren)) {
2133 if (Tok.
isNot(tok::eod)) {
2139 auto Toks = std::make_unique<Token[]>(1);
2140 Toks[0].startToken();
2141 Toks[0].setKind(tok::annot_pragma_vis);
2142 Toks[0].setLocation(VisLoc);
2143 Toks[0].setAnnotationEndLoc(EndLoc);
2144 Toks[0].setAnnotationValue(
2145 const_cast<void *
>(
static_cast<const void *
>(VisType)));
2146 PP.EnterTokenStream(std::move(Toks), 1,
true,
2161 if (Tok.
isNot(tok::l_paren)) {
2162 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
2167 StringRef SlotLabel;
2171 if (Tok.
is(tok::numeric_constant)) {
2182 }
else if (Tok.
is(tok::identifier)) {
2184 if (II->
isStr(
"show")) {
2188 if (II->
isStr(
"push")) {
2190 }
else if (II->
isStr(
"pop")) {
2193 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
2198 if (Tok.
is(tok::comma)) {
2201 if (Tok.
is(tok::numeric_constant)) {
2206 }
else if (Tok.
is(tok::identifier)) {
2210 if (Tok.
is(tok::comma)) {
2213 if (Tok.
isNot(tok::numeric_constant)) {
2238 if (Tok.
isNot(tok::r_paren)) {
2239 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
2245 if (Tok.
isNot(tok::eod)) {
2246 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
2258 Toks[0].startToken();
2259 Toks[0].setKind(tok::annot_pragma_pack);
2260 Toks[0].setLocation(PackLoc);
2261 Toks[0].setAnnotationEndLoc(RParenLoc);
2262 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2263 PP.EnterTokenStream(Toks,
true,
2269void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
2271 Token &MSStructTok) {
2276 if (Tok.
isNot(tok::identifier)) {
2282 if (II->
isStr(
"on")) {
2286 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
2293 if (Tok.
isNot(tok::eod)) {
2301 Toks[0].startToken();
2302 Toks[0].setKind(tok::annot_pragma_msstruct);
2304 Toks[0].setAnnotationEndLoc(EndLoc);
2305 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2307 PP.EnterTokenStream(Toks,
true,
2312void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
2314 Token &FirstToken) {
2320 while (Tok.
isNot(tok::eod)) {
2321 if (Tok.
isNot(tok::identifier)) {
2322 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2327 if (SecType->
isStr(
"bss"))
2329 else if (SecType->
isStr(
"data"))
2331 else if (SecType->
isStr(
"rodata"))
2333 else if (SecType->
isStr(
"relro"))
2335 else if (SecType->
isStr(
"text"))
2338 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
2344 if (Tok.
isNot(tok::equal)) {
2345 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal) << SecKind;
2349 std::string SecName;
2353 Actions.ActOnPragmaClangSection(
2370 if (Tok.
isNot(tok::identifier) ||
2379 if (Tok.
isNot(tok::l_paren)) {
2380 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"align";
2383 }
else if (Tok.
isNot(tok::equal)) {
2390 if (Tok.
isNot(tok::identifier)) {
2392 << (IsOptions ?
"options" :
"align");
2398 if (II->
isStr(
"native"))
2400 else if (II->
isStr(
"natural"))
2402 else if (II->
isStr(
"packed"))
2404 else if (II->
isStr(
"power"))
2406 else if (II->
isStr(
"mac68k"))
2408 else if (II->
isStr(
"reset"))
2418 if (Tok.
isNot(tok::r_paren)) {
2419 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"align";
2426 if (Tok.
isNot(tok::eod)) {
2428 << (IsOptions ?
"options" :
"align");
2434 Toks[0].startToken();
2435 Toks[0].setKind(tok::annot_pragma_align);
2437 Toks[0].setAnnotationEndLoc(EndLoc);
2438 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2440 PP.EnterTokenStream(Toks,
true,
2450void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
2452 Token &OptionsTok) {
2457void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
2466 if (Tok.
isNot(tok::l_paren)) {
2467 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
2480 if (Tok.
is(tok::identifier)) {
2481 Identifiers.push_back(Tok);
2492 if (Tok.
is(tok::comma)) {
2497 if (Tok.
is(tok::r_paren)) {
2503 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
2508 if (Tok.
isNot(tok::eod)) {
2515 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
2516 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
2525 2 * Identifiers.size());
2526 for (
unsigned i=0; i != Identifiers.size(); i++) {
2527 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
2529 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
2531 idTok = Identifiers[i];
2533 PP.EnterTokenStream(Toks,
true,
2546 if (Tok.
isNot(tok::identifier)) {
2547 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
2551 Token WeakName = Tok;
2552 bool HasAlias =
false;
2556 if (Tok.
is(tok::equal)) {
2559 if (Tok.
isNot(tok::identifier)) {
2568 if (Tok.
isNot(tok::eod)) {
2569 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
2576 Token &pragmaUnusedTok = Toks[0];
2578 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
2582 Toks[2] = AliasName;
2583 PP.EnterTokenStream(Toks,
true,
2588 Token &pragmaUnusedTok = Toks[0];
2590 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
2594 PP.EnterTokenStream(Toks,
true,
2600void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
2602 Token &RedefToken) {
2607 if (Tok.
isNot(tok::identifier)) {
2613 Token RedefName = Tok;
2616 if (Tok.
isNot(tok::identifier)) {
2618 <<
"redefine_extname";
2622 Token AliasName = Tok;
2625 if (Tok.
isNot(tok::eod)) {
2633 Token &pragmaRedefTok = Toks[0];
2635 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
2638 Toks[1] = RedefName;
2639 Toks[2] = AliasName;
2640 PP.EnterTokenStream(Toks,
true,
2644void PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
2653 Toks[0].startToken();
2654 Toks[0].setKind(tok::annot_pragma_fp_contract);
2657 Toks[0].setAnnotationValue(
reinterpret_cast<void*
>(
2659 PP.EnterTokenStream(Toks,
true,
2663void PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
2667 if (Tok.
isNot(tok::identifier)) {
2676 if (Tok.
isNot(tok::colon)) {
2682 if (Tok.
isNot(tok::identifier)) {
2683 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
2688 OpenCLExtState State;
2689 if (Pred->
isStr(
"enable")) {
2691 }
else if (Pred->
isStr(
"disable")) {
2693 }
else if (Pred->
isStr(
"begin"))
2695 else if (Pred->
isStr(
"end"))
2699 << Ext->
isStr(
"all");
2705 if (Tok.
isNot(tok::eod)) {
2713 Info->second = State;
2716 Toks[0].startToken();
2717 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2718 Toks[0].setLocation(NameLoc);
2719 Toks[0].setAnnotationValue(
static_cast<void*
>(Info));
2720 Toks[0].setAnnotationEndLoc(StateLoc);
2721 PP.EnterTokenStream(Toks,
true,
2731template <diag::kind IgnoredDiag>
2732void PragmaNoSupportHandler<IgnoredDiag>::HandlePragma(
2735 PP.
Diag(FirstTok, IgnoredDiag);
2746void PragmaSupportHandler<StartTok, EndTok, UnexpectedDiag>::HandlePragma(
2754 while (Tok.
isNot(tok::eod) && Tok.
isNot(tok::eof)) {
2755 Pragma.push_back(Tok);
2757 if (Tok.
is(StartTok)) {
2758 PP.
Diag(Tok, UnexpectedDiag) << 0;
2759 unsigned InnerPragmaCnt = 1;
2760 while (InnerPragmaCnt != 0) {
2762 if (Tok.
is(StartTok))
2764 else if (Tok.
is(EndTok))
2774 Pragma.push_back(Tok);
2776 auto Toks = std::make_unique<Token[]>(Pragma.size());
2777 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2778 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2790void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2795 if (Tok.
isNot(tok::l_paren)) {
2796 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2797 <<
"pointers_to_members";
2804 <<
"pointers_to_members";
2810 if (Arg->
isStr(
"best_case")) {
2813 if (Arg->
isStr(
"full_generality")) {
2814 if (Tok.
is(tok::comma)) {
2820 diag::err_pragma_pointers_to_members_unknown_kind)
2825 }
else if (Tok.
is(tok::r_paren)) {
2832 <<
"full_generality";
2838 if (Arg->
isStr(
"single_inheritance")) {
2839 RepresentationMethod =
2841 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2842 RepresentationMethod =
2844 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2845 RepresentationMethod =
2849 diag::err_pragma_pointers_to_members_unknown_kind)
2856 if (Tok.
isNot(tok::r_paren)) {
2858 << (Arg ? Arg->
getName() :
"full_generality");
2864 if (Tok.
isNot(tok::eod)) {
2866 <<
"pointers_to_members";
2872 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2876 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RepresentationMethod)));
2892 if (Tok.
isNot(tok::l_paren)) {
2893 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2901 if (II->
isStr(
"push")) {
2904 if (Tok.
isNot(tok::comma)) {
2905 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2911 }
else if (II->
isStr(
"pop")) {
2918 if (Tok.
is(tok::r_paren)) {
2928 if (II && II->
isStr(
"off")) {
2931 }
else if (II && II->
isStr(
"on")) {
2934 }
else if (Tok.
is(tok::numeric_constant) &&
2938 << 0 << 2 <<
"vtordisp";
2949 if (Tok.
isNot(tok::r_paren)) {
2950 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2955 if (Tok.
isNot(tok::eod)) {
2964 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2976 Token EoF, AnnotTok;
2980 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2985 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2986 TokenVector.push_back(Tok);
2990 TokenVector.push_back(EoF);
2993 markAsReinjectedForRelexing(TokenVector);
2994 auto TokenArray = std::make_unique<Token[]>(TokenVector.size());
2995 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2997 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2998 TokenVector.size());
3014void PragmaFloatControlHandler::HandlePragma(
Preprocessor &PP,
3019 Token PragmaName = Tok;
3026 if (Tok.
isNot(tok::l_paren)) {
3027 PP.
Diag(FloatControlLoc, diag::err_expected) << tok::l_paren;
3033 if (Tok.
isNot(tok::identifier)) {
3041 llvm::StringSwitch<PragmaFloatControlKind>(II->
getName())
3052 if (Tok.
isNot(tok::r_paren)) {
3059 if (Tok.
is(tok::r_paren))
3062 else if (Tok.
isNot(tok::comma)) {
3072 if (PushOnOff ==
"on")
3075 else if (PushOnOff ==
"off") {
3080 }
else if (PushOnOff ==
"push") {
3087 if (Tok.
is(tok::comma)) {
3094 if (ExpectedPush ==
"push") {
3102 if (Tok.
isNot(tok::r_paren)) {
3110 if (Tok.
isNot(tok::eod)) {
3119 auto TokenArray = std::make_unique<Token[]>(1);
3120 TokenArray[0].startToken();
3121 TokenArray[0].setKind(tok::annot_pragma_float_control);
3122 TokenArray[0].setLocation(FloatControlLoc);
3123 TokenArray[0].setAnnotationEndLoc(EndLoc);
3126 TokenArray[0].setAnnotationValue(
reinterpret_cast<void *
>(
3127 static_cast<uintptr_t>((Action << 16) | (Kind & 0xFFFF))));
3128 PP.EnterTokenStream(std::move(TokenArray), 1,
3142void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
3147 if (Tok.
isNot(tok::l_paren)) {
3148 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
3153 std::string NameString;
3155 "pragma detect_mismatch",
3160 std::string ValueString;
3161 if (Tok.
isNot(tok::comma)) {
3162 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3170 if (Tok.
isNot(tok::r_paren)) {
3176 if (Tok.
isNot(tok::eod)) {
3177 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
3186 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
3198void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
3203 if (Tok.
isNot(tok::l_paren)) {
3204 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3210 if (Tok.
isNot(tok::identifier)) {
3211 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
3218 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
3238 std::string ArgumentString;
3251 if (Tok.
isNot(tok::r_paren)) {
3257 if (Tok.
isNot(tok::eod)) {
3266 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
3271void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
3273 Token &FirstToken) {
3276 if (Tok.
is(tok::eod)) {
3278 <<
"clang optimize" <<
true <<
"'on' or 'off'";
3281 if (Tok.
isNot(tok::identifier)) {
3282 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3289 if (II->
isStr(
"on")) {
3291 }
else if (!II->
isStr(
"off")) {
3292 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
3298 if (Tok.
isNot(tok::eod)) {
3304 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
3309struct TokFPAnnotValue {
3310 enum FlagValues { On, Off, Fast };
3312 std::optional<LangOptions::FPModeKind> ContractValue;
3313 std::optional<LangOptions::FPModeKind> ReassociateValue;
3314 std::optional<LangOptions::FPModeKind> ReciprocalValue;
3315 std::optional<LangOptions::FPExceptionModeKind> ExceptionsValue;
3316 std::optional<LangOptions::FPEvalMethodKind> EvalMethodValue;
3323 Token PragmaName = Tok;
3327 if (Tok.
isNot(tok::identifier)) {
3334 while (Tok.
is(tok::identifier)) {
3338 llvm::StringSwitch<std::optional<PragmaFPKind>>(OptionInfo->
getName())
3344 .Default(std::nullopt);
3347 <<
false << OptionInfo;
3353 if (Tok.
isNot(tok::l_paren)) {
3358 bool isEvalMethodDouble =
3362 if (Tok.
isNot(tok::identifier) && !isEvalMethodDouble) {
3365 <<
static_cast<int>(*FlagKind);
3371 AnnotValue->ContractValue =
3372 llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3377 .Default(std::nullopt);
3378 if (!AnnotValue->ContractValue) {
3385 : AnnotValue->ReciprocalValue;
3386 Value = llvm::StringSwitch<std::optional<LangOptions::FPModeKind>>(
3390 .Default(std::nullopt);
3397 AnnotValue->ExceptionsValue =
3398 llvm::StringSwitch<std::optional<LangOptions::FPExceptionModeKind>>(
3403 .Default(std::nullopt);
3404 if (!AnnotValue->ExceptionsValue) {
3410 AnnotValue->EvalMethodValue =
3411 llvm::StringSwitch<std::optional<LangOptions::FPEvalMethodKind>>(
3416 .Default(std::nullopt);
3417 if (!AnnotValue->EvalMethodValue) {
3426 if (Tok.
isNot(tok::r_paren)) {
3433 if (Tok.
isNot(tok::eod)) {
3441 FPTok.
setKind(tok::annot_pragma_fp);
3445 TokenList.push_back(FPTok);
3447 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3448 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3450 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3454void PragmaSTDC_FENV_ROUNDHandler::HandlePragma(
Preprocessor &PP,
3457 Token PragmaName = Tok;
3466 if (Tok.
isNot(tok::identifier)) {
3474 llvm::StringSwitch<llvm::RoundingMode>(II->
getName())
3475 .Case(
"FE_TOWARDZERO", llvm::RoundingMode::TowardZero)
3476 .Case(
"FE_TONEAREST", llvm::RoundingMode::NearestTiesToEven)
3477 .Case(
"FE_UPWARD", llvm::RoundingMode::TowardPositive)
3478 .Case(
"FE_DOWNWARD", llvm::RoundingMode::TowardNegative)
3479 .Case(
"FE_TONEARESTFROMZERO", llvm::RoundingMode::NearestTiesToAway)
3480 .Case(
"FE_DYNAMIC", llvm::RoundingMode::Dynamic)
3481 .Default(llvm::RoundingMode::Invalid);
3482 if (RM == llvm::RoundingMode::Invalid) {
3488 if (Tok.
isNot(tok::eod)) {
3490 <<
"STDC FENV_ROUND";
3499 Toks[0].startToken();
3500 Toks[0].setKind(tok::annot_pragma_fenv_round);
3503 Toks[0].setAnnotationValue(
3504 reinterpret_cast<void *
>(
static_cast<uintptr_t>(RM)));
3505 PP.EnterTokenStream(Toks,
true,
3509void Parser::HandlePragmaFP() {
3510 assert(Tok.
is(tok::annot_pragma_fp));
3514 if (AnnotValue->ReassociateValue)
3519 if (AnnotValue->ReciprocalValue)
3524 if (AnnotValue->ContractValue)
3526 *AnnotValue->ContractValue);
3527 if (AnnotValue->ExceptionsValue)
3529 *AnnotValue->ExceptionsValue);
3530 if (AnnotValue->EvalMethodValue)
3532 *AnnotValue->EvalMethodValue);
3533 ConsumeAnnotationToken();
3538 Token Option,
bool ValueInParens,
3541 int OpenParens = ValueInParens ? 1 : 0;
3543 while (Tok.
isNot(tok::eod)) {
3544 if (Tok.
is(tok::l_paren))
3546 else if (Tok.
is(tok::r_paren)) {
3548 if (OpenParens == 0 && ValueInParens)
3556 if (ValueInParens) {
3558 if (Tok.
isNot(tok::r_paren)) {
3627void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
3631 Token PragmaName = Tok;
3636 if (Tok.
isNot(tok::identifier)) {
3642 while (Tok.
is(tok::identifier)) {
3646 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
3647 .Case(
"vectorize",
true)
3648 .Case(
"interleave",
true)
3649 .Case(
"unroll",
true)
3650 .Case(
"distribute",
true)
3651 .Case(
"vectorize_predicate",
true)
3652 .Case(
"vectorize_width",
true)
3653 .Case(
"interleave_count",
true)
3654 .Case(
"unroll_count",
true)
3655 .Case(
"pipeline",
true)
3656 .Case(
"pipeline_initiation_interval",
true)
3660 <<
false << OptionInfo;
3666 if (Tok.
isNot(tok::l_paren)) {
3680 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
3684 TokenList.push_back(LoopHintTok);
3687 if (Tok.
isNot(tok::eod)) {
3693 auto TokenArray = std::make_unique<Token[]>(TokenList.size());
3694 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
3696 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
3721void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
3726 Token PragmaName = Tok;
3729 if (Tok.
is(tok::eod)) {
3731 Info->PragmaName = PragmaName;
3732 Info->Option.startToken();
3742 bool ValueInParens = Tok.
is(tok::l_paren);
3754 PP.
Diag(Info->Toks[0].getLocation(),
3755 diag::warn_pragma_unroll_cuda_value_in_parens);
3757 if (Tok.
isNot(tok::eod)) {
3765 auto TokenArray = std::make_unique<Token[]>(1);
3766 TokenArray[0].startToken();
3767 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
3768 TokenArray[0].setLocation(Introducer.
Loc);
3769 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
3770 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
3771 PP.EnterTokenStream(std::move(TokenArray), 1,
3787void PragmaMSIntrinsicHandler::HandlePragma(
Preprocessor &PP,
3792 if (Tok.
isNot(tok::l_paren)) {
3801 while (Tok.
is(tok::identifier)) {
3805 << II << SuggestIntrinH;
3808 if (Tok.
isNot(tok::comma))
3813 if (Tok.
isNot(tok::r_paren)) {
3820 if (Tok.
isNot(tok::eod))
3825bool Parser::HandlePragmaMSFunction(StringRef PragmaName,
3827 Token FirstTok = Tok;
3829 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3836 while (Tok.
is(tok::identifier)) {
3840 << II << SuggestIntrinH;
3842 NoBuiltins.emplace_back(II->
getName());
3845 if (Tok.
isNot(tok::comma))
3850 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3852 ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3861bool Parser::HandlePragmaMSOptimize(StringRef PragmaName,
3863 Token FirstTok = Tok;
3864 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
3868 if (Tok.
isNot(tok::string_literal)) {
3869 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_string) << PragmaName;
3877 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
3882 if (ExpectAndConsume(tok::comma, diag::warn_pragma_expected_comma,
3886 if (Tok.
is(tok::eof) || Tok.
is(tok::r_paren)) {
3887 PP.
Diag(PragmaLocation, diag::warn_pragma_missing_argument)
3888 << PragmaName <<
true <<
"'on' or 'off'";
3892 if (!II || (!II->
isStr(
"on") && !II->
isStr(
"off"))) {
3893 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3898 bool IsOn = II->
isStr(
"on");
3901 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
3906 if (!OptimizationList->
getString().empty()) {
3907 PP.
Diag(PragmaLocation, diag::warn_pragma_invalid_argument)
3908 << OptimizationList->
getString() << PragmaName <<
true
3913 if (ExpectAndConsume(tok::eof, diag::warn_pragma_extra_tokens_at_eol,
3921void PragmaForceCUDAHostDeviceHandler::HandlePragma(
3923 Token FirstTok = Tok;
3927 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
3929 diag::warn_pragma_force_cuda_host_device_bad_arg);
3933 if (Info->
isStr(
"begin"))
3934 Actions.CUDA().PushForceHostDevice();
3935 else if (!Actions.CUDA().PopForceHostDevice())
3937 diag::err_pragma_cannot_end_force_cuda_host_device);
3940 if (!Tok.
is(tok::eod))
3942 diag::warn_pragma_force_cuda_host_device_bad_arg);
3972void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
3974 Token &FirstToken) {
3978 PragmaAttributeInfo(AttributesForPragmaAttribute);
3981 if (Tok.
is(tok::identifier)) {
3983 if (!II->
isStr(
"push") && !II->
isStr(
"pop")) {
3984 Info->Namespace = II;
3987 if (!Tok.
is(tok::period)) {
3988 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_period)
3996 if (!Tok.
isOneOf(tok::identifier, tok::l_paren)) {
3998 diag::err_pragma_attribute_expected_push_pop_paren);
4003 if (Tok.
is(tok::l_paren)) {
4004 if (Info->Namespace) {
4006 diag::err_pragma_attribute_namespace_on_attribute);
4008 diag::note_pragma_attribute_namespace_on_attribute);
4011 Info->Action = PragmaAttributeInfo::Attribute;
4014 if (II->
isStr(
"push"))
4015 Info->Action = PragmaAttributeInfo::Push;
4017 Info->Action = PragmaAttributeInfo::Pop;
4019 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
4028 if ((Info->Action == PragmaAttributeInfo::Push && Tok.
isNot(tok::eod)) ||
4029 Info->Action == PragmaAttributeInfo::Attribute) {
4030 if (Tok.
isNot(tok::l_paren)) {
4039 while (Tok.
isNot(tok::eod)) {
4040 if (Tok.
is(tok::l_paren))
4042 else if (Tok.
is(tok::r_paren)) {
4044 if (OpenParens == 0)
4048 AttributeTokens.push_back(Tok);
4052 if (AttributeTokens.empty()) {
4053 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
4056 if (Tok.
isNot(tok::r_paren)) {
4068 AttributeTokens.push_back(EOFTok);
4070 markAsReinjectedForRelexing(AttributeTokens);
4075 if (Tok.
isNot(tok::eod))
4077 <<
"clang attribute";
4080 auto TokenArray = std::make_unique<Token[]>(1);
4081 TokenArray[0].startToken();
4082 TokenArray[0].setKind(tok::annot_pragma_attribute);
4083 TokenArray[0].setLocation(FirstToken.
getLocation());
4084 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
4085 TokenArray[0].setAnnotationValue(
static_cast<void *
>(Info));
4086 PP.EnterTokenStream(std::move(TokenArray), 1,
4091void PragmaMaxTokensHereHandler::HandlePragma(
Preprocessor &PP,
4095 if (Tok.
is(tok::eod)) {
4097 <<
"clang max_tokens_here" <<
true <<
"integer";
4103 if (Tok.
isNot(tok::numeric_constant) ||
4106 <<
"clang max_tokens_here";
4110 if (Tok.
isNot(tok::eod)) {
4112 <<
"clang max_tokens_here";
4117 PP.
Diag(
Loc, diag::warn_max_tokens)
4123void PragmaMaxTokensTotalHandler::HandlePragma(
Preprocessor &PP,
4127 if (Tok.
is(tok::eod)) {
4129 <<
"clang max_tokens_total" <<
true <<
"integer";
4135 if (Tok.
isNot(tok::numeric_constant) ||
4138 <<
"clang max_tokens_total";
4142 if (Tok.
isNot(tok::eod)) {
4144 <<
"clang max_tokens_total";
4155 Token &FirstToken) {
4160 if (!II || !II->
isStr(
"intrinsic")) {
4162 << PP.
getSpelling(Tok) <<
"riscv" <<
true <<
"'intrinsic'";
4168 if (!II || !(II->
isStr(
"vector") || II->
isStr(
"sifive_vector"))) {
4171 <<
"'vector' or 'sifive_vector'";
4176 if (Tok.
isNot(tok::eod)) {
4178 <<
"clang riscv intrinsic";
4182 if (II->
isStr(
"vector"))
4183 Actions.RISCV().DeclareRVVBuiltins =
true;
4184 else if (II->
isStr(
"sifive_vector"))
4185 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
bool ErrorOnPragmaMcfuncOnAIX
If set, the preprocessor reports an error when processing #pragma mc_func on AIX.
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
PreprocessorOptions & getPreprocessorOpts() const
Retrieve the preprocessor options used to initialize this preprocessor.
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