Skip to content

Commit 05e93da

Browse files
committed
Simplify and test ASTGen support
Rather than adding custom parsing to SwiftSyntax, we can parse this as a custom attribute and convert it to a built-in one in ASTGen. Test that this works correctly (and fix a bug where it wasn’t).
1 parent 858b557 commit 05e93da

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,16 @@ namespace {
10841084

10851085
printFlag(D->isImplicit(), "implicit", DeclModifierColor);
10861086
printFlag(D->isHoisted(), "hoisted", DeclModifierColor);
1087+
1088+
if (auto implAttr = D->getAttrs().getAttribute<ObjCImplementationAttr>()) {
1089+
StringRef label =
1090+
implAttr->isEarlyAdopter() ? "objc_impl" : "clang_impl";
1091+
if (implAttr->CategoryName.empty())
1092+
printFlag(label);
1093+
else
1094+
printFieldQuoted(implAttr->CategoryName.str(), label);
1095+
}
1096+
10871097
printSourceRange(D->getSourceRange(), &D->getASTContext());
10881098
printFlag(D->TrailingSemiLoc.isValid(), "trailing_semi",
10891099
DeclModifierColor);

lib/ASTGen/Sources/ASTGen/DeclAttrs.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,11 @@ extension ASTGenVisitor {
10661066
return nil
10671067
}
10681068

1069+
if case .token(let tok) = arguments {
1070+
// Special case: was parsed as a token, not an an argument list
1071+
return valueGeneratorFunction(tok)
1072+
}
1073+
10691074
guard var arguments = arguments.as(LabeledExprListSyntax.self)?[...] else {
10701075
// TODO: Diagnose.
10711076
return nil

test/ASTGen/attrs.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ func testMutating(value: S3) {
5757
class C1 {}
5858
@_alignment(7) // expected-error {{alignment value must be a power of two}}
5959
struct S4 {}
60+
61+
@implementation extension ObjCClass1 {} // expected-error {{cannot find type 'ObjCClass1' in scope}}
62+
@implementation(Category) extension ObjCClass1 {} // expected-error {{cannot find type 'ObjCClass1' in scope}}
63+
@_objcImplementation extension ObjCClass2 {} // expected-error {{cannot find type 'ObjCClass2' in scope}}
64+
@_objcImplementation(Category) extension ObjCClass2 {} // expected-error {{cannot find type 'ObjCClass2' in scope}}

0 commit comments

Comments
 (0)