Module: TheoryComponent

Includes:
ActsAsCode
Included in:
TheoryAction, TheoryDependent, TheoryResult
Defined in:
lib/theory/TheoryComponent.rb

Constant Summary collapse

@@theory_component_id =

TODO Complete hack for issue where component ids aren’t unique - using marshal load

0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ActsAsCode

#write_structure

Instance Attribute Details

#theory_component_idObject (readonly)

Returns the value of attribute theory_component_id.



4
5
6
# File 'lib/theory/TheoryComponent.rb', line 4

def theory_component_id
  @theory_component_id
end

Instance Method Details

#accessorsObject

Returns an array of any of the accessors in the statement. An accessor is the chain to access a property e.g. in the following statement =>

var1[var3].something(var6)

it would return [“var1[var3]”,“var6”]

The needed when trying to determine intrinsic values. So in this case var1 couln’t be a runtime_method instance becuase it doesn’t use the has key



55
56
57
# File 'lib/theory/TheoryComponent.rb', line 55

def accessors
  
end

#generate_theory_component_idObject



9
10
11
12
13
14
# File 'lib/theory/TheoryComponent.rb', line 9

def generate_theory_component_id
  if @theory_component_id.nil?
    @theory_component_id = @@theory_component_id
    @@theory_component_id += 1
  end
end

#statements_with_variable(variable_id) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/theory/TheoryComponent.rb', line 27

def statements_with_variable(variable_id)
  
  # Duplicate the current statement before it is rewritten
  rewritten_statement = @statement.copy
  
  # Find all containers of VariableDeclarations that declare a TheoryVariable
  containers = [rewritten_statement].select_all {|x| x.respond_to?(:has?)}
  theory_variable_containers = containers.select {|x| x.has? {|y| y.kind_of?(TheoryVariable)}}
  
  results = theory_variable_containers.select do |x|
    reg = eval '/var'+variable_id.to_s+'/'
    x.write.match(reg)
  end
  return results
  
end

#theory_variablesObject

Returns all the theory vairables in this theory dependent.



19
20
21
# File 'lib/theory/TheoryComponent.rb', line 19

def theory_variables
  return @statement.select_all {|x| x.kind_of?(TheoryVariable)}
end

#tokensObject



23
24
25
# File 'lib/theory/TheoryComponent.rb', line 23

def tokens
  return @statement.tokens
end