1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.AssignmentCheckerPass; 28 import org.aspectj.compiler.base.*; 29 import org.aspectj.compiler.crosscuts.AccessFixer; 30 31 import java.util.*; 32 33 import org.aspectj.compiler.base.bcg.CodeBuilder; 34 import org.aspectj.compiler.base.bcg.Label; 35 36 40 public class AddAssignExpr extends AssignExpr { 41 42 public Type discoverType() { 43 Type ty1 = lhs.getType(); 44 Type ty2 = rhs.getType(); 45 if (! ((ty1.isString() && !ty2.isVoid()) 46 || ((ty1 instanceof NumericType) 47 && (ty2 instanceof NumericType)))) { 48 showOperatorTypeError(op, ty1, ty2); 49 } 50 return ty1; 51 } 52 53 protected void cgValue(CodeBuilder cb) { 56 cgValueEffect(cb, true); 57 } 58 protected void cgEffect(CodeBuilder cb) { 59 cgValueEffect(cb, false); 60 } 61 private void cgValueEffect(CodeBuilder cb, boolean needsValue) { 62 AssignableExpr lhs = getLhs(); 63 Expr rhs = getRhs(); 64 Type lhsTy = lhs.getType(); 65 if (lhsTy.isString()) { 66 NameType stringBufferType = getTypeManager().getStringBufferType(); 67 lhs.cgLvalue(cb); 68 lhs.cgDupLvalue(cb); 69 lhs.cgLtoRvalue(cb); 70 cb.emitNEW(stringBufferType); 71 cb.emitDUP(); 72 cb.emitINVOKESPECIAL(stringBufferType, "<init>", "()V", -1); 73 cb.emitSWAP(); 74 cb.emitINVOKEVIRTUAL(stringBufferType, "append", 75 "(Ljava/lang/String;)Ljava/lang/StringBuffer;", 76 -1); 77 rhs.cgBuffer(cb); 78 cb.emitINVOKEVIRTUAL(stringBufferType, "toString", "()Ljava/lang/String;", 0); 79 if (needsValue) lhs.cgDupRvalue(cb); 80 lhs.cgAssignment(cb); 81 } else if ((rhs instanceof IntLiteralExpr) 82 && lhsTy.hasFastIncOp(lhs, ((IntLiteralExpr) rhs).getIntValue())) { 83 lhsTy.emitFastIncOp(cb, lhs, ((IntLiteralExpr) rhs).getIntValue()); 84 if (needsValue) lhs.cgValue(cb); 85 } else { 86 Type rhsTy = rhs.getType(); 87 Type ty = getTypeManager().binaryNumericPromotion(lhsTy, rhsTy); 88 lhs.cgLvalue(cb); 89 lhs.cgDupLvalue(cb); 90 lhs.cgLtoRvalue(cb); 91 lhsTy.emitCast(cb, ty); 92 rhs.cgValue(cb, ty); 93 ty.emitAdd(cb); 94 ty.emitCast(cb, lhsTy); 95 if (needsValue) lhs.cgDupRvalue(cb); 96 lhs.cgAssignment(cb); 97 } 98 } 99 100 102 public AddAssignExpr(SourceLocation location, AssignableExpr _lhs, String _op, Expr _rhs) { 103 super(location, _lhs, _op, _rhs); 104 105 } 106 protected AddAssignExpr(SourceLocation source) { 107 super(source); 108 } 109 110 public ASTObject copyWalk(CopyWalker walker) { 111 AddAssignExpr ret = new AddAssignExpr(getSourceLocation()); 112 ret.preCopy(walker, this); 113 if (lhs != null) ret.setLhs( (AssignableExpr)walker.process(lhs) ); 114 ret.op = op; 115 if (rhs != null) ret.setRhs( (Expr)walker.process(rhs) ); 116 return ret; 117 } 118 119 120 public String getDefaultDisplayName() { 121 return "AddAssignExpr(op: "+op+")"; 122 } 123 124 } 126 | Popular Tags |