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

#add_global_flag, #clean_flag, #extract_globals, #extract_volatiles, #global_flag?, #global_flags, #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



70
71
72
73
74
75
76
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 70

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



44
45
46
47
48
49
50
51
52
53
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 44

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 unless literal_flags is set



13
14
15
16
17
18
19
20
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 13

def on_id(node)
  id = node.to_a[0]
  if tester.literal_flags
    node.updated(nil, [id])
  else
    node.updated(nil, [clean(id)])
  end
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 unless literal_flags is set



24
25
26
27
28
29
30
31
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 24

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

#on_test(node) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/origen_testers/atp/processors/pre_cleaner.rb', line 56

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