Skip to content

Commit c2d4cc5

Browse files
committed
LAYOUT
1 parent 4efd9b5 commit c2d4cc5

File tree

4 files changed

+7
-22
lines changed

4 files changed

+7
-22
lines changed

Sources/JExtractSwift/JavaConstants/ForeignValueLayouts.swift

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import Foundation
1615
import JavaTypes
1716

1817
/// Represents a value of a `java.lang.foreign.Self` that we want to render in generated Java code.
@@ -22,18 +21,16 @@ public struct ForeignValueLayout: CustomStringConvertible, Equatable {
2221
var inlineComment: String?
2322
var value: String
2423

25-
var needsMemoryLayoutCall: Bool = false
26-
2724
public init(inlineComment: String? = nil, javaConstant: String) {
2825
self.inlineComment = inlineComment
2926
self.value = "SwiftValueLayout.\(javaConstant)"
30-
self.needsMemoryLayoutCall = false
3127
}
3228

3329
public init(inlineComment: String? = nil, customType: String) {
3430
self.inlineComment = inlineComment
35-
self.value = customType
36-
self.needsMemoryLayoutCall = true
31+
// When the type is some custom type, e.g. another Swift struct that we imported,
32+
// we need to import its layout. We do this by referring $LAYOUT on it.
33+
self.value = "\(customType).$LAYOUT"
3734
}
3835

3936
public init?(javaType: JavaType) {
@@ -59,12 +56,6 @@ public struct ForeignValueLayout: CustomStringConvertible, Equatable {
5956

6057
result.append(value)
6158

62-
// When the type is some custom type, e.g. another Swift struct that we imported,
63-
// we need to import its layout. We do this by calling $LAYOUT() on it.
64-
if needsMemoryLayoutCall {
65-
result.append(".$LAYOUT()")
66-
}
67-
6859
return result
6960
}
7061
}

Sources/JExtractSwift/Swift2JavaTranslator+Printing.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,7 @@ extension Swift2JavaTranslator {
288288
private func printClassMemoryLayout(_ printer: inout CodePrinter, _ decl: ImportedNominalType) {
289289
printer.print(
290290
"""
291-
private static final GroupLayout $LAYOUT = (GroupLayout) SwiftValueWitnessTable.layoutOfSwiftType(TYPE_METADATA.$memorySegment());
292-
public static final GroupLayout $LAYOUT() {
293-
return $LAYOUT;
294-
}
291+
public static final GroupLayout $LAYOUT = (GroupLayout) SwiftValueWitnessTable.layoutOfSwiftType(TYPE_METADATA.$memorySegment());
295292
public final GroupLayout $layout() {
296293
return $LAYOUT;
297294
}

Tests/JExtractSwiftTests/ClassPrintingTests.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ struct ClassPrintingTests {
5454
return TYPE_METADATA;
5555
}
5656
57-
private static final GroupLayout $LAYOUT = (GroupLayout) SwiftValueWitnessTable.layoutOfSwiftType(TYPE_METADATA.$memorySegment());
58-
public static final GroupLayout $LAYOUT() {
59-
return $LAYOUT;
60-
}
57+
public static final GroupLayout $LAYOUT = (GroupLayout) SwiftValueWitnessTable.layoutOfSwiftType(TYPE_METADATA.$memorySegment());
6158
public final GroupLayout $layout() {
6259
return $LAYOUT;
6360
}

Tests/JExtractSwiftTests/MethodImportTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ final class MethodImportTests {
304304
super(() -> {
305305
var mh$ = swiftjava___FakeModule_MySwiftClass_init_len_cap.HANDLE;
306306
try {
307-
MemorySegment _result = swiftArena$.allocate(MySwiftClass.$LAYOUT());
307+
MemorySegment _result = swiftArena$.allocate(MySwiftClass.$LAYOUT);
308308
if (SwiftKit.TRACE_DOWNCALLS) {
309309
SwiftKit.traceDowncall(len, cap, _result);
310310
}
@@ -352,7 +352,7 @@ final class MethodImportTests {
352352
super(() -> {
353353
var mh$ = swiftjava___FakeModule_MySwiftStruct_init_len_cap.HANDLE;
354354
try {
355-
MemorySegment _result = swiftArena$.allocate(MySwiftStruct.$LAYOUT());
355+
MemorySegment _result = swiftArena$.allocate(MySwiftStruct.$LAYOUT);
356356
if (SwiftKit.TRACE_DOWNCALLS) {
357357
SwiftKit.traceDowncall(len, cap, _result);
358358
}

0 commit comments

Comments
 (0)