Class: Rubinius::AST::IterArguments
- Defined in:
- lib/compiler/ast/sends.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#arity ⇒ Object
Returns the value of attribute arity.
-
#optional ⇒ Object
Returns the value of attribute optional.
-
#prelude ⇒ Object
Returns the value of attribute prelude.
-
#required_args ⇒ Object
(also: #total_args)
Returns the value of attribute required_args.
-
#splat_index ⇒ Object
Returns the value of attribute splat_index.
Attributes inherited from Node
Instance Method Summary collapse
-
#initialize(line, arguments) ⇒ IterArguments
constructor
A new instance of IterArguments.
- #names ⇒ Object
- #post_args ⇒ Object
- #to_sexp ⇒ Object
Methods inherited from Node
#ascii_graph, #attributes, #children, match_arguments?, match_send?, #new_block_generator, #new_generator, #node_name, node_name, #pos, #set_child, transform, #transform, transform_comment, transform_kind, transform_kind=, transform_name, #visit, #walk
Constructor Details
#initialize(line, arguments) ⇒ IterArguments
Returns a new instance of IterArguments.
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/compiler/ast/sends.rb', line 363 def initialize(line, arguments) @line = line @optional = 0 @arguments = nil @splat_index = -1 @required_args = 0 @splat = nil @block = nil @prelude = nil case arguments when Fixnum @splat_index = nil @arity = 0 @prelude = nil when MultipleAssignment arguments.iter_arguments if arguments.splat case arguments.splat when EmptySplat @splat_index = -2 arguments.splat = nil @prelude = :empty else @splat = arguments.splat = arguments.splat.value end @optional = 1 if arguments.left @prelude = :multi size = arguments.left.body.size @arity = -(size + 1) @required_args = size else @prelude = :splat unless @prelude @arity = -1 end elsif arguments.left size = arguments.left.body.size @prelude = :multi @arity = size @required_args = size # distinguish { |a, | ... } from { |a| ... } @splat_index = nil unless size == 1 else @splat_index = 0 @prelude = :multi @arity = -1 end @block = arguments.block @arguments = arguments when nil @arity = -1 @splat_index = -2 # -2 means accept the splat, but don't store it anywhere @prelude = nil when BlockPass @arity = -1 @splat_index = -2 @prelude = nil @block = arguments else # Assignment @splat_index = nil @arguments = arguments @arity = 1 @required_args = 1 @prelude = :single end end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
360 361 362 |
# File 'lib/compiler/ast/sends.rb', line 360 def arguments @arguments end |
#arity ⇒ Object
Returns the value of attribute arity.
360 361 362 |
# File 'lib/compiler/ast/sends.rb', line 360 def arity @arity end |
#optional ⇒ Object
Returns the value of attribute optional.
360 361 362 |
# File 'lib/compiler/ast/sends.rb', line 360 def optional @optional end |
#prelude ⇒ Object
Returns the value of attribute prelude.
360 361 362 |
# File 'lib/compiler/ast/sends.rb', line 360 def prelude @prelude end |
#required_args ⇒ Object Also known as: total_args
Returns the value of attribute required_args.
361 362 363 |
# File 'lib/compiler/ast/sends.rb', line 361 def required_args @required_args end |
#splat_index ⇒ Object
Returns the value of attribute splat_index.
360 361 362 |
# File 'lib/compiler/ast/sends.rb', line 360 def splat_index @splat_index end |
Instance Method Details
#names ⇒ Object
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/compiler/ast/sends.rb', line 443 def names case @arguments when MultipleAssignment if arguments = @arguments.left.body array = arguments.map { |x| x.name } else array = [] end if @arguments.splat.kind_of? SplatAssignment array << @arguments.splat.name end array when nil [] else [@arguments.name] end end |
#post_args ⇒ Object
439 440 441 |
# File 'lib/compiler/ast/sends.rb', line 439 def post_args 0 end |
#to_sexp ⇒ Object
464 465 466 467 468 469 470 471 472 |
# File 'lib/compiler/ast/sends.rb', line 464 def to_sexp if @arguments @arguments.to_sexp elsif @arity == 0 0 else nil end end |