import barectf.template as barectf_template
import barectf.config as barectf_config
import barectf.cgen as barectf_cgen
+from typing import List, Optional
# A file generated by a `CodeGenerator` object.
# A generated file has a name (influenced by the configuration's
# file name prefix option) and contents.
class _GeneratedFile:
- def __init__(self, name, contents):
+ def __init__(self, name: str, contents: str):
self._name = name
self._contents = contents
@property
- def name(self):
+ def name(self) -> str:
return self._name
@property
- def contents(self):
+ def contents(self) -> str:
return self._contents
# A code generator can generate the TSDL `metadata` file and C source
# and header files.
class CodeGenerator:
- def __init__(self, configuration):
+ def __init__(self, configuration: barectf_config.Configuration):
self._config = configuration
self._file_name_prefix = configuration.options.code_generation_options.file_name_prefix
self._c_code_gen = barectf_cgen._CodeGen(configuration)
- self._c_headers = None
- self._c_sources = None
- self._metadata_stream = None
+ self._c_headers: Optional[List[_GeneratedFile]] = None
+ self._c_sources: Optional[List[_GeneratedFile]] = None
+ self._metadata_stream: Optional[_GeneratedFile] = None
@property
- def _barectf_header_name(self):
+ def _barectf_header_name(self) -> str:
return f'{self._file_name_prefix}.h'
@property
- def _bitfield_header_name(self):
+ def _bitfield_header_name(self) -> str:
return f'{self._file_name_prefix}-bitfield.h'
- def generate_c_headers(self):
+ def generate_c_headers(self) -> List[_GeneratedFile]:
if self._c_headers is None:
self._c_headers = [
_GeneratedFile(self._barectf_header_name, self._c_code_gen.gen_header()),
return self._c_headers
- def generate_c_sources(self):
+ def generate_c_sources(self) -> List[_GeneratedFile]:
if self._c_sources is None:
self._c_sources = [
_GeneratedFile(f'{self._file_name_prefix}.c',
return self._c_sources
- def generate_metadata_stream(self):
+ def generate_metadata_stream(self) -> _GeneratedFile:
if self._metadata_stream is None:
self._metadata_stream = _GeneratedFile('metadata',
barectf_tsdl182gen._from_config(self._config))