|
78 | 78 | # |
79 | 79 | struct_args_pattern = r'([^,)]+)' |
80 | 80 |
|
81 | | -struct_prefixes = [ |
| 81 | +struct_xforms = [ |
82 | 82 | # Strip attributes |
83 | 83 | (KernRe(r"__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)", flags=re.I | re.S, cache=False), ' '), |
84 | 84 | (KernRe(r'\s*__aligned\s*\([^;]*\)', re.S), ' '), |
|
165 | 165 | # Transforms for function prototypes |
166 | 166 | # |
167 | 167 | function_xforms = [ |
168 | | - (r"^static +", "", 0), |
169 | | - (r"^extern +", "", 0), |
170 | | - (r"^asmlinkage +", "", 0), |
171 | | - (r"^inline +", "", 0), |
172 | | - (r"^__inline__ +", "", 0), |
173 | | - (r"^__inline +", "", 0), |
174 | | - (r"^__always_inline +", "", 0), |
175 | | - (r"^noinline +", "", 0), |
176 | | - (r"^__FORTIFY_INLINE +", "", 0), |
177 | | - (r"__init +", "", 0), |
178 | | - (r"__init_or_module +", "", 0), |
179 | | - (r"__deprecated +", "", 0), |
180 | | - (r"__flatten +", "", 0), |
181 | | - (r"__meminit +", "", 0), |
182 | | - (r"__must_check +", "", 0), |
183 | | - (r"__weak +", "", 0), |
184 | | - (r"__sched +", "", 0), |
185 | | - (r"_noprof", "", 0), |
186 | | - (r"__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +", "", 0), |
187 | | - (r"__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +", "", 0), |
188 | | - (r"__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +", "", 0), |
189 | | - (r"DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)", r"\1, \2", 0), |
190 | | - (r"__attribute_const__ +", "", 0), |
191 | | - (r"__attribute__\s*\(\((?:[\w\s]+(?:\([^)]*\))?\s*,?)+\)\)\s+", "", 0), |
| 168 | + (KernRe(r"^static +"), ""), |
| 169 | + (KernRe(r"^extern +"), ""), |
| 170 | + (KernRe(r"^asmlinkage +"), ""), |
| 171 | + (KernRe(r"^inline +"), ""), |
| 172 | + (KernRe(r"^__inline__ +"), ""), |
| 173 | + (KernRe(r"^__inline +"), ""), |
| 174 | + (KernRe(r"^__always_inline +"), ""), |
| 175 | + (KernRe(r"^noinline +"), ""), |
| 176 | + (KernRe(r"^__FORTIFY_INLINE +"), ""), |
| 177 | + (KernRe(r"__init +"), ""), |
| 178 | + (KernRe(r"__init_or_module +"), ""), |
| 179 | + (KernRe(r"__deprecated +"), ""), |
| 180 | + (KernRe(r"__flatten +"), ""), |
| 181 | + (KernRe(r"__meminit +"), ""), |
| 182 | + (KernRe(r"__must_check +"), ""), |
| 183 | + (KernRe(r"__weak +"), ""), |
| 184 | + (KernRe(r"__sched +"), ""), |
| 185 | + (KernRe(r"_noprof"), ""), |
| 186 | + (KernRe(r"__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +"), ""), |
| 187 | + (KernRe(r"__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +"), ""), |
| 188 | + (KernRe(r"__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +"), ""), |
| 189 | + (KernRe(r"DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)"), r"\1, \2"), |
| 190 | + (KernRe(r"__attribute_const__ +"), ""), |
| 191 | + (KernRe(r"__attribute__\s*\(\((?:[\w\s]+(?:\([^)]*\))?\s*,?)+\)\)\s+"), ""), |
192 | 192 | ] |
193 | 193 |
|
194 | | - |
| 194 | +# |
| 195 | +# Apply a set of transforms to a block of text. |
| 196 | +# |
| 197 | +def apply_transforms(xforms, text): |
| 198 | + for search, subst in xforms: |
| 199 | + text = search.sub(subst, text) |
| 200 | + return text |
195 | 201 |
|
196 | 202 | # |
197 | 203 | # A little helper to get rid of excess white space |
@@ -807,8 +813,7 @@ def dump_struct(self, ln, proto): |
807 | 813 | # Go through the list of members applying all of our transformations. |
808 | 814 | # |
809 | 815 | members = trim_private_members(members) |
810 | | - for search, sub in struct_prefixes: |
811 | | - members = search.sub(sub, members) |
| 816 | + members = apply_transforms(struct_xforms, members) |
812 | 817 |
|
813 | 818 | nested = NestedMatch() |
814 | 819 | for search, sub in struct_nested_prefixes: |
@@ -924,12 +929,10 @@ def dump_function(self, ln, prototype): |
924 | 929 | func_macro = False |
925 | 930 | return_type = '' |
926 | 931 | decl_type = 'function' |
927 | | - |
928 | 932 | # |
929 | 933 | # Apply the initial transformations. |
930 | 934 | # |
931 | | - for search, sub, flags in function_xforms: |
932 | | - prototype = KernRe(search, flags).sub(sub, prototype) |
| 935 | + prototype = apply_transforms(function_xforms, prototype) |
933 | 936 |
|
934 | 937 | # Macros are a special case, as they change the prototype format |
935 | 938 | new_proto = KernRe(r"^#\s*define\s+").sub("", prototype) |
|
0 commit comments