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 * Java long integer literal. Can store any number that fits in 64 bits 026 * of data, or less. 027 * @ast node 028 * @declaredat /home/jesper/git/extendj/java7/grammar/Literals.ast:54 029 * @production LongLiteral : {@link NumericLiteral}; 030 031 */ 032 public class LongLiteral extends NumericLiteral implements Cloneable { 033 /** 034 * @aspect CodeGeneration 035 * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:120 036 */ 037 public static void push(CodeGeneration gen, long value) { 038 if (value == 0) { 039 gen.emit(Bytecode.LCONST_0); 040 } else if (value == 1) { 041 gen.emit(Bytecode.LCONST_1); 042 } else { 043 int index = gen.constantPool().addConstant(value); 044 gen.emit(Bytecode.LDC2_W).add2(index); 045 } 046 } 047 /** 048 * @aspect CodeGeneration 049 * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:193 050 */ 051 public void emitPushConstant(CodeGeneration gen) { 052 LongLiteral.push(gen, constant().longValue()); 053 } 054 /** 055 * @declaredat ASTNode:1 056 */ 057 public LongLiteral() { 058 super(); 059 } 060 /** 061 * Initializes the child array to the correct size. 062 * Initializes List and Opt nta children. 063 * @apilevel internal 064 * @ast method 065 * @declaredat ASTNode:10 066 */ 067 public void init$Children() { 068 } 069 /** 070 * @declaredat ASTNode:12 071 */ 072 public LongLiteral(String p0) { 073 setLITERAL(p0); 074 } 075 /** 076 * @declaredat ASTNode:15 077 */ 078 public LongLiteral(beaver.Symbol p0) { 079 setLITERAL(p0); 080 } 081 /** 082 * @apilevel low-level 083 * @declaredat ASTNode:21 084 */ 085 protected int numChildren() { 086 return 0; 087 } 088 /** 089 * @apilevel internal 090 * @declaredat ASTNode:27 091 */ 092 public boolean mayHaveRewrite() { 093 return true; 094 } 095 /** 096 * @apilevel internal 097 * @declaredat ASTNode:33 098 */ 099 public void flushAttrCache() { 100 super.flushAttrCache(); 101 type_reset(); 102 constant_reset(); 103 } 104 /** 105 * @apilevel internal 106 * @declaredat ASTNode:41 107 */ 108 public void flushCollectionCache() { 109 super.flushCollectionCache(); 110 } 111 /** 112 * @apilevel internal 113 * @declaredat ASTNode:47 114 */ 115 public void flushRewriteCache() { 116 super.flushRewriteCache(); 117 } 118 /** 119 * @apilevel internal 120 * @declaredat ASTNode:53 121 */ 122 public LongLiteral clone() throws CloneNotSupportedException { 123 LongLiteral node = (LongLiteral) super.clone(); 124 return node; 125 } 126 /** 127 * @apilevel internal 128 * @declaredat ASTNode:60 129 */ 130 public LongLiteral copy() { 131 try { 132 LongLiteral node = (LongLiteral) clone(); 133 node.parent = null; 134 if (children != null) { 135 node.children = (ASTNode[]) children.clone(); 136 } 137 return node; 138 } catch (CloneNotSupportedException e) { 139 throw new Error("Error: clone not supported for " + getClass().getName()); 140 } 141 } 142 /** 143 * Create a deep copy of the AST subtree at this node. 144 * The copy is dangling, i.e. has no parent. 145 * @return dangling copy of the subtree at this node 146 * @apilevel low-level 147 * @deprecated Please use treeCopy or treeCopyNoTransform instead 148 * @declaredat ASTNode:79 149 */ 150 @Deprecated 151 public LongLiteral fullCopy() { 152 return treeCopyNoTransform(); 153 } 154 /** 155 * Create a deep copy of the AST subtree at this node. 156 * The copy is dangling, i.e. has no parent. 157 * @return dangling copy of the subtree at this node 158 * @apilevel low-level 159 * @declaredat ASTNode:89 160 */ 161 public LongLiteral treeCopyNoTransform() { 162 LongLiteral tree = (LongLiteral) copy(); 163 if (children != null) { 164 for (int i = 0; i < children.length; ++i) { 165 ASTNode child = (ASTNode) children[i]; 166 if (child != null) { 167 child = child.treeCopyNoTransform(); 168 tree.setChild(child, i); 169 } 170 } 171 } 172 return tree; 173 } 174 /** 175 * Create a deep copy of the AST subtree at this node. 176 * The subtree of this node is traversed to trigger rewrites before copy. 177 * The copy is dangling, i.e. has no parent. 178 * @return dangling copy of the subtree at this node 179 * @apilevel low-level 180 * @declaredat ASTNode:109 181 */ 182 public LongLiteral treeCopy() { 183 doFullTraversal(); 184 return treeCopyNoTransform(); 185 } 186 /** 187 * @apilevel internal 188 * @declaredat ASTNode:116 189 */ 190 protected boolean is$Equal(ASTNode node) { 191 return super.is$Equal(node) && (tokenString_LITERAL == ((LongLiteral)node).tokenString_LITERAL); 192 } 193 /** 194 * Replaces the lexeme LITERAL. 195 * @param value The new value for the lexeme LITERAL. 196 * @apilevel high-level 197 */ 198 public void setLITERAL(String value) { 199 tokenString_LITERAL = value; 200 } 201 /** 202 * JastAdd-internal setter for lexeme LITERAL using the Beaver parser. 203 * @param symbol Symbol containing the new value for the lexeme LITERAL 204 * @apilevel internal 205 */ 206 public void setLITERAL(beaver.Symbol symbol) { 207 if (symbol.value != null && !(symbol.value instanceof String)) 208 throw new UnsupportedOperationException("setLITERAL is only valid for String lexemes"); 209 tokenString_LITERAL = (String)symbol.value; 210 LITERALstart = symbol.getStart(); 211 LITERALend = symbol.getEnd(); 212 } 213 /** 214 * Retrieves the value for the lexeme LITERAL. 215 * @return The value for the lexeme LITERAL. 216 * @apilevel high-level 217 */ 218 @ASTNodeAnnotation.Token(name="LITERAL") 219 public String getLITERAL() { 220 return tokenString_LITERAL != null ? tokenString_LITERAL : ""; 221 } 222 /** 223 * Defer pretty printing to superclass. 224 * @aspect Java7Literals 225 * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:124 226 */ 227 public void prettyPrint(PrettyPrinter out) { 228 super.prettyPrint(out); 229 } 230 /** 231 * Check for and report literal-out-of-bounds error. 232 * If the constant is error-marked, there exists a literal out of bounds error. 233 * @aspect Java7Literals 234 * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:157 235 */ 236 public void typeCheck() { 237 if (constant().error) { 238 errorf("The integer literal \"%s\" is too large for type long.", getLITERAL()); 239 } 240 } 241 /** 242 * @attribute syn 243 * @aspect PositiveLiterals 244 * @declaredat /home/jesper/git/extendj/java4/frontend/PositiveLiterals.jrag:36 245 */ 246 @ASTNodeAnnotation.Attribute 247 public boolean isPositive() { 248 boolean isPositive_value = !getLITERAL().startsWith("-"); 249 250 return isPositive_value; 251 } 252 /** 253 * @apilevel internal 254 */ 255 protected boolean type_computed = false; 256 /** 257 * @apilevel internal 258 */ 259 protected TypeDecl type_value; 260 /** 261 * @apilevel internal 262 */ 263 private void type_reset() { 264 type_computed = false; 265 type_value = null; 266 } 267 /** 268 * @attribute syn 269 * @aspect TypeAnalysis 270 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302 271 */ 272 @ASTNodeAnnotation.Attribute 273 public TypeDecl type() { 274 ASTNode$State state = state(); 275 if (type_computed) { 276 return type_value; 277 } 278 boolean intermediate = state.INTERMEDIATE_VALUE; 279 state.INTERMEDIATE_VALUE = false; 280 int num = state.boundariesCrossed; 281 boolean isFinal = this.is$Final(); 282 type_value = typeLong(); 283 if (isFinal && num == state().boundariesCrossed) { 284 type_computed = true; 285 } else { 286 } 287 state.INTERMEDIATE_VALUE |= intermediate; 288 289 return type_value; 290 } 291 /** 292 * @apilevel internal 293 */ 294 protected boolean constant_computed = false; 295 /** 296 * @apilevel internal 297 */ 298 protected Constant constant_value; 299 /** 300 * @apilevel internal 301 */ 302 private void constant_reset() { 303 constant_computed = false; 304 constant_value = null; 305 } 306 /** 307 * @attribute syn 308 * @aspect ConstantExpression 309 * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:37 310 */ 311 @ASTNodeAnnotation.Attribute 312 public Constant constant() { 313 ASTNode$State state = state(); 314 if (constant_computed) { 315 return constant_value; 316 } 317 boolean intermediate = state.INTERMEDIATE_VALUE; 318 state.INTERMEDIATE_VALUE = false; 319 int num = state.boundariesCrossed; 320 boolean isFinal = this.is$Final(); 321 constant_value = constant_compute(); 322 if (isFinal && num == state().boundariesCrossed) { 323 constant_computed = true; 324 } else { 325 } 326 state.INTERMEDIATE_VALUE |= intermediate; 327 328 return constant_value; 329 } 330 /** 331 * @apilevel internal 332 */ 333 private Constant constant_compute() { 334 try { 335 return Constant.create(parseLong()); 336 } catch (NumberFormatException e) { 337 Constant c = Constant.create(0L); 338 c.error = true; 339 return c; 340 } 341 } 342 /** 343 * Utility attribute for literal rewriting. 344 * Any of the NumericLiteral subclasses have already 345 * been rewritten and/or parsed, and should not be 346 * rewritten again. 347 * 348 * @return true if this literal is a "raw", not-yet-parsed NumericLiteral 349 * @attribute syn 350 * @aspect Java7Literals 351 * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:373 352 */ 353 @ASTNodeAnnotation.Attribute 354 public boolean needsRewrite() { 355 boolean needsRewrite_value = false; 356 357 return needsRewrite_value; 358 } 359 /** 360 * @apilevel internal 361 */ 362 public ASTNode rewriteTo() { 363 return super.rewriteTo(); 364 } 365 }