[Spice-devel] [RFC 2/4] allow attributes on channel elements in .proto files

Christophe Fergeau cfergeau at redhat.com
Fri Jun 24 07:34:03 PDT 2011


We want to be able to add an @ifdef annotation to optional messages
For example, we want to compile in the smartcard messages only if
libcacard is available
---
 python_modules/ptypes.py       |    4 +++-
 python_modules/spice_parser.py |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py
index a99a57a..cdbe871 100644
--- a/python_modules/ptypes.py
+++ b/python_modules/ptypes.py
@@ -907,12 +907,14 @@ class ChannelMember(Containee):
         return "%s (%s)" % (str(self.name), str(self.message_type))
 
 class ChannelType(Type):
-    def __init__(self, name, base, members):
+    def __init__(self, name, base, members, attribute_list):
         Type.__init__(self)
         self.name = name
         self.base = base
         self.member_name = None
         self.members = members
+        for attr in attribute_list:
+            self.attributes[attr[0][1:]] = attr[1:]
 
     def __str__(self):
         if self.name == None:
diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py
index 43e930c..a71b2c2 100644
--- a/python_modules/spice_parser.py
+++ b/python_modules/spice_parser.py
@@ -119,7 +119,7 @@ def SPICE_BNF():
         enumDef = Group(enum_ + identifier + enumBody + attributes - semi).setParseAction(lambda toks: ptypes.EnumType(toks[0][0], toks[0][1], toks[0][2], toks[0][3]))
         flagsDef = Group(flags_ + identifier + flagsBody + attributes  - semi).setParseAction(lambda toks: ptypes.FlagsType(toks[0][0], toks[0][1], toks[0][2], toks[0][3]))
         messageDef = Group(message_ + identifier + messageBody + attributes - semi).setParseAction(lambda toks: ptypes.MessageType(toks[0][1], toks[0][2], toks[0][3]))
-        channelDef = Group(channel_ + identifier + channelBody - semi).setParseAction(lambda toks: ptypes.ChannelType(toks[0][1], toks[0][2], toks[0][3]))
+        channelDef = Group(channel_ + identifier + channelBody + attributes - semi).setParseAction(lambda toks: ptypes.ChannelType(toks[0][1], toks[0][2], toks[0][3], toks[0][4]))
         structDef = Group(struct_ + identifier + structBody + attributes - semi).setParseAction(lambda toks: ptypes.StructType(toks[0][1], toks[0][2], toks[0][3]))
         typedefDef = Group(typedef_ + identifier  + typeSpec + attributes - semi).setParseAction(lambda toks: ptypes.TypeAlias(toks[0][1], toks[0][2], toks[0][3]))
 
-- 
1.7.5.4



More information about the Spice-devel mailing list