Class: Opal::Rewriters::InlineArgs::Initializer
- Inherits:
-
Base
- Object
- Parser::AST::Processor
- Base
- Opal::Rewriters::InlineArgs::Initializer
show all
- Defined in:
- opal/lib/opal/rewriters/inline_args.rb
Constant Summary
collapse
- STEPS =
%i[
extract_blockarg
initialize_shadowargs
extract_args
prepare_post_args
prepare_kwargs
extract_optargs
extract_restarg
extract_post_args
extract_kwargs
extract_kwoptargs
extract_kwrestarg
].freeze
Constants inherited
from Base
Base::DUMMY_LOCATION
Instance Attribute Summary collapse
Attributes inherited from Base
#current_node
Instance Method Summary
collapse
Methods inherited from Base
#append_to_body, #begin_with_stmts, #dynamic!, #error, #on_top, #prepend_to_body, #process, s, #s, #stmts_of
Constructor Details
#initialize(args, type:) ⇒ Initializer
Returns a new instance of Initializer.
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 87
def initialize(args, type:)
@args = Arguments.new(args.children)
@inline = []
@initialization = []
@type = type
@underscore_found = false
STEPS.each do |step|
send(step)
end
if @initialization.any?
@initialization = s(:begin, *@initialization)
else
@initialization = nil
end
end
|
Instance Attribute Details
#initialization ⇒ Object
Returns the value of attribute initialization.
68
69
70
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 68
def initialization
@initialization
end
|
#inline ⇒ Object
Returns the value of attribute inline.
68
69
70
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 68
def inline
@inline
end
|
Instance Method Details
#args_to_keep ⇒ Object
214
215
216
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 214
def args_to_keep
@args.postargs.length
end
|
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 119
def
@args.args.each do |arg|
if @type == :iter
@initialization << arg.updated(:initialize_iter_arg)
if arg.children[0] == :_
if @underscore_found
arg = s(:fake_arg)
end
@underscore_found = true
end
else
end
@inline << arg
end
end
|
107
108
109
110
111
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 107
def
if (arg = @args.blockarg)
@initialization << arg.updated(:extract_blockarg)
end
end
|
164
165
166
167
168
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 164
def
@args.kwargs.each do |arg|
@initialization << arg.updated(:extract_kwarg)
end
end
|
170
171
172
173
174
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 170
def
@args.kwoptargs.each do |arg|
@initialization << arg.updated(:extract_kwoptarg)
end
end
|
176
177
178
179
180
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 176
def
if (arg = @args.kwrestarg)
@initialization << arg.updated(:extract_kwrestarg)
end
end
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 190
def
has_post_args = @args.has_post_args?
@args.optargs.each do |arg|
if has_post_args
arg_name, default_value = *arg
@initialization << arg.updated(:extract_post_optarg, [arg_name, default_value, args_to_keep])
@inline << s(:fake_arg)
else
@inline << arg.updated(:arg)
@initialization << arg.updated(:extract_optarg)
end
end
end
|
182
183
184
185
186
187
188
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 182
def
@args.postargs.each do |arg|
@initialization << arg.updated(:extract_post_arg)
@inline << s(:fake_arg)
end
end
|
206
207
208
209
210
211
212
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 206
def
if (arg = @args.restarg)
arg_name = arg.children[0]
@initialization << arg.updated(:extract_restarg, [arg_name, args_to_keep])
@inline << s(:fake_arg)
end
end
|
#initialize_shadowargs ⇒ Object
113
114
115
116
117
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 113
def initialize_shadowargs
@args.shadowargs.each do |arg|
@initialization << arg.updated(:initialize_shadowarg)
end
end
|
#prepare_kwargs ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 151
def prepare_kwargs
return unless @args.has_any_kwargs?
if @args.can_inline_kwargs?
@inline << s(:arg, :'$kwargs')
else
@initialization << s(:extract_kwargs)
@inline << s(:fake_arg)
end
@initialization << s(:ensure_kwargs_are_kwargs)
end
|
#prepare_post_args ⇒ Object
145
146
147
148
149
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 145
def prepare_post_args
if @args.has_post_args?
@initialization << s(:prepare_post_args, @args.args.length)
end
end
|