Class: Node::SCOPE

Inherits:
Object show all
Includes:
MethodSig
Defined in:
lib/decompiler/method/signature/node.rb

Overview

pre-YARV

Instance Method Summary collapse

Methods included from MethodSig

#arguments

Instance Method Details

#args_nodeObject



28
29
30
31
32
33
34
35
36
# File 'lib/decompiler/method/signature/node.rb', line 28

def args_node
  if self.next.class == Node::ARGS then
    return self.next
  elsif self.next.head.class == Node::ARGS then
    return self.next.head
  else
    raise "Could not find method arguments"
  end
end

#argument_namesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/decompiler/method/signature/node.rb', line 10

def argument_names
  local_vars = self.local_vars
  args = self.args_node
  num_required_args = args.cnt
  num_optional_args = 0
  opt = args.opt
  while opt do
    num_optional_args += 1
    opt = opt.next
  end
  num_args = \
    num_required_args + \
    num_optional_args + \
    (rest_arg ? 1 : 0) + \
    (block_arg ? 1 : 0)
  return local_vars[0...num_args]
end

#block_argObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/decompiler/method/signature/node.rb', line 51

def block_arg
  block = self.next
  if block.class == Node::BLOCK and
     block.next.head.class == Node::BLOCK_ARG then
    # subtract 2 to account for implicit vars
    return block.next.head.cnt - 2
  else
    return nil
  end
end

#local_varsObject



6
7
8
# File 'lib/decompiler/method/signature/node.rb', line 6

def local_vars
  return self.tbl || []
end

#rest_argObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/decompiler/method/signature/node.rb', line 38

def rest_arg
  args_node = args_node()
  rest = args_node.rest()
  if rest.class == Node::LASGN then
    # subtract 2 to account for implicit vars
    return rest.cnt - 2
  elsif not rest
    return nil
  else
    return rest > 0 ? rest - 2 : nil
  end
end

#set_optional_args(args, args_node, names) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/decompiler/method/signature/node.rb', line 62

def set_optional_args(args, args_node, names)
  opt = args_node.opt
  while opt do
    head = opt.head
    if head.class == Node::LASGN then
      args[head.vid] = NodeOptionalArgument.new(
          head.vid, head.value.as_expression, head.value, false, false)
    else
      raise "Unexpected node type: #{opt.class}"
    end
    opt = opt.next
  end
end