12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875 |
- //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
- //
- // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
- // See https://llvm.org/LICENSE.txt for license information.
- // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- //===----------------------------------------------------------------------===//
- //
- // This file implements a semantic tree transformation that takes a given
- // AST and rebuilds it, possibly transforming some nodes in the process.
- //
- //===----------------------------------------------------------------------===//
- #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
- #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
- #include "CoroutineStmtBuilder.h"
- #include "TypeLocBuilder.h"
- #include "clang/AST/Decl.h"
- #include "clang/AST/DeclObjC.h"
- #include "clang/AST/DeclTemplate.h"
- #include "clang/AST/Expr.h"
- #include "clang/AST/ExprConcepts.h"
- #include "clang/AST/ExprCXX.h"
- #include "clang/AST/ExprObjC.h"
- #include "clang/AST/ExprOpenMP.h"
- #include "clang/AST/OpenMPClause.h"
- #include "clang/AST/Stmt.h"
- #include "clang/AST/StmtCXX.h"
- #include "clang/AST/StmtObjC.h"
- #include "clang/AST/StmtOpenMP.h"
- #include "clang/Basic/DiagnosticParse.h"
- #include "clang/Basic/OpenMPKinds.h"
- #include "clang/Sema/Designator.h"
- #include "clang/Sema/Lookup.h"
- #include "clang/Sema/Ownership.h"
- #include "clang/Sema/ParsedTemplate.h"
- #include "clang/Sema/ScopeInfo.h"
- #include "clang/Sema/SemaDiagnostic.h"
- #include "clang/Sema/SemaInternal.h"
- #include "llvm/ADT/ArrayRef.h"
- #include "llvm/Support/ErrorHandling.h"
- #include <algorithm>
- using namespace llvm::omp;
- namespace clang {
- using namespace sema;
- /// A semantic tree transformation that allows one to transform one
- /// abstract syntax tree into another.
- ///
- /// A new tree transformation is defined by creating a new subclass \c X of
- /// \c TreeTransform<X> and then overriding certain operations to provide
- /// behavior specific to that transformation. For example, template
- /// instantiation is implemented as a tree transformation where the
- /// transformation of TemplateTypeParmType nodes involves substituting the
- /// template arguments for their corresponding template parameters; a similar
- /// transformation is performed for non-type template parameters and
- /// template template parameters.
- ///
- /// This tree-transformation template uses static polymorphism to allow
- /// subclasses to customize any of its operations. Thus, a subclass can
- /// override any of the transformation or rebuild operators by providing an
- /// operation with the same signature as the default implementation. The
- /// overriding function should not be virtual.
- ///
- /// Semantic tree transformations are split into two stages, either of which
- /// can be replaced by a subclass. The "transform" step transforms an AST node
- /// or the parts of an AST node using the various transformation functions,
- /// then passes the pieces on to the "rebuild" step, which constructs a new AST
- /// node of the appropriate kind from the pieces. The default transformation
- /// routines recursively transform the operands to composite AST nodes (e.g.,
- /// the pointee type of a PointerType node) and, if any of those operand nodes
- /// were changed by the transformation, invokes the rebuild operation to create
- /// a new AST node.
- ///
- /// Subclasses can customize the transformation at various levels. The
- /// most coarse-grained transformations involve replacing TransformType(),
- /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
- /// TransformTemplateName(), or TransformTemplateArgument() with entirely
- /// new implementations.
- ///
- /// For more fine-grained transformations, subclasses can replace any of the
- /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
- /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
- /// replacing TransformTemplateTypeParmType() allows template instantiation
- /// to substitute template arguments for their corresponding template
- /// parameters. Additionally, subclasses can override the \c RebuildXXX
- /// functions to control how AST nodes are rebuilt when their operands change.
- /// By default, \c TreeTransform will invoke semantic analysis to rebuild
- /// AST nodes. However, certain other tree transformations (e.g, cloning) may
- /// be able to use more efficient rebuild steps.
- ///
- /// There are a handful of other functions that can be overridden, allowing one
- /// to avoid traversing nodes that don't need any transformation
- /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
- /// operands have not changed (\c AlwaysRebuild()), and customize the
- /// default locations and entity names used for type-checking
- /// (\c getBaseLocation(), \c getBaseEntity()).
- template<typename Derived>
- class TreeTransform {
- /// Private RAII object that helps us forget and then re-remember
- /// the template argument corresponding to a partially-substituted parameter
- /// pack.
- class ForgetPartiallySubstitutedPackRAII {
- Derived &Self;
- TemplateArgument Old;
- public:
- ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
- Old = Self.ForgetPartiallySubstitutedPack();
- }
- ~ForgetPartiallySubstitutedPackRAII() {
- Self.RememberPartiallySubstitutedPack(Old);
- }
- };
- protected:
- Sema &SemaRef;
- /// The set of local declarations that have been transformed, for
- /// cases where we are forced to build new declarations within the transformer
- /// rather than in the subclass (e.g., lambda closure types).
- llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
- public:
- /// Initializes a new tree transformer.
- TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
- /// Retrieves a reference to the derived class.
- Derived &getDerived() { return static_cast<Derived&>(*this); }
- /// Retrieves a reference to the derived class.
- const Derived &getDerived() const {
- return static_cast<const Derived&>(*this);
- }
- static inline ExprResult Owned(Expr *E) { return E; }
- static inline StmtResult Owned(Stmt *S) { return S; }
- /// Retrieves a reference to the semantic analysis object used for
- /// this tree transform.
- Sema &getSema() const { return SemaRef; }
- /// Whether the transformation should always rebuild AST nodes, even
- /// if none of the children have changed.
- ///
- /// Subclasses may override this function to specify when the transformation
- /// should rebuild all AST nodes.
- ///
- /// We must always rebuild all AST nodes when performing variadic template
- /// pack expansion, in order to avoid violating the AST invariant that each
- /// statement node appears at most once in its containing declaration.
- bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
- /// Whether the transformation is forming an expression or statement that
- /// replaces the original. In this case, we'll reuse mangling numbers from
- /// existing lambdas.
- bool ReplacingOriginal() { return false; }
- /// Wether CXXConstructExpr can be skipped when they are implicit.
- /// They will be reconstructed when used if needed.
- /// This is useful when the user that cause rebuilding of the
- /// CXXConstructExpr is outside of the expression at which the TreeTransform
- /// started.
- bool AllowSkippingCXXConstructExpr() { return true; }
- /// Returns the location of the entity being transformed, if that
- /// information was not available elsewhere in the AST.
- ///
- /// By default, returns no source-location information. Subclasses can
- /// provide an alternative implementation that provides better location
- /// information.
- SourceLocation getBaseLocation() { return SourceLocation(); }
- /// Returns the name of the entity being transformed, if that
- /// information was not available elsewhere in the AST.
- ///
- /// By default, returns an empty name. Subclasses can provide an alternative
- /// implementation with a more precise name.
- DeclarationName getBaseEntity() { return DeclarationName(); }
- /// Sets the "base" location and entity when that
- /// information is known based on another transformation.
- ///
- /// By default, the source location and entity are ignored. Subclasses can
- /// override this function to provide a customized implementation.
- void setBase(SourceLocation Loc, DeclarationName Entity) { }
- /// RAII object that temporarily sets the base location and entity
- /// used for reporting diagnostics in types.
- class TemporaryBase {
- TreeTransform &Self;
- SourceLocation OldLocation;
- DeclarationName OldEntity;
- public:
- TemporaryBase(TreeTransform &Self, SourceLocation Location,
- DeclarationName Entity) : Self(Self) {
- OldLocation = Self.getDerived().getBaseLocation();
- OldEntity = Self.getDerived().getBaseEntity();
- if (Location.isValid())
- Self.getDerived().setBase(Location, Entity);
- }
- ~TemporaryBase() {
- Self.getDerived().setBase(OldLocation, OldEntity);
- }
- };
- /// Determine whether the given type \p T has already been
- /// transformed.
- ///
- /// Subclasses can provide an alternative implementation of this routine
- /// to short-circuit evaluation when it is known that a given type will
- /// not change. For example, template instantiation need not traverse
- /// non-dependent types.
- bool AlreadyTransformed(QualType T) {
- return T.isNull();
- }
- /// Transform a template parameter depth level.
- ///
- /// During a transformation that transforms template parameters, this maps
- /// an old template parameter depth to a new depth.
- unsigned TransformTemplateDepth(unsigned Depth) {
- return Depth;
- }
- /// Determine whether the given call argument should be dropped, e.g.,
- /// because it is a default argument.
- ///
- /// Subclasses can provide an alternative implementation of this routine to
- /// determine which kinds of call arguments get dropped. By default,
- /// CXXDefaultArgument nodes are dropped (prior to transformation).
- bool DropCallArgument(Expr *E) {
- return E->isDefaultArgument();
- }
- /// Determine whether we should expand a pack expansion with the
- /// given set of parameter packs into separate arguments by repeatedly
- /// transforming the pattern.
- ///
- /// By default, the transformer never tries to expand pack expansions.
- /// Subclasses can override this routine to provide different behavior.
- ///
- /// \param EllipsisLoc The location of the ellipsis that identifies the
- /// pack expansion.
- ///
- /// \param PatternRange The source range that covers the entire pattern of
- /// the pack expansion.
- ///
- /// \param Unexpanded The set of unexpanded parameter packs within the
- /// pattern.
- ///
- /// \param ShouldExpand Will be set to \c true if the transformer should
- /// expand the corresponding pack expansions into separate arguments. When
- /// set, \c NumExpansions must also be set.
- ///
- /// \param RetainExpansion Whether the caller should add an unexpanded
- /// pack expansion after all of the expanded arguments. This is used
- /// when extending explicitly-specified template argument packs per
- /// C++0x [temp.arg.explicit]p9.
- ///
- /// \param NumExpansions The number of separate arguments that will be in
- /// the expanded form of the corresponding pack expansion. This is both an
- /// input and an output parameter, which can be set by the caller if the
- /// number of expansions is known a priori (e.g., due to a prior substitution)
- /// and will be set by the callee when the number of expansions is known.
- /// The callee must set this value when \c ShouldExpand is \c true; it may
- /// set this value in other cases.
- ///
- /// \returns true if an error occurred (e.g., because the parameter packs
- /// are to be instantiated with arguments of different lengths), false
- /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
- /// must be set.
- bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
- SourceRange PatternRange,
- ArrayRef<UnexpandedParameterPack> Unexpanded,
- bool &ShouldExpand,
- bool &RetainExpansion,
- Optional<unsigned> &NumExpansions) {
- ShouldExpand = false;
- return false;
- }
- /// "Forget" about the partially-substituted pack template argument,
- /// when performing an instantiation that must preserve the parameter pack
- /// use.
- ///
- /// This routine is meant to be overridden by the template instantiator.
- TemplateArgument ForgetPartiallySubstitutedPack() {
- return TemplateArgument();
- }
- /// "Remember" the partially-substituted pack template argument
- /// after performing an instantiation that must preserve the parameter pack
- /// use.
- ///
- /// This routine is meant to be overridden by the template instantiator.
- void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
- /// Note to the derived class when a function parameter pack is
- /// being expanded.
- void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
- /// Transforms the given type into another type.
- ///
- /// By default, this routine transforms a type by creating a
- /// TypeSourceInfo for it and delegating to the appropriate
- /// function. This is expensive, but we don't mind, because
- /// this method is deprecated anyway; all users should be
- /// switched to storing TypeSourceInfos.
- ///
- /// \returns the transformed type.
- QualType TransformType(QualType T);
- /// Transforms the given type-with-location into a new
- /// type-with-location.
- ///
- /// By default, this routine transforms a type by delegating to the
- /// appropriate TransformXXXType to build a new type. Subclasses
- /// may override this function (to take over all type
- /// transformations) or some set of the TransformXXXType functions
- /// to alter the transformation.
- TypeSourceInfo *TransformType(TypeSourceInfo *DI);
- /// Transform the given type-with-location into a new
- /// type, collecting location information in the given builder
- /// as necessary.
- ///
- QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
- /// Transform a type that is permitted to produce a
- /// DeducedTemplateSpecializationType.
- ///
- /// This is used in the (relatively rare) contexts where it is acceptable
- /// for transformation to produce a class template type with deduced
- /// template arguments.
- /// @{
- QualType TransformTypeWithDeducedTST(QualType T);
- TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
- /// @}
- /// The reason why the value of a statement is not discarded, if any.
- enum StmtDiscardKind {
- SDK_Discarded,
- SDK_NotDiscarded,
- SDK_StmtExprResult,
- };
- /// Transform the given statement.
- ///
- /// By default, this routine transforms a statement by delegating to the
- /// appropriate TransformXXXStmt function to transform a specific kind of
- /// statement or the TransformExpr() function to transform an expression.
- /// Subclasses may override this function to transform statements using some
- /// other mechanism.
- ///
- /// \returns the transformed statement.
- StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded);
- /// Transform the given statement.
- ///
- /// By default, this routine transforms a statement by delegating to the
- /// appropriate TransformOMPXXXClause function to transform a specific kind
- /// of clause. Subclasses may override this function to transform statements
- /// using some other mechanism.
- ///
- /// \returns the transformed OpenMP clause.
- OMPClause *TransformOMPClause(OMPClause *S);
- /// Transform the given attribute.
- ///
- /// By default, this routine transforms a statement by delegating to the
- /// appropriate TransformXXXAttr function to transform a specific kind
- /// of attribute. Subclasses may override this function to transform
- /// attributed statements using some other mechanism.
- ///
- /// \returns the transformed attribute
- const Attr *TransformAttr(const Attr *S);
- /// Transform the specified attribute.
- ///
- /// Subclasses should override the transformation of attributes with a pragma
- /// spelling to transform expressions stored within the attribute.
- ///
- /// \returns the transformed attribute.
- #define ATTR(X)
- #define PRAGMA_SPELLING_ATTR(X) \
- const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
- #include "clang/Basic/AttrList.inc"
- /// Transform the given expression.
- ///
- /// By default, this routine transforms an expression by delegating to the
- /// appropriate TransformXXXExpr function to build a new expression.
- /// Subclasses may override this function to transform expressions using some
- /// other mechanism.
- ///
- /// \returns the transformed expression.
- ExprResult TransformExpr(Expr *E);
- /// Transform the given initializer.
- ///
- /// By default, this routine transforms an initializer by stripping off the
- /// semantic nodes added by initialization, then passing the result to
- /// TransformExpr or TransformExprs.
- ///
- /// \returns the transformed initializer.
- ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
- /// Transform the given list of expressions.
- ///
- /// This routine transforms a list of expressions by invoking
- /// \c TransformExpr() for each subexpression. However, it also provides
- /// support for variadic templates by expanding any pack expansions (if the
- /// derived class permits such expansion) along the way. When pack expansions
- /// are present, the number of outputs may not equal the number of inputs.
- ///
- /// \param Inputs The set of expressions to be transformed.
- ///
- /// \param NumInputs The number of expressions in \c Inputs.
- ///
- /// \param IsCall If \c true, then this transform is being performed on
- /// function-call arguments, and any arguments that should be dropped, will
- /// be.
- ///
- /// \param Outputs The transformed input expressions will be added to this
- /// vector.
- ///
- /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
- /// due to transformation.
- ///
- /// \returns true if an error occurred, false otherwise.
- bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
- SmallVectorImpl<Expr *> &Outputs,
- bool *ArgChanged = nullptr);
- /// Transform the given declaration, which is referenced from a type
- /// or expression.
- ///
- /// By default, acts as the identity function on declarations, unless the
- /// transformer has had to transform the declaration itself. Subclasses
- /// may override this function to provide alternate behavior.
- Decl *TransformDecl(SourceLocation Loc, Decl *D) {
- llvm::DenseMap<Decl *, Decl *>::iterator Known
- = TransformedLocalDecls.find(D);
- if (Known != TransformedLocalDecls.end())
- return Known->second;
- return D;
- }
- /// Transform the specified condition.
- ///
- /// By default, this transforms the variable and expression and rebuilds
- /// the condition.
- Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
- Expr *Expr,
- Sema::ConditionKind Kind);
- /// Transform the attributes associated with the given declaration and
- /// place them on the new declaration.
- ///
- /// By default, this operation does nothing. Subclasses may override this
- /// behavior to transform attributes.
- void transformAttrs(Decl *Old, Decl *New) { }
- /// Note that a local declaration has been transformed by this
- /// transformer.
- ///
- /// Local declarations are typically transformed via a call to
- /// TransformDefinition. However, in some cases (e.g., lambda expressions),
- /// the transformer itself has to transform the declarations. This routine
- /// can be overridden by a subclass that keeps track of such mappings.
- void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) {
- assert(New.size() == 1 &&
- "must override transformedLocalDecl if performing pack expansion");
- TransformedLocalDecls[Old] = New.front();
- }
- /// Transform the definition of the given declaration.
- ///
- /// By default, invokes TransformDecl() to transform the declaration.
- /// Subclasses may override this function to provide alternate behavior.
- Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
- return getDerived().TransformDecl(Loc, D);
- }
- /// Transform the given declaration, which was the first part of a
- /// nested-name-specifier in a member access expression.
- ///
- /// This specific declaration transformation only applies to the first
- /// identifier in a nested-name-specifier of a member access expression, e.g.,
- /// the \c T in \c x->T::member
- ///
- /// By default, invokes TransformDecl() to transform the declaration.
- /// Subclasses may override this function to provide alternate behavior.
- NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
- return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
- }
- /// Transform the set of declarations in an OverloadExpr.
- bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
- LookupResult &R);
- /// Transform the given nested-name-specifier with source-location
- /// information.
- ///
- /// By default, transforms all of the types and declarations within the
- /// nested-name-specifier. Subclasses may override this function to provide
- /// alternate behavior.
- NestedNameSpecifierLoc
- TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
- QualType ObjectType = QualType(),
- NamedDecl *FirstQualifierInScope = nullptr);
- /// Transform the given declaration name.
- ///
- /// By default, transforms the types of conversion function, constructor,
- /// and destructor names and then (if needed) rebuilds the declaration name.
- /// Identifiers and selectors are returned unmodified. Subclasses may
- /// override this function to provide alternate behavior.
- DeclarationNameInfo
- TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
- bool TransformRequiresExprRequirements(ArrayRef<concepts::Requirement *> Reqs,
- llvm::SmallVectorImpl<concepts::Requirement *> &Transformed);
- concepts::TypeRequirement *
- TransformTypeRequirement(concepts::TypeRequirement *Req);
- concepts::ExprRequirement *
- TransformExprRequirement(concepts::ExprRequirement *Req);
- concepts::NestedRequirement *
- TransformNestedRequirement(concepts::NestedRequirement *Req);
- /// Transform the given template name.
- ///
- /// \param SS The nested-name-specifier that qualifies the template
- /// name. This nested-name-specifier must already have been transformed.
- ///
- /// \param Name The template name to transform.
- ///
- /// \param NameLoc The source location of the template name.
- ///
- /// \param ObjectType If we're translating a template name within a member
- /// access expression, this is the type of the object whose member template
- /// is being referenced.
- ///
- /// \param FirstQualifierInScope If the first part of a nested-name-specifier
- /// also refers to a name within the current (lexical) scope, this is the
- /// declaration it refers to.
- ///
- /// By default, transforms the template name by transforming the declarations
- /// and nested-name-specifiers that occur within the template name.
- /// Subclasses may override this function to provide alternate behavior.
- TemplateName
- TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
- SourceLocation NameLoc,
- QualType ObjectType = QualType(),
- NamedDecl *FirstQualifierInScope = nullptr,
- bool AllowInjectedClassName = false);
- /// Transform the given template argument.
- ///
- /// By default, this operation transforms the type, expression, or
- /// declaration stored within the template argument and constructs a
- /// new template argument from the transformed result. Subclasses may
- /// override this function to provide alternate behavior.
- ///
- /// Returns true if there was an error.
- bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
- TemplateArgumentLoc &Output,
- bool Uneval = false);
- /// Transform the given set of template arguments.
- ///
- /// By default, this operation transforms all of the template arguments
- /// in the input set using \c TransformTemplateArgument(), and appends
- /// the transformed arguments to the output list.
- ///
- /// Note that this overload of \c TransformTemplateArguments() is merely
- /// a convenience function. Subclasses that wish to override this behavior
- /// should override the iterator-based member template version.
- ///
- /// \param Inputs The set of template arguments to be transformed.
- ///
- /// \param NumInputs The number of template arguments in \p Inputs.
- ///
- /// \param Outputs The set of transformed template arguments output by this
- /// routine.
- ///
- /// Returns true if an error occurred.
- bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
- unsigned NumInputs,
- TemplateArgumentListInfo &Outputs,
- bool Uneval = false) {
- return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
- Uneval);
- }
- /// Transform the given set of template arguments.
- ///
- /// By default, this operation transforms all of the template arguments
- /// in the input set using \c TransformTemplateArgument(), and appends
- /// the transformed arguments to the output list.
- ///
- /// \param First An iterator to the first template argument.
- ///
- /// \param Last An iterator one step past the last template argument.
- ///
- /// \param Outputs The set of transformed template arguments output by this
- /// routine.
- ///
- /// Returns true if an error occurred.
- template<typename InputIterator>
- bool TransformTemplateArguments(InputIterator First,
- InputIterator Last,
- TemplateArgumentListInfo &Outputs,
- bool Uneval = false);
- /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
- void InventTemplateArgumentLoc(const TemplateArgument &Arg,
- TemplateArgumentLoc &ArgLoc);
- /// Fakes up a TypeSourceInfo for a type.
- TypeSourceInfo *InventTypeSourceInfo(QualType T) {
- return SemaRef.Context.getTrivialTypeSourceInfo(T,
- getDerived().getBaseLocation());
- }
- #define ABSTRACT_TYPELOC(CLASS, PARENT)
- #define TYPELOC(CLASS, PARENT) \
- QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
- #include "clang/AST/TypeLocNodes.def"
- template<typename Fn>
- QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
- FunctionProtoTypeLoc TL,
- CXXRecordDecl *ThisContext,
- Qualifiers ThisTypeQuals,
- Fn TransformExceptionSpec);
- bool TransformExceptionSpec(SourceLocation Loc,
- FunctionProtoType::ExceptionSpecInfo &ESI,
- SmallVectorImpl<QualType> &Exceptions,
- bool &Changed);
- StmtResult TransformSEHHandler(Stmt *Handler);
- QualType
- TransformTemplateSpecializationType(TypeLocBuilder &TLB,
- TemplateSpecializationTypeLoc TL,
- TemplateName Template);
- QualType
- TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
- DependentTemplateSpecializationTypeLoc TL,
- TemplateName Template,
- CXXScopeSpec &SS);
- QualType TransformDependentTemplateSpecializationType(
- TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
- NestedNameSpecifierLoc QualifierLoc);
- /// Transforms the parameters of a function type into the
- /// given vectors.
- ///
- /// The result vectors should be kept in sync; null entries in the
- /// variables vector are acceptable.
- ///
- /// Return true on error.
- bool TransformFunctionTypeParams(
- SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
- const QualType *ParamTypes,
- const FunctionProtoType::ExtParameterInfo *ParamInfos,
- SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
- Sema::ExtParameterInfoBuilder &PInfos);
- /// Transforms a single function-type parameter. Return null
- /// on error.
- ///
- /// \param indexAdjustment - A number to add to the parameter's
- /// scope index; can be negative
- ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
- int indexAdjustment,
- Optional<unsigned> NumExpansions,
- bool ExpectParameterPack);
- /// Transform the body of a lambda-expression.
- StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body);
- /// Alternative implementation of TransformLambdaBody that skips transforming
- /// the body.
- StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
- QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
- StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
- ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
- TemplateParameterList *TransformTemplateParameterList(
- TemplateParameterList *TPL) {
- return TPL;
- }
- ExprResult TransformAddressOfOperand(Expr *E);
- ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
- bool IsAddressOfOperand,
- TypeSourceInfo **RecoveryTSI);
- ExprResult TransformParenDependentScopeDeclRefExpr(
- ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
- TypeSourceInfo **RecoveryTSI);
- StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
- // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
- // amount of stack usage with clang.
- #define STMT(Node, Parent) \
- LLVM_ATTRIBUTE_NOINLINE \
- StmtResult Transform##Node(Node *S);
- #define VALUESTMT(Node, Parent) \
- LLVM_ATTRIBUTE_NOINLINE \
- StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
- #define EXPR(Node, Parent) \
- LLVM_ATTRIBUTE_NOINLINE \
- ExprResult Transform##Node(Node *E);
- #define ABSTRACT_STMT(Stmt)
- #include "clang/AST/StmtNodes.inc"
- #define GEN_CLANG_CLAUSE_CLASS
- #define CLAUSE_CLASS(Enum, Str, Class) \
- LLVM_ATTRIBUTE_NOINLINE \
- OMPClause *Transform##Class(Class *S);
- #include "llvm/Frontend/OpenMP/OMP.inc"
- /// Build a new qualified type given its unqualified type and type location.
- ///
- /// By default, this routine adds type qualifiers only to types that can
- /// have qualifiers, and silently suppresses those qualifiers that are not
- /// permitted. Subclasses may override this routine to provide different
- /// behavior.
- QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
- /// Build a new pointer type given its pointee type.
- ///
- /// By default, performs semantic analysis when building the pointer type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
- /// Build a new block pointer type given its pointee type.
- ///
- /// By default, performs semantic analysis when building the block pointer
- /// type. Subclasses may override this routine to provide different behavior.
- QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
- /// Build a new reference type given the type it references.
- ///
- /// By default, performs semantic analysis when building the
- /// reference type. Subclasses may override this routine to provide
- /// different behavior.
- ///
- /// \param LValue whether the type was written with an lvalue sigil
- /// or an rvalue sigil.
- QualType RebuildReferenceType(QualType ReferentType,
- bool LValue,
- SourceLocation Sigil);
- /// Build a new member pointer type given the pointee type and the
- /// class type it refers into.
- ///
- /// By default, performs semantic analysis when building the member pointer
- /// type. Subclasses may override this routine to provide different behavior.
- QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
- SourceLocation Sigil);
- QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
- SourceLocation ProtocolLAngleLoc,
- ArrayRef<ObjCProtocolDecl *> Protocols,
- ArrayRef<SourceLocation> ProtocolLocs,
- SourceLocation ProtocolRAngleLoc);
- /// Build an Objective-C object type.
- ///
- /// By default, performs semantic analysis when building the object type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildObjCObjectType(QualType BaseType,
- SourceLocation Loc,
- SourceLocation TypeArgsLAngleLoc,
- ArrayRef<TypeSourceInfo *> TypeArgs,
- SourceLocation TypeArgsRAngleLoc,
- SourceLocation ProtocolLAngleLoc,
- ArrayRef<ObjCProtocolDecl *> Protocols,
- ArrayRef<SourceLocation> ProtocolLocs,
- SourceLocation ProtocolRAngleLoc);
- /// Build a new Objective-C object pointer type given the pointee type.
- ///
- /// By default, directly builds the pointer type, with no additional semantic
- /// analysis.
- QualType RebuildObjCObjectPointerType(QualType PointeeType,
- SourceLocation Star);
- /// Build a new array type given the element type, size
- /// modifier, size of the array (if known), size expression, and index type
- /// qualifiers.
- ///
- /// By default, performs semantic analysis when building the array type.
- /// Subclasses may override this routine to provide different behavior.
- /// Also by default, all of the other Rebuild*Array
- QualType RebuildArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- const llvm::APInt *Size,
- Expr *SizeExpr,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange);
- /// Build a new constant array type given the element type, size
- /// modifier, (known) size of the array, and index type qualifiers.
- ///
- /// By default, performs semantic analysis when building the array type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildConstantArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- const llvm::APInt &Size,
- Expr *SizeExpr,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange);
- /// Build a new incomplete array type given the element type, size
- /// modifier, and index type qualifiers.
- ///
- /// By default, performs semantic analysis when building the array type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildIncompleteArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange);
- /// Build a new variable-length array type given the element type,
- /// size modifier, size expression, and index type qualifiers.
- ///
- /// By default, performs semantic analysis when building the array type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildVariableArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- Expr *SizeExpr,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange);
- /// Build a new dependent-sized array type given the element type,
- /// size modifier, size expression, and index type qualifiers.
- ///
- /// By default, performs semantic analysis when building the array type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildDependentSizedArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- Expr *SizeExpr,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange);
- /// Build a new vector type given the element type and
- /// number of elements.
- ///
- /// By default, performs semantic analysis when building the vector type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
- VectorType::VectorKind VecKind);
- /// Build a new potentially dependently-sized extended vector type
- /// given the element type and number of elements.
- ///
- /// By default, performs semantic analysis when building the vector type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
- SourceLocation AttributeLoc,
- VectorType::VectorKind);
- /// Build a new extended vector type given the element type and
- /// number of elements.
- ///
- /// By default, performs semantic analysis when building the vector type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
- SourceLocation AttributeLoc);
- /// Build a new potentially dependently-sized extended vector type
- /// given the element type and number of elements.
- ///
- /// By default, performs semantic analysis when building the vector type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildDependentSizedExtVectorType(QualType ElementType,
- Expr *SizeExpr,
- SourceLocation AttributeLoc);
- /// Build a new matrix type given the element type and dimensions.
- QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
- unsigned NumColumns);
- /// Build a new matrix type given the type and dependently-defined
- /// dimensions.
- QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr,
- Expr *ColumnExpr,
- SourceLocation AttributeLoc);
- /// Build a new DependentAddressSpaceType or return the pointee
- /// type variable with the correct address space (retrieved from
- /// AddrSpaceExpr) applied to it. The former will be returned in cases
- /// where the address space remains dependent.
- ///
- /// By default, performs semantic analysis when building the type with address
- /// space applied. Subclasses may override this routine to provide different
- /// behavior.
- QualType RebuildDependentAddressSpaceType(QualType PointeeType,
- Expr *AddrSpaceExpr,
- SourceLocation AttributeLoc);
- /// Build a new function type.
- ///
- /// By default, performs semantic analysis when building the function type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildFunctionProtoType(QualType T,
- MutableArrayRef<QualType> ParamTypes,
- const FunctionProtoType::ExtProtoInfo &EPI);
- /// Build a new unprototyped function type.
- QualType RebuildFunctionNoProtoType(QualType ResultType);
- /// Rebuild an unresolved typename type, given the decl that
- /// the UnresolvedUsingTypenameDecl was transformed to.
- QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
- /// Build a new type found via an alias.
- QualType RebuildUsingType(UsingShadowDecl *Found, QualType Underlying) {
- return SemaRef.Context.getUsingType(Found, Underlying);
- }
- /// Build a new typedef type.
- QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
- return SemaRef.Context.getTypeDeclType(Typedef);
- }
- /// Build a new MacroDefined type.
- QualType RebuildMacroQualifiedType(QualType T,
- const IdentifierInfo *MacroII) {
- return SemaRef.Context.getMacroQualifiedType(T, MacroII);
- }
- /// Build a new class/struct/union type.
- QualType RebuildRecordType(RecordDecl *Record) {
- return SemaRef.Context.getTypeDeclType(Record);
- }
- /// Build a new Enum type.
- QualType RebuildEnumType(EnumDecl *Enum) {
- return SemaRef.Context.getTypeDeclType(Enum);
- }
- /// Build a new typeof(expr) type.
- ///
- /// By default, performs semantic analysis when building the typeof type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
- /// Build a new typeof(type) type.
- ///
- /// By default, builds a new TypeOfType with the given underlying type.
- QualType RebuildTypeOfType(QualType Underlying);
- /// Build a new unary transform type.
- QualType RebuildUnaryTransformType(QualType BaseType,
- UnaryTransformType::UTTKind UKind,
- SourceLocation Loc);
- /// Build a new C++11 decltype type.
- ///
- /// By default, performs semantic analysis when building the decltype type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
- /// Build a new C++11 auto type.
- ///
- /// By default, builds a new AutoType with the given deduced type.
- QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword,
- ConceptDecl *TypeConstraintConcept,
- ArrayRef<TemplateArgument> TypeConstraintArgs) {
- // Note, IsDependent is always false here: we implicitly convert an 'auto'
- // which has been deduced to a dependent type into an undeduced 'auto', so
- // that we'll retry deduction after the transformation.
- return SemaRef.Context.getAutoType(Deduced, Keyword,
- /*IsDependent*/ false, /*IsPack=*/false,
- TypeConstraintConcept,
- TypeConstraintArgs);
- }
- /// By default, builds a new DeducedTemplateSpecializationType with the given
- /// deduced type.
- QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
- QualType Deduced) {
- return SemaRef.Context.getDeducedTemplateSpecializationType(
- Template, Deduced, /*IsDependent*/ false);
- }
- /// Build a new template specialization type.
- ///
- /// By default, performs semantic analysis when building the template
- /// specialization type. Subclasses may override this routine to provide
- /// different behavior.
- QualType RebuildTemplateSpecializationType(TemplateName Template,
- SourceLocation TemplateLoc,
- TemplateArgumentListInfo &Args);
- /// Build a new parenthesized type.
- ///
- /// By default, builds a new ParenType type from the inner type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildParenType(QualType InnerType) {
- return SemaRef.BuildParenType(InnerType);
- }
- /// Build a new qualified name type.
- ///
- /// By default, builds a new ElaboratedType type from the keyword,
- /// the nested-name-specifier and the named type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildElaboratedType(SourceLocation KeywordLoc,
- ElaboratedTypeKeyword Keyword,
- NestedNameSpecifierLoc QualifierLoc,
- QualType Named) {
- return SemaRef.Context.getElaboratedType(Keyword,
- QualifierLoc.getNestedNameSpecifier(),
- Named);
- }
- /// Build a new typename type that refers to a template-id.
- ///
- /// By default, builds a new DependentNameType type from the
- /// nested-name-specifier and the given type. Subclasses may override
- /// this routine to provide different behavior.
- QualType RebuildDependentTemplateSpecializationType(
- ElaboratedTypeKeyword Keyword,
- NestedNameSpecifierLoc QualifierLoc,
- SourceLocation TemplateKWLoc,
- const IdentifierInfo *Name,
- SourceLocation NameLoc,
- TemplateArgumentListInfo &Args,
- bool AllowInjectedClassName) {
- // Rebuild the template name.
- // TODO: avoid TemplateName abstraction
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- TemplateName InstName = getDerived().RebuildTemplateName(
- SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
- AllowInjectedClassName);
- if (InstName.isNull())
- return QualType();
- // If it's still dependent, make a dependent specialization.
- if (InstName.getAsDependentTemplateName())
- return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
- QualifierLoc.getNestedNameSpecifier(),
- Name,
- Args);
- // Otherwise, make an elaborated type wrapping a non-dependent
- // specialization.
- QualType T =
- getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
- if (T.isNull()) return QualType();
- if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
- return T;
- return SemaRef.Context.getElaboratedType(Keyword,
- QualifierLoc.getNestedNameSpecifier(),
- T);
- }
- /// Build a new typename type that refers to an identifier.
- ///
- /// By default, performs semantic analysis when building the typename type
- /// (or elaborated type). Subclasses may override this routine to provide
- /// different behavior.
- QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
- SourceLocation KeywordLoc,
- NestedNameSpecifierLoc QualifierLoc,
- const IdentifierInfo *Id,
- SourceLocation IdLoc,
- bool DeducedTSTContext) {
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
- // If the name is still dependent, just build a new dependent name type.
- if (!SemaRef.computeDeclContext(SS))
- return SemaRef.Context.getDependentNameType(Keyword,
- QualifierLoc.getNestedNameSpecifier(),
- Id);
- }
- if (Keyword == ETK_None || Keyword == ETK_Typename) {
- return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
- *Id, IdLoc, DeducedTSTContext);
- }
- TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
- // We had a dependent elaborated-type-specifier that has been transformed
- // into a non-dependent elaborated-type-specifier. Find the tag we're
- // referring to.
- LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
- DeclContext *DC = SemaRef.computeDeclContext(SS, false);
- if (!DC)
- return QualType();
- if (SemaRef.RequireCompleteDeclContext(SS, DC))
- return QualType();
- TagDecl *Tag = nullptr;
- SemaRef.LookupQualifiedName(Result, DC);
- switch (Result.getResultKind()) {
- case LookupResult::NotFound:
- case LookupResult::NotFoundInCurrentInstantiation:
- break;
- case LookupResult::Found:
- Tag = Result.getAsSingle<TagDecl>();
- break;
- case LookupResult::FoundOverloaded:
- case LookupResult::FoundUnresolvedValue:
- llvm_unreachable("Tag lookup cannot find non-tags");
- case LookupResult::Ambiguous:
- // Let the LookupResult structure handle ambiguities.
- return QualType();
- }
- if (!Tag) {
- // Check where the name exists but isn't a tag type and use that to emit
- // better diagnostics.
- LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
- SemaRef.LookupQualifiedName(Result, DC);
- switch (Result.getResultKind()) {
- case LookupResult::Found:
- case LookupResult::FoundOverloaded:
- case LookupResult::FoundUnresolvedValue: {
- NamedDecl *SomeDecl = Result.getRepresentativeDecl();
- Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
- SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
- << NTK << Kind;
- SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
- break;
- }
- default:
- SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
- << Kind << Id << DC << QualifierLoc.getSourceRange();
- break;
- }
- return QualType();
- }
- if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
- IdLoc, Id)) {
- SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
- SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
- return QualType();
- }
- // Build the elaborated-type-specifier type.
- QualType T = SemaRef.Context.getTypeDeclType(Tag);
- return SemaRef.Context.getElaboratedType(Keyword,
- QualifierLoc.getNestedNameSpecifier(),
- T);
- }
- /// Build a new pack expansion type.
- ///
- /// By default, builds a new PackExpansionType type from the given pattern.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildPackExpansionType(QualType Pattern,
- SourceRange PatternRange,
- SourceLocation EllipsisLoc,
- Optional<unsigned> NumExpansions) {
- return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
- NumExpansions);
- }
- /// Build a new atomic type given its value type.
- ///
- /// By default, performs semantic analysis when building the atomic type.
- /// Subclasses may override this routine to provide different behavior.
- QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
- /// Build a new pipe type given its value type.
- QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
- bool isReadPipe);
- /// Build a bit-precise int given its value type.
- QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
- SourceLocation Loc);
- /// Build a dependent bit-precise int given its value type.
- QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
- SourceLocation Loc);
- /// Build a new template name given a nested name specifier, a flag
- /// indicating whether the "template" keyword was provided, and the template
- /// that the template name refers to.
- ///
- /// By default, builds the new template name directly. Subclasses may override
- /// this routine to provide different behavior.
- TemplateName RebuildTemplateName(CXXScopeSpec &SS,
- bool TemplateKW,
- TemplateDecl *Template);
- /// Build a new template name given a nested name specifier and the
- /// name that is referred to as a template.
- ///
- /// By default, performs semantic analysis to determine whether the name can
- /// be resolved to a specific template, then builds the appropriate kind of
- /// template name. Subclasses may override this routine to provide different
- /// behavior.
- TemplateName RebuildTemplateName(CXXScopeSpec &SS,
- SourceLocation TemplateKWLoc,
- const IdentifierInfo &Name,
- SourceLocation NameLoc, QualType ObjectType,
- NamedDecl *FirstQualifierInScope,
- bool AllowInjectedClassName);
- /// Build a new template name given a nested name specifier and the
- /// overloaded operator name that is referred to as a template.
- ///
- /// By default, performs semantic analysis to determine whether the name can
- /// be resolved to a specific template, then builds the appropriate kind of
- /// template name. Subclasses may override this routine to provide different
- /// behavior.
- TemplateName RebuildTemplateName(CXXScopeSpec &SS,
- SourceLocation TemplateKWLoc,
- OverloadedOperatorKind Operator,
- SourceLocation NameLoc, QualType ObjectType,
- bool AllowInjectedClassName);
- /// Build a new template name given a template template parameter pack
- /// and the
- ///
- /// By default, performs semantic analysis to determine whether the name can
- /// be resolved to a specific template, then builds the appropriate kind of
- /// template name. Subclasses may override this routine to provide different
- /// behavior.
- TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
- const TemplateArgument &ArgPack) {
- return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
- }
- /// Build a new compound statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
- MultiStmtArg Statements,
- SourceLocation RBraceLoc,
- bool IsStmtExpr) {
- return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
- IsStmtExpr);
- }
- /// Build a new case statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
- Expr *LHS,
- SourceLocation EllipsisLoc,
- Expr *RHS,
- SourceLocation ColonLoc) {
- return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
- ColonLoc);
- }
- /// Attach the body to a new case statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
- getSema().ActOnCaseStmtBody(S, Body);
- return S;
- }
- /// Build a new default statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
- SourceLocation ColonLoc,
- Stmt *SubStmt) {
- return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
- /*CurScope=*/nullptr);
- }
- /// Build a new label statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
- SourceLocation ColonLoc, Stmt *SubStmt) {
- return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
- }
- /// Build a new attributed statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
- ArrayRef<const Attr *> Attrs,
- Stmt *SubStmt) {
- return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
- }
- /// Build a new "if" statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind,
- SourceLocation LParenLoc, Sema::ConditionResult Cond,
- SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
- SourceLocation ElseLoc, Stmt *Else) {
- return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
- Then, ElseLoc, Else);
- }
- /// Start building a new switch statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
- SourceLocation LParenLoc, Stmt *Init,
- Sema::ConditionResult Cond,
- SourceLocation RParenLoc) {
- return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
- RParenLoc);
- }
- /// Attach the body to the switch statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
- Stmt *Switch, Stmt *Body) {
- return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
- }
- /// Build a new while statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc,
- Sema::ConditionResult Cond,
- SourceLocation RParenLoc, Stmt *Body) {
- return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
- }
- /// Build a new do-while statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
- SourceLocation WhileLoc, SourceLocation LParenLoc,
- Expr *Cond, SourceLocation RParenLoc) {
- return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
- Cond, RParenLoc);
- }
- /// Build a new for statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
- Stmt *Init, Sema::ConditionResult Cond,
- Sema::FullExprArg Inc, SourceLocation RParenLoc,
- Stmt *Body) {
- return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
- Inc, RParenLoc, Body);
- }
- /// Build a new goto statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
- LabelDecl *Label) {
- return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
- }
- /// Build a new indirect goto statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
- SourceLocation StarLoc,
- Expr *Target) {
- return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
- }
- /// Build a new return statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
- return getSema().BuildReturnStmt(ReturnLoc, Result);
- }
- /// Build a new declaration statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
- SourceLocation StartLoc, SourceLocation EndLoc) {
- Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
- return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
- }
- /// Build a new inline asm statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
- bool IsVolatile, unsigned NumOutputs,
- unsigned NumInputs, IdentifierInfo **Names,
- MultiExprArg Constraints, MultiExprArg Exprs,
- Expr *AsmString, MultiExprArg Clobbers,
- unsigned NumLabels,
- SourceLocation RParenLoc) {
- return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
- NumInputs, Names, Constraints, Exprs,
- AsmString, Clobbers, NumLabels, RParenLoc);
- }
- /// Build a new MS style inline asm statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
- ArrayRef<Token> AsmToks,
- StringRef AsmString,
- unsigned NumOutputs, unsigned NumInputs,
- ArrayRef<StringRef> Constraints,
- ArrayRef<StringRef> Clobbers,
- ArrayRef<Expr*> Exprs,
- SourceLocation EndLoc) {
- return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
- NumOutputs, NumInputs,
- Constraints, Clobbers, Exprs, EndLoc);
- }
- /// Build a new co_return statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
- bool IsImplicit) {
- return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
- }
- /// Build a new co_await expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
- bool IsImplicit) {
- return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
- }
- /// Build a new co_await expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
- Expr *Result,
- UnresolvedLookupExpr *Lookup) {
- return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
- }
- /// Build a new co_yield expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
- return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
- }
- StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
- return getSema().BuildCoroutineBodyStmt(Args);
- }
- /// Build a new Objective-C \@try statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
- Stmt *TryBody,
- MultiStmtArg CatchStmts,
- Stmt *Finally) {
- return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
- Finally);
- }
- /// Rebuild an Objective-C exception declaration.
- ///
- /// By default, performs semantic analysis to build the new declaration.
- /// Subclasses may override this routine to provide different behavior.
- VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
- TypeSourceInfo *TInfo, QualType T) {
- return getSema().BuildObjCExceptionDecl(TInfo, T,
- ExceptionDecl->getInnerLocStart(),
- ExceptionDecl->getLocation(),
- ExceptionDecl->getIdentifier());
- }
- /// Build a new Objective-C \@catch statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
- SourceLocation RParenLoc,
- VarDecl *Var,
- Stmt *Body) {
- return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
- Var, Body);
- }
- /// Build a new Objective-C \@finally statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
- Stmt *Body) {
- return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
- }
- /// Build a new Objective-C \@throw statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
- Expr *Operand) {
- return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
- }
- /// Build a new OpenMP Canonical loop.
- ///
- /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
- /// OMPCanonicalLoop.
- StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt) {
- return getSema().ActOnOpenMPCanonicalLoop(LoopStmt);
- }
- /// Build a new OpenMP executable directive.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
- DeclarationNameInfo DirName,
- OpenMPDirectiveKind CancelRegion,
- ArrayRef<OMPClause *> Clauses,
- Stmt *AStmt, SourceLocation StartLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPExecutableDirective(
- Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
- }
- /// Build a new OpenMP 'if' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
- Expr *Condition, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation NameModifierLoc,
- SourceLocation ColonLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
- LParenLoc, NameModifierLoc, ColonLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'final' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'num_threads' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
- LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'safelen' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'simdlen' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
- }
- OMPClause *RebuildOMPSizesClause(ArrayRef<Expr *> Sizes,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'full' clause.
- OMPClause *RebuildOMPFullClause(SourceLocation StartLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPFullClause(StartLoc, EndLoc);
- }
- /// Build a new OpenMP 'partial' clause.
- OMPClause *RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPPartialClause(Factor, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'allocator' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'collapse' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'default' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
- StartLoc, LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'proc_bind' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPProcBindClause(ProcBindKind Kind,
- SourceLocation KindKwLoc,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
- StartLoc, LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'schedule' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPScheduleClause(
- OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
- OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
- SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
- return getSema().ActOnOpenMPScheduleClause(
- M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
- CommaLoc, EndLoc);
- }
- /// Build a new OpenMP 'ordered' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
- SourceLocation EndLoc,
- SourceLocation LParenLoc, Expr *Num) {
- return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
- }
- /// Build a new OpenMP 'private' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'firstprivate' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'lastprivate' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
- OpenMPLastprivateModifier LPKind,
- SourceLocation LPKindLoc,
- SourceLocation ColonLoc,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPLastprivateClause(
- VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'shared' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'reduction' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPReductionClause(
- ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier,
- SourceLocation StartLoc, SourceLocation LParenLoc,
- SourceLocation ModifierLoc, SourceLocation ColonLoc,
- SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
- const DeclarationNameInfo &ReductionId,
- ArrayRef<Expr *> UnresolvedReductions) {
- return getSema().ActOnOpenMPReductionClause(
- VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
- ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
- }
- /// Build a new OpenMP 'task_reduction' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPTaskReductionClause(
- ArrayRef<Expr *> VarList, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
- CXXScopeSpec &ReductionIdScopeSpec,
- const DeclarationNameInfo &ReductionId,
- ArrayRef<Expr *> UnresolvedReductions) {
- return getSema().ActOnOpenMPTaskReductionClause(
- VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
- ReductionId, UnresolvedReductions);
- }
- /// Build a new OpenMP 'in_reduction' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *
- RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation ColonLoc,
- SourceLocation EndLoc,
- CXXScopeSpec &ReductionIdScopeSpec,
- const DeclarationNameInfo &ReductionId,
- ArrayRef<Expr *> UnresolvedReductions) {
- return getSema().ActOnOpenMPInReductionClause(
- VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
- ReductionId, UnresolvedReductions);
- }
- /// Build a new OpenMP 'linear' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- OpenMPLinearClauseKind Modifier,
- SourceLocation ModifierLoc,
- SourceLocation ColonLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
- Modifier, ModifierLoc, ColonLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'aligned' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation ColonLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
- LParenLoc, ColonLoc, EndLoc);
- }
- /// Build a new OpenMP 'copyin' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'copyprivate' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'flush' pseudo clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'depobj' pseudo clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'depend' pseudo clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *
- RebuildOMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind,
- SourceLocation DepLoc, SourceLocation ColonLoc,
- ArrayRef<Expr *> VarList, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation EndLoc) {
- return getSema().ActOnOpenMPDependClause(DepModifier, DepKind, DepLoc,
- ColonLoc, VarList, StartLoc,
- LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'device' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier,
- Expr *Device, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation ModifierLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc,
- LParenLoc, ModifierLoc, EndLoc);
- }
- /// Build a new OpenMP 'map' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPMapClause(
- ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
- ArrayRef<SourceLocation> MapTypeModifiersLoc,
- CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
- OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
- SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
- const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
- return getSema().ActOnOpenMPMapClause(
- MapTypeModifiers, MapTypeModifiersLoc, MapperIdScopeSpec, MapperId,
- MapType, IsMapTypeImplicit, MapLoc, ColonLoc, VarList, Locs,
- /*NoDiagnose=*/false, UnresolvedMappers);
- }
- /// Build a new OpenMP 'allocate' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation ColonLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
- LParenLoc, ColonLoc, EndLoc);
- }
- /// Build a new OpenMP 'num_teams' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'thread_limit' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
- LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'priority' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'grainsize' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'num_tasks' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'hint' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'detach' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'dist_schedule' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *
- RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
- Expr *ChunkSize, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation KindLoc,
- SourceLocation CommaLoc, SourceLocation EndLoc) {
- return getSema().ActOnOpenMPDistScheduleClause(
- Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
- }
- /// Build a new OpenMP 'to' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *
- RebuildOMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
- ArrayRef<SourceLocation> MotionModifiersLoc,
- CXXScopeSpec &MapperIdScopeSpec,
- DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
- ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
- ArrayRef<Expr *> UnresolvedMappers) {
- return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc,
- MapperIdScopeSpec, MapperId, ColonLoc,
- VarList, Locs, UnresolvedMappers);
- }
- /// Build a new OpenMP 'from' clause.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *
- RebuildOMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
- ArrayRef<SourceLocation> MotionModifiersLoc,
- CXXScopeSpec &MapperIdScopeSpec,
- DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
- ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
- ArrayRef<Expr *> UnresolvedMappers) {
- return getSema().ActOnOpenMPFromClause(
- MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
- ColonLoc, VarList, Locs, UnresolvedMappers);
- }
- /// Build a new OpenMP 'use_device_ptr' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
- const OMPVarListLocTy &Locs) {
- return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
- }
- /// Build a new OpenMP 'use_device_addr' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPUseDeviceAddrClause(ArrayRef<Expr *> VarList,
- const OMPVarListLocTy &Locs) {
- return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
- }
- /// Build a new OpenMP 'is_device_ptr' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
- const OMPVarListLocTy &Locs) {
- return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
- }
- /// Build a new OpenMP 'defaultmap' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M,
- OpenMPDefaultmapClauseKind Kind,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation MLoc,
- SourceLocation KindLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc,
- MLoc, KindLoc, EndLoc);
- }
- /// Build a new OpenMP 'nontemporal' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPNontemporalClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'inclusive' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPInclusiveClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'exclusive' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPExclusiveClause(ArrayRef<Expr *> VarList,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'uses_allocators' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPUsesAllocatorsClause(
- ArrayRef<Sema::UsesAllocatorsData> Data, SourceLocation StartLoc,
- SourceLocation LParenLoc, SourceLocation EndLoc) {
- return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc,
- Data);
- }
- /// Build a new OpenMP 'affinity' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPAffinityClause(SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation ColonLoc,
- SourceLocation EndLoc, Expr *Modifier,
- ArrayRef<Expr *> Locators) {
- return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc,
- EndLoc, Modifier, Locators);
- }
- /// Build a new OpenMP 'order' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPOrderClause(OpenMPOrderClauseKind Kind,
- SourceLocation KindKwLoc,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPOrderClause(Kind, KindKwLoc, StartLoc,
- LParenLoc, EndLoc);
- }
- /// Build a new OpenMP 'init' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPInitClause(Expr *InteropVar, ArrayRef<Expr *> PrefExprs,
- bool IsTarget, bool IsTargetSync,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation VarLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPInitClause(InteropVar, PrefExprs, IsTarget,
- IsTargetSync, StartLoc, LParenLoc,
- VarLoc, EndLoc);
- }
- /// Build a new OpenMP 'use' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation VarLoc, SourceLocation EndLoc) {
- return getSema().ActOnOpenMPUseClause(InteropVar, StartLoc, LParenLoc,
- VarLoc, EndLoc);
- }
- /// Build a new OpenMP 'destroy' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation VarLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPDestroyClause(InteropVar, StartLoc, LParenLoc,
- VarLoc, EndLoc);
- }
- /// Build a new OpenMP 'novariants' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPNovariantsClause(Expr *Condition,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPNovariantsClause(Condition, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'nocontext' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPNocontextClause(Condition, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'filter' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPFilterClause(ThreadID, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'bind' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPBindClause(OpenMPBindClauseKind Kind,
- SourceLocation KindLoc,
- SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc, LParenLoc,
- EndLoc);
- }
- /// Build a new OpenMP 'align' clause.
- ///
- /// By default, performs semantic analysis to build the new OpenMP clause.
- /// Subclasses may override this routine to provide different behavior.
- OMPClause *RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc,
- SourceLocation LParenLoc,
- SourceLocation EndLoc) {
- return getSema().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc, EndLoc);
- }
- /// Rebuild the operand to an Objective-C \@synchronized statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
- Expr *object) {
- return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
- }
- /// Build a new Objective-C \@synchronized statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
- Expr *Object, Stmt *Body) {
- return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
- }
- /// Build a new Objective-C \@autoreleasepool statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
- Stmt *Body) {
- return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
- }
- /// Build a new Objective-C fast enumeration statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
- Stmt *Element,
- Expr *Collection,
- SourceLocation RParenLoc,
- Stmt *Body) {
- StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
- Element,
- Collection,
- RParenLoc);
- if (ForEachStmt.isInvalid())
- return StmtError();
- return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
- }
- /// Build a new C++ exception declaration.
- ///
- /// By default, performs semantic analysis to build the new decaration.
- /// Subclasses may override this routine to provide different behavior.
- VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
- TypeSourceInfo *Declarator,
- SourceLocation StartLoc,
- SourceLocation IdLoc,
- IdentifierInfo *Id) {
- VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
- StartLoc, IdLoc, Id);
- if (Var)
- getSema().CurContext->addDecl(Var);
- return Var;
- }
- /// Build a new C++ catch statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
- VarDecl *ExceptionDecl,
- Stmt *Handler) {
- return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
- Handler));
- }
- /// Build a new C++ try statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
- ArrayRef<Stmt *> Handlers) {
- return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
- }
- /// Build a new C++0x range-based for statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
- SourceLocation CoawaitLoc, Stmt *Init,
- SourceLocation ColonLoc, Stmt *Range,
- Stmt *Begin, Stmt *End, Expr *Cond,
- Expr *Inc, Stmt *LoopVar,
- SourceLocation RParenLoc) {
- // If we've just learned that the range is actually an Objective-C
- // collection, treat this as an Objective-C fast enumeration loop.
- if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
- if (RangeStmt->isSingleDecl()) {
- if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
- if (RangeVar->isInvalidDecl())
- return StmtError();
- Expr *RangeExpr = RangeVar->getInit();
- if (!RangeExpr->isTypeDependent() &&
- RangeExpr->getType()->isObjCObjectPointerType()) {
- // FIXME: Support init-statements in Objective-C++20 ranged for
- // statement.
- if (Init) {
- return SemaRef.Diag(Init->getBeginLoc(),
- diag::err_objc_for_range_init_stmt)
- << Init->getSourceRange();
- }
- return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
- RangeExpr, RParenLoc);
- }
- }
- }
- }
- return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
- Range, Begin, End, Cond, Inc, LoopVar,
- RParenLoc, Sema::BFRK_Rebuild);
- }
- /// Build a new C++0x range-based for statement.
- ///
- /// By default, performs semantic analysis to build the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
- bool IsIfExists,
- NestedNameSpecifierLoc QualifierLoc,
- DeclarationNameInfo NameInfo,
- Stmt *Nested) {
- return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
- QualifierLoc, NameInfo, Nested);
- }
- /// Attach body to a C++0x range-based for statement.
- ///
- /// By default, performs semantic analysis to finish the new statement.
- /// Subclasses may override this routine to provide different behavior.
- StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
- return getSema().FinishCXXForRangeStmt(ForRange, Body);
- }
- StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
- Stmt *TryBlock, Stmt *Handler) {
- return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
- }
- StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
- Stmt *Block) {
- return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
- }
- StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
- return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
- }
- ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc,
- SourceLocation LParen,
- SourceLocation RParen,
- TypeSourceInfo *TSI) {
- return getSema().BuildSYCLUniqueStableNameExpr(OpLoc, LParen, RParen, TSI);
- }
- /// Build a new predefined expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildPredefinedExpr(SourceLocation Loc,
- PredefinedExpr::IdentKind IK) {
- return getSema().BuildPredefinedExpr(Loc, IK);
- }
- /// Build a new expression that references a declaration.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
- LookupResult &R,
- bool RequiresADL) {
- return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
- }
- /// Build a new expression that references a declaration.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
- ValueDecl *VD,
- const DeclarationNameInfo &NameInfo,
- NamedDecl *Found,
- TemplateArgumentListInfo *TemplateArgs) {
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
- TemplateArgs);
- }
- /// Build a new expression in parentheses.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
- SourceLocation RParen) {
- return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
- }
- /// Build a new pseudo-destructor expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
- SourceLocation OperatorLoc,
- bool isArrow,
- CXXScopeSpec &SS,
- TypeSourceInfo *ScopeType,
- SourceLocation CCLoc,
- SourceLocation TildeLoc,
- PseudoDestructorTypeStorage Destroyed);
- /// Build a new unary operator expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
- UnaryOperatorKind Opc,
- Expr *SubExpr) {
- return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
- }
- /// Build a new builtin offsetof expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
- TypeSourceInfo *Type,
- ArrayRef<Sema::OffsetOfComponent> Components,
- SourceLocation RParenLoc) {
- return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
- RParenLoc);
- }
- /// Build a new sizeof, alignof or vec_step expression with a
- /// type argument.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
- SourceLocation OpLoc,
- UnaryExprOrTypeTrait ExprKind,
- SourceRange R) {
- return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
- }
- /// Build a new sizeof, alignof or vec step expression with an
- /// expression argument.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
- UnaryExprOrTypeTrait ExprKind,
- SourceRange R) {
- ExprResult Result
- = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
- if (Result.isInvalid())
- return ExprError();
- return Result;
- }
- /// Build a new array subscript expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildArraySubscriptExpr(Expr *LHS,
- SourceLocation LBracketLoc,
- Expr *RHS,
- SourceLocation RBracketLoc) {
- return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
- LBracketLoc, RHS,
- RBracketLoc);
- }
- /// Build a new matrix subscript expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx,
- Expr *ColumnIdx,
- SourceLocation RBracketLoc) {
- return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
- RBracketLoc);
- }
- /// Build a new array section expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
- Expr *LowerBound,
- SourceLocation ColonLocFirst,
- SourceLocation ColonLocSecond,
- Expr *Length, Expr *Stride,
- SourceLocation RBracketLoc) {
- return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
- ColonLocFirst, ColonLocSecond,
- Length, Stride, RBracketLoc);
- }
- /// Build a new array shaping expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc,
- SourceLocation RParenLoc,
- ArrayRef<Expr *> Dims,
- ArrayRef<SourceRange> BracketsRanges) {
- return getSema().ActOnOMPArrayShapingExpr(Base, LParenLoc, RParenLoc, Dims,
- BracketsRanges);
- }
- /// Build a new iterator expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildOMPIteratorExpr(
- SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc,
- ArrayRef<Sema::OMPIteratorData> Data) {
- return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc,
- LLoc, RLoc, Data);
- }
- /// Build a new call expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
- MultiExprArg Args,
- SourceLocation RParenLoc,
- Expr *ExecConfig = nullptr) {
- return getSema().ActOnCallExpr(
- /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
- }
- /// Build a new member access expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
- bool isArrow,
- NestedNameSpecifierLoc QualifierLoc,
- SourceLocation TemplateKWLoc,
- const DeclarationNameInfo &MemberNameInfo,
- ValueDecl *Member,
- NamedDecl *FoundDecl,
- const TemplateArgumentListInfo *ExplicitTemplateArgs,
- NamedDecl *FirstQualifierInScope) {
- ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
- isArrow);
- if (!Member->getDeclName()) {
- // We have a reference to an unnamed field. This is always the
- // base of an anonymous struct/union member access, i.e. the
- // field is always of record type.
- assert(Member->getType()->isRecordType() &&
- "unnamed member not of record type?");
- BaseResult =
- getSema().PerformObjectMemberConversion(BaseResult.get(),
- QualifierLoc.getNestedNameSpecifier(),
- FoundDecl, Member);
- if (BaseResult.isInvalid())
- return ExprError();
- Base = BaseResult.get();
- CXXScopeSpec EmptySS;
- return getSema().BuildFieldReferenceExpr(
- Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
- DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
- }
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- Base = BaseResult.get();
- QualType BaseType = Base->getType();
- if (isArrow && !BaseType->isPointerType())
- return ExprError();
- // FIXME: this involves duplicating earlier analysis in a lot of
- // cases; we should avoid this when possible.
- LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
- R.addDecl(FoundDecl);
- R.resolveKind();
- return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
- SS, TemplateKWLoc,
- FirstQualifierInScope,
- R, ExplicitTemplateArgs,
- /*S*/nullptr);
- }
- /// Build a new binary operator expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
- BinaryOperatorKind Opc,
- Expr *LHS, Expr *RHS) {
- return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
- }
- /// Build a new rewritten operator expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXRewrittenBinaryOperator(
- SourceLocation OpLoc, BinaryOperatorKind Opcode,
- const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
- return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
- RHS, /*RequiresADL*/false);
- }
- /// Build a new conditional operator expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildConditionalOperator(Expr *Cond,
- SourceLocation QuestionLoc,
- Expr *LHS,
- SourceLocation ColonLoc,
- Expr *RHS) {
- return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
- LHS, RHS);
- }
- /// Build a new C-style cast expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
- TypeSourceInfo *TInfo,
- SourceLocation RParenLoc,
- Expr *SubExpr) {
- return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
- SubExpr);
- }
- /// Build a new compound literal expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
- TypeSourceInfo *TInfo,
- SourceLocation RParenLoc,
- Expr *Init) {
- return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
- Init);
- }
- /// Build a new extended vector element access expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildExtVectorElementExpr(Expr *Base,
- SourceLocation OpLoc,
- SourceLocation AccessorLoc,
- IdentifierInfo &Accessor) {
- CXXScopeSpec SS;
- DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
- return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
- OpLoc, /*IsArrow*/ false,
- SS, SourceLocation(),
- /*FirstQualifierInScope*/ nullptr,
- NameInfo,
- /* TemplateArgs */ nullptr,
- /*S*/ nullptr);
- }
- /// Build a new initializer list expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildInitList(SourceLocation LBraceLoc,
- MultiExprArg Inits,
- SourceLocation RBraceLoc) {
- return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
- }
- /// Build a new designated initializer expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildDesignatedInitExpr(Designation &Desig,
- MultiExprArg ArrayExprs,
- SourceLocation EqualOrColonLoc,
- bool GNUSyntax,
- Expr *Init) {
- ExprResult Result
- = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
- Init);
- if (Result.isInvalid())
- return ExprError();
- return Result;
- }
- /// Build a new value-initialized expression.
- ///
- /// By default, builds the implicit value initialization without performing
- /// any semantic analysis. Subclasses may override this routine to provide
- /// different behavior.
- ExprResult RebuildImplicitValueInitExpr(QualType T) {
- return new (SemaRef.Context) ImplicitValueInitExpr(T);
- }
- /// Build a new \c va_arg expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
- Expr *SubExpr, TypeSourceInfo *TInfo,
- SourceLocation RParenLoc) {
- return getSema().BuildVAArgExpr(BuiltinLoc,
- SubExpr, TInfo,
- RParenLoc);
- }
- /// Build a new expression list in parentheses.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
- MultiExprArg SubExprs,
- SourceLocation RParenLoc) {
- return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
- }
- /// Build a new address-of-label expression.
- ///
- /// By default, performs semantic analysis, using the name of the label
- /// rather than attempting to map the label statement itself.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
- SourceLocation LabelLoc, LabelDecl *Label) {
- return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
- }
- /// Build a new GNU statement expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt,
- SourceLocation RParenLoc, unsigned TemplateDepth) {
- return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
- TemplateDepth);
- }
- /// Build a new __builtin_choose_expr expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
- Expr *Cond, Expr *LHS, Expr *RHS,
- SourceLocation RParenLoc) {
- return SemaRef.ActOnChooseExpr(BuiltinLoc,
- Cond, LHS, RHS,
- RParenLoc);
- }
- /// Build a new generic selection expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
- SourceLocation DefaultLoc,
- SourceLocation RParenLoc,
- Expr *ControllingExpr,
- ArrayRef<TypeSourceInfo *> Types,
- ArrayRef<Expr *> Exprs) {
- return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
- ControllingExpr, Types, Exprs);
- }
- /// Build a new overloaded operator call expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// The semantic analysis provides the behavior of template instantiation,
- /// copying with transformations that turn what looks like an overloaded
- /// operator call into a use of a builtin operator, performing
- /// argument-dependent lookup, etc. Subclasses may override this routine to
- /// provide different behavior.
- ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
- SourceLocation OpLoc,
- Expr *Callee,
- Expr *First,
- Expr *Second);
- /// Build a new C++ "named" cast expression, such as static_cast or
- /// reinterpret_cast.
- ///
- /// By default, this routine dispatches to one of the more-specific routines
- /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
- Stmt::StmtClass Class,
- SourceLocation LAngleLoc,
- TypeSourceInfo *TInfo,
- SourceLocation RAngleLoc,
- SourceLocation LParenLoc,
- Expr *SubExpr,
- SourceLocation RParenLoc) {
- switch (Class) {
- case Stmt::CXXStaticCastExprClass:
- return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
- RAngleLoc, LParenLoc,
- SubExpr, RParenLoc);
- case Stmt::CXXDynamicCastExprClass:
- return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
- RAngleLoc, LParenLoc,
- SubExpr, RParenLoc);
- case Stmt::CXXReinterpretCastExprClass:
- return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
- RAngleLoc, LParenLoc,
- SubExpr,
- RParenLoc);
- case Stmt::CXXConstCastExprClass:
- return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
- RAngleLoc, LParenLoc,
- SubExpr, RParenLoc);
- case Stmt::CXXAddrspaceCastExprClass:
- return getDerived().RebuildCXXAddrspaceCastExpr(
- OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
- default:
- llvm_unreachable("Invalid C++ named cast");
- }
- }
- /// Build a new C++ static_cast expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
- SourceLocation LAngleLoc,
- TypeSourceInfo *TInfo,
- SourceLocation RAngleLoc,
- SourceLocation LParenLoc,
- Expr *SubExpr,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
- TInfo, SubExpr,
- SourceRange(LAngleLoc, RAngleLoc),
- SourceRange(LParenLoc, RParenLoc));
- }
- /// Build a new C++ dynamic_cast expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
- SourceLocation LAngleLoc,
- TypeSourceInfo *TInfo,
- SourceLocation RAngleLoc,
- SourceLocation LParenLoc,
- Expr *SubExpr,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
- TInfo, SubExpr,
- SourceRange(LAngleLoc, RAngleLoc),
- SourceRange(LParenLoc, RParenLoc));
- }
- /// Build a new C++ reinterpret_cast expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
- SourceLocation LAngleLoc,
- TypeSourceInfo *TInfo,
- SourceLocation RAngleLoc,
- SourceLocation LParenLoc,
- Expr *SubExpr,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
- TInfo, SubExpr,
- SourceRange(LAngleLoc, RAngleLoc),
- SourceRange(LParenLoc, RParenLoc));
- }
- /// Build a new C++ const_cast expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
- SourceLocation LAngleLoc,
- TypeSourceInfo *TInfo,
- SourceLocation RAngleLoc,
- SourceLocation LParenLoc,
- Expr *SubExpr,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
- TInfo, SubExpr,
- SourceRange(LAngleLoc, RAngleLoc),
- SourceRange(LParenLoc, RParenLoc));
- }
- ExprResult
- RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc,
- TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
- SourceLocation LParenLoc, Expr *SubExpr,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXNamedCast(
- OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
- SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
- }
- /// Build a new C++ functional-style cast expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
- SourceLocation LParenLoc,
- Expr *Sub,
- SourceLocation RParenLoc,
- bool ListInitialization) {
- return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
- MultiExprArg(&Sub, 1), RParenLoc,
- ListInitialization);
- }
- /// Build a new C++ __builtin_bit_cast expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc,
- TypeSourceInfo *TSI, Expr *Sub,
- SourceLocation RParenLoc) {
- return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
- }
- /// Build a new C++ typeid(type) expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
- SourceLocation TypeidLoc,
- TypeSourceInfo *Operand,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
- RParenLoc);
- }
- /// Build a new C++ typeid(expr) expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
- SourceLocation TypeidLoc,
- Expr *Operand,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
- RParenLoc);
- }
- /// Build a new C++ __uuidof(type) expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc,
- TypeSourceInfo *Operand,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
- }
- /// Build a new C++ __uuidof(expr) expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc,
- Expr *Operand, SourceLocation RParenLoc) {
- return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
- }
- /// Build a new C++ "this" expression.
- ///
- /// By default, builds a new "this" expression without performing any
- /// semantic analysis. Subclasses may override this routine to provide
- /// different behavior.
- ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
- QualType ThisType,
- bool isImplicit) {
- return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
- }
- /// Build a new C++ throw expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
- bool IsThrownVariableInScope) {
- return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
- }
- /// Build a new C++ default-argument expression.
- ///
- /// By default, builds a new default-argument expression, which does not
- /// require any semantic analysis. Subclasses may override this routine to
- /// provide different behavior.
- ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) {
- return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
- getSema().CurContext);
- }
- /// Build a new C++11 default-initialization expression.
- ///
- /// By default, builds a new default field initialization expression, which
- /// does not require any semantic analysis. Subclasses may override this
- /// routine to provide different behavior.
- ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
- FieldDecl *Field) {
- return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
- getSema().CurContext);
- }
- /// Build a new C++ zero-initialization expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
- SourceLocation LParenLoc,
- SourceLocation RParenLoc) {
- return getSema().BuildCXXTypeConstructExpr(
- TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
- }
- /// Build a new C++ "new" expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
- bool UseGlobal,
- SourceLocation PlacementLParen,
- MultiExprArg PlacementArgs,
- SourceLocation PlacementRParen,
- SourceRange TypeIdParens,
- QualType AllocatedType,
- TypeSourceInfo *AllocatedTypeInfo,
- Optional<Expr *> ArraySize,
- SourceRange DirectInitRange,
- Expr *Initializer) {
- return getSema().BuildCXXNew(StartLoc, UseGlobal,
- PlacementLParen,
- PlacementArgs,
- PlacementRParen,
- TypeIdParens,
- AllocatedType,
- AllocatedTypeInfo,
- ArraySize,
- DirectInitRange,
- Initializer);
- }
- /// Build a new C++ "delete" expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
- bool IsGlobalDelete,
- bool IsArrayForm,
- Expr *Operand) {
- return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
- Operand);
- }
- /// Build a new type trait expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildTypeTrait(TypeTrait Trait,
- SourceLocation StartLoc,
- ArrayRef<TypeSourceInfo *> Args,
- SourceLocation RParenLoc) {
- return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
- }
- /// Build a new array type trait expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
- SourceLocation StartLoc,
- TypeSourceInfo *TSInfo,
- Expr *DimExpr,
- SourceLocation RParenLoc) {
- return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
- }
- /// Build a new expression trait expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
- SourceLocation StartLoc,
- Expr *Queried,
- SourceLocation RParenLoc) {
- return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
- }
- /// Build a new (previously unresolved) declaration reference
- /// expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildDependentScopeDeclRefExpr(
- NestedNameSpecifierLoc QualifierLoc,
- SourceLocation TemplateKWLoc,
- const DeclarationNameInfo &NameInfo,
- const TemplateArgumentListInfo *TemplateArgs,
- bool IsAddressOfOperand,
- TypeSourceInfo **RecoveryTSI) {
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- if (TemplateArgs || TemplateKWLoc.isValid())
- return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
- TemplateArgs);
- return getSema().BuildQualifiedDeclarationNameExpr(
- SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
- }
- /// Build a new template-id expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
- SourceLocation TemplateKWLoc,
- LookupResult &R,
- bool RequiresADL,
- const TemplateArgumentListInfo *TemplateArgs) {
- return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
- TemplateArgs);
- }
- /// Build a new object-construction expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXConstructExpr(QualType T,
- SourceLocation Loc,
- CXXConstructorDecl *Constructor,
- bool IsElidable,
- MultiExprArg Args,
- bool HadMultipleCandidates,
- bool ListInitialization,
- bool StdInitListInitialization,
- bool RequiresZeroInit,
- CXXConstructExpr::ConstructionKind ConstructKind,
- SourceRange ParenRange) {
- // Reconstruct the constructor we originally found, which might be
- // different if this is a call to an inherited constructor.
- CXXConstructorDecl *FoundCtor = Constructor;
- if (Constructor->isInheritingConstructor())
- FoundCtor = Constructor->getInheritedConstructor().getConstructor();
- SmallVector<Expr *, 8> ConvertedArgs;
- if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
- ConvertedArgs))
- return ExprError();
- return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
- IsElidable,
- ConvertedArgs,
- HadMultipleCandidates,
- ListInitialization,
- StdInitListInitialization,
- RequiresZeroInit, ConstructKind,
- ParenRange);
- }
- /// Build a new implicit construction via inherited constructor
- /// expression.
- ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
- CXXConstructorDecl *Constructor,
- bool ConstructsVBase,
- bool InheritedFromVBase) {
- return new (getSema().Context) CXXInheritedCtorInitExpr(
- Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
- }
- /// Build a new object-construction expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
- SourceLocation LParenOrBraceLoc,
- MultiExprArg Args,
- SourceLocation RParenOrBraceLoc,
- bool ListInitialization) {
- return getSema().BuildCXXTypeConstructExpr(
- TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
- }
- /// Build a new object-construction expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
- SourceLocation LParenLoc,
- MultiExprArg Args,
- SourceLocation RParenLoc,
- bool ListInitialization) {
- return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
- RParenLoc, ListInitialization);
- }
- /// Build a new member reference expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
- QualType BaseType,
- bool IsArrow,
- SourceLocation OperatorLoc,
- NestedNameSpecifierLoc QualifierLoc,
- SourceLocation TemplateKWLoc,
- NamedDecl *FirstQualifierInScope,
- const DeclarationNameInfo &MemberNameInfo,
- const TemplateArgumentListInfo *TemplateArgs) {
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
- OperatorLoc, IsArrow,
- SS, TemplateKWLoc,
- FirstQualifierInScope,
- MemberNameInfo,
- TemplateArgs, /*S*/nullptr);
- }
- /// Build a new member reference expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
- SourceLocation OperatorLoc,
- bool IsArrow,
- NestedNameSpecifierLoc QualifierLoc,
- SourceLocation TemplateKWLoc,
- NamedDecl *FirstQualifierInScope,
- LookupResult &R,
- const TemplateArgumentListInfo *TemplateArgs) {
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
- OperatorLoc, IsArrow,
- SS, TemplateKWLoc,
- FirstQualifierInScope,
- R, TemplateArgs, /*S*/nullptr);
- }
- /// Build a new noexcept expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
- return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
- }
- /// Build a new expression to compute the length of a parameter pack.
- ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
- NamedDecl *Pack,
- SourceLocation PackLoc,
- SourceLocation RParenLoc,
- Optional<unsigned> Length,
- ArrayRef<TemplateArgument> PartialArgs) {
- return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
- RParenLoc, Length, PartialArgs);
- }
- /// Build a new expression representing a call to a source location
- /// builtin.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
- SourceLocation BuiltinLoc,
- SourceLocation RPLoc,
- DeclContext *ParentContext) {
- return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
- }
- /// Build a new Objective-C boxed expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS,
- SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
- NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
- TemplateArgumentListInfo *TALI) {
- CXXScopeSpec SS;
- SS.Adopt(NNS);
- ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
- ConceptNameInfo,
- FoundDecl,
- NamedConcept, TALI);
- if (Result.isInvalid())
- return ExprError();
- return Result;
- }
- /// \brief Build a new requires expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc,
- RequiresExprBodyDecl *Body,
- ArrayRef<ParmVarDecl *> LocalParameters,
- ArrayRef<concepts::Requirement *> Requirements,
- SourceLocation ClosingBraceLoc) {
- return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body,
- LocalParameters, Requirements, ClosingBraceLoc);
- }
- concepts::TypeRequirement *
- RebuildTypeRequirement(
- concepts::Requirement::SubstitutionDiagnostic *SubstDiag) {
- return SemaRef.BuildTypeRequirement(SubstDiag);
- }
- concepts::TypeRequirement *RebuildTypeRequirement(TypeSourceInfo *T) {
- return SemaRef.BuildTypeRequirement(T);
- }
- concepts::ExprRequirement *
- RebuildExprRequirement(
- concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
- SourceLocation NoexceptLoc,
- concepts::ExprRequirement::ReturnTypeRequirement Ret) {
- return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
- std::move(Ret));
- }
- concepts::ExprRequirement *
- RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
- concepts::ExprRequirement::ReturnTypeRequirement Ret) {
- return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
- std::move(Ret));
- }
- concepts::NestedRequirement *
- RebuildNestedRequirement(
- concepts::Requirement::SubstitutionDiagnostic *SubstDiag) {
- return SemaRef.BuildNestedRequirement(SubstDiag);
- }
- concepts::NestedRequirement *RebuildNestedRequirement(Expr *Constraint) {
- return SemaRef.BuildNestedRequirement(Constraint);
- }
- /// \brief Build a new Objective-C boxed expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
- return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
- }
- /// Build a new Objective-C array literal.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCArrayLiteral(SourceRange Range,
- Expr **Elements, unsigned NumElements) {
- return getSema().BuildObjCArrayLiteral(Range,
- MultiExprArg(Elements, NumElements));
- }
- ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
- Expr *Base, Expr *Key,
- ObjCMethodDecl *getterMethod,
- ObjCMethodDecl *setterMethod) {
- return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
- getterMethod, setterMethod);
- }
- /// Build a new Objective-C dictionary literal.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
- MutableArrayRef<ObjCDictionaryElement> Elements) {
- return getSema().BuildObjCDictionaryLiteral(Range, Elements);
- }
- /// Build a new Objective-C \@encode expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
- TypeSourceInfo *EncodeTypeInfo,
- SourceLocation RParenLoc) {
- return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
- }
- /// Build a new Objective-C class message.
- ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
- Selector Sel,
- ArrayRef<SourceLocation> SelectorLocs,
- ObjCMethodDecl *Method,
- SourceLocation LBracLoc,
- MultiExprArg Args,
- SourceLocation RBracLoc) {
- return SemaRef.BuildClassMessage(ReceiverTypeInfo,
- ReceiverTypeInfo->getType(),
- /*SuperLoc=*/SourceLocation(),
- Sel, Method, LBracLoc, SelectorLocs,
- RBracLoc, Args);
- }
- /// Build a new Objective-C instance message.
- ExprResult RebuildObjCMessageExpr(Expr *Receiver,
- Selector Sel,
- ArrayRef<SourceLocation> SelectorLocs,
- ObjCMethodDecl *Method,
- SourceLocation LBracLoc,
- MultiExprArg Args,
- SourceLocation RBracLoc) {
- return SemaRef.BuildInstanceMessage(Receiver,
- Receiver->getType(),
- /*SuperLoc=*/SourceLocation(),
- Sel, Method, LBracLoc, SelectorLocs,
- RBracLoc, Args);
- }
- /// Build a new Objective-C instance/class message to 'super'.
- ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
- Selector Sel,
- ArrayRef<SourceLocation> SelectorLocs,
- QualType SuperType,
- ObjCMethodDecl *Method,
- SourceLocation LBracLoc,
- MultiExprArg Args,
- SourceLocation RBracLoc) {
- return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
- SuperType,
- SuperLoc,
- Sel, Method, LBracLoc, SelectorLocs,
- RBracLoc, Args)
- : SemaRef.BuildClassMessage(nullptr,
- SuperType,
- SuperLoc,
- Sel, Method, LBracLoc, SelectorLocs,
- RBracLoc, Args);
- }
- /// Build a new Objective-C ivar reference expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
- SourceLocation IvarLoc,
- bool IsArrow, bool IsFreeIvar) {
- CXXScopeSpec SS;
- DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
- ExprResult Result = getSema().BuildMemberReferenceExpr(
- BaseArg, BaseArg->getType(),
- /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
- /*FirstQualifierInScope=*/nullptr, NameInfo,
- /*TemplateArgs=*/nullptr,
- /*S=*/nullptr);
- if (IsFreeIvar && Result.isUsable())
- cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
- return Result;
- }
- /// Build a new Objective-C property reference expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
- ObjCPropertyDecl *Property,
- SourceLocation PropertyLoc) {
- CXXScopeSpec SS;
- DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
- return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
- /*FIXME:*/PropertyLoc,
- /*IsArrow=*/false,
- SS, SourceLocation(),
- /*FirstQualifierInScope=*/nullptr,
- NameInfo,
- /*TemplateArgs=*/nullptr,
- /*S=*/nullptr);
- }
- /// Build a new Objective-C property reference expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
- ObjCMethodDecl *Getter,
- ObjCMethodDecl *Setter,
- SourceLocation PropertyLoc) {
- // Since these expressions can only be value-dependent, we do not
- // need to perform semantic analysis again.
- return Owned(
- new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
- VK_LValue, OK_ObjCProperty,
- PropertyLoc, Base));
- }
- /// Build a new Objective-C "isa" expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
- SourceLocation OpLoc, bool IsArrow) {
- CXXScopeSpec SS;
- DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
- return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
- OpLoc, IsArrow,
- SS, SourceLocation(),
- /*FirstQualifierInScope=*/nullptr,
- NameInfo,
- /*TemplateArgs=*/nullptr,
- /*S=*/nullptr);
- }
- /// Build a new shuffle vector expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
- MultiExprArg SubExprs,
- SourceLocation RParenLoc) {
- // Find the declaration for __builtin_shufflevector
- const IdentifierInfo &Name
- = SemaRef.Context.Idents.get("__builtin_shufflevector");
- TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
- DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
- assert(!Lookup.empty() && "No __builtin_shufflevector?");
- // Build a reference to the __builtin_shufflevector builtin
- FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
- Expr *Callee = new (SemaRef.Context)
- DeclRefExpr(SemaRef.Context, Builtin, false,
- SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
- QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
- Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
- CK_BuiltinFnToFnPtr).get();
- // Build the CallExpr
- ExprResult TheCall = CallExpr::Create(
- SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
- Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
- FPOptionsOverride());
- // Type-check the __builtin_shufflevector expression.
- return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
- }
- /// Build a new convert vector expression.
- ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
- Expr *SrcExpr, TypeSourceInfo *DstTInfo,
- SourceLocation RParenLoc) {
- return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
- BuiltinLoc, RParenLoc);
- }
- /// Build a new template argument pack expansion.
- ///
- /// By default, performs semantic analysis to build a new pack expansion
- /// for a template argument. Subclasses may override this routine to provide
- /// different behavior.
- TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
- SourceLocation EllipsisLoc,
- Optional<unsigned> NumExpansions) {
- switch (Pattern.getArgument().getKind()) {
- case TemplateArgument::Expression: {
- ExprResult Result
- = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
- EllipsisLoc, NumExpansions);
- if (Result.isInvalid())
- return TemplateArgumentLoc();
- return TemplateArgumentLoc(Result.get(), Result.get());
- }
- case TemplateArgument::Template:
- return TemplateArgumentLoc(
- SemaRef.Context,
- TemplateArgument(Pattern.getArgument().getAsTemplate(),
- NumExpansions),
- Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
- EllipsisLoc);
- case TemplateArgument::Null:
- case TemplateArgument::Integral:
- case TemplateArgument::Declaration:
- case TemplateArgument::Pack:
- case TemplateArgument::TemplateExpansion:
- case TemplateArgument::NullPtr:
- llvm_unreachable("Pack expansion pattern has no parameter packs");
- case TemplateArgument::Type:
- if (TypeSourceInfo *Expansion
- = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
- EllipsisLoc,
- NumExpansions))
- return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
- Expansion);
- break;
- }
- return TemplateArgumentLoc();
- }
- /// Build a new expression pack expansion.
- ///
- /// By default, performs semantic analysis to build a new pack expansion
- /// for an expression. Subclasses may override this routine to provide
- /// different behavior.
- ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
- Optional<unsigned> NumExpansions) {
- return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
- }
- /// Build a new C++1z fold-expression.
- ///
- /// By default, performs semantic analysis in order to build a new fold
- /// expression.
- ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE,
- SourceLocation LParenLoc, Expr *LHS,
- BinaryOperatorKind Operator,
- SourceLocation EllipsisLoc, Expr *RHS,
- SourceLocation RParenLoc,
- Optional<unsigned> NumExpansions) {
- return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
- EllipsisLoc, RHS, RParenLoc,
- NumExpansions);
- }
- /// Build an empty C++1z fold-expression with the given operator.
- ///
- /// By default, produces the fallback value for the fold-expression, or
- /// produce an error if there is no fallback value.
- ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
- BinaryOperatorKind Operator) {
- return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
- }
- /// Build a new atomic operation expression.
- ///
- /// By default, performs semantic analysis to build the new expression.
- /// Subclasses may override this routine to provide different behavior.
- ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs,
- AtomicExpr::AtomicOp Op,
- SourceLocation RParenLoc) {
- // Use this for all of the locations, since we don't know the difference
- // between the call and the expr at this point.
- SourceRange Range{BuiltinLoc, RParenLoc};
- return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
- Sema::AtomicArgumentOrder::AST);
- }
- ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc,
- ArrayRef<Expr *> SubExprs, QualType Type) {
- return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
- }
- private:
- TypeLoc TransformTypeInObjectScope(TypeLoc TL,
- QualType ObjectType,
- NamedDecl *FirstQualifierInScope,
- CXXScopeSpec &SS);
- TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
- QualType ObjectType,
- NamedDecl *FirstQualifierInScope,
- CXXScopeSpec &SS);
- TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
- NamedDecl *FirstQualifierInScope,
- CXXScopeSpec &SS);
- QualType TransformDependentNameType(TypeLocBuilder &TLB,
- DependentNameTypeLoc TL,
- bool DeducibleTSTContext);
- };
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
- if (!S)
- return S;
- switch (S->getStmtClass()) {
- case Stmt::NoStmtClass: break;
- // Transform individual statement nodes
- // Pass SDK into statements that can produce a value
- #define STMT(Node, Parent) \
- case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
- #define VALUESTMT(Node, Parent) \
- case Stmt::Node##Class: \
- return getDerived().Transform##Node(cast<Node>(S), SDK);
- #define ABSTRACT_STMT(Node)
- #define EXPR(Node, Parent)
- #include "clang/AST/StmtNodes.inc"
- // Transform expressions by calling TransformExpr.
- #define STMT(Node, Parent)
- #define ABSTRACT_STMT(Stmt)
- #define EXPR(Node, Parent) case Stmt::Node##Class:
- #include "clang/AST/StmtNodes.inc"
- {
- ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
- if (SDK == SDK_StmtExprResult)
- E = getSema().ActOnStmtExprResult(E);
- return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
- }
- }
- return S;
- }
- template<typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
- if (!S)
- return S;
- switch (S->getClauseKind()) {
- default: break;
- // Transform individual clause nodes
- #define GEN_CLANG_CLAUSE_CLASS
- #define CLAUSE_CLASS(Enum, Str, Class) \
- case Enum: \
- return getDerived().Transform##Class(cast<Class>(S));
- #include "llvm/Frontend/OpenMP/OMP.inc"
- }
- return S;
- }
- template<typename Derived>
- ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
- if (!E)
- return E;
- switch (E->getStmtClass()) {
- case Stmt::NoStmtClass: break;
- #define STMT(Node, Parent) case Stmt::Node##Class: break;
- #define ABSTRACT_STMT(Stmt)
- #define EXPR(Node, Parent) \
- case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
- #include "clang/AST/StmtNodes.inc"
- }
- return E;
- }
- template<typename Derived>
- ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
- bool NotCopyInit) {
- // Initializers are instantiated like expressions, except that various outer
- // layers are stripped.
- if (!Init)
- return Init;
- if (auto *FE = dyn_cast<FullExpr>(Init))
- Init = FE->getSubExpr();
- if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
- OpaqueValueExpr *OVE = AIL->getCommonExpr();
- Init = OVE->getSourceExpr();
- }
- if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
- Init = MTE->getSubExpr();
- while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
- Init = Binder->getSubExpr();
- if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
- Init = ICE->getSubExprAsWritten();
- if (CXXStdInitializerListExpr *ILE =
- dyn_cast<CXXStdInitializerListExpr>(Init))
- return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
- // If this is copy-initialization, we only need to reconstruct
- // InitListExprs. Other forms of copy-initialization will be a no-op if
- // the initializer is already the right type.
- CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
- if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
- return getDerived().TransformExpr(Init);
- // Revert value-initialization back to empty parens.
- if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
- SourceRange Parens = VIE->getSourceRange();
- return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
- Parens.getEnd());
- }
- // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
- if (isa<ImplicitValueInitExpr>(Init))
- return getDerived().RebuildParenListExpr(SourceLocation(), None,
- SourceLocation());
- // Revert initialization by constructor back to a parenthesized or braced list
- // of expressions. Any other form of initializer can just be reused directly.
- if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
- return getDerived().TransformExpr(Init);
- // If the initialization implicitly converted an initializer list to a
- // std::initializer_list object, unwrap the std::initializer_list too.
- if (Construct && Construct->isStdInitListInitialization())
- return TransformInitializer(Construct->getArg(0), NotCopyInit);
- // Enter a list-init context if this was list initialization.
- EnterExpressionEvaluationContext Context(
- getSema(), EnterExpressionEvaluationContext::InitList,
- Construct->isListInitialization());
- SmallVector<Expr*, 8> NewArgs;
- bool ArgChanged = false;
- if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
- /*IsCall*/true, NewArgs, &ArgChanged))
- return ExprError();
- // If this was list initialization, revert to syntactic list form.
- if (Construct->isListInitialization())
- return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
- Construct->getEndLoc());
- // Build a ParenListExpr to represent anything else.
- SourceRange Parens = Construct->getParenOrBraceRange();
- if (Parens.isInvalid()) {
- // This was a variable declaration's initialization for which no initializer
- // was specified.
- assert(NewArgs.empty() &&
- "no parens or braces but have direct init with arguments?");
- return ExprEmpty();
- }
- return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
- Parens.getEnd());
- }
- template<typename Derived>
- bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
- unsigned NumInputs,
- bool IsCall,
- SmallVectorImpl<Expr *> &Outputs,
- bool *ArgChanged) {
- for (unsigned I = 0; I != NumInputs; ++I) {
- // If requested, drop call arguments that need to be dropped.
- if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
- if (ArgChanged)
- *ArgChanged = true;
- break;
- }
- if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
- Expr *Pattern = Expansion->getPattern();
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
- assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
- // Determine whether the set of unexpanded parameter packs can and should
- // be expanded.
- bool Expand = true;
- bool RetainExpansion = false;
- Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
- Optional<unsigned> NumExpansions = OrigNumExpansions;
- if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
- Pattern->getSourceRange(),
- Unexpanded,
- Expand, RetainExpansion,
- NumExpansions))
- return true;
- if (!Expand) {
- // The transform has determined that we should perform a simple
- // transformation on the pack expansion, producing another pack
- // expansion.
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- ExprResult OutPattern = getDerived().TransformExpr(Pattern);
- if (OutPattern.isInvalid())
- return true;
- ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
- Expansion->getEllipsisLoc(),
- NumExpansions);
- if (Out.isInvalid())
- return true;
- if (ArgChanged)
- *ArgChanged = true;
- Outputs.push_back(Out.get());
- continue;
- }
- // Record right away that the argument was changed. This needs
- // to happen even if the array expands to nothing.
- if (ArgChanged) *ArgChanged = true;
- // The transform has determined that we should perform an elementwise
- // expansion of the pattern. Do so.
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
- ExprResult Out = getDerived().TransformExpr(Pattern);
- if (Out.isInvalid())
- return true;
- if (Out.get()->containsUnexpandedParameterPack()) {
- Out = getDerived().RebuildPackExpansion(
- Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
- if (Out.isInvalid())
- return true;
- }
- Outputs.push_back(Out.get());
- }
- // If we're supposed to retain a pack expansion, do so by temporarily
- // forgetting the partially-substituted parameter pack.
- if (RetainExpansion) {
- ForgetPartiallySubstitutedPackRAII Forget(getDerived());
- ExprResult Out = getDerived().TransformExpr(Pattern);
- if (Out.isInvalid())
- return true;
- Out = getDerived().RebuildPackExpansion(
- Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
- if (Out.isInvalid())
- return true;
- Outputs.push_back(Out.get());
- }
- continue;
- }
- ExprResult Result =
- IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
- : getDerived().TransformExpr(Inputs[I]);
- if (Result.isInvalid())
- return true;
- if (Result.get() != Inputs[I] && ArgChanged)
- *ArgChanged = true;
- Outputs.push_back(Result.get());
- }
- return false;
- }
- template <typename Derived>
- Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
- SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
- if (Var) {
- VarDecl *ConditionVar = cast_or_null<VarDecl>(
- getDerived().TransformDefinition(Var->getLocation(), Var));
- if (!ConditionVar)
- return Sema::ConditionError();
- return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
- }
- if (Expr) {
- ExprResult CondExpr = getDerived().TransformExpr(Expr);
- if (CondExpr.isInvalid())
- return Sema::ConditionError();
- return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
- /*MissingOK=*/true);
- }
- return Sema::ConditionResult();
- }
- template <typename Derived>
- NestedNameSpecifierLoc TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
- NestedNameSpecifierLoc NNS, QualType ObjectType,
- NamedDecl *FirstQualifierInScope) {
- SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
- for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
- Qualifier = Qualifier.getPrefix())
- Qualifiers.push_back(Qualifier);
- CXXScopeSpec SS;
- while (!Qualifiers.empty()) {
- NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
- NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
- switch (QNNS->getKind()) {
- case NestedNameSpecifier::Identifier: {
- Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
- Q.getLocalBeginLoc(), Q.getLocalEndLoc(),
- ObjectType);
- if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
- SS, FirstQualifierInScope, false))
- return NestedNameSpecifierLoc();
- break;
- }
- case NestedNameSpecifier::Namespace: {
- NamespaceDecl *NS =
- cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
- Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
- SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
- break;
- }
- case NestedNameSpecifier::NamespaceAlias: {
- NamespaceAliasDecl *Alias =
- cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
- Q.getLocalBeginLoc(), QNNS->getAsNamespaceAlias()));
- SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
- Q.getLocalEndLoc());
- break;
- }
- case NestedNameSpecifier::Global:
- // There is no meaningful transformation that one could perform on the
- // global scope.
- SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
- break;
- case NestedNameSpecifier::Super: {
- CXXRecordDecl *RD =
- cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
- SourceLocation(), QNNS->getAsRecordDecl()));
- SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
- break;
- }
- case NestedNameSpecifier::TypeSpecWithTemplate:
- case NestedNameSpecifier::TypeSpec: {
- TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
- FirstQualifierInScope, SS);
- if (!TL)
- return NestedNameSpecifierLoc();
- if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
- (SemaRef.getLangOpts().CPlusPlus11 &&
- TL.getType()->isEnumeralType())) {
- assert(!TL.getType().hasLocalQualifiers() &&
- "Can't get cv-qualifiers here");
- if (TL.getType()->isEnumeralType())
- SemaRef.Diag(TL.getBeginLoc(),
- diag::warn_cxx98_compat_enum_nested_name_spec);
- SS.Extend(SemaRef.Context, /*FIXME:*/ SourceLocation(), TL,
- Q.getLocalEndLoc());
- break;
- }
- // If the nested-name-specifier is an invalid type def, don't emit an
- // error because a previous error should have already been emitted.
- TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
- if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
- SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
- << TL.getType() << SS.getRange();
- }
- return NestedNameSpecifierLoc();
- }
- }
- // The qualifier-in-scope and object type only apply to the leftmost entity.
- FirstQualifierInScope = nullptr;
- ObjectType = QualType();
- }
- // Don't rebuild the nested-name-specifier if we don't have to.
- if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
- !getDerived().AlwaysRebuild())
- return NNS;
- // If we can re-use the source-location data from the original
- // nested-name-specifier, do so.
- if (SS.location_size() == NNS.getDataLength() &&
- memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
- return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
- // Allocate new nested-name-specifier location information.
- return SS.getWithLocInContext(SemaRef.Context);
- }
- template<typename Derived>
- DeclarationNameInfo
- TreeTransform<Derived>
- ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
- DeclarationName Name = NameInfo.getName();
- if (!Name)
- return DeclarationNameInfo();
- switch (Name.getNameKind()) {
- case DeclarationName::Identifier:
- case DeclarationName::ObjCZeroArgSelector:
- case DeclarationName::ObjCOneArgSelector:
- case DeclarationName::ObjCMultiArgSelector:
- case DeclarationName::CXXOperatorName:
- case DeclarationName::CXXLiteralOperatorName:
- case DeclarationName::CXXUsingDirective:
- return NameInfo;
- case DeclarationName::CXXDeductionGuideName: {
- TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
- TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
- getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
- if (!NewTemplate)
- return DeclarationNameInfo();
- DeclarationNameInfo NewNameInfo(NameInfo);
- NewNameInfo.setName(
- SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
- return NewNameInfo;
- }
- case DeclarationName::CXXConstructorName:
- case DeclarationName::CXXDestructorName:
- case DeclarationName::CXXConversionFunctionName: {
- TypeSourceInfo *NewTInfo;
- CanQualType NewCanTy;
- if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
- NewTInfo = getDerived().TransformType(OldTInfo);
- if (!NewTInfo)
- return DeclarationNameInfo();
- NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
- }
- else {
- NewTInfo = nullptr;
- TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
- QualType NewT = getDerived().TransformType(Name.getCXXNameType());
- if (NewT.isNull())
- return DeclarationNameInfo();
- NewCanTy = SemaRef.Context.getCanonicalType(NewT);
- }
- DeclarationName NewName
- = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
- NewCanTy);
- DeclarationNameInfo NewNameInfo(NameInfo);
- NewNameInfo.setName(NewName);
- NewNameInfo.setNamedTypeInfo(NewTInfo);
- return NewNameInfo;
- }
- }
- llvm_unreachable("Unknown name kind.");
- }
- template<typename Derived>
- TemplateName
- TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
- TemplateName Name,
- SourceLocation NameLoc,
- QualType ObjectType,
- NamedDecl *FirstQualifierInScope,
- bool AllowInjectedClassName) {
- if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
- TemplateDecl *Template = QTN->getTemplateDecl();
- assert(Template && "qualified template name must refer to a template");
- TemplateDecl *TransTemplate
- = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
- Template));
- if (!TransTemplate)
- return TemplateName();
- if (!getDerived().AlwaysRebuild() &&
- SS.getScopeRep() == QTN->getQualifier() &&
- TransTemplate == Template)
- return Name;
- return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
- TransTemplate);
- }
- if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
- if (SS.getScopeRep()) {
- // These apply to the scope specifier, not the template.
- ObjectType = QualType();
- FirstQualifierInScope = nullptr;
- }
- if (!getDerived().AlwaysRebuild() &&
- SS.getScopeRep() == DTN->getQualifier() &&
- ObjectType.isNull())
- return Name;
- // FIXME: Preserve the location of the "template" keyword.
- SourceLocation TemplateKWLoc = NameLoc;
- if (DTN->isIdentifier()) {
- return getDerived().RebuildTemplateName(SS,
- TemplateKWLoc,
- *DTN->getIdentifier(),
- NameLoc,
- ObjectType,
- FirstQualifierInScope,
- AllowInjectedClassName);
- }
- return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
- DTN->getOperator(), NameLoc,
- ObjectType, AllowInjectedClassName);
- }
- if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
- TemplateDecl *TransTemplate
- = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
- Template));
- if (!TransTemplate)
- return TemplateName();
- if (!getDerived().AlwaysRebuild() &&
- TransTemplate == Template)
- return Name;
- return TemplateName(TransTemplate);
- }
- if (SubstTemplateTemplateParmPackStorage *SubstPack
- = Name.getAsSubstTemplateTemplateParmPack()) {
- TemplateTemplateParmDecl *TransParam
- = cast_or_null<TemplateTemplateParmDecl>(
- getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
- if (!TransParam)
- return TemplateName();
- if (!getDerived().AlwaysRebuild() &&
- TransParam == SubstPack->getParameterPack())
- return Name;
- return getDerived().RebuildTemplateName(TransParam,
- SubstPack->getArgumentPack());
- }
- // These should be getting filtered out before they reach the AST.
- llvm_unreachable("overloaded function decl survived to here");
- }
- template<typename Derived>
- void TreeTransform<Derived>::InventTemplateArgumentLoc(
- const TemplateArgument &Arg,
- TemplateArgumentLoc &Output) {
- Output = getSema().getTrivialTemplateArgumentLoc(
- Arg, QualType(), getDerived().getBaseLocation());
- }
- template <typename Derived>
- bool TreeTransform<Derived>::TransformTemplateArgument(
- const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
- bool Uneval) {
- const TemplateArgument &Arg = Input.getArgument();
- switch (Arg.getKind()) {
- case TemplateArgument::Null:
- case TemplateArgument::Pack:
- llvm_unreachable("Unexpected TemplateArgument");
- case TemplateArgument::Integral:
- case TemplateArgument::NullPtr:
- case TemplateArgument::Declaration: {
- // Transform a resolved template argument straight to a resolved template
- // argument. We get here when substituting into an already-substituted
- // template type argument during concept satisfaction checking.
- QualType T = Arg.getNonTypeTemplateArgumentType();
- QualType NewT = getDerived().TransformType(T);
- if (NewT.isNull())
- return true;
- ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration
- ? Arg.getAsDecl()
- : nullptr;
- ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
- getDerived().getBaseLocation(), D))
- : nullptr;
- if (D && !NewD)
- return true;
- if (NewT == T && D == NewD)
- Output = Input;
- else if (Arg.getKind() == TemplateArgument::Integral)
- Output = TemplateArgumentLoc(
- TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
- TemplateArgumentLocInfo());
- else if (Arg.getKind() == TemplateArgument::NullPtr)
- Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
- TemplateArgumentLocInfo());
- else
- Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
- TemplateArgumentLocInfo());
- return false;
- }
- case TemplateArgument::Type: {
- TypeSourceInfo *DI = Input.getTypeSourceInfo();
- if (!DI)
- DI = InventTypeSourceInfo(Input.getArgument().getAsType());
- DI = getDerived().TransformType(DI);
- if (!DI)
- return true;
- Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
- return false;
- }
- case TemplateArgument::Template: {
- NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
- if (QualifierLoc) {
- QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
- if (!QualifierLoc)
- return true;
- }
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- TemplateName Template = getDerived().TransformTemplateName(
- SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
- if (Template.isNull())
- return true;
- Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
- QualifierLoc, Input.getTemplateNameLoc());
- return false;
- }
- case TemplateArgument::TemplateExpansion:
- llvm_unreachable("Caller should expand pack expansions");
- case TemplateArgument::Expression: {
- // Template argument expressions are constant expressions.
- EnterExpressionEvaluationContext Unevaluated(
- getSema(),
- Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
- : Sema::ExpressionEvaluationContext::ConstantEvaluated,
- /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
- Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
- Expr *InputExpr = Input.getSourceExpression();
- if (!InputExpr)
- InputExpr = Input.getArgument().getAsExpr();
- ExprResult E = getDerived().TransformExpr(InputExpr);
- E = SemaRef.ActOnConstantExpression(E);
- if (E.isInvalid())
- return true;
- Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
- return false;
- }
- }
- // Work around bogus GCC warning
- return true;
- }
- /// Iterator adaptor that invents template argument location information
- /// for each of the template arguments in its underlying iterator.
- template<typename Derived, typename InputIterator>
- class TemplateArgumentLocInventIterator {
- TreeTransform<Derived> &Self;
- InputIterator Iter;
- public:
- typedef TemplateArgumentLoc value_type;
- typedef TemplateArgumentLoc reference;
- typedef typename std::iterator_traits<InputIterator>::difference_type
- difference_type;
- typedef std::input_iterator_tag iterator_category;
- class pointer {
- TemplateArgumentLoc Arg;
- public:
- explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
- const TemplateArgumentLoc *operator->() const { return &Arg; }
- };
- TemplateArgumentLocInventIterator() { }
- explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
- InputIterator Iter)
- : Self(Self), Iter(Iter) { }
- TemplateArgumentLocInventIterator &operator++() {
- ++Iter;
- return *this;
- }
- TemplateArgumentLocInventIterator operator++(int) {
- TemplateArgumentLocInventIterator Old(*this);
- ++(*this);
- return Old;
- }
- reference operator*() const {
- TemplateArgumentLoc Result;
- Self.InventTemplateArgumentLoc(*Iter, Result);
- return Result;
- }
- pointer operator->() const { return pointer(**this); }
- friend bool operator==(const TemplateArgumentLocInventIterator &X,
- const TemplateArgumentLocInventIterator &Y) {
- return X.Iter == Y.Iter;
- }
- friend bool operator!=(const TemplateArgumentLocInventIterator &X,
- const TemplateArgumentLocInventIterator &Y) {
- return X.Iter != Y.Iter;
- }
- };
- template<typename Derived>
- template<typename InputIterator>
- bool TreeTransform<Derived>::TransformTemplateArguments(
- InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
- bool Uneval) {
- for (; First != Last; ++First) {
- TemplateArgumentLoc Out;
- TemplateArgumentLoc In = *First;
- if (In.getArgument().getKind() == TemplateArgument::Pack) {
- // Unpack argument packs, which we translate them into separate
- // arguments.
- // FIXME: We could do much better if we could guarantee that the
- // TemplateArgumentLocInfo for the pack expansion would be usable for
- // all of the template arguments in the argument pack.
- typedef TemplateArgumentLocInventIterator<Derived,
- TemplateArgument::pack_iterator>
- PackLocIterator;
- if (TransformTemplateArguments(PackLocIterator(*this,
- In.getArgument().pack_begin()),
- PackLocIterator(*this,
- In.getArgument().pack_end()),
- Outputs, Uneval))
- return true;
- continue;
- }
- if (In.getArgument().isPackExpansion()) {
- // We have a pack expansion, for which we will be substituting into
- // the pattern.
- SourceLocation Ellipsis;
- Optional<unsigned> OrigNumExpansions;
- TemplateArgumentLoc Pattern
- = getSema().getTemplateArgumentPackExpansionPattern(
- In, Ellipsis, OrigNumExpansions);
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
- assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
- // Determine whether the set of unexpanded parameter packs can and should
- // be expanded.
- bool Expand = true;
- bool RetainExpansion = false;
- Optional<unsigned> NumExpansions = OrigNumExpansions;
- if (getDerived().TryExpandParameterPacks(Ellipsis,
- Pattern.getSourceRange(),
- Unexpanded,
- Expand,
- RetainExpansion,
- NumExpansions))
- return true;
- if (!Expand) {
- // The transform has determined that we should perform a simple
- // transformation on the pack expansion, producing another pack
- // expansion.
- TemplateArgumentLoc OutPattern;
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
- return true;
- Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
- NumExpansions);
- if (Out.getArgument().isNull())
- return true;
- Outputs.addArgument(Out);
- continue;
- }
- // The transform has determined that we should perform an elementwise
- // expansion of the pattern. Do so.
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
- if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
- return true;
- if (Out.getArgument().containsUnexpandedParameterPack()) {
- Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
- OrigNumExpansions);
- if (Out.getArgument().isNull())
- return true;
- }
- Outputs.addArgument(Out);
- }
- // If we're supposed to retain a pack expansion, do so by temporarily
- // forgetting the partially-substituted parameter pack.
- if (RetainExpansion) {
- ForgetPartiallySubstitutedPackRAII Forget(getDerived());
- if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
- return true;
- Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
- OrigNumExpansions);
- if (Out.getArgument().isNull())
- return true;
- Outputs.addArgument(Out);
- }
- continue;
- }
- // The simple case:
- if (getDerived().TransformTemplateArgument(In, Out, Uneval))
- return true;
- Outputs.addArgument(Out);
- }
- return false;
- }
- //===----------------------------------------------------------------------===//
- // Type transformation
- //===----------------------------------------------------------------------===//
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformType(QualType T) {
- if (getDerived().AlreadyTransformed(T))
- return T;
- // Temporary workaround. All of these transformations should
- // eventually turn into transformations on TypeLocs.
- TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
- getDerived().getBaseLocation());
- TypeSourceInfo *NewDI = getDerived().TransformType(DI);
- if (!NewDI)
- return QualType();
- return NewDI->getType();
- }
- template<typename Derived>
- TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
- // Refine the base location to the type's location.
- TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
- getDerived().getBaseEntity());
- if (getDerived().AlreadyTransformed(DI->getType()))
- return DI;
- TypeLocBuilder TLB;
- TypeLoc TL = DI->getTypeLoc();
- TLB.reserve(TL.getFullDataSize());
- QualType Result = getDerived().TransformType(TLB, TL);
- if (Result.isNull())
- return nullptr;
- return TLB.getTypeSourceInfo(SemaRef.Context, Result);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
- switch (T.getTypeLocClass()) {
- #define ABSTRACT_TYPELOC(CLASS, PARENT)
- #define TYPELOC(CLASS, PARENT) \
- case TypeLoc::CLASS: \
- return getDerived().Transform##CLASS##Type(TLB, \
- T.castAs<CLASS##TypeLoc>());
- #include "clang/AST/TypeLocNodes.def"
- }
- llvm_unreachable("unhandled type loc!");
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
- if (!isa<DependentNameType>(T))
- return TransformType(T);
- if (getDerived().AlreadyTransformed(T))
- return T;
- TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
- getDerived().getBaseLocation());
- TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
- return NewDI ? NewDI->getType() : QualType();
- }
- template<typename Derived>
- TypeSourceInfo *
- TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
- if (!isa<DependentNameType>(DI->getType()))
- return TransformType(DI);
- // Refine the base location to the type's location.
- TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
- getDerived().getBaseEntity());
- if (getDerived().AlreadyTransformed(DI->getType()))
- return DI;
- TypeLocBuilder TLB;
- TypeLoc TL = DI->getTypeLoc();
- TLB.reserve(TL.getFullDataSize());
- auto QTL = TL.getAs<QualifiedTypeLoc>();
- if (QTL)
- TL = QTL.getUnqualifiedLoc();
- auto DNTL = TL.castAs<DependentNameTypeLoc>();
- QualType Result = getDerived().TransformDependentNameType(
- TLB, DNTL, /*DeducedTSTContext*/true);
- if (Result.isNull())
- return nullptr;
- if (QTL) {
- Result = getDerived().RebuildQualifiedType(Result, QTL);
- if (Result.isNull())
- return nullptr;
- TLB.TypeWasModifiedSafely(Result);
- }
- return TLB.getTypeSourceInfo(SemaRef.Context, Result);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
- QualifiedTypeLoc T) {
- QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
- if (Result.isNull())
- return QualType();
- Result = getDerived().RebuildQualifiedType(Result, T);
- if (Result.isNull())
- return QualType();
- // RebuildQualifiedType might have updated the type, but not in a way
- // that invalidates the TypeLoc. (There's no location information for
- // qualifiers.)
- TLB.TypeWasModifiedSafely(Result);
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
- QualifiedTypeLoc TL) {
- SourceLocation Loc = TL.getBeginLoc();
- Qualifiers Quals = TL.getType().getLocalQualifiers();
- if ((T.getAddressSpace() != LangAS::Default &&
- Quals.getAddressSpace() != LangAS::Default) &&
- T.getAddressSpace() != Quals.getAddressSpace()) {
- SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
- << TL.getType() << T;
- return QualType();
- }
- // C++ [dcl.fct]p7:
- // [When] adding cv-qualifications on top of the function type [...] the
- // cv-qualifiers are ignored.
- if (T->isFunctionType()) {
- T = SemaRef.getASTContext().getAddrSpaceQualType(T,
- Quals.getAddressSpace());
- return T;
- }
- // C++ [dcl.ref]p1:
- // when the cv-qualifiers are introduced through the use of a typedef-name
- // or decltype-specifier [...] the cv-qualifiers are ignored.
- // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
- // applied to a reference type.
- if (T->isReferenceType()) {
- // The only qualifier that applies to a reference type is restrict.
- if (!Quals.hasRestrict())
- return T;
- Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
- }
- // Suppress Objective-C lifetime qualifiers if they don't make sense for the
- // resulting type.
- if (Quals.hasObjCLifetime()) {
- if (!T->isObjCLifetimeType() && !T->isDependentType())
- Quals.removeObjCLifetime();
- else if (T.getObjCLifetime()) {
- // Objective-C ARC:
- // A lifetime qualifier applied to a substituted template parameter
- // overrides the lifetime qualifier from the template argument.
- const AutoType *AutoTy;
- if (const SubstTemplateTypeParmType *SubstTypeParam
- = dyn_cast<SubstTemplateTypeParmType>(T)) {
- QualType Replacement = SubstTypeParam->getReplacementType();
- Qualifiers Qs = Replacement.getQualifiers();
- Qs.removeObjCLifetime();
- Replacement = SemaRef.Context.getQualifiedType(
- Replacement.getUnqualifiedType(), Qs);
- T = SemaRef.Context.getSubstTemplateTypeParmType(
- SubstTypeParam->getReplacedParameter(), Replacement);
- } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
- // 'auto' types behave the same way as template parameters.
- QualType Deduced = AutoTy->getDeducedType();
- Qualifiers Qs = Deduced.getQualifiers();
- Qs.removeObjCLifetime();
- Deduced =
- SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
- T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
- AutoTy->isDependentType(),
- /*isPack=*/false,
- AutoTy->getTypeConstraintConcept(),
- AutoTy->getTypeConstraintArguments());
- } else {
- // Otherwise, complain about the addition of a qualifier to an
- // already-qualified type.
- // FIXME: Why is this check not in Sema::BuildQualifiedType?
- SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
- Quals.removeObjCLifetime();
- }
- }
- }
- return SemaRef.BuildQualifiedType(T, Loc, Quals);
- }
- template<typename Derived>
- TypeLoc
- TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
- QualType ObjectType,
- NamedDecl *UnqualLookup,
- CXXScopeSpec &SS) {
- if (getDerived().AlreadyTransformed(TL.getType()))
- return TL;
- TypeSourceInfo *TSI =
- TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
- if (TSI)
- return TSI->getTypeLoc();
- return TypeLoc();
- }
- template<typename Derived>
- TypeSourceInfo *
- TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
- QualType ObjectType,
- NamedDecl *UnqualLookup,
- CXXScopeSpec &SS) {
- if (getDerived().AlreadyTransformed(TSInfo->getType()))
- return TSInfo;
- return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
- UnqualLookup, SS);
- }
- template <typename Derived>
- TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
- TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
- CXXScopeSpec &SS) {
- QualType T = TL.getType();
- assert(!getDerived().AlreadyTransformed(T));
- TypeLocBuilder TLB;
- QualType Result;
- if (isa<TemplateSpecializationType>(T)) {
- TemplateSpecializationTypeLoc SpecTL =
- TL.castAs<TemplateSpecializationTypeLoc>();
- TemplateName Template = getDerived().TransformTemplateName(
- SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
- ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
- if (Template.isNull())
- return nullptr;
- Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
- Template);
- } else if (isa<DependentTemplateSpecializationType>(T)) {
- DependentTemplateSpecializationTypeLoc SpecTL =
- TL.castAs<DependentTemplateSpecializationTypeLoc>();
- TemplateName Template
- = getDerived().RebuildTemplateName(SS,
- SpecTL.getTemplateKeywordLoc(),
- *SpecTL.getTypePtr()->getIdentifier(),
- SpecTL.getTemplateNameLoc(),
- ObjectType, UnqualLookup,
- /*AllowInjectedClassName*/true);
- if (Template.isNull())
- return nullptr;
- Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
- SpecTL,
- Template,
- SS);
- } else {
- // Nothing special needs to be done for these.
- Result = getDerived().TransformType(TLB, TL);
- }
- if (Result.isNull())
- return nullptr;
- return TLB.getTypeSourceInfo(SemaRef.Context, Result);
- }
- template <class TyLoc> static inline
- QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
- TyLoc NewT = TLB.push<TyLoc>(T.getType());
- NewT.setNameLoc(T.getNameLoc());
- return T.getType();
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
- BuiltinTypeLoc T) {
- BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
- NewT.setBuiltinLoc(T.getBuiltinLoc());
- if (T.needsExtraLocalData())
- NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
- return T.getType();
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
- ComplexTypeLoc T) {
- // FIXME: recurse?
- return TransformTypeSpecType(TLB, T);
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
- AdjustedTypeLoc TL) {
- // Adjustments applied during transformation are handled elsewhere.
- return getDerived().TransformType(TLB, TL.getOriginalLoc());
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
- DecayedTypeLoc TL) {
- QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
- if (OriginalType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- OriginalType != TL.getOriginalLoc().getType())
- Result = SemaRef.Context.getDecayedType(OriginalType);
- TLB.push<DecayedTypeLoc>(Result);
- // Nothing to set for DecayedTypeLoc.
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
- PointerTypeLoc TL) {
- QualType PointeeType
- = getDerived().TransformType(TLB, TL.getPointeeLoc());
- if (PointeeType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (PointeeType->getAs<ObjCObjectType>()) {
- // A dependent pointer type 'T *' has is being transformed such
- // that an Objective-C class type is being replaced for 'T'. The
- // resulting pointer type is an ObjCObjectPointerType, not a
- // PointerType.
- Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
- ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
- NewT.setStarLoc(TL.getStarLoc());
- return Result;
- }
- if (getDerived().AlwaysRebuild() ||
- PointeeType != TL.getPointeeLoc().getType()) {
- Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
- if (Result.isNull())
- return QualType();
- }
- // Objective-C ARC can add lifetime qualifiers to the type that we're
- // pointing to.
- TLB.TypeWasModifiedSafely(Result->getPointeeType());
- PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
- NewT.setSigilLoc(TL.getSigilLoc());
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
- BlockPointerTypeLoc TL) {
- QualType PointeeType
- = getDerived().TransformType(TLB, TL.getPointeeLoc());
- if (PointeeType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- PointeeType != TL.getPointeeLoc().getType()) {
- Result = getDerived().RebuildBlockPointerType(PointeeType,
- TL.getSigilLoc());
- if (Result.isNull())
- return QualType();
- }
- BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
- NewT.setSigilLoc(TL.getSigilLoc());
- return Result;
- }
- /// Transforms a reference type. Note that somewhat paradoxically we
- /// don't care whether the type itself is an l-value type or an r-value
- /// type; we only care if the type was *written* as an l-value type
- /// or an r-value type.
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
- ReferenceTypeLoc TL) {
- const ReferenceType *T = TL.getTypePtr();
- // Note that this works with the pointee-as-written.
- QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
- if (PointeeType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- PointeeType != T->getPointeeTypeAsWritten()) {
- Result = getDerived().RebuildReferenceType(PointeeType,
- T->isSpelledAsLValue(),
- TL.getSigilLoc());
- if (Result.isNull())
- return QualType();
- }
- // Objective-C ARC can add lifetime qualifiers to the type that we're
- // referring to.
- TLB.TypeWasModifiedSafely(
- Result->castAs<ReferenceType>()->getPointeeTypeAsWritten());
- // r-value references can be rebuilt as l-value references.
- ReferenceTypeLoc NewTL;
- if (isa<LValueReferenceType>(Result))
- NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
- else
- NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
- NewTL.setSigilLoc(TL.getSigilLoc());
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
- LValueReferenceTypeLoc TL) {
- return TransformReferenceType(TLB, TL);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
- RValueReferenceTypeLoc TL) {
- return TransformReferenceType(TLB, TL);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
- MemberPointerTypeLoc TL) {
- QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
- if (PointeeType.isNull())
- return QualType();
- TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
- TypeSourceInfo *NewClsTInfo = nullptr;
- if (OldClsTInfo) {
- NewClsTInfo = getDerived().TransformType(OldClsTInfo);
- if (!NewClsTInfo)
- return QualType();
- }
- const MemberPointerType *T = TL.getTypePtr();
- QualType OldClsType = QualType(T->getClass(), 0);
- QualType NewClsType;
- if (NewClsTInfo)
- NewClsType = NewClsTInfo->getType();
- else {
- NewClsType = getDerived().TransformType(OldClsType);
- if (NewClsType.isNull())
- return QualType();
- }
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- PointeeType != T->getPointeeType() ||
- NewClsType != OldClsType) {
- Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
- TL.getStarLoc());
- if (Result.isNull())
- return QualType();
- }
- // If we had to adjust the pointee type when building a member pointer, make
- // sure to push TypeLoc info for it.
- const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
- if (MPT && PointeeType != MPT->getPointeeType()) {
- assert(isa<AdjustedType>(MPT->getPointeeType()));
- TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
- }
- MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
- NewTL.setSigilLoc(TL.getSigilLoc());
- NewTL.setClassTInfo(NewClsTInfo);
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
- ConstantArrayTypeLoc TL) {
- const ConstantArrayType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
- if (ElementType.isNull())
- return QualType();
- // Prefer the expression from the TypeLoc; the other may have been uniqued.
- Expr *OldSize = TL.getSizeExpr();
- if (!OldSize)
- OldSize = const_cast<Expr*>(T->getSizeExpr());
- Expr *NewSize = nullptr;
- if (OldSize) {
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
- NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
- }
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ElementType != T->getElementType() ||
- (T->getSizeExpr() && NewSize != OldSize)) {
- Result = getDerived().RebuildConstantArrayType(ElementType,
- T->getSizeModifier(),
- T->getSize(), NewSize,
- T->getIndexTypeCVRQualifiers(),
- TL.getBracketsRange());
- if (Result.isNull())
- return QualType();
- }
- // We might have either a ConstantArrayType or a VariableArrayType now:
- // a ConstantArrayType is allowed to have an element type which is a
- // VariableArrayType if the type is dependent. Fortunately, all array
- // types have the same location layout.
- ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
- NewTL.setLBracketLoc(TL.getLBracketLoc());
- NewTL.setRBracketLoc(TL.getRBracketLoc());
- NewTL.setSizeExpr(NewSize);
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformIncompleteArrayType(
- TypeLocBuilder &TLB,
- IncompleteArrayTypeLoc TL) {
- const IncompleteArrayType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
- if (ElementType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ElementType != T->getElementType()) {
- Result = getDerived().RebuildIncompleteArrayType(ElementType,
- T->getSizeModifier(),
- T->getIndexTypeCVRQualifiers(),
- TL.getBracketsRange());
- if (Result.isNull())
- return QualType();
- }
- IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
- NewTL.setLBracketLoc(TL.getLBracketLoc());
- NewTL.setRBracketLoc(TL.getRBracketLoc());
- NewTL.setSizeExpr(nullptr);
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
- VariableArrayTypeLoc TL) {
- const VariableArrayType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
- if (ElementType.isNull())
- return QualType();
- ExprResult SizeResult;
- {
- EnterExpressionEvaluationContext Context(
- SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
- SizeResult = getDerived().TransformExpr(T->getSizeExpr());
- }
- if (SizeResult.isInvalid())
- return QualType();
- SizeResult =
- SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
- if (SizeResult.isInvalid())
- return QualType();
- Expr *Size = SizeResult.get();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ElementType != T->getElementType() ||
- Size != T->getSizeExpr()) {
- Result = getDerived().RebuildVariableArrayType(ElementType,
- T->getSizeModifier(),
- Size,
- T->getIndexTypeCVRQualifiers(),
- TL.getBracketsRange());
- if (Result.isNull())
- return QualType();
- }
- // We might have constant size array now, but fortunately it has the same
- // location layout.
- ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
- NewTL.setLBracketLoc(TL.getLBracketLoc());
- NewTL.setRBracketLoc(TL.getRBracketLoc());
- NewTL.setSizeExpr(Size);
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
- DependentSizedArrayTypeLoc TL) {
- const DependentSizedArrayType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
- if (ElementType.isNull())
- return QualType();
- // Array bounds are constant expressions.
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- // Prefer the expression from the TypeLoc; the other may have been uniqued.
- Expr *origSize = TL.getSizeExpr();
- if (!origSize) origSize = T->getSizeExpr();
- ExprResult sizeResult
- = getDerived().TransformExpr(origSize);
- sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
- if (sizeResult.isInvalid())
- return QualType();
- Expr *size = sizeResult.get();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ElementType != T->getElementType() ||
- size != origSize) {
- Result = getDerived().RebuildDependentSizedArrayType(ElementType,
- T->getSizeModifier(),
- size,
- T->getIndexTypeCVRQualifiers(),
- TL.getBracketsRange());
- if (Result.isNull())
- return QualType();
- }
- // We might have any sort of array type now, but fortunately they
- // all have the same location layout.
- ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
- NewTL.setLBracketLoc(TL.getLBracketLoc());
- NewTL.setRBracketLoc(TL.getRBracketLoc());
- NewTL.setSizeExpr(size);
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformDependentVectorType(
- TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
- const DependentVectorType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
- if (ElementType.isNull())
- return QualType();
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
- Size = SemaRef.ActOnConstantExpression(Size);
- if (Size.isInvalid())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
- Size.get() != T->getSizeExpr()) {
- Result = getDerived().RebuildDependentVectorType(
- ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
- if (Result.isNull())
- return QualType();
- }
- // Result might be dependent or not.
- if (isa<DependentVectorType>(Result)) {
- DependentVectorTypeLoc NewTL =
- TLB.push<DependentVectorTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- } else {
- VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- }
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
- TypeLocBuilder &TLB,
- DependentSizedExtVectorTypeLoc TL) {
- const DependentSizedExtVectorType *T = TL.getTypePtr();
- // FIXME: ext vector locs should be nested
- QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
- if (ElementType.isNull())
- return QualType();
- // Vector sizes are constant expressions.
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
- Size = SemaRef.ActOnConstantExpression(Size);
- if (Size.isInvalid())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ElementType != T->getElementType() ||
- Size.get() != T->getSizeExpr()) {
- Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
- Size.get(),
- T->getAttributeLoc());
- if (Result.isNull())
- return QualType();
- }
- // Result might be dependent or not.
- if (isa<DependentSizedExtVectorType>(Result)) {
- DependentSizedExtVectorTypeLoc NewTL
- = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- } else {
- ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- }
- return Result;
- }
- template <typename Derived>
- QualType
- TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
- ConstantMatrixTypeLoc TL) {
- const ConstantMatrixType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(T->getElementType());
- if (ElementType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
- Result = getDerived().RebuildConstantMatrixType(
- ElementType, T->getNumRows(), T->getNumColumns());
- if (Result.isNull())
- return QualType();
- }
- ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
- NewTL.setAttrNameLoc(TL.getAttrNameLoc());
- NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
- NewTL.setAttrRowOperand(TL.getAttrRowOperand());
- NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
- TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
- const DependentSizedMatrixType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(T->getElementType());
- if (ElementType.isNull()) {
- return QualType();
- }
- // Matrix dimensions are constant expressions.
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- Expr *origRows = TL.getAttrRowOperand();
- if (!origRows)
- origRows = T->getRowExpr();
- Expr *origColumns = TL.getAttrColumnOperand();
- if (!origColumns)
- origColumns = T->getColumnExpr();
- ExprResult rowResult = getDerived().TransformExpr(origRows);
- rowResult = SemaRef.ActOnConstantExpression(rowResult);
- if (rowResult.isInvalid())
- return QualType();
- ExprResult columnResult = getDerived().TransformExpr(origColumns);
- columnResult = SemaRef.ActOnConstantExpression(columnResult);
- if (columnResult.isInvalid())
- return QualType();
- Expr *rows = rowResult.get();
- Expr *columns = columnResult.get();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
- rows != origRows || columns != origColumns) {
- Result = getDerived().RebuildDependentSizedMatrixType(
- ElementType, rows, columns, T->getAttributeLoc());
- if (Result.isNull())
- return QualType();
- }
- // We might have any sort of matrix type now, but fortunately they
- // all have the same location layout.
- MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
- NewTL.setAttrNameLoc(TL.getAttrNameLoc());
- NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
- NewTL.setAttrRowOperand(rows);
- NewTL.setAttrColumnOperand(columns);
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
- TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
- const DependentAddressSpaceType *T = TL.getTypePtr();
- QualType pointeeType = getDerived().TransformType(T->getPointeeType());
- if (pointeeType.isNull())
- return QualType();
- // Address spaces are constant expressions.
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
- AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
- if (AddrSpace.isInvalid())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
- AddrSpace.get() != T->getAddrSpaceExpr()) {
- Result = getDerived().RebuildDependentAddressSpaceType(
- pointeeType, AddrSpace.get(), T->getAttributeLoc());
- if (Result.isNull())
- return QualType();
- }
- // Result might be dependent or not.
- if (isa<DependentAddressSpaceType>(Result)) {
- DependentAddressSpaceTypeLoc NewTL =
- TLB.push<DependentAddressSpaceTypeLoc>(Result);
- NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
- NewTL.setAttrExprOperand(TL.getAttrExprOperand());
- NewTL.setAttrNameLoc(TL.getAttrNameLoc());
- } else {
- TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
- Result, getDerived().getBaseLocation());
- TransformType(TLB, DI->getTypeLoc());
- }
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
- VectorTypeLoc TL) {
- const VectorType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
- if (ElementType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ElementType != T->getElementType()) {
- Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
- T->getVectorKind());
- if (Result.isNull())
- return QualType();
- }
- VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
- ExtVectorTypeLoc TL) {
- const VectorType *T = TL.getTypePtr();
- QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
- if (ElementType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ElementType != T->getElementType()) {
- Result = getDerived().RebuildExtVectorType(ElementType,
- T->getNumElements(),
- /*FIXME*/ SourceLocation());
- if (Result.isNull())
- return QualType();
- }
- ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- return Result;
- }
- template <typename Derived>
- ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
- ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
- bool ExpectParameterPack) {
- TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
- TypeSourceInfo *NewDI = nullptr;
- if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
- // If we're substituting into a pack expansion type and we know the
- // length we want to expand to, just substitute for the pattern.
- TypeLoc OldTL = OldDI->getTypeLoc();
- PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
- TypeLocBuilder TLB;
- TypeLoc NewTL = OldDI->getTypeLoc();
- TLB.reserve(NewTL.getFullDataSize());
- QualType Result = getDerived().TransformType(TLB,
- OldExpansionTL.getPatternLoc());
- if (Result.isNull())
- return nullptr;
- Result = RebuildPackExpansionType(Result,
- OldExpansionTL.getPatternLoc().getSourceRange(),
- OldExpansionTL.getEllipsisLoc(),
- NumExpansions);
- if (Result.isNull())
- return nullptr;
- PackExpansionTypeLoc NewExpansionTL
- = TLB.push<PackExpansionTypeLoc>(Result);
- NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
- NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
- } else
- NewDI = getDerived().TransformType(OldDI);
- if (!NewDI)
- return nullptr;
- if (NewDI == OldDI && indexAdjustment == 0)
- return OldParm;
- ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
- OldParm->getDeclContext(),
- OldParm->getInnerLocStart(),
- OldParm->getLocation(),
- OldParm->getIdentifier(),
- NewDI->getType(),
- NewDI,
- OldParm->getStorageClass(),
- /* DefArg */ nullptr);
- newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
- OldParm->getFunctionScopeIndex() + indexAdjustment);
- transformedLocalDecl(OldParm, {newParm});
- return newParm;
- }
- template <typename Derived>
- bool TreeTransform<Derived>::TransformFunctionTypeParams(
- SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
- const QualType *ParamTypes,
- const FunctionProtoType::ExtParameterInfo *ParamInfos,
- SmallVectorImpl<QualType> &OutParamTypes,
- SmallVectorImpl<ParmVarDecl *> *PVars,
- Sema::ExtParameterInfoBuilder &PInfos) {
- int indexAdjustment = 0;
- unsigned NumParams = Params.size();
- for (unsigned i = 0; i != NumParams; ++i) {
- if (ParmVarDecl *OldParm = Params[i]) {
- assert(OldParm->getFunctionScopeIndex() == i);
- Optional<unsigned> NumExpansions;
- ParmVarDecl *NewParm = nullptr;
- if (OldParm->isParameterPack()) {
- // We have a function parameter pack that may need to be expanded.
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- // Find the parameter packs that could be expanded.
- TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
- PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
- TypeLoc Pattern = ExpansionTL.getPatternLoc();
- SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
- // Determine whether we should expand the parameter packs.
- bool ShouldExpand = false;
- bool RetainExpansion = false;
- Optional<unsigned> OrigNumExpansions;
- if (Unexpanded.size() > 0) {
- OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
- NumExpansions = OrigNumExpansions;
- if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
- Pattern.getSourceRange(),
- Unexpanded,
- ShouldExpand,
- RetainExpansion,
- NumExpansions)) {
- return true;
- }
- } else {
- #ifndef NDEBUG
- const AutoType *AT =
- Pattern.getType().getTypePtr()->getContainedAutoType();
- assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
- "Could not find parameter packs or undeduced auto type!");
- #endif
- }
- if (ShouldExpand) {
- // Expand the function parameter pack into multiple, separate
- // parameters.
- getDerived().ExpandingFunctionParameterPack(OldParm);
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
- ParmVarDecl *NewParm
- = getDerived().TransformFunctionTypeParam(OldParm,
- indexAdjustment++,
- OrigNumExpansions,
- /*ExpectParameterPack=*/false);
- if (!NewParm)
- return true;
- if (ParamInfos)
- PInfos.set(OutParamTypes.size(), ParamInfos[i]);
- OutParamTypes.push_back(NewParm->getType());
- if (PVars)
- PVars->push_back(NewParm);
- }
- // If we're supposed to retain a pack expansion, do so by temporarily
- // forgetting the partially-substituted parameter pack.
- if (RetainExpansion) {
- ForgetPartiallySubstitutedPackRAII Forget(getDerived());
- ParmVarDecl *NewParm
- = getDerived().TransformFunctionTypeParam(OldParm,
- indexAdjustment++,
- OrigNumExpansions,
- /*ExpectParameterPack=*/false);
- if (!NewParm)
- return true;
- if (ParamInfos)
- PInfos.set(OutParamTypes.size(), ParamInfos[i]);
- OutParamTypes.push_back(NewParm->getType());
- if (PVars)
- PVars->push_back(NewParm);
- }
- // The next parameter should have the same adjustment as the
- // last thing we pushed, but we post-incremented indexAdjustment
- // on every push. Also, if we push nothing, the adjustment should
- // go down by one.
- indexAdjustment--;
- // We're done with the pack expansion.
- continue;
- }
- // We'll substitute the parameter now without expanding the pack
- // expansion.
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- NewParm = getDerived().TransformFunctionTypeParam(OldParm,
- indexAdjustment,
- NumExpansions,
- /*ExpectParameterPack=*/true);
- assert(NewParm->isParameterPack() &&
- "Parameter pack no longer a parameter pack after "
- "transformation.");
- } else {
- NewParm = getDerived().TransformFunctionTypeParam(
- OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
- }
- if (!NewParm)
- return true;
- if (ParamInfos)
- PInfos.set(OutParamTypes.size(), ParamInfos[i]);
- OutParamTypes.push_back(NewParm->getType());
- if (PVars)
- PVars->push_back(NewParm);
- continue;
- }
- // Deal with the possibility that we don't have a parameter
- // declaration for this parameter.
- QualType OldType = ParamTypes[i];
- bool IsPackExpansion = false;
- Optional<unsigned> NumExpansions;
- QualType NewType;
- if (const PackExpansionType *Expansion
- = dyn_cast<PackExpansionType>(OldType)) {
- // We have a function parameter pack that may need to be expanded.
- QualType Pattern = Expansion->getPattern();
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
- // Determine whether we should expand the parameter packs.
- bool ShouldExpand = false;
- bool RetainExpansion = false;
- if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
- Unexpanded,
- ShouldExpand,
- RetainExpansion,
- NumExpansions)) {
- return true;
- }
- if (ShouldExpand) {
- // Expand the function parameter pack into multiple, separate
- // parameters.
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
- QualType NewType = getDerived().TransformType(Pattern);
- if (NewType.isNull())
- return true;
- if (NewType->containsUnexpandedParameterPack()) {
- NewType =
- getSema().getASTContext().getPackExpansionType(NewType, None);
- if (NewType.isNull())
- return true;
- }
- if (ParamInfos)
- PInfos.set(OutParamTypes.size(), ParamInfos[i]);
- OutParamTypes.push_back(NewType);
- if (PVars)
- PVars->push_back(nullptr);
- }
- // We're done with the pack expansion.
- continue;
- }
- // If we're supposed to retain a pack expansion, do so by temporarily
- // forgetting the partially-substituted parameter pack.
- if (RetainExpansion) {
- ForgetPartiallySubstitutedPackRAII Forget(getDerived());
- QualType NewType = getDerived().TransformType(Pattern);
- if (NewType.isNull())
- return true;
- if (ParamInfos)
- PInfos.set(OutParamTypes.size(), ParamInfos[i]);
- OutParamTypes.push_back(NewType);
- if (PVars)
- PVars->push_back(nullptr);
- }
- // We'll substitute the parameter now without expanding the pack
- // expansion.
- OldType = Expansion->getPattern();
- IsPackExpansion = true;
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- NewType = getDerived().TransformType(OldType);
- } else {
- NewType = getDerived().TransformType(OldType);
- }
- if (NewType.isNull())
- return true;
- if (IsPackExpansion)
- NewType = getSema().Context.getPackExpansionType(NewType,
- NumExpansions);
- if (ParamInfos)
- PInfos.set(OutParamTypes.size(), ParamInfos[i]);
- OutParamTypes.push_back(NewType);
- if (PVars)
- PVars->push_back(nullptr);
- }
- #ifndef NDEBUG
- if (PVars) {
- for (unsigned i = 0, e = PVars->size(); i != e; ++i)
- if (ParmVarDecl *parm = (*PVars)[i])
- assert(parm->getFunctionScopeIndex() == i);
- }
- #endif
- return false;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
- FunctionProtoTypeLoc TL) {
- SmallVector<QualType, 4> ExceptionStorage;
- TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
- return getDerived().TransformFunctionProtoType(
- TLB, TL, nullptr, Qualifiers(),
- [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
- return This->getDerived().TransformExceptionSpec(
- TL.getBeginLoc(), ESI, ExceptionStorage, Changed);
- });
- }
- template<typename Derived> template<typename Fn>
- QualType TreeTransform<Derived>::TransformFunctionProtoType(
- TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
- Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
- // Transform the parameters and return type.
- //
- // We are required to instantiate the params and return type in source order.
- // When the function has a trailing return type, we instantiate the
- // parameters before the return type, since the return type can then refer
- // to the parameters themselves (via decltype, sizeof, etc.).
- //
- SmallVector<QualType, 4> ParamTypes;
- SmallVector<ParmVarDecl*, 4> ParamDecls;
- Sema::ExtParameterInfoBuilder ExtParamInfos;
- const FunctionProtoType *T = TL.getTypePtr();
- QualType ResultType;
- if (T->hasTrailingReturn()) {
- if (getDerived().TransformFunctionTypeParams(
- TL.getBeginLoc(), TL.getParams(),
- TL.getTypePtr()->param_type_begin(),
- T->getExtParameterInfosOrNull(),
- ParamTypes, &ParamDecls, ExtParamInfos))
- return QualType();
- {
- // C++11 [expr.prim.general]p3:
- // If a declaration declares a member function or member function
- // template of a class X, the expression this is a prvalue of type
- // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
- // and the end of the function-definition, member-declarator, or
- // declarator.
- Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
- ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
- if (ResultType.isNull())
- return QualType();
- }
- }
- else {
- ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
- if (ResultType.isNull())
- return QualType();
- if (getDerived().TransformFunctionTypeParams(
- TL.getBeginLoc(), TL.getParams(),
- TL.getTypePtr()->param_type_begin(),
- T->getExtParameterInfosOrNull(),
- ParamTypes, &ParamDecls, ExtParamInfos))
- return QualType();
- }
- FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
- bool EPIChanged = false;
- if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
- return QualType();
- // Handle extended parameter information.
- if (auto NewExtParamInfos =
- ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
- if (!EPI.ExtParameterInfos ||
- llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
- != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
- EPIChanged = true;
- }
- EPI.ExtParameterInfos = NewExtParamInfos;
- } else if (EPI.ExtParameterInfos) {
- EPIChanged = true;
- EPI.ExtParameterInfos = nullptr;
- }
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
- T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
- Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
- if (Result.isNull())
- return QualType();
- }
- FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
- NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
- NewTL.setLParenLoc(TL.getLParenLoc());
- NewTL.setRParenLoc(TL.getRParenLoc());
- NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
- NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
- for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
- NewTL.setParam(i, ParamDecls[i]);
- return Result;
- }
- template<typename Derived>
- bool TreeTransform<Derived>::TransformExceptionSpec(
- SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
- SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
- assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
- // Instantiate a dynamic noexcept expression, if any.
- if (isComputedNoexcept(ESI.Type)) {
- EnterExpressionEvaluationContext Unevaluated(
- getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
- ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
- if (NoexceptExpr.isInvalid())
- return true;
- ExceptionSpecificationType EST = ESI.Type;
- NoexceptExpr =
- getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
- if (NoexceptExpr.isInvalid())
- return true;
- if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
- Changed = true;
- ESI.NoexceptExpr = NoexceptExpr.get();
- ESI.Type = EST;
- }
- if (ESI.Type != EST_Dynamic)
- return false;
- // Instantiate a dynamic exception specification's type.
- for (QualType T : ESI.Exceptions) {
- if (const PackExpansionType *PackExpansion =
- T->getAs<PackExpansionType>()) {
- Changed = true;
- // We have a pack expansion. Instantiate it.
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
- Unexpanded);
- assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
- // Determine whether the set of unexpanded parameter packs can and
- // should
- // be expanded.
- bool Expand = false;
- bool RetainExpansion = false;
- Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
- // FIXME: Track the location of the ellipsis (and track source location
- // information for the types in the exception specification in general).
- if (getDerived().TryExpandParameterPacks(
- Loc, SourceRange(), Unexpanded, Expand,
- RetainExpansion, NumExpansions))
- return true;
- if (!Expand) {
- // We can't expand this pack expansion into separate arguments yet;
- // just substitute into the pattern and create a new pack expansion
- // type.
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- QualType U = getDerived().TransformType(PackExpansion->getPattern());
- if (U.isNull())
- return true;
- U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
- Exceptions.push_back(U);
- continue;
- }
- // Substitute into the pack expansion pattern for each slice of the
- // pack.
- for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
- QualType U = getDerived().TransformType(PackExpansion->getPattern());
- if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
- return true;
- Exceptions.push_back(U);
- }
- } else {
- QualType U = getDerived().TransformType(T);
- if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
- return true;
- if (T != U)
- Changed = true;
- Exceptions.push_back(U);
- }
- }
- ESI.Exceptions = Exceptions;
- if (ESI.Exceptions.empty())
- ESI.Type = EST_DynamicNone;
- return false;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
- TypeLocBuilder &TLB,
- FunctionNoProtoTypeLoc TL) {
- const FunctionNoProtoType *T = TL.getTypePtr();
- QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
- if (ResultType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
- Result = getDerived().RebuildFunctionNoProtoType(ResultType);
- FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
- NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
- NewTL.setLParenLoc(TL.getLParenLoc());
- NewTL.setRParenLoc(TL.getRParenLoc());
- NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
- TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
- const UnresolvedUsingType *T = TL.getTypePtr();
- Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
- if (!D)
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
- Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
- if (Result.isNull())
- return QualType();
- }
- // We might get an arbitrary type spec type back. We should at
- // least always get a type spec type, though.
- TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
- UsingTypeLoc TL) {
- const UsingType *T = TL.getTypePtr();
- auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
- TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
- if (!Found)
- return QualType();
- QualType Underlying = getDerived().TransformType(T->desugar());
- if (Underlying.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() ||
- Underlying != T->getUnderlyingType()) {
- Result = getDerived().RebuildUsingType(Found, Underlying);
- if (Result.isNull())
- return QualType();
- }
- TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
- TypedefTypeLoc TL) {
- const TypedefType *T = TL.getTypePtr();
- TypedefNameDecl *Typedef
- = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
- T->getDecl()));
- if (!Typedef)
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- Typedef != T->getDecl()) {
- Result = getDerived().RebuildTypedefType(Typedef);
- if (Result.isNull())
- return QualType();
- }
- TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
- TypeOfExprTypeLoc TL) {
- // typeof expressions are not potentially evaluated contexts
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
- Sema::ReuseLambdaContextDecl);
- ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
- if (E.isInvalid())
- return QualType();
- E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
- if (E.isInvalid())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- E.get() != TL.getUnderlyingExpr()) {
- Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
- if (Result.isNull())
- return QualType();
- }
- else E.get();
- TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
- NewTL.setTypeofLoc(TL.getTypeofLoc());
- NewTL.setLParenLoc(TL.getLParenLoc());
- NewTL.setRParenLoc(TL.getRParenLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
- TypeOfTypeLoc TL) {
- TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
- TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
- if (!New_Under_TI)
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
- Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
- if (Result.isNull())
- return QualType();
- }
- TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
- NewTL.setTypeofLoc(TL.getTypeofLoc());
- NewTL.setLParenLoc(TL.getLParenLoc());
- NewTL.setRParenLoc(TL.getRParenLoc());
- NewTL.setUnderlyingTInfo(New_Under_TI);
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
- DecltypeTypeLoc TL) {
- const DecltypeType *T = TL.getTypePtr();
- // decltype expressions are not potentially evaluated contexts
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
- Sema::ExpressionEvaluationContextRecord::EK_Decltype);
- ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
- if (E.isInvalid())
- return QualType();
- E = getSema().ActOnDecltypeExpression(E.get());
- if (E.isInvalid())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- E.get() != T->getUnderlyingExpr()) {
- Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
- if (Result.isNull())
- return QualType();
- }
- else E.get();
- DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
- NewTL.setDecltypeLoc(TL.getDecltypeLoc());
- NewTL.setRParenLoc(TL.getRParenLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformUnaryTransformType(
- TypeLocBuilder &TLB,
- UnaryTransformTypeLoc TL) {
- QualType Result = TL.getType();
- if (Result->isDependentType()) {
- const UnaryTransformType *T = TL.getTypePtr();
- QualType NewBase =
- getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
- Result = getDerived().RebuildUnaryTransformType(NewBase,
- T->getUTTKind(),
- TL.getKWLoc());
- if (Result.isNull())
- return QualType();
- }
- UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
- NewTL.setKWLoc(TL.getKWLoc());
- NewTL.setParensRange(TL.getParensRange());
- NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
- TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
- const DeducedTemplateSpecializationType *T = TL.getTypePtr();
- CXXScopeSpec SS;
- TemplateName TemplateName = getDerived().TransformTemplateName(
- SS, T->getTemplateName(), TL.getTemplateNameLoc());
- if (TemplateName.isNull())
- return QualType();
- QualType OldDeduced = T->getDeducedType();
- QualType NewDeduced;
- if (!OldDeduced.isNull()) {
- NewDeduced = getDerived().TransformType(OldDeduced);
- if (NewDeduced.isNull())
- return QualType();
- }
- QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
- TemplateName, NewDeduced);
- if (Result.isNull())
- return QualType();
- DeducedTemplateSpecializationTypeLoc NewTL =
- TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
- NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
- RecordTypeLoc TL) {
- const RecordType *T = TL.getTypePtr();
- RecordDecl *Record
- = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
- T->getDecl()));
- if (!Record)
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- Record != T->getDecl()) {
- Result = getDerived().RebuildRecordType(Record);
- if (Result.isNull())
- return QualType();
- }
- RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
- EnumTypeLoc TL) {
- const EnumType *T = TL.getTypePtr();
- EnumDecl *Enum
- = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
- T->getDecl()));
- if (!Enum)
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- Enum != T->getDecl()) {
- Result = getDerived().RebuildEnumType(Enum);
- if (Result.isNull())
- return QualType();
- }
- EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformInjectedClassNameType(
- TypeLocBuilder &TLB,
- InjectedClassNameTypeLoc TL) {
- Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
- TL.getTypePtr()->getDecl());
- if (!D) return QualType();
- QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
- TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
- return T;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
- TypeLocBuilder &TLB,
- TemplateTypeParmTypeLoc TL) {
- return TransformTypeSpecType(TLB, TL);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
- TypeLocBuilder &TLB,
- SubstTemplateTypeParmTypeLoc TL) {
- const SubstTemplateTypeParmType *T = TL.getTypePtr();
- // Substitute into the replacement type, which itself might involve something
- // that needs to be transformed. This only tends to occur with default
- // template arguments of template template parameters.
- TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
- QualType Replacement = getDerived().TransformType(T->getReplacementType());
- if (Replacement.isNull())
- return QualType();
- // Always canonicalize the replacement type.
- Replacement = SemaRef.Context.getCanonicalType(Replacement);
- QualType Result
- = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
- Replacement);
- // Propagate type-source information.
- SubstTemplateTypeParmTypeLoc NewTL
- = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
- TypeLocBuilder &TLB,
- SubstTemplateTypeParmPackTypeLoc TL) {
- return TransformTypeSpecType(TLB, TL);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
- TypeLocBuilder &TLB,
- TemplateSpecializationTypeLoc TL) {
- const TemplateSpecializationType *T = TL.getTypePtr();
- // The nested-name-specifier never matters in a TemplateSpecializationType,
- // because we can't have a dependent nested-name-specifier anyway.
- CXXScopeSpec SS;
- TemplateName Template
- = getDerived().TransformTemplateName(SS, T->getTemplateName(),
- TL.getTemplateNameLoc());
- if (Template.isNull())
- return QualType();
- return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
- AtomicTypeLoc TL) {
- QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
- if (ValueType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- ValueType != TL.getValueLoc().getType()) {
- Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
- if (Result.isNull())
- return QualType();
- }
- AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
- NewTL.setKWLoc(TL.getKWLoc());
- NewTL.setLParenLoc(TL.getLParenLoc());
- NewTL.setRParenLoc(TL.getRParenLoc());
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
- PipeTypeLoc TL) {
- QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
- if (ValueType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
- const PipeType *PT = Result->castAs<PipeType>();
- bool isReadPipe = PT->isReadOnly();
- Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
- if (Result.isNull())
- return QualType();
- }
- PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
- NewTL.setKWLoc(TL.getKWLoc());
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
- BitIntTypeLoc TL) {
- const BitIntType *EIT = TL.getTypePtr();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild()) {
- Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
- EIT->getNumBits(), TL.getNameLoc());
- if (Result.isNull())
- return QualType();
- }
- BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformDependentBitIntType(
- TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
- const DependentBitIntType *EIT = TL.getTypePtr();
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
- BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
- if (BitsExpr.isInvalid())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
- Result = getDerived().RebuildDependentBitIntType(
- EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
- if (Result.isNull())
- return QualType();
- }
- if (isa<DependentBitIntType>(Result)) {
- DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- } else {
- BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- }
- return Result;
- }
- /// Simple iterator that traverses the template arguments in a
- /// container that provides a \c getArgLoc() member function.
- ///
- /// This iterator is intended to be used with the iterator form of
- /// \c TreeTransform<Derived>::TransformTemplateArguments().
- template<typename ArgLocContainer>
- class TemplateArgumentLocContainerIterator {
- ArgLocContainer *Container;
- unsigned Index;
- public:
- typedef TemplateArgumentLoc value_type;
- typedef TemplateArgumentLoc reference;
- typedef int difference_type;
- typedef std::input_iterator_tag iterator_category;
- class pointer {
- TemplateArgumentLoc Arg;
- public:
- explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
- const TemplateArgumentLoc *operator->() const {
- return &Arg;
- }
- };
- TemplateArgumentLocContainerIterator() {}
- TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
- unsigned Index)
- : Container(&Container), Index(Index) { }
- TemplateArgumentLocContainerIterator &operator++() {
- ++Index;
- return *this;
- }
- TemplateArgumentLocContainerIterator operator++(int) {
- TemplateArgumentLocContainerIterator Old(*this);
- ++(*this);
- return Old;
- }
- TemplateArgumentLoc operator*() const {
- return Container->getArgLoc(Index);
- }
- pointer operator->() const {
- return pointer(Container->getArgLoc(Index));
- }
- friend bool operator==(const TemplateArgumentLocContainerIterator &X,
- const TemplateArgumentLocContainerIterator &Y) {
- return X.Container == Y.Container && X.Index == Y.Index;
- }
- friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
- const TemplateArgumentLocContainerIterator &Y) {
- return !(X == Y);
- }
- };
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
- AutoTypeLoc TL) {
- const AutoType *T = TL.getTypePtr();
- QualType OldDeduced = T->getDeducedType();
- QualType NewDeduced;
- if (!OldDeduced.isNull()) {
- NewDeduced = getDerived().TransformType(OldDeduced);
- if (NewDeduced.isNull())
- return QualType();
- }
- ConceptDecl *NewCD = nullptr;
- TemplateArgumentListInfo NewTemplateArgs;
- NestedNameSpecifierLoc NewNestedNameSpec;
- if (T->isConstrained()) {
- NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
- TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
- NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
- NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
- typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
- if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
- ArgIterator(TL,
- TL.getNumArgs()),
- NewTemplateArgs))
- return QualType();
- if (TL.getNestedNameSpecifierLoc()) {
- NewNestedNameSpec
- = getDerived().TransformNestedNameSpecifierLoc(
- TL.getNestedNameSpecifierLoc());
- if (!NewNestedNameSpec)
- return QualType();
- }
- }
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
- T->isDependentType() || T->isConstrained()) {
- // FIXME: Maybe don't rebuild if all template arguments are the same.
- llvm::SmallVector<TemplateArgument, 4> NewArgList;
- NewArgList.reserve(NewTemplateArgs.size());
- for (const auto &ArgLoc : NewTemplateArgs.arguments())
- NewArgList.push_back(ArgLoc.getArgument());
- Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
- NewArgList);
- if (Result.isNull())
- return QualType();
- }
- AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
- NewTL.setNameLoc(TL.getNameLoc());
- NewTL.setNestedNameSpecifierLoc(NewNestedNameSpec);
- NewTL.setTemplateKWLoc(TL.getTemplateKWLoc());
- NewTL.setConceptNameLoc(TL.getConceptNameLoc());
- NewTL.setFoundDecl(TL.getFoundDecl());
- NewTL.setLAngleLoc(TL.getLAngleLoc());
- NewTL.setRAngleLoc(TL.getRAngleLoc());
- NewTL.setRParenLoc(TL.getRParenLoc());
- for (unsigned I = 0; I < NewTL.getNumArgs(); ++I)
- NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo());
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
- TypeLocBuilder &TLB,
- TemplateSpecializationTypeLoc TL,
- TemplateName Template) {
- TemplateArgumentListInfo NewTemplateArgs;
- NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
- NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
- typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
- ArgIterator;
- if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
- ArgIterator(TL, TL.getNumArgs()),
- NewTemplateArgs))
- return QualType();
- // FIXME: maybe don't rebuild if all the template arguments are the same.
- QualType Result =
- getDerived().RebuildTemplateSpecializationType(Template,
- TL.getTemplateNameLoc(),
- NewTemplateArgs);
- if (!Result.isNull()) {
- // Specializations of template template parameters are represented as
- // TemplateSpecializationTypes, and substitution of type alias templates
- // within a dependent context can transform them into
- // DependentTemplateSpecializationTypes.
- if (isa<DependentTemplateSpecializationType>(Result)) {
- DependentTemplateSpecializationTypeLoc NewTL
- = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
- NewTL.setElaboratedKeywordLoc(SourceLocation());
- NewTL.setQualifierLoc(NestedNameSpecifierLoc());
- NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
- NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
- NewTL.setLAngleLoc(TL.getLAngleLoc());
- NewTL.setRAngleLoc(TL.getRAngleLoc());
- for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
- NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
- return Result;
- }
- TemplateSpecializationTypeLoc NewTL
- = TLB.push<TemplateSpecializationTypeLoc>(Result);
- NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
- NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
- NewTL.setLAngleLoc(TL.getLAngleLoc());
- NewTL.setRAngleLoc(TL.getRAngleLoc());
- for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
- NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
- }
- return Result;
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
- TypeLocBuilder &TLB,
- DependentTemplateSpecializationTypeLoc TL,
- TemplateName Template,
- CXXScopeSpec &SS) {
- TemplateArgumentListInfo NewTemplateArgs;
- NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
- NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
- typedef TemplateArgumentLocContainerIterator<
- DependentTemplateSpecializationTypeLoc> ArgIterator;
- if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
- ArgIterator(TL, TL.getNumArgs()),
- NewTemplateArgs))
- return QualType();
- // FIXME: maybe don't rebuild if all the template arguments are the same.
- if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
- QualType Result
- = getSema().Context.getDependentTemplateSpecializationType(
- TL.getTypePtr()->getKeyword(),
- DTN->getQualifier(),
- DTN->getIdentifier(),
- NewTemplateArgs);
- DependentTemplateSpecializationTypeLoc NewTL
- = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
- NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
- NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
- NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
- NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
- NewTL.setLAngleLoc(TL.getLAngleLoc());
- NewTL.setRAngleLoc(TL.getRAngleLoc());
- for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
- NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
- return Result;
- }
- QualType Result
- = getDerived().RebuildTemplateSpecializationType(Template,
- TL.getTemplateNameLoc(),
- NewTemplateArgs);
- if (!Result.isNull()) {
- /// FIXME: Wrap this in an elaborated-type-specifier?
- TemplateSpecializationTypeLoc NewTL
- = TLB.push<TemplateSpecializationTypeLoc>(Result);
- NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
- NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
- NewTL.setLAngleLoc(TL.getLAngleLoc());
- NewTL.setRAngleLoc(TL.getRAngleLoc());
- for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
- NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
- }
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
- ElaboratedTypeLoc TL) {
- const ElaboratedType *T = TL.getTypePtr();
- NestedNameSpecifierLoc QualifierLoc;
- // NOTE: the qualifier in an ElaboratedType is optional.
- if (TL.getQualifierLoc()) {
- QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
- if (!QualifierLoc)
- return QualType();
- }
- QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
- if (NamedT.isNull())
- return QualType();
- // C++0x [dcl.type.elab]p2:
- // If the identifier resolves to a typedef-name or the simple-template-id
- // resolves to an alias template specialization, the
- // elaborated-type-specifier is ill-formed.
- if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
- if (const TemplateSpecializationType *TST =
- NamedT->getAs<TemplateSpecializationType>()) {
- TemplateName Template = TST->getTemplateName();
- if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
- Template.getAsTemplateDecl())) {
- SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
- diag::err_tag_reference_non_tag)
- << TAT << Sema::NTK_TypeAliasTemplate
- << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
- SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
- }
- }
- }
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- QualifierLoc != TL.getQualifierLoc() ||
- NamedT != T->getNamedType()) {
- Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
- T->getKeyword(),
- QualifierLoc, NamedT);
- if (Result.isNull())
- return QualType();
- }
- ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
- NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
- NewTL.setQualifierLoc(QualifierLoc);
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformAttributedType(
- TypeLocBuilder &TLB,
- AttributedTypeLoc TL) {
- const AttributedType *oldType = TL.getTypePtr();
- QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
- if (modifiedType.isNull())
- return QualType();
- // oldAttr can be null if we started with a QualType rather than a TypeLoc.
- const Attr *oldAttr = TL.getAttr();
- const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
- if (oldAttr && !newAttr)
- return QualType();
- QualType result = TL.getType();
- // FIXME: dependent operand expressions?
- if (getDerived().AlwaysRebuild() ||
- modifiedType != oldType->getModifiedType()) {
- // TODO: this is really lame; we should really be rebuilding the
- // equivalent type from first principles.
- QualType equivalentType
- = getDerived().TransformType(oldType->getEquivalentType());
- if (equivalentType.isNull())
- return QualType();
- // Check whether we can add nullability; it is only represented as
- // type sugar, and therefore cannot be diagnosed in any other way.
- if (auto nullability = oldType->getImmediateNullability()) {
- if (!modifiedType->canHaveNullability()) {
- SemaRef.Diag(TL.getAttr()->getLocation(),
- diag::err_nullability_nonpointer)
- << DiagNullabilityKind(*nullability, false) << modifiedType;
- return QualType();
- }
- }
- result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
- modifiedType,
- equivalentType);
- }
- AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
- newTL.setAttr(newAttr);
- return result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
- ParenTypeLoc TL) {
- QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
- if (Inner.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- Inner != TL.getInnerLoc().getType()) {
- Result = getDerived().RebuildParenType(Inner);
- if (Result.isNull())
- return QualType();
- }
- ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
- NewTL.setLParenLoc(TL.getLParenLoc());
- NewTL.setRParenLoc(TL.getRParenLoc());
- return Result;
- }
- template <typename Derived>
- QualType
- TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
- MacroQualifiedTypeLoc TL) {
- QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
- if (Inner.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
- Result =
- getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
- if (Result.isNull())
- return QualType();
- }
- MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
- NewTL.setExpansionLoc(TL.getExpansionLoc());
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformDependentNameType(
- TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
- return TransformDependentNameType(TLB, TL, false);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformDependentNameType(
- TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
- const DependentNameType *T = TL.getTypePtr();
- NestedNameSpecifierLoc QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
- if (!QualifierLoc)
- return QualType();
- QualType Result
- = getDerived().RebuildDependentNameType(T->getKeyword(),
- TL.getElaboratedKeywordLoc(),
- QualifierLoc,
- T->getIdentifier(),
- TL.getNameLoc(),
- DeducedTSTContext);
- if (Result.isNull())
- return QualType();
- if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
- QualType NamedT = ElabT->getNamedType();
- TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
- ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
- NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
- NewTL.setQualifierLoc(QualifierLoc);
- } else {
- DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
- NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
- NewTL.setQualifierLoc(QualifierLoc);
- NewTL.setNameLoc(TL.getNameLoc());
- }
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::
- TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
- DependentTemplateSpecializationTypeLoc TL) {
- NestedNameSpecifierLoc QualifierLoc;
- if (TL.getQualifierLoc()) {
- QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
- if (!QualifierLoc)
- return QualType();
- }
- return getDerived()
- .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::
- TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
- DependentTemplateSpecializationTypeLoc TL,
- NestedNameSpecifierLoc QualifierLoc) {
- const DependentTemplateSpecializationType *T = TL.getTypePtr();
- TemplateArgumentListInfo NewTemplateArgs;
- NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
- NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
- typedef TemplateArgumentLocContainerIterator<
- DependentTemplateSpecializationTypeLoc> ArgIterator;
- if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
- ArgIterator(TL, TL.getNumArgs()),
- NewTemplateArgs))
- return QualType();
- QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
- T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
- T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
- /*AllowInjectedClassName*/ false);
- if (Result.isNull())
- return QualType();
- if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
- QualType NamedT = ElabT->getNamedType();
- // Copy information relevant to the template specialization.
- TemplateSpecializationTypeLoc NamedTL
- = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
- NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
- NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
- NamedTL.setLAngleLoc(TL.getLAngleLoc());
- NamedTL.setRAngleLoc(TL.getRAngleLoc());
- for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
- NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
- // Copy information relevant to the elaborated type.
- ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
- NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
- NewTL.setQualifierLoc(QualifierLoc);
- } else if (isa<DependentTemplateSpecializationType>(Result)) {
- DependentTemplateSpecializationTypeLoc SpecTL
- = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
- SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
- SpecTL.setQualifierLoc(QualifierLoc);
- SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
- SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
- SpecTL.setLAngleLoc(TL.getLAngleLoc());
- SpecTL.setRAngleLoc(TL.getRAngleLoc());
- for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
- SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
- } else {
- TemplateSpecializationTypeLoc SpecTL
- = TLB.push<TemplateSpecializationTypeLoc>(Result);
- SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
- SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
- SpecTL.setLAngleLoc(TL.getLAngleLoc());
- SpecTL.setRAngleLoc(TL.getRAngleLoc());
- for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
- SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
- }
- return Result;
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
- PackExpansionTypeLoc TL) {
- QualType Pattern
- = getDerived().TransformType(TLB, TL.getPatternLoc());
- if (Pattern.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- Pattern != TL.getPatternLoc().getType()) {
- Result = getDerived().RebuildPackExpansionType(Pattern,
- TL.getPatternLoc().getSourceRange(),
- TL.getEllipsisLoc(),
- TL.getTypePtr()->getNumExpansions());
- if (Result.isNull())
- return QualType();
- }
- PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
- NewT.setEllipsisLoc(TL.getEllipsisLoc());
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
- ObjCInterfaceTypeLoc TL) {
- // ObjCInterfaceType is never dependent.
- TLB.pushFullCopy(TL);
- return TL.getType();
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
- ObjCTypeParamTypeLoc TL) {
- const ObjCTypeParamType *T = TL.getTypePtr();
- ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
- getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
- if (!OTP)
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- OTP != T->getDecl()) {
- Result = getDerived().RebuildObjCTypeParamType(OTP,
- TL.getProtocolLAngleLoc(),
- llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
- TL.getNumProtocols()),
- TL.getProtocolLocs(),
- TL.getProtocolRAngleLoc());
- if (Result.isNull())
- return QualType();
- }
- ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
- if (TL.getNumProtocols()) {
- NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
- for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
- NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
- NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
- }
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
- ObjCObjectTypeLoc TL) {
- // Transform base type.
- QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
- if (BaseType.isNull())
- return QualType();
- bool AnyChanged = BaseType != TL.getBaseLoc().getType();
- // Transform type arguments.
- SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
- for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
- TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
- TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
- QualType TypeArg = TypeArgInfo->getType();
- if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
- AnyChanged = true;
- // We have a pack expansion. Instantiate it.
- const auto *PackExpansion = PackExpansionLoc.getType()
- ->castAs<PackExpansionType>();
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
- Unexpanded);
- assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
- // Determine whether the set of unexpanded parameter packs can
- // and should be expanded.
- TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
- bool Expand = false;
- bool RetainExpansion = false;
- Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
- if (getDerived().TryExpandParameterPacks(
- PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
- Unexpanded, Expand, RetainExpansion, NumExpansions))
- return QualType();
- if (!Expand) {
- // We can't expand this pack expansion into separate arguments yet;
- // just substitute into the pattern and create a new pack expansion
- // type.
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- TypeLocBuilder TypeArgBuilder;
- TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
- QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
- PatternLoc);
- if (NewPatternType.isNull())
- return QualType();
- QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
- NewPatternType, NumExpansions);
- auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
- NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
- NewTypeArgInfos.push_back(
- TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
- continue;
- }
- // Substitute into the pack expansion pattern for each slice of the
- // pack.
- for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
- TypeLocBuilder TypeArgBuilder;
- TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
- QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
- PatternLoc);
- if (NewTypeArg.isNull())
- return QualType();
- NewTypeArgInfos.push_back(
- TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
- }
- continue;
- }
- TypeLocBuilder TypeArgBuilder;
- TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
- QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
- if (NewTypeArg.isNull())
- return QualType();
- // If nothing changed, just keep the old TypeSourceInfo.
- if (NewTypeArg == TypeArg) {
- NewTypeArgInfos.push_back(TypeArgInfo);
- continue;
- }
- NewTypeArgInfos.push_back(
- TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
- AnyChanged = true;
- }
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() || AnyChanged) {
- // Rebuild the type.
- Result = getDerived().RebuildObjCObjectType(
- BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
- TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
- llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
- TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
- if (Result.isNull())
- return QualType();
- }
- ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
- NewT.setHasBaseTypeAsWritten(true);
- NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
- for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
- NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
- NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
- NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
- for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
- NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
- NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
- return Result;
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
- ObjCObjectPointerTypeLoc TL) {
- QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
- if (PointeeType.isNull())
- return QualType();
- QualType Result = TL.getType();
- if (getDerived().AlwaysRebuild() ||
- PointeeType != TL.getPointeeLoc().getType()) {
- Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
- TL.getStarLoc());
- if (Result.isNull())
- return QualType();
- }
- ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
- NewT.setStarLoc(TL.getStarLoc());
- return Result;
- }
- //===----------------------------------------------------------------------===//
- // Statement transformation
- //===----------------------------------------------------------------------===//
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
- return S;
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
- return getDerived().TransformCompoundStmt(S, false);
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
- bool IsStmtExpr) {
- Sema::CompoundScopeRAII CompoundScope(getSema());
- const Stmt *ExprResult = S->getStmtExprResult();
- bool SubStmtInvalid = false;
- bool SubStmtChanged = false;
- SmallVector<Stmt*, 8> Statements;
- for (auto *B : S->body()) {
- StmtResult Result = getDerived().TransformStmt(
- B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
- if (Result.isInvalid()) {
- // Immediately fail if this was a DeclStmt, since it's very
- // likely that this will cause problems for future statements.
- if (isa<DeclStmt>(B))
- return StmtError();
- // Otherwise, just keep processing substatements and fail later.
- SubStmtInvalid = true;
- continue;
- }
- SubStmtChanged = SubStmtChanged || Result.get() != B;
- Statements.push_back(Result.getAs<Stmt>());
- }
- if (SubStmtInvalid)
- return StmtError();
- if (!getDerived().AlwaysRebuild() &&
- !SubStmtChanged)
- return S;
- return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
- Statements,
- S->getRBracLoc(),
- IsStmtExpr);
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
- ExprResult LHS, RHS;
- {
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
- // Transform the left-hand case value.
- LHS = getDerived().TransformExpr(S->getLHS());
- LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
- if (LHS.isInvalid())
- return StmtError();
- // Transform the right-hand case value (for the GNU case-range extension).
- RHS = getDerived().TransformExpr(S->getRHS());
- RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
- if (RHS.isInvalid())
- return StmtError();
- }
- // Build the case statement.
- // Case statements are always rebuilt so that they will attached to their
- // transformed switch statement.
- StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
- LHS.get(),
- S->getEllipsisLoc(),
- RHS.get(),
- S->getColonLoc());
- if (Case.isInvalid())
- return StmtError();
- // Transform the statement following the case
- StmtResult SubStmt =
- getDerived().TransformStmt(S->getSubStmt());
- if (SubStmt.isInvalid())
- return StmtError();
- // Attach the body to the case statement
- return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
- // Transform the statement following the default case
- StmtResult SubStmt =
- getDerived().TransformStmt(S->getSubStmt());
- if (SubStmt.isInvalid())
- return StmtError();
- // Default statements are always rebuilt
- return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
- SubStmt.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
- StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
- if (SubStmt.isInvalid())
- return StmtError();
- Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
- S->getDecl());
- if (!LD)
- return StmtError();
- // If we're transforming "in-place" (we're not creating new local
- // declarations), assume we're replacing the old label statement
- // and clear out the reference to it.
- if (LD == S->getDecl())
- S->getDecl()->setStmt(nullptr);
- // FIXME: Pass the real colon location in.
- return getDerived().RebuildLabelStmt(S->getIdentLoc(),
- cast<LabelDecl>(LD), SourceLocation(),
- SubStmt.get());
- }
- template <typename Derived>
- const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
- if (!R)
- return R;
- switch (R->getKind()) {
- // Transform attributes with a pragma spelling by calling TransformXXXAttr.
- #define ATTR(X)
- #define PRAGMA_SPELLING_ATTR(X) \
- case attr::X: \
- return getDerived().Transform##X##Attr(cast<X##Attr>(R));
- #include "clang/Basic/AttrList.inc"
- default:
- return R;
- }
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
- StmtDiscardKind SDK) {
- bool AttrsChanged = false;
- SmallVector<const Attr *, 1> Attrs;
- // Visit attributes and keep track if any are transformed.
- for (const auto *I : S->getAttrs()) {
- const Attr *R = getDerived().TransformAttr(I);
- AttrsChanged |= (I != R);
- if (R)
- Attrs.push_back(R);
- }
- StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
- if (SubStmt.isInvalid())
- return StmtError();
- if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
- return S;
- // If transforming the attributes failed for all of the attributes in the
- // statement, don't make an AttributedStmt without attributes.
- if (Attrs.empty())
- return SubStmt;
- return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
- SubStmt.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
- // Transform the initialization statement
- StmtResult Init = getDerived().TransformStmt(S->getInit());
- if (Init.isInvalid())
- return StmtError();
- Sema::ConditionResult Cond;
- if (!S->isConsteval()) {
- // Transform the condition
- Cond = getDerived().TransformCondition(
- S->getIfLoc(), S->getConditionVariable(), S->getCond(),
- S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
- : Sema::ConditionKind::Boolean);
- if (Cond.isInvalid())
- return StmtError();
- }
- // If this is a constexpr if, determine which arm we should instantiate.
- llvm::Optional<bool> ConstexprConditionValue;
- if (S->isConstexpr())
- ConstexprConditionValue = Cond.getKnownValue();
- // Transform the "then" branch.
- StmtResult Then;
- if (!ConstexprConditionValue || *ConstexprConditionValue) {
- Then = getDerived().TransformStmt(S->getThen());
- if (Then.isInvalid())
- return StmtError();
- } else {
- Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
- }
- // Transform the "else" branch.
- StmtResult Else;
- if (!ConstexprConditionValue || !*ConstexprConditionValue) {
- Else = getDerived().TransformStmt(S->getElse());
- if (Else.isInvalid())
- return StmtError();
- }
- if (!getDerived().AlwaysRebuild() &&
- Init.get() == S->getInit() &&
- Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
- Then.get() == S->getThen() &&
- Else.get() == S->getElse())
- return S;
- return getDerived().RebuildIfStmt(
- S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
- S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
- // Transform the initialization statement
- StmtResult Init = getDerived().TransformStmt(S->getInit());
- if (Init.isInvalid())
- return StmtError();
- // Transform the condition.
- Sema::ConditionResult Cond = getDerived().TransformCondition(
- S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
- Sema::ConditionKind::Switch);
- if (Cond.isInvalid())
- return StmtError();
- // Rebuild the switch statement.
- StmtResult Switch =
- getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
- Init.get(), Cond, S->getRParenLoc());
- if (Switch.isInvalid())
- return StmtError();
- // Transform the body of the switch statement.
- StmtResult Body = getDerived().TransformStmt(S->getBody());
- if (Body.isInvalid())
- return StmtError();
- // Complete the switch statement.
- return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
- Body.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
- // Transform the condition
- Sema::ConditionResult Cond = getDerived().TransformCondition(
- S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
- Sema::ConditionKind::Boolean);
- if (Cond.isInvalid())
- return StmtError();
- // Transform the body
- StmtResult Body = getDerived().TransformStmt(S->getBody());
- if (Body.isInvalid())
- return StmtError();
- if (!getDerived().AlwaysRebuild() &&
- Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
- Body.get() == S->getBody())
- return Owned(S);
- return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
- Cond, S->getRParenLoc(), Body.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
- // Transform the body
- StmtResult Body = getDerived().TransformStmt(S->getBody());
- if (Body.isInvalid())
- return StmtError();
- // Transform the condition
- ExprResult Cond = getDerived().TransformExpr(S->getCond());
- if (Cond.isInvalid())
- return StmtError();
- if (!getDerived().AlwaysRebuild() &&
- Cond.get() == S->getCond() &&
- Body.get() == S->getBody())
- return S;
- return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
- /*FIXME:*/S->getWhileLoc(), Cond.get(),
- S->getRParenLoc());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
- if (getSema().getLangOpts().OpenMP)
- getSema().startOpenMPLoop();
- // Transform the initialization statement
- StmtResult Init = getDerived().TransformStmt(S->getInit());
- if (Init.isInvalid())
- return StmtError();
- // In OpenMP loop region loop control variable must be captured and be
- // private. Perform analysis of first part (if any).
- if (getSema().getLangOpts().OpenMP && Init.isUsable())
- getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
- // Transform the condition
- Sema::ConditionResult Cond = getDerived().TransformCondition(
- S->getForLoc(), S->getConditionVariable(), S->getCond(),
- Sema::ConditionKind::Boolean);
- if (Cond.isInvalid())
- return StmtError();
- // Transform the increment
- ExprResult Inc = getDerived().TransformExpr(S->getInc());
- if (Inc.isInvalid())
- return StmtError();
- Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
- if (S->getInc() && !FullInc.get())
- return StmtError();
- // Transform the body
- StmtResult Body = getDerived().TransformStmt(S->getBody());
- if (Body.isInvalid())
- return StmtError();
- if (!getDerived().AlwaysRebuild() &&
- Init.get() == S->getInit() &&
- Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
- Inc.get() == S->getInc() &&
- Body.get() == S->getBody())
- return S;
- return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
- Init.get(), Cond, FullInc,
- S->getRParenLoc(), Body.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
- Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
- S->getLabel());
- if (!LD)
- return StmtError();
- // Goto statements must always be rebuilt, to resolve the label.
- return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
- cast<LabelDecl>(LD));
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
- ExprResult Target = getDerived().TransformExpr(S->getTarget());
- if (Target.isInvalid())
- return StmtError();
- Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
- if (!getDerived().AlwaysRebuild() &&
- Target.get() == S->getTarget())
- return S;
- return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
- Target.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
- return S;
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
- return S;
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
- ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
- /*NotCopyInit*/false);
- if (Result.isInvalid())
- return StmtError();
- // FIXME: We always rebuild the return statement because there is no way
- // to tell whether the return type of the function has changed.
- return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
- bool DeclChanged = false;
- SmallVector<Decl *, 4> Decls;
- for (auto *D : S->decls()) {
- Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
- if (!Transformed)
- return StmtError();
- if (Transformed != D)
- DeclChanged = true;
- Decls.push_back(Transformed);
- }
- if (!getDerived().AlwaysRebuild() && !DeclChanged)
- return S;
- return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
- SmallVector<Expr*, 8> Constraints;
- SmallVector<Expr*, 8> Exprs;
- SmallVector<IdentifierInfo *, 4> Names;
- ExprResult AsmString;
- SmallVector<Expr*, 8> Clobbers;
- bool ExprsChanged = false;
- // Go through the outputs.
- for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
- Names.push_back(S->getOutputIdentifier(I));
- // No need to transform the constraint literal.
- Constraints.push_back(S->getOutputConstraintLiteral(I));
- // Transform the output expr.
- Expr *OutputExpr = S->getOutputExpr(I);
- ExprResult Result = getDerived().TransformExpr(OutputExpr);
- if (Result.isInvalid())
- return StmtError();
- ExprsChanged |= Result.get() != OutputExpr;
- Exprs.push_back(Result.get());
- }
- // Go through the inputs.
- for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
- Names.push_back(S->getInputIdentifier(I));
- // No need to transform the constraint literal.
- Constraints.push_back(S->getInputConstraintLiteral(I));
- // Transform the input expr.
- Expr *InputExpr = S->getInputExpr(I);
- ExprResult Result = getDerived().TransformExpr(InputExpr);
- if (Result.isInvalid())
- return StmtError();
- ExprsChanged |= Result.get() != InputExpr;
- Exprs.push_back(Result.get());
- }
- // Go through the Labels.
- for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
- Names.push_back(S->getLabelIdentifier(I));
- ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
- if (Result.isInvalid())
- return StmtError();
- ExprsChanged |= Result.get() != S->getLabelExpr(I);
- Exprs.push_back(Result.get());
- }
- if (!getDerived().AlwaysRebuild() && !ExprsChanged)
- return S;
- // Go through the clobbers.
- for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
- Clobbers.push_back(S->getClobberStringLiteral(I));
- // No need to transform the asm string literal.
- AsmString = S->getAsmString();
- return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
- S->isVolatile(), S->getNumOutputs(),
- S->getNumInputs(), Names.data(),
- Constraints, Exprs, AsmString.get(),
- Clobbers, S->getNumLabels(),
- S->getRParenLoc());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
- ArrayRef<Token> AsmToks =
- llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
- bool HadError = false, HadChange = false;
- ArrayRef<Expr*> SrcExprs = S->getAllExprs();
- SmallVector<Expr*, 8> TransformedExprs;
- TransformedExprs.reserve(SrcExprs.size());
- for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
- ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
- if (!Result.isUsable()) {
- HadError = true;
- } else {
- HadChange |= (Result.get() != SrcExprs[i]);
- TransformedExprs.push_back(Result.get());
- }
- }
- if (HadError) return StmtError();
- if (!HadChange && !getDerived().AlwaysRebuild())
- return Owned(S);
- return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
- AsmToks, S->getAsmString(),
- S->getNumOutputs(), S->getNumInputs(),
- S->getAllConstraints(), S->getClobbers(),
- TransformedExprs, S->getEndLoc());
- }
- // C++ Coroutines TS
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
- auto *ScopeInfo = SemaRef.getCurFunction();
- auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
- assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
- ScopeInfo->NeedsCoroutineSuspends &&
- ScopeInfo->CoroutineSuspends.first == nullptr &&
- ScopeInfo->CoroutineSuspends.second == nullptr &&
- "expected clean scope info");
- // Set that we have (possibly-invalid) suspend points before we do anything
- // that may fail.
- ScopeInfo->setNeedsCoroutineSuspends(false);
- // We re-build the coroutine promise object (and the coroutine parameters its
- // type and constructor depend on) based on the types used in our current
- // function. We must do so, and set it on the current FunctionScopeInfo,
- // before attempting to transform the other parts of the coroutine body
- // statement, such as the implicit suspend statements (because those
- // statements reference the FunctionScopeInfo::CoroutinePromise).
- if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
- return StmtError();
- auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
- if (!Promise)
- return StmtError();
- getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
- ScopeInfo->CoroutinePromise = Promise;
- // Transform the implicit coroutine statements constructed using dependent
- // types during the previous parse: initial and final suspensions, the return
- // object, and others. We also transform the coroutine function's body.
- StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
- if (InitSuspend.isInvalid())
- return StmtError();
- StmtResult FinalSuspend =
- getDerived().TransformStmt(S->getFinalSuspendStmt());
- if (FinalSuspend.isInvalid() ||
- !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
- return StmtError();
- ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
- assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
- StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
- if (BodyRes.isInvalid())
- return StmtError();
- CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
- if (Builder.isInvalid())
- return StmtError();
- Expr *ReturnObject = S->getReturnValueInit();
- assert(ReturnObject && "the return object is expected to be valid");
- ExprResult Res = getDerived().TransformInitializer(ReturnObject,
- /*NoCopyInit*/ false);
- if (Res.isInvalid())
- return StmtError();
- Builder.ReturnValue = Res.get();
- // If during the previous parse the coroutine still had a dependent promise
- // statement, we may need to build some implicit coroutine statements
- // (such as exception and fallthrough handlers) for the first time.
- if (S->hasDependentPromiseType()) {
- // We can only build these statements, however, if the current promise type
- // is not dependent.
- if (!Promise->getType()->isDependentType()) {
- assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
- !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
- "these nodes should not have been built yet");
- if (!Builder.buildDependentStatements())
- return StmtError();
- }
- } else {
- if (auto *OnFallthrough = S->getFallthroughHandler()) {
- StmtResult Res = getDerived().TransformStmt(OnFallthrough);
- if (Res.isInvalid())
- return StmtError();
- Builder.OnFallthrough = Res.get();
- }
- if (auto *OnException = S->getExceptionHandler()) {
- StmtResult Res = getDerived().TransformStmt(OnException);
- if (Res.isInvalid())
- return StmtError();
- Builder.OnException = Res.get();
- }
- if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
- StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
- if (Res.isInvalid())
- return StmtError();
- Builder.ReturnStmtOnAllocFailure = Res.get();
- }
- // Transform any additional statements we may have already built
- assert(S->getAllocate() && S->getDeallocate() &&
- "allocation and deallocation calls must already be built");
- ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
- if (AllocRes.isInvalid())
- return StmtError();
- Builder.Allocate = AllocRes.get();
- ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
- if (DeallocRes.isInvalid())
- return StmtError();
- Builder.Deallocate = DeallocRes.get();
- assert(S->getResultDecl() && "ResultDecl must already be built");
- StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
- if (ResultDecl.isInvalid())
- return StmtError();
- Builder.ResultDecl = ResultDecl.get();
- if (auto *ReturnStmt = S->getReturnStmt()) {
- StmtResult Res = getDerived().TransformStmt(ReturnStmt);
- if (Res.isInvalid())
- return StmtError();
- Builder.ReturnStmt = Res.get();
- }
- }
- return getDerived().RebuildCoroutineBodyStmt(Builder);
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
- ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
- /*NotCopyInit*/false);
- if (Result.isInvalid())
- return StmtError();
- // Always rebuild; we don't know if this needs to be injected into a new
- // context or if the promise type has changed.
- return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
- S->isImplicit());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
- ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
- /*NotCopyInit*/false);
- if (Result.isInvalid())
- return ExprError();
- // Always rebuild; we don't know if this needs to be injected into a new
- // context or if the promise type has changed.
- return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
- E->isImplicit());
- }
- template <typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
- ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
- /*NotCopyInit*/ false);
- if (OperandResult.isInvalid())
- return ExprError();
- ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
- E->getOperatorCoawaitLookup());
- if (LookupResult.isInvalid())
- return ExprError();
- // Always rebuild; we don't know if this needs to be injected into a new
- // context or if the promise type has changed.
- return getDerived().RebuildDependentCoawaitExpr(
- E->getKeywordLoc(), OperandResult.get(),
- cast<UnresolvedLookupExpr>(LookupResult.get()));
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
- ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
- /*NotCopyInit*/false);
- if (Result.isInvalid())
- return ExprError();
- // Always rebuild; we don't know if this needs to be injected into a new
- // context or if the promise type has changed.
- return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
- }
- // Objective-C Statements.
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
- // Transform the body of the @try.
- StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
- if (TryBody.isInvalid())
- return StmtError();
- // Transform the @catch statements (if present).
- bool AnyCatchChanged = false;
- SmallVector<Stmt*, 8> CatchStmts;
- for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
- StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
- if (Catch.isInvalid())
- return StmtError();
- if (Catch.get() != S->getCatchStmt(I))
- AnyCatchChanged = true;
- CatchStmts.push_back(Catch.get());
- }
- // Transform the @finally statement (if present).
- StmtResult Finally;
- if (S->getFinallyStmt()) {
- Finally = getDerived().TransformStmt(S->getFinallyStmt());
- if (Finally.isInvalid())
- return StmtError();
- }
- // If nothing changed, just retain this statement.
- if (!getDerived().AlwaysRebuild() &&
- TryBody.get() == S->getTryBody() &&
- !AnyCatchChanged &&
- Finally.get() == S->getFinallyStmt())
- return S;
- // Build a new statement.
- return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
- CatchStmts, Finally.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
- // Transform the @catch parameter, if there is one.
- VarDecl *Var = nullptr;
- if (VarDecl *FromVar = S->getCatchParamDecl()) {
- TypeSourceInfo *TSInfo = nullptr;
- if (FromVar->getTypeSourceInfo()) {
- TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
- if (!TSInfo)
- return StmtError();
- }
- QualType T;
- if (TSInfo)
- T = TSInfo->getType();
- else {
- T = getDerived().TransformType(FromVar->getType());
- if (T.isNull())
- return StmtError();
- }
- Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
- if (!Var)
- return StmtError();
- }
- StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
- if (Body.isInvalid())
- return StmtError();
- return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
- S->getRParenLoc(),
- Var, Body.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
- // Transform the body.
- StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
- if (Body.isInvalid())
- return StmtError();
- // If nothing changed, just retain this statement.
- if (!getDerived().AlwaysRebuild() &&
- Body.get() == S->getFinallyBody())
- return S;
- // Build a new statement.
- return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
- Body.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
- ExprResult Operand;
- if (S->getThrowExpr()) {
- Operand = getDerived().TransformExpr(S->getThrowExpr());
- if (Operand.isInvalid())
- return StmtError();
- }
- if (!getDerived().AlwaysRebuild() &&
- Operand.get() == S->getThrowExpr())
- return S;
- return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
- ObjCAtSynchronizedStmt *S) {
- // Transform the object we are locking.
- ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
- if (Object.isInvalid())
- return StmtError();
- Object =
- getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
- Object.get());
- if (Object.isInvalid())
- return StmtError();
- // Transform the body.
- StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
- if (Body.isInvalid())
- return StmtError();
- // If nothing change, just retain the current statement.
- if (!getDerived().AlwaysRebuild() &&
- Object.get() == S->getSynchExpr() &&
- Body.get() == S->getSynchBody())
- return S;
- // Build a new statement.
- return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
- Object.get(), Body.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
- ObjCAutoreleasePoolStmt *S) {
- // Transform the body.
- StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
- if (Body.isInvalid())
- return StmtError();
- // If nothing changed, just retain this statement.
- if (!getDerived().AlwaysRebuild() &&
- Body.get() == S->getSubStmt())
- return S;
- // Build a new statement.
- return getDerived().RebuildObjCAutoreleasePoolStmt(
- S->getAtLoc(), Body.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformObjCForCollectionStmt(
- ObjCForCollectionStmt *S) {
- // Transform the element statement.
- StmtResult Element =
- getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
- if (Element.isInvalid())
- return StmtError();
- // Transform the collection expression.
- ExprResult Collection = getDerived().TransformExpr(S->getCollection());
- if (Collection.isInvalid())
- return StmtError();
- // Transform the body.
- StmtResult Body = getDerived().TransformStmt(S->getBody());
- if (Body.isInvalid())
- return StmtError();
- // If nothing changed, just retain this statement.
- if (!getDerived().AlwaysRebuild() &&
- Element.get() == S->getElement() &&
- Collection.get() == S->getCollection() &&
- Body.get() == S->getBody())
- return S;
- // Build a new statement.
- return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
- Element.get(),
- Collection.get(),
- S->getRParenLoc(),
- Body.get());
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
- // Transform the exception declaration, if any.
- VarDecl *Var = nullptr;
- if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
- TypeSourceInfo *T =
- getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
- if (!T)
- return StmtError();
- Var = getDerived().RebuildExceptionDecl(
- ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
- ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
- if (!Var || Var->isInvalidDecl())
- return StmtError();
- }
- // Transform the actual exception handler.
- StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
- if (Handler.isInvalid())
- return StmtError();
- if (!getDerived().AlwaysRebuild() && !Var &&
- Handler.get() == S->getHandlerBlock())
- return S;
- return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
- // Transform the try block itself.
- StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
- if (TryBlock.isInvalid())
- return StmtError();
- // Transform the handlers.
- bool HandlerChanged = false;
- SmallVector<Stmt *, 8> Handlers;
- for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
- StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
- if (Handler.isInvalid())
- return StmtError();
- HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
- Handlers.push_back(Handler.getAs<Stmt>());
- }
- if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
- !HandlerChanged)
- return S;
- return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
- Handlers);
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
- StmtResult Init =
- S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
- if (Init.isInvalid())
- return StmtError();
- StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
- if (Range.isInvalid())
- return StmtError();
- StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
- if (Begin.isInvalid())
- return StmtError();
- StmtResult End = getDerived().TransformStmt(S->getEndStmt());
- if (End.isInvalid())
- return StmtError();
- ExprResult Cond = getDerived().TransformExpr(S->getCond());
- if (Cond.isInvalid())
- return StmtError();
- if (Cond.get())
- Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
- if (Cond.isInvalid())
- return StmtError();
- if (Cond.get())
- Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
- ExprResult Inc = getDerived().TransformExpr(S->getInc());
- if (Inc.isInvalid())
- return StmtError();
- if (Inc.get())
- Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
- StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
- if (LoopVar.isInvalid())
- return StmtError();
- StmtResult NewStmt = S;
- if (getDerived().AlwaysRebuild() ||
- Init.get() != S->getInit() ||
- Range.get() != S->getRangeStmt() ||
- Begin.get() != S->getBeginStmt() ||
- End.get() != S->getEndStmt() ||
- Cond.get() != S->getCond() ||
- Inc.get() != S->getInc() ||
- LoopVar.get() != S->getLoopVarStmt()) {
- NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
- S->getCoawaitLoc(), Init.get(),
- S->getColonLoc(), Range.get(),
- Begin.get(), End.get(),
- Cond.get(),
- Inc.get(), LoopVar.get(),
- S->getRParenLoc());
- if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
- // Might not have attached any initializer to the loop variable.
- getSema().ActOnInitializerError(
- cast<DeclStmt>(LoopVar.get())->getSingleDecl());
- return StmtError();
- }
- }
- StmtResult Body = getDerived().TransformStmt(S->getBody());
- if (Body.isInvalid())
- return StmtError();
- // Body has changed but we didn't rebuild the for-range statement. Rebuild
- // it now so we have a new statement to attach the body to.
- if (Body.get() != S->getBody() && NewStmt.get() == S) {
- NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
- S->getCoawaitLoc(), Init.get(),
- S->getColonLoc(), Range.get(),
- Begin.get(), End.get(),
- Cond.get(),
- Inc.get(), LoopVar.get(),
- S->getRParenLoc());
- if (NewStmt.isInvalid())
- return StmtError();
- }
- if (NewStmt.get() == S)
- return S;
- return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformMSDependentExistsStmt(
- MSDependentExistsStmt *S) {
- // Transform the nested-name-specifier, if any.
- NestedNameSpecifierLoc QualifierLoc;
- if (S->getQualifierLoc()) {
- QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
- if (!QualifierLoc)
- return StmtError();
- }
- // Transform the declaration name.
- DeclarationNameInfo NameInfo = S->getNameInfo();
- if (NameInfo.getName()) {
- NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
- if (!NameInfo.getName())
- return StmtError();
- }
- // Check whether anything changed.
- if (!getDerived().AlwaysRebuild() &&
- QualifierLoc == S->getQualifierLoc() &&
- NameInfo.getName() == S->getNameInfo().getName())
- return S;
- // Determine whether this name exists, if we can.
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- bool Dependent = false;
- switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
- case Sema::IER_Exists:
- if (S->isIfExists())
- break;
- return new (getSema().Context) NullStmt(S->getKeywordLoc());
- case Sema::IER_DoesNotExist:
- if (S->isIfNotExists())
- break;
- return new (getSema().Context) NullStmt(S->getKeywordLoc());
- case Sema::IER_Dependent:
- Dependent = true;
- break;
- case Sema::IER_Error:
- return StmtError();
- }
- // We need to continue with the instantiation, so do so now.
- StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
- if (SubStmt.isInvalid())
- return StmtError();
- // If we have resolved the name, just transform to the substatement.
- if (!Dependent)
- return SubStmt;
- // The name is still dependent, so build a dependent expression again.
- return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
- S->isIfExists(),
- QualifierLoc,
- NameInfo,
- SubStmt.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
- NestedNameSpecifierLoc QualifierLoc;
- if (E->getQualifierLoc()) {
- QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
- if (!QualifierLoc)
- return ExprError();
- }
- MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
- getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
- if (!PD)
- return ExprError();
- ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
- if (Base.isInvalid())
- return ExprError();
- return new (SemaRef.getASTContext())
- MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
- SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
- QualifierLoc, E->getMemberLoc());
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
- MSPropertySubscriptExpr *E) {
- auto BaseRes = getDerived().TransformExpr(E->getBase());
- if (BaseRes.isInvalid())
- return ExprError();
- auto IdxRes = getDerived().TransformExpr(E->getIdx());
- if (IdxRes.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- BaseRes.get() == E->getBase() &&
- IdxRes.get() == E->getIdx())
- return E;
- return getDerived().RebuildArraySubscriptExpr(
- BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
- StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
- if (TryBlock.isInvalid())
- return StmtError();
- StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
- if (Handler.isInvalid())
- return StmtError();
- if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
- Handler.get() == S->getHandler())
- return S;
- return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
- TryBlock.get(), Handler.get());
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
- StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
- if (Block.isInvalid())
- return StmtError();
- return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
- ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
- if (FilterExpr.isInvalid())
- return StmtError();
- StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
- if (Block.isInvalid())
- return StmtError();
- return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
- Block.get());
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
- if (isa<SEHFinallyStmt>(Handler))
- return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
- else
- return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
- return S;
- }
- //===----------------------------------------------------------------------===//
- // OpenMP directive transformation
- //===----------------------------------------------------------------------===//
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
- // OMPCanonicalLoops are eliminated during transformation, since they will be
- // recomputed by semantic analysis of the associated OMPLoopBasedDirective
- // after transformation.
- return getDerived().TransformStmt(L->getLoopStmt());
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
- OMPExecutableDirective *D) {
- // Transform the clauses
- llvm::SmallVector<OMPClause *, 16> TClauses;
- ArrayRef<OMPClause *> Clauses = D->clauses();
- TClauses.reserve(Clauses.size());
- for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
- I != E; ++I) {
- if (*I) {
- getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
- OMPClause *Clause = getDerived().TransformOMPClause(*I);
- getDerived().getSema().EndOpenMPClause();
- if (Clause)
- TClauses.push_back(Clause);
- } else {
- TClauses.push_back(nullptr);
- }
- }
- StmtResult AssociatedStmt;
- if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
- getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
- /*CurScope=*/nullptr);
- StmtResult Body;
- {
- Sema::CompoundScopeRAII CompoundScope(getSema());
- Stmt *CS;
- if (D->getDirectiveKind() == OMPD_atomic ||
- D->getDirectiveKind() == OMPD_critical ||
- D->getDirectiveKind() == OMPD_section ||
- D->getDirectiveKind() == OMPD_master)
- CS = D->getAssociatedStmt();
- else
- CS = D->getRawStmt();
- Body = getDerived().TransformStmt(CS);
- if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
- getSema().getLangOpts().OpenMPIRBuilder)
- Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
- }
- AssociatedStmt =
- getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
- if (AssociatedStmt.isInvalid()) {
- return StmtError();
- }
- }
- if (TClauses.size() != Clauses.size()) {
- return StmtError();
- }
- // Transform directive name for 'omp critical' directive.
- DeclarationNameInfo DirName;
- if (D->getDirectiveKind() == OMPD_critical) {
- DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
- DirName = getDerived().TransformDeclarationNameInfo(DirName);
- }
- OpenMPDirectiveKind CancelRegion = OMPD_unknown;
- if (D->getDirectiveKind() == OMPD_cancellation_point) {
- CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
- } else if (D->getDirectiveKind() == OMPD_cancel) {
- CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
- }
- return getDerived().RebuildOMPExecutableDirective(
- D->getDirectiveKind(), DirName, CancelRegion, TClauses,
- AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPMetaDirective(OMPMetaDirective *D) {
- // TODO: Fix This
- SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
- << getOpenMPDirectiveName(D->getDirectiveKind());
- return StmtError();
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(D->getDirectiveKind(), DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(D->getDirectiveKind(), DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
- OMPParallelForDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
- OMPParallelForSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
- OMPParallelMasterDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
- OMPParallelSectionsDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
- OMPTaskyieldDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
- OMPTaskgroupDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_depobj, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_scan, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
- OMPTargetDataDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
- OMPTargetEnterDataDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
- OMPTargetExitDataDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
- OMPTargetParallelDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
- OMPTargetParallelForDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
- OMPTargetUpdateDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
- OMPCancellationPointDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
- OMPTaskLoopSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
- OMPMasterTaskLoopDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
- OMPMasterTaskLoopSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop_simd, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
- OMPParallelMasterTaskLoopDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
- OMPParallelMasterTaskLoopSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
- OMPDistributeDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
- OMPDistributeParallelForDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
- OMPDistributeParallelForSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
- OMPDistributeSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
- OMPTargetParallelForSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
- OMPTargetSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
- OMPTeamsDistributeDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
- nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
- OMPTeamsDistributeSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
- OMPTeamsDistributeParallelForSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
- OMPTeamsDistributeParallelForDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
- OMPTargetTeamsDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
- nullptr, D->getBeginLoc());
- auto Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
- OMPTargetTeamsDistributeDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
- auto Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
- OMPTargetTeamsDistributeParallelForDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
- D->getBeginLoc());
- auto Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::
- TransformOMPTargetTeamsDistributeParallelForSimdDirective(
- OMPTargetTeamsDistributeParallelForSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
- D->getBeginLoc());
- auto Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
- OMPTargetTeamsDistributeSimdDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(
- OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
- auto Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_interop, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_dispatch, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_masked, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- template <typename Derived>
- StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
- OMPGenericLoopDirective *D) {
- DeclarationNameInfo DirName;
- getDerived().getSema().StartOpenMPDSABlock(OMPD_loop, DirName, nullptr,
- D->getBeginLoc());
- StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
- getDerived().getSema().EndOpenMPDSABlock(Res.get());
- return Res;
- }
- //===----------------------------------------------------------------------===//
- // OpenMP clause transformation
- //===----------------------------------------------------------------------===//
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
- ExprResult Cond = getDerived().TransformExpr(C->getCondition());
- if (Cond.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPIfClause(
- C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
- C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
- ExprResult Cond = getDerived().TransformExpr(C->getCondition());
- if (Cond.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
- ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
- if (NumThreads.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPNumThreadsClause(
- NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getSafelen());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPSafelenClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getAllocator());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPAllocatorClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getSimdlen());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPSimdlenClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
- SmallVector<Expr *, 4> TransformedSizes;
- TransformedSizes.reserve(C->getNumSizes());
- bool Changed = false;
- for (Expr *E : C->getSizesRefs()) {
- if (!E) {
- TransformedSizes.push_back(nullptr);
- continue;
- }
- ExprResult T = getDerived().TransformExpr(E);
- if (T.isInvalid())
- return nullptr;
- if (E != T.get())
- Changed = true;
- TransformedSizes.push_back(T.get());
- }
- if (!Changed && !getDerived().AlwaysRebuild())
- return C;
- return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
- if (!getDerived().AlwaysRebuild())
- return C;
- return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
- ExprResult T = getDerived().TransformExpr(C->getFactor());
- if (T.isInvalid())
- return nullptr;
- Expr *Factor = T.get();
- bool Changed = Factor != C->getFactor();
- if (!Changed && !getDerived().AlwaysRebuild())
- return C;
- return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
- C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPCollapseClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
- return getDerived().RebuildOMPDefaultClause(
- C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
- return getDerived().RebuildOMPProcBindClause(
- C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getChunkSize());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPScheduleClause(
- C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
- C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
- C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
- C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
- ExprResult E;
- if (auto *Num = C->getNumForLoops()) {
- E = getDerived().TransformExpr(Num);
- if (E.isInvalid())
- return nullptr;
- }
- return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
- C->getLParenLoc(), E.get());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
- ExprResult E;
- if (Expr *Evt = C->getEventHandler()) {
- E = getDerived().TransformExpr(Evt);
- if (E.isInvalid())
- return nullptr;
- }
- return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
- // No need to rebuild this clause, no template-dependent parameters.
- return C;
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
- ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
- if (IVR.isInvalid())
- return nullptr;
- llvm::SmallVector<Expr *, 8> PrefExprs;
- PrefExprs.reserve(C->varlist_size() - 1);
- for (Expr *E : llvm::drop_begin(C->varlists())) {
- ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
- if (ER.isInvalid())
- return nullptr;
- PrefExprs.push_back(ER.get());
- }
- return getDerived().RebuildOMPInitClause(
- IVR.get(), PrefExprs, C->getIsTarget(), C->getIsTargetSync(),
- C->getBeginLoc(), C->getLParenLoc(), C->getVarLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
- ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
- if (ER.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
- C->getLParenLoc(), C->getVarLoc(),
- C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
- ExprResult ER;
- if (Expr *IV = C->getInteropVar()) {
- ER = getDerived().TransformExpr(IV);
- if (ER.isInvalid())
- return nullptr;
- }
- return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
- C->getLParenLoc(), C->getVarLoc(),
- C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
- ExprResult Cond = getDerived().TransformExpr(C->getCondition());
- if (Cond.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPNovariantsClause(
- Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
- ExprResult Cond = getDerived().TransformExpr(C->getCondition());
- if (Cond.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPNocontextClause(
- Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
- ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
- if (ThreadID.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getAlignment());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
- OMPUnifiedAddressClause *C) {
- llvm_unreachable("unified_address clause cannot appear in dependent context");
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
- OMPUnifiedSharedMemoryClause *C) {
- llvm_unreachable(
- "unified_shared_memory clause cannot appear in dependent context");
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
- OMPReverseOffloadClause *C) {
- llvm_unreachable("reverse_offload clause cannot appear in dependent context");
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
- OMPDynamicAllocatorsClause *C) {
- llvm_unreachable(
- "dynamic_allocators clause cannot appear in dependent context");
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
- OMPAtomicDefaultMemOrderClause *C) {
- llvm_unreachable(
- "atomic_default_mem_order clause cannot appear in dependent context");
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPPrivateClause(
- Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
- OMPFirstprivateClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPFirstprivateClause(
- Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPLastprivateClause(
- Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- CXXScopeSpec ReductionIdScopeSpec;
- ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
- DeclarationNameInfo NameInfo = C->getNameInfo();
- if (NameInfo.getName()) {
- NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
- if (!NameInfo.getName())
- return nullptr;
- }
- // Build a list of all UDR decls with the same names ranged by the Scopes.
- // The Scope boundary is a duplication of the previous decl.
- llvm::SmallVector<Expr *, 16> UnresolvedReductions;
- for (auto *E : C->reduction_ops()) {
- // Transform all the decls.
- if (E) {
- auto *ULE = cast<UnresolvedLookupExpr>(E);
- UnresolvedSet<8> Decls;
- for (auto *D : ULE->decls()) {
- NamedDecl *InstD =
- cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
- Decls.addDecl(InstD, InstD->getAccess());
- }
- UnresolvedReductions.push_back(
- UnresolvedLookupExpr::Create(
- SemaRef.Context, /*NamingClass=*/nullptr,
- ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
- NameInfo, /*ADL=*/true, ULE->isOverloaded(),
- Decls.begin(), Decls.end()));
- } else
- UnresolvedReductions.push_back(nullptr);
- }
- return getDerived().RebuildOMPReductionClause(
- Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(),
- C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
- ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
- OMPTaskReductionClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- CXXScopeSpec ReductionIdScopeSpec;
- ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
- DeclarationNameInfo NameInfo = C->getNameInfo();
- if (NameInfo.getName()) {
- NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
- if (!NameInfo.getName())
- return nullptr;
- }
- // Build a list of all UDR decls with the same names ranged by the Scopes.
- // The Scope boundary is a duplication of the previous decl.
- llvm::SmallVector<Expr *, 16> UnresolvedReductions;
- for (auto *E : C->reduction_ops()) {
- // Transform all the decls.
- if (E) {
- auto *ULE = cast<UnresolvedLookupExpr>(E);
- UnresolvedSet<8> Decls;
- for (auto *D : ULE->decls()) {
- NamedDecl *InstD =
- cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
- Decls.addDecl(InstD, InstD->getAccess());
- }
- UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
- SemaRef.Context, /*NamingClass=*/nullptr,
- ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
- /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
- } else
- UnresolvedReductions.push_back(nullptr);
- }
- return getDerived().RebuildOMPTaskReductionClause(
- Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
- C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- CXXScopeSpec ReductionIdScopeSpec;
- ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
- DeclarationNameInfo NameInfo = C->getNameInfo();
- if (NameInfo.getName()) {
- NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
- if (!NameInfo.getName())
- return nullptr;
- }
- // Build a list of all UDR decls with the same names ranged by the Scopes.
- // The Scope boundary is a duplication of the previous decl.
- llvm::SmallVector<Expr *, 16> UnresolvedReductions;
- for (auto *E : C->reduction_ops()) {
- // Transform all the decls.
- if (E) {
- auto *ULE = cast<UnresolvedLookupExpr>(E);
- UnresolvedSet<8> Decls;
- for (auto *D : ULE->decls()) {
- NamedDecl *InstD =
- cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
- Decls.addDecl(InstD, InstD->getAccess());
- }
- UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
- SemaRef.Context, /*NamingClass=*/nullptr,
- ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
- /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
- } else
- UnresolvedReductions.push_back(nullptr);
- }
- return getDerived().RebuildOMPInReductionClause(
- Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
- C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- ExprResult Step = getDerived().TransformExpr(C->getStep());
- if (Step.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPLinearClause(
- Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
- C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
- if (Alignment.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPAlignedClause(
- Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
- C->getColonLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPCopyprivateClause(
- Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getDepobj());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Expr *DepModifier = C->getModifier();
- if (DepModifier) {
- ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
- if (DepModRes.isInvalid())
- return nullptr;
- DepModifier = DepModRes.get();
- }
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPDependClause(
- DepModifier, C->getDependencyKind(), C->getDependencyLoc(),
- C->getColonLoc(), Vars, C->getBeginLoc(), C->getLParenLoc(),
- C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getDevice());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPDeviceClause(
- C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
- C->getModifierLoc(), C->getEndLoc());
- }
- template <typename Derived, class T>
- bool transformOMPMappableExprListClause(
- TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C,
- llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
- DeclarationNameInfo &MapperIdInfo,
- llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
- // Transform expressions in the list.
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return true;
- Vars.push_back(EVar.get());
- }
- // Transform mapper scope specifier and identifier.
- NestedNameSpecifierLoc QualifierLoc;
- if (C->getMapperQualifierLoc()) {
- QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
- C->getMapperQualifierLoc());
- if (!QualifierLoc)
- return true;
- }
- MapperIdScopeSpec.Adopt(QualifierLoc);
- MapperIdInfo = C->getMapperIdInfo();
- if (MapperIdInfo.getName()) {
- MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
- if (!MapperIdInfo.getName())
- return true;
- }
- // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
- // the previous user-defined mapper lookup in dependent environment.
- for (auto *E : C->mapperlists()) {
- // Transform all the decls.
- if (E) {
- auto *ULE = cast<UnresolvedLookupExpr>(E);
- UnresolvedSet<8> Decls;
- for (auto *D : ULE->decls()) {
- NamedDecl *InstD =
- cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
- Decls.addDecl(InstD, InstD->getAccess());
- }
- UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
- TT.getSema().Context, /*NamingClass=*/nullptr,
- MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
- MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(),
- Decls.end()));
- } else {
- UnresolvedMappers.push_back(nullptr);
- }
- }
- return false;
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
- OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- llvm::SmallVector<Expr *, 16> Vars;
- CXXScopeSpec MapperIdScopeSpec;
- DeclarationNameInfo MapperIdInfo;
- llvm::SmallVector<Expr *, 16> UnresolvedMappers;
- if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
- *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
- return nullptr;
- return getDerived().RebuildOMPMapClause(
- C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec,
- MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(),
- C->getColonLoc(), Vars, Locs, UnresolvedMappers);
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
- Expr *Allocator = C->getAllocator();
- if (Allocator) {
- ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
- if (AllocatorRes.isInvalid())
- return nullptr;
- Allocator = AllocatorRes.get();
- }
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPAllocateClause(
- Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
- C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getNumTeams());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPNumTeamsClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPThreadLimitClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getPriority());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPPriorityClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getGrainsize());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPGrainsizeClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getNumTasks());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPNumTasksClause(
- E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getHint());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
- OMPDistScheduleClause *C) {
- ExprResult E = getDerived().TransformExpr(C->getChunkSize());
- if (E.isInvalid())
- return nullptr;
- return getDerived().RebuildOMPDistScheduleClause(
- C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
- C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
- // Rebuild Defaultmap Clause since we need to invoke the checking of
- // defaultmap(none:variable-category) after template initialization.
- return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
- C->getDefaultmapKind(),
- C->getBeginLoc(),
- C->getLParenLoc(),
- C->getDefaultmapModifierLoc(),
- C->getDefaultmapKindLoc(),
- C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
- OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- llvm::SmallVector<Expr *, 16> Vars;
- CXXScopeSpec MapperIdScopeSpec;
- DeclarationNameInfo MapperIdInfo;
- llvm::SmallVector<Expr *, 16> UnresolvedMappers;
- if (transformOMPMappableExprListClause<Derived, OMPToClause>(
- *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
- return nullptr;
- return getDerived().RebuildOMPToClause(
- C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
- MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
- OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- llvm::SmallVector<Expr *, 16> Vars;
- CXXScopeSpec MapperIdScopeSpec;
- DeclarationNameInfo MapperIdInfo;
- llvm::SmallVector<Expr *, 16> UnresolvedMappers;
- if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
- *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
- return nullptr;
- return getDerived().RebuildOMPFromClause(
- C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
- MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
- OMPUseDevicePtrClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
- OMPUseDeviceAddrClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPNontemporalClause(
- Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPInclusiveClause(
- Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
- llvm::SmallVector<Expr *, 16> Vars;
- Vars.reserve(C->varlist_size());
- for (auto *VE : C->varlists()) {
- ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
- if (EVar.isInvalid())
- return nullptr;
- Vars.push_back(EVar.get());
- }
- return getDerived().RebuildOMPExclusiveClause(
- Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
- OMPUsesAllocatorsClause *C) {
- SmallVector<Sema::UsesAllocatorsData, 16> Data;
- Data.reserve(C->getNumberOfAllocators());
- for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
- OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
- ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
- if (Allocator.isInvalid())
- continue;
- ExprResult AllocatorTraits;
- if (Expr *AT = D.AllocatorTraits) {
- AllocatorTraits = getDerived().TransformExpr(AT);
- if (AllocatorTraits.isInvalid())
- continue;
- }
- Sema::UsesAllocatorsData &NewD = Data.emplace_back();
- NewD.Allocator = Allocator.get();
- NewD.AllocatorTraits = AllocatorTraits.get();
- NewD.LParenLoc = D.LParenLoc;
- NewD.RParenLoc = D.RParenLoc;
- }
- return getDerived().RebuildOMPUsesAllocatorsClause(
- Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *
- TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
- SmallVector<Expr *, 4> Locators;
- Locators.reserve(C->varlist_size());
- ExprResult ModifierRes;
- if (Expr *Modifier = C->getModifier()) {
- ModifierRes = getDerived().TransformExpr(Modifier);
- if (ModifierRes.isInvalid())
- return nullptr;
- }
- for (Expr *E : C->varlists()) {
- ExprResult Locator = getDerived().TransformExpr(E);
- if (Locator.isInvalid())
- continue;
- Locators.push_back(Locator.get());
- }
- return getDerived().RebuildOMPAffinityClause(
- C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
- ModifierRes.get(), Locators);
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
- return getDerived().RebuildOMPOrderClause(C->getKind(), C->getKindKwLoc(),
- C->getBeginLoc(), C->getLParenLoc(),
- C->getEndLoc());
- }
- template <typename Derived>
- OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
- return getDerived().RebuildOMPBindClause(
- C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
- C->getLParenLoc(), C->getEndLoc());
- }
- //===----------------------------------------------------------------------===//
- // Expression transformation
- //===----------------------------------------------------------------------===//
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
- return TransformExpr(E->getSubExpr());
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
- SYCLUniqueStableNameExpr *E) {
- if (!E->isTypeDependent())
- return E;
- TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
- if (!NewT)
- return ExprError();
- if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
- return E;
- return getDerived().RebuildSYCLUniqueStableNameExpr(
- E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
- if (!E->isTypeDependent())
- return E;
- return getDerived().RebuildPredefinedExpr(E->getLocation(),
- E->getIdentKind());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
- NestedNameSpecifierLoc QualifierLoc;
- if (E->getQualifierLoc()) {
- QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
- if (!QualifierLoc)
- return ExprError();
- }
- ValueDecl *ND
- = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
- E->getDecl()));
- if (!ND)
- return ExprError();
- NamedDecl *Found = ND;
- if (E->getFoundDecl() != E->getDecl()) {
- Found = cast_or_null<NamedDecl>(
- getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
- if (!Found)
- return ExprError();
- }
- DeclarationNameInfo NameInfo = E->getNameInfo();
- if (NameInfo.getName()) {
- NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
- if (!NameInfo.getName())
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() &&
- QualifierLoc == E->getQualifierLoc() &&
- ND == E->getDecl() &&
- Found == E->getFoundDecl() &&
- NameInfo.getName() == E->getDecl()->getDeclName() &&
- !E->hasExplicitTemplateArgs()) {
- // Mark it referenced in the new context regardless.
- // FIXME: this is a bit instantiation-specific.
- SemaRef.MarkDeclRefReferenced(E);
- return E;
- }
- TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
- if (E->hasExplicitTemplateArgs()) {
- TemplateArgs = &TransArgs;
- TransArgs.setLAngleLoc(E->getLAngleLoc());
- TransArgs.setRAngleLoc(E->getRAngleLoc());
- if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
- E->getNumTemplateArgs(),
- TransArgs))
- return ExprError();
- }
- return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
- Found, TemplateArgs);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
- return E;
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
- FixedPointLiteral *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
- if (FunctionDecl *FD = E->getDirectCallee())
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
- return SemaRef.MaybeBindToTemporary(E);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
- ExprResult ControllingExpr =
- getDerived().TransformExpr(E->getControllingExpr());
- if (ControllingExpr.isInvalid())
- return ExprError();
- SmallVector<Expr *, 4> AssocExprs;
- SmallVector<TypeSourceInfo *, 4> AssocTypes;
- for (const GenericSelectionExpr::Association Assoc : E->associations()) {
- TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
- if (TSI) {
- TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
- if (!AssocType)
- return ExprError();
- AssocTypes.push_back(AssocType);
- } else {
- AssocTypes.push_back(nullptr);
- }
- ExprResult AssocExpr =
- getDerived().TransformExpr(Assoc.getAssociationExpr());
- if (AssocExpr.isInvalid())
- return ExprError();
- AssocExprs.push_back(AssocExpr.get());
- }
- return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
- E->getDefaultLoc(),
- E->getRParenLoc(),
- ControllingExpr.get(),
- AssocTypes,
- AssocExprs);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
- ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
- return E;
- return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
- E->getRParen());
- }
- /// The operand of a unary address-of operator has special rules: it's
- /// allowed to refer to a non-static member of a class even if there's no 'this'
- /// object available.
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
- if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
- return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
- else
- return getDerived().TransformExpr(E);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
- ExprResult SubExpr;
- if (E->getOpcode() == UO_AddrOf)
- SubExpr = TransformAddressOfOperand(E->getSubExpr());
- else
- SubExpr = TransformExpr(E->getSubExpr());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
- return E;
- return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
- E->getOpcode(),
- SubExpr.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
- // Transform the type.
- TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
- if (!Type)
- return ExprError();
- // Transform all of the components into components similar to what the
- // parser uses.
- // FIXME: It would be slightly more efficient in the non-dependent case to
- // just map FieldDecls, rather than requiring the rebuilder to look for
- // the fields again. However, __builtin_offsetof is rare enough in
- // template code that we don't care.
- bool ExprChanged = false;
- typedef Sema::OffsetOfComponent Component;
- SmallVector<Component, 4> Components;
- for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
- const OffsetOfNode &ON = E->getComponent(I);
- Component Comp;
- Comp.isBrackets = true;
- Comp.LocStart = ON.getSourceRange().getBegin();
- Comp.LocEnd = ON.getSourceRange().getEnd();
- switch (ON.getKind()) {
- case OffsetOfNode::Array: {
- Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
- ExprResult Index = getDerived().TransformExpr(FromIndex);
- if (Index.isInvalid())
- return ExprError();
- ExprChanged = ExprChanged || Index.get() != FromIndex;
- Comp.isBrackets = true;
- Comp.U.E = Index.get();
- break;
- }
- case OffsetOfNode::Field:
- case OffsetOfNode::Identifier:
- Comp.isBrackets = false;
- Comp.U.IdentInfo = ON.getFieldName();
- if (!Comp.U.IdentInfo)
- continue;
- break;
- case OffsetOfNode::Base:
- // Will be recomputed during the rebuild.
- continue;
- }
- Components.push_back(Comp);
- }
- // If nothing changed, retain the existing expression.
- if (!getDerived().AlwaysRebuild() &&
- Type == E->getTypeSourceInfo() &&
- !ExprChanged)
- return E;
- // Build a new offsetof expression.
- return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
- Components, E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
- assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
- "opaque value expression requires transformation");
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
- return E;
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
- llvm::SmallVector<Expr *, 8> Children;
- bool Changed = false;
- for (Expr *C : E->subExpressions()) {
- ExprResult NewC = getDerived().TransformExpr(C);
- if (NewC.isInvalid())
- return ExprError();
- Children.push_back(NewC.get());
- Changed |= NewC.get() != C;
- }
- if (!getDerived().AlwaysRebuild() && !Changed)
- return E;
- return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
- Children, E->getType());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
- // Rebuild the syntactic form. The original syntactic form has
- // opaque-value expressions in it, so strip those away and rebuild
- // the result. This is a really awful way of doing this, but the
- // better solution (rebuilding the semantic expressions and
- // rebinding OVEs as necessary) doesn't work; we'd need
- // TreeTransform to not strip away implicit conversions.
- Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
- ExprResult result = getDerived().TransformExpr(newSyntacticForm);
- if (result.isInvalid()) return ExprError();
- // If that gives us a pseudo-object result back, the pseudo-object
- // expression must have been an lvalue-to-rvalue conversion which we
- // should reapply.
- if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
- result = SemaRef.checkPseudoObjectRValue(result.get());
- return result;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
- UnaryExprOrTypeTraitExpr *E) {
- if (E->isArgumentType()) {
- TypeSourceInfo *OldT = E->getArgumentTypeInfo();
- TypeSourceInfo *NewT = getDerived().TransformType(OldT);
- if (!NewT)
- return ExprError();
- if (!getDerived().AlwaysRebuild() && OldT == NewT)
- return E;
- return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
- E->getKind(),
- E->getSourceRange());
- }
- // C++0x [expr.sizeof]p1:
- // The operand is either an expression, which is an unevaluated operand
- // [...]
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
- Sema::ReuseLambdaContextDecl);
- // Try to recover if we have something like sizeof(T::X) where X is a type.
- // Notably, there must be *exactly* one set of parens if X is a type.
- TypeSourceInfo *RecoveryTSI = nullptr;
- ExprResult SubExpr;
- auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
- if (auto *DRE =
- PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
- SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
- PE, DRE, false, &RecoveryTSI);
- else
- SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
- if (RecoveryTSI) {
- return getDerived().RebuildUnaryExprOrTypeTrait(
- RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
- } else if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
- return E;
- return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
- E->getOperatorLoc(),
- E->getKind(),
- E->getSourceRange());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
- ExprResult LHS = getDerived().TransformExpr(E->getLHS());
- if (LHS.isInvalid())
- return ExprError();
- ExprResult RHS = getDerived().TransformExpr(E->getRHS());
- if (RHS.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- LHS.get() == E->getLHS() &&
- RHS.get() == E->getRHS())
- return E;
- return getDerived().RebuildArraySubscriptExpr(
- LHS.get(),
- /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
- }
- template <typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
- if (RowIdx.isInvalid())
- return ExprError();
- ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
- if (ColumnIdx.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
- RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
- return E;
- return getDerived().RebuildMatrixSubscriptExpr(
- Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
- }
- template <typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- ExprResult LowerBound;
- if (E->getLowerBound()) {
- LowerBound = getDerived().TransformExpr(E->getLowerBound());
- if (LowerBound.isInvalid())
- return ExprError();
- }
- ExprResult Length;
- if (E->getLength()) {
- Length = getDerived().TransformExpr(E->getLength());
- if (Length.isInvalid())
- return ExprError();
- }
- ExprResult Stride;
- if (Expr *Str = E->getStride()) {
- Stride = getDerived().TransformExpr(Str);
- if (Stride.isInvalid())
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
- LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
- return E;
- return getDerived().RebuildOMPArraySectionExpr(
- Base.get(), E->getBase()->getEndLoc(), LowerBound.get(),
- E->getColonLocFirst(), E->getColonLocSecond(), Length.get(), Stride.get(),
- E->getRBracketLoc());
- }
- template <typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- SmallVector<Expr *, 4> Dims;
- bool ErrorFound = false;
- for (Expr *Dim : E->getDimensions()) {
- ExprResult DimRes = getDerived().TransformExpr(Dim);
- if (DimRes.isInvalid()) {
- ErrorFound = true;
- continue;
- }
- Dims.push_back(DimRes.get());
- }
- if (ErrorFound)
- return ExprError();
- return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
- E->getRParenLoc(), Dims,
- E->getBracketsRanges());
- }
- template <typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
- unsigned NumIterators = E->numOfIterators();
- SmallVector<Sema::OMPIteratorData, 4> Data(NumIterators);
- bool ErrorFound = false;
- bool NeedToRebuild = getDerived().AlwaysRebuild();
- for (unsigned I = 0; I < NumIterators; ++I) {
- auto *D = cast<VarDecl>(E->getIteratorDecl(I));
- Data[I].DeclIdent = D->getIdentifier();
- Data[I].DeclIdentLoc = D->getLocation();
- if (D->getLocation() == D->getBeginLoc()) {
- assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
- "Implicit type must be int.");
- } else {
- TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
- QualType DeclTy = getDerived().TransformType(D->getType());
- Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
- }
- OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
- ExprResult Begin = getDerived().TransformExpr(Range.Begin);
- ExprResult End = getDerived().TransformExpr(Range.End);
- ExprResult Step = getDerived().TransformExpr(Range.Step);
- ErrorFound = ErrorFound ||
- !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
- !Data[I].Type.get().isNull())) ||
- Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
- if (ErrorFound)
- continue;
- Data[I].Range.Begin = Begin.get();
- Data[I].Range.End = End.get();
- Data[I].Range.Step = Step.get();
- Data[I].AssignLoc = E->getAssignLoc(I);
- Data[I].ColonLoc = E->getColonLoc(I);
- Data[I].SecColonLoc = E->getSecondColonLoc(I);
- NeedToRebuild =
- NeedToRebuild ||
- (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
- D->getType().getTypePtrOrNull()) ||
- Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
- Range.Step != Data[I].Range.Step;
- }
- if (ErrorFound)
- return ExprError();
- if (!NeedToRebuild)
- return E;
- ExprResult Res = getDerived().RebuildOMPIteratorExpr(
- E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
- if (!Res.isUsable())
- return Res;
- auto *IE = cast<OMPIteratorExpr>(Res.get());
- for (unsigned I = 0; I < NumIterators; ++I)
- getDerived().transformedLocalDecl(E->getIteratorDecl(I),
- IE->getIteratorDecl(I));
- return Res;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
- // Transform the callee.
- ExprResult Callee = getDerived().TransformExpr(E->getCallee());
- if (Callee.isInvalid())
- return ExprError();
- // Transform arguments.
- bool ArgChanged = false;
- SmallVector<Expr*, 8> Args;
- if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
- &ArgChanged))
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Callee.get() == E->getCallee() &&
- !ArgChanged)
- return SemaRef.MaybeBindToTemporary(E);
- // FIXME: Wrong source location information for the '('.
- SourceLocation FakeLParenLoc
- = ((Expr *)Callee.get())->getSourceRange().getBegin();
- Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
- if (E->hasStoredFPFeatures()) {
- FPOptionsOverride NewOverrides = E->getFPFeatures();
- getSema().CurFPFeatures =
- NewOverrides.applyOverrides(getSema().getLangOpts());
- getSema().FpPragmaStack.CurrentValue = NewOverrides;
- }
- return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
- Args,
- E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- NestedNameSpecifierLoc QualifierLoc;
- if (E->hasQualifier()) {
- QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
- if (!QualifierLoc)
- return ExprError();
- }
- SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
- ValueDecl *Member
- = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
- E->getMemberDecl()));
- if (!Member)
- return ExprError();
- NamedDecl *FoundDecl = E->getFoundDecl();
- if (FoundDecl == E->getMemberDecl()) {
- FoundDecl = Member;
- } else {
- FoundDecl = cast_or_null<NamedDecl>(
- getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
- if (!FoundDecl)
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() &&
- Base.get() == E->getBase() &&
- QualifierLoc == E->getQualifierLoc() &&
- Member == E->getMemberDecl() &&
- FoundDecl == E->getFoundDecl() &&
- !E->hasExplicitTemplateArgs()) {
- // Mark it referenced in the new context regardless.
- // FIXME: this is a bit instantiation-specific.
- SemaRef.MarkMemberReferenced(E);
- return E;
- }
- TemplateArgumentListInfo TransArgs;
- if (E->hasExplicitTemplateArgs()) {
- TransArgs.setLAngleLoc(E->getLAngleLoc());
- TransArgs.setRAngleLoc(E->getRAngleLoc());
- if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
- E->getNumTemplateArgs(),
- TransArgs))
- return ExprError();
- }
- // FIXME: Bogus source location for the operator
- SourceLocation FakeOperatorLoc =
- SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
- // FIXME: to do this check properly, we will need to preserve the
- // first-qualifier-in-scope here, just in case we had a dependent
- // base (and therefore couldn't do the check) and a
- // nested-name-qualifier (and therefore could do the lookup).
- NamedDecl *FirstQualifierInScope = nullptr;
- DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
- if (MemberNameInfo.getName()) {
- MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
- if (!MemberNameInfo.getName())
- return ExprError();
- }
- return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
- E->isArrow(),
- QualifierLoc,
- TemplateKWLoc,
- MemberNameInfo,
- Member,
- FoundDecl,
- (E->hasExplicitTemplateArgs()
- ? &TransArgs : nullptr),
- FirstQualifierInScope);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
- ExprResult LHS = getDerived().TransformExpr(E->getLHS());
- if (LHS.isInvalid())
- return ExprError();
- ExprResult RHS = getDerived().TransformExpr(E->getRHS());
- if (RHS.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- LHS.get() == E->getLHS() &&
- RHS.get() == E->getRHS())
- return E;
- if (E->isCompoundAssignmentOp())
- // FPFeatures has already been established from trailing storage
- return getDerived().RebuildBinaryOperator(
- E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
- Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
- FPOptionsOverride NewOverrides(E->getFPFeatures(getSema().getLangOpts()));
- getSema().CurFPFeatures =
- NewOverrides.applyOverrides(getSema().getLangOpts());
- getSema().FpPragmaStack.CurrentValue = NewOverrides;
- return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
- LHS.get(), RHS.get());
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
- CXXRewrittenBinaryOperator *E) {
- CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
- ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
- if (LHS.isInvalid())
- return ExprError();
- ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
- if (RHS.isInvalid())
- return ExprError();
- // Extract the already-resolved callee declarations so that we can restrict
- // ourselves to using them as the unqualified lookup results when rebuilding.
- UnresolvedSet<2> UnqualLookups;
- bool ChangedAnyLookups = false;
- Expr *PossibleBinOps[] = {E->getSemanticForm(),
- const_cast<Expr *>(Decomp.InnerBinOp)};
- for (Expr *PossibleBinOp : PossibleBinOps) {
- auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
- if (!Op)
- continue;
- auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
- if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
- continue;
- // Transform the callee in case we built a call to a local extern
- // declaration.
- NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
- E->getOperatorLoc(), Callee->getFoundDecl()));
- if (!Found)
- return ExprError();
- if (Found != Callee->getFoundDecl())
- ChangedAnyLookups = true;
- UnqualLookups.addDecl(Found);
- }
- if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
- LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
- // Mark all functions used in the rewrite as referenced. Note that when
- // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
- // function calls, and/or there might be a user-defined conversion sequence
- // applied to the operands of the <.
- // FIXME: this is a bit instantiation-specific.
- const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
- SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
- return E;
- }
- return getDerived().RebuildCXXRewrittenBinaryOperator(
- E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCompoundAssignOperator(
- CompoundAssignOperator *E) {
- Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
- FPOptionsOverride NewOverrides(E->getFPFeatures(getSema().getLangOpts()));
- getSema().CurFPFeatures =
- NewOverrides.applyOverrides(getSema().getLangOpts());
- getSema().FpPragmaStack.CurrentValue = NewOverrides;
- return getDerived().TransformBinaryOperator(E);
- }
- template<typename Derived>
- ExprResult TreeTransform<Derived>::
- TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
- // Just rebuild the common and RHS expressions and see whether we
- // get any changes.
- ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
- if (commonExpr.isInvalid())
- return ExprError();
- ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
- if (rhs.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- commonExpr.get() == e->getCommon() &&
- rhs.get() == e->getFalseExpr())
- return e;
- return getDerived().RebuildConditionalOperator(commonExpr.get(),
- e->getQuestionLoc(),
- nullptr,
- e->getColonLoc(),
- rhs.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
- ExprResult Cond = getDerived().TransformExpr(E->getCond());
- if (Cond.isInvalid())
- return ExprError();
- ExprResult LHS = getDerived().TransformExpr(E->getLHS());
- if (LHS.isInvalid())
- return ExprError();
- ExprResult RHS = getDerived().TransformExpr(E->getRHS());
- if (RHS.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Cond.get() == E->getCond() &&
- LHS.get() == E->getLHS() &&
- RHS.get() == E->getRHS())
- return E;
- return getDerived().RebuildConditionalOperator(Cond.get(),
- E->getQuestionLoc(),
- LHS.get(),
- E->getColonLoc(),
- RHS.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
- // Implicit casts are eliminated during transformation, since they
- // will be recomputed by semantic analysis after transformation.
- return getDerived().TransformExpr(E->getSubExprAsWritten());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
- TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
- if (!Type)
- return ExprError();
- ExprResult SubExpr
- = getDerived().TransformExpr(E->getSubExprAsWritten());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Type == E->getTypeInfoAsWritten() &&
- SubExpr.get() == E->getSubExpr())
- return E;
- return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
- Type,
- E->getRParenLoc(),
- SubExpr.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
- TypeSourceInfo *OldT = E->getTypeSourceInfo();
- TypeSourceInfo *NewT = getDerived().TransformType(OldT);
- if (!NewT)
- return ExprError();
- ExprResult Init = getDerived().TransformExpr(E->getInitializer());
- if (Init.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- OldT == NewT &&
- Init.get() == E->getInitializer())
- return SemaRef.MaybeBindToTemporary(E);
- // Note: the expression type doesn't necessarily match the
- // type-as-written, but that's okay, because it should always be
- // derivable from the initializer.
- return getDerived().RebuildCompoundLiteralExpr(
- E->getLParenLoc(), NewT,
- /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Base.get() == E->getBase())
- return E;
- // FIXME: Bad source location
- SourceLocation FakeOperatorLoc =
- SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
- return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
- E->getAccessorLoc(),
- E->getAccessor());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
- if (InitListExpr *Syntactic = E->getSyntacticForm())
- E = Syntactic;
- bool InitChanged = false;
- EnterExpressionEvaluationContext Context(
- getSema(), EnterExpressionEvaluationContext::InitList);
- SmallVector<Expr*, 4> Inits;
- if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
- Inits, &InitChanged))
- return ExprError();
- if (!getDerived().AlwaysRebuild() && !InitChanged) {
- // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
- // in some cases. We can't reuse it in general, because the syntactic and
- // semantic forms are linked, and we can't know that semantic form will
- // match even if the syntactic form does.
- }
- return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
- E->getRBraceLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
- Designation Desig;
- // transform the initializer value
- ExprResult Init = getDerived().TransformExpr(E->getInit());
- if (Init.isInvalid())
- return ExprError();
- // transform the designators.
- SmallVector<Expr*, 4> ArrayExprs;
- bool ExprChanged = false;
- for (const DesignatedInitExpr::Designator &D : E->designators()) {
- if (D.isFieldDesignator()) {
- Desig.AddDesignator(Designator::getField(D.getFieldName(),
- D.getDotLoc(),
- D.getFieldLoc()));
- if (D.getField()) {
- FieldDecl *Field = cast_or_null<FieldDecl>(
- getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
- if (Field != D.getField())
- // Rebuild the expression when the transformed FieldDecl is
- // different to the already assigned FieldDecl.
- ExprChanged = true;
- } else {
- // Ensure that the designator expression is rebuilt when there isn't
- // a resolved FieldDecl in the designator as we don't want to assign
- // a FieldDecl to a pattern designator that will be instantiated again.
- ExprChanged = true;
- }
- continue;
- }
- if (D.isArrayDesignator()) {
- ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
- if (Index.isInvalid())
- return ExprError();
- Desig.AddDesignator(
- Designator::getArray(Index.get(), D.getLBracketLoc()));
- ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
- ArrayExprs.push_back(Index.get());
- continue;
- }
- assert(D.isArrayRangeDesignator() && "New kind of designator?");
- ExprResult Start
- = getDerived().TransformExpr(E->getArrayRangeStart(D));
- if (Start.isInvalid())
- return ExprError();
- ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
- if (End.isInvalid())
- return ExprError();
- Desig.AddDesignator(Designator::getArrayRange(Start.get(),
- End.get(),
- D.getLBracketLoc(),
- D.getEllipsisLoc()));
- ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
- End.get() != E->getArrayRangeEnd(D);
- ArrayExprs.push_back(Start.get());
- ArrayExprs.push_back(End.get());
- }
- if (!getDerived().AlwaysRebuild() &&
- Init.get() == E->getInit() &&
- !ExprChanged)
- return E;
- return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
- E->getEqualOrColonLoc(),
- E->usesGNUSyntax(), Init.get());
- }
- // Seems that if TransformInitListExpr() only works on the syntactic form of an
- // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
- DesignatedInitUpdateExpr *E) {
- llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
- "initializer");
- return ExprError();
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformNoInitExpr(
- NoInitExpr *E) {
- llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
- return ExprError();
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
- llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
- return ExprError();
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
- llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
- return ExprError();
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformImplicitValueInitExpr(
- ImplicitValueInitExpr *E) {
- TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
- // FIXME: Will we ever have proper type location here? Will we actually
- // need to transform the type?
- QualType T = getDerived().TransformType(E->getType());
- if (T.isNull())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- T == E->getType())
- return E;
- return getDerived().RebuildImplicitValueInitExpr(T);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
- TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
- if (!TInfo)
- return ExprError();
- ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- TInfo == E->getWrittenTypeInfo() &&
- SubExpr.get() == E->getSubExpr())
- return E;
- return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
- TInfo, E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
- bool ArgumentChanged = false;
- SmallVector<Expr*, 4> Inits;
- if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
- &ArgumentChanged))
- return ExprError();
- return getDerived().RebuildParenListExpr(E->getLParenLoc(),
- Inits,
- E->getRParenLoc());
- }
- /// Transform an address-of-label expression.
- ///
- /// By default, the transformation of an address-of-label expression always
- /// rebuilds the expression, so that the label identifier can be resolved to
- /// the corresponding label statement by semantic analysis.
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
- Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
- E->getLabel());
- if (!LD)
- return ExprError();
- return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
- cast<LabelDecl>(LD));
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
- SemaRef.ActOnStartStmtExpr();
- StmtResult SubStmt
- = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
- if (SubStmt.isInvalid()) {
- SemaRef.ActOnStmtExprError();
- return ExprError();
- }
- unsigned OldDepth = E->getTemplateDepth();
- unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
- if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
- SubStmt.get() == E->getSubStmt()) {
- // Calling this an 'error' is unintuitive, but it does the right thing.
- SemaRef.ActOnStmtExprError();
- return SemaRef.MaybeBindToTemporary(E);
- }
- return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
- E->getRParenLoc(), NewDepth);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
- ExprResult Cond = getDerived().TransformExpr(E->getCond());
- if (Cond.isInvalid())
- return ExprError();
- ExprResult LHS = getDerived().TransformExpr(E->getLHS());
- if (LHS.isInvalid())
- return ExprError();
- ExprResult RHS = getDerived().TransformExpr(E->getRHS());
- if (RHS.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Cond.get() == E->getCond() &&
- LHS.get() == E->getLHS() &&
- RHS.get() == E->getRHS())
- return E;
- return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
- Cond.get(), LHS.get(), RHS.get(),
- E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
- switch (E->getOperator()) {
- case OO_New:
- case OO_Delete:
- case OO_Array_New:
- case OO_Array_Delete:
- llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
- case OO_Call: {
- // This is a call to an object's operator().
- assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
- // Transform the object itself.
- ExprResult Object = getDerived().TransformExpr(E->getArg(0));
- if (Object.isInvalid())
- return ExprError();
- // FIXME: Poor location information
- SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
- static_cast<Expr *>(Object.get())->getEndLoc());
- // Transform the call arguments.
- SmallVector<Expr*, 8> Args;
- if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
- Args))
- return ExprError();
- return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
- E->getEndLoc());
- }
- #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
- case OO_##Name:
- #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
- #include "clang/Basic/OperatorKinds.def"
- case OO_Subscript:
- // Handled below.
- break;
- case OO_Conditional:
- llvm_unreachable("conditional operator is not actually overloadable");
- case OO_None:
- case NUM_OVERLOADED_OPERATORS:
- llvm_unreachable("not an overloaded operator?");
- }
- ExprResult Callee = getDerived().TransformExpr(E->getCallee());
- if (Callee.isInvalid())
- return ExprError();
- ExprResult First;
- if (E->getOperator() == OO_Amp)
- First = getDerived().TransformAddressOfOperand(E->getArg(0));
- else
- First = getDerived().TransformExpr(E->getArg(0));
- if (First.isInvalid())
- return ExprError();
- ExprResult Second;
- if (E->getNumArgs() == 2) {
- Second = getDerived().TransformExpr(E->getArg(1));
- if (Second.isInvalid())
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() &&
- Callee.get() == E->getCallee() &&
- First.get() == E->getArg(0) &&
- (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
- return SemaRef.MaybeBindToTemporary(E);
- Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
- FPOptionsOverride NewOverrides(E->getFPFeatures());
- getSema().CurFPFeatures =
- NewOverrides.applyOverrides(getSema().getLangOpts());
- getSema().FpPragmaStack.CurrentValue = NewOverrides;
- return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
- E->getOperatorLoc(),
- Callee.get(),
- First.get(),
- Second.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
- return getDerived().TransformCallExpr(E);
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
- bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function &&
- getSema().CurContext != E->getParentContext();
- if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
- return E;
- return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(),
- E->getEndLoc(),
- getSema().CurContext);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
- // Transform the callee.
- ExprResult Callee = getDerived().TransformExpr(E->getCallee());
- if (Callee.isInvalid())
- return ExprError();
- // Transform exec config.
- ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
- if (EC.isInvalid())
- return ExprError();
- // Transform arguments.
- bool ArgChanged = false;
- SmallVector<Expr*, 8> Args;
- if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
- &ArgChanged))
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Callee.get() == E->getCallee() &&
- !ArgChanged)
- return SemaRef.MaybeBindToTemporary(E);
- // FIXME: Wrong source location information for the '('.
- SourceLocation FakeLParenLoc
- = ((Expr *)Callee.get())->getSourceRange().getBegin();
- return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
- Args,
- E->getRParenLoc(), EC.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
- TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
- if (!Type)
- return ExprError();
- ExprResult SubExpr
- = getDerived().TransformExpr(E->getSubExprAsWritten());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Type == E->getTypeInfoAsWritten() &&
- SubExpr.get() == E->getSubExpr())
- return E;
- return getDerived().RebuildCXXNamedCastExpr(
- E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
- Type, E->getAngleBrackets().getEnd(),
- // FIXME. this should be '(' location
- E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) {
- TypeSourceInfo *TSI =
- getDerived().TransformType(BCE->getTypeInfoAsWritten());
- if (!TSI)
- return ExprError();
- ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
- if (Sub.isInvalid())
- return ExprError();
- return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
- Sub.get(), BCE->getEndLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
- return getDerived().TransformCXXNamedCastExpr(E);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
- return getDerived().TransformCXXNamedCastExpr(E);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
- CXXReinterpretCastExpr *E) {
- return getDerived().TransformCXXNamedCastExpr(E);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
- return getDerived().TransformCXXNamedCastExpr(E);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
- return getDerived().TransformCXXNamedCastExpr(E);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
- CXXFunctionalCastExpr *E) {
- TypeSourceInfo *Type =
- getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
- if (!Type)
- return ExprError();
- ExprResult SubExpr
- = getDerived().TransformExpr(E->getSubExprAsWritten());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Type == E->getTypeInfoAsWritten() &&
- SubExpr.get() == E->getSubExpr())
- return E;
- return getDerived().RebuildCXXFunctionalCastExpr(Type,
- E->getLParenLoc(),
- SubExpr.get(),
- E->getRParenLoc(),
- E->isListInitialization());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
- if (E->isTypeOperand()) {
- TypeSourceInfo *TInfo
- = getDerived().TransformType(E->getTypeOperandSourceInfo());
- if (!TInfo)
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- TInfo == E->getTypeOperandSourceInfo())
- return E;
- return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
- TInfo, E->getEndLoc());
- }
- // Typeid's operand is an unevaluated context, unless it's a polymorphic
- // type. We must not unilaterally enter unevaluated context here, as then
- // semantic processing can re-transform an already transformed operand.
- Expr *Op = E->getExprOperand();
- auto EvalCtx = Sema::ExpressionEvaluationContext::Unevaluated;
- if (E->isGLValue())
- if (auto *RecordT = Op->getType()->getAs<RecordType>())
- if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic())
- EvalCtx = SemaRef.ExprEvalContexts.back().Context;
- EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
- Sema::ReuseLambdaContextDecl);
- ExprResult SubExpr = getDerived().TransformExpr(Op);
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- SubExpr.get() == E->getExprOperand())
- return E;
- return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
- SubExpr.get(), E->getEndLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
- if (E->isTypeOperand()) {
- TypeSourceInfo *TInfo
- = getDerived().TransformType(E->getTypeOperandSourceInfo());
- if (!TInfo)
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- TInfo == E->getTypeOperandSourceInfo())
- return E;
- return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
- TInfo, E->getEndLoc());
- }
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
- ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- SubExpr.get() == E->getExprOperand())
- return E;
- return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
- SubExpr.get(), E->getEndLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
- CXXNullPtrLiteralExpr *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
- QualType T = getSema().getCurrentThisType();
- if (!getDerived().AlwaysRebuild() && T == E->getType()) {
- // Mark it referenced in the new context regardless.
- // FIXME: this is a bit instantiation-specific.
- getSema().MarkThisReferenced(E);
- return E;
- }
- return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
- ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- SubExpr.get() == E->getSubExpr())
- return E;
- return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
- E->isThrownVariableInScope());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
- ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
- getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
- if (!Param)
- return ExprError();
- if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
- E->getUsedContext() == SemaRef.CurContext)
- return E;
- return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
- FieldDecl *Field = cast_or_null<FieldDecl>(
- getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
- if (!Field)
- return ExprError();
- if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
- E->getUsedContext() == SemaRef.CurContext)
- return E;
- return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
- CXXScalarValueInitExpr *E) {
- TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
- if (!T)
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- T == E->getTypeSourceInfo())
- return E;
- return getDerived().RebuildCXXScalarValueInitExpr(T,
- /*FIXME:*/T->getTypeLoc().getEndLoc(),
- E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
- // Transform the type that we're allocating
- TypeSourceInfo *AllocTypeInfo =
- getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
- if (!AllocTypeInfo)
- return ExprError();
- // Transform the size of the array we're allocating (if any).
- Optional<Expr *> ArraySize;
- if (Optional<Expr *> OldArraySize = E->getArraySize()) {
- ExprResult NewArraySize;
- if (*OldArraySize) {
- NewArraySize = getDerived().TransformExpr(*OldArraySize);
- if (NewArraySize.isInvalid())
- return ExprError();
- }
- ArraySize = NewArraySize.get();
- }
- // Transform the placement arguments (if any).
- bool ArgumentChanged = false;
- SmallVector<Expr*, 8> PlacementArgs;
- if (getDerived().TransformExprs(E->getPlacementArgs(),
- E->getNumPlacementArgs(), true,
- PlacementArgs, &ArgumentChanged))
- return ExprError();
- // Transform the initializer (if any).
- Expr *OldInit = E->getInitializer();
- ExprResult NewInit;
- if (OldInit)
- NewInit = getDerived().TransformInitializer(OldInit, true);
- if (NewInit.isInvalid())
- return ExprError();
- // Transform new operator and delete operator.
- FunctionDecl *OperatorNew = nullptr;
- if (E->getOperatorNew()) {
- OperatorNew = cast_or_null<FunctionDecl>(
- getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
- if (!OperatorNew)
- return ExprError();
- }
- FunctionDecl *OperatorDelete = nullptr;
- if (E->getOperatorDelete()) {
- OperatorDelete = cast_or_null<FunctionDecl>(
- getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
- if (!OperatorDelete)
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() &&
- AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
- ArraySize == E->getArraySize() &&
- NewInit.get() == OldInit &&
- OperatorNew == E->getOperatorNew() &&
- OperatorDelete == E->getOperatorDelete() &&
- !ArgumentChanged) {
- // Mark any declarations we need as referenced.
- // FIXME: instantiation-specific.
- if (OperatorNew)
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
- if (OperatorDelete)
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
- if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
- QualType ElementType
- = SemaRef.Context.getBaseElementType(E->getAllocatedType());
- if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
- CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
- if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
- }
- }
- }
- return E;
- }
- QualType AllocType = AllocTypeInfo->getType();
- if (!ArraySize) {
- // If no array size was specified, but the new expression was
- // instantiated with an array type (e.g., "new T" where T is
- // instantiated with "int[4]"), extract the outer bound from the
- // array type as our array size. We do this with constant and
- // dependently-sized array types.
- const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
- if (!ArrayT) {
- // Do nothing
- } else if (const ConstantArrayType *ConsArrayT
- = dyn_cast<ConstantArrayType>(ArrayT)) {
- ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
- SemaRef.Context.getSizeType(),
- /*FIXME:*/ E->getBeginLoc());
- AllocType = ConsArrayT->getElementType();
- } else if (const DependentSizedArrayType *DepArrayT
- = dyn_cast<DependentSizedArrayType>(ArrayT)) {
- if (DepArrayT->getSizeExpr()) {
- ArraySize = DepArrayT->getSizeExpr();
- AllocType = DepArrayT->getElementType();
- }
- }
- }
- return getDerived().RebuildCXXNewExpr(
- E->getBeginLoc(), E->isGlobalNew(),
- /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
- /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
- AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
- ExprResult Operand = getDerived().TransformExpr(E->getArgument());
- if (Operand.isInvalid())
- return ExprError();
- // Transform the delete operator, if known.
- FunctionDecl *OperatorDelete = nullptr;
- if (E->getOperatorDelete()) {
- OperatorDelete = cast_or_null<FunctionDecl>(
- getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
- if (!OperatorDelete)
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() &&
- Operand.get() == E->getArgument() &&
- OperatorDelete == E->getOperatorDelete()) {
- // Mark any declarations we need as referenced.
- // FIXME: instantiation-specific.
- if (OperatorDelete)
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
- if (!E->getArgument()->isTypeDependent()) {
- QualType Destroyed = SemaRef.Context.getBaseElementType(
- E->getDestroyedType());
- if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
- CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
- SemaRef.LookupDestructor(Record));
- }
- }
- return E;
- }
- return getDerived().RebuildCXXDeleteExpr(
- E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
- CXXPseudoDestructorExpr *E) {
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- ParsedType ObjectTypePtr;
- bool MayBePseudoDestructor = false;
- Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
- E->getOperatorLoc(),
- E->isArrow()? tok::arrow : tok::period,
- ObjectTypePtr,
- MayBePseudoDestructor);
- if (Base.isInvalid())
- return ExprError();
- QualType ObjectType = ObjectTypePtr.get();
- NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
- if (QualifierLoc) {
- QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
- if (!QualifierLoc)
- return ExprError();
- }
- CXXScopeSpec SS;
- SS.Adopt(QualifierLoc);
- PseudoDestructorTypeStorage Destroyed;
- if (E->getDestroyedTypeInfo()) {
- TypeSourceInfo *DestroyedTypeInfo
- = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
- ObjectType, nullptr, SS);
- if (!DestroyedTypeInfo)
- return ExprError();
- Destroyed = DestroyedTypeInfo;
- } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
- // We aren't likely to be able to resolve the identifier down to a type
- // now anyway, so just retain the identifier.
- Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
- E->getDestroyedTypeLoc());
- } else {
- // Look for a destructor known with the given name.
- ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
- *E->getDestroyedTypeIdentifier(),
- E->getDestroyedTypeLoc(),
- /*Scope=*/nullptr,
- SS, ObjectTypePtr,
- false);
- if (!T)
- return ExprError();
- Destroyed
- = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
- E->getDestroyedTypeLoc());
- }
- TypeSourceInfo *ScopeTypeInfo = nullptr;
- if (E->getScopeTypeInfo()) {
- CXXScopeSpec EmptySS;
- ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
- E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
- if (!ScopeTypeInfo)
- return ExprError();
- }
- return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
- E->getOperatorLoc(),
- E->isArrow(),
- SS,
- ScopeTypeInfo,
- E->getColonColonLoc(),
- E->getTildeLoc(),
- Destroyed);
- }
- template <typename Derived>
- bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
- bool RequiresADL,
- LookupResult &R) {
- // Transform all the decls.
- bool AllEmptyPacks = true;
- for (auto *OldD : Old->decls()) {
- Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
- if (!InstD) {
- // Silently ignore these if a UsingShadowDecl instantiated to nothing.
- // This can happen because of dependent hiding.
- if (isa<UsingShadowDecl>(OldD))
- continue;
- else {
- R.clear();
- return true;
- }
- }
- // Expand using pack declarations.
- NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
- ArrayRef<NamedDecl*> Decls = SingleDecl;
- if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
- Decls = UPD->expansions();
- // Expand using declarations.
- for (auto *D : Decls) {
- if (auto *UD = dyn_cast<UsingDecl>(D)) {
- for (auto *SD : UD->shadows())
- R.addDecl(SD);
- } else {
- R.addDecl(D);
- }
- }
- AllEmptyPacks &= Decls.empty();
- };
- // C++ [temp.res]/8.4.2:
- // The program is ill-formed, no diagnostic required, if [...] lookup for
- // a name in the template definition found a using-declaration, but the
- // lookup in the corresponding scope in the instantiation odoes not find
- // any declarations because the using-declaration was a pack expansion and
- // the corresponding pack is empty
- if (AllEmptyPacks && !RequiresADL) {
- getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
- << isa<UnresolvedMemberExpr>(Old) << Old->getName();
- return true;
- }
- // Resolve a kind, but don't do any further analysis. If it's
- // ambiguous, the callee needs to deal with it.
- R.resolveKind();
- return false;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformUnresolvedLookupExpr(
- UnresolvedLookupExpr *Old) {
- LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
- Sema::LookupOrdinaryName);
- // Transform the declaration set.
- if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
- return ExprError();
- // Rebuild the nested-name qualifier, if present.
- CXXScopeSpec SS;
- if (Old->getQualifierLoc()) {
- NestedNameSpecifierLoc QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
- if (!QualifierLoc)
- return ExprError();
- SS.Adopt(QualifierLoc);
- }
- if (Old->getNamingClass()) {
- CXXRecordDecl *NamingClass
- = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
- Old->getNameLoc(),
- Old->getNamingClass()));
- if (!NamingClass) {
- R.clear();
- return ExprError();
- }
- R.setNamingClass(NamingClass);
- }
- SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
- // If we have neither explicit template arguments, nor the template keyword,
- // it's a normal declaration name or member reference.
- if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
- NamedDecl *D = R.getAsSingle<NamedDecl>();
- // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
- // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
- // give a good diagnostic.
- if (D && D->isCXXInstanceMember()) {
- return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
- /*TemplateArgs=*/nullptr,
- /*Scope=*/nullptr);
- }
- return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
- }
- // If we have template arguments, rebuild them, then rebuild the
- // templateid expression.
- TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
- if (Old->hasExplicitTemplateArgs() &&
- getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
- Old->getNumTemplateArgs(),
- TransArgs)) {
- R.clear();
- return ExprError();
- }
- return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
- Old->requiresADL(), &TransArgs);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
- bool ArgChanged = false;
- SmallVector<TypeSourceInfo *, 4> Args;
- for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
- TypeSourceInfo *From = E->getArg(I);
- TypeLoc FromTL = From->getTypeLoc();
- if (!FromTL.getAs<PackExpansionTypeLoc>()) {
- TypeLocBuilder TLB;
- TLB.reserve(FromTL.getFullDataSize());
- QualType To = getDerived().TransformType(TLB, FromTL);
- if (To.isNull())
- return ExprError();
- if (To == From->getType())
- Args.push_back(From);
- else {
- Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
- ArgChanged = true;
- }
- continue;
- }
- ArgChanged = true;
- // We have a pack expansion. Instantiate it.
- PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
- TypeLoc PatternTL = ExpansionTL.getPatternLoc();
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
- // Determine whether the set of unexpanded parameter packs can and should
- // be expanded.
- bool Expand = true;
- bool RetainExpansion = false;
- Optional<unsigned> OrigNumExpansions =
- ExpansionTL.getTypePtr()->getNumExpansions();
- Optional<unsigned> NumExpansions = OrigNumExpansions;
- if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
- PatternTL.getSourceRange(),
- Unexpanded,
- Expand, RetainExpansion,
- NumExpansions))
- return ExprError();
- if (!Expand) {
- // The transform has determined that we should perform a simple
- // transformation on the pack expansion, producing another pack
- // expansion.
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- TypeLocBuilder TLB;
- TLB.reserve(From->getTypeLoc().getFullDataSize());
- QualType To = getDerived().TransformType(TLB, PatternTL);
- if (To.isNull())
- return ExprError();
- To = getDerived().RebuildPackExpansionType(To,
- PatternTL.getSourceRange(),
- ExpansionTL.getEllipsisLoc(),
- NumExpansions);
- if (To.isNull())
- return ExprError();
- PackExpansionTypeLoc ToExpansionTL
- = TLB.push<PackExpansionTypeLoc>(To);
- ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
- Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
- continue;
- }
- // Expand the pack expansion by substituting for each argument in the
- // pack(s).
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
- TypeLocBuilder TLB;
- TLB.reserve(PatternTL.getFullDataSize());
- QualType To = getDerived().TransformType(TLB, PatternTL);
- if (To.isNull())
- return ExprError();
- if (To->containsUnexpandedParameterPack()) {
- To = getDerived().RebuildPackExpansionType(To,
- PatternTL.getSourceRange(),
- ExpansionTL.getEllipsisLoc(),
- NumExpansions);
- if (To.isNull())
- return ExprError();
- PackExpansionTypeLoc ToExpansionTL
- = TLB.push<PackExpansionTypeLoc>(To);
- ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
- }
- Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
- }
- if (!RetainExpansion)
- continue;
- // If we're supposed to retain a pack expansion, do so by temporarily
- // forgetting the partially-substituted parameter pack.
- ForgetPartiallySubstitutedPackRAII Forget(getDerived());
- TypeLocBuilder TLB;
- TLB.reserve(From->getTypeLoc().getFullDataSize());
- QualType To = getDerived().TransformType(TLB, PatternTL);
- if (To.isNull())
- return ExprError();
- To = getDerived().RebuildPackExpansionType(To,
- PatternTL.getSourceRange(),
- ExpansionTL.getEllipsisLoc(),
- NumExpansions);
- if (To.isNull())
- return ExprError();
- PackExpansionTypeLoc ToExpansionTL
- = TLB.push<PackExpansionTypeLoc>(To);
- ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
- Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
- }
- if (!getDerived().AlwaysRebuild() && !ArgChanged)
- return E;
- return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
- E->getEndLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformConceptSpecializationExpr(
- ConceptSpecializationExpr *E) {
- const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
- TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
- if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
- Old->NumTemplateArgs, TransArgs))
- return ExprError();
- return getDerived().RebuildConceptSpecializationExpr(
- E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
- E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
- &TransArgs);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
- SmallVector<ParmVarDecl*, 4> TransParams;
- SmallVector<QualType, 4> TransParamTypes;
- Sema::ExtParameterInfoBuilder ExtParamInfos;
- // C++2a [expr.prim.req]p2
- // Expressions appearing within a requirement-body are unevaluated operands.
- EnterExpressionEvaluationContext Ctx(
- SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
- RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
- getSema().Context, getSema().CurContext,
- E->getBody()->getBeginLoc());
- Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
- if (getDerived().TransformFunctionTypeParams(E->getRequiresKWLoc(),
- E->getLocalParameters(),
- /*ParamTypes=*/nullptr,
- /*ParamInfos=*/nullptr,
- TransParamTypes, &TransParams,
- ExtParamInfos))
- return ExprError();
- for (ParmVarDecl *Param : TransParams)
- Param->setDeclContext(Body);
- SmallVector<concepts::Requirement *, 4> TransReqs;
- if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
- TransReqs))
- return ExprError();
- for (concepts::Requirement *Req : TransReqs) {
- if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
- if (ER->getReturnTypeRequirement().isTypeConstraint()) {
- ER->getReturnTypeRequirement()
- .getTypeConstraintTemplateParameterList()->getParam(0)
- ->setDeclContext(Body);
- }
- }
- }
- return getDerived().RebuildRequiresExpr(E->getRequiresKWLoc(), Body,
- TransParams, TransReqs,
- E->getRBraceLoc());
- }
- template<typename Derived>
- bool TreeTransform<Derived>::TransformRequiresExprRequirements(
- ArrayRef<concepts::Requirement *> Reqs,
- SmallVectorImpl<concepts::Requirement *> &Transformed) {
- for (concepts::Requirement *Req : Reqs) {
- concepts::Requirement *TransReq = nullptr;
- if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
- TransReq = getDerived().TransformTypeRequirement(TypeReq);
- else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
- TransReq = getDerived().TransformExprRequirement(ExprReq);
- else
- TransReq = getDerived().TransformNestedRequirement(
- cast<concepts::NestedRequirement>(Req));
- if (!TransReq)
- return true;
- Transformed.push_back(TransReq);
- }
- return false;
- }
- template<typename Derived>
- concepts::TypeRequirement *
- TreeTransform<Derived>::TransformTypeRequirement(
- concepts::TypeRequirement *Req) {
- if (Req->isSubstitutionFailure()) {
- if (getDerived().AlwaysRebuild())
- return getDerived().RebuildTypeRequirement(
- Req->getSubstitutionDiagnostic());
- return Req;
- }
- TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
- if (!TransType)
- return nullptr;
- return getDerived().RebuildTypeRequirement(TransType);
- }
- template<typename Derived>
- concepts::ExprRequirement *
- TreeTransform<Derived>::TransformExprRequirement(concepts::ExprRequirement *Req) {
- llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
- if (Req->isExprSubstitutionFailure())
- TransExpr = Req->getExprSubstitutionDiagnostic();
- else {
- ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
- if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
- TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
- if (TransExprRes.isInvalid())
- return nullptr;
- TransExpr = TransExprRes.get();
- }
- llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
- const auto &RetReq = Req->getReturnTypeRequirement();
- if (RetReq.isEmpty())
- TransRetReq.emplace();
- else if (RetReq.isSubstitutionFailure())
- TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
- else if (RetReq.isTypeConstraint()) {
- TemplateParameterList *OrigTPL =
- RetReq.getTypeConstraintTemplateParameterList();
- TemplateParameterList *TPL =
- getDerived().TransformTemplateParameterList(OrigTPL);
- if (!TPL)
- return nullptr;
- TransRetReq.emplace(TPL);
- }
- assert(TransRetReq.hasValue() &&
- "All code paths leading here must set TransRetReq");
- if (Expr *E = TransExpr.dyn_cast<Expr *>())
- return getDerived().RebuildExprRequirement(E, Req->isSimple(),
- Req->getNoexceptLoc(),
- std::move(*TransRetReq));
- return getDerived().RebuildExprRequirement(
- TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(),
- Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
- }
- template<typename Derived>
- concepts::NestedRequirement *
- TreeTransform<Derived>::TransformNestedRequirement(
- concepts::NestedRequirement *Req) {
- if (Req->isSubstitutionFailure()) {
- if (getDerived().AlwaysRebuild())
- return getDerived().RebuildNestedRequirement(
- Req->getSubstitutionDiagnostic());
- return Req;
- }
- ExprResult TransConstraint =
- getDerived().TransformExpr(Req->getConstraintExpr());
- if (TransConstraint.isInvalid())
- return nullptr;
- return getDerived().RebuildNestedRequirement(TransConstraint.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
- TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
- if (!T)
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- T == E->getQueriedTypeSourceInfo())
- return E;
- ExprResult SubExpr;
- {
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
- SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
- return E;
- }
- return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
- SubExpr.get(), E->getEndLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
- ExprResult SubExpr;
- {
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
- SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
- return E;
- }
- return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
- SubExpr.get(), E->getEndLoc());
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
- ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
- TypeSourceInfo **RecoveryTSI) {
- ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
- DRE, AddrTaken, RecoveryTSI);
- // Propagate both errors and recovered types, which return ExprEmpty.
- if (!NewDRE.isUsable())
- return NewDRE;
- // We got an expr, wrap it up in parens.
- if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
- return PE;
- return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
- PE->getRParen());
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
- DependentScopeDeclRefExpr *E) {
- return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
- nullptr);
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
- DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
- TypeSourceInfo **RecoveryTSI) {
- assert(E->getQualifierLoc());
- NestedNameSpecifierLoc QualifierLoc =
- getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
- if (!QualifierLoc)
- return ExprError();
- SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
- // TODO: If this is a conversion-function-id, verify that the
- // destination type name (if present) resolves the same way after
- // instantiation as it did in the local scope.
- DeclarationNameInfo NameInfo =
- getDerived().TransformDeclarationNameInfo(E->getNameInfo());
- if (!NameInfo.getName())
- return ExprError();
- if (!E->hasExplicitTemplateArgs()) {
- if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
- // Note: it is sufficient to compare the Name component of NameInfo:
- // if name has not changed, DNLoc has not changed either.
- NameInfo.getName() == E->getDeclName())
- return E;
- return getDerived().RebuildDependentScopeDeclRefExpr(
- QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
- IsAddressOfOperand, RecoveryTSI);
- }
- TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
- if (getDerived().TransformTemplateArguments(
- E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
- return ExprError();
- return getDerived().RebuildDependentScopeDeclRefExpr(
- QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
- RecoveryTSI);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
- // CXXConstructExprs other than for list-initialization and
- // CXXTemporaryObjectExpr are always implicit, so when we have
- // a 1-argument construction we just transform that argument.
- if (getDerived().AllowSkippingCXXConstructExpr() &&
- ((E->getNumArgs() == 1 ||
- (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
- (!getDerived().DropCallArgument(E->getArg(0))) &&
- !E->isListInitialization()))
- return getDerived().TransformInitializer(E->getArg(0),
- /*DirectInit*/ false);
- TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
- QualType T = getDerived().TransformType(E->getType());
- if (T.isNull())
- return ExprError();
- CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
- getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
- if (!Constructor)
- return ExprError();
- bool ArgumentChanged = false;
- SmallVector<Expr*, 8> Args;
- {
- EnterExpressionEvaluationContext Context(
- getSema(), EnterExpressionEvaluationContext::InitList,
- E->isListInitialization());
- if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
- &ArgumentChanged))
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() &&
- T == E->getType() &&
- Constructor == E->getConstructor() &&
- !ArgumentChanged) {
- // Mark the constructor as referenced.
- // FIXME: Instantiation-specific
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
- return E;
- }
- return getDerived().RebuildCXXConstructExpr(
- T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
- E->hadMultipleCandidates(), E->isListInitialization(),
- E->isStdInitListInitialization(), E->requiresZeroInitialization(),
- E->getConstructionKind(), E->getParenOrBraceRange());
- }
- template<typename Derived>
- ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
- CXXInheritedCtorInitExpr *E) {
- QualType T = getDerived().TransformType(E->getType());
- if (T.isNull())
- return ExprError();
- CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
- getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
- if (!Constructor)
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- T == E->getType() &&
- Constructor == E->getConstructor()) {
- // Mark the constructor as referenced.
- // FIXME: Instantiation-specific
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
- return E;
- }
- return getDerived().RebuildCXXInheritedCtorInitExpr(
- T, E->getLocation(), Constructor,
- E->constructsVBase(), E->inheritedFromVBase());
- }
- /// Transform a C++ temporary-binding expression.
- ///
- /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
- /// transform the subexpression and return that.
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
- return getDerived().TransformExpr(E->getSubExpr());
- }
- /// Transform a C++ expression that contains cleanups that should
- /// be run after the expression is evaluated.
- ///
- /// Since ExprWithCleanups nodes are implicitly generated, we
- /// just transform the subexpression and return that.
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
- return getDerived().TransformExpr(E->getSubExpr());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
- CXXTemporaryObjectExpr *E) {
- TypeSourceInfo *T =
- getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
- if (!T)
- return ExprError();
- CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
- getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
- if (!Constructor)
- return ExprError();
- bool ArgumentChanged = false;
- SmallVector<Expr*, 8> Args;
- Args.reserve(E->getNumArgs());
- {
- EnterExpressionEvaluationContext Context(
- getSema(), EnterExpressionEvaluationContext::InitList,
- E->isListInitialization());
- if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
- &ArgumentChanged))
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() &&
- T == E->getTypeSourceInfo() &&
- Constructor == E->getConstructor() &&
- !ArgumentChanged) {
- // FIXME: Instantiation-specific
- SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
- return SemaRef.MaybeBindToTemporary(E);
- }
- // FIXME: We should just pass E->isListInitialization(), but we're not
- // prepared to handle list-initialization without a child InitListExpr.
- SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
- return getDerived().RebuildCXXTemporaryObjectExpr(
- T, LParenLoc, Args, E->getEndLoc(),
- /*ListInitialization=*/LParenLoc.isInvalid());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
- // Transform any init-capture expressions before entering the scope of the
- // lambda body, because they are not semantically within that scope.
- typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
- struct TransformedInitCapture {
- // The location of the ... if the result is retaining a pack expansion.
- SourceLocation EllipsisLoc;
- // Zero or more expansions of the init-capture.
- SmallVector<InitCaptureInfoTy, 4> Expansions;
- };
- SmallVector<TransformedInitCapture, 4> InitCaptures;
- InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
- for (LambdaExpr::capture_iterator C = E->capture_begin(),
- CEnd = E->capture_end();
- C != CEnd; ++C) {
- if (!E->isInitCapture(C))
- continue;
- TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
- VarDecl *OldVD = C->getCapturedVar();
- auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
- Optional<unsigned> NumExpansions) {
- ExprResult NewExprInitResult = getDerived().TransformInitializer(
- OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
- if (NewExprInitResult.isInvalid()) {
- Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
- return;
- }
- Expr *NewExprInit = NewExprInitResult.get();
- QualType NewInitCaptureType =
- getSema().buildLambdaInitCaptureInitialization(
- C->getLocation(), OldVD->getType()->isReferenceType(),
- EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
- C->getCapturedVar()->getInitStyle() != VarDecl::CInit,
- NewExprInit);
- Result.Expansions.push_back(
- InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
- };
- // If this is an init-capture pack, consider expanding the pack now.
- if (OldVD->isParameterPack()) {
- PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
- ->getTypeLoc()
- .castAs<PackExpansionTypeLoc>();
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
- // Determine whether the set of unexpanded parameter packs can and should
- // be expanded.
- bool Expand = true;
- bool RetainExpansion = false;
- Optional<unsigned> OrigNumExpansions =
- ExpansionTL.getTypePtr()->getNumExpansions();
- Optional<unsigned> NumExpansions = OrigNumExpansions;
- if (getDerived().TryExpandParameterPacks(
- ExpansionTL.getEllipsisLoc(),
- OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
- RetainExpansion, NumExpansions))
- return ExprError();
- if (Expand) {
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
- SubstInitCapture(SourceLocation(), None);
- }
- }
- if (!Expand || RetainExpansion) {
- ForgetPartiallySubstitutedPackRAII Forget(getDerived());
- SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
- Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
- }
- } else {
- SubstInitCapture(SourceLocation(), None);
- }
- }
- LambdaScopeInfo *LSI = getSema().PushLambdaScope();
- Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
- // Transform the template parameters, and add them to the current
- // instantiation scope. The null case is handled correctly.
- auto TPL = getDerived().TransformTemplateParameterList(
- E->getTemplateParameterList());
- LSI->GLTemplateParameterList = TPL;
- // Transform the type of the original lambda's call operator.
- // The transformation MUST be done in the CurrentInstantiationScope since
- // it introduces a mapping of the original to the newly created
- // transformed parameters.
- TypeSourceInfo *NewCallOpTSI = nullptr;
- {
- TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
- FunctionProtoTypeLoc OldCallOpFPTL =
- OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
- TypeLocBuilder NewCallOpTLBuilder;
- SmallVector<QualType, 4> ExceptionStorage;
- TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
- QualType NewCallOpType = TransformFunctionProtoType(
- NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
- [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
- return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
- ExceptionStorage, Changed);
- });
- if (NewCallOpType.isNull())
- return ExprError();
- NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
- NewCallOpType);
- }
- // Transform the trailing requires clause
- ExprResult NewTrailingRequiresClause;
- if (Expr *TRC = E->getCallOperator()->getTrailingRequiresClause())
- // FIXME: Concepts: Substitution into requires clause should only happen
- // when checking satisfaction.
- NewTrailingRequiresClause = getDerived().TransformExpr(TRC);
- // Create the local class that will describe the lambda.
- // FIXME: KnownDependent below is wrong when substituting inside a templated
- // context that isn't a DeclContext (such as a variable template).
- CXXRecordDecl *OldClass = E->getLambdaClass();
- CXXRecordDecl *Class
- = getSema().createLambdaClosureType(E->getIntroducerRange(),
- NewCallOpTSI,
- /*KnownDependent=*/false,
- E->getCaptureDefault());
- getDerived().transformedLocalDecl(OldClass, {Class});
- Optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling;
- if (getDerived().ReplacingOriginal())
- Mangling = std::make_tuple(OldClass->hasKnownLambdaInternalLinkage(),
- OldClass->getLambdaManglingNumber(),
- OldClass->getDeviceLambdaManglingNumber(),
- OldClass->getLambdaContextDecl());
- // Build the call operator.
- CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
- Class, E->getIntroducerRange(), NewCallOpTSI,
- E->getCallOperator()->getEndLoc(),
- NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
- E->getCallOperator()->getConstexprKind(),
- NewTrailingRequiresClause.get());
- LSI->CallOperator = NewCallOperator;
- getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
- getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
- // Number the lambda for linkage purposes if necessary.
- getSema().handleLambdaNumbering(Class, NewCallOperator, Mangling);
- // Introduce the context of the call operator.
- Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
- /*NewThisContext*/false);
- // Enter the scope of the lambda.
- getSema().buildLambdaScope(LSI, NewCallOperator,
- E->getIntroducerRange(),
- E->getCaptureDefault(),
- E->getCaptureDefaultLoc(),
- E->hasExplicitParameters(),
- E->hasExplicitResultType(),
- E->isMutable());
- bool Invalid = false;
- // Transform captures.
- for (LambdaExpr::capture_iterator C = E->capture_begin(),
- CEnd = E->capture_end();
- C != CEnd; ++C) {
- // When we hit the first implicit capture, tell Sema that we've finished
- // the list of explicit captures.
- if (C->isImplicit())
- break;
- // Capturing 'this' is trivial.
- if (C->capturesThis()) {
- getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
- /*BuildAndDiagnose*/ true, nullptr,
- C->getCaptureKind() == LCK_StarThis);
- continue;
- }
- // Captured expression will be recaptured during captured variables
- // rebuilding.
- if (C->capturesVLAType())
- continue;
- // Rebuild init-captures, including the implied field declaration.
- if (E->isInitCapture(C)) {
- TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
- VarDecl *OldVD = C->getCapturedVar();
- llvm::SmallVector<Decl*, 4> NewVDs;
- for (InitCaptureInfoTy &Info : NewC.Expansions) {
- ExprResult Init = Info.first;
- QualType InitQualType = Info.second;
- if (Init.isInvalid() || InitQualType.isNull()) {
- Invalid = true;
- break;
- }
- VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
- OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
- OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get());
- if (!NewVD) {
- Invalid = true;
- break;
- }
- NewVDs.push_back(NewVD);
- getSema().addInitCapture(LSI, NewVD);
- }
- if (Invalid)
- break;
- getDerived().transformedLocalDecl(OldVD, NewVDs);
- continue;
- }
- assert(C->capturesVariable() && "unexpected kind of lambda capture");
- // Determine the capture kind for Sema.
- Sema::TryCaptureKind Kind
- = C->isImplicit()? Sema::TryCapture_Implicit
- : C->getCaptureKind() == LCK_ByCopy
- ? Sema::TryCapture_ExplicitByVal
- : Sema::TryCapture_ExplicitByRef;
- SourceLocation EllipsisLoc;
- if (C->isPackExpansion()) {
- UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
- bool ShouldExpand = false;
- bool RetainExpansion = false;
- Optional<unsigned> NumExpansions;
- if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
- C->getLocation(),
- Unexpanded,
- ShouldExpand, RetainExpansion,
- NumExpansions)) {
- Invalid = true;
- continue;
- }
- if (ShouldExpand) {
- // The transform has determined that we should perform an expansion;
- // transform and capture each of the arguments.
- // expansion of the pattern. Do so.
- VarDecl *Pack = C->getCapturedVar();
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
- VarDecl *CapturedVar
- = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
- Pack));
- if (!CapturedVar) {
- Invalid = true;
- continue;
- }
- // Capture the transformed variable.
- getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
- }
- // FIXME: Retain a pack expansion if RetainExpansion is true.
- continue;
- }
- EllipsisLoc = C->getEllipsisLoc();
- }
- // Transform the captured variable.
- VarDecl *CapturedVar
- = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
- C->getCapturedVar()));
- if (!CapturedVar || CapturedVar->isInvalidDecl()) {
- Invalid = true;
- continue;
- }
- // Capture the transformed variable.
- getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
- EllipsisLoc);
- }
- getSema().finishLambdaExplicitCaptures(LSI);
- // FIXME: Sema's lambda-building mechanism expects us to push an expression
- // evaluation context even if we're not transforming the function body.
- getSema().PushExpressionEvaluationContext(
- Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
- // Instantiate the body of the lambda expression.
- StmtResult Body =
- Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
- // ActOnLambda* will pop the function scope for us.
- FuncScopeCleanup.disable();
- if (Body.isInvalid()) {
- SavedContext.pop();
- getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
- /*IsInstantiation=*/true);
- return ExprError();
- }
- // Copy the LSI before ActOnFinishFunctionBody removes it.
- // FIXME: This is dumb. Store the lambda information somewhere that outlives
- // the call operator.
- auto LSICopy = *LSI;
- getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
- /*IsInstantiation*/ true);
- SavedContext.pop();
- return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
- &LSICopy);
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) {
- return TransformStmt(S);
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) {
- // Transform captures.
- for (LambdaExpr::capture_iterator C = E->capture_begin(),
- CEnd = E->capture_end();
- C != CEnd; ++C) {
- // When we hit the first implicit capture, tell Sema that we've finished
- // the list of explicit captures.
- if (!C->isImplicit())
- continue;
- // Capturing 'this' is trivial.
- if (C->capturesThis()) {
- getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
- /*BuildAndDiagnose*/ true, nullptr,
- C->getCaptureKind() == LCK_StarThis);
- continue;
- }
- // Captured expression will be recaptured during captured variables
- // rebuilding.
- if (C->capturesVLAType())
- continue;
- assert(C->capturesVariable() && "unexpected kind of lambda capture");
- assert(!E->isInitCapture(C) && "implicit init-capture?");
- // Transform the captured variable.
- VarDecl *CapturedVar = cast_or_null<VarDecl>(
- getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
- if (!CapturedVar || CapturedVar->isInvalidDecl())
- return StmtError();
- // Capture the transformed variable.
- getSema().tryCaptureVariable(CapturedVar, C->getLocation());
- }
- return S;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
- CXXUnresolvedConstructExpr *E) {
- TypeSourceInfo *T =
- getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
- if (!T)
- return ExprError();
- bool ArgumentChanged = false;
- SmallVector<Expr*, 8> Args;
- Args.reserve(E->getNumArgs());
- {
- EnterExpressionEvaluationContext Context(
- getSema(), EnterExpressionEvaluationContext::InitList,
- E->isListInitialization());
- if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
- &ArgumentChanged))
- return ExprError();
- }
- if (!getDerived().AlwaysRebuild() &&
- T == E->getTypeSourceInfo() &&
- !ArgumentChanged)
- return E;
- // FIXME: we're faking the locations of the commas
- return getDerived().RebuildCXXUnresolvedConstructExpr(
- T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
- CXXDependentScopeMemberExpr *E) {
- // Transform the base of the expression.
- ExprResult Base((Expr*) nullptr);
- Expr *OldBase;
- QualType BaseType;
- QualType ObjectType;
- if (!E->isImplicitAccess()) {
- OldBase = E->getBase();
- Base = getDerived().TransformExpr(OldBase);
- if (Base.isInvalid())
- return ExprError();
- // Start the member reference and compute the object's type.
- ParsedType ObjectTy;
- bool MayBePseudoDestructor = false;
- Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
- E->getOperatorLoc(),
- E->isArrow()? tok::arrow : tok::period,
- ObjectTy,
- MayBePseudoDestructor);
- if (Base.isInvalid())
- return ExprError();
- ObjectType = ObjectTy.get();
- BaseType = ((Expr*) Base.get())->getType();
- } else {
- OldBase = nullptr;
- BaseType = getDerived().TransformType(E->getBaseType());
- ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
- }
- // Transform the first part of the nested-name-specifier that qualifies
- // the member name.
- NamedDecl *FirstQualifierInScope
- = getDerived().TransformFirstQualifierInScope(
- E->getFirstQualifierFoundInScope(),
- E->getQualifierLoc().getBeginLoc());
- NestedNameSpecifierLoc QualifierLoc;
- if (E->getQualifier()) {
- QualifierLoc
- = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
- ObjectType,
- FirstQualifierInScope);
- if (!QualifierLoc)
- return ExprError();
- }
- SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
- // TODO: If this is a conversion-function-id, verify that the
- // destination type name (if present) resolves the same way after
- // instantiation as it did in the local scope.
- DeclarationNameInfo NameInfo
- = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
- if (!NameInfo.getName())
- return ExprError();
- if (!E->hasExplicitTemplateArgs()) {
- // This is a reference to a member without an explicitly-specified
- // template argument list. Optimize for this common case.
- if (!getDerived().AlwaysRebuild() &&
- Base.get() == OldBase &&
- BaseType == E->getBaseType() &&
- QualifierLoc == E->getQualifierLoc() &&
- NameInfo.getName() == E->getMember() &&
- FirstQualifierInScope == E->getFirstQualifierFoundInScope())
- return E;
- return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
- BaseType,
- E->isArrow(),
- E->getOperatorLoc(),
- QualifierLoc,
- TemplateKWLoc,
- FirstQualifierInScope,
- NameInfo,
- /*TemplateArgs*/nullptr);
- }
- TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
- if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
- E->getNumTemplateArgs(),
- TransArgs))
- return ExprError();
- return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
- BaseType,
- E->isArrow(),
- E->getOperatorLoc(),
- QualifierLoc,
- TemplateKWLoc,
- FirstQualifierInScope,
- NameInfo,
- &TransArgs);
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
- UnresolvedMemberExpr *Old) {
- // Transform the base of the expression.
- ExprResult Base((Expr *)nullptr);
- QualType BaseType;
- if (!Old->isImplicitAccess()) {
- Base = getDerived().TransformExpr(Old->getBase());
- if (Base.isInvalid())
- return ExprError();
- Base =
- getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
- if (Base.isInvalid())
- return ExprError();
- BaseType = Base.get()->getType();
- } else {
- BaseType = getDerived().TransformType(Old->getBaseType());
- }
- NestedNameSpecifierLoc QualifierLoc;
- if (Old->getQualifierLoc()) {
- QualifierLoc =
- getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
- if (!QualifierLoc)
- return ExprError();
- }
- SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
- LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
- // Transform the declaration set.
- if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
- return ExprError();
- // Determine the naming class.
- if (Old->getNamingClass()) {
- CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
- getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
- if (!NamingClass)
- return ExprError();
- R.setNamingClass(NamingClass);
- }
- TemplateArgumentListInfo TransArgs;
- if (Old->hasExplicitTemplateArgs()) {
- TransArgs.setLAngleLoc(Old->getLAngleLoc());
- TransArgs.setRAngleLoc(Old->getRAngleLoc());
- if (getDerived().TransformTemplateArguments(
- Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
- return ExprError();
- }
- // FIXME: to do this check properly, we will need to preserve the
- // first-qualifier-in-scope here, just in case we had a dependent
- // base (and therefore couldn't do the check) and a
- // nested-name-qualifier (and therefore could do the lookup).
- NamedDecl *FirstQualifierInScope = nullptr;
- return getDerived().RebuildUnresolvedMemberExpr(
- Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
- TemplateKWLoc, FirstQualifierInScope, R,
- (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
- EnterExpressionEvaluationContext Unevaluated(
- SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
- ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
- return E;
- return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
- ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
- if (Pattern.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
- return E;
- return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
- E->getNumExpansions());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
- // If E is not value-dependent, then nothing will change when we transform it.
- // Note: This is an instantiation-centric view.
- if (!E->isValueDependent())
- return E;
- EnterExpressionEvaluationContext Unevaluated(
- getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
- ArrayRef<TemplateArgument> PackArgs;
- TemplateArgument ArgStorage;
- // Find the argument list to transform.
- if (E->isPartiallySubstituted()) {
- PackArgs = E->getPartialArguments();
- } else if (E->isValueDependent()) {
- UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
- bool ShouldExpand = false;
- bool RetainExpansion = false;
- Optional<unsigned> NumExpansions;
- if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
- Unexpanded,
- ShouldExpand, RetainExpansion,
- NumExpansions))
- return ExprError();
- // If we need to expand the pack, build a template argument from it and
- // expand that.
- if (ShouldExpand) {
- auto *Pack = E->getPack();
- if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
- ArgStorage = getSema().Context.getPackExpansionType(
- getSema().Context.getTypeDeclType(TTPD), None);
- } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
- ArgStorage = TemplateArgument(TemplateName(TTPD), None);
- } else {
- auto *VD = cast<ValueDecl>(Pack);
- ExprResult DRE = getSema().BuildDeclRefExpr(
- VD, VD->getType().getNonLValueExprType(getSema().Context),
- VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
- E->getPackLoc());
- if (DRE.isInvalid())
- return ExprError();
- ArgStorage = new (getSema().Context) PackExpansionExpr(
- getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
- }
- PackArgs = ArgStorage;
- }
- }
- // If we're not expanding the pack, just transform the decl.
- if (!PackArgs.size()) {
- auto *Pack = cast_or_null<NamedDecl>(
- getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
- if (!Pack)
- return ExprError();
- return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
- E->getPackLoc(),
- E->getRParenLoc(), None, None);
- }
- // Try to compute the result without performing a partial substitution.
- Optional<unsigned> Result = 0;
- for (const TemplateArgument &Arg : PackArgs) {
- if (!Arg.isPackExpansion()) {
- Result = *Result + 1;
- continue;
- }
- TemplateArgumentLoc ArgLoc;
- InventTemplateArgumentLoc(Arg, ArgLoc);
- // Find the pattern of the pack expansion.
- SourceLocation Ellipsis;
- Optional<unsigned> OrigNumExpansions;
- TemplateArgumentLoc Pattern =
- getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
- OrigNumExpansions);
- // Substitute under the pack expansion. Do not expand the pack (yet).
- TemplateArgumentLoc OutPattern;
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
- /*Uneval*/ true))
- return true;
- // See if we can determine the number of arguments from the result.
- Optional<unsigned> NumExpansions =
- getSema().getFullyPackExpandedSize(OutPattern.getArgument());
- if (!NumExpansions) {
- // No: we must be in an alias template expansion, and we're going to need
- // to actually expand the packs.
- Result = None;
- break;
- }
- Result = *Result + *NumExpansions;
- }
- // Common case: we could determine the number of expansions without
- // substituting.
- if (Result)
- return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
- E->getPackLoc(),
- E->getRParenLoc(), *Result, None);
- TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
- E->getPackLoc());
- {
- TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
- typedef TemplateArgumentLocInventIterator<
- Derived, const TemplateArgument*> PackLocIterator;
- if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
- PackLocIterator(*this, PackArgs.end()),
- TransformedPackArgs, /*Uneval*/true))
- return ExprError();
- }
- // Check whether we managed to fully-expand the pack.
- // FIXME: Is it possible for us to do so and not hit the early exit path?
- SmallVector<TemplateArgument, 8> Args;
- bool PartialSubstitution = false;
- for (auto &Loc : TransformedPackArgs.arguments()) {
- Args.push_back(Loc.getArgument());
- if (Loc.getArgument().isPackExpansion())
- PartialSubstitution = true;
- }
- if (PartialSubstitution)
- return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
- E->getPackLoc(),
- E->getRParenLoc(), None, Args);
- return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
- E->getPackLoc(), E->getRParenLoc(),
- Args.size(), None);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
- SubstNonTypeTemplateParmPackExpr *E) {
- // Default behavior is to do nothing with this transformation.
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
- SubstNonTypeTemplateParmExpr *E) {
- // Default behavior is to do nothing with this transformation.
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
- // Default behavior is to do nothing with this transformation.
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
- MaterializeTemporaryExpr *E) {
- return getDerived().TransformExpr(E->getSubExpr());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
- UnresolvedLookupExpr *Callee = nullptr;
- if (Expr *OldCallee = E->getCallee()) {
- ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
- if (CalleeResult.isInvalid())
- return ExprError();
- Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
- }
- Expr *Pattern = E->getPattern();
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
- assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
- // Determine whether the set of unexpanded parameter packs can and should
- // be expanded.
- bool Expand = true;
- bool RetainExpansion = false;
- Optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
- NumExpansions = OrigNumExpansions;
- if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
- Pattern->getSourceRange(),
- Unexpanded,
- Expand, RetainExpansion,
- NumExpansions))
- return true;
- if (!Expand) {
- // Do not expand any packs here, just transform and rebuild a fold
- // expression.
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- ExprResult LHS =
- E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
- if (LHS.isInvalid())
- return true;
- ExprResult RHS =
- E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
- if (RHS.isInvalid())
- return true;
- if (!getDerived().AlwaysRebuild() &&
- LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
- return E;
- return getDerived().RebuildCXXFoldExpr(
- Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
- E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
- }
- // Formally a fold expression expands to nested parenthesized expressions.
- // Enforce this limit to avoid creating trees so deep we can't safely traverse
- // them.
- if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) {
- SemaRef.Diag(E->getEllipsisLoc(),
- clang::diag::err_fold_expression_limit_exceeded)
- << *NumExpansions << SemaRef.getLangOpts().BracketDepth
- << E->getSourceRange();
- SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
- return ExprError();
- }
- // The transform has determined that we should perform an elementwise
- // expansion of the pattern. Do so.
- ExprResult Result = getDerived().TransformExpr(E->getInit());
- if (Result.isInvalid())
- return true;
- bool LeftFold = E->isLeftFold();
- // If we're retaining an expansion for a right fold, it is the innermost
- // component and takes the init (if any).
- if (!LeftFold && RetainExpansion) {
- ForgetPartiallySubstitutedPackRAII Forget(getDerived());
- ExprResult Out = getDerived().TransformExpr(Pattern);
- if (Out.isInvalid())
- return true;
- Result = getDerived().RebuildCXXFoldExpr(
- Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
- E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
- if (Result.isInvalid())
- return true;
- }
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
- getSema(), LeftFold ? I : *NumExpansions - I - 1);
- ExprResult Out = getDerived().TransformExpr(Pattern);
- if (Out.isInvalid())
- return true;
- if (Out.get()->containsUnexpandedParameterPack()) {
- // We still have a pack; retain a pack expansion for this slice.
- Result = getDerived().RebuildCXXFoldExpr(
- Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
- E->getOperator(), E->getEllipsisLoc(),
- LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
- OrigNumExpansions);
- } else if (Result.isUsable()) {
- // We've got down to a single element; build a binary operator.
- Expr *LHS = LeftFold ? Result.get() : Out.get();
- Expr *RHS = LeftFold ? Out.get() : Result.get();
- if (Callee)
- Result = getDerived().RebuildCXXOperatorCallExpr(
- BinaryOperator::getOverloadedOperator(E->getOperator()),
- E->getEllipsisLoc(), Callee, LHS, RHS);
- else
- Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
- E->getOperator(), LHS, RHS);
- } else
- Result = Out;
- if (Result.isInvalid())
- return true;
- }
- // If we're retaining an expansion for a left fold, it is the outermost
- // component and takes the complete expansion so far as its init (if any).
- if (LeftFold && RetainExpansion) {
- ForgetPartiallySubstitutedPackRAII Forget(getDerived());
- ExprResult Out = getDerived().TransformExpr(Pattern);
- if (Out.isInvalid())
- return true;
- Result = getDerived().RebuildCXXFoldExpr(
- Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
- E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
- if (Result.isInvalid())
- return true;
- }
- // If we had no init and an empty pack, and we're not retaining an expansion,
- // then produce a fallback value or error.
- if (Result.isUnset())
- return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
- E->getOperator());
- return Result;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
- CXXStdInitializerListExpr *E) {
- return getDerived().TransformExpr(E->getSubExpr());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
- return SemaRef.MaybeBindToTemporary(E);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
- ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
- if (SubExpr.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- SubExpr.get() == E->getSubExpr())
- return E;
- return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
- // Transform each of the elements.
- SmallVector<Expr *, 8> Elements;
- bool ArgChanged = false;
- if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
- /*IsCall=*/false, Elements, &ArgChanged))
- return ExprError();
- if (!getDerived().AlwaysRebuild() && !ArgChanged)
- return SemaRef.MaybeBindToTemporary(E);
- return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
- Elements.data(),
- Elements.size());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCDictionaryLiteral(
- ObjCDictionaryLiteral *E) {
- // Transform each of the elements.
- SmallVector<ObjCDictionaryElement, 8> Elements;
- bool ArgChanged = false;
- for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
- ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
- if (OrigElement.isPackExpansion()) {
- // This key/value element is a pack expansion.
- SmallVector<UnexpandedParameterPack, 2> Unexpanded;
- getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
- getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
- assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
- // Determine whether the set of unexpanded parameter packs can
- // and should be expanded.
- bool Expand = true;
- bool RetainExpansion = false;
- Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
- Optional<unsigned> NumExpansions = OrigNumExpansions;
- SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
- OrigElement.Value->getEndLoc());
- if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
- PatternRange, Unexpanded, Expand,
- RetainExpansion, NumExpansions))
- return ExprError();
- if (!Expand) {
- // The transform has determined that we should perform a simple
- // transformation on the pack expansion, producing another pack
- // expansion.
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
- ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
- if (Key.isInvalid())
- return ExprError();
- if (Key.get() != OrigElement.Key)
- ArgChanged = true;
- ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
- if (Value.isInvalid())
- return ExprError();
- if (Value.get() != OrigElement.Value)
- ArgChanged = true;
- ObjCDictionaryElement Expansion = {
- Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
- };
- Elements.push_back(Expansion);
- continue;
- }
- // Record right away that the argument was changed. This needs
- // to happen even if the array expands to nothing.
- ArgChanged = true;
- // The transform has determined that we should perform an elementwise
- // expansion of the pattern. Do so.
- for (unsigned I = 0; I != *NumExpansions; ++I) {
- Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
- ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
- if (Key.isInvalid())
- return ExprError();
- ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
- if (Value.isInvalid())
- return ExprError();
- ObjCDictionaryElement Element = {
- Key.get(), Value.get(), SourceLocation(), NumExpansions
- };
- // If any unexpanded parameter packs remain, we still have a
- // pack expansion.
- // FIXME: Can this really happen?
- if (Key.get()->containsUnexpandedParameterPack() ||
- Value.get()->containsUnexpandedParameterPack())
- Element.EllipsisLoc = OrigElement.EllipsisLoc;
- Elements.push_back(Element);
- }
- // FIXME: Retain a pack expansion if RetainExpansion is true.
- // We've finished with this pack expansion.
- continue;
- }
- // Transform and check key.
- ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
- if (Key.isInvalid())
- return ExprError();
- if (Key.get() != OrigElement.Key)
- ArgChanged = true;
- // Transform and check value.
- ExprResult Value
- = getDerived().TransformExpr(OrigElement.Value);
- if (Value.isInvalid())
- return ExprError();
- if (Value.get() != OrigElement.Value)
- ArgChanged = true;
- ObjCDictionaryElement Element = {
- Key.get(), Value.get(), SourceLocation(), None
- };
- Elements.push_back(Element);
- }
- if (!getDerived().AlwaysRebuild() && !ArgChanged)
- return SemaRef.MaybeBindToTemporary(E);
- return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
- Elements);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
- TypeSourceInfo *EncodedTypeInfo
- = getDerived().TransformType(E->getEncodedTypeSourceInfo());
- if (!EncodedTypeInfo)
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- EncodedTypeInfo == E->getEncodedTypeSourceInfo())
- return E;
- return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
- EncodedTypeInfo,
- E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult TreeTransform<Derived>::
- TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
- // This is a kind of implicit conversion, and it needs to get dropped
- // and recomputed for the same general reasons that ImplicitCastExprs
- // do, as well a more specific one: this expression is only valid when
- // it appears *immediately* as an argument expression.
- return getDerived().TransformExpr(E->getSubExpr());
- }
- template<typename Derived>
- ExprResult TreeTransform<Derived>::
- TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
- TypeSourceInfo *TSInfo
- = getDerived().TransformType(E->getTypeInfoAsWritten());
- if (!TSInfo)
- return ExprError();
- ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
- if (Result.isInvalid())
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- TSInfo == E->getTypeInfoAsWritten() &&
- Result.get() == E->getSubExpr())
- return E;
- return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
- E->getBridgeKeywordLoc(), TSInfo,
- Result.get());
- }
- template <typename Derived>
- ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
- ObjCAvailabilityCheckExpr *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
- // Transform arguments.
- bool ArgChanged = false;
- SmallVector<Expr*, 8> Args;
- Args.reserve(E->getNumArgs());
- if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
- &ArgChanged))
- return ExprError();
- if (E->getReceiverKind() == ObjCMessageExpr::Class) {
- // Class message: transform the receiver type.
- TypeSourceInfo *ReceiverTypeInfo
- = getDerived().TransformType(E->getClassReceiverTypeInfo());
- if (!ReceiverTypeInfo)
- return ExprError();
- // If nothing changed, just retain the existing message send.
- if (!getDerived().AlwaysRebuild() &&
- ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
- return SemaRef.MaybeBindToTemporary(E);
- // Build a new class message send.
- SmallVector<SourceLocation, 16> SelLocs;
- E->getSelectorLocs(SelLocs);
- return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
- E->getSelector(),
- SelLocs,
- E->getMethodDecl(),
- E->getLeftLoc(),
- Args,
- E->getRightLoc());
- }
- else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
- E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
- if (!E->getMethodDecl())
- return ExprError();
- // Build a new class message send to 'super'.
- SmallVector<SourceLocation, 16> SelLocs;
- E->getSelectorLocs(SelLocs);
- return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
- E->getSelector(),
- SelLocs,
- E->getReceiverType(),
- E->getMethodDecl(),
- E->getLeftLoc(),
- Args,
- E->getRightLoc());
- }
- // Instance message: transform the receiver
- assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
- "Only class and instance messages may be instantiated");
- ExprResult Receiver
- = getDerived().TransformExpr(E->getInstanceReceiver());
- if (Receiver.isInvalid())
- return ExprError();
- // If nothing changed, just retain the existing message send.
- if (!getDerived().AlwaysRebuild() &&
- Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
- return SemaRef.MaybeBindToTemporary(E);
- // Build a new instance message send.
- SmallVector<SourceLocation, 16> SelLocs;
- E->getSelectorLocs(SelLocs);
- return getDerived().RebuildObjCMessageExpr(Receiver.get(),
- E->getSelector(),
- SelLocs,
- E->getMethodDecl(),
- E->getLeftLoc(),
- Args,
- E->getRightLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
- return E;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
- // Transform the base expression.
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- // We don't need to transform the ivar; it will never change.
- // If nothing changed, just retain the existing expression.
- if (!getDerived().AlwaysRebuild() &&
- Base.get() == E->getBase())
- return E;
- return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
- E->getLocation(),
- E->isArrow(), E->isFreeIvar());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
- // 'super' and types never change. Property never changes. Just
- // retain the existing expression.
- if (!E->isObjectReceiver())
- return E;
- // Transform the base expression.
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- // We don't need to transform the property; it will never change.
- // If nothing changed, just retain the existing expression.
- if (!getDerived().AlwaysRebuild() &&
- Base.get() == E->getBase())
- return E;
- if (E->isExplicitProperty())
- return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
- E->getExplicitProperty(),
- E->getLocation());
- return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
- SemaRef.Context.PseudoObjectTy,
- E->getImplicitPropertyGetter(),
- E->getImplicitPropertySetter(),
- E->getLocation());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
- // Transform the base expression.
- ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
- if (Base.isInvalid())
- return ExprError();
- // Transform the key expression.
- ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
- if (Key.isInvalid())
- return ExprError();
- // If nothing changed, just retain the existing expression.
- if (!getDerived().AlwaysRebuild() &&
- Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
- return E;
- return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
- Base.get(), Key.get(),
- E->getAtIndexMethodDecl(),
- E->setAtIndexMethodDecl());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
- // Transform the base expression.
- ExprResult Base = getDerived().TransformExpr(E->getBase());
- if (Base.isInvalid())
- return ExprError();
- // If nothing changed, just retain the existing expression.
- if (!getDerived().AlwaysRebuild() &&
- Base.get() == E->getBase())
- return E;
- return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
- E->getOpLoc(),
- E->isArrow());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
- bool ArgumentChanged = false;
- SmallVector<Expr*, 8> SubExprs;
- SubExprs.reserve(E->getNumSubExprs());
- if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
- SubExprs, &ArgumentChanged))
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- !ArgumentChanged)
- return E;
- return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
- SubExprs,
- E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
- ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
- if (SrcExpr.isInvalid())
- return ExprError();
- TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
- if (!Type)
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- Type == E->getTypeSourceInfo() &&
- SrcExpr.get() == E->getSrcExpr())
- return E;
- return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
- SrcExpr.get(), Type,
- E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
- BlockDecl *oldBlock = E->getBlockDecl();
- SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
- BlockScopeInfo *blockScope = SemaRef.getCurBlock();
- blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
- blockScope->TheDecl->setBlockMissingReturnType(
- oldBlock->blockMissingReturnType());
- SmallVector<ParmVarDecl*, 4> params;
- SmallVector<QualType, 4> paramTypes;
- const FunctionProtoType *exprFunctionType = E->getFunctionType();
- // Parameter substitution.
- Sema::ExtParameterInfoBuilder extParamInfos;
- if (getDerived().TransformFunctionTypeParams(
- E->getCaretLocation(), oldBlock->parameters(), nullptr,
- exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms,
- extParamInfos)) {
- getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
- return ExprError();
- }
- QualType exprResultType =
- getDerived().TransformType(exprFunctionType->getReturnType());
- auto epi = exprFunctionType->getExtProtoInfo();
- epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
- QualType functionType =
- getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
- blockScope->FunctionType = functionType;
- // Set the parameters on the block decl.
- if (!params.empty())
- blockScope->TheDecl->setParams(params);
- if (!oldBlock->blockMissingReturnType()) {
- blockScope->HasImplicitReturnType = false;
- blockScope->ReturnType = exprResultType;
- }
- // Transform the body
- StmtResult body = getDerived().TransformStmt(E->getBody());
- if (body.isInvalid()) {
- getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
- return ExprError();
- }
- #ifndef NDEBUG
- // In builds with assertions, make sure that we captured everything we
- // captured before.
- if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
- for (const auto &I : oldBlock->captures()) {
- VarDecl *oldCapture = I.getVariable();
- // Ignore parameter packs.
- if (oldCapture->isParameterPack())
- continue;
- VarDecl *newCapture =
- cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
- oldCapture));
- assert(blockScope->CaptureMap.count(newCapture));
- }
- assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
- }
- #endif
- return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
- /*Scope=*/nullptr);
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
- ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
- if (SrcExpr.isInvalid())
- return ExprError();
- QualType Type = getDerived().TransformType(E->getType());
- return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
- E->getRParenLoc());
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
- bool ArgumentChanged = false;
- SmallVector<Expr*, 8> SubExprs;
- SubExprs.reserve(E->getNumSubExprs());
- if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
- SubExprs, &ArgumentChanged))
- return ExprError();
- if (!getDerived().AlwaysRebuild() &&
- !ArgumentChanged)
- return E;
- return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
- E->getOp(), E->getRParenLoc());
- }
- //===----------------------------------------------------------------------===//
- // Type reconstruction
- //===----------------------------------------------------------------------===//
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
- SourceLocation Star) {
- return SemaRef.BuildPointerType(PointeeType, Star,
- getDerived().getBaseEntity());
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
- SourceLocation Star) {
- return SemaRef.BuildBlockPointerType(PointeeType, Star,
- getDerived().getBaseEntity());
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
- bool WrittenAsLValue,
- SourceLocation Sigil) {
- return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
- Sigil, getDerived().getBaseEntity());
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
- QualType ClassType,
- SourceLocation Sigil) {
- return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
- getDerived().getBaseEntity());
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
- const ObjCTypeParamDecl *Decl,
- SourceLocation ProtocolLAngleLoc,
- ArrayRef<ObjCProtocolDecl *> Protocols,
- ArrayRef<SourceLocation> ProtocolLocs,
- SourceLocation ProtocolRAngleLoc) {
- return SemaRef.BuildObjCTypeParamType(Decl,
- ProtocolLAngleLoc, Protocols,
- ProtocolLocs, ProtocolRAngleLoc,
- /*FailOnError=*/true);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildObjCObjectType(
- QualType BaseType,
- SourceLocation Loc,
- SourceLocation TypeArgsLAngleLoc,
- ArrayRef<TypeSourceInfo *> TypeArgs,
- SourceLocation TypeArgsRAngleLoc,
- SourceLocation ProtocolLAngleLoc,
- ArrayRef<ObjCProtocolDecl *> Protocols,
- ArrayRef<SourceLocation> ProtocolLocs,
- SourceLocation ProtocolRAngleLoc) {
- return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
- TypeArgs, TypeArgsRAngleLoc,
- ProtocolLAngleLoc, Protocols, ProtocolLocs,
- ProtocolRAngleLoc,
- /*FailOnError=*/true);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
- QualType PointeeType,
- SourceLocation Star) {
- return SemaRef.Context.getObjCObjectPointerType(PointeeType);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- const llvm::APInt *Size,
- Expr *SizeExpr,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange) {
- if (SizeExpr || !Size)
- return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
- IndexTypeQuals, BracketsRange,
- getDerived().getBaseEntity());
- QualType Types[] = {
- SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
- SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
- SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
- };
- const unsigned NumTypes = llvm::array_lengthof(Types);
- QualType SizeType;
- for (unsigned I = 0; I != NumTypes; ++I)
- if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
- SizeType = Types[I];
- break;
- }
- // Note that we can return a VariableArrayType here in the case where
- // the element type was a dependent VariableArrayType.
- IntegerLiteral *ArraySize
- = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
- /*FIXME*/BracketsRange.getBegin());
- return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
- IndexTypeQuals, BracketsRange,
- getDerived().getBaseEntity());
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- const llvm::APInt &Size,
- Expr *SizeExpr,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange) {
- return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
- IndexTypeQuals, BracketsRange);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange) {
- return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
- IndexTypeQuals, BracketsRange);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- Expr *SizeExpr,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange) {
- return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
- SizeExpr,
- IndexTypeQuals, BracketsRange);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
- ArrayType::ArraySizeModifier SizeMod,
- Expr *SizeExpr,
- unsigned IndexTypeQuals,
- SourceRange BracketsRange) {
- return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
- SizeExpr,
- IndexTypeQuals, BracketsRange);
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
- QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
- return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
- AttributeLoc);
- }
- template <typename Derived>
- QualType
- TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
- unsigned NumElements,
- VectorType::VectorKind VecKind) {
- // FIXME: semantic checking!
- return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildDependentVectorType(
- QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
- VectorType::VectorKind VecKind) {
- return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
- unsigned NumElements,
- SourceLocation AttributeLoc) {
- llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
- NumElements, true);
- IntegerLiteral *VectorSize
- = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
- AttributeLoc);
- return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
- }
- template<typename Derived>
- QualType
- TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
- Expr *SizeExpr,
- SourceLocation AttributeLoc) {
- return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildConstantMatrixType(
- QualType ElementType, unsigned NumRows, unsigned NumColumns) {
- return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
- NumColumns);
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildDependentSizedMatrixType(
- QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
- SourceLocation AttributeLoc) {
- return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
- AttributeLoc);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildFunctionProtoType(
- QualType T,
- MutableArrayRef<QualType> ParamTypes,
- const FunctionProtoType::ExtProtoInfo &EPI) {
- return SemaRef.BuildFunctionType(T, ParamTypes,
- getDerived().getBaseLocation(),
- getDerived().getBaseEntity(),
- EPI);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
- return SemaRef.Context.getFunctionNoProtoType(T);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
- Decl *D) {
- assert(D && "no decl found");
- if (D->isInvalidDecl()) return QualType();
- // FIXME: Doesn't account for ObjCInterfaceDecl!
- if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
- // A valid resolved using typename pack expansion decl can have multiple
- // UsingDecls, but they must each have exactly one type, and it must be
- // the same type in every case. But we must have at least one expansion!
- if (UPD->expansions().empty()) {
- getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
- << UPD->isCXXClassMember() << UPD;
- return QualType();
- }
- // We might still have some unresolved types. Try to pick a resolved type
- // if we can. The final instantiation will check that the remaining
- // unresolved types instantiate to the type we pick.
- QualType FallbackT;
- QualType T;
- for (auto *E : UPD->expansions()) {
- QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
- if (ThisT.isNull())
- continue;
- else if (ThisT->getAs<UnresolvedUsingType>())
- FallbackT = ThisT;
- else if (T.isNull())
- T = ThisT;
- else
- assert(getSema().Context.hasSameType(ThisT, T) &&
- "mismatched resolved types in using pack expansion");
- }
- return T.isNull() ? FallbackT : T;
- } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
- assert(Using->hasTypename() &&
- "UnresolvedUsingTypenameDecl transformed to non-typename using");
- // A valid resolved using typename decl points to exactly one type decl.
- assert(++Using->shadow_begin() == Using->shadow_end());
- UsingShadowDecl *Shadow = *Using->shadow_begin();
- if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc))
- return QualType();
- return SemaRef.Context.getUsingType(
- Shadow, SemaRef.Context.getTypeDeclType(
- cast<TypeDecl>(Shadow->getTargetDecl())));
- } else {
- assert(isa<UnresolvedUsingTypenameDecl>(D) &&
- "UnresolvedUsingTypenameDecl transformed to non-using decl");
- return SemaRef.Context.getTypeDeclType(
- cast<UnresolvedUsingTypenameDecl>(D));
- }
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
- SourceLocation) {
- return SemaRef.BuildTypeofExprType(E);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
- return SemaRef.Context.getTypeOfType(Underlying);
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, SourceLocation) {
- return SemaRef.BuildDecltypeType(E);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
- UnaryTransformType::UTTKind UKind,
- SourceLocation Loc) {
- return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
- TemplateName Template,
- SourceLocation TemplateNameLoc,
- TemplateArgumentListInfo &TemplateArgs) {
- return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
- SourceLocation KWLoc) {
- return SemaRef.BuildAtomicType(ValueType, KWLoc);
- }
- template<typename Derived>
- QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
- SourceLocation KWLoc,
- bool isReadPipe) {
- return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
- : SemaRef.BuildWritePipeType(ValueType, KWLoc);
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildBitIntType(bool IsUnsigned,
- unsigned NumBits,
- SourceLocation Loc) {
- llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
- NumBits, true);
- IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
- SemaRef.Context.IntTy, Loc);
- return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
- }
- template <typename Derived>
- QualType TreeTransform<Derived>::RebuildDependentBitIntType(
- bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
- return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
- }
- template<typename Derived>
- TemplateName
- TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
- bool TemplateKW,
- TemplateDecl *Template) {
- return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
- Template);
- }
- template<typename Derived>
- TemplateName
- TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
- SourceLocation TemplateKWLoc,
- const IdentifierInfo &Name,
- SourceLocation NameLoc,
- QualType ObjectType,
- NamedDecl *FirstQualifierInScope,
- bool AllowInjectedClassName) {
- UnqualifiedId TemplateName;
- TemplateName.setIdentifier(&Name, NameLoc);
- Sema::TemplateTy Template;
- getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
- TemplateName, ParsedType::make(ObjectType),
- /*EnteringContext=*/false, Template,
- AllowInjectedClassName);
- return Template.get();
- }
- template<typename Derived>
- TemplateName
- TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
- SourceLocation TemplateKWLoc,
- OverloadedOperatorKind Operator,
- SourceLocation NameLoc,
- QualType ObjectType,
- bool AllowInjectedClassName) {
- UnqualifiedId Name;
- // FIXME: Bogus location information.
- SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
- Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
- Sema::TemplateTy Template;
- getSema().ActOnTemplateName(
- /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
- /*EnteringContext=*/false, Template, AllowInjectedClassName);
- return Template.get();
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
- SourceLocation OpLoc,
- Expr *OrigCallee,
- Expr *First,
- Expr *Second) {
- Expr *Callee = OrigCallee->IgnoreParenCasts();
- bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
- if (First->getObjectKind() == OK_ObjCProperty) {
- BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
- if (BinaryOperator::isAssignmentOp(Opc))
- return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
- First, Second);
- ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
- if (Result.isInvalid())
- return ExprError();
- First = Result.get();
- }
- if (Second && Second->getObjectKind() == OK_ObjCProperty) {
- ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
- if (Result.isInvalid())
- return ExprError();
- Second = Result.get();
- }
- // Determine whether this should be a builtin operation.
- if (Op == OO_Subscript) {
- if (!First->getType()->isOverloadableType() &&
- !Second->getType()->isOverloadableType())
- return getSema().CreateBuiltinArraySubscriptExpr(
- First, Callee->getBeginLoc(), Second, OpLoc);
- } else if (Op == OO_Arrow) {
- // -> is never a builtin operation.
- return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
- } else if (Second == nullptr || isPostIncDec) {
- if (!First->getType()->isOverloadableType() ||
- (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
- // The argument is not of overloadable type, or this is an expression
- // of the form &Class::member, so try to create a built-in unary
- // operation.
- UnaryOperatorKind Opc
- = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
- return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
- }
- } else {
- if (!First->getType()->isOverloadableType() &&
- !Second->getType()->isOverloadableType()) {
- // Neither of the arguments is an overloadable type, so try to
- // create a built-in binary operation.
- BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
- ExprResult Result
- = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
- if (Result.isInvalid())
- return ExprError();
- return Result;
- }
- }
- // Compute the transformed set of functions (and function templates) to be
- // used during overload resolution.
- UnresolvedSet<16> Functions;
- bool RequiresADL;
- if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
- Functions.append(ULE->decls_begin(), ULE->decls_end());
- // If the overload could not be resolved in the template definition
- // (because we had a dependent argument), ADL is performed as part of
- // template instantiation.
- RequiresADL = ULE->requiresADL();
- } else {
- // If we've resolved this to a particular non-member function, just call
- // that function. If we resolved it to a member function,
- // CreateOverloaded* will find that function for us.
- NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
- if (!isa<CXXMethodDecl>(ND))
- Functions.addDecl(ND);
- RequiresADL = false;
- }
- // Add any functions found via argument-dependent lookup.
- Expr *Args[2] = { First, Second };
- unsigned NumArgs = 1 + (Second != nullptr);
- // Create the overloaded operator invocation for unary operators.
- if (NumArgs == 1 || isPostIncDec) {
- UnaryOperatorKind Opc
- = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
- return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
- RequiresADL);
- }
- if (Op == OO_Subscript) {
- SourceLocation LBrace;
- SourceLocation RBrace;
- if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
- DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
- LBrace = NameLoc.getCXXOperatorNameBeginLoc();
- RBrace = NameLoc.getCXXOperatorNameEndLoc();
- } else {
- LBrace = Callee->getBeginLoc();
- RBrace = OpLoc;
- }
- return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
- First, Second);
- }
- // Create the overloaded operator invocation for binary operators.
- BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
- ExprResult Result = SemaRef.CreateOverloadedBinOp(
- OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
- if (Result.isInvalid())
- return ExprError();
- return Result;
- }
- template<typename Derived>
- ExprResult
- TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
- SourceLocation OperatorLoc,
- bool isArrow,
- CXXScopeSpec &SS,
- TypeSourceInfo *ScopeType,
- SourceLocation CCLoc,
- SourceLocation TildeLoc,
- PseudoDestructorTypeStorage Destroyed) {
- QualType BaseType = Base->getType();
- if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
- (!isArrow && !BaseType->getAs<RecordType>()) ||
- (isArrow && BaseType->getAs<PointerType>() &&
- !BaseType->castAs<PointerType>()->getPointeeType()
- ->template getAs<RecordType>())){
- // This pseudo-destructor expression is still a pseudo-destructor.
- return SemaRef.BuildPseudoDestructorExpr(
- Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
- CCLoc, TildeLoc, Destroyed);
- }
- TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
- DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
- SemaRef.Context.getCanonicalType(DestroyedType->getType())));
- DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
- NameInfo.setNamedTypeInfo(DestroyedType);
- // The scope type is now known to be a valid nested name specifier
- // component. Tack it on to the end of the nested name specifier.
- if (ScopeType) {
- if (!ScopeType->getType()->getAs<TagType>()) {
- getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
- diag::err_expected_class_or_namespace)
- << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
- return ExprError();
- }
- SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
- CCLoc);
- }
- SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
- return getSema().BuildMemberReferenceExpr(Base, BaseType,
- OperatorLoc, isArrow,
- SS, TemplateKWLoc,
- /*FIXME: FirstQualifier*/ nullptr,
- NameInfo,
- /*TemplateArgs*/ nullptr,
- /*S*/nullptr);
- }
- template<typename Derived>
- StmtResult
- TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
- SourceLocation Loc = S->getBeginLoc();
- CapturedDecl *CD = S->getCapturedDecl();
- unsigned NumParams = CD->getNumParams();
- unsigned ContextParamPos = CD->getContextParamPosition();
- SmallVector<Sema::CapturedParamNameType, 4> Params;
- for (unsigned I = 0; I < NumParams; ++I) {
- if (I != ContextParamPos) {
- Params.push_back(
- std::make_pair(
- CD->getParam(I)->getName(),
- getDerived().TransformType(CD->getParam(I)->getType())));
- } else {
- Params.push_back(std::make_pair(StringRef(), QualType()));
- }
- }
- getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
- S->getCapturedRegionKind(), Params);
- StmtResult Body;
- {
- Sema::CompoundScopeRAII CompoundScope(getSema());
- Body = getDerived().TransformStmt(S->getCapturedStmt());
- }
- if (Body.isInvalid()) {
- getSema().ActOnCapturedRegionError();
- return StmtError();
- }
- return getSema().ActOnCapturedRegionEnd(Body.get());
- }
- } // end namespace clang
- #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
|