All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jtransc.plugin.lang.ExtraLangJTranscPlugin.kt Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.6.8
Show newest version
package com.jtransc.plugin.lang

import com.jtransc.ast.AstExpr
import com.jtransc.ast.AstProgram
import com.jtransc.ast.fqname
import com.jtransc.plugin.JTranscPlugin
import j.ProgramReflection
import java.lang.reflect.Method

class ExtraLangJTranscPlugin : JTranscPlugin() {
	override fun processAfterTreeShaking(program: AstProgram) {
		if (ProgramReflection::class.java.fqname !in program) return // ProgramReflection not referenced!
		val ProgramReflection = program[ProgramReflection::class.java.name.fqname]
		val ProgramReflection_getMethodByInfo = ProgramReflection.getMethodWithoutOverrides(j.ProgramReflection::getMethodByInfo.name) ?: return

		ProgramReflection_getMethodByInfo.replaceBodyOptBuild { args ->
			val (clazz, methodInfo) = args

			val constructor = program[Method::class.java.fqname].constructors.first()
			RETURN(AstExpr.NEW_WITH_CONSTRUCTOR(constructor.ref, listOf(clazz.expr, methodInfo.expr)))
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy