Skip to content

Commit 9bc4efb

Browse files
committed
Update generator to use cfile v0.3.2
1 parent 12dbab2 commit 9bc4efb

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

.github/workflows/python-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: actions/checkout@v4
2626
with:
2727
repository: cogu/cfile
28-
ref: v0.3.1
28+
ref: v0.3.2
2929
path: cfile_0.3
3030
- name: Set up Python ${{ matrix.python-version }}
3131
uses: actions/setup-python@v4

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ For currently supported XML elements, see the [CHANGELOG](CHANGELOG.md) file.
5353

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

5858
## Installation
5959

@@ -73,7 +73,7 @@ python -m pip install --upgrade pip
7373
python -m pip install --upgrade setuptools
7474
git clone https://github.com/cogu/cfile.git cfile_0.3
7575
cd cfile_0.3
76-
git checkout v0.3.1
76+
git checkout v0.3.2
7777
cd ..
7878
python -m pip install cfile_0.3
7979
```

examples/generator/data_types/gen_type_defs_array.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Example generation of RTE type header - Array type
3-
Requires cfile v0.3.1
3+
Requires cfile v0.3.2
44
"""
55
import autosar
66
import autosar.xml.element as ar_element

examples/generator/data_types/gen_type_defs_record.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Example generation of RTE type header - Record type
3-
Requires cfile v0.3.1
3+
Requires cfile v0.3.2
44
"""
55
import autosar
66
import autosar.xml.element as ar_element

examples/generator/data_types/gen_type_defs_scalar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Example generation of RTE type header - Scalar type
3-
Requires cfile v0.3.1
3+
Requires cfile v0.3.2
44
"""
55
import autosar
66
import autosar.xml.element as ar_element

src/autosar/generator/type_generator.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
RTE type generator
3-
Requires cfile v0.3.1
3+
Requires cfile v0.3.2
44
"""
55
import os
66
from typing import Iterator
@@ -104,11 +104,11 @@ def _gen_type_defs(self, data_types: Iterator[rte_element.Element]) -> cfile.cor
104104
code = C.sequence()
105105
for data_type in data_types:
106106
if isinstance(data_type, rte_element.BaseType):
107-
code.append(C.statement(C.typedef(data_type.name, data_type.native_declaration)))
107+
code.append(C.statement(C.declaration(C.typedef(data_type.name, data_type.native_declaration))))
108108
elif isinstance(data_type, rte_element.ScalarType):
109-
code.append(C.statement(C.typedef(data_type.name, data_type.base_type.name)))
109+
code.append(C.statement(C.declaration(C.typedef(data_type.name, data_type.base_type.name))))
110110
elif isinstance(data_type, rte_element.RefType):
111-
code.append(C.statement(C.typedef(data_type.name, data_type.impl_type.name)))
111+
code.append(C.statement(C.declaration(C.typedef(data_type.name, data_type.impl_type.name))))
112112
elif isinstance(data_type, rte_element.ArrayType):
113113
code.append(self._gen_array_type_def(data_type))
114114
elif isinstance(data_type, rte_element.RecordType):
@@ -129,7 +129,7 @@ def _gen_array_type_def(self, data_type: rte_element.ArrayType) -> cfile.core.St
129129
target_type = C.type(last_element.data_type.impl_type.name)
130130
else:
131131
raise NotImplementedError(str(type(last_element.data_type)))
132-
return C.statement(C.typedef(data_type.name, target_type, array=last_element.array_size))
132+
return C.statement(C.declaration(C.typedef(data_type.name, target_type, array=last_element.array_size)))
133133

134134
def _gen_record_type_def(self, data_type: rte_element.RecordType) -> cfile.core.Statement:
135135
members = []
@@ -147,6 +147,7 @@ def _gen_record_type_def(self, data_type: rte_element.RecordType) -> cfile.core.
147147
members.append(C.struct_member(element.name, target_type))
148148
struct_name = "Rte_struct_" + data_type.name
149149
code = C.sequence()
150-
code.append(C.statement(C.struct(struct_name, members)))
151-
code.append(C.statement(C.typedef(data_type.name, C.struct_ref(struct_name))))
150+
struct = C.struct(struct_name, members)
151+
code.append(C.statement(C.declaration(struct)))
152+
code.append(C.statement(C.declaration(C.typedef(data_type.name, struct))))
152153
return code

0 commit comments

Comments
 (0)