1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 29 import org.aspectj.compiler.base.JavaCompiler; 30 import org.aspectj.compiler.base.cst.*; 31 32 import org.aspectj.compiler.base.bcg.CodeBuilder; 33 import org.aspectj.compiler.base.bcg.Label; 34 35 38 public abstract class Expr extends ASTObject { 39 41 public boolean isInConstructorCallExpr() { 42 ASTObject e = this; 43 while (true) { 44 if (e instanceof ConstructorCallExpr) return true; 45 else if (e instanceof Expr) e = e.getParent(); 46 else return false; 47 } 48 } 49 50 51 public boolean isConstantZero() { return false; } 52 53 54 public boolean isConstantTrue() { return false; } 55 56 57 public boolean isConstantFalse() { return false; } 58 59 63 public boolean isAssignableTo(Type type) { 64 return type.isAssignableFrom(getType()); 65 } 66 67 72 public final boolean isMethodConvertableTo(Type type) { 73 return type.isAssignableFrom(getType()); 74 } 75 76 public boolean isLegalStmt() { 77 return false; 78 } 79 80 public ASTObject postCopy(CopyWalker walker, ASTObject oldObject) { 81 if (this.type == null) { 82 this.type = ((Expr)oldObject).type; 83 } 84 return super.postCopy(walker, oldObject); 85 } 86 87 protected Expr makeQualifiedThis(Type declaringType) { 89 if (getLexicalType() != null && getLexicalType().isInnerType()) { 90 return getAST().makeQualifiedThis(declaringType); 91 } else { 92 return getAST().makeThis(declaringType); 93 } 94 } 95 96 public boolean isInExprStmt() { 97 ASTObject parent = this.getParent(); 98 if (parent instanceof ExprStmt) return true; 99 if (parent instanceof Exprs) { 100 ASTObject grandparent = parent.getParent(); 101 return (grandparent instanceof ForStmt ? true : false); 102 } 103 return false; 104 } 105 106 public void checkSpec() { 107 if (type == null) type = discoverType(); 108 } 109 110 public void assertType(Type type) { 111 if (!(type.isAssignableFrom(getType()))) { 112 showTypeError(getType(), type); 113 } 114 } 115 116 protected Type type; 117 public Type getType() { 118 if (type == null) type = discoverType(); 119 if (type == null) { 120 } 124 return type; 125 } 126 127 public void setType(Type type) { 129 this.type = type; 130 } 131 132 public void showOperatorTypeError(String op, Type a, Type b) { 133 if (a.isMissing() || b.isMissing()) return; 134 showError("operator " + op + " cannot be applied to " + a.getString() + "," + b.getString()); 135 } 136 137 138 public void showOperatorTypeError(String op, Type a) { 139 if (a.isMissing()) return; 140 showError("operator " + op + " cannot be applied to " + a.getString()); 141 } 142 143 155 public Expr makeReference() { 156 return new ReferenceExpr(getSourceLocation(), this); 157 } 158 159 163 public boolean canBeCopied() { 164 return false; 165 } 166 167 174 public boolean isUltimatelyLiteral() { 175 return false; 176 } 177 178 179 abstract protected Type discoverType(); 180 181 188 public void cleanup() { 189 type = null; 190 super.cleanup(); 191 } 192 193 196 public void walkCleanup(ByteCodeCleanupPass w) { 198 return; 199 } 200 201 204 206 protected void cgValue(CodeBuilder cb) { 207 Label trueLab = cb.genLabel(); 208 Label falseLab = cb.genLabel(); 209 Label endLab = cb.genLabel(); 210 cgTest(cb, trueLab, falseLab); 211 cb.emitLabel(trueLab); 212 cb.emitIntConstant(1); 213 cb.emitJump(endLab); 214 cb.emitLabel(falseLab); 215 cb.popStack(1); 216 cb.emitIntConstant(0); 217 cb.emitLabel(endLab); 218 } 219 220 222 protected void cgValue(CodeBuilder cb, Type castTo) { 223 cgValue(cb); 224 getType().emitCast(cb, castTo); 225 } 226 227 232 protected void cgEffect(CodeBuilder cb) { 233 cgValue(cb); 234 getType().emitPop(cb); 235 } 236 237 242 protected void cgBuffer(CodeBuilder cb) { 243 cgValue(cb); 244 NameType stringBufferType = getTypeManager().getStringBufferType(); 245 Type ty = getType(); 246 if (ty instanceof ByteType || ty instanceof ShortType) { 247 ty = getTypeManager().intType; 248 } else if (ty.isString()) { 249 } else if (ty instanceof RefType) { 250 ty = getTypeManager().getObjectType(); 251 } 252 cb.emitINVOKEVIRTUAL(stringBufferType, "append", 253 "(" + ty.getDescriptor() + ")Ljava/lang/StringBuffer;", 254 - ty.getSlotCount()); 255 } 256 257 265 protected void cgTest(CodeBuilder cb, Label tdest, Label fdest) { 266 cgValue(cb); 267 cb.emitIFNE(tdest, fdest); 268 } 269 270 273 public void walkFrameLoc(FrameLocPass walker) { 275 } 276 277 279 public Expr(SourceLocation location) { 280 super(location); 281 282 } 283 284 285 public String getDefaultDisplayName() { 286 return "Expr()"; 287 } 288 289 } 291 | Popular Tags |