Modify top-level/extension property hierarchy

- rename KTopLevelProperty to KTopLevelVariable
- create KTopLevelExtensionProperty, a subclass of KExtensionProperty
- create KTopLevelProperty, a superclass of KTopLevelVariable and
  KTopLevelExtensionProperty. (In the future, it will have a container of type
  KPackage.)
This commit is contained in:
Alexander Udalov
2014-07-01 17:12:47 +04:00
parent f73b8b9ff8
commit d32a02f21a
11 changed files with 83 additions and 35 deletions
@@ -2452,14 +2452,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (receiverParameter != null) {
Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE, getType(Class.class)};
factoryMethod = descriptor.isVar()
? method("mutableExtensionProperty", K_MUTABLE_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes)
: method("extensionProperty", K_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes);
? method("mutableTopLevelExtensionProperty", K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes)
: method("topLevelExtensionProperty", K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE, parameterTypes);
}
else {
Type[] parameterTypes = new Type[] {JAVA_STRING_TYPE, K_PACKAGE_IMPL_TYPE};
factoryMethod = descriptor.isVar()
? method("mutableTopLevelProperty", K_MUTABLE_TOP_LEVEL_PROPERTY_IMPL_TYPE, parameterTypes)
: method("topLevelProperty", K_TOP_LEVEL_PROPERTY_IMPL_TYPE, parameterTypes);
? method("mutableTopLevelVariable", K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE, parameterTypes)
: method("topLevelVariable", K_TOP_LEVEL_VARIABLE_IMPL_TYPE, parameterTypes);
}
v.visitLdcInsn(descriptor.getName().asString());
@@ -43,10 +43,10 @@ public class AsmTypeConstants {
public static final Type K_CLASS_IMPL_TYPE = reflectInternal("KClassImpl");
public static final Type K_PACKAGE_IMPL_TYPE = reflectInternal("KPackageImpl");
public static final Type K_TOP_LEVEL_PROPERTY_IMPL_TYPE = reflectInternal("KTopLevelPropertyImpl");
public static final Type K_MUTABLE_TOP_LEVEL_PROPERTY_IMPL_TYPE = reflectInternal("KMutableTopLevelPropertyImpl");
public static final Type K_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KExtensionPropertyImpl");
public static final Type K_MUTABLE_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KMutableExtensionPropertyImpl");
public static final Type K_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KTopLevelVariableImpl");
public static final Type K_MUTABLE_TOP_LEVEL_VARIABLE_IMPL_TYPE = reflectInternal("KMutableTopLevelVariableImpl");
public static final Type K_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KTopLevelExtensionPropertyImpl");
public static final Type K_MUTABLE_TOP_LEVEL_EXTENSION_PROPERTY_IMPL_TYPE = reflectInternal("KMutableTopLevelExtensionPropertyImpl");
public static final String REFLECTION_INTERNAL_PACKAGE = reflectInternal("InternalPackage").getInternalName();
@@ -49,12 +49,12 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
public fun getKExtensionFunction(n: Int): ClassDescriptor = find("KExtensionFunction$n")
public fun getKMemberFunction(n: Int): ClassDescriptor = find("KMemberFunction$n")
public val kTopLevelProperty: ClassDescriptor by ClassLookup
public val kMutableTopLevelProperty: ClassDescriptor by ClassLookup
public val kTopLevelVariable: ClassDescriptor by ClassLookup
public val kMutableTopLevelVariable: ClassDescriptor by ClassLookup
public val kMemberProperty: ClassDescriptor by ClassLookup
public val kMutableMemberProperty: ClassDescriptor by ClassLookup
public val kExtensionProperty: ClassDescriptor by ClassLookup
public val kMutableExtensionProperty: ClassDescriptor by ClassLookup
public val kTopLevelExtensionProperty: ClassDescriptor by ClassLookup
public val kMutableTopLevelExtensionProperty: ClassDescriptor by ClassLookup
public fun getKFunctionType(
annotations: Annotations,
@@ -85,14 +85,14 @@ public class ReflectionTypes(private val module: ModuleDescriptor) {
mutable: Boolean
): JetType {
val classDescriptor = if (mutable) when {
extensionProperty -> kMutableExtensionProperty
extensionProperty -> kMutableTopLevelExtensionProperty
receiverType != null -> kMutableMemberProperty
else -> kMutableTopLevelProperty
else -> kMutableTopLevelVariable
}
else when {
extensionProperty -> kExtensionProperty
extensionProperty -> kTopLevelExtensionProperty
receiverType != null -> kMemberProperty
else -> kTopLevelProperty
else -> kTopLevelVariable
}
if (ErrorUtils.isError(classDescriptor)) {
@@ -8,6 +8,7 @@ var Int.meaning: Long
fun test() {
val f = String::countCharacters
f : KTopLevelExtensionProperty<String, Int>
f : KExtensionProperty<String, Int>
<!TYPE_MISMATCH!>f<!> : KMutableExtensionProperty<String, Int>
f.get("abc") : Int
@@ -15,7 +16,9 @@ fun test() {
val g = Int::meaning
g : KTopLevelExtensionProperty<Int, Long>
g : KExtensionProperty<Int, Long>
g : KMutableTopLevelExtensionProperty<Int, Long>
g : KMutableExtensionProperty<Int, Long>
g.get(0) : Long
g.set(1, 0L)
@@ -4,8 +4,11 @@ val y: String get() = "y"
fun testX() {
val xx = ::x
xx : KMutableTopLevelProperty<Int>
xx : KMutableTopLevelVariable<Int>
xx : KTopLevelProperty<Int>
xx : KTopLevelVariable<Int>
xx : KMutableProperty<Int>
xx : KMutableVariable<Int>
xx : KProperty<Int>
xx : KCallable<Int>
@@ -17,7 +20,7 @@ fun testX() {
fun testY() {
val yy = ::y
<!TYPE_MISMATCH!>yy<!> : KMutableTopLevelProperty<String>
yy : KTopLevelProperty<String>
yy : KTopLevelVariable<String>
<!TYPE_MISMATCH!>yy<!> : KMutableProperty<String>
yy : KProperty<String>
yy : KCallable<String>