[FIR/IR generator] Move usedTypes to AbstractElement, rename it
This commit is contained in:
committed by
Space Team
parent
e4078d163b
commit
19ff050eae
-1
@@ -22,7 +22,6 @@ fun Implementation.generateCode(generationPath: File): GeneratedFile =
|
||||
this.typeName,
|
||||
fileSuppressions = listOf("DuplicatedCode", "unused"),
|
||||
) {
|
||||
addAllImports(usedTypes)
|
||||
ImplementationPrinter(this).printImplementation(this@generateCode)
|
||||
}
|
||||
|
||||
|
||||
@@ -208,7 +208,7 @@ object IrTree : AbstractTreeBuilder() {
|
||||
+field("isCrossinline", boolean)
|
||||
+field("isNoinline", boolean)
|
||||
+field("isHidden", boolean) {
|
||||
usedTypes.add(idSignatureType)
|
||||
additionalImports.add(idSignatureType)
|
||||
kDoc = """
|
||||
If `true`, the value parameter does not participate in [IdSignature] computation.
|
||||
|
||||
@@ -487,7 +487,7 @@ object IrTree : AbstractTreeBuilder() {
|
||||
+field("name", type<Name>(), mutable = false)
|
||||
+field("irBuiltins", type(Packages.tree, "IrBuiltIns"), mutable = false)
|
||||
+listField("files", file, mutability = MutableList)
|
||||
usedTypes += ArbitraryImportable(Packages.tree, "UNDEFINED_OFFSET")
|
||||
additionalImports += ArbitraryImportable(Packages.tree, "UNDEFINED_OFFSET")
|
||||
+field("startOffset", int, mutable = false) {
|
||||
baseGetter = "UNDEFINED_OFFSET"
|
||||
}
|
||||
@@ -722,8 +722,8 @@ object IrTree : AbstractTreeBuilder() {
|
||||
visibility = Visibility.PROTECTED
|
||||
}
|
||||
|
||||
usedTypes += ArbitraryImportable(Packages.exprs, "checkArgumentSlotAccess")
|
||||
generationCallback = {
|
||||
addImport(ArbitraryImportable(Packages.exprs, "checkArgumentSlotAccess"))
|
||||
val indexParam = FunctionParameter("index", StandardTypes.int)
|
||||
val valueArgumentParam = FunctionParameter("valueArgument", expression.copy(nullable = true))
|
||||
val typeArgumentParam = FunctionParameter("type", irTypeType.copy(nullable = true))
|
||||
|
||||
-2
@@ -124,8 +124,6 @@ class Element(
|
||||
|
||||
override var kDoc: String? = null
|
||||
|
||||
val usedTypes = mutableListOf<Importable>()
|
||||
|
||||
override fun toString() = name
|
||||
|
||||
operator fun TypeVariable.unaryPlus() = apply {
|
||||
|
||||
-1
@@ -137,7 +137,6 @@ private class ElementPrinter(printer: SmartPrinter) : AbstractElementPrinter<Ele
|
||||
|
||||
fun printElements(generationPath: File, model: Model) = model.elements.map { element ->
|
||||
printGeneratedType(generationPath, TREE_GENERATOR_README, element.packageName, element.typeName) {
|
||||
addAllImports(element.usedTypes)
|
||||
ElementPrinter(this).printElement(element)
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -166,6 +166,15 @@ abstract class AbstractElement<Element, Field, Implementation>(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Types/functions that you want to additionally import in the file with the element class.
|
||||
*
|
||||
* This is useful if, for example, default values of fields reference classes or functions from other packages.
|
||||
*
|
||||
* Note that classes referenced in field types will be imported automatically.
|
||||
*/
|
||||
val additionalImports = mutableListOf<Importable>()
|
||||
|
||||
final override fun get(fieldName: String): Field? {
|
||||
return allFields.firstOrNull { it.name == fieldName }
|
||||
}
|
||||
|
||||
+1
@@ -31,6 +31,7 @@ abstract class AbstractElementPrinter<Element : AbstractElement<Element, Field,
|
||||
|
||||
context(ImportCollector)
|
||||
fun printElement(element: Element) {
|
||||
addAllImports(element.additionalImports)
|
||||
printer.run {
|
||||
val kind = element.kind ?: error("Expected non-null element kind")
|
||||
|
||||
|
||||
+8
-1
@@ -42,7 +42,14 @@ abstract class AbstractImplementation<Implementation, Element, Field>(
|
||||
|
||||
override val packageName = element.packageName + ".impl"
|
||||
|
||||
val usedTypes = mutableListOf<Importable>()
|
||||
/**
|
||||
* Types/functions that you want to additionally import in the file with the implementation class.
|
||||
*
|
||||
* This is useful if, for example, default values of fields reference classes or functions from other packages.
|
||||
*
|
||||
* Note that classes referenced in field types will be imported automatically.
|
||||
*/
|
||||
val additionalImports = mutableListOf<Importable>()
|
||||
|
||||
init {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ abstract class AbstractImplementationPrinter<Implementation, Element, Implementa
|
||||
|
||||
context(ImportCollector)
|
||||
fun printImplementation(implementation: Implementation) {
|
||||
addAllImports(implementation.additionalImports)
|
||||
printer.run {
|
||||
buildSet {
|
||||
if (implementation.requiresOptIn) {
|
||||
|
||||
+1
-1
@@ -156,7 +156,7 @@ abstract class AbstractImplementationConfigurator<Implementation, Element, Imple
|
||||
* Note that classes referenced in field types will be imported automatically.
|
||||
*/
|
||||
fun additionalImports(vararg importables: Importable) {
|
||||
importables.forEach { implementation.usedTypes += it }
|
||||
implementation.additionalImports.addAll(importables)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user