<commit_before>"""
Fulara Syntactic Dictionary Usage Abstract Domain
===============================

Abstract domain to be used for **input data usage analysis** using syntactic variable dependencies
with support to analyze abstract dictionary segments.
A program variable or dictionary segment
can have value *U* (used), *S* (scoped), *W* (written), and *N* (not used).

:Authors: <NAME>
"""
from collections import defaultdict
from copy import deepcopy, copy
from typing import Type, Set, Union, Callable

from lyra.abstract_domains.container.fulara.fulara_domain import FularaState
from lyra.abstract_domains.container.fulara.fulara_lattice import FularaLattice
from lyra.abstract_domains.container.fulara.key_wrapper import KeyWrapper
from lyra.abstract_domains.lattice import Lattice
from lyra.abstract_domains.stack import Stack
from lyra.abstract_domains.state import State
from lyra.abstract_domains.store import Store
from lyra.abstract_domains.usage.usage_domain import SimpleUsageStore
from lyra.abstract_domains.usage.usage_lattice import UsageLattice
from lyra.core.expressions import VariableIdentifier, Expression, Subscription, \
    _iter_child_exprs, NegationFreeNormalExpression, Keys, Values, \
    Items, BinaryComparisonOperation, TupleDisplay
from lyra.core.types import BooleanLyraType, IntegerLyraType, StringLyraType, \
    FloatLyraType, DictLyraType
from lyra.core.utils import copy_docstring

Status = UsageLattice.Status

# special variable names:
k_name = "0v_k"

scalar_types = {BooleanLyraType, IntegerLyraType, FloatLyraType, StringLyraType}


class FularaUsageLattice(Lattice):
    """Dictionary segment usage analysis state.
    An element of the dictionary segment usage abstract domain.

    It consists of the following 2 elements:
    - Usage domain state over all scalar variables, abstracting their usage status
    - Map from each dictionary variable to a DictSegmentLattice element with a given key domain K
       and the usage domain as value domain, abstracting the usage state of the dictionary segments
    TODO: Map from each dictionary variable to a usage status for the usage of the dictionary length

    All elements are *not used* (bottom) by default<commit_msg>pep 8 fix<commit_after>"""
Fulara Syntactic Dictionary Usage Abstract Domain
===============================

Abstract domain to be used for **input data usage analysis** using syntactic variable dependencies
with support to analyze abstract dictionary segments.
A program variable or dictionary segment
can have value *U* (used), *S* (scoped), *W* (written), and *N* (not used).

:Authors: <NAME>
"""
from collections import defaultdict
from copy import deepcopy, copy
from typing import Type, Set, Union, Callable

from lyra.abstract_domains.container.fulara.fulara_domain import FularaState
from lyra.abstract_domains.container.fulara.fulara_lattice import FularaLattice
from lyra.abstract_domains.container.fulara.key_wrapper import KeyWrapper
from lyra.abstract_domains.lattice import Lattice
from lyra.abstract_domains.stack import Stack
from lyra.abstract_domains.state import State
from lyra.abstract_domains.store import Store
from lyra.abstract_domains.usage.usage_domain import SimpleUsageStore
from lyra.abstract_domains.usage.usage_lattice import UsageLattice
from lyra.core.expressions import VariableIdentifier, Expression, Subscription, \
    _iter_child_exprs, NegationFreeNormalExpression, Keys, Values, \
    Items, BinaryComparisonOperation, TupleDisplay
from lyra.core.types import BooleanLyraType, IntegerLyraType, StringLyraType, \
    FloatLyraType, DictLyraType
from lyra.core.utils import copy_docstring

Status = UsageLattice.Status

# special variable names:
k_name = "0v_k"

scalar_types = {BooleanLyraType, IntegerLyraType, FloatLyraType, StringLyraType}


class FularaUsageLattice(Lattice):
    """Dictionary segment usage analysis state.
    An element of the dictionary segment usage abstract domain.

    It consists of the following 2 elements:
    - Usage domain state over all scalar variables, abstracting their usage status
    - Map from each dictionary variable to a DictSegmentLattice element with a given key domain K
       and the usage domain as value domain, abstracting the usage state of the dictionary segments
    TODO: Map from each dictionary variable to a usage status for the usage of the dictionary
                                                                                        length

    All elements are *not used* (bottom) by default
{'fraction_non_alphanumeric': 0.06725663716814159, 'fraction_numerical': 0.0011061946902654867, 'mean_word_length': 4.925294888597641, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '526954', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1158, 'n_words': 455}