ž
¬ÿ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 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