|
|
@ -60,14 +60,13 @@ class GlConstantTransformer : Transformer() { |
|
|
|
val glUnit = units[GL_CLASS] ?: return |
|
|
|
val glUnit = units[GL_CLASS] ?: return |
|
|
|
val glInterface = glUnit.primaryType.get() |
|
|
|
val glInterface = glUnit.primaryType.get() |
|
|
|
|
|
|
|
|
|
|
|
// remove existing declarations first to maintain sort order |
|
|
|
// add missing fields |
|
|
|
for (enum in enums) { |
|
|
|
val fields = enums.filter { !glInterface.getFieldByName(it.name).isPresent } |
|
|
|
val declaration = glInterface.getFieldByName(enum.name) |
|
|
|
.map { it.toDeclaration() } |
|
|
|
declaration.ifPresent { it.remove() } |
|
|
|
glInterface.members.addAll(fields) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val fields = enums.sortedBy(GlEnum::value).map { it.toDeclaration() } |
|
|
|
// sort fields by value for consistency |
|
|
|
glInterface.members.addAll(0, fields) |
|
|
|
glInterface.members.sortWith(FIELD_METHOD_COMPARATOR.thenComparing(GL_FIELD_VALUE_COMPARATOR)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun transformCall(unit: CompilationUnit, expr: MethodCallExpr) { |
|
|
|
private fun transformCall(unit: CompilationUnit, expr: MethodCallExpr) { |
|
|
@ -203,5 +202,39 @@ class GlConstantTransformer : Transformer() { |
|
|
|
private const val GL_CLASS = "javax.media.opengl.$GL_CLASS_UNQUALIFIED" |
|
|
|
private const val GL_CLASS = "javax.media.opengl.$GL_CLASS_UNQUALIFIED" |
|
|
|
private val REGISTRY = GlRegistry.parse() |
|
|
|
private val REGISTRY = GlRegistry.parse() |
|
|
|
private val VENDORS = setOf("ARB", "EXT") |
|
|
|
private val VENDORS = setOf("ARB", "EXT") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val FIELD_METHOD_COMPARATOR = Comparator<BodyDeclaration<*>> { a, b -> |
|
|
|
|
|
|
|
when { |
|
|
|
|
|
|
|
a.isFieldDeclaration && !b.isFieldDeclaration -> -1 |
|
|
|
|
|
|
|
!a.isFieldDeclaration && b.isFieldDeclaration -> 1 |
|
|
|
|
|
|
|
else -> 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun BodyDeclaration<*>.getIntValue(): Int? { |
|
|
|
|
|
|
|
if (!isFieldDeclaration) { |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val variable = asFieldDeclaration().variables.firstOrNull() ?: return null |
|
|
|
|
|
|
|
return variable.initializer.map { |
|
|
|
|
|
|
|
if (it.isIntegerLiteralExpr) { |
|
|
|
|
|
|
|
it.asIntegerLiteralExpr().checkedAsInt() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}.orElse(null) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val GL_FIELD_VALUE_COMPARATOR = Comparator<BodyDeclaration<*>> { a, b -> |
|
|
|
|
|
|
|
val aValue = a.getIntValue() |
|
|
|
|
|
|
|
val bValue = b.getIntValue() |
|
|
|
|
|
|
|
when { |
|
|
|
|
|
|
|
aValue != null && bValue != null -> aValue - bValue |
|
|
|
|
|
|
|
aValue != null && bValue == null -> -1 |
|
|
|
|
|
|
|
aValue == null && bValue != null -> 1 |
|
|
|
|
|
|
|
else -> 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|