AlkantarClanX12
Current Path : /opt/alt/python33/lib64/python3.3/lib2to3/__pycache__/ |
Current File : //opt/alt/python33/lib64/python3.3/lib2to3/__pycache__/btm_matcher.cpython-33.pyo |
� ��f� c @ 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( u� 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.u+ George Boutsioukis <gboutsioukis@gmail.com>i N( u defaultdicti ( u pytree( u reduce_treec B s2 | Ee Z d Z d Z e j � Z d d � Z d S( u BMNodeu? Class for a node of the Aho-Corasick automaton used in matchingc C s1 i | _ g | _ t t j � | _ d | _ d S( Nu ( u transition_tableu fixersu nextu BMNodeu countu idu content( u self( ( u8 /opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu __init__ s u BMNode.__init__N( u __name__u __module__u __qualname__u __doc__u itertoolsu countu __init__( u __locals__( ( u8 /opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu BMNode s u BMNodec B sV | Ee Z d Z d Z d d � Z d d � Z d d � Z d d � Z d d � Z d S( u BottomMatcherug The 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( Nu RefactoringTool( u setu matchu BMNodeu rootu nodesu fixersu loggingu getLoggeru logger( u self( ( u8 /opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu __init__ s u BottomMatcher.__init__c C sh | j j | � t | j � } | j � } | j | d | j �} x | D] } | j j | � qJ Wd S( u� 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 reachedu startN( u fixersu appendu reduce_treeu pattern_treeu get_linear_subpatternu addu root( u selfu fixeru treeu linearu match_nodesu match_node( ( u8 /opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu add_fixer% s u BottomMatcher.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( u5 Recursively adds a linear pattern to the AC automatoni u starti N( u isinstanceu tupleu addu extendu transition_tableu BMNode( u selfu patternu startu match_nodesu alternativeu end_nodesu endu next_node( ( u8 /opt/alt/python33/lib64/python3.3/lib2to3/btm_matcher.pyu add1 s"