Class: Kumi::Core::Analyzer::Passes::NameIndexerPass
- Defined in:
- lib/kumi/core/analyzer/passes/name_indexer_pass.rb
Constant Summary
Constants inherited from PassBase
Instance Method Summary collapse
Methods inherited from PassBase
contract_declared?, #debug, #debug_enabled?, declared_optional_reads, declared_reads, declared_writes, #initialize, optional_reads, reads, writes
Methods included from ErrorReporting
#inferred_location, #raise_localized_error, #raise_syntax_error, #raise_type_error, #report_enhanced_error, #report_error, #report_semantic_error, #report_syntax_error, #report_type_error
Constructor Details
This class inherits a constructor from Kumi::Core::Analyzer::Passes::PassBase
Instance Method Details
#run(errors) ⇒ Object
10 11 12 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 |
# File 'lib/kumi/core/analyzer/passes/name_indexer_pass.rb', line 10 def run(errors) definitions = {} imported_declarations = {} hints = {} # Phase 1: Register imports as lazy references (schema.imports || []).each do |import_decl| import_decl.names.each do |name| imported_declarations[name] = { type: :import, from_module: import_decl.module_ref, loc: import_decl.loc } end end # Phase 2: Index local declarations each_decl do |decl| if definitions.key?(decl.name) || imported_declarations.key?(decl.name) report_error(errors, "duplicated definition `#{decl.name}`", location: decl.loc) end definitions[decl.name] = decl hints[decl.name] = decl.hints end state.with(:declarations, definitions.freeze) .with(:imported_declarations, imported_declarations.freeze) .with(:hints, hints) end |