Class: OrigenTesters::ATP::Processors::PreCleaner

Inherits:
OrigenTesters::ATP::Processor show all
Defined in:
lib/origen_testers/atp/processors/pre_cleaner.rb

Overview

Modifies the AST by performing some basic clean up, mainly to sanitize user input. For example it will ensure that all IDs and references are underscored and lower cased.

Instance Method Summary collapse

Methods inherited from OrigenTesters::ATP::Processor

#clean_flag, #extract_volatiles, #handler_missing, #process, #process_all, #run, #volatile?, #volatile_flags

Constructor Details

#initializePreCleaner

Returns a new instance of PreCleaner.



7
8
9
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 7

def initialize
  @group_ids = []
end

Instance Method Details

#clean(id) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 60

def clean(id)
  if id.is_a?(Array)
    id.map { |i| clean(i) }
  else
    id.to_s.symbolize.to_s
  end
end

#on_group(node) ⇒ Object Also known as: on_sub_flow



34
35
36
37
38
39
40
41
42
43
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 34

def on_group(node)
  if id = node.children.find { |n| n.type == :id }
    @group_ids << process(id).value
  else
    @group_ids << nil
  end
  group = node.updated(nil, process_all(node.children))
  @group_ids.pop
  group
end

#on_id(node) ⇒ Object

Make all IDs lower cased symbols



12
13
14
15
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 12

def on_id(node)
  id = node.to_a[0]
  node.updated(nil, [clean(id)])
end

#on_if_failed(node) ⇒ Object Also known as: on_if_passed, on_if_any_failed, on_if_all_failed, on_if_any_passed, on_if_all_passed, on_if_ran, on_unless_ran, on_if_any_sites_failed, on_if_all_sites_failed, on_if_any_sites_passed, on_if_all_sites_passed

Make all ID references use the lower case symbols



18
19
20
21
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 18

def on_if_failed(node)
  id, *children = *node
  node.updated(nil, [clean(id)] + process_all(children))
end

#on_test(node) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 46

def on_test(node)
  # Remove IDs nodes from test nodes if they refer to the ID of a parent group
  if @group_ids.last
    children = node.children.reject do |n|
      if n.type == :id
        @group_ids.last == process(n).value
      end
    end
  else
    children = node.children
  end
  node.updated(nil, process_all(children))
end