From 4aee80e02528c77d0064953236bbd085efd9ec90 Mon Sep 17 00:00:00 2001 From: cperkonig Date: Sat, 10 Jul 2004 08:08:17 +0000 Subject: [PATCH] Initial implementation - Class to parse evalString form dbg --- .../debug/core/model/PHPDBGEvalString.java | 317 ++++++++++++++++++++ 1 files changed, 317 insertions(+), 0 deletions(-) create mode 100644 net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java 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 new file mode 100644 index 0000000..8a15874 --- /dev/null +++ b/net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDBGEvalString.java @@ -0,0 +1,317 @@ +package net.sourceforge.phpdt.internal.debug.core.model; + +/* + * Created on 17.04.2004 + * + * To change the template for this generated file go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ +/** + * @author Chris Admin + * + * To change the template for this generated type comment go to + * Window - Preferences - Java - Code Generation - Code and Comments + */ + +import java.util.Vector; + +import org.eclipse.debug.core.DebugException; +import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin; +import org.eclipse.core.runtime.Status; + + +public class PHPDBGEvalString { + + String workStr; + private PHPStackFrame fStackFrame; + + 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); + } + int 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); + } + rslt=workStr.substring(idx,i); + + 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); + } + rslt=workStr.substring(idx+1, idx+1+slen); + workStr=workStr.substring(idx+2+slen); + return rslt; + } + + + int ExtractInt(char chstart, char chend,int startIdx) throws DebugException { + String subs; + int rslt; + subs=ExtractSubStr(chstart, chend,startIdx); + 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; + PHPVariable item; + Vector subitems=null; + + 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); + } + 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); + + } + ((PHPValue)item.getValue()).addVariable(subitems); + workStr=workStr.substring(1); + return item; + } + + 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); + 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); + } + + boolean ParseEvalInt( String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { + String subs=null; + 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); + return true; + } + + boolean ParseEvalDouble(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException { + String subs=null; + 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); + 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); + } + workStr=workStr.substring(1); + String 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); + } + 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; + } + + 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; + + 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; + + 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; + } + + + boolean ParseEvalRef(String name,PHPVariable parent, Vector list, Vector var_list, boolean isSoftRef, int startIdx) + throws DebugException{ + int v; + + v=ExtractInt(':', ';',startIdx); + + 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 + + + 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); + try { + 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(); + } + list.add(item); + } + + + return true; + } + + public PHPVariable[] getVars(){ + Vector list=new Vector(); + Vector var_list=new Vector(); + parse("",null,list,var_list,false,0); + return (PHPVariable[])list.toArray(new PHPVariable[list.size()]); + } + + boolean parse(String name,PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr,int startIdx) { + boolean ret_val = false; + + if (startIdx >= workStr.length()) return false; + char ch = workStr.charAt(startIdx); + workStr=workStr.substring(1); + try { + switch (ch) { + 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; + case 's': + ParseEvalString(name,parent, list, var_list, MakePhpStr, startIdx); + break; + case 'a': + ParseEvalArray(name,parent, list, var_list, "", PHPValue.PEVT_ARRAY); + break; + case 'O': + ParseEvalObject(name,parent, list, var_list, startIdx); + break; + case 'b': + ParseEvalBool(name,parent, list, var_list, startIdx); + break; + case 'z': + ParseEvalResource(name,parent, list, var_list, startIdx); + break; + case 'R': + ParseEvalRef(name,parent, list, var_list, false, startIdx); + break; + case 'r': + ParseEvalRef(name,parent, list, var_list, true, startIdx); + break; + } + } catch (DebugException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } +/* if (!ret_val) { // try to recover + unsigned int i=*startIdx; + while (i