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 * String literal. 026 * May not contain Unicode escape sequences (Unicode escapes 027 * are transcoded by the scanner). 028 * @ast node 029 * @declaredat /home/jesper/git/extendj/java7/grammar/Literals.ast:37 030 * @production StringLiteral : {@link Literal}; 031 032 */ 033 public class StringLiteral extends Literal implements Cloneable { 034 /** 035 * @aspect Java4PrettyPrint 036 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrint.jadd:470 037 */ 038 public void prettyPrint(PrettyPrinter out) { 039 out.print("\""); 040 out.print(escapedLiteral()); 041 out.print("\""); 042 } 043 /** 044 * @aspect CodeGeneration 045 * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:156 046 */ 047 public static void push(CodeGeneration gen, String value) { 048 int index = gen.constantPool().addConstant(value); 049 if (index < 256) { 050 gen.emit(Bytecode.LDC).add(index); 051 } else { 052 gen.emit(Bytecode.LDC_W).add2(index); 053 } 054 } 055 /** 056 * @aspect CodeGeneration 057 * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:201 058 */ 059 public void emitPushConstant(CodeGeneration gen) { 060 StringLiteral.push(gen, getLITERAL()); 061 } 062 /** 063 * @declaredat ASTNode:1 064 */ 065 public StringLiteral() { 066 super(); 067 } 068 /** 069 * Initializes the child array to the correct size. 070 * Initializes List and Opt nta children. 071 * @apilevel internal 072 * @ast method 073 * @declaredat ASTNode:10 074 */ 075 public void init$Children() { 076 } 077 /** 078 * @declaredat ASTNode:12 079 */ 080 public StringLiteral(String p0) { 081 setLITERAL(p0); 082 } 083 /** 084 * @declaredat ASTNode:15 085 */ 086 public StringLiteral(beaver.Symbol p0) { 087 setLITERAL(p0); 088 } 089 /** 090 * @apilevel low-level 091 * @declaredat ASTNode:21 092 */ 093 protected int numChildren() { 094 return 0; 095 } 096 /** 097 * @apilevel internal 098 * @declaredat ASTNode:27 099 */ 100 public boolean mayHaveRewrite() { 101 return false; 102 } 103 /** 104 * @apilevel internal 105 * @declaredat ASTNode:33 106 */ 107 public void flushAttrCache() { 108 super.flushAttrCache(); 109 constant_reset(); 110 type_reset(); 111 } 112 /** 113 * @apilevel internal 114 * @declaredat ASTNode:41 115 */ 116 public void flushCollectionCache() { 117 super.flushCollectionCache(); 118 } 119 /** 120 * @apilevel internal 121 * @declaredat ASTNode:47 122 */ 123 public void flushRewriteCache() { 124 super.flushRewriteCache(); 125 } 126 /** 127 * @apilevel internal 128 * @declaredat ASTNode:53 129 */ 130 public StringLiteral clone() throws CloneNotSupportedException { 131 StringLiteral node = (StringLiteral) super.clone(); 132 return node; 133 } 134 /** 135 * @apilevel internal 136 * @declaredat ASTNode:60 137 */ 138 public StringLiteral copy() { 139 try { 140 StringLiteral node = (StringLiteral) clone(); 141 node.parent = null; 142 if (children != null) { 143 node.children = (ASTNode[]) children.clone(); 144 } 145 return node; 146 } catch (CloneNotSupportedException e) { 147 throw new Error("Error: clone not supported for " + getClass().getName()); 148 } 149 } 150 /** 151 * Create a deep copy of the AST subtree at this node. 152 * The copy is dangling, i.e. has no parent. 153 * @return dangling copy of the subtree at this node 154 * @apilevel low-level 155 * @deprecated Please use treeCopy or treeCopyNoTransform instead 156 * @declaredat ASTNode:79 157 */ 158 @Deprecated 159 public StringLiteral fullCopy() { 160 return treeCopyNoTransform(); 161 } 162 /** 163 * Create a deep copy of the AST subtree at this node. 164 * The copy is dangling, i.e. has no parent. 165 * @return dangling copy of the subtree at this node 166 * @apilevel low-level 167 * @declaredat ASTNode:89 168 */ 169 public StringLiteral treeCopyNoTransform() { 170 StringLiteral tree = (StringLiteral) copy(); 171 if (children != null) { 172 for (int i = 0; i < children.length; ++i) { 173 ASTNode child = (ASTNode) children[i]; 174 if (child != null) { 175 child = child.treeCopyNoTransform(); 176 tree.setChild(child, i); 177 } 178 } 179 } 180 return tree; 181 } 182 /** 183 * Create a deep copy of the AST subtree at this node. 184 * The subtree of this node is traversed to trigger rewrites before copy. 185 * The copy is dangling, i.e. has no parent. 186 * @return dangling copy of the subtree at this node 187 * @apilevel low-level 188 * @declaredat ASTNode:109 189 */ 190 public StringLiteral treeCopy() { 191 doFullTraversal(); 192 return treeCopyNoTransform(); 193 } 194 /** 195 * @apilevel internal 196 * @declaredat ASTNode:116 197 */ 198 protected boolean is$Equal(ASTNode node) { 199 return super.is$Equal(node) && (tokenString_LITERAL == ((StringLiteral)node).tokenString_LITERAL); 200 } 201 /** 202 * Replaces the lexeme LITERAL. 203 * @param value The new value for the lexeme LITERAL. 204 * @apilevel high-level 205 */ 206 public void setLITERAL(String value) { 207 tokenString_LITERAL = value; 208 } 209 /** 210 * JastAdd-internal setter for lexeme LITERAL using the Beaver parser. 211 * @param symbol Symbol containing the new value for the lexeme LITERAL 212 * @apilevel internal 213 */ 214 public void setLITERAL(beaver.Symbol symbol) { 215 if (symbol.value != null && !(symbol.value instanceof String)) 216 throw new UnsupportedOperationException("setLITERAL is only valid for String lexemes"); 217 tokenString_LITERAL = (String)symbol.value; 218 LITERALstart = symbol.getStart(); 219 LITERALend = symbol.getEnd(); 220 } 221 /** 222 * Retrieves the value for the lexeme LITERAL. 223 * @return The value for the lexeme LITERAL. 224 * @apilevel high-level 225 */ 226 @ASTNodeAnnotation.Token(name="LITERAL") 227 public String getLITERAL() { 228 return tokenString_LITERAL != null ? tokenString_LITERAL : ""; 229 } 230 /** 231 * @apilevel internal 232 */ 233 protected boolean constant_computed = false; 234 /** 235 * @apilevel internal 236 */ 237 protected Constant constant_value; 238 /** 239 * @apilevel internal 240 */ 241 private void constant_reset() { 242 constant_computed = false; 243 constant_value = null; 244 } 245 /** 246 * @attribute syn 247 * @aspect ConstantExpression 248 * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:37 249 */ 250 @ASTNodeAnnotation.Attribute 251 public Constant constant() { 252 ASTNode$State state = state(); 253 if (constant_computed) { 254 return constant_value; 255 } 256 boolean intermediate = state.INTERMEDIATE_VALUE; 257 state.INTERMEDIATE_VALUE = false; 258 int num = state.boundariesCrossed; 259 boolean isFinal = this.is$Final(); 260 constant_value = Constant.create(getLITERAL()); 261 if (isFinal && num == state().boundariesCrossed) { 262 constant_computed = true; 263 } else { 264 } 265 state.INTERMEDIATE_VALUE |= intermediate; 266 267 return constant_value; 268 } 269 /** 270 * @attribute syn 271 * @aspect PrettyPrintUtil 272 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:263 273 */ 274 @ASTNodeAnnotation.Attribute 275 public String escapedLiteral() { 276 String escapedLiteral_value = escape(getLITERAL()); 277 278 return escapedLiteral_value; 279 } 280 /** 281 * @apilevel internal 282 */ 283 protected boolean type_computed = false; 284 /** 285 * @apilevel internal 286 */ 287 protected TypeDecl type_value; 288 /** 289 * @apilevel internal 290 */ 291 private void type_reset() { 292 type_computed = false; 293 type_value = null; 294 } 295 /** 296 * @attribute syn 297 * @aspect TypeAnalysis 298 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302 299 */ 300 @ASTNodeAnnotation.Attribute 301 public TypeDecl type() { 302 ASTNode$State state = state(); 303 if (type_computed) { 304 return type_value; 305 } 306 boolean intermediate = state.INTERMEDIATE_VALUE; 307 state.INTERMEDIATE_VALUE = false; 308 int num = state.boundariesCrossed; 309 boolean isFinal = this.is$Final(); 310 type_value = typeString(); 311 if (isFinal && num == state().boundariesCrossed) { 312 type_computed = true; 313 } else { 314 } 315 state.INTERMEDIATE_VALUE |= intermediate; 316 317 return type_value; 318 } 319 /** 320 * @apilevel internal 321 */ 322 public ASTNode rewriteTo() { 323 return super.rewriteTo(); 324 } 325 }