class RedParse::ListInNode::CallSiteNode

Attributes

lvalue[W]

Public Class Methods

new(*args) click to toggle source
Calls superclass method RedParse::ListInNode::Node::new
# File lib/redparse/node.rb, line 3070
      def initialize(*args)
        if KeywordToken===args.first and args.first.ident=='('
          method,open_paren,param_list,close_paren,block="()",*args
          parened=open_paren
        else 
          method,open_paren,param_list,close_paren,block=*args
          @not_real_parens=!open_paren || open_paren.not_real?
        end

        if KeywordToken===method and method.ident=='->'
          if SequenceNode===param_list
            blockparams,blocklocals,* = param_list
            if CommaOpNode===blocklocals
              blocklocals=Array(blocklocals)
            else
              blocklocals=[blocklocals]
            end
            blocklocals.map!{|bl| bl.ident}
            blocklocals.extend ListInNode
          else
            blockparams= param_list
          end

          if CommaOpNode===blockparams
            blockparams=Array(blockparams)
          elsif blockparams
            blockparams=[blockparams]
          end

          blockparams=BlockParams.new blockparams if blockparams
          param_list=nil
        end

        case param_list
        when CommaOpNode
          #handle inlined hash pairs in param list (if any)
#          compr=Object.new
#          def compr.==(other) ArrowOpNode===other end
          h,arrowrange=param_list.extract_unbraced_hash
          param_list=Array.new(param_list)
          param_list[arrowrange]=[h] if arrowrange
        
        when ArrowOpNode
          h=HashLiteralNode.new(nil,param_list,nil)
          h.startline=param_list.startline
          h.endline=param_list.endline
          param_list=[h]
#        when KeywordOpNode
#          fail "didn't expect '#{param_list.inspect}' inside actual parameter list"
        when nil
        else
          param_list=[param_list]
        end

        param_list.extend ListInNode if param_list

        if block
          @do_end=block.do_end
          blockparams||=block.params
          blocklocals||=block.locals
          block=block.body #||[]
        end
        if Token===method 
          @offset=method.offset
          method=method.ident
          fail unless String===method
        else
          @offset=parened&&parened.offset
        end

        super(nil,method,param_list,blockparams,blocklocals,block)
        #receiver, if any, is tacked on later
      end

Public Instance Methods

blockformals_parsetree(data,o) click to toggle source
# File lib/redparse/node.rb, line 3331
      def blockformals_parsetree data,o  #dead code?
        data.empty? and return nil 
        data=data.dup
        star=data.pop if UnaryStarNode===data.last
        result=data.map{|x| x.parsetree(o) }
=begin
 {          if VarNode===x
            ident=x.ident
            ty=x.varname2assigntype
#            ty==:lasgn and ty=:dasgn_curr
            [ty, ident.to_sym] 
          else
            x=x.parsetree(o)
            if x[0]==:call
              x[0]=:attrasgn
              x[2]="#{x[2]}=".to_sym
            end
            x
          end
        }
=end
        if result.size==0
          star or fail
          result=[:masgn, star.parsetree(o).last]
        elsif result.size==1 and !star
          result=result.first
        else
          result=[:masgn, [:array, *result]]
          if star 
            old=star= star.val
            star=star.parsetree(o)
            if star[0]==:call
              star[0]=:attrasgn
              star[2]="#{star[2]}=".to_sym
            end

            if VarNode===old
              ty=old.varname2assigntype
#              ty==:lasgn and ty=:dasgn_curr
              star[0]=ty
            end
            result.push star
          end
        end
        result
      end
has_parens?()
Alias for: real_parens
image() click to toggle source
# File lib/redparse/node.rb, line 3175
def image
  "(#{receiver.image if receiver}.#{name})"
end
lvalue() click to toggle source
# File lib/redparse/node.rb, line 3193
def lvalue
  return @lvalue if defined? @lvalue
  @lvalue=true
end
lvalue_parsetree(o) click to toggle source

identity_param :with_commas, false, true

# File lib/redparse/node.rb, line 3186
def lvalue_parsetree(o)
  result=parsetree(o)
  result[0]=:attrasgn
  result[2]="#{result[2]}=".to_sym
  result
end
parsetree(o) click to toggle source
# File lib/redparse/node.rb, line 3280
def parsetree(o)
  callsite=parsetree_with_params o
  return callsite unless blockparams or block
  call=name
  callsite[0]=:fcall  if callsite[0]==:call or callsite[0]==:vcall
  unless receiver
    case call
    when "BEGIN"
      if o[:quirks]
        return []
      else
        callsite=[:preexe] 
      end
    when "END"; callsite=[:postexe]
    end
  else
    callsite[0]=:call if callsite[0]==:fcall
  end

  if blockparams
    bparams=blockparams.dup
    lastparam=bparams.last
    amped=bparams.pop.val if UnOpNode===lastparam and lastparam.op=="&@"
    bparams=bparams.parsetree(o)||0
    if amped
      bparams=[:masgn, [:array, bparams]] unless bparams==0 or bparams.first==:masgn
      bparams=[:block_pass, amped.lvalue_parsetree(o), bparams]
    end
  else
    bparams=nil
  end
  result=[:iter, callsite, bparams]
  unless block.empty?
    body=block.parsetree(o)
    if curr_vars=block.lvars_defined_in
      curr_vars-=blockparams.all_current_lvars if blockparams
      if curr_vars.empty?
        result.push body
      else
        curr_vars.map!{|cv| [:dasgn_curr, cv.to_sym] }
        (0...curr_vars.size-1).each{|i| curr_vars[i]<<curr_vars[i+1] }
        #body.first==:block ? body.shift : body=[body]
        result.push((body)) #.unshift curr_vars[0]))
      end
    else
      result.push body
    end
  end 
  result
end
parsetree_with_params(o) click to toggle source
# File lib/redparse/node.rb, line 3212
      def parsetree_with_params o
        args=args()||[]
        if (UnOpNode===args.last and args.last.ident=="&@")
          lasti=args.size-2
          unamp_expr=args.last.val
        else
          lasti=args.size-1
        end
        methodname= name
        methodname= methodname.chop if /^[~!]@$/===methodname
        methodsym=methodname.to_sym
        is_kw= RubyLexer::FUNCLIKE_KEYWORDS&~/^(BEGIN|END|raise)$/===methodname

        result=
        if lasti==-1
          [(@not_real_parens and /[!?]$/!~methodname and !unamp_expr) ? 
             :vcall : :fcall, methodsym
          ]
        elsif (UnaryStarNode===args[lasti])
          if lasti.zero?
            [:fcall, methodsym, args.first.rescue_parsetree(o)]
          else
            [:fcall, methodsym, 
             [:argscat, 
               [:array, *args[0...lasti].map{|x| x.rescue_parsetree(o) } ], 
                  args[lasti].val.rescue_parsetree(o) 
             ]
            ]
          end         
        else
          singlearg= lasti.zero?&&args.first
          [:fcall, methodsym, 
           [:array, *args[0..lasti].map{|x| x.rescue_parsetree(o) } ]
          ]
        end

        result[0]=:vcall if block #and /\Af?call\Z/===result[0].to_s

        if is_kw and !receiver
          if singlearg and "super"!=methodname
            result=[methodsym, singlearg.parsetree(o)]
            result.push(true) if methodname=="yield" and ArrayLiteralNode===singlearg #why???!!
            return result
          end
          breaklike=  /^(break|next|return)$/===methodname
          if @not_real_parens
              return [:zsuper] if "super"==methodname and !args()
          else
              return [methodsym, [:nil]] if breaklike and args.size.zero?
          end
          result.shift 
          arg=result[1]
          result[1]=[:svalue,arg] if arg and arg[0]==:splat and breaklike
        end

        if receiver
          result.shift if result.first==:vcall or result.first==:fcall #if not kw
          result=[:call, receiver.rescue_parsetree(o), *result]
        end

        if unamp_expr
#          result[0]=:fcall if lasti.zero?
          result=[:block_pass, unamp_expr.rescue_parsetree(o), result]
        end

        return result
      end
real_parens() click to toggle source
# File lib/redparse/node.rb, line 3144
def real_parens; @not_real_parens||=nil; !@not_real_parens end
Also aliased as: has_parens?
real_parens=(x;) click to toggle source
# File lib/redparse/node.rb, line 3145
def real_parens= x; @not_real_parens=!x end
set_receiver!(expr) click to toggle source
# File lib/redparse/node.rb, line 3208
def set_receiver!(expr)
  self[0]=expr
end
to_lisp() click to toggle source
# File lib/redparse/node.rb, line 3201
def to_lisp
  "(#{receiver.to_lisp} #{self[1..-1].map{|x| x.to_lisp}.join(' ')})"
end
unparse(o=default_unparse_options) click to toggle source
# File lib/redparse/node.rb, line 3148
def unparse o=default_unparse_options
  fail if block==false
  parensadded=[false]
  params=params()
  params&&=params.map{|param|  
    unparse_nl(param,o,'',"\\\n")+param.unparse_maybe_parens(o,parensadded)  
  }.join(', ')
  real_parens=real_parens() || parensadded[0]
  result=[
   receiver&&receiver.unparse(o)+'.',
   name=='()' ? '' : name,
   real_parens ? '(' : (' ' if params),
   params,
   real_parens ? ')' : nil,
  
   block&&[
     @do_end ? " do " : "{", 
       block_params&&block_params.unparse(o),
       unparse_nl(block,o," "),
       block.unparse(o),
       unparse_nl(endline,o),
     @do_end ? " end" : "}"
   ]
  ]
  return result.join
end
with_commas() click to toggle source
# File lib/redparse/node.rb, line 3179
def with_commas
   !real_parens and 
   args and args.size>0
end