Skip to content

Commit

Permalink
Move all progress printing to RDoc::Stats
Browse files Browse the repository at this point in the history
  • Loading branch information
drbrain committed Jul 21, 2008
1 parent 66cbb5d commit 5328a37
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 123 deletions.
26 changes: 16 additions & 10 deletions lib/rdoc/code_objects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def document_children=(val)
# Do we _force_ documentation, even is we wouldn't normally show the entity
attr_accessor :force_documentation

def parent_file_name
@parent ? @parent.file_base_name : '(unknown)'
end

def parent_name
@parent ? @parent.name : '(unknown)'
end

# Default callbacks to nothing, but this is overridden for classes
# and modules
def remove_classes_and_modules
Expand Down Expand Up @@ -272,7 +280,6 @@ def add_module(class_type, name)
end

def add_method(a_method)
puts "Adding #@visibility method #{a_method.name} to #@name" if $DEBUG_RDOC
a_method.visibility = @visibility
add_to(@method_list, a_method)
end
Expand All @@ -283,7 +290,8 @@ def add_attribute(an_attribute)

def add_alias(an_alias)
meth = find_instance_method_named(an_alias.old_name)
if meth

if meth then
new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
new_meth.is_alias_for = meth
new_meth.singleton = meth.singleton
Expand All @@ -294,6 +302,8 @@ def add_alias(an_alias)
else
add_to(@aliases, an_alias)
end

an_alias
end

def add_include(an_include)
Expand Down Expand Up @@ -321,7 +331,6 @@ def add_class_or_module(collection, class_type, name, superclass=nil)
puts "Reusing class/module #{name}" if $DEBUG_RDOC
else
cls = class_type.new(name, superclass)
puts "Adding class/module #{name} to #@name" if $DEBUG_RDOC
# collection[name] = cls if @document_self && !@done_documenting
collection[name] = cls if !@done_documenting
cls.parent = self
Expand Down Expand Up @@ -569,8 +578,6 @@ def add_class_or_module(collection, class_type, name, superclass)
all[name] = cls unless @done_documenting
end

puts "Adding class/module #{name} to #{full_name}" if $DEBUG_RDOC

collection[name] = cls unless @done_documenting

cls.parent = self
Expand Down Expand Up @@ -806,7 +813,7 @@ def inspect
alias_for = @is_alias_for ? " (alias for #{@is_alias_for.name})" : nil
"#<%s:0x%x %s%s%s (%s)%s>" % [
self.class, object_id,
@parent.name,
parent_name,
singleton ? '::' : '#',
name,
visibility,
Expand Down Expand Up @@ -928,7 +935,7 @@ def inspect

"#<%s:0x%x %s.%s :%s>" % [
self.class, object_id,
@parent.name, attr, @name,
parent_name, attr, @name,
]
end

Expand All @@ -955,7 +962,7 @@ def inspect
self.class,
object_id,
@name,
@parent.file_base_name,
parent_file_name,
]
end

Expand All @@ -979,8 +986,7 @@ def inspect
"#<%s:0x%x %s.include %s>" % [
self.class,
object_id,
@parent.name,
@name,
parent_name, @name,
]
end

Expand Down
31 changes: 24 additions & 7 deletions lib/rdoc/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ class RDoc::Options

attr_reader :promiscuous

##
# Don't display progress as we process the files

attr_accessor :quiet

##
# Array of directories to search for files to satisfy an :include:

Expand Down Expand Up @@ -149,6 +144,11 @@ class RDoc::Options

attr_reader :title

##
# Verbosity, zero means quiet

attr_accessor :verbosity

##
# URL of web cvs frontend

Expand All @@ -161,7 +161,6 @@ def initialize(generators = {}) # :nodoc:
@main_page = nil
@merge = false
@exclude = []
@quiet = false
@generators = generators
@generator_name = 'html'
@generator = @generators[@generator_name]
Expand All @@ -180,6 +179,7 @@ def initialize(generators = {}) # :nodoc:
@extra_accessor_flags = {}
@promiscuous = false
@force_update = false
@verbosity = 1

@css = nil
@webcvs = nil
Expand Down Expand Up @@ -424,9 +424,15 @@ def parse(argv)

opt.on("--quiet", "-q",
"Don't show progress as we parse.") do |value|
@quiet = value
@verbosity = 0
end

