* net/loveruby/cflat/compiler/JumpResolver.java (currentBreakTarget, currentContinueTarget): does not throw exception.

* net/loveruby/cflat/compiler/JumpResolver.java: add preproc tags.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@3871 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2008-02-07 19:46:21 +00:00
parent cd77f10e64
commit 5e8902cc51
2 changed files with 36 additions and 18 deletions

View File

@ -1,3 +1,11 @@
Fri Feb 8 04:46:14 2008 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/compiler/JumpResolver.java
(currentBreakTarget, currentContinueTarget): does not throw
exception.
* net/loveruby/cflat/compiler/JumpResolver.java: add preproc tags.
Sun Feb 3 18:37:21 2008 Minero Aoki <aamine@loveruby.net> Sun Feb 3 18:37:21 2008 Minero Aoki <aamine@loveruby.net>
* build.xml: unify task: jar and compile. * build.xml: unify task: jar and compile.

View File

@ -10,6 +10,7 @@ public class JumpResolver extends Visitor {
new JumpResolver(h).resolve(ast); new JumpResolver(h).resolve(ast);
} }
// #@@range/ctor{
protected ErrorHandler errorHandler; protected ErrorHandler errorHandler;
protected LinkedList breakTargetStack; protected LinkedList breakTargetStack;
protected LinkedList continueTargetStack; protected LinkedList continueTargetStack;
@ -18,7 +19,9 @@ public class JumpResolver extends Visitor {
public JumpResolver(ErrorHandler h) { public JumpResolver(ErrorHandler h) {
errorHandler = h; errorHandler = h;
} }
// #@@}
// #@@range/resolve{
public void resolve(AST ast) throws SemanticException { public void resolve(AST ast) throws SemanticException {
breakTargetStack = new LinkedList(); breakTargetStack = new LinkedList();
continueTargetStack = new LinkedList(); continueTargetStack = new LinkedList();
@ -32,24 +35,19 @@ public class JumpResolver extends Visitor {
throw new SemanticException("compile failed."); throw new SemanticException("compile failed.");
} }
} }
// #@@}
protected void resolve(Node n) { protected void resolve(Node n) {
visitNode(n); visitNode(n);
} }
private BreakableStmt currentBreakTarget() // #@@range/currentBreakTarget{
throws SemanticException { private BreakableStmt currentBreakTarget() {
if (breakTargetStack.isEmpty()) {
throw new SemanticException("break from out of while/for/switch");
}
return (BreakableStmt)breakTargetStack.getLast(); return (BreakableStmt)breakTargetStack.getLast();
} }
// #@@}
private ContinueableStmt currentContinueTarget() private ContinueableStmt currentContinueTarget() {
throws SemanticException {
if (continueTargetStack.isEmpty()) {
throw new SemanticException("continue from out of while/for");
}
return (ContinueableStmt)continueTargetStack.getLast(); return (ContinueableStmt)continueTargetStack.getLast();
} }
@ -60,6 +58,7 @@ public class JumpResolver extends Visitor {
breakTargetStack.removeLast(); breakTargetStack.removeLast();
} }
// #@@range/_while{
public void visit(WhileNode node) { public void visit(WhileNode node) {
resolve(node.cond()); resolve(node.cond());
breakTargetStack.add(node); breakTargetStack.add(node);
@ -68,6 +67,7 @@ public class JumpResolver extends Visitor {
continueTargetStack.removeLast(); continueTargetStack.removeLast();
breakTargetStack.removeLast(); breakTargetStack.removeLast();
} }
// #@@}
public void visit(DoWhileNode node) { public void visit(DoWhileNode node) {
breakTargetStack.add(node); breakTargetStack.add(node);
@ -78,6 +78,7 @@ public class JumpResolver extends Visitor {
resolve(node.cond()); resolve(node.cond());
} }
// #@@range/_for{
public void visit(ForNode node) { public void visit(ForNode node) {
resolve(node.init()); resolve(node.init());
resolve(node.cond()); resolve(node.cond());
@ -88,24 +89,33 @@ public class JumpResolver extends Visitor {
continueTargetStack.removeLast(); continueTargetStack.removeLast();
breakTargetStack.removeLast(); breakTargetStack.removeLast();
} }
// #@@}
// #@@range/_break{
public void visit(BreakNode node) { public void visit(BreakNode node) {
try { BreakableStmt target = currentBreakTarget();
node.setTargetLabel(currentBreakTarget().endLabel()); if (target != null) {
node.setTargetLabel(target.endLabel());
} }
catch (SemanticException ex) { else {
errorHandler.error(node.location(), ex.getMessage()); errorHandler.error(node.location(),
"break from out of while/do-while/for/switch");
} }
} }
// #@@}
// #@@range/_continue{
public void visit(ContinueNode node) { public void visit(ContinueNode node) {
try { ContinueableStmt target = currentContinueTarget();
node.setTargetLabel(currentContinueTarget().continueLabel()); if (target != null) {
node.setTargetLabel(target.continueLabel());
} }
catch (SemanticException ex) { else {
errorHandler.error(node.location(), ex.getMessage()); errorHandler.error(node.location(),
"continue from out of while/do-while/for");
} }
} }
// #@@}
public void visit(LabelNode node) { public void visit(LabelNode node) {
try { try {