1 package net.sourceforge.phpdt.internal.debug.core.model;
4 * Created on 17.04.2004
6 * To change the template for this generated file go to
7 * Window - Preferences - Java - Code Generation - Code and Comments
12 * To change the template for this generated type comment go to
13 * Window - Preferences - Java - Code Generation - Code and Comments
16 import java.util.Vector;
18 import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
20 import org.eclipse.core.runtime.Status;
21 import org.eclipse.debug.core.DebugException;
26 public class PHPDBGEvalString {
29 private PHPStackFrame fStackFrame;
34 public PHPDBGEvalString (PHPStackFrame stack, String dataStr) {
46 String ExtractSubStr (char chstart, char chend, int startIdx) throws DebugException {
54 if (idx >= (workStr.length () - 1) ||
55 workStr.charAt (idx) != chstart) {
56 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "worng startIdx!", null);
58 throw new DebugException (status);
62 i = workStr.indexOf(chend, i);
65 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "endchar not found!", null);
67 throw new DebugException (status);
69 rslt = workStr.substring (idx, i);
70 workStr = workStr.substring (i + 1);
80 String ExtractQuotedSubStr (int slen, int startIdx) throws DebugException {
87 if ((idx + slen + 1) >= workStr.length () ||
88 workStr.charAt (idx)!= '"' ||
89 workStr.charAt (idx + slen + 1) != '"') {
90 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no quoted substring found!", null);
92 throw new DebugException (status);
95 rslt = workStr.substring (idx + 1, idx + 1 + slen);
96 workStr = workStr.substring (idx + 2 + slen);
108 int ExtractInt (char chstart, char chend, int startIdx) throws DebugException {
112 subs = ExtractSubStr (chstart, chend, startIdx);
114 return (Integer.parseInt (subs));
120 * @param list The list of PHPVariables
123 * @param atype The type of the variable (Either PEVT_ARRAY or PEVT_OBJECT)
126 PHPVariable ParseEvalArray (String name, PHPVariable parent, Vector list, Vector var_list, String classname, int atype) throws DebugException {
127 long arritems; // The number of items (or fields or entries) for the array (or short, array size)
129 Vector subitems = null;
132 arritems = ExtractInt (':', ':', 0); // Get the number of items/fields for the array
133 // E.g. :12: means there are 12 entries in array
135 if ((workStr.length () > 0) && // Is there still something to parse?
136 (workStr.charAt (0) != '{')) { // And the next character is not a '{', then output an error
137 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no array startcharacter!", null);
139 throw new DebugException (status);
142 workStr = workStr.substring (1); // Remove the '{'
143 item = new PHPVariable (fStackFrame, name, parent, classname, atype, null); // Create a new (empty) PHPVariable
145 list.add (item); // Add the newly created PHPVariable to list
147 if (var_list != null) { //
148 var_list.add (item); // Add the PHPVariable also to the var_list
151 if (arritems > 0) { // If the array is not empty
152 subitems = new Vector (); // Create a new child variable list for the array
153 } else if (workStr.charAt (0) != '}') { // If the array is empty the next character has to be '}'
154 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no array endcharacter!", null);
156 throw new DebugException (status);
159 while ((workStr.length () > 0) && // Is there still something to parse?
160 (workStr.charAt (0) != '}')) { // And the next character is not '}'
161 Vector tmplst = new Vector (); // Create a temporary list
163 parse ("", null, tmplst, null, false, 0); // And parse the string for the array's name.
165 if (tmplst.size () != 1) { // Parsing should return exactly on entry (which is the name)
166 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no name found!", null);
168 throw new DebugException (status);
170 // Go for the array values
171 parse (((PHPVariable) tmplst.elementAt (0)).getValue ().getValueString (), item, subitems, var_list, true, 0);
174 ((PHPValue) item.getValue ()).addVariable (subitems); // Append the list of all child variables to this PHPVariables PHPValue
175 workStr = workStr.substring (1); // Remove the '}'
177 return item; // And return the PHPVariable we just build
188 void ParseEvalNULL (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
195 if ((idx >= workStr.length ()) ||
196 (workStr.charAt (idx) != ';')) {
197 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "NULL not found!", null);
199 throw new DebugException(status);
202 workStr = workStr.substring (1);
203 item = new PHPVariable (fStackFrame, name, parent, "NULL", PHPValue.PEVT_UNKNOWN, null);
207 if (var_list != null) {
220 boolean ParseEvalInt (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
224 subs = ExtractSubStr (':', ';', startIdx);
225 item = new PHPVariable (fStackFrame, name, parent, subs, PHPValue.PEVT_LONG, null);
229 if (var_list != null) {
244 boolean ParseEvalDouble (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
248 subs = ExtractSubStr (':', ';', startIdx);
249 item = new PHPVariable (fStackFrame, name, parent, subs, PHPValue.PEVT_DOUBLE, null);
253 if (var_list != null) {
269 boolean ParseEvalString (String name, PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr, int startIdx)
270 throws DebugException {
276 slen = ExtractInt( ':', ':',startIdx);
278 if ((workStr.length () <= slen) ||
279 (workStr.charAt (0) != '"')) {
280 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no String startcharecter!", null);
282 throw new DebugException (status);
285 workStr = workStr.substring (1);
286 subs = workStr.substring (0, slen);
289 subs = subs.replaceAll ("\\\\\\\\","\\\\");
291 if (workStr.charAt (slen) != '"') {
292 status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (),Status.OK, "no String endcharecter!", null);
293 throw new DebugException (status);
296 workStr = workStr.substring (slen + 2);
299 ConvertToPhpString(subs, &subs);
302 item = new PHPVariable (fStackFrame, name, parent, subs, PHPValue.PEVT_STRING, null);
306 if (var_list != null) {
321 boolean ParseEvalBool (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
325 v = ExtractInt (':', ';', startIdx);
326 item = new PHPVariable (fStackFrame, name, parent, (v==0) ? ("FALSE") : ("TRUE"), PHPValue.PEVT_BOOLEAN, null);
330 if (var_list != null) {
345 boolean ParseEvalObject (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
349 slen = ExtractInt (':', ':', startIdx);
350 classname = ExtractQuotedSubStr (slen, startIdx);
352 if ((int) classname.length () != slen) {
356 ParseEvalArray (name,parent, list, var_list, classname,PHPValue.PEVT_OBJECT);
369 boolean ParseEvalResource (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
375 slen = ExtractInt (':', ':', startIdx);
376 restype = ExtractQuotedSubStr (slen, startIdx);
377 val = ExtractSubStr (':', ';', startIdx);
379 item = new PHPVariable (fStackFrame, name, parent, restype + ":" + val, PHPValue.PEVT_RESOURCE, null);
383 if (var_list != null) {
399 boolean ParseEvalRef (String name, PHPVariable parent, Vector list, Vector var_list, boolean isSoftRef, int startIdx) throws DebugException {
402 PHPVariable var_item;
404 v = ExtractInt(':', ';',startIdx);
405 item = new PHPVariable (fStackFrame, name, parent, "", (isSoftRef) ? (PHPValue.PEVT_SOFTREF) : (PHPValue.PEVT_REF), null);
406 v--; // ref ID is 1-based, EvalList is 0-based
408 if ((var_list == null) ||
410 (v >= var_list.size ())) {
411 // item.ref = item; // self-resolving
415 var_item = (PHPVariable) var_list.get (v);
418 item.setValue (var_item.getValue ());
419 item.setReferenceType (var_item.getReferenceType ());
420 ((PHPValue) item.getValue ()).setParent (item);
421 } catch (DebugException e) {
422 // TODO Auto-generated catch block
423 e.printStackTrace ();
434 * @return The array of PHPVariables
436 public PHPVariable[] getVars () {
437 Vector list = new Vector ();
438 Vector var_list = new Vector ();
440 parse ("", null, list, var_list, false, 0);
442 return (PHPVariable[]) list.toArray (new PHPVariable[list.size ()]); // Convert the list to an array and return the array
447 * @return The PHPVariables as list
449 public Vector getVariables () {
450 Vector list = new Vector ();
451 Vector var_list = new Vector ();
453 parse ("", null, list, var_list, false, 0);
455 return list; // return the PHPVariable list
462 * @param name The name of the PHPVariable
463 * @param parent The PHPVariable to which this parsing belongs
469 boolean parse (String name, PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr, int startIdx) {
470 boolean ret_val = false;
473 if (startIdx >= workStr.length ()) { // Is there something to parse
474 return false; // No, then leave here
477 ch = workStr.charAt (startIdx); // The first character denotes the type of variable
478 workStr = workStr.substring (1); // Remove the 'variable type' character
481 switch (ch) { // Switch according the 'variable type'
482 case 'N': ParseEvalNULL (name, parent, list, var_list, startIdx); break;
483 case 'i': ParseEvalInt (name, parent, list, var_list, startIdx); break;
484 case 'd': ParseEvalDouble (name, parent, list, var_list, startIdx); break;
485 case 's': ParseEvalString (name, parent, list, var_list, MakePhpStr, startIdx); break;
486 case 'a': ParseEvalArray (name, parent, list, var_list, "", PHPValue.PEVT_ARRAY); break;
487 case 'O': ParseEvalObject (name, parent, list, var_list, startIdx); break;
488 case 'b': ParseEvalBool (name, parent, list, var_list, startIdx); break;
489 case 'z': ParseEvalResource (name, parent, list, var_list, startIdx); break;
490 case 'R': ParseEvalRef (name, parent, list, var_list, false, startIdx); break;
491 case 'r': ParseEvalRef (name, parent, list, var_list, true, startIdx); break;
493 } catch (DebugException e) {
494 // TODO Auto-generated catch block
498 /* if (!ret_val) { // try to recover
499 unsigned int i=*startIdx;
500 while (i<str.length() && str[i]!='{' && str[i]!=';') i++;
501 if (i<str.length() && str[i] == '{') {
504 while (i<str.length() && cnt!=0) {
507 else if (str[i] == '}')
515 return ret_val; // Always false