1 package org.apache.regexp; 2 3 59 60 import java.util.*; 61 import java.io.*; 62 63 70 public class REDebugCompiler extends RECompiler 71 { 72 75 static Hashtable hashOpcode = new Hashtable(); 76 static 77 { 78 hashOpcode.put(new Integer (RE.OP_RELUCTANTSTAR), "OP_RELUCTANTSTAR"); 79 hashOpcode.put(new Integer (RE.OP_RELUCTANTPLUS), "OP_RELUCTANTPLUS"); 80 hashOpcode.put(new Integer (RE.OP_RELUCTANTMAYBE), "OP_RELUCTANTMAYBE"); 81 hashOpcode.put(new Integer (RE.OP_END), "OP_END"); 82 hashOpcode.put(new Integer (RE.OP_BOL), "OP_BOL"); 83 hashOpcode.put(new Integer (RE.OP_EOL), "OP_EOL"); 84 hashOpcode.put(new Integer (RE.OP_ANY), "OP_ANY"); 85 hashOpcode.put(new Integer (RE.OP_ANYOF), "OP_ANYOF"); 86 hashOpcode.put(new Integer (RE.OP_BRANCH), "OP_BRANCH"); 87 hashOpcode.put(new Integer (RE.OP_ATOM), "OP_ATOM"); 88 hashOpcode.put(new Integer (RE.OP_STAR), "OP_STAR"); 89 hashOpcode.put(new Integer (RE.OP_PLUS), "OP_PLUS"); 90 hashOpcode.put(new Integer (RE.OP_MAYBE), "OP_MAYBE"); 91 hashOpcode.put(new Integer (RE.OP_NOTHING), "OP_NOTHING"); 92 hashOpcode.put(new Integer (RE.OP_GOTO), "OP_GOTO"); 93 hashOpcode.put(new Integer (RE.OP_ESCAPE), "OP_ESCAPE"); 94 hashOpcode.put(new Integer (RE.OP_OPEN), "OP_OPEN"); 95 hashOpcode.put(new Integer (RE.OP_CLOSE), "OP_CLOSE"); 96 hashOpcode.put(new Integer (RE.OP_BACKREF), "OP_BACKREF"); 97 hashOpcode.put(new Integer (RE.OP_POSIXCLASS), "OP_POSIXCLASS"); 98 hashOpcode.put(new Integer (RE.OP_OPEN_CLUSTER), "OP_OPEN_CLUSTER"); 99 hashOpcode.put(new Integer (RE.OP_CLOSE_CLUSTER), "OP_CLOSE_CLUSTER"); 100 } 101 102 107 String opcodeToString(char opcode) 108 { 109 String ret =(String )hashOpcode.get(new Integer (opcode)); 111 112 if (ret == null) 114 { 115 ret = "OP_????"; 116 } 117 return ret; 118 } 119 120 125 String charToString(char c) 126 { 127 if (c < ' ' || c > 127) 129 { 130 return "\\" + (int)c; 131 } 132 133 return String.valueOf(c); 135 } 136 137 142 String nodeToString(int node) 143 { 144 char opcode = instruction[node + RE.offsetOpcode]; 146 int opdata = (int)instruction[node + RE.offsetOpdata]; 147 148 return opcodeToString(opcode) + ", opdata = " + opdata; 150 } 151 152 167 168 169 182 183 184 188 public void dumpProgram(PrintWriter p) 189 { 190 for (int i = 0; i < lenInstruction; ) 192 { 193 char opcode = instruction[i + RE.offsetOpcode]; 195 char opdata = instruction[i + RE.offsetOpdata]; 196 short next = (short)instruction[i + RE.offsetNext]; 197 198 p.print(i + ". " + nodeToString(i) + ", next = "); 200 201 if (next == 0) 203 { 204 p.print("none"); 205 } 206 else 207 { 208 p.print(i + next); 209 } 210 211 i += RE.nodeSize; 213 214 if (opcode == RE.OP_ANYOF) 216 { 217 p.print(", ["); 219 220 int rangeCount = opdata; 222 for (int r = 0; r < rangeCount; r++) 223 { 224 char charFirst = instruction[i++]; 226 char charLast = instruction[i++]; 227 228 if (charFirst == charLast) 230 { 231 p.print(charToString(charFirst)); 232 } 233 else 234 { 235 p.print(charToString(charFirst) + "-" + charToString(charLast)); 236 } 237 } 238 239 p.print("]"); 241 } 242 243 if (opcode == RE.OP_ATOM) 245 { 246 p.print(", \""); 248 249 for (int len = opdata; len-- != 0; ) 251 { 252 p.print(charToString(instruction[i++])); 253 } 254 255 p.print("\""); 257 } 258 259 p.println(""); 261 } 262 } 263 } 264 | Popular Tags |