Skip to content

[jextract] Update for review feedback #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ extension Swift2JavaTranslator {
}

/// Lower the given variable decl to a C-compatible entrypoint,
/// providing all of the mappings between the parameter and result types
/// of the original function and its `@_cdecl` counterpart.
/// providing the mappings between the `self` and value type of the variable
/// and its `@_cdecl` counterpart.
@_spi(Testing)
public func lowerFunctionSignature(
_ decl: VariableDeclSyntax,
Expand Down Expand Up @@ -297,7 +297,7 @@ struct CdeclLowering {
}
}

/// Lower a Swift result type to cdecl parameters and return type.
/// Lower a Swift result type to cdecl out parameters and return type.
///
/// - Parameters:
/// - type: The return type.
Expand Down
21 changes: 6 additions & 15 deletions Sources/JExtractSwift/SwiftTypes/SwiftFunctionSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,26 +227,17 @@ extension VariableDeclSyntax {
case .getter:
return [.get]
case .accessors(let accessors):
var hasGetter = false
var hasSetter = false

for accessor in accessors {
switch accessor.accessorSpecifier {
case .keyword(.get), .keyword(._read), .keyword(.unsafeAddress):
hasGetter = true
case .keyword(.set), .keyword(._modify), .keyword(.unsafeMutableAddress):
hasSetter = true
switch accessor.accessorSpecifier.tokenKind {
// Existence of any write accessor or observer implies this supports read/write.
case .keyword(.set), .keyword(._modify), .keyword(.unsafeMutableAddress),
.keyword(.willSet), .keyword(.didSet):
return [.get, .set]
default: // Ignore willSet/didSet and unknown accessors.
break
}
}

switch (hasGetter, hasSetter) {
case (true, true): return [.get, .set]
case (true, false): return [.get]
case (false, true): return [.set]
case (false, false): break
}
return [.get]
}
}

Expand Down