1 24 25 package org.aspectj.compiler.base; 26 27 import org.aspectj.compiler.base.ast.*; 28 29 30 import java.util.*; 31 32 35 public class ExprMaker extends MovingWalker { 36 public ExprMaker(JavaCompiler compiler) { 37 super(compiler); 38 } 39 40 boolean mayReturn; 41 boolean mustReturn; 42 43 public Map getInParams() { return inParams; } 44 public Map getOutParams() { return outParams; } 45 public boolean getNeedsThis() { return needsThis; } 46 47 Map inParams = new HashMap(); 48 Map outParams = new HashMap(); 49 boolean needsThis = false; 50 51 public Expr moveThisExpr(ThisExpr thisExpr, Type thisType) { 52 needsThis = true; 53 return super.moveThisExpr(thisExpr, thisType); 54 } 55 56 VarDec lookupVarDec(VarDec oldDec) { 57 VarDec ret = (VarDec)remapNodes.get(oldDec); 58 if (ret != null) { 59 return ret; 60 } else { 61 FormalDec formal = getAST().makeFormal(oldDec.getType(), oldDec.getId()); if (oldDec.isFinal()) formal.getModifiers().setFinal(true); 63 inParams.put(oldDec, formal); 64 remapNodes.put(oldDec, formal); 65 return formal; 66 } 67 } 68 69 70 public Expr moveVarExpr(VarExpr var) { 71 var.setVarDec(lookupVarDec(var.getVarDec())); 72 return var; 73 } 74 75 public Expr makeExpr(ASTObject object, boolean allowVoid) { 76 final AST ast = getAST(); 77 CodeDec inCode = object.getEnclosingCodeDec(); 78 79 BlockStmt block = ast.makeBlock(this.process(object)); 80 81 Formals formals = ast.makeFormals(); 82 Exprs args = ast.makeExprs(); 83 84 for (Iterator i = inParams.entrySet().iterator(); i.hasNext(); ) { 86 Map.Entry entry = (Map.Entry)i.next(); 87 VarDec varDec = (VarDec)entry.getKey(); 88 varDec.getModifiers().setFinal(true); args.add(ast.makeVar(varDec)); 90 91 FormalDec formalDec = (FormalDec)entry.getValue(); 92 formals.add(formalDec); 93 } 94 95 Modifiers mods = ast.makeModifiers(Modifiers.PRIVATE); 96 mods.setStatic(inCode.isStatic()); 97 98 Type returnType = inCode.getResultType(); 99 100 String id = getAST().makeGeneratedName(inCode.getId() + "$ajcPostAround" + 101 inCode.getBytecodeTypeDec().getBody().size()); 102 103 MethodDec newMethod = ast.makeMethod(mods, returnType, id, formals, block); 104 inCode.getBytecodeTypeDec().getBody().add(newMethod); 106 107 Expr thisExpr = ast.makePrimary(newMethod, inCode.getBytecodeTypeDec()); 108 110 Expr ret = ast.makeCall(newMethod, thisExpr, args); 111 112 if (!allowVoid && newMethod.getResultType().isVoid()) { 113 MethodDec voidWrapper = (MethodDec)CopyWalker.copy(newMethod); 114 voidWrapper.setId(newMethod.getId() + "$ajcVoidWrapper"); 115 voidWrapper.setResultTypeD( getTypeManager().getObjectType().makeTypeD() ); 117 newMethod.getBytecodeTypeDec().getBody().add(voidWrapper); 118 Expr internalCall = ast.makeCall( 119 newMethod, 120 ast.makePrimary(newMethod, inCode.getBytecodeTypeDec()), 121 voidWrapper.getFormals().makeExprs()); 122 123 Stmts stmts = ast.makeStmts( 124 ast.makeStmt(internalCall), ast.makeReturn(ast.makeNull())); 125 voidWrapper.getBody().setStmts(stmts); 126 thisExpr = ast.makePrimary(voidWrapper, newMethod.getBytecodeTypeDec()); 127 ret = ast.makeCall(voidWrapper, thisExpr, args); 128 } 129 130 return ret; 131 } 132 } 133 134 | Popular Tags |