Skip to content

Commit

Permalink
dont write tiny mappings with missing ns's update kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Aug 30, 2024
1 parent 01329a5 commit 687b0ce
Show file tree
Hide file tree
Showing 11 changed files with 336 additions and 395 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store

.kotlin
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ allprojects {

repositories {
mavenCentral()
maven("https://maven.wagyourtail.xyz/snapshots")
}
}

Expand Down Expand Up @@ -51,6 +52,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
api("xyz.wagyourtail.commons:commons-kt:1.0.0-SNAPSHOT")
api("io.github.oshai:kotlin-logging:6.0.1")
api("com.squareup.okio:okio:3.7.0")
api("com.sschr15.annotations:jb-annotations-kmp:24.1.0")
Expand Down
3 changes: 1 addition & 2 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.archivesName
import xyz.wagyourtail.commons.gradle.shadow.ShadowJar

plugins {
Expand All @@ -20,7 +19,7 @@ dependencies {
val shadowJar by tasks.registering(ShadowJar::class) {
from(sourceSets.main.get().output)

archivesName.set(base.archivesName.get() + "-cli")
archiveBaseName.set(base.archivesName.get() + "-cli")
archiveClassifier = "all"
shadowContents.add(configurations.runtimeClasspath.get())

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kotlin.code.style=official

javaVersion=8
systemProp.kotlinVersion=1.9.20
systemProp.kotlinVersion=2.0.20

group=xyz.wagyourtail.unimined.mapping
archives_base_name=unimined-mapping-library
Expand Down
526 changes: 266 additions & 260 deletions kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package xyz.wagyourtail.unimined.mapping.formats.tiny.v2
import xyz.wagyourtail.unimined.mapping.EnvType
import xyz.wagyourtail.unimined.mapping.Namespace
import xyz.wagyourtail.unimined.mapping.formats.FormatWriter
import xyz.wagyourtail.unimined.mapping.formats.umf.UMFWriter.minus
import xyz.wagyourtail.unimined.mapping.jvms.ext.FieldOrMethodDescriptor
import xyz.wagyourtail.unimined.mapping.jvms.ext.FullyQualifiedName
import xyz.wagyourtail.unimined.mapping.jvms.ext.annotation.Annotation
Expand All @@ -16,6 +17,9 @@ import xyz.wagyourtail.unimined.mapping.tree.node._class.InnerClassNode
import xyz.wagyourtail.unimined.mapping.tree.node._class.member.WildcardNode
import xyz.wagyourtail.unimined.mapping.tree.node._constant.ConstantGroupNode
import xyz.wagyourtail.unimined.mapping.visitor.*
import xyz.wagyourtail.unimined.mapping.visitor.delegate.Delegator
import xyz.wagyourtail.unimined.mapping.visitor.delegate.NullDelegator
import xyz.wagyourtail.unimined.mapping.visitor.delegate.delegator

@Suppress("UNUSED_PARAMETER")
object TinyV2Writer : FormatWriter {
Expand All @@ -37,175 +41,114 @@ object TinyV2Writer : FormatWriter {
}

override fun write(append: (String) -> Unit, envType: EnvType): MappingVisitor {
return TinyV2MappingWriter(append)
return EmptyMappingVisitor().delegator(TinyV2WriterDelegator(append))
}

open class BaseTinyV2Writer<T: BaseVisitor<T>>(val into: (String) -> Unit, val parent: BaseTinyV2Writer<*>?, val indent: String = ""): BaseVisitor<T> {

val root: TinyV2MappingWriter get() = (this as? TinyV2MappingWriter) ?: parent!!.root
class TinyV2WriterDelegator(
val into: (String) -> Unit,
) : NullDelegator() {

var indent = ""
lateinit var namespaces: List<Namespace>

fun ((String) -> Unit).writeNamespaced(names: Map<Namespace, String>) {
root.namespaces.withIndex().forEach { (i, ns) ->
namespaces.withIndex().forEach { (i, ns) ->
this((names[ns]?.escape() ?: ""))
if (i != root.namespaces.lastIndex) {
if (i != namespaces.lastIndex) {
this("\t")
}
}
}

override fun visitEnd() {}

}

open class TinyV2MemberWriter<T: MemberVisitor<T>>(into: (String) -> Unit, parent: BaseTinyV2Writer<*>?, indent: String = ""): BaseTinyV2Writer<T>(into, parent, indent), MemberVisitor<T> {
override fun visitJavadoc(value: String, baseNs: Namespace, namespaces: Set<Namespace>): JavadocVisitor? {
if (value.isEmpty()) return null
into(indent)
into("c\t")
into(value.escape())
into("\n")
return null
}

fun visitSignature(value: String, baseNs: Namespace, namespaces: Set<Namespace>): SignatureVisitor? {
return null
}

override fun visitAccess(
type: AccessType,
value: AccessFlag,
condition: AccessConditions,
namespaces: Set<Namespace>
): AccessVisitor? {
return null
}

override fun visitAnnotation(
type: AnnotationType,
baseNs: Namespace,
annotation: Annotation,
namespaces: Set<Namespace>
): AnnotationVisitor? {
return null
}

}

class TinyV2MappingWriter(into: (String) -> Unit) : BaseTinyV2Writer<MappingVisitor>(into, null), MappingVisitor {
lateinit var namespaces: List<Namespace>

override fun nextUnnamedNs(): Namespace {
val ns = Namespace("unnamed_${namespaces.size}")
namespaces += ns
return ns
}

override fun visitHeader(vararg namespaces: String) {
override fun visitHeader(delegate: MappingVisitor, vararg namespaces: String) {
into("tiny\t2\t0\t")
this.namespaces = namespaces.map { Namespace(it) }
into(this.namespaces.joinToString("\t") { it.name })
into("\n")
into("\n\tescaped-names\n")
}

override fun visitPackage(names: Map<Namespace, PackageName>): PackageVisitor? {
return null
override fun visitEnd(delegate: BaseVisitor<*>) {
indent -= "\t"
}

override fun visitClass(names: Map<Namespace, InternalName>): ClassVisitor {
override fun visitClass(delegate: MappingVisitor, names: Map<Namespace, InternalName>): ClassVisitor? {
if (namespaces.first() !in names) return null
into("c\t")
into.writeNamespaced(names.mapValues { it.value.toString() })
into("\n")
return TinyV2ClassWriter(into, this)
indent += "\t"
return default.visitClass(delegate, names)
}

override fun visitConstantGroup(
type: ConstantGroupNode.InlineType,
name: String?,
baseNs: Namespace,
namespaces: Set<Namespace>
): ConstantGroupVisitor? {
return null
}

}

class TinyV2ClassWriter(into: (String) -> Unit, parent: BaseTinyV2Writer<*>?): TinyV2MemberWriter<ClassVisitor>(into, parent, "\t"), ClassVisitor {
override fun visitMethod(namespaces: Map<Namespace, Pair<String, MethodDescriptor?>>): MethodVisitor? {
// get desc in first namespace
val desc = namespaces[root.namespaces.first()]?.second ?: return null
override fun visitMethod(
delegate: ClassVisitor,
names: Map<Namespace, Pair<String, MethodDescriptor?>>
): MethodVisitor? {
if (namespaces.first() !in names) return null
val srcDesc = names[namespaces.first()]?.second ?: return null
into(indent)
into("m\t")
into(desc.toString())
into(srcDesc.toString().escape())
into("\t")
into.writeNamespaced(namespaces.mapValues { it.value.first })
into.writeNamespaced(names.mapValues { it.value.first })
into("\n")
return TinyV2MethodWriter(into, this)
indent += "\t"
return default.visitMethod(delegate, names)
}

override fun visitField(namespaces: Map<Namespace, Pair<String, FieldDescriptor?>>): FieldVisitor? {
// get desc in first namespace
val desc = namespaces[root.namespaces.first()]?.second ?: return null
override fun visitField(
delegate: ClassVisitor,
names: Map<Namespace, Pair<String, FieldDescriptor?>>
): FieldVisitor? {
if (namespaces.first() !in names) return null
val srcDesc = names[namespaces.first()]?.second ?: return null
into(indent)
into("f\t")
into(desc.toString())
into(srcDesc.toString().escape())
into("\t")
into.writeNamespaced(namespaces.mapValues { it.value.first })
into.writeNamespaced(names.mapValues { it.value.first })
into("\n")
return TinyV2FieldWriter(into, this, indent + "\t")
}

override fun visitInnerClass(
type: InnerClassNode.InnerType,
names: Map<Namespace, Pair<String, FullyQualifiedName?>>
): InnerClassVisitor? {
return null
}

override fun visitWildcard(
type: WildcardNode.WildcardType,
descs: Map<Namespace, FieldOrMethodDescriptor>
): WildcardVisitor? {
return null
indent += "\t"
return default.visitField(delegate, names)
}

override fun visitSeal(
type: SealedType,
name: InternalName?,
override fun visitJavadoc(
delegate: JavadocParentNode<*>,
value: String,
baseNs: Namespace,
namespaces: Set<Namespace>
): SealVisitor? {
return null
}

override fun visitInterface(
type: InterfacesType,
name: InternalName,
baseNs: Namespace,
namespaces: Set<Namespace>
): InterfaceVisitor? {
): JavadocVisitor? {
if (indent.isEmpty()) throw IllegalStateException("Top level javadoc?")
into(indent)
into("c\t")
into(value.escape())
into("\n")
return null
}

}

class TinyV2MethodWriter(into: (String) -> Unit, parent: BaseTinyV2Writer<*>?): TinyV2MemberWriter<MethodVisitor>(into, parent, "\t\t"), MethodVisitor {
override fun visitParameter(index: Int?, lvOrd: Int?, names: Map<Namespace, String>): ParameterVisitor? {
override fun visitParameter(
delegate: InvokableVisitor<*>,
index: Int?,
lvOrd: Int?,
names: Map<Namespace, String>
): ParameterVisitor? {
if (lvOrd == null) return null
into(indent)
into("p\t")
into(lvOrd.toString())
into("\t")
into.writeNamespaced(names)
into("\n")
return object : TinyV2MemberWriter<ParameterVisitor>(into, this, indent + "\t"), ParameterVisitor {}
indent += "\t"
return default.visitParameter(delegate, index, lvOrd, names)
}

override fun visitLocalVariable(
delegate: InvokableVisitor<*>,
lvOrd: Int,
startOp: Int?,
names: Map<Namespace, String>
): LocalVariableVisitor {
): LocalVariableVisitor? {
into(indent)
into("v\t")
into(lvOrd.toString())
Expand All @@ -214,20 +157,8 @@ object TinyV2Writer : FormatWriter {
into("\t\t") // skip lvt-idx
into.writeNamespaced(names)
into("\n")
return object : TinyV2MemberWriter<LocalVariableVisitor>(into, this, indent + "\t"), LocalVariableVisitor {}
}

override fun visitException(
type: ExceptionType,
exception: InternalName,
baseNs: Namespace,
namespaces: Set<Namespace>
): ExceptionVisitor? {
return null
}

}

class TinyV2FieldWriter(into: (String) -> Unit, parent: BaseTinyV2Writer<*>?, indent: String = ""): TinyV2MemberWriter<FieldVisitor>(into, parent, indent), FieldVisitor

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TinyV2ReadWriteTest {
companion object {
val mappings = """
tiny 2 0 intermediary named
escaped-names
c net/minecraft/class_3720 net/minecraft/block/entity/BlastFurnaceBlockEntity
c this is a comment block
m (Lnet/minecraft/class_2338;Lnet/minecraft/class_2680;)V <init> <init>
Expand Down

0 comments on commit 687b0ce

Please sign in to comment.