[Spice-devel] [PATCH 06/33] codegen: Reuse code to fix attribute from prototype file

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


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

diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index d031d09..845fa73 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -62,6 +62,14 @@ class FixedSize:
 # other members
 propagated_attributes=["ptr_array", "nonnull", "chunk"]
 
+def fix_attributes(attribute_list):
+    attrs = {}
+    for attr in attribute_list:
+        name = attr[0][1:]
+        lst = attr[1:]
+        attrs[name] = lst
+    return attrs
+
 class Type:
     def __init__(self):
         self.attributes = {}
@@ -178,8 +186,7 @@ class TypeAlias(Type):
         Type.__init__(self)
         self.name = name
         self.the_type = the_type
-        for attr in attribute_list:
-            self.attributes[attr[0][1:]] = attr[1:]
+        self.attributes = fix_attributes(attribute_list)
 
     def get_type(self, recursive=False):
         if recursive:
@@ -288,8 +295,7 @@ class EnumType(EnumBaseType):
         self.names = names
         self.values = values
 
-        for attr in attribute_list:
-            self.attributes[attr[0][1:]] = attr[1:]
+        self.attributes = fix_attributes(attribute_list)
 
     def __str__(self):
         return "enum %s" % self.name
@@ -342,8 +348,7 @@ class FlagsType(EnumBaseType):
         self.names = names
         self.values = values
 
-        for attr in attribute_list:
-            self.attributes[attr[0][1:]] = attr[1:]
+        self.attributes = fix_attributes(attribute_list)
 
     def __str__(self):
         return "flags %s" % self.name
@@ -533,8 +538,7 @@ class Member(Containee):
         Containee.__init__(self)
         self.name = name
         self.member_type = member_type
-        for attr in attribute_list:
-            self.attributes[attr[0][1:]] = attr[1:]
+        self.attributes = fix_attributes(attribute_list)
 
     def resolve(self, container):
         self.container = container
@@ -636,8 +640,7 @@ class Switch(Containee):
         self.variable = variable
         self.name = name
         self.cases = cases
-        for attr in attribute_list:
-            self.attributes[attr[0][1:]] = attr[1:]
+        self.attributes = fix_attributes(attribute_list)
 
     def is_switch(self):
         return True
@@ -846,8 +849,7 @@ class StructType(ContainerType):
         self.members_by_name = {}
         for m in members:
             self.members_by_name[m.name] = m
-        for attr in attribute_list:
-            self.attributes[attr[0][1:]] = attr[1:]
+        self.attributes = fix_attributes(attribute_list)
 
     def __str__(self):
         if self.name == None:
@@ -869,8 +871,7 @@ class MessageType(ContainerType):
         for m in members:
             self.members_by_name[m.name] = m
         self.reverse_members = {} # ChannelMembers referencing this message
-        for attr in attribute_list:
-            self.attributes[attr[0][1:]] = attr[1:]
+        self.attributes = fix_attributes(attribute_list)
 
     def __str__(self):
         if self.name == None:
@@ -938,8 +939,7 @@ class ChannelType(Type):
         self.base = base
         self.member_name = None
         self.members = members
-        for attr in attribute_list:
-            self.attributes[attr[0][1:]] = attr[1:]
+        self.attributes = fix_attributes(attribute_list)
 
     def __str__(self):
         if self.name == None:
-- 
2.1.0



More information about the Spice-devel mailing list