Class: SyntaxTree::Environment::Local

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/visitor/environment.rb

Overview

This class tracks the occurrences of a local variable or argument

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Local

initialize: (Symbol type) -> void



24
25
26
27
28
# File 'lib/syntax_tree/visitor/environment.rb', line 24

def initialize(type)
  @type = type
  @definitions = []
  @usages = []
end

Instance Attribute Details

#definitionsObject (readonly)

Array

The locations of all definitions and assignments of

this local



18
19
20
# File 'lib/syntax_tree/visitor/environment.rb', line 18

def definitions
  @definitions
end

#typeObject (readonly)

Symbol

The type of the local (e.g. :argument, :variable)



14
15
16
# File 'lib/syntax_tree/visitor/environment.rb', line 14

def type
  @type
end

#usagesObject (readonly)

Array

The locations of all usages of this local



21
22
23
# File 'lib/syntax_tree/visitor/environment.rb', line 21

def usages
  @usages
end

Instance Method Details

#add_definition(location) ⇒ Object

add_definition: (Location location) -> void



31
32
33
# File 'lib/syntax_tree/visitor/environment.rb', line 31

def add_definition(location)
  @definitions << location
end

#add_usage(location) ⇒ Object

add_usage: (Location location) -> void



36
37
38
# File 'lib/syntax_tree/visitor/environment.rb', line 36

def add_usage(location)
  @usages << location
end