1 package polyglot.frontend; 2 3 import polyglot.ast.Node; 4 import polyglot.visit.NodeVisitor; 5 import polyglot.main.Report; 6 import polyglot.util.*; 7 8 9 public class VisitorPass extends AbstractPass 10 { 11 Job job; 12 NodeVisitor v; 13 14 public VisitorPass(Pass.ID id, Job job) { 15 this(id, job, null); 16 } 17 18 public VisitorPass(Pass.ID id, Job job, NodeVisitor v) { 19 super(id); 20 this.job = job; 21 this.v = v; 22 } 23 24 public void visitor(NodeVisitor v) { 25 this.v = v; 26 } 27 28 public NodeVisitor visitor() { 29 return v; 30 } 31 32 public boolean run() { 33 Node ast = job.ast(); 34 35 if (ast == null) { 36 throw new InternalCompilerError("Null AST: did the parser run?"); 37 } 38 39 NodeVisitor v_ = v.begin(); 40 41 if (v_ != null) { 42 ErrorQueue q = job.compiler().errorQueue(); 43 int nErrsBefore = q.errorCount(); 44 45 if (Report.should_report(Report.frontend, 3)) 46 Report.report(3, "Running " + v_ + " on " + ast); 47 48 ast = ast.visit(v_); 49 v_.finish(ast); 50 51 58 59 int nErrsAfter = q.errorCount(); 60 61 job.ast(ast); 62 63 return (nErrsBefore == nErrsAfter); 64 } 67 68 return false; 69 } 70 71 public String toString() { 72 return id.toString(); 73 } 74 } 75 | Popular Tags |