Class: Cloc::Linker
- Inherits:
-
Object
- Object
- Cloc::Linker
- Defined in:
- lib/cloc/linker.rb
Overview
Connects method declarations to location of c functions. The result is written to the database.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize ⇒ Linker
constructor
A new instance of Linker.
- #process_file(pathname) ⇒ Object
- #remove_missing ⇒ Object
- #resolve_non_static_functions ⇒ Object
Constructor Details
#initialize ⇒ Linker
Returns a new instance of Linker.
8 9 10 11 |
# File 'lib/cloc/linker.rb', line 8 def initialize @table = {} @non_static_functions = {} end |
Instance Method Details
#data ⇒ Object
66 67 68 |
# File 'lib/cloc/linker.rb', line 66 def data @table end |
#process_file(pathname) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cloc/linker.rb', line 13 def process_file(pathname) puts "Processing #{pathname} ..." # Since same pathnames appear many many times, we store them as # symbols to conserve memory. absolute_pathname = File.(pathname).to_sym src = FileSource.new(pathname) src.refs.each do |klass, rmethod, cfunc| if @table[klass] klass = @table[klass] else klass = @table[klass] = {} end klass[rmethod] = begin if src.cfunctions[cfunc] # Resolve static methods. [ absolute_pathname, src.cfunctions[cfunc] ] else # Postpone to later. cfunc end end end # Save non-static functions for later. src.cfunctions.each_pair do |cfunc, lineno| @non_static_functions[cfunc] = [ absolute_pathname, lineno ] end end |
#remove_missing ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/cloc/linker.rb', line 55 def remove_missing @table.each_pair do |klass, methods_table| methods_table.each_pair do |method, location_or_cfunction| if location_or_cfunction.is_a? String puts "-- Couldn't resolve #{klass}##{method}" if Cloc.warn? methods_table.delete(method) end end end end |
#resolve_non_static_functions ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cloc/linker.rb', line 43 def resolve_non_static_functions @table.each_pair do |klass, methods_table| methods_table.each_pair do |method, location_or_cfunction| if location_or_cfunction.is_a? String if @non_static_functions[location_or_cfunction] methods_table[method] = @non_static_functions[location_or_cfunction] end end end end end |