summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2022-02-27 00:06:25 +0100
committerAleksander Morgado <aleksander@aleksander.es>2022-02-27 00:25:30 +0100
commitae3b2e4eb208d558df447eb8de7a3e22ba01d116 (patch)
tree22142a77dd71d5e667a49e0c03407ebdfa6f28f2
parented0959ea69e3789713437318438e6531bfdeead8 (diff)
downloadlibqmi-ae3b2e4eb208d558df447eb8de7a3e22ba01d116.tar.gz
build-aux,codegen: split variable declarations for bundles and structs
-rw-r--r--build-aux/qmi-codegen/Container.py2
-rw-r--r--build-aux/qmi-codegen/Variable.py12
-rw-r--r--build-aux/qmi-codegen/VariableArray.py6
-rw-r--r--build-aux/qmi-codegen/VariableInteger.py21
-rw-r--r--build-aux/qmi-codegen/VariableSequence.py8
-rw-r--r--build-aux/qmi-codegen/VariableString.py21
-rw-r--r--build-aux/qmi-codegen/VariableStruct.py10
7 files changed, 56 insertions, 24 deletions
diff --git a/build-aux/qmi-codegen/Container.py b/build-aux/qmi-codegen/Container.py
index d6ee6106..1b8d18a4 100644
--- a/build-aux/qmi-codegen/Container.py
+++ b/build-aux/qmi-codegen/Container.py
@@ -169,7 +169,7 @@ class Container:
if self.fields is not None:
for field in self.fields:
if field.variable is not None:
- variable_declaration = field.variable.build_variable_declaration(False, ' ', field.variable_name)
+ variable_declaration = field.variable.build_variable_declaration(' ', field.variable_name)
translations['field_variable_name'] = field.variable_name
translations['field_name'] = field.name
template = (
diff --git a/build-aux/qmi-codegen/Variable.py b/build-aux/qmi-codegen/Variable.py
index b23630f4..c9f4da9e 100644
--- a/build-aux/qmi-codegen/Variable.py
+++ b/build-aux/qmi-codegen/Variable.py
@@ -111,9 +111,10 @@ class Variable:
pass
"""
- Builds the code to include the declaration of a variable of this kind.
+ Builds the code to include the declaration of a variable of this kind,
+ used when generating input/output bundles.
"""
- def build_variable_declaration(self, public, line_prefix, variable_name):
+ def build_variable_declaration(self, line_prefix, variable_name):
return ''
"""
@@ -153,6 +154,13 @@ class Variable:
return ''
"""
+ Builds the code to include the declaration of a variable of this kind
+ as a field in a public struct
+ """
+ def build_struct_field_declaration(self, line_prefix, variable_name):
+ return ''
+
+ """
Documentation for the struct field
"""
def build_struct_field_documentation(self, line_prefix, variable_name):
diff --git a/build-aux/qmi-codegen/VariableArray.py b/build-aux/qmi-codegen/VariableArray.py
index cae020f2..3d413a0a 100644
--- a/build-aux/qmi-codegen/VariableArray.py
+++ b/build-aux/qmi-codegen/VariableArray.py
@@ -279,7 +279,7 @@ class VariableArray(Variable):
f.write(string.Template(template).substitute(translations))
- def build_variable_declaration(self, public, line_prefix, variable_name):
+ def build_variable_declaration(self, line_prefix, variable_name):
translations = { 'lp' : line_prefix,
'name' : variable_name }
@@ -294,6 +294,10 @@ class VariableArray(Variable):
return string.Template(template).substitute(translations)
+ def build_struct_field_declaration(self, line_prefix, variable_name):
+ return self.build_variable_declaration(line_prefix, variable_name)
+
+
def build_getter_declaration(self, line_prefix, variable_name):
if not self.visible:
return ""
diff --git a/build-aux/qmi-codegen/VariableInteger.py b/build-aux/qmi-codegen/VariableInteger.py
index 01e43540..0a628d67 100644
--- a/build-aux/qmi-codegen/VariableInteger.py
+++ b/build-aux/qmi-codegen/VariableInteger.py
@@ -238,18 +238,21 @@ class VariableInteger(Variable):
f.write(string.Template(template).substitute(translations))
- def build_variable_declaration(self, public, line_prefix, variable_name):
+ def build_variable_declaration(self, line_prefix, variable_name):
translations = { 'lp' : line_prefix,
'private_format' : self.private_format,
- 'public_format' : self.public_format,
'name' : variable_name }
- template = ''
- if public:
- template += (
- '${lp}${public_format} ${name};\n')
- else:
- template += (
- '${lp}${private_format} ${name};\n')
+ template = (
+ '${lp}${private_format} ${name};\n')
+ return string.Template(template).substitute(translations)
+
+
+ def build_struct_field_declaration(self, line_prefix, variable_name):
+ translations = { 'lp' : line_prefix,
+ 'public_format' : self.public_format,
+ 'name' : variable_name }
+ template = (
+ '${lp}${public_format} ${name};\n')
return string.Template(template).substitute(translations)
diff --git a/build-aux/qmi-codegen/VariableSequence.py b/build-aux/qmi-codegen/VariableSequence.py
index 6fb5427c..5bf9bbce 100644
--- a/build-aux/qmi-codegen/VariableSequence.py
+++ b/build-aux/qmi-codegen/VariableSequence.py
@@ -89,13 +89,17 @@ class VariableSequence(Variable):
f.write(string.Template(template).substitute(translations))
- def build_variable_declaration(self, public, line_prefix, variable_name):
+ def build_variable_declaration(self, line_prefix, variable_name):
built = ''
for member in self.members:
- built += member['object'].build_variable_declaration(public, line_prefix, variable_name + '_' + member['name'])
+ built += member['object'].build_variable_declaration(line_prefix, variable_name + '_' + member['name'])
return built
+ def build_struct_field_declaration(self, line_prefix, variable_name):
+ raise RuntimeError('Variable of type "sequence" is never expected as a struct field')
+
+
def build_getter_declaration(self, line_prefix, variable_name):
if not self.visible:
return ""
diff --git a/build-aux/qmi-codegen/VariableString.py b/build-aux/qmi-codegen/VariableString.py
index aace5660..52aeb73d 100644
--- a/build-aux/qmi-codegen/VariableString.py
+++ b/build-aux/qmi-codegen/VariableString.py
@@ -154,17 +154,11 @@ class VariableString(Variable):
f.write(string.Template(template).substitute(translations))
- def build_variable_declaration(self, public, line_prefix, variable_name):
+ def build_variable_declaration(self, line_prefix, variable_name):
translations = { 'lp' : line_prefix,
'name' : variable_name }
- if public:
- # Fixed sized strings given in public structs are given as pointers,
- # instead of as fixed-sized arrays directly in the struct.
- template = (
- '${lp}gchar *${name};\n')
- self.is_public = True
- elif self.is_fixed_size:
+ if self.is_fixed_size:
translations['fixed_size_plus_one'] = int(self.fixed_size) + 1
template = (
'${lp}gchar ${name}[${fixed_size_plus_one}];\n')
@@ -174,6 +168,17 @@ class VariableString(Variable):
return string.Template(template).substitute(translations)
+ def build_struct_field_declaration(self, line_prefix, variable_name):
+ translations = { 'lp' : line_prefix,
+ 'name' : variable_name }
+
+ # Fixed sized strings given in public structs are given as pointers,
+ # instead of as fixed-sized arrays directly in the struct.
+ template = (
+ '${lp}gchar *${name};\n')
+ return string.Template(template).substitute(translations)
+
+
def build_getter_declaration(self, line_prefix, variable_name):
if not self.visible:
return ""
diff --git a/build-aux/qmi-codegen/VariableStruct.py b/build-aux/qmi-codegen/VariableStruct.py
index 4bbb44db..5377ceec 100644
--- a/build-aux/qmi-codegen/VariableStruct.py
+++ b/build-aux/qmi-codegen/VariableStruct.py
@@ -62,6 +62,14 @@ class VariableStruct(Variable):
break
+ def build_variable_declaration(self, line_prefix, variable_name):
+ raise RuntimeError('Variable of type "struct" can only be defined as array members')
+
+
+ def build_struct_field_declaration(self, line_prefix, variable_name):
+ raise RuntimeError('Variable of type "struct" cannot be defined as struct fields')
+
+
def emit_types(self, hfile, cfile, since, static):
for member in self.members:
member['object'].emit_types(hfile, cfile, since, static)
@@ -92,7 +100,7 @@ class VariableStruct(Variable):
hfile.write(string.Template(template).substitute(translations))
for member in self.members:
- hfile.write(member['object'].build_variable_declaration(True, ' ', member['name']))
+ hfile.write(member['object'].build_struct_field_declaration(' ', member['name']))
template = ('} ${format};\n')
hfile.write(string.Template(template).substitute(translations))