Minor, fix/suppress warnings in codegen

This commit is contained in:
Alexander Udalov
2013-12-05 17:22:35 +04:00
parent 0215f892a6
commit 523ad697c7
3 changed files with 33 additions and 45 deletions
@@ -151,7 +151,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
static class FinallyBlockStackElement extends BlockStackElement {
List<Label> gaps = new ArrayList();
List<Label> gaps = new ArrayList<Label>();
final JetTryExpression expression;
@@ -178,21 +178,17 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
this.returnType = returnType;
this.state = state;
this.methodVisitor = v;
this.v = createInstructionAdapter(methodVisitor);
this.bindingContext = state.getBindingContext();
this.context = context;
this.statementVisitor = new CodegenStatementVisitor(this);
this.tailRecursionCodegen = new TailRecursionCodegen(context, this, this.v, state);
}
protected InstructionAdapter createInstructionAdapter(MethodVisitor mv) {
return new InstructionAdapter(methodVisitor) {
this.v = new InstructionAdapter(methodVisitor) {
@Override
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
super.visitLocalVariable(name, desc, signature, start, end, index);
localVariableNames.add(name);
}
};
this.bindingContext = state.getBindingContext();
this.context = context;
this.statementVisitor = new CodegenStatementVisitor(this);
this.tailRecursionCodegen = new TailRecursionCodegen(context, this, this.v, state);
}
public GenerationState getState() {
@@ -1150,16 +1146,16 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
@Override
public StackValue visitBreakExpression(@NotNull JetBreakExpression expression, StackValue receiver) {
return visitBreakOrContinueExpression(expression, receiver, true);
return generateBreakOrContinueExpression(expression, true);
}
@Override
public StackValue visitContinueExpression(@NotNull JetContinueExpression expression, StackValue receiver) {
return visitBreakOrContinueExpression(expression, receiver, false);
return generateBreakOrContinueExpression(expression, false);
}
@NotNull
private StackValue visitBreakOrContinueExpression(@NotNull JetLabelQualifiedExpression expression, StackValue receiver, boolean isBreak) {
private StackValue generateBreakOrContinueExpression(@NotNull JetLabelQualifiedExpression expression, boolean isBreak) {
assert expression instanceof JetContinueExpression || expression instanceof JetBreakExpression;
if (!blockStackElements.isEmpty()) {
@@ -1186,11 +1182,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
blockStackElements.pop();
StackValue result = visitBreakOrContinueExpression(expression, receiver, isBreak);
StackValue result = generateBreakOrContinueExpression(expression, isBreak);
blockStackElements.push(stackElement);
return result;
}
throw new UnsupportedOperationException("Target label for break/continue not found");
@@ -1812,6 +1806,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
int flags = AsmUtil.getVisibilityForSpecialPropertyBackingField(propertyDescriptor, isDelegatedProperty);
skipPropertyAccessors = (flags & ACC_PRIVATE) == 0 || methodKind == MethodKind.SYNTHETIC_ACCESSOR || methodKind == MethodKind.INITIALIZER;
if (!skipPropertyAccessors) {
//noinspection ConstantConditions
propertyDescriptor = (PropertyDescriptor) backingFieldContext.getAccessor(propertyDescriptor, true, delegateType);
}
isStatic = true;
@@ -1869,6 +1864,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
String name;
//noinspection ConstantConditions
if (propertyDescriptor.getContainingDeclaration() == backingFieldContext.getContextDescriptor()) {
assert backingFieldContext instanceof FieldOwnerContext : "Actual context is " + backingFieldContext + " but should be instance of FieldOwnerContext" ;
name = ((FieldOwnerContext) backingFieldContext).getFieldName(propertyDescriptor, isDelegatedProperty);
@@ -1947,6 +1943,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
v.anew(asmType);
v.dup();
@SuppressWarnings("ConstantConditions")
Type functionType = typeMapper.mapType(samInterface.getFunctionTypeForSamInterface());
expression.accept(visitor, StackValue.none()).put(functionType, v);
@@ -2097,7 +2094,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
}
private boolean isCallAsFunctionObject(FunctionDescriptor fd) {
private static boolean isCallAsFunctionObject(FunctionDescriptor fd) {
if (fd instanceof ExpressionAsFunctionDescriptor) {
JetExpression deparenthesize = JetPsiUtil.deparenthesize(((ExpressionAsFunctionDescriptor) fd).getExpression());
return !(deparenthesize instanceof JetCallableReferenceExpression || deparenthesize instanceof JetFunctionLiteralExpression);
@@ -2294,7 +2291,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
}
@NotNull
private CodegenContext getNotNullParentContextForMethod(@NotNull CodegenContext cur) {
private static CodegenContext getNotNullParentContextForMethod(CodegenContext cur) {
if (cur instanceof MethodContext) {
cur = cur.getParentContext();
}
@@ -3549,8 +3546,8 @@ The "returned" value of try expression with no finally is either the last expres
}
}
private List<Label> getCurrentCatchIntervals(
@NotNull
private static List<Label> getCurrentCatchIntervals(
@Nullable FinallyBlockStackElement finallyBlockStackElement,
@NotNull Label blockStart,
@NotNull Label blockEnd
@@ -217,6 +217,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ClassData data = new ClassData(createNameResolver(serializer.getNameTable()), classProto);
AnnotationVisitor av = v.getVisitor().visitAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_CLASS), true);
//noinspection ConstantConditions
av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
AnnotationVisitor array = av.visitArray(JvmAnnotationNames.DATA_FIELD_NAME);
for (String string : BitEncoding.encodeBytes(data.toBytes())) {
@@ -1068,7 +1069,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
private void generateClassObjectBackingFieldCopies() {
if (classObjectPropertiesToCopy != null) {
for (PropertyAndDefaultValue propertyInfo : classObjectPropertiesToCopy) {
PropertyDescriptor propertyDescriptor = propertyInfo.propertyDescriptor;
PropertyDescriptor propertyDescriptor = propertyInfo.descriptor;
FieldVisitor fv = v.newField(null, ACC_STATIC | ACC_FINAL | ACC_PUBLIC, context.getFieldName(propertyDescriptor),
typeMapper.mapType(propertyDescriptor).getDescriptor(), null, propertyInfo.defaultValue);
@@ -1224,13 +1225,11 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
ImplementationBodyCodegen parentCodegen = getParentBodyCodegen(this);
//generate object$
parentCodegen.genInitSingleton(descriptor, StackValue.singleton(descriptor, typeMapper));
parentCodegen.generateInitializers(parentCodegen.createOrGetClInitCodegen(),
myClass.getDeclarations(), bindingContext, state);
generateInitializers(parentCodegen.createOrGetClInitCodegen(), myClass.getDeclarations(), bindingContext, state);
} else {
generateInitializers(codegen, myClass.getDeclarations(), bindingContext, state);
}
iv.visitInsn(RETURN);
}
@@ -1435,7 +1434,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
}
private void generateDelegationToTraitImpl(final @NotNull FunctionDescriptor fun, @NotNull FunctionDescriptor inheritedFun) {
private void generateDelegationToTraitImpl(@NotNull FunctionDescriptor fun, @NotNull FunctionDescriptor inheritedFun) {
DeclarationDescriptor containingDeclaration = fun.getContainingDeclaration();
if (!(containingDeclaration instanceof ClassDescriptor)) {
return;
@@ -1873,17 +1872,13 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
classObjectPropertiesToCopy.add(new PropertyAndDefaultValue(descriptor, defaultValue));
}
static class PropertyAndDefaultValue {
private static class PropertyAndDefaultValue {
public final PropertyDescriptor descriptor;
public final Object defaultValue;
PropertyAndDefaultValue(PropertyDescriptor propertyDescriptor, Object defaultValue) {
this.propertyDescriptor = propertyDescriptor;
public PropertyAndDefaultValue(PropertyDescriptor descriptor, Object defaultValue) {
this.descriptor = descriptor;
this.defaultValue = defaultValue;
}
private PropertyDescriptor propertyDescriptor;
private Object defaultValue;
}
}
@@ -853,22 +853,18 @@ public class JetTypeMapper extends BindingTraceAware {
JetDelegatorToSuperCall superCall = closure.getSuperCall();
if (superCall != null) {
DeclarationDescriptor superDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET,
superCall
.getCalleeExpression()
.getConstructorReferenceExpression());
DeclarationDescriptor superDescriptor = bindingContext
.get(BindingContext.REFERENCE_TARGET, superCall.getCalleeExpression().getConstructorReferenceExpression());
if(superDescriptor instanceof ConstructorDescriptor) {
if (superDescriptor instanceof ConstructorDescriptor) {
ConstructorDescriptor superConstructor = (ConstructorDescriptor) superDescriptor;
if (isObjectLiteral(bindingContext, descriptor.getContainingDeclaration())) {
List<JvmMethodParameterSignature> types = mapConstructorSignature(superConstructor).getKotlinParameterTypes();
if (types != null) {
for (JvmMethodParameterSignature type : types) {
signatureWriter.writeParameterType(JvmMethodParameterKind.SUPER_CALL_PARAM);
signatureWriter.writeAsmType(type.getAsmType());
signatureWriter.writeParameterTypeEnd();
}
for (JvmMethodParameterSignature type : types) {
signatureWriter.writeParameterType(JvmMethodParameterKind.SUPER_CALL_PARAM);
signatureWriter.writeAsmType(type.getAsmType());
signatureWriter.writeParameterTypeEnd();
}
}
}