23 #include "llvm/ADT/StringSwitch.h"
24 using namespace clang;
31 Token &FirstToken)
override;
35 explicit PragmaGCCVisibilityHandler() :
PragmaHandler(
"visibility") {}
37 Token &FirstToken)
override;
43 Token &FirstToken)
override;
49 Token &FirstToken)
override;
53 explicit PragmaClangSectionHandler(
Sema &
S)
56 Token &FirstToken)
override;
62 explicit PragmaMSStructHandler() :
PragmaHandler(
"ms_struct") {}
64 Token &FirstToken)
override;
70 Token &FirstToken)
override;
76 Token &FirstToken)
override;
80 explicit PragmaRedefineExtnameHandler() :
PragmaHandler(
"redefine_extname") {}
82 Token &FirstToken)
override;
86 PragmaOpenCLExtensionHandler() :
PragmaHandler(
"EXTENSION") {}
88 Token &FirstToken)
override;
95 Token &FirstToken)
override;
101 Token &FirstToken)
override;
107 Token &FirstToken)
override;
113 Token &FirstToken)
override;
118 PragmaCommentHandler(
Sema &Actions)
121 Token &FirstToken)
override;
127 PragmaDetectMismatchHandler(
Sema &Actions)
130 Token &FirstToken)
override;
136 explicit PragmaMSPointersToMembers() :
PragmaHandler(
"pointers_to_members") {}
138 Token &FirstToken)
override;
144 Token &FirstToken)
override;
148 explicit PragmaMSPragma(
const char *name) :
PragmaHandler(name) {}
150 Token &FirstToken)
override;
155 PragmaOptimizeHandler(
Sema &
S)
158 Token &FirstToken)
override;
166 Token &FirstToken)
override;
170 PragmaUnrollHintHandler(
const char *name) :
PragmaHandler(name) {}
172 Token &FirstToken)
override;
182 Token &FirstToken)
override;
185 struct PragmaForceCUDAHostDeviceHandler :
public PragmaHandler {
186 PragmaForceCUDAHostDeviceHandler(
Sema &Actions)
187 :
PragmaHandler(
"force_cuda_host_device"), Actions(Actions) {}
189 Token &FirstToken)
override;
198 :
PragmaHandler(
"attribute"), AttributesForPragmaAttribute(AttrFactory) {}
200 Token &FirstToken)
override;
208 void Parser::initializePragmaHandlers() {
209 AlignHandler.reset(
new PragmaAlignHandler());
212 GCCVisibilityHandler.reset(
new PragmaGCCVisibilityHandler());
215 OptionsHandler.reset(
new PragmaOptionsHandler());
218 PackHandler.reset(
new PragmaPackHandler());
221 MSStructHandler.reset(
new PragmaMSStructHandler());
224 UnusedHandler.reset(
new PragmaUnusedHandler());
227 WeakHandler.reset(
new PragmaWeakHandler());
230 RedefineExtnameHandler.reset(
new PragmaRedefineExtnameHandler());
233 FPContractHandler.reset(
new PragmaFPContractHandler());
236 PCSectionHandler.reset(
new PragmaClangSectionHandler(Actions));
240 OpenCLExtensionHandler.reset(
new PragmaOpenCLExtensionHandler());
246 OpenMPHandler.reset(
new PragmaOpenMPHandler());
248 OpenMPHandler.reset(
new PragmaNoOpenMPHandler());
252 MSCommentHandler.reset(
new PragmaCommentHandler(Actions));
257 MSDetectMismatchHandler.reset(
new PragmaDetectMismatchHandler(Actions));
259 MSPointersToMembers.reset(
new PragmaMSPointersToMembers());
261 MSVtorDisp.reset(
new PragmaMSVtorDisp());
263 MSInitSeg.reset(
new PragmaMSPragma(
"init_seg"));
265 MSDataSeg.reset(
new PragmaMSPragma(
"data_seg"));
267 MSBSSSeg.reset(
new PragmaMSPragma(
"bss_seg"));
269 MSConstSeg.reset(
new PragmaMSPragma(
"const_seg"));
271 MSCodeSeg.reset(
new PragmaMSPragma(
"code_seg"));
273 MSSection.reset(
new PragmaMSPragma(
"section"));
275 MSRuntimeChecks.reset(
new PragmaMSRuntimeChecksHandler());
277 MSIntrinsic.reset(
new PragmaMSIntrinsicHandler());
282 CUDAForceHostDeviceHandler.reset(
283 new PragmaForceCUDAHostDeviceHandler(Actions));
287 OptimizeHandler.reset(
new PragmaOptimizeHandler(Actions));
290 LoopHintHandler.reset(
new PragmaLoopHintHandler());
293 UnrollHintHandler.reset(
new PragmaUnrollHintHandler(
"unroll"));
296 NoUnrollHintHandler.reset(
new PragmaUnrollHintHandler(
"nounroll"));
299 FPHandler.reset(
new PragmaFPHandler());
302 AttributePragmaHandler.reset(
new PragmaAttributeHandler(AttrFactory));
306 void Parser::resetPragmaHandlers() {
309 AlignHandler.reset();
311 GCCVisibilityHandler.reset();
313 OptionsHandler.reset();
317 MSStructHandler.reset();
319 UnusedHandler.reset();
323 RedefineExtnameHandler.reset();
327 OpenCLExtensionHandler.reset();
331 OpenMPHandler.reset();
335 MSCommentHandler.reset();
339 PCSectionHandler.reset();
343 MSDetectMismatchHandler.reset();
345 MSPointersToMembers.reset();
361 MSRuntimeChecks.reset();
368 CUDAForceHostDeviceHandler.reset();
372 FPContractHandler.reset();
375 OptimizeHandler.reset();
378 LoopHintHandler.reset();
381 UnrollHintHandler.reset();
384 NoUnrollHintHandler.reset();
390 AttributePragmaHandler.reset();
398 void Parser::HandlePragmaUnused() {
399 assert(Tok.
is(tok::annot_pragma_unused));
405 void Parser::HandlePragmaVisibility() {
406 assert(Tok.
is(tok::annot_pragma_vis));
414 struct PragmaPackInfo {
421 void Parser::HandlePragmaPack() {
422 assert(Tok.
is(tok::annot_pragma_pack));
423 PragmaPackInfo *Info =
427 if (Info->Alignment.is(tok::numeric_constant)) {
436 void Parser::HandlePragmaMSStruct() {
437 assert(Tok.
is(tok::annot_pragma_msstruct));
441 ConsumeAnnotationToken();
444 void Parser::HandlePragmaAlign() {
445 assert(Tok.
is(tok::annot_pragma_align));
453 void Parser::HandlePragmaDump() {
454 assert(Tok.
is(tok::annot_pragma_dump));
458 ConsumeAnnotationToken();
461 void Parser::HandlePragmaWeak() {
462 assert(Tok.
is(tok::annot_pragma_weak));
469 void Parser::HandlePragmaWeakAlias() {
470 assert(Tok.
is(tok::annot_pragma_weakalias));
479 WeakNameLoc, AliasNameLoc);
483 void Parser::HandlePragmaRedefineExtname() {
484 assert(Tok.
is(tok::annot_pragma_redefine_extname));
493 RedefNameLoc, AliasNameLoc);
496 void Parser::HandlePragmaFPContract() {
497 assert(Tok.
is(tok::annot_pragma_fp_contract));
516 ConsumeAnnotationToken();
521 assert(Tok.
is(tok::annot_pragma_captured));
522 ConsumeAnnotationToken();
524 if (Tok.
isNot(tok::l_brace)) {
525 PP.
Diag(Tok, diag::err_expected) << tok::l_brace;
536 CapturedRegionScope.Exit();
550 typedef std::pair<const IdentifierInfo *, OpenCLExtState> OpenCLExtData;
553 void Parser::HandlePragmaOpenCLExtension() {
554 assert(Tok.
is(tok::annot_pragma_opencl_extension));
556 auto State = Data->second;
557 auto Ident = Data->first;
559 ConsumeAnnotationToken();
562 auto Name = Ident->getName();
567 if (
State == Disable) {
569 Opt.enableSupportedCore(
getLangOpts().OpenCLVersion);
571 PP.
Diag(NameLoc, diag::warn_pragma_expected_predicate) << 1;
574 if (!Opt.isKnown(
Name) ||
581 PP.
Diag(NameLoc, diag::warn_pragma_begin_end_mismatch);
583 }
else if (!Opt.isKnown(
Name))
584 PP.
Diag(NameLoc, diag::warn_pragma_unknown_extension) << Ident;
588 PP.
Diag(NameLoc, diag::warn_pragma_extension_is_core) << Ident;
590 PP.
Diag(NameLoc, diag::warn_pragma_unsupported_extension) << Ident;
593 void Parser::HandlePragmaMSPointersToMembers() {
594 assert(Tok.
is(tok::annot_pragma_ms_pointers_to_members));
602 void Parser::HandlePragmaMSVtorDisp() {
603 assert(Tok.
is(tok::annot_pragma_ms_vtordisp));
607 MSVtorDispAttr::Mode Mode = MSVtorDispAttr::Mode(Value & 0xFFFF);
612 void Parser::HandlePragmaMSPragma() {
613 assert(Tok.
is(tok::annot_pragma_ms_pragma));
617 PP.EnterTokenStream(std::move(TheTokens->first), TheTokens->second,
true);
626 PragmaHandler Handler = llvm::StringSwitch<PragmaHandler>(PragmaName)
627 .Case(
"data_seg", &Parser::HandlePragmaMSSegment)
628 .Case(
"bss_seg", &Parser::HandlePragmaMSSegment)
629 .Case(
"const_seg", &Parser::HandlePragmaMSSegment)
630 .Case(
"code_seg", &Parser::HandlePragmaMSSegment)
631 .Case(
"section", &Parser::HandlePragmaMSSection)
632 .Case(
"init_seg", &Parser::HandlePragmaMSInitSeg);
634 if (!(this->*Handler)(PragmaName, PragmaLocation)) {
643 bool Parser::HandlePragmaMSSection(StringRef PragmaName,
645 if (Tok.
isNot(tok::l_paren)) {
646 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
651 if (Tok.
isNot(tok::string_literal)) {
652 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_section_name)
656 ExprResult StringResult = ParseStringLiteralExpression();
661 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
666 bool SectionFlagsAreDefault =
true;
667 while (Tok.
is(tok::comma)) {
672 if (Tok.
is(tok::kw_long) || Tok.
is(tok::kw_short)) {
678 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_action_or_r_paren)
683 llvm::StringSwitch<ASTContext::PragmaSectionFlag>(
696 ? diag::warn_pragma_invalid_specific_action
697 : diag::warn_pragma_unsupported_action)
701 SectionFlags |= Flag;
702 SectionFlagsAreDefault =
false;
707 if (SectionFlagsAreDefault)
709 if (Tok.
isNot(tok::r_paren)) {
710 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
715 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
724 bool Parser::HandlePragmaMSSegment(StringRef PragmaName,
726 if (Tok.
isNot(tok::l_paren)) {
727 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_lparen) << PragmaName;
735 if (PushPop ==
"push")
737 else if (PushPop ==
"pop")
740 PP.
Diag(PragmaLocation,
741 diag::warn_pragma_expected_section_push_pop_or_name)
747 if (Tok.
is(tok::comma)) {
753 if (Tok.
is(tok::comma))
755 else if (Tok.
isNot(tok::r_paren)) {
756 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc)
761 }
else if (Tok.
isNot(tok::r_paren)) {
762 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_punc) << PragmaName;
769 if (Tok.
isNot(tok::r_paren)) {
770 if (Tok.
isNot(tok::string_literal)) {
772 diag::warn_pragma_expected_section_name :
773 diag::warn_pragma_expected_section_label_or_name :
774 diag::warn_pragma_expected_section_push_pop_or_name;
775 PP.
Diag(PragmaLocation, DiagID) << PragmaName;
778 ExprResult StringResult = ParseStringLiteralExpression();
781 SegmentName = cast<StringLiteral>(StringResult.
get());
783 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
791 if (Tok.
isNot(tok::r_paren)) {
792 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_rparen) << PragmaName;
797 PP.
Diag(PragmaLocation, diag::warn_pragma_extra_tokens_at_eol)
803 SegmentName, PragmaName);
808 bool Parser::HandlePragmaMSInitSeg(StringRef PragmaName,
810 if (
getTargetInfo().getTriple().getEnvironment() != llvm::Triple::MSVC) {
811 PP.
Diag(PragmaLocation, diag::warn_pragma_init_seg_unsupported_target);
815 if (ExpectAndConsume(tok::l_paren, diag::warn_pragma_expected_lparen,
823 StringRef Section = llvm::StringSwitch<StringRef>(II->getName())
824 .Case(
"compiler",
"\".CRT$XCC\"")
825 .Case(
"lib",
"\".CRT$XCL\"")
826 .Case(
"user",
"\".CRT$XCU\"")
829 if (!Section.empty()) {
833 Toks[0].
setKind(tok::string_literal);
841 }
else if (Tok.
is(tok::string_literal)) {
842 ExprResult StringResult = ParseStringLiteralExpression();
845 SegmentName = cast<StringLiteral>(StringResult.
get());
847 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_non_wide_string)
855 PP.
Diag(PragmaLocation, diag::warn_pragma_expected_init_seg) << PragmaName;
859 if (ExpectAndConsume(tok::r_paren, diag::warn_pragma_expected_rparen,
861 ExpectAndConsume(
tok::eof, diag::warn_pragma_extra_tokens_at_eol,
870 struct PragmaLoopHintInfo {
878 std::string PragmaString;
880 PragmaString =
"clang loop ";
884 "Unexpected pragma name");
885 PragmaString =
"unroll";
890 bool Parser::HandlePragmaLoopHint(
LoopHint &Hint) {
891 assert(Tok.
is(tok::annot_pragma_loop_hint));
892 PragmaLoopHintInfo *Info =
895 IdentifierInfo *PragmaNameInfo = Info->PragmaName.getIdentifierInfo();
897 Actions.
Context, Info->PragmaName.getLocation(), PragmaNameInfo);
902 ? Info->Option.getIdentifierInfo()
905 Actions.
Context, Info->Option.getLocation(), OptionInfo);
911 bool PragmaUnroll = PragmaNameInfo->
getName() ==
"unroll";
912 bool PragmaNoUnroll = PragmaNameInfo->
getName() ==
"nounroll";
913 if (Toks.empty() && (PragmaUnroll || PragmaNoUnroll)) {
914 ConsumeAnnotationToken();
915 Hint.
Range = Info->PragmaName.getLocation();
921 assert(!Toks.empty() &&
922 "PragmaLoopHintInfo::Toks must contain at least one token.");
925 bool OptionUnroll =
false;
926 bool OptionDistribute =
false;
927 bool StateOption =
false;
929 OptionUnroll = OptionInfo->isStr(
"unroll");
930 OptionDistribute = OptionInfo->isStr(
"distribute");
931 StateOption = llvm::StringSwitch<bool>(OptionInfo->getName())
932 .Case(
"vectorize",
true)
933 .Case(
"interleave",
true)
935 OptionUnroll || OptionDistribute;
938 bool AssumeSafetyArg = !OptionUnroll && !OptionDistribute;
941 ConsumeAnnotationToken();
942 Diag(Toks[0].getLocation(), diag::err_pragma_loop_missing_argument)
943 << StateOption << OptionUnroll
950 ConsumeAnnotationToken();
954 bool Valid = StateInfo &&
955 llvm::StringSwitch<bool>(StateInfo->
getName())
956 .Cases(
"enable",
"disable",
true)
957 .Case(
"full", OptionUnroll)
958 .Case(
"assume_safety", AssumeSafetyArg)
961 Diag(Toks[0].getLocation(), diag::err_pragma_invalid_keyword)
972 PP.EnterTokenStream(Toks,
false);
973 ConsumeAnnotationToken();
997 Info->Toks.back().getLocation());
1002 struct PragmaAttributeInfo {
1003 enum ActionType { Push, Pop };
1008 PragmaAttributeInfo(
ParsedAttributes &Attributes) : Attributes(Attributes) {}
1011 #include "clang/Parse/AttrSubMatchRulesParserStringSwitches.inc"
1016 if (Tok.
is(tok::identifier))
1025 using namespace attr;
1027 #define ATTR_MATCH_RULE(Value, Spelling, IsAbstract) \
1030 #include "clang/Basic/AttrSubMatchRulesList.inc"
1032 llvm_unreachable(
"Invalid attribute subject match rule");
1040 PRef.
Diag(SubRuleLoc,
1041 diag::err_pragma_attribute_expected_subject_sub_identifier)
1043 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1054 PRef.
Diag(SubRuleLoc, diag::err_pragma_attribute_unknown_subject_sub_rule)
1055 << SubRuleName << PrimaryRuleName;
1056 if (
const char *SubRules = validAttributeSubjectMatchSubRules(PrimaryRule))
1062 bool Parser::ParsePragmaAttributeSubjectMatchRuleSet(
1070 if (AnyParens.expectAndConsume())
1078 Diag(Tok, diag::err_pragma_attribute_expected_subject_identifier);
1081 std::pair<Optional<attr::SubjectMatchRule>,
1083 Rule = isAttributeSubjectMatchRule(Name);
1085 Diag(Tok, diag::err_pragma_attribute_unknown_subject_rule) <<
Name;
1093 if (Parens.expectAndConsume())
1095 }
else if (Parens.consumeOpen()) {
1096 if (!SubjectMatchRules
1098 std::make_pair(PrimaryRule,
SourceRange(RuleLoc, RuleLoc)))
1100 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1103 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleLoc));
1104 LastMatchRuleEndLoc = RuleLoc;
1110 if (SubRuleName.empty()) {
1116 if (SubRuleName ==
"unless") {
1119 if (Parens.expectAndConsume())
1122 if (SubRuleName.empty()) {
1127 auto SubRuleOrNone = Rule.second(SubRuleName,
true);
1128 if (!SubRuleOrNone) {
1129 std::string SubRuleUnlessName =
"unless(" + SubRuleName.str() +
")";
1131 SubRuleUnlessName, SubRuleLoc);
1134 SubRule = *SubRuleOrNone;
1136 if (Parens.consumeClose())
1139 auto SubRuleOrNone = Rule.second(SubRuleName,
false);
1140 if (!SubRuleOrNone) {
1145 SubRule = *SubRuleOrNone;
1149 LastMatchRuleEndLoc = RuleEndLoc;
1150 if (Parens.consumeClose())
1152 if (!SubjectMatchRules
1153 .insert(std::make_pair(SubRule,
SourceRange(RuleLoc, RuleEndLoc)))
1155 Diag(RuleLoc, diag::err_pragma_attribute_duplicate_subject)
1158 RuleLoc, Tok.
is(tok::comma) ? Tok.
getLocation() : RuleEndLoc));
1164 if (AnyParens.consumeClose())
1182 getAttributeSubjectRulesRecoveryPointForToken(
const Token &Tok) {
1184 if (II->isStr(
"apply_to"))
1185 return MissingAttributeSubjectRulesRecoveryPoint::ApplyTo;
1186 if (II->isStr(
"any"))
1187 return MissingAttributeSubjectRulesRecoveryPoint::Any;
1189 if (Tok.
is(tok::equal))
1190 return MissingAttributeSubjectRulesRecoveryPoint::Equals;
1206 getAttributeSubjectRulesRecoveryPointForToken(PRef.
getCurToken());
1209 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::ApplyTo &&
1210 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::ApplyTo)
1211 FixIt +=
"apply_to";
1212 if (Point <= MissingAttributeSubjectRulesRecoveryPoint::Equals &&
1213 EndPoint > MissingAttributeSubjectRulesRecoveryPoint::Equals)
1220 if (SubjectMatchRuleSet.empty()) {
1226 bool NeedsComma =
false;
1227 for (
const auto &
I : SubjectMatchRuleSet) {
1243 if (FixItRange.getBegin() == FixItRange.getEnd())
1253 void Parser::HandlePragmaAttribute() {
1254 assert(Tok.
is(tok::annot_pragma_attribute) &&
1255 "Expected #pragma attribute annotation token");
1258 if (Info->Action == PragmaAttributeInfo::Pop) {
1259 ConsumeAnnotationToken();
1264 assert(Info->Action == PragmaAttributeInfo::Push &&
1265 "Unexpected #pragma attribute command");
1266 PP.EnterTokenStream(Info->Tokens,
false);
1267 ConsumeAnnotationToken();
1272 auto SkipToEnd = [
this]() {
1277 if (Tok.
is(tok::l_square) &&
NextToken().
is(tok::l_square)) {
1279 ParseCXX11AttributeSpecifier(Attrs);
1280 }
else if (Tok.
is(tok::kw___attribute)) {
1282 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
1285 if (ExpectAndConsume(tok::l_paren, diag::err_expected_lparen_after,
"("))
1288 if (Tok.
isNot(tok::identifier)) {
1289 Diag(Tok, diag::err_pragma_attribute_expected_attribute_name);
1296 if (Tok.
isNot(tok::l_paren))
1297 Attrs.
addNew(AttrName, AttrNameLoc,
nullptr, AttrNameLoc,
nullptr, 0,
1300 ParseGNUAttributeArgs(AttrName, AttrNameLoc, Attrs,
nullptr,
1306 if (ExpectAndConsume(tok::r_paren))
1308 if (ExpectAndConsume(tok::r_paren))
1310 }
else if (Tok.
is(tok::kw___declspec)) {
1311 ParseMicrosoftDeclSpecs(Attrs);
1313 Diag(Tok, diag::err_pragma_attribute_expected_attribute_syntax);
1322 if (Tok.
is(tok::l_paren)) {
1325 if (Tok.
isNot(tok::r_paren))
1328 Diag(Tok, diag::note_pragma_attribute_use_attribute_kw)
1345 Diag(Loc, diag::err_pragma_attribute_multiple_attributes);
1351 Diag(PragmaLoc, diag::err_pragma_attribute_unsupported_attribute)
1360 createExpectedAttributeSubjectRulesTokenDiagnostic(
1361 diag::err_expected, Attribute,
1368 if (Tok.
isNot(tok::identifier)) {
1369 createExpectedAttributeSubjectRulesTokenDiagnostic(
1370 diag::err_pragma_attribute_invalid_subject_set_specifier, Attribute,
1371 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
1376 if (!II->
isStr(
"apply_to")) {
1377 createExpectedAttributeSubjectRulesTokenDiagnostic(
1378 diag::err_pragma_attribute_invalid_subject_set_specifier, Attribute,
1379 MissingAttributeSubjectRulesRecoveryPoint::ApplyTo, *
this);
1386 createExpectedAttributeSubjectRulesTokenDiagnostic(
1387 diag::err_expected, Attribute,
1388 MissingAttributeSubjectRulesRecoveryPoint::Equals, *
this)
1396 if (ParsePragmaAttributeSubjectMatchRuleSet(SubjectMatchRules, AnyLoc,
1397 LastMatchRuleEndLoc)) {
1405 Diag(Tok, diag::err_pragma_attribute_extra_tokens_after_attribute);
1414 std::move(SubjectMatchRules));
1420 void PragmaGCCVisibilityHandler::HandlePragma(
Preprocessor &PP,
1431 if (PushPop && PushPop->
isStr(
"pop")) {
1433 }
else if (PushPop && PushPop->
isStr(
"push")) {
1435 if (Tok.
isNot(tok::l_paren)) {
1448 if (Tok.
isNot(tok::r_paren)) {
1460 if (Tok.
isNot(tok::eod)) {
1466 auto Toks = llvm::make_unique<Token[]>(1);
1467 Toks[0].startToken();
1468 Toks[0].setKind(tok::annot_pragma_vis);
1469 Toks[0].setLocation(VisLoc);
1470 Toks[0].setAnnotationEndLoc(EndLoc);
1471 Toks[0].setAnnotationValue(
1472 const_cast<void*>(static_cast<const void*>(VisType)));
1473 PP.EnterTokenStream(std::move(Toks), 1,
true);
1487 if (Tok.
isNot(tok::l_paren)) {
1488 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"pack";
1493 StringRef SlotLabel;
1497 if (Tok.
is(tok::numeric_constant)) {
1507 }
else if (Tok.
is(tok::identifier)) {
1509 if (II->
isStr(
"show")) {
1513 if (II->
isStr(
"push")) {
1515 }
else if (II->
isStr(
"pop")) {
1518 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_invalid_action) <<
"pack";
1523 if (Tok.
is(tok::comma)) {
1526 if (Tok.
is(tok::numeric_constant)) {
1531 }
else if (Tok.
is(tok::identifier)) {
1535 if (Tok.
is(tok::comma)) {
1538 if (Tok.
isNot(tok::numeric_constant)) {
1561 if (Tok.
isNot(tok::r_paren)) {
1562 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_rparen) <<
"pack";
1568 if (Tok.
isNot(tok::eod)) {
1569 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"pack";
1573 PragmaPackInfo *Info =
1576 Info->SlotLabel = SlotLabel;
1577 Info->Alignment = Alignment;
1581 Toks[0].startToken();
1582 Toks[0].setKind(tok::annot_pragma_pack);
1583 Toks[0].setLocation(PackLoc);
1584 Toks[0].setAnnotationEndLoc(RParenLoc);
1585 Toks[0].setAnnotationValue(static_cast<void*>(Info));
1586 PP.EnterTokenStream(Toks,
true);
1591 void PragmaMSStructHandler::HandlePragma(
Preprocessor &PP,
1593 Token &MSStructTok) {
1598 if (Tok.
isNot(tok::identifier)) {
1604 if (II->
isStr(
"on")) {
1608 else if (II->
isStr(
"off") || II->
isStr(
"reset"))
1615 if (Tok.
isNot(tok::eod)) {
1623 Toks[0].startToken();
1624 Toks[0].setKind(tok::annot_pragma_msstruct);
1626 Toks[0].setAnnotationEndLoc(EndLoc);
1627 Toks[0].setAnnotationValue(reinterpret_cast<void*>(
1628 static_cast<uintptr_t>(Kind)));
1629 PP.EnterTokenStream(Toks,
true);
1633 void PragmaClangSectionHandler::HandlePragma(
Preprocessor &PP,
1637 auto SecKind = Sema::PragmaClangSectionKind::PCSK_Invalid;
1640 while (Tok.
isNot(tok::eod)) {
1641 if (Tok.
isNot(tok::identifier)) {
1642 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
1647 if (SecType->
isStr(
"bss"))
1648 SecKind = Sema::PragmaClangSectionKind::PCSK_BSS;
1649 else if (SecType->
isStr(
"data"))
1650 SecKind = Sema::PragmaClangSectionKind::PCSK_Data;
1651 else if (SecType->
isStr(
"rodata"))
1652 SecKind = Sema::PragmaClangSectionKind::PCSK_Rodata;
1653 else if (SecType->
isStr(
"text"))
1654 SecKind = Sema::PragmaClangSectionKind::PCSK_Text;
1656 PP.
Diag(Tok.
getLocation(), diag::err_pragma_expected_clang_section_name) <<
"clang section";
1661 if (Tok.
isNot(tok::equal)) {
1662 PP.
Diag(Tok.
getLocation(), diag::err_pragma_clang_section_expected_equal) << SecKind;
1666 std::string SecName;
1670 Actions.ActOnPragmaClangSection(Tok.
getLocation(),
1671 (SecName.size()? Sema::PragmaClangSectionAction::PCSA_Set :
1672 Sema::PragmaClangSectionAction::PCSA_Clear),
1685 if (Tok.
isNot(tok::identifier) ||
1693 if (Tok.
isNot(tok::equal)) {
1700 if (Tok.
isNot(tok::identifier)) {
1702 << (IsOptions ?
"options" :
"align");
1708 if (II->
isStr(
"native"))
1710 else if (II->
isStr(
"natural"))
1712 else if (II->
isStr(
"packed"))
1714 else if (II->
isStr(
"power"))
1716 else if (II->
isStr(
"mac68k"))
1718 else if (II->
isStr(
"reset"))
1728 if (Tok.
isNot(tok::eod)) {
1730 << (IsOptions ?
"options" :
"align");
1736 Toks[0].startToken();
1737 Toks[0].setKind(tok::annot_pragma_align);
1739 Toks[0].setAnnotationEndLoc(EndLoc);
1740 Toks[0].setAnnotationValue(reinterpret_cast<void*>(
1741 static_cast<uintptr_t>(Kind)));
1742 PP.EnterTokenStream(Toks,
true);
1745 void PragmaAlignHandler::HandlePragma(
Preprocessor &PP,
1751 void PragmaOptionsHandler::HandlePragma(
Preprocessor &PP,
1753 Token &OptionsTok) {
1758 void PragmaUnusedHandler::HandlePragma(
Preprocessor &PP,
1767 if (Tok.
isNot(tok::l_paren)) {
1768 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_lparen) <<
"unused";
1781 if (Tok.
is(tok::identifier)) {
1782 Identifiers.push_back(Tok);
1793 if (Tok.
is(tok::comma)) {
1798 if (Tok.
is(tok::r_paren)) {
1804 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_punc) <<
"unused";
1809 if (Tok.
isNot(tok::eod)) {
1816 assert(RParenLoc.
isValid() &&
"Valid '#pragma unused' must have ')'");
1817 assert(!Identifiers.empty() &&
"Valid '#pragma unused' must have arguments");
1826 2 * Identifiers.size());
1827 for (
unsigned i=0; i != Identifiers.size(); i++) {
1828 Token &pragmaUnusedTok = Toks[2*i], &idTok = Toks[2*i+1];
1830 pragmaUnusedTok.
setKind(tok::annot_pragma_unused);
1832 idTok = Identifiers[i];
1834 PP.EnterTokenStream(Toks,
true);
1846 if (Tok.
isNot(tok::identifier)) {
1847 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_identifier) <<
"weak";
1851 Token WeakName = Tok;
1852 bool HasAlias =
false;
1856 if (Tok.
is(tok::equal)) {
1859 if (Tok.
isNot(tok::identifier)) {
1868 if (Tok.
isNot(tok::eod)) {
1869 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_extra_tokens_at_eol) <<
"weak";
1876 Token &pragmaUnusedTok = Toks[0];
1878 pragmaUnusedTok.
setKind(tok::annot_pragma_weakalias);
1882 Toks[2] = AliasName;
1883 PP.EnterTokenStream(Toks,
true);
1887 Token &pragmaUnusedTok = Toks[0];
1889 pragmaUnusedTok.
setKind(tok::annot_pragma_weak);
1893 PP.EnterTokenStream(Toks,
true);
1898 void PragmaRedefineExtnameHandler::HandlePragma(
Preprocessor &PP,
1900 Token &RedefToken) {
1905 if (Tok.
isNot(tok::identifier)) {
1911 Token RedefName = Tok;
1914 if (Tok.
isNot(tok::identifier)) {
1916 <<
"redefine_extname";
1920 Token AliasName = Tok;
1923 if (Tok.
isNot(tok::eod)) {
1931 Token &pragmaRedefTok = Toks[0];
1933 pragmaRedefTok.
setKind(tok::annot_pragma_redefine_extname);
1936 Toks[1] = RedefName;
1937 Toks[2] = AliasName;
1938 PP.EnterTokenStream(Toks,
true);
1943 PragmaFPContractHandler::HandlePragma(
Preprocessor &PP,
1952 Toks[0].startToken();
1953 Toks[0].setKind(tok::annot_pragma_fp_contract);
1956 Toks[0].setAnnotationValue(reinterpret_cast<void*>(
1957 static_cast<uintptr_t>(OOS)));
1958 PP.EnterTokenStream(Toks,
true);
1962 PragmaOpenCLExtensionHandler::HandlePragma(
Preprocessor &PP,
1966 if (Tok.
isNot(tok::identifier)) {
1975 if (Tok.
isNot(tok::colon)) {
1981 if (Tok.
isNot(tok::identifier)) {
1982 PP.
Diag(Tok.
getLocation(), diag::warn_pragma_expected_predicate) << 0;
1988 if (Pred->
isStr(
"enable")) {
1990 }
else if (Pred->
isStr(
"disable")) {
1992 }
else if (Pred->
isStr(
"begin"))
1994 else if (Pred->
isStr(
"end"))
1998 << Ext->
isStr(
"all");
2004 if (Tok.
isNot(tok::eod)) {
2012 Info->second =
State;
2015 Toks[0].startToken();
2016 Toks[0].setKind(tok::annot_pragma_opencl_extension);
2017 Toks[0].setLocation(NameLoc);
2018 Toks[0].setAnnotationValue(static_cast<void*>(Info));
2019 Toks[0].setAnnotationEndLoc(StateLoc);
2020 PP.EnterTokenStream(Toks,
true);
2035 PP.
Diag(FirstTok, diag::warn_pragma_omp_ignored);
2051 Tok.
setKind(tok::annot_pragma_openmp);
2054 while (Tok.
isNot(tok::eod)) {
2055 Pragma.push_back(Tok);
2060 Tok.
setKind(tok::annot_pragma_openmp_end);
2062 Pragma.push_back(Tok);
2064 auto Toks = llvm::make_unique<Token[]>(Pragma.size());
2065 std::copy(Pragma.begin(), Pragma.end(), Toks.get());
2066 PP.EnterTokenStream(std::move(Toks), Pragma.size(),
2078 void PragmaMSPointersToMembers::HandlePragma(
Preprocessor &PP,
2083 if (Tok.
isNot(tok::l_paren)) {
2084 PP.
Diag(PointersToMembersLoc, diag::warn_pragma_expected_lparen)
2085 <<
"pointers_to_members";
2092 <<
"pointers_to_members";
2098 if (Arg->
isStr(
"best_case")) {
2101 if (Arg->
isStr(
"full_generality")) {
2102 if (Tok.
is(tok::comma)) {
2108 diag::err_pragma_pointers_to_members_unknown_kind)
2113 }
else if (Tok.
is(tok::r_paren)) {
2120 <<
"full_generality";
2126 if (Arg->
isStr(
"single_inheritance")) {
2127 RepresentationMethod =
2129 }
else if (Arg->
isStr(
"multiple_inheritance")) {
2130 RepresentationMethod =
2132 }
else if (Arg->
isStr(
"virtual_inheritance")) {
2133 RepresentationMethod =
2137 diag::err_pragma_pointers_to_members_unknown_kind)
2144 if (Tok.
isNot(tok::r_paren)) {
2146 << (Arg ? Arg->
getName() :
"full_generality");
2152 if (Tok.
isNot(tok::eod)) {
2154 <<
"pointers_to_members";
2160 AnnotTok.
setKind(tok::annot_pragma_ms_pointers_to_members);
2164 reinterpret_cast<void *>(static_cast<uintptr_t>(RepresentationMethod)));
2181 if (Tok.
isNot(tok::l_paren)) {
2182 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_lparen) <<
"vtordisp";
2190 if (II->
isStr(
"push")) {
2193 if (Tok.
isNot(tok::comma)) {
2194 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_punc) <<
"vtordisp";
2200 }
else if (II->
isStr(
"pop")) {
2207 if (Tok.
is(tok::r_paren)) {
2217 if (II && II->
isStr(
"off")) {
2220 }
else if (II && II->
isStr(
"on")) {
2223 }
else if (Tok.
is(tok::numeric_constant) &&
2227 << 0 << 2 <<
"vtordisp";
2238 if (Tok.
isNot(tok::r_paren)) {
2239 PP.
Diag(VtorDispLoc, diag::warn_pragma_expected_rparen) <<
"vtordisp";
2244 if (Tok.
isNot(tok::eod)) {
2253 AnnotTok.
setKind(tok::annot_pragma_ms_vtordisp);
2257 static_cast<uintptr_t>((Action << 16) | (Value & 0xFFFF))));
2266 Token EoF, AnnotTok;
2270 AnnotTok.
setKind(tok::annot_pragma_ms_pragma);
2275 for (; Tok.
isNot(tok::eod); PP.
Lex(Tok)) {
2276 TokenVector.push_back(Tok);
2280 TokenVector.push_back(EoF);
2283 auto TokenArray = llvm::make_unique<Token[]>(TokenVector.size());
2284 std::copy(TokenVector.begin(), TokenVector.end(), TokenArray.get());
2286 std::pair<std::unique_ptr<
Token[]>,
size_t>(std::move(TokenArray),
2287 TokenVector.size());
2302 void PragmaDetectMismatchHandler::HandlePragma(
Preprocessor &PP,
2307 if (Tok.
isNot(tok::l_paren)) {
2308 PP.
Diag(DetectMismatchLoc, diag::err_expected) << tok::l_paren;
2313 std::string NameString;
2315 "pragma detect_mismatch",
2320 std::string ValueString;
2321 if (Tok.
isNot(tok::comma)) {
2322 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
2330 if (Tok.
isNot(tok::r_paren)) {
2336 if (Tok.
isNot(tok::eod)) {
2337 PP.
Diag(Tok.
getLocation(), diag::err_pragma_detect_mismatch_malformed);
2346 Actions.ActOnPragmaDetectMismatch(DetectMismatchLoc, NameString, ValueString);
2358 void PragmaCommentHandler::HandlePragma(
Preprocessor &PP,
2363 if (Tok.
isNot(tok::l_paren)) {
2364 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
2370 if (Tok.
isNot(tok::identifier)) {
2371 PP.
Diag(CommentLoc, diag::err_pragma_comment_malformed);
2378 llvm::StringSwitch<PragmaMSCommentKind>(II->
getName())
2400 std::string ArgumentString;
2413 if (Tok.
isNot(tok::r_paren)) {
2419 if (Tok.
isNot(tok::eod)) {
2428 Actions.ActOnPragmaMSComment(CommentLoc, Kind, ArgumentString);
2433 void PragmaOptimizeHandler::HandlePragma(
Preprocessor &PP,
2435 Token &FirstToken) {
2438 if (Tok.
is(tok::eod)) {
2440 <<
"clang optimize" <<
true <<
"'on' or 'off'";
2443 if (Tok.
isNot(tok::identifier)) {
2444 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
2451 if (II->
isStr(
"on")) {
2453 }
else if (!II->
isStr(
"off")) {
2454 PP.
Diag(Tok.
getLocation(), diag::err_pragma_optimize_invalid_argument)
2460 if (Tok.
isNot(tok::eod)) {
2466 Actions.ActOnPragmaOptimize(IsOn, FirstToken.
getLocation());
2471 struct TokFPAnnotValue {
2472 enum FlagKinds { Contract };
2473 enum FlagValues { On, Off, Fast };
2476 FlagValues FlagValue;
2484 Token PragmaName = Tok;
2488 if (Tok.
isNot(tok::identifier)) {
2494 while (Tok.
is(tok::identifier)) {
2498 llvm::StringSwitch<llvm::Optional<TokFPAnnotValue::FlagKinds>>(
2500 .Case(
"contract", TokFPAnnotValue::Contract)
2504 <<
false << OptionInfo;
2510 if (Tok.
isNot(tok::l_paren)) {
2516 if (Tok.
isNot(tok::identifier)) {
2524 llvm::StringSwitch<llvm::Optional<TokFPAnnotValue::FlagValues>>(
2526 .Case(
"on", TokFPAnnotValue::On)
2527 .Case(
"off", TokFPAnnotValue::Off)
2528 .Case(
"fast", TokFPAnnotValue::Fast)
2539 if (Tok.
isNot(tok::r_paren)) {
2546 TokFPAnnotValue{*FlagKind, *FlagValue};
2550 FPTok.
setKind(tok::annot_pragma_fp);
2554 TokenList.push_back(FPTok);
2557 if (Tok.
isNot(tok::eod)) {
2563 auto TokenArray = llvm::make_unique<Token[]>(TokenList.size());
2564 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
2566 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
2570 void Parser::HandlePragmaFP() {
2571 assert(Tok.
is(tok::annot_pragma_fp));
2576 switch (AnnotValue->FlagValue) {
2577 case TokFPAnnotValue::On:
2580 case TokFPAnnotValue::Fast:
2583 case TokFPAnnotValue::Off:
2589 ConsumeAnnotationToken();
2594 Token Option,
bool ValueInParens,
2595 PragmaLoopHintInfo &Info) {
2597 int OpenParens = ValueInParens ? 1 : 0;
2599 while (Tok.
isNot(tok::eod)) {
2600 if (Tok.
is(tok::l_paren))
2602 else if (Tok.
is(tok::r_paren)) {
2604 if (OpenParens == 0 && ValueInParens)
2608 ValueList.push_back(Tok);
2612 if (ValueInParens) {
2614 if (Tok.
isNot(tok::r_paren)) {
2625 ValueList.push_back(EOFTok);
2629 Info.PragmaName = PragmaName;
2630 Info.Option = Option;
2679 void PragmaLoopHintHandler::HandlePragma(
Preprocessor &PP,
2683 Token PragmaName = Tok;
2688 if (Tok.
isNot(tok::identifier)) {
2694 while (Tok.
is(tok::identifier)) {
2698 bool OptionValid = llvm::StringSwitch<bool>(OptionInfo->
getName())
2699 .Case(
"vectorize",
true)
2700 .Case(
"interleave",
true)
2701 .Case(
"unroll",
true)
2702 .Case(
"distribute",
true)
2703 .Case(
"vectorize_width",
true)
2704 .Case(
"interleave_count",
true)
2705 .Case(
"unroll_count",
true)
2709 <<
false << OptionInfo;
2715 if (Tok.
isNot(tok::l_paren)) {
2729 LoopHintTok.
setKind(tok::annot_pragma_loop_hint);
2733 TokenList.push_back(LoopHintTok);
2736 if (Tok.
isNot(tok::eod)) {
2742 auto TokenArray = llvm::make_unique<Token[]>(TokenList.size());
2743 std::copy(TokenList.begin(), TokenList.end(), TokenArray.get());
2745 PP.EnterTokenStream(std::move(TokenArray), TokenList.size(),
2766 void PragmaUnrollHintHandler::HandlePragma(
Preprocessor &PP,
2771 Token PragmaName = Tok;
2774 if (Tok.
is(tok::eod)) {
2776 Info->PragmaName = PragmaName;
2777 Info->Option.startToken();
2786 bool ValueInParens = Tok.
is(tok::l_paren);
2798 PP.
Diag(Info->Toks[0].getLocation(),
2799 diag::warn_pragma_unroll_cuda_value_in_parens);
2801 if (Tok.
isNot(tok::eod)) {
2809 auto TokenArray = llvm::make_unique<Token[]>(1);
2810 TokenArray[0].startToken();
2811 TokenArray[0].setKind(tok::annot_pragma_loop_hint);
2812 TokenArray[0].setLocation(PragmaName.
getLocation());
2813 TokenArray[0].setAnnotationEndLoc(PragmaName.
getLocation());
2814 TokenArray[0].setAnnotationValue(static_cast<void *>(Info));
2815 PP.EnterTokenStream(std::move(TokenArray), 1,
2831 void PragmaMSIntrinsicHandler::HandlePragma(
Preprocessor &PP,
2836 if (Tok.
isNot(tok::l_paren)) {
2845 while (Tok.
is(tok::identifier)) {
2849 << II << SuggestIntrinH;
2852 if (Tok.
isNot(tok::comma))
2857 if (Tok.
isNot(tok::r_paren)) {
2864 if (Tok.
isNot(tok::eod))
2868 void PragmaForceCUDAHostDeviceHandler::HandlePragma(
2870 Token FirstTok = Tok;
2874 if (!Info || (!Info->
isStr(
"begin") && !Info->
isStr(
"end"))) {
2876 diag::warn_pragma_force_cuda_host_device_bad_arg);
2880 if (Info->
isStr(
"begin"))
2881 Actions.PushForceCUDAHostDevice();
2882 else if (!Actions.PopForceCUDAHostDevice())
2884 diag::err_pragma_cannot_end_force_cuda_host_device);
2887 if (!Tok.
is(tok::eod))
2889 diag::warn_pragma_force_cuda_host_device_bad_arg);
2907 void PragmaAttributeHandler::HandlePragma(
Preprocessor &PP,
2909 Token &FirstToken) {
2913 PragmaAttributeInfo(AttributesForPragmaAttribute);
2916 if (Tok.
isNot(tok::identifier)) {
2917 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_push_pop);
2921 if (II->
isStr(
"push"))
2922 Info->Action = PragmaAttributeInfo::Push;
2924 Info->Action = PragmaAttributeInfo::Pop;
2926 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_invalid_argument)
2933 if (Info->Action == PragmaAttributeInfo::Push) {
2934 if (Tok.
isNot(tok::l_paren)) {
2943 while (Tok.
isNot(tok::eod)) {
2944 if (Tok.
is(tok::l_paren))
2946 else if (Tok.
is(tok::r_paren)) {
2948 if (OpenParens == 0)
2952 AttributeTokens.push_back(Tok);
2956 if (AttributeTokens.empty()) {
2957 PP.
Diag(Tok.
getLocation(), diag::err_pragma_attribute_expected_attribute);
2960 if (Tok.
isNot(tok::r_paren)) {
2972 AttributeTokens.push_back(EOFTok);
2978 if (Tok.
isNot(tok::eod))
2980 <<
"clang attribute";
2983 auto TokenArray = llvm::make_unique<Token[]>(1);
2984 TokenArray[0].startToken();
2985 TokenArray[0].setKind(tok::annot_pragma_attribute);
2986 TokenArray[0].setLocation(FirstToken.
getLocation());
2987 TokenArray[0].setAnnotationEndLoc(FirstToken.
getLocation());
2988 TokenArray[0].setAnnotationValue(static_cast<void *>(Info));
2989 PP.EnterTokenStream(std::move(TokenArray), 1,
Defines the clang::ASTContext interface.
IdentifierLoc * PragmaNameLoc
bool isSupportedByPragmaAttribute() const
llvm::BumpPtrAllocator & getPreprocessorAllocator()
bool CheckLoopHintExpr(Expr *E, SourceLocation Loc)
void ActOnPragmaMSStruct(PragmaMSStructKind Kind)
ActOnPragmaMSStruct - Called on well formed #pragma ms_struct [on|off].
void ActOnPragmaWeakAlias(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaWeakAlias - Called on well formed #pragma weak ident = ident.
SourceLocation getEndOfPreviousToken()
void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, CapturedRegionKind Kind, unsigned NumParams)
const Token & getCurToken() const
const LangOptions & getLangOpts() const
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.
const SourceLocation Point
void AddPragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Add the specified pragma handler to this preprocessor.
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.
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.
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...
void getMatchRules(const LangOptions &LangOpts, SmallVectorImpl< std::pair< attr::SubjectMatchRule, bool >> &MatchRules) const
void setCurrentOpenCLExtension(llvm::StringRef Ext)
void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, SourceLocation PragmaLoc, MSVtorDispAttr::Mode Value)
Called on well formed #pragma vtordisp().
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
This indicates that the scope corresponds to a function, which means that labels are set here...
Parser - This implements a parser for the C family of languages.
static IdentifierLoc * create(ASTContext &Ctx, SourceLocation Loc, IdentifierInfo *Ident)
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
static void diagnoseUnknownAttributeSubjectSubRule(Parser &PRef, attr::SubjectMatchRule PrimaryRule, StringRef PrimaryRuleName, StringRef SubRuleName, SourceLocation SubRuleLoc)
static std::string PragmaLoopHintString(Token PragmaName, Token Option)
IdentifierLoc * OptionLoc
bool isAnyIdentifier() const
Return true if this is a raw identifier (when lexing in raw mode) or a non-keyword identifier (when l...
OpenCLOptions & getOpenCLOptions()
Parse and apply any fixits to the source.
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 ...
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 & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
bool TryConsumeToken(tok::TokenKind Expected)
One of these records is kept for each identifier that is lexed.
SubjectMatchRule
A list of all the recognized kinds of attributes.
AttributeList * getList() const
const LangOptions & getLangOpts() const
Token - This structure provides full information about a lexed token.
void setKind(tok::TokenKind K)
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ...
MissingAttributeSubjectRulesRecoveryPoint
Describes the stage at which attribute subject rule parsing was interruped.
const TargetInfo & getTargetInfo() const
void ActOnPragmaMSSection(SourceLocation PragmaLocation, int SectionFlags, StringLiteral *SegmentName)
Called on well formed #pragma section().
const char * getKeywordSpelling(TokenKind Kind) LLVM_READNONE
Determines the spelling of simple keyword and contextual keyword tokens like 'int' and 'dynamic_cast'...
unsigned getLength() const
void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, SourceLocation PragmaLoc)
ActOnPragmaOptionsAlign - Called on well formed #pragma options align.
void ActOnPragmaAttributePop(SourceLocation PragmaLoc)
Called on well-formed '#pragma clang attribute pop'.
void ActOnPragmaFPContract(LangOptions::FPContractModeKind FPC)
ActOnPragmaFPContract - Called on well formed #pragma {STDC,OPENCL} FP_CONTRACT and #pragma clang fp ...
tok::TokenKind getKind() const
const TargetInfo & getTargetInfo() const
ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope=nullptr)
detail::InMemoryDirectory::const_iterator I
PragmaIntroducerKind
Describes how the pragma was introduced, e.g., with #pragma, _Pragma, or __pragma.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
void * getAnnotationValue() const
Sema - This implements semantic analysis and AST building for C.
A little helper class used to produce diagnostics.
EmptyPragmaHandler - A pragma handler which takes no action, which can be used to ignore particular p...
void setAnnotationValue(void *val)
StringRef getName() const
Return the actual identifier string.
void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, StringLiteral *SegmentName)
Called on well-formed #pragma init_seg().
bool LexOnOffSwitch(tok::OnOffSwitch &OOS)
Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD.
Defines the clang::Preprocessor interface.
void RemovePragmaHandler(StringRef Namespace, PragmaHandler *Handler)
Remove the specific pragma handler from this preprocessor.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
void ActOnPragmaUnused(const Token &Identifier, Scope *curScope, SourceLocation PragmaLoc)
ActOnPragmaUnused - Called on well-formed '#pragma unused'.
bool isNot(tok::TokenKind K) const
llvm::StringRef getCurrentOpenCLExtension() const
static bool isAbstractAttrMatcherRule(attr::SubjectMatchRule Rule)
virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, StringRef Str)
Callback invoked when a #pragma comment directive is read.
static StringRef getIdentifier(const Token &Tok)
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
static CharSourceRange getCharRange(SourceRange R)
static void ParseAlignPragma(Preprocessor &PP, Token &FirstTok, bool IsOptions)
Encodes a location in the source.
const char * getSubjectMatchRuleSpelling(SubjectMatchRule Rule)
void setLength(unsigned Len)
void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, StringRef SlotLabel, Expr *Alignment)
ActOnPragmaPack - Called on well formed #pragma pack(...).
SourceLocation getEndLoc() const
void ActOnPragmaWeakID(IdentifierInfo *WeakName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc)
ActOnPragmaWeakID - Called on well formed #pragma weak ident.
bool isValid() const
Return true if this is a valid SourceLocation object.
void setAnnotationEndLoc(SourceLocation L)
Scope * getCurScope() const
StmtResult ActOnCapturedRegionEnd(Stmt *S)
void Lex(Token &Result)
Lex the next token for this preprocessor.
ArrayRef< FormatToken * > Tokens
unsigned getCharByteWidth() const
PPCallbacks * getPPCallbacks() const
Accessors for preprocessor callbacks.
PragmaMSPointersToMembersKind
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)) {...
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
DiagnosticsEngine & getDiagnostics() const
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
bool isMacroDefined(StringRef Id)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T-> getSizeExpr()))
void ActOnCapturedRegionError()
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
virtual void PragmaDetectMismatch(SourceLocation Loc, StringRef Name, StringRef Value)
Callback invoked when a #pragma detect_mismatch directive is read.
PragmaHandler - Instances of this interface defined to handle the various pragmas that the language f...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
static void diagnoseExpectedAttributeSubjectSubRule(Parser &PRef, attr::SubjectMatchRule PrimaryRule, StringRef PrimaryRuleName, SourceLocation SubRuleLoc)
void setLiteralData(const char *Ptr)
OnOffSwitch
Defines the possible values of an on-off-switch (C99 6.10.6p2).
IdentifierInfo * getName() const
void ActOnPragmaMSPointersToMembers(LangOptions::PragmaMSPointersToMembersKind Kind, SourceLocation PragmaLoc)
ActOnPragmaMSPointersToMembers - called on well formed #pragma pointers_to_members(representation met...
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
void setSeverity(diag::kind Diag, diag::Severity Map, SourceLocation Loc)
This allows the client to specify that certain warnings are ignored.
ActionResult< Stmt * > StmtResult
void ActOnPragmaRedefineExtname(IdentifierInfo *WeakName, IdentifierInfo *AliasName, SourceLocation PragmaLoc, SourceLocation WeakNameLoc, SourceLocation AliasNameLoc)
ActOnPragmaRedefineExtname - Called on well formed #pragma redefine_extname oldname newname...
SourceLocation getLoc() const
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.
AttributeList * addNew(IdentifierInfo *attrName, SourceRange attrRange, IdentifierInfo *scopeName, SourceLocation scopeLoc, ArgsUnion *args, unsigned numArgs, AttributeList::Syntax syntax, SourceLocation ellipsisLoc=SourceLocation())
Add attribute with expression arguments.
This is a scope that can contain a declaration.
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
A factory, from which one makes pools, from which one creates individual attributes which are dealloc...
Do not present this diagnostic, ignore it.
llvm::DenseMap< int, SourceRange > ParsedSubjectMatchRuleSet
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
StringLiteral - This represents a string literal expression, e.g.
Defines the clang::TargetInfo interface.
void ActOnPragmaVisibility(const IdentifierInfo *VisType, SourceLocation PragmaLoc)
ActOnPragmaVisibility - Called on well formed #pragma GCC visibility... .
void ActOnPragmaAttributePush(AttributeList &Attribute, SourceLocation PragmaLoc, attr::ParsedSubjectMatchRuleSet Rules)
Called on well-formed '#pragma clang attribute push'.
void DiscardUntilEndOfDirective()
Read and discard all tokens remaining on the current line until the tok::eod token is found...
ExprResult ActOnStringLiteral(ArrayRef< Token > StringToks, Scope *UDLScope=nullptr)
ActOnStringLiteral - The specified tokens were lexed as pasted string fragments (e.g.
Loop optimization hint for loop and unroll pragmas.
void setLocation(SourceLocation L)
AttributeList * getNext() const
A trivial tuple used to represent a source range.
ParsedAttributes - A collection of parsed attributes.
void startToken()
Reset all flags to cleared.
ArrayRef< SVal > ValueList
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
AttributeList - Represents a syntactic attribute.
Stop skipping at specified token, but don't skip the token itself.
void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II)
Called on #pragma clang __debug dump II.
IdentifierInfo * getIdentifierInfo() const