Commit ecc579b8 authored by Emmanuele Bassi's avatar Emmanuele Bassi 👣
Browse files

generate: Move declarations into the Python side

It's easier to deal with whitespace inside Python than it is inside
Jinja templates.
parent 9d9f4be1
Pipeline #253459 passed with stage
in 1 minute and 36 seconds
......@@ -472,6 +472,10 @@ class TemplateInterface:
for vfunc in self.virtual_methods:
self.virtual_methods.append(TemplateMethod(namespace, self, vfunc))
@property
def c_decl(self):
return f"interface {self.type_cname} : {self.requires}"
class TemplateClass:
def __init__(self, namespace, cls):
......@@ -552,6 +556,24 @@ class TemplateClass:
for func in cls.functions:
self.type_funcs.append(TemplateFunction(func))
@property
def c_decl(self):
if not self.class_struct or not self.instance_struct:
res = [f"final class {self.type_cname} : {self.parent} {{"]
else:
res = [f"class {self.type_cname} : {self.parent} {{"]
n_fields = len(self.fields)
if n_fields > 0:
for (idx, field) in enumerate(self.fields):
if idx < n_fields - 1:
res += [f" {field.name}: {field.type_cname},"]
else:
res += [f" {field.name}: {field.type_cname}"]
else:
res += [" /* No available fields */"]
res += ["}"]
return "\n".join(res)
class TemplateRecord:
def __init__(self, namespace, record):
......
......@@ -82,7 +82,7 @@
<div class="toggle-wrapper">
<h4 id="description">Description</a></h4>
<pre><code>{% if not class.class_struct or not class.instance_struct %}final {% endif -%}class {{ namespace.name }}.{{ class.name }} : {{ class.parent }} { }</code></pre>
<pre><code>{{ class.c_decl }}</pre></code>
<div class="docblock">
{{ class.description|safe }}
......
......@@ -74,7 +74,7 @@
<div class="toggle-wrapper">
<h4><a name="description">Description</a></h4>
<pre><code>interface {{ namespace.name }}.{{ interface.name }} : {{ interface.requires }}</code></pre>
<pre><code>{{ interface.c_decl }}</code></pre>
<div class="docblock">
{{ interface.description|safe }}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment