Class: Y2R::AST::YCP::Symbol

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

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

Instance Method Details

#compile(context) ⇒ Object



1847
1848
1849
# File 'lib/y2r/ast/ycp.rb', line 1847

def compile(context)
  RubyVar.for(nil, name, context, :in_arg)
end

#compile_as_copy_arg_call(context) ⇒ Object



1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
# File 'lib/y2r/ast/ycp.rb', line 1851

def compile_as_copy_arg_call(context)
  Ruby::Assignment.new(
    :lhs => RubyVar.for(nil, name, context, :in_code),
    :rhs => Ruby::MethodCall.new(
      :receiver => nil,
      :name     => "deep_copy",
      :args     => [RubyVar.for(nil, name, context, :in_code)],
      :block    => nil,
      :parens   => true
    )
  )
end

#compile_as_publish_call(context) ⇒ Object



1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
# File 'lib/y2r/ast/ycp.rb', line 1864

def compile_as_publish_call(context)
  args = [
    Ruby::HashEntry.new(
      :key   => Ruby::Literal.new(:value => category),
      :value => Ruby::Literal.new(:value => name.to_sym)
    ),
    Ruby::HashEntry.new(
      :key   => Ruby::Literal.new(:value => :type),
      :value => Ruby::Literal.new(:value => type.to_s)
    )
  ]

  unless global
    args << Ruby::HashEntry.new(
      :key   => Ruby::Literal.new(:value => :private),
      :value => Ruby::Literal.new(:value => true)
    )
  end

  Ruby::MethodCall.new(
    :receiver => nil,
    :name     => "publish",
    :args     => args,
    :block    => nil,
    :parens   => false
  )
end

#needs_copy?Boolean

Returns:

  • (Boolean)


1843
1844
1845
# File 'lib/y2r/ast/ycp.rb', line 1843

def needs_copy?
  type.needs_copy?
end