[Nice-commit] Nice/src/bossa/syntax LoopStmt.java,1.9,1.10
Brought to you by:
bonniot
|
From: <ar...@us...> - 2003-03-11 17:14:45
|
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv24309a/F:/nice/src/bossa/syntax
Modified Files:
LoopStmt.java
Log Message:
Added the 'for in' loop.
Index: LoopStmt.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/LoopStmt.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** LoopStmt.java 25 Jul 2002 13:33:12 -0000 1.9
--- LoopStmt.java 11 Mar 2003 17:14:38 -0000 1.10
***************
*** 42,45 ****
--- 42,75 ----
}
+ public static Statement forInLoop(Monotype vartype, LocatedString var, Location loc, Expression container, Statement body)
+ {
+ Monotype itertype;
+ LocatedString iter;
+ Expression getiter,iterexp,cond,getvar;
+ Statement loop,init,assign;
+
+ List tparams = new ArrayList(1);
+ tparams.add(vartype);
+ itertype = new MonotypeConstructor(new TypeIdent(new LocatedString("ForInIterator", loc)),
+ new TypeParameters(tparams), loc);
+ itertype.nullness = Monotype.sure;
+ getiter = CallExp.create(new IdentExp(new LocatedString("forInIterator", loc)), container);
+ iter = new LocatedString("for_in_iter", loc);
+ init = new Block.LocalVariable(iter, itertype, true, getiter);
+ iterexp = new IdentExp(iter);
+ cond = CallExp.create(new IdentExp(new LocatedString("next", loc)), iterexp);
+ getvar = CallExp.create(new IdentExp(new LocatedString("current", loc)), iterexp);
+ assign = new Block.LocalVariable(var, vartype, false, getvar);
+ List loopbody = new LinkedList();
+ loopbody.add(assign);
+ loopbody.add(body);
+ loop = LoopStmt.whileLoop(cond, new Block(loopbody));
+ List l = new LinkedList();
+ l.add(init);
+ l.add(loop);
+ return new Block(l);
+
+ }
+
/**
* Create a loop statement.
|