diff options
-rw-r--r-- | docs/spice_protocol.txt | 6 | ||||
-rw-r--r-- | python_modules/ptypes.py | 22 | ||||
-rw-r--r-- | python_modules/spice_parser.py | 2 | ||||
-rw-r--r-- | spice.proto | 2 |
4 files changed, 22 insertions, 10 deletions
diff --git a/docs/spice_protocol.txt b/docs/spice_protocol.txt index e0c27b8..48f67c7 100644 --- a/docs/spice_protocol.txt +++ b/docs/spice_protocol.txt @@ -438,6 +438,12 @@ This flag field should contain just a single flag. Actually it's not used by python code so it's not enforced and no code is generated. +deprecated +~~~~~~~~~~ + +This flag currently apply only to enumerations and flags types and will set +generated C enumeration constant to deprecated + ptr_array ~~~~~~~~~ diff --git a/python_modules/ptypes.py b/python_modules/ptypes.py index 5aa6e18..7b4146d 100644 --- a/python_modules/ptypes.py +++ b/python_modules/ptypes.py @@ -20,7 +20,7 @@ def get_named_types(): # other members propagated_attributes=["ptr_array", "nonnull", "chunk"] -valid_attributes=set([ +valid_attributes_generic=set([ # embedded/appended at the end of the resulting C structure 'end', # the C structure contains a pointer to data @@ -86,7 +86,7 @@ attributes_with_arguments=set([ 'virtual', ]) -def fix_attributes(attribute_list): +def fix_attributes(attribute_list, valid_attributes=valid_attributes_generic): attrs = {} for attr in attribute_list: name = attr[0][1:] # [1:] strips the leading '@' from the name @@ -173,8 +173,6 @@ class Type: _types_by_name[self.name] = self def has_attr(self, name): - if not name in valid_attributes: - raise Exception('attribute %s not expected' % name) return name in self.attributes class TypeRef(Type): @@ -310,9 +308,10 @@ class EnumType(EnumBaseType): last = -1 names = {} values = {} + attributes = {} for v in enums: name = v[0] - if len(v) > 1: + if v[1] is not None: value = v[1] else: value = last + 1 @@ -321,9 +320,11 @@ class EnumType(EnumBaseType): assert value not in names names[value] = name values[name] = value + attributes[value] = fix_attributes(v[2], set(['deprecated'])) self.names = names self.values = values + self.val_attributes = attributes self.attributes = fix_attributes(attribute_list) @@ -341,6 +342,8 @@ class EnumType(EnumBaseType): writer.write(self.c_enumname(i)) if i != current_default: writer.write(" = %d" % (i)) + if 'deprecated' in self.val_attributes[i]: + writer.write(' SPICE_GNUC_DEPRECATED') writer.write(",") writer.newline() current_default = i + 1 @@ -363,9 +366,10 @@ class FlagsType(EnumBaseType): last = -1 names = {} values = {} + attributes = {} for v in flags: name = v[0] - if len(v) > 1: + if v[1] is not None: value = v[1] else: value = last + 1 @@ -374,9 +378,11 @@ class FlagsType(EnumBaseType): assert value not in names names[value] = name values[name] = value + attributes[value] = fix_attributes(v[2], set(['deprecated'])) self.names = names self.values = values + self.val_attributes = attributes self.attributes = fix_attributes(attribute_list) @@ -394,6 +400,8 @@ class FlagsType(EnumBaseType): writer.write(self.c_enumname(i)) mask = mask | (1<<i) writer.write(" = (1 << %d)" % (i)) + if 'deprecated' in self.val_attributes[i]: + writer.write(' SPICE_GNUC_DEPRECATED') writer.write(",") writer.newline() current_default = i + 1 @@ -600,8 +608,6 @@ class Containee: return not self.is_switch() and self.member_type.is_primitive() def has_attr(self, name): - if not name in valid_attributes: - raise Exception('attribute %s not expected' % name) return name in self.attributes def has_end_attr(self): diff --git a/python_modules/spice_parser.py b/python_modules/spice_parser.py index db3cc8d..6fa3fc8 100644 --- a/python_modules/spice_parser.py +++ b/python_modules/spice_parser.py @@ -112,7 +112,7 @@ def SPICE_BNF(): int32_ ^ uint32_ ^ int64_ ^ uint64_ ^ unix_fd_ ^ typename).setName("type") - flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(equals + integer))) + Optional(comma) + rbrace) + flagsBody = enumBody = Group(lbrace + delimitedList(Group (enumname + Optional(equals + integer, default=None) + attributes)) + Optional(comma) + rbrace) messageSpec = Group(message_ + messageBody + attributes).setParseAction(lambda toks: ptypes.MessageType(None, toks[0][1], toks[0][2])) | typename diff --git a/spice.proto b/spice.proto index d9b419e..2042754 100644 --- a/spice.proto +++ b/spice.proto @@ -1163,7 +1163,7 @@ channel CursorChannel : BaseChannel { enum16 audio_data_mode { INVALID, RAW, - CELT_0_5_1, + CELT_0_5_1 @deprecated, OPUS, }; |