Your IP : 3.139.234.68
�
�Q�f� � �v � d Z dZddlZddlZddlmZ ddlmZ ddlm Z G d� d e
� Z G d
� de
� Zi a
d� Zy)
a� A bottom-up tree matching algorithm implementation meant to speed
up 2to3's matching process. After the tree patterns are reduced to
their rarest linear path, a linear Aho-Corasick automaton is
created. The linear automaton traverses the linear paths from the
leaves to the root of the AST and returns a set of nodes for further
matching. This reduces significantly the number of candidate nodes.z+George Boutsioukis <gboutsioukis@gmail.com>� N)�defaultdict� )�pytree)�reduce_treec �8 � e Zd ZdZ ej
� Zd� Zy)�BMNodez?Class for a node of the Aho-Corasick automaton used in matchingc �j � i | _ g | _ t t j � | _ d| _ y )N� )�transition_table�fixers�nextr �count�id�content��selfs �:/opt/alt/python312/lib64/python3.12/lib2to3/btm_matcher.py�__init__zBMNode.__init__ s( � � "�������v�|�|�$������ N)�__name__�
__module__�__qualname__�__doc__� itertoolsr r � r r r r s � �I��I�O�O��E�r r c �. � e Zd ZdZd� Zd� Zd� Zd� Zd� Zy)�
BottomMatcherzgThe main matcher class. After instantiating the patterns should
be added using the add_fixer methodc � � t � | _ t � | _ | j g| _ g | _ t
j d� | _ y )N�RefactoringTool) �set�matchr �root�nodesr �logging� getLogger�loggerr s r r zBottomMatcher.__init__ s; � ��U��
��H�� ��i�i�[��
�����'�'�(9�:��r c � � | j j |� t |j � }|j � }| j || j �� }|D ] }|j j |� � y)z�Reduces a fixer's pattern tree to a linear path and adds it
to the matcher(a common Aho-Corasick automaton). The fixer is
appended on the matching states and called when they are
reached��startN)r �appendr �pattern_tree�get_linear_subpattern�addr"