1 package polyglot.types; 2 3 import polyglot.util.*; 4 import polyglot.main.Report; 5 import java.util.*; 6 7 8 public class TableResolver extends ClassResolver implements TopLevelResolver { 9 protected Map table; 10 11 14 public TableResolver() { 15 this.table = new HashMap(); 16 } 17 18 21 public void addNamed(Named type) { 22 addNamed(type.name(), type); 23 } 24 25 28 public void addNamed(String name, Named type) { 29 if (name == null || type == null) { 30 throw new InternalCompilerError("Bad insertion into TableResolver"); 31 } 32 if (Report.should_report(TOPICS, 3)) 33 Report.report(3, "TableCR.addNamed(" + name + ", " + type + ")"); 34 table.put(name, type); 35 } 36 37 public boolean packageExists(String name) { 38 39 for (Iterator i = table.entrySet().iterator(); i.hasNext(); ) { 40 Map.Entry e = (Map.Entry) i.next(); 41 Named type = (Named) e.getValue(); 42 if (type instanceof Importable) { 43 Importable im = (Importable) type; 44 if (im.package_() != null && 45 im.package_().fullName().startsWith(name)) { 46 return true; 47 } 48 } 49 } 50 51 return false; 52 } 53 54 57 public Named find(String name) throws SemanticException { 58 if (Report.should_report(TOPICS, 3)) 59 Report.report(3, "TableCR.find(" + name + ")"); 60 61 Named n = (Named) table.get(name); 62 63 if (n != null) { 64 return n; 65 } 66 67 throw new NoClassException(name); 68 } 69 70 public String toString() { 71 return "(table " + table + ")"; 72 } 73 74 private static final Collection TOPICS = 75 CollectionUtil.list(Report.types, Report.resolver); 76 } 77 | Popular Tags |