| 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.
| aliases | [R] | |
| attributes | [R] | |
| constants | [R] | |
| in_files | [R] | |
| includes | [R] | |
| method_list | [R] | |
| name | [R] | |
| requires | [R] | |
| sections | [R] | |
| visibility | [R] |
# 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 code_objects.rb, line 263
263: def add_alias(an_alias)
264: meth = find_instance_method_named(an_alias.old_name)
265: if meth
266: new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
267: new_meth.is_alias_for = meth
268: new_meth.singleton = meth.singleton
269: new_meth.params = meth.params
270: new_meth.comment = "Alias for \##{meth.name}"
271: meth.add_alias(new_meth)
272: add_method(new_meth)
273: else
274: add_to(@aliases, an_alias)
275: end
276: end
# File parsers/parse_f95.rb, line 391
391: def add_alias(an_alias, ignore_case=nil)
392: meth = find_instance_method_named(an_alias.old_name, ignore_case)
393: if meth
394: new_meth = AnyMethod.new(an_alias.text, an_alias.new_name)
395: new_meth.is_alias_for = meth
396: new_meth.singleton = meth.singleton
397: new_meth.params = meth.params
398: new_meth.comment = "Alias for \##{meth.name}"
399: meth.add_alias(new_meth)
400: add_method(new_meth)
401: else
402: add_to(@aliases, an_alias)
403: end
404: end
moved to parse_f95.rb #
!# !# def add_method(a_method) !# if !(a_method.visibility == :public) && !# !(a_method.visibility == :private) && !# !(a_method.visibility == :protected) !# a_method.visibility = @visibility !# end !# puts "Adding #{a_method.visibility} method #{a_method.name} to #@name" if $DEBUG !# add_to(@method_list, a_method) !# end !#
moved to parse_f95.rb #
# File code_objects.rb, line 259
259: def add_attribute(an_attribute)
260: add_to(@attributes, an_attribute)
261: 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 316
316: def add_class_or_module(collection, class_type, name, superclass=nil)
317: cls = collection[name]
318: if cls
319: puts "Reusing class/module #{name}" if $DEBUG
320: else
321: cls = class_type.new(name, superclass)
322: puts "Adding class/module #{name} to #@name" if $DEBUG
323: # collection[name] = cls if @document_self && !@done_documenting
324: collection[name] = cls if !@done_documenting
325: cls.parent = self
326: cls.section = @current_section
327: end
328: cls
329: end
# File code_objects.rb, line 303
303: def add_constant(const)
304: add_to(@constants, const)
305: 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 #
# File code_objects.rb, line 299
299: def add_include(an_include)
300: add_to(@includes, an_include)
301: end
# File parsers/parse_f95.rb, line 381
381: def add_method(a_method)
382: if !(a_method.visibility == :public) &&
383: !(a_method.visibility == :private) &&
384: !(a_method.visibility == :protected)
385: a_method.visibility = @visibility
386: end
387: puts "Adding #{a_method.visibility} method #{a_method.name} to #@name" if $DEBUG
388: add_to(@method_list, a_method)
389: 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
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
Requires always get added to the top-level (file) context
# File code_objects.rb, line 308
308: def add_require(a_require)
309: if self.kind_of? TopLevel
310: add_to(@requires, a_require)
311: else
312: parent.add_require(a_require)
313: end
314: end
# File code_objects.rb, line 331
331: def add_to(array, thing)
332: array << thing if @document_self && !@done_documenting
333: thing.parent = self
334: thing.section = @current_section
335: 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 code_objects.rb, line 225
225: def defined_in?(file)
226: @in_files.include?(file)
227: end
# File code_objects.rb, line 426
426: def each_attribute
427: @attributes.each {|a| yield a}
428: end
# File parsers/parse_f95.rb, line 437
437: def each_includes
438: @includes.each {|i| yield i}
439: end
Find a named attribute, or return nil
# File code_objects.rb, line 629
629: def find_attribute_named(name)
630: @attributes.find {|m| m.name == name}
631: end
Find a named attribute, or return nil
# File parsers/parse_f95.rb, line 556
556: def find_attribute_named(name, ignore_case=nil)
557: if !ignore_case
558: @attributes.find {|m| m.name == name}
559: else
560: @attributes.find {|m| m.name.upcase == name.upcase}
561: end
562: end
Find a named constant, or return nil
# File code_objects.rb, line 624
624: def find_constant_named(name)
625: @constants.find {|m| m.name == name}
626: end
Find a named constant, or return nil
# File parsers/parse_f95.rb, line 547
547: def find_constant_named(name, ignore_case=nil)
548: if !ignore_case
549: @constants.find {|m| m.name == name}
550: else
551: @constants.find {|m| m.name.upcase == name.upcase}
552: end
553: end
find a module at a higher scope
# File code_objects.rb, line 373
373: def find_enclosing_module_named(name)
374: parent && parent.find_module_named(name)
375: end
find a module at a higher scope
# File parsers/parse_f95.rb, line 433
433: def find_enclosing_module_named(name, ignore_case=nil)
434: parent && parent.find_module_named(name, ignore_case)
435: end
Look up the given filename.
# File parsers/parse_f95.rb, line 442
442: def find_file(file, method=nil, ignore_case=nil)
443: find_file_named(file, method, ignore_case)
444: end
Find a named instance method, or return nil
# File code_objects.rb, line 619
619: def find_instance_method_named(name)
620: @method_list.find {|meth| meth.name == name && !meth.singleton}
621: end
Find a named instance method, or return nil
# File parsers/parse_f95.rb, line 536
536: def find_instance_method_named(name, ignore_case=nil)
537: if !ignore_case
538: @method_list.find {|meth| meth.name == name && !meth.singleton}
539: else
540: @method_list.find {|meth|
541: meth.name.upcase == name.upcase && !meth.singleton
542: }
543: end
544: end
# File code_objects.rb, line 506
506: def find_local_symbol(symbol)
507: res = find_method_named(symbol) ||
508: find_constant_named(symbol) ||
509: find_attribute_named(symbol) ||
510: find_module_named(symbol)
511: end
# File parsers/parse_f95.rb, line 495
495: def find_local_symbol(symbol, ignore_case=nil)
496: res = find_method_named(symbol, ignore_case) ||
497: find_constant_named(symbol, ignore_case) ||
498: find_attribute_named(symbol, ignore_case) ||
499: find_module_named(symbol, ignore_case)
500: end
Find a named method, or return nil
# File code_objects.rb, line 614
614: def find_method_named(name)
615: @method_list.find {|meth| meth.name == name}
616: end
Find a named method, or return nil
# File parsers/parse_f95.rb, line 527
527: def find_method_named(name, ignore_case=nil)
528: if !ignore_case
529: @method_list.find {|meth| meth.name == name}
530: else
531: @method_list.find {|meth| meth.name.upcase == name.upcase}
532: end
533: end
Find a named module
# File code_objects.rb, line 365
365: def find_module_named(name)
366: return self if self.name == name
367: res = @modules[name] || @classes[name]
368: return res if res
369: find_enclosing_module_named(name)
370: end
Find a named module
# File parsers/parse_f95.rb, line 407
407: def find_module_named(name, ignore_case=nil)
408: res = nil
409: if !ignore_case
410: return self if self.name == name
411: else
412: return self if self.name.upcase == name.upcase
413: end
414: if !ignore_case
415: res = @modules[name] || @classes[name]
416: else
417: @modules.each{ |n, v|
418: if n.upcase == name.upcase
419: res = v ; break
420: end
421: }
422: @classes.each{ |n, v|
423: if n.upcase == name.upcase
424: res = v ; break
425: end
426: } if !res
427: end
428: return res if res
429: find_enclosing_module_named(name, ignore_case)
430: 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 461
461: def find_symbol(symbol, method=nil)
462: result = nil
463: case symbol
464: when /^::(.*)/
465: result = toplevel.find_symbol($1)
466: when /::/
467: modules = symbol.split(/::/)
468: unless modules.empty?
469: module_name = modules.shift
470: result = find_module_named(module_name)
471: if result
472: modules.each do |module_name|
473: result = result.find_module_named(module_name)
474: break unless result
475: end
476: end
477: end
478: else
479: # if a method is specified, then we're definitely looking for
480: # a module, otherwise it could be any symbol
481: if method
482: result = find_module_named(symbol)
483: else
484: result = find_local_symbol(symbol)
485: if result.nil?
486: if symbol =~ /^[A-Z]/
487: result = parent
488: while result && result.name != symbol
489: result = result.parent
490: end
491: end
492: end
493: end
494: end
495: if result && method
496: if !result.respond_to?(:find_local_symbol)
497: p result.name
498: p method
499: fail
500: end
501: result = result.find_local_symbol(method)
502: end
503: result
504: 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 449
449: def find_symbol(symbol, method=nil, ignore_case=nil)
450: result = nil
451: case symbol
452: when /^::(.*)/
453: result = toplevel.find_symbol($1, nil, ignore_case)
454: when /::/
455: modules = symbol.split(/::/)
456: unless modules.empty?
457: module_name = modules.shift
458: result = find_module_named(module_name, ignore_case)
459: if result
460: modules.each do |module_name|
461: result = result.find_module_named(module_name, ignore_case)
462: break unless result
463: end
464: end
465: end
466: else
467: # if a method is specified, then we're definitely looking for
468: # a module, otherwise it could be any symbol
469: if method
470: result = find_module_named(symbol, ignore_case)
471: else
472: result = find_local_symbol(symbol, ignore_case)
473: if result.nil?
474: if symbol =~ /^[A-Z]/ ||
475: symbol =~ /^[A-Za-z]/ && ignore_case
476: result = parent
477: while result && result.name != symbol
478: result = result.parent
479: end
480: end
481: end
482: end
483: end
484: if result && method
485: if !result.respond_to?(:find_local_symbol)
486: p result.name
487: p method
488: fail
489: end
490: result = result.find_local_symbol(method, ignore_case)
491: end
492: result
493: end
# File parsers/parse_f95.rb, line 516
516: def include_includes?(name, ignore_case=nil)
517: self.includes.each{|i|
518: if i.name == name ||
519: i.name.upcase == name.upcase && ignore_case
520: return true
521: end
522: }
523: return false
524: end
# File parsers/parse_f95.rb, line 502
502: def include_requires?(name, ignore_case=nil)
503: if self.kind_of? TopLevel
504: self.requires.each{|r|
505: if r.name == name ||
506: r.name.upcase == name.upcase && ignore_case
507: return true
508: end
509: }
510: return false
511: else
512: parent.include_requires?(name)
513: end
514: end
# File code_objects.rb, line 359
359: def initialize_classes_and_modules
360: @classes = {}
361: @modules = {}
362: end
# File code_objects.rb, line 345
345: def initialize_methods_etc
346: @method_list = []
347: @attributes = []
348: @aliases = []
349: @requires = []
350: @includes = []
351: @constants = []
352: 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
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 341
341: def remove_methods_etc
342: initialize_methods_etc
343: end
Handle sections
# File code_objects.rb, line 606
606: def set_current_section(title, comment)
607: @current_section = Section.new(title, comment)
608: @sections << @current_section
609: 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