Skip to content

Commit

Permalink
Incorporate PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
skeetsaz committed Aug 28, 2023
1 parent 582566b commit 34c0d0b
Show file tree
Hide file tree
Showing 23 changed files with 516 additions and 244 deletions.
16 changes: 16 additions & 0 deletions .vscode/cmake-variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
"NUNAVUT_VERIFICATION_LANG_STANDARD": "c++14"
}
},
"CETL++": {
"short": "--std=cetl++",
"long": "Compile and link using the C++14 standard and use CETL.",
"settings": {
"NUNAVUT_VERIFICATION_LANG": "cpp",
"NUNAVUT_VERIFICATION_LANG_STANDARD": "cetl++"
}
},
"C++17": {
"short": "--std=c++17",
"long": "Compile and link using the C++17 standard.",
Expand All @@ -65,6 +73,14 @@
"NUNAVUT_VERIFICATION_LANG_STANDARD": "c++17"
}
},
"C++17 PMR": {
"short": "--std=c++17-pmr",
"long": "Compile and link using the C++17 standard and use polymorphic memory resources.",
"settings": {
"NUNAVUT_VERIFICATION_LANG": "cpp",
"NUNAVUT_VERIFICATION_LANG_STANDARD": "c++17-pmr"
}
},
"C++20": {
"short": "--std=c++20",
"long": "Compile and link using the C++20 standard.",
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ way to ensure the example is correct especially if used in a trailing ``invisibl
assert 'scotec_mcu_timer' == filter_to_snake_case(input)

These tests are run as part of the regular pytest build. You can see the Sybil setup in the
``conftest.py`` found under the ``src`` directory but otherwise shouldn't need to worry about
``conftest.py`` found under the project directory but otherwise shouldn't need to worry about
it. The simple rule is; if the docstring ends up in the rendered documentation then your
``code-block`` tests will be executed as unit tests.

Expand Down
35 changes: 24 additions & 11 deletions docs/languages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,48 @@ See :ref:`template-language-guide` until this section is more complete.
Using a Different Variable-Length Array Type
==============================================

For now this tip is important for people using the experimental C++ support. To use :code:`std::vector` instead of the
minimal build-in :code:`variable_length_array` type create a properties override yaml file and pass it to nnvg.
For now this tip is important for people using the experimental C++ support. To set which variable length array
implementation to use, create a properties override yaml file and pass it to nnvg. Specifying the use of an
allocator is optional (If ctor_convention is set to "default" then the allocator_include and allocator_type
properties don't need to be set.)

vector.yaml
Alternatively, you may specify the language standard argument as -std=c++17-pmr or -std=cetl++ as short-hand for
the following configurations shown below.

c++17-pmr.yaml
"""""""""""""""""

.. code-block :: yaml
nunavut.lang.cpp:
options:
variable_array_type_include: <vector>
variable_array_type_template: std::vector<{TYPE}>
variable_array_type_include: "<vector>"
variable_array_type_template: "std::vector<{TYPE}, {REBIND_ALLOCATOR}>"
variable_array_type_constructor_args: ""
allocator_include: "<memory>"
allocator_type: "std::pmr::polymorphic_allocator"
ctor_convention: "uses-trailing-allocator"
variable_length_array_with_polymorphic_allocator.yaml
cetl++.yaml
"""""""""""""""""

.. code-block :: yaml
variable_array_type_include: <cetl/variable_length_array.hpp>
variable_array_type_template: "cetl::VariableLengthArray<{TYPE}, typename std::allocator_traits<Allocator>::template rebind_alloc<{TYPE}>>"
variable_array_type_init_args_template: "{SIZE}"
variable_array_type_allocator_type: "cetl::pf17::pmr::polymorphic_allocator"
nunavut.lang.cpp:
options:
variable_array_type_include: '"cetl/variable_length_array.hpp"'
variable_array_type_template: "cetl::VariableLengthArray<{TYPE}, {REBIND_ALLOCATOR}>"
variable_array_type_constructor_args: "{MAX_SIZE}"
allocator_include: '"cetl/pf17/sys/memory_resource.hpp"'
allocator_type: "cetl::pf17::pmr::polymorphic_allocator"
ctor_convention: "uses-trailing-allocator"
nnvg command
""""""""""""""""""

.. code-block :: bash
nnvg --configuration=vector.yaml \
nnvg --configuration=c++17-pmr.yaml \ # or --configuration=cetl++.yaml
-l cpp \
--experimental-languages \
-I path/to/public_regulated_data_types/uavcan \
Expand Down
27 changes: 17 additions & 10 deletions src/nunavut/cli/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ def _create_language_context(self) -> LanguageContext:
language_options["enable_serialization_asserts"] = self._args.enable_serialization_asserts
language_options["enable_override_variable_array_capacity"] = self._args.enable_override_variable_array_capacity
if self._args.language_standard is not None:
valid_language_standards: typing.List[str] = ["c11", "c++14", "cetl++", "c++17", "c++17-pmr", "c++20"]
if self._args.language_standard not in valid_language_standards:
raise RuntimeError(
f"'{self._args.language_standard}' language standard not found. "
f"Must be one of {', '.join(valid_language_standards)}."
)
language_options["std"] = self._args.language_standard

if self._args.configuration is None:
Expand All @@ -155,17 +161,18 @@ def _create_language_context(self) -> LanguageContext:

target_language_name = self._args.target_language

return (
LanguageContextBuilder(include_experimental_languages=self._args.experimental_languages)
.set_target_language(target_language_name)
.set_additional_config_files(additional_config_files)
.set_target_language_extension(self._args.output_extension)
.set_target_language_configuration_override(
Language.WKCV_NAMESPACE_FILE_STEM, self._args.namespace_output_stem
)
.set_target_language_configuration_override(Language.WKCV_LANGUAGE_OPTIONS, language_options)
.create()
builder: LanguageContextBuilder = LanguageContextBuilder(
include_experimental_languages=self._args.experimental_languages
)
builder.set_target_language(target_language_name)
builder.load_default_config(self._args.language_standard)
builder.set_additional_config_files(additional_config_files)
builder.set_target_language_extension(self._args.output_extension)
builder.set_target_language_configuration_override(
Language.WKCV_NAMESPACE_FILE_STEM, self._args.namespace_output_stem
)
builder.set_target_language_configuration_override(Language.WKCV_LANGUAGE_OPTIONS, language_options)
return builder.create()

# +---------------------------------------------------------------------------------------------------------------+
# | PRIVATE :: RUN METHODS
Expand Down
7 changes: 7 additions & 0 deletions src/nunavut/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ def set_target_language(self, target_language: typing.Optional[str]) -> "Languag
self._target_language_name = LanguageClassLoader.to_language_name(target_language)
return self

def load_default_config(self, language_standard: str) -> None:
self._ln_loader.config # Accessing this property causes the defaults to load
defaults_key = f"{language_standard}_options"
if defaults_key in self._ln_loader.config.sections()["nunavut.lang.cpp"]:
defaults_data = self._ln_loader.config.get_config_value_as_dict("nunavut.lang.cpp", defaults_key)
self._ln_loader.config.update_section("nunavut.lang.cpp", {"options": defaults_data})

def set_additional_config_files(
self, additional_config_files: typing.List[pathlib.Path]
) -> "LanguageContextBuilder":
Expand Down
10 changes: 10 additions & 0 deletions src/nunavut/lang/_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def __init__(self, language_module_name: str, config: LanguageConfig, **kwargs:
self._tests = dict() # type: typing.Dict[str, typing.Callable]
self._uses = dict() # type: typing.Dict[str, typing.Callable]

self._validate_language_options(self._language_options)

def _validate_language_options(self, language_options: typing.Mapping[str, typing.Any]) -> None:
pass

def __getattr__(self, name: str) -> typing.Any:
"""
Any attribute access to a Language object will return the regular properties and
Expand Down Expand Up @@ -222,6 +227,9 @@ def named_values(self) -> typing.Mapping[str, str]:
# | METHODS
# +-----------------------------------------------------------------------+

def _add_additional_globals(self, globals_map: typing.Dict[str, typing.Any]) -> None:
pass

def get_support_module(self) -> typing.Tuple[str, typing.Tuple[int, int, int], typing.Optional["types.ModuleType"]]:
"""
Returns the module object for the language support files.
Expand Down Expand Up @@ -469,6 +477,8 @@ def get_globals(self) -> typing.Mapping[str, typing.Any]:
for key, value in self.named_values.items():
globals_map["valuetoken_{}".format(key)] = value

self._add_additional_globals(globals_map)

self._globals = globals_map
return self._globals

Expand Down
Loading

0 comments on commit 34c0d0b

Please sign in to comment.