Class: Y2R::AST::YCP::Default

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)


1156
1157
1158
# File 'lib/y2r/ast/ycp.rb', line 1156

def always_returns?
  body.always_returns?
end

#compile(context) ⇒ Object



1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
# File 'lib/y2r/ast/ycp.rb', line 1140

def compile(context)
  if body.statements.last.is_a?(Break)
    # The following dance is here because we want ot keep the AST nodes
    # immutable and thus avoid modifying their data.

    body_without_break = body.dup
    body_without_break.statements = body.statements[0..-2]
  else
    body_without_break = body
  end

  context.inside self do |inner_context|
    Ruby::Else.new(:body => body_without_break.compile(inner_context))
  end
end

#symbolsObject



1136
1137
1138
# File 'lib/y2r/ast/ycp.rb', line 1136

def symbols
  []
end