Class: Mirah::AST::Super

Inherits:
Node
  • Object
show all
Includes:
Named, Scoped
Defined in:
lib/mirah/jvm/source_generator/precompile.rb,
lib/mirah/ast/call.rb,
lib/mirah/jvm/compiler.rb,
lib/mirah/compiler/call.rb

Overview

TODO merge with FunctionalCall logic (almost identical)

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #inferred_type, #newline, #parent, #position

Instance Method Summary collapse

Methods included from Scoped

#containing_scope, #scope

Methods included from Named

#string_value, #to_s, #validate_name

Methods inherited from Node

#<<, ===, #[], #[]=, #_dump, _load, #_set_parent, child, child_name, #child_nodes, #each, #empty?, #inferred_type!, #initialize_copy, #insert, #inspect, #inspect_children, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #string_value, #temp, #to_s, #top_level?, #validate_child, #validate_children

Constructor Details

#initialize(parent, line_number) ⇒ Super

Returns a new instance of Super.



284
285
286
287
# File 'lib/mirah/ast/call.rb', line 284

def initialize(parent, line_number)
  super(parent, line_number)
  @cast = false
end

Instance Attribute Details

#castObject Also known as: cast?

Returns the value of attribute cast.



279
280
281
# File 'lib/mirah/ast/call.rb', line 279

def cast
  @cast
end

#method(compiler) ⇒ Object

Returns the value of attribute method.



279
280
281
# File 'lib/mirah/ast/call.rb', line 279

def method
  @method
end

#targetObject

Returns the value of attribute target.



32
33
34
# File 'lib/mirah/jvm/compiler.rb', line 32

def target
  @target
end

Instance Method Details

#call_parentObject



289
290
291
292
293
294
295
# File 'lib/mirah/ast/call.rb', line 289

def call_parent
  @call_parent ||= begin
    node = parent
    node = (node && node.parent) until MethodDefinition === node
    node
  end
end

#compile(compiler, expression) ⇒ Object



37
38
39
40
41
42
# File 'lib/mirah/compiler/call.rb', line 37

def compile(compiler, expression)
  compiler.line(line_number)
  compiler.super_call(self, expression)
rescue Exception => ex
  raise Mirah::InternalCompilerError.wrap(ex, self)
end

#default_parametersObject



331
332
333
334
335
336
337
338
339
# File 'lib/mirah/ast/call.rb', line 331

def default_parameters
  node = self
  node = node.parent until MethodDefinition === node || node.nil?
  return [] if node.nil?
  args = node.arguments.children.map {|x| x || []}
  args.flatten.map do |arg|
    Local.new(self, position, arg.name)
  end
end

#expr?(compiler) ⇒ Boolean

Returns:



132
133
134
135
# File 'lib/mirah/jvm/source_generator/precompile.rb', line 132

def expr?(compiler)
  parameters.all? {|p| p.expr?(compiler)} &&
      !method(compiler).return_type.void?
end

#infer(typer, expression) ⇒ Object



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'lib/mirah/ast/call.rb', line 301

def infer(typer, expression)
  @self_type ||= scope.static_scope.self_type.superclass

  unless @inferred_type
    receiver_type = call_parent.defining_class.superclass
    should_defer = receiver_type.nil?
    parameter_types = parameters.map do |param|
      typer.infer(param, true) || should_defer = true
    end

    unless should_defer
      @inferred_type = typer.method_type(receiver_type, name,
                                         parameter_types)
    end

    @inferred_type ? resolved! : typer.defer(self)
  end

  @inferred_type
end

#nameObject



297
298
299
# File 'lib/mirah/ast/call.rb', line 297

def name
  call_parent.name
end

#originial_parametersObject



322
# File 'lib/mirah/ast/call.rb', line 322

alias originial_parameters parameters

#parametersObject



324
325
326
327
328
329
# File 'lib/mirah/ast/call.rb', line 324

def parameters
  if originial_parameters.nil?
    self.parameters = default_parameters
  end
  originial_parameters
end