forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIRMethod.java
More file actions
87 lines (71 loc) · 3.02 KB
/
Copy pathIRMethod.java
File metadata and controls
87 lines (71 loc) · 3.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
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
package org.jruby.ir;
import java.util.ArrayList;
import java.util.List;
import org.jruby.ir.instructions.Instr;
import org.jruby.ir.instructions.ReceiveArgBase;
import org.jruby.ir.instructions.ReceiveRestArgBase;
import org.jruby.ir.operands.LocalVariable;
import org.jruby.ir.operands.Operand;
import org.jruby.ir.operands.Splat;
import org.jruby.ir.operands.Variable;
import org.jruby.parser.IRStaticScope;
import org.jruby.parser.StaticScope;
public class IRMethod extends IRScope {
public final boolean isInstanceMethod;
// SSS FIXME: Note that if operands from the method are modified,
// callArgs would have to be updated as well
// Call parameters
private List<Operand> callArgs;
// Argument description of the form [:req, "a"], [:opt, "b"] ..
private List<String[]> argDesc;
public IRMethod(IRManager manager, IRScope lexicalParent, String name,
boolean isInstanceMethod, int lineNumber, StaticScope staticScope) {
super(manager, lexicalParent, name, lexicalParent.getFileName(), lineNumber, staticScope);
this.isInstanceMethod = isInstanceMethod;
this.callArgs = new ArrayList<Operand>();
this.argDesc = new ArrayList<String[]>();
if (!getManager().isDryRun()) {
if (staticScope != null) ((IRStaticScope)staticScope).setIRScope(this);
}
}
public String getScopeName() {
return "Method";
}
@Override
public void addInstr(Instr i) {
// Accumulate call arguments
if (i instanceof ReceiveRestArgBase) callArgs.add(new Splat(((ReceiveRestArgBase)i).getResult()));
else if (i instanceof ReceiveArgBase) callArgs.add(((ReceiveArgBase) i).getResult());
super.addInstr(i);
}
public void addArgDesc(String type, String argName) {
argDesc.add(new String[]{type, argName});
}
public List<String[]> getArgDesc() {
return argDesc;
}
public Operand[] getCallArgs() {
return callArgs.toArray(new Operand[callArgs.size()]);
}
@Override
public LocalVariable findExistingLocalVariable(String name, int scopeDepth) {
assert scopeDepth == 0: "Local variable depth in IRMethod should always be zero (" + name + " had depth of " + scopeDepth + ")";
return localVars.getVariable(name);
}
@Override
public LocalVariable getNewLocalVariable(String name, int scopeDepth) {
assert scopeDepth == 0: "Local variable depth in IRMethod should always be zero (" + name + " had depth of " + scopeDepth + ")";
LocalVariable lvar = new LocalVariable(name, 0, localVars.nextSlot);
localVars.putVariable(name, lvar);
return lvar;
}
@Override
public LocalVariable getLocalVariable(String name, int scopeDepth) {
LocalVariable lvar = findExistingLocalVariable(name, scopeDepth);
if (lvar == null) lvar = getNewLocalVariable(name, scopeDepth);
return lvar;
}
public LocalVariable getImplicitBlockArg() {
return getLocalVariable(Variable.BLOCK, 0);
}
}