Class: CSVPlusPlus::Runtime::References

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/csv_plus_plus/runtime/references.rb

Overview

References in an AST that need to be resolved

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReferences

Create an object with empty references. The caller will build them up as it depth-first-searches



93
94
95
96
# File 'lib/csv_plus_plus/runtime/references.rb', line 93

def initialize
  @functions = ::T.let([], ::T::Array[::CSVPlusPlus::Entities::FunctionCall])
  @variables = ::T.let([], ::T::Array[::CSVPlusPlus::Entities::Reference])
end

Instance Attribute Details

#functionsArray<Entities::Function>

Functions references

Returns:



10
11
12
# File 'lib/csv_plus_plus/runtime/references.rb', line 10

def functions
  @functions
end

#variablesArray<Entities::Variable>

Variable references

Returns:

  • (Array<Entities::Variable>)

    the current value of variables



10
11
12
# File 'lib/csv_plus_plus/runtime/references.rb', line 10

def variables
  @variables
end

Class Method Details

.extract(ast, position, scope) ⇒ References

Extract references from an AST and return them in a new References object

Parameters:

  • ast (Entity)

    An Entity to do a depth first search on for references. Entities can be infinitely deep because they can contain other function calls as params to a function call

  • scope (Scope)

    The current scope

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/csv_plus_plus/runtime/references.rb', line 33

def self.extract(ast, position, scope)
  new.tap do |refs|
    ::CSVPlusPlus::Runtime::Graph.depth_first_search(ast) do |node|
      unless node.is_a?(::CSVPlusPlus::Entities::FunctionCall) || node.is_a?(::CSVPlusPlus::Entities::Reference)
        next
      end

      refs.functions << node if function_reference?(node, scope)
      refs.variables << node if variable_reference?(node, position, scope)
    end
  end
end

Instance Method Details

#==(other) ⇒ boolean

Parameters:

Returns:

  • (boolean)


102
103
104
# File 'lib/csv_plus_plus/runtime/references.rb', line 102

def ==(other)
  @functions == other.functions && @variables == other.variables
end

#empty?::T::Boolean

Are there any references to be resolved?

Returns:

  • (::T::Boolean)


110
111
112
# File 'lib/csv_plus_plus/runtime/references.rb', line 110

def empty?
  @functions.empty? && @variables.empty?
end