1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 29 import java.util.*; 30 31 import org.aspectj.compiler.base.bcg.CodeBuilder; 32 import org.aspectj.compiler.base.bcg.Label; 33 34 39 public class PostfixExpr extends BangExpr { 40 41 public ASTObject fixAccessToFieldSet(FieldAccessExpr expr) { 43 final AST ast = getAST(); 44 Expr newExpr = makeInPlaceSet(expr, op.substring(1), ast.makeLiteral(1)); 47 if (isInExprStmt()) { 48 return newExpr; 49 } 50 51 return ast.makeParen(ast.makeBinop(op.substring(1), newExpr, ast.makeLiteral(-1))); 52 } 53 54 public void unparse(CodeWriter writer) { 55 writer.write(lhs); 56 writer.write(op); 57 } 58 59 public void checkSpec() { 60 Type ty = getType(); 61 if (ty.isVoid() || 62 !(ty.isNumeric() || ty.isAnyType())) { 63 showOperatorTypeError(op, ty); 64 } 65 } 66 69 public ASTObject postInnerAccess(InnerAccessFixer w) { 70 if (! (getLhs() instanceof FieldAccessExpr)) return this; 71 72 FieldAccessExpr lhs = (FieldAccessExpr) getLhs(); 73 Expr q = lhs.getExpr(); 74 FieldDec dec = lhs.getFieldDec(); 75 if (w.isAccessible(dec, q)) return this; 76 77 final AST ast = getAST(); 78 Type qType = q.getType(); 79 MethodDec newMethodDec = w.getAccessMethod(qType, dec, "x" + getOp(), this); 80 Exprs newArgs = ast.makeExprs(); 81 Expr newExpr = w.makeOutsidePrimary(dec.isStatic(), newArgs, q); 82 return ast.makeCall(newMethodDec, newExpr, newArgs); 83 } 84 85 public MethodDec buildAccessMethod(InnerAccessFixer w) { 86 final AST ast = getAST(); 87 FieldAccessExpr lhs = (FieldAccessExpr) getLhs(); 88 Expr q = lhs.getExpr(); 89 Type qType = q.getType(); 90 FieldDec dec = lhs.getFieldDec(); 91 Type fieldType = dec.getType(); 92 93 Formals newFormals = ast.makeFormals(); 94 Expr newExpr = w.makeInsidePrimary(dec.isStatic(), newFormals, qType); 95 96 return 97 w.makeAccessMethod(fieldType, 98 newFormals, 99 ast.makePostfix(newExpr, dec, getOp())); 100 } 101 102 public void cgValue(CodeBuilder cb) { 105 cgValueEffect(cb, true); 106 } 107 public void cgEffect(CodeBuilder cb) { 108 cgValueEffect(cb, false); 109 } 110 private void cgValueEffect(CodeBuilder cb, boolean needsValue) { 111 Type ty = getType(); 112 AssignableExpr lhs = getLhs(); 113 114 if (ty.hasFastIncOp(lhs, 1)) { 115 if (needsValue) lhs.cgValue(cb); 116 ty.emitFastIncOp(cb, lhs, op.equals("++") ? 1 : -1); 117 } else { 118 lhs.cgLvalue(cb); 119 lhs.cgDupLvalue(cb); 120 lhs.cgLtoRvalue(cb); 121 if (needsValue) lhs.cgDupRvalue(cb); 122 ty.emitOne(cb); 123 if (op.equals("++")) ty.emitAdd(cb); 124 else ty.emitNumericOp(cb, "-"); 125 if (ty instanceof IntishType) { 126 ((IntishType)ty).emitCastFromInt(cb); 127 } 128 lhs.cgAssignment(cb); 129 } 130 } 131 132 protected String op; 134 public String getOp() { return op; } 135 public void setOp(String _op) { op = _op; } 136 137 public PostfixExpr(SourceLocation location, AssignableExpr _lhs, String _op) { 138 super(location, _lhs); 139 setOp(_op); 140 } 141 protected PostfixExpr(SourceLocation source) { 142 super(source); 143 } 144 145 public ASTObject copyWalk(CopyWalker walker) { 146 PostfixExpr ret = new PostfixExpr(getSourceLocation()); 147 ret.preCopy(walker, this); 148 if (lhs != null) ret.setLhs( (AssignableExpr)walker.process(lhs) ); 149 ret.op = op; 150 return ret; 151 } 152 153 154 public String getDefaultDisplayName() { 155 return "PostfixExpr(op: "+op+")"; 156 } 157 158 } 160 | Popular Tags |