summaryrefslogtreecommitdiff
path: root/lib/rdoc/parser/c.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-25 02:43:03 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-25 02:43:03 +0000
commit858362e761a41e7d96efbcb9b38ae815b1e388d7 (patch)
treeb47a0968d921320591f9218bc746e11a7922c53f /lib/rdoc/parser/c.rb
parent00b4a3f9c4aaf5aa038a9530ec515e1718ae1c42 (diff)
Import RDoc 2.2.1 r185
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc/parser/c.rb')
-rw-r--r--lib/rdoc/parser/c.rb64
1 files changed, 34 insertions, 30 deletions
diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb
index 43bb767da9..a5b06c2b04 100644
--- a/lib/rdoc/parser/c.rb
+++ b/lib/rdoc/parser/c.rb
@@ -120,7 +120,7 @@ class RDoc::Parser::C < RDoc::Parser
@stats.add_alias as
end
- end
+ end
def do_classes
@content.scan(/(\w+)\s* = \s*rb_define_module\s*\(\s*"(\w+)"\s*\)/mx) do
@@ -155,7 +155,7 @@ class RDoc::Parser::C < RDoc::Parser
\(
\s*(\w+),
\s*"(\w+)",
- \s*(\w+)\s*
+ \s*([\w\*\s\(\)\.\->]+)\s* # for SWIG
\s*\)/mx) do |var_name, in_module, class_name, parent|
handle_class_module(var_name, "class", class_name, parent, in_module)
end
@@ -251,7 +251,7 @@ class RDoc::Parser::C < RDoc::Parser
handle_method("method", "rb_mFileTest", meth_name, meth_body, param_count)
handle_method("singleton_method", "rb_cFile", meth_name, meth_body, param_count)
end
- end
+ end
def find_attr_comment(attr_name)
if @content =~ %r{((?>/\*.*?\*/\s+))
@@ -267,10 +267,10 @@ class RDoc::Parser::C < RDoc::Parser
##
# Find the C code corresponding to a Ruby method
- def find_body(meth_name, meth_obj, body, quiet = false)
+ def find_body(class_name, meth_name, meth_obj, body, quiet = false)
case body
- when %r"((?>/\*.*?\*/\s*))(?:static\s+)?VALUE\s+#{meth_name}
- \s*(\([^)]*\))\s*\{.*?^\}"xm
+ when %r"((?>/\*.*?\*/\s*)*)(?:(?:static|SWIGINTERN)\s+)?(?:intern\s+)?VALUE\s+#{meth_name}
+ \s*(\([^)]*\))([^;]|$)"xm
comment, params = $1, $2
body_text = $&
@@ -279,9 +279,7 @@ class RDoc::Parser::C < RDoc::Parser
# 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
@@ -289,7 +287,7 @@ class RDoc::Parser::C < RDoc::Parser
# distinct (for example Kernel.hash and Kernel.object_id share the same
# implementation
- override_comment = find_override_comment(meth_obj.name)
+ override_comment = find_override_comment(class_name, meth_obj.name)
comment = override_comment if override_comment
find_modifiers(comment, meth_obj) if comment
@@ -300,18 +298,18 @@ class RDoc::Parser::C < RDoc::Parser
meth_obj.comment = mangle_comment(comment)
when %r{((?>/\*.*?\*/\s*))^\s*\#\s*define\s+#{meth_name}\s+(\w+)}m
comment = $1
- find_body($2, meth_obj, body, true)
+ find_body(class_name, $2, meth_obj, body, true)
find_modifiers(comment, meth_obj)
meth_obj.comment = mangle_comment(comment) + meth_obj.comment
when %r{^\s*\#\s*define\s+#{meth_name}\s+(\w+)}m
- unless find_body($1, meth_obj, body, true)
+ unless find_body(class_name, $1, meth_obj, body, true)
warn "No definition for #{meth_name}" unless @options.quiet
return false
end
else
# No body, but might still have an override comment
- comment = find_override_comment(meth_obj.name)
+ comment = find_override_comment(class_name, meth_obj.name)
if comment
find_modifiers(comment, meth_obj)
@@ -367,10 +365,10 @@ class RDoc::Parser::C < RDoc::Parser
def find_class_comment(class_name, class_meth)
comment = nil
if @content =~ %r{((?>/\*.*?\*/\s+))
- (static\s+)?void\s+Init_#{class_name}\s*(?:_\(\s*)?\(\s*(?:void\s*)\)}xmi
+ (static\s+)?void\s+Init_#{class_name}\s*(?:_\(\s*)?\(\s*(?:void\s*)\)}xmi then
+ comment = $1
+ elsif @content =~ %r{Document-(?:class|module):\s#{class_name}\s*?(?:<\s+[:,\w]+)?\n((?>.*?\*/))}m
comment = $1
- elsif @content =~ %r{Document-(class|module):\s#{class_name}\s*?\n((?>.*?\*/))}m
- comment = $2
else
if @content =~ /rb_define_(class|module)/m then
class_name = class_name.split("::").last
@@ -424,9 +422,11 @@ class RDoc::Parser::C < RDoc::Parser
end
end
- def find_override_comment(meth_name)
+ def find_override_comment(class_name, meth_name)
name = Regexp.escape(meth_name)
- if @content =~ %r{Document-method:\s#{name}\s*?\n((?>.*?\*/))}m
+ if @content =~ %r{Document-method:\s+#{class_name}(?:\.|::)#{name}\s*?\n((?>.*?\*/))}m then
+ $1
+ elsif @content =~ %r{Document-method:\s#{name}\s*?\n((?>.*?\*/))}m then
$1
end
end
@@ -480,6 +480,10 @@ class RDoc::Parser::C < RDoc::Parser
end
if class_mod == "class" then
+ full_name = enclosure.full_name.to_s + "::#{class_name}"
+ if @content =~ %r{Document-class:\s+#{full_name}\s*<\s+([:,\w]+)} then
+ parent_name = $1
+ end
cm = enclosure.add_class RDoc::NormalClass, class_name, parent_name
@stats.add_class cm
else
@@ -562,18 +566,16 @@ class RDoc::Parser::C < RDoc::Parser
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)
@@ -585,14 +587,16 @@ class RDoc::Parser::C < RDoc::Parser
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(class_name, 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
@@ -628,8 +632,8 @@ class RDoc::Parser::C < RDoc::Parser
end
def remove_private_comments(comment)
- comment.gsub!(/\/?\*--(.*?)\/?\*\+\+/m, '')
- comment.sub!(/\/?\*--.*/m, '')
+ comment.gsub!(/\/?\*--\n(.*?)\/?\*\+\+/m, '')
+ comment.sub!(/\/?\*--\n.*/m, '')
end
##