Conversation
e5111e9 to
5bc7668
Compare
a01680f to
fcb71fe
Compare
fcb71fe to
a51ba9b
Compare
a51ba9b to
64fbf46
Compare
70f9407 to
d597a64
Compare
5732e36 to
54b9299
Compare
| public init(inlineComment: String? = nil, javaConstant: String) { | ||
| self.inlineComment = inlineComment | ||
| self.value = javaConstant | ||
| self.value = "SwiftValueLayout.\(javaConstant)" |
|
|
||
| // When the type is some custom type, e.g. another Swift struct that we imported, | ||
| // we need to import its layout. We do this by calling $layout() on it. | ||
| // we need to import its layout. We do this by calling $LAYOUT() on it. |
There was a problem hiding this comment.
is this because openjdk seems to use uppercase for these?
There was a problem hiding this comment.
There is $layout() method as an instance method. I added $LAYOUT() as a static method because this is rendered as ClassName.$LAYOUT(). Maybe we could just use $LAYOUT static field, but I wasn't sure it's OK to make it public.
There was a problem hiding this comment.
public static final ... LAYOUT field is fine I think, it'd help differentiate the field and method. TBD if we need both, but we can decide this later. Uppercase like that does look a bit weird so I'd go for a constant which then looks "expected" being uppercase.
There was a problem hiding this comment.
Sounds good. Updated. While I am here, I removed needsMemoryLayoutCall from the type and added .$LAYOUT in the constructor.
ktoso
left a comment
There was a problem hiding this comment.
Looks all fine to me, thank you @rintaro.
Just few minor comments, one of which you already fixed, which can be done anytime in the future. LGTM, please merge at will 👍
FYI @madsodgaard -- with this merged, it'll be a good time for you to introduce the protocol to pick between ffm and jni modes 👍
| } | ||
|
|
||
| for (param, isLast) in cFunc.parameters.withIsLast { | ||
| printer.print("/* \(param.name ?? "_"): */", .continue) |
There was a problem hiding this comment.
Minor / doesn't have to be in this PR: I think we had an effectiveParamLabel somewhere?
There was a problem hiding this comment.
This actually never be nil. cFunc is created from LoweredFunctionSignature created by lowerFunctionSignature() which actually gives a name to every parameter.
| * Create an instance of {@code \(className)}. | ||
| * | ||
| * {@snippet lang=swift : | ||
| * \(decl.signatureString) |
There was a problem hiding this comment.
Follow up:
Silly but I think now if a signature contains /**/ because we take the raw syntax with the trivia that would break rendering of the source file because the */ will end the comment.
We probably should sanitize that and add a test for it?
There was a problem hiding this comment.
Added FIXME on ImportedFunc.signatureString
| case .getter: "get\(decl.name.toCamelCase)" | ||
| case .setter: "set\(decl.name.toCamelCase)" | ||
| case .function: decl.name | ||
| case .initializer: fatalError("unreachable") |
There was a problem hiding this comment.
give this a better reason string why we crash?
| self.needsMemoryLayoutCall = true | ||
| // When the type is some custom type, e.g. another Swift struct that we imported, | ||
| // we need to import its layout. We do this by referring $LAYOUT on it. | ||
| self.value = "\(customType).$LAYOUT" |
There was a problem hiding this comment.
thanks for updating that to a property
| returnTy = typeAnnotation.type | ||
| } else { | ||
| returnTy = "Swift.Void" | ||
| func importAccessor(kind: SwiftAPIKind) throws { |
| extension SyntaxProtocol { | ||
| /// Look in the comment text prior to the node to find a mangled name | ||
| /// identified by "// MANGLED NAME: ". | ||
| var mangledNameFromComment: String? { |
There was a problem hiding this comment.
yup we dont need this anymore, thank you
| // } | ||
| for decl in nominal.methods { | ||
| decls.append(contentsOf: render(forFunc: decl)) | ||
| } |
* Utilize `SwiftFunctionSignature` and the cdecl-lowering facilities
throughout the code base.
* `SwiftFunctionSignature` is created from the `DeclSyntax` in
`Swift2JavaVisitor`.
* `LoweredFunctionSignature` describing `@cdecl` thunk, is created
from `SwiftFunctionSignature`.
* `TranslatedFunctionSignature` describing generated Java API, is
created from `LoweredFunctionSignature`.
(Swift2JavaTranslator+JavaTranslation.swift)
* `ImportedFunc` is now basically just a wrapper of
`TranslatedFunctionSignature` with the `name`.
* Remove `ImportedVariable`, instead variables are described as
`ImportedFunc` as accessors.
* Support APIs returning imported type values. E.g.
`func factory(arg: Int) -> MyClass` such methods require `SwiftArena`
parameter passed-in.
* Built-in lowerings (e.g. `toCString(String)` for `String` -> C string
conversion) are now implemented in JavaKit.
* Stop emitting `MyClass::apiName$descriptor()` method etc. as they were
not used.
* Use the `@cdecl` thunk name as the function descriptor class name, for
simplicity.
* Getter and setter accessors are now completely separate API. No more
`HANDLE_GET` and `HANDLE_SET` etc. Instead descriptor class is split
to `$get` or `$set` suffixed name.
c2d4cc5 to
637d800
Compare
SwiftFunctionSignatureand the cdecl-lowering facilities throughout the code base.SwiftFunctionSignatureis created from theDeclSyntaxinSwift2JavaVisitor.LoweredFunctionSignaturedescribing@cdeclthunk, is created fromSwiftFunctionSignature.TranslatedFunctionSignaturedescribing generated Java API, is created fromLoweredFunctionSignature. (Swift2JavaTranslator+JavaTranslation.swift)ImportedFuncis now basically just a wrapper ofTranslatedFunctionSignaturewith thename.ImportedVariable, instead variables are described asImportedFuncas accessors.func factory(arg: Int) -> MyClasssuch methods requireSwiftArenapassed-in.toCString(String)forString-> C string conversion) are now implemented in JavaKit.MyClass::apiName$descriptor()method etc. as they were not used.@cdeclthunk name as the function descriptor class name, for simplicity.HANDLE_GETandHANDLE_SETetc. Instead descriptor class is split to$getor$setsuffixed name.Actual output of MyClass.java ▼