Пример #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);
 }
Пример #3
0
  private Expression expressionSimplificationTester(
      Expression exp,
      java.lang.Class expectedClass,
      Type expectedType,
      int result,
      boolean testNumericValue) {
    ExpressionVisitor cfv = new ExpressionVisitor(new SymbolTable());
    Expression simplifiedExp = exp.accept(cfv);

    assertEquals(expectedType, simplifiedExp.type);
    assertEquals(expectedClass, simplifiedExp.getClass());
    if (testNumericValue) assertEquals(result, ((Number) simplifiedExp).id);
    return simplifiedExp;
  }