Search in sources :

Example 1 with ScopeVariableImpl

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;
}
Also used : ReadWriteInstruction(com.jetbrains.python.codeInsight.controlflow.ReadWriteInstruction) PyFunction(com.jetbrains.python.psi.PyFunction) ScopeVariableImpl(com.jetbrains.python.codeInsight.dataflow.scope.impl.ScopeVariableImpl) ScopeVariable(com.jetbrains.python.codeInsight.dataflow.scope.ScopeVariable) PsiElement(com.intellij.psi.PsiElement)

Example 2 with ScopeVariableImpl

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;
}
Also used : ScopeVariableImpl(com.jetbrains.python.codeInsight.dataflow.scope.impl.ScopeVariableImpl) ScopeVariable(com.jetbrains.python.codeInsight.dataflow.scope.ScopeVariable) PsiElement(com.intellij.psi.PsiElement) DFAMap(com.intellij.codeInsight.dataflow.map.DFAMap) HashSet(com.intellij.util.containers.HashSet)

Aggregations

PsiElement (com.intellij.psi.PsiElement)2 ScopeVariable (com.jetbrains.python.codeInsight.dataflow.scope.ScopeVariable)2 ScopeVariableImpl (com.jetbrains.python.codeInsight.dataflow.scope.impl.ScopeVariableImpl)2 DFAMap (com.intellij.codeInsight.dataflow.map.DFAMap)1 HashSet (com.intellij.util.containers.HashSet)1 ReadWriteInstruction (com.jetbrains.python.codeInsight.controlflow.ReadWriteInstruction)1 PyFunction (com.jetbrains.python.psi.PyFunction)1