-
Notifications
You must be signed in to change notification settings - Fork 46
Prepare accessor function descriptors for properties: get set #41
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
258ccff
Prepare accessor function descriptors for properties: get set
ktoso a8f1cc9
Printing for handles, descriptors and address methods for props
ktoso aa2d017
getter and setter generated for stored property
ktoso 5986b30
jextract: end to end run for a property import
ktoso 9a561cf
disable runtime tests on linux until we have mangling
ktoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,9 @@ | |
package com.example.swift.generated; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.condition.DisabledOnOs; | ||
import org.junit.jupiter.api.condition.OS; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
@@ -31,6 +34,27 @@ static void beforeAll() { | |
System.setProperty("jextract.trace.downcalls", "true"); | ||
} | ||
|
||
// TODO: test member methods on MySwiftClass | ||
@Test | ||
@DisabledOnOs(OS.LINUX) // FIXME: enable on Linux when we get new compiler with mangled names in swift interfaces | ||
void test_MySwiftClass_voidMethod() { | ||
MySwiftClass o = new MySwiftClass(12, 42); | ||
o.voidMethod(); | ||
} | ||
|
||
@Test | ||
@DisabledOnOs(OS.LINUX) // FIXME: enable on Linux when we get new compiler with mangled names in swift interfaces | ||
void test_MySwiftClass_makeIntMethod() { | ||
MySwiftClass o = new MySwiftClass(12, 42); | ||
var got = o.makeIntMethod(); | ||
assertEquals(12, got); | ||
} | ||
|
||
@Test | ||
@DisabledOnOs(OS.LINUX) // FIXME: enable on Linux when we get new compiler with mangled names in swift interfaces | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lots of tests waiting on #27 |
||
void test_MySwiftClass_property_len() { | ||
MySwiftClass o = new MySwiftClass(12, 42); | ||
var got = o.makeIntMethod(); | ||
assertEquals(12, got); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
extension String { | ||
|
||
// TODO: naive implementation good enough for our simple case `methodMethodSomething` -> `MethodSomething` | ||
var toCamelCase: String { | ||
guard let f = first else { | ||
return self | ||
} | ||
|
||
return "\(f.uppercased())\(String(dropFirst()))" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift.org project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of Swift.org project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Foundation | ||
import JavaTypes | ||
import SwiftSyntax | ||
import OrderedCollections | ||
|
||
extension ImportedFunc { | ||
/// Render a `@{@snippet ... }` comment section that can be put inside a JavaDoc comment | ||
/// when referring to the original declaration a printed method refers to. | ||
var renderCommentSnippet: String? { | ||
if let syntax { | ||
""" | ||
* {@snippet lang=swift : | ||
* \(syntax) | ||
* } | ||
""" | ||
} else { | ||
nil | ||
} | ||
} | ||
} | ||
|
||
extension VariableAccessorKind { | ||
|
||
public var fieldSuffix: String { | ||
switch self { | ||
case .get: "_GET" | ||
case .set: "_SET" | ||
} | ||
} | ||
|
||
public var renderDescFieldName: String { | ||
switch self { | ||
case .get: "DESC_GET" | ||
case .set: "DESC_SET" | ||
} | ||
} | ||
|
||
public var renderAddrFieldName: String { | ||
switch self { | ||
case .get: "ADDR_GET" | ||
case .set: "ADDR_SET" | ||
} | ||
} | ||
|
||
public var renderHandleFieldName: String { | ||
switch self { | ||
case .get: "HANDLE_GET" | ||
case .set: "HANDLE_SET" | ||
} | ||
} | ||
|
||
/// Renders a "$get" part that can be used in a method signature representing this accessor. | ||
public var renderMethodNameSegment: String { | ||
switch self { | ||
case .get: "$get" | ||
case .set: "$set" | ||
} | ||
} | ||
|
||
func renderMethodName(_ decl: ImportedFunc) -> String? { | ||
switch self { | ||
case .get: "get\(decl.identifier.toCamelCase)" | ||
case .set: "set\(decl.identifier.toCamelCase)" | ||
} | ||
} | ||
} | ||
|
||
extension Optional where Wrapped == VariableAccessorKind { | ||
public var renderDescFieldName: String { | ||
self?.renderDescFieldName ?? "DESC" | ||
} | ||
|
||
public var renderAddrFieldName: String { | ||
self?.renderAddrFieldName ?? "ADDR" | ||
} | ||
|
||
public var renderHandleFieldName: String { | ||
self?.renderHandleFieldName ?? "HANDLE" | ||
} | ||
|
||
public var renderMethodNameSegment: String { | ||
self?.renderMethodNameSegment ?? "" | ||
} | ||
|
||
func renderMethodName(_ decl: ImportedFunc) -> String { | ||
self?.renderMethodName(decl) ?? decl.baseIdentifier | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OrderedSet
to avoid sourcegen order breaking some tests