Skip to content
Snippets Groups Projects
Commit 43901615 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

fixed nested namespaces

parent 59f06397
Branches
Tags
No related merge requests found
......@@ -57,6 +57,8 @@ class SfgContext:
self._config = config
self._default_kernel_namespace = SfgKernelNamespace(self, "kernels")
self._code_namespace = None
# Source Components
self._includes = set()
self._kernel_namespaces = {self._default_kernel_namespace.name: self._default_kernel_namespace}
......@@ -70,6 +72,18 @@ class SfgContext:
def root_namespace(self) -> str:
return self._config.base_namespace
@property
def inner_namespace(self) -> str:
return self._code_namespace
@property
def fully_qualified_namespace(self) -> str:
match (self.root_namespace, self.inner_namespace):
case None, None: return None
case outer, None: return outer
case None, inner: return inner
case outer, inner: return f"{outer}::{inner}"
@property
def codestyle(self) -> SfgCodeStyle:
return self._config.codestyle
......
......@@ -21,12 +21,14 @@ class BasicCpuEmitter:
)
def write_files(self, ctx: SfgContext):
fq_namespace = ctx.fully_qualified_namespace
jinja_context = {
'ctx': ctx,
'header_filename': self._header_filename,
'source_filename': self._source_filename,
'basename': self._basename,
'root_namespace': ctx.root_namespace,
'fq_namespace': fq_namespace,
'public_includes': list(incl.get_code() for incl in ctx.includes() if not incl.private),
'private_includes': list(incl.get_code() for incl in ctx.includes() if incl.private),
'kernel_namespaces': list(ctx.kernel_namespaces()),
......@@ -35,7 +37,10 @@ class BasicCpuEmitter:
template_name = "BasicCpu"
env = Environment(loader=PackageLoader('pystencilssfg.emitters.cpu'), undefined=StrictUndefined)
env = Environment(loader=PackageLoader('pystencilssfg.emitters.cpu'),
undefined=StrictUndefined,
trim_blocks=True,
lstrip_blocks=True)
from .jinja_filters import add_filters_to_jinja
add_filters_to_jinja(env)
......
#include "{{header_filename}}"
{% for incl in private_includes -%}
{% for incl in private_includes %}
{{incl}}
{% endfor %}
#define FUNC_PREFIX inline
namespace {{root_namespace}} {
{% if fq_namespace is not none %}
namespace {{fq_namespace}} {
{% endif %}
/*************************************************************************************
* Kernels
*************************************************************************************/
{% for kns in kernel_namespaces -%}
{% for kns in kernel_namespaces %}
namespace {{ kns.name }} {
{% for ast in kns.asts %}
......@@ -32,4 +34,6 @@ void {{ function.name }} ( {{ function | generate_function_parameter_list }} ) {
}
{% endfor %}
} // namespace {{root_namespace}}
{% if fq_namespace is not none %}
} // namespace {{fq_namespace}}
{% endif %}
......@@ -2,16 +2,20 @@
#include <cstdint>
{% for incl in public_includes -%}
{% for incl in public_includes %}
{{incl}}
{% endfor %}
#define RESTRICT __restrict__
namespace {{root_namespace}} {
{% if fq_namespace is not none %}
namespace {{fq_namespace}} {
{% endif %}
{% for function in functions %}
void {{ function.name }} ( {{ function | generate_function_parameter_list }} );
{% endfor %}
} // namespace {{root_namespace}}
{% if fq_namespace is not none %}
} // namespace {{fq_namespace}}
{% endif %}
\ No newline at end of file
......@@ -59,7 +59,9 @@ class SfgKernelHandle:
@property
def fully_qualified_name(self):
return f"{self._ctx.root_namespace}::{self.kernel_namespace.name}::{self.kernel_name}"
match self._ctx.fully_qualified_namespace:
case None: return f"{self.kernel_namespace.name}::{self.kernel_name}"
case fqn: return f"{fqn}::{self.kernel_namespace.name}::{self.kernel_name}"
@property
def parameters(self):
......
......@@ -6,7 +6,6 @@ from itertools import chain
from ..kernel_namespace import SfgKernelHandle
from ..source_concepts.source_objects import SrcObject, TypedSymbolOrObject
from ..exceptions import SfgException
if TYPE_CHECKING:
from ..context import SfgContext
......@@ -43,7 +42,6 @@ class SfgCallTreeNode(ABC):
By convention, the code block emitted by this function should not contain a trailing newline.
"""
pass
@property
def required_includes(self) -> Set[SfgHeaderInclude]:
......
from __future__ import annotations
from typing import TYPE_CHECKING, Sequence, Optional, Set
from typing import TYPE_CHECKING, Optional, Set
from .basic_nodes import SfgCallTreeNode, SfgCallTreeLeaf
from ..source_concepts.source_objects import TypedSymbolOrObject
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment