Skip to content

Commit

Permalink
Use unsigned number types
Browse files Browse the repository at this point in the history
  • Loading branch information
turansky committed Dec 18, 2024
1 parent 001fa73 commit ff094dc
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions buildSrc/src/main/kotlin/karakum/browser/IDL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ private data class MethodReturnData(
) : MemberNumberData()

private val NUMBER_TYPE_MAP = mapOf(
"octet" to "Short /* unsigned byte */",
"octet" to "UByte",

"short" to "Short",
"unsigned short" to "Short",
"unsigned short" to "UShort",

"float" to "Float",

"double" to "Double",
"unrestricted double" to "Double",

"long" to "Int",
"unsigned long" to "Int",
"unsigned long" to "UInt",

"long long" to "JsLong",
"unsigned long long" to "JsLong",
Expand Down Expand Up @@ -165,10 +165,15 @@ internal object IDLRegistry {
.removePrefix("unrestricted ")
.substringBefore(" = ")

val type = getNumberType(data.substringBeforeLast(" ").removeSuffix("?"))
var type = getNumberType(data.substringBeforeLast(" ").removeSuffix("?"))
?: return emptySequence()

val name = data.substringAfterLast(" ")

// TEMP
if ((name == "length" || name == "size") && type == "UInt")
type = "Int"

return sequenceOf(
PropertyData(
className = className,
Expand All @@ -195,13 +200,19 @@ internal object IDLRegistry {
.map { it.substringAfter("] ") }
.map { it.removePrefix("optional ") }
.mapNotNull { psource ->
val type = getNumberType(psource.substringBeforeLast(" ").removeSuffix("?"))
var type = getNumberType(psource.substringBeforeLast(" ").removeSuffix("?"))
?: return@mapNotNull null

val name = psource.substringAfterLast(" ")

// TEMP
if (name == "index" && type == "UInt")
type = "Int"

ParameterData(
className = className,
methodName = methodName,
parameterName = psource.substringAfterLast(" "),
parameterName = name,
parameterType = type,
)
}
Expand Down

0 comments on commit ff094dc

Please sign in to comment.