Skip to content

jextract: support Swift operators +/- etc #817

Description

@ktoso

Swift has custom operators like + etc, since Java doesn't have direct equivalent, today we drop them entirely.

Extracting

We need to start extracting operators; I think we can get them into ExtractedFunc and just give them a new .operator kind. Most of this work is done by SwiftAnalysisVisitor.

This would be done in the swift-extract layer; we should have tests that we extract all those kinds of operators.

Naming

Naming should likely have some recursive mechanism to give it a swift name ++ and we turn it into plusPlus etc. We should likely do this in makeJavaMethodName and have a special case for .operator apiKind there.

Swift Java
+ plus
- minus
* times
/ dividedBy
% remainder
<< shiftedLeft
>> shiftedRight
| bitwiseOr
~ bitwiseNot
prefix - negated
== isEqual???
!= isNotEqual
< lessThan
<= lessThanOrEqual
> greaterThan
>= greaterThanOrEqual
& bitwiseAnd
^ bitwiseXor
?? coalescingNil
prefix ! logicalNot

There are some special ones, like == IF the type conforms to Equatable which translates to equals... so we'd probably skip that one because we already handle it as equals I think 🤔

And for printing I think this should mostly just work because they are effectively like functions.

Please also add runtime tests -- we do those by adding real examples in Samples/SwiftJavaExtractJNISampleApp/Sources/MySwiftLibrary (add an Operators.swift) and add a bunch of normal java Junit tests later on.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions