Class: Rattler::BackEnd::Optimizer::OptimizationContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rattler/back_end/optimizer/optimization_context.rb

Overview

OptimizationContext provides contextual information to optimzations.

Author:

  • Jason Arhart

Constant Summary collapse

@@cache =
Hash.new {|h, attrs| h[attrs] = self.new(attrs) }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ OptimizationContext

Returns a new instance of OptimizationContext.



23
24
25
26
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 23

def initialize(attrs)
  @attrs = attrs
  @rules = @attrs[:rules]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 59

def method_missing(symbol, *args)
  if args.empty? and @attrs.has_key? symbol
    @attrs[symbol]
  else
    super
  end
end

Instance Attribute Details

#rulesObject (readonly)

Returns the value of attribute rules.



28
29
30
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 28

def rules
  @rules
end

#typeObject (readonly)

Returns the value of attribute type.



28
29
30
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 28

def type
  @type
end

Class Method Details

.[](attrs) ⇒ Object



19
20
21
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 19

def self.[](attrs)
  @@cache[attrs]
end

Instance Method Details

#analysisObject



34
35
36
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 34

def analysis
  rules && rules.analysis
end

#capturing?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 38

def capturing?
  @attrs[:type] == :capturing
end

#matching?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 42

def matching?
  @attrs[:type] == :matching
end

#relavent?(rule) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 50

def relavent?(rule)
  (not standalone? and not rule.attrs[:inline]) or
  analysis.referenced?(rule.name)
end

#respond_to?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 67

def respond_to?(symbol)
  super or @attrs.has_key? symbol
end

#standalone?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 46

def standalone?
  start_rule && @attrs[:standalone]
end

#start_ruleObject



30
31
32
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 30

def start_rule
  rules && rules.start_rule
end

#with(new_attrs) ⇒ Object



55
56
57
# File 'lib/rattler/back_end/optimizer/optimization_context.rb', line 55

def with(new_attrs)
  self.class[@attrs.merge new_attrs]
end