[PATCH v6 05/42] dissector: Decorate writer class to make easier ifdef/endif handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 python_modules/dissector.py | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index cf44e3c..8446e2e 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -2,6 +2,9 @@
 from . import codegen
 import re
 
+import sys
+import types
+
 dissector_short_name = 'spice2'
 
 
@@ -97,10 +100,28 @@ 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])
+        if sys.version_info[0] == 2:
+            return types.MethodType(ifdef, None, cls)
+        return ifdef
+
+    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.4.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]