Class: Autotype::Analyzer
- Inherits:
-
Object
- Object
- Autotype::Analyzer
- Defined in:
- lib/autotype/engine.rb
Instance Attribute Summary collapse
-
#capabilities ⇒ Object
readonly
Returns the value of attribute capabilities.
Instance Method Summary collapse
- #analyze(node, qualified_name, owner:, kind:, superclass:) ⇒ Object
-
#initialize ⇒ Analyzer
constructor
A new instance of Analyzer.
Constructor Details
#initialize ⇒ Analyzer
Returns a new instance of Analyzer.
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/autotype/engine.rb', line 204 def initialize @next_id = 0 @environment = {} @local_bindings = {} @block_locals = {} @ivars = {} @capabilities = [] @return_types = [] @port_assignments = [] @scope = Object.new @self_type = fresh("self") end |
Instance Attribute Details
#capabilities ⇒ Object (readonly)
Returns the value of attribute capabilities.
202 203 204 |
# File 'lib/autotype/engine.rb', line 202 def capabilities @capabilities end |
Instance Method Details
#analyze(node, qualified_name, owner:, kind:, superclass:) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/autotype/engine.rb', line 217 def analyze(node, qualified_name, owner:, kind:, superclass:) @infer_cache = {} @case_narrowings = Hash.new { |hash, key| hash[key] = [] } parameters = bind_parameters(node.parameters) result = infer(node.body) result = Named.new("nil") unless result @return_types.each { |return_type| result = union(result, return_type) } if @yield_function && parameters.none? { |parameter| parameter.kind == :block } parameters += [Parameter.new(name: :block, type: @yield_function, kind: :block)] end MethodResult.new( name: qualified_name, owner: owner, kind: kind, method_name: node.name, superclass: superclass, line: node.location.start_line, end_line: node.location.end_line, parameters: parameters, result: result, capabilities: capabilities, self_type: @self_type, ivars: @ivars.dup, # A name bound both at method level and inside blocks (e.g. # `x = nil` reassigned within an each) carries both types. locals: @block_locals.merge(@environment) { |_name, inner, outer| union(inner, outer) }, port_assignments: @port_assignments.dup, case_narrowings: @case_narrowings.transform_values { |types| types.uniq } ) end |