[JS IR BE] Arrays, varargs
This commit is contained in:
+25
@@ -87,6 +87,18 @@ class IrSimpleBuiltinOperatorDescriptorImpl(
|
||||
|
||||
override fun getReturnType(): KotlinType = returnType
|
||||
override fun getValueParameters(): List<ValueParameterDescriptor> = valueParameters
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return this === other ||
|
||||
other is IrSimpleBuiltinOperatorDescriptorImpl &&
|
||||
name == other.name &&
|
||||
valueParameters.map { it.type } == other.valueParameters.map { it.type } &&
|
||||
containingDeclaration == other.containingDeclaration
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return (containingDeclaration.hashCode() * 31 + name.hashCode()) * 31 + valueParameters.map { it.type }.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
class IrBuiltinValueParameterDescriptorImpl(
|
||||
@@ -118,4 +130,17 @@ class IrBuiltinValueParameterDescriptorImpl(
|
||||
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
|
||||
return visitor.visitValueParameterDescriptor(this, data)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return this === other ||
|
||||
other is IrBuiltinValueParameterDescriptorImpl &&
|
||||
name == other.name &&
|
||||
index == other.index &&
|
||||
type == other.type &&
|
||||
containingDeclaration == other.containingDeclaration
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return (name.hashCode() * 31 + index) * 31 + type.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -45,4 +45,15 @@ class IrBuiltinsPackageFragmentDescriptorImpl(
|
||||
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>) {
|
||||
visitor.visitPackageFragmentDescriptor(this, null)
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return this === other ||
|
||||
other is IrBuiltinsPackageFragmentDescriptorImpl &&
|
||||
fqName == other.fqName &&
|
||||
containingModule == other.containingModule
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return containingModule.hashCode() * 31 + fqName.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,13 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
private val typeRemapper: TypeRemapper
|
||||
) : IrElementTransformerVoid() {
|
||||
|
||||
init {
|
||||
// TODO refactor
|
||||
(typeRemapper as? DeepCopyTypeRemapper)?.let {
|
||||
it.deepCopy = this
|
||||
}
|
||||
}
|
||||
|
||||
private fun mapDeclarationOrigin(origin: IrDeclarationOrigin) = origin
|
||||
private fun mapStatementOrigin(origin: IrStatementOrigin?) = origin
|
||||
|
||||
|
||||
@@ -6,12 +6,20 @@
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrTypeProjectionImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.originalKotlinType
|
||||
|
||||
class DeepCopyTypeRemapper(
|
||||
private val symbolRemapper: SymbolRemapper
|
||||
) : TypeRemapper {
|
||||
|
||||
lateinit var deepCopy: DeepCopyIrTreeWithSymbols
|
||||
|
||||
override fun enterScope(irTypeParametersContainer: IrTypeParametersContainer) {
|
||||
// TODO
|
||||
}
|
||||
@@ -20,6 +28,26 @@ class DeepCopyTypeRemapper(
|
||||
// TODO
|
||||
}
|
||||
|
||||
override fun remapType(type: IrType): IrType = type // TODO
|
||||
// TODO This is a hack
|
||||
override fun remapType(type: IrType): IrType {
|
||||
if (type !is IrSimpleType) return type
|
||||
|
||||
val arguments = type.arguments.map {
|
||||
if (it is IrTypeProjection) {
|
||||
IrTypeProjectionImpl(this.remapType(it.type), it.variance)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
val annotations = type.annotations.map { it.transform(deepCopy, null) as IrCall }
|
||||
|
||||
return IrSimpleTypeImpl(
|
||||
type.originalKotlinType,
|
||||
symbolRemapper.getReferencedClassifier(type.classifier),
|
||||
type.hasQuestionMark,
|
||||
arguments,
|
||||
annotations)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.*
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable
|
||||
@@ -25,6 +26,9 @@ import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
|
||||
interface ReferenceSymbolTable {
|
||||
fun referenceClass(descriptor: ClassDescriptor): IrClassSymbol
|
||||
@@ -54,7 +58,7 @@ open class SymbolTable : ReferenceSymbolTable {
|
||||
val unboundSymbols = linkedSetOf<S>()
|
||||
|
||||
abstract fun get(d: D): S?
|
||||
protected abstract fun set(d: D, s: S)
|
||||
abstract fun set(d: D, s: S)
|
||||
|
||||
inline fun declare(d: D, createSymbol: () -> S, createOwner: (S) -> B): B {
|
||||
val existing = get(d)
|
||||
@@ -92,6 +96,13 @@ open class SymbolTable : ReferenceSymbolTable {
|
||||
override fun set(d: D, s: S) {
|
||||
descriptorToSymbol[d] = s
|
||||
}
|
||||
|
||||
fun copyTo(other: FlatSymbolTable<D, B, S>) {
|
||||
for ((d, s) in descriptorToSymbol) {
|
||||
other.descriptorToSymbol[d] = s
|
||||
}
|
||||
other.unboundSymbols.addAll(unboundSymbols)
|
||||
}
|
||||
}
|
||||
|
||||
private class ScopedSymbolTable<D : DeclarationDescriptor, B : IrSymbolOwner, S : IrBindableSymbol<D, B>>
|
||||
@@ -411,6 +422,51 @@ open class SymbolTable : ReferenceSymbolTable {
|
||||
else ->
|
||||
throw IllegalArgumentException("Unexpected value descriptor: $value")
|
||||
}
|
||||
|
||||
fun loadModule(module: IrModuleFragment) {
|
||||
module.acceptVoid(object: IrElementVisitorVoid {
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitClass(declaration: IrClass) {
|
||||
// TODO should we check there are no conflicts?
|
||||
classSymbolTable.descriptorToSymbol[declaration.descriptor] = declaration.symbol
|
||||
super.visitClass(declaration)
|
||||
}
|
||||
|
||||
override fun visitConstructor(declaration: IrConstructor) {
|
||||
constructorSymbolTable.descriptorToSymbol[declaration.descriptor] = declaration.symbol
|
||||
super.visitConstructor(declaration)
|
||||
}
|
||||
|
||||
override fun visitEnumEntry(declaration: IrEnumEntry) {
|
||||
enumEntrySymbolTable.descriptorToSymbol[declaration.descriptor] = declaration.symbol
|
||||
super.visitEnumEntry(declaration)
|
||||
}
|
||||
|
||||
override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment) {
|
||||
externalPackageFragmentTable.descriptorToSymbol[declaration.symbol.descriptor] = declaration.symbol
|
||||
super.visitExternalPackageFragment(declaration)
|
||||
}
|
||||
|
||||
override fun visitField(declaration: IrField) {
|
||||
fieldSymbolTable.descriptorToSymbol[declaration.descriptor] = declaration.symbol
|
||||
super.visitField(declaration)
|
||||
}
|
||||
|
||||
override fun visitSimpleFunction(declaration: IrSimpleFunction) {
|
||||
simpleFunctionSymbolTable.descriptorToSymbol[declaration.descriptor] = declaration.symbol
|
||||
super.visitSimpleFunction(declaration)
|
||||
}
|
||||
|
||||
override fun visitTypeParameter(declaration: IrTypeParameter) {
|
||||
// What about scoped type parameters?
|
||||
globalTypeParameterSymbolTable.descriptorToSymbol[declaration.descriptor] = declaration.symbol
|
||||
super.visitTypeParameter(declaration)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <T, D: DeclarationDescriptor> SymbolTable.withScope(owner: D, block: SymbolTable.(D) -> T): T {
|
||||
|
||||
Reference in New Issue
Block a user