KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > polyglot > ext > jl > ast > ArrayTypeNode_c


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.Main;
8 import java.io.IOException JavaDoc;
9
10 /**
11  * A <code>TypeNode</code> represents the syntactic representation of a
12  * <code>Type</code> within the abstract syntax tree.
13  */

14 public class ArrayTypeNode_c extends TypeNode_c implements ArrayTypeNode
15 {
16     protected TypeNode base;
17
18     public ArrayTypeNode_c(Position pos, TypeNode base) {
19     super(pos);
20     this.base = base;
21     }
22
23     public TypeNode base() {
24         return base;
25     }
26
27     public ArrayTypeNode base(TypeNode base) {
28         ArrayTypeNode_c n = (ArrayTypeNode_c) copy();
29     n.base = base;
30     return n;
31     }
32
33     protected ArrayTypeNode_c reconstruct(TypeNode base) {
34         if (base != this.base) {
35         ArrayTypeNode_c n = (ArrayTypeNode_c) copy();
36         n.base = base;
37         return n;
38     }
39
40     return this;
41     }
42
43     public Node visitChildren(NodeVisitor v) {
44         TypeNode base = (TypeNode) visitChild(this.base, v);
45     return reconstruct(base);
46     }
47
48     public Node buildTypes(TypeBuilder tb) throws SemanticException {
49     TypeSystem ts = tb.typeSystem();
50         return type(ts.arrayOf(position(), base.type()));
51     }
52
53     public Node disambiguate(AmbiguityRemover ar) throws SemanticException {
54     TypeSystem ts = ar.typeSystem();
55     NodeFactory nf = ar.nodeFactory();
56
57         Type baseType = base.type();
58
59         if (! baseType.isCanonical()) {
60         throw new SemanticException(
61         "Base type " + baseType + " of array could not be resolved.",
62         base.position());
63     }
64
65         return nf.CanonicalTypeNode(position(),
66                             ts.arrayOf(position(), baseType));
67     }
68
69     public Node typeCheck(TypeChecker tc) throws SemanticException {
70     throw new InternalCompilerError(position(),
71         "Cannot type check ambiguous node " + this + ".");
72     }
73
74     public Node exceptionCheck(ExceptionChecker ec) throws SemanticException {
75     throw new InternalCompilerError(position(),
76         "Cannot exception check ambiguous node " + this + ".");
77     }
78
79     public void prettyPrint(CodeWriter w, PrettyPrinter tr) {
80         print(base, w, tr);
81         w.write("[]");
82     }
83
84     public void translate(CodeWriter w, Translator tr) {
85       throw new InternalCompilerError(position(),
86                                       "Cannot translate ambiguous node "
87                                       + this + ".");
88     }
89
90     public String JavaDoc toString() {
91         return base.toString() + "[]";
92     }
93 }
94
Popular Tags