KT-2363 Drop secondary constructors

#KT-2363 Fixed
This commit is contained in:
Andrey Breslav
2012-07-19 19:52:56 +04:00
parent fd96e9b9c0
commit bf503e9a4b
64 changed files with 240 additions and 1695 deletions
@@ -884,10 +884,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
@Override
protected void generateDeclaration(PropertyCodegen propertyCodegen, JetDeclaration declaration, FunctionCodegen functionCodegen) {
if (declaration instanceof JetSecondaryConstructor) {
generateSecondaryConstructor((JetSecondaryConstructor) declaration);
}
else if (declaration instanceof JetClassObject) {
if (declaration instanceof JetClassObject) {
// done earlier in order to have accessors
}
else if (declaration instanceof JetEnumEntry && !((JetEnumEntry) declaration).hasPrimaryConstructor()) {
@@ -944,57 +941,6 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
}
private void generateSecondaryConstructor(JetSecondaryConstructor constructor) {
ConstructorDescriptor constructorDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, constructor);
if (constructorDescriptor == null) {
throw new UnsupportedOperationException("failed to get descriptor for secondary constructor");
}
CallableMethod method = typeMapper.mapToCallableMethod(constructorDescriptor, kind, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
int flags = JetTypeMapper.getAccessModifiers(constructorDescriptor, 0);
final MethodVisitor mv = v.newMethod(constructor, flags, "<init>", method.getSignature().getAsmMethod().getDescriptor(), null, null);
AnnotationVisitor jetConstructorVisitor = mv.visitAnnotation(JvmStdlibNames.JET_CONSTRUCTOR.getDescriptor(), true);
int flagsValue = BitSetUtils.toInt(CodegenUtil.getFlagsForVisibility(constructorDescriptor.getVisibility()));
if (JvmStdlibNames.FLAGS_DEFAULT_VALUE != flagsValue) {
jetConstructorVisitor.visit(JvmStdlibNames.JET_CLASS_FLAGS_FIELD, flagsValue);
}
jetConstructorVisitor.visitEnd();
if (state.getClassBuilderMode() == ClassBuilderMode.STUBS) {
StubCodegen.generateStubCode(mv);
}
else if (state.getClassBuilderMode() == ClassBuilderMode.FULL) {
mv.visitCode();
ConstructorFrameMap frameMap = new ConstructorFrameMap(method, constructorDescriptor, typeMapper.hasThis0(constructorDescriptor.getContainingDeclaration()));
final InstructionAdapter iv = new InstructionAdapter(mv);
ExpressionCodegen codegen = new ExpressionCodegen(mv, frameMap, Type.VOID_TYPE, context, state);
for (JetDelegationSpecifier initializer : constructor.getInitializers()) {
if (initializer instanceof JetDelegatorToThisCall) {
JetDelegatorToThisCall thisCall = (JetDelegatorToThisCall) initializer;
DeclarationDescriptor thisDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, thisCall.getThisReference());
if (!(thisDescriptor instanceof ConstructorDescriptor)) {
throw new UnsupportedOperationException("expected 'this' delegator to resolve to constructor");
}
generateDelegatorToConstructorCall(iv, codegen, thisCall, (ConstructorDescriptor) thisDescriptor, frameMap, flags);
}
else {
throw new UnsupportedOperationException("unknown initializer type");
}
}
JetExpression bodyExpression = constructor.getBodyExpression();
if (bodyExpression != null) {
codegen.gen(bodyExpression, Type.VOID_TYPE);
}
mv.visitInsn(RETURN);
FunctionCodegen.endVisit(mv, "constructor", null);
}
}
public static void generateInitializers(@NotNull ExpressionCodegen codegen, @NotNull InstructionAdapter iv, @NotNull List<JetDeclaration> declarations,
@NotNull BindingContext bindingContext, @NotNull JetTypeMapper typeMapper) {
for (JetDeclaration declaration : declarations) {