Python-ast.c 442 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224
  1. // File automatically generated by Parser/asdl_c.py.
  2. #include "Python.h"
  3. #include "pycore_ast.h"
  4. #include "pycore_ast_state.h" // struct ast_state
  5. #include "pycore_ceval.h" // _Py_EnterRecursiveCall
  6. #include "pycore_interp.h" // _PyInterpreterState.ast
  7. #include "pycore_pystate.h" // _PyInterpreterState_GET()
  8. #include "structmember.h"
  9. #include <stddef.h>
  10. struct validator {
  11. int recursion_depth; /* current recursion depth */
  12. int recursion_limit; /* recursion limit */
  13. };
  14. // Forward declaration
  15. static int init_types(struct ast_state *state);
  16. static struct ast_state*
  17. get_ast_state(void)
  18. {
  19. PyInterpreterState *interp = _PyInterpreterState_GET();
  20. struct ast_state *state = &interp->ast;
  21. if (!init_types(state)) {
  22. return NULL;
  23. }
  24. return state;
  25. }
  26. void _PyAST_Fini(PyInterpreterState *interp)
  27. {
  28. struct ast_state *state = &interp->ast;
  29. Py_CLEAR(state->AST_type);
  30. Py_CLEAR(state->Add_singleton);
  31. Py_CLEAR(state->Add_type);
  32. Py_CLEAR(state->And_singleton);
  33. Py_CLEAR(state->And_type);
  34. Py_CLEAR(state->AnnAssign_type);
  35. Py_CLEAR(state->Assert_type);
  36. Py_CLEAR(state->Assign_type);
  37. Py_CLEAR(state->AsyncFor_type);
  38. Py_CLEAR(state->AsyncFunctionDef_type);
  39. Py_CLEAR(state->AsyncWith_type);
  40. Py_CLEAR(state->Attribute_type);
  41. Py_CLEAR(state->AugAssign_type);
  42. Py_CLEAR(state->Await_type);
  43. Py_CLEAR(state->BinOp_type);
  44. Py_CLEAR(state->BitAnd_singleton);
  45. Py_CLEAR(state->BitAnd_type);
  46. Py_CLEAR(state->BitOr_singleton);
  47. Py_CLEAR(state->BitOr_type);
  48. Py_CLEAR(state->BitXor_singleton);
  49. Py_CLEAR(state->BitXor_type);
  50. Py_CLEAR(state->BoolOp_type);
  51. Py_CLEAR(state->Break_type);
  52. Py_CLEAR(state->Call_type);
  53. Py_CLEAR(state->ClassDef_type);
  54. Py_CLEAR(state->Compare_type);
  55. Py_CLEAR(state->Constant_type);
  56. Py_CLEAR(state->Continue_type);
  57. Py_CLEAR(state->Del_singleton);
  58. Py_CLEAR(state->Del_type);
  59. Py_CLEAR(state->Delete_type);
  60. Py_CLEAR(state->DictComp_type);
  61. Py_CLEAR(state->Dict_type);
  62. Py_CLEAR(state->Div_singleton);
  63. Py_CLEAR(state->Div_type);
  64. Py_CLEAR(state->Eq_singleton);
  65. Py_CLEAR(state->Eq_type);
  66. Py_CLEAR(state->ExceptHandler_type);
  67. Py_CLEAR(state->Expr_type);
  68. Py_CLEAR(state->Expression_type);
  69. Py_CLEAR(state->FloorDiv_singleton);
  70. Py_CLEAR(state->FloorDiv_type);
  71. Py_CLEAR(state->For_type);
  72. Py_CLEAR(state->FormattedValue_type);
  73. Py_CLEAR(state->FunctionDef_type);
  74. Py_CLEAR(state->FunctionType_type);
  75. Py_CLEAR(state->GeneratorExp_type);
  76. Py_CLEAR(state->Global_type);
  77. Py_CLEAR(state->GtE_singleton);
  78. Py_CLEAR(state->GtE_type);
  79. Py_CLEAR(state->Gt_singleton);
  80. Py_CLEAR(state->Gt_type);
  81. Py_CLEAR(state->IfExp_type);
  82. Py_CLEAR(state->If_type);
  83. Py_CLEAR(state->ImportFrom_type);
  84. Py_CLEAR(state->Import_type);
  85. Py_CLEAR(state->In_singleton);
  86. Py_CLEAR(state->In_type);
  87. Py_CLEAR(state->Interactive_type);
  88. Py_CLEAR(state->Invert_singleton);
  89. Py_CLEAR(state->Invert_type);
  90. Py_CLEAR(state->IsNot_singleton);
  91. Py_CLEAR(state->IsNot_type);
  92. Py_CLEAR(state->Is_singleton);
  93. Py_CLEAR(state->Is_type);
  94. Py_CLEAR(state->JoinedStr_type);
  95. Py_CLEAR(state->LShift_singleton);
  96. Py_CLEAR(state->LShift_type);
  97. Py_CLEAR(state->Lambda_type);
  98. Py_CLEAR(state->ListComp_type);
  99. Py_CLEAR(state->List_type);
  100. Py_CLEAR(state->Load_singleton);
  101. Py_CLEAR(state->Load_type);
  102. Py_CLEAR(state->LtE_singleton);
  103. Py_CLEAR(state->LtE_type);
  104. Py_CLEAR(state->Lt_singleton);
  105. Py_CLEAR(state->Lt_type);
  106. Py_CLEAR(state->MatMult_singleton);
  107. Py_CLEAR(state->MatMult_type);
  108. Py_CLEAR(state->MatchAs_type);
  109. Py_CLEAR(state->MatchClass_type);
  110. Py_CLEAR(state->MatchMapping_type);
  111. Py_CLEAR(state->MatchOr_type);
  112. Py_CLEAR(state->MatchSequence_type);
  113. Py_CLEAR(state->MatchSingleton_type);
  114. Py_CLEAR(state->MatchStar_type);
  115. Py_CLEAR(state->MatchValue_type);
  116. Py_CLEAR(state->Match_type);
  117. Py_CLEAR(state->Mod_singleton);
  118. Py_CLEAR(state->Mod_type);
  119. Py_CLEAR(state->Module_type);
  120. Py_CLEAR(state->Mult_singleton);
  121. Py_CLEAR(state->Mult_type);
  122. Py_CLEAR(state->Name_type);
  123. Py_CLEAR(state->NamedExpr_type);
  124. Py_CLEAR(state->Nonlocal_type);
  125. Py_CLEAR(state->NotEq_singleton);
  126. Py_CLEAR(state->NotEq_type);
  127. Py_CLEAR(state->NotIn_singleton);
  128. Py_CLEAR(state->NotIn_type);
  129. Py_CLEAR(state->Not_singleton);
  130. Py_CLEAR(state->Not_type);
  131. Py_CLEAR(state->Or_singleton);
  132. Py_CLEAR(state->Or_type);
  133. Py_CLEAR(state->ParamSpec_type);
  134. Py_CLEAR(state->Pass_type);
  135. Py_CLEAR(state->Pow_singleton);
  136. Py_CLEAR(state->Pow_type);
  137. Py_CLEAR(state->RShift_singleton);
  138. Py_CLEAR(state->RShift_type);
  139. Py_CLEAR(state->Raise_type);
  140. Py_CLEAR(state->Return_type);
  141. Py_CLEAR(state->SetComp_type);
  142. Py_CLEAR(state->Set_type);
  143. Py_CLEAR(state->Slice_type);
  144. Py_CLEAR(state->Starred_type);
  145. Py_CLEAR(state->Store_singleton);
  146. Py_CLEAR(state->Store_type);
  147. Py_CLEAR(state->Sub_singleton);
  148. Py_CLEAR(state->Sub_type);
  149. Py_CLEAR(state->Subscript_type);
  150. Py_CLEAR(state->TryStar_type);
  151. Py_CLEAR(state->Try_type);
  152. Py_CLEAR(state->Tuple_type);
  153. Py_CLEAR(state->TypeAlias_type);
  154. Py_CLEAR(state->TypeIgnore_type);
  155. Py_CLEAR(state->TypeVarTuple_type);
  156. Py_CLEAR(state->TypeVar_type);
  157. Py_CLEAR(state->UAdd_singleton);
  158. Py_CLEAR(state->UAdd_type);
  159. Py_CLEAR(state->USub_singleton);
  160. Py_CLEAR(state->USub_type);
  161. Py_CLEAR(state->UnaryOp_type);
  162. Py_CLEAR(state->While_type);
  163. Py_CLEAR(state->With_type);
  164. Py_CLEAR(state->YieldFrom_type);
  165. Py_CLEAR(state->Yield_type);
  166. Py_CLEAR(state->__dict__);
  167. Py_CLEAR(state->__doc__);
  168. Py_CLEAR(state->__match_args__);
  169. Py_CLEAR(state->__module__);
  170. Py_CLEAR(state->_attributes);
  171. Py_CLEAR(state->_fields);
  172. Py_CLEAR(state->alias_type);
  173. Py_CLEAR(state->annotation);
  174. Py_CLEAR(state->arg);
  175. Py_CLEAR(state->arg_type);
  176. Py_CLEAR(state->args);
  177. Py_CLEAR(state->argtypes);
  178. Py_CLEAR(state->arguments_type);
  179. Py_CLEAR(state->asname);
  180. Py_CLEAR(state->ast);
  181. Py_CLEAR(state->attr);
  182. Py_CLEAR(state->bases);
  183. Py_CLEAR(state->body);
  184. Py_CLEAR(state->boolop_type);
  185. Py_CLEAR(state->bound);
  186. Py_CLEAR(state->cases);
  187. Py_CLEAR(state->cause);
  188. Py_CLEAR(state->cls);
  189. Py_CLEAR(state->cmpop_type);
  190. Py_CLEAR(state->col_offset);
  191. Py_CLEAR(state->comparators);
  192. Py_CLEAR(state->comprehension_type);
  193. Py_CLEAR(state->context_expr);
  194. Py_CLEAR(state->conversion);
  195. Py_CLEAR(state->ctx);
  196. Py_CLEAR(state->decorator_list);
  197. Py_CLEAR(state->defaults);
  198. Py_CLEAR(state->elt);
  199. Py_CLEAR(state->elts);
  200. Py_CLEAR(state->end_col_offset);
  201. Py_CLEAR(state->end_lineno);
  202. Py_CLEAR(state->exc);
  203. Py_CLEAR(state->excepthandler_type);
  204. Py_CLEAR(state->expr_context_type);
  205. Py_CLEAR(state->expr_type);
  206. Py_CLEAR(state->finalbody);
  207. Py_CLEAR(state->format_spec);
  208. Py_CLEAR(state->func);
  209. Py_CLEAR(state->generators);
  210. Py_CLEAR(state->guard);
  211. Py_CLEAR(state->handlers);
  212. Py_CLEAR(state->id);
  213. Py_CLEAR(state->ifs);
  214. Py_CLEAR(state->is_async);
  215. Py_CLEAR(state->items);
  216. Py_CLEAR(state->iter);
  217. Py_CLEAR(state->key);
  218. Py_CLEAR(state->keys);
  219. Py_CLEAR(state->keyword_type);
  220. Py_CLEAR(state->keywords);
  221. Py_CLEAR(state->kind);
  222. Py_CLEAR(state->kw_defaults);
  223. Py_CLEAR(state->kwarg);
  224. Py_CLEAR(state->kwd_attrs);
  225. Py_CLEAR(state->kwd_patterns);
  226. Py_CLEAR(state->kwonlyargs);
  227. Py_CLEAR(state->left);
  228. Py_CLEAR(state->level);
  229. Py_CLEAR(state->lineno);
  230. Py_CLEAR(state->lower);
  231. Py_CLEAR(state->match_case_type);
  232. Py_CLEAR(state->mod_type);
  233. Py_CLEAR(state->module);
  234. Py_CLEAR(state->msg);
  235. Py_CLEAR(state->name);
  236. Py_CLEAR(state->names);
  237. Py_CLEAR(state->op);
  238. Py_CLEAR(state->operand);
  239. Py_CLEAR(state->operator_type);
  240. Py_CLEAR(state->ops);
  241. Py_CLEAR(state->optional_vars);
  242. Py_CLEAR(state->orelse);
  243. Py_CLEAR(state->pattern);
  244. Py_CLEAR(state->pattern_type);
  245. Py_CLEAR(state->patterns);
  246. Py_CLEAR(state->posonlyargs);
  247. Py_CLEAR(state->rest);
  248. Py_CLEAR(state->returns);
  249. Py_CLEAR(state->right);
  250. Py_CLEAR(state->simple);
  251. Py_CLEAR(state->slice);
  252. Py_CLEAR(state->step);
  253. Py_CLEAR(state->stmt_type);
  254. Py_CLEAR(state->subject);
  255. Py_CLEAR(state->tag);
  256. Py_CLEAR(state->target);
  257. Py_CLEAR(state->targets);
  258. Py_CLEAR(state->test);
  259. Py_CLEAR(state->type);
  260. Py_CLEAR(state->type_comment);
  261. Py_CLEAR(state->type_ignore_type);
  262. Py_CLEAR(state->type_ignores);
  263. Py_CLEAR(state->type_param_type);
  264. Py_CLEAR(state->type_params);
  265. Py_CLEAR(state->unaryop_type);
  266. Py_CLEAR(state->upper);
  267. Py_CLEAR(state->value);
  268. Py_CLEAR(state->values);
  269. Py_CLEAR(state->vararg);
  270. Py_CLEAR(state->withitem_type);
  271. Py_CLEAR(_Py_INTERP_CACHED_OBJECT(interp, str_replace_inf));
  272. #if !defined(NDEBUG)
  273. state->initialized = -1;
  274. #else
  275. state->initialized = 0;
  276. #endif
  277. }
  278. static int init_identifiers(struct ast_state *state)
  279. {
  280. if ((state->__dict__ = PyUnicode_InternFromString("__dict__")) == NULL) return 0;
  281. if ((state->__doc__ = PyUnicode_InternFromString("__doc__")) == NULL) return 0;
  282. if ((state->__match_args__ = PyUnicode_InternFromString("__match_args__")) == NULL) return 0;
  283. if ((state->__module__ = PyUnicode_InternFromString("__module__")) == NULL) return 0;
  284. if ((state->_attributes = PyUnicode_InternFromString("_attributes")) == NULL) return 0;
  285. if ((state->_fields = PyUnicode_InternFromString("_fields")) == NULL) return 0;
  286. if ((state->annotation = PyUnicode_InternFromString("annotation")) == NULL) return 0;
  287. if ((state->arg = PyUnicode_InternFromString("arg")) == NULL) return 0;
  288. if ((state->args = PyUnicode_InternFromString("args")) == NULL) return 0;
  289. if ((state->argtypes = PyUnicode_InternFromString("argtypes")) == NULL) return 0;
  290. if ((state->asname = PyUnicode_InternFromString("asname")) == NULL) return 0;
  291. if ((state->ast = PyUnicode_InternFromString("ast")) == NULL) return 0;
  292. if ((state->attr = PyUnicode_InternFromString("attr")) == NULL) return 0;
  293. if ((state->bases = PyUnicode_InternFromString("bases")) == NULL) return 0;
  294. if ((state->body = PyUnicode_InternFromString("body")) == NULL) return 0;
  295. if ((state->bound = PyUnicode_InternFromString("bound")) == NULL) return 0;
  296. if ((state->cases = PyUnicode_InternFromString("cases")) == NULL) return 0;
  297. if ((state->cause = PyUnicode_InternFromString("cause")) == NULL) return 0;
  298. if ((state->cls = PyUnicode_InternFromString("cls")) == NULL) return 0;
  299. if ((state->col_offset = PyUnicode_InternFromString("col_offset")) == NULL) return 0;
  300. if ((state->comparators = PyUnicode_InternFromString("comparators")) == NULL) return 0;
  301. if ((state->context_expr = PyUnicode_InternFromString("context_expr")) == NULL) return 0;
  302. if ((state->conversion = PyUnicode_InternFromString("conversion")) == NULL) return 0;
  303. if ((state->ctx = PyUnicode_InternFromString("ctx")) == NULL) return 0;
  304. if ((state->decorator_list = PyUnicode_InternFromString("decorator_list")) == NULL) return 0;
  305. if ((state->defaults = PyUnicode_InternFromString("defaults")) == NULL) return 0;
  306. if ((state->elt = PyUnicode_InternFromString("elt")) == NULL) return 0;
  307. if ((state->elts = PyUnicode_InternFromString("elts")) == NULL) return 0;
  308. if ((state->end_col_offset = PyUnicode_InternFromString("end_col_offset")) == NULL) return 0;
  309. if ((state->end_lineno = PyUnicode_InternFromString("end_lineno")) == NULL) return 0;
  310. if ((state->exc = PyUnicode_InternFromString("exc")) == NULL) return 0;
  311. if ((state->finalbody = PyUnicode_InternFromString("finalbody")) == NULL) return 0;
  312. if ((state->format_spec = PyUnicode_InternFromString("format_spec")) == NULL) return 0;
  313. if ((state->func = PyUnicode_InternFromString("func")) == NULL) return 0;
  314. if ((state->generators = PyUnicode_InternFromString("generators")) == NULL) return 0;
  315. if ((state->guard = PyUnicode_InternFromString("guard")) == NULL) return 0;
  316. if ((state->handlers = PyUnicode_InternFromString("handlers")) == NULL) return 0;
  317. if ((state->id = PyUnicode_InternFromString("id")) == NULL) return 0;
  318. if ((state->ifs = PyUnicode_InternFromString("ifs")) == NULL) return 0;
  319. if ((state->is_async = PyUnicode_InternFromString("is_async")) == NULL) return 0;
  320. if ((state->items = PyUnicode_InternFromString("items")) == NULL) return 0;
  321. if ((state->iter = PyUnicode_InternFromString("iter")) == NULL) return 0;
  322. if ((state->key = PyUnicode_InternFromString("key")) == NULL) return 0;
  323. if ((state->keys = PyUnicode_InternFromString("keys")) == NULL) return 0;
  324. if ((state->keywords = PyUnicode_InternFromString("keywords")) == NULL) return 0;
  325. if ((state->kind = PyUnicode_InternFromString("kind")) == NULL) return 0;
  326. if ((state->kw_defaults = PyUnicode_InternFromString("kw_defaults")) == NULL) return 0;
  327. if ((state->kwarg = PyUnicode_InternFromString("kwarg")) == NULL) return 0;
  328. if ((state->kwd_attrs = PyUnicode_InternFromString("kwd_attrs")) == NULL) return 0;
  329. if ((state->kwd_patterns = PyUnicode_InternFromString("kwd_patterns")) == NULL) return 0;
  330. if ((state->kwonlyargs = PyUnicode_InternFromString("kwonlyargs")) == NULL) return 0;
  331. if ((state->left = PyUnicode_InternFromString("left")) == NULL) return 0;
  332. if ((state->level = PyUnicode_InternFromString("level")) == NULL) return 0;
  333. if ((state->lineno = PyUnicode_InternFromString("lineno")) == NULL) return 0;
  334. if ((state->lower = PyUnicode_InternFromString("lower")) == NULL) return 0;
  335. if ((state->module = PyUnicode_InternFromString("module")) == NULL) return 0;
  336. if ((state->msg = PyUnicode_InternFromString("msg")) == NULL) return 0;
  337. if ((state->name = PyUnicode_InternFromString("name")) == NULL) return 0;
  338. if ((state->names = PyUnicode_InternFromString("names")) == NULL) return 0;
  339. if ((state->op = PyUnicode_InternFromString("op")) == NULL) return 0;
  340. if ((state->operand = PyUnicode_InternFromString("operand")) == NULL) return 0;
  341. if ((state->ops = PyUnicode_InternFromString("ops")) == NULL) return 0;
  342. if ((state->optional_vars = PyUnicode_InternFromString("optional_vars")) == NULL) return 0;
  343. if ((state->orelse = PyUnicode_InternFromString("orelse")) == NULL) return 0;
  344. if ((state->pattern = PyUnicode_InternFromString("pattern")) == NULL) return 0;
  345. if ((state->patterns = PyUnicode_InternFromString("patterns")) == NULL) return 0;
  346. if ((state->posonlyargs = PyUnicode_InternFromString("posonlyargs")) == NULL) return 0;
  347. if ((state->rest = PyUnicode_InternFromString("rest")) == NULL) return 0;
  348. if ((state->returns = PyUnicode_InternFromString("returns")) == NULL) return 0;
  349. if ((state->right = PyUnicode_InternFromString("right")) == NULL) return 0;
  350. if ((state->simple = PyUnicode_InternFromString("simple")) == NULL) return 0;
  351. if ((state->slice = PyUnicode_InternFromString("slice")) == NULL) return 0;
  352. if ((state->step = PyUnicode_InternFromString("step")) == NULL) return 0;
  353. if ((state->subject = PyUnicode_InternFromString("subject")) == NULL) return 0;
  354. if ((state->tag = PyUnicode_InternFromString("tag")) == NULL) return 0;
  355. if ((state->target = PyUnicode_InternFromString("target")) == NULL) return 0;
  356. if ((state->targets = PyUnicode_InternFromString("targets")) == NULL) return 0;
  357. if ((state->test = PyUnicode_InternFromString("test")) == NULL) return 0;
  358. if ((state->type = PyUnicode_InternFromString("type")) == NULL) return 0;
  359. if ((state->type_comment = PyUnicode_InternFromString("type_comment")) == NULL) return 0;
  360. if ((state->type_ignores = PyUnicode_InternFromString("type_ignores")) == NULL) return 0;
  361. if ((state->type_params = PyUnicode_InternFromString("type_params")) == NULL) return 0;
  362. if ((state->upper = PyUnicode_InternFromString("upper")) == NULL) return 0;
  363. if ((state->value = PyUnicode_InternFromString("value")) == NULL) return 0;
  364. if ((state->values = PyUnicode_InternFromString("values")) == NULL) return 0;
  365. if ((state->vararg = PyUnicode_InternFromString("vararg")) == NULL) return 0;
  366. return 1;
  367. };
  368. GENERATE_ASDL_SEQ_CONSTRUCTOR(mod, mod_ty)
  369. GENERATE_ASDL_SEQ_CONSTRUCTOR(stmt, stmt_ty)
  370. GENERATE_ASDL_SEQ_CONSTRUCTOR(expr, expr_ty)
  371. GENERATE_ASDL_SEQ_CONSTRUCTOR(comprehension, comprehension_ty)
  372. GENERATE_ASDL_SEQ_CONSTRUCTOR(excepthandler, excepthandler_ty)
  373. GENERATE_ASDL_SEQ_CONSTRUCTOR(arguments, arguments_ty)
  374. GENERATE_ASDL_SEQ_CONSTRUCTOR(arg, arg_ty)
  375. GENERATE_ASDL_SEQ_CONSTRUCTOR(keyword, keyword_ty)
  376. GENERATE_ASDL_SEQ_CONSTRUCTOR(alias, alias_ty)
  377. GENERATE_ASDL_SEQ_CONSTRUCTOR(withitem, withitem_ty)
  378. GENERATE_ASDL_SEQ_CONSTRUCTOR(match_case, match_case_ty)
  379. GENERATE_ASDL_SEQ_CONSTRUCTOR(pattern, pattern_ty)
  380. GENERATE_ASDL_SEQ_CONSTRUCTOR(type_ignore, type_ignore_ty)
  381. GENERATE_ASDL_SEQ_CONSTRUCTOR(type_param, type_param_ty)
  382. static PyObject* ast2obj_mod(struct ast_state *state, struct validator *vstate,
  383. void*);
  384. static const char * const Module_fields[]={
  385. "body",
  386. "type_ignores",
  387. };
  388. static const char * const Interactive_fields[]={
  389. "body",
  390. };
  391. static const char * const Expression_fields[]={
  392. "body",
  393. };
  394. static const char * const FunctionType_fields[]={
  395. "argtypes",
  396. "returns",
  397. };
  398. static const char * const stmt_attributes[] = {
  399. "lineno",
  400. "col_offset",
  401. "end_lineno",
  402. "end_col_offset",
  403. };
  404. static PyObject* ast2obj_stmt(struct ast_state *state, struct validator
  405. *vstate, void*);
  406. static const char * const FunctionDef_fields[]={
  407. "name",
  408. "args",
  409. "body",
  410. "decorator_list",
  411. "returns",
  412. "type_comment",
  413. "type_params",
  414. };
  415. static const char * const AsyncFunctionDef_fields[]={
  416. "name",
  417. "args",
  418. "body",
  419. "decorator_list",
  420. "returns",
  421. "type_comment",
  422. "type_params",
  423. };
  424. static const char * const ClassDef_fields[]={
  425. "name",
  426. "bases",
  427. "keywords",
  428. "body",
  429. "decorator_list",
  430. "type_params",
  431. };
  432. static const char * const Return_fields[]={
  433. "value",
  434. };
  435. static const char * const Delete_fields[]={
  436. "targets",
  437. };
  438. static const char * const Assign_fields[]={
  439. "targets",
  440. "value",
  441. "type_comment",
  442. };
  443. static const char * const TypeAlias_fields[]={
  444. "name",
  445. "type_params",
  446. "value",
  447. };
  448. static const char * const AugAssign_fields[]={
  449. "target",
  450. "op",
  451. "value",
  452. };
  453. static const char * const AnnAssign_fields[]={
  454. "target",
  455. "annotation",
  456. "value",
  457. "simple",
  458. };
  459. static const char * const For_fields[]={
  460. "target",
  461. "iter",
  462. "body",
  463. "orelse",
  464. "type_comment",
  465. };
  466. static const char * const AsyncFor_fields[]={
  467. "target",
  468. "iter",
  469. "body",
  470. "orelse",
  471. "type_comment",
  472. };
  473. static const char * const While_fields[]={
  474. "test",
  475. "body",
  476. "orelse",
  477. };
  478. static const char * const If_fields[]={
  479. "test",
  480. "body",
  481. "orelse",
  482. };
  483. static const char * const With_fields[]={
  484. "items",
  485. "body",
  486. "type_comment",
  487. };
  488. static const char * const AsyncWith_fields[]={
  489. "items",
  490. "body",
  491. "type_comment",
  492. };
  493. static const char * const Match_fields[]={
  494. "subject",
  495. "cases",
  496. };
  497. static const char * const Raise_fields[]={
  498. "exc",
  499. "cause",
  500. };
  501. static const char * const Try_fields[]={
  502. "body",
  503. "handlers",
  504. "orelse",
  505. "finalbody",
  506. };
  507. static const char * const TryStar_fields[]={
  508. "body",
  509. "handlers",
  510. "orelse",
  511. "finalbody",
  512. };
  513. static const char * const Assert_fields[]={
  514. "test",
  515. "msg",
  516. };
  517. static const char * const Import_fields[]={
  518. "names",
  519. };
  520. static const char * const ImportFrom_fields[]={
  521. "module",
  522. "names",
  523. "level",
  524. };
  525. static const char * const Global_fields[]={
  526. "names",
  527. };
  528. static const char * const Nonlocal_fields[]={
  529. "names",
  530. };
  531. static const char * const Expr_fields[]={
  532. "value",
  533. };
  534. static const char * const expr_attributes[] = {
  535. "lineno",
  536. "col_offset",
  537. "end_lineno",
  538. "end_col_offset",
  539. };
  540. static PyObject* ast2obj_expr(struct ast_state *state, struct validator
  541. *vstate, void*);
  542. static const char * const BoolOp_fields[]={
  543. "op",
  544. "values",
  545. };
  546. static const char * const NamedExpr_fields[]={
  547. "target",
  548. "value",
  549. };
  550. static const char * const BinOp_fields[]={
  551. "left",
  552. "op",
  553. "right",
  554. };
  555. static const char * const UnaryOp_fields[]={
  556. "op",
  557. "operand",
  558. };
  559. static const char * const Lambda_fields[]={
  560. "args",
  561. "body",
  562. };
  563. static const char * const IfExp_fields[]={
  564. "test",
  565. "body",
  566. "orelse",
  567. };
  568. static const char * const Dict_fields[]={
  569. "keys",
  570. "values",
  571. };
  572. static const char * const Set_fields[]={
  573. "elts",
  574. };
  575. static const char * const ListComp_fields[]={
  576. "elt",
  577. "generators",
  578. };
  579. static const char * const SetComp_fields[]={
  580. "elt",
  581. "generators",
  582. };
  583. static const char * const DictComp_fields[]={
  584. "key",
  585. "value",
  586. "generators",
  587. };
  588. static const char * const GeneratorExp_fields[]={
  589. "elt",
  590. "generators",
  591. };
  592. static const char * const Await_fields[]={
  593. "value",
  594. };
  595. static const char * const Yield_fields[]={
  596. "value",
  597. };
  598. static const char * const YieldFrom_fields[]={
  599. "value",
  600. };
  601. static const char * const Compare_fields[]={
  602. "left",
  603. "ops",
  604. "comparators",
  605. };
  606. static const char * const Call_fields[]={
  607. "func",
  608. "args",
  609. "keywords",
  610. };
  611. static const char * const FormattedValue_fields[]={
  612. "value",
  613. "conversion",
  614. "format_spec",
  615. };
  616. static const char * const JoinedStr_fields[]={
  617. "values",
  618. };
  619. static const char * const Constant_fields[]={
  620. "value",
  621. "kind",
  622. };
  623. static const char * const Attribute_fields[]={
  624. "value",
  625. "attr",
  626. "ctx",
  627. };
  628. static const char * const Subscript_fields[]={
  629. "value",
  630. "slice",
  631. "ctx",
  632. };
  633. static const char * const Starred_fields[]={
  634. "value",
  635. "ctx",
  636. };
  637. static const char * const Name_fields[]={
  638. "id",
  639. "ctx",
  640. };
  641. static const char * const List_fields[]={
  642. "elts",
  643. "ctx",
  644. };
  645. static const char * const Tuple_fields[]={
  646. "elts",
  647. "ctx",
  648. };
  649. static const char * const Slice_fields[]={
  650. "lower",
  651. "upper",
  652. "step",
  653. };
  654. static PyObject* ast2obj_expr_context(struct ast_state *state, struct validator
  655. *vstate, expr_context_ty);
  656. static PyObject* ast2obj_boolop(struct ast_state *state, struct validator
  657. *vstate, boolop_ty);
  658. static PyObject* ast2obj_operator(struct ast_state *state, struct validator
  659. *vstate, operator_ty);
  660. static PyObject* ast2obj_unaryop(struct ast_state *state, struct validator
  661. *vstate, unaryop_ty);
  662. static PyObject* ast2obj_cmpop(struct ast_state *state, struct validator
  663. *vstate, cmpop_ty);
  664. static PyObject* ast2obj_comprehension(struct ast_state *state, struct
  665. validator *vstate, void*);
  666. static const char * const comprehension_fields[]={
  667. "target",
  668. "iter",
  669. "ifs",
  670. "is_async",
  671. };
  672. static const char * const excepthandler_attributes[] = {
  673. "lineno",
  674. "col_offset",
  675. "end_lineno",
  676. "end_col_offset",
  677. };
  678. static PyObject* ast2obj_excepthandler(struct ast_state *state, struct
  679. validator *vstate, void*);
  680. static const char * const ExceptHandler_fields[]={
  681. "type",
  682. "name",
  683. "body",
  684. };
  685. static PyObject* ast2obj_arguments(struct ast_state *state, struct validator
  686. *vstate, void*);
  687. static const char * const arguments_fields[]={
  688. "posonlyargs",
  689. "args",
  690. "vararg",
  691. "kwonlyargs",
  692. "kw_defaults",
  693. "kwarg",
  694. "defaults",
  695. };
  696. static PyObject* ast2obj_arg(struct ast_state *state, struct validator *vstate,
  697. void*);
  698. static const char * const arg_attributes[] = {
  699. "lineno",
  700. "col_offset",
  701. "end_lineno",
  702. "end_col_offset",
  703. };
  704. static const char * const arg_fields[]={
  705. "arg",
  706. "annotation",
  707. "type_comment",
  708. };
  709. static PyObject* ast2obj_keyword(struct ast_state *state, struct validator
  710. *vstate, void*);
  711. static const char * const keyword_attributes[] = {
  712. "lineno",
  713. "col_offset",
  714. "end_lineno",
  715. "end_col_offset",
  716. };
  717. static const char * const keyword_fields[]={
  718. "arg",
  719. "value",
  720. };
  721. static PyObject* ast2obj_alias(struct ast_state *state, struct validator
  722. *vstate, void*);
  723. static const char * const alias_attributes[] = {
  724. "lineno",
  725. "col_offset",
  726. "end_lineno",
  727. "end_col_offset",
  728. };
  729. static const char * const alias_fields[]={
  730. "name",
  731. "asname",
  732. };
  733. static PyObject* ast2obj_withitem(struct ast_state *state, struct validator
  734. *vstate, void*);
  735. static const char * const withitem_fields[]={
  736. "context_expr",
  737. "optional_vars",
  738. };
  739. static PyObject* ast2obj_match_case(struct ast_state *state, struct validator
  740. *vstate, void*);
  741. static const char * const match_case_fields[]={
  742. "pattern",
  743. "guard",
  744. "body",
  745. };
  746. static const char * const pattern_attributes[] = {
  747. "lineno",
  748. "col_offset",
  749. "end_lineno",
  750. "end_col_offset",
  751. };
  752. static PyObject* ast2obj_pattern(struct ast_state *state, struct validator
  753. *vstate, void*);
  754. static const char * const MatchValue_fields[]={
  755. "value",
  756. };
  757. static const char * const MatchSingleton_fields[]={
  758. "value",
  759. };
  760. static const char * const MatchSequence_fields[]={
  761. "patterns",
  762. };
  763. static const char * const MatchMapping_fields[]={
  764. "keys",
  765. "patterns",
  766. "rest",
  767. };
  768. static const char * const MatchClass_fields[]={
  769. "cls",
  770. "patterns",
  771. "kwd_attrs",
  772. "kwd_patterns",
  773. };
  774. static const char * const MatchStar_fields[]={
  775. "name",
  776. };
  777. static const char * const MatchAs_fields[]={
  778. "pattern",
  779. "name",
  780. };
  781. static const char * const MatchOr_fields[]={
  782. "patterns",
  783. };
  784. static PyObject* ast2obj_type_ignore(struct ast_state *state, struct validator
  785. *vstate, void*);
  786. static const char * const TypeIgnore_fields[]={
  787. "lineno",
  788. "tag",
  789. };
  790. static const char * const type_param_attributes[] = {
  791. "lineno",
  792. "col_offset",
  793. "end_lineno",
  794. "end_col_offset",
  795. };
  796. static PyObject* ast2obj_type_param(struct ast_state *state, struct validator
  797. *vstate, void*);
  798. static const char * const TypeVar_fields[]={
  799. "name",
  800. "bound",
  801. };
  802. static const char * const ParamSpec_fields[]={
  803. "name",
  804. };
  805. static const char * const TypeVarTuple_fields[]={
  806. "name",
  807. };
  808. typedef struct {
  809. PyObject_HEAD
  810. PyObject *dict;
  811. } AST_object;
  812. static void
  813. ast_dealloc(AST_object *self)
  814. {
  815. /* bpo-31095: UnTrack is needed before calling any callbacks */
  816. PyTypeObject *tp = Py_TYPE(self);
  817. PyObject_GC_UnTrack(self);
  818. Py_CLEAR(self->dict);
  819. freefunc free_func = PyType_GetSlot(tp, Py_tp_free);
  820. assert(free_func != NULL);
  821. free_func(self);
  822. Py_DECREF(tp);
  823. }
  824. static int
  825. ast_traverse(AST_object *self, visitproc visit, void *arg)
  826. {
  827. Py_VISIT(Py_TYPE(self));
  828. Py_VISIT(self->dict);
  829. return 0;
  830. }
  831. static int
  832. ast_clear(AST_object *self)
  833. {
  834. Py_CLEAR(self->dict);
  835. return 0;
  836. }
  837. static int
  838. ast_type_init(PyObject *self, PyObject *args, PyObject *kw)
  839. {
  840. struct ast_state *state = get_ast_state();
  841. if (state == NULL) {
  842. return -1;
  843. }
  844. Py_ssize_t i, numfields = 0;
  845. int res = -1;
  846. PyObject *key, *value, *fields;
  847. if (_PyObject_LookupAttr((PyObject*)Py_TYPE(self), state->_fields, &fields) < 0) {
  848. goto cleanup;
  849. }
  850. if (fields) {
  851. numfields = PySequence_Size(fields);
  852. if (numfields == -1) {
  853. goto cleanup;
  854. }
  855. }
  856. res = 0; /* if no error occurs, this stays 0 to the end */
  857. if (numfields < PyTuple_GET_SIZE(args)) {
  858. PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
  859. "%zd positional argument%s",
  860. _PyType_Name(Py_TYPE(self)),
  861. numfields, numfields == 1 ? "" : "s");
  862. res = -1;
  863. goto cleanup;
  864. }
  865. for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
  866. /* cannot be reached when fields is NULL */
  867. PyObject *name = PySequence_GetItem(fields, i);
  868. if (!name) {
  869. res = -1;
  870. goto cleanup;
  871. }
  872. res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
  873. Py_DECREF(name);
  874. if (res < 0) {
  875. goto cleanup;
  876. }
  877. }
  878. if (kw) {
  879. i = 0; /* needed by PyDict_Next */
  880. while (PyDict_Next(kw, &i, &key, &value)) {
  881. int contains = PySequence_Contains(fields, key);
  882. if (contains == -1) {
  883. res = -1;
  884. goto cleanup;
  885. } else if (contains == 1) {
  886. Py_ssize_t p = PySequence_Index(fields, key);
  887. if (p == -1) {
  888. res = -1;
  889. goto cleanup;
  890. }
  891. if (p < PyTuple_GET_SIZE(args)) {
  892. PyErr_Format(PyExc_TypeError,
  893. "%.400s got multiple values for argument '%U'",
  894. Py_TYPE(self)->tp_name, key);
  895. res = -1;
  896. goto cleanup;
  897. }
  898. }
  899. res = PyObject_SetAttr(self, key, value);
  900. if (res < 0) {
  901. goto cleanup;
  902. }
  903. }
  904. }
  905. cleanup:
  906. Py_XDECREF(fields);
  907. return res;
  908. }
  909. /* Pickling support */
  910. static PyObject *
  911. ast_type_reduce(PyObject *self, PyObject *unused)
  912. {
  913. struct ast_state *state = get_ast_state();
  914. if (state == NULL) {
  915. return NULL;
  916. }
  917. PyObject *dict;
  918. if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) {
  919. return NULL;
  920. }
  921. if (dict) {
  922. return Py_BuildValue("O()N", Py_TYPE(self), dict);
  923. }
  924. return Py_BuildValue("O()", Py_TYPE(self));
  925. }
  926. static PyMemberDef ast_type_members[] = {
  927. {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
  928. {NULL} /* Sentinel */
  929. };
  930. static PyMethodDef ast_type_methods[] = {
  931. {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
  932. {NULL}
  933. };
  934. static PyGetSetDef ast_type_getsets[] = {
  935. {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
  936. {NULL}
  937. };
  938. static PyType_Slot AST_type_slots[] = {
  939. {Py_tp_dealloc, ast_dealloc},
  940. {Py_tp_getattro, PyObject_GenericGetAttr},
  941. {Py_tp_setattro, PyObject_GenericSetAttr},
  942. {Py_tp_traverse, ast_traverse},
  943. {Py_tp_clear, ast_clear},
  944. {Py_tp_members, ast_type_members},
  945. {Py_tp_methods, ast_type_methods},
  946. {Py_tp_getset, ast_type_getsets},
  947. {Py_tp_init, ast_type_init},
  948. {Py_tp_alloc, PyType_GenericAlloc},
  949. {Py_tp_new, PyType_GenericNew},
  950. {Py_tp_free, PyObject_GC_Del},
  951. {0, 0},
  952. };
  953. static PyType_Spec AST_type_spec = {
  954. "ast.AST",
  955. sizeof(AST_object),
  956. 0,
  957. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
  958. AST_type_slots
  959. };
  960. static PyObject *
  961. make_type(struct ast_state *state, const char *type, PyObject* base,
  962. const char* const* fields, int num_fields, const char *doc)
  963. {
  964. PyObject *fnames, *result;
  965. int i;
  966. fnames = PyTuple_New(num_fields);
  967. if (!fnames) return NULL;
  968. for (i = 0; i < num_fields; i++) {
  969. PyObject *field = PyUnicode_InternFromString(fields[i]);
  970. if (!field) {
  971. Py_DECREF(fnames);
  972. return NULL;
  973. }
  974. PyTuple_SET_ITEM(fnames, i, field);
  975. }
  976. result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
  977. type, base,
  978. state->_fields, fnames,
  979. state->__match_args__, fnames,
  980. state->__module__,
  981. state->ast,
  982. state->__doc__, doc);
  983. Py_DECREF(fnames);
  984. return result;
  985. }
  986. static int
  987. add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
  988. {
  989. int i, result;
  990. PyObject *s, *l = PyTuple_New(num_fields);
  991. if (!l)
  992. return 0;
  993. for (i = 0; i < num_fields; i++) {
  994. s = PyUnicode_InternFromString(attrs[i]);
  995. if (!s) {
  996. Py_DECREF(l);
  997. return 0;
  998. }
  999. PyTuple_SET_ITEM(l, i, s);
  1000. }
  1001. result = PyObject_SetAttr(type, state->_attributes, l) >= 0;
  1002. Py_DECREF(l);
  1003. return result;
  1004. }
  1005. /* Conversion AST -> Python */
  1006. static PyObject* ast2obj_list(struct ast_state *state, struct validator *vstate, asdl_seq *seq,
  1007. PyObject* (*func)(struct ast_state *state, struct validator *vstate, void*))
  1008. {
  1009. Py_ssize_t i, n = asdl_seq_LEN(seq);
  1010. PyObject *result = PyList_New(n);
  1011. PyObject *value;
  1012. if (!result)
  1013. return NULL;
  1014. for (i = 0; i < n; i++) {
  1015. value = func(state, vstate, asdl_seq_GET_UNTYPED(seq, i));
  1016. if (!value) {
  1017. Py_DECREF(result);
  1018. return NULL;
  1019. }
  1020. PyList_SET_ITEM(result, i, value);
  1021. }
  1022. return result;
  1023. }
  1024. static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), struct validator *Py_UNUSED(vstate), void *o)
  1025. {
  1026. PyObject *op = (PyObject*)o;
  1027. if (!op) {
  1028. op = Py_None;
  1029. }
  1030. return Py_NewRef(op);
  1031. }
  1032. #define ast2obj_constant ast2obj_object
  1033. #define ast2obj_identifier ast2obj_object
  1034. #define ast2obj_string ast2obj_object
  1035. static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), struct validator *Py_UNUSED(vstate), long b)
  1036. {
  1037. return PyLong_FromLong(b);
  1038. }
  1039. /* Conversion Python -> AST */
  1040. static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
  1041. {
  1042. if (obj == Py_None)
  1043. obj = NULL;
  1044. if (obj) {
  1045. if (_PyArena_AddPyObject(arena, obj) < 0) {
  1046. *out = NULL;
  1047. return -1;
  1048. }
  1049. *out = Py_NewRef(obj);
  1050. }
  1051. else {
  1052. *out = NULL;
  1053. }
  1054. return 0;
  1055. }
  1056. static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
  1057. {
  1058. if (_PyArena_AddPyObject(arena, obj) < 0) {
  1059. *out = NULL;
  1060. return -1;
  1061. }
  1062. *out = Py_NewRef(obj);
  1063. return 0;
  1064. }
  1065. static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
  1066. {
  1067. if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
  1068. PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
  1069. return 1;
  1070. }
  1071. return obj2ast_object(state, obj, out, arena);
  1072. }
  1073. static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
  1074. {
  1075. if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
  1076. PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
  1077. return 1;
  1078. }
  1079. return obj2ast_object(state, obj, out, arena);
  1080. }
  1081. static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena)
  1082. {
  1083. int i;
  1084. if (!PyLong_Check(obj)) {
  1085. PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
  1086. return 1;
  1087. }
  1088. i = _PyLong_AsInt(obj);
  1089. if (i == -1 && PyErr_Occurred())
  1090. return 1;
  1091. *out = i;
  1092. return 0;
  1093. }
  1094. static int add_ast_fields(struct ast_state *state)
  1095. {
  1096. PyObject *empty_tuple;
  1097. empty_tuple = PyTuple_New(0);
  1098. if (!empty_tuple ||
  1099. PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
  1100. PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
  1101. PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
  1102. Py_XDECREF(empty_tuple);
  1103. return -1;
  1104. }
  1105. Py_DECREF(empty_tuple);
  1106. return 0;
  1107. }
  1108. static int
  1109. init_types(struct ast_state *state)
  1110. {
  1111. // init_types() must not be called after _PyAST_Fini()
  1112. // has been called
  1113. assert(state->initialized >= 0);
  1114. if (state->initialized) {
  1115. return 1;
  1116. }
  1117. if (init_identifiers(state) < 0) {
  1118. return 0;
  1119. }
  1120. state->AST_type = PyType_FromSpec(&AST_type_spec);
  1121. if (!state->AST_type) {
  1122. return 0;
  1123. }
  1124. if (add_ast_fields(state) < 0) {
  1125. return 0;
  1126. }
  1127. state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
  1128. "mod = Module(stmt* body, type_ignore* type_ignores)\n"
  1129. " | Interactive(stmt* body)\n"
  1130. " | Expression(expr body)\n"
  1131. " | FunctionType(expr* argtypes, expr returns)");
  1132. if (!state->mod_type) return 0;
  1133. if (!add_attributes(state, state->mod_type, NULL, 0)) return 0;
  1134. state->Module_type = make_type(state, "Module", state->mod_type,
  1135. Module_fields, 2,
  1136. "Module(stmt* body, type_ignore* type_ignores)");
  1137. if (!state->Module_type) return 0;
  1138. state->Interactive_type = make_type(state, "Interactive", state->mod_type,
  1139. Interactive_fields, 1,
  1140. "Interactive(stmt* body)");
  1141. if (!state->Interactive_type) return 0;
  1142. state->Expression_type = make_type(state, "Expression", state->mod_type,
  1143. Expression_fields, 1,
  1144. "Expression(expr body)");
  1145. if (!state->Expression_type) return 0;
  1146. state->FunctionType_type = make_type(state, "FunctionType",
  1147. state->mod_type, FunctionType_fields,
  1148. 2,
  1149. "FunctionType(expr* argtypes, expr returns)");
  1150. if (!state->FunctionType_type) return 0;
  1151. state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
  1152. "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
  1153. " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
  1154. " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)\n"
  1155. " | Return(expr? value)\n"
  1156. " | Delete(expr* targets)\n"
  1157. " | Assign(expr* targets, expr value, string? type_comment)\n"
  1158. " | TypeAlias(expr name, type_param* type_params, expr value)\n"
  1159. " | AugAssign(expr target, operator op, expr value)\n"
  1160. " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
  1161. " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
  1162. " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
  1163. " | While(expr test, stmt* body, stmt* orelse)\n"
  1164. " | If(expr test, stmt* body, stmt* orelse)\n"
  1165. " | With(withitem* items, stmt* body, string? type_comment)\n"
  1166. " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
  1167. " | Match(expr subject, match_case* cases)\n"
  1168. " | Raise(expr? exc, expr? cause)\n"
  1169. " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
  1170. " | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
  1171. " | Assert(expr test, expr? msg)\n"
  1172. " | Import(alias* names)\n"
  1173. " | ImportFrom(identifier? module, alias* names, int? level)\n"
  1174. " | Global(identifier* names)\n"
  1175. " | Nonlocal(identifier* names)\n"
  1176. " | Expr(expr value)\n"
  1177. " | Pass\n"
  1178. " | Break\n"
  1179. " | Continue");
  1180. if (!state->stmt_type) return 0;
  1181. if (!add_attributes(state, state->stmt_type, stmt_attributes, 4)) return 0;
  1182. if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
  1183. return 0;
  1184. if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
  1185. -1)
  1186. return 0;
  1187. state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
  1188. FunctionDef_fields, 7,
  1189. "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
  1190. if (!state->FunctionDef_type) return 0;
  1191. if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
  1192. -1)
  1193. return 0;
  1194. if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
  1195. == -1)
  1196. return 0;
  1197. state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
  1198. state->stmt_type,
  1199. AsyncFunctionDef_fields, 7,
  1200. "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
  1201. if (!state->AsyncFunctionDef_type) return 0;
  1202. if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
  1203. == -1)
  1204. return 0;
  1205. if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
  1206. Py_None) == -1)
  1207. return 0;
  1208. state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
  1209. ClassDef_fields, 6,
  1210. "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)");
  1211. if (!state->ClassDef_type) return 0;
  1212. state->Return_type = make_type(state, "Return", state->stmt_type,
  1213. Return_fields, 1,
  1214. "Return(expr? value)");
  1215. if (!state->Return_type) return 0;
  1216. if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
  1217. return 0;
  1218. state->Delete_type = make_type(state, "Delete", state->stmt_type,
  1219. Delete_fields, 1,
  1220. "Delete(expr* targets)");
  1221. if (!state->Delete_type) return 0;
  1222. state->Assign_type = make_type(state, "Assign", state->stmt_type,
  1223. Assign_fields, 3,
  1224. "Assign(expr* targets, expr value, string? type_comment)");
  1225. if (!state->Assign_type) return 0;
  1226. if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
  1227. -1)
  1228. return 0;
  1229. state->TypeAlias_type = make_type(state, "TypeAlias", state->stmt_type,
  1230. TypeAlias_fields, 3,
  1231. "TypeAlias(expr name, type_param* type_params, expr value)");
  1232. if (!state->TypeAlias_type) return 0;
  1233. state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
  1234. AugAssign_fields, 3,
  1235. "AugAssign(expr target, operator op, expr value)");
  1236. if (!state->AugAssign_type) return 0;
  1237. state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
  1238. AnnAssign_fields, 4,
  1239. "AnnAssign(expr target, expr annotation, expr? value, int simple)");
  1240. if (!state->AnnAssign_type) return 0;
  1241. if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
  1242. return 0;
  1243. state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
  1244. "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
  1245. if (!state->For_type) return 0;
  1246. if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
  1247. return 0;
  1248. state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
  1249. AsyncFor_fields, 5,
  1250. "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
  1251. if (!state->AsyncFor_type) return 0;
  1252. if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
  1253. -1)
  1254. return 0;
  1255. state->While_type = make_type(state, "While", state->stmt_type,
  1256. While_fields, 3,
  1257. "While(expr test, stmt* body, stmt* orelse)");
  1258. if (!state->While_type) return 0;
  1259. state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
  1260. "If(expr test, stmt* body, stmt* orelse)");
  1261. if (!state->If_type) return 0;
  1262. state->With_type = make_type(state, "With", state->stmt_type, With_fields,
  1263. 3,
  1264. "With(withitem* items, stmt* body, string? type_comment)");
  1265. if (!state->With_type) return 0;
  1266. if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
  1267. return 0;
  1268. state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
  1269. AsyncWith_fields, 3,
  1270. "AsyncWith(withitem* items, stmt* body, string? type_comment)");
  1271. if (!state->AsyncWith_type) return 0;
  1272. if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
  1273. == -1)
  1274. return 0;
  1275. state->Match_type = make_type(state, "Match", state->stmt_type,
  1276. Match_fields, 2,
  1277. "Match(expr subject, match_case* cases)");
  1278. if (!state->Match_type) return 0;
  1279. state->Raise_type = make_type(state, "Raise", state->stmt_type,
  1280. Raise_fields, 2,
  1281. "Raise(expr? exc, expr? cause)");
  1282. if (!state->Raise_type) return 0;
  1283. if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
  1284. return 0;
  1285. if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
  1286. return 0;
  1287. state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
  1288. "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
  1289. if (!state->Try_type) return 0;
  1290. state->TryStar_type = make_type(state, "TryStar", state->stmt_type,
  1291. TryStar_fields, 4,
  1292. "TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
  1293. if (!state->TryStar_type) return 0;
  1294. state->Assert_type = make_type(state, "Assert", state->stmt_type,
  1295. Assert_fields, 2,
  1296. "Assert(expr test, expr? msg)");
  1297. if (!state->Assert_type) return 0;
  1298. if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
  1299. return 0;
  1300. state->Import_type = make_type(state, "Import", state->stmt_type,
  1301. Import_fields, 1,
  1302. "Import(alias* names)");
  1303. if (!state->Import_type) return 0;
  1304. state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
  1305. ImportFrom_fields, 3,
  1306. "ImportFrom(identifier? module, alias* names, int? level)");
  1307. if (!state->ImportFrom_type) return 0;
  1308. if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
  1309. return 0;
  1310. if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
  1311. return 0;
  1312. state->Global_type = make_type(state, "Global", state->stmt_type,
  1313. Global_fields, 1,
  1314. "Global(identifier* names)");
  1315. if (!state->Global_type) return 0;
  1316. state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
  1317. Nonlocal_fields, 1,
  1318. "Nonlocal(identifier* names)");
  1319. if (!state->Nonlocal_type) return 0;
  1320. state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
  1321. 1,
  1322. "Expr(expr value)");
  1323. if (!state->Expr_type) return 0;
  1324. state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
  1325. "Pass");
  1326. if (!state->Pass_type) return 0;
  1327. state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
  1328. "Break");
  1329. if (!state->Break_type) return 0;
  1330. state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
  1331. 0,
  1332. "Continue");
  1333. if (!state->Continue_type) return 0;
  1334. state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
  1335. "expr = BoolOp(boolop op, expr* values)\n"
  1336. " | NamedExpr(expr target, expr value)\n"
  1337. " | BinOp(expr left, operator op, expr right)\n"
  1338. " | UnaryOp(unaryop op, expr operand)\n"
  1339. " | Lambda(arguments args, expr body)\n"
  1340. " | IfExp(expr test, expr body, expr orelse)\n"
  1341. " | Dict(expr* keys, expr* values)\n"
  1342. " | Set(expr* elts)\n"
  1343. " | ListComp(expr elt, comprehension* generators)\n"
  1344. " | SetComp(expr elt, comprehension* generators)\n"
  1345. " | DictComp(expr key, expr value, comprehension* generators)\n"
  1346. " | GeneratorExp(expr elt, comprehension* generators)\n"
  1347. " | Await(expr value)\n"
  1348. " | Yield(expr? value)\n"
  1349. " | YieldFrom(expr value)\n"
  1350. " | Compare(expr left, cmpop* ops, expr* comparators)\n"
  1351. " | Call(expr func, expr* args, keyword* keywords)\n"
  1352. " | FormattedValue(expr value, int conversion, expr? format_spec)\n"
  1353. " | JoinedStr(expr* values)\n"
  1354. " | Constant(constant value, string? kind)\n"
  1355. " | Attribute(expr value, identifier attr, expr_context ctx)\n"
  1356. " | Subscript(expr value, expr slice, expr_context ctx)\n"
  1357. " | Starred(expr value, expr_context ctx)\n"
  1358. " | Name(identifier id, expr_context ctx)\n"
  1359. " | List(expr* elts, expr_context ctx)\n"
  1360. " | Tuple(expr* elts, expr_context ctx)\n"
  1361. " | Slice(expr? lower, expr? upper, expr? step)");
  1362. if (!state->expr_type) return 0;
  1363. if (!add_attributes(state, state->expr_type, expr_attributes, 4)) return 0;
  1364. if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
  1365. return 0;
  1366. if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
  1367. -1)
  1368. return 0;
  1369. state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
  1370. BoolOp_fields, 2,
  1371. "BoolOp(boolop op, expr* values)");
  1372. if (!state->BoolOp_type) return 0;
  1373. state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
  1374. NamedExpr_fields, 2,
  1375. "NamedExpr(expr target, expr value)");
  1376. if (!state->NamedExpr_type) return 0;
  1377. state->BinOp_type = make_type(state, "BinOp", state->expr_type,
  1378. BinOp_fields, 3,
  1379. "BinOp(expr left, operator op, expr right)");
  1380. if (!state->BinOp_type) return 0;
  1381. state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
  1382. UnaryOp_fields, 2,
  1383. "UnaryOp(unaryop op, expr operand)");
  1384. if (!state->UnaryOp_type) return 0;
  1385. state->Lambda_type = make_type(state, "Lambda", state->expr_type,
  1386. Lambda_fields, 2,
  1387. "Lambda(arguments args, expr body)");
  1388. if (!state->Lambda_type) return 0;
  1389. state->IfExp_type = make_type(state, "IfExp", state->expr_type,
  1390. IfExp_fields, 3,
  1391. "IfExp(expr test, expr body, expr orelse)");
  1392. if (!state->IfExp_type) return 0;
  1393. state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
  1394. 2,
  1395. "Dict(expr* keys, expr* values)");
  1396. if (!state->Dict_type) return 0;
  1397. state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
  1398. "Set(expr* elts)");
  1399. if (!state->Set_type) return 0;
  1400. state->ListComp_type = make_type(state, "ListComp", state->expr_type,
  1401. ListComp_fields, 2,
  1402. "ListComp(expr elt, comprehension* generators)");
  1403. if (!state->ListComp_type) return 0;
  1404. state->SetComp_type = make_type(state, "SetComp", state->expr_type,
  1405. SetComp_fields, 2,
  1406. "SetComp(expr elt, comprehension* generators)");
  1407. if (!state->SetComp_type) return 0;
  1408. state->DictComp_type = make_type(state, "DictComp", state->expr_type,
  1409. DictComp_fields, 3,
  1410. "DictComp(expr key, expr value, comprehension* generators)");
  1411. if (!state->DictComp_type) return 0;
  1412. state->GeneratorExp_type = make_type(state, "GeneratorExp",
  1413. state->expr_type, GeneratorExp_fields,
  1414. 2,
  1415. "GeneratorExp(expr elt, comprehension* generators)");
  1416. if (!state->GeneratorExp_type) return 0;
  1417. state->Await_type = make_type(state, "Await", state->expr_type,
  1418. Await_fields, 1,
  1419. "Await(expr value)");
  1420. if (!state->Await_type) return 0;
  1421. state->Yield_type = make_type(state, "Yield", state->expr_type,
  1422. Yield_fields, 1,
  1423. "Yield(expr? value)");
  1424. if (!state->Yield_type) return 0;
  1425. if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
  1426. return 0;
  1427. state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
  1428. YieldFrom_fields, 1,
  1429. "YieldFrom(expr value)");
  1430. if (!state->YieldFrom_type) return 0;
  1431. state->Compare_type = make_type(state, "Compare", state->expr_type,
  1432. Compare_fields, 3,
  1433. "Compare(expr left, cmpop* ops, expr* comparators)");
  1434. if (!state->Compare_type) return 0;
  1435. state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
  1436. 3,
  1437. "Call(expr func, expr* args, keyword* keywords)");
  1438. if (!state->Call_type) return 0;
  1439. state->FormattedValue_type = make_type(state, "FormattedValue",
  1440. state->expr_type,
  1441. FormattedValue_fields, 3,
  1442. "FormattedValue(expr value, int conversion, expr? format_spec)");
  1443. if (!state->FormattedValue_type) return 0;
  1444. if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
  1445. Py_None) == -1)
  1446. return 0;
  1447. state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
  1448. JoinedStr_fields, 1,
  1449. "JoinedStr(expr* values)");
  1450. if (!state->JoinedStr_type) return 0;
  1451. state->Constant_type = make_type(state, "Constant", state->expr_type,
  1452. Constant_fields, 2,
  1453. "Constant(constant value, string? kind)");
  1454. if (!state->Constant_type) return 0;
  1455. if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
  1456. return 0;
  1457. state->Attribute_type = make_type(state, "Attribute", state->expr_type,
  1458. Attribute_fields, 3,
  1459. "Attribute(expr value, identifier attr, expr_context ctx)");
  1460. if (!state->Attribute_type) return 0;
  1461. state->Subscript_type = make_type(state, "Subscript", state->expr_type,
  1462. Subscript_fields, 3,
  1463. "Subscript(expr value, expr slice, expr_context ctx)");
  1464. if (!state->Subscript_type) return 0;
  1465. state->Starred_type = make_type(state, "Starred", state->expr_type,
  1466. Starred_fields, 2,
  1467. "Starred(expr value, expr_context ctx)");
  1468. if (!state->Starred_type) return 0;
  1469. state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
  1470. 2,
  1471. "Name(identifier id, expr_context ctx)");
  1472. if (!state->Name_type) return 0;
  1473. state->List_type = make_type(state, "List", state->expr_type, List_fields,
  1474. 2,
  1475. "List(expr* elts, expr_context ctx)");
  1476. if (!state->List_type) return 0;
  1477. state->Tuple_type = make_type(state, "Tuple", state->expr_type,
  1478. Tuple_fields, 2,
  1479. "Tuple(expr* elts, expr_context ctx)");
  1480. if (!state->Tuple_type) return 0;
  1481. state->Slice_type = make_type(state, "Slice", state->expr_type,
  1482. Slice_fields, 3,
  1483. "Slice(expr? lower, expr? upper, expr? step)");
  1484. if (!state->Slice_type) return 0;
  1485. if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
  1486. return 0;
  1487. if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
  1488. return 0;
  1489. if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
  1490. return 0;
  1491. state->expr_context_type = make_type(state, "expr_context",
  1492. state->AST_type, NULL, 0,
  1493. "expr_context = Load | Store | Del");
  1494. if (!state->expr_context_type) return 0;
  1495. if (!add_attributes(state, state->expr_context_type, NULL, 0)) return 0;
  1496. state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
  1497. 0,
  1498. "Load");
  1499. if (!state->Load_type) return 0;
  1500. state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
  1501. NULL, NULL);
  1502. if (!state->Load_singleton) return 0;
  1503. state->Store_type = make_type(state, "Store", state->expr_context_type,
  1504. NULL, 0,
  1505. "Store");
  1506. if (!state->Store_type) return 0;
  1507. state->Store_singleton = PyType_GenericNew((PyTypeObject
  1508. *)state->Store_type, NULL, NULL);
  1509. if (!state->Store_singleton) return 0;
  1510. state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
  1511. "Del");
  1512. if (!state->Del_type) return 0;
  1513. state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
  1514. NULL, NULL);
  1515. if (!state->Del_singleton) return 0;
  1516. state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
  1517. "boolop = And | Or");
  1518. if (!state->boolop_type) return 0;
  1519. if (!add_attributes(state, state->boolop_type, NULL, 0)) return 0;
  1520. state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
  1521. "And");
  1522. if (!state->And_type) return 0;
  1523. state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
  1524. NULL, NULL);
  1525. if (!state->And_singleton) return 0;
  1526. state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
  1527. "Or");
  1528. if (!state->Or_type) return 0;
  1529. state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
  1530. NULL, NULL);
  1531. if (!state->Or_singleton) return 0;
  1532. state->operator_type = make_type(state, "operator", state->AST_type, NULL,
  1533. 0,
  1534. "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
  1535. if (!state->operator_type) return 0;
  1536. if (!add_attributes(state, state->operator_type, NULL, 0)) return 0;
  1537. state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
  1538. "Add");
  1539. if (!state->Add_type) return 0;
  1540. state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
  1541. NULL, NULL);
  1542. if (!state->Add_singleton) return 0;
  1543. state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
  1544. "Sub");
  1545. if (!state->Sub_type) return 0;
  1546. state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
  1547. NULL, NULL);
  1548. if (!state->Sub_singleton) return 0;
  1549. state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
  1550. "Mult");
  1551. if (!state->Mult_type) return 0;
  1552. state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
  1553. NULL, NULL);
  1554. if (!state->Mult_singleton) return 0;
  1555. state->MatMult_type = make_type(state, "MatMult", state->operator_type,
  1556. NULL, 0,
  1557. "MatMult");
  1558. if (!state->MatMult_type) return 0;
  1559. state->MatMult_singleton = PyType_GenericNew((PyTypeObject
  1560. *)state->MatMult_type, NULL,
  1561. NULL);
  1562. if (!state->MatMult_singleton) return 0;
  1563. state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
  1564. "Div");
  1565. if (!state->Div_type) return 0;
  1566. state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
  1567. NULL, NULL);
  1568. if (!state->Div_singleton) return 0;
  1569. state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
  1570. "Mod");
  1571. if (!state->Mod_type) return 0;
  1572. state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
  1573. NULL, NULL);
  1574. if (!state->Mod_singleton) return 0;
  1575. state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
  1576. "Pow");
  1577. if (!state->Pow_type) return 0;
  1578. state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
  1579. NULL, NULL);
  1580. if (!state->Pow_singleton) return 0;
  1581. state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
  1582. 0,
  1583. "LShift");
  1584. if (!state->LShift_type) return 0;
  1585. state->LShift_singleton = PyType_GenericNew((PyTypeObject
  1586. *)state->LShift_type, NULL,
  1587. NULL);
  1588. if (!state->LShift_singleton) return 0;
  1589. state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
  1590. 0,
  1591. "RShift");
  1592. if (!state->RShift_type) return 0;
  1593. state->RShift_singleton = PyType_GenericNew((PyTypeObject
  1594. *)state->RShift_type, NULL,
  1595. NULL);
  1596. if (!state->RShift_singleton) return 0;
  1597. state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
  1598. "BitOr");
  1599. if (!state->BitOr_type) return 0;
  1600. state->BitOr_singleton = PyType_GenericNew((PyTypeObject
  1601. *)state->BitOr_type, NULL, NULL);
  1602. if (!state->BitOr_singleton) return 0;
  1603. state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
  1604. 0,
  1605. "BitXor");
  1606. if (!state->BitXor_type) return 0;
  1607. state->BitXor_singleton = PyType_GenericNew((PyTypeObject
  1608. *)state->BitXor_type, NULL,
  1609. NULL);
  1610. if (!state->BitXor_singleton) return 0;
  1611. state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
  1612. 0,
  1613. "BitAnd");
  1614. if (!state->BitAnd_type) return 0;
  1615. state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
  1616. *)state->BitAnd_type, NULL,
  1617. NULL);
  1618. if (!state->BitAnd_singleton) return 0;
  1619. state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
  1620. NULL, 0,
  1621. "FloorDiv");
  1622. if (!state->FloorDiv_type) return 0;
  1623. state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
  1624. *)state->FloorDiv_type, NULL,
  1625. NULL);
  1626. if (!state->FloorDiv_singleton) return 0;
  1627. state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
  1628. "unaryop = Invert | Not | UAdd | USub");
  1629. if (!state->unaryop_type) return 0;
  1630. if (!add_attributes(state, state->unaryop_type, NULL, 0)) return 0;
  1631. state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
  1632. 0,
  1633. "Invert");
  1634. if (!state->Invert_type) return 0;
  1635. state->Invert_singleton = PyType_GenericNew((PyTypeObject
  1636. *)state->Invert_type, NULL,
  1637. NULL);
  1638. if (!state->Invert_singleton) return 0;
  1639. state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
  1640. "Not");
  1641. if (!state->Not_type) return 0;
  1642. state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
  1643. NULL, NULL);
  1644. if (!state->Not_singleton) return 0;
  1645. state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
  1646. "UAdd");
  1647. if (!state->UAdd_type) return 0;
  1648. state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
  1649. NULL, NULL);
  1650. if (!state->UAdd_singleton) return 0;
  1651. state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
  1652. "USub");
  1653. if (!state->USub_type) return 0;
  1654. state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
  1655. NULL, NULL);
  1656. if (!state->USub_singleton) return 0;
  1657. state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
  1658. "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
  1659. if (!state->cmpop_type) return 0;
  1660. if (!add_attributes(state, state->cmpop_type, NULL, 0)) return 0;
  1661. state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
  1662. "Eq");
  1663. if (!state->Eq_type) return 0;
  1664. state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
  1665. NULL, NULL);
  1666. if (!state->Eq_singleton) return 0;
  1667. state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
  1668. "NotEq");
  1669. if (!state->NotEq_type) return 0;
  1670. state->NotEq_singleton = PyType_GenericNew((PyTypeObject
  1671. *)state->NotEq_type, NULL, NULL);
  1672. if (!state->NotEq_singleton) return 0;
  1673. state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
  1674. "Lt");
  1675. if (!state->Lt_type) return 0;
  1676. state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
  1677. NULL, NULL);
  1678. if (!state->Lt_singleton) return 0;
  1679. state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
  1680. "LtE");
  1681. if (!state->LtE_type) return 0;
  1682. state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
  1683. NULL, NULL);
  1684. if (!state->LtE_singleton) return 0;
  1685. state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
  1686. "Gt");
  1687. if (!state->Gt_type) return 0;
  1688. state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
  1689. NULL, NULL);
  1690. if (!state->Gt_singleton) return 0;
  1691. state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
  1692. "GtE");
  1693. if (!state->GtE_type) return 0;
  1694. state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
  1695. NULL, NULL);
  1696. if (!state->GtE_singleton) return 0;
  1697. state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
  1698. "Is");
  1699. if (!state->Is_type) return 0;
  1700. state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
  1701. NULL, NULL);
  1702. if (!state->Is_singleton) return 0;
  1703. state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
  1704. "IsNot");
  1705. if (!state->IsNot_type) return 0;
  1706. state->IsNot_singleton = PyType_GenericNew((PyTypeObject
  1707. *)state->IsNot_type, NULL, NULL);
  1708. if (!state->IsNot_singleton) return 0;
  1709. state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
  1710. "In");
  1711. if (!state->In_type) return 0;
  1712. state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
  1713. NULL, NULL);
  1714. if (!state->In_singleton) return 0;
  1715. state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
  1716. "NotIn");
  1717. if (!state->NotIn_type) return 0;
  1718. state->NotIn_singleton = PyType_GenericNew((PyTypeObject
  1719. *)state->NotIn_type, NULL, NULL);
  1720. if (!state->NotIn_singleton) return 0;
  1721. state->comprehension_type = make_type(state, "comprehension",
  1722. state->AST_type,
  1723. comprehension_fields, 4,
  1724. "comprehension(expr target, expr iter, expr* ifs, int is_async)");
  1725. if (!state->comprehension_type) return 0;
  1726. if (!add_attributes(state, state->comprehension_type, NULL, 0)) return 0;
  1727. state->excepthandler_type = make_type(state, "excepthandler",
  1728. state->AST_type, NULL, 0,
  1729. "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
  1730. if (!state->excepthandler_type) return 0;
  1731. if (!add_attributes(state, state->excepthandler_type,
  1732. excepthandler_attributes, 4)) return 0;
  1733. if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
  1734. == -1)
  1735. return 0;
  1736. if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
  1737. Py_None) == -1)
  1738. return 0;
  1739. state->ExceptHandler_type = make_type(state, "ExceptHandler",
  1740. state->excepthandler_type,
  1741. ExceptHandler_fields, 3,
  1742. "ExceptHandler(expr? type, identifier? name, stmt* body)");
  1743. if (!state->ExceptHandler_type) return 0;
  1744. if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
  1745. return 0;
  1746. if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
  1747. return 0;
  1748. state->arguments_type = make_type(state, "arguments", state->AST_type,
  1749. arguments_fields, 7,
  1750. "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
  1751. if (!state->arguments_type) return 0;
  1752. if (!add_attributes(state, state->arguments_type, NULL, 0)) return 0;
  1753. if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
  1754. return 0;
  1755. if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
  1756. return 0;
  1757. state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
  1758. "arg(identifier arg, expr? annotation, string? type_comment)");
  1759. if (!state->arg_type) return 0;
  1760. if (!add_attributes(state, state->arg_type, arg_attributes, 4)) return 0;
  1761. if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
  1762. return 0;
  1763. if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
  1764. return 0;
  1765. if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
  1766. return 0;
  1767. if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
  1768. return 0;
  1769. state->keyword_type = make_type(state, "keyword", state->AST_type,
  1770. keyword_fields, 2,
  1771. "keyword(identifier? arg, expr value)");
  1772. if (!state->keyword_type) return 0;
  1773. if (!add_attributes(state, state->keyword_type, keyword_attributes, 4))
  1774. return 0;
  1775. if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
  1776. return 0;
  1777. if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
  1778. return 0;
  1779. if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
  1780. == -1)
  1781. return 0;
  1782. state->alias_type = make_type(state, "alias", state->AST_type,
  1783. alias_fields, 2,
  1784. "alias(identifier name, identifier? asname)");
  1785. if (!state->alias_type) return 0;
  1786. if (!add_attributes(state, state->alias_type, alias_attributes, 4)) return
  1787. 0;
  1788. if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
  1789. return 0;
  1790. if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
  1791. return 0;
  1792. if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
  1793. -1)
  1794. return 0;
  1795. state->withitem_type = make_type(state, "withitem", state->AST_type,
  1796. withitem_fields, 2,
  1797. "withitem(expr context_expr, expr? optional_vars)");
  1798. if (!state->withitem_type) return 0;
  1799. if (!add_attributes(state, state->withitem_type, NULL, 0)) return 0;
  1800. if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
  1801. == -1)
  1802. return 0;
  1803. state->match_case_type = make_type(state, "match_case", state->AST_type,
  1804. match_case_fields, 3,
  1805. "match_case(pattern pattern, expr? guard, stmt* body)");
  1806. if (!state->match_case_type) return 0;
  1807. if (!add_attributes(state, state->match_case_type, NULL, 0)) return 0;
  1808. if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
  1809. return 0;
  1810. state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
  1811. "pattern = MatchValue(expr value)\n"
  1812. " | MatchSingleton(constant value)\n"
  1813. " | MatchSequence(pattern* patterns)\n"
  1814. " | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
  1815. " | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
  1816. " | MatchStar(identifier? name)\n"
  1817. " | MatchAs(pattern? pattern, identifier? name)\n"
  1818. " | MatchOr(pattern* patterns)");
  1819. if (!state->pattern_type) return 0;
  1820. if (!add_attributes(state, state->pattern_type, pattern_attributes, 4))
  1821. return 0;
  1822. state->MatchValue_type = make_type(state, "MatchValue",
  1823. state->pattern_type, MatchValue_fields,
  1824. 1,
  1825. "MatchValue(expr value)");
  1826. if (!state->MatchValue_type) return 0;
  1827. state->MatchSingleton_type = make_type(state, "MatchSingleton",
  1828. state->pattern_type,
  1829. MatchSingleton_fields, 1,
  1830. "MatchSingleton(constant value)");
  1831. if (!state->MatchSingleton_type) return 0;
  1832. state->MatchSequence_type = make_type(state, "MatchSequence",
  1833. state->pattern_type,
  1834. MatchSequence_fields, 1,
  1835. "MatchSequence(pattern* patterns)");
  1836. if (!state->MatchSequence_type) return 0;
  1837. state->MatchMapping_type = make_type(state, "MatchMapping",
  1838. state->pattern_type,
  1839. MatchMapping_fields, 3,
  1840. "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
  1841. if (!state->MatchMapping_type) return 0;
  1842. if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
  1843. return 0;
  1844. state->MatchClass_type = make_type(state, "MatchClass",
  1845. state->pattern_type, MatchClass_fields,
  1846. 4,
  1847. "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
  1848. if (!state->MatchClass_type) return 0;
  1849. state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
  1850. MatchStar_fields, 1,
  1851. "MatchStar(identifier? name)");
  1852. if (!state->MatchStar_type) return 0;
  1853. if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
  1854. return 0;
  1855. state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
  1856. MatchAs_fields, 2,
  1857. "MatchAs(pattern? pattern, identifier? name)");
  1858. if (!state->MatchAs_type) return 0;
  1859. if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
  1860. return 0;
  1861. if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
  1862. return 0;
  1863. state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
  1864. MatchOr_fields, 1,
  1865. "MatchOr(pattern* patterns)");
  1866. if (!state->MatchOr_type) return 0;
  1867. state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
  1868. NULL, 0,
  1869. "type_ignore = TypeIgnore(int lineno, string tag)");
  1870. if (!state->type_ignore_type) return 0;
  1871. if (!add_attributes(state, state->type_ignore_type, NULL, 0)) return 0;
  1872. state->TypeIgnore_type = make_type(state, "TypeIgnore",
  1873. state->type_ignore_type,
  1874. TypeIgnore_fields, 2,
  1875. "TypeIgnore(int lineno, string tag)");
  1876. if (!state->TypeIgnore_type) return 0;
  1877. state->type_param_type = make_type(state, "type_param", state->AST_type,
  1878. NULL, 0,
  1879. "type_param = TypeVar(identifier name, expr? bound)\n"
  1880. " | ParamSpec(identifier name)\n"
  1881. " | TypeVarTuple(identifier name)");
  1882. if (!state->type_param_type) return 0;
  1883. if (!add_attributes(state, state->type_param_type, type_param_attributes,
  1884. 4)) return 0;
  1885. state->TypeVar_type = make_type(state, "TypeVar", state->type_param_type,
  1886. TypeVar_fields, 2,
  1887. "TypeVar(identifier name, expr? bound)");
  1888. if (!state->TypeVar_type) return 0;
  1889. if (PyObject_SetAttr(state->TypeVar_type, state->bound, Py_None) == -1)
  1890. return 0;
  1891. state->ParamSpec_type = make_type(state, "ParamSpec",
  1892. state->type_param_type, ParamSpec_fields,
  1893. 1,
  1894. "ParamSpec(identifier name)");
  1895. if (!state->ParamSpec_type) return 0;
  1896. state->TypeVarTuple_type = make_type(state, "TypeVarTuple",
  1897. state->type_param_type,
  1898. TypeVarTuple_fields, 1,
  1899. "TypeVarTuple(identifier name)");
  1900. if (!state->TypeVarTuple_type) return 0;
  1901. state->initialized = 1;
  1902. return 1;
  1903. }
  1904. static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
  1905. PyArena* arena);
  1906. static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
  1907. PyArena* arena);
  1908. static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
  1909. PyArena* arena);
  1910. static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
  1911. expr_context_ty* out, PyArena* arena);
  1912. static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
  1913. out, PyArena* arena);
  1914. static int obj2ast_operator(struct ast_state *state, PyObject* obj,
  1915. operator_ty* out, PyArena* arena);
  1916. static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
  1917. out, PyArena* arena);
  1918. static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
  1919. PyArena* arena);
  1920. static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
  1921. comprehension_ty* out, PyArena* arena);
  1922. static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
  1923. excepthandler_ty* out, PyArena* arena);
  1924. static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
  1925. arguments_ty* out, PyArena* arena);
  1926. static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
  1927. PyArena* arena);
  1928. static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
  1929. out, PyArena* arena);
  1930. static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
  1931. PyArena* arena);
  1932. static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
  1933. withitem_ty* out, PyArena* arena);
  1934. static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
  1935. match_case_ty* out, PyArena* arena);
  1936. static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
  1937. out, PyArena* arena);
  1938. static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
  1939. type_ignore_ty* out, PyArena* arena);
  1940. static int obj2ast_type_param(struct ast_state *state, PyObject* obj,
  1941. type_param_ty* out, PyArena* arena);
  1942. mod_ty
  1943. _PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
  1944. PyArena *arena)
  1945. {
  1946. mod_ty p;
  1947. p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
  1948. if (!p)
  1949. return NULL;
  1950. p->kind = Module_kind;
  1951. p->v.Module.body = body;
  1952. p->v.Module.type_ignores = type_ignores;
  1953. return p;
  1954. }
  1955. mod_ty
  1956. _PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
  1957. {
  1958. mod_ty p;
  1959. p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
  1960. if (!p)
  1961. return NULL;
  1962. p->kind = Interactive_kind;
  1963. p->v.Interactive.body = body;
  1964. return p;
  1965. }
  1966. mod_ty
  1967. _PyAST_Expression(expr_ty body, PyArena *arena)
  1968. {
  1969. mod_ty p;
  1970. if (!body) {
  1971. PyErr_SetString(PyExc_ValueError,
  1972. "field 'body' is required for Expression");
  1973. return NULL;
  1974. }
  1975. p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
  1976. if (!p)
  1977. return NULL;
  1978. p->kind = Expression_kind;
  1979. p->v.Expression.body = body;
  1980. return p;
  1981. }
  1982. mod_ty
  1983. _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
  1984. {
  1985. mod_ty p;
  1986. if (!returns) {
  1987. PyErr_SetString(PyExc_ValueError,
  1988. "field 'returns' is required for FunctionType");
  1989. return NULL;
  1990. }
  1991. p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
  1992. if (!p)
  1993. return NULL;
  1994. p->kind = FunctionType_kind;
  1995. p->v.FunctionType.argtypes = argtypes;
  1996. p->v.FunctionType.returns = returns;
  1997. return p;
  1998. }
  1999. stmt_ty
  2000. _PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
  2001. asdl_expr_seq * decorator_list, expr_ty returns, string
  2002. type_comment, asdl_type_param_seq * type_params, int lineno,
  2003. int col_offset, int end_lineno, int end_col_offset, PyArena
  2004. *arena)
  2005. {
  2006. stmt_ty p;
  2007. if (!name) {
  2008. PyErr_SetString(PyExc_ValueError,
  2009. "field 'name' is required for FunctionDef");
  2010. return NULL;
  2011. }
  2012. if (!args) {
  2013. PyErr_SetString(PyExc_ValueError,
  2014. "field 'args' is required for FunctionDef");
  2015. return NULL;
  2016. }
  2017. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2018. if (!p)
  2019. return NULL;
  2020. p->kind = FunctionDef_kind;
  2021. p->v.FunctionDef.name = name;
  2022. p->v.FunctionDef.args = args;
  2023. p->v.FunctionDef.body = body;
  2024. p->v.FunctionDef.decorator_list = decorator_list;
  2025. p->v.FunctionDef.returns = returns;
  2026. p->v.FunctionDef.type_comment = type_comment;
  2027. p->v.FunctionDef.type_params = type_params;
  2028. p->lineno = lineno;
  2029. p->col_offset = col_offset;
  2030. p->end_lineno = end_lineno;
  2031. p->end_col_offset = end_col_offset;
  2032. return p;
  2033. }
  2034. stmt_ty
  2035. _PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
  2036. body, asdl_expr_seq * decorator_list, expr_ty returns,
  2037. string type_comment, asdl_type_param_seq * type_params,
  2038. int lineno, int col_offset, int end_lineno, int
  2039. end_col_offset, PyArena *arena)
  2040. {
  2041. stmt_ty p;
  2042. if (!name) {
  2043. PyErr_SetString(PyExc_ValueError,
  2044. "field 'name' is required for AsyncFunctionDef");
  2045. return NULL;
  2046. }
  2047. if (!args) {
  2048. PyErr_SetString(PyExc_ValueError,
  2049. "field 'args' is required for AsyncFunctionDef");
  2050. return NULL;
  2051. }
  2052. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2053. if (!p)
  2054. return NULL;
  2055. p->kind = AsyncFunctionDef_kind;
  2056. p->v.AsyncFunctionDef.name = name;
  2057. p->v.AsyncFunctionDef.args = args;
  2058. p->v.AsyncFunctionDef.body = body;
  2059. p->v.AsyncFunctionDef.decorator_list = decorator_list;
  2060. p->v.AsyncFunctionDef.returns = returns;
  2061. p->v.AsyncFunctionDef.type_comment = type_comment;
  2062. p->v.AsyncFunctionDef.type_params = type_params;
  2063. p->lineno = lineno;
  2064. p->col_offset = col_offset;
  2065. p->end_lineno = end_lineno;
  2066. p->end_col_offset = end_col_offset;
  2067. return p;
  2068. }
  2069. stmt_ty
  2070. _PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
  2071. keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
  2072. asdl_type_param_seq * type_params, int lineno, int col_offset,
  2073. int end_lineno, int end_col_offset, PyArena *arena)
  2074. {
  2075. stmt_ty p;
  2076. if (!name) {
  2077. PyErr_SetString(PyExc_ValueError,
  2078. "field 'name' is required for ClassDef");
  2079. return NULL;
  2080. }
  2081. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2082. if (!p)
  2083. return NULL;
  2084. p->kind = ClassDef_kind;
  2085. p->v.ClassDef.name = name;
  2086. p->v.ClassDef.bases = bases;
  2087. p->v.ClassDef.keywords = keywords;
  2088. p->v.ClassDef.body = body;
  2089. p->v.ClassDef.decorator_list = decorator_list;
  2090. p->v.ClassDef.type_params = type_params;
  2091. p->lineno = lineno;
  2092. p->col_offset = col_offset;
  2093. p->end_lineno = end_lineno;
  2094. p->end_col_offset = end_col_offset;
  2095. return p;
  2096. }
  2097. stmt_ty
  2098. _PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2099. end_col_offset, PyArena *arena)
  2100. {
  2101. stmt_ty p;
  2102. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2103. if (!p)
  2104. return NULL;
  2105. p->kind = Return_kind;
  2106. p->v.Return.value = value;
  2107. p->lineno = lineno;
  2108. p->col_offset = col_offset;
  2109. p->end_lineno = end_lineno;
  2110. p->end_col_offset = end_col_offset;
  2111. return p;
  2112. }
  2113. stmt_ty
  2114. _PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
  2115. end_lineno, int end_col_offset, PyArena *arena)
  2116. {
  2117. stmt_ty p;
  2118. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2119. if (!p)
  2120. return NULL;
  2121. p->kind = Delete_kind;
  2122. p->v.Delete.targets = targets;
  2123. p->lineno = lineno;
  2124. p->col_offset = col_offset;
  2125. p->end_lineno = end_lineno;
  2126. p->end_col_offset = end_col_offset;
  2127. return p;
  2128. }
  2129. stmt_ty
  2130. _PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
  2131. lineno, int col_offset, int end_lineno, int end_col_offset,
  2132. PyArena *arena)
  2133. {
  2134. stmt_ty p;
  2135. if (!value) {
  2136. PyErr_SetString(PyExc_ValueError,
  2137. "field 'value' is required for Assign");
  2138. return NULL;
  2139. }
  2140. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2141. if (!p)
  2142. return NULL;
  2143. p->kind = Assign_kind;
  2144. p->v.Assign.targets = targets;
  2145. p->v.Assign.value = value;
  2146. p->v.Assign.type_comment = type_comment;
  2147. p->lineno = lineno;
  2148. p->col_offset = col_offset;
  2149. p->end_lineno = end_lineno;
  2150. p->end_col_offset = end_col_offset;
  2151. return p;
  2152. }
  2153. stmt_ty
  2154. _PyAST_TypeAlias(expr_ty name, asdl_type_param_seq * type_params, expr_ty
  2155. value, int lineno, int col_offset, int end_lineno, int
  2156. end_col_offset, PyArena *arena)
  2157. {
  2158. stmt_ty p;
  2159. if (!name) {
  2160. PyErr_SetString(PyExc_ValueError,
  2161. "field 'name' is required for TypeAlias");
  2162. return NULL;
  2163. }
  2164. if (!value) {
  2165. PyErr_SetString(PyExc_ValueError,
  2166. "field 'value' is required for TypeAlias");
  2167. return NULL;
  2168. }
  2169. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2170. if (!p)
  2171. return NULL;
  2172. p->kind = TypeAlias_kind;
  2173. p->v.TypeAlias.name = name;
  2174. p->v.TypeAlias.type_params = type_params;
  2175. p->v.TypeAlias.value = value;
  2176. p->lineno = lineno;
  2177. p->col_offset = col_offset;
  2178. p->end_lineno = end_lineno;
  2179. p->end_col_offset = end_col_offset;
  2180. return p;
  2181. }
  2182. stmt_ty
  2183. _PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
  2184. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2185. {
  2186. stmt_ty p;
  2187. if (!target) {
  2188. PyErr_SetString(PyExc_ValueError,
  2189. "field 'target' is required for AugAssign");
  2190. return NULL;
  2191. }
  2192. if (!op) {
  2193. PyErr_SetString(PyExc_ValueError,
  2194. "field 'op' is required for AugAssign");
  2195. return NULL;
  2196. }
  2197. if (!value) {
  2198. PyErr_SetString(PyExc_ValueError,
  2199. "field 'value' is required for AugAssign");
  2200. return NULL;
  2201. }
  2202. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2203. if (!p)
  2204. return NULL;
  2205. p->kind = AugAssign_kind;
  2206. p->v.AugAssign.target = target;
  2207. p->v.AugAssign.op = op;
  2208. p->v.AugAssign.value = value;
  2209. p->lineno = lineno;
  2210. p->col_offset = col_offset;
  2211. p->end_lineno = end_lineno;
  2212. p->end_col_offset = end_col_offset;
  2213. return p;
  2214. }
  2215. stmt_ty
  2216. _PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
  2217. int lineno, int col_offset, int end_lineno, int
  2218. end_col_offset, PyArena *arena)
  2219. {
  2220. stmt_ty p;
  2221. if (!target) {
  2222. PyErr_SetString(PyExc_ValueError,
  2223. "field 'target' is required for AnnAssign");
  2224. return NULL;
  2225. }
  2226. if (!annotation) {
  2227. PyErr_SetString(PyExc_ValueError,
  2228. "field 'annotation' is required for AnnAssign");
  2229. return NULL;
  2230. }
  2231. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2232. if (!p)
  2233. return NULL;
  2234. p->kind = AnnAssign_kind;
  2235. p->v.AnnAssign.target = target;
  2236. p->v.AnnAssign.annotation = annotation;
  2237. p->v.AnnAssign.value = value;
  2238. p->v.AnnAssign.simple = simple;
  2239. p->lineno = lineno;
  2240. p->col_offset = col_offset;
  2241. p->end_lineno = end_lineno;
  2242. p->end_col_offset = end_col_offset;
  2243. return p;
  2244. }
  2245. stmt_ty
  2246. _PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
  2247. orelse, string type_comment, int lineno, int col_offset, int
  2248. end_lineno, int end_col_offset, PyArena *arena)
  2249. {
  2250. stmt_ty p;
  2251. if (!target) {
  2252. PyErr_SetString(PyExc_ValueError,
  2253. "field 'target' is required for For");
  2254. return NULL;
  2255. }
  2256. if (!iter) {
  2257. PyErr_SetString(PyExc_ValueError,
  2258. "field 'iter' is required for For");
  2259. return NULL;
  2260. }
  2261. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2262. if (!p)
  2263. return NULL;
  2264. p->kind = For_kind;
  2265. p->v.For.target = target;
  2266. p->v.For.iter = iter;
  2267. p->v.For.body = body;
  2268. p->v.For.orelse = orelse;
  2269. p->v.For.type_comment = type_comment;
  2270. p->lineno = lineno;
  2271. p->col_offset = col_offset;
  2272. p->end_lineno = end_lineno;
  2273. p->end_col_offset = end_col_offset;
  2274. return p;
  2275. }
  2276. stmt_ty
  2277. _PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
  2278. asdl_stmt_seq * orelse, string type_comment, int lineno, int
  2279. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2280. {
  2281. stmt_ty p;
  2282. if (!target) {
  2283. PyErr_SetString(PyExc_ValueError,
  2284. "field 'target' is required for AsyncFor");
  2285. return NULL;
  2286. }
  2287. if (!iter) {
  2288. PyErr_SetString(PyExc_ValueError,
  2289. "field 'iter' is required for AsyncFor");
  2290. return NULL;
  2291. }
  2292. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2293. if (!p)
  2294. return NULL;
  2295. p->kind = AsyncFor_kind;
  2296. p->v.AsyncFor.target = target;
  2297. p->v.AsyncFor.iter = iter;
  2298. p->v.AsyncFor.body = body;
  2299. p->v.AsyncFor.orelse = orelse;
  2300. p->v.AsyncFor.type_comment = type_comment;
  2301. p->lineno = lineno;
  2302. p->col_offset = col_offset;
  2303. p->end_lineno = end_lineno;
  2304. p->end_col_offset = end_col_offset;
  2305. return p;
  2306. }
  2307. stmt_ty
  2308. _PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
  2309. lineno, int col_offset, int end_lineno, int end_col_offset,
  2310. PyArena *arena)
  2311. {
  2312. stmt_ty p;
  2313. if (!test) {
  2314. PyErr_SetString(PyExc_ValueError,
  2315. "field 'test' is required for While");
  2316. return NULL;
  2317. }
  2318. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2319. if (!p)
  2320. return NULL;
  2321. p->kind = While_kind;
  2322. p->v.While.test = test;
  2323. p->v.While.body = body;
  2324. p->v.While.orelse = orelse;
  2325. p->lineno = lineno;
  2326. p->col_offset = col_offset;
  2327. p->end_lineno = end_lineno;
  2328. p->end_col_offset = end_col_offset;
  2329. return p;
  2330. }
  2331. stmt_ty
  2332. _PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
  2333. lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
  2334. *arena)
  2335. {
  2336. stmt_ty p;
  2337. if (!test) {
  2338. PyErr_SetString(PyExc_ValueError,
  2339. "field 'test' is required for If");
  2340. return NULL;
  2341. }
  2342. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2343. if (!p)
  2344. return NULL;
  2345. p->kind = If_kind;
  2346. p->v.If.test = test;
  2347. p->v.If.body = body;
  2348. p->v.If.orelse = orelse;
  2349. p->lineno = lineno;
  2350. p->col_offset = col_offset;
  2351. p->end_lineno = end_lineno;
  2352. p->end_col_offset = end_col_offset;
  2353. return p;
  2354. }
  2355. stmt_ty
  2356. _PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
  2357. type_comment, int lineno, int col_offset, int end_lineno, int
  2358. end_col_offset, PyArena *arena)
  2359. {
  2360. stmt_ty p;
  2361. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2362. if (!p)
  2363. return NULL;
  2364. p->kind = With_kind;
  2365. p->v.With.items = items;
  2366. p->v.With.body = body;
  2367. p->v.With.type_comment = type_comment;
  2368. p->lineno = lineno;
  2369. p->col_offset = col_offset;
  2370. p->end_lineno = end_lineno;
  2371. p->end_col_offset = end_col_offset;
  2372. return p;
  2373. }
  2374. stmt_ty
  2375. _PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
  2376. type_comment, int lineno, int col_offset, int end_lineno, int
  2377. end_col_offset, PyArena *arena)
  2378. {
  2379. stmt_ty p;
  2380. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2381. if (!p)
  2382. return NULL;
  2383. p->kind = AsyncWith_kind;
  2384. p->v.AsyncWith.items = items;
  2385. p->v.AsyncWith.body = body;
  2386. p->v.AsyncWith.type_comment = type_comment;
  2387. p->lineno = lineno;
  2388. p->col_offset = col_offset;
  2389. p->end_lineno = end_lineno;
  2390. p->end_col_offset = end_col_offset;
  2391. return p;
  2392. }
  2393. stmt_ty
  2394. _PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
  2395. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2396. {
  2397. stmt_ty p;
  2398. if (!subject) {
  2399. PyErr_SetString(PyExc_ValueError,
  2400. "field 'subject' is required for Match");
  2401. return NULL;
  2402. }
  2403. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2404. if (!p)
  2405. return NULL;
  2406. p->kind = Match_kind;
  2407. p->v.Match.subject = subject;
  2408. p->v.Match.cases = cases;
  2409. p->lineno = lineno;
  2410. p->col_offset = col_offset;
  2411. p->end_lineno = end_lineno;
  2412. p->end_col_offset = end_col_offset;
  2413. return p;
  2414. }
  2415. stmt_ty
  2416. _PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
  2417. end_lineno, int end_col_offset, PyArena *arena)
  2418. {
  2419. stmt_ty p;
  2420. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2421. if (!p)
  2422. return NULL;
  2423. p->kind = Raise_kind;
  2424. p->v.Raise.exc = exc;
  2425. p->v.Raise.cause = cause;
  2426. p->lineno = lineno;
  2427. p->col_offset = col_offset;
  2428. p->end_lineno = end_lineno;
  2429. p->end_col_offset = end_col_offset;
  2430. return p;
  2431. }
  2432. stmt_ty
  2433. _PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
  2434. asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
  2435. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2436. {
  2437. stmt_ty p;
  2438. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2439. if (!p)
  2440. return NULL;
  2441. p->kind = Try_kind;
  2442. p->v.Try.body = body;
  2443. p->v.Try.handlers = handlers;
  2444. p->v.Try.orelse = orelse;
  2445. p->v.Try.finalbody = finalbody;
  2446. p->lineno = lineno;
  2447. p->col_offset = col_offset;
  2448. p->end_lineno = end_lineno;
  2449. p->end_col_offset = end_col_offset;
  2450. return p;
  2451. }
  2452. stmt_ty
  2453. _PyAST_TryStar(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
  2454. asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
  2455. int col_offset, int end_lineno, int end_col_offset, PyArena
  2456. *arena)
  2457. {
  2458. stmt_ty p;
  2459. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2460. if (!p)
  2461. return NULL;
  2462. p->kind = TryStar_kind;
  2463. p->v.TryStar.body = body;
  2464. p->v.TryStar.handlers = handlers;
  2465. p->v.TryStar.orelse = orelse;
  2466. p->v.TryStar.finalbody = finalbody;
  2467. p->lineno = lineno;
  2468. p->col_offset = col_offset;
  2469. p->end_lineno = end_lineno;
  2470. p->end_col_offset = end_col_offset;
  2471. return p;
  2472. }
  2473. stmt_ty
  2474. _PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
  2475. end_lineno, int end_col_offset, PyArena *arena)
  2476. {
  2477. stmt_ty p;
  2478. if (!test) {
  2479. PyErr_SetString(PyExc_ValueError,
  2480. "field 'test' is required for Assert");
  2481. return NULL;
  2482. }
  2483. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2484. if (!p)
  2485. return NULL;
  2486. p->kind = Assert_kind;
  2487. p->v.Assert.test = test;
  2488. p->v.Assert.msg = msg;
  2489. p->lineno = lineno;
  2490. p->col_offset = col_offset;
  2491. p->end_lineno = end_lineno;
  2492. p->end_col_offset = end_col_offset;
  2493. return p;
  2494. }
  2495. stmt_ty
  2496. _PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
  2497. end_lineno, int end_col_offset, PyArena *arena)
  2498. {
  2499. stmt_ty p;
  2500. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2501. if (!p)
  2502. return NULL;
  2503. p->kind = Import_kind;
  2504. p->v.Import.names = names;
  2505. p->lineno = lineno;
  2506. p->col_offset = col_offset;
  2507. p->end_lineno = end_lineno;
  2508. p->end_col_offset = end_col_offset;
  2509. return p;
  2510. }
  2511. stmt_ty
  2512. _PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
  2513. lineno, int col_offset, int end_lineno, int end_col_offset,
  2514. PyArena *arena)
  2515. {
  2516. stmt_ty p;
  2517. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2518. if (!p)
  2519. return NULL;
  2520. p->kind = ImportFrom_kind;
  2521. p->v.ImportFrom.module = module;
  2522. p->v.ImportFrom.names = names;
  2523. p->v.ImportFrom.level = level;
  2524. p->lineno = lineno;
  2525. p->col_offset = col_offset;
  2526. p->end_lineno = end_lineno;
  2527. p->end_col_offset = end_col_offset;
  2528. return p;
  2529. }
  2530. stmt_ty
  2531. _PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
  2532. end_lineno, int end_col_offset, PyArena *arena)
  2533. {
  2534. stmt_ty p;
  2535. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2536. if (!p)
  2537. return NULL;
  2538. p->kind = Global_kind;
  2539. p->v.Global.names = names;
  2540. p->lineno = lineno;
  2541. p->col_offset = col_offset;
  2542. p->end_lineno = end_lineno;
  2543. p->end_col_offset = end_col_offset;
  2544. return p;
  2545. }
  2546. stmt_ty
  2547. _PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
  2548. end_lineno, int end_col_offset, PyArena *arena)
  2549. {
  2550. stmt_ty p;
  2551. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2552. if (!p)
  2553. return NULL;
  2554. p->kind = Nonlocal_kind;
  2555. p->v.Nonlocal.names = names;
  2556. p->lineno = lineno;
  2557. p->col_offset = col_offset;
  2558. p->end_lineno = end_lineno;
  2559. p->end_col_offset = end_col_offset;
  2560. return p;
  2561. }
  2562. stmt_ty
  2563. _PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2564. end_col_offset, PyArena *arena)
  2565. {
  2566. stmt_ty p;
  2567. if (!value) {
  2568. PyErr_SetString(PyExc_ValueError,
  2569. "field 'value' is required for Expr");
  2570. return NULL;
  2571. }
  2572. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2573. if (!p)
  2574. return NULL;
  2575. p->kind = Expr_kind;
  2576. p->v.Expr.value = value;
  2577. p->lineno = lineno;
  2578. p->col_offset = col_offset;
  2579. p->end_lineno = end_lineno;
  2580. p->end_col_offset = end_col_offset;
  2581. return p;
  2582. }
  2583. stmt_ty
  2584. _PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
  2585. PyArena *arena)
  2586. {
  2587. stmt_ty p;
  2588. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2589. if (!p)
  2590. return NULL;
  2591. p->kind = Pass_kind;
  2592. p->lineno = lineno;
  2593. p->col_offset = col_offset;
  2594. p->end_lineno = end_lineno;
  2595. p->end_col_offset = end_col_offset;
  2596. return p;
  2597. }
  2598. stmt_ty
  2599. _PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
  2600. PyArena *arena)
  2601. {
  2602. stmt_ty p;
  2603. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2604. if (!p)
  2605. return NULL;
  2606. p->kind = Break_kind;
  2607. p->lineno = lineno;
  2608. p->col_offset = col_offset;
  2609. p->end_lineno = end_lineno;
  2610. p->end_col_offset = end_col_offset;
  2611. return p;
  2612. }
  2613. stmt_ty
  2614. _PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
  2615. PyArena *arena)
  2616. {
  2617. stmt_ty p;
  2618. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2619. if (!p)
  2620. return NULL;
  2621. p->kind = Continue_kind;
  2622. p->lineno = lineno;
  2623. p->col_offset = col_offset;
  2624. p->end_lineno = end_lineno;
  2625. p->end_col_offset = end_col_offset;
  2626. return p;
  2627. }
  2628. expr_ty
  2629. _PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
  2630. int end_lineno, int end_col_offset, PyArena *arena)
  2631. {
  2632. expr_ty p;
  2633. if (!op) {
  2634. PyErr_SetString(PyExc_ValueError,
  2635. "field 'op' is required for BoolOp");
  2636. return NULL;
  2637. }
  2638. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2639. if (!p)
  2640. return NULL;
  2641. p->kind = BoolOp_kind;
  2642. p->v.BoolOp.op = op;
  2643. p->v.BoolOp.values = values;
  2644. p->lineno = lineno;
  2645. p->col_offset = col_offset;
  2646. p->end_lineno = end_lineno;
  2647. p->end_col_offset = end_col_offset;
  2648. return p;
  2649. }
  2650. expr_ty
  2651. _PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
  2652. end_lineno, int end_col_offset, PyArena *arena)
  2653. {
  2654. expr_ty p;
  2655. if (!target) {
  2656. PyErr_SetString(PyExc_ValueError,
  2657. "field 'target' is required for NamedExpr");
  2658. return NULL;
  2659. }
  2660. if (!value) {
  2661. PyErr_SetString(PyExc_ValueError,
  2662. "field 'value' is required for NamedExpr");
  2663. return NULL;
  2664. }
  2665. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2666. if (!p)
  2667. return NULL;
  2668. p->kind = NamedExpr_kind;
  2669. p->v.NamedExpr.target = target;
  2670. p->v.NamedExpr.value = value;
  2671. p->lineno = lineno;
  2672. p->col_offset = col_offset;
  2673. p->end_lineno = end_lineno;
  2674. p->end_col_offset = end_col_offset;
  2675. return p;
  2676. }
  2677. expr_ty
  2678. _PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
  2679. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2680. {
  2681. expr_ty p;
  2682. if (!left) {
  2683. PyErr_SetString(PyExc_ValueError,
  2684. "field 'left' is required for BinOp");
  2685. return NULL;
  2686. }
  2687. if (!op) {
  2688. PyErr_SetString(PyExc_ValueError,
  2689. "field 'op' is required for BinOp");
  2690. return NULL;
  2691. }
  2692. if (!right) {
  2693. PyErr_SetString(PyExc_ValueError,
  2694. "field 'right' is required for BinOp");
  2695. return NULL;
  2696. }
  2697. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2698. if (!p)
  2699. return NULL;
  2700. p->kind = BinOp_kind;
  2701. p->v.BinOp.left = left;
  2702. p->v.BinOp.op = op;
  2703. p->v.BinOp.right = right;
  2704. p->lineno = lineno;
  2705. p->col_offset = col_offset;
  2706. p->end_lineno = end_lineno;
  2707. p->end_col_offset = end_col_offset;
  2708. return p;
  2709. }
  2710. expr_ty
  2711. _PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
  2712. end_lineno, int end_col_offset, PyArena *arena)
  2713. {
  2714. expr_ty p;
  2715. if (!op) {
  2716. PyErr_SetString(PyExc_ValueError,
  2717. "field 'op' is required for UnaryOp");
  2718. return NULL;
  2719. }
  2720. if (!operand) {
  2721. PyErr_SetString(PyExc_ValueError,
  2722. "field 'operand' is required for UnaryOp");
  2723. return NULL;
  2724. }
  2725. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2726. if (!p)
  2727. return NULL;
  2728. p->kind = UnaryOp_kind;
  2729. p->v.UnaryOp.op = op;
  2730. p->v.UnaryOp.operand = operand;
  2731. p->lineno = lineno;
  2732. p->col_offset = col_offset;
  2733. p->end_lineno = end_lineno;
  2734. p->end_col_offset = end_col_offset;
  2735. return p;
  2736. }
  2737. expr_ty
  2738. _PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
  2739. end_lineno, int end_col_offset, PyArena *arena)
  2740. {
  2741. expr_ty p;
  2742. if (!args) {
  2743. PyErr_SetString(PyExc_ValueError,
  2744. "field 'args' is required for Lambda");
  2745. return NULL;
  2746. }
  2747. if (!body) {
  2748. PyErr_SetString(PyExc_ValueError,
  2749. "field 'body' is required for Lambda");
  2750. return NULL;
  2751. }
  2752. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2753. if (!p)
  2754. return NULL;
  2755. p->kind = Lambda_kind;
  2756. p->v.Lambda.args = args;
  2757. p->v.Lambda.body = body;
  2758. p->lineno = lineno;
  2759. p->col_offset = col_offset;
  2760. p->end_lineno = end_lineno;
  2761. p->end_col_offset = end_col_offset;
  2762. return p;
  2763. }
  2764. expr_ty
  2765. _PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
  2766. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2767. {
  2768. expr_ty p;
  2769. if (!test) {
  2770. PyErr_SetString(PyExc_ValueError,
  2771. "field 'test' is required for IfExp");
  2772. return NULL;
  2773. }
  2774. if (!body) {
  2775. PyErr_SetString(PyExc_ValueError,
  2776. "field 'body' is required for IfExp");
  2777. return NULL;
  2778. }
  2779. if (!orelse) {
  2780. PyErr_SetString(PyExc_ValueError,
  2781. "field 'orelse' is required for IfExp");
  2782. return NULL;
  2783. }
  2784. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2785. if (!p)
  2786. return NULL;
  2787. p->kind = IfExp_kind;
  2788. p->v.IfExp.test = test;
  2789. p->v.IfExp.body = body;
  2790. p->v.IfExp.orelse = orelse;
  2791. p->lineno = lineno;
  2792. p->col_offset = col_offset;
  2793. p->end_lineno = end_lineno;
  2794. p->end_col_offset = end_col_offset;
  2795. return p;
  2796. }
  2797. expr_ty
  2798. _PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
  2799. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2800. {
  2801. expr_ty p;
  2802. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2803. if (!p)
  2804. return NULL;
  2805. p->kind = Dict_kind;
  2806. p->v.Dict.keys = keys;
  2807. p->v.Dict.values = values;
  2808. p->lineno = lineno;
  2809. p->col_offset = col_offset;
  2810. p->end_lineno = end_lineno;
  2811. p->end_col_offset = end_col_offset;
  2812. return p;
  2813. }
  2814. expr_ty
  2815. _PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
  2816. int end_col_offset, PyArena *arena)
  2817. {
  2818. expr_ty p;
  2819. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2820. if (!p)
  2821. return NULL;
  2822. p->kind = Set_kind;
  2823. p->v.Set.elts = elts;
  2824. p->lineno = lineno;
  2825. p->col_offset = col_offset;
  2826. p->end_lineno = end_lineno;
  2827. p->end_col_offset = end_col_offset;
  2828. return p;
  2829. }
  2830. expr_ty
  2831. _PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
  2832. int col_offset, int end_lineno, int end_col_offset, PyArena
  2833. *arena)
  2834. {
  2835. expr_ty p;
  2836. if (!elt) {
  2837. PyErr_SetString(PyExc_ValueError,
  2838. "field 'elt' is required for ListComp");
  2839. return NULL;
  2840. }
  2841. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2842. if (!p)
  2843. return NULL;
  2844. p->kind = ListComp_kind;
  2845. p->v.ListComp.elt = elt;
  2846. p->v.ListComp.generators = generators;
  2847. p->lineno = lineno;
  2848. p->col_offset = col_offset;
  2849. p->end_lineno = end_lineno;
  2850. p->end_col_offset = end_col_offset;
  2851. return p;
  2852. }
  2853. expr_ty
  2854. _PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
  2855. int col_offset, int end_lineno, int end_col_offset, PyArena
  2856. *arena)
  2857. {
  2858. expr_ty p;
  2859. if (!elt) {
  2860. PyErr_SetString(PyExc_ValueError,
  2861. "field 'elt' is required for SetComp");
  2862. return NULL;
  2863. }
  2864. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2865. if (!p)
  2866. return NULL;
  2867. p->kind = SetComp_kind;
  2868. p->v.SetComp.elt = elt;
  2869. p->v.SetComp.generators = generators;
  2870. p->lineno = lineno;
  2871. p->col_offset = col_offset;
  2872. p->end_lineno = end_lineno;
  2873. p->end_col_offset = end_col_offset;
  2874. return p;
  2875. }
  2876. expr_ty
  2877. _PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
  2878. generators, int lineno, int col_offset, int end_lineno, int
  2879. end_col_offset, PyArena *arena)
  2880. {
  2881. expr_ty p;
  2882. if (!key) {
  2883. PyErr_SetString(PyExc_ValueError,
  2884. "field 'key' is required for DictComp");
  2885. return NULL;
  2886. }
  2887. if (!value) {
  2888. PyErr_SetString(PyExc_ValueError,
  2889. "field 'value' is required for DictComp");
  2890. return NULL;
  2891. }
  2892. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2893. if (!p)
  2894. return NULL;
  2895. p->kind = DictComp_kind;
  2896. p->v.DictComp.key = key;
  2897. p->v.DictComp.value = value;
  2898. p->v.DictComp.generators = generators;
  2899. p->lineno = lineno;
  2900. p->col_offset = col_offset;
  2901. p->end_lineno = end_lineno;
  2902. p->end_col_offset = end_col_offset;
  2903. return p;
  2904. }
  2905. expr_ty
  2906. _PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
  2907. lineno, int col_offset, int end_lineno, int end_col_offset,
  2908. PyArena *arena)
  2909. {
  2910. expr_ty p;
  2911. if (!elt) {
  2912. PyErr_SetString(PyExc_ValueError,
  2913. "field 'elt' is required for GeneratorExp");
  2914. return NULL;
  2915. }
  2916. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2917. if (!p)
  2918. return NULL;
  2919. p->kind = GeneratorExp_kind;
  2920. p->v.GeneratorExp.elt = elt;
  2921. p->v.GeneratorExp.generators = generators;
  2922. p->lineno = lineno;
  2923. p->col_offset = col_offset;
  2924. p->end_lineno = end_lineno;
  2925. p->end_col_offset = end_col_offset;
  2926. return p;
  2927. }
  2928. expr_ty
  2929. _PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2930. end_col_offset, PyArena *arena)
  2931. {
  2932. expr_ty p;
  2933. if (!value) {
  2934. PyErr_SetString(PyExc_ValueError,
  2935. "field 'value' is required for Await");
  2936. return NULL;
  2937. }
  2938. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2939. if (!p)
  2940. return NULL;
  2941. p->kind = Await_kind;
  2942. p->v.Await.value = value;
  2943. p->lineno = lineno;
  2944. p->col_offset = col_offset;
  2945. p->end_lineno = end_lineno;
  2946. p->end_col_offset = end_col_offset;
  2947. return p;
  2948. }
  2949. expr_ty
  2950. _PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2951. end_col_offset, PyArena *arena)
  2952. {
  2953. expr_ty p;
  2954. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2955. if (!p)
  2956. return NULL;
  2957. p->kind = Yield_kind;
  2958. p->v.Yield.value = value;
  2959. p->lineno = lineno;
  2960. p->col_offset = col_offset;
  2961. p->end_lineno = end_lineno;
  2962. p->end_col_offset = end_col_offset;
  2963. return p;
  2964. }
  2965. expr_ty
  2966. _PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2967. end_col_offset, PyArena *arena)
  2968. {
  2969. expr_ty p;
  2970. if (!value) {
  2971. PyErr_SetString(PyExc_ValueError,
  2972. "field 'value' is required for YieldFrom");
  2973. return NULL;
  2974. }
  2975. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2976. if (!p)
  2977. return NULL;
  2978. p->kind = YieldFrom_kind;
  2979. p->v.YieldFrom.value = value;
  2980. p->lineno = lineno;
  2981. p->col_offset = col_offset;
  2982. p->end_lineno = end_lineno;
  2983. p->end_col_offset = end_col_offset;
  2984. return p;
  2985. }
  2986. expr_ty
  2987. _PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
  2988. int lineno, int col_offset, int end_lineno, int end_col_offset,
  2989. PyArena *arena)
  2990. {
  2991. expr_ty p;
  2992. if (!left) {
  2993. PyErr_SetString(PyExc_ValueError,
  2994. "field 'left' is required for Compare");
  2995. return NULL;
  2996. }
  2997. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2998. if (!p)
  2999. return NULL;
  3000. p->kind = Compare_kind;
  3001. p->v.Compare.left = left;
  3002. p->v.Compare.ops = ops;
  3003. p->v.Compare.comparators = comparators;
  3004. p->lineno = lineno;
  3005. p->col_offset = col_offset;
  3006. p->end_lineno = end_lineno;
  3007. p->end_col_offset = end_col_offset;
  3008. return p;
  3009. }
  3010. expr_ty
  3011. _PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
  3012. int lineno, int col_offset, int end_lineno, int end_col_offset,
  3013. PyArena *arena)
  3014. {
  3015. expr_ty p;
  3016. if (!func) {
  3017. PyErr_SetString(PyExc_ValueError,
  3018. "field 'func' is required for Call");
  3019. return NULL;
  3020. }
  3021. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3022. if (!p)
  3023. return NULL;
  3024. p->kind = Call_kind;
  3025. p->v.Call.func = func;
  3026. p->v.Call.args = args;
  3027. p->v.Call.keywords = keywords;
  3028. p->lineno = lineno;
  3029. p->col_offset = col_offset;
  3030. p->end_lineno = end_lineno;
  3031. p->end_col_offset = end_col_offset;
  3032. return p;
  3033. }
  3034. expr_ty
  3035. _PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
  3036. lineno, int col_offset, int end_lineno, int
  3037. end_col_offset, PyArena *arena)
  3038. {
  3039. expr_ty p;
  3040. if (!value) {
  3041. PyErr_SetString(PyExc_ValueError,
  3042. "field 'value' is required for FormattedValue");
  3043. return NULL;
  3044. }
  3045. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3046. if (!p)
  3047. return NULL;
  3048. p->kind = FormattedValue_kind;
  3049. p->v.FormattedValue.value = value;
  3050. p->v.FormattedValue.conversion = conversion;
  3051. p->v.FormattedValue.format_spec = format_spec;
  3052. p->lineno = lineno;
  3053. p->col_offset = col_offset;
  3054. p->end_lineno = end_lineno;
  3055. p->end_col_offset = end_col_offset;
  3056. return p;
  3057. }
  3058. expr_ty
  3059. _PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
  3060. end_lineno, int end_col_offset, PyArena *arena)
  3061. {
  3062. expr_ty p;
  3063. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3064. if (!p)
  3065. return NULL;
  3066. p->kind = JoinedStr_kind;
  3067. p->v.JoinedStr.values = values;
  3068. p->lineno = lineno;
  3069. p->col_offset = col_offset;
  3070. p->end_lineno = end_lineno;
  3071. p->end_col_offset = end_col_offset;
  3072. return p;
  3073. }
  3074. expr_ty
  3075. _PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
  3076. end_lineno, int end_col_offset, PyArena *arena)
  3077. {
  3078. expr_ty p;
  3079. if (!value) {
  3080. PyErr_SetString(PyExc_ValueError,
  3081. "field 'value' is required for Constant");
  3082. return NULL;
  3083. }
  3084. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3085. if (!p)
  3086. return NULL;
  3087. p->kind = Constant_kind;
  3088. p->v.Constant.value = value;
  3089. p->v.Constant.kind = kind;
  3090. p->lineno = lineno;
  3091. p->col_offset = col_offset;
  3092. p->end_lineno = end_lineno;
  3093. p->end_col_offset = end_col_offset;
  3094. return p;
  3095. }
  3096. expr_ty
  3097. _PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
  3098. lineno, int col_offset, int end_lineno, int end_col_offset,
  3099. PyArena *arena)
  3100. {
  3101. expr_ty p;
  3102. if (!value) {
  3103. PyErr_SetString(PyExc_ValueError,
  3104. "field 'value' is required for Attribute");
  3105. return NULL;
  3106. }
  3107. if (!attr) {
  3108. PyErr_SetString(PyExc_ValueError,
  3109. "field 'attr' is required for Attribute");
  3110. return NULL;
  3111. }
  3112. if (!ctx) {
  3113. PyErr_SetString(PyExc_ValueError,
  3114. "field 'ctx' is required for Attribute");
  3115. return NULL;
  3116. }
  3117. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3118. if (!p)
  3119. return NULL;
  3120. p->kind = Attribute_kind;
  3121. p->v.Attribute.value = value;
  3122. p->v.Attribute.attr = attr;
  3123. p->v.Attribute.ctx = ctx;
  3124. p->lineno = lineno;
  3125. p->col_offset = col_offset;
  3126. p->end_lineno = end_lineno;
  3127. p->end_col_offset = end_col_offset;
  3128. return p;
  3129. }
  3130. expr_ty
  3131. _PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
  3132. int col_offset, int end_lineno, int end_col_offset, PyArena
  3133. *arena)
  3134. {
  3135. expr_ty p;
  3136. if (!value) {
  3137. PyErr_SetString(PyExc_ValueError,
  3138. "field 'value' is required for Subscript");
  3139. return NULL;
  3140. }
  3141. if (!slice) {
  3142. PyErr_SetString(PyExc_ValueError,
  3143. "field 'slice' is required for Subscript");
  3144. return NULL;
  3145. }
  3146. if (!ctx) {
  3147. PyErr_SetString(PyExc_ValueError,
  3148. "field 'ctx' is required for Subscript");
  3149. return NULL;
  3150. }
  3151. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3152. if (!p)
  3153. return NULL;
  3154. p->kind = Subscript_kind;
  3155. p->v.Subscript.value = value;
  3156. p->v.Subscript.slice = slice;
  3157. p->v.Subscript.ctx = ctx;
  3158. p->lineno = lineno;
  3159. p->col_offset = col_offset;
  3160. p->end_lineno = end_lineno;
  3161. p->end_col_offset = end_col_offset;
  3162. return p;
  3163. }
  3164. expr_ty
  3165. _PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
  3166. int end_lineno, int end_col_offset, PyArena *arena)
  3167. {
  3168. expr_ty p;
  3169. if (!value) {
  3170. PyErr_SetString(PyExc_ValueError,
  3171. "field 'value' is required for Starred");
  3172. return NULL;
  3173. }
  3174. if (!ctx) {
  3175. PyErr_SetString(PyExc_ValueError,
  3176. "field 'ctx' is required for Starred");
  3177. return NULL;
  3178. }
  3179. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3180. if (!p)
  3181. return NULL;
  3182. p->kind = Starred_kind;
  3183. p->v.Starred.value = value;
  3184. p->v.Starred.ctx = ctx;
  3185. p->lineno = lineno;
  3186. p->col_offset = col_offset;
  3187. p->end_lineno = end_lineno;
  3188. p->end_col_offset = end_col_offset;
  3189. return p;
  3190. }
  3191. expr_ty
  3192. _PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
  3193. end_lineno, int end_col_offset, PyArena *arena)
  3194. {
  3195. expr_ty p;
  3196. if (!id) {
  3197. PyErr_SetString(PyExc_ValueError,
  3198. "field 'id' is required for Name");
  3199. return NULL;
  3200. }
  3201. if (!ctx) {
  3202. PyErr_SetString(PyExc_ValueError,
  3203. "field 'ctx' is required for Name");
  3204. return NULL;
  3205. }
  3206. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3207. if (!p)
  3208. return NULL;
  3209. p->kind = Name_kind;
  3210. p->v.Name.id = id;
  3211. p->v.Name.ctx = ctx;
  3212. p->lineno = lineno;
  3213. p->col_offset = col_offset;
  3214. p->end_lineno = end_lineno;
  3215. p->end_col_offset = end_col_offset;
  3216. return p;
  3217. }
  3218. expr_ty
  3219. _PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
  3220. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  3221. {
  3222. expr_ty p;
  3223. if (!ctx) {
  3224. PyErr_SetString(PyExc_ValueError,
  3225. "field 'ctx' is required for List");
  3226. return NULL;
  3227. }
  3228. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3229. if (!p)
  3230. return NULL;
  3231. p->kind = List_kind;
  3232. p->v.List.elts = elts;
  3233. p->v.List.ctx = ctx;
  3234. p->lineno = lineno;
  3235. p->col_offset = col_offset;
  3236. p->end_lineno = end_lineno;
  3237. p->end_col_offset = end_col_offset;
  3238. return p;
  3239. }
  3240. expr_ty
  3241. _PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
  3242. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  3243. {
  3244. expr_ty p;
  3245. if (!ctx) {
  3246. PyErr_SetString(PyExc_ValueError,
  3247. "field 'ctx' is required for Tuple");
  3248. return NULL;
  3249. }
  3250. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3251. if (!p)
  3252. return NULL;
  3253. p->kind = Tuple_kind;
  3254. p->v.Tuple.elts = elts;
  3255. p->v.Tuple.ctx = ctx;
  3256. p->lineno = lineno;
  3257. p->col_offset = col_offset;
  3258. p->end_lineno = end_lineno;
  3259. p->end_col_offset = end_col_offset;
  3260. return p;
  3261. }
  3262. expr_ty
  3263. _PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
  3264. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  3265. {
  3266. expr_ty p;
  3267. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3268. if (!p)
  3269. return NULL;
  3270. p->kind = Slice_kind;
  3271. p->v.Slice.lower = lower;
  3272. p->v.Slice.upper = upper;
  3273. p->v.Slice.step = step;
  3274. p->lineno = lineno;
  3275. p->col_offset = col_offset;
  3276. p->end_lineno = end_lineno;
  3277. p->end_col_offset = end_col_offset;
  3278. return p;
  3279. }
  3280. comprehension_ty
  3281. _PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
  3282. is_async, PyArena *arena)
  3283. {
  3284. comprehension_ty p;
  3285. if (!target) {
  3286. PyErr_SetString(PyExc_ValueError,
  3287. "field 'target' is required for comprehension");
  3288. return NULL;
  3289. }
  3290. if (!iter) {
  3291. PyErr_SetString(PyExc_ValueError,
  3292. "field 'iter' is required for comprehension");
  3293. return NULL;
  3294. }
  3295. p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
  3296. if (!p)
  3297. return NULL;
  3298. p->target = target;
  3299. p->iter = iter;
  3300. p->ifs = ifs;
  3301. p->is_async = is_async;
  3302. return p;
  3303. }
  3304. excepthandler_ty
  3305. _PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
  3306. lineno, int col_offset, int end_lineno, int
  3307. end_col_offset, PyArena *arena)
  3308. {
  3309. excepthandler_ty p;
  3310. p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
  3311. if (!p)
  3312. return NULL;
  3313. p->kind = ExceptHandler_kind;
  3314. p->v.ExceptHandler.type = type;
  3315. p->v.ExceptHandler.name = name;
  3316. p->v.ExceptHandler.body = body;
  3317. p->lineno = lineno;
  3318. p->col_offset = col_offset;
  3319. p->end_lineno = end_lineno;
  3320. p->end_col_offset = end_col_offset;
  3321. return p;
  3322. }
  3323. arguments_ty
  3324. _PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
  3325. vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
  3326. kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
  3327. *arena)
  3328. {
  3329. arguments_ty p;
  3330. p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
  3331. if (!p)
  3332. return NULL;
  3333. p->posonlyargs = posonlyargs;
  3334. p->args = args;
  3335. p->vararg = vararg;
  3336. p->kwonlyargs = kwonlyargs;
  3337. p->kw_defaults = kw_defaults;
  3338. p->kwarg = kwarg;
  3339. p->defaults = defaults;
  3340. return p;
  3341. }
  3342. arg_ty
  3343. _PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
  3344. int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  3345. {
  3346. arg_ty p;
  3347. if (!arg) {
  3348. PyErr_SetString(PyExc_ValueError,
  3349. "field 'arg' is required for arg");
  3350. return NULL;
  3351. }
  3352. p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
  3353. if (!p)
  3354. return NULL;
  3355. p->arg = arg;
  3356. p->annotation = annotation;
  3357. p->type_comment = type_comment;
  3358. p->lineno = lineno;
  3359. p->col_offset = col_offset;
  3360. p->end_lineno = end_lineno;
  3361. p->end_col_offset = end_col_offset;
  3362. return p;
  3363. }
  3364. keyword_ty
  3365. _PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
  3366. end_lineno, int end_col_offset, PyArena *arena)
  3367. {
  3368. keyword_ty p;
  3369. if (!value) {
  3370. PyErr_SetString(PyExc_ValueError,
  3371. "field 'value' is required for keyword");
  3372. return NULL;
  3373. }
  3374. p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
  3375. if (!p)
  3376. return NULL;
  3377. p->arg = arg;
  3378. p->value = value;
  3379. p->lineno = lineno;
  3380. p->col_offset = col_offset;
  3381. p->end_lineno = end_lineno;
  3382. p->end_col_offset = end_col_offset;
  3383. return p;
  3384. }
  3385. alias_ty
  3386. _PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
  3387. int end_lineno, int end_col_offset, PyArena *arena)
  3388. {
  3389. alias_ty p;
  3390. if (!name) {
  3391. PyErr_SetString(PyExc_ValueError,
  3392. "field 'name' is required for alias");
  3393. return NULL;
  3394. }
  3395. p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
  3396. if (!p)
  3397. return NULL;
  3398. p->name = name;
  3399. p->asname = asname;
  3400. p->lineno = lineno;
  3401. p->col_offset = col_offset;
  3402. p->end_lineno = end_lineno;
  3403. p->end_col_offset = end_col_offset;
  3404. return p;
  3405. }
  3406. withitem_ty
  3407. _PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
  3408. {
  3409. withitem_ty p;
  3410. if (!context_expr) {
  3411. PyErr_SetString(PyExc_ValueError,
  3412. "field 'context_expr' is required for withitem");
  3413. return NULL;
  3414. }
  3415. p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
  3416. if (!p)
  3417. return NULL;
  3418. p->context_expr = context_expr;
  3419. p->optional_vars = optional_vars;
  3420. return p;
  3421. }
  3422. match_case_ty
  3423. _PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
  3424. PyArena *arena)
  3425. {
  3426. match_case_ty p;
  3427. if (!pattern) {
  3428. PyErr_SetString(PyExc_ValueError,
  3429. "field 'pattern' is required for match_case");
  3430. return NULL;
  3431. }
  3432. p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
  3433. if (!p)
  3434. return NULL;
  3435. p->pattern = pattern;
  3436. p->guard = guard;
  3437. p->body = body;
  3438. return p;
  3439. }
  3440. pattern_ty
  3441. _PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
  3442. int end_col_offset, PyArena *arena)
  3443. {
  3444. pattern_ty p;
  3445. if (!value) {
  3446. PyErr_SetString(PyExc_ValueError,
  3447. "field 'value' is required for MatchValue");
  3448. return NULL;
  3449. }
  3450. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3451. if (!p)
  3452. return NULL;
  3453. p->kind = MatchValue_kind;
  3454. p->v.MatchValue.value = value;
  3455. p->lineno = lineno;
  3456. p->col_offset = col_offset;
  3457. p->end_lineno = end_lineno;
  3458. p->end_col_offset = end_col_offset;
  3459. return p;
  3460. }
  3461. pattern_ty
  3462. _PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
  3463. end_lineno, int end_col_offset, PyArena *arena)
  3464. {
  3465. pattern_ty p;
  3466. if (!value) {
  3467. PyErr_SetString(PyExc_ValueError,
  3468. "field 'value' is required for MatchSingleton");
  3469. return NULL;
  3470. }
  3471. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3472. if (!p)
  3473. return NULL;
  3474. p->kind = MatchSingleton_kind;
  3475. p->v.MatchSingleton.value = value;
  3476. p->lineno = lineno;
  3477. p->col_offset = col_offset;
  3478. p->end_lineno = end_lineno;
  3479. p->end_col_offset = end_col_offset;
  3480. return p;
  3481. }
  3482. pattern_ty
  3483. _PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
  3484. int end_lineno, int end_col_offset, PyArena *arena)
  3485. {
  3486. pattern_ty p;
  3487. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3488. if (!p)
  3489. return NULL;
  3490. p->kind = MatchSequence_kind;
  3491. p->v.MatchSequence.patterns = patterns;
  3492. p->lineno = lineno;
  3493. p->col_offset = col_offset;
  3494. p->end_lineno = end_lineno;
  3495. p->end_col_offset = end_col_offset;
  3496. return p;
  3497. }
  3498. pattern_ty
  3499. _PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
  3500. identifier rest, int lineno, int col_offset, int
  3501. end_lineno, int end_col_offset, PyArena *arena)
  3502. {
  3503. pattern_ty p;
  3504. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3505. if (!p)
  3506. return NULL;
  3507. p->kind = MatchMapping_kind;
  3508. p->v.MatchMapping.keys = keys;
  3509. p->v.MatchMapping.patterns = patterns;
  3510. p->v.MatchMapping.rest = rest;
  3511. p->lineno = lineno;
  3512. p->col_offset = col_offset;
  3513. p->end_lineno = end_lineno;
  3514. p->end_col_offset = end_col_offset;
  3515. return p;
  3516. }
  3517. pattern_ty
  3518. _PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
  3519. * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
  3520. col_offset, int end_lineno, int end_col_offset, PyArena
  3521. *arena)
  3522. {
  3523. pattern_ty p;
  3524. if (!cls) {
  3525. PyErr_SetString(PyExc_ValueError,
  3526. "field 'cls' is required for MatchClass");
  3527. return NULL;
  3528. }
  3529. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3530. if (!p)
  3531. return NULL;
  3532. p->kind = MatchClass_kind;
  3533. p->v.MatchClass.cls = cls;
  3534. p->v.MatchClass.patterns = patterns;
  3535. p->v.MatchClass.kwd_attrs = kwd_attrs;
  3536. p->v.MatchClass.kwd_patterns = kwd_patterns;
  3537. p->lineno = lineno;
  3538. p->col_offset = col_offset;
  3539. p->end_lineno = end_lineno;
  3540. p->end_col_offset = end_col_offset;
  3541. return p;
  3542. }
  3543. pattern_ty
  3544. _PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
  3545. int end_col_offset, PyArena *arena)
  3546. {
  3547. pattern_ty p;
  3548. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3549. if (!p)
  3550. return NULL;
  3551. p->kind = MatchStar_kind;
  3552. p->v.MatchStar.name = name;
  3553. p->lineno = lineno;
  3554. p->col_offset = col_offset;
  3555. p->end_lineno = end_lineno;
  3556. p->end_col_offset = end_col_offset;
  3557. return p;
  3558. }
  3559. pattern_ty
  3560. _PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
  3561. int end_lineno, int end_col_offset, PyArena *arena)
  3562. {
  3563. pattern_ty p;
  3564. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3565. if (!p)
  3566. return NULL;
  3567. p->kind = MatchAs_kind;
  3568. p->v.MatchAs.pattern = pattern;
  3569. p->v.MatchAs.name = name;
  3570. p->lineno = lineno;
  3571. p->col_offset = col_offset;
  3572. p->end_lineno = end_lineno;
  3573. p->end_col_offset = end_col_offset;
  3574. return p;
  3575. }
  3576. pattern_ty
  3577. _PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
  3578. end_lineno, int end_col_offset, PyArena *arena)
  3579. {
  3580. pattern_ty p;
  3581. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3582. if (!p)
  3583. return NULL;
  3584. p->kind = MatchOr_kind;
  3585. p->v.MatchOr.patterns = patterns;
  3586. p->lineno = lineno;
  3587. p->col_offset = col_offset;
  3588. p->end_lineno = end_lineno;
  3589. p->end_col_offset = end_col_offset;
  3590. return p;
  3591. }
  3592. type_ignore_ty
  3593. _PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
  3594. {
  3595. type_ignore_ty p;
  3596. if (!tag) {
  3597. PyErr_SetString(PyExc_ValueError,
  3598. "field 'tag' is required for TypeIgnore");
  3599. return NULL;
  3600. }
  3601. p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
  3602. if (!p)
  3603. return NULL;
  3604. p->kind = TypeIgnore_kind;
  3605. p->v.TypeIgnore.lineno = lineno;
  3606. p->v.TypeIgnore.tag = tag;
  3607. return p;
  3608. }
  3609. type_param_ty
  3610. _PyAST_TypeVar(identifier name, expr_ty bound, int lineno, int col_offset, int
  3611. end_lineno, int end_col_offset, PyArena *arena)
  3612. {
  3613. type_param_ty p;
  3614. if (!name) {
  3615. PyErr_SetString(PyExc_ValueError,
  3616. "field 'name' is required for TypeVar");
  3617. return NULL;
  3618. }
  3619. p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
  3620. if (!p)
  3621. return NULL;
  3622. p->kind = TypeVar_kind;
  3623. p->v.TypeVar.name = name;
  3624. p->v.TypeVar.bound = bound;
  3625. p->lineno = lineno;
  3626. p->col_offset = col_offset;
  3627. p->end_lineno = end_lineno;
  3628. p->end_col_offset = end_col_offset;
  3629. return p;
  3630. }
  3631. type_param_ty
  3632. _PyAST_ParamSpec(identifier name, int lineno, int col_offset, int end_lineno,
  3633. int end_col_offset, PyArena *arena)
  3634. {
  3635. type_param_ty p;
  3636. if (!name) {
  3637. PyErr_SetString(PyExc_ValueError,
  3638. "field 'name' is required for ParamSpec");
  3639. return NULL;
  3640. }
  3641. p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
  3642. if (!p)
  3643. return NULL;
  3644. p->kind = ParamSpec_kind;
  3645. p->v.ParamSpec.name = name;
  3646. p->lineno = lineno;
  3647. p->col_offset = col_offset;
  3648. p->end_lineno = end_lineno;
  3649. p->end_col_offset = end_col_offset;
  3650. return p;
  3651. }
  3652. type_param_ty
  3653. _PyAST_TypeVarTuple(identifier name, int lineno, int col_offset, int
  3654. end_lineno, int end_col_offset, PyArena *arena)
  3655. {
  3656. type_param_ty p;
  3657. if (!name) {
  3658. PyErr_SetString(PyExc_ValueError,
  3659. "field 'name' is required for TypeVarTuple");
  3660. return NULL;
  3661. }
  3662. p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
  3663. if (!p)
  3664. return NULL;
  3665. p->kind = TypeVarTuple_kind;
  3666. p->v.TypeVarTuple.name = name;
  3667. p->lineno = lineno;
  3668. p->col_offset = col_offset;
  3669. p->end_lineno = end_lineno;
  3670. p->end_col_offset = end_col_offset;
  3671. return p;
  3672. }
  3673. PyObject*
  3674. ast2obj_mod(struct ast_state *state, struct validator *vstate, void* _o)
  3675. {
  3676. mod_ty o = (mod_ty)_o;
  3677. PyObject *result = NULL, *value = NULL;
  3678. PyTypeObject *tp;
  3679. if (!o) {
  3680. Py_RETURN_NONE;
  3681. }
  3682. if (++vstate->recursion_depth > vstate->recursion_limit) {
  3683. PyErr_SetString(PyExc_RecursionError,
  3684. "maximum recursion depth exceeded during ast construction");
  3685. return 0;
  3686. }
  3687. switch (o->kind) {
  3688. case Module_kind:
  3689. tp = (PyTypeObject *)state->Module_type;
  3690. result = PyType_GenericNew(tp, NULL, NULL);
  3691. if (!result) goto failed;
  3692. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Module.body,
  3693. ast2obj_stmt);
  3694. if (!value) goto failed;
  3695. if (PyObject_SetAttr(result, state->body, value) == -1)
  3696. goto failed;
  3697. Py_DECREF(value);
  3698. value = ast2obj_list(state, vstate,
  3699. (asdl_seq*)o->v.Module.type_ignores,
  3700. ast2obj_type_ignore);
  3701. if (!value) goto failed;
  3702. if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
  3703. goto failed;
  3704. Py_DECREF(value);
  3705. break;
  3706. case Interactive_kind:
  3707. tp = (PyTypeObject *)state->Interactive_type;
  3708. result = PyType_GenericNew(tp, NULL, NULL);
  3709. if (!result) goto failed;
  3710. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Interactive.body,
  3711. ast2obj_stmt);
  3712. if (!value) goto failed;
  3713. if (PyObject_SetAttr(result, state->body, value) == -1)
  3714. goto failed;
  3715. Py_DECREF(value);
  3716. break;
  3717. case Expression_kind:
  3718. tp = (PyTypeObject *)state->Expression_type;
  3719. result = PyType_GenericNew(tp, NULL, NULL);
  3720. if (!result) goto failed;
  3721. value = ast2obj_expr(state, vstate, o->v.Expression.body);
  3722. if (!value) goto failed;
  3723. if (PyObject_SetAttr(result, state->body, value) == -1)
  3724. goto failed;
  3725. Py_DECREF(value);
  3726. break;
  3727. case FunctionType_kind:
  3728. tp = (PyTypeObject *)state->FunctionType_type;
  3729. result = PyType_GenericNew(tp, NULL, NULL);
  3730. if (!result) goto failed;
  3731. value = ast2obj_list(state, vstate,
  3732. (asdl_seq*)o->v.FunctionType.argtypes,
  3733. ast2obj_expr);
  3734. if (!value) goto failed;
  3735. if (PyObject_SetAttr(result, state->argtypes, value) == -1)
  3736. goto failed;
  3737. Py_DECREF(value);
  3738. value = ast2obj_expr(state, vstate, o->v.FunctionType.returns);
  3739. if (!value) goto failed;
  3740. if (PyObject_SetAttr(result, state->returns, value) == -1)
  3741. goto failed;
  3742. Py_DECREF(value);
  3743. break;
  3744. }
  3745. vstate->recursion_depth--;
  3746. return result;
  3747. failed:
  3748. vstate->recursion_depth--;
  3749. Py_XDECREF(value);
  3750. Py_XDECREF(result);
  3751. return NULL;
  3752. }
  3753. PyObject*
  3754. ast2obj_stmt(struct ast_state *state, struct validator *vstate, void* _o)
  3755. {
  3756. stmt_ty o = (stmt_ty)_o;
  3757. PyObject *result = NULL, *value = NULL;
  3758. PyTypeObject *tp;
  3759. if (!o) {
  3760. Py_RETURN_NONE;
  3761. }
  3762. if (++vstate->recursion_depth > vstate->recursion_limit) {
  3763. PyErr_SetString(PyExc_RecursionError,
  3764. "maximum recursion depth exceeded during ast construction");
  3765. return 0;
  3766. }
  3767. switch (o->kind) {
  3768. case FunctionDef_kind:
  3769. tp = (PyTypeObject *)state->FunctionDef_type;
  3770. result = PyType_GenericNew(tp, NULL, NULL);
  3771. if (!result) goto failed;
  3772. value = ast2obj_identifier(state, vstate, o->v.FunctionDef.name);
  3773. if (!value) goto failed;
  3774. if (PyObject_SetAttr(result, state->name, value) == -1)
  3775. goto failed;
  3776. Py_DECREF(value);
  3777. value = ast2obj_arguments(state, vstate, o->v.FunctionDef.args);
  3778. if (!value) goto failed;
  3779. if (PyObject_SetAttr(result, state->args, value) == -1)
  3780. goto failed;
  3781. Py_DECREF(value);
  3782. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.FunctionDef.body,
  3783. ast2obj_stmt);
  3784. if (!value) goto failed;
  3785. if (PyObject_SetAttr(result, state->body, value) == -1)
  3786. goto failed;
  3787. Py_DECREF(value);
  3788. value = ast2obj_list(state, vstate,
  3789. (asdl_seq*)o->v.FunctionDef.decorator_list,
  3790. ast2obj_expr);
  3791. if (!value) goto failed;
  3792. if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
  3793. goto failed;
  3794. Py_DECREF(value);
  3795. value = ast2obj_expr(state, vstate, o->v.FunctionDef.returns);
  3796. if (!value) goto failed;
  3797. if (PyObject_SetAttr(result, state->returns, value) == -1)
  3798. goto failed;
  3799. Py_DECREF(value);
  3800. value = ast2obj_string(state, vstate, o->v.FunctionDef.type_comment);
  3801. if (!value) goto failed;
  3802. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  3803. goto failed;
  3804. Py_DECREF(value);
  3805. value = ast2obj_list(state, vstate,
  3806. (asdl_seq*)o->v.FunctionDef.type_params,
  3807. ast2obj_type_param);
  3808. if (!value) goto failed;
  3809. if (PyObject_SetAttr(result, state->type_params, value) == -1)
  3810. goto failed;
  3811. Py_DECREF(value);
  3812. break;
  3813. case AsyncFunctionDef_kind:
  3814. tp = (PyTypeObject *)state->AsyncFunctionDef_type;
  3815. result = PyType_GenericNew(tp, NULL, NULL);
  3816. if (!result) goto failed;
  3817. value = ast2obj_identifier(state, vstate, o->v.AsyncFunctionDef.name);
  3818. if (!value) goto failed;
  3819. if (PyObject_SetAttr(result, state->name, value) == -1)
  3820. goto failed;
  3821. Py_DECREF(value);
  3822. value = ast2obj_arguments(state, vstate, o->v.AsyncFunctionDef.args);
  3823. if (!value) goto failed;
  3824. if (PyObject_SetAttr(result, state->args, value) == -1)
  3825. goto failed;
  3826. Py_DECREF(value);
  3827. value = ast2obj_list(state, vstate,
  3828. (asdl_seq*)o->v.AsyncFunctionDef.body,
  3829. ast2obj_stmt);
  3830. if (!value) goto failed;
  3831. if (PyObject_SetAttr(result, state->body, value) == -1)
  3832. goto failed;
  3833. Py_DECREF(value);
  3834. value = ast2obj_list(state, vstate,
  3835. (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
  3836. ast2obj_expr);
  3837. if (!value) goto failed;
  3838. if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
  3839. goto failed;
  3840. Py_DECREF(value);
  3841. value = ast2obj_expr(state, vstate, o->v.AsyncFunctionDef.returns);
  3842. if (!value) goto failed;
  3843. if (PyObject_SetAttr(result, state->returns, value) == -1)
  3844. goto failed;
  3845. Py_DECREF(value);
  3846. value = ast2obj_string(state, vstate, o->v.AsyncFunctionDef.type_comment);
  3847. if (!value) goto failed;
  3848. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  3849. goto failed;
  3850. Py_DECREF(value);
  3851. value = ast2obj_list(state, vstate,
  3852. (asdl_seq*)o->v.AsyncFunctionDef.type_params,
  3853. ast2obj_type_param);
  3854. if (!value) goto failed;
  3855. if (PyObject_SetAttr(result, state->type_params, value) == -1)
  3856. goto failed;
  3857. Py_DECREF(value);
  3858. break;
  3859. case ClassDef_kind:
  3860. tp = (PyTypeObject *)state->ClassDef_type;
  3861. result = PyType_GenericNew(tp, NULL, NULL);
  3862. if (!result) goto failed;
  3863. value = ast2obj_identifier(state, vstate, o->v.ClassDef.name);
  3864. if (!value) goto failed;
  3865. if (PyObject_SetAttr(result, state->name, value) == -1)
  3866. goto failed;
  3867. Py_DECREF(value);
  3868. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.bases,
  3869. ast2obj_expr);
  3870. if (!value) goto failed;
  3871. if (PyObject_SetAttr(result, state->bases, value) == -1)
  3872. goto failed;
  3873. Py_DECREF(value);
  3874. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.keywords,
  3875. ast2obj_keyword);
  3876. if (!value) goto failed;
  3877. if (PyObject_SetAttr(result, state->keywords, value) == -1)
  3878. goto failed;
  3879. Py_DECREF(value);
  3880. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.body,
  3881. ast2obj_stmt);
  3882. if (!value) goto failed;
  3883. if (PyObject_SetAttr(result, state->body, value) == -1)
  3884. goto failed;
  3885. Py_DECREF(value);
  3886. value = ast2obj_list(state, vstate,
  3887. (asdl_seq*)o->v.ClassDef.decorator_list,
  3888. ast2obj_expr);
  3889. if (!value) goto failed;
  3890. if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
  3891. goto failed;
  3892. Py_DECREF(value);
  3893. value = ast2obj_list(state, vstate,
  3894. (asdl_seq*)o->v.ClassDef.type_params,
  3895. ast2obj_type_param);
  3896. if (!value) goto failed;
  3897. if (PyObject_SetAttr(result, state->type_params, value) == -1)
  3898. goto failed;
  3899. Py_DECREF(value);
  3900. break;
  3901. case Return_kind:
  3902. tp = (PyTypeObject *)state->Return_type;
  3903. result = PyType_GenericNew(tp, NULL, NULL);
  3904. if (!result) goto failed;
  3905. value = ast2obj_expr(state, vstate, o->v.Return.value);
  3906. if (!value) goto failed;
  3907. if (PyObject_SetAttr(result, state->value, value) == -1)
  3908. goto failed;
  3909. Py_DECREF(value);
  3910. break;
  3911. case Delete_kind:
  3912. tp = (PyTypeObject *)state->Delete_type;
  3913. result = PyType_GenericNew(tp, NULL, NULL);
  3914. if (!result) goto failed;
  3915. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Delete.targets,
  3916. ast2obj_expr);
  3917. if (!value) goto failed;
  3918. if (PyObject_SetAttr(result, state->targets, value) == -1)
  3919. goto failed;
  3920. Py_DECREF(value);
  3921. break;
  3922. case Assign_kind:
  3923. tp = (PyTypeObject *)state->Assign_type;
  3924. result = PyType_GenericNew(tp, NULL, NULL);
  3925. if (!result) goto failed;
  3926. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Assign.targets,
  3927. ast2obj_expr);
  3928. if (!value) goto failed;
  3929. if (PyObject_SetAttr(result, state->targets, value) == -1)
  3930. goto failed;
  3931. Py_DECREF(value);
  3932. value = ast2obj_expr(state, vstate, o->v.Assign.value);
  3933. if (!value) goto failed;
  3934. if (PyObject_SetAttr(result, state->value, value) == -1)
  3935. goto failed;
  3936. Py_DECREF(value);
  3937. value = ast2obj_string(state, vstate, o->v.Assign.type_comment);
  3938. if (!value) goto failed;
  3939. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  3940. goto failed;
  3941. Py_DECREF(value);
  3942. break;
  3943. case TypeAlias_kind:
  3944. tp = (PyTypeObject *)state->TypeAlias_type;
  3945. result = PyType_GenericNew(tp, NULL, NULL);
  3946. if (!result) goto failed;
  3947. value = ast2obj_expr(state, vstate, o->v.TypeAlias.name);
  3948. if (!value) goto failed;
  3949. if (PyObject_SetAttr(result, state->name, value) == -1)
  3950. goto failed;
  3951. Py_DECREF(value);
  3952. value = ast2obj_list(state, vstate,
  3953. (asdl_seq*)o->v.TypeAlias.type_params,
  3954. ast2obj_type_param);
  3955. if (!value) goto failed;
  3956. if (PyObject_SetAttr(result, state->type_params, value) == -1)
  3957. goto failed;
  3958. Py_DECREF(value);
  3959. value = ast2obj_expr(state, vstate, o->v.TypeAlias.value);
  3960. if (!value) goto failed;
  3961. if (PyObject_SetAttr(result, state->value, value) == -1)
  3962. goto failed;
  3963. Py_DECREF(value);
  3964. break;
  3965. case AugAssign_kind:
  3966. tp = (PyTypeObject *)state->AugAssign_type;
  3967. result = PyType_GenericNew(tp, NULL, NULL);
  3968. if (!result) goto failed;
  3969. value = ast2obj_expr(state, vstate, o->v.AugAssign.target);
  3970. if (!value) goto failed;
  3971. if (PyObject_SetAttr(result, state->target, value) == -1)
  3972. goto failed;
  3973. Py_DECREF(value);
  3974. value = ast2obj_operator(state, vstate, o->v.AugAssign.op);
  3975. if (!value) goto failed;
  3976. if (PyObject_SetAttr(result, state->op, value) == -1)
  3977. goto failed;
  3978. Py_DECREF(value);
  3979. value = ast2obj_expr(state, vstate, o->v.AugAssign.value);
  3980. if (!value) goto failed;
  3981. if (PyObject_SetAttr(result, state->value, value) == -1)
  3982. goto failed;
  3983. Py_DECREF(value);
  3984. break;
  3985. case AnnAssign_kind:
  3986. tp = (PyTypeObject *)state->AnnAssign_type;
  3987. result = PyType_GenericNew(tp, NULL, NULL);
  3988. if (!result) goto failed;
  3989. value = ast2obj_expr(state, vstate, o->v.AnnAssign.target);
  3990. if (!value) goto failed;
  3991. if (PyObject_SetAttr(result, state->target, value) == -1)
  3992. goto failed;
  3993. Py_DECREF(value);
  3994. value = ast2obj_expr(state, vstate, o->v.AnnAssign.annotation);
  3995. if (!value) goto failed;
  3996. if (PyObject_SetAttr(result, state->annotation, value) == -1)
  3997. goto failed;
  3998. Py_DECREF(value);
  3999. value = ast2obj_expr(state, vstate, o->v.AnnAssign.value);
  4000. if (!value) goto failed;
  4001. if (PyObject_SetAttr(result, state->value, value) == -1)
  4002. goto failed;
  4003. Py_DECREF(value);
  4004. value = ast2obj_int(state, vstate, o->v.AnnAssign.simple);
  4005. if (!value) goto failed;
  4006. if (PyObject_SetAttr(result, state->simple, value) == -1)
  4007. goto failed;
  4008. Py_DECREF(value);
  4009. break;
  4010. case For_kind:
  4011. tp = (PyTypeObject *)state->For_type;
  4012. result = PyType_GenericNew(tp, NULL, NULL);
  4013. if (!result) goto failed;
  4014. value = ast2obj_expr(state, vstate, o->v.For.target);
  4015. if (!value) goto failed;
  4016. if (PyObject_SetAttr(result, state->target, value) == -1)
  4017. goto failed;
  4018. Py_DECREF(value);
  4019. value = ast2obj_expr(state, vstate, o->v.For.iter);
  4020. if (!value) goto failed;
  4021. if (PyObject_SetAttr(result, state->iter, value) == -1)
  4022. goto failed;
  4023. Py_DECREF(value);
  4024. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.For.body,
  4025. ast2obj_stmt);
  4026. if (!value) goto failed;
  4027. if (PyObject_SetAttr(result, state->body, value) == -1)
  4028. goto failed;
  4029. Py_DECREF(value);
  4030. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.For.orelse,
  4031. ast2obj_stmt);
  4032. if (!value) goto failed;
  4033. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4034. goto failed;
  4035. Py_DECREF(value);
  4036. value = ast2obj_string(state, vstate, o->v.For.type_comment);
  4037. if (!value) goto failed;
  4038. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  4039. goto failed;
  4040. Py_DECREF(value);
  4041. break;
  4042. case AsyncFor_kind:
  4043. tp = (PyTypeObject *)state->AsyncFor_type;
  4044. result = PyType_GenericNew(tp, NULL, NULL);
  4045. if (!result) goto failed;
  4046. value = ast2obj_expr(state, vstate, o->v.AsyncFor.target);
  4047. if (!value) goto failed;
  4048. if (PyObject_SetAttr(result, state->target, value) == -1)
  4049. goto failed;
  4050. Py_DECREF(value);
  4051. value = ast2obj_expr(state, vstate, o->v.AsyncFor.iter);
  4052. if (!value) goto failed;
  4053. if (PyObject_SetAttr(result, state->iter, value) == -1)
  4054. goto failed;
  4055. Py_DECREF(value);
  4056. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncFor.body,
  4057. ast2obj_stmt);
  4058. if (!value) goto failed;
  4059. if (PyObject_SetAttr(result, state->body, value) == -1)
  4060. goto failed;
  4061. Py_DECREF(value);
  4062. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncFor.orelse,
  4063. ast2obj_stmt);
  4064. if (!value) goto failed;
  4065. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4066. goto failed;
  4067. Py_DECREF(value);
  4068. value = ast2obj_string(state, vstate, o->v.AsyncFor.type_comment);
  4069. if (!value) goto failed;
  4070. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  4071. goto failed;
  4072. Py_DECREF(value);
  4073. break;
  4074. case While_kind:
  4075. tp = (PyTypeObject *)state->While_type;
  4076. result = PyType_GenericNew(tp, NULL, NULL);
  4077. if (!result) goto failed;
  4078. value = ast2obj_expr(state, vstate, o->v.While.test);
  4079. if (!value) goto failed;
  4080. if (PyObject_SetAttr(result, state->test, value) == -1)
  4081. goto failed;
  4082. Py_DECREF(value);
  4083. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.While.body,
  4084. ast2obj_stmt);
  4085. if (!value) goto failed;
  4086. if (PyObject_SetAttr(result, state->body, value) == -1)
  4087. goto failed;
  4088. Py_DECREF(value);
  4089. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.While.orelse,
  4090. ast2obj_stmt);
  4091. if (!value) goto failed;
  4092. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4093. goto failed;
  4094. Py_DECREF(value);
  4095. break;
  4096. case If_kind:
  4097. tp = (PyTypeObject *)state->If_type;
  4098. result = PyType_GenericNew(tp, NULL, NULL);
  4099. if (!result) goto failed;
  4100. value = ast2obj_expr(state, vstate, o->v.If.test);
  4101. if (!value) goto failed;
  4102. if (PyObject_SetAttr(result, state->test, value) == -1)
  4103. goto failed;
  4104. Py_DECREF(value);
  4105. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.If.body,
  4106. ast2obj_stmt);
  4107. if (!value) goto failed;
  4108. if (PyObject_SetAttr(result, state->body, value) == -1)
  4109. goto failed;
  4110. Py_DECREF(value);
  4111. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.If.orelse,
  4112. ast2obj_stmt);
  4113. if (!value) goto failed;
  4114. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4115. goto failed;
  4116. Py_DECREF(value);
  4117. break;
  4118. case With_kind:
  4119. tp = (PyTypeObject *)state->With_type;
  4120. result = PyType_GenericNew(tp, NULL, NULL);
  4121. if (!result) goto failed;
  4122. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.With.items,
  4123. ast2obj_withitem);
  4124. if (!value) goto failed;
  4125. if (PyObject_SetAttr(result, state->items, value) == -1)
  4126. goto failed;
  4127. Py_DECREF(value);
  4128. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.With.body,
  4129. ast2obj_stmt);
  4130. if (!value) goto failed;
  4131. if (PyObject_SetAttr(result, state->body, value) == -1)
  4132. goto failed;
  4133. Py_DECREF(value);
  4134. value = ast2obj_string(state, vstate, o->v.With.type_comment);
  4135. if (!value) goto failed;
  4136. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  4137. goto failed;
  4138. Py_DECREF(value);
  4139. break;
  4140. case AsyncWith_kind:
  4141. tp = (PyTypeObject *)state->AsyncWith_type;
  4142. result = PyType_GenericNew(tp, NULL, NULL);
  4143. if (!result) goto failed;
  4144. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncWith.items,
  4145. ast2obj_withitem);
  4146. if (!value) goto failed;
  4147. if (PyObject_SetAttr(result, state->items, value) == -1)
  4148. goto failed;
  4149. Py_DECREF(value);
  4150. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncWith.body,
  4151. ast2obj_stmt);
  4152. if (!value) goto failed;
  4153. if (PyObject_SetAttr(result, state->body, value) == -1)
  4154. goto failed;
  4155. Py_DECREF(value);
  4156. value = ast2obj_string(state, vstate, o->v.AsyncWith.type_comment);
  4157. if (!value) goto failed;
  4158. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  4159. goto failed;
  4160. Py_DECREF(value);
  4161. break;
  4162. case Match_kind:
  4163. tp = (PyTypeObject *)state->Match_type;
  4164. result = PyType_GenericNew(tp, NULL, NULL);
  4165. if (!result) goto failed;
  4166. value = ast2obj_expr(state, vstate, o->v.Match.subject);
  4167. if (!value) goto failed;
  4168. if (PyObject_SetAttr(result, state->subject, value) == -1)
  4169. goto failed;
  4170. Py_DECREF(value);
  4171. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Match.cases,
  4172. ast2obj_match_case);
  4173. if (!value) goto failed;
  4174. if (PyObject_SetAttr(result, state->cases, value) == -1)
  4175. goto failed;
  4176. Py_DECREF(value);
  4177. break;
  4178. case Raise_kind:
  4179. tp = (PyTypeObject *)state->Raise_type;
  4180. result = PyType_GenericNew(tp, NULL, NULL);
  4181. if (!result) goto failed;
  4182. value = ast2obj_expr(state, vstate, o->v.Raise.exc);
  4183. if (!value) goto failed;
  4184. if (PyObject_SetAttr(result, state->exc, value) == -1)
  4185. goto failed;
  4186. Py_DECREF(value);
  4187. value = ast2obj_expr(state, vstate, o->v.Raise.cause);
  4188. if (!value) goto failed;
  4189. if (PyObject_SetAttr(result, state->cause, value) == -1)
  4190. goto failed;
  4191. Py_DECREF(value);
  4192. break;
  4193. case Try_kind:
  4194. tp = (PyTypeObject *)state->Try_type;
  4195. result = PyType_GenericNew(tp, NULL, NULL);
  4196. if (!result) goto failed;
  4197. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.body,
  4198. ast2obj_stmt);
  4199. if (!value) goto failed;
  4200. if (PyObject_SetAttr(result, state->body, value) == -1)
  4201. goto failed;
  4202. Py_DECREF(value);
  4203. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.handlers,
  4204. ast2obj_excepthandler);
  4205. if (!value) goto failed;
  4206. if (PyObject_SetAttr(result, state->handlers, value) == -1)
  4207. goto failed;
  4208. Py_DECREF(value);
  4209. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.orelse,
  4210. ast2obj_stmt);
  4211. if (!value) goto failed;
  4212. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4213. goto failed;
  4214. Py_DECREF(value);
  4215. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.finalbody,
  4216. ast2obj_stmt);
  4217. if (!value) goto failed;
  4218. if (PyObject_SetAttr(result, state->finalbody, value) == -1)
  4219. goto failed;
  4220. Py_DECREF(value);
  4221. break;
  4222. case TryStar_kind:
  4223. tp = (PyTypeObject *)state->TryStar_type;
  4224. result = PyType_GenericNew(tp, NULL, NULL);
  4225. if (!result) goto failed;
  4226. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.body,
  4227. ast2obj_stmt);
  4228. if (!value) goto failed;
  4229. if (PyObject_SetAttr(result, state->body, value) == -1)
  4230. goto failed;
  4231. Py_DECREF(value);
  4232. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.handlers,
  4233. ast2obj_excepthandler);
  4234. if (!value) goto failed;
  4235. if (PyObject_SetAttr(result, state->handlers, value) == -1)
  4236. goto failed;
  4237. Py_DECREF(value);
  4238. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.orelse,
  4239. ast2obj_stmt);
  4240. if (!value) goto failed;
  4241. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4242. goto failed;
  4243. Py_DECREF(value);
  4244. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.finalbody,
  4245. ast2obj_stmt);
  4246. if (!value) goto failed;
  4247. if (PyObject_SetAttr(result, state->finalbody, value) == -1)
  4248. goto failed;
  4249. Py_DECREF(value);
  4250. break;
  4251. case Assert_kind:
  4252. tp = (PyTypeObject *)state->Assert_type;
  4253. result = PyType_GenericNew(tp, NULL, NULL);
  4254. if (!result) goto failed;
  4255. value = ast2obj_expr(state, vstate, o->v.Assert.test);
  4256. if (!value) goto failed;
  4257. if (PyObject_SetAttr(result, state->test, value) == -1)
  4258. goto failed;
  4259. Py_DECREF(value);
  4260. value = ast2obj_expr(state, vstate, o->v.Assert.msg);
  4261. if (!value) goto failed;
  4262. if (PyObject_SetAttr(result, state->msg, value) == -1)
  4263. goto failed;
  4264. Py_DECREF(value);
  4265. break;
  4266. case Import_kind:
  4267. tp = (PyTypeObject *)state->Import_type;
  4268. result = PyType_GenericNew(tp, NULL, NULL);
  4269. if (!result) goto failed;
  4270. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Import.names,
  4271. ast2obj_alias);
  4272. if (!value) goto failed;
  4273. if (PyObject_SetAttr(result, state->names, value) == -1)
  4274. goto failed;
  4275. Py_DECREF(value);
  4276. break;
  4277. case ImportFrom_kind:
  4278. tp = (PyTypeObject *)state->ImportFrom_type;
  4279. result = PyType_GenericNew(tp, NULL, NULL);
  4280. if (!result) goto failed;
  4281. value = ast2obj_identifier(state, vstate, o->v.ImportFrom.module);
  4282. if (!value) goto failed;
  4283. if (PyObject_SetAttr(result, state->module, value) == -1)
  4284. goto failed;
  4285. Py_DECREF(value);
  4286. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ImportFrom.names,
  4287. ast2obj_alias);
  4288. if (!value) goto failed;
  4289. if (PyObject_SetAttr(result, state->names, value) == -1)
  4290. goto failed;
  4291. Py_DECREF(value);
  4292. value = ast2obj_int(state, vstate, o->v.ImportFrom.level);
  4293. if (!value) goto failed;
  4294. if (PyObject_SetAttr(result, state->level, value) == -1)
  4295. goto failed;
  4296. Py_DECREF(value);
  4297. break;
  4298. case Global_kind:
  4299. tp = (PyTypeObject *)state->Global_type;
  4300. result = PyType_GenericNew(tp, NULL, NULL);
  4301. if (!result) goto failed;
  4302. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Global.names,
  4303. ast2obj_identifier);
  4304. if (!value) goto failed;
  4305. if (PyObject_SetAttr(result, state->names, value) == -1)
  4306. goto failed;
  4307. Py_DECREF(value);
  4308. break;
  4309. case Nonlocal_kind:
  4310. tp = (PyTypeObject *)state->Nonlocal_type;
  4311. result = PyType_GenericNew(tp, NULL, NULL);
  4312. if (!result) goto failed;
  4313. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Nonlocal.names,
  4314. ast2obj_identifier);
  4315. if (!value) goto failed;
  4316. if (PyObject_SetAttr(result, state->names, value) == -1)
  4317. goto failed;
  4318. Py_DECREF(value);
  4319. break;
  4320. case Expr_kind:
  4321. tp = (PyTypeObject *)state->Expr_type;
  4322. result = PyType_GenericNew(tp, NULL, NULL);
  4323. if (!result) goto failed;
  4324. value = ast2obj_expr(state, vstate, o->v.Expr.value);
  4325. if (!value) goto failed;
  4326. if (PyObject_SetAttr(result, state->value, value) == -1)
  4327. goto failed;
  4328. Py_DECREF(value);
  4329. break;
  4330. case Pass_kind:
  4331. tp = (PyTypeObject *)state->Pass_type;
  4332. result = PyType_GenericNew(tp, NULL, NULL);
  4333. if (!result) goto failed;
  4334. break;
  4335. case Break_kind:
  4336. tp = (PyTypeObject *)state->Break_type;
  4337. result = PyType_GenericNew(tp, NULL, NULL);
  4338. if (!result) goto failed;
  4339. break;
  4340. case Continue_kind:
  4341. tp = (PyTypeObject *)state->Continue_type;
  4342. result = PyType_GenericNew(tp, NULL, NULL);
  4343. if (!result) goto failed;
  4344. break;
  4345. }
  4346. value = ast2obj_int(state, vstate, o->lineno);
  4347. if (!value) goto failed;
  4348. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  4349. goto failed;
  4350. Py_DECREF(value);
  4351. value = ast2obj_int(state, vstate, o->col_offset);
  4352. if (!value) goto failed;
  4353. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  4354. goto failed;
  4355. Py_DECREF(value);
  4356. value = ast2obj_int(state, vstate, o->end_lineno);
  4357. if (!value) goto failed;
  4358. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  4359. goto failed;
  4360. Py_DECREF(value);
  4361. value = ast2obj_int(state, vstate, o->end_col_offset);
  4362. if (!value) goto failed;
  4363. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  4364. goto failed;
  4365. Py_DECREF(value);
  4366. vstate->recursion_depth--;
  4367. return result;
  4368. failed:
  4369. vstate->recursion_depth--;
  4370. Py_XDECREF(value);
  4371. Py_XDECREF(result);
  4372. return NULL;
  4373. }
  4374. PyObject*
  4375. ast2obj_expr(struct ast_state *state, struct validator *vstate, void* _o)
  4376. {
  4377. expr_ty o = (expr_ty)_o;
  4378. PyObject *result = NULL, *value = NULL;
  4379. PyTypeObject *tp;
  4380. if (!o) {
  4381. Py_RETURN_NONE;
  4382. }
  4383. if (++vstate->recursion_depth > vstate->recursion_limit) {
  4384. PyErr_SetString(PyExc_RecursionError,
  4385. "maximum recursion depth exceeded during ast construction");
  4386. return 0;
  4387. }
  4388. switch (o->kind) {
  4389. case BoolOp_kind:
  4390. tp = (PyTypeObject *)state->BoolOp_type;
  4391. result = PyType_GenericNew(tp, NULL, NULL);
  4392. if (!result) goto failed;
  4393. value = ast2obj_boolop(state, vstate, o->v.BoolOp.op);
  4394. if (!value) goto failed;
  4395. if (PyObject_SetAttr(result, state->op, value) == -1)
  4396. goto failed;
  4397. Py_DECREF(value);
  4398. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.BoolOp.values,
  4399. ast2obj_expr);
  4400. if (!value) goto failed;
  4401. if (PyObject_SetAttr(result, state->values, value) == -1)
  4402. goto failed;
  4403. Py_DECREF(value);
  4404. break;
  4405. case NamedExpr_kind:
  4406. tp = (PyTypeObject *)state->NamedExpr_type;
  4407. result = PyType_GenericNew(tp, NULL, NULL);
  4408. if (!result) goto failed;
  4409. value = ast2obj_expr(state, vstate, o->v.NamedExpr.target);
  4410. if (!value) goto failed;
  4411. if (PyObject_SetAttr(result, state->target, value) == -1)
  4412. goto failed;
  4413. Py_DECREF(value);
  4414. value = ast2obj_expr(state, vstate, o->v.NamedExpr.value);
  4415. if (!value) goto failed;
  4416. if (PyObject_SetAttr(result, state->value, value) == -1)
  4417. goto failed;
  4418. Py_DECREF(value);
  4419. break;
  4420. case BinOp_kind:
  4421. tp = (PyTypeObject *)state->BinOp_type;
  4422. result = PyType_GenericNew(tp, NULL, NULL);
  4423. if (!result) goto failed;
  4424. value = ast2obj_expr(state, vstate, o->v.BinOp.left);
  4425. if (!value) goto failed;
  4426. if (PyObject_SetAttr(result, state->left, value) == -1)
  4427. goto failed;
  4428. Py_DECREF(value);
  4429. value = ast2obj_operator(state, vstate, o->v.BinOp.op);
  4430. if (!value) goto failed;
  4431. if (PyObject_SetAttr(result, state->op, value) == -1)
  4432. goto failed;
  4433. Py_DECREF(value);
  4434. value = ast2obj_expr(state, vstate, o->v.BinOp.right);
  4435. if (!value) goto failed;
  4436. if (PyObject_SetAttr(result, state->right, value) == -1)
  4437. goto failed;
  4438. Py_DECREF(value);
  4439. break;
  4440. case UnaryOp_kind:
  4441. tp = (PyTypeObject *)state->UnaryOp_type;
  4442. result = PyType_GenericNew(tp, NULL, NULL);
  4443. if (!result) goto failed;
  4444. value = ast2obj_unaryop(state, vstate, o->v.UnaryOp.op);
  4445. if (!value) goto failed;
  4446. if (PyObject_SetAttr(result, state->op, value) == -1)
  4447. goto failed;
  4448. Py_DECREF(value);
  4449. value = ast2obj_expr(state, vstate, o->v.UnaryOp.operand);
  4450. if (!value) goto failed;
  4451. if (PyObject_SetAttr(result, state->operand, value) == -1)
  4452. goto failed;
  4453. Py_DECREF(value);
  4454. break;
  4455. case Lambda_kind:
  4456. tp = (PyTypeObject *)state->Lambda_type;
  4457. result = PyType_GenericNew(tp, NULL, NULL);
  4458. if (!result) goto failed;
  4459. value = ast2obj_arguments(state, vstate, o->v.Lambda.args);
  4460. if (!value) goto failed;
  4461. if (PyObject_SetAttr(result, state->args, value) == -1)
  4462. goto failed;
  4463. Py_DECREF(value);
  4464. value = ast2obj_expr(state, vstate, o->v.Lambda.body);
  4465. if (!value) goto failed;
  4466. if (PyObject_SetAttr(result, state->body, value) == -1)
  4467. goto failed;
  4468. Py_DECREF(value);
  4469. break;
  4470. case IfExp_kind:
  4471. tp = (PyTypeObject *)state->IfExp_type;
  4472. result = PyType_GenericNew(tp, NULL, NULL);
  4473. if (!result) goto failed;
  4474. value = ast2obj_expr(state, vstate, o->v.IfExp.test);
  4475. if (!value) goto failed;
  4476. if (PyObject_SetAttr(result, state->test, value) == -1)
  4477. goto failed;
  4478. Py_DECREF(value);
  4479. value = ast2obj_expr(state, vstate, o->v.IfExp.body);
  4480. if (!value) goto failed;
  4481. if (PyObject_SetAttr(result, state->body, value) == -1)
  4482. goto failed;
  4483. Py_DECREF(value);
  4484. value = ast2obj_expr(state, vstate, o->v.IfExp.orelse);
  4485. if (!value) goto failed;
  4486. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4487. goto failed;
  4488. Py_DECREF(value);
  4489. break;
  4490. case Dict_kind:
  4491. tp = (PyTypeObject *)state->Dict_type;
  4492. result = PyType_GenericNew(tp, NULL, NULL);
  4493. if (!result) goto failed;
  4494. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Dict.keys,
  4495. ast2obj_expr);
  4496. if (!value) goto failed;
  4497. if (PyObject_SetAttr(result, state->keys, value) == -1)
  4498. goto failed;
  4499. Py_DECREF(value);
  4500. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Dict.values,
  4501. ast2obj_expr);
  4502. if (!value) goto failed;
  4503. if (PyObject_SetAttr(result, state->values, value) == -1)
  4504. goto failed;
  4505. Py_DECREF(value);
  4506. break;
  4507. case Set_kind:
  4508. tp = (PyTypeObject *)state->Set_type;
  4509. result = PyType_GenericNew(tp, NULL, NULL);
  4510. if (!result) goto failed;
  4511. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Set.elts,
  4512. ast2obj_expr);
  4513. if (!value) goto failed;
  4514. if (PyObject_SetAttr(result, state->elts, value) == -1)
  4515. goto failed;
  4516. Py_DECREF(value);
  4517. break;
  4518. case ListComp_kind:
  4519. tp = (PyTypeObject *)state->ListComp_type;
  4520. result = PyType_GenericNew(tp, NULL, NULL);
  4521. if (!result) goto failed;
  4522. value = ast2obj_expr(state, vstate, o->v.ListComp.elt);
  4523. if (!value) goto failed;
  4524. if (PyObject_SetAttr(result, state->elt, value) == -1)
  4525. goto failed;
  4526. Py_DECREF(value);
  4527. value = ast2obj_list(state, vstate,
  4528. (asdl_seq*)o->v.ListComp.generators,
  4529. ast2obj_comprehension);
  4530. if (!value) goto failed;
  4531. if (PyObject_SetAttr(result, state->generators, value) == -1)
  4532. goto failed;
  4533. Py_DECREF(value);
  4534. break;
  4535. case SetComp_kind:
  4536. tp = (PyTypeObject *)state->SetComp_type;
  4537. result = PyType_GenericNew(tp, NULL, NULL);
  4538. if (!result) goto failed;
  4539. value = ast2obj_expr(state, vstate, o->v.SetComp.elt);
  4540. if (!value) goto failed;
  4541. if (PyObject_SetAttr(result, state->elt, value) == -1)
  4542. goto failed;
  4543. Py_DECREF(value);
  4544. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.SetComp.generators,
  4545. ast2obj_comprehension);
  4546. if (!value) goto failed;
  4547. if (PyObject_SetAttr(result, state->generators, value) == -1)
  4548. goto failed;
  4549. Py_DECREF(value);
  4550. break;
  4551. case DictComp_kind:
  4552. tp = (PyTypeObject *)state->DictComp_type;
  4553. result = PyType_GenericNew(tp, NULL, NULL);
  4554. if (!result) goto failed;
  4555. value = ast2obj_expr(state, vstate, o->v.DictComp.key);
  4556. if (!value) goto failed;
  4557. if (PyObject_SetAttr(result, state->key, value) == -1)
  4558. goto failed;
  4559. Py_DECREF(value);
  4560. value = ast2obj_expr(state, vstate, o->v.DictComp.value);
  4561. if (!value) goto failed;
  4562. if (PyObject_SetAttr(result, state->value, value) == -1)
  4563. goto failed;
  4564. Py_DECREF(value);
  4565. value = ast2obj_list(state, vstate,
  4566. (asdl_seq*)o->v.DictComp.generators,
  4567. ast2obj_comprehension);
  4568. if (!value) goto failed;
  4569. if (PyObject_SetAttr(result, state->generators, value) == -1)
  4570. goto failed;
  4571. Py_DECREF(value);
  4572. break;
  4573. case GeneratorExp_kind:
  4574. tp = (PyTypeObject *)state->GeneratorExp_type;
  4575. result = PyType_GenericNew(tp, NULL, NULL);
  4576. if (!result) goto failed;
  4577. value = ast2obj_expr(state, vstate, o->v.GeneratorExp.elt);
  4578. if (!value) goto failed;
  4579. if (PyObject_SetAttr(result, state->elt, value) == -1)
  4580. goto failed;
  4581. Py_DECREF(value);
  4582. value = ast2obj_list(state, vstate,
  4583. (asdl_seq*)o->v.GeneratorExp.generators,
  4584. ast2obj_comprehension);
  4585. if (!value) goto failed;
  4586. if (PyObject_SetAttr(result, state->generators, value) == -1)
  4587. goto failed;
  4588. Py_DECREF(value);
  4589. break;
  4590. case Await_kind:
  4591. tp = (PyTypeObject *)state->Await_type;
  4592. result = PyType_GenericNew(tp, NULL, NULL);
  4593. if (!result) goto failed;
  4594. value = ast2obj_expr(state, vstate, o->v.Await.value);
  4595. if (!value) goto failed;
  4596. if (PyObject_SetAttr(result, state->value, value) == -1)
  4597. goto failed;
  4598. Py_DECREF(value);
  4599. break;
  4600. case Yield_kind:
  4601. tp = (PyTypeObject *)state->Yield_type;
  4602. result = PyType_GenericNew(tp, NULL, NULL);
  4603. if (!result) goto failed;
  4604. value = ast2obj_expr(state, vstate, o->v.Yield.value);
  4605. if (!value) goto failed;
  4606. if (PyObject_SetAttr(result, state->value, value) == -1)
  4607. goto failed;
  4608. Py_DECREF(value);
  4609. break;
  4610. case YieldFrom_kind:
  4611. tp = (PyTypeObject *)state->YieldFrom_type;
  4612. result = PyType_GenericNew(tp, NULL, NULL);
  4613. if (!result) goto failed;
  4614. value = ast2obj_expr(state, vstate, o->v.YieldFrom.value);
  4615. if (!value) goto failed;
  4616. if (PyObject_SetAttr(result, state->value, value) == -1)
  4617. goto failed;
  4618. Py_DECREF(value);
  4619. break;
  4620. case Compare_kind:
  4621. tp = (PyTypeObject *)state->Compare_type;
  4622. result = PyType_GenericNew(tp, NULL, NULL);
  4623. if (!result) goto failed;
  4624. value = ast2obj_expr(state, vstate, o->v.Compare.left);
  4625. if (!value) goto failed;
  4626. if (PyObject_SetAttr(result, state->left, value) == -1)
  4627. goto failed;
  4628. Py_DECREF(value);
  4629. {
  4630. Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
  4631. value = PyList_New(n);
  4632. if (!value) goto failed;
  4633. for(i = 0; i < n; i++)
  4634. PyList_SET_ITEM(value, i, ast2obj_cmpop(state, vstate, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
  4635. }
  4636. if (!value) goto failed;
  4637. if (PyObject_SetAttr(result, state->ops, value) == -1)
  4638. goto failed;
  4639. Py_DECREF(value);
  4640. value = ast2obj_list(state, vstate,
  4641. (asdl_seq*)o->v.Compare.comparators, ast2obj_expr);
  4642. if (!value) goto failed;
  4643. if (PyObject_SetAttr(result, state->comparators, value) == -1)
  4644. goto failed;
  4645. Py_DECREF(value);
  4646. break;
  4647. case Call_kind:
  4648. tp = (PyTypeObject *)state->Call_type;
  4649. result = PyType_GenericNew(tp, NULL, NULL);
  4650. if (!result) goto failed;
  4651. value = ast2obj_expr(state, vstate, o->v.Call.func);
  4652. if (!value) goto failed;
  4653. if (PyObject_SetAttr(result, state->func, value) == -1)
  4654. goto failed;
  4655. Py_DECREF(value);
  4656. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Call.args,
  4657. ast2obj_expr);
  4658. if (!value) goto failed;
  4659. if (PyObject_SetAttr(result, state->args, value) == -1)
  4660. goto failed;
  4661. Py_DECREF(value);
  4662. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Call.keywords,
  4663. ast2obj_keyword);
  4664. if (!value) goto failed;
  4665. if (PyObject_SetAttr(result, state->keywords, value) == -1)
  4666. goto failed;
  4667. Py_DECREF(value);
  4668. break;
  4669. case FormattedValue_kind:
  4670. tp = (PyTypeObject *)state->FormattedValue_type;
  4671. result = PyType_GenericNew(tp, NULL, NULL);
  4672. if (!result) goto failed;
  4673. value = ast2obj_expr(state, vstate, o->v.FormattedValue.value);
  4674. if (!value) goto failed;
  4675. if (PyObject_SetAttr(result, state->value, value) == -1)
  4676. goto failed;
  4677. Py_DECREF(value);
  4678. value = ast2obj_int(state, vstate, o->v.FormattedValue.conversion);
  4679. if (!value) goto failed;
  4680. if (PyObject_SetAttr(result, state->conversion, value) == -1)
  4681. goto failed;
  4682. Py_DECREF(value);
  4683. value = ast2obj_expr(state, vstate, o->v.FormattedValue.format_spec);
  4684. if (!value) goto failed;
  4685. if (PyObject_SetAttr(result, state->format_spec, value) == -1)
  4686. goto failed;
  4687. Py_DECREF(value);
  4688. break;
  4689. case JoinedStr_kind:
  4690. tp = (PyTypeObject *)state->JoinedStr_type;
  4691. result = PyType_GenericNew(tp, NULL, NULL);
  4692. if (!result) goto failed;
  4693. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.JoinedStr.values,
  4694. ast2obj_expr);
  4695. if (!value) goto failed;
  4696. if (PyObject_SetAttr(result, state->values, value) == -1)
  4697. goto failed;
  4698. Py_DECREF(value);
  4699. break;
  4700. case Constant_kind:
  4701. tp = (PyTypeObject *)state->Constant_type;
  4702. result = PyType_GenericNew(tp, NULL, NULL);
  4703. if (!result) goto failed;
  4704. value = ast2obj_constant(state, vstate, o->v.Constant.value);
  4705. if (!value) goto failed;
  4706. if (PyObject_SetAttr(result, state->value, value) == -1)
  4707. goto failed;
  4708. Py_DECREF(value);
  4709. value = ast2obj_string(state, vstate, o->v.Constant.kind);
  4710. if (!value) goto failed;
  4711. if (PyObject_SetAttr(result, state->kind, value) == -1)
  4712. goto failed;
  4713. Py_DECREF(value);
  4714. break;
  4715. case Attribute_kind:
  4716. tp = (PyTypeObject *)state->Attribute_type;
  4717. result = PyType_GenericNew(tp, NULL, NULL);
  4718. if (!result) goto failed;
  4719. value = ast2obj_expr(state, vstate, o->v.Attribute.value);
  4720. if (!value) goto failed;
  4721. if (PyObject_SetAttr(result, state->value, value) == -1)
  4722. goto failed;
  4723. Py_DECREF(value);
  4724. value = ast2obj_identifier(state, vstate, o->v.Attribute.attr);
  4725. if (!value) goto failed;
  4726. if (PyObject_SetAttr(result, state->attr, value) == -1)
  4727. goto failed;
  4728. Py_DECREF(value);
  4729. value = ast2obj_expr_context(state, vstate, o->v.Attribute.ctx);
  4730. if (!value) goto failed;
  4731. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4732. goto failed;
  4733. Py_DECREF(value);
  4734. break;
  4735. case Subscript_kind:
  4736. tp = (PyTypeObject *)state->Subscript_type;
  4737. result = PyType_GenericNew(tp, NULL, NULL);
  4738. if (!result) goto failed;
  4739. value = ast2obj_expr(state, vstate, o->v.Subscript.value);
  4740. if (!value) goto failed;
  4741. if (PyObject_SetAttr(result, state->value, value) == -1)
  4742. goto failed;
  4743. Py_DECREF(value);
  4744. value = ast2obj_expr(state, vstate, o->v.Subscript.slice);
  4745. if (!value) goto failed;
  4746. if (PyObject_SetAttr(result, state->slice, value) == -1)
  4747. goto failed;
  4748. Py_DECREF(value);
  4749. value = ast2obj_expr_context(state, vstate, o->v.Subscript.ctx);
  4750. if (!value) goto failed;
  4751. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4752. goto failed;
  4753. Py_DECREF(value);
  4754. break;
  4755. case Starred_kind:
  4756. tp = (PyTypeObject *)state->Starred_type;
  4757. result = PyType_GenericNew(tp, NULL, NULL);
  4758. if (!result) goto failed;
  4759. value = ast2obj_expr(state, vstate, o->v.Starred.value);
  4760. if (!value) goto failed;
  4761. if (PyObject_SetAttr(result, state->value, value) == -1)
  4762. goto failed;
  4763. Py_DECREF(value);
  4764. value = ast2obj_expr_context(state, vstate, o->v.Starred.ctx);
  4765. if (!value) goto failed;
  4766. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4767. goto failed;
  4768. Py_DECREF(value);
  4769. break;
  4770. case Name_kind:
  4771. tp = (PyTypeObject *)state->Name_type;
  4772. result = PyType_GenericNew(tp, NULL, NULL);
  4773. if (!result) goto failed;
  4774. value = ast2obj_identifier(state, vstate, o->v.Name.id);
  4775. if (!value) goto failed;
  4776. if (PyObject_SetAttr(result, state->id, value) == -1)
  4777. goto failed;
  4778. Py_DECREF(value);
  4779. value = ast2obj_expr_context(state, vstate, o->v.Name.ctx);
  4780. if (!value) goto failed;
  4781. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4782. goto failed;
  4783. Py_DECREF(value);
  4784. break;
  4785. case List_kind:
  4786. tp = (PyTypeObject *)state->List_type;
  4787. result = PyType_GenericNew(tp, NULL, NULL);
  4788. if (!result) goto failed;
  4789. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.List.elts,
  4790. ast2obj_expr);
  4791. if (!value) goto failed;
  4792. if (PyObject_SetAttr(result, state->elts, value) == -1)
  4793. goto failed;
  4794. Py_DECREF(value);
  4795. value = ast2obj_expr_context(state, vstate, o->v.List.ctx);
  4796. if (!value) goto failed;
  4797. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4798. goto failed;
  4799. Py_DECREF(value);
  4800. break;
  4801. case Tuple_kind:
  4802. tp = (PyTypeObject *)state->Tuple_type;
  4803. result = PyType_GenericNew(tp, NULL, NULL);
  4804. if (!result) goto failed;
  4805. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Tuple.elts,
  4806. ast2obj_expr);
  4807. if (!value) goto failed;
  4808. if (PyObject_SetAttr(result, state->elts, value) == -1)
  4809. goto failed;
  4810. Py_DECREF(value);
  4811. value = ast2obj_expr_context(state, vstate, o->v.Tuple.ctx);
  4812. if (!value) goto failed;
  4813. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4814. goto failed;
  4815. Py_DECREF(value);
  4816. break;
  4817. case Slice_kind:
  4818. tp = (PyTypeObject *)state->Slice_type;
  4819. result = PyType_GenericNew(tp, NULL, NULL);
  4820. if (!result) goto failed;
  4821. value = ast2obj_expr(state, vstate, o->v.Slice.lower);
  4822. if (!value) goto failed;
  4823. if (PyObject_SetAttr(result, state->lower, value) == -1)
  4824. goto failed;
  4825. Py_DECREF(value);
  4826. value = ast2obj_expr(state, vstate, o->v.Slice.upper);
  4827. if (!value) goto failed;
  4828. if (PyObject_SetAttr(result, state->upper, value) == -1)
  4829. goto failed;
  4830. Py_DECREF(value);
  4831. value = ast2obj_expr(state, vstate, o->v.Slice.step);
  4832. if (!value) goto failed;
  4833. if (PyObject_SetAttr(result, state->step, value) == -1)
  4834. goto failed;
  4835. Py_DECREF(value);
  4836. break;
  4837. }
  4838. value = ast2obj_int(state, vstate, o->lineno);
  4839. if (!value) goto failed;
  4840. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  4841. goto failed;
  4842. Py_DECREF(value);
  4843. value = ast2obj_int(state, vstate, o->col_offset);
  4844. if (!value) goto failed;
  4845. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  4846. goto failed;
  4847. Py_DECREF(value);
  4848. value = ast2obj_int(state, vstate, o->end_lineno);
  4849. if (!value) goto failed;
  4850. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  4851. goto failed;
  4852. Py_DECREF(value);
  4853. value = ast2obj_int(state, vstate, o->end_col_offset);
  4854. if (!value) goto failed;
  4855. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  4856. goto failed;
  4857. Py_DECREF(value);
  4858. vstate->recursion_depth--;
  4859. return result;
  4860. failed:
  4861. vstate->recursion_depth--;
  4862. Py_XDECREF(value);
  4863. Py_XDECREF(result);
  4864. return NULL;
  4865. }
  4866. PyObject* ast2obj_expr_context(struct ast_state *state, struct validator
  4867. *vstate, expr_context_ty o)
  4868. {
  4869. switch(o) {
  4870. case Load:
  4871. return Py_NewRef(state->Load_singleton);
  4872. case Store:
  4873. return Py_NewRef(state->Store_singleton);
  4874. case Del:
  4875. return Py_NewRef(state->Del_singleton);
  4876. }
  4877. Py_UNREACHABLE();
  4878. }
  4879. PyObject* ast2obj_boolop(struct ast_state *state, struct validator *vstate,
  4880. boolop_ty o)
  4881. {
  4882. switch(o) {
  4883. case And:
  4884. return Py_NewRef(state->And_singleton);
  4885. case Or:
  4886. return Py_NewRef(state->Or_singleton);
  4887. }
  4888. Py_UNREACHABLE();
  4889. }
  4890. PyObject* ast2obj_operator(struct ast_state *state, struct validator *vstate,
  4891. operator_ty o)
  4892. {
  4893. switch(o) {
  4894. case Add:
  4895. return Py_NewRef(state->Add_singleton);
  4896. case Sub:
  4897. return Py_NewRef(state->Sub_singleton);
  4898. case Mult:
  4899. return Py_NewRef(state->Mult_singleton);
  4900. case MatMult:
  4901. return Py_NewRef(state->MatMult_singleton);
  4902. case Div:
  4903. return Py_NewRef(state->Div_singleton);
  4904. case Mod:
  4905. return Py_NewRef(state->Mod_singleton);
  4906. case Pow:
  4907. return Py_NewRef(state->Pow_singleton);
  4908. case LShift:
  4909. return Py_NewRef(state->LShift_singleton);
  4910. case RShift:
  4911. return Py_NewRef(state->RShift_singleton);
  4912. case BitOr:
  4913. return Py_NewRef(state->BitOr_singleton);
  4914. case BitXor:
  4915. return Py_NewRef(state->BitXor_singleton);
  4916. case BitAnd:
  4917. return Py_NewRef(state->BitAnd_singleton);
  4918. case FloorDiv:
  4919. return Py_NewRef(state->FloorDiv_singleton);
  4920. }
  4921. Py_UNREACHABLE();
  4922. }
  4923. PyObject* ast2obj_unaryop(struct ast_state *state, struct validator *vstate,
  4924. unaryop_ty o)
  4925. {
  4926. switch(o) {
  4927. case Invert:
  4928. return Py_NewRef(state->Invert_singleton);
  4929. case Not:
  4930. return Py_NewRef(state->Not_singleton);
  4931. case UAdd:
  4932. return Py_NewRef(state->UAdd_singleton);
  4933. case USub:
  4934. return Py_NewRef(state->USub_singleton);
  4935. }
  4936. Py_UNREACHABLE();
  4937. }
  4938. PyObject* ast2obj_cmpop(struct ast_state *state, struct validator *vstate,
  4939. cmpop_ty o)
  4940. {
  4941. switch(o) {
  4942. case Eq:
  4943. return Py_NewRef(state->Eq_singleton);
  4944. case NotEq:
  4945. return Py_NewRef(state->NotEq_singleton);
  4946. case Lt:
  4947. return Py_NewRef(state->Lt_singleton);
  4948. case LtE:
  4949. return Py_NewRef(state->LtE_singleton);
  4950. case Gt:
  4951. return Py_NewRef(state->Gt_singleton);
  4952. case GtE:
  4953. return Py_NewRef(state->GtE_singleton);
  4954. case Is:
  4955. return Py_NewRef(state->Is_singleton);
  4956. case IsNot:
  4957. return Py_NewRef(state->IsNot_singleton);
  4958. case In:
  4959. return Py_NewRef(state->In_singleton);
  4960. case NotIn:
  4961. return Py_NewRef(state->NotIn_singleton);
  4962. }
  4963. Py_UNREACHABLE();
  4964. }
  4965. PyObject*
  4966. ast2obj_comprehension(struct ast_state *state, struct validator *vstate, void*
  4967. _o)
  4968. {
  4969. comprehension_ty o = (comprehension_ty)_o;
  4970. PyObject *result = NULL, *value = NULL;
  4971. PyTypeObject *tp;
  4972. if (!o) {
  4973. Py_RETURN_NONE;
  4974. }
  4975. if (++vstate->recursion_depth > vstate->recursion_limit) {
  4976. PyErr_SetString(PyExc_RecursionError,
  4977. "maximum recursion depth exceeded during ast construction");
  4978. return 0;
  4979. }
  4980. tp = (PyTypeObject *)state->comprehension_type;
  4981. result = PyType_GenericNew(tp, NULL, NULL);
  4982. if (!result) return NULL;
  4983. value = ast2obj_expr(state, vstate, o->target);
  4984. if (!value) goto failed;
  4985. if (PyObject_SetAttr(result, state->target, value) == -1)
  4986. goto failed;
  4987. Py_DECREF(value);
  4988. value = ast2obj_expr(state, vstate, o->iter);
  4989. if (!value) goto failed;
  4990. if (PyObject_SetAttr(result, state->iter, value) == -1)
  4991. goto failed;
  4992. Py_DECREF(value);
  4993. value = ast2obj_list(state, vstate, (asdl_seq*)o->ifs, ast2obj_expr);
  4994. if (!value) goto failed;
  4995. if (PyObject_SetAttr(result, state->ifs, value) == -1)
  4996. goto failed;
  4997. Py_DECREF(value);
  4998. value = ast2obj_int(state, vstate, o->is_async);
  4999. if (!value) goto failed;
  5000. if (PyObject_SetAttr(result, state->is_async, value) == -1)
  5001. goto failed;
  5002. Py_DECREF(value);
  5003. vstate->recursion_depth--;
  5004. return result;
  5005. failed:
  5006. vstate->recursion_depth--;
  5007. Py_XDECREF(value);
  5008. Py_XDECREF(result);
  5009. return NULL;
  5010. }
  5011. PyObject*
  5012. ast2obj_excepthandler(struct ast_state *state, struct validator *vstate, void*
  5013. _o)
  5014. {
  5015. excepthandler_ty o = (excepthandler_ty)_o;
  5016. PyObject *result = NULL, *value = NULL;
  5017. PyTypeObject *tp;
  5018. if (!o) {
  5019. Py_RETURN_NONE;
  5020. }
  5021. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5022. PyErr_SetString(PyExc_RecursionError,
  5023. "maximum recursion depth exceeded during ast construction");
  5024. return 0;
  5025. }
  5026. switch (o->kind) {
  5027. case ExceptHandler_kind:
  5028. tp = (PyTypeObject *)state->ExceptHandler_type;
  5029. result = PyType_GenericNew(tp, NULL, NULL);
  5030. if (!result) goto failed;
  5031. value = ast2obj_expr(state, vstate, o->v.ExceptHandler.type);
  5032. if (!value) goto failed;
  5033. if (PyObject_SetAttr(result, state->type, value) == -1)
  5034. goto failed;
  5035. Py_DECREF(value);
  5036. value = ast2obj_identifier(state, vstate, o->v.ExceptHandler.name);
  5037. if (!value) goto failed;
  5038. if (PyObject_SetAttr(result, state->name, value) == -1)
  5039. goto failed;
  5040. Py_DECREF(value);
  5041. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ExceptHandler.body,
  5042. ast2obj_stmt);
  5043. if (!value) goto failed;
  5044. if (PyObject_SetAttr(result, state->body, value) == -1)
  5045. goto failed;
  5046. Py_DECREF(value);
  5047. break;
  5048. }
  5049. value = ast2obj_int(state, vstate, o->lineno);
  5050. if (!value) goto failed;
  5051. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5052. goto failed;
  5053. Py_DECREF(value);
  5054. value = ast2obj_int(state, vstate, o->col_offset);
  5055. if (!value) goto failed;
  5056. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5057. goto failed;
  5058. Py_DECREF(value);
  5059. value = ast2obj_int(state, vstate, o->end_lineno);
  5060. if (!value) goto failed;
  5061. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5062. goto failed;
  5063. Py_DECREF(value);
  5064. value = ast2obj_int(state, vstate, o->end_col_offset);
  5065. if (!value) goto failed;
  5066. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5067. goto failed;
  5068. Py_DECREF(value);
  5069. vstate->recursion_depth--;
  5070. return result;
  5071. failed:
  5072. vstate->recursion_depth--;
  5073. Py_XDECREF(value);
  5074. Py_XDECREF(result);
  5075. return NULL;
  5076. }
  5077. PyObject*
  5078. ast2obj_arguments(struct ast_state *state, struct validator *vstate, void* _o)
  5079. {
  5080. arguments_ty o = (arguments_ty)_o;
  5081. PyObject *result = NULL, *value = NULL;
  5082. PyTypeObject *tp;
  5083. if (!o) {
  5084. Py_RETURN_NONE;
  5085. }
  5086. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5087. PyErr_SetString(PyExc_RecursionError,
  5088. "maximum recursion depth exceeded during ast construction");
  5089. return 0;
  5090. }
  5091. tp = (PyTypeObject *)state->arguments_type;
  5092. result = PyType_GenericNew(tp, NULL, NULL);
  5093. if (!result) return NULL;
  5094. value = ast2obj_list(state, vstate, (asdl_seq*)o->posonlyargs, ast2obj_arg);
  5095. if (!value) goto failed;
  5096. if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
  5097. goto failed;
  5098. Py_DECREF(value);
  5099. value = ast2obj_list(state, vstate, (asdl_seq*)o->args, ast2obj_arg);
  5100. if (!value) goto failed;
  5101. if (PyObject_SetAttr(result, state->args, value) == -1)
  5102. goto failed;
  5103. Py_DECREF(value);
  5104. value = ast2obj_arg(state, vstate, o->vararg);
  5105. if (!value) goto failed;
  5106. if (PyObject_SetAttr(result, state->vararg, value) == -1)
  5107. goto failed;
  5108. Py_DECREF(value);
  5109. value = ast2obj_list(state, vstate, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
  5110. if (!value) goto failed;
  5111. if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
  5112. goto failed;
  5113. Py_DECREF(value);
  5114. value = ast2obj_list(state, vstate, (asdl_seq*)o->kw_defaults,
  5115. ast2obj_expr);
  5116. if (!value) goto failed;
  5117. if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
  5118. goto failed;
  5119. Py_DECREF(value);
  5120. value = ast2obj_arg(state, vstate, o->kwarg);
  5121. if (!value) goto failed;
  5122. if (PyObject_SetAttr(result, state->kwarg, value) == -1)
  5123. goto failed;
  5124. Py_DECREF(value);
  5125. value = ast2obj_list(state, vstate, (asdl_seq*)o->defaults, ast2obj_expr);
  5126. if (!value) goto failed;
  5127. if (PyObject_SetAttr(result, state->defaults, value) == -1)
  5128. goto failed;
  5129. Py_DECREF(value);
  5130. vstate->recursion_depth--;
  5131. return result;
  5132. failed:
  5133. vstate->recursion_depth--;
  5134. Py_XDECREF(value);
  5135. Py_XDECREF(result);
  5136. return NULL;
  5137. }
  5138. PyObject*
  5139. ast2obj_arg(struct ast_state *state, struct validator *vstate, void* _o)
  5140. {
  5141. arg_ty o = (arg_ty)_o;
  5142. PyObject *result = NULL, *value = NULL;
  5143. PyTypeObject *tp;
  5144. if (!o) {
  5145. Py_RETURN_NONE;
  5146. }
  5147. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5148. PyErr_SetString(PyExc_RecursionError,
  5149. "maximum recursion depth exceeded during ast construction");
  5150. return 0;
  5151. }
  5152. tp = (PyTypeObject *)state->arg_type;
  5153. result = PyType_GenericNew(tp, NULL, NULL);
  5154. if (!result) return NULL;
  5155. value = ast2obj_identifier(state, vstate, o->arg);
  5156. if (!value) goto failed;
  5157. if (PyObject_SetAttr(result, state->arg, value) == -1)
  5158. goto failed;
  5159. Py_DECREF(value);
  5160. value = ast2obj_expr(state, vstate, o->annotation);
  5161. if (!value) goto failed;
  5162. if (PyObject_SetAttr(result, state->annotation, value) == -1)
  5163. goto failed;
  5164. Py_DECREF(value);
  5165. value = ast2obj_string(state, vstate, o->type_comment);
  5166. if (!value) goto failed;
  5167. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  5168. goto failed;
  5169. Py_DECREF(value);
  5170. value = ast2obj_int(state, vstate, o->lineno);
  5171. if (!value) goto failed;
  5172. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5173. goto failed;
  5174. Py_DECREF(value);
  5175. value = ast2obj_int(state, vstate, o->col_offset);
  5176. if (!value) goto failed;
  5177. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5178. goto failed;
  5179. Py_DECREF(value);
  5180. value = ast2obj_int(state, vstate, o->end_lineno);
  5181. if (!value) goto failed;
  5182. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5183. goto failed;
  5184. Py_DECREF(value);
  5185. value = ast2obj_int(state, vstate, o->end_col_offset);
  5186. if (!value) goto failed;
  5187. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5188. goto failed;
  5189. Py_DECREF(value);
  5190. vstate->recursion_depth--;
  5191. return result;
  5192. failed:
  5193. vstate->recursion_depth--;
  5194. Py_XDECREF(value);
  5195. Py_XDECREF(result);
  5196. return NULL;
  5197. }
  5198. PyObject*
  5199. ast2obj_keyword(struct ast_state *state, struct validator *vstate, void* _o)
  5200. {
  5201. keyword_ty o = (keyword_ty)_o;
  5202. PyObject *result = NULL, *value = NULL;
  5203. PyTypeObject *tp;
  5204. if (!o) {
  5205. Py_RETURN_NONE;
  5206. }
  5207. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5208. PyErr_SetString(PyExc_RecursionError,
  5209. "maximum recursion depth exceeded during ast construction");
  5210. return 0;
  5211. }
  5212. tp = (PyTypeObject *)state->keyword_type;
  5213. result = PyType_GenericNew(tp, NULL, NULL);
  5214. if (!result) return NULL;
  5215. value = ast2obj_identifier(state, vstate, o->arg);
  5216. if (!value) goto failed;
  5217. if (PyObject_SetAttr(result, state->arg, value) == -1)
  5218. goto failed;
  5219. Py_DECREF(value);
  5220. value = ast2obj_expr(state, vstate, o->value);
  5221. if (!value) goto failed;
  5222. if (PyObject_SetAttr(result, state->value, value) == -1)
  5223. goto failed;
  5224. Py_DECREF(value);
  5225. value = ast2obj_int(state, vstate, o->lineno);
  5226. if (!value) goto failed;
  5227. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5228. goto failed;
  5229. Py_DECREF(value);
  5230. value = ast2obj_int(state, vstate, o->col_offset);
  5231. if (!value) goto failed;
  5232. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5233. goto failed;
  5234. Py_DECREF(value);
  5235. value = ast2obj_int(state, vstate, o->end_lineno);
  5236. if (!value) goto failed;
  5237. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5238. goto failed;
  5239. Py_DECREF(value);
  5240. value = ast2obj_int(state, vstate, o->end_col_offset);
  5241. if (!value) goto failed;
  5242. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5243. goto failed;
  5244. Py_DECREF(value);
  5245. vstate->recursion_depth--;
  5246. return result;
  5247. failed:
  5248. vstate->recursion_depth--;
  5249. Py_XDECREF(value);
  5250. Py_XDECREF(result);
  5251. return NULL;
  5252. }
  5253. PyObject*
  5254. ast2obj_alias(struct ast_state *state, struct validator *vstate, void* _o)
  5255. {
  5256. alias_ty o = (alias_ty)_o;
  5257. PyObject *result = NULL, *value = NULL;
  5258. PyTypeObject *tp;
  5259. if (!o) {
  5260. Py_RETURN_NONE;
  5261. }
  5262. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5263. PyErr_SetString(PyExc_RecursionError,
  5264. "maximum recursion depth exceeded during ast construction");
  5265. return 0;
  5266. }
  5267. tp = (PyTypeObject *)state->alias_type;
  5268. result = PyType_GenericNew(tp, NULL, NULL);
  5269. if (!result) return NULL;
  5270. value = ast2obj_identifier(state, vstate, o->name);
  5271. if (!value) goto failed;
  5272. if (PyObject_SetAttr(result, state->name, value) == -1)
  5273. goto failed;
  5274. Py_DECREF(value);
  5275. value = ast2obj_identifier(state, vstate, o->asname);
  5276. if (!value) goto failed;
  5277. if (PyObject_SetAttr(result, state->asname, value) == -1)
  5278. goto failed;
  5279. Py_DECREF(value);
  5280. value = ast2obj_int(state, vstate, o->lineno);
  5281. if (!value) goto failed;
  5282. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5283. goto failed;
  5284. Py_DECREF(value);
  5285. value = ast2obj_int(state, vstate, o->col_offset);
  5286. if (!value) goto failed;
  5287. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5288. goto failed;
  5289. Py_DECREF(value);
  5290. value = ast2obj_int(state, vstate, o->end_lineno);
  5291. if (!value) goto failed;
  5292. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5293. goto failed;
  5294. Py_DECREF(value);
  5295. value = ast2obj_int(state, vstate, o->end_col_offset);
  5296. if (!value) goto failed;
  5297. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5298. goto failed;
  5299. Py_DECREF(value);
  5300. vstate->recursion_depth--;
  5301. return result;
  5302. failed:
  5303. vstate->recursion_depth--;
  5304. Py_XDECREF(value);
  5305. Py_XDECREF(result);
  5306. return NULL;
  5307. }
  5308. PyObject*
  5309. ast2obj_withitem(struct ast_state *state, struct validator *vstate, void* _o)
  5310. {
  5311. withitem_ty o = (withitem_ty)_o;
  5312. PyObject *result = NULL, *value = NULL;
  5313. PyTypeObject *tp;
  5314. if (!o) {
  5315. Py_RETURN_NONE;
  5316. }
  5317. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5318. PyErr_SetString(PyExc_RecursionError,
  5319. "maximum recursion depth exceeded during ast construction");
  5320. return 0;
  5321. }
  5322. tp = (PyTypeObject *)state->withitem_type;
  5323. result = PyType_GenericNew(tp, NULL, NULL);
  5324. if (!result) return NULL;
  5325. value = ast2obj_expr(state, vstate, o->context_expr);
  5326. if (!value) goto failed;
  5327. if (PyObject_SetAttr(result, state->context_expr, value) == -1)
  5328. goto failed;
  5329. Py_DECREF(value);
  5330. value = ast2obj_expr(state, vstate, o->optional_vars);
  5331. if (!value) goto failed;
  5332. if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
  5333. goto failed;
  5334. Py_DECREF(value);
  5335. vstate->recursion_depth--;
  5336. return result;
  5337. failed:
  5338. vstate->recursion_depth--;
  5339. Py_XDECREF(value);
  5340. Py_XDECREF(result);
  5341. return NULL;
  5342. }
  5343. PyObject*
  5344. ast2obj_match_case(struct ast_state *state, struct validator *vstate, void* _o)
  5345. {
  5346. match_case_ty o = (match_case_ty)_o;
  5347. PyObject *result = NULL, *value = NULL;
  5348. PyTypeObject *tp;
  5349. if (!o) {
  5350. Py_RETURN_NONE;
  5351. }
  5352. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5353. PyErr_SetString(PyExc_RecursionError,
  5354. "maximum recursion depth exceeded during ast construction");
  5355. return 0;
  5356. }
  5357. tp = (PyTypeObject *)state->match_case_type;
  5358. result = PyType_GenericNew(tp, NULL, NULL);
  5359. if (!result) return NULL;
  5360. value = ast2obj_pattern(state, vstate, o->pattern);
  5361. if (!value) goto failed;
  5362. if (PyObject_SetAttr(result, state->pattern, value) == -1)
  5363. goto failed;
  5364. Py_DECREF(value);
  5365. value = ast2obj_expr(state, vstate, o->guard);
  5366. if (!value) goto failed;
  5367. if (PyObject_SetAttr(result, state->guard, value) == -1)
  5368. goto failed;
  5369. Py_DECREF(value);
  5370. value = ast2obj_list(state, vstate, (asdl_seq*)o->body, ast2obj_stmt);
  5371. if (!value) goto failed;
  5372. if (PyObject_SetAttr(result, state->body, value) == -1)
  5373. goto failed;
  5374. Py_DECREF(value);
  5375. vstate->recursion_depth--;
  5376. return result;
  5377. failed:
  5378. vstate->recursion_depth--;
  5379. Py_XDECREF(value);
  5380. Py_XDECREF(result);
  5381. return NULL;
  5382. }
  5383. PyObject*
  5384. ast2obj_pattern(struct ast_state *state, struct validator *vstate, void* _o)
  5385. {
  5386. pattern_ty o = (pattern_ty)_o;
  5387. PyObject *result = NULL, *value = NULL;
  5388. PyTypeObject *tp;
  5389. if (!o) {
  5390. Py_RETURN_NONE;
  5391. }
  5392. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5393. PyErr_SetString(PyExc_RecursionError,
  5394. "maximum recursion depth exceeded during ast construction");
  5395. return 0;
  5396. }
  5397. switch (o->kind) {
  5398. case MatchValue_kind:
  5399. tp = (PyTypeObject *)state->MatchValue_type;
  5400. result = PyType_GenericNew(tp, NULL, NULL);
  5401. if (!result) goto failed;
  5402. value = ast2obj_expr(state, vstate, o->v.MatchValue.value);
  5403. if (!value) goto failed;
  5404. if (PyObject_SetAttr(result, state->value, value) == -1)
  5405. goto failed;
  5406. Py_DECREF(value);
  5407. break;
  5408. case MatchSingleton_kind:
  5409. tp = (PyTypeObject *)state->MatchSingleton_type;
  5410. result = PyType_GenericNew(tp, NULL, NULL);
  5411. if (!result) goto failed;
  5412. value = ast2obj_constant(state, vstate, o->v.MatchSingleton.value);
  5413. if (!value) goto failed;
  5414. if (PyObject_SetAttr(result, state->value, value) == -1)
  5415. goto failed;
  5416. Py_DECREF(value);
  5417. break;
  5418. case MatchSequence_kind:
  5419. tp = (PyTypeObject *)state->MatchSequence_type;
  5420. result = PyType_GenericNew(tp, NULL, NULL);
  5421. if (!result) goto failed;
  5422. value = ast2obj_list(state, vstate,
  5423. (asdl_seq*)o->v.MatchSequence.patterns,
  5424. ast2obj_pattern);
  5425. if (!value) goto failed;
  5426. if (PyObject_SetAttr(result, state->patterns, value) == -1)
  5427. goto failed;
  5428. Py_DECREF(value);
  5429. break;
  5430. case MatchMapping_kind:
  5431. tp = (PyTypeObject *)state->MatchMapping_type;
  5432. result = PyType_GenericNew(tp, NULL, NULL);
  5433. if (!result) goto failed;
  5434. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.MatchMapping.keys,
  5435. ast2obj_expr);
  5436. if (!value) goto failed;
  5437. if (PyObject_SetAttr(result, state->keys, value) == -1)
  5438. goto failed;
  5439. Py_DECREF(value);
  5440. value = ast2obj_list(state, vstate,
  5441. (asdl_seq*)o->v.MatchMapping.patterns,
  5442. ast2obj_pattern);
  5443. if (!value) goto failed;
  5444. if (PyObject_SetAttr(result, state->patterns, value) == -1)
  5445. goto failed;
  5446. Py_DECREF(value);
  5447. value = ast2obj_identifier(state, vstate, o->v.MatchMapping.rest);
  5448. if (!value) goto failed;
  5449. if (PyObject_SetAttr(result, state->rest, value) == -1)
  5450. goto failed;
  5451. Py_DECREF(value);
  5452. break;
  5453. case MatchClass_kind:
  5454. tp = (PyTypeObject *)state->MatchClass_type;
  5455. result = PyType_GenericNew(tp, NULL, NULL);
  5456. if (!result) goto failed;
  5457. value = ast2obj_expr(state, vstate, o->v.MatchClass.cls);
  5458. if (!value) goto failed;
  5459. if (PyObject_SetAttr(result, state->cls, value) == -1)
  5460. goto failed;
  5461. Py_DECREF(value);
  5462. value = ast2obj_list(state, vstate,
  5463. (asdl_seq*)o->v.MatchClass.patterns,
  5464. ast2obj_pattern);
  5465. if (!value) goto failed;
  5466. if (PyObject_SetAttr(result, state->patterns, value) == -1)
  5467. goto failed;
  5468. Py_DECREF(value);
  5469. value = ast2obj_list(state, vstate,
  5470. (asdl_seq*)o->v.MatchClass.kwd_attrs,
  5471. ast2obj_identifier);
  5472. if (!value) goto failed;
  5473. if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
  5474. goto failed;
  5475. Py_DECREF(value);
  5476. value = ast2obj_list(state, vstate,
  5477. (asdl_seq*)o->v.MatchClass.kwd_patterns,
  5478. ast2obj_pattern);
  5479. if (!value) goto failed;
  5480. if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
  5481. goto failed;
  5482. Py_DECREF(value);
  5483. break;
  5484. case MatchStar_kind:
  5485. tp = (PyTypeObject *)state->MatchStar_type;
  5486. result = PyType_GenericNew(tp, NULL, NULL);
  5487. if (!result) goto failed;
  5488. value = ast2obj_identifier(state, vstate, o->v.MatchStar.name);
  5489. if (!value) goto failed;
  5490. if (PyObject_SetAttr(result, state->name, value) == -1)
  5491. goto failed;
  5492. Py_DECREF(value);
  5493. break;
  5494. case MatchAs_kind:
  5495. tp = (PyTypeObject *)state->MatchAs_type;
  5496. result = PyType_GenericNew(tp, NULL, NULL);
  5497. if (!result) goto failed;
  5498. value = ast2obj_pattern(state, vstate, o->v.MatchAs.pattern);
  5499. if (!value) goto failed;
  5500. if (PyObject_SetAttr(result, state->pattern, value) == -1)
  5501. goto failed;
  5502. Py_DECREF(value);
  5503. value = ast2obj_identifier(state, vstate, o->v.MatchAs.name);
  5504. if (!value) goto failed;
  5505. if (PyObject_SetAttr(result, state->name, value) == -1)
  5506. goto failed;
  5507. Py_DECREF(value);
  5508. break;
  5509. case MatchOr_kind:
  5510. tp = (PyTypeObject *)state->MatchOr_type;
  5511. result = PyType_GenericNew(tp, NULL, NULL);
  5512. if (!result) goto failed;
  5513. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.MatchOr.patterns,
  5514. ast2obj_pattern);
  5515. if (!value) goto failed;
  5516. if (PyObject_SetAttr(result, state->patterns, value) == -1)
  5517. goto failed;
  5518. Py_DECREF(value);
  5519. break;
  5520. }
  5521. value = ast2obj_int(state, vstate, o->lineno);
  5522. if (!value) goto failed;
  5523. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5524. goto failed;
  5525. Py_DECREF(value);
  5526. value = ast2obj_int(state, vstate, o->col_offset);
  5527. if (!value) goto failed;
  5528. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5529. goto failed;
  5530. Py_DECREF(value);
  5531. value = ast2obj_int(state, vstate, o->end_lineno);
  5532. if (!value) goto failed;
  5533. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5534. goto failed;
  5535. Py_DECREF(value);
  5536. value = ast2obj_int(state, vstate, o->end_col_offset);
  5537. if (!value) goto failed;
  5538. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5539. goto failed;
  5540. Py_DECREF(value);
  5541. vstate->recursion_depth--;
  5542. return result;
  5543. failed:
  5544. vstate->recursion_depth--;
  5545. Py_XDECREF(value);
  5546. Py_XDECREF(result);
  5547. return NULL;
  5548. }
  5549. PyObject*
  5550. ast2obj_type_ignore(struct ast_state *state, struct validator *vstate, void* _o)
  5551. {
  5552. type_ignore_ty o = (type_ignore_ty)_o;
  5553. PyObject *result = NULL, *value = NULL;
  5554. PyTypeObject *tp;
  5555. if (!o) {
  5556. Py_RETURN_NONE;
  5557. }
  5558. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5559. PyErr_SetString(PyExc_RecursionError,
  5560. "maximum recursion depth exceeded during ast construction");
  5561. return 0;
  5562. }
  5563. switch (o->kind) {
  5564. case TypeIgnore_kind:
  5565. tp = (PyTypeObject *)state->TypeIgnore_type;
  5566. result = PyType_GenericNew(tp, NULL, NULL);
  5567. if (!result) goto failed;
  5568. value = ast2obj_int(state, vstate, o->v.TypeIgnore.lineno);
  5569. if (!value) goto failed;
  5570. if (PyObject_SetAttr(result, state->lineno, value) == -1)
  5571. goto failed;
  5572. Py_DECREF(value);
  5573. value = ast2obj_string(state, vstate, o->v.TypeIgnore.tag);
  5574. if (!value) goto failed;
  5575. if (PyObject_SetAttr(result, state->tag, value) == -1)
  5576. goto failed;
  5577. Py_DECREF(value);
  5578. break;
  5579. }
  5580. vstate->recursion_depth--;
  5581. return result;
  5582. failed:
  5583. vstate->recursion_depth--;
  5584. Py_XDECREF(value);
  5585. Py_XDECREF(result);
  5586. return NULL;
  5587. }
  5588. PyObject*
  5589. ast2obj_type_param(struct ast_state *state, struct validator *vstate, void* _o)
  5590. {
  5591. type_param_ty o = (type_param_ty)_o;
  5592. PyObject *result = NULL, *value = NULL;
  5593. PyTypeObject *tp;
  5594. if (!o) {
  5595. Py_RETURN_NONE;
  5596. }
  5597. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5598. PyErr_SetString(PyExc_RecursionError,
  5599. "maximum recursion depth exceeded during ast construction");
  5600. return 0;
  5601. }
  5602. switch (o->kind) {
  5603. case TypeVar_kind:
  5604. tp = (PyTypeObject *)state->TypeVar_type;
  5605. result = PyType_GenericNew(tp, NULL, NULL);
  5606. if (!result) goto failed;
  5607. value = ast2obj_identifier(state, vstate, o->v.TypeVar.name);
  5608. if (!value) goto failed;
  5609. if (PyObject_SetAttr(result, state->name, value) == -1)
  5610. goto failed;
  5611. Py_DECREF(value);
  5612. value = ast2obj_expr(state, vstate, o->v.TypeVar.bound);
  5613. if (!value) goto failed;
  5614. if (PyObject_SetAttr(result, state->bound, value) == -1)
  5615. goto failed;
  5616. Py_DECREF(value);
  5617. break;
  5618. case ParamSpec_kind:
  5619. tp = (PyTypeObject *)state->ParamSpec_type;
  5620. result = PyType_GenericNew(tp, NULL, NULL);
  5621. if (!result) goto failed;
  5622. value = ast2obj_identifier(state, vstate, o->v.ParamSpec.name);
  5623. if (!value) goto failed;
  5624. if (PyObject_SetAttr(result, state->name, value) == -1)
  5625. goto failed;
  5626. Py_DECREF(value);
  5627. break;
  5628. case TypeVarTuple_kind:
  5629. tp = (PyTypeObject *)state->TypeVarTuple_type;
  5630. result = PyType_GenericNew(tp, NULL, NULL);
  5631. if (!result) goto failed;
  5632. value = ast2obj_identifier(state, vstate, o->v.TypeVarTuple.name);
  5633. if (!value) goto failed;
  5634. if (PyObject_SetAttr(result, state->name, value) == -1)
  5635. goto failed;
  5636. Py_DECREF(value);
  5637. break;
  5638. }
  5639. value = ast2obj_int(state, vstate, o->lineno);
  5640. if (!value) goto failed;
  5641. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5642. goto failed;
  5643. Py_DECREF(value);
  5644. value = ast2obj_int(state, vstate, o->col_offset);
  5645. if (!value) goto failed;
  5646. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5647. goto failed;
  5648. Py_DECREF(value);
  5649. value = ast2obj_int(state, vstate, o->end_lineno);
  5650. if (!value) goto failed;
  5651. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5652. goto failed;
  5653. Py_DECREF(value);
  5654. value = ast2obj_int(state, vstate, o->end_col_offset);
  5655. if (!value) goto failed;
  5656. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5657. goto failed;
  5658. Py_DECREF(value);
  5659. vstate->recursion_depth--;
  5660. return result;
  5661. failed:
  5662. vstate->recursion_depth--;
  5663. Py_XDECREF(value);
  5664. Py_XDECREF(result);
  5665. return NULL;
  5666. }
  5667. int
  5668. obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
  5669. {
  5670. int isinstance;
  5671. PyObject *tmp = NULL;
  5672. PyObject *tp;
  5673. if (obj == Py_None) {
  5674. *out = NULL;
  5675. return 0;
  5676. }
  5677. tp = state->Module_type;
  5678. isinstance = PyObject_IsInstance(obj, tp);
  5679. if (isinstance == -1) {
  5680. return 1;
  5681. }
  5682. if (isinstance) {
  5683. asdl_stmt_seq* body;
  5684. asdl_type_ignore_seq* type_ignores;
  5685. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  5686. return 1;
  5687. }
  5688. if (tmp == NULL) {
  5689. tmp = PyList_New(0);
  5690. if (tmp == NULL) {
  5691. return 1;
  5692. }
  5693. }
  5694. {
  5695. int res;
  5696. Py_ssize_t len;
  5697. Py_ssize_t i;
  5698. if (!PyList_Check(tmp)) {
  5699. PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  5700. goto failed;
  5701. }
  5702. len = PyList_GET_SIZE(tmp);
  5703. body = _Py_asdl_stmt_seq_new(len, arena);
  5704. if (body == NULL) goto failed;
  5705. for (i = 0; i < len; i++) {
  5706. stmt_ty val;
  5707. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  5708. if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
  5709. goto failed;
  5710. }
  5711. res = obj2ast_stmt(state, tmp2, &val, arena);
  5712. _Py_LeaveRecursiveCall();
  5713. Py_DECREF(tmp2);
  5714. if (res != 0) goto failed;
  5715. if (len != PyList_GET_SIZE(tmp)) {
  5716. PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
  5717. goto failed;
  5718. }
  5719. asdl_seq_SET(body, i, val);
  5720. }
  5721. Py_CLEAR(tmp);
  5722. }
  5723. if (_PyObject_LookupAttr(obj, state->type_ignores, &tmp) < 0) {
  5724. return 1;
  5725. }
  5726. if (tmp == NULL) {
  5727. tmp = PyList_New(0);
  5728. if (tmp == NULL) {
  5729. return 1;
  5730. }
  5731. }
  5732. {
  5733. int res;
  5734. Py_ssize_t len;
  5735. Py_ssize_t i;
  5736. if (!PyList_Check(tmp)) {
  5737. PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  5738. goto failed;
  5739. }
  5740. len = PyList_GET_SIZE(tmp);
  5741. type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
  5742. if (type_ignores == NULL) goto failed;
  5743. for (i = 0; i < len; i++) {
  5744. type_ignore_ty val;
  5745. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  5746. if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
  5747. goto failed;
  5748. }
  5749. res = obj2ast_type_ignore(state, tmp2, &val, arena);
  5750. _Py_LeaveRecursiveCall();
  5751. Py_DECREF(tmp2);
  5752. if (res != 0) goto failed;
  5753. if (len != PyList_GET_SIZE(tmp)) {
  5754. PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
  5755. goto failed;
  5756. }
  5757. asdl_seq_SET(type_ignores, i, val);
  5758. }
  5759. Py_CLEAR(tmp);
  5760. }
  5761. *out = _PyAST_Module(body, type_ignores, arena);
  5762. if (*out == NULL) goto failed;
  5763. return 0;
  5764. }
  5765. tp = state->Interactive_type;
  5766. isinstance = PyObject_IsInstance(obj, tp);
  5767. if (isinstance == -1) {
  5768. return 1;
  5769. }
  5770. if (isinstance) {
  5771. asdl_stmt_seq* body;
  5772. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  5773. return 1;
  5774. }
  5775. if (tmp == NULL) {
  5776. tmp = PyList_New(0);
  5777. if (tmp == NULL) {
  5778. return 1;
  5779. }
  5780. }
  5781. {
  5782. int res;
  5783. Py_ssize_t len;
  5784. Py_ssize_t i;
  5785. if (!PyList_Check(tmp)) {
  5786. PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  5787. goto failed;
  5788. }
  5789. len = PyList_GET_SIZE(tmp);
  5790. body = _Py_asdl_stmt_seq_new(len, arena);
  5791. if (body == NULL) goto failed;
  5792. for (i = 0; i < len; i++) {
  5793. stmt_ty val;
  5794. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  5795. if (_Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
  5796. goto failed;
  5797. }
  5798. res = obj2ast_stmt(state, tmp2, &val, arena);
  5799. _Py_LeaveRecursiveCall();
  5800. Py_DECREF(tmp2);
  5801. if (res != 0) goto failed;
  5802. if (len != PyList_GET_SIZE(tmp)) {
  5803. PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
  5804. goto failed;
  5805. }
  5806. asdl_seq_SET(body, i, val);
  5807. }
  5808. Py_CLEAR(tmp);
  5809. }
  5810. *out = _PyAST_Interactive(body, arena);
  5811. if (*out == NULL) goto failed;
  5812. return 0;
  5813. }
  5814. tp = state->Expression_type;
  5815. isinstance = PyObject_IsInstance(obj, tp);
  5816. if (isinstance == -1) {
  5817. return 1;
  5818. }
  5819. if (isinstance) {
  5820. expr_ty body;
  5821. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  5822. return 1;
  5823. }
  5824. if (tmp == NULL) {
  5825. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
  5826. return 1;
  5827. }
  5828. else {
  5829. int res;
  5830. if (_Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
  5831. goto failed;
  5832. }
  5833. res = obj2ast_expr(state, tmp, &body, arena);
  5834. _Py_LeaveRecursiveCall();
  5835. if (res != 0) goto failed;
  5836. Py_CLEAR(tmp);
  5837. }
  5838. *out = _PyAST_Expression(body, arena);
  5839. if (*out == NULL) goto failed;
  5840. return 0;
  5841. }
  5842. tp = state->FunctionType_type;
  5843. isinstance = PyObject_IsInstance(obj, tp);
  5844. if (isinstance == -1) {
  5845. return 1;
  5846. }
  5847. if (isinstance) {
  5848. asdl_expr_seq* argtypes;
  5849. expr_ty returns;
  5850. if (_PyObject_LookupAttr(obj, state->argtypes, &tmp) < 0) {
  5851. return 1;
  5852. }
  5853. if (tmp == NULL) {
  5854. tmp = PyList_New(0);
  5855. if (tmp == NULL) {
  5856. return 1;
  5857. }
  5858. }
  5859. {
  5860. int res;
  5861. Py_ssize_t len;
  5862. Py_ssize_t i;
  5863. if (!PyList_Check(tmp)) {
  5864. PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  5865. goto failed;
  5866. }
  5867. len = PyList_GET_SIZE(tmp);
  5868. argtypes = _Py_asdl_expr_seq_new(len, arena);
  5869. if (argtypes == NULL) goto failed;
  5870. for (i = 0; i < len; i++) {
  5871. expr_ty val;
  5872. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  5873. if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
  5874. goto failed;
  5875. }
  5876. res = obj2ast_expr(state, tmp2, &val, arena);
  5877. _Py_LeaveRecursiveCall();
  5878. Py_DECREF(tmp2);
  5879. if (res != 0) goto failed;
  5880. if (len != PyList_GET_SIZE(tmp)) {
  5881. PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
  5882. goto failed;
  5883. }
  5884. asdl_seq_SET(argtypes, i, val);
  5885. }
  5886. Py_CLEAR(tmp);
  5887. }
  5888. if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
  5889. return 1;
  5890. }
  5891. if (tmp == NULL) {
  5892. PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
  5893. return 1;
  5894. }
  5895. else {
  5896. int res;
  5897. if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
  5898. goto failed;
  5899. }
  5900. res = obj2ast_expr(state, tmp, &returns, arena);
  5901. _Py_LeaveRecursiveCall();
  5902. if (res != 0) goto failed;
  5903. Py_CLEAR(tmp);
  5904. }
  5905. *out = _PyAST_FunctionType(argtypes, returns, arena);
  5906. if (*out == NULL) goto failed;
  5907. return 0;
  5908. }
  5909. PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
  5910. failed:
  5911. Py_XDECREF(tmp);
  5912. return 1;
  5913. }
  5914. int
  5915. obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
  5916. arena)
  5917. {
  5918. int isinstance;
  5919. PyObject *tmp = NULL;
  5920. PyObject *tp;
  5921. int lineno;
  5922. int col_offset;
  5923. int end_lineno;
  5924. int end_col_offset;
  5925. if (obj == Py_None) {
  5926. *out = NULL;
  5927. return 0;
  5928. }
  5929. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  5930. return 1;
  5931. }
  5932. if (tmp == NULL) {
  5933. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
  5934. return 1;
  5935. }
  5936. else {
  5937. int res;
  5938. if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
  5939. goto failed;
  5940. }
  5941. res = obj2ast_int(state, tmp, &lineno, arena);
  5942. _Py_LeaveRecursiveCall();
  5943. if (res != 0) goto failed;
  5944. Py_CLEAR(tmp);
  5945. }
  5946. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  5947. return 1;
  5948. }
  5949. if (tmp == NULL) {
  5950. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
  5951. return 1;
  5952. }
  5953. else {
  5954. int res;
  5955. if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
  5956. goto failed;
  5957. }
  5958. res = obj2ast_int(state, tmp, &col_offset, arena);
  5959. _Py_LeaveRecursiveCall();
  5960. if (res != 0) goto failed;
  5961. Py_CLEAR(tmp);
  5962. }
  5963. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  5964. return 1;
  5965. }
  5966. if (tmp == NULL || tmp == Py_None) {
  5967. Py_CLEAR(tmp);
  5968. end_lineno = lineno;
  5969. }
  5970. else {
  5971. int res;
  5972. if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
  5973. goto failed;
  5974. }
  5975. res = obj2ast_int(state, tmp, &end_lineno, arena);
  5976. _Py_LeaveRecursiveCall();
  5977. if (res != 0) goto failed;
  5978. Py_CLEAR(tmp);
  5979. }
  5980. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  5981. return 1;
  5982. }
  5983. if (tmp == NULL || tmp == Py_None) {
  5984. Py_CLEAR(tmp);
  5985. end_col_offset = col_offset;
  5986. }
  5987. else {
  5988. int res;
  5989. if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
  5990. goto failed;
  5991. }
  5992. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  5993. _Py_LeaveRecursiveCall();
  5994. if (res != 0) goto failed;
  5995. Py_CLEAR(tmp);
  5996. }
  5997. tp = state->FunctionDef_type;
  5998. isinstance = PyObject_IsInstance(obj, tp);
  5999. if (isinstance == -1) {
  6000. return 1;
  6001. }
  6002. if (isinstance) {
  6003. identifier name;
  6004. arguments_ty args;
  6005. asdl_stmt_seq* body;
  6006. asdl_expr_seq* decorator_list;
  6007. expr_ty returns;
  6008. string type_comment;
  6009. asdl_type_param_seq* type_params;
  6010. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  6011. return 1;
  6012. }
  6013. if (tmp == NULL) {
  6014. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
  6015. return 1;
  6016. }
  6017. else {
  6018. int res;
  6019. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6020. goto failed;
  6021. }
  6022. res = obj2ast_identifier(state, tmp, &name, arena);
  6023. _Py_LeaveRecursiveCall();
  6024. if (res != 0) goto failed;
  6025. Py_CLEAR(tmp);
  6026. }
  6027. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  6028. return 1;
  6029. }
  6030. if (tmp == NULL) {
  6031. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
  6032. return 1;
  6033. }
  6034. else {
  6035. int res;
  6036. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6037. goto failed;
  6038. }
  6039. res = obj2ast_arguments(state, tmp, &args, arena);
  6040. _Py_LeaveRecursiveCall();
  6041. if (res != 0) goto failed;
  6042. Py_CLEAR(tmp);
  6043. }
  6044. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  6045. return 1;
  6046. }
  6047. if (tmp == NULL) {
  6048. tmp = PyList_New(0);
  6049. if (tmp == NULL) {
  6050. return 1;
  6051. }
  6052. }
  6053. {
  6054. int res;
  6055. Py_ssize_t len;
  6056. Py_ssize_t i;
  6057. if (!PyList_Check(tmp)) {
  6058. PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6059. goto failed;
  6060. }
  6061. len = PyList_GET_SIZE(tmp);
  6062. body = _Py_asdl_stmt_seq_new(len, arena);
  6063. if (body == NULL) goto failed;
  6064. for (i = 0; i < len; i++) {
  6065. stmt_ty val;
  6066. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6067. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6068. goto failed;
  6069. }
  6070. res = obj2ast_stmt(state, tmp2, &val, arena);
  6071. _Py_LeaveRecursiveCall();
  6072. Py_DECREF(tmp2);
  6073. if (res != 0) goto failed;
  6074. if (len != PyList_GET_SIZE(tmp)) {
  6075. PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
  6076. goto failed;
  6077. }
  6078. asdl_seq_SET(body, i, val);
  6079. }
  6080. Py_CLEAR(tmp);
  6081. }
  6082. if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
  6083. return 1;
  6084. }
  6085. if (tmp == NULL) {
  6086. tmp = PyList_New(0);
  6087. if (tmp == NULL) {
  6088. return 1;
  6089. }
  6090. }
  6091. {
  6092. int res;
  6093. Py_ssize_t len;
  6094. Py_ssize_t i;
  6095. if (!PyList_Check(tmp)) {
  6096. PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6097. goto failed;
  6098. }
  6099. len = PyList_GET_SIZE(tmp);
  6100. decorator_list = _Py_asdl_expr_seq_new(len, arena);
  6101. if (decorator_list == NULL) goto failed;
  6102. for (i = 0; i < len; i++) {
  6103. expr_ty val;
  6104. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6105. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6106. goto failed;
  6107. }
  6108. res = obj2ast_expr(state, tmp2, &val, arena);
  6109. _Py_LeaveRecursiveCall();
  6110. Py_DECREF(tmp2);
  6111. if (res != 0) goto failed;
  6112. if (len != PyList_GET_SIZE(tmp)) {
  6113. PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
  6114. goto failed;
  6115. }
  6116. asdl_seq_SET(decorator_list, i, val);
  6117. }
  6118. Py_CLEAR(tmp);
  6119. }
  6120. if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
  6121. return 1;
  6122. }
  6123. if (tmp == NULL || tmp == Py_None) {
  6124. Py_CLEAR(tmp);
  6125. returns = NULL;
  6126. }
  6127. else {
  6128. int res;
  6129. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6130. goto failed;
  6131. }
  6132. res = obj2ast_expr(state, tmp, &returns, arena);
  6133. _Py_LeaveRecursiveCall();
  6134. if (res != 0) goto failed;
  6135. Py_CLEAR(tmp);
  6136. }
  6137. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  6138. return 1;
  6139. }
  6140. if (tmp == NULL || tmp == Py_None) {
  6141. Py_CLEAR(tmp);
  6142. type_comment = NULL;
  6143. }
  6144. else {
  6145. int res;
  6146. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6147. goto failed;
  6148. }
  6149. res = obj2ast_string(state, tmp, &type_comment, arena);
  6150. _Py_LeaveRecursiveCall();
  6151. if (res != 0) goto failed;
  6152. Py_CLEAR(tmp);
  6153. }
  6154. if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
  6155. return 1;
  6156. }
  6157. if (tmp == NULL) {
  6158. tmp = PyList_New(0);
  6159. if (tmp == NULL) {
  6160. return 1;
  6161. }
  6162. }
  6163. {
  6164. int res;
  6165. Py_ssize_t len;
  6166. Py_ssize_t i;
  6167. if (!PyList_Check(tmp)) {
  6168. PyErr_Format(PyExc_TypeError, "FunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6169. goto failed;
  6170. }
  6171. len = PyList_GET_SIZE(tmp);
  6172. type_params = _Py_asdl_type_param_seq_new(len, arena);
  6173. if (type_params == NULL) goto failed;
  6174. for (i = 0; i < len; i++) {
  6175. type_param_ty val;
  6176. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6177. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6178. goto failed;
  6179. }
  6180. res = obj2ast_type_param(state, tmp2, &val, arena);
  6181. _Py_LeaveRecursiveCall();
  6182. Py_DECREF(tmp2);
  6183. if (res != 0) goto failed;
  6184. if (len != PyList_GET_SIZE(tmp)) {
  6185. PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"type_params\" changed size during iteration");
  6186. goto failed;
  6187. }
  6188. asdl_seq_SET(type_params, i, val);
  6189. }
  6190. Py_CLEAR(tmp);
  6191. }
  6192. *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
  6193. type_comment, type_params, lineno,
  6194. col_offset, end_lineno, end_col_offset,
  6195. arena);
  6196. if (*out == NULL) goto failed;
  6197. return 0;
  6198. }
  6199. tp = state->AsyncFunctionDef_type;
  6200. isinstance = PyObject_IsInstance(obj, tp);
  6201. if (isinstance == -1) {
  6202. return 1;
  6203. }
  6204. if (isinstance) {
  6205. identifier name;
  6206. arguments_ty args;
  6207. asdl_stmt_seq* body;
  6208. asdl_expr_seq* decorator_list;
  6209. expr_ty returns;
  6210. string type_comment;
  6211. asdl_type_param_seq* type_params;
  6212. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  6213. return 1;
  6214. }
  6215. if (tmp == NULL) {
  6216. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
  6217. return 1;
  6218. }
  6219. else {
  6220. int res;
  6221. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6222. goto failed;
  6223. }
  6224. res = obj2ast_identifier(state, tmp, &name, arena);
  6225. _Py_LeaveRecursiveCall();
  6226. if (res != 0) goto failed;
  6227. Py_CLEAR(tmp);
  6228. }
  6229. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  6230. return 1;
  6231. }
  6232. if (tmp == NULL) {
  6233. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
  6234. return 1;
  6235. }
  6236. else {
  6237. int res;
  6238. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6239. goto failed;
  6240. }
  6241. res = obj2ast_arguments(state, tmp, &args, arena);
  6242. _Py_LeaveRecursiveCall();
  6243. if (res != 0) goto failed;
  6244. Py_CLEAR(tmp);
  6245. }
  6246. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  6247. return 1;
  6248. }
  6249. if (tmp == NULL) {
  6250. tmp = PyList_New(0);
  6251. if (tmp == NULL) {
  6252. return 1;
  6253. }
  6254. }
  6255. {
  6256. int res;
  6257. Py_ssize_t len;
  6258. Py_ssize_t i;
  6259. if (!PyList_Check(tmp)) {
  6260. PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6261. goto failed;
  6262. }
  6263. len = PyList_GET_SIZE(tmp);
  6264. body = _Py_asdl_stmt_seq_new(len, arena);
  6265. if (body == NULL) goto failed;
  6266. for (i = 0; i < len; i++) {
  6267. stmt_ty val;
  6268. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6269. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6270. goto failed;
  6271. }
  6272. res = obj2ast_stmt(state, tmp2, &val, arena);
  6273. _Py_LeaveRecursiveCall();
  6274. Py_DECREF(tmp2);
  6275. if (res != 0) goto failed;
  6276. if (len != PyList_GET_SIZE(tmp)) {
  6277. PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
  6278. goto failed;
  6279. }
  6280. asdl_seq_SET(body, i, val);
  6281. }
  6282. Py_CLEAR(tmp);
  6283. }
  6284. if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
  6285. return 1;
  6286. }
  6287. if (tmp == NULL) {
  6288. tmp = PyList_New(0);
  6289. if (tmp == NULL) {
  6290. return 1;
  6291. }
  6292. }
  6293. {
  6294. int res;
  6295. Py_ssize_t len;
  6296. Py_ssize_t i;
  6297. if (!PyList_Check(tmp)) {
  6298. PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6299. goto failed;
  6300. }
  6301. len = PyList_GET_SIZE(tmp);
  6302. decorator_list = _Py_asdl_expr_seq_new(len, arena);
  6303. if (decorator_list == NULL) goto failed;
  6304. for (i = 0; i < len; i++) {
  6305. expr_ty val;
  6306. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6307. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6308. goto failed;
  6309. }
  6310. res = obj2ast_expr(state, tmp2, &val, arena);
  6311. _Py_LeaveRecursiveCall();
  6312. Py_DECREF(tmp2);
  6313. if (res != 0) goto failed;
  6314. if (len != PyList_GET_SIZE(tmp)) {
  6315. PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
  6316. goto failed;
  6317. }
  6318. asdl_seq_SET(decorator_list, i, val);
  6319. }
  6320. Py_CLEAR(tmp);
  6321. }
  6322. if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
  6323. return 1;
  6324. }
  6325. if (tmp == NULL || tmp == Py_None) {
  6326. Py_CLEAR(tmp);
  6327. returns = NULL;
  6328. }
  6329. else {
  6330. int res;
  6331. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6332. goto failed;
  6333. }
  6334. res = obj2ast_expr(state, tmp, &returns, arena);
  6335. _Py_LeaveRecursiveCall();
  6336. if (res != 0) goto failed;
  6337. Py_CLEAR(tmp);
  6338. }
  6339. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  6340. return 1;
  6341. }
  6342. if (tmp == NULL || tmp == Py_None) {
  6343. Py_CLEAR(tmp);
  6344. type_comment = NULL;
  6345. }
  6346. else {
  6347. int res;
  6348. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6349. goto failed;
  6350. }
  6351. res = obj2ast_string(state, tmp, &type_comment, arena);
  6352. _Py_LeaveRecursiveCall();
  6353. if (res != 0) goto failed;
  6354. Py_CLEAR(tmp);
  6355. }
  6356. if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
  6357. return 1;
  6358. }
  6359. if (tmp == NULL) {
  6360. tmp = PyList_New(0);
  6361. if (tmp == NULL) {
  6362. return 1;
  6363. }
  6364. }
  6365. {
  6366. int res;
  6367. Py_ssize_t len;
  6368. Py_ssize_t i;
  6369. if (!PyList_Check(tmp)) {
  6370. PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6371. goto failed;
  6372. }
  6373. len = PyList_GET_SIZE(tmp);
  6374. type_params = _Py_asdl_type_param_seq_new(len, arena);
  6375. if (type_params == NULL) goto failed;
  6376. for (i = 0; i < len; i++) {
  6377. type_param_ty val;
  6378. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6379. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6380. goto failed;
  6381. }
  6382. res = obj2ast_type_param(state, tmp2, &val, arena);
  6383. _Py_LeaveRecursiveCall();
  6384. Py_DECREF(tmp2);
  6385. if (res != 0) goto failed;
  6386. if (len != PyList_GET_SIZE(tmp)) {
  6387. PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"type_params\" changed size during iteration");
  6388. goto failed;
  6389. }
  6390. asdl_seq_SET(type_params, i, val);
  6391. }
  6392. Py_CLEAR(tmp);
  6393. }
  6394. *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
  6395. returns, type_comment, type_params,
  6396. lineno, col_offset, end_lineno,
  6397. end_col_offset, arena);
  6398. if (*out == NULL) goto failed;
  6399. return 0;
  6400. }
  6401. tp = state->ClassDef_type;
  6402. isinstance = PyObject_IsInstance(obj, tp);
  6403. if (isinstance == -1) {
  6404. return 1;
  6405. }
  6406. if (isinstance) {
  6407. identifier name;
  6408. asdl_expr_seq* bases;
  6409. asdl_keyword_seq* keywords;
  6410. asdl_stmt_seq* body;
  6411. asdl_expr_seq* decorator_list;
  6412. asdl_type_param_seq* type_params;
  6413. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  6414. return 1;
  6415. }
  6416. if (tmp == NULL) {
  6417. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
  6418. return 1;
  6419. }
  6420. else {
  6421. int res;
  6422. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6423. goto failed;
  6424. }
  6425. res = obj2ast_identifier(state, tmp, &name, arena);
  6426. _Py_LeaveRecursiveCall();
  6427. if (res != 0) goto failed;
  6428. Py_CLEAR(tmp);
  6429. }
  6430. if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
  6431. return 1;
  6432. }
  6433. if (tmp == NULL) {
  6434. tmp = PyList_New(0);
  6435. if (tmp == NULL) {
  6436. return 1;
  6437. }
  6438. }
  6439. {
  6440. int res;
  6441. Py_ssize_t len;
  6442. Py_ssize_t i;
  6443. if (!PyList_Check(tmp)) {
  6444. PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6445. goto failed;
  6446. }
  6447. len = PyList_GET_SIZE(tmp);
  6448. bases = _Py_asdl_expr_seq_new(len, arena);
  6449. if (bases == NULL) goto failed;
  6450. for (i = 0; i < len; i++) {
  6451. expr_ty val;
  6452. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6453. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6454. goto failed;
  6455. }
  6456. res = obj2ast_expr(state, tmp2, &val, arena);
  6457. _Py_LeaveRecursiveCall();
  6458. Py_DECREF(tmp2);
  6459. if (res != 0) goto failed;
  6460. if (len != PyList_GET_SIZE(tmp)) {
  6461. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
  6462. goto failed;
  6463. }
  6464. asdl_seq_SET(bases, i, val);
  6465. }
  6466. Py_CLEAR(tmp);
  6467. }
  6468. if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
  6469. return 1;
  6470. }
  6471. if (tmp == NULL) {
  6472. tmp = PyList_New(0);
  6473. if (tmp == NULL) {
  6474. return 1;
  6475. }
  6476. }
  6477. {
  6478. int res;
  6479. Py_ssize_t len;
  6480. Py_ssize_t i;
  6481. if (!PyList_Check(tmp)) {
  6482. PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6483. goto failed;
  6484. }
  6485. len = PyList_GET_SIZE(tmp);
  6486. keywords = _Py_asdl_keyword_seq_new(len, arena);
  6487. if (keywords == NULL) goto failed;
  6488. for (i = 0; i < len; i++) {
  6489. keyword_ty val;
  6490. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6491. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6492. goto failed;
  6493. }
  6494. res = obj2ast_keyword(state, tmp2, &val, arena);
  6495. _Py_LeaveRecursiveCall();
  6496. Py_DECREF(tmp2);
  6497. if (res != 0) goto failed;
  6498. if (len != PyList_GET_SIZE(tmp)) {
  6499. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
  6500. goto failed;
  6501. }
  6502. asdl_seq_SET(keywords, i, val);
  6503. }
  6504. Py_CLEAR(tmp);
  6505. }
  6506. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  6507. return 1;
  6508. }
  6509. if (tmp == NULL) {
  6510. tmp = PyList_New(0);
  6511. if (tmp == NULL) {
  6512. return 1;
  6513. }
  6514. }
  6515. {
  6516. int res;
  6517. Py_ssize_t len;
  6518. Py_ssize_t i;
  6519. if (!PyList_Check(tmp)) {
  6520. PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6521. goto failed;
  6522. }
  6523. len = PyList_GET_SIZE(tmp);
  6524. body = _Py_asdl_stmt_seq_new(len, arena);
  6525. if (body == NULL) goto failed;
  6526. for (i = 0; i < len; i++) {
  6527. stmt_ty val;
  6528. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6529. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6530. goto failed;
  6531. }
  6532. res = obj2ast_stmt(state, tmp2, &val, arena);
  6533. _Py_LeaveRecursiveCall();
  6534. Py_DECREF(tmp2);
  6535. if (res != 0) goto failed;
  6536. if (len != PyList_GET_SIZE(tmp)) {
  6537. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
  6538. goto failed;
  6539. }
  6540. asdl_seq_SET(body, i, val);
  6541. }
  6542. Py_CLEAR(tmp);
  6543. }
  6544. if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
  6545. return 1;
  6546. }
  6547. if (tmp == NULL) {
  6548. tmp = PyList_New(0);
  6549. if (tmp == NULL) {
  6550. return 1;
  6551. }
  6552. }
  6553. {
  6554. int res;
  6555. Py_ssize_t len;
  6556. Py_ssize_t i;
  6557. if (!PyList_Check(tmp)) {
  6558. PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6559. goto failed;
  6560. }
  6561. len = PyList_GET_SIZE(tmp);
  6562. decorator_list = _Py_asdl_expr_seq_new(len, arena);
  6563. if (decorator_list == NULL) goto failed;
  6564. for (i = 0; i < len; i++) {
  6565. expr_ty val;
  6566. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6567. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6568. goto failed;
  6569. }
  6570. res = obj2ast_expr(state, tmp2, &val, arena);
  6571. _Py_LeaveRecursiveCall();
  6572. Py_DECREF(tmp2);
  6573. if (res != 0) goto failed;
  6574. if (len != PyList_GET_SIZE(tmp)) {
  6575. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
  6576. goto failed;
  6577. }
  6578. asdl_seq_SET(decorator_list, i, val);
  6579. }
  6580. Py_CLEAR(tmp);
  6581. }
  6582. if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
  6583. return 1;
  6584. }
  6585. if (tmp == NULL) {
  6586. tmp = PyList_New(0);
  6587. if (tmp == NULL) {
  6588. return 1;
  6589. }
  6590. }
  6591. {
  6592. int res;
  6593. Py_ssize_t len;
  6594. Py_ssize_t i;
  6595. if (!PyList_Check(tmp)) {
  6596. PyErr_Format(PyExc_TypeError, "ClassDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6597. goto failed;
  6598. }
  6599. len = PyList_GET_SIZE(tmp);
  6600. type_params = _Py_asdl_type_param_seq_new(len, arena);
  6601. if (type_params == NULL) goto failed;
  6602. for (i = 0; i < len; i++) {
  6603. type_param_ty val;
  6604. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6605. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6606. goto failed;
  6607. }
  6608. res = obj2ast_type_param(state, tmp2, &val, arena);
  6609. _Py_LeaveRecursiveCall();
  6610. Py_DECREF(tmp2);
  6611. if (res != 0) goto failed;
  6612. if (len != PyList_GET_SIZE(tmp)) {
  6613. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"type_params\" changed size during iteration");
  6614. goto failed;
  6615. }
  6616. asdl_seq_SET(type_params, i, val);
  6617. }
  6618. Py_CLEAR(tmp);
  6619. }
  6620. *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
  6621. type_params, lineno, col_offset, end_lineno,
  6622. end_col_offset, arena);
  6623. if (*out == NULL) goto failed;
  6624. return 0;
  6625. }
  6626. tp = state->Return_type;
  6627. isinstance = PyObject_IsInstance(obj, tp);
  6628. if (isinstance == -1) {
  6629. return 1;
  6630. }
  6631. if (isinstance) {
  6632. expr_ty value;
  6633. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6634. return 1;
  6635. }
  6636. if (tmp == NULL || tmp == Py_None) {
  6637. Py_CLEAR(tmp);
  6638. value = NULL;
  6639. }
  6640. else {
  6641. int res;
  6642. if (_Py_EnterRecursiveCall(" while traversing 'Return' node")) {
  6643. goto failed;
  6644. }
  6645. res = obj2ast_expr(state, tmp, &value, arena);
  6646. _Py_LeaveRecursiveCall();
  6647. if (res != 0) goto failed;
  6648. Py_CLEAR(tmp);
  6649. }
  6650. *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
  6651. end_col_offset, arena);
  6652. if (*out == NULL) goto failed;
  6653. return 0;
  6654. }
  6655. tp = state->Delete_type;
  6656. isinstance = PyObject_IsInstance(obj, tp);
  6657. if (isinstance == -1) {
  6658. return 1;
  6659. }
  6660. if (isinstance) {
  6661. asdl_expr_seq* targets;
  6662. if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
  6663. return 1;
  6664. }
  6665. if (tmp == NULL) {
  6666. tmp = PyList_New(0);
  6667. if (tmp == NULL) {
  6668. return 1;
  6669. }
  6670. }
  6671. {
  6672. int res;
  6673. Py_ssize_t len;
  6674. Py_ssize_t i;
  6675. if (!PyList_Check(tmp)) {
  6676. PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6677. goto failed;
  6678. }
  6679. len = PyList_GET_SIZE(tmp);
  6680. targets = _Py_asdl_expr_seq_new(len, arena);
  6681. if (targets == NULL) goto failed;
  6682. for (i = 0; i < len; i++) {
  6683. expr_ty val;
  6684. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6685. if (_Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
  6686. goto failed;
  6687. }
  6688. res = obj2ast_expr(state, tmp2, &val, arena);
  6689. _Py_LeaveRecursiveCall();
  6690. Py_DECREF(tmp2);
  6691. if (res != 0) goto failed;
  6692. if (len != PyList_GET_SIZE(tmp)) {
  6693. PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
  6694. goto failed;
  6695. }
  6696. asdl_seq_SET(targets, i, val);
  6697. }
  6698. Py_CLEAR(tmp);
  6699. }
  6700. *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
  6701. end_col_offset, arena);
  6702. if (*out == NULL) goto failed;
  6703. return 0;
  6704. }
  6705. tp = state->Assign_type;
  6706. isinstance = PyObject_IsInstance(obj, tp);
  6707. if (isinstance == -1) {
  6708. return 1;
  6709. }
  6710. if (isinstance) {
  6711. asdl_expr_seq* targets;
  6712. expr_ty value;
  6713. string type_comment;
  6714. if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
  6715. return 1;
  6716. }
  6717. if (tmp == NULL) {
  6718. tmp = PyList_New(0);
  6719. if (tmp == NULL) {
  6720. return 1;
  6721. }
  6722. }
  6723. {
  6724. int res;
  6725. Py_ssize_t len;
  6726. Py_ssize_t i;
  6727. if (!PyList_Check(tmp)) {
  6728. PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6729. goto failed;
  6730. }
  6731. len = PyList_GET_SIZE(tmp);
  6732. targets = _Py_asdl_expr_seq_new(len, arena);
  6733. if (targets == NULL) goto failed;
  6734. for (i = 0; i < len; i++) {
  6735. expr_ty val;
  6736. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6737. if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
  6738. goto failed;
  6739. }
  6740. res = obj2ast_expr(state, tmp2, &val, arena);
  6741. _Py_LeaveRecursiveCall();
  6742. Py_DECREF(tmp2);
  6743. if (res != 0) goto failed;
  6744. if (len != PyList_GET_SIZE(tmp)) {
  6745. PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
  6746. goto failed;
  6747. }
  6748. asdl_seq_SET(targets, i, val);
  6749. }
  6750. Py_CLEAR(tmp);
  6751. }
  6752. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6753. return 1;
  6754. }
  6755. if (tmp == NULL) {
  6756. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
  6757. return 1;
  6758. }
  6759. else {
  6760. int res;
  6761. if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
  6762. goto failed;
  6763. }
  6764. res = obj2ast_expr(state, tmp, &value, arena);
  6765. _Py_LeaveRecursiveCall();
  6766. if (res != 0) goto failed;
  6767. Py_CLEAR(tmp);
  6768. }
  6769. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  6770. return 1;
  6771. }
  6772. if (tmp == NULL || tmp == Py_None) {
  6773. Py_CLEAR(tmp);
  6774. type_comment = NULL;
  6775. }
  6776. else {
  6777. int res;
  6778. if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
  6779. goto failed;
  6780. }
  6781. res = obj2ast_string(state, tmp, &type_comment, arena);
  6782. _Py_LeaveRecursiveCall();
  6783. if (res != 0) goto failed;
  6784. Py_CLEAR(tmp);
  6785. }
  6786. *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
  6787. end_lineno, end_col_offset, arena);
  6788. if (*out == NULL) goto failed;
  6789. return 0;
  6790. }
  6791. tp = state->TypeAlias_type;
  6792. isinstance = PyObject_IsInstance(obj, tp);
  6793. if (isinstance == -1) {
  6794. return 1;
  6795. }
  6796. if (isinstance) {
  6797. expr_ty name;
  6798. asdl_type_param_seq* type_params;
  6799. expr_ty value;
  6800. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  6801. return 1;
  6802. }
  6803. if (tmp == NULL) {
  6804. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeAlias");
  6805. return 1;
  6806. }
  6807. else {
  6808. int res;
  6809. if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
  6810. goto failed;
  6811. }
  6812. res = obj2ast_expr(state, tmp, &name, arena);
  6813. _Py_LeaveRecursiveCall();
  6814. if (res != 0) goto failed;
  6815. Py_CLEAR(tmp);
  6816. }
  6817. if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
  6818. return 1;
  6819. }
  6820. if (tmp == NULL) {
  6821. tmp = PyList_New(0);
  6822. if (tmp == NULL) {
  6823. return 1;
  6824. }
  6825. }
  6826. {
  6827. int res;
  6828. Py_ssize_t len;
  6829. Py_ssize_t i;
  6830. if (!PyList_Check(tmp)) {
  6831. PyErr_Format(PyExc_TypeError, "TypeAlias field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6832. goto failed;
  6833. }
  6834. len = PyList_GET_SIZE(tmp);
  6835. type_params = _Py_asdl_type_param_seq_new(len, arena);
  6836. if (type_params == NULL) goto failed;
  6837. for (i = 0; i < len; i++) {
  6838. type_param_ty val;
  6839. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6840. if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
  6841. goto failed;
  6842. }
  6843. res = obj2ast_type_param(state, tmp2, &val, arena);
  6844. _Py_LeaveRecursiveCall();
  6845. Py_DECREF(tmp2);
  6846. if (res != 0) goto failed;
  6847. if (len != PyList_GET_SIZE(tmp)) {
  6848. PyErr_SetString(PyExc_RuntimeError, "TypeAlias field \"type_params\" changed size during iteration");
  6849. goto failed;
  6850. }
  6851. asdl_seq_SET(type_params, i, val);
  6852. }
  6853. Py_CLEAR(tmp);
  6854. }
  6855. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6856. return 1;
  6857. }
  6858. if (tmp == NULL) {
  6859. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from TypeAlias");
  6860. return 1;
  6861. }
  6862. else {
  6863. int res;
  6864. if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
  6865. goto failed;
  6866. }
  6867. res = obj2ast_expr(state, tmp, &value, arena);
  6868. _Py_LeaveRecursiveCall();
  6869. if (res != 0) goto failed;
  6870. Py_CLEAR(tmp);
  6871. }
  6872. *out = _PyAST_TypeAlias(name, type_params, value, lineno, col_offset,
  6873. end_lineno, end_col_offset, arena);
  6874. if (*out == NULL) goto failed;
  6875. return 0;
  6876. }
  6877. tp = state->AugAssign_type;
  6878. isinstance = PyObject_IsInstance(obj, tp);
  6879. if (isinstance == -1) {
  6880. return 1;
  6881. }
  6882. if (isinstance) {
  6883. expr_ty target;
  6884. operator_ty op;
  6885. expr_ty value;
  6886. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  6887. return 1;
  6888. }
  6889. if (tmp == NULL) {
  6890. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
  6891. return 1;
  6892. }
  6893. else {
  6894. int res;
  6895. if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
  6896. goto failed;
  6897. }
  6898. res = obj2ast_expr(state, tmp, &target, arena);
  6899. _Py_LeaveRecursiveCall();
  6900. if (res != 0) goto failed;
  6901. Py_CLEAR(tmp);
  6902. }
  6903. if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
  6904. return 1;
  6905. }
  6906. if (tmp == NULL) {
  6907. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
  6908. return 1;
  6909. }
  6910. else {
  6911. int res;
  6912. if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
  6913. goto failed;
  6914. }
  6915. res = obj2ast_operator(state, tmp, &op, arena);
  6916. _Py_LeaveRecursiveCall();
  6917. if (res != 0) goto failed;
  6918. Py_CLEAR(tmp);
  6919. }
  6920. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6921. return 1;
  6922. }
  6923. if (tmp == NULL) {
  6924. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
  6925. return 1;
  6926. }
  6927. else {
  6928. int res;
  6929. if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
  6930. goto failed;
  6931. }
  6932. res = obj2ast_expr(state, tmp, &value, arena);
  6933. _Py_LeaveRecursiveCall();
  6934. if (res != 0) goto failed;
  6935. Py_CLEAR(tmp);
  6936. }
  6937. *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
  6938. end_lineno, end_col_offset, arena);
  6939. if (*out == NULL) goto failed;
  6940. return 0;
  6941. }
  6942. tp = state->AnnAssign_type;
  6943. isinstance = PyObject_IsInstance(obj, tp);
  6944. if (isinstance == -1) {
  6945. return 1;
  6946. }
  6947. if (isinstance) {
  6948. expr_ty target;
  6949. expr_ty annotation;
  6950. expr_ty value;
  6951. int simple;
  6952. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  6953. return 1;
  6954. }
  6955. if (tmp == NULL) {
  6956. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
  6957. return 1;
  6958. }
  6959. else {
  6960. int res;
  6961. if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
  6962. goto failed;
  6963. }
  6964. res = obj2ast_expr(state, tmp, &target, arena);
  6965. _Py_LeaveRecursiveCall();
  6966. if (res != 0) goto failed;
  6967. Py_CLEAR(tmp);
  6968. }
  6969. if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
  6970. return 1;
  6971. }
  6972. if (tmp == NULL) {
  6973. PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
  6974. return 1;
  6975. }
  6976. else {
  6977. int res;
  6978. if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
  6979. goto failed;
  6980. }
  6981. res = obj2ast_expr(state, tmp, &annotation, arena);
  6982. _Py_LeaveRecursiveCall();
  6983. if (res != 0) goto failed;
  6984. Py_CLEAR(tmp);
  6985. }
  6986. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6987. return 1;
  6988. }
  6989. if (tmp == NULL || tmp == Py_None) {
  6990. Py_CLEAR(tmp);
  6991. value = NULL;
  6992. }
  6993. else {
  6994. int res;
  6995. if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
  6996. goto failed;
  6997. }
  6998. res = obj2ast_expr(state, tmp, &value, arena);
  6999. _Py_LeaveRecursiveCall();
  7000. if (res != 0) goto failed;
  7001. Py_CLEAR(tmp);
  7002. }
  7003. if (_PyObject_LookupAttr(obj, state->simple, &tmp) < 0) {
  7004. return 1;
  7005. }
  7006. if (tmp == NULL) {
  7007. PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
  7008. return 1;
  7009. }
  7010. else {
  7011. int res;
  7012. if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
  7013. goto failed;
  7014. }
  7015. res = obj2ast_int(state, tmp, &simple, arena);
  7016. _Py_LeaveRecursiveCall();
  7017. if (res != 0) goto failed;
  7018. Py_CLEAR(tmp);
  7019. }
  7020. *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
  7021. col_offset, end_lineno, end_col_offset, arena);
  7022. if (*out == NULL) goto failed;
  7023. return 0;
  7024. }
  7025. tp = state->For_type;
  7026. isinstance = PyObject_IsInstance(obj, tp);
  7027. if (isinstance == -1) {
  7028. return 1;
  7029. }
  7030. if (isinstance) {
  7031. expr_ty target;
  7032. expr_ty iter;
  7033. asdl_stmt_seq* body;
  7034. asdl_stmt_seq* orelse;
  7035. string type_comment;
  7036. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  7037. return 1;
  7038. }
  7039. if (tmp == NULL) {
  7040. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
  7041. return 1;
  7042. }
  7043. else {
  7044. int res;
  7045. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7046. goto failed;
  7047. }
  7048. res = obj2ast_expr(state, tmp, &target, arena);
  7049. _Py_LeaveRecursiveCall();
  7050. if (res != 0) goto failed;
  7051. Py_CLEAR(tmp);
  7052. }
  7053. if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
  7054. return 1;
  7055. }
  7056. if (tmp == NULL) {
  7057. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
  7058. return 1;
  7059. }
  7060. else {
  7061. int res;
  7062. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7063. goto failed;
  7064. }
  7065. res = obj2ast_expr(state, tmp, &iter, arena);
  7066. _Py_LeaveRecursiveCall();
  7067. if (res != 0) goto failed;
  7068. Py_CLEAR(tmp);
  7069. }
  7070. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7071. return 1;
  7072. }
  7073. if (tmp == NULL) {
  7074. tmp = PyList_New(0);
  7075. if (tmp == NULL) {
  7076. return 1;
  7077. }
  7078. }
  7079. {
  7080. int res;
  7081. Py_ssize_t len;
  7082. Py_ssize_t i;
  7083. if (!PyList_Check(tmp)) {
  7084. PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7085. goto failed;
  7086. }
  7087. len = PyList_GET_SIZE(tmp);
  7088. body = _Py_asdl_stmt_seq_new(len, arena);
  7089. if (body == NULL) goto failed;
  7090. for (i = 0; i < len; i++) {
  7091. stmt_ty val;
  7092. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7093. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7094. goto failed;
  7095. }
  7096. res = obj2ast_stmt(state, tmp2, &val, arena);
  7097. _Py_LeaveRecursiveCall();
  7098. Py_DECREF(tmp2);
  7099. if (res != 0) goto failed;
  7100. if (len != PyList_GET_SIZE(tmp)) {
  7101. PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
  7102. goto failed;
  7103. }
  7104. asdl_seq_SET(body, i, val);
  7105. }
  7106. Py_CLEAR(tmp);
  7107. }
  7108. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7109. return 1;
  7110. }
  7111. if (tmp == NULL) {
  7112. tmp = PyList_New(0);
  7113. if (tmp == NULL) {
  7114. return 1;
  7115. }
  7116. }
  7117. {
  7118. int res;
  7119. Py_ssize_t len;
  7120. Py_ssize_t i;
  7121. if (!PyList_Check(tmp)) {
  7122. PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7123. goto failed;
  7124. }
  7125. len = PyList_GET_SIZE(tmp);
  7126. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7127. if (orelse == NULL) goto failed;
  7128. for (i = 0; i < len; i++) {
  7129. stmt_ty val;
  7130. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7131. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7132. goto failed;
  7133. }
  7134. res = obj2ast_stmt(state, tmp2, &val, arena);
  7135. _Py_LeaveRecursiveCall();
  7136. Py_DECREF(tmp2);
  7137. if (res != 0) goto failed;
  7138. if (len != PyList_GET_SIZE(tmp)) {
  7139. PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
  7140. goto failed;
  7141. }
  7142. asdl_seq_SET(orelse, i, val);
  7143. }
  7144. Py_CLEAR(tmp);
  7145. }
  7146. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  7147. return 1;
  7148. }
  7149. if (tmp == NULL || tmp == Py_None) {
  7150. Py_CLEAR(tmp);
  7151. type_comment = NULL;
  7152. }
  7153. else {
  7154. int res;
  7155. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7156. goto failed;
  7157. }
  7158. res = obj2ast_string(state, tmp, &type_comment, arena);
  7159. _Py_LeaveRecursiveCall();
  7160. if (res != 0) goto failed;
  7161. Py_CLEAR(tmp);
  7162. }
  7163. *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
  7164. col_offset, end_lineno, end_col_offset, arena);
  7165. if (*out == NULL) goto failed;
  7166. return 0;
  7167. }
  7168. tp = state->AsyncFor_type;
  7169. isinstance = PyObject_IsInstance(obj, tp);
  7170. if (isinstance == -1) {
  7171. return 1;
  7172. }
  7173. if (isinstance) {
  7174. expr_ty target;
  7175. expr_ty iter;
  7176. asdl_stmt_seq* body;
  7177. asdl_stmt_seq* orelse;
  7178. string type_comment;
  7179. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  7180. return 1;
  7181. }
  7182. if (tmp == NULL) {
  7183. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
  7184. return 1;
  7185. }
  7186. else {
  7187. int res;
  7188. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7189. goto failed;
  7190. }
  7191. res = obj2ast_expr(state, tmp, &target, arena);
  7192. _Py_LeaveRecursiveCall();
  7193. if (res != 0) goto failed;
  7194. Py_CLEAR(tmp);
  7195. }
  7196. if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
  7197. return 1;
  7198. }
  7199. if (tmp == NULL) {
  7200. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
  7201. return 1;
  7202. }
  7203. else {
  7204. int res;
  7205. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7206. goto failed;
  7207. }
  7208. res = obj2ast_expr(state, tmp, &iter, arena);
  7209. _Py_LeaveRecursiveCall();
  7210. if (res != 0) goto failed;
  7211. Py_CLEAR(tmp);
  7212. }
  7213. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7214. return 1;
  7215. }
  7216. if (tmp == NULL) {
  7217. tmp = PyList_New(0);
  7218. if (tmp == NULL) {
  7219. return 1;
  7220. }
  7221. }
  7222. {
  7223. int res;
  7224. Py_ssize_t len;
  7225. Py_ssize_t i;
  7226. if (!PyList_Check(tmp)) {
  7227. PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7228. goto failed;
  7229. }
  7230. len = PyList_GET_SIZE(tmp);
  7231. body = _Py_asdl_stmt_seq_new(len, arena);
  7232. if (body == NULL) goto failed;
  7233. for (i = 0; i < len; i++) {
  7234. stmt_ty val;
  7235. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7236. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7237. goto failed;
  7238. }
  7239. res = obj2ast_stmt(state, tmp2, &val, arena);
  7240. _Py_LeaveRecursiveCall();
  7241. Py_DECREF(tmp2);
  7242. if (res != 0) goto failed;
  7243. if (len != PyList_GET_SIZE(tmp)) {
  7244. PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
  7245. goto failed;
  7246. }
  7247. asdl_seq_SET(body, i, val);
  7248. }
  7249. Py_CLEAR(tmp);
  7250. }
  7251. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7252. return 1;
  7253. }
  7254. if (tmp == NULL) {
  7255. tmp = PyList_New(0);
  7256. if (tmp == NULL) {
  7257. return 1;
  7258. }
  7259. }
  7260. {
  7261. int res;
  7262. Py_ssize_t len;
  7263. Py_ssize_t i;
  7264. if (!PyList_Check(tmp)) {
  7265. PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7266. goto failed;
  7267. }
  7268. len = PyList_GET_SIZE(tmp);
  7269. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7270. if (orelse == NULL) goto failed;
  7271. for (i = 0; i < len; i++) {
  7272. stmt_ty val;
  7273. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7274. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7275. goto failed;
  7276. }
  7277. res = obj2ast_stmt(state, tmp2, &val, arena);
  7278. _Py_LeaveRecursiveCall();
  7279. Py_DECREF(tmp2);
  7280. if (res != 0) goto failed;
  7281. if (len != PyList_GET_SIZE(tmp)) {
  7282. PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
  7283. goto failed;
  7284. }
  7285. asdl_seq_SET(orelse, i, val);
  7286. }
  7287. Py_CLEAR(tmp);
  7288. }
  7289. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  7290. return 1;
  7291. }
  7292. if (tmp == NULL || tmp == Py_None) {
  7293. Py_CLEAR(tmp);
  7294. type_comment = NULL;
  7295. }
  7296. else {
  7297. int res;
  7298. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7299. goto failed;
  7300. }
  7301. res = obj2ast_string(state, tmp, &type_comment, arena);
  7302. _Py_LeaveRecursiveCall();
  7303. if (res != 0) goto failed;
  7304. Py_CLEAR(tmp);
  7305. }
  7306. *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
  7307. lineno, col_offset, end_lineno, end_col_offset,
  7308. arena);
  7309. if (*out == NULL) goto failed;
  7310. return 0;
  7311. }
  7312. tp = state->While_type;
  7313. isinstance = PyObject_IsInstance(obj, tp);
  7314. if (isinstance == -1) {
  7315. return 1;
  7316. }
  7317. if (isinstance) {
  7318. expr_ty test;
  7319. asdl_stmt_seq* body;
  7320. asdl_stmt_seq* orelse;
  7321. if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
  7322. return 1;
  7323. }
  7324. if (tmp == NULL) {
  7325. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
  7326. return 1;
  7327. }
  7328. else {
  7329. int res;
  7330. if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
  7331. goto failed;
  7332. }
  7333. res = obj2ast_expr(state, tmp, &test, arena);
  7334. _Py_LeaveRecursiveCall();
  7335. if (res != 0) goto failed;
  7336. Py_CLEAR(tmp);
  7337. }
  7338. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7339. return 1;
  7340. }
  7341. if (tmp == NULL) {
  7342. tmp = PyList_New(0);
  7343. if (tmp == NULL) {
  7344. return 1;
  7345. }
  7346. }
  7347. {
  7348. int res;
  7349. Py_ssize_t len;
  7350. Py_ssize_t i;
  7351. if (!PyList_Check(tmp)) {
  7352. PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7353. goto failed;
  7354. }
  7355. len = PyList_GET_SIZE(tmp);
  7356. body = _Py_asdl_stmt_seq_new(len, arena);
  7357. if (body == NULL) goto failed;
  7358. for (i = 0; i < len; i++) {
  7359. stmt_ty val;
  7360. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7361. if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
  7362. goto failed;
  7363. }
  7364. res = obj2ast_stmt(state, tmp2, &val, arena);
  7365. _Py_LeaveRecursiveCall();
  7366. Py_DECREF(tmp2);
  7367. if (res != 0) goto failed;
  7368. if (len != PyList_GET_SIZE(tmp)) {
  7369. PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
  7370. goto failed;
  7371. }
  7372. asdl_seq_SET(body, i, val);
  7373. }
  7374. Py_CLEAR(tmp);
  7375. }
  7376. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7377. return 1;
  7378. }
  7379. if (tmp == NULL) {
  7380. tmp = PyList_New(0);
  7381. if (tmp == NULL) {
  7382. return 1;
  7383. }
  7384. }
  7385. {
  7386. int res;
  7387. Py_ssize_t len;
  7388. Py_ssize_t i;
  7389. if (!PyList_Check(tmp)) {
  7390. PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7391. goto failed;
  7392. }
  7393. len = PyList_GET_SIZE(tmp);
  7394. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7395. if (orelse == NULL) goto failed;
  7396. for (i = 0; i < len; i++) {
  7397. stmt_ty val;
  7398. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7399. if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
  7400. goto failed;
  7401. }
  7402. res = obj2ast_stmt(state, tmp2, &val, arena);
  7403. _Py_LeaveRecursiveCall();
  7404. Py_DECREF(tmp2);
  7405. if (res != 0) goto failed;
  7406. if (len != PyList_GET_SIZE(tmp)) {
  7407. PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
  7408. goto failed;
  7409. }
  7410. asdl_seq_SET(orelse, i, val);
  7411. }
  7412. Py_CLEAR(tmp);
  7413. }
  7414. *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
  7415. end_col_offset, arena);
  7416. if (*out == NULL) goto failed;
  7417. return 0;
  7418. }
  7419. tp = state->If_type;
  7420. isinstance = PyObject_IsInstance(obj, tp);
  7421. if (isinstance == -1) {
  7422. return 1;
  7423. }
  7424. if (isinstance) {
  7425. expr_ty test;
  7426. asdl_stmt_seq* body;
  7427. asdl_stmt_seq* orelse;
  7428. if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
  7429. return 1;
  7430. }
  7431. if (tmp == NULL) {
  7432. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
  7433. return 1;
  7434. }
  7435. else {
  7436. int res;
  7437. if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
  7438. goto failed;
  7439. }
  7440. res = obj2ast_expr(state, tmp, &test, arena);
  7441. _Py_LeaveRecursiveCall();
  7442. if (res != 0) goto failed;
  7443. Py_CLEAR(tmp);
  7444. }
  7445. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7446. return 1;
  7447. }
  7448. if (tmp == NULL) {
  7449. tmp = PyList_New(0);
  7450. if (tmp == NULL) {
  7451. return 1;
  7452. }
  7453. }
  7454. {
  7455. int res;
  7456. Py_ssize_t len;
  7457. Py_ssize_t i;
  7458. if (!PyList_Check(tmp)) {
  7459. PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7460. goto failed;
  7461. }
  7462. len = PyList_GET_SIZE(tmp);
  7463. body = _Py_asdl_stmt_seq_new(len, arena);
  7464. if (body == NULL) goto failed;
  7465. for (i = 0; i < len; i++) {
  7466. stmt_ty val;
  7467. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7468. if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
  7469. goto failed;
  7470. }
  7471. res = obj2ast_stmt(state, tmp2, &val, arena);
  7472. _Py_LeaveRecursiveCall();
  7473. Py_DECREF(tmp2);
  7474. if (res != 0) goto failed;
  7475. if (len != PyList_GET_SIZE(tmp)) {
  7476. PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
  7477. goto failed;
  7478. }
  7479. asdl_seq_SET(body, i, val);
  7480. }
  7481. Py_CLEAR(tmp);
  7482. }
  7483. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7484. return 1;
  7485. }
  7486. if (tmp == NULL) {
  7487. tmp = PyList_New(0);
  7488. if (tmp == NULL) {
  7489. return 1;
  7490. }
  7491. }
  7492. {
  7493. int res;
  7494. Py_ssize_t len;
  7495. Py_ssize_t i;
  7496. if (!PyList_Check(tmp)) {
  7497. PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7498. goto failed;
  7499. }
  7500. len = PyList_GET_SIZE(tmp);
  7501. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7502. if (orelse == NULL) goto failed;
  7503. for (i = 0; i < len; i++) {
  7504. stmt_ty val;
  7505. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7506. if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
  7507. goto failed;
  7508. }
  7509. res = obj2ast_stmt(state, tmp2, &val, arena);
  7510. _Py_LeaveRecursiveCall();
  7511. Py_DECREF(tmp2);
  7512. if (res != 0) goto failed;
  7513. if (len != PyList_GET_SIZE(tmp)) {
  7514. PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
  7515. goto failed;
  7516. }
  7517. asdl_seq_SET(orelse, i, val);
  7518. }
  7519. Py_CLEAR(tmp);
  7520. }
  7521. *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
  7522. end_col_offset, arena);
  7523. if (*out == NULL) goto failed;
  7524. return 0;
  7525. }
  7526. tp = state->With_type;
  7527. isinstance = PyObject_IsInstance(obj, tp);
  7528. if (isinstance == -1) {
  7529. return 1;
  7530. }
  7531. if (isinstance) {
  7532. asdl_withitem_seq* items;
  7533. asdl_stmt_seq* body;
  7534. string type_comment;
  7535. if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
  7536. return 1;
  7537. }
  7538. if (tmp == NULL) {
  7539. tmp = PyList_New(0);
  7540. if (tmp == NULL) {
  7541. return 1;
  7542. }
  7543. }
  7544. {
  7545. int res;
  7546. Py_ssize_t len;
  7547. Py_ssize_t i;
  7548. if (!PyList_Check(tmp)) {
  7549. PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7550. goto failed;
  7551. }
  7552. len = PyList_GET_SIZE(tmp);
  7553. items = _Py_asdl_withitem_seq_new(len, arena);
  7554. if (items == NULL) goto failed;
  7555. for (i = 0; i < len; i++) {
  7556. withitem_ty val;
  7557. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7558. if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
  7559. goto failed;
  7560. }
  7561. res = obj2ast_withitem(state, tmp2, &val, arena);
  7562. _Py_LeaveRecursiveCall();
  7563. Py_DECREF(tmp2);
  7564. if (res != 0) goto failed;
  7565. if (len != PyList_GET_SIZE(tmp)) {
  7566. PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
  7567. goto failed;
  7568. }
  7569. asdl_seq_SET(items, i, val);
  7570. }
  7571. Py_CLEAR(tmp);
  7572. }
  7573. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7574. return 1;
  7575. }
  7576. if (tmp == NULL) {
  7577. tmp = PyList_New(0);
  7578. if (tmp == NULL) {
  7579. return 1;
  7580. }
  7581. }
  7582. {
  7583. int res;
  7584. Py_ssize_t len;
  7585. Py_ssize_t i;
  7586. if (!PyList_Check(tmp)) {
  7587. PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7588. goto failed;
  7589. }
  7590. len = PyList_GET_SIZE(tmp);
  7591. body = _Py_asdl_stmt_seq_new(len, arena);
  7592. if (body == NULL) goto failed;
  7593. for (i = 0; i < len; i++) {
  7594. stmt_ty val;
  7595. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7596. if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
  7597. goto failed;
  7598. }
  7599. res = obj2ast_stmt(state, tmp2, &val, arena);
  7600. _Py_LeaveRecursiveCall();
  7601. Py_DECREF(tmp2);
  7602. if (res != 0) goto failed;
  7603. if (len != PyList_GET_SIZE(tmp)) {
  7604. PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
  7605. goto failed;
  7606. }
  7607. asdl_seq_SET(body, i, val);
  7608. }
  7609. Py_CLEAR(tmp);
  7610. }
  7611. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  7612. return 1;
  7613. }
  7614. if (tmp == NULL || tmp == Py_None) {
  7615. Py_CLEAR(tmp);
  7616. type_comment = NULL;
  7617. }
  7618. else {
  7619. int res;
  7620. if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
  7621. goto failed;
  7622. }
  7623. res = obj2ast_string(state, tmp, &type_comment, arena);
  7624. _Py_LeaveRecursiveCall();
  7625. if (res != 0) goto failed;
  7626. Py_CLEAR(tmp);
  7627. }
  7628. *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
  7629. end_lineno, end_col_offset, arena);
  7630. if (*out == NULL) goto failed;
  7631. return 0;
  7632. }
  7633. tp = state->AsyncWith_type;
  7634. isinstance = PyObject_IsInstance(obj, tp);
  7635. if (isinstance == -1) {
  7636. return 1;
  7637. }
  7638. if (isinstance) {
  7639. asdl_withitem_seq* items;
  7640. asdl_stmt_seq* body;
  7641. string type_comment;
  7642. if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
  7643. return 1;
  7644. }
  7645. if (tmp == NULL) {
  7646. tmp = PyList_New(0);
  7647. if (tmp == NULL) {
  7648. return 1;
  7649. }
  7650. }
  7651. {
  7652. int res;
  7653. Py_ssize_t len;
  7654. Py_ssize_t i;
  7655. if (!PyList_Check(tmp)) {
  7656. PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7657. goto failed;
  7658. }
  7659. len = PyList_GET_SIZE(tmp);
  7660. items = _Py_asdl_withitem_seq_new(len, arena);
  7661. if (items == NULL) goto failed;
  7662. for (i = 0; i < len; i++) {
  7663. withitem_ty val;
  7664. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7665. if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
  7666. goto failed;
  7667. }
  7668. res = obj2ast_withitem(state, tmp2, &val, arena);
  7669. _Py_LeaveRecursiveCall();
  7670. Py_DECREF(tmp2);
  7671. if (res != 0) goto failed;
  7672. if (len != PyList_GET_SIZE(tmp)) {
  7673. PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
  7674. goto failed;
  7675. }
  7676. asdl_seq_SET(items, i, val);
  7677. }
  7678. Py_CLEAR(tmp);
  7679. }
  7680. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7681. return 1;
  7682. }
  7683. if (tmp == NULL) {
  7684. tmp = PyList_New(0);
  7685. if (tmp == NULL) {
  7686. return 1;
  7687. }
  7688. }
  7689. {
  7690. int res;
  7691. Py_ssize_t len;
  7692. Py_ssize_t i;
  7693. if (!PyList_Check(tmp)) {
  7694. PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7695. goto failed;
  7696. }
  7697. len = PyList_GET_SIZE(tmp);
  7698. body = _Py_asdl_stmt_seq_new(len, arena);
  7699. if (body == NULL) goto failed;
  7700. for (i = 0; i < len; i++) {
  7701. stmt_ty val;
  7702. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7703. if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
  7704. goto failed;
  7705. }
  7706. res = obj2ast_stmt(state, tmp2, &val, arena);
  7707. _Py_LeaveRecursiveCall();
  7708. Py_DECREF(tmp2);
  7709. if (res != 0) goto failed;
  7710. if (len != PyList_GET_SIZE(tmp)) {
  7711. PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
  7712. goto failed;
  7713. }
  7714. asdl_seq_SET(body, i, val);
  7715. }
  7716. Py_CLEAR(tmp);
  7717. }
  7718. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  7719. return 1;
  7720. }
  7721. if (tmp == NULL || tmp == Py_None) {
  7722. Py_CLEAR(tmp);
  7723. type_comment = NULL;
  7724. }
  7725. else {
  7726. int res;
  7727. if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
  7728. goto failed;
  7729. }
  7730. res = obj2ast_string(state, tmp, &type_comment, arena);
  7731. _Py_LeaveRecursiveCall();
  7732. if (res != 0) goto failed;
  7733. Py_CLEAR(tmp);
  7734. }
  7735. *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
  7736. end_lineno, end_col_offset, arena);
  7737. if (*out == NULL) goto failed;
  7738. return 0;
  7739. }
  7740. tp = state->Match_type;
  7741. isinstance = PyObject_IsInstance(obj, tp);
  7742. if (isinstance == -1) {
  7743. return 1;
  7744. }
  7745. if (isinstance) {
  7746. expr_ty subject;
  7747. asdl_match_case_seq* cases;
  7748. if (_PyObject_LookupAttr(obj, state->subject, &tmp) < 0) {
  7749. return 1;
  7750. }
  7751. if (tmp == NULL) {
  7752. PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
  7753. return 1;
  7754. }
  7755. else {
  7756. int res;
  7757. if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
  7758. goto failed;
  7759. }
  7760. res = obj2ast_expr(state, tmp, &subject, arena);
  7761. _Py_LeaveRecursiveCall();
  7762. if (res != 0) goto failed;
  7763. Py_CLEAR(tmp);
  7764. }
  7765. if (_PyObject_LookupAttr(obj, state->cases, &tmp) < 0) {
  7766. return 1;
  7767. }
  7768. if (tmp == NULL) {
  7769. tmp = PyList_New(0);
  7770. if (tmp == NULL) {
  7771. return 1;
  7772. }
  7773. }
  7774. {
  7775. int res;
  7776. Py_ssize_t len;
  7777. Py_ssize_t i;
  7778. if (!PyList_Check(tmp)) {
  7779. PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7780. goto failed;
  7781. }
  7782. len = PyList_GET_SIZE(tmp);
  7783. cases = _Py_asdl_match_case_seq_new(len, arena);
  7784. if (cases == NULL) goto failed;
  7785. for (i = 0; i < len; i++) {
  7786. match_case_ty val;
  7787. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7788. if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
  7789. goto failed;
  7790. }
  7791. res = obj2ast_match_case(state, tmp2, &val, arena);
  7792. _Py_LeaveRecursiveCall();
  7793. Py_DECREF(tmp2);
  7794. if (res != 0) goto failed;
  7795. if (len != PyList_GET_SIZE(tmp)) {
  7796. PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
  7797. goto failed;
  7798. }
  7799. asdl_seq_SET(cases, i, val);
  7800. }
  7801. Py_CLEAR(tmp);
  7802. }
  7803. *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
  7804. end_col_offset, arena);
  7805. if (*out == NULL) goto failed;
  7806. return 0;
  7807. }
  7808. tp = state->Raise_type;
  7809. isinstance = PyObject_IsInstance(obj, tp);
  7810. if (isinstance == -1) {
  7811. return 1;
  7812. }
  7813. if (isinstance) {
  7814. expr_ty exc;
  7815. expr_ty cause;
  7816. if (_PyObject_LookupAttr(obj, state->exc, &tmp) < 0) {
  7817. return 1;
  7818. }
  7819. if (tmp == NULL || tmp == Py_None) {
  7820. Py_CLEAR(tmp);
  7821. exc = NULL;
  7822. }
  7823. else {
  7824. int res;
  7825. if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
  7826. goto failed;
  7827. }
  7828. res = obj2ast_expr(state, tmp, &exc, arena);
  7829. _Py_LeaveRecursiveCall();
  7830. if (res != 0) goto failed;
  7831. Py_CLEAR(tmp);
  7832. }
  7833. if (_PyObject_LookupAttr(obj, state->cause, &tmp) < 0) {
  7834. return 1;
  7835. }
  7836. if (tmp == NULL || tmp == Py_None) {
  7837. Py_CLEAR(tmp);
  7838. cause = NULL;
  7839. }
  7840. else {
  7841. int res;
  7842. if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
  7843. goto failed;
  7844. }
  7845. res = obj2ast_expr(state, tmp, &cause, arena);
  7846. _Py_LeaveRecursiveCall();
  7847. if (res != 0) goto failed;
  7848. Py_CLEAR(tmp);
  7849. }
  7850. *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
  7851. end_col_offset, arena);
  7852. if (*out == NULL) goto failed;
  7853. return 0;
  7854. }
  7855. tp = state->Try_type;
  7856. isinstance = PyObject_IsInstance(obj, tp);
  7857. if (isinstance == -1) {
  7858. return 1;
  7859. }
  7860. if (isinstance) {
  7861. asdl_stmt_seq* body;
  7862. asdl_excepthandler_seq* handlers;
  7863. asdl_stmt_seq* orelse;
  7864. asdl_stmt_seq* finalbody;
  7865. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7866. return 1;
  7867. }
  7868. if (tmp == NULL) {
  7869. tmp = PyList_New(0);
  7870. if (tmp == NULL) {
  7871. return 1;
  7872. }
  7873. }
  7874. {
  7875. int res;
  7876. Py_ssize_t len;
  7877. Py_ssize_t i;
  7878. if (!PyList_Check(tmp)) {
  7879. PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7880. goto failed;
  7881. }
  7882. len = PyList_GET_SIZE(tmp);
  7883. body = _Py_asdl_stmt_seq_new(len, arena);
  7884. if (body == NULL) goto failed;
  7885. for (i = 0; i < len; i++) {
  7886. stmt_ty val;
  7887. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7888. if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
  7889. goto failed;
  7890. }
  7891. res = obj2ast_stmt(state, tmp2, &val, arena);
  7892. _Py_LeaveRecursiveCall();
  7893. Py_DECREF(tmp2);
  7894. if (res != 0) goto failed;
  7895. if (len != PyList_GET_SIZE(tmp)) {
  7896. PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
  7897. goto failed;
  7898. }
  7899. asdl_seq_SET(body, i, val);
  7900. }
  7901. Py_CLEAR(tmp);
  7902. }
  7903. if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
  7904. return 1;
  7905. }
  7906. if (tmp == NULL) {
  7907. tmp = PyList_New(0);
  7908. if (tmp == NULL) {
  7909. return 1;
  7910. }
  7911. }
  7912. {
  7913. int res;
  7914. Py_ssize_t len;
  7915. Py_ssize_t i;
  7916. if (!PyList_Check(tmp)) {
  7917. PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7918. goto failed;
  7919. }
  7920. len = PyList_GET_SIZE(tmp);
  7921. handlers = _Py_asdl_excepthandler_seq_new(len, arena);
  7922. if (handlers == NULL) goto failed;
  7923. for (i = 0; i < len; i++) {
  7924. excepthandler_ty val;
  7925. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7926. if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
  7927. goto failed;
  7928. }
  7929. res = obj2ast_excepthandler(state, tmp2, &val, arena);
  7930. _Py_LeaveRecursiveCall();
  7931. Py_DECREF(tmp2);
  7932. if (res != 0) goto failed;
  7933. if (len != PyList_GET_SIZE(tmp)) {
  7934. PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
  7935. goto failed;
  7936. }
  7937. asdl_seq_SET(handlers, i, val);
  7938. }
  7939. Py_CLEAR(tmp);
  7940. }
  7941. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7942. return 1;
  7943. }
  7944. if (tmp == NULL) {
  7945. tmp = PyList_New(0);
  7946. if (tmp == NULL) {
  7947. return 1;
  7948. }
  7949. }
  7950. {
  7951. int res;
  7952. Py_ssize_t len;
  7953. Py_ssize_t i;
  7954. if (!PyList_Check(tmp)) {
  7955. PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7956. goto failed;
  7957. }
  7958. len = PyList_GET_SIZE(tmp);
  7959. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7960. if (orelse == NULL) goto failed;
  7961. for (i = 0; i < len; i++) {
  7962. stmt_ty val;
  7963. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7964. if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
  7965. goto failed;
  7966. }
  7967. res = obj2ast_stmt(state, tmp2, &val, arena);
  7968. _Py_LeaveRecursiveCall();
  7969. Py_DECREF(tmp2);
  7970. if (res != 0) goto failed;
  7971. if (len != PyList_GET_SIZE(tmp)) {
  7972. PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
  7973. goto failed;
  7974. }
  7975. asdl_seq_SET(orelse, i, val);
  7976. }
  7977. Py_CLEAR(tmp);
  7978. }
  7979. if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
  7980. return 1;
  7981. }
  7982. if (tmp == NULL) {
  7983. tmp = PyList_New(0);
  7984. if (tmp == NULL) {
  7985. return 1;
  7986. }
  7987. }
  7988. {
  7989. int res;
  7990. Py_ssize_t len;
  7991. Py_ssize_t i;
  7992. if (!PyList_Check(tmp)) {
  7993. PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7994. goto failed;
  7995. }
  7996. len = PyList_GET_SIZE(tmp);
  7997. finalbody = _Py_asdl_stmt_seq_new(len, arena);
  7998. if (finalbody == NULL) goto failed;
  7999. for (i = 0; i < len; i++) {
  8000. stmt_ty val;
  8001. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8002. if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
  8003. goto failed;
  8004. }
  8005. res = obj2ast_stmt(state, tmp2, &val, arena);
  8006. _Py_LeaveRecursiveCall();
  8007. Py_DECREF(tmp2);
  8008. if (res != 0) goto failed;
  8009. if (len != PyList_GET_SIZE(tmp)) {
  8010. PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
  8011. goto failed;
  8012. }
  8013. asdl_seq_SET(finalbody, i, val);
  8014. }
  8015. Py_CLEAR(tmp);
  8016. }
  8017. *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
  8018. col_offset, end_lineno, end_col_offset, arena);
  8019. if (*out == NULL) goto failed;
  8020. return 0;
  8021. }
  8022. tp = state->TryStar_type;
  8023. isinstance = PyObject_IsInstance(obj, tp);
  8024. if (isinstance == -1) {
  8025. return 1;
  8026. }
  8027. if (isinstance) {
  8028. asdl_stmt_seq* body;
  8029. asdl_excepthandler_seq* handlers;
  8030. asdl_stmt_seq* orelse;
  8031. asdl_stmt_seq* finalbody;
  8032. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  8033. return 1;
  8034. }
  8035. if (tmp == NULL) {
  8036. tmp = PyList_New(0);
  8037. if (tmp == NULL) {
  8038. return 1;
  8039. }
  8040. }
  8041. {
  8042. int res;
  8043. Py_ssize_t len;
  8044. Py_ssize_t i;
  8045. if (!PyList_Check(tmp)) {
  8046. PyErr_Format(PyExc_TypeError, "TryStar field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8047. goto failed;
  8048. }
  8049. len = PyList_GET_SIZE(tmp);
  8050. body = _Py_asdl_stmt_seq_new(len, arena);
  8051. if (body == NULL) goto failed;
  8052. for (i = 0; i < len; i++) {
  8053. stmt_ty val;
  8054. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8055. if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
  8056. goto failed;
  8057. }
  8058. res = obj2ast_stmt(state, tmp2, &val, arena);
  8059. _Py_LeaveRecursiveCall();
  8060. Py_DECREF(tmp2);
  8061. if (res != 0) goto failed;
  8062. if (len != PyList_GET_SIZE(tmp)) {
  8063. PyErr_SetString(PyExc_RuntimeError, "TryStar field \"body\" changed size during iteration");
  8064. goto failed;
  8065. }
  8066. asdl_seq_SET(body, i, val);
  8067. }
  8068. Py_CLEAR(tmp);
  8069. }
  8070. if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
  8071. return 1;
  8072. }
  8073. if (tmp == NULL) {
  8074. tmp = PyList_New(0);
  8075. if (tmp == NULL) {
  8076. return 1;
  8077. }
  8078. }
  8079. {
  8080. int res;
  8081. Py_ssize_t len;
  8082. Py_ssize_t i;
  8083. if (!PyList_Check(tmp)) {
  8084. PyErr_Format(PyExc_TypeError, "TryStar field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8085. goto failed;
  8086. }
  8087. len = PyList_GET_SIZE(tmp);
  8088. handlers = _Py_asdl_excepthandler_seq_new(len, arena);
  8089. if (handlers == NULL) goto failed;
  8090. for (i = 0; i < len; i++) {
  8091. excepthandler_ty val;
  8092. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8093. if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
  8094. goto failed;
  8095. }
  8096. res = obj2ast_excepthandler(state, tmp2, &val, arena);
  8097. _Py_LeaveRecursiveCall();
  8098. Py_DECREF(tmp2);
  8099. if (res != 0) goto failed;
  8100. if (len != PyList_GET_SIZE(tmp)) {
  8101. PyErr_SetString(PyExc_RuntimeError, "TryStar field \"handlers\" changed size during iteration");
  8102. goto failed;
  8103. }
  8104. asdl_seq_SET(handlers, i, val);
  8105. }
  8106. Py_CLEAR(tmp);
  8107. }
  8108. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  8109. return 1;
  8110. }
  8111. if (tmp == NULL) {
  8112. tmp = PyList_New(0);
  8113. if (tmp == NULL) {
  8114. return 1;
  8115. }
  8116. }
  8117. {
  8118. int res;
  8119. Py_ssize_t len;
  8120. Py_ssize_t i;
  8121. if (!PyList_Check(tmp)) {
  8122. PyErr_Format(PyExc_TypeError, "TryStar field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8123. goto failed;
  8124. }
  8125. len = PyList_GET_SIZE(tmp);
  8126. orelse = _Py_asdl_stmt_seq_new(len, arena);
  8127. if (orelse == NULL) goto failed;
  8128. for (i = 0; i < len; i++) {
  8129. stmt_ty val;
  8130. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8131. if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
  8132. goto failed;
  8133. }
  8134. res = obj2ast_stmt(state, tmp2, &val, arena);
  8135. _Py_LeaveRecursiveCall();
  8136. Py_DECREF(tmp2);
  8137. if (res != 0) goto failed;
  8138. if (len != PyList_GET_SIZE(tmp)) {
  8139. PyErr_SetString(PyExc_RuntimeError, "TryStar field \"orelse\" changed size during iteration");
  8140. goto failed;
  8141. }
  8142. asdl_seq_SET(orelse, i, val);
  8143. }
  8144. Py_CLEAR(tmp);
  8145. }
  8146. if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
  8147. return 1;
  8148. }
  8149. if (tmp == NULL) {
  8150. tmp = PyList_New(0);
  8151. if (tmp == NULL) {
  8152. return 1;
  8153. }
  8154. }
  8155. {
  8156. int res;
  8157. Py_ssize_t len;
  8158. Py_ssize_t i;
  8159. if (!PyList_Check(tmp)) {
  8160. PyErr_Format(PyExc_TypeError, "TryStar field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8161. goto failed;
  8162. }
  8163. len = PyList_GET_SIZE(tmp);
  8164. finalbody = _Py_asdl_stmt_seq_new(len, arena);
  8165. if (finalbody == NULL) goto failed;
  8166. for (i = 0; i < len; i++) {
  8167. stmt_ty val;
  8168. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8169. if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
  8170. goto failed;
  8171. }
  8172. res = obj2ast_stmt(state, tmp2, &val, arena);
  8173. _Py_LeaveRecursiveCall();
  8174. Py_DECREF(tmp2);
  8175. if (res != 0) goto failed;
  8176. if (len != PyList_GET_SIZE(tmp)) {
  8177. PyErr_SetString(PyExc_RuntimeError, "TryStar field \"finalbody\" changed size during iteration");
  8178. goto failed;
  8179. }
  8180. asdl_seq_SET(finalbody, i, val);
  8181. }
  8182. Py_CLEAR(tmp);
  8183. }
  8184. *out = _PyAST_TryStar(body, handlers, orelse, finalbody, lineno,
  8185. col_offset, end_lineno, end_col_offset, arena);
  8186. if (*out == NULL) goto failed;
  8187. return 0;
  8188. }
  8189. tp = state->Assert_type;
  8190. isinstance = PyObject_IsInstance(obj, tp);
  8191. if (isinstance == -1) {
  8192. return 1;
  8193. }
  8194. if (isinstance) {
  8195. expr_ty test;
  8196. expr_ty msg;
  8197. if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
  8198. return 1;
  8199. }
  8200. if (tmp == NULL) {
  8201. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
  8202. return 1;
  8203. }
  8204. else {
  8205. int res;
  8206. if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
  8207. goto failed;
  8208. }
  8209. res = obj2ast_expr(state, tmp, &test, arena);
  8210. _Py_LeaveRecursiveCall();
  8211. if (res != 0) goto failed;
  8212. Py_CLEAR(tmp);
  8213. }
  8214. if (_PyObject_LookupAttr(obj, state->msg, &tmp) < 0) {
  8215. return 1;
  8216. }
  8217. if (tmp == NULL || tmp == Py_None) {
  8218. Py_CLEAR(tmp);
  8219. msg = NULL;
  8220. }
  8221. else {
  8222. int res;
  8223. if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
  8224. goto failed;
  8225. }
  8226. res = obj2ast_expr(state, tmp, &msg, arena);
  8227. _Py_LeaveRecursiveCall();
  8228. if (res != 0) goto failed;
  8229. Py_CLEAR(tmp);
  8230. }
  8231. *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
  8232. end_col_offset, arena);
  8233. if (*out == NULL) goto failed;
  8234. return 0;
  8235. }
  8236. tp = state->Import_type;
  8237. isinstance = PyObject_IsInstance(obj, tp);
  8238. if (isinstance == -1) {
  8239. return 1;
  8240. }
  8241. if (isinstance) {
  8242. asdl_alias_seq* names;
  8243. if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
  8244. return 1;
  8245. }
  8246. if (tmp == NULL) {
  8247. tmp = PyList_New(0);
  8248. if (tmp == NULL) {
  8249. return 1;
  8250. }
  8251. }
  8252. {
  8253. int res;
  8254. Py_ssize_t len;
  8255. Py_ssize_t i;
  8256. if (!PyList_Check(tmp)) {
  8257. PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8258. goto failed;
  8259. }
  8260. len = PyList_GET_SIZE(tmp);
  8261. names = _Py_asdl_alias_seq_new(len, arena);
  8262. if (names == NULL) goto failed;
  8263. for (i = 0; i < len; i++) {
  8264. alias_ty val;
  8265. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8266. if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
  8267. goto failed;
  8268. }
  8269. res = obj2ast_alias(state, tmp2, &val, arena);
  8270. _Py_LeaveRecursiveCall();
  8271. Py_DECREF(tmp2);
  8272. if (res != 0) goto failed;
  8273. if (len != PyList_GET_SIZE(tmp)) {
  8274. PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
  8275. goto failed;
  8276. }
  8277. asdl_seq_SET(names, i, val);
  8278. }
  8279. Py_CLEAR(tmp);
  8280. }
  8281. *out = _PyAST_Import(names, lineno, col_offset, end_lineno,
  8282. end_col_offset, arena);
  8283. if (*out == NULL) goto failed;
  8284. return 0;
  8285. }
  8286. tp = state->ImportFrom_type;
  8287. isinstance = PyObject_IsInstance(obj, tp);
  8288. if (isinstance == -1) {
  8289. return 1;
  8290. }
  8291. if (isinstance) {
  8292. identifier module;
  8293. asdl_alias_seq* names;
  8294. int level;
  8295. if (_PyObject_LookupAttr(obj, state->module, &tmp) < 0) {
  8296. return 1;
  8297. }
  8298. if (tmp == NULL || tmp == Py_None) {
  8299. Py_CLEAR(tmp);
  8300. module = NULL;
  8301. }
  8302. else {
  8303. int res;
  8304. if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
  8305. goto failed;
  8306. }
  8307. res = obj2ast_identifier(state, tmp, &module, arena);
  8308. _Py_LeaveRecursiveCall();
  8309. if (res != 0) goto failed;
  8310. Py_CLEAR(tmp);
  8311. }
  8312. if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
  8313. return 1;
  8314. }
  8315. if (tmp == NULL) {
  8316. tmp = PyList_New(0);
  8317. if (tmp == NULL) {
  8318. return 1;
  8319. }
  8320. }
  8321. {
  8322. int res;
  8323. Py_ssize_t len;
  8324. Py_ssize_t i;
  8325. if (!PyList_Check(tmp)) {
  8326. PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8327. goto failed;
  8328. }
  8329. len = PyList_GET_SIZE(tmp);
  8330. names = _Py_asdl_alias_seq_new(len, arena);
  8331. if (names == NULL) goto failed;
  8332. for (i = 0; i < len; i++) {
  8333. alias_ty val;
  8334. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8335. if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
  8336. goto failed;
  8337. }
  8338. res = obj2ast_alias(state, tmp2, &val, arena);
  8339. _Py_LeaveRecursiveCall();
  8340. Py_DECREF(tmp2);
  8341. if (res != 0) goto failed;
  8342. if (len != PyList_GET_SIZE(tmp)) {
  8343. PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
  8344. goto failed;
  8345. }
  8346. asdl_seq_SET(names, i, val);
  8347. }
  8348. Py_CLEAR(tmp);
  8349. }
  8350. if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) {
  8351. return 1;
  8352. }
  8353. if (tmp == NULL || tmp == Py_None) {
  8354. Py_CLEAR(tmp);
  8355. level = 0;
  8356. }
  8357. else {
  8358. int res;
  8359. if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
  8360. goto failed;
  8361. }
  8362. res = obj2ast_int(state, tmp, &level, arena);
  8363. _Py_LeaveRecursiveCall();
  8364. if (res != 0) goto failed;
  8365. Py_CLEAR(tmp);
  8366. }
  8367. *out = _PyAST_ImportFrom(module, names, level, lineno, col_offset,
  8368. end_lineno, end_col_offset, arena);
  8369. if (*out == NULL) goto failed;
  8370. return 0;
  8371. }
  8372. tp = state->Global_type;
  8373. isinstance = PyObject_IsInstance(obj, tp);
  8374. if (isinstance == -1) {
  8375. return 1;
  8376. }
  8377. if (isinstance) {
  8378. asdl_identifier_seq* names;
  8379. if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
  8380. return 1;
  8381. }
  8382. if (tmp == NULL) {
  8383. tmp = PyList_New(0);
  8384. if (tmp == NULL) {
  8385. return 1;
  8386. }
  8387. }
  8388. {
  8389. int res;
  8390. Py_ssize_t len;
  8391. Py_ssize_t i;
  8392. if (!PyList_Check(tmp)) {
  8393. PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8394. goto failed;
  8395. }
  8396. len = PyList_GET_SIZE(tmp);
  8397. names = _Py_asdl_identifier_seq_new(len, arena);
  8398. if (names == NULL) goto failed;
  8399. for (i = 0; i < len; i++) {
  8400. identifier val;
  8401. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8402. if (_Py_EnterRecursiveCall(" while traversing 'Global' node")) {
  8403. goto failed;
  8404. }
  8405. res = obj2ast_identifier(state, tmp2, &val, arena);
  8406. _Py_LeaveRecursiveCall();
  8407. Py_DECREF(tmp2);
  8408. if (res != 0) goto failed;
  8409. if (len != PyList_GET_SIZE(tmp)) {
  8410. PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
  8411. goto failed;
  8412. }
  8413. asdl_seq_SET(names, i, val);
  8414. }
  8415. Py_CLEAR(tmp);
  8416. }
  8417. *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
  8418. end_col_offset, arena);
  8419. if (*out == NULL) goto failed;
  8420. return 0;
  8421. }
  8422. tp = state->Nonlocal_type;
  8423. isinstance = PyObject_IsInstance(obj, tp);
  8424. if (isinstance == -1) {
  8425. return 1;
  8426. }
  8427. if (isinstance) {
  8428. asdl_identifier_seq* names;
  8429. if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
  8430. return 1;
  8431. }
  8432. if (tmp == NULL) {
  8433. tmp = PyList_New(0);
  8434. if (tmp == NULL) {
  8435. return 1;
  8436. }
  8437. }
  8438. {
  8439. int res;
  8440. Py_ssize_t len;
  8441. Py_ssize_t i;
  8442. if (!PyList_Check(tmp)) {
  8443. PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8444. goto failed;
  8445. }
  8446. len = PyList_GET_SIZE(tmp);
  8447. names = _Py_asdl_identifier_seq_new(len, arena);
  8448. if (names == NULL) goto failed;
  8449. for (i = 0; i < len; i++) {
  8450. identifier val;
  8451. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8452. if (_Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
  8453. goto failed;
  8454. }
  8455. res = obj2ast_identifier(state, tmp2, &val, arena);
  8456. _Py_LeaveRecursiveCall();
  8457. Py_DECREF(tmp2);
  8458. if (res != 0) goto failed;
  8459. if (len != PyList_GET_SIZE(tmp)) {
  8460. PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
  8461. goto failed;
  8462. }
  8463. asdl_seq_SET(names, i, val);
  8464. }
  8465. Py_CLEAR(tmp);
  8466. }
  8467. *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
  8468. end_col_offset, arena);
  8469. if (*out == NULL) goto failed;
  8470. return 0;
  8471. }
  8472. tp = state->Expr_type;
  8473. isinstance = PyObject_IsInstance(obj, tp);
  8474. if (isinstance == -1) {
  8475. return 1;
  8476. }
  8477. if (isinstance) {
  8478. expr_ty value;
  8479. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  8480. return 1;
  8481. }
  8482. if (tmp == NULL) {
  8483. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
  8484. return 1;
  8485. }
  8486. else {
  8487. int res;
  8488. if (_Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
  8489. goto failed;
  8490. }
  8491. res = obj2ast_expr(state, tmp, &value, arena);
  8492. _Py_LeaveRecursiveCall();
  8493. if (res != 0) goto failed;
  8494. Py_CLEAR(tmp);
  8495. }
  8496. *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
  8497. end_col_offset, arena);
  8498. if (*out == NULL) goto failed;
  8499. return 0;
  8500. }
  8501. tp = state->Pass_type;
  8502. isinstance = PyObject_IsInstance(obj, tp);
  8503. if (isinstance == -1) {
  8504. return 1;
  8505. }
  8506. if (isinstance) {
  8507. *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
  8508. arena);
  8509. if (*out == NULL) goto failed;
  8510. return 0;
  8511. }
  8512. tp = state->Break_type;
  8513. isinstance = PyObject_IsInstance(obj, tp);
  8514. if (isinstance == -1) {
  8515. return 1;
  8516. }
  8517. if (isinstance) {
  8518. *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
  8519. arena);
  8520. if (*out == NULL) goto failed;
  8521. return 0;
  8522. }
  8523. tp = state->Continue_type;
  8524. isinstance = PyObject_IsInstance(obj, tp);
  8525. if (isinstance == -1) {
  8526. return 1;
  8527. }
  8528. if (isinstance) {
  8529. *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
  8530. arena);
  8531. if (*out == NULL) goto failed;
  8532. return 0;
  8533. }
  8534. PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
  8535. failed:
  8536. Py_XDECREF(tmp);
  8537. return 1;
  8538. }
  8539. int
  8540. obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
  8541. arena)
  8542. {
  8543. int isinstance;
  8544. PyObject *tmp = NULL;
  8545. PyObject *tp;
  8546. int lineno;
  8547. int col_offset;
  8548. int end_lineno;
  8549. int end_col_offset;
  8550. if (obj == Py_None) {
  8551. *out = NULL;
  8552. return 0;
  8553. }
  8554. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  8555. return 1;
  8556. }
  8557. if (tmp == NULL) {
  8558. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
  8559. return 1;
  8560. }
  8561. else {
  8562. int res;
  8563. if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
  8564. goto failed;
  8565. }
  8566. res = obj2ast_int(state, tmp, &lineno, arena);
  8567. _Py_LeaveRecursiveCall();
  8568. if (res != 0) goto failed;
  8569. Py_CLEAR(tmp);
  8570. }
  8571. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  8572. return 1;
  8573. }
  8574. if (tmp == NULL) {
  8575. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
  8576. return 1;
  8577. }
  8578. else {
  8579. int res;
  8580. if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
  8581. goto failed;
  8582. }
  8583. res = obj2ast_int(state, tmp, &col_offset, arena);
  8584. _Py_LeaveRecursiveCall();
  8585. if (res != 0) goto failed;
  8586. Py_CLEAR(tmp);
  8587. }
  8588. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  8589. return 1;
  8590. }
  8591. if (tmp == NULL || tmp == Py_None) {
  8592. Py_CLEAR(tmp);
  8593. end_lineno = lineno;
  8594. }
  8595. else {
  8596. int res;
  8597. if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
  8598. goto failed;
  8599. }
  8600. res = obj2ast_int(state, tmp, &end_lineno, arena);
  8601. _Py_LeaveRecursiveCall();
  8602. if (res != 0) goto failed;
  8603. Py_CLEAR(tmp);
  8604. }
  8605. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  8606. return 1;
  8607. }
  8608. if (tmp == NULL || tmp == Py_None) {
  8609. Py_CLEAR(tmp);
  8610. end_col_offset = col_offset;
  8611. }
  8612. else {
  8613. int res;
  8614. if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
  8615. goto failed;
  8616. }
  8617. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  8618. _Py_LeaveRecursiveCall();
  8619. if (res != 0) goto failed;
  8620. Py_CLEAR(tmp);
  8621. }
  8622. tp = state->BoolOp_type;
  8623. isinstance = PyObject_IsInstance(obj, tp);
  8624. if (isinstance == -1) {
  8625. return 1;
  8626. }
  8627. if (isinstance) {
  8628. boolop_ty op;
  8629. asdl_expr_seq* values;
  8630. if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
  8631. return 1;
  8632. }
  8633. if (tmp == NULL) {
  8634. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
  8635. return 1;
  8636. }
  8637. else {
  8638. int res;
  8639. if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
  8640. goto failed;
  8641. }
  8642. res = obj2ast_boolop(state, tmp, &op, arena);
  8643. _Py_LeaveRecursiveCall();
  8644. if (res != 0) goto failed;
  8645. Py_CLEAR(tmp);
  8646. }
  8647. if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
  8648. return 1;
  8649. }
  8650. if (tmp == NULL) {
  8651. tmp = PyList_New(0);
  8652. if (tmp == NULL) {
  8653. return 1;
  8654. }
  8655. }
  8656. {
  8657. int res;
  8658. Py_ssize_t len;
  8659. Py_ssize_t i;
  8660. if (!PyList_Check(tmp)) {
  8661. PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8662. goto failed;
  8663. }
  8664. len = PyList_GET_SIZE(tmp);
  8665. values = _Py_asdl_expr_seq_new(len, arena);
  8666. if (values == NULL) goto failed;
  8667. for (i = 0; i < len; i++) {
  8668. expr_ty val;
  8669. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8670. if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
  8671. goto failed;
  8672. }
  8673. res = obj2ast_expr(state, tmp2, &val, arena);
  8674. _Py_LeaveRecursiveCall();
  8675. Py_DECREF(tmp2);
  8676. if (res != 0) goto failed;
  8677. if (len != PyList_GET_SIZE(tmp)) {
  8678. PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
  8679. goto failed;
  8680. }
  8681. asdl_seq_SET(values, i, val);
  8682. }
  8683. Py_CLEAR(tmp);
  8684. }
  8685. *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
  8686. end_col_offset, arena);
  8687. if (*out == NULL) goto failed;
  8688. return 0;
  8689. }
  8690. tp = state->NamedExpr_type;
  8691. isinstance = PyObject_IsInstance(obj, tp);
  8692. if (isinstance == -1) {
  8693. return 1;
  8694. }
  8695. if (isinstance) {
  8696. expr_ty target;
  8697. expr_ty value;
  8698. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  8699. return 1;
  8700. }
  8701. if (tmp == NULL) {
  8702. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
  8703. return 1;
  8704. }
  8705. else {
  8706. int res;
  8707. if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
  8708. goto failed;
  8709. }
  8710. res = obj2ast_expr(state, tmp, &target, arena);
  8711. _Py_LeaveRecursiveCall();
  8712. if (res != 0) goto failed;
  8713. Py_CLEAR(tmp);
  8714. }
  8715. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  8716. return 1;
  8717. }
  8718. if (tmp == NULL) {
  8719. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
  8720. return 1;
  8721. }
  8722. else {
  8723. int res;
  8724. if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
  8725. goto failed;
  8726. }
  8727. res = obj2ast_expr(state, tmp, &value, arena);
  8728. _Py_LeaveRecursiveCall();
  8729. if (res != 0) goto failed;
  8730. Py_CLEAR(tmp);
  8731. }
  8732. *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
  8733. end_col_offset, arena);
  8734. if (*out == NULL) goto failed;
  8735. return 0;
  8736. }
  8737. tp = state->BinOp_type;
  8738. isinstance = PyObject_IsInstance(obj, tp);
  8739. if (isinstance == -1) {
  8740. return 1;
  8741. }
  8742. if (isinstance) {
  8743. expr_ty left;
  8744. operator_ty op;
  8745. expr_ty right;
  8746. if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
  8747. return 1;
  8748. }
  8749. if (tmp == NULL) {
  8750. PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
  8751. return 1;
  8752. }
  8753. else {
  8754. int res;
  8755. if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
  8756. goto failed;
  8757. }
  8758. res = obj2ast_expr(state, tmp, &left, arena);
  8759. _Py_LeaveRecursiveCall();
  8760. if (res != 0) goto failed;
  8761. Py_CLEAR(tmp);
  8762. }
  8763. if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
  8764. return 1;
  8765. }
  8766. if (tmp == NULL) {
  8767. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
  8768. return 1;
  8769. }
  8770. else {
  8771. int res;
  8772. if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
  8773. goto failed;
  8774. }
  8775. res = obj2ast_operator(state, tmp, &op, arena);
  8776. _Py_LeaveRecursiveCall();
  8777. if (res != 0) goto failed;
  8778. Py_CLEAR(tmp);
  8779. }
  8780. if (_PyObject_LookupAttr(obj, state->right, &tmp) < 0) {
  8781. return 1;
  8782. }
  8783. if (tmp == NULL) {
  8784. PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
  8785. return 1;
  8786. }
  8787. else {
  8788. int res;
  8789. if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
  8790. goto failed;
  8791. }
  8792. res = obj2ast_expr(state, tmp, &right, arena);
  8793. _Py_LeaveRecursiveCall();
  8794. if (res != 0) goto failed;
  8795. Py_CLEAR(tmp);
  8796. }
  8797. *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
  8798. end_col_offset, arena);
  8799. if (*out == NULL) goto failed;
  8800. return 0;
  8801. }
  8802. tp = state->UnaryOp_type;
  8803. isinstance = PyObject_IsInstance(obj, tp);
  8804. if (isinstance == -1) {
  8805. return 1;
  8806. }
  8807. if (isinstance) {
  8808. unaryop_ty op;
  8809. expr_ty operand;
  8810. if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
  8811. return 1;
  8812. }
  8813. if (tmp == NULL) {
  8814. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
  8815. return 1;
  8816. }
  8817. else {
  8818. int res;
  8819. if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
  8820. goto failed;
  8821. }
  8822. res = obj2ast_unaryop(state, tmp, &op, arena);
  8823. _Py_LeaveRecursiveCall();
  8824. if (res != 0) goto failed;
  8825. Py_CLEAR(tmp);
  8826. }
  8827. if (_PyObject_LookupAttr(obj, state->operand, &tmp) < 0) {
  8828. return 1;
  8829. }
  8830. if (tmp == NULL) {
  8831. PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
  8832. return 1;
  8833. }
  8834. else {
  8835. int res;
  8836. if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
  8837. goto failed;
  8838. }
  8839. res = obj2ast_expr(state, tmp, &operand, arena);
  8840. _Py_LeaveRecursiveCall();
  8841. if (res != 0) goto failed;
  8842. Py_CLEAR(tmp);
  8843. }
  8844. *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
  8845. end_col_offset, arena);
  8846. if (*out == NULL) goto failed;
  8847. return 0;
  8848. }
  8849. tp = state->Lambda_type;
  8850. isinstance = PyObject_IsInstance(obj, tp);
  8851. if (isinstance == -1) {
  8852. return 1;
  8853. }
  8854. if (isinstance) {
  8855. arguments_ty args;
  8856. expr_ty body;
  8857. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  8858. return 1;
  8859. }
  8860. if (tmp == NULL) {
  8861. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
  8862. return 1;
  8863. }
  8864. else {
  8865. int res;
  8866. if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
  8867. goto failed;
  8868. }
  8869. res = obj2ast_arguments(state, tmp, &args, arena);
  8870. _Py_LeaveRecursiveCall();
  8871. if (res != 0) goto failed;
  8872. Py_CLEAR(tmp);
  8873. }
  8874. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  8875. return 1;
  8876. }
  8877. if (tmp == NULL) {
  8878. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
  8879. return 1;
  8880. }
  8881. else {
  8882. int res;
  8883. if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
  8884. goto failed;
  8885. }
  8886. res = obj2ast_expr(state, tmp, &body, arena);
  8887. _Py_LeaveRecursiveCall();
  8888. if (res != 0) goto failed;
  8889. Py_CLEAR(tmp);
  8890. }
  8891. *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
  8892. end_col_offset, arena);
  8893. if (*out == NULL) goto failed;
  8894. return 0;
  8895. }
  8896. tp = state->IfExp_type;
  8897. isinstance = PyObject_IsInstance(obj, tp);
  8898. if (isinstance == -1) {
  8899. return 1;
  8900. }
  8901. if (isinstance) {
  8902. expr_ty test;
  8903. expr_ty body;
  8904. expr_ty orelse;
  8905. if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
  8906. return 1;
  8907. }
  8908. if (tmp == NULL) {
  8909. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
  8910. return 1;
  8911. }
  8912. else {
  8913. int res;
  8914. if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
  8915. goto failed;
  8916. }
  8917. res = obj2ast_expr(state, tmp, &test, arena);
  8918. _Py_LeaveRecursiveCall();
  8919. if (res != 0) goto failed;
  8920. Py_CLEAR(tmp);
  8921. }
  8922. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  8923. return 1;
  8924. }
  8925. if (tmp == NULL) {
  8926. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
  8927. return 1;
  8928. }
  8929. else {
  8930. int res;
  8931. if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
  8932. goto failed;
  8933. }
  8934. res = obj2ast_expr(state, tmp, &body, arena);
  8935. _Py_LeaveRecursiveCall();
  8936. if (res != 0) goto failed;
  8937. Py_CLEAR(tmp);
  8938. }
  8939. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  8940. return 1;
  8941. }
  8942. if (tmp == NULL) {
  8943. PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
  8944. return 1;
  8945. }
  8946. else {
  8947. int res;
  8948. if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
  8949. goto failed;
  8950. }
  8951. res = obj2ast_expr(state, tmp, &orelse, arena);
  8952. _Py_LeaveRecursiveCall();
  8953. if (res != 0) goto failed;
  8954. Py_CLEAR(tmp);
  8955. }
  8956. *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
  8957. end_col_offset, arena);
  8958. if (*out == NULL) goto failed;
  8959. return 0;
  8960. }
  8961. tp = state->Dict_type;
  8962. isinstance = PyObject_IsInstance(obj, tp);
  8963. if (isinstance == -1) {
  8964. return 1;
  8965. }
  8966. if (isinstance) {
  8967. asdl_expr_seq* keys;
  8968. asdl_expr_seq* values;
  8969. if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
  8970. return 1;
  8971. }
  8972. if (tmp == NULL) {
  8973. tmp = PyList_New(0);
  8974. if (tmp == NULL) {
  8975. return 1;
  8976. }
  8977. }
  8978. {
  8979. int res;
  8980. Py_ssize_t len;
  8981. Py_ssize_t i;
  8982. if (!PyList_Check(tmp)) {
  8983. PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8984. goto failed;
  8985. }
  8986. len = PyList_GET_SIZE(tmp);
  8987. keys = _Py_asdl_expr_seq_new(len, arena);
  8988. if (keys == NULL) goto failed;
  8989. for (i = 0; i < len; i++) {
  8990. expr_ty val;
  8991. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8992. if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
  8993. goto failed;
  8994. }
  8995. res = obj2ast_expr(state, tmp2, &val, arena);
  8996. _Py_LeaveRecursiveCall();
  8997. Py_DECREF(tmp2);
  8998. if (res != 0) goto failed;
  8999. if (len != PyList_GET_SIZE(tmp)) {
  9000. PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
  9001. goto failed;
  9002. }
  9003. asdl_seq_SET(keys, i, val);
  9004. }
  9005. Py_CLEAR(tmp);
  9006. }
  9007. if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
  9008. return 1;
  9009. }
  9010. if (tmp == NULL) {
  9011. tmp = PyList_New(0);
  9012. if (tmp == NULL) {
  9013. return 1;
  9014. }
  9015. }
  9016. {
  9017. int res;
  9018. Py_ssize_t len;
  9019. Py_ssize_t i;
  9020. if (!PyList_Check(tmp)) {
  9021. PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9022. goto failed;
  9023. }
  9024. len = PyList_GET_SIZE(tmp);
  9025. values = _Py_asdl_expr_seq_new(len, arena);
  9026. if (values == NULL) goto failed;
  9027. for (i = 0; i < len; i++) {
  9028. expr_ty val;
  9029. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9030. if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
  9031. goto failed;
  9032. }
  9033. res = obj2ast_expr(state, tmp2, &val, arena);
  9034. _Py_LeaveRecursiveCall();
  9035. Py_DECREF(tmp2);
  9036. if (res != 0) goto failed;
  9037. if (len != PyList_GET_SIZE(tmp)) {
  9038. PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
  9039. goto failed;
  9040. }
  9041. asdl_seq_SET(values, i, val);
  9042. }
  9043. Py_CLEAR(tmp);
  9044. }
  9045. *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
  9046. end_col_offset, arena);
  9047. if (*out == NULL) goto failed;
  9048. return 0;
  9049. }
  9050. tp = state->Set_type;
  9051. isinstance = PyObject_IsInstance(obj, tp);
  9052. if (isinstance == -1) {
  9053. return 1;
  9054. }
  9055. if (isinstance) {
  9056. asdl_expr_seq* elts;
  9057. if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
  9058. return 1;
  9059. }
  9060. if (tmp == NULL) {
  9061. tmp = PyList_New(0);
  9062. if (tmp == NULL) {
  9063. return 1;
  9064. }
  9065. }
  9066. {
  9067. int res;
  9068. Py_ssize_t len;
  9069. Py_ssize_t i;
  9070. if (!PyList_Check(tmp)) {
  9071. PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9072. goto failed;
  9073. }
  9074. len = PyList_GET_SIZE(tmp);
  9075. elts = _Py_asdl_expr_seq_new(len, arena);
  9076. if (elts == NULL) goto failed;
  9077. for (i = 0; i < len; i++) {
  9078. expr_ty val;
  9079. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9080. if (_Py_EnterRecursiveCall(" while traversing 'Set' node")) {
  9081. goto failed;
  9082. }
  9083. res = obj2ast_expr(state, tmp2, &val, arena);
  9084. _Py_LeaveRecursiveCall();
  9085. Py_DECREF(tmp2);
  9086. if (res != 0) goto failed;
  9087. if (len != PyList_GET_SIZE(tmp)) {
  9088. PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
  9089. goto failed;
  9090. }
  9091. asdl_seq_SET(elts, i, val);
  9092. }
  9093. Py_CLEAR(tmp);
  9094. }
  9095. *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
  9096. arena);
  9097. if (*out == NULL) goto failed;
  9098. return 0;
  9099. }
  9100. tp = state->ListComp_type;
  9101. isinstance = PyObject_IsInstance(obj, tp);
  9102. if (isinstance == -1) {
  9103. return 1;
  9104. }
  9105. if (isinstance) {
  9106. expr_ty elt;
  9107. asdl_comprehension_seq* generators;
  9108. if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
  9109. return 1;
  9110. }
  9111. if (tmp == NULL) {
  9112. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
  9113. return 1;
  9114. }
  9115. else {
  9116. int res;
  9117. if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
  9118. goto failed;
  9119. }
  9120. res = obj2ast_expr(state, tmp, &elt, arena);
  9121. _Py_LeaveRecursiveCall();
  9122. if (res != 0) goto failed;
  9123. Py_CLEAR(tmp);
  9124. }
  9125. if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
  9126. return 1;
  9127. }
  9128. if (tmp == NULL) {
  9129. tmp = PyList_New(0);
  9130. if (tmp == NULL) {
  9131. return 1;
  9132. }
  9133. }
  9134. {
  9135. int res;
  9136. Py_ssize_t len;
  9137. Py_ssize_t i;
  9138. if (!PyList_Check(tmp)) {
  9139. PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9140. goto failed;
  9141. }
  9142. len = PyList_GET_SIZE(tmp);
  9143. generators = _Py_asdl_comprehension_seq_new(len, arena);
  9144. if (generators == NULL) goto failed;
  9145. for (i = 0; i < len; i++) {
  9146. comprehension_ty val;
  9147. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9148. if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
  9149. goto failed;
  9150. }
  9151. res = obj2ast_comprehension(state, tmp2, &val, arena);
  9152. _Py_LeaveRecursiveCall();
  9153. Py_DECREF(tmp2);
  9154. if (res != 0) goto failed;
  9155. if (len != PyList_GET_SIZE(tmp)) {
  9156. PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
  9157. goto failed;
  9158. }
  9159. asdl_seq_SET(generators, i, val);
  9160. }
  9161. Py_CLEAR(tmp);
  9162. }
  9163. *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
  9164. end_col_offset, arena);
  9165. if (*out == NULL) goto failed;
  9166. return 0;
  9167. }
  9168. tp = state->SetComp_type;
  9169. isinstance = PyObject_IsInstance(obj, tp);
  9170. if (isinstance == -1) {
  9171. return 1;
  9172. }
  9173. if (isinstance) {
  9174. expr_ty elt;
  9175. asdl_comprehension_seq* generators;
  9176. if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
  9177. return 1;
  9178. }
  9179. if (tmp == NULL) {
  9180. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
  9181. return 1;
  9182. }
  9183. else {
  9184. int res;
  9185. if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
  9186. goto failed;
  9187. }
  9188. res = obj2ast_expr(state, tmp, &elt, arena);
  9189. _Py_LeaveRecursiveCall();
  9190. if (res != 0) goto failed;
  9191. Py_CLEAR(tmp);
  9192. }
  9193. if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
  9194. return 1;
  9195. }
  9196. if (tmp == NULL) {
  9197. tmp = PyList_New(0);
  9198. if (tmp == NULL) {
  9199. return 1;
  9200. }
  9201. }
  9202. {
  9203. int res;
  9204. Py_ssize_t len;
  9205. Py_ssize_t i;
  9206. if (!PyList_Check(tmp)) {
  9207. PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9208. goto failed;
  9209. }
  9210. len = PyList_GET_SIZE(tmp);
  9211. generators = _Py_asdl_comprehension_seq_new(len, arena);
  9212. if (generators == NULL) goto failed;
  9213. for (i = 0; i < len; i++) {
  9214. comprehension_ty val;
  9215. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9216. if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
  9217. goto failed;
  9218. }
  9219. res = obj2ast_comprehension(state, tmp2, &val, arena);
  9220. _Py_LeaveRecursiveCall();
  9221. Py_DECREF(tmp2);
  9222. if (res != 0) goto failed;
  9223. if (len != PyList_GET_SIZE(tmp)) {
  9224. PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
  9225. goto failed;
  9226. }
  9227. asdl_seq_SET(generators, i, val);
  9228. }
  9229. Py_CLEAR(tmp);
  9230. }
  9231. *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
  9232. end_col_offset, arena);
  9233. if (*out == NULL) goto failed;
  9234. return 0;
  9235. }
  9236. tp = state->DictComp_type;
  9237. isinstance = PyObject_IsInstance(obj, tp);
  9238. if (isinstance == -1) {
  9239. return 1;
  9240. }
  9241. if (isinstance) {
  9242. expr_ty key;
  9243. expr_ty value;
  9244. asdl_comprehension_seq* generators;
  9245. if (_PyObject_LookupAttr(obj, state->key, &tmp) < 0) {
  9246. return 1;
  9247. }
  9248. if (tmp == NULL) {
  9249. PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
  9250. return 1;
  9251. }
  9252. else {
  9253. int res;
  9254. if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
  9255. goto failed;
  9256. }
  9257. res = obj2ast_expr(state, tmp, &key, arena);
  9258. _Py_LeaveRecursiveCall();
  9259. if (res != 0) goto failed;
  9260. Py_CLEAR(tmp);
  9261. }
  9262. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9263. return 1;
  9264. }
  9265. if (tmp == NULL) {
  9266. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
  9267. return 1;
  9268. }
  9269. else {
  9270. int res;
  9271. if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
  9272. goto failed;
  9273. }
  9274. res = obj2ast_expr(state, tmp, &value, arena);
  9275. _Py_LeaveRecursiveCall();
  9276. if (res != 0) goto failed;
  9277. Py_CLEAR(tmp);
  9278. }
  9279. if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
  9280. return 1;
  9281. }
  9282. if (tmp == NULL) {
  9283. tmp = PyList_New(0);
  9284. if (tmp == NULL) {
  9285. return 1;
  9286. }
  9287. }
  9288. {
  9289. int res;
  9290. Py_ssize_t len;
  9291. Py_ssize_t i;
  9292. if (!PyList_Check(tmp)) {
  9293. PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9294. goto failed;
  9295. }
  9296. len = PyList_GET_SIZE(tmp);
  9297. generators = _Py_asdl_comprehension_seq_new(len, arena);
  9298. if (generators == NULL) goto failed;
  9299. for (i = 0; i < len; i++) {
  9300. comprehension_ty val;
  9301. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9302. if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
  9303. goto failed;
  9304. }
  9305. res = obj2ast_comprehension(state, tmp2, &val, arena);
  9306. _Py_LeaveRecursiveCall();
  9307. Py_DECREF(tmp2);
  9308. if (res != 0) goto failed;
  9309. if (len != PyList_GET_SIZE(tmp)) {
  9310. PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
  9311. goto failed;
  9312. }
  9313. asdl_seq_SET(generators, i, val);
  9314. }
  9315. Py_CLEAR(tmp);
  9316. }
  9317. *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
  9318. end_lineno, end_col_offset, arena);
  9319. if (*out == NULL) goto failed;
  9320. return 0;
  9321. }
  9322. tp = state->GeneratorExp_type;
  9323. isinstance = PyObject_IsInstance(obj, tp);
  9324. if (isinstance == -1) {
  9325. return 1;
  9326. }
  9327. if (isinstance) {
  9328. expr_ty elt;
  9329. asdl_comprehension_seq* generators;
  9330. if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
  9331. return 1;
  9332. }
  9333. if (tmp == NULL) {
  9334. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
  9335. return 1;
  9336. }
  9337. else {
  9338. int res;
  9339. if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
  9340. goto failed;
  9341. }
  9342. res = obj2ast_expr(state, tmp, &elt, arena);
  9343. _Py_LeaveRecursiveCall();
  9344. if (res != 0) goto failed;
  9345. Py_CLEAR(tmp);
  9346. }
  9347. if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
  9348. return 1;
  9349. }
  9350. if (tmp == NULL) {
  9351. tmp = PyList_New(0);
  9352. if (tmp == NULL) {
  9353. return 1;
  9354. }
  9355. }
  9356. {
  9357. int res;
  9358. Py_ssize_t len;
  9359. Py_ssize_t i;
  9360. if (!PyList_Check(tmp)) {
  9361. PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9362. goto failed;
  9363. }
  9364. len = PyList_GET_SIZE(tmp);
  9365. generators = _Py_asdl_comprehension_seq_new(len, arena);
  9366. if (generators == NULL) goto failed;
  9367. for (i = 0; i < len; i++) {
  9368. comprehension_ty val;
  9369. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9370. if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
  9371. goto failed;
  9372. }
  9373. res = obj2ast_comprehension(state, tmp2, &val, arena);
  9374. _Py_LeaveRecursiveCall();
  9375. Py_DECREF(tmp2);
  9376. if (res != 0) goto failed;
  9377. if (len != PyList_GET_SIZE(tmp)) {
  9378. PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
  9379. goto failed;
  9380. }
  9381. asdl_seq_SET(generators, i, val);
  9382. }
  9383. Py_CLEAR(tmp);
  9384. }
  9385. *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
  9386. end_lineno, end_col_offset, arena);
  9387. if (*out == NULL) goto failed;
  9388. return 0;
  9389. }
  9390. tp = state->Await_type;
  9391. isinstance = PyObject_IsInstance(obj, tp);
  9392. if (isinstance == -1) {
  9393. return 1;
  9394. }
  9395. if (isinstance) {
  9396. expr_ty value;
  9397. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9398. return 1;
  9399. }
  9400. if (tmp == NULL) {
  9401. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
  9402. return 1;
  9403. }
  9404. else {
  9405. int res;
  9406. if (_Py_EnterRecursiveCall(" while traversing 'Await' node")) {
  9407. goto failed;
  9408. }
  9409. res = obj2ast_expr(state, tmp, &value, arena);
  9410. _Py_LeaveRecursiveCall();
  9411. if (res != 0) goto failed;
  9412. Py_CLEAR(tmp);
  9413. }
  9414. *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
  9415. end_col_offset, arena);
  9416. if (*out == NULL) goto failed;
  9417. return 0;
  9418. }
  9419. tp = state->Yield_type;
  9420. isinstance = PyObject_IsInstance(obj, tp);
  9421. if (isinstance == -1) {
  9422. return 1;
  9423. }
  9424. if (isinstance) {
  9425. expr_ty value;
  9426. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9427. return 1;
  9428. }
  9429. if (tmp == NULL || tmp == Py_None) {
  9430. Py_CLEAR(tmp);
  9431. value = NULL;
  9432. }
  9433. else {
  9434. int res;
  9435. if (_Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
  9436. goto failed;
  9437. }
  9438. res = obj2ast_expr(state, tmp, &value, arena);
  9439. _Py_LeaveRecursiveCall();
  9440. if (res != 0) goto failed;
  9441. Py_CLEAR(tmp);
  9442. }
  9443. *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
  9444. end_col_offset, arena);
  9445. if (*out == NULL) goto failed;
  9446. return 0;
  9447. }
  9448. tp = state->YieldFrom_type;
  9449. isinstance = PyObject_IsInstance(obj, tp);
  9450. if (isinstance == -1) {
  9451. return 1;
  9452. }
  9453. if (isinstance) {
  9454. expr_ty value;
  9455. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9456. return 1;
  9457. }
  9458. if (tmp == NULL) {
  9459. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
  9460. return 1;
  9461. }
  9462. else {
  9463. int res;
  9464. if (_Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
  9465. goto failed;
  9466. }
  9467. res = obj2ast_expr(state, tmp, &value, arena);
  9468. _Py_LeaveRecursiveCall();
  9469. if (res != 0) goto failed;
  9470. Py_CLEAR(tmp);
  9471. }
  9472. *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
  9473. end_col_offset, arena);
  9474. if (*out == NULL) goto failed;
  9475. return 0;
  9476. }
  9477. tp = state->Compare_type;
  9478. isinstance = PyObject_IsInstance(obj, tp);
  9479. if (isinstance == -1) {
  9480. return 1;
  9481. }
  9482. if (isinstance) {
  9483. expr_ty left;
  9484. asdl_int_seq* ops;
  9485. asdl_expr_seq* comparators;
  9486. if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
  9487. return 1;
  9488. }
  9489. if (tmp == NULL) {
  9490. PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
  9491. return 1;
  9492. }
  9493. else {
  9494. int res;
  9495. if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
  9496. goto failed;
  9497. }
  9498. res = obj2ast_expr(state, tmp, &left, arena);
  9499. _Py_LeaveRecursiveCall();
  9500. if (res != 0) goto failed;
  9501. Py_CLEAR(tmp);
  9502. }
  9503. if (_PyObject_LookupAttr(obj, state->ops, &tmp) < 0) {
  9504. return 1;
  9505. }
  9506. if (tmp == NULL) {
  9507. tmp = PyList_New(0);
  9508. if (tmp == NULL) {
  9509. return 1;
  9510. }
  9511. }
  9512. {
  9513. int res;
  9514. Py_ssize_t len;
  9515. Py_ssize_t i;
  9516. if (!PyList_Check(tmp)) {
  9517. PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9518. goto failed;
  9519. }
  9520. len = PyList_GET_SIZE(tmp);
  9521. ops = _Py_asdl_int_seq_new(len, arena);
  9522. if (ops == NULL) goto failed;
  9523. for (i = 0; i < len; i++) {
  9524. cmpop_ty val;
  9525. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9526. if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
  9527. goto failed;
  9528. }
  9529. res = obj2ast_cmpop(state, tmp2, &val, arena);
  9530. _Py_LeaveRecursiveCall();
  9531. Py_DECREF(tmp2);
  9532. if (res != 0) goto failed;
  9533. if (len != PyList_GET_SIZE(tmp)) {
  9534. PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
  9535. goto failed;
  9536. }
  9537. asdl_seq_SET(ops, i, val);
  9538. }
  9539. Py_CLEAR(tmp);
  9540. }
  9541. if (_PyObject_LookupAttr(obj, state->comparators, &tmp) < 0) {
  9542. return 1;
  9543. }
  9544. if (tmp == NULL) {
  9545. tmp = PyList_New(0);
  9546. if (tmp == NULL) {
  9547. return 1;
  9548. }
  9549. }
  9550. {
  9551. int res;
  9552. Py_ssize_t len;
  9553. Py_ssize_t i;
  9554. if (!PyList_Check(tmp)) {
  9555. PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9556. goto failed;
  9557. }
  9558. len = PyList_GET_SIZE(tmp);
  9559. comparators = _Py_asdl_expr_seq_new(len, arena);
  9560. if (comparators == NULL) goto failed;
  9561. for (i = 0; i < len; i++) {
  9562. expr_ty val;
  9563. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9564. if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
  9565. goto failed;
  9566. }
  9567. res = obj2ast_expr(state, tmp2, &val, arena);
  9568. _Py_LeaveRecursiveCall();
  9569. Py_DECREF(tmp2);
  9570. if (res != 0) goto failed;
  9571. if (len != PyList_GET_SIZE(tmp)) {
  9572. PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
  9573. goto failed;
  9574. }
  9575. asdl_seq_SET(comparators, i, val);
  9576. }
  9577. Py_CLEAR(tmp);
  9578. }
  9579. *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
  9580. end_lineno, end_col_offset, arena);
  9581. if (*out == NULL) goto failed;
  9582. return 0;
  9583. }
  9584. tp = state->Call_type;
  9585. isinstance = PyObject_IsInstance(obj, tp);
  9586. if (isinstance == -1) {
  9587. return 1;
  9588. }
  9589. if (isinstance) {
  9590. expr_ty func;
  9591. asdl_expr_seq* args;
  9592. asdl_keyword_seq* keywords;
  9593. if (_PyObject_LookupAttr(obj, state->func, &tmp) < 0) {
  9594. return 1;
  9595. }
  9596. if (tmp == NULL) {
  9597. PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
  9598. return 1;
  9599. }
  9600. else {
  9601. int res;
  9602. if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
  9603. goto failed;
  9604. }
  9605. res = obj2ast_expr(state, tmp, &func, arena);
  9606. _Py_LeaveRecursiveCall();
  9607. if (res != 0) goto failed;
  9608. Py_CLEAR(tmp);
  9609. }
  9610. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  9611. return 1;
  9612. }
  9613. if (tmp == NULL) {
  9614. tmp = PyList_New(0);
  9615. if (tmp == NULL) {
  9616. return 1;
  9617. }
  9618. }
  9619. {
  9620. int res;
  9621. Py_ssize_t len;
  9622. Py_ssize_t i;
  9623. if (!PyList_Check(tmp)) {
  9624. PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9625. goto failed;
  9626. }
  9627. len = PyList_GET_SIZE(tmp);
  9628. args = _Py_asdl_expr_seq_new(len, arena);
  9629. if (args == NULL) goto failed;
  9630. for (i = 0; i < len; i++) {
  9631. expr_ty val;
  9632. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9633. if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
  9634. goto failed;
  9635. }
  9636. res = obj2ast_expr(state, tmp2, &val, arena);
  9637. _Py_LeaveRecursiveCall();
  9638. Py_DECREF(tmp2);
  9639. if (res != 0) goto failed;
  9640. if (len != PyList_GET_SIZE(tmp)) {
  9641. PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
  9642. goto failed;
  9643. }
  9644. asdl_seq_SET(args, i, val);
  9645. }
  9646. Py_CLEAR(tmp);
  9647. }
  9648. if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
  9649. return 1;
  9650. }
  9651. if (tmp == NULL) {
  9652. tmp = PyList_New(0);
  9653. if (tmp == NULL) {
  9654. return 1;
  9655. }
  9656. }
  9657. {
  9658. int res;
  9659. Py_ssize_t len;
  9660. Py_ssize_t i;
  9661. if (!PyList_Check(tmp)) {
  9662. PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9663. goto failed;
  9664. }
  9665. len = PyList_GET_SIZE(tmp);
  9666. keywords = _Py_asdl_keyword_seq_new(len, arena);
  9667. if (keywords == NULL) goto failed;
  9668. for (i = 0; i < len; i++) {
  9669. keyword_ty val;
  9670. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9671. if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
  9672. goto failed;
  9673. }
  9674. res = obj2ast_keyword(state, tmp2, &val, arena);
  9675. _Py_LeaveRecursiveCall();
  9676. Py_DECREF(tmp2);
  9677. if (res != 0) goto failed;
  9678. if (len != PyList_GET_SIZE(tmp)) {
  9679. PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
  9680. goto failed;
  9681. }
  9682. asdl_seq_SET(keywords, i, val);
  9683. }
  9684. Py_CLEAR(tmp);
  9685. }
  9686. *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
  9687. end_lineno, end_col_offset, arena);
  9688. if (*out == NULL) goto failed;
  9689. return 0;
  9690. }
  9691. tp = state->FormattedValue_type;
  9692. isinstance = PyObject_IsInstance(obj, tp);
  9693. if (isinstance == -1) {
  9694. return 1;
  9695. }
  9696. if (isinstance) {
  9697. expr_ty value;
  9698. int conversion;
  9699. expr_ty format_spec;
  9700. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9701. return 1;
  9702. }
  9703. if (tmp == NULL) {
  9704. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
  9705. return 1;
  9706. }
  9707. else {
  9708. int res;
  9709. if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
  9710. goto failed;
  9711. }
  9712. res = obj2ast_expr(state, tmp, &value, arena);
  9713. _Py_LeaveRecursiveCall();
  9714. if (res != 0) goto failed;
  9715. Py_CLEAR(tmp);
  9716. }
  9717. if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) {
  9718. return 1;
  9719. }
  9720. if (tmp == NULL) {
  9721. PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
  9722. return 1;
  9723. }
  9724. else {
  9725. int res;
  9726. if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
  9727. goto failed;
  9728. }
  9729. res = obj2ast_int(state, tmp, &conversion, arena);
  9730. _Py_LeaveRecursiveCall();
  9731. if (res != 0) goto failed;
  9732. Py_CLEAR(tmp);
  9733. }
  9734. if (_PyObject_LookupAttr(obj, state->format_spec, &tmp) < 0) {
  9735. return 1;
  9736. }
  9737. if (tmp == NULL || tmp == Py_None) {
  9738. Py_CLEAR(tmp);
  9739. format_spec = NULL;
  9740. }
  9741. else {
  9742. int res;
  9743. if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
  9744. goto failed;
  9745. }
  9746. res = obj2ast_expr(state, tmp, &format_spec, arena);
  9747. _Py_LeaveRecursiveCall();
  9748. if (res != 0) goto failed;
  9749. Py_CLEAR(tmp);
  9750. }
  9751. *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
  9752. col_offset, end_lineno, end_col_offset,
  9753. arena);
  9754. if (*out == NULL) goto failed;
  9755. return 0;
  9756. }
  9757. tp = state->JoinedStr_type;
  9758. isinstance = PyObject_IsInstance(obj, tp);
  9759. if (isinstance == -1) {
  9760. return 1;
  9761. }
  9762. if (isinstance) {
  9763. asdl_expr_seq* values;
  9764. if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
  9765. return 1;
  9766. }
  9767. if (tmp == NULL) {
  9768. tmp = PyList_New(0);
  9769. if (tmp == NULL) {
  9770. return 1;
  9771. }
  9772. }
  9773. {
  9774. int res;
  9775. Py_ssize_t len;
  9776. Py_ssize_t i;
  9777. if (!PyList_Check(tmp)) {
  9778. PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9779. goto failed;
  9780. }
  9781. len = PyList_GET_SIZE(tmp);
  9782. values = _Py_asdl_expr_seq_new(len, arena);
  9783. if (values == NULL) goto failed;
  9784. for (i = 0; i < len; i++) {
  9785. expr_ty val;
  9786. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9787. if (_Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
  9788. goto failed;
  9789. }
  9790. res = obj2ast_expr(state, tmp2, &val, arena);
  9791. _Py_LeaveRecursiveCall();
  9792. Py_DECREF(tmp2);
  9793. if (res != 0) goto failed;
  9794. if (len != PyList_GET_SIZE(tmp)) {
  9795. PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
  9796. goto failed;
  9797. }
  9798. asdl_seq_SET(values, i, val);
  9799. }
  9800. Py_CLEAR(tmp);
  9801. }
  9802. *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
  9803. end_col_offset, arena);
  9804. if (*out == NULL) goto failed;
  9805. return 0;
  9806. }
  9807. tp = state->Constant_type;
  9808. isinstance = PyObject_IsInstance(obj, tp);
  9809. if (isinstance == -1) {
  9810. return 1;
  9811. }
  9812. if (isinstance) {
  9813. constant value;
  9814. string kind;
  9815. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9816. return 1;
  9817. }
  9818. if (tmp == NULL) {
  9819. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
  9820. return 1;
  9821. }
  9822. else {
  9823. int res;
  9824. if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
  9825. goto failed;
  9826. }
  9827. res = obj2ast_constant(state, tmp, &value, arena);
  9828. _Py_LeaveRecursiveCall();
  9829. if (res != 0) goto failed;
  9830. Py_CLEAR(tmp);
  9831. }
  9832. if (_PyObject_LookupAttr(obj, state->kind, &tmp) < 0) {
  9833. return 1;
  9834. }
  9835. if (tmp == NULL || tmp == Py_None) {
  9836. Py_CLEAR(tmp);
  9837. kind = NULL;
  9838. }
  9839. else {
  9840. int res;
  9841. if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
  9842. goto failed;
  9843. }
  9844. res = obj2ast_string(state, tmp, &kind, arena);
  9845. _Py_LeaveRecursiveCall();
  9846. if (res != 0) goto failed;
  9847. Py_CLEAR(tmp);
  9848. }
  9849. *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
  9850. end_col_offset, arena);
  9851. if (*out == NULL) goto failed;
  9852. return 0;
  9853. }
  9854. tp = state->Attribute_type;
  9855. isinstance = PyObject_IsInstance(obj, tp);
  9856. if (isinstance == -1) {
  9857. return 1;
  9858. }
  9859. if (isinstance) {
  9860. expr_ty value;
  9861. identifier attr;
  9862. expr_context_ty ctx;
  9863. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9864. return 1;
  9865. }
  9866. if (tmp == NULL) {
  9867. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
  9868. return 1;
  9869. }
  9870. else {
  9871. int res;
  9872. if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
  9873. goto failed;
  9874. }
  9875. res = obj2ast_expr(state, tmp, &value, arena);
  9876. _Py_LeaveRecursiveCall();
  9877. if (res != 0) goto failed;
  9878. Py_CLEAR(tmp);
  9879. }
  9880. if (_PyObject_LookupAttr(obj, state->attr, &tmp) < 0) {
  9881. return 1;
  9882. }
  9883. if (tmp == NULL) {
  9884. PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
  9885. return 1;
  9886. }
  9887. else {
  9888. int res;
  9889. if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
  9890. goto failed;
  9891. }
  9892. res = obj2ast_identifier(state, tmp, &attr, arena);
  9893. _Py_LeaveRecursiveCall();
  9894. if (res != 0) goto failed;
  9895. Py_CLEAR(tmp);
  9896. }
  9897. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  9898. return 1;
  9899. }
  9900. if (tmp == NULL) {
  9901. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
  9902. return 1;
  9903. }
  9904. else {
  9905. int res;
  9906. if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
  9907. goto failed;
  9908. }
  9909. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  9910. _Py_LeaveRecursiveCall();
  9911. if (res != 0) goto failed;
  9912. Py_CLEAR(tmp);
  9913. }
  9914. *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
  9915. end_lineno, end_col_offset, arena);
  9916. if (*out == NULL) goto failed;
  9917. return 0;
  9918. }
  9919. tp = state->Subscript_type;
  9920. isinstance = PyObject_IsInstance(obj, tp);
  9921. if (isinstance == -1) {
  9922. return 1;
  9923. }
  9924. if (isinstance) {
  9925. expr_ty value;
  9926. expr_ty slice;
  9927. expr_context_ty ctx;
  9928. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9929. return 1;
  9930. }
  9931. if (tmp == NULL) {
  9932. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
  9933. return 1;
  9934. }
  9935. else {
  9936. int res;
  9937. if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
  9938. goto failed;
  9939. }
  9940. res = obj2ast_expr(state, tmp, &value, arena);
  9941. _Py_LeaveRecursiveCall();
  9942. if (res != 0) goto failed;
  9943. Py_CLEAR(tmp);
  9944. }
  9945. if (_PyObject_LookupAttr(obj, state->slice, &tmp) < 0) {
  9946. return 1;
  9947. }
  9948. if (tmp == NULL) {
  9949. PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
  9950. return 1;
  9951. }
  9952. else {
  9953. int res;
  9954. if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
  9955. goto failed;
  9956. }
  9957. res = obj2ast_expr(state, tmp, &slice, arena);
  9958. _Py_LeaveRecursiveCall();
  9959. if (res != 0) goto failed;
  9960. Py_CLEAR(tmp);
  9961. }
  9962. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  9963. return 1;
  9964. }
  9965. if (tmp == NULL) {
  9966. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
  9967. return 1;
  9968. }
  9969. else {
  9970. int res;
  9971. if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
  9972. goto failed;
  9973. }
  9974. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  9975. _Py_LeaveRecursiveCall();
  9976. if (res != 0) goto failed;
  9977. Py_CLEAR(tmp);
  9978. }
  9979. *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
  9980. end_lineno, end_col_offset, arena);
  9981. if (*out == NULL) goto failed;
  9982. return 0;
  9983. }
  9984. tp = state->Starred_type;
  9985. isinstance = PyObject_IsInstance(obj, tp);
  9986. if (isinstance == -1) {
  9987. return 1;
  9988. }
  9989. if (isinstance) {
  9990. expr_ty value;
  9991. expr_context_ty ctx;
  9992. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9993. return 1;
  9994. }
  9995. if (tmp == NULL) {
  9996. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
  9997. return 1;
  9998. }
  9999. else {
  10000. int res;
  10001. if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
  10002. goto failed;
  10003. }
  10004. res = obj2ast_expr(state, tmp, &value, arena);
  10005. _Py_LeaveRecursiveCall();
  10006. if (res != 0) goto failed;
  10007. Py_CLEAR(tmp);
  10008. }
  10009. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  10010. return 1;
  10011. }
  10012. if (tmp == NULL) {
  10013. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
  10014. return 1;
  10015. }
  10016. else {
  10017. int res;
  10018. if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
  10019. goto failed;
  10020. }
  10021. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  10022. _Py_LeaveRecursiveCall();
  10023. if (res != 0) goto failed;
  10024. Py_CLEAR(tmp);
  10025. }
  10026. *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
  10027. end_col_offset, arena);
  10028. if (*out == NULL) goto failed;
  10029. return 0;
  10030. }
  10031. tp = state->Name_type;
  10032. isinstance = PyObject_IsInstance(obj, tp);
  10033. if (isinstance == -1) {
  10034. return 1;
  10035. }
  10036. if (isinstance) {
  10037. identifier id;
  10038. expr_context_ty ctx;
  10039. if (_PyObject_LookupAttr(obj, state->id, &tmp) < 0) {
  10040. return 1;
  10041. }
  10042. if (tmp == NULL) {
  10043. PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
  10044. return 1;
  10045. }
  10046. else {
  10047. int res;
  10048. if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
  10049. goto failed;
  10050. }
  10051. res = obj2ast_identifier(state, tmp, &id, arena);
  10052. _Py_LeaveRecursiveCall();
  10053. if (res != 0) goto failed;
  10054. Py_CLEAR(tmp);
  10055. }
  10056. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  10057. return 1;
  10058. }
  10059. if (tmp == NULL) {
  10060. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
  10061. return 1;
  10062. }
  10063. else {
  10064. int res;
  10065. if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
  10066. goto failed;
  10067. }
  10068. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  10069. _Py_LeaveRecursiveCall();
  10070. if (res != 0) goto failed;
  10071. Py_CLEAR(tmp);
  10072. }
  10073. *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
  10074. end_col_offset, arena);
  10075. if (*out == NULL) goto failed;
  10076. return 0;
  10077. }
  10078. tp = state->List_type;
  10079. isinstance = PyObject_IsInstance(obj, tp);
  10080. if (isinstance == -1) {
  10081. return 1;
  10082. }
  10083. if (isinstance) {
  10084. asdl_expr_seq* elts;
  10085. expr_context_ty ctx;
  10086. if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
  10087. return 1;
  10088. }
  10089. if (tmp == NULL) {
  10090. tmp = PyList_New(0);
  10091. if (tmp == NULL) {
  10092. return 1;
  10093. }
  10094. }
  10095. {
  10096. int res;
  10097. Py_ssize_t len;
  10098. Py_ssize_t i;
  10099. if (!PyList_Check(tmp)) {
  10100. PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10101. goto failed;
  10102. }
  10103. len = PyList_GET_SIZE(tmp);
  10104. elts = _Py_asdl_expr_seq_new(len, arena);
  10105. if (elts == NULL) goto failed;
  10106. for (i = 0; i < len; i++) {
  10107. expr_ty val;
  10108. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10109. if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
  10110. goto failed;
  10111. }
  10112. res = obj2ast_expr(state, tmp2, &val, arena);
  10113. _Py_LeaveRecursiveCall();
  10114. Py_DECREF(tmp2);
  10115. if (res != 0) goto failed;
  10116. if (len != PyList_GET_SIZE(tmp)) {
  10117. PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
  10118. goto failed;
  10119. }
  10120. asdl_seq_SET(elts, i, val);
  10121. }
  10122. Py_CLEAR(tmp);
  10123. }
  10124. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  10125. return 1;
  10126. }
  10127. if (tmp == NULL) {
  10128. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
  10129. return 1;
  10130. }
  10131. else {
  10132. int res;
  10133. if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
  10134. goto failed;
  10135. }
  10136. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  10137. _Py_LeaveRecursiveCall();
  10138. if (res != 0) goto failed;
  10139. Py_CLEAR(tmp);
  10140. }
  10141. *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
  10142. end_col_offset, arena);
  10143. if (*out == NULL) goto failed;
  10144. return 0;
  10145. }
  10146. tp = state->Tuple_type;
  10147. isinstance = PyObject_IsInstance(obj, tp);
  10148. if (isinstance == -1) {
  10149. return 1;
  10150. }
  10151. if (isinstance) {
  10152. asdl_expr_seq* elts;
  10153. expr_context_ty ctx;
  10154. if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
  10155. return 1;
  10156. }
  10157. if (tmp == NULL) {
  10158. tmp = PyList_New(0);
  10159. if (tmp == NULL) {
  10160. return 1;
  10161. }
  10162. }
  10163. {
  10164. int res;
  10165. Py_ssize_t len;
  10166. Py_ssize_t i;
  10167. if (!PyList_Check(tmp)) {
  10168. PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10169. goto failed;
  10170. }
  10171. len = PyList_GET_SIZE(tmp);
  10172. elts = _Py_asdl_expr_seq_new(len, arena);
  10173. if (elts == NULL) goto failed;
  10174. for (i = 0; i < len; i++) {
  10175. expr_ty val;
  10176. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10177. if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
  10178. goto failed;
  10179. }
  10180. res = obj2ast_expr(state, tmp2, &val, arena);
  10181. _Py_LeaveRecursiveCall();
  10182. Py_DECREF(tmp2);
  10183. if (res != 0) goto failed;
  10184. if (len != PyList_GET_SIZE(tmp)) {
  10185. PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
  10186. goto failed;
  10187. }
  10188. asdl_seq_SET(elts, i, val);
  10189. }
  10190. Py_CLEAR(tmp);
  10191. }
  10192. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  10193. return 1;
  10194. }
  10195. if (tmp == NULL) {
  10196. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
  10197. return 1;
  10198. }
  10199. else {
  10200. int res;
  10201. if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
  10202. goto failed;
  10203. }
  10204. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  10205. _Py_LeaveRecursiveCall();
  10206. if (res != 0) goto failed;
  10207. Py_CLEAR(tmp);
  10208. }
  10209. *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
  10210. end_col_offset, arena);
  10211. if (*out == NULL) goto failed;
  10212. return 0;
  10213. }
  10214. tp = state->Slice_type;
  10215. isinstance = PyObject_IsInstance(obj, tp);
  10216. if (isinstance == -1) {
  10217. return 1;
  10218. }
  10219. if (isinstance) {
  10220. expr_ty lower;
  10221. expr_ty upper;
  10222. expr_ty step;
  10223. if (_PyObject_LookupAttr(obj, state->lower, &tmp) < 0) {
  10224. return 1;
  10225. }
  10226. if (tmp == NULL || tmp == Py_None) {
  10227. Py_CLEAR(tmp);
  10228. lower = NULL;
  10229. }
  10230. else {
  10231. int res;
  10232. if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
  10233. goto failed;
  10234. }
  10235. res = obj2ast_expr(state, tmp, &lower, arena);
  10236. _Py_LeaveRecursiveCall();
  10237. if (res != 0) goto failed;
  10238. Py_CLEAR(tmp);
  10239. }
  10240. if (_PyObject_LookupAttr(obj, state->upper, &tmp) < 0) {
  10241. return 1;
  10242. }
  10243. if (tmp == NULL || tmp == Py_None) {
  10244. Py_CLEAR(tmp);
  10245. upper = NULL;
  10246. }
  10247. else {
  10248. int res;
  10249. if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
  10250. goto failed;
  10251. }
  10252. res = obj2ast_expr(state, tmp, &upper, arena);
  10253. _Py_LeaveRecursiveCall();
  10254. if (res != 0) goto failed;
  10255. Py_CLEAR(tmp);
  10256. }
  10257. if (_PyObject_LookupAttr(obj, state->step, &tmp) < 0) {
  10258. return 1;
  10259. }
  10260. if (tmp == NULL || tmp == Py_None) {
  10261. Py_CLEAR(tmp);
  10262. step = NULL;
  10263. }
  10264. else {
  10265. int res;
  10266. if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
  10267. goto failed;
  10268. }
  10269. res = obj2ast_expr(state, tmp, &step, arena);
  10270. _Py_LeaveRecursiveCall();
  10271. if (res != 0) goto failed;
  10272. Py_CLEAR(tmp);
  10273. }
  10274. *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
  10275. end_col_offset, arena);
  10276. if (*out == NULL) goto failed;
  10277. return 0;
  10278. }
  10279. PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
  10280. failed:
  10281. Py_XDECREF(tmp);
  10282. return 1;
  10283. }
  10284. int
  10285. obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
  10286. out, PyArena* arena)
  10287. {
  10288. int isinstance;
  10289. isinstance = PyObject_IsInstance(obj, state->Load_type);
  10290. if (isinstance == -1) {
  10291. return 1;
  10292. }
  10293. if (isinstance) {
  10294. *out = Load;
  10295. return 0;
  10296. }
  10297. isinstance = PyObject_IsInstance(obj, state->Store_type);
  10298. if (isinstance == -1) {
  10299. return 1;
  10300. }
  10301. if (isinstance) {
  10302. *out = Store;
  10303. return 0;
  10304. }
  10305. isinstance = PyObject_IsInstance(obj, state->Del_type);
  10306. if (isinstance == -1) {
  10307. return 1;
  10308. }
  10309. if (isinstance) {
  10310. *out = Del;
  10311. return 0;
  10312. }
  10313. PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
  10314. return 1;
  10315. }
  10316. int
  10317. obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
  10318. arena)
  10319. {
  10320. int isinstance;
  10321. isinstance = PyObject_IsInstance(obj, state->And_type);
  10322. if (isinstance == -1) {
  10323. return 1;
  10324. }
  10325. if (isinstance) {
  10326. *out = And;
  10327. return 0;
  10328. }
  10329. isinstance = PyObject_IsInstance(obj, state->Or_type);
  10330. if (isinstance == -1) {
  10331. return 1;
  10332. }
  10333. if (isinstance) {
  10334. *out = Or;
  10335. return 0;
  10336. }
  10337. PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
  10338. return 1;
  10339. }
  10340. int
  10341. obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
  10342. PyArena* arena)
  10343. {
  10344. int isinstance;
  10345. isinstance = PyObject_IsInstance(obj, state->Add_type);
  10346. if (isinstance == -1) {
  10347. return 1;
  10348. }
  10349. if (isinstance) {
  10350. *out = Add;
  10351. return 0;
  10352. }
  10353. isinstance = PyObject_IsInstance(obj, state->Sub_type);
  10354. if (isinstance == -1) {
  10355. return 1;
  10356. }
  10357. if (isinstance) {
  10358. *out = Sub;
  10359. return 0;
  10360. }
  10361. isinstance = PyObject_IsInstance(obj, state->Mult_type);
  10362. if (isinstance == -1) {
  10363. return 1;
  10364. }
  10365. if (isinstance) {
  10366. *out = Mult;
  10367. return 0;
  10368. }
  10369. isinstance = PyObject_IsInstance(obj, state->MatMult_type);
  10370. if (isinstance == -1) {
  10371. return 1;
  10372. }
  10373. if (isinstance) {
  10374. *out = MatMult;
  10375. return 0;
  10376. }
  10377. isinstance = PyObject_IsInstance(obj, state->Div_type);
  10378. if (isinstance == -1) {
  10379. return 1;
  10380. }
  10381. if (isinstance) {
  10382. *out = Div;
  10383. return 0;
  10384. }
  10385. isinstance = PyObject_IsInstance(obj, state->Mod_type);
  10386. if (isinstance == -1) {
  10387. return 1;
  10388. }
  10389. if (isinstance) {
  10390. *out = Mod;
  10391. return 0;
  10392. }
  10393. isinstance = PyObject_IsInstance(obj, state->Pow_type);
  10394. if (isinstance == -1) {
  10395. return 1;
  10396. }
  10397. if (isinstance) {
  10398. *out = Pow;
  10399. return 0;
  10400. }
  10401. isinstance = PyObject_IsInstance(obj, state->LShift_type);
  10402. if (isinstance == -1) {
  10403. return 1;
  10404. }
  10405. if (isinstance) {
  10406. *out = LShift;
  10407. return 0;
  10408. }
  10409. isinstance = PyObject_IsInstance(obj, state->RShift_type);
  10410. if (isinstance == -1) {
  10411. return 1;
  10412. }
  10413. if (isinstance) {
  10414. *out = RShift;
  10415. return 0;
  10416. }
  10417. isinstance = PyObject_IsInstance(obj, state->BitOr_type);
  10418. if (isinstance == -1) {
  10419. return 1;
  10420. }
  10421. if (isinstance) {
  10422. *out = BitOr;
  10423. return 0;
  10424. }
  10425. isinstance = PyObject_IsInstance(obj, state->BitXor_type);
  10426. if (isinstance == -1) {
  10427. return 1;
  10428. }
  10429. if (isinstance) {
  10430. *out = BitXor;
  10431. return 0;
  10432. }
  10433. isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
  10434. if (isinstance == -1) {
  10435. return 1;
  10436. }
  10437. if (isinstance) {
  10438. *out = BitAnd;
  10439. return 0;
  10440. }
  10441. isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
  10442. if (isinstance == -1) {
  10443. return 1;
  10444. }
  10445. if (isinstance) {
  10446. *out = FloorDiv;
  10447. return 0;
  10448. }
  10449. PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
  10450. return 1;
  10451. }
  10452. int
  10453. obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
  10454. PyArena* arena)
  10455. {
  10456. int isinstance;
  10457. isinstance = PyObject_IsInstance(obj, state->Invert_type);
  10458. if (isinstance == -1) {
  10459. return 1;
  10460. }
  10461. if (isinstance) {
  10462. *out = Invert;
  10463. return 0;
  10464. }
  10465. isinstance = PyObject_IsInstance(obj, state->Not_type);
  10466. if (isinstance == -1) {
  10467. return 1;
  10468. }
  10469. if (isinstance) {
  10470. *out = Not;
  10471. return 0;
  10472. }
  10473. isinstance = PyObject_IsInstance(obj, state->UAdd_type);
  10474. if (isinstance == -1) {
  10475. return 1;
  10476. }
  10477. if (isinstance) {
  10478. *out = UAdd;
  10479. return 0;
  10480. }
  10481. isinstance = PyObject_IsInstance(obj, state->USub_type);
  10482. if (isinstance == -1) {
  10483. return 1;
  10484. }
  10485. if (isinstance) {
  10486. *out = USub;
  10487. return 0;
  10488. }
  10489. PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
  10490. return 1;
  10491. }
  10492. int
  10493. obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
  10494. arena)
  10495. {
  10496. int isinstance;
  10497. isinstance = PyObject_IsInstance(obj, state->Eq_type);
  10498. if (isinstance == -1) {
  10499. return 1;
  10500. }
  10501. if (isinstance) {
  10502. *out = Eq;
  10503. return 0;
  10504. }
  10505. isinstance = PyObject_IsInstance(obj, state->NotEq_type);
  10506. if (isinstance == -1) {
  10507. return 1;
  10508. }
  10509. if (isinstance) {
  10510. *out = NotEq;
  10511. return 0;
  10512. }
  10513. isinstance = PyObject_IsInstance(obj, state->Lt_type);
  10514. if (isinstance == -1) {
  10515. return 1;
  10516. }
  10517. if (isinstance) {
  10518. *out = Lt;
  10519. return 0;
  10520. }
  10521. isinstance = PyObject_IsInstance(obj, state->LtE_type);
  10522. if (isinstance == -1) {
  10523. return 1;
  10524. }
  10525. if (isinstance) {
  10526. *out = LtE;
  10527. return 0;
  10528. }
  10529. isinstance = PyObject_IsInstance(obj, state->Gt_type);
  10530. if (isinstance == -1) {
  10531. return 1;
  10532. }
  10533. if (isinstance) {
  10534. *out = Gt;
  10535. return 0;
  10536. }
  10537. isinstance = PyObject_IsInstance(obj, state->GtE_type);
  10538. if (isinstance == -1) {
  10539. return 1;
  10540. }
  10541. if (isinstance) {
  10542. *out = GtE;
  10543. return 0;
  10544. }
  10545. isinstance = PyObject_IsInstance(obj, state->Is_type);
  10546. if (isinstance == -1) {
  10547. return 1;
  10548. }
  10549. if (isinstance) {
  10550. *out = Is;
  10551. return 0;
  10552. }
  10553. isinstance = PyObject_IsInstance(obj, state->IsNot_type);
  10554. if (isinstance == -1) {
  10555. return 1;
  10556. }
  10557. if (isinstance) {
  10558. *out = IsNot;
  10559. return 0;
  10560. }
  10561. isinstance = PyObject_IsInstance(obj, state->In_type);
  10562. if (isinstance == -1) {
  10563. return 1;
  10564. }
  10565. if (isinstance) {
  10566. *out = In;
  10567. return 0;
  10568. }
  10569. isinstance = PyObject_IsInstance(obj, state->NotIn_type);
  10570. if (isinstance == -1) {
  10571. return 1;
  10572. }
  10573. if (isinstance) {
  10574. *out = NotIn;
  10575. return 0;
  10576. }
  10577. PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
  10578. return 1;
  10579. }
  10580. int
  10581. obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
  10582. out, PyArena* arena)
  10583. {
  10584. PyObject* tmp = NULL;
  10585. expr_ty target;
  10586. expr_ty iter;
  10587. asdl_expr_seq* ifs;
  10588. int is_async;
  10589. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  10590. return 1;
  10591. }
  10592. if (tmp == NULL) {
  10593. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
  10594. return 1;
  10595. }
  10596. else {
  10597. int res;
  10598. if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
  10599. goto failed;
  10600. }
  10601. res = obj2ast_expr(state, tmp, &target, arena);
  10602. _Py_LeaveRecursiveCall();
  10603. if (res != 0) goto failed;
  10604. Py_CLEAR(tmp);
  10605. }
  10606. if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
  10607. return 1;
  10608. }
  10609. if (tmp == NULL) {
  10610. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
  10611. return 1;
  10612. }
  10613. else {
  10614. int res;
  10615. if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
  10616. goto failed;
  10617. }
  10618. res = obj2ast_expr(state, tmp, &iter, arena);
  10619. _Py_LeaveRecursiveCall();
  10620. if (res != 0) goto failed;
  10621. Py_CLEAR(tmp);
  10622. }
  10623. if (_PyObject_LookupAttr(obj, state->ifs, &tmp) < 0) {
  10624. return 1;
  10625. }
  10626. if (tmp == NULL) {
  10627. tmp = PyList_New(0);
  10628. if (tmp == NULL) {
  10629. return 1;
  10630. }
  10631. }
  10632. {
  10633. int res;
  10634. Py_ssize_t len;
  10635. Py_ssize_t i;
  10636. if (!PyList_Check(tmp)) {
  10637. PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10638. goto failed;
  10639. }
  10640. len = PyList_GET_SIZE(tmp);
  10641. ifs = _Py_asdl_expr_seq_new(len, arena);
  10642. if (ifs == NULL) goto failed;
  10643. for (i = 0; i < len; i++) {
  10644. expr_ty val;
  10645. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10646. if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
  10647. goto failed;
  10648. }
  10649. res = obj2ast_expr(state, tmp2, &val, arena);
  10650. _Py_LeaveRecursiveCall();
  10651. Py_DECREF(tmp2);
  10652. if (res != 0) goto failed;
  10653. if (len != PyList_GET_SIZE(tmp)) {
  10654. PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
  10655. goto failed;
  10656. }
  10657. asdl_seq_SET(ifs, i, val);
  10658. }
  10659. Py_CLEAR(tmp);
  10660. }
  10661. if (_PyObject_LookupAttr(obj, state->is_async, &tmp) < 0) {
  10662. return 1;
  10663. }
  10664. if (tmp == NULL) {
  10665. PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
  10666. return 1;
  10667. }
  10668. else {
  10669. int res;
  10670. if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
  10671. goto failed;
  10672. }
  10673. res = obj2ast_int(state, tmp, &is_async, arena);
  10674. _Py_LeaveRecursiveCall();
  10675. if (res != 0) goto failed;
  10676. Py_CLEAR(tmp);
  10677. }
  10678. *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
  10679. if (*out == NULL) goto failed;
  10680. return 0;
  10681. failed:
  10682. Py_XDECREF(tmp);
  10683. return 1;
  10684. }
  10685. int
  10686. obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
  10687. out, PyArena* arena)
  10688. {
  10689. int isinstance;
  10690. PyObject *tmp = NULL;
  10691. PyObject *tp;
  10692. int lineno;
  10693. int col_offset;
  10694. int end_lineno;
  10695. int end_col_offset;
  10696. if (obj == Py_None) {
  10697. *out = NULL;
  10698. return 0;
  10699. }
  10700. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  10701. return 1;
  10702. }
  10703. if (tmp == NULL) {
  10704. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
  10705. return 1;
  10706. }
  10707. else {
  10708. int res;
  10709. if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
  10710. goto failed;
  10711. }
  10712. res = obj2ast_int(state, tmp, &lineno, arena);
  10713. _Py_LeaveRecursiveCall();
  10714. if (res != 0) goto failed;
  10715. Py_CLEAR(tmp);
  10716. }
  10717. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  10718. return 1;
  10719. }
  10720. if (tmp == NULL) {
  10721. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
  10722. return 1;
  10723. }
  10724. else {
  10725. int res;
  10726. if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
  10727. goto failed;
  10728. }
  10729. res = obj2ast_int(state, tmp, &col_offset, arena);
  10730. _Py_LeaveRecursiveCall();
  10731. if (res != 0) goto failed;
  10732. Py_CLEAR(tmp);
  10733. }
  10734. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  10735. return 1;
  10736. }
  10737. if (tmp == NULL || tmp == Py_None) {
  10738. Py_CLEAR(tmp);
  10739. end_lineno = lineno;
  10740. }
  10741. else {
  10742. int res;
  10743. if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
  10744. goto failed;
  10745. }
  10746. res = obj2ast_int(state, tmp, &end_lineno, arena);
  10747. _Py_LeaveRecursiveCall();
  10748. if (res != 0) goto failed;
  10749. Py_CLEAR(tmp);
  10750. }
  10751. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  10752. return 1;
  10753. }
  10754. if (tmp == NULL || tmp == Py_None) {
  10755. Py_CLEAR(tmp);
  10756. end_col_offset = col_offset;
  10757. }
  10758. else {
  10759. int res;
  10760. if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
  10761. goto failed;
  10762. }
  10763. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  10764. _Py_LeaveRecursiveCall();
  10765. if (res != 0) goto failed;
  10766. Py_CLEAR(tmp);
  10767. }
  10768. tp = state->ExceptHandler_type;
  10769. isinstance = PyObject_IsInstance(obj, tp);
  10770. if (isinstance == -1) {
  10771. return 1;
  10772. }
  10773. if (isinstance) {
  10774. expr_ty type;
  10775. identifier name;
  10776. asdl_stmt_seq* body;
  10777. if (_PyObject_LookupAttr(obj, state->type, &tmp) < 0) {
  10778. return 1;
  10779. }
  10780. if (tmp == NULL || tmp == Py_None) {
  10781. Py_CLEAR(tmp);
  10782. type = NULL;
  10783. }
  10784. else {
  10785. int res;
  10786. if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
  10787. goto failed;
  10788. }
  10789. res = obj2ast_expr(state, tmp, &type, arena);
  10790. _Py_LeaveRecursiveCall();
  10791. if (res != 0) goto failed;
  10792. Py_CLEAR(tmp);
  10793. }
  10794. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  10795. return 1;
  10796. }
  10797. if (tmp == NULL || tmp == Py_None) {
  10798. Py_CLEAR(tmp);
  10799. name = NULL;
  10800. }
  10801. else {
  10802. int res;
  10803. if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
  10804. goto failed;
  10805. }
  10806. res = obj2ast_identifier(state, tmp, &name, arena);
  10807. _Py_LeaveRecursiveCall();
  10808. if (res != 0) goto failed;
  10809. Py_CLEAR(tmp);
  10810. }
  10811. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  10812. return 1;
  10813. }
  10814. if (tmp == NULL) {
  10815. tmp = PyList_New(0);
  10816. if (tmp == NULL) {
  10817. return 1;
  10818. }
  10819. }
  10820. {
  10821. int res;
  10822. Py_ssize_t len;
  10823. Py_ssize_t i;
  10824. if (!PyList_Check(tmp)) {
  10825. PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10826. goto failed;
  10827. }
  10828. len = PyList_GET_SIZE(tmp);
  10829. body = _Py_asdl_stmt_seq_new(len, arena);
  10830. if (body == NULL) goto failed;
  10831. for (i = 0; i < len; i++) {
  10832. stmt_ty val;
  10833. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10834. if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
  10835. goto failed;
  10836. }
  10837. res = obj2ast_stmt(state, tmp2, &val, arena);
  10838. _Py_LeaveRecursiveCall();
  10839. Py_DECREF(tmp2);
  10840. if (res != 0) goto failed;
  10841. if (len != PyList_GET_SIZE(tmp)) {
  10842. PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
  10843. goto failed;
  10844. }
  10845. asdl_seq_SET(body, i, val);
  10846. }
  10847. Py_CLEAR(tmp);
  10848. }
  10849. *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
  10850. end_lineno, end_col_offset, arena);
  10851. if (*out == NULL) goto failed;
  10852. return 0;
  10853. }
  10854. PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
  10855. failed:
  10856. Py_XDECREF(tmp);
  10857. return 1;
  10858. }
  10859. int
  10860. obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
  10861. PyArena* arena)
  10862. {
  10863. PyObject* tmp = NULL;
  10864. asdl_arg_seq* posonlyargs;
  10865. asdl_arg_seq* args;
  10866. arg_ty vararg;
  10867. asdl_arg_seq* kwonlyargs;
  10868. asdl_expr_seq* kw_defaults;
  10869. arg_ty kwarg;
  10870. asdl_expr_seq* defaults;
  10871. if (_PyObject_LookupAttr(obj, state->posonlyargs, &tmp) < 0) {
  10872. return 1;
  10873. }
  10874. if (tmp == NULL) {
  10875. tmp = PyList_New(0);
  10876. if (tmp == NULL) {
  10877. return 1;
  10878. }
  10879. }
  10880. {
  10881. int res;
  10882. Py_ssize_t len;
  10883. Py_ssize_t i;
  10884. if (!PyList_Check(tmp)) {
  10885. PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10886. goto failed;
  10887. }
  10888. len = PyList_GET_SIZE(tmp);
  10889. posonlyargs = _Py_asdl_arg_seq_new(len, arena);
  10890. if (posonlyargs == NULL) goto failed;
  10891. for (i = 0; i < len; i++) {
  10892. arg_ty val;
  10893. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10894. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  10895. goto failed;
  10896. }
  10897. res = obj2ast_arg(state, tmp2, &val, arena);
  10898. _Py_LeaveRecursiveCall();
  10899. Py_DECREF(tmp2);
  10900. if (res != 0) goto failed;
  10901. if (len != PyList_GET_SIZE(tmp)) {
  10902. PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
  10903. goto failed;
  10904. }
  10905. asdl_seq_SET(posonlyargs, i, val);
  10906. }
  10907. Py_CLEAR(tmp);
  10908. }
  10909. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  10910. return 1;
  10911. }
  10912. if (tmp == NULL) {
  10913. tmp = PyList_New(0);
  10914. if (tmp == NULL) {
  10915. return 1;
  10916. }
  10917. }
  10918. {
  10919. int res;
  10920. Py_ssize_t len;
  10921. Py_ssize_t i;
  10922. if (!PyList_Check(tmp)) {
  10923. PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10924. goto failed;
  10925. }
  10926. len = PyList_GET_SIZE(tmp);
  10927. args = _Py_asdl_arg_seq_new(len, arena);
  10928. if (args == NULL) goto failed;
  10929. for (i = 0; i < len; i++) {
  10930. arg_ty val;
  10931. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10932. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  10933. goto failed;
  10934. }
  10935. res = obj2ast_arg(state, tmp2, &val, arena);
  10936. _Py_LeaveRecursiveCall();
  10937. Py_DECREF(tmp2);
  10938. if (res != 0) goto failed;
  10939. if (len != PyList_GET_SIZE(tmp)) {
  10940. PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
  10941. goto failed;
  10942. }
  10943. asdl_seq_SET(args, i, val);
  10944. }
  10945. Py_CLEAR(tmp);
  10946. }
  10947. if (_PyObject_LookupAttr(obj, state->vararg, &tmp) < 0) {
  10948. return 1;
  10949. }
  10950. if (tmp == NULL || tmp == Py_None) {
  10951. Py_CLEAR(tmp);
  10952. vararg = NULL;
  10953. }
  10954. else {
  10955. int res;
  10956. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  10957. goto failed;
  10958. }
  10959. res = obj2ast_arg(state, tmp, &vararg, arena);
  10960. _Py_LeaveRecursiveCall();
  10961. if (res != 0) goto failed;
  10962. Py_CLEAR(tmp);
  10963. }
  10964. if (_PyObject_LookupAttr(obj, state->kwonlyargs, &tmp) < 0) {
  10965. return 1;
  10966. }
  10967. if (tmp == NULL) {
  10968. tmp = PyList_New(0);
  10969. if (tmp == NULL) {
  10970. return 1;
  10971. }
  10972. }
  10973. {
  10974. int res;
  10975. Py_ssize_t len;
  10976. Py_ssize_t i;
  10977. if (!PyList_Check(tmp)) {
  10978. PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10979. goto failed;
  10980. }
  10981. len = PyList_GET_SIZE(tmp);
  10982. kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
  10983. if (kwonlyargs == NULL) goto failed;
  10984. for (i = 0; i < len; i++) {
  10985. arg_ty val;
  10986. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10987. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  10988. goto failed;
  10989. }
  10990. res = obj2ast_arg(state, tmp2, &val, arena);
  10991. _Py_LeaveRecursiveCall();
  10992. Py_DECREF(tmp2);
  10993. if (res != 0) goto failed;
  10994. if (len != PyList_GET_SIZE(tmp)) {
  10995. PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
  10996. goto failed;
  10997. }
  10998. asdl_seq_SET(kwonlyargs, i, val);
  10999. }
  11000. Py_CLEAR(tmp);
  11001. }
  11002. if (_PyObject_LookupAttr(obj, state->kw_defaults, &tmp) < 0) {
  11003. return 1;
  11004. }
  11005. if (tmp == NULL) {
  11006. tmp = PyList_New(0);
  11007. if (tmp == NULL) {
  11008. return 1;
  11009. }
  11010. }
  11011. {
  11012. int res;
  11013. Py_ssize_t len;
  11014. Py_ssize_t i;
  11015. if (!PyList_Check(tmp)) {
  11016. PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11017. goto failed;
  11018. }
  11019. len = PyList_GET_SIZE(tmp);
  11020. kw_defaults = _Py_asdl_expr_seq_new(len, arena);
  11021. if (kw_defaults == NULL) goto failed;
  11022. for (i = 0; i < len; i++) {
  11023. expr_ty val;
  11024. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11025. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  11026. goto failed;
  11027. }
  11028. res = obj2ast_expr(state, tmp2, &val, arena);
  11029. _Py_LeaveRecursiveCall();
  11030. Py_DECREF(tmp2);
  11031. if (res != 0) goto failed;
  11032. if (len != PyList_GET_SIZE(tmp)) {
  11033. PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
  11034. goto failed;
  11035. }
  11036. asdl_seq_SET(kw_defaults, i, val);
  11037. }
  11038. Py_CLEAR(tmp);
  11039. }
  11040. if (_PyObject_LookupAttr(obj, state->kwarg, &tmp) < 0) {
  11041. return 1;
  11042. }
  11043. if (tmp == NULL || tmp == Py_None) {
  11044. Py_CLEAR(tmp);
  11045. kwarg = NULL;
  11046. }
  11047. else {
  11048. int res;
  11049. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  11050. goto failed;
  11051. }
  11052. res = obj2ast_arg(state, tmp, &kwarg, arena);
  11053. _Py_LeaveRecursiveCall();
  11054. if (res != 0) goto failed;
  11055. Py_CLEAR(tmp);
  11056. }
  11057. if (_PyObject_LookupAttr(obj, state->defaults, &tmp) < 0) {
  11058. return 1;
  11059. }
  11060. if (tmp == NULL) {
  11061. tmp = PyList_New(0);
  11062. if (tmp == NULL) {
  11063. return 1;
  11064. }
  11065. }
  11066. {
  11067. int res;
  11068. Py_ssize_t len;
  11069. Py_ssize_t i;
  11070. if (!PyList_Check(tmp)) {
  11071. PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11072. goto failed;
  11073. }
  11074. len = PyList_GET_SIZE(tmp);
  11075. defaults = _Py_asdl_expr_seq_new(len, arena);
  11076. if (defaults == NULL) goto failed;
  11077. for (i = 0; i < len; i++) {
  11078. expr_ty val;
  11079. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11080. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  11081. goto failed;
  11082. }
  11083. res = obj2ast_expr(state, tmp2, &val, arena);
  11084. _Py_LeaveRecursiveCall();
  11085. Py_DECREF(tmp2);
  11086. if (res != 0) goto failed;
  11087. if (len != PyList_GET_SIZE(tmp)) {
  11088. PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
  11089. goto failed;
  11090. }
  11091. asdl_seq_SET(defaults, i, val);
  11092. }
  11093. Py_CLEAR(tmp);
  11094. }
  11095. *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
  11096. kwarg, defaults, arena);
  11097. if (*out == NULL) goto failed;
  11098. return 0;
  11099. failed:
  11100. Py_XDECREF(tmp);
  11101. return 1;
  11102. }
  11103. int
  11104. obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
  11105. {
  11106. PyObject* tmp = NULL;
  11107. identifier arg;
  11108. expr_ty annotation;
  11109. string type_comment;
  11110. int lineno;
  11111. int col_offset;
  11112. int end_lineno;
  11113. int end_col_offset;
  11114. if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
  11115. return 1;
  11116. }
  11117. if (tmp == NULL) {
  11118. PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
  11119. return 1;
  11120. }
  11121. else {
  11122. int res;
  11123. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11124. goto failed;
  11125. }
  11126. res = obj2ast_identifier(state, tmp, &arg, arena);
  11127. _Py_LeaveRecursiveCall();
  11128. if (res != 0) goto failed;
  11129. Py_CLEAR(tmp);
  11130. }
  11131. if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
  11132. return 1;
  11133. }
  11134. if (tmp == NULL || tmp == Py_None) {
  11135. Py_CLEAR(tmp);
  11136. annotation = NULL;
  11137. }
  11138. else {
  11139. int res;
  11140. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11141. goto failed;
  11142. }
  11143. res = obj2ast_expr(state, tmp, &annotation, arena);
  11144. _Py_LeaveRecursiveCall();
  11145. if (res != 0) goto failed;
  11146. Py_CLEAR(tmp);
  11147. }
  11148. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  11149. return 1;
  11150. }
  11151. if (tmp == NULL || tmp == Py_None) {
  11152. Py_CLEAR(tmp);
  11153. type_comment = NULL;
  11154. }
  11155. else {
  11156. int res;
  11157. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11158. goto failed;
  11159. }
  11160. res = obj2ast_string(state, tmp, &type_comment, arena);
  11161. _Py_LeaveRecursiveCall();
  11162. if (res != 0) goto failed;
  11163. Py_CLEAR(tmp);
  11164. }
  11165. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  11166. return 1;
  11167. }
  11168. if (tmp == NULL) {
  11169. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
  11170. return 1;
  11171. }
  11172. else {
  11173. int res;
  11174. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11175. goto failed;
  11176. }
  11177. res = obj2ast_int(state, tmp, &lineno, arena);
  11178. _Py_LeaveRecursiveCall();
  11179. if (res != 0) goto failed;
  11180. Py_CLEAR(tmp);
  11181. }
  11182. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  11183. return 1;
  11184. }
  11185. if (tmp == NULL) {
  11186. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
  11187. return 1;
  11188. }
  11189. else {
  11190. int res;
  11191. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11192. goto failed;
  11193. }
  11194. res = obj2ast_int(state, tmp, &col_offset, arena);
  11195. _Py_LeaveRecursiveCall();
  11196. if (res != 0) goto failed;
  11197. Py_CLEAR(tmp);
  11198. }
  11199. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  11200. return 1;
  11201. }
  11202. if (tmp == NULL || tmp == Py_None) {
  11203. Py_CLEAR(tmp);
  11204. end_lineno = lineno;
  11205. }
  11206. else {
  11207. int res;
  11208. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11209. goto failed;
  11210. }
  11211. res = obj2ast_int(state, tmp, &end_lineno, arena);
  11212. _Py_LeaveRecursiveCall();
  11213. if (res != 0) goto failed;
  11214. Py_CLEAR(tmp);
  11215. }
  11216. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  11217. return 1;
  11218. }
  11219. if (tmp == NULL || tmp == Py_None) {
  11220. Py_CLEAR(tmp);
  11221. end_col_offset = col_offset;
  11222. }
  11223. else {
  11224. int res;
  11225. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11226. goto failed;
  11227. }
  11228. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  11229. _Py_LeaveRecursiveCall();
  11230. if (res != 0) goto failed;
  11231. Py_CLEAR(tmp);
  11232. }
  11233. *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
  11234. end_lineno, end_col_offset, arena);
  11235. if (*out == NULL) goto failed;
  11236. return 0;
  11237. failed:
  11238. Py_XDECREF(tmp);
  11239. return 1;
  11240. }
  11241. int
  11242. obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
  11243. PyArena* arena)
  11244. {
  11245. PyObject* tmp = NULL;
  11246. identifier arg;
  11247. expr_ty value;
  11248. int lineno;
  11249. int col_offset;
  11250. int end_lineno;
  11251. int end_col_offset;
  11252. if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
  11253. return 1;
  11254. }
  11255. if (tmp == NULL || tmp == Py_None) {
  11256. Py_CLEAR(tmp);
  11257. arg = NULL;
  11258. }
  11259. else {
  11260. int res;
  11261. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11262. goto failed;
  11263. }
  11264. res = obj2ast_identifier(state, tmp, &arg, arena);
  11265. _Py_LeaveRecursiveCall();
  11266. if (res != 0) goto failed;
  11267. Py_CLEAR(tmp);
  11268. }
  11269. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  11270. return 1;
  11271. }
  11272. if (tmp == NULL) {
  11273. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
  11274. return 1;
  11275. }
  11276. else {
  11277. int res;
  11278. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11279. goto failed;
  11280. }
  11281. res = obj2ast_expr(state, tmp, &value, arena);
  11282. _Py_LeaveRecursiveCall();
  11283. if (res != 0) goto failed;
  11284. Py_CLEAR(tmp);
  11285. }
  11286. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  11287. return 1;
  11288. }
  11289. if (tmp == NULL) {
  11290. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
  11291. return 1;
  11292. }
  11293. else {
  11294. int res;
  11295. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11296. goto failed;
  11297. }
  11298. res = obj2ast_int(state, tmp, &lineno, arena);
  11299. _Py_LeaveRecursiveCall();
  11300. if (res != 0) goto failed;
  11301. Py_CLEAR(tmp);
  11302. }
  11303. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  11304. return 1;
  11305. }
  11306. if (tmp == NULL) {
  11307. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
  11308. return 1;
  11309. }
  11310. else {
  11311. int res;
  11312. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11313. goto failed;
  11314. }
  11315. res = obj2ast_int(state, tmp, &col_offset, arena);
  11316. _Py_LeaveRecursiveCall();
  11317. if (res != 0) goto failed;
  11318. Py_CLEAR(tmp);
  11319. }
  11320. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  11321. return 1;
  11322. }
  11323. if (tmp == NULL || tmp == Py_None) {
  11324. Py_CLEAR(tmp);
  11325. end_lineno = lineno;
  11326. }
  11327. else {
  11328. int res;
  11329. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11330. goto failed;
  11331. }
  11332. res = obj2ast_int(state, tmp, &end_lineno, arena);
  11333. _Py_LeaveRecursiveCall();
  11334. if (res != 0) goto failed;
  11335. Py_CLEAR(tmp);
  11336. }
  11337. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  11338. return 1;
  11339. }
  11340. if (tmp == NULL || tmp == Py_None) {
  11341. Py_CLEAR(tmp);
  11342. end_col_offset = col_offset;
  11343. }
  11344. else {
  11345. int res;
  11346. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11347. goto failed;
  11348. }
  11349. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  11350. _Py_LeaveRecursiveCall();
  11351. if (res != 0) goto failed;
  11352. Py_CLEAR(tmp);
  11353. }
  11354. *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
  11355. end_col_offset, arena);
  11356. if (*out == NULL) goto failed;
  11357. return 0;
  11358. failed:
  11359. Py_XDECREF(tmp);
  11360. return 1;
  11361. }
  11362. int
  11363. obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
  11364. arena)
  11365. {
  11366. PyObject* tmp = NULL;
  11367. identifier name;
  11368. identifier asname;
  11369. int lineno;
  11370. int col_offset;
  11371. int end_lineno;
  11372. int end_col_offset;
  11373. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  11374. return 1;
  11375. }
  11376. if (tmp == NULL) {
  11377. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
  11378. return 1;
  11379. }
  11380. else {
  11381. int res;
  11382. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11383. goto failed;
  11384. }
  11385. res = obj2ast_identifier(state, tmp, &name, arena);
  11386. _Py_LeaveRecursiveCall();
  11387. if (res != 0) goto failed;
  11388. Py_CLEAR(tmp);
  11389. }
  11390. if (_PyObject_LookupAttr(obj, state->asname, &tmp) < 0) {
  11391. return 1;
  11392. }
  11393. if (tmp == NULL || tmp == Py_None) {
  11394. Py_CLEAR(tmp);
  11395. asname = NULL;
  11396. }
  11397. else {
  11398. int res;
  11399. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11400. goto failed;
  11401. }
  11402. res = obj2ast_identifier(state, tmp, &asname, arena);
  11403. _Py_LeaveRecursiveCall();
  11404. if (res != 0) goto failed;
  11405. Py_CLEAR(tmp);
  11406. }
  11407. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  11408. return 1;
  11409. }
  11410. if (tmp == NULL) {
  11411. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
  11412. return 1;
  11413. }
  11414. else {
  11415. int res;
  11416. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11417. goto failed;
  11418. }
  11419. res = obj2ast_int(state, tmp, &lineno, arena);
  11420. _Py_LeaveRecursiveCall();
  11421. if (res != 0) goto failed;
  11422. Py_CLEAR(tmp);
  11423. }
  11424. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  11425. return 1;
  11426. }
  11427. if (tmp == NULL) {
  11428. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
  11429. return 1;
  11430. }
  11431. else {
  11432. int res;
  11433. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11434. goto failed;
  11435. }
  11436. res = obj2ast_int(state, tmp, &col_offset, arena);
  11437. _Py_LeaveRecursiveCall();
  11438. if (res != 0) goto failed;
  11439. Py_CLEAR(tmp);
  11440. }
  11441. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  11442. return 1;
  11443. }
  11444. if (tmp == NULL || tmp == Py_None) {
  11445. Py_CLEAR(tmp);
  11446. end_lineno = lineno;
  11447. }
  11448. else {
  11449. int res;
  11450. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11451. goto failed;
  11452. }
  11453. res = obj2ast_int(state, tmp, &end_lineno, arena);
  11454. _Py_LeaveRecursiveCall();
  11455. if (res != 0) goto failed;
  11456. Py_CLEAR(tmp);
  11457. }
  11458. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  11459. return 1;
  11460. }
  11461. if (tmp == NULL || tmp == Py_None) {
  11462. Py_CLEAR(tmp);
  11463. end_col_offset = col_offset;
  11464. }
  11465. else {
  11466. int res;
  11467. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11468. goto failed;
  11469. }
  11470. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  11471. _Py_LeaveRecursiveCall();
  11472. if (res != 0) goto failed;
  11473. Py_CLEAR(tmp);
  11474. }
  11475. *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
  11476. end_col_offset, arena);
  11477. if (*out == NULL) goto failed;
  11478. return 0;
  11479. failed:
  11480. Py_XDECREF(tmp);
  11481. return 1;
  11482. }
  11483. int
  11484. obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
  11485. PyArena* arena)
  11486. {
  11487. PyObject* tmp = NULL;
  11488. expr_ty context_expr;
  11489. expr_ty optional_vars;
  11490. if (_PyObject_LookupAttr(obj, state->context_expr, &tmp) < 0) {
  11491. return 1;
  11492. }
  11493. if (tmp == NULL) {
  11494. PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
  11495. return 1;
  11496. }
  11497. else {
  11498. int res;
  11499. if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
  11500. goto failed;
  11501. }
  11502. res = obj2ast_expr(state, tmp, &context_expr, arena);
  11503. _Py_LeaveRecursiveCall();
  11504. if (res != 0) goto failed;
  11505. Py_CLEAR(tmp);
  11506. }
  11507. if (_PyObject_LookupAttr(obj, state->optional_vars, &tmp) < 0) {
  11508. return 1;
  11509. }
  11510. if (tmp == NULL || tmp == Py_None) {
  11511. Py_CLEAR(tmp);
  11512. optional_vars = NULL;
  11513. }
  11514. else {
  11515. int res;
  11516. if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
  11517. goto failed;
  11518. }
  11519. res = obj2ast_expr(state, tmp, &optional_vars, arena);
  11520. _Py_LeaveRecursiveCall();
  11521. if (res != 0) goto failed;
  11522. Py_CLEAR(tmp);
  11523. }
  11524. *out = _PyAST_withitem(context_expr, optional_vars, arena);
  11525. if (*out == NULL) goto failed;
  11526. return 0;
  11527. failed:
  11528. Py_XDECREF(tmp);
  11529. return 1;
  11530. }
  11531. int
  11532. obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
  11533. PyArena* arena)
  11534. {
  11535. PyObject* tmp = NULL;
  11536. pattern_ty pattern;
  11537. expr_ty guard;
  11538. asdl_stmt_seq* body;
  11539. if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
  11540. return 1;
  11541. }
  11542. if (tmp == NULL) {
  11543. PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
  11544. return 1;
  11545. }
  11546. else {
  11547. int res;
  11548. if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
  11549. goto failed;
  11550. }
  11551. res = obj2ast_pattern(state, tmp, &pattern, arena);
  11552. _Py_LeaveRecursiveCall();
  11553. if (res != 0) goto failed;
  11554. Py_CLEAR(tmp);
  11555. }
  11556. if (_PyObject_LookupAttr(obj, state->guard, &tmp) < 0) {
  11557. return 1;
  11558. }
  11559. if (tmp == NULL || tmp == Py_None) {
  11560. Py_CLEAR(tmp);
  11561. guard = NULL;
  11562. }
  11563. else {
  11564. int res;
  11565. if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
  11566. goto failed;
  11567. }
  11568. res = obj2ast_expr(state, tmp, &guard, arena);
  11569. _Py_LeaveRecursiveCall();
  11570. if (res != 0) goto failed;
  11571. Py_CLEAR(tmp);
  11572. }
  11573. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  11574. return 1;
  11575. }
  11576. if (tmp == NULL) {
  11577. tmp = PyList_New(0);
  11578. if (tmp == NULL) {
  11579. return 1;
  11580. }
  11581. }
  11582. {
  11583. int res;
  11584. Py_ssize_t len;
  11585. Py_ssize_t i;
  11586. if (!PyList_Check(tmp)) {
  11587. PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11588. goto failed;
  11589. }
  11590. len = PyList_GET_SIZE(tmp);
  11591. body = _Py_asdl_stmt_seq_new(len, arena);
  11592. if (body == NULL) goto failed;
  11593. for (i = 0; i < len; i++) {
  11594. stmt_ty val;
  11595. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11596. if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
  11597. goto failed;
  11598. }
  11599. res = obj2ast_stmt(state, tmp2, &val, arena);
  11600. _Py_LeaveRecursiveCall();
  11601. Py_DECREF(tmp2);
  11602. if (res != 0) goto failed;
  11603. if (len != PyList_GET_SIZE(tmp)) {
  11604. PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
  11605. goto failed;
  11606. }
  11607. asdl_seq_SET(body, i, val);
  11608. }
  11609. Py_CLEAR(tmp);
  11610. }
  11611. *out = _PyAST_match_case(pattern, guard, body, arena);
  11612. if (*out == NULL) goto failed;
  11613. return 0;
  11614. failed:
  11615. Py_XDECREF(tmp);
  11616. return 1;
  11617. }
  11618. int
  11619. obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
  11620. PyArena* arena)
  11621. {
  11622. int isinstance;
  11623. PyObject *tmp = NULL;
  11624. PyObject *tp;
  11625. int lineno;
  11626. int col_offset;
  11627. int end_lineno;
  11628. int end_col_offset;
  11629. if (obj == Py_None) {
  11630. *out = NULL;
  11631. return 0;
  11632. }
  11633. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  11634. return 1;
  11635. }
  11636. if (tmp == NULL) {
  11637. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
  11638. return 1;
  11639. }
  11640. else {
  11641. int res;
  11642. if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
  11643. goto failed;
  11644. }
  11645. res = obj2ast_int(state, tmp, &lineno, arena);
  11646. _Py_LeaveRecursiveCall();
  11647. if (res != 0) goto failed;
  11648. Py_CLEAR(tmp);
  11649. }
  11650. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  11651. return 1;
  11652. }
  11653. if (tmp == NULL) {
  11654. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
  11655. return 1;
  11656. }
  11657. else {
  11658. int res;
  11659. if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
  11660. goto failed;
  11661. }
  11662. res = obj2ast_int(state, tmp, &col_offset, arena);
  11663. _Py_LeaveRecursiveCall();
  11664. if (res != 0) goto failed;
  11665. Py_CLEAR(tmp);
  11666. }
  11667. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  11668. return 1;
  11669. }
  11670. if (tmp == NULL) {
  11671. PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
  11672. return 1;
  11673. }
  11674. else {
  11675. int res;
  11676. if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
  11677. goto failed;
  11678. }
  11679. res = obj2ast_int(state, tmp, &end_lineno, arena);
  11680. _Py_LeaveRecursiveCall();
  11681. if (res != 0) goto failed;
  11682. Py_CLEAR(tmp);
  11683. }
  11684. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  11685. return 1;
  11686. }
  11687. if (tmp == NULL) {
  11688. PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
  11689. return 1;
  11690. }
  11691. else {
  11692. int res;
  11693. if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
  11694. goto failed;
  11695. }
  11696. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  11697. _Py_LeaveRecursiveCall();
  11698. if (res != 0) goto failed;
  11699. Py_CLEAR(tmp);
  11700. }
  11701. tp = state->MatchValue_type;
  11702. isinstance = PyObject_IsInstance(obj, tp);
  11703. if (isinstance == -1) {
  11704. return 1;
  11705. }
  11706. if (isinstance) {
  11707. expr_ty value;
  11708. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  11709. return 1;
  11710. }
  11711. if (tmp == NULL) {
  11712. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
  11713. return 1;
  11714. }
  11715. else {
  11716. int res;
  11717. if (_Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
  11718. goto failed;
  11719. }
  11720. res = obj2ast_expr(state, tmp, &value, arena);
  11721. _Py_LeaveRecursiveCall();
  11722. if (res != 0) goto failed;
  11723. Py_CLEAR(tmp);
  11724. }
  11725. *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
  11726. end_col_offset, arena);
  11727. if (*out == NULL) goto failed;
  11728. return 0;
  11729. }
  11730. tp = state->MatchSingleton_type;
  11731. isinstance = PyObject_IsInstance(obj, tp);
  11732. if (isinstance == -1) {
  11733. return 1;
  11734. }
  11735. if (isinstance) {
  11736. constant value;
  11737. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  11738. return 1;
  11739. }
  11740. if (tmp == NULL) {
  11741. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
  11742. return 1;
  11743. }
  11744. else {
  11745. int res;
  11746. if (_Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
  11747. goto failed;
  11748. }
  11749. res = obj2ast_constant(state, tmp, &value, arena);
  11750. _Py_LeaveRecursiveCall();
  11751. if (res != 0) goto failed;
  11752. Py_CLEAR(tmp);
  11753. }
  11754. *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
  11755. end_col_offset, arena);
  11756. if (*out == NULL) goto failed;
  11757. return 0;
  11758. }
  11759. tp = state->MatchSequence_type;
  11760. isinstance = PyObject_IsInstance(obj, tp);
  11761. if (isinstance == -1) {
  11762. return 1;
  11763. }
  11764. if (isinstance) {
  11765. asdl_pattern_seq* patterns;
  11766. if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
  11767. return 1;
  11768. }
  11769. if (tmp == NULL) {
  11770. tmp = PyList_New(0);
  11771. if (tmp == NULL) {
  11772. return 1;
  11773. }
  11774. }
  11775. {
  11776. int res;
  11777. Py_ssize_t len;
  11778. Py_ssize_t i;
  11779. if (!PyList_Check(tmp)) {
  11780. PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11781. goto failed;
  11782. }
  11783. len = PyList_GET_SIZE(tmp);
  11784. patterns = _Py_asdl_pattern_seq_new(len, arena);
  11785. if (patterns == NULL) goto failed;
  11786. for (i = 0; i < len; i++) {
  11787. pattern_ty val;
  11788. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11789. if (_Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
  11790. goto failed;
  11791. }
  11792. res = obj2ast_pattern(state, tmp2, &val, arena);
  11793. _Py_LeaveRecursiveCall();
  11794. Py_DECREF(tmp2);
  11795. if (res != 0) goto failed;
  11796. if (len != PyList_GET_SIZE(tmp)) {
  11797. PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
  11798. goto failed;
  11799. }
  11800. asdl_seq_SET(patterns, i, val);
  11801. }
  11802. Py_CLEAR(tmp);
  11803. }
  11804. *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
  11805. end_col_offset, arena);
  11806. if (*out == NULL) goto failed;
  11807. return 0;
  11808. }
  11809. tp = state->MatchMapping_type;
  11810. isinstance = PyObject_IsInstance(obj, tp);
  11811. if (isinstance == -1) {
  11812. return 1;
  11813. }
  11814. if (isinstance) {
  11815. asdl_expr_seq* keys;
  11816. asdl_pattern_seq* patterns;
  11817. identifier rest;
  11818. if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
  11819. return 1;
  11820. }
  11821. if (tmp == NULL) {
  11822. tmp = PyList_New(0);
  11823. if (tmp == NULL) {
  11824. return 1;
  11825. }
  11826. }
  11827. {
  11828. int res;
  11829. Py_ssize_t len;
  11830. Py_ssize_t i;
  11831. if (!PyList_Check(tmp)) {
  11832. PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11833. goto failed;
  11834. }
  11835. len = PyList_GET_SIZE(tmp);
  11836. keys = _Py_asdl_expr_seq_new(len, arena);
  11837. if (keys == NULL) goto failed;
  11838. for (i = 0; i < len; i++) {
  11839. expr_ty val;
  11840. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11841. if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
  11842. goto failed;
  11843. }
  11844. res = obj2ast_expr(state, tmp2, &val, arena);
  11845. _Py_LeaveRecursiveCall();
  11846. Py_DECREF(tmp2);
  11847. if (res != 0) goto failed;
  11848. if (len != PyList_GET_SIZE(tmp)) {
  11849. PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
  11850. goto failed;
  11851. }
  11852. asdl_seq_SET(keys, i, val);
  11853. }
  11854. Py_CLEAR(tmp);
  11855. }
  11856. if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
  11857. return 1;
  11858. }
  11859. if (tmp == NULL) {
  11860. tmp = PyList_New(0);
  11861. if (tmp == NULL) {
  11862. return 1;
  11863. }
  11864. }
  11865. {
  11866. int res;
  11867. Py_ssize_t len;
  11868. Py_ssize_t i;
  11869. if (!PyList_Check(tmp)) {
  11870. PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11871. goto failed;
  11872. }
  11873. len = PyList_GET_SIZE(tmp);
  11874. patterns = _Py_asdl_pattern_seq_new(len, arena);
  11875. if (patterns == NULL) goto failed;
  11876. for (i = 0; i < len; i++) {
  11877. pattern_ty val;
  11878. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11879. if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
  11880. goto failed;
  11881. }
  11882. res = obj2ast_pattern(state, tmp2, &val, arena);
  11883. _Py_LeaveRecursiveCall();
  11884. Py_DECREF(tmp2);
  11885. if (res != 0) goto failed;
  11886. if (len != PyList_GET_SIZE(tmp)) {
  11887. PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
  11888. goto failed;
  11889. }
  11890. asdl_seq_SET(patterns, i, val);
  11891. }
  11892. Py_CLEAR(tmp);
  11893. }
  11894. if (_PyObject_LookupAttr(obj, state->rest, &tmp) < 0) {
  11895. return 1;
  11896. }
  11897. if (tmp == NULL || tmp == Py_None) {
  11898. Py_CLEAR(tmp);
  11899. rest = NULL;
  11900. }
  11901. else {
  11902. int res;
  11903. if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
  11904. goto failed;
  11905. }
  11906. res = obj2ast_identifier(state, tmp, &rest, arena);
  11907. _Py_LeaveRecursiveCall();
  11908. if (res != 0) goto failed;
  11909. Py_CLEAR(tmp);
  11910. }
  11911. *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
  11912. end_lineno, end_col_offset, arena);
  11913. if (*out == NULL) goto failed;
  11914. return 0;
  11915. }
  11916. tp = state->MatchClass_type;
  11917. isinstance = PyObject_IsInstance(obj, tp);
  11918. if (isinstance == -1) {
  11919. return 1;
  11920. }
  11921. if (isinstance) {
  11922. expr_ty cls;
  11923. asdl_pattern_seq* patterns;
  11924. asdl_identifier_seq* kwd_attrs;
  11925. asdl_pattern_seq* kwd_patterns;
  11926. if (_PyObject_LookupAttr(obj, state->cls, &tmp) < 0) {
  11927. return 1;
  11928. }
  11929. if (tmp == NULL) {
  11930. PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
  11931. return 1;
  11932. }
  11933. else {
  11934. int res;
  11935. if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
  11936. goto failed;
  11937. }
  11938. res = obj2ast_expr(state, tmp, &cls, arena);
  11939. _Py_LeaveRecursiveCall();
  11940. if (res != 0) goto failed;
  11941. Py_CLEAR(tmp);
  11942. }
  11943. if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
  11944. return 1;
  11945. }
  11946. if (tmp == NULL) {
  11947. tmp = PyList_New(0);
  11948. if (tmp == NULL) {
  11949. return 1;
  11950. }
  11951. }
  11952. {
  11953. int res;
  11954. Py_ssize_t len;
  11955. Py_ssize_t i;
  11956. if (!PyList_Check(tmp)) {
  11957. PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11958. goto failed;
  11959. }
  11960. len = PyList_GET_SIZE(tmp);
  11961. patterns = _Py_asdl_pattern_seq_new(len, arena);
  11962. if (patterns == NULL) goto failed;
  11963. for (i = 0; i < len; i++) {
  11964. pattern_ty val;
  11965. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11966. if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
  11967. goto failed;
  11968. }
  11969. res = obj2ast_pattern(state, tmp2, &val, arena);
  11970. _Py_LeaveRecursiveCall();
  11971. Py_DECREF(tmp2);
  11972. if (res != 0) goto failed;
  11973. if (len != PyList_GET_SIZE(tmp)) {
  11974. PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
  11975. goto failed;
  11976. }
  11977. asdl_seq_SET(patterns, i, val);
  11978. }
  11979. Py_CLEAR(tmp);
  11980. }
  11981. if (_PyObject_LookupAttr(obj, state->kwd_attrs, &tmp) < 0) {
  11982. return 1;
  11983. }
  11984. if (tmp == NULL) {
  11985. tmp = PyList_New(0);
  11986. if (tmp == NULL) {
  11987. return 1;
  11988. }
  11989. }
  11990. {
  11991. int res;
  11992. Py_ssize_t len;
  11993. Py_ssize_t i;
  11994. if (!PyList_Check(tmp)) {
  11995. PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11996. goto failed;
  11997. }
  11998. len = PyList_GET_SIZE(tmp);
  11999. kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
  12000. if (kwd_attrs == NULL) goto failed;
  12001. for (i = 0; i < len; i++) {
  12002. identifier val;
  12003. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  12004. if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
  12005. goto failed;
  12006. }
  12007. res = obj2ast_identifier(state, tmp2, &val, arena);
  12008. _Py_LeaveRecursiveCall();
  12009. Py_DECREF(tmp2);
  12010. if (res != 0) goto failed;
  12011. if (len != PyList_GET_SIZE(tmp)) {
  12012. PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
  12013. goto failed;
  12014. }
  12015. asdl_seq_SET(kwd_attrs, i, val);
  12016. }
  12017. Py_CLEAR(tmp);
  12018. }
  12019. if (_PyObject_LookupAttr(obj, state->kwd_patterns, &tmp) < 0) {
  12020. return 1;
  12021. }
  12022. if (tmp == NULL) {
  12023. tmp = PyList_New(0);
  12024. if (tmp == NULL) {
  12025. return 1;
  12026. }
  12027. }
  12028. {
  12029. int res;
  12030. Py_ssize_t len;
  12031. Py_ssize_t i;
  12032. if (!PyList_Check(tmp)) {
  12033. PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  12034. goto failed;
  12035. }
  12036. len = PyList_GET_SIZE(tmp);
  12037. kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
  12038. if (kwd_patterns == NULL) goto failed;
  12039. for (i = 0; i < len; i++) {
  12040. pattern_ty val;
  12041. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  12042. if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
  12043. goto failed;
  12044. }
  12045. res = obj2ast_pattern(state, tmp2, &val, arena);
  12046. _Py_LeaveRecursiveCall();
  12047. Py_DECREF(tmp2);
  12048. if (res != 0) goto failed;
  12049. if (len != PyList_GET_SIZE(tmp)) {
  12050. PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
  12051. goto failed;
  12052. }
  12053. asdl_seq_SET(kwd_patterns, i, val);
  12054. }
  12055. Py_CLEAR(tmp);
  12056. }
  12057. *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
  12058. lineno, col_offset, end_lineno,
  12059. end_col_offset, arena);
  12060. if (*out == NULL) goto failed;
  12061. return 0;
  12062. }
  12063. tp = state->MatchStar_type;
  12064. isinstance = PyObject_IsInstance(obj, tp);
  12065. if (isinstance == -1) {
  12066. return 1;
  12067. }
  12068. if (isinstance) {
  12069. identifier name;
  12070. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12071. return 1;
  12072. }
  12073. if (tmp == NULL || tmp == Py_None) {
  12074. Py_CLEAR(tmp);
  12075. name = NULL;
  12076. }
  12077. else {
  12078. int res;
  12079. if (_Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
  12080. goto failed;
  12081. }
  12082. res = obj2ast_identifier(state, tmp, &name, arena);
  12083. _Py_LeaveRecursiveCall();
  12084. if (res != 0) goto failed;
  12085. Py_CLEAR(tmp);
  12086. }
  12087. *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
  12088. end_col_offset, arena);
  12089. if (*out == NULL) goto failed;
  12090. return 0;
  12091. }
  12092. tp = state->MatchAs_type;
  12093. isinstance = PyObject_IsInstance(obj, tp);
  12094. if (isinstance == -1) {
  12095. return 1;
  12096. }
  12097. if (isinstance) {
  12098. pattern_ty pattern;
  12099. identifier name;
  12100. if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
  12101. return 1;
  12102. }
  12103. if (tmp == NULL || tmp == Py_None) {
  12104. Py_CLEAR(tmp);
  12105. pattern = NULL;
  12106. }
  12107. else {
  12108. int res;
  12109. if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
  12110. goto failed;
  12111. }
  12112. res = obj2ast_pattern(state, tmp, &pattern, arena);
  12113. _Py_LeaveRecursiveCall();
  12114. if (res != 0) goto failed;
  12115. Py_CLEAR(tmp);
  12116. }
  12117. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12118. return 1;
  12119. }
  12120. if (tmp == NULL || tmp == Py_None) {
  12121. Py_CLEAR(tmp);
  12122. name = NULL;
  12123. }
  12124. else {
  12125. int res;
  12126. if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
  12127. goto failed;
  12128. }
  12129. res = obj2ast_identifier(state, tmp, &name, arena);
  12130. _Py_LeaveRecursiveCall();
  12131. if (res != 0) goto failed;
  12132. Py_CLEAR(tmp);
  12133. }
  12134. *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
  12135. end_col_offset, arena);
  12136. if (*out == NULL) goto failed;
  12137. return 0;
  12138. }
  12139. tp = state->MatchOr_type;
  12140. isinstance = PyObject_IsInstance(obj, tp);
  12141. if (isinstance == -1) {
  12142. return 1;
  12143. }
  12144. if (isinstance) {
  12145. asdl_pattern_seq* patterns;
  12146. if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
  12147. return 1;
  12148. }
  12149. if (tmp == NULL) {
  12150. tmp = PyList_New(0);
  12151. if (tmp == NULL) {
  12152. return 1;
  12153. }
  12154. }
  12155. {
  12156. int res;
  12157. Py_ssize_t len;
  12158. Py_ssize_t i;
  12159. if (!PyList_Check(tmp)) {
  12160. PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  12161. goto failed;
  12162. }
  12163. len = PyList_GET_SIZE(tmp);
  12164. patterns = _Py_asdl_pattern_seq_new(len, arena);
  12165. if (patterns == NULL) goto failed;
  12166. for (i = 0; i < len; i++) {
  12167. pattern_ty val;
  12168. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  12169. if (_Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
  12170. goto failed;
  12171. }
  12172. res = obj2ast_pattern(state, tmp2, &val, arena);
  12173. _Py_LeaveRecursiveCall();
  12174. Py_DECREF(tmp2);
  12175. if (res != 0) goto failed;
  12176. if (len != PyList_GET_SIZE(tmp)) {
  12177. PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
  12178. goto failed;
  12179. }
  12180. asdl_seq_SET(patterns, i, val);
  12181. }
  12182. Py_CLEAR(tmp);
  12183. }
  12184. *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
  12185. end_col_offset, arena);
  12186. if (*out == NULL) goto failed;
  12187. return 0;
  12188. }
  12189. PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
  12190. failed:
  12191. Py_XDECREF(tmp);
  12192. return 1;
  12193. }
  12194. int
  12195. obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
  12196. out, PyArena* arena)
  12197. {
  12198. int isinstance;
  12199. PyObject *tmp = NULL;
  12200. PyObject *tp;
  12201. if (obj == Py_None) {
  12202. *out = NULL;
  12203. return 0;
  12204. }
  12205. tp = state->TypeIgnore_type;
  12206. isinstance = PyObject_IsInstance(obj, tp);
  12207. if (isinstance == -1) {
  12208. return 1;
  12209. }
  12210. if (isinstance) {
  12211. int lineno;
  12212. string tag;
  12213. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  12214. return 1;
  12215. }
  12216. if (tmp == NULL) {
  12217. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
  12218. return 1;
  12219. }
  12220. else {
  12221. int res;
  12222. if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
  12223. goto failed;
  12224. }
  12225. res = obj2ast_int(state, tmp, &lineno, arena);
  12226. _Py_LeaveRecursiveCall();
  12227. if (res != 0) goto failed;
  12228. Py_CLEAR(tmp);
  12229. }
  12230. if (_PyObject_LookupAttr(obj, state->tag, &tmp) < 0) {
  12231. return 1;
  12232. }
  12233. if (tmp == NULL) {
  12234. PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
  12235. return 1;
  12236. }
  12237. else {
  12238. int res;
  12239. if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
  12240. goto failed;
  12241. }
  12242. res = obj2ast_string(state, tmp, &tag, arena);
  12243. _Py_LeaveRecursiveCall();
  12244. if (res != 0) goto failed;
  12245. Py_CLEAR(tmp);
  12246. }
  12247. *out = _PyAST_TypeIgnore(lineno, tag, arena);
  12248. if (*out == NULL) goto failed;
  12249. return 0;
  12250. }
  12251. PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
  12252. failed:
  12253. Py_XDECREF(tmp);
  12254. return 1;
  12255. }
  12256. int
  12257. obj2ast_type_param(struct ast_state *state, PyObject* obj, type_param_ty* out,
  12258. PyArena* arena)
  12259. {
  12260. int isinstance;
  12261. PyObject *tmp = NULL;
  12262. PyObject *tp;
  12263. int lineno;
  12264. int col_offset;
  12265. int end_lineno;
  12266. int end_col_offset;
  12267. if (obj == Py_None) {
  12268. *out = NULL;
  12269. return 0;
  12270. }
  12271. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  12272. return 1;
  12273. }
  12274. if (tmp == NULL) {
  12275. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from type_param");
  12276. return 1;
  12277. }
  12278. else {
  12279. int res;
  12280. if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
  12281. goto failed;
  12282. }
  12283. res = obj2ast_int(state, tmp, &lineno, arena);
  12284. _Py_LeaveRecursiveCall();
  12285. if (res != 0) goto failed;
  12286. Py_CLEAR(tmp);
  12287. }
  12288. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  12289. return 1;
  12290. }
  12291. if (tmp == NULL) {
  12292. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from type_param");
  12293. return 1;
  12294. }
  12295. else {
  12296. int res;
  12297. if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
  12298. goto failed;
  12299. }
  12300. res = obj2ast_int(state, tmp, &col_offset, arena);
  12301. _Py_LeaveRecursiveCall();
  12302. if (res != 0) goto failed;
  12303. Py_CLEAR(tmp);
  12304. }
  12305. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  12306. return 1;
  12307. }
  12308. if (tmp == NULL) {
  12309. PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from type_param");
  12310. return 1;
  12311. }
  12312. else {
  12313. int res;
  12314. if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
  12315. goto failed;
  12316. }
  12317. res = obj2ast_int(state, tmp, &end_lineno, arena);
  12318. _Py_LeaveRecursiveCall();
  12319. if (res != 0) goto failed;
  12320. Py_CLEAR(tmp);
  12321. }
  12322. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  12323. return 1;
  12324. }
  12325. if (tmp == NULL) {
  12326. PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from type_param");
  12327. return 1;
  12328. }
  12329. else {
  12330. int res;
  12331. if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
  12332. goto failed;
  12333. }
  12334. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  12335. _Py_LeaveRecursiveCall();
  12336. if (res != 0) goto failed;
  12337. Py_CLEAR(tmp);
  12338. }
  12339. tp = state->TypeVar_type;
  12340. isinstance = PyObject_IsInstance(obj, tp);
  12341. if (isinstance == -1) {
  12342. return 1;
  12343. }
  12344. if (isinstance) {
  12345. identifier name;
  12346. expr_ty bound;
  12347. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12348. return 1;
  12349. }
  12350. if (tmp == NULL) {
  12351. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVar");
  12352. return 1;
  12353. }
  12354. else {
  12355. int res;
  12356. if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
  12357. goto failed;
  12358. }
  12359. res = obj2ast_identifier(state, tmp, &name, arena);
  12360. _Py_LeaveRecursiveCall();
  12361. if (res != 0) goto failed;
  12362. Py_CLEAR(tmp);
  12363. }
  12364. if (_PyObject_LookupAttr(obj, state->bound, &tmp) < 0) {
  12365. return 1;
  12366. }
  12367. if (tmp == NULL || tmp == Py_None) {
  12368. Py_CLEAR(tmp);
  12369. bound = NULL;
  12370. }
  12371. else {
  12372. int res;
  12373. if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
  12374. goto failed;
  12375. }
  12376. res = obj2ast_expr(state, tmp, &bound, arena);
  12377. _Py_LeaveRecursiveCall();
  12378. if (res != 0) goto failed;
  12379. Py_CLEAR(tmp);
  12380. }
  12381. *out = _PyAST_TypeVar(name, bound, lineno, col_offset, end_lineno,
  12382. end_col_offset, arena);
  12383. if (*out == NULL) goto failed;
  12384. return 0;
  12385. }
  12386. tp = state->ParamSpec_type;
  12387. isinstance = PyObject_IsInstance(obj, tp);
  12388. if (isinstance == -1) {
  12389. return 1;
  12390. }
  12391. if (isinstance) {
  12392. identifier name;
  12393. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12394. return 1;
  12395. }
  12396. if (tmp == NULL) {
  12397. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ParamSpec");
  12398. return 1;
  12399. }
  12400. else {
  12401. int res;
  12402. if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
  12403. goto failed;
  12404. }
  12405. res = obj2ast_identifier(state, tmp, &name, arena);
  12406. _Py_LeaveRecursiveCall();
  12407. if (res != 0) goto failed;
  12408. Py_CLEAR(tmp);
  12409. }
  12410. *out = _PyAST_ParamSpec(name, lineno, col_offset, end_lineno,
  12411. end_col_offset, arena);
  12412. if (*out == NULL) goto failed;
  12413. return 0;
  12414. }
  12415. tp = state->TypeVarTuple_type;
  12416. isinstance = PyObject_IsInstance(obj, tp);
  12417. if (isinstance == -1) {
  12418. return 1;
  12419. }
  12420. if (isinstance) {
  12421. identifier name;
  12422. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12423. return 1;
  12424. }
  12425. if (tmp == NULL) {
  12426. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVarTuple");
  12427. return 1;
  12428. }
  12429. else {
  12430. int res;
  12431. if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
  12432. goto failed;
  12433. }
  12434. res = obj2ast_identifier(state, tmp, &name, arena);
  12435. _Py_LeaveRecursiveCall();
  12436. if (res != 0) goto failed;
  12437. Py_CLEAR(tmp);
  12438. }
  12439. *out = _PyAST_TypeVarTuple(name, lineno, col_offset, end_lineno,
  12440. end_col_offset, arena);
  12441. if (*out == NULL) goto failed;
  12442. return 0;
  12443. }
  12444. PyErr_Format(PyExc_TypeError, "expected some sort of type_param, but got %R", obj);
  12445. failed:
  12446. Py_XDECREF(tmp);
  12447. return 1;
  12448. }
  12449. static int
  12450. astmodule_exec(PyObject *m)
  12451. {
  12452. struct ast_state *state = get_ast_state();
  12453. if (state == NULL) {
  12454. return -1;
  12455. }
  12456. if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
  12457. return -1;
  12458. }
  12459. if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
  12460. return -1;
  12461. }
  12462. if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
  12463. return -1;
  12464. }
  12465. if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
  12466. return -1;
  12467. }
  12468. if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
  12469. return -1;
  12470. }
  12471. if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
  12472. return -1;
  12473. }
  12474. if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
  12475. return -1;
  12476. }
  12477. if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
  12478. return -1;
  12479. }
  12480. if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
  12481. {
  12482. return -1;
  12483. }
  12484. if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
  12485. return -1;
  12486. }
  12487. if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
  12488. return -1;
  12489. }
  12490. if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
  12491. state->AsyncFunctionDef_type) < 0) {
  12492. return -1;
  12493. }
  12494. if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
  12495. return -1;
  12496. }
  12497. if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
  12498. return -1;
  12499. }
  12500. if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
  12501. return -1;
  12502. }
  12503. if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
  12504. return -1;
  12505. }
  12506. if (PyModule_AddObjectRef(m, "TypeAlias", state->TypeAlias_type) < 0) {
  12507. return -1;
  12508. }
  12509. if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
  12510. return -1;
  12511. }
  12512. if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
  12513. return -1;
  12514. }
  12515. if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
  12516. return -1;
  12517. }
  12518. if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
  12519. return -1;
  12520. }
  12521. if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
  12522. return -1;
  12523. }
  12524. if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
  12525. return -1;
  12526. }
  12527. if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
  12528. return -1;
  12529. }
  12530. if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
  12531. return -1;
  12532. }
  12533. if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
  12534. return -1;
  12535. }
  12536. if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
  12537. return -1;
  12538. }
  12539. if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
  12540. return -1;
  12541. }
  12542. if (PyModule_AddObjectRef(m, "TryStar", state->TryStar_type) < 0) {
  12543. return -1;
  12544. }
  12545. if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
  12546. return -1;
  12547. }
  12548. if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
  12549. return -1;
  12550. }
  12551. if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
  12552. return -1;
  12553. }
  12554. if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
  12555. return -1;
  12556. }
  12557. if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
  12558. return -1;
  12559. }
  12560. if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
  12561. return -1;
  12562. }
  12563. if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
  12564. return -1;
  12565. }
  12566. if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
  12567. return -1;
  12568. }
  12569. if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
  12570. return -1;
  12571. }
  12572. if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
  12573. return -1;
  12574. }
  12575. if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
  12576. return -1;
  12577. }
  12578. if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
  12579. return -1;
  12580. }
  12581. if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
  12582. return -1;
  12583. }
  12584. if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
  12585. return -1;
  12586. }
  12587. if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
  12588. return -1;
  12589. }
  12590. if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
  12591. return -1;
  12592. }
  12593. if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
  12594. return -1;
  12595. }
  12596. if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
  12597. return -1;
  12598. }
  12599. if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
  12600. return -1;
  12601. }
  12602. if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
  12603. return -1;
  12604. }
  12605. if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
  12606. return -1;
  12607. }
  12608. if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
  12609. {
  12610. return -1;
  12611. }
  12612. if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
  12613. return -1;
  12614. }
  12615. if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
  12616. return -1;
  12617. }
  12618. if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
  12619. return -1;
  12620. }
  12621. if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
  12622. return -1;
  12623. }
  12624. if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
  12625. return -1;
  12626. }
  12627. if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
  12628. < 0) {
  12629. return -1;
  12630. }
  12631. if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
  12632. return -1;
  12633. }
  12634. if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
  12635. return -1;
  12636. }
  12637. if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
  12638. return -1;
  12639. }
  12640. if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
  12641. return -1;
  12642. }
  12643. if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
  12644. return -1;
  12645. }
  12646. if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
  12647. return -1;
  12648. }
  12649. if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
  12650. return -1;
  12651. }
  12652. if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
  12653. return -1;
  12654. }
  12655. if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
  12656. return -1;
  12657. }
  12658. if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
  12659. {
  12660. return -1;
  12661. }
  12662. if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
  12663. return -1;
  12664. }
  12665. if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
  12666. return -1;
  12667. }
  12668. if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
  12669. return -1;
  12670. }
  12671. if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
  12672. return -1;
  12673. }
  12674. if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
  12675. return -1;
  12676. }
  12677. if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
  12678. return -1;
  12679. }
  12680. if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
  12681. return -1;
  12682. }
  12683. if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
  12684. return -1;
  12685. }
  12686. if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
  12687. return -1;
  12688. }
  12689. if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
  12690. return -1;
  12691. }
  12692. if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
  12693. return -1;
  12694. }
  12695. if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
  12696. return -1;
  12697. }
  12698. if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
  12699. return -1;
  12700. }
  12701. if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
  12702. return -1;
  12703. }
  12704. if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
  12705. return -1;
  12706. }
  12707. if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
  12708. return -1;
  12709. }
  12710. if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
  12711. return -1;
  12712. }
  12713. if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
  12714. return -1;
  12715. }
  12716. if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
  12717. return -1;
  12718. }
  12719. if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
  12720. return -1;
  12721. }
  12722. if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
  12723. return -1;
  12724. }
  12725. if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
  12726. return -1;
  12727. }
  12728. if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
  12729. return -1;
  12730. }
  12731. if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
  12732. return -1;
  12733. }
  12734. if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
  12735. return -1;
  12736. }
  12737. if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
  12738. return -1;
  12739. }
  12740. if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
  12741. return -1;
  12742. }
  12743. if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
  12744. return -1;
  12745. }
  12746. if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
  12747. return -1;
  12748. }
  12749. if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
  12750. return -1;
  12751. }
  12752. if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
  12753. return -1;
  12754. }
  12755. if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
  12756. return -1;
  12757. }
  12758. if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
  12759. return -1;
  12760. }
  12761. if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
  12762. return -1;
  12763. }
  12764. if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
  12765. return -1;
  12766. }
  12767. if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
  12768. return -1;
  12769. }
  12770. if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
  12771. 0) {
  12772. return -1;
  12773. }
  12774. if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
  12775. 0) {
  12776. return -1;
  12777. }
  12778. if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
  12779. 0) {
  12780. return -1;
  12781. }
  12782. if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
  12783. return -1;
  12784. }
  12785. if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
  12786. return -1;
  12787. }
  12788. if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
  12789. return -1;
  12790. }
  12791. if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
  12792. return -1;
  12793. }
  12794. if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
  12795. return -1;
  12796. }
  12797. if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
  12798. return -1;
  12799. }
  12800. if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
  12801. return -1;
  12802. }
  12803. if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
  12804. return -1;
  12805. }
  12806. if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
  12807. < 0) {
  12808. return -1;
  12809. }
  12810. if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
  12811. 0) {
  12812. return -1;
  12813. }
  12814. if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
  12815. {
  12816. return -1;
  12817. }
  12818. if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
  12819. return -1;
  12820. }
  12821. if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
  12822. return -1;
  12823. }
  12824. if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
  12825. return -1;
  12826. }
  12827. if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
  12828. return -1;
  12829. }
  12830. if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
  12831. return -1;
  12832. }
  12833. if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
  12834. return -1;
  12835. }
  12836. if (PyModule_AddObjectRef(m, "type_param", state->type_param_type) < 0) {
  12837. return -1;
  12838. }
  12839. if (PyModule_AddObjectRef(m, "TypeVar", state->TypeVar_type) < 0) {
  12840. return -1;
  12841. }
  12842. if (PyModule_AddObjectRef(m, "ParamSpec", state->ParamSpec_type) < 0) {
  12843. return -1;
  12844. }
  12845. if (PyModule_AddObjectRef(m, "TypeVarTuple", state->TypeVarTuple_type) < 0)
  12846. {
  12847. return -1;
  12848. }
  12849. return 0;
  12850. }
  12851. static PyModuleDef_Slot astmodule_slots[] = {
  12852. {Py_mod_exec, astmodule_exec},
  12853. {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
  12854. {0, NULL}
  12855. };
  12856. static struct PyModuleDef _astmodule = {
  12857. PyModuleDef_HEAD_INIT,
  12858. .m_name = "_ast",
  12859. // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
  12860. .m_size = 0,
  12861. .m_slots = astmodule_slots,
  12862. };
  12863. PyMODINIT_FUNC
  12864. PyInit__ast(void)
  12865. {
  12866. return PyModuleDef_Init(&_astmodule);
  12867. }
  12868. PyObject* PyAST_mod2obj(mod_ty t)
  12869. {
  12870. struct ast_state *state = get_ast_state();
  12871. if (state == NULL) {
  12872. return NULL;
  12873. }
  12874. int starting_recursion_depth;
  12875. /* Be careful here to prevent overflow. */
  12876. PyThreadState *tstate = _PyThreadState_GET();
  12877. if (!tstate) {
  12878. return NULL;
  12879. }
  12880. struct validator vstate;
  12881. vstate.recursion_limit = C_RECURSION_LIMIT;
  12882. int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
  12883. starting_recursion_depth = recursion_depth;
  12884. vstate.recursion_depth = starting_recursion_depth;
  12885. PyObject *result = ast2obj_mod(state, &vstate, t);
  12886. /* Check that the recursion depth counting balanced correctly */
  12887. if (result && vstate.recursion_depth != starting_recursion_depth) {
  12888. PyErr_Format(PyExc_SystemError,
  12889. "AST constructor recursion depth mismatch (before=%d, after=%d)",
  12890. starting_recursion_depth, vstate.recursion_depth);
  12891. return NULL;
  12892. }
  12893. return result;
  12894. }
  12895. /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
  12896. mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
  12897. {
  12898. const char * const req_name[] = {"Module", "Expression", "Interactive"};
  12899. int isinstance;
  12900. if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
  12901. return NULL;
  12902. }
  12903. struct ast_state *state = get_ast_state();
  12904. if (state == NULL) {
  12905. return NULL;
  12906. }
  12907. PyObject *req_type[3];
  12908. req_type[0] = state->Module_type;
  12909. req_type[1] = state->Expression_type;
  12910. req_type[2] = state->Interactive_type;
  12911. assert(0 <= mode && mode <= 2);
  12912. isinstance = PyObject_IsInstance(ast, req_type[mode]);
  12913. if (isinstance == -1)
  12914. return NULL;
  12915. if (!isinstance) {
  12916. PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
  12917. req_name[mode], _PyType_Name(Py_TYPE(ast)));
  12918. return NULL;
  12919. }
  12920. mod_ty res = NULL;
  12921. if (obj2ast_mod(state, ast, &res, arena) != 0)
  12922. return NULL;
  12923. else
  12924. return res;
  12925. }
  12926. int PyAST_Check(PyObject* obj)
  12927. {
  12928. struct ast_state *state = get_ast_state();
  12929. if (state == NULL) {
  12930. return -1;
  12931. }
  12932. return PyObject_IsInstance(obj, state->AST_type);
  12933. }