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 * @ast node 026 * @declaredat /home/jesper/git/extendj/java4/grammar/Java.ast:136 027 * @production MinusExpr : {@link Unary}; 028 029 */ 030 public class MinusExpr extends Unary implements Cloneable { 031 /** 032 * @aspect TypeCheck 033 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeCheck.jrag:324 034 */ 035 public void typeCheck() { 036 if (!getOperand().type().isNumericType()) { 037 error("unary minus only operates on numeric types"); 038 } 039 } 040 /** 041 * @aspect CodeGenerationBinaryOperations 042 * @declaredat /home/jesper/git/extendj/java4/backend/CodeGeneration.jrag:656 043 */ 044 void emitOperation(CodeGeneration gen) { type().neg(gen); } 045 /** 046 * @aspect AutoBoxingCodegen 047 * @declaredat /home/jesper/git/extendj/java5/backend/AutoBoxingCodegen.jrag:355 048 */ 049 public void createBCode(CodeGeneration gen) { boxingGen(gen); } 050 /** 051 * @declaredat ASTNode:1 052 */ 053 public MinusExpr() { 054 super(); 055 } 056 /** 057 * Initializes the child array to the correct size. 058 * Initializes List and Opt nta children. 059 * @apilevel internal 060 * @ast method 061 * @declaredat ASTNode:10 062 */ 063 public void init$Children() { 064 children = new ASTNode[1]; 065 } 066 /** 067 * @declaredat ASTNode:13 068 */ 069 public MinusExpr(Expr p0) { 070 setChild(p0, 0); 071 } 072 /** 073 * @apilevel low-level 074 * @declaredat ASTNode:19 075 */ 076 protected int numChildren() { 077 return 1; 078 } 079 /** 080 * @apilevel internal 081 * @declaredat ASTNode:25 082 */ 083 public boolean mayHaveRewrite() { 084 return true; 085 } 086 /** 087 * @apilevel internal 088 * @declaredat ASTNode:31 089 */ 090 public void flushAttrCache() { 091 super.flushAttrCache(); 092 type_reset(); 093 } 094 /** 095 * @apilevel internal 096 * @declaredat ASTNode:38 097 */ 098 public void flushCollectionCache() { 099 super.flushCollectionCache(); 100 } 101 /** 102 * @apilevel internal 103 * @declaredat ASTNode:44 104 */ 105 public void flushRewriteCache() { 106 super.flushRewriteCache(); 107 } 108 /** 109 * @apilevel internal 110 * @declaredat ASTNode:50 111 */ 112 public MinusExpr clone() throws CloneNotSupportedException { 113 MinusExpr node = (MinusExpr) super.clone(); 114 return node; 115 } 116 /** 117 * @apilevel internal 118 * @declaredat ASTNode:57 119 */ 120 public MinusExpr copy() { 121 try { 122 MinusExpr node = (MinusExpr) clone(); 123 node.parent = null; 124 if (children != null) { 125 node.children = (ASTNode[]) children.clone(); 126 } 127 return node; 128 } catch (CloneNotSupportedException e) { 129 throw new Error("Error: clone not supported for " + getClass().getName()); 130 } 131 } 132 /** 133 * Create a deep copy of the AST subtree at this node. 134 * The copy is dangling, i.e. has no parent. 135 * @return dangling copy of the subtree at this node 136 * @apilevel low-level 137 * @deprecated Please use treeCopy or treeCopyNoTransform instead 138 * @declaredat ASTNode:76 139 */ 140 @Deprecated 141 public MinusExpr fullCopy() { 142 return treeCopyNoTransform(); 143 } 144 /** 145 * Create a deep copy of the AST subtree at this node. 146 * The copy is dangling, i.e. has no parent. 147 * @return dangling copy of the subtree at this node 148 * @apilevel low-level 149 * @declaredat ASTNode:86 150 */ 151 public MinusExpr treeCopyNoTransform() { 152 MinusExpr tree = (MinusExpr) copy(); 153 if (children != null) { 154 for (int i = 0; i < children.length; ++i) { 155 ASTNode child = (ASTNode) children[i]; 156 if (child != null) { 157 child = child.treeCopyNoTransform(); 158 tree.setChild(child, i); 159 } 160 } 161 } 162 return tree; 163 } 164 /** 165 * Create a deep copy of the AST subtree at this node. 166 * The subtree of this node is traversed to trigger rewrites before copy. 167 * The copy is dangling, i.e. has no parent. 168 * @return dangling copy of the subtree at this node 169 * @apilevel low-level 170 * @declaredat ASTNode:106 171 */ 172 public MinusExpr treeCopy() { 173 doFullTraversal(); 174 return treeCopyNoTransform(); 175 } 176 /** 177 * @apilevel internal 178 * @declaredat ASTNode:113 179 */ 180 protected boolean is$Equal(ASTNode node) { 181 return super.is$Equal(node); 182 } 183 /** 184 * Replaces the Operand child. 185 * @param node The new node to replace the Operand child. 186 * @apilevel high-level 187 */ 188 public void setOperand(Expr node) { 189 setChild(node, 0); 190 } 191 /** 192 * Retrieves the Operand child. 193 * @return The current node used as the Operand child. 194 * @apilevel high-level 195 */ 196 @ASTNodeAnnotation.Child(name="Operand") 197 public Expr getOperand() { 198 return (Expr) getChild(0); 199 } 200 /** 201 * Retrieves the Operand child. 202 * <p><em>This method does not invoke AST transformations.</em></p> 203 * @return The current node used as the Operand child. 204 * @apilevel low-level 205 */ 206 public Expr getOperandNoTransform() { 207 return (Expr) getChildNoTransform(0); 208 } 209 /** 210 * @attribute syn 211 * @aspect ConstantExpression 212 * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:32 213 */ 214 @ASTNodeAnnotation.Attribute 215 public Constant constant() { 216 Constant constant_value = type().minus(getOperand().constant()); 217 218 return constant_value; 219 } 220 /** 221 * @attribute syn 222 * @aspect ConstantExpression 223 * @declaredat /home/jesper/git/extendj/java4/frontend/ConstantExpression.jrag:254 224 */ 225 @ASTNodeAnnotation.Attribute 226 public boolean isConstant() { 227 boolean isConstant_value = getOperand().isConstant(); 228 229 return isConstant_value; 230 } 231 /** 232 * @attribute syn 233 * @aspect PrettyPrintUtil 234 * @declaredat /home/jesper/git/extendj/java4/frontend/PrettyPrintUtil.jrag:310 235 */ 236 @ASTNodeAnnotation.Attribute 237 public String printPreOp() { 238 String printPreOp_value = "-"; 239 240 return printPreOp_value; 241 } 242 /** 243 * @apilevel internal 244 */ 245 protected boolean type_computed = false; 246 /** 247 * @apilevel internal 248 */ 249 protected TypeDecl type_value; 250 /** 251 * @apilevel internal 252 */ 253 private void type_reset() { 254 type_computed = false; 255 type_value = null; 256 } 257 /** 258 * @attribute syn 259 * @aspect TypeAnalysis 260 * @declaredat /home/jesper/git/extendj/java4/frontend/TypeAnalysis.jrag:302 261 */ 262 @ASTNodeAnnotation.Attribute 263 public TypeDecl type() { 264 ASTNode$State state = state(); 265 if (type_computed) { 266 return type_value; 267 } 268 boolean intermediate = state.INTERMEDIATE_VALUE; 269 state.INTERMEDIATE_VALUE = false; 270 int num = state.boundariesCrossed; 271 boolean isFinal = this.is$Final(); 272 type_value = getOperand().type().unaryNumericPromotion(); 273 if (isFinal && num == state().boundariesCrossed) { 274 type_computed = true; 275 } else { 276 } 277 state.INTERMEDIATE_VALUE |= intermediate; 278 279 return type_value; 280 } 281 /** 282 * @apilevel internal 283 */ 284 public ASTNode rewriteTo() { 285 // Declared at /home/jesper/git/extendj/java7/frontend/Literals.jrag:380 286 if (getOperand() instanceof IntegerLiteral 287 && ((IntegerLiteral) getOperand()).isDecimal() && getOperand().isPositive()) { 288 return rewriteRule0(); 289 } 290 // Declared at /home/jesper/git/extendj/java7/frontend/Literals.jrag:392 291 if (getOperand() instanceof LongLiteral 292 && ((LongLiteral) getOperand()).isDecimal() && getOperand().isPositive()) { 293 return rewriteRule1(); 294 } 295 return super.rewriteTo(); 296 } 297 /** 298 * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:380 299 * @apilevel internal 300 */ 301 private IntegerLiteral rewriteRule0() { 302 { 303 IntegerLiteral original = (IntegerLiteral) getOperand(); 304 IntegerLiteral literal = new IntegerLiteral("-" + original.getLITERAL()); 305 literal.setDigits(original.getDigits()); 306 literal.setKind(original.getKind()); 307 return literal; 308 } } 309 /** 310 * @declaredat /home/jesper/git/extendj/java7/frontend/Literals.jrag:392 311 * @apilevel internal 312 */ 313 private LongLiteral rewriteRule1() { 314 { 315 LongLiteral original = (LongLiteral) getOperand(); 316 LongLiteral literal = new LongLiteral("-" + original.getLITERAL()); 317 literal.setDigits(original.getDigits()); 318 literal.setKind(original.getKind()); 319 return literal; 320 } } 321 }