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

org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsDeclarationTable.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
/*
 * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
 * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
 */

package org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir

import org.jetbrains.kotlin.backend.common.serialization.GlobalDeclarationTable
import org.jetbrains.kotlin.backend.common.serialization.IdSignatureClashTracker
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.render

class JsUniqIdClashTracker : IdSignatureClashTracker {
    private val committedIdSignatures = mutableMapOf()

    override fun commit(declaration: IrDeclaration, signature: IdSignature) {
        if (!signature.isPublic) return // don't track local ids

        if (signature in committedIdSignatures) {
            val clashedDeclaration = committedIdSignatures[signature]!!
            val parent = declaration.parent
            val clashedParent = clashedDeclaration.parent
            if (declaration is IrTypeParameter && parent is IrSimpleFunction && parent.parent is IrProperty && parent !== clashedParent) {
                // Check whether they are type parameters of the same extension property but different accessors
                require(clashedParent is IrSimpleFunction)
                require(clashedParent.correspondingPropertySymbol === parent.correspondingPropertySymbol)
            } else {
                // TODO: handle clashes properly
                error("IdSignature clash: $signature; Existed declaration ${clashedDeclaration.render()} clashed with new ${declaration.render()}")
            }
        }

        committedIdSignatures[signature] = declaration
    }
}

class JsGlobalDeclarationTable(signatureSerializer: IdSignatureSerializer, builtIns: IrBuiltIns) :
    GlobalDeclarationTable(signatureSerializer, JsManglerIr, JsUniqIdClashTracker()) {
    init {
        loadKnownBuiltins(builtIns)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy