kurangu 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/kurangu.rb +13 -10
- data/lib/trace.rb +9 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7752f5414ccab463481b345ff7200e814fb5859a
|
4
|
+
data.tar.gz: b47108ea9f4cd426311d641d6807a6cf48bd2ac5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a07563548226e345a01eda0373b3ab2becf85f9bfa43be17882a7ddaa4c91e46179c02f2486a841dbb6f16f1a9701be5267abb8dc2efacb163e6fcdd09fb5c42
|
7
|
+
data.tar.gz: c0fee84605fa788d50f1a59e7e4d5e1a30b965b31aa213dfa262dbdcd789a6a9af5169e6a1d5d14528b7cc6671c9700246cc925d5b52b634bf877666b116a9bb
|
data/lib/kurangu.rb
CHANGED
@@ -18,11 +18,8 @@ class Kurangu
|
|
18
18
|
f.each_line do |annotation_file|
|
19
19
|
puts annotation_file
|
20
20
|
File.open(annotation_file, "r") do |f|
|
21
|
-
f.
|
22
|
-
|
23
|
-
puts line
|
24
|
-
end
|
25
|
-
end
|
21
|
+
contents = f.read
|
22
|
+
puts contents
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
@@ -34,12 +31,12 @@ class Kurangu
|
|
34
31
|
original_path = annotation_path.chomp('.annotations')
|
35
32
|
annotated_path = "#{original_path}.annotated"
|
36
33
|
puts "\ngenerating annotated file #{annotated_path}\n"
|
37
|
-
annotations = Hash.new
|
34
|
+
annotations = Hash.new { |h, k| h[k] = [] }
|
38
35
|
File.open(annotation_path, "r") do |f|
|
39
36
|
f.each_line do |line|
|
40
37
|
split = line.split(" ", 2)
|
41
38
|
index = split[0].to_i
|
42
|
-
annotations[index]
|
39
|
+
annotations[index].push split[1]
|
43
40
|
end
|
44
41
|
end
|
45
42
|
lines = []
|
@@ -47,14 +44,20 @@ class Kurangu
|
|
47
44
|
File.open(original_path, "r") do |f|
|
48
45
|
f.each_line.with_index do |line, index|
|
49
46
|
whitespace = line.chomp(line.lstrip)
|
50
|
-
if annotations
|
47
|
+
if annotations[index + 1].size > 0
|
51
48
|
if lines.last and lines.last.start_with?('type')
|
52
49
|
has_types = true
|
53
|
-
lines.last = "#{whitespace}#{annotations[index + 1]}"
|
50
|
+
lines.last = "#{whitespace}#{annotations[index + 1][0]}"
|
51
|
+
annotations[index + 1].drop(1).each do |annotation|
|
52
|
+
lines << "#{whitespace}#{annotation}"
|
53
|
+
end
|
54
54
|
else
|
55
55
|
lines << "#{whitespace}extend RDL::Annotate\n"
|
56
|
-
|
56
|
+
annotations[index + 1].each do |annotation|
|
57
|
+
lines << "#{whitespace}#{annotation}"
|
58
|
+
end
|
57
59
|
end
|
60
|
+
lines << "\n"
|
58
61
|
end
|
59
62
|
lines << line
|
60
63
|
end
|
data/lib/trace.rb
CHANGED
@@ -2,16 +2,14 @@ require 'set'
|
|
2
2
|
|
3
3
|
INPUT_FILE = $stdin.readline.chomp
|
4
4
|
|
5
|
-
stack = Hash.new
|
6
|
-
|
7
|
-
|
8
|
-
parameter_list = Hash.new Array.new
|
9
|
-
signatures = Hash.new
|
5
|
+
stack = Hash.new { |h, k| h[k] = [] }
|
6
|
+
parameter_list = Hash.new { |h, k| h[k] = [] }
|
7
|
+
signatures = Array.new
|
10
8
|
paths = Set.new
|
11
9
|
|
12
|
-
def generate_signature(line, parameters, parameter_types,
|
13
|
-
joined_parameters = parameters.map { |arg| parameter_types[arg]
|
14
|
-
"#{line} type '(#{joined_parameters.join(", ")}) -> #{
|
10
|
+
def generate_signature(line, parameters, parameter_types, return_type)
|
11
|
+
joined_parameters = parameters.map { |arg| parameter_types[arg] }
|
12
|
+
"#{line} type '(#{joined_parameters.join(", ")}) -> #{return_type}'"
|
15
13
|
end
|
16
14
|
|
17
15
|
def write_annotations_paths(dir, paths)
|
@@ -20,7 +18,7 @@ def write_annotations_paths(dir, paths)
|
|
20
18
|
end
|
21
19
|
|
22
20
|
def write_annotations(path, signatures)
|
23
|
-
IO.write(path, signatures.
|
21
|
+
IO.write(path, signatures.join("\n"))
|
24
22
|
end
|
25
23
|
|
26
24
|
trace_return = TracePoint.new(:return) do |t|
|
@@ -28,13 +26,9 @@ trace_return = TracePoint.new(:return) do |t|
|
|
28
26
|
s = "#{t.defined_class}, :#{t.method_id}"
|
29
27
|
args = stack[s].pop
|
30
28
|
if args
|
31
|
-
|
32
|
-
parameter_types[s][arg].add(type)
|
33
|
-
end
|
34
|
-
return_types[s].add(t.return_value.class)
|
35
|
-
parameter_list[s] = t.self.method(t.method_id).parameters.map { |a | a[1] }
|
29
|
+
parameter_list = t.self.method(t.method_id).parameters.map { |a | a[1] }
|
36
30
|
line = t.self.method(t.method_id).source_location[1]
|
37
|
-
signatures
|
31
|
+
signatures.push generate_signature(line, parameter_list, args, t.return_value.class)
|
38
32
|
path = "#{t.path}.annotations"
|
39
33
|
dir = File.dirname(t.path)
|
40
34
|
write_annotations_paths(dir, paths.add(path))
|