Class: Duby::AST::FunctionalCall

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

Instance Attribute Summary collapse

Attributes included from Named

#name

Attributes inherited from Node

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Scoped

#containing_scope, #scope

Methods included from Named

#to_s

Methods inherited from Node

#<<, ===, #[], #_set_parent, child, child_name, #each, #empty?, #initialize_copy, #insert, #inspect, #line_number, #log, #precompile, #resolve_if, #resolved!, #resolved?, #simple_name, #temp, #to_s

Constructor Details

#initialize(parent, line_number, name, &kids) ⇒ FunctionalCall

Returns a new instance of FunctionalCall.



33
34
35
36
37
# File 'lib/duby/ast/call.rb', line 33

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

Instance Attribute Details

#castObject Also known as: cast?

Returns the value of attribute cast.



22
23
24
# File 'lib/duby/ast/call.rb', line 22

def cast
  @cast
end

#inlinedObject

Returns the value of attribute inlined.



22
23
24
# File 'lib/duby/ast/call.rb', line 22

def inlined
  @inlined
end

#proxyObject

Returns the value of attribute proxy.



22
23
24
# File 'lib/duby/ast/call.rb', line 22

def proxy
  @proxy
end

#targetObject

Returns the value of attribute target.



49
50
51
# File 'lib/duby/ast/call.rb', line 49

def target
  nil
end

Class Method Details

.new(*args, &block) ⇒ Object



28
29
30
31
# File 'lib/duby/ast/call.rb', line 28

def self.new(*args, &block)
  real_node = super
  real_node.proxy = NodeProxy.new(real_node)
end

Instance Method Details

#argumentsObject



39
40
41
42
43
44
45
46
47
# File 'lib/duby/ast/call.rb', line 39

def arguments
  @arguments ||= begin
    args = java.util.ArrayList.new(parameters.size)
    parameters.each do |param|
      args.add(param)
    end
    args
  end
end

#compile(compiler, expression) ⇒ Object



191
192
193
194
# File 'lib/duby/compiler.rb', line 191

def compile(compiler, expression)
  compiler.line(line_number)
  compiler.self_call(self, expression)
end

#expr?(compiler) ⇒ Boolean

Returns:



93
94
95
96
# File 'lib/duby/jvm/source_generator/precompile.rb', line 93

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

#infer(typer) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/duby/ast/call.rb', line 53

def infer(typer)
  @self_type ||= scope.defining_class

  unless @inferred_type
    receiver_type = @self_type
    should_defer = false

    parameter_types = parameters.map do |param|
      typer.infer(param) || should_defer = true
    end

    parameter_types << Duby::AST.block_type if block

    unless should_defer
      if parameters.size == 1 && typer.known_type(name)
        # cast operation
        resolved!
        self.cast = true
        @inferred_type = typer.known_type(name)
      elsif parameters.size == 0 && scope.static_scope.include?(name)
        @inlined = Local.new(parent, position, name)
        proxy.__inline__(@inlined)
        return proxy.infer(typer)
      else
        @inferred_type = typer.method_type(receiver_type, name,
                                           parameter_types)
        if @inferred_type.kind_of? InlineCode
          @inlined = @inferred_type.inline(typer.transformer, self)
          proxy.__inline__(@inlined)
          return proxy.infer(typer)
        end
      end
    end

    if @inferred_type
      if block
        method = receiver_type.get_method(name, parameter_types)
        block.prepare(typer, method)
      end
      resolved!
    else
      typer.defer(proxy)
    end
  end

  @inferred_type
end

#method(compiler) ⇒ Object



86
87
88
89
90
91
# File 'lib/duby/jvm/source_generator/precompile.rb', line 86

def method(compiler)
  @method ||= begin
    arg_types = parameters.map {|p| p.inferred_type}
    compiler.self_type.get_method(name, arg_types)
  end
end