def resolve_state_vars(expr, state_vars, mangled_names):
    """Convert references to state variables into NamedStateAttributeRef
    references.

    :param expr: An expression instances
    :type expr: Expression
    :param state_vars: Variables that represent state variables
    :type state_vars: List of strings
    :param mangled_names: A mapping from name to its mangled version
    :type mangled_names: Dictionary from string to string
    :return: An instance of Expression
    """

    def convert(n):
        if isinstance(n, NamedAttributeRef) and n.name in state_vars:
            n = NamedStateAttributeRef(mangled_names[n.name])
        else:
            n.apply(convert)
        return n

    return convert(copy.deepcopy(expr))
dataset/ETHPy150Open uwescience/raco/raco/expression/util.py/resolve_state_vars/original