Skip to content

Commit

Permalink
Update generator to use cfile v0.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cogu committed Feb 5, 2024
1 parent 12dbab2 commit 5978bc4
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: cogu/cfile
ref: v0.3.1
ref: v0.3.2
path: cfile_0.3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ For currently supported XML elements, see the [CHANGELOG](CHANGELOG.md) file.

* Python 3.10+
* lxml
* [cfile](https://github.com/cogu/cfile) v0.3.1+
* [cfile](https://github.com/cogu/cfile) v0.3.2+

## Installation

Expand All @@ -73,7 +73,7 @@ python -m pip install --upgrade pip
python -m pip install --upgrade setuptools
git clone https://github.com/cogu/cfile.git cfile_0.3
cd cfile_0.3
git checkout v0.3.1
git checkout v0.3.2
cd ..
python -m pip install cfile_0.3
```
Expand Down
2 changes: 1 addition & 1 deletion examples/generator/data_types/gen_type_defs_array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Example generation of RTE type header - Array type
Requires cfile v0.3.1
Requires cfile v0.3.2
"""
import autosar
import autosar.xml.element as ar_element
Expand Down
2 changes: 1 addition & 1 deletion examples/generator/data_types/gen_type_defs_record.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Example generation of RTE type header - Record type
Requires cfile v0.3.1
Requires cfile v0.3.2
"""
import autosar
import autosar.xml.element as ar_element
Expand Down
2 changes: 1 addition & 1 deletion examples/generator/data_types/gen_type_defs_scalar.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
Example generation of RTE type header - Scalar type
Requires cfile v0.3.1
Requires cfile v0.3.2
"""
import autosar
import autosar.xml.element as ar_element
Expand Down
15 changes: 8 additions & 7 deletions src/autosar/generator/type_generator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
RTE type generator
Requires cfile v0.3.1
Requires cfile v0.3.2
"""
import os
from typing import Iterator
Expand Down Expand Up @@ -104,11 +104,11 @@ def _gen_type_defs(self, data_types: Iterator[rte_element.Element]) -> cfile.cor
code = C.sequence()
for data_type in data_types:
if isinstance(data_type, rte_element.BaseType):
code.append(C.statement(C.typedef(data_type.name, data_type.native_declaration)))
code.append(C.statement(C.declaration(C.typedef(data_type.name, data_type.native_declaration))))
elif isinstance(data_type, rte_element.ScalarType):
code.append(C.statement(C.typedef(data_type.name, data_type.base_type.name)))
code.append(C.statement(C.declaration(C.typedef(data_type.name, data_type.base_type.name))))
elif isinstance(data_type, rte_element.RefType):
code.append(C.statement(C.typedef(data_type.name, data_type.impl_type.name)))
code.append(C.statement(C.declaration(C.typedef(data_type.name, data_type.impl_type.name))))
elif isinstance(data_type, rte_element.ArrayType):
code.append(self._gen_array_type_def(data_type))
elif isinstance(data_type, rte_element.RecordType):
Expand All @@ -129,7 +129,7 @@ def _gen_array_type_def(self, data_type: rte_element.ArrayType) -> cfile.core.St
target_type = C.type(last_element.data_type.impl_type.name)
else:
raise NotImplementedError(str(type(last_element.data_type)))
return C.statement(C.typedef(data_type.name, target_type, array=last_element.array_size))
return C.statement(C.declaration(C.typedef(data_type.name, target_type, array=last_element.array_size)))

def _gen_record_type_def(self, data_type: rte_element.RecordType) -> cfile.core.Statement:
members = []
Expand All @@ -147,6 +147,7 @@ def _gen_record_type_def(self, data_type: rte_element.RecordType) -> cfile.core.
members.append(C.struct_member(element.name, target_type))
struct_name = "Rte_struct_" + data_type.name
code = C.sequence()
code.append(C.statement(C.struct(struct_name, members)))
code.append(C.statement(C.typedef(data_type.name, C.struct_ref(struct_name))))
struct = C.struct(struct_name, members)
code.append(C.statement(C.declaration(struct)))
code.append(C.statement(C.declaration(C.typedef(data_type.name, struct))))
return code

0 comments on commit 5978bc4

Please sign in to comment.