kurangu 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/kurangu.rb +13 -10
  3. data/lib/trace.rb +9 -15
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1edac603765e16e67954a8413fb896f5eb29f3c1
4
- data.tar.gz: 08ed42aa75aca7d75d52888bab152a1e4824dbba
3
+ metadata.gz: 7752f5414ccab463481b345ff7200e814fb5859a
4
+ data.tar.gz: b47108ea9f4cd426311d641d6807a6cf48bd2ac5
5
5
  SHA512:
6
- metadata.gz: b9b0bb828692c4f30dfbd53569c97e6f441716e4bc49c89fa028da82e243b4383f87bc7203945632c06f1fcf47d064a951c6ed170ec714f49c1d91d9a0fb6f2a
7
- data.tar.gz: 82c27311d8eb3ce022052d5ce04e07f0df6adf9c06efdb961716db9b8dd689bd128df7bfdf01468590e45ccc05722ae82d43dbed2d7fd148e33074d1b212cf7a
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.each_line.with_index do |line, index|
22
- if index > 2
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] = "#{split[1]}\n"
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.key?(index + 1)
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
- lines << "#{whitespace}#{annotations[index + 1]}"
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 Array.new
6
- parameter_types = Hash.new Hash.new Set.new
7
- return_types = Hash.new Set.new
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, return_types)
13
- joined_parameters = parameters.map { |arg| parameter_types[arg].to_a.join(" or ") }
14
- "#{line} type '(#{joined_parameters.join(", ")}) -> #{return_types.to_a.join(" or ")}'"
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.values.join("\n"))
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
- args.each do |arg, type|
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[s] = generate_signature(line, parameter_list[s], parameter_types[s], return_types[s])
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))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kurangu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arpith Siromoney