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 * A catch clause that can catch a multiple exception types. 015 * @production MultiCatch : {@link CatchClause} ::= <span class="component">Parameter:{@link CatchParameterDeclaration}</span> <span class="component">{@link Block}</span>; 016 * @ast node 017 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/MultiCatch.ast:14 018 */ 019 public class MultiCatch extends CatchClause implements Cloneable { 020 /** 021 * @apilevel low-level 022 */ 023 public void flushCache() { 024 } 025 /** 026 * @apilevel internal 027 */ 028 public void flushCollectionCache() { 029 } 030 /** 031 * @apilevel internal 032 */ 033 @SuppressWarnings({"unchecked", "cast"}) 034 public MultiCatch clone() throws CloneNotSupportedException { 035 MultiCatch node = (MultiCatch)super.clone(); 036 node.parameterDeclaration_String_values = null; 037 node.localNum_computed = false; 038 node.in$Circle(false); 039 node.is$Final(false); 040 return node; 041 } 042 /** 043 * @apilevel internal 044 */ 045 @SuppressWarnings({"unchecked", "cast"}) 046 public MultiCatch copy() { 047 048 try { 049 MultiCatch node = (MultiCatch) clone(); 050 node.parent = null; 051 if(children != null) 052 node.children = (ASTNode[]) children.clone(); 053 054 return node; 055 } catch (CloneNotSupportedException e) { 056 throw new Error("Error: clone not supported for " + getClass().getName()); 057 } 058 059 }/** 060 * Create a deep copy of the AST subtree at this node. 061 * The copy is dangling, i.e. has no parent. 062 * @return dangling copy of the subtree at this node 063 * @apilevel low-level 064 */ 065 @SuppressWarnings({"unchecked", "cast"}) 066 public MultiCatch fullCopy() { 067 068 MultiCatch tree = (MultiCatch) copy(); 069 if (children != null) { 070 for (int i = 0; i < children.length; ++i) { 071 072 ASTNode child = (ASTNode) children[i]; 073 if(child != null) { 074 child = child.fullCopy(); 075 tree.setChild(child, i); 076 } 077 } 078 } 079 return tree; 080 081 } /** 082 * Pretty printing of multi-catch clause. 083 * @ast method 084 * @aspect MultiCatch 085 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/MultiCatch.jrag:146 086 */ 087 public void toString(StringBuffer sb) { 088 sb.append("catch ("); 089 getParameter().toString(sb); 090 sb.append(") "); 091 getBlock().toString(sb); 092 } 093 /** 094 * @ast method 095 * @aspect PreciseRethrow 096 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/PreciseRethrow.jrag:204 097 */ 098 void checkUnreachableStmt() { 099 if (!getBlock().reachable() && reportUnreachable()) 100 error("the exception "+getParameter().type().fullName()+ 101 " is not thrown in the body of the try statement"); 102 } 103 /** 104 * The Multi-Catch clause has two or more exception table entries 105 * which all point to the same exception handler. 106 * @ast method 107 * @aspect MultiCatch 108 * @declaredat /home/jesper/svn/JastAddJ/Java7Backend/MultiCatch.jrag:15 109 */ 110 public void exceptionTableEntries(CodeGeneration gen, TryStmt tryStmt) { 111 for (int i = 0; i < getParameter().getNumTypeAccess(); ++i) { 112 TypeDecl type = getParameter().getTypeAccess(i).type(); 113 114 gen.addException( 115 gen.addressOf(tryStmt.label_begin()), 116 gen.addressOf(tryStmt.label_block_end()), 117 gen.addressOf(label()), 118 gen.constantPool().addClass(type.constantPoolName()) 119 ); 120 } 121 } 122 /** 123 * Code gen. 124 * @ast method 125 * @aspect MultiCatch 126 * @declaredat /home/jesper/svn/JastAddJ/Java7Backend/MultiCatch.jrag:31 127 */ 128 public void createBCode(CodeGeneration gen) { 129 gen.addLabel(label()); 130 // add 1 to stack depth 131 gen.changeStackDepth(1); 132 getParameter().type().emitStoreLocal(gen, localNum()); 133 getBlock().createBCode(gen); 134 } 135 /** 136 * @ast method 137 * 138 */ 139 public MultiCatch() { 140 super(); 141 142 143 } 144 /** 145 * Initializes the child array to the correct size. 146 * Initializes List and Opt nta children. 147 * @apilevel internal 148 * @ast method 149 * @ast method 150 * 151 */ 152 public void init$Children() { 153 children = new ASTNode[2]; 154 } 155 /** 156 * @ast method 157 * 158 */ 159 public MultiCatch(CatchParameterDeclaration p0, Block p1) { 160 setChild(p0, 0); 161 setChild(p1, 1); 162 } 163 /** 164 * @apilevel low-level 165 * @ast method 166 * 167 */ 168 protected int numChildren() { 169 return 2; 170 } 171 /** 172 * @apilevel internal 173 * @ast method 174 * 175 */ 176 public boolean mayHaveRewrite() { 177 return false; 178 } 179 /** 180 * Replaces the Parameter child. 181 * @param node The new node to replace the Parameter child. 182 * @apilevel high-level 183 * @ast method 184 * 185 */ 186 public void setParameter(CatchParameterDeclaration node) { 187 setChild(node, 0); 188 } 189 /** 190 * Retrieves the Parameter child. 191 * @return The current node used as the Parameter child. 192 * @apilevel high-level 193 * @ast method 194 * 195 */ 196 public CatchParameterDeclaration getParameter() { 197 return (CatchParameterDeclaration)getChild(0); 198 } 199 /** 200 * Retrieves the Parameter child. 201 * <p><em>This method does not invoke AST transformations.</em></p> 202 * @return The current node used as the Parameter child. 203 * @apilevel low-level 204 * @ast method 205 * 206 */ 207 public CatchParameterDeclaration getParameterNoTransform() { 208 return (CatchParameterDeclaration)getChildNoTransform(0); 209 } 210 /** 211 * Replaces the Block child. 212 * @param node The new node to replace the Block child. 213 * @apilevel high-level 214 * @ast method 215 * 216 */ 217 public void setBlock(Block node) { 218 setChild(node, 1); 219 } 220 /** 221 * Retrieves the Block child. 222 * @return The current node used as the Block child. 223 * @apilevel high-level 224 * @ast method 225 * 226 */ 227 public Block getBlock() { 228 return (Block)getChild(1); 229 } 230 /** 231 * Retrieves the Block child. 232 * <p><em>This method does not invoke AST transformations.</em></p> 233 * @return The current node used as the Block child. 234 * @apilevel low-level 235 * @ast method 236 * 237 */ 238 public Block getBlockNoTransform() { 239 return (Block)getChildNoTransform(1); 240 } 241 protected java.util.Map parameterDeclaration_String_values; 242 /** 243 * Variable lookup in catch parameter scope. 244 * @attribute syn 245 * @aspect MultiCatch 246 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/MultiCatch.jrag:86 247 */ 248 @SuppressWarnings({"unchecked", "cast"}) 249 public SimpleSet parameterDeclaration(String name) { 250 Object _parameters = name; 251 if(parameterDeclaration_String_values == null) parameterDeclaration_String_values = new java.util.HashMap(4); 252 if(parameterDeclaration_String_values.containsKey(_parameters)) { 253 return (SimpleSet)parameterDeclaration_String_values.get(_parameters); 254 } 255 ASTNode$State state = state(); 256 int num = state.boundariesCrossed; 257 boolean isFinal = this.is$Final(); 258 SimpleSet parameterDeclaration_String_value = parameterDeclaration_compute(name); 259 if(isFinal && num == state().boundariesCrossed){ parameterDeclaration_String_values.put(_parameters, parameterDeclaration_String_value); } 260 return parameterDeclaration_String_value; 261 } 262 /** 263 * @apilevel internal 264 */ 265 private SimpleSet parameterDeclaration_compute(String name) { return getParameter().name().equals(name) ? getParameter() : SimpleSet.emptySet; } 266 /** 267 * @attribute syn 268 * @aspect ExceptionHandling 269 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/ExceptionHandling.jrag:212 270 */ 271 public boolean handles(TypeDecl exceptionType) { 272 ASTNode$State state = state(); 273 try { 274 CatchParameterDeclaration param = getParameter(); 275 for (int i = 0; i < param.getNumTypeAccess(); ++i) { 276 TypeDecl type = param.getTypeAccess(i).type(); 277 if (!type.isUnknown() && exceptionType.instanceOf(type)) 278 return true; 279 } 280 return false; 281 } 282 finally { 283 } 284 } 285 /** 286 * @apilevel internal 287 */ 288 protected boolean localNum_computed = false; 289 /** 290 * @apilevel internal 291 */ 292 protected int localNum_value; 293 /** 294 * @attribute inh 295 * @aspect MultiCatch 296 * @declaredat /home/jesper/svn/JastAddJ/Java7Backend/MultiCatch.jrag:43 297 */ 298 @SuppressWarnings({"unchecked", "cast"}) 299 public int localNum() { 300 if(localNum_computed) { 301 return localNum_value; 302 } 303 ASTNode$State state = state(); 304 int num = state.boundariesCrossed; 305 boolean isFinal = this.is$Final(); 306 localNum_value = getParent().Define_int_localNum(this, null); 307 if(isFinal && num == state().boundariesCrossed){ localNum_computed = true; } 308 return localNum_value; 309 } 310 /** 311 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/MultiCatch.jrag:27 312 * @apilevel internal 313 */ 314 public boolean Define_boolean_isMethodParameter(ASTNode caller, ASTNode child) { 315 if(caller == getParameterNoTransform()) { 316 return false; 317 } 318 else { return getParent().Define_boolean_isMethodParameter(this, caller); 319 } 320 } 321 /** 322 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/MultiCatch.jrag:28 323 * @apilevel internal 324 */ 325 public boolean Define_boolean_isConstructorParameter(ASTNode caller, ASTNode child) { 326 if(caller == getParameterNoTransform()) { 327 return false; 328 } 329 else { return getParent().Define_boolean_isConstructorParameter(this, caller); 330 } 331 } 332 /** 333 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/MultiCatch.jrag:29 334 * @apilevel internal 335 */ 336 public boolean Define_boolean_isExceptionHandlerParameter(ASTNode caller, ASTNode child) { 337 if(caller == getParameterNoTransform()) { 338 return true; 339 } 340 else { return getParent().Define_boolean_isExceptionHandlerParameter(this, caller); 341 } 342 } 343 /** 344 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/MultiCatch.jrag:80 345 * @apilevel internal 346 */ 347 public SimpleSet Define_SimpleSet_lookupVariable(ASTNode caller, ASTNode child, String name) { 348 if(caller == getParameterNoTransform()) { 349 return parameterDeclaration(name); 350 } 351 else { return super.Define_SimpleSet_lookupVariable(caller, child, name); 352 } 353 } 354 /** 355 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/MultiCatch.jrag:128 356 * @apilevel internal 357 */ 358 public boolean Define_boolean_reachable(ASTNode caller, ASTNode child) { 359 if(caller == getBlockNoTransform()){ 360 boolean anyReachable = false; 361 CatchParameterDeclaration param = getParameter(); 362 for (int i = 0; i < param.getNumTypeAccess(); ++i) { 363 TypeDecl type = param.getTypeAccess(i).type(); 364 if (!reachableCatchClause(type)) 365 error("The exception type "+type.fullName()+ 366 " can not be caught "+ 367 "by this multi-catch clause"); 368 else 369 anyReachable = true; 370 } 371 return anyReachable; 372 } 373 else { return getParent().Define_boolean_reachable(this, caller); 374 } 375 } 376 /** 377 * @declaredat /home/jesper/svn/JastAddJ/Java7Backend/MultiCatch.jrag:47 378 * @apilevel internal 379 */ 380 public int Define_int_localNum(ASTNode caller, ASTNode child) { 381 if(caller == getParameterNoTransform()) { 382 return localNum(); 383 } 384 else if(caller == getBlockNoTransform()) { 385 return localNum() + getParameter().type().variableSize(); 386 } 387 else { return getParent().Define_int_localNum(this, caller); 388 } 389 } 390 /** 391 * @apilevel internal 392 */ 393 public ASTNode rewriteTo() { 394 return super.rewriteTo(); 395 } 396 }