1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import java.io.IOException ; 29 30 import java.util.*; 31 32 import org.aspectj.compiler.base.bcg.CodeBuilder; 33 import org.aspectj.compiler.base.bcg.Label; 34 35 38 public class AddOpExpr extends BinopExpr { 39 40 void checkAssignmentOperatorType() { 41 Type ty1 = getRand1().getType(); 42 Type ty2 = getRand2().getType(); 43 44 if (ty1.isVoid() || ty2.isVoid()) { 45 showOperatorTypeError("+", ty1, ty2); 46 } else if (ty1.isAnyType() || ty2.isAnyType() || 47 ty1.isString() || ty2.isString() || 48 (ty1.isNumeric() && ty2.isNumeric())) { 49 } else { 50 showOperatorTypeError("+", ty1, ty2); 51 } 52 } 53 54 protected LiteralExpr halfFold(Type type, LiteralExpr lit1, LiteralExpr lit2) { 55 return type.foldAddOp(lit1, lit2); 56 } 57 58 protected Type discoverType() { 59 Expr rand1 = getRand1(); 60 Expr rand2 = getRand2(); 61 Type ty1 = rand1.getType(); 62 Type ty2 = rand2.getType(); 63 64 if (ty1.isAnyType() || ty2.isAnyType()) { 65 return getTypeManager().anyType; 66 } else if (ty1.isVoid() || ty2.isVoid()) { 67 showOperatorTypeError("+", ty1, ty2); 68 return getTypeManager().anyType; 69 } else if (ty1.isString() || ty2.isString()) { 70 return getTypeManager().getStringType(); 71 } else if (ty1.isNumeric() && ty2.isNumeric()) { 72 return getTypeManager().binaryNumericPromotion(ty1, ty2); 73 } else { 74 showOperatorTypeError("+", ty1, ty2); 75 return getTypeManager().anyType; 76 } 77 } 78 79 protected Type getLiftType() { 80 return getType(); 81 } 82 83 protected void cgValue(CodeBuilder cb) { 86 Type liftTy = getLiftType(); 87 if (liftTy.isString()) { 88 NameType stringBufferType = getTypeManager().getStringBufferType(); 89 cb.emitNEW(stringBufferType); 90 cb.emitDUP(); 91 cb.emitINVOKESPECIAL(stringBufferType, "<init>", "()V", -1); 92 rand1.cgBuffer(cb); 93 rand2.cgBuffer(cb); 94 cb.emitINVOKEVIRTUAL(stringBufferType, "toString", 95 "()Ljava/lang/String;", 0); 96 } else { 97 rand1.cgValue(cb, liftTy); 98 rand2.cgValue(cb, liftTy); 99 liftTy.emitAdd(cb); 100 } 101 } 102 protected void cgBuffer(CodeBuilder cb) { 103 if (getType().isString()) { 104 rand1.cgBuffer(cb); 105 rand2.cgBuffer(cb); 106 } else { 107 super.cgBuffer(cb); 108 } 109 } 110 protected void cgOp(CodeBuilder cb, Type ty) { 111 ty.emitAdd(cb); 112 } 113 114 116 public AddOpExpr(SourceLocation location, Expr _rand1, String _op, Expr _rand2) { 117 super(location, _rand1, _op, _rand2); 118 119 } 120 protected AddOpExpr(SourceLocation source) { 121 super(source); 122 } 123 124 public ASTObject copyWalk(CopyWalker walker) { 125 AddOpExpr ret = new AddOpExpr(getSourceLocation()); 126 ret.preCopy(walker, this); 127 if (rand1 != null) ret.setRand1( (Expr)walker.process(rand1) ); 128 ret.op = op; 129 if (rand2 != null) ret.setRand2( (Expr)walker.process(rand2) ); 130 return ret; 131 } 132 133 134 public String getDefaultDisplayName() { 135 return "AddOpExpr(op: "+op+")"; 136 } 137 138 } 140 | Popular Tags |