Class: Orbacle::Indexer

Inherits:
Object
  • Object
show all
Defined in:
lib/orbacle/indexer.rb

Defined Under Namespace

Classes: BuildingProcess, ParsingProcess, QueueElement, ReadingProcess, StatsRecorder

Instance Method Summary collapse

Constructor Details

#initialize(logger, stats) ⇒ Indexer

Returns a new instance of Indexer.



104
105
106
107
# File 'lib/orbacle/indexer.rb', line 104

def initialize(logger, stats)
  @logger = logger
  @stats = stats
end

Instance Method Details

#call(project_root:) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/orbacle/indexer.rb', line 109

def call(project_root:)
  project_root_path = Pathname.new(project_root)

  files = Dir.glob("#{project_root_path}/**/*.rb")
  id_generator = IntegerIdGenerator.new
  worklist = Worklist.new
  state = GlobalTree.new(id_generator)
  graph = Graph.new
  DefineBuiltins.new(graph, state, id_generator).()
  @parser = Builder.new(graph, worklist, state, id_generator)

  queue_contents = Queue.new
  queue_asts = Queue.new

  logger.info "Reading..."
  reading_process = ReadingProcess.new(logger, queue_contents, files)
  @stats.measure(:reading) { reading_process.call() }

  logger.info "Parsing..."
  parsing_process = ParsingProcess.new(logger, queue_contents, queue_asts)
  @stats.measure(:parsing) { parsing_process.call() }

  logger.info "Building graph..."
  building_process = BuildingProcess.new(queue_asts, @parser)
  @stats.measure(:building) { building_process.call() }

  logger.info "Typing..."
  typing_service = TypingService.new(logger, @stats)
  @stats.measure(:typing) { typing_service.(graph, worklist, state) }

  type_mapping = state.instance_variable_get(:@type_mapping)
  @stats.set_value(:typed_nodes_all, type_mapping.size)
  @stats.set_value(:typed_nodes_not_bottom, type_mapping.count {|k,v| !v.bottom? })
  @stats.set_value(:typed_nodes_call_result, type_mapping.count {|k,v| k.type == :call_result })
  @stats.set_value(:typed_nodes_call_result_not_bottom, type_mapping.count {|k,v| k.type == :call_result && !v.bottom? })

  return state, graph, worklist
end