Delete JvmClassName.byType
Replace JvmClassName by ASM Type in many places of JVM codegen: it wasn't used to abstract anything, but there was a lot of useless conversions between the two
This commit is contained in:
@@ -676,4 +676,10 @@ public class AsmUtil {
|
|||||||
int lastSlash = internalName.lastIndexOf('/');
|
int lastSlash = internalName.lastIndexOf('/');
|
||||||
return lastSlash < 0 ? internalName : internalName.substring(lastSlash + 1);
|
return lastSlash < 0 ? internalName : internalName.substring(lastSlash + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WARNING: this method works incorrectly for classes with dollars in their names
|
||||||
|
@NotNull
|
||||||
|
public static FqName fqNameByAsmTypeUnsafe(@NotNull Type asmType) {
|
||||||
|
return JvmClassName.byInternalName(asmType.getInternalName()).getFqName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
|||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -34,28 +33,28 @@ import static org.jetbrains.asm4.Opcodes.INVOKESTATIC;
|
|||||||
|
|
||||||
public class CallableMethod implements Callable {
|
public class CallableMethod implements Callable {
|
||||||
@NotNull
|
@NotNull
|
||||||
private final JvmClassName owner;
|
private final Type owner;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final JvmClassName defaultImplOwner;
|
private final Type defaultImplOwner;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Type defaultImplParam;
|
private final Type defaultImplParam;
|
||||||
private final JvmMethodSignature signature;
|
private final JvmMethodSignature signature;
|
||||||
private final int invokeOpcode;
|
private final int invokeOpcode;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final JvmClassName thisClass;
|
private final Type thisClass;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Type receiverParameterType;
|
private final Type receiverParameterType;
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Type generateCalleeType;
|
private final Type generateCalleeType;
|
||||||
|
|
||||||
public CallableMethod(
|
public CallableMethod(
|
||||||
@NotNull JvmClassName owner, @Nullable JvmClassName defaultImplOwner, @Nullable JvmClassName defaultImplParam,
|
@NotNull Type owner, @Nullable Type defaultImplOwner, @Nullable Type defaultImplParam,
|
||||||
JvmMethodSignature signature, int invokeOpcode,
|
JvmMethodSignature signature, int invokeOpcode,
|
||||||
@Nullable JvmClassName thisClass, @Nullable Type receiverParameterType, @Nullable Type generateCalleeType
|
@Nullable Type thisClass, @Nullable Type receiverParameterType, @Nullable Type generateCalleeType
|
||||||
) {
|
) {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.defaultImplOwner = defaultImplOwner;
|
this.defaultImplOwner = defaultImplOwner;
|
||||||
this.defaultImplParam = defaultImplParam == null ? null : defaultImplParam.getAsmType();
|
this.defaultImplParam = defaultImplParam;
|
||||||
this.signature = signature;
|
this.signature = signature;
|
||||||
this.invokeOpcode = invokeOpcode;
|
this.invokeOpcode = invokeOpcode;
|
||||||
this.thisClass = thisClass;
|
this.thisClass = thisClass;
|
||||||
@@ -64,7 +63,7 @@ public class CallableMethod implements Callable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JvmClassName getOwner() {
|
public Type getOwner() {
|
||||||
return owner;
|
return owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +80,7 @@ public class CallableMethod implements Callable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JvmClassName getThisType() {
|
public Type getThisType() {
|
||||||
return thisClass;
|
return thisClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.jetbrains.jet.codegen.state.GenerationStateAware;
|
|||||||
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@@ -53,13 +52,13 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
ClassBuilder newVisitor(@NotNull JvmClassName className, @NotNull PsiFile sourceFile) {
|
ClassBuilder newVisitor(@NotNull Type asmType, @NotNull PsiFile sourceFile) {
|
||||||
return newVisitor(className, Collections.singletonList(sourceFile));
|
return newVisitor(asmType, Collections.singletonList(sourceFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ClassBuilder newVisitor(@NotNull JvmClassName className, @NotNull Collection<? extends PsiFile> sourceFiles) {
|
private ClassBuilder newVisitor(@NotNull Type asmType, @NotNull Collection<? extends PsiFile> sourceFiles) {
|
||||||
String outputFilePath = className.getInternalName() + ".class";
|
String outputFilePath = asmType.getInternalName() + ".class";
|
||||||
state.getProgress().reportOutput(toIoFilesIgnoringNonPhysical(sourceFiles), new File(outputFilePath));
|
state.getProgress().reportOutput(toIoFilesIgnoringNonPhysical(sourceFiles), new File(outputFilePath));
|
||||||
ClassBuilder answer = builderFactory.newClassBuilder();
|
ClassBuilder answer = builderFactory.newClassBuilder();
|
||||||
generators.put(outputFilePath, answer);
|
generators.put(outputFilePath, answer);
|
||||||
@@ -112,7 +111,7 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected ClassBuilder createClassBuilder() {
|
protected ClassBuilder createClassBuilder() {
|
||||||
return newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName), files);
|
return newVisitor(NamespaceCodegen.getJVMClassNameForKotlinNs(fqName).getAsmType(), files);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
codegen = new NamespaceCodegen(onDemand, fqName, state, files);
|
codegen = new NamespaceCodegen(onDemand, fqName, state, files);
|
||||||
@@ -127,18 +126,18 @@ public final class ClassFileFactory extends GenerationStateAware {
|
|||||||
if (isPrimitive(type)) {
|
if (isPrimitive(type)) {
|
||||||
throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass);
|
throw new IllegalStateException("Codegen for primitive type is not possible: " + aClass);
|
||||||
}
|
}
|
||||||
return newVisitor(JvmClassName.byType(type), sourceFile);
|
return newVisitor(type, sourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ClassBuilder forNamespacePart(@NotNull JvmClassName name, @NotNull PsiFile sourceFile) {
|
public ClassBuilder forNamespacePart(@NotNull Type asmType, @NotNull PsiFile sourceFile) {
|
||||||
return newVisitor(name, sourceFile);
|
return newVisitor(asmType, sourceFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public ClassBuilder forTraitImplementation(@NotNull ClassDescriptor aClass, @NotNull GenerationState state, @NotNull PsiFile file) {
|
public ClassBuilder forTraitImplementation(@NotNull ClassDescriptor aClass, @NotNull GenerationState state, @NotNull PsiFile file) {
|
||||||
Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
|
Type type = state.getTypeMapper().mapType(aClass.getDefaultType(), JetTypeMapperMode.TRAIT_IMPL);
|
||||||
return newVisitor(JvmClassName.byType(type), file);
|
return newVisitor(type, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<File> toIoFilesIgnoringNonPhysical(Collection<? extends PsiFile> psiFiles) {
|
private static Collection<File> toIoFilesIgnoringNonPhysical(Collection<? extends PsiFile> psiFiles) {
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import org.jetbrains.jet.codegen.state.JetTypeMapperMode;
|
|||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
|
import org.jetbrains.jet.lang.resolve.java.sam.SingleAbstractMethodUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -56,7 +55,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
private final PsiElement fun;
|
private final PsiElement fun;
|
||||||
private final FunctionDescriptor funDescriptor;
|
private final FunctionDescriptor funDescriptor;
|
||||||
private final ClassDescriptor samInterface;
|
private final ClassDescriptor samInterface;
|
||||||
private final JvmClassName superClass;
|
private final Type superClass;
|
||||||
private final CodegenContext context;
|
private final CodegenContext context;
|
||||||
private final FunctionGenerationStrategy strategy;
|
private final FunctionGenerationStrategy strategy;
|
||||||
private final CalculatedClosure closure;
|
private final CalculatedClosure closure;
|
||||||
@@ -69,7 +68,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
@NotNull PsiElement fun,
|
@NotNull PsiElement fun,
|
||||||
@NotNull FunctionDescriptor funDescriptor,
|
@NotNull FunctionDescriptor funDescriptor,
|
||||||
@Nullable ClassDescriptor samInterface,
|
@Nullable ClassDescriptor samInterface,
|
||||||
@NotNull JvmClassName closureSuperClass,
|
@NotNull Type closureSuperClass,
|
||||||
@NotNull CodegenContext context,
|
@NotNull CodegenContext context,
|
||||||
@NotNull LocalLookup localLookup,
|
@NotNull LocalLookup localLookup,
|
||||||
@NotNull FunctionGenerationStrategy strategy
|
@NotNull FunctionGenerationStrategy strategy
|
||||||
@@ -87,12 +86,12 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
this.closure = bindingContext.get(CLOSURE, classDescriptor);
|
this.closure = bindingContext.get(CLOSURE, classDescriptor);
|
||||||
assert closure != null : "Closure must be calculated for class: " + classDescriptor;
|
assert closure != null : "Closure must be calculated for class: " + classDescriptor;
|
||||||
|
|
||||||
this.asmType = classNameForAnonymousClass(bindingContext, funDescriptor).getAsmType();
|
this.asmType = asmTypeForAnonymousClass(bindingContext, funDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void gen() {
|
public void gen() {
|
||||||
ClassBuilder cv = state.getFactory().newVisitor(JvmClassName.byType(asmType), fun.getContainingFile());
|
ClassBuilder cv = state.getFactory().newVisitor(asmType, fun.getContainingFile());
|
||||||
|
|
||||||
FunctionDescriptor interfaceFunction;
|
FunctionDescriptor interfaceFunction;
|
||||||
String[] superInterfaces;
|
String[] superInterfaces;
|
||||||
@@ -231,7 +230,7 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
|
|
||||||
iv.load(0, superClass.getAsmType());
|
iv.load(0, superClass);
|
||||||
iv.invokespecial(superClass.getInternalName(), "<init>", "()V");
|
iv.invokespecial(superClass.getInternalName(), "<init>", "()V");
|
||||||
|
|
||||||
int k = 1;
|
int k = 1;
|
||||||
@@ -274,8 +273,8 @@ public class ClosureCodegen extends GenerationStateAware {
|
|||||||
args.add(FieldInfo.createForHiddenField(ownerType, type, "$" + descriptor.getName().asString()));
|
args.add(FieldInfo.createForHiddenField(ownerType, type, "$" + descriptor.getName().asString()));
|
||||||
}
|
}
|
||||||
else if (isLocalNamedFun(descriptor)) {
|
else if (isLocalNamedFun(descriptor)) {
|
||||||
JvmClassName className = classNameForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
|
Type classType = asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
|
||||||
args.add(FieldInfo.createForHiddenField(ownerType, className.getAsmType(), "$" + descriptor.getName().asString()));
|
args.add(FieldInfo.createForHiddenField(ownerType, classType, "$" + descriptor.getName().asString()));
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof FunctionDescriptor) {
|
else if (descriptor instanceof FunctionDescriptor) {
|
||||||
assert captureReceiver != null;
|
assert captureReceiver != null;
|
||||||
|
|||||||
@@ -70,10 +70,9 @@ import static org.jetbrains.asm4.Opcodes.*;
|
|||||||
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
||||||
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
||||||
import static org.jetbrains.jet.codegen.FunctionTypesUtil.functionTypeToImpl;
|
import static org.jetbrains.jet.codegen.FunctionTypesUtil.functionTypeToImpl;
|
||||||
import static org.jetbrains.jet.codegen.FunctionTypesUtil.getFunctionImplClassName;
|
import static org.jetbrains.jet.codegen.FunctionTypesUtil.getFunctionImplType;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getNotNull;
|
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.getNotNull;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.RECEIVER_ARGUMENT;
|
import static org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.RECEIVER_ARGUMENT;
|
||||||
import static org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.THIS_OBJECT;
|
import static org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind.THIS_OBJECT;
|
||||||
@@ -112,8 +111,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
public CalculatedClosure generateObjectLiteral(GenerationState state, JetObjectLiteralExpression literal) {
|
public CalculatedClosure generateObjectLiteral(GenerationState state, JetObjectLiteralExpression literal) {
|
||||||
JetObjectDeclaration objectDeclaration = literal.getObjectDeclaration();
|
JetObjectDeclaration objectDeclaration = literal.getObjectDeclaration();
|
||||||
|
|
||||||
JvmClassName className = classNameForAnonymousClass(bindingContext, objectDeclaration);
|
Type asmType = asmTypeForAnonymousClass(bindingContext, objectDeclaration);
|
||||||
ClassBuilder classBuilder = state.getFactory().newVisitor(className, literal.getContainingFile());
|
ClassBuilder classBuilder = state.getFactory().newVisitor(asmType, literal.getContainingFile());
|
||||||
|
|
||||||
ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration);
|
ClassDescriptor classDescriptor = bindingContext.get(CLASS, objectDeclaration);
|
||||||
assert classDescriptor != null;
|
assert classDescriptor != null;
|
||||||
@@ -286,8 +285,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
ClassDescriptor descriptor = bindingContext.get(BindingContext.CLASS, declaration);
|
ClassDescriptor descriptor = bindingContext.get(BindingContext.CLASS, declaration);
|
||||||
assert descriptor != null;
|
assert descriptor != null;
|
||||||
|
|
||||||
JvmClassName className = classNameForAnonymousClass(bindingContext, declaration);
|
Type asmType = asmTypeForAnonymousClass(bindingContext, declaration);
|
||||||
ClassBuilder classBuilder = state.getFactory().newVisitor(className, declaration.getContainingFile());
|
ClassBuilder classBuilder = state.getFactory().newVisitor(asmType, declaration.getContainingFile());
|
||||||
|
|
||||||
ClassContext objectContext = context.intoAnonymousClass(descriptor, this);
|
ClassContext objectContext = context.intoAnonymousClass(descriptor, this);
|
||||||
|
|
||||||
@@ -1310,7 +1309,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
FunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
|
FunctionDescriptor descriptor = bindingContext.get(BindingContext.FUNCTION, declaration);
|
||||||
assert descriptor != null : "Function is not resolved to descriptor: " + declaration.getText();
|
assert descriptor != null : "Function is not resolved to descriptor: " + declaration.getText();
|
||||||
|
|
||||||
JvmClassName closureSuperClass = samInterfaceClass == null ? getFunctionImplClassName(descriptor) : JvmClassName.byType(OBJECT_TYPE);
|
Type closureSuperClass = samInterfaceClass == null ? getFunctionImplType(descriptor) : OBJECT_TYPE;
|
||||||
|
|
||||||
ClosureCodegen closureCodegen = new ClosureCodegen(state, declaration, descriptor, samInterfaceClass, closureSuperClass, context,
|
ClosureCodegen closureCodegen = new ClosureCodegen(state, declaration, descriptor, samInterfaceClass, closureSuperClass, context,
|
||||||
this, new FunctionGenerationStrategy.FunctionDefault(state, descriptor, declaration));
|
this, new FunctionGenerationStrategy.FunctionDefault(state, descriptor, declaration));
|
||||||
@@ -1701,13 +1700,13 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
if (descriptor instanceof ValueParameterDescriptor && descriptor.getContainingDeclaration() instanceof ScriptDescriptor) {
|
if (descriptor instanceof ValueParameterDescriptor && descriptor.getContainingDeclaration() instanceof ScriptDescriptor) {
|
||||||
ScriptDescriptor scriptDescriptor = (ScriptDescriptor) descriptor.getContainingDeclaration();
|
ScriptDescriptor scriptDescriptor = (ScriptDescriptor) descriptor.getContainingDeclaration();
|
||||||
assert scriptDescriptor != null;
|
assert scriptDescriptor != null;
|
||||||
JvmClassName scriptClassName = classNameForScriptDescriptor(bindingContext, scriptDescriptor);
|
Type scriptClassType = asmTypeForScriptDescriptor(bindingContext, scriptDescriptor);
|
||||||
ValueParameterDescriptor valueParameterDescriptor = (ValueParameterDescriptor) descriptor;
|
ValueParameterDescriptor valueParameterDescriptor = (ValueParameterDescriptor) descriptor;
|
||||||
ClassDescriptor scriptClass = bindingContext.get(CLASS_FOR_SCRIPT, scriptDescriptor);
|
ClassDescriptor scriptClass = bindingContext.get(CLASS_FOR_SCRIPT, scriptDescriptor);
|
||||||
StackValue script = StackValue.thisOrOuter(this, scriptClass, false);
|
StackValue script = StackValue.thisOrOuter(this, scriptClass, false);
|
||||||
script.put(script.type, v);
|
script.put(script.type, v);
|
||||||
Type fieldType = typeMapper.mapType(valueParameterDescriptor);
|
Type fieldType = typeMapper.mapType(valueParameterDescriptor);
|
||||||
return StackValue.field(fieldType, scriptClassName, valueParameterDescriptor.getName().getIdentifier(), false);
|
return StackValue.field(fieldType, scriptClassType, valueParameterDescriptor.getName().getIdentifier(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new UnsupportedOperationException("don't know how to generate reference " + descriptor);
|
throw new UnsupportedOperationException("don't know how to generate reference " + descriptor);
|
||||||
@@ -1719,7 +1718,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
ClassDescriptor containing = (ClassDescriptor) variableDescriptor.getContainingDeclaration().getContainingDeclaration();
|
ClassDescriptor containing = (ClassDescriptor) variableDescriptor.getContainingDeclaration().getContainingDeclaration();
|
||||||
assert containing != null;
|
assert containing != null;
|
||||||
Type type = typeMapper.mapType(containing);
|
Type type = typeMapper.mapType(containing);
|
||||||
return StackValue.field(type, JvmClassName.byType(type), variableDescriptor.getName().asString(), true);
|
return StackValue.field(type, type, variableDescriptor.getName().asString(), true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return StackValue.singleton(objectClassDescriptor, typeMapper);
|
return StackValue.singleton(objectClassDescriptor, typeMapper);
|
||||||
@@ -1846,7 +1845,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JvmClassName owner;
|
Type owner;
|
||||||
CallableMethod callableMethod = callableGetter != null ? callableGetter : callableSetter;
|
CallableMethod callableMethod = callableGetter != null ? callableGetter : callableSetter;
|
||||||
|
|
||||||
propertyDescriptor = unwrapFakeOverride(propertyDescriptor);
|
propertyDescriptor = unwrapFakeOverride(propertyDescriptor);
|
||||||
@@ -1938,10 +1937,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
return genClosure(((JetFunctionLiteralExpression) expression).getFunctionLiteral(), samInterface);
|
return genClosure(((JetFunctionLiteralExpression) expression).getFunctionLiteral(), samInterface);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JvmClassName className =
|
Type asmType = state.getSamWrapperClasses().getSamWrapperClass(samInterface, (JetFile) expression.getContainingFile());
|
||||||
state.getSamWrapperClasses().getSamWrapperClass(samInterface, (JetFile) expression.getContainingFile());
|
|
||||||
|
|
||||||
v.anew(className.getAsmType());
|
v.anew(asmType);
|
||||||
v.dup();
|
v.dup();
|
||||||
|
|
||||||
Type functionType = typeMapper.mapType(samInterface.getFunctionTypeForSamInterface());
|
Type functionType = typeMapper.mapType(samInterface.getFunctionTypeForSamInterface());
|
||||||
@@ -1960,10 +1958,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
v.goTo(afterAll);
|
v.goTo(afterAll);
|
||||||
|
|
||||||
v.mark(ifNonNull);
|
v.mark(ifNonNull);
|
||||||
v.invokespecial(className.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType));
|
v.invokespecial(asmType.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, functionType));
|
||||||
|
|
||||||
v.mark(afterAll);
|
v.mark(afterAll);
|
||||||
return StackValue.onStack(className.getAsmType());
|
return StackValue.onStack(asmType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2216,19 +2214,15 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
if (cur instanceof ScriptContext) {
|
if (cur instanceof ScriptContext) {
|
||||||
ScriptContext scriptContext = (ScriptContext) cur;
|
ScriptContext scriptContext = (ScriptContext) cur;
|
||||||
|
|
||||||
JvmClassName currentScriptClassName =
|
Type currentScriptType = asmTypeForScriptDescriptor(bindingContext, scriptContext.getScriptDescriptor());
|
||||||
classNameForScriptDescriptor(bindingContext,
|
|
||||||
scriptContext.getScriptDescriptor());
|
|
||||||
if (scriptContext.getScriptDescriptor() == receiver.getDeclarationDescriptor()) {
|
if (scriptContext.getScriptDescriptor() == receiver.getDeclarationDescriptor()) {
|
||||||
result.put(currentScriptClassName.getAsmType(), v);
|
result.put(currentScriptType, v);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JvmClassName className =
|
Type classType = asmTypeForScriptDescriptor(bindingContext, receiver.getDeclarationDescriptor());
|
||||||
classNameForScriptDescriptor(bindingContext,
|
|
||||||
receiver.getDeclarationDescriptor());
|
|
||||||
String fieldName = state.getScriptCodegen().getScriptFieldName(receiver.getDeclarationDescriptor());
|
String fieldName = state.getScriptCodegen().getScriptFieldName(receiver.getDeclarationDescriptor());
|
||||||
result.put(currentScriptClassName.getAsmType(), v);
|
result.put(currentScriptType, v);
|
||||||
StackValue.field(className.getAsmType(), currentScriptClassName, fieldName, false).put(className.getAsmType(), v);
|
StackValue.field(classType, currentScriptType, fieldName, false).put(classType, v);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -2433,7 +2427,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
ClassDescriptor kFunctionImpl = functionTypeToImpl(kFunctionType);
|
ClassDescriptor kFunctionImpl = functionTypeToImpl(kFunctionType);
|
||||||
assert kFunctionImpl != null : "Impl type is not found for the function type: " + kFunctionType;
|
assert kFunctionImpl != null : "Impl type is not found for the function type: " + kFunctionType;
|
||||||
|
|
||||||
JvmClassName closureSuperClass = JvmClassName.byType(typeMapper.mapType(kFunctionImpl));
|
Type closureSuperClass = typeMapper.mapType(kFunctionImpl);
|
||||||
|
|
||||||
ClosureCodegen closureCodegen = new ClosureCodegen(state, expression, functionDescriptor, null, closureSuperClass, context, this,
|
ClosureCodegen closureCodegen = new ClosureCodegen(state, expression, functionDescriptor, null, closureSuperClass, context, this,
|
||||||
new FunctionGenerationStrategy.CodegenBased<CallableDescriptor>(state, functionDescriptor) {
|
new FunctionGenerationStrategy.CodegenBased<CallableDescriptor>(state, functionDescriptor) {
|
||||||
@@ -3019,7 +3013,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
private StackValue invokeOperation(JetOperationExpression expression, FunctionDescriptor op, CallableMethod callable) {
|
private StackValue invokeOperation(JetOperationExpression expression, FunctionDescriptor op, CallableMethod callable) {
|
||||||
int functionLocalIndex = lookupLocalIndex(op);
|
int functionLocalIndex = lookupLocalIndex(op);
|
||||||
if (functionLocalIndex >= 0) {
|
if (functionLocalIndex >= 0) {
|
||||||
stackValueForLocal(op, functionLocalIndex).put(callable.getOwner().getAsmType(), v);
|
stackValueForLocal(op, functionLocalIndex).put(callable.getOwner(), v);
|
||||||
}
|
}
|
||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
||||||
bindingContext.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
|
bindingContext.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
|
||||||
@@ -3217,8 +3211,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
generateInitializer.fun(variableDescriptor);
|
generateInitializer.fun(variableDescriptor);
|
||||||
JetScript scriptPsi = JetPsiUtil.getScript(variableDeclaration);
|
JetScript scriptPsi = JetPsiUtil.getScript(variableDeclaration);
|
||||||
assert scriptPsi != null;
|
assert scriptPsi != null;
|
||||||
JvmClassName scriptClassName = classNameForScriptPsi(bindingContext, scriptPsi);
|
Type scriptClassType = asmTypeForScriptPsi(bindingContext, scriptPsi);
|
||||||
v.putfield(scriptClassName.getInternalName(), variableDeclaration.getName(), varType.getDescriptor());
|
v.putfield(scriptClassType.getInternalName(), variableDeclaration.getName(), varType.getDescriptor());
|
||||||
}
|
}
|
||||||
else if (sharedVarType == null) {
|
else if (sharedVarType == null) {
|
||||||
generateInitializer.fun(variableDescriptor);
|
generateInitializer.fun(variableDescriptor);
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import org.jetbrains.jet.lang.descriptors.*;
|
|||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -50,7 +49,7 @@ import java.util.*;
|
|||||||
import static org.jetbrains.asm4.Opcodes.*;
|
import static org.jetbrains.asm4.Opcodes.*;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
||||||
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration;
|
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescriptorToDeclaration;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
|
||||||
@@ -112,8 +111,8 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
OwnerKind contextKind = owner.getContextKind();
|
OwnerKind contextKind = owner.getContextKind();
|
||||||
if (contextKind instanceof OwnerKind.StaticDelegateKind) {
|
if (contextKind instanceof OwnerKind.StaticDelegateKind) {
|
||||||
JvmClassName ownerName = ((OwnerKind.StaticDelegateKind) contextKind).getOwnerClass();
|
Type ownerType = ((OwnerKind.StaticDelegateKind) contextKind).getOwnerClass();
|
||||||
v.getMemberMap().recordSrcClassNameForCallable(functionDescriptor, shortNameByAsmType(ownerName.getAsmType()));
|
v.getMemberMap().recordSrcClassNameForCallable(functionDescriptor, shortNameByAsmType(ownerType));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
v.getMemberMap().recordMethodOfDescriptor(functionDescriptor, asmMethod);
|
v.getMemberMap().recordMethodOfDescriptor(functionDescriptor, asmMethod);
|
||||||
@@ -486,9 +485,9 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
InstructionAdapter v = new InstructionAdapter(mv);
|
InstructionAdapter v = new InstructionAdapter(mv);
|
||||||
mv.visitCode();
|
mv.visitCode();
|
||||||
|
|
||||||
JvmClassName ownerInternalName = method.getOwner();
|
Type methodOwner = method.getOwner();
|
||||||
Method jvmSignature = method.getSignature().getAsmMethod();
|
Method jvmSignature = method.getSignature().getAsmMethod();
|
||||||
v.load(0, ownerInternalName.getAsmType()); // Load this on stack
|
v.load(0, methodOwner); // Load this on stack
|
||||||
|
|
||||||
int mask = 0;
|
int mask = 0;
|
||||||
for (ValueParameterDescriptor parameterDescriptor : constructorDescriptor.getValueParameters()) {
|
for (ValueParameterDescriptor parameterDescriptor : constructorDescriptor.getValueParameters()) {
|
||||||
@@ -498,9 +497,9 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
}
|
}
|
||||||
v.iconst(mask);
|
v.iconst(mask);
|
||||||
String desc = jvmSignature.getDescriptor().replace(")", "I)");
|
String desc = jvmSignature.getDescriptor().replace(")", "I)");
|
||||||
v.invokespecial(ownerInternalName.getInternalName(), "<init>", desc);
|
v.invokespecial(methodOwner.getInternalName(), "<init>", desc);
|
||||||
v.areturn(Type.VOID_TYPE);
|
v.areturn(Type.VOID_TYPE);
|
||||||
endVisit(mv, "default constructor for " + ownerInternalName.getInternalName(), null);
|
endVisit(mv, "default constructor for " + methodOwner.getInternalName(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,13 +532,13 @@ public class FunctionCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
Type ownerType;
|
Type ownerType;
|
||||||
if (contextClass instanceof NamespaceDescriptor) {
|
if (contextClass instanceof NamespaceDescriptor) {
|
||||||
ownerType = state.getTypeMapper().getOwner(functionDescriptor, kind, true).getAsmType();
|
ownerType = state.getTypeMapper().getOwner(functionDescriptor, kind, true);
|
||||||
}
|
}
|
||||||
else if (contextClass instanceof ClassDescriptor) {
|
else if (contextClass instanceof ClassDescriptor) {
|
||||||
ownerType = state.getTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), JetTypeMapperMode.IMPL);
|
ownerType = state.getTypeMapper().mapType(((ClassDescriptor) contextClass).getDefaultType(), JetTypeMapperMode.IMPL);
|
||||||
}
|
}
|
||||||
else if (isLocalNamedFun(functionDescriptor)) {
|
else if (isLocalNamedFun(functionDescriptor)) {
|
||||||
ownerType = classNameForAnonymousClass(state.getBindingContext(), functionDescriptor).getAsmType();
|
ownerType = asmTypeForAnonymousClass(state.getBindingContext(), functionDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new IllegalStateException("Couldn't obtain owner name for " + functionDescriptor);
|
throw new IllegalStateException("Couldn't obtain owner name for " + functionDescriptor);
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ package org.jetbrains.jet.codegen;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -157,24 +157,24 @@ public class FunctionTypesUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName getFunctionTraitClassName(@NotNull FunctionDescriptor descriptor) {
|
public static Type getFunctionTraitClassName(@NotNull FunctionDescriptor descriptor) {
|
||||||
int paramCount = descriptor.getValueParameters().size();
|
int paramCount = descriptor.getValueParameters().size();
|
||||||
if (descriptor.getReceiverParameter() != null) {
|
if (descriptor.getReceiverParameter() != null) {
|
||||||
return JvmClassName.byInternalName("jet/ExtensionFunction" + paramCount);
|
return Type.getObjectType("jet/ExtensionFunction" + paramCount);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return JvmClassName.byInternalName("jet/Function" + paramCount);
|
return Type.getObjectType("jet/Function" + paramCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName getFunctionImplClassName(@NotNull FunctionDescriptor descriptor) {
|
public static Type getFunctionImplType(@NotNull FunctionDescriptor descriptor) {
|
||||||
int paramCount = descriptor.getValueParameters().size();
|
int paramCount = descriptor.getValueParameters().size();
|
||||||
if (descriptor.getReceiverParameter() != null) {
|
if (descriptor.getReceiverParameter() != null) {
|
||||||
return JvmClassName.byInternalName("jet/ExtensionFunctionImpl" + paramCount);
|
return Type.getObjectType("jet/ExtensionFunctionImpl" + paramCount);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return JvmClassName.byInternalName("jet/FunctionImpl" + paramCount);
|
return Type.getObjectType("jet/FunctionImpl" + paramCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
|||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
|
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||||
@@ -867,7 +866,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (closure != null && closure.getCaptureThis() != null) {
|
if (closure != null && closure.getCaptureThis() != null) {
|
||||||
Type type = typeMapper.mapType(enclosingClassDescriptor(bindingContext, descriptor));
|
Type type = typeMapper.mapType(enclosingClassDescriptor(bindingContext, descriptor));
|
||||||
iv.load(0, classAsmType);
|
iv.load(0, classAsmType);
|
||||||
iv.getfield(JvmClassName.byType(classAsmType).getInternalName(), CAPTURED_THIS_FIELD, type.getDescriptor());
|
iv.getfield(classAsmType.getInternalName(), CAPTURED_THIS_FIELD, type.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
int parameterIndex = 1; // localVariable 0 = this
|
int parameterIndex = 1; // localVariable 0 = this
|
||||||
@@ -1041,7 +1040,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
int reg = 1;
|
int reg = 1;
|
||||||
if (isConstructor) {
|
if (isConstructor) {
|
||||||
iv.anew(callableMethod.getOwner().getAsmType());
|
iv.anew(callableMethod.getOwner());
|
||||||
iv.dup();
|
iv.dup();
|
||||||
reg = 0;
|
reg = 0;
|
||||||
}
|
}
|
||||||
@@ -1123,8 +1122,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||||
StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, false, null);
|
StackValue property = codegen.intermediateValueForProperty(propertyDescriptor, false, null);
|
||||||
property.put(property.type, codegen.v);
|
property.put(property.type, codegen.v);
|
||||||
StackValue.Field field = StackValue.field(property.type, JvmClassName.byType(classAsmType),
|
StackValue.Field field = StackValue.field(property.type, classAsmType, propertyDescriptor.getName().asString(), true);
|
||||||
propertyDescriptor.getName().asString(), true);
|
|
||||||
field.store(field.type, codegen.v);
|
field.store(field.type, codegen.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1195,8 +1193,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
InstructionAdapter iv = codegen.v;
|
InstructionAdapter iv = codegen.v;
|
||||||
|
|
||||||
JvmClassName className = JvmClassName.byType(classAsmType);
|
|
||||||
|
|
||||||
if (superCall == null) {
|
if (superCall == null) {
|
||||||
genSimpleSuperCall(iv);
|
genSimpleSuperCall(iv);
|
||||||
}
|
}
|
||||||
@@ -1222,7 +1218,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (specifier instanceof JetDelegatorByExpressionSpecifier) {
|
if (specifier instanceof JetDelegatorByExpressionSpecifier) {
|
||||||
genCallToDelegatorByExpressionSpecifier(iv, codegen, classAsmType, className, n++, specifier);
|
genCallToDelegatorByExpressionSpecifier(iv, codegen, n++, specifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1288,8 +1284,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
private void genCallToDelegatorByExpressionSpecifier(
|
private void genCallToDelegatorByExpressionSpecifier(
|
||||||
InstructionAdapter iv,
|
InstructionAdapter iv,
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
Type classType,
|
|
||||||
JvmClassName className,
|
|
||||||
int n,
|
int n,
|
||||||
JetDelegationSpecifier specifier
|
JetDelegationSpecifier specifier
|
||||||
) {
|
) {
|
||||||
@@ -1325,20 +1319,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
!propertyDescriptor.isVar() &&
|
!propertyDescriptor.isVar() &&
|
||||||
Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor))) {
|
Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor))) {
|
||||||
// final property with backing field
|
// final property with backing field
|
||||||
field = StackValue.field(typeMapper.mapType(propertyDescriptor.getType()), className,
|
field = StackValue.field(typeMapper.mapType(propertyDescriptor.getType()), classAsmType,
|
||||||
propertyDescriptor.getName().asString(), false);
|
propertyDescriptor.getName().asString(), false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
iv.load(0, classType);
|
iv.load(0, classAsmType);
|
||||||
codegen.genToJVMStack(expression);
|
codegen.genToJVMStack(expression);
|
||||||
|
|
||||||
String delegateField = "$delegate_" + n;
|
String delegateField = "$delegate_" + n;
|
||||||
Type fieldType = typeMapper.mapType(superClassDescriptor);
|
Type fieldType = typeMapper.mapType(superClassDescriptor);
|
||||||
String fieldDesc = fieldType.getDescriptor();
|
String fieldDesc = fieldType.getDescriptor();
|
||||||
|
|
||||||
v.newField(specifier, ACC_PRIVATE|ACC_FINAL|ACC_SYNTHETIC, delegateField, fieldDesc, /*TODO*/null, null);
|
v.newField(specifier, ACC_PRIVATE | ACC_FINAL | ACC_SYNTHETIC, delegateField, fieldDesc, /*TODO*/null, null);
|
||||||
|
|
||||||
field = StackValue.field(fieldType, className, delegateField, false);
|
field = StackValue.field(fieldType, classAsmType, delegateField, false);
|
||||||
field.store(fieldType, iv);
|
field.store(fieldType, iv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.jetbrains.jet.codegen;
|
|||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.util.containers.MultiMap;
|
import com.intellij.util.containers.MultiMap;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
@@ -48,7 +49,7 @@ public class KotlinCodegenFacade {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state.getScriptCodegen().registerEarlierScripts(Collections.<Pair<ScriptDescriptor, JvmClassName>>emptyList());
|
state.getScriptCodegen().registerEarlierScripts(Collections.<Pair<ScriptDescriptor, Type>>emptyList());
|
||||||
|
|
||||||
state.beforeCompile();
|
state.beforeCompile();
|
||||||
|
|
||||||
|
|||||||
@@ -183,12 +183,12 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
|
|
||||||
if (!generateSrcClass) return null;
|
if (!generateSrcClass) return null;
|
||||||
|
|
||||||
JvmClassName className = getMultiFileNamespaceInternalName(PackageClassUtils.getPackageClassFqName(name), file);
|
Type namespacePartType = getNamespacePartType(PackageClassUtils.getPackageClassFqName(name), file);
|
||||||
ClassBuilder builder = state.getFactory().forNamespacePart(className, file);
|
ClassBuilder builder = state.getFactory().forNamespacePart(namespacePartType, file);
|
||||||
|
|
||||||
builder.defineClass(file, V1_6,
|
builder.defineClass(file, V1_6,
|
||||||
ACC_PUBLIC | ACC_FINAL,
|
ACC_PUBLIC | ACC_FINAL,
|
||||||
className.getInternalName(),
|
namespacePartType.getInternalName(),
|
||||||
null,
|
null,
|
||||||
//"jet/lang/Namespace",
|
//"jet/lang/Namespace",
|
||||||
"java/lang/Object",
|
"java/lang/Object",
|
||||||
@@ -200,7 +200,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
|
|
||||||
FieldOwnerContext nameSpaceContext = CodegenContext.STATIC.intoNamespace(descriptor);
|
FieldOwnerContext nameSpaceContext = CodegenContext.STATIC.intoNamespace(descriptor);
|
||||||
|
|
||||||
FieldOwnerContext nameSpacePart = CodegenContext.STATIC.intoNamespacePart(className, descriptor);
|
FieldOwnerContext nameSpacePart = CodegenContext.STATIC.intoNamespacePart(namespacePartType, descriptor);
|
||||||
|
|
||||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||||
if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) {
|
if (declaration instanceof JetNamedFunction || declaration instanceof JetProperty) {
|
||||||
@@ -319,7 +319,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static JvmClassName getMultiFileNamespaceInternalName(@NotNull FqName facadeFqName, @NotNull PsiFile file) {
|
private static Type getNamespacePartType(@NotNull FqName facadeFqName, @NotNull PsiFile file) {
|
||||||
String fileName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(file.getName()));
|
String fileName = FileUtil.getNameWithoutExtension(PathUtil.getFileName(file.getName()));
|
||||||
|
|
||||||
// path hashCode to prevent same name / different path collision
|
// path hashCode to prevent same name / different path collision
|
||||||
@@ -328,7 +328,7 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
|
|
||||||
FqName srcFqName = facadeFqName.parent().child(Name.identifier(srcName));
|
FqName srcFqName = facadeFqName.parent().child(Name.identifier(srcName));
|
||||||
|
|
||||||
return JvmClassName.byFqNameWithoutInnerClasses(srcFqName);
|
return JvmClassName.byFqNameWithoutInnerClasses(srcFqName).getAsmType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -340,6 +340,6 @@ public class NamespaceCodegen extends MemberCodegen {
|
|||||||
public static String getNamespacePartInternalName(@NotNull JetFile file) {
|
public static String getNamespacePartInternalName(@NotNull JetFile file) {
|
||||||
FqName fqName = JetPsiUtil.getFQName(file);
|
FqName fqName = JetPsiUtil.getFQName(file);
|
||||||
JvmClassName namespaceJvmClassName = getJVMClassNameForKotlinNs(fqName);
|
JvmClassName namespaceJvmClassName = getJVMClassNameForKotlinNs(fqName);
|
||||||
return getMultiFileNamespaceInternalName(namespaceJvmClassName.getFqName(), file).getInternalName();
|
return getNamespacePartType(namespaceJvmClassName.getFqName(), file).getInternalName();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package org.jetbrains.jet.codegen;
|
package org.jetbrains.jet.codegen;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
import org.jetbrains.asm4.Type;
|
||||||
|
|
||||||
public class OwnerKind {
|
public class OwnerKind {
|
||||||
private final String name;
|
private final String name;
|
||||||
@@ -31,15 +31,15 @@ public class OwnerKind {
|
|||||||
public static final OwnerKind TRAIT_IMPL = new OwnerKind("trait implementation");
|
public static final OwnerKind TRAIT_IMPL = new OwnerKind("trait implementation");
|
||||||
|
|
||||||
public static class StaticDelegateKind extends OwnerKind {
|
public static class StaticDelegateKind extends OwnerKind {
|
||||||
private final JvmClassName ownerClass;
|
private final Type ownerClass;
|
||||||
|
|
||||||
public StaticDelegateKind(@NotNull JvmClassName ownerClass) {
|
public StaticDelegateKind(@NotNull Type ownerClass) {
|
||||||
super("staticDelegateKind");
|
super("staticDelegateKind");
|
||||||
this.ownerClass = ownerClass;
|
this.ownerClass = ownerClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JvmClassName getOwnerClass() {
|
public Type getOwnerClass() {
|
||||||
return ownerClass;
|
return ownerClass;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
|||||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
@@ -88,8 +87,8 @@ public class PropertyCodegen extends GenerationStateAware {
|
|||||||
: "Generating property with a wrong kind (" + kind + "): " + propertyDescriptor;
|
: "Generating property with a wrong kind (" + kind + "): " + propertyDescriptor;
|
||||||
|
|
||||||
if (kind instanceof OwnerKind.StaticDelegateKind) {
|
if (kind instanceof OwnerKind.StaticDelegateKind) {
|
||||||
JvmClassName ownerName = ((OwnerKind.StaticDelegateKind) kind).getOwnerClass();
|
Type ownerType = ((OwnerKind.StaticDelegateKind) kind).getOwnerClass();
|
||||||
v.getMemberMap().recordSrcClassNameForCallable(propertyDescriptor, shortNameByAsmType(ownerName.getAsmType()));
|
v.getMemberMap().recordSrcClassNameForCallable(propertyDescriptor, shortNameByAsmType(ownerType));
|
||||||
}
|
}
|
||||||
else if (kind != OwnerKind.TRAIT_IMPL) {
|
else if (kind != OwnerKind.TRAIT_IMPL) {
|
||||||
generateBackingField(p, propertyDescriptor);
|
generateBackingField(p, propertyDescriptor);
|
||||||
|
|||||||
@@ -21,11 +21,9 @@ import com.intellij.openapi.util.Factory;
|
|||||||
import com.intellij.openapi.util.Pair;
|
import com.intellij.openapi.util.Pair;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmBytecode;
|
import org.jetbrains.jet.lang.resolve.java.descriptor.ClassDescriptorFromJvmBytecode;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -33,18 +31,18 @@ import java.util.Map;
|
|||||||
public class SamWrapperClasses {
|
public class SamWrapperClasses {
|
||||||
private final GenerationState state;
|
private final GenerationState state;
|
||||||
|
|
||||||
private final Map<Pair<ClassDescriptorFromJvmBytecode, JetFile>, JvmClassName> samInterfaceToWrapperClass = Maps.newHashMap();
|
private final Map<Pair<ClassDescriptorFromJvmBytecode, JetFile>, Type> samInterfaceToWrapperClass = Maps.newHashMap();
|
||||||
|
|
||||||
public SamWrapperClasses(GenerationState state) {
|
public SamWrapperClasses(GenerationState state) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JvmClassName getSamWrapperClass(@NotNull final ClassDescriptorFromJvmBytecode samInterface, @NotNull final JetFile file) {
|
public Type getSamWrapperClass(@NotNull final ClassDescriptorFromJvmBytecode samInterface, @NotNull final JetFile file) {
|
||||||
return ContainerUtil.getOrCreate(samInterfaceToWrapperClass, Pair.create(samInterface, file),
|
return ContainerUtil.getOrCreate(samInterfaceToWrapperClass, Pair.create(samInterface, file),
|
||||||
new Factory<JvmClassName>() {
|
new Factory<Type>() {
|
||||||
@Override
|
@Override
|
||||||
public JvmClassName create() {
|
public Type create() {
|
||||||
return new SamWrapperCodegen(state, samInterface).genWrapper(file);
|
return new SamWrapperCodegen(state, samInterface).genWrapper(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -53,9 +53,9 @@ public class SamWrapperCodegen extends GenerationStateAware {
|
|||||||
this.samInterface = samInterface;
|
this.samInterface = samInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JvmClassName genWrapper(@NotNull JetFile file) {
|
public Type genWrapper(@NotNull JetFile file) {
|
||||||
// Name for generated class, in form of whatever$1
|
// Name for generated class, in form of whatever$1
|
||||||
JvmClassName name = JvmClassName.byInternalName(getWrapperName(file));
|
Type asmType = Type.getObjectType(getWrapperName(file));
|
||||||
|
|
||||||
// e.g. (T, T) -> Int
|
// e.g. (T, T) -> Int
|
||||||
JetType functionType = samInterface.getFunctionTypeForSamInterface();
|
JetType functionType = samInterface.getFunctionTypeForSamInterface();
|
||||||
@@ -63,11 +63,11 @@ public class SamWrapperCodegen extends GenerationStateAware {
|
|||||||
// e.g. compare(T, T)
|
// e.g. compare(T, T)
|
||||||
SimpleFunctionDescriptor interfaceFunction = SingleAbstractMethodUtils.getAbstractMethodOfSamInterface(samInterface);
|
SimpleFunctionDescriptor interfaceFunction = SingleAbstractMethodUtils.getAbstractMethodOfSamInterface(samInterface);
|
||||||
|
|
||||||
ClassBuilder cv = state.getFactory().newVisitor(name, file);
|
ClassBuilder cv = state.getFactory().newVisitor(asmType, file);
|
||||||
cv.defineClass(file,
|
cv.defineClass(file,
|
||||||
V1_6,
|
V1_6,
|
||||||
ACC_FINAL,
|
ACC_FINAL,
|
||||||
name.getInternalName(),
|
asmType.getInternalName(),
|
||||||
null,
|
null,
|
||||||
OBJECT_TYPE.getInternalName(),
|
OBJECT_TYPE.getInternalName(),
|
||||||
new String[]{ typeMapper.mapType(samInterface).getInternalName() }
|
new String[]{ typeMapper.mapType(samInterface).getInternalName() }
|
||||||
@@ -84,12 +84,12 @@ public class SamWrapperCodegen extends GenerationStateAware {
|
|||||||
null,
|
null,
|
||||||
null);
|
null);
|
||||||
|
|
||||||
generateConstructor(name.getAsmType(), functionAsmType, cv);
|
generateConstructor(asmType, functionAsmType, cv);
|
||||||
generateMethod(name.getAsmType(), functionAsmType, cv, interfaceFunction, functionType);
|
generateMethod(asmType, functionAsmType, cv, interfaceFunction, functionType);
|
||||||
|
|
||||||
cv.done();
|
cv.done();
|
||||||
|
|
||||||
return name;
|
return asmType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generateConstructor(Type ownerType, Type functionType, ClassBuilder cv) {
|
private void generateConstructor(Type ownerType, Type functionType, ClassBuilder cv) {
|
||||||
@@ -129,7 +129,7 @@ public class SamWrapperCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
FunctionDescriptor invokeFunction = functionJetType.getMemberScope()
|
FunctionDescriptor invokeFunction = functionJetType.getMemberScope()
|
||||||
.getFunctions(Name.identifier("invoke")).iterator().next().getOriginal();
|
.getFunctions(Name.identifier("invoke")).iterator().next().getOriginal();
|
||||||
StackValue functionField = StackValue.field(functionType, JvmClassName.byType(ownerType), FUNCTION_FIELD_NAME, false);
|
StackValue functionField = StackValue.field(functionType, ownerType, FUNCTION_FIELD_NAME, false);
|
||||||
codegen.genDelegate(interfaceFunction, invokeFunction, functionField);
|
codegen.genDelegate(interfaceFunction, invokeFunction, functionField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
|
JvmClassName className = bindingContext.get(FQN, classDescriptorForScript);
|
||||||
assert className != null;
|
assert className != null;
|
||||||
|
|
||||||
ClassBuilder classBuilder = classFileFactory.newVisitor(className, scriptDeclaration.getContainingFile());
|
ClassBuilder classBuilder = classFileFactory.newVisitor(className.getAsmType(), scriptDeclaration.getContainingFile());
|
||||||
classBuilder.defineClass(scriptDeclaration,
|
classBuilder.defineClass(scriptDeclaration,
|
||||||
V1_6,
|
V1_6,
|
||||||
ACC_PUBLIC,
|
ACC_PUBLIC,
|
||||||
@@ -151,12 +151,11 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
int offset = 1;
|
int offset = 1;
|
||||||
|
|
||||||
for (ScriptDescriptor earlierScript : importedScripts) {
|
for (ScriptDescriptor earlierScript : importedScripts) {
|
||||||
JvmClassName earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
|
Type earlierClassType = asmTypeForScriptDescriptor(bindingContext, earlierScript);
|
||||||
instructionAdapter.load(0, className.getAsmType());
|
instructionAdapter.load(0, className.getAsmType());
|
||||||
instructionAdapter.load(offset, earlierClassName.getAsmType());
|
instructionAdapter.load(offset, earlierClassType);
|
||||||
offset += earlierClassName.getAsmType().getSize();
|
offset += earlierClassType.getSize();
|
||||||
instructionAdapter.putfield(className.getInternalName(), getScriptFieldName(earlierScript),
|
instructionAdapter.putfield(className.getInternalName(), getScriptFieldName(earlierScript), earlierClassType.getDescriptor());
|
||||||
earlierClassName.getAsmType().getDescriptor());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ValueParameterDescriptor parameter : scriptDescriptor.getValueParameters()) {
|
for (ValueParameterDescriptor parameter : scriptDescriptor.getValueParameters()) {
|
||||||
@@ -171,8 +170,8 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, context, state).gen(scriptDeclaration.getBlockExpression());
|
new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, context, state).gen(scriptDeclaration.getBlockExpression());
|
||||||
if (stackValue.type != Type.VOID_TYPE) {
|
if (stackValue.type != Type.VOID_TYPE) {
|
||||||
stackValue.put(stackValue.type, instructionAdapter);
|
stackValue.put(stackValue.type, instructionAdapter);
|
||||||
instructionAdapter
|
instructionAdapter.putfield(className.getInternalName(), ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME,
|
||||||
.putfield(className.getInternalName(), ScriptDescriptor.LAST_EXPRESSION_VALUE_FIELD_NAME, blockType.getDescriptor());
|
blockType.getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
instructionAdapter.areturn(Type.VOID_TYPE);
|
instructionAdapter.areturn(Type.VOID_TYPE);
|
||||||
@@ -182,9 +181,9 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
|
|
||||||
private void genFieldsForParameters(@NotNull ScriptDescriptor script, @NotNull ClassBuilder classBuilder) {
|
private void genFieldsForParameters(@NotNull ScriptDescriptor script, @NotNull ClassBuilder classBuilder) {
|
||||||
for (ScriptDescriptor earlierScript : earlierScripts) {
|
for (ScriptDescriptor earlierScript : earlierScripts) {
|
||||||
JvmClassName earlierClassName = classNameForScriptDescriptor(bindingContext, earlierScript);
|
Type earlierClassName = asmTypeForScriptDescriptor(bindingContext, earlierScript);
|
||||||
int access = ACC_PRIVATE | ACC_FINAL;
|
int access = ACC_PRIVATE | ACC_FINAL;
|
||||||
classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getAsmType().getDescriptor(), null, null);
|
classBuilder.newField(null, access, getScriptFieldName(earlierScript), earlierClassName.getDescriptor(), null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ValueParameterDescriptor parameter : script.getValueParameters()) {
|
for (ValueParameterDescriptor parameter : script.getValueParameters()) {
|
||||||
@@ -200,16 +199,17 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEarlierScripts(List<Pair<ScriptDescriptor, JvmClassName>> earlierScripts) {
|
public void registerEarlierScripts(List<Pair<ScriptDescriptor, Type>> earlierScripts) {
|
||||||
for (Pair<ScriptDescriptor, JvmClassName> t : earlierScripts) {
|
for (Pair<ScriptDescriptor, Type> t : earlierScripts) {
|
||||||
ScriptDescriptor earlierDescriptor = t.first;
|
ScriptDescriptor earlierDescriptor = t.first;
|
||||||
JvmClassName earlierClassName = t.second;
|
Type earlierClassName = t.second;
|
||||||
|
|
||||||
registerClassNameForScript(state.getBindingTrace(), earlierDescriptor, earlierClassName);
|
registerClassNameForScript(state.getBindingTrace(), earlierDescriptor,
|
||||||
|
JvmClassName.byInternalName(earlierClassName.getInternalName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ScriptDescriptor> earlierScriptDescriptors = Lists.newArrayList();
|
List<ScriptDescriptor> earlierScriptDescriptors = Lists.newArrayList();
|
||||||
for (Pair<ScriptDescriptor, JvmClassName> t : earlierScripts) {
|
for (Pair<ScriptDescriptor, Type> t : earlierScripts) {
|
||||||
ScriptDescriptor earlierDescriptor = t.first;
|
ScriptDescriptor earlierDescriptor = t.first;
|
||||||
earlierScriptDescriptors.add(earlierDescriptor);
|
earlierScriptDescriptors.add(earlierDescriptor);
|
||||||
}
|
}
|
||||||
@@ -238,12 +238,12 @@ public class ScriptCodegen extends MemberCodegen {
|
|||||||
|
|
||||||
public void compileScript(
|
public void compileScript(
|
||||||
@NotNull JetScript script,
|
@NotNull JetScript script,
|
||||||
@NotNull JvmClassName className,
|
@NotNull Type classType,
|
||||||
@NotNull List<Pair<ScriptDescriptor, JvmClassName>> earlierScripts,
|
@NotNull List<Pair<ScriptDescriptor, Type>> earlierScripts,
|
||||||
@NotNull CompilationErrorHandler errorHandler
|
@NotNull CompilationErrorHandler errorHandler
|
||||||
) {
|
) {
|
||||||
registerEarlierScripts(earlierScripts);
|
registerEarlierScripts(earlierScripts);
|
||||||
registerClassNameForScript(state.getBindingTrace(), script, className);
|
registerClassNameForScript(state.getBindingTrace(), script, JvmClassName.byInternalName(classType.getInternalName()));
|
||||||
|
|
||||||
state.beforeCompile();
|
state.beforeCompile();
|
||||||
KotlinCodegenFacade.generateNamespace(
|
KotlinCodegenFacade.generateNamespace(
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.descriptors.*;
|
|||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
@@ -132,14 +131,14 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Field field(@NotNull Type type, @NotNull JvmClassName owner, @NotNull String name, boolean isStatic) {
|
public static Field field(@NotNull Type type, @NotNull Type owner, @NotNull String name, boolean isStatic) {
|
||||||
return new Field(type, owner, name, isStatic);
|
return new Field(type, owner, name, isStatic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static Property property(
|
public static Property property(
|
||||||
@NotNull PropertyDescriptor descriptor,
|
@NotNull PropertyDescriptor descriptor,
|
||||||
@NotNull JvmClassName methodOwner,
|
@NotNull Type methodOwner,
|
||||||
@NotNull Type type,
|
@NotNull Type type,
|
||||||
boolean isStatic,
|
boolean isStatic,
|
||||||
@NotNull String name,
|
@NotNull String name,
|
||||||
@@ -288,8 +287,8 @@ public abstract class StackValue {
|
|||||||
return None.INSTANCE;
|
return None.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StackValue fieldForSharedVar(Type type, JvmClassName name, String fieldName) {
|
public static StackValue fieldForSharedVar(Type localType, Type classType, String fieldName) {
|
||||||
return new FieldForSharedVar(type, name, fieldName);
|
return new FieldForSharedVar(localType, classType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StackValue composed(StackValue prefix, StackValue suffix) {
|
public static StackValue composed(StackValue prefix, StackValue suffix) {
|
||||||
@@ -334,7 +333,7 @@ public abstract class StackValue {
|
|||||||
|
|
||||||
public static Field singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
public static Field singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||||
FieldInfo info = FieldInfo.createForSingleton(classDescriptor, typeMapper);
|
FieldInfo info = FieldInfo.createForSingleton(classDescriptor, typeMapper);
|
||||||
return field(info.getFieldType(), JvmClassName.byInternalName(info.getOwnerInternalName()), info.getFieldName(), true);
|
return field(info.getFieldType(), Type.getObjectType(info.getOwnerInternalName()), info.getFieldName(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class None extends StackValue {
|
private static class None extends StackValue {
|
||||||
@@ -830,10 +829,10 @@ public abstract class StackValue {
|
|||||||
|
|
||||||
|
|
||||||
static class Field extends StackValueWithSimpleReceiver {
|
static class Field extends StackValueWithSimpleReceiver {
|
||||||
final JvmClassName owner;
|
final Type owner;
|
||||||
final String name;
|
final String name;
|
||||||
|
|
||||||
public Field(Type type, JvmClassName owner, String name, boolean isStatic) {
|
public Field(Type type, Type owner, String name, boolean isStatic) {
|
||||||
super(type, isStatic);
|
super(type, isStatic);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -858,7 +857,7 @@ public abstract class StackValue {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private final CallableMethod setter;
|
private final CallableMethod setter;
|
||||||
@NotNull
|
@NotNull
|
||||||
public final JvmClassName methodOwner;
|
public final Type methodOwner;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final PropertyDescriptor descriptor;
|
private final PropertyDescriptor descriptor;
|
||||||
@@ -868,7 +867,7 @@ public abstract class StackValue {
|
|||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
public Property(
|
public Property(
|
||||||
@NotNull PropertyDescriptor descriptor, @NotNull JvmClassName methodOwner,
|
@NotNull PropertyDescriptor descriptor, @NotNull Type methodOwner,
|
||||||
@Nullable CallableMethod getter, @Nullable CallableMethod setter, boolean isStatic,
|
@Nullable CallableMethod getter, @Nullable CallableMethod setter, boolean isStatic,
|
||||||
@NotNull String name, @NotNull Type type, @NotNull GenerationState state
|
@NotNull String name, @NotNull Type type, @NotNull GenerationState state
|
||||||
) {
|
) {
|
||||||
@@ -1014,10 +1013,10 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class FieldForSharedVar extends StackValueWithSimpleReceiver {
|
static class FieldForSharedVar extends StackValueWithSimpleReceiver {
|
||||||
final JvmClassName owner;
|
final Type owner;
|
||||||
final String name;
|
final String name;
|
||||||
|
|
||||||
public FieldForSharedVar(Type type, JvmClassName owner, String name) {
|
public FieldForSharedVar(Type type, Type owner, String name) {
|
||||||
super(type, false);
|
super(type, false);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -1162,7 +1161,7 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return callableMethod.getThisType().getAsmType();
|
return callableMethod.getThisType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1198,7 +1197,7 @@ public abstract class StackValue {
|
|||||||
if (thisObject.exists()) {
|
if (thisObject.exists()) {
|
||||||
if (receiverArgument.exists()) {
|
if (receiverArgument.exists()) {
|
||||||
if (callableMethod != null) {
|
if (callableMethod != null) {
|
||||||
codegen.generateFromResolvedCall(thisObject, callableMethod.getOwner().getAsmType());
|
codegen.generateFromResolvedCall(thisObject, callableMethod.getOwner());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
codegen.generateFromResolvedCall(thisObject, codegen.typeMapper
|
codegen.generateFromResolvedCall(thisObject, codegen.typeMapper
|
||||||
|
|||||||
+1
-1
@@ -131,7 +131,7 @@ class CodegenAnnotatingVisitor extends JetVisitorVoid {
|
|||||||
ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_SCRIPT, bindingContext.get(SCRIPT, file.getScript()));
|
ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_SCRIPT, bindingContext.get(SCRIPT, file.getScript()));
|
||||||
classStack.push(classDescriptor);
|
classStack.push(classDescriptor);
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
nameStack.push(classNameForScriptPsi(bindingContext, file.getScript()).getInternalName());
|
nameStack.push(asmTypeForScriptPsi(bindingContext, file.getScript()).getInternalName());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
nameStack.push(JvmClassName.byFqNameWithoutInnerClasses(JetPsiUtil.getFQName(file)).getInternalName());
|
nameStack.push(JvmClassName.byFqNameWithoutInnerClasses(JetPsiUtil.getFQName(file)).getInternalName());
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
|||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl;
|
import org.jetbrains.jet.lang.descriptors.impl.ClassDescriptorImpl;
|
||||||
@@ -79,19 +80,19 @@ public class CodegenBinding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName classNameForScriptDescriptor(BindingContext bindingContext, @NotNull ScriptDescriptor scriptDescriptor) {
|
public static Type asmTypeForScriptDescriptor(BindingContext bindingContext, @NotNull ScriptDescriptor scriptDescriptor) {
|
||||||
ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_SCRIPT, scriptDescriptor);
|
ClassDescriptor classDescriptor = bindingContext.get(CLASS_FOR_SCRIPT, scriptDescriptor);
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return fqn(bindingContext, classDescriptor);
|
return fqn(bindingContext, classDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName classNameForScriptPsi(BindingContext bindingContext, @NotNull JetScript script) {
|
public static Type asmTypeForScriptPsi(BindingContext bindingContext, @NotNull JetScript script) {
|
||||||
ScriptDescriptor scriptDescriptor = bindingContext.get(SCRIPT, script);
|
ScriptDescriptor scriptDescriptor = bindingContext.get(SCRIPT, script);
|
||||||
if (scriptDescriptor == null) {
|
if (scriptDescriptor == null) {
|
||||||
throw new IllegalStateException("Script descriptor not found by PSI " + script);
|
throw new IllegalStateException("Script descriptor not found by PSI " + script);
|
||||||
}
|
}
|
||||||
return classNameForScriptDescriptor(bindingContext, scriptDescriptor);
|
return asmTypeForScriptDescriptor(bindingContext, scriptDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClassDescriptor enclosingClassDescriptor(BindingContext bindingContext, ClassDescriptor descriptor) {
|
public static ClassDescriptor enclosingClassDescriptor(BindingContext bindingContext, ClassDescriptor descriptor) {
|
||||||
@@ -109,13 +110,13 @@ public class CodegenBinding {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static JvmClassName fqn(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor descriptor) {
|
private static Type fqn(@NotNull BindingContext bindingContext, @NotNull ClassDescriptor descriptor) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return bindingContext.get(FQN, descriptor);
|
return bindingContext.get(FQN, descriptor).getAsmType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName classNameForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull JetElement expression) {
|
public static Type asmTypeForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull JetElement expression) {
|
||||||
if (expression instanceof JetObjectLiteralExpression) {
|
if (expression instanceof JetObjectLiteralExpression) {
|
||||||
JetObjectLiteralExpression jetObjectLiteralExpression = (JetObjectLiteralExpression) expression;
|
JetObjectLiteralExpression jetObjectLiteralExpression = (JetObjectLiteralExpression) expression;
|
||||||
expression = jetObjectLiteralExpression.getObjectDeclaration();
|
expression = jetObjectLiteralExpression.getObjectDeclaration();
|
||||||
@@ -125,14 +126,14 @@ public class CodegenBinding {
|
|||||||
if (descriptor == null) {
|
if (descriptor == null) {
|
||||||
SimpleFunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression);
|
SimpleFunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression);
|
||||||
assert functionDescriptor != null;
|
assert functionDescriptor != null;
|
||||||
return classNameForAnonymousClass(bindingContext, functionDescriptor);
|
return asmTypeForAnonymousClass(bindingContext, functionDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return fqn(bindingContext, descriptor);
|
return fqn(bindingContext, descriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JvmClassName classNameForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull FunctionDescriptor descriptor) {
|
public static Type asmTypeForAnonymousClass(@NotNull BindingContext bindingContext, @NotNull FunctionDescriptor descriptor) {
|
||||||
ClassDescriptor classDescriptor = anonymousClassForFunction(bindingContext, descriptor);
|
ClassDescriptor classDescriptor = anonymousClassForFunction(bindingContext, descriptor);
|
||||||
return fqn(bindingContext, classDescriptor);
|
return fqn(bindingContext, classDescriptor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public FieldOwnerContext intoNamespacePart(@NotNull JvmClassName delegateTo, @NotNull NamespaceDescriptor descriptor) {
|
public FieldOwnerContext intoNamespacePart(@NotNull Type delegateTo, @NotNull NamespaceDescriptor descriptor) {
|
||||||
return new NamespaceContext(descriptor, this, new OwnerKind.StaticDelegateKind(delegateTo));
|
return new NamespaceContext(descriptor, this, new OwnerKind.StaticDelegateKind(delegateTo));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
ClassDescriptor enclosingClass = getEnclosingClass();
|
ClassDescriptor enclosingClass = getEnclosingClass();
|
||||||
outerExpression = enclosingClass != null && canHaveOuter(typeMapper.getBindingContext(), classDescriptor)
|
outerExpression = enclosingClass != null && canHaveOuter(typeMapper.getBindingContext(), classDescriptor)
|
||||||
? StackValue.field(typeMapper.mapType(enclosingClass),
|
? StackValue.field(typeMapper.mapType(enclosingClass),
|
||||||
CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor),
|
CodegenBinding.getJvmInternalName(typeMapper.getBindingTrace(), classDescriptor).getAsmType(),
|
||||||
CAPTURED_THIS_FIELD,
|
CAPTURED_THIS_FIELD,
|
||||||
false)
|
false)
|
||||||
: null;
|
: null;
|
||||||
@@ -295,7 +295,9 @@ public abstract class CodegenContext<T extends DeclarationDescriptor> {
|
|||||||
|
|
||||||
for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) {
|
for (LocalLookup.LocalLookupCase aCase : LocalLookup.LocalLookupCase.values()) {
|
||||||
if (aCase.isCase(d, state)) {
|
if (aCase.isCase(d, state)) {
|
||||||
StackValue innerValue = aCase.innerValue(d, enclosingLocalLookup, state, closure, state.getBindingContext().get(FQN, getThisDescriptor()));
|
JvmClassName className = state.getBindingContext().get(FQN, getThisDescriptor());
|
||||||
|
Type classType = className == null ? null : className.getAsmType();
|
||||||
|
StackValue innerValue = aCase.innerValue(d, enclosingLocalLookup, state, closure, classType);
|
||||||
if (innerValue == null) {
|
if (innerValue == null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,10 @@ import org.jetbrains.jet.codegen.StackValue;
|
|||||||
import org.jetbrains.jet.codegen.binding.MutableClosure;
|
import org.jetbrains.jet.codegen.binding.MutableClosure;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.CAPTURED_RECEIVER_FIELD;
|
import static org.jetbrains.jet.codegen.AsmUtil.CAPTURED_RECEIVER_FIELD;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
|
||||||
|
|
||||||
public interface LocalLookup {
|
public interface LocalLookup {
|
||||||
@@ -44,7 +43,8 @@ public interface LocalLookup {
|
|||||||
DeclarationDescriptor d,
|
DeclarationDescriptor d,
|
||||||
LocalLookup localLookup,
|
LocalLookup localLookup,
|
||||||
GenerationState state,
|
GenerationState state,
|
||||||
MutableClosure closure, JvmClassName className
|
MutableClosure closure,
|
||||||
|
Type classType
|
||||||
) {
|
) {
|
||||||
VariableDescriptor vd = (VariableDescriptor) d;
|
VariableDescriptor vd = (VariableDescriptor) d;
|
||||||
|
|
||||||
@@ -57,8 +57,8 @@ public interface LocalLookup {
|
|||||||
|
|
||||||
String fieldName = "$" + vd.getName();
|
String fieldName = "$" + vd.getName();
|
||||||
StackValue innerValue = sharedVarType != null
|
StackValue innerValue = sharedVarType != null
|
||||||
? StackValue.fieldForSharedVar(localType, className, fieldName)
|
? StackValue.fieldForSharedVar(localType, classType, fieldName)
|
||||||
: StackValue.field(type, className, fieldName, false);
|
: StackValue.field(type, classType, fieldName, false);
|
||||||
|
|
||||||
closure.recordField(fieldName, type);
|
closure.recordField(fieldName, type);
|
||||||
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, type));
|
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, type));
|
||||||
@@ -79,17 +79,17 @@ public interface LocalLookup {
|
|||||||
LocalLookup localLookup,
|
LocalLookup localLookup,
|
||||||
GenerationState state,
|
GenerationState state,
|
||||||
MutableClosure closure,
|
MutableClosure closure,
|
||||||
JvmClassName className
|
Type classType
|
||||||
) {
|
) {
|
||||||
FunctionDescriptor vd = (FunctionDescriptor) d;
|
FunctionDescriptor vd = (FunctionDescriptor) d;
|
||||||
|
|
||||||
boolean idx = localLookup != null && localLookup.lookupLocal(vd);
|
boolean idx = localLookup != null && localLookup.lookupLocal(vd);
|
||||||
if (!idx) return null;
|
if (!idx) return null;
|
||||||
|
|
||||||
Type localType = classNameForAnonymousClass(state.getBindingContext(), vd).getAsmType();
|
Type localType = asmTypeForAnonymousClass(state.getBindingContext(), vd);
|
||||||
|
|
||||||
String fieldName = "$" + vd.getName();
|
String fieldName = "$" + vd.getName();
|
||||||
StackValue innerValue = StackValue.field(localType, className, fieldName, false);
|
StackValue innerValue = StackValue.field(localType, classType, fieldName, false);
|
||||||
|
|
||||||
closure.recordField(fieldName, localType);
|
closure.recordField(fieldName, localType);
|
||||||
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, localType));
|
closure.captureVariable(new EnclosedValueDescriptor(d, innerValue, localType));
|
||||||
@@ -109,13 +109,14 @@ public interface LocalLookup {
|
|||||||
DeclarationDescriptor d,
|
DeclarationDescriptor d,
|
||||||
LocalLookup enclosingLocalLookup,
|
LocalLookup enclosingLocalLookup,
|
||||||
GenerationState state,
|
GenerationState state,
|
||||||
MutableClosure closure, JvmClassName className
|
MutableClosure closure,
|
||||||
|
Type classType
|
||||||
) {
|
) {
|
||||||
if (closure.getEnclosingReceiverDescriptor() != d) return null;
|
if (closure.getEnclosingReceiverDescriptor() != d) return null;
|
||||||
|
|
||||||
JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
|
JetType receiverType = ((CallableDescriptor) d).getReceiverParameter().getType();
|
||||||
Type type = state.getTypeMapper().mapType(receiverType);
|
Type type = state.getTypeMapper().mapType(receiverType);
|
||||||
StackValue innerValue = StackValue.field(type, className, CAPTURED_RECEIVER_FIELD, false);
|
StackValue innerValue = StackValue.field(type, classType, CAPTURED_RECEIVER_FIELD, false);
|
||||||
closure.setCaptureReceiver();
|
closure.setCaptureReceiver();
|
||||||
|
|
||||||
return innerValue;
|
return innerValue;
|
||||||
@@ -135,7 +136,7 @@ public interface LocalLookup {
|
|||||||
LocalLookup localLookup,
|
LocalLookup localLookup,
|
||||||
GenerationState state,
|
GenerationState state,
|
||||||
MutableClosure closure,
|
MutableClosure closure,
|
||||||
JvmClassName className
|
Type classType
|
||||||
);
|
);
|
||||||
|
|
||||||
public StackValue outerValue(EnclosedValueDescriptor d, ExpressionCodegen expressionCodegen) {
|
public StackValue outerValue(EnclosedValueDescriptor d, ExpressionCodegen expressionCodegen) {
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ import static org.jetbrains.jet.codegen.AsmUtil.getTraitImplThisParameterType;
|
|||||||
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
import static org.jetbrains.jet.codegen.CodegenUtil.*;
|
||||||
import static org.jetbrains.jet.codegen.FunctionTypesUtil.getFunctionTraitClassName;
|
import static org.jetbrains.jet.codegen.FunctionTypesUtil.getFunctionTraitClassName;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
|
|
||||||
|
|
||||||
public class JetTypeMapper extends BindingTraceAware {
|
public class JetTypeMapper extends BindingTraceAware {
|
||||||
|
|
||||||
@@ -68,12 +67,12 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JvmClassName getOwner(DeclarationDescriptor descriptor, OwnerKind kind, boolean isInsideModule) {
|
public Type getOwner(DeclarationDescriptor descriptor, OwnerKind kind, boolean isInsideModule) {
|
||||||
JetTypeMapperMode mapTypeMode = ownerKindToMapTypeMode(kind);
|
JetTypeMapperMode mapTypeMode = ownerKindToMapTypeMode(kind);
|
||||||
|
|
||||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
if (containingDeclaration instanceof NamespaceDescriptor) {
|
if (containingDeclaration instanceof NamespaceDescriptor) {
|
||||||
return jvmClassNameForNamespace((NamespaceDescriptor) containingDeclaration, descriptor, isInsideModule);
|
return asmTypeForNamespace((NamespaceDescriptor) containingDeclaration, descriptor, isInsideModule);
|
||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof ClassDescriptor) {
|
else if (containingDeclaration instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||||
@@ -84,10 +83,10 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
if (asmType.getSort() != Type.OBJECT) {
|
if (asmType.getSort() != Type.OBJECT) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
return JvmClassName.byType(asmType);
|
return asmType;
|
||||||
}
|
}
|
||||||
else if (containingDeclaration instanceof ScriptDescriptor) {
|
else if (containingDeclaration instanceof ScriptDescriptor) {
|
||||||
return classNameForScriptDescriptor(bindingContext, (ScriptDescriptor) containingDeclaration);
|
return asmTypeForScriptDescriptor(bindingContext, (ScriptDescriptor) containingDeclaration);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("don't know how to generate owner for parent " + containingDeclaration);
|
throw new UnsupportedOperationException("don't know how to generate owner for parent " + containingDeclaration);
|
||||||
@@ -128,7 +127,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JvmClassName jvmClassNameForNamespace(
|
private Type asmTypeForNamespace(
|
||||||
@NotNull NamespaceDescriptor namespace,
|
@NotNull NamespaceDescriptor namespace,
|
||||||
@NotNull DeclarationDescriptor descriptor,
|
@NotNull DeclarationDescriptor descriptor,
|
||||||
boolean insideModule
|
boolean insideModule
|
||||||
@@ -170,7 +169,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
throw new IllegalStateException("internal error: failed to generate classname for " + namespace);
|
throw new IllegalStateException("internal error: failed to generate classname for " + namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
return JvmClassName.byInternalName(r.toString());
|
return Type.getObjectType(r.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -482,11 +481,11 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
functionDescriptor = unwrapFakeOverride(functionDescriptor);
|
functionDescriptor = unwrapFakeOverride(functionDescriptor);
|
||||||
|
|
||||||
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, kind);
|
JvmMethodSignature descriptor = mapSignature(functionDescriptor.getOriginal(), true, kind);
|
||||||
JvmClassName owner;
|
Type owner;
|
||||||
JvmClassName ownerForDefaultImpl;
|
Type ownerForDefaultImpl;
|
||||||
JvmClassName ownerForDefaultParam;
|
Type ownerForDefaultParam;
|
||||||
int invokeOpcode;
|
int invokeOpcode;
|
||||||
JvmClassName thisClass;
|
Type thisClass;
|
||||||
Type calleeType = null;
|
Type calleeType = null;
|
||||||
|
|
||||||
if (isLocalNamedFun(functionDescriptor) || functionDescriptor instanceof ExpressionAsFunctionDescriptor) {
|
if (isLocalNamedFun(functionDescriptor) || functionDescriptor instanceof ExpressionAsFunctionDescriptor) {
|
||||||
@@ -499,15 +498,15 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
}
|
}
|
||||||
functionDescriptor = functionDescriptor.getOriginal();
|
functionDescriptor = functionDescriptor.getOriginal();
|
||||||
|
|
||||||
owner = classNameForAnonymousClass(bindingContext, functionDescriptor);
|
owner = asmTypeForAnonymousClass(bindingContext, functionDescriptor);
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = thisClass = owner;
|
ownerForDefaultImpl = ownerForDefaultParam = thisClass = owner;
|
||||||
invokeOpcode = INVOKEVIRTUAL;
|
invokeOpcode = INVOKEVIRTUAL;
|
||||||
descriptor = mapSignature("invoke", functionDescriptor, true, kind);
|
descriptor = mapSignature("invoke", functionDescriptor, true, kind);
|
||||||
calleeType = owner.getAsmType();
|
calleeType = owner;
|
||||||
}
|
}
|
||||||
else if (functionParent instanceof NamespaceDescriptor) {
|
else if (functionParent instanceof NamespaceDescriptor) {
|
||||||
assert !superCall;
|
assert !superCall;
|
||||||
owner = jvmClassNameForNamespace((NamespaceDescriptor) functionParent, functionDescriptor, isInsideModule);
|
owner = asmTypeForNamespace((NamespaceDescriptor) functionParent, functionDescriptor, isInsideModule);
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
||||||
invokeOpcode = INVOKESTATIC;
|
invokeOpcode = INVOKESTATIC;
|
||||||
thisClass = null;
|
thisClass = null;
|
||||||
@@ -515,14 +514,14 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
else if (functionDescriptor instanceof ConstructorDescriptor) {
|
else if (functionDescriptor instanceof ConstructorDescriptor) {
|
||||||
assert !superCall;
|
assert !superCall;
|
||||||
ClassDescriptor containingClass = (ClassDescriptor) functionParent;
|
ClassDescriptor containingClass = (ClassDescriptor) functionParent;
|
||||||
owner = JvmClassName.byType(mapType(containingClass.getDefaultType(), JetTypeMapperMode.IMPL));
|
owner = mapType(containingClass.getDefaultType(), JetTypeMapperMode.IMPL);
|
||||||
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
ownerForDefaultImpl = ownerForDefaultParam = owner;
|
||||||
invokeOpcode = INVOKESPECIAL;
|
invokeOpcode = INVOKESPECIAL;
|
||||||
thisClass = null;
|
thisClass = null;
|
||||||
}
|
}
|
||||||
else if (functionParent instanceof ScriptDescriptor) {
|
else if (functionParent instanceof ScriptDescriptor) {
|
||||||
thisClass = owner =
|
thisClass = owner = ownerForDefaultParam = ownerForDefaultImpl =
|
||||||
ownerForDefaultParam = ownerForDefaultImpl = classNameForScriptDescriptor(bindingContext, (ScriptDescriptor) functionParent);
|
asmTypeForScriptDescriptor(bindingContext, (ScriptDescriptor) functionParent);
|
||||||
invokeOpcode = INVOKEVIRTUAL;
|
invokeOpcode = INVOKEVIRTUAL;
|
||||||
}
|
}
|
||||||
else if (functionParent instanceof ClassDescriptor) {
|
else if (functionParent instanceof ClassDescriptor) {
|
||||||
@@ -548,12 +547,11 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
// TODO: TYPE_PARAMETER is hack here
|
// TODO: TYPE_PARAMETER is hack here
|
||||||
|
|
||||||
boolean isInterface = originalIsInterface && currentIsInterface;
|
boolean isInterface = originalIsInterface && currentIsInterface;
|
||||||
Type type = mapType(receiver.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER);
|
owner = mapType(receiver.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER);
|
||||||
owner = JvmClassName.byType(type);
|
|
||||||
|
|
||||||
ClassDescriptor declarationOwnerForDefault = (ClassDescriptor) findBaseDeclaration(functionDescriptor).getContainingDeclaration();
|
ClassDescriptor declarationOwnerForDefault = (ClassDescriptor) findBaseDeclaration(functionDescriptor).getContainingDeclaration();
|
||||||
ownerForDefaultParam = JvmClassName.byType(mapType(declarationOwnerForDefault.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER));
|
ownerForDefaultParam = mapType(declarationOwnerForDefault.getDefaultType(), JetTypeMapperMode.TYPE_PARAMETER);
|
||||||
ownerForDefaultImpl = JvmClassName.byInternalName(
|
ownerForDefaultImpl = Type.getObjectType(
|
||||||
ownerForDefaultParam.getInternalName() + (isInterface(declarationOwnerForDefault) ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
|
ownerForDefaultParam.getInternalName() + (isInterface(declarationOwnerForDefault) ? JvmAbi.TRAIT_IMPL_SUFFIX : ""));
|
||||||
if (isInterface) {
|
if (isInterface) {
|
||||||
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE;
|
invokeOpcode = superCall ? INVOKESTATIC : INVOKEINTERFACE;
|
||||||
@@ -570,9 +568,9 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
|
|
||||||
if (isInterface && superCall) {
|
if (isInterface && superCall) {
|
||||||
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
|
descriptor = mapSignature(functionDescriptor, false, OwnerKind.TRAIT_IMPL);
|
||||||
owner = JvmClassName.byInternalName(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
owner = Type.getObjectType(owner.getInternalName() + JvmAbi.TRAIT_IMPL_SUFFIX);
|
||||||
}
|
}
|
||||||
thisClass = JvmClassName.byType(mapType(receiver.getDefaultType()));
|
thisClass = mapType(receiver.getDefaultType());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("unknown function parent");
|
throw new UnsupportedOperationException("unknown function parent");
|
||||||
@@ -876,7 +874,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
type = sharedVarType;
|
type = sharedVarType;
|
||||||
}
|
}
|
||||||
else if (isLocalNamedFun(variableDescriptor)) {
|
else if (isLocalNamedFun(variableDescriptor)) {
|
||||||
type = classNameForAnonymousClass(bindingContext, (FunctionDescriptor) variableDescriptor).getAsmType();
|
type = asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) variableDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
@@ -953,11 +951,10 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
public CallableMethod mapToCallableMethod(@NotNull ConstructorDescriptor descriptor, @Nullable CalculatedClosure closure) {
|
public CallableMethod mapToCallableMethod(@NotNull ConstructorDescriptor descriptor, @Nullable CalculatedClosure closure) {
|
||||||
JvmMethodSignature method = mapConstructorSignature(descriptor, closure);
|
JvmMethodSignature method = mapConstructorSignature(descriptor, closure);
|
||||||
JetType defaultType = descriptor.getContainingDeclaration().getDefaultType();
|
JetType defaultType = descriptor.getContainingDeclaration().getDefaultType();
|
||||||
Type mapped = mapType(defaultType, JetTypeMapperMode.IMPL);
|
Type owner = mapType(defaultType, JetTypeMapperMode.IMPL);
|
||||||
if (mapped.getSort() != Type.OBJECT) {
|
if (owner.getSort() != Type.OBJECT) {
|
||||||
throw new IllegalStateException("type must have been mapped to object: " + defaultType + ", actual: " + mapped);
|
throw new IllegalStateException("type must have been mapped to object: " + defaultType + ", actual: " + owner);
|
||||||
}
|
}
|
||||||
JvmClassName owner = JvmClassName.byType(mapped);
|
|
||||||
return new CallableMethod(owner, owner, owner, method, INVOKESPECIAL, null, null, null);
|
return new CallableMethod(owner, owner, owner, method, INVOKESPECIAL, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -969,15 +966,13 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
|
|
||||||
public Type getSharedVarType(DeclarationDescriptor descriptor) {
|
public Type getSharedVarType(DeclarationDescriptor descriptor) {
|
||||||
if (descriptor instanceof PropertyDescriptor) {
|
if (descriptor instanceof PropertyDescriptor) {
|
||||||
return StackValue
|
return StackValue.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType()));
|
||||||
.sharedTypeForType(mapType(((PropertyDescriptor) descriptor).getReceiverParameter().getType()));
|
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
|
else if (descriptor instanceof SimpleFunctionDescriptor && descriptor.getContainingDeclaration() instanceof FunctionDescriptor) {
|
||||||
return classNameForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor).getAsmType();
|
return asmTypeForAnonymousClass(bindingContext, (FunctionDescriptor) descriptor);
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof FunctionDescriptor) {
|
else if (descriptor instanceof FunctionDescriptor) {
|
||||||
return StackValue
|
return StackValue.sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType()));
|
||||||
.sharedTypeForType(mapType(((FunctionDescriptor) descriptor).getReceiverParameter().getType()));
|
|
||||||
}
|
}
|
||||||
else if (descriptor instanceof VariableDescriptor && isVarCapturedInClosure(bindingContext, descriptor)) {
|
else if (descriptor instanceof VariableDescriptor && isVarCapturedInClosure(bindingContext, descriptor)) {
|
||||||
JetType outType = ((VariableDescriptor) descriptor).getType();
|
JetType outType = ((VariableDescriptor) descriptor).getType();
|
||||||
@@ -989,7 +984,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public CallableMethod mapToFunctionInvokeCallableMethod(@NotNull FunctionDescriptor fd) {
|
public CallableMethod mapToFunctionInvokeCallableMethod(@NotNull FunctionDescriptor fd) {
|
||||||
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
|
JvmMethodSignature descriptor = erasedInvokeSignature(fd);
|
||||||
JvmClassName owner = getFunctionTraitClassName(fd);
|
Type owner = getFunctionTraitClassName(fd);
|
||||||
Type receiverParameterType;
|
Type receiverParameterType;
|
||||||
ReceiverParameterDescriptor receiverParameter = fd.getOriginal().getReceiverParameter();
|
ReceiverParameterDescriptor receiverParameter = fd.getOriginal().getReceiverParameter();
|
||||||
if (receiverParameter != null) {
|
if (receiverParameter != null) {
|
||||||
@@ -998,7 +993,7 @@ public class JetTypeMapper extends BindingTraceAware {
|
|||||||
else {
|
else {
|
||||||
receiverParameterType = null;
|
receiverParameterType = null;
|
||||||
}
|
}
|
||||||
return new CallableMethod(owner, null, null, descriptor, INVOKEINTERFACE, owner, receiverParameterType, owner.getAsmType());
|
return new CallableMethod(owner, null, null, descriptor, INVOKEINTERFACE, owner, receiverParameterType, owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
package org.jetbrains.jet.cli.jvm.repl;
|
package org.jetbrains.jet.cli.jvm.repl;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
|
||||||
|
|
||||||
public class EarlierLine {
|
public class EarlierLine {
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -30,14 +30,14 @@ public class EarlierLine {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final Object scriptInstance;
|
private final Object scriptInstance;
|
||||||
@NotNull
|
@NotNull
|
||||||
private final JvmClassName className;
|
private final Type classType;
|
||||||
|
|
||||||
public EarlierLine(@NotNull String code, @NotNull ScriptDescriptor scriptDescriptor, @NotNull Class<?> scriptClass, @NotNull Object scriptInstance, @NotNull JvmClassName className) {
|
public EarlierLine(@NotNull String code, @NotNull ScriptDescriptor scriptDescriptor, @NotNull Class<?> scriptClass, @NotNull Object scriptInstance, @NotNull Type classType) {
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.scriptDescriptor = scriptDescriptor;
|
this.scriptDescriptor = scriptDescriptor;
|
||||||
this.scriptClass = scriptClass;
|
this.scriptClass = scriptClass;
|
||||||
this.scriptInstance = scriptInstance;
|
this.scriptInstance = scriptInstance;
|
||||||
this.className = className;
|
this.classType = classType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -61,7 +61,7 @@ public class EarlierLine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public JvmClassName getClassName() {
|
public Type getClassType() {
|
||||||
return className;
|
return classType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.intellij.psi.impl.PsiFileFactoryImpl;
|
|||||||
import com.intellij.testFramework.LightVirtualFile;
|
import com.intellij.testFramework.LightVirtualFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
import org.jetbrains.jet.cli.common.messages.AnalyzerWithCompilerReport;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
@@ -66,6 +67,8 @@ import java.net.URLClassLoader;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.codegen.AsmUtil.fqNameByAsmTypeUnsafe;
|
||||||
|
|
||||||
public class ReplInterpreter {
|
public class ReplInterpreter {
|
||||||
|
|
||||||
private int lineNumber = 0;
|
private int lineNumber = 0;
|
||||||
@@ -181,7 +184,7 @@ public class ReplInterpreter {
|
|||||||
public LineResult eval(@NotNull String line) {
|
public LineResult eval(@NotNull String line) {
|
||||||
++lineNumber;
|
++lineNumber;
|
||||||
|
|
||||||
JvmClassName scriptClassName = JvmClassName.byInternalName("Line" + lineNumber);
|
Type scriptClassType = Type.getObjectType("Line" + lineNumber);
|
||||||
|
|
||||||
StringBuilder fullText = new StringBuilder();
|
StringBuilder fullText = new StringBuilder();
|
||||||
for (String prevLine : previousIncompleteLines) {
|
for (String prevLine : previousIncompleteLines) {
|
||||||
@@ -219,16 +222,16 @@ public class ReplInterpreter {
|
|||||||
return LineResult.error(errorCollector.getString());
|
return LineResult.error(errorCollector.getString());
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Pair<ScriptDescriptor, JvmClassName>> earierScripts = Lists.newArrayList();
|
List<Pair<ScriptDescriptor, Type>> earlierScripts = Lists.newArrayList();
|
||||||
|
|
||||||
for (EarlierLine earlierLine : earlierLines) {
|
for (EarlierLine earlierLine : earlierLines) {
|
||||||
earierScripts.add(Pair.create(earlierLine.getScriptDescriptor(), earlierLine.getClassName()));
|
earlierScripts.add(Pair.create(earlierLine.getScriptDescriptor(), earlierLine.getClassType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
BindingContext bindingContext = AnalyzeExhaust.success(trace.getBindingContext(), module).getBindingContext();
|
BindingContext bindingContext = AnalyzeExhaust.success(trace.getBindingContext(), module).getBindingContext();
|
||||||
GenerationState generationState = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false),
|
GenerationState generationState = new GenerationState(psiFile.getProject(), ClassBuilderFactories.binaries(false),
|
||||||
bindingContext, Collections.singletonList(psiFile));
|
bindingContext, Collections.singletonList(psiFile));
|
||||||
generationState.getScriptCodegen().compileScript(psiFile.getScript(), scriptClassName, earierScripts,
|
generationState.getScriptCodegen().compileScript(psiFile.getScript(), scriptClassType, earlierScripts,
|
||||||
CompilationErrorHandler.THROW_EXCEPTION);
|
CompilationErrorHandler.THROW_EXCEPTION);
|
||||||
|
|
||||||
for (String file : generationState.getFactory().files()) {
|
for (String file : generationState.getFactory().files()) {
|
||||||
@@ -236,7 +239,7 @@ public class ReplInterpreter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Class<?> scriptClass = classLoader.loadClass(scriptClassName.getFqName().asString());
|
Class<?> scriptClass = classLoader.loadClass(fqNameByAsmTypeUnsafe(scriptClassType).asString());
|
||||||
|
|
||||||
Class<?>[] constructorParams = new Class<?>[earlierLines.size()];
|
Class<?>[] constructorParams = new Class<?>[earlierLines.size()];
|
||||||
Object[] constructorArgs = new Object[earlierLines.size()];
|
Object[] constructorArgs = new Object[earlierLines.size()];
|
||||||
@@ -257,7 +260,7 @@ public class ReplInterpreter {
|
|||||||
rvField.setAccessible(true);
|
rvField.setAccessible(true);
|
||||||
Object rv = rvField.get(scriptInstance);
|
Object rv = rvField.get(scriptInstance);
|
||||||
|
|
||||||
earlierLines.add(new EarlierLine(line, scriptDescriptor, scriptClass, scriptInstance, scriptClassName));
|
earlierLines.add(new EarlierLine(line, scriptDescriptor, scriptClass, scriptInstance, scriptClassType));
|
||||||
|
|
||||||
return LineResult.successful(rv, scriptDescriptor.getReturnType().equals(KotlinBuiltIns.getInstance().getUnitType()));
|
return LineResult.successful(rv, scriptDescriptor.getReturnType().equals(KotlinBuiltIns.getInstance().getUnitType()));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|||||||
+1
-1
@@ -210,7 +210,7 @@ public class TypeTransformingVisitor extends JetVisitor<JetType, Void> {
|
|||||||
Type javaAnalog = KotlinToJavaTypesMap.getInstance().getJavaAnalog(originalType);
|
Type javaAnalog = KotlinToJavaTypesMap.getInstance().getJavaAnalog(originalType);
|
||||||
if (javaAnalog == null || javaAnalog.getSort() != Type.OBJECT) return null;
|
if (javaAnalog == null || javaAnalog.getSort() != Type.OBJECT) return null;
|
||||||
Collection<ClassDescriptor> descriptors =
|
Collection<ClassDescriptor> descriptors =
|
||||||
JavaToKotlinClassMap.getInstance().mapPlatformClass(JvmClassName.byType(javaAnalog).getFqName());
|
JavaToKotlinClassMap.getInstance().mapPlatformClass(JvmClassName.byInternalName(javaAnalog.getInternalName()).getFqName());
|
||||||
for (ClassDescriptor descriptor : descriptors) {
|
for (ClassDescriptor descriptor : descriptors) {
|
||||||
String fqName = DescriptorUtils.getFQName(descriptor).asString();
|
String fqName = DescriptorUtils.getFQName(descriptor).asString();
|
||||||
if (isSameName(qualifiedName, fqName)) {
|
if (isSameName(qualifiedName, fqName)) {
|
||||||
|
|||||||
@@ -28,14 +28,6 @@ public class JvmClassName {
|
|||||||
return new JvmClassName(internalName);
|
return new JvmClassName(internalName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JvmClassName byType(@NotNull Type type) {
|
|
||||||
if (type.getSort() != Type.OBJECT) {
|
|
||||||
throw new IllegalArgumentException("Type is not convertible to " + JvmClassName.class.getSimpleName() + ": " + type);
|
|
||||||
}
|
|
||||||
return byInternalName(type.getInternalName());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WARNING: fq name cannot be uniquely mapped to JVM class name.
|
* WARNING: fq name cannot be uniquely mapped to JVM class name.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import com.sun.jdi.request.ClassPrepareRequest;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.TestOnly;
|
import org.jetbrains.annotations.TestOnly;
|
||||||
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||||
import org.jetbrains.jet.codegen.ClassBuilderMode;
|
import org.jetbrains.jet.codegen.ClassBuilderMode;
|
||||||
import org.jetbrains.jet.codegen.NamespaceCodegen;
|
import org.jetbrains.jet.codegen.NamespaceCodegen;
|
||||||
@@ -55,7 +56,7 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.classNameForAnonymousClass;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.asmTypeForAnonymousClass;
|
||||||
|
|
||||||
public class JetPositionManager implements PositionManager {
|
public class JetPositionManager implements PositionManager {
|
||||||
private final DebugProcess myDebugProcess;
|
private final DebugProcess myDebugProcess;
|
||||||
@@ -139,8 +140,8 @@ public class JetPositionManager implements PositionManager {
|
|||||||
result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) element));
|
result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) element));
|
||||||
}
|
}
|
||||||
else if (element instanceof JetFunctionLiteral) {
|
else if (element instanceof JetFunctionLiteral) {
|
||||||
result.set(classNameForAnonymousClass(typeMapper.getBindingContext(),
|
Type asmType = asmTypeForAnonymousClass(typeMapper.getBindingContext(), ((JetFunctionLiteral) element));
|
||||||
((JetFunctionLiteral) element)).getInternalName());
|
result.set(asmType.getInternalName());
|
||||||
}
|
}
|
||||||
else if (element instanceof JetNamedFunction) {
|
else if (element instanceof JetNamedFunction) {
|
||||||
PsiElement parent = PsiTreeUtil.getParentOfType(element, JetClassOrObject.class, JetFunctionLiteralExpression.class, JetNamedFunction.class);
|
PsiElement parent = PsiTreeUtil.getParentOfType(element, JetClassOrObject.class, JetFunctionLiteralExpression.class, JetNamedFunction.class);
|
||||||
@@ -148,8 +149,8 @@ public class JetPositionManager implements PositionManager {
|
|||||||
result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) parent));
|
result.set(getJvmInternalNameForImpl(typeMapper, (JetClassOrObject) parent));
|
||||||
}
|
}
|
||||||
else if (parent instanceof JetFunctionLiteralExpression || parent instanceof JetNamedFunction) {
|
else if (parent instanceof JetFunctionLiteralExpression || parent instanceof JetNamedFunction) {
|
||||||
result.set(classNameForAnonymousClass(typeMapper.getBindingContext(),
|
Type asmType = asmTypeForAnonymousClass(typeMapper.getBindingContext(), (JetElement) element);
|
||||||
(JetElement) element).getInternalName());
|
result.set(asmType.getInternalName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.codegen.AsmUtil.fqNameByAsmTypeUnsafe;
|
||||||
import static org.jetbrains.jet.plugin.libraries.MemberMatching.*;
|
import static org.jetbrains.jet.plugin.libraries.MemberMatching.*;
|
||||||
|
|
||||||
public class JetSourceNavigationHelper {
|
public class JetSourceNavigationHelper {
|
||||||
@@ -360,7 +361,7 @@ public class JetSourceNavigationHelper {
|
|||||||
if (javaAnalog.getSort() != Type.OBJECT) {
|
if (javaAnalog.getSort() != Type.OBJECT) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String fqName = JvmClassName.byType(javaAnalog).getFqName().asString();
|
String fqName = fqNameByAsmTypeUnsafe(javaAnalog).asString();
|
||||||
return JavaPsiFacade.getInstance(classOrObject.getProject()).
|
return JavaPsiFacade.getInstance(classOrObject.getProject()).
|
||||||
findClass(fqName, GlobalSearchScope.allScope(classOrObject.getProject()));
|
findClass(fqName, GlobalSearchScope.allScope(classOrObject.getProject()));
|
||||||
}
|
}
|
||||||
@@ -390,7 +391,7 @@ public class JetSourceNavigationHelper {
|
|||||||
if (vFile == null || !idx.isInLibrarySource(vFile)) return null;
|
if (vFile == null || !idx.isInLibrarySource(vFile)) return null;
|
||||||
final Set<OrderEntry> orderEntries = new THashSet<OrderEntry>(idx.getOrderEntriesForFile(vFile));
|
final Set<OrderEntry> orderEntries = new THashSet<OrderEntry>(idx.getOrderEntriesForFile(vFile));
|
||||||
|
|
||||||
PsiClass original = JavaPsiFacade.getInstance(project).findClass(fqName, new GlobalSearchScope(project) {
|
return JavaPsiFacade.getInstance(project).findClass(fqName, new GlobalSearchScope(project) {
|
||||||
@Override
|
@Override
|
||||||
public int compare(VirtualFile file1, VirtualFile file2) {
|
public int compare(VirtualFile file1, VirtualFile file2) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -399,9 +400,7 @@ public class JetSourceNavigationHelper {
|
|||||||
@Override
|
@Override
|
||||||
public boolean contains(VirtualFile file) {
|
public boolean contains(VirtualFile file) {
|
||||||
List<OrderEntry> entries = idx.getOrderEntriesForFile(file);
|
List<OrderEntry> entries = idx.getOrderEntriesForFile(file);
|
||||||
//noinspection ForLoopReplaceableByForEach
|
for (OrderEntry entry : entries) {
|
||||||
for (int i = 0; i < entries.size(); i++) {
|
|
||||||
final OrderEntry entry = entries.get(i);
|
|
||||||
if (orderEntries.contains(entry)) return true;
|
if (orderEntries.contains(entry)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -417,8 +416,6 @@ public class JetSourceNavigationHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return original;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
Reference in New Issue
Block a user