Python-ast.c 442 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225
  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. fields = PyObject_GetAttr((PyObject*)Py_TYPE(self), state->_fields);
  848. if (fields == NULL) {
  849. goto cleanup;
  850. }
  851. numfields = PySequence_Size(fields);
  852. if (numfields == -1) {
  853. goto cleanup;
  854. }
  855. res = 0; /* if no error occurs, this stays 0 to the end */
  856. if (numfields < PyTuple_GET_SIZE(args)) {
  857. PyErr_Format(PyExc_TypeError, "%.400s constructor takes at most "
  858. "%zd positional argument%s",
  859. _PyType_Name(Py_TYPE(self)),
  860. numfields, numfields == 1 ? "" : "s");
  861. res = -1;
  862. goto cleanup;
  863. }
  864. for (i = 0; i < PyTuple_GET_SIZE(args); i++) {
  865. /* cannot be reached when fields is NULL */
  866. PyObject *name = PySequence_GetItem(fields, i);
  867. if (!name) {
  868. res = -1;
  869. goto cleanup;
  870. }
  871. res = PyObject_SetAttr(self, name, PyTuple_GET_ITEM(args, i));
  872. Py_DECREF(name);
  873. if (res < 0) {
  874. goto cleanup;
  875. }
  876. }
  877. if (kw) {
  878. i = 0; /* needed by PyDict_Next */
  879. while (PyDict_Next(kw, &i, &key, &value)) {
  880. int contains = PySequence_Contains(fields, key);
  881. if (contains == -1) {
  882. res = -1;
  883. goto cleanup;
  884. } else if (contains == 1) {
  885. Py_ssize_t p = PySequence_Index(fields, key);
  886. if (p == -1) {
  887. res = -1;
  888. goto cleanup;
  889. }
  890. if (p < PyTuple_GET_SIZE(args)) {
  891. PyErr_Format(PyExc_TypeError,
  892. "%.400s got multiple values for argument '%U'",
  893. Py_TYPE(self)->tp_name, key);
  894. res = -1;
  895. goto cleanup;
  896. }
  897. }
  898. res = PyObject_SetAttr(self, key, value);
  899. if (res < 0) {
  900. goto cleanup;
  901. }
  902. }
  903. }
  904. cleanup:
  905. Py_XDECREF(fields);
  906. return res;
  907. }
  908. /* Pickling support */
  909. static PyObject *
  910. ast_type_reduce(PyObject *self, PyObject *unused)
  911. {
  912. struct ast_state *state = get_ast_state();
  913. if (state == NULL) {
  914. return NULL;
  915. }
  916. PyObject *dict;
  917. if (_PyObject_LookupAttr(self, state->__dict__, &dict) < 0) {
  918. return NULL;
  919. }
  920. if (dict) {
  921. return Py_BuildValue("O()N", Py_TYPE(self), dict);
  922. }
  923. return Py_BuildValue("O()", Py_TYPE(self));
  924. }
  925. static PyMemberDef ast_type_members[] = {
  926. {"__dictoffset__", T_PYSSIZET, offsetof(AST_object, dict), READONLY},
  927. {NULL} /* Sentinel */
  928. };
  929. static PyMethodDef ast_type_methods[] = {
  930. {"__reduce__", ast_type_reduce, METH_NOARGS, NULL},
  931. {NULL}
  932. };
  933. static PyGetSetDef ast_type_getsets[] = {
  934. {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
  935. {NULL}
  936. };
  937. static PyType_Slot AST_type_slots[] = {
  938. {Py_tp_dealloc, ast_dealloc},
  939. {Py_tp_getattro, PyObject_GenericGetAttr},
  940. {Py_tp_setattro, PyObject_GenericSetAttr},
  941. {Py_tp_traverse, ast_traverse},
  942. {Py_tp_clear, ast_clear},
  943. {Py_tp_members, ast_type_members},
  944. {Py_tp_methods, ast_type_methods},
  945. {Py_tp_getset, ast_type_getsets},
  946. {Py_tp_init, ast_type_init},
  947. {Py_tp_alloc, PyType_GenericAlloc},
  948. {Py_tp_new, PyType_GenericNew},
  949. {Py_tp_free, PyObject_GC_Del},
  950. {0, 0},
  951. };
  952. static PyType_Spec AST_type_spec = {
  953. "ast.AST",
  954. sizeof(AST_object),
  955. 0,
  956. Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
  957. AST_type_slots
  958. };
  959. static PyObject *
  960. make_type(struct ast_state *state, const char *type, PyObject* base,
  961. const char* const* fields, int num_fields, const char *doc)
  962. {
  963. PyObject *fnames, *result;
  964. int i;
  965. fnames = PyTuple_New(num_fields);
  966. if (!fnames) return NULL;
  967. for (i = 0; i < num_fields; i++) {
  968. PyObject *field = PyUnicode_InternFromString(fields[i]);
  969. if (!field) {
  970. Py_DECREF(fnames);
  971. return NULL;
  972. }
  973. PyTuple_SET_ITEM(fnames, i, field);
  974. }
  975. result = PyObject_CallFunction((PyObject*)&PyType_Type, "s(O){OOOOOOOs}",
  976. type, base,
  977. state->_fields, fnames,
  978. state->__match_args__, fnames,
  979. state->__module__,
  980. state->ast,
  981. state->__doc__, doc);
  982. Py_DECREF(fnames);
  983. return result;
  984. }
  985. static int
  986. add_attributes(struct ast_state *state, PyObject *type, const char * const *attrs, int num_fields)
  987. {
  988. int i, result;
  989. PyObject *s, *l = PyTuple_New(num_fields);
  990. if (!l)
  991. return 0;
  992. for (i = 0; i < num_fields; i++) {
  993. s = PyUnicode_InternFromString(attrs[i]);
  994. if (!s) {
  995. Py_DECREF(l);
  996. return 0;
  997. }
  998. PyTuple_SET_ITEM(l, i, s);
  999. }
  1000. result = PyObject_SetAttr(type, state->_attributes, l) >= 0;
  1001. Py_DECREF(l);
  1002. return result;
  1003. }
  1004. /* Conversion AST -> Python */
  1005. static PyObject* ast2obj_list(struct ast_state *state, struct validator *vstate, asdl_seq *seq,
  1006. PyObject* (*func)(struct ast_state *state, struct validator *vstate, void*))
  1007. {
  1008. Py_ssize_t i, n = asdl_seq_LEN(seq);
  1009. PyObject *result = PyList_New(n);
  1010. PyObject *value;
  1011. if (!result)
  1012. return NULL;
  1013. for (i = 0; i < n; i++) {
  1014. value = func(state, vstate, asdl_seq_GET_UNTYPED(seq, i));
  1015. if (!value) {
  1016. Py_DECREF(result);
  1017. return NULL;
  1018. }
  1019. PyList_SET_ITEM(result, i, value);
  1020. }
  1021. return result;
  1022. }
  1023. static PyObject* ast2obj_object(struct ast_state *Py_UNUSED(state), struct validator *Py_UNUSED(vstate), void *o)
  1024. {
  1025. PyObject *op = (PyObject*)o;
  1026. if (!op) {
  1027. op = Py_None;
  1028. }
  1029. return Py_NewRef(op);
  1030. }
  1031. #define ast2obj_constant ast2obj_object
  1032. #define ast2obj_identifier ast2obj_object
  1033. #define ast2obj_string ast2obj_object
  1034. static PyObject* ast2obj_int(struct ast_state *Py_UNUSED(state), struct validator *Py_UNUSED(vstate), long b)
  1035. {
  1036. return PyLong_FromLong(b);
  1037. }
  1038. /* Conversion Python -> AST */
  1039. static int obj2ast_object(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
  1040. {
  1041. if (obj == Py_None)
  1042. obj = NULL;
  1043. if (obj) {
  1044. if (_PyArena_AddPyObject(arena, obj) < 0) {
  1045. *out = NULL;
  1046. return -1;
  1047. }
  1048. *out = Py_NewRef(obj);
  1049. }
  1050. else {
  1051. *out = NULL;
  1052. }
  1053. return 0;
  1054. }
  1055. static int obj2ast_constant(struct ast_state *Py_UNUSED(state), PyObject* obj, PyObject** out, PyArena* arena)
  1056. {
  1057. if (_PyArena_AddPyObject(arena, obj) < 0) {
  1058. *out = NULL;
  1059. return -1;
  1060. }
  1061. *out = Py_NewRef(obj);
  1062. return 0;
  1063. }
  1064. static int obj2ast_identifier(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
  1065. {
  1066. if (!PyUnicode_CheckExact(obj) && obj != Py_None) {
  1067. PyErr_SetString(PyExc_TypeError, "AST identifier must be of type str");
  1068. return 1;
  1069. }
  1070. return obj2ast_object(state, obj, out, arena);
  1071. }
  1072. static int obj2ast_string(struct ast_state *state, PyObject* obj, PyObject** out, PyArena* arena)
  1073. {
  1074. if (!PyUnicode_CheckExact(obj) && !PyBytes_CheckExact(obj)) {
  1075. PyErr_SetString(PyExc_TypeError, "AST string must be of type str");
  1076. return 1;
  1077. }
  1078. return obj2ast_object(state, obj, out, arena);
  1079. }
  1080. static int obj2ast_int(struct ast_state* Py_UNUSED(state), PyObject* obj, int* out, PyArena* arena)
  1081. {
  1082. int i;
  1083. if (!PyLong_Check(obj)) {
  1084. PyErr_Format(PyExc_ValueError, "invalid integer value: %R", obj);
  1085. return 1;
  1086. }
  1087. i = _PyLong_AsInt(obj);
  1088. if (i == -1 && PyErr_Occurred())
  1089. return 1;
  1090. *out = i;
  1091. return 0;
  1092. }
  1093. static int add_ast_fields(struct ast_state *state)
  1094. {
  1095. PyObject *empty_tuple;
  1096. empty_tuple = PyTuple_New(0);
  1097. if (!empty_tuple ||
  1098. PyObject_SetAttrString(state->AST_type, "_fields", empty_tuple) < 0 ||
  1099. PyObject_SetAttrString(state->AST_type, "__match_args__", empty_tuple) < 0 ||
  1100. PyObject_SetAttrString(state->AST_type, "_attributes", empty_tuple) < 0) {
  1101. Py_XDECREF(empty_tuple);
  1102. return -1;
  1103. }
  1104. Py_DECREF(empty_tuple);
  1105. return 0;
  1106. }
  1107. static int
  1108. init_types(struct ast_state *state)
  1109. {
  1110. // init_types() must not be called after _PyAST_Fini()
  1111. // has been called
  1112. assert(state->initialized >= 0);
  1113. if (state->initialized) {
  1114. return 1;
  1115. }
  1116. if (init_identifiers(state) < 0) {
  1117. return 0;
  1118. }
  1119. state->AST_type = PyType_FromSpec(&AST_type_spec);
  1120. if (!state->AST_type) {
  1121. return 0;
  1122. }
  1123. if (add_ast_fields(state) < 0) {
  1124. return 0;
  1125. }
  1126. state->mod_type = make_type(state, "mod", state->AST_type, NULL, 0,
  1127. "mod = Module(stmt* body, type_ignore* type_ignores)\n"
  1128. " | Interactive(stmt* body)\n"
  1129. " | Expression(expr body)\n"
  1130. " | FunctionType(expr* argtypes, expr returns)");
  1131. if (!state->mod_type) return 0;
  1132. if (!add_attributes(state, state->mod_type, NULL, 0)) return 0;
  1133. state->Module_type = make_type(state, "Module", state->mod_type,
  1134. Module_fields, 2,
  1135. "Module(stmt* body, type_ignore* type_ignores)");
  1136. if (!state->Module_type) return 0;
  1137. state->Interactive_type = make_type(state, "Interactive", state->mod_type,
  1138. Interactive_fields, 1,
  1139. "Interactive(stmt* body)");
  1140. if (!state->Interactive_type) return 0;
  1141. state->Expression_type = make_type(state, "Expression", state->mod_type,
  1142. Expression_fields, 1,
  1143. "Expression(expr body)");
  1144. if (!state->Expression_type) return 0;
  1145. state->FunctionType_type = make_type(state, "FunctionType",
  1146. state->mod_type, FunctionType_fields,
  1147. 2,
  1148. "FunctionType(expr* argtypes, expr returns)");
  1149. if (!state->FunctionType_type) return 0;
  1150. state->stmt_type = make_type(state, "stmt", state->AST_type, NULL, 0,
  1151. "stmt = FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
  1152. " | AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)\n"
  1153. " | ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)\n"
  1154. " | Return(expr? value)\n"
  1155. " | Delete(expr* targets)\n"
  1156. " | Assign(expr* targets, expr value, string? type_comment)\n"
  1157. " | TypeAlias(expr name, type_param* type_params, expr value)\n"
  1158. " | AugAssign(expr target, operator op, expr value)\n"
  1159. " | AnnAssign(expr target, expr annotation, expr? value, int simple)\n"
  1160. " | For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
  1161. " | AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)\n"
  1162. " | While(expr test, stmt* body, stmt* orelse)\n"
  1163. " | If(expr test, stmt* body, stmt* orelse)\n"
  1164. " | With(withitem* items, stmt* body, string? type_comment)\n"
  1165. " | AsyncWith(withitem* items, stmt* body, string? type_comment)\n"
  1166. " | Match(expr subject, match_case* cases)\n"
  1167. " | Raise(expr? exc, expr? cause)\n"
  1168. " | Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
  1169. " | TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)\n"
  1170. " | Assert(expr test, expr? msg)\n"
  1171. " | Import(alias* names)\n"
  1172. " | ImportFrom(identifier? module, alias* names, int? level)\n"
  1173. " | Global(identifier* names)\n"
  1174. " | Nonlocal(identifier* names)\n"
  1175. " | Expr(expr value)\n"
  1176. " | Pass\n"
  1177. " | Break\n"
  1178. " | Continue");
  1179. if (!state->stmt_type) return 0;
  1180. if (!add_attributes(state, state->stmt_type, stmt_attributes, 4)) return 0;
  1181. if (PyObject_SetAttr(state->stmt_type, state->end_lineno, Py_None) == -1)
  1182. return 0;
  1183. if (PyObject_SetAttr(state->stmt_type, state->end_col_offset, Py_None) ==
  1184. -1)
  1185. return 0;
  1186. state->FunctionDef_type = make_type(state, "FunctionDef", state->stmt_type,
  1187. FunctionDef_fields, 7,
  1188. "FunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
  1189. if (!state->FunctionDef_type) return 0;
  1190. if (PyObject_SetAttr(state->FunctionDef_type, state->returns, Py_None) ==
  1191. -1)
  1192. return 0;
  1193. if (PyObject_SetAttr(state->FunctionDef_type, state->type_comment, Py_None)
  1194. == -1)
  1195. return 0;
  1196. state->AsyncFunctionDef_type = make_type(state, "AsyncFunctionDef",
  1197. state->stmt_type,
  1198. AsyncFunctionDef_fields, 7,
  1199. "AsyncFunctionDef(identifier name, arguments args, stmt* body, expr* decorator_list, expr? returns, string? type_comment, type_param* type_params)");
  1200. if (!state->AsyncFunctionDef_type) return 0;
  1201. if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->returns, Py_None)
  1202. == -1)
  1203. return 0;
  1204. if (PyObject_SetAttr(state->AsyncFunctionDef_type, state->type_comment,
  1205. Py_None) == -1)
  1206. return 0;
  1207. state->ClassDef_type = make_type(state, "ClassDef", state->stmt_type,
  1208. ClassDef_fields, 6,
  1209. "ClassDef(identifier name, expr* bases, keyword* keywords, stmt* body, expr* decorator_list, type_param* type_params)");
  1210. if (!state->ClassDef_type) return 0;
  1211. state->Return_type = make_type(state, "Return", state->stmt_type,
  1212. Return_fields, 1,
  1213. "Return(expr? value)");
  1214. if (!state->Return_type) return 0;
  1215. if (PyObject_SetAttr(state->Return_type, state->value, Py_None) == -1)
  1216. return 0;
  1217. state->Delete_type = make_type(state, "Delete", state->stmt_type,
  1218. Delete_fields, 1,
  1219. "Delete(expr* targets)");
  1220. if (!state->Delete_type) return 0;
  1221. state->Assign_type = make_type(state, "Assign", state->stmt_type,
  1222. Assign_fields, 3,
  1223. "Assign(expr* targets, expr value, string? type_comment)");
  1224. if (!state->Assign_type) return 0;
  1225. if (PyObject_SetAttr(state->Assign_type, state->type_comment, Py_None) ==
  1226. -1)
  1227. return 0;
  1228. state->TypeAlias_type = make_type(state, "TypeAlias", state->stmt_type,
  1229. TypeAlias_fields, 3,
  1230. "TypeAlias(expr name, type_param* type_params, expr value)");
  1231. if (!state->TypeAlias_type) return 0;
  1232. state->AugAssign_type = make_type(state, "AugAssign", state->stmt_type,
  1233. AugAssign_fields, 3,
  1234. "AugAssign(expr target, operator op, expr value)");
  1235. if (!state->AugAssign_type) return 0;
  1236. state->AnnAssign_type = make_type(state, "AnnAssign", state->stmt_type,
  1237. AnnAssign_fields, 4,
  1238. "AnnAssign(expr target, expr annotation, expr? value, int simple)");
  1239. if (!state->AnnAssign_type) return 0;
  1240. if (PyObject_SetAttr(state->AnnAssign_type, state->value, Py_None) == -1)
  1241. return 0;
  1242. state->For_type = make_type(state, "For", state->stmt_type, For_fields, 5,
  1243. "For(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
  1244. if (!state->For_type) return 0;
  1245. if (PyObject_SetAttr(state->For_type, state->type_comment, Py_None) == -1)
  1246. return 0;
  1247. state->AsyncFor_type = make_type(state, "AsyncFor", state->stmt_type,
  1248. AsyncFor_fields, 5,
  1249. "AsyncFor(expr target, expr iter, stmt* body, stmt* orelse, string? type_comment)");
  1250. if (!state->AsyncFor_type) return 0;
  1251. if (PyObject_SetAttr(state->AsyncFor_type, state->type_comment, Py_None) ==
  1252. -1)
  1253. return 0;
  1254. state->While_type = make_type(state, "While", state->stmt_type,
  1255. While_fields, 3,
  1256. "While(expr test, stmt* body, stmt* orelse)");
  1257. if (!state->While_type) return 0;
  1258. state->If_type = make_type(state, "If", state->stmt_type, If_fields, 3,
  1259. "If(expr test, stmt* body, stmt* orelse)");
  1260. if (!state->If_type) return 0;
  1261. state->With_type = make_type(state, "With", state->stmt_type, With_fields,
  1262. 3,
  1263. "With(withitem* items, stmt* body, string? type_comment)");
  1264. if (!state->With_type) return 0;
  1265. if (PyObject_SetAttr(state->With_type, state->type_comment, Py_None) == -1)
  1266. return 0;
  1267. state->AsyncWith_type = make_type(state, "AsyncWith", state->stmt_type,
  1268. AsyncWith_fields, 3,
  1269. "AsyncWith(withitem* items, stmt* body, string? type_comment)");
  1270. if (!state->AsyncWith_type) return 0;
  1271. if (PyObject_SetAttr(state->AsyncWith_type, state->type_comment, Py_None)
  1272. == -1)
  1273. return 0;
  1274. state->Match_type = make_type(state, "Match", state->stmt_type,
  1275. Match_fields, 2,
  1276. "Match(expr subject, match_case* cases)");
  1277. if (!state->Match_type) return 0;
  1278. state->Raise_type = make_type(state, "Raise", state->stmt_type,
  1279. Raise_fields, 2,
  1280. "Raise(expr? exc, expr? cause)");
  1281. if (!state->Raise_type) return 0;
  1282. if (PyObject_SetAttr(state->Raise_type, state->exc, Py_None) == -1)
  1283. return 0;
  1284. if (PyObject_SetAttr(state->Raise_type, state->cause, Py_None) == -1)
  1285. return 0;
  1286. state->Try_type = make_type(state, "Try", state->stmt_type, Try_fields, 4,
  1287. "Try(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
  1288. if (!state->Try_type) return 0;
  1289. state->TryStar_type = make_type(state, "TryStar", state->stmt_type,
  1290. TryStar_fields, 4,
  1291. "TryStar(stmt* body, excepthandler* handlers, stmt* orelse, stmt* finalbody)");
  1292. if (!state->TryStar_type) return 0;
  1293. state->Assert_type = make_type(state, "Assert", state->stmt_type,
  1294. Assert_fields, 2,
  1295. "Assert(expr test, expr? msg)");
  1296. if (!state->Assert_type) return 0;
  1297. if (PyObject_SetAttr(state->Assert_type, state->msg, Py_None) == -1)
  1298. return 0;
  1299. state->Import_type = make_type(state, "Import", state->stmt_type,
  1300. Import_fields, 1,
  1301. "Import(alias* names)");
  1302. if (!state->Import_type) return 0;
  1303. state->ImportFrom_type = make_type(state, "ImportFrom", state->stmt_type,
  1304. ImportFrom_fields, 3,
  1305. "ImportFrom(identifier? module, alias* names, int? level)");
  1306. if (!state->ImportFrom_type) return 0;
  1307. if (PyObject_SetAttr(state->ImportFrom_type, state->module, Py_None) == -1)
  1308. return 0;
  1309. if (PyObject_SetAttr(state->ImportFrom_type, state->level, Py_None) == -1)
  1310. return 0;
  1311. state->Global_type = make_type(state, "Global", state->stmt_type,
  1312. Global_fields, 1,
  1313. "Global(identifier* names)");
  1314. if (!state->Global_type) return 0;
  1315. state->Nonlocal_type = make_type(state, "Nonlocal", state->stmt_type,
  1316. Nonlocal_fields, 1,
  1317. "Nonlocal(identifier* names)");
  1318. if (!state->Nonlocal_type) return 0;
  1319. state->Expr_type = make_type(state, "Expr", state->stmt_type, Expr_fields,
  1320. 1,
  1321. "Expr(expr value)");
  1322. if (!state->Expr_type) return 0;
  1323. state->Pass_type = make_type(state, "Pass", state->stmt_type, NULL, 0,
  1324. "Pass");
  1325. if (!state->Pass_type) return 0;
  1326. state->Break_type = make_type(state, "Break", state->stmt_type, NULL, 0,
  1327. "Break");
  1328. if (!state->Break_type) return 0;
  1329. state->Continue_type = make_type(state, "Continue", state->stmt_type, NULL,
  1330. 0,
  1331. "Continue");
  1332. if (!state->Continue_type) return 0;
  1333. state->expr_type = make_type(state, "expr", state->AST_type, NULL, 0,
  1334. "expr = BoolOp(boolop op, expr* values)\n"
  1335. " | NamedExpr(expr target, expr value)\n"
  1336. " | BinOp(expr left, operator op, expr right)\n"
  1337. " | UnaryOp(unaryop op, expr operand)\n"
  1338. " | Lambda(arguments args, expr body)\n"
  1339. " | IfExp(expr test, expr body, expr orelse)\n"
  1340. " | Dict(expr* keys, expr* values)\n"
  1341. " | Set(expr* elts)\n"
  1342. " | ListComp(expr elt, comprehension* generators)\n"
  1343. " | SetComp(expr elt, comprehension* generators)\n"
  1344. " | DictComp(expr key, expr value, comprehension* generators)\n"
  1345. " | GeneratorExp(expr elt, comprehension* generators)\n"
  1346. " | Await(expr value)\n"
  1347. " | Yield(expr? value)\n"
  1348. " | YieldFrom(expr value)\n"
  1349. " | Compare(expr left, cmpop* ops, expr* comparators)\n"
  1350. " | Call(expr func, expr* args, keyword* keywords)\n"
  1351. " | FormattedValue(expr value, int conversion, expr? format_spec)\n"
  1352. " | JoinedStr(expr* values)\n"
  1353. " | Constant(constant value, string? kind)\n"
  1354. " | Attribute(expr value, identifier attr, expr_context ctx)\n"
  1355. " | Subscript(expr value, expr slice, expr_context ctx)\n"
  1356. " | Starred(expr value, expr_context ctx)\n"
  1357. " | Name(identifier id, expr_context ctx)\n"
  1358. " | List(expr* elts, expr_context ctx)\n"
  1359. " | Tuple(expr* elts, expr_context ctx)\n"
  1360. " | Slice(expr? lower, expr? upper, expr? step)");
  1361. if (!state->expr_type) return 0;
  1362. if (!add_attributes(state, state->expr_type, expr_attributes, 4)) return 0;
  1363. if (PyObject_SetAttr(state->expr_type, state->end_lineno, Py_None) == -1)
  1364. return 0;
  1365. if (PyObject_SetAttr(state->expr_type, state->end_col_offset, Py_None) ==
  1366. -1)
  1367. return 0;
  1368. state->BoolOp_type = make_type(state, "BoolOp", state->expr_type,
  1369. BoolOp_fields, 2,
  1370. "BoolOp(boolop op, expr* values)");
  1371. if (!state->BoolOp_type) return 0;
  1372. state->NamedExpr_type = make_type(state, "NamedExpr", state->expr_type,
  1373. NamedExpr_fields, 2,
  1374. "NamedExpr(expr target, expr value)");
  1375. if (!state->NamedExpr_type) return 0;
  1376. state->BinOp_type = make_type(state, "BinOp", state->expr_type,
  1377. BinOp_fields, 3,
  1378. "BinOp(expr left, operator op, expr right)");
  1379. if (!state->BinOp_type) return 0;
  1380. state->UnaryOp_type = make_type(state, "UnaryOp", state->expr_type,
  1381. UnaryOp_fields, 2,
  1382. "UnaryOp(unaryop op, expr operand)");
  1383. if (!state->UnaryOp_type) return 0;
  1384. state->Lambda_type = make_type(state, "Lambda", state->expr_type,
  1385. Lambda_fields, 2,
  1386. "Lambda(arguments args, expr body)");
  1387. if (!state->Lambda_type) return 0;
  1388. state->IfExp_type = make_type(state, "IfExp", state->expr_type,
  1389. IfExp_fields, 3,
  1390. "IfExp(expr test, expr body, expr orelse)");
  1391. if (!state->IfExp_type) return 0;
  1392. state->Dict_type = make_type(state, "Dict", state->expr_type, Dict_fields,
  1393. 2,
  1394. "Dict(expr* keys, expr* values)");
  1395. if (!state->Dict_type) return 0;
  1396. state->Set_type = make_type(state, "Set", state->expr_type, Set_fields, 1,
  1397. "Set(expr* elts)");
  1398. if (!state->Set_type) return 0;
  1399. state->ListComp_type = make_type(state, "ListComp", state->expr_type,
  1400. ListComp_fields, 2,
  1401. "ListComp(expr elt, comprehension* generators)");
  1402. if (!state->ListComp_type) return 0;
  1403. state->SetComp_type = make_type(state, "SetComp", state->expr_type,
  1404. SetComp_fields, 2,
  1405. "SetComp(expr elt, comprehension* generators)");
  1406. if (!state->SetComp_type) return 0;
  1407. state->DictComp_type = make_type(state, "DictComp", state->expr_type,
  1408. DictComp_fields, 3,
  1409. "DictComp(expr key, expr value, comprehension* generators)");
  1410. if (!state->DictComp_type) return 0;
  1411. state->GeneratorExp_type = make_type(state, "GeneratorExp",
  1412. state->expr_type, GeneratorExp_fields,
  1413. 2,
  1414. "GeneratorExp(expr elt, comprehension* generators)");
  1415. if (!state->GeneratorExp_type) return 0;
  1416. state->Await_type = make_type(state, "Await", state->expr_type,
  1417. Await_fields, 1,
  1418. "Await(expr value)");
  1419. if (!state->Await_type) return 0;
  1420. state->Yield_type = make_type(state, "Yield", state->expr_type,
  1421. Yield_fields, 1,
  1422. "Yield(expr? value)");
  1423. if (!state->Yield_type) return 0;
  1424. if (PyObject_SetAttr(state->Yield_type, state->value, Py_None) == -1)
  1425. return 0;
  1426. state->YieldFrom_type = make_type(state, "YieldFrom", state->expr_type,
  1427. YieldFrom_fields, 1,
  1428. "YieldFrom(expr value)");
  1429. if (!state->YieldFrom_type) return 0;
  1430. state->Compare_type = make_type(state, "Compare", state->expr_type,
  1431. Compare_fields, 3,
  1432. "Compare(expr left, cmpop* ops, expr* comparators)");
  1433. if (!state->Compare_type) return 0;
  1434. state->Call_type = make_type(state, "Call", state->expr_type, Call_fields,
  1435. 3,
  1436. "Call(expr func, expr* args, keyword* keywords)");
  1437. if (!state->Call_type) return 0;
  1438. state->FormattedValue_type = make_type(state, "FormattedValue",
  1439. state->expr_type,
  1440. FormattedValue_fields, 3,
  1441. "FormattedValue(expr value, int conversion, expr? format_spec)");
  1442. if (!state->FormattedValue_type) return 0;
  1443. if (PyObject_SetAttr(state->FormattedValue_type, state->format_spec,
  1444. Py_None) == -1)
  1445. return 0;
  1446. state->JoinedStr_type = make_type(state, "JoinedStr", state->expr_type,
  1447. JoinedStr_fields, 1,
  1448. "JoinedStr(expr* values)");
  1449. if (!state->JoinedStr_type) return 0;
  1450. state->Constant_type = make_type(state, "Constant", state->expr_type,
  1451. Constant_fields, 2,
  1452. "Constant(constant value, string? kind)");
  1453. if (!state->Constant_type) return 0;
  1454. if (PyObject_SetAttr(state->Constant_type, state->kind, Py_None) == -1)
  1455. return 0;
  1456. state->Attribute_type = make_type(state, "Attribute", state->expr_type,
  1457. Attribute_fields, 3,
  1458. "Attribute(expr value, identifier attr, expr_context ctx)");
  1459. if (!state->Attribute_type) return 0;
  1460. state->Subscript_type = make_type(state, "Subscript", state->expr_type,
  1461. Subscript_fields, 3,
  1462. "Subscript(expr value, expr slice, expr_context ctx)");
  1463. if (!state->Subscript_type) return 0;
  1464. state->Starred_type = make_type(state, "Starred", state->expr_type,
  1465. Starred_fields, 2,
  1466. "Starred(expr value, expr_context ctx)");
  1467. if (!state->Starred_type) return 0;
  1468. state->Name_type = make_type(state, "Name", state->expr_type, Name_fields,
  1469. 2,
  1470. "Name(identifier id, expr_context ctx)");
  1471. if (!state->Name_type) return 0;
  1472. state->List_type = make_type(state, "List", state->expr_type, List_fields,
  1473. 2,
  1474. "List(expr* elts, expr_context ctx)");
  1475. if (!state->List_type) return 0;
  1476. state->Tuple_type = make_type(state, "Tuple", state->expr_type,
  1477. Tuple_fields, 2,
  1478. "Tuple(expr* elts, expr_context ctx)");
  1479. if (!state->Tuple_type) return 0;
  1480. state->Slice_type = make_type(state, "Slice", state->expr_type,
  1481. Slice_fields, 3,
  1482. "Slice(expr? lower, expr? upper, expr? step)");
  1483. if (!state->Slice_type) return 0;
  1484. if (PyObject_SetAttr(state->Slice_type, state->lower, Py_None) == -1)
  1485. return 0;
  1486. if (PyObject_SetAttr(state->Slice_type, state->upper, Py_None) == -1)
  1487. return 0;
  1488. if (PyObject_SetAttr(state->Slice_type, state->step, Py_None) == -1)
  1489. return 0;
  1490. state->expr_context_type = make_type(state, "expr_context",
  1491. state->AST_type, NULL, 0,
  1492. "expr_context = Load | Store | Del");
  1493. if (!state->expr_context_type) return 0;
  1494. if (!add_attributes(state, state->expr_context_type, NULL, 0)) return 0;
  1495. state->Load_type = make_type(state, "Load", state->expr_context_type, NULL,
  1496. 0,
  1497. "Load");
  1498. if (!state->Load_type) return 0;
  1499. state->Load_singleton = PyType_GenericNew((PyTypeObject *)state->Load_type,
  1500. NULL, NULL);
  1501. if (!state->Load_singleton) return 0;
  1502. state->Store_type = make_type(state, "Store", state->expr_context_type,
  1503. NULL, 0,
  1504. "Store");
  1505. if (!state->Store_type) return 0;
  1506. state->Store_singleton = PyType_GenericNew((PyTypeObject
  1507. *)state->Store_type, NULL, NULL);
  1508. if (!state->Store_singleton) return 0;
  1509. state->Del_type = make_type(state, "Del", state->expr_context_type, NULL, 0,
  1510. "Del");
  1511. if (!state->Del_type) return 0;
  1512. state->Del_singleton = PyType_GenericNew((PyTypeObject *)state->Del_type,
  1513. NULL, NULL);
  1514. if (!state->Del_singleton) return 0;
  1515. state->boolop_type = make_type(state, "boolop", state->AST_type, NULL, 0,
  1516. "boolop = And | Or");
  1517. if (!state->boolop_type) return 0;
  1518. if (!add_attributes(state, state->boolop_type, NULL, 0)) return 0;
  1519. state->And_type = make_type(state, "And", state->boolop_type, NULL, 0,
  1520. "And");
  1521. if (!state->And_type) return 0;
  1522. state->And_singleton = PyType_GenericNew((PyTypeObject *)state->And_type,
  1523. NULL, NULL);
  1524. if (!state->And_singleton) return 0;
  1525. state->Or_type = make_type(state, "Or", state->boolop_type, NULL, 0,
  1526. "Or");
  1527. if (!state->Or_type) return 0;
  1528. state->Or_singleton = PyType_GenericNew((PyTypeObject *)state->Or_type,
  1529. NULL, NULL);
  1530. if (!state->Or_singleton) return 0;
  1531. state->operator_type = make_type(state, "operator", state->AST_type, NULL,
  1532. 0,
  1533. "operator = Add | Sub | Mult | MatMult | Div | Mod | Pow | LShift | RShift | BitOr | BitXor | BitAnd | FloorDiv");
  1534. if (!state->operator_type) return 0;
  1535. if (!add_attributes(state, state->operator_type, NULL, 0)) return 0;
  1536. state->Add_type = make_type(state, "Add", state->operator_type, NULL, 0,
  1537. "Add");
  1538. if (!state->Add_type) return 0;
  1539. state->Add_singleton = PyType_GenericNew((PyTypeObject *)state->Add_type,
  1540. NULL, NULL);
  1541. if (!state->Add_singleton) return 0;
  1542. state->Sub_type = make_type(state, "Sub", state->operator_type, NULL, 0,
  1543. "Sub");
  1544. if (!state->Sub_type) return 0;
  1545. state->Sub_singleton = PyType_GenericNew((PyTypeObject *)state->Sub_type,
  1546. NULL, NULL);
  1547. if (!state->Sub_singleton) return 0;
  1548. state->Mult_type = make_type(state, "Mult", state->operator_type, NULL, 0,
  1549. "Mult");
  1550. if (!state->Mult_type) return 0;
  1551. state->Mult_singleton = PyType_GenericNew((PyTypeObject *)state->Mult_type,
  1552. NULL, NULL);
  1553. if (!state->Mult_singleton) return 0;
  1554. state->MatMult_type = make_type(state, "MatMult", state->operator_type,
  1555. NULL, 0,
  1556. "MatMult");
  1557. if (!state->MatMult_type) return 0;
  1558. state->MatMult_singleton = PyType_GenericNew((PyTypeObject
  1559. *)state->MatMult_type, NULL,
  1560. NULL);
  1561. if (!state->MatMult_singleton) return 0;
  1562. state->Div_type = make_type(state, "Div", state->operator_type, NULL, 0,
  1563. "Div");
  1564. if (!state->Div_type) return 0;
  1565. state->Div_singleton = PyType_GenericNew((PyTypeObject *)state->Div_type,
  1566. NULL, NULL);
  1567. if (!state->Div_singleton) return 0;
  1568. state->Mod_type = make_type(state, "Mod", state->operator_type, NULL, 0,
  1569. "Mod");
  1570. if (!state->Mod_type) return 0;
  1571. state->Mod_singleton = PyType_GenericNew((PyTypeObject *)state->Mod_type,
  1572. NULL, NULL);
  1573. if (!state->Mod_singleton) return 0;
  1574. state->Pow_type = make_type(state, "Pow", state->operator_type, NULL, 0,
  1575. "Pow");
  1576. if (!state->Pow_type) return 0;
  1577. state->Pow_singleton = PyType_GenericNew((PyTypeObject *)state->Pow_type,
  1578. NULL, NULL);
  1579. if (!state->Pow_singleton) return 0;
  1580. state->LShift_type = make_type(state, "LShift", state->operator_type, NULL,
  1581. 0,
  1582. "LShift");
  1583. if (!state->LShift_type) return 0;
  1584. state->LShift_singleton = PyType_GenericNew((PyTypeObject
  1585. *)state->LShift_type, NULL,
  1586. NULL);
  1587. if (!state->LShift_singleton) return 0;
  1588. state->RShift_type = make_type(state, "RShift", state->operator_type, NULL,
  1589. 0,
  1590. "RShift");
  1591. if (!state->RShift_type) return 0;
  1592. state->RShift_singleton = PyType_GenericNew((PyTypeObject
  1593. *)state->RShift_type, NULL,
  1594. NULL);
  1595. if (!state->RShift_singleton) return 0;
  1596. state->BitOr_type = make_type(state, "BitOr", state->operator_type, NULL, 0,
  1597. "BitOr");
  1598. if (!state->BitOr_type) return 0;
  1599. state->BitOr_singleton = PyType_GenericNew((PyTypeObject
  1600. *)state->BitOr_type, NULL, NULL);
  1601. if (!state->BitOr_singleton) return 0;
  1602. state->BitXor_type = make_type(state, "BitXor", state->operator_type, NULL,
  1603. 0,
  1604. "BitXor");
  1605. if (!state->BitXor_type) return 0;
  1606. state->BitXor_singleton = PyType_GenericNew((PyTypeObject
  1607. *)state->BitXor_type, NULL,
  1608. NULL);
  1609. if (!state->BitXor_singleton) return 0;
  1610. state->BitAnd_type = make_type(state, "BitAnd", state->operator_type, NULL,
  1611. 0,
  1612. "BitAnd");
  1613. if (!state->BitAnd_type) return 0;
  1614. state->BitAnd_singleton = PyType_GenericNew((PyTypeObject
  1615. *)state->BitAnd_type, NULL,
  1616. NULL);
  1617. if (!state->BitAnd_singleton) return 0;
  1618. state->FloorDiv_type = make_type(state, "FloorDiv", state->operator_type,
  1619. NULL, 0,
  1620. "FloorDiv");
  1621. if (!state->FloorDiv_type) return 0;
  1622. state->FloorDiv_singleton = PyType_GenericNew((PyTypeObject
  1623. *)state->FloorDiv_type, NULL,
  1624. NULL);
  1625. if (!state->FloorDiv_singleton) return 0;
  1626. state->unaryop_type = make_type(state, "unaryop", state->AST_type, NULL, 0,
  1627. "unaryop = Invert | Not | UAdd | USub");
  1628. if (!state->unaryop_type) return 0;
  1629. if (!add_attributes(state, state->unaryop_type, NULL, 0)) return 0;
  1630. state->Invert_type = make_type(state, "Invert", state->unaryop_type, NULL,
  1631. 0,
  1632. "Invert");
  1633. if (!state->Invert_type) return 0;
  1634. state->Invert_singleton = PyType_GenericNew((PyTypeObject
  1635. *)state->Invert_type, NULL,
  1636. NULL);
  1637. if (!state->Invert_singleton) return 0;
  1638. state->Not_type = make_type(state, "Not", state->unaryop_type, NULL, 0,
  1639. "Not");
  1640. if (!state->Not_type) return 0;
  1641. state->Not_singleton = PyType_GenericNew((PyTypeObject *)state->Not_type,
  1642. NULL, NULL);
  1643. if (!state->Not_singleton) return 0;
  1644. state->UAdd_type = make_type(state, "UAdd", state->unaryop_type, NULL, 0,
  1645. "UAdd");
  1646. if (!state->UAdd_type) return 0;
  1647. state->UAdd_singleton = PyType_GenericNew((PyTypeObject *)state->UAdd_type,
  1648. NULL, NULL);
  1649. if (!state->UAdd_singleton) return 0;
  1650. state->USub_type = make_type(state, "USub", state->unaryop_type, NULL, 0,
  1651. "USub");
  1652. if (!state->USub_type) return 0;
  1653. state->USub_singleton = PyType_GenericNew((PyTypeObject *)state->USub_type,
  1654. NULL, NULL);
  1655. if (!state->USub_singleton) return 0;
  1656. state->cmpop_type = make_type(state, "cmpop", state->AST_type, NULL, 0,
  1657. "cmpop = Eq | NotEq | Lt | LtE | Gt | GtE | Is | IsNot | In | NotIn");
  1658. if (!state->cmpop_type) return 0;
  1659. if (!add_attributes(state, state->cmpop_type, NULL, 0)) return 0;
  1660. state->Eq_type = make_type(state, "Eq", state->cmpop_type, NULL, 0,
  1661. "Eq");
  1662. if (!state->Eq_type) return 0;
  1663. state->Eq_singleton = PyType_GenericNew((PyTypeObject *)state->Eq_type,
  1664. NULL, NULL);
  1665. if (!state->Eq_singleton) return 0;
  1666. state->NotEq_type = make_type(state, "NotEq", state->cmpop_type, NULL, 0,
  1667. "NotEq");
  1668. if (!state->NotEq_type) return 0;
  1669. state->NotEq_singleton = PyType_GenericNew((PyTypeObject
  1670. *)state->NotEq_type, NULL, NULL);
  1671. if (!state->NotEq_singleton) return 0;
  1672. state->Lt_type = make_type(state, "Lt", state->cmpop_type, NULL, 0,
  1673. "Lt");
  1674. if (!state->Lt_type) return 0;
  1675. state->Lt_singleton = PyType_GenericNew((PyTypeObject *)state->Lt_type,
  1676. NULL, NULL);
  1677. if (!state->Lt_singleton) return 0;
  1678. state->LtE_type = make_type(state, "LtE", state->cmpop_type, NULL, 0,
  1679. "LtE");
  1680. if (!state->LtE_type) return 0;
  1681. state->LtE_singleton = PyType_GenericNew((PyTypeObject *)state->LtE_type,
  1682. NULL, NULL);
  1683. if (!state->LtE_singleton) return 0;
  1684. state->Gt_type = make_type(state, "Gt", state->cmpop_type, NULL, 0,
  1685. "Gt");
  1686. if (!state->Gt_type) return 0;
  1687. state->Gt_singleton = PyType_GenericNew((PyTypeObject *)state->Gt_type,
  1688. NULL, NULL);
  1689. if (!state->Gt_singleton) return 0;
  1690. state->GtE_type = make_type(state, "GtE", state->cmpop_type, NULL, 0,
  1691. "GtE");
  1692. if (!state->GtE_type) return 0;
  1693. state->GtE_singleton = PyType_GenericNew((PyTypeObject *)state->GtE_type,
  1694. NULL, NULL);
  1695. if (!state->GtE_singleton) return 0;
  1696. state->Is_type = make_type(state, "Is", state->cmpop_type, NULL, 0,
  1697. "Is");
  1698. if (!state->Is_type) return 0;
  1699. state->Is_singleton = PyType_GenericNew((PyTypeObject *)state->Is_type,
  1700. NULL, NULL);
  1701. if (!state->Is_singleton) return 0;
  1702. state->IsNot_type = make_type(state, "IsNot", state->cmpop_type, NULL, 0,
  1703. "IsNot");
  1704. if (!state->IsNot_type) return 0;
  1705. state->IsNot_singleton = PyType_GenericNew((PyTypeObject
  1706. *)state->IsNot_type, NULL, NULL);
  1707. if (!state->IsNot_singleton) return 0;
  1708. state->In_type = make_type(state, "In", state->cmpop_type, NULL, 0,
  1709. "In");
  1710. if (!state->In_type) return 0;
  1711. state->In_singleton = PyType_GenericNew((PyTypeObject *)state->In_type,
  1712. NULL, NULL);
  1713. if (!state->In_singleton) return 0;
  1714. state->NotIn_type = make_type(state, "NotIn", state->cmpop_type, NULL, 0,
  1715. "NotIn");
  1716. if (!state->NotIn_type) return 0;
  1717. state->NotIn_singleton = PyType_GenericNew((PyTypeObject
  1718. *)state->NotIn_type, NULL, NULL);
  1719. if (!state->NotIn_singleton) return 0;
  1720. state->comprehension_type = make_type(state, "comprehension",
  1721. state->AST_type,
  1722. comprehension_fields, 4,
  1723. "comprehension(expr target, expr iter, expr* ifs, int is_async)");
  1724. if (!state->comprehension_type) return 0;
  1725. if (!add_attributes(state, state->comprehension_type, NULL, 0)) return 0;
  1726. state->excepthandler_type = make_type(state, "excepthandler",
  1727. state->AST_type, NULL, 0,
  1728. "excepthandler = ExceptHandler(expr? type, identifier? name, stmt* body)");
  1729. if (!state->excepthandler_type) return 0;
  1730. if (!add_attributes(state, state->excepthandler_type,
  1731. excepthandler_attributes, 4)) return 0;
  1732. if (PyObject_SetAttr(state->excepthandler_type, state->end_lineno, Py_None)
  1733. == -1)
  1734. return 0;
  1735. if (PyObject_SetAttr(state->excepthandler_type, state->end_col_offset,
  1736. Py_None) == -1)
  1737. return 0;
  1738. state->ExceptHandler_type = make_type(state, "ExceptHandler",
  1739. state->excepthandler_type,
  1740. ExceptHandler_fields, 3,
  1741. "ExceptHandler(expr? type, identifier? name, stmt* body)");
  1742. if (!state->ExceptHandler_type) return 0;
  1743. if (PyObject_SetAttr(state->ExceptHandler_type, state->type, Py_None) == -1)
  1744. return 0;
  1745. if (PyObject_SetAttr(state->ExceptHandler_type, state->name, Py_None) == -1)
  1746. return 0;
  1747. state->arguments_type = make_type(state, "arguments", state->AST_type,
  1748. arguments_fields, 7,
  1749. "arguments(arg* posonlyargs, arg* args, arg? vararg, arg* kwonlyargs, expr* kw_defaults, arg? kwarg, expr* defaults)");
  1750. if (!state->arguments_type) return 0;
  1751. if (!add_attributes(state, state->arguments_type, NULL, 0)) return 0;
  1752. if (PyObject_SetAttr(state->arguments_type, state->vararg, Py_None) == -1)
  1753. return 0;
  1754. if (PyObject_SetAttr(state->arguments_type, state->kwarg, Py_None) == -1)
  1755. return 0;
  1756. state->arg_type = make_type(state, "arg", state->AST_type, arg_fields, 3,
  1757. "arg(identifier arg, expr? annotation, string? type_comment)");
  1758. if (!state->arg_type) return 0;
  1759. if (!add_attributes(state, state->arg_type, arg_attributes, 4)) return 0;
  1760. if (PyObject_SetAttr(state->arg_type, state->annotation, Py_None) == -1)
  1761. return 0;
  1762. if (PyObject_SetAttr(state->arg_type, state->type_comment, Py_None) == -1)
  1763. return 0;
  1764. if (PyObject_SetAttr(state->arg_type, state->end_lineno, Py_None) == -1)
  1765. return 0;
  1766. if (PyObject_SetAttr(state->arg_type, state->end_col_offset, Py_None) == -1)
  1767. return 0;
  1768. state->keyword_type = make_type(state, "keyword", state->AST_type,
  1769. keyword_fields, 2,
  1770. "keyword(identifier? arg, expr value)");
  1771. if (!state->keyword_type) return 0;
  1772. if (!add_attributes(state, state->keyword_type, keyword_attributes, 4))
  1773. return 0;
  1774. if (PyObject_SetAttr(state->keyword_type, state->arg, Py_None) == -1)
  1775. return 0;
  1776. if (PyObject_SetAttr(state->keyword_type, state->end_lineno, Py_None) == -1)
  1777. return 0;
  1778. if (PyObject_SetAttr(state->keyword_type, state->end_col_offset, Py_None)
  1779. == -1)
  1780. return 0;
  1781. state->alias_type = make_type(state, "alias", state->AST_type,
  1782. alias_fields, 2,
  1783. "alias(identifier name, identifier? asname)");
  1784. if (!state->alias_type) return 0;
  1785. if (!add_attributes(state, state->alias_type, alias_attributes, 4)) return
  1786. 0;
  1787. if (PyObject_SetAttr(state->alias_type, state->asname, Py_None) == -1)
  1788. return 0;
  1789. if (PyObject_SetAttr(state->alias_type, state->end_lineno, Py_None) == -1)
  1790. return 0;
  1791. if (PyObject_SetAttr(state->alias_type, state->end_col_offset, Py_None) ==
  1792. -1)
  1793. return 0;
  1794. state->withitem_type = make_type(state, "withitem", state->AST_type,
  1795. withitem_fields, 2,
  1796. "withitem(expr context_expr, expr? optional_vars)");
  1797. if (!state->withitem_type) return 0;
  1798. if (!add_attributes(state, state->withitem_type, NULL, 0)) return 0;
  1799. if (PyObject_SetAttr(state->withitem_type, state->optional_vars, Py_None)
  1800. == -1)
  1801. return 0;
  1802. state->match_case_type = make_type(state, "match_case", state->AST_type,
  1803. match_case_fields, 3,
  1804. "match_case(pattern pattern, expr? guard, stmt* body)");
  1805. if (!state->match_case_type) return 0;
  1806. if (!add_attributes(state, state->match_case_type, NULL, 0)) return 0;
  1807. if (PyObject_SetAttr(state->match_case_type, state->guard, Py_None) == -1)
  1808. return 0;
  1809. state->pattern_type = make_type(state, "pattern", state->AST_type, NULL, 0,
  1810. "pattern = MatchValue(expr value)\n"
  1811. " | MatchSingleton(constant value)\n"
  1812. " | MatchSequence(pattern* patterns)\n"
  1813. " | MatchMapping(expr* keys, pattern* patterns, identifier? rest)\n"
  1814. " | MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)\n"
  1815. " | MatchStar(identifier? name)\n"
  1816. " | MatchAs(pattern? pattern, identifier? name)\n"
  1817. " | MatchOr(pattern* patterns)");
  1818. if (!state->pattern_type) return 0;
  1819. if (!add_attributes(state, state->pattern_type, pattern_attributes, 4))
  1820. return 0;
  1821. state->MatchValue_type = make_type(state, "MatchValue",
  1822. state->pattern_type, MatchValue_fields,
  1823. 1,
  1824. "MatchValue(expr value)");
  1825. if (!state->MatchValue_type) return 0;
  1826. state->MatchSingleton_type = make_type(state, "MatchSingleton",
  1827. state->pattern_type,
  1828. MatchSingleton_fields, 1,
  1829. "MatchSingleton(constant value)");
  1830. if (!state->MatchSingleton_type) return 0;
  1831. state->MatchSequence_type = make_type(state, "MatchSequence",
  1832. state->pattern_type,
  1833. MatchSequence_fields, 1,
  1834. "MatchSequence(pattern* patterns)");
  1835. if (!state->MatchSequence_type) return 0;
  1836. state->MatchMapping_type = make_type(state, "MatchMapping",
  1837. state->pattern_type,
  1838. MatchMapping_fields, 3,
  1839. "MatchMapping(expr* keys, pattern* patterns, identifier? rest)");
  1840. if (!state->MatchMapping_type) return 0;
  1841. if (PyObject_SetAttr(state->MatchMapping_type, state->rest, Py_None) == -1)
  1842. return 0;
  1843. state->MatchClass_type = make_type(state, "MatchClass",
  1844. state->pattern_type, MatchClass_fields,
  1845. 4,
  1846. "MatchClass(expr cls, pattern* patterns, identifier* kwd_attrs, pattern* kwd_patterns)");
  1847. if (!state->MatchClass_type) return 0;
  1848. state->MatchStar_type = make_type(state, "MatchStar", state->pattern_type,
  1849. MatchStar_fields, 1,
  1850. "MatchStar(identifier? name)");
  1851. if (!state->MatchStar_type) return 0;
  1852. if (PyObject_SetAttr(state->MatchStar_type, state->name, Py_None) == -1)
  1853. return 0;
  1854. state->MatchAs_type = make_type(state, "MatchAs", state->pattern_type,
  1855. MatchAs_fields, 2,
  1856. "MatchAs(pattern? pattern, identifier? name)");
  1857. if (!state->MatchAs_type) return 0;
  1858. if (PyObject_SetAttr(state->MatchAs_type, state->pattern, Py_None) == -1)
  1859. return 0;
  1860. if (PyObject_SetAttr(state->MatchAs_type, state->name, Py_None) == -1)
  1861. return 0;
  1862. state->MatchOr_type = make_type(state, "MatchOr", state->pattern_type,
  1863. MatchOr_fields, 1,
  1864. "MatchOr(pattern* patterns)");
  1865. if (!state->MatchOr_type) return 0;
  1866. state->type_ignore_type = make_type(state, "type_ignore", state->AST_type,
  1867. NULL, 0,
  1868. "type_ignore = TypeIgnore(int lineno, string tag)");
  1869. if (!state->type_ignore_type) return 0;
  1870. if (!add_attributes(state, state->type_ignore_type, NULL, 0)) return 0;
  1871. state->TypeIgnore_type = make_type(state, "TypeIgnore",
  1872. state->type_ignore_type,
  1873. TypeIgnore_fields, 2,
  1874. "TypeIgnore(int lineno, string tag)");
  1875. if (!state->TypeIgnore_type) return 0;
  1876. state->type_param_type = make_type(state, "type_param", state->AST_type,
  1877. NULL, 0,
  1878. "type_param = TypeVar(identifier name, expr? bound)\n"
  1879. " | ParamSpec(identifier name)\n"
  1880. " | TypeVarTuple(identifier name)");
  1881. if (!state->type_param_type) return 0;
  1882. if (!add_attributes(state, state->type_param_type, type_param_attributes,
  1883. 4)) return 0;
  1884. state->TypeVar_type = make_type(state, "TypeVar", state->type_param_type,
  1885. TypeVar_fields, 2,
  1886. "TypeVar(identifier name, expr? bound)");
  1887. if (!state->TypeVar_type) return 0;
  1888. if (PyObject_SetAttr(state->TypeVar_type, state->bound, Py_None) == -1)
  1889. return 0;
  1890. state->ParamSpec_type = make_type(state, "ParamSpec",
  1891. state->type_param_type, ParamSpec_fields,
  1892. 1,
  1893. "ParamSpec(identifier name)");
  1894. if (!state->ParamSpec_type) return 0;
  1895. state->TypeVarTuple_type = make_type(state, "TypeVarTuple",
  1896. state->type_param_type,
  1897. TypeVarTuple_fields, 1,
  1898. "TypeVarTuple(identifier name)");
  1899. if (!state->TypeVarTuple_type) return 0;
  1900. state->initialized = 1;
  1901. return 1;
  1902. }
  1903. static int obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out,
  1904. PyArena* arena);
  1905. static int obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out,
  1906. PyArena* arena);
  1907. static int obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out,
  1908. PyArena* arena);
  1909. static int obj2ast_expr_context(struct ast_state *state, PyObject* obj,
  1910. expr_context_ty* out, PyArena* arena);
  1911. static int obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty*
  1912. out, PyArena* arena);
  1913. static int obj2ast_operator(struct ast_state *state, PyObject* obj,
  1914. operator_ty* out, PyArena* arena);
  1915. static int obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty*
  1916. out, PyArena* arena);
  1917. static int obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out,
  1918. PyArena* arena);
  1919. static int obj2ast_comprehension(struct ast_state *state, PyObject* obj,
  1920. comprehension_ty* out, PyArena* arena);
  1921. static int obj2ast_excepthandler(struct ast_state *state, PyObject* obj,
  1922. excepthandler_ty* out, PyArena* arena);
  1923. static int obj2ast_arguments(struct ast_state *state, PyObject* obj,
  1924. arguments_ty* out, PyArena* arena);
  1925. static int obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out,
  1926. PyArena* arena);
  1927. static int obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty*
  1928. out, PyArena* arena);
  1929. static int obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out,
  1930. PyArena* arena);
  1931. static int obj2ast_withitem(struct ast_state *state, PyObject* obj,
  1932. withitem_ty* out, PyArena* arena);
  1933. static int obj2ast_match_case(struct ast_state *state, PyObject* obj,
  1934. match_case_ty* out, PyArena* arena);
  1935. static int obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty*
  1936. out, PyArena* arena);
  1937. static int obj2ast_type_ignore(struct ast_state *state, PyObject* obj,
  1938. type_ignore_ty* out, PyArena* arena);
  1939. static int obj2ast_type_param(struct ast_state *state, PyObject* obj,
  1940. type_param_ty* out, PyArena* arena);
  1941. mod_ty
  1942. _PyAST_Module(asdl_stmt_seq * body, asdl_type_ignore_seq * type_ignores,
  1943. PyArena *arena)
  1944. {
  1945. mod_ty p;
  1946. p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
  1947. if (!p)
  1948. return NULL;
  1949. p->kind = Module_kind;
  1950. p->v.Module.body = body;
  1951. p->v.Module.type_ignores = type_ignores;
  1952. return p;
  1953. }
  1954. mod_ty
  1955. _PyAST_Interactive(asdl_stmt_seq * body, PyArena *arena)
  1956. {
  1957. mod_ty p;
  1958. p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
  1959. if (!p)
  1960. return NULL;
  1961. p->kind = Interactive_kind;
  1962. p->v.Interactive.body = body;
  1963. return p;
  1964. }
  1965. mod_ty
  1966. _PyAST_Expression(expr_ty body, PyArena *arena)
  1967. {
  1968. mod_ty p;
  1969. if (!body) {
  1970. PyErr_SetString(PyExc_ValueError,
  1971. "field 'body' is required for Expression");
  1972. return NULL;
  1973. }
  1974. p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
  1975. if (!p)
  1976. return NULL;
  1977. p->kind = Expression_kind;
  1978. p->v.Expression.body = body;
  1979. return p;
  1980. }
  1981. mod_ty
  1982. _PyAST_FunctionType(asdl_expr_seq * argtypes, expr_ty returns, PyArena *arena)
  1983. {
  1984. mod_ty p;
  1985. if (!returns) {
  1986. PyErr_SetString(PyExc_ValueError,
  1987. "field 'returns' is required for FunctionType");
  1988. return NULL;
  1989. }
  1990. p = (mod_ty)_PyArena_Malloc(arena, sizeof(*p));
  1991. if (!p)
  1992. return NULL;
  1993. p->kind = FunctionType_kind;
  1994. p->v.FunctionType.argtypes = argtypes;
  1995. p->v.FunctionType.returns = returns;
  1996. return p;
  1997. }
  1998. stmt_ty
  1999. _PyAST_FunctionDef(identifier name, arguments_ty args, asdl_stmt_seq * body,
  2000. asdl_expr_seq * decorator_list, expr_ty returns, string
  2001. type_comment, asdl_type_param_seq * type_params, int lineno,
  2002. int col_offset, int end_lineno, int end_col_offset, PyArena
  2003. *arena)
  2004. {
  2005. stmt_ty p;
  2006. if (!name) {
  2007. PyErr_SetString(PyExc_ValueError,
  2008. "field 'name' is required for FunctionDef");
  2009. return NULL;
  2010. }
  2011. if (!args) {
  2012. PyErr_SetString(PyExc_ValueError,
  2013. "field 'args' is required for FunctionDef");
  2014. return NULL;
  2015. }
  2016. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2017. if (!p)
  2018. return NULL;
  2019. p->kind = FunctionDef_kind;
  2020. p->v.FunctionDef.name = name;
  2021. p->v.FunctionDef.args = args;
  2022. p->v.FunctionDef.body = body;
  2023. p->v.FunctionDef.decorator_list = decorator_list;
  2024. p->v.FunctionDef.returns = returns;
  2025. p->v.FunctionDef.type_comment = type_comment;
  2026. p->v.FunctionDef.type_params = type_params;
  2027. p->lineno = lineno;
  2028. p->col_offset = col_offset;
  2029. p->end_lineno = end_lineno;
  2030. p->end_col_offset = end_col_offset;
  2031. return p;
  2032. }
  2033. stmt_ty
  2034. _PyAST_AsyncFunctionDef(identifier name, arguments_ty args, asdl_stmt_seq *
  2035. body, asdl_expr_seq * decorator_list, expr_ty returns,
  2036. string type_comment, asdl_type_param_seq * type_params,
  2037. int lineno, int col_offset, int end_lineno, int
  2038. end_col_offset, PyArena *arena)
  2039. {
  2040. stmt_ty p;
  2041. if (!name) {
  2042. PyErr_SetString(PyExc_ValueError,
  2043. "field 'name' is required for AsyncFunctionDef");
  2044. return NULL;
  2045. }
  2046. if (!args) {
  2047. PyErr_SetString(PyExc_ValueError,
  2048. "field 'args' is required for AsyncFunctionDef");
  2049. return NULL;
  2050. }
  2051. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2052. if (!p)
  2053. return NULL;
  2054. p->kind = AsyncFunctionDef_kind;
  2055. p->v.AsyncFunctionDef.name = name;
  2056. p->v.AsyncFunctionDef.args = args;
  2057. p->v.AsyncFunctionDef.body = body;
  2058. p->v.AsyncFunctionDef.decorator_list = decorator_list;
  2059. p->v.AsyncFunctionDef.returns = returns;
  2060. p->v.AsyncFunctionDef.type_comment = type_comment;
  2061. p->v.AsyncFunctionDef.type_params = type_params;
  2062. p->lineno = lineno;
  2063. p->col_offset = col_offset;
  2064. p->end_lineno = end_lineno;
  2065. p->end_col_offset = end_col_offset;
  2066. return p;
  2067. }
  2068. stmt_ty
  2069. _PyAST_ClassDef(identifier name, asdl_expr_seq * bases, asdl_keyword_seq *
  2070. keywords, asdl_stmt_seq * body, asdl_expr_seq * decorator_list,
  2071. asdl_type_param_seq * type_params, int lineno, int col_offset,
  2072. int end_lineno, int end_col_offset, PyArena *arena)
  2073. {
  2074. stmt_ty p;
  2075. if (!name) {
  2076. PyErr_SetString(PyExc_ValueError,
  2077. "field 'name' is required for ClassDef");
  2078. return NULL;
  2079. }
  2080. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2081. if (!p)
  2082. return NULL;
  2083. p->kind = ClassDef_kind;
  2084. p->v.ClassDef.name = name;
  2085. p->v.ClassDef.bases = bases;
  2086. p->v.ClassDef.keywords = keywords;
  2087. p->v.ClassDef.body = body;
  2088. p->v.ClassDef.decorator_list = decorator_list;
  2089. p->v.ClassDef.type_params = type_params;
  2090. p->lineno = lineno;
  2091. p->col_offset = col_offset;
  2092. p->end_lineno = end_lineno;
  2093. p->end_col_offset = end_col_offset;
  2094. return p;
  2095. }
  2096. stmt_ty
  2097. _PyAST_Return(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2098. end_col_offset, PyArena *arena)
  2099. {
  2100. stmt_ty p;
  2101. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2102. if (!p)
  2103. return NULL;
  2104. p->kind = Return_kind;
  2105. p->v.Return.value = value;
  2106. p->lineno = lineno;
  2107. p->col_offset = col_offset;
  2108. p->end_lineno = end_lineno;
  2109. p->end_col_offset = end_col_offset;
  2110. return p;
  2111. }
  2112. stmt_ty
  2113. _PyAST_Delete(asdl_expr_seq * targets, int lineno, int col_offset, int
  2114. end_lineno, int end_col_offset, PyArena *arena)
  2115. {
  2116. stmt_ty p;
  2117. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2118. if (!p)
  2119. return NULL;
  2120. p->kind = Delete_kind;
  2121. p->v.Delete.targets = targets;
  2122. p->lineno = lineno;
  2123. p->col_offset = col_offset;
  2124. p->end_lineno = end_lineno;
  2125. p->end_col_offset = end_col_offset;
  2126. return p;
  2127. }
  2128. stmt_ty
  2129. _PyAST_Assign(asdl_expr_seq * targets, expr_ty value, string type_comment, int
  2130. lineno, int col_offset, int end_lineno, int end_col_offset,
  2131. PyArena *arena)
  2132. {
  2133. stmt_ty p;
  2134. if (!value) {
  2135. PyErr_SetString(PyExc_ValueError,
  2136. "field 'value' is required for Assign");
  2137. return NULL;
  2138. }
  2139. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2140. if (!p)
  2141. return NULL;
  2142. p->kind = Assign_kind;
  2143. p->v.Assign.targets = targets;
  2144. p->v.Assign.value = value;
  2145. p->v.Assign.type_comment = type_comment;
  2146. p->lineno = lineno;
  2147. p->col_offset = col_offset;
  2148. p->end_lineno = end_lineno;
  2149. p->end_col_offset = end_col_offset;
  2150. return p;
  2151. }
  2152. stmt_ty
  2153. _PyAST_TypeAlias(expr_ty name, asdl_type_param_seq * type_params, expr_ty
  2154. value, int lineno, int col_offset, int end_lineno, int
  2155. end_col_offset, PyArena *arena)
  2156. {
  2157. stmt_ty p;
  2158. if (!name) {
  2159. PyErr_SetString(PyExc_ValueError,
  2160. "field 'name' is required for TypeAlias");
  2161. return NULL;
  2162. }
  2163. if (!value) {
  2164. PyErr_SetString(PyExc_ValueError,
  2165. "field 'value' is required for TypeAlias");
  2166. return NULL;
  2167. }
  2168. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2169. if (!p)
  2170. return NULL;
  2171. p->kind = TypeAlias_kind;
  2172. p->v.TypeAlias.name = name;
  2173. p->v.TypeAlias.type_params = type_params;
  2174. p->v.TypeAlias.value = value;
  2175. p->lineno = lineno;
  2176. p->col_offset = col_offset;
  2177. p->end_lineno = end_lineno;
  2178. p->end_col_offset = end_col_offset;
  2179. return p;
  2180. }
  2181. stmt_ty
  2182. _PyAST_AugAssign(expr_ty target, operator_ty op, expr_ty value, int lineno, int
  2183. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2184. {
  2185. stmt_ty p;
  2186. if (!target) {
  2187. PyErr_SetString(PyExc_ValueError,
  2188. "field 'target' is required for AugAssign");
  2189. return NULL;
  2190. }
  2191. if (!op) {
  2192. PyErr_SetString(PyExc_ValueError,
  2193. "field 'op' is required for AugAssign");
  2194. return NULL;
  2195. }
  2196. if (!value) {
  2197. PyErr_SetString(PyExc_ValueError,
  2198. "field 'value' is required for AugAssign");
  2199. return NULL;
  2200. }
  2201. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2202. if (!p)
  2203. return NULL;
  2204. p->kind = AugAssign_kind;
  2205. p->v.AugAssign.target = target;
  2206. p->v.AugAssign.op = op;
  2207. p->v.AugAssign.value = value;
  2208. p->lineno = lineno;
  2209. p->col_offset = col_offset;
  2210. p->end_lineno = end_lineno;
  2211. p->end_col_offset = end_col_offset;
  2212. return p;
  2213. }
  2214. stmt_ty
  2215. _PyAST_AnnAssign(expr_ty target, expr_ty annotation, expr_ty value, int simple,
  2216. int lineno, int col_offset, int end_lineno, int
  2217. end_col_offset, PyArena *arena)
  2218. {
  2219. stmt_ty p;
  2220. if (!target) {
  2221. PyErr_SetString(PyExc_ValueError,
  2222. "field 'target' is required for AnnAssign");
  2223. return NULL;
  2224. }
  2225. if (!annotation) {
  2226. PyErr_SetString(PyExc_ValueError,
  2227. "field 'annotation' is required for AnnAssign");
  2228. return NULL;
  2229. }
  2230. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2231. if (!p)
  2232. return NULL;
  2233. p->kind = AnnAssign_kind;
  2234. p->v.AnnAssign.target = target;
  2235. p->v.AnnAssign.annotation = annotation;
  2236. p->v.AnnAssign.value = value;
  2237. p->v.AnnAssign.simple = simple;
  2238. p->lineno = lineno;
  2239. p->col_offset = col_offset;
  2240. p->end_lineno = end_lineno;
  2241. p->end_col_offset = end_col_offset;
  2242. return p;
  2243. }
  2244. stmt_ty
  2245. _PyAST_For(expr_ty target, expr_ty iter, asdl_stmt_seq * body, asdl_stmt_seq *
  2246. orelse, string type_comment, int lineno, int col_offset, int
  2247. end_lineno, int end_col_offset, PyArena *arena)
  2248. {
  2249. stmt_ty p;
  2250. if (!target) {
  2251. PyErr_SetString(PyExc_ValueError,
  2252. "field 'target' is required for For");
  2253. return NULL;
  2254. }
  2255. if (!iter) {
  2256. PyErr_SetString(PyExc_ValueError,
  2257. "field 'iter' is required for For");
  2258. return NULL;
  2259. }
  2260. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2261. if (!p)
  2262. return NULL;
  2263. p->kind = For_kind;
  2264. p->v.For.target = target;
  2265. p->v.For.iter = iter;
  2266. p->v.For.body = body;
  2267. p->v.For.orelse = orelse;
  2268. p->v.For.type_comment = type_comment;
  2269. p->lineno = lineno;
  2270. p->col_offset = col_offset;
  2271. p->end_lineno = end_lineno;
  2272. p->end_col_offset = end_col_offset;
  2273. return p;
  2274. }
  2275. stmt_ty
  2276. _PyAST_AsyncFor(expr_ty target, expr_ty iter, asdl_stmt_seq * body,
  2277. asdl_stmt_seq * orelse, string type_comment, int lineno, int
  2278. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2279. {
  2280. stmt_ty p;
  2281. if (!target) {
  2282. PyErr_SetString(PyExc_ValueError,
  2283. "field 'target' is required for AsyncFor");
  2284. return NULL;
  2285. }
  2286. if (!iter) {
  2287. PyErr_SetString(PyExc_ValueError,
  2288. "field 'iter' is required for AsyncFor");
  2289. return NULL;
  2290. }
  2291. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2292. if (!p)
  2293. return NULL;
  2294. p->kind = AsyncFor_kind;
  2295. p->v.AsyncFor.target = target;
  2296. p->v.AsyncFor.iter = iter;
  2297. p->v.AsyncFor.body = body;
  2298. p->v.AsyncFor.orelse = orelse;
  2299. p->v.AsyncFor.type_comment = type_comment;
  2300. p->lineno = lineno;
  2301. p->col_offset = col_offset;
  2302. p->end_lineno = end_lineno;
  2303. p->end_col_offset = end_col_offset;
  2304. return p;
  2305. }
  2306. stmt_ty
  2307. _PyAST_While(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
  2308. lineno, int col_offset, int end_lineno, int end_col_offset,
  2309. PyArena *arena)
  2310. {
  2311. stmt_ty p;
  2312. if (!test) {
  2313. PyErr_SetString(PyExc_ValueError,
  2314. "field 'test' is required for While");
  2315. return NULL;
  2316. }
  2317. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2318. if (!p)
  2319. return NULL;
  2320. p->kind = While_kind;
  2321. p->v.While.test = test;
  2322. p->v.While.body = body;
  2323. p->v.While.orelse = orelse;
  2324. p->lineno = lineno;
  2325. p->col_offset = col_offset;
  2326. p->end_lineno = end_lineno;
  2327. p->end_col_offset = end_col_offset;
  2328. return p;
  2329. }
  2330. stmt_ty
  2331. _PyAST_If(expr_ty test, asdl_stmt_seq * body, asdl_stmt_seq * orelse, int
  2332. lineno, int col_offset, int end_lineno, int end_col_offset, PyArena
  2333. *arena)
  2334. {
  2335. stmt_ty p;
  2336. if (!test) {
  2337. PyErr_SetString(PyExc_ValueError,
  2338. "field 'test' is required for If");
  2339. return NULL;
  2340. }
  2341. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2342. if (!p)
  2343. return NULL;
  2344. p->kind = If_kind;
  2345. p->v.If.test = test;
  2346. p->v.If.body = body;
  2347. p->v.If.orelse = orelse;
  2348. p->lineno = lineno;
  2349. p->col_offset = col_offset;
  2350. p->end_lineno = end_lineno;
  2351. p->end_col_offset = end_col_offset;
  2352. return p;
  2353. }
  2354. stmt_ty
  2355. _PyAST_With(asdl_withitem_seq * items, asdl_stmt_seq * body, string
  2356. type_comment, int lineno, int col_offset, int end_lineno, int
  2357. end_col_offset, PyArena *arena)
  2358. {
  2359. stmt_ty p;
  2360. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2361. if (!p)
  2362. return NULL;
  2363. p->kind = With_kind;
  2364. p->v.With.items = items;
  2365. p->v.With.body = body;
  2366. p->v.With.type_comment = type_comment;
  2367. p->lineno = lineno;
  2368. p->col_offset = col_offset;
  2369. p->end_lineno = end_lineno;
  2370. p->end_col_offset = end_col_offset;
  2371. return p;
  2372. }
  2373. stmt_ty
  2374. _PyAST_AsyncWith(asdl_withitem_seq * items, asdl_stmt_seq * body, string
  2375. type_comment, int lineno, int col_offset, int end_lineno, int
  2376. end_col_offset, PyArena *arena)
  2377. {
  2378. stmt_ty p;
  2379. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2380. if (!p)
  2381. return NULL;
  2382. p->kind = AsyncWith_kind;
  2383. p->v.AsyncWith.items = items;
  2384. p->v.AsyncWith.body = body;
  2385. p->v.AsyncWith.type_comment = type_comment;
  2386. p->lineno = lineno;
  2387. p->col_offset = col_offset;
  2388. p->end_lineno = end_lineno;
  2389. p->end_col_offset = end_col_offset;
  2390. return p;
  2391. }
  2392. stmt_ty
  2393. _PyAST_Match(expr_ty subject, asdl_match_case_seq * cases, int lineno, int
  2394. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2395. {
  2396. stmt_ty p;
  2397. if (!subject) {
  2398. PyErr_SetString(PyExc_ValueError,
  2399. "field 'subject' is required for Match");
  2400. return NULL;
  2401. }
  2402. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2403. if (!p)
  2404. return NULL;
  2405. p->kind = Match_kind;
  2406. p->v.Match.subject = subject;
  2407. p->v.Match.cases = cases;
  2408. p->lineno = lineno;
  2409. p->col_offset = col_offset;
  2410. p->end_lineno = end_lineno;
  2411. p->end_col_offset = end_col_offset;
  2412. return p;
  2413. }
  2414. stmt_ty
  2415. _PyAST_Raise(expr_ty exc, expr_ty cause, int lineno, int col_offset, int
  2416. end_lineno, int end_col_offset, PyArena *arena)
  2417. {
  2418. stmt_ty p;
  2419. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2420. if (!p)
  2421. return NULL;
  2422. p->kind = Raise_kind;
  2423. p->v.Raise.exc = exc;
  2424. p->v.Raise.cause = cause;
  2425. p->lineno = lineno;
  2426. p->col_offset = col_offset;
  2427. p->end_lineno = end_lineno;
  2428. p->end_col_offset = end_col_offset;
  2429. return p;
  2430. }
  2431. stmt_ty
  2432. _PyAST_Try(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
  2433. asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno, int
  2434. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2435. {
  2436. stmt_ty p;
  2437. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2438. if (!p)
  2439. return NULL;
  2440. p->kind = Try_kind;
  2441. p->v.Try.body = body;
  2442. p->v.Try.handlers = handlers;
  2443. p->v.Try.orelse = orelse;
  2444. p->v.Try.finalbody = finalbody;
  2445. p->lineno = lineno;
  2446. p->col_offset = col_offset;
  2447. p->end_lineno = end_lineno;
  2448. p->end_col_offset = end_col_offset;
  2449. return p;
  2450. }
  2451. stmt_ty
  2452. _PyAST_TryStar(asdl_stmt_seq * body, asdl_excepthandler_seq * handlers,
  2453. asdl_stmt_seq * orelse, asdl_stmt_seq * finalbody, int lineno,
  2454. int col_offset, int end_lineno, int end_col_offset, PyArena
  2455. *arena)
  2456. {
  2457. stmt_ty p;
  2458. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2459. if (!p)
  2460. return NULL;
  2461. p->kind = TryStar_kind;
  2462. p->v.TryStar.body = body;
  2463. p->v.TryStar.handlers = handlers;
  2464. p->v.TryStar.orelse = orelse;
  2465. p->v.TryStar.finalbody = finalbody;
  2466. p->lineno = lineno;
  2467. p->col_offset = col_offset;
  2468. p->end_lineno = end_lineno;
  2469. p->end_col_offset = end_col_offset;
  2470. return p;
  2471. }
  2472. stmt_ty
  2473. _PyAST_Assert(expr_ty test, expr_ty msg, int lineno, int col_offset, int
  2474. end_lineno, int end_col_offset, PyArena *arena)
  2475. {
  2476. stmt_ty p;
  2477. if (!test) {
  2478. PyErr_SetString(PyExc_ValueError,
  2479. "field 'test' is required for Assert");
  2480. return NULL;
  2481. }
  2482. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2483. if (!p)
  2484. return NULL;
  2485. p->kind = Assert_kind;
  2486. p->v.Assert.test = test;
  2487. p->v.Assert.msg = msg;
  2488. p->lineno = lineno;
  2489. p->col_offset = col_offset;
  2490. p->end_lineno = end_lineno;
  2491. p->end_col_offset = end_col_offset;
  2492. return p;
  2493. }
  2494. stmt_ty
  2495. _PyAST_Import(asdl_alias_seq * names, int lineno, int col_offset, int
  2496. end_lineno, int end_col_offset, PyArena *arena)
  2497. {
  2498. stmt_ty p;
  2499. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2500. if (!p)
  2501. return NULL;
  2502. p->kind = Import_kind;
  2503. p->v.Import.names = names;
  2504. p->lineno = lineno;
  2505. p->col_offset = col_offset;
  2506. p->end_lineno = end_lineno;
  2507. p->end_col_offset = end_col_offset;
  2508. return p;
  2509. }
  2510. stmt_ty
  2511. _PyAST_ImportFrom(identifier module, asdl_alias_seq * names, int level, int
  2512. lineno, int col_offset, int end_lineno, int end_col_offset,
  2513. PyArena *arena)
  2514. {
  2515. stmt_ty p;
  2516. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2517. if (!p)
  2518. return NULL;
  2519. p->kind = ImportFrom_kind;
  2520. p->v.ImportFrom.module = module;
  2521. p->v.ImportFrom.names = names;
  2522. p->v.ImportFrom.level = level;
  2523. p->lineno = lineno;
  2524. p->col_offset = col_offset;
  2525. p->end_lineno = end_lineno;
  2526. p->end_col_offset = end_col_offset;
  2527. return p;
  2528. }
  2529. stmt_ty
  2530. _PyAST_Global(asdl_identifier_seq * names, int lineno, int col_offset, int
  2531. end_lineno, int end_col_offset, PyArena *arena)
  2532. {
  2533. stmt_ty p;
  2534. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2535. if (!p)
  2536. return NULL;
  2537. p->kind = Global_kind;
  2538. p->v.Global.names = names;
  2539. p->lineno = lineno;
  2540. p->col_offset = col_offset;
  2541. p->end_lineno = end_lineno;
  2542. p->end_col_offset = end_col_offset;
  2543. return p;
  2544. }
  2545. stmt_ty
  2546. _PyAST_Nonlocal(asdl_identifier_seq * names, int lineno, int col_offset, int
  2547. end_lineno, int end_col_offset, PyArena *arena)
  2548. {
  2549. stmt_ty p;
  2550. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2551. if (!p)
  2552. return NULL;
  2553. p->kind = Nonlocal_kind;
  2554. p->v.Nonlocal.names = names;
  2555. p->lineno = lineno;
  2556. p->col_offset = col_offset;
  2557. p->end_lineno = end_lineno;
  2558. p->end_col_offset = end_col_offset;
  2559. return p;
  2560. }
  2561. stmt_ty
  2562. _PyAST_Expr(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2563. end_col_offset, PyArena *arena)
  2564. {
  2565. stmt_ty p;
  2566. if (!value) {
  2567. PyErr_SetString(PyExc_ValueError,
  2568. "field 'value' is required for Expr");
  2569. return NULL;
  2570. }
  2571. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2572. if (!p)
  2573. return NULL;
  2574. p->kind = Expr_kind;
  2575. p->v.Expr.value = value;
  2576. p->lineno = lineno;
  2577. p->col_offset = col_offset;
  2578. p->end_lineno = end_lineno;
  2579. p->end_col_offset = end_col_offset;
  2580. return p;
  2581. }
  2582. stmt_ty
  2583. _PyAST_Pass(int lineno, int col_offset, int end_lineno, int end_col_offset,
  2584. PyArena *arena)
  2585. {
  2586. stmt_ty p;
  2587. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2588. if (!p)
  2589. return NULL;
  2590. p->kind = Pass_kind;
  2591. p->lineno = lineno;
  2592. p->col_offset = col_offset;
  2593. p->end_lineno = end_lineno;
  2594. p->end_col_offset = end_col_offset;
  2595. return p;
  2596. }
  2597. stmt_ty
  2598. _PyAST_Break(int lineno, int col_offset, int end_lineno, int end_col_offset,
  2599. PyArena *arena)
  2600. {
  2601. stmt_ty p;
  2602. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2603. if (!p)
  2604. return NULL;
  2605. p->kind = Break_kind;
  2606. p->lineno = lineno;
  2607. p->col_offset = col_offset;
  2608. p->end_lineno = end_lineno;
  2609. p->end_col_offset = end_col_offset;
  2610. return p;
  2611. }
  2612. stmt_ty
  2613. _PyAST_Continue(int lineno, int col_offset, int end_lineno, int end_col_offset,
  2614. PyArena *arena)
  2615. {
  2616. stmt_ty p;
  2617. p = (stmt_ty)_PyArena_Malloc(arena, sizeof(*p));
  2618. if (!p)
  2619. return NULL;
  2620. p->kind = Continue_kind;
  2621. p->lineno = lineno;
  2622. p->col_offset = col_offset;
  2623. p->end_lineno = end_lineno;
  2624. p->end_col_offset = end_col_offset;
  2625. return p;
  2626. }
  2627. expr_ty
  2628. _PyAST_BoolOp(boolop_ty op, asdl_expr_seq * values, int lineno, int col_offset,
  2629. int end_lineno, int end_col_offset, PyArena *arena)
  2630. {
  2631. expr_ty p;
  2632. if (!op) {
  2633. PyErr_SetString(PyExc_ValueError,
  2634. "field 'op' is required for BoolOp");
  2635. return NULL;
  2636. }
  2637. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2638. if (!p)
  2639. return NULL;
  2640. p->kind = BoolOp_kind;
  2641. p->v.BoolOp.op = op;
  2642. p->v.BoolOp.values = values;
  2643. p->lineno = lineno;
  2644. p->col_offset = col_offset;
  2645. p->end_lineno = end_lineno;
  2646. p->end_col_offset = end_col_offset;
  2647. return p;
  2648. }
  2649. expr_ty
  2650. _PyAST_NamedExpr(expr_ty target, expr_ty value, int lineno, int col_offset, int
  2651. end_lineno, int end_col_offset, PyArena *arena)
  2652. {
  2653. expr_ty p;
  2654. if (!target) {
  2655. PyErr_SetString(PyExc_ValueError,
  2656. "field 'target' is required for NamedExpr");
  2657. return NULL;
  2658. }
  2659. if (!value) {
  2660. PyErr_SetString(PyExc_ValueError,
  2661. "field 'value' is required for NamedExpr");
  2662. return NULL;
  2663. }
  2664. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2665. if (!p)
  2666. return NULL;
  2667. p->kind = NamedExpr_kind;
  2668. p->v.NamedExpr.target = target;
  2669. p->v.NamedExpr.value = value;
  2670. p->lineno = lineno;
  2671. p->col_offset = col_offset;
  2672. p->end_lineno = end_lineno;
  2673. p->end_col_offset = end_col_offset;
  2674. return p;
  2675. }
  2676. expr_ty
  2677. _PyAST_BinOp(expr_ty left, operator_ty op, expr_ty right, int lineno, int
  2678. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2679. {
  2680. expr_ty p;
  2681. if (!left) {
  2682. PyErr_SetString(PyExc_ValueError,
  2683. "field 'left' is required for BinOp");
  2684. return NULL;
  2685. }
  2686. if (!op) {
  2687. PyErr_SetString(PyExc_ValueError,
  2688. "field 'op' is required for BinOp");
  2689. return NULL;
  2690. }
  2691. if (!right) {
  2692. PyErr_SetString(PyExc_ValueError,
  2693. "field 'right' is required for BinOp");
  2694. return NULL;
  2695. }
  2696. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2697. if (!p)
  2698. return NULL;
  2699. p->kind = BinOp_kind;
  2700. p->v.BinOp.left = left;
  2701. p->v.BinOp.op = op;
  2702. p->v.BinOp.right = right;
  2703. p->lineno = lineno;
  2704. p->col_offset = col_offset;
  2705. p->end_lineno = end_lineno;
  2706. p->end_col_offset = end_col_offset;
  2707. return p;
  2708. }
  2709. expr_ty
  2710. _PyAST_UnaryOp(unaryop_ty op, expr_ty operand, int lineno, int col_offset, int
  2711. end_lineno, int end_col_offset, PyArena *arena)
  2712. {
  2713. expr_ty p;
  2714. if (!op) {
  2715. PyErr_SetString(PyExc_ValueError,
  2716. "field 'op' is required for UnaryOp");
  2717. return NULL;
  2718. }
  2719. if (!operand) {
  2720. PyErr_SetString(PyExc_ValueError,
  2721. "field 'operand' is required for UnaryOp");
  2722. return NULL;
  2723. }
  2724. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2725. if (!p)
  2726. return NULL;
  2727. p->kind = UnaryOp_kind;
  2728. p->v.UnaryOp.op = op;
  2729. p->v.UnaryOp.operand = operand;
  2730. p->lineno = lineno;
  2731. p->col_offset = col_offset;
  2732. p->end_lineno = end_lineno;
  2733. p->end_col_offset = end_col_offset;
  2734. return p;
  2735. }
  2736. expr_ty
  2737. _PyAST_Lambda(arguments_ty args, expr_ty body, int lineno, int col_offset, int
  2738. end_lineno, int end_col_offset, PyArena *arena)
  2739. {
  2740. expr_ty p;
  2741. if (!args) {
  2742. PyErr_SetString(PyExc_ValueError,
  2743. "field 'args' is required for Lambda");
  2744. return NULL;
  2745. }
  2746. if (!body) {
  2747. PyErr_SetString(PyExc_ValueError,
  2748. "field 'body' is required for Lambda");
  2749. return NULL;
  2750. }
  2751. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2752. if (!p)
  2753. return NULL;
  2754. p->kind = Lambda_kind;
  2755. p->v.Lambda.args = args;
  2756. p->v.Lambda.body = body;
  2757. p->lineno = lineno;
  2758. p->col_offset = col_offset;
  2759. p->end_lineno = end_lineno;
  2760. p->end_col_offset = end_col_offset;
  2761. return p;
  2762. }
  2763. expr_ty
  2764. _PyAST_IfExp(expr_ty test, expr_ty body, expr_ty orelse, int lineno, int
  2765. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2766. {
  2767. expr_ty p;
  2768. if (!test) {
  2769. PyErr_SetString(PyExc_ValueError,
  2770. "field 'test' is required for IfExp");
  2771. return NULL;
  2772. }
  2773. if (!body) {
  2774. PyErr_SetString(PyExc_ValueError,
  2775. "field 'body' is required for IfExp");
  2776. return NULL;
  2777. }
  2778. if (!orelse) {
  2779. PyErr_SetString(PyExc_ValueError,
  2780. "field 'orelse' is required for IfExp");
  2781. return NULL;
  2782. }
  2783. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2784. if (!p)
  2785. return NULL;
  2786. p->kind = IfExp_kind;
  2787. p->v.IfExp.test = test;
  2788. p->v.IfExp.body = body;
  2789. p->v.IfExp.orelse = orelse;
  2790. p->lineno = lineno;
  2791. p->col_offset = col_offset;
  2792. p->end_lineno = end_lineno;
  2793. p->end_col_offset = end_col_offset;
  2794. return p;
  2795. }
  2796. expr_ty
  2797. _PyAST_Dict(asdl_expr_seq * keys, asdl_expr_seq * values, int lineno, int
  2798. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  2799. {
  2800. expr_ty p;
  2801. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2802. if (!p)
  2803. return NULL;
  2804. p->kind = Dict_kind;
  2805. p->v.Dict.keys = keys;
  2806. p->v.Dict.values = values;
  2807. p->lineno = lineno;
  2808. p->col_offset = col_offset;
  2809. p->end_lineno = end_lineno;
  2810. p->end_col_offset = end_col_offset;
  2811. return p;
  2812. }
  2813. expr_ty
  2814. _PyAST_Set(asdl_expr_seq * elts, int lineno, int col_offset, int end_lineno,
  2815. int end_col_offset, PyArena *arena)
  2816. {
  2817. expr_ty p;
  2818. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2819. if (!p)
  2820. return NULL;
  2821. p->kind = Set_kind;
  2822. p->v.Set.elts = elts;
  2823. p->lineno = lineno;
  2824. p->col_offset = col_offset;
  2825. p->end_lineno = end_lineno;
  2826. p->end_col_offset = end_col_offset;
  2827. return p;
  2828. }
  2829. expr_ty
  2830. _PyAST_ListComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
  2831. int col_offset, int end_lineno, int end_col_offset, PyArena
  2832. *arena)
  2833. {
  2834. expr_ty p;
  2835. if (!elt) {
  2836. PyErr_SetString(PyExc_ValueError,
  2837. "field 'elt' is required for ListComp");
  2838. return NULL;
  2839. }
  2840. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2841. if (!p)
  2842. return NULL;
  2843. p->kind = ListComp_kind;
  2844. p->v.ListComp.elt = elt;
  2845. p->v.ListComp.generators = generators;
  2846. p->lineno = lineno;
  2847. p->col_offset = col_offset;
  2848. p->end_lineno = end_lineno;
  2849. p->end_col_offset = end_col_offset;
  2850. return p;
  2851. }
  2852. expr_ty
  2853. _PyAST_SetComp(expr_ty elt, asdl_comprehension_seq * generators, int lineno,
  2854. int col_offset, int end_lineno, int end_col_offset, PyArena
  2855. *arena)
  2856. {
  2857. expr_ty p;
  2858. if (!elt) {
  2859. PyErr_SetString(PyExc_ValueError,
  2860. "field 'elt' is required for SetComp");
  2861. return NULL;
  2862. }
  2863. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2864. if (!p)
  2865. return NULL;
  2866. p->kind = SetComp_kind;
  2867. p->v.SetComp.elt = elt;
  2868. p->v.SetComp.generators = generators;
  2869. p->lineno = lineno;
  2870. p->col_offset = col_offset;
  2871. p->end_lineno = end_lineno;
  2872. p->end_col_offset = end_col_offset;
  2873. return p;
  2874. }
  2875. expr_ty
  2876. _PyAST_DictComp(expr_ty key, expr_ty value, asdl_comprehension_seq *
  2877. generators, int lineno, int col_offset, int end_lineno, int
  2878. end_col_offset, PyArena *arena)
  2879. {
  2880. expr_ty p;
  2881. if (!key) {
  2882. PyErr_SetString(PyExc_ValueError,
  2883. "field 'key' is required for DictComp");
  2884. return NULL;
  2885. }
  2886. if (!value) {
  2887. PyErr_SetString(PyExc_ValueError,
  2888. "field 'value' is required for DictComp");
  2889. return NULL;
  2890. }
  2891. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2892. if (!p)
  2893. return NULL;
  2894. p->kind = DictComp_kind;
  2895. p->v.DictComp.key = key;
  2896. p->v.DictComp.value = value;
  2897. p->v.DictComp.generators = generators;
  2898. p->lineno = lineno;
  2899. p->col_offset = col_offset;
  2900. p->end_lineno = end_lineno;
  2901. p->end_col_offset = end_col_offset;
  2902. return p;
  2903. }
  2904. expr_ty
  2905. _PyAST_GeneratorExp(expr_ty elt, asdl_comprehension_seq * generators, int
  2906. lineno, int col_offset, int end_lineno, int end_col_offset,
  2907. PyArena *arena)
  2908. {
  2909. expr_ty p;
  2910. if (!elt) {
  2911. PyErr_SetString(PyExc_ValueError,
  2912. "field 'elt' is required for GeneratorExp");
  2913. return NULL;
  2914. }
  2915. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2916. if (!p)
  2917. return NULL;
  2918. p->kind = GeneratorExp_kind;
  2919. p->v.GeneratorExp.elt = elt;
  2920. p->v.GeneratorExp.generators = generators;
  2921. p->lineno = lineno;
  2922. p->col_offset = col_offset;
  2923. p->end_lineno = end_lineno;
  2924. p->end_col_offset = end_col_offset;
  2925. return p;
  2926. }
  2927. expr_ty
  2928. _PyAST_Await(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2929. end_col_offset, PyArena *arena)
  2930. {
  2931. expr_ty p;
  2932. if (!value) {
  2933. PyErr_SetString(PyExc_ValueError,
  2934. "field 'value' is required for Await");
  2935. return NULL;
  2936. }
  2937. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2938. if (!p)
  2939. return NULL;
  2940. p->kind = Await_kind;
  2941. p->v.Await.value = value;
  2942. p->lineno = lineno;
  2943. p->col_offset = col_offset;
  2944. p->end_lineno = end_lineno;
  2945. p->end_col_offset = end_col_offset;
  2946. return p;
  2947. }
  2948. expr_ty
  2949. _PyAST_Yield(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2950. end_col_offset, PyArena *arena)
  2951. {
  2952. expr_ty p;
  2953. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2954. if (!p)
  2955. return NULL;
  2956. p->kind = Yield_kind;
  2957. p->v.Yield.value = value;
  2958. p->lineno = lineno;
  2959. p->col_offset = col_offset;
  2960. p->end_lineno = end_lineno;
  2961. p->end_col_offset = end_col_offset;
  2962. return p;
  2963. }
  2964. expr_ty
  2965. _PyAST_YieldFrom(expr_ty value, int lineno, int col_offset, int end_lineno, int
  2966. end_col_offset, PyArena *arena)
  2967. {
  2968. expr_ty p;
  2969. if (!value) {
  2970. PyErr_SetString(PyExc_ValueError,
  2971. "field 'value' is required for YieldFrom");
  2972. return NULL;
  2973. }
  2974. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2975. if (!p)
  2976. return NULL;
  2977. p->kind = YieldFrom_kind;
  2978. p->v.YieldFrom.value = value;
  2979. p->lineno = lineno;
  2980. p->col_offset = col_offset;
  2981. p->end_lineno = end_lineno;
  2982. p->end_col_offset = end_col_offset;
  2983. return p;
  2984. }
  2985. expr_ty
  2986. _PyAST_Compare(expr_ty left, asdl_int_seq * ops, asdl_expr_seq * comparators,
  2987. int lineno, int col_offset, int end_lineno, int end_col_offset,
  2988. PyArena *arena)
  2989. {
  2990. expr_ty p;
  2991. if (!left) {
  2992. PyErr_SetString(PyExc_ValueError,
  2993. "field 'left' is required for Compare");
  2994. return NULL;
  2995. }
  2996. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  2997. if (!p)
  2998. return NULL;
  2999. p->kind = Compare_kind;
  3000. p->v.Compare.left = left;
  3001. p->v.Compare.ops = ops;
  3002. p->v.Compare.comparators = comparators;
  3003. p->lineno = lineno;
  3004. p->col_offset = col_offset;
  3005. p->end_lineno = end_lineno;
  3006. p->end_col_offset = end_col_offset;
  3007. return p;
  3008. }
  3009. expr_ty
  3010. _PyAST_Call(expr_ty func, asdl_expr_seq * args, asdl_keyword_seq * keywords,
  3011. int lineno, int col_offset, int end_lineno, int end_col_offset,
  3012. PyArena *arena)
  3013. {
  3014. expr_ty p;
  3015. if (!func) {
  3016. PyErr_SetString(PyExc_ValueError,
  3017. "field 'func' is required for Call");
  3018. return NULL;
  3019. }
  3020. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3021. if (!p)
  3022. return NULL;
  3023. p->kind = Call_kind;
  3024. p->v.Call.func = func;
  3025. p->v.Call.args = args;
  3026. p->v.Call.keywords = keywords;
  3027. p->lineno = lineno;
  3028. p->col_offset = col_offset;
  3029. p->end_lineno = end_lineno;
  3030. p->end_col_offset = end_col_offset;
  3031. return p;
  3032. }
  3033. expr_ty
  3034. _PyAST_FormattedValue(expr_ty value, int conversion, expr_ty format_spec, int
  3035. lineno, int col_offset, int end_lineno, int
  3036. end_col_offset, PyArena *arena)
  3037. {
  3038. expr_ty p;
  3039. if (!value) {
  3040. PyErr_SetString(PyExc_ValueError,
  3041. "field 'value' is required for FormattedValue");
  3042. return NULL;
  3043. }
  3044. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3045. if (!p)
  3046. return NULL;
  3047. p->kind = FormattedValue_kind;
  3048. p->v.FormattedValue.value = value;
  3049. p->v.FormattedValue.conversion = conversion;
  3050. p->v.FormattedValue.format_spec = format_spec;
  3051. p->lineno = lineno;
  3052. p->col_offset = col_offset;
  3053. p->end_lineno = end_lineno;
  3054. p->end_col_offset = end_col_offset;
  3055. return p;
  3056. }
  3057. expr_ty
  3058. _PyAST_JoinedStr(asdl_expr_seq * values, int lineno, int col_offset, int
  3059. end_lineno, int end_col_offset, PyArena *arena)
  3060. {
  3061. expr_ty p;
  3062. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3063. if (!p)
  3064. return NULL;
  3065. p->kind = JoinedStr_kind;
  3066. p->v.JoinedStr.values = values;
  3067. p->lineno = lineno;
  3068. p->col_offset = col_offset;
  3069. p->end_lineno = end_lineno;
  3070. p->end_col_offset = end_col_offset;
  3071. return p;
  3072. }
  3073. expr_ty
  3074. _PyAST_Constant(constant value, string kind, int lineno, int col_offset, int
  3075. end_lineno, int end_col_offset, PyArena *arena)
  3076. {
  3077. expr_ty p;
  3078. if (!value) {
  3079. PyErr_SetString(PyExc_ValueError,
  3080. "field 'value' is required for Constant");
  3081. return NULL;
  3082. }
  3083. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3084. if (!p)
  3085. return NULL;
  3086. p->kind = Constant_kind;
  3087. p->v.Constant.value = value;
  3088. p->v.Constant.kind = kind;
  3089. p->lineno = lineno;
  3090. p->col_offset = col_offset;
  3091. p->end_lineno = end_lineno;
  3092. p->end_col_offset = end_col_offset;
  3093. return p;
  3094. }
  3095. expr_ty
  3096. _PyAST_Attribute(expr_ty value, identifier attr, expr_context_ty ctx, int
  3097. lineno, int col_offset, int end_lineno, int end_col_offset,
  3098. PyArena *arena)
  3099. {
  3100. expr_ty p;
  3101. if (!value) {
  3102. PyErr_SetString(PyExc_ValueError,
  3103. "field 'value' is required for Attribute");
  3104. return NULL;
  3105. }
  3106. if (!attr) {
  3107. PyErr_SetString(PyExc_ValueError,
  3108. "field 'attr' is required for Attribute");
  3109. return NULL;
  3110. }
  3111. if (!ctx) {
  3112. PyErr_SetString(PyExc_ValueError,
  3113. "field 'ctx' is required for Attribute");
  3114. return NULL;
  3115. }
  3116. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3117. if (!p)
  3118. return NULL;
  3119. p->kind = Attribute_kind;
  3120. p->v.Attribute.value = value;
  3121. p->v.Attribute.attr = attr;
  3122. p->v.Attribute.ctx = ctx;
  3123. p->lineno = lineno;
  3124. p->col_offset = col_offset;
  3125. p->end_lineno = end_lineno;
  3126. p->end_col_offset = end_col_offset;
  3127. return p;
  3128. }
  3129. expr_ty
  3130. _PyAST_Subscript(expr_ty value, expr_ty slice, expr_context_ty ctx, int lineno,
  3131. int col_offset, int end_lineno, int end_col_offset, PyArena
  3132. *arena)
  3133. {
  3134. expr_ty p;
  3135. if (!value) {
  3136. PyErr_SetString(PyExc_ValueError,
  3137. "field 'value' is required for Subscript");
  3138. return NULL;
  3139. }
  3140. if (!slice) {
  3141. PyErr_SetString(PyExc_ValueError,
  3142. "field 'slice' is required for Subscript");
  3143. return NULL;
  3144. }
  3145. if (!ctx) {
  3146. PyErr_SetString(PyExc_ValueError,
  3147. "field 'ctx' is required for Subscript");
  3148. return NULL;
  3149. }
  3150. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3151. if (!p)
  3152. return NULL;
  3153. p->kind = Subscript_kind;
  3154. p->v.Subscript.value = value;
  3155. p->v.Subscript.slice = slice;
  3156. p->v.Subscript.ctx = ctx;
  3157. p->lineno = lineno;
  3158. p->col_offset = col_offset;
  3159. p->end_lineno = end_lineno;
  3160. p->end_col_offset = end_col_offset;
  3161. return p;
  3162. }
  3163. expr_ty
  3164. _PyAST_Starred(expr_ty value, expr_context_ty ctx, int lineno, int col_offset,
  3165. int end_lineno, int end_col_offset, PyArena *arena)
  3166. {
  3167. expr_ty p;
  3168. if (!value) {
  3169. PyErr_SetString(PyExc_ValueError,
  3170. "field 'value' is required for Starred");
  3171. return NULL;
  3172. }
  3173. if (!ctx) {
  3174. PyErr_SetString(PyExc_ValueError,
  3175. "field 'ctx' is required for Starred");
  3176. return NULL;
  3177. }
  3178. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3179. if (!p)
  3180. return NULL;
  3181. p->kind = Starred_kind;
  3182. p->v.Starred.value = value;
  3183. p->v.Starred.ctx = ctx;
  3184. p->lineno = lineno;
  3185. p->col_offset = col_offset;
  3186. p->end_lineno = end_lineno;
  3187. p->end_col_offset = end_col_offset;
  3188. return p;
  3189. }
  3190. expr_ty
  3191. _PyAST_Name(identifier id, expr_context_ty ctx, int lineno, int col_offset, int
  3192. end_lineno, int end_col_offset, PyArena *arena)
  3193. {
  3194. expr_ty p;
  3195. if (!id) {
  3196. PyErr_SetString(PyExc_ValueError,
  3197. "field 'id' is required for Name");
  3198. return NULL;
  3199. }
  3200. if (!ctx) {
  3201. PyErr_SetString(PyExc_ValueError,
  3202. "field 'ctx' is required for Name");
  3203. return NULL;
  3204. }
  3205. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3206. if (!p)
  3207. return NULL;
  3208. p->kind = Name_kind;
  3209. p->v.Name.id = id;
  3210. p->v.Name.ctx = ctx;
  3211. p->lineno = lineno;
  3212. p->col_offset = col_offset;
  3213. p->end_lineno = end_lineno;
  3214. p->end_col_offset = end_col_offset;
  3215. return p;
  3216. }
  3217. expr_ty
  3218. _PyAST_List(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
  3219. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  3220. {
  3221. expr_ty p;
  3222. if (!ctx) {
  3223. PyErr_SetString(PyExc_ValueError,
  3224. "field 'ctx' is required for List");
  3225. return NULL;
  3226. }
  3227. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3228. if (!p)
  3229. return NULL;
  3230. p->kind = List_kind;
  3231. p->v.List.elts = elts;
  3232. p->v.List.ctx = ctx;
  3233. p->lineno = lineno;
  3234. p->col_offset = col_offset;
  3235. p->end_lineno = end_lineno;
  3236. p->end_col_offset = end_col_offset;
  3237. return p;
  3238. }
  3239. expr_ty
  3240. _PyAST_Tuple(asdl_expr_seq * elts, expr_context_ty ctx, int lineno, int
  3241. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  3242. {
  3243. expr_ty p;
  3244. if (!ctx) {
  3245. PyErr_SetString(PyExc_ValueError,
  3246. "field 'ctx' is required for Tuple");
  3247. return NULL;
  3248. }
  3249. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3250. if (!p)
  3251. return NULL;
  3252. p->kind = Tuple_kind;
  3253. p->v.Tuple.elts = elts;
  3254. p->v.Tuple.ctx = ctx;
  3255. p->lineno = lineno;
  3256. p->col_offset = col_offset;
  3257. p->end_lineno = end_lineno;
  3258. p->end_col_offset = end_col_offset;
  3259. return p;
  3260. }
  3261. expr_ty
  3262. _PyAST_Slice(expr_ty lower, expr_ty upper, expr_ty step, int lineno, int
  3263. col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  3264. {
  3265. expr_ty p;
  3266. p = (expr_ty)_PyArena_Malloc(arena, sizeof(*p));
  3267. if (!p)
  3268. return NULL;
  3269. p->kind = Slice_kind;
  3270. p->v.Slice.lower = lower;
  3271. p->v.Slice.upper = upper;
  3272. p->v.Slice.step = step;
  3273. p->lineno = lineno;
  3274. p->col_offset = col_offset;
  3275. p->end_lineno = end_lineno;
  3276. p->end_col_offset = end_col_offset;
  3277. return p;
  3278. }
  3279. comprehension_ty
  3280. _PyAST_comprehension(expr_ty target, expr_ty iter, asdl_expr_seq * ifs, int
  3281. is_async, PyArena *arena)
  3282. {
  3283. comprehension_ty p;
  3284. if (!target) {
  3285. PyErr_SetString(PyExc_ValueError,
  3286. "field 'target' is required for comprehension");
  3287. return NULL;
  3288. }
  3289. if (!iter) {
  3290. PyErr_SetString(PyExc_ValueError,
  3291. "field 'iter' is required for comprehension");
  3292. return NULL;
  3293. }
  3294. p = (comprehension_ty)_PyArena_Malloc(arena, sizeof(*p));
  3295. if (!p)
  3296. return NULL;
  3297. p->target = target;
  3298. p->iter = iter;
  3299. p->ifs = ifs;
  3300. p->is_async = is_async;
  3301. return p;
  3302. }
  3303. excepthandler_ty
  3304. _PyAST_ExceptHandler(expr_ty type, identifier name, asdl_stmt_seq * body, int
  3305. lineno, int col_offset, int end_lineno, int
  3306. end_col_offset, PyArena *arena)
  3307. {
  3308. excepthandler_ty p;
  3309. p = (excepthandler_ty)_PyArena_Malloc(arena, sizeof(*p));
  3310. if (!p)
  3311. return NULL;
  3312. p->kind = ExceptHandler_kind;
  3313. p->v.ExceptHandler.type = type;
  3314. p->v.ExceptHandler.name = name;
  3315. p->v.ExceptHandler.body = body;
  3316. p->lineno = lineno;
  3317. p->col_offset = col_offset;
  3318. p->end_lineno = end_lineno;
  3319. p->end_col_offset = end_col_offset;
  3320. return p;
  3321. }
  3322. arguments_ty
  3323. _PyAST_arguments(asdl_arg_seq * posonlyargs, asdl_arg_seq * args, arg_ty
  3324. vararg, asdl_arg_seq * kwonlyargs, asdl_expr_seq *
  3325. kw_defaults, arg_ty kwarg, asdl_expr_seq * defaults, PyArena
  3326. *arena)
  3327. {
  3328. arguments_ty p;
  3329. p = (arguments_ty)_PyArena_Malloc(arena, sizeof(*p));
  3330. if (!p)
  3331. return NULL;
  3332. p->posonlyargs = posonlyargs;
  3333. p->args = args;
  3334. p->vararg = vararg;
  3335. p->kwonlyargs = kwonlyargs;
  3336. p->kw_defaults = kw_defaults;
  3337. p->kwarg = kwarg;
  3338. p->defaults = defaults;
  3339. return p;
  3340. }
  3341. arg_ty
  3342. _PyAST_arg(identifier arg, expr_ty annotation, string type_comment, int lineno,
  3343. int col_offset, int end_lineno, int end_col_offset, PyArena *arena)
  3344. {
  3345. arg_ty p;
  3346. if (!arg) {
  3347. PyErr_SetString(PyExc_ValueError,
  3348. "field 'arg' is required for arg");
  3349. return NULL;
  3350. }
  3351. p = (arg_ty)_PyArena_Malloc(arena, sizeof(*p));
  3352. if (!p)
  3353. return NULL;
  3354. p->arg = arg;
  3355. p->annotation = annotation;
  3356. p->type_comment = type_comment;
  3357. p->lineno = lineno;
  3358. p->col_offset = col_offset;
  3359. p->end_lineno = end_lineno;
  3360. p->end_col_offset = end_col_offset;
  3361. return p;
  3362. }
  3363. keyword_ty
  3364. _PyAST_keyword(identifier arg, expr_ty value, int lineno, int col_offset, int
  3365. end_lineno, int end_col_offset, PyArena *arena)
  3366. {
  3367. keyword_ty p;
  3368. if (!value) {
  3369. PyErr_SetString(PyExc_ValueError,
  3370. "field 'value' is required for keyword");
  3371. return NULL;
  3372. }
  3373. p = (keyword_ty)_PyArena_Malloc(arena, sizeof(*p));
  3374. if (!p)
  3375. return NULL;
  3376. p->arg = arg;
  3377. p->value = value;
  3378. p->lineno = lineno;
  3379. p->col_offset = col_offset;
  3380. p->end_lineno = end_lineno;
  3381. p->end_col_offset = end_col_offset;
  3382. return p;
  3383. }
  3384. alias_ty
  3385. _PyAST_alias(identifier name, identifier asname, int lineno, int col_offset,
  3386. int end_lineno, int end_col_offset, PyArena *arena)
  3387. {
  3388. alias_ty p;
  3389. if (!name) {
  3390. PyErr_SetString(PyExc_ValueError,
  3391. "field 'name' is required for alias");
  3392. return NULL;
  3393. }
  3394. p = (alias_ty)_PyArena_Malloc(arena, sizeof(*p));
  3395. if (!p)
  3396. return NULL;
  3397. p->name = name;
  3398. p->asname = asname;
  3399. p->lineno = lineno;
  3400. p->col_offset = col_offset;
  3401. p->end_lineno = end_lineno;
  3402. p->end_col_offset = end_col_offset;
  3403. return p;
  3404. }
  3405. withitem_ty
  3406. _PyAST_withitem(expr_ty context_expr, expr_ty optional_vars, PyArena *arena)
  3407. {
  3408. withitem_ty p;
  3409. if (!context_expr) {
  3410. PyErr_SetString(PyExc_ValueError,
  3411. "field 'context_expr' is required for withitem");
  3412. return NULL;
  3413. }
  3414. p = (withitem_ty)_PyArena_Malloc(arena, sizeof(*p));
  3415. if (!p)
  3416. return NULL;
  3417. p->context_expr = context_expr;
  3418. p->optional_vars = optional_vars;
  3419. return p;
  3420. }
  3421. match_case_ty
  3422. _PyAST_match_case(pattern_ty pattern, expr_ty guard, asdl_stmt_seq * body,
  3423. PyArena *arena)
  3424. {
  3425. match_case_ty p;
  3426. if (!pattern) {
  3427. PyErr_SetString(PyExc_ValueError,
  3428. "field 'pattern' is required for match_case");
  3429. return NULL;
  3430. }
  3431. p = (match_case_ty)_PyArena_Malloc(arena, sizeof(*p));
  3432. if (!p)
  3433. return NULL;
  3434. p->pattern = pattern;
  3435. p->guard = guard;
  3436. p->body = body;
  3437. return p;
  3438. }
  3439. pattern_ty
  3440. _PyAST_MatchValue(expr_ty value, int lineno, int col_offset, int end_lineno,
  3441. int end_col_offset, PyArena *arena)
  3442. {
  3443. pattern_ty p;
  3444. if (!value) {
  3445. PyErr_SetString(PyExc_ValueError,
  3446. "field 'value' is required for MatchValue");
  3447. return NULL;
  3448. }
  3449. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3450. if (!p)
  3451. return NULL;
  3452. p->kind = MatchValue_kind;
  3453. p->v.MatchValue.value = value;
  3454. p->lineno = lineno;
  3455. p->col_offset = col_offset;
  3456. p->end_lineno = end_lineno;
  3457. p->end_col_offset = end_col_offset;
  3458. return p;
  3459. }
  3460. pattern_ty
  3461. _PyAST_MatchSingleton(constant value, int lineno, int col_offset, int
  3462. end_lineno, int end_col_offset, PyArena *arena)
  3463. {
  3464. pattern_ty p;
  3465. if (!value) {
  3466. PyErr_SetString(PyExc_ValueError,
  3467. "field 'value' is required for MatchSingleton");
  3468. return NULL;
  3469. }
  3470. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3471. if (!p)
  3472. return NULL;
  3473. p->kind = MatchSingleton_kind;
  3474. p->v.MatchSingleton.value = value;
  3475. p->lineno = lineno;
  3476. p->col_offset = col_offset;
  3477. p->end_lineno = end_lineno;
  3478. p->end_col_offset = end_col_offset;
  3479. return p;
  3480. }
  3481. pattern_ty
  3482. _PyAST_MatchSequence(asdl_pattern_seq * patterns, int lineno, int col_offset,
  3483. int end_lineno, int end_col_offset, PyArena *arena)
  3484. {
  3485. pattern_ty p;
  3486. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3487. if (!p)
  3488. return NULL;
  3489. p->kind = MatchSequence_kind;
  3490. p->v.MatchSequence.patterns = patterns;
  3491. p->lineno = lineno;
  3492. p->col_offset = col_offset;
  3493. p->end_lineno = end_lineno;
  3494. p->end_col_offset = end_col_offset;
  3495. return p;
  3496. }
  3497. pattern_ty
  3498. _PyAST_MatchMapping(asdl_expr_seq * keys, asdl_pattern_seq * patterns,
  3499. identifier rest, int lineno, int col_offset, int
  3500. end_lineno, int end_col_offset, PyArena *arena)
  3501. {
  3502. pattern_ty p;
  3503. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3504. if (!p)
  3505. return NULL;
  3506. p->kind = MatchMapping_kind;
  3507. p->v.MatchMapping.keys = keys;
  3508. p->v.MatchMapping.patterns = patterns;
  3509. p->v.MatchMapping.rest = rest;
  3510. p->lineno = lineno;
  3511. p->col_offset = col_offset;
  3512. p->end_lineno = end_lineno;
  3513. p->end_col_offset = end_col_offset;
  3514. return p;
  3515. }
  3516. pattern_ty
  3517. _PyAST_MatchClass(expr_ty cls, asdl_pattern_seq * patterns, asdl_identifier_seq
  3518. * kwd_attrs, asdl_pattern_seq * kwd_patterns, int lineno, int
  3519. col_offset, int end_lineno, int end_col_offset, PyArena
  3520. *arena)
  3521. {
  3522. pattern_ty p;
  3523. if (!cls) {
  3524. PyErr_SetString(PyExc_ValueError,
  3525. "field 'cls' is required for MatchClass");
  3526. return NULL;
  3527. }
  3528. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3529. if (!p)
  3530. return NULL;
  3531. p->kind = MatchClass_kind;
  3532. p->v.MatchClass.cls = cls;
  3533. p->v.MatchClass.patterns = patterns;
  3534. p->v.MatchClass.kwd_attrs = kwd_attrs;
  3535. p->v.MatchClass.kwd_patterns = kwd_patterns;
  3536. p->lineno = lineno;
  3537. p->col_offset = col_offset;
  3538. p->end_lineno = end_lineno;
  3539. p->end_col_offset = end_col_offset;
  3540. return p;
  3541. }
  3542. pattern_ty
  3543. _PyAST_MatchStar(identifier name, int lineno, int col_offset, int end_lineno,
  3544. int end_col_offset, PyArena *arena)
  3545. {
  3546. pattern_ty p;
  3547. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3548. if (!p)
  3549. return NULL;
  3550. p->kind = MatchStar_kind;
  3551. p->v.MatchStar.name = name;
  3552. p->lineno = lineno;
  3553. p->col_offset = col_offset;
  3554. p->end_lineno = end_lineno;
  3555. p->end_col_offset = end_col_offset;
  3556. return p;
  3557. }
  3558. pattern_ty
  3559. _PyAST_MatchAs(pattern_ty pattern, identifier name, int lineno, int col_offset,
  3560. int end_lineno, int end_col_offset, PyArena *arena)
  3561. {
  3562. pattern_ty p;
  3563. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3564. if (!p)
  3565. return NULL;
  3566. p->kind = MatchAs_kind;
  3567. p->v.MatchAs.pattern = pattern;
  3568. p->v.MatchAs.name = name;
  3569. p->lineno = lineno;
  3570. p->col_offset = col_offset;
  3571. p->end_lineno = end_lineno;
  3572. p->end_col_offset = end_col_offset;
  3573. return p;
  3574. }
  3575. pattern_ty
  3576. _PyAST_MatchOr(asdl_pattern_seq * patterns, int lineno, int col_offset, int
  3577. end_lineno, int end_col_offset, PyArena *arena)
  3578. {
  3579. pattern_ty p;
  3580. p = (pattern_ty)_PyArena_Malloc(arena, sizeof(*p));
  3581. if (!p)
  3582. return NULL;
  3583. p->kind = MatchOr_kind;
  3584. p->v.MatchOr.patterns = patterns;
  3585. p->lineno = lineno;
  3586. p->col_offset = col_offset;
  3587. p->end_lineno = end_lineno;
  3588. p->end_col_offset = end_col_offset;
  3589. return p;
  3590. }
  3591. type_ignore_ty
  3592. _PyAST_TypeIgnore(int lineno, string tag, PyArena *arena)
  3593. {
  3594. type_ignore_ty p;
  3595. if (!tag) {
  3596. PyErr_SetString(PyExc_ValueError,
  3597. "field 'tag' is required for TypeIgnore");
  3598. return NULL;
  3599. }
  3600. p = (type_ignore_ty)_PyArena_Malloc(arena, sizeof(*p));
  3601. if (!p)
  3602. return NULL;
  3603. p->kind = TypeIgnore_kind;
  3604. p->v.TypeIgnore.lineno = lineno;
  3605. p->v.TypeIgnore.tag = tag;
  3606. return p;
  3607. }
  3608. type_param_ty
  3609. _PyAST_TypeVar(identifier name, expr_ty bound, int lineno, int col_offset, int
  3610. end_lineno, int end_col_offset, PyArena *arena)
  3611. {
  3612. type_param_ty p;
  3613. if (!name) {
  3614. PyErr_SetString(PyExc_ValueError,
  3615. "field 'name' is required for TypeVar");
  3616. return NULL;
  3617. }
  3618. p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
  3619. if (!p)
  3620. return NULL;
  3621. p->kind = TypeVar_kind;
  3622. p->v.TypeVar.name = name;
  3623. p->v.TypeVar.bound = bound;
  3624. p->lineno = lineno;
  3625. p->col_offset = col_offset;
  3626. p->end_lineno = end_lineno;
  3627. p->end_col_offset = end_col_offset;
  3628. return p;
  3629. }
  3630. type_param_ty
  3631. _PyAST_ParamSpec(identifier name, int lineno, int col_offset, int end_lineno,
  3632. int end_col_offset, PyArena *arena)
  3633. {
  3634. type_param_ty p;
  3635. if (!name) {
  3636. PyErr_SetString(PyExc_ValueError,
  3637. "field 'name' is required for ParamSpec");
  3638. return NULL;
  3639. }
  3640. p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
  3641. if (!p)
  3642. return NULL;
  3643. p->kind = ParamSpec_kind;
  3644. p->v.ParamSpec.name = name;
  3645. p->lineno = lineno;
  3646. p->col_offset = col_offset;
  3647. p->end_lineno = end_lineno;
  3648. p->end_col_offset = end_col_offset;
  3649. return p;
  3650. }
  3651. type_param_ty
  3652. _PyAST_TypeVarTuple(identifier name, int lineno, int col_offset, int
  3653. end_lineno, int end_col_offset, PyArena *arena)
  3654. {
  3655. type_param_ty p;
  3656. if (!name) {
  3657. PyErr_SetString(PyExc_ValueError,
  3658. "field 'name' is required for TypeVarTuple");
  3659. return NULL;
  3660. }
  3661. p = (type_param_ty)_PyArena_Malloc(arena, sizeof(*p));
  3662. if (!p)
  3663. return NULL;
  3664. p->kind = TypeVarTuple_kind;
  3665. p->v.TypeVarTuple.name = name;
  3666. p->lineno = lineno;
  3667. p->col_offset = col_offset;
  3668. p->end_lineno = end_lineno;
  3669. p->end_col_offset = end_col_offset;
  3670. return p;
  3671. }
  3672. PyObject*
  3673. ast2obj_mod(struct ast_state *state, struct validator *vstate, void* _o)
  3674. {
  3675. mod_ty o = (mod_ty)_o;
  3676. PyObject *result = NULL, *value = NULL;
  3677. PyTypeObject *tp;
  3678. if (!o) {
  3679. Py_RETURN_NONE;
  3680. }
  3681. if (++vstate->recursion_depth > vstate->recursion_limit) {
  3682. PyErr_SetString(PyExc_RecursionError,
  3683. "maximum recursion depth exceeded during ast construction");
  3684. return 0;
  3685. }
  3686. switch (o->kind) {
  3687. case Module_kind:
  3688. tp = (PyTypeObject *)state->Module_type;
  3689. result = PyType_GenericNew(tp, NULL, NULL);
  3690. if (!result) goto failed;
  3691. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Module.body,
  3692. ast2obj_stmt);
  3693. if (!value) goto failed;
  3694. if (PyObject_SetAttr(result, state->body, value) == -1)
  3695. goto failed;
  3696. Py_DECREF(value);
  3697. value = ast2obj_list(state, vstate,
  3698. (asdl_seq*)o->v.Module.type_ignores,
  3699. ast2obj_type_ignore);
  3700. if (!value) goto failed;
  3701. if (PyObject_SetAttr(result, state->type_ignores, value) == -1)
  3702. goto failed;
  3703. Py_DECREF(value);
  3704. break;
  3705. case Interactive_kind:
  3706. tp = (PyTypeObject *)state->Interactive_type;
  3707. result = PyType_GenericNew(tp, NULL, NULL);
  3708. if (!result) goto failed;
  3709. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Interactive.body,
  3710. ast2obj_stmt);
  3711. if (!value) goto failed;
  3712. if (PyObject_SetAttr(result, state->body, value) == -1)
  3713. goto failed;
  3714. Py_DECREF(value);
  3715. break;
  3716. case Expression_kind:
  3717. tp = (PyTypeObject *)state->Expression_type;
  3718. result = PyType_GenericNew(tp, NULL, NULL);
  3719. if (!result) goto failed;
  3720. value = ast2obj_expr(state, vstate, o->v.Expression.body);
  3721. if (!value) goto failed;
  3722. if (PyObject_SetAttr(result, state->body, value) == -1)
  3723. goto failed;
  3724. Py_DECREF(value);
  3725. break;
  3726. case FunctionType_kind:
  3727. tp = (PyTypeObject *)state->FunctionType_type;
  3728. result = PyType_GenericNew(tp, NULL, NULL);
  3729. if (!result) goto failed;
  3730. value = ast2obj_list(state, vstate,
  3731. (asdl_seq*)o->v.FunctionType.argtypes,
  3732. ast2obj_expr);
  3733. if (!value) goto failed;
  3734. if (PyObject_SetAttr(result, state->argtypes, value) == -1)
  3735. goto failed;
  3736. Py_DECREF(value);
  3737. value = ast2obj_expr(state, vstate, o->v.FunctionType.returns);
  3738. if (!value) goto failed;
  3739. if (PyObject_SetAttr(result, state->returns, value) == -1)
  3740. goto failed;
  3741. Py_DECREF(value);
  3742. break;
  3743. }
  3744. vstate->recursion_depth--;
  3745. return result;
  3746. failed:
  3747. vstate->recursion_depth--;
  3748. Py_XDECREF(value);
  3749. Py_XDECREF(result);
  3750. return NULL;
  3751. }
  3752. PyObject*
  3753. ast2obj_stmt(struct ast_state *state, struct validator *vstate, void* _o)
  3754. {
  3755. stmt_ty o = (stmt_ty)_o;
  3756. PyObject *result = NULL, *value = NULL;
  3757. PyTypeObject *tp;
  3758. if (!o) {
  3759. Py_RETURN_NONE;
  3760. }
  3761. if (++vstate->recursion_depth > vstate->recursion_limit) {
  3762. PyErr_SetString(PyExc_RecursionError,
  3763. "maximum recursion depth exceeded during ast construction");
  3764. return 0;
  3765. }
  3766. switch (o->kind) {
  3767. case FunctionDef_kind:
  3768. tp = (PyTypeObject *)state->FunctionDef_type;
  3769. result = PyType_GenericNew(tp, NULL, NULL);
  3770. if (!result) goto failed;
  3771. value = ast2obj_identifier(state, vstate, o->v.FunctionDef.name);
  3772. if (!value) goto failed;
  3773. if (PyObject_SetAttr(result, state->name, value) == -1)
  3774. goto failed;
  3775. Py_DECREF(value);
  3776. value = ast2obj_arguments(state, vstate, o->v.FunctionDef.args);
  3777. if (!value) goto failed;
  3778. if (PyObject_SetAttr(result, state->args, value) == -1)
  3779. goto failed;
  3780. Py_DECREF(value);
  3781. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.FunctionDef.body,
  3782. ast2obj_stmt);
  3783. if (!value) goto failed;
  3784. if (PyObject_SetAttr(result, state->body, value) == -1)
  3785. goto failed;
  3786. Py_DECREF(value);
  3787. value = ast2obj_list(state, vstate,
  3788. (asdl_seq*)o->v.FunctionDef.decorator_list,
  3789. ast2obj_expr);
  3790. if (!value) goto failed;
  3791. if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
  3792. goto failed;
  3793. Py_DECREF(value);
  3794. value = ast2obj_expr(state, vstate, o->v.FunctionDef.returns);
  3795. if (!value) goto failed;
  3796. if (PyObject_SetAttr(result, state->returns, value) == -1)
  3797. goto failed;
  3798. Py_DECREF(value);
  3799. value = ast2obj_string(state, vstate, o->v.FunctionDef.type_comment);
  3800. if (!value) goto failed;
  3801. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  3802. goto failed;
  3803. Py_DECREF(value);
  3804. value = ast2obj_list(state, vstate,
  3805. (asdl_seq*)o->v.FunctionDef.type_params,
  3806. ast2obj_type_param);
  3807. if (!value) goto failed;
  3808. if (PyObject_SetAttr(result, state->type_params, value) == -1)
  3809. goto failed;
  3810. Py_DECREF(value);
  3811. break;
  3812. case AsyncFunctionDef_kind:
  3813. tp = (PyTypeObject *)state->AsyncFunctionDef_type;
  3814. result = PyType_GenericNew(tp, NULL, NULL);
  3815. if (!result) goto failed;
  3816. value = ast2obj_identifier(state, vstate, o->v.AsyncFunctionDef.name);
  3817. if (!value) goto failed;
  3818. if (PyObject_SetAttr(result, state->name, value) == -1)
  3819. goto failed;
  3820. Py_DECREF(value);
  3821. value = ast2obj_arguments(state, vstate, o->v.AsyncFunctionDef.args);
  3822. if (!value) goto failed;
  3823. if (PyObject_SetAttr(result, state->args, value) == -1)
  3824. goto failed;
  3825. Py_DECREF(value);
  3826. value = ast2obj_list(state, vstate,
  3827. (asdl_seq*)o->v.AsyncFunctionDef.body,
  3828. ast2obj_stmt);
  3829. if (!value) goto failed;
  3830. if (PyObject_SetAttr(result, state->body, value) == -1)
  3831. goto failed;
  3832. Py_DECREF(value);
  3833. value = ast2obj_list(state, vstate,
  3834. (asdl_seq*)o->v.AsyncFunctionDef.decorator_list,
  3835. ast2obj_expr);
  3836. if (!value) goto failed;
  3837. if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
  3838. goto failed;
  3839. Py_DECREF(value);
  3840. value = ast2obj_expr(state, vstate, o->v.AsyncFunctionDef.returns);
  3841. if (!value) goto failed;
  3842. if (PyObject_SetAttr(result, state->returns, value) == -1)
  3843. goto failed;
  3844. Py_DECREF(value);
  3845. value = ast2obj_string(state, vstate, o->v.AsyncFunctionDef.type_comment);
  3846. if (!value) goto failed;
  3847. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  3848. goto failed;
  3849. Py_DECREF(value);
  3850. value = ast2obj_list(state, vstate,
  3851. (asdl_seq*)o->v.AsyncFunctionDef.type_params,
  3852. ast2obj_type_param);
  3853. if (!value) goto failed;
  3854. if (PyObject_SetAttr(result, state->type_params, value) == -1)
  3855. goto failed;
  3856. Py_DECREF(value);
  3857. break;
  3858. case ClassDef_kind:
  3859. tp = (PyTypeObject *)state->ClassDef_type;
  3860. result = PyType_GenericNew(tp, NULL, NULL);
  3861. if (!result) goto failed;
  3862. value = ast2obj_identifier(state, vstate, o->v.ClassDef.name);
  3863. if (!value) goto failed;
  3864. if (PyObject_SetAttr(result, state->name, value) == -1)
  3865. goto failed;
  3866. Py_DECREF(value);
  3867. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.bases,
  3868. ast2obj_expr);
  3869. if (!value) goto failed;
  3870. if (PyObject_SetAttr(result, state->bases, value) == -1)
  3871. goto failed;
  3872. Py_DECREF(value);
  3873. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.keywords,
  3874. ast2obj_keyword);
  3875. if (!value) goto failed;
  3876. if (PyObject_SetAttr(result, state->keywords, value) == -1)
  3877. goto failed;
  3878. Py_DECREF(value);
  3879. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ClassDef.body,
  3880. ast2obj_stmt);
  3881. if (!value) goto failed;
  3882. if (PyObject_SetAttr(result, state->body, value) == -1)
  3883. goto failed;
  3884. Py_DECREF(value);
  3885. value = ast2obj_list(state, vstate,
  3886. (asdl_seq*)o->v.ClassDef.decorator_list,
  3887. ast2obj_expr);
  3888. if (!value) goto failed;
  3889. if (PyObject_SetAttr(result, state->decorator_list, value) == -1)
  3890. goto failed;
  3891. Py_DECREF(value);
  3892. value = ast2obj_list(state, vstate,
  3893. (asdl_seq*)o->v.ClassDef.type_params,
  3894. ast2obj_type_param);
  3895. if (!value) goto failed;
  3896. if (PyObject_SetAttr(result, state->type_params, value) == -1)
  3897. goto failed;
  3898. Py_DECREF(value);
  3899. break;
  3900. case Return_kind:
  3901. tp = (PyTypeObject *)state->Return_type;
  3902. result = PyType_GenericNew(tp, NULL, NULL);
  3903. if (!result) goto failed;
  3904. value = ast2obj_expr(state, vstate, o->v.Return.value);
  3905. if (!value) goto failed;
  3906. if (PyObject_SetAttr(result, state->value, value) == -1)
  3907. goto failed;
  3908. Py_DECREF(value);
  3909. break;
  3910. case Delete_kind:
  3911. tp = (PyTypeObject *)state->Delete_type;
  3912. result = PyType_GenericNew(tp, NULL, NULL);
  3913. if (!result) goto failed;
  3914. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Delete.targets,
  3915. ast2obj_expr);
  3916. if (!value) goto failed;
  3917. if (PyObject_SetAttr(result, state->targets, value) == -1)
  3918. goto failed;
  3919. Py_DECREF(value);
  3920. break;
  3921. case Assign_kind:
  3922. tp = (PyTypeObject *)state->Assign_type;
  3923. result = PyType_GenericNew(tp, NULL, NULL);
  3924. if (!result) goto failed;
  3925. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Assign.targets,
  3926. ast2obj_expr);
  3927. if (!value) goto failed;
  3928. if (PyObject_SetAttr(result, state->targets, value) == -1)
  3929. goto failed;
  3930. Py_DECREF(value);
  3931. value = ast2obj_expr(state, vstate, o->v.Assign.value);
  3932. if (!value) goto failed;
  3933. if (PyObject_SetAttr(result, state->value, value) == -1)
  3934. goto failed;
  3935. Py_DECREF(value);
  3936. value = ast2obj_string(state, vstate, o->v.Assign.type_comment);
  3937. if (!value) goto failed;
  3938. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  3939. goto failed;
  3940. Py_DECREF(value);
  3941. break;
  3942. case TypeAlias_kind:
  3943. tp = (PyTypeObject *)state->TypeAlias_type;
  3944. result = PyType_GenericNew(tp, NULL, NULL);
  3945. if (!result) goto failed;
  3946. value = ast2obj_expr(state, vstate, o->v.TypeAlias.name);
  3947. if (!value) goto failed;
  3948. if (PyObject_SetAttr(result, state->name, value) == -1)
  3949. goto failed;
  3950. Py_DECREF(value);
  3951. value = ast2obj_list(state, vstate,
  3952. (asdl_seq*)o->v.TypeAlias.type_params,
  3953. ast2obj_type_param);
  3954. if (!value) goto failed;
  3955. if (PyObject_SetAttr(result, state->type_params, value) == -1)
  3956. goto failed;
  3957. Py_DECREF(value);
  3958. value = ast2obj_expr(state, vstate, o->v.TypeAlias.value);
  3959. if (!value) goto failed;
  3960. if (PyObject_SetAttr(result, state->value, value) == -1)
  3961. goto failed;
  3962. Py_DECREF(value);
  3963. break;
  3964. case AugAssign_kind:
  3965. tp = (PyTypeObject *)state->AugAssign_type;
  3966. result = PyType_GenericNew(tp, NULL, NULL);
  3967. if (!result) goto failed;
  3968. value = ast2obj_expr(state, vstate, o->v.AugAssign.target);
  3969. if (!value) goto failed;
  3970. if (PyObject_SetAttr(result, state->target, value) == -1)
  3971. goto failed;
  3972. Py_DECREF(value);
  3973. value = ast2obj_operator(state, vstate, o->v.AugAssign.op);
  3974. if (!value) goto failed;
  3975. if (PyObject_SetAttr(result, state->op, value) == -1)
  3976. goto failed;
  3977. Py_DECREF(value);
  3978. value = ast2obj_expr(state, vstate, o->v.AugAssign.value);
  3979. if (!value) goto failed;
  3980. if (PyObject_SetAttr(result, state->value, value) == -1)
  3981. goto failed;
  3982. Py_DECREF(value);
  3983. break;
  3984. case AnnAssign_kind:
  3985. tp = (PyTypeObject *)state->AnnAssign_type;
  3986. result = PyType_GenericNew(tp, NULL, NULL);
  3987. if (!result) goto failed;
  3988. value = ast2obj_expr(state, vstate, o->v.AnnAssign.target);
  3989. if (!value) goto failed;
  3990. if (PyObject_SetAttr(result, state->target, value) == -1)
  3991. goto failed;
  3992. Py_DECREF(value);
  3993. value = ast2obj_expr(state, vstate, o->v.AnnAssign.annotation);
  3994. if (!value) goto failed;
  3995. if (PyObject_SetAttr(result, state->annotation, value) == -1)
  3996. goto failed;
  3997. Py_DECREF(value);
  3998. value = ast2obj_expr(state, vstate, o->v.AnnAssign.value);
  3999. if (!value) goto failed;
  4000. if (PyObject_SetAttr(result, state->value, value) == -1)
  4001. goto failed;
  4002. Py_DECREF(value);
  4003. value = ast2obj_int(state, vstate, o->v.AnnAssign.simple);
  4004. if (!value) goto failed;
  4005. if (PyObject_SetAttr(result, state->simple, value) == -1)
  4006. goto failed;
  4007. Py_DECREF(value);
  4008. break;
  4009. case For_kind:
  4010. tp = (PyTypeObject *)state->For_type;
  4011. result = PyType_GenericNew(tp, NULL, NULL);
  4012. if (!result) goto failed;
  4013. value = ast2obj_expr(state, vstate, o->v.For.target);
  4014. if (!value) goto failed;
  4015. if (PyObject_SetAttr(result, state->target, value) == -1)
  4016. goto failed;
  4017. Py_DECREF(value);
  4018. value = ast2obj_expr(state, vstate, o->v.For.iter);
  4019. if (!value) goto failed;
  4020. if (PyObject_SetAttr(result, state->iter, value) == -1)
  4021. goto failed;
  4022. Py_DECREF(value);
  4023. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.For.body,
  4024. ast2obj_stmt);
  4025. if (!value) goto failed;
  4026. if (PyObject_SetAttr(result, state->body, value) == -1)
  4027. goto failed;
  4028. Py_DECREF(value);
  4029. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.For.orelse,
  4030. ast2obj_stmt);
  4031. if (!value) goto failed;
  4032. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4033. goto failed;
  4034. Py_DECREF(value);
  4035. value = ast2obj_string(state, vstate, o->v.For.type_comment);
  4036. if (!value) goto failed;
  4037. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  4038. goto failed;
  4039. Py_DECREF(value);
  4040. break;
  4041. case AsyncFor_kind:
  4042. tp = (PyTypeObject *)state->AsyncFor_type;
  4043. result = PyType_GenericNew(tp, NULL, NULL);
  4044. if (!result) goto failed;
  4045. value = ast2obj_expr(state, vstate, o->v.AsyncFor.target);
  4046. if (!value) goto failed;
  4047. if (PyObject_SetAttr(result, state->target, value) == -1)
  4048. goto failed;
  4049. Py_DECREF(value);
  4050. value = ast2obj_expr(state, vstate, o->v.AsyncFor.iter);
  4051. if (!value) goto failed;
  4052. if (PyObject_SetAttr(result, state->iter, value) == -1)
  4053. goto failed;
  4054. Py_DECREF(value);
  4055. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncFor.body,
  4056. ast2obj_stmt);
  4057. if (!value) goto failed;
  4058. if (PyObject_SetAttr(result, state->body, value) == -1)
  4059. goto failed;
  4060. Py_DECREF(value);
  4061. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncFor.orelse,
  4062. ast2obj_stmt);
  4063. if (!value) goto failed;
  4064. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4065. goto failed;
  4066. Py_DECREF(value);
  4067. value = ast2obj_string(state, vstate, o->v.AsyncFor.type_comment);
  4068. if (!value) goto failed;
  4069. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  4070. goto failed;
  4071. Py_DECREF(value);
  4072. break;
  4073. case While_kind:
  4074. tp = (PyTypeObject *)state->While_type;
  4075. result = PyType_GenericNew(tp, NULL, NULL);
  4076. if (!result) goto failed;
  4077. value = ast2obj_expr(state, vstate, o->v.While.test);
  4078. if (!value) goto failed;
  4079. if (PyObject_SetAttr(result, state->test, value) == -1)
  4080. goto failed;
  4081. Py_DECREF(value);
  4082. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.While.body,
  4083. ast2obj_stmt);
  4084. if (!value) goto failed;
  4085. if (PyObject_SetAttr(result, state->body, value) == -1)
  4086. goto failed;
  4087. Py_DECREF(value);
  4088. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.While.orelse,
  4089. ast2obj_stmt);
  4090. if (!value) goto failed;
  4091. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4092. goto failed;
  4093. Py_DECREF(value);
  4094. break;
  4095. case If_kind:
  4096. tp = (PyTypeObject *)state->If_type;
  4097. result = PyType_GenericNew(tp, NULL, NULL);
  4098. if (!result) goto failed;
  4099. value = ast2obj_expr(state, vstate, o->v.If.test);
  4100. if (!value) goto failed;
  4101. if (PyObject_SetAttr(result, state->test, value) == -1)
  4102. goto failed;
  4103. Py_DECREF(value);
  4104. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.If.body,
  4105. ast2obj_stmt);
  4106. if (!value) goto failed;
  4107. if (PyObject_SetAttr(result, state->body, value) == -1)
  4108. goto failed;
  4109. Py_DECREF(value);
  4110. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.If.orelse,
  4111. ast2obj_stmt);
  4112. if (!value) goto failed;
  4113. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4114. goto failed;
  4115. Py_DECREF(value);
  4116. break;
  4117. case With_kind:
  4118. tp = (PyTypeObject *)state->With_type;
  4119. result = PyType_GenericNew(tp, NULL, NULL);
  4120. if (!result) goto failed;
  4121. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.With.items,
  4122. ast2obj_withitem);
  4123. if (!value) goto failed;
  4124. if (PyObject_SetAttr(result, state->items, value) == -1)
  4125. goto failed;
  4126. Py_DECREF(value);
  4127. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.With.body,
  4128. ast2obj_stmt);
  4129. if (!value) goto failed;
  4130. if (PyObject_SetAttr(result, state->body, value) == -1)
  4131. goto failed;
  4132. Py_DECREF(value);
  4133. value = ast2obj_string(state, vstate, o->v.With.type_comment);
  4134. if (!value) goto failed;
  4135. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  4136. goto failed;
  4137. Py_DECREF(value);
  4138. break;
  4139. case AsyncWith_kind:
  4140. tp = (PyTypeObject *)state->AsyncWith_type;
  4141. result = PyType_GenericNew(tp, NULL, NULL);
  4142. if (!result) goto failed;
  4143. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncWith.items,
  4144. ast2obj_withitem);
  4145. if (!value) goto failed;
  4146. if (PyObject_SetAttr(result, state->items, value) == -1)
  4147. goto failed;
  4148. Py_DECREF(value);
  4149. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.AsyncWith.body,
  4150. ast2obj_stmt);
  4151. if (!value) goto failed;
  4152. if (PyObject_SetAttr(result, state->body, value) == -1)
  4153. goto failed;
  4154. Py_DECREF(value);
  4155. value = ast2obj_string(state, vstate, o->v.AsyncWith.type_comment);
  4156. if (!value) goto failed;
  4157. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  4158. goto failed;
  4159. Py_DECREF(value);
  4160. break;
  4161. case Match_kind:
  4162. tp = (PyTypeObject *)state->Match_type;
  4163. result = PyType_GenericNew(tp, NULL, NULL);
  4164. if (!result) goto failed;
  4165. value = ast2obj_expr(state, vstate, o->v.Match.subject);
  4166. if (!value) goto failed;
  4167. if (PyObject_SetAttr(result, state->subject, value) == -1)
  4168. goto failed;
  4169. Py_DECREF(value);
  4170. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Match.cases,
  4171. ast2obj_match_case);
  4172. if (!value) goto failed;
  4173. if (PyObject_SetAttr(result, state->cases, value) == -1)
  4174. goto failed;
  4175. Py_DECREF(value);
  4176. break;
  4177. case Raise_kind:
  4178. tp = (PyTypeObject *)state->Raise_type;
  4179. result = PyType_GenericNew(tp, NULL, NULL);
  4180. if (!result) goto failed;
  4181. value = ast2obj_expr(state, vstate, o->v.Raise.exc);
  4182. if (!value) goto failed;
  4183. if (PyObject_SetAttr(result, state->exc, value) == -1)
  4184. goto failed;
  4185. Py_DECREF(value);
  4186. value = ast2obj_expr(state, vstate, o->v.Raise.cause);
  4187. if (!value) goto failed;
  4188. if (PyObject_SetAttr(result, state->cause, value) == -1)
  4189. goto failed;
  4190. Py_DECREF(value);
  4191. break;
  4192. case Try_kind:
  4193. tp = (PyTypeObject *)state->Try_type;
  4194. result = PyType_GenericNew(tp, NULL, NULL);
  4195. if (!result) goto failed;
  4196. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.body,
  4197. ast2obj_stmt);
  4198. if (!value) goto failed;
  4199. if (PyObject_SetAttr(result, state->body, value) == -1)
  4200. goto failed;
  4201. Py_DECREF(value);
  4202. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.handlers,
  4203. ast2obj_excepthandler);
  4204. if (!value) goto failed;
  4205. if (PyObject_SetAttr(result, state->handlers, value) == -1)
  4206. goto failed;
  4207. Py_DECREF(value);
  4208. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.orelse,
  4209. ast2obj_stmt);
  4210. if (!value) goto failed;
  4211. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4212. goto failed;
  4213. Py_DECREF(value);
  4214. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Try.finalbody,
  4215. ast2obj_stmt);
  4216. if (!value) goto failed;
  4217. if (PyObject_SetAttr(result, state->finalbody, value) == -1)
  4218. goto failed;
  4219. Py_DECREF(value);
  4220. break;
  4221. case TryStar_kind:
  4222. tp = (PyTypeObject *)state->TryStar_type;
  4223. result = PyType_GenericNew(tp, NULL, NULL);
  4224. if (!result) goto failed;
  4225. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.body,
  4226. ast2obj_stmt);
  4227. if (!value) goto failed;
  4228. if (PyObject_SetAttr(result, state->body, value) == -1)
  4229. goto failed;
  4230. Py_DECREF(value);
  4231. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.handlers,
  4232. ast2obj_excepthandler);
  4233. if (!value) goto failed;
  4234. if (PyObject_SetAttr(result, state->handlers, value) == -1)
  4235. goto failed;
  4236. Py_DECREF(value);
  4237. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.orelse,
  4238. ast2obj_stmt);
  4239. if (!value) goto failed;
  4240. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4241. goto failed;
  4242. Py_DECREF(value);
  4243. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.TryStar.finalbody,
  4244. ast2obj_stmt);
  4245. if (!value) goto failed;
  4246. if (PyObject_SetAttr(result, state->finalbody, value) == -1)
  4247. goto failed;
  4248. Py_DECREF(value);
  4249. break;
  4250. case Assert_kind:
  4251. tp = (PyTypeObject *)state->Assert_type;
  4252. result = PyType_GenericNew(tp, NULL, NULL);
  4253. if (!result) goto failed;
  4254. value = ast2obj_expr(state, vstate, o->v.Assert.test);
  4255. if (!value) goto failed;
  4256. if (PyObject_SetAttr(result, state->test, value) == -1)
  4257. goto failed;
  4258. Py_DECREF(value);
  4259. value = ast2obj_expr(state, vstate, o->v.Assert.msg);
  4260. if (!value) goto failed;
  4261. if (PyObject_SetAttr(result, state->msg, value) == -1)
  4262. goto failed;
  4263. Py_DECREF(value);
  4264. break;
  4265. case Import_kind:
  4266. tp = (PyTypeObject *)state->Import_type;
  4267. result = PyType_GenericNew(tp, NULL, NULL);
  4268. if (!result) goto failed;
  4269. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Import.names,
  4270. ast2obj_alias);
  4271. if (!value) goto failed;
  4272. if (PyObject_SetAttr(result, state->names, value) == -1)
  4273. goto failed;
  4274. Py_DECREF(value);
  4275. break;
  4276. case ImportFrom_kind:
  4277. tp = (PyTypeObject *)state->ImportFrom_type;
  4278. result = PyType_GenericNew(tp, NULL, NULL);
  4279. if (!result) goto failed;
  4280. value = ast2obj_identifier(state, vstate, o->v.ImportFrom.module);
  4281. if (!value) goto failed;
  4282. if (PyObject_SetAttr(result, state->module, value) == -1)
  4283. goto failed;
  4284. Py_DECREF(value);
  4285. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ImportFrom.names,
  4286. ast2obj_alias);
  4287. if (!value) goto failed;
  4288. if (PyObject_SetAttr(result, state->names, value) == -1)
  4289. goto failed;
  4290. Py_DECREF(value);
  4291. value = ast2obj_int(state, vstate, o->v.ImportFrom.level);
  4292. if (!value) goto failed;
  4293. if (PyObject_SetAttr(result, state->level, value) == -1)
  4294. goto failed;
  4295. Py_DECREF(value);
  4296. break;
  4297. case Global_kind:
  4298. tp = (PyTypeObject *)state->Global_type;
  4299. result = PyType_GenericNew(tp, NULL, NULL);
  4300. if (!result) goto failed;
  4301. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Global.names,
  4302. ast2obj_identifier);
  4303. if (!value) goto failed;
  4304. if (PyObject_SetAttr(result, state->names, value) == -1)
  4305. goto failed;
  4306. Py_DECREF(value);
  4307. break;
  4308. case Nonlocal_kind:
  4309. tp = (PyTypeObject *)state->Nonlocal_type;
  4310. result = PyType_GenericNew(tp, NULL, NULL);
  4311. if (!result) goto failed;
  4312. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Nonlocal.names,
  4313. ast2obj_identifier);
  4314. if (!value) goto failed;
  4315. if (PyObject_SetAttr(result, state->names, value) == -1)
  4316. goto failed;
  4317. Py_DECREF(value);
  4318. break;
  4319. case Expr_kind:
  4320. tp = (PyTypeObject *)state->Expr_type;
  4321. result = PyType_GenericNew(tp, NULL, NULL);
  4322. if (!result) goto failed;
  4323. value = ast2obj_expr(state, vstate, o->v.Expr.value);
  4324. if (!value) goto failed;
  4325. if (PyObject_SetAttr(result, state->value, value) == -1)
  4326. goto failed;
  4327. Py_DECREF(value);
  4328. break;
  4329. case Pass_kind:
  4330. tp = (PyTypeObject *)state->Pass_type;
  4331. result = PyType_GenericNew(tp, NULL, NULL);
  4332. if (!result) goto failed;
  4333. break;
  4334. case Break_kind:
  4335. tp = (PyTypeObject *)state->Break_type;
  4336. result = PyType_GenericNew(tp, NULL, NULL);
  4337. if (!result) goto failed;
  4338. break;
  4339. case Continue_kind:
  4340. tp = (PyTypeObject *)state->Continue_type;
  4341. result = PyType_GenericNew(tp, NULL, NULL);
  4342. if (!result) goto failed;
  4343. break;
  4344. }
  4345. value = ast2obj_int(state, vstate, o->lineno);
  4346. if (!value) goto failed;
  4347. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  4348. goto failed;
  4349. Py_DECREF(value);
  4350. value = ast2obj_int(state, vstate, o->col_offset);
  4351. if (!value) goto failed;
  4352. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  4353. goto failed;
  4354. Py_DECREF(value);
  4355. value = ast2obj_int(state, vstate, o->end_lineno);
  4356. if (!value) goto failed;
  4357. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  4358. goto failed;
  4359. Py_DECREF(value);
  4360. value = ast2obj_int(state, vstate, o->end_col_offset);
  4361. if (!value) goto failed;
  4362. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  4363. goto failed;
  4364. Py_DECREF(value);
  4365. vstate->recursion_depth--;
  4366. return result;
  4367. failed:
  4368. vstate->recursion_depth--;
  4369. Py_XDECREF(value);
  4370. Py_XDECREF(result);
  4371. return NULL;
  4372. }
  4373. PyObject*
  4374. ast2obj_expr(struct ast_state *state, struct validator *vstate, void* _o)
  4375. {
  4376. expr_ty o = (expr_ty)_o;
  4377. PyObject *result = NULL, *value = NULL;
  4378. PyTypeObject *tp;
  4379. if (!o) {
  4380. Py_RETURN_NONE;
  4381. }
  4382. if (++vstate->recursion_depth > vstate->recursion_limit) {
  4383. PyErr_SetString(PyExc_RecursionError,
  4384. "maximum recursion depth exceeded during ast construction");
  4385. return 0;
  4386. }
  4387. switch (o->kind) {
  4388. case BoolOp_kind:
  4389. tp = (PyTypeObject *)state->BoolOp_type;
  4390. result = PyType_GenericNew(tp, NULL, NULL);
  4391. if (!result) goto failed;
  4392. value = ast2obj_boolop(state, vstate, o->v.BoolOp.op);
  4393. if (!value) goto failed;
  4394. if (PyObject_SetAttr(result, state->op, value) == -1)
  4395. goto failed;
  4396. Py_DECREF(value);
  4397. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.BoolOp.values,
  4398. ast2obj_expr);
  4399. if (!value) goto failed;
  4400. if (PyObject_SetAttr(result, state->values, value) == -1)
  4401. goto failed;
  4402. Py_DECREF(value);
  4403. break;
  4404. case NamedExpr_kind:
  4405. tp = (PyTypeObject *)state->NamedExpr_type;
  4406. result = PyType_GenericNew(tp, NULL, NULL);
  4407. if (!result) goto failed;
  4408. value = ast2obj_expr(state, vstate, o->v.NamedExpr.target);
  4409. if (!value) goto failed;
  4410. if (PyObject_SetAttr(result, state->target, value) == -1)
  4411. goto failed;
  4412. Py_DECREF(value);
  4413. value = ast2obj_expr(state, vstate, o->v.NamedExpr.value);
  4414. if (!value) goto failed;
  4415. if (PyObject_SetAttr(result, state->value, value) == -1)
  4416. goto failed;
  4417. Py_DECREF(value);
  4418. break;
  4419. case BinOp_kind:
  4420. tp = (PyTypeObject *)state->BinOp_type;
  4421. result = PyType_GenericNew(tp, NULL, NULL);
  4422. if (!result) goto failed;
  4423. value = ast2obj_expr(state, vstate, o->v.BinOp.left);
  4424. if (!value) goto failed;
  4425. if (PyObject_SetAttr(result, state->left, value) == -1)
  4426. goto failed;
  4427. Py_DECREF(value);
  4428. value = ast2obj_operator(state, vstate, o->v.BinOp.op);
  4429. if (!value) goto failed;
  4430. if (PyObject_SetAttr(result, state->op, value) == -1)
  4431. goto failed;
  4432. Py_DECREF(value);
  4433. value = ast2obj_expr(state, vstate, o->v.BinOp.right);
  4434. if (!value) goto failed;
  4435. if (PyObject_SetAttr(result, state->right, value) == -1)
  4436. goto failed;
  4437. Py_DECREF(value);
  4438. break;
  4439. case UnaryOp_kind:
  4440. tp = (PyTypeObject *)state->UnaryOp_type;
  4441. result = PyType_GenericNew(tp, NULL, NULL);
  4442. if (!result) goto failed;
  4443. value = ast2obj_unaryop(state, vstate, o->v.UnaryOp.op);
  4444. if (!value) goto failed;
  4445. if (PyObject_SetAttr(result, state->op, value) == -1)
  4446. goto failed;
  4447. Py_DECREF(value);
  4448. value = ast2obj_expr(state, vstate, o->v.UnaryOp.operand);
  4449. if (!value) goto failed;
  4450. if (PyObject_SetAttr(result, state->operand, value) == -1)
  4451. goto failed;
  4452. Py_DECREF(value);
  4453. break;
  4454. case Lambda_kind:
  4455. tp = (PyTypeObject *)state->Lambda_type;
  4456. result = PyType_GenericNew(tp, NULL, NULL);
  4457. if (!result) goto failed;
  4458. value = ast2obj_arguments(state, vstate, o->v.Lambda.args);
  4459. if (!value) goto failed;
  4460. if (PyObject_SetAttr(result, state->args, value) == -1)
  4461. goto failed;
  4462. Py_DECREF(value);
  4463. value = ast2obj_expr(state, vstate, o->v.Lambda.body);
  4464. if (!value) goto failed;
  4465. if (PyObject_SetAttr(result, state->body, value) == -1)
  4466. goto failed;
  4467. Py_DECREF(value);
  4468. break;
  4469. case IfExp_kind:
  4470. tp = (PyTypeObject *)state->IfExp_type;
  4471. result = PyType_GenericNew(tp, NULL, NULL);
  4472. if (!result) goto failed;
  4473. value = ast2obj_expr(state, vstate, o->v.IfExp.test);
  4474. if (!value) goto failed;
  4475. if (PyObject_SetAttr(result, state->test, value) == -1)
  4476. goto failed;
  4477. Py_DECREF(value);
  4478. value = ast2obj_expr(state, vstate, o->v.IfExp.body);
  4479. if (!value) goto failed;
  4480. if (PyObject_SetAttr(result, state->body, value) == -1)
  4481. goto failed;
  4482. Py_DECREF(value);
  4483. value = ast2obj_expr(state, vstate, o->v.IfExp.orelse);
  4484. if (!value) goto failed;
  4485. if (PyObject_SetAttr(result, state->orelse, value) == -1)
  4486. goto failed;
  4487. Py_DECREF(value);
  4488. break;
  4489. case Dict_kind:
  4490. tp = (PyTypeObject *)state->Dict_type;
  4491. result = PyType_GenericNew(tp, NULL, NULL);
  4492. if (!result) goto failed;
  4493. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Dict.keys,
  4494. ast2obj_expr);
  4495. if (!value) goto failed;
  4496. if (PyObject_SetAttr(result, state->keys, value) == -1)
  4497. goto failed;
  4498. Py_DECREF(value);
  4499. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Dict.values,
  4500. ast2obj_expr);
  4501. if (!value) goto failed;
  4502. if (PyObject_SetAttr(result, state->values, value) == -1)
  4503. goto failed;
  4504. Py_DECREF(value);
  4505. break;
  4506. case Set_kind:
  4507. tp = (PyTypeObject *)state->Set_type;
  4508. result = PyType_GenericNew(tp, NULL, NULL);
  4509. if (!result) goto failed;
  4510. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Set.elts,
  4511. ast2obj_expr);
  4512. if (!value) goto failed;
  4513. if (PyObject_SetAttr(result, state->elts, value) == -1)
  4514. goto failed;
  4515. Py_DECREF(value);
  4516. break;
  4517. case ListComp_kind:
  4518. tp = (PyTypeObject *)state->ListComp_type;
  4519. result = PyType_GenericNew(tp, NULL, NULL);
  4520. if (!result) goto failed;
  4521. value = ast2obj_expr(state, vstate, o->v.ListComp.elt);
  4522. if (!value) goto failed;
  4523. if (PyObject_SetAttr(result, state->elt, value) == -1)
  4524. goto failed;
  4525. Py_DECREF(value);
  4526. value = ast2obj_list(state, vstate,
  4527. (asdl_seq*)o->v.ListComp.generators,
  4528. ast2obj_comprehension);
  4529. if (!value) goto failed;
  4530. if (PyObject_SetAttr(result, state->generators, value) == -1)
  4531. goto failed;
  4532. Py_DECREF(value);
  4533. break;
  4534. case SetComp_kind:
  4535. tp = (PyTypeObject *)state->SetComp_type;
  4536. result = PyType_GenericNew(tp, NULL, NULL);
  4537. if (!result) goto failed;
  4538. value = ast2obj_expr(state, vstate, o->v.SetComp.elt);
  4539. if (!value) goto failed;
  4540. if (PyObject_SetAttr(result, state->elt, value) == -1)
  4541. goto failed;
  4542. Py_DECREF(value);
  4543. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.SetComp.generators,
  4544. ast2obj_comprehension);
  4545. if (!value) goto failed;
  4546. if (PyObject_SetAttr(result, state->generators, value) == -1)
  4547. goto failed;
  4548. Py_DECREF(value);
  4549. break;
  4550. case DictComp_kind:
  4551. tp = (PyTypeObject *)state->DictComp_type;
  4552. result = PyType_GenericNew(tp, NULL, NULL);
  4553. if (!result) goto failed;
  4554. value = ast2obj_expr(state, vstate, o->v.DictComp.key);
  4555. if (!value) goto failed;
  4556. if (PyObject_SetAttr(result, state->key, value) == -1)
  4557. goto failed;
  4558. Py_DECREF(value);
  4559. value = ast2obj_expr(state, vstate, o->v.DictComp.value);
  4560. if (!value) goto failed;
  4561. if (PyObject_SetAttr(result, state->value, value) == -1)
  4562. goto failed;
  4563. Py_DECREF(value);
  4564. value = ast2obj_list(state, vstate,
  4565. (asdl_seq*)o->v.DictComp.generators,
  4566. ast2obj_comprehension);
  4567. if (!value) goto failed;
  4568. if (PyObject_SetAttr(result, state->generators, value) == -1)
  4569. goto failed;
  4570. Py_DECREF(value);
  4571. break;
  4572. case GeneratorExp_kind:
  4573. tp = (PyTypeObject *)state->GeneratorExp_type;
  4574. result = PyType_GenericNew(tp, NULL, NULL);
  4575. if (!result) goto failed;
  4576. value = ast2obj_expr(state, vstate, o->v.GeneratorExp.elt);
  4577. if (!value) goto failed;
  4578. if (PyObject_SetAttr(result, state->elt, value) == -1)
  4579. goto failed;
  4580. Py_DECREF(value);
  4581. value = ast2obj_list(state, vstate,
  4582. (asdl_seq*)o->v.GeneratorExp.generators,
  4583. ast2obj_comprehension);
  4584. if (!value) goto failed;
  4585. if (PyObject_SetAttr(result, state->generators, value) == -1)
  4586. goto failed;
  4587. Py_DECREF(value);
  4588. break;
  4589. case Await_kind:
  4590. tp = (PyTypeObject *)state->Await_type;
  4591. result = PyType_GenericNew(tp, NULL, NULL);
  4592. if (!result) goto failed;
  4593. value = ast2obj_expr(state, vstate, o->v.Await.value);
  4594. if (!value) goto failed;
  4595. if (PyObject_SetAttr(result, state->value, value) == -1)
  4596. goto failed;
  4597. Py_DECREF(value);
  4598. break;
  4599. case Yield_kind:
  4600. tp = (PyTypeObject *)state->Yield_type;
  4601. result = PyType_GenericNew(tp, NULL, NULL);
  4602. if (!result) goto failed;
  4603. value = ast2obj_expr(state, vstate, o->v.Yield.value);
  4604. if (!value) goto failed;
  4605. if (PyObject_SetAttr(result, state->value, value) == -1)
  4606. goto failed;
  4607. Py_DECREF(value);
  4608. break;
  4609. case YieldFrom_kind:
  4610. tp = (PyTypeObject *)state->YieldFrom_type;
  4611. result = PyType_GenericNew(tp, NULL, NULL);
  4612. if (!result) goto failed;
  4613. value = ast2obj_expr(state, vstate, o->v.YieldFrom.value);
  4614. if (!value) goto failed;
  4615. if (PyObject_SetAttr(result, state->value, value) == -1)
  4616. goto failed;
  4617. Py_DECREF(value);
  4618. break;
  4619. case Compare_kind:
  4620. tp = (PyTypeObject *)state->Compare_type;
  4621. result = PyType_GenericNew(tp, NULL, NULL);
  4622. if (!result) goto failed;
  4623. value = ast2obj_expr(state, vstate, o->v.Compare.left);
  4624. if (!value) goto failed;
  4625. if (PyObject_SetAttr(result, state->left, value) == -1)
  4626. goto failed;
  4627. Py_DECREF(value);
  4628. {
  4629. Py_ssize_t i, n = asdl_seq_LEN(o->v.Compare.ops);
  4630. value = PyList_New(n);
  4631. if (!value) goto failed;
  4632. for(i = 0; i < n; i++)
  4633. PyList_SET_ITEM(value, i, ast2obj_cmpop(state, vstate, (cmpop_ty)asdl_seq_GET(o->v.Compare.ops, i)));
  4634. }
  4635. if (!value) goto failed;
  4636. if (PyObject_SetAttr(result, state->ops, value) == -1)
  4637. goto failed;
  4638. Py_DECREF(value);
  4639. value = ast2obj_list(state, vstate,
  4640. (asdl_seq*)o->v.Compare.comparators, ast2obj_expr);
  4641. if (!value) goto failed;
  4642. if (PyObject_SetAttr(result, state->comparators, value) == -1)
  4643. goto failed;
  4644. Py_DECREF(value);
  4645. break;
  4646. case Call_kind:
  4647. tp = (PyTypeObject *)state->Call_type;
  4648. result = PyType_GenericNew(tp, NULL, NULL);
  4649. if (!result) goto failed;
  4650. value = ast2obj_expr(state, vstate, o->v.Call.func);
  4651. if (!value) goto failed;
  4652. if (PyObject_SetAttr(result, state->func, value) == -1)
  4653. goto failed;
  4654. Py_DECREF(value);
  4655. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Call.args,
  4656. ast2obj_expr);
  4657. if (!value) goto failed;
  4658. if (PyObject_SetAttr(result, state->args, value) == -1)
  4659. goto failed;
  4660. Py_DECREF(value);
  4661. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Call.keywords,
  4662. ast2obj_keyword);
  4663. if (!value) goto failed;
  4664. if (PyObject_SetAttr(result, state->keywords, value) == -1)
  4665. goto failed;
  4666. Py_DECREF(value);
  4667. break;
  4668. case FormattedValue_kind:
  4669. tp = (PyTypeObject *)state->FormattedValue_type;
  4670. result = PyType_GenericNew(tp, NULL, NULL);
  4671. if (!result) goto failed;
  4672. value = ast2obj_expr(state, vstate, o->v.FormattedValue.value);
  4673. if (!value) goto failed;
  4674. if (PyObject_SetAttr(result, state->value, value) == -1)
  4675. goto failed;
  4676. Py_DECREF(value);
  4677. value = ast2obj_int(state, vstate, o->v.FormattedValue.conversion);
  4678. if (!value) goto failed;
  4679. if (PyObject_SetAttr(result, state->conversion, value) == -1)
  4680. goto failed;
  4681. Py_DECREF(value);
  4682. value = ast2obj_expr(state, vstate, o->v.FormattedValue.format_spec);
  4683. if (!value) goto failed;
  4684. if (PyObject_SetAttr(result, state->format_spec, value) == -1)
  4685. goto failed;
  4686. Py_DECREF(value);
  4687. break;
  4688. case JoinedStr_kind:
  4689. tp = (PyTypeObject *)state->JoinedStr_type;
  4690. result = PyType_GenericNew(tp, NULL, NULL);
  4691. if (!result) goto failed;
  4692. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.JoinedStr.values,
  4693. ast2obj_expr);
  4694. if (!value) goto failed;
  4695. if (PyObject_SetAttr(result, state->values, value) == -1)
  4696. goto failed;
  4697. Py_DECREF(value);
  4698. break;
  4699. case Constant_kind:
  4700. tp = (PyTypeObject *)state->Constant_type;
  4701. result = PyType_GenericNew(tp, NULL, NULL);
  4702. if (!result) goto failed;
  4703. value = ast2obj_constant(state, vstate, o->v.Constant.value);
  4704. if (!value) goto failed;
  4705. if (PyObject_SetAttr(result, state->value, value) == -1)
  4706. goto failed;
  4707. Py_DECREF(value);
  4708. value = ast2obj_string(state, vstate, o->v.Constant.kind);
  4709. if (!value) goto failed;
  4710. if (PyObject_SetAttr(result, state->kind, value) == -1)
  4711. goto failed;
  4712. Py_DECREF(value);
  4713. break;
  4714. case Attribute_kind:
  4715. tp = (PyTypeObject *)state->Attribute_type;
  4716. result = PyType_GenericNew(tp, NULL, NULL);
  4717. if (!result) goto failed;
  4718. value = ast2obj_expr(state, vstate, o->v.Attribute.value);
  4719. if (!value) goto failed;
  4720. if (PyObject_SetAttr(result, state->value, value) == -1)
  4721. goto failed;
  4722. Py_DECREF(value);
  4723. value = ast2obj_identifier(state, vstate, o->v.Attribute.attr);
  4724. if (!value) goto failed;
  4725. if (PyObject_SetAttr(result, state->attr, value) == -1)
  4726. goto failed;
  4727. Py_DECREF(value);
  4728. value = ast2obj_expr_context(state, vstate, o->v.Attribute.ctx);
  4729. if (!value) goto failed;
  4730. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4731. goto failed;
  4732. Py_DECREF(value);
  4733. break;
  4734. case Subscript_kind:
  4735. tp = (PyTypeObject *)state->Subscript_type;
  4736. result = PyType_GenericNew(tp, NULL, NULL);
  4737. if (!result) goto failed;
  4738. value = ast2obj_expr(state, vstate, o->v.Subscript.value);
  4739. if (!value) goto failed;
  4740. if (PyObject_SetAttr(result, state->value, value) == -1)
  4741. goto failed;
  4742. Py_DECREF(value);
  4743. value = ast2obj_expr(state, vstate, o->v.Subscript.slice);
  4744. if (!value) goto failed;
  4745. if (PyObject_SetAttr(result, state->slice, value) == -1)
  4746. goto failed;
  4747. Py_DECREF(value);
  4748. value = ast2obj_expr_context(state, vstate, o->v.Subscript.ctx);
  4749. if (!value) goto failed;
  4750. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4751. goto failed;
  4752. Py_DECREF(value);
  4753. break;
  4754. case Starred_kind:
  4755. tp = (PyTypeObject *)state->Starred_type;
  4756. result = PyType_GenericNew(tp, NULL, NULL);
  4757. if (!result) goto failed;
  4758. value = ast2obj_expr(state, vstate, o->v.Starred.value);
  4759. if (!value) goto failed;
  4760. if (PyObject_SetAttr(result, state->value, value) == -1)
  4761. goto failed;
  4762. Py_DECREF(value);
  4763. value = ast2obj_expr_context(state, vstate, o->v.Starred.ctx);
  4764. if (!value) goto failed;
  4765. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4766. goto failed;
  4767. Py_DECREF(value);
  4768. break;
  4769. case Name_kind:
  4770. tp = (PyTypeObject *)state->Name_type;
  4771. result = PyType_GenericNew(tp, NULL, NULL);
  4772. if (!result) goto failed;
  4773. value = ast2obj_identifier(state, vstate, o->v.Name.id);
  4774. if (!value) goto failed;
  4775. if (PyObject_SetAttr(result, state->id, value) == -1)
  4776. goto failed;
  4777. Py_DECREF(value);
  4778. value = ast2obj_expr_context(state, vstate, o->v.Name.ctx);
  4779. if (!value) goto failed;
  4780. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4781. goto failed;
  4782. Py_DECREF(value);
  4783. break;
  4784. case List_kind:
  4785. tp = (PyTypeObject *)state->List_type;
  4786. result = PyType_GenericNew(tp, NULL, NULL);
  4787. if (!result) goto failed;
  4788. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.List.elts,
  4789. ast2obj_expr);
  4790. if (!value) goto failed;
  4791. if (PyObject_SetAttr(result, state->elts, value) == -1)
  4792. goto failed;
  4793. Py_DECREF(value);
  4794. value = ast2obj_expr_context(state, vstate, o->v.List.ctx);
  4795. if (!value) goto failed;
  4796. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4797. goto failed;
  4798. Py_DECREF(value);
  4799. break;
  4800. case Tuple_kind:
  4801. tp = (PyTypeObject *)state->Tuple_type;
  4802. result = PyType_GenericNew(tp, NULL, NULL);
  4803. if (!result) goto failed;
  4804. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.Tuple.elts,
  4805. ast2obj_expr);
  4806. if (!value) goto failed;
  4807. if (PyObject_SetAttr(result, state->elts, value) == -1)
  4808. goto failed;
  4809. Py_DECREF(value);
  4810. value = ast2obj_expr_context(state, vstate, o->v.Tuple.ctx);
  4811. if (!value) goto failed;
  4812. if (PyObject_SetAttr(result, state->ctx, value) == -1)
  4813. goto failed;
  4814. Py_DECREF(value);
  4815. break;
  4816. case Slice_kind:
  4817. tp = (PyTypeObject *)state->Slice_type;
  4818. result = PyType_GenericNew(tp, NULL, NULL);
  4819. if (!result) goto failed;
  4820. value = ast2obj_expr(state, vstate, o->v.Slice.lower);
  4821. if (!value) goto failed;
  4822. if (PyObject_SetAttr(result, state->lower, value) == -1)
  4823. goto failed;
  4824. Py_DECREF(value);
  4825. value = ast2obj_expr(state, vstate, o->v.Slice.upper);
  4826. if (!value) goto failed;
  4827. if (PyObject_SetAttr(result, state->upper, value) == -1)
  4828. goto failed;
  4829. Py_DECREF(value);
  4830. value = ast2obj_expr(state, vstate, o->v.Slice.step);
  4831. if (!value) goto failed;
  4832. if (PyObject_SetAttr(result, state->step, value) == -1)
  4833. goto failed;
  4834. Py_DECREF(value);
  4835. break;
  4836. }
  4837. value = ast2obj_int(state, vstate, o->lineno);
  4838. if (!value) goto failed;
  4839. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  4840. goto failed;
  4841. Py_DECREF(value);
  4842. value = ast2obj_int(state, vstate, o->col_offset);
  4843. if (!value) goto failed;
  4844. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  4845. goto failed;
  4846. Py_DECREF(value);
  4847. value = ast2obj_int(state, vstate, o->end_lineno);
  4848. if (!value) goto failed;
  4849. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  4850. goto failed;
  4851. Py_DECREF(value);
  4852. value = ast2obj_int(state, vstate, o->end_col_offset);
  4853. if (!value) goto failed;
  4854. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  4855. goto failed;
  4856. Py_DECREF(value);
  4857. vstate->recursion_depth--;
  4858. return result;
  4859. failed:
  4860. vstate->recursion_depth--;
  4861. Py_XDECREF(value);
  4862. Py_XDECREF(result);
  4863. return NULL;
  4864. }
  4865. PyObject* ast2obj_expr_context(struct ast_state *state, struct validator
  4866. *vstate, expr_context_ty o)
  4867. {
  4868. switch(o) {
  4869. case Load:
  4870. return Py_NewRef(state->Load_singleton);
  4871. case Store:
  4872. return Py_NewRef(state->Store_singleton);
  4873. case Del:
  4874. return Py_NewRef(state->Del_singleton);
  4875. }
  4876. Py_UNREACHABLE();
  4877. }
  4878. PyObject* ast2obj_boolop(struct ast_state *state, struct validator *vstate,
  4879. boolop_ty o)
  4880. {
  4881. switch(o) {
  4882. case And:
  4883. return Py_NewRef(state->And_singleton);
  4884. case Or:
  4885. return Py_NewRef(state->Or_singleton);
  4886. }
  4887. Py_UNREACHABLE();
  4888. }
  4889. PyObject* ast2obj_operator(struct ast_state *state, struct validator *vstate,
  4890. operator_ty o)
  4891. {
  4892. switch(o) {
  4893. case Add:
  4894. return Py_NewRef(state->Add_singleton);
  4895. case Sub:
  4896. return Py_NewRef(state->Sub_singleton);
  4897. case Mult:
  4898. return Py_NewRef(state->Mult_singleton);
  4899. case MatMult:
  4900. return Py_NewRef(state->MatMult_singleton);
  4901. case Div:
  4902. return Py_NewRef(state->Div_singleton);
  4903. case Mod:
  4904. return Py_NewRef(state->Mod_singleton);
  4905. case Pow:
  4906. return Py_NewRef(state->Pow_singleton);
  4907. case LShift:
  4908. return Py_NewRef(state->LShift_singleton);
  4909. case RShift:
  4910. return Py_NewRef(state->RShift_singleton);
  4911. case BitOr:
  4912. return Py_NewRef(state->BitOr_singleton);
  4913. case BitXor:
  4914. return Py_NewRef(state->BitXor_singleton);
  4915. case BitAnd:
  4916. return Py_NewRef(state->BitAnd_singleton);
  4917. case FloorDiv:
  4918. return Py_NewRef(state->FloorDiv_singleton);
  4919. }
  4920. Py_UNREACHABLE();
  4921. }
  4922. PyObject* ast2obj_unaryop(struct ast_state *state, struct validator *vstate,
  4923. unaryop_ty o)
  4924. {
  4925. switch(o) {
  4926. case Invert:
  4927. return Py_NewRef(state->Invert_singleton);
  4928. case Not:
  4929. return Py_NewRef(state->Not_singleton);
  4930. case UAdd:
  4931. return Py_NewRef(state->UAdd_singleton);
  4932. case USub:
  4933. return Py_NewRef(state->USub_singleton);
  4934. }
  4935. Py_UNREACHABLE();
  4936. }
  4937. PyObject* ast2obj_cmpop(struct ast_state *state, struct validator *vstate,
  4938. cmpop_ty o)
  4939. {
  4940. switch(o) {
  4941. case Eq:
  4942. return Py_NewRef(state->Eq_singleton);
  4943. case NotEq:
  4944. return Py_NewRef(state->NotEq_singleton);
  4945. case Lt:
  4946. return Py_NewRef(state->Lt_singleton);
  4947. case LtE:
  4948. return Py_NewRef(state->LtE_singleton);
  4949. case Gt:
  4950. return Py_NewRef(state->Gt_singleton);
  4951. case GtE:
  4952. return Py_NewRef(state->GtE_singleton);
  4953. case Is:
  4954. return Py_NewRef(state->Is_singleton);
  4955. case IsNot:
  4956. return Py_NewRef(state->IsNot_singleton);
  4957. case In:
  4958. return Py_NewRef(state->In_singleton);
  4959. case NotIn:
  4960. return Py_NewRef(state->NotIn_singleton);
  4961. }
  4962. Py_UNREACHABLE();
  4963. }
  4964. PyObject*
  4965. ast2obj_comprehension(struct ast_state *state, struct validator *vstate, void*
  4966. _o)
  4967. {
  4968. comprehension_ty o = (comprehension_ty)_o;
  4969. PyObject *result = NULL, *value = NULL;
  4970. PyTypeObject *tp;
  4971. if (!o) {
  4972. Py_RETURN_NONE;
  4973. }
  4974. if (++vstate->recursion_depth > vstate->recursion_limit) {
  4975. PyErr_SetString(PyExc_RecursionError,
  4976. "maximum recursion depth exceeded during ast construction");
  4977. return 0;
  4978. }
  4979. tp = (PyTypeObject *)state->comprehension_type;
  4980. result = PyType_GenericNew(tp, NULL, NULL);
  4981. if (!result) return NULL;
  4982. value = ast2obj_expr(state, vstate, o->target);
  4983. if (!value) goto failed;
  4984. if (PyObject_SetAttr(result, state->target, value) == -1)
  4985. goto failed;
  4986. Py_DECREF(value);
  4987. value = ast2obj_expr(state, vstate, o->iter);
  4988. if (!value) goto failed;
  4989. if (PyObject_SetAttr(result, state->iter, value) == -1)
  4990. goto failed;
  4991. Py_DECREF(value);
  4992. value = ast2obj_list(state, vstate, (asdl_seq*)o->ifs, ast2obj_expr);
  4993. if (!value) goto failed;
  4994. if (PyObject_SetAttr(result, state->ifs, value) == -1)
  4995. goto failed;
  4996. Py_DECREF(value);
  4997. value = ast2obj_int(state, vstate, o->is_async);
  4998. if (!value) goto failed;
  4999. if (PyObject_SetAttr(result, state->is_async, value) == -1)
  5000. goto failed;
  5001. Py_DECREF(value);
  5002. vstate->recursion_depth--;
  5003. return result;
  5004. failed:
  5005. vstate->recursion_depth--;
  5006. Py_XDECREF(value);
  5007. Py_XDECREF(result);
  5008. return NULL;
  5009. }
  5010. PyObject*
  5011. ast2obj_excepthandler(struct ast_state *state, struct validator *vstate, void*
  5012. _o)
  5013. {
  5014. excepthandler_ty o = (excepthandler_ty)_o;
  5015. PyObject *result = NULL, *value = NULL;
  5016. PyTypeObject *tp;
  5017. if (!o) {
  5018. Py_RETURN_NONE;
  5019. }
  5020. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5021. PyErr_SetString(PyExc_RecursionError,
  5022. "maximum recursion depth exceeded during ast construction");
  5023. return 0;
  5024. }
  5025. switch (o->kind) {
  5026. case ExceptHandler_kind:
  5027. tp = (PyTypeObject *)state->ExceptHandler_type;
  5028. result = PyType_GenericNew(tp, NULL, NULL);
  5029. if (!result) goto failed;
  5030. value = ast2obj_expr(state, vstate, o->v.ExceptHandler.type);
  5031. if (!value) goto failed;
  5032. if (PyObject_SetAttr(result, state->type, value) == -1)
  5033. goto failed;
  5034. Py_DECREF(value);
  5035. value = ast2obj_identifier(state, vstate, o->v.ExceptHandler.name);
  5036. if (!value) goto failed;
  5037. if (PyObject_SetAttr(result, state->name, value) == -1)
  5038. goto failed;
  5039. Py_DECREF(value);
  5040. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.ExceptHandler.body,
  5041. ast2obj_stmt);
  5042. if (!value) goto failed;
  5043. if (PyObject_SetAttr(result, state->body, value) == -1)
  5044. goto failed;
  5045. Py_DECREF(value);
  5046. break;
  5047. }
  5048. value = ast2obj_int(state, vstate, o->lineno);
  5049. if (!value) goto failed;
  5050. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5051. goto failed;
  5052. Py_DECREF(value);
  5053. value = ast2obj_int(state, vstate, o->col_offset);
  5054. if (!value) goto failed;
  5055. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5056. goto failed;
  5057. Py_DECREF(value);
  5058. value = ast2obj_int(state, vstate, o->end_lineno);
  5059. if (!value) goto failed;
  5060. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5061. goto failed;
  5062. Py_DECREF(value);
  5063. value = ast2obj_int(state, vstate, o->end_col_offset);
  5064. if (!value) goto failed;
  5065. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5066. goto failed;
  5067. Py_DECREF(value);
  5068. vstate->recursion_depth--;
  5069. return result;
  5070. failed:
  5071. vstate->recursion_depth--;
  5072. Py_XDECREF(value);
  5073. Py_XDECREF(result);
  5074. return NULL;
  5075. }
  5076. PyObject*
  5077. ast2obj_arguments(struct ast_state *state, struct validator *vstate, void* _o)
  5078. {
  5079. arguments_ty o = (arguments_ty)_o;
  5080. PyObject *result = NULL, *value = NULL;
  5081. PyTypeObject *tp;
  5082. if (!o) {
  5083. Py_RETURN_NONE;
  5084. }
  5085. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5086. PyErr_SetString(PyExc_RecursionError,
  5087. "maximum recursion depth exceeded during ast construction");
  5088. return 0;
  5089. }
  5090. tp = (PyTypeObject *)state->arguments_type;
  5091. result = PyType_GenericNew(tp, NULL, NULL);
  5092. if (!result) return NULL;
  5093. value = ast2obj_list(state, vstate, (asdl_seq*)o->posonlyargs, ast2obj_arg);
  5094. if (!value) goto failed;
  5095. if (PyObject_SetAttr(result, state->posonlyargs, value) == -1)
  5096. goto failed;
  5097. Py_DECREF(value);
  5098. value = ast2obj_list(state, vstate, (asdl_seq*)o->args, ast2obj_arg);
  5099. if (!value) goto failed;
  5100. if (PyObject_SetAttr(result, state->args, value) == -1)
  5101. goto failed;
  5102. Py_DECREF(value);
  5103. value = ast2obj_arg(state, vstate, o->vararg);
  5104. if (!value) goto failed;
  5105. if (PyObject_SetAttr(result, state->vararg, value) == -1)
  5106. goto failed;
  5107. Py_DECREF(value);
  5108. value = ast2obj_list(state, vstate, (asdl_seq*)o->kwonlyargs, ast2obj_arg);
  5109. if (!value) goto failed;
  5110. if (PyObject_SetAttr(result, state->kwonlyargs, value) == -1)
  5111. goto failed;
  5112. Py_DECREF(value);
  5113. value = ast2obj_list(state, vstate, (asdl_seq*)o->kw_defaults,
  5114. ast2obj_expr);
  5115. if (!value) goto failed;
  5116. if (PyObject_SetAttr(result, state->kw_defaults, value) == -1)
  5117. goto failed;
  5118. Py_DECREF(value);
  5119. value = ast2obj_arg(state, vstate, o->kwarg);
  5120. if (!value) goto failed;
  5121. if (PyObject_SetAttr(result, state->kwarg, value) == -1)
  5122. goto failed;
  5123. Py_DECREF(value);
  5124. value = ast2obj_list(state, vstate, (asdl_seq*)o->defaults, ast2obj_expr);
  5125. if (!value) goto failed;
  5126. if (PyObject_SetAttr(result, state->defaults, value) == -1)
  5127. goto failed;
  5128. Py_DECREF(value);
  5129. vstate->recursion_depth--;
  5130. return result;
  5131. failed:
  5132. vstate->recursion_depth--;
  5133. Py_XDECREF(value);
  5134. Py_XDECREF(result);
  5135. return NULL;
  5136. }
  5137. PyObject*
  5138. ast2obj_arg(struct ast_state *state, struct validator *vstate, void* _o)
  5139. {
  5140. arg_ty o = (arg_ty)_o;
  5141. PyObject *result = NULL, *value = NULL;
  5142. PyTypeObject *tp;
  5143. if (!o) {
  5144. Py_RETURN_NONE;
  5145. }
  5146. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5147. PyErr_SetString(PyExc_RecursionError,
  5148. "maximum recursion depth exceeded during ast construction");
  5149. return 0;
  5150. }
  5151. tp = (PyTypeObject *)state->arg_type;
  5152. result = PyType_GenericNew(tp, NULL, NULL);
  5153. if (!result) return NULL;
  5154. value = ast2obj_identifier(state, vstate, o->arg);
  5155. if (!value) goto failed;
  5156. if (PyObject_SetAttr(result, state->arg, value) == -1)
  5157. goto failed;
  5158. Py_DECREF(value);
  5159. value = ast2obj_expr(state, vstate, o->annotation);
  5160. if (!value) goto failed;
  5161. if (PyObject_SetAttr(result, state->annotation, value) == -1)
  5162. goto failed;
  5163. Py_DECREF(value);
  5164. value = ast2obj_string(state, vstate, o->type_comment);
  5165. if (!value) goto failed;
  5166. if (PyObject_SetAttr(result, state->type_comment, value) == -1)
  5167. goto failed;
  5168. Py_DECREF(value);
  5169. value = ast2obj_int(state, vstate, o->lineno);
  5170. if (!value) goto failed;
  5171. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5172. goto failed;
  5173. Py_DECREF(value);
  5174. value = ast2obj_int(state, vstate, o->col_offset);
  5175. if (!value) goto failed;
  5176. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5177. goto failed;
  5178. Py_DECREF(value);
  5179. value = ast2obj_int(state, vstate, o->end_lineno);
  5180. if (!value) goto failed;
  5181. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5182. goto failed;
  5183. Py_DECREF(value);
  5184. value = ast2obj_int(state, vstate, o->end_col_offset);
  5185. if (!value) goto failed;
  5186. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5187. goto failed;
  5188. Py_DECREF(value);
  5189. vstate->recursion_depth--;
  5190. return result;
  5191. failed:
  5192. vstate->recursion_depth--;
  5193. Py_XDECREF(value);
  5194. Py_XDECREF(result);
  5195. return NULL;
  5196. }
  5197. PyObject*
  5198. ast2obj_keyword(struct ast_state *state, struct validator *vstate, void* _o)
  5199. {
  5200. keyword_ty o = (keyword_ty)_o;
  5201. PyObject *result = NULL, *value = NULL;
  5202. PyTypeObject *tp;
  5203. if (!o) {
  5204. Py_RETURN_NONE;
  5205. }
  5206. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5207. PyErr_SetString(PyExc_RecursionError,
  5208. "maximum recursion depth exceeded during ast construction");
  5209. return 0;
  5210. }
  5211. tp = (PyTypeObject *)state->keyword_type;
  5212. result = PyType_GenericNew(tp, NULL, NULL);
  5213. if (!result) return NULL;
  5214. value = ast2obj_identifier(state, vstate, o->arg);
  5215. if (!value) goto failed;
  5216. if (PyObject_SetAttr(result, state->arg, value) == -1)
  5217. goto failed;
  5218. Py_DECREF(value);
  5219. value = ast2obj_expr(state, vstate, o->value);
  5220. if (!value) goto failed;
  5221. if (PyObject_SetAttr(result, state->value, value) == -1)
  5222. goto failed;
  5223. Py_DECREF(value);
  5224. value = ast2obj_int(state, vstate, o->lineno);
  5225. if (!value) goto failed;
  5226. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5227. goto failed;
  5228. Py_DECREF(value);
  5229. value = ast2obj_int(state, vstate, o->col_offset);
  5230. if (!value) goto failed;
  5231. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5232. goto failed;
  5233. Py_DECREF(value);
  5234. value = ast2obj_int(state, vstate, o->end_lineno);
  5235. if (!value) goto failed;
  5236. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5237. goto failed;
  5238. Py_DECREF(value);
  5239. value = ast2obj_int(state, vstate, o->end_col_offset);
  5240. if (!value) goto failed;
  5241. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5242. goto failed;
  5243. Py_DECREF(value);
  5244. vstate->recursion_depth--;
  5245. return result;
  5246. failed:
  5247. vstate->recursion_depth--;
  5248. Py_XDECREF(value);
  5249. Py_XDECREF(result);
  5250. return NULL;
  5251. }
  5252. PyObject*
  5253. ast2obj_alias(struct ast_state *state, struct validator *vstate, void* _o)
  5254. {
  5255. alias_ty o = (alias_ty)_o;
  5256. PyObject *result = NULL, *value = NULL;
  5257. PyTypeObject *tp;
  5258. if (!o) {
  5259. Py_RETURN_NONE;
  5260. }
  5261. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5262. PyErr_SetString(PyExc_RecursionError,
  5263. "maximum recursion depth exceeded during ast construction");
  5264. return 0;
  5265. }
  5266. tp = (PyTypeObject *)state->alias_type;
  5267. result = PyType_GenericNew(tp, NULL, NULL);
  5268. if (!result) return NULL;
  5269. value = ast2obj_identifier(state, vstate, o->name);
  5270. if (!value) goto failed;
  5271. if (PyObject_SetAttr(result, state->name, value) == -1)
  5272. goto failed;
  5273. Py_DECREF(value);
  5274. value = ast2obj_identifier(state, vstate, o->asname);
  5275. if (!value) goto failed;
  5276. if (PyObject_SetAttr(result, state->asname, value) == -1)
  5277. goto failed;
  5278. Py_DECREF(value);
  5279. value = ast2obj_int(state, vstate, o->lineno);
  5280. if (!value) goto failed;
  5281. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5282. goto failed;
  5283. Py_DECREF(value);
  5284. value = ast2obj_int(state, vstate, o->col_offset);
  5285. if (!value) goto failed;
  5286. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5287. goto failed;
  5288. Py_DECREF(value);
  5289. value = ast2obj_int(state, vstate, o->end_lineno);
  5290. if (!value) goto failed;
  5291. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5292. goto failed;
  5293. Py_DECREF(value);
  5294. value = ast2obj_int(state, vstate, o->end_col_offset);
  5295. if (!value) goto failed;
  5296. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5297. goto failed;
  5298. Py_DECREF(value);
  5299. vstate->recursion_depth--;
  5300. return result;
  5301. failed:
  5302. vstate->recursion_depth--;
  5303. Py_XDECREF(value);
  5304. Py_XDECREF(result);
  5305. return NULL;
  5306. }
  5307. PyObject*
  5308. ast2obj_withitem(struct ast_state *state, struct validator *vstate, void* _o)
  5309. {
  5310. withitem_ty o = (withitem_ty)_o;
  5311. PyObject *result = NULL, *value = NULL;
  5312. PyTypeObject *tp;
  5313. if (!o) {
  5314. Py_RETURN_NONE;
  5315. }
  5316. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5317. PyErr_SetString(PyExc_RecursionError,
  5318. "maximum recursion depth exceeded during ast construction");
  5319. return 0;
  5320. }
  5321. tp = (PyTypeObject *)state->withitem_type;
  5322. result = PyType_GenericNew(tp, NULL, NULL);
  5323. if (!result) return NULL;
  5324. value = ast2obj_expr(state, vstate, o->context_expr);
  5325. if (!value) goto failed;
  5326. if (PyObject_SetAttr(result, state->context_expr, value) == -1)
  5327. goto failed;
  5328. Py_DECREF(value);
  5329. value = ast2obj_expr(state, vstate, o->optional_vars);
  5330. if (!value) goto failed;
  5331. if (PyObject_SetAttr(result, state->optional_vars, value) == -1)
  5332. goto failed;
  5333. Py_DECREF(value);
  5334. vstate->recursion_depth--;
  5335. return result;
  5336. failed:
  5337. vstate->recursion_depth--;
  5338. Py_XDECREF(value);
  5339. Py_XDECREF(result);
  5340. return NULL;
  5341. }
  5342. PyObject*
  5343. ast2obj_match_case(struct ast_state *state, struct validator *vstate, void* _o)
  5344. {
  5345. match_case_ty o = (match_case_ty)_o;
  5346. PyObject *result = NULL, *value = NULL;
  5347. PyTypeObject *tp;
  5348. if (!o) {
  5349. Py_RETURN_NONE;
  5350. }
  5351. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5352. PyErr_SetString(PyExc_RecursionError,
  5353. "maximum recursion depth exceeded during ast construction");
  5354. return 0;
  5355. }
  5356. tp = (PyTypeObject *)state->match_case_type;
  5357. result = PyType_GenericNew(tp, NULL, NULL);
  5358. if (!result) return NULL;
  5359. value = ast2obj_pattern(state, vstate, o->pattern);
  5360. if (!value) goto failed;
  5361. if (PyObject_SetAttr(result, state->pattern, value) == -1)
  5362. goto failed;
  5363. Py_DECREF(value);
  5364. value = ast2obj_expr(state, vstate, o->guard);
  5365. if (!value) goto failed;
  5366. if (PyObject_SetAttr(result, state->guard, value) == -1)
  5367. goto failed;
  5368. Py_DECREF(value);
  5369. value = ast2obj_list(state, vstate, (asdl_seq*)o->body, ast2obj_stmt);
  5370. if (!value) goto failed;
  5371. if (PyObject_SetAttr(result, state->body, value) == -1)
  5372. goto failed;
  5373. Py_DECREF(value);
  5374. vstate->recursion_depth--;
  5375. return result;
  5376. failed:
  5377. vstate->recursion_depth--;
  5378. Py_XDECREF(value);
  5379. Py_XDECREF(result);
  5380. return NULL;
  5381. }
  5382. PyObject*
  5383. ast2obj_pattern(struct ast_state *state, struct validator *vstate, void* _o)
  5384. {
  5385. pattern_ty o = (pattern_ty)_o;
  5386. PyObject *result = NULL, *value = NULL;
  5387. PyTypeObject *tp;
  5388. if (!o) {
  5389. Py_RETURN_NONE;
  5390. }
  5391. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5392. PyErr_SetString(PyExc_RecursionError,
  5393. "maximum recursion depth exceeded during ast construction");
  5394. return 0;
  5395. }
  5396. switch (o->kind) {
  5397. case MatchValue_kind:
  5398. tp = (PyTypeObject *)state->MatchValue_type;
  5399. result = PyType_GenericNew(tp, NULL, NULL);
  5400. if (!result) goto failed;
  5401. value = ast2obj_expr(state, vstate, o->v.MatchValue.value);
  5402. if (!value) goto failed;
  5403. if (PyObject_SetAttr(result, state->value, value) == -1)
  5404. goto failed;
  5405. Py_DECREF(value);
  5406. break;
  5407. case MatchSingleton_kind:
  5408. tp = (PyTypeObject *)state->MatchSingleton_type;
  5409. result = PyType_GenericNew(tp, NULL, NULL);
  5410. if (!result) goto failed;
  5411. value = ast2obj_constant(state, vstate, o->v.MatchSingleton.value);
  5412. if (!value) goto failed;
  5413. if (PyObject_SetAttr(result, state->value, value) == -1)
  5414. goto failed;
  5415. Py_DECREF(value);
  5416. break;
  5417. case MatchSequence_kind:
  5418. tp = (PyTypeObject *)state->MatchSequence_type;
  5419. result = PyType_GenericNew(tp, NULL, NULL);
  5420. if (!result) goto failed;
  5421. value = ast2obj_list(state, vstate,
  5422. (asdl_seq*)o->v.MatchSequence.patterns,
  5423. ast2obj_pattern);
  5424. if (!value) goto failed;
  5425. if (PyObject_SetAttr(result, state->patterns, value) == -1)
  5426. goto failed;
  5427. Py_DECREF(value);
  5428. break;
  5429. case MatchMapping_kind:
  5430. tp = (PyTypeObject *)state->MatchMapping_type;
  5431. result = PyType_GenericNew(tp, NULL, NULL);
  5432. if (!result) goto failed;
  5433. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.MatchMapping.keys,
  5434. ast2obj_expr);
  5435. if (!value) goto failed;
  5436. if (PyObject_SetAttr(result, state->keys, value) == -1)
  5437. goto failed;
  5438. Py_DECREF(value);
  5439. value = ast2obj_list(state, vstate,
  5440. (asdl_seq*)o->v.MatchMapping.patterns,
  5441. ast2obj_pattern);
  5442. if (!value) goto failed;
  5443. if (PyObject_SetAttr(result, state->patterns, value) == -1)
  5444. goto failed;
  5445. Py_DECREF(value);
  5446. value = ast2obj_identifier(state, vstate, o->v.MatchMapping.rest);
  5447. if (!value) goto failed;
  5448. if (PyObject_SetAttr(result, state->rest, value) == -1)
  5449. goto failed;
  5450. Py_DECREF(value);
  5451. break;
  5452. case MatchClass_kind:
  5453. tp = (PyTypeObject *)state->MatchClass_type;
  5454. result = PyType_GenericNew(tp, NULL, NULL);
  5455. if (!result) goto failed;
  5456. value = ast2obj_expr(state, vstate, o->v.MatchClass.cls);
  5457. if (!value) goto failed;
  5458. if (PyObject_SetAttr(result, state->cls, value) == -1)
  5459. goto failed;
  5460. Py_DECREF(value);
  5461. value = ast2obj_list(state, vstate,
  5462. (asdl_seq*)o->v.MatchClass.patterns,
  5463. ast2obj_pattern);
  5464. if (!value) goto failed;
  5465. if (PyObject_SetAttr(result, state->patterns, value) == -1)
  5466. goto failed;
  5467. Py_DECREF(value);
  5468. value = ast2obj_list(state, vstate,
  5469. (asdl_seq*)o->v.MatchClass.kwd_attrs,
  5470. ast2obj_identifier);
  5471. if (!value) goto failed;
  5472. if (PyObject_SetAttr(result, state->kwd_attrs, value) == -1)
  5473. goto failed;
  5474. Py_DECREF(value);
  5475. value = ast2obj_list(state, vstate,
  5476. (asdl_seq*)o->v.MatchClass.kwd_patterns,
  5477. ast2obj_pattern);
  5478. if (!value) goto failed;
  5479. if (PyObject_SetAttr(result, state->kwd_patterns, value) == -1)
  5480. goto failed;
  5481. Py_DECREF(value);
  5482. break;
  5483. case MatchStar_kind:
  5484. tp = (PyTypeObject *)state->MatchStar_type;
  5485. result = PyType_GenericNew(tp, NULL, NULL);
  5486. if (!result) goto failed;
  5487. value = ast2obj_identifier(state, vstate, o->v.MatchStar.name);
  5488. if (!value) goto failed;
  5489. if (PyObject_SetAttr(result, state->name, value) == -1)
  5490. goto failed;
  5491. Py_DECREF(value);
  5492. break;
  5493. case MatchAs_kind:
  5494. tp = (PyTypeObject *)state->MatchAs_type;
  5495. result = PyType_GenericNew(tp, NULL, NULL);
  5496. if (!result) goto failed;
  5497. value = ast2obj_pattern(state, vstate, o->v.MatchAs.pattern);
  5498. if (!value) goto failed;
  5499. if (PyObject_SetAttr(result, state->pattern, value) == -1)
  5500. goto failed;
  5501. Py_DECREF(value);
  5502. value = ast2obj_identifier(state, vstate, o->v.MatchAs.name);
  5503. if (!value) goto failed;
  5504. if (PyObject_SetAttr(result, state->name, value) == -1)
  5505. goto failed;
  5506. Py_DECREF(value);
  5507. break;
  5508. case MatchOr_kind:
  5509. tp = (PyTypeObject *)state->MatchOr_type;
  5510. result = PyType_GenericNew(tp, NULL, NULL);
  5511. if (!result) goto failed;
  5512. value = ast2obj_list(state, vstate, (asdl_seq*)o->v.MatchOr.patterns,
  5513. ast2obj_pattern);
  5514. if (!value) goto failed;
  5515. if (PyObject_SetAttr(result, state->patterns, value) == -1)
  5516. goto failed;
  5517. Py_DECREF(value);
  5518. break;
  5519. }
  5520. value = ast2obj_int(state, vstate, o->lineno);
  5521. if (!value) goto failed;
  5522. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5523. goto failed;
  5524. Py_DECREF(value);
  5525. value = ast2obj_int(state, vstate, o->col_offset);
  5526. if (!value) goto failed;
  5527. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5528. goto failed;
  5529. Py_DECREF(value);
  5530. value = ast2obj_int(state, vstate, o->end_lineno);
  5531. if (!value) goto failed;
  5532. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5533. goto failed;
  5534. Py_DECREF(value);
  5535. value = ast2obj_int(state, vstate, o->end_col_offset);
  5536. if (!value) goto failed;
  5537. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5538. goto failed;
  5539. Py_DECREF(value);
  5540. vstate->recursion_depth--;
  5541. return result;
  5542. failed:
  5543. vstate->recursion_depth--;
  5544. Py_XDECREF(value);
  5545. Py_XDECREF(result);
  5546. return NULL;
  5547. }
  5548. PyObject*
  5549. ast2obj_type_ignore(struct ast_state *state, struct validator *vstate, void* _o)
  5550. {
  5551. type_ignore_ty o = (type_ignore_ty)_o;
  5552. PyObject *result = NULL, *value = NULL;
  5553. PyTypeObject *tp;
  5554. if (!o) {
  5555. Py_RETURN_NONE;
  5556. }
  5557. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5558. PyErr_SetString(PyExc_RecursionError,
  5559. "maximum recursion depth exceeded during ast construction");
  5560. return 0;
  5561. }
  5562. switch (o->kind) {
  5563. case TypeIgnore_kind:
  5564. tp = (PyTypeObject *)state->TypeIgnore_type;
  5565. result = PyType_GenericNew(tp, NULL, NULL);
  5566. if (!result) goto failed;
  5567. value = ast2obj_int(state, vstate, o->v.TypeIgnore.lineno);
  5568. if (!value) goto failed;
  5569. if (PyObject_SetAttr(result, state->lineno, value) == -1)
  5570. goto failed;
  5571. Py_DECREF(value);
  5572. value = ast2obj_string(state, vstate, o->v.TypeIgnore.tag);
  5573. if (!value) goto failed;
  5574. if (PyObject_SetAttr(result, state->tag, value) == -1)
  5575. goto failed;
  5576. Py_DECREF(value);
  5577. break;
  5578. }
  5579. vstate->recursion_depth--;
  5580. return result;
  5581. failed:
  5582. vstate->recursion_depth--;
  5583. Py_XDECREF(value);
  5584. Py_XDECREF(result);
  5585. return NULL;
  5586. }
  5587. PyObject*
  5588. ast2obj_type_param(struct ast_state *state, struct validator *vstate, void* _o)
  5589. {
  5590. type_param_ty o = (type_param_ty)_o;
  5591. PyObject *result = NULL, *value = NULL;
  5592. PyTypeObject *tp;
  5593. if (!o) {
  5594. Py_RETURN_NONE;
  5595. }
  5596. if (++vstate->recursion_depth > vstate->recursion_limit) {
  5597. PyErr_SetString(PyExc_RecursionError,
  5598. "maximum recursion depth exceeded during ast construction");
  5599. return 0;
  5600. }
  5601. switch (o->kind) {
  5602. case TypeVar_kind:
  5603. tp = (PyTypeObject *)state->TypeVar_type;
  5604. result = PyType_GenericNew(tp, NULL, NULL);
  5605. if (!result) goto failed;
  5606. value = ast2obj_identifier(state, vstate, o->v.TypeVar.name);
  5607. if (!value) goto failed;
  5608. if (PyObject_SetAttr(result, state->name, value) == -1)
  5609. goto failed;
  5610. Py_DECREF(value);
  5611. value = ast2obj_expr(state, vstate, o->v.TypeVar.bound);
  5612. if (!value) goto failed;
  5613. if (PyObject_SetAttr(result, state->bound, value) == -1)
  5614. goto failed;
  5615. Py_DECREF(value);
  5616. break;
  5617. case ParamSpec_kind:
  5618. tp = (PyTypeObject *)state->ParamSpec_type;
  5619. result = PyType_GenericNew(tp, NULL, NULL);
  5620. if (!result) goto failed;
  5621. value = ast2obj_identifier(state, vstate, o->v.ParamSpec.name);
  5622. if (!value) goto failed;
  5623. if (PyObject_SetAttr(result, state->name, value) == -1)
  5624. goto failed;
  5625. Py_DECREF(value);
  5626. break;
  5627. case TypeVarTuple_kind:
  5628. tp = (PyTypeObject *)state->TypeVarTuple_type;
  5629. result = PyType_GenericNew(tp, NULL, NULL);
  5630. if (!result) goto failed;
  5631. value = ast2obj_identifier(state, vstate, o->v.TypeVarTuple.name);
  5632. if (!value) goto failed;
  5633. if (PyObject_SetAttr(result, state->name, value) == -1)
  5634. goto failed;
  5635. Py_DECREF(value);
  5636. break;
  5637. }
  5638. value = ast2obj_int(state, vstate, o->lineno);
  5639. if (!value) goto failed;
  5640. if (PyObject_SetAttr(result, state->lineno, value) < 0)
  5641. goto failed;
  5642. Py_DECREF(value);
  5643. value = ast2obj_int(state, vstate, o->col_offset);
  5644. if (!value) goto failed;
  5645. if (PyObject_SetAttr(result, state->col_offset, value) < 0)
  5646. goto failed;
  5647. Py_DECREF(value);
  5648. value = ast2obj_int(state, vstate, o->end_lineno);
  5649. if (!value) goto failed;
  5650. if (PyObject_SetAttr(result, state->end_lineno, value) < 0)
  5651. goto failed;
  5652. Py_DECREF(value);
  5653. value = ast2obj_int(state, vstate, o->end_col_offset);
  5654. if (!value) goto failed;
  5655. if (PyObject_SetAttr(result, state->end_col_offset, value) < 0)
  5656. goto failed;
  5657. Py_DECREF(value);
  5658. vstate->recursion_depth--;
  5659. return result;
  5660. failed:
  5661. vstate->recursion_depth--;
  5662. Py_XDECREF(value);
  5663. Py_XDECREF(result);
  5664. return NULL;
  5665. }
  5666. int
  5667. obj2ast_mod(struct ast_state *state, PyObject* obj, mod_ty* out, PyArena* arena)
  5668. {
  5669. int isinstance;
  5670. PyObject *tmp = NULL;
  5671. PyObject *tp;
  5672. if (obj == Py_None) {
  5673. *out = NULL;
  5674. return 0;
  5675. }
  5676. tp = state->Module_type;
  5677. isinstance = PyObject_IsInstance(obj, tp);
  5678. if (isinstance == -1) {
  5679. return 1;
  5680. }
  5681. if (isinstance) {
  5682. asdl_stmt_seq* body;
  5683. asdl_type_ignore_seq* type_ignores;
  5684. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  5685. return 1;
  5686. }
  5687. if (tmp == NULL) {
  5688. tmp = PyList_New(0);
  5689. if (tmp == NULL) {
  5690. return 1;
  5691. }
  5692. }
  5693. {
  5694. int res;
  5695. Py_ssize_t len;
  5696. Py_ssize_t i;
  5697. if (!PyList_Check(tmp)) {
  5698. PyErr_Format(PyExc_TypeError, "Module field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  5699. goto failed;
  5700. }
  5701. len = PyList_GET_SIZE(tmp);
  5702. body = _Py_asdl_stmt_seq_new(len, arena);
  5703. if (body == NULL) goto failed;
  5704. for (i = 0; i < len; i++) {
  5705. stmt_ty val;
  5706. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  5707. if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
  5708. goto failed;
  5709. }
  5710. res = obj2ast_stmt(state, tmp2, &val, arena);
  5711. _Py_LeaveRecursiveCall();
  5712. Py_DECREF(tmp2);
  5713. if (res != 0) goto failed;
  5714. if (len != PyList_GET_SIZE(tmp)) {
  5715. PyErr_SetString(PyExc_RuntimeError, "Module field \"body\" changed size during iteration");
  5716. goto failed;
  5717. }
  5718. asdl_seq_SET(body, i, val);
  5719. }
  5720. Py_CLEAR(tmp);
  5721. }
  5722. if (_PyObject_LookupAttr(obj, state->type_ignores, &tmp) < 0) {
  5723. return 1;
  5724. }
  5725. if (tmp == NULL) {
  5726. tmp = PyList_New(0);
  5727. if (tmp == NULL) {
  5728. return 1;
  5729. }
  5730. }
  5731. {
  5732. int res;
  5733. Py_ssize_t len;
  5734. Py_ssize_t i;
  5735. if (!PyList_Check(tmp)) {
  5736. PyErr_Format(PyExc_TypeError, "Module field \"type_ignores\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  5737. goto failed;
  5738. }
  5739. len = PyList_GET_SIZE(tmp);
  5740. type_ignores = _Py_asdl_type_ignore_seq_new(len, arena);
  5741. if (type_ignores == NULL) goto failed;
  5742. for (i = 0; i < len; i++) {
  5743. type_ignore_ty val;
  5744. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  5745. if (_Py_EnterRecursiveCall(" while traversing 'Module' node")) {
  5746. goto failed;
  5747. }
  5748. res = obj2ast_type_ignore(state, tmp2, &val, arena);
  5749. _Py_LeaveRecursiveCall();
  5750. Py_DECREF(tmp2);
  5751. if (res != 0) goto failed;
  5752. if (len != PyList_GET_SIZE(tmp)) {
  5753. PyErr_SetString(PyExc_RuntimeError, "Module field \"type_ignores\" changed size during iteration");
  5754. goto failed;
  5755. }
  5756. asdl_seq_SET(type_ignores, i, val);
  5757. }
  5758. Py_CLEAR(tmp);
  5759. }
  5760. *out = _PyAST_Module(body, type_ignores, arena);
  5761. if (*out == NULL) goto failed;
  5762. return 0;
  5763. }
  5764. tp = state->Interactive_type;
  5765. isinstance = PyObject_IsInstance(obj, tp);
  5766. if (isinstance == -1) {
  5767. return 1;
  5768. }
  5769. if (isinstance) {
  5770. asdl_stmt_seq* body;
  5771. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  5772. return 1;
  5773. }
  5774. if (tmp == NULL) {
  5775. tmp = PyList_New(0);
  5776. if (tmp == NULL) {
  5777. return 1;
  5778. }
  5779. }
  5780. {
  5781. int res;
  5782. Py_ssize_t len;
  5783. Py_ssize_t i;
  5784. if (!PyList_Check(tmp)) {
  5785. PyErr_Format(PyExc_TypeError, "Interactive field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  5786. goto failed;
  5787. }
  5788. len = PyList_GET_SIZE(tmp);
  5789. body = _Py_asdl_stmt_seq_new(len, arena);
  5790. if (body == NULL) goto failed;
  5791. for (i = 0; i < len; i++) {
  5792. stmt_ty val;
  5793. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  5794. if (_Py_EnterRecursiveCall(" while traversing 'Interactive' node")) {
  5795. goto failed;
  5796. }
  5797. res = obj2ast_stmt(state, tmp2, &val, arena);
  5798. _Py_LeaveRecursiveCall();
  5799. Py_DECREF(tmp2);
  5800. if (res != 0) goto failed;
  5801. if (len != PyList_GET_SIZE(tmp)) {
  5802. PyErr_SetString(PyExc_RuntimeError, "Interactive field \"body\" changed size during iteration");
  5803. goto failed;
  5804. }
  5805. asdl_seq_SET(body, i, val);
  5806. }
  5807. Py_CLEAR(tmp);
  5808. }
  5809. *out = _PyAST_Interactive(body, arena);
  5810. if (*out == NULL) goto failed;
  5811. return 0;
  5812. }
  5813. tp = state->Expression_type;
  5814. isinstance = PyObject_IsInstance(obj, tp);
  5815. if (isinstance == -1) {
  5816. return 1;
  5817. }
  5818. if (isinstance) {
  5819. expr_ty body;
  5820. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  5821. return 1;
  5822. }
  5823. if (tmp == NULL) {
  5824. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Expression");
  5825. return 1;
  5826. }
  5827. else {
  5828. int res;
  5829. if (_Py_EnterRecursiveCall(" while traversing 'Expression' node")) {
  5830. goto failed;
  5831. }
  5832. res = obj2ast_expr(state, tmp, &body, arena);
  5833. _Py_LeaveRecursiveCall();
  5834. if (res != 0) goto failed;
  5835. Py_CLEAR(tmp);
  5836. }
  5837. *out = _PyAST_Expression(body, arena);
  5838. if (*out == NULL) goto failed;
  5839. return 0;
  5840. }
  5841. tp = state->FunctionType_type;
  5842. isinstance = PyObject_IsInstance(obj, tp);
  5843. if (isinstance == -1) {
  5844. return 1;
  5845. }
  5846. if (isinstance) {
  5847. asdl_expr_seq* argtypes;
  5848. expr_ty returns;
  5849. if (_PyObject_LookupAttr(obj, state->argtypes, &tmp) < 0) {
  5850. return 1;
  5851. }
  5852. if (tmp == NULL) {
  5853. tmp = PyList_New(0);
  5854. if (tmp == NULL) {
  5855. return 1;
  5856. }
  5857. }
  5858. {
  5859. int res;
  5860. Py_ssize_t len;
  5861. Py_ssize_t i;
  5862. if (!PyList_Check(tmp)) {
  5863. PyErr_Format(PyExc_TypeError, "FunctionType field \"argtypes\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  5864. goto failed;
  5865. }
  5866. len = PyList_GET_SIZE(tmp);
  5867. argtypes = _Py_asdl_expr_seq_new(len, arena);
  5868. if (argtypes == NULL) goto failed;
  5869. for (i = 0; i < len; i++) {
  5870. expr_ty val;
  5871. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  5872. if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
  5873. goto failed;
  5874. }
  5875. res = obj2ast_expr(state, tmp2, &val, arena);
  5876. _Py_LeaveRecursiveCall();
  5877. Py_DECREF(tmp2);
  5878. if (res != 0) goto failed;
  5879. if (len != PyList_GET_SIZE(tmp)) {
  5880. PyErr_SetString(PyExc_RuntimeError, "FunctionType field \"argtypes\" changed size during iteration");
  5881. goto failed;
  5882. }
  5883. asdl_seq_SET(argtypes, i, val);
  5884. }
  5885. Py_CLEAR(tmp);
  5886. }
  5887. if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
  5888. return 1;
  5889. }
  5890. if (tmp == NULL) {
  5891. PyErr_SetString(PyExc_TypeError, "required field \"returns\" missing from FunctionType");
  5892. return 1;
  5893. }
  5894. else {
  5895. int res;
  5896. if (_Py_EnterRecursiveCall(" while traversing 'FunctionType' node")) {
  5897. goto failed;
  5898. }
  5899. res = obj2ast_expr(state, tmp, &returns, arena);
  5900. _Py_LeaveRecursiveCall();
  5901. if (res != 0) goto failed;
  5902. Py_CLEAR(tmp);
  5903. }
  5904. *out = _PyAST_FunctionType(argtypes, returns, arena);
  5905. if (*out == NULL) goto failed;
  5906. return 0;
  5907. }
  5908. PyErr_Format(PyExc_TypeError, "expected some sort of mod, but got %R", obj);
  5909. failed:
  5910. Py_XDECREF(tmp);
  5911. return 1;
  5912. }
  5913. int
  5914. obj2ast_stmt(struct ast_state *state, PyObject* obj, stmt_ty* out, PyArena*
  5915. arena)
  5916. {
  5917. int isinstance;
  5918. PyObject *tmp = NULL;
  5919. PyObject *tp;
  5920. int lineno;
  5921. int col_offset;
  5922. int end_lineno;
  5923. int end_col_offset;
  5924. if (obj == Py_None) {
  5925. *out = NULL;
  5926. return 0;
  5927. }
  5928. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  5929. return 1;
  5930. }
  5931. if (tmp == NULL) {
  5932. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from stmt");
  5933. return 1;
  5934. }
  5935. else {
  5936. int res;
  5937. if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
  5938. goto failed;
  5939. }
  5940. res = obj2ast_int(state, tmp, &lineno, arena);
  5941. _Py_LeaveRecursiveCall();
  5942. if (res != 0) goto failed;
  5943. Py_CLEAR(tmp);
  5944. }
  5945. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  5946. return 1;
  5947. }
  5948. if (tmp == NULL) {
  5949. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from stmt");
  5950. return 1;
  5951. }
  5952. else {
  5953. int res;
  5954. if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
  5955. goto failed;
  5956. }
  5957. res = obj2ast_int(state, tmp, &col_offset, arena);
  5958. _Py_LeaveRecursiveCall();
  5959. if (res != 0) goto failed;
  5960. Py_CLEAR(tmp);
  5961. }
  5962. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  5963. return 1;
  5964. }
  5965. if (tmp == NULL || tmp == Py_None) {
  5966. Py_CLEAR(tmp);
  5967. end_lineno = lineno;
  5968. }
  5969. else {
  5970. int res;
  5971. if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
  5972. goto failed;
  5973. }
  5974. res = obj2ast_int(state, tmp, &end_lineno, arena);
  5975. _Py_LeaveRecursiveCall();
  5976. if (res != 0) goto failed;
  5977. Py_CLEAR(tmp);
  5978. }
  5979. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  5980. return 1;
  5981. }
  5982. if (tmp == NULL || tmp == Py_None) {
  5983. Py_CLEAR(tmp);
  5984. end_col_offset = col_offset;
  5985. }
  5986. else {
  5987. int res;
  5988. if (_Py_EnterRecursiveCall(" while traversing 'stmt' node")) {
  5989. goto failed;
  5990. }
  5991. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  5992. _Py_LeaveRecursiveCall();
  5993. if (res != 0) goto failed;
  5994. Py_CLEAR(tmp);
  5995. }
  5996. tp = state->FunctionDef_type;
  5997. isinstance = PyObject_IsInstance(obj, tp);
  5998. if (isinstance == -1) {
  5999. return 1;
  6000. }
  6001. if (isinstance) {
  6002. identifier name;
  6003. arguments_ty args;
  6004. asdl_stmt_seq* body;
  6005. asdl_expr_seq* decorator_list;
  6006. expr_ty returns;
  6007. string type_comment;
  6008. asdl_type_param_seq* type_params;
  6009. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  6010. return 1;
  6011. }
  6012. if (tmp == NULL) {
  6013. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from FunctionDef");
  6014. return 1;
  6015. }
  6016. else {
  6017. int res;
  6018. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6019. goto failed;
  6020. }
  6021. res = obj2ast_identifier(state, tmp, &name, arena);
  6022. _Py_LeaveRecursiveCall();
  6023. if (res != 0) goto failed;
  6024. Py_CLEAR(tmp);
  6025. }
  6026. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  6027. return 1;
  6028. }
  6029. if (tmp == NULL) {
  6030. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from FunctionDef");
  6031. return 1;
  6032. }
  6033. else {
  6034. int res;
  6035. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6036. goto failed;
  6037. }
  6038. res = obj2ast_arguments(state, tmp, &args, arena);
  6039. _Py_LeaveRecursiveCall();
  6040. if (res != 0) goto failed;
  6041. Py_CLEAR(tmp);
  6042. }
  6043. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  6044. return 1;
  6045. }
  6046. if (tmp == NULL) {
  6047. tmp = PyList_New(0);
  6048. if (tmp == NULL) {
  6049. return 1;
  6050. }
  6051. }
  6052. {
  6053. int res;
  6054. Py_ssize_t len;
  6055. Py_ssize_t i;
  6056. if (!PyList_Check(tmp)) {
  6057. PyErr_Format(PyExc_TypeError, "FunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6058. goto failed;
  6059. }
  6060. len = PyList_GET_SIZE(tmp);
  6061. body = _Py_asdl_stmt_seq_new(len, arena);
  6062. if (body == NULL) goto failed;
  6063. for (i = 0; i < len; i++) {
  6064. stmt_ty val;
  6065. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6066. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6067. goto failed;
  6068. }
  6069. res = obj2ast_stmt(state, tmp2, &val, arena);
  6070. _Py_LeaveRecursiveCall();
  6071. Py_DECREF(tmp2);
  6072. if (res != 0) goto failed;
  6073. if (len != PyList_GET_SIZE(tmp)) {
  6074. PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"body\" changed size during iteration");
  6075. goto failed;
  6076. }
  6077. asdl_seq_SET(body, i, val);
  6078. }
  6079. Py_CLEAR(tmp);
  6080. }
  6081. if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
  6082. return 1;
  6083. }
  6084. if (tmp == NULL) {
  6085. tmp = PyList_New(0);
  6086. if (tmp == NULL) {
  6087. return 1;
  6088. }
  6089. }
  6090. {
  6091. int res;
  6092. Py_ssize_t len;
  6093. Py_ssize_t i;
  6094. if (!PyList_Check(tmp)) {
  6095. PyErr_Format(PyExc_TypeError, "FunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6096. goto failed;
  6097. }
  6098. len = PyList_GET_SIZE(tmp);
  6099. decorator_list = _Py_asdl_expr_seq_new(len, arena);
  6100. if (decorator_list == NULL) goto failed;
  6101. for (i = 0; i < len; i++) {
  6102. expr_ty val;
  6103. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6104. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6105. goto failed;
  6106. }
  6107. res = obj2ast_expr(state, tmp2, &val, arena);
  6108. _Py_LeaveRecursiveCall();
  6109. Py_DECREF(tmp2);
  6110. if (res != 0) goto failed;
  6111. if (len != PyList_GET_SIZE(tmp)) {
  6112. PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"decorator_list\" changed size during iteration");
  6113. goto failed;
  6114. }
  6115. asdl_seq_SET(decorator_list, i, val);
  6116. }
  6117. Py_CLEAR(tmp);
  6118. }
  6119. if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
  6120. return 1;
  6121. }
  6122. if (tmp == NULL || tmp == Py_None) {
  6123. Py_CLEAR(tmp);
  6124. returns = NULL;
  6125. }
  6126. else {
  6127. int res;
  6128. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6129. goto failed;
  6130. }
  6131. res = obj2ast_expr(state, tmp, &returns, arena);
  6132. _Py_LeaveRecursiveCall();
  6133. if (res != 0) goto failed;
  6134. Py_CLEAR(tmp);
  6135. }
  6136. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  6137. return 1;
  6138. }
  6139. if (tmp == NULL || tmp == Py_None) {
  6140. Py_CLEAR(tmp);
  6141. type_comment = NULL;
  6142. }
  6143. else {
  6144. int res;
  6145. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6146. goto failed;
  6147. }
  6148. res = obj2ast_string(state, tmp, &type_comment, arena);
  6149. _Py_LeaveRecursiveCall();
  6150. if (res != 0) goto failed;
  6151. Py_CLEAR(tmp);
  6152. }
  6153. if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
  6154. return 1;
  6155. }
  6156. if (tmp == NULL) {
  6157. tmp = PyList_New(0);
  6158. if (tmp == NULL) {
  6159. return 1;
  6160. }
  6161. }
  6162. {
  6163. int res;
  6164. Py_ssize_t len;
  6165. Py_ssize_t i;
  6166. if (!PyList_Check(tmp)) {
  6167. PyErr_Format(PyExc_TypeError, "FunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6168. goto failed;
  6169. }
  6170. len = PyList_GET_SIZE(tmp);
  6171. type_params = _Py_asdl_type_param_seq_new(len, arena);
  6172. if (type_params == NULL) goto failed;
  6173. for (i = 0; i < len; i++) {
  6174. type_param_ty val;
  6175. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6176. if (_Py_EnterRecursiveCall(" while traversing 'FunctionDef' node")) {
  6177. goto failed;
  6178. }
  6179. res = obj2ast_type_param(state, tmp2, &val, arena);
  6180. _Py_LeaveRecursiveCall();
  6181. Py_DECREF(tmp2);
  6182. if (res != 0) goto failed;
  6183. if (len != PyList_GET_SIZE(tmp)) {
  6184. PyErr_SetString(PyExc_RuntimeError, "FunctionDef field \"type_params\" changed size during iteration");
  6185. goto failed;
  6186. }
  6187. asdl_seq_SET(type_params, i, val);
  6188. }
  6189. Py_CLEAR(tmp);
  6190. }
  6191. *out = _PyAST_FunctionDef(name, args, body, decorator_list, returns,
  6192. type_comment, type_params, lineno,
  6193. col_offset, end_lineno, end_col_offset,
  6194. arena);
  6195. if (*out == NULL) goto failed;
  6196. return 0;
  6197. }
  6198. tp = state->AsyncFunctionDef_type;
  6199. isinstance = PyObject_IsInstance(obj, tp);
  6200. if (isinstance == -1) {
  6201. return 1;
  6202. }
  6203. if (isinstance) {
  6204. identifier name;
  6205. arguments_ty args;
  6206. asdl_stmt_seq* body;
  6207. asdl_expr_seq* decorator_list;
  6208. expr_ty returns;
  6209. string type_comment;
  6210. asdl_type_param_seq* type_params;
  6211. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  6212. return 1;
  6213. }
  6214. if (tmp == NULL) {
  6215. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from AsyncFunctionDef");
  6216. return 1;
  6217. }
  6218. else {
  6219. int res;
  6220. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6221. goto failed;
  6222. }
  6223. res = obj2ast_identifier(state, tmp, &name, arena);
  6224. _Py_LeaveRecursiveCall();
  6225. if (res != 0) goto failed;
  6226. Py_CLEAR(tmp);
  6227. }
  6228. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  6229. return 1;
  6230. }
  6231. if (tmp == NULL) {
  6232. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from AsyncFunctionDef");
  6233. return 1;
  6234. }
  6235. else {
  6236. int res;
  6237. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6238. goto failed;
  6239. }
  6240. res = obj2ast_arguments(state, tmp, &args, arena);
  6241. _Py_LeaveRecursiveCall();
  6242. if (res != 0) goto failed;
  6243. Py_CLEAR(tmp);
  6244. }
  6245. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  6246. return 1;
  6247. }
  6248. if (tmp == NULL) {
  6249. tmp = PyList_New(0);
  6250. if (tmp == NULL) {
  6251. return 1;
  6252. }
  6253. }
  6254. {
  6255. int res;
  6256. Py_ssize_t len;
  6257. Py_ssize_t i;
  6258. if (!PyList_Check(tmp)) {
  6259. PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6260. goto failed;
  6261. }
  6262. len = PyList_GET_SIZE(tmp);
  6263. body = _Py_asdl_stmt_seq_new(len, arena);
  6264. if (body == NULL) goto failed;
  6265. for (i = 0; i < len; i++) {
  6266. stmt_ty val;
  6267. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6268. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6269. goto failed;
  6270. }
  6271. res = obj2ast_stmt(state, tmp2, &val, arena);
  6272. _Py_LeaveRecursiveCall();
  6273. Py_DECREF(tmp2);
  6274. if (res != 0) goto failed;
  6275. if (len != PyList_GET_SIZE(tmp)) {
  6276. PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"body\" changed size during iteration");
  6277. goto failed;
  6278. }
  6279. asdl_seq_SET(body, i, val);
  6280. }
  6281. Py_CLEAR(tmp);
  6282. }
  6283. if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
  6284. return 1;
  6285. }
  6286. if (tmp == NULL) {
  6287. tmp = PyList_New(0);
  6288. if (tmp == NULL) {
  6289. return 1;
  6290. }
  6291. }
  6292. {
  6293. int res;
  6294. Py_ssize_t len;
  6295. Py_ssize_t i;
  6296. if (!PyList_Check(tmp)) {
  6297. PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6298. goto failed;
  6299. }
  6300. len = PyList_GET_SIZE(tmp);
  6301. decorator_list = _Py_asdl_expr_seq_new(len, arena);
  6302. if (decorator_list == NULL) goto failed;
  6303. for (i = 0; i < len; i++) {
  6304. expr_ty val;
  6305. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6306. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6307. goto failed;
  6308. }
  6309. res = obj2ast_expr(state, tmp2, &val, arena);
  6310. _Py_LeaveRecursiveCall();
  6311. Py_DECREF(tmp2);
  6312. if (res != 0) goto failed;
  6313. if (len != PyList_GET_SIZE(tmp)) {
  6314. PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"decorator_list\" changed size during iteration");
  6315. goto failed;
  6316. }
  6317. asdl_seq_SET(decorator_list, i, val);
  6318. }
  6319. Py_CLEAR(tmp);
  6320. }
  6321. if (_PyObject_LookupAttr(obj, state->returns, &tmp) < 0) {
  6322. return 1;
  6323. }
  6324. if (tmp == NULL || tmp == Py_None) {
  6325. Py_CLEAR(tmp);
  6326. returns = NULL;
  6327. }
  6328. else {
  6329. int res;
  6330. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6331. goto failed;
  6332. }
  6333. res = obj2ast_expr(state, tmp, &returns, arena);
  6334. _Py_LeaveRecursiveCall();
  6335. if (res != 0) goto failed;
  6336. Py_CLEAR(tmp);
  6337. }
  6338. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  6339. return 1;
  6340. }
  6341. if (tmp == NULL || tmp == Py_None) {
  6342. Py_CLEAR(tmp);
  6343. type_comment = NULL;
  6344. }
  6345. else {
  6346. int res;
  6347. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6348. goto failed;
  6349. }
  6350. res = obj2ast_string(state, tmp, &type_comment, arena);
  6351. _Py_LeaveRecursiveCall();
  6352. if (res != 0) goto failed;
  6353. Py_CLEAR(tmp);
  6354. }
  6355. if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
  6356. return 1;
  6357. }
  6358. if (tmp == NULL) {
  6359. tmp = PyList_New(0);
  6360. if (tmp == NULL) {
  6361. return 1;
  6362. }
  6363. }
  6364. {
  6365. int res;
  6366. Py_ssize_t len;
  6367. Py_ssize_t i;
  6368. if (!PyList_Check(tmp)) {
  6369. PyErr_Format(PyExc_TypeError, "AsyncFunctionDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6370. goto failed;
  6371. }
  6372. len = PyList_GET_SIZE(tmp);
  6373. type_params = _Py_asdl_type_param_seq_new(len, arena);
  6374. if (type_params == NULL) goto failed;
  6375. for (i = 0; i < len; i++) {
  6376. type_param_ty val;
  6377. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6378. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFunctionDef' node")) {
  6379. goto failed;
  6380. }
  6381. res = obj2ast_type_param(state, tmp2, &val, arena);
  6382. _Py_LeaveRecursiveCall();
  6383. Py_DECREF(tmp2);
  6384. if (res != 0) goto failed;
  6385. if (len != PyList_GET_SIZE(tmp)) {
  6386. PyErr_SetString(PyExc_RuntimeError, "AsyncFunctionDef field \"type_params\" changed size during iteration");
  6387. goto failed;
  6388. }
  6389. asdl_seq_SET(type_params, i, val);
  6390. }
  6391. Py_CLEAR(tmp);
  6392. }
  6393. *out = _PyAST_AsyncFunctionDef(name, args, body, decorator_list,
  6394. returns, type_comment, type_params,
  6395. lineno, col_offset, end_lineno,
  6396. end_col_offset, arena);
  6397. if (*out == NULL) goto failed;
  6398. return 0;
  6399. }
  6400. tp = state->ClassDef_type;
  6401. isinstance = PyObject_IsInstance(obj, tp);
  6402. if (isinstance == -1) {
  6403. return 1;
  6404. }
  6405. if (isinstance) {
  6406. identifier name;
  6407. asdl_expr_seq* bases;
  6408. asdl_keyword_seq* keywords;
  6409. asdl_stmt_seq* body;
  6410. asdl_expr_seq* decorator_list;
  6411. asdl_type_param_seq* type_params;
  6412. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  6413. return 1;
  6414. }
  6415. if (tmp == NULL) {
  6416. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ClassDef");
  6417. return 1;
  6418. }
  6419. else {
  6420. int res;
  6421. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6422. goto failed;
  6423. }
  6424. res = obj2ast_identifier(state, tmp, &name, arena);
  6425. _Py_LeaveRecursiveCall();
  6426. if (res != 0) goto failed;
  6427. Py_CLEAR(tmp);
  6428. }
  6429. if (_PyObject_LookupAttr(obj, state->bases, &tmp) < 0) {
  6430. return 1;
  6431. }
  6432. if (tmp == NULL) {
  6433. tmp = PyList_New(0);
  6434. if (tmp == NULL) {
  6435. return 1;
  6436. }
  6437. }
  6438. {
  6439. int res;
  6440. Py_ssize_t len;
  6441. Py_ssize_t i;
  6442. if (!PyList_Check(tmp)) {
  6443. PyErr_Format(PyExc_TypeError, "ClassDef field \"bases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6444. goto failed;
  6445. }
  6446. len = PyList_GET_SIZE(tmp);
  6447. bases = _Py_asdl_expr_seq_new(len, arena);
  6448. if (bases == NULL) goto failed;
  6449. for (i = 0; i < len; i++) {
  6450. expr_ty val;
  6451. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6452. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6453. goto failed;
  6454. }
  6455. res = obj2ast_expr(state, tmp2, &val, arena);
  6456. _Py_LeaveRecursiveCall();
  6457. Py_DECREF(tmp2);
  6458. if (res != 0) goto failed;
  6459. if (len != PyList_GET_SIZE(tmp)) {
  6460. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"bases\" changed size during iteration");
  6461. goto failed;
  6462. }
  6463. asdl_seq_SET(bases, i, val);
  6464. }
  6465. Py_CLEAR(tmp);
  6466. }
  6467. if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
  6468. return 1;
  6469. }
  6470. if (tmp == NULL) {
  6471. tmp = PyList_New(0);
  6472. if (tmp == NULL) {
  6473. return 1;
  6474. }
  6475. }
  6476. {
  6477. int res;
  6478. Py_ssize_t len;
  6479. Py_ssize_t i;
  6480. if (!PyList_Check(tmp)) {
  6481. PyErr_Format(PyExc_TypeError, "ClassDef field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6482. goto failed;
  6483. }
  6484. len = PyList_GET_SIZE(tmp);
  6485. keywords = _Py_asdl_keyword_seq_new(len, arena);
  6486. if (keywords == NULL) goto failed;
  6487. for (i = 0; i < len; i++) {
  6488. keyword_ty val;
  6489. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6490. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6491. goto failed;
  6492. }
  6493. res = obj2ast_keyword(state, tmp2, &val, arena);
  6494. _Py_LeaveRecursiveCall();
  6495. Py_DECREF(tmp2);
  6496. if (res != 0) goto failed;
  6497. if (len != PyList_GET_SIZE(tmp)) {
  6498. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"keywords\" changed size during iteration");
  6499. goto failed;
  6500. }
  6501. asdl_seq_SET(keywords, i, val);
  6502. }
  6503. Py_CLEAR(tmp);
  6504. }
  6505. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  6506. return 1;
  6507. }
  6508. if (tmp == NULL) {
  6509. tmp = PyList_New(0);
  6510. if (tmp == NULL) {
  6511. return 1;
  6512. }
  6513. }
  6514. {
  6515. int res;
  6516. Py_ssize_t len;
  6517. Py_ssize_t i;
  6518. if (!PyList_Check(tmp)) {
  6519. PyErr_Format(PyExc_TypeError, "ClassDef field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6520. goto failed;
  6521. }
  6522. len = PyList_GET_SIZE(tmp);
  6523. body = _Py_asdl_stmt_seq_new(len, arena);
  6524. if (body == NULL) goto failed;
  6525. for (i = 0; i < len; i++) {
  6526. stmt_ty val;
  6527. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6528. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6529. goto failed;
  6530. }
  6531. res = obj2ast_stmt(state, tmp2, &val, arena);
  6532. _Py_LeaveRecursiveCall();
  6533. Py_DECREF(tmp2);
  6534. if (res != 0) goto failed;
  6535. if (len != PyList_GET_SIZE(tmp)) {
  6536. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"body\" changed size during iteration");
  6537. goto failed;
  6538. }
  6539. asdl_seq_SET(body, i, val);
  6540. }
  6541. Py_CLEAR(tmp);
  6542. }
  6543. if (_PyObject_LookupAttr(obj, state->decorator_list, &tmp) < 0) {
  6544. return 1;
  6545. }
  6546. if (tmp == NULL) {
  6547. tmp = PyList_New(0);
  6548. if (tmp == NULL) {
  6549. return 1;
  6550. }
  6551. }
  6552. {
  6553. int res;
  6554. Py_ssize_t len;
  6555. Py_ssize_t i;
  6556. if (!PyList_Check(tmp)) {
  6557. PyErr_Format(PyExc_TypeError, "ClassDef field \"decorator_list\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6558. goto failed;
  6559. }
  6560. len = PyList_GET_SIZE(tmp);
  6561. decorator_list = _Py_asdl_expr_seq_new(len, arena);
  6562. if (decorator_list == NULL) goto failed;
  6563. for (i = 0; i < len; i++) {
  6564. expr_ty val;
  6565. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6566. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6567. goto failed;
  6568. }
  6569. res = obj2ast_expr(state, tmp2, &val, arena);
  6570. _Py_LeaveRecursiveCall();
  6571. Py_DECREF(tmp2);
  6572. if (res != 0) goto failed;
  6573. if (len != PyList_GET_SIZE(tmp)) {
  6574. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"decorator_list\" changed size during iteration");
  6575. goto failed;
  6576. }
  6577. asdl_seq_SET(decorator_list, i, val);
  6578. }
  6579. Py_CLEAR(tmp);
  6580. }
  6581. if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
  6582. return 1;
  6583. }
  6584. if (tmp == NULL) {
  6585. tmp = PyList_New(0);
  6586. if (tmp == NULL) {
  6587. return 1;
  6588. }
  6589. }
  6590. {
  6591. int res;
  6592. Py_ssize_t len;
  6593. Py_ssize_t i;
  6594. if (!PyList_Check(tmp)) {
  6595. PyErr_Format(PyExc_TypeError, "ClassDef field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6596. goto failed;
  6597. }
  6598. len = PyList_GET_SIZE(tmp);
  6599. type_params = _Py_asdl_type_param_seq_new(len, arena);
  6600. if (type_params == NULL) goto failed;
  6601. for (i = 0; i < len; i++) {
  6602. type_param_ty val;
  6603. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6604. if (_Py_EnterRecursiveCall(" while traversing 'ClassDef' node")) {
  6605. goto failed;
  6606. }
  6607. res = obj2ast_type_param(state, tmp2, &val, arena);
  6608. _Py_LeaveRecursiveCall();
  6609. Py_DECREF(tmp2);
  6610. if (res != 0) goto failed;
  6611. if (len != PyList_GET_SIZE(tmp)) {
  6612. PyErr_SetString(PyExc_RuntimeError, "ClassDef field \"type_params\" changed size during iteration");
  6613. goto failed;
  6614. }
  6615. asdl_seq_SET(type_params, i, val);
  6616. }
  6617. Py_CLEAR(tmp);
  6618. }
  6619. *out = _PyAST_ClassDef(name, bases, keywords, body, decorator_list,
  6620. type_params, lineno, col_offset, end_lineno,
  6621. end_col_offset, arena);
  6622. if (*out == NULL) goto failed;
  6623. return 0;
  6624. }
  6625. tp = state->Return_type;
  6626. isinstance = PyObject_IsInstance(obj, tp);
  6627. if (isinstance == -1) {
  6628. return 1;
  6629. }
  6630. if (isinstance) {
  6631. expr_ty value;
  6632. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6633. return 1;
  6634. }
  6635. if (tmp == NULL || tmp == Py_None) {
  6636. Py_CLEAR(tmp);
  6637. value = NULL;
  6638. }
  6639. else {
  6640. int res;
  6641. if (_Py_EnterRecursiveCall(" while traversing 'Return' node")) {
  6642. goto failed;
  6643. }
  6644. res = obj2ast_expr(state, tmp, &value, arena);
  6645. _Py_LeaveRecursiveCall();
  6646. if (res != 0) goto failed;
  6647. Py_CLEAR(tmp);
  6648. }
  6649. *out = _PyAST_Return(value, lineno, col_offset, end_lineno,
  6650. end_col_offset, arena);
  6651. if (*out == NULL) goto failed;
  6652. return 0;
  6653. }
  6654. tp = state->Delete_type;
  6655. isinstance = PyObject_IsInstance(obj, tp);
  6656. if (isinstance == -1) {
  6657. return 1;
  6658. }
  6659. if (isinstance) {
  6660. asdl_expr_seq* targets;
  6661. if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
  6662. return 1;
  6663. }
  6664. if (tmp == NULL) {
  6665. tmp = PyList_New(0);
  6666. if (tmp == NULL) {
  6667. return 1;
  6668. }
  6669. }
  6670. {
  6671. int res;
  6672. Py_ssize_t len;
  6673. Py_ssize_t i;
  6674. if (!PyList_Check(tmp)) {
  6675. PyErr_Format(PyExc_TypeError, "Delete field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6676. goto failed;
  6677. }
  6678. len = PyList_GET_SIZE(tmp);
  6679. targets = _Py_asdl_expr_seq_new(len, arena);
  6680. if (targets == NULL) goto failed;
  6681. for (i = 0; i < len; i++) {
  6682. expr_ty val;
  6683. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6684. if (_Py_EnterRecursiveCall(" while traversing 'Delete' node")) {
  6685. goto failed;
  6686. }
  6687. res = obj2ast_expr(state, tmp2, &val, arena);
  6688. _Py_LeaveRecursiveCall();
  6689. Py_DECREF(tmp2);
  6690. if (res != 0) goto failed;
  6691. if (len != PyList_GET_SIZE(tmp)) {
  6692. PyErr_SetString(PyExc_RuntimeError, "Delete field \"targets\" changed size during iteration");
  6693. goto failed;
  6694. }
  6695. asdl_seq_SET(targets, i, val);
  6696. }
  6697. Py_CLEAR(tmp);
  6698. }
  6699. *out = _PyAST_Delete(targets, lineno, col_offset, end_lineno,
  6700. end_col_offset, arena);
  6701. if (*out == NULL) goto failed;
  6702. return 0;
  6703. }
  6704. tp = state->Assign_type;
  6705. isinstance = PyObject_IsInstance(obj, tp);
  6706. if (isinstance == -1) {
  6707. return 1;
  6708. }
  6709. if (isinstance) {
  6710. asdl_expr_seq* targets;
  6711. expr_ty value;
  6712. string type_comment;
  6713. if (_PyObject_LookupAttr(obj, state->targets, &tmp) < 0) {
  6714. return 1;
  6715. }
  6716. if (tmp == NULL) {
  6717. tmp = PyList_New(0);
  6718. if (tmp == NULL) {
  6719. return 1;
  6720. }
  6721. }
  6722. {
  6723. int res;
  6724. Py_ssize_t len;
  6725. Py_ssize_t i;
  6726. if (!PyList_Check(tmp)) {
  6727. PyErr_Format(PyExc_TypeError, "Assign field \"targets\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6728. goto failed;
  6729. }
  6730. len = PyList_GET_SIZE(tmp);
  6731. targets = _Py_asdl_expr_seq_new(len, arena);
  6732. if (targets == NULL) goto failed;
  6733. for (i = 0; i < len; i++) {
  6734. expr_ty val;
  6735. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6736. if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
  6737. goto failed;
  6738. }
  6739. res = obj2ast_expr(state, tmp2, &val, arena);
  6740. _Py_LeaveRecursiveCall();
  6741. Py_DECREF(tmp2);
  6742. if (res != 0) goto failed;
  6743. if (len != PyList_GET_SIZE(tmp)) {
  6744. PyErr_SetString(PyExc_RuntimeError, "Assign field \"targets\" changed size during iteration");
  6745. goto failed;
  6746. }
  6747. asdl_seq_SET(targets, i, val);
  6748. }
  6749. Py_CLEAR(tmp);
  6750. }
  6751. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6752. return 1;
  6753. }
  6754. if (tmp == NULL) {
  6755. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Assign");
  6756. return 1;
  6757. }
  6758. else {
  6759. int res;
  6760. if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
  6761. goto failed;
  6762. }
  6763. res = obj2ast_expr(state, tmp, &value, arena);
  6764. _Py_LeaveRecursiveCall();
  6765. if (res != 0) goto failed;
  6766. Py_CLEAR(tmp);
  6767. }
  6768. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  6769. return 1;
  6770. }
  6771. if (tmp == NULL || tmp == Py_None) {
  6772. Py_CLEAR(tmp);
  6773. type_comment = NULL;
  6774. }
  6775. else {
  6776. int res;
  6777. if (_Py_EnterRecursiveCall(" while traversing 'Assign' node")) {
  6778. goto failed;
  6779. }
  6780. res = obj2ast_string(state, tmp, &type_comment, arena);
  6781. _Py_LeaveRecursiveCall();
  6782. if (res != 0) goto failed;
  6783. Py_CLEAR(tmp);
  6784. }
  6785. *out = _PyAST_Assign(targets, value, type_comment, lineno, col_offset,
  6786. end_lineno, end_col_offset, arena);
  6787. if (*out == NULL) goto failed;
  6788. return 0;
  6789. }
  6790. tp = state->TypeAlias_type;
  6791. isinstance = PyObject_IsInstance(obj, tp);
  6792. if (isinstance == -1) {
  6793. return 1;
  6794. }
  6795. if (isinstance) {
  6796. expr_ty name;
  6797. asdl_type_param_seq* type_params;
  6798. expr_ty value;
  6799. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  6800. return 1;
  6801. }
  6802. if (tmp == NULL) {
  6803. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeAlias");
  6804. return 1;
  6805. }
  6806. else {
  6807. int res;
  6808. if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
  6809. goto failed;
  6810. }
  6811. res = obj2ast_expr(state, tmp, &name, arena);
  6812. _Py_LeaveRecursiveCall();
  6813. if (res != 0) goto failed;
  6814. Py_CLEAR(tmp);
  6815. }
  6816. if (_PyObject_LookupAttr(obj, state->type_params, &tmp) < 0) {
  6817. return 1;
  6818. }
  6819. if (tmp == NULL) {
  6820. tmp = PyList_New(0);
  6821. if (tmp == NULL) {
  6822. return 1;
  6823. }
  6824. }
  6825. {
  6826. int res;
  6827. Py_ssize_t len;
  6828. Py_ssize_t i;
  6829. if (!PyList_Check(tmp)) {
  6830. PyErr_Format(PyExc_TypeError, "TypeAlias field \"type_params\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  6831. goto failed;
  6832. }
  6833. len = PyList_GET_SIZE(tmp);
  6834. type_params = _Py_asdl_type_param_seq_new(len, arena);
  6835. if (type_params == NULL) goto failed;
  6836. for (i = 0; i < len; i++) {
  6837. type_param_ty val;
  6838. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  6839. if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
  6840. goto failed;
  6841. }
  6842. res = obj2ast_type_param(state, tmp2, &val, arena);
  6843. _Py_LeaveRecursiveCall();
  6844. Py_DECREF(tmp2);
  6845. if (res != 0) goto failed;
  6846. if (len != PyList_GET_SIZE(tmp)) {
  6847. PyErr_SetString(PyExc_RuntimeError, "TypeAlias field \"type_params\" changed size during iteration");
  6848. goto failed;
  6849. }
  6850. asdl_seq_SET(type_params, i, val);
  6851. }
  6852. Py_CLEAR(tmp);
  6853. }
  6854. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6855. return 1;
  6856. }
  6857. if (tmp == NULL) {
  6858. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from TypeAlias");
  6859. return 1;
  6860. }
  6861. else {
  6862. int res;
  6863. if (_Py_EnterRecursiveCall(" while traversing 'TypeAlias' node")) {
  6864. goto failed;
  6865. }
  6866. res = obj2ast_expr(state, tmp, &value, arena);
  6867. _Py_LeaveRecursiveCall();
  6868. if (res != 0) goto failed;
  6869. Py_CLEAR(tmp);
  6870. }
  6871. *out = _PyAST_TypeAlias(name, type_params, value, lineno, col_offset,
  6872. end_lineno, end_col_offset, arena);
  6873. if (*out == NULL) goto failed;
  6874. return 0;
  6875. }
  6876. tp = state->AugAssign_type;
  6877. isinstance = PyObject_IsInstance(obj, tp);
  6878. if (isinstance == -1) {
  6879. return 1;
  6880. }
  6881. if (isinstance) {
  6882. expr_ty target;
  6883. operator_ty op;
  6884. expr_ty value;
  6885. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  6886. return 1;
  6887. }
  6888. if (tmp == NULL) {
  6889. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AugAssign");
  6890. return 1;
  6891. }
  6892. else {
  6893. int res;
  6894. if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
  6895. goto failed;
  6896. }
  6897. res = obj2ast_expr(state, tmp, &target, arena);
  6898. _Py_LeaveRecursiveCall();
  6899. if (res != 0) goto failed;
  6900. Py_CLEAR(tmp);
  6901. }
  6902. if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
  6903. return 1;
  6904. }
  6905. if (tmp == NULL) {
  6906. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from AugAssign");
  6907. return 1;
  6908. }
  6909. else {
  6910. int res;
  6911. if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
  6912. goto failed;
  6913. }
  6914. res = obj2ast_operator(state, tmp, &op, arena);
  6915. _Py_LeaveRecursiveCall();
  6916. if (res != 0) goto failed;
  6917. Py_CLEAR(tmp);
  6918. }
  6919. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6920. return 1;
  6921. }
  6922. if (tmp == NULL) {
  6923. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from AugAssign");
  6924. return 1;
  6925. }
  6926. else {
  6927. int res;
  6928. if (_Py_EnterRecursiveCall(" while traversing 'AugAssign' node")) {
  6929. goto failed;
  6930. }
  6931. res = obj2ast_expr(state, tmp, &value, arena);
  6932. _Py_LeaveRecursiveCall();
  6933. if (res != 0) goto failed;
  6934. Py_CLEAR(tmp);
  6935. }
  6936. *out = _PyAST_AugAssign(target, op, value, lineno, col_offset,
  6937. end_lineno, end_col_offset, arena);
  6938. if (*out == NULL) goto failed;
  6939. return 0;
  6940. }
  6941. tp = state->AnnAssign_type;
  6942. isinstance = PyObject_IsInstance(obj, tp);
  6943. if (isinstance == -1) {
  6944. return 1;
  6945. }
  6946. if (isinstance) {
  6947. expr_ty target;
  6948. expr_ty annotation;
  6949. expr_ty value;
  6950. int simple;
  6951. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  6952. return 1;
  6953. }
  6954. if (tmp == NULL) {
  6955. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AnnAssign");
  6956. return 1;
  6957. }
  6958. else {
  6959. int res;
  6960. if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
  6961. goto failed;
  6962. }
  6963. res = obj2ast_expr(state, tmp, &target, arena);
  6964. _Py_LeaveRecursiveCall();
  6965. if (res != 0) goto failed;
  6966. Py_CLEAR(tmp);
  6967. }
  6968. if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
  6969. return 1;
  6970. }
  6971. if (tmp == NULL) {
  6972. PyErr_SetString(PyExc_TypeError, "required field \"annotation\" missing from AnnAssign");
  6973. return 1;
  6974. }
  6975. else {
  6976. int res;
  6977. if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
  6978. goto failed;
  6979. }
  6980. res = obj2ast_expr(state, tmp, &annotation, arena);
  6981. _Py_LeaveRecursiveCall();
  6982. if (res != 0) goto failed;
  6983. Py_CLEAR(tmp);
  6984. }
  6985. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  6986. return 1;
  6987. }
  6988. if (tmp == NULL || tmp == Py_None) {
  6989. Py_CLEAR(tmp);
  6990. value = NULL;
  6991. }
  6992. else {
  6993. int res;
  6994. if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
  6995. goto failed;
  6996. }
  6997. res = obj2ast_expr(state, tmp, &value, arena);
  6998. _Py_LeaveRecursiveCall();
  6999. if (res != 0) goto failed;
  7000. Py_CLEAR(tmp);
  7001. }
  7002. if (_PyObject_LookupAttr(obj, state->simple, &tmp) < 0) {
  7003. return 1;
  7004. }
  7005. if (tmp == NULL) {
  7006. PyErr_SetString(PyExc_TypeError, "required field \"simple\" missing from AnnAssign");
  7007. return 1;
  7008. }
  7009. else {
  7010. int res;
  7011. if (_Py_EnterRecursiveCall(" while traversing 'AnnAssign' node")) {
  7012. goto failed;
  7013. }
  7014. res = obj2ast_int(state, tmp, &simple, arena);
  7015. _Py_LeaveRecursiveCall();
  7016. if (res != 0) goto failed;
  7017. Py_CLEAR(tmp);
  7018. }
  7019. *out = _PyAST_AnnAssign(target, annotation, value, simple, lineno,
  7020. col_offset, end_lineno, end_col_offset, arena);
  7021. if (*out == NULL) goto failed;
  7022. return 0;
  7023. }
  7024. tp = state->For_type;
  7025. isinstance = PyObject_IsInstance(obj, tp);
  7026. if (isinstance == -1) {
  7027. return 1;
  7028. }
  7029. if (isinstance) {
  7030. expr_ty target;
  7031. expr_ty iter;
  7032. asdl_stmt_seq* body;
  7033. asdl_stmt_seq* orelse;
  7034. string type_comment;
  7035. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  7036. return 1;
  7037. }
  7038. if (tmp == NULL) {
  7039. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from For");
  7040. return 1;
  7041. }
  7042. else {
  7043. int res;
  7044. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7045. goto failed;
  7046. }
  7047. res = obj2ast_expr(state, tmp, &target, arena);
  7048. _Py_LeaveRecursiveCall();
  7049. if (res != 0) goto failed;
  7050. Py_CLEAR(tmp);
  7051. }
  7052. if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
  7053. return 1;
  7054. }
  7055. if (tmp == NULL) {
  7056. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from For");
  7057. return 1;
  7058. }
  7059. else {
  7060. int res;
  7061. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7062. goto failed;
  7063. }
  7064. res = obj2ast_expr(state, tmp, &iter, arena);
  7065. _Py_LeaveRecursiveCall();
  7066. if (res != 0) goto failed;
  7067. Py_CLEAR(tmp);
  7068. }
  7069. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7070. return 1;
  7071. }
  7072. if (tmp == NULL) {
  7073. tmp = PyList_New(0);
  7074. if (tmp == NULL) {
  7075. return 1;
  7076. }
  7077. }
  7078. {
  7079. int res;
  7080. Py_ssize_t len;
  7081. Py_ssize_t i;
  7082. if (!PyList_Check(tmp)) {
  7083. PyErr_Format(PyExc_TypeError, "For field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7084. goto failed;
  7085. }
  7086. len = PyList_GET_SIZE(tmp);
  7087. body = _Py_asdl_stmt_seq_new(len, arena);
  7088. if (body == NULL) goto failed;
  7089. for (i = 0; i < len; i++) {
  7090. stmt_ty val;
  7091. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7092. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7093. goto failed;
  7094. }
  7095. res = obj2ast_stmt(state, tmp2, &val, arena);
  7096. _Py_LeaveRecursiveCall();
  7097. Py_DECREF(tmp2);
  7098. if (res != 0) goto failed;
  7099. if (len != PyList_GET_SIZE(tmp)) {
  7100. PyErr_SetString(PyExc_RuntimeError, "For field \"body\" changed size during iteration");
  7101. goto failed;
  7102. }
  7103. asdl_seq_SET(body, i, val);
  7104. }
  7105. Py_CLEAR(tmp);
  7106. }
  7107. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7108. return 1;
  7109. }
  7110. if (tmp == NULL) {
  7111. tmp = PyList_New(0);
  7112. if (tmp == NULL) {
  7113. return 1;
  7114. }
  7115. }
  7116. {
  7117. int res;
  7118. Py_ssize_t len;
  7119. Py_ssize_t i;
  7120. if (!PyList_Check(tmp)) {
  7121. PyErr_Format(PyExc_TypeError, "For field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7122. goto failed;
  7123. }
  7124. len = PyList_GET_SIZE(tmp);
  7125. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7126. if (orelse == NULL) goto failed;
  7127. for (i = 0; i < len; i++) {
  7128. stmt_ty val;
  7129. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7130. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7131. goto failed;
  7132. }
  7133. res = obj2ast_stmt(state, tmp2, &val, arena);
  7134. _Py_LeaveRecursiveCall();
  7135. Py_DECREF(tmp2);
  7136. if (res != 0) goto failed;
  7137. if (len != PyList_GET_SIZE(tmp)) {
  7138. PyErr_SetString(PyExc_RuntimeError, "For field \"orelse\" changed size during iteration");
  7139. goto failed;
  7140. }
  7141. asdl_seq_SET(orelse, i, val);
  7142. }
  7143. Py_CLEAR(tmp);
  7144. }
  7145. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  7146. return 1;
  7147. }
  7148. if (tmp == NULL || tmp == Py_None) {
  7149. Py_CLEAR(tmp);
  7150. type_comment = NULL;
  7151. }
  7152. else {
  7153. int res;
  7154. if (_Py_EnterRecursiveCall(" while traversing 'For' node")) {
  7155. goto failed;
  7156. }
  7157. res = obj2ast_string(state, tmp, &type_comment, arena);
  7158. _Py_LeaveRecursiveCall();
  7159. if (res != 0) goto failed;
  7160. Py_CLEAR(tmp);
  7161. }
  7162. *out = _PyAST_For(target, iter, body, orelse, type_comment, lineno,
  7163. col_offset, end_lineno, end_col_offset, arena);
  7164. if (*out == NULL) goto failed;
  7165. return 0;
  7166. }
  7167. tp = state->AsyncFor_type;
  7168. isinstance = PyObject_IsInstance(obj, tp);
  7169. if (isinstance == -1) {
  7170. return 1;
  7171. }
  7172. if (isinstance) {
  7173. expr_ty target;
  7174. expr_ty iter;
  7175. asdl_stmt_seq* body;
  7176. asdl_stmt_seq* orelse;
  7177. string type_comment;
  7178. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  7179. return 1;
  7180. }
  7181. if (tmp == NULL) {
  7182. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from AsyncFor");
  7183. return 1;
  7184. }
  7185. else {
  7186. int res;
  7187. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7188. goto failed;
  7189. }
  7190. res = obj2ast_expr(state, tmp, &target, arena);
  7191. _Py_LeaveRecursiveCall();
  7192. if (res != 0) goto failed;
  7193. Py_CLEAR(tmp);
  7194. }
  7195. if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
  7196. return 1;
  7197. }
  7198. if (tmp == NULL) {
  7199. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from AsyncFor");
  7200. return 1;
  7201. }
  7202. else {
  7203. int res;
  7204. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7205. goto failed;
  7206. }
  7207. res = obj2ast_expr(state, tmp, &iter, arena);
  7208. _Py_LeaveRecursiveCall();
  7209. if (res != 0) goto failed;
  7210. Py_CLEAR(tmp);
  7211. }
  7212. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7213. return 1;
  7214. }
  7215. if (tmp == NULL) {
  7216. tmp = PyList_New(0);
  7217. if (tmp == NULL) {
  7218. return 1;
  7219. }
  7220. }
  7221. {
  7222. int res;
  7223. Py_ssize_t len;
  7224. Py_ssize_t i;
  7225. if (!PyList_Check(tmp)) {
  7226. PyErr_Format(PyExc_TypeError, "AsyncFor field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7227. goto failed;
  7228. }
  7229. len = PyList_GET_SIZE(tmp);
  7230. body = _Py_asdl_stmt_seq_new(len, arena);
  7231. if (body == NULL) goto failed;
  7232. for (i = 0; i < len; i++) {
  7233. stmt_ty val;
  7234. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7235. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7236. goto failed;
  7237. }
  7238. res = obj2ast_stmt(state, tmp2, &val, arena);
  7239. _Py_LeaveRecursiveCall();
  7240. Py_DECREF(tmp2);
  7241. if (res != 0) goto failed;
  7242. if (len != PyList_GET_SIZE(tmp)) {
  7243. PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"body\" changed size during iteration");
  7244. goto failed;
  7245. }
  7246. asdl_seq_SET(body, i, val);
  7247. }
  7248. Py_CLEAR(tmp);
  7249. }
  7250. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7251. return 1;
  7252. }
  7253. if (tmp == NULL) {
  7254. tmp = PyList_New(0);
  7255. if (tmp == NULL) {
  7256. return 1;
  7257. }
  7258. }
  7259. {
  7260. int res;
  7261. Py_ssize_t len;
  7262. Py_ssize_t i;
  7263. if (!PyList_Check(tmp)) {
  7264. PyErr_Format(PyExc_TypeError, "AsyncFor field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7265. goto failed;
  7266. }
  7267. len = PyList_GET_SIZE(tmp);
  7268. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7269. if (orelse == NULL) goto failed;
  7270. for (i = 0; i < len; i++) {
  7271. stmt_ty val;
  7272. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7273. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7274. goto failed;
  7275. }
  7276. res = obj2ast_stmt(state, tmp2, &val, arena);
  7277. _Py_LeaveRecursiveCall();
  7278. Py_DECREF(tmp2);
  7279. if (res != 0) goto failed;
  7280. if (len != PyList_GET_SIZE(tmp)) {
  7281. PyErr_SetString(PyExc_RuntimeError, "AsyncFor field \"orelse\" changed size during iteration");
  7282. goto failed;
  7283. }
  7284. asdl_seq_SET(orelse, i, val);
  7285. }
  7286. Py_CLEAR(tmp);
  7287. }
  7288. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  7289. return 1;
  7290. }
  7291. if (tmp == NULL || tmp == Py_None) {
  7292. Py_CLEAR(tmp);
  7293. type_comment = NULL;
  7294. }
  7295. else {
  7296. int res;
  7297. if (_Py_EnterRecursiveCall(" while traversing 'AsyncFor' node")) {
  7298. goto failed;
  7299. }
  7300. res = obj2ast_string(state, tmp, &type_comment, arena);
  7301. _Py_LeaveRecursiveCall();
  7302. if (res != 0) goto failed;
  7303. Py_CLEAR(tmp);
  7304. }
  7305. *out = _PyAST_AsyncFor(target, iter, body, orelse, type_comment,
  7306. lineno, col_offset, end_lineno, end_col_offset,
  7307. arena);
  7308. if (*out == NULL) goto failed;
  7309. return 0;
  7310. }
  7311. tp = state->While_type;
  7312. isinstance = PyObject_IsInstance(obj, tp);
  7313. if (isinstance == -1) {
  7314. return 1;
  7315. }
  7316. if (isinstance) {
  7317. expr_ty test;
  7318. asdl_stmt_seq* body;
  7319. asdl_stmt_seq* orelse;
  7320. if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
  7321. return 1;
  7322. }
  7323. if (tmp == NULL) {
  7324. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from While");
  7325. return 1;
  7326. }
  7327. else {
  7328. int res;
  7329. if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
  7330. goto failed;
  7331. }
  7332. res = obj2ast_expr(state, tmp, &test, arena);
  7333. _Py_LeaveRecursiveCall();
  7334. if (res != 0) goto failed;
  7335. Py_CLEAR(tmp);
  7336. }
  7337. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7338. return 1;
  7339. }
  7340. if (tmp == NULL) {
  7341. tmp = PyList_New(0);
  7342. if (tmp == NULL) {
  7343. return 1;
  7344. }
  7345. }
  7346. {
  7347. int res;
  7348. Py_ssize_t len;
  7349. Py_ssize_t i;
  7350. if (!PyList_Check(tmp)) {
  7351. PyErr_Format(PyExc_TypeError, "While field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7352. goto failed;
  7353. }
  7354. len = PyList_GET_SIZE(tmp);
  7355. body = _Py_asdl_stmt_seq_new(len, arena);
  7356. if (body == NULL) goto failed;
  7357. for (i = 0; i < len; i++) {
  7358. stmt_ty val;
  7359. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7360. if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
  7361. goto failed;
  7362. }
  7363. res = obj2ast_stmt(state, tmp2, &val, arena);
  7364. _Py_LeaveRecursiveCall();
  7365. Py_DECREF(tmp2);
  7366. if (res != 0) goto failed;
  7367. if (len != PyList_GET_SIZE(tmp)) {
  7368. PyErr_SetString(PyExc_RuntimeError, "While field \"body\" changed size during iteration");
  7369. goto failed;
  7370. }
  7371. asdl_seq_SET(body, i, val);
  7372. }
  7373. Py_CLEAR(tmp);
  7374. }
  7375. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7376. return 1;
  7377. }
  7378. if (tmp == NULL) {
  7379. tmp = PyList_New(0);
  7380. if (tmp == NULL) {
  7381. return 1;
  7382. }
  7383. }
  7384. {
  7385. int res;
  7386. Py_ssize_t len;
  7387. Py_ssize_t i;
  7388. if (!PyList_Check(tmp)) {
  7389. PyErr_Format(PyExc_TypeError, "While field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7390. goto failed;
  7391. }
  7392. len = PyList_GET_SIZE(tmp);
  7393. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7394. if (orelse == NULL) goto failed;
  7395. for (i = 0; i < len; i++) {
  7396. stmt_ty val;
  7397. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7398. if (_Py_EnterRecursiveCall(" while traversing 'While' node")) {
  7399. goto failed;
  7400. }
  7401. res = obj2ast_stmt(state, tmp2, &val, arena);
  7402. _Py_LeaveRecursiveCall();
  7403. Py_DECREF(tmp2);
  7404. if (res != 0) goto failed;
  7405. if (len != PyList_GET_SIZE(tmp)) {
  7406. PyErr_SetString(PyExc_RuntimeError, "While field \"orelse\" changed size during iteration");
  7407. goto failed;
  7408. }
  7409. asdl_seq_SET(orelse, i, val);
  7410. }
  7411. Py_CLEAR(tmp);
  7412. }
  7413. *out = _PyAST_While(test, body, orelse, lineno, col_offset, end_lineno,
  7414. end_col_offset, arena);
  7415. if (*out == NULL) goto failed;
  7416. return 0;
  7417. }
  7418. tp = state->If_type;
  7419. isinstance = PyObject_IsInstance(obj, tp);
  7420. if (isinstance == -1) {
  7421. return 1;
  7422. }
  7423. if (isinstance) {
  7424. expr_ty test;
  7425. asdl_stmt_seq* body;
  7426. asdl_stmt_seq* orelse;
  7427. if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
  7428. return 1;
  7429. }
  7430. if (tmp == NULL) {
  7431. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from If");
  7432. return 1;
  7433. }
  7434. else {
  7435. int res;
  7436. if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
  7437. goto failed;
  7438. }
  7439. res = obj2ast_expr(state, tmp, &test, arena);
  7440. _Py_LeaveRecursiveCall();
  7441. if (res != 0) goto failed;
  7442. Py_CLEAR(tmp);
  7443. }
  7444. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7445. return 1;
  7446. }
  7447. if (tmp == NULL) {
  7448. tmp = PyList_New(0);
  7449. if (tmp == NULL) {
  7450. return 1;
  7451. }
  7452. }
  7453. {
  7454. int res;
  7455. Py_ssize_t len;
  7456. Py_ssize_t i;
  7457. if (!PyList_Check(tmp)) {
  7458. PyErr_Format(PyExc_TypeError, "If field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7459. goto failed;
  7460. }
  7461. len = PyList_GET_SIZE(tmp);
  7462. body = _Py_asdl_stmt_seq_new(len, arena);
  7463. if (body == NULL) goto failed;
  7464. for (i = 0; i < len; i++) {
  7465. stmt_ty val;
  7466. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7467. if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
  7468. goto failed;
  7469. }
  7470. res = obj2ast_stmt(state, tmp2, &val, arena);
  7471. _Py_LeaveRecursiveCall();
  7472. Py_DECREF(tmp2);
  7473. if (res != 0) goto failed;
  7474. if (len != PyList_GET_SIZE(tmp)) {
  7475. PyErr_SetString(PyExc_RuntimeError, "If field \"body\" changed size during iteration");
  7476. goto failed;
  7477. }
  7478. asdl_seq_SET(body, i, val);
  7479. }
  7480. Py_CLEAR(tmp);
  7481. }
  7482. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7483. return 1;
  7484. }
  7485. if (tmp == NULL) {
  7486. tmp = PyList_New(0);
  7487. if (tmp == NULL) {
  7488. return 1;
  7489. }
  7490. }
  7491. {
  7492. int res;
  7493. Py_ssize_t len;
  7494. Py_ssize_t i;
  7495. if (!PyList_Check(tmp)) {
  7496. PyErr_Format(PyExc_TypeError, "If field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7497. goto failed;
  7498. }
  7499. len = PyList_GET_SIZE(tmp);
  7500. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7501. if (orelse == NULL) goto failed;
  7502. for (i = 0; i < len; i++) {
  7503. stmt_ty val;
  7504. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7505. if (_Py_EnterRecursiveCall(" while traversing 'If' node")) {
  7506. goto failed;
  7507. }
  7508. res = obj2ast_stmt(state, tmp2, &val, arena);
  7509. _Py_LeaveRecursiveCall();
  7510. Py_DECREF(tmp2);
  7511. if (res != 0) goto failed;
  7512. if (len != PyList_GET_SIZE(tmp)) {
  7513. PyErr_SetString(PyExc_RuntimeError, "If field \"orelse\" changed size during iteration");
  7514. goto failed;
  7515. }
  7516. asdl_seq_SET(orelse, i, val);
  7517. }
  7518. Py_CLEAR(tmp);
  7519. }
  7520. *out = _PyAST_If(test, body, orelse, lineno, col_offset, end_lineno,
  7521. end_col_offset, arena);
  7522. if (*out == NULL) goto failed;
  7523. return 0;
  7524. }
  7525. tp = state->With_type;
  7526. isinstance = PyObject_IsInstance(obj, tp);
  7527. if (isinstance == -1) {
  7528. return 1;
  7529. }
  7530. if (isinstance) {
  7531. asdl_withitem_seq* items;
  7532. asdl_stmt_seq* body;
  7533. string type_comment;
  7534. if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
  7535. return 1;
  7536. }
  7537. if (tmp == NULL) {
  7538. tmp = PyList_New(0);
  7539. if (tmp == NULL) {
  7540. return 1;
  7541. }
  7542. }
  7543. {
  7544. int res;
  7545. Py_ssize_t len;
  7546. Py_ssize_t i;
  7547. if (!PyList_Check(tmp)) {
  7548. PyErr_Format(PyExc_TypeError, "With field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7549. goto failed;
  7550. }
  7551. len = PyList_GET_SIZE(tmp);
  7552. items = _Py_asdl_withitem_seq_new(len, arena);
  7553. if (items == NULL) goto failed;
  7554. for (i = 0; i < len; i++) {
  7555. withitem_ty val;
  7556. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7557. if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
  7558. goto failed;
  7559. }
  7560. res = obj2ast_withitem(state, tmp2, &val, arena);
  7561. _Py_LeaveRecursiveCall();
  7562. Py_DECREF(tmp2);
  7563. if (res != 0) goto failed;
  7564. if (len != PyList_GET_SIZE(tmp)) {
  7565. PyErr_SetString(PyExc_RuntimeError, "With field \"items\" changed size during iteration");
  7566. goto failed;
  7567. }
  7568. asdl_seq_SET(items, i, val);
  7569. }
  7570. Py_CLEAR(tmp);
  7571. }
  7572. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7573. return 1;
  7574. }
  7575. if (tmp == NULL) {
  7576. tmp = PyList_New(0);
  7577. if (tmp == NULL) {
  7578. return 1;
  7579. }
  7580. }
  7581. {
  7582. int res;
  7583. Py_ssize_t len;
  7584. Py_ssize_t i;
  7585. if (!PyList_Check(tmp)) {
  7586. PyErr_Format(PyExc_TypeError, "With field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7587. goto failed;
  7588. }
  7589. len = PyList_GET_SIZE(tmp);
  7590. body = _Py_asdl_stmt_seq_new(len, arena);
  7591. if (body == NULL) goto failed;
  7592. for (i = 0; i < len; i++) {
  7593. stmt_ty val;
  7594. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7595. if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
  7596. goto failed;
  7597. }
  7598. res = obj2ast_stmt(state, tmp2, &val, arena);
  7599. _Py_LeaveRecursiveCall();
  7600. Py_DECREF(tmp2);
  7601. if (res != 0) goto failed;
  7602. if (len != PyList_GET_SIZE(tmp)) {
  7603. PyErr_SetString(PyExc_RuntimeError, "With field \"body\" changed size during iteration");
  7604. goto failed;
  7605. }
  7606. asdl_seq_SET(body, i, val);
  7607. }
  7608. Py_CLEAR(tmp);
  7609. }
  7610. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  7611. return 1;
  7612. }
  7613. if (tmp == NULL || tmp == Py_None) {
  7614. Py_CLEAR(tmp);
  7615. type_comment = NULL;
  7616. }
  7617. else {
  7618. int res;
  7619. if (_Py_EnterRecursiveCall(" while traversing 'With' node")) {
  7620. goto failed;
  7621. }
  7622. res = obj2ast_string(state, tmp, &type_comment, arena);
  7623. _Py_LeaveRecursiveCall();
  7624. if (res != 0) goto failed;
  7625. Py_CLEAR(tmp);
  7626. }
  7627. *out = _PyAST_With(items, body, type_comment, lineno, col_offset,
  7628. end_lineno, end_col_offset, arena);
  7629. if (*out == NULL) goto failed;
  7630. return 0;
  7631. }
  7632. tp = state->AsyncWith_type;
  7633. isinstance = PyObject_IsInstance(obj, tp);
  7634. if (isinstance == -1) {
  7635. return 1;
  7636. }
  7637. if (isinstance) {
  7638. asdl_withitem_seq* items;
  7639. asdl_stmt_seq* body;
  7640. string type_comment;
  7641. if (_PyObject_LookupAttr(obj, state->items, &tmp) < 0) {
  7642. return 1;
  7643. }
  7644. if (tmp == NULL) {
  7645. tmp = PyList_New(0);
  7646. if (tmp == NULL) {
  7647. return 1;
  7648. }
  7649. }
  7650. {
  7651. int res;
  7652. Py_ssize_t len;
  7653. Py_ssize_t i;
  7654. if (!PyList_Check(tmp)) {
  7655. PyErr_Format(PyExc_TypeError, "AsyncWith field \"items\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7656. goto failed;
  7657. }
  7658. len = PyList_GET_SIZE(tmp);
  7659. items = _Py_asdl_withitem_seq_new(len, arena);
  7660. if (items == NULL) goto failed;
  7661. for (i = 0; i < len; i++) {
  7662. withitem_ty val;
  7663. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7664. if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
  7665. goto failed;
  7666. }
  7667. res = obj2ast_withitem(state, tmp2, &val, arena);
  7668. _Py_LeaveRecursiveCall();
  7669. Py_DECREF(tmp2);
  7670. if (res != 0) goto failed;
  7671. if (len != PyList_GET_SIZE(tmp)) {
  7672. PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"items\" changed size during iteration");
  7673. goto failed;
  7674. }
  7675. asdl_seq_SET(items, i, val);
  7676. }
  7677. Py_CLEAR(tmp);
  7678. }
  7679. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7680. return 1;
  7681. }
  7682. if (tmp == NULL) {
  7683. tmp = PyList_New(0);
  7684. if (tmp == NULL) {
  7685. return 1;
  7686. }
  7687. }
  7688. {
  7689. int res;
  7690. Py_ssize_t len;
  7691. Py_ssize_t i;
  7692. if (!PyList_Check(tmp)) {
  7693. PyErr_Format(PyExc_TypeError, "AsyncWith field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7694. goto failed;
  7695. }
  7696. len = PyList_GET_SIZE(tmp);
  7697. body = _Py_asdl_stmt_seq_new(len, arena);
  7698. if (body == NULL) goto failed;
  7699. for (i = 0; i < len; i++) {
  7700. stmt_ty val;
  7701. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7702. if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
  7703. goto failed;
  7704. }
  7705. res = obj2ast_stmt(state, tmp2, &val, arena);
  7706. _Py_LeaveRecursiveCall();
  7707. Py_DECREF(tmp2);
  7708. if (res != 0) goto failed;
  7709. if (len != PyList_GET_SIZE(tmp)) {
  7710. PyErr_SetString(PyExc_RuntimeError, "AsyncWith field \"body\" changed size during iteration");
  7711. goto failed;
  7712. }
  7713. asdl_seq_SET(body, i, val);
  7714. }
  7715. Py_CLEAR(tmp);
  7716. }
  7717. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  7718. return 1;
  7719. }
  7720. if (tmp == NULL || tmp == Py_None) {
  7721. Py_CLEAR(tmp);
  7722. type_comment = NULL;
  7723. }
  7724. else {
  7725. int res;
  7726. if (_Py_EnterRecursiveCall(" while traversing 'AsyncWith' node")) {
  7727. goto failed;
  7728. }
  7729. res = obj2ast_string(state, tmp, &type_comment, arena);
  7730. _Py_LeaveRecursiveCall();
  7731. if (res != 0) goto failed;
  7732. Py_CLEAR(tmp);
  7733. }
  7734. *out = _PyAST_AsyncWith(items, body, type_comment, lineno, col_offset,
  7735. end_lineno, end_col_offset, arena);
  7736. if (*out == NULL) goto failed;
  7737. return 0;
  7738. }
  7739. tp = state->Match_type;
  7740. isinstance = PyObject_IsInstance(obj, tp);
  7741. if (isinstance == -1) {
  7742. return 1;
  7743. }
  7744. if (isinstance) {
  7745. expr_ty subject;
  7746. asdl_match_case_seq* cases;
  7747. if (_PyObject_LookupAttr(obj, state->subject, &tmp) < 0) {
  7748. return 1;
  7749. }
  7750. if (tmp == NULL) {
  7751. PyErr_SetString(PyExc_TypeError, "required field \"subject\" missing from Match");
  7752. return 1;
  7753. }
  7754. else {
  7755. int res;
  7756. if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
  7757. goto failed;
  7758. }
  7759. res = obj2ast_expr(state, tmp, &subject, arena);
  7760. _Py_LeaveRecursiveCall();
  7761. if (res != 0) goto failed;
  7762. Py_CLEAR(tmp);
  7763. }
  7764. if (_PyObject_LookupAttr(obj, state->cases, &tmp) < 0) {
  7765. return 1;
  7766. }
  7767. if (tmp == NULL) {
  7768. tmp = PyList_New(0);
  7769. if (tmp == NULL) {
  7770. return 1;
  7771. }
  7772. }
  7773. {
  7774. int res;
  7775. Py_ssize_t len;
  7776. Py_ssize_t i;
  7777. if (!PyList_Check(tmp)) {
  7778. PyErr_Format(PyExc_TypeError, "Match field \"cases\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7779. goto failed;
  7780. }
  7781. len = PyList_GET_SIZE(tmp);
  7782. cases = _Py_asdl_match_case_seq_new(len, arena);
  7783. if (cases == NULL) goto failed;
  7784. for (i = 0; i < len; i++) {
  7785. match_case_ty val;
  7786. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7787. if (_Py_EnterRecursiveCall(" while traversing 'Match' node")) {
  7788. goto failed;
  7789. }
  7790. res = obj2ast_match_case(state, tmp2, &val, arena);
  7791. _Py_LeaveRecursiveCall();
  7792. Py_DECREF(tmp2);
  7793. if (res != 0) goto failed;
  7794. if (len != PyList_GET_SIZE(tmp)) {
  7795. PyErr_SetString(PyExc_RuntimeError, "Match field \"cases\" changed size during iteration");
  7796. goto failed;
  7797. }
  7798. asdl_seq_SET(cases, i, val);
  7799. }
  7800. Py_CLEAR(tmp);
  7801. }
  7802. *out = _PyAST_Match(subject, cases, lineno, col_offset, end_lineno,
  7803. end_col_offset, arena);
  7804. if (*out == NULL) goto failed;
  7805. return 0;
  7806. }
  7807. tp = state->Raise_type;
  7808. isinstance = PyObject_IsInstance(obj, tp);
  7809. if (isinstance == -1) {
  7810. return 1;
  7811. }
  7812. if (isinstance) {
  7813. expr_ty exc;
  7814. expr_ty cause;
  7815. if (_PyObject_LookupAttr(obj, state->exc, &tmp) < 0) {
  7816. return 1;
  7817. }
  7818. if (tmp == NULL || tmp == Py_None) {
  7819. Py_CLEAR(tmp);
  7820. exc = NULL;
  7821. }
  7822. else {
  7823. int res;
  7824. if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
  7825. goto failed;
  7826. }
  7827. res = obj2ast_expr(state, tmp, &exc, arena);
  7828. _Py_LeaveRecursiveCall();
  7829. if (res != 0) goto failed;
  7830. Py_CLEAR(tmp);
  7831. }
  7832. if (_PyObject_LookupAttr(obj, state->cause, &tmp) < 0) {
  7833. return 1;
  7834. }
  7835. if (tmp == NULL || tmp == Py_None) {
  7836. Py_CLEAR(tmp);
  7837. cause = NULL;
  7838. }
  7839. else {
  7840. int res;
  7841. if (_Py_EnterRecursiveCall(" while traversing 'Raise' node")) {
  7842. goto failed;
  7843. }
  7844. res = obj2ast_expr(state, tmp, &cause, arena);
  7845. _Py_LeaveRecursiveCall();
  7846. if (res != 0) goto failed;
  7847. Py_CLEAR(tmp);
  7848. }
  7849. *out = _PyAST_Raise(exc, cause, lineno, col_offset, end_lineno,
  7850. end_col_offset, arena);
  7851. if (*out == NULL) goto failed;
  7852. return 0;
  7853. }
  7854. tp = state->Try_type;
  7855. isinstance = PyObject_IsInstance(obj, tp);
  7856. if (isinstance == -1) {
  7857. return 1;
  7858. }
  7859. if (isinstance) {
  7860. asdl_stmt_seq* body;
  7861. asdl_excepthandler_seq* handlers;
  7862. asdl_stmt_seq* orelse;
  7863. asdl_stmt_seq* finalbody;
  7864. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  7865. return 1;
  7866. }
  7867. if (tmp == NULL) {
  7868. tmp = PyList_New(0);
  7869. if (tmp == NULL) {
  7870. return 1;
  7871. }
  7872. }
  7873. {
  7874. int res;
  7875. Py_ssize_t len;
  7876. Py_ssize_t i;
  7877. if (!PyList_Check(tmp)) {
  7878. PyErr_Format(PyExc_TypeError, "Try field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7879. goto failed;
  7880. }
  7881. len = PyList_GET_SIZE(tmp);
  7882. body = _Py_asdl_stmt_seq_new(len, arena);
  7883. if (body == NULL) goto failed;
  7884. for (i = 0; i < len; i++) {
  7885. stmt_ty val;
  7886. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7887. if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
  7888. goto failed;
  7889. }
  7890. res = obj2ast_stmt(state, tmp2, &val, arena);
  7891. _Py_LeaveRecursiveCall();
  7892. Py_DECREF(tmp2);
  7893. if (res != 0) goto failed;
  7894. if (len != PyList_GET_SIZE(tmp)) {
  7895. PyErr_SetString(PyExc_RuntimeError, "Try field \"body\" changed size during iteration");
  7896. goto failed;
  7897. }
  7898. asdl_seq_SET(body, i, val);
  7899. }
  7900. Py_CLEAR(tmp);
  7901. }
  7902. if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
  7903. return 1;
  7904. }
  7905. if (tmp == NULL) {
  7906. tmp = PyList_New(0);
  7907. if (tmp == NULL) {
  7908. return 1;
  7909. }
  7910. }
  7911. {
  7912. int res;
  7913. Py_ssize_t len;
  7914. Py_ssize_t i;
  7915. if (!PyList_Check(tmp)) {
  7916. PyErr_Format(PyExc_TypeError, "Try field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7917. goto failed;
  7918. }
  7919. len = PyList_GET_SIZE(tmp);
  7920. handlers = _Py_asdl_excepthandler_seq_new(len, arena);
  7921. if (handlers == NULL) goto failed;
  7922. for (i = 0; i < len; i++) {
  7923. excepthandler_ty val;
  7924. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7925. if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
  7926. goto failed;
  7927. }
  7928. res = obj2ast_excepthandler(state, tmp2, &val, arena);
  7929. _Py_LeaveRecursiveCall();
  7930. Py_DECREF(tmp2);
  7931. if (res != 0) goto failed;
  7932. if (len != PyList_GET_SIZE(tmp)) {
  7933. PyErr_SetString(PyExc_RuntimeError, "Try field \"handlers\" changed size during iteration");
  7934. goto failed;
  7935. }
  7936. asdl_seq_SET(handlers, i, val);
  7937. }
  7938. Py_CLEAR(tmp);
  7939. }
  7940. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  7941. return 1;
  7942. }
  7943. if (tmp == NULL) {
  7944. tmp = PyList_New(0);
  7945. if (tmp == NULL) {
  7946. return 1;
  7947. }
  7948. }
  7949. {
  7950. int res;
  7951. Py_ssize_t len;
  7952. Py_ssize_t i;
  7953. if (!PyList_Check(tmp)) {
  7954. PyErr_Format(PyExc_TypeError, "Try field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7955. goto failed;
  7956. }
  7957. len = PyList_GET_SIZE(tmp);
  7958. orelse = _Py_asdl_stmt_seq_new(len, arena);
  7959. if (orelse == NULL) goto failed;
  7960. for (i = 0; i < len; i++) {
  7961. stmt_ty val;
  7962. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  7963. if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
  7964. goto failed;
  7965. }
  7966. res = obj2ast_stmt(state, tmp2, &val, arena);
  7967. _Py_LeaveRecursiveCall();
  7968. Py_DECREF(tmp2);
  7969. if (res != 0) goto failed;
  7970. if (len != PyList_GET_SIZE(tmp)) {
  7971. PyErr_SetString(PyExc_RuntimeError, "Try field \"orelse\" changed size during iteration");
  7972. goto failed;
  7973. }
  7974. asdl_seq_SET(orelse, i, val);
  7975. }
  7976. Py_CLEAR(tmp);
  7977. }
  7978. if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
  7979. return 1;
  7980. }
  7981. if (tmp == NULL) {
  7982. tmp = PyList_New(0);
  7983. if (tmp == NULL) {
  7984. return 1;
  7985. }
  7986. }
  7987. {
  7988. int res;
  7989. Py_ssize_t len;
  7990. Py_ssize_t i;
  7991. if (!PyList_Check(tmp)) {
  7992. PyErr_Format(PyExc_TypeError, "Try field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  7993. goto failed;
  7994. }
  7995. len = PyList_GET_SIZE(tmp);
  7996. finalbody = _Py_asdl_stmt_seq_new(len, arena);
  7997. if (finalbody == NULL) goto failed;
  7998. for (i = 0; i < len; i++) {
  7999. stmt_ty val;
  8000. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8001. if (_Py_EnterRecursiveCall(" while traversing 'Try' node")) {
  8002. goto failed;
  8003. }
  8004. res = obj2ast_stmt(state, tmp2, &val, arena);
  8005. _Py_LeaveRecursiveCall();
  8006. Py_DECREF(tmp2);
  8007. if (res != 0) goto failed;
  8008. if (len != PyList_GET_SIZE(tmp)) {
  8009. PyErr_SetString(PyExc_RuntimeError, "Try field \"finalbody\" changed size during iteration");
  8010. goto failed;
  8011. }
  8012. asdl_seq_SET(finalbody, i, val);
  8013. }
  8014. Py_CLEAR(tmp);
  8015. }
  8016. *out = _PyAST_Try(body, handlers, orelse, finalbody, lineno,
  8017. col_offset, end_lineno, end_col_offset, arena);
  8018. if (*out == NULL) goto failed;
  8019. return 0;
  8020. }
  8021. tp = state->TryStar_type;
  8022. isinstance = PyObject_IsInstance(obj, tp);
  8023. if (isinstance == -1) {
  8024. return 1;
  8025. }
  8026. if (isinstance) {
  8027. asdl_stmt_seq* body;
  8028. asdl_excepthandler_seq* handlers;
  8029. asdl_stmt_seq* orelse;
  8030. asdl_stmt_seq* finalbody;
  8031. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  8032. return 1;
  8033. }
  8034. if (tmp == NULL) {
  8035. tmp = PyList_New(0);
  8036. if (tmp == NULL) {
  8037. return 1;
  8038. }
  8039. }
  8040. {
  8041. int res;
  8042. Py_ssize_t len;
  8043. Py_ssize_t i;
  8044. if (!PyList_Check(tmp)) {
  8045. PyErr_Format(PyExc_TypeError, "TryStar field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8046. goto failed;
  8047. }
  8048. len = PyList_GET_SIZE(tmp);
  8049. body = _Py_asdl_stmt_seq_new(len, arena);
  8050. if (body == NULL) goto failed;
  8051. for (i = 0; i < len; i++) {
  8052. stmt_ty val;
  8053. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8054. if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
  8055. goto failed;
  8056. }
  8057. res = obj2ast_stmt(state, tmp2, &val, arena);
  8058. _Py_LeaveRecursiveCall();
  8059. Py_DECREF(tmp2);
  8060. if (res != 0) goto failed;
  8061. if (len != PyList_GET_SIZE(tmp)) {
  8062. PyErr_SetString(PyExc_RuntimeError, "TryStar field \"body\" changed size during iteration");
  8063. goto failed;
  8064. }
  8065. asdl_seq_SET(body, i, val);
  8066. }
  8067. Py_CLEAR(tmp);
  8068. }
  8069. if (_PyObject_LookupAttr(obj, state->handlers, &tmp) < 0) {
  8070. return 1;
  8071. }
  8072. if (tmp == NULL) {
  8073. tmp = PyList_New(0);
  8074. if (tmp == NULL) {
  8075. return 1;
  8076. }
  8077. }
  8078. {
  8079. int res;
  8080. Py_ssize_t len;
  8081. Py_ssize_t i;
  8082. if (!PyList_Check(tmp)) {
  8083. PyErr_Format(PyExc_TypeError, "TryStar field \"handlers\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8084. goto failed;
  8085. }
  8086. len = PyList_GET_SIZE(tmp);
  8087. handlers = _Py_asdl_excepthandler_seq_new(len, arena);
  8088. if (handlers == NULL) goto failed;
  8089. for (i = 0; i < len; i++) {
  8090. excepthandler_ty val;
  8091. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8092. if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
  8093. goto failed;
  8094. }
  8095. res = obj2ast_excepthandler(state, tmp2, &val, arena);
  8096. _Py_LeaveRecursiveCall();
  8097. Py_DECREF(tmp2);
  8098. if (res != 0) goto failed;
  8099. if (len != PyList_GET_SIZE(tmp)) {
  8100. PyErr_SetString(PyExc_RuntimeError, "TryStar field \"handlers\" changed size during iteration");
  8101. goto failed;
  8102. }
  8103. asdl_seq_SET(handlers, i, val);
  8104. }
  8105. Py_CLEAR(tmp);
  8106. }
  8107. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  8108. return 1;
  8109. }
  8110. if (tmp == NULL) {
  8111. tmp = PyList_New(0);
  8112. if (tmp == NULL) {
  8113. return 1;
  8114. }
  8115. }
  8116. {
  8117. int res;
  8118. Py_ssize_t len;
  8119. Py_ssize_t i;
  8120. if (!PyList_Check(tmp)) {
  8121. PyErr_Format(PyExc_TypeError, "TryStar field \"orelse\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8122. goto failed;
  8123. }
  8124. len = PyList_GET_SIZE(tmp);
  8125. orelse = _Py_asdl_stmt_seq_new(len, arena);
  8126. if (orelse == NULL) goto failed;
  8127. for (i = 0; i < len; i++) {
  8128. stmt_ty val;
  8129. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8130. if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
  8131. goto failed;
  8132. }
  8133. res = obj2ast_stmt(state, tmp2, &val, arena);
  8134. _Py_LeaveRecursiveCall();
  8135. Py_DECREF(tmp2);
  8136. if (res != 0) goto failed;
  8137. if (len != PyList_GET_SIZE(tmp)) {
  8138. PyErr_SetString(PyExc_RuntimeError, "TryStar field \"orelse\" changed size during iteration");
  8139. goto failed;
  8140. }
  8141. asdl_seq_SET(orelse, i, val);
  8142. }
  8143. Py_CLEAR(tmp);
  8144. }
  8145. if (_PyObject_LookupAttr(obj, state->finalbody, &tmp) < 0) {
  8146. return 1;
  8147. }
  8148. if (tmp == NULL) {
  8149. tmp = PyList_New(0);
  8150. if (tmp == NULL) {
  8151. return 1;
  8152. }
  8153. }
  8154. {
  8155. int res;
  8156. Py_ssize_t len;
  8157. Py_ssize_t i;
  8158. if (!PyList_Check(tmp)) {
  8159. PyErr_Format(PyExc_TypeError, "TryStar field \"finalbody\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8160. goto failed;
  8161. }
  8162. len = PyList_GET_SIZE(tmp);
  8163. finalbody = _Py_asdl_stmt_seq_new(len, arena);
  8164. if (finalbody == NULL) goto failed;
  8165. for (i = 0; i < len; i++) {
  8166. stmt_ty val;
  8167. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8168. if (_Py_EnterRecursiveCall(" while traversing 'TryStar' node")) {
  8169. goto failed;
  8170. }
  8171. res = obj2ast_stmt(state, tmp2, &val, arena);
  8172. _Py_LeaveRecursiveCall();
  8173. Py_DECREF(tmp2);
  8174. if (res != 0) goto failed;
  8175. if (len != PyList_GET_SIZE(tmp)) {
  8176. PyErr_SetString(PyExc_RuntimeError, "TryStar field \"finalbody\" changed size during iteration");
  8177. goto failed;
  8178. }
  8179. asdl_seq_SET(finalbody, i, val);
  8180. }
  8181. Py_CLEAR(tmp);
  8182. }
  8183. *out = _PyAST_TryStar(body, handlers, orelse, finalbody, lineno,
  8184. col_offset, end_lineno, end_col_offset, arena);
  8185. if (*out == NULL) goto failed;
  8186. return 0;
  8187. }
  8188. tp = state->Assert_type;
  8189. isinstance = PyObject_IsInstance(obj, tp);
  8190. if (isinstance == -1) {
  8191. return 1;
  8192. }
  8193. if (isinstance) {
  8194. expr_ty test;
  8195. expr_ty msg;
  8196. if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
  8197. return 1;
  8198. }
  8199. if (tmp == NULL) {
  8200. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from Assert");
  8201. return 1;
  8202. }
  8203. else {
  8204. int res;
  8205. if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
  8206. goto failed;
  8207. }
  8208. res = obj2ast_expr(state, tmp, &test, arena);
  8209. _Py_LeaveRecursiveCall();
  8210. if (res != 0) goto failed;
  8211. Py_CLEAR(tmp);
  8212. }
  8213. if (_PyObject_LookupAttr(obj, state->msg, &tmp) < 0) {
  8214. return 1;
  8215. }
  8216. if (tmp == NULL || tmp == Py_None) {
  8217. Py_CLEAR(tmp);
  8218. msg = NULL;
  8219. }
  8220. else {
  8221. int res;
  8222. if (_Py_EnterRecursiveCall(" while traversing 'Assert' node")) {
  8223. goto failed;
  8224. }
  8225. res = obj2ast_expr(state, tmp, &msg, arena);
  8226. _Py_LeaveRecursiveCall();
  8227. if (res != 0) goto failed;
  8228. Py_CLEAR(tmp);
  8229. }
  8230. *out = _PyAST_Assert(test, msg, lineno, col_offset, end_lineno,
  8231. end_col_offset, arena);
  8232. if (*out == NULL) goto failed;
  8233. return 0;
  8234. }
  8235. tp = state->Import_type;
  8236. isinstance = PyObject_IsInstance(obj, tp);
  8237. if (isinstance == -1) {
  8238. return 1;
  8239. }
  8240. if (isinstance) {
  8241. asdl_alias_seq* names;
  8242. if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
  8243. return 1;
  8244. }
  8245. if (tmp == NULL) {
  8246. tmp = PyList_New(0);
  8247. if (tmp == NULL) {
  8248. return 1;
  8249. }
  8250. }
  8251. {
  8252. int res;
  8253. Py_ssize_t len;
  8254. Py_ssize_t i;
  8255. if (!PyList_Check(tmp)) {
  8256. PyErr_Format(PyExc_TypeError, "Import field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8257. goto failed;
  8258. }
  8259. len = PyList_GET_SIZE(tmp);
  8260. names = _Py_asdl_alias_seq_new(len, arena);
  8261. if (names == NULL) goto failed;
  8262. for (i = 0; i < len; i++) {
  8263. alias_ty val;
  8264. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8265. if (_Py_EnterRecursiveCall(" while traversing 'Import' node")) {
  8266. goto failed;
  8267. }
  8268. res = obj2ast_alias(state, tmp2, &val, arena);
  8269. _Py_LeaveRecursiveCall();
  8270. Py_DECREF(tmp2);
  8271. if (res != 0) goto failed;
  8272. if (len != PyList_GET_SIZE(tmp)) {
  8273. PyErr_SetString(PyExc_RuntimeError, "Import field \"names\" changed size during iteration");
  8274. goto failed;
  8275. }
  8276. asdl_seq_SET(names, i, val);
  8277. }
  8278. Py_CLEAR(tmp);
  8279. }
  8280. *out = _PyAST_Import(names, lineno, col_offset, end_lineno,
  8281. end_col_offset, arena);
  8282. if (*out == NULL) goto failed;
  8283. return 0;
  8284. }
  8285. tp = state->ImportFrom_type;
  8286. isinstance = PyObject_IsInstance(obj, tp);
  8287. if (isinstance == -1) {
  8288. return 1;
  8289. }
  8290. if (isinstance) {
  8291. identifier module;
  8292. asdl_alias_seq* names;
  8293. int level;
  8294. if (_PyObject_LookupAttr(obj, state->module, &tmp) < 0) {
  8295. return 1;
  8296. }
  8297. if (tmp == NULL || tmp == Py_None) {
  8298. Py_CLEAR(tmp);
  8299. module = NULL;
  8300. }
  8301. else {
  8302. int res;
  8303. if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
  8304. goto failed;
  8305. }
  8306. res = obj2ast_identifier(state, tmp, &module, arena);
  8307. _Py_LeaveRecursiveCall();
  8308. if (res != 0) goto failed;
  8309. Py_CLEAR(tmp);
  8310. }
  8311. if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
  8312. return 1;
  8313. }
  8314. if (tmp == NULL) {
  8315. tmp = PyList_New(0);
  8316. if (tmp == NULL) {
  8317. return 1;
  8318. }
  8319. }
  8320. {
  8321. int res;
  8322. Py_ssize_t len;
  8323. Py_ssize_t i;
  8324. if (!PyList_Check(tmp)) {
  8325. PyErr_Format(PyExc_TypeError, "ImportFrom field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8326. goto failed;
  8327. }
  8328. len = PyList_GET_SIZE(tmp);
  8329. names = _Py_asdl_alias_seq_new(len, arena);
  8330. if (names == NULL) goto failed;
  8331. for (i = 0; i < len; i++) {
  8332. alias_ty val;
  8333. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8334. if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
  8335. goto failed;
  8336. }
  8337. res = obj2ast_alias(state, tmp2, &val, arena);
  8338. _Py_LeaveRecursiveCall();
  8339. Py_DECREF(tmp2);
  8340. if (res != 0) goto failed;
  8341. if (len != PyList_GET_SIZE(tmp)) {
  8342. PyErr_SetString(PyExc_RuntimeError, "ImportFrom field \"names\" changed size during iteration");
  8343. goto failed;
  8344. }
  8345. asdl_seq_SET(names, i, val);
  8346. }
  8347. Py_CLEAR(tmp);
  8348. }
  8349. if (_PyObject_LookupAttr(obj, state->level, &tmp) < 0) {
  8350. return 1;
  8351. }
  8352. if (tmp == NULL || tmp == Py_None) {
  8353. Py_CLEAR(tmp);
  8354. level = 0;
  8355. }
  8356. else {
  8357. int res;
  8358. if (_Py_EnterRecursiveCall(" while traversing 'ImportFrom' node")) {
  8359. goto failed;
  8360. }
  8361. res = obj2ast_int(state, tmp, &level, arena);
  8362. _Py_LeaveRecursiveCall();
  8363. if (res != 0) goto failed;
  8364. Py_CLEAR(tmp);
  8365. }
  8366. *out = _PyAST_ImportFrom(module, names, level, lineno, col_offset,
  8367. end_lineno, end_col_offset, arena);
  8368. if (*out == NULL) goto failed;
  8369. return 0;
  8370. }
  8371. tp = state->Global_type;
  8372. isinstance = PyObject_IsInstance(obj, tp);
  8373. if (isinstance == -1) {
  8374. return 1;
  8375. }
  8376. if (isinstance) {
  8377. asdl_identifier_seq* names;
  8378. if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
  8379. return 1;
  8380. }
  8381. if (tmp == NULL) {
  8382. tmp = PyList_New(0);
  8383. if (tmp == NULL) {
  8384. return 1;
  8385. }
  8386. }
  8387. {
  8388. int res;
  8389. Py_ssize_t len;
  8390. Py_ssize_t i;
  8391. if (!PyList_Check(tmp)) {
  8392. PyErr_Format(PyExc_TypeError, "Global field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8393. goto failed;
  8394. }
  8395. len = PyList_GET_SIZE(tmp);
  8396. names = _Py_asdl_identifier_seq_new(len, arena);
  8397. if (names == NULL) goto failed;
  8398. for (i = 0; i < len; i++) {
  8399. identifier val;
  8400. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8401. if (_Py_EnterRecursiveCall(" while traversing 'Global' node")) {
  8402. goto failed;
  8403. }
  8404. res = obj2ast_identifier(state, tmp2, &val, arena);
  8405. _Py_LeaveRecursiveCall();
  8406. Py_DECREF(tmp2);
  8407. if (res != 0) goto failed;
  8408. if (len != PyList_GET_SIZE(tmp)) {
  8409. PyErr_SetString(PyExc_RuntimeError, "Global field \"names\" changed size during iteration");
  8410. goto failed;
  8411. }
  8412. asdl_seq_SET(names, i, val);
  8413. }
  8414. Py_CLEAR(tmp);
  8415. }
  8416. *out = _PyAST_Global(names, lineno, col_offset, end_lineno,
  8417. end_col_offset, arena);
  8418. if (*out == NULL) goto failed;
  8419. return 0;
  8420. }
  8421. tp = state->Nonlocal_type;
  8422. isinstance = PyObject_IsInstance(obj, tp);
  8423. if (isinstance == -1) {
  8424. return 1;
  8425. }
  8426. if (isinstance) {
  8427. asdl_identifier_seq* names;
  8428. if (_PyObject_LookupAttr(obj, state->names, &tmp) < 0) {
  8429. return 1;
  8430. }
  8431. if (tmp == NULL) {
  8432. tmp = PyList_New(0);
  8433. if (tmp == NULL) {
  8434. return 1;
  8435. }
  8436. }
  8437. {
  8438. int res;
  8439. Py_ssize_t len;
  8440. Py_ssize_t i;
  8441. if (!PyList_Check(tmp)) {
  8442. PyErr_Format(PyExc_TypeError, "Nonlocal field \"names\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8443. goto failed;
  8444. }
  8445. len = PyList_GET_SIZE(tmp);
  8446. names = _Py_asdl_identifier_seq_new(len, arena);
  8447. if (names == NULL) goto failed;
  8448. for (i = 0; i < len; i++) {
  8449. identifier val;
  8450. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8451. if (_Py_EnterRecursiveCall(" while traversing 'Nonlocal' node")) {
  8452. goto failed;
  8453. }
  8454. res = obj2ast_identifier(state, tmp2, &val, arena);
  8455. _Py_LeaveRecursiveCall();
  8456. Py_DECREF(tmp2);
  8457. if (res != 0) goto failed;
  8458. if (len != PyList_GET_SIZE(tmp)) {
  8459. PyErr_SetString(PyExc_RuntimeError, "Nonlocal field \"names\" changed size during iteration");
  8460. goto failed;
  8461. }
  8462. asdl_seq_SET(names, i, val);
  8463. }
  8464. Py_CLEAR(tmp);
  8465. }
  8466. *out = _PyAST_Nonlocal(names, lineno, col_offset, end_lineno,
  8467. end_col_offset, arena);
  8468. if (*out == NULL) goto failed;
  8469. return 0;
  8470. }
  8471. tp = state->Expr_type;
  8472. isinstance = PyObject_IsInstance(obj, tp);
  8473. if (isinstance == -1) {
  8474. return 1;
  8475. }
  8476. if (isinstance) {
  8477. expr_ty value;
  8478. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  8479. return 1;
  8480. }
  8481. if (tmp == NULL) {
  8482. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Expr");
  8483. return 1;
  8484. }
  8485. else {
  8486. int res;
  8487. if (_Py_EnterRecursiveCall(" while traversing 'Expr' node")) {
  8488. goto failed;
  8489. }
  8490. res = obj2ast_expr(state, tmp, &value, arena);
  8491. _Py_LeaveRecursiveCall();
  8492. if (res != 0) goto failed;
  8493. Py_CLEAR(tmp);
  8494. }
  8495. *out = _PyAST_Expr(value, lineno, col_offset, end_lineno,
  8496. end_col_offset, arena);
  8497. if (*out == NULL) goto failed;
  8498. return 0;
  8499. }
  8500. tp = state->Pass_type;
  8501. isinstance = PyObject_IsInstance(obj, tp);
  8502. if (isinstance == -1) {
  8503. return 1;
  8504. }
  8505. if (isinstance) {
  8506. *out = _PyAST_Pass(lineno, col_offset, end_lineno, end_col_offset,
  8507. arena);
  8508. if (*out == NULL) goto failed;
  8509. return 0;
  8510. }
  8511. tp = state->Break_type;
  8512. isinstance = PyObject_IsInstance(obj, tp);
  8513. if (isinstance == -1) {
  8514. return 1;
  8515. }
  8516. if (isinstance) {
  8517. *out = _PyAST_Break(lineno, col_offset, end_lineno, end_col_offset,
  8518. arena);
  8519. if (*out == NULL) goto failed;
  8520. return 0;
  8521. }
  8522. tp = state->Continue_type;
  8523. isinstance = PyObject_IsInstance(obj, tp);
  8524. if (isinstance == -1) {
  8525. return 1;
  8526. }
  8527. if (isinstance) {
  8528. *out = _PyAST_Continue(lineno, col_offset, end_lineno, end_col_offset,
  8529. arena);
  8530. if (*out == NULL) goto failed;
  8531. return 0;
  8532. }
  8533. PyErr_Format(PyExc_TypeError, "expected some sort of stmt, but got %R", obj);
  8534. failed:
  8535. Py_XDECREF(tmp);
  8536. return 1;
  8537. }
  8538. int
  8539. obj2ast_expr(struct ast_state *state, PyObject* obj, expr_ty* out, PyArena*
  8540. arena)
  8541. {
  8542. int isinstance;
  8543. PyObject *tmp = NULL;
  8544. PyObject *tp;
  8545. int lineno;
  8546. int col_offset;
  8547. int end_lineno;
  8548. int end_col_offset;
  8549. if (obj == Py_None) {
  8550. *out = NULL;
  8551. return 0;
  8552. }
  8553. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  8554. return 1;
  8555. }
  8556. if (tmp == NULL) {
  8557. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from expr");
  8558. return 1;
  8559. }
  8560. else {
  8561. int res;
  8562. if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
  8563. goto failed;
  8564. }
  8565. res = obj2ast_int(state, tmp, &lineno, arena);
  8566. _Py_LeaveRecursiveCall();
  8567. if (res != 0) goto failed;
  8568. Py_CLEAR(tmp);
  8569. }
  8570. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  8571. return 1;
  8572. }
  8573. if (tmp == NULL) {
  8574. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from expr");
  8575. return 1;
  8576. }
  8577. else {
  8578. int res;
  8579. if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
  8580. goto failed;
  8581. }
  8582. res = obj2ast_int(state, tmp, &col_offset, arena);
  8583. _Py_LeaveRecursiveCall();
  8584. if (res != 0) goto failed;
  8585. Py_CLEAR(tmp);
  8586. }
  8587. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  8588. return 1;
  8589. }
  8590. if (tmp == NULL || tmp == Py_None) {
  8591. Py_CLEAR(tmp);
  8592. end_lineno = lineno;
  8593. }
  8594. else {
  8595. int res;
  8596. if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
  8597. goto failed;
  8598. }
  8599. res = obj2ast_int(state, tmp, &end_lineno, arena);
  8600. _Py_LeaveRecursiveCall();
  8601. if (res != 0) goto failed;
  8602. Py_CLEAR(tmp);
  8603. }
  8604. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  8605. return 1;
  8606. }
  8607. if (tmp == NULL || tmp == Py_None) {
  8608. Py_CLEAR(tmp);
  8609. end_col_offset = col_offset;
  8610. }
  8611. else {
  8612. int res;
  8613. if (_Py_EnterRecursiveCall(" while traversing 'expr' node")) {
  8614. goto failed;
  8615. }
  8616. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  8617. _Py_LeaveRecursiveCall();
  8618. if (res != 0) goto failed;
  8619. Py_CLEAR(tmp);
  8620. }
  8621. tp = state->BoolOp_type;
  8622. isinstance = PyObject_IsInstance(obj, tp);
  8623. if (isinstance == -1) {
  8624. return 1;
  8625. }
  8626. if (isinstance) {
  8627. boolop_ty op;
  8628. asdl_expr_seq* values;
  8629. if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
  8630. return 1;
  8631. }
  8632. if (tmp == NULL) {
  8633. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BoolOp");
  8634. return 1;
  8635. }
  8636. else {
  8637. int res;
  8638. if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
  8639. goto failed;
  8640. }
  8641. res = obj2ast_boolop(state, tmp, &op, arena);
  8642. _Py_LeaveRecursiveCall();
  8643. if (res != 0) goto failed;
  8644. Py_CLEAR(tmp);
  8645. }
  8646. if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
  8647. return 1;
  8648. }
  8649. if (tmp == NULL) {
  8650. tmp = PyList_New(0);
  8651. if (tmp == NULL) {
  8652. return 1;
  8653. }
  8654. }
  8655. {
  8656. int res;
  8657. Py_ssize_t len;
  8658. Py_ssize_t i;
  8659. if (!PyList_Check(tmp)) {
  8660. PyErr_Format(PyExc_TypeError, "BoolOp field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8661. goto failed;
  8662. }
  8663. len = PyList_GET_SIZE(tmp);
  8664. values = _Py_asdl_expr_seq_new(len, arena);
  8665. if (values == NULL) goto failed;
  8666. for (i = 0; i < len; i++) {
  8667. expr_ty val;
  8668. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8669. if (_Py_EnterRecursiveCall(" while traversing 'BoolOp' node")) {
  8670. goto failed;
  8671. }
  8672. res = obj2ast_expr(state, tmp2, &val, arena);
  8673. _Py_LeaveRecursiveCall();
  8674. Py_DECREF(tmp2);
  8675. if (res != 0) goto failed;
  8676. if (len != PyList_GET_SIZE(tmp)) {
  8677. PyErr_SetString(PyExc_RuntimeError, "BoolOp field \"values\" changed size during iteration");
  8678. goto failed;
  8679. }
  8680. asdl_seq_SET(values, i, val);
  8681. }
  8682. Py_CLEAR(tmp);
  8683. }
  8684. *out = _PyAST_BoolOp(op, values, lineno, col_offset, end_lineno,
  8685. end_col_offset, arena);
  8686. if (*out == NULL) goto failed;
  8687. return 0;
  8688. }
  8689. tp = state->NamedExpr_type;
  8690. isinstance = PyObject_IsInstance(obj, tp);
  8691. if (isinstance == -1) {
  8692. return 1;
  8693. }
  8694. if (isinstance) {
  8695. expr_ty target;
  8696. expr_ty value;
  8697. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  8698. return 1;
  8699. }
  8700. if (tmp == NULL) {
  8701. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from NamedExpr");
  8702. return 1;
  8703. }
  8704. else {
  8705. int res;
  8706. if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
  8707. goto failed;
  8708. }
  8709. res = obj2ast_expr(state, tmp, &target, arena);
  8710. _Py_LeaveRecursiveCall();
  8711. if (res != 0) goto failed;
  8712. Py_CLEAR(tmp);
  8713. }
  8714. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  8715. return 1;
  8716. }
  8717. if (tmp == NULL) {
  8718. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from NamedExpr");
  8719. return 1;
  8720. }
  8721. else {
  8722. int res;
  8723. if (_Py_EnterRecursiveCall(" while traversing 'NamedExpr' node")) {
  8724. goto failed;
  8725. }
  8726. res = obj2ast_expr(state, tmp, &value, arena);
  8727. _Py_LeaveRecursiveCall();
  8728. if (res != 0) goto failed;
  8729. Py_CLEAR(tmp);
  8730. }
  8731. *out = _PyAST_NamedExpr(target, value, lineno, col_offset, end_lineno,
  8732. end_col_offset, arena);
  8733. if (*out == NULL) goto failed;
  8734. return 0;
  8735. }
  8736. tp = state->BinOp_type;
  8737. isinstance = PyObject_IsInstance(obj, tp);
  8738. if (isinstance == -1) {
  8739. return 1;
  8740. }
  8741. if (isinstance) {
  8742. expr_ty left;
  8743. operator_ty op;
  8744. expr_ty right;
  8745. if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
  8746. return 1;
  8747. }
  8748. if (tmp == NULL) {
  8749. PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from BinOp");
  8750. return 1;
  8751. }
  8752. else {
  8753. int res;
  8754. if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
  8755. goto failed;
  8756. }
  8757. res = obj2ast_expr(state, tmp, &left, arena);
  8758. _Py_LeaveRecursiveCall();
  8759. if (res != 0) goto failed;
  8760. Py_CLEAR(tmp);
  8761. }
  8762. if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
  8763. return 1;
  8764. }
  8765. if (tmp == NULL) {
  8766. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from BinOp");
  8767. return 1;
  8768. }
  8769. else {
  8770. int res;
  8771. if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
  8772. goto failed;
  8773. }
  8774. res = obj2ast_operator(state, tmp, &op, arena);
  8775. _Py_LeaveRecursiveCall();
  8776. if (res != 0) goto failed;
  8777. Py_CLEAR(tmp);
  8778. }
  8779. if (_PyObject_LookupAttr(obj, state->right, &tmp) < 0) {
  8780. return 1;
  8781. }
  8782. if (tmp == NULL) {
  8783. PyErr_SetString(PyExc_TypeError, "required field \"right\" missing from BinOp");
  8784. return 1;
  8785. }
  8786. else {
  8787. int res;
  8788. if (_Py_EnterRecursiveCall(" while traversing 'BinOp' node")) {
  8789. goto failed;
  8790. }
  8791. res = obj2ast_expr(state, tmp, &right, arena);
  8792. _Py_LeaveRecursiveCall();
  8793. if (res != 0) goto failed;
  8794. Py_CLEAR(tmp);
  8795. }
  8796. *out = _PyAST_BinOp(left, op, right, lineno, col_offset, end_lineno,
  8797. end_col_offset, arena);
  8798. if (*out == NULL) goto failed;
  8799. return 0;
  8800. }
  8801. tp = state->UnaryOp_type;
  8802. isinstance = PyObject_IsInstance(obj, tp);
  8803. if (isinstance == -1) {
  8804. return 1;
  8805. }
  8806. if (isinstance) {
  8807. unaryop_ty op;
  8808. expr_ty operand;
  8809. if (_PyObject_LookupAttr(obj, state->op, &tmp) < 0) {
  8810. return 1;
  8811. }
  8812. if (tmp == NULL) {
  8813. PyErr_SetString(PyExc_TypeError, "required field \"op\" missing from UnaryOp");
  8814. return 1;
  8815. }
  8816. else {
  8817. int res;
  8818. if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
  8819. goto failed;
  8820. }
  8821. res = obj2ast_unaryop(state, tmp, &op, arena);
  8822. _Py_LeaveRecursiveCall();
  8823. if (res != 0) goto failed;
  8824. Py_CLEAR(tmp);
  8825. }
  8826. if (_PyObject_LookupAttr(obj, state->operand, &tmp) < 0) {
  8827. return 1;
  8828. }
  8829. if (tmp == NULL) {
  8830. PyErr_SetString(PyExc_TypeError, "required field \"operand\" missing from UnaryOp");
  8831. return 1;
  8832. }
  8833. else {
  8834. int res;
  8835. if (_Py_EnterRecursiveCall(" while traversing 'UnaryOp' node")) {
  8836. goto failed;
  8837. }
  8838. res = obj2ast_expr(state, tmp, &operand, arena);
  8839. _Py_LeaveRecursiveCall();
  8840. if (res != 0) goto failed;
  8841. Py_CLEAR(tmp);
  8842. }
  8843. *out = _PyAST_UnaryOp(op, operand, lineno, col_offset, end_lineno,
  8844. end_col_offset, arena);
  8845. if (*out == NULL) goto failed;
  8846. return 0;
  8847. }
  8848. tp = state->Lambda_type;
  8849. isinstance = PyObject_IsInstance(obj, tp);
  8850. if (isinstance == -1) {
  8851. return 1;
  8852. }
  8853. if (isinstance) {
  8854. arguments_ty args;
  8855. expr_ty body;
  8856. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  8857. return 1;
  8858. }
  8859. if (tmp == NULL) {
  8860. PyErr_SetString(PyExc_TypeError, "required field \"args\" missing from Lambda");
  8861. return 1;
  8862. }
  8863. else {
  8864. int res;
  8865. if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
  8866. goto failed;
  8867. }
  8868. res = obj2ast_arguments(state, tmp, &args, arena);
  8869. _Py_LeaveRecursiveCall();
  8870. if (res != 0) goto failed;
  8871. Py_CLEAR(tmp);
  8872. }
  8873. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  8874. return 1;
  8875. }
  8876. if (tmp == NULL) {
  8877. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from Lambda");
  8878. return 1;
  8879. }
  8880. else {
  8881. int res;
  8882. if (_Py_EnterRecursiveCall(" while traversing 'Lambda' node")) {
  8883. goto failed;
  8884. }
  8885. res = obj2ast_expr(state, tmp, &body, arena);
  8886. _Py_LeaveRecursiveCall();
  8887. if (res != 0) goto failed;
  8888. Py_CLEAR(tmp);
  8889. }
  8890. *out = _PyAST_Lambda(args, body, lineno, col_offset, end_lineno,
  8891. end_col_offset, arena);
  8892. if (*out == NULL) goto failed;
  8893. return 0;
  8894. }
  8895. tp = state->IfExp_type;
  8896. isinstance = PyObject_IsInstance(obj, tp);
  8897. if (isinstance == -1) {
  8898. return 1;
  8899. }
  8900. if (isinstance) {
  8901. expr_ty test;
  8902. expr_ty body;
  8903. expr_ty orelse;
  8904. if (_PyObject_LookupAttr(obj, state->test, &tmp) < 0) {
  8905. return 1;
  8906. }
  8907. if (tmp == NULL) {
  8908. PyErr_SetString(PyExc_TypeError, "required field \"test\" missing from IfExp");
  8909. return 1;
  8910. }
  8911. else {
  8912. int res;
  8913. if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
  8914. goto failed;
  8915. }
  8916. res = obj2ast_expr(state, tmp, &test, arena);
  8917. _Py_LeaveRecursiveCall();
  8918. if (res != 0) goto failed;
  8919. Py_CLEAR(tmp);
  8920. }
  8921. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  8922. return 1;
  8923. }
  8924. if (tmp == NULL) {
  8925. PyErr_SetString(PyExc_TypeError, "required field \"body\" missing from IfExp");
  8926. return 1;
  8927. }
  8928. else {
  8929. int res;
  8930. if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
  8931. goto failed;
  8932. }
  8933. res = obj2ast_expr(state, tmp, &body, arena);
  8934. _Py_LeaveRecursiveCall();
  8935. if (res != 0) goto failed;
  8936. Py_CLEAR(tmp);
  8937. }
  8938. if (_PyObject_LookupAttr(obj, state->orelse, &tmp) < 0) {
  8939. return 1;
  8940. }
  8941. if (tmp == NULL) {
  8942. PyErr_SetString(PyExc_TypeError, "required field \"orelse\" missing from IfExp");
  8943. return 1;
  8944. }
  8945. else {
  8946. int res;
  8947. if (_Py_EnterRecursiveCall(" while traversing 'IfExp' node")) {
  8948. goto failed;
  8949. }
  8950. res = obj2ast_expr(state, tmp, &orelse, arena);
  8951. _Py_LeaveRecursiveCall();
  8952. if (res != 0) goto failed;
  8953. Py_CLEAR(tmp);
  8954. }
  8955. *out = _PyAST_IfExp(test, body, orelse, lineno, col_offset, end_lineno,
  8956. end_col_offset, arena);
  8957. if (*out == NULL) goto failed;
  8958. return 0;
  8959. }
  8960. tp = state->Dict_type;
  8961. isinstance = PyObject_IsInstance(obj, tp);
  8962. if (isinstance == -1) {
  8963. return 1;
  8964. }
  8965. if (isinstance) {
  8966. asdl_expr_seq* keys;
  8967. asdl_expr_seq* values;
  8968. if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
  8969. return 1;
  8970. }
  8971. if (tmp == NULL) {
  8972. tmp = PyList_New(0);
  8973. if (tmp == NULL) {
  8974. return 1;
  8975. }
  8976. }
  8977. {
  8978. int res;
  8979. Py_ssize_t len;
  8980. Py_ssize_t i;
  8981. if (!PyList_Check(tmp)) {
  8982. PyErr_Format(PyExc_TypeError, "Dict field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  8983. goto failed;
  8984. }
  8985. len = PyList_GET_SIZE(tmp);
  8986. keys = _Py_asdl_expr_seq_new(len, arena);
  8987. if (keys == NULL) goto failed;
  8988. for (i = 0; i < len; i++) {
  8989. expr_ty val;
  8990. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  8991. if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
  8992. goto failed;
  8993. }
  8994. res = obj2ast_expr(state, tmp2, &val, arena);
  8995. _Py_LeaveRecursiveCall();
  8996. Py_DECREF(tmp2);
  8997. if (res != 0) goto failed;
  8998. if (len != PyList_GET_SIZE(tmp)) {
  8999. PyErr_SetString(PyExc_RuntimeError, "Dict field \"keys\" changed size during iteration");
  9000. goto failed;
  9001. }
  9002. asdl_seq_SET(keys, i, val);
  9003. }
  9004. Py_CLEAR(tmp);
  9005. }
  9006. if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
  9007. return 1;
  9008. }
  9009. if (tmp == NULL) {
  9010. tmp = PyList_New(0);
  9011. if (tmp == NULL) {
  9012. return 1;
  9013. }
  9014. }
  9015. {
  9016. int res;
  9017. Py_ssize_t len;
  9018. Py_ssize_t i;
  9019. if (!PyList_Check(tmp)) {
  9020. PyErr_Format(PyExc_TypeError, "Dict field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9021. goto failed;
  9022. }
  9023. len = PyList_GET_SIZE(tmp);
  9024. values = _Py_asdl_expr_seq_new(len, arena);
  9025. if (values == NULL) goto failed;
  9026. for (i = 0; i < len; i++) {
  9027. expr_ty val;
  9028. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9029. if (_Py_EnterRecursiveCall(" while traversing 'Dict' node")) {
  9030. goto failed;
  9031. }
  9032. res = obj2ast_expr(state, tmp2, &val, arena);
  9033. _Py_LeaveRecursiveCall();
  9034. Py_DECREF(tmp2);
  9035. if (res != 0) goto failed;
  9036. if (len != PyList_GET_SIZE(tmp)) {
  9037. PyErr_SetString(PyExc_RuntimeError, "Dict field \"values\" changed size during iteration");
  9038. goto failed;
  9039. }
  9040. asdl_seq_SET(values, i, val);
  9041. }
  9042. Py_CLEAR(tmp);
  9043. }
  9044. *out = _PyAST_Dict(keys, values, lineno, col_offset, end_lineno,
  9045. end_col_offset, arena);
  9046. if (*out == NULL) goto failed;
  9047. return 0;
  9048. }
  9049. tp = state->Set_type;
  9050. isinstance = PyObject_IsInstance(obj, tp);
  9051. if (isinstance == -1) {
  9052. return 1;
  9053. }
  9054. if (isinstance) {
  9055. asdl_expr_seq* elts;
  9056. if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
  9057. return 1;
  9058. }
  9059. if (tmp == NULL) {
  9060. tmp = PyList_New(0);
  9061. if (tmp == NULL) {
  9062. return 1;
  9063. }
  9064. }
  9065. {
  9066. int res;
  9067. Py_ssize_t len;
  9068. Py_ssize_t i;
  9069. if (!PyList_Check(tmp)) {
  9070. PyErr_Format(PyExc_TypeError, "Set field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9071. goto failed;
  9072. }
  9073. len = PyList_GET_SIZE(tmp);
  9074. elts = _Py_asdl_expr_seq_new(len, arena);
  9075. if (elts == NULL) goto failed;
  9076. for (i = 0; i < len; i++) {
  9077. expr_ty val;
  9078. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9079. if (_Py_EnterRecursiveCall(" while traversing 'Set' node")) {
  9080. goto failed;
  9081. }
  9082. res = obj2ast_expr(state, tmp2, &val, arena);
  9083. _Py_LeaveRecursiveCall();
  9084. Py_DECREF(tmp2);
  9085. if (res != 0) goto failed;
  9086. if (len != PyList_GET_SIZE(tmp)) {
  9087. PyErr_SetString(PyExc_RuntimeError, "Set field \"elts\" changed size during iteration");
  9088. goto failed;
  9089. }
  9090. asdl_seq_SET(elts, i, val);
  9091. }
  9092. Py_CLEAR(tmp);
  9093. }
  9094. *out = _PyAST_Set(elts, lineno, col_offset, end_lineno, end_col_offset,
  9095. arena);
  9096. if (*out == NULL) goto failed;
  9097. return 0;
  9098. }
  9099. tp = state->ListComp_type;
  9100. isinstance = PyObject_IsInstance(obj, tp);
  9101. if (isinstance == -1) {
  9102. return 1;
  9103. }
  9104. if (isinstance) {
  9105. expr_ty elt;
  9106. asdl_comprehension_seq* generators;
  9107. if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
  9108. return 1;
  9109. }
  9110. if (tmp == NULL) {
  9111. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from ListComp");
  9112. return 1;
  9113. }
  9114. else {
  9115. int res;
  9116. if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
  9117. goto failed;
  9118. }
  9119. res = obj2ast_expr(state, tmp, &elt, arena);
  9120. _Py_LeaveRecursiveCall();
  9121. if (res != 0) goto failed;
  9122. Py_CLEAR(tmp);
  9123. }
  9124. if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
  9125. return 1;
  9126. }
  9127. if (tmp == NULL) {
  9128. tmp = PyList_New(0);
  9129. if (tmp == NULL) {
  9130. return 1;
  9131. }
  9132. }
  9133. {
  9134. int res;
  9135. Py_ssize_t len;
  9136. Py_ssize_t i;
  9137. if (!PyList_Check(tmp)) {
  9138. PyErr_Format(PyExc_TypeError, "ListComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9139. goto failed;
  9140. }
  9141. len = PyList_GET_SIZE(tmp);
  9142. generators = _Py_asdl_comprehension_seq_new(len, arena);
  9143. if (generators == NULL) goto failed;
  9144. for (i = 0; i < len; i++) {
  9145. comprehension_ty val;
  9146. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9147. if (_Py_EnterRecursiveCall(" while traversing 'ListComp' node")) {
  9148. goto failed;
  9149. }
  9150. res = obj2ast_comprehension(state, tmp2, &val, arena);
  9151. _Py_LeaveRecursiveCall();
  9152. Py_DECREF(tmp2);
  9153. if (res != 0) goto failed;
  9154. if (len != PyList_GET_SIZE(tmp)) {
  9155. PyErr_SetString(PyExc_RuntimeError, "ListComp field \"generators\" changed size during iteration");
  9156. goto failed;
  9157. }
  9158. asdl_seq_SET(generators, i, val);
  9159. }
  9160. Py_CLEAR(tmp);
  9161. }
  9162. *out = _PyAST_ListComp(elt, generators, lineno, col_offset, end_lineno,
  9163. end_col_offset, arena);
  9164. if (*out == NULL) goto failed;
  9165. return 0;
  9166. }
  9167. tp = state->SetComp_type;
  9168. isinstance = PyObject_IsInstance(obj, tp);
  9169. if (isinstance == -1) {
  9170. return 1;
  9171. }
  9172. if (isinstance) {
  9173. expr_ty elt;
  9174. asdl_comprehension_seq* generators;
  9175. if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
  9176. return 1;
  9177. }
  9178. if (tmp == NULL) {
  9179. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from SetComp");
  9180. return 1;
  9181. }
  9182. else {
  9183. int res;
  9184. if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
  9185. goto failed;
  9186. }
  9187. res = obj2ast_expr(state, tmp, &elt, arena);
  9188. _Py_LeaveRecursiveCall();
  9189. if (res != 0) goto failed;
  9190. Py_CLEAR(tmp);
  9191. }
  9192. if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
  9193. return 1;
  9194. }
  9195. if (tmp == NULL) {
  9196. tmp = PyList_New(0);
  9197. if (tmp == NULL) {
  9198. return 1;
  9199. }
  9200. }
  9201. {
  9202. int res;
  9203. Py_ssize_t len;
  9204. Py_ssize_t i;
  9205. if (!PyList_Check(tmp)) {
  9206. PyErr_Format(PyExc_TypeError, "SetComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9207. goto failed;
  9208. }
  9209. len = PyList_GET_SIZE(tmp);
  9210. generators = _Py_asdl_comprehension_seq_new(len, arena);
  9211. if (generators == NULL) goto failed;
  9212. for (i = 0; i < len; i++) {
  9213. comprehension_ty val;
  9214. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9215. if (_Py_EnterRecursiveCall(" while traversing 'SetComp' node")) {
  9216. goto failed;
  9217. }
  9218. res = obj2ast_comprehension(state, tmp2, &val, arena);
  9219. _Py_LeaveRecursiveCall();
  9220. Py_DECREF(tmp2);
  9221. if (res != 0) goto failed;
  9222. if (len != PyList_GET_SIZE(tmp)) {
  9223. PyErr_SetString(PyExc_RuntimeError, "SetComp field \"generators\" changed size during iteration");
  9224. goto failed;
  9225. }
  9226. asdl_seq_SET(generators, i, val);
  9227. }
  9228. Py_CLEAR(tmp);
  9229. }
  9230. *out = _PyAST_SetComp(elt, generators, lineno, col_offset, end_lineno,
  9231. end_col_offset, arena);
  9232. if (*out == NULL) goto failed;
  9233. return 0;
  9234. }
  9235. tp = state->DictComp_type;
  9236. isinstance = PyObject_IsInstance(obj, tp);
  9237. if (isinstance == -1) {
  9238. return 1;
  9239. }
  9240. if (isinstance) {
  9241. expr_ty key;
  9242. expr_ty value;
  9243. asdl_comprehension_seq* generators;
  9244. if (_PyObject_LookupAttr(obj, state->key, &tmp) < 0) {
  9245. return 1;
  9246. }
  9247. if (tmp == NULL) {
  9248. PyErr_SetString(PyExc_TypeError, "required field \"key\" missing from DictComp");
  9249. return 1;
  9250. }
  9251. else {
  9252. int res;
  9253. if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
  9254. goto failed;
  9255. }
  9256. res = obj2ast_expr(state, tmp, &key, arena);
  9257. _Py_LeaveRecursiveCall();
  9258. if (res != 0) goto failed;
  9259. Py_CLEAR(tmp);
  9260. }
  9261. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9262. return 1;
  9263. }
  9264. if (tmp == NULL) {
  9265. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from DictComp");
  9266. return 1;
  9267. }
  9268. else {
  9269. int res;
  9270. if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
  9271. goto failed;
  9272. }
  9273. res = obj2ast_expr(state, tmp, &value, arena);
  9274. _Py_LeaveRecursiveCall();
  9275. if (res != 0) goto failed;
  9276. Py_CLEAR(tmp);
  9277. }
  9278. if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
  9279. return 1;
  9280. }
  9281. if (tmp == NULL) {
  9282. tmp = PyList_New(0);
  9283. if (tmp == NULL) {
  9284. return 1;
  9285. }
  9286. }
  9287. {
  9288. int res;
  9289. Py_ssize_t len;
  9290. Py_ssize_t i;
  9291. if (!PyList_Check(tmp)) {
  9292. PyErr_Format(PyExc_TypeError, "DictComp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9293. goto failed;
  9294. }
  9295. len = PyList_GET_SIZE(tmp);
  9296. generators = _Py_asdl_comprehension_seq_new(len, arena);
  9297. if (generators == NULL) goto failed;
  9298. for (i = 0; i < len; i++) {
  9299. comprehension_ty val;
  9300. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9301. if (_Py_EnterRecursiveCall(" while traversing 'DictComp' node")) {
  9302. goto failed;
  9303. }
  9304. res = obj2ast_comprehension(state, tmp2, &val, arena);
  9305. _Py_LeaveRecursiveCall();
  9306. Py_DECREF(tmp2);
  9307. if (res != 0) goto failed;
  9308. if (len != PyList_GET_SIZE(tmp)) {
  9309. PyErr_SetString(PyExc_RuntimeError, "DictComp field \"generators\" changed size during iteration");
  9310. goto failed;
  9311. }
  9312. asdl_seq_SET(generators, i, val);
  9313. }
  9314. Py_CLEAR(tmp);
  9315. }
  9316. *out = _PyAST_DictComp(key, value, generators, lineno, col_offset,
  9317. end_lineno, end_col_offset, arena);
  9318. if (*out == NULL) goto failed;
  9319. return 0;
  9320. }
  9321. tp = state->GeneratorExp_type;
  9322. isinstance = PyObject_IsInstance(obj, tp);
  9323. if (isinstance == -1) {
  9324. return 1;
  9325. }
  9326. if (isinstance) {
  9327. expr_ty elt;
  9328. asdl_comprehension_seq* generators;
  9329. if (_PyObject_LookupAttr(obj, state->elt, &tmp) < 0) {
  9330. return 1;
  9331. }
  9332. if (tmp == NULL) {
  9333. PyErr_SetString(PyExc_TypeError, "required field \"elt\" missing from GeneratorExp");
  9334. return 1;
  9335. }
  9336. else {
  9337. int res;
  9338. if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
  9339. goto failed;
  9340. }
  9341. res = obj2ast_expr(state, tmp, &elt, arena);
  9342. _Py_LeaveRecursiveCall();
  9343. if (res != 0) goto failed;
  9344. Py_CLEAR(tmp);
  9345. }
  9346. if (_PyObject_LookupAttr(obj, state->generators, &tmp) < 0) {
  9347. return 1;
  9348. }
  9349. if (tmp == NULL) {
  9350. tmp = PyList_New(0);
  9351. if (tmp == NULL) {
  9352. return 1;
  9353. }
  9354. }
  9355. {
  9356. int res;
  9357. Py_ssize_t len;
  9358. Py_ssize_t i;
  9359. if (!PyList_Check(tmp)) {
  9360. PyErr_Format(PyExc_TypeError, "GeneratorExp field \"generators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9361. goto failed;
  9362. }
  9363. len = PyList_GET_SIZE(tmp);
  9364. generators = _Py_asdl_comprehension_seq_new(len, arena);
  9365. if (generators == NULL) goto failed;
  9366. for (i = 0; i < len; i++) {
  9367. comprehension_ty val;
  9368. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9369. if (_Py_EnterRecursiveCall(" while traversing 'GeneratorExp' node")) {
  9370. goto failed;
  9371. }
  9372. res = obj2ast_comprehension(state, tmp2, &val, arena);
  9373. _Py_LeaveRecursiveCall();
  9374. Py_DECREF(tmp2);
  9375. if (res != 0) goto failed;
  9376. if (len != PyList_GET_SIZE(tmp)) {
  9377. PyErr_SetString(PyExc_RuntimeError, "GeneratorExp field \"generators\" changed size during iteration");
  9378. goto failed;
  9379. }
  9380. asdl_seq_SET(generators, i, val);
  9381. }
  9382. Py_CLEAR(tmp);
  9383. }
  9384. *out = _PyAST_GeneratorExp(elt, generators, lineno, col_offset,
  9385. end_lineno, end_col_offset, arena);
  9386. if (*out == NULL) goto failed;
  9387. return 0;
  9388. }
  9389. tp = state->Await_type;
  9390. isinstance = PyObject_IsInstance(obj, tp);
  9391. if (isinstance == -1) {
  9392. return 1;
  9393. }
  9394. if (isinstance) {
  9395. expr_ty value;
  9396. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9397. return 1;
  9398. }
  9399. if (tmp == NULL) {
  9400. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Await");
  9401. return 1;
  9402. }
  9403. else {
  9404. int res;
  9405. if (_Py_EnterRecursiveCall(" while traversing 'Await' node")) {
  9406. goto failed;
  9407. }
  9408. res = obj2ast_expr(state, tmp, &value, arena);
  9409. _Py_LeaveRecursiveCall();
  9410. if (res != 0) goto failed;
  9411. Py_CLEAR(tmp);
  9412. }
  9413. *out = _PyAST_Await(value, lineno, col_offset, end_lineno,
  9414. end_col_offset, arena);
  9415. if (*out == NULL) goto failed;
  9416. return 0;
  9417. }
  9418. tp = state->Yield_type;
  9419. isinstance = PyObject_IsInstance(obj, tp);
  9420. if (isinstance == -1) {
  9421. return 1;
  9422. }
  9423. if (isinstance) {
  9424. expr_ty value;
  9425. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9426. return 1;
  9427. }
  9428. if (tmp == NULL || tmp == Py_None) {
  9429. Py_CLEAR(tmp);
  9430. value = NULL;
  9431. }
  9432. else {
  9433. int res;
  9434. if (_Py_EnterRecursiveCall(" while traversing 'Yield' node")) {
  9435. goto failed;
  9436. }
  9437. res = obj2ast_expr(state, tmp, &value, arena);
  9438. _Py_LeaveRecursiveCall();
  9439. if (res != 0) goto failed;
  9440. Py_CLEAR(tmp);
  9441. }
  9442. *out = _PyAST_Yield(value, lineno, col_offset, end_lineno,
  9443. end_col_offset, arena);
  9444. if (*out == NULL) goto failed;
  9445. return 0;
  9446. }
  9447. tp = state->YieldFrom_type;
  9448. isinstance = PyObject_IsInstance(obj, tp);
  9449. if (isinstance == -1) {
  9450. return 1;
  9451. }
  9452. if (isinstance) {
  9453. expr_ty value;
  9454. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9455. return 1;
  9456. }
  9457. if (tmp == NULL) {
  9458. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from YieldFrom");
  9459. return 1;
  9460. }
  9461. else {
  9462. int res;
  9463. if (_Py_EnterRecursiveCall(" while traversing 'YieldFrom' node")) {
  9464. goto failed;
  9465. }
  9466. res = obj2ast_expr(state, tmp, &value, arena);
  9467. _Py_LeaveRecursiveCall();
  9468. if (res != 0) goto failed;
  9469. Py_CLEAR(tmp);
  9470. }
  9471. *out = _PyAST_YieldFrom(value, lineno, col_offset, end_lineno,
  9472. end_col_offset, arena);
  9473. if (*out == NULL) goto failed;
  9474. return 0;
  9475. }
  9476. tp = state->Compare_type;
  9477. isinstance = PyObject_IsInstance(obj, tp);
  9478. if (isinstance == -1) {
  9479. return 1;
  9480. }
  9481. if (isinstance) {
  9482. expr_ty left;
  9483. asdl_int_seq* ops;
  9484. asdl_expr_seq* comparators;
  9485. if (_PyObject_LookupAttr(obj, state->left, &tmp) < 0) {
  9486. return 1;
  9487. }
  9488. if (tmp == NULL) {
  9489. PyErr_SetString(PyExc_TypeError, "required field \"left\" missing from Compare");
  9490. return 1;
  9491. }
  9492. else {
  9493. int res;
  9494. if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
  9495. goto failed;
  9496. }
  9497. res = obj2ast_expr(state, tmp, &left, arena);
  9498. _Py_LeaveRecursiveCall();
  9499. if (res != 0) goto failed;
  9500. Py_CLEAR(tmp);
  9501. }
  9502. if (_PyObject_LookupAttr(obj, state->ops, &tmp) < 0) {
  9503. return 1;
  9504. }
  9505. if (tmp == NULL) {
  9506. tmp = PyList_New(0);
  9507. if (tmp == NULL) {
  9508. return 1;
  9509. }
  9510. }
  9511. {
  9512. int res;
  9513. Py_ssize_t len;
  9514. Py_ssize_t i;
  9515. if (!PyList_Check(tmp)) {
  9516. PyErr_Format(PyExc_TypeError, "Compare field \"ops\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9517. goto failed;
  9518. }
  9519. len = PyList_GET_SIZE(tmp);
  9520. ops = _Py_asdl_int_seq_new(len, arena);
  9521. if (ops == NULL) goto failed;
  9522. for (i = 0; i < len; i++) {
  9523. cmpop_ty val;
  9524. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9525. if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
  9526. goto failed;
  9527. }
  9528. res = obj2ast_cmpop(state, tmp2, &val, arena);
  9529. _Py_LeaveRecursiveCall();
  9530. Py_DECREF(tmp2);
  9531. if (res != 0) goto failed;
  9532. if (len != PyList_GET_SIZE(tmp)) {
  9533. PyErr_SetString(PyExc_RuntimeError, "Compare field \"ops\" changed size during iteration");
  9534. goto failed;
  9535. }
  9536. asdl_seq_SET(ops, i, val);
  9537. }
  9538. Py_CLEAR(tmp);
  9539. }
  9540. if (_PyObject_LookupAttr(obj, state->comparators, &tmp) < 0) {
  9541. return 1;
  9542. }
  9543. if (tmp == NULL) {
  9544. tmp = PyList_New(0);
  9545. if (tmp == NULL) {
  9546. return 1;
  9547. }
  9548. }
  9549. {
  9550. int res;
  9551. Py_ssize_t len;
  9552. Py_ssize_t i;
  9553. if (!PyList_Check(tmp)) {
  9554. PyErr_Format(PyExc_TypeError, "Compare field \"comparators\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9555. goto failed;
  9556. }
  9557. len = PyList_GET_SIZE(tmp);
  9558. comparators = _Py_asdl_expr_seq_new(len, arena);
  9559. if (comparators == NULL) goto failed;
  9560. for (i = 0; i < len; i++) {
  9561. expr_ty val;
  9562. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9563. if (_Py_EnterRecursiveCall(" while traversing 'Compare' node")) {
  9564. goto failed;
  9565. }
  9566. res = obj2ast_expr(state, tmp2, &val, arena);
  9567. _Py_LeaveRecursiveCall();
  9568. Py_DECREF(tmp2);
  9569. if (res != 0) goto failed;
  9570. if (len != PyList_GET_SIZE(tmp)) {
  9571. PyErr_SetString(PyExc_RuntimeError, "Compare field \"comparators\" changed size during iteration");
  9572. goto failed;
  9573. }
  9574. asdl_seq_SET(comparators, i, val);
  9575. }
  9576. Py_CLEAR(tmp);
  9577. }
  9578. *out = _PyAST_Compare(left, ops, comparators, lineno, col_offset,
  9579. end_lineno, end_col_offset, arena);
  9580. if (*out == NULL) goto failed;
  9581. return 0;
  9582. }
  9583. tp = state->Call_type;
  9584. isinstance = PyObject_IsInstance(obj, tp);
  9585. if (isinstance == -1) {
  9586. return 1;
  9587. }
  9588. if (isinstance) {
  9589. expr_ty func;
  9590. asdl_expr_seq* args;
  9591. asdl_keyword_seq* keywords;
  9592. if (_PyObject_LookupAttr(obj, state->func, &tmp) < 0) {
  9593. return 1;
  9594. }
  9595. if (tmp == NULL) {
  9596. PyErr_SetString(PyExc_TypeError, "required field \"func\" missing from Call");
  9597. return 1;
  9598. }
  9599. else {
  9600. int res;
  9601. if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
  9602. goto failed;
  9603. }
  9604. res = obj2ast_expr(state, tmp, &func, arena);
  9605. _Py_LeaveRecursiveCall();
  9606. if (res != 0) goto failed;
  9607. Py_CLEAR(tmp);
  9608. }
  9609. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  9610. return 1;
  9611. }
  9612. if (tmp == NULL) {
  9613. tmp = PyList_New(0);
  9614. if (tmp == NULL) {
  9615. return 1;
  9616. }
  9617. }
  9618. {
  9619. int res;
  9620. Py_ssize_t len;
  9621. Py_ssize_t i;
  9622. if (!PyList_Check(tmp)) {
  9623. PyErr_Format(PyExc_TypeError, "Call field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9624. goto failed;
  9625. }
  9626. len = PyList_GET_SIZE(tmp);
  9627. args = _Py_asdl_expr_seq_new(len, arena);
  9628. if (args == NULL) goto failed;
  9629. for (i = 0; i < len; i++) {
  9630. expr_ty val;
  9631. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9632. if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
  9633. goto failed;
  9634. }
  9635. res = obj2ast_expr(state, tmp2, &val, arena);
  9636. _Py_LeaveRecursiveCall();
  9637. Py_DECREF(tmp2);
  9638. if (res != 0) goto failed;
  9639. if (len != PyList_GET_SIZE(tmp)) {
  9640. PyErr_SetString(PyExc_RuntimeError, "Call field \"args\" changed size during iteration");
  9641. goto failed;
  9642. }
  9643. asdl_seq_SET(args, i, val);
  9644. }
  9645. Py_CLEAR(tmp);
  9646. }
  9647. if (_PyObject_LookupAttr(obj, state->keywords, &tmp) < 0) {
  9648. return 1;
  9649. }
  9650. if (tmp == NULL) {
  9651. tmp = PyList_New(0);
  9652. if (tmp == NULL) {
  9653. return 1;
  9654. }
  9655. }
  9656. {
  9657. int res;
  9658. Py_ssize_t len;
  9659. Py_ssize_t i;
  9660. if (!PyList_Check(tmp)) {
  9661. PyErr_Format(PyExc_TypeError, "Call field \"keywords\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9662. goto failed;
  9663. }
  9664. len = PyList_GET_SIZE(tmp);
  9665. keywords = _Py_asdl_keyword_seq_new(len, arena);
  9666. if (keywords == NULL) goto failed;
  9667. for (i = 0; i < len; i++) {
  9668. keyword_ty val;
  9669. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9670. if (_Py_EnterRecursiveCall(" while traversing 'Call' node")) {
  9671. goto failed;
  9672. }
  9673. res = obj2ast_keyword(state, tmp2, &val, arena);
  9674. _Py_LeaveRecursiveCall();
  9675. Py_DECREF(tmp2);
  9676. if (res != 0) goto failed;
  9677. if (len != PyList_GET_SIZE(tmp)) {
  9678. PyErr_SetString(PyExc_RuntimeError, "Call field \"keywords\" changed size during iteration");
  9679. goto failed;
  9680. }
  9681. asdl_seq_SET(keywords, i, val);
  9682. }
  9683. Py_CLEAR(tmp);
  9684. }
  9685. *out = _PyAST_Call(func, args, keywords, lineno, col_offset,
  9686. end_lineno, end_col_offset, arena);
  9687. if (*out == NULL) goto failed;
  9688. return 0;
  9689. }
  9690. tp = state->FormattedValue_type;
  9691. isinstance = PyObject_IsInstance(obj, tp);
  9692. if (isinstance == -1) {
  9693. return 1;
  9694. }
  9695. if (isinstance) {
  9696. expr_ty value;
  9697. int conversion;
  9698. expr_ty format_spec;
  9699. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9700. return 1;
  9701. }
  9702. if (tmp == NULL) {
  9703. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from FormattedValue");
  9704. return 1;
  9705. }
  9706. else {
  9707. int res;
  9708. if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
  9709. goto failed;
  9710. }
  9711. res = obj2ast_expr(state, tmp, &value, arena);
  9712. _Py_LeaveRecursiveCall();
  9713. if (res != 0) goto failed;
  9714. Py_CLEAR(tmp);
  9715. }
  9716. if (_PyObject_LookupAttr(obj, state->conversion, &tmp) < 0) {
  9717. return 1;
  9718. }
  9719. if (tmp == NULL) {
  9720. PyErr_SetString(PyExc_TypeError, "required field \"conversion\" missing from FormattedValue");
  9721. return 1;
  9722. }
  9723. else {
  9724. int res;
  9725. if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
  9726. goto failed;
  9727. }
  9728. res = obj2ast_int(state, tmp, &conversion, arena);
  9729. _Py_LeaveRecursiveCall();
  9730. if (res != 0) goto failed;
  9731. Py_CLEAR(tmp);
  9732. }
  9733. if (_PyObject_LookupAttr(obj, state->format_spec, &tmp) < 0) {
  9734. return 1;
  9735. }
  9736. if (tmp == NULL || tmp == Py_None) {
  9737. Py_CLEAR(tmp);
  9738. format_spec = NULL;
  9739. }
  9740. else {
  9741. int res;
  9742. if (_Py_EnterRecursiveCall(" while traversing 'FormattedValue' node")) {
  9743. goto failed;
  9744. }
  9745. res = obj2ast_expr(state, tmp, &format_spec, arena);
  9746. _Py_LeaveRecursiveCall();
  9747. if (res != 0) goto failed;
  9748. Py_CLEAR(tmp);
  9749. }
  9750. *out = _PyAST_FormattedValue(value, conversion, format_spec, lineno,
  9751. col_offset, end_lineno, end_col_offset,
  9752. arena);
  9753. if (*out == NULL) goto failed;
  9754. return 0;
  9755. }
  9756. tp = state->JoinedStr_type;
  9757. isinstance = PyObject_IsInstance(obj, tp);
  9758. if (isinstance == -1) {
  9759. return 1;
  9760. }
  9761. if (isinstance) {
  9762. asdl_expr_seq* values;
  9763. if (_PyObject_LookupAttr(obj, state->values, &tmp) < 0) {
  9764. return 1;
  9765. }
  9766. if (tmp == NULL) {
  9767. tmp = PyList_New(0);
  9768. if (tmp == NULL) {
  9769. return 1;
  9770. }
  9771. }
  9772. {
  9773. int res;
  9774. Py_ssize_t len;
  9775. Py_ssize_t i;
  9776. if (!PyList_Check(tmp)) {
  9777. PyErr_Format(PyExc_TypeError, "JoinedStr field \"values\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  9778. goto failed;
  9779. }
  9780. len = PyList_GET_SIZE(tmp);
  9781. values = _Py_asdl_expr_seq_new(len, arena);
  9782. if (values == NULL) goto failed;
  9783. for (i = 0; i < len; i++) {
  9784. expr_ty val;
  9785. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  9786. if (_Py_EnterRecursiveCall(" while traversing 'JoinedStr' node")) {
  9787. goto failed;
  9788. }
  9789. res = obj2ast_expr(state, tmp2, &val, arena);
  9790. _Py_LeaveRecursiveCall();
  9791. Py_DECREF(tmp2);
  9792. if (res != 0) goto failed;
  9793. if (len != PyList_GET_SIZE(tmp)) {
  9794. PyErr_SetString(PyExc_RuntimeError, "JoinedStr field \"values\" changed size during iteration");
  9795. goto failed;
  9796. }
  9797. asdl_seq_SET(values, i, val);
  9798. }
  9799. Py_CLEAR(tmp);
  9800. }
  9801. *out = _PyAST_JoinedStr(values, lineno, col_offset, end_lineno,
  9802. end_col_offset, arena);
  9803. if (*out == NULL) goto failed;
  9804. return 0;
  9805. }
  9806. tp = state->Constant_type;
  9807. isinstance = PyObject_IsInstance(obj, tp);
  9808. if (isinstance == -1) {
  9809. return 1;
  9810. }
  9811. if (isinstance) {
  9812. constant value;
  9813. string kind;
  9814. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9815. return 1;
  9816. }
  9817. if (tmp == NULL) {
  9818. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Constant");
  9819. return 1;
  9820. }
  9821. else {
  9822. int res;
  9823. if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
  9824. goto failed;
  9825. }
  9826. res = obj2ast_constant(state, tmp, &value, arena);
  9827. _Py_LeaveRecursiveCall();
  9828. if (res != 0) goto failed;
  9829. Py_CLEAR(tmp);
  9830. }
  9831. if (_PyObject_LookupAttr(obj, state->kind, &tmp) < 0) {
  9832. return 1;
  9833. }
  9834. if (tmp == NULL || tmp == Py_None) {
  9835. Py_CLEAR(tmp);
  9836. kind = NULL;
  9837. }
  9838. else {
  9839. int res;
  9840. if (_Py_EnterRecursiveCall(" while traversing 'Constant' node")) {
  9841. goto failed;
  9842. }
  9843. res = obj2ast_string(state, tmp, &kind, arena);
  9844. _Py_LeaveRecursiveCall();
  9845. if (res != 0) goto failed;
  9846. Py_CLEAR(tmp);
  9847. }
  9848. *out = _PyAST_Constant(value, kind, lineno, col_offset, end_lineno,
  9849. end_col_offset, arena);
  9850. if (*out == NULL) goto failed;
  9851. return 0;
  9852. }
  9853. tp = state->Attribute_type;
  9854. isinstance = PyObject_IsInstance(obj, tp);
  9855. if (isinstance == -1) {
  9856. return 1;
  9857. }
  9858. if (isinstance) {
  9859. expr_ty value;
  9860. identifier attr;
  9861. expr_context_ty ctx;
  9862. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9863. return 1;
  9864. }
  9865. if (tmp == NULL) {
  9866. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Attribute");
  9867. return 1;
  9868. }
  9869. else {
  9870. int res;
  9871. if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
  9872. goto failed;
  9873. }
  9874. res = obj2ast_expr(state, tmp, &value, arena);
  9875. _Py_LeaveRecursiveCall();
  9876. if (res != 0) goto failed;
  9877. Py_CLEAR(tmp);
  9878. }
  9879. if (_PyObject_LookupAttr(obj, state->attr, &tmp) < 0) {
  9880. return 1;
  9881. }
  9882. if (tmp == NULL) {
  9883. PyErr_SetString(PyExc_TypeError, "required field \"attr\" missing from Attribute");
  9884. return 1;
  9885. }
  9886. else {
  9887. int res;
  9888. if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
  9889. goto failed;
  9890. }
  9891. res = obj2ast_identifier(state, tmp, &attr, arena);
  9892. _Py_LeaveRecursiveCall();
  9893. if (res != 0) goto failed;
  9894. Py_CLEAR(tmp);
  9895. }
  9896. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  9897. return 1;
  9898. }
  9899. if (tmp == NULL) {
  9900. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Attribute");
  9901. return 1;
  9902. }
  9903. else {
  9904. int res;
  9905. if (_Py_EnterRecursiveCall(" while traversing 'Attribute' node")) {
  9906. goto failed;
  9907. }
  9908. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  9909. _Py_LeaveRecursiveCall();
  9910. if (res != 0) goto failed;
  9911. Py_CLEAR(tmp);
  9912. }
  9913. *out = _PyAST_Attribute(value, attr, ctx, lineno, col_offset,
  9914. end_lineno, end_col_offset, arena);
  9915. if (*out == NULL) goto failed;
  9916. return 0;
  9917. }
  9918. tp = state->Subscript_type;
  9919. isinstance = PyObject_IsInstance(obj, tp);
  9920. if (isinstance == -1) {
  9921. return 1;
  9922. }
  9923. if (isinstance) {
  9924. expr_ty value;
  9925. expr_ty slice;
  9926. expr_context_ty ctx;
  9927. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9928. return 1;
  9929. }
  9930. if (tmp == NULL) {
  9931. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Subscript");
  9932. return 1;
  9933. }
  9934. else {
  9935. int res;
  9936. if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
  9937. goto failed;
  9938. }
  9939. res = obj2ast_expr(state, tmp, &value, arena);
  9940. _Py_LeaveRecursiveCall();
  9941. if (res != 0) goto failed;
  9942. Py_CLEAR(tmp);
  9943. }
  9944. if (_PyObject_LookupAttr(obj, state->slice, &tmp) < 0) {
  9945. return 1;
  9946. }
  9947. if (tmp == NULL) {
  9948. PyErr_SetString(PyExc_TypeError, "required field \"slice\" missing from Subscript");
  9949. return 1;
  9950. }
  9951. else {
  9952. int res;
  9953. if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
  9954. goto failed;
  9955. }
  9956. res = obj2ast_expr(state, tmp, &slice, arena);
  9957. _Py_LeaveRecursiveCall();
  9958. if (res != 0) goto failed;
  9959. Py_CLEAR(tmp);
  9960. }
  9961. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  9962. return 1;
  9963. }
  9964. if (tmp == NULL) {
  9965. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Subscript");
  9966. return 1;
  9967. }
  9968. else {
  9969. int res;
  9970. if (_Py_EnterRecursiveCall(" while traversing 'Subscript' node")) {
  9971. goto failed;
  9972. }
  9973. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  9974. _Py_LeaveRecursiveCall();
  9975. if (res != 0) goto failed;
  9976. Py_CLEAR(tmp);
  9977. }
  9978. *out = _PyAST_Subscript(value, slice, ctx, lineno, col_offset,
  9979. end_lineno, end_col_offset, arena);
  9980. if (*out == NULL) goto failed;
  9981. return 0;
  9982. }
  9983. tp = state->Starred_type;
  9984. isinstance = PyObject_IsInstance(obj, tp);
  9985. if (isinstance == -1) {
  9986. return 1;
  9987. }
  9988. if (isinstance) {
  9989. expr_ty value;
  9990. expr_context_ty ctx;
  9991. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  9992. return 1;
  9993. }
  9994. if (tmp == NULL) {
  9995. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from Starred");
  9996. return 1;
  9997. }
  9998. else {
  9999. int res;
  10000. if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
  10001. goto failed;
  10002. }
  10003. res = obj2ast_expr(state, tmp, &value, arena);
  10004. _Py_LeaveRecursiveCall();
  10005. if (res != 0) goto failed;
  10006. Py_CLEAR(tmp);
  10007. }
  10008. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  10009. return 1;
  10010. }
  10011. if (tmp == NULL) {
  10012. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Starred");
  10013. return 1;
  10014. }
  10015. else {
  10016. int res;
  10017. if (_Py_EnterRecursiveCall(" while traversing 'Starred' node")) {
  10018. goto failed;
  10019. }
  10020. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  10021. _Py_LeaveRecursiveCall();
  10022. if (res != 0) goto failed;
  10023. Py_CLEAR(tmp);
  10024. }
  10025. *out = _PyAST_Starred(value, ctx, lineno, col_offset, end_lineno,
  10026. end_col_offset, arena);
  10027. if (*out == NULL) goto failed;
  10028. return 0;
  10029. }
  10030. tp = state->Name_type;
  10031. isinstance = PyObject_IsInstance(obj, tp);
  10032. if (isinstance == -1) {
  10033. return 1;
  10034. }
  10035. if (isinstance) {
  10036. identifier id;
  10037. expr_context_ty ctx;
  10038. if (_PyObject_LookupAttr(obj, state->id, &tmp) < 0) {
  10039. return 1;
  10040. }
  10041. if (tmp == NULL) {
  10042. PyErr_SetString(PyExc_TypeError, "required field \"id\" missing from Name");
  10043. return 1;
  10044. }
  10045. else {
  10046. int res;
  10047. if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
  10048. goto failed;
  10049. }
  10050. res = obj2ast_identifier(state, tmp, &id, arena);
  10051. _Py_LeaveRecursiveCall();
  10052. if (res != 0) goto failed;
  10053. Py_CLEAR(tmp);
  10054. }
  10055. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  10056. return 1;
  10057. }
  10058. if (tmp == NULL) {
  10059. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Name");
  10060. return 1;
  10061. }
  10062. else {
  10063. int res;
  10064. if (_Py_EnterRecursiveCall(" while traversing 'Name' node")) {
  10065. goto failed;
  10066. }
  10067. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  10068. _Py_LeaveRecursiveCall();
  10069. if (res != 0) goto failed;
  10070. Py_CLEAR(tmp);
  10071. }
  10072. *out = _PyAST_Name(id, ctx, lineno, col_offset, end_lineno,
  10073. end_col_offset, arena);
  10074. if (*out == NULL) goto failed;
  10075. return 0;
  10076. }
  10077. tp = state->List_type;
  10078. isinstance = PyObject_IsInstance(obj, tp);
  10079. if (isinstance == -1) {
  10080. return 1;
  10081. }
  10082. if (isinstance) {
  10083. asdl_expr_seq* elts;
  10084. expr_context_ty ctx;
  10085. if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
  10086. return 1;
  10087. }
  10088. if (tmp == NULL) {
  10089. tmp = PyList_New(0);
  10090. if (tmp == NULL) {
  10091. return 1;
  10092. }
  10093. }
  10094. {
  10095. int res;
  10096. Py_ssize_t len;
  10097. Py_ssize_t i;
  10098. if (!PyList_Check(tmp)) {
  10099. PyErr_Format(PyExc_TypeError, "List field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10100. goto failed;
  10101. }
  10102. len = PyList_GET_SIZE(tmp);
  10103. elts = _Py_asdl_expr_seq_new(len, arena);
  10104. if (elts == NULL) goto failed;
  10105. for (i = 0; i < len; i++) {
  10106. expr_ty val;
  10107. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10108. if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
  10109. goto failed;
  10110. }
  10111. res = obj2ast_expr(state, tmp2, &val, arena);
  10112. _Py_LeaveRecursiveCall();
  10113. Py_DECREF(tmp2);
  10114. if (res != 0) goto failed;
  10115. if (len != PyList_GET_SIZE(tmp)) {
  10116. PyErr_SetString(PyExc_RuntimeError, "List field \"elts\" changed size during iteration");
  10117. goto failed;
  10118. }
  10119. asdl_seq_SET(elts, i, val);
  10120. }
  10121. Py_CLEAR(tmp);
  10122. }
  10123. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  10124. return 1;
  10125. }
  10126. if (tmp == NULL) {
  10127. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from List");
  10128. return 1;
  10129. }
  10130. else {
  10131. int res;
  10132. if (_Py_EnterRecursiveCall(" while traversing 'List' node")) {
  10133. goto failed;
  10134. }
  10135. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  10136. _Py_LeaveRecursiveCall();
  10137. if (res != 0) goto failed;
  10138. Py_CLEAR(tmp);
  10139. }
  10140. *out = _PyAST_List(elts, ctx, lineno, col_offset, end_lineno,
  10141. end_col_offset, arena);
  10142. if (*out == NULL) goto failed;
  10143. return 0;
  10144. }
  10145. tp = state->Tuple_type;
  10146. isinstance = PyObject_IsInstance(obj, tp);
  10147. if (isinstance == -1) {
  10148. return 1;
  10149. }
  10150. if (isinstance) {
  10151. asdl_expr_seq* elts;
  10152. expr_context_ty ctx;
  10153. if (_PyObject_LookupAttr(obj, state->elts, &tmp) < 0) {
  10154. return 1;
  10155. }
  10156. if (tmp == NULL) {
  10157. tmp = PyList_New(0);
  10158. if (tmp == NULL) {
  10159. return 1;
  10160. }
  10161. }
  10162. {
  10163. int res;
  10164. Py_ssize_t len;
  10165. Py_ssize_t i;
  10166. if (!PyList_Check(tmp)) {
  10167. PyErr_Format(PyExc_TypeError, "Tuple field \"elts\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10168. goto failed;
  10169. }
  10170. len = PyList_GET_SIZE(tmp);
  10171. elts = _Py_asdl_expr_seq_new(len, arena);
  10172. if (elts == NULL) goto failed;
  10173. for (i = 0; i < len; i++) {
  10174. expr_ty val;
  10175. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10176. if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
  10177. goto failed;
  10178. }
  10179. res = obj2ast_expr(state, tmp2, &val, arena);
  10180. _Py_LeaveRecursiveCall();
  10181. Py_DECREF(tmp2);
  10182. if (res != 0) goto failed;
  10183. if (len != PyList_GET_SIZE(tmp)) {
  10184. PyErr_SetString(PyExc_RuntimeError, "Tuple field \"elts\" changed size during iteration");
  10185. goto failed;
  10186. }
  10187. asdl_seq_SET(elts, i, val);
  10188. }
  10189. Py_CLEAR(tmp);
  10190. }
  10191. if (_PyObject_LookupAttr(obj, state->ctx, &tmp) < 0) {
  10192. return 1;
  10193. }
  10194. if (tmp == NULL) {
  10195. PyErr_SetString(PyExc_TypeError, "required field \"ctx\" missing from Tuple");
  10196. return 1;
  10197. }
  10198. else {
  10199. int res;
  10200. if (_Py_EnterRecursiveCall(" while traversing 'Tuple' node")) {
  10201. goto failed;
  10202. }
  10203. res = obj2ast_expr_context(state, tmp, &ctx, arena);
  10204. _Py_LeaveRecursiveCall();
  10205. if (res != 0) goto failed;
  10206. Py_CLEAR(tmp);
  10207. }
  10208. *out = _PyAST_Tuple(elts, ctx, lineno, col_offset, end_lineno,
  10209. end_col_offset, arena);
  10210. if (*out == NULL) goto failed;
  10211. return 0;
  10212. }
  10213. tp = state->Slice_type;
  10214. isinstance = PyObject_IsInstance(obj, tp);
  10215. if (isinstance == -1) {
  10216. return 1;
  10217. }
  10218. if (isinstance) {
  10219. expr_ty lower;
  10220. expr_ty upper;
  10221. expr_ty step;
  10222. if (_PyObject_LookupAttr(obj, state->lower, &tmp) < 0) {
  10223. return 1;
  10224. }
  10225. if (tmp == NULL || tmp == Py_None) {
  10226. Py_CLEAR(tmp);
  10227. lower = NULL;
  10228. }
  10229. else {
  10230. int res;
  10231. if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
  10232. goto failed;
  10233. }
  10234. res = obj2ast_expr(state, tmp, &lower, arena);
  10235. _Py_LeaveRecursiveCall();
  10236. if (res != 0) goto failed;
  10237. Py_CLEAR(tmp);
  10238. }
  10239. if (_PyObject_LookupAttr(obj, state->upper, &tmp) < 0) {
  10240. return 1;
  10241. }
  10242. if (tmp == NULL || tmp == Py_None) {
  10243. Py_CLEAR(tmp);
  10244. upper = NULL;
  10245. }
  10246. else {
  10247. int res;
  10248. if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
  10249. goto failed;
  10250. }
  10251. res = obj2ast_expr(state, tmp, &upper, arena);
  10252. _Py_LeaveRecursiveCall();
  10253. if (res != 0) goto failed;
  10254. Py_CLEAR(tmp);
  10255. }
  10256. if (_PyObject_LookupAttr(obj, state->step, &tmp) < 0) {
  10257. return 1;
  10258. }
  10259. if (tmp == NULL || tmp == Py_None) {
  10260. Py_CLEAR(tmp);
  10261. step = NULL;
  10262. }
  10263. else {
  10264. int res;
  10265. if (_Py_EnterRecursiveCall(" while traversing 'Slice' node")) {
  10266. goto failed;
  10267. }
  10268. res = obj2ast_expr(state, tmp, &step, arena);
  10269. _Py_LeaveRecursiveCall();
  10270. if (res != 0) goto failed;
  10271. Py_CLEAR(tmp);
  10272. }
  10273. *out = _PyAST_Slice(lower, upper, step, lineno, col_offset, end_lineno,
  10274. end_col_offset, arena);
  10275. if (*out == NULL) goto failed;
  10276. return 0;
  10277. }
  10278. PyErr_Format(PyExc_TypeError, "expected some sort of expr, but got %R", obj);
  10279. failed:
  10280. Py_XDECREF(tmp);
  10281. return 1;
  10282. }
  10283. int
  10284. obj2ast_expr_context(struct ast_state *state, PyObject* obj, expr_context_ty*
  10285. out, PyArena* arena)
  10286. {
  10287. int isinstance;
  10288. isinstance = PyObject_IsInstance(obj, state->Load_type);
  10289. if (isinstance == -1) {
  10290. return 1;
  10291. }
  10292. if (isinstance) {
  10293. *out = Load;
  10294. return 0;
  10295. }
  10296. isinstance = PyObject_IsInstance(obj, state->Store_type);
  10297. if (isinstance == -1) {
  10298. return 1;
  10299. }
  10300. if (isinstance) {
  10301. *out = Store;
  10302. return 0;
  10303. }
  10304. isinstance = PyObject_IsInstance(obj, state->Del_type);
  10305. if (isinstance == -1) {
  10306. return 1;
  10307. }
  10308. if (isinstance) {
  10309. *out = Del;
  10310. return 0;
  10311. }
  10312. PyErr_Format(PyExc_TypeError, "expected some sort of expr_context, but got %R", obj);
  10313. return 1;
  10314. }
  10315. int
  10316. obj2ast_boolop(struct ast_state *state, PyObject* obj, boolop_ty* out, PyArena*
  10317. arena)
  10318. {
  10319. int isinstance;
  10320. isinstance = PyObject_IsInstance(obj, state->And_type);
  10321. if (isinstance == -1) {
  10322. return 1;
  10323. }
  10324. if (isinstance) {
  10325. *out = And;
  10326. return 0;
  10327. }
  10328. isinstance = PyObject_IsInstance(obj, state->Or_type);
  10329. if (isinstance == -1) {
  10330. return 1;
  10331. }
  10332. if (isinstance) {
  10333. *out = Or;
  10334. return 0;
  10335. }
  10336. PyErr_Format(PyExc_TypeError, "expected some sort of boolop, but got %R", obj);
  10337. return 1;
  10338. }
  10339. int
  10340. obj2ast_operator(struct ast_state *state, PyObject* obj, operator_ty* out,
  10341. PyArena* arena)
  10342. {
  10343. int isinstance;
  10344. isinstance = PyObject_IsInstance(obj, state->Add_type);
  10345. if (isinstance == -1) {
  10346. return 1;
  10347. }
  10348. if (isinstance) {
  10349. *out = Add;
  10350. return 0;
  10351. }
  10352. isinstance = PyObject_IsInstance(obj, state->Sub_type);
  10353. if (isinstance == -1) {
  10354. return 1;
  10355. }
  10356. if (isinstance) {
  10357. *out = Sub;
  10358. return 0;
  10359. }
  10360. isinstance = PyObject_IsInstance(obj, state->Mult_type);
  10361. if (isinstance == -1) {
  10362. return 1;
  10363. }
  10364. if (isinstance) {
  10365. *out = Mult;
  10366. return 0;
  10367. }
  10368. isinstance = PyObject_IsInstance(obj, state->MatMult_type);
  10369. if (isinstance == -1) {
  10370. return 1;
  10371. }
  10372. if (isinstance) {
  10373. *out = MatMult;
  10374. return 0;
  10375. }
  10376. isinstance = PyObject_IsInstance(obj, state->Div_type);
  10377. if (isinstance == -1) {
  10378. return 1;
  10379. }
  10380. if (isinstance) {
  10381. *out = Div;
  10382. return 0;
  10383. }
  10384. isinstance = PyObject_IsInstance(obj, state->Mod_type);
  10385. if (isinstance == -1) {
  10386. return 1;
  10387. }
  10388. if (isinstance) {
  10389. *out = Mod;
  10390. return 0;
  10391. }
  10392. isinstance = PyObject_IsInstance(obj, state->Pow_type);
  10393. if (isinstance == -1) {
  10394. return 1;
  10395. }
  10396. if (isinstance) {
  10397. *out = Pow;
  10398. return 0;
  10399. }
  10400. isinstance = PyObject_IsInstance(obj, state->LShift_type);
  10401. if (isinstance == -1) {
  10402. return 1;
  10403. }
  10404. if (isinstance) {
  10405. *out = LShift;
  10406. return 0;
  10407. }
  10408. isinstance = PyObject_IsInstance(obj, state->RShift_type);
  10409. if (isinstance == -1) {
  10410. return 1;
  10411. }
  10412. if (isinstance) {
  10413. *out = RShift;
  10414. return 0;
  10415. }
  10416. isinstance = PyObject_IsInstance(obj, state->BitOr_type);
  10417. if (isinstance == -1) {
  10418. return 1;
  10419. }
  10420. if (isinstance) {
  10421. *out = BitOr;
  10422. return 0;
  10423. }
  10424. isinstance = PyObject_IsInstance(obj, state->BitXor_type);
  10425. if (isinstance == -1) {
  10426. return 1;
  10427. }
  10428. if (isinstance) {
  10429. *out = BitXor;
  10430. return 0;
  10431. }
  10432. isinstance = PyObject_IsInstance(obj, state->BitAnd_type);
  10433. if (isinstance == -1) {
  10434. return 1;
  10435. }
  10436. if (isinstance) {
  10437. *out = BitAnd;
  10438. return 0;
  10439. }
  10440. isinstance = PyObject_IsInstance(obj, state->FloorDiv_type);
  10441. if (isinstance == -1) {
  10442. return 1;
  10443. }
  10444. if (isinstance) {
  10445. *out = FloorDiv;
  10446. return 0;
  10447. }
  10448. PyErr_Format(PyExc_TypeError, "expected some sort of operator, but got %R", obj);
  10449. return 1;
  10450. }
  10451. int
  10452. obj2ast_unaryop(struct ast_state *state, PyObject* obj, unaryop_ty* out,
  10453. PyArena* arena)
  10454. {
  10455. int isinstance;
  10456. isinstance = PyObject_IsInstance(obj, state->Invert_type);
  10457. if (isinstance == -1) {
  10458. return 1;
  10459. }
  10460. if (isinstance) {
  10461. *out = Invert;
  10462. return 0;
  10463. }
  10464. isinstance = PyObject_IsInstance(obj, state->Not_type);
  10465. if (isinstance == -1) {
  10466. return 1;
  10467. }
  10468. if (isinstance) {
  10469. *out = Not;
  10470. return 0;
  10471. }
  10472. isinstance = PyObject_IsInstance(obj, state->UAdd_type);
  10473. if (isinstance == -1) {
  10474. return 1;
  10475. }
  10476. if (isinstance) {
  10477. *out = UAdd;
  10478. return 0;
  10479. }
  10480. isinstance = PyObject_IsInstance(obj, state->USub_type);
  10481. if (isinstance == -1) {
  10482. return 1;
  10483. }
  10484. if (isinstance) {
  10485. *out = USub;
  10486. return 0;
  10487. }
  10488. PyErr_Format(PyExc_TypeError, "expected some sort of unaryop, but got %R", obj);
  10489. return 1;
  10490. }
  10491. int
  10492. obj2ast_cmpop(struct ast_state *state, PyObject* obj, cmpop_ty* out, PyArena*
  10493. arena)
  10494. {
  10495. int isinstance;
  10496. isinstance = PyObject_IsInstance(obj, state->Eq_type);
  10497. if (isinstance == -1) {
  10498. return 1;
  10499. }
  10500. if (isinstance) {
  10501. *out = Eq;
  10502. return 0;
  10503. }
  10504. isinstance = PyObject_IsInstance(obj, state->NotEq_type);
  10505. if (isinstance == -1) {
  10506. return 1;
  10507. }
  10508. if (isinstance) {
  10509. *out = NotEq;
  10510. return 0;
  10511. }
  10512. isinstance = PyObject_IsInstance(obj, state->Lt_type);
  10513. if (isinstance == -1) {
  10514. return 1;
  10515. }
  10516. if (isinstance) {
  10517. *out = Lt;
  10518. return 0;
  10519. }
  10520. isinstance = PyObject_IsInstance(obj, state->LtE_type);
  10521. if (isinstance == -1) {
  10522. return 1;
  10523. }
  10524. if (isinstance) {
  10525. *out = LtE;
  10526. return 0;
  10527. }
  10528. isinstance = PyObject_IsInstance(obj, state->Gt_type);
  10529. if (isinstance == -1) {
  10530. return 1;
  10531. }
  10532. if (isinstance) {
  10533. *out = Gt;
  10534. return 0;
  10535. }
  10536. isinstance = PyObject_IsInstance(obj, state->GtE_type);
  10537. if (isinstance == -1) {
  10538. return 1;
  10539. }
  10540. if (isinstance) {
  10541. *out = GtE;
  10542. return 0;
  10543. }
  10544. isinstance = PyObject_IsInstance(obj, state->Is_type);
  10545. if (isinstance == -1) {
  10546. return 1;
  10547. }
  10548. if (isinstance) {
  10549. *out = Is;
  10550. return 0;
  10551. }
  10552. isinstance = PyObject_IsInstance(obj, state->IsNot_type);
  10553. if (isinstance == -1) {
  10554. return 1;
  10555. }
  10556. if (isinstance) {
  10557. *out = IsNot;
  10558. return 0;
  10559. }
  10560. isinstance = PyObject_IsInstance(obj, state->In_type);
  10561. if (isinstance == -1) {
  10562. return 1;
  10563. }
  10564. if (isinstance) {
  10565. *out = In;
  10566. return 0;
  10567. }
  10568. isinstance = PyObject_IsInstance(obj, state->NotIn_type);
  10569. if (isinstance == -1) {
  10570. return 1;
  10571. }
  10572. if (isinstance) {
  10573. *out = NotIn;
  10574. return 0;
  10575. }
  10576. PyErr_Format(PyExc_TypeError, "expected some sort of cmpop, but got %R", obj);
  10577. return 1;
  10578. }
  10579. int
  10580. obj2ast_comprehension(struct ast_state *state, PyObject* obj, comprehension_ty*
  10581. out, PyArena* arena)
  10582. {
  10583. PyObject* tmp = NULL;
  10584. expr_ty target;
  10585. expr_ty iter;
  10586. asdl_expr_seq* ifs;
  10587. int is_async;
  10588. if (_PyObject_LookupAttr(obj, state->target, &tmp) < 0) {
  10589. return 1;
  10590. }
  10591. if (tmp == NULL) {
  10592. PyErr_SetString(PyExc_TypeError, "required field \"target\" missing from comprehension");
  10593. return 1;
  10594. }
  10595. else {
  10596. int res;
  10597. if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
  10598. goto failed;
  10599. }
  10600. res = obj2ast_expr(state, tmp, &target, arena);
  10601. _Py_LeaveRecursiveCall();
  10602. if (res != 0) goto failed;
  10603. Py_CLEAR(tmp);
  10604. }
  10605. if (_PyObject_LookupAttr(obj, state->iter, &tmp) < 0) {
  10606. return 1;
  10607. }
  10608. if (tmp == NULL) {
  10609. PyErr_SetString(PyExc_TypeError, "required field \"iter\" missing from comprehension");
  10610. return 1;
  10611. }
  10612. else {
  10613. int res;
  10614. if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
  10615. goto failed;
  10616. }
  10617. res = obj2ast_expr(state, tmp, &iter, arena);
  10618. _Py_LeaveRecursiveCall();
  10619. if (res != 0) goto failed;
  10620. Py_CLEAR(tmp);
  10621. }
  10622. if (_PyObject_LookupAttr(obj, state->ifs, &tmp) < 0) {
  10623. return 1;
  10624. }
  10625. if (tmp == NULL) {
  10626. tmp = PyList_New(0);
  10627. if (tmp == NULL) {
  10628. return 1;
  10629. }
  10630. }
  10631. {
  10632. int res;
  10633. Py_ssize_t len;
  10634. Py_ssize_t i;
  10635. if (!PyList_Check(tmp)) {
  10636. PyErr_Format(PyExc_TypeError, "comprehension field \"ifs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10637. goto failed;
  10638. }
  10639. len = PyList_GET_SIZE(tmp);
  10640. ifs = _Py_asdl_expr_seq_new(len, arena);
  10641. if (ifs == NULL) goto failed;
  10642. for (i = 0; i < len; i++) {
  10643. expr_ty val;
  10644. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10645. if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
  10646. goto failed;
  10647. }
  10648. res = obj2ast_expr(state, tmp2, &val, arena);
  10649. _Py_LeaveRecursiveCall();
  10650. Py_DECREF(tmp2);
  10651. if (res != 0) goto failed;
  10652. if (len != PyList_GET_SIZE(tmp)) {
  10653. PyErr_SetString(PyExc_RuntimeError, "comprehension field \"ifs\" changed size during iteration");
  10654. goto failed;
  10655. }
  10656. asdl_seq_SET(ifs, i, val);
  10657. }
  10658. Py_CLEAR(tmp);
  10659. }
  10660. if (_PyObject_LookupAttr(obj, state->is_async, &tmp) < 0) {
  10661. return 1;
  10662. }
  10663. if (tmp == NULL) {
  10664. PyErr_SetString(PyExc_TypeError, "required field \"is_async\" missing from comprehension");
  10665. return 1;
  10666. }
  10667. else {
  10668. int res;
  10669. if (_Py_EnterRecursiveCall(" while traversing 'comprehension' node")) {
  10670. goto failed;
  10671. }
  10672. res = obj2ast_int(state, tmp, &is_async, arena);
  10673. _Py_LeaveRecursiveCall();
  10674. if (res != 0) goto failed;
  10675. Py_CLEAR(tmp);
  10676. }
  10677. *out = _PyAST_comprehension(target, iter, ifs, is_async, arena);
  10678. if (*out == NULL) goto failed;
  10679. return 0;
  10680. failed:
  10681. Py_XDECREF(tmp);
  10682. return 1;
  10683. }
  10684. int
  10685. obj2ast_excepthandler(struct ast_state *state, PyObject* obj, excepthandler_ty*
  10686. out, PyArena* arena)
  10687. {
  10688. int isinstance;
  10689. PyObject *tmp = NULL;
  10690. PyObject *tp;
  10691. int lineno;
  10692. int col_offset;
  10693. int end_lineno;
  10694. int end_col_offset;
  10695. if (obj == Py_None) {
  10696. *out = NULL;
  10697. return 0;
  10698. }
  10699. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  10700. return 1;
  10701. }
  10702. if (tmp == NULL) {
  10703. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from excepthandler");
  10704. return 1;
  10705. }
  10706. else {
  10707. int res;
  10708. if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
  10709. goto failed;
  10710. }
  10711. res = obj2ast_int(state, tmp, &lineno, arena);
  10712. _Py_LeaveRecursiveCall();
  10713. if (res != 0) goto failed;
  10714. Py_CLEAR(tmp);
  10715. }
  10716. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  10717. return 1;
  10718. }
  10719. if (tmp == NULL) {
  10720. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from excepthandler");
  10721. return 1;
  10722. }
  10723. else {
  10724. int res;
  10725. if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
  10726. goto failed;
  10727. }
  10728. res = obj2ast_int(state, tmp, &col_offset, arena);
  10729. _Py_LeaveRecursiveCall();
  10730. if (res != 0) goto failed;
  10731. Py_CLEAR(tmp);
  10732. }
  10733. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  10734. return 1;
  10735. }
  10736. if (tmp == NULL || tmp == Py_None) {
  10737. Py_CLEAR(tmp);
  10738. end_lineno = lineno;
  10739. }
  10740. else {
  10741. int res;
  10742. if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
  10743. goto failed;
  10744. }
  10745. res = obj2ast_int(state, tmp, &end_lineno, arena);
  10746. _Py_LeaveRecursiveCall();
  10747. if (res != 0) goto failed;
  10748. Py_CLEAR(tmp);
  10749. }
  10750. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  10751. return 1;
  10752. }
  10753. if (tmp == NULL || tmp == Py_None) {
  10754. Py_CLEAR(tmp);
  10755. end_col_offset = col_offset;
  10756. }
  10757. else {
  10758. int res;
  10759. if (_Py_EnterRecursiveCall(" while traversing 'excepthandler' node")) {
  10760. goto failed;
  10761. }
  10762. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  10763. _Py_LeaveRecursiveCall();
  10764. if (res != 0) goto failed;
  10765. Py_CLEAR(tmp);
  10766. }
  10767. tp = state->ExceptHandler_type;
  10768. isinstance = PyObject_IsInstance(obj, tp);
  10769. if (isinstance == -1) {
  10770. return 1;
  10771. }
  10772. if (isinstance) {
  10773. expr_ty type;
  10774. identifier name;
  10775. asdl_stmt_seq* body;
  10776. if (_PyObject_LookupAttr(obj, state->type, &tmp) < 0) {
  10777. return 1;
  10778. }
  10779. if (tmp == NULL || tmp == Py_None) {
  10780. Py_CLEAR(tmp);
  10781. type = NULL;
  10782. }
  10783. else {
  10784. int res;
  10785. if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
  10786. goto failed;
  10787. }
  10788. res = obj2ast_expr(state, tmp, &type, arena);
  10789. _Py_LeaveRecursiveCall();
  10790. if (res != 0) goto failed;
  10791. Py_CLEAR(tmp);
  10792. }
  10793. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  10794. return 1;
  10795. }
  10796. if (tmp == NULL || tmp == Py_None) {
  10797. Py_CLEAR(tmp);
  10798. name = NULL;
  10799. }
  10800. else {
  10801. int res;
  10802. if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
  10803. goto failed;
  10804. }
  10805. res = obj2ast_identifier(state, tmp, &name, arena);
  10806. _Py_LeaveRecursiveCall();
  10807. if (res != 0) goto failed;
  10808. Py_CLEAR(tmp);
  10809. }
  10810. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  10811. return 1;
  10812. }
  10813. if (tmp == NULL) {
  10814. tmp = PyList_New(0);
  10815. if (tmp == NULL) {
  10816. return 1;
  10817. }
  10818. }
  10819. {
  10820. int res;
  10821. Py_ssize_t len;
  10822. Py_ssize_t i;
  10823. if (!PyList_Check(tmp)) {
  10824. PyErr_Format(PyExc_TypeError, "ExceptHandler field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10825. goto failed;
  10826. }
  10827. len = PyList_GET_SIZE(tmp);
  10828. body = _Py_asdl_stmt_seq_new(len, arena);
  10829. if (body == NULL) goto failed;
  10830. for (i = 0; i < len; i++) {
  10831. stmt_ty val;
  10832. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10833. if (_Py_EnterRecursiveCall(" while traversing 'ExceptHandler' node")) {
  10834. goto failed;
  10835. }
  10836. res = obj2ast_stmt(state, tmp2, &val, arena);
  10837. _Py_LeaveRecursiveCall();
  10838. Py_DECREF(tmp2);
  10839. if (res != 0) goto failed;
  10840. if (len != PyList_GET_SIZE(tmp)) {
  10841. PyErr_SetString(PyExc_RuntimeError, "ExceptHandler field \"body\" changed size during iteration");
  10842. goto failed;
  10843. }
  10844. asdl_seq_SET(body, i, val);
  10845. }
  10846. Py_CLEAR(tmp);
  10847. }
  10848. *out = _PyAST_ExceptHandler(type, name, body, lineno, col_offset,
  10849. end_lineno, end_col_offset, arena);
  10850. if (*out == NULL) goto failed;
  10851. return 0;
  10852. }
  10853. PyErr_Format(PyExc_TypeError, "expected some sort of excepthandler, but got %R", obj);
  10854. failed:
  10855. Py_XDECREF(tmp);
  10856. return 1;
  10857. }
  10858. int
  10859. obj2ast_arguments(struct ast_state *state, PyObject* obj, arguments_ty* out,
  10860. PyArena* arena)
  10861. {
  10862. PyObject* tmp = NULL;
  10863. asdl_arg_seq* posonlyargs;
  10864. asdl_arg_seq* args;
  10865. arg_ty vararg;
  10866. asdl_arg_seq* kwonlyargs;
  10867. asdl_expr_seq* kw_defaults;
  10868. arg_ty kwarg;
  10869. asdl_expr_seq* defaults;
  10870. if (_PyObject_LookupAttr(obj, state->posonlyargs, &tmp) < 0) {
  10871. return 1;
  10872. }
  10873. if (tmp == NULL) {
  10874. tmp = PyList_New(0);
  10875. if (tmp == NULL) {
  10876. return 1;
  10877. }
  10878. }
  10879. {
  10880. int res;
  10881. Py_ssize_t len;
  10882. Py_ssize_t i;
  10883. if (!PyList_Check(tmp)) {
  10884. PyErr_Format(PyExc_TypeError, "arguments field \"posonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10885. goto failed;
  10886. }
  10887. len = PyList_GET_SIZE(tmp);
  10888. posonlyargs = _Py_asdl_arg_seq_new(len, arena);
  10889. if (posonlyargs == NULL) goto failed;
  10890. for (i = 0; i < len; i++) {
  10891. arg_ty val;
  10892. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10893. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  10894. goto failed;
  10895. }
  10896. res = obj2ast_arg(state, tmp2, &val, arena);
  10897. _Py_LeaveRecursiveCall();
  10898. Py_DECREF(tmp2);
  10899. if (res != 0) goto failed;
  10900. if (len != PyList_GET_SIZE(tmp)) {
  10901. PyErr_SetString(PyExc_RuntimeError, "arguments field \"posonlyargs\" changed size during iteration");
  10902. goto failed;
  10903. }
  10904. asdl_seq_SET(posonlyargs, i, val);
  10905. }
  10906. Py_CLEAR(tmp);
  10907. }
  10908. if (_PyObject_LookupAttr(obj, state->args, &tmp) < 0) {
  10909. return 1;
  10910. }
  10911. if (tmp == NULL) {
  10912. tmp = PyList_New(0);
  10913. if (tmp == NULL) {
  10914. return 1;
  10915. }
  10916. }
  10917. {
  10918. int res;
  10919. Py_ssize_t len;
  10920. Py_ssize_t i;
  10921. if (!PyList_Check(tmp)) {
  10922. PyErr_Format(PyExc_TypeError, "arguments field \"args\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10923. goto failed;
  10924. }
  10925. len = PyList_GET_SIZE(tmp);
  10926. args = _Py_asdl_arg_seq_new(len, arena);
  10927. if (args == NULL) goto failed;
  10928. for (i = 0; i < len; i++) {
  10929. arg_ty val;
  10930. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10931. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  10932. goto failed;
  10933. }
  10934. res = obj2ast_arg(state, tmp2, &val, arena);
  10935. _Py_LeaveRecursiveCall();
  10936. Py_DECREF(tmp2);
  10937. if (res != 0) goto failed;
  10938. if (len != PyList_GET_SIZE(tmp)) {
  10939. PyErr_SetString(PyExc_RuntimeError, "arguments field \"args\" changed size during iteration");
  10940. goto failed;
  10941. }
  10942. asdl_seq_SET(args, i, val);
  10943. }
  10944. Py_CLEAR(tmp);
  10945. }
  10946. if (_PyObject_LookupAttr(obj, state->vararg, &tmp) < 0) {
  10947. return 1;
  10948. }
  10949. if (tmp == NULL || tmp == Py_None) {
  10950. Py_CLEAR(tmp);
  10951. vararg = NULL;
  10952. }
  10953. else {
  10954. int res;
  10955. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  10956. goto failed;
  10957. }
  10958. res = obj2ast_arg(state, tmp, &vararg, arena);
  10959. _Py_LeaveRecursiveCall();
  10960. if (res != 0) goto failed;
  10961. Py_CLEAR(tmp);
  10962. }
  10963. if (_PyObject_LookupAttr(obj, state->kwonlyargs, &tmp) < 0) {
  10964. return 1;
  10965. }
  10966. if (tmp == NULL) {
  10967. tmp = PyList_New(0);
  10968. if (tmp == NULL) {
  10969. return 1;
  10970. }
  10971. }
  10972. {
  10973. int res;
  10974. Py_ssize_t len;
  10975. Py_ssize_t i;
  10976. if (!PyList_Check(tmp)) {
  10977. PyErr_Format(PyExc_TypeError, "arguments field \"kwonlyargs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  10978. goto failed;
  10979. }
  10980. len = PyList_GET_SIZE(tmp);
  10981. kwonlyargs = _Py_asdl_arg_seq_new(len, arena);
  10982. if (kwonlyargs == NULL) goto failed;
  10983. for (i = 0; i < len; i++) {
  10984. arg_ty val;
  10985. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  10986. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  10987. goto failed;
  10988. }
  10989. res = obj2ast_arg(state, tmp2, &val, arena);
  10990. _Py_LeaveRecursiveCall();
  10991. Py_DECREF(tmp2);
  10992. if (res != 0) goto failed;
  10993. if (len != PyList_GET_SIZE(tmp)) {
  10994. PyErr_SetString(PyExc_RuntimeError, "arguments field \"kwonlyargs\" changed size during iteration");
  10995. goto failed;
  10996. }
  10997. asdl_seq_SET(kwonlyargs, i, val);
  10998. }
  10999. Py_CLEAR(tmp);
  11000. }
  11001. if (_PyObject_LookupAttr(obj, state->kw_defaults, &tmp) < 0) {
  11002. return 1;
  11003. }
  11004. if (tmp == NULL) {
  11005. tmp = PyList_New(0);
  11006. if (tmp == NULL) {
  11007. return 1;
  11008. }
  11009. }
  11010. {
  11011. int res;
  11012. Py_ssize_t len;
  11013. Py_ssize_t i;
  11014. if (!PyList_Check(tmp)) {
  11015. PyErr_Format(PyExc_TypeError, "arguments field \"kw_defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11016. goto failed;
  11017. }
  11018. len = PyList_GET_SIZE(tmp);
  11019. kw_defaults = _Py_asdl_expr_seq_new(len, arena);
  11020. if (kw_defaults == NULL) goto failed;
  11021. for (i = 0; i < len; i++) {
  11022. expr_ty val;
  11023. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11024. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  11025. goto failed;
  11026. }
  11027. res = obj2ast_expr(state, tmp2, &val, arena);
  11028. _Py_LeaveRecursiveCall();
  11029. Py_DECREF(tmp2);
  11030. if (res != 0) goto failed;
  11031. if (len != PyList_GET_SIZE(tmp)) {
  11032. PyErr_SetString(PyExc_RuntimeError, "arguments field \"kw_defaults\" changed size during iteration");
  11033. goto failed;
  11034. }
  11035. asdl_seq_SET(kw_defaults, i, val);
  11036. }
  11037. Py_CLEAR(tmp);
  11038. }
  11039. if (_PyObject_LookupAttr(obj, state->kwarg, &tmp) < 0) {
  11040. return 1;
  11041. }
  11042. if (tmp == NULL || tmp == Py_None) {
  11043. Py_CLEAR(tmp);
  11044. kwarg = NULL;
  11045. }
  11046. else {
  11047. int res;
  11048. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  11049. goto failed;
  11050. }
  11051. res = obj2ast_arg(state, tmp, &kwarg, arena);
  11052. _Py_LeaveRecursiveCall();
  11053. if (res != 0) goto failed;
  11054. Py_CLEAR(tmp);
  11055. }
  11056. if (_PyObject_LookupAttr(obj, state->defaults, &tmp) < 0) {
  11057. return 1;
  11058. }
  11059. if (tmp == NULL) {
  11060. tmp = PyList_New(0);
  11061. if (tmp == NULL) {
  11062. return 1;
  11063. }
  11064. }
  11065. {
  11066. int res;
  11067. Py_ssize_t len;
  11068. Py_ssize_t i;
  11069. if (!PyList_Check(tmp)) {
  11070. PyErr_Format(PyExc_TypeError, "arguments field \"defaults\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11071. goto failed;
  11072. }
  11073. len = PyList_GET_SIZE(tmp);
  11074. defaults = _Py_asdl_expr_seq_new(len, arena);
  11075. if (defaults == NULL) goto failed;
  11076. for (i = 0; i < len; i++) {
  11077. expr_ty val;
  11078. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11079. if (_Py_EnterRecursiveCall(" while traversing 'arguments' node")) {
  11080. goto failed;
  11081. }
  11082. res = obj2ast_expr(state, tmp2, &val, arena);
  11083. _Py_LeaveRecursiveCall();
  11084. Py_DECREF(tmp2);
  11085. if (res != 0) goto failed;
  11086. if (len != PyList_GET_SIZE(tmp)) {
  11087. PyErr_SetString(PyExc_RuntimeError, "arguments field \"defaults\" changed size during iteration");
  11088. goto failed;
  11089. }
  11090. asdl_seq_SET(defaults, i, val);
  11091. }
  11092. Py_CLEAR(tmp);
  11093. }
  11094. *out = _PyAST_arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults,
  11095. kwarg, defaults, arena);
  11096. if (*out == NULL) goto failed;
  11097. return 0;
  11098. failed:
  11099. Py_XDECREF(tmp);
  11100. return 1;
  11101. }
  11102. int
  11103. obj2ast_arg(struct ast_state *state, PyObject* obj, arg_ty* out, PyArena* arena)
  11104. {
  11105. PyObject* tmp = NULL;
  11106. identifier arg;
  11107. expr_ty annotation;
  11108. string type_comment;
  11109. int lineno;
  11110. int col_offset;
  11111. int end_lineno;
  11112. int end_col_offset;
  11113. if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
  11114. return 1;
  11115. }
  11116. if (tmp == NULL) {
  11117. PyErr_SetString(PyExc_TypeError, "required field \"arg\" missing from arg");
  11118. return 1;
  11119. }
  11120. else {
  11121. int res;
  11122. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11123. goto failed;
  11124. }
  11125. res = obj2ast_identifier(state, tmp, &arg, arena);
  11126. _Py_LeaveRecursiveCall();
  11127. if (res != 0) goto failed;
  11128. Py_CLEAR(tmp);
  11129. }
  11130. if (_PyObject_LookupAttr(obj, state->annotation, &tmp) < 0) {
  11131. return 1;
  11132. }
  11133. if (tmp == NULL || tmp == Py_None) {
  11134. Py_CLEAR(tmp);
  11135. annotation = NULL;
  11136. }
  11137. else {
  11138. int res;
  11139. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11140. goto failed;
  11141. }
  11142. res = obj2ast_expr(state, tmp, &annotation, arena);
  11143. _Py_LeaveRecursiveCall();
  11144. if (res != 0) goto failed;
  11145. Py_CLEAR(tmp);
  11146. }
  11147. if (_PyObject_LookupAttr(obj, state->type_comment, &tmp) < 0) {
  11148. return 1;
  11149. }
  11150. if (tmp == NULL || tmp == Py_None) {
  11151. Py_CLEAR(tmp);
  11152. type_comment = NULL;
  11153. }
  11154. else {
  11155. int res;
  11156. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11157. goto failed;
  11158. }
  11159. res = obj2ast_string(state, tmp, &type_comment, arena);
  11160. _Py_LeaveRecursiveCall();
  11161. if (res != 0) goto failed;
  11162. Py_CLEAR(tmp);
  11163. }
  11164. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  11165. return 1;
  11166. }
  11167. if (tmp == NULL) {
  11168. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from arg");
  11169. return 1;
  11170. }
  11171. else {
  11172. int res;
  11173. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11174. goto failed;
  11175. }
  11176. res = obj2ast_int(state, tmp, &lineno, arena);
  11177. _Py_LeaveRecursiveCall();
  11178. if (res != 0) goto failed;
  11179. Py_CLEAR(tmp);
  11180. }
  11181. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  11182. return 1;
  11183. }
  11184. if (tmp == NULL) {
  11185. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from arg");
  11186. return 1;
  11187. }
  11188. else {
  11189. int res;
  11190. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11191. goto failed;
  11192. }
  11193. res = obj2ast_int(state, tmp, &col_offset, arena);
  11194. _Py_LeaveRecursiveCall();
  11195. if (res != 0) goto failed;
  11196. Py_CLEAR(tmp);
  11197. }
  11198. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  11199. return 1;
  11200. }
  11201. if (tmp == NULL || tmp == Py_None) {
  11202. Py_CLEAR(tmp);
  11203. end_lineno = lineno;
  11204. }
  11205. else {
  11206. int res;
  11207. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11208. goto failed;
  11209. }
  11210. res = obj2ast_int(state, tmp, &end_lineno, arena);
  11211. _Py_LeaveRecursiveCall();
  11212. if (res != 0) goto failed;
  11213. Py_CLEAR(tmp);
  11214. }
  11215. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  11216. return 1;
  11217. }
  11218. if (tmp == NULL || tmp == Py_None) {
  11219. Py_CLEAR(tmp);
  11220. end_col_offset = col_offset;
  11221. }
  11222. else {
  11223. int res;
  11224. if (_Py_EnterRecursiveCall(" while traversing 'arg' node")) {
  11225. goto failed;
  11226. }
  11227. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  11228. _Py_LeaveRecursiveCall();
  11229. if (res != 0) goto failed;
  11230. Py_CLEAR(tmp);
  11231. }
  11232. *out = _PyAST_arg(arg, annotation, type_comment, lineno, col_offset,
  11233. end_lineno, end_col_offset, arena);
  11234. if (*out == NULL) goto failed;
  11235. return 0;
  11236. failed:
  11237. Py_XDECREF(tmp);
  11238. return 1;
  11239. }
  11240. int
  11241. obj2ast_keyword(struct ast_state *state, PyObject* obj, keyword_ty* out,
  11242. PyArena* arena)
  11243. {
  11244. PyObject* tmp = NULL;
  11245. identifier arg;
  11246. expr_ty value;
  11247. int lineno;
  11248. int col_offset;
  11249. int end_lineno;
  11250. int end_col_offset;
  11251. if (_PyObject_LookupAttr(obj, state->arg, &tmp) < 0) {
  11252. return 1;
  11253. }
  11254. if (tmp == NULL || tmp == Py_None) {
  11255. Py_CLEAR(tmp);
  11256. arg = NULL;
  11257. }
  11258. else {
  11259. int res;
  11260. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11261. goto failed;
  11262. }
  11263. res = obj2ast_identifier(state, tmp, &arg, arena);
  11264. _Py_LeaveRecursiveCall();
  11265. if (res != 0) goto failed;
  11266. Py_CLEAR(tmp);
  11267. }
  11268. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  11269. return 1;
  11270. }
  11271. if (tmp == NULL) {
  11272. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from keyword");
  11273. return 1;
  11274. }
  11275. else {
  11276. int res;
  11277. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11278. goto failed;
  11279. }
  11280. res = obj2ast_expr(state, tmp, &value, arena);
  11281. _Py_LeaveRecursiveCall();
  11282. if (res != 0) goto failed;
  11283. Py_CLEAR(tmp);
  11284. }
  11285. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  11286. return 1;
  11287. }
  11288. if (tmp == NULL) {
  11289. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from keyword");
  11290. return 1;
  11291. }
  11292. else {
  11293. int res;
  11294. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11295. goto failed;
  11296. }
  11297. res = obj2ast_int(state, tmp, &lineno, arena);
  11298. _Py_LeaveRecursiveCall();
  11299. if (res != 0) goto failed;
  11300. Py_CLEAR(tmp);
  11301. }
  11302. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  11303. return 1;
  11304. }
  11305. if (tmp == NULL) {
  11306. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from keyword");
  11307. return 1;
  11308. }
  11309. else {
  11310. int res;
  11311. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11312. goto failed;
  11313. }
  11314. res = obj2ast_int(state, tmp, &col_offset, arena);
  11315. _Py_LeaveRecursiveCall();
  11316. if (res != 0) goto failed;
  11317. Py_CLEAR(tmp);
  11318. }
  11319. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  11320. return 1;
  11321. }
  11322. if (tmp == NULL || tmp == Py_None) {
  11323. Py_CLEAR(tmp);
  11324. end_lineno = lineno;
  11325. }
  11326. else {
  11327. int res;
  11328. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11329. goto failed;
  11330. }
  11331. res = obj2ast_int(state, tmp, &end_lineno, arena);
  11332. _Py_LeaveRecursiveCall();
  11333. if (res != 0) goto failed;
  11334. Py_CLEAR(tmp);
  11335. }
  11336. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  11337. return 1;
  11338. }
  11339. if (tmp == NULL || tmp == Py_None) {
  11340. Py_CLEAR(tmp);
  11341. end_col_offset = col_offset;
  11342. }
  11343. else {
  11344. int res;
  11345. if (_Py_EnterRecursiveCall(" while traversing 'keyword' node")) {
  11346. goto failed;
  11347. }
  11348. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  11349. _Py_LeaveRecursiveCall();
  11350. if (res != 0) goto failed;
  11351. Py_CLEAR(tmp);
  11352. }
  11353. *out = _PyAST_keyword(arg, value, lineno, col_offset, end_lineno,
  11354. end_col_offset, arena);
  11355. if (*out == NULL) goto failed;
  11356. return 0;
  11357. failed:
  11358. Py_XDECREF(tmp);
  11359. return 1;
  11360. }
  11361. int
  11362. obj2ast_alias(struct ast_state *state, PyObject* obj, alias_ty* out, PyArena*
  11363. arena)
  11364. {
  11365. PyObject* tmp = NULL;
  11366. identifier name;
  11367. identifier asname;
  11368. int lineno;
  11369. int col_offset;
  11370. int end_lineno;
  11371. int end_col_offset;
  11372. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  11373. return 1;
  11374. }
  11375. if (tmp == NULL) {
  11376. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from alias");
  11377. return 1;
  11378. }
  11379. else {
  11380. int res;
  11381. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11382. goto failed;
  11383. }
  11384. res = obj2ast_identifier(state, tmp, &name, arena);
  11385. _Py_LeaveRecursiveCall();
  11386. if (res != 0) goto failed;
  11387. Py_CLEAR(tmp);
  11388. }
  11389. if (_PyObject_LookupAttr(obj, state->asname, &tmp) < 0) {
  11390. return 1;
  11391. }
  11392. if (tmp == NULL || tmp == Py_None) {
  11393. Py_CLEAR(tmp);
  11394. asname = NULL;
  11395. }
  11396. else {
  11397. int res;
  11398. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11399. goto failed;
  11400. }
  11401. res = obj2ast_identifier(state, tmp, &asname, arena);
  11402. _Py_LeaveRecursiveCall();
  11403. if (res != 0) goto failed;
  11404. Py_CLEAR(tmp);
  11405. }
  11406. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  11407. return 1;
  11408. }
  11409. if (tmp == NULL) {
  11410. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from alias");
  11411. return 1;
  11412. }
  11413. else {
  11414. int res;
  11415. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11416. goto failed;
  11417. }
  11418. res = obj2ast_int(state, tmp, &lineno, arena);
  11419. _Py_LeaveRecursiveCall();
  11420. if (res != 0) goto failed;
  11421. Py_CLEAR(tmp);
  11422. }
  11423. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  11424. return 1;
  11425. }
  11426. if (tmp == NULL) {
  11427. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from alias");
  11428. return 1;
  11429. }
  11430. else {
  11431. int res;
  11432. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11433. goto failed;
  11434. }
  11435. res = obj2ast_int(state, tmp, &col_offset, arena);
  11436. _Py_LeaveRecursiveCall();
  11437. if (res != 0) goto failed;
  11438. Py_CLEAR(tmp);
  11439. }
  11440. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  11441. return 1;
  11442. }
  11443. if (tmp == NULL || tmp == Py_None) {
  11444. Py_CLEAR(tmp);
  11445. end_lineno = lineno;
  11446. }
  11447. else {
  11448. int res;
  11449. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11450. goto failed;
  11451. }
  11452. res = obj2ast_int(state, tmp, &end_lineno, arena);
  11453. _Py_LeaveRecursiveCall();
  11454. if (res != 0) goto failed;
  11455. Py_CLEAR(tmp);
  11456. }
  11457. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  11458. return 1;
  11459. }
  11460. if (tmp == NULL || tmp == Py_None) {
  11461. Py_CLEAR(tmp);
  11462. end_col_offset = col_offset;
  11463. }
  11464. else {
  11465. int res;
  11466. if (_Py_EnterRecursiveCall(" while traversing 'alias' node")) {
  11467. goto failed;
  11468. }
  11469. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  11470. _Py_LeaveRecursiveCall();
  11471. if (res != 0) goto failed;
  11472. Py_CLEAR(tmp);
  11473. }
  11474. *out = _PyAST_alias(name, asname, lineno, col_offset, end_lineno,
  11475. end_col_offset, arena);
  11476. if (*out == NULL) goto failed;
  11477. return 0;
  11478. failed:
  11479. Py_XDECREF(tmp);
  11480. return 1;
  11481. }
  11482. int
  11483. obj2ast_withitem(struct ast_state *state, PyObject* obj, withitem_ty* out,
  11484. PyArena* arena)
  11485. {
  11486. PyObject* tmp = NULL;
  11487. expr_ty context_expr;
  11488. expr_ty optional_vars;
  11489. if (_PyObject_LookupAttr(obj, state->context_expr, &tmp) < 0) {
  11490. return 1;
  11491. }
  11492. if (tmp == NULL) {
  11493. PyErr_SetString(PyExc_TypeError, "required field \"context_expr\" missing from withitem");
  11494. return 1;
  11495. }
  11496. else {
  11497. int res;
  11498. if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
  11499. goto failed;
  11500. }
  11501. res = obj2ast_expr(state, tmp, &context_expr, arena);
  11502. _Py_LeaveRecursiveCall();
  11503. if (res != 0) goto failed;
  11504. Py_CLEAR(tmp);
  11505. }
  11506. if (_PyObject_LookupAttr(obj, state->optional_vars, &tmp) < 0) {
  11507. return 1;
  11508. }
  11509. if (tmp == NULL || tmp == Py_None) {
  11510. Py_CLEAR(tmp);
  11511. optional_vars = NULL;
  11512. }
  11513. else {
  11514. int res;
  11515. if (_Py_EnterRecursiveCall(" while traversing 'withitem' node")) {
  11516. goto failed;
  11517. }
  11518. res = obj2ast_expr(state, tmp, &optional_vars, arena);
  11519. _Py_LeaveRecursiveCall();
  11520. if (res != 0) goto failed;
  11521. Py_CLEAR(tmp);
  11522. }
  11523. *out = _PyAST_withitem(context_expr, optional_vars, arena);
  11524. if (*out == NULL) goto failed;
  11525. return 0;
  11526. failed:
  11527. Py_XDECREF(tmp);
  11528. return 1;
  11529. }
  11530. int
  11531. obj2ast_match_case(struct ast_state *state, PyObject* obj, match_case_ty* out,
  11532. PyArena* arena)
  11533. {
  11534. PyObject* tmp = NULL;
  11535. pattern_ty pattern;
  11536. expr_ty guard;
  11537. asdl_stmt_seq* body;
  11538. if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
  11539. return 1;
  11540. }
  11541. if (tmp == NULL) {
  11542. PyErr_SetString(PyExc_TypeError, "required field \"pattern\" missing from match_case");
  11543. return 1;
  11544. }
  11545. else {
  11546. int res;
  11547. if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
  11548. goto failed;
  11549. }
  11550. res = obj2ast_pattern(state, tmp, &pattern, arena);
  11551. _Py_LeaveRecursiveCall();
  11552. if (res != 0) goto failed;
  11553. Py_CLEAR(tmp);
  11554. }
  11555. if (_PyObject_LookupAttr(obj, state->guard, &tmp) < 0) {
  11556. return 1;
  11557. }
  11558. if (tmp == NULL || tmp == Py_None) {
  11559. Py_CLEAR(tmp);
  11560. guard = NULL;
  11561. }
  11562. else {
  11563. int res;
  11564. if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
  11565. goto failed;
  11566. }
  11567. res = obj2ast_expr(state, tmp, &guard, arena);
  11568. _Py_LeaveRecursiveCall();
  11569. if (res != 0) goto failed;
  11570. Py_CLEAR(tmp);
  11571. }
  11572. if (_PyObject_LookupAttr(obj, state->body, &tmp) < 0) {
  11573. return 1;
  11574. }
  11575. if (tmp == NULL) {
  11576. tmp = PyList_New(0);
  11577. if (tmp == NULL) {
  11578. return 1;
  11579. }
  11580. }
  11581. {
  11582. int res;
  11583. Py_ssize_t len;
  11584. Py_ssize_t i;
  11585. if (!PyList_Check(tmp)) {
  11586. PyErr_Format(PyExc_TypeError, "match_case field \"body\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11587. goto failed;
  11588. }
  11589. len = PyList_GET_SIZE(tmp);
  11590. body = _Py_asdl_stmt_seq_new(len, arena);
  11591. if (body == NULL) goto failed;
  11592. for (i = 0; i < len; i++) {
  11593. stmt_ty val;
  11594. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11595. if (_Py_EnterRecursiveCall(" while traversing 'match_case' node")) {
  11596. goto failed;
  11597. }
  11598. res = obj2ast_stmt(state, tmp2, &val, arena);
  11599. _Py_LeaveRecursiveCall();
  11600. Py_DECREF(tmp2);
  11601. if (res != 0) goto failed;
  11602. if (len != PyList_GET_SIZE(tmp)) {
  11603. PyErr_SetString(PyExc_RuntimeError, "match_case field \"body\" changed size during iteration");
  11604. goto failed;
  11605. }
  11606. asdl_seq_SET(body, i, val);
  11607. }
  11608. Py_CLEAR(tmp);
  11609. }
  11610. *out = _PyAST_match_case(pattern, guard, body, arena);
  11611. if (*out == NULL) goto failed;
  11612. return 0;
  11613. failed:
  11614. Py_XDECREF(tmp);
  11615. return 1;
  11616. }
  11617. int
  11618. obj2ast_pattern(struct ast_state *state, PyObject* obj, pattern_ty* out,
  11619. PyArena* arena)
  11620. {
  11621. int isinstance;
  11622. PyObject *tmp = NULL;
  11623. PyObject *tp;
  11624. int lineno;
  11625. int col_offset;
  11626. int end_lineno;
  11627. int end_col_offset;
  11628. if (obj == Py_None) {
  11629. *out = NULL;
  11630. return 0;
  11631. }
  11632. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  11633. return 1;
  11634. }
  11635. if (tmp == NULL) {
  11636. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from pattern");
  11637. return 1;
  11638. }
  11639. else {
  11640. int res;
  11641. if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
  11642. goto failed;
  11643. }
  11644. res = obj2ast_int(state, tmp, &lineno, arena);
  11645. _Py_LeaveRecursiveCall();
  11646. if (res != 0) goto failed;
  11647. Py_CLEAR(tmp);
  11648. }
  11649. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  11650. return 1;
  11651. }
  11652. if (tmp == NULL) {
  11653. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from pattern");
  11654. return 1;
  11655. }
  11656. else {
  11657. int res;
  11658. if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
  11659. goto failed;
  11660. }
  11661. res = obj2ast_int(state, tmp, &col_offset, arena);
  11662. _Py_LeaveRecursiveCall();
  11663. if (res != 0) goto failed;
  11664. Py_CLEAR(tmp);
  11665. }
  11666. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  11667. return 1;
  11668. }
  11669. if (tmp == NULL) {
  11670. PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from pattern");
  11671. return 1;
  11672. }
  11673. else {
  11674. int res;
  11675. if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
  11676. goto failed;
  11677. }
  11678. res = obj2ast_int(state, tmp, &end_lineno, arena);
  11679. _Py_LeaveRecursiveCall();
  11680. if (res != 0) goto failed;
  11681. Py_CLEAR(tmp);
  11682. }
  11683. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  11684. return 1;
  11685. }
  11686. if (tmp == NULL) {
  11687. PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from pattern");
  11688. return 1;
  11689. }
  11690. else {
  11691. int res;
  11692. if (_Py_EnterRecursiveCall(" while traversing 'pattern' node")) {
  11693. goto failed;
  11694. }
  11695. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  11696. _Py_LeaveRecursiveCall();
  11697. if (res != 0) goto failed;
  11698. Py_CLEAR(tmp);
  11699. }
  11700. tp = state->MatchValue_type;
  11701. isinstance = PyObject_IsInstance(obj, tp);
  11702. if (isinstance == -1) {
  11703. return 1;
  11704. }
  11705. if (isinstance) {
  11706. expr_ty value;
  11707. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  11708. return 1;
  11709. }
  11710. if (tmp == NULL) {
  11711. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchValue");
  11712. return 1;
  11713. }
  11714. else {
  11715. int res;
  11716. if (_Py_EnterRecursiveCall(" while traversing 'MatchValue' node")) {
  11717. goto failed;
  11718. }
  11719. res = obj2ast_expr(state, tmp, &value, arena);
  11720. _Py_LeaveRecursiveCall();
  11721. if (res != 0) goto failed;
  11722. Py_CLEAR(tmp);
  11723. }
  11724. *out = _PyAST_MatchValue(value, lineno, col_offset, end_lineno,
  11725. end_col_offset, arena);
  11726. if (*out == NULL) goto failed;
  11727. return 0;
  11728. }
  11729. tp = state->MatchSingleton_type;
  11730. isinstance = PyObject_IsInstance(obj, tp);
  11731. if (isinstance == -1) {
  11732. return 1;
  11733. }
  11734. if (isinstance) {
  11735. constant value;
  11736. if (_PyObject_LookupAttr(obj, state->value, &tmp) < 0) {
  11737. return 1;
  11738. }
  11739. if (tmp == NULL) {
  11740. PyErr_SetString(PyExc_TypeError, "required field \"value\" missing from MatchSingleton");
  11741. return 1;
  11742. }
  11743. else {
  11744. int res;
  11745. if (_Py_EnterRecursiveCall(" while traversing 'MatchSingleton' node")) {
  11746. goto failed;
  11747. }
  11748. res = obj2ast_constant(state, tmp, &value, arena);
  11749. _Py_LeaveRecursiveCall();
  11750. if (res != 0) goto failed;
  11751. Py_CLEAR(tmp);
  11752. }
  11753. *out = _PyAST_MatchSingleton(value, lineno, col_offset, end_lineno,
  11754. end_col_offset, arena);
  11755. if (*out == NULL) goto failed;
  11756. return 0;
  11757. }
  11758. tp = state->MatchSequence_type;
  11759. isinstance = PyObject_IsInstance(obj, tp);
  11760. if (isinstance == -1) {
  11761. return 1;
  11762. }
  11763. if (isinstance) {
  11764. asdl_pattern_seq* patterns;
  11765. if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
  11766. return 1;
  11767. }
  11768. if (tmp == NULL) {
  11769. tmp = PyList_New(0);
  11770. if (tmp == NULL) {
  11771. return 1;
  11772. }
  11773. }
  11774. {
  11775. int res;
  11776. Py_ssize_t len;
  11777. Py_ssize_t i;
  11778. if (!PyList_Check(tmp)) {
  11779. PyErr_Format(PyExc_TypeError, "MatchSequence field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11780. goto failed;
  11781. }
  11782. len = PyList_GET_SIZE(tmp);
  11783. patterns = _Py_asdl_pattern_seq_new(len, arena);
  11784. if (patterns == NULL) goto failed;
  11785. for (i = 0; i < len; i++) {
  11786. pattern_ty val;
  11787. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11788. if (_Py_EnterRecursiveCall(" while traversing 'MatchSequence' node")) {
  11789. goto failed;
  11790. }
  11791. res = obj2ast_pattern(state, tmp2, &val, arena);
  11792. _Py_LeaveRecursiveCall();
  11793. Py_DECREF(tmp2);
  11794. if (res != 0) goto failed;
  11795. if (len != PyList_GET_SIZE(tmp)) {
  11796. PyErr_SetString(PyExc_RuntimeError, "MatchSequence field \"patterns\" changed size during iteration");
  11797. goto failed;
  11798. }
  11799. asdl_seq_SET(patterns, i, val);
  11800. }
  11801. Py_CLEAR(tmp);
  11802. }
  11803. *out = _PyAST_MatchSequence(patterns, lineno, col_offset, end_lineno,
  11804. end_col_offset, arena);
  11805. if (*out == NULL) goto failed;
  11806. return 0;
  11807. }
  11808. tp = state->MatchMapping_type;
  11809. isinstance = PyObject_IsInstance(obj, tp);
  11810. if (isinstance == -1) {
  11811. return 1;
  11812. }
  11813. if (isinstance) {
  11814. asdl_expr_seq* keys;
  11815. asdl_pattern_seq* patterns;
  11816. identifier rest;
  11817. if (_PyObject_LookupAttr(obj, state->keys, &tmp) < 0) {
  11818. return 1;
  11819. }
  11820. if (tmp == NULL) {
  11821. tmp = PyList_New(0);
  11822. if (tmp == NULL) {
  11823. return 1;
  11824. }
  11825. }
  11826. {
  11827. int res;
  11828. Py_ssize_t len;
  11829. Py_ssize_t i;
  11830. if (!PyList_Check(tmp)) {
  11831. PyErr_Format(PyExc_TypeError, "MatchMapping field \"keys\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11832. goto failed;
  11833. }
  11834. len = PyList_GET_SIZE(tmp);
  11835. keys = _Py_asdl_expr_seq_new(len, arena);
  11836. if (keys == NULL) goto failed;
  11837. for (i = 0; i < len; i++) {
  11838. expr_ty val;
  11839. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11840. if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
  11841. goto failed;
  11842. }
  11843. res = obj2ast_expr(state, tmp2, &val, arena);
  11844. _Py_LeaveRecursiveCall();
  11845. Py_DECREF(tmp2);
  11846. if (res != 0) goto failed;
  11847. if (len != PyList_GET_SIZE(tmp)) {
  11848. PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"keys\" changed size during iteration");
  11849. goto failed;
  11850. }
  11851. asdl_seq_SET(keys, i, val);
  11852. }
  11853. Py_CLEAR(tmp);
  11854. }
  11855. if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
  11856. return 1;
  11857. }
  11858. if (tmp == NULL) {
  11859. tmp = PyList_New(0);
  11860. if (tmp == NULL) {
  11861. return 1;
  11862. }
  11863. }
  11864. {
  11865. int res;
  11866. Py_ssize_t len;
  11867. Py_ssize_t i;
  11868. if (!PyList_Check(tmp)) {
  11869. PyErr_Format(PyExc_TypeError, "MatchMapping field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11870. goto failed;
  11871. }
  11872. len = PyList_GET_SIZE(tmp);
  11873. patterns = _Py_asdl_pattern_seq_new(len, arena);
  11874. if (patterns == NULL) goto failed;
  11875. for (i = 0; i < len; i++) {
  11876. pattern_ty val;
  11877. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11878. if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
  11879. goto failed;
  11880. }
  11881. res = obj2ast_pattern(state, tmp2, &val, arena);
  11882. _Py_LeaveRecursiveCall();
  11883. Py_DECREF(tmp2);
  11884. if (res != 0) goto failed;
  11885. if (len != PyList_GET_SIZE(tmp)) {
  11886. PyErr_SetString(PyExc_RuntimeError, "MatchMapping field \"patterns\" changed size during iteration");
  11887. goto failed;
  11888. }
  11889. asdl_seq_SET(patterns, i, val);
  11890. }
  11891. Py_CLEAR(tmp);
  11892. }
  11893. if (_PyObject_LookupAttr(obj, state->rest, &tmp) < 0) {
  11894. return 1;
  11895. }
  11896. if (tmp == NULL || tmp == Py_None) {
  11897. Py_CLEAR(tmp);
  11898. rest = NULL;
  11899. }
  11900. else {
  11901. int res;
  11902. if (_Py_EnterRecursiveCall(" while traversing 'MatchMapping' node")) {
  11903. goto failed;
  11904. }
  11905. res = obj2ast_identifier(state, tmp, &rest, arena);
  11906. _Py_LeaveRecursiveCall();
  11907. if (res != 0) goto failed;
  11908. Py_CLEAR(tmp);
  11909. }
  11910. *out = _PyAST_MatchMapping(keys, patterns, rest, lineno, col_offset,
  11911. end_lineno, end_col_offset, arena);
  11912. if (*out == NULL) goto failed;
  11913. return 0;
  11914. }
  11915. tp = state->MatchClass_type;
  11916. isinstance = PyObject_IsInstance(obj, tp);
  11917. if (isinstance == -1) {
  11918. return 1;
  11919. }
  11920. if (isinstance) {
  11921. expr_ty cls;
  11922. asdl_pattern_seq* patterns;
  11923. asdl_identifier_seq* kwd_attrs;
  11924. asdl_pattern_seq* kwd_patterns;
  11925. if (_PyObject_LookupAttr(obj, state->cls, &tmp) < 0) {
  11926. return 1;
  11927. }
  11928. if (tmp == NULL) {
  11929. PyErr_SetString(PyExc_TypeError, "required field \"cls\" missing from MatchClass");
  11930. return 1;
  11931. }
  11932. else {
  11933. int res;
  11934. if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
  11935. goto failed;
  11936. }
  11937. res = obj2ast_expr(state, tmp, &cls, arena);
  11938. _Py_LeaveRecursiveCall();
  11939. if (res != 0) goto failed;
  11940. Py_CLEAR(tmp);
  11941. }
  11942. if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
  11943. return 1;
  11944. }
  11945. if (tmp == NULL) {
  11946. tmp = PyList_New(0);
  11947. if (tmp == NULL) {
  11948. return 1;
  11949. }
  11950. }
  11951. {
  11952. int res;
  11953. Py_ssize_t len;
  11954. Py_ssize_t i;
  11955. if (!PyList_Check(tmp)) {
  11956. PyErr_Format(PyExc_TypeError, "MatchClass field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11957. goto failed;
  11958. }
  11959. len = PyList_GET_SIZE(tmp);
  11960. patterns = _Py_asdl_pattern_seq_new(len, arena);
  11961. if (patterns == NULL) goto failed;
  11962. for (i = 0; i < len; i++) {
  11963. pattern_ty val;
  11964. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  11965. if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
  11966. goto failed;
  11967. }
  11968. res = obj2ast_pattern(state, tmp2, &val, arena);
  11969. _Py_LeaveRecursiveCall();
  11970. Py_DECREF(tmp2);
  11971. if (res != 0) goto failed;
  11972. if (len != PyList_GET_SIZE(tmp)) {
  11973. PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"patterns\" changed size during iteration");
  11974. goto failed;
  11975. }
  11976. asdl_seq_SET(patterns, i, val);
  11977. }
  11978. Py_CLEAR(tmp);
  11979. }
  11980. if (_PyObject_LookupAttr(obj, state->kwd_attrs, &tmp) < 0) {
  11981. return 1;
  11982. }
  11983. if (tmp == NULL) {
  11984. tmp = PyList_New(0);
  11985. if (tmp == NULL) {
  11986. return 1;
  11987. }
  11988. }
  11989. {
  11990. int res;
  11991. Py_ssize_t len;
  11992. Py_ssize_t i;
  11993. if (!PyList_Check(tmp)) {
  11994. PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_attrs\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  11995. goto failed;
  11996. }
  11997. len = PyList_GET_SIZE(tmp);
  11998. kwd_attrs = _Py_asdl_identifier_seq_new(len, arena);
  11999. if (kwd_attrs == NULL) goto failed;
  12000. for (i = 0; i < len; i++) {
  12001. identifier val;
  12002. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  12003. if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
  12004. goto failed;
  12005. }
  12006. res = obj2ast_identifier(state, tmp2, &val, arena);
  12007. _Py_LeaveRecursiveCall();
  12008. Py_DECREF(tmp2);
  12009. if (res != 0) goto failed;
  12010. if (len != PyList_GET_SIZE(tmp)) {
  12011. PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_attrs\" changed size during iteration");
  12012. goto failed;
  12013. }
  12014. asdl_seq_SET(kwd_attrs, i, val);
  12015. }
  12016. Py_CLEAR(tmp);
  12017. }
  12018. if (_PyObject_LookupAttr(obj, state->kwd_patterns, &tmp) < 0) {
  12019. return 1;
  12020. }
  12021. if (tmp == NULL) {
  12022. tmp = PyList_New(0);
  12023. if (tmp == NULL) {
  12024. return 1;
  12025. }
  12026. }
  12027. {
  12028. int res;
  12029. Py_ssize_t len;
  12030. Py_ssize_t i;
  12031. if (!PyList_Check(tmp)) {
  12032. PyErr_Format(PyExc_TypeError, "MatchClass field \"kwd_patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  12033. goto failed;
  12034. }
  12035. len = PyList_GET_SIZE(tmp);
  12036. kwd_patterns = _Py_asdl_pattern_seq_new(len, arena);
  12037. if (kwd_patterns == NULL) goto failed;
  12038. for (i = 0; i < len; i++) {
  12039. pattern_ty val;
  12040. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  12041. if (_Py_EnterRecursiveCall(" while traversing 'MatchClass' node")) {
  12042. goto failed;
  12043. }
  12044. res = obj2ast_pattern(state, tmp2, &val, arena);
  12045. _Py_LeaveRecursiveCall();
  12046. Py_DECREF(tmp2);
  12047. if (res != 0) goto failed;
  12048. if (len != PyList_GET_SIZE(tmp)) {
  12049. PyErr_SetString(PyExc_RuntimeError, "MatchClass field \"kwd_patterns\" changed size during iteration");
  12050. goto failed;
  12051. }
  12052. asdl_seq_SET(kwd_patterns, i, val);
  12053. }
  12054. Py_CLEAR(tmp);
  12055. }
  12056. *out = _PyAST_MatchClass(cls, patterns, kwd_attrs, kwd_patterns,
  12057. lineno, col_offset, end_lineno,
  12058. end_col_offset, arena);
  12059. if (*out == NULL) goto failed;
  12060. return 0;
  12061. }
  12062. tp = state->MatchStar_type;
  12063. isinstance = PyObject_IsInstance(obj, tp);
  12064. if (isinstance == -1) {
  12065. return 1;
  12066. }
  12067. if (isinstance) {
  12068. identifier name;
  12069. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12070. return 1;
  12071. }
  12072. if (tmp == NULL || tmp == Py_None) {
  12073. Py_CLEAR(tmp);
  12074. name = NULL;
  12075. }
  12076. else {
  12077. int res;
  12078. if (_Py_EnterRecursiveCall(" while traversing 'MatchStar' node")) {
  12079. goto failed;
  12080. }
  12081. res = obj2ast_identifier(state, tmp, &name, arena);
  12082. _Py_LeaveRecursiveCall();
  12083. if (res != 0) goto failed;
  12084. Py_CLEAR(tmp);
  12085. }
  12086. *out = _PyAST_MatchStar(name, lineno, col_offset, end_lineno,
  12087. end_col_offset, arena);
  12088. if (*out == NULL) goto failed;
  12089. return 0;
  12090. }
  12091. tp = state->MatchAs_type;
  12092. isinstance = PyObject_IsInstance(obj, tp);
  12093. if (isinstance == -1) {
  12094. return 1;
  12095. }
  12096. if (isinstance) {
  12097. pattern_ty pattern;
  12098. identifier name;
  12099. if (_PyObject_LookupAttr(obj, state->pattern, &tmp) < 0) {
  12100. return 1;
  12101. }
  12102. if (tmp == NULL || tmp == Py_None) {
  12103. Py_CLEAR(tmp);
  12104. pattern = NULL;
  12105. }
  12106. else {
  12107. int res;
  12108. if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
  12109. goto failed;
  12110. }
  12111. res = obj2ast_pattern(state, tmp, &pattern, arena);
  12112. _Py_LeaveRecursiveCall();
  12113. if (res != 0) goto failed;
  12114. Py_CLEAR(tmp);
  12115. }
  12116. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12117. return 1;
  12118. }
  12119. if (tmp == NULL || tmp == Py_None) {
  12120. Py_CLEAR(tmp);
  12121. name = NULL;
  12122. }
  12123. else {
  12124. int res;
  12125. if (_Py_EnterRecursiveCall(" while traversing 'MatchAs' node")) {
  12126. goto failed;
  12127. }
  12128. res = obj2ast_identifier(state, tmp, &name, arena);
  12129. _Py_LeaveRecursiveCall();
  12130. if (res != 0) goto failed;
  12131. Py_CLEAR(tmp);
  12132. }
  12133. *out = _PyAST_MatchAs(pattern, name, lineno, col_offset, end_lineno,
  12134. end_col_offset, arena);
  12135. if (*out == NULL) goto failed;
  12136. return 0;
  12137. }
  12138. tp = state->MatchOr_type;
  12139. isinstance = PyObject_IsInstance(obj, tp);
  12140. if (isinstance == -1) {
  12141. return 1;
  12142. }
  12143. if (isinstance) {
  12144. asdl_pattern_seq* patterns;
  12145. if (_PyObject_LookupAttr(obj, state->patterns, &tmp) < 0) {
  12146. return 1;
  12147. }
  12148. if (tmp == NULL) {
  12149. tmp = PyList_New(0);
  12150. if (tmp == NULL) {
  12151. return 1;
  12152. }
  12153. }
  12154. {
  12155. int res;
  12156. Py_ssize_t len;
  12157. Py_ssize_t i;
  12158. if (!PyList_Check(tmp)) {
  12159. PyErr_Format(PyExc_TypeError, "MatchOr field \"patterns\" must be a list, not a %.200s", _PyType_Name(Py_TYPE(tmp)));
  12160. goto failed;
  12161. }
  12162. len = PyList_GET_SIZE(tmp);
  12163. patterns = _Py_asdl_pattern_seq_new(len, arena);
  12164. if (patterns == NULL) goto failed;
  12165. for (i = 0; i < len; i++) {
  12166. pattern_ty val;
  12167. PyObject *tmp2 = Py_NewRef(PyList_GET_ITEM(tmp, i));
  12168. if (_Py_EnterRecursiveCall(" while traversing 'MatchOr' node")) {
  12169. goto failed;
  12170. }
  12171. res = obj2ast_pattern(state, tmp2, &val, arena);
  12172. _Py_LeaveRecursiveCall();
  12173. Py_DECREF(tmp2);
  12174. if (res != 0) goto failed;
  12175. if (len != PyList_GET_SIZE(tmp)) {
  12176. PyErr_SetString(PyExc_RuntimeError, "MatchOr field \"patterns\" changed size during iteration");
  12177. goto failed;
  12178. }
  12179. asdl_seq_SET(patterns, i, val);
  12180. }
  12181. Py_CLEAR(tmp);
  12182. }
  12183. *out = _PyAST_MatchOr(patterns, lineno, col_offset, end_lineno,
  12184. end_col_offset, arena);
  12185. if (*out == NULL) goto failed;
  12186. return 0;
  12187. }
  12188. PyErr_Format(PyExc_TypeError, "expected some sort of pattern, but got %R", obj);
  12189. failed:
  12190. Py_XDECREF(tmp);
  12191. return 1;
  12192. }
  12193. int
  12194. obj2ast_type_ignore(struct ast_state *state, PyObject* obj, type_ignore_ty*
  12195. out, PyArena* arena)
  12196. {
  12197. int isinstance;
  12198. PyObject *tmp = NULL;
  12199. PyObject *tp;
  12200. if (obj == Py_None) {
  12201. *out = NULL;
  12202. return 0;
  12203. }
  12204. tp = state->TypeIgnore_type;
  12205. isinstance = PyObject_IsInstance(obj, tp);
  12206. if (isinstance == -1) {
  12207. return 1;
  12208. }
  12209. if (isinstance) {
  12210. int lineno;
  12211. string tag;
  12212. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  12213. return 1;
  12214. }
  12215. if (tmp == NULL) {
  12216. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from TypeIgnore");
  12217. return 1;
  12218. }
  12219. else {
  12220. int res;
  12221. if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
  12222. goto failed;
  12223. }
  12224. res = obj2ast_int(state, tmp, &lineno, arena);
  12225. _Py_LeaveRecursiveCall();
  12226. if (res != 0) goto failed;
  12227. Py_CLEAR(tmp);
  12228. }
  12229. if (_PyObject_LookupAttr(obj, state->tag, &tmp) < 0) {
  12230. return 1;
  12231. }
  12232. if (tmp == NULL) {
  12233. PyErr_SetString(PyExc_TypeError, "required field \"tag\" missing from TypeIgnore");
  12234. return 1;
  12235. }
  12236. else {
  12237. int res;
  12238. if (_Py_EnterRecursiveCall(" while traversing 'TypeIgnore' node")) {
  12239. goto failed;
  12240. }
  12241. res = obj2ast_string(state, tmp, &tag, arena);
  12242. _Py_LeaveRecursiveCall();
  12243. if (res != 0) goto failed;
  12244. Py_CLEAR(tmp);
  12245. }
  12246. *out = _PyAST_TypeIgnore(lineno, tag, arena);
  12247. if (*out == NULL) goto failed;
  12248. return 0;
  12249. }
  12250. PyErr_Format(PyExc_TypeError, "expected some sort of type_ignore, but got %R", obj);
  12251. failed:
  12252. Py_XDECREF(tmp);
  12253. return 1;
  12254. }
  12255. int
  12256. obj2ast_type_param(struct ast_state *state, PyObject* obj, type_param_ty* out,
  12257. PyArena* arena)
  12258. {
  12259. int isinstance;
  12260. PyObject *tmp = NULL;
  12261. PyObject *tp;
  12262. int lineno;
  12263. int col_offset;
  12264. int end_lineno;
  12265. int end_col_offset;
  12266. if (obj == Py_None) {
  12267. *out = NULL;
  12268. return 0;
  12269. }
  12270. if (_PyObject_LookupAttr(obj, state->lineno, &tmp) < 0) {
  12271. return 1;
  12272. }
  12273. if (tmp == NULL) {
  12274. PyErr_SetString(PyExc_TypeError, "required field \"lineno\" missing from type_param");
  12275. return 1;
  12276. }
  12277. else {
  12278. int res;
  12279. if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
  12280. goto failed;
  12281. }
  12282. res = obj2ast_int(state, tmp, &lineno, arena);
  12283. _Py_LeaveRecursiveCall();
  12284. if (res != 0) goto failed;
  12285. Py_CLEAR(tmp);
  12286. }
  12287. if (_PyObject_LookupAttr(obj, state->col_offset, &tmp) < 0) {
  12288. return 1;
  12289. }
  12290. if (tmp == NULL) {
  12291. PyErr_SetString(PyExc_TypeError, "required field \"col_offset\" missing from type_param");
  12292. return 1;
  12293. }
  12294. else {
  12295. int res;
  12296. if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
  12297. goto failed;
  12298. }
  12299. res = obj2ast_int(state, tmp, &col_offset, arena);
  12300. _Py_LeaveRecursiveCall();
  12301. if (res != 0) goto failed;
  12302. Py_CLEAR(tmp);
  12303. }
  12304. if (_PyObject_LookupAttr(obj, state->end_lineno, &tmp) < 0) {
  12305. return 1;
  12306. }
  12307. if (tmp == NULL) {
  12308. PyErr_SetString(PyExc_TypeError, "required field \"end_lineno\" missing from type_param");
  12309. return 1;
  12310. }
  12311. else {
  12312. int res;
  12313. if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
  12314. goto failed;
  12315. }
  12316. res = obj2ast_int(state, tmp, &end_lineno, arena);
  12317. _Py_LeaveRecursiveCall();
  12318. if (res != 0) goto failed;
  12319. Py_CLEAR(tmp);
  12320. }
  12321. if (_PyObject_LookupAttr(obj, state->end_col_offset, &tmp) < 0) {
  12322. return 1;
  12323. }
  12324. if (tmp == NULL) {
  12325. PyErr_SetString(PyExc_TypeError, "required field \"end_col_offset\" missing from type_param");
  12326. return 1;
  12327. }
  12328. else {
  12329. int res;
  12330. if (_Py_EnterRecursiveCall(" while traversing 'type_param' node")) {
  12331. goto failed;
  12332. }
  12333. res = obj2ast_int(state, tmp, &end_col_offset, arena);
  12334. _Py_LeaveRecursiveCall();
  12335. if (res != 0) goto failed;
  12336. Py_CLEAR(tmp);
  12337. }
  12338. tp = state->TypeVar_type;
  12339. isinstance = PyObject_IsInstance(obj, tp);
  12340. if (isinstance == -1) {
  12341. return 1;
  12342. }
  12343. if (isinstance) {
  12344. identifier name;
  12345. expr_ty bound;
  12346. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12347. return 1;
  12348. }
  12349. if (tmp == NULL) {
  12350. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVar");
  12351. return 1;
  12352. }
  12353. else {
  12354. int res;
  12355. if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
  12356. goto failed;
  12357. }
  12358. res = obj2ast_identifier(state, tmp, &name, arena);
  12359. _Py_LeaveRecursiveCall();
  12360. if (res != 0) goto failed;
  12361. Py_CLEAR(tmp);
  12362. }
  12363. if (_PyObject_LookupAttr(obj, state->bound, &tmp) < 0) {
  12364. return 1;
  12365. }
  12366. if (tmp == NULL || tmp == Py_None) {
  12367. Py_CLEAR(tmp);
  12368. bound = NULL;
  12369. }
  12370. else {
  12371. int res;
  12372. if (_Py_EnterRecursiveCall(" while traversing 'TypeVar' node")) {
  12373. goto failed;
  12374. }
  12375. res = obj2ast_expr(state, tmp, &bound, arena);
  12376. _Py_LeaveRecursiveCall();
  12377. if (res != 0) goto failed;
  12378. Py_CLEAR(tmp);
  12379. }
  12380. *out = _PyAST_TypeVar(name, bound, lineno, col_offset, end_lineno,
  12381. end_col_offset, arena);
  12382. if (*out == NULL) goto failed;
  12383. return 0;
  12384. }
  12385. tp = state->ParamSpec_type;
  12386. isinstance = PyObject_IsInstance(obj, tp);
  12387. if (isinstance == -1) {
  12388. return 1;
  12389. }
  12390. if (isinstance) {
  12391. identifier name;
  12392. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12393. return 1;
  12394. }
  12395. if (tmp == NULL) {
  12396. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from ParamSpec");
  12397. return 1;
  12398. }
  12399. else {
  12400. int res;
  12401. if (_Py_EnterRecursiveCall(" while traversing 'ParamSpec' node")) {
  12402. goto failed;
  12403. }
  12404. res = obj2ast_identifier(state, tmp, &name, arena);
  12405. _Py_LeaveRecursiveCall();
  12406. if (res != 0) goto failed;
  12407. Py_CLEAR(tmp);
  12408. }
  12409. *out = _PyAST_ParamSpec(name, lineno, col_offset, end_lineno,
  12410. end_col_offset, arena);
  12411. if (*out == NULL) goto failed;
  12412. return 0;
  12413. }
  12414. tp = state->TypeVarTuple_type;
  12415. isinstance = PyObject_IsInstance(obj, tp);
  12416. if (isinstance == -1) {
  12417. return 1;
  12418. }
  12419. if (isinstance) {
  12420. identifier name;
  12421. if (_PyObject_LookupAttr(obj, state->name, &tmp) < 0) {
  12422. return 1;
  12423. }
  12424. if (tmp == NULL) {
  12425. PyErr_SetString(PyExc_TypeError, "required field \"name\" missing from TypeVarTuple");
  12426. return 1;
  12427. }
  12428. else {
  12429. int res;
  12430. if (_Py_EnterRecursiveCall(" while traversing 'TypeVarTuple' node")) {
  12431. goto failed;
  12432. }
  12433. res = obj2ast_identifier(state, tmp, &name, arena);
  12434. _Py_LeaveRecursiveCall();
  12435. if (res != 0) goto failed;
  12436. Py_CLEAR(tmp);
  12437. }
  12438. *out = _PyAST_TypeVarTuple(name, lineno, col_offset, end_lineno,
  12439. end_col_offset, arena);
  12440. if (*out == NULL) goto failed;
  12441. return 0;
  12442. }
  12443. PyErr_Format(PyExc_TypeError, "expected some sort of type_param, but got %R", obj);
  12444. failed:
  12445. Py_XDECREF(tmp);
  12446. return 1;
  12447. }
  12448. static int
  12449. astmodule_exec(PyObject *m)
  12450. {
  12451. struct ast_state *state = get_ast_state();
  12452. if (state == NULL) {
  12453. return -1;
  12454. }
  12455. if (PyModule_AddObjectRef(m, "AST", state->AST_type) < 0) {
  12456. return -1;
  12457. }
  12458. if (PyModule_AddIntMacro(m, PyCF_ALLOW_TOP_LEVEL_AWAIT) < 0) {
  12459. return -1;
  12460. }
  12461. if (PyModule_AddIntMacro(m, PyCF_ONLY_AST) < 0) {
  12462. return -1;
  12463. }
  12464. if (PyModule_AddIntMacro(m, PyCF_TYPE_COMMENTS) < 0) {
  12465. return -1;
  12466. }
  12467. if (PyModule_AddObjectRef(m, "mod", state->mod_type) < 0) {
  12468. return -1;
  12469. }
  12470. if (PyModule_AddObjectRef(m, "Module", state->Module_type) < 0) {
  12471. return -1;
  12472. }
  12473. if (PyModule_AddObjectRef(m, "Interactive", state->Interactive_type) < 0) {
  12474. return -1;
  12475. }
  12476. if (PyModule_AddObjectRef(m, "Expression", state->Expression_type) < 0) {
  12477. return -1;
  12478. }
  12479. if (PyModule_AddObjectRef(m, "FunctionType", state->FunctionType_type) < 0)
  12480. {
  12481. return -1;
  12482. }
  12483. if (PyModule_AddObjectRef(m, "stmt", state->stmt_type) < 0) {
  12484. return -1;
  12485. }
  12486. if (PyModule_AddObjectRef(m, "FunctionDef", state->FunctionDef_type) < 0) {
  12487. return -1;
  12488. }
  12489. if (PyModule_AddObjectRef(m, "AsyncFunctionDef",
  12490. state->AsyncFunctionDef_type) < 0) {
  12491. return -1;
  12492. }
  12493. if (PyModule_AddObjectRef(m, "ClassDef", state->ClassDef_type) < 0) {
  12494. return -1;
  12495. }
  12496. if (PyModule_AddObjectRef(m, "Return", state->Return_type) < 0) {
  12497. return -1;
  12498. }
  12499. if (PyModule_AddObjectRef(m, "Delete", state->Delete_type) < 0) {
  12500. return -1;
  12501. }
  12502. if (PyModule_AddObjectRef(m, "Assign", state->Assign_type) < 0) {
  12503. return -1;
  12504. }
  12505. if (PyModule_AddObjectRef(m, "TypeAlias", state->TypeAlias_type) < 0) {
  12506. return -1;
  12507. }
  12508. if (PyModule_AddObjectRef(m, "AugAssign", state->AugAssign_type) < 0) {
  12509. return -1;
  12510. }
  12511. if (PyModule_AddObjectRef(m, "AnnAssign", state->AnnAssign_type) < 0) {
  12512. return -1;
  12513. }
  12514. if (PyModule_AddObjectRef(m, "For", state->For_type) < 0) {
  12515. return -1;
  12516. }
  12517. if (PyModule_AddObjectRef(m, "AsyncFor", state->AsyncFor_type) < 0) {
  12518. return -1;
  12519. }
  12520. if (PyModule_AddObjectRef(m, "While", state->While_type) < 0) {
  12521. return -1;
  12522. }
  12523. if (PyModule_AddObjectRef(m, "If", state->If_type) < 0) {
  12524. return -1;
  12525. }
  12526. if (PyModule_AddObjectRef(m, "With", state->With_type) < 0) {
  12527. return -1;
  12528. }
  12529. if (PyModule_AddObjectRef(m, "AsyncWith", state->AsyncWith_type) < 0) {
  12530. return -1;
  12531. }
  12532. if (PyModule_AddObjectRef(m, "Match", state->Match_type) < 0) {
  12533. return -1;
  12534. }
  12535. if (PyModule_AddObjectRef(m, "Raise", state->Raise_type) < 0) {
  12536. return -1;
  12537. }
  12538. if (PyModule_AddObjectRef(m, "Try", state->Try_type) < 0) {
  12539. return -1;
  12540. }
  12541. if (PyModule_AddObjectRef(m, "TryStar", state->TryStar_type) < 0) {
  12542. return -1;
  12543. }
  12544. if (PyModule_AddObjectRef(m, "Assert", state->Assert_type) < 0) {
  12545. return -1;
  12546. }
  12547. if (PyModule_AddObjectRef(m, "Import", state->Import_type) < 0) {
  12548. return -1;
  12549. }
  12550. if (PyModule_AddObjectRef(m, "ImportFrom", state->ImportFrom_type) < 0) {
  12551. return -1;
  12552. }
  12553. if (PyModule_AddObjectRef(m, "Global", state->Global_type) < 0) {
  12554. return -1;
  12555. }
  12556. if (PyModule_AddObjectRef(m, "Nonlocal", state->Nonlocal_type) < 0) {
  12557. return -1;
  12558. }
  12559. if (PyModule_AddObjectRef(m, "Expr", state->Expr_type) < 0) {
  12560. return -1;
  12561. }
  12562. if (PyModule_AddObjectRef(m, "Pass", state->Pass_type) < 0) {
  12563. return -1;
  12564. }
  12565. if (PyModule_AddObjectRef(m, "Break", state->Break_type) < 0) {
  12566. return -1;
  12567. }
  12568. if (PyModule_AddObjectRef(m, "Continue", state->Continue_type) < 0) {
  12569. return -1;
  12570. }
  12571. if (PyModule_AddObjectRef(m, "expr", state->expr_type) < 0) {
  12572. return -1;
  12573. }
  12574. if (PyModule_AddObjectRef(m, "BoolOp", state->BoolOp_type) < 0) {
  12575. return -1;
  12576. }
  12577. if (PyModule_AddObjectRef(m, "NamedExpr", state->NamedExpr_type) < 0) {
  12578. return -1;
  12579. }
  12580. if (PyModule_AddObjectRef(m, "BinOp", state->BinOp_type) < 0) {
  12581. return -1;
  12582. }
  12583. if (PyModule_AddObjectRef(m, "UnaryOp", state->UnaryOp_type) < 0) {
  12584. return -1;
  12585. }
  12586. if (PyModule_AddObjectRef(m, "Lambda", state->Lambda_type) < 0) {
  12587. return -1;
  12588. }
  12589. if (PyModule_AddObjectRef(m, "IfExp", state->IfExp_type) < 0) {
  12590. return -1;
  12591. }
  12592. if (PyModule_AddObjectRef(m, "Dict", state->Dict_type) < 0) {
  12593. return -1;
  12594. }
  12595. if (PyModule_AddObjectRef(m, "Set", state->Set_type) < 0) {
  12596. return -1;
  12597. }
  12598. if (PyModule_AddObjectRef(m, "ListComp", state->ListComp_type) < 0) {
  12599. return -1;
  12600. }
  12601. if (PyModule_AddObjectRef(m, "SetComp", state->SetComp_type) < 0) {
  12602. return -1;
  12603. }
  12604. if (PyModule_AddObjectRef(m, "DictComp", state->DictComp_type) < 0) {
  12605. return -1;
  12606. }
  12607. if (PyModule_AddObjectRef(m, "GeneratorExp", state->GeneratorExp_type) < 0)
  12608. {
  12609. return -1;
  12610. }
  12611. if (PyModule_AddObjectRef(m, "Await", state->Await_type) < 0) {
  12612. return -1;
  12613. }
  12614. if (PyModule_AddObjectRef(m, "Yield", state->Yield_type) < 0) {
  12615. return -1;
  12616. }
  12617. if (PyModule_AddObjectRef(m, "YieldFrom", state->YieldFrom_type) < 0) {
  12618. return -1;
  12619. }
  12620. if (PyModule_AddObjectRef(m, "Compare", state->Compare_type) < 0) {
  12621. return -1;
  12622. }
  12623. if (PyModule_AddObjectRef(m, "Call", state->Call_type) < 0) {
  12624. return -1;
  12625. }
  12626. if (PyModule_AddObjectRef(m, "FormattedValue", state->FormattedValue_type)
  12627. < 0) {
  12628. return -1;
  12629. }
  12630. if (PyModule_AddObjectRef(m, "JoinedStr", state->JoinedStr_type) < 0) {
  12631. return -1;
  12632. }
  12633. if (PyModule_AddObjectRef(m, "Constant", state->Constant_type) < 0) {
  12634. return -1;
  12635. }
  12636. if (PyModule_AddObjectRef(m, "Attribute", state->Attribute_type) < 0) {
  12637. return -1;
  12638. }
  12639. if (PyModule_AddObjectRef(m, "Subscript", state->Subscript_type) < 0) {
  12640. return -1;
  12641. }
  12642. if (PyModule_AddObjectRef(m, "Starred", state->Starred_type) < 0) {
  12643. return -1;
  12644. }
  12645. if (PyModule_AddObjectRef(m, "Name", state->Name_type) < 0) {
  12646. return -1;
  12647. }
  12648. if (PyModule_AddObjectRef(m, "List", state->List_type) < 0) {
  12649. return -1;
  12650. }
  12651. if (PyModule_AddObjectRef(m, "Tuple", state->Tuple_type) < 0) {
  12652. return -1;
  12653. }
  12654. if (PyModule_AddObjectRef(m, "Slice", state->Slice_type) < 0) {
  12655. return -1;
  12656. }
  12657. if (PyModule_AddObjectRef(m, "expr_context", state->expr_context_type) < 0)
  12658. {
  12659. return -1;
  12660. }
  12661. if (PyModule_AddObjectRef(m, "Load", state->Load_type) < 0) {
  12662. return -1;
  12663. }
  12664. if (PyModule_AddObjectRef(m, "Store", state->Store_type) < 0) {
  12665. return -1;
  12666. }
  12667. if (PyModule_AddObjectRef(m, "Del", state->Del_type) < 0) {
  12668. return -1;
  12669. }
  12670. if (PyModule_AddObjectRef(m, "boolop", state->boolop_type) < 0) {
  12671. return -1;
  12672. }
  12673. if (PyModule_AddObjectRef(m, "And", state->And_type) < 0) {
  12674. return -1;
  12675. }
  12676. if (PyModule_AddObjectRef(m, "Or", state->Or_type) < 0) {
  12677. return -1;
  12678. }
  12679. if (PyModule_AddObjectRef(m, "operator", state->operator_type) < 0) {
  12680. return -1;
  12681. }
  12682. if (PyModule_AddObjectRef(m, "Add", state->Add_type) < 0) {
  12683. return -1;
  12684. }
  12685. if (PyModule_AddObjectRef(m, "Sub", state->Sub_type) < 0) {
  12686. return -1;
  12687. }
  12688. if (PyModule_AddObjectRef(m, "Mult", state->Mult_type) < 0) {
  12689. return -1;
  12690. }
  12691. if (PyModule_AddObjectRef(m, "MatMult", state->MatMult_type) < 0) {
  12692. return -1;
  12693. }
  12694. if (PyModule_AddObjectRef(m, "Div", state->Div_type) < 0) {
  12695. return -1;
  12696. }
  12697. if (PyModule_AddObjectRef(m, "Mod", state->Mod_type) < 0) {
  12698. return -1;
  12699. }
  12700. if (PyModule_AddObjectRef(m, "Pow", state->Pow_type) < 0) {
  12701. return -1;
  12702. }
  12703. if (PyModule_AddObjectRef(m, "LShift", state->LShift_type) < 0) {
  12704. return -1;
  12705. }
  12706. if (PyModule_AddObjectRef(m, "RShift", state->RShift_type) < 0) {
  12707. return -1;
  12708. }
  12709. if (PyModule_AddObjectRef(m, "BitOr", state->BitOr_type) < 0) {
  12710. return -1;
  12711. }
  12712. if (PyModule_AddObjectRef(m, "BitXor", state->BitXor_type) < 0) {
  12713. return -1;
  12714. }
  12715. if (PyModule_AddObjectRef(m, "BitAnd", state->BitAnd_type) < 0) {
  12716. return -1;
  12717. }
  12718. if (PyModule_AddObjectRef(m, "FloorDiv", state->FloorDiv_type) < 0) {
  12719. return -1;
  12720. }
  12721. if (PyModule_AddObjectRef(m, "unaryop", state->unaryop_type) < 0) {
  12722. return -1;
  12723. }
  12724. if (PyModule_AddObjectRef(m, "Invert", state->Invert_type) < 0) {
  12725. return -1;
  12726. }
  12727. if (PyModule_AddObjectRef(m, "Not", state->Not_type) < 0) {
  12728. return -1;
  12729. }
  12730. if (PyModule_AddObjectRef(m, "UAdd", state->UAdd_type) < 0) {
  12731. return -1;
  12732. }
  12733. if (PyModule_AddObjectRef(m, "USub", state->USub_type) < 0) {
  12734. return -1;
  12735. }
  12736. if (PyModule_AddObjectRef(m, "cmpop", state->cmpop_type) < 0) {
  12737. return -1;
  12738. }
  12739. if (PyModule_AddObjectRef(m, "Eq", state->Eq_type) < 0) {
  12740. return -1;
  12741. }
  12742. if (PyModule_AddObjectRef(m, "NotEq", state->NotEq_type) < 0) {
  12743. return -1;
  12744. }
  12745. if (PyModule_AddObjectRef(m, "Lt", state->Lt_type) < 0) {
  12746. return -1;
  12747. }
  12748. if (PyModule_AddObjectRef(m, "LtE", state->LtE_type) < 0) {
  12749. return -1;
  12750. }
  12751. if (PyModule_AddObjectRef(m, "Gt", state->Gt_type) < 0) {
  12752. return -1;
  12753. }
  12754. if (PyModule_AddObjectRef(m, "GtE", state->GtE_type) < 0) {
  12755. return -1;
  12756. }
  12757. if (PyModule_AddObjectRef(m, "Is", state->Is_type) < 0) {
  12758. return -1;
  12759. }
  12760. if (PyModule_AddObjectRef(m, "IsNot", state->IsNot_type) < 0) {
  12761. return -1;
  12762. }
  12763. if (PyModule_AddObjectRef(m, "In", state->In_type) < 0) {
  12764. return -1;
  12765. }
  12766. if (PyModule_AddObjectRef(m, "NotIn", state->NotIn_type) < 0) {
  12767. return -1;
  12768. }
  12769. if (PyModule_AddObjectRef(m, "comprehension", state->comprehension_type) <
  12770. 0) {
  12771. return -1;
  12772. }
  12773. if (PyModule_AddObjectRef(m, "excepthandler", state->excepthandler_type) <
  12774. 0) {
  12775. return -1;
  12776. }
  12777. if (PyModule_AddObjectRef(m, "ExceptHandler", state->ExceptHandler_type) <
  12778. 0) {
  12779. return -1;
  12780. }
  12781. if (PyModule_AddObjectRef(m, "arguments", state->arguments_type) < 0) {
  12782. return -1;
  12783. }
  12784. if (PyModule_AddObjectRef(m, "arg", state->arg_type) < 0) {
  12785. return -1;
  12786. }
  12787. if (PyModule_AddObjectRef(m, "keyword", state->keyword_type) < 0) {
  12788. return -1;
  12789. }
  12790. if (PyModule_AddObjectRef(m, "alias", state->alias_type) < 0) {
  12791. return -1;
  12792. }
  12793. if (PyModule_AddObjectRef(m, "withitem", state->withitem_type) < 0) {
  12794. return -1;
  12795. }
  12796. if (PyModule_AddObjectRef(m, "match_case", state->match_case_type) < 0) {
  12797. return -1;
  12798. }
  12799. if (PyModule_AddObjectRef(m, "pattern", state->pattern_type) < 0) {
  12800. return -1;
  12801. }
  12802. if (PyModule_AddObjectRef(m, "MatchValue", state->MatchValue_type) < 0) {
  12803. return -1;
  12804. }
  12805. if (PyModule_AddObjectRef(m, "MatchSingleton", state->MatchSingleton_type)
  12806. < 0) {
  12807. return -1;
  12808. }
  12809. if (PyModule_AddObjectRef(m, "MatchSequence", state->MatchSequence_type) <
  12810. 0) {
  12811. return -1;
  12812. }
  12813. if (PyModule_AddObjectRef(m, "MatchMapping", state->MatchMapping_type) < 0)
  12814. {
  12815. return -1;
  12816. }
  12817. if (PyModule_AddObjectRef(m, "MatchClass", state->MatchClass_type) < 0) {
  12818. return -1;
  12819. }
  12820. if (PyModule_AddObjectRef(m, "MatchStar", state->MatchStar_type) < 0) {
  12821. return -1;
  12822. }
  12823. if (PyModule_AddObjectRef(m, "MatchAs", state->MatchAs_type) < 0) {
  12824. return -1;
  12825. }
  12826. if (PyModule_AddObjectRef(m, "MatchOr", state->MatchOr_type) < 0) {
  12827. return -1;
  12828. }
  12829. if (PyModule_AddObjectRef(m, "type_ignore", state->type_ignore_type) < 0) {
  12830. return -1;
  12831. }
  12832. if (PyModule_AddObjectRef(m, "TypeIgnore", state->TypeIgnore_type) < 0) {
  12833. return -1;
  12834. }
  12835. if (PyModule_AddObjectRef(m, "type_param", state->type_param_type) < 0) {
  12836. return -1;
  12837. }
  12838. if (PyModule_AddObjectRef(m, "TypeVar", state->TypeVar_type) < 0) {
  12839. return -1;
  12840. }
  12841. if (PyModule_AddObjectRef(m, "ParamSpec", state->ParamSpec_type) < 0) {
  12842. return -1;
  12843. }
  12844. if (PyModule_AddObjectRef(m, "TypeVarTuple", state->TypeVarTuple_type) < 0)
  12845. {
  12846. return -1;
  12847. }
  12848. return 0;
  12849. }
  12850. static PyModuleDef_Slot astmodule_slots[] = {
  12851. {Py_mod_exec, astmodule_exec},
  12852. {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
  12853. {0, NULL}
  12854. };
  12855. static struct PyModuleDef _astmodule = {
  12856. PyModuleDef_HEAD_INIT,
  12857. .m_name = "_ast",
  12858. // The _ast module uses a per-interpreter state (PyInterpreterState.ast)
  12859. .m_size = 0,
  12860. .m_slots = astmodule_slots,
  12861. };
  12862. PyMODINIT_FUNC
  12863. PyInit__ast(void)
  12864. {
  12865. return PyModuleDef_Init(&_astmodule);
  12866. }
  12867. PyObject* PyAST_mod2obj(mod_ty t)
  12868. {
  12869. struct ast_state *state = get_ast_state();
  12870. if (state == NULL) {
  12871. return NULL;
  12872. }
  12873. int starting_recursion_depth;
  12874. /* Be careful here to prevent overflow. */
  12875. PyThreadState *tstate = _PyThreadState_GET();
  12876. if (!tstate) {
  12877. return NULL;
  12878. }
  12879. struct validator vstate;
  12880. vstate.recursion_limit = C_RECURSION_LIMIT;
  12881. int recursion_depth = C_RECURSION_LIMIT - tstate->c_recursion_remaining;
  12882. starting_recursion_depth = recursion_depth;
  12883. vstate.recursion_depth = starting_recursion_depth;
  12884. PyObject *result = ast2obj_mod(state, &vstate, t);
  12885. /* Check that the recursion depth counting balanced correctly */
  12886. if (result && vstate.recursion_depth != starting_recursion_depth) {
  12887. PyErr_Format(PyExc_SystemError,
  12888. "AST constructor recursion depth mismatch (before=%d, after=%d)",
  12889. starting_recursion_depth, vstate.recursion_depth);
  12890. return NULL;
  12891. }
  12892. return result;
  12893. }
  12894. /* mode is 0 for "exec", 1 for "eval" and 2 for "single" input */
  12895. mod_ty PyAST_obj2mod(PyObject* ast, PyArena* arena, int mode)
  12896. {
  12897. const char * const req_name[] = {"Module", "Expression", "Interactive"};
  12898. int isinstance;
  12899. if (PySys_Audit("compile", "OO", ast, Py_None) < 0) {
  12900. return NULL;
  12901. }
  12902. struct ast_state *state = get_ast_state();
  12903. if (state == NULL) {
  12904. return NULL;
  12905. }
  12906. PyObject *req_type[3];
  12907. req_type[0] = state->Module_type;
  12908. req_type[1] = state->Expression_type;
  12909. req_type[2] = state->Interactive_type;
  12910. assert(0 <= mode && mode <= 2);
  12911. isinstance = PyObject_IsInstance(ast, req_type[mode]);
  12912. if (isinstance == -1)
  12913. return NULL;
  12914. if (!isinstance) {
  12915. PyErr_Format(PyExc_TypeError, "expected %s node, got %.400s",
  12916. req_name[mode], _PyType_Name(Py_TYPE(ast)));
  12917. return NULL;
  12918. }
  12919. mod_ty res = NULL;
  12920. if (obj2ast_mod(state, ast, &res, arena) != 0)
  12921. return NULL;
  12922. else
  12923. return res;
  12924. }
  12925. int PyAST_Check(PyObject* obj)
  12926. {
  12927. struct ast_state *state = get_ast_state();
  12928. if (state == NULL) {
  12929. return -1;
  12930. }
  12931. return PyObject_IsInstance(obj, state->AST_type);
  12932. }