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