예제 #1
0
  private Expression operationWithConstantValue(
      BinaryExpression binExp,
      java.lang.Class expectedClass,
      Expression constantExp,
      boolean constantOnLeft,
      boolean operationWithSideEffect) {
    Expression exp;
    if (operationWithSideEffect) {
      MethodAccess call = new MethodAccess();
      call.expression = new This();
      exp = call;
    } else {
      exp = new IdExpression();
    }
    exp.type = constantExp.type;
    if (constantOnLeft) {
      binExp.right = exp;
      binExp.left = constantExp;
    } else {
      binExp.left = exp;
      binExp.right = constantExp;
    }
    if (null == expectedClass) expectedClass = MethodAccess.class;

    return expressionSimplificationTester(binExp, expectedClass, constantExp.type, 0, false);
  }
예제 #2
0
 public void testDowncast() {
   SymbolTableForTests table = new SymbolTableForTests();
   table.addClasses("A", "B");
   table.getClass("B").superName = "A";
   Expression expression = new IdExpression("a");
   expression.type = new IdType("A");
   ExpressionVisitor visitor = new ExpressionVisitor(table);
   Cast cast = new Cast(expression);
   cast.type = new IdType("B");
   assertEquals(visitor.visit(cast), cast);
 }