furnace 0.2.6 → 0.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/furnace/ast/node.rb +22 -51
- data/lib/furnace/ast/strict_visitor.rb +12 -4
- data/lib/furnace/cfg/graph.rb +2 -0
- data/lib/furnace/version.rb +1 -1
- metadata +6 -7
data/lib/furnace/ast/node.rb
CHANGED
@@ -1,36 +1,33 @@
|
|
1
1
|
module Furnace::AST
|
2
2
|
class Node
|
3
|
-
|
3
|
+
attr_reader :type, :children
|
4
4
|
|
5
|
-
def initialize(type, children=[],
|
6
|
-
@type, @children
|
5
|
+
def initialize(type, children=[], properties={})
|
6
|
+
@type, @children = type.to_sym, children.to_a
|
7
|
+
properties.each do |name, value|
|
8
|
+
instance_variable_set :"@#{name}", value
|
9
|
+
end
|
10
|
+
freeze
|
7
11
|
end
|
8
12
|
|
9
|
-
def update(type, children=nil,
|
10
|
-
|
11
|
-
|
13
|
+
def update(type=nil, children=nil, properties={})
|
14
|
+
new_type = type || @type
|
15
|
+
new_children = children || @children
|
12
16
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
if @type == new_type &&
|
18
|
+
@children == new_children &&
|
19
|
+
properties.empty?
|
20
|
+
self
|
17
21
|
else
|
18
|
-
|
22
|
+
dup.send :initialize, new_type, new_children, properties
|
19
23
|
end
|
20
|
-
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
def dup
|
25
|
-
node = super
|
26
|
-
node.children = @children.dup
|
27
|
-
node.metadata = @metadata.dup
|
28
|
-
node
|
29
24
|
end
|
30
25
|
|
31
26
|
def ==(other)
|
32
|
-
if other
|
33
|
-
|
27
|
+
if equal?(other)
|
28
|
+
true
|
29
|
+
elsif other.respond_to? :to_ast
|
30
|
+
other = other.to_ast
|
34
31
|
other.type == self.type &&
|
35
32
|
other.children == self.children
|
36
33
|
else
|
@@ -45,17 +42,10 @@ module Furnace::AST
|
|
45
42
|
def to_sexp(indent=0)
|
46
43
|
str = "#{" " * indent}(#{fancy_type}"
|
47
44
|
|
48
|
-
if @metadata[:ellipsis]
|
49
|
-
str << " <omitted>)"
|
50
|
-
|
51
|
-
return str
|
52
|
-
end
|
53
|
-
|
54
45
|
children.each do |child|
|
55
46
|
if (!children[0].is_a?(Node) && child.is_a?(Node)) ||
|
56
47
|
(children[0].is_a?(Node) && child.is_a?(Node) &&
|
57
|
-
child.children.any? { |c| c.is_a?(Node) || c.is_a?(Array) })
|
58
|
-
(child.is_a?(Node) && child.metadata[:label])
|
48
|
+
child.children.any? { |c| c.is_a?(Node) || c.is_a?(Array) })
|
59
49
|
str << "\n#{child.to_sexp(indent + 1)}"
|
60
50
|
else
|
61
51
|
str << " #{child.inspect}"
|
@@ -68,33 +58,14 @@ module Furnace::AST
|
|
68
58
|
end
|
69
59
|
alias :inspect :to_sexp
|
70
60
|
|
71
|
-
def
|
61
|
+
def to_ast
|
72
62
|
self
|
73
63
|
end
|
74
64
|
|
75
65
|
protected
|
76
66
|
|
77
67
|
def fancy_type
|
78
|
-
|
79
|
-
|
80
|
-
if @metadata.any?
|
81
|
-
metainfo = @metadata.dup
|
82
|
-
metainfo.delete :label
|
83
|
-
metainfo.delete :origin
|
84
|
-
metainfo.delete :ellipsis
|
85
|
-
|
86
|
-
if metainfo.any?
|
87
|
-
metainfo = "#{metainfo.inspect}:"
|
88
|
-
else
|
89
|
-
metainfo = nil
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
if @metadata[:label]
|
94
|
-
"#{@metadata[:label]}:#{metainfo}#{dasherized}"
|
95
|
-
else
|
96
|
-
"#{metainfo}#{dasherized}"
|
97
|
-
end
|
68
|
+
@type.to_s.gsub('_', '-')
|
98
69
|
end
|
99
70
|
end
|
100
71
|
end
|
@@ -1,10 +1,15 @@
|
|
1
1
|
module Furnace::AST
|
2
2
|
module StrictVisitor
|
3
3
|
def visit(node)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
if node
|
5
|
+
# Invoke a specific handler
|
6
|
+
on_handler = :"on_#{node.type}"
|
7
|
+
if respond_to? on_handler
|
8
|
+
new_node = send on_handler, node
|
9
|
+
else
|
10
|
+
new_node = handler_missing(node)
|
11
|
+
end
|
12
|
+
|
8
13
|
node = new_node if new_node
|
9
14
|
end
|
10
15
|
|
@@ -16,5 +21,8 @@ module Furnace::AST
|
|
16
21
|
visit node
|
17
22
|
end
|
18
23
|
end
|
24
|
+
|
25
|
+
def handler_missing(node)
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
data/lib/furnace/cfg/graph.rb
CHANGED
@@ -128,6 +128,8 @@ module Furnace::CFG
|
|
128
128
|
# Are we computing dominators or postdominators?
|
129
129
|
if forward
|
130
130
|
edges = node.sources + node.exception_sources
|
131
|
+
elsif node.exception.nil?
|
132
|
+
edges = node.targets
|
131
133
|
else
|
132
134
|
edges = node.targets + [ node.exception ]
|
133
135
|
end
|
data/lib/furnace/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: furnace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.0.beta1
|
5
|
+
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Peter Zotov
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-31 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Furnace is a static code analysis framework for dynamic languages, aimed
|
15
15
|
at efficient type and behavior inference.
|
@@ -61,14 +61,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
|
-
- - ! '
|
64
|
+
- - ! '>'
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version:
|
66
|
+
version: 1.3.1
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.8.
|
69
|
+
rubygems_version: 1.8.23
|
70
70
|
signing_key:
|
71
71
|
specification_version: 3
|
72
72
|
summary: A static code analysis framework
|
73
73
|
test_files: []
|
74
|
-
has_rdoc:
|