001 /* This file was generated with JastAdd2 (http://jastadd.org) version 2.1.13-12-g880e696 */ 002 package org.extendj.ast; 003 004 import java.util.HashSet; 005 import java.io.File; 006 import java.util.Set; 007 import java.util.Collections; 008 import java.util.Collection; 009 import java.util.ArrayList; 010 import beaver.*; 011 import java.util.*; 012 import java.io.ByteArrayOutputStream; 013 import java.io.PrintStream; 014 import java.lang.reflect.InvocationTargetException; 015 import java.lang.reflect.Method; 016 import org.jastadd.util.*; 017 import java.util.zip.*; 018 import java.io.*; 019 import org.jastadd.util.PrettyPrintable; 020 import org.jastadd.util.PrettyPrinter; 021 import java.io.FileNotFoundException; 022 import java.io.BufferedInputStream; 023 import java.io.DataInputStream; 024 /** 025 * @ast node 026 * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:82 027 * @production VariableDecl : {@link ASTNode} ::= <span class="component"><ID:String></span> <span class="component">{@link Dims}*</span> <span class="component">[Init:{@link Expr}]</span>; 028 029 */ 030 public class VariableDecl extends ASTNode<ASTNode> implements Cloneable { 031 /** 032 * @aspect Java4PrettyPrint 033 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:58 034 */ 035 public void prettyPrint(PrettyPrinter out) { 036 out.print(getID()); 037 out.print(getDimsList()); 038 if (hasInit()) { 039 out.print(" = "); 040 out.print(getInit()); 041 } 042 } 043 /** 044 * @aspect VariableDeclarationTransformation 045 * @declaredat /home/jesper/git/extendj/java4/frontend/VariableDeclaration.jrag:173 046 */ 047 public VariableDeclaration createVariableDeclarationFrom(Modifiers modifiers, Access type) { 048 // TODO should treeCopy modifiers init opt etc??? 049 VariableDeclaration decl = new VariableDeclaration( 050 modifiers, 051 type.addArrayDims(getDimsList()), 052 getID(), 053 getInitOpt() 054 ); 055 decl.setStart(start); // copy location information 056 decl.setEnd(end); // copy location information 057 decl.IDstart = IDstart; 058 decl.IDend = IDend; 059 return decl; 060 } 061 /** 062 * @aspect VariableDeclarationTransformation 063 * @declaredat /home/jesper/git/extendj/java4/frontend/VariableDeclaration.jrag:188 064 */ 065 public FieldDeclaration createFieldDeclarationFrom(Modifiers modifiers, Access type) { 066 // TODO should treeCopy modifiers init opt etc??? 067 FieldDeclaration decl = new FieldDeclaration( 068 modifiers, 069 type.addArrayDims(getDimsList()), 070 getID(), 071 getInitOpt() 072 ); 073 decl.setStart(start); // copy location information 074 decl.setEnd(end); // copy location information 075 decl.IDstart = IDstart; 076 decl.IDend = IDend; 077 return decl; 078 } 079 /** 080 * @declaredat ASTNode:1 081 */ 082 public VariableDecl() { 083 super(); 084 } 085 /** 086 * Initializes the child array to the correct size. 087 * Initializes List and Opt nta children. 088 * @apilevel internal 089 * @ast method 090 * @declaredat ASTNode:10 091 */ 092 public void init$Children() { 093 children = new ASTNode[2]; 094 setChild(new List(), 0); 095 setChild(new Opt(), 1); 096 } 097 /** 098 * @declaredat ASTNode:15 099 */ 100 public VariableDecl(String p0, List<Dims> p1, Opt<Expr> p2) { 101 setID(p0); 102 setChild(p1, 0); 103 setChild(p2, 1); 104 } 105 /** 106 * @declaredat ASTNode:20 107 */ 108 public VariableDecl(beaver.Symbol p0, List<Dims> p1, Opt<Expr> p2) { 109 setID(p0); 110 setChild(p1, 0); 111 setChild(p2, 1); 112 } 113 /** 114 * @apilevel low-level 115 * @declaredat ASTNode:28 116 */ 117 protected int numChildren() { 118 return 2; 119 } 120 /** 121 * @apilevel internal 122 * @declaredat ASTNode:34 123 */ 124 public boolean mayHaveRewrite() { 125 return false; 126 } 127 /** 128 * @apilevel internal 129 * @declaredat ASTNode:40 130 */ 131 public void flushAttrCache() { 132 super.flushAttrCache(); 133 } 134 /** 135 * @apilevel internal 136 * @declaredat ASTNode:46 137 */ 138 public void flushCollectionCache() { 139 super.flushCollectionCache(); 140 } 141 /** 142 * @apilevel internal 143 * @declaredat ASTNode:52 144 */ 145 public void flushRewriteCache() { 146 super.flushRewriteCache(); 147 } 148 /** 149 * @apilevel internal 150 * @declaredat ASTNode:58 151 */ 152 public VariableDecl clone() throws CloneNotSupportedException { 153 VariableDecl node = (VariableDecl) super.clone(); 154 return node; 155 } 156 /** 157 * @apilevel internal 158 * @declaredat ASTNode:65 159 */ 160 public VariableDecl copy() { 161 try { 162 VariableDecl node = (VariableDecl) clone(); 163 node.parent = null; 164 if (children != null) { 165 node.children = (ASTNode[]) children.clone(); 166 } 167 return node; 168 } catch (CloneNotSupportedException e) { 169 throw new Error("Error: clone not supported for " + getClass().getName()); 170 } 171 } 172 /** 173 * Create a deep copy of the AST subtree at this node. 174 * The copy is dangling, i.e. has no parent. 175 * @return dangling copy of the subtree at this node 176 * @apilevel low-level 177 * @deprecated Please use treeCopy or treeCopyNoTransform instead 178 * @declaredat ASTNode:84 179 */ 180 @Deprecated 181 public VariableDecl fullCopy() { 182 return treeCopyNoTransform(); 183 } 184 /** 185 * Create a deep copy of the AST subtree at this node. 186 * The copy is dangling, i.e. has no parent. 187 * @return dangling copy of the subtree at this node 188 * @apilevel low-level 189 * @declaredat ASTNode:94 190 */ 191 public VariableDecl treeCopyNoTransform() { 192 VariableDecl tree = (VariableDecl) copy(); 193 if (children != null) { 194 for (int i = 0; i < children.length; ++i) { 195 ASTNode child = (ASTNode) children[i]; 196 if (child != null) { 197 child = child.treeCopyNoTransform(); 198 tree.setChild(child, i); 199 } 200 } 201 } 202 return tree; 203 } 204 /** 205 * Create a deep copy of the AST subtree at this node. 206 * The subtree of this node is traversed to trigger rewrites before copy. 207 * The copy is dangling, i.e. has no parent. 208 * @return dangling copy of the subtree at this node 209 * @apilevel low-level 210 * @declaredat ASTNode:114 211 */ 212 public VariableDecl treeCopy() { 213 doFullTraversal(); 214 return treeCopyNoTransform(); 215 } 216 /** 217 * @apilevel internal 218 * @declaredat ASTNode:121 219 */ 220 protected boolean is$Equal(ASTNode node) { 221 return super.is$Equal(node) && (tokenString_ID == ((VariableDecl)node).tokenString_ID); 222 } 223 /** 224 * Replaces the lexeme ID. 225 * @param value The new value for the lexeme ID. 226 * @apilevel high-level 227 */ 228 public void setID(String value) { 229 tokenString_ID = value; 230 } 231 /** 232 * @apilevel internal 233 */ 234 protected String tokenString_ID; 235 /** 236 */ 237 public int IDstart; 238 /** 239 */ 240 public int IDend; 241 /** 242 * JastAdd-internal setter for lexeme ID using the Beaver parser. 243 * @param symbol Symbol containing the new value for the lexeme ID 244 * @apilevel internal 245 */ 246 public void setID(beaver.Symbol symbol) { 247 if (symbol.value != null && !(symbol.value instanceof String)) 248 throw new UnsupportedOperationException("setID is only valid for String lexemes"); 249 tokenString_ID = (String)symbol.value; 250 IDstart = symbol.getStart(); 251 IDend = symbol.getEnd(); 252 } 253 /** 254 * Retrieves the value for the lexeme ID. 255 * @return The value for the lexeme ID. 256 * @apilevel high-level 257 */ 258 @ASTNodeAnnotation.Token(name="ID") 259 public String getID() { 260 return tokenString_ID != null ? tokenString_ID : ""; 261 } 262 /** 263 * Replaces the Dims list. 264 * @param list The new list node to be used as the Dims list. 265 * @apilevel high-level 266 */ 267 public void setDimsList(List<Dims> list) { 268 setChild(list, 0); 269 } 270 /** 271 * Retrieves the number of children in the Dims list. 272 * @return Number of children in the Dims list. 273 * @apilevel high-level 274 */ 275 public int getNumDims() { 276 return getDimsList().getNumChild(); 277 } 278 /** 279 * Retrieves the number of children in the Dims list. 280 * Calling this method will not trigger rewrites. 281 * @return Number of children in the Dims list. 282 * @apilevel low-level 283 */ 284 public int getNumDimsNoTransform() { 285 return getDimsListNoTransform().getNumChildNoTransform(); 286 } 287 /** 288 * Retrieves the element at index {@code i} in the Dims list. 289 * @param i Index of the element to return. 290 * @return The element at position {@code i} in the Dims list. 291 * @apilevel high-level 292 */ 293 public Dims getDims(int i) { 294 return (Dims) getDimsList().getChild(i); 295 } 296 /** 297 * Check whether the Dims list has any children. 298 * @return {@code true} if it has at least one child, {@code false} otherwise. 299 * @apilevel high-level 300 */ 301 public boolean hasDims() { 302 return getDimsList().getNumChild() != 0; 303 } 304 /** 305 * Append an element to the Dims list. 306 * @param node The element to append to the Dims list. 307 * @apilevel high-level 308 */ 309 public void addDims(Dims node) { 310 List<Dims> list = (parent == null) ? getDimsListNoTransform() : getDimsList(); 311 list.addChild(node); 312 } 313 /** 314 * @apilevel low-level 315 */ 316 public void addDimsNoTransform(Dims node) { 317 List<Dims> list = getDimsListNoTransform(); 318 list.addChild(node); 319 } 320 /** 321 * Replaces the Dims list element at index {@code i} with the new node {@code node}. 322 * @param node The new node to replace the old list element. 323 * @param i The list index of the node to be replaced. 324 * @apilevel high-level 325 */ 326 public void setDims(Dims node, int i) { 327 List<Dims> list = getDimsList(); 328 list.setChild(node, i); 329 } 330 /** 331 * Retrieves the Dims list. 332 * @return The node representing the Dims list. 333 * @apilevel high-level 334 */ 335 @ASTNodeAnnotation.ListChild(name="Dims") 336 public List<Dims> getDimsList() { 337 List<Dims> list = (List<Dims>) getChild(0); 338 return list; 339 } 340 /** 341 * Retrieves the Dims list. 342 * <p><em>This method does not invoke AST transformations.</em></p> 343 * @return The node representing the Dims list. 344 * @apilevel low-level 345 */ 346 public List<Dims> getDimsListNoTransform() { 347 return (List<Dims>) getChildNoTransform(0); 348 } 349 /** 350 * Retrieves the Dims list. 351 * @return The node representing the Dims list. 352 * @apilevel high-level 353 */ 354 public List<Dims> getDimss() { 355 return getDimsList(); 356 } 357 /** 358 * Retrieves the Dims list. 359 * <p><em>This method does not invoke AST transformations.</em></p> 360 * @return The node representing the Dims list. 361 * @apilevel low-level 362 */ 363 public List<Dims> getDimssNoTransform() { 364 return getDimsListNoTransform(); 365 } 366 /** 367 * Replaces the optional node for the Init child. This is the <code>Opt</code> 368 * node containing the child Init, not the actual child! 369 * @param opt The new node to be used as the optional node for the Init child. 370 * @apilevel low-level 371 */ 372 public void setInitOpt(Opt<Expr> opt) { 373 setChild(opt, 1); 374 } 375 /** 376 * Replaces the (optional) Init child. 377 * @param node The new node to be used as the Init child. 378 * @apilevel high-level 379 */ 380 public void setInit(Expr node) { 381 getInitOpt().setChild(node, 0); 382 } 383 /** 384 * Check whether the optional Init child exists. 385 * @return {@code true} if the optional Init child exists, {@code false} if it does not. 386 * @apilevel high-level 387 */ 388 public boolean hasInit() { 389 return getInitOpt().getNumChild() != 0; 390 } 391 /** 392 * Retrieves the (optional) Init child. 393 * @return The Init child, if it exists. Returns {@code null} otherwise. 394 * @apilevel low-level 395 */ 396 public Expr getInit() { 397 return (Expr) getInitOpt().getChild(0); 398 } 399 /** 400 * Retrieves the optional node for the Init child. This is the <code>Opt</code> node containing the child Init, not the actual child! 401 * @return The optional node for child the Init child. 402 * @apilevel low-level 403 */ 404 @ASTNodeAnnotation.OptChild(name="Init") 405 public Opt<Expr> getInitOpt() { 406 return (Opt<Expr>) getChild(1); 407 } 408 /** 409 * Retrieves the optional node for child Init. This is the <code>Opt</code> node containing the child Init, not the actual child! 410 * <p><em>This method does not invoke AST transformations.</em></p> 411 * @return The optional node for child Init. 412 * @apilevel low-level 413 */ 414 public Opt<Expr> getInitOptNoTransform() { 415 return (Opt<Expr>) getChildNoTransform(1); 416 } 417 /** 418 * @attribute syn 419 * @aspect Variables 420 * @declaredat /home/jesper/git/extendj/java4/frontend/VariableDeclaration.jrag:105 421 */ 422 @ASTNodeAnnotation.Attribute 423 public String name() { 424 String name_value = getID(); 425 426 return name_value; 427 } 428 /** 429 * @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:47 430 * @apilevel internal 431 */ 432 public boolean Define_isSource(ASTNode caller, ASTNode child) { 433 if (caller == getInitOptNoTransform()) { 434 // @declaredat /home/jesper/git/extendj/java4/frontend/DefiniteAssignment.jrag:63 435 return true; 436 } 437 else { 438 return getParent().Define_isSource(this, caller); 439 } 440 } 441 protected boolean canDefine_isSource(ASTNode caller, ASTNode child) { 442 return true; 443 } 444 /** 445 * @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:93 446 * @apilevel internal 447 */ 448 public TypeDecl Define_expectedType(ASTNode caller, ASTNode child) { 449 if (caller == getInitOptNoTransform()) { 450 // @declaredat /home/jesper/git/extendj/java4/backend/InnerClasses.jrag:100 451 return null; 452 } 453 else { 454 return getParent().Define_expectedType(this, caller); 455 } 456 } 457 protected boolean canDefine_expectedType(ASTNode caller, ASTNode child) { 458 return true; 459 } 460 /** 461 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:196 462 * @apilevel internal 463 */ 464 public boolean Define_assignmentContext(ASTNode caller, ASTNode child) { 465 if (caller == getInitOptNoTransform()) { 466 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:361 467 return true; 468 } 469 else { 470 return getParent().Define_assignmentContext(this, caller); 471 } 472 } 473 protected boolean canDefine_assignmentContext(ASTNode caller, ASTNode child) { 474 return true; 475 } 476 /** 477 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:197 478 * @apilevel internal 479 */ 480 public boolean Define_invocationContext(ASTNode caller, ASTNode child) { 481 if (caller == getInitOptNoTransform()) { 482 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:362 483 return false; 484 } 485 else { 486 return getParent().Define_invocationContext(this, caller); 487 } 488 } 489 protected boolean canDefine_invocationContext(ASTNode caller, ASTNode child) { 490 return true; 491 } 492 /** 493 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:198 494 * @apilevel internal 495 */ 496 public boolean Define_castContext(ASTNode caller, ASTNode child) { 497 if (caller == getInitOptNoTransform()) { 498 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:363 499 return false; 500 } 501 else { 502 return getParent().Define_castContext(this, caller); 503 } 504 } 505 protected boolean canDefine_castContext(ASTNode caller, ASTNode child) { 506 return true; 507 } 508 /** 509 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:199 510 * @apilevel internal 511 */ 512 public boolean Define_stringContext(ASTNode caller, ASTNode child) { 513 if (caller == getInitOptNoTransform()) { 514 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:364 515 return false; 516 } 517 else { 518 return getParent().Define_stringContext(this, caller); 519 } 520 } 521 protected boolean canDefine_stringContext(ASTNode caller, ASTNode child) { 522 return true; 523 } 524 /** 525 * @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:200 526 * @apilevel internal 527 */ 528 public boolean Define_numericContext(ASTNode caller, ASTNode child) { 529 if (caller == getInitOptNoTransform()) { 530 // @declaredat /home/jesper/git/extendj/java8/frontend/TargetType.jrag:365 531 return false; 532 } 533 else { 534 return getParent().Define_numericContext(this, caller); 535 } 536 } 537 protected boolean canDefine_numericContext(ASTNode caller, ASTNode child) { 538 return true; 539 } 540 /** 541 * @apilevel internal 542 */ 543 public ASTNode rewriteTo() { 544 return super.rewriteTo(); 545 } 546 }