001    /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.3 */
002    package AST;
003    
004    import java.util.Collection;
005    import java.util.ArrayList;
006    import java.util.HashSet;
007    /**
008     * @ast node
009     * @declaredat /home/csz-naf/examples/PicoJava/spec/picojava.ast:10
010     * @production AssignStmt : {@link Stmt} ::= <span class="component">Variable:{@link Access}</span> <span class="component">Value:{@link Exp}</span>;
011    
012     */
013    public class AssignStmt extends Stmt implements Cloneable {
014      /**
015       * @apilevel internal
016       */
017      public AssignStmt clone() throws CloneNotSupportedException {
018        AssignStmt node = (AssignStmt) super.clone();
019        node.in$Circle(false);
020        node.is$Final(false);
021        return node;
022      }
023      /**
024       * @apilevel internal
025       */
026      public AssignStmt copy() {
027        try {
028          AssignStmt node = (AssignStmt) clone();
029          node.parent = null;
030          if(children != null) {
031            node.children = (ASTNode[]) children.clone();
032          }
033          return node;
034        } catch (CloneNotSupportedException e) {
035          throw new Error("Error: clone not supported for " + getClass().getName());
036        }
037      }
038      /**
039       * Create a deep copy of the AST subtree at this node.
040       * The copy is dangling, i.e. has no parent.
041       * @return dangling copy of the subtree at this node
042       * @apilevel low-level
043       */
044      public AssignStmt fullCopy() {
045        AssignStmt tree = (AssignStmt) copy();
046        if (children != null) {
047          for (int i = 0; i < children.length; ++i) {
048            ASTNode child = (ASTNode) children[i];
049            if(child != null) {
050              child = child.fullCopy();
051              tree.setChild(child, i);
052            }
053          }
054        }
055        return tree;
056      }
057      /**
058       * @aspect ErrorCheck
059       * @declaredat /home/csz-naf/examples/PicoJava/spec/ErrorCheck.jadd:24
060       */
061      public void collectErrors(Collection c) {
062        super.collectErrors(c);
063        if(!getValue().type().isSubtypeOf(getVariable().type()))
064          error(c, "Can not assign a variable of type " + getVariable().type().getName() +
065            " to a value of type " + getValue().type().getName());
066      }
067      /**
068       * @aspect PrettyPrint
069       * @declaredat /home/csz-naf/examples/PicoJava/spec/PrettyPrint.jadd:52
070       */
071      public void prettyPrint(StringBuilder sb, int t) {
072                sb.append(getIndent(t)).append(getVariable()).append(" = ");
073                sb.append(getValue()).append(";\n");    
074        }
075      /**
076       */
077      public AssignStmt() {
078        super();
079      }
080      /**
081       * Initializes the child array to the correct size.
082       * Initializes List and Opt nta children.
083       * @apilevel internal
084       * @ast method
085       */
086      public void init$Children() {
087        children = new ASTNode[2];
088      }
089      /**
090       */
091      public AssignStmt(Access p0, Exp p1) {
092        setChild(p0, 0);
093        setChild(p1, 1);
094      }
095      /**
096       * @apilevel low-level
097       */
098      protected int numChildren() {
099        return 2;
100      }
101      /**
102       * @apilevel internal
103       */
104      public boolean mayHaveRewrite() {
105        return false;
106      }
107      /**
108       * @apilevel low-level
109       */
110      public void flushCache() {
111        super.flushCache();
112      }
113      /**
114       * @apilevel internal
115       */
116      public void flushCollectionCache() {
117        super.flushCollectionCache();
118      }
119      /**
120       * Replaces the Variable child.
121       * @param node The new node to replace the Variable child.
122       * @apilevel high-level
123       */
124      public void setVariable(Access node) {
125        setChild(node, 0);
126      }
127      /**
128       * Retrieves the Variable child.
129       * @return The current node used as the Variable child.
130       * @apilevel high-level
131       */
132      public Access getVariable() {
133        return (Access) getChild(0);
134      }
135      /**
136       * Retrieves the Variable child.
137       * <p><em>This method does not invoke AST transformations.</em></p>
138       * @return The current node used as the Variable child.
139       * @apilevel low-level
140       */
141      public Access getVariableNoTransform() {
142        return (Access) getChildNoTransform(0);
143      }
144      /**
145       * Replaces the Value child.
146       * @param node The new node to replace the Value child.
147       * @apilevel high-level
148       */
149      public void setValue(Exp node) {
150        setChild(node, 1);
151      }
152      /**
153       * Retrieves the Value child.
154       * @return The current node used as the Value child.
155       * @apilevel high-level
156       */
157      public Exp getValue() {
158        return (Exp) getChild(1);
159      }
160      /**
161       * Retrieves the Value child.
162       * <p><em>This method does not invoke AST transformations.</em></p>
163       * @return The current node used as the Value child.
164       * @apilevel low-level
165       */
166      public Exp getValueNoTransform() {
167        return (Exp) getChildNoTransform(1);
168      }
169      /**
170       * @apilevel internal
171       */
172      public ASTNode rewriteTo() {    return super.rewriteTo();
173      }}