python (3.11.7)

(root)/
lib/
python3.11/
lib2to3/
__pycache__/
btm_matcher.cpython-311.opt-1.pyc

edZdZddlZddlZddlmZddlmZddlm	Z	Gdd	e
ZGd
de
Zia
dZdS)
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_treec6eZdZdZejZdZdS)BMNodez?Class for a node of the Aho-Corasick automaton used in matchingcli|_g|_ttj|_d|_dS)N)transition_tablefixersnextrcountidcontentselfs G/BuggyBox/python/3.11.7/bootstrap/lib/python3.11/lib2to3/btm_matcher.py__init__zBMNode.__init__s- "v|$$N)__name__
__module____qualname____doc__	itertoolsrrrrrrs8IIIOErrc0eZdZdZdZdZdZdZdZdS)
BottomMatcherzgThe main matcher class. After instantiating the patterns should
    be added using the add_fixer methodct|_t|_|jg|_g|_t
jd|_dS)NRefactoringTool)	setmatchrrootnodesrlogging	getLoggerloggerrs rrzBottomMatcher.__init__sAUU
HH	i[
'(9::rc|j|t|j}|}|||j}|D]}|j|dS)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%s
	
5!!!5-..++--hhvTYh77%	,	,J$$U++++	,	,rc	|s|gSt|dtr\g}|dD]O}|||}|D]3}|||dd|4P|S|d|jvrt}||j|d<n|j|d}|ddr ||dd|}n|g}|S)z5Recursively adds a linear pattern to the AC automatonrr(rN)
isinstancetupler-extendrr)rpatternr)r1alternative	end_nodesend	next_nodes        rr-zBottomMatcher.add1s&	7Ngaj%((	K&qz
C
C!HH[H>>	$CCC&&txxS'A'ABBBBCqz!777"HH	5>&wqz22"271:>	qrr{
( HHWQRR[	HBB		&K	rc6|j}tt}|D]}|}|rd|_|jD]0}t|tjr|jdkr	d|_n1|j	dkr|j}n|j	}||j
vr3|j
|}|jD]}|||nV|j}|j

|j
jrnD||j
vr2|j
|}|jD]}||||j
}||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.runSs )d###	;#	;D#"!
;/3 ,-6E!%55%+:L:L7<(4#(A--!1!7JJ!1!6J!AAA&5&Fz&RO!0!7@@--.>????@'+iO(/;,3?<"_%EEE*9*J:*V%4%;DDE#EN112BCCCC#3#: C#!
;Drcntdfd|jtddS)z<Prints a graphviz diagram of the BM automaton(for debugging)z
digraph g{c
"|jD]s}|j|}td|j|jt	|t|jfz|dkrt|j|tdS)Nz%d -> %d [label=%s] //%sr)rkeysprintr	type_reprstrrr)nodesubnode_keysubnode
print_nodes   rrWz*BottomMatcher.print_ac.<locals>.print_nodes#499;;
$
$/<0w
Ik,B,BCDWDWXYZZZ!##'/***
7####

$
$r}N)rQr")rrWs @rprint_aczBottomMatcher.print_acsM
l	$	$	$	$	$	
49
c




rN)	rrrrrr3r-rMrYrrrrrsk++;;;
,
,
,   D666prrctsGddlm}|jD]'\}}t|tkr
|t|<(t||S)Nr)python_symbols)_type_reprspygramr[__dict__itemsrDint
setdefault)type_numr[namevals    rrRrRsq9******(06688	9	9ID#CyyCDS!1!!(H555r)r
__author__r$rcollectionsrr
r	btm_utilsrobjectrrr\rRrrr<module>risGG;
######""""""V}}}}}F}}}@66666r