1 24 package org.aspectj.compiler.crosscuts.joinpoints; 25 26 import org.aspectj.compiler.base.ast.*; 27 import org.aspectj.compiler.crosscuts.ast.*; 28 import org.aspectj.compiler.crosscuts.*; 29 30 import java.util.*; 31 32 33 public abstract class ExprJp extends CodeBodyJp { 34 public Expr expr; 35 36 AnonymousMethodExpr syntheticCall = null; 37 38 FormalDec targetFormal = null; 39 FormalDec thisFormal = null; 40 41 public ExprJp(Expr expr, JoinPoint enclosingJoinPoint) { 42 super(enclosingJoinPoint); 43 this.expr = expr; 44 } 45 46 public abstract Dec getTargetDec(); 47 48 public String toString() { 49 return getKind().toShortString() + 50 "(" + getTargetDec().toShortString() + ")"; 51 } 52 53 54 FormalDec getTargetFormal() { 55 if (getTargetExprType() == null) return null; 56 57 if (targetFormal == null) { 58 targetFormal = getAST().makeFormal(getTargetExprType(), "target"); 59 } 60 return targetFormal; 61 } 62 63 FormalDec getThisFormal() { 64 return null; 65 73 } 74 75 public abstract Type getTargetExprType(); 76 public abstract Type getTargetType(); 77 78 public Expr makeTargetExpr() { 79 FormalDec formal = getTargetFormal(); 80 if (formal == null) return null; 81 else return getAST().makeVar(formal); 82 } 83 84 public Expr makeTargetExprOrType() { 85 Expr ret = makeTargetExpr(); 86 if (ret != null) return ret; 87 return getAST().makeTypeExpr(getTargetType()); 88 } 89 90 public Expr makeThisExpr() { 91 return super.makeThisExpr(); 92 } 96 97 public Type getResultType() { 98 return expr.getType(); 99 } 100 101 public ASTObject getSourceLocation() { return expr; } 102 103 protected abstract AnonymousMethodExpr makeSyntheticCall(); 104 105 protected abstract ASTObject makeInnerCall(Expr targetExpr, Exprs argsExprs); 106 107 protected AnonymousMethodExpr makeAnonMethodExpr(Formals formals, 108 Expr targetExpr, Exprs argsExprs) 109 { 110 final AST ast = getAST(); 111 112 FormalDec targetFormal = getTargetFormal(); 113 if (targetFormal != null) { 114 formals.add(0, targetFormal); 115 argsExprs.add(0, targetExpr); 116 } 117 118 FormalDec thisFormal = getThisFormal(); 119 if (thisFormal != null) { 120 formals.add(0, thisFormal); 121 argsExprs.add(0, ast.makeThis(getThisExprType())); 122 } 123 124 ASTObject innerCall = makeInnerCall(makeTargetExprOrType(), makeArgsExprs()); 125 126 Modifiers modifiers = ast.makeModifiers(Modifiers.PRIVATE); 127 if (getThisExprType() == null) modifiers.setStatic(true); 128 129 String innerName = 130 getAST().makeGeneratedName(getTargetDec().getName() + "$" + getKind()); 131 132 Type innerResultType = getResultType(); 133 Stmt stmt; 134 if (innerResultType.isVoid()) { 135 if (innerCall instanceof Stmt) stmt = (Stmt)innerCall; 136 else stmt = ast.makeStmt((Expr)innerCall); 137 } else { 138 stmt = ast.makeReturn((Expr)innerCall); 139 } 140 141 142 SourceLocation loc = getSourceLocation().getSourceLocation(); 143 innerCall.setSourceLocation(loc); 145 stmt.setSourceLocation(loc); 146 147 MethodDec innerMethod = ast.makeMethod(modifiers, innerResultType, innerName, 148 formals, ast.makeBlock(stmt)); 149 innerMethod.setAllEnclosingTypes(getBytecodeType()); 152 return new AnonymousMethodExpr(loc, argsExprs, innerMethod); 153 } 154 155 156 AnonymousMethodExpr getSyntheticCall() { 157 if (syntheticCall == null) { 158 syntheticCall = makeSyntheticCall(); 159 syntheticCall.grabContext(); 160 replaceExprWith(syntheticCall); 161 } 162 return syntheticCall; 163 } 164 165 protected void replaceExprWith(Expr newExpr) { 166 expr.replaceWith(newExpr); 167 } 168 169 public CodeDec getBaseCodeDec() { 170 return getSyntheticCall().getMethodDec(); 171 } 172 173 public Stmts getStmts() { 174 return getBaseCodeDec().getBody().getStmts(); 175 } 176 public void setStmts(Stmts stmts) { 177 getBaseCodeDec().getBody().setStmts(stmts); 178 } 179 180 public void finishJoinPoint() { 181 super.finishJoinPoint(); 182 getBaseCodeDec().computeMinimalThrows(); 183 } 184 } 185 | Popular Tags |