Class: Y2R::AST::YCP::Return

Inherits:
Node
  • Object
show all
Defined in:
lib/y2r/ast/ycp.rb

Instance Method Summary collapse

Methods inherited from Node

#compile_as_copy_if_needed, #compile_statements, #compile_statements_inside_block, #compile_statements_with_whitespace, #creates_local_scope?, #needs_copy?, #never_nil?, #optimize_last_statement, #optimize_next, #optimize_return, #remove_duplicate_imports, transfers_comments

Instance Method Details

#always_returns?Boolean

Returns:

  • (Boolean)


1793
1794
1795
# File 'lib/y2r/ast/ycp.rb', line 1793

def always_returns?
  true
end

#compile(context) ⇒ Object



1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
# File 'lib/y2r/ast/ycp.rb', line 1778

def compile(context)
  case context.innermost(DefBlock, FileBlock, UnspecBlock)
    when DefBlock, FileBlock
      Ruby::Return.new(
        :value => child ? child.compile_as_copy_if_needed(context) : nil
      )
    when UnspecBlock
      Ruby::Next.new(
        :value => child ? child.compile_as_copy_if_needed(context) : nil
      )
    else
      raise "Misplaced \"return\" statement."
  end
end