class << self #14

Closed
wants to merge 1 commit into
from
View
Binary file not shown.
View
@@ -79,7 +79,7 @@ class Flog < SexpProcessor
@@no_method = :none
attr_accessor :multiplier
- attr_reader :calls, :option, :class_stack, :method_stack, :mass
+ attr_reader :calls, :option, :class_stack, :method_stack, :mass, :sclass
attr_reader :method_locations
def self.plugins
@@ -324,6 +324,7 @@ def in_method(name, file, line)
def initialize option = {}
super()
@option = option
+ @sclass = nil
@class_stack = []
@method_stack = []
@method_locations = {}
@@ -621,7 +622,8 @@ def process_dasgn_curr(exp) # FIX: remove
alias :process_lasgn :process_dasgn_curr
def process_defn(exp)
- in_method exp.shift, exp.file, exp.line do
+ name = @sclass ? "::#{exp.shift}" : exp.shift
+ in_method name, exp.file, exp.line do
process_until_empty exp
end
s()
@@ -736,10 +738,12 @@ def process_module(exp)
end
def process_sclass(exp)
+ @sclass = true
penalize_by 0.5 do
process exp.shift # recv
process_until_empty exp
end
+ @sclass = nil
add_to_score :sclass
s()
View
Binary file not shown.
View
@@ -399,6 +399,21 @@ def test_process_defn
util_process sexp, 0.275, :lit_fixnum => 0.275
end
+ def test_process_defn_in_self
+ sexp = s(:sclass, s(:self),
+ s(:defn, :x,
+ s(:args, :y),
+ s(:lit, 42)))
+
+ setup
+ @flog.process sexp
+
+ exp = {'main::x' => {:lit_fixnum => 0.375}, 'main#none' => {:sclass => 5.0}}
+ assert_equal exp, @flog.calls
+
+ assert_in_delta 5.375, @flog.total
+ end
+
def test_process_defs
@meth = "::x" # HACK, I don't like this