mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add Scope#yields?
This commit is contained in:
parent
4b1378aa33
commit
6ffb635dcc
2 changed files with 16 additions and 0 deletions
|
@ -4,6 +4,9 @@ module Ameba::AST
|
|||
# Represents a context of the local variable visibility.
|
||||
# This is where the local variables belong to.
|
||||
class Scope
|
||||
# Whether the scope yields.
|
||||
setter yields = false
|
||||
|
||||
# Link to local variables
|
||||
getter variables = [] of Variable
|
||||
|
||||
|
@ -143,6 +146,14 @@ module Ameba::AST
|
|||
end || variable.used_in_macro?
|
||||
end
|
||||
|
||||
# Returns `true` if current scope (or any of inner scopes) yields,
|
||||
# `false` otherwise.
|
||||
def yields?(check_inner_scopes = true)
|
||||
return true if @yields
|
||||
return inner_scopes.any?(&.yields?) if check_inner_scopes
|
||||
false
|
||||
end
|
||||
|
||||
# Returns `true` if current scope is a def, `false` otherwise.
|
||||
def def?
|
||||
node.is_a?(Crystal::Def)
|
||||
|
|
|
@ -64,6 +64,11 @@ module Ameba::AST
|
|||
end
|
||||
{% end %}
|
||||
|
||||
# :nodoc:
|
||||
def visit(node : Crystal::Yield)
|
||||
@current_scope.yields = true
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
def visit(node : Crystal::Def)
|
||||
node.name == "->" || on_scope_enter(node)
|
||||
|
|
Loading…
Reference in a new issue