generation of inner classes inside object literal. #KT-2607 fixed
on the way ClassCodegen and MemberCodegen refactored out and injectors regenerated
This commit is contained in:
@@ -89,7 +89,7 @@ public abstract class ClassBodyCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration, FunctionCodegen functionCodegen) {
|
protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration, FunctionCodegen functionCodegen) {
|
||||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||||
state.getMemberCodegen().generateFunctionOrProperty((JetTypeParameterListOwner) declaration, context, v);
|
CodegenUtil.generateFunctionOrProperty(state, (JetTypeParameterListOwner) declaration, context, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.codegen.state.GenerationStateAware;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author max
|
|
||||||
* @author alex.tkachman
|
|
||||||
*/
|
|
||||||
public class ClassCodegen extends GenerationStateAware {
|
|
||||||
public ClassCodegen(@NotNull GenerationState state) {
|
|
||||||
super(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generate(CodegenContext context, JetClassOrObject aClass) {
|
|
||||||
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
|
||||||
|
|
||||||
if (descriptor == null || ErrorUtils.isError(descriptor) || descriptor.getName().equals(JetPsiUtil.NO_NAME_PROVIDED)) {
|
|
||||||
if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Generating bad descriptor in ClassBuilderMode = " + state.getClassBuilderMode() + ": " + descriptor);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClassBuilder classBuilder = state.getFactory().forClassImplementation(descriptor);
|
|
||||||
|
|
||||||
final CodegenContext contextForInners = context.intoClass(descriptor, OwnerKind.IMPLEMENTATION, state);
|
|
||||||
|
|
||||||
if (state.getClassBuilderMode() == ClassBuilderMode.SIGNATURES) {
|
|
||||||
// Outer class implementation must happen prior inner classes so we get proper scoping tree in JetLightClass's delegate
|
|
||||||
// The same code is present below for the case when we generate real bytecode. This is because the order should be
|
|
||||||
// different for the case when we compute closures
|
|
||||||
generateImplementation(context, aClass, OwnerKind.IMPLEMENTATION, contextForInners.getAccessors(), classBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (JetDeclaration declaration : aClass.getDeclarations()) {
|
|
||||||
if (declaration instanceof JetClass) {
|
|
||||||
if (declaration instanceof JetEnumEntry && !enumEntryNeedSubclass(
|
|
||||||
state.getBindingContext(), (JetEnumEntry) declaration)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
generate(contextForInners, (JetClass) declaration);
|
|
||||||
}
|
|
||||||
else if (declaration instanceof JetClassObject) {
|
|
||||||
generate(contextForInners, ((JetClassObject) declaration).getObjectDeclaration());
|
|
||||||
}
|
|
||||||
else if (declaration instanceof JetObjectDeclaration) {
|
|
||||||
generate(contextForInners, (JetObjectDeclaration) declaration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES) {
|
|
||||||
generateImplementation(context, aClass, OwnerKind.IMPLEMENTATION, contextForInners.getAccessors(), classBuilder);
|
|
||||||
}
|
|
||||||
|
|
||||||
classBuilder.done();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void generateImplementation(
|
|
||||||
CodegenContext context,
|
|
||||||
JetClassOrObject aClass,
|
|
||||||
OwnerKind kind,
|
|
||||||
Map<DeclarationDescriptor, DeclarationDescriptor> accessors,
|
|
||||||
ClassBuilder classBuilder
|
|
||||||
) {
|
|
||||||
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
|
||||||
CodegenContext classContext = context.intoClass(descriptor, kind, state);
|
|
||||||
classContext.copyAccessors(accessors);
|
|
||||||
|
|
||||||
new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate();
|
|
||||||
|
|
||||||
if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) {
|
|
||||||
ClassBuilder traitBuilder = state.getFactory().forTraitImplementation(descriptor, state);
|
|
||||||
new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state), traitBuilder, state)
|
|
||||||
.generate();
|
|
||||||
traitBuilder.done();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -29,18 +29,20 @@ import org.jetbrains.asm4.MethodVisitor;
|
|||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
import org.jetbrains.jet.codegen.binding.CalculatedClosure;
|
||||||
|
import org.jetbrains.jet.codegen.context.CodegenContext;
|
||||||
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
|
import org.jetbrains.jet.codegen.signature.BothSignatureWriter;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
|
import org.jetbrains.jet.codegen.signature.JvmMethodParameterKind;
|
||||||
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
import org.jetbrains.jet.codegen.signature.JvmMethodSignature;
|
||||||
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||||
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.psi.JetClassObject;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.java.*;
|
import org.jetbrains.jet.lang.resolve.java.*;
|
||||||
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.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||||
@@ -49,6 +51,7 @@ import org.jetbrains.jet.lexer.JetTokens;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.jetbrains.asm4.Opcodes.*;
|
import static org.jetbrains.asm4.Opcodes.*;
|
||||||
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.enumEntryNeedSubclass;
|
||||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
|
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||||
@@ -566,4 +569,109 @@ public class CodegenUtil {
|
|||||||
v.neg(expectedType);
|
v.neg(expectedType);
|
||||||
return expectedType;
|
return expectedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void generate(GenerationState state, CodegenContext context, JetClassOrObject aClass) {
|
||||||
|
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
||||||
|
|
||||||
|
if (descriptor == null || ErrorUtils.isError(descriptor) || descriptor.getName().equals(JetPsiUtil.NO_NAME_PROVIDED)) {
|
||||||
|
if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"Generating bad descriptor in ClassBuilderMode = " + state.getClassBuilderMode() + ": " + descriptor);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassBuilder classBuilder = state.getFactory().forClassImplementation(descriptor);
|
||||||
|
|
||||||
|
final CodegenContext contextForInners = context.intoClass(descriptor, OwnerKind.IMPLEMENTATION, state);
|
||||||
|
|
||||||
|
if (state.getClassBuilderMode() == ClassBuilderMode.SIGNATURES) {
|
||||||
|
// Outer class implementation must happen prior inner classes so we get proper scoping tree in JetLightClass's delegate
|
||||||
|
// The same code is present below for the case when we generate real bytecode. This is because the order should be
|
||||||
|
// different for the case when we compute closures
|
||||||
|
generateImplementation(state, context, aClass, OwnerKind.IMPLEMENTATION, contextForInners.getAccessors(), classBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
genInners(state, aClass, contextForInners);
|
||||||
|
|
||||||
|
if (state.getClassBuilderMode() != ClassBuilderMode.SIGNATURES) {
|
||||||
|
generateImplementation(state, context, aClass, OwnerKind.IMPLEMENTATION, contextForInners.getAccessors(), classBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
classBuilder.done();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void genInners(GenerationState state, JetClassOrObject aClass, CodegenContext contextForInners) {
|
||||||
|
for (JetDeclaration declaration : aClass.getDeclarations()) {
|
||||||
|
if (declaration instanceof JetClass) {
|
||||||
|
if (declaration instanceof JetEnumEntry && !enumEntryNeedSubclass(
|
||||||
|
state.getBindingContext(), (JetEnumEntry) declaration)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
generate(state, contextForInners, (JetClass) declaration);
|
||||||
|
}
|
||||||
|
else if (declaration instanceof JetClassObject) {
|
||||||
|
generate(state, contextForInners, ((JetClassObject) declaration).getObjectDeclaration());
|
||||||
|
}
|
||||||
|
else if (declaration instanceof JetObjectDeclaration) {
|
||||||
|
generate(state, contextForInners, (JetObjectDeclaration) declaration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void generateImplementation(
|
||||||
|
GenerationState state,
|
||||||
|
CodegenContext context,
|
||||||
|
JetClassOrObject aClass,
|
||||||
|
OwnerKind kind,
|
||||||
|
Map<DeclarationDescriptor, DeclarationDescriptor> accessors,
|
||||||
|
ClassBuilder classBuilder
|
||||||
|
) {
|
||||||
|
ClassDescriptor descriptor = state.getBindingContext().get(BindingContext.CLASS, aClass);
|
||||||
|
CodegenContext classContext = context.intoClass(descriptor, kind, state);
|
||||||
|
classContext.copyAccessors(accessors);
|
||||||
|
|
||||||
|
new ImplementationBodyCodegen(aClass, classContext, classBuilder, state).generate();
|
||||||
|
|
||||||
|
if (aClass instanceof JetClass && ((JetClass) aClass).isTrait()) {
|
||||||
|
ClassBuilder traitBuilder = state.getFactory().forTraitImplementation(descriptor, state);
|
||||||
|
new TraitImplBodyCodegen(aClass, context.intoClass(descriptor, OwnerKind.TRAIT_IMPL, state), traitBuilder, state)
|
||||||
|
.generate();
|
||||||
|
traitBuilder.done();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void generateFunctionOrProperty(
|
||||||
|
GenerationState state,
|
||||||
|
@NotNull JetTypeParameterListOwner functionOrProperty,
|
||||||
|
@NotNull CodegenContext context, @NotNull ClassBuilder classBuilder
|
||||||
|
) {
|
||||||
|
FunctionCodegen functionCodegen = new FunctionCodegen(context, classBuilder, state);
|
||||||
|
if (functionOrProperty instanceof JetNamedFunction) {
|
||||||
|
try {
|
||||||
|
functionCodegen.gen((JetNamedFunction) functionOrProperty);
|
||||||
|
}
|
||||||
|
catch (CompilationException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new CompilationException("Failed to generate function " + functionOrProperty.getName(), e, functionOrProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (functionOrProperty instanceof JetProperty) {
|
||||||
|
try {
|
||||||
|
new PropertyCodegen(context, classBuilder, functionCodegen).gen((JetProperty) functionOrProperty);
|
||||||
|
}
|
||||||
|
catch (CompilationException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new CompilationException("Failed to generate property " + functionOrProperty.getName(), e, functionOrProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new IllegalArgumentException("Unknown parameter: " + functionOrProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,8 +116,11 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
//noinspection SuspiciousMethodCalls
|
//noinspection SuspiciousMethodCalls
|
||||||
final CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor);
|
final CalculatedClosure closure = bindingContext.get(CLOSURE, classDescriptor);
|
||||||
|
|
||||||
final CodegenContext objectContext = context.intoAnonymousClass(classDescriptor, this);
|
final CodegenContext contextForInners = context.intoClass(classDescriptor, OwnerKind.IMPLEMENTATION, state);
|
||||||
|
genInners(state, objectDeclaration, contextForInners);
|
||||||
|
|
||||||
|
final CodegenContext objectContext = context.intoAnonymousClass(classDescriptor, this);
|
||||||
|
objectContext.copyAccessors(contextForInners.getAccessors());
|
||||||
new ImplementationBodyCodegen(objectDeclaration, objectContext, classBuilder, state).generate();
|
new ImplementationBodyCodegen(objectDeclaration, objectContext, classBuilder, state).generate();
|
||||||
|
|
||||||
return closure;
|
return closure;
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.jet.codegen;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.codegen.context.CodegenContext;
|
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.codegen.state.GenerationStateAware;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetTypeParameterListOwner;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Stepan Koltsov
|
|
||||||
*/
|
|
||||||
public class MemberCodegen extends GenerationStateAware {
|
|
||||||
|
|
||||||
public MemberCodegen(@NotNull GenerationState state) {
|
|
||||||
super(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generateFunctionOrProperty(
|
|
||||||
@NotNull JetTypeParameterListOwner functionOrProperty,
|
|
||||||
@NotNull CodegenContext context, @NotNull ClassBuilder classBuilder
|
|
||||||
) {
|
|
||||||
FunctionCodegen functionCodegen = new FunctionCodegen(context, classBuilder, state);
|
|
||||||
if (functionOrProperty instanceof JetNamedFunction) {
|
|
||||||
try {
|
|
||||||
functionCodegen.gen((JetNamedFunction) functionOrProperty);
|
|
||||||
}
|
|
||||||
catch (CompilationException e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new CompilationException("Failed to generate function " + functionOrProperty.getName(), e, functionOrProperty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (functionOrProperty instanceof JetProperty) {
|
|
||||||
try {
|
|
||||||
new PropertyCodegen(context, classBuilder, functionCodegen).gen((JetProperty) functionOrProperty);
|
|
||||||
}
|
|
||||||
catch (CompilationException e) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
throw new CompilationException("Failed to generate property " + functionOrProperty.getName(), e, functionOrProperty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalArgumentException("Unknown parameter: " + functionOrProperty);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -128,19 +128,19 @@ public class NamespaceCodegen extends GenerationStateAware {
|
|||||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||||
if (declaration instanceof JetProperty) {
|
if (declaration instanceof JetProperty) {
|
||||||
final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor);
|
final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor);
|
||||||
state.getMemberCodegen().generateFunctionOrProperty(
|
CodegenUtil.generateFunctionOrProperty(
|
||||||
(JetTypeParameterListOwner) declaration, context, v.getClassBuilder());
|
state, (JetTypeParameterListOwner) declaration, context, v.getClassBuilder());
|
||||||
}
|
}
|
||||||
else if (declaration instanceof JetNamedFunction) {
|
else if (declaration instanceof JetNamedFunction) {
|
||||||
if (!multiFile) {
|
if (!multiFile) {
|
||||||
final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor);
|
final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor);
|
||||||
state.getMemberCodegen().generateFunctionOrProperty(
|
CodegenUtil.generateFunctionOrProperty(
|
||||||
(JetTypeParameterListOwner) declaration, context, v.getClassBuilder());
|
state, (JetTypeParameterListOwner) declaration, context, v.getClassBuilder());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (declaration instanceof JetClassOrObject) {
|
else if (declaration instanceof JetClassOrObject) {
|
||||||
final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor);
|
final CodegenContext context = CodegenContext.STATIC.intoNamespace(descriptor);
|
||||||
state.getClassCodegen().generate(context, (JetClassOrObject) declaration);
|
CodegenUtil.generate(state, context, (JetClassOrObject) declaration);
|
||||||
}
|
}
|
||||||
else if (declaration instanceof JetScript) {
|
else if (declaration instanceof JetScript) {
|
||||||
state.getScriptCodegen().generate((JetScript) declaration);
|
state.getScriptCodegen().generate((JetScript) declaration);
|
||||||
@@ -176,14 +176,16 @@ public class NamespaceCodegen extends GenerationStateAware {
|
|||||||
{
|
{
|
||||||
final CodegenContext context =
|
final CodegenContext context =
|
||||||
CodegenContext.STATIC.intoNamespace(descriptor);
|
CodegenContext.STATIC.intoNamespace(descriptor);
|
||||||
state.getMemberCodegen()
|
CodegenUtil
|
||||||
.generateFunctionOrProperty((JetTypeParameterListOwner) declaration, context, builder);
|
.generateFunctionOrProperty(state, (JetTypeParameterListOwner) declaration,
|
||||||
|
context, builder);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final CodegenContext context =
|
final CodegenContext context =
|
||||||
CodegenContext.STATIC.intoNamespacePart(className, descriptor);
|
CodegenContext.STATIC.intoNamespacePart(className, descriptor);
|
||||||
state.getMemberCodegen()
|
CodegenUtil
|
||||||
.generateFunctionOrProperty((JetTypeParameterListOwner) declaration, context, v.getClassBuilder());
|
.generateFunctionOrProperty(state, (JetTypeParameterListOwner) declaration,
|
||||||
|
context, v.getClassBuilder());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.asm4.Opcodes.*;
|
import static org.jetbrains.asm4.Opcodes.*;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
|
||||||
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
import static org.jetbrains.jet.codegen.binding.CodegenBinding.*;
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Stepan Koltsov
|
* @author Stepan Koltsov
|
||||||
@@ -52,8 +52,6 @@ public class ScriptCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ClassFileFactory classFileFactory;
|
private ClassFileFactory classFileFactory;
|
||||||
@NotNull
|
|
||||||
private MemberCodegen memberCodegen;
|
|
||||||
|
|
||||||
private List<ScriptDescriptor> earlierScripts;
|
private List<ScriptDescriptor> earlierScripts;
|
||||||
private Method scriptConstructorMethod;
|
private Method scriptConstructorMethod;
|
||||||
@@ -67,11 +65,6 @@ public class ScriptCodegen extends GenerationStateAware {
|
|||||||
this.classFileFactory = classFileFactory;
|
this.classFileFactory = classFileFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject
|
|
||||||
public void setMemberCodegen(@NotNull MemberCodegen memberCodegen) {
|
|
||||||
this.memberCodegen = memberCodegen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void generate(JetScript scriptDeclaration) {
|
public void generate(JetScript scriptDeclaration) {
|
||||||
|
|
||||||
ScriptDescriptor scriptDescriptor = state.getBindingContext().get(BindingContext.SCRIPT, scriptDeclaration);
|
ScriptDescriptor scriptDescriptor = state.getBindingContext().get(BindingContext.SCRIPT, scriptDeclaration);
|
||||||
@@ -209,7 +202,7 @@ public class ScriptCodegen extends GenerationStateAware {
|
|||||||
|
|
||||||
private void genMembers(@NotNull JetScript scriptDeclaration, @NotNull CodegenContext context, @NotNull ClassBuilder classBuilder) {
|
private void genMembers(@NotNull JetScript scriptDeclaration, @NotNull CodegenContext context, @NotNull ClassBuilder classBuilder) {
|
||||||
for (JetDeclaration decl : scriptDeclaration.getDeclarations()) {
|
for (JetDeclaration decl : scriptDeclaration.getDeclarations()) {
|
||||||
memberCodegen.generateFunctionOrProperty((JetTypeParameterListOwner) decl, context, classBuilder);
|
CodegenUtil.generateFunctionOrProperty(state, (JetTypeParameterListOwner) decl, context, classBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,12 +68,6 @@ public class GenerationState {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final JetTypeMapper typeMapper;
|
private final JetTypeMapper typeMapper;
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final MemberCodegen memberCodegen;
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final ClassCodegen classCodegen;
|
|
||||||
|
|
||||||
public GenerationState(Project project, ClassBuilderFactory builderFactory, AnalyzeExhaust analyzeExhaust, List<JetFile> files) {
|
public GenerationState(Project project, ClassBuilderFactory builderFactory, AnalyzeExhaust analyzeExhaust, List<JetFile> files) {
|
||||||
this(project, builderFactory, Progress.DEAF, analyzeExhaust, files, BuiltinToJavaTypesMapping.ENABLED);
|
this(project, builderFactory, Progress.DEAF, analyzeExhaust, files, BuiltinToJavaTypesMapping.ENABLED);
|
||||||
}
|
}
|
||||||
@@ -98,8 +92,6 @@ public class GenerationState {
|
|||||||
builtinToJavaTypesMapping, this, builderFactory, project);
|
builtinToJavaTypesMapping, this, builderFactory, project);
|
||||||
|
|
||||||
this.scriptCodegen = injector.getScriptCodegen();
|
this.scriptCodegen = injector.getScriptCodegen();
|
||||||
this.memberCodegen = injector.getMemberCodegen();
|
|
||||||
this.classCodegen = injector.getClassCodegen();
|
|
||||||
this.intrinsics = injector.getIntrinsics();
|
this.intrinsics = injector.getIntrinsics();
|
||||||
this.classFileFactory = injector.getClassFileFactory();
|
this.classFileFactory = injector.getClassFileFactory();
|
||||||
}
|
}
|
||||||
@@ -154,16 +146,6 @@ public class GenerationState {
|
|||||||
return intrinsics;
|
return intrinsics;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public MemberCodegen getMemberCodegen() {
|
|
||||||
return memberCodegen;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public ClassCodegen getClassCodegen() {
|
|
||||||
return classCodegen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeCompile() {
|
public void beforeCompile() {
|
||||||
markUsed();
|
markUsed();
|
||||||
|
|
||||||
|
|||||||
@@ -17,23 +17,18 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.di;
|
package org.jetbrains.jet.di;
|
||||||
|
|
||||||
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
|
||||||
import java.util.List;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
|
||||||
import org.jetbrains.jet.codegen.BuiltinToJavaTypesMapping;
|
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
|
||||||
import org.jetbrains.jet.codegen.ClassBuilderMode;
|
|
||||||
import org.jetbrains.jet.codegen.ClassCodegen;
|
|
||||||
import org.jetbrains.jet.codegen.ScriptCodegen;
|
|
||||||
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
|
|
||||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
|
||||||
import org.jetbrains.jet.codegen.MemberCodegen;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.codegen.*;
|
||||||
|
import org.jetbrains.jet.codegen.intrinsics.IntrinsicMethods;
|
||||||
|
import org.jetbrains.jet.codegen.state.GenerationState;
|
||||||
|
import org.jetbrains.jet.codegen.state.JetTypeMapper;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||||
|
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
/* This file is generated by org.jetbrains.jet.di.AllInjectorsGenerator. DO NOT EDIT! */
|
||||||
public class InjectorForJvmCodegen {
|
public class InjectorForJvmCodegen {
|
||||||
@@ -47,11 +42,9 @@ public class InjectorForJvmCodegen {
|
|||||||
private BindingTrace bindingTrace;
|
private BindingTrace bindingTrace;
|
||||||
private BindingContext bindingContext;
|
private BindingContext bindingContext;
|
||||||
private ClassBuilderMode classBuilderMode;
|
private ClassBuilderMode classBuilderMode;
|
||||||
private ClassCodegen classCodegen;
|
|
||||||
private ScriptCodegen scriptCodegen;
|
private ScriptCodegen scriptCodegen;
|
||||||
private IntrinsicMethods intrinsics;
|
private IntrinsicMethods intrinsics;
|
||||||
private ClassFileFactory classFileFactory;
|
private ClassFileFactory classFileFactory;
|
||||||
private MemberCodegen memberCodegen;
|
|
||||||
|
|
||||||
public InjectorForJvmCodegen(
|
public InjectorForJvmCodegen(
|
||||||
@NotNull JetTypeMapper jetTypeMapper,
|
@NotNull JetTypeMapper jetTypeMapper,
|
||||||
@@ -70,14 +63,11 @@ public class InjectorForJvmCodegen {
|
|||||||
this.bindingTrace = jetTypeMapper.getBindingTrace();
|
this.bindingTrace = jetTypeMapper.getBindingTrace();
|
||||||
this.bindingContext = bindingTrace.getBindingContext();
|
this.bindingContext = bindingTrace.getBindingContext();
|
||||||
this.classBuilderMode = classBuilderFactory.getClassBuilderMode();
|
this.classBuilderMode = classBuilderFactory.getClassBuilderMode();
|
||||||
this.classCodegen = new ClassCodegen(getGenerationState());
|
|
||||||
this.scriptCodegen = new ScriptCodegen(getGenerationState());
|
this.scriptCodegen = new ScriptCodegen(getGenerationState());
|
||||||
this.intrinsics = new IntrinsicMethods();
|
this.intrinsics = new IntrinsicMethods();
|
||||||
this.classFileFactory = new ClassFileFactory(getGenerationState());
|
this.classFileFactory = new ClassFileFactory(getGenerationState());
|
||||||
this.memberCodegen = new MemberCodegen(getGenerationState());
|
|
||||||
|
|
||||||
this.scriptCodegen.setClassFileFactory(classFileFactory);
|
this.scriptCodegen.setClassFileFactory(classFileFactory);
|
||||||
this.scriptCodegen.setMemberCodegen(memberCodegen);
|
|
||||||
|
|
||||||
this.classFileFactory.setBuilderFactory(classBuilderFactory);
|
this.classFileFactory.setBuilderFactory(classBuilderFactory);
|
||||||
|
|
||||||
@@ -105,10 +95,6 @@ public class InjectorForJvmCodegen {
|
|||||||
return this.project;
|
return this.project;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClassCodegen getClassCodegen() {
|
|
||||||
return this.classCodegen;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ScriptCodegen getScriptCodegen() {
|
public ScriptCodegen getScriptCodegen() {
|
||||||
return this.scriptCodegen;
|
return this.scriptCodegen;
|
||||||
}
|
}
|
||||||
@@ -121,8 +107,4 @@ public class InjectorForJvmCodegen {
|
|||||||
return this.classFileFactory;
|
return this.classFileFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemberCodegen getMemberCodegen() {
|
|
||||||
return this.memberCodegen;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
fun box() : String {
|
||||||
|
val o = object {
|
||||||
|
|
||||||
|
class C {
|
||||||
|
fun foo() = "OK"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return o.C().foo()
|
||||||
|
}
|
||||||
@@ -606,4 +606,9 @@ public class ClassGenTest extends CodegenTestCase {
|
|||||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
blackBoxFileWithJava("regressions/kt2781.kt", true);
|
blackBoxFileWithJava("regressions/kt2781.kt", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt2607() throws Exception {
|
||||||
|
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||||
|
blackBoxFile("regressions/kt2607.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,11 +210,9 @@ public class AllInjectorsGenerator {
|
|||||||
new GivenExpression("bindingTrace.getBindingContext()"));
|
new GivenExpression("bindingTrace.getBindingContext()"));
|
||||||
generator.addField(false, ClassBuilderMode.class, "classBuilderMode",
|
generator.addField(false, ClassBuilderMode.class, "classBuilderMode",
|
||||||
new GivenExpression("classBuilderFactory.getClassBuilderMode()"));
|
new GivenExpression("classBuilderFactory.getClassBuilderMode()"));
|
||||||
generator.addPublicField(ClassCodegen.class);
|
|
||||||
generator.addPublicField(ScriptCodegen.class);
|
generator.addPublicField(ScriptCodegen.class);
|
||||||
generator.addField(true, IntrinsicMethods.class, "intrinsics", null);
|
generator.addField(true, IntrinsicMethods.class, "intrinsics", null);
|
||||||
generator.addPublicField(ClassFileFactory.class);
|
generator.addPublicField(ClassFileFactory.class);
|
||||||
generator.addPublicField(MemberCodegen.class);
|
|
||||||
|
|
||||||
generator.generate("compiler/backend/src", "org.jetbrains.jet.di", "InjectorForJvmCodegen");
|
generator.generate("compiler/backend/src", "org.jetbrains.jet.di", "InjectorForJvmCodegen");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user