Class: CFGVisualizerController

Inherits:
Object
  • Object
show all
Includes:
JRubyFX::Controller
Defined in:
lib/jruby_visualizer/cfg_visualizer.rb

Overview

This controller connects the CompilerData to the CFG View and handles opening/updating tabs for CFGs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compiler_data) ⇒ CFGVisualizerController

Returns a new instance of CFGVisualizerController.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/jruby_visualizer/cfg_visualizer.rb', line 51

def initialize(compiler_data)
  @compiler_data = compiler_data

  # read scopes into the registry
  @ir_registry = IRScopeRegistry.new(@compiler_data.ir_scope)
  read_registry_into_selector
  # listen to changes of the ir_scope property
  @compiler_data.ir_scope_property.add_invalidation_listener do |new_scope_property|
    root_scope = new_scope_property.get
    @ir_registry.clear
    @ir_registry.fill_registry(root_scope)
    read_registry_into_selector
    update_tabs
  end
end

Instance Attribute Details

#compiler_dataObject (readonly)

Returns the value of attribute compiler_data.



49
50
51
# File 'lib/jruby_visualizer/cfg_visualizer.rb', line 49

def compiler_data
  @compiler_data
end

#ir_registryObject (readonly)

Returns the value of attribute ir_registry.



49
50
51
# File 'lib/jruby_visualizer/cfg_visualizer.rb', line 49

def ir_registry
  @ir_registry
end

Instance Method Details

#get_selected_scopeObject



102
103
104
# File 'lib/jruby_visualizer/cfg_visualizer.rb', line 102

def get_selected_scope
  @ir_registry.scopes[@selected_scope.to_sym]
end

#open_cfg_tabObject



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/jruby_visualizer/cfg_visualizer.rb', line 81

def open_cfg_tab
  if @selected_scope.nil?
    return
  end

  tabs = @cfg_scopes_view.tabs
  is_tab_opened = tabs.find do |tab|
    # get string value from StringProperty name
    tab.text == @selected_scope
  end

  unless is_tab_opened
    tab = Tab.new(@selected_scope)
    cfg = get_selected_scope.cfg!
    tab.set_content(ControlFlowGraphView.new(cfg))
    tabs << tab
    # set focus on selected tab
    @cfg_scopes_view.selection_model.select(tab)
  end
end

#read_registry_into_selectorObject



67
68
69
70
71
72
73
74
# File 'lib/jruby_visualizer/cfg_visualizer.rb', line 67

def read_registry_into_selector
  scopes_keys = @ir_registry.scopes.keys.map do |key|
    key.to_s
  end
  scopes_keys.sort!
  @ir_scope_selector.items = FXCollections.observable_array_list(scopes_keys)
  @ir_scope_selector.value = @selected_scope = scopes_keys[0]
end

#select_scopeObject



76
77
78
79
# File 'lib/jruby_visualizer/cfg_visualizer.rb', line 76

def select_scope
  @selected_scope = @ir_scope_selector.value
  open_cfg_tab
end

#update_tabsObject



106
107
108
109
110
111
112
113
114
# File 'lib/jruby_visualizer/cfg_visualizer.rb', line 106

def update_tabs
  @cfg_scopes_view.tabs.each do |tab|
    scope_name = tab.text
    # TODO read and diff on custom cfg objects
    cfg = @ir_registry.scopes[scope_name.to_sym].cfg!
    # TODO listen to events if the ir scope changes
    tab.set_content(ControlFlowGraphView.new(cfg))
  end
end