[Spice-devel] [PATCH 13/33] Decorate writer class to make easier ifdef/endif handling

Frediano Ziglio fziglio at redhat.com
Wed Jul 1 10:10:05 PDT 2015


I'm generating code for dissector from demarshaller.
Make simple to hangle ifdef/endif not having to check manually attribute.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 python_modules/dissector.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index 6751534..67d0fa7 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -1,6 +1,8 @@
 
 from . import codegen
 
+import types
+
 
 # generate a new tree identifier
 ett_writer = None
@@ -84,10 +86,26 @@ def write_protocol_definitions(writer):
     writer.end_block()
 
 
+def decorate_writer(writer):
+    cls = writer.__class__
+
+    def create(old):
+        def ifdef(self, member):
+            if member.has_attr("ifdef"):
+                old(self, member.attributes["ifdef"][0])
+        return types.MethodType(ifdef, None, cls)
+
+    cls.ifdef      = create(cls.ifdef)
+    cls.ifdef_else = create(cls.ifdef_else)
+    cls.endif      = create(cls.endif)
+
+
 def write_protocol_parser(writer, proto):
     global hf_writer
     global ett_writer
 
+    decorate_writer(writer)
+
     write_parser_helpers(writer)
 
     # put fields declaration first
-- 
2.1.0



More information about the Spice-devel mailing list