@@ -2042,7 +2042,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
2042
2042
llvm::SmallVector<std::pair<PlatformKind, llvm::VersionTuple>, 4 >
2043
2043
PlatformAndVersions;
2044
2044
2045
- StringRef AttrName = " @_originalDefinedIn " ;
2045
+ StringRef AttrName = " @_originallyDefinedIn " ;
2046
2046
bool SuppressLaterDiags = false ;
2047
2047
if (parseList (tok::r_paren, LeftLoc, RightLoc, false ,
2048
2048
diag::originally_defined_in_missing_rparen,
@@ -2084,9 +2084,53 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
2084
2084
// Parse 'OSX 13.13'.
2085
2085
case NextSegmentKind::PlatformVersion: {
2086
2086
if ((Tok.is (tok::identifier) || Tok.is (tok::oper_binary_spaced)) &&
2087
- (peekToken ().is (tok::floating_literal) ||
2088
- peekToken ().is (tok::integer_literal))) {
2087
+ (peekToken ().isAny (tok::integer_literal, tok::floating_literal) ||
2088
+ peekAvailabilityMacroName ())) {
2089
+
2089
2090
PlatformKind Platform;
2091
+
2092
+ if (peekAvailabilityMacroName ()) {
2093
+ // Handle availability macros first.
2094
+ //
2095
+ // The logic to search for macros and platform name could
2096
+ // likely be handled by parseAvailabilitySpecList
2097
+ // if we don't rely on parseList here.
2098
+ SmallVector<AvailabilitySpec *, 4 > Specs;
2099
+ ParserStatus MacroStatus = parseAvailabilityMacro (Specs);
2100
+ if (MacroStatus.isError ())
2101
+ return MacroStatus;
2102
+
2103
+ for (auto *Spec : Specs) {
2104
+ if (auto *PlatformVersionSpec =
2105
+ dyn_cast<PlatformVersionConstraintAvailabilitySpec>(Spec)) {
2106
+ auto Platform = PlatformVersionSpec->getPlatform ();
2107
+ auto Version = PlatformVersionSpec->getVersion ();
2108
+ if (Version.getSubminor ().hasValue () ||
2109
+ Version.getBuild ().hasValue ()) {
2110
+ diagnose (Tok.getLoc (), diag::originally_defined_in_major_minor_only);
2111
+ }
2112
+ PlatformAndVersions.emplace_back (Platform, Version);
2113
+
2114
+ } else if (auto *PlatformAgnostic =
2115
+ dyn_cast<PlatformAgnosticVersionConstraintAvailabilitySpec>(Spec)) {
2116
+ diagnose (PlatformAgnostic->getPlatformAgnosticNameLoc (),
2117
+ PlatformAgnostic->isLanguageVersionSpecific () ?
2118
+ diag::originally_defined_in_swift_version :
2119
+ diag::originally_defined_in_package_description);
2120
+
2121
+ } else if (auto *OtherPlatform =
2122
+ dyn_cast<OtherPlatformAvailabilitySpec>(Spec)) {
2123
+ diagnose (OtherPlatform->getStarLoc (),
2124
+ diag::originally_defined_in_missing_platform_name);
2125
+
2126
+ } else {
2127
+ llvm_unreachable (" Unexpected AvailabilitySpec kind." );
2128
+ }
2129
+ }
2130
+
2131
+ return makeParserSuccess ();
2132
+ }
2133
+
2090
2134
// Parse platform name.
2091
2135
auto Plat = platformFromString (Tok.getText ());
2092
2136
if (!Plat.hasValue ()) {
0 commit comments