grthtrhthjhtyjytjytkergtrhtrjytjerhrfh3 \±ã@shdZddlZddlZddlmZddlmZddlmZGdd„de ƒZ Gd d „d e ƒZ ia d d „Z dS) z+George Boutsioukis éN)Ú defaultdicté)Úpytree)Ú reduce_treec@seZdZejƒZdd„ZdS)ÚBMNodecCs"i|_g|_ttjƒ|_d|_dS)NÚ)Útransition_tableÚfixersÚnextrÚcountÚidÚcontent)Úself©rú+/usr/lib64/python3.6/lib2to3/btm_matcher.pyÚ__init__s zBMNode.__init__N)Ú__name__Ú __module__Ú __qualname__Ú itertoolsr rrrrrrsrc@s4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) Ú BottomMatchercCs0tƒ|_tƒ|_|jg|_g|_tjdƒ|_dS)NZRefactoringTool) ÚsetÚmatchrÚrootZnodesr ÚloggingZ getLoggerZlogger)rrrrrs  zBottomMatcher.__init__cCsL|jj|ƒt|jƒ}|jƒ}|j||jd�}x|D]}|jj|ƒq4WdS)N)Ústart)r ÚappendrZ pattern_treeZget_linear_subpatternÚaddr)rÚfixerZtreeZlinearÚ match_nodesZ match_noderrrÚ add_fixer%s    zBottomMatcher.add_fixercCsÌ|s |gSt|dtƒrhg}xF|dD]:}|j||d�}x&|D]}|j|j|dd…|ƒƒq>Wq&W|S|d|jkrŒtƒ}||j|d<n|j|d}|dd…r¾|j|dd…|d�}n|g}|SdS)Nr)rr)Ú isinstanceÚtuplerÚextendrr)rÚpatternrrÚ alternativeZ end_nodesÚendZ next_noderrrr1s" " zBottomMatcher.addc Cs0|j}ttƒ}�x|D�]}|}�x|�r&d|_x,|jD]"}t|tjƒr8|jdkr8d|_Pq8W|j dkrp|j}n|j }||j krº|j |}x’|j D]"}||kr¦g||<||j |ƒq’Wnd|j}|j dk rÔ|j jrÔP||j k�r|j |}x2|j D](}||jƒk�r g||<||j |ƒqòW|j }q$WqW|S)NTú;Fr)rrÚlistZ was_checkedZchildrenr!rZLeafÚvalueÚtyperr rÚparentÚkeys) rZleavesZcurrent_ac_nodeZresultsZleafZcurrent_ast_nodeZchildZ node_tokenrrrrÚrunSs>          zBottomMatcher.runcs*tdƒ‡fdd„‰ˆ|jƒtdƒdS)Nz digraph g{cs^xX|jjƒD]J}|j|}td|j|jt|ƒt|jƒfƒ|dkrNt|jƒˆ|ƒq WdS)Nz%d -> %d [label=%s] //%sr)rr,Úprintr Ú type_reprÚstrr r )ZnodeZ subnode_keyZsubnode)Ú print_noderrr1“s  z*BottomMatcher.print_ac..print_nodeú})r.r)rr)r1rÚprint_ac�s  zBottomMatcher.print_acN)rrrrr rr-r3rrrrrs  "=rcCsHtss