1 package com.sun.org.apache.regexp.internal; 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 } 99 100 105 String opcodeToString(char opcode) 106 { 107 String ret =(String )hashOpcode.get(new Integer (opcode)); 109 110 if (ret == null) 112 { 113 ret = "OP_????"; 114 } 115 return ret; 116 } 117 118 123 String charToString(char c) 124 { 125 if (c < ' ' || c > 127) 127 { 128 return "\\" + (int)c; 129 } 130 131 return String.valueOf(c); 133 } 134 135 140 String nodeToString(int node) 141 { 142 char opcode = instruction[node + RE.offsetOpcode]; 144 int opdata = (int)instruction[node + RE.offsetOpdata]; 145 146 return opcodeToString(opcode) + ", opdata = " + opdata; 148 } 149 150 154 public void dumpProgram(PrintWriter p) 155 { 156 for (int i = 0; i < lenInstruction; ) 158 { 159 char opcode = instruction[i + RE.offsetOpcode]; 161 char opdata = instruction[i + RE.offsetOpdata]; 162 short next = (short)instruction[i + RE.offsetNext]; 163 164 p.print(i + ". " + nodeToString(i) + ", next = "); 166 167 if (next == 0) 169 { 170 p.print("none"); 171 } 172 else 173 { 174 p.print(i + next); 175 } 176 177 i += RE.nodeSize; 179 180 if (opcode == RE.OP_ANYOF) 182 { 183 p.print(", ["); 185 186 int rangeCount = opdata; 188 for (int r = 0; r < rangeCount; r++) 189 { 190 char charFirst = instruction[i++]; 192 char charLast = instruction[i++]; 193 194 if (charFirst == charLast) 196 { 197 p.print(charToString(charFirst)); 198 } 199 else 200 { 201 p.print(charToString(charFirst) + "-" + charToString(charLast)); 202 } 203 } 204 205 p.print("]"); 207 } 208 209 if (opcode == RE.OP_ATOM) 211 { 212 p.print(", \""); 214 215 for (int len = opdata; len-- != 0; ) 217 { 218 p.print(charToString(instruction[i++])); 219 } 220 221 p.print("\""); 223 } 224 225 p.println(""); 227 } 228 } 229 } 230 | Popular Tags |