opt.on("--verbose", "-v",
"Display extra progress as we parse.") do |value|
@verbosity = 2
end


opt.separator nil

opt.on("--ri", "-r",
Expand Down Expand Up @@ -559,6 +565,17 @@ def title=(string)
@title ||= string
end

##
# Don't display progress as we process the files

def quiet
@verbosity.zero?
end

def quiet=(bool)
@verbosity = bool ? 0 : 1
end

private

##
Expand Down
3 changes: 0 additions & 3 deletions lib/rdoc/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class << self
attr_reader :parsers
end

attr_writer :progress

##
# Alias an extension to another extension. After this call, files ending
# "new_ext" will be parsed using the same parser as "old_ext"
Expand Down Expand Up @@ -103,7 +101,6 @@ def initialize(top_level, file_name, content, options, stats)
@content = content
@options = options
@stats = stats
@progress = $stderr unless options.quiet
end

end
Expand Down
29 changes: 9 additions & 20 deletions lib/rdoc/parser/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ class RDoc::Parser::C < RDoc::Parser

parse_files_matching(/\.(?:([CcHh])\1?|c([+xp])\2|y)\z/)

attr_writer :progress

@@enclosure_classes = {}
@@known_bodies = {}

Expand All @@ -115,11 +113,12 @@ def initialize(top_level, file_name, content, options, stats)
def do_aliases
@content.scan(%r{rb_define_alias\s*\(\s*(\w+),\s*"([^"]+)",\s*"([^"]+)"\s*\)}m) do
|var_name, new_name, old_name|
@stats.num_methods += 1
class_name = @known_classes[var_name] || var_name
class_obj = find_class(var_name, class_name)

class_obj.add_alias RDoc::Alias.new("", old_name, new_name, "")
as = class_obj.add_alias RDoc::Alias.new("", old_name, new_name, "")

@stats.add_alias as
end
end

Expand Down Expand Up @@ -306,7 +305,7 @@ def find_body(meth_name, meth_obj, body, quiet = false)
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)
warn "No definition for #{meth_name}" unless quiet
warn "No definition for #{meth_name}" unless @options.quiet
return false
end
else
Expand All @@ -318,7 +317,7 @@ def find_body(meth_name, meth_obj, body, quiet = false)
find_modifiers(comment, meth_obj)
meth_obj.comment = mangle_comment(comment)
else
warn "No definition for #{meth_name}" unless quiet
warn "No definition for #{meth_name}" unless @options.quiet
return false
end
end
Expand Down Expand Up @@ -460,8 +459,6 @@ def handle_attr(var_name, attr_name, reader, writer)
end

def handle_class_module(var_name, class_mod, class_name, parent, in_module)
progress(class_mod[0, 1])

parent_name = @known_classes[parent] || parent

if in_module
Expand All @@ -484,10 +481,10 @@ def handle_class_module(var_name, class_mod, class_name, parent, in_module)

if class_mod == "class" then
cm = enclosure.add_class RDoc::NormalClass, class_name, parent_name
@stats.num_classes += 1
@stats.add_class cm
else
cm = enclosure.add_module RDoc::NormalModule, class_name
@stats.num_modules += 1
@stats.add_module cm
end

cm.record_location(enclosure.toplevel)
Expand Down Expand Up @@ -561,9 +558,6 @@ def handle_ifdefs_in(body)

def handle_method(type, var_name, meth_name, meth_body, param_count,
source_file = nil)
progress(".")

@stats.num_methods += 1
class_name = @known_classes[var_name]

return unless class_name
Expand All @@ -579,6 +573,8 @@ def handle_method(type, var_name, meth_name, meth_body, param_count,
meth_obj.singleton =
%w{singleton_method module_function}.include?(type)

@stats.add_method meth_obj

p_count = (Integer(param_count) rescue -1)

if p_count < 0
Expand Down Expand Up @@ -623,13 +619,6 @@ def mangle_comment(comment)
comment
end

def progress(char)
unless @options.quiet
@progress.print(char)
@progress.flush
end
end

##
# Removes lines that are commented out that might otherwise get picked up
# when scanning for classes and methods
Expand Down
Loading

0 comments on commit 5328a37

Please sign in to comment.