@@ -285,7 +285,7 @@ def do_methods
285285 \s *(?:RUBY_METHOD_FUNC\( |VALUEFUNC\( )?(\w +)\) ?,
286286 \s *(-?\w +)\s *\)
287287 (?:;\s */[*/]\s +in\s +(\w +?\. [cy]))?
288- %xm ) do |type , var_name , meth_name , meth_body , param_count , source_file |
288+ %xm ) do |type , var_name , meth_name , function , param_count , source_file |
289289
290290 # Ignore top-object and weird struct.c dynamic stuff
291291 next if var_name == "ruby_top_self"
@@ -294,7 +294,7 @@ def do_methods
294294 next if var_name == "argf" # it'd be nice to handle this one
295295
296296 var_name = "rb_cObject" if var_name == "rb_mKernel"
297- handle_method ( type , var_name , meth_name , meth_body , param_count ,
297+ handle_method ( type , var_name , meth_name , function , param_count ,
298298 source_file )
299299 end
300300
@@ -303,18 +303,19 @@ def do_methods
303303 \s *(?:RUBY_METHOD_FUNC\( |VALUEFUNC\( )?(\w +)\) ?,
304304 \s *(-?\w +)\s *\)
305305 (?:;\s */[*/]\s +in\s +(\w +?\. [cy]))?
306- %xm ) do |meth_name , meth_body , param_count , source_file |
307- handle_method ( "method" , "rb_mKernel" , meth_name ,
308- meth_body , param_count , source_file )
306+ %xm ) do |meth_name , function , param_count , source_file |
307+ handle_method ( "method" , "rb_mKernel" , meth_name , function , param_count ,
308+ source_file )
309309 end
310310
311311 @content . scan ( /define_filetest_function\s *\(
312312 \s *"([^"]+)",
313313 \s *(?:RUBY_METHOD_FUNC\( |VALUEFUNC\( )?(\w +)\) ?,
314- \s *(-?\w +)\s *\) /xm ) do |meth_name , meth_body , param_count |
314+ \s *(-?\w +)\s *\) /xm ) do |meth_name , function , param_count |
315315
316- handle_method ( "method" , "rb_mFileTest" , meth_name , meth_body , param_count )
317- handle_method ( "singleton_method" , "rb_cFile" , meth_name , meth_body , param_count )
316+ handle_method ( "method" , "rb_mFileTest" , meth_name , function , param_count )
317+ handle_method ( "singleton_method" , "rb_cFile" , meth_name , function ,
318+ param_count )
318319 end
319320 end
320321
@@ -370,21 +371,20 @@ def find_attr_comment var_name, attr_name, read = nil, write = nil
370371 ##
371372 # Find the C code corresponding to a Ruby method
372373
373- def find_body ( class_name , meth_name , meth_obj , body , quiet = false )
374- case body
374+ def find_body class_name , meth_name , meth_obj , file_content , quiet = false
375+ case file_content
375376 when %r%((?>/\* .*?\* /\s *)?)
376377 ((?:(?:static|SWIGINTERN)\s +)?
377378 (?:intern\s +)?VALUE\s +#{ meth_name }
378379 \s *(\( [^)]*\) )([^;]|$))%xm then
379380 comment = $1
380- body_text = $2
381+ body = $2
381382
382383 remove_private_comments comment if comment
383384
384385 # see if we can find the whole body
385386
386- re = Regexp . escape ( body_text ) + '[^(]*^\{.*?^\}'
387- body_text = $& if /#{ re } /m =~ body
387+ body = $& if /#{ Regexp . escape body } [^(]*?\{ .*?^\} /m =~ file_content
388388
389389 # The comment block may have been overridden with a 'Document-method'
390390 # block. This happens in the interpreter when multiple methods are
@@ -400,38 +400,44 @@ def find_body(class_name, meth_name, meth_obj, body, quiet = false)
400400 #meth_obj.params = params
401401 meth_obj . start_collecting_tokens
402402 tk = RDoc ::RubyToken ::Token . new nil , 1 , 1
403- tk . set_text body_text
403+ tk . set_text body
404404 meth_obj . add_token tk
405405 meth_obj . comment = strip_stars comment
406- when %r%((?>/\* .*?\* /\s *))^\s *(\# \s *define\s +#{ meth_name } \s +(\w +))%m
406+
407+ body
408+ when %r%((?>/\* .*?\* /\s *))^\s *(\# \s *define\s +#{ meth_name } \s +(\w +))%m then
407409 comment = $1
408- body_text = $2
409- find_body class_name , $3, meth_obj , body , true
410+ body = $2
411+ find_body class_name , $3, meth_obj , file_content , true
410412 find_modifiers comment , meth_obj
411413
412414 meth_obj . start_collecting_tokens
413415 tk = RDoc ::RubyToken ::Token . new nil , 1 , 1
414- tk . set_text body_text
416+ tk . set_text body
415417 meth_obj . add_token tk
416418 meth_obj . comment = strip_stars ( comment ) + meth_obj . comment . to_s
417- when %r%^\s *\# \s *define\s +#{ meth_name } \s +(\w +)%m
418- unless find_body ( class_name , $1, meth_obj , body , true )
419- warn "No definition for #{ meth_name } " if @options . verbosity > 1
420- return false
421- end
419+
420+ body
421+ when %r%^\s *\# \s *define\s +#{ meth_name } \s +(\w +)%m then
422+ body = find_body ( class_name , $1, meth_obj , file_content , true )
423+
424+ return body if body
425+
426+ warn "No definition for #{ meth_name } " if @options . verbosity > 1
427+ false
422428 else # No body, but might still have an override comment
423429 comment = find_override_comment class_name , meth_obj . name
424430
425- if comment
431+ if comment then
426432 find_modifiers comment , meth_obj
427433 meth_obj . comment = strip_stars comment
434+
435+ ''
428436 else
429437 warn "No definition for #{ meth_name } " if @options . verbosity > 1
430- return false
438+ false
431439 end
432440 end
433-
434- true
435441 end
436442
437443 ##
@@ -751,7 +757,7 @@ def handle_ifdefs_in(body)
751757 # to +var_name+. +type+ is the type of method definition function used.
752758 # +singleton_method+ and +module_function+ create a singleton method.
753759
754- def handle_method ( type , var_name , meth_name , meth_body , param_count ,
760+ def handle_method ( type , var_name , meth_name , function , param_count ,
755761 source_file = nil )
756762 singleton = false
757763 class_name = @known_classes [ var_name ]
@@ -773,33 +779,36 @@ def handle_method(type, var_name, meth_name, meth_body, param_count,
773779 end
774780
775781 meth_obj = RDoc ::AnyMethod . new '' , meth_name
782+ meth_obj . c_function = function
776783 meth_obj . singleton =
777784 singleton || %w[ singleton_method module_function ] . include? ( type )
778785
779786 p_count = Integer ( param_count ) rescue -1
780787
781- meth_obj . params = if p_count < -1 then # -2 is Array
782- '(*args)'
783- elsif p_count == -1 then # argc, argv
784- rb_scan_args meth_body
785- else
786- "(#{ ( 1 ..p_count ) . map { |i | "p#{ i } " } . join ', ' } )"
787- end
788-
789788 if source_file then
790789 file_name = File . join @file_dir , source_file
791790
792791 if File . exist? file_name then
793- body = ( @@known_bodies [ file_name ] ||= File . read ( file_name ) )
792+ file_content = ( @@known_bodies [ file_name ] ||= File . read ( file_name ) )
794793 else
795794 warn "unknown source #{ source_file } for #{ meth_name } in #{ @file_name } "
796795 end
797796 else
798- body = @content
797+ file_content = @content
799798 end
800799
801- if find_body ( class_name , meth_body , meth_obj , body ) and
802- meth_obj . document_self then
800+ body = find_body class_name , function , meth_obj , file_content
801+
802+ if body and meth_obj . document_self then
803+ meth_obj . params = if p_count < -1 then # -2 is Array
804+ '(*args)'
805+ elsif p_count == -1 then # argc, argv
806+ rb_scan_args body
807+ else
808+ "(#{ ( 1 ..p_count ) . map { |i | "p#{ i } " } . join ', ' } )"
809+ end
810+
811+
803812 meth_obj . record_location @top_level
804813 class_obj . add_method meth_obj
805814 @stats . add_method meth_obj
0 commit comments