Skip to content

Commit ac37684

Browse files
committed
[Parse] Allow @_objcRuntimeName to be used in source.
rdar://problem/46546165
1 parent a49e2dd commit ac37684

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ DECL_ATTR(_implements, Implements,
338338
NotSerialized, 67)
339339
DECL_ATTR(_objcRuntimeName, ObjCRuntimeName,
340340
OnClass |
341-
UserInaccessible | RejectByParser |
341+
UserInaccessible |
342342
NotSerialized, 68)
343343
SIMPLE_DECL_ATTR(_staticInitializeObjCMetadata, StaticInitializeObjCMetadata,
344344
OnClass | LongAttribute | RejectByParser |

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,9 @@ ERROR(alignment_must_be_positive_integer,none,
13201320
ERROR(swift_native_objc_runtime_base_must_be_identifier,none,
13211321
"@_swift_native_objc_runtime_base class name must be an identifier", ())
13221322

1323+
ERROR(objc_runtime_name_must_be_identifier,none,
1324+
"@_objcRuntimeName name must be an identifier", ())
1325+
13231326
ERROR(attr_only_at_non_local_scope, none,
13241327
"attribute '%0' can only be used in a non-local scope", (StringRef))
13251328

lib/Parse/ParseDecl.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,6 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
914914

915915
case DAK_RawDocComment:
916916
case DAK_ObjCBridged:
917-
case DAK_ObjCRuntimeName:
918917
case DAK_RestatedObjCConformance:
919918
case DAK_SynthesizedProtocol:
920919
case DAK_ClangImporterSynthesizedType:
@@ -1506,6 +1505,34 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
15061505
Attributes.add(attr);
15071506
break;
15081507
}
1508+
case DAK_ObjCRuntimeName: {
1509+
if (!consumeIf(tok::l_paren)) {
1510+
diagnose(Loc, diag::attr_expected_lparen, AttrName,
1511+
DeclAttribute::isDeclModifier(DK));
1512+
return false;
1513+
}
1514+
1515+
if (Tok.isNot(tok::identifier)) {
1516+
diagnose(Loc, diag::objc_runtime_name_must_be_identifier);
1517+
return false;
1518+
}
1519+
1520+
auto name = Tok.getText();
1521+
1522+
consumeToken(tok::identifier);
1523+
1524+
auto range = SourceRange(Loc, Tok.getRange().getStart());
1525+
1526+
if (!consumeIf(tok::r_paren)) {
1527+
diagnose(Loc, diag::attr_expected_rparen, AttrName,
1528+
DeclAttribute::isDeclModifier(DK));
1529+
return false;
1530+
}
1531+
1532+
Attributes.add(new (Context) ObjCRuntimeNameAttr(name, AtLoc, range,
1533+
/*implicit*/ false));
1534+
break;
1535+
}
15091536

15101537

15111538
case DAK_DynamicReplacement: {

0 commit comments

Comments
 (0)