Nice/src/bossa/syntax typecheck.nice,1.124,1.125 loop.nice,1.11,1.12 locals.nice,1.10,1.11 customConstructor.nice,1.21,1.22 block.nice,1.4,1.5 analyse.nice,1.129,1.130
Daniel Bonniot <[email protected]>
| Newsgroups | gmane.comp.lang.nice.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16668/src/bossa/syntax
Modified Files:
typecheck.nice loop.nice locals.nice customConstructor.nice
block.nice analyse.nice
Log Message:
Avoid building blocks that contain a single statement, unless necessary
for scoping reasons.
Index: analyse.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v
retrieving revision 1.129
retrieving revision 1.130
diff -C2 -d -r1.129 -r1.130
*** analyse.nice 17 Jan 2005 18:26:14 -0000 1.129
--- analyse.nice 22 Feb 2005 10:27:09 -0000 1.130
***************
*** 765,769 ****
l.whileExp = analyse(l.whileExp, info);
if (notNull(l.whileExp).isFalse())
! info.setUnreachable();
}
--- 765,769 ----
l.whileExp = analyse(l.whileExp, info);
if (notNull(l.whileExp).isFalse())
! throw error(l.loopBody, "This statement is never executed");
}
Index: customConstructor.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** customConstructor.nice 17 Jan 2005 18:26:18 -0000 1.21
--- customConstructor.nice 22 Feb 2005 10:27:09 -0000 1.22
***************
*** 193,208 ****
}
! Block block = cast(stmt);
!
! if (block.statements.length == 0)
! missingThisError();
- Statement last = block.last;
- if (last instanceof Block)
- {
- resolveCCThis(last, thisLoc, classe);
- return;
- }
-
if (! (last instanceof ExpressionStmt))
missingThisError();
--- 193,204 ----
}
! var last = stmt;
! while (last instanceof Block)
! {
! if (last.statements.length == 0)
! missingThisError();
! last = last.last;
! }
if (! (last instanceof ExpressionStmt))
missingThisError();
Index: block.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/block.nice,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** block.nice 16 Jan 2005 00:28:21 -0000 1.4
--- block.nice 22 Feb 2005 10:27:09 -0000 1.5
***************
*** 136,146 ****
}
! public Block createBlock(List<Statement> statements)
{
! let res = new Block(statements: cast(null));
! let stmts = res.cutInBlocks(statements);
! res.statements = stmts;
! if (stmts.length > 0)
! res.setLocation(stmts[0].location());
! return res;
}
--- 136,161 ----
}
! public Statement createBlock(List<Statement> statements) =
! createBlock(statements, false, null);
!
! /**
! @param always When true, always create a block. When false, a block might
! not be created if there are not several statements.
! */
! public Statement createBlock(List<Statement> statements, boolean always,
! ?Location loc)
{
! if (!always && statements.size() == 1)
! return statements[0];
!
! let res = new Block(statements: cast(null));
! let stmts = res.cutInBlocks(statements);
! res.statements = stmts;
!
! if (loc != null)
! res.setLocation(loc);
! else if (stmts.length > 0)
! res.setLocation(stmts[0].location());
!
! return res;
}
Index: loop.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/loop.nice,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** loop.nice 16 Jan 2005 00:28:21 -0000 1.11
--- loop.nice 22 Feb 2005 10:27:07 -0000 1.12
***************
*** 23,27 ****
?Expression whileExp;
final Statement loopBody;
! final ?Block iterationStatements = null;
final boolean testFirst;
--- 23,27 ----
?Expression whileExp;
final Statement loopBody;
! final ?Statement iterationStatements = null;
final boolean testFirst;
***************
*** 88,106 ****
return "while (" + whileExp + ")" + loopBody;
! Statement[] itStatements = notNull(iterationStatements).statements;
! String itStats = "";
! for (int i = 0; i<itStatements.length; i++)
! {
! String tmp = itStatements[i].toString();
! itStats += tmp.substring(0, tmp.lastIndexOf(';'));
! if (i<itStatements.length-1) itStats += ", ";
! }
! return "for(; " + whileExp + " ;" + itStats + ")\n " + loopBody;
}
}
public Statement createForLoop
! (Expression test, Block update, Statement body, List<Statement> inits)
{
inits.add(new LoopStmt(whileExp:test, loopBody: body, iterationStatements: update, testFirst: true));
--- 88,121 ----
return "while (" + whileExp + ")" + loopBody;
! String itStats = iterationStatementsToString(notNull(iterationStatements));
! return "for(; "whileExp"; "itStats")\n "loopBody;
}
}
+ private String iterationStatementsToString(Statement s)
+ {
+ String res = s.toString();
+ return res.substring(0, res.lastIndexOf(';'));
+ }
+
+ iterationStatementsToString(Block iterationStatements)
+ {
+ Statement[] itStatements = iterationStatements.statements;
+
+ StringBuffer res = new StringBuffer();
+ for (int i = 0; i < itStatements.length; i++)
+ {
+ String tmp = itStatements[i].toString();
+ res.append(tmp.substring(0, tmp.lastIndexOf(';')));
+ if (i < itStatements.length - 1) res.append(", ");
+ }
+
+ return res.toString();
+ }
+
+
public Statement createForLoop
! (Expression test, Statement update, Statement body, List<Statement> inits)
{
inits.add(new LoopStmt(whileExp:test, loopBody: body, iterationStatements: update, testFirst: true));
Index: locals.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/locals.nice,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** locals.nice 16 Jan 2005 00:28:21 -0000 1.10
--- locals.nice 22 Feb 2005 10:27:07 -0000 1.11
***************
*** 45,49 ****
generateCode()
{
! throw Internal.error("Should not be called");
}
--- 45,59 ----
generateCode()
{
! /*
! This declaration is not inside a block, so it must be on its own.
! We still need to compile it, because the computation of the value
! can have side effects and for testing/debugging purposes.
! */
!
! gnu.expr.Expression[] inits = cast(new gnu.expr.Expression[1]);
! let letExp = new gnu.expr.LetExp(inits);
! inits[0] = this.compile(letExp);
! letExp.setBody(gnu.expr.QuoteExp.voidExp);
! return letExp;
}
Index: typecheck.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v
retrieving revision 1.124
retrieving revision 1.125
diff -C2 -d -r1.124 -r1.125
*** typecheck.nice 16 Jan 2005 00:28:21 -0000 1.124
--- typecheck.nice 22 Feb 2005 10:26:42 -0000 1.125
***************
*** 828,832 ****
{
s.exp = s.exp.noOverloading();
! typecheck(s.exp);
}
--- 828,833 ----
{
s.exp = s.exp.noOverloading();
! try { typecheck(s.exp); }
! catch (bossa.util.UserError ex) { throw ensureLocated(ex, s); }
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click