Skip to content

Commit f5f77f2

Browse files
author
dlsmith
committed
DynamicJava: Fix for broken for loops.
git-svn-id: file:///tmp/test-svn/trunk@4559 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 23d9ee9 commit f5f77f2

File tree

6 files changed

+23
-27
lines changed

6 files changed

+23
-27
lines changed

dynamicjava/lib/plt.jar

3 Bytes
Binary file not shown.

dynamicjava/src/edu/rice/cs/dynamicjava/interpreter/StatementChecker.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ public StatementChecker(TypeContext ctx, Options options) {
125125

126126
private TypeContext checkList(Iterable<? extends Node> l) {
127127
TypeContext c = context;
128-
for (Node n : l) {
129-
// TODO: fix the parser so there aren't any Expressions here
130-
if (n instanceof Expression) { n.acceptVisitor(new ExpressionChecker(c, opt)); }
131-
else { c = n.acceptVisitor(new StatementChecker(c, opt)); }
132-
}
128+
for (Node n : l) { c = n.acceptVisitor(new StatementChecker(c, opt)); }
133129
return c;
134130
}
135131

dynamicjava/src/edu/rice/cs/dynamicjava/interpreter/StatementEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public Object next() {
194194
catch (ContinueException e) {
195195
if (e.hasLabel() && !node.hasLabel(e.label())) { throw e; }
196196
}
197-
if (update != null) { evaluateSequence(update); }
197+
if (update != null) { seval.evaluateSequence(update); }
198198
}
199199
}
200200
catch (BreakException e) {

dynamicjava/src/edu/rice/cs/dynamicjava/symbol/LocalVariable.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ public LocalVariable(String name, Type type, boolean isFinal) {
2222

2323
public boolean isFinal() { return _isFinal; }
2424

25+
public String toString() { return "LocalVariable(" + _name + ")@" + Integer.toHexString(hashCode()); }
2526
}

dynamicjava/src/koala/dynamicjava/parser/grammar.jj

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,7 @@ PARSER_END(Parser)
26772677
|
26782678
( init=forInit() | ";" )
26792679
[ exp=expression() ] ";"
2680-
[ update=statementExpressionList() ]
2680+
[ update=expressionStatementList() ]
26812681
)
26822682
")" stmt=statement(true)
26832683
{
@@ -2701,7 +2701,8 @@ PARSER_END(Parser)
27012701
}
27022702

27032703
/**
2704-
* Used internally to parse a 'for' statement
2704+
* Used internally to parse a 'for' statement; produces a list of
2705+
* ExpressionStatements or a variable declaration
27052706
*/
27062707
List<Node> forInit() :
27072708
{
@@ -2710,34 +2711,32 @@ PARSER_END(Parser)
27102711
{
27112712
( LOOKAHEAD( variableDeclarationLookahead() )
27122713
list=localVariableDeclaration(true)
2713-
| list=statementExpressionList() ";"
2714+
| list=expressionStatementList() ";"
27142715
)
27152716
{
27162717
return list;
27172718
}
27182719
}
27192720

27202721
/**
2721-
* Parses a comma separated list of expression
2722+
* Parses a comma separated list of strict ExpressionStatements
27222723
*/
2723-
List<Node> statementExpressionList() :
2724+
List<Node> expressionStatementList() :
2725+
{ List<Node> list = new LinkedList<Node>(); Expression exp; }
27242726
{
2725-
List<Node> list = new LinkedList<Node>();
2726-
Node node;
2727-
}
2728-
{
2729-
node=statementExpression()
2727+
exp=statementExpression()
27302728
{
2731-
list.add(node);
2732-
}
2733-
( "," node=statementExpression()
2734-
{
2735-
list.add(node);
2729+
list.add(new ExpressionStatement(exp, true, filename,
2730+
exp.getBeginLine(), exp.getBeginColumn(),
2731+
exp.getEndLine(), exp.getEndColumn()));
27362732
}
2733+
( "," exp=statementExpression()
2734+
{ list.add(new ExpressionStatement(exp, true, filename,
2735+
exp.getBeginLine(), exp.getBeginColumn(),
2736+
exp.getEndLine(), exp.getEndColumn()));
2737+
}
27372738
)*
2738-
{
2739-
return list;
2740-
}
2739+
{ return list; }
27412740
}
27422741

27432742
/**
@@ -2918,7 +2917,7 @@ PARSER_END(Parser)
29182917
* a trailing semicolon is required and only StatementExpressions
29192918
* will be allowed.
29202919
*/
2921-
Node expressionStatement(boolean strictExpression) :
2920+
ExpressionStatement expressionStatement(boolean strictExpression) :
29222921
{ Expression exp; Token t = null; }
29232922
{
29242923
{ lookaheadFlag = strictExpression; } // makes strictExpression visible to lookahead

dynamicjava/src/koala/dynamicjava/tree/ForStatement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ public ForStatement(List<Node> init, Expression cond, List<Node> updt, Node body
9999

100100
/**
101101
* Creates a new for statement
102-
* @param init the initialization statements
102+
* @param init the initialization statements (either Statements or declarations)
103103
* @param cond the condition to evaluate at each loop
104-
* @param updt the update statements
104+
* @param updt the update statements (either Statements or declarations)
105105
* @param body the body
106106
* @param fn the filename
107107
* @param bl the begin line

0 commit comments

Comments
 (0)