Package com.odiago.flumebase.lang

Examples of com.odiago.flumebase.lang.TypeChecker


  }

  @Test
  public void testMinus() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Subtract,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(2), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Subtract,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(-2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(6), value);
  }
View Full Code Here


  }

  @Test
  public void testDiv() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(6)),
        BinOp.Div,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(3), value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.FLOAT), Float.valueOf(7f)),
        BinOp.Div,
        new ConstExpr(Type.getPrimitive(Type.TypeName.FLOAT), Float.valueOf(2f)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Float.valueOf(7f/2f), value);
  }
View Full Code Here

  }

  @Test
  public void testMod() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)),
        BinOp.Mod,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Integer.valueOf(1), value);
  }
View Full Code Here

  }

  @Test
  public void testGreater() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)),
        BinOp.Greater,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)),
        BinOp.Greater,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Greater,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    // Note that booleans are comparable..
    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE),
        BinOp.Greater,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);
  }
View Full Code Here

  }

  @Test
  public void testGreaterEq() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)),
        BinOp.GreaterEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)),
        BinOp.GreaterEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.GreaterEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);
  }
View Full Code Here

  }

  @Test
  public void testLessEq() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)),
        BinOp.LessEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)),
        BinOp.LessEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.LessEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);
  }
View Full Code Here

  }

  @Test
  public void testLess() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)),
        BinOp.Less,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)),
        BinOp.Less,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Less,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);
  }
View Full Code Here

  }

  @Test
  public void testEq() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)),
        BinOp.Eq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Eq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getNullable(Type.TypeName.INT), null),
        BinOp.Eq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertNull(value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")),
        BinOp.Eq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")),
        BinOp.Eq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("ABC")));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    // integer-to-string promotion holds for the '=' operator too.

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("4")),
        BinOp.Eq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.Eq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("4")));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);
  }
View Full Code Here

  }

  @Test
  public void testNotEq() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(7)),
        BinOp.NotEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(2)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)),
        BinOp.NotEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getNullable(Type.TypeName.INT), null),
        BinOp.NotEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertNull(value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")),
        BinOp.NotEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("abc")),
        BinOp.NotEq,
        new ConstExpr(Type.getPrimitive(Type.TypeName.STRING), new Utf8("ABC")));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);
  }
View Full Code Here

  }

  @Test
  public void testAnd() throws Exception {
    Expr binExpr;
    TypeChecker checker;
    Object value;

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE),
        BinOp.And,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.TRUE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE),
        BinOp.And,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.TRUE),
        BinOp.And,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    binExpr = new BinExpr(
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE),
        BinOp.And,
        new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE));
    checker = new TypeChecker(new HashSymbolTable());
    binExpr.accept(checker);
    value = binExpr.eval(getEmptyEventWrapper());
    assertEquals(Boolean.FALSE, value);

    try {
      // This should cause a typechecker exception.
      binExpr = new BinExpr(
          new ConstExpr(Type.getPrimitive(Type.TypeName.BOOLEAN), Boolean.FALSE),
          BinOp.And,
          new ConstExpr(Type.getPrimitive(Type.TypeName.INT), Integer.valueOf(4)));
      checker = new TypeChecker(new HashSymbolTable());
      binExpr.accept(checker);

      fail("Expected typechecker error ; int does not promote to boolean.");
    } catch (VisitException ve) {
      // Expected.
View Full Code Here

TOP

Related Classes of com.odiago.flumebase.lang.TypeChecker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.