python (3.12.0)

(root)/
lib/
python3.12/
lib2to3/
__pycache__/
btm_matcher.cpython-312.pyc

̑evdZdZddlZddlZddlmZddlmZddlm	Z	Gdd	e
ZGd
de
Zia
dZy)
aA 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_treec8eZdZdZej
ZdZy)BMNodez?Class for a node of the Aho-Corasick automaton used in matchingcji|_g|_ttj|_d|_y)N)transition_tablefixersnextrcountidcontentselfs G/BuggyBox/python/3.12.0/bootstrap/lib/python3.12/lib2to3/btm_matcher.py__init__zBMNode.__init__s( "v||$N)__name__
__module____qualname____doc__	itertoolsrrrrrrsIIOOErrc.eZdZdZdZdZdZdZdZy)
BottomMatcherzgThe main matcher class. After instantiating the patterns should
    be added using the add_fixer methodct|_t|_|jg|_g|_t
jd|_y)NRefactoringTool)	setmatchrrootnodesrlogging	getLoggerloggerrs rrzBottomMatcher.__init__s;U
H	ii[
''(9:rc|jj|t|j}|j	}|j||j}|D]}|jj|y)zReduces 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
        reachedstartN)rappendrpattern_treeget_linear_subpatternaddr")rfixertreelinearmatch_nodes
match_nodes      r	add_fixerzBottomMatcher.add_fixer%sm
	
5!5--.++-hhvTYYh7%	,J$$U+	,rc	|s|gSt|dtrLg}|dD]@}|j||}|D]&}|j|j|dd|(B|S|d|jvrt}||j|d<n|j|d}|ddr|j|dd|}|S|g}|S)z5Recursively adds a linear pattern to the AC automatonrr(rN)
isinstancetupler-extendrr)rpatternr)r1alternative	end_nodesend	next_nodes        rr-zBottomMatcher.add1s7Ngaj%(K&qz
C!HH[H>	$CC&&txxS'ABC	
Cqz!7!77"H	5>&&wqz2"2271:>	qr{ HHWQR[	HB	'K	rc|j}tt}|D]?}|}|s	d|_|jD]5}t|tjs|jdk(s.d|_n|jdk(r
|j}n|j}||jvr5|j|}|jD]}||j|nq|j}|j|jjr||jvr4|j|}|jD]}||j||j}|r7B|S)auThe main interface with the bottom matcher. The tree is
        traversed from the bottom using the constructed
        automaton. Nodes are only checked once as the tree is
        retraversed. When the automaton fails, we give it one more
        shot(in case the above tree matches as a whole with the
        rejected leaf), then we break for the next leaf. There is the
        special case of multiple arguments(see code comments) where we
        recheck the nodes

        Args:
           The leaves of the AST tree to be matched

        Returns:
           A dictionary of node matches with fixers as the keys
        T;Fr)r"rlistwas_checkedchildrenr5rLeafvaluetyperrr*parent)	rleavescurrent_ac_noderesultsleafcurrent_ast_nodechild
node_tokenr.s	         rrunzBottomMatcher.runSso ))d##	;D#"/3 ,-66E!%5%++:L7<(4	
$((A-!1!7!7J!1!6!6J!A!AA&5&F&Fz&RO!0!7!7@--.>?@'+iiO(//;,33??"_%E%EE*9*J*J:*V%4%;%;DE#EN112BCD$4#:#: C##	;Hrc`tdfd|jtdy)z<Prints a graphviz diagram of the BM automaton(for debugging)z
digraph g{c
*|jjD]u}|j|}td|j|jt	|t|jfz|dk(rt|j|wy)Nz%d -> %d [label=%s] //%sr)rkeysprintr	type_reprstrrr)nodesubnode_keysubnode
print_nodes   rrWz*BottomMatcher.print_ac.<locals>.print_nodes#4499;
$//<0ww

Ik,BCDWXYZ!#'//*7#

$r}N)rQr")rrWs @rprint_aczBottomMatcher.print_acs%
l	$	499
c
rN)	rrrrrr3r-rMrYrrrrrs"+;
, D6prrctsDddlm}|jj	D]!\}}t|tk(s|t|<#tj||S)Nr)python_symbols)_type_reprspygramr[__dict__itemsrDint
setdefault)type_numr[namevals    rrRrRsT*(00668	9ID#CyCDS!1	9!!(H55r)r
__author__r$rcollectionsrr
r	btm_utilsrobjectrrr\rRrrr<module>risHG;
#"V}F}@6r