org.jruby.ir.dataflow.analyses.DefinedVariablesProblem Maven / Gradle / Ivy
package org.jruby.ir.dataflow.analyses;
import org.jruby.ir.IRScope;
import org.jruby.ir.dataflow.DataFlowProblem;
import org.jruby.ir.operands.Variable;
import org.jruby.ir.representations.BasicBlock;
import java.util.*;
public class DefinedVariablesProblem extends DataFlowProblem {
public static final String NAME = "Defined Variables Analysis";
public DefinedVariablesProblem(IRScope scope) {
super(DataFlowProblem.DF_Direction.FORWARD);
setup(scope);
}
public Integer getDFVar(Variable v) {
return dfVarMap.get(v);
}
public boolean dfVarExists(Variable v) {
return getDFVar(v) != null;
}
public Variable getVariable(int id) {
return varDfVarMap.get(id);
}
@Override
public DefinedVariableNode buildFlowGraphNode(BasicBlock bb) {
return new DefinedVariableNode(this, bb);
}
public void addDFVar(Variable v) {
Integer dfv = addDataFlowVar();
dfVarMap.put(v, dfv);
varDfVarMap.put(dfv, v);
vars.add(v);
}
public Set findUndefinedVars() {
Set undefinedVars = new HashSet();
for (DefinedVariableNode n : flowGraphNodes) {
n.identifyInits(undefinedVars);
}
return undefinedVars;
}
public Set getAllVars() {
return dfVarMap.keySet();
}
@Override
public String getName() {
return NAME;
}
/* ----------- Private Interface ------------ */
private HashMap dfVarMap = new HashMap();
private HashMap varDfVarMap = new HashMap();
private HashSet vars = new HashSet();
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy