summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2015-07-21 17:45:36 +0100
committerChristophe Fergeau <cfergeau@redhat.com>2015-07-23 11:11:47 +0200
commit6f729cb32ccda351451f1cd0c9eac031fc007986 (patch)
tree5a59206c48a6b976ca0bc0a95da9d87046af4533
parent13aabda256b8a8342735b52fc3fb9e426f581dae (diff)
downloadspice-protocol-6f729cb32ccda351451f1cd0c9eac031fc007986.tar.gz
spice-protocol-6f729cb32ccda351451f1cd0c9eac031fc007986.tar.xz
spice-protocol-6f729cb32ccda351451f1cd0c9eac031fc007986.zip
codegen: Reuse code to fix attribute from prototype file
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r--python_modules/ptypes.py32
1 files 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: