class Ameba::AST::Scope

Overview

Represents a context of the local variable visibility. This is where the local variables belong to.

Defined in:

ameba/ast/scope.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(node : Crystal::ASTNode, outer_scope : Nil | Ameba::AST::Scope = nil) #

Creates a new scope. Accepts the AST node and the outer scope.

scope = Scope.new(class_node, nil)

[View source]

Instance Method Detail

def ==(other : self) #
Description copied from class Reference

Returns true if this reference is the same as other. Invokes same?.


def add_argument(node) #

Creates a new argument in the current scope.

scope = Scope.new(class_node, nil)
scope.add_argument(arg_node)

[View source]
def add_ivariable(node) #

Adds a new instance variable to the current scope.

scope = Scope.new(class_node, nil)
scope.add_ivariable(ivar_node)

[View source]
def add_variable(node) #

Creates a new variable in the current scope.

scope = Scope.new(class_node, nil)
scope.add_variable(var_node)

[View source]
def arg?(var) #

Returns true if var is an argument in current scope, false otherwise.


[View source]
def arguments : Array(Ameba::AST::Argument) #

Link to the arguments in current scope


[View source]
def assign_variable(name, node) #

Creates a new assignment for the variable.

scope = Scope.new(class_node, nil)
scope.assign_variable(var_name, assign_node)

[View source]
def assigns_ivar?(name) #

Returns true if instance variable is assinged in this scope.


[View source]
def block? #

Returns true if current scope represents a block (or proc), false otherwise.


[View source]
def def? #

Returns true if current scope is a def, false otherwise.


[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 find_variable(name : String) #

Returns variable by its name or nil if it does not exist.

scope = Scope.new(class_node, nil)
scope.find_variable("foo")

[View source]
def hash(hasher) #
Description copied from class Reference

See Object#hash(hasher)


def in_macro? #

Returns true if current scope sits inside a macro.


[View source]
def inner_scopes : Array(Ameba::AST::Scope) #

List of inner scopes


[View source]
def ivariables : Array(Ameba::AST::InstanceVariable) #

Link to the instance variables used in current scope


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

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

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

The actual AST node that represents a current scope.


[View source]
def outer_scope : Scope | Nil #

Link to the outer scope


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

Link to all variable references in currency scope


[View source]
def references?(variable : Variable, check_inner_scopes = true) #

Returns true if current scope (or any of inner scopes) references variable, false otherwise.


[View source]
def spawn_block? #

Returns true if current scope represents a spawn block, e. g.

spawn do
  # ...
end

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

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

[View source]
def top_level? #

Returns true if this scope is a top level scope, false otherwise.


[View source]
def type_definition? #

Returns true if and only if current scope represents some type definition, for example a class.


[View source]
def variables : Array(Ameba::AST::Variable) #

Link to local variables


[View source]