📄 simpleinstr.java
字号:
// $Id: SimpleInstr.java,v 1.3 1999/09/29 06:20:44 deberg Exp $package java6035.tools.IR;/** * The SimpleInstr class captures a simple assignment instruction or rhs * values without a destination. For example, the following examples can be * represented as SimpleInstr objects: * * "a = b+c;" or "a = foo();" or "a;" or "foo();" * * A SimpleInstr object contains a Lhs object and a Rhs object. Depends on the * structure of the Rhs object, sub-expressions may exist. */public class SimpleInstr extends Instruction{ protected Lhs lhs; protected Rhs rhs; /** * Creates a simple instruction with just a rhs value. */ public SimpleInstr(Rhs r) { this(null,r); } /** * Creates a simple instruction with just a lhs value and a rhs value. */ public SimpleInstr(Lhs l, Rhs r) { this.lhs = l; this.rhs = r; if (this.rhs == null) throw new IRException("SimpleInstr: constructor: rhs null"); } /** * Returns the rhs value. */ public Rhs getRhs() { return rhs; } /** * Sets the rhs value. */ public void setRhs(Rhs r) { this.rhs = r; if (this.rhs == null) throw new IRException("SimpleInstr: setRhs: rhs null"); } /** * Returns the lhs value. */ public Lhs getLhs() { return lhs; } /** * Sets the lhs value. */ public void setLhs(Lhs l) { this.lhs = l; } /** * Returns the type of the instruction. */ protected int tnkind() { return SIMPLE_INSTR; } /** * Walkable: returns the name of the node. */ public String getNodeName() { if (lhs != null) return "assignment"; else return "expression"; } /** * Walkable: returns the number of neighbors from this node. */ public int getNeighborCount() { if (lhs != null) return 2; return 1; } /** * Walkable: returns a specific neighbor: 0, lhs if there is one; * otherwise, rhs. */ public Object getNeighbor(int index) { if (lhs != null) { if (index == 0) return lhs; index--; } if (index == 0) return rhs; else return null; } public String PPrint(int indent, boolean recursive) { String output = new String(); for(int i=0;i<indent;i++) output += " "; output += "(simple_instruction\n"; if (recursive) { if (lhs != null) { // assignment output += this.lhs.PPrint(indent+2, true); for(int i=0;i<indent+2;i++) output += " "; output += " :=\n"; output += this.rhs.PPrint(indent+4, true); } else { // no assignment output += this.rhs.PPrint(indent+2, true); } } for(int i=0;i<indent;i++) output += " "; output += ") /* simple_instruction */\n"; return output; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -