From f6b77b643c936b4a2b5a997bfa6bcc6a5294443d Mon Sep 17 00:00:00 2001 From: robekras Date: Thu, 27 Oct 2005 19:55:31 +0000 Subject: [PATCH] 1) Fixed the missing resource variable bug. 2) Code aligned and comments added. --- .../debug/core/model/PHPDBGEvalString.java | 503 ++++++++++++++------ 1 files changed, 345 insertions(+), 158 deletions(-) diff --git a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java index 40afdb0..7c71364 100644 --- a/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java @@ -20,226 +20,411 @@ import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.DebugException; - +/** + * + */ public class PHPDBGEvalString { - String workStr; + String workStr; private PHPStackFrame fStackFrame; - public PHPDBGEvalString(PHPStackFrame stack,String dataStr) { - fStackFrame=stack; - workStr=dataStr; + /** + * + */ + public PHPDBGEvalString (PHPStackFrame stack, String dataStr) { + fStackFrame = stack; + workStr = dataStr; } - String ExtractSubStr(char chstart, char chend,int startIdx) throws DebugException { - int idx=startIdx; - String rslt; - if (idx >= (workStr.length() - 1) || workStr.charAt(idx) != chstart) { - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"worng startIdx!",null); - throw new DebugException(status); + /** + * + * @param chstart + * @param chend + * @param startIdx + * @return + */ + String ExtractSubStr (char chstart, char chend, int startIdx) throws DebugException { + int idx; + int i; + String rslt; + Status status; + + idx = startIdx; + + if (idx >= (workStr.length () - 1) || + workStr.charAt (idx) != chstart) { + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "worng startIdx!", null); + + throw new DebugException (status); } - int i = ++idx; + + i = ++idx; i = workStr.indexOf(chend, i); - if (i==-1){ - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"endchar not found!",null); - throw new DebugException(status); + + if (i == -1) { + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "endchar not found!", null); + + throw new DebugException (status); } - rslt=workStr.substring(idx,i); + rslt = workStr.substring (idx, i); + workStr = workStr.substring (i + 1); - workStr=workStr.substring(i+1); return rslt; } - String ExtractQuotedSubStr(int slen,int startIdx) throws DebugException { - int idx=startIdx; - String rslt; - if (idx+slen+1 >= workStr.length() || - workStr.charAt(idx)!= '"' || - workStr.charAt(idx+slen+1) != '"') { - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no quoted substring found!",null); - throw new DebugException(status); + /** + * @param slen + * @param startIdx + * @return + */ + String ExtractQuotedSubStr (int slen, int startIdx) throws DebugException { + int idx; + String rslt; + Status status; + + idx = startIdx; + + if ((idx + slen + 1) >= workStr.length () || + workStr.charAt (idx)!= '"' || + workStr.charAt (idx + slen + 1) != '"') { + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no quoted substring found!", null); + + throw new DebugException (status); } - rslt=workStr.substring(idx+1, idx+1+slen); - workStr=workStr.substring(idx+2+slen); + + rslt = workStr.substring (idx + 1, idx + 1 + slen); + workStr = workStr.substring (idx + 2 + slen); + return rslt; } + /** + * + * @param chstart + * @param chend + * @apram startIdx + * @return + */ + int ExtractInt (char chstart, char chend, int startIdx) throws DebugException { + String subs; + int rslt; + + subs = ExtractSubStr (chstart, chend, startIdx); - int ExtractInt(char chstart, char chend,int startIdx) throws DebugException { - String subs; - int rslt; - subs=ExtractSubStr(chstart, chend,startIdx); - return (Integer.parseInt(subs)); + return (Integer.parseInt (subs)); } - PHPVariable ParseEvalArray(String name, PHPVariable parent,Vector list, Vector var_list, String classname, int atype) throws DebugException{ - long arritems; - String itemname; + /** + * @param name + * @param parent + * @param list The list of PHPVariables + * @param var_list + * @param classname + * @param atype The type of the variable (Either PEVT_ARRAY or PEVT_OBJECT) + * @return + */ + PHPVariable ParseEvalArray (String name, PHPVariable parent, Vector list, Vector var_list, String classname, int atype) throws DebugException { + long arritems; // The number of items (or fields or entries) for the array (or short, array size) PHPVariable item; - Vector subitems=null; + Vector subitems = null; + Status status; - arritems= ExtractInt(':', ':',0); - if ((workStr.length()>0)&&(workStr.charAt(0)!='{')) { - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no array startcharecter!",null); - throw new DebugException(status); + arritems = ExtractInt (':', ':', 0); // Get the number of items/fields for the array + // E.g. :12: means there are 12 entries in array + + if ((workStr.length () > 0) && // Is there still something to parse? + (workStr.charAt (0) != '{')) { // And the next character is not a '{', then output an error + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no array startcharacter!", null); + + throw new DebugException (status); + } + + workStr = workStr.substring (1); // Remove the '{' + item = new PHPVariable (fStackFrame, name, parent, classname, atype, null); // Create a new (empty) PHPVariable + + list.add (item); // Add the newly created PHPVariable to list + + if (var_list != null) { // + var_list.add (item); // Add the PHPVariable also to the var_list } - workStr=workStr.substring(1); - item= new PHPVariable(fStackFrame,name,parent,classname,atype,null); - list.add(item); - if (var_list!=null) - var_list.add(item); - if (arritems > 0) { - subitems = new Vector(); - } else - if (workStr.charAt(0)!='}') - { - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no array endcharecter!",null); - throw new DebugException(status); - } - while ((workStr.length()>0) && (workStr.charAt(0)!='}')) { - Vector tmplst=new Vector(); - // name - parse("",null, tmplst, null, false,0); - if(tmplst.size()!=1){ - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no name found!",null); - throw new DebugException(status); - } - // value - parse(((PHPVariable)tmplst.elementAt(0)).getValue().getValueString(),item, subitems, var_list, true,0); + if (arritems > 0) { // If the array is not empty + subitems = new Vector (); // Create a new child variable list for the array + } else if (workStr.charAt (0) != '}') { // If the array is empty the next character has to be '}' + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no array endcharacter!", null); + + throw new DebugException (status); + } + + while ((workStr.length () > 0) && // Is there still something to parse? + (workStr.charAt (0) != '}')) { // And the next character is not '}' + Vector tmplst = new Vector (); // Create a temporary list + + parse ("", null, tmplst, null, false, 0); // And parse the string for the array's name. + + if (tmplst.size () != 1) { // Parsing should return exactly on entry (which is the name) + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no name found!", null); + + throw new DebugException (status); + } + // Go for the array values + parse (((PHPVariable) tmplst.elementAt (0)).getValue ().getValueString (), item, subitems, var_list, true, 0); } - ((PHPValue)item.getValue()).addVariable(subitems); - workStr=workStr.substring(1); - return item; + + ((PHPValue) item.getValue ()).addVariable (subitems); // Append the list of all child variables to this PHPVariables PHPValue + workStr = workStr.substring (1); // Remove the '}' + + return item; // And return the PHPVariable we just build } - void ParseEvalNULL(String name,PHPVariable parent,Vector list, Vector var_list, int startIdx) throws DebugException { - int idx=startIdx; - if (idx >= workStr.length() || workStr.charAt(idx) != ';') { - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"NULL not found!",null); + /** + * + * @param name + * @param parent + * @param list + * @param var_list + * @param startIdx + */ + void ParseEvalNULL (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { + int idx; + PHPVariable item; + Status status; + + idx = startIdx; + + if ((idx >= workStr.length ()) || + (workStr.charAt (idx) != ';')) { + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "NULL not found!", null); + throw new DebugException(status); } - workStr=workStr.substring(1); - PHPVariable item= new PHPVariable(fStackFrame, name,parent,"NULL",PHPValue.PEVT_UNKNOWN,null); - list.add(item); - if (var_list!=null) - var_list.add(item); + + workStr = workStr.substring (1); + item = new PHPVariable (fStackFrame, name, parent, "NULL", PHPValue.PEVT_UNKNOWN, null); + + list.add (item); + + if (var_list != null) { + var_list.add (item); + } } - boolean ParseEvalInt( String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { - String subs=null; + /** + * + * @param name + * @param parent + * @param list + * @param var_list + * @param startIdx + */ + boolean ParseEvalInt (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { + String subs; PHPVariable item; - subs = ExtractSubStr(':',';',startIdx); - item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_LONG,null); - list.add(item); - if (var_list!=null) - var_list.add(item); + + subs = ExtractSubStr (':', ';', startIdx); + item = new PHPVariable (fStackFrame, name, parent, subs, PHPValue.PEVT_LONG, null); + + list.add (item); + + if (var_list != null) { + var_list.add (item); + } + return true; } - boolean ParseEvalDouble(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { - String subs=null; + /** + * + * @param name + * @param parent + * @param list + * @param var_list + * @param startIdx + */ + boolean ParseEvalDouble (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { + String subs; PHPVariable item; - subs = ExtractSubStr(':',';',startIdx); - item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_DOUBLE,null); - list.add(item); - if (var_list!=null) - var_list.add(item); + + subs = ExtractSubStr (':', ';', startIdx); + item = new PHPVariable (fStackFrame, name, parent, subs, PHPValue.PEVT_DOUBLE, null); + + list.add (item); + + if (var_list != null) { + var_list.add (item); + } + return true; } - boolean ParseEvalString(String name,PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr, int startIdx) - throws DebugException{ - int slen; - slen= ExtractInt( ':', ':',startIdx); - if ((workStr.length()<=slen)||(workStr.charAt(0)!='"')) { - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no String startcharecter!",null); - throw new DebugException(status); + /** + * + * @param name + * @param parent + * @param list + * @param var_list + * @param MakePhpStr + * @param startIdx + */ + boolean ParseEvalString (String name, PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr, int startIdx) + throws DebugException { + int slen; + Status status; + String subs; + PHPVariable item; + + slen = ExtractInt( ':', ':',startIdx); + + if ((workStr.length () <= slen) || + (workStr.charAt (0) != '"')) { + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (), Status.OK, "no String startcharecter!", null); + + throw new DebugException (status); } - workStr=workStr.substring(1); - String subs = workStr.substring(0,slen); + + workStr = workStr.substring (1); + subs = workStr.substring (0, slen); + // replace \\ with \ - subs=subs.replaceAll("\\\\\\\\","\\\\"); - if (workStr.charAt(slen)!='"') { - Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no String endcharecter!",null); - throw new DebugException(status); + subs = subs.replaceAll ("\\\\\\\\","\\\\"); + + if (workStr.charAt (slen) != '"') { + status = new Status (Status.ERROR, PHPDebugCorePlugin.getUniqueIdentifier (),Status.OK, "no String endcharecter!", null); + throw new DebugException (status); } - workStr=workStr.substring(slen+2); + + workStr = workStr.substring (slen + 2); /* if (MakePhpStr) { ConvertToPhpString(subs, &subs); } */ - PHPVariable item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_STRING,null); - list.add(item); - if (var_list!=null) - var_list.add(item); - return true; - } + item = new PHPVariable (fStackFrame, name, parent, subs, PHPValue.PEVT_STRING, null); + + list.add (item); + + if (var_list != null) { + var_list.add (item); + } - boolean ParseEvalBool(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx) - throws DebugException{ - long v; - v=ExtractInt(':', ';',startIdx); - PHPVariable item= new PHPVariable(fStackFrame, name,parent,(v==0)?("FALSE"):("TRUE"),PHPValue.PEVT_BOOLEAN,null); - list.add(item); - if (var_list!=null) - list.add(item); return true; } - boolean ParseEvalObject(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx) - throws DebugException{ - int slen; - String classname; + /** + * + * @param name + * @param parent + * @param list + * @param var_list + * @param startIdx + */ + boolean ParseEvalBool (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { + long v; + PHPVariable item; + + v = ExtractInt (':', ';', startIdx); + item = new PHPVariable (fStackFrame, name, parent, (v==0) ? ("FALSE") : ("TRUE"), PHPValue.PEVT_BOOLEAN, null); + + list.add (item); + + if (var_list != null) { + list.add (item); + } - slen=ExtractInt(':', ':',startIdx); - classname= ExtractQuotedSubStr(slen, startIdx); - if ((int)classname.length()!=slen) return false; - ParseEvalArray(name,parent, list, var_list, classname,PHPValue.PEVT_OBJECT); return true; } - boolean ParseEvalResource(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx) - throws DebugException{ - int v, slen; - String restype, val; + /** + * + * @param name + * @param parent + * @param list + * @param var_list + * @param startIdx + */ + boolean ParseEvalObject (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { + int slen; + String classname; + + slen = ExtractInt (':', ':', startIdx); + classname = ExtractQuotedSubStr (slen, startIdx); + + if ((int) classname.length () != slen) { + return false; + } + + ParseEvalArray (name,parent, list, var_list, classname,PHPValue.PEVT_OBJECT); - slen=ExtractInt(':', ':',startIdx); - restype=ExtractQuotedSubStr(slen, startIdx); - v=ExtractInt(':', ';',startIdx); -// std_sprintf(val, "%ld", v); -// list->Add(var_list, name, val, ptResource, restype); return true; } + /** + * + * @param name + * @param parent + * @param list + * @param var_list + * @param startIdx + */ + boolean ParseEvalResource (String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { + PHPVariable item; + int slen; + String restype; + String val; + + slen = ExtractInt (':', ':', startIdx); + restype = ExtractQuotedSubStr (slen, startIdx); + val = ExtractSubStr (':', ';', startIdx); + + item = new PHPVariable (fStackFrame, name, parent, restype + ":" + val, PHPValue.PEVT_RESOURCE, null); + + list.add (item); - boolean ParseEvalRef(String name,PHPVariable parent, Vector list, Vector var_list, boolean isSoftRef, int startIdx) - throws DebugException{ - int v; + if (var_list != null) { + list.add (item); + } - v=ExtractInt(':', ';',startIdx); + return true; + } - PHPVariable item= new PHPVariable(fStackFrame, name,parent,"",(isSoftRef)? (PHPValue.PEVT_SOFTREF): (PHPValue.PEVT_REF),null); - v--; // ref ID is 1-based, EvalList is 0-based + /** + * + * @param name + * @param parent + * @param list + * @param var_list + * @param startIdx + */ + boolean ParseEvalRef (String name, PHPVariable parent, Vector list, Vector var_list, boolean isSoftRef, int startIdx) throws DebugException { + int v; + PHPVariable item; + PHPVariable var_item; - if ((var_list==null) || (v<0) || (v >= var_list.size())) { + v = ExtractInt(':', ';',startIdx); + item = new PHPVariable (fStackFrame, name, parent, "", (isSoftRef) ? (PHPValue.PEVT_SOFTREF) : (PHPValue.PEVT_REF), null); + v--; // ref ID is 1-based, EvalList is 0-based + + if ((var_list == null) || + (v < 0) || + (v >= var_list.size ())) { // item.ref = item; // self-resolving +// return true; - } else { - PHPVariable var_item=(PHPVariable)var_list.get(v); + } else { + var_item = (PHPVariable) var_list.get (v); + try { - item.setValue(var_item.getValue()); - item.setReferenceType(var_item.getReferenceType()); - ((PHPValue)item.getValue()).setParent(item); + item.setValue (var_item.getValue ()); + item.setReferenceType (var_item.getReferenceType ()); + ((PHPValue) item.getValue ()).setParent (item); } catch (DebugException e) { // TODO Auto-generated catch block - e.printStackTrace(); + e.printStackTrace (); } - list.add(item); - } + list.add (item); + } return true; } @@ -259,7 +444,7 @@ public class PHPDBGEvalString { /** * - * @return The array of PHPVariables + * @return The PHPVariables as list */ public Vector getVariables () { Vector list = new Vector (); @@ -272,8 +457,10 @@ public class PHPDBGEvalString { /** * - * @param name - * @param parent + * + * + * @param name The name of the PHPVariable + * @param parent The PHPVariable to which this parsing belongs * @param list * @param var_list * @param MakePhpStr @@ -283,15 +470,15 @@ public class PHPDBGEvalString { boolean ret_val = false; char ch; - if (startIdx >= workStr.length ()) { - return false; + if (startIdx >= workStr.length ()) { // Is there something to parse + return false; // No, then leave here } - ch = workStr.charAt (startIdx); - workStr = workStr.substring (1); + ch = workStr.charAt (startIdx); // The first character denotes the type of variable + workStr = workStr.substring (1); // Remove the 'variable type' character try { - switch (ch) { + switch (ch) { // Switch according the 'variable type' case 'N': ParseEvalNULL (name, parent, list, var_list, startIdx); break; case 'i': ParseEvalInt (name, parent, list, var_list, startIdx); break; case 'd': ParseEvalDouble (name, parent, list, var_list, startIdx); break; @@ -325,6 +512,6 @@ public class PHPDBGEvalString { *startIdx = i; } */ - return ret_val; + return ret_val; // Always false } } -- 1.7.1