KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > python > parser > SimpleNode


1 // Copyright (c) Corporation for National Research Initiatives
2
package org.python.parser;
3
4 import org.python.parser.ast.*;
5 import java.io.DataOutputStream JavaDoc;
6 import java.io.IOException JavaDoc;
7
8 public class SimpleNode implements Node {
9     public int beginLine, beginColumn;
10
11     public boolean from_future_checked = false; // from __future__ support
12

13     public SimpleNode() { }
14
15     public static Node jjtCreate(PythonGrammar p, int id) {
16         return p.jjtree.openNode(id);
17     }
18
19     public int getId() {
20         return -1;
21     }
22
23     public Object JavaDoc getImage() {
24         return null;
25     }
26
27     public void setImage(Object JavaDoc image) {
28     }
29
30     /* You can override these two methods in subclasses of SimpleNode to
31        customize the way the node appears when the tree is dumped. If
32        your output uses more than one line you should override
33        toString(String), otherwise overriding toString() is probably all
34        you need to do. */

35
36     public String JavaDoc toString() {
37         return super.toString() + " at line "+beginLine;
38     }
39     public String JavaDoc toString(String JavaDoc prefix) { return prefix + toString(); }
40
41     public Object JavaDoc accept(VisitorIF visitor) throws Exception JavaDoc {
42         throw new ParseException("Unexpected node: "+this);
43     }
44
45     public void traverse(VisitorIF visitor) throws Exception JavaDoc {
46         throw new ParseException("Unexpected node: "+this);
47     }
48
49     /* Override this method if you want to customize how the node dumps
50        ut its children. */

51
52     protected String JavaDoc dumpThis(String JavaDoc s) {
53         return s;
54     }
55
56     protected String JavaDoc dumpThis(Object JavaDoc o) {
57         return String.valueOf(o);
58     }
59
60     protected String JavaDoc dumpThis(Object JavaDoc[] s) {
61         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
62         if (s == null) {
63             sb.append("null");
64         } else {
65             sb.append("[");
66             for (int i = 0; i < s.length; i++) {
67                 if (i > 0)
68                     sb.append(", ");
69                 sb.append(String.valueOf(s[i]));
70             }
71             sb.append("]");
72         }
73         
74         return sb.toString();
75     }
76
77     protected String JavaDoc dumpThis(int i) {
78         return Integer.toString(i);
79     }
80
81     protected String JavaDoc dumpThis(int i, String JavaDoc[] names) {
82         // XXX Verify bounds.
83
return names[i];
84     }
85
86     protected String JavaDoc dumpThis(int[] arr, String JavaDoc[] names) {
87         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
88         if (arr == null) {
89             sb.append("null");
90         } else {
91             sb.append("[");
92             for (int i = 0; i < arr.length; i++) {
93                 if (i > 0)
94                     sb.append(", ");
95                 // XXX Verify bounds.
96
sb.append(names[arr[i]]);
97             }
98             sb.append("]");
99         }
100         return sb.toString();
101     }
102
103     protected String JavaDoc dumpThis(boolean b) {
104         return String.valueOf(b);
105     }
106
107
108     public void pickle(DataOutputStream JavaDoc ostream) throws IOException JavaDoc {
109         throw new IOException JavaDoc("Pickling not implemented");
110     }
111
112     protected void pickleThis(String JavaDoc s, DataOutputStream JavaDoc ostream)
113         throws IOException JavaDoc
114     {
115         if (s == null) {
116             ostream.writeInt(-1);
117         } else {
118             ostream.writeInt(s.length());
119             ostream.writeBytes(s);
120         }
121     }
122
123     protected void pickleThis(String JavaDoc[] s, DataOutputStream JavaDoc ostream)
124         throws IOException JavaDoc
125     {
126         if (s == null) {
127             ostream.writeInt(-1);
128         } else {
129             ostream.writeInt(s.length);
130             for (int i = 0; i < s.length; i++) {
131                 pickleThis(s[i], ostream);
132             }
133         }
134     }
135
136     protected void pickleThis(SimpleNode o, DataOutputStream JavaDoc ostream)
137         throws IOException JavaDoc
138     {
139         if (o == null) {
140             ostream.writeInt(-1);
141         } else {
142             o.pickle(ostream);
143         }
144     }
145
146     protected void pickleThis(SimpleNode[] s, DataOutputStream JavaDoc ostream)
147         throws IOException JavaDoc
148     {
149         if (s == null) {
150             ostream.writeInt(-1);
151         } else {
152             ostream.writeInt(s.length);
153             for (int i = 0; i < s.length; i++) {
154                 pickleThis(s[i], ostream);
155             }
156         }
157     }
158
159     protected void pickleThis(int i, DataOutputStream JavaDoc ostream)
160         throws IOException JavaDoc
161     {
162         ostream.writeInt(i);
163     }
164
165     protected void pickleThis(int[] arr, DataOutputStream JavaDoc ostream)
166         throws IOException JavaDoc
167     {
168         if (arr == null) {
169             ostream.writeInt(-1);
170         } else {
171             ostream.writeInt(arr.length);
172             for (int i = 0; i < arr.length; i++) {
173                 ostream.writeInt(arr[i]);
174             }
175         }
176     }
177
178     protected void pickleThis(boolean b, DataOutputStream JavaDoc ostream)
179         throws IOException JavaDoc
180     {
181         ostream.writeBoolean(b);
182     }
183
184     protected void pickleThis(Object JavaDoc n, DataOutputStream JavaDoc ostream)
185         throws IOException JavaDoc
186     {
187         String JavaDoc s = n.toString();
188         ostream.writeInt(s.length());
189         ostream.writeBytes(s);
190     }
191 }
192
Popular Tags