%PDF- %PDF-
Direktori : /usr/local/lib/python2.7/lib2to3/ |
Current File : //usr/local/lib/python2.7/lib2to3/btm_matcher.pyc |
ó Pêáac @ 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 d e f d „ ƒ YZ d e f d „ ƒ YZ i a d „ Z d S( sŒ 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.s+ George Boutsioukis <gboutsioukis@gmail.com>iÿÿÿÿN( t defaultdicti ( t pytree( t reduce_treet BMNodec B s# e Z d Z e j ƒ Z d „ Z RS( s? Class for a node of the Aho-Corasick automaton used in matchingc C s1 i | _ g | _ t t j ƒ | _ d | _ d S( Nt ( t transition_tablet fixerst nextR t countt idt content( t self( ( s/ /usr/local/lib/python2.7/lib2to3/btm_matcher.pyt __init__ s ( t __name__t __module__t __doc__t itertoolsR R ( ( ( s/ /usr/local/lib/python2.7/lib2to3/btm_matcher.pyR s t BottomMatcherc B s; e Z d Z d „ Z d „ Z d „ Z d „ Z d „ Z RS( sg 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( Nt RefactoringTool( t sett matchR t roott nodesR t loggingt getLoggert logger( R ( ( s/ /usr/local/lib/python2.7/lib2to3/btm_matcher.pyR s c C sh | j j | ƒ t | j ƒ } | j ƒ } | j | d | j ƒ} x | D] } | j j | ƒ qJ Wd S( sÒ 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 reachedt startN( R t appendR t pattern_treet get_linear_subpatternt addR ( R t fixert treet lineart match_nodest match_node( ( s/ /usr/local/lib/python2.7/lib2to3/btm_matcher.pyt add_fixer% s c C sú | s | g St | d t ƒ r‚ g } xU | d D]I } | j | d | ƒ} x+ | D]# } | j | j | d | ƒ ƒ qS Wq1 W| S| d | j k r² t ƒ } | | j | d <n | j | d } | d ré | j | d d | ƒ} n | g } | Sd S( s5 Recursively adds a linear pattern to the AC automatoni R i N( t isinstancet tupleR t extendR R ( R t patternR R"