wined3d: Merge volumetexture_init() and texture_init().
[wine.git] / dlls / vbscript / vbscript.h
blob5e935ff76af568025724215977537ff5288476da
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>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "ole2.h"
26 #include "dispex.h"
27 #include "activscp.h"
29 #include "vbscript_classes.h"
31 #include "wine/heap.h"
32 #include "wine/list.h"
33 #include "wine/unicode.h"
35 typedef struct {
36 void **blocks;
37 DWORD block_cnt;
38 DWORD last_block;
39 DWORD offset;
40 BOOL mark;
41 struct list custom_blocks;
42 } heap_pool_t;
44 void heap_pool_init(heap_pool_t*) DECLSPEC_HIDDEN;
45 void *heap_pool_alloc(heap_pool_t*,size_t) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN;
46 void *heap_pool_grow(heap_pool_t*,void*,DWORD,DWORD) DECLSPEC_HIDDEN;
47 void heap_pool_clear(heap_pool_t*) DECLSPEC_HIDDEN;
48 void heap_pool_free(heap_pool_t*) DECLSPEC_HIDDEN;
49 heap_pool_t *heap_pool_mark(heap_pool_t*) DECLSPEC_HIDDEN;
51 typedef struct _function_t function_t;
52 typedef struct _vbscode_t vbscode_t;
53 typedef struct _script_ctx_t script_ctx_t;
54 typedef struct _vbdisp_t vbdisp_t;
56 typedef struct named_item_t {
57 IDispatch *disp;
58 DWORD flags;
59 LPWSTR name;
61 struct list entry;
62 } named_item_t;
64 typedef enum {
65 VBDISP_CALLGET,
66 VBDISP_LET,
67 VBDISP_SET,
68 VBDISP_ANY
69 } vbdisp_invoke_type_t;
71 typedef struct {
72 unsigned dim_cnt;
73 SAFEARRAYBOUND *bounds;
74 } array_desc_t;
76 typedef struct {
77 BOOL is_public;
78 BOOL is_array;
79 const WCHAR *name;
80 } vbdisp_prop_desc_t;
82 typedef struct {
83 const WCHAR *name;
84 BOOL is_public;
85 BOOL is_array;
86 function_t *entries[VBDISP_ANY];
87 } vbdisp_funcprop_desc_t;
89 #define BP_GET 1
90 #define BP_GETPUT 2
92 typedef struct {
93 DISPID id;
94 HRESULT (*proc)(vbdisp_t*,VARIANT*,unsigned,VARIANT*);
95 DWORD flags;
96 unsigned min_args;
97 UINT_PTR max_args;
98 } builtin_prop_t;
100 typedef struct _class_desc_t {
101 const WCHAR *name;
102 script_ctx_t *ctx;
104 unsigned class_initialize_id;
105 unsigned class_terminate_id;
106 unsigned func_cnt;
107 vbdisp_funcprop_desc_t *funcs;
109 unsigned prop_cnt;
110 vbdisp_prop_desc_t *props;
112 unsigned array_cnt;
113 array_desc_t *array_descs;
115 unsigned builtin_prop_cnt;
116 const builtin_prop_t *builtin_props;
117 ITypeInfo *typeinfo;
118 function_t *value_func;
120 struct _class_desc_t *next;
121 } class_desc_t;
123 struct _vbdisp_t {
124 IDispatchEx IDispatchEx_iface;
126 LONG ref;
127 BOOL terminator_ran;
128 struct list entry;
130 const class_desc_t *desc;
131 SAFEARRAY **arrays;
132 VARIANT props[1];
135 typedef struct _ident_map_t ident_map_t;
137 typedef struct {
138 IDispatchEx IDispatchEx_iface;
139 LONG ref;
141 ident_map_t *ident_map;
142 unsigned ident_map_cnt;
143 unsigned ident_map_size;
145 script_ctx_t *ctx;
146 } ScriptDisp;
148 HRESULT create_vbdisp(const class_desc_t*,vbdisp_t**) DECLSPEC_HIDDEN;
149 HRESULT disp_get_id(IDispatch*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*) DECLSPEC_HIDDEN;
150 HRESULT vbdisp_get_id(vbdisp_t*,BSTR,vbdisp_invoke_type_t,BOOL,DISPID*) DECLSPEC_HIDDEN;
151 HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
152 HRESULT disp_propput(script_ctx_t*,IDispatch*,DISPID,WORD,DISPPARAMS*) DECLSPEC_HIDDEN;
153 HRESULT get_disp_value(script_ctx_t*,IDispatch*,VARIANT*) DECLSPEC_HIDDEN;
154 void collect_objects(script_ctx_t*) DECLSPEC_HIDDEN;
155 HRESULT create_procedure_disp(script_ctx_t*,vbscode_t*,IDispatch**) DECLSPEC_HIDDEN;
156 HRESULT create_script_disp(script_ctx_t*,ScriptDisp**) DECLSPEC_HIDDEN;
158 HRESULT to_int(VARIANT*,int*) DECLSPEC_HIDDEN;
160 static inline unsigned arg_cnt(const DISPPARAMS *dp)
162 return dp->cArgs - dp->cNamedArgs;
165 static inline VARIANT *get_arg(DISPPARAMS *dp, DWORD i)
167 return dp->rgvarg + dp->cArgs-i-1;
170 typedef struct _dynamic_var_t {
171 struct _dynamic_var_t *next;
172 VARIANT v;
173 const WCHAR *name;
174 BOOL is_const;
175 } dynamic_var_t;
177 struct _script_ctx_t {
178 IActiveScriptSite *site;
179 LCID lcid;
181 IInternetHostSecurityManager *secmgr;
182 DWORD safeopt;
184 IDispatch *host_global;
186 ScriptDisp *script_obj;
188 class_desc_t global_desc;
189 vbdisp_t *global_obj;
191 class_desc_t err_desc;
192 vbdisp_t *err_obj;
194 HRESULT err_number;
196 dynamic_var_t *global_vars;
197 function_t *global_funcs;
198 class_desc_t *classes;
199 class_desc_t *procs;
201 heap_pool_t heap;
203 struct list objects;
204 struct list code_list;
205 struct list named_items;
208 HRESULT init_global(script_ctx_t*) DECLSPEC_HIDDEN;
209 HRESULT init_err(script_ctx_t*) DECLSPEC_HIDDEN;
211 IUnknown *create_ax_site(script_ctx_t*) DECLSPEC_HIDDEN;
213 typedef enum {
214 ARG_NONE = 0,
215 ARG_STR,
216 ARG_BSTR,
217 ARG_INT,
218 ARG_UINT,
219 ARG_ADDR,
220 ARG_DOUBLE
221 } instr_arg_type_t;
223 #define OP_LIST \
224 X(add, 1, 0, 0) \
225 X(and, 1, 0, 0) \
226 X(assign_ident, 1, ARG_BSTR, ARG_UINT) \
227 X(assign_member, 1, ARG_BSTR, ARG_UINT) \
228 X(bool, 1, ARG_INT, 0) \
229 X(catch, 1, ARG_ADDR, ARG_UINT) \
230 X(case, 0, ARG_ADDR, 0) \
231 X(concat, 1, 0, 0) \
232 X(const, 1, ARG_BSTR, 0) \
233 X(dim, 1, ARG_BSTR, ARG_UINT) \
234 X(div, 1, 0, 0) \
235 X(double, 1, ARG_DOUBLE, 0) \
236 X(empty, 1, 0, 0) \
237 X(enumnext, 0, ARG_ADDR, ARG_BSTR) \
238 X(equal, 1, 0, 0) \
239 X(hres, 1, ARG_UINT, 0) \
240 X(errmode, 1, ARG_INT, 0) \
241 X(eqv, 1, 0, 0) \
242 X(exp, 1, 0, 0) \
243 X(gt, 1, 0, 0) \
244 X(gteq, 1, 0, 0) \
245 X(icall, 1, ARG_BSTR, ARG_UINT) \
246 X(icallv, 1, ARG_BSTR, ARG_UINT) \
247 X(idiv, 1, 0, 0) \
248 X(imp, 1, 0, 0) \
249 X(incc, 1, ARG_BSTR, 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(long, 1, ARG_INT, 0) \
255 X(lt, 1, 0, 0) \
256 X(lteq, 1, 0, 0) \
257 X(mcall, 1, ARG_BSTR, ARG_UINT) \
258 X(mcallv, 1, ARG_BSTR, ARG_UINT) \
259 X(me, 1, 0, 0) \
260 X(mod, 1, 0, 0) \
261 X(mul, 1, 0, 0) \
262 X(neg, 1, 0, 0) \
263 X(nequal, 1, 0, 0) \
264 X(new, 1, ARG_STR, 0) \
265 X(newenum, 1, 0, 0) \
266 X(not, 1, 0, 0) \
267 X(nothing, 1, 0, 0) \
268 X(null, 1, 0, 0) \
269 X(or, 1, 0, 0) \
270 X(pop, 1, ARG_UINT, 0) \
271 X(ret, 0, 0, 0) \
272 X(set_ident, 1, ARG_BSTR, ARG_UINT) \
273 X(set_member, 1, ARG_BSTR, ARG_UINT) \
274 X(short, 1, ARG_INT, 0) \
275 X(step, 0, ARG_ADDR, ARG_BSTR) \
276 X(stop, 1, 0, 0) \
277 X(string, 1, ARG_STR, 0) \
278 X(sub, 1, 0, 0) \
279 X(val, 1, 0, 0) \
280 X(xor, 1, 0, 0)
282 typedef enum {
283 #define X(x,n,a,b) OP_##x,
284 OP_LIST
285 #undef X
286 OP_LAST
287 } vbsop_t;
289 typedef union {
290 const WCHAR *str;
291 BSTR bstr;
292 unsigned uint;
293 LONG lng;
294 double *dbl;
295 } instr_arg_t;
297 typedef struct {
298 vbsop_t op;
299 instr_arg_t arg1;
300 instr_arg_t arg2;
301 } instr_t;
303 typedef struct {
304 const WCHAR *name;
305 BOOL by_ref;
306 } arg_desc_t;
308 typedef enum {
309 FUNC_GLOBAL,
310 FUNC_FUNCTION,
311 FUNC_SUB,
312 FUNC_PROPGET,
313 FUNC_PROPLET,
314 FUNC_PROPSET,
315 FUNC_DEFGET
316 } function_type_t;
318 typedef struct {
319 const WCHAR *name;
320 } var_desc_t;
322 struct _function_t {
323 function_type_t type;
324 const WCHAR *name;
325 BOOL is_public;
326 arg_desc_t *args;
327 unsigned arg_cnt;
328 var_desc_t *vars;
329 unsigned var_cnt;
330 array_desc_t *array_descs;
331 unsigned array_cnt;
332 unsigned code_off;
333 vbscode_t *code_ctx;
334 function_t *next;
337 struct _vbscode_t {
338 instr_t *instrs;
339 WCHAR *source;
341 BOOL option_explicit;
343 BOOL pending_exec;
344 function_t main_code;
346 BSTR *bstr_pool;
347 unsigned bstr_pool_size;
348 unsigned bstr_cnt;
349 heap_pool_t heap;
351 struct list entry;
354 void release_vbscode(vbscode_t*) DECLSPEC_HIDDEN;
355 HRESULT compile_script(script_ctx_t*,const WCHAR*,const WCHAR*,vbscode_t**) DECLSPEC_HIDDEN;
356 HRESULT exec_script(script_ctx_t*,function_t*,vbdisp_t*,DISPPARAMS*,VARIANT*) DECLSPEC_HIDDEN;
357 void release_dynamic_vars(dynamic_var_t*) DECLSPEC_HIDDEN;
359 typedef struct {
360 UINT16 len;
361 WCHAR buf[7];
362 } string_constant_t;
364 #define TID_LIST \
365 XDIID(ErrObj) \
366 XDIID(GlobalObj)
368 typedef enum {
369 #define XDIID(iface) iface ## _tid,
370 TID_LIST
371 #undef XDIID
372 LAST_tid
373 } tid_t;
375 HRESULT get_typeinfo(tid_t,ITypeInfo**) DECLSPEC_HIDDEN;
376 void release_regexp_typelib(void) DECLSPEC_HIDDEN;
378 #ifndef INT32_MIN
379 #define INT32_MIN (-2147483647-1)
380 #endif
382 #ifndef INT32_MAX
383 #define INT32_MAX (2147483647)
384 #endif
386 static inline BOOL is_int32(double d)
388 return INT32_MIN <= d && d <= INT32_MAX && (double)(int)d == d;
391 HRESULT create_regexp(IDispatch**) DECLSPEC_HIDDEN;
393 HRESULT map_hres(HRESULT) DECLSPEC_HIDDEN;
395 HRESULT create_safearray_iter(SAFEARRAY *sa, IEnumVARIANT **ev) DECLSPEC_HIDDEN;
397 #define FACILITY_VBS 0xa
398 #define MAKE_VBSERROR(code) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_VBS, code)
400 #define VBSE_ILLEGAL_FUNC_CALL 5
401 #define VBSE_OVERFLOW 6
402 #define VBSE_OUT_OF_MEMORY 7
403 #define VBSE_OUT_OF_BOUNDS 9
404 #define VBSE_ARRAY_LOCKED 10
405 #define VBSE_TYPE_MISMATCH 13
406 #define VBSE_FILE_NOT_FOUND 53
407 #define VBSE_IO_ERROR 57
408 #define VBSE_FILE_ALREADY_EXISTS 58
409 #define VBSE_DISK_FULL 61
410 #define VBSE_TOO_MANY_FILES 67
411 #define VBSE_PERMISSION_DENIED 70
412 #define VBSE_PATH_FILE_ACCESS 75
413 #define VBSE_PATH_NOT_FOUND 76
414 #define VBSE_ILLEGAL_NULL_USE 94
415 #define VBSE_OLE_NOT_SUPPORTED 430
416 #define VBSE_OLE_NO_PROP_OR_METHOD 438
417 #define VBSE_ACTION_NOT_SUPPORTED 445
418 #define VBSE_NAMED_ARGS_NOT_SUPPORTED 446
419 #define VBSE_LOCALE_SETTING_NOT_SUPPORTED 447
420 #define VBSE_NAMED_PARAM_NOT_FOUND 448
421 #define VBSE_INVALID_TYPELIB_VARIABLE 458
422 #define VBSE_FUNC_ARITY_MISMATCH 450
423 #define VBSE_PARAMETER_NOT_OPTIONAL 449
424 #define VBSE_NOT_ENUM 451
425 #define VBSE_INVALID_DLL_FUNCTION_NAME 453
426 #define VBSE_CANT_CREATE_TMP_FILE 322
427 #define VBSE_OLE_FILE_NOT_FOUND 432
428 #define VBSE_CANT_CREATE_OBJECT 429
429 #define VBSE_SERVER_NOT_FOUND 462
431 HRESULT WINAPI VBScriptFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
432 HRESULT WINAPI VBScriptRegExpFactory_CreateInstance(IClassFactory*,IUnknown*,REFIID,void**) DECLSPEC_HIDDEN;
434 static inline LPWSTR heap_strdupW(LPCWSTR str)
436 LPWSTR ret = NULL;
438 if(str) {
439 DWORD size;
441 size = (strlenW(str)+1)*sizeof(WCHAR);
442 ret = heap_alloc(size);
443 if(ret)
444 memcpy(ret, str, size);
447 return ret;
450 #define VBSCRIPT_BUILD_VERSION 16978
451 #define VBSCRIPT_MAJOR_VERSION 5
452 #define VBSCRIPT_MINOR_VERSION 8