Class: RedParse::VarNode

Inherits:
ValueNode show all
Includes:
FlattenedIvars
Defined in:
lib/redparse/node.rb

Constant Summary

Constants included from FlattenedIvars

FlattenedIvars::EXCLUDED_IVARS

Instance Attribute Summary collapse

Attributes inherited from Node

#errors, #parent

Attributes included from Stackable::Meta

#boolean_identity_params, #identity_params

Instance Method Summary collapse

Methods included from FlattenedIvars

#flattened_ivars, #flattened_ivars_equal?

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, #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!

Methods included from Stackable::Meta

#build_exemplars, #enumerate_exemplars, #identity_param

Methods included from Stackable

#identity_name

Constructor Details

#initialize(tok) ⇒ VarNode

Returns a new instance of VarNode.



1123
1124
1125
1126
1127
1128
1129
# File 'lib/redparse/node.rb', line 1123

def initialize(tok)
  super(tok.ident)
  @lvar_type=tok.lvar_type
  @offset=tok.offset
  @endline=@startline=tok.endline
  @in_def=tok.in_def
end

Instance Attribute Details

#endlineObject Also known as: startline

Returns the value of attribute endline.



1117
1118
1119
# File 'lib/redparse/node.rb', line 1117

def endline
  @endline
end

#in_defObject (readonly)

Returns the value of attribute in_def.



1118
1119
1120
# File 'lib/redparse/node.rb', line 1118

def in_def
  @in_def
end

#lvalueObject



1189
1190
1191
1192
# File 'lib/redparse/node.rb', line 1189

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

#lvar_typeObject (readonly)

Returns the value of attribute lvar_type.



1118
1119
1120
# File 'lib/redparse/node.rb', line 1118

def lvar_type
  @lvar_type
end

#offsetObject

Returns the value of attribute offset.



1117
1118
1119
# File 'lib/redparse/node.rb', line 1117

def offset
  @offset
end

Instance Method Details

#all_current_lvarsObject



1196
1197
1198
# File 'lib/redparse/node.rb', line 1196

def all_current_lvars
  lvar_type==:current ? [ident] : []
end

#dupObject



1201
1202
1203
1204
1205
# File 'lib/redparse/node.rb', line 1201

def dup
  result=super
  result.ident=ident.dup if ident
  return result
end

#lvalue_parsetree(o) ⇒ Object



1183
1184
1185
# File 'lib/redparse/node.rb', line 1183

def lvalue_parsetree(o)
  [varname2assigntype, ident.to_sym]
end

#parsetree(o) ⇒ Object



1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
# File 'lib/redparse/node.rb', line 1138

def parsetree(o)
  type=case ident[0]
   when ?$
     case ident[1]
     when ?1..?9; return [:nth_ref,ident[1..-1].to_i]
     when ?&,?+,?`,?'; return [:back_ref,ident[1].chr.to_sym] #`
     else :gvar
     end
   when ?@
     if ident[1]==?@
       :cvar
     else
       :ivar
     end
   when ?A..?Z; :const
   else 
     case lvar_type
     when :local; :lvar
     when :block; :dvar
     when :current; :dvar#_curr
     else fail
     end
   end
   return [type,ident.to_sym]
end

#unparse(o = default_unparse_options) ⇒ Object Also known as: lhs_unparse



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

def unparse o=default_unparse_options; ident end

#varname2assigntypeObject



1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
# File 'lib/redparse/node.rb', line 1164

def varname2assigntype
    case ident[0]
      when ?$; :gasgn
      when ?@
        if ident[1]!=?@;  :iasgn
        elsif in_def;     :cvasgn
        else              :cvdecl
        end
      when ?A..?Z; :cdecl
      else
        case lvar_type
        when :local; :lasgn
        when :block; :dasgn
        when :current; :dasgn_curr
        else fail
        end
    end
end