3 \@shdZddlZddlZddlmZddlmZddlmZGddde Z Gd d d e Z ia d d Z dS) z+George Boutsioukis N) defaultdict)pytree) reduce_treec@seZdZejZddZdS)BMNodecCs"i|_g|_ttj|_d|_dS)N)transition_tablefixersnextrcountidcontent)selfr+/usr/lib64/python3.6/lib2to3/btm_matcher.py__init__s zBMNode.__init__N)__name__ __module__ __qualname__ itertoolsr rrrrrrsrc@s4eZdZddZddZddZddZd d Zd S) BottomMatchercCs0t|_t|_|jg|_g|_tjd|_dS)NZRefactoringTool) setmatchrrootZnodesr loggingZ getLoggerZlogger)rrrrrs  zBottomMatcher.__init__cCsL|jj|t|j}|j}|j||jd}x|D]}|jj|q4WdS)N)start)r appendrZ pattern_treeZget_linear_subpatternaddr)rfixerZtreeZlinear match_nodesZ match_noderrr add_fixer%s    zBottomMatcher.add_fixercCs|s |gSt|dtrhg}xF|dD]:}|j||d}x&|D]}|j|j|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 Cs0|j}tt}x|D]}|}x|r&d|_x,|jD]"}t|tjr8|jdkr8d|_Pq8W|j dkrp|j}n|j }||j kr|j |}x|j D]"}||krg||<||j |qWnd|j}|j dk r|j jrP||j kr|j |}x2|j D](}||jkr g||<||j |qW|j }q$WqW|S)NT;Fr)rrlistZ was_checkedZchildrenr!rZLeafvaluetyperr rparentkeys) rZleavesZcurrent_ac_nodeZresultsZleafZcurrent_ast_nodeZchildZ node_tokenrrrrrunSs>          zBottomMatcher.runcs*tdfdd|jtddS)Nz digraph g{cs^xX|jjD]J}|j|}td|j|jt|t|jf|dkrNt|j|q WdS)Nz%d -> %d [label=%s] //%sr)rr+printr type_reprstrr r )ZnodeZ subnode_keyZsubnode) print_noderrr0s  z*BottomMatcher.print_ac..print_node})r-r)rr)r0rprint_acs  zBottomMatcher.print_acN)rrrrr rr,r2rrrrrs  "=rcCsHtss