1 23 24 29 30 package com.sun.jdo.spi.persistence.support.sqlstore.query.util.scope; 31 32 import java.util.Hashtable ; 33 import java.util.Iterator ; 34 import java.util.Stack ; 35 36 42 public class SymbolTable 43 { 44 47 protected int actualScope = 0; 48 49 52 protected Stack nestings = new Stack (); 53 54 57 protected Hashtable symbols = new Hashtable (); 58 59 64 public void enterScope() 65 { 66 actualScope++; 67 nestings.push(new Nesting()); 68 } 69 70 74 public void leaveScope() 75 { 76 forgetNesting((Nesting)nestings.pop()); 77 actualScope--; 78 } 79 80 84 public int getActualScope() 85 { 86 return actualScope; 87 } 88 89 102 public Definition declare(String ident, Definition def) 103 { 104 Definition old = (Definition)symbols.get(ident); 105 def.setScope(actualScope); 106 if ((old == null) || (old.getScope() < actualScope)) 107 { 108 Nesting nest = (Nesting)nestings.peek(); 109 nest.add(ident, old); symbols.put(ident, def); return null; 112 } 113 else 114 { 115 return old; 116 } 117 } 118 119 125 public boolean isDeclared(String ident) 126 { 127 return (getDefinition(ident) != null); 128 } 129 130 138 public Definition getDefinition(String ident) 139 { 140 return (Definition)symbols.get(ident); 141 } 142 143 151 protected void forgetNesting(Nesting nesting) 152 { 153 String ident = null; 154 Definition hidden = null; 155 156 Iterator idents = nesting.getIdents(); 157 Iterator hiddenDefs = nesting.getHiddenDefinitions(); 158 159 while (idents.hasNext()) 160 { 161 ident = (String ) idents.next(); 162 hidden = (Definition) hiddenDefs.next(); 163 if (hidden == null) 164 { 165 symbols.remove(ident); 166 } 167 else 168 { 169 symbols.put(ident, hidden); 170 } 171 } 172 } 173 } 174 | Popular Tags |