Decompilation support

- class header reader for KotlinMultifileClass, KotlinMultifileClassPart
- proper implClassName for multifile class members
This commit is contained in:
Dmitry Petrov
2015-09-08 16:35:25 +03:00
parent e88584742e
commit 0c951b2ed3
15 changed files with 207 additions and 70 deletions
@@ -27,10 +27,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.backend.common.bridges.Bridge;
import org.jetbrains.kotlin.backend.common.bridges.BridgesPackage;
import org.jetbrains.kotlin.codegen.annotation.AnnotatedWithOnlyTargetedAnnotations;
import org.jetbrains.kotlin.codegen.context.CodegenContext;
import org.jetbrains.kotlin.codegen.context.MethodContext;
import org.jetbrains.kotlin.codegen.context.PackageContext;
import org.jetbrains.kotlin.codegen.context.PackageFacadeContext;
import org.jetbrains.kotlin.codegen.context.*;
import org.jetbrains.kotlin.codegen.optimization.OptimizationMethodVisitor;
import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
@@ -163,15 +160,11 @@ public class FunctionCodegen {
jvmSignature.getGenericsSignature(),
getThrownExceptions(functionDescriptor, typeMapper));
if (owner instanceof PackageFacadeContext) {
Type ownerType = ((PackageFacadeContext) owner).getDelegateToClassType();
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, functionDescriptor, shortNameByAsmType(ownerType));
String implClassName = CodegenContextUtil.getImplClassNameByOwnerIfRequired(owner);
if (implClassName != null) {
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, functionDescriptor, implClassName);
}
else {
if (owner instanceof PackageContext) {
Type ownerType = ((PackageContext) owner).getPackagePartType();
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, functionDescriptor, shortNameByAsmType(ownerType));
}
if (CodegenContextUtil.isImplClassOwner(owner)) {
v.getSerializationBindings().put(METHOD_FOR_FUNCTION, functionDescriptor, asmMethod);
}
@@ -110,15 +110,12 @@ public class PropertyCodegen {
assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.TRAIT_IMPL
: "Generating property with a wrong kind (" + kind + "): " + descriptor;
if (context instanceof PackageFacadeContext) {
Type ownerType = ((PackageFacadeContext) context).getDelegateToClassType();
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, shortNameByAsmType(ownerType));
Type implClassType = CodegenContextUtil.getImplClassTypeByOwnerIfRequired(context);
if (implClassType != null) {
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, shortNameByAsmType(implClassType));
}
else {
if (context instanceof PackageContext) {
Type ownerType = ((PackageContext) context).getPackagePartType();
v.getSerializationBindings().put(IMPL_CLASS_NAME_FOR_CALLABLE, descriptor, shortNameByAsmType(ownerType));
}
if (CodegenContextUtil.isImplClassOwner(context)) {
assert declaration != null : "Declaration is null for different context: " + context;
boolean hasBackingField = hasBackingField(declaration, descriptor);
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2015 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.codegen.context
import org.jetbrains.kotlin.codegen.AsmUtil
import org.jetbrains.org.objectweb.asm.Type
public object CodegenContextUtil {
public @JvmStatic fun getImplClassTypeByOwnerIfRequired(owner: CodegenContext<*>): Type? =
when (owner) {
is PackageFacadeContext ->
owner.delegateToClassType
is PackageContext ->
owner.packagePartType
is MultifileClassOrPartContext ->
owner.filePartType
else ->
null
}
public @JvmStatic fun getImplClassNameByOwnerIfRequired(owner: CodegenContext<*>): String? =
getImplClassTypeByOwnerIfRequired(owner)?.let{ AsmUtil.shortNameByAsmType(it) }
public @JvmStatic fun isImplClassOwner(owner: CodegenContext<*>): Boolean =
!(owner is PackageFacadeContext || owner is MultifileClassContext)
}
@@ -21,26 +21,14 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
import org.jetbrains.org.objectweb.asm.Type;
public class MultifileClassContext extends FieldOwnerContext<PackageFragmentDescriptor> {
private final Type multifileClassType;
private final Type filePartType;
public class MultifileClassContext extends MultifileClassOrPartContext {
public MultifileClassContext(
PackageFragmentDescriptor descriptor,
CodegenContext parent,
Type multifileClassType,
Type filePartType
) {
super(descriptor, OwnerKind.PACKAGE, parent, null, null, null);
this.multifileClassType = multifileClassType;
this.filePartType = filePartType;
super(descriptor, parent, multifileClassType, filePartType);
}
public Type getMultifileClassType() {
return multifileClassType;
}
public Type getFilePartType() {
return filePartType;
}
}
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2015 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.codegen.context;
import org.jetbrains.kotlin.codegen.OwnerKind;
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
import org.jetbrains.org.objectweb.asm.Type;
public class MultifileClassOrPartContext extends FieldOwnerContext<PackageFragmentDescriptor> {
private final Type multifileClassType;
private final Type filePartType;
public MultifileClassOrPartContext(
PackageFragmentDescriptor descriptor,
CodegenContext parent,
Type multifileClassType,
Type filePartType
) {
super(descriptor, OwnerKind.PACKAGE, parent, null, null, null);
this.multifileClassType = multifileClassType;
this.filePartType = filePartType;
}
public Type getMultifileClassType() {
return multifileClassType;
}
public Type getFilePartType() {
return filePartType;
}
}
@@ -21,26 +21,14 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
import org.jetbrains.org.objectweb.asm.Type;
public class MultifileClassPartContext extends FieldOwnerContext<PackageFragmentDescriptor> {
private final Type multifileClassType;
private final Type filePartType;
public class MultifileClassPartContext extends MultifileClassOrPartContext {
public MultifileClassPartContext(
PackageFragmentDescriptor descriptor,
CodegenContext parent,
Type multifileClassType,
Type filePartType
) {
super(descriptor, OwnerKind.PACKAGE, parent, null, null, null);
this.multifileClassType = multifileClassType;
this.filePartType = filePartType;
super(descriptor, parent, multifileClassType, filePartType);
}
public Type getMultifileClassType() {
return multifileClassType;
}
public Type getFilePartType() {
return filePartType;
}
}