Our previous approach to solve nested structs were to use NestedMatch. It works well, but adding support to parse delimiters is very complex. Instead, use CMatch, which uses a C tokenizer, making the code more reliable and simpler.
Showing the changes to tools/lib/python (2 of 2 files). Show all
Unified · Split
| @@ -14,7 +14,7 @@ import re · 13 unmodified lines | ||
| 14 | 14 | from pprint import pformat |
| 15 | 15 | |
| 16 | 16 | from kdoc.c_lex import CTokenizer |
| 17 | −from kdoc.kdoc_re import NestedMatch, KernRe | |
| 17 | +from kdoc.kdoc_re import KernRe | |
| 18 | 18 | from kdoc.kdoc_item import KdocItem |
| 19 | 19 | |
| 20 | 20 | # |
| @@ -4,7 +4,8 @@ · 3 unmodified lines | ||
| 4 | 4 | |
| 5 | 5 | import re |
| 6 | 6 | |
| 7 | −from kdoc.kdoc_re import KernRe, NestedMatch | |
| 7 | +from kdoc.kdoc_re import KernRe | |
| 8 | +from kdoc.c_lex import CMatch | |
| 8 | 9 | |
| 9 | 10 | struct_args_pattern = r'([^,)]+)' |
| 10 | 11 | |
| @@ -60,7 +61,7 @@ class CTransforms: · 49 unmodified lines | ||
| 60 | 61 | # |
| 61 | 62 | # As it doesn't properly match the end parenthesis on some cases. |
| 62 | 63 | # |
| 63 | − # So, a better solution was crafted: there's now a NestedMatch | |
| 64 | + # So, a better solution was crafted: there's now a CMatch | |
| 64 | 65 | # class that ensures that delimiters after a search are properly |
| 65 | 66 | # matched. So, the implementation to drop STRUCT_GROUP() will be |
| 66 | 67 | # handled in separate. |
| @@ -72,9 +73,9 @@ class CTransforms: · 5 unmodified lines | ||
| 72 | 73 | # |
| 73 | 74 | # Replace macros |
| 74 | 75 | # |
| 75 | − # TODO: use NestedMatch for FOO($1, $2, ...) matches | |
| 76 | + # TODO: use CMatch for FOO($1, $2, ...) matches | |
| 76 | 77 | # |
| 77 | − # it is better to also move those to the NestedMatch logic, | |
| 78 | + # it is better to also move those to the CMatch logic, | |
| 78 | 79 | # to ensure that parentheses will be properly matched. |
| 79 | 80 | # |
| 80 | 81 | (KernRe(r'__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)', re.S), |
| @@ -95,17 +96,17 @@ class CTransforms: · 14 unmodified lines | ||
| 95 | 96 | (KernRe(r'DEFINE_DMA_UNMAP_LEN\s*\(' + struct_args_pattern + r'\)', re.S), r'__u32 \1'), |
| 96 | 97 | (KernRe(r'VIRTIO_DECLARE_FEATURES\(([\w_]+)\)'), r'union { u64 \1; u64 \1_array[VIRTIO_FEATURES_U64S]; }'), |
| 97 | 98 | |
| 98 | − (NestedMatch(r"__cond_acquires\s*\("), ""), | |
| 99 | − (NestedMatch(r"__cond_releases\s*\("), ""), | |
| 100 | − (NestedMatch(r"__acquires\s*\("), ""), | |
| 101 | − (NestedMatch(r"__releases\s*\("), ""), | |
| 102 | − (NestedMatch(r"__must_hold\s*\("), ""), | |
| 103 | − (NestedMatch(r"__must_not_hold\s*\("), ""), | |
| 104 | − (NestedMatch(r"__must_hold_shared\s*\("), ""), | |
| 105 | − (NestedMatch(r"__cond_acquires_shared\s*\("), ""), | |
| 106 | − (NestedMatch(r"__acquires_shared\s*\("), ""), | |
| 107 | − (NestedMatch(r"__releases_shared\s*\("), ""), | |
| 108 | − (NestedMatch(r'\bSTRUCT_GROUP\('), r'\0'), | |
| 99 | + (CMatch(r"__cond_acquires"), ""), | |
| 100 | + (CMatch(r"__cond_releases"), ""), | |
| 101 | + (CMatch(r"__acquires"), ""), | |
| 102 | + (CMatch(r"__releases"), ""), | |
| 103 | + (CMatch(r"__must_hold"), ""), | |
| 104 | + (CMatch(r"__must_not_hold"), ""), | |
| 105 | + (CMatch(r"__must_hold_shared"), ""), | |
| 106 | + (CMatch(r"__cond_acquires_shared"), ""), | |
| 107 | + (CMatch(r"__acquires_shared"), ""), | |
| 108 | + (CMatch(r"__releases_shared"), ""), | |
| 109 | + (CMatch(r"STRUCT_GROUP"), r'\0'), | |
| 109 | 110 | ] |
| 110 | 111 | |
| 111 | 112 | #: Transforms for function prototypes. |