Jacek Caban : vbscript: Added class functions parser implementation.

Alexandre Julliard julliard at winehq.org
Thu Sep 15 12:34:55 CDT 2011


Module: wine
Branch: master
Commit: ee67bc7a37dc8133ea5711e013825382730b9087
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=ee67bc7a37dc8133ea5711e013825382730b9087

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Sep 15 19:04:43 2011 +0200

vbscript: Added class functions parser implementation.

---

 dlls/vbscript/parse.h        |    1 +
 dlls/vbscript/parser.y       |   24 ++++++++++++++++++++++++
 dlls/vbscript/tests/lang.vbs |   12 ++++++++++++
 3 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h
index 3a4d03b..94ba0cf 100644
--- a/dlls/vbscript/parse.h
+++ b/dlls/vbscript/parse.h
@@ -148,6 +148,7 @@ typedef struct _function_statement_t {
 
 typedef struct _class_decl_t {
     const WCHAR *name;
+    function_decl_t *funcs;
     struct _class_decl_t *next;
 } class_decl_t;
 
diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y
index e310a70..3eacf2f 100644
--- a/dlls/vbscript/parser.y
+++ b/dlls/vbscript/parser.y
@@ -59,7 +59,9 @@ 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 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 class_decl_t *new_class_decl(parser_ctx_t*);
+static class_decl_t *add_class_function(parser_ctx_t*,class_decl_t*,function_decl_t*);
 
 #define STORAGE_IS_PRIVATE    1
 #define STORAGE_IS_DEFAULT    2
@@ -289,6 +291,7 @@ ClassDeclaration
 
 ClassBody
     : /* empty */                               { $$ = new_class_decl(ctx); }
+    | FunctionDecl tNL ClassBody                { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
 
 FunctionDecl
     : Storage_opt tSUB tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tSUB
@@ -599,6 +602,7 @@ static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name,
     decl->is_public = !(storage_flags & STORAGE_IS_PRIVATE);
     decl->args = arg_decl;
     decl->body = body;
+    decl->next = NULL;
     return decl;
 }
 
@@ -622,10 +626,30 @@ static class_decl_t *new_class_decl(parser_ctx_t *ctx)
     if(!class_decl)
         return NULL;
 
+    class_decl->funcs = NULL;
     class_decl->next = NULL;
     return class_decl;
 }
 
+static class_decl_t *add_class_function(parser_ctx_t *ctx, class_decl_t *class_decl, function_decl_t *decl)
+{
+    function_decl_t *iter;
+
+    for(iter = class_decl->funcs; iter; iter = iter->next) {
+        if(!strcmpiW(iter->name, decl->name)) {
+            if(decl->type == FUNC_SUB || decl->type == FUNC_FUNCTION) {
+                FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
+                ctx->hres = E_FAIL;
+                return NULL;
+            }
+        }
+    }
+
+    decl->next = class_decl->funcs;
+    class_decl->funcs = decl;
+    return class_decl;
+}
+
 void *parser_alloc(parser_ctx_t *ctx, size_t size)
 {
     void *ret;
diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs
index bc64f85..2f78403 100644
--- a/dlls/vbscript/tests/lang.vbs
+++ b/dlls/vbscript/tests/lang.vbs
@@ -386,4 +386,16 @@ Call ok(getVT(obj) = "VT_DISPATCH*", "getVT(obj) = " & getVT(obj))
 Class EmptyClass
 End Class
 
+Class TestClass
+    Public Function publicFunction()
+        publicFunction = 4
+    End Function
+
+    Public Sub publicSub
+    End Sub
+
+    Public Sub privateSub
+    End Sub
+End Class
+
 reportSuccess()




More information about the wine-cvs mailing list