rubynode 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rubynode.rb ADDED
@@ -0,0 +1,206 @@
1
+
2
+ require "rubynode_ext"
3
+
4
+ class RubyNode
5
+
6
+ VERSION = "0.1.1"
7
+
8
+ NODE_ATTRIBS = {
9
+ :alias =>
10
+ lambda { |node|
11
+ { # ruby >1.8.4 doesn't have nd_new and nd_old
12
+ :new => ((node.respond_to?(:nd_new) && node.nd_new) || node.u1_node),
13
+ :old => ((node.respond_to?(:nd_old) && node.nd_old) || node.u2_node),
14
+ }
15
+ },
16
+ :alloca => [], # not supported
17
+ :and => {:first=>:nd_1st, :second=>:nd_2nd},
18
+ :args => [:cnt, :rest, :opt],
19
+ :argscat => [:body, :head],
20
+ :argspush => [:body, :head],
21
+ :array => [:head, :alen, :next],
22
+ :attrasgn => [:mid, :args, :recv],
23
+ :attrset => [:vid],
24
+ :back_ref => [:nth, :cnt],
25
+ :begin => [:body],
26
+ :block => [:head, :next],
27
+ :block_arg => [:vid, :cnt],
28
+ :block_pass => [:body, :iter],
29
+ :bmethod => [:cval],
30
+ :break => [:stts],
31
+ :call => [:mid, :args, :recv],
32
+ :case => [:body, :head],
33
+ :cdecl => [:vid, :value, :else],
34
+ :cfunc => [:argc, :cfnc],
35
+ :class => [:super, :cpath, :body],
36
+ :colon2 => [:head, :mid],
37
+ :colon3 => [:mid],
38
+ :const => [:vid],
39
+ :cref => [:next, :clss],
40
+ :cvar => [:vid],
41
+ :cvasgn => [:vid, :value],
42
+ :cvdecl => [:vid, :value],
43
+ :dasgn => [:vid, :value],
44
+ :dasgn_curr => [:vid, :value],
45
+ :defined => [:head],
46
+ :defn => [:mid, :defn, :noex], # noex seems unused and always NOEX_PRIVATE in 1.8.4
47
+ :defs => [:mid, :defn, :recv],
48
+ :dmethod => [:cval],
49
+ :dot2 => [:beg, :end],
50
+ :dot3 => [:beg, :end],
51
+ :dregx => [:next, :lit, :cflag],
52
+ :dregx_once => [:next, :lit, :cflag],
53
+ :dstr => [:next, :lit],
54
+ :dsym => [:next, :lit],
55
+ :dvar => [:vid],
56
+ :dxstr => [:next, :lit],
57
+ :ensure => [:head, :ensr],
58
+ :evstr => [:body],
59
+ :false => [],
60
+ :fbody => [:orig, :mid, :head],
61
+ :fcall => [:mid, :args],
62
+ :flip2 => [:cnt, :beg, :end],
63
+ :flip3 => [:cnt, :beg, :end],
64
+ :for => [:body, :iter, :var],
65
+ :gasgn => [:vid, :value], # entry not supported
66
+ :gvar => [:vid], # entry not supported
67
+ :hash => [:head],
68
+ :iasgn => [:vid, :value],
69
+ :if => [:body, :cond, :else],
70
+ :ifunc => [:tval, :state, :cfnc],
71
+ :iter => [:body, :iter, :var],
72
+ :ivar => [:vid],
73
+ :lasgn => [:vid, :cnt, :value],
74
+ :last => [],
75
+ :lit => [:lit],
76
+ :lvar => [:vid, :cnt],
77
+ :masgn => [:head, :value, :args],
78
+ :match => [:lit],
79
+ :match2 => [:value, :recv],
80
+ :match3 => [:value, :recv],
81
+ :memo => {:u1_value=>:u1_value}, # different uses in enum.c, variabe.c and eval.c ...
82
+ :method => [:body, :noex, :cnt], # cnt seems to be always 0 in 1.8.4
83
+ :module => [:cpath, :body],
84
+ :newline => [:next],
85
+ :next => [:stts],
86
+ :nil => [],
87
+ :not => [:body],
88
+ :nth_ref => [:nth, :cnt],
89
+ :op_asgn1 => [:mid, :args, :recv],
90
+ :op_asgn2 =>
91
+ lambda { |node|
92
+ if ((v = node.nd_vid) && (m = node.nd_mid) && (a = node.nd_aid))
93
+ {:vid => v, :mid => m, :aid => a}
94
+ else
95
+ {:recv => node.nd_recv, :value => node.nd_value, :next => node.nd_next}
96
+ end
97
+ },
98
+ :op_asgn_and => [:head, :value],
99
+ :op_asgn_or => [:head, :aid, :value],
100
+ :opt_n => [:body],
101
+ :or => {:first=>:nd_1st, :second=>:nd_2nd},
102
+ :postexe => [],
103
+ :redo => [],
104
+ :resbody => [:body, :head, :args],
105
+ :rescue => [:head, :else, :resq],
106
+ :retry => [],
107
+ :return => [:stts],
108
+ :sclass => [:recv, :body],
109
+ :scope => [:rval, :next, :tbl],
110
+ :self => [],
111
+ :splat => [:head],
112
+ :str => [:lit],
113
+ :super => [:args],
114
+ :svalue => [:head],
115
+ :to_ary => [:head],
116
+ :true => [],
117
+ :undef =>
118
+ lambda { |node|
119
+ # ruby >1.8.4 uses u2.node instead of nd_mid
120
+ {:mid => (node.u2_node || node.nd_mid)}
121
+ },
122
+ :until => [:body, :cond, :state],
123
+ :valias =>
124
+ lambda { |node|
125
+ { # ruby >1.8.4 doesn't have nd_new and nd_old
126
+ :new => ((node.respond_to?(:nd_new) && node.nd_new) || node.u1_id),
127
+ :old => ((node.respond_to?(:nd_old) && node.nd_old) || node.u2_id),
128
+ }
129
+ },
130
+ :vcall => [:mid],
131
+ :when => [:body, :head, :next],
132
+ :while => [:body, :cond, :state],
133
+ :xstr => [:lit],
134
+ :yield => [:head, :state],
135
+ :zarray => [],
136
+ :zsuper => [],
137
+ }
138
+ if RUBY_VERSION >= "1.9.0"
139
+ # nodes that are only in 1.9 or changed in 1.9
140
+ NODE_ATTRIBS.merge!({
141
+ :args => [:frml, :rest, :opt, :head],
142
+ :colon2 => [:head, :mid, :recv], # head is also accessed as recv in 1.9.0 ???
143
+ :errinfo => [],
144
+ :lambda => [:body, :var],
145
+ :method => [:body, :noex],
146
+ :postexe => [:body],
147
+ :prelude => [:body, :head],
148
+ :values => [:alen, :head, :next],
149
+ })
150
+ end
151
+
152
+ def attribs_hash
153
+ if (t = NODE_ATTRIBS[type])
154
+ case t
155
+ when Array
156
+ res = {}
157
+ t.each { |s| res[s] = send("nd_#{s}") }
158
+ res
159
+ when Hash
160
+ res = {}
161
+ t.each { |k, v| res[k] = send(v) }
162
+ res
163
+ else
164
+ t.call(self)
165
+ end
166
+ else
167
+ # guess by trying
168
+ u1 = u1_value || u1_id || u1_tbl || u1_as_long
169
+ u2 = u2_value || u2_id || u2_argc
170
+ u3 = u3_value || u3_id || u3_cnt
171
+ {:u1 => u1, :u2 => u2, :u3 => u3}
172
+ end
173
+ end
174
+
175
+ def transform(opts = {})
176
+ if type == :newline && !opts[:keep_newline_nodes]
177
+ tmp = nd_next
178
+ return tmp && tmp.transform(opts)
179
+ end
180
+ if (type == :array && !opts[:keep_array_nodes]) || (type == :block && !opts[:keep_block_nodes])
181
+ arr = []
182
+ tmp = self
183
+ begin
184
+ tmp_head = tmp.nd_head
185
+ tmp_head = tmp_head.transform(opts) if RubyNode === tmp_head
186
+ arr << tmp_head
187
+ end while tmp = tmp.nd_next
188
+ [type, arr]
189
+ else
190
+ ah = attribs_hash
191
+ ah.each { |k, v|
192
+ ah[k] = v.transform(opts) if RubyNode === v
193
+ }
194
+ ah[:node] = self if opts[:include_node]
195
+ [type, ah]
196
+ end
197
+ end
198
+
199
+ def inspect
200
+ "#<#{self.class} #{type.inspect}>"
201
+ end
202
+
203
+ def to_s
204
+ "#{self.class}(#{type.inspect}, #{attribs_hash.inspect})"
205
+ end
206
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: rubynode
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.1.1
7
+ date: 2006-09-25 00:00:00 +02:00
8
+ summary: RubyNode is a library that allows read only access to Ruby's internal NODE structure.
9
+ require_paths:
10
+ - lib
11
+ email: dbatml@gmx.de
12
+ homepage: http://rubynode.rubyforge.org/
13
+ rubyforge_project:
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Dominik Bathon
31
+ files:
32
+ - ext/rubynode_ext
33
+ - ext/rubynode_ext/ruby_src
34
+ - ext/rubynode_ext/extconf.rb
35
+ - ext/rubynode_ext/rubynode_ext.c
36
+ - ext/rubynode_ext/ruby_src/1.8.4_2005-12-24
37
+ - ext/rubynode_ext/ruby_src/1.8.5_2006-08-25
38
+ - ext/rubynode_ext/ruby_src/1.8.4_2005-12-24/gc.c
39
+ - ext/rubynode_ext/ruby_src/1.8.4_2005-12-24/eval.c
40
+ - ext/rubynode_ext/ruby_src/1.8.4_2005-12-24/node.h
41
+ - ext/rubynode_ext/ruby_src/1.8.5_2006-08-25/gc.c
42
+ - ext/rubynode_ext/ruby_src/1.8.5_2006-08-25/eval.c
43
+ - ext/rubynode_ext/ruby_src/1.8.5_2006-08-25/node.h
44
+ - lib/rubynode.rb
45
+ - doc/api.html
46
+ - doc/index.html
47
+ - doc/style.css
48
+ - README
49
+ - Changelog
50
+ test_files: []
51
+
52
+ rdoc_options: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ executables: []
57
+
58
+ extensions:
59
+ - ext/rubynode_ext/extconf.rb
60
+ requirements: []
61
+
62
+ dependencies: []
63
+