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



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

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

Instance Attribute Details

#definitionsObject (readonly)

Array

The locations of all definitions and assignments of

this local



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

def definitions
  @definitions
end

#typeObject (readonly)

Symbol

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



10
11
12
# File 'lib/syntax_tree/visitor/environment.rb', line 10

def type
  @type
end

#usagesObject (readonly)

Array

The locations of all usages of this local



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

def usages
  @usages
end

Instance Method Details

#add_definition(location) ⇒ Object

add_definition: (Location location) -> void



27
28
29
# File 'lib/syntax_tree/visitor/environment.rb', line 27

def add_definition(location)
  @definitions << location
end

#add_usage(location) ⇒ Object

add_usage: (Location location) -> void



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

def add_usage(location)
  @usages << location
end