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
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 87
def initialize(args, type:)
@args = Arguments.new(args.children)
@inline = []
@initialization = []
@type = type
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
202
203
204
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 202
def args_to_keep
@args.postargs.length
end
|
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 118
def
@args.args.each do |arg|
if @type == :iter
@initialization << arg.updated(:initialize_iter_arg)
else
end
@inline << arg
end
end
|
106
107
108
109
110
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 106
def
if (arg = @args.blockarg)
@initialization << arg.updated(:extract_blockarg)
end
end
|
152
153
154
155
156
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 152
def
@args.kwargs.each do |arg|
@initialization << arg.updated(:extract_kwarg)
end
end
|
158
159
160
161
162
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 158
def
@args.kwoptargs.each do |arg|
@initialization << arg.updated(:extract_kwoptarg)
end
end
|
164
165
166
167
168
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 164
def
if (arg = @args.kwrestarg)
@initialization << arg.updated(:extract_kwrestarg)
end
end
|
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 178
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
|
170
171
172
173
174
175
176
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 170
def
@args.postargs.each do |arg|
@initialization << arg.updated(:extract_post_arg)
@inline << s(:fake_arg)
end
end
|
194
195
196
197
198
199
200
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 194
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
112
113
114
115
116
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 112
def initialize_shadowargs
@args.shadowargs.each do |arg|
@initialization << arg.updated(:initialize_shadowarg)
end
end
|
#prepare_kwargs ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 139
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
133
134
135
136
137
|
# File 'opal/lib/opal/rewriters/inline_args.rb', line 133
def prepare_post_args
if @args.has_post_args?
@initialization << s(:prepare_post_args, @args.args.length)
end
end
|