Class: Y2R::AST::YCP::YEPropagate

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

Constant Summary collapse

TYPES_WITH_SHORTCUT_CONVERSION =

Needs to be in sync with |Yast::Ops::SHORTCUT_TYPES| in Ruby bindings.

[
  "boolean",
  "float",
  "integer",
  "list",
  "locale",
  "map",
  "path",
  "string",
  "symbol",
  "term",
]

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



2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
# File 'lib/y2r/ast/ycp.rb', line 2277

def compile(context)
  if from.no_const != to.no_const
    if compile_as_shortcut?
      if child.is_a?(YEBracket)
        child.compile_as_shortcut(to.no_const, context)
      else
        Ruby::MethodCall.new(
          :receiver => Ruby::Variable.new(:name => "Convert"),
          :name     => "to_#{to.no_const}",
          :args     => [child.compile(context)],
          :block    => nil,
          :parens   => true
        )
      end
    else
      Ruby::MethodCall.new(
        :receiver => Ruby::Variable.new(:name => "Convert"),
        :name     => "convert",
        :args     => [
          child.compile(context),
          Ruby::HashEntry.new(
            :key   => Ruby::Literal.new(:value => :from),
            :value => Ruby::Literal.new(:value => from.no_const.to_s)
          ),
          Ruby::HashEntry.new(
            :key   => Ruby::Literal.new(:value => :to),
            :value => Ruby::Literal.new(:value => to.no_const.to_s)
          )
        ],
        :block    => nil,
        :parens   => true
      )
    end
  else
    child.compile(context)
  end
end