1 package org.python.parser; 3 4 import org.python.parser.ast.*; 5 import java.io.DataOutputStream ; 6 import java.io.IOException ; 7 8 public class SimpleNode implements Node { 9 public int beginLine, beginColumn; 10 11 public boolean from_future_checked = false; 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 getImage() { 24 return null; 25 } 26 27 public void setImage(Object image) { 28 } 29 30 35 36 public String toString() { 37 return super.toString() + " at line "+beginLine; 38 } 39 public String toString(String prefix) { return prefix + toString(); } 40 41 public Object accept(VisitorIF visitor) throws Exception { 42 throw new ParseException("Unexpected node: "+this); 43 } 44 45 public void traverse(VisitorIF visitor) throws Exception { 46 throw new ParseException("Unexpected node: "+this); 47 } 48 49 51 52 protected String dumpThis(String s) { 53 return s; 54 } 55 56 protected String dumpThis(Object o) { 57 return String.valueOf(o); 58 } 59 60 protected String dumpThis(Object [] s) { 61 StringBuffer sb = new StringBuffer (); 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 dumpThis(int i) { 78 return Integer.toString(i); 79 } 80 81 protected String dumpThis(int i, String [] names) { 82 return names[i]; 84 } 85 86 protected String dumpThis(int[] arr, String [] names) { 87 StringBuffer sb = new StringBuffer (); 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 sb.append(names[arr[i]]); 97 } 98 sb.append("]"); 99 } 100 return sb.toString(); 101 } 102 103 protected String dumpThis(boolean b) { 104 return String.valueOf(b); 105 } 106 107 108 public void pickle(DataOutputStream ostream) throws IOException { 109 throw new IOException ("Pickling not implemented"); 110 } 111 112 protected void pickleThis(String s, DataOutputStream ostream) 113 throws IOException 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 [] s, DataOutputStream ostream) 124 throws IOException 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 ostream) 137 throws IOException 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 ostream) 147 throws IOException 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 ostream) 160 throws IOException 161 { 162 ostream.writeInt(i); 163 } 164 165 protected void pickleThis(int[] arr, DataOutputStream ostream) 166 throws IOException 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 ostream) 179 throws IOException 180 { 181 ostream.writeBoolean(b); 182 } 183 184 protected void pickleThis(Object n, DataOutputStream ostream) 185 throws IOException 186 { 187 String s = n.toString(); 188 ostream.writeInt(s.length()); 189 ostream.writeBytes(s); 190 } 191 } 192 | Popular Tags |