Package org.allspice.structured.statement

Examples of org.allspice.structured.statement.ExprStatement


  }
  public void test1() throws Exception {
    DoWhileTest obj = makeObject(DoWhileTest.class,new DeclareStatement(
        new FIFO<VarDecl>(new VarDecl("int","i"),new VarDecl("int","total")),
        new FIFO<Statement>(
            new ExprStatement(new SetValueExpr(I,new ConstExpr(Integer.valueOf(0),null),null),null),
            new ExprStatement(new SetValueExpr(TOTAL,new ConstExpr(Integer.valueOf(0),null),null),null),
            new DoWhileStatement(
                new LTExpr(I,ARG0,null),
                new FIFO<Statement>(
                  new ExprStatement(new AddInPlaceExpr(I,new ConstExpr(Integer.valueOf(1),null),null),null),
                  new ExprStatement(new AddInPlaceExpr(TOTAL,new ConstExpr(Integer.valueOf(2),null),null),null)
                ),
                null),
            new ReturnStatement(TOTAL,null)
      ),null)) ;
    assertEquals(obj.meth(5),10) ;
View Full Code Here


  }
  public static FIFO<Statement> createForStatement(PositionRange range,ForInitializer init,Expr term,Expr inc,ImmutableCollection<Statement> statement) {
    ImmutableCollection<Statement> whilebody = statement ;
    if (inc != null) {
      whilebody = whilebody.insert(new ExprStatement(inc,inc.getPositionRange())) ;
    }
    Expr test ;
    if (term == null) {
      test = new ConstExpr(Boolean.TRUE,range) ;
    }
    else {
        test = term ;
    }
    Statement whileState = new WhileStatement(test,whilebody,range) ;
    if (init == null) {
      return new FIFO<Statement>(whileState) ;
    }
    if (init instanceof ExprForInit) {
        Expr e = ((ExprForInit)init).e ;
        return new FIFO<Statement>(
          new ExprStatement(e,e.getPositionRange()),
          whileState) ;
    }
    ImmutableCollection<VarDecl> vardecls = ((DeclarationForInit)init).vardecls ;
    return new FIFO<Statement>(new DeclareStatement(
      vardecls,
View Full Code Here

        }
        else if (fom instanceof FieldDecl) {
          FieldDecl fdecl = (FieldDecl)fom ;
          if (fdecl.fieldAttrs.isStatic && fdecl.intializer != null) {
            SetValueExpr se = new SetValueExpr(new FieldVarExpr(cname.toString(),fdecl.name,null),fdecl.intializer,null) ;
            body = body.insert(new ExprStatement(se,null)) ;         
          }
        }
      }
      MethodDecl clinit = new MethodDecl(fa,"void","<clinit>",new FIFO<VarDecl>(),new FIFO<String>(),body) ;
      if (!foundInit && cdecl.classType != ClassType.INTERFACE) {
View Full Code Here

  private static void modifyConstructor(EvaluationContext context,
      final ArrayList<Statement> body) throws CompilerException {
    boolean foundInit = firstIsSuperInit(body);
    if (!foundInit) {
      body.add(0,new ExprStatement(new CallExpr(new FieldVarExpr(new VarExpr("super",null),"<init>",null),new FIFO<Expr>(),null),null)) ;
    }
    StubResolver resolver = context.classDef ;
    int pos = 1 ;
    ClassStub stub = resolver.getStub() ;
    for(FieldStub def: stub.fields.values()) {
      if (!def.isStatic) {
        if (def.initializer != null) {
          SetValueExpr se = new SetValueExpr(new FieldVarExpr(new VarExpr("this",null),def.nm,null),def.initializer,null) ;
          body.add(pos++,new ExprStatement(se,null)) ;
        }
      }
    }
  }
View Full Code Here

  private static boolean firstIsSuperInit(final ArrayList<Statement> body) {
    Iterator<Statement> i = body.iterator() ;
    if (i.hasNext()) {
      Statement st = i.next() ;
      if (st instanceof ExprStatement) {
        ExprStatement es = (ExprStatement)st ;
        Expr e = es.e ;
        if (e instanceof CallExpr) {
          CallExpr ce = (CallExpr)e ;
          Expr ve = ce.object ;
          if (ve instanceof FieldVarExpr) {
View Full Code Here

    public int meth(int arg0) ;
  }

  public void test1() throws Exception {
    MyInterface obj = makeObject(MyInterface.class,   
            new ExprStatement(new PostIncExpr(ARG0,null),null),
            new ReturnStatement(ARG0,null)) ;
    assertEquals(obj.meth(5),6) ;
  }
View Full Code Here

  }
  public void test0() throws Exception {
    MethTest obj = makeObject(MethTest.class,new TryCatchStatement(
            new FIFO<Statement>(new ReturnStatement(new ConstExpr(Integer.valueOf(0),null),null)),
            new FIFO<CatchBlock>(),
            new FIFO<Statement>(new ExprStatement(new ConstExpr(Integer.valueOf(5),null),null)),
            null
          ),
          new ReturnStatement(new ConstExpr(Integer.valueOf(-1),null),null)) ;
    assertEquals(obj.meth(),0) ;
  }
View Full Code Here

  }
  public void test1() throws Exception {
    MethTest obj = makeObject(MethTest.class,new DeclareStatement(
        new FIFO<VarDecl>(new VarDecl("int","x")),
        new FIFO<Statement>(new TryCatchStatement(
            new FIFO<Statement>(new ExprStatement(new SetValueExpr(X,new ConstExpr(Integer.valueOf(7),null),null),null)),
            new FIFO<CatchBlock>(),
            new FIFO<Statement>(new ExprStatement(new SetValueExpr(X,new PlusExpr(X,new ConstExpr(Integer.valueOf(1),null),null),null),null)),
            null
          ),
        new ReturnStatement(X,null)),
        null)) ;
    assertEquals(obj.meth(),8) ;
View Full Code Here

  public void test2() throws Exception {
    MethTest obj = makeObject(MethTest.class,new DeclareStatement(
        new FIFO<VarDecl>(new VarDecl("int","x")),
        new FIFO<Statement>(
          new TryCatchStatement(
            new FIFO<Statement>(new ExprStatement(new SetValueExpr(X,new ConstExpr(Integer.valueOf(7),null),null),null),new ReturnStatement(X,null)),
            new FIFO<CatchBlock>(),
            new FIFO<Statement>(new ExprStatement(new SetValueExpr(X,new PlusExpr(X,new ConstExpr(Integer.valueOf(1),null),null),null),null)),
            null
          ),
          new ReturnStatement(new ConstExpr(Integer.valueOf(-1),null),null)),
          null)) ;
    assertEquals(obj.meth(),7) ;
View Full Code Here

    public int meth(int arg0) ;
  }

  public void test1() throws Exception {
    MyInterface obj = makeObject(MyInterface.class,   
            new ExprStatement(new PreIncExpr(ARG0,null),null),
            new ReturnStatement(ARG0,null)) ;
    assertEquals(obj.meth(5),6) ;
  }
View Full Code Here

TOP

Related Classes of org.allspice.structured.statement.ExprStatement

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.