Class: Archruby::Ruby::TypeInference::Ruby::ProcessMethodArguments

Inherits:
SexpInterpreter
  • Object
show all
Defined in:
lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb

Instance Method Summary collapse

Constructor Details

#initialize(ast) ⇒ ProcessMethodArguments

Returns a new instance of ProcessMethodArguments.



7
8
9
10
11
12
13
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 7

def initialize(ast)
  super()
  @ast = ast
  @params = {}
  @current_dependency_class = []
  @current_dependency_class_name = nil
end

Instance Method Details

#build_full_name(const_name) ⇒ Object



69
70
71
72
73
74
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 69

def build_full_name(const_name)
  @current_dependency_class.unshift(const_name)
  full_class_path = @current_dependency_class.join('::')
  @current_dependency_class = []
  full_class_path
end

#parseObject



15
16
17
18
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 15

def parse
  process(@ast)
  @params
end

#process_args(exp) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 20

def process_args(exp)
  _, *args = exp
  if !args.empty?
    if args.first.class == Symbol
      @params[args.first] ||= Set.new
    else
      args.map! {|sub_tree| process(sub_tree) if sub_tree.class == Sexp}
    end
  end
end

#process_array(exp) ⇒ Object



92
93
94
95
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 92

def process_array(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end

#process_call(exp) ⇒ Object



43
44
45
46
47
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 43

def process_call(exp)
  _, receiver, method_name, *args = exp
  process(receiver)
  args.map! { |subtree| process(subtree) }
end

#process_colon2(exp) ⇒ Object



58
59
60
61
62
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 58

def process_colon2(exp)
  _, first_part, last_part = exp
  @current_dependency_class.unshift(last_part)
  process(first_part)
end

#process_colon3(exp) ⇒ Object



64
65
66
67
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 64

def process_colon3(exp)
  _, constant_name = exp
  @current_dependency_class_name = build_full_name("::#{constant_name}")
end

#process_const(exp) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 49

def process_const(exp)
  _, const_name = exp
  if !@current_dependency_class.empty?
    @current_dependency_class_name = build_full_name(const_name)
  else
    @current_dependency_class_name = const_name.to_s
  end
end

#process_cvar(exp) ⇒ Object



127
128
129
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 127

def process_cvar(exp)
  # class variable
end

#process_cvasgn(exp) ⇒ Object



108
109
110
111
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 108

def process_cvasgn(exp)
  _, class_var_name, *value = exp
  value.map! {|sub_tree| process(sub_tree)}
end

#process_false(exp) ⇒ Object



140
141
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 140

def process_false(exp)
end

#process_gvar(exp) ⇒ Object



146
147
148
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 146

def process_gvar(exp)
  #global variables
end

#process_hash(exp) ⇒ Object



76
77
78
79
80
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 76

def process_hash(exp)
  _, key, value = exp
  process(key)
  process(value)
end

#process_if(exp) ⇒ Object



82
83
84
85
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 82

def process_if(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree) if sub_tree.class == Sexp }
end

#process_iter(exp) ⇒ Object



102
103
104
105
106
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 102

def process_iter(exp)
  _, first_part, second_part, *body = exp
  process(first_part)
  body.map! {|sub_tree| process(sub_tree)}
end

#process_ivar(exp) ⇒ Object



97
98
99
100
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 97

def process_ivar(exp)
  _, var_name, *args = exp
  args.map! {|sub_tree| process(sub_tree)}
end

#process_kwarg(exp) ⇒ Object



87
88
89
90
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 87

def process_kwarg(exp)
  _, *args = exp
  args.map! { |subtree| process(subtree) if subtree.class == Sexp}
end

#process_lasgn(exp) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 31

def process_lasgn(exp)
  _, variable_name, *args = exp
  @params[variable_name] ||= Set.new
  args.map! {|sub_tree| process(sub_tree)}
  @params[variable_name].add(@current_dependency_class_name)
  @current_dependency_class_name = nil
end

#process_lit(exp) ⇒ Object



39
40
41
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 39

def process_lit(exp)
  _, value = exp
end

#process_lvar(exp) ⇒ Object



124
125
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 124

def process_lvar(exp)
end

#process_masgn(exp) ⇒ Object



113
114
115
116
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 113

def process_masgn(exp)
  _, *args = exp
  args.map! {|sub_tree| process(sub_tree) if sub_tree.class == Sexp}
end

#process_nil(exp) ⇒ Object



134
135
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 134

def process_nil(exp)
end

#process_or(exp) ⇒ Object



118
119
120
121
122
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 118

def process_or(exp)
  _, left_side, right_side = exp
  process(left_side)
  process(right_side)
end

#process_self(exp) ⇒ Object



143
144
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 143

def process_self(exp)
end

#process_str(exp) ⇒ Object



137
138
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 137

def process_str(exp)
end

#process_true(exp) ⇒ Object



131
132
# File 'lib/archruby/ruby/type_inference/ruby/process_method_arguments.rb', line 131

def process_true(exp)
end