Skip to content

Commit

Permalink
C parser/SWIG improvements, ruby bugs #10742 #13993 #11993
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Sep 23, 2008
1 parent 35f1764 commit 05ce9d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
5 changes: 4 additions & 1 deletion History.txt
Expand Up @@ -5,6 +5,8 @@ to polish RDoc for Ruby 1.9.1.
* X Major Enhancements

* Y Minor Enhancements
* Support for parsing RDoc from SWIG. Ruby patch #10742 by Gonzalo
Garramuno, #13993 by Steven Jenkins.

* Z Bug Fixes
* Explicitly set the html template's text color, so that the generated
Expand All @@ -14,7 +16,8 @@ to polish RDoc for Ruby 1.9.1.
if it encounters the alias first because the alias lives in a different
file.
* Fix the parsing of multiline constants (patch by Chris Alfeld and Joel VanderWerf)
* Make --exclude usuable. Patch #11671 by Trans.
* Make --exclude usuable. Ruby patch #11671 by Trans.
* Detect inline C functions. Ruby Bug #11993 by Florian Frank.

=== 2.2.0 / 2008-09-19
This version includes some significant enhancements to ri. See RI.txt for
Expand Down
30 changes: 18 additions & 12 deletions lib/rdoc/parser/c.rb
Expand Up @@ -155,7 +155,7 @@ def do_classes
\(
\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
Expand Down Expand Up @@ -267,9 +267,9 @@ def find_attr_comment(attr_name)
##
# 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}
when %r"((?>/\*.*?\*/\s*)*)(?:static|SWIGINTERN\s+)?(?:intern\s+)?VALUE\s+#{meth_name}
\s*(\([^)]*\))([^;]|$)"xm
comment, params = $1, $2
body_text = $&
Expand All @@ -287,7 +287,7 @@ def find_body(meth_name, meth_obj, body, quiet = false)
# 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
Expand All @@ -298,7 +298,7 @@ def find_body(meth_name, meth_obj, body, quiet = false)
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
Expand All @@ -309,7 +309,7 @@ def find_body(meth_name, meth_obj, body, quiet = false)
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)
Expand Down Expand Up @@ -365,10 +365,10 @@ def find_class(raw_name, name)
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
Expand Down Expand Up @@ -422,9 +422,11 @@ def find_modifiers(comment, meth_obj)
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
Expand Down Expand Up @@ -478,6 +480,10 @@ def handle_class_module(var_name, class_mod, class_name, parent, in_module)
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
Expand Down Expand Up @@ -588,7 +594,7 @@ def handle_method(type, var_name, meth_name, meth_body, param_count,
body = @content
end

if find_body(meth_body, meth_obj, body) and meth_obj.document_self then
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
Expand Down

0 comments on commit 05ce9d4

Please sign in to comment.