Class: RedParse::UnOpNode

Inherits:
ValueNode show all
Defined in:
lib/redparse/node.rb,
lib/redparse/node.rb,
lib/redparse/ripper.rb,
lib/redparse/ReduceWithsFor_RedParse_1_9.rb,
lib/redparse/ReduceWithsFor_RedParse_1_8.rb

Direct Known Subclasses

UnaryAmpNode, UnaryStarNode

Constant Summary

Constants included from FlattenedIvars

FlattenedIvars::EXCLUDED_IVARS

Instance Attribute Summary collapse

Attributes inherited from Node

#endline, #errors, #offset, #parent, #startline

Attributes included from Stackable::Meta

#boolean_identity_params, #identity_params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ValueNode

#reducer_method

Methods inherited from Node

#+, #+@, #==, [], #[]=, #add_parent_links!, #args_rip, #begin_parsetree, #classic_inspect, #data, #deep_copy, #delete_extraneous_ivars!, #delete_linenums!, #depthwalk, #depthwalk_nodes, #error?, #evalable_inspect, #fixup_multiple_assignments!, #fixup_rescue_assignments!, #force_stmt_list_rip, #initialize_ivars, inline_symbols, #inspect, #lhs_unparse, #linerange, #lvars_defined_in, #merge_replacement_session, namelist, #negate, #original_brackets_assign, param_names, #parsetrees, #pretty_print, #prohibit_fixup, #replace_ivars_and_self, #replace_value, #rescue_parsetree, #rfind, #rfind_all, #rgrep, #rip_and_rescues, #rip_explode!, #short_inspect, #stmts_rip, #to_parsetree, #to_parsetree_and_warnings, #to_ruby, #to_s, #unary, #walk, #xform_tree!

Methods included from Stackable::Meta

#build_exemplars, #enumerate_exemplars, #identity_param

Methods included from FlattenedIvars

#flattened_ivars, #flattened_ivars_equal?

Methods included from Stackable

#identity_name

Constructor Details

#initialize(op, val, options = nil) ⇒ UnOpNode

Returns a new instance of UnOpNode.



1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
# File 'lib/redparse/node.rb', line 1776

def initialize(op,val,options=nil)
  @offset||=op.offset rescue val.offset
  op=op.ident if op.respond_to? :ident
  /([&*])$/===op and op=$1+"@"
  /^(?:!|not)$/===op and 
    val.respond_to? :special_conditions! and 
      val.special_conditions!
  args=[op,val]
  args<<options if options
  super(*args)
end

Instance Attribute Details

#lvalueObject



1795
1796
1797
1798
1799
1800
# File 'lib/redparse/node.rb', line 1795

def lvalue
#        return nil unless op=="*@"

  return @lvalue if defined? @lvalue
  @lvalue=true
end

Class Method Details

.create(op, val) ⇒ Object



1770
1771
1772
1773
1774
# File 'lib/redparse/node.rb', line 1770

def self.create(op,val)
  return UnaryStarNode.new(op,val) if /\*$/===op.ident
  return UnaryAmpNode.new(op,val) if /&$/===op.ident
  return new(op,val)
end

Instance Method Details

#argObject



1788
# File 'lib/redparse/node.rb', line 1788

def arg; val end

#arg=(x) ⇒ Object



1789
# File 'lib/redparse/node.rb', line 1789

def arg= x; self.val=x end

#imageObject



1793
# File 'lib/redparse/node.rb', line 1793

def image; "(#{op})" end

#lvalue_parsetree(o) ⇒ Object



1822
1823
1824
# File 'lib/redparse/node.rb', line 1822

def lvalue_parsetree(o)
  parsetree(o)
end

#parsetree(o) ⇒ Object



1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
# File 'lib/redparse/node.rb', line 1807

def parsetree(o)
  node=self
  node=node.val while UnOpNode===node and node.op=="+@"
  return node.parsetree(o) if LiteralNode&-{:val=>Integer|Float|Symbol}===node
  return node.parsetree(o) if StringNode&-{:char=>'/', :size=>1}===node

  case op
  when /^&/; [:block_arg, val.ident.to_sym]
  when "!","not"; [:not, val.rescue_parsetree(o)]
  when "defined?"; [:defined, val.parsetree(o)]
  else
    [:call, val.rescue_parsetree(o), op.to_sym]
  end
end

#reducer_identObject



17515
17516
17517
# File 'lib/redparse/ReduceWithsFor_RedParse_1_9.rb', line 17515

def reducer_ident
  :UnOpNode
end

#rip(p) ⇒ Object



125
126
127
# File 'lib/redparse/ripper.rb', line 125

def rip p
  p.on_unary(op.to_sym, val.rip(p))
end

#to_lispObject



1803
1804
1805
# File 'lib/redparse/node.rb', line 1803

def to_lisp
  "(#{op} #{val.to_lisp})"
end

#unparse(o = default_unparse_options) ⇒ Object



1826
1827
1828
1829
1830
1831
1832
# File 'lib/redparse/node.rb', line 1826

def unparse o=default_unparse_options
  op=op()
  op=op.chomp "@"
  result=op
  result+=" " if /(?:#{LETTER}|[?!])$/o===op or /^[+-]/===op && LiteralNode===val
  result+=val.unparse(o)
end