Remove unused parameter of JetTypeMapper#mapOwner, simplify lots of code

This commit is contained in:
Alexander Udalov
2015-09-14 19:57:02 +03:00
parent 90cef6553c
commit 7c0780455a
12 changed files with 86 additions and 137 deletions
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.codegen package org.jetbrains.kotlin.codegen
import org.jetbrains.kotlin.codegen.binding.CodegenBinding import org.jetbrains.kotlin.codegen.binding.CodegenBinding
import org.jetbrains.kotlin.codegen.context.CodegenContext
import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.psi.JetClass import org.jetbrains.kotlin.psi.JetClass
@@ -25,8 +24,8 @@ import org.jetbrains.kotlin.psi.JetClassOrObject
import org.jetbrains.kotlin.psi.JetElement import org.jetbrains.kotlin.psi.JetElement
import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue
import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.kotlin.resolve.jvm.diagnostics.OtherOrigin
import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmOverloadsAnnotation import org.jetbrains.kotlin.resolve.jvm.annotations.hasJvmOverloadsAnnotation
import org.jetbrains.kotlin.resolve.jvm.diagnostics.OtherOrigin
import org.jetbrains.org.objectweb.asm.Opcodes import org.jetbrains.org.objectweb.asm.Opcodes
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
@@ -39,12 +38,13 @@ public class DefaultParameterValueSubstitutor(val state: GenerationState) {
* If all of the parameters of the specified constructor declare default values, * If all of the parameters of the specified constructor declare default values,
* generates a no-argument constructor that passes default values for all arguments. * generates a no-argument constructor that passes default values for all arguments.
*/ */
fun generateConstructorOverloadsIfNeeded(constructorDescriptor: ConstructorDescriptor, fun generateConstructorOverloadsIfNeeded(
classBuilder: ClassBuilder, constructorDescriptor: ConstructorDescriptor,
context: CodegenContext<*>, classBuilder: ClassBuilder,
classOrObject: JetClassOrObject) { contextKind: OwnerKind,
if (generateOverloadsIfNeeded(classOrObject, constructorDescriptor, constructorDescriptor, classOrObject: JetClassOrObject
context, classBuilder)) { ) {
if (generateOverloadsIfNeeded(classOrObject, constructorDescriptor, constructorDescriptor, contextKind, classBuilder)) {
return return
} }
@@ -52,8 +52,7 @@ public class DefaultParameterValueSubstitutor(val state: GenerationState) {
return return
} }
generateOverloadWithSubstitutedParameters(constructorDescriptor, constructorDescriptor, classBuilder, classOrObject, generateOverloadWithSubstitutedParameters(constructorDescriptor, constructorDescriptor, classBuilder, classOrObject, contextKind,
context,
constructorDescriptor.countDefaultParameters()) constructorDescriptor.countDefaultParameters())
} }
@@ -70,21 +69,25 @@ public class DefaultParameterValueSubstitutor(val state: GenerationState) {
* implementation in the companion object class) * implementation in the companion object class)
* @return true if the overloads annotation was found on the element, false otherwise * @return true if the overloads annotation was found on the element, false otherwise
*/ */
fun generateOverloadsIfNeeded(methodElement: JetElement?, fun generateOverloadsIfNeeded(
functionDescriptor: FunctionDescriptor, methodElement: JetElement?,
delegateFunctionDescriptor: FunctionDescriptor, functionDescriptor: FunctionDescriptor,
owner: CodegenContext<*>, delegateFunctionDescriptor: FunctionDescriptor,
classBuilder: ClassBuilder): Boolean { contextKind: OwnerKind,
classBuilder: ClassBuilder
): Boolean {
if (!functionDescriptor.hasJvmOverloadsAnnotation()) { if (!functionDescriptor.hasJvmOverloadsAnnotation()) {
return false return false
} }
val count = functionDescriptor.countDefaultParameters() val count = functionDescriptor.countDefaultParameters()
val context = owner.intoFunction(functionDescriptor)
for (i in 1..count) { for (i in 1..count) {
generateOverloadWithSubstitutedParameters(functionDescriptor, delegateFunctionDescriptor, classBuilder, methodElement, context, i) generateOverloadWithSubstitutedParameters(
functionDescriptor, delegateFunctionDescriptor, classBuilder, methodElement, contextKind, i
)
} }
return true return true
} }
@@ -102,18 +105,19 @@ public class DefaultParameterValueSubstitutor(val state: GenerationState) {
* implementation in the companion object class) * implementation in the companion object class)
* @param methodElement the PSI element for the method implementation (used in diagnostic messages only) * @param methodElement the PSI element for the method implementation (used in diagnostic messages only)
*/ */
fun generateOverloadWithSubstitutedParameters(functionDescriptor: FunctionDescriptor, private fun generateOverloadWithSubstitutedParameters(
delegateFunctionDescriptor: FunctionDescriptor, functionDescriptor: FunctionDescriptor,
classBuilder: ClassBuilder, delegateFunctionDescriptor: FunctionDescriptor,
methodElement: JetElement?, classBuilder: ClassBuilder,
context: CodegenContext<*>, methodElement: JetElement?,
substituteCount: Int) { contextKind: OwnerKind,
substituteCount: Int
) {
val typeMapper = state.typeMapper val typeMapper = state.typeMapper
val isStatic = AsmUtil.isStaticMethod(contextKind, functionDescriptor)
val isStatic = AsmUtil.isStaticMethod(context.getContextKind(), functionDescriptor)
val flags = AsmUtil.getVisibilityAccessFlag(functionDescriptor) or (if (isStatic) Opcodes.ACC_STATIC else 0) val flags = AsmUtil.getVisibilityAccessFlag(functionDescriptor) or (if (isStatic) Opcodes.ACC_STATIC else 0)
val remainingParameters = getRemainingParameters(functionDescriptor.getOriginal(), substituteCount) val remainingParameters = getRemainingParameters(functionDescriptor.getOriginal(), substituteCount)
val signature = typeMapper.mapSignature(functionDescriptor, context.getContextKind(), remainingParameters) val signature = typeMapper.mapSignature(functionDescriptor, contextKind, remainingParameters)
val mv = classBuilder.newMethod(OtherOrigin(methodElement, functionDescriptor), flags, val mv = classBuilder.newMethod(OtherOrigin(methodElement, functionDescriptor), flags,
signature.getAsmMethod().getName(), signature.getAsmMethod().getName(),
signature.getAsmMethod().getDescriptor(), signature.getAsmMethod().getDescriptor(),
@@ -136,7 +140,7 @@ public class DefaultParameterValueSubstitutor(val state: GenerationState) {
val v = InstructionAdapter(mv) val v = InstructionAdapter(mv)
mv.visitCode() mv.visitCode()
val methodOwner = typeMapper.mapToCallableMethod(delegateFunctionDescriptor, false, context).owner val methodOwner = typeMapper.mapToCallableMethod(delegateFunctionDescriptor, false).owner
if (!isStatic) { if (!isStatic) {
val thisIndex = frameMap.enterTemp(AsmTypes.OBJECT_TYPE) val thisIndex = frameMap.enterTemp(AsmTypes.OBJECT_TYPE)
v.load(thisIndex, methodOwner) // Load this on stack v.load(thisIndex, methodOwner) // Load this on stack
@@ -187,7 +191,7 @@ public class DefaultParameterValueSubstitutor(val state: GenerationState) {
v.aconst(null) v.aconst(null)
} }
val defaultMethod = typeMapper.mapDefaultMethod(delegateFunctionDescriptor, context.getContextKind(), context) val defaultMethod = typeMapper.mapDefaultMethod(delegateFunctionDescriptor, contextKind)
if (functionDescriptor is ConstructorDescriptor) { if (functionDescriptor is ConstructorDescriptor) {
v.invokespecial(methodOwner.getInternalName(), defaultMethod.getName(), defaultMethod.getDescriptor(), false) v.invokespecial(methodOwner.getInternalName(), defaultMethod.getName(), defaultMethod.getDescriptor(), false)
} }
@@ -2210,22 +2210,21 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
PropertyGetterDescriptor getter = propertyDescriptor.getGetter(); PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
if (getter != null) { if (getter != null) {
callableGetter = typeMapper.mapToCallableMethod(getter, isSuper, context); callableGetter = typeMapper.mapToCallableMethod(getter, isSuper);
} }
} }
if (propertyDescriptor.isVar()) { if (propertyDescriptor.isVar()) {
PropertySetterDescriptor setter = propertyDescriptor.getSetter(); PropertySetterDescriptor setter = propertyDescriptor.getSetter();
if (setter != null && !couldUseDirectAccessToProperty(propertyDescriptor, false, isDelegatedProperty, context)) { if (setter != null && !couldUseDirectAccessToProperty(propertyDescriptor, false, isDelegatedProperty, context)) {
callableSetter = typeMapper.mapToCallableMethod(setter, isSuper, context); callableSetter = typeMapper.mapToCallableMethod(setter, isSuper);
} }
} }
} }
propertyDescriptor = DescriptorUtils.unwrapFakeOverride(propertyDescriptor); propertyDescriptor = DescriptorUtils.unwrapFakeOverride(propertyDescriptor);
Type backingFieldOwner = Type backingFieldOwner =
typeMapper.mapOwner(changeOwnerOnTypeMapping ? propertyDescriptor.getContainingDeclaration() : propertyDescriptor, typeMapper.mapOwner(changeOwnerOnTypeMapping ? propertyDescriptor.getContainingDeclaration() : propertyDescriptor);
isCallInsideSameModuleAsDeclared(propertyDescriptor, context, state.getOutDirectory()));
String fieldName; String fieldName;
if (isExtensionProperty && !isDelegatedProperty) { if (isExtensionProperty && !isDelegatedProperty) {
@@ -2247,11 +2246,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
} }
@NotNull @NotNull
private StackValue.Property intermediateValueForSyntheticExtensionProperty(@NotNull SyntheticJavaPropertyDescriptor propertyDescriptor, StackValue receiver) { private StackValue.Property intermediateValueForSyntheticExtensionProperty(
@NotNull SyntheticJavaPropertyDescriptor propertyDescriptor,
StackValue receiver
) {
Type type = typeMapper.mapType(propertyDescriptor.getOriginal().getType()); Type type = typeMapper.mapType(propertyDescriptor.getOriginal().getType());
CallableMethod callableGetter = typeMapper.mapToCallableMethod(propertyDescriptor.getGetMethod(), false, context); CallableMethod callableGetter = typeMapper.mapToCallableMethod(propertyDescriptor.getGetMethod(), false);
FunctionDescriptor setMethod = propertyDescriptor.getSetMethod(); FunctionDescriptor setMethod = propertyDescriptor.getSetMethod();
CallableMethod callableSetter = setMethod != null ? typeMapper.mapToCallableMethod(setMethod, false, context) : null; CallableMethod callableSetter = setMethod != null ? typeMapper.mapToCallableMethod(setMethod, false) : null;
return StackValue.property(propertyDescriptor, null, type, false, null, callableGetter, callableSetter, state, receiver); return StackValue.property(propertyDescriptor, null, type, false, null, callableGetter, callableSetter, state, receiver);
} }
@@ -2393,12 +2395,12 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
return intrinsic.toCallable(fd, superCall, resolvedCall, this); return intrinsic.toCallable(fd, superCall, resolvedCall, this);
} }
return resolveToCallableMethod(fd, superCall, context); return resolveToCallableMethod(fd, superCall);
} }
@NotNull @NotNull
private CallableMethod resolveToCallableMethod(@NotNull FunctionDescriptor fd, boolean superCall, @NotNull CodegenContext context) { private CallableMethod resolveToCallableMethod(@NotNull FunctionDescriptor fd, boolean superCall) {
return typeMapper.mapToCallableMethod(SamCodegenUtil.resolveSamAdapter(fd), superCall, context); return typeMapper.mapToCallableMethod(SamCodegenUtil.resolveSamAdapter(fd), superCall);
} }
public void invokeMethodWithArguments( public void invokeMethodWithArguments(
@@ -3483,7 +3485,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
boolean isGetter = "get".equals(operationDescriptor.getName().asString()); boolean isGetter = "get".equals(operationDescriptor.getName().asString());
Callable callable = resolveToCallable(operationDescriptor, false, isGetter ? resolvedGetCall : resolvedSetCall); Callable callable = resolveToCallable(operationDescriptor, false, isGetter ? resolvedGetCall : resolvedSetCall);
Callable callableMethod = resolveToCallableMethod(operationDescriptor, false, context); Callable callableMethod = resolveToCallableMethod(operationDescriptor, false);
Type[] argumentTypes = callableMethod.getParameterTypes(); Type[] argumentTypes = callableMethod.getParameterTypes();
StackValue collectionElementReceiver = createCollectionElementReceiver( StackValue collectionElementReceiver = createCollectionElementReceiver(
@@ -27,7 +27,10 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.backend.common.bridges.Bridge; import org.jetbrains.kotlin.backend.common.bridges.Bridge;
import org.jetbrains.kotlin.backend.common.bridges.BridgesPackage; import org.jetbrains.kotlin.backend.common.bridges.BridgesPackage;
import org.jetbrains.kotlin.codegen.annotation.AnnotatedWithOnlyTargetedAnnotations; import org.jetbrains.kotlin.codegen.annotation.AnnotatedWithOnlyTargetedAnnotations;
import org.jetbrains.kotlin.codegen.context.*; import org.jetbrains.kotlin.codegen.context.CodegenContext;
import org.jetbrains.kotlin.codegen.context.CodegenContextUtil;
import org.jetbrains.kotlin.codegen.context.DelegatingFacadeContext;
import org.jetbrains.kotlin.codegen.context.MethodContext;
import org.jetbrains.kotlin.codegen.optimization.OptimizationMethodVisitor; import org.jetbrains.kotlin.codegen.optimization.OptimizationMethodVisitor;
import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.codegen.state.JetTypeMapper; import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
@@ -121,10 +124,9 @@ public class FunctionCodegen {
@NotNull FunctionDescriptor functionDescriptor, @NotNull FunctionDescriptor functionDescriptor,
@NotNull FunctionDescriptor delegateFunctionDescriptor @NotNull FunctionDescriptor delegateFunctionDescriptor
) { ) {
new DefaultParameterValueSubstitutor(state).generateOverloadsIfNeeded(function, new DefaultParameterValueSubstitutor(state).generateOverloadsIfNeeded(
functionDescriptor, function, functionDescriptor, delegateFunctionDescriptor, owner.getContextKind(), v
delegateFunctionDescriptor, );
owner, v);
} }
public void generateMethod( public void generateMethod(
@@ -580,7 +582,7 @@ public class FunctionCodegen {
// $default methods are never private to be accessible from other class files (e.g. inner) without the need of synthetic accessors // $default methods are never private to be accessible from other class files (e.g. inner) without the need of synthetic accessors
flags &= ~ACC_PRIVATE; flags &= ~ACC_PRIVATE;
Method defaultMethod = typeMapper.mapDefaultMethod(functionDescriptor, kind, owner); Method defaultMethod = typeMapper.mapDefaultMethod(functionDescriptor, kind);
MethodVisitor mv = v.newMethod( MethodVisitor mv = v.newMethod(
Synthetic(function, functionDescriptor), Synthetic(function, functionDescriptor),
@@ -667,7 +669,7 @@ public class FunctionCodegen {
method = state.getTypeMapper().mapToCallableMethod((ConstructorDescriptor) functionDescriptor); method = state.getTypeMapper().mapToCallableMethod((ConstructorDescriptor) functionDescriptor);
} }
else { else {
method = state.getTypeMapper().mapToCallableMethod(functionDescriptor, false, methodContext); method = state.getTypeMapper().mapToCallableMethod(functionDescriptor, false);
} }
generator.genCallWithoutAssertions(method, codegen); generator.genCallWithoutAssertions(method, codegen);
@@ -944,7 +944,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
((AccessorForCallableDescriptor) accessorDescriptor).getSuperCallExpression() != null; ((AccessorForCallableDescriptor) accessorDescriptor).getSuperCallExpression() != null;
CallableMethod callableMethod = isConstructor ? CallableMethod callableMethod = isConstructor ?
typeMapper.mapToCallableMethod((ConstructorDescriptor) functionDescriptor) : typeMapper.mapToCallableMethod((ConstructorDescriptor) functionDescriptor) :
typeMapper.mapToCallableMethod(functionDescriptor, superCall, context); typeMapper.mapToCallableMethod(functionDescriptor, superCall);
int reg = 1; int reg = 1;
if (isConstructor && !accessorIsConstructor) { if (isConstructor && !accessorIsConstructor) {
@@ -1084,8 +1084,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
functionCodegen.generateDefaultIfNeeded(constructorContext, constructorDescriptor, OwnerKind.IMPLEMENTATION, functionCodegen.generateDefaultIfNeeded(constructorContext, constructorDescriptor, OwnerKind.IMPLEMENTATION,
DefaultParameterValueLoader.DEFAULT, null); DefaultParameterValueLoader.DEFAULT, null);
new DefaultParameterValueSubstitutor(state).generateConstructorOverloadsIfNeeded(constructorDescriptor, v, new DefaultParameterValueSubstitutor(state).generateConstructorOverloadsIfNeeded(constructorDescriptor, v, kind, myClass);
constructorContext, myClass);
if (isCompanionObject(descriptor)) { if (isCompanionObject(descriptor)) {
context.recordSyntheticAccessorIfNeeded(constructorDescriptor, bindingContext); context.recordSyntheticAccessorIfNeeded(constructorDescriptor, bindingContext);
@@ -1110,8 +1109,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
functionCodegen.generateDefaultIfNeeded(constructorContext, constructorDescriptor, OwnerKind.IMPLEMENTATION, functionCodegen.generateDefaultIfNeeded(constructorContext, constructorDescriptor, OwnerKind.IMPLEMENTATION,
DefaultParameterValueLoader.DEFAULT, null); DefaultParameterValueLoader.DEFAULT, null);
new DefaultParameterValueSubstitutor(state).generateOverloadsIfNeeded(myClass, constructorDescriptor, constructorDescriptor, new DefaultParameterValueSubstitutor(state).generateOverloadsIfNeeded(
constructorContext, v); myClass, constructorDescriptor, constructorDescriptor, kind, v
);
} }
private void generatePrimaryConstructorImpl( private void generatePrimaryConstructorImpl(
@@ -65,8 +65,7 @@ class PlatformStaticGenerator(
val syntheticOrOriginalMethod = typeMapper.mapToCallableMethod( val syntheticOrOriginalMethod = typeMapper.mapToCallableMethod(
codegen.getContext().accessibleDescriptor(descriptor, /* superCallExpression = */ null), codegen.getContext().accessibleDescriptor(descriptor, /* superCallExpression = */ null),
false, false
codegen.getContext()
) )
syntheticOrOriginalMethod.genInvokeInstruction(iv) syntheticOrOriginalMethod.genInvokeInstruction(iv)
iv.areturn(asmMethod.returnType) iv.areturn(asmMethod.returnType)
@@ -101,7 +101,7 @@ public class TraitImplBodyCodegen(
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) { override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
val iv = codegen.v val iv = codegen.v
val method = typeMapper.mapToCallableMethod(delegateTo, true, context) val method = typeMapper.mapToCallableMethod(delegateTo, true)
val myParameters = signature.getValueParameters() val myParameters = signature.getValueParameters()
val calleeParameters = method.getValueParameters() val calleeParameters = method.getValueParameters()
@@ -185,7 +185,7 @@ public class InlineCodegen extends CallGenerator {
Method asmMethod; Method asmMethod;
if (callDefault) { if (callDefault) {
asmMethod = typeMapper.mapDefaultMethod(functionDescriptor, context.getContextKind(), context); asmMethod = typeMapper.mapDefaultMethod(functionDescriptor, context.getContextKind());
} }
else { else {
asmMethod = jvmSignature.getAsmMethod(); asmMethod = jvmSignature.getAsmMethod();
@@ -231,7 +231,7 @@ public class InlineCodegen extends CallGenerator {
SMAP smap; SMAP smap;
if (callDefault) { if (callDefault) {
Type ownerType = typeMapper.mapOwner(functionDescriptor, true/*TODO: false, migration*/); Type ownerType = typeMapper.mapOwner(functionDescriptor);
FakeMemberCodegen parentCodegen = new FakeMemberCodegen(codegen.getParentCodegen(), inliningFunction, FakeMemberCodegen parentCodegen = new FakeMemberCodegen(codegen.getParentCodegen(), inliningFunction,
(FieldOwnerContext) methodContext.getParentContext(), (FieldOwnerContext) methodContext.getParentContext(),
ownerType.getInternalName()); ownerType.getInternalName());
@@ -343,7 +343,7 @@ public class InlineCodegen extends CallGenerator {
new FakeMemberCodegen(codegen.getParentCodegen(), expression, new FakeMemberCodegen(codegen.getParentCodegen(), expression,
(FieldOwnerContext) context.getParentContext(), (FieldOwnerContext) context.getParentContext(),
isLambda ? codegen.getParentCodegen().getClassName() isLambda ? codegen.getParentCodegen().getClassName()
: typeMapper.mapOwner(descriptor, true /*TODO: false, migration*/).getInternalName()); : typeMapper.mapOwner(descriptor).getInternalName());
FunctionGenerationStrategy strategy = FunctionGenerationStrategy strategy =
expression instanceof JetCallableReferenceExpression ? expression instanceof JetCallableReferenceExpression ?
@@ -33,7 +33,7 @@ public abstract class IntrinsicMethod {
@NotNull ResolvedCall resolvedCall, @NotNull ResolvedCall resolvedCall,
@NotNull ExpressionCodegen codegen @NotNull ExpressionCodegen codegen
) { ) {
return toCallable(codegen.getState().getTypeMapper().mapToCallableMethod(fd, false, codegen.getContext()), isSuper, resolvedCall); return toCallable(codegen.getState().getTypeMapper().mapToCallableMethod(fd, false), isSuper, resolvedCall);
} }
@NotNull @NotNull
@@ -58,4 +58,4 @@ public abstract class IntrinsicMethod {
public Type nullOr(Type type, Type newType) { public Type nullOr(Type type, Type newType) {
return type == null ? null : newType; return type == null ? null : newType;
} }
} }
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.codegen.optimization.OptimizationClassBuilderFactory
import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.ScriptDescriptor import org.jetbrains.kotlin.descriptors.ScriptDescriptor
import org.jetbrains.kotlin.diagnostics.DiagnosticSink import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.modules.TargetId import org.jetbrains.kotlin.modules.TargetId
import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.FqName
@@ -41,7 +40,7 @@ import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace import org.jetbrains.kotlin.resolve.DelegatingBindingTrace
import java.io.File import java.io.File
public class GenerationState jvmOverloads constructor( public class GenerationState @JvmOverloads constructor(
public val project: Project, public val project: Project,
builderFactory: ClassBuilderFactory, builderFactory: ClassBuilderFactory,
public val module: ModuleDescriptor, public val module: ModuleDescriptor,
@@ -58,7 +57,9 @@ public class GenerationState jvmOverloads constructor(
// for PackageCodegen in incremental compilation mode // for PackageCodegen in incremental compilation mode
public val targetId: TargetId? = null, public val targetId: TargetId? = null,
moduleName: String? = null, moduleName: String? = null,
// TODO: temporary hack, see JetTypeMapperWithOutDirectory state for details // 'outDirectory' is a hack to correctly determine if a compiled class is from the same module as the callee during
// partial compilation. Module chunks are treated as a single module.
// TODO: get rid of it with the proper module infrastructure
public val outDirectory: File? = null, public val outDirectory: File? = null,
public val incrementalCompilationComponents: IncrementalCompilationComponents? = null, public val incrementalCompilationComponents: IncrementalCompilationComponents? = null,
public val progress: Progress = Progress.DEAF public val progress: Progress = Progress.DEAF
@@ -87,8 +88,7 @@ public class GenerationState jvmOverloads constructor(
public val classBuilderMode: ClassBuilderMode = builderFactory.getClassBuilderMode() public val classBuilderMode: ClassBuilderMode = builderFactory.getClassBuilderMode()
public val bindingTrace: BindingTrace = DelegatingBindingTrace(bindingContext, "trace in GenerationState") public val bindingTrace: BindingTrace = DelegatingBindingTrace(bindingContext, "trace in GenerationState")
public val bindingContext: BindingContext = bindingTrace.getBindingContext() public val bindingContext: BindingContext = bindingTrace.getBindingContext()
public val typeMapper: JetTypeMapper = public val typeMapper: JetTypeMapper = JetTypeMapper(this.bindingContext, classBuilderMode, fileClassesProvider)
JetTypeMapperWithOutDirectory(this.bindingContext, classBuilderMode, fileClassesProvider, outDirectory)
public val intrinsics: IntrinsicMethods = IntrinsicMethods() public val intrinsics: IntrinsicMethods = IntrinsicMethods()
public val samWrapperClasses: SamWrapperClasses = SamWrapperClasses(this) public val samWrapperClasses: SamWrapperClasses = SamWrapperClasses(this)
public val inlineCycleReporter: InlineCycleReporter = InlineCycleReporter(diagnostics) public val inlineCycleReporter: InlineCycleReporter = InlineCycleReporter(diagnostics)
@@ -101,13 +101,13 @@ public class GenerationState jvmOverloads constructor(
private var used = false private var used = false
public val isCallAssertionsEnabled: Boolean = !disableCallAssertions public val isCallAssertionsEnabled: Boolean = !disableCallAssertions
@jvmName("isCallAssertionsEnabled") get @JvmName("isCallAssertionsEnabled") get
public val isParamAssertionsEnabled: Boolean = !disableParamAssertions public val isParamAssertionsEnabled: Boolean = !disableParamAssertions
@jvmName("isParamAssertionsEnabled") get @JvmName("isParamAssertionsEnabled") get
public val isInlineEnabled: Boolean = !disableInline public val isInlineEnabled: Boolean = !disableInline
@jvmName("isInlineEnabled") get @JvmName("isInlineEnabled") get
public val moduleName: String = moduleName ?: JvmCodegenUtil.getModuleName(module) public val moduleName: String = moduleName ?: JvmCodegenUtil.getModuleName(module)
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.codegen.*;
import org.jetbrains.kotlin.codegen.binding.CodegenBinding; import org.jetbrains.kotlin.codegen.binding.CodegenBinding;
import org.jetbrains.kotlin.codegen.binding.MutableClosure; import org.jetbrains.kotlin.codegen.binding.MutableClosure;
import org.jetbrains.kotlin.codegen.binding.PsiCodegenPredictor; import org.jetbrains.kotlin.codegen.binding.PsiCodegenPredictor;
import org.jetbrains.kotlin.codegen.context.CodegenContext;
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter; import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter;
import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.fileClasses.FileClassesPackage; import org.jetbrains.kotlin.fileClasses.FileClassesPackage;
@@ -69,7 +68,6 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions;
import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.Method; import org.jetbrains.org.objectweb.asm.commons.Method;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -139,7 +137,7 @@ public class JetTypeMapper {
} }
@NotNull @NotNull
public Type mapOwner(@NotNull DeclarationDescriptor descriptor, boolean isInsideModule) { public Type mapOwner(@NotNull DeclarationDescriptor descriptor) {
if (isLocalFunction(descriptor)) { if (isLocalFunction(descriptor)) {
return asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor); return asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
} }
@@ -594,11 +592,7 @@ public class JetTypeMapper {
} }
@NotNull @NotNull
public CallableMethod mapToCallableMethod( public CallableMethod mapToCallableMethod(@NotNull FunctionDescriptor descriptor, boolean superCall) {
@NotNull FunctionDescriptor descriptor,
boolean superCall,
@NotNull CodegenContext<?> context
) {
DeclarationDescriptor functionParent = descriptor.getOriginal().getContainingDeclaration(); DeclarationDescriptor functionParent = descriptor.getOriginal().getContainingDeclaration();
FunctionDescriptor functionDescriptor = unwrapFakeOverride(descriptor.getOriginal()); FunctionDescriptor functionDescriptor = unwrapFakeOverride(descriptor.getOriginal());
@@ -663,7 +657,7 @@ public class JetTypeMapper {
} }
else { else {
signature = mapSignature(functionDescriptor.getOriginal()); signature = mapSignature(functionDescriptor.getOriginal());
owner = mapOwner(functionDescriptor, isCallInsideSameModuleAsDeclared(functionDescriptor, context, getOutDirectory())); owner = mapOwner(functionDescriptor);
ownerForDefaultParam = owner; ownerForDefaultParam = owner;
ownerForDefaultImpl = owner; ownerForDefaultImpl = owner;
if (functionParent instanceof PackageFragmentDescriptor) { if (functionParent instanceof PackageFragmentDescriptor) {
@@ -852,13 +846,15 @@ public class JetTypeMapper {
} }
@NotNull @NotNull
public Method mapDefaultMethod(@NotNull FunctionDescriptor functionDescriptor, @NotNull OwnerKind kind, @NotNull CodegenContext<?> context) { public Method mapDefaultMethod(@NotNull FunctionDescriptor functionDescriptor, @NotNull OwnerKind kind) {
Method jvmSignature = mapSignature(functionDescriptor, kind).getAsmMethod(); Method jvmSignature = mapSignature(functionDescriptor, kind).getAsmMethod();
Type ownerType = mapOwner(functionDescriptor, isCallInsideSameModuleAsDeclared(functionDescriptor, context, getOutDirectory())); Type ownerType = mapOwner(functionDescriptor);
boolean isConstructor = isConstructor(jvmSignature); boolean isConstructor = isConstructor(jvmSignature);
String descriptor = getDefaultDescriptor(jvmSignature, String descriptor = getDefaultDescriptor(
isStaticMethod(kind, functionDescriptor) || isConstructor ? null : ownerType.getDescriptor(), jvmSignature,
functionDescriptor.getExtensionReceiverParameter() != null); isStaticMethod(kind, functionDescriptor) || isConstructor ? null : ownerType.getDescriptor(),
functionDescriptor.getExtensionReceiverParameter() != null
);
return new Method(isConstructor ? "<init>" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, descriptor); return new Method(isConstructor ? "<init>" : jvmSignature.getName() + JvmAbi.DEFAULT_PARAMS_IMPL_SUFFIX, descriptor);
} }
@@ -1142,10 +1138,4 @@ public class JetTypeMapper {
} }
return null; return null;
} }
// TODO Temporary hack until modules infrastructure is implemented. See JetTypeMapperWithOutDirectory for details
@Nullable
protected File getOutDirectory() {
return null;
}
} }
@@ -1,48 +0,0 @@
/*
* 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.state;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.codegen.ClassBuilderMode;
import org.jetbrains.kotlin.fileClasses.JvmFileClassesProvider;
import org.jetbrains.kotlin.resolve.BindingContext;
import java.io.File;
// TODO Temporary hack until modules infrastructure is implemented.
// This class is necessary for detecting if compiled class is from the same module as callee.
// Module chunks are treated as single module.
public class JetTypeMapperWithOutDirectory extends JetTypeMapper {
private final File outDirectory;
public JetTypeMapperWithOutDirectory(
@NotNull BindingContext bindingContext,
@NotNull ClassBuilderMode classBuilderMode,
@NotNull JvmFileClassesProvider fileClassesManager,
@Nullable File outDirectory
) {
super(bindingContext, classBuilderMode, fileClassesManager);
this.outDirectory = outDirectory;
}
@Nullable
@Override
public File getOutDirectory() {
return outDirectory;
}
}
@@ -408,8 +408,8 @@ public class JetPositionManager(private val myDebugProcess: DebugProcess) : Mult
public fun getJvmInternalNameForPropertyOwner(typeMapper: JetTypeMapper, descriptor: PropertyDescriptor): String { public fun getJvmInternalNameForPropertyOwner(typeMapper: JetTypeMapper, descriptor: PropertyDescriptor): String {
return typeMapper.mapOwner( return typeMapper.mapOwner(
if (AsmUtil.isPropertyWithBackingFieldInOuterClass(descriptor)) descriptor.getContainingDeclaration() else descriptor, if (AsmUtil.isPropertyWithBackingFieldInOuterClass(descriptor)) descriptor.containingDeclaration else descriptor
true).getInternalName() ).internalName
} }
private fun isInPropertyAccessor(element: PsiElement?) = private fun isInPropertyAccessor(element: PsiElement?) =