Class: TurboTest::StaticAnalysis::Constants::SexpBuilder

Inherits:
Ripper::SexpBuilder
  • Object
show all
Includes:
NodeMaker, NodeProcessor, TokenMatcher
Defined in:
lib/turbo_test_static_analysis/constants/sexp_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, filename = "-", lineno = 1) ⇒ SexpBuilder

Returns a new instance of SexpBuilder.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 19

def initialize(path, filename = "-", lineno = 1)
  @const_refs = {}
  @referenced_top_constants = {}
  @referenced_constants = {}
  @class_nodes = []
  @defined_classes = []
  @all_nodes = []
  @var_refs = []
  @block_nodes = []
  super
end

Instance Attribute Details

#defined_classesObject (readonly)

Returns the value of attribute defined_classes.



13
14
15
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 13

def defined_classes
  @defined_classes
end

#referenced_constantsObject (readonly)

Returns the value of attribute referenced_constants.



13
14
15
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 13

def referenced_constants
  @referenced_constants
end

#referenced_top_constantsObject (readonly)

Returns the value of attribute referenced_top_constants.



13
14
15
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 13

def referenced_top_constants
  @referenced_top_constants
end

Instance Method Details

#on_const_ref(token) ⇒ Object



66
67
68
69
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 66

def on_const_ref(token)
  add_const_ref token
  super
end

#on_def(token_one, token_two, token_three) ⇒ Object



82
83
84
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 82

def on_def(token_one, token_two, token_three)
  super
end

#on_defs(token_one, token_two, token_three, token_four, token_five) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 50

def on_defs(token_one, token_two, token_three, token_four, token_five)
  if singleton_method_definition_with_self?(token_one)
    create_singleton_method_definition_with_self_node(token_one)
  elsif singleton_method_definition_with_constant?(token_one)
    node = create_singleton_method_definition_with_constant_node(token_one)
    process_module(node)
  end
  super
end

#on_method_add_block(token_one, token_two) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 86

def on_method_add_block(token_one, token_two)
  add_block_node(token_one)
  if const_class_or_module_eval?(token_one)
    node = find_or_new_node_for_const_class_or_module_eval(token_one)
    process_module node
  elsif ident_class_or_module_eval?(token_one)
    node = ident_class_or_module_eval_node(token_one)
    reject_children_in_class_nodes(node)
  end
  super
end

#on_module(token_one, token_two, token_three = nil) ⇒ Object Also known as: on_class



44
45
46
47
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 44

def on_module(token_one, token_two, token_three = nil)
  process_module find_and_update_node(token_one)
  super
end

#on_program(token_one) ⇒ Object



98
99
100
101
102
103
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 98

def on_program(token_one)
  process_class_nodes
  process_var_refs
  reject_unknown_constants
  super
end

#on_sclass(token_one, token_two) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 31

def on_sclass(token_one, token_two)
  node = if top_const_ref?(token_one)
           create_top_singleton_class_node(token_one)
         elsif var_ref?(token_one)
           create_var_ref_singleton_class_node(token_one)
         else
           create_singleton_class_node(token_one)
         end
  process_module(node)
  @all_nodes.shift if top_const_ref?(token_one)
  super
end

#on_top_const_field(token) ⇒ Object



77
78
79
80
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 77

def on_top_const_field(token)
  add_referenced_top_constant token[1]
  super
end

#on_top_const_ref(token) ⇒ Object



60
61
62
63
64
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 60

def on_top_const_ref(token)
  add_const_ref token, top_level: true
  add_referenced_top_constant token[1]
  super
end

#on_var_ref(token) ⇒ Object Also known as: on_var_field



71
72
73
74
# File 'lib/turbo_test_static_analysis/constants/sexp_builder.rb', line 71

def on_var_ref(token)
  @var_refs << new_node_from_token(token, [lineno, column]) if token[0] == :@const
  super
end