Class: ASTTransform::AbstractTransformation

Inherits:
Parser::AST::Processor
  • Object
show all
Includes:
TransformationHelper
Defined in:
lib/ast_transform/abstract_transformation.rb

Direct Known Subclasses

Transformation

Instance Method Summary collapse

Methods included from TransformationHelper

included

Instance Method Details

#on_ast_thunk(node) ⇒ Object

Thunks are framework-owned IR: descend into the body so passes that don't know about thunks still process the wrapped statements. Without this, Processor's handler_missing default would pass the node through opaquely, hiding the body from every later transformation. The token (first child) is not a node and passes through untouched.



30
31
32
# File 'lib/ast_transform/abstract_transformation.rb', line 30

def on_ast_thunk(node)
  node.updated(nil, [node.children[0], *process_all(node.children.drop(1))])
end

#process(node) ⇒ Object

Used internally by Parser::AST::Processor to process each node. DO NOT OVERRIDE.



20
21
22
23
24
# File 'lib/ast_transform/abstract_transformation.rb', line 20

def process(node)
  return node unless node.is_a?(Parser::AST::Node)

  process_node(node)
end

#run(node) ⇒ Parser::AST::Node

Runs this transformation on node. Note: If you want to add one-time checks to the transformation, override this, then call super.

Parameters:

  • node (Parser::AST::Node)

    The node to be transformed.

Returns:

  • (Parser::AST::Node)

    The transformed node.



15
16
17
# File 'lib/ast_transform/abstract_transformation.rb', line 15

def run(node)
  process(node)
end