Class: Prism::ShareableConstantNode

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

Overview

This node wraps a constant write to indicate that when the value is written, it should have its shareability state modified.

# shareable_constant_value: literal
C = { a: 1 }
^^^^^^^^^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, write) ⇒ ShareableConstantNode

Initialize a new ShareableConstantNode node.



14688
14689
14690
14691
14692
14693
14694
# File 'lib/prism/node.rb', line 14688

def initialize(source, node_id, location, flags, write)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @write = write
end

Instance Attribute Details

#writeObject (readonly)

The constant write that should be modified with the shareability state.



14745
14746
14747
# File 'lib/prism/node.rb', line 14745

def write
  @write
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See ‘Node::type`.



14758
14759
14760
# File 'lib/prism/node.rb', line 14758

def self.type
  :shareable_constant_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



14764
14765
14766
14767
14768
# File 'lib/prism/node.rb', line 14764

def ===(other)
  other.is_a?(ShareableConstantNode) &&
    (flags === other.flags) &&
    (write === other.write)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



14697
14698
14699
# File 'lib/prism/node.rb', line 14697

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

#child_nodesObject Also known as: deconstruct

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



14702
14703
14704
# File 'lib/prism/node.rb', line 14702

def child_nodes
  [write]
end

#comment_targetsObject

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



14712
14713
14714
# File 'lib/prism/node.rb', line 14712

def comment_targets
  [write] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



14707
14708
14709
# File 'lib/prism/node.rb', line 14707

def compact_child_nodes
  [write]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, write: self.write) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?write: ConstantWriteNode | ConstantAndWriteNode | ConstantOrWriteNode | ConstantOperatorWriteNode | ConstantPathWriteNode | ConstantPathAndWriteNode | ConstantPathOrWriteNode | ConstantPathOperatorWriteNode) -> ShareableConstantNode



14717
14718
14719
# File 'lib/prism/node.rb', line 14717

def copy(node_id: self.node_id, location: self.location, flags: self.flags, write: self.write)
  ShareableConstantNode.new(source, node_id, location, flags, write)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, write: ConstantWriteNode | ConstantAndWriteNode | ConstantOrWriteNode | ConstantOperatorWriteNode | ConstantPathWriteNode | ConstantPathAndWriteNode | ConstantPathOrWriteNode | ConstantPathOperatorWriteNode }



14725
14726
14727
# File 'lib/prism/node.rb', line 14725

def deconstruct_keys(keys)
  { node_id: node_id, location: location, write: write }
end

#experimental_copy?Boolean

def experimental_copy?: () -> bool

Returns:

  • (Boolean)


14740
14741
14742
# File 'lib/prism/node.rb', line 14740

def experimental_copy?
  flags.anybits?(ShareableConstantNodeFlags::EXPERIMENTAL_COPY)
end

#experimental_everything?Boolean

def experimental_everything?: () -> bool

Returns:

  • (Boolean)


14735
14736
14737
# File 'lib/prism/node.rb', line 14735

def experimental_everything?
  flags.anybits?(ShareableConstantNodeFlags::EXPERIMENTAL_EVERYTHING)
end

#inspectObject

def inspect -> String



14748
14749
14750
# File 'lib/prism/node.rb', line 14748

def inspect
  InspectVisitor.compose(self)
end

#literal?Boolean

def literal?: () -> bool

Returns:

  • (Boolean)


14730
14731
14732
# File 'lib/prism/node.rb', line 14730

def literal?
  flags.anybits?(ShareableConstantNodeFlags::LITERAL)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



14753
14754
14755
# File 'lib/prism/node.rb', line 14753

def type
  :shareable_constant_node
end