vbscript: Added class function compiler implementation.

This commit is contained in:
Jacek Caban 2011-09-15 14:20:46 +02:00 committed by Alexandre Julliard
parent ee67bc7a37
commit 8fb2b985dc
2 changed files with 48 additions and 7 deletions

View File

@ -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;

View File

@ -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*);