Commit 3862cdab authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Added function storage specifiers support.

parent dfc74ac0
...@@ -760,6 +760,7 @@ static HRESULT create_function(compile_ctx_t *ctx, function_decl_t *decl, functi ...@@ -760,6 +760,7 @@ static HRESULT create_function(compile_ctx_t *ctx, function_decl_t *decl, functi
func->var_cnt = 0; func->var_cnt = 0;
func->code_ctx = ctx->code; func->code_ctx = ctx->code;
func->type = decl->type; func->type = decl->type;
func->is_public = decl->is_public;
func->arg_cnt = 0; func->arg_cnt = 0;
if(decl->args) { if(decl->args) {
......
...@@ -135,6 +135,7 @@ typedef struct _arg_decl_t { ...@@ -135,6 +135,7 @@ typedef struct _arg_decl_t {
typedef struct _function_decl_t { typedef struct _function_decl_t {
const WCHAR *name; const WCHAR *name;
function_type_t type; function_type_t type;
BOOL is_public;
arg_decl_t *args; arg_decl_t *args;
statement_t *body; statement_t *body;
struct _function_decl_t *next; struct _function_decl_t *next;
......
...@@ -31,7 +31,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(vbscript); ...@@ -31,7 +31,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(vbscript);
static int parser_error(const char*); static int parser_error(const char*);
static void parse_complete(parser_ctx_t*,BOOL); static void parse_complete(parser_ctx_t*,BOOL);
static void source_add_statement(parser_ctx_t*,statement_t*); static void source_add_statement(parser_ctx_t*,statement_t*);
static void source_add_class(parser_ctx_t*,class_decl_t*); static void source_add_class(parser_ctx_t*,class_decl_t*);
...@@ -57,10 +57,13 @@ static statement_t *new_function_statement(parser_ctx_t*,function_decl_t*); ...@@ -57,10 +57,13 @@ static statement_t *new_function_statement(parser_ctx_t*,function_decl_t*);
static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,dim_decl_t*); static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,dim_decl_t*);
static elseif_decl_t *new_elseif_decl(parser_ctx_t*,expression_t*,statement_t*); static elseif_decl_t *new_elseif_decl(parser_ctx_t*,expression_t*,statement_t*);
static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,arg_decl_t*,statement_t*); static function_decl_t *new_function_decl(parser_ctx_t*,const WCHAR*,function_type_t,unsigned,arg_decl_t*,statement_t*);
static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL); static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL);
static class_decl_t *new_class_decl(parser_ctx_t*); static class_decl_t *new_class_decl(parser_ctx_t*);
#define STORAGE_IS_PRIVATE 1
#define STORAGE_IS_DEFAULT 2
#define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT #define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT
%} %}
...@@ -78,6 +81,7 @@ static class_decl_t *new_class_decl(parser_ctx_t*); ...@@ -78,6 +81,7 @@ static class_decl_t *new_class_decl(parser_ctx_t*);
function_decl_t *func_decl; function_decl_t *func_decl;
arg_decl_t *arg_decl; arg_decl_t *arg_decl;
class_decl_t *class_decl; class_decl_t *class_decl;
unsigned uint;
LONG lng; LONG lng;
BOOL bool; BOOL bool;
double dbl; double dbl;
...@@ -111,6 +115,7 @@ static class_decl_t *new_class_decl(parser_ctx_t*); ...@@ -111,6 +115,7 @@ static class_decl_t *new_class_decl(parser_ctx_t*);
%type <func_decl> FunctionDecl %type <func_decl> FunctionDecl
%type <elseif> ElseIfs_opt ElseIfs ElseIf %type <elseif> ElseIfs_opt ElseIfs ElseIf
%type <class_decl> ClassDeclaration ClassBody %type <class_decl> ClassDeclaration ClassBody
%type <uint> Storage Storage_opt
%type <dim_decl> DimDeclList %type <dim_decl> DimDeclList
%% %%
...@@ -286,10 +291,19 @@ ClassBody ...@@ -286,10 +291,19 @@ ClassBody
: /* empty */ { $$ = new_class_decl(ctx); } : /* empty */ { $$ = new_class_decl(ctx); }
FunctionDecl FunctionDecl
: /* Storage_opt */ tSUB tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tSUB : Storage_opt tSUB tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tSUB
{ $$ = new_function_decl(ctx, $2, FUNC_SUB, $3, $5); CHECK_ERROR; } { $$ = new_function_decl(ctx, $3, FUNC_SUB, $1, $4, $6); CHECK_ERROR; }
| /* Storage_opt */ tFUNCTION tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tFUNCTION | Storage_opt tFUNCTION tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tFUNCTION
{ $$ = new_function_decl(ctx, $2, FUNC_FUNCTION, $3, $5); CHECK_ERROR; } { $$ = new_function_decl(ctx, $3, FUNC_FUNCTION, $1, $4, $6); CHECK_ERROR; }
Storage_opt
: /* empty*/ { $$ = 0; }
| Storage { $$ = $1; }
Storage
: tPUBLIC tDEFAULT { $$ = STORAGE_IS_DEFAULT; }
| tPUBLIC { $$ = 0; }
| tPRIVATE { $$ = STORAGE_IS_PRIVATE; }
ArgumentsDecl_opt ArgumentsDecl_opt
: EmptyBrackets_opt { $$ = NULL; } : EmptyBrackets_opt { $$ = NULL; }
...@@ -566,16 +580,23 @@ static arg_decl_t *new_argument_decl(parser_ctx_t *ctx, const WCHAR *name, BOOL ...@@ -566,16 +580,23 @@ static arg_decl_t *new_argument_decl(parser_ctx_t *ctx, const WCHAR *name, BOOL
} }
static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name, function_type_t type, static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name, function_type_t type,
arg_decl_t *arg_decl, statement_t *body) unsigned storage_flags, arg_decl_t *arg_decl, statement_t *body)
{ {
function_decl_t *decl; function_decl_t *decl;
if(storage_flags & STORAGE_IS_DEFAULT) {
FIXME("Function declared as default property\n");
ctx->hres = E_FAIL;
return NULL;
}
decl = parser_alloc(ctx, sizeof(*decl)); decl = parser_alloc(ctx, sizeof(*decl));
if(!decl) if(!decl)
return NULL; return NULL;
decl->name = name; decl->name = name;
decl->type = type; decl->type = type;
decl->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
decl->args = arg_decl; decl->args = arg_decl;
decl->body = body; decl->body = body;
return decl; return decl;
......
...@@ -271,6 +271,14 @@ y = true ...@@ -271,6 +271,14 @@ y = true
Call TestSubLocalVal Call TestSubLocalVal
Call ok(x, "global x is not true?") Call ok(x, "global x is not true?")
Public Sub TestPublicSub
End Sub
Call TestPublicSub
Private Sub TestPrivateSub
End Sub
Call TestPrivateSub
if false then if false then
Function testfunc Function testfunc
x = true x = true
...@@ -360,6 +368,14 @@ x = false ...@@ -360,6 +368,14 @@ x = false
ok SetVal(x, true), "SetVal returned false?" ok SetVal(x, true), "SetVal returned false?"
Call ok(x, "x is not set to true by SetVal?") Call ok(x, "x is not set to true by SetVal?")
Public Function TestPublicFunc
End Function
Call TestPublicFunc
Private Function TestPrivateFunc
End Function
Call TestPrivateFunc
set x = testObj set x = testObj
Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=testObj) = " & getVT(x)) Call ok(getVT(x) = "VT_DISPATCH*", "getVT(x=testObj) = " & getVT(x))
......
...@@ -204,6 +204,7 @@ typedef struct { ...@@ -204,6 +204,7 @@ typedef struct {
struct _function_t { struct _function_t {
function_type_t type; function_type_t type;
const WCHAR *name; const WCHAR *name;
BOOL is_public;
arg_desc_t *args; arg_desc_t *args;
unsigned arg_cnt; unsigned arg_cnt;
var_desc_t *vars; var_desc_t *vars;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment