2003-12-01 02:12:49 -05:00
|
|
|
# We represent the various high-level code constructs that appear
|
|
|
|
# in Ruby programs: classes, modules, methods, and so on.
|
|
|
|
|
|
|
|
require 'rdoc/tokenstream'
|
|
|
|
|
|
|
|
module RDoc
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
##
|
2008-07-17 20:46:16 -04:00
|
|
|
# We contain the common stuff for contexts (which are containers) and other
|
|
|
|
# elements (methods, attributes and so on)
|
2008-02-09 22:59:08 -05:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class CodeObject
|
|
|
|
|
|
|
|
attr_accessor :parent
|
|
|
|
|
|
|
|
# We are the model of the code, but we know that at some point
|
|
|
|
# we will be worked on by viewers. By implementing the Viewable
|
|
|
|
# protocol, viewers can associated themselves with these objects.
|
|
|
|
|
|
|
|
attr_accessor :viewer
|
|
|
|
|
|
|
|
# are we done documenting (ie, did we come across a :enddoc:)?
|
|
|
|
|
|
|
|
attr_accessor :done_documenting
|
|
|
|
|
2004-11-20 10:02:57 -05:00
|
|
|
# Which section are we in
|
|
|
|
|
|
|
|
attr_accessor :section
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
# do we document ourselves?
|
|
|
|
|
|
|
|
attr_reader :document_self
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def initialize
|
|
|
|
@document_self = true
|
|
|
|
@document_children = true
|
|
|
|
@force_documentation = false
|
|
|
|
@done_documenting = false
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def document_self=(val)
|
|
|
|
@document_self = val
|
|
|
|
if !val
|
|
|
|
remove_methods_etc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# set and cleared by :startdoc: and :enddoc:, this is used to toggle
|
|
|
|
# the capturing of documentation
|
|
|
|
def start_doc
|
|
|
|
@document_self = true
|
|
|
|
@document_children = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_doc
|
|
|
|
@document_self = false
|
|
|
|
@document_children = false
|
|
|
|
end
|
|
|
|
|
|
|
|
# do we document ourselves and our children
|
|
|
|
|
|
|
|
attr_reader :document_children
|
|
|
|
|
|
|
|
def document_children=(val)
|
|
|
|
@document_children = val
|
|
|
|
if !val
|
|
|
|
remove_classes_and_modules
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Do we _force_ documentation, even is we wouldn't normally show the entity
|
|
|
|
attr_accessor :force_documentation
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def parent_file_name
|
|
|
|
@parent ? @parent.file_base_name : '(unknown)'
|
|
|
|
end
|
|
|
|
|
|
|
|
def parent_name
|
|
|
|
@parent ? @parent.name : '(unknown)'
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
# Default callbacks to nothing, but this is overridden for classes
|
|
|
|
# and modules
|
|
|
|
def remove_classes_and_modules
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_methods_etc
|
|
|
|
end
|
|
|
|
|
|
|
|
# Access the code object's comment
|
|
|
|
attr_reader :comment
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
# Update the comment, but don't overwrite a real comment with an empty one
|
2003-12-01 02:12:49 -05:00
|
|
|
def comment=(comment)
|
|
|
|
@comment = comment unless comment.empty?
|
|
|
|
end
|
|
|
|
|
|
|
|
# There's a wee trick we pull. Comment blocks can have directives that
|
|
|
|
# override the stuff we extract during the parse. So, we have a special
|
|
|
|
# class method, attr_overridable, that lets code objects list
|
|
|
|
# those directives. Wehn a comment is assigned, we then extract
|
|
|
|
# out any matching directives and update our object
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
def self.attr_overridable(name, *aliases)
|
2003-12-01 02:12:49 -05:00
|
|
|
@overridables ||= {}
|
|
|
|
|
|
|
|
attr_accessor name
|
|
|
|
|
|
|
|
aliases.unshift name
|
|
|
|
aliases.each do |directive_name|
|
|
|
|
@overridables[directive_name.to_s] = name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# A Context is something that can hold modules, classes, methods,
|
|
|
|
# attributes, aliases, requires, and includes. Classes, modules, and files
|
|
|
|
# are all Contexts.
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
class Context < CodeObject
|
2004-11-20 10:02:57 -05:00
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
attr_reader :aliases
|
|
|
|
attr_reader :attributes
|
|
|
|
attr_reader :constants
|
|
|
|
attr_reader :current_section
|
|
|
|
attr_reader :in_files
|
|
|
|
attr_reader :includes
|
|
|
|
attr_reader :method_list
|
|
|
|
attr_reader :name
|
|
|
|
attr_reader :requires
|
|
|
|
attr_reader :sections
|
|
|
|
attr_reader :visibility
|
2004-11-20 10:02:57 -05:00
|
|
|
|
|
|
|
class Section
|
|
|
|
attr_reader :title, :comment, :sequence
|
|
|
|
|
|
|
|
@@sequence = "SEC00000"
|
|
|
|
|
|
|
|
def initialize(title, comment)
|
|
|
|
@title = title
|
|
|
|
@@sequence.succ!
|
|
|
|
@sequence = @@sequence.dup
|
2007-12-23 02:13:09 -05:00
|
|
|
@comment = nil
|
2004-12-04 00:38:17 -05:00
|
|
|
set_comment(comment)
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def ==(other)
|
|
|
|
self.class === other and @sequence == other.sequence
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<%s:0x%x %s %p>" % [
|
|
|
|
self.class, object_id,
|
|
|
|
@sequence, title
|
|
|
|
]
|
|
|
|
end
|
2004-12-04 00:38:17 -05:00
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# Set the comment for this section from the original comment block If
|
|
|
|
# the first line contains :section:, strip it and use the rest.
|
|
|
|
# Otherwise remove lines up to the line containing :section:, and look
|
|
|
|
# for those lines again at the end and remove them. This lets us write
|
2004-12-04 00:38:17 -05:00
|
|
|
#
|
|
|
|
# # ---------------------
|
|
|
|
# # :SECTION: The title
|
|
|
|
# # The body
|
|
|
|
# # ---------------------
|
|
|
|
|
|
|
|
def set_comment(comment)
|
|
|
|
return unless comment
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
if comment =~ /^#[ \t]*:section:.*\n/
|
2004-12-04 00:38:17 -05:00
|
|
|
start = $`
|
|
|
|
rest = $'
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2004-12-04 00:38:17 -05:00
|
|
|
if start.empty?
|
|
|
|
@comment = rest
|
|
|
|
else
|
|
|
|
@comment = rest.sub(/#{start.chomp}\Z/, '')
|
|
|
|
end
|
|
|
|
else
|
|
|
|
@comment = comment
|
2004-11-20 10:02:57 -05:00
|
|
|
end
|
2004-12-04 00:38:17 -05:00
|
|
|
@comment = nil if @comment.empty?
|
2004-11-20 10:02:57 -05:00
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
def initialize
|
2008-07-17 20:46:16 -04:00
|
|
|
super
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
@in_files = []
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
@name ||= "unknown"
|
|
|
|
@comment ||= ""
|
|
|
|
@parent = nil
|
|
|
|
@visibility = :public
|
|
|
|
|
2004-11-20 10:02:57 -05:00
|
|
|
@current_section = Section.new(nil, nil)
|
|
|
|
@sections = [ @current_section ]
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
initialize_methods_etc
|
|
|
|
initialize_classes_and_modules
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# map the class hash to an array externally
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def classes
|
|
|
|
@classes.values
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# map the module hash to an array externally
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def modules
|
|
|
|
@modules.values
|
|
|
|
end
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
##
|
|
|
|
# return the classes Hash (only to be used internally)
|
|
|
|
|
|
|
|
def classes_hash
|
|
|
|
@classes
|
|
|
|
end
|
|
|
|
protected :classes_hash
|
|
|
|
|
|
|
|
##
|
|
|
|
# return the modules Hash (only to be used internally)
|
|
|
|
|
|
|
|
def modules_hash
|
|
|
|
@modules
|
|
|
|
end
|
|
|
|
protected :modules_hash
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Change the default visibility for new methods
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def ongoing_visibility=(vis)
|
|
|
|
@visibility = vis
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# Yields Method and Attr entries matching the list of names in +methods+.
|
|
|
|
# Attributes are only returned when +singleton+ is false.
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def methods_matching(methods, singleton = false)
|
2004-02-19 09:26:05 -05:00
|
|
|
count = 0
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2004-02-19 09:26:05 -05:00
|
|
|
@method_list.each do |m|
|
2008-07-17 20:46:16 -04:00
|
|
|
if methods.include? m.name and m.singleton == singleton then
|
|
|
|
yield m
|
2004-02-19 09:26:05 -05:00
|
|
|
count += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return if count == methods.size || singleton
|
|
|
|
|
|
|
|
# perhaps we need to look at attributes
|
|
|
|
|
|
|
|
@attributes.each do |a|
|
2008-07-17 20:46:16 -04:00
|
|
|
yield a if methods.include? a.name
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# Given an array +methods+ of method names, set the visibility of the
|
|
|
|
# corresponding AnyMethod object
|
|
|
|
|
|
|
|
def set_visibility_for(methods, vis, singleton = false)
|
|
|
|
methods_matching methods, singleton do |m|
|
|
|
|
m.visibility = vis
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Record the file that we happen to find it in
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def record_location(toplevel)
|
|
|
|
@in_files << toplevel unless @in_files.include?(toplevel)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return true if at least part of this thing was defined in +file+
|
|
|
|
def defined_in?(file)
|
|
|
|
@in_files.include?(file)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_class(class_type, name, superclass)
|
2008-09-24 22:43:03 -04:00
|
|
|
klass = add_class_or_module @classes, class_type, name, superclass
|
|
|
|
|
|
|
|
#
|
|
|
|
# If the parser encounters Container::Item before encountering
|
|
|
|
# Container, then it assumes that Container is a module. This
|
|
|
|
# may not be the case, so remove Container from the module list
|
|
|
|
# if present and transfer any contained classes and modules to
|
|
|
|
# the new class.
|
|
|
|
#
|
|
|
|
mod = @modules.delete(name)
|
|
|
|
|
|
|
|
if mod then
|
|
|
|
klass.classes_hash.update(mod.classes_hash)
|
|
|
|
klass.modules_hash.update(mod.modules_hash)
|
|
|
|
klass.method_list.concat(mod.method_list)
|
|
|
|
end
|
|
|
|
|
|
|
|
return klass
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_module(class_type, name)
|
|
|
|
add_class_or_module(@modules, class_type, name, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_method(a_method)
|
|
|
|
a_method.visibility = @visibility
|
|
|
|
add_to(@method_list, a_method)
|
2008-09-24 22:43:03 -04:00
|
|
|
|
|
|
|
unmatched_alias_list = @unmatched_alias_lists[a_method.name]
|
|
|
|
if unmatched_alias_list then
|
|
|
|
unmatched_alias_list.each do |unmatched_alias|
|
|
|
|
add_alias_impl unmatched_alias, a_method
|
|
|
|
@aliases.delete unmatched_alias
|
|
|
|
end
|
|
|
|
|
|
|
|
@unmatched_alias_lists.delete a_method.name
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_attribute(an_attribute)
|
|
|
|
add_to(@attributes, an_attribute)
|
|
|
|
end
|
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
def add_alias_impl(an_alias, meth)
|
|
|
|
new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
|
|
|
|
new_meth.is_alias_for = meth
|
|
|
|
new_meth.singleton = meth.singleton
|
|
|
|
new_meth.params = meth.params
|
|
|
|
new_meth.comment = "Alias for \##{meth.name}"
|
|
|
|
meth.add_alias(new_meth)
|
|
|
|
add_method(new_meth)
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def add_alias(an_alias)
|
2004-04-26 08:42:01 -04:00
|
|
|
meth = find_instance_method_named(an_alias.old_name)
|
2008-07-21 14:35:14 -04:00
|
|
|
|
|
|
|
if meth then
|
2008-09-24 22:43:03 -04:00
|
|
|
add_alias_impl(an_alias, meth)
|
2003-12-01 02:12:49 -05:00
|
|
|
else
|
|
|
|
add_to(@aliases, an_alias)
|
2008-09-24 22:43:03 -04:00
|
|
|
unmatched_alias_list = @unmatched_alias_lists[an_alias.old_name] ||= []
|
|
|
|
unmatched_alias_list.push(an_alias)
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-07-21 14:35:14 -04:00
|
|
|
|
|
|
|
an_alias
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_include(an_include)
|
|
|
|
add_to(@includes, an_include)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_constant(const)
|
|
|
|
add_to(@constants, const)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Requires always get added to the top-level (file) context
|
|
|
|
def add_require(a_require)
|
2008-07-17 20:46:16 -04:00
|
|
|
if TopLevel === self then
|
|
|
|
add_to @requires, a_require
|
2003-12-01 02:12:49 -05:00
|
|
|
else
|
2008-07-17 20:46:16 -04:00
|
|
|
parent.add_require a_require
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_class_or_module(collection, class_type, name, superclass=nil)
|
|
|
|
cls = collection[name]
|
2008-07-21 14:35:14 -04:00
|
|
|
|
|
|
|
if cls then
|
|
|
|
cls.superclass = superclass unless cls.module?
|
2007-12-24 19:13:12 -05:00
|
|
|
puts "Reusing class/module #{name}" if $DEBUG_RDOC
|
2003-12-01 02:12:49 -05:00
|
|
|
else
|
|
|
|
cls = class_type.new(name, superclass)
|
2004-10-26 10:33:17 -04:00
|
|
|
# collection[name] = cls if @document_self && !@done_documenting
|
|
|
|
collection[name] = cls if !@done_documenting
|
2003-12-01 02:12:49 -05:00
|
|
|
cls.parent = self
|
2004-11-20 10:02:57 -05:00
|
|
|
cls.section = @current_section
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
cls
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_to(array, thing)
|
2008-07-17 20:46:16 -04:00
|
|
|
array << thing if @document_self and not @done_documenting
|
2003-12-01 02:12:49 -05:00
|
|
|
thing.parent = self
|
2004-11-20 10:02:57 -05:00
|
|
|
thing.section = @current_section
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# If a class's documentation is turned off after we've started
|
|
|
|
# collecting methods etc., we need to remove the ones
|
|
|
|
# we have
|
|
|
|
|
|
|
|
def remove_methods_etc
|
|
|
|
initialize_methods_etc
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize_methods_etc
|
|
|
|
@method_list = []
|
|
|
|
@attributes = []
|
|
|
|
@aliases = []
|
|
|
|
@requires = []
|
|
|
|
@includes = []
|
|
|
|
@constants = []
|
2008-09-24 22:43:03 -04:00
|
|
|
|
|
|
|
# This Hash maps a method name to a list of unmatched
|
|
|
|
# aliases (aliases of a method not yet encountered).
|
|
|
|
@unmatched_alias_lists = {}
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
# and remove classes and modules when we see a :nodoc: all
|
|
|
|
def remove_classes_and_modules
|
|
|
|
initialize_classes_and_modules
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize_classes_and_modules
|
|
|
|
@classes = {}
|
|
|
|
@modules = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Find a named module
|
|
|
|
def find_module_named(name)
|
2008-09-24 22:43:03 -04:00
|
|
|
# First check the enclosed modules, then check the module itself,
|
|
|
|
# then check the enclosing modules (this mirrors the check done by
|
|
|
|
# the Ruby parser)
|
2003-12-01 02:12:49 -05:00
|
|
|
res = @modules[name] || @classes[name]
|
|
|
|
return res if res
|
2008-09-24 22:43:03 -04:00
|
|
|
return self if self.name == name
|
2004-01-02 01:01:12 -05:00
|
|
|
find_enclosing_module_named(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
# find a module at a higher scope
|
|
|
|
def find_enclosing_module_named(name)
|
2003-12-01 02:12:49 -05:00
|
|
|
parent && parent.find_module_named(name)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Iterate over all the classes and modules in
|
|
|
|
# this object
|
|
|
|
|
|
|
|
def each_classmodule
|
|
|
|
@modules.each_value {|m| yield m}
|
|
|
|
@classes.each_value {|c| yield c}
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_method
|
|
|
|
@method_list.each {|m| yield m}
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_attribute
|
|
|
|
@attributes.each {|a| yield a}
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_constant
|
|
|
|
@constants.each {|c| yield c}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Return the toplevel that owns us
|
|
|
|
|
|
|
|
def toplevel
|
|
|
|
return @toplevel if defined? @toplevel
|
|
|
|
@toplevel = self
|
|
|
|
@toplevel = @toplevel.parent until TopLevel === @toplevel
|
|
|
|
@toplevel
|
|
|
|
end
|
|
|
|
|
|
|
|
# allow us to sort modules by name
|
|
|
|
def <=>(other)
|
|
|
|
name <=> other.name
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# Look up +symbol+. If +method+ is non-nil, then we assume the symbol
|
|
|
|
# references a module that contains that method.
|
|
|
|
|
|
|
|
def find_symbol(symbol, method = nil)
|
2003-12-01 02:12:49 -05:00
|
|
|
result = nil
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
case symbol
|
2008-07-17 20:46:16 -04:00
|
|
|
when /^::(.*)/ then
|
2004-08-01 22:59:17 -04:00
|
|
|
result = toplevel.find_symbol($1)
|
2008-07-17 20:46:16 -04:00
|
|
|
when /::/ then
|
2003-12-01 02:12:49 -05:00
|
|
|
modules = symbol.split(/::/)
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
unless modules.empty? then
|
2003-12-01 02:12:49 -05:00
|
|
|
module_name = modules.shift
|
|
|
|
result = find_module_named(module_name)
|
2008-09-24 22:43:03 -04:00
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
if result then
|
2007-12-23 02:13:09 -05:00
|
|
|
modules.each do |name|
|
|
|
|
result = result.find_module_named(name)
|
2004-01-02 01:01:12 -05:00
|
|
|
break unless result
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
else
|
2003-12-29 22:33:35 -05:00
|
|
|
# if a method is specified, then we're definitely looking for
|
|
|
|
# a module, otherwise it could be any symbol
|
|
|
|
if method
|
|
|
|
result = find_module_named(symbol)
|
|
|
|
else
|
|
|
|
result = find_local_symbol(symbol)
|
|
|
|
if result.nil?
|
|
|
|
if symbol =~ /^[A-Z]/
|
|
|
|
result = parent
|
|
|
|
while result && result.name != symbol
|
|
|
|
result = result.parent
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
if result and method then
|
|
|
|
fail unless result.respond_to? :find_local_symbol
|
2003-12-01 02:12:49 -05:00
|
|
|
result = result.find_local_symbol(method)
|
|
|
|
end
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
result
|
|
|
|
end
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def find_local_symbol(symbol)
|
|
|
|
res = find_method_named(symbol) ||
|
|
|
|
find_constant_named(symbol) ||
|
|
|
|
find_attribute_named(symbol) ||
|
2008-07-17 20:46:16 -04:00
|
|
|
find_module_named(symbol) ||
|
|
|
|
find_file_named(symbol)
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2004-11-20 10:02:57 -05:00
|
|
|
# Handle sections
|
|
|
|
|
|
|
|
def set_current_section(title, comment)
|
|
|
|
@current_section = Section.new(title, comment)
|
|
|
|
@sections << @current_section
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
# Find a named method, or return nil
|
|
|
|
def find_method_named(name)
|
|
|
|
@method_list.find {|meth| meth.name == name}
|
|
|
|
end
|
|
|
|
|
2004-04-26 08:42:01 -04:00
|
|
|
# Find a named instance method, or return nil
|
|
|
|
def find_instance_method_named(name)
|
|
|
|
@method_list.find {|meth| meth.name == name && !meth.singleton}
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
# Find a named constant, or return nil
|
|
|
|
def find_constant_named(name)
|
|
|
|
@constants.find {|m| m.name == name}
|
|
|
|
end
|
|
|
|
|
|
|
|
# Find a named attribute, or return nil
|
|
|
|
def find_attribute_named(name)
|
|
|
|
@attributes.find {|m| m.name == name}
|
|
|
|
end
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
##
|
|
|
|
# Find a named file, or return nil
|
|
|
|
|
|
|
|
def find_file_named(name)
|
|
|
|
toplevel.class.find_file_named(name)
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# A TopLevel context is a source file
|
|
|
|
|
|
|
|
class TopLevel < Context
|
|
|
|
attr_accessor :file_stat
|
|
|
|
attr_accessor :file_relative_name
|
|
|
|
attr_accessor :file_absolute_name
|
|
|
|
attr_accessor :diagram
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
@@all_classes = {}
|
|
|
|
@@all_modules = {}
|
2008-07-17 20:46:16 -04:00
|
|
|
@@all_files = {}
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
def self.reset
|
2003-12-01 02:12:49 -05:00
|
|
|
@@all_classes = {}
|
|
|
|
@@all_modules = {}
|
2008-07-17 20:46:16 -04:00
|
|
|
@@all_files = {}
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(file_name)
|
|
|
|
super()
|
|
|
|
@name = "TopLevel"
|
2008-07-17 20:46:16 -04:00
|
|
|
@file_relative_name = file_name
|
|
|
|
@file_absolute_name = file_name
|
|
|
|
@file_stat = File.stat(file_name)
|
|
|
|
@diagram = nil
|
|
|
|
@@all_files[file_name] = self
|
|
|
|
end
|
|
|
|
|
|
|
|
def file_base_name
|
|
|
|
File.basename @file_absolute_name
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def full_name
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
##
|
|
|
|
# Adding a class or module to a TopLevel is special, as we only want one
|
|
|
|
# copy of a particular top-level class. For example, if both file A and
|
|
|
|
# file B implement class C, we only want one ClassModule object for C.
|
|
|
|
# This code arranges to share classes and modules between files.
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
def add_class_or_module(collection, class_type, name, superclass)
|
|
|
|
cls = collection[name]
|
2008-01-13 22:34:05 -05:00
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
if cls then
|
|
|
|
cls.superclass = superclass unless cls.module?
|
|
|
|
puts "Reusing class/module #{cls.full_name}" if $DEBUG_RDOC
|
2003-12-01 02:12:49 -05:00
|
|
|
else
|
2008-07-21 14:35:14 -04:00
|
|
|
if class_type == NormalModule then
|
2003-12-01 02:12:49 -05:00
|
|
|
all = @@all_modules
|
|
|
|
else
|
|
|
|
all = @@all_classes
|
|
|
|
end
|
2008-01-13 22:34:05 -05:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
cls = all[name]
|
2008-01-13 22:34:05 -05:00
|
|
|
|
2008-09-24 22:43:03 -04:00
|
|
|
if !cls then
|
2008-07-21 14:35:14 -04:00
|
|
|
cls = class_type.new name, superclass
|
2008-01-13 22:34:05 -05:00
|
|
|
all[name] = cls unless @done_documenting
|
2008-09-24 22:43:03 -04:00
|
|
|
else
|
|
|
|
# If the class has been encountered already, check that its
|
|
|
|
# superclass has been set (it may not have been, depending on
|
|
|
|
# the context in which it was encountered).
|
|
|
|
if class_type == NormalClass
|
|
|
|
if !cls.superclass then
|
|
|
|
cls.superclass = superclass
|
|
|
|
end
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-01-13 22:34:05 -05:00
|
|
|
|
2004-04-10 21:49:10 -04:00
|
|
|
collection[name] = cls unless @done_documenting
|
2008-01-13 22:34:05 -05:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
cls.parent = self
|
|
|
|
end
|
2008-01-13 22:34:05 -05:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
cls
|
|
|
|
end
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
def self.all_classes_and_modules
|
2003-12-01 02:12:49 -05:00
|
|
|
@@all_classes.values + @@all_modules.values
|
|
|
|
end
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
def self.find_class_named(name)
|
2003-12-01 02:12:49 -05:00
|
|
|
@@all_classes.each_value do |c|
|
|
|
|
res = c.find_class_named(name)
|
|
|
|
return res if res
|
|
|
|
end
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def self.find_file_named(name)
|
|
|
|
@@all_files[name]
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def find_local_symbol(symbol)
|
|
|
|
find_class_or_module_named(symbol) || super
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_class_or_module_named(symbol)
|
|
|
|
@@all_classes.each_value {|c| return c if c.name == symbol}
|
|
|
|
@@all_modules.each_value {|m| return m if m.name == symbol}
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
2008-01-13 22:34:05 -05:00
|
|
|
##
|
2004-09-11 03:11:46 -04:00
|
|
|
# Find a named module
|
2008-01-13 22:34:05 -05:00
|
|
|
|
2004-09-11 03:11:46 -04:00
|
|
|
def find_module_named(name)
|
|
|
|
find_class_or_module_named(name) || find_enclosing_module_named(name)
|
|
|
|
end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def inspect
|
|
|
|
"#<%s:0x%x %p modules: %p classes: %p>" % [
|
|
|
|
self.class, object_id,
|
|
|
|
file_base_name,
|
|
|
|
@modules.map { |n,m| m },
|
|
|
|
@classes.map { |n,c| c }
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# ClassModule is the base class for objects representing either a class or a
|
|
|
|
# module.
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
class ClassModule < Context
|
|
|
|
|
|
|
|
attr_accessor :diagram
|
|
|
|
|
|
|
|
def initialize(name, superclass = nil)
|
|
|
|
@name = name
|
|
|
|
@diagram = nil
|
|
|
|
@superclass = superclass
|
|
|
|
@comment = ""
|
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def find_class_named(name)
|
|
|
|
return self if full_name == name
|
|
|
|
@classes.each_value {|c| return c if c.find_class_named(name) }
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Return the fully qualified name of this class or module
|
2008-07-21 14:35:14 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def full_name
|
|
|
|
if @parent && @parent.full_name
|
|
|
|
@parent.full_name + "::" + @name
|
|
|
|
else
|
|
|
|
@name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def http_url(prefix)
|
|
|
|
path = full_name.split("::")
|
|
|
|
File.join(prefix, *path) + ".html"
|
|
|
|
end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
##
|
|
|
|
# Does this object represent a module?
|
|
|
|
|
|
|
|
def module?
|
2003-12-01 02:12:49 -05:00
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
##
|
|
|
|
# Get the superclass of this class. Attempts to retrieve the superclass'
|
|
|
|
# real name by following module nesting.
|
|
|
|
|
|
|
|
def superclass
|
|
|
|
raise NoMethodError, "#{full_name} is a module" if module?
|
|
|
|
|
|
|
|
scope = self
|
|
|
|
|
|
|
|
begin
|
|
|
|
superclass = scope.classes.find { |c| c.name == @superclass }
|
|
|
|
|
|
|
|
return superclass.full_name if superclass
|
|
|
|
scope = scope.parent
|
|
|
|
end until scope.nil? or TopLevel === scope
|
|
|
|
|
|
|
|
@superclass
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
##
|
|
|
|
# Set the superclass of this class
|
|
|
|
|
|
|
|
def superclass=(superclass)
|
|
|
|
raise NoMethodError, "#{full_name} is a module" if module?
|
|
|
|
|
|
|
|
if @superclass.nil? or @superclass == 'Object' then
|
|
|
|
@superclass = superclass
|
|
|
|
end
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-07-21 14:35:14 -04:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
"#{self.class}: #{@name} #{@comment} #{super}"
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Anonymous classes
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class AnonClass < ClassModule
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Normal classes
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class NormalClass < ClassModule
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
def inspect
|
|
|
|
superclass = @superclass ? " < #{@superclass}" : nil
|
|
|
|
"<%s:0x%x class %s%s includes: %p attributes: %p methods: %p aliases: %p>" % [
|
|
|
|
self.class, object_id,
|
|
|
|
@name, superclass, @includes, @attributes, @method_list, @aliases
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Singleton classes
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class SingleClass < ClassModule
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Module
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class NormalModule < ClassModule
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
def comment=(comment)
|
|
|
|
return if comment.empty?
|
|
|
|
comment = @comment << "# ---\n" << comment unless @comment.empty?
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<%s:0x%x module %s includes: %p attributes: %p methods: %p aliases: %p>" % [
|
|
|
|
self.class, object_id,
|
|
|
|
@name, @includes, @attributes, @method_list, @aliases
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
def module?
|
2003-12-01 02:12:49 -05:00
|
|
|
true
|
|
|
|
end
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-02-09 22:59:08 -05:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# AnyMethod is the base class for objects representing methods
|
|
|
|
|
|
|
|
class AnyMethod < CodeObject
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
attr_accessor :name
|
|
|
|
attr_accessor :visibility
|
|
|
|
attr_accessor :block_params
|
|
|
|
attr_accessor :dont_rename_initialize
|
|
|
|
attr_accessor :singleton
|
2008-02-09 22:59:08 -05:00
|
|
|
attr_reader :text
|
|
|
|
|
|
|
|
# list of other names for this method
|
|
|
|
attr_reader :aliases
|
|
|
|
|
|
|
|
# method we're aliasing
|
|
|
|
attr_accessor :is_alias_for
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
attr_overridable :params, :param, :parameters, :parameter
|
|
|
|
|
2003-12-23 23:24:29 -05:00
|
|
|
attr_accessor :call_seq
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
include TokenStream
|
|
|
|
|
|
|
|
def initialize(text, name)
|
|
|
|
super()
|
|
|
|
@text = text
|
|
|
|
@name = name
|
|
|
|
@token_stream = nil
|
|
|
|
@visibility = :public
|
|
|
|
@dont_rename_initialize = false
|
|
|
|
@block_params = nil
|
|
|
|
@aliases = []
|
|
|
|
@is_alias_for = nil
|
|
|
|
@comment = ""
|
2003-12-23 23:24:29 -05:00
|
|
|
@call_seq = nil
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def <=>(other)
|
|
|
|
@name <=> other.name
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def add_alias(method)
|
|
|
|
@aliases << method
|
|
|
|
end
|
|
|
|
|
|
|
|
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,
|
2008-07-21 14:35:14 -04:00
|
|
|
parent_name,
|
2008-07-17 20:46:16 -04:00
|
|
|
singleton ? '::' : '#',
|
|
|
|
name,
|
|
|
|
visibility,
|
|
|
|
alias_for,
|
|
|
|
]
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def param_seq
|
2008-07-21 14:35:14 -04:00
|
|
|
params = params.gsub(/\s*\#.*/, '')
|
|
|
|
params = params.tr("\n", " ").squeeze(" ")
|
|
|
|
params = "(#{params})" unless p[0] == ?(
|
2003-12-01 02:12:49 -05:00
|
|
|
|
2008-07-21 14:35:14 -04:00
|
|
|
if block = block_params then # yes, =
|
|
|
|
# If this method has explicit block parameters, remove any explicit
|
|
|
|
# &block
|
|
|
|
params.sub!(/,?\s*&\w+/)
|
2004-05-05 13:02:47 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
block.gsub!(/\s*\#.*/, '')
|
|
|
|
block = block.tr("\n", " ").squeeze(" ")
|
|
|
|
if block[0] == ?(
|
|
|
|
block.sub!(/^\(/, '').sub!(/\)/, '')
|
|
|
|
end
|
2008-07-21 14:35:14 -04:00
|
|
|
params << " { |#{block}| ... }"
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-07-21 14:35:14 -04:00
|
|
|
|
|
|
|
params
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def to_s
|
|
|
|
res = self.class.name + ": " + @name + " (" + @text + ")\n"
|
|
|
|
res << @comment.to_s
|
|
|
|
res
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# GhostMethod represents a method referenced only by a comment
|
|
|
|
|
|
|
|
class GhostMethod < AnyMethod
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# MetaMethod represents a meta-programmed method
|
|
|
|
|
|
|
|
class MetaMethod < AnyMethod
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# Represent an alias, which is an old_name/ new_name pair associated with a
|
|
|
|
# particular context
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class Alias < CodeObject
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
attr_accessor :text, :old_name, :new_name, :comment
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def initialize(text, old_name, new_name, comment)
|
|
|
|
super()
|
|
|
|
@text = text
|
|
|
|
@old_name = old_name
|
|
|
|
@new_name = new_name
|
|
|
|
self.comment = comment
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def inspect
|
|
|
|
"#<%s:0x%x %s.alias_method %s, %s>" % [
|
|
|
|
self.class, object_id,
|
|
|
|
parent.name, @old_name, @new_name,
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def to_s
|
|
|
|
"alias: #{self.old_name} -> #{self.new_name}\n#{self.comment}"
|
|
|
|
end
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Represent a constant
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class Constant < CodeObject
|
|
|
|
attr_accessor :name, :value
|
|
|
|
|
|
|
|
def initialize(name, value, comment)
|
|
|
|
super()
|
|
|
|
@name = name
|
|
|
|
@value = value
|
|
|
|
self.comment = comment
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
2003-12-01 02:12:49 -05:00
|
|
|
# Represent attributes
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class Attr < CodeObject
|
2004-02-19 09:26:05 -05:00
|
|
|
attr_accessor :text, :name, :rw, :visibility
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
def initialize(text, name, rw, comment)
|
|
|
|
super()
|
|
|
|
@text = text
|
|
|
|
@name = name
|
|
|
|
@rw = rw
|
2004-02-19 09:26:05 -05:00
|
|
|
@visibility = :public
|
2003-12-01 02:12:49 -05:00
|
|
|
self.comment = comment
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def <=>(other)
|
|
|
|
self.name <=> other.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
attr = case rw
|
|
|
|
when 'RW' then :attr_accessor
|
|
|
|
when 'R' then :attr_reader
|
|
|
|
when 'W' then :attr_writer
|
|
|
|
else
|
|
|
|
" (#{rw})"
|
|
|
|
end
|
|
|
|
|
|
|
|
"#<%s:0x%x %s.%s :%s>" % [
|
|
|
|
self.class, object_id,
|
2008-07-21 14:35:14 -04:00
|
|
|
parent_name, attr, @name,
|
2008-07-17 20:46:16 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
def to_s
|
|
|
|
"attr: #{self.name} #{self.rw}\n#{self.comment}"
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# A required file
|
2003-12-01 02:12:49 -05:00
|
|
|
|
|
|
|
class Require < CodeObject
|
|
|
|
attr_accessor :name
|
|
|
|
|
|
|
|
def initialize(name, comment)
|
|
|
|
super()
|
|
|
|
@name = name.gsub(/'|"/, "") #'
|
|
|
|
self.comment = comment
|
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
def inspect
|
|
|
|
"#<%s:0x%x require '%s' in %s>" % [
|
|
|
|
self.class,
|
|
|
|
object_id,
|
|
|
|
@name,
|
2008-07-21 14:35:14 -04:00
|
|
|
parent_file_name,
|
2008-07-17 20:46:16 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# An included module
|
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
class Include < CodeObject
|
2008-07-17 20:46:16 -04:00
|
|
|
|
2003-12-01 02:12:49 -05:00
|
|
|
attr_accessor :name
|
|
|
|
|
|
|
|
def initialize(name, comment)
|
|
|
|
super()
|
|
|
|
@name = name
|
|
|
|
self.comment = comment
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
|
|
|
"#<%s:0x%x %s.include %s>" % [
|
|
|
|
self.class,
|
|
|
|
object_id,
|
2008-07-21 14:35:14 -04:00
|
|
|
parent_name, @name,
|
2008-07-17 20:46:16 -04:00
|
|
|
]
|
2003-12-01 02:12:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|