Class RDoc::Context
In: code_objects.rb
parsers/parse_f95.rb
Parent: CodeObject

Extend Context class for parse_f95.rb Original class is defined in code_objects.rb.

Methods

Classes and Modules

Class RDoc::Context::Section

Attributes

aliases  [R] 
attributes  [R] 
constants  [R] 
in_files  [R] 
includes  [R] 
method_list  [R] 
name  [R] 
requires  [R] 
sections  [R] 
visibility  [R] 

Public Class methods

[Source]

     # 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

Public Instance methods

allow us to sort modules by name

[Source]

     # File code_objects.rb, line 414
414:     def <=>(other)
415:       name <=> other.name
416:     end

[Source]

     # File parsers/parse_f95.rb, line 381
381:     def add_alias(an_alias, ignore_case=nil)
382:       meth = find_instance_method_named(an_alias.old_name, ignore_case)
383:       if meth
384:         new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
385:         new_meth.is_alias_for = meth
386:         new_meth.singleton    = meth.singleton
387:         new_meth.params       = meth.params
388:         new_meth.comment = "Alias for \##{meth.name}"
389:         meth.add_alias(new_meth)
390:         add_method(new_meth)
391:       else
392:         add_to(@aliases, an_alias)
393:       end
394:     end

[Source]

     # File code_objects.rb, line 247
247:     def add_attribute(an_attribute)
248:       add_to(@attributes, an_attribute)
249:     end

[Source]

     # 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

[Source]

     # File code_objects.rb, line 289
289:     def add_class_or_module(collection, class_type, name, superclass=nil)
290:       cls = collection[name]
291:       if cls
292:         puts "Reusing class/module #{name}" if $DEBUG
293:       else
294:         cls = class_type.new(name, superclass)
295:         puts "Adding class/module #{name} to #@name" if $DEBUG
296: #        collection[name] = cls if @document_self  && !@done_documenting
297:         collection[name] = cls if !@done_documenting
298:         cls.parent = self
299:         cls.section = @current_section
300:       end
301:       cls
302:     end

[Source]

     # File code_objects.rb, line 276
276:     def add_constant(const)
277:       add_to(@constants, const)
278:     end
 moved to parse_f95.rb #

!# !# def add_alias(an_alias, ignore_case=nil) !# meth = find_instance_method_named(an_alias.old_name, ignore_case) !# if 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) !# else !# add_to(@aliases, an_alias) !# end !# end !#

 moved to parse_f95.rb #

[Source]

     # File code_objects.rb, line 272
272:     def add_include(an_include)
273:       add_to(@includes, an_include)
274:     end

[Source]

     # File code_objects.rb, line 237
237:     def add_method(a_method)
238:       if !(a_method.visibility == :public)      &&
239:            !(a_method.visibility == :private)   &&
240:            !(a_method.visibility == :protected)
241:         a_method.visibility = @visibility
242:       end
243:       puts "Adding #{a_method.visibility} method #{a_method.name} to #@name" if $DEBUG
244:       add_to(@method_list, a_method)
245:     end

[Source]

     # 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

Requires always get added to the top-level (file) context

[Source]

     # File code_objects.rb, line 281
281:     def add_require(a_require)
282:       if self.kind_of? TopLevel
283:         add_to(@requires, a_require)
284:       else
285:         parent.add_require(a_require)
286:       end
287:     end

[Source]

     # File code_objects.rb, line 304
304:     def add_to(array, thing)
305:       array <<  thing if @document_self  && !@done_documenting
306:       thing.parent = self
307:       thing.section = @current_section
308:     end

map the class hash to an array externally

[Source]

     # 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

[Source]

     # File code_objects.rb, line 225
225:     def defined_in?(file)
226:       @in_files.include?(file)
227:     end

[Source]

     # File code_objects.rb, line 386
386:     def each_attribute 
387:       @attributes.each {|a| yield a}
388:     end

Iterate over all the classes and modules in this object

[Source]

     # File code_objects.rb, line 377
377:     def each_classmodule
378:       @modules.each_value {|m| yield m}
379:       @classes.each_value {|c| yield c}
380:     end

[Source]

     # File code_objects.rb, line 390
390:     def each_constant
391:       @constants.each {|c| yield c}
392:     end

[Source]

     # File parsers/parse_f95.rb, line 427
427:     def each_includes
428:       @includes.each {|i| yield i}
429:     end

[Source]

     # File code_objects.rb, line 382
382:     def each_method
383:       @method_list.each {|m| yield m}
384:     end

Find a named attribute, or return nil

[Source]

     # File parsers/parse_f95.rb, line 546
546:     def find_attribute_named(name, ignore_case=nil)
547:       if !ignore_case
548:         @attributes.find {|m| m.name == name}
549:       else
550:         @attributes.find {|m| m.name.upcase == name.upcase}
551:       end
552:     end

Find a named constant, or return nil

[Source]

     # File parsers/parse_f95.rb, line 537
537:     def find_constant_named(name, ignore_case=nil)
538:       if !ignore_case
539:         @constants.find {|m| m.name == name}
540:       else
541:         @constants.find {|m| m.name.upcase == name.upcase}
542:       end
543:     end

find a module at a higher scope

[Source]

     # File parsers/parse_f95.rb, line 423
423:     def find_enclosing_module_named(name, ignore_case=nil)
424:       parent && parent.find_module_named(name, ignore_case)
425:     end

Look up the given filename.

[Source]

     # File parsers/parse_f95.rb, line 432
432:     def find_file(file, method=nil, ignore_case=nil)
433:       find_file_named(file, method, ignore_case)
434:     end

Find a named instance method, or return nil

[Source]

     # File parsers/parse_f95.rb, line 526
526:     def find_instance_method_named(name, ignore_case=nil)
527:       if !ignore_case
528:         @method_list.find {|meth| meth.name == name && !meth.singleton}
529:       else
530:         @method_list.find {|meth| 
531:           meth.name.upcase == name.upcase && !meth.singleton
532:         } 
533:       end
534:     end

[Source]

     # File parsers/parse_f95.rb, line 485
485:     def find_local_symbol(symbol, ignore_case=nil)
486:       res = find_method_named(symbol, ignore_case) ||
487:             find_constant_named(symbol, ignore_case) ||
488:             find_attribute_named(symbol, ignore_case) ||
489:             find_module_named(symbol, ignore_case) 
490:     end

Find a named method, or return nil

[Source]

     # File parsers/parse_f95.rb, line 517
517:     def find_method_named(name, ignore_case=nil)
518:       if !ignore_case
519:         @method_list.find {|meth| meth.name == name}
520:       else
521:         @method_list.find {|meth| meth.name.upcase == name.upcase}
522:       end
523:     end

Find a named module

[Source]

     # File parsers/parse_f95.rb, line 397
397:     def find_module_named(name, ignore_case=nil)
398:       res = nil
399:       if !ignore_case
400:         return self if self.name == name
401:       else
402:         return self if self.name.upcase == name.upcase
403:       end
404:       if !ignore_case
405:         res = @modules[name] || @classes[name]
406:       else
407:         @modules.each{ |n, v|
408:           if n.upcase == name.upcase
409:             res = v ; break
410:           end
411:         }
412:         @classes.each{ |n, v|
413:           if n.upcase == name.upcase
414:             res = v ; break
415:           end
416:         } if !res
417:       end
418:       return res if res
419:       find_enclosing_module_named(name, ignore_case)
420:     end

Look up the given symbol. If method is non-nil, then we assume the symbol references a module that contains that method

[Source]

     # File parsers/parse_f95.rb, line 439
439:     def find_symbol(symbol, method=nil, ignore_case=nil)
440:       result = nil
441:       case symbol
442:       when /^::(.*)/
443:         result = toplevel.find_symbol($1, nil, ignore_case)
444:       when /::/
445:         modules = symbol.split(/::/)
446:         unless modules.empty?
447:           module_name = modules.shift
448:           result = find_module_named(module_name, ignore_case)
449:           if result
450:             modules.each do |module_name|
451:               result = result.find_module_named(module_name, ignore_case)
452:               break unless result
453:             end
454:           end
455:         end
456:       else
457:         # if a method is specified, then we're definitely looking for
458:         # a module, otherwise it could be any symbol
459:         if method
460:           result = find_module_named(symbol, ignore_case)
461:         else
462:           result = find_local_symbol(symbol, ignore_case)
463:           if result.nil?
464:             if symbol =~ /^[A-Z]/ ||
465:                        symbol =~ /^[A-Za-z]/ && ignore_case
466:               result = parent
467:               while result && result.name != symbol
468:                 result = result.parent
469:               end
470:             end
471:           end
472:         end
473:       end
474:       if result && method
475:         if !result.respond_to?(:find_local_symbol)
476:           p result.name
477:           p method
478:           fail
479:         end
480:         result = result.find_local_symbol(method, ignore_case)
481:       end
482:       result
483:     end

[Source]

     # File parsers/parse_f95.rb, line 506
506:     def include_includes?(name, ignore_case=nil)
507:       self.includes.each{|i|
508:         if i.name == name ||
509:             i.name.upcase == name.upcase && ignore_case
510:           return true
511:         end
512:       }
513:       return false
514:     end

[Source]

     # File parsers/parse_f95.rb, line 492
492:     def include_requires?(name, ignore_case=nil)
493:       if self.kind_of? TopLevel
494:         self.requires.each{|r|
495:           if r.name == name ||
496:               r.name.upcase == name.upcase && ignore_case
497:             return true
498:           end
499:         }
500:         return false
501:       else
502:         parent.include_requires?(name)
503:       end
504:     end

[Source]

     # File code_objects.rb, line 332
332:     def initialize_classes_and_modules
333:       @classes     = {}
334:       @modules     = {}
335:     end

[Source]

     # File code_objects.rb, line 318
318:     def initialize_methods_etc
319:       @method_list = []
320:       @attributes  = []
321:       @aliases     = []
322:       @requires    = []
323:       @includes    = []
324:       @constants   = []
325:     end

map the module hash to an array externally

[Source]

     # File code_objects.rb, line 186
186:     def modules
187:       @modules.values
188:     end

Change the default visibility for new methods

[Source]

     # File code_objects.rb, line 191
191:     def ongoing_visibility=(vis)
192:       @visibility = vis
193:     end

Record the file that we happen to find it in

[Source]

     # File code_objects.rb, line 220
220:     def record_location(toplevel)
221:       @in_files << toplevel unless @in_files.include?(toplevel)
222:     end

and remove classes and modules when we see a :nodoc: all

[Source]

     # File code_objects.rb, line 328
328:     def remove_classes_and_modules
329:       initialize_classes_and_modules
330:     end

If a class‘s documentation is turned off after we‘ve started collecting methods etc., we need to remove the ones we have

[Source]

     # File code_objects.rb, line 314
314:     def remove_methods_etc
315:       initialize_methods_etc
316:     end

Handle sections

[Source]

     # File code_objects.rb, line 511
511:     def set_current_section(title, comment)
512:       @current_section = Section.new(title, comment)
513:       @sections << @current_section
514:     end

Given an array methods of method names, set the visibility of the corresponding AnyMethod object

[Source]

     # 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

Return the toplevel that owns us

[Source]

     # File code_objects.rb, line 406
406:     def toplevel
407:       return @toplevel if defined? @toplevel
408:       @toplevel = self
409:       @toplevel = @toplevel.parent until TopLevel === @toplevel
410:       @toplevel
411:     end

[Validate]