mfplat/tests: Add a separate test function for MFGetPlaneSize().
[wine.git] / dlls / vbscript / vbscript.h
blobf5353b33caee4ead6fca21fd2fa16f3bc09ce0e8
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/heap.h"
35 #include "wine/list.h"
37 typedef struct {
38 void **blocks;
39 DWORD block_cnt;
40 DWORD last_block;
41 DWORD offset;
42 BOOL mark;
43 struct list custom_blocks;
44 } heap_pool_t;
46 void heap_pool_init(heap_pool_t*) DECLSPEC_HIDDEN;
47 void *heap_pool_alloc(heap_pool_t*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN;
48 void *heap_pool_grow(heap_pool_t*,void*,DWORD,DWORD) DECLSPEC_HIDDEN;
49 void heap_pool_clear(heap_pool_t*) DECLSPEC_HIDDEN;
50 void heap_pool_free(heap_pool_t*) DECLSPEC_HIDDEN;
51 heap_pool_t *heap_pool_mark(heap_pool_t*) DECLSPEC_HIDDEN;
53 typedef struct _function_t function_t;
54 typedef struct _vbscode_t vbscode_t;
55 typedef struct _script_ctx_t script_ctx_t;
56 typedef struct _vbdisp_t vbdisp_t;
58 typedef enum {
59 VBDISP_CALLGET,
60 VBDISP_LET,
61 VBDISP_SET,
62 VBDISP_ANY
63 } vbdisp_invoke_type_t;
65 typedef struct {
66 unsigned dim_cnt;
67 SAFEARRAYBOUND *bounds;
68 } array_desc_t;
70 typedef struct {
71 BOOL is_public;
72 BOOL is_array;
73 const WCHAR *name;
74 } vbdisp_prop_desc_t;
76 typedef struct {
77 const WCHAR *name;
78 BOOL is_public;
79 BOOL is_array;
80 function_t *entries[VBDISP_ANY];
81 } vbdisp_funcprop_desc_t;
83 typedef struct _class_desc_t {
84 const WCHAR *name;
85 script_ctx_t *ctx;
87 unsigned class_initialize_id;
88 unsigned class_terminate_id;
89 unsigned func_cnt;
90 vbdisp_funcprop_desc_t *funcs;
92 unsigned prop_cnt;
93 vbdisp_prop_desc_t *props;
95 unsigned array_cnt;
96 array_desc_t *array_descs;
98 function_t *value_func;
100 struct _class_desc_t *next;
101 } class_desc_t;
103 struct _vbdisp_t {
104 IDispatchEx IDispatchEx_iface;
106 LONG ref;
107 BOOL terminator_ran;
108 struct list entry;
110 const class_desc_t *desc;
111 SAFEARRAY **arrays;
112 VARIANT props[1];
115 typedef struct _dynamic_var_t {
116 struct _dynamic_var_t *next;
117 VARIANT v;
118 const WCHAR *name;
119 BOOL is_const;
120 SAFEARRAY *array;
121 } dynamic_var_t;
123 typedef struct {
124 IDispatchEx IDispatchEx_iface;
125 LONG ref;
127 dynamic_var_t **global_vars;
128 size_t global_vars_cnt;
129 size_t global_vars_size;
131 function_t **global_funcs;
132 size_t global_funcs_cnt;
133 size_t global_funcs_size;
135 class_desc_t *classes;
137 script_ctx_t *ctx;
138 heap_pool_t heap;
139 } ScriptDisp;
141 typedef struct _builtin_prop_t builtin_prop_t;
143 typedef struct {
144 IDispatch IDispatch_iface;
145 LONG ref;
146 size_t member_cnt;
147 const builtin_prop_t *members;
148 script_ctx_t *ctx;
149 } BuiltinDisp;
151 typedef struct named_item_t {
152 ScriptDisp *script_obj;
153 IDispatch *disp;
154 unsigned ref;
155 DWORD flags;
156 LPWSTR name;
158 struct list entry;
159 } named_item_t;
161 HRESULT create_vbdisp(const class_desc_t*,vbdisp_t**) DECLSPEC_HIDDEN;
162 HRESULT disp_get_id(IDispatch*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*) DECLSPEC_HIDDEN;
163 HRESULT vbdisp_get_id(vbdisp_t*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*) DECLSPEC_HIDDEN;
164 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
165 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,WORD,DISPPARAMS*) DECLSPEC_HIDDEN;
166 HRESULT get_disp_value(script_ctx_t*,IDispatch*,VARIANT*) DECLSPEC_HIDDEN;
167 void collect_objects(script_ctx_t*) DECLSPEC_HIDDEN;
168 HRESULT create_script_disp(script_ctx_t*,ScriptDisp**) DECLSPEC_HIDDEN;
170 HRESULT to_int(VARIANT*,int*) DECLSPEC_HIDDEN;
172 static inline unsigned arg_cnt(const DISPPARAMS *dp)
174 return dp->cArgs - dp->cNamedArgs;
177 static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
179 return dp->rgvarg + dp->cArgs-i-1;
182 struct _script_ctx_t {
183 IActiveScriptSite *site;
184 LCID lcid;
186 IInternetHostSecurityManager *secmgr;
187 DWORD safeopt;
189 ScriptDisp *script_obj;
191 BuiltinDisp *global_obj;
192 BuiltinDisp *err_obj;
194 EXCEPINFO ei;
195 vbscode_t *error_loc_code;
196 unsigned error_loc_offset;
198 struct list objects;
199 struct list code_list;
200 struct list named_items;
203 HRESULT init_global(script_ctx_t*) DECLSPEC_HIDDEN;
204 HRESULT init_err(script_ctx_t*) DECLSPEC_HIDDEN;
206 IUnknown *create_ax_site(script_ctx_t*) DECLSPEC_HIDDEN;
208 typedef enum {
209 ARG_NONE = 0,
210 ARG_STR,
211 ARG_BSTR,
212 ARG_INT,
213 ARG_UINT,
214 ARG_ADDR,
215 ARG_DOUBLE,
216 ARG_DATE
217 } instr_arg_type_t;
219 #define OP_LIST \
220 X(add, 1, 0, 0) \
221 X(and, 1, 0, 0) \
222 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
223 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
224 X(bool, 1, ARG_INT, 0) \
225 X(catch, 1, ARG_ADDR, ARG_UINT) \
226 X(case, 0, ARG_ADDR, 0) \
227 X(concat, 1, 0, 0) \
228 X(const, 1, ARG_BSTR, 0) \
229 X(date, 1, ARG_DATE, 0) \
230 X(deref, 1, 0, 0) \
231 X(dim, 1, ARG_BSTR, ARG_UINT) \
232 X(div, 1, 0, 0) \
233 X(double, 1, ARG_DOUBLE, 0) \
234 X(empty, 1, 0, 0) \
235 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
236 X(equal, 1, 0, 0) \
237 X(hres, 1, ARG_UINT, 0) \
238 X(errmode, 1, ARG_INT, 0) \
239 X(eqv, 1, 0, 0) \
240 X(exp, 1, 0, 0) \
241 X(gt, 1, 0, 0) \
242 X(gteq, 1, 0, 0) \
243 X(icall, 1, ARG_BSTR, ARG_UINT) \
244 X(icallv, 1, ARG_BSTR, ARG_UINT) \
245 X(ident, 1, ARG_BSTR, 0) \
246 X(idiv, 1, 0, 0) \
247 X(imp, 1, 0, 0) \
248 X(incc, 1, ARG_BSTR, 0) \
249 X(int, 1, ARG_INT, 0) \
250 X(is, 1, 0, 0) \
251 X(jmp, 0, ARG_ADDR, 0) \
252 X(jmp_false, 0, ARG_ADDR, 0) \
253 X(jmp_true, 0, ARG_ADDR, 0) \
254 X(lt, 1, 0, 0) \
255 X(lteq, 1, 0, 0) \
256 X(mcall, 1, ARG_BSTR, ARG_UINT) \
257 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
258 X(me, 1, 0, 0) \
259 X(mod, 1, 0, 0) \
260 X(mul, 1, 0, 0) \
261 X(neg, 1, 0, 0) \
262 X(nequal, 1, 0, 0) \
263 X(new, 1, ARG_STR, 0) \
264 X(newenum, 1, 0, 0) \
265 X(not, 1, 0, 0) \
266 X(nothing, 1, 0, 0) \
267 X(null, 1, 0, 0) \
268 X(or, 1, 0, 0) \
269 X(pop, 1, ARG_UINT, 0) \
270 X(redim, 1, ARG_BSTR, ARG_UINT) \
271 X(redim_preserve, 1, ARG_BSTR, ARG_UINT) \
272 X(ret, 0, 0, 0) \
273 X(retval, 1, 0, 0) \
274 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
275 X(set_member, 1, ARG_BSTR, ARG_UINT) \
276 X(stack, 1, ARG_UINT, 0) \
277 X(step, 0, ARG_ADDR, ARG_BSTR) \
278 X(stop, 1, 0, 0) \
279 X(string, 1, ARG_STR, 0) \
280 X(sub, 1, 0, 0) \
281 X(val, 1, 0, 0) \
282 X(vcall, 1, ARG_UINT, 0) \
283 X(vcallv, 1, ARG_UINT, 0) \
284 X(xor, 1, 0, 0)
286 typedef enum {
287 #define X(x,n,a,b) OP_##x,
288 OP_LIST
289 #undef X
290 OP_LAST
291 } vbsop_t;
293 typedef union {
294 const WCHAR *str;
295 BSTR bstr;
296 unsigned uint;
297 LONG lng;
298 double *dbl;
299 DATE *date;
300 } instr_arg_t;
302 typedef struct {
303 vbsop_t op;
304 unsigned loc;
305 instr_arg_t arg1;
306 instr_arg_t arg2;
307 } instr_t;
309 typedef struct {
310 const WCHAR *name;
311 BOOL by_ref;
312 } arg_desc_t;
314 typedef enum {
315 FUNC_GLOBAL,
316 FUNC_FUNCTION,
317 FUNC_SUB,
318 FUNC_PROPGET,
319 FUNC_PROPLET,
320 FUNC_PROPSET,
321 } function_type_t;
323 typedef struct {
324 const WCHAR *name;
325 } var_desc_t;
327 struct _function_t {
328 function_type_t type;
329 const WCHAR *name;
330 BOOL is_public;
331 arg_desc_t *args;
332 unsigned arg_cnt;
333 var_desc_t *vars;
334 unsigned var_cnt;
335 array_desc_t *array_descs;
336 unsigned array_cnt;
337 unsigned code_off;
338 vbscode_t *code_ctx;
339 function_t *next;
342 struct _vbscode_t {
343 instr_t *instrs;
344 unsigned ref;
346 WCHAR *source;
347 DWORD_PTR cookie;
348 unsigned start_line;
350 BOOL option_explicit;
352 BOOL pending_exec;
353 BOOL is_persistent;
354 function_t main_code;
355 named_item_t *named_item;
357 BSTR *bstr_pool;
358 unsigned bstr_pool_size;
359 unsigned bstr_cnt;
360 heap_pool_t heap;
362 function_t *funcs;
363 class_desc_t *classes;
364 class_desc_t *last_class;
366 struct list entry;
369 static inline void grab_vbscode(vbscode_t *code)
371 code->ref++;
374 void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
375 HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,const WCHAR*,DWORD_PTR,unsigned,DWORD,vbscode_t**) DECLSPEC_HIDDEN;
376 HRESULT compile_procedure(script_ctx_t*,const WCHAR*,const WCHAR*,const WCHAR*,DWORD_PTR,unsigned,DWORD,class_desc_t**) DECLSPEC_HIDDEN;
377 HRESULT exec_script(script_ctx_t*,BOOL,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
378 void release_dynamic_var(dynamic_var_t*) DECLSPEC_HIDDEN;
379 named_item_t *lookup_named_item(script_ctx_t*,const WCHAR*,unsigned) DECLSPEC_HIDDEN;
380 void release_named_item(named_item_t*) DECLSPEC_HIDDEN;
381 void clear_ei(EXCEPINFO*) DECLSPEC_HIDDEN;
382 HRESULT report_script_error(script_ctx_t*,const vbscode_t*,unsigned) DECLSPEC_HIDDEN;
383 void detach_global_objects(script_ctx_t*) DECLSPEC_HIDDEN;
384 HRESULT get_builtin_id(BuiltinDisp*,const WCHAR*,DISPID*) DECLSPEC_HIDDEN;
386 void release_regexp_typelib(void) DECLSPEC_HIDDEN;
387 HRESULT get_dispatch_typeinfo(ITypeInfo**) DECLSPEC_HIDDEN;
389 static inline BOOL is_int32(double d)
391 return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
394 static inline BOOL is_digit(WCHAR c)
396 return '0' <= c && c <= '9';
399 HRESULT create_regexp(IDispatch**) DECLSPEC_HIDDEN;
400 BSTR string_replace(BSTR,BSTR,BSTR,int,int,int) DECLSPEC_HIDDEN;
402 HRESULT map_hres(HRESULT) DECLSPEC_HIDDEN;
404 HRESULT create_safearray_iter(SAFEARRAY *sa, IEnumVARIANT **ev) DECLSPEC_HIDDEN;
406 #define FACILITY_VBS 0xa
407 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
409 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
410 HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
412 BSTR get_vbscript_string(int) DECLSPEC_HIDDEN;
413 BSTR get_vbscript_error_string(HRESULT) DECLSPEC_HIDDEN;
415 static inline LPWSTR heap_strdupW(LPCWSTR str)
417 LPWSTR ret = NULL;
419 if(str) {
420 DWORD size;
422 size = (lstrlenW(str)+1)*sizeof(WCHAR);
423 ret = heap_alloc(size);
424 if(ret)
425 memcpy(ret, str, size);
428 return ret;
431 #define VBSCRIPT_BUILD_VERSION 16978
432 #define VBSCRIPT_MAJOR_VERSION 5
433 #define VBSCRIPT_MINOR_VERSION 8