1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.JavaCompiler; 28 import org.aspectj.compiler.base.CodeWriter; 29 import java.io.IOException ; 30 31 import java.util.*; 32 33 import org.aspectj.compiler.base.bcg.CodeBuilder; 34 import org.aspectj.compiler.base.bcg.Label; 35 36 39 public class EqualityTestOpExpr extends BinopExpr { 40 41 protected Type discoverType() { 42 Type ty1 = getRand1().getType(); 43 Type ty2 = getRand2().getType(); 44 45 if (ty1 instanceof RefType && ty2 instanceof RefType) { 46 if (! (ty1.isCoercableTo(ty2) || ty2.isCoercableTo(ty1))) { 47 showError("incomparable types: " + ty1.getString() + 48 " and " + ty2.getString()); 49 } 50 } else if ((ty1 instanceof RefType || ty2 instanceof RefType) || 51 ! ((ty1.isBoolean() && ty2.isBoolean()) || 52 (ty1.isNumeric() && ty2.isNumeric()))) { 53 showOperatorTypeError(op, ty1, ty2); 54 } 55 return getTypeManager().booleanType; 56 } 57 58 protected Type getLiftType() { 59 Type ty1 = getRand1().getType(); 60 Type ty2 = getRand2().getType(); 61 62 if (ty1.isBoolean() && ty2.isBoolean()) { 63 return getTypeManager().booleanType; 64 } else if (ty1.isNumeric() && ty2.isNumeric()) { 65 return getTypeManager().binaryNumericPromotion(ty1, ty2); 66 } else if (ty1 instanceof RefType && ty2 instanceof RefType) { 67 return getTypeManager().getObjectType(); 68 } else { 69 showOperatorTypeError(op, ty1, ty2); 70 return getTypeManager().anyType; 71 } 72 } 73 74 protected LiteralExpr halfFold(Type type, LiteralExpr lit1, LiteralExpr lit2) { 75 return type.foldEqualityTestOp(getOp(), lit1, lit2); 76 } 77 78 81 protected void cgTest(CodeBuilder cb, Label t, Label f) { 82 Type liftType = getLiftType(); 83 if (liftType.hasFastEqualityTestOp()) { 84 liftType.emitFastEqualityTestOp(cb, this, t, f); 85 } else { 86 getRand1().cgValue(cb, liftType); 87 getRand2().cgValue(cb, liftType); 88 liftType.emitEqualityCompare(cb, getOp(), t, f); 89 } 90 } 91 92 protected void cgOp(CodeBuilder cb, Type ty) { 93 throw new RuntimeException ("Attempt to generate code for effect op " 94 + getOp()); 95 } 96 97 99 public EqualityTestOpExpr(SourceLocation location, Expr _rand1, String _op, Expr _rand2) { 100 super(location, _rand1, _op, _rand2); 101 102 } 103 protected EqualityTestOpExpr(SourceLocation source) { 104 super(source); 105 } 106 107 public ASTObject copyWalk(CopyWalker walker) { 108 EqualityTestOpExpr ret = new EqualityTestOpExpr(getSourceLocation()); 109 ret.preCopy(walker, this); 110 if (rand1 != null) ret.setRand1( (Expr)walker.process(rand1) ); 111 ret.op = op; 112 if (rand2 != null) ret.setRand2( (Expr)walker.process(rand2) ); 113 return ret; 114 } 115 116 117 public String getDefaultDisplayName() { 118 return "EqualityTestOpExpr(op: "+op+")"; 119 } 120 121 } 123 | Popular Tags |