Class: Duby::AST::Call

Inherits:
Node
  • Object
show all
Includes:
Named
Defined in:
lib/duby/ast/call.rb,
lib/duby/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 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) ⇒ Call

Returns a new instance of Call.



116
117
118
119
# File 'lib/duby/ast/call.rb', line 116

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

Instance Attribute Details

#inlinedObject

Returns the value of attribute inlined.



105
106
107
# File 'lib/duby/ast/call.rb', line 105

def inlined
  @inlined
end

#proxyObject

Returns the value of attribute proxy.



105
106
107
# File 'lib/duby/ast/call.rb', line 105

def proxy
  @proxy
end

Class Method Details

.new(*args, &block) ⇒ Object



111
112
113
114
# File 'lib/duby/ast/call.rb', line 111

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

Instance Method Details

#argumentsObject



121
122
123
124
125
126
127
128
129
# File 'lib/duby/ast/call.rb', line 121

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



198
199
200
201
# File 'lib/duby/compiler.rb', line 198

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

#expr?(compiler) ⇒ Boolean

Returns:



77
78
79
80
81
82
# File 'lib/duby/jvm/source_generator/precompile.rb', line 77

def expr?(compiler)
  target.expr?(compiler) &&
      parameters.all? {|p| p.expr?(compiler)} &&
      !method.return_type.kind_of?(Duby::AST::InlineCode) &&
      !method.actual_return_type.void?
end

#infer(typer) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/duby/ast/call.rb', line 131

def infer(typer)
  unless @inferred_type
    receiver_type = typer.infer(target)
    should_defer = receiver_type.nil?
    parameter_types = parameters.map do |param|
      typer.infer(param) || should_defer = true
    end

    parameter_types << Duby::AST.block_type if block

    unless should_defer
      @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

    if @inferred_type
      if block && !receiver_type.error?
        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 = nil) ⇒ Object



70
71
72
73
74
75
# File 'lib/duby/jvm/source_generator/precompile.rb', line 70

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