Skip to content

Commit c40bda5

Browse files
committed
Sema: Abstracted service for @cdecl style attributes
1 parent 3088105 commit c40bda5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

include/swift/AST/Decl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8113,6 +8113,11 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
81138113
/// instance method.
81148114
bool isObjCInstanceMethod() const;
81158115

8116+
/// Get the foreign language targeted by a @cdecl-style attribute, if any.
8117+
/// Used to abstract away the change in meaning of @cdecl vs @_cdecl while
8118+
/// formalizing the attribute.
8119+
std::optional<ForeignLanguage> getCDeclKind() const;
8120+
81168121
/// Determine whether the name of an argument is an API name by default
81178122
/// depending on the function context.
81188123
bool argumentNameIsAPIByDefault() const;

lib/AST/Decl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10451,6 +10451,15 @@ bool AbstractFunctionDecl::isObjCInstanceMethod() const {
1045110451
return isInstanceMember() || isa<ConstructorDecl>(this);
1045210452
}
1045310453

10454+
std::optional<ForeignLanguage> AbstractFunctionDecl::getCDeclKind() const {
10455+
auto attr = getAttrs().getAttribute<CDeclAttr>();
10456+
if (!attr)
10457+
return std::nullopt;
10458+
10459+
return attr->Underscored ? ForeignLanguage::ObjectiveC
10460+
: ForeignLanguage::C;
10461+
}
10462+
1045410463
bool AbstractFunctionDecl::needsNewVTableEntry() const {
1045510464
auto &ctx = getASTContext();
1045610465
return evaluateOrDefault(

0 commit comments

Comments
 (0)