Skip to content

Commit

Permalink
[sourcegen] Handle custom code
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jan 5, 2025
1 parent 4a7f97f commit 38bef3d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
12 changes: 11 additions & 1 deletion interfaces/sourcegen/sourcegen/_data/ctsol_auto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ recipes:
- name: thermo
- name: kinetics
- name: transport
- name: setTransport # currently disabled in CLib's config.yaml
- name: setTransportModel
code: |-
try {
auto obj = SolutionCabinet::at(handle);
TransportCabinet::del(
TransportCabinet::index(*(obj->transport()), handle));
obj->setTransportModel(model);
return TransportCabinet::add(obj->transport(), handle);
} catch (...) {
return handleAllExceptions(-2, ERR);
}
- name: nAdjacent
- name: adjacent
implements: Solution::adjacent(size_t)
Expand Down
11 changes: 6 additions & 5 deletions interfaces/sourcegen/sourcegen/clib/_CLibSourceGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,12 @@ def _scaffold_body(self, c_func: CFunc, recipe: Recipe) -> tuple[str, set[str]]:
args, bases = self._reverse_crosswalk(c_func, recipe.base)
args["what"] = recipe.what

if recipe.what == "noop":
if recipe.code:
# override auto-generated code
template = loader.from_string(self._templates["clib-custom-code"])
args["lines"] = recipe.code.strip(" \n").split("\n")

elif recipe.what == "noop":
template = loader.from_string(self._templates["clib-noop"])

elif recipe.what == "function":
Expand Down Expand Up @@ -383,10 +388,6 @@ def merge_params(implements, cxx_func: CFunc) -> tuple[list[Param], int]:
args = []
brief = ""

if recipe.code:
_LOGGER.warning("Custom code is currently not implemented: "
"continuing with auto-generated code.")

if recipe.implements:
if not quiet:
_LOGGER.debug(f" generating {func_name!r} -> {recipe.implements}")
Expand Down
4 changes: 2 additions & 2 deletions interfaces/sourcegen/sourcegen/clib/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
ignore_files: []

# Ignore these specific functions:
ignore_funcs:
ctsol_auto.yaml: [setTransport]
ignore_funcs: {}
# ctsol_auto.yaml: [setTransport]

# Cabinets with associated includes
includes:
Expand Down
8 changes: 8 additions & 0 deletions interfaces/sourcegen/sourcegen/clib/templates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ clib-noop: |-
// no-op
return 0;
clib-custom-code: |-
// {{ what }}: {{ cxx_implements }}
// ********** custom code begin **********
{% for line in lines %}
{{ line }}
{% endfor -%}
// *********** custom code end ***********
clib-implementation: |-
{{ declaration }}
{
Expand Down

0 comments on commit 38bef3d

Please sign in to comment.