ruby_codex 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ruby_codex.rb +33 -33
  2. metadata +1 -1
data/lib/ruby_codex.rb CHANGED
@@ -29,8 +29,6 @@ class Codex
29
29
 
30
30
  key = {
31
31
  :type => type,
32
- :info => info,
33
- :func_info => func_info
34
32
  }
35
33
 
36
34
  data_core = {
@@ -86,7 +84,7 @@ class Codex
86
84
  "We've seen #{keys[:func]} blocks returning the #{keys[:ret_val]} type #{query_count.to_s} " +
87
85
  "times, and we've seen #{keys[:func]} blocks #{blocks.to_s} times and #{keys[:ret_val]} " +
88
86
  "returned #{rets.to_s} times.",
89
- :unlikely => Proc.new { |gt=1,bt = 5,rt = 5| query_count < gt && blocks > bt && rets > rt}
87
+ :unlikely => Proc.new { |gt=1,bt=5,rt=5| query_count < gt && blocks > bt && rets > rt}
90
88
  }
91
89
  }
92
90
  )
@@ -96,36 +94,34 @@ class Codex
96
94
  Proc.new { |x| x.type == :send},
97
95
  key.merge({
98
96
  :func => Proc.new { |x| func_name.call(x) },
99
- :norm_code => Proc.new { |x| normal_node(x) { |x| Unparser.unparse(without_caller(x)) rescue nil } },
100
97
  :sig => Proc.new { |x| x.children.drop(2).map { |y| type.call(y) } },
98
+ }),
99
+ data_core.merge({
101
100
  :info => Proc.new { |x| info.call(without_caller(x)) },
102
101
  :func_info => Proc.new { |x| func_info.call(without_caller(x)) }
103
102
  }),
104
- data_core,
105
103
  combine,
106
- Proc.new { |db,keys,values|
107
- if keys[:norm_code] != nil # Hack for binary operators that disappear
108
- query = db.where(keys).first
109
- query_count = query.nil? ? 0 : query.count
110
- func = db.where(:type => keys[:type], :func => keys[:func]).sort(:count => -1).limit(1).first
111
- alt_text =
112
- if func
113
- alt_count = func.count
114
- "and the most common alternative #{func.norm_code} has appeared #{alt_count.to_s} times."
115
- else
116
- alt_count = 0
117
- "and we've seen no known alternative."
118
- end
119
- { :keys => keys,
120
- :message =>
121
- "Function call #{keys[:norm_code]} has appeared #{query_count.to_s} times, " +
122
- alt_text,
123
- :unlikely => Proc.new { |t=10| alt_count > t * (query_count + 1)}
124
- }
125
- else
126
- { :message => "Never Seen", :unlikely => Proc.new { false } }
127
- end
128
- }
104
+ Proc.new do |db,keys,values|
105
+ query = db.where( :type => keys[:type], :func => keys[:func], :sig => keys[:sig]).first
106
+ query_count = query.nil? ? 0 : query.count
107
+ func = db.where(:type => keys[:type], :func => keys[:func], :sig => {:$ne => keys[:sig]}).sort(:count => -1).limit(1).first
108
+ alt_text =
109
+ if func
110
+ alt_count = func.count
111
+ "and the most common alternative #{func.func}:#{func.sig.join(",")} has appeared #{alt_count.to_s} times."
112
+ else
113
+ alt_count = 0
114
+ "and we've seen no known alternative."
115
+ end
116
+ { :keys => keys,
117
+ :message =>
118
+ "Function call #{keys[:func]}:#{keys[:sig].join(",")} has appeared #{query_count.to_s} times, " +
119
+ alt_text,
120
+ :unlikely => Proc.new do |ac=5,t=1024|
121
+ query_count == 0 && alt_count >= ac || alt_count >= t * (query_count + 1)
122
+ end
123
+ }
124
+ end
129
125
  )
130
126
 
131
127
  @nodes[:func_chain] = DataNode.new(
@@ -135,8 +131,6 @@ class Codex
135
131
  :type => Proc.new { "func_chain" },
136
132
  :f1 => Proc.new { |x| func_name.call(x) },
137
133
  :f2 => Proc.new { |x| func_name.call(x.children.first) },
138
- :info => Proc.new { 0 },
139
- :func_info => Proc.new { 0 }
140
134
  }),
141
135
  data_core,
142
136
  combine,
@@ -162,6 +156,8 @@ class Codex
162
156
  :cond => Proc.new { |x| normal_node(x) { |n| Unparser.unparse(n.children.first) }},
163
157
  :iftrue => Proc.new { |x| normal_node(x) { |n| Unparser.unparse(n.children[1]) }},
164
158
  :iffalse => Proc.new { |x| normal_node(x) { |n| Unparser.unparse(n.children[2]) }},
159
+ :info => info,
160
+ :func_info => func_info
165
161
  }),
166
162
  data_core,
167
163
  combine
@@ -173,8 +169,6 @@ class Codex
173
169
  key.merge({
174
170
  :type => Proc.new { "ident" },
175
171
  :ident => Proc.new { |x| x.children.first.to_s },
176
- :info => Proc.new { 0 },
177
- :func_info => Proc.new { 0 }
178
172
  }),
179
173
  data_core.merge({
180
174
  :ident_type => Proc.new { |x| type.call(x.children[1]) rescue nil }
@@ -194,7 +188,13 @@ class Codex
194
188
  :message =>
195
189
  "The identifier #{keys[:ident]} has appeared #{types[data[:ident_type]].to_s} " +
196
190
  "times as #{data[:ident_type].to_s} and #{best_str}",
197
- :unlikely => Proc.new { |t=5| best ? best[1] > t * (types[keys[:ident_type]] + 1) : false }
191
+ :unlikely => Proc.new do |ac=5,t=8|
192
+ if best
193
+ types[keys[:ident_type]] == 0 && best[1] >= ac || best[1] >= t * (types[keys[:ident_type]] + 1)
194
+ else
195
+ false
196
+ end
197
+ end
198
198
  }
199
199
  else
200
200
  { :message => "Never Seen", :unlikely => Proc.new { false } }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_codex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: