diff mbox

[v2,08/14] qapi: add expr_name() helper

Message ID 1407278346-17427-9-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake Aug. 5, 2014, 10:39 p.m. UTC
Now that we know every expression has a known meta-type, we
can add a helper function that retrieves the name of an
arbitrary expression, for use in future error messages.

* scripts/qapi.py (expr_name): New function.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 scripts/qapi.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)
diff mbox

Patch

diff --git a/scripts/qapi.py b/scripts/qapi.py
index 910e422..e02fa0b 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -248,6 +248,19 @@  def discriminator_find_enum_define(expr):

     return find_enum(discriminator_type)

+def expr_name(expr):
+    if expr.has_key('union'):
+        return expr['union']
+    if expr.has_key('type'):
+        return expr['type']
+    if expr.has_key('enum'):
+        return expr['enum']
+    if expr.has_key('command'):
+        return expr['command']
+    if expr.has_key('event'):
+        return expr['event']
+    return None
+
 def check_event(expr, expr_info):
     params = expr.get('data')
     if params: