use of com.jetbrains.python.codeInsight.dataflow.scope.impl.ScopeVariableImpl in project intellij-community by JetBrains.
the class PyReachingDefsDfaInstance method processReducedMap.
private DFAMap<ScopeVariable> processReducedMap(DFAMap<ScopeVariable> map, final Instruction instruction, final PsiElement element) {
String name = null;
// Process readwrite instruction
if (instruction instanceof ReadWriteInstruction && ((ReadWriteInstruction) instruction).getAccess().isWriteAccess()) {
name = ((ReadWriteInstruction) instruction).getName();
} else // Processing PyFunction
if (element instanceof PyFunction) {
name = ((PyFunction) element).getName();
}
if (name == null) {
return map;
}
final ScopeVariable variable = map.get(name);
// Parameter case
final PsiElement parameterScope = ScopeUtil.getParameterScope(element);
if (parameterScope != null) {
final ScopeVariable scopeVariable = new ScopeVariableImpl(name, true, element);
map = map.asWritable();
map.put(name, scopeVariable);
} else // Local variable case
{
final ScopeVariableImpl scopeVariable;
final boolean isParameter = variable != null && variable.isParameter();
if (variable == null) {
scopeVariable = new ScopeVariableImpl(name, isParameter, element);
} else {
scopeVariable = new ScopeVariableImpl(name, isParameter, variable.getDeclarations());
}
map = map.asWritable();
map.put(name, scopeVariable);
}
return map;
}
use of com.jetbrains.python.codeInsight.dataflow.scope.impl.ScopeVariableImpl in project intellij-community by JetBrains.
the class PyReachingDefsSemilattice method join.
public DFAMap<ScopeVariable> join(ArrayList<DFAMap<ScopeVariable>> ins) {
if (ins.isEmpty()) {
return DFAMap.empty();
}
if (ins.size() == 1) {
return ins.get(0);
}
final Set<String> resultNames = getResultNames(ins);
if (resultNames == null || resultNames.isEmpty()) {
return new DFAMap<>();
}
final DFAMap<ScopeVariable> result = new DFAMap<>();
for (String name : resultNames) {
boolean isParameter = true;
Set<PsiElement> declarations = new HashSet<>();
// iterating over all maps
for (DFAMap<ScopeVariable> map : ins) {
final ScopeVariable variable = map.get(name);
if (variable == null) {
continue;
}
isParameter = isParameter && variable.isParameter();
declarations.addAll(variable.getDeclarations());
}
final ScopeVariable scopeVariable = new ScopeVariableImpl(name, isParameter, declarations);
result.put(name, scopeVariable);
}
return result;
}
Aggregations