Class: OrigenTesters::ATP::Processor

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin
Defined in:
lib/origen_testers/atp/processor.rb

Overview

The base processor, this provides a default handler for all node types and will not make any changes to the AST, i.e. an equivalent AST will be returned by the process method.

Child classes of this should be used to implement additional processors to modify or otherwise work with the AST.

Instance Method Summary collapse

Instance Method Details

#clean_flag(flag) ⇒ Object



67
68
69
70
71
# File 'lib/origen_testers/atp/processor.rb', line 67

def clean_flag(flag)
  flag = flag.dup.to_s
  flag[0] = '' if flag[0] == '$'
  flag.downcase
end

#extract_volatiles(flow) ⇒ Object



47
48
49
50
51
52
# File 'lib/origen_testers/atp/processor.rb', line 47

def extract_volatiles(flow)
  @volatiles = {}
  if v = flow.find(:volatile)
    @volatiles[:flags] = Array(v.find_all(:flag)).map(&:value)
  end
end

#handler_missing(node) ⇒ Object



43
44
45
# File 'lib/origen_testers/atp/processor.rb', line 43

def handler_missing(node)
  node.updated(nil, process_all(node.children))
end

#process(node) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/origen_testers/atp/processor.rb', line 18

def process(node)
  if node.respond_to?(:to_ast)
    super(node)
  else
    node
  end
end

#process_all(nodes) ⇒ Object

Some of our processors remove a wrapping node from the AST, returning a node of type :inline containing the children which should be inlined. Here we override the default version of this method to deal with handlers that return an inline node in place of a regular node.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/origen_testers/atp/processor.rb', line 30

def process_all(nodes)
  results = []
  nodes.to_a.each do |node|
    n = process(node)
    if n.respond_to?(:type) && n.type == :inline
      results += n.children
    else
      results << n unless n.respond_to?(:type) && n.type == :remove
    end
  end
  results
end

#run(node) ⇒ Object



14
15
16
# File 'lib/origen_testers/atp/processor.rb', line 14

def run(node)
  process(node)
end

#volatile?(flag) ⇒ Boolean

Returns true if the given flag name has been marked as volatile

Returns:

  • (Boolean)


62
63
64
65
# File 'lib/origen_testers/atp/processor.rb', line 62

def volatile?(flag)
  result = volatile_flags.any? { |f| clean_flag(f) == clean_flag(flag) }
  result
end

#volatile_flagsObject



54
55
56
57
58
59
# File 'lib/origen_testers/atp/processor.rb', line 54

def volatile_flags
  unless @volatiles
    fail 'You must first call extract_volatiles(node) from your on_flow hander method'
  end
  @volatiles[:flags] || []
end