Skip to content

Commit

Permalink
fix(generator) struct validation ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Spasi committed Sep 25, 2024
1 parent 2254657 commit 9ab9fd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion modules/generator/src/main/kotlin/org/lwjgl/generator/Structs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,18 @@ class Struct(
val validations = ArrayList<String>()

fun MutableList<String>.addPointer(m: StructMember) = this.add("$t${t}long ${m.name} = memGetAddress($STRUCT + $className.${m.offsetField});")
fun MutableList<String>.addCount(m: StructMember) = this.add("$t$t${m.nativeType.javaMethodType} ${m.name} = n${m.name}($STRUCT);")
fun MutableList<String>.addCount(m: StructMember) {
val validation = "$t$t${m.nativeType.javaMethodType} ${m.name} = n${m.name}($STRUCT);"
if (!this.isEmpty()) {
for (i in 0 until this.size) {
if (this[i].contains(m.name)) {
this.add(i, validation)
return
}
}
}
this.add(validation)
}

fun validate(m: StructMember, indent: String, hasPointer: Boolean = false): String {
return if (m.nativeType.hasStructValidation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static void validate(long array, int count, int SIZEOF, StructValidation
validation.validate(array + Integer.toUnsignedLong(i) * SIZEOF);
}
}
public static void validate(long array, long count, int SIZEOF, StructValidation validation) { validate(array, (int)count, SIZEOF, validation); }

// ---------------- Struct Member Layout ----------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ public static LLVMOrcCSymbolDependenceGroup.Buffer calloc(int capacity, MemorySt
*/
public static void validate(long struct) {
LLVMOrcCSymbolsList.validate(struct + LLVMOrcCSymbolDependenceGroup.SYMBOLS);
long NumDependencies = nNumDependencies(struct);
long Dependencies = memGetAddress(struct + LLVMOrcCSymbolDependenceGroup.DEPENDENCIES);
check(Dependencies);
validate(Dependencies, NumDependencies, LLVMOrcCDependenceMapPair.SIZEOF, LLVMOrcCDependenceMapPair::validate);
long NumDependencies = nNumDependencies(struct);
}

// -----------------------------------
Expand Down

0 comments on commit 9ab9fd5

Please sign in to comment.