Class: YARP::CallOperatorWriteNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
ext/yarp/api_node.c

Overview

Represents the use of an assignment operator on a call.

foo.bar += baz
^^^^^^^^^^^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator, operator_loc, value, location) ⇒ CallOperatorWriteNode

def initialize: (receiver: Node?, call_operator_loc: Location?, message_loc: Location?, opening_loc: Location?, arguments: ArgumentsNode?, closing_loc: Location?, flags: Integer, read_name: String, write_name: String, operator: Symbol, operator_loc: Location, value: Node, location: Location) -> void



1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
# File 'lib/yarp/node.rb', line 1573

def initialize(receiver, call_operator_loc, message_loc, opening_loc, arguments, closing_loc, flags, read_name, write_name, operator, operator_loc, value, location)
  @receiver = receiver
  @call_operator_loc = call_operator_loc
  @message_loc = message_loc
  @opening_loc = opening_loc
  @arguments = arguments
  @closing_loc = closing_loc
  @flags = flags
  @read_name = read_name
  @write_name = write_name
  @operator = operator
  @operator_loc = operator_loc
  @value = value
  @location = location
end

Instance Attribute Details

#argumentsObject (readonly)

attr_reader arguments: ArgumentsNode?



1549
1550
1551
# File 'lib/yarp/node.rb', line 1549

def arguments
  @arguments
end

#call_operator_locObject (readonly)

attr_reader call_operator_loc: Location?



1540
1541
1542
# File 'lib/yarp/node.rb', line 1540

def call_operator_loc
  @call_operator_loc
end

#closing_locObject (readonly)

attr_reader closing_loc: Location?



1552
1553
1554
# File 'lib/yarp/node.rb', line 1552

def closing_loc
  @closing_loc
end

#flagsObject (readonly)

attr_reader flags: Integer



1555
1556
1557
# File 'lib/yarp/node.rb', line 1555

def flags
  @flags
end

#message_locObject (readonly)

attr_reader message_loc: Location?



1543
1544
1545
# File 'lib/yarp/node.rb', line 1543

def message_loc
  @message_loc
end

#opening_locObject (readonly)

attr_reader opening_loc: Location?



1546
1547
1548
# File 'lib/yarp/node.rb', line 1546

def opening_loc
  @opening_loc
end

#operatorObject (readonly)

attr_reader operator: Symbol



1564
1565
1566
# File 'lib/yarp/node.rb', line 1564

def operator
  @operator
end

#operator_locObject (readonly)

attr_reader operator_loc: Location



1567
1568
1569
# File 'lib/yarp/node.rb', line 1567

def operator_loc
  @operator_loc
end

#read_nameObject (readonly)

attr_reader read_name: String



1558
1559
1560
# File 'lib/yarp/node.rb', line 1558

def read_name
  @read_name
end

#receiverObject (readonly)

attr_reader receiver: Node?



1537
1538
1539
# File 'lib/yarp/node.rb', line 1537

def receiver
  @receiver
end

#valueObject (readonly)

attr_reader value: Node



1570
1571
1572
# File 'lib/yarp/node.rb', line 1570

def value
  @value
end

#write_nameObject (readonly)

attr_reader write_name: String



1561
1562
1563
# File 'lib/yarp/node.rb', line 1561

def write_name
  @write_name
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



1590
1591
1592
# File 'lib/yarp/node.rb', line 1590

def accept(visitor)
  visitor.visit_call_operator_write_node(self)
end

#call_operatorObject

def call_operator: () -> String?



1632
1633
1634
# File 'lib/yarp/node.rb', line 1632

def call_operator
  call_operator_loc&.slice
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



1595
1596
1597
# File 'lib/yarp/node.rb', line 1595

def child_nodes
  [receiver, arguments, value]
end

#closingObject

def closing: () -> String?



1647
1648
1649
# File 'lib/yarp/node.rb', line 1647

def closing
  closing_loc&.slice
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



1600
1601
1602
# File 'lib/yarp/node.rb', line 1600

def comment_targets
  [*receiver, *call_operator_loc, *message_loc, *opening_loc, *arguments, *closing_loc, operator_loc, value]
end

#copy(**params) ⇒ Object

def copy: (**params) -> CallOperatorWriteNode



1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
# File 'lib/yarp/node.rb', line 1605

def copy(**params)
  CallOperatorWriteNode.new(
    params.fetch(:receiver) { receiver },
    params.fetch(:call_operator_loc) { call_operator_loc },
    params.fetch(:message_loc) { message_loc },
    params.fetch(:opening_loc) { opening_loc },
    params.fetch(:arguments) { arguments },
    params.fetch(:closing_loc) { closing_loc },
    params.fetch(:flags) { flags },
    params.fetch(:read_name) { read_name },
    params.fetch(:write_name) { write_name },
    params.fetch(:operator) { operator },
    params.fetch(:operator_loc) { operator_loc },
    params.fetch(:value) { value },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



1627
1628
1629
# File 'lib/yarp/node.rb', line 1627

def deconstruct_keys(keys)
  { receiver: receiver, call_operator_loc: call_operator_loc, message_loc: message_loc, opening_loc: opening_loc, arguments: arguments, closing_loc: closing_loc, flags: flags, read_name: read_name, write_name: write_name, operator: operator, operator_loc: operator_loc, value: value, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
# File 'lib/yarp/node.rb', line 1661

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  if (receiver = self.receiver).nil?
    inspector << "├── receiver: ∅\n"
  else
    inspector << "├── receiver:\n"
    inspector << receiver.inspect(inspector.child_inspector("")).delete_prefix(inspector.prefix)
  end
  inspector << "├── call_operator_loc: #{inspector.location(call_operator_loc)}\n"
  inspector << "├── message_loc: #{inspector.location(message_loc)}\n"
  inspector << "├── opening_loc: #{inspector.location(opening_loc)}\n"
  if (arguments = self.arguments).nil?
    inspector << "├── arguments: ∅\n"
  else
    inspector << "├── arguments:\n"
    inspector << arguments.inspect(inspector.child_inspector("")).delete_prefix(inspector.prefix)
  end
  inspector << "├── closing_loc: #{inspector.location(closing_loc)}\n"
  inspector << "├── flags: #{[("safe_navigation" if safe_navigation?), ("variable_call" if variable_call?)].compact.join(", ")}\n"
  inspector << "├── read_name: #{read_name.inspect}\n"
  inspector << "├── write_name: #{write_name.inspect}\n"
  inspector << "├── operator: #{operator.inspect}\n"
  inspector << "├── operator_loc: #{inspector.location(operator_loc)}\n"
  inspector << "└── value:\n"
  inspector << inspector.child_node(value, "    ")
  inspector.to_str
end

#messageObject

def message: () -> String?



1637
1638
1639
# File 'lib/yarp/node.rb', line 1637

def message
  message_loc&.slice
end

#openingObject

def opening: () -> String?



1642
1643
1644
# File 'lib/yarp/node.rb', line 1642

def opening
  opening_loc&.slice
end

#safe_navigation?Boolean

def safe_navigation?: () -> bool

Returns:

  • (Boolean)


1652
1653
1654
# File 'lib/yarp/node.rb', line 1652

def safe_navigation?
  flags.anybits?(CallNodeFlags::SAFE_NAVIGATION)
end

#variable_call?Boolean

def variable_call?: () -> bool

Returns:

  • (Boolean)


1657
1658
1659
# File 'lib/yarp/node.rb', line 1657

def variable_call?
  flags.anybits?(CallNodeFlags::VARIABLE_CALL)
end