@@ -76,14 +76,14 @@ def __extract_function_definitions(c_kinds:, kind:, is_parse_multiline_definitio
76
76
parts = line . split ( "\t " )
77
77
78
78
function_name = parts [ 0 ]
79
+ filepath = parts [ 1 ]
79
80
80
81
next unless data . should_generate_function? ( function_name )
81
82
82
83
next unless parts [ 3 ] == kind
83
84
84
85
line_num = Util . find_field ( parts , "line" ) . to_i
85
- definition =
86
- parse_function_definition ( filepath : parts [ 1 ] , pattern : parts [ 2 ] , line_num :, is_parse_multiline_definition :)
86
+ definition = parse_function_definition ( filepath :, pattern : parts [ 2 ] , line_num :, is_parse_multiline_definition :)
87
87
88
88
args = parse_definition_args ( function_name , Util . find_field ( parts , "signature" ) )
89
89
@@ -94,9 +94,9 @@ def __extract_function_definitions(c_kinds:, kind:, is_parse_multiline_definitio
94
94
95
95
definitions << FunctionDefinition . new (
96
96
definition :,
97
- name : parts [ 0 ] ,
98
- filepath : parts [ 1 ] ,
99
- typeref : create_typeref ( definition :, function_name :, typeref_field :) ,
97
+ name : function_name ,
98
+ filepath :,
99
+ typeref : create_typeref ( definition :, function_name :, typeref_field :, filepath : , line_num : ) ,
100
100
args :,
101
101
)
102
102
end
@@ -212,17 +212,11 @@ def parse_definition_args(function_name, signature)
212
212
# @param definition [String]
213
213
# @param function_name [String]
214
214
# @param typeref_field [String,nil]
215
+ # @param filepath [String]
216
+ # @param line_num [Integer]
215
217
# @return [RubyHeaderParser::TyperefDefinition]
216
- def create_typeref ( definition :, function_name :, typeref_field :)
217
- typeref_type =
218
- if typeref_field
219
- type = typeref_field . gsub ( /[A-Z_]+\s *\( \( .*\) \) / , "" ) . gsub ( "RUBY_SYMBOL_EXPORT_BEGIN" , "" )
220
- Util . sanitize_type ( type ) # rubocop:disable Style/IdenticalConditionalBranches
221
- else
222
- # parse typeref in definition
223
- type = definition [ 0 ...definition . index ( function_name ) ] . gsub ( "char *" , "char*" ) . strip
224
- Util . sanitize_type ( type ) # rubocop:disable Style/IdenticalConditionalBranches
225
- end
218
+ def create_typeref ( definition :, function_name :, typeref_field :, filepath :, line_num :)
219
+ typeref_type = parse_typeref_type ( definition :, function_name :, typeref_field :, filepath :, line_num :)
226
220
227
221
typeref_pointer = nil
228
222
if typeref_type . match? ( /\* +$/ )
@@ -232,5 +226,39 @@ def create_typeref(definition:, function_name:, typeref_field:)
232
226
233
227
TyperefDefinition . new ( type : typeref_type , pointer : typeref_pointer )
234
228
end
229
+
230
+ # @param definition [String]
231
+ # @param function_name [String]
232
+ # @param typeref_field [String,nil]
233
+ # @param filepath [String]
234
+ # @param line_num [Integer]
235
+ # @return [String]
236
+ def parse_typeref_type ( definition :, function_name :, typeref_field :, filepath :, line_num :)
237
+ typeref_type =
238
+ if typeref_field
239
+ typeref_field . gsub ( /[A-Z_]+\s *\( \( .*\) \) / , "" ) . gsub ( "RUBY_SYMBOL_EXPORT_BEGIN" , "" )
240
+ else
241
+ # parse typeref in definition
242
+ definition [ 0 ...definition . index ( function_name ) ] . gsub ( "char *" , "char*" ) . strip
243
+ end
244
+
245
+ typeref_type = Util . sanitize_type ( typeref_type )
246
+ return typeref_type unless typeref_type . empty?
247
+
248
+ # Check prev line
249
+ line = read_file_line ( filepath :, line_num : line_num - 1 )
250
+ return Util . sanitize_type ( line ) if line
251
+
252
+ ""
253
+ end
254
+
255
+ # @param filepath [String]
256
+ # @param line_num [Integer]
257
+ def read_file_line ( filepath :, line_num :)
258
+ return nil if line_num < 1
259
+
260
+ lines = File . open ( filepath , "rb" ) { |f | f . readlines ( chomp : true ) }
261
+ lines [ line_num - 1 ]
262
+ end
235
263
end
236
264
end
0 commit comments