diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2022-02-22 23:01:03 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2022-02-26 23:10:21 +0100 |
commit | 6dbe93d72613536a3f4466710874bece66069d58 (patch) | |
tree | d083b4e218548b211244d33eb1aca967985f40f4 | |
parent | 84621fc57b35f757c804ce47d8593725ae0bcdd3 (diff) | |
download | libqmi-6dbe93d72613536a3f4466710874bece66069d58.tar.gz |
build-aux,codegen: no longer allow TLVs as structs
The TLVs that have more than one item should be defined as sequences,
not as structs, so that we can avoid any unneeded intermediate
struct.
The struct variable types will now exclusively be for array elements.
-rw-r--r-- | build-aux/qmi-codegen/Field.py | 4 | ||||
-rw-r--r-- | build-aux/qmi-codegen/VariableStruct.py | 130 |
2 files changed, 6 insertions, 128 deletions
diff --git a/build-aux/qmi-codegen/Field.py b/build-aux/qmi-codegen/Field.py index dd9fc70f..bdbb04e7 100644 --- a/build-aux/qmi-codegen/Field.py +++ b/build-aux/qmi-codegen/Field.py @@ -60,6 +60,10 @@ class Field: if self.since is None: raise ValueError('TLV ' + self.fullname + ' requires a "since" tag specifying the major version where it was introduced') + # TLVs can no longer be structs, they must be sequences instead + if dictionary['format'] == 'struct': + raise RuntimeError('TLV ' + self.fullname + ' cannot have type "struct": use "sequence" instead') + # Create our variable object self.variable = VariableFactory.create_variable(self.service, dictionary, self.fullname, self.container_type) diff --git a/build-aux/qmi-codegen/VariableStruct.py b/build-aux/qmi-codegen/VariableStruct.py index 91e3fa65..26f08710 100644 --- a/build-aux/qmi-codegen/VariableStruct.py +++ b/build-aux/qmi-codegen/VariableStruct.py @@ -25,6 +25,8 @@ import VariableFactory """ Variable type for Structs ('struct' format) +These variables are exclusively used as array elements, they can not be used as +independent TLVs. Use Sequence instead for that. """ class VariableStruct(Variable): @@ -155,134 +157,6 @@ class VariableStruct(Variable): """ - Variable declaration - """ - def build_variable_declaration(self, public, line_prefix, variable_name): - translations = { 'lp' : line_prefix, - 'format' : self.public_format, - 'name' : variable_name } - - template = ( - '${lp}${format} ${name};\n') - return string.Template(template).substitute(translations) - - - """ - The getter for a struct variable will include independent getters for each - of the variables in the struct. - """ - def build_getter_declaration(self, line_prefix, variable_name): - if not self.visible: - return "" - - translations = { 'lp' : line_prefix, - 'format' : self.public_format, - 'name' : variable_name } - - template = ( - '${lp}${format} *${name},\n') - return string.Template(template).substitute(translations) - - - """ - Documentation for the getter - """ - def build_getter_documentation(self, line_prefix, variable_name): - if not self.visible: - return "" - - translations = { 'lp' : line_prefix, - 'format' : self.public_format, - 'name' : variable_name } - - template = ( - '${lp}@${name}: (out)(optional)(transfer none): a placeholder for the output constant #${format}, or %NULL if not required.\n') - return string.Template(template).substitute(translations) - - - """ - Builds the Struct getter implementation - """ - def build_getter_implementation(self, line_prefix, variable_name_from, variable_name_to, to_is_reference): - if not self.visible: - return "" - - translations = { 'lp' : line_prefix, - 'from' : variable_name_from, - 'to' : variable_name_to } - - if to_is_reference: - template = ( - '${lp}if (${to})\n' - '${lp} *${to} = ${from};\n') - return string.Template(template).substitute(translations) - else: - template = ( - '${lp}${to} = ${from};\n') - return string.Template(template).substitute(translations) - - - """ - The setter for a struct variable will include independent setters for each - of the variables in the struct. - """ - def build_setter_declaration(self, line_prefix, variable_name): - if not self.visible: - return "" - - translations = { 'lp' : line_prefix, - 'format' : self.public_format, - 'name' : variable_name } - - template = ( - '${lp}const ${format} *${name},\n') - return string.Template(template).substitute(translations) - - - """ - Documentation for the setter - """ - def build_setter_documentation(self, line_prefix, variable_name): - if not self.visible: - return "" - - translations = { 'lp' : line_prefix, - 'format' : self.public_format, - 'name' : variable_name } - - template = ( - '${lp}@${name}: the address of the #${format} to set.\n') - return string.Template(template).substitute(translations) - - """ - Builds the Struct setter implementation - """ - def build_setter_implementation(self, line_prefix, variable_name_from, variable_name_to): - if not self.visible: - return "" - - built = '' - for member in self.members: - built += member['object'].build_setter_implementation(line_prefix, - variable_name_from + '->' + member['name'], - variable_name_to + '.' + member['name']) - return built - - - """ - Documentation for the struct field - """ - def build_struct_field_documentation(self, line_prefix, variable_name): - translations = { 'lp' : line_prefix, - 'format' : self.public_format, - 'name' : variable_name } - - template = ( - '${lp}@${name}: a #${format} struct.\n') - return string.Template(template).substitute(translations) - - - """ Disposing a struct is just about disposing each of the struct fields one by one. """ |