[Spice-devel,v2,18/43] Allows to specify attributes for array items and pointers

Submitted by Frediano Ziglio on July 8, 2015, 1:53 p.m.

Details

Message ID 1436363656-4266-19-git-send-email-fziglio@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 8, 2015, 1:53 p.m.
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@redhat.com>
---
 python_modules/ptypes.py       |  9 +++++++--
 python_modules/spice_parser.py | 18 +++++++++++-------
 2 files changed, 18 insertions(+), 9 deletions(-)

Patch hide | download patch | download mbox

diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index ff044fb..2f7e2ef 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -477,12 +477,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:
@@ -557,11 +561,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) \