Class: Kumi::Core::Analyzer::Passes::NameIndexer
- Defined in:
- lib/kumi/core/analyzer/passes/name_indexer.rb
Overview
RESPONSIBILITY: Build definitions index and detect duplicate names DEPENDENCIES: None (first pass in pipeline) PRODUCES: :declarations - Hash mapping names to declaration nodes
- annotates hints to declarations (e.g. inlining)
:imported_declarations - Hash of lazy import references
INTERFACE: new(schema, state).run(errors)
Instance Method Summary collapse
Methods inherited from PassBase
#debug, #debug_enabled?, #initialize
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
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 42 |
# File 'lib/kumi/core/analyzer/passes/name_indexer.rb', line 14 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 |