1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 import org.aspectj.compiler.base.cst.*; 29 30 import java.util.*; 31 32 34 public class MovingWalker extends Walker { 35 protected Map remapNodes = new HashMap(); 36 protected Stack lexicalTypes = new Stack(); 37 public Type toType; 38 public boolean isStatic; 39 40 public MovingWalker(JavaCompiler compiler) { 42 super(compiler); 43 } 44 45 public MovingWalker(JavaCompiler compiler, Type fromType, Type toType) { 46 super(compiler); 47 this.toType = toType; 48 pushLexicalType(fromType); 49 } 50 51 public void addMappings(Map map) { 52 remapNodes.putAll(map); 53 } 54 55 public boolean hasToType() { return toType != null; } 56 57 public Type getToType() { return toType; } 58 59 public void addMapping(Object oldObject, Object newObject) { 60 remapNodes.put(oldObject, newObject); 61 } 62 63 public boolean inTopLexicalType() { 64 return lexicalTypes.size() == 1; 65 } 66 67 public boolean hasLexicalType() { 68 return lexicalTypes.size() > 0; 69 } 70 71 public Type getLexicalType() { 72 return (Type)lexicalTypes.peek(); 73 } 74 75 public Type getTopLexicalType() { 76 return (Type)lexicalTypes.get(0); 77 } 78 79 public void pushLexicalType(Type t) { 80 lexicalTypes.push(t); 81 } 82 83 public void popLexicalType() { 84 lexicalTypes.pop(); 85 } 86 87 public Expr moveThisExpr(ThisExpr thisExpr, Type thisType) { 88 90 if (hasLexicalType() && thisType == getTopLexicalType()) { 91 Expr ret = makeThisExpr(); 92 if (ret != null) { 94 return ret; 95 } 96 } 97 return thisExpr; 98 } 99 100 103 public Expr moveVarExpr(VarExpr var) { 104 VarDec ret = (VarDec)remapNodes.get(var.getVarDec()); 105 if (ret != null) { 106 if (ret instanceof FieldDec) { 107 return getAST().makeGet((FieldDec)ret); 108 } else { 109 var.setVarDec(ret); 110 var.setType(null); 111 var.getType(); 112 return var; 113 } 114 } else { 115 return handleFreeVar(var); 116 } 117 } 118 119 121 protected Expr handleFreeVar(VarExpr var) { 122 return var; 123 } 124 125 protected Expr makeThisExpr() { return null; } 126 127 public Type moveType(Type type) { 128 SemanticObject ret = (SemanticObject)remapNodes.get(type); 129 if (ret != null && ret instanceof Type) return (Type)ret; 130 return type; 131 } 132 133 public void moveLink(SOLink link) { 134 SemanticObject ret = (SemanticObject)remapNodes.get(link.getTarget()); 135 if (ret != null) link.setTarget(ret); 136 } 137 138 public Expr moveLinkExpr(SOLink link) { 139 SemanticObject ret = (SemanticObject)remapNodes.get(link.getTarget()); 140 if (ret != null) link.setTarget(ret); 141 return (Expr)link; 142 } 143 144 public ASTObject process(ASTObject object) { 145 object.preMove(this); 146 object.walk(this); 147 return object.postMove(this); 148 } 149 } 150 | Popular Tags |