23#include "parser.tab.h"
78#define X(n,a,b,c) {#n,b,c},
91 TRACE_(vbscript_disas)(
"\t%d",
arg->uint);
95 TRACE_(vbscript_disas)(
"\t%u",
arg->uint);
98 TRACE_(vbscript_disas)(
"\t%lf", *
arg->dbl);
110 for(instr =
ctx->code->instrs+1; instr < ctx->
code->instrs+
ctx->instr_cnt; instr++) {
115 TRACE_(vbscript_disas)(
"\n");
148 assert(id < ctx->instr_cnt);
149 return ctx->code->instrs +
id;
156 if(
ctx->instr_size ==
ctx->instr_cnt) {
163 ctx->code->instrs = new_instr;
164 ctx->instr_size *= 2;
167 ctx->code->instrs[
ctx->instr_cnt].op =
op;
168 return ctx->instr_cnt++;
244 if(!
ctx->code->bstr_pool_size) {
246 if(!
ctx->code->bstr_pool)
248 ctx->code->bstr_pool_size = 8;
249 }
else if(
ctx->code->bstr_pool_size ==
ctx->code->bstr_cnt) {
256 ctx->code->bstr_pool = new_pool;
257 ctx->code->bstr_pool_size *= 2;
261 if(!
ctx->code->bstr_pool[
ctx->code->bstr_cnt])
264 return ctx->code->bstr_pool[
ctx->code->bstr_cnt++];
320#define LABEL_FLAG 0x80000000
324 if(!
ctx->labels_size) {
328 ctx->labels_size = 8;
329 }
else if(
ctx->labels_size ==
ctx->labels_cnt) {
330 unsigned *new_labels;
336 ctx->labels = new_labels;
337 ctx->labels_size *= 2;
354 for(iter =
ctx->stat_ctx; iter; iter = iter->
next)
380 if(
error == SCRIPT_E_REPORTED)
394 for(decl =
ctx->const_decls; decl; decl = decl->
next) {
402 for(decl =
ctx->global_consts; decl; decl = decl->
next) {
433 if(ret_val && !
expr->args) {
565 unsigned cnd_jmp, endif_label = 0;
584 if(
stat->else_stat ||
stat->elseifs) {
594 for(elseif_decl =
stat->elseifs; elseif_decl; elseif_decl = elseif_decl->
next) {
619 if(
stat->else_stat) {
637 start_addr =
ctx->instr_cnt;
655 loop_ctx = &stat_ctx;
681 start_addr =
ctx->instr_cnt;
739 loop_start =
ctx->instr_cnt;
760 unsigned step_instr, instr;
786 if(
stat->step_expr) {
841 unsigned end_label, case_cnt = 0, *case_labels =
NULL,
i;
860 for(case_iter =
stat->case_clausules; case_iter; case_iter = case_iter->
next)
864 case_labels =
heap_alloc(case_cnt*
sizeof(*case_labels));
869 for(case_iter =
stat->case_clausules,
i=0; case_iter; case_iter = case_iter->
next,
i++) {
871 if(!case_labels[
i]) {
879 for(expr_iter = case_iter->
expr; expr_iter; expr_iter = expr_iter->
next) {
912 for(case_iter =
stat->case_clausules,
i=0; case_iter; case_iter = case_iter->
next,
i++) {
945 op = is_set ? OP_set_member : OP_assign_member;
947 op = is_set ? OP_set_ident : OP_assign_ident;
985 WARN(
"converting call expr to assign expr\n");
1006 for(dim_decl =
ctx->dim_decls; dim_decl; dim_decl = dim_decl->
next) {
1018 for(
i = 0;
i <
ctx->func->arg_cnt;
i++) {
1037 ctx->func->var_cnt++;
1050 dim_decl = dim_decl->
next;
1053 if(
ctx->dim_decls_tail)
1054 ctx->dim_decls_tail->next =
stat->dim_decls;
1056 ctx->dim_decls =
stat->dim_decls;
1057 ctx->dim_decls_tail = dim_decl;
1089 next_decl = decl->
next;
1090 decl->
next =
ctx->const_decls;
1091 ctx->const_decls = decl;
1099 if(
ctx->func != &
ctx->code->main_code) {
1100 FIXME(
"Function is not in the global code\n");
1104 stat->func_decl->next =
ctx->func_decls;
1105 ctx->func_decls =
stat->func_decl;
1112 unsigned pop_cnt = 0;
1114 for(iter =
ctx->stat_ctx; iter; iter = iter->
next) {
1120 FIXME(
"Exit Do outside Do Loop\n");
1138 unsigned pop_cnt = 0;
1140 for(iter =
ctx->stat_ctx; iter; iter = iter->
next) {
1146 FIXME(
"Exit For outside For loop\n");
1178 if(!
ctx->sub_end_label) {
1179 FIXME(
"Exit Sub outside Sub?\n");
1188 if(!
ctx->func_end_label) {
1189 FIXME(
"Exit Function outside Function?\n");
1198 if(!
ctx->prop_end_label) {
1199 FIXME(
"Exit Property outside Property?\n");
1231 stat_ctx->
next =
ctx->stat_ctx;
1232 ctx->stat_ctx = stat_ctx;
1236 switch(
stat->type) {
1301 FIXME(
"Unimplemented statement type %d\n",
stat->type);
1312 ctx->stat_ctx = stat_ctx->
next;
1322 for(instr =
ctx->code->instrs+off; instr < ctx->
code->instrs+
ctx->instr_cnt; instr++) {
1330 ctx->labels_cnt = 0;
1335 unsigned dim_cnt = 0,
i;
1338 for(iter = dim_decl->
dims; iter; iter = iter->
next)
1345 array_desc->
dim_cnt = dim_cnt;
1347 for(iter = dim_decl->
dims,
i=0; iter; iter = iter->
next,
i++) {
1359 func->code_off =
ctx->instr_cnt;
1361 ctx->sub_end_label = 0;
1362 ctx->func_end_label = 0;
1363 ctx->prop_end_label = 0;
1365 switch(
func->type) {
1368 if(!
ctx->func_end_label)
1373 if(!
ctx->sub_end_label)
1381 if(!
ctx->prop_end_label)
1396 if(
ctx->sub_end_label)
1398 if(
ctx->func_end_label)
1400 if(
ctx->prop_end_label)
1416 for(dim_decl =
ctx->dim_decls; dim_decl; dim_decl = dim_decl->
next) {
1428 new_var->
next =
ctx->global_vars;
1429 ctx->global_vars = new_var;
1438 for(dim_decl =
ctx->dim_decls,
i=0; dim_decl; dim_decl = dim_decl->
next,
i++) {
1440 if(!
func->vars[
i].name)
1448 if(
func->array_cnt) {
1449 unsigned array_id = 0;
1453 if(!
func->array_descs)
1456 for(dim_decl =
ctx->dim_decls; dim_decl; dim_decl = dim_decl->
next) {
1474 for(iter =
ctx->funcs; iter; iter = iter->
next) {
1502 func->array_cnt = 0;
1521 if(!
func->args[
i].name)
1523 func->args[
i].by_ref =
arg->by_ref;
1541 for(iter =
ctx->classes; iter; iter = iter->
next) {
1559 for(funcprop_decl = func_decl; funcprop_decl; funcprop_decl = funcprop_decl->
next_prop_func) {
1560 switch(funcprop_decl->
type) {
1609 static const WCHAR class_initializeW[] = {
'c',
'l',
'a',
's',
's',
'_',
'i',
'n',
'i',
't',
'i',
'a',
'l',
'i',
'z',
'e',0};
1610 static const WCHAR class_terminateW[] = {
'c',
'l',
'a',
's',
's',
'_',
't',
'e',
'r',
'm',
'i',
'n',
'a',
't',
'e',0};
1623 if(!class_desc->
name)
1628 for(func_decl = class_decl->
funcs; func_decl; func_decl = func_decl->
next) {
1629 for(func_prop_decl = func_decl; func_prop_decl; func_prop_decl = func_prop_decl->
next_prop_func) {
1638 if(!class_desc->
funcs)
1642 for(func_decl = class_decl->
funcs,
i=1; func_decl; func_decl = func_decl->
next,
i++) {
1643 for(func_prop_decl = func_decl; func_prop_decl; func_prop_decl = func_prop_decl->
next_prop_func) {
1650 if(!
wcsicmp(class_initializeW, func_decl->
name)) {
1652 FIXME(
"class initializer is not sub\n");
1657 }
else if(!
wcsicmp(class_terminateW, func_decl->
name)) {
1659 FIXME(
"class terminator is not sub\n");
1671 for(prop_decl = class_decl->
props; prop_decl; prop_decl = prop_decl->
next)
1675 if(!class_desc->
props)
1678 for(prop_decl = class_decl->
props,
i=0; prop_decl; prop_decl = prop_decl->
next,
i++) {
1700 for(prop_decl = class_decl->
props,
i=0; prop_decl; prop_decl = prop_decl->
next) {
1709 class_desc->
next =
ctx->classes;
1710 ctx->classes = class_desc;
1730 for(
class =
script->classes;
class;
class =
class->next) {
1758 for(
class =
ctx->classes;
class;
class =
class->next) {
1774 for(
i=0;
i <
code->bstr_cnt;
i++)
1778 IDispatch_Release(
code->context);
1791 ret = heap_alloc_zero(
sizeof(*
ret));
1808 ctx->instr_size = 32;
1811 ret->option_explicit =
ctx->parser.option_explicit;
1814 ret->main_code.code_ctx =
ret;
1854 ctx.labels_cnt =
ctx.labels_size = 0;
1862 ctx.global_consts =
ctx.const_decls;
1864 for(func_decl =
ctx.func_decls; func_decl; func_decl = func_decl->
next) {
1872 ctx.funcs = new_func;
1875 for(class_decl =
ctx.parser.class_decls; class_decl; class_decl = class_decl->
next) {
1889 if(
ctx.global_vars) {
1899 for(new_func =
ctx.funcs; new_func->
next; new_func = new_func->
next);
1915 class->next =
script->classes;
static void * heap_alloc(size_t len)
static BOOL heap_free(void *mem)
static void * heap_realloc(void *mem, size_t len)
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
static void list_remove(struct list_entry *entry)
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
static void list_init(struct list_entry *head)
static WCHAR * heap_strdupW(const WCHAR *str)
#define WINE_DECLARE_DEBUG_CHANNEL(x)
void parser_release(parser_ctx_t *) DECLSPEC_HIDDEN
HRESULT parse_script(parser_ctx_t *, const WCHAR *, const WCHAR *, DWORD) DECLSPEC_HIDDEN
HRESULT report_script_error(script_ctx_t *ctx)
#define VBS_COMPILE_ERROR
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
void clear_ei(script_ctx_t *ctx)
GLuint GLuint GLsizei GLenum type
GLuint GLuint GLuint GLuint arg1
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
static HRESULT push_instr_bstr(compiler_ctx_t *ctx, jsop_t op, const WCHAR *arg)
static void dump_code(compiler_ctx_t *ctx, unsigned off)
static HRESULT compile_expression(compiler_ctx_t *, expression_t *, BOOL)
static HRESULT compile_while_statement(compiler_ctx_t *ctx, while_statement_t *stat)
static void * compiler_alloc(bytecode_t *code, size_t size)
static HRESULT compile_member_expression(compiler_ctx_t *ctx, member_expression_t *expr)
static HRESULT compile_statement(compiler_ctx_t *, statement_ctx_t *, statement_t *)
static unsigned push_instr(compiler_ctx_t *ctx, jsop_t op)
static void resolve_labels(compiler_ctx_t *ctx, unsigned off)
static unsigned alloc_label(compiler_ctx_t *ctx)
static HRESULT compile_binary_expression(compiler_ctx_t *ctx, binary_expression_t *expr, jsop_t op)
static void dump_instr_arg(instr_arg_type_t type, instr_arg_t *arg)
static HRESULT compile_if_statement(compiler_ctx_t *ctx, if_statement_t *stat)
static HRESULT push_instr_double(compiler_ctx_t *ctx, jsop_t op, double arg)
static HRESULT compile_unary_expression(compiler_ctx_t *ctx, unary_expression_t *expr, jsop_t op)
static jsstr_t * compiler_alloc_string(compiler_ctx_t *ctx, const WCHAR *str)
static void label_set_addr(compiler_ctx_t *ctx, unsigned label)
static HRESULT push_instr_uint(compiler_ctx_t *ctx, jsop_t op, unsigned arg)
static HRESULT push_instr_bstr_uint(compiler_ctx_t *ctx, jsop_t op, const WCHAR *arg1, unsigned arg2)
static instr_t * instr_ptr(compiler_ctx_t *ctx, unsigned off)
struct _statement_ctx_t statement_ctx_t
static HRESULT push_instr_int(compiler_ctx_t *ctx, jsop_t op, LONG arg)
static HRESULT push_instr_str(compiler_ctx_t *ctx, jsop_t op, jsstr_t *str)
HRESULT compile_script(script_ctx_t *ctx, const WCHAR *code, const WCHAR *args, const WCHAR *delimiter, BOOL from_eval, BOOL use_decode, bytecode_t **ret)
void * heap_pool_alloc(heap_pool_t *, DWORD) __WINE_ALLOC_SIZE(2) DECLSPEC_HIDDEN
void heap_pool_free(heap_pool_t *) DECLSPEC_HIDDEN
void heap_pool_init(heap_pool_t *) DECLSPEC_HIDDEN
#define memcpy(s1, s2, n)
static const WCHAR label[]
static const WCHAR desc[]
#define DEFAULT_UNREACHABLE
BSTR WINAPI SysAllocString(LPCOLESTR str)
void WINAPI DECLSPEC_HOTPATCH SysFreeString(BSTR str)
static unsigned __int64 next
struct _case_clausule_t * next
struct _class_decl_t * next
array_desc_t * array_descs
vbdisp_prop_desc_t * props
vbdisp_funcprop_desc_t * funcs
unsigned class_terminate_id
unsigned class_initialize_id
struct _class_desc_t * next
struct _const_decl_t * next
expression_t * value_expr
struct _dim_decl_t * next
struct _dim_list_t * next
struct _dynamic_var_t * next
struct _elseif_decl_t * next
struct _expression_t * next
struct _function_decl_t * next_prop_func
struct _function_decl_t * next
struct _statement_ctx_t * next
function_decl_t * func_decls
const_decl_t * const_decls
const_decl_t * global_consts
dim_decl_t * dim_decls_tail
dynamic_var_t * global_vars
statement_ctx_t * stat_ctx
static HRESULT compile_select_statement(compile_ctx_t *ctx, select_statement_t *stat)
static HRESULT compile_call_statement(compile_ctx_t *ctx, call_statement_t *stat)
static BOOL emit_catch_jmp(compile_ctx_t *ctx, unsigned stack_off, unsigned code_off)
static void release_compiler(compile_ctx_t *ctx)
static vbscode_t * alloc_vbscode(compile_ctx_t *ctx, const WCHAR *source)
static HRESULT compile_dowhile_statement(compile_ctx_t *ctx, while_statement_t *stat)
static HRESULT compile_assign_statement(compile_ctx_t *ctx, assign_statement_t *stat, BOOL is_set)
static HRESULT compile_function_statement(compile_ctx_t *ctx, function_statement_t *stat)
static HRESULT compile_assignment(compile_ctx_t *ctx, member_expression_t *member_expr, expression_t *value_expr, BOOL is_set)
static HRESULT compile_class(compile_ctx_t *ctx, class_decl_t *class_decl)
instr_arg_type_t arg2_type
HRESULT compile_procedure(script_ctx_t *script, const WCHAR *src, const WCHAR *delimiter, DWORD flags, class_desc_t **ret)
static BOOL lookup_dim_decls(compile_ctx_t *ctx, const WCHAR *name)
static HRESULT push_instr_uint_bstr(compile_ctx_t *ctx, vbsop_t op, unsigned arg1, const WCHAR *arg2)
static HRESULT exit_label(compile_ctx_t *ctx, unsigned jmp_label)
static HRESULT compile_exitfor_statement(compile_ctx_t *ctx)
static BSTR alloc_bstr_arg(compile_ctx_t *ctx, const WCHAR *str)
instr_arg_type_t arg1_type
static HRESULT fill_array_desc(compile_ctx_t *ctx, dim_decl_t *dim_decl, array_desc_t *array_desc)
static HRESULT compile_const_statement(compile_ctx_t *ctx, const_statement_t *stat)
static BOOL lookup_class_funcs(class_desc_t *class_desc, const WCHAR *name)
static unsigned stack_offset(compile_ctx_t *ctx)
void release_vbscode(vbscode_t *code)
static HRESULT compile_error(script_ctx_t *ctx, HRESULT error)
static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *func)
static BOOL emit_catch(compile_ctx_t *ctx, unsigned off)
static HRESULT push_instr_addr(compile_ctx_t *ctx, vbsop_t op, unsigned arg)
static HRESULT compile_exitfunc_statement(compile_ctx_t *ctx)
static HRESULT compile_forto_statement(compile_ctx_t *ctx, forto_statement_t *stat)
static HRESULT compile_exitdo_statement(compile_ctx_t *ctx)
static BOOL lookup_args_name(compile_ctx_t *ctx, const WCHAR *name)
static expression_t * lookup_const_decls(compile_ctx_t *ctx, const WCHAR *name, BOOL lookup_global)
static BOOL lookup_class_name(compile_ctx_t *ctx, const WCHAR *name)
static HRESULT compile_args(compile_ctx_t *ctx, expression_t *args, unsigned *ret)
static void * compiler_alloc_zero(vbscode_t *vbscode, size_t size)
static HRESULT compile_onerror_statement(compile_ctx_t *ctx, onerror_statement_t *stat)
static HRESULT compile_exitprop_statement(compile_ctx_t *ctx)
static HRESULT check_script_collisions(compile_ctx_t *ctx, script_ctx_t *script)
static HRESULT compile_foreach_statement(compile_ctx_t *ctx, foreach_statement_t *stat)
static HRESULT compile_dim_statement(compile_ctx_t *ctx, dim_statement_t *stat)
static HRESULT create_class_funcprop(compile_ctx_t *ctx, function_decl_t *func_decl, vbdisp_funcprop_desc_t *desc)
static HRESULT compile_retval_statement(compile_ctx_t *ctx, retval_statement_t *stat)
static BOOL lookup_script_identifier(script_ctx_t *script, const WCHAR *identifier)
static BOOL lookup_funcs_name(compile_ctx_t *ctx, const WCHAR *name)
static HRESULT compile_exitsub_statement(compile_ctx_t *ctx)
static HRESULT create_function(compile_ctx_t *ctx, function_decl_t *decl, function_t **ret)
BSTR get_vbscript_error_string(HRESULT) DECLSPEC_HIDDEN
static unsigned arg_cnt(const DISPPARAMS *dp)
BSTR get_vbscript_string(int) DECLSPEC_HIDDEN
#define DISP_E_PARAMNOTFOUND