forked from JavaTX/JavaCompilerCore
TypeStmt für +,-,/,*,% einführen
This commit is contained in:
parent
77aaa0ecb6
commit
f023754328
@ -13,16 +13,17 @@ public class BinaryExpr extends Expression
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Operator{
|
public enum Operator{
|
||||||
ADD,
|
ADD, // +
|
||||||
SUB,
|
SUB, // -
|
||||||
MUL,
|
MUL, // *
|
||||||
AND,
|
MOD, // Modulo Operator %
|
||||||
OR,
|
AND, // &&
|
||||||
DIV,
|
OR, // ||
|
||||||
LESSTHAN,
|
DIV, // /
|
||||||
BIGGERTHAN,
|
LESSTHAN, // <
|
||||||
LESSEQUAL,
|
BIGGERTHAN, // >
|
||||||
BIGGEREQUAL
|
LESSEQUAL, // <=
|
||||||
|
BIGGEREQUAL // >=
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Operator operation;
|
public final Operator operation;
|
||||||
|
@ -81,11 +81,6 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT));
|
assign.rightSide.getType(), assign.lefSide.getType(), PairOperator.SMALLERDOT));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(BinaryExpr binary) {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Block block) {
|
public void visit(Block block) {
|
||||||
for(Statement stmt : block.getStatements()){
|
for(Statement stmt : block.getStatements()){
|
||||||
@ -190,6 +185,8 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
receiver.expr.accept(this);
|
receiver.expr.accept(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), new NullToken());
|
||||||
|
private final RefType string = new RefType(ASTFactory.createClass(String.class).getClassName(), new NullToken());
|
||||||
@Override
|
@Override
|
||||||
public void visit(UnaryExpr unaryExpr) {
|
public void visit(UnaryExpr unaryExpr) {
|
||||||
if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT ||
|
if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT ||
|
||||||
@ -198,7 +195,6 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
|
unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
|
||||||
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
|
//@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2
|
||||||
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
||||||
RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), unaryExpr.getOffset());
|
|
||||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERDOT));
|
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERDOT));
|
||||||
//The type of the postfix increment expression is the type of the variable
|
//The type of the postfix increment expression is the type of the variable
|
||||||
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
|
constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT));
|
||||||
@ -207,9 +203,40 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(BinaryExpr binary) {
|
||||||
|
if(binary.operation.equals(BinaryExpr.Operator.DIV) ||
|
||||||
|
binary.operation.equals(BinaryExpr.Operator.MUL)||
|
||||||
|
binary.operation.equals(BinaryExpr.Operator.MOD)||
|
||||||
|
binary.operation.equals(BinaryExpr.Operator.ADD)){
|
||||||
|
Set<Constraint> numericAdditionOrStringConcatenation = new HashSet<>();
|
||||||
|
Constraint<Pair> numeric = new Constraint<>();
|
||||||
|
//Zuerst der Fall für Numerische AusdrücPairOpnumericeratorke, das sind Mul, Mod und Div immer:
|
||||||
|
//see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.17
|
||||||
|
//Expression muss zu Numeric Convertierbar sein. also von Numeric erben
|
||||||
|
numeric.add(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERDOT));
|
||||||
|
numeric.add(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERDOT));
|
||||||
|
//The type of a multiplicative expression is the promoted type of its operands.
|
||||||
|
numeric.add(new Pair(binary.rexpr.getType(), binary.getType(), PairOperator.SMALLERDOT));
|
||||||
|
numeric.add(new Pair(binary.lexpr.getType(), binary.getType(), PairOperator.SMALLERDOT));
|
||||||
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
|
if(binary.operation.equals(BinaryExpr.Operator.ADD)) {
|
||||||
|
//Dann kann der Ausdruck auch das aneinanderfügen zweier Strings sein: ("a" + "b") oder (1 + 2)
|
||||||
|
Constraint<Pair> stringConcat = new Constraint<>();
|
||||||
|
stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT));
|
||||||
|
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT));
|
||||||
|
stringConcat.add(new Pair(binary.getType(), string, PairOperator.EQUALSDOT));
|
||||||
|
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||||
|
}
|
||||||
|
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
|
||||||
|
}else {
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Literal literal) {
|
public void visit(Literal literal) {
|
||||||
//Nothing to do here. Literale kriegen beim parsen den korrekten Typ.
|
//Nothing to do here. Literale erzeugen keine Constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user