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 org.eclipse.debug.core.DebugException;
19 import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
20 import org.eclipse.core.runtime.Status;
23 public class PHPDBGEvalString {
26 private PHPStackFrame fStackFrame;
28 public PHPDBGEvalString(PHPStackFrame stack,String dataStr) {
33 String ExtractSubStr(char chstart, char chend,int startIdx) throws DebugException {
36 if (idx >= (workStr.length() - 1) || workStr.charAt(idx) != chstart) {
37 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"worng startIdx!",null);
38 throw new DebugException(status);
41 i = workStr.indexOf(chend, i);
43 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"endchar not found!",null);
44 throw new DebugException(status);
46 rslt=workStr.substring(idx,i);
48 workStr=workStr.substring(i+1);
52 String ExtractQuotedSubStr(int slen,int startIdx) throws DebugException {
55 if (idx+slen+1 >= workStr.length() ||
56 workStr.charAt(idx)!= '"' ||
57 workStr.charAt(idx+slen+1) != '"') {
58 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no quoted substring found!",null);
59 throw new DebugException(status);
61 rslt=workStr.substring(idx+1, idx+1+slen);
62 workStr=workStr.substring(idx+2+slen);
67 int ExtractInt(char chstart, char chend,int startIdx) throws DebugException {
70 subs=ExtractSubStr(chstart, chend,startIdx);
71 return (Integer.parseInt(subs));
74 PHPVariable ParseEvalArray(String name, PHPVariable parent,Vector list, Vector var_list, String classname, int atype) throws DebugException{
80 arritems= ExtractInt(':', ':',0);
81 if ((workStr.length()>0)&&(workStr.charAt(0)!='{')) {
82 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no array startcharecter!",null);
83 throw new DebugException(status);
85 workStr=workStr.substring(1);
86 item= new PHPVariable(fStackFrame,name,parent,classname,atype,null);
91 subitems = new Vector();
93 if (workStr.charAt(0)!='}')
95 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no array endcharecter!",null);
96 throw new DebugException(status);
98 while ((workStr.length()>0) && (workStr.charAt(0)!='}')) {
99 Vector tmplst=new Vector();
101 parse("",null, tmplst, null, false,0);
102 if(tmplst.size()!=1){
103 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no name found!",null);
104 throw new DebugException(status);
107 parse(((PHPVariable)tmplst.elementAt(0)).getValue().getValueString(),item, subitems, var_list, true,0);
110 ((PHPValue)item.getValue()).addVariable(subitems);
111 workStr=workStr.substring(1);
115 void ParseEvalNULL(String name,PHPVariable parent,Vector list, Vector var_list, int startIdx) throws DebugException {
117 if (idx >= workStr.length() || workStr.charAt(idx) != ';') {
118 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"NULL not found!",null);
119 throw new DebugException(status);
121 workStr=workStr.substring(1);
122 PHPVariable item= new PHPVariable(fStackFrame, name,parent,"NULL",PHPValue.PEVT_UNKNOWN,null);
128 boolean ParseEvalInt( String name, PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
131 subs = ExtractSubStr(':',';',startIdx);
132 item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_LONG,null);
139 boolean ParseEvalDouble(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx) throws DebugException {
142 subs = ExtractSubStr(':',';',startIdx);
143 item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_DOUBLE,null);
150 boolean ParseEvalString(String name,PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr, int startIdx)
151 throws DebugException{
153 slen= ExtractInt( ':', ':',startIdx);
154 if ((workStr.length()<=slen)||(workStr.charAt(0)!='"')) {
155 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no String startcharecter!",null);
156 throw new DebugException(status);
158 workStr=workStr.substring(1);
159 String subs = workStr.substring(0,slen);
161 subs=subs.replaceAll("\\\\\\\\","\\\\");
162 if (workStr.charAt(slen)!='"') {
163 Status status= new Status(Status.ERROR,PHPDebugCorePlugin.getUniqueIdentifier(),Status.OK,"no String endcharecter!",null);
164 throw new DebugException(status);
166 workStr=workStr.substring(slen+2);
169 ConvertToPhpString(subs, &subs);
172 PHPVariable item= new PHPVariable(fStackFrame, name,parent,subs,PHPValue.PEVT_STRING,null);
179 boolean ParseEvalBool(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
180 throws DebugException{
182 v=ExtractInt(':', ';',startIdx);
183 PHPVariable item= new PHPVariable(fStackFrame, name,parent,(v==0)?("FALSE"):("TRUE"),PHPValue.PEVT_BOOLEAN,null);
190 boolean ParseEvalObject(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
191 throws DebugException{
195 slen=ExtractInt(':', ':',startIdx);
196 classname= ExtractQuotedSubStr(slen, startIdx);
197 if ((int)classname.length()!=slen) return false;
198 ParseEvalArray(name,parent, list, var_list, classname,PHPValue.PEVT_OBJECT);
202 boolean ParseEvalResource(String name,PHPVariable parent, Vector list, Vector var_list, int startIdx)
203 throws DebugException{
207 slen=ExtractInt(':', ':',startIdx);
208 restype=ExtractQuotedSubStr(slen, startIdx);
209 v=ExtractInt(':', ';',startIdx);
210 // std_sprintf(val, "%ld", v);
211 // list->Add(var_list, name, val, ptResource, restype);
216 boolean ParseEvalRef(String name,PHPVariable parent, Vector list, Vector var_list, boolean isSoftRef, int startIdx)
217 throws DebugException{
220 v=ExtractInt(':', ';',startIdx);
222 PHPVariable item= new PHPVariable(fStackFrame, name,parent,"",(isSoftRef)? (PHPValue.PEVT_SOFTREF): (PHPValue.PEVT_REF),null);
223 v--; // ref ID is 1-based, EvalList is 0-based
226 if ((var_list==null) || (v<0) || (v >= var_list.size())) {
227 // item.ref = item; // self-resolving
230 PHPVariable var_item=(PHPVariable)var_list.get(v);
232 item.setValue(var_item.getValue());
233 item.setReferenceType(var_item.getReferenceType());
234 ((PHPValue)item.getValue()).setParent(item);
235 } catch (DebugException e) {
236 // TODO Auto-generated catch block
246 public PHPVariable[] getVars(){
247 Vector list=new Vector();
248 Vector var_list=new Vector();
249 parse("",null,list,var_list,false,0);
250 return (PHPVariable[])list.toArray(new PHPVariable[list.size()]);
253 boolean parse(String name,PHPVariable parent, Vector list, Vector var_list, boolean MakePhpStr,int startIdx) {
254 boolean ret_val = false;
256 if (startIdx >= workStr.length()) return false;
257 char ch = workStr.charAt(startIdx);
258 workStr=workStr.substring(1);
262 ParseEvalNULL(name,parent, list, var_list, startIdx);
265 ParseEvalInt(name,parent, list, var_list, startIdx);
268 ParseEvalDouble(name,parent, list, var_list, startIdx);
271 ParseEvalString(name,parent, list, var_list, MakePhpStr, startIdx);
274 ParseEvalArray(name,parent, list, var_list, "", PHPValue.PEVT_ARRAY);
277 ParseEvalObject(name,parent, list, var_list, startIdx);
280 ParseEvalBool(name,parent, list, var_list, startIdx);
283 ParseEvalResource(name,parent, list, var_list, startIdx);
286 ParseEvalRef(name,parent, list, var_list, false, startIdx);
289 ParseEvalRef(name,parent, list, var_list, true, startIdx);
292 } catch (DebugException e) {
293 // TODO Auto-generated catch block
296 /* if (!ret_val) { // try to recover
297 unsigned int i=*startIdx;
298 while (i<str.length() && str[i]!='{' && str[i]!=';') i++;
299 if (i<str.length() && str[i] == '{') {
302 while (i<str.length() && cnt!=0) {
305 else if (str[i] == '}')