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

TODO: turn this into a CanExtractReferences?

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



88
89
90
91
# File 'lib/csv_plus_plus/runtime/references.rb', line 88

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

Instance Attribute Details

#functionsArray<Entities::Function>

Functions references

Returns:



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

def functions
  @functions
end

#variablesArray<Entities::Variable>

Variable references

Returns:



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

def variables
  @variables
end

Class Method Details

.extract(ast, runtime) ⇒ 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

  • runtime (Runtime)

    The current runtime

Returns:



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

def self.extract(ast, runtime)
  new.tap do |refs|
    ::CSVPlusPlus::Runtime::Graph.depth_first_search(ast) do |node|
      unless node.type == ::CSVPlusPlus::Entities::Type::FunctionCall \
          || node.type == ::CSVPlusPlus::Entities::Type::Variable

        next
      end

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

Instance Method Details

#==(other) ⇒ boolean

Parameters:

Returns:

  • (boolean)


97
98
99
# File 'lib/csv_plus_plus/runtime/references.rb', line 97

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

#empty?::T::Boolean

Are there any references to be resolved?

Returns:

  • (::T::Boolean)


105
106
107
# File 'lib/csv_plus_plus/runtime/references.rb', line 105

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