class

Ameba::AST::Scope

Inherits Reference < Object

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

Constructors

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)
Source

Instance methods

==(other : self)

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

add_argument(node)

Creates a new argument in the current scope.

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

Adds a new instance variable to the current scope.

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

Adds a new type declaration variable to the current scope.

scope = Scope.new(class_node, nil)
scope.add_type_dec_variable(node)
Source
add_variable(node)

Creates a new variable in the current scope.

scope = Scope.new(class_node, nil)
scope.add_variable(var_node)
Source
arg?(var)

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

Source
arguments

Link to the arguments in current scope

Source
assign_variable(name, node)

Creates a new assignment for the variable.

scope = Scope.new(class_node, nil)
scope.assign_variable(var_name, assign_node)
Source
assigns_ivar?(name)

Returns true if instance variable is assigned in this scope.

Source
assigns_type_dec_variable?(name)

Returns true if type declaration variable is assigned in this scope.

Source
block?

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

Source
class_def?(*, check_outer_scopes = false)

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

Source
declared_at?(name : String, node) : Bool

Returns true if a local variable named name has a definition that reaches the program point where node (an inner scope's node) is introduced.

scope.declared_at?("foo", block_node)
Source
def?(*, check_outer_scopes = false)

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

Source
end_location(*args, **options)
Source
end_location(*args, **options, &)
Source
enum_def?(*, check_outer_scopes = false)

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

Source
eql?(node)

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

Source
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")
Source
fun_def?(*, check_outer_scopes = false)

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

Source
hash(hasher)

See Object#hash(hasher)

in_macro?

Returns true if current scope sits inside a macro.

Source
inherited?
Source
inherited?
Source
inner_scopes

List of inner scopes

Source
ivariables

Link to the instance variables used in current scope

Source
lib_def?(*, check_outer_scopes = false)

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

Source
location(*args, **options)
Source
location(*args, **options, &)
Source
module_def?(*, check_outer_scopes = false)

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

Source
node

The actual AST node that represents a current scope.

Source
outer_scope

Link to the outer scope

Source
references

Link to all variable references in current scope

Source
references?(variable : Variable, check_inner_scopes = true)

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

Source
spawn_block?

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

spawn do
  # ...
end
Source
to_s(*args, **options)
Source
to_s(*args, **options, &)
Source
top_level?

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

Source
type_dec_variables

Link to the type declaration variables used in current scope

Source
type_definition?

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

Source
variables

Link to local variables

Source
visibility

Returns visibility of the current scope (could be inherited from the outer scope).

Source
visibility=(visibility : Crystal::Visibility | Nil)

Scope visibility level

Source
yields=(yields : Bool)

Whether the scope yields.

Source
yields?(check_inner_scopes = true)

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

Source