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 import org.aspectj.compiler.base.bcg.CodeBuilder; 31 import org.aspectj.compiler.base.bcg.Label; 32 33 import java.util.*; 34 35 38 public class NumericTestOpExpr extends BinopExpr { 39 40 protected Type discoverType() { 41 Expr rand1 = getRand1(); 42 Expr rand2 = getRand2(); 43 Type ty1 = rand1.getType(); 44 Type ty2 = rand2.getType(); 45 46 if (!(ty1 instanceof NumericType && ty2 instanceof NumericType)) { 47 showOperatorTypeError(op, ty1, ty2); 48 } 49 return getTypeManager().booleanType; 50 } 51 52 protected Type getLiftType() { 53 Expr rand1 = getRand1(); 54 Expr rand2 = getRand2(); 55 Type ty1 = rand1.getType(); 56 Type ty2 = rand2.getType(); 57 58 if (ty1 instanceof NumericType && ty2 instanceof NumericType) { 59 return getTypeManager().binaryNumericPromotion(ty1, ty2); 60 } else { 61 showOperatorTypeError(op, ty1, ty2); 62 return getTypeManager().anyType; 63 } 64 } 65 66 protected LiteralExpr halfFold(Type type, LiteralExpr lit1, LiteralExpr lit2) { 67 return type.foldNumericTestOp(getOp(), lit1, lit2); 68 } 69 70 73 protected void cgTest(CodeBuilder cb, Label t, Label f) { 74 Type liftType = getLiftType(); 75 if (liftType.hasFastNumericTestOp()) { 76 liftType.emitFastNumericTestOp(cb, this, t, f); 77 } else { 78 getRand1().cgValue(cb, liftType); 79 getRand2().cgValue(cb, liftType); 80 liftType.emitNumericCompare(cb, getOp(), t, f); 81 } 82 } 83 84 protected void cgOp(CodeBuilder cb, Type ty) { 85 throw new RuntimeException ("Attempt to generate code for effect op " 86 + getOp()); 87 } 88 89 91 public NumericTestOpExpr(SourceLocation location, Expr _rand1, String _op, Expr _rand2) { 92 super(location, _rand1, _op, _rand2); 93 94 } 95 protected NumericTestOpExpr(SourceLocation source) { 96 super(source); 97 } 98 99 public ASTObject copyWalk(CopyWalker walker) { 100 NumericTestOpExpr ret = new NumericTestOpExpr(getSourceLocation()); 101 ret.preCopy(walker, this); 102 if (rand1 != null) ret.setRand1( (Expr)walker.process(rand1) ); 103 ret.op = op; 104 if (rand2 != null) ret.setRand2( (Expr)walker.process(rand2) ); 105 return ret; 106 } 107 108 109 public String getDefaultDisplayName() { 110 return "NumericTestOpExpr(op: "+op+")"; 111 } 112 113 } 115 | Popular Tags |