class Ameba::AST::FlowExpression

Overview

Represents a flow expression in Crystal code. For example,

def foobar
  a = 3
  return 42 # => flow expression
  a + 1
end

Flow expression contains an actual node of a control expression and a parent node, which allows easily search through the related statement (i.e. find unreachable code)

Included Modules

Defined in:

ameba/ast/flow_expression.cr

Constructors

Instance Method Summary

Instance methods inherited from module Ameba::AST::Util

abort?(node) abort?, control_exp_code(node : Crystal::ControlExpression, code_lines) control_exp_code, dynamic_literal?(node) : Bool dynamic_literal?, exit?(node) exit?, flow_command?(node, in_loop) flow_command?, flow_expression?(node, in_loop = false) flow_expression?, literal?(node) : Bool literal?, loop?(node) loop?, name_end_location(node) name_end_location, name_location(node) name_location, name_size(node) name_size, node_source(node, code_lines) node_source, path_named?(node, name) : Bool path_named?, raise?(node) raise?, source_between(loc, end_loc, code_lines) : String | Nil source_between, static_literal?(node) : Bool static_literal?

Constructor Detail

def self.new(node : Crystal::ASTNode, in_loop : Bool) #

Creates a new flow expression.

FlowExpression.new(node, parent_node)

[View source]

Instance Method Detail

def end_location(*args, **options) #

[View source]
def end_location(*args, **options, &) #

[View source]
def in_loop? : Bool #

Is true only if some of the nodes parents is a loop.


[View source]
def location(*args, **options) #

[View source]
def location(*args, **options, &) #

[View source]
def node : Crystal::ASTNode #

The actual node of the flow expression.


[View source]
def to_s(*args, **options) #

[View source]
def to_s(*args, **options, &) #

[View source]
def unreachable_nodes #

Returns nodes which can't be reached because of a flow command inside. For example:

def foobar
  a = 1
  return 42

  a + 2 # => unreachable assign node
end

[View source]