mirror of https://github.com/aamine/cbc
* 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:
parent
cd77f10e64
commit
5e8902cc51
|
|
@ -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>
|
||||
|
||||
* build.xml: unify task: jar and compile.
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ public class JumpResolver extends Visitor {
|
|||
new JumpResolver(h).resolve(ast);
|
||||
}
|
||||
|
||||
// #@@range/ctor{
|
||||
protected ErrorHandler errorHandler;
|
||||
protected LinkedList breakTargetStack;
|
||||
protected LinkedList continueTargetStack;
|
||||
|
|
@ -18,7 +19,9 @@ public class JumpResolver extends Visitor {
|
|||
public JumpResolver(ErrorHandler h) {
|
||||
errorHandler = h;
|
||||
}
|
||||
// #@@}
|
||||
|
||||
// #@@range/resolve{
|
||||
public void resolve(AST ast) throws SemanticException {
|
||||
breakTargetStack = new LinkedList();
|
||||
continueTargetStack = new LinkedList();
|
||||
|
|
@ -32,24 +35,19 @@ public class JumpResolver extends Visitor {
|
|||
throw new SemanticException("compile failed.");
|
||||
}
|
||||
}
|
||||
// #@@}
|
||||
|
||||
protected void resolve(Node n) {
|
||||
visitNode(n);
|
||||
}
|
||||
|
||||
private BreakableStmt currentBreakTarget()
|
||||
throws SemanticException {
|
||||
if (breakTargetStack.isEmpty()) {
|
||||
throw new SemanticException("break from out of while/for/switch");
|
||||
}
|
||||
// #@@range/currentBreakTarget{
|
||||
private BreakableStmt currentBreakTarget() {
|
||||
return (BreakableStmt)breakTargetStack.getLast();
|
||||
}
|
||||
// #@@}
|
||||
|
||||
private ContinueableStmt currentContinueTarget()
|
||||
throws SemanticException {
|
||||
if (continueTargetStack.isEmpty()) {
|
||||
throw new SemanticException("continue from out of while/for");
|
||||
}
|
||||
private ContinueableStmt currentContinueTarget() {
|
||||
return (ContinueableStmt)continueTargetStack.getLast();
|
||||
}
|
||||
|
||||
|
|
@ -60,6 +58,7 @@ public class JumpResolver extends Visitor {
|
|||
breakTargetStack.removeLast();
|
||||
}
|
||||
|
||||
// #@@range/_while{
|
||||
public void visit(WhileNode node) {
|
||||
resolve(node.cond());
|
||||
breakTargetStack.add(node);
|
||||
|
|
@ -68,6 +67,7 @@ public class JumpResolver extends Visitor {
|
|||
continueTargetStack.removeLast();
|
||||
breakTargetStack.removeLast();
|
||||
}
|
||||
// #@@}
|
||||
|
||||
public void visit(DoWhileNode node) {
|
||||
breakTargetStack.add(node);
|
||||
|
|
@ -78,6 +78,7 @@ public class JumpResolver extends Visitor {
|
|||
resolve(node.cond());
|
||||
}
|
||||
|
||||
// #@@range/_for{
|
||||
public void visit(ForNode node) {
|
||||
resolve(node.init());
|
||||
resolve(node.cond());
|
||||
|
|
@ -88,24 +89,33 @@ public class JumpResolver extends Visitor {
|
|||
continueTargetStack.removeLast();
|
||||
breakTargetStack.removeLast();
|
||||
}
|
||||
// #@@}
|
||||
|
||||
// #@@range/_break{
|
||||
public void visit(BreakNode node) {
|
||||
try {
|
||||
node.setTargetLabel(currentBreakTarget().endLabel());
|
||||
BreakableStmt target = currentBreakTarget();
|
||||
if (target != null) {
|
||||
node.setTargetLabel(target.endLabel());
|
||||
}
|
||||
catch (SemanticException ex) {
|
||||
errorHandler.error(node.location(), ex.getMessage());
|
||||
else {
|
||||
errorHandler.error(node.location(),
|
||||
"break from out of while/do-while/for/switch");
|
||||
}
|
||||
}
|
||||
// #@@}
|
||||
|
||||
// #@@range/_continue{
|
||||
public void visit(ContinueNode node) {
|
||||
try {
|
||||
node.setTargetLabel(currentContinueTarget().continueLabel());
|
||||
ContinueableStmt target = currentContinueTarget();
|
||||
if (target != null) {
|
||||
node.setTargetLabel(target.continueLabel());
|
||||
}
|
||||
catch (SemanticException ex) {
|
||||
errorHandler.error(node.location(), ex.getMessage());
|
||||
else {
|
||||
errorHandler.error(node.location(),
|
||||
"continue from out of while/do-while/for");
|
||||
}
|
||||
}
|
||||
// #@@}
|
||||
|
||||
public void visit(LabelNode node) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in New Issue