AlkantarClanX12
Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/lib2to3/__pycache__/ |
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/lib2to3/__pycache__/btm_matcher.cpython-35.pyc |
��Yf� � @ s� d Z d Z d d l Z d d l Z d d l m Z d d l m Z d d l m Z Gd d � d e � Z Gd d � d e � Z i a d d � Z d S)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 @ s. e Z d Z d Z e j � Z d d � Z d S)�BMNodez?Class for a node of the Aho-Corasick automaton used in matchingc C s1 i | _ g | _ t t j � | _ d | _ d S)N� )�transition_table�fixers�nextr �count�id�content)�self� r �8/opt/alt/python35/lib64/python3.5/lib2to3/btm_matcher.py�__init__ s zBMNode.__init__N)�__name__� __module__�__qualname__�__doc__� itertoolsr r r r r r r s r c @ sR e Z d Z d Z d d � Z d d � Z d d � Z d d � Z d d � Z d S) � BottomMatcherzgThe main matcher class. After instantiating the patterns should be added using the add_fixer methodc C sF t � | _ t � | _ | j g | _ g | _ t j d � | _ d S)NZRefactoringTool) �set�matchr �rootZnodesr �loggingZ getLoggerZlogger)r r r r r s zBottomMatcher.__init__c C sh | j j | � t | j � } | j � } | j | d | j �} x | D] } | j j | � qJ Wd S)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 Zpattern_treeZget_linear_subpattern�addr )r �fixerZtreeZlinear�match_nodesZ match_noder r r � add_fixer% s zBottomMatcher.add_fixerc C s | s | g St | d t � r� g } x[ | d D]O } | j | d | �} x1 | D]) } | j | j | d d � | � � qS Wq1 W| S| d | j k r� t � } | | j | d <n | j | d } | d d � r� | j | d d � d | �} n | g } | Sd S)z5Recursively adds a linear pattern to the AC automatonr r r N)� isinstance�tupler �extendr r )r �patternr r ZalternativeZ end_nodes�endZ next_noder r r r 1 s"