class Ameba::AST::Variable

Overview

Represents the existence of the local variable. Holds the var node and variable assignments.

Direct Known Subclasses

Defined in:

ameba/ast/variabling/variable.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(node : Crystal::Var, scope : Ameba::AST::Scope) #

Creates a new variable(in the scope).

Variable.new(node, scope)

[View source]

Instance Method Detail

def assign(node, scope) #

Assigns the variable (creates a new assignment). Variable may have multiple assignments.

variable = Variable.new(node, scope)
variable.assign(node1)
variable.assign(node2)
variable.assignment.size # => 2

[View source]
def assign_before_reference : Crystal::ASTNode | Nil #

Node of the first assignment which can be available before any reference.


[View source]
def assignments : Array(Ameba::AST::Assignment) #

List of the assignments of this variable.


[View source]
def captured_by_block?(scope = @scope) #

Returns true if the current var is referenced in in the block. For example this variable is captured by block:

a = 1
3.times { |i| a = a + i }

And this variable is not captured by block.

i = 1
3.times { |i| i + 1 }

[View source]
def declared_before?(node) #

Returns true if the variable is declared before the #node.


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

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

[View source]
def eql?(node) #

Returns true if the #node represents exactly the same Crystal node as @node.


[View source]
def ignored? #

Returns true if the name starts with '_', false if not.


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

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

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

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

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

The actual var node.


[View source]
def reference(node : Crystal::Var, scope : Scope) #

Creates a reference to this variable in some scope.

variable = Variable.new(node, scope)
variable.reference(var_node, some_scope)

[View source]
def reference(scope : Scope) #

Creates a reference to this variable in some scope.

variable = Variable.new(node, scope)
variable.reference(var_node, some_scope)

[View source]
def reference_assignments! #

Reference variable's assignments.

variable = Variable.new(node, scope)
variable.assign(assign_node)
variable.reference_assignments!

[View source]
def referenced? #

Returns true if variable has any reference.

variable = Variable.new(node, scope)
variable.reference(var_node, some_scope)
variable.referenced? # => true

[View source]
def references : Array(Ameba::AST::Reference) #

List of the references of this variable.


[View source]
def scope : Scope #

Scope of this variable.


[View source]
def special? #

Returns true if it is a special variable, i.e $?.


[View source]
def target_of?(assign) #

Returns true if the variable is a target (on the left) of the assignment, false otherwise.


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

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

[View source]
def used_in_macro?(scope = @scope) #

Returns true if current variable potentially referenced in a macro, false if not.


[View source]