cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-qjson-Give-each-of-the-six-structural-chars-its-own-.patch

34b321
From 95aeff93da762bf7f69317eb674d3eccce672038 Mon Sep 17 00:00:00 2001
34b321
From: Markus Armbruster <armbru@redhat.com>
34b321
Date: Wed, 27 Jul 2016 07:35:04 +0200
34b321
Subject: [PATCH 06/16] qjson: Give each of the six structural chars its own
34b321
 token type
34b321
34b321
RH-Author: Markus Armbruster <armbru@redhat.com>
34b321
Message-id: <1469604913-12442-8-git-send-email-armbru@redhat.com>
34b321
Patchwork-id: 71482
34b321
O-Subject: [RHEL-7.3 qemu-kvm PATCH v2 06/15] qjson: Give each of the six structural chars its own token type
34b321
Bugzilla: 1276036
34b321
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
RH-Acked-by: John Snow <jsnow@redhat.com>
34b321
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
34b321
34b321
Simplifies things, because we always check for a specific one.
34b321
34b321
Signed-off-by: Markus Armbruster <armbru@redhat.com>
34b321
Message-Id: <1448486613-17634-6-git-send-email-armbru@redhat.com>
34b321
Reviewed-by: Eric Blake <eblake@redhat.com>
34b321
(cherry picked from commit c54616608af442edf4cfb7397a1909c2653efba0)
34b321
Signed-off-by: Markus Armbruster <armbru@redhat.com>
34b321
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
34b321
---
34b321
 include/qapi/qmp/json-lexer.h |  7 ++++++-
34b321
 qobject/json-lexer.c          | 19 ++++++++++++-------
34b321
 qobject/json-parser.c         | 31 +++++++++----------------------
34b321
 qobject/json-streamer.c       | 32 +++++++++++++++-----------------
34b321
 4 files changed, 42 insertions(+), 47 deletions(-)
34b321
34b321
diff --git a/include/qapi/qmp/json-lexer.h b/include/qapi/qmp/json-lexer.h
34b321
index 61a143f..f3e8dc7 100644
34b321
--- a/include/qapi/qmp/json-lexer.h
34b321
+++ b/include/qapi/qmp/json-lexer.h
34b321
@@ -19,7 +19,12 @@
34b321
 
34b321
 typedef enum json_token_type {
34b321
     JSON_MIN = 100,
34b321
-    JSON_OPERATOR = JSON_MIN,
34b321
+    JSON_LCURLY = JSON_MIN,
34b321
+    JSON_RCURLY,
34b321
+    JSON_LSQUARE,
34b321
+    JSON_RSQUARE,
34b321
+    JSON_COLON,
34b321
+    JSON_COMMA,
34b321
     JSON_INTEGER,
34b321
     JSON_FLOAT,
34b321
     JSON_KEYWORD,
34b321
diff --git a/qobject/json-lexer.c b/qobject/json-lexer.c
34b321
index f106ffb..1bfff02 100644
34b321
--- a/qobject/json-lexer.c
34b321
+++ b/qobject/json-lexer.c
34b321
@@ -257,12 +257,12 @@ static const uint8_t json_lexer[][256] =  {
34b321
         ['0'] = IN_ZERO,
34b321
         ['1' ... '9'] = IN_NONZERO_NUMBER,
34b321
         ['-'] = IN_NEG_NONZERO_NUMBER,
34b321
-        ['{'] = JSON_OPERATOR,
34b321
-        ['}'] = JSON_OPERATOR,
34b321
-        ['['] = JSON_OPERATOR,
34b321
-        [']'] = JSON_OPERATOR,
34b321
-        [','] = JSON_OPERATOR,
34b321
-        [':'] = JSON_OPERATOR,
34b321
+        ['{'] = JSON_LCURLY,
34b321
+        ['}'] = JSON_RCURLY,
34b321
+        ['['] = JSON_LSQUARE,
34b321
+        [']'] = JSON_RSQUARE,
34b321
+        [','] = JSON_COMMA,
34b321
+        [':'] = JSON_COLON,
34b321
         ['a' ... 'z'] = IN_KEYWORD,
34b321
         ['%'] = IN_ESCAPE,
34b321
         [' '] = IN_WHITESPACE,
34b321
@@ -299,7 +299,12 @@ static int json_lexer_feed_char(JSONLexer *lexer, char ch, bool flush)
34b321
         }
34b321
 
34b321
         switch (new_state) {
34b321
-        case JSON_OPERATOR:
34b321
+        case JSON_LCURLY:
34b321
+        case JSON_RCURLY:
34b321
+        case JSON_LSQUARE:
34b321
+        case JSON_RSQUARE:
34b321
+        case JSON_COLON:
34b321
+        case JSON_COMMA:
34b321
         case JSON_ESCAPE:
34b321
         case JSON_INTEGER:
34b321
         case JSON_FLOAT:
34b321
diff --git a/qobject/json-parser.c b/qobject/json-parser.c
34b321
index fa09769..50bf30c 100644
34b321
--- a/qobject/json-parser.c
34b321
+++ b/qobject/json-parser.c
34b321
@@ -64,19 +64,6 @@ static JSONTokenType token_get_type(QObject *obj)
34b321
     return qdict_get_int(qobject_to_qdict(obj), "type");
34b321
 }
34b321
 
34b321
-static int token_is_operator(QObject *obj, char op)
34b321
-{
34b321
-    const char *val;
34b321
-
34b321
-    if (token_get_type(obj) != JSON_OPERATOR) {
34b321
-        return 0;
34b321
-    }
34b321
-
34b321
-    val = token_get_value(obj);
34b321
-
34b321
-    return (val[0] == op) && (val[1] == 0);
34b321
-}
34b321
-
34b321
 static int token_is_keyword(QObject *obj, const char *value)
34b321
 {
34b321
     if (token_get_type(obj) != JSON_KEYWORD) {
34b321
@@ -385,7 +372,7 @@ static int parse_pair(JSONParserContext *ctxt, QDict *dict, va_list *ap)
34b321
         goto out;
34b321
     }
34b321
 
34b321
-    if (!token_is_operator(token, ':')) {
34b321
+    if (token_get_type(token) != JSON_COLON) {
34b321
         parse_error(ctxt, token, "missing : in object pair");
34b321
         goto out;
34b321
     }
34b321
@@ -420,7 +407,7 @@ static QObject *parse_object(JSONParserContext *ctxt, va_list *ap)
34b321
         goto out;
34b321
     }
34b321
 
34b321
-    if (!token_is_operator(token, '{')) {
34b321
+    if (token_get_type(token) != JSON_LCURLY) {
34b321
         goto out;
34b321
     }
34b321
 
34b321
@@ -432,7 +419,7 @@ static QObject *parse_object(JSONParserContext *ctxt, va_list *ap)
34b321
         goto out;
34b321
     }
34b321
 
34b321
-    if (!token_is_operator(peek, '}')) {
34b321
+    if (token_get_type(peek) != JSON_RCURLY) {
34b321
         if (parse_pair(ctxt, dict, ap) == -1) {
34b321
             goto out;
34b321
         }
34b321
@@ -443,8 +430,8 @@ static QObject *parse_object(JSONParserContext *ctxt, va_list *ap)
34b321
             goto out;
34b321
         }
34b321
 
34b321
-        while (!token_is_operator(token, '}')) {
34b321
-            if (!token_is_operator(token, ',')) {
34b321
+        while (token_get_type(token) != JSON_RCURLY) {
34b321
+            if (token_get_type(token) != JSON_COMMA) {
34b321
                 parse_error(ctxt, token, "expected separator in dict");
34b321
                 goto out;
34b321
             }
34b321
@@ -482,7 +469,7 @@ static QObject *parse_array(JSONParserContext *ctxt, va_list *ap)
34b321
         goto out;
34b321
     }
34b321
 
34b321
-    if (!token_is_operator(token, '[')) {
34b321
+    if (token_get_type(token) != JSON_LSQUARE) {
34b321
         goto out;
34b321
     }
34b321
 
34b321
@@ -494,7 +481,7 @@ static QObject *parse_array(JSONParserContext *ctxt, va_list *ap)
34b321
         goto out;
34b321
     }
34b321
 
34b321
-    if (!token_is_operator(peek, ']')) {
34b321
+    if (token_get_type(peek) != JSON_RSQUARE) {
34b321
         QObject *obj;
34b321
 
34b321
         obj = parse_value(ctxt, ap);
34b321
@@ -511,8 +498,8 @@ static QObject *parse_array(JSONParserContext *ctxt, va_list *ap)
34b321
             goto out;
34b321
         }
34b321
 
34b321
-        while (!token_is_operator(token, ']')) {
34b321
-            if (!token_is_operator(token, ',')) {
34b321
+        while (token_get_type(token) != JSON_RSQUARE) {
34b321
+            if (token_get_type(token) != JSON_COMMA) {
34b321
                 parse_error(ctxt, token, "expected separator in list");
34b321
                 goto out;
34b321
             }
34b321
diff --git a/qobject/json-streamer.c b/qobject/json-streamer.c
34b321
index 2bd22a7..4a161a1 100644
34b321
--- a/qobject/json-streamer.c
34b321
+++ b/qobject/json-streamer.c
34b321
@@ -26,23 +26,21 @@ static void json_message_process_token(JSONLexer *lexer, QString *token, JSONTok
34b321
     JSONMessageParser *parser = container_of(lexer, JSONMessageParser, lexer);
34b321
     QDict *dict;
34b321
 
34b321
-    if (type == JSON_OPERATOR) {
34b321
-        switch (qstring_get_str(token)[0]) {
34b321
-        case '{':
34b321
-            parser->brace_count++;
34b321
-            break;
34b321
-        case '}':
34b321
-            parser->brace_count--;
34b321
-            break;
34b321
-        case '[':
34b321
-            parser->bracket_count++;
34b321
-            break;
34b321
-        case ']':
34b321
-            parser->bracket_count--;
34b321
-            break;
34b321
-        default:
34b321
-            break;
34b321
-        }
34b321
+    switch (type) {
34b321
+    case JSON_LCURLY:
34b321
+        parser->brace_count++;
34b321
+        break;
34b321
+    case JSON_RCURLY:
34b321
+        parser->brace_count--;
34b321
+        break;
34b321
+    case JSON_LSQUARE:
34b321
+        parser->bracket_count++;
34b321
+        break;
34b321
+    case JSON_RSQUARE:
34b321
+        parser->bracket_count--;
34b321
+        break;
34b321
+    default:
34b321
+        break;
34b321
     }
34b321
 
34b321
     dict = qdict_new();
34b321
-- 
34b321
1.8.3.1
34b321