Class: FastRuby::GetLocalsProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/fastruby/getlocals.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGetLocalsProcessor

Returns a new instance of GetLocalsProcessor.



29
30
31
# File 'lib/fastruby/getlocals.rb', line 29

def initialize
  @locals = Set.new
end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals.



27
28
29
# File 'lib/fastruby/getlocals.rb', line 27

def locals
  @locals
end

Class Method Details

.get_locals(tree) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/fastruby/getlocals.rb', line 61

def self.get_locals(tree)
  processor = GetLocalsProcessor.new
  processor.process(tree)
  ret_locals = processor.locals
  ret_locals << :self
  ret_locals
end

Instance Method Details

#process(tree) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fastruby/getlocals.rb', line 33

def process(tree)
  if tree.node_type == :lasgn
   @locals << tree[1]
  end
  
  if tree[0] == :args

    tree[1..-1].each do |subtree|
      if subtree.instance_of? Symbol
         @locals << subtree.to_s.gsub("*","").gsub("&","").to_sym
      end
    end

    if tree.find{|x| x.to_s[0] == ?&}
      @locals << :__xproc_arguments
    end
  end

  if tree[0] == :block_pass
    @locals << :__xblock_arguments
    @locals << :__x_proc
  end

  tree.select{|subtree| subtree.instance_of? FastRuby::FastRubySexp}.each do |subtree|
    process(subtree)
  end
end