Skip to content

Commit 1ea2d46

Browse files
committed
[SourceKit] Add builtin attribute tags
As promised, tag the whole attribute include all of its 'parameters'. rdar://problem/24292226
1 parent bb152f1 commit 1ea2d46

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

include/swift/AST/ASTPrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ enum class PrintStructureKind {
6060
GenericParameter,
6161
GenericRequirement,
6262
FunctionParameter,
63+
BuiltinAttribute,
6364
};
6465

6566
/// An abstract class used to print an AST.

lib/AST/Attr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/Decl.h"
2121
#include "swift/AST/Module.h"
2222
#include "swift/AST/Types.h"
23+
#include "swift/Basic/Defer.h"
2324
#include "llvm/ADT/SmallString.h"
2425
#include "llvm/Support/raw_ostream.h"
2526
#include "llvm/ADT/StringSwitch.h"
@@ -298,7 +299,9 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options)
298299
if (DeclAttribute::isDeclModifier(getKind())) {
299300
Printer.printKeyword(getAttrName());
300301
} else {
302+
Printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
301303
Printer.printAttrName(getAttrName(), /*needAt=*/true);
304+
Printer.printStructurePost(PrintStructureKind::BuiltinAttribute);
302305
}
303306
return true;
304307

@@ -311,6 +314,9 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options)
311314
break;
312315
}
313316

317+
Printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
318+
defer { Printer.printStructurePost(PrintStructureKind::BuiltinAttribute); };
319+
314320
switch (getKind()) {
315321
case DAK_Semantics:
316322
Printer.printAttrName("@_semantics");

test/SourceKit/DocSupport/doc_clang_module.swift.response

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3656,15 +3656,15 @@ var FooSubUnnamedEnumeratorA1: Int { get }
36563656
key.usr: "c:@F@fooFuncNoreturn1",
36573657
key.offset: 1606,
36583658
key.length: 33,
3659-
key.fully_annotated_decl: "<decl.function.free><syntaxtype.attribute.name>@noreturn</syntaxtype.attribute.name> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fooFuncNoreturn1</decl.name>()</decl.function.free>"
3659+
key.fully_annotated_decl: "<decl.function.free><syntaxtype.attribute.builtin><syntaxtype.attribute.name>@noreturn</syntaxtype.attribute.name></syntaxtype.attribute.builtin> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fooFuncNoreturn1</decl.name>()</decl.function.free>"
36603660
},
36613661
{
36623662
key.kind: source.lang.swift.decl.function.free,
36633663
key.name: "fooFuncNoreturn2()",
36643664
key.usr: "c:@F@fooFuncNoreturn2",
36653665
key.offset: 1640,
36663666
key.length: 33,
3667-
key.fully_annotated_decl: "<decl.function.free><syntaxtype.attribute.name>@noreturn</syntaxtype.attribute.name> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fooFuncNoreturn2</decl.name>()</decl.function.free>"
3667+
key.fully_annotated_decl: "<decl.function.free><syntaxtype.attribute.builtin><syntaxtype.attribute.name>@noreturn</syntaxtype.attribute.name></syntaxtype.attribute.builtin> <syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>fooFuncNoreturn2</decl.name>()</decl.function.free>"
36683668
},
36693669
{
36703670
key.kind: source.lang.swift.decl.function.free,
@@ -4270,7 +4270,7 @@ var FooSubUnnamedEnumeratorA1: Int { get }
42704270
key.usr: "c:objc(cs)FooClassPropertyOwnership(py)copyable",
42714271
key.offset: 3701,
42724272
key.length: 35,
4273-
key.fully_annotated_decl: "<decl.var.instance><syntaxtype.attribute.name>@NSCopying</syntaxtype.attribute.name> <syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>copyable</decl.name>: <decl.var.type><ref.protocol usr=\"s:Ps9AnyObject\">AnyObject</ref.protocol>!</decl.var.type> { <syntaxtype.keyword>get</syntaxtype.keyword> <syntaxtype.keyword>set</syntaxtype.keyword> }</decl.var.instance>"
4273+
key.fully_annotated_decl: "<decl.var.instance><syntaxtype.attribute.builtin><syntaxtype.attribute.name>@NSCopying</syntaxtype.attribute.name></syntaxtype.attribute.builtin> <syntaxtype.keyword>var</syntaxtype.keyword> <decl.name>copyable</decl.name>: <decl.var.type><ref.protocol usr=\"s:Ps9AnyObject\">AnyObject</ref.protocol>!</decl.var.type> { <syntaxtype.keyword>get</syntaxtype.keyword> <syntaxtype.keyword>set</syntaxtype.keyword> }</decl.var.instance>"
42744274
},
42754275
{
42764276
key.kind: source.lang.swift.decl.var.instance,

test/SourceKit/SourceDocInfo/cursor_info.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,11 @@ func genReq<U, V: P1 where V.T == U>(u: U, v: V) {}
463463

464464
// RUN: %sourcekitd-test -req=cursor -pos=119:13 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck %s -check-prefix=CHECK54
465465
// CHECK54: source.lang.swift.decl.class (119:13-119:15)
466-
// CHECK54: <decl.class><syntaxtype.attribute.name>@objc</syntaxtype.attribute.name> <syntaxtype.keyword>class
466+
// CHECK54: <decl.class><syntaxtype.attribute.builtin><syntaxtype.attribute.name>@objc</syntaxtype.attribute.name></syntaxtype.attribute.builtin> <syntaxtype.keyword>class
467467

468468
// RUN: %sourcekitd-test -req=cursor -pos=122:8 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck %s -check-prefix=CHECK55
469469
// CHECK55: source.lang.swift.decl.function.method.instance (122:8-122:12)
470-
// CHECK55: <decl.function.method.instance><syntaxtype.attribute.name>@objc</syntaxtype.attribute.name>(mmm1) <syntaxtype.attribute.name>@noreturn</syntaxtype.attribute.name> <syntaxtype.keyword>func
470+
// CHECK55: <decl.function.method.instance><syntaxtype.attribute.builtin><syntaxtype.attribute.name>@objc</syntaxtype.attribute.name>(mmm1)</syntaxtype.attribute.builtin> <syntaxtype.attribute.builtin><syntaxtype.attribute.name>@noreturn</syntaxtype.attribute.name></syntaxtype.attribute.builtin> <syntaxtype.keyword>func
471471

472472
// RUN: %sourcekitd-test -req=cursor -pos=126:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | FileCheck %s -check-prefix=CHECK56
473473
// CHECK56: source.lang.swift.decl.var.instance (126:7-126:9)

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ static StringRef getTagForParameter(PrintStructureKind context) {
7878
return "decl.generic_type_param";
7979
case PrintStructureKind::GenericRequirement:
8080
return "decl.generic_type_requirement";
81+
case PrintStructureKind::BuiltinAttribute:
82+
return "syntaxtype.attribute.builtin";
8183
}
8284
llvm_unreachable("unexpected parameter kind");
8385
}
@@ -257,7 +259,8 @@ class FullyAnnotatedDeclarationPrinter final : public XMLEscapingPrinter {
257259
return parameterTypeTag;
258260
if (context.is(PrintStructureKind::GenericParameter))
259261
return genericParamTypeTag;
260-
if (context.is(PrintStructureKind::GenericRequirement))
262+
if (context.is(PrintStructureKind::GenericRequirement) ||
263+
context.is(PrintStructureKind::BuiltinAttribute))
261264
return "";
262265

263266
assert(context.getDecl() && "unexpected context kind");

0 commit comments

Comments
 (0)