| Class | RDoc::Context |
| In: |
code_objects.rb
parsers/parse_f95.rb doc-tmp/rdoc/code_objects.rb |
| Parent: | CodeObject |
# File doc-tmp/rdoc/code_objects.rb, line 163
163: def initialize
164: super()
165:
166: @in_files = []
167:
168: @name ||= "unknown"
169: @comment ||= ""
170: @parent = nil
171: @visibility = :public
172:
173: @current_section = Section.new(nil, nil)
174: @sections = [ @current_section ]
175:
176: initialize_methods_etc
177: initialize_classes_and_modules
178: end
# File code_objects.rb, line 163
163: def initialize
164: super()
165:
166: @in_files = []
167:
168: @name ||= "unknown"
169: @comment ||= ""
170: @parent = nil
171: @visibility = :public
172:
173: @current_section = Section.new(nil, nil)
174: @sections = [ @current_section ]
175:
176: initialize_methods_etc
177: initialize_classes_and_modules
178: end
# File doc-tmp/rdoc/code_objects.rb, line 247
247: def add_alias(an_alias)
248: meth = find_instance_method_named(an_alias.old_name)
249: if meth
250: new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
251: new_meth.is_alias_for = meth
252: new_meth.singleton = meth.singleton
253: new_meth.params = meth.params
254: new_meth.comment = "Alias for \##{meth.name}"
255: meth.add_alias(new_meth)
256: add_method(new_meth)
257: else
258: add_to(@aliases, an_alias)
259: end
260: end
# File code_objects.rb, line 247
247: def add_alias(an_alias)
248: meth = find_instance_method_named(an_alias.old_name)
249: if meth
250: new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
251: new_meth.is_alias_for = meth
252: new_meth.singleton = meth.singleton
253: new_meth.params = meth.params
254: new_meth.comment = "Alias for \##{meth.name}"
255: meth.add_alias(new_meth)
256: add_method(new_meth)
257: else
258: add_to(@aliases, an_alias)
259: end
260: end
# File parsers/parse_f95.rb, line 557
557: def add_alias(an_alias, ignore_case=nil)
558: meth = find_instance_method_named(an_alias.old_name, ignore_case)
559: if meth
560: new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
561: new_meth.is_alias_for = meth
562: new_meth.singleton = meth.singleton
563: new_meth.params = meth.params
564: new_meth.comment = "Alias for \##{meth.name}"
565: meth.add_alias(new_meth)
566: add_method(new_meth)
567: else
568: add_to(@aliases, an_alias)
569: end
570: end
# File doc-tmp/rdoc/code_objects.rb, line 243
243: def add_attribute(an_attribute)
244: add_to(@attributes, an_attribute)
245: end
# File code_objects.rb, line 243
243: def add_attribute(an_attribute)
244: add_to(@attributes, an_attribute)
245: end
# File doc-tmp/rdoc/code_objects.rb, line 229
229: def add_class(class_type, name, superclass)
230: add_class_or_module(@classes, class_type, name, superclass)
231: end
# File code_objects.rb, line 229
229: def add_class(class_type, name, superclass)
230: add_class_or_module(@classes, class_type, name, superclass)
231: end
# File code_objects.rb, line 279
279: def add_class_or_module(collection, class_type, name, superclass=nil)
280: cls = collection[name]
281: if cls
282: puts "Reusing class/module #{name}" if $DEBUG_RDOC
283: else
284: cls = class_type.new(name, superclass)
285: puts "Adding class/module #{name} to #@name" if $DEBUG_RDOC
286: # collection[name] = cls if @document_self && !@done_documenting
287: collection[name] = cls if !@done_documenting
288: cls.parent = self
289: cls.section = @current_section
290: end
291: cls
292: end
# File doc-tmp/rdoc/code_objects.rb, line 279
279: def add_class_or_module(collection, class_type, name, superclass=nil)
280: cls = collection[name]
281: if cls
282: puts "Reusing class/module #{name}" if $DEBUG_RDOC
283: else
284: cls = class_type.new(name, superclass)
285: puts "Adding class/module #{name} to #@name" if $DEBUG_RDOC
286: # collection[name] = cls if @document_self && !@done_documenting
287: collection[name] = cls if !@done_documenting
288: cls.parent = self
289: cls.section = @current_section
290: end
291: cls
292: end
# File doc-tmp/rdoc/code_objects.rb, line 266
266: def add_constant(const)
267: add_to(@constants, const)
268: end
# File code_objects.rb, line 266
266: def add_constant(const)
267: add_to(@constants, const)
268: end
# File code_objects.rb, line 262
262: def add_include(an_include)
263: add_to(@includes, an_include)
264: end
# File doc-tmp/rdoc/code_objects.rb, line 262
262: def add_include(an_include)
263: add_to(@includes, an_include)
264: end
# File parsers/parse_f95.rb, line 547
547: def add_method(a_method)
548: if !(a_method.visibility == :public) &&
549: !(a_method.visibility == :private) &&
550: !(a_method.visibility == :protected)
551: a_method.visibility = @visibility
552: end
553: puts "Adding #{a_method.visibility} method #{a_method.name} to #@name" if $DEBUG_RDOC
554: add_to(@method_list, a_method)
555: end
# File code_objects.rb, line 237
237: def add_method(a_method)
238: puts "Adding #@visibility method #{a_method.name} to #@name" if $DEBUG_RDOC
239: a_method.visibility = @visibility
240: add_to(@method_list, a_method)
241: end
# File doc-tmp/rdoc/code_objects.rb, line 237
237: def add_method(a_method)
238: puts "Adding #@visibility method #{a_method.name} to #@name" if $DEBUG_RDOC
239: a_method.visibility = @visibility
240: add_to(@method_list, a_method)
241: end
# File code_objects.rb, line 233
233: def add_module(class_type, name)
234: add_class_or_module(@modules, class_type, name, nil)
235: end
# File doc-tmp/rdoc/code_objects.rb, line 233
233: def add_module(class_type, name)
234: add_class_or_module(@modules, class_type, name, nil)
235: end
Requires always get added to the top-level (file) context
# File code_objects.rb, line 271
271: def add_require(a_require)
272: if self.kind_of? TopLevel
273: add_to(@requires, a_require)
274: else
275: parent.add_require(a_require)
276: end
277: end
Requires always get added to the top-level (file) context
# File doc-tmp/rdoc/code_objects.rb, line 271
271: def add_require(a_require)
272: if self.kind_of? TopLevel
273: add_to(@requires, a_require)
274: else
275: parent.add_require(a_require)
276: end
277: end
# File doc-tmp/rdoc/code_objects.rb, line 294
294: def add_to(array, thing)
295: array << thing if @document_self && !@done_documenting
296: thing.parent = self
297: thing.section = @current_section
298: end
# File code_objects.rb, line 294
294: def add_to(array, thing)
295: array << thing if @document_self && !@done_documenting
296: thing.parent = self
297: thing.section = @current_section
298: end
map the class hash to an array externally
# File doc-tmp/rdoc/code_objects.rb, line 181
181: def classes
182: @classes.values
183: end
map the class hash to an array externally
# File code_objects.rb, line 181
181: def classes
182: @classes.values
183: end
Return true if at least part of this thing was defined in file
# File doc-tmp/rdoc/code_objects.rb, line 225
225: def defined_in?(file)
226: @in_files.include?(file)
227: end
Return true if at least part of this thing was defined in file
# File code_objects.rb, line 225
225: def defined_in?(file)
226: @in_files.include?(file)
227: end
# File code_objects.rb, line 352
352: def each_attribute
353: @attributes.each {|a| yield a}
354: end
# File doc-tmp/rdoc/code_objects.rb, line 352
352: def each_attribute
353: @attributes.each {|a| yield a}
354: end
# File doc-tmp/rdoc/code_objects.rb, line 356
356: def each_constant
357: @constants.each {|c| yield c}
358: end
# File parsers/parse_f95.rb, line 603
603: def each_includes
604: @includes.each {|i| yield i}
605: end
# File doc-tmp/rdoc/code_objects.rb, line 348
348: def each_method
349: @method_list.each {|m| yield m}
350: end
Find a named attribute, or return nil
# File code_objects.rb, line 454
454: def find_attribute_named(name)
455: @attributes.find {|m| m.name == name}
456: end
Find a named attribute, or return nil
# File doc-tmp/rdoc/code_objects.rb, line 454
454: def find_attribute_named(name)
455: @attributes.find {|m| m.name == name}
456: end
Find a named attribute, or return nil
# File parsers/parse_f95.rb, line 722
722: def find_attribute_named(name, ignore_case=nil)
723: if !ignore_case
724: @attributes.find {|m| m.name == name}
725: else
726: @attributes.find {|m| m.name.upcase == name.upcase}
727: end
728: end
Find a named constant, or return nil
# File doc-tmp/rdoc/code_objects.rb, line 449
449: def find_constant_named(name)
450: @constants.find {|m| m.name == name}
451: end
Find a named constant, or return nil
# File code_objects.rb, line 449
449: def find_constant_named(name)
450: @constants.find {|m| m.name == name}
451: end
Find a named constant, or return nil
# File parsers/parse_f95.rb, line 713
713: def find_constant_named(name, ignore_case=nil)
714: if !ignore_case
715: @constants.find {|m| m.name == name}
716: else
717: @constants.find {|m| m.name.upcase == name.upcase}
718: end
719: end
find a module at a higher scope
# File code_objects.rb, line 336
336: def find_enclosing_module_named(name)
337: parent && parent.find_module_named(name)
338: end
find a module at a higher scope
# File doc-tmp/rdoc/code_objects.rb, line 336
336: def find_enclosing_module_named(name)
337: parent && parent.find_module_named(name)
338: end
find a module at a higher scope
# File parsers/parse_f95.rb, line 599
599: def find_enclosing_module_named(name, ignore_case=nil)
600: parent && parent.find_module_named(name, ignore_case)
601: end
Look up the given filename.
# File parsers/parse_f95.rb, line 608
608: def find_file(file, method=nil, ignore_case=nil)
609: find_file_named(file, method, ignore_case)
610: end
Find a named instance method, or return nil
# File doc-tmp/rdoc/code_objects.rb, line 444
444: def find_instance_method_named(name)
445: @method_list.find {|meth| meth.name == name && !meth.singleton}
446: end
Find a named instance method, or return nil
# File code_objects.rb, line 444
444: def find_instance_method_named(name)
445: @method_list.find {|meth| meth.name == name && !meth.singleton}
446: end
Find a named instance method, or return nil
# File parsers/parse_f95.rb, line 702
702: def find_instance_method_named(name, ignore_case=nil)
703: if !ignore_case
704: @method_list.find {|meth| meth.name == name && !meth.singleton}
705: else
706: @method_list.find {|meth|
707: meth.name.upcase == name.upcase && !meth.singleton
708: }
709: end
710: end
# File code_objects.rb, line 422
422: def find_local_symbol(symbol)
423: res = find_method_named(symbol) ||
424: find_constant_named(symbol) ||
425: find_attribute_named(symbol) ||
426: find_module_named(symbol)
427: end
# File doc-tmp/rdoc/code_objects.rb, line 422
422: def find_local_symbol(symbol)
423: res = find_method_named(symbol) ||
424: find_constant_named(symbol) ||
425: find_attribute_named(symbol) ||
426: find_module_named(symbol)
427: end
# File parsers/parse_f95.rb, line 661
661: def find_local_symbol(symbol, ignore_case=nil)
662: res = find_method_named(symbol, ignore_case) ||
663: find_constant_named(symbol, ignore_case) ||
664: find_attribute_named(symbol, ignore_case) ||
665: find_module_named(symbol, ignore_case)
666: end
Find a named method, or return nil
# File code_objects.rb, line 439
439: def find_method_named(name)
440: @method_list.find {|meth| meth.name == name}
441: end
Find a named method, or return nil
# File doc-tmp/rdoc/code_objects.rb, line 439
439: def find_method_named(name)
440: @method_list.find {|meth| meth.name == name}
441: end
Find a named method, or return nil
# File parsers/parse_f95.rb, line 693
693: def find_method_named(name, ignore_case=nil)
694: if !ignore_case
695: @method_list.find {|meth| meth.name == name}
696: else
697: @method_list.find {|meth| meth.name.upcase == name.upcase}
698: end
699: end
Find a named module
# File doc-tmp/rdoc/code_objects.rb, line 328
328: def find_module_named(name)
329: return self if self.name == name
330: res = @modules[name] || @classes[name]
331: return res if res
332: find_enclosing_module_named(name)
333: end
Find a named module
# File code_objects.rb, line 328
328: def find_module_named(name)
329: return self if self.name == name
330: res = @modules[name] || @classes[name]
331: return res if res
332: find_enclosing_module_named(name)
333: end
Find a named module
# File parsers/parse_f95.rb, line 573
573: def find_module_named(name, ignore_case=nil)
574: res = nil
575: if !ignore_case
576: return self if self.name == name
577: else
578: return self if self.name.upcase == name.upcase
579: end
580: if !ignore_case
581: res = @modules[name] || @classes[name]
582: else
583: @modules.each{ |n, v|
584: if n.upcase == name.upcase
585: res = v ; break
586: end
587: }
588: @classes.each{ |n, v|
589: if n.upcase == name.upcase
590: res = v ; break
591: end
592: } if !res
593: end
594: return res if res
595: find_enclosing_module_named(name, ignore_case)
596: end
Look up the given symbol. If method is non-nil, then we assume the symbol references a module that contains that method
# File doc-tmp/rdoc/code_objects.rb, line 377
377: def find_symbol(symbol, method=nil)
378: result = nil
379: case symbol
380: when /^::(.*)/
381: result = toplevel.find_symbol($1)
382: when /::/
383: modules = symbol.split(/::/)
384: unless modules.empty?
385: module_name = modules.shift
386: result = find_module_named(module_name)
387: if result
388: modules.each do |name|
389: result = result.find_module_named(name)
390: break unless result
391: end
392: end
393: end
394: else
395: # if a method is specified, then we're definitely looking for
396: # a module, otherwise it could be any symbol
397: if method
398: result = find_module_named(symbol)
399: else
400: result = find_local_symbol(symbol)
401: if result.nil?
402: if symbol =~ /^[A-Z]/
403: result = parent
404: while result && result.name != symbol
405: result = result.parent
406: end
407: end
408: end
409: end
410: end
411: if result && method
412: if !result.respond_to?(:find_local_symbol)
413: p result.name
414: p method
415: fail
416: end
417: result = result.find_local_symbol(method)
418: end
419: result
420: end
Look up the given symbol. If method is non-nil, then we assume the symbol references a module that contains that method
# File code_objects.rb, line 377
377: def find_symbol(symbol, method=nil)
378: result = nil
379: case symbol
380: when /^::(.*)/
381: result = toplevel.find_symbol($1)
382: when /::/
383: modules = symbol.split(/::/)
384: unless modules.empty?
385: module_name = modules.shift
386: result = find_module_named(module_name)
387: if result
388: modules.each do |name|
389: result = result.find_module_named(name)
390: break unless result
391: end
392: end
393: end
394: else
395: # if a method is specified, then we're definitely looking for
396: # a module, otherwise it could be any symbol
397: if method
398: result = find_module_named(symbol)
399: else
400: result = find_local_symbol(symbol)
401: if result.nil?
402: if symbol =~ /^[A-Z]/
403: result = parent
404: while result && result.name != symbol
405: result = result.parent
406: end
407: end
408: end
409: end
410: end
411: if result && method
412: if !result.respond_to?(:find_local_symbol)
413: p result.name
414: p method
415: fail
416: end
417: result = result.find_local_symbol(method)
418: end
419: result
420: end
Look up the given symbol. If method is non-nil, then we assume the symbol references a module that contains that method
# File parsers/parse_f95.rb, line 615
615: def find_symbol(symbol, method=nil, ignore_case=nil)
616: result = nil
617: case symbol
618: when /^::(.*)/
619: result = toplevel.find_symbol($1, nil, ignore_case)
620: when /::/
621: modules = symbol.split(/::/)
622: unless modules.empty?
623: module_name = modules.shift
624: result = find_module_named(module_name, ignore_case)
625: if result
626: modules.each do |module_name|
627: result = result.find_module_named(module_name, ignore_case)
628: break unless result
629: end
630: end
631: end
632: else
633: # if a method is specified, then we're definitely looking for
634: # a module, otherwise it could be any symbol
635: if method
636: result = find_module_named(symbol, ignore_case)
637: else
638: result = find_local_symbol(symbol, ignore_case)
639: if result.nil?
640: if symbol =~ /^[A-Z]/ ||
641: symbol =~ /^[A-Za-z]/ && ignore_case
642: result = parent
643: while result && result.name != symbol
644: result = result.parent
645: end
646: end
647: end
648: end
649: end
650: if result && method
651: if !result.respond_to?(:find_local_symbol)
652: p result.name
653: p method
654: fail
655: end
656: result = result.find_local_symbol(method, ignore_case)
657: end
658: result
659: end
# File parsers/parse_f95.rb, line 682
682: def include_includes?(name, ignore_case=nil)
683: self.includes.each{|i|
684: if i.name == name ||
685: i.name.upcase == name.upcase && ignore_case
686: return true
687: end
688: }
689: return false
690: end
# File parsers/parse_f95.rb, line 668
668: def include_requires?(name, ignore_case=nil)
669: if self.kind_of? TopLevel
670: self.requires.each{|r|
671: if r.name == name ||
672: r.name.upcase == name.upcase && ignore_case
673: return true
674: end
675: }
676: return false
677: else
678: parent.include_requires?(name)
679: end
680: end
# File doc-tmp/rdoc/code_objects.rb, line 322
322: def initialize_classes_and_modules
323: @classes = {}
324: @modules = {}
325: end
# File code_objects.rb, line 322
322: def initialize_classes_and_modules
323: @classes = {}
324: @modules = {}
325: end
# File doc-tmp/rdoc/code_objects.rb, line 308
308: def initialize_methods_etc
309: @method_list = []
310: @attributes = []
311: @aliases = []
312: @requires = []
313: @includes = []
314: @constants = []
315: end
# File code_objects.rb, line 308
308: def initialize_methods_etc
309: @method_list = []
310: @attributes = []
311: @aliases = []
312: @requires = []
313: @includes = []
314: @constants = []
315: end
map the module hash to an array externally
# File doc-tmp/rdoc/code_objects.rb, line 186
186: def modules
187: @modules.values
188: end
map the module hash to an array externally
# File code_objects.rb, line 186
186: def modules
187: @modules.values
188: end
Record the file that we happen to find it in
# File code_objects.rb, line 220
220: def record_location(toplevel)
221: @in_files << toplevel unless @in_files.include?(toplevel)
222: end
Record the file that we happen to find it in
# File doc-tmp/rdoc/code_objects.rb, line 220
220: def record_location(toplevel)
221: @in_files << toplevel unless @in_files.include?(toplevel)
222: end
If a class‘s documentation is turned off after we‘ve started collecting methods etc., we need to remove the ones we have
# File doc-tmp/rdoc/code_objects.rb, line 304
304: def remove_methods_etc
305: initialize_methods_etc
306: end
If a class‘s documentation is turned off after we‘ve started collecting methods etc., we need to remove the ones we have
# File code_objects.rb, line 304
304: def remove_methods_etc
305: initialize_methods_etc
306: end
Handle sections
# File code_objects.rb, line 431
431: def set_current_section(title, comment)
432: @current_section = Section.new(title, comment)
433: @sections << @current_section
434: end
Handle sections
# File doc-tmp/rdoc/code_objects.rb, line 431
431: def set_current_section(title, comment)
432: @current_section = Section.new(title, comment)
433: @sections << @current_section
434: end
Given an array methods of method names, set the visibility of the corresponding AnyMethod object
# File doc-tmp/rdoc/code_objects.rb, line 198
198: def set_visibility_for(methods, vis, singleton=false)
199: count = 0
200: @method_list.each do |m|
201: if methods.include?(m.name) && m.singleton == singleton
202: m.visibility = vis
203: count += 1
204: end
205: end
206:
207: return if count == methods.size || singleton
208:
209: # perhaps we need to look at attributes
210:
211: @attributes.each do |a|
212: if methods.include?(a.name)
213: a.visibility = vis
214: count += 1
215: end
216: end
217: end
Given an array methods of method names, set the visibility of the corresponding AnyMethod object
# File code_objects.rb, line 198
198: def set_visibility_for(methods, vis, singleton=false)
199: count = 0
200: @method_list.each do |m|
201: if methods.include?(m.name) && m.singleton == singleton
202: m.visibility = vis
203: count += 1
204: end
205: end
206:
207: return if count == methods.size || singleton
208:
209: # perhaps we need to look at attributes
210:
211: @attributes.each do |a|
212: if methods.include?(a.name)
213: a.visibility = vis
214: count += 1
215: end
216: end
217: end