Jacek Caban : vbscript: Added hex literal implementation.

Alexandre Julliard julliard at winehq.org
Mon Sep 12 11:42:59 CDT 2011


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Sep 12 12:30:34 2011 +0200

vbscript: Added hex literal implementation.

---

 dlls/vbscript/lex.c          |   33 +++++++++++++++++++++++++++++++++
 dlls/vbscript/tests/lang.vbs |    8 ++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/dlls/vbscript/lex.c b/dlls/vbscript/lex.c
index ddafee9..394a24d 100644
--- a/dlls/vbscript/lex.c
+++ b/dlls/vbscript/lex.c
@@ -267,6 +267,35 @@ static int parse_numeric_literal(parser_ctx_t *ctx, void **ret)
     return tDouble;
 }
 
+static int hex_to_int(WCHAR c)
+{
+    if('0' <= c && c <= '9')
+        return c-'0';
+    if('a' <= c && c <= 'f')
+        return c+10-'a';
+    if('A' <= c && c <= 'F')
+        return c+10-'A';
+    return -1;
+}
+
+static int parse_hex_literal(parser_ctx_t *ctx, LONG *ret)
+{
+    const WCHAR *begin = ctx->ptr;
+    LONG l = 0, d;
+
+    while((d = hex_to_int(*++ctx->ptr)) != -1)
+        l = l*16 + d;
+
+    if(begin + 9 /* max digits+1 */ < ctx->ptr || *ctx->ptr != '&') {
+        FIXME("invalid literal\n");
+        return 0;
+    }
+
+    ctx->ptr++;
+    *ret = l;
+    return (short)l == l ? tShort : tLong;
+}
+
 static void skip_spaces(parser_ctx_t *ctx)
 {
     while(*ctx->ptr == ' ' || *ctx->ptr == '\t' || *ctx->ptr == '\r')
@@ -329,6 +358,10 @@ static int parse_next_token(void *lval, parser_ctx_t *ctx)
         return '(';
     case '"':
         return parse_string_literal(ctx, lval);
+    case '&':
+        if(*++ctx->ptr == 'h' || *ctx->ptr == 'H')
+            return parse_hex_literal(ctx, lval);
+        return '&';
     case '<':
         switch(*++ctx->ptr) {
         case '>':
diff --git a/dlls/vbscript/tests/lang.vbs b/dlls/vbscript/tests/lang.vbs
index 91da4fe..dba5c9a 100644
--- a/dlls/vbscript/tests/lang.vbs
+++ b/dlls/vbscript/tests/lang.vbs
@@ -31,6 +31,10 @@ Call ok(not (true = false), "true = false is true")
 Call ok("x" = "x", """x"" = ""x"" is false")
 Call ok(empty = empty, "empty = empty is false")
 Call ok(empty = "", "empty = """" is false")
+Call ok(0 = 0.0, "0 <> 0.0")
+Call ok(16 = &h10&, "16 <> &h10&")
+Call ok(010 = 10, "010 <> 10")
+Call ok(10. = 10, "10. <> 10")
 
 Call ok(getVT(false) = "VT_BOOL", "getVT(false) is not VT_BOOL")
 Call ok(getVT(true) = "VT_BOOL", "getVT(true) is not VT_BOOL")
@@ -44,5 +48,9 @@ Call ok(getVT(0.5) = "VT_R8", "getVT(0.5) is not VT_R8")
 Call ok(getVT(0.0) = "VT_R8", "getVT(0.0) is not VT_R8")
 Call ok(getVT(2147483647) = "VT_I4", "getVT(2147483647) is not VT_I4")
 Call ok(getVT(2147483648) = "VT_R8", "getVT(2147483648) is not VT_R8")
+Call ok(getVT(&h10&) = "VT_I2", "getVT(&h10&) is not VT_I2")
+Call ok(getVT(&h10000&) = "VT_I4", "getVT(&h10000&) is not VT_I4")
+Call ok(getVT(&H10000&) = "VT_I4", "getVT(&H10000&) is not VT_I4")
+Call ok(getVT(&hffFFffFF&) = "VT_I2", "getVT(&hffFFffFF&) is not VT_I2")
 
 reportSuccess()




More information about the wine-cvs mailing list