⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treeblock.java

📁 用Java实现的编译器。把源代码编译成SPARC汇编程序
💻 JAVA
字号:
// $Id: TreeBlock.java,v 1.6 1999/10/06 03:40:32 deberg Exp $package java6035.tools.IR;import java.util.*;/** * TreeBlock represents an ordered list of TreeNode objects forming a scope. */public class TreeBlock extends TreeNode{    protected Vector body;    protected LabelInstr label;    /**     * Constructs a TreeBlock object, given suffix of the label for the block.     */    public TreeBlock(String suffix)    {	body = new Vector();	this.label = new LabelInstr(suffix);    }    /**     * Constructs an empty TreeBlock object.      */    public TreeBlock()    {        this("block");    }    protected int tnkind()    {	return TREE_BLOCK;    }    /**     * Return the label instruction for this block.     */    public LabelInstr getLabelInstr()    {	return label;    }    /**     * Returns an enumeration of tree nodes.     */    public Enumeration nodes()    {	return body.elements();    }    /**     * Returns the size of the body.     */    public int size()    {	return body.size();    }    /**     * Removes a node at index i.      */    public void removeNodeAt(int i)    {	body.removeElementAt(i);    }    /**     * Removes a node.     */    public void removeNode(TreeNode n)    {	body.removeElement(n);    }    /**     * Returns a node at index i.      */    public TreeNode getNodeAt(int i)    {	return (TreeNode) body.elementAt(i);    }    /**     * Replace the node at index i with a new one.      */    public void setNodeAt(TreeNode tn, int i)    {	if (tn == null)	    throw new IRException("TreeBlock: setNodeAt: node null");	body.setElementAt(tn,i);        tn.setParent(this);    }    /**     * Insert given node into this block at index i.      */    public void insertNodeAt(TreeNode tn, int i)    {	if (tn == null)	    throw new IRException("TreeBlock: insertNodeAt: node null");	body.insertElementAt(tn,i);        tn.setParent(this);    }    /**     * Add given node to this block.      */    public void appendNode(TreeNode tn)    {	if (tn == null)	    throw new IRException("TreeBlock: appendNode: node null");	body.addElement(tn);        tn.setParent(this);    }    /**     * Add the set of nodes in the given vector.      */    public void appendNodes(Vector tnlist)    {	if (tnlist == null)	    throw new IRException("TreeBlock: appendNodes: list null");	for (int i=0; i<tnlist.size(); i++)	{	    Object o = tnlist.elementAt(i);	    if (o != null && o instanceof TreeNode) {		this.appendNode((TreeNode)o);                ((TreeNode)o).setParent(this);            }            else		throw new IRException		    ("TreeBlock: appendNodes: node null or not a TreeNode");	}    }    /**     * Add the set of nodes in the given vector.      */    public void appendNodes(TreeBlock tb)    {	if (tb == null)	    throw new IRException("TreeBlock: appendNodes: list null");	for (int i=0; i<tb.size(); i++)	{	    Object o = tb.getNodeAt(i);	    if (o != null && o instanceof TreeNode) {		this.appendNode((TreeNode)o);                ((TreeNode)o).setParent(this);            }            else		throw new IRException		    ("TreeBlock: appendNodes: node null or not a TreeNode");	}    }    /**     * Walkable interface: get name of the node.     */    public String getNodeName()    {        return "block";    }    /**     * Walkable interface: return number of neighbors.     */    public int getNeighborCount()    {	return 1+size();    }    /**     * Walkable interface: return the requested neighbor: 0, label; 1 - n,     * elements of the body (index 0 - n-1).     */    public Object getNeighbor(int index)    {	if (index == 0)	    return this.label;	else	    return getNodeAt(index-1);    }    public String PPrint(int indent, boolean recursive)    {        String output = new String();        for(int i=0;i<indent;i++) output += " ";        output += "(tree_block "+label.getLabel().toString()+"\n";        indent += 2;        if (recursive) {            for(int i=0;i<getNeighborCount();i++) {                Object o = getNeighbor(i);                if (o instanceof Walkable) {                    output +=                     ((Walkable)o).PPrint(indent, recursive);                } else {                    for(int j=0;j<indent;j++) output+=" ";                    output += o.toString() + "\n";                }            }        } else {            for(int i=0;i<indent;i++) output += " ";            output += getNeighborCount();            output += " elements)\n";        }        indent -= 2;        for(int i=0;i<indent;i++) output += " ";        output += ") /* tree_block "+label.getLabel().toString()+" */\n";        return output;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -