001 /* This file was generated with JastAdd2 (http://jastadd.org) version R20130213 */ 002 package AST; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.*; 007 import beaver.*; 008 import java.util.ArrayList; 009 import java.util.zip.*; 010 import java.io.*; 011 import java.io.FileNotFoundException; 012 import java.util.Collection; 013 /** 014 * @production ConstCase : {@link Case} ::= <span class="component">Value:{@link Expr}</span>; 015 * @ast node 016 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/java.ast:204 017 */ 018 public class ConstCase extends Case implements Cloneable { 019 /** 020 * @apilevel low-level 021 */ 022 public void flushCache() { 023 } 024 /** 025 * @apilevel internal 026 */ 027 public void flushCollectionCache() { 028 } 029 /** 030 * @apilevel internal 031 */ 032 @SuppressWarnings({"unchecked", "cast"}) 033 public ConstCase clone() throws CloneNotSupportedException { 034 ConstCase node = (ConstCase)super.clone(); 035 node.in$Circle(false); 036 node.is$Final(false); 037 return node; 038 } 039 /** 040 * @apilevel internal 041 */ 042 @SuppressWarnings({"unchecked", "cast"}) 043 public ConstCase copy() { 044 045 try { 046 ConstCase node = (ConstCase) clone(); 047 node.parent = null; 048 if(children != null) 049 node.children = (ASTNode[]) children.clone(); 050 051 return node; 052 } catch (CloneNotSupportedException e) { 053 throw new Error("Error: clone not supported for " + getClass().getName()); 054 } 055 056 }/** 057 * Create a deep copy of the AST subtree at this node. 058 * The copy is dangling, i.e. has no parent. 059 * @return dangling copy of the subtree at this node 060 * @apilevel low-level 061 */ 062 @SuppressWarnings({"unchecked", "cast"}) 063 public ConstCase fullCopy() { 064 065 ConstCase tree = (ConstCase) copy(); 066 if (children != null) { 067 for (int i = 0; i < children.length; ++i) { 068 069 ASTNode child = (ASTNode) children[i]; 070 if(child != null) { 071 child = child.fullCopy(); 072 tree.setChild(child, i); 073 } 074 } 075 } 076 return tree; 077 078 } /** 079 * @ast method 080 * @aspect NameCheck 081 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/NameCheck.jrag:406 082 */ 083 public void nameCheck() { 084 if(getValue().isConstant() && bind(this) != this) { 085 error("constant expression " + getValue() + " is multiply declared in two case statements"); 086 } 087 } 088 /** 089 * @ast method 090 * @aspect PrettyPrint 091 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:562 092 */ 093 public void toString(StringBuffer s) { 094 s.append(indent()); 095 s.append("case "); 096 getValue().toString(s); 097 s.append(":"); 098 } 099 /** 100 * @ast method 101 * @aspect EnumsCodegen 102 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Backend/EnumsCodegen.jrag:32 103 */ 104 public void transformation() { 105 if(getValue() instanceof VarAccess && getValue().varDecl() instanceof EnumConstant) { 106 int i = hostType().createEnumIndex((EnumConstant)getValue().varDecl()); 107 setValue(Literal.buildIntegerLiteral(i)); 108 } 109 super.transformation(); 110 } 111 /** 112 * @ast method 113 * 114 */ 115 public ConstCase() { 116 super(); 117 118 119 } 120 /** 121 * Initializes the child array to the correct size. 122 * Initializes List and Opt nta children. 123 * @apilevel internal 124 * @ast method 125 * @ast method 126 * 127 */ 128 public void init$Children() { 129 children = new ASTNode[1]; 130 } 131 /** 132 * @ast method 133 * 134 */ 135 public ConstCase(Expr p0) { 136 setChild(p0, 0); 137 } 138 /** 139 * @apilevel low-level 140 * @ast method 141 * 142 */ 143 protected int numChildren() { 144 return 1; 145 } 146 /** 147 * @apilevel internal 148 * @ast method 149 * 150 */ 151 public boolean mayHaveRewrite() { 152 return false; 153 } 154 /** 155 * Replaces the Value child. 156 * @param node The new node to replace the Value child. 157 * @apilevel high-level 158 * @ast method 159 * 160 */ 161 public void setValue(Expr node) { 162 setChild(node, 0); 163 } 164 /** 165 * Retrieves the Value child. 166 * @return The current node used as the Value child. 167 * @apilevel high-level 168 * @ast method 169 * 170 */ 171 public Expr getValue() { 172 return (Expr)getChild(0); 173 } 174 /** 175 * Retrieves the Value child. 176 * <p><em>This method does not invoke AST transformations.</em></p> 177 * @return The current node used as the Value child. 178 * @apilevel low-level 179 * @ast method 180 * 181 */ 182 public Expr getValueNoTransform() { 183 return (Expr)getChildNoTransform(0); 184 } 185 /** 186 * @ast method 187 * @aspect Enums 188 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:503 189 */ 190 public void refined_Enums_ConstCase_typeCheck() { 191 boolean isEnumConstant = getValue().isEnumConstant(); 192 if(switchType().isEnumDecl() && !isEnumConstant) { 193 error("Unqualified enumeration constant required"); 194 } else { 195 TypeDecl switchType = switchType(); 196 TypeDecl type = getValue().type(); 197 if(!type.assignConversionTo(switchType, getValue())) 198 error("Constant expression must be assignable to Expression"); 199 if(!getValue().isConstant() && !getValue().type().isUnknown() && 200 !isEnumConstant) 201 error("Switch expression must be constant"); 202 } 203 } 204 /** 205 * <p>Improve the type checking error messages given for case labels. 206 * @ast method 207 * @aspect StringsInSwitch 208 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/StringsInSwitch.jrag:68 209 */ 210 public void typeCheck() { 211 boolean isEnumConstant = getValue().isEnumConstant(); 212 TypeDecl switchType = switchType(); 213 TypeDecl type = getValue().type(); 214 if (switchType.isEnumDecl() && !isEnumConstant) 215 error("Unqualified enumeration constant required"); 216 if (!type.assignConversionTo(switchType, getValue())) 217 error("Case label has incompatible type "+switchType.name()+ 218 ", expected type compatible with "+type.name()); 219 if (!getValue().isConstant() && !getValue().type().isUnknown() && 220 !isEnumConstant) 221 error("Case label must have constant expression"); 222 } 223 /** 224 * @ast method 225 * @aspect NameCheck 226 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/NameCheck.jrag:432 227 */ 228 private boolean refined_NameCheck_ConstCase_constValue_Case(Case c) 229 { 230 if(!(c instanceof ConstCase) || !getValue().isConstant()) 231 return false; 232 if(!getValue().type().assignableToInt() || !((ConstCase)c).getValue().type().assignableToInt()) 233 return false; 234 return getValue().constant().intValue() == ((ConstCase)c).getValue().constant().intValue(); 235 } 236 /** 237 * @ast method 238 * @aspect Enums 239 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:517 240 */ 241 private boolean refined_Enums_ConstCase_constValue_Case(Case c) 242 { 243 if(switchType().isEnumDecl()) { 244 if(!(c instanceof ConstCase) || !getValue().isConstant()) 245 return false; 246 return getValue().varDecl() == ((ConstCase)c).getValue().varDecl(); 247 } 248 else 249 return refined_NameCheck_ConstCase_constValue_Case(c); 250 } 251 /** 252 * @attribute syn 253 * @aspect NameCheck 254 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/NameCheck.jrag:431 255 */ 256 public boolean constValue(Case c) { 257 ASTNode$State state = state(); 258 try { 259 if (isDefaultCase() || c.isDefaultCase()) 260 return isDefaultCase() && c.isDefaultCase(); 261 262 Expr myValue = getValue(); 263 Expr otherValue = ((ConstCase) c).getValue(); 264 TypeDecl myType = myValue.type(); 265 TypeDecl otherType = otherValue.type(); 266 if (myType.isString() || otherType.isString()) { 267 if (!myType.isString() || !otherType.isString()) 268 return false; 269 if (!myValue.isConstant() || !otherValue.isConstant()) 270 return false; 271 return myValue.constant().stringValue().equals( 272 otherValue.constant().stringValue()); 273 } 274 275 return refined_Enums_ConstCase_constValue_Case(c); 276 } 277 finally { 278 } 279 } 280 /** 281 * @declaredat /home/jesper/svn/JastAddJ/Java1.5Frontend/Enums.jrag:497 282 * @apilevel internal 283 */ 284 public SimpleSet Define_SimpleSet_lookupVariable(ASTNode caller, ASTNode child, String name) { 285 if(caller == getValueNoTransform()) { 286 return switchType().isEnumDecl() ? switchType().memberFields(name) : lookupVariable(name); 287 } 288 else { return getParent().Define_SimpleSet_lookupVariable(this, caller, name); 289 } 290 } 291 /** 292 * @apilevel internal 293 */ 294 public ASTNode rewriteTo() { 295 return super.rewriteTo(); 296 } 297 }