Jacek Caban : vbscript: Added getters/setters parser implementation.

Alexandre Julliard julliard at winehq.org
Fri Sep 16 13:28:32 CDT 2011


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Sep 16 13:28:00 2011 +0200

vbscript: Added getters/setters parser implementation.

---

 dlls/vbscript/compile.c      |    4 ++++
 dlls/vbscript/parse.h        |    1 +
 dlls/vbscript/parser.y       |   37 +++++++++++++++++++++++++++++++++----
 dlls/vbscript/tests/lang.vbs |   14 ++++++++++++++
 dlls/vbscript/vbscript.h     |    5 ++++-
 5 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/dlls/vbscript/compile.c b/dlls/vbscript/compile.c
index 14d2598..015e775 100644
--- a/dlls/vbscript/compile.c
+++ b/dlls/vbscript/compile.c
@@ -666,6 +666,10 @@ static HRESULT compile_func(compile_ctx_t *ctx, statement_t *stat, function_t *f
         if(ctx->sub_end_label == -1)
             return E_OUTOFMEMORY;
         break;
+    case FUNC_PROPGET:
+    case FUNC_PROPLET:
+    case FUNC_PROPSET:
+        /* FIXME */
     case FUNC_GLOBAL:
         break;
     }
diff --git a/dlls/vbscript/parse.h b/dlls/vbscript/parse.h
index 63b2ded..6227e0c 100644
--- a/dlls/vbscript/parse.h
+++ b/dlls/vbscript/parse.h
@@ -140,6 +140,7 @@ typedef struct _function_decl_t {
     arg_decl_t *args;
     statement_t *body;
     struct _function_decl_t *next;
+    struct _function_decl_t *next_prop_func;
 } function_decl_t;
 
 typedef struct {
diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y
index 5224c71..f67abd5 100644
--- a/dlls/vbscript/parser.y
+++ b/dlls/vbscript/parser.y
@@ -115,7 +115,7 @@ static class_decl_t *add_variant_prop(parser_ctx_t*,class_decl_t*,const WCHAR*,u
 %type <expression> Arguments_opt ArgumentList_opt ArgumentList
 %type <bool> OptionExplicit_opt
 %type <arg_decl> ArgumentsDecl_opt ArgumentDeclList ArgumentDecl
-%type <func_decl> FunctionDecl
+%type <func_decl> FunctionDecl PropertyDecl
 %type <elseif> ElseIfs_opt ElseIfs ElseIf
 %type <class_decl> ClassDeclaration ClassBody
 %type <uint> Storage Storage_opt
@@ -295,6 +295,15 @@ ClassBody
     : /* empty */                               { $$ = new_class_decl(ctx); }
     | FunctionDecl tNL ClassBody                { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
     | Storage tIdentifier tNL ClassBody         { $$ = add_variant_prop(ctx, $4, $2, $1); CHECK_ERROR; }
+    | PropertyDecl tNL ClassBody                { $$ = add_class_function(ctx, $3, $1); CHECK_ERROR; }
+
+PropertyDecl
+    : Storage_opt tPROPERTY tGET tIdentifier EmptyBrackets_opt tNL StatementsNl_opt tEND tPROPERTY
+                                    { $$ = new_function_decl(ctx, $4, FUNC_PROPGET, $1, NULL, $7); CHECK_ERROR; }
+    | Storage_opt tPROPERTY tLET tIdentifier '(' ArgumentDecl ')' tNL StatementsNl_opt tEND tPROPERTY
+                                    { $$ = new_function_decl(ctx, $4, FUNC_PROPLET, $1, $6, $9); CHECK_ERROR; }
+    | Storage_opt tPROPERTY tSET tIdentifier '(' ArgumentDecl ')' tNL StatementsNl_opt tEND tPROPERTY
+                                    { $$ = new_function_decl(ctx, $4, FUNC_PROPSET, $1, $6, $9); CHECK_ERROR; }
 
 FunctionDecl
     : Storage_opt tSUB tIdentifier ArgumentsDecl_opt tNL StatementsNl_opt tEND tSUB
@@ -591,9 +600,14 @@ static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name,
     function_decl_t *decl;
 
     if(storage_flags & STORAGE_IS_DEFAULT) {
-        FIXME("Function declared as default property\n");
-        ctx->hres = E_FAIL;
-        return NULL;
+        if(type == FUNC_PROPGET) {
+            FIXME("default value not implemented\n");
+            ctx->hres = E_NOTIMPL;
+        }else {
+            FIXME("Invalid default property\n");
+            ctx->hres = E_FAIL;
+            return NULL;
+        }
     }
 
     decl = parser_alloc(ctx, sizeof(*decl));
@@ -606,6 +620,7 @@ static function_decl_t *new_function_decl(parser_ctx_t *ctx, const WCHAR *name,
     decl->args = arg_decl;
     decl->body = body;
     decl->next = NULL;
+    decl->next_prop_func = NULL;
     return decl;
 }
 
@@ -646,6 +661,20 @@ static class_decl_t *add_class_function(parser_ctx_t *ctx, class_decl_t *class_d
                 ctx->hres = E_FAIL;
                 return NULL;
             }
+
+            while(1) {
+                if(iter->type == decl->type) {
+                    FIXME("Redefinition of %s::%s\n", debugstr_w(class_decl->name), debugstr_w(decl->name));
+                    ctx->hres = E_FAIL;
+                    return NULL;
+                }
+                if(!iter->next_prop_func)
+                    break;
+                iter = iter->next_prop_func;
+            }
+
+            iter->next_prop_func = decl;
+            return class_decl;
         }
     }
 
diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs
index e29a20f..ac70b5f 100644
--- a/dlls/vbscript/tests/lang.vbs
+++ b/dlls/vbscript/tests/lang.vbs
@@ -399,11 +399,25 @@ Class TestClass
         publicFunction = 4
     End Function
 
+    Public Property Get gsProp()
+        gsProp = privateProp
+        funcCalled = "gsProp get"
+    End Property
+
     Public publicProp2
 
     Public Sub publicSub
     End Sub
 
+    Public Property Let gsProp(val)
+        privateProp = val
+        funcCalled = "gsProp let"
+    End Property
+
+    Public Property Set gsProp(val)
+        funcCalled = "gsProp set"
+    End Property
+
     Public Sub setPrivateProp(x)
         privateProp = x
     End Sub
diff --git a/dlls/vbscript/vbscript.h b/dlls/vbscript/vbscript.h
index ce1fa01..7433293 100644
--- a/dlls/vbscript/vbscript.h
+++ b/dlls/vbscript/vbscript.h
@@ -211,7 +211,10 @@ typedef struct {
 typedef enum {
     FUNC_GLOBAL,
     FUNC_FUNCTION,
-    FUNC_SUB
+    FUNC_SUB,
+    FUNC_PROPGET,
+    FUNC_PROPLET,
+    FUNC_PROPSET
 } function_type_t;
 
 typedef struct {




More information about the wine-cvs mailing list