1 package polyglot.ext.jl.ast; 2 3 import polyglot.ast.*; 4 import polyglot.types.*; 5 import polyglot.visit.*; 6 import polyglot.util.*; 7 8 12 public class AmbTypeNode_c extends TypeNode_c implements AmbTypeNode { 13 protected QualifierNode qual; 14 protected String name; 15 16 public AmbTypeNode_c(Position pos, QualifierNode qual, 17 String name) { 18 super(pos); 19 20 this.qual = qual; 21 this.name = name; 22 } 23 24 public String name() { 25 return this.name; 26 } 27 28 public AmbTypeNode name(String name) { 29 AmbTypeNode_c n = (AmbTypeNode_c) copy(); 30 n.name = name; 31 return n; 32 } 33 34 public QualifierNode qual() { 35 return this.qual; 36 } 37 38 public AmbTypeNode qual(QualifierNode qual) { 39 AmbTypeNode_c n = (AmbTypeNode_c) copy(); 40 n.qual = qual; 41 return n; 42 } 43 44 protected AmbTypeNode_c reconstruct(QualifierNode qual) { 45 if (qual != this.qual) { 46 AmbTypeNode_c n = (AmbTypeNode_c) copy(); 47 n.qual = qual; 48 return n; 49 } 50 51 return this; 52 } 53 54 public Node buildTypes(TypeBuilder tb) throws SemanticException { 55 return type(tb.typeSystem().unknownType(position())); 56 } 57 58 public Node visitChildren(NodeVisitor v) { 59 QualifierNode qual = (QualifierNode) visitChild(this.qual, v); 60 return reconstruct(qual); 61 } 62 63 public Node disambiguate(AmbiguityRemover sc) throws SemanticException { 64 Node n = sc.nodeFactory().disamb().disambiguate(this, sc, position(), qual, 65 name); 66 67 if (n instanceof TypeNode) { 68 return n; 69 } 70 71 throw new SemanticException("Could not find type \"" + 72 (qual == null ? name : qual.toString() + "." + name) + 73 "\".", position()); 74 } 75 76 public Node typeCheck(TypeChecker tc) throws SemanticException { 77 throw new InternalCompilerError(position(), 78 "Cannot type check ambiguous node " 79 + this + "."); 80 } 81 82 public Node exceptionCheck(ExceptionChecker ec) throws SemanticException { 83 throw new InternalCompilerError(position(), 84 "Cannot exception check ambiguous node " 85 + this + "."); 86 } 87 88 public void prettyPrint(CodeWriter w, PrettyPrinter tr) { 89 if (qual != null) { 90 print(qual, w, tr); 91 w.write("."); 92 } 93 94 w.write(name); 95 } 96 97 public void translate(CodeWriter w, Translator tr) { 98 throw new InternalCompilerError(position(), 99 "Cannot translate ambiguous node " 100 + this + "."); 101 } 102 103 public String toString() { 104 return (qual == null 105 ? name 106 : qual.toString() + "." + name) + "{amb}"; 107 } 108 109 public void dump(CodeWriter w) { 110 super.dump(w); 111 112 w.allowBreak(4, " "); 113 w.begin(0); 114 w.write("(name \"" + name + "\")"); 115 w.end(); 116 } 117 } 118 | Popular Tags |