| 1 4 package gnu.expr; 5 6 8 9 public class ResolveNames extends ExpWalker 10 { 11 protected NameLookup lookup; 12 13 public ResolveNames () 14 { 15 } 16 17 public ResolveNames (Compilation comp) 18 { 19 setContext(comp); 20 lookup = comp.lexical; 21 } 22 23 public void resolveModule(ModuleExp exp) 24 { 25 Compilation save_comp = Compilation.getCurrent(); 26 try 27 { 28 if (comp != null) 29 Compilation.setCurrent(comp); 30 push(exp); 31 exp.walkChildren(this); 32 } 33 finally 34 { 35 Compilation.setCurrent(save_comp); 36 } 39 } 40 41 protected void push (ScopeExp exp) 42 { 43 lookup.push(exp); 44 } 45 46 protected Expression walkScopeExp (ScopeExp exp) 47 { 48 walkDeclarationTypes(exp); 49 push(exp); 50 exp.walkChildren(this); 51 lookup.pop(exp); 52 return exp; 53 } 54 55 protected Expression walkLetExp (LetExp exp) 56 { 57 walkDeclarationTypes(exp); 58 exp.walkInitializers(this); 59 push(exp); 60 exp.body = (Expression) walk(exp.body); 61 lookup.pop(exp); 62 return exp; 63 } 64 65 public Declaration lookup (Expression exp, Object symbol, boolean function) 66 { 67 return lookup.lookup(symbol, function); 68 } 69 70 protected Expression walkReferenceExp (ReferenceExp exp) 71 { 72 Declaration decl = exp.getBinding(); 73 if (decl == null) 74 { 75 decl = lookup(exp, exp.getSymbol(), exp.isProcedureName()); 76 if (decl != null) 77 exp.setBinding(decl); 78 } 79 return exp; 80 } 81 82 protected Expression walkSetExp (SetExp exp) 83 { 84 if (exp.binding == null) 85 exp.binding = lookup(exp, exp.getSymbol(), exp.isFuncDef()); 86 return super.walkSetExp(exp); 87 } 88 } 89 | Popular Tags |