Class: Seafoam::Passes::FallbackPass

Inherits:
Seafoam::Pass show all
Defined in:
lib/seafoam/passes/fallback.rb

Overview

The fallback pass always applies, and adds some basic properties. Works for example with Truffle AST and call graphs, but also means anyone can emit a graph with ‘label’ properties and we can do something useful with it.

Constant Summary

Constants inherited from Seafoam::Pass

Seafoam::Pass::SUBCLASSES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Seafoam::Pass

#applies?, inherited, #initialize

Constructor Details

This class inherits a constructor from Seafoam::Pass

Class Method Details

.applies?(_graph) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/seafoam/passes/fallback.rb', line 11

def applies?(_graph)
  true
end

Instance Method Details

#apply(graph) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/seafoam/passes/fallback.rb', line 16

def apply(graph)
  graph.nodes.each_value do |node|
    if node.props[:label].nil? && node.props["label"]
      node.props[:label] = node.props["label"]
    end

    node.props[:kind] ||= "other"
  end

  graph.edges.each do |edge|
    edge.props[:kind] ||= "other"
  end
end