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