1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780(*
Copyright 2012-2025 Codinuum Software Lab <https://codinuum.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)(* py_label.ml *)moduleXset=Diffast_misc.XsetmoduleXlist=Diffast_misc.XlistmoduleXML=Diffast_misc.XMLmoduleLoc=Diffast_misc.LocmoduleAstml=Diffast_core.AstmlmoduleLang_base=Diffast_core.Lang_basemoduleCharpool=Diffast_core.CharpoolmoduleAst=Python_parsing.Asttypename=stringletlang_prefix=Astml.python_prefixletoperator_attr_name="operator"letsprintf=Printf.sprintfletkeyroot_depth_min=1typetie_id=Lang_base.tie_idletnull_tid=Lang_base.null_tidletmktid=Lang_base.mktidlettid_to_string=Lang_base.tid_to_stringletanonymize_tid=Lang_base.anonymize_tidletmktidattr=Lang_base.mktidattrletconv_loc{Ast.Loc.start_offset=so;Ast.Loc.end_offset=eo;Ast.Loc.start_line=sl;Ast.Loc.start_char=sc;Ast.Loc.end_line=el;Ast.Loc.end_char=ec;_}=Loc.makesoeoslscelecletconv_name(_,name)=nameletloc_of_name(loc,_)=locletdottedname_to_stringdname=String.concat"."(List.mapconv_namedname)openCharpoolmoduleLiteral=structtypet=|Integerofstring|LongIntegerofstring|FloatNumberofstring|ImagNumberofstring|Stringofstring|CatStringofstring|None_|True|Falseletto_string=function|Integerstr->sprintf"Integer:%s"str|LongIntegerstr->sprintf"LongInteger:%s"str|FloatNumberstr->sprintf"FloatNumber:%s"str|ImagNumberstr->sprintf"ImagNumber:%s"str|Stringstr->sprintf"String(%s)"str|CatStringstr->sprintf"CatString(%s)"str|None_->"None_"|True->"True"|False->"False"letto_simple_string=function|Integerstr|LongIntegerstr|FloatNumberstr|ImagNumberstr|Stringstr|CatStringstr->str|None_->"None"|True->"True"|False->"False"letanonymize=function|Integer_->Integer""|LongInteger_->LongInteger""|FloatNumber_->FloatNumber""|ImagNumber_->ImagNumber""|String_->String""|CatString_->CatString""|x->xletto_short_string?(ignore_identifiers_flag=false)=letcombo=combo~ignore_identifiers_flaginfunction|Integer_->mkstr0|LongIntegerstr->combo1[str]|FloatNumberstr->combo2[str]|ImagNumberstr->combo3[str]|Stringstr->combo4[str]|CatStringstr->combo5[str]|None_->mkstr6|True->mkstr7|False->mkstr8letpystr_to_string=function|Ast.PSshort(_,s)|Ast.PSlong(_,s)->sletof_literal=function|Ast.Lintegerstr->Integerstr|Ast.Llongintegerstr->LongIntegerstr|Ast.Lfloatnumberstr->FloatNumberstr|Ast.Limagnumberstr->ImagNumberstr|Ast.Lstring[]->String""|Ast.Lstring[pystr]->String(pystr_to_stringpystr)|Ast.Lstringpystrs->beginlets=String.concat""(List.map(function|Ast.PSshort(_,s)->String.subs1((String.lengths)-2)|Ast.PSlong(_,s)->String.subs3((String.lengths)-6))pystrs)inlets_=iftrue||(String.lengths)>string_len_thresholdthenDigest.to_hex(Digest.strings)elsesinCatStrings_end|Ast.Lnone->None_|Ast.Ltrue->True|Ast.Lfalse->Falseletto_taglit=letname,attrs=matchlitwith|Integerstr->"IntegerLiteral",["value",XML.encode_stringstr]|LongIntegerstr->"LongIntegerLiteral",["value",XML.encode_stringstr]|FloatNumberstr->"FloatNumberLiteral",["value",XML.encode_stringstr]|ImagNumberstr->"ImagNumberLiteral",["value",XML.encode_stringstr]|Stringstr->"StringLiteral",["value",XML.encode_stringstr]|CatStringstr->"CatStringLiteral",["value",XML.encode_stringstr]|None_->"None_",[]|True->"True",[]|False->"False",[]inname,attrsend(* of module Literal *)moduleAssignmentOperator=structtypet=|Eq|AddEq|SubEq|MulEq|DivEq|ModEq|AndEq|OrEq|XorEq|ShiftLEq|ShiftREq|PowEq|FDivEqletto_simple_string=function|Eq->"="|AddEq->"+="|SubEq->"-="|MulEq->"*="|DivEq->"/="|ModEq->"%="|AndEq->"&="|OrEq->"|="|XorEq->"^="|ShiftLEq->"<<="|ShiftREq->">>="|PowEq->"**="|FDivEq->"//="letto_stringao=sprintf"AO(%s)"(to_simple_stringao)letto_short_string=function|Eq->mkstr0|AddEq->mkstr1|SubEq->mkstr2|MulEq->mkstr3|DivEq->mkstr4|ModEq->mkstr5|AndEq->mkstr6|OrEq->mkstr7|XorEq->mkstr8|ShiftLEq->mkstr9|ShiftREq->mkstr10|PowEq->mkstr11|FDivEq->mkstr12letof_aop=functionAst.AaddEq->AddEq|Ast.AsubEq->SubEq|Ast.AmulEq->MulEq|Ast.AdivEq->DivEq|Ast.AmodEq->ModEq|Ast.AandEq->AndEq|Ast.AorEq->OrEq|Ast.AxorEq->XorEq|Ast.AshiftLEq->ShiftLEq|Ast.AshiftREq->ShiftREq|Ast.ApowEq->PowEq|Ast.AfdivEq->FDivEqletto_tagaop=letname=matchaopwith|Eq->"Assign"|AddEq->"AddAssign"|SubEq->"SubtAssign"|MulEq->"MultAssign"|DivEq->"DivAssign"|ModEq->"ModAssign"|AndEq->"AndAssign"|OrEq->"OrAssign"|XorEq->"XorAssign"|ShiftLEq->"ShiftLAssign"|ShiftREq->"ShiftRAssign"|PowEq->"PowAssign"|FDivEq->"FDivAssign"inname,[]end(* of module AssignmentOperator *)moduleUnaryOperator=structtypet=|Positive|Negative|Complement|Notletto_simple_string=function|Positive->"+"|Negative->"-"|Complement->"~"|Not->"not "letto_stringuo=sprintf"UO(%s)"(to_simple_stringuo)letto_short_string=function|Positive->mkstr0|Negative->mkstr1|Complement->mkstr2|Not->mkstr3letof_uop=functionAst.Upositive->Positive|Ast.Unegative->Negative|Ast.Ucomplement->Complement|Ast.Unot->Notletto_taguo=letname=matchuowith|Positive->"Positive"|Negative->"Negative"|Complement->"Complement"|Not->"Not"inname,[]end(* of module UnaryOperator *)moduleBinaryOperator=structtypet=|Mul|Div|FDiv|Mod|Add|Sub|ShiftL|ShiftR|Eq|Neq|Lt|Gt|Le|Ge|BitAnd|BitOr|BitXor|And|Or|Is|IsNot|In|NotInletto_simple_string=function|Mul->"*"|Div->"/"|FDiv->"//"|Mod->"%"|Add->"+"|Sub->"-"|ShiftL->"<<"|ShiftR->">>"|Eq->"=="|Neq->"!="|Lt->"<"|Gt->">"|Le->"<="|Ge->">="|BitAnd->"&"|BitOr->"|"|BitXor->"^"|And->" and "|Or->" or "|Is->" is "|IsNot->" is not "|In->" in "|NotIn->" not in "letto_stringbo=sprintf"BO(%s)"(to_simple_stringbo)letto_short_string=function|Mul->mkstr0|Div->mkstr1|FDiv->mkstr2|Mod->mkstr3|Add->mkstr4|Sub->mkstr5|ShiftL->mkstr6|ShiftR->mkstr7|Eq->mkstr8|Neq->mkstr9|Lt->mkstr10|Gt->mkstr11|Le->mkstr12|Ge->mkstr13|BitAnd->mkstr14|BitOr->mkstr15|BitXor->mkstr16|And->mkstr17|Or->mkstr18|Is->mkstr19|IsNot->mkstr20|In->mkstr21|NotIn->mkstr22letof_bop=function|Ast.Bmul->Mul|Ast.Bdiv->Div|Ast.Bfdiv->FDiv|Ast.Bmod->Mod|Ast.Badd->Add|Ast.Bsub->Sub|Ast.BshiftL->ShiftL|Ast.BshiftR->ShiftR|Ast.Beq->Eq|Ast.Bneq->Neq|Ast.Blt->Lt|Ast.Bgt->Gt|Ast.Ble->Le|Ast.Bge->Ge|Ast.BbitAnd->BitAnd|Ast.BbitOr->BitOr|Ast.BbitXor->BitXor|Ast.Band->And|Ast.Bor->Or|Ast.Bis->Is|Ast.BisNot->IsNot|Ast.Bin->In|Ast.BnotIn->NotInletto_tagbo=letname=matchbowith|Mul->"Mult"|Div->"Div"|FDiv->"FDiv"|Mod->"Mod"|Add->"Add"|Sub->"Subt"|ShiftL->"ShiftL"|ShiftR->"ShiftR"|Eq->"Eq"|Neq->"NotEq"|Lt->"Le"|Gt->"Gt"|Le->"Le"|Ge->"Ge"|BitAnd->"BitAnd"|BitOr->"BitOr"|BitXor->"BitXor"|And->"And"|Or->"Or"|Is->"Is"|IsNot->"IsNot"|In->"InOp"|NotIn->"NotIn"inname,[]end(* of module BinaryOperator *)moduleStatement=structtypet=|Simple|Ifoftie_id|While|For|Try|With|FuncDefofname|ClassDefofname|Async|AsyncFuncDefofname|ERROR|MARKERofstringletto_string=function|Simple->"Simple"|Iftid->sprintf"If(%s)"(tid_to_stringtid)|While->"While"|For->"For"|Try->"Try"|With->"With"|FuncDefname->"FuncDef:"^name|ClassDefname->"ClassDef:"^name|Async->"Async"|AsyncFuncDefname->"AsyncFuncDef:"^name|ERROR->"ERROR"|MARKERm->"MARKER:"^mletis_named=function|FuncDef_|AsyncFuncDef_|ClassDef_->true|_->falseletget_name=function|FuncDefn|AsyncFuncDefn|ClassDefn->n|_->raiseNot_foundletis_named_orig=function|FuncDef_|AsyncFuncDef_|ClassDef_->true|_->falseletanonymize=function|FuncDef_->FuncDef""|ClassDef_->ClassDef""|AsyncFuncDef_->AsyncFuncDef""|stmt->stmtletto_short_string?(ignore_identifiers_flag=false)=letcombo=combo~ignore_identifiers_flaginfunction|Simple->mkstr0|Iftid->combo1[tid_to_stringtid]|While->mkstr2|For->mkstr3|Try->mkstr4|With->mkstr5|FuncDefname->combo6[name]|ClassDefname->combo7[name]|Async->mkstr8|AsyncFuncDefname->combo9[name]|ERROR->mkstr10|MARKERm->combo11[m]letto_tagstmt=letname,attrs=matchstmtwith|Simple->"SimpleStmt",[]|Iftid->"IfStmt",mktidattrtid|While->"WhileStmt",[]|For->"ForStmt",[]|Try->"TryStmt",[]|With->"WithStmt",[]|FuncDefname->"FuncDef",["name",name]|ClassDefname->"ClassDef",["name",name]|Async->"Async",[]|AsyncFuncDefname->"AsyncFuncDef",["name",name]|ERROR->"ERROR",[]|MARKERm->"MARKER",["line",m]inname,attrsend(* of module Statement *)moduleSimpleStatement=structtypet=|Expr|AssignofAssignmentOperator.t|Print|Del|Pass|Break|Continue|Return|Raise|Yield|Import|FromImport|Global|Exec|Assert|RaiseFrom|Nonlocal|ERRORletto_string=function|Expr->"Expr"|Assignaop->sprintf"Assignment.%s"(AssignmentOperator.to_stringaop)|Print->"Print"|Del->"Del"|Pass->"Pass"|Break->"Break"|Continue->"Continue"|Return->"Return"|Raise->"Raise"|Yield->"Yield"|Import->"Import"|FromImport->"FromImport"|Global->"Global"|Exec->"Exec"|Assert->"Assert"|RaiseFrom->"RaiseFrom"|Nonlocal->"Nonlocal"|ERROR->"ERROR"letto_short_string=function|Expr->mkstr0|Assignaop->catstr[mkstr1;AssignmentOperator.to_short_stringaop]|Print->mkstr2|Del->mkstr3|Pass->mkstr4|Break->mkstr5|Continue->mkstr6|Return->mkstr7|Raise->mkstr8|Yield->mkstr9|Import->mkstr10|FromImport->mkstr11|Global->mkstr12|Exec->mkstr13|Assert->mkstr14|RaiseFrom->mkstr15|Nonlocal->mkstr16|ERROR->mkstr17letanonymize?(more=false)lab=ignoremore;matchlabwith|Assign_->AssignAssignmentOperator.Eq|lab->labletto_tagsstmt=letname,attrs=matchsstmtwith|Expr->"ExprStmt",[]|Assignaop->AssignmentOperator.to_tagaop|Print->"PrintStmt",[]|Del->"DelStmt",[]|Pass->"PassStmt",[]|Break->"BreakStmt",[]|Continue->"ContinueStmt",[]|Return->"ReturnStmt",[]|Raise->"RaiseStmt",[]|Yield->"YieldStmt",[]|Import->"ImportStmt",[]|FromImport->"FromImportStmt",[]|Global->"GlobalStmt",[]|Exec->"ExecStmt",[]|Assert->"AssertStmt",[]|RaiseFrom->"RaiseFromStmt",[]|Nonlocal->"NonlocalStmt",[]|ERROR->"ERROR",[]inname,attrsend(* of module SimpleStatement *)modulePrimary=structtypet=|Nameofname|LiteralofLiteral.t|Paren|Tuple|Yield|Test|List|ListFor|Dict|StringConv|AttrRefofname|Subscription|Slicing|Calloftie_id|Await|Ellipsisletto_string=function|Namename->sprintf"Name:%s"name|Literallit->Literal.to_stringlit|Paren->"Paren"|Tuple->"Tuple"|Yield->"Yield"|Test->"Test"|List->"List"|ListFor->"ListFor"|Dict->"Dict"|StringConv->"StringConv"|AttrRefn->"AttrRef:"^n|Subscription->"Subscription"|Slicing->"Slicing"|Calltid->"Call:"^(tid_to_stringtid)|Await->"Await"|Ellipsis->"Ellipsis"letstrip=function|Call_->Callnull_tid|prim->primletanonymize?(more=false)=function|Name_->Name""|AttrRef_->AttrRef""|Literallit->Literal(Literal.anonymizelit)|Calltid->Call(anonymize_tid~moretid)|prim->primletto_short_string?(ignore_identifiers_flag=false)=letcombo=combo~ignore_identifiers_flaginfunction|Namename->combo0[name]|Literallit->combo1[Literal.to_short_string~ignore_identifiers_flaglit]|Paren->mkstr2|Tuple->mkstr3|Yield->mkstr4|Test->mkstr5|List->mkstr6|ListFor->mkstr7|Dict->mkstr8|StringConv->mkstr9|AttrRefn->combo10[n]|Subscription->mkstr11|Slicing->mkstr12|Calltid->combo13[tid_to_stringtid]|Await->mkstr14|Ellipsis->mkstr15letto_tagprim=letname,attrs=matchprimwith|Namename->"NameAtom",["name",name]|Literallit->Literal.to_taglit|Paren->"ParenAtom",[]|Tuple->"TupleAtom",[]|Yield->"YieldAtom",[]|Test->"TestAtom",[]|List->"ListAtom",[]|ListFor->"ListForAtom",[]|Dict->"DictAtom",[]|StringConv->"StringConvAtom",[]|AttrRefn->"AttrRef",["name",n]|Subscription->"Subscription",[]|Slicing->"Slicing",[]|Calltid->"Call",mktidattrtid|Await->"Await",[]|Ellipsis->"Ellipsis",[]inname,attrsend(* of module Primary *)typeannotation=stringoptionletnull_annotation=Noneletannotation_to_string=function|None->"<none>"|Somex->xtypet=(* Label *)|Dummy|ERROR|Commentofstring|FileInputofname|DottedNameofstring|Nameofname|Lambda|Test|Power|PrimaryofPrimary.t|UnaryOperatorofUnaryOperator.t|BinaryOperatorofBinaryOperator.t|StatementofStatement.t|SimpleStatementofSimpleStatement.t|Elifoftie_id|Else|Targets|Target|Except|Suite|NamedSuiteofname|Parameters|NamedParametersofname|Decoratorsofname|Decoratorofname|Finally|In|Yield|LHS|RHS|As|ListIf|KeyDatum|SliceItem|Ellipsis|Argumentsoftie_id|NamedArgumentsofname|Argument|CompArgument|AssignArgument|GenFor|AsyncGenFor|GenIf|Inheritance|Chevron|From|ParamDefofname|ListParamDef|TypedParamDefofname|WithItem|StarStar|Star|Slash|Named|ReturnAnnotation|Dotsofint|Stride|Annotationletopt_to_stringto_str=function|Somex->to_strx|None->""letname_to_string(_,n)=nletliteral_to_string=function|Ast.Lintegerstr->"Linteger:"^str|Ast.Llongintegerstr->"Llonginteger:"^str|Ast.Lfloatnumberstr->"Lfloatnumber:"^str|Ast.Limagnumberstr->"Linagnumber:"^str|Ast.Lstringpystrs->"Lstring["^(Xlist.to_string(function|Ast.PSlong(_,s)->"PSlong:"^s|Ast.PSshort(_,s)->"PSshort:"^s)";"pystrs)^"]"|Ast.Lnone->"Lnone"|Ast.Ltrue->"Ltrue"|Ast.Lfalse->"Lfalse"letrecprimary_to_stringprim=primary_desc_to_stringprim.Ast.prim_descandprimary_desc_to_string=function|Ast.Pnamename->sprintf"Pname(%s)"(name_to_stringname)|Ast.Pliterallit->sprintf"Pliteral(%s)"(literal_to_stringlit)|Ast.Pexprexpr->sprintf"Pexpr(%s)"(expr_to_stringexpr)|Ast.Pparenexpr->sprintf"Pparen(%s)"(expr_to_stringexpr)|Ast.Ptupleexprs->"Ptuple"^(exprs_to_stringexprs)|Ast.Pyieldexprs->"Pyield"^(exprs_to_stringexprs)|Ast.PcompT(expr,compfor)->sprintf"PcompT(%s,%s)"(expr_to_stringexpr)(compfor_to_stringcompfor)|Ast.PcompL(expr,compfor)->sprintf"PcompL(%s,%s)"(expr_to_stringexpr)(compfor_to_stringcompfor)|Ast.Plistexprs->"Plist"^(exprs_to_stringexprs)|Ast.Plistnull->"Plistnull"|Ast.Pdictorsetdictorsetmaker->"Pdictorset"^(dictorsetmaker_to_stringdictorsetmaker)|Ast.Pdictnull->"Pdictnull"|Ast.Pstrconvexprs->"Pstrconv"^(exprs_to_stringexprs)|Ast.Pattrref(prim,name)->sprintf"Pattrref(%s,%s)"(primary_to_stringprim)(name_to_stringname)|Ast.Psubscript(prim,exprs)->sprintf"Psubscript(%s,%s)"(primary_to_stringprim)(exprs_to_stringexprs)|Ast.Pslice(prim,sliceitems)->sprintf"Pslice(%s,[%s])"(primary_to_stringprim)(Xlist.to_stringsliceitem_to_string";"sliceitems)|Ast.Pcall(prim,arglist)->sprintf"Pcall(%s,%s)"(primary_to_stringprim)(arglist_to_stringarglist)|Ast.Pawaitprim->sprintf"Pawait(%s)"(primary_to_stringprim)|Ast.Pellipsis->sprintf"Ellipsis"andexpr_to_stringexpr=matchexpr.Ast.expr_descwith|Ast.Eprimaryprim->sprintf"Eprimary(%s)"(primary_to_stringprim)|Ast.Epower(prim,expr)->sprintf"Epower(%s,%s)"(primary_to_stringprim)(expr_to_stringexpr)|Ast.Ebop(expr1,bop,expr2)->sprintf"Ebop(%s,%s,%s)"(expr_to_stringexpr1)(bop_to_stringbop)(expr_to_stringexpr2)|Ast.Euop(uop,expr)->sprintf"Euop(%s,%s)"(uop_to_stringuop)(expr_to_stringexpr)|Ast.Elambda(params,expr)->"Elambda("^(matchparamswith|_,[]->""|_->parameters_to_stringparams)^(expr_to_stringexpr)|Ast.Econd(expr1,expr2,expr3)->sprintf"Econd(%s,%s,%s)"(expr_to_stringexpr1)(expr_to_stringexpr2)(expr_to_stringexpr3)|Ast.Estarexpr->sprintf"Estar(%s)"(expr_to_stringexpr)|Ast.Enamed(expr1,expr2)->sprintf"Enamed(%s,%s)"(expr_to_stringexpr1)(expr_to_stringexpr2)|Ast.Efromexpr->sprintf"Efrom(%s)"(expr_to_stringexpr)|Ast.Earg(expr1,expr2)->sprintf"Earg(%s,%s)"(expr_to_stringexpr1)(expr_to_stringexpr2)|Ast.Eerror->"ERROR"andbop_to_string=function|Ast.Bmul->"Bmul"|Ast.Bdiv->"Bdiv"|Ast.Bfdiv->"Bfdiv"|Ast.Bmod->"Bmod"|Ast.Badd->"Badd"|Ast.Bsub->"Bsub"|Ast.BshiftL->"BshiftL"|Ast.BshiftR->"BshiftR"|Ast.Beq->"Beq"|Ast.Bneq->"Bneq"|Ast.Blt->"Blt"|Ast.Bgt->"Bgt"|Ast.Ble->"Ble"|Ast.Bge->"Bge"|Ast.BbitAnd->"BbitAnd"|Ast.BbitOr->"BbitOr"|Ast.BbitXor->"BbitXor"|Ast.Band->"Band"|Ast.Bor->"Bor"|Ast.Bis->"Bis"|Ast.BisNot->"BisNot"|Ast.Bin->"Bin"|Ast.BnotIn->"BnotIn"anduop_to_string=function|Ast.Upositive->"Upositive"|Ast.Unegative->"Unegative"|Ast.Ucomplement->"Ucomplement"|Ast.Unot->"Unot"andparameters_to_string(_,vargs)="("^(vargs_to_stringvargs)^","^")"andvararg_to_string=function|Ast.VAarg(fpdef,expr_opt)->(fpdef_to_stringfpdef)^","^(opt_to_stringexpr_to_stringexpr_opt)|Ast.VAargs(_,None,expr_opt)->"*"^","^(opt_to_stringexpr_to_stringexpr_opt)|Ast.VAargs(_,Somen,expr_opt)->"*"^(name_to_stringn)^","^(opt_to_stringexpr_to_stringexpr_opt)|Ast.VAkwargs(_,n,expr_opt)->"**"^(name_to_stringn)^","^(opt_to_stringexpr_to_stringexpr_opt)|Ast.VAsep_->"/"andvargs_to_stringvargs="["^(Xlist.to_stringvararg_to_string";"vargs)^"]"andfpdef_to_string=function|Ast.Fnamen->sprintf"Fname(%s)"(name_to_stringn)|Ast.Ftyped(_,name,expr)->sprintf"Ftyped(%s,%s)"(name_to_stringname)(expr_to_stringexpr)|Ast.Flist(_,fpdefs)->sprintf"Flist[%s]"(Xlist.to_stringfpdef_to_string";"fpdefs)andexprs_to_stringexprs=sprintf"[%s]"(Xlist.to_stringexpr_to_string";"exprs)andcompfor_to_string(_,(exprs,expr,compiter_opt),async)=(ifasyncthen"async "else"")^"for "^(exprs_to_stringexprs)^" in "^(expr_to_stringexpr)^" "^(opt_to_stringcompiter_to_stringcompiter_opt)andcompiter_to_string=function|Ast.Cforgf->"Cfor("^(compfor_to_stringgf)^")"|Ast.Cifgi->"Cif("^(compif_to_stringgi)^")"andcompif_to_string(_,expr,compiter_opt)="("^(expr_to_stringexpr)^","^(opt_to_stringcompiter_to_stringcompiter_opt)^")"andlistfor_to_string(_,exprs1,exprs2,listiter_opt)="("^(exprs_to_stringexprs1)^","^(exprs_to_stringexprs2)^","^(opt_to_stringlistiter_to_stringlistiter_opt)^")"andlistiter_to_string=function|Ast.LIforlf->"LIfor("^(listfor_to_stringlf)^")"|Ast.LIifli->"LIif("^(listif_to_stringli)^")"andlistif_to_string(_,expr,listiter_opt)="("^(expr_to_stringexpr)^","^(opt_to_stringlistiter_to_stringlistiter_opt)^")"anddictelem_to_stringdelem=matchdelem.Ast.delem_descwith|DEkeyValue(e1,e2)->(expr_to_stringe1)^":"^(expr_to_stringe2)|DEstarStare->"**"^(expr_to_stringe)anddictorsetmaker_to_stringdictorsetmaker=lets=matchdictorsetmakerwith|Ast.DSMdictkey_dats->Xlist.to_stringdictelem_to_string","key_dats|Ast.DSMdictC(delem,compfor)->(dictelem_to_stringdelem)^" "^(compfor_to_stringcompfor)|Ast.DSMsetes->Xlist.to_stringexpr_to_string","es|Ast.DSMsetC(e,compfor)->(expr_to_stringe)^" "^(compfor_to_stringcompfor)in"{"^s^"}"andsliceitem_to_string=function|Ast.SIexprexpr->"SIexpr("^(expr_to_stringexpr)^")"|Ast.SI2(_,expr_opt1,expr_opt2)->"SI2("^(opt_to_stringexpr_to_stringexpr_opt1)^","^(opt_to_stringexpr_to_stringexpr_opt2)^")"|Ast.SI3(_,expr_opt1,expr_opt2,expr_opt3)->"SI3("^(opt_to_stringexpr_to_stringexpr_opt1)^","^(opt_to_stringexpr_to_stringexpr_opt2)^","^(opt_to_stringexpr_to_stringexpr_opt3)^")"(*| Ast.SIellipsis _ -> "SIellipsis"*)andarglist_to_string(_,args)=sprintf"(%s)"(Xlist.to_stringargument_to_string","args)andargument_to_string=function|Aarg(_,expr,expr_opt)->begin(expr_to_stringexpr)^(matchexpr_optwith|Somee->"="^(expr_to_stringe)|_->"")end|Acomp(_,expr,compfor)->(expr_to_stringexpr)^" "^(compfor_to_stringcompfor)|Aassign(_,expr1,expr2)->(expr_to_stringexpr1)^":="^(expr_to_stringexpr2)|Aargs(_,expr)->"*"^(expr_to_stringexpr)|Akwargs(_,expr)->"**"^(expr_to_stringexpr)lettid_of_exprexpr=mktid(Digest.to_hex(Digest.string(expr_to_stringexpr)))""let_of_statement=function|Ast.Ssimple_->Statement.Simple|Ast.Sif(e,_,_,_)->beginlettid=tid_of_expreinStatement.Iftidend|Ast.Swhile_->Statement.While|Ast.Sfor_->Statement.For|Ast.Stry_->Statement.Try|Ast.Stryfin_->Statement.Try|Ast.Swith_->Statement.With|Ast.Sasync_->Statement.Async|Ast.Sasync_funcdef(_,name,_,_,_)->Statement.AsyncFuncDef(conv_namename)|Ast.Sfuncdef(_,name,_,_,_)->Statement.FuncDef(conv_namename)|Ast.Sclassdef(_,name,_,_)->Statement.ClassDef(conv_namename)|Ast.Smatch_->failwith"not yet"|Ast.Serror->Statement.ERROR|Ast.Smarkerm->Statement.MARKERmletof_statementstmt=Statement(_of_statementstmt)lettid_of_importname_as_names=letdottedname_as_names_to_stringdname_as_names=letf=function|(dn,Somen)->(dottedname_to_stringdn)^" as "^(conv_namen)|(dn,None)->dottedname_to_stringdninString.concat","(List.mapfdname_as_names)inlets=dottedname_as_names_to_stringname_as_namesinmktid(Digest.to_hex(Digest.strings))""lettid_of_from_import(dots_opt,dname_opt,name_as_names)=letname_as_names_to_stringname_as_names=letf=function|(n,Somen0)->(conv_namen)^" as "^(conv_namen0)|(n,None)->conv_nameninmatchname_as_nameswith|[]->"*"|_->String.concat","(List.mapfname_as_names)inlets=(matchdots_optwith|Some(_,ndots)->String.makendots'.'|_->"")^(matchdname_optwith|Somedname->dottedname_to_stringdname|_->"")^" import "^(name_as_names_to_stringname_as_names)inmktid(Digest.to_hex(Digest.strings))""letof_simplestmtsstmt=SimpleStatement(matchsstmtwith|Ast.SSexpr_->SimpleStatement.Expr|Ast.SSassign_->SimpleStatement.AssignAssignmentOperator.Eq|Ast.SSaugassign(_,aop,_)->SimpleStatement.Assign(AssignmentOperator.of_aopaop)|Ast.SSannassign_->SimpleStatement.AssignAssignmentOperator.Eq|Ast.SSprint_->SimpleStatement.Print|Ast.SSprintchevron_->SimpleStatement.Print|Ast.SSdel_->SimpleStatement.Del|Ast.SSpass->SimpleStatement.Pass|Ast.SSbreak->SimpleStatement.Break|Ast.SScontinue->SimpleStatement.Continue|Ast.SSreturn_->SimpleStatement.Return|Ast.SSraise->SimpleStatement.Raise|Ast.SSraise1_->SimpleStatement.Raise|Ast.SSraise2_->SimpleStatement.Raise|Ast.SSraise3_->SimpleStatement.Raise|Ast.SSyield_->SimpleStatement.Yield|Ast.SSimport_->SimpleStatement.Import|Ast.SSfrom_->SimpleStatement.FromImport|Ast.SSglobal_->SimpleStatement.Global|Ast.SSexec_->SimpleStatement.Exec|Ast.SSexec2_->SimpleStatement.Exec|Ast.SSexec3_->SimpleStatement.Exec|Ast.SSassert_->SimpleStatement.Assert|Ast.SSassert2_->SimpleStatement.Assert|Ast.SSraisefrom_->SimpleStatement.RaiseFrom|Ast.SSnonlocal_->SimpleStatement.Nonlocal|Ast.SSerror->SimpleStatement.ERROR)letof_bopbop=BinaryOperator(BinaryOperator.of_bopbop)letof_uopuop=UnaryOperator(UnaryOperator.of_uopuop)lettid_of_primaryprim=mktid(Digest.to_hex(Digest.string(primary_to_stringprim)))""let_of_primary=function|Ast.Pnamename->Primary.Name(conv_namename)|Ast.Pliterallit->Primary.Literal(Literal.of_literallit)|Ast.Pexpr_->Primary.Paren(* dummy *)|Ast.Pparen_->Primary.Paren|Ast.Ptuple_->Primary.Tuple|Ast.Pyield_->Primary.Yield|Ast.PcompT_->Primary.Test|Ast.PcompL_->Primary.ListFor|Ast.Plist_->Primary.List|Ast.Plistnull->Primary.List|Ast.Pdictorset_->Primary.Dict|Ast.Pdictnull->Primary.Dict|Ast.Pstrconv_->Primary.StringConv|Ast.Pattrref(_,(_,n))->Primary.AttrRefn|Ast.Psubscript_->Primary.Subscription|Ast.Pslice_->Primary.Slicing|Ast.Pcall(prim,_)->Primary.Call(tid_of_primaryprim)|Ast.Pawait_->Primary.Await|Ast.Pellipsis->Primary.Ellipsisletof_primaryp=Primary(_of_primaryp)letto_string=function|Dummy->"Dummy"|ERROR->"ERROR"|Primaryp->Primary.to_stringp|UnaryOperatoruo->UnaryOperator.to_stringuo|BinaryOperatorbo->BinaryOperator.to_stringbo|Statementstmt->Statement.to_stringstmt|SimpleStatementsstmt->SimpleStatement.to_stringsstmt|FileInputn->sprintf"FileInput:%s"n|DottedNames->sprintf"DottedName:%s"s|Namen->sprintf"Name:%s"n|Lambda->"Lambda"|Test->"Test"|Power->"Power"|Eliftid->sprintf"Elif(%s)"(tid_to_stringtid)|Else->"Else"|Targets->"Targets"|Target->"Target"|Except->"Except"|Suite->"Suite"|NamedSuiten->sprintf"Suite:%s"n|Parameters->"Parameters"|NamedParametersn->sprintf"Parameters:%s"n|Decoratorsn->sprintf"Decorators:%s"n|Decoratorn->sprintf"Decorator:%s"n|Finally->"Finally"|In->"In"|Yield->"Yield"|LHS->"LHS"|RHS->"RHS"|As->"As"|ListIf->"ListIf"|KeyDatum->"KeyDatum"|SliceItem->"SliceItem"|Ellipsis->"Ellipsis"|Argumentstid->sprintf"Arguments:%s"(tid_to_stringtid)|NamedArgumentsn->sprintf"NamedArguments:%s"n|Argument->"Argument"|CompArgument->"CompArgument"|AssignArgument->"AssignArgument"|GenFor->"GenFor"|AsyncGenFor->"AsyncGenFor"|GenIf->"GenIf"|Inheritance->"Inheritance"|Chevron->"Chevron"|From->"From"|ParamDefn->sprintf"ParamDef:%s"n|ListParamDef->"ListParamDef"|TypedParamDefn->sprintf"TypedParamDef:%s"n|WithItem->"WithItem"|StarStar->"StarStar"|Star->"Star"|Slash->"Slash"|Named->"Named"|ReturnAnnotation->"ReturnAnnotation"|Dotsi->sprintf"Dots:%d"i|Stride->"Stride"|Commentc->sprintf"Comment(%s)"c|Annotation->"Annotation"letstrip=function|Primaryp->Primary(Primary.stripp)|Arguments_->Argumentsnull_tid|Dots_->Dots0|lab->labletanonymize?(more=false)=function|CompArgument|AssignArgument|AsyncGenForwhenmore->GenFor|Primaryp->Primary(Primary.anonymize~morep)|Statementstmt->Statement(Statement.anonymizestmt)|SimpleStatementsstmt->SimpleStatement(SimpleStatement.anonymize~moresstmt)|FileInput_->FileInput""|Name_->Name""|DottedName_whenmore->Name""|DottedName_->DottedName""|NamedSuite_->NamedSuite""|NamedParameters_->NamedParameters""|Argumentstid->Arguments(anonymize_tid~moretid)|NamedArguments_->NamedArguments""|Decorator_->Decorator""|Decorators_->Decorators""|Dots_->Dots0|Comment_->Comment""|ParamDef_->ParamDef""|TypedParamDef_->TypedParamDef""|lab->labletanonymize2=anonymize~more:trueletanonymize3=anonymize~more:trueletto_simple_string=to_string(* to be implemented *)letto_short_string?(ignore_identifiers_flag=false)=letcombo=combo~ignore_identifiers_flaginfunction|Dummy->mkstr0|Primaryp->catstr[mkstr1;Primary.to_short_string~ignore_identifiers_flagp]|UnaryOperatoruo->catstr[mkstr2;UnaryOperator.to_short_stringuo]|BinaryOperatorbo->catstr[mkstr3;BinaryOperator.to_short_stringbo]|Statementstmt->catstr[mkstr4;Statement.to_short_string~ignore_identifiers_flagstmt]|SimpleStatementsstmt->catstr[mkstr5;SimpleStatement.to_short_stringsstmt]|FileInputn->combo6[n]|DottedNames->combo7[s]|Namen->combo8[n]|Lambda->mkstr9|Test->mkstr10|Power->mkstr11|Eliftid->combo12[tid_to_stringtid]|Else->mkstr13|Targets->mkstr14|Target->mkstr15|Except->mkstr16|Suite->mkstr17|NamedSuiten->combo18[n]|Parameters->mkstr19|NamedParametersn->combo20[n]|Decoratorsn->combo21[n]|Decoratorn->combo22[n]|Finally->mkstr23|In->mkstr24|LHS->mkstr25|RHS->mkstr26|As->mkstr27|ListIf->mkstr29|KeyDatum->mkstr32|SliceItem->mkstr33|Ellipsis->mkstr37|Argumentstid->combo38[tid_to_stringtid]|NamedArgumentsn->combo39[n]|Argument->mkstr40|GenFor->mkstr41|GenIf->mkstr42|Inheritance->mkstr43|Chevron->mkstr44|From->mkstr45|ParamDefn->combo48[n]|ListParamDef->mkstr49|WithItem->mkstr52|StarStar->mkstr53|Star->mkstr54|Slash->mkstr55|Named->mkstr56|ReturnAnnotation->mkstr57|TypedParamDefn->combo58[n]|Dotsi->combo59[string_of_inti]|CompArgument->mkstr60|AssignArgument->mkstr61|AsyncGenFor->mkstr62|Yield->mkstr63|Stride->mkstr64|ERROR->mkstr65|Commentc->combo66[c]|Annotation->mkstr67letto_tag?(strip=false)l=ignorestrip;letname,attrs=matchlwith|Dummy->"Dummy",[]|ERROR->"ERROR",[]|Primaryp->Primary.to_tagp|UnaryOperatoruo->UnaryOperator.to_taguo|BinaryOperatorbo->BinaryOperator.to_tagbo|Statementstmt->Statement.to_tagstmt|SimpleStatementsstmt->SimpleStatement.to_tagsstmt|DottedNames->"DottedName",["name",s]|Namen->"name",["name",n]|Lambda->"Lambda",[]|Test->"Test",[]|Power->"Power",[]|Eliftid->"Elif",mktidattrtid|Else->"Else",[]|Targets->"Targets",[]|Target->"Target",[]|Except->"Except",[]|Suite->"Suite",[]|NamedSuiten->"NamedSuite",["name",n]|Parameters->"Parameters",[]|NamedParametersn->"NamedParameters",["name",n]|Decoratorsn->"Decorators",["name",n]|Decoratorn->"Decorator",["name",n]|Finally->"Finally",[]|In->"In",[]|Yield->"Yield",[]|LHS->"Lhs",[]|RHS->"Rhs",[]|As->"As",[]|ListIf->"ListIf",[]|KeyDatum->"KeyDatum",[]|SliceItem->"SliceItem",[]|Ellipsis->"Ellipsis",[]|Argumentstid->"Arguments",mktidattrtid|NamedArgumentsn->"NamedArguments",["name",n]|Argument->"Argument",[]|CompArgument->"CompArgument",[]|AssignArgument->"AssignArgument",[]|GenFor->"GenFor",[]|AsyncGenFor->"AsyncGenFor",[]|GenIf->"GenIf",[]|Inheritance->"Inheritance",[]|Chevron->"Chevron",[]|From->"From",[]|ParamDefn->"ParamDef",["name",n]|ListParamDef->"ListParamDef",[]|TypedParamDefn->"TypedParamDef",["name",n]|WithItem->"WithItem",[]|StarStar->"StarStar",[]|Star->"Star",[]|Slash->"Slash",[]|Named->"Named",[]|ReturnAnnotation->"ReturnAnnotation",[]|Dotsi->"Dots",["ndots",string_of_inti]|Stride->"Stride",[]|FileInputn->"FileInput",["name",n]|Commentc->"Comment",["comment",c]|Annotation->"Annotation",[]inname,attrsletto_char(*lab*)_='0'(* to be implemented *)letto_elem_data=Astml.to_elem_datalang_prefixto_tagletis_common_name=letcommon_name_list=["True";"False";"None";"self";"abs";"all";"any";"bin";"bool";"bytearray";"callable";"chr";"classmethod";"compile";"complex";"delattr";"dict";"dir";"divmod";"enumerate";"eval";"filter";"float";"format";"frozenset";"getattr";"globals";"hasattr";"hash";"help";"hex";"id";"input";"int";"isinstance";"issubclass";"iter";"len";"list";"locals";"map";"max";"memoryview";"min";"next";"object";"oct";"open";"ord";"pow";"property";"range";"repr";"reversed";"round";"set";"setattr";"slice";"sorted";"staticmethod";"str";"sum";"super";"tuple";"type";"vars";"zip";"__import__";"NotImplemented";"Ellipsis";"__debug__";]inlets=Xset.create(List.lengthcommon_name_list)inlet_=List.iter(Xset.adds)common_name_listinXset.memsletis_named=function|FileInput_|Name_|DottedName_|NamedSuite_|NamedParameters_|NamedArguments_|Decorator_|Decorators_|ParamDef_|TypedParamDef_|Primary(Primary.Name_|Primary.AttrRef_)->true(*| Primary (Primary.Literal (Literal.String s|Literal.CatString s)) when s <> "" -> true*)|Statementstmt->Statement.is_namedstmt|Comment_->true|_->falseletis_named_orig=function|FileInput_|Name_(*| DottedName _*)|Decorator_|Primary(Primary.Name_)->true(*| Primary (Primary.Literal (Literal.String s|Literal.CatString s)) when s <> "" -> true*)|Statementstmt->Statement.is_named_origstmt|Comment_->true|_->falseletis_compatible?(weak=false)__=ignoreweak;falseletis_order_insensitive=function|_->falseletquasi_eq__=falseletrelabel_allowed=function(* FIXME: should be tuned! *)|Primary_,SimpleStatement_|SimpleStatement_,Primary_|UnaryOperator_,Primary_|Primary_,UnaryOperator_|BinaryOperator_,Primary_|Primary_,BinaryOperator_|Statement(Statement.If_),Elif_|Elif_,(StatementStatement.If_)|Statement(Statement.If_),Else|Else,Statement(Statement.If_)|Elif_,Else|Else,Elif_->true|l1,l2->anonymize2l1=anonymize2l2letmove_disallowed=function|Primary(Primary.Namen)|Namenwhenis_common_namen->true|_->falseletis_common=function|Namenwhenis_common_namen->true|Else|_->falseletis_hunk_boundary__=false(* not yet *)(* These labels are collapsible whether they are leaves or not. *)letforced_to_be_collapsible(*lab*)_=falseletis_collapse_targetoptionslab=letres=ifoptions#no_collapse_flagthenfalseelsematchlabwith|Statement_|SimpleStatement_|Primary_|Inheritance|Parameters|NamedParameters_|Arguments_|NamedArguments_|Lambda|Suite|NamedSuite_|ParamDef_|TypedParamDef_|Argument|CompArgument|AssignArgument|Star|StarStar|LHS|Annotation|RHS->true|_->falsein(* [%debug_log "%s -> %B" (to_string lab) res]; *)resletis_to_be_notified=function|Statement(Statement.FuncDef_|Statement.ClassDef_)->true|_->falseletis_boundary=function|FileInput""|Statement(Statement.FuncDef_|Statement.AsyncFuncDef_|Statement.ClassDef_)->true|_->falseletis_partition=function|Statement_|SimpleStatement_->true|_->falseletis_sequence=function|FileInput_|Suite|NamedSuite_->true|_->falseletis_ntuple=function|Parameters|NamedParameters_|Arguments_|NamedArguments_->true|_->falseletis_comment=function|Comment_->true|_->falseletget_ident_use=function|Namen->n|Primary(Primary.Namen)->n|_->""letis_string_literal=function|Primary(Primary.LiteralLiteral.String_)->true|_->falseletis_int_literal=function|Primary(Primary.Literal(Literal.Integer_|Literal.LongInteger_))->true|_->falseletis_real_literal=function|Primary(Primary.Literal(Literal.FloatNumber_))->true|_->falseletis_statement=function|Statement_|SimpleStatement_->true|_->falseletis_block=function|_->falseletis_op=function|UnaryOperator_|BinaryOperator_->true|_->falseletis_assign=function|SimpleStatement(SimpleStatement.Assign_)->true|_->falseletis_param=function|ParamDef_|TypedParamDef_->true|_->falseletis_attrref=function|Primary(Primary.AttrRef_)->true|_->falselet_is_name=function|Name_->true|_->falseletis_name=function|Name_|Primary(Primary.Name_)->true|_->falseletis_primary=function|Primary_->true|_->falseletis_primaryname=function|Primary(Primary.Name_)->true|_->falseletis_scope_creating=function(* not yet *)|FileInput_|Suite|NamedSuite_->true|_->false(* for fact extraction *)letget_categorylab=letname,_=to_taglabinnameletget_name?(strip=false)lab=ignorestrip;matchlabwith|FileInputn|Namen|DottedNamen|NamedSuiten|NamedParametersn|NamedArgumentsn|Decoratorn|Decoratorsn|ParamDefn|TypedParamDefn|Primary(Primary.Namen|Primary.AttrRefn)->n|Statementstmt->Statement.get_namestmt|Commentc->c|_->raiseNot_foundletget_value=function|Primary(Primary.Literallit)->Literal.to_simple_stringlit|_->raiseNot_foundlethas_value=function|Primary(Primary.Literal_)->true|_->falselethas_non_trivial_valuelab=tryletv=get_valuelabinv<>"0"&&v<>"1"&&v<>"True"&&v<>"False"&&v<>"None"withNot_found->falselethas_non_trivial_tid(*lab*)_=false(* not yet *)letcannot_be_keyroot(*nd*)_=falseletis_phantom=function|Decorators_|Targets|Parameters|NamedParameters_|Arguments_|NamedArguments_->true|_->falseletis_special_=falseopenAstml.Attrletof_elem_data=letmkprimx=Primaryxinletmklitx=Primary(Primary.Literalx)inletmksstmtx=SimpleStatementxinletmkaopx=SimpleStatement(SimpleStatement.Assignx)inletmkstmtx=Statementxinletmkbopx=BinaryOperatorxinletmkuopx=UnaryOperatorxinlettag_list=["Dummy",(fun_->Dummy);"NameAtom",(funa->Name(find_namea));"IntegerLiteral",(funa->mklit(Literal.Integer(find_valuea)));"LongIntegerLiteral",(funa->mklit(Literal.LongInteger(find_valuea)));"FloatNumberLiteral",(funa->mklit(Literal.FloatNumber(find_valuea)));"ImagNumberLiteral",(funa->mklit(Literal.ImagNumber(find_valuea)));"StringLiteral",(funa->mklit(Literal.String(find_valuea)));"CatStringLiteral",(funa->mklit(Literal.CatString(find_valuea)));"ParenAtom",(fun_->mkprim(Primary.Paren));"TupleAtom",(fun_->mkprim(Primary.Tuple));"YieldAtom",(fun_->mkprim(Primary.Yield));"TestAtom",(fun_->mkprim(Primary.Test));"ListAtom",(fun_->mkprim(Primary.List));"ListForAtom",(fun_->mkprim(Primary.ListFor));"DictAtom",(fun_->mkprim(Primary.Dict));"StringConvAtom",(fun_->mkprim(Primary.StringConv));"AttrRef",(funa->mkprim(Primary.AttrRef(find_namea)));"Subscription",(fun_->mkprim(Primary.Subscription));"Slicing",(fun_->mkprim(Primary.Slicing));"Call",(funa->mkprim(Primary.Call(find_tida)));"Await",(fun_->mkprim(Primary.Await));"ExprStmt",(fun_->mksstmt(SimpleStatement.Expr));"Assign",(fun_->mkaop(AssignmentOperator.Eq));"AddAssign",(fun_->mkaop(AssignmentOperator.AddEq));"SubtAssign",(fun_->mkaop(AssignmentOperator.SubEq));"MultAssign",(fun_->mkaop(AssignmentOperator.MulEq));"DivAssign",(fun_->mkaop(AssignmentOperator.DivEq));"ModAssign",(fun_->mkaop(AssignmentOperator.ModEq));"AndAssign",(fun_->mkaop(AssignmentOperator.AndEq));"OrAssign",(fun_->mkaop(AssignmentOperator.OrEq));"XorAssign",(fun_->mkaop(AssignmentOperator.XorEq));"ShiftLAssign",(fun_->mkaop(AssignmentOperator.ShiftLEq));"ShiftRAssign",(fun_->mkaop(AssignmentOperator.ShiftREq));"PowAssign",(fun_->mkaop(AssignmentOperator.PowEq));"FDivAssign",(fun_->mkaop(AssignmentOperator.FDivEq));"PrintStmt",(fun_->mksstmt(SimpleStatement.Print));"DelStmt",(fun_->mksstmt(SimpleStatement.Del));"PassStmt",(fun_->mksstmt(SimpleStatement.Pass));"BreakStmt",(fun_->mksstmt(SimpleStatement.Break));"ContinueStmt",(fun_->mksstmt(SimpleStatement.Continue));"ReturnStmt",(fun_->mksstmt(SimpleStatement.Return));"RaiseStmt",(fun_->mksstmt(SimpleStatement.Raise));"YieldStmt",(fun_->mksstmt(SimpleStatement.Yield));"ImportStmt",(fun_->mksstmt(SimpleStatement.Import));"FromImportStmt",(fun_->mksstmt(SimpleStatement.FromImport));"GlobalStmt",(fun_->mksstmt(SimpleStatement.Global));"ExecStmt",(fun_->mksstmt(SimpleStatement.Exec));"AssertStmt",(fun_->mksstmt(SimpleStatement.Assert));"RaiseFromStmt",(fun_->mksstmt(SimpleStatement.RaiseFrom));"NonlocalStmt",(fun_->mksstmt(SimpleStatement.Nonlocal));"SimpleStmt",(fun_->mkstmt(Statement.Simple));"IfStmt",(funa->mkstmt(Statement.If(find_tida)));"WhileStmt",(fun_->mkstmt(Statement.While));"ForStmt",(fun_->mkstmt(Statement.For));"TryStmt",(fun_->mkstmt(Statement.Try));"WithStmt",(fun_->mkstmt(Statement.With));"FuncDef",(funa->mkstmt(Statement.FuncDef(find_namea)));"AsyncFuncDef",(funa->mkstmt(Statement.AsyncFuncDef(find_namea)));"ClassDef",(funa->mkstmt(Statement.ClassDef(find_namea)));"Async",(fun_->mkstmt(Statement.Async));"Mult",(fun_->mkbop(BinaryOperator.Mul));"Div",(fun_->mkbop(BinaryOperator.Div));"FDiv",(fun_->mkbop(BinaryOperator.FDiv));"Mod",(fun_->mkbop(BinaryOperator.Mod));"Add",(fun_->mkbop(BinaryOperator.Add));"Subt",(fun_->mkbop(BinaryOperator.Sub));"ShiftL",(fun_->mkbop(BinaryOperator.ShiftL));"ShiftR",(fun_->mkbop(BinaryOperator.ShiftR));"Eq",(fun_->mkbop(BinaryOperator.Eq));"NotEq",(fun_->mkbop(BinaryOperator.Neq));"Le",(fun_->mkbop(BinaryOperator.Lt));"Gt",(fun_->mkbop(BinaryOperator.Gt));"Le",(fun_->mkbop(BinaryOperator.Le));"Ge",(fun_->mkbop(BinaryOperator.Ge));"BitAnd",(fun_->mkbop(BinaryOperator.BitAnd));"BitOr",(fun_->mkbop(BinaryOperator.BitOr));"BitXor",(fun_->mkbop(BinaryOperator.BitXor));"And",(fun_->mkbop(BinaryOperator.And));"Or",(fun_->mkbop(BinaryOperator.Or));"Is",(fun_->mkbop(BinaryOperator.Is));"IsNot",(fun_->mkbop(BinaryOperator.IsNot));"InOp",(fun_->mkbop(BinaryOperator.In));"NotIn",(fun_->mkbop(BinaryOperator.NotIn));"Positive",(fun_->mkuop(UnaryOperator.Positive));"Negative",(fun_->mkuop(UnaryOperator.Negative));"Complement",(fun_->mkuop(UnaryOperator.Complement));"Not",(fun_->mkuop(UnaryOperator.Not));"DottedName",(funa->DottedName(find_namea));"name",(funa->Name(find_namea));"Lambda",(fun_->Lambda);"Test",(fun_->Test);"Power",(fun_->Power);"Elif",(funa->Elif(find_tida));"Else",(fun_->Else);"Targets",(fun_->Targets);"Target",(fun_->Target);"Except",(fun_->Except);"Suite",(fun_->Suite);"NamedSuite",(funa->NamedSuite(find_namea));"Parameters",(fun_->Parameters);"NamedParameters",(funa->NamedParameters(find_namea));"Decorators",(funa->Decorators(find_namea));"Decorator",(funa->Decorator(find_namea));"Finally",(fun_->Finally);"In",(fun_->In);"Yield",(fun_->Yield);"Lhs",(fun_->LHS);"Rhs",(fun_->RHS);"As",(fun_->As);"ListIf",(fun_->ListIf);"KeyDatum",(fun_->KeyDatum);"SliceItem",(fun_->SliceItem);"Ellipsis",(fun_->Ellipsis);"Arguments",(funa->Arguments(find_tida));"NamedArguments",(funa->NamedArguments(find_namea));"Argument",(fun_->Argument);"CompArgument",(fun_->CompArgument);"AssignArgument",(fun_->AssignArgument);"GenFor",(fun_->GenFor);"AsyncGenFor",(fun_->AsyncGenFor);"GenIf",(fun_->GenIf);"Inheritance",(fun_->Inheritance);"Chevron",(fun_->Chevron);"From",(fun_->From);"ParamDef",(funa->ParamDef(find_namea));"ListParamDef",(fun_->ListParamDef);"TypedParamDef",(funa->TypedParamDef(find_namea));"WithItem",(fun_->WithItem);"StarStar",(fun_->StarStar);"Star",(fun_->Star);"Slash",(fun_->Slash);"Named",(fun_->Named);"ReturnAnnotation",(fun_->ReturnAnnotation);"Dots",(funa->Dots(find_inta"ndots"));"Stride",(fun_->Stride);"FileInput",(funa->FileInput(find_namea));"Comment",(funa->Comment(find_attra"comment"));"Annotation",(fun_->Annotation);]inlettbl=Hashtbl.create(List.lengthtag_list)inlet_=List.iter(fun(tname,lab)->Hashtbl.addtbltnamelab)tag_listinletof_elemnameattrs(_:string)=try(Hashtbl.findtblname)attrswith|Not_found->failwith("Py_label.of_tag: tag not found: "^name)|e->failwith("Py_label.of_tag: "^(Printexc.to_stringe))inof_elem