Class: Y2R::AST::YCP::YEUnary
- Inherits:
-
Node
- Object
- OpenStruct
- Node
- Y2R::AST::YCP::YEUnary
show all
- Defined in:
- lib/y2r/ast/ycp.rb
Constant Summary
collapse
- OPS_TO_OPS =
{
"!" => "!"
}
- OPS_TO_OPS_OPTIONAL =
{
"-" => "-",
"~" => "~",
}
- OPS_TO_METHODS =
{
"-" => "unary_minus",
"~" => "bitwise_not",
}
Instance Method Summary
collapse
Methods inherited from Node
#always_returns?, #compile_as_copy_if_needed, #compile_statements, #compile_statements_inside_block, #compile_statements_with_whitespace, #creates_local_scope?, #needs_copy?, #optimize_last_statement, #optimize_next, #optimize_return, #remove_duplicate_imports, transfers_comments
Instance Method Details
#compile(context) ⇒ Object
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
|
# File 'lib/y2r/ast/ycp.rb', line 2542
def compile(context)
if OPS_TO_OPS[name]
Ruby::UnaryOperator.new(
:op => OPS_TO_OPS[name],
:expression => child.compile(context)
)
elsif OPS_TO_METHODS[name]
if never_nil?
Ruby::UnaryOperator.new(
:op => OPS_TO_OPS_OPTIONAL[name],
:expression => child.compile(context)
)
else
Ruby::MethodCall.new(
:receiver => Ruby::Variable.new(:name => "Ops"),
:name => OPS_TO_METHODS[name],
:args => [child.compile(context)],
:block => nil,
:parens => true
)
end
else
raise "Unknown unary operator: #{name.inspect}."
end
end
|
#never_nil? ⇒ Boolean
2570
2571
2572
|
# File 'lib/y2r/ast/ycp.rb', line 2570
def never_nil?
return child.never_nil?
end
|