Package org.allspice.structured.statement

Examples of org.allspice.structured.statement.CaseStatement


    boolean deffound = false ;
    IdentityHashMap<CaseStatement, Mark> marks = new IdentityHashMap<CaseStatement, Mark>() ;
    for(Statement s: statements) {
      if (s instanceof CaseStatement) {
        Mark mark = new Mark() ;
        CaseStatement cs = (CaseStatement)s ;
        final Expr e = cs.e;
        if (e == null) {
          labels.add(new CaseLabel(null,mark)) ;
          deffound = true ;
        }
        else {
          ConstObj constobj = newContext.getConst(e) ;
          if (constobj == null) {
            throw new NonConstCase() ;
          }
          Integer label = getIntValue(constobj) ;
          labels.add(new CaseLabel(label,mark)) ;         
        }
        marks.put(cs,mark) ;
      }
    }
    if (!deffound) {
      labels.add(new CaseLabel(null,theEnd)) ;
    }
    l.add(new LookupSwitch(labels)) ;
    for(Statement s: statements) {
      if (s instanceof CaseStatement) {
        CaseStatement cs = (CaseStatement)s ;
        Mark mark = marks.get(cs) ;
        l.add(new Nop(mark)) ;
      }
      else {
        newContext.compile(s,l) ;
View Full Code Here


    public int meth(int arg0) ;
  }
  public void test1() throws Exception {
    SwitchTest obj = makeObject(SwitchTest.class,new SwitchStatement(ARG0,
        new FIFO<Statement>(
        new CaseStatement(new ConstExpr(Integer.valueOf(1),null),null),
        new ReturnStatement(new ConstExpr(Integer.valueOf(2),null),null),
        new CaseStatement(new ConstExpr(Integer.valueOf(0),null),null),
        new ReturnStatement(new ConstExpr(Integer.valueOf(0),null),null),
        new CaseStatement(new ConstExpr(Integer.valueOf(2),null),null),
        new ReturnStatement(new ConstExpr(Integer.valueOf(4),null),null),
        new CaseStatement(null,null),
        new ReturnStatement(new ConstExpr(Integer.valueOf(-1),null),null)
    ),null)) ;
    assertEquals(obj.meth(0),0) ;
    assertEquals(obj.meth(1),2) ;
    assertEquals(obj.meth(2),4) ;
View Full Code Here

TOP

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

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.