|
|
@@ -12,9 +12,9 @@ module Bitshift |
|
|
|
parser = RubyParser.new |
|
|
|
tree = parser.parse(@source) |
|
|
|
offset = tree.line - 1 |
|
|
|
processor = NodeVisitor.new offset |
|
|
|
processor.process tree |
|
|
|
return processor.symbols |
|
|
|
processor = NodeVisitor.new offset, tree |
|
|
|
processor.process(tree) |
|
|
|
return processor.to_s |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
@@ -22,16 +22,16 @@ module Bitshift |
|
|
|
attr_accessor :symbols |
|
|
|
attr_accessor :offset |
|
|
|
|
|
|
|
def initialize(offset) |
|
|
|
def initialize(offset, tree) |
|
|
|
super() |
|
|
|
@require_empty = false |
|
|
|
@offset = offset |
|
|
|
|
|
|
|
module_hash = Hash.new {|hash, key| hash[key] = Hash.new} |
|
|
|
class_hash = module_hash.clone |
|
|
|
function_hash = Hash.new {|hash, key| hash[key] = { calls: [] } } |
|
|
|
var_hash = Hash.new {|hash, key| hash[key] = [] } |
|
|
|
|
|
|
|
@require_empty = false |
|
|
|
@offset = offset |
|
|
|
@symbols = { |
|
|
|
modules: module_hash, |
|
|
|
classes: class_hash, |
|
|
@@ -68,7 +68,7 @@ module Bitshift |
|
|
|
end |
|
|
|
|
|
|
|
def process_module(exp) |
|
|
|
pos = block_position exp |
|
|
|
pos = block_position(exp) |
|
|
|
exp.shift |
|
|
|
name = exp.shift |
|
|
|
symbols[:modules][name] = pos |
|
|
@@ -77,7 +77,7 @@ module Bitshift |
|
|
|
end |
|
|
|
|
|
|
|
def process_class(exp) |
|
|
|
pos = block_position exp |
|
|
|
pos = block_position(exp) |
|
|
|
exp.shift |
|
|
|
name = exp.shift |
|
|
|
symbols[:classes][name] = pos |
|
|
@@ -86,7 +86,7 @@ module Bitshift |
|
|
|
end |
|
|
|
|
|
|
|
def process_defn(exp) |
|
|
|
pos = block_position exp |
|
|
|
pos = block_position(exp) |
|
|
|
exp.shift |
|
|
|
name = exp.shift |
|
|
|
symbols[:functions][name][:declaration] = pos |
|
|
@@ -95,7 +95,7 @@ module Bitshift |
|
|
|
end |
|
|
|
|
|
|
|
def process_call(exp) |
|
|
|
pos = statement_position exp |
|
|
|
pos = statement_position(exp) |
|
|
|
exp.shift |
|
|
|
exp.shift |
|
|
|
name = exp.shift |
|
|
@@ -105,7 +105,7 @@ module Bitshift |
|
|
|
end |
|
|
|
|
|
|
|
def process_iasgn(exp) |
|
|
|
pos = statement_position exp |
|
|
|
pos = statement_position(exp) |
|
|
|
exp.shift |
|
|
|
name = exp.shift |
|
|
|
symbols[:vars][name] << pos |
|
|
@@ -114,12 +114,18 @@ module Bitshift |
|
|
|
end |
|
|
|
|
|
|
|
def process_lasgn(exp) |
|
|
|
pos = statement_position exp |
|
|
|
pos = statement_position(exp) |
|
|
|
exp.shift |
|
|
|
name = exp.shift |
|
|
|
symbols[:vars][name] << pos |
|
|
|
exp.each_sexp {|s| process(s)} |
|
|
|
return exp.clear |
|
|
|
end |
|
|
|
|
|
|
|
def to_s |
|
|
|
str = symbols.to_s |
|
|
|
str = str.gsub(/:(\w*)=>/, '"\1":') |
|
|
|
return str |
|
|
|
end |
|
|
|
end |
|
|
|
end |