Skip to content

Commit 3efb1f8

Browse files
committed
Simplify generation classes (#782)
* Simplify TypedTrait * Enriching API is now a rule
1 parent 68783b2 commit 3efb1f8

File tree

264 files changed

+1228
-1364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+1228
-1364
lines changed

kt/api-generator/src/main/kotlin/godot/codegen/constants/CoreTypeTraits.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

kt/api-generator/src/main/kotlin/godot/codegen/exceptions/ClassGenerationException.kt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package godot.codegen.exceptions
22

3+
import godot.codegen.models.Method
4+
import godot.codegen.models.Signal
35
import godot.codegen.models.enriched.EnrichedMethod
46
import godot.codegen.models.enriched.EnrichedSignal
57
import godot.common.constants.Constraints
68

7-
class TooManyMethodArgument(method: EnrichedMethod) :
8-
Exception("${method.name} has ${method.arguments.size} arguments but the maximum number is ${Constraints.MAX_FUNCTION_ARG_COUNT}")
9+
class TooManyMethodArgument(method: Method) :
10+
Exception("${method.name} has ${method.arguments!!.size} arguments but the maximum number is ${Constraints.MAX_FUNCTION_ARG_COUNT}")
911

10-
class TooManySignalArgument(signal: EnrichedSignal) :
11-
Exception("${signal.name} has ${signal.arguments.size} arguments but the maximum number is ${Constraints.MAX_SIGNAL_ARG_COUNT}")
12+
class TooManySignalArgument(signal: Signal) :
13+
Exception("${signal.name} has ${signal.arguments!!.size} arguments but the maximum number is ${Constraints.MAX_SIGNAL_ARG_COUNT}")

kt/api-generator/src/main/kotlin/godot/codegen/extensions/TypedExtensions.kt

Lines changed: 0 additions & 220 deletions
This file was deleted.

kt/api-generator/src/main/kotlin/godot/codegen/generation/Context.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package godot.codegen.generation
2+
3+
import godot.codegen.exceptions.NoMatchingEnumFound
4+
import godot.codegen.models.traits.GenerationType
5+
import godot.codegen.models.ApiDescription
6+
import godot.codegen.models.enriched.EnrichedClass
7+
import godot.codegen.models.enriched.EnrichedEnum
8+
import godot.codegen.models.enriched.EnrichedNativeStructure
9+
import godot.tools.common.constants.GodotTypes
10+
import java.io.File
11+
12+
class GenerationContext(
13+
val api: ApiDescription,
14+
) {
15+
private var nextEngineClassIndex = 0
16+
private var nextSingletonIndex = 0
17+
18+
val coreTypeMap = mutableMapOf<String, List<EnrichedEnum>>()
19+
val nativeStructureMap = HashMap<String, EnrichedNativeStructure>()
20+
21+
val globalEnumMap = mutableMapOf<String, EnrichedEnum>()
22+
val globalEnumList = mutableListOf<EnrichedEnum>()
23+
val classMap = mutableMapOf<String, EnrichedClass>()
24+
val classList = mutableListOf<EnrichedClass>()
25+
26+
27+
fun getNextEngineClassIndex() = nextEngineClassIndex++
28+
fun getNextSingletonIndex(): Int {
29+
nextEngineClassIndex++
30+
return nextSingletonIndex++
31+
}
32+
33+
fun isNativeStructure(name: String) = name in nativeStructureMap
34+
35+
fun generateEnumDefaultValue(type: GenerationType, value: Long): String {
36+
val simpleNames = type.className.simpleNames
37+
val className: String
38+
val enrichedEnum = if (simpleNames.size > 1) {
39+
className = simpleNames[0]
40+
if (GodotTypes.coreTypes.contains(className)) {
41+
coreTypeMap[className] ?: listOf()
42+
} else {
43+
classMap[className]!!.enums
44+
}.firstOrNull {
45+
it.identifier == type.identifier
46+
} ?: throw NoMatchingEnumFound(type.identifier)
47+
} else {
48+
className = ""
49+
globalEnumMap[type.identifier]!!
50+
}
51+
52+
val enumValue = enrichedEnum.values.firstOrNull { it.value == value }
53+
return if (enumValue != null) {
54+
enrichedEnum.identifier + "." + enumValue.name
55+
} else {
56+
enrichedEnum.identifier + "(" + value + ")"
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)