summaryrefslogtreecommitdiff
path: root/lib/rdoc
diff options
context:
space:
mode:
authordave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-21 07:28:54 +0000
committerdave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-12-21 07:28:54 +0000
commitda99e407fbf36051bf9ebce01418589bff557298 (patch)
tree2d673dc5133830cc910ac4e05106236659ff1658 /lib/rdoc
parent6228cbe5efb35f3fb867f42525905cf2ded37aad (diff)
Add file.c comments (and necessary support in parse_c.rb)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rdoc')
-rw-r--r--lib/rdoc/generators/ri_generator.rb8
-rw-r--r--lib/rdoc/parsers/parse_c.rb109
-rw-r--r--lib/rdoc/ri/ri_descriptions.rb19
-rw-r--r--lib/rdoc/ri/ri_formatter.rb30
4 files changed, 112 insertions, 54 deletions
diff --git a/lib/rdoc/generators/ri_generator.rb b/lib/rdoc/generators/ri_generator.rb
index 4e842d09e9..22467e4ba9 100644
--- a/lib/rdoc/generators/ri_generator.rb
+++ b/lib/rdoc/generators/ri_generator.rb
@@ -96,10 +96,14 @@ module Generators
end
def generate_class_info(cls)
- cls_desc = RI::ClassDescription.new
+ if cls === RDoc::NormalModule
+ cls_desc = RI::ClassDescription.new
+ cls_desc.superclass = cls.superclass
+ else
+ cls_desc = RI::ModuleDescription.new
+ end
cls_desc.name = cls.name
cls_desc.full_name = cls.full_name
- cls_desc.superclass = cls.superclass
cls_desc.comment = markup(cls.comment)
cls_desc.attributes =cls.attributes.sort.map do |a|
diff --git a/lib/rdoc/parsers/parse_c.rb b/lib/rdoc/parsers/parse_c.rb
index 0cc19d851f..1de4797c5f 100644
--- a/lib/rdoc/parsers/parse_c.rb
+++ b/lib/rdoc/parsers/parse_c.rb
@@ -156,7 +156,6 @@ module RDoc
end
def handle_class_module(var_name, class_mod, class_name, parent, in_module)
- @known_classes[var_name] = class_name
parent_name = @known_classes[parent] || parent
if in_module
@@ -176,8 +175,10 @@ module RDoc
cm = enclosure.add_module(NormalModule, class_name)
end
cm.record_location(enclosure.toplevel)
- find_class_comment(class_name, cm)
+
+ find_class_comment(cm.full_name, cm)
@classes[var_name] = cm
+ @known_classes[var_name] = cm.full_name
end
@@ -186,8 +187,8 @@ module RDoc
if @body =~ %r{((?>/\*.*?\*/\s+))
(static\s+)?void\s+Init_#{class_name}\s*\(\)}xm
comment = $1
- elsif @body =~ %r{Document-class:\s#{class_name}.*?\n((?>.*?\*/))}m
- comment = $1
+ elsif @body =~ %r{Document-(class|module):\s#{class_name}.*?\n((?>.*?\*/))}m
+ comment = $2
end
class_meth.comment = mangle_comment(comment) if comment
end
@@ -198,16 +199,6 @@ module RDoc
handle_class_module(var_name, "module", class_name, nil, nil)
end
- @body.scan(/(\w+)\s* = \s*rb_define_module_under
- \(
- \s*(\w+),
- \s*"(\w+)"
- \)/mx) do
-
- |var_name, in_module, class_name|
- handle_class_module(var_name, "module", class_name, nil, in_module)
- end
-
@body.scan(/(\w+)\s* = \s*rb_define_class
\(
\s*"(\w+)",
@@ -224,6 +215,16 @@ module RDoc
handle_class_module(var_name, "class", class_name, parent, nil)
end
+ @body.scan(/(\w+)\s* = \s*rb_define_module_under
+ \(
+ \s*(\w+),
+ \s*"(\w+)"
+ \)/mx) do
+
+ |var_name, in_module, class_name|
+ handle_class_module(var_name, "module", class_name, nil, in_module)
+ end
+
@body.scan(/(\w+)\s* = \s*rb_define_class_under
\(
\s*(\w+),
@@ -247,32 +248,56 @@ module RDoc
next if meth_name == "initialize_copy"
- class_name = @known_classes[var_name] || var_name
- class_obj = find_class(var_name, class_name)
+ handle_method(type, var_name, meth_name, meth_body, param_count)
+ end
+
+ @body.scan(/rb_define_global_function\(
+ \s*"([^"]+)",
+ \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
+ \s*(-?\w+)\s*\)/xm) do #"
+ |meth_name, meth_body, param_count|
- if class_obj
- if meth_name == "initialize"
- meth_name = "new"
- type = "singleton_method"
- end
- meth_obj = AnyMethod.new("", meth_name)
- meth_obj.singleton = type == "singleton_method"
-
- p_count = (Integer(param_count) rescue -1)
-
- if p_count < 0
- meth_obj.params = "(...)"
- elsif p_count == 0
- meth_obj.params = "()"
- else
- meth_obj.params = "(" +
- (1..p_count).map{|i| "p#{i}"}.join(", ") +
- ")"
- end
-
- find_body(meth_body, meth_obj)
- class_obj.add_method(meth_obj)
+ handle_method("method", "rb_mKernel", meth_name, meth_body, param_count)
+ end
+
+ @body.scan(/define_filetest_function\(
+ \s*"([^"]+)",
+ \s*(?:RUBY_METHOD_FUNC\(|VALUEFUNC\()?(\w+)\)?,
+ \s*(-?\w+)\s*\)/xm) do #"
+ |meth_name, meth_body, param_count|
+
+ 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
+
+
+ def handle_method(type, var_name, meth_name, meth_body, param_count)
+ class_name = @known_classes[var_name] || var_name
+ class_obj = find_class(var_name, class_name)
+
+ if class_obj
+ if meth_name == "initialize"
+ meth_name = "new"
+ type = "singleton_method"
end
+ meth_obj = AnyMethod.new("", meth_name)
+ meth_obj.singleton = type == "singleton_method"
+
+ p_count = (Integer(param_count) rescue -1)
+
+ if p_count < 0
+ meth_obj.params = "(...)"
+ elsif p_count == 0
+ meth_obj.params = "()"
+ else
+ meth_obj.params = "(" +
+ (1..p_count).map{|i| "p#{i}"}.join(", ") +
+ ")"
+ end
+
+ find_body(meth_body, meth_obj)
+ class_obj.add_method(meth_obj)
end
end
@@ -331,14 +356,14 @@ module RDoc
end
def find_class(raw_name, name)
- unless @classes[name]
+ unless @classes[raw_name]
if raw_name =~ /^rb_m/
- @classes[name] = @top_level.add_module(NormalModule, name)
+ @classes[raw_name] = @top_level.add_module(NormalModule, name)
else
- @classes[name] = @top_level.add_class(NormalClass, name, nil)
+ @classes[raw_name] = @top_level.add_class(NormalClass, name, nil)
end
end
- @classes[name]
+ @classes[raw_name]
end
end
diff --git a/lib/rdoc/ri/ri_descriptions.rb b/lib/rdoc/ri/ri_descriptions.rb
index 9e280abf94..9bd5c2d13b 100644
--- a/lib/rdoc/ri/ri_descriptions.rb
+++ b/lib/rdoc/ri/ri_descriptions.rb
@@ -76,13 +76,12 @@ module RI
end
end
- class ClassDescription < Description
+ class ModuleDescription < Description
attr_accessor :class_methods
attr_accessor :instance_methods
attr_accessor :attributes
attr_accessor :constants
- attr_accessor :superclass
attr_accessor :includes
# merge in another class desscription into this one
@@ -92,6 +91,13 @@ module RI
merge(@attributes, old.attributes)
merge(@constants, old.constants)
merge(@includes, old.includes)
+ if @comment.nil? || @comment.empty?
+ @comment = old.comment
+ end
+ end
+
+ def display_name
+ "Module"
end
private
@@ -104,6 +110,15 @@ module RI
end
end
+ class ClassDescription < ModuleDescription
+ attr_accessor :superclass
+
+ def display_name
+ "Class"
+ end
+ end
+
+
class MethodDescription < Description
attr_accessor :is_class_method
diff --git a/lib/rdoc/ri/ri_formatter.rb b/lib/rdoc/ri/ri_formatter.rb
index 1e70529bfe..b3024d4c6c 100644
--- a/lib/rdoc/ri/ri_formatter.rb
+++ b/lib/rdoc/ri/ri_formatter.rb
@@ -1,11 +1,16 @@
module RI
- class RiFormatter
+ class TextFormatter
+
+ def TextFormatter.create(options, indent)
+ new(options, indent)
+ end
attr_reader :indent
- def initialize(width, indent)
- @width = width
- @indent = indent
+ def initialize(options, indent)
+ @options = options
+ @width = options.width
+ @indent = indent
end
@@ -23,7 +28,7 @@ module RI
def wrap(txt, prefix=@indent, linelen=@width)
return unless txt && !txt.empty?
- work = txt.dup
+ work = conv_markup(txt)
textLen = linelen - prefix.length
patt = Regexp.new("^(.{0,#{textLen}})[ \n]")
next_prefix = prefix.tr("^ ", " ")
@@ -53,9 +58,6 @@ module RI
# convert HTML entities back to ASCII
def conv_html(txt)
txt.
- gsub(%r{<tt>(.*?)</tt>}) { "+#$1+" } .
- gsub(%r{<b>(.*?)</b>}) { "*#$1*" } .
- gsub(%r{<em>(.*?)</em>}) { "_#$1_" } .
gsub(/&gt;/, '>').
gsub(/&lt;/, '<').
gsub(/&quot;/, '"').
@@ -63,6 +65,15 @@ module RI
end
+ # convert markup into display form
+ def conv_markup(txt)
+ txt.
+ gsub(%r{<tt>(.*?)</tt>}) { "+#$1+" } .
+ gsub(%r{<code>(.*?)</code>}) { "+#$1+" } .
+ gsub(%r{<b>(.*?)</b>}) { "*#$1*" } .
+ gsub(%r{<em>(.*?)</em>}) { "_#$1_" }
+ end
+
######################################################################
def display_list(list)
@@ -167,4 +178,7 @@ module RI
end
end
end
+
end
+
+