Class: Kumi::Core::Analyzer::Passes::PassBase
- Inherits:
-
Object
- Object
- Kumi::Core::Analyzer::Passes::PassBase
show all
- Includes:
- ErrorReporting, Syntax
- Defined in:
- lib/kumi/core/analyzer/passes/pass_base.rb
Overview
Base class for analyzer passes with simple immutable state
Direct Known Subclasses
AttachAnchorsPass, AttachTerminalInfoPass, Codegen::LoopJsPass, Codegen::LoopRubyPass, ConstantFoldingPass, ContractCheckerPass, DependencyResolverPass, IRDependencyPass, IRExecutionSchedulePass, IRLowerPass, IRValidatePass, ImportAnalysisPass, InputAccessPlannerPass, InputCollectorPass, InputFormSchemaPass, JoinReducePlanningPass, LoadInputCSEPass, LowerToDFIRPass, NASTDimensionalAnalyzerPass, NameIndexerPass, NormalizeToNASTPass, OutputSchemaPass, PrecomputeAccessPathsPass, SNASTPass, ToposorterPass, VisitorPass
Constant Summary
collapse
- HALT =
Sentinel thrown by halt_pass! to stop a pass after a user error has been recorded, without raising an exception (which PassManager would otherwise wrap as a second, internal-looking error).
:kumi_pass_halt
Class Method Summary
collapse
Instance Method Summary
collapse
#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
#initialize(schema, state) ⇒ PassBase
Returns a new instance of PassBase.
69
70
71
72
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 69
def initialize(schema, state)
@schema = schema
@state = state
end
|
Class Method Details
.contract_declared? ⇒ Boolean
46
47
48
49
50
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 46
def contract_declared?
return true if defined?(@contract_declared) && @contract_declared
superclass.respond_to?(:contract_declared?) && superclass.contract_declared?
end
|
.declared_optional_reads ⇒ Object
38
39
40
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 38
def declared_optional_reads
inherited_contract(:declared_optional_reads) + own_optional_reads
end
|
.declared_reads ⇒ Object
34
35
36
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 34
def declared_reads
inherited_contract(:declared_reads) + own_reads
end
|
.declared_writes ⇒ Object
42
43
44
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 42
def declared_writes
inherited_contract(:declared_writes) + own_writes
end
|
.optional_reads(*keys) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 21
def optional_reads(*keys)
keys.each do |key|
own_optional_reads << key
define_method(key) { state[key] }
end
mark_contract!
end
|
.reads(*keys) ⇒ Object
13
14
15
16
17
18
19
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 13
def reads(*keys)
keys.each do |key|
own_reads << key
define_method(key) { get_state(key) }
end
mark_contract!
end
|
.writes(*keys) ⇒ Object
29
30
31
32
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 29
def writes(*keys)
own_writes.concat(keys)
mark_contract!
end
|
Instance Method Details
#debug(message) ⇒ Object
95
96
97
98
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 95
def debug(message)
class_name = self.class.name.split("::").last.gsub(/Pass$/, "")
puts "[#{class_name}] #{message}" if debug_enabled?
end
|
#debug_enabled? ⇒ Boolean
Debug helpers - automatic pattern based on pass class name InputIndexTablePass -> DEBUG_INPUT_INDEX_TABLE=1 ScopeResolutionPass -> DEBUG_SCOPE_RESOLUTION=1
89
90
91
92
93
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 89
def debug_enabled?
class_name = self.class.name.split("::").last
env_name = "DEBUG_#{to_underscore(class_name.gsub(/Pass$/, '')).upcase}"
ENV[env_name] == "1"
end
|
Main pass execution - subclasses implement this
82
83
84
|
# File 'lib/kumi/core/analyzer/passes/pass_base.rb', line 82
def run(errors)
raise NotImplementedError, "#{self.class.name} must implement #run"
end
|