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 * The abstract base class for all literals. 015 * @production Literal : {@link PrimaryExpr} ::= <span class="component"><LITERAL:String></span>; 016 * @ast node 017 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.ast:4 018 */ 019 public abstract class Literal extends PrimaryExpr 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 Literal clone() throws CloneNotSupportedException { 035 Literal node = (Literal)super.clone(); 036 node.constant_computed = false; 037 node.constant_value = null; 038 node.in$Circle(false); 039 node.is$Final(false); 040 return node; 041 } 042 /** 043 * @ast method 044 * @aspect BytecodeCONSTANT 045 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/BytecodeCONSTANT.jrag:75 046 */ 047 public static Literal buildBooleanLiteral(boolean value) { 048 return new BooleanLiteral(value ? "true" : "false"); 049 } 050 /** 051 * @ast method 052 * @aspect BytecodeCONSTANT 053 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/BytecodeCONSTANT.jrag:79 054 */ 055 public static Literal buildStringLiteral(String value) { 056 return new StringLiteral(value); 057 } 058 /** 059 * @ast method 060 * @aspect PrettyPrint 061 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:263 062 */ 063 public void toString(StringBuffer s) { 064 s.append(getLITERAL()); 065 } 066 /** 067 * @ast method 068 * @aspect PrettyPrint 069 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:290 070 */ 071 protected static String escape(String s) { 072 StringBuffer result = new StringBuffer(); 073 for (int i=0; i < s.length(); i++) { 074 switch(s.charAt(i)) { 075 case '\b' : result.append("\\b"); break; 076 case '\t' : result.append("\\t"); break; 077 case '\n' : result.append("\\n"); break; 078 case '\f' : result.append("\\f"); break; 079 case '\r' : result.append("\\r"); break; 080 case '\"' : result.append("\\\""); break; 081 case '\'' : result.append("\\\'"); break; 082 case '\\' : result.append("\\\\"); break; 083 default: 084 int value = (int)s.charAt(i); 085 if(value < 0x20 || (value > 0x7e)) 086 result.append(asEscape(value)); 087 else 088 result.append(s.charAt(i)); 089 } 090 } 091 return result.toString(); 092 } 093 /** 094 * @ast method 095 * @aspect PrettyPrint 096 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:312 097 */ 098 protected static String asEscape(int value) { 099 StringBuffer s = new StringBuffer("\\u"); 100 String hex = Integer.toHexString(value); 101 for(int i = 0; i < 4-hex.length(); i++) 102 s.append("0"); 103 s.append(hex); 104 return s.toString(); 105 } 106 /** 107 * @ast method 108 * @aspect CodeGeneration 109 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CodeGeneration.jrag:550 110 */ 111 public void emitPushConstant(CodeGeneration gen) { 112 System.out.println("ERROR: Tried to generate bytecode for: " + getClass().getName()); 113 } 114 /** 115 * @ast method 116 * @aspect CreateBCode 117 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Backend/CreateBCode.jrag:207 118 */ 119 public void createBCode(CodeGeneration gen) { 120 emitPushConstant(gen); 121 } 122 /** 123 * @ast method 124 * 125 */ 126 public Literal() { 127 super(); 128 129 130 } 131 /** 132 * Initializes the child array to the correct size. 133 * Initializes List and Opt nta children. 134 * @apilevel internal 135 * @ast method 136 * @ast method 137 * 138 */ 139 public void init$Children() { 140 } 141 /** 142 * @ast method 143 * 144 */ 145 public Literal(String p0) { 146 setLITERAL(p0); 147 } 148 /** 149 * @ast method 150 * 151 */ 152 public Literal(beaver.Symbol p0) { 153 setLITERAL(p0); 154 } 155 /** 156 * @apilevel low-level 157 * @ast method 158 * 159 */ 160 protected int numChildren() { 161 return 0; 162 } 163 /** 164 * @apilevel internal 165 * @ast method 166 * 167 */ 168 public boolean mayHaveRewrite() { 169 return false; 170 } 171 /** 172 * Replaces the lexeme LITERAL. 173 * @param value The new value for the lexeme LITERAL. 174 * @apilevel high-level 175 * @ast method 176 * 177 */ 178 public void setLITERAL(String value) { 179 tokenString_LITERAL = value; 180 } 181 /** 182 * @apilevel internal 183 * @ast method 184 * 185 */ 186 187 /** 188 * @apilevel internal 189 */ 190 protected String tokenString_LITERAL; 191 /** 192 * @ast method 193 * 194 */ 195 196 public int LITERALstart; 197 /** 198 * @ast method 199 * 200 */ 201 202 public int LITERALend; 203 /** 204 * JastAdd-internal setter for lexeme LITERAL using the Beaver parser. 205 * @apilevel internal 206 * @ast method 207 * 208 */ 209 public void setLITERAL(beaver.Symbol symbol) { 210 if(symbol.value != null && !(symbol.value instanceof String)) 211 throw new UnsupportedOperationException("setLITERAL is only valid for String lexemes"); 212 tokenString_LITERAL = (String)symbol.value; 213 LITERALstart = symbol.getStart(); 214 LITERALend = symbol.getEnd(); 215 } 216 /** 217 * Retrieves the value for the lexeme LITERAL. 218 * @return The value for the lexeme LITERAL. 219 * @apilevel high-level 220 * @ast method 221 * 222 */ 223 public String getLITERAL() { 224 return tokenString_LITERAL != null ? tokenString_LITERAL : ""; 225 } 226 /** 227 * @return a fresh double literal representing the given value 228 * @ast method 229 * @aspect Literals 230 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:50 231 */ 232 public static Literal buildDoubleLiteral(double value) { 233 String digits = Double.toString(value); 234 NumericLiteral lit = new DoubleLiteral(digits); 235 lit.setDigits(digits); 236 lit.setKind(NumericLiteral.DECIMAL); 237 return lit; 238 } 239 /** 240 * @return a fresh float literal representing the given value 241 * @ast method 242 * @aspect Literals 243 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:62 244 */ 245 public static Literal buildFloatLiteral(float value) { 246 String digits = Float.toString(value); 247 NumericLiteral lit = new FloatingPointLiteral(digits); 248 lit.setDigits(digits); 249 lit.setKind(NumericLiteral.DECIMAL); 250 return lit; 251 } 252 /** 253 * @return a fresh integer literal representing the given value 254 * @ast method 255 * @aspect Literals 256 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:74 257 */ 258 public static Literal buildIntegerLiteral(int value) { 259 String digits = Integer.toHexString(value); 260 NumericLiteral lit = new IntegerLiteral("0x"+digits); 261 lit.setDigits(digits.toLowerCase()); 262 lit.setKind(NumericLiteral.HEXADECIMAL); 263 return lit; 264 } 265 /** 266 * @return a fresh long literal representing the given value 267 * @ast method 268 * @aspect Literals 269 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/Literals.jrag:86 270 */ 271 public static Literal buildLongLiteral(long value) { 272 String digits = Long.toHexString(value); 273 NumericLiteral lit = new LongLiteral("0x"+digits); 274 lit.setDigits(digits.toLowerCase()); 275 lit.setKind(NumericLiteral.HEXADECIMAL); 276 return lit; 277 } 278 /** 279 * @apilevel internal 280 */ 281 protected boolean constant_computed = false; 282 /** 283 * @apilevel internal 284 */ 285 protected Constant constant_value; 286 /** 287 * @attribute syn 288 * @aspect ConstantExpression 289 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/ConstantExpression.jrag:96 290 */ 291 @SuppressWarnings({"unchecked", "cast"}) 292 public Constant constant() { 293 if(constant_computed) { 294 return constant_value; 295 } 296 ASTNode$State state = state(); 297 int num = state.boundariesCrossed; 298 boolean isFinal = this.is$Final(); 299 constant_value = constant_compute(); 300 if(isFinal && num == state().boundariesCrossed){ constant_computed = true; } 301 return constant_value; 302 } 303 /** 304 * @apilevel internal 305 */ 306 private Constant constant_compute() { 307 throw new UnsupportedOperationException("ConstantExpression operation constant" + 308 " not supported for type " + getClass().getName()); 309 } 310 /** 311 * @attribute syn 312 * @aspect ConstantExpression 313 * @declaredat /home/jesper/svn/JastAddJ/Java7Frontend/ConstantExpression.jrag:336 314 */ 315 public boolean isConstant() { 316 ASTNode$State state = state(); 317 try { return true; } 318 finally { 319 } 320 } 321 /** 322 * @attribute syn 323 * @aspect PrettyPrint 324 * @declaredat /home/jesper/svn/JastAddJ/Java1.4Frontend/PrettyPrint.jadd:800 325 */ 326 public String dumpString() { 327 ASTNode$State state = state(); 328 try { return getClass().getName() + " [" + getLITERAL() + "]"; } 329 finally { 330 } 331 } 332 /** 333 * @apilevel internal 334 */ 335 public ASTNode rewriteTo() { 336 return super.rewriteTo(); 337 } 338 }