Commit 80ad3a23 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

vbscript: Added class parser implementation.

parent 84ec1acc
...@@ -142,6 +142,11 @@ typedef struct _function_statement_t { ...@@ -142,6 +142,11 @@ typedef struct _function_statement_t {
function_decl_t *func_decl; function_decl_t *func_decl;
} function_statement_t; } function_statement_t;
typedef struct _class_decl_t {
const WCHAR *name;
struct _class_decl_t *next;
} class_decl_t;
typedef struct _elseif_decl_t { typedef struct _elseif_decl_t {
expression_t *expr; expression_t *expr;
statement_t *stat; statement_t *stat;
...@@ -170,6 +175,7 @@ typedef struct { ...@@ -170,6 +175,7 @@ typedef struct {
statement_t *stats; statement_t *stats;
statement_t *stats_tail; statement_t *stats_tail;
class_decl_t *class_decls;
vbsheap_t heap; vbsheap_t heap;
} parser_ctx_t; } parser_ctx_t;
......
...@@ -34,6 +34,7 @@ static int parser_error(const char*); ...@@ -34,6 +34,7 @@ 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 *new_expression(parser_ctx_t*,expression_type_t,size_t); static void *new_expression(parser_ctx_t*,expression_type_t,size_t);
static expression_t *new_bool_expression(parser_ctx_t*,VARIANT_BOOL); static expression_t *new_bool_expression(parser_ctx_t*,VARIANT_BOOL);
...@@ -56,6 +57,7 @@ static dim_decl_t *new_dim_decl(parser_ctx_t*,const WCHAR*,dim_decl_t*); ...@@ -56,6 +57,7 @@ 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,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*);
#define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT #define CHECK_ERROR if(((parser_ctx_t*)ctx)->hres != S_OK) YYABORT
...@@ -73,6 +75,7 @@ static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL); ...@@ -73,6 +75,7 @@ static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL);
dim_decl_t *dim_decl; dim_decl_t *dim_decl;
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;
LONG lng; LONG lng;
BOOL bool; BOOL bool;
double dbl; double dbl;
...@@ -105,6 +108,7 @@ static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL); ...@@ -105,6 +108,7 @@ static arg_decl_t *new_argument_decl(parser_ctx_t*,const WCHAR*,BOOL);
%type <arg_decl> ArgumentsDecl_opt ArgumentDeclList ArgumentDecl %type <arg_decl> ArgumentsDecl_opt ArgumentDeclList ArgumentDecl
%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 <dim_decl> DimDeclList %type <dim_decl> DimDeclList
%% %%
...@@ -118,7 +122,8 @@ OptionExplicit_opt ...@@ -118,7 +122,8 @@ OptionExplicit_opt
SourceElements SourceElements
: /* empty */ : /* empty */
| SourceElements StatementNl { source_add_statement(ctx, $2); } | SourceElements StatementNl { source_add_statement(ctx, $2); }
| SourceElements ClassDeclaration { source_add_class(ctx, $2); }
StatementsNl_opt StatementsNl_opt
: /* empty */ { $$ = NULL; } : /* empty */ { $$ = NULL; }
...@@ -268,6 +273,12 @@ LiteralExpression ...@@ -268,6 +273,12 @@ LiteralExpression
PrimaryExpression PrimaryExpression
: '(' Expression ')' { $$ = $2; } : '(' Expression ')' { $$ = $2; }
ClassDeclaration
: tCLASS tIdentifier tNL ClassBody tEND tCLASS tNL { $4->name = $2; $$ = $4; }
ClassBody
: /* 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, $2, FUNC_SUB, $3, $5); CHECK_ERROR; }
...@@ -304,6 +315,12 @@ static void source_add_statement(parser_ctx_t *ctx, statement_t *stat) ...@@ -304,6 +315,12 @@ static void source_add_statement(parser_ctx_t *ctx, statement_t *stat)
} }
} }
static void source_add_class(parser_ctx_t *ctx, class_decl_t *class_decl)
{
class_decl->next = ctx->class_decls;
ctx->class_decls = class_decl;
}
static void parse_complete(parser_ctx_t *ctx, BOOL option_explicit) static void parse_complete(parser_ctx_t *ctx, BOOL option_explicit)
{ {
ctx->parse_complete = TRUE; ctx->parse_complete = TRUE;
...@@ -545,6 +562,18 @@ static statement_t *new_function_statement(parser_ctx_t *ctx, function_decl_t *d ...@@ -545,6 +562,18 @@ static statement_t *new_function_statement(parser_ctx_t *ctx, function_decl_t *d
return &stat->stat; return &stat->stat;
} }
static class_decl_t *new_class_decl(parser_ctx_t *ctx)
{
class_decl_t *class_decl;
class_decl = parser_alloc(ctx, sizeof(*class_decl));
if(!class_decl)
return NULL;
class_decl->next = NULL;
return class_decl;
}
void *parser_alloc(parser_ctx_t *ctx, size_t size) void *parser_alloc(parser_ctx_t *ctx, size_t size)
{ {
void *ret; void *ret;
...@@ -568,6 +597,7 @@ HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code) ...@@ -568,6 +597,7 @@ HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
ctx->last_token = tNL; ctx->last_token = tNL;
ctx->last_nl = 0; ctx->last_nl = 0;
ctx->stats = ctx->stats_tail = NULL; ctx->stats = ctx->stats_tail = NULL;
ctx->class_decls = NULL;
ctx->option_explicit = FALSE; ctx->option_explicit = FALSE;
parser_parse(ctx); parser_parse(ctx);
......
...@@ -355,4 +355,7 @@ x = false ...@@ -355,4 +355,7 @@ 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?")
Class EmptyClass
End Class
reportSuccess() reportSuccess()
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