mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-11 02:50:15 +08:00
Optimize codegen
This commit is contained in:
parent
f9132124e7
commit
e0c1600001
@ -53,14 +53,14 @@ class CodegenScope : MutableList<Replacer> by mutableListOf() {
|
|||||||
@RegionCodegenDsl
|
@RegionCodegenDsl
|
||||||
operator fun RegionCodegen.invoke(ktTypes: Collection<KtType>) {
|
operator fun RegionCodegen.invoke(ktTypes: Collection<KtType>) {
|
||||||
add(Replacer {
|
add(Replacer {
|
||||||
it.replace(Regex("""//// region $regionName CODEGEN START ////([\s\S]*?)//// endregion $regionName CODEGEN END ////""")) {
|
it.replace(Regex("""//// region $regionName CODEGEN ////([\s\S]*?)//// endregion $regionName CODEGEN ////""")) {
|
||||||
val code = CodegenScope().apply { (this@invoke as Codegen).invoke(*ktTypes.toTypedArray()) }.applyTo("")
|
val code = CodegenScope().apply { (this@invoke as Codegen).invoke(*ktTypes.toTypedArray()) }.applyTo("")
|
||||||
"""
|
"""
|
||||||
|//// region $regionName CODEGEN START ////
|
|//// region $regionName CODEGEN ////
|
||||||
|
|
|
|
||||||
|$code
|
|$code
|
||||||
|
|
|
|
||||||
|//// endregion $regionName CODEGEN END ////
|
|//// endregion $regionName CODEGEN ////
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -92,8 +92,8 @@ val KtType.lowerCaseName: String get() = this.standardName.toLowerCase()
|
|||||||
inline fun kCode(@Language("kt") source: String) = source.trimIndent()
|
inline fun kCode(@Language("kt") source: String) = source.trimIndent()
|
||||||
|
|
||||||
fun codegen(targetFile: String, block: CodegenScope.() -> Unit) {
|
fun codegen(targetFile: String, block: CodegenScope.() -> Unit) {
|
||||||
//// region PrimitiveValue CODEGEN START ////
|
//// region PrimitiveValue CODEGEN ////
|
||||||
//// region PrimitiveValue CODEGEN END ////
|
//// region PrimitiveValue CODEGEN ////
|
||||||
|
|
||||||
targetFile.findFileSmart().also {
|
targetFile.findFileSmart().also {
|
||||||
println("Codegen target: ${it.absolutePath}")
|
println("Codegen target: ${it.absolutePath}")
|
||||||
|
@ -40,13 +40,13 @@ internal abstract class SettingImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//// region Setting.value primitives CODEGEN START ////
|
//// region Setting.value primitives CODEGEN ////
|
||||||
|
|
||||||
// TODO: 2020/6/19 CODEGEN
|
// TODO: 2020/6/19 CODEGEN
|
||||||
|
|
||||||
fun Setting.value(value: Int): IntValue = TODO("codegen")
|
fun Setting.value(value: Int): IntValue = TODO("codegen")
|
||||||
|
|
||||||
//// endregion Setting.value primitives CODEGEN END ////
|
//// endregion Setting.value primitives CODEGEN ////
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
* https://github.com/mamoe/mirai/blob/master/LICENSE
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
|
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "unused")
|
||||||
|
|
||||||
package net.mamoe.mirai.console.setting
|
package net.mamoe.mirai.console.setting
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ typealias ValueSerializer<T> = KSerializer<Value<T>>
|
|||||||
interface PrimitiveValue<T> : Value<T>
|
interface PrimitiveValue<T> : Value<T>
|
||||||
|
|
||||||
|
|
||||||
//// region PrimitiveValues CODEGEN START ////
|
//// region PrimitiveValues CODEGEN ////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a non-null [Byte] value.
|
* Represents a non-null [Byte] value.
|
||||||
@ -96,7 +96,7 @@ interface BooleanValue : PrimitiveValue<Boolean>
|
|||||||
interface StringValue : PrimitiveValue<String>
|
interface StringValue : PrimitiveValue<String>
|
||||||
|
|
||||||
|
|
||||||
//// endregion PrimitiveValues CODEGEN END ////
|
//// endregion PrimitiveValues CODEGEN ////
|
||||||
|
|
||||||
|
|
||||||
@MiraiExperimentalAPI
|
@MiraiExperimentalAPI
|
||||||
@ -120,13 +120,13 @@ interface CompositeListValue<T> : ListValue<Value<T>>
|
|||||||
interface PrimitiveListValue<T> : ListValue<T>
|
interface PrimitiveListValue<T> : ListValue<T>
|
||||||
|
|
||||||
|
|
||||||
//// region PrimitiveListValue CODEGEN START ////
|
//// region PrimitiveListValue CODEGEN ////
|
||||||
|
|
||||||
interface PrimitiveIntListValue<T> : PrimitiveListValue<T>
|
interface PrimitiveIntListValue<T> : PrimitiveListValue<T>
|
||||||
interface PrimitiveLongListValue<T> : PrimitiveListValue<T>
|
interface PrimitiveLongListValue<T> : PrimitiveListValue<T>
|
||||||
// TODO + codegen
|
// TODO + codegen
|
||||||
|
|
||||||
//// endregion PrimitiveListValue CODEGEN END ////
|
//// endregion PrimitiveListValue CODEGEN ////
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,13 +147,13 @@ interface CompositeSetValue<T> : SetValue<Value<T>>
|
|||||||
interface PrimitiveSetValue<T> : SetValue<T>
|
interface PrimitiveSetValue<T> : SetValue<T>
|
||||||
|
|
||||||
|
|
||||||
//// region PrimitiveSetValue CODEGEN START ////
|
//// region PrimitiveSetValue CODEGEN ////
|
||||||
|
|
||||||
interface PrimitiveIntSetValue<T> : PrimitiveSetValue<T>
|
interface PrimitiveIntSetValue<T> : PrimitiveSetValue<T>
|
||||||
interface PrimitiveLongSetValue<T> : PrimitiveSetValue<T>
|
interface PrimitiveLongSetValue<T> : PrimitiveSetValue<T>
|
||||||
// TODO + codegen
|
// TODO + codegen
|
||||||
|
|
||||||
//// endregion PrimitiveSetValue CODEGEN END ////
|
//// endregion PrimitiveSetValue CODEGEN ////
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -166,13 +166,13 @@ interface CompositeMapValue<K, V> : MapValue<Value<K>, Value<V>>
|
|||||||
interface PrimitiveMapValue<K, V> : MapValue<K, V>
|
interface PrimitiveMapValue<K, V> : MapValue<K, V>
|
||||||
|
|
||||||
|
|
||||||
//// region PrimitiveMapValue CODEGEN START ////
|
//// region PrimitiveMapValue CODEGEN ////
|
||||||
|
|
||||||
interface PrimitiveIntIntMapValue : PrimitiveMapValue<Int, Int>
|
interface PrimitiveIntIntMapValue : PrimitiveMapValue<Int, Int>
|
||||||
interface PrimitiveIntLongMapValue : PrimitiveMapValue<Int, Long>
|
interface PrimitiveIntLongMapValue : PrimitiveMapValue<Int, Long>
|
||||||
// TODO + codegen
|
// TODO + codegen
|
||||||
|
|
||||||
//// endregion PrimitiveSetValue CODEGEN END ////
|
//// endregion PrimitiveSetValue CODEGEN ////
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user