Skip to content

Commit 7d297bc

Browse files
Print the full calling convention; include the Clang type if applicable.
1 parent fb59293 commit 7d297bc

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

include/swift/AST/Attr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ class TypeAttributes {
159159
return ConventionArguments.getValue().Name;
160160
}
161161

162+
/// Show the string enclosed between @convention(..)'s parentheses.
163+
///
164+
/// For example, @convention(foo, bar) will give the string "foo, bar".
165+
void getConventionArguments(SmallVectorImpl<char> &buffer) const;
166+
162167
bool hasOwnership() const {
163168
return getOwnership() != ReferenceOwnership::Strong;
164169
}

lib/AST/Attr.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "swift/AST/Types.h"
2727
#include "swift/AST/ParameterList.h"
2828
#include "swift/Basic/Defer.h"
29+
#include "swift/Basic/QuotedString.h"
2930
#include "llvm/ADT/SmallString.h"
3031
#include "llvm/Support/raw_ostream.h"
3132
#include "llvm/Support/ErrorHandling.h"
@@ -83,6 +84,18 @@ StringRef swift::getAccessLevelSpelling(AccessLevel value) {
8384
llvm_unreachable("Unhandled AccessLevel in switch.");
8485
}
8586

87+
void TypeAttributes::getConventionArguments(SmallVectorImpl<char> &buf) const {
88+
llvm::raw_svector_ostream stream(buf);
89+
auto &convention = ConventionArguments.getValue();
90+
stream << convention.Name;
91+
if (!convention.WitnessMethodProtocol.empty()) {
92+
stream << ": " << convention.WitnessMethodProtocol;
93+
return;
94+
}
95+
if (!convention.ClangType.empty())
96+
stream << ", cType: " << QuotedString(convention.ClangType);
97+
}
98+
8699
/// Given a name like "autoclosure", return the type attribute ID that
87100
/// corresponds to it. This returns TAK_Count on failure.
88101
///

lib/AST/TypeRepr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@ void AttributedTypeRepr::printAttrs(ASTPrinter &Printer,
313313
Printer.printSimpleAttr("@thick") << " ";
314314

315315
if (hasAttr(TAK_convention) && Attrs.hasConvention()) {
316-
// TODO: (Varun) Print clang type here!
317316
Printer.callPrintStructurePre(PrintStructureKind::BuiltinAttribute);
318317
Printer.printAttrName("@convention");
319-
Printer << "(" << Attrs.getConvention() << ")";
318+
SmallString<32> convention;
319+
Attrs.getConventionArguments(convention);
320+
Printer << "(" << convention << ")";
320321
Printer.printStructurePost(PrintStructureKind::BuiltinAttribute);
321322
Printer << " ";
322323
}

test/SourceKit/CursorInfo/cursor_info.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ enum E7: String {
719719
// RUN: %sourcekitd-test -req=cursor -pos=206:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck -check-prefix=CHECK86 %s
720720
// RUN: %sourcekitd-test -req=cursor -pos=207:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck -check-prefix=CHECK86 %s
721721
// RUN: %sourcekitd-test -req=cursor -pos=208:6 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck -check-prefix=CHECK86 %s
722-
// CHECK86: <syntaxtype.attribute.builtin><syntaxtype.attribute.name>@convention</syntaxtype.attribute.name>({{[a-z_]*}})</syntaxtype.attribute.builtin>
722+
// CHECK86: <syntaxtype.attribute.builtin><syntaxtype.attribute.name>@convention</syntaxtype.attribute.name>({{[a-z_]*((, [a-zA-Z_]*: &quot;[^&]*&quot;)|(: [a-zA-Z0-9_]*))?}})</syntaxtype.attribute.builtin>
723723

724724
// RUN: %sourcekitd-test -req=cursor -pos=213:8 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck -check-prefix=CHECK87 %s
725725
// CHECK87: source.lang.swift.decl.struct (213:8-213:26)

0 commit comments

Comments
 (0)