[PATCH v4 34/41] codegen: Reuse enumarators constructor

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

 



EnumType.__init__ and FlagsType.__init__ was equivalents, merge into
the base class EnumBaseType.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 python_modules/ptypes.py | 87 ++++++++++++++++--------------------------------
 1 file changed, 29 insertions(+), 58 deletions(-)

diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index 7771c81..d0b26ba 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -319,6 +319,35 @@ class TypeAlias(Type):
         return self.name
 
 class EnumBaseType(Type):
+    def __init__(self, bits, name, enums, attribute_list):
+        Type.__init__(self)
+        self.bits = bits
+        self.name = name
+
+        last = -1
+        names = {}
+        values = {}
+        descs = {}
+        for v in enums:
+            name = v[0]
+            desc = v[1][1]
+            if len(v) > 2:
+                value = v[2]
+            else:
+                value = last + 1
+            last = value
+
+            assert value not in names
+            names[value] = name
+            descs[value] = desc
+            values[name] = value
+
+        self.names = names
+        self.values = values
+        self.descs = descs
+
+        self.attributes = fix_attributes(attribute_list)
+
     def is_enum(self):
         return isinstance(self, EnumType)
 
@@ -363,35 +392,6 @@ class EnumBaseType(Type):
 
 
 class EnumType(EnumBaseType):
-    def __init__(self, bits, name, enums, attribute_list):
-        Type.__init__(self)
-        self.bits = bits
-        self.name = name
-
-        last = -1
-        names = {}
-        values = {}
-        descs = {}
-        for v in enums:
-            name = v[0]
-            desc = v[1][1]
-            if len(v) > 2:
-                value = v[2]
-            else:
-                value = last + 1
-            last = value
-
-            assert value not in names
-            names[value] = name
-            descs[value] = desc
-            values[name] = value
-
-        self.names = names
-        self.values = values
-        self.descs = descs
-
-        self.attributes = fix_attributes(attribute_list)
-
     def __str__(self):
         return "enum %s" % self.name
 
@@ -420,35 +420,6 @@ class EnumType(EnumBaseType):
         writer.newline()
 
 class FlagsType(EnumBaseType):
-    def __init__(self, bits, name, flags, attribute_list):
-        Type.__init__(self)
-        self.bits = bits
-        self.name = name
-
-        last = -1
-        names = {}
-        values = {}
-        descs = {}
-        for v in flags:
-            name = v[0]
-            desc = v[1][1]
-            if len(v) > 2:
-                value = v[2]
-            else:
-                value = last + 1
-            last = value
-
-            assert value not in names
-            names[value] = name
-            descs[value] = desc
-            values[name] = value
-
-        self.names = names
-        self.values = values
-        self.descs = descs
-
-        self.attributes = fix_attributes(attribute_list)
-
     def __str__(self):
         return "flags %s" % self.name
 
-- 
2.1.0

_______________________________________________
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]