vbscript: Added is expression implementation.
authorJacek Caban <jacek@codeweavers.com>
Mon, 19 Sep 2011 12:08:02 +0000 (14:08 +0200)
committerAlexandre Julliard <julliard@winehq.org>
Mon, 19 Sep 2011 16:00:01 +0000 (18:00 +0200)
dlls/vbscript/compile.c
dlls/vbscript/interp.c
dlls/vbscript/parse.h
dlls/vbscript/parser.y
dlls/vbscript/tests/lang.vbs
dlls/vbscript/vbscript.h

index c939aea214896a0e38594392cc1abb2ec46d2df6..df08c2422c66e7aa64c63579c5b12511cd107ae0 100644 (file)
@@ -387,6 +387,8 @@ static HRESULT compile_expression(compile_ctx_t *ctx, expression_t *expr)
         return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_gteq);
     case EXPR_IDIV:
         return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_idiv);
+    case EXPR_IS:
+        return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_is);
     case EXPR_IMP:
         return compile_binary_expression(ctx, (binary_expression_t*)expr, OP_imp);
     case EXPR_LT:
index d3c3483e8b2ca40e0a15eab4027b0363d0f46074..472d23c4d44127877d4f48ea9d657870ea971ff5 100644 (file)
@@ -1005,6 +1005,77 @@ static HRESULT interp_lteq(exec_ctx_t *ctx)
     return stack_push(ctx, &v);
 }
 
+static HRESULT disp_cmp(IDispatch *disp1, IDispatch *disp2, VARIANT_BOOL *ret)
+{
+    IObjectIdentity *identity;
+    IUnknown *unk1, *unk2;
+    HRESULT hres;
+
+    if(disp1 == disp2) {
+        *ret = VARIANT_TRUE;
+        return S_OK;
+    }
+
+    if(!disp1 || !disp2) {
+        *ret = VARIANT_FALSE;
+        return S_OK;
+    }
+
+    hres = IDispatch_QueryInterface(disp1, &IID_IUnknown, (void**)&unk1);
+    if(FAILED(hres))
+        return hres;
+
+    hres = IDispatch_QueryInterface(disp2, &IID_IUnknown, (void**)&unk2);
+    if(FAILED(hres)) {
+        IUnknown_Release(unk1);
+        return hres;
+    }
+
+    if(unk1 == unk2) {
+        *ret = VARIANT_TRUE;
+    }else {
+        hres = IUnknown_QueryInterface(unk1, &IID_IObjectIdentity, (void**)&identity);
+        if(SUCCEEDED(hres)) {
+            hres = IObjectIdentity_IsEqualObject(identity, unk2);
+            IObjectIdentity_Release(identity);
+            *ret = hres == S_OK ? VARIANT_TRUE : VARIANT_FALSE;
+        }else {
+            *ret = VARIANT_FALSE;
+        }
+    }
+
+    IUnknown_Release(unk1);
+    IUnknown_Release(unk2);
+    return S_OK;
+}
+
+static HRESULT interp_is(exec_ctx_t *ctx)
+{
+    IDispatch *l, *r;
+    VARIANT v;
+    HRESULT hres;
+
+    TRACE("\n");
+
+    hres = stack_pop_disp(ctx, &r);
+    if(FAILED(hres))
+        return hres;
+
+    hres = stack_pop_disp(ctx, &l);
+    if(SUCCEEDED(hres)) {
+        V_VT(&v) = VT_BOOL;
+        hres = disp_cmp(l, r, &V_BOOL(&v));
+        if(l)
+            IDispatch_Release(l);
+    }
+    if(r)
+        IDispatch_Release(r);
+    if(FAILED(hres))
+        return hres;
+
+    return stack_push(ctx, &v);
+}
+
 static HRESULT interp_concat(exec_ctx_t *ctx)
 {
     variant_val_t r, l;
index ef7f1390ed39785a4e8b9dd024eb5e463b11a4c3..b61582b9a714e229c913c2eb5e320c0bb94cc713 100644 (file)
@@ -31,6 +31,7 @@ typedef enum {
     EXPR_GTEQ,
     EXPR_IDIV,
     EXPR_IMP,
+    EXPR_IS,
     EXPR_LT,
     EXPR_LTEQ,
     EXPR_MEMBER,
index d0c3f700751f3ee062c952753f0bd221db802ff0..f25d82591c59e4a88f7822d32343871232b433de 100644 (file)
@@ -252,6 +252,7 @@ EqualityExpression
     | EqualityExpression '<' ConcatExpression   { $$ = new_binary_expression(ctx, EXPR_LT, $1, $3); CHECK_ERROR; }
     | EqualityExpression tGTEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_GTEQ, $1, $3); CHECK_ERROR; }
     | EqualityExpression tLTEQ ConcatExpression { $$ = new_binary_expression(ctx, EXPR_LTEQ, $1, $3); CHECK_ERROR; }
+    | EqualityExpression tIS ConcatExpression   { $$ = new_binary_expression(ctx, EXPR_IS, $1, $3); CHECK_ERROR; }
 
 ConcatExpression
     : AdditiveExpression                        { $$ = $1; }
index a63f9cf016106b2cfe9ea26c799f3658431fdd3c..64230dc1ecfe1c1769b271132c520168a7420aa8 100644 (file)
@@ -608,4 +608,16 @@ funcCalled = ""
 Set obj = Nothing
 Call ok(funcCalled = "terminate", "funcCalled = " & funcCalled)
 
+Set obj = new EmptyClass
+Set x = obj
+Set y = new EmptyClass
+
+Call ok(obj is x, "obj is not x")
+Call ok(x is obj, "x is not obj")
+Call ok(not (obj is y), "obj is not y")
+Call ok(not obj is y, "obj is not y")
+Call ok(not (x is Nothing), "x is 1")
+Call ok(Nothing is Nothing, "Nothing is not Nothing")
+Call ok(x is obj and true, "x is obj and true is false")
+
 reportSuccess()
index c73f11df1a382149cec6672c3d9b26f5424beb73..60835118961fc55ac1b0ccaebbff444c3fdf7c52 100644 (file)
@@ -167,6 +167,7 @@ typedef enum {
     X(icallv,         1, ARG_BSTR,    ARG_UINT)   \
     X(idiv,           1, 0,           0)          \
     X(imp,            1, 0,           0)          \
+    X(is,             1, 0,           0)          \
     X(jmp,            0, ARG_ADDR,    0)          \
     X(jmp_false,      0, ARG_ADDR,    0)          \
     X(jmp_true,       0, ARG_ADDR,    0)          \