Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions aas_core_codegen/cpp/aas_common/__init__.py

This file was deleted.

72 changes: 68 additions & 4 deletions aas_core_codegen/cpp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def wstring_literal(text: str) -> Stripped:
else:
escaped.append(character)

# NOTE (mristin, 2023-06-28):
# NOTE (mristin):
# We use std::wstring, therefore ``L`` prefix.
return Stripped('L"{}"'.format("".join(escaped)))

Expand Down Expand Up @@ -144,7 +144,7 @@ def wchar_literal(character: str) -> Stripped:


# fmt: off
# NOTE (mristin, 2023-09-24):
# NOTE (mristin):
# We use a pre-condition here to simplify the client code. The client must check
# before if the input text is all in ASCII, and report to the user if there are
# any non-ASCII characters in the input.
Expand Down Expand Up @@ -428,7 +428,7 @@ def generate_type(
elif isinstance(
our_type, (intermediate.AbstractClass, intermediate.ConcreteClass)
):
# NOTE (mristin, 2023-06-28):
# NOTE (mristin):
# We always refer to interfaces even in cases of concrete classes without
# concrete descendants since we want to allow enhancing.
interface_name = cpp_naming.interface_name(our_type.name)
Expand Down Expand Up @@ -578,7 +578,7 @@ def break_type_in_lines(text: str) -> str:
last_match = match

if last_match is None:
# NOTE (mristin, 2024-01-18):
# NOTE (mristin):
# Not a signle angle bracket has been detected.
return text

Expand Down Expand Up @@ -679,3 +679,67 @@ def non_documentation_comment(text: str) -> str:
lines.append("//")

return "\n".join(lines)


def assert_module_docstring_and_generate_header_consistent(
module_doc: str, generate_header_doc: str
) -> None:
"""Check that the two docstrings are consistent and raise an exception otherwise."""
generate_code_text = "Generate code "
if not module_doc.startswith(generate_code_text):
raise ValueError(
f"Expected the module docstring to start "
f"with {generate_code_text!r}, but got: {module_doc}"
)

generate_header_text = "Generate header "
if not generate_header_doc.startswith(generate_header_text):
raise ValueError(
f"Expected the header generator docstring to start "
f"with {generate_header_text!r}, "
f"but got: {generate_header_doc}"
)

suffix_module_doc = module_doc[len(generate_code_text) :]
suffix_generate_header_doc = generate_header_doc[len(generate_header_text) :]

if not suffix_generate_header_doc.startswith(suffix_module_doc):
raise ValueError(
f"Expected the header generator docstring "
f"to include the part of the module docstring, "
f"but got: {generate_header_doc!r} and "
f"the module docstring was {module_doc!r}"
)


def assert_module_docstring_and_generate_implementation_consistent(
module_doc: str, generate_implementation_doc: str
) -> None:
"""Check that the two docstrings are consistent and raise an exception otherwise."""
generate_code_text = "Generate code "
if not module_doc.startswith(generate_code_text):
raise ValueError(
f"Expected the module docstring to start "
f"with {generate_code_text!r}, but got: {module_doc}"
)

generate_implementation_text = "Generate implementation "
if not generate_implementation_doc.startswith(generate_implementation_text):
raise ValueError(
f"Expected the implementation generator docstring to start "
f"with {generate_implementation_text!r}, "
f"but got: {generate_implementation_doc}"
)

suffix_module_doc = module_doc[len(generate_code_text) :]
suffix_generate_implementation_doc = generate_implementation_doc[
len(generate_implementation_text) :
]

if not suffix_generate_implementation_doc.startswith(suffix_module_doc):
raise ValueError(
f"Expected the implementation generator docstring "
f"to include the part of the module docstring, "
f"but got: {generate_implementation_doc!r} and "
f"the module docstring was {module_doc!r}"
)
6 changes: 0 additions & 6 deletions aas_core_codegen/cpp/constants/__init__.py

This file was deleted.

10 changes: 5 additions & 5 deletions aas_core_codegen/cpp/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _children_are_not_paragraph_blocks(
self, children: Sequence[docutils.nodes.Element]
) -> bool:
for child in children:
# NOTE (mristin, 2023-06-28):
# NOTE (mristin):
# We have to handle ``docutils.nodes.paragraph`` differently,
# outside ``transform``, as a single paragraph with non-block children
# is still OK.
Expand Down Expand Up @@ -200,7 +200,7 @@ def transform_reference_to_our_type_in_doc(
element.our_type,
(intermediate.AbstractClass, intermediate.ConcreteClass),
):
# NOTE (mristin, 2023-06-28):
# NOTE (mristin):
# We always refer to interfaces even in cases of concrete classes without
# concrete descendants since we want to allow enhancing.
name = cpp_naming.interface_name(element.our_type.name)
Expand All @@ -214,7 +214,7 @@ def transform_reference_to_our_type_in_doc(
result = f"{cpp_common.TYPES_NAMESPACE}::{name}"

elif isinstance(element.our_type, intermediate.ConstrainedPrimitive):
# NOTE (mristin, 2022-09-08):
# NOTE (mristin):
# We do not generate a class for constrained primitives, but we
# leave it here as a literal.

Expand Down Expand Up @@ -286,7 +286,7 @@ def transform_reference_to_constant_in_doc(
def transform_literal(
self, element: docutils.nodes.literal
) -> Tuple[Optional[str], Optional[List[str]]]:
# NOTE (mristin, 2023-06-28):
# NOTE (mristin):
# We fail here catastrophically if there are backticks as there is no easy way
# to escape them in doxygen. However, since our meta-model is written in
# Python, this assertion will almost always pass as we can not escape backticks
Expand Down Expand Up @@ -387,7 +387,7 @@ def transform_bullet_list(

writer.write("* ")

# NOTE (mristin, 2023-06-28):
# NOTE (mristin):
# This has a potentially exponential complexity w.r.t. indention level.
# However, as the indention level is thus far limited to only a single
# level, we ignore this pitfall for the moment.
Expand Down
4 changes: 0 additions & 4 deletions aas_core_codegen/cpp/enhancing/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions aas_core_codegen/cpp/iteration/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions aas_core_codegen/cpp/jsonization/__init__.py

This file was deleted.

61 changes: 61 additions & 0 deletions aas_core_codegen/cpp/lib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
"""Provide generators for the main library."""

from aas_core_codegen.cpp.lib import (
_generate_common,
_generate_constants,
_generate_enhancing,
_generate_iteration,
_generate_jsonization,
_generate_pattern,
_generate_revm,
_generate_stringification,
_generate_types,
_generate_verification,
_generate_visitation,
_generate_wstringification,
_generate_xmlization,
)

generate_common_header = _generate_common.generate_header
generate_common_implementation = _generate_common.generate_implementation

generate_constants_header = _generate_constants.generate_header
generate_constants_implementation = _generate_constants.generate_implementation

generate_enhancing_header = _generate_enhancing.generate_header

generate_iteration_header = _generate_iteration.generate_header
generate_iteration_implementation = _generate_iteration.generate_implementation

generate_jsonization_header = _generate_jsonization.generate_header
generate_jsonization_implementation = _generate_jsonization.generate_implementation

generate_pattern_header = _generate_pattern.generate_header
generate_pattern_implementation = _generate_pattern.generate_implementation

generate_revm_header = _generate_revm.generate_header
generate_revm_implementation = _generate_revm.generate_implementation

generate_stringification_header = _generate_stringification.generate_header
generate_stringification_implementation = (
_generate_stringification.generate_implementation
)

generate_types_header = _generate_types.generate_header
generate_types_implementation = _generate_types.generate_implementation

generate_verification_header = _generate_verification.generate_header
generate_verification_implementation = _generate_verification.generate_implementation

generate_visitation_header = _generate_visitation.generate_header
generate_visitation_implementation = _generate_visitation.generate_implementation

generate_wstringification_header = _generate_wstringification.generate_header
generate_wstringification_implementation = (
_generate_wstringification.generate_implementation
)

generate_xmlization_header = _generate_xmlization.generate_header
generate_xmlization_implementation = _generate_xmlization.generate_implementation

verify_for_types = _generate_types.verify
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Generate C++ code of common functions by including the code directly."""
"""Generate code of common functions used across other modules."""

# pylint: disable=line-too-long

Expand Down Expand Up @@ -151,7 +151,7 @@ def _generate_concatenate_implementations_for_2_parts_and_above() -> List[Stripp
)
# fmt: on
def generate_header(library_namespace: Stripped) -> str:
"""Generate the C++ header code for common functions."""
"""Generate header of common functions used across other modules."""
namespace = Stripped(f"{library_namespace}")

include_guard_var = cpp_common.include_guard_var(namespace)
Expand Down Expand Up @@ -216,13 +216,16 @@ def generate_header(library_namespace: Stripped) -> str:
#include <utility>
#pragma warning(pop)

// NOTE (mristin):
// See: https://stackoverflow.com/questions/2324658/how-to-determine-the-version-of-the-c-standard-used-by-the-compiler
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
// NOTE (mristin):
// Standard library provides std::optional in C++17 and above.
#pragma warning(push, 0)
#include <optional>
#pragma warning(pop)
#else
// NOTE (mristin):
// We rely on https://github.com/TartanLlama/optional for optional structure.
#pragma warning(push, 0)
#include <tl/optional.hpp>
Expand All @@ -240,6 +243,7 @@ def generate_header(library_namespace: Stripped) -> str:
#include <expected>
#pragma warning(pop)
#else
// NOTE (mristin):
// We rely on https://github.com/TartanLlama/expected for expected structure.
#pragma warning(push, 0)
#include <tl/expected.hpp>
Expand Down Expand Up @@ -482,7 +486,7 @@ def generate_header(library_namespace: Stripped) -> str:
)
# fmt: on
def generate_implementation(library_namespace: Stripped) -> str:
"""Generate the C++ code for common functions."""
"""Generate implementation of common functions used across other modules."""
namespace = Stripped(f"{library_namespace}::{cpp_common.COMMON_NAMESPACE}")

include_prefix_path = cpp_common.generate_include_prefix_path(library_namespace)
Expand Down Expand Up @@ -711,3 +715,14 @@ def generate_implementation(library_namespace: Stripped) -> str:
writer.write("\n")

return writer.getvalue()


assert generate_header.__doc__ is not None
cpp_common.assert_module_docstring_and_generate_header_consistent(
module_doc=__doc__, generate_header_doc=generate_header.__doc__
)

assert generate_implementation.__doc__ is not None
cpp_common.assert_module_docstring_and_generate_implementation_consistent(
module_doc=__doc__, generate_implementation_doc=generate_implementation.__doc__
)
Loading
Loading