| 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 ScopeWalker extends Walker { 35 public static void bindNames(ASTObject node, Scope topScope) { 36 new ScopeWalker(node.getCompiler(), topScope).process(node); 37 } 38 39 public Scope scope; 40 41 public ScopeWalker(JavaCompiler compiler) { 42 super(compiler); 43 } 44 45 public ScopeWalker(JavaCompiler compiler, Scope initialScope) { 46 this(compiler); 47 scope = initialScope; 48 } 49 50 public void enterCU(CompilationUnit cu) { 51 scope = new CUScope(getCompiler(), null, cu); 52 } 53 61 public Scope getScope() { return scope; } 62 63 public void pushBlockScope() { 64 pushScope(new BlockScope(getCompiler(), null)); 65 } 66 67 public void pushScope(Scope newScope) { 68 if (newScope.getStackParent() != null) { 69 throw new IllegalArgumentException ("can't push a scope that already has a parent"); 70 } 71 newScope.setStackParent(scope); 72 scope = newScope; 73 } 74 75 public void popScope() { 76 scope = scope.getStackParent(); 77 } 78 79 80 public void pushBlock() { 81 if (scope instanceof BlockScope) ((BlockScope)scope).pushBlock(); 82 } 83 84 85 public void popBlock() { 86 if (scope instanceof BlockScope) ((BlockScope)scope).popBlock(); 87 } 88 89 public void addVarDec(VarDec varDec) { 90 if (scope instanceof BlockScope) ((BlockScope)scope).addVarDec(varDec); 91 } 92 93 public void addTypeDec(TypeDec typeDec) { 94 if (typeDec.getId().equals("ANONYMOUS")) return; 95 96 if (scope instanceof BlockScope) ((BlockScope)scope).addTypeDec(typeDec); 97 } 98 99 public void addMethodDec(MethodDec methodDec) { } 100 101 public ASTObject process(ASTObject object) { 102 object.preScope(this); 104 object.walkScope(this); 105 ASTObject ret = object.postScope(this); 106 return ret; 108 } 109 110 private boolean walkBodies = true; 111 public boolean walkBodies() { return walkBodies; } 112 public void setWalkBodies(boolean b) { walkBodies = b; } 113 114 public boolean walkSignatures() { return true; } 115 116 public boolean useJavaScopes() { return false; } 117 } 118 | Popular Tags |