Jacek Caban : vbscript: Added function call statement parsing beginning implementation.
Alexandre Julliard
julliard at winehq.org
Wed Sep 7 12:35:30 CDT 2011
Module: wine
Branch: master
Commit: 6c5570297e34fce58be2ebe6236bf793cae4cfcf
URL: http://source.winehq.org/git/wine.git/?a=commit;h=6c5570297e34fce58be2ebe6236bf793cae4cfcf
Author: Jacek Caban <jacek at codeweavers.com>
Date: Wed Sep 7 14:08:21 2011 +0200
vbscript: Added function call statement parsing beginning implementation.
---
dlls/vbscript/compile.c | 9 ++++-
dlls/vbscript/parse.h | 33 +++++++++++++++++
dlls/vbscript/parser.y | 93 ++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 131 insertions(+), 4 deletions(-)
diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index c51dd97..4ac760b 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -53,13 +53,18 @@ static unsigned push_instr(compile_ctx_t *ctx, vbsop_t op)
return ctx->instr_cnt++;
}
-static HRESULT compile_func(compile_ctx_t *ctx, function_t *func)
+static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *func)
{
func->code_off = ctx->instr_cnt;
if(push_instr(ctx, OP_ret) == -1)
return E_OUTOFMEMORY;
+ if(stat) {
+ FIXME("statements compilation not implemented\n");
+ return E_NOTIMPL;
+ }
+
return S_OK;
}
@@ -113,7 +118,7 @@ HRESULT compile_script(script_ctx_t *script, const WCHAR *src, vbscode_t **ret)
if(!ctx.code)
return E_OUTOFMEMORY;
- hres = compile_func(&ctx, &ctx.code->global_code);
+ hres = compile_func(&ctx, ctx.parser.stats, &ctx.code->global_code);
if(FAILED(hres)) {
release_vbscode(ctx.code);
return hres;
diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h
index fa6424f..7c9ab26 100644
--- a/dlls/vbscript/parse.h
+++ b/dlls/vbscript/parse.h
@@ -16,6 +16,36 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
+typedef enum {
+ EXPR_MEMBER
+} expression_type_t;
+
+typedef struct _expression_t {
+ expression_type_t type;
+ struct _expression_t *next;
+} expression_t;
+
+typedef struct {
+ expression_t expr;
+ expression_t *obj_expr;
+ const WCHAR *identifier;
+ expression_t *args;
+} member_expression_t;
+
+typedef enum {
+ STAT_CALL
+} statement_type_t;
+
+typedef struct _statement_t {
+ statement_type_t type;
+ struct _statement_t *next;
+} statement_t;
+
+typedef struct {
+ statement_t stat;
+ member_expression_t *expr;
+} call_statement_t;
+
typedef struct {
const WCHAR *code;
const WCHAR *ptr;
@@ -26,6 +56,9 @@ typedef struct {
int last_token;
unsigned last_nl;
+
+ statement_t *stats;
+ statement_t *stats_tail;
} parser_ctx_t;
HRESULT parse_script(parser_ctx_t*,const WCHAR*) DECLSPEC_HIDDEN;
diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y
index 0ae6008..5fb6bd2 100644
--- a/dlls/vbscript/parser.y
+++ b/dlls/vbscript/parser.y
@@ -33,6 +33,12 @@ static int parser_error(const char*);
static void parse_complete(parser_ctx_t*);
+static void source_add_statement(parser_ctx_t*,statement_t*);
+
+static member_expression_t *new_member_expression(parser_ctx_t*,expression_t*,const WCHAR*);
+
+static statement_t *new_call_statement(parser_ctx_t*,member_expression_t*);
+
%}
%pure_parser
@@ -40,14 +46,34 @@ static void parse_complete(parser_ctx_t*);
%union {
const WCHAR *string;
+ statement_t *statement;
+ member_expression_t *member;
}
-%token tEOF tNL
+%token tEOF tNL blah
%token <string> tIdentifier
+%type <statement> Statement StatementNl
+%type <member> MemberExpression
+
%%
-Program : tEOF { parse_complete(ctx); }
+Program
+ : SourceElements tEOF { parse_complete(ctx); }
+
+SourceElements
+ : /* empty */
+ | SourceElements StatementNl { source_add_statement(ctx, $2); }
+
+StatementNl
+ : Statement tNL { $$ = $1; }
+
+Statement
+ : MemberExpression /* FIXME: Arguments_opt */ { $$ = new_call_statement(ctx, $1); }
+
+MemberExpression
+ : tIdentifier { $$ = new_member_expression(ctx, NULL, $1); }
+ /* FIXME: MemberExpressionArgs '.' tIdentifier */
%%
@@ -56,11 +82,73 @@ static int parser_error(const char *str)
return 0;
}
+static void source_add_statement(parser_ctx_t *ctx, statement_t *stat)
+{
+ if(ctx->stats) {
+ ctx->stats_tail->next = stat;
+ ctx->stats_tail = stat;
+ }else {
+ ctx->stats = ctx->stats_tail = stat;
+ }
+}
+
static void parse_complete(parser_ctx_t *ctx)
{
ctx->parse_complete = TRUE;
}
+static void *new_expression(parser_ctx_t *ctx, expression_type_t type, unsigned size)
+{
+ expression_t *expr;
+
+ expr = parser_alloc(ctx, size ? size : sizeof(*expr));
+ if(expr) {
+ expr->type = type;
+ expr->next = NULL;
+ }
+
+ return expr;
+}
+
+static member_expression_t *new_member_expression(parser_ctx_t *ctx, expression_t *obj_expr, const WCHAR *identifier)
+{
+ member_expression_t *expr;
+
+ expr = new_expression(ctx, EXPR_MEMBER, sizeof(*expr));
+ if(!expr)
+ return NULL;
+
+ expr->obj_expr = obj_expr;
+ expr->identifier = identifier;
+ expr->args = NULL;
+ return expr;
+}
+
+static void *new_statement(parser_ctx_t *ctx, statement_type_t type, unsigned size)
+{
+ statement_t *stat;
+
+ stat = parser_alloc(ctx, size);
+ if(stat) {
+ stat->type = type;
+ stat->next = NULL;
+ }
+
+ return stat;
+}
+
+static statement_t *new_call_statement(parser_ctx_t *ctx, member_expression_t *expr)
+{
+ call_statement_t *stat;
+
+ stat = new_statement(ctx, STAT_CALL, sizeof(*stat));
+ if(!stat)
+ return NULL;
+
+ stat->expr = expr;
+ return &stat->stat;
+}
+
void *parser_alloc(parser_ctx_t *ctx, size_t size)
{
void *ret;
@@ -82,6 +170,7 @@ HRESULT parse_script(parser_ctx_t *ctx, const WCHAR *code)
ctx->last_token = tNL;
ctx->last_nl = 0;
+ ctx->stats = ctx->stats_tail = NULL;
parser_parse(ctx);
More information about the wine-cvs
mailing list