Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57,872 changes: 57,176 additions & 696 deletions codegen/input/meos-idl.json

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions codegen/src/main/java/FunctionsGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,51 @@ public class FunctionsGenerator {
// so we force long when the interface type resolved to int for these names.
private static final Set<String> SIZE_PARAM_NAMES = Set.of("size", "wkb_size");

// -------------------------------------------------------------------------
// Optional MEOS type families, gated by build flags mirroring the
// MobilityDB/MEOS flag names and ON|OFF (also 1|0) values: -DCBUFFER=OFF,
// -DNPOINT=OFF, -DPOSE=OFF, -DRGEO=OFF, -DH3=OFF. Each family maps to the
// public headers that declare its functions; a function whose header belongs
// to an excluded family is omitted from the generated binding, so a subset
// jar ships without it. The shared binding jar includes every family by
// default; pass -D<FAMILY>=OFF|0 to drop one (RGEO needs POSE).
// -------------------------------------------------------------------------
private static final Map<String, String> HEADER_FAMILY = Map.ofEntries(
Map.entry("meos_cbuffer.h", "CBUFFER"),
Map.entry("meos_npoint.h", "NPOINT"),
Map.entry("meos_pose.h", "POSE"),
Map.entry("meos_rgeo.h", "RGEO"),
Map.entry("meos_h3.h", "H3"),
Map.entry("th3index.h", "H3"),
Map.entry("th3index_internal.h", "H3"),
Map.entry("th3index_boxops.h", "H3"),
Map.entry("h3index.h", "H3"),
Map.entry("h3index_sets.h", "H3"),
Map.entry("h3_generated.h", "H3"));
private static final Set<String> OPTIONAL_FAMILIES =
Set.of("CBUFFER", "NPOINT", "POSE", "RGEO", "H3");

// Families enabled for this generation run; core headers are always emitted.
private Set<String> enabledFamilies;

private static Set<String> resolveEnabledFamilies() {
Set<String> enabled = new LinkedHashSet<>();
for (String family : OPTIONAL_FAMILIES) {
String v = System.getProperty(family);
boolean off = v != null
&& (v.equalsIgnoreCase("OFF") || v.equals("0") || v.equalsIgnoreCase("false"));
if (!off) {
enabled.add(family); // included by default, dropped only by -D<FAMILY>=OFF|0
}
}
return enabled;
}

private boolean familyEnabled(String file) {
String family = HEADER_FAMILY.get(file);
return family == null || enabledFamilies.contains(family); // core (unmapped) always on
}

// Output-only size parameters that must not appear in the public
// static wrapper signature.
//
Expand Down Expand Up @@ -121,7 +166,15 @@ private void run(String inputPath, String outputPath) throws IOException {
List<FunctionDef> functions = new ArrayList<>();
Set<String> seen = new LinkedHashSet<>(); // deduplicate by name#arity

enabledFamilies = resolveEnabledFamilies();
System.out.println("Enabled optional families: " + enabledFamilies
+ " (core always included)");

for (JsonNode fn : functionsNode) {
JsonNode fileNode = fn.get("file");
if (fileNode != null && !familyEnabled(fileNode.asText())) {
continue; // function belongs to a disabled type family
}
FunctionDef def = parseFunctionDef(fn);
String key = def.name + "#" + def.params.size();
if (seen.add(key)) {
Expand Down Expand Up @@ -266,6 +319,10 @@ private String mapCTypeToJava(String cType) {
// DateADT is int32 under the hood; Timestamp/TimestampTz are int64.
case "DateADT" -> "int";
case "Timestamp", "TimestampTz" -> "long";
// H3Index is a uint64 cell identifier (DGGRID/H3), not an opaque
// struct pointer; without this it hits the default branch and
// becomes Pointer, breaking every h3index/th3index binding.
case "H3Index" -> "long";

// Explicit enum names (in case not in JSON enums section)
case "interpType", "RTreeSearchOp",
Expand Down
1 change: 1 addition & 0 deletions codegen/src/test/java/FunctionsGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class MapCTypeToJavaTests {
@Test void DateADT() throws Exception { assertEquals("int", mapJava("DateADT")); }
@Test void Timestamp() throws Exception { assertEquals("long", mapJava("Timestamp")); }
@Test void TimestampTz() throws Exception { assertEquals("long", mapJava("TimestampTz")); }
@Test void H3Index() throws Exception { assertEquals("long", mapJava("H3Index")); }

@Test void charPointer() throws Exception { assertEquals("String", mapJava("char *")); }
@Test void structPointer() throws Exception { assertEquals("Pointer", mapJava("STBox *")); }
Expand Down
51 changes: 51 additions & 0 deletions jmeos-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,57 @@
</plugin>


<!-- Generate functions.GeneratedFunctions from the MEOS IDL at build
time. The optional type families are selected with the same flag
names and ON|OFF (also 1|0) values as the MobilityDB/MEOS build:
every family is included by default; pass -DCBUFFER=OFF (or
-DNPOINT/-DPOSE/-DRGEO/-DH3=OFF|0) to drop one (RGEO needs POSE).
exec:java runs in-process so the -D flags are inherited. -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>generate-meos-facade</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>FunctionsGenerator</mainClass>
<additionalClasspathElements>
<additionalClasspathElement>${project.basedir}/../codegen/target/classes</additionalClasspathElement>
</additionalClasspathElements>
<arguments>
<argument>${project.basedir}/../codegen/input/meos-idl.json</argument>
<argument>${project.build.directory}/generated-sources/jmeos/functions/GeneratedFunctions.java</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>add-generated-facade</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/jmeos</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Binary file modified jmeos-core/src/libmeos.so
Binary file not shown.
Loading
Loading