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