forked from JavaTX/JavaCompilerCore
== Operator anfügen
This commit is contained in:
parent
1e037a0019
commit
c72204428f
@ -583,7 +583,10 @@ public class StatementGenerator {
|
|||||||
if(expression.equalityExpression() == null){
|
if(expression.equalityExpression() == null){
|
||||||
return convert(expression.relationalExpression());
|
return convert(expression.relationalExpression());
|
||||||
}else{
|
}else{
|
||||||
throw new NotImplementedException();
|
String operator = expression.getChild(1).getText();
|
||||||
|
Expression leftSide = convert(expression.equalityExpression());
|
||||||
|
Expression rightSide = convert(expression.relationalExpression());
|
||||||
|
return new BinaryExpr(convertBinaryOperator(operator), TypePlaceholder.fresh(expression.getStart()), leftSide, rightSide, expression.getStart());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -619,8 +622,12 @@ public class StatementGenerator {
|
|||||||
return BinaryExpr.Operator.BIGGERTHAN;
|
return BinaryExpr.Operator.BIGGERTHAN;
|
||||||
}else if(operator.equals(">=")) {
|
}else if(operator.equals(">=")) {
|
||||||
return BinaryExpr.Operator.BIGGEREQUAL;
|
return BinaryExpr.Operator.BIGGEREQUAL;
|
||||||
} else if(operator.equals("<=")) {
|
} else if(operator.equals("<=")) {
|
||||||
return BinaryExpr.Operator.LESSEQUAL;
|
return BinaryExpr.Operator.LESSEQUAL;
|
||||||
|
} else if(operator.equals("==")) {
|
||||||
|
return BinaryExpr.Operator.EQUAL;
|
||||||
|
} else if(operator.equals("!=")) {
|
||||||
|
return BinaryExpr.Operator.NOTEQUAL;
|
||||||
} else {
|
} else {
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@ public class BinaryExpr extends Expression
|
|||||||
LESSTHAN, // <
|
LESSTHAN, // <
|
||||||
BIGGERTHAN, // >
|
BIGGERTHAN, // >
|
||||||
LESSEQUAL, // <=
|
LESSEQUAL, // <=
|
||||||
BIGGEREQUAL // >=
|
BIGGEREQUAL, // >=
|
||||||
|
EQUAL, // ==
|
||||||
|
NOTEQUAL // !=
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Operator operation;
|
public final Operator operation;
|
||||||
|
@ -223,7 +223,8 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
if(binary.operation.equals(BinaryExpr.Operator.DIV) ||
|
if(binary.operation.equals(BinaryExpr.Operator.DIV) ||
|
||||||
binary.operation.equals(BinaryExpr.Operator.MUL)||
|
binary.operation.equals(BinaryExpr.Operator.MUL)||
|
||||||
binary.operation.equals(BinaryExpr.Operator.MOD)||
|
binary.operation.equals(BinaryExpr.Operator.MOD)||
|
||||||
binary.operation.equals(BinaryExpr.Operator.ADD)){
|
binary.operation.equals(BinaryExpr.Operator.ADD)||
|
||||||
|
binary.operation.equals(BinaryExpr.Operator.SUB)){
|
||||||
Set<Constraint<Pair>> numericAdditionOrStringConcatenation = new HashSet<>();
|
Set<Constraint<Pair>> numericAdditionOrStringConcatenation = new HashSet<>();
|
||||||
|
|
||||||
//Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer:
|
//Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer:
|
||||||
@ -303,7 +304,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
}else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) ||
|
}else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) ||
|
||||||
binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) ||
|
binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) ||
|
||||||
binary.operation.equals(BinaryExpr.Operator.BIGGERTHAN) ||
|
binary.operation.equals(BinaryExpr.Operator.BIGGERTHAN) ||
|
||||||
binary.operation.equals(BinaryExpr.Operator.LESSTHAN)){
|
binary.operation.equals(BinaryExpr.Operator.LESSTHAN)) {
|
||||||
/* //eingefuegt PL 2018-05-24
|
/* //eingefuegt PL 2018-05-24
|
||||||
Set<Constraint<Pair>> numericRelationConcatenation = new HashSet<>();
|
Set<Constraint<Pair>> numericRelationConcatenation = new HashSet<>();
|
||||||
Constraint<Pair> numeric = new Constraint<>();
|
Constraint<Pair> numeric = new Constraint<>();
|
||||||
@ -340,18 +341,24 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
//***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
//***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
||||||
constraintsSet.addOderConstraint(numericRelationConcatenation);
|
constraintsSet.addOderConstraint(numericRelationConcatenation);
|
||||||
//***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
//***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
||||||
*/
|
*/
|
||||||
//Testeise eingefuegt PL 2018-05-24
|
//Testeise eingefuegt PL 2018-05-24
|
||||||
constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
//Rückgabetyp ist Boolean
|
//Rückgabetyp ist Boolean
|
||||||
constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.SMALLERDOT));
|
constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.SMALLERDOT));
|
||||||
|
|
||||||
//auskommentiert PL 2018-05-24
|
//auskommentiert PL 2018-05-24
|
||||||
//constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT));
|
//constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT));
|
||||||
//constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT));
|
//constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT));
|
||||||
//Rückgabetyp ist Boolean
|
//Rückgabetyp ist Boolean
|
||||||
//constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT));
|
//constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.EQUALSDOT));
|
||||||
|
}else if(binary.operation.equals(BinaryExpr.Operator.EQUAL) || binary.operation.equals(BinaryExpr.Operator.NOTEQUAL)){
|
||||||
|
/*Auszug aus https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-15.21
|
||||||
|
The equality operators may be used to compare two operands that are convertible (§5.1.8) to numeric type, or two operands of type boolean or Boolean, or two operands that are each of either reference type or the null type. All other cases result in a compile-time error.
|
||||||
|
*/
|
||||||
|
//Der Equals Operator geht mit fast allen Typen, daher werden hier keine Constraints gesetzt
|
||||||
|
constraintsSet.addUndConstraint(new Pair(bool, binary.getType(), PairOperator.SMALLERDOT));
|
||||||
}else{
|
}else{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user