Class: Yadriggy::Call

Inherits:
ASTnode show all
Includes:
AstHelper
Defined in:
lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb

Overview

Method call following parentheses.

See Also:

Direct Known Subclasses

Command

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string

Constructor Details

#initialize(sexp) ⇒ Call

Returns a new instance of Call.



817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
# File 'lib/yadriggy/ast.rb', line 817

def initialize(sexp)
  @args = []
  @block_arg = nil
  @block = nil

  case sexp[0]
  when :call, :field
    initialize_call(sexp)
  when :method_add_block
    marg = sexp[1]
    if marg[0] == :method_add_arg
      initialize_method_arg(marg[1], marg[2])
    else
      initialize_method_arg(marg, [])
    end
    @block = to_node(sexp[2])
    add_child(@block)
  else
    initialize_method_arg(sexp[1], sexp[2])
  end
end

Instance Attribute Details

#argsArray<ASTnode> (readonly)

Returns the method-call arguments.

Returns:

  • (Array<ASTnode>)

    the method-call arguments.



767
768
769
# File 'lib/yadriggy/ast.rb', line 767

def args
  @args
end

#blockASTnode|nil (readonly)

Returns the block passed to the method.

Returns:

  • (ASTnode|nil)

    the block passed to the method.



773
774
775
# File 'lib/yadriggy/ast.rb', line 773

def block
  @block
end

#block_argASTnode|nil (readonly)

Returns the argument preceded by an ampersand.

Returns:

  • (ASTnode|nil)

    the argument preceded by an ampersand.



770
771
772
# File 'lib/yadriggy/ast.rb', line 770

def block_arg
  @block_arg
end

#nameIdentifier (readonly)

Returns the method name.

Returns:



764
765
766
# File 'lib/yadriggy/ast.rb', line 764

def name
  @name
end

#opSymbol (readonly)

Returns either ‘:“.”`, `:“::”`, or `nil`.

Returns:

  • (Symbol)

    the symbol used as a separator between the receiver and the method name. It is either ‘:“.”`, `:“::”`, or `nil`.



761
762
763
# File 'lib/yadriggy/ast.rb', line 761

def op
  @op
end

#receiverASTnode|nil (readonly)

Returns the callee object.

Returns:

  • (ASTnode|nil)

    the callee object.



755
756
757
# File 'lib/yadriggy/ast.rb', line 755

def receiver
  @receiver
end

Class Method Details

.make(receiver: nil, op: nil, name:, args: [], block_arg: nil, block: nil, parent:, link_from_children: false) ⇒ Call

Makes an instance of Yadriggy::Call with the given values for its instance variables.

Parameters:

  • receiver (ASTnode|nil) (defaults to: nil)

    the receiver object.

  • op (Symbol|nil) (defaults to: nil)

    the operator.

  • name (Identifeir)

    the method name.

  • args (Array<ASTnode>) (defaults to: [])

    the method-call arguments.

  • block_arg (ASTnode|nil) (defaults to: nil)

    the argument preceded by an ampersand.

  • block (ASTnode|nil) (defaults to: nil)

    the block passed to the method.

  • parent (ASTnode)

    the parent node.

  • link_from_children (Boolean) (defaults to: false)

    if true, links from children to ‘self` are added.

Returns:

  • (Call)

    the created object.



787
788
789
790
791
792
793
# File 'lib/yadriggy/ast.rb', line 787

def self.make(receiver: nil, op: nil, name:, args: [],
              block_arg: nil, block: nil,
              parent:, link_from_children: false)
  obj = self.allocate
  obj.initialize2(receiver, op, name, args, block_arg, block,
                  parent, link_from_children)
end

.tagsObject



815
# File 'lib/yadriggy/ast.rb', line 815

def self.tags() [:method_add_arg, :call, :method_add_block, :field] end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



842
843
844
# File 'lib/yadriggy/ast.rb', line 842

def accept(evaluator)
  evaluator.call(self)
end

#initialize2(recv, op, name, args, barg, blk, parent, link_from_children) ⇒ Object



796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
# File 'lib/yadriggy/ast.rb', line 796

def initialize2(recv, op, name, args, barg, blk,
                parent, link_from_children)
  @receiver = recv
  @op = op
  @name = name
  @args = args
  @block_arg = barg
  @block = blk
  @parent = parent
  if link_from_children
    add_child(@receiver)
    add_child(@name)
    add_children(@args)
    add_child(@block_arg)
    add_child(@block)
  end
  self
end

#valueObject

Gets the invoked method or Undef.



397
398
399
400
401
402
403
# File 'lib/yadriggy/ast_value.rb', line 397

def value()
  if @receiver.nil?
    lookup_method(get_receiver_object)
  else
    lookup_method(@receiver.value)
  end
end

#value_in_class(klass) ⇒ Object



405
406
407
408
409
410
411
# File 'lib/yadriggy/ast_value.rb', line 405

def value_in_class(klass)
  if @receiver.nil?
    lookup_method(get_receiver_object)
  else
    lookup_method(@receiver.value_in_class(klass))
  end
end