Jacek Caban : vbscript: Added support for negative constants.

Alexandre Julliard julliard at winehq.org
Mon Oct 29 13:52:52 CDT 2012


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Oct 29 11:52:31 2012 +0100

vbscript: Added support for negative constants.

---

 dlls/vbscript/parser.y       |   19 ++++++++++++++-----
 dlls/vbscript/tests/lang.vbs |   12 +++++++++++-
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/dlls/vbscript/parser.y b/dlls/vbscript/parser.y
index 8a2a9e3..45f9169 100644
--- a/dlls/vbscript/parser.y
+++ b/dlls/vbscript/parser.y
@@ -125,6 +125,7 @@ static const WCHAR propertyW[] = {'p','r','o','p','e','r','t','y',0};
 %type <expression> Expression LiteralExpression PrimaryExpression EqualityExpression CallExpression
 %type <expression> ConcatExpression AdditiveExpression ModExpression IntdivExpression MultiplicativeExpression ExpExpression
 %type <expression> NotExpression UnaryExpression AndExpression OrExpression XorExpression EqvExpression
+%type <expression> ConstExpression NumericLiteralExpression
 %type <member> MemberExpression
 %type <expression> Arguments_opt ArgumentList_opt Step_opt ExpressionList
 %type <bool> OptionExplicit_opt DoType
@@ -218,7 +219,11 @@ ConstDeclList
     | ConstDecl ',' ConstDeclList           { $1->next = $3; $$ = $1; }
 
 ConstDecl
-    : Identifier '=' LiteralExpression      { $$ = new_const_decl(ctx, $1, $3); CHECK_ERROR; }
+    : Identifier '=' ConstExpression        { $$ = new_const_decl(ctx, $1, $3); CHECK_ERROR; }
+
+ConstExpression
+    : LiteralExpression                     { $$ = $1; }
+    | '-' NumericLiteralExpression          { $$ = new_unary_expression(ctx, EXPR_NEG, $2); CHECK_ERROR; }
 
 DoType
     : tWHILE        { $$ = TRUE; }
@@ -354,14 +359,18 @@ LiteralExpression
     : tTRUE                         { $$ = new_bool_expression(ctx, VARIANT_TRUE); CHECK_ERROR; }
     | tFALSE                        { $$ = new_bool_expression(ctx, VARIANT_FALSE); CHECK_ERROR; }
     | tString                       { $$ = new_string_expression(ctx, $1); CHECK_ERROR; }
-    | tShort                        { $$ = new_long_expression(ctx, EXPR_USHORT, $1); CHECK_ERROR; }
-    | '0'                           { $$ = new_long_expression(ctx, EXPR_USHORT, 0); CHECK_ERROR; }
-    | tLong                         { $$ = new_long_expression(ctx, EXPR_ULONG, $1); CHECK_ERROR; }
-    | tDouble                       { $$ = new_double_expression(ctx, $1); CHECK_ERROR; }
+    | NumericLiteralExpression      { $$ = $1; }
     | tEMPTY                        { $$ = new_expression(ctx, EXPR_EMPTY, 0); CHECK_ERROR; }
     | tNULL                         { $$ = new_expression(ctx, EXPR_NULL, 0); CHECK_ERROR; }
     | tNOTHING                      { $$ = new_expression(ctx, EXPR_NOTHING, 0); CHECK_ERROR; }
 
+NumericLiteralExpression
+    : tShort                        { $$ = new_long_expression(ctx, EXPR_USHORT, $1); CHECK_ERROR; }
+    | '0'                           { $$ = new_long_expression(ctx, EXPR_USHORT, 0); CHECK_ERROR; }
+    | tLong                         { $$ = new_long_expression(ctx, EXPR_ULONG, $1); CHECK_ERROR; }
+    | tDouble                       { $$ = new_double_expression(ctx, $1); CHECK_ERROR; }
+
+
 PrimaryExpression
     : '(' Expression ')'            { $$ = new_unary_expression(ctx, EXPR_BRACKETS, $2); }
     | tME                           { $$ = new_expression(ctx, EXPR_ME, 0); CHECK_ERROR; }
diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs
index 76f4003..8cffc7f 100644
--- a/dlls/vbscript/tests/lang.vbs
+++ b/dlls/vbscript/tests/lang.vbs
@@ -912,9 +912,19 @@ Call obj.test(obj)
 Call ok(getVT(test) = "VT_DISPATCH", "getVT(test) = " & getVT(test))
 Call ok(Me is Test, "Me is not Test")
 
-Const c1 = 1, c2 = 2
+Const c1 = 1, c2 = 2, c3 = -3
 Call ok(c1 = 1, "c1 = " & c1)
 Call ok(getVT(c1) = "VT_I2", "getVT(c1) = " & getVT(c1))
+Call ok(c3 = -3, "c3 = " & c3)
+Call ok(getVT(c3) = "VT_I2", "getVT(c3) = " & getVT(c3))
+
+Const cb = True, cs = "test", cnull = null
+Call ok(cb, "cb = " & cb)
+Call ok(getVT(cb) = "VT_BOOL", "getVT(cb) = " & getVT(cb))
+Call ok(cs = "test", "cs = " & cs)
+Call ok(getVT(cs) = "VT_BSTR", "getVT(cs) = " & getVT(cs))
+Call ok(isNull(cnull), "cnull = " & cnull)
+Call ok(getVT(cnull) = "VT_NULL", "getVT(cnull) = " & getVT(cnull))
 
 if false then Const conststr = "str"
 Call ok(conststr = "str", "conststr = " & conststr)




More information about the wine-cvs mailing list