Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Track stack of nested sclass scopes for parser #23

Closed
wants to merge 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 7, 2013
  1. @pithyless
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 4 deletions.
  1. +4 −4 lib/flog.rb
  2. +16 −0 test/test_flog.rb
View
8 lib/flog.rb
@@ -369,7 +369,7 @@ def in_method(name, file, line)
def initialize option = {}
super()
@option = option
- @sclass = nil
+ @sclass = []
@class_stack = []
@method_stack = []
@method_locations = {}
@@ -684,7 +684,7 @@ def process_dasgn_curr(exp) # FIX: remove
alias :process_lasgn :process_dasgn_curr
def process_defn(exp)
- name = @sclass ? "::#{exp.shift}" : exp.shift
+ name = @sclass.empty? ? exp.shift : "::#{exp.shift}"
in_method name, exp.file, exp.line do
process_until_empty exp
end
@@ -800,12 +800,12 @@ def process_module(exp)
end
def process_sclass(exp)
- @sclass = true
+ @sclass.push(true)
penalize_by 0.5 do
process exp.shift # recv
process_until_empty exp
end
- @sclass = nil
+ @sclass.pop
add_to_score :sclass
s()
View
16 test/test_flog.rb
@@ -427,6 +427,22 @@ def test_process_defn_in_self
assert_in_delta 5.375, @flog.total
end
+ def test_process_defn_in_self_after_self
+ sexp = s(:sclass, s(:self),
+ s(:sclass, s(:self), 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 => 12.5}}
+ assert_equal exp, @flog.calls
+
+ assert_in_delta 12.875, @flog.total
+ end
+
def test_process_defs
@meth = "::x" # HACK, I don't like this
Something went wrong with that request. Please try again.