ntdll/tests: Introduce enumeration to handle stages in test_debugger().
[wine.git] / dlls / vbscript / vbscript.h
blob24915a5ca0402611e81608091565493719a97540
1 /*
2 * Copyright 2011 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <stdint.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "ole2.h"
27 #include "dispex.h"
28 #include "activscp.h"
29 #include "activdbg.h"
31 #include "vbscript_classes.h"
32 #include "vbscript_defs.h"
34 #include "wine/list.h"
36 typedef struct {
37 void **blocks;
38 DWORD block_cnt;
39 DWORD last_block;
40 DWORD offset;
41 BOOL mark;
42 struct list custom_blocks;
43 } heap_pool_t;
45 void heap_pool_init(heap_pool_t*);
46 void *heap_pool_alloc(heap_pool_t*,size_t) __WINE_ALLOC_SIZE(2);
47 void *heap_pool_grow(heap_pool_t*,void*,DWORD,DWORD);
48 void heap_pool_clear(heap_pool_t*);
49 void heap_pool_free(heap_pool_t*);
50 heap_pool_t *heap_pool_mark(heap_pool_t*);
52 typedef struct _function_t function_t;
53 typedef struct _vbscode_t vbscode_t;
54 typedef struct _script_ctx_t script_ctx_t;
55 typedef struct _vbdisp_t vbdisp_t;
57 typedef enum {
58 VBDISP_CALLGET,
59 VBDISP_LET,
60 VBDISP_SET,
61 VBDISP_ANY
62 } vbdisp_invoke_type_t;
64 typedef struct {
65 unsigned dim_cnt;
66 SAFEARRAYBOUND *bounds;
67 } array_desc_t;
69 typedef struct {
70 BOOL is_public;
71 BOOL is_array;
72 const WCHAR *name;
73 } vbdisp_prop_desc_t;
75 typedef struct {
76 const WCHAR *name;
77 BOOL is_public;
78 BOOL is_array;
79 function_t *entries[VBDISP_ANY];
80 } vbdisp_funcprop_desc_t;
82 typedef struct _class_desc_t {
83 const WCHAR *name;
84 script_ctx_t *ctx;
86 unsigned class_initialize_id;
87 unsigned class_terminate_id;
88 unsigned func_cnt;
89 vbdisp_funcprop_desc_t *funcs;
91 unsigned prop_cnt;
92 vbdisp_prop_desc_t *props;
94 unsigned array_cnt;
95 array_desc_t *array_descs;
97 function_t *value_func;
99 struct _class_desc_t *next;
100 } class_desc_t;
102 struct _vbdisp_t {
103 IDispatchEx IDispatchEx_iface;
105 LONG ref;
106 BOOL terminator_ran;
107 struct list entry;
109 const class_desc_t *desc;
110 SAFEARRAY **arrays;
111 VARIANT props[1];
114 typedef struct _dynamic_var_t {
115 struct _dynamic_var_t *next;
116 VARIANT v;
117 const WCHAR *name;
118 BOOL is_const;
119 SAFEARRAY *array;
120 } dynamic_var_t;
122 typedef struct {
123 IDispatchEx IDispatchEx_iface;
124 LONG ref;
126 dynamic_var_t **global_vars;
127 size_t global_vars_cnt;
128 size_t global_vars_size;
130 function_t **global_funcs;
131 size_t global_funcs_cnt;
132 size_t global_funcs_size;
134 class_desc_t *classes;
136 script_ctx_t *ctx;
137 heap_pool_t heap;
139 unsigned int rnd;
140 } ScriptDisp;
142 typedef struct _builtin_prop_t builtin_prop_t;
144 typedef struct {
145 IDispatch IDispatch_iface;
146 LONG ref;
147 size_t member_cnt;
148 const builtin_prop_t *members;
149 script_ctx_t *ctx;
150 } BuiltinDisp;
152 typedef struct named_item_t {
153 ScriptDisp *script_obj;
154 IDispatch *disp;
155 unsigned ref;
156 DWORD flags;
157 LPWSTR name;
159 struct list entry;
160 } named_item_t;
162 HRESULT create_vbdisp(const class_desc_t*,vbdisp_t**);
163 HRESULT disp_get_id(IDispatch*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*);
164 HRESULT vbdisp_get_id(vbdisp_t*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*);
165 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*);
166 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,WORD,DISPPARAMS*);
167 HRESULT get_disp_value(script_ctx_t*,IDispatch*,VARIANT*);
168 void collect_objects(script_ctx_t*);
169 HRESULT create_script_disp(script_ctx_t*,ScriptDisp**);
171 HRESULT to_int(VARIANT*,int*);
173 static inline unsigned arg_cnt(const DISPPARAMS *dp)
175 return dp->cArgs - dp->cNamedArgs;
178 static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
180 return dp->rgvarg + dp->cArgs-i-1;
183 #define SP_CALLER_UNINITIALIZED ((IServiceProvider*)IntToPtr(-1))
185 struct vbcaller {
186 IServiceProvider IServiceProvider_iface;
188 LONG ref;
190 IServiceProvider *caller;
193 struct _script_ctx_t {
194 IActiveScriptSite *site;
195 LCID lcid;
196 UINT codepage;
198 IInternetHostSecurityManager *secmgr;
199 struct vbcaller *vbcaller;
200 DWORD safeopt;
202 ScriptDisp *script_obj;
204 BuiltinDisp *global_obj;
205 BuiltinDisp *err_obj;
207 EXCEPINFO ei;
208 vbscode_t *error_loc_code;
209 unsigned error_loc_offset;
211 struct list objects;
212 struct list code_list;
213 struct list named_items;
216 HRESULT init_global(script_ctx_t*);
217 HRESULT init_err(script_ctx_t*);
219 IUnknown *create_ax_site(script_ctx_t*);
221 typedef enum {
222 ARG_NONE = 0,
223 ARG_STR,
224 ARG_BSTR,
225 ARG_INT,
226 ARG_UINT,
227 ARG_ADDR,
228 ARG_DOUBLE,
229 ARG_DATE
230 } instr_arg_type_t;
232 #define OP_LIST \
233 X(add, 1, 0, 0) \
234 X(and, 1, 0, 0) \
235 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
236 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
237 X(bool, 1, ARG_INT, 0) \
238 X(catch, 1, ARG_ADDR, ARG_UINT) \
239 X(case, 0, ARG_ADDR, 0) \
240 X(concat, 1, 0, 0) \
241 X(const, 1, ARG_BSTR, 0) \
242 X(date, 1, ARG_DATE, 0) \
243 X(deref, 1, 0, 0) \
244 X(dim, 1, ARG_BSTR, ARG_UINT) \
245 X(div, 1, 0, 0) \
246 X(double, 1, ARG_DOUBLE, 0) \
247 X(empty, 1, 0, 0) \
248 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
249 X(equal, 1, 0, 0) \
250 X(hres, 1, ARG_UINT, 0) \
251 X(errmode, 1, ARG_INT, 0) \
252 X(eqv, 1, 0, 0) \
253 X(exp, 1, 0, 0) \
254 X(gt, 1, 0, 0) \
255 X(gteq, 1, 0, 0) \
256 X(icall, 1, ARG_BSTR, ARG_UINT) \
257 X(icallv, 1, ARG_BSTR, ARG_UINT) \
258 X(ident, 1, ARG_BSTR, 0) \
259 X(idiv, 1, 0, 0) \
260 X(imp, 1, 0, 0) \
261 X(incc, 1, ARG_BSTR, 0) \
262 X(int, 1, ARG_INT, 0) \
263 X(is, 1, 0, 0) \
264 X(jmp, 0, ARG_ADDR, 0) \
265 X(jmp_false, 0, ARG_ADDR, 0) \
266 X(jmp_true, 0, ARG_ADDR, 0) \
267 X(lt, 1, 0, 0) \
268 X(lteq, 1, 0, 0) \
269 X(mcall, 1, ARG_BSTR, ARG_UINT) \
270 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
271 X(me, 1, 0, 0) \
272 X(mod, 1, 0, 0) \
273 X(mul, 1, 0, 0) \
274 X(neg, 1, 0, 0) \
275 X(nequal, 1, 0, 0) \
276 X(new, 1, ARG_STR, 0) \
277 X(newenum, 1, 0, 0) \
278 X(not, 1, 0, 0) \
279 X(nothing, 1, 0, 0) \
280 X(null, 1, 0, 0) \
281 X(or, 1, 0, 0) \
282 X(pop, 1, ARG_UINT, 0) \
283 X(redim, 1, ARG_BSTR, ARG_UINT) \
284 X(redim_preserve, 1, ARG_BSTR, ARG_UINT) \
285 X(ret, 0, 0, 0) \
286 X(retval, 1, 0, 0) \
287 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
288 X(set_member, 1, ARG_BSTR, ARG_UINT) \
289 X(stack, 1, ARG_UINT, 0) \
290 X(step, 0, ARG_ADDR, ARG_BSTR) \
291 X(stop, 1, 0, 0) \
292 X(string, 1, ARG_STR, 0) \
293 X(sub, 1, 0, 0) \
294 X(val, 1, 0, 0) \
295 X(vcall, 1, ARG_UINT, 0) \
296 X(vcallv, 1, ARG_UINT, 0) \
297 X(xor, 1, 0, 0)
299 typedef enum {
300 #define X(x,n,a,b) OP_##x,
301 OP_LIST
302 #undef X
303 OP_LAST
304 } vbsop_t;
306 typedef union {
307 const WCHAR *str;
308 BSTR bstr;
309 unsigned uint;
310 LONG lng;
311 double *dbl;
312 DATE *date;
313 } instr_arg_t;
315 typedef struct {
316 vbsop_t op;
317 unsigned loc;
318 instr_arg_t arg1;
319 instr_arg_t arg2;
320 } instr_t;
322 typedef struct {
323 const WCHAR *name;
324 BOOL by_ref;
325 } arg_desc_t;
327 typedef enum {
328 FUNC_GLOBAL,
329 FUNC_FUNCTION,
330 FUNC_SUB,
331 FUNC_PROPGET,
332 FUNC_PROPLET,
333 FUNC_PROPSET,
334 } function_type_t;
336 typedef struct {
337 const WCHAR *name;
338 } var_desc_t;
340 struct _function_t {
341 function_type_t type;
342 const WCHAR *name;
343 BOOL is_public;
344 arg_desc_t *args;
345 unsigned arg_cnt;
346 var_desc_t *vars;
347 unsigned var_cnt;
348 array_desc_t *array_descs;
349 unsigned array_cnt;
350 unsigned code_off;
351 vbscode_t *code_ctx;
352 function_t *next;
355 struct _vbscode_t {
356 instr_t *instrs;
357 unsigned ref;
359 WCHAR *source;
360 DWORD_PTR cookie;
361 unsigned start_line;
363 BOOL option_explicit;
365 BOOL pending_exec;
366 BOOL is_persistent;
367 function_t main_code;
368 named_item_t *named_item;
370 BSTR *bstr_pool;
371 unsigned bstr_pool_size;
372 unsigned bstr_cnt;
373 heap_pool_t heap;
375 function_t *funcs;
376 class_desc_t *classes;
377 class_desc_t *last_class;
379 struct list entry;
382 static inline void grab_vbscode(vbscode_t *code)
384 code->ref++;
387 void release_vbscode(vbscode_t*);
388 HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,const WCHAR*,DWORD_PTR,unsigned,DWORD,vbscode_t**);
389 HRESULT compile_procedure(script_ctx_t*,const WCHAR*,const WCHAR*,const WCHAR*,DWORD_PTR,unsigned,DWORD,class_desc_t**);
390 HRESULT exec_script(script_ctx_t*,BOOL,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*);
391 void release_dynamic_var(dynamic_var_t*);
392 named_item_t *lookup_named_item(script_ctx_t*,const WCHAR*,unsigned);
393 void release_named_item(named_item_t*);
394 void clear_ei(EXCEPINFO*);
395 HRESULT report_script_error(script_ctx_t*,const vbscode_t*,unsigned);
396 void detach_global_objects(script_ctx_t*);
397 HRESULT get_builtin_id(BuiltinDisp*,const WCHAR*,DISPID*);
398 HRESULT array_access(SAFEARRAY *array, DISPPARAMS *dp, VARIANT **ret);
400 void release_regexp_typelib(void);
401 HRESULT get_dispatch_typeinfo(ITypeInfo**);
403 static inline BOOL is_int32(double d)
405 return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
408 static inline BOOL is_digit(WCHAR c)
410 return '0' <= c && c <= '9';
413 HRESULT create_regexp(IDispatch**);
414 BSTR string_replace(BSTR,BSTR,BSTR,int,int,int);
416 void map_vbs_exception(EXCEPINFO *);
418 HRESULT create_safearray_iter(SAFEARRAY *sa, BOOL owned, IEnumVARIANT **ev);
420 #define FACILITY_VBS 0xa
421 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
423 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
424 HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**);
426 BSTR get_vbscript_string(int);
428 #define VBSCRIPT_BUILD_VERSION 16978
429 #define VBSCRIPT_MAJOR_VERSION 5
430 #define VBSCRIPT_MINOR_VERSION 8