Skip to content

Commit 844da5c

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

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
@@ -1327,6 +1327,9 @@ ERROR(alignment_must_be_positive_integer,none,
13271327
ERROR(swift_native_objc_runtime_base_must_be_identifier,none,
13281328
"@_swift_native_objc_runtime_base class name must be an identifier", ())
13291329

1330+
ERROR(objc_runtime_name_must_be_identifier,none,
1331+
"@_objcRuntimeName name must be an identifier", ())
1332+
13301333
ERROR(attr_only_at_non_local_scope, none,
13311334
"attribute '%0' can only be used in a non-local scope", (StringRef))
13321335

lib/Parse/ParseDecl.cpp

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

903903
case DAK_RawDocComment:
904904
case DAK_ObjCBridged:
905-
case DAK_ObjCRuntimeName:
906905
case DAK_RestatedObjCConformance:
907906
case DAK_SynthesizedProtocol:
908907
case DAK_ClangImporterSynthesizedType:
@@ -1494,6 +1493,34 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
14941493
Attributes.add(attr);
14951494
break;
14961495
}
1496+
case DAK_ObjCRuntimeName: {
1497+
if (!consumeIf(tok::l_paren)) {
1498+
diagnose(Loc, diag::attr_expected_lparen, AttrName,
1499+
DeclAttribute::isDeclModifier(DK));
1500+
return false;
1501+
}
1502+
1503+
if (Tok.isNot(tok::identifier)) {
1504+
diagnose(Loc, diag::objc_runtime_name_must_be_identifier);
1505+
return false;
1506+
}
1507+
1508+
auto name = Tok.getText();
1509+
1510+
consumeToken(tok::identifier);
1511+
1512+
auto range = SourceRange(Loc, Tok.getRange().getStart());
1513+
1514+
if (!consumeIf(tok::r_paren)) {
1515+
diagnose(Loc, diag::attr_expected_rparen, AttrName,
1516+
DeclAttribute::isDeclModifier(DK));
1517+
return false;
1518+
}
1519+
1520+
Attributes.add(new (Context) ObjCRuntimeNameAttr(name, AtLoc, range,
1521+
/*implicit*/ false));
1522+
break;
1523+
}
14971524

14981525

14991526
case DAK_DynamicReplacement: {

0 commit comments

Comments
 (0)