Patchwork [07/22] qapi: qapi_visit.py, support generating static functions

login
register
mail settings
Submitter Michael Roth
Date July 24, 2012, 5:20 p.m.
Message ID <1343150454-4677-8-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/173020/
State New
Headers show

Comments

Michael Roth - July 24, 2012, 5:20 p.m.
qidl embeds visitor code into object files rather than linking against
seperate files, so allow for static declarations when we're using
qapi_visit.py as a library as we do with qidl.py

Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 scripts/qapi_visit.py |   51 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 18 deletions(-)
Anthony Liguori - July 24, 2012, 10:19 p.m.
Michael Roth <mdroth@linux.vnet.ibm.com> writes:

Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>

Regards,

Anthony Liguori

> qidl embeds visitor code into object files rather than linking against
> seperate files, so allow for static declarations when we're using
> qapi_visit.py as a library as we do with qidl.py
>
> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
> ---
>  scripts/qapi_visit.py |   51 ++++++++++++++++++++++++++++++++-----------------
>  1 file changed, 33 insertions(+), 18 deletions(-)
>
> diff --git a/scripts/qapi_visit.py b/scripts/qapi_visit.py
> index bf93bfe..864acb2 100644
> --- a/scripts/qapi_visit.py
> +++ b/scripts/qapi_visit.py
> @@ -139,13 +139,16 @@ visit_end_optional(m, &err);
>  ''')
>      return ret
>  
> -def generate_visit_struct(name, members):
> +def generate_visit_struct(name, members, static=False):
> +    ret_type = "void"
> +    if static:
> +        ret_type = "static " + ret_type
>      ret = mcgen('''
>  
> -void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp)
> +%(ret_type)s visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp)
>  {
>  ''',
> -                name=name)
> +                name=name, ret_type=ret_type)
>  
>      push_indent()
>      ret += generate_visit_struct_body("", name, members)
> @@ -156,10 +159,13 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
>  ''')
>      return ret
>  
> -def generate_visit_list(name, members):
> +def generate_visit_list(name, members, static=False):
> +    ret_type = "void"
> +    if static:
> +        ret_type = "static " + ret_type
>      return mcgen('''
>  
> -void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
> +%(ret_type)s visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
>  {
>      GenericList *i, **prev = (GenericList **)obj;
>      Error *err = NULL;
> @@ -181,19 +187,22 @@ void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name,
>      }
>  }
>  ''',
> -                name=name)
> +                name=name, ret_type=ret_type)
>  
> -def generate_visit_enum(name, members):
> +def generate_visit_enum(name, members, static=False):
> +    ret_type = "void"
> +    if static:
> +        ret_type = "static " + ret_type
>      return mcgen('''
>  
> -void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp)
> +%(ret_type)s visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp)
>  {
>      visit_type_enum(m, (int *)obj, %(name)s_lookup, "%(name)s", name, errp);
>  }
>  ''',
> -                 name=name)
> +                 name=name, ret_type=ret_type)
>  
> -def generate_visit_union(name, members):
> +def generate_visit_union(name, members, static=False):
>      ret = generate_visit_enum('%sKind' % name, members.keys())
>  
>      ret += mcgen('''
> @@ -250,27 +259,33 @@ void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
>  
>      return ret
>  
> -def generate_declaration(name, members, genlist=True):
> +def generate_declaration(name, members, genlist=True, static=False):
> +    ret_type = "void"
> +    if static:
> +        ret_type = "static " + ret_type
>      ret = mcgen('''
>  
> -void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
> +%(ret_type)s visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
>  ''',
> -                name=name)
> +                name=name, ret_type=ret_type)
>  
>      if genlist:
>          ret += mcgen('''
> -void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp);
> +%(ret_type)s visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp);
>  ''',
> -                 name=name)
> +                 name=name, ret_type=ret_type)
>  
>      return ret
>  
> -def generate_decl_enum(name, members, genlist=True):
> +def generate_decl_enum(name, members, genlist=True, static=False):
> +    ret_type = "void"
> +    if static:
> +        ret_type = "static " + ret_type
>      return mcgen('''
>  
> -void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp);
> +%(ret_type)s visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp);
>  ''',
> -                name=name)
> +                name=name, ret_type=ret_type)
>  
>  def main(argv=[]):
>      try:
> -- 
> 1.7.9.5

Patch

diff --git a/scripts/qapi_visit.py b/scripts/qapi_visit.py
index bf93bfe..864acb2 100644
--- a/scripts/qapi_visit.py
+++ b/scripts/qapi_visit.py
@@ -139,13 +139,16 @@  visit_end_optional(m, &err);
 ''')
     return ret
 
-def generate_visit_struct(name, members):
+def generate_visit_struct(name, members, static=False):
+    ret_type = "void"
+    if static:
+        ret_type = "static " + ret_type
     ret = mcgen('''
 
-void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp)
+%(ret_type)s visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp)
 {
 ''',
-                name=name)
+                name=name, ret_type=ret_type)
 
     push_indent()
     ret += generate_visit_struct_body("", name, members)
@@ -156,10 +159,13 @@  void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
 ''')
     return ret
 
-def generate_visit_list(name, members):
+def generate_visit_list(name, members, static=False):
+    ret_type = "void"
+    if static:
+        ret_type = "static " + ret_type
     return mcgen('''
 
-void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
+%(ret_type)s visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp)
 {
     GenericList *i, **prev = (GenericList **)obj;
     Error *err = NULL;
@@ -181,19 +187,22 @@  void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name,
     }
 }
 ''',
-                name=name)
+                name=name, ret_type=ret_type)
 
-def generate_visit_enum(name, members):
+def generate_visit_enum(name, members, static=False):
+    ret_type = "void"
+    if static:
+        ret_type = "static " + ret_type
     return mcgen('''
 
-void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp)
+%(ret_type)s visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp)
 {
     visit_type_enum(m, (int *)obj, %(name)s_lookup, "%(name)s", name, errp);
 }
 ''',
-                 name=name)
+                 name=name, ret_type=ret_type)
 
-def generate_visit_union(name, members):
+def generate_visit_union(name, members, static=False):
     ret = generate_visit_enum('%sKind' % name, members.keys())
 
     ret += mcgen('''
@@ -250,27 +259,33 @@  void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **
 
     return ret
 
-def generate_declaration(name, members, genlist=True):
+def generate_declaration(name, members, genlist=True, static=False):
+    ret_type = "void"
+    if static:
+        ret_type = "static " + ret_type
     ret = mcgen('''
 
-void visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
+%(ret_type)s visit_type_%(name)s(Visitor *m, %(name)s ** obj, const char *name, Error **errp);
 ''',
-                name=name)
+                name=name, ret_type=ret_type)
 
     if genlist:
         ret += mcgen('''
-void visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp);
+%(ret_type)s visit_type_%(name)sList(Visitor *m, %(name)sList ** obj, const char *name, Error **errp);
 ''',
-                 name=name)
+                 name=name, ret_type=ret_type)
 
     return ret
 
-def generate_decl_enum(name, members, genlist=True):
+def generate_decl_enum(name, members, genlist=True, static=False):
+    ret_type = "void"
+    if static:
+        ret_type = "static " + ret_type
     return mcgen('''
 
-void visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp);
+%(ret_type)s visit_type_%(name)s(Visitor *m, %(name)s * obj, const char *name, Error **errp);
 ''',
-                name=name)
+                name=name, ret_type=ret_type)
 
 def main(argv=[]):
     try: