-
Enhancement
-
Resolution: Fixed
-
P3
-
None
-
None
Consider the following struct declaration:
```
struct Point2d {
double x;
double y;
};
```
For this, jextract generates the following code (some details have been left out):
```
public class Point2d {
public static double x$get(MemorySegment seg) { ... }
public static void x$set(MemorySegment seg, double x) { ... }
public static double x$get(MemorySegment seg, long index) { ... }
public static void x$set(MemorySegment seg, long index, double x) { ... }
public static double y$get(MemorySegment seg) { ... }
public static void y$set(MemorySegment seg, double x) { ... }
public static double y$get(MemorySegment seg, long index) { ... }
public static void y$set(MemorySegment seg, long index, double x) { ... }
...
}
```
The naming scheme used for getter and setter is:
<field name> '$' [ get, set ]
This scheme is something that comes from a time where for each fields we had _three_ different accessors (get, set and ref). Now that it's just about getting and setting, it would be nice to perhaps replace the naming scheme with something more modern such as:
double x(MemorySegment segment) { ... }
void x(MemorySegment segment, double val) { ... }
One complication with this naming scheme is what to do about indexed accessors, as some of those accessors might clash if a struct field has type `long`. In such case, the indexed getter will have the same signature as the non-indexed setter.
```
struct Point2d {
double x;
double y;
};
```
For this, jextract generates the following code (some details have been left out):
```
public class Point2d {
public static double x$get(MemorySegment seg) { ... }
public static void x$set(MemorySegment seg, double x) { ... }
public static double x$get(MemorySegment seg, long index) { ... }
public static void x$set(MemorySegment seg, long index, double x) { ... }
public static double y$get(MemorySegment seg) { ... }
public static void y$set(MemorySegment seg, double x) { ... }
public static double y$get(MemorySegment seg, long index) { ... }
public static void y$set(MemorySegment seg, long index, double x) { ... }
...
}
```
The naming scheme used for getter and setter is:
<field name> '$' [ get, set ]
This scheme is something that comes from a time where for each fields we had _three_ different accessors (get, set and ref). Now that it's just about getting and setting, it would be nice to perhaps replace the naming scheme with something more modern such as:
double x(MemorySegment segment) { ... }
void x(MemorySegment segment, double val) { ... }
One complication with this naming scheme is what to do about indexed accessors, as some of those accessors might clash if a struct field has type `long`. In such case, the indexed getter will have the same signature as the non-indexed setter.