lib/rdoc/parser/c.rb in rdoc-2.1.0 vs lib/rdoc/parser/c.rb in rdoc-2.2.0
- old
+ new
@@ -268,22 +268,20 @@
# Find the C code corresponding to a Ruby method
def find_body(meth_name, meth_obj, body, quiet = false)
case body
when %r"((?>/\*.*?\*/\s*))(?:static\s+)?VALUE\s+#{meth_name}
- \s*(\([^)]*\))\s*\{.*?^\}"xm
+ \s*(\([^)]*\))([^;]|$)"xm
comment, params = $1, $2
body_text = $&
remove_private_comments(comment) if comment
# see if we can find the whole body
re = Regexp.escape(body_text) + '[^(]*^\{.*?^\}'
- if Regexp.new(re, Regexp::MULTILINE).match(body)
- body_text = $&
- end
+ body_text = $& if /#{re}/m =~ body
# The comment block may have been overridden with a 'Document-method'
# block. This happens in the interpreter when multiple methods are
# vectored through to the same C method but those methods are logically
# distinct (for example Kernel.hash and Kernel.object_id share the same
@@ -560,22 +558,20 @@
source_file = nil)
class_name = @known_classes[var_name]
return unless class_name
- class_obj = find_class(var_name, class_name)
+ class_obj = find_class var_name, class_name
- if class_obj
- if meth_name == "initialize"
+ if class_obj then
+ if meth_name == "initialize" then
meth_name = "new"
type = "singleton_method"
end
- meth_obj = RDoc::AnyMethod.new("", meth_name)
- meth_obj.singleton =
- %w{singleton_method module_function}.include?(type)
- @stats.add_method meth_obj
+ meth_obj = RDoc::AnyMethod.new '', meth_name
+ meth_obj.singleton = %w[singleton_method module_function].include? type
p_count = (Integer(param_count) rescue -1)
if p_count < 0
meth_obj.params = "(...)"
@@ -583,18 +579,20 @@
meth_obj.params = "()"
else
meth_obj.params = "(" + (1..p_count).map{|i| "p#{i}"}.join(", ") + ")"
end
- if source_file
+ if source_file then
file_name = File.join(@file_dir, source_file)
body = (@@known_bodies[source_file] ||= File.read(file_name))
else
body = @content
end
- if find_body(meth_body, meth_obj, body) and meth_obj.document_self
- class_obj.add_method(meth_obj)
+
+ if find_body(meth_body, meth_obj, body) and meth_obj.document_self then
+ class_obj.add_method meth_obj
+ @stats.add_method meth_obj
end
end
end
def handle_tab_width(body)
@@ -626,11 +624,11 @@
def remove_commented_out_lines
@content.gsub!(%r{//.*rb_define_}, '//')
end
def remove_private_comments(comment)
- comment.gsub!(/\/?\*--(.*?)\/?\*\+\+/m, '')
- comment.sub!(/\/?\*--.*/m, '')
+ comment.gsub!(/\/?\*--\n(.*?)\/?\*\+\+/m, '')
+ comment.sub!(/\/?\*--\n.*/m, '')
end
##
# Extract the classes/modules and methods from a C file and return the
# corresponding top-level object