-
Notifications
You must be signed in to change notification settings - Fork 914
/
IRScriptBody.java
69 lines (56 loc) · 1.87 KB
/
IRScriptBody.java
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.jruby.ir;
import org.jruby.ir.interpreter.BeginEndInterpreterContext;
import org.jruby.ir.interpreter.InterpreterContext;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import java.util.ArrayList;
import java.util.List;
public class IRScriptBody extends IRScope {
private List<IRClosure> beginBlocks;
private DynamicScope toplevelScope;
public IRScriptBody(IRManager manager, String sourceName, StaticScope staticScope) {
super(manager, null, sourceName, sourceName, 0, staticScope);
this.toplevelScope = null;
if (!getManager().isDryRun() && staticScope != null) {
staticScope.setIRScope(this);
staticScope.setScopeType(this.getScopeType());
}
}
public DynamicScope getToplevelScope() {
return toplevelScope;
}
public void setTopLevelBindingScope(DynamicScope tlbScope) {
this.toplevelScope = tlbScope;
}
@Override
public InterpreterContext allocateInterpreterContext() {
return new BeginEndInterpreterContext(this, instrList);
}
@Override
public int getNearestModuleReferencingScopeDepth() {
return 0;
}
@Override
public IRScopeType getScopeType() {
return IRScopeType.SCRIPT_BODY;
}
@Override
public String toString() {
return "Script: file: " + getFileName() + super.toString();
}
/* Record a begin block -- not all scope implementations can handle them */
@Override
public void recordBeginBlock(IRClosure beginBlockClosure) {
if (beginBlocks == null) beginBlocks = new ArrayList<>();
beginBlockClosure.setBeginEndBlock();
beginBlocks.add(beginBlockClosure);
}
@Override
public List<IRClosure> getBeginBlocks() {
return beginBlocks;
}
@Override
public boolean isScriptScope() {
return true;
}
}