Class: Rubinius::ToolSet.current::TS::AST::FormalArguments
- Defined in:
- lib/rubinius/ast/definitions.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#block_arg ⇒ Object
Returns the value of attribute block_arg.
-
#block_index ⇒ Object
readonly
Returns the value of attribute block_index.
-
#defaults ⇒ Object
Returns the value of attribute defaults.
-
#names ⇒ Object
Returns the value of attribute names.
-
#optional ⇒ Object
Returns the value of attribute optional.
-
#required ⇒ Object
Returns the value of attribute required.
-
#splat ⇒ Object
Returns the value of attribute splat.
Attributes inherited from Node
Instance Method Summary collapse
- #bytecode(g) ⇒ Object
-
#initialize(line, args, defaults, splat) ⇒ FormalArguments
constructor
A new instance of FormalArguments.
- #map_arguments(scope) ⇒ Object
- #post_args ⇒ Object
- #required_args ⇒ Object (also: #arity)
- #splat_index ⇒ Object
- #to_actual(line) ⇒ Object
- #to_sexp ⇒ Object
- #total_args ⇒ Object
Methods inherited from Node
#ascii_graph, #attributes, #children, #defined, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, #or_bytecode, #pos, #set_child, #transform, transform, transform_comment, transform_kind, transform_kind=, transform_name, #value_defined, #visit, #walk
Constructor Details
#initialize(line, args, defaults, splat) ⇒ FormalArguments
Returns a new instance of FormalArguments.
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/rubinius/ast/definitions.rb', line 284 def initialize(line, args, defaults, splat) @line = line @defaults = nil @block_arg = nil @block_index = nil if defaults defaults = DefaultArguments.new line, defaults @defaults = defaults @optional = defaults.names stop = defaults.names.first last = args.each_with_index { |a, i| break i if a == stop } @required = args[0, last] else @required = args.dup @optional = [] end if splat.kind_of? Symbol args << splat elsif splat splat = :* args << splat end @names = args @splat = splat end |
Instance Attribute Details
#block_arg ⇒ Object
Returns the value of attribute block_arg.
282 283 284 |
# File 'lib/rubinius/ast/definitions.rb', line 282 def block_arg @block_arg end |
#block_index ⇒ Object (readonly)
Returns the value of attribute block_index.
282 283 284 |
# File 'lib/rubinius/ast/definitions.rb', line 282 def block_index @block_index end |
#defaults ⇒ Object
Returns the value of attribute defaults.
281 282 283 |
# File 'lib/rubinius/ast/definitions.rb', line 281 def defaults @defaults end |
#names ⇒ Object
Returns the value of attribute names.
281 282 283 |
# File 'lib/rubinius/ast/definitions.rb', line 281 def names @names end |
#optional ⇒ Object
Returns the value of attribute optional.
281 282 283 |
# File 'lib/rubinius/ast/definitions.rb', line 281 def optional @optional end |
#required ⇒ Object
Returns the value of attribute required.
281 282 283 |
# File 'lib/rubinius/ast/definitions.rb', line 281 def required @required end |
#splat ⇒ Object
Returns the value of attribute splat.
281 282 283 |
# File 'lib/rubinius/ast/definitions.rb', line 281 def splat @splat end |
Instance Method Details
#bytecode(g) ⇒ Object
320 321 322 323 324 325 326 327 |
# File 'lib/rubinius/ast/definitions.rb', line 320 def bytecode(g) g.state.check_for_locals = false map_arguments g.state.scope @defaults.bytecode(g) if @defaults @block_arg.bytecode(g) if @block_arg g.state.check_for_locals = true end |
#map_arguments(scope) ⇒ Object
352 353 354 355 356 357 |
# File 'lib/rubinius/ast/definitions.rb', line 352 def map_arguments(scope) @required.each { |arg| scope.new_local arg } @defaults.map_arguments scope if @defaults scope.new_local @splat if @splat.kind_of? Symbol scope.assign_local_reference @block_arg if @block_arg end |
#post_args ⇒ Object
335 336 337 |
# File 'lib/rubinius/ast/definitions.rb', line 335 def post_args 0 end |
#required_args ⇒ Object Also known as: arity
329 330 331 |
# File 'lib/rubinius/ast/definitions.rb', line 329 def required_args @required.size end |
#splat_index ⇒ Object
343 344 345 346 347 348 349 350 |
# File 'lib/rubinius/ast/definitions.rb', line 343 def splat_index if @splat index = @names.size index -= 1 if @block_arg index -= 1 if @splat.kind_of? Symbol index end end |
#to_actual(line) ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/rubinius/ast/definitions.rb', line 359 def to_actual(line) arguments = ActualArguments.new line last = -1 last -= 1 if @block_arg and @block_arg.name == names[last] last -= 1 if @splat == names[last] arguments.array = @names[0..last].map { |name| LocalVariableAccess.new line, name } if @splat.kind_of? Symbol arguments.splat = SplatValue.new(line, LocalVariableAccess.new(line, @splat)) end arguments end |
#to_sexp ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/rubinius/ast/definitions.rb', line 375 def to_sexp sexp = [:args] @required.each { |x| sexp << x } sexp += @defaults.names if @defaults if @splat == :* sexp << :* elsif @splat sexp << :"*#{@splat}" end sexp += @post if @post sexp << :"&#{@block_arg.name}" if @block_arg sexp << [:block] + @defaults.to_sexp if @defaults sexp end |
#total_args ⇒ Object
339 340 341 |
# File 'lib/rubinius/ast/definitions.rb', line 339 def total_args @required.size + @optional.size end |