📄 treewhile.java
字号:
// $Id: TreeWhile.java,v 1.5 2000/10/21 22:44:33 mdeeds Exp $package java6035.tools.IR;/** * TreeWhile represents a loop. It has two components: condition for * the loop and a body. */public class TreeWhile extends TreeNode { protected TreeBlock body; protected TreeBlock conditions; /** * Constructs a TreeWhile object with the arguments given. If the * @param body is null, an empty block is created. <BR> Requires * @param cond is not null. **/ public TreeWhile(Expression cond, TreeBlock body) { if (cond == null) throw new IRException("TreeWhile: constructor: cond null"); TreeBlock conditions = new TreeBlock("while_cond"); conditions.appendNode(new SimpleInstr(cond)); init(conditions, body); } /** * Constructs a TreeWhile object with the arguments given. The * last entry in @param cond TreeBlock should be an expression * with a boolean value. The Treeblock may contain a single * expression, or the flattened instructions for a larger boolean * expression. If @param body is null, an empty block is created. **/ public TreeWhile(TreeBlock cond, TreeBlock body) { init(cond, body); } private void init(TreeBlock cond, TreeBlock body) { this.conditions = cond; this.body = body; if (this.conditions == null) throw new IRException("TreeWhile: constructor: cond null"); this.conditions.setParent(this); if (this.body == null) this.body = new TreeBlock("while_body"); this.body.setParent(this); } /** * Returns the kind of this expression. (i.e. TREE_WHILE) **/ protected int tnkind() { return TREE_WHILE; } /** * Returns the body of this TreeWhile object. **/ public TreeBlock getBody() { return this.body; } /** * Return the conditional expression for this block. If the block already * flattened, behavior is not specified. If conditional block passed in is * null, behavior not specified. **/ public Rhs getCondition() { /* The conditional expression is assumed to be the expression on the * rhs of the first node of the block. */ if (conditions.size() > 0) { TreeNode tn = conditions.getNodeAt(0); if (tn.isSimpleInstr()) { return ((SimpleInstr)tn).getRhs(); } } return null; } /** * Returns the condition block of this TreeWhile object. **/ public TreeBlock getConditions() { return this.conditions; } /** * Walkable: returns the name of the node. */ public String getNodeName() { return "WHILE"; } /** * Walkable: returns the number of neighbors. */ public int getNeighborCount() { return 2; } /** * Walkable: returns the requested neighbor: 0, conditions; 1, body. */ public Object getNeighbor(int i) { if (i == 0) return conditions; else if (i == 1) return body; else return null; } public String PPrint(int indent, boolean recursive) { String output = new String(); for(int i=0;i<indent;i++) output += " "; output += "(WHILE /* conditions, loop_body */\n"; indent += 2; output += conditions.PPrint(indent,true); if (recursive) { output += body.PPrint(indent,recursive); } else { for(int i=0;i<indent;i++) output += " "; output += body.getNodeName() + "\n"; } indent -= 2; for(int i=0;i<indent;i++) output += " "; output += ") /* WHILE */ \n"; return output; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -