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:9
010     * @production VarDecl : {@link Decl} ::= <span class="component">Type:{@link Access}</span>;
011    
012     */
013    public class VarDecl extends Decl implements Cloneable {
014      /**
015       * @apilevel internal
016       */
017      public VarDecl clone() throws CloneNotSupportedException {
018        VarDecl node = (VarDecl) super.clone();
019        node.type_visited = -1;
020        node.type_computed = false;
021        node.type_value = null;
022        node.in$Circle(false);
023        node.is$Final(false);
024        return node;
025      }
026      /**
027       * @apilevel internal
028       */
029      public VarDecl copy() {
030        try {
031          VarDecl node = (VarDecl) clone();
032          node.parent = null;
033          if(children != null) {
034            node.children = (ASTNode[]) children.clone();
035          }
036          return node;
037        } catch (CloneNotSupportedException e) {
038          throw new Error("Error: clone not supported for " + getClass().getName());
039        }
040      }
041      /**
042       * Create a deep copy of the AST subtree at this node.
043       * The copy is dangling, i.e. has no parent.
044       * @return dangling copy of the subtree at this node
045       * @apilevel low-level
046       */
047      public VarDecl fullCopy() {
048        VarDecl tree = (VarDecl) copy();
049        if (children != null) {
050          for (int i = 0; i < children.length; ++i) {
051            ASTNode child = (ASTNode) children[i];
052            if(child != null) {
053              child = child.fullCopy();
054              tree.setChild(child, i);
055            }
056          }
057        }
058        return tree;
059      }
060      /**
061       * @aspect PrettyPrint
062       * @declaredat /home/csz-naf/examples/PicoJava/spec/PrettyPrint.jadd:48
063       */
064      public void prettyPrint(StringBuilder sb, int t) {
065                sb.append(getIndent(t)).append(getType()).append(" ");
066                sb.append(getName()).append(";\n");
067        }
068      /**
069       */
070      public VarDecl() {
071        super();
072      }
073      /**
074       * Initializes the child array to the correct size.
075       * Initializes List and Opt nta children.
076       * @apilevel internal
077       * @ast method
078       */
079      public void init$Children() {
080        children = new ASTNode[1];
081      }
082      /**
083       */
084      public VarDecl(String p0, Access p1) {
085        setName(p0);
086        setChild(p1, 0);
087      }
088      /**
089       * @apilevel low-level
090       */
091      protected int numChildren() {
092        return 1;
093      }
094      /**
095       * @apilevel internal
096       */
097      public boolean mayHaveRewrite() {
098        return false;
099      }
100      /**
101       * @apilevel low-level
102       */
103      public void flushCache() {
104        super.flushCache();
105        type_visited = -1;
106        type_computed = false;
107        type_value = null;
108      }
109      /**
110       * @apilevel internal
111       */
112      public void flushCollectionCache() {
113        super.flushCollectionCache();
114      }
115      /**
116       * Replaces the lexeme Name.
117       * @param value The new value for the lexeme Name.
118       * @apilevel high-level
119       */
120      public void setName(String value) {
121        tokenString_Name = value;
122      }
123      /**
124       * Retrieves the value for the lexeme Name.
125       * @return The value for the lexeme Name.
126       * @apilevel high-level
127       */
128      public String getName() {
129        return tokenString_Name != null ? tokenString_Name : "";
130      }
131      /**
132       * Replaces the Type child.
133       * @param node The new node to replace the Type child.
134       * @apilevel high-level
135       */
136      public void setType(Access node) {
137        setChild(node, 0);
138      }
139      /**
140       * Retrieves the Type child.
141       * @return The current node used as the Type child.
142       * @apilevel high-level
143       */
144      public Access getType() {
145        return (Access) getChild(0);
146      }
147      /**
148       * Retrieves the Type child.
149       * <p><em>This method does not invoke AST transformations.</em></p>
150       * @return The current node used as the Type child.
151       * @apilevel low-level
152       */
153      public Access getTypeNoTransform() {
154        return (Access) getChildNoTransform(0);
155      }
156      /**
157       * @apilevel internal
158       */
159      protected int type_visited = -1;
160      /**
161       * @apilevel internal
162       */
163      protected boolean type_computed = false;
164      /**
165       * @apilevel internal
166       */
167      protected TypeDecl type_value;
168      /**
169       * @attribute syn
170       * @aspect TypeAnalysis
171       * @declaredat /home/csz-naf/examples/PicoJava/spec/TypeAnalysis.jrag:34
172       */
173      public TypeDecl type() {
174        if(type_computed) {
175          return type_value;
176        }
177        ASTNode$State state = state();
178        if (type_visited == state().boundariesCrossed) {
179          throw new RuntimeException("Circular definition of attr: type in class: org.jastadd.ast.AST.SynDecl");
180        }
181        type_visited = state().boundariesCrossed;
182        int num = state.boundariesCrossed;
183        boolean isFinal = this.is$Final();
184        type_value = type_compute();
185        if(isFinal && num == state().boundariesCrossed) {
186          type_computed = true;
187        } else {
188        }
189    
190        type_visited = -1;
191        return type_value;
192      }
193      /**
194       * @apilevel internal
195       */
196      private TypeDecl type_compute() {  return getType().decl().type();  }
197      /**
198       * @apilevel internal
199       */
200      public ASTNode rewriteTo() {    return super.rewriteTo();
201      }}