Reflection literals (no bound member references yet).
This commit is contained in:
committed by
Dmitry Petrov
parent
8b95992af1
commit
3c0cce4c48
@@ -17,20 +17,21 @@
|
||||
package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
|
||||
interface IrClassReference : IrDeclarationReference {
|
||||
override val descriptor: ClassDescriptor
|
||||
override val descriptor: ClassifierDescriptor
|
||||
}
|
||||
|
||||
class IrClassReferenceImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
type: KotlinType,
|
||||
descriptor: ClassDescriptor
|
||||
) : IrTerminalDeclarationReferenceBase<ClassDescriptor>(startOffset, endOffset, type, descriptor), IrClassReference {
|
||||
descriptor: ClassifierDescriptor
|
||||
) : IrTerminalDeclarationReferenceBase<ClassifierDescriptor>(startOffset, endOffset, type, descriptor), IrClassReference {
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
||||
return visitor.visitClassReference(this, data)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.expressions
|
||||
|
||||
import org.jetbrains.kotlin.ir.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
|
||||
interface IrGetClass : IrExpression {
|
||||
var argument : IrExpression
|
||||
}
|
||||
|
||||
class IrGetClassImpl(startOffset: Int, endOffset: Int, type: KotlinType) : IrExpressionBase(startOffset, endOffset, type), IrGetClass {
|
||||
constructor(startOffset: Int, endOffset: Int, type: KotlinType, argument: IrExpression) : this(startOffset, endOffset, type) {
|
||||
this.argument = argument
|
||||
}
|
||||
|
||||
private var argumentImpl: IrExpression? = null
|
||||
override var argument: IrExpression
|
||||
get() = argumentImpl!!
|
||||
set(value) {
|
||||
value.assertDetached()
|
||||
argumentImpl?.detach()
|
||||
argumentImpl = value
|
||||
value.setTreeLocation(this, CHILD_EXPRESSION_SLOT)
|
||||
}
|
||||
|
||||
override fun getChild(slot: Int): IrElement? =
|
||||
when (slot) {
|
||||
CHILD_EXPRESSION_SLOT -> argument
|
||||
else -> null
|
||||
}
|
||||
|
||||
override fun replaceChild(slot: Int, newChild: IrElement) {
|
||||
when (slot) {
|
||||
CHILD_EXPRESSION_SLOT -> argument = newChild.assertCast()
|
||||
}
|
||||
}
|
||||
|
||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
|
||||
return visitor.visitGetClass(this, data)
|
||||
}
|
||||
|
||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||
argument.accept(visitor, data)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -176,6 +176,9 @@ class RenderIrElementVisitor : IrElementVisitor<String, Nothing?> {
|
||||
override fun visitClassReference(expression: IrClassReference, data: Nothing?): String =
|
||||
"CLASS_REFERENCE ${expression.descriptor.render()} type=${expression.type.render()}"
|
||||
|
||||
override fun visitGetClass(expression: IrGetClass, data: Nothing?): String =
|
||||
"GET_CLASS type=${expression.type.render()}"
|
||||
|
||||
override fun visitTryCatch(tryCatch: IrTryCatch, data: Nothing?): String =
|
||||
"TRY_CATCH type=${tryCatch.type.render()}"
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ interface IrElementVisitor<out R, in D> {
|
||||
fun visitCall(expression: IrCall, data: D) = visitGeneralCall(expression, data)
|
||||
fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: D) = visitGeneralCall(expression, data)
|
||||
fun visitEnumConstructorCall(expression: IrEnumConstructorCall, data: D) = visitGeneralCall(expression, data)
|
||||
fun visitGetClass(expression: IrGetClass, data: D) = visitExpression(expression, data)
|
||||
|
||||
fun visitCallableReference(expression: IrCallableReference, data: D) = visitDeclarationReference(expression, data)
|
||||
fun visitClassReference(expression: IrClassReference, data: D) = visitDeclarationReference(expression, data)
|
||||
|
||||
Reference in New Issue
Block a user