@@ -606,46 +606,18 @@ def find_attr_comment var_name, attr_name, read = nil, write = nil
606606 RDoc ::Comment . new comment , @top_level
607607 end
608608
609- ##
610- # Generate a Ruby-method table
611-
612- def gen_body_table file_content
613- table = { }
614- file_content . scan ( %r{
615- ((?>/\* .*?\* /\s *)?)
616- ((?:(?:\w +)\s +)?
617- (?:intern\s +)?VALUE\s +(\w +)
618- \s *(?:\( [^)]*\) )(?:[^;]|$))
619- | ((?>/\* .*?\* /\s *))^\s *(\# \s *define\s +(\w +)\s +(\w +))
620- | ^\s *\# \s *define\s +(\w +)\s +(\w +)
621- }xm ) do
622- case
623- when $1
624- table [ $3] = [ :func_def , $1, $2, $~. offset ( 2 ) ] if !table [ $3] || table [ $3] [ 0 ] != :func_def
625- when $4
626- table [ $6] = [ :macro_def , $4, $5, $~. offset ( 5 ) , $7] if !table [ $6] || table [ $6] [ 0 ] == :macro_alias
627- when $8
628- table [ $8] ||= [ :macro_alias , $9]
629- end
630- end
631- table
632- end
633-
634609 ##
635610 # Find the C code corresponding to a Ruby method
636611
637612 def find_body class_name , meth_name , meth_obj , file_content , quiet = false
638- if file_content
639- @body_table ||= { }
640- @body_table [ file_content ] ||= gen_body_table file_content
641- type , *args = @body_table [ file_content ] [ meth_name ]
642- end
643-
644- case type
645- when :func_def
646- comment = RDoc ::Comment . new args [ 0 ] , @top_level
647- body = args [ 1 ]
648- offset , = args [ 2 ]
613+ case file_content
614+ when %r%((?>/\* .*?\* /\s *)?)
615+ ((?:(?:\w +)\s +)?
616+ (?:intern\s +)?VALUE\s +#{ meth_name }
617+ \s *(\( [^)]*\) )([^;]|$))%xm then
618+ comment = RDoc ::Comment . new $1, @top_level
619+ body = $2
620+ offset , = $~. offset ( 2 )
649621
650622 comment . remove_private if comment
651623
@@ -674,12 +646,12 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
674646 meth_obj . line = file_content [ 0 , offset ] . count ( "\n " ) + 1
675647
676648 body
677- when :macro_def
678- comment = RDoc ::Comment . new args [ 0 ] , @top_level
679- body = args [ 1 ]
680- offset , = args [ 2 ]
649+ when %r%((?>/ \* .*? \* / \s *))^ \s *( \# \s *define \s + #{ meth_name } \s +( \w +))%m then
650+ comment = RDoc ::Comment . new $1 , @top_level
651+ body = $2
652+ offset = $~ . offset ( 2 ) . first
681653
682- find_body class_name , args [ 3 ] , meth_obj , file_content , true
654+ find_body class_name , $3 , meth_obj , file_content , true
683655
684656 comment . normalize
685657 find_modifiers comment , meth_obj
@@ -693,11 +665,11 @@ def find_body class_name, meth_name, meth_obj, file_content, quiet = false
693665 meth_obj . line = file_content [ 0 , offset ] . count ( "\n " ) + 1
694666
695667 body
696- when :macro_alias
668+ when %r%^ \s * \# \s *define \s + #{ meth_name } \s +( \w +)%m then
697669 # with no comment we hope the aliased definition has it and use it's
698670 # definition
699671
700- body = find_body ( class_name , args [ 0 ] , meth_obj , file_content , true )
672+ body = find_body ( class_name , $1 , meth_obj , file_content , true )
701673
702674 return body if body
703675
@@ -792,42 +764,28 @@ def find_class_comment class_name, class_mod
792764 class_mod . add_comment comment , @top_level
793765 end
794766
795- ##
796- # Generate a const table
797-
798- def gen_const_table file_content
799- table = { }
800- @content . scan ( %r{
801- ((?>^\s */\* .*?\* /\s +))
802- rb_define_(\w +)\( (?:\s *(?:\w +),)?\s *
803- "(\w +)"\s *,
804- .*?\) \s *;
805- | Document-(?:const|global|variable):\s
806- ((?:\w +::)*\w +)
807- \s *?\n ((?>.*?\* /))
808- }mxi ) do
809- case
810- when $1 then table [ [ $2, $3] ] = $1
811- when $4 then table [ $4] = "/*\n " + $5
812- end
813- end
814- table
815- end
816-
817767 ##
818768 # Finds a comment matching +type+ and +const_name+ either above the
819769 # comment or in the matching Document- section.
820770
821771 def find_const_comment ( type , const_name , class_name = nil )
822- @const_table ||= { }
823- @const_table [ @content ] ||= gen_const_table @content
824- table = @const_table [ @content ]
825-
826- comment =
827- table [ [ type , const_name ] ] ||
828- ( class_name && table [ class_name + "::" + const_name ] ) ||
829- table [ const_name ] ||
830- ''
772+ comment = if @content =~ %r%((?>^\s */\* .*?\* /\s +))
773+ rb_define_#{ type } \( (?:\s *(\w +),)?\s *
774+ "#{ const_name } "\s *,
775+ .*?\) \s *;%xmi then
776+ $1
777+ elsif class_name and
778+ @content =~ %r%Document-(?:const|global|variable):\s
779+ #{ class_name } ::#{ const_name }
780+ \s *?\n ((?>.*?\* /))%xm then
781+ "/*\n #{ $1} "
782+ elsif @content =~ %r%Document-(?:const|global|variable):
783+ \s #{ const_name }
784+ \s *?\n ((?>.*?\* /))%xm then
785+ "/*\n #{ $1} "
786+ else
787+ ''
788+ end
831789
832790 RDoc ::Comment . new comment , @top_level
833791 end
0 commit comments