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