Class: Rubinius::ToolSet.current::TS::AST::RescueCondition
- Defined in:
- lib/rubinius/ast/exceptions.rb
Instance Attribute Summary collapse
-
#assignment ⇒ Object
Returns the value of attribute assignment.
-
#body ⇒ Object
Returns the value of attribute body.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#next ⇒ Object
Returns the value of attribute next.
-
#splat ⇒ Object
Returns the value of attribute splat.
Attributes inherited from Node
Instance Method Summary collapse
- #assignment?(node) ⇒ Boolean
- #bytecode(g, reraise, done, outer_exc_state) ⇒ Object
-
#initialize(line, conditions, body, nxt) ⇒ RescueCondition
constructor
A new instance of RescueCondition.
- #to_sexp ⇒ 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, conditions, body, nxt) ⇒ RescueCondition
Returns a new instance of RescueCondition.
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 |
# File 'lib/rubinius/ast/exceptions.rb', line 373 def initialize(line, conditions, body, nxt) @line = line @next = nxt @splat = nil @assignment = nil case conditions when ArrayLiteral @conditions = conditions when ConcatArgs @conditions = conditions.array @splat = RescueSplat.new line, conditions.rest when SplatValue @splat = RescueSplat.new line, conditions.value when nil condition = ConstantAccess.new line, :StandardError, true @conditions = ArrayLiteral.new line, [condition] end case body when Block @assignment = body.array.shift if assignment? body.array.first @body = body when nil @body = NilLiteral.new line else if assignment? body @assignment = body @body = NilLiteral.new line else @body = body end end end |
Instance Attribute Details
#assignment ⇒ Object
Returns the value of attribute assignment.
371 372 373 |
# File 'lib/rubinius/ast/exceptions.rb', line 371 def assignment @assignment end |
#body ⇒ Object
Returns the value of attribute body.
371 372 373 |
# File 'lib/rubinius/ast/exceptions.rb', line 371 def body @body end |
#conditions ⇒ Object
Returns the value of attribute conditions.
371 372 373 |
# File 'lib/rubinius/ast/exceptions.rb', line 371 def conditions @conditions end |
#next ⇒ Object
Returns the value of attribute next.
371 372 373 |
# File 'lib/rubinius/ast/exceptions.rb', line 371 def next @next end |
#splat ⇒ Object
Returns the value of attribute splat.
371 372 373 |
# File 'lib/rubinius/ast/exceptions.rb', line 371 def splat @splat end |
Instance Method Details
#assignment?(node) ⇒ Boolean
408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/rubinius/ast/exceptions.rb', line 408 def assignment?(node) case node when VariableAssignment value = node.value when AttributeAssignment value = node.arguments.array.last else return false end return true if value.kind_of? CurrentException end |
#bytecode(g, reraise, done, outer_exc_state) ⇒ Object
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/rubinius/ast/exceptions.rb', line 421 def bytecode(g, reraise, done, outer_exc_state) pos(g) body = g.new_label # Exception has left the current exception on the top # of the stack, use it rather than using push_current_exception. if @conditions @conditions.body.each do |c| g.dup c.bytecode(g) g.swap g.send :===, 1 g.git body end end @splat.bytecode(g, body) if @splat if @next if_false = g.new_label g.goto if_false else g.goto reraise end body.set! # Remove the current exception from the top of the stack now # that we've hit a handler g.pop if @assignment @assignment.bytecode(g) g.pop end current_break = g.break g.break = g.new_label current_next = g.next g.next = g.new_label g.state.push_rescue(outer_exc_state) @body.bytecode(g) g.state.pop_rescue g.clear_exception g.goto done if g.break.used? g.break.set! g.clear_exception # Reset the outer exception g.push_stack_local outer_exc_state g.restore_exception_state if current_break g.goto current_break else g.raise_break end end g.break = current_break if g.next.used? g.next.set! g.clear_exception # Reset the outer exception g.push_stack_local outer_exc_state g.restore_exception_state if current_next g.goto current_next else g.ret end end g.next = current_next if @next if_false.set! @next.bytecode(g, reraise, done, outer_exc_state) end end |
#to_sexp ⇒ Object
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/rubinius/ast/exceptions.rb', line 512 def to_sexp array = @conditions.to_sexp array << @assignment.to_sexp if @assignment array << @splat.to_sexp if @splat sexp = [:resbody, array] case @body when Block sexp << (@body ? @body.array.map { |x| x.to_sexp } : nil) when nil sexp << nil else sexp << @body.to_sexp end sexp << @next.to_sexp if @next sexp end |