Class: Yadriggy::Unary

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

Overview

Unary expression. The splat operator * is also a unary operator.

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, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string

Constructor Details

#initialize(sexp) ⇒ Unary

Returns a new instance of Unary.



619
620
621
622
623
# File 'lib/yadriggy/ast.rb', line 619

def initialize(sexp)
  @op = sexp[1]
  @operand = to_node(sexp[2])
  add_child(@operand)
end

Instance Attribute Details

#opSymbol (readonly)

Returns the operator name.

Returns:

  • (Symbol)

    the operator name. If this is a unary plus/minus expression, :+@ or :-@ is returned.



612
613
614
# File 'lib/yadriggy/ast.rb', line 612

def op
  @op
end

#operandASTnode (readonly)

Returns the operand.

Returns:



615
616
617
# File 'lib/yadriggy/ast.rb', line 615

def operand
  @operand
end

Class Method Details

.tagObject



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

def self.tag() :unary 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.



644
645
646
# File 'lib/yadriggy/ast.rb', line 644

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

#const_valueObject



336
337
338
# File 'lib/yadriggy/ast_value.rb', line 336

def const_value()
  send_op_to_value(@operand.const_value)
end

#const_value_in_class(klass) ⇒ Object



340
341
342
# File 'lib/yadriggy/ast_value.rb', line 340

def const_value_in_class(klass)
  send_op_to_value(@operand.const_value_in_class(klass))
end

#real_operatorSymbol

Returns the real operator name.

Returns:

  • (Symbol)

    the real operator name. If the operator is a unary plus or minus, the method returns :+ or :- although #op returns :+@ or :-@.



630
631
632
633
634
635
636
637
638
639
# File 'lib/yadriggy/ast.rb', line 630

def real_operator
  case @op
  when :+@
    :+
  when :-@
    :-
  else
    @op
  end
end

#valueObject



328
329
330
# File 'lib/yadriggy/ast_value.rb', line 328

def value()
  send_op_to_value(@operand.value)
end

#value_in_class(klass) ⇒ Object



332
333
334
# File 'lib/yadriggy/ast_value.rb', line 332

def value_in_class(klass)
  send_op_to_value(@operand.value_in_class(klass))
end