B (4T@shdZddlZddlZddlmZddlmZddlmZGddde Z Gd d d e Z ia d d Z dS) z+George Boutsioukis N) defaultdict)pytree) reduce_treec@seZdZeZddZdS)BMNodecCs"i|_g|_ttj|_d|_dS)N)transition_tablefixersnextrcountidcontent)selfr6/opt/alt/python37/lib/python3.7/lib2to3/btm_matcher.py__init__s zBMNode.__init__N)__name__ __module__ __qualname__ itertoolsr rrrrrrsrc@s4eZdZddZddZddZddZd d Zd S) BottomMatchercCs0t|_t|_|jg|_g|_td|_dS)NZRefactoringTool) setmatchrrootZnodesr loggingZ getLoggerZlogger)rrrrrs  zBottomMatcher.__init__cCsL|j|t|j}|}|j||jd}x|D]}|j|q4WdS)N)start)r appendrZ pattern_treeZget_linear_subpatternaddr)rfixerZtreeZlinear match_nodesZ match_noderrr add_fixer%s    zBottomMatcher.add_fixerc Cs|s |gSt|dtrhg}xF|dD]:}|j||d}x&|D]}|||dd|q>Wq&W|S|d|jkrt}||j|d<n|j|d}|ddr|j|dd|d}n|g}|SdS)Nr)rr) isinstancetuplerextendrr)rpatternrrZ alternativeZ end_nodesendZ next_noderrrr1s" " zBottomMatcher.addc Cs|j}tt}x|D]}|}x|rd|_x,|jD]"}t|tjr0|jdkr0d|_Pq0W|j dkrh|j}n|j }||j kr|j |}xj|j D]}|| |qWnL|j}|j dk r|j jrP||j kr|j |}x|j D]}|| |qW|j }qWqW|S)NT;Fr)rrlistZ was_checkedZchildrenr!rZLeafvaluetyperr rparent) rZleavesZcurrent_ac_noderesultsZleafZcurrent_ast_nodeZchildZ node_tokenrrrrrunSs6          zBottomMatcher.runcs*tdfdd|jtddS)Nz digraph g{cs^xX|jD]J}|j|}td|j|jt|t|jf|dkrNt|j|q WdS)Nz%d -> %d [label=%s] //%sr)rkeysprintr type_reprstrr r )ZnodeZ subnode_keyZsubnode) print_noderrr1s  z*BottomMatcher.print_ac..print_node})r.r)rr)r1rprint_acs  zBottomMatcher.print_acN)rrrrr rr,r3rrrrrs  "8rcCsHtss