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;
24 public class PHPDBGEvalString {
27 private PHPStackFrame fStackFrame;
29 public PHPDBGEvalString(PHPStackFrame stack,String dataStr) {
34 String ExtractSubStr(char chstart, char chend,int startIdx) throws DebugException {
37 if (idx >= (workStr.length() - 1) || workStr.charAt(idx) != chstart) {
38 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"worng startIdx!",null);
39 throw new DebugException(status);
42 i = workStr.indexOf(chend, i);
44 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"endchar not found!",null);
45 throw new DebugException(status);
47 rslt=workStr.substring(idx,i);
49 workStr=workStr.substring(i+1);
53 String ExtractQuotedSubStr(int slen,int startIdx) throws DebugException {
56 if (idx+slen+1 >= workStr.length() ||
57 workStr.charAt(idx)!= '"' ||
58 workStr.charAt(idx+slen+1) != '"') {
59 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no quoted substring found!",null);
60 throw new DebugException(status);
62 rslt=workStr.substring(idx+1, idx+1+slen);
63 workStr=workStr.substring(idx+2+slen);
68 int ExtractInt(char chstart, char chend,int startIdx) throws DebugException {
71 subs=ExtractSubStr(chstart, chend,startIdx);
72 return (Integer.parseInt(subs));
75 PHPVariable ParseEvalArray(String name, PHPVariable parent,Vector list, Vector var_list, String classname, int atype) throws DebugException{
81 arritems= ExtractInt(':', ':',0);
82 if ((workStr.length()>0)&&(workStr.charAt(0)!='{')) {
83 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no array startcharecter!",null);
84 throw new DebugException(status);
86 workStr=workStr.substring(1);
87 item= new PHPVariable(fStackFrame,name,parent,classname,atype,null);
92 subitems = new Vector();
94 if (workStr.charAt(0)!='}')
96 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no array endcharecter!",null);
97 throw new DebugException(status);
99 while ((workStr.length()>0) && (workStr.charAt(0)!='}')) {
100 Vector tmplst=new Vector();
102 parse("",null, tmplst, null, false,0);
103 if(tmplst.size()!=1){
104 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no name found!",null);
105 throw new DebugException(status);
108 parse(((PHPVariable)tmplst.elementAt(0)).getValue().getValueString(),item, subitems, var_list, true,0);
111 ((PHPValue)item.getValue()).addVariable(subitems);
112 workStr=workStr.substring(1);
116 void ParseEvalNULL(String name,PHPVariable parent,Vector list, Vector var_list, int startIdx) throws DebugException {
118 if (idx >= workStr.length() || workStr.charAt(idx) != ';') {
119 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"NULL not found!",null);
120 throw new DebugException(status);
122 workStr=workStr.substring(1);
123 PHPVariable item= new PHPVariable(fStackFrame, name,parent,"NULL",PHPValue.PEVT_UNKNOWN,null);
129 boolean ParseEvalInt( String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
132 subs = ExtractSubStr(':',';',startIdx);
133 item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_LONG,null);
140 boolean ParseEvalDouble(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
143 subs = ExtractSubStr(':',';',startIdx);
144 item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_DOUBLE,null);
151 boolean ParseEvalString(String name,PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr, int startIdx)
152 throws DebugException{
154 slen= ExtractInt( ':', ':',startIdx);
155 if ((workStr.length()<=slen)||(workStr.charAt(0)!='"')) {
156 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no String startcharecter!",null);
157 throw new DebugException(status);
159 workStr=workStr.substring(1);
160 String subs = workStr.substring(0,slen);
162 subs=subs.replaceAll("\\\\\\\\","\\\\");
163 if (workStr.charAt(slen)!='"') {
164 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no String endcharecter!",null);
165 throw new DebugException(status);
167 workStr=workStr.substring(slen+2);
170 ConvertToPhpString(subs, &subs);
173 PHPVariable item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_STRING,null);
180 boolean ParseEvalBool(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
181 throws DebugException{
183 v=ExtractInt(':', ';',startIdx);
184 PHPVariable item= new PHPVariable(fStackFrame, name,parent,(v==0)?("FALSE"):("TRUE"),PHPValue.PEVT_BOOLEAN,null);
191 boolean ParseEvalObject(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
192 throws DebugException{
196 slen=ExtractInt(':', ':',startIdx);
197 classname= ExtractQuotedSubStr(slen, startIdx);
198 if ((int)classname.length()!=slen) return false;
199 ParseEvalArray(name,parent, list, var_list, classname,PHPValue.PEVT_OBJECT);
203 boolean ParseEvalResource(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
204 throws DebugException{
208 slen=ExtractInt(':', ':',startIdx);
209 restype=ExtractQuotedSubStr(slen, startIdx);
210 v=ExtractInt(':', ';',startIdx);
211 // std_sprintf(val, "%ld", v);
212 // list->Add(var_list, name, val, ptResource, restype);
217 boolean ParseEvalRef(String name,PHPVariable parent, Vector list, Vector var_list, boolean isSoftRef, int startIdx)
218 throws DebugException{
221 v=ExtractInt(':', ';',startIdx);
223 PHPVariable item= new PHPVariable(fStackFrame, name,parent,"",(isSoftRef)? (PHPValue.PEVT_SOFTREF): (PHPValue.PEVT_REF),null);
224 v--; // ref ID is 1-based, EvalList is 0-based
227 if ((var_list==null) || (v<0) || (v >= var_list.size())) {
228 // item.ref = item; // self-resolving
231 PHPVariable var_item=(PHPVariable)var_list.get(v);
233 item.setValue(var_item.getValue());
234 item.setReferenceType(var_item.getReferenceType());
235 ((PHPValue)item.getValue()).setParent(item);
236 } catch (DebugException e) {
237 // TODO Auto-generated catch block
247 public PHPVariable[] getVars(){
248 Vector list=new Vector();
249 Vector var_list=new Vector();
250 parse("",null,list,var_list,false,0);
251 return (PHPVariable[])list.toArray(new PHPVariable[list.size()]);
254 boolean parse(String name,PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr,int startIdx) {
255 boolean ret_val = false;
257 if (startIdx >= workStr.length()) return false;
258 char ch = workStr.charAt(startIdx);
259 workStr=workStr.substring(1);
263 ParseEvalNULL(name,parent, list, var_list, startIdx);
266 ParseEvalInt(name,parent, list, var_list, startIdx);
269 ParseEvalDouble(name,parent, list, var_list, startIdx);
272 ParseEvalString(name,parent, list, var_list, MakePhpStr, startIdx);
275 ParseEvalArray(name,parent, list, var_list, "", PHPValue.PEVT_ARRAY);
278 ParseEvalObject(name,parent, list, var_list, startIdx);
281 ParseEvalBool(name,parent, list, var_list, startIdx);
284 ParseEvalResource(name,parent, list, var_list, startIdx);
287 ParseEvalRef(name,parent, list, var_list, false, startIdx);
290 ParseEvalRef(name,parent, list, var_list, true, startIdx);
293 } catch (DebugException e) {
294 // TODO Auto-generated catch block
297 /* if (!ret_val) { // try to recover
298 unsigned int i=*startIdx;
299 while (i<str.length() && str[i]!='{' && str[i]!=';') i++;
300 if (i<str.length() && str[i] == '{') {
303 while (i<str.length() && cnt!=0) {
306 else if (str[i] == '}')