@@ -190,67 +190,10 @@ def parse_definition_args(function_name, signature)
190
190
args = Util . split_signature ( signature )
191
191
192
192
arg_pos = 0
193
- args . map do |str |
193
+ args . map do |arg |
194
194
arg_pos += 1
195
- parts = str . split
196
-
197
- if parts . count < 2
198
- ArgumentDefinition . new (
199
- type : parts [ 0 ] ,
200
- name : "arg#{ arg_pos } " ,
201
- pointer : nil ,
202
- )
203
- else
204
- loop do
205
- pointer_index = parts . index ( "*" )
206
- break unless pointer_index
207
-
208
- parts [ pointer_index - 1 ] << "*"
209
- parts . delete_at ( pointer_index )
210
- end
211
-
212
- pointer = nil
213
- length = 0
214
-
215
- if parts [ -1 ] =~ /\[ ([0-9]+)?\] $/
216
- parts [ -1 ] . gsub! ( /\[ ([0-9]+)?\] $/ , "" )
217
- length = ::Regexp . last_match ( 1 ) . to_i
218
- pointer = :array
219
- end
220
-
221
- unless parts [ -1 ] =~ /^[0-9a-zA-Z_]+$/
222
- # last elements isn't dummy argument
223
- parts << "arg#{ arg_pos } "
224
- end
225
-
226
- type = ""
227
- original_type = Util . sanitize_type ( parts [ 0 ...-1 ] . join ( " " ) )
228
- name = parts [ -1 ]
229
-
230
- if original_type . match? ( /\* +$/ )
231
- type = original_type . gsub ( /\* +$/ , "" ) . strip
232
- pointer = data . function_arg_pointer_hint ( function_name :, pos : arg_pos )
233
- elsif /^void\s *\s / . match? ( original_type ) || /\( .*\) / . match? ( original_type )
234
- # function pointer (e.g. void *(*func)(void *)) is treated as `void*`
235
- type = "void"
236
- pointer = data . function_arg_pointer_hint ( function_name :, pos : arg_pos )
237
- else
238
- type = original_type
239
- end
240
-
241
- if pointer == :sref
242
- original_type =~ /(\* +)$/
243
- length = ::Regexp . last_match ( 1 ) . length
244
- end
245
-
246
- ArgumentDefinition . new (
247
- type :,
248
- name :,
249
- pointer :,
250
- length :,
251
- )
252
- end
253
- end . compact
195
+ generate_argument_definition ( function_name :, arg :, arg_pos :)
196
+ end
254
197
end
255
198
256
199
# @param definition [String]
@@ -304,5 +247,70 @@ def read_file_line(filepath:, line_num:)
304
247
lines = File . open ( filepath , "rb" ) { |f | f . readlines ( chomp : true ) }
305
248
lines [ line_num - 1 ]
306
249
end
250
+
251
+ # @param function_name [String]
252
+ # @param arg [String]
253
+ # @param arg_pos [Integer]
254
+ #
255
+ # @return [ArgumentDefinition]
256
+ def generate_argument_definition ( function_name :, arg :, arg_pos :)
257
+ parts = arg . split
258
+
259
+ if parts . count < 2
260
+ return ArgumentDefinition . new (
261
+ type : parts [ 0 ] ,
262
+ name : "arg#{ arg_pos } " ,
263
+ pointer : nil ,
264
+ )
265
+ end
266
+
267
+ loop do
268
+ pointer_index = parts . index ( "*" )
269
+ break unless pointer_index
270
+
271
+ parts [ pointer_index - 1 ] << "*"
272
+ parts . delete_at ( pointer_index )
273
+ end
274
+
275
+ pointer = nil
276
+ length = 0
277
+
278
+ if parts [ -1 ] =~ /\[ ([0-9]+)?\] $/
279
+ parts [ -1 ] . gsub! ( /\[ ([0-9]+)?\] $/ , "" )
280
+ length = ::Regexp . last_match ( 1 ) . to_i
281
+ pointer = :array
282
+ end
283
+
284
+ unless parts [ -1 ] =~ /^[0-9a-zA-Z_]+$/
285
+ # last elements isn't dummy argument
286
+ parts << "arg#{ arg_pos } "
287
+ end
288
+
289
+ original_type = Util . sanitize_type ( parts [ 0 ...-1 ] . join ( " " ) )
290
+ name = parts [ -1 ]
291
+
292
+ if original_type . match? ( /\* +$/ )
293
+ type = original_type . gsub ( /\* +$/ , "" ) . strip
294
+ pointer = data . function_arg_pointer_hint ( function_name :, pos : arg_pos )
295
+ elsif /^void\s *\s / . match? ( original_type ) || /\( .*\) / . match? ( original_type )
296
+ # function pointer (e.g. void *(*func)(void *)) is treated as `void*`
297
+ type = "void"
298
+ pointer = data . function_arg_pointer_hint ( function_name :, pos : arg_pos )
299
+ else
300
+ type = original_type
301
+ end
302
+
303
+ if pointer == :sref
304
+ original_type =~ /(\* +)$/
305
+ length = ::Regexp . last_match ( 1 ) . length
306
+ end
307
+
308
+ ArgumentDefinition . new (
309
+ type :,
310
+ name :,
311
+ pointer :,
312
+ length :,
313
+ )
314
+ end
307
315
end
308
316
end
0 commit comments