Class: RedParse::CallSiteNode
Constant Summary
FlattenedIvars::EXCLUDED_IVARS
Instance Attribute Summary collapse
Attributes inherited from Node
#endline, #errors, #offset, #parent, #startline
#boolean_identity_params, #identity_params
Instance Method Summary
collapse
Methods inherited from Node
#+, #+@, #==, [], #[]=, #add_parent_links!, #begin_parsetree, create, #data, #deep_copy, #delete_extraneous_ivars!, #delete_linenums!, #depthwalk, #depthwalk_nodes, #error?, #evalable_inspect, #fixup_multiple_assignments!, #fixup_rescue_assignments!, #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, #to_parsetree, #to_parsetree_and_warnings, #unary, #walk, #xform_tree!
#build_exemplars, #enumerate_exemplars, #identity_param
#flattened_ivars, #flattened_ivars_equal?
Methods included from Stackable
#identity_name
Constructor Details
#initialize(method, open_paren, param_list, close_paren, block) ⇒ CallSiteNode
Returns a new instance of CallSiteNode.
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
|
# File 'lib/redparse/node.rb', line 2889
def initialize(method,open_paren,param_list,close_paren,block)
@not_real_parens=!open_paren || open_paren.not_real?
case param_list
when CommaOpNode
h,arrowrange=param_list.
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 nil
else
param_list=[param_list]
end
param_list.extend ListInNode if param_list
if block
@do_end=block.do_end
blockparams=block.params
block=block.body end
@offset=method.offset
if Token===method
method=method.ident
fail unless String===method
end
super(nil,method,param_list,blockparams,block)
end
|
Instance Attribute Details
#lvalue ⇒ Object
2971
2972
2973
2974
|
# File 'lib/redparse/node.rb', line 2971
def lvalue
return @lvalue if defined? @lvalue
@lvalue=true
end
|
Instance Method Details
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
|
# File 'lib/redparse/node.rb', line 3109
def blockformals_parsetree data,o 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
star[0]=ty
end
result.push star
end
end
result
end
|
#image ⇒ Object
2953
2954
2955
|
# File 'lib/redparse/node.rb', line 2953
def image
result="(#{receiver.image if receiver}.#{name})"
end
|
#lvalue_parsetree(o) ⇒ Object
identity_param :with_commas, false, true
2964
2965
2966
2967
2968
2969
|
# File 'lib/redparse/node.rb', line 2964
def lvalue_parsetree(o)
result=parsetree(o)
result[0]=:attrasgn
result[2]="#{result[2]}=".to_sym
result
end
|
#parsetree(o) ⇒ Object
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
|
# File 'lib/redparse/node.rb', line 3058
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] }
result.push((body)) end
else
result.push body
end
end
result
end
|
#parsetree_with_params(o) ⇒ Object
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
|
# File 'lib/redparse/node.rb', line 2990
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
if is_kw and !receiver
if singlearg and "super"!=methodname
result=[methodsym, singlearg.parsetree(o)]
result.push(true) if methodname=="yield" and ArrayLiteralNode===singlearg 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 result=[:call, receiver.rescue_parsetree(o), *result]
end
if unamp_expr
result=[:block_pass, unamp_expr.rescue_parsetree(o), result]
end
return result
end
|
#real_parens ⇒ Object
2930
|
# File 'lib/redparse/node.rb', line 2930
def real_parens; !@not_real_parens end
|
#real_parens=(x) ⇒ Object
2931
|
# File 'lib/redparse/node.rb', line 2931
def real_parens= x; @not_real_parens=!x end
|
#set_receiver!(expr) ⇒ Object
2986
2987
2988
|
# File 'lib/redparse/node.rb', line 2986
def set_receiver!(expr)
self[0]=expr
end
|
#to_lisp ⇒ Object
2979
2980
2981
|
# File 'lib/redparse/node.rb', line 2979
def to_lisp
"(#{receiver.to_lisp} #{self[1..-1].map{|x| x.to_lisp}.join(' ')})"
end
|
#unparse(o = default_unparse_options) ⇒ Object
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
|
# File 'lib/redparse/node.rb', line 2933
def unparse o=default_unparse_options
fail if block==false
result=[
receiver&&receiver.unparse(o)+'.',name,
real_parens ? '(' : (' ' if params),
params&¶ms.map{|param| unparse_nl(param,o,'',"\\\n")+param.unparse(o) }.join(', '),
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 ⇒ Object
2957
2958
2959
2960
|
# File 'lib/redparse/node.rb', line 2957
def with_commas
!real_parens and
args and args.size>0
end
|