-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathfuncscope.rb
More file actions
53 lines (42 loc) · 1.02 KB
/
Copy pathfuncscope.rb
File metadata and controls
53 lines (42 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Function Scope.
# Holds variables defined within function, as well as all arguments
# part of the function.
class FuncScope < Scope
attr_reader :func
def initialize(func)
@func = func
@next = @func.scope
end
def rest?
@func ? @func.rest? : false
end
def lvaroffset
@func.lvaroffset
end
# Returns an argument within the function scope, if defined here.
# A function holds it's own scope chain, so if the function doens't
# return anything, we fall back to just an addr.
def get_arg(a, save = false)
a = a.to_sym
if @func
arg = @func.get_arg(a)
return arg if arg
end
return [:addr, a]
end
def method
@func
end
# Delegate to next scope to find ClassScope/ModuleScope
def class_scope
if @next
return @next.class_scope
end
return self
end
# Delegate to parent scope for name (module/class prefix)
# This ensures constants defined inside module/class bodies get the correct prefix
def name
@next ? @next.name : ""
end
end