[PATCH v5 08/41] codegen: Allows to specify attributes for array items and pointers

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

 



Specifying attributes for items allows to specify different attribute
for the same member where some are specific to the item while the
other to the array.
The element attributes are attached to the array as they cannot be
attached to the type as the object is unique for each type.
Same for pointers but in this case these attributes are attached
directly to the pointer.

Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx>
---
 python_modules/ptypes.py       |  9 +++++++--
 python_modules/spice_parser.py | 18 +++++++++++-------
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index 158809a..9436e36 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -478,12 +478,16 @@ class FlagsType(EnumBaseType):
         writer.newline()
 
 class ArrayType(Type):
-    def __init__(self, element_type, size):
+    def __init__(self, element_type, size, item_attribute_list):
         Type.__init__(self)
         self.name = None
 
         self.element_type = element_type
         self.size = size
+        self.item_attrs = fix_attributes(item_attribute_list)
+        wrong = [k for k in self.item_attrs.keys() if k[:2] != 'ws']
+        if len(wrong) != 0:
+            assert False, 'Attributes %s not expected in item list' % wrong
 
     def __str__(self):
         if self.size == None:
@@ -558,11 +562,12 @@ class ArrayType(Type):
         return self.element_type.c_type()
 
 class PointerType(Type):
-    def __init__(self, target_type):
+    def __init__(self, target_type, attribute_list):
         Type.__init__(self)
         self.name = None
         self.target_type = target_type
         self.pointer_size = default_pointer_size
+        self.attributes = fix_attributes(attribute_list)
 
     def __str__(self):
         return "%s*" % (str(self.target_type))
diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py
index 06000a4..5326e59 100644
--- a/python_modules/spice_parser.py
+++ b/python_modules/spice_parser.py
@@ -16,16 +16,20 @@ cvtInt = lambda toks: int(toks[0])
 
 def parseVariableDef(toks):
     t = toks[0][0]
-    pointer = toks[0][1]
-    name = toks[0][2]
-    array_size = toks[0][3]
-    attributes = toks[0][4]
+    item_attrs = toks[0][1]
+    pointer = toks[0][2]
+    pointer_attrs = toks[0][3]
+    name = toks[0][4]
+    array_size = toks[0][5]
+    attributes = toks[0][6]
 
     if array_size != None:
-        t = ptypes.ArrayType(t, array_size)
+        t = ptypes.ArrayType(t, array_size, item_attrs)
+    else:
+        assert len(item_attrs) == 0, "Cannot specify item attributes without an array"
 
     if pointer != None:
-        t = ptypes.PointerType(t)
+        t = ptypes.PointerType(t, pointer_attrs)
 
     return ptypes.Member(name, t, attributes)
 
@@ -105,7 +109,7 @@ def SPICE_BNF():
         arraySizeSpecBytes = Group(bytes_ + lparen + identifier + comma + identifier + rparen)
         arraySizeSpecCString = Group(cstring_ + lparen + rparen)
         arraySizeSpec = lbrack + Optional(identifier ^ integer ^ arraySizeSpecImage ^ arraySizeSpecBytes ^arraySizeSpecCString, default="") + rbrack
-        variableDef = Group(typeSpec + Optional("*", default=None) + identifier + Optional(arraySizeSpec, default=None) + attributes - semi) \
+        variableDef = Group(typeSpec + attributes + Optional("*", default=None) + attributes + identifier + Optional(arraySizeSpec, default=None) + attributes - semi) \
             .setParseAction(parseVariableDef)
 
         switchCase = Group(Group(OneOrMore(default_.setParseAction(replaceWith(None)) + colon | Group(case_.suppress() + Optional("!", default="") + identifier) + colon)) + variableDef) \
-- 
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]