trystmt.java
来自「JDK1.4编译器后端」· Java 代码 · 共 940 行 · 第 1/3 页
JAVA
940 行
package AST;
import java.util.HashSet;import java.util.LinkedHashSet;import java.io.FileNotFoundException;import java.io.File;import java.util.*;import beaver.*;import java.util.ArrayList;import java.util.zip.*;import java.io.*;public class TryStmt extends Stmt implements Cloneable, FinallyHost {
public void flushCache() { super.flushCache(); branches_computed = false; branches_value = null; branchesFromFinally_computed = false; branchesFromFinally_value = null; targetBranches_computed = false; targetBranches_value = null; escapedBranches_computed = false; escapedBranches_value = null; isDAafter_Variable_values = null; isDUbefore_Variable_visited = new java.util.HashMap(4); isDUafter_Variable_values = null; reachableThrow_CatchClause_values = null; canCompleteNormally_computed = false; label_begin_computed = false; label_block_end_computed = false; label_end_computed = false; label_finally_computed = false; label_finally_block_computed = false; label_exception_handler_computed = false; label_catch_end_computed = false; handlesException_TypeDecl_values = null; typeError_computed = false; typeError_value = null; typeRuntimeException_computed = false; typeRuntimeException_value = null; } @SuppressWarnings({"unchecked", "cast"}) public TryStmt clone() throws CloneNotSupportedException { TryStmt node = (TryStmt)super.clone(); node.branches_computed = false; node.branches_value = null; node.branchesFromFinally_computed = false; node.branchesFromFinally_value = null; node.targetBranches_computed = false; node.targetBranches_value = null; node.escapedBranches_computed = false; node.escapedBranches_value = null; node.isDAafter_Variable_values = null; node.isDUbefore_Variable_visited = new java.util.HashMap(4); node.isDUafter_Variable_values = null; node.reachableThrow_CatchClause_values = null; node.canCompleteNormally_computed = false; node.label_begin_computed = false; node.label_block_end_computed = false; node.label_end_computed = false; node.label_finally_computed = false; node.label_finally_block_computed = false; node.label_exception_handler_computed = false; node.label_catch_end_computed = false; node.handlesException_TypeDecl_values = null; node.typeError_computed = false; node.typeError_value = null; node.typeRuntimeException_computed = false; node.typeRuntimeException_value = null; node.in$Circle(false); node.is$Final(false); return node; } @SuppressWarnings({"unchecked", "cast"}) public TryStmt copy() { try { TryStmt node = (TryStmt)clone(); if(children != null) node.children = (ASTNode[])children.clone(); return node; } catch (CloneNotSupportedException e) { } System.err.println("Error: Could not clone node of type " + getClass().getName() + "!"); return null; } @SuppressWarnings({"unchecked", "cast"}) public TryStmt fullCopy() { TryStmt res = (TryStmt)copy(); for(int i = 0; i < getNumChildNoTransform(); i++) { ASTNode node = getChildNoTransform(i); if(node != null) node = node.fullCopy(); res.setChild(node, i); } return res; } // Declared in BranchTarget.jrag at line 61 public void collectBranches(Collection c) { c.addAll(escapedBranches()); } // Declared in BranchTarget.jrag at line 162 public Stmt branchTarget(Stmt branchStmt) { if(targetBranches().contains(branchStmt)) return this; return super.branchTarget(branchStmt); } // Declared in BranchTarget.jrag at line 200 public void collectFinally(Stmt branchStmt, ArrayList list) { if(hasFinally() && !branchesFromFinally().contains(branchStmt)) list.add(this); if(targetBranches().contains(branchStmt)) return; super.collectFinally(branchStmt, list); } // Declared in ExceptionHandling.jrag at line 203 protected boolean reachedException(TypeDecl type) { boolean found = false; // found is true if the exception type is caught by a catch clause for(int i = 0; i < getNumCatchClause() && !found; i++) if(getCatchClause(i).handles(type)) found = true; // if an exception is thrown in the block and the exception is not caught and // either there is no finally block or the finally block can complete normally if(!found && (!hasFinally() || getFinally().canCompleteNormally()) ) if(getBlock().reachedException(type)) return true; // even if the exception is caught by the catch clauses they may // throw new exceptions for(int i = 0; i < getNumCatchClause() && found; i++) if(getCatchClause(i).reachedException(type)) return true; return hasFinally() && getFinally().reachedException(type); } // Declared in PrettyPrint.jadd at line 712 public void toString(StringBuffer s) { s.append("try "); getBlock().toString(s); for(int i = 0; i < getNumCatchClause(); i++) { s.append(indent()); getCatchClause(i).toString(s); } if(hasFinally()) { s.append(indent()); s.append("finally "); getFinally().toString(s); } } // Declared in CodeGeneration.jrag at line 800 public void emitExceptionHandler(CodeGeneration gen) { // add 1 to stack depth gen.changeStackDepth(1); int num = localNum(); gen.emitStoreReference(num); gen.emitJsr(label_finally_block()); gen.emitLoadReference(num); gen.emit(Bytecode.ATHROW); } // Declared in CodeGeneration.jrag at line 810 public void emitFinallyBlock(CodeGeneration gen) { // add 1 to stack depth gen.changeStackDepth(1); int num = localNum()+1; gen.emitStoreReference(num); getFinally().createBCode(gen); if(num < 256) gen.emit(Bytecode.RET).add(num); else gen.emit(Bytecode.WIDE).emit(Bytecode.RET).add2(num); } // Declared in CreateBCode.jrag at line 1464 public void createBCode(CodeGeneration gen) { super.createBCode(gen); gen.addLabel(label_begin()); getBlock().createBCode(gen); if(getBlock().canCompleteNormally()) gen.emitGoto(label_finally()); gen.addLabel(label_block_end()); for(int i = 0; i < getNumCatchClause(); i++) { getCatchClause(i).createBCode(gen); if(getCatchClause(i).getBlock().canCompleteNormally()) { if(!hasFinally()) gen.emitGoto(label_finally()); else gen.emitGoto(label_catch_end()); } } gen.addLabel(label_catch_end()); if(hasFinally() && getNumCatchClause() > 0) { gen.emitJsr(label_finally_block()); if(canCompleteNormally()) gen.emitGoto(label_end()); } gen.addLabel(label_finally()); if(hasFinally()) { if(getBlock().canCompleteNormally()) { gen.emitJsr(label_finally_block()); if(canCompleteNormally()) gen.emitGoto(label_end()); } gen.addLabel(label_exception_handler()); emitExceptionHandler(gen); gen.addLabel(label_finally_block()); emitFinallyBlock(gen); } gen.addLabel(label_end()); gen.createExceptionTable(this); } // Declared in java.ast at line 3 // Declared in java.ast line 222
public TryStmt() { super();
setChild(new List(), 1);
setChild(new Opt(), 2);
} // Declared in java.ast at line 12
// Declared in java.ast line 222 public TryStmt(Block p0, List<CatchClause> p1, Opt<Block> p2) { setChild(p0, 0); setChild(p1, 1); setChild(p2, 2); } // Declared in java.ast at line 18 protected int numChildren() {
return 3;
} // Declared in java.ast at line 21
public boolean mayHaveRewrite() { return false; } // Declared in java.ast at line 2 // Declared in java.ast line 222 public void setBlock(Block node) { setChild(node, 0); } // Declared in java.ast at line 5 public Block getBlock() { return (Block)getChild(0); } // Declared in java.ast at line 9 public Block getBlockNoTransform() { return (Block)getChildNoTransform(0); } // Declared in java.ast at line 2 // Declared in java.ast line 222 public void setCatchClauseList(List<CatchClause> list) { setChild(list, 1); } // Declared in java.ast at line 6 private int getNumCatchClause = 0; // Declared in java.ast at line 7 public int getNumCatchClause() { return getCatchClauseList().getNumChild(); } // Declared in java.ast at line 11 @SuppressWarnings({"unchecked", "cast"}) public CatchClause getCatchClause(int i) { return (CatchClause)getCatchClauseList().getChild(i); } // Declared in java.ast at line 15 public void addCatchClause(CatchClause node) { List<CatchClause> list = getCatchClauseList(); list.addChild(node); } // Declared in java.ast at line 20 public void setCatchClause(CatchClause node, int i) { List<CatchClause> list = getCatchClauseList(); list.setChild(node, i); } // Declared in java.ast at line 24 public List<CatchClause> getCatchClauses() { return getCatchClauseList();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?