1 package polyglot.ext.jl.ast; 2 3 import polyglot.ast.*; 4 import polyglot.types.*; 5 import polyglot.util.*; 6 import polyglot.visit.*; 7 import polyglot.main.Options; 8 9 12 public class CanonicalTypeNode_c extends TypeNode_c implements CanonicalTypeNode 13 { 14 public CanonicalTypeNode_c(Position pos, Type type) { 15 super(pos); 16 this.type = type; 17 } 18 19 25 public void prettyPrint(CodeWriter w, PrettyPrinter tr) { 26 if (type == null) w.write("<unknown-type>"); 27 else w.write(type.toString()); 28 } 29 30 31 public Node typeCheck(TypeChecker tc) throws SemanticException { 32 TypeSystem ts = tc.typeSystem(); 33 34 if (type.isClass()) { 35 ClassType ct = type.toClass(); 36 if (ct.isTopLevel() || ct.isMember()) { 37 if (! ts.classAccessible(ct, tc.context())) { 38 throw new SemanticException("Cannot access class \"" + 39 ct + "\" from the body of \"" + 40 tc.context().currentClass() + "\".", position()); 41 } 42 } 43 } 44 45 return this; 46 } 47 48 public void translate(CodeWriter w, Translator tr) { 49 TypeSystem ts = tr.typeSystem(); 50 51 if (tr.outerClass() != null) { 52 w.write(type.translate(ts.classContextResolver(tr.outerClass()))); 53 } 54 else if (Options.global.fully_qualified_names) { 55 w.write(type.translate(null)); 65 } 66 else { 67 w.write(type.translate(tr.context())); 68 } 69 } 70 71 public String toString() { 72 if (type == null) return "<unknown-type>"; 73 return type.toString(); 74 } 75 76 public void dump(CodeWriter w) { 77 super.dump(w); 78 w.allowBreak(4, " "); 79 w.begin(0); 80 w.write("(type " + type + ")"); 81 w.end(); 82 } 83 } 84 | Popular Tags |