Skip to content

Commit

Permalink
[sourcegen] Add cabinets
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Dec 31, 2024
1 parent 0b623d9 commit 78e5333
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
12 changes: 9 additions & 3 deletions interfaces/sourcegen/sourcegen/clib/_CLibSourceGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def _reverse_crosswalk(c_func: CFunc, base: str) -> tuple[dict[str, str], set[st
buffer = ["auto& obj", "", f"{obj_base}Cabinet::index(obj)"]
else:
buffer = ["auto& obj", "", f"{obj_base}Cabinet::index(obj, {handle})"]
bases |= {obj_base}
error = ["-2", "ERR"]
elif cxx_type.endswith("void"):
buffer = ["", "", "0"]
Expand Down Expand Up @@ -418,15 +419,20 @@ def _scaffold_source(self, header: HeaderFile) -> None:

template = loader.from_string(self._templates["clib-implementation"])
implementations = []
cabinet = None
other = set()
for c_func, recipe in zip(header.funcs, header.recipes):
body, bases = self._scaffold_body(c_func, recipe)
implementations.append(
template.render(declaration=c_func.declaration(),
body=self._scaffold_body(c_func, recipe)[0]))
template.render(declaration=c_func.declaration(),body=body))
cabinet = recipe.base
other |= bases

filename = header.output_name(suffix=".cpp", auto="3")
template = loader.from_string(self._templates["clib-source-file"])
output = template.render(
name=filename.stem, source_entries=implementations)
name=filename.stem, source_entries=implementations,
base=cabinet, other=other)

if self._out_dir:
out = Path(self._out_dir) / "src" / filename.name
Expand Down
7 changes: 7 additions & 0 deletions interfaces/sourcegen/sourcegen/clib/templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ clib-source-file: |-
using namespace Cantera;
typedef Cabinet<{{ base }}> {{ base }}Cabinet;
template<> {{ base }}Cabinet* {{ base }}Cabinet::s_storage = 0;
{% if other %}
{% for entry in other -%}
typedef Cabinet<{{ entry }}> {{ entry }}Cabinet;
{% endfor -%}
{% endif %}
extern "C" {
{% for entry in source_entries %}
{{ entry | indent(4) }}
Expand Down

0 comments on commit 78e5333

Please sign in to comment.