From 8fb2b985dc74714905c0593cfa826fb2cf9d3006 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 15 Sep 2011 14:20:46 +0200 Subject: [PATCH] vbscript: Added class function compiler implementation. --- dlls/vbscript/compile.c | 33 +++++++++++++++++++++++++++++++++ dlls/vbscript/vbscript.h | 22 +++++++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c index 5c7f7e3a436..32707dc648a 100644 --- a/dlls/vbscript/compile.c +++ b/dlls/vbscript/compile.c @@ -804,9 +804,26 @@ static BOOL lookup_class_name(compile_ctx_t *ctx, const WCHAR *name) return FALSE; } +static HRESULT create_class_funcprop(compile_ctx_t *ctx, function_decl_t *func_decl, vbdisp_funcprop_desc_t *desc) +{ + desc->name = compiler_alloc_string(ctx->code, func_decl->name); + if(!desc->name) + return E_OUTOFMEMORY; + + assert(!desc->entries[0]); + + if(func_decl->is_public) + desc->is_public = TRUE; + + return create_function(ctx, func_decl, desc->entries); +} + static HRESULT compile_class(compile_ctx_t *ctx, class_decl_t *class_decl) { + function_decl_t *func_decl; class_desc_t *class_desc; + unsigned i; + HRESULT hres; if(lookup_dim_decls(ctx, class_decl->name) || lookup_funcs_name(ctx, class_decl->name) || lookup_class_name(ctx, class_decl->name)) { @@ -822,6 +839,22 @@ static HRESULT compile_class(compile_ctx_t *ctx, class_decl_t *class_decl) if(!class_desc->name) return E_OUTOFMEMORY; + class_desc->func_cnt = 1; /* always allocate slot for default getter */ + + for(func_decl = class_decl->funcs; func_decl; func_decl = func_decl->next) + class_desc->func_cnt++; + + class_desc->funcs = compiler_alloc(ctx->code, class_desc->func_cnt*sizeof(*class_desc->funcs)); + if(!class_desc->funcs) + return E_OUTOFMEMORY; + memset(class_desc->funcs, 0, class_desc->func_cnt*sizeof(*class_desc->funcs)); + + for(func_decl = class_decl->funcs, i=1; func_decl; func_decl = func_decl->next, i++) { + hres = create_class_funcprop(ctx, func_decl, class_desc->funcs + i); + if(FAILED(hres)) + return hres; + } + class_desc->next = ctx->classes; ctx->classes = class_desc; return S_OK; diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h index 014e4808243..11a5862d94b 100644 --- a/dlls/vbscript/vbscript.h +++ b/dlls/vbscript/vbscript.h @@ -55,9 +55,24 @@ typedef struct named_item_t { struct list entry; } named_item_t; +typedef enum { + VBDISP_CALLGET, + VBDISP_LET, + VBDISP_SET, + VBDISP_ANY +} vbdisp_invoke_type_t; + +typedef struct { + const WCHAR *name; + BOOL is_public; + function_t *entries[VBDISP_ANY]; +} vbdisp_funcprop_desc_t; + typedef struct _class_desc_t { const WCHAR *name; script_ctx_t *ctx; + unsigned func_cnt; + vbdisp_funcprop_desc_t *funcs; struct _class_desc_t *next; } class_desc_t; @@ -69,13 +84,6 @@ typedef struct { const class_desc_t *desc; } vbdisp_t; -typedef enum { - VBDISP_CALLGET, - VBDISP_LET, - VBDISP_SET, - VBDISP_ANY -} vbdisp_invoke_type_t; - HRESULT create_vbdisp(const class_desc_t*,vbdisp_t**); HRESULT disp_get_id(IDispatch*,BSTR,DISPID*); HRESULT disp_call(script_ctx_t*,IDispatch*,DISPID,DISPPARAMS*,VARIANT*);