|
1 | 1 | #!/usr/bin/env python |
2 | | -# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD |
| 2 | +# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | | - |
5 | 4 | # A check script that just works at the time of writing... |
6 | 5 | # |
7 | 6 | # also builds a structure tree for further reference |
8 | 7 | # |
9 | | -# Input file format must be similiar to those headers generated by regtool, or this script makes no sense at all |
| 8 | +# Input file format must be similar to those headers generated by regtool, or this script makes no sense at all |
10 | 9 | # |
11 | 10 | # Known limitation: |
12 | 11 | # 1. won't accept /* ... */ /* ... */': badly behavior with multiline comment |
|
21 | 20 | # 5. typedef volatile struct xxx{}: xxx must exists |
22 | 21 | # |
23 | 22 | # Otherwise won't fail but warning |
24 | | - |
25 | 23 | import os |
26 | 24 | import re |
27 | 25 | import sys |
28 | 26 | from typing import Any |
| 27 | +from typing import Optional |
29 | 28 |
|
30 | 29 |
|
31 | 30 | class MemberField: |
32 | 31 | member_type = '' |
33 | 32 | bitfield = None |
34 | 33 |
|
35 | | - def __init__(self, m_type: str, m_bits: int=None) -> None: |
| 34 | + def __init__(self, m_type: str, m_bits: Optional[int]=None) -> None: |
36 | 35 | self.member_type = m_type |
37 | 36 | self.bitfield = m_bits |
38 | 37 |
|
@@ -74,7 +73,7 @@ class SoCStructureHeaderChecker: |
74 | 73 | # named typedef, or named struct/union. referd but will not delete |
75 | 74 | __temp_ref_types = dict() # type: dict |
76 | 75 |
|
77 | | - def __expand_type(self, member_type: str, bitfield: int=None) -> Any: |
| 76 | + def __expand_type(self, member_type: str, bitfield: Optional[int]=None) -> Any: |
78 | 77 | if member_type == 'uint32_t': |
79 | 78 | return MemberField(member_type, bitfield) |
80 | 79 | if bitfield is not None: |
@@ -121,15 +120,15 @@ def __getline(self, incomment:bool=False) -> Any: |
121 | 120 | # skip empty line |
122 | 121 | return self.__getline() |
123 | 122 | if rawline.count(';') > 1: |
124 | | - print('\033[0;34mINFO\033[0m: line: {}: possibily multiple expression within same line'.format(self.__linecount)) |
| 123 | + print('\033[0;34mINFO\033[0m: line: {}: possibly multiple expression within same line'.format(self.__linecount)) |
125 | 124 | print(rawline) |
126 | 125 | return rawline |
127 | 126 |
|
128 | 127 | def __process_structure(self, name: str, is_typedef: bool, is_volatile: bool) -> Any: |
129 | 128 | ret_val = 0 |
130 | 129 | # first check for anonymous register structs |
131 | 130 | if is_typedef and is_volatile and name is None: |
132 | | - print('\033[0;31mERROR\033[0m: line {}: annoymous struct'.format(self.__linecount)) |
| 131 | + print('\033[0;31mERROR\033[0m: line {}: anonymous struct'.format(self.__linecount)) |
133 | 132 | ret_val = -1 |
134 | 133 | node_tree = dict() |
135 | 134 | bitcount = 0 |
@@ -252,7 +251,7 @@ def __process_union(self, name: str, is_typedef: bool, is_volatile: bool) -> Any |
252 | 251 | ret_val = 0 |
253 | 252 | # first check for anonymous register structs |
254 | 253 | if is_typedef and is_volatile and name is None: |
255 | | - print('\033[0;31mERROR\033[0m: line {}: annoymous union'.format(self.__linecount)) |
| 254 | + print('\033[0;31mERROR\033[0m: line {}: anonymous union'.format(self.__linecount)) |
256 | 255 | ret_val = -1 |
257 | 256 | node_tree = dict() # type: Any |
258 | 257 | has_struct_count = 0 |
@@ -334,7 +333,7 @@ def __process_union(self, name: str, is_typedef: bool, is_volatile: bool) -> Any |
334 | 333 | node_tree[match_obj.groups()[1]] = member_node |
335 | 334 | else: |
336 | 335 | if '*' not in match_obj.groups()[0]: |
337 | | - print('\033[0;31mERROR\033[0m: line {}: unknown type {}'.format(self.__linecount, match_obj.groups()[0])) |
| 336 | + print('\033[0;31mWARN\033[0m: line {}: unknown type {}'.format(self.__linecount, match_obj.groups()[0])) |
338 | 337 | else: |
339 | 338 | print('\033[0;33mWARN\033[0m: line {}: pointer type {}'.format(self.__linecount, match_obj.groups()[0])) |
340 | 339 | continue |
|
0 commit comments