class Ameba::AST::Scope
- Ameba::AST::Scope
- Reference
- Object
Overview
Represents a context of the local variable visibility. This is where the local variables belong to.
Defined in:
ameba/ast/scope.crConstructors
-
.new(node : Crystal::ASTNode, outer_scope : Nil | Ameba::AST::Scope = nil)
Creates a new scope.
Instance Method Summary
-
#==(other : self)
Returns
trueif this reference is the same as other. -
#add_argument(node)
Creates a new argument in the current scope.
-
#add_ivariable(node)
Adds a new instance variable to the current scope.
-
#add_variable(node)
Creates a new variable in the current scope.
-
#arg?(var)
Returns true if var is an argument in current scope,
falseotherwise. -
#arguments : Array(Ameba::AST::Argument)
Link to the arguments in current scope
-
#assign_variable(name, node)
Creates a new assignment for the variable.
-
#assigns_ivar?(name)
Returns
trueif instance variable is assinged in this scope. -
#block?
Returns
trueif current scope represents a block (or proc),falseotherwise. -
#def?
Returns
trueif current scope is a def,falseotherwise. - #end_location(*args, **options)
- #end_location(*args, **options, &)
-
#eql?(node)
Returns
trueif the node represents exactly the same Crystal node as@node. -
#find_variable(name : String)
Returns variable by its name or
nilif it does not exist. -
#hash(hasher)
See
Object#hash(hasher) -
#in_macro?
Returns
trueif current scope sits inside a macro. -
#inner_scopes : Array(Ameba::AST::Scope)
List of inner scopes
-
#ivariables : Array(Ameba::AST::InstanceVariable)
Link to the instance variables used in current scope
- #location(*args, **options)
- #location(*args, **options, &)
-
#node : Crystal::ASTNode
The actual AST node that represents a current scope.
-
#outer_scope : Scope | Nil
Link to the outer scope
-
#references : Array(Ameba::AST::Reference)
Link to all variable references in currency scope
-
#references?(variable : Variable, check_inner_scopes = true)
Returns true if current scope (or any of inner scopes) references variable,
falseotherwise. -
#spawn_block?
Returns
trueif current scope represents a spawn block, e. - #to_s(*args, **options)
- #to_s(*args, **options, &)
-
#top_level?
Returns
trueif this scope is a top level scope,falseotherwise. -
#type_definition?
Returns
trueif and only if current scope represents some type definition, for example a class. -
#variables : Array(Ameba::AST::Variable)
Link to local variables
Constructor Detail
Creates a new scope. Accepts the AST node and the outer scope.
scope = Scope.new(class_node, nil)
Instance Method Detail
Returns true if this reference is the same as other. Invokes same?.
Creates a new argument in the current scope.
scope = Scope.new(class_node, nil)
scope.add_argument(arg_node)
Adds a new instance variable to the current scope.
scope = Scope.new(class_node, nil)
scope.add_ivariable(ivar_node)
Creates a new variable in the current scope.
scope = Scope.new(class_node, nil)
scope.add_variable(var_node)
Creates a new assignment for the variable.
scope = Scope.new(class_node, nil)
scope.assign_variable(var_name, assign_node)
Returns variable by its name or nil if it does not exist.
scope = Scope.new(class_node, nil)
scope.find_variable("foo")
Link to the instance variables used in current scope
Returns true if current scope (or any of inner scopes) references variable,
false otherwise.
Returns true if and only if current scope represents some
type definition, for example a class.