JavaPatternMatching/src/de/dhbwstuttgart/syntaxtree/operator/RelOp.java
2016-04-29 14:05:25 +02:00

109 lines
4.2 KiB
Java
Executable File

// ino.module.RelOp.8610.package
package de.dhbwstuttgart.syntaxtree.operator;
// ino.end
// ino.module.RelOp.8610.import
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.generic.BranchInstruction;
import org.apache.commons.bcel6.generic.GOTO;
import org.apache.commons.bcel6.generic.InstructionConstants;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.ObjectType;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.statement.Binary;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.unify.TypeUnify;
// ino.class.RelOp.24299.declaration
public abstract class RelOp extends Operator
// ino.end
// ino.class.RelOp.24299.body
{
// ino.method.RelOp.24303.definition
public RelOp(int offset, int variableLength)
// ino.end
// ino.method.RelOp.24303.body
{
super(offset, variableLength);
}
// ino.end
protected Hashtable<RefType, RefType> getOperatorTypes() {
Hashtable<RefType, RefType> types = new Hashtable<RefType, RefType>();
types.put(new RefType("java.lang.Integer",this,-1), new RefType("java.lang.Boolean",this,-1));
types.put(new RefType("java.lang.Double",this,-1), new RefType("java.lang.Boolean",this,-1));
types.put(new RefType("java.lang.Float",this,-1), new RefType("java.lang.Boolean",this,-1));
types.put(new RefType("java.lang.Long",this,-1), new RefType("java.lang.Boolean",this,-1));
return types;
}
@Override
public HashMap<Type,Type> getReturnTypes(TypeAssumptions ass) {
HashMap<Type,Type> ret = new HashMap<>();
ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Integer",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Double",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Float",this,-1).TYPE(ass, this));
ret.put(new RefType("java.lang.Boolean",this,-1).TYPE(ass, this), new RefType("java.lang.Long",this,-1).TYPE(ass, this));
return ret;
}
@Override
public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs, Binary operator) {
/*
0: aload_1
1: invokevirtual #3 // Method java/lang/Integer.intValue:()I
4: aload_2
5: invokevirtual #3 // Method java/lang/Integer.intValue:()I
8: if_icmplt 15
11: iconst_1
12: goto 16
15: iconst_0
16: invokestatic #2 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
19: areturn
*/
DHBWInstructionFactory _factory = _cg.getInstructionFactory();
InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), "java.lang.Boolean");
il.append(getInstructionListForOperand(_cg, rs, operator.get_Expr2(), "java.lang.Boolean"));
BranchInstruction operatorBranchInstruction = getOperator();
il.append(operatorBranchInstruction);
il.append(InstructionConstants.ICONST_1);
BranchInstruction gotoInstruction = new GOTO(null);
il.append(gotoInstruction);
operatorBranchInstruction.setTarget(il.append(InstructionConstants.ICONST_0));
gotoInstruction.setTarget(il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.BOOLEAN}, Constants.INVOKESTATIC)));
return il;
}
abstract BranchInstruction getOperator();
}
// ino.end