Class: Y2R::AST::YCP::If
- Inherits:
-
Node
- Object
- OpenStruct
- Node
- Y2R::AST::YCP::If
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
1397
1398
1399
1400
1401
1402
1403
1404
1405
|
# File 'lib/y2r/ast/ycp.rb', line 1397
def always_returns?
if self.then && self.else
self.then.always_returns? && self.else.always_returns?
else
false
end
end
|
#compile(context) ⇒ Object
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
|
# File 'lib/y2r/ast/ycp.rb', line 1374
def compile(context)
then_context = context.disable_elsif
then_compiled = compile_statements(self.then, then_context)
if self.else
else_context = if self.else.is_a?(If)
context.enable_elsif
else
context.disable_elsif
end
else_compiled = compile_statements(self.else, else_context)
else
else_compiled = nil
end
Ruby::If.new(
:condition => cond.compile(context),
:then => then_compiled,
:else => else_compiled,
:elsif => !!context.elsif_mode
)
end
|