Repository navigation
Expand file tree
/
Copy pathDummyDynamicScope.java
More file actions
94 lines (83 loc) · 3.04 KB
/
Copy pathDummyDynamicScope.java
File metadata and controls
94 lines (83 loc) · 3.04 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package org.jruby.runtime.scope;
import org.jruby.Ruby;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.builtin.IRubyObject;
/**
* This is a DynamicScope that does not support any variables. It differs from
* NoVarsDynamicScope in that it has hard failures for "backref" and "lastline"
* accesses, since in the JRuby 1.3 cycle it was discovered that threads were
* sharing a single dummyscope while still setting per-call backrefs. The hard
* errors here are an attempt to catch such situations in the future, before
* the optimizing compiler work makes such determinations in advance.
*/
public class DummyDynamicScope extends NoVarsDynamicScope {
private static final int SIZE = 0;
private static final String GROW_ERROR = "DummyDynamicScope cannot be grown; use ManyVarsDynamicScope";
public DummyDynamicScope(StaticScope staticScope, DynamicScope parent) {
super(staticScope, parent);
}
public DummyDynamicScope(StaticScope staticScope) {
super(staticScope);
}
public void growIfNeeded() {
growIfNeeded(SIZE, GROW_ERROR);
}
protected void growIfNeeded(int size, String message) {
if (staticScope.getNumberOfVariables() != size) {
throw new RuntimeException(message);
}
}
public DynamicScope cloneScope() {
// there should be no mutable state in this scope, so return same
return this;
}
/**
* Get backref
*/
public IRubyObject getBackRef(Ruby runtime) {
if (!staticScope.isBackrefLastlineScope()) {
return parent.getBackRef(runtime);
}
if (runtime.getDebug().isTrue()) {
runtime.getWarnings().warn("DummyDynamicScope should never be used for backref storage");
}
return runtime.getNil();
}
/**
* Set backref
*/
public IRubyObject setBackRef(IRubyObject backref) {
if (!staticScope.isBackrefLastlineScope()) {
return parent.setBackRef(backref);
}
if (backref.getRuntime().getDebug().isTrue()) {
backref.getRuntime().getWarnings().warn("DummyDynamicScope should never be used for backref storage");
}
return backref;
}
/**
* Get lastline
*/
public IRubyObject getLastLine(Ruby runtime) {
if (!staticScope.isBackrefLastlineScope()) {
return parent.getLastLine(runtime);
}
if (runtime.getDebug().isTrue()) {
runtime.getWarnings().warn("DummyDynamicScope should never be used for lastline storage");
}
return runtime.getNil();
}
/**
* Set lastline
*/
public IRubyObject setLastLine(IRubyObject lastline) {
if (!staticScope.isBackrefLastlineScope()) {
return parent.setLastLine(lastline);
}
if (lastline.getRuntime().getDebug().isTrue()) {
lastline.getRuntime().getWarnings().warn("DummyDynamicScope should never be used for backref storage");
}
return lastline;
}
}