1 package polyglot.visit; 2 3 import java.util.HashSet ; 4 import java.util.Iterator ; 5 import java.util.Set ; 6 import java.util.Stack ; 7 8 import polyglot.ast.Node; 9 import polyglot.ast.NodeFactory; 10 import polyglot.frontend.Job; 11 import polyglot.main.Report; 12 import polyglot.types.*; 13 import polyglot.util.Enum; 14 15 19 public class AmbiguityRemover extends ContextVisitor 20 { 21 public static class Kind extends Enum { 22 protected Kind(String name) { 23 super(name); 24 } 25 } 26 27 public static final Kind SUPER = new Kind("disam-super"); 28 public static final Kind SIGNATURES = new Kind("disam-sigs"); 29 public static final Kind FIELDS = new Kind("disam-fields"); 30 public static final Kind ALL = new Kind("disam-all"); 31 32 protected Kind kind; 33 34 public AmbiguityRemover(Job job, TypeSystem ts, NodeFactory nf, Kind kind) { 35 super(job, ts, nf); 36 this.kind = kind; 37 } 38 39 public Kind kind() { 40 return kind; 41 } 42 43 protected NodeVisitor enterCall(Node n) throws SemanticException { 44 if (Report.should_report(Report.visit, 2)) 45 Report.report(2, ">> " + kind + "::enter " + n); 46 NodeVisitor v = n.del().disambiguateEnter(this); 47 if (Report.should_report(Report.visit, 2)) 48 Report.report(2, "<< " + kind + "::enter " + n + " -> " + v); 49 return v; 50 } 51 52 protected Node leaveCall(Node old, Node n, NodeVisitor v) throws SemanticException { 53 if (Report.should_report(Report.visit, 2)) 54 Report.report(2, ">> " + kind + "::leave " + n); 55 Node m = n.del().disambiguate((AmbiguityRemover) v); 56 if (Report.should_report(Report.visit, 2)) 57 Report.report(2, "<< " + kind + "::leave " + n + " -> " + m); 58 return m; 59 } 60 61 65 public void addSuperDependencies(ClassType ct) { 66 Set seen = new HashSet (); 69 70 Stack s = new Stack (); 71 s.push(ct); 72 while (! s.isEmpty()) { 73 Type t = (Type) s.pop(); 74 if (t.isClass()) { 75 ClassType classt = t.toClass(); 76 77 if (seen.contains(classt)) { 78 continue; 79 } 80 else { 81 seen.add(classt); 82 } 83 84 if (classt instanceof ParsedClassType) { 86 this.job().extensionInfo().addDependencyToCurrentJob( 87 ((ParsedClassType)classt).fromSource()); 88 } 89 90 for (Iterator i = classt.interfaces().iterator(); i.hasNext(); ) { 92 s.push(i.next()); 93 } 94 95 if (classt.superType() != null) { 97 s.push(classt.superType()); 98 } 99 } 100 } 101 102 } 103 104 public String toString() { 105 return super.toString() + "(" + kind + ")"; 106 } 107 } 108 | Popular Tags |