forked from JavaTX/JavaCompilerCore
- Div und MulOperatoren für alle numerischen Datentypen implementiert (Nur wenn beide Operanten den gleichen Typ haben)
This commit is contained in:
parent
c2d3fce75e
commit
e5fc8c8288
@ -142,7 +142,6 @@ public abstract class AddOp extends Operator
|
||||
}else{
|
||||
return type.get_Name();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract ArithmeticInstruction getOperator(String returnType);
|
||||
|
@ -3,9 +3,17 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
// ino.end
|
||||
// ino.module.DivideOp.8596.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.DADD;
|
||||
import org.apache.commons.bcel6.generic.DDIV;
|
||||
import org.apache.commons.bcel6.generic.FADD;
|
||||
import org.apache.commons.bcel6.generic.FDIV;
|
||||
import org.apache.commons.bcel6.generic.IADD;
|
||||
import org.apache.commons.bcel6.generic.IDIV;
|
||||
import org.apache.commons.bcel6.generic.LADD;
|
||||
import org.apache.commons.bcel6.generic.LDIV;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
|
||||
@ -29,9 +37,18 @@ public class DivideOp extends MulOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
ArithmeticInstruction getOperator(String returnType) {
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
return new IDIV();
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
return new DDIV();
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
return new FDIV();
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
return new LDIV();
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -19,8 +19,11 @@ import de.dhbwstuttgart.bytecode.DHBWInstructionFactory;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Expr;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||
@ -75,7 +78,7 @@ public abstract class MulOp extends Operator
|
||||
*/
|
||||
DHBWInstructionFactory _factory = _cg.getInstructionFactory();
|
||||
|
||||
String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2());
|
||||
String returnType = getReturnType(operator.get_Expr1(), operator.get_Expr2(), rs);
|
||||
|
||||
InstructionList il = getInstructionListForOperand(_cg, rs, operator.get_Expr1(), returnType);
|
||||
|
||||
@ -87,8 +90,20 @@ public abstract class MulOp extends Operator
|
||||
return il;
|
||||
}
|
||||
|
||||
private String getReturnType(Expr expr1, Expr expr2) {
|
||||
return "java.lang.Integer";
|
||||
private String getReturnType(Expr expr1, Expr expr2, TypeinferenceResultSet rs) {
|
||||
Type type = expr1.getType();
|
||||
if(type instanceof TypePlaceholder){
|
||||
Type tphType = rs.getTypeOfPlaceholder((TypePlaceholder) expr1.getType());
|
||||
if(tphType instanceof ExtendsWildcardType){
|
||||
return ((ExtendsWildcardType) tphType).get_ExtendsType().get_Name();
|
||||
}else if(tphType instanceof SuperWildcardType){
|
||||
return ((SuperWildcardType) tphType).get_SuperType().get_Name();
|
||||
}else{
|
||||
return tphType.getName().toString();
|
||||
}
|
||||
}else{
|
||||
return type.get_Name();
|
||||
}
|
||||
}
|
||||
|
||||
abstract ArithmeticInstruction getOperator(String returnType);
|
||||
@ -96,6 +111,12 @@ public abstract class MulOp extends Operator
|
||||
private InvokeInstruction convertValueToObject(DHBWInstructionFactory _factory, String returnType) {
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
return _factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.INT}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
return _factory.createInvoke("java.lang.Double", "valueOf", new ObjectType("java.lang.Double"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.DOUBLE}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
return _factory.createInvoke("java.lang.Float", "valueOf", new ObjectType("java.lang.Float"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.FLOAT}, Constants.INVOKESTATIC);
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
return _factory.createInvoke("java.lang.Long", "valueOf", new ObjectType("java.lang.Long"), new org.apache.commons.bcel6.generic.Type[] {org.apache.commons.bcel6.generic.Type.LONG}, Constants.INVOKESTATIC);
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -57,7 +57,6 @@ public class PlusOp extends AddOp
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -4,9 +4,13 @@ package de.dhbwstuttgart.syntaxtree.operator;
|
||||
|
||||
// ino.module.TimesOp.8611.import
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
|
||||
|
||||
import org.apache.commons.bcel6.generic.ArithmeticInstruction;
|
||||
import org.apache.commons.bcel6.generic.DMUL;
|
||||
import org.apache.commons.bcel6.generic.FMUL;
|
||||
import org.apache.commons.bcel6.generic.IMUL;
|
||||
import org.apache.commons.bcel6.generic.LMUL;
|
||||
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Binary;
|
||||
@ -26,9 +30,18 @@ public class TimesOp extends MulOp
|
||||
}
|
||||
// ino.end
|
||||
|
||||
@Override
|
||||
ArithmeticInstruction getOperator(String returnType) {
|
||||
if(returnType.equals("java.lang.Integer")){
|
||||
return new IMUL();
|
||||
}else if(returnType.equals("java.lang.Double")){
|
||||
return new DMUL();
|
||||
}else if(returnType.equals("java.lang.Float")){
|
||||
return new FMUL();
|
||||
}else if(returnType.equals("java.lang.Long")){
|
||||
return new LMUL();
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
class DivOperator{
|
||||
Integer method(Integer x, Integer y){
|
||||
method(x, y){
|
||||
return x / y;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
class MulOperator{
|
||||
Integer method(Integer x, Integer y){
|
||||
method(x, y){
|
||||
return x * y;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user