package org.yinwang.pysonar.ast;
import org.jetbrains.annotations.NotNull;
import org.yinwang.pysonar.State;
import org.yinwang.pysonar.types.Type;
import org.yinwang.pysonar.types.UnionType;
public class BinOp extends Node {
@NotNull
public Node left;
@NotNull
public Node right;
@NotNull
public Op op;
public BinOp(@NotNull Op op, @NotNull Node left, @NotNull Node right, String file, int start, int end) {
super(file, start, end);
this.left = left;
this.right = right;
this.op = op;
addChildren(left, right);
}
@NotNull
@Override
public Type transform(State s) {
Type ltype = transformExpr(left, s);
Type rtype = transformExpr(right, s);
if (Op.isBoolean(op)) {
return Type.BOOL;
} else {
return UnionType.union(ltype, rtype);
}
}
@NotNull
@Override
public String toString() {
return "(" + left + " " + op + " " + right + ")";
}
}