Class: Y2R::AST::YCP::YEIs

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

Constant Summary collapse

KNOWN_SHORTCUTS =
[
  'any',
  'boolean',
  'byteblock',
  'float',
  'integer',
  'list',
  'locale',
  'map',
  'path',
  'string',
  'symbol',
  'term',
  'void',
]

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?, #never_nil?, #optimize_last_statement, #optimize_next, #optimize_return, #remove_duplicate_imports, transfers_comments

Instance Method Details

#compile(context) ⇒ Object



2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
# File 'lib/y2r/ast/ycp.rb', line 2234

def compile(context)
  if KNOWN_SHORTCUTS.include?(type.to_s)
    Ruby::MethodCall.new(
      :receiver => Ruby::Variable.new(:name => "Ops"),
      :name     => "is_#{type}?",
      :args     => [
        child.compile(context)
      ],
      :block    => nil,
      :parens   => true
    )
  else
    Ruby::MethodCall.new(
      :receiver => Ruby::Variable.new(:name => "Ops"),
      :name     => "is",
      :args     => [
        child.compile(context),
        Ruby::Literal.new(:value => type.to_s)
      ],
      :block    => nil,
      :parens   => true
    )
  end
end