TreeTransform.h 573 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875
  1. //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // This file implements a semantic tree transformation that takes a given
  9. // AST and rebuilds it, possibly transforming some nodes in the process.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
  13. #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
  14. #include "CoroutineStmtBuilder.h"
  15. #include "TypeLocBuilder.h"
  16. #include "clang/AST/Decl.h"
  17. #include "clang/AST/DeclObjC.h"
  18. #include "clang/AST/DeclTemplate.h"
  19. #include "clang/AST/Expr.h"
  20. #include "clang/AST/ExprConcepts.h"
  21. #include "clang/AST/ExprCXX.h"
  22. #include "clang/AST/ExprObjC.h"
  23. #include "clang/AST/ExprOpenMP.h"
  24. #include "clang/AST/OpenMPClause.h"
  25. #include "clang/AST/Stmt.h"
  26. #include "clang/AST/StmtCXX.h"
  27. #include "clang/AST/StmtObjC.h"
  28. #include "clang/AST/StmtOpenMP.h"
  29. #include "clang/Basic/DiagnosticParse.h"
  30. #include "clang/Basic/OpenMPKinds.h"
  31. #include "clang/Sema/Designator.h"
  32. #include "clang/Sema/Lookup.h"
  33. #include "clang/Sema/Ownership.h"
  34. #include "clang/Sema/ParsedTemplate.h"
  35. #include "clang/Sema/ScopeInfo.h"
  36. #include "clang/Sema/SemaDiagnostic.h"
  37. #include "clang/Sema/SemaInternal.h"
  38. #include "llvm/ADT/ArrayRef.h"
  39. #include "llvm/Support/ErrorHandling.h"
  40. #include <algorithm>
  41. using namespace llvm::omp;
  42. namespace clang {
  43. using namespace sema;
  44. /// A semantic tree transformation that allows one to transform one
  45. /// abstract syntax tree into another.
  46. ///
  47. /// A new tree transformation is defined by creating a new subclass \c X of
  48. /// \c TreeTransform<X> and then overriding certain operations to provide
  49. /// behavior specific to that transformation. For example, template
  50. /// instantiation is implemented as a tree transformation where the
  51. /// transformation of TemplateTypeParmType nodes involves substituting the
  52. /// template arguments for their corresponding template parameters; a similar
  53. /// transformation is performed for non-type template parameters and
  54. /// template template parameters.
  55. ///
  56. /// This tree-transformation template uses static polymorphism to allow
  57. /// subclasses to customize any of its operations. Thus, a subclass can
  58. /// override any of the transformation or rebuild operators by providing an
  59. /// operation with the same signature as the default implementation. The
  60. /// overriding function should not be virtual.
  61. ///
  62. /// Semantic tree transformations are split into two stages, either of which
  63. /// can be replaced by a subclass. The "transform" step transforms an AST node
  64. /// or the parts of an AST node using the various transformation functions,
  65. /// then passes the pieces on to the "rebuild" step, which constructs a new AST
  66. /// node of the appropriate kind from the pieces. The default transformation
  67. /// routines recursively transform the operands to composite AST nodes (e.g.,
  68. /// the pointee type of a PointerType node) and, if any of those operand nodes
  69. /// were changed by the transformation, invokes the rebuild operation to create
  70. /// a new AST node.
  71. ///
  72. /// Subclasses can customize the transformation at various levels. The
  73. /// most coarse-grained transformations involve replacing TransformType(),
  74. /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
  75. /// TransformTemplateName(), or TransformTemplateArgument() with entirely
  76. /// new implementations.
  77. ///
  78. /// For more fine-grained transformations, subclasses can replace any of the
  79. /// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
  80. /// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
  81. /// replacing TransformTemplateTypeParmType() allows template instantiation
  82. /// to substitute template arguments for their corresponding template
  83. /// parameters. Additionally, subclasses can override the \c RebuildXXX
  84. /// functions to control how AST nodes are rebuilt when their operands change.
  85. /// By default, \c TreeTransform will invoke semantic analysis to rebuild
  86. /// AST nodes. However, certain other tree transformations (e.g, cloning) may
  87. /// be able to use more efficient rebuild steps.
  88. ///
  89. /// There are a handful of other functions that can be overridden, allowing one
  90. /// to avoid traversing nodes that don't need any transformation
  91. /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
  92. /// operands have not changed (\c AlwaysRebuild()), and customize the
  93. /// default locations and entity names used for type-checking
  94. /// (\c getBaseLocation(), \c getBaseEntity()).
  95. template<typename Derived>
  96. class TreeTransform {
  97. /// Private RAII object that helps us forget and then re-remember
  98. /// the template argument corresponding to a partially-substituted parameter
  99. /// pack.
  100. class ForgetPartiallySubstitutedPackRAII {
  101. Derived &Self;
  102. TemplateArgument Old;
  103. public:
  104. ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
  105. Old = Self.ForgetPartiallySubstitutedPack();
  106. }
  107. ~ForgetPartiallySubstitutedPackRAII() {
  108. Self.RememberPartiallySubstitutedPack(Old);
  109. }
  110. };
  111. protected:
  112. Sema &SemaRef;
  113. /// The set of local declarations that have been transformed, for
  114. /// cases where we are forced to build new declarations within the transformer
  115. /// rather than in the subclass (e.g., lambda closure types).
  116. llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
  117. public:
  118. /// Initializes a new tree transformer.
  119. TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
  120. /// Retrieves a reference to the derived class.
  121. Derived &getDerived() { return static_cast<Derived&>(*this); }
  122. /// Retrieves a reference to the derived class.
  123. const Derived &getDerived() const {
  124. return static_cast<const Derived&>(*this);
  125. }
  126. static inline ExprResult Owned(Expr *E) { return E; }
  127. static inline StmtResult Owned(Stmt *S) { return S; }
  128. /// Retrieves a reference to the semantic analysis object used for
  129. /// this tree transform.
  130. Sema &getSema() const { return SemaRef; }
  131. /// Whether the transformation should always rebuild AST nodes, even
  132. /// if none of the children have changed.
  133. ///
  134. /// Subclasses may override this function to specify when the transformation
  135. /// should rebuild all AST nodes.
  136. ///
  137. /// We must always rebuild all AST nodes when performing variadic template
  138. /// pack expansion, in order to avoid violating the AST invariant that each
  139. /// statement node appears at most once in its containing declaration.
  140. bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
  141. /// Whether the transformation is forming an expression or statement that
  142. /// replaces the original. In this case, we'll reuse mangling numbers from
  143. /// existing lambdas.
  144. bool ReplacingOriginal() { return false; }
  145. /// Wether CXXConstructExpr can be skipped when they are implicit.
  146. /// They will be reconstructed when used if needed.
  147. /// This is useful when the user that cause rebuilding of the
  148. /// CXXConstructExpr is outside of the expression at which the TreeTransform
  149. /// started.
  150. bool AllowSkippingCXXConstructExpr() { return true; }
  151. /// Returns the location of the entity being transformed, if that
  152. /// information was not available elsewhere in the AST.
  153. ///
  154. /// By default, returns no source-location information. Subclasses can
  155. /// provide an alternative implementation that provides better location
  156. /// information.
  157. SourceLocation getBaseLocation() { return SourceLocation(); }
  158. /// Returns the name of the entity being transformed, if that
  159. /// information was not available elsewhere in the AST.
  160. ///
  161. /// By default, returns an empty name. Subclasses can provide an alternative
  162. /// implementation with a more precise name.
  163. DeclarationName getBaseEntity() { return DeclarationName(); }
  164. /// Sets the "base" location and entity when that
  165. /// information is known based on another transformation.
  166. ///
  167. /// By default, the source location and entity are ignored. Subclasses can
  168. /// override this function to provide a customized implementation.
  169. void setBase(SourceLocation Loc, DeclarationName Entity) { }
  170. /// RAII object that temporarily sets the base location and entity
  171. /// used for reporting diagnostics in types.
  172. class TemporaryBase {
  173. TreeTransform &Self;
  174. SourceLocation OldLocation;
  175. DeclarationName OldEntity;
  176. public:
  177. TemporaryBase(TreeTransform &Self, SourceLocation Location,
  178. DeclarationName Entity) : Self(Self) {
  179. OldLocation = Self.getDerived().getBaseLocation();
  180. OldEntity = Self.getDerived().getBaseEntity();
  181. if (Location.isValid())
  182. Self.getDerived().setBase(Location, Entity);
  183. }
  184. ~TemporaryBase() {
  185. Self.getDerived().setBase(OldLocation, OldEntity);
  186. }
  187. };
  188. /// Determine whether the given type \p T has already been
  189. /// transformed.
  190. ///
  191. /// Subclasses can provide an alternative implementation of this routine
  192. /// to short-circuit evaluation when it is known that a given type will
  193. /// not change. For example, template instantiation need not traverse
  194. /// non-dependent types.
  195. bool AlreadyTransformed(QualType T) {
  196. return T.isNull();
  197. }
  198. /// Transform a template parameter depth level.
  199. ///
  200. /// During a transformation that transforms template parameters, this maps
  201. /// an old template parameter depth to a new depth.
  202. unsigned TransformTemplateDepth(unsigned Depth) {
  203. return Depth;
  204. }
  205. /// Determine whether the given call argument should be dropped, e.g.,
  206. /// because it is a default argument.
  207. ///
  208. /// Subclasses can provide an alternative implementation of this routine to
  209. /// determine which kinds of call arguments get dropped. By default,
  210. /// CXXDefaultArgument nodes are dropped (prior to transformation).
  211. bool DropCallArgument(Expr *E) {
  212. return E->isDefaultArgument();
  213. }
  214. /// Determine whether we should expand a pack expansion with the
  215. /// given set of parameter packs into separate arguments by repeatedly
  216. /// transforming the pattern.
  217. ///
  218. /// By default, the transformer never tries to expand pack expansions.
  219. /// Subclasses can override this routine to provide different behavior.
  220. ///
  221. /// \param EllipsisLoc The location of the ellipsis that identifies the
  222. /// pack expansion.
  223. ///
  224. /// \param PatternRange The source range that covers the entire pattern of
  225. /// the pack expansion.
  226. ///
  227. /// \param Unexpanded The set of unexpanded parameter packs within the
  228. /// pattern.
  229. ///
  230. /// \param ShouldExpand Will be set to \c true if the transformer should
  231. /// expand the corresponding pack expansions into separate arguments. When
  232. /// set, \c NumExpansions must also be set.
  233. ///
  234. /// \param RetainExpansion Whether the caller should add an unexpanded
  235. /// pack expansion after all of the expanded arguments. This is used
  236. /// when extending explicitly-specified template argument packs per
  237. /// C++0x [temp.arg.explicit]p9.
  238. ///
  239. /// \param NumExpansions The number of separate arguments that will be in
  240. /// the expanded form of the corresponding pack expansion. This is both an
  241. /// input and an output parameter, which can be set by the caller if the
  242. /// number of expansions is known a priori (e.g., due to a prior substitution)
  243. /// and will be set by the callee when the number of expansions is known.
  244. /// The callee must set this value when \c ShouldExpand is \c true; it may
  245. /// set this value in other cases.
  246. ///
  247. /// \returns true if an error occurred (e.g., because the parameter packs
  248. /// are to be instantiated with arguments of different lengths), false
  249. /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
  250. /// must be set.
  251. bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
  252. SourceRange PatternRange,
  253. ArrayRef<UnexpandedParameterPack> Unexpanded,
  254. bool &ShouldExpand,
  255. bool &RetainExpansion,
  256. Optional<unsigned> &NumExpansions) {
  257. ShouldExpand = false;
  258. return false;
  259. }
  260. /// "Forget" about the partially-substituted pack template argument,
  261. /// when performing an instantiation that must preserve the parameter pack
  262. /// use.
  263. ///
  264. /// This routine is meant to be overridden by the template instantiator.
  265. TemplateArgument ForgetPartiallySubstitutedPack() {
  266. return TemplateArgument();
  267. }
  268. /// "Remember" the partially-substituted pack template argument
  269. /// after performing an instantiation that must preserve the parameter pack
  270. /// use.
  271. ///
  272. /// This routine is meant to be overridden by the template instantiator.
  273. void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
  274. /// Note to the derived class when a function parameter pack is
  275. /// being expanded.
  276. void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
  277. /// Transforms the given type into another type.
  278. ///
  279. /// By default, this routine transforms a type by creating a
  280. /// TypeSourceInfo for it and delegating to the appropriate
  281. /// function. This is expensive, but we don't mind, because
  282. /// this method is deprecated anyway; all users should be
  283. /// switched to storing TypeSourceInfos.
  284. ///
  285. /// \returns the transformed type.
  286. QualType TransformType(QualType T);
  287. /// Transforms the given type-with-location into a new
  288. /// type-with-location.
  289. ///
  290. /// By default, this routine transforms a type by delegating to the
  291. /// appropriate TransformXXXType to build a new type. Subclasses
  292. /// may override this function (to take over all type
  293. /// transformations) or some set of the TransformXXXType functions
  294. /// to alter the transformation.
  295. TypeSourceInfo *TransformType(TypeSourceInfo *DI);
  296. /// Transform the given type-with-location into a new
  297. /// type, collecting location information in the given builder
  298. /// as necessary.
  299. ///
  300. QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
  301. /// Transform a type that is permitted to produce a
  302. /// DeducedTemplateSpecializationType.
  303. ///
  304. /// This is used in the (relatively rare) contexts where it is acceptable
  305. /// for transformation to produce a class template type with deduced
  306. /// template arguments.
  307. /// @{
  308. QualType TransformTypeWithDeducedTST(QualType T);
  309. TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI);
  310. /// @}
  311. /// The reason why the value of a statement is not discarded, if any.
  312. enum StmtDiscardKind {
  313. SDK_Discarded,
  314. SDK_NotDiscarded,
  315. SDK_StmtExprResult,
  316. };
  317. /// Transform the given statement.
  318. ///
  319. /// By default, this routine transforms a statement by delegating to the
  320. /// appropriate TransformXXXStmt function to transform a specific kind of
  321. /// statement or the TransformExpr() function to transform an expression.
  322. /// Subclasses may override this function to transform statements using some
  323. /// other mechanism.
  324. ///
  325. /// \returns the transformed statement.
  326. StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded);
  327. /// Transform the given statement.
  328. ///
  329. /// By default, this routine transforms a statement by delegating to the
  330. /// appropriate TransformOMPXXXClause function to transform a specific kind
  331. /// of clause. Subclasses may override this function to transform statements
  332. /// using some other mechanism.
  333. ///
  334. /// \returns the transformed OpenMP clause.
  335. OMPClause *TransformOMPClause(OMPClause *S);
  336. /// Transform the given attribute.
  337. ///
  338. /// By default, this routine transforms a statement by delegating to the
  339. /// appropriate TransformXXXAttr function to transform a specific kind
  340. /// of attribute. Subclasses may override this function to transform
  341. /// attributed statements using some other mechanism.
  342. ///
  343. /// \returns the transformed attribute
  344. const Attr *TransformAttr(const Attr *S);
  345. /// Transform the specified attribute.
  346. ///
  347. /// Subclasses should override the transformation of attributes with a pragma
  348. /// spelling to transform expressions stored within the attribute.
  349. ///
  350. /// \returns the transformed attribute.
  351. #define ATTR(X)
  352. #define PRAGMA_SPELLING_ATTR(X) \
  353. const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
  354. #include "clang/Basic/AttrList.inc"
  355. /// Transform the given expression.
  356. ///
  357. /// By default, this routine transforms an expression by delegating to the
  358. /// appropriate TransformXXXExpr function to build a new expression.
  359. /// Subclasses may override this function to transform expressions using some
  360. /// other mechanism.
  361. ///
  362. /// \returns the transformed expression.
  363. ExprResult TransformExpr(Expr *E);
  364. /// Transform the given initializer.
  365. ///
  366. /// By default, this routine transforms an initializer by stripping off the
  367. /// semantic nodes added by initialization, then passing the result to
  368. /// TransformExpr or TransformExprs.
  369. ///
  370. /// \returns the transformed initializer.
  371. ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
  372. /// Transform the given list of expressions.
  373. ///
  374. /// This routine transforms a list of expressions by invoking
  375. /// \c TransformExpr() for each subexpression. However, it also provides
  376. /// support for variadic templates by expanding any pack expansions (if the
  377. /// derived class permits such expansion) along the way. When pack expansions
  378. /// are present, the number of outputs may not equal the number of inputs.
  379. ///
  380. /// \param Inputs The set of expressions to be transformed.
  381. ///
  382. /// \param NumInputs The number of expressions in \c Inputs.
  383. ///
  384. /// \param IsCall If \c true, then this transform is being performed on
  385. /// function-call arguments, and any arguments that should be dropped, will
  386. /// be.
  387. ///
  388. /// \param Outputs The transformed input expressions will be added to this
  389. /// vector.
  390. ///
  391. /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
  392. /// due to transformation.
  393. ///
  394. /// \returns true if an error occurred, false otherwise.
  395. bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
  396. SmallVectorImpl<Expr *> &Outputs,
  397. bool *ArgChanged = nullptr);
  398. /// Transform the given declaration, which is referenced from a type
  399. /// or expression.
  400. ///
  401. /// By default, acts as the identity function on declarations, unless the
  402. /// transformer has had to transform the declaration itself. Subclasses
  403. /// may override this function to provide alternate behavior.
  404. Decl *TransformDecl(SourceLocation Loc, Decl *D) {
  405. llvm::DenseMap<Decl *, Decl *>::iterator Known
  406. = TransformedLocalDecls.find(D);
  407. if (Known != TransformedLocalDecls.end())
  408. return Known->second;
  409. return D;
  410. }
  411. /// Transform the specified condition.
  412. ///
  413. /// By default, this transforms the variable and expression and rebuilds
  414. /// the condition.
  415. Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var,
  416. Expr *Expr,
  417. Sema::ConditionKind Kind);
  418. /// Transform the attributes associated with the given declaration and
  419. /// place them on the new declaration.
  420. ///
  421. /// By default, this operation does nothing. Subclasses may override this
  422. /// behavior to transform attributes.
  423. void transformAttrs(Decl *Old, Decl *New) { }
  424. /// Note that a local declaration has been transformed by this
  425. /// transformer.
  426. ///
  427. /// Local declarations are typically transformed via a call to
  428. /// TransformDefinition. However, in some cases (e.g., lambda expressions),
  429. /// the transformer itself has to transform the declarations. This routine
  430. /// can be overridden by a subclass that keeps track of such mappings.
  431. void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) {
  432. assert(New.size() == 1 &&
  433. "must override transformedLocalDecl if performing pack expansion");
  434. TransformedLocalDecls[Old] = New.front();
  435. }
  436. /// Transform the definition of the given declaration.
  437. ///
  438. /// By default, invokes TransformDecl() to transform the declaration.
  439. /// Subclasses may override this function to provide alternate behavior.
  440. Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
  441. return getDerived().TransformDecl(Loc, D);
  442. }
  443. /// Transform the given declaration, which was the first part of a
  444. /// nested-name-specifier in a member access expression.
  445. ///
  446. /// This specific declaration transformation only applies to the first
  447. /// identifier in a nested-name-specifier of a member access expression, e.g.,
  448. /// the \c T in \c x->T::member
  449. ///
  450. /// By default, invokes TransformDecl() to transform the declaration.
  451. /// Subclasses may override this function to provide alternate behavior.
  452. NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
  453. return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
  454. }
  455. /// Transform the set of declarations in an OverloadExpr.
  456. bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
  457. LookupResult &R);
  458. /// Transform the given nested-name-specifier with source-location
  459. /// information.
  460. ///
  461. /// By default, transforms all of the types and declarations within the
  462. /// nested-name-specifier. Subclasses may override this function to provide
  463. /// alternate behavior.
  464. NestedNameSpecifierLoc
  465. TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
  466. QualType ObjectType = QualType(),
  467. NamedDecl *FirstQualifierInScope = nullptr);
  468. /// Transform the given declaration name.
  469. ///
  470. /// By default, transforms the types of conversion function, constructor,
  471. /// and destructor names and then (if needed) rebuilds the declaration name.
  472. /// Identifiers and selectors are returned unmodified. Subclasses may
  473. /// override this function to provide alternate behavior.
  474. DeclarationNameInfo
  475. TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
  476. bool TransformRequiresExprRequirements(ArrayRef<concepts::Requirement *> Reqs,
  477. llvm::SmallVectorImpl<concepts::Requirement *> &Transformed);
  478. concepts::TypeRequirement *
  479. TransformTypeRequirement(concepts::TypeRequirement *Req);
  480. concepts::ExprRequirement *
  481. TransformExprRequirement(concepts::ExprRequirement *Req);
  482. concepts::NestedRequirement *
  483. TransformNestedRequirement(concepts::NestedRequirement *Req);
  484. /// Transform the given template name.
  485. ///
  486. /// \param SS The nested-name-specifier that qualifies the template
  487. /// name. This nested-name-specifier must already have been transformed.
  488. ///
  489. /// \param Name The template name to transform.
  490. ///
  491. /// \param NameLoc The source location of the template name.
  492. ///
  493. /// \param ObjectType If we're translating a template name within a member
  494. /// access expression, this is the type of the object whose member template
  495. /// is being referenced.
  496. ///
  497. /// \param FirstQualifierInScope If the first part of a nested-name-specifier
  498. /// also refers to a name within the current (lexical) scope, this is the
  499. /// declaration it refers to.
  500. ///
  501. /// By default, transforms the template name by transforming the declarations
  502. /// and nested-name-specifiers that occur within the template name.
  503. /// Subclasses may override this function to provide alternate behavior.
  504. TemplateName
  505. TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
  506. SourceLocation NameLoc,
  507. QualType ObjectType = QualType(),
  508. NamedDecl *FirstQualifierInScope = nullptr,
  509. bool AllowInjectedClassName = false);
  510. /// Transform the given template argument.
  511. ///
  512. /// By default, this operation transforms the type, expression, or
  513. /// declaration stored within the template argument and constructs a
  514. /// new template argument from the transformed result. Subclasses may
  515. /// override this function to provide alternate behavior.
  516. ///
  517. /// Returns true if there was an error.
  518. bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
  519. TemplateArgumentLoc &Output,
  520. bool Uneval = false);
  521. /// Transform the given set of template arguments.
  522. ///
  523. /// By default, this operation transforms all of the template arguments
  524. /// in the input set using \c TransformTemplateArgument(), and appends
  525. /// the transformed arguments to the output list.
  526. ///
  527. /// Note that this overload of \c TransformTemplateArguments() is merely
  528. /// a convenience function. Subclasses that wish to override this behavior
  529. /// should override the iterator-based member template version.
  530. ///
  531. /// \param Inputs The set of template arguments to be transformed.
  532. ///
  533. /// \param NumInputs The number of template arguments in \p Inputs.
  534. ///
  535. /// \param Outputs The set of transformed template arguments output by this
  536. /// routine.
  537. ///
  538. /// Returns true if an error occurred.
  539. bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
  540. unsigned NumInputs,
  541. TemplateArgumentListInfo &Outputs,
  542. bool Uneval = false) {
  543. return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
  544. Uneval);
  545. }
  546. /// Transform the given set of template arguments.
  547. ///
  548. /// By default, this operation transforms all of the template arguments
  549. /// in the input set using \c TransformTemplateArgument(), and appends
  550. /// the transformed arguments to the output list.
  551. ///
  552. /// \param First An iterator to the first template argument.
  553. ///
  554. /// \param Last An iterator one step past the last template argument.
  555. ///
  556. /// \param Outputs The set of transformed template arguments output by this
  557. /// routine.
  558. ///
  559. /// Returns true if an error occurred.
  560. template<typename InputIterator>
  561. bool TransformTemplateArguments(InputIterator First,
  562. InputIterator Last,
  563. TemplateArgumentListInfo &Outputs,
  564. bool Uneval = false);
  565. /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
  566. void InventTemplateArgumentLoc(const TemplateArgument &Arg,
  567. TemplateArgumentLoc &ArgLoc);
  568. /// Fakes up a TypeSourceInfo for a type.
  569. TypeSourceInfo *InventTypeSourceInfo(QualType T) {
  570. return SemaRef.Context.getTrivialTypeSourceInfo(T,
  571. getDerived().getBaseLocation());
  572. }
  573. #define ABSTRACT_TYPELOC(CLASS, PARENT)
  574. #define TYPELOC(CLASS, PARENT) \
  575. QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
  576. #include "clang/AST/TypeLocNodes.def"
  577. template<typename Fn>
  578. QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
  579. FunctionProtoTypeLoc TL,
  580. CXXRecordDecl *ThisContext,
  581. Qualifiers ThisTypeQuals,
  582. Fn TransformExceptionSpec);
  583. bool TransformExceptionSpec(SourceLocation Loc,
  584. FunctionProtoType::ExceptionSpecInfo &ESI,
  585. SmallVectorImpl<QualType> &Exceptions,
  586. bool &Changed);
  587. StmtResult TransformSEHHandler(Stmt *Handler);
  588. QualType
  589. TransformTemplateSpecializationType(TypeLocBuilder &TLB,
  590. TemplateSpecializationTypeLoc TL,
  591. TemplateName Template);
  592. QualType
  593. TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
  594. DependentTemplateSpecializationTypeLoc TL,
  595. TemplateName Template,
  596. CXXScopeSpec &SS);
  597. QualType TransformDependentTemplateSpecializationType(
  598. TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
  599. NestedNameSpecifierLoc QualifierLoc);
  600. /// Transforms the parameters of a function type into the
  601. /// given vectors.
  602. ///
  603. /// The result vectors should be kept in sync; null entries in the
  604. /// variables vector are acceptable.
  605. ///
  606. /// Return true on error.
  607. bool TransformFunctionTypeParams(
  608. SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
  609. const QualType *ParamTypes,
  610. const FunctionProtoType::ExtParameterInfo *ParamInfos,
  611. SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars,
  612. Sema::ExtParameterInfoBuilder &PInfos);
  613. /// Transforms a single function-type parameter. Return null
  614. /// on error.
  615. ///
  616. /// \param indexAdjustment - A number to add to the parameter's
  617. /// scope index; can be negative
  618. ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
  619. int indexAdjustment,
  620. Optional<unsigned> NumExpansions,
  621. bool ExpectParameterPack);
  622. /// Transform the body of a lambda-expression.
  623. StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body);
  624. /// Alternative implementation of TransformLambdaBody that skips transforming
  625. /// the body.
  626. StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
  627. QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
  628. StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
  629. ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
  630. TemplateParameterList *TransformTemplateParameterList(
  631. TemplateParameterList *TPL) {
  632. return TPL;
  633. }
  634. ExprResult TransformAddressOfOperand(Expr *E);
  635. ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
  636. bool IsAddressOfOperand,
  637. TypeSourceInfo **RecoveryTSI);
  638. ExprResult TransformParenDependentScopeDeclRefExpr(
  639. ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
  640. TypeSourceInfo **RecoveryTSI);
  641. StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
  642. // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
  643. // amount of stack usage with clang.
  644. #define STMT(Node, Parent) \
  645. LLVM_ATTRIBUTE_NOINLINE \
  646. StmtResult Transform##Node(Node *S);
  647. #define VALUESTMT(Node, Parent) \
  648. LLVM_ATTRIBUTE_NOINLINE \
  649. StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
  650. #define EXPR(Node, Parent) \
  651. LLVM_ATTRIBUTE_NOINLINE \
  652. ExprResult Transform##Node(Node *E);
  653. #define ABSTRACT_STMT(Stmt)
  654. #include "clang/AST/StmtNodes.inc"
  655. #define GEN_CLANG_CLAUSE_CLASS
  656. #define CLAUSE_CLASS(Enum, Str, Class) \
  657. LLVM_ATTRIBUTE_NOINLINE \
  658. OMPClause *Transform##Class(Class *S);
  659. #include "llvm/Frontend/OpenMP/OMP.inc"
  660. /// Build a new qualified type given its unqualified type and type location.
  661. ///
  662. /// By default, this routine adds type qualifiers only to types that can
  663. /// have qualifiers, and silently suppresses those qualifiers that are not
  664. /// permitted. Subclasses may override this routine to provide different
  665. /// behavior.
  666. QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL);
  667. /// Build a new pointer type given its pointee type.
  668. ///
  669. /// By default, performs semantic analysis when building the pointer type.
  670. /// Subclasses may override this routine to provide different behavior.
  671. QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
  672. /// Build a new block pointer type given its pointee type.
  673. ///
  674. /// By default, performs semantic analysis when building the block pointer
  675. /// type. Subclasses may override this routine to provide different behavior.
  676. QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
  677. /// Build a new reference type given the type it references.
  678. ///
  679. /// By default, performs semantic analysis when building the
  680. /// reference type. Subclasses may override this routine to provide
  681. /// different behavior.
  682. ///
  683. /// \param LValue whether the type was written with an lvalue sigil
  684. /// or an rvalue sigil.
  685. QualType RebuildReferenceType(QualType ReferentType,
  686. bool LValue,
  687. SourceLocation Sigil);
  688. /// Build a new member pointer type given the pointee type and the
  689. /// class type it refers into.
  690. ///
  691. /// By default, performs semantic analysis when building the member pointer
  692. /// type. Subclasses may override this routine to provide different behavior.
  693. QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
  694. SourceLocation Sigil);
  695. QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl,
  696. SourceLocation ProtocolLAngleLoc,
  697. ArrayRef<ObjCProtocolDecl *> Protocols,
  698. ArrayRef<SourceLocation> ProtocolLocs,
  699. SourceLocation ProtocolRAngleLoc);
  700. /// Build an Objective-C object type.
  701. ///
  702. /// By default, performs semantic analysis when building the object type.
  703. /// Subclasses may override this routine to provide different behavior.
  704. QualType RebuildObjCObjectType(QualType BaseType,
  705. SourceLocation Loc,
  706. SourceLocation TypeArgsLAngleLoc,
  707. ArrayRef<TypeSourceInfo *> TypeArgs,
  708. SourceLocation TypeArgsRAngleLoc,
  709. SourceLocation ProtocolLAngleLoc,
  710. ArrayRef<ObjCProtocolDecl *> Protocols,
  711. ArrayRef<SourceLocation> ProtocolLocs,
  712. SourceLocation ProtocolRAngleLoc);
  713. /// Build a new Objective-C object pointer type given the pointee type.
  714. ///
  715. /// By default, directly builds the pointer type, with no additional semantic
  716. /// analysis.
  717. QualType RebuildObjCObjectPointerType(QualType PointeeType,
  718. SourceLocation Star);
  719. /// Build a new array type given the element type, size
  720. /// modifier, size of the array (if known), size expression, and index type
  721. /// qualifiers.
  722. ///
  723. /// By default, performs semantic analysis when building the array type.
  724. /// Subclasses may override this routine to provide different behavior.
  725. /// Also by default, all of the other Rebuild*Array
  726. QualType RebuildArrayType(QualType ElementType,
  727. ArrayType::ArraySizeModifier SizeMod,
  728. const llvm::APInt *Size,
  729. Expr *SizeExpr,
  730. unsigned IndexTypeQuals,
  731. SourceRange BracketsRange);
  732. /// Build a new constant array type given the element type, size
  733. /// modifier, (known) size of the array, and index type qualifiers.
  734. ///
  735. /// By default, performs semantic analysis when building the array type.
  736. /// Subclasses may override this routine to provide different behavior.
  737. QualType RebuildConstantArrayType(QualType ElementType,
  738. ArrayType::ArraySizeModifier SizeMod,
  739. const llvm::APInt &Size,
  740. Expr *SizeExpr,
  741. unsigned IndexTypeQuals,
  742. SourceRange BracketsRange);
  743. /// Build a new incomplete array type given the element type, size
  744. /// modifier, and index type qualifiers.
  745. ///
  746. /// By default, performs semantic analysis when building the array type.
  747. /// Subclasses may override this routine to provide different behavior.
  748. QualType RebuildIncompleteArrayType(QualType ElementType,
  749. ArrayType::ArraySizeModifier SizeMod,
  750. unsigned IndexTypeQuals,
  751. SourceRange BracketsRange);
  752. /// Build a new variable-length array type given the element type,
  753. /// size modifier, size expression, and index type qualifiers.
  754. ///
  755. /// By default, performs semantic analysis when building the array type.
  756. /// Subclasses may override this routine to provide different behavior.
  757. QualType RebuildVariableArrayType(QualType ElementType,
  758. ArrayType::ArraySizeModifier SizeMod,
  759. Expr *SizeExpr,
  760. unsigned IndexTypeQuals,
  761. SourceRange BracketsRange);
  762. /// Build a new dependent-sized array type given the element type,
  763. /// size modifier, size expression, and index type qualifiers.
  764. ///
  765. /// By default, performs semantic analysis when building the array type.
  766. /// Subclasses may override this routine to provide different behavior.
  767. QualType RebuildDependentSizedArrayType(QualType ElementType,
  768. ArrayType::ArraySizeModifier SizeMod,
  769. Expr *SizeExpr,
  770. unsigned IndexTypeQuals,
  771. SourceRange BracketsRange);
  772. /// Build a new vector type given the element type and
  773. /// number of elements.
  774. ///
  775. /// By default, performs semantic analysis when building the vector type.
  776. /// Subclasses may override this routine to provide different behavior.
  777. QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
  778. VectorType::VectorKind VecKind);
  779. /// Build a new potentially dependently-sized extended vector type
  780. /// given the element type and number of elements.
  781. ///
  782. /// By default, performs semantic analysis when building the vector type.
  783. /// Subclasses may override this routine to provide different behavior.
  784. QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr,
  785. SourceLocation AttributeLoc,
  786. VectorType::VectorKind);
  787. /// Build a new extended vector type given the element type and
  788. /// number of elements.
  789. ///
  790. /// By default, performs semantic analysis when building the vector type.
  791. /// Subclasses may override this routine to provide different behavior.
  792. QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
  793. SourceLocation AttributeLoc);
  794. /// Build a new potentially dependently-sized extended vector type
  795. /// given the element type and number of elements.
  796. ///
  797. /// By default, performs semantic analysis when building the vector type.
  798. /// Subclasses may override this routine to provide different behavior.
  799. QualType RebuildDependentSizedExtVectorType(QualType ElementType,
  800. Expr *SizeExpr,
  801. SourceLocation AttributeLoc);
  802. /// Build a new matrix type given the element type and dimensions.
  803. QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
  804. unsigned NumColumns);
  805. /// Build a new matrix type given the type and dependently-defined
  806. /// dimensions.
  807. QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr,
  808. Expr *ColumnExpr,
  809. SourceLocation AttributeLoc);
  810. /// Build a new DependentAddressSpaceType or return the pointee
  811. /// type variable with the correct address space (retrieved from
  812. /// AddrSpaceExpr) applied to it. The former will be returned in cases
  813. /// where the address space remains dependent.
  814. ///
  815. /// By default, performs semantic analysis when building the type with address
  816. /// space applied. Subclasses may override this routine to provide different
  817. /// behavior.
  818. QualType RebuildDependentAddressSpaceType(QualType PointeeType,
  819. Expr *AddrSpaceExpr,
  820. SourceLocation AttributeLoc);
  821. /// Build a new function type.
  822. ///
  823. /// By default, performs semantic analysis when building the function type.
  824. /// Subclasses may override this routine to provide different behavior.
  825. QualType RebuildFunctionProtoType(QualType T,
  826. MutableArrayRef<QualType> ParamTypes,
  827. const FunctionProtoType::ExtProtoInfo &EPI);
  828. /// Build a new unprototyped function type.
  829. QualType RebuildFunctionNoProtoType(QualType ResultType);
  830. /// Rebuild an unresolved typename type, given the decl that
  831. /// the UnresolvedUsingTypenameDecl was transformed to.
  832. QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D);
  833. /// Build a new type found via an alias.
  834. QualType RebuildUsingType(UsingShadowDecl *Found, QualType Underlying) {
  835. return SemaRef.Context.getUsingType(Found, Underlying);
  836. }
  837. /// Build a new typedef type.
  838. QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
  839. return SemaRef.Context.getTypeDeclType(Typedef);
  840. }
  841. /// Build a new MacroDefined type.
  842. QualType RebuildMacroQualifiedType(QualType T,
  843. const IdentifierInfo *MacroII) {
  844. return SemaRef.Context.getMacroQualifiedType(T, MacroII);
  845. }
  846. /// Build a new class/struct/union type.
  847. QualType RebuildRecordType(RecordDecl *Record) {
  848. return SemaRef.Context.getTypeDeclType(Record);
  849. }
  850. /// Build a new Enum type.
  851. QualType RebuildEnumType(EnumDecl *Enum) {
  852. return SemaRef.Context.getTypeDeclType(Enum);
  853. }
  854. /// Build a new typeof(expr) type.
  855. ///
  856. /// By default, performs semantic analysis when building the typeof type.
  857. /// Subclasses may override this routine to provide different behavior.
  858. QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
  859. /// Build a new typeof(type) type.
  860. ///
  861. /// By default, builds a new TypeOfType with the given underlying type.
  862. QualType RebuildTypeOfType(QualType Underlying);
  863. /// Build a new unary transform type.
  864. QualType RebuildUnaryTransformType(QualType BaseType,
  865. UnaryTransformType::UTTKind UKind,
  866. SourceLocation Loc);
  867. /// Build a new C++11 decltype type.
  868. ///
  869. /// By default, performs semantic analysis when building the decltype type.
  870. /// Subclasses may override this routine to provide different behavior.
  871. QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
  872. /// Build a new C++11 auto type.
  873. ///
  874. /// By default, builds a new AutoType with the given deduced type.
  875. QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword,
  876. ConceptDecl *TypeConstraintConcept,
  877. ArrayRef<TemplateArgument> TypeConstraintArgs) {
  878. // Note, IsDependent is always false here: we implicitly convert an 'auto'
  879. // which has been deduced to a dependent type into an undeduced 'auto', so
  880. // that we'll retry deduction after the transformation.
  881. return SemaRef.Context.getAutoType(Deduced, Keyword,
  882. /*IsDependent*/ false, /*IsPack=*/false,
  883. TypeConstraintConcept,
  884. TypeConstraintArgs);
  885. }
  886. /// By default, builds a new DeducedTemplateSpecializationType with the given
  887. /// deduced type.
  888. QualType RebuildDeducedTemplateSpecializationType(TemplateName Template,
  889. QualType Deduced) {
  890. return SemaRef.Context.getDeducedTemplateSpecializationType(
  891. Template, Deduced, /*IsDependent*/ false);
  892. }
  893. /// Build a new template specialization type.
  894. ///
  895. /// By default, performs semantic analysis when building the template
  896. /// specialization type. Subclasses may override this routine to provide
  897. /// different behavior.
  898. QualType RebuildTemplateSpecializationType(TemplateName Template,
  899. SourceLocation TemplateLoc,
  900. TemplateArgumentListInfo &Args);
  901. /// Build a new parenthesized type.
  902. ///
  903. /// By default, builds a new ParenType type from the inner type.
  904. /// Subclasses may override this routine to provide different behavior.
  905. QualType RebuildParenType(QualType InnerType) {
  906. return SemaRef.BuildParenType(InnerType);
  907. }
  908. /// Build a new qualified name type.
  909. ///
  910. /// By default, builds a new ElaboratedType type from the keyword,
  911. /// the nested-name-specifier and the named type.
  912. /// Subclasses may override this routine to provide different behavior.
  913. QualType RebuildElaboratedType(SourceLocation KeywordLoc,
  914. ElaboratedTypeKeyword Keyword,
  915. NestedNameSpecifierLoc QualifierLoc,
  916. QualType Named) {
  917. return SemaRef.Context.getElaboratedType(Keyword,
  918. QualifierLoc.getNestedNameSpecifier(),
  919. Named);
  920. }
  921. /// Build a new typename type that refers to a template-id.
  922. ///
  923. /// By default, builds a new DependentNameType type from the
  924. /// nested-name-specifier and the given type. Subclasses may override
  925. /// this routine to provide different behavior.
  926. QualType RebuildDependentTemplateSpecializationType(
  927. ElaboratedTypeKeyword Keyword,
  928. NestedNameSpecifierLoc QualifierLoc,
  929. SourceLocation TemplateKWLoc,
  930. const IdentifierInfo *Name,
  931. SourceLocation NameLoc,
  932. TemplateArgumentListInfo &Args,
  933. bool AllowInjectedClassName) {
  934. // Rebuild the template name.
  935. // TODO: avoid TemplateName abstraction
  936. CXXScopeSpec SS;
  937. SS.Adopt(QualifierLoc);
  938. TemplateName InstName = getDerived().RebuildTemplateName(
  939. SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
  940. AllowInjectedClassName);
  941. if (InstName.isNull())
  942. return QualType();
  943. // If it's still dependent, make a dependent specialization.
  944. if (InstName.getAsDependentTemplateName())
  945. return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
  946. QualifierLoc.getNestedNameSpecifier(),
  947. Name,
  948. Args);
  949. // Otherwise, make an elaborated type wrapping a non-dependent
  950. // specialization.
  951. QualType T =
  952. getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
  953. if (T.isNull()) return QualType();
  954. if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
  955. return T;
  956. return SemaRef.Context.getElaboratedType(Keyword,
  957. QualifierLoc.getNestedNameSpecifier(),
  958. T);
  959. }
  960. /// Build a new typename type that refers to an identifier.
  961. ///
  962. /// By default, performs semantic analysis when building the typename type
  963. /// (or elaborated type). Subclasses may override this routine to provide
  964. /// different behavior.
  965. QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
  966. SourceLocation KeywordLoc,
  967. NestedNameSpecifierLoc QualifierLoc,
  968. const IdentifierInfo *Id,
  969. SourceLocation IdLoc,
  970. bool DeducedTSTContext) {
  971. CXXScopeSpec SS;
  972. SS.Adopt(QualifierLoc);
  973. if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
  974. // If the name is still dependent, just build a new dependent name type.
  975. if (!SemaRef.computeDeclContext(SS))
  976. return SemaRef.Context.getDependentNameType(Keyword,
  977. QualifierLoc.getNestedNameSpecifier(),
  978. Id);
  979. }
  980. if (Keyword == ETK_None || Keyword == ETK_Typename) {
  981. return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
  982. *Id, IdLoc, DeducedTSTContext);
  983. }
  984. TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
  985. // We had a dependent elaborated-type-specifier that has been transformed
  986. // into a non-dependent elaborated-type-specifier. Find the tag we're
  987. // referring to.
  988. LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
  989. DeclContext *DC = SemaRef.computeDeclContext(SS, false);
  990. if (!DC)
  991. return QualType();
  992. if (SemaRef.RequireCompleteDeclContext(SS, DC))
  993. return QualType();
  994. TagDecl *Tag = nullptr;
  995. SemaRef.LookupQualifiedName(Result, DC);
  996. switch (Result.getResultKind()) {
  997. case LookupResult::NotFound:
  998. case LookupResult::NotFoundInCurrentInstantiation:
  999. break;
  1000. case LookupResult::Found:
  1001. Tag = Result.getAsSingle<TagDecl>();
  1002. break;
  1003. case LookupResult::FoundOverloaded:
  1004. case LookupResult::FoundUnresolvedValue:
  1005. llvm_unreachable("Tag lookup cannot find non-tags");
  1006. case LookupResult::Ambiguous:
  1007. // Let the LookupResult structure handle ambiguities.
  1008. return QualType();
  1009. }
  1010. if (!Tag) {
  1011. // Check where the name exists but isn't a tag type and use that to emit
  1012. // better diagnostics.
  1013. LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
  1014. SemaRef.LookupQualifiedName(Result, DC);
  1015. switch (Result.getResultKind()) {
  1016. case LookupResult::Found:
  1017. case LookupResult::FoundOverloaded:
  1018. case LookupResult::FoundUnresolvedValue: {
  1019. NamedDecl *SomeDecl = Result.getRepresentativeDecl();
  1020. Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
  1021. SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl
  1022. << NTK << Kind;
  1023. SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
  1024. break;
  1025. }
  1026. default:
  1027. SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
  1028. << Kind << Id << DC << QualifierLoc.getSourceRange();
  1029. break;
  1030. }
  1031. return QualType();
  1032. }
  1033. if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
  1034. IdLoc, Id)) {
  1035. SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
  1036. SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
  1037. return QualType();
  1038. }
  1039. // Build the elaborated-type-specifier type.
  1040. QualType T = SemaRef.Context.getTypeDeclType(Tag);
  1041. return SemaRef.Context.getElaboratedType(Keyword,
  1042. QualifierLoc.getNestedNameSpecifier(),
  1043. T);
  1044. }
  1045. /// Build a new pack expansion type.
  1046. ///
  1047. /// By default, builds a new PackExpansionType type from the given pattern.
  1048. /// Subclasses may override this routine to provide different behavior.
  1049. QualType RebuildPackExpansionType(QualType Pattern,
  1050. SourceRange PatternRange,
  1051. SourceLocation EllipsisLoc,
  1052. Optional<unsigned> NumExpansions) {
  1053. return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
  1054. NumExpansions);
  1055. }
  1056. /// Build a new atomic type given its value type.
  1057. ///
  1058. /// By default, performs semantic analysis when building the atomic type.
  1059. /// Subclasses may override this routine to provide different behavior.
  1060. QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
  1061. /// Build a new pipe type given its value type.
  1062. QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc,
  1063. bool isReadPipe);
  1064. /// Build a bit-precise int given its value type.
  1065. QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
  1066. SourceLocation Loc);
  1067. /// Build a dependent bit-precise int given its value type.
  1068. QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
  1069. SourceLocation Loc);
  1070. /// Build a new template name given a nested name specifier, a flag
  1071. /// indicating whether the "template" keyword was provided, and the template
  1072. /// that the template name refers to.
  1073. ///
  1074. /// By default, builds the new template name directly. Subclasses may override
  1075. /// this routine to provide different behavior.
  1076. TemplateName RebuildTemplateName(CXXScopeSpec &SS,
  1077. bool TemplateKW,
  1078. TemplateDecl *Template);
  1079. /// Build a new template name given a nested name specifier and the
  1080. /// name that is referred to as a template.
  1081. ///
  1082. /// By default, performs semantic analysis to determine whether the name can
  1083. /// be resolved to a specific template, then builds the appropriate kind of
  1084. /// template name. Subclasses may override this routine to provide different
  1085. /// behavior.
  1086. TemplateName RebuildTemplateName(CXXScopeSpec &SS,
  1087. SourceLocation TemplateKWLoc,
  1088. const IdentifierInfo &Name,
  1089. SourceLocation NameLoc, QualType ObjectType,
  1090. NamedDecl *FirstQualifierInScope,
  1091. bool AllowInjectedClassName);
  1092. /// Build a new template name given a nested name specifier and the
  1093. /// overloaded operator name that is referred to as a template.
  1094. ///
  1095. /// By default, performs semantic analysis to determine whether the name can
  1096. /// be resolved to a specific template, then builds the appropriate kind of
  1097. /// template name. Subclasses may override this routine to provide different
  1098. /// behavior.
  1099. TemplateName RebuildTemplateName(CXXScopeSpec &SS,
  1100. SourceLocation TemplateKWLoc,
  1101. OverloadedOperatorKind Operator,
  1102. SourceLocation NameLoc, QualType ObjectType,
  1103. bool AllowInjectedClassName);
  1104. /// Build a new template name given a template template parameter pack
  1105. /// and the
  1106. ///
  1107. /// By default, performs semantic analysis to determine whether the name can
  1108. /// be resolved to a specific template, then builds the appropriate kind of
  1109. /// template name. Subclasses may override this routine to provide different
  1110. /// behavior.
  1111. TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
  1112. const TemplateArgument &ArgPack) {
  1113. return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
  1114. }
  1115. /// Build a new compound statement.
  1116. ///
  1117. /// By default, performs semantic analysis to build the new statement.
  1118. /// Subclasses may override this routine to provide different behavior.
  1119. StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
  1120. MultiStmtArg Statements,
  1121. SourceLocation RBraceLoc,
  1122. bool IsStmtExpr) {
  1123. return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
  1124. IsStmtExpr);
  1125. }
  1126. /// Build a new case statement.
  1127. ///
  1128. /// By default, performs semantic analysis to build the new statement.
  1129. /// Subclasses may override this routine to provide different behavior.
  1130. StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
  1131. Expr *LHS,
  1132. SourceLocation EllipsisLoc,
  1133. Expr *RHS,
  1134. SourceLocation ColonLoc) {
  1135. return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
  1136. ColonLoc);
  1137. }
  1138. /// Attach the body to a new case statement.
  1139. ///
  1140. /// By default, performs semantic analysis to build the new statement.
  1141. /// Subclasses may override this routine to provide different behavior.
  1142. StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
  1143. getSema().ActOnCaseStmtBody(S, Body);
  1144. return S;
  1145. }
  1146. /// Build a new default statement.
  1147. ///
  1148. /// By default, performs semantic analysis to build the new statement.
  1149. /// Subclasses may override this routine to provide different behavior.
  1150. StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
  1151. SourceLocation ColonLoc,
  1152. Stmt *SubStmt) {
  1153. return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
  1154. /*CurScope=*/nullptr);
  1155. }
  1156. /// Build a new label statement.
  1157. ///
  1158. /// By default, performs semantic analysis to build the new statement.
  1159. /// Subclasses may override this routine to provide different behavior.
  1160. StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
  1161. SourceLocation ColonLoc, Stmt *SubStmt) {
  1162. return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
  1163. }
  1164. /// Build a new attributed statement.
  1165. ///
  1166. /// By default, performs semantic analysis to build the new statement.
  1167. /// Subclasses may override this routine to provide different behavior.
  1168. StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
  1169. ArrayRef<const Attr *> Attrs,
  1170. Stmt *SubStmt) {
  1171. return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
  1172. }
  1173. /// Build a new "if" statement.
  1174. ///
  1175. /// By default, performs semantic analysis to build the new statement.
  1176. /// Subclasses may override this routine to provide different behavior.
  1177. StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind,
  1178. SourceLocation LParenLoc, Sema::ConditionResult Cond,
  1179. SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
  1180. SourceLocation ElseLoc, Stmt *Else) {
  1181. return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
  1182. Then, ElseLoc, Else);
  1183. }
  1184. /// Start building a new switch statement.
  1185. ///
  1186. /// By default, performs semantic analysis to build the new statement.
  1187. /// Subclasses may override this routine to provide different behavior.
  1188. StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
  1189. SourceLocation LParenLoc, Stmt *Init,
  1190. Sema::ConditionResult Cond,
  1191. SourceLocation RParenLoc) {
  1192. return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
  1193. RParenLoc);
  1194. }
  1195. /// Attach the body to the switch statement.
  1196. ///
  1197. /// By default, performs semantic analysis to build the new statement.
  1198. /// Subclasses may override this routine to provide different behavior.
  1199. StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
  1200. Stmt *Switch, Stmt *Body) {
  1201. return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
  1202. }
  1203. /// Build a new while statement.
  1204. ///
  1205. /// By default, performs semantic analysis to build the new statement.
  1206. /// Subclasses may override this routine to provide different behavior.
  1207. StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc,
  1208. Sema::ConditionResult Cond,
  1209. SourceLocation RParenLoc, Stmt *Body) {
  1210. return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
  1211. }
  1212. /// Build a new do-while statement.
  1213. ///
  1214. /// By default, performs semantic analysis to build the new statement.
  1215. /// Subclasses may override this routine to provide different behavior.
  1216. StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
  1217. SourceLocation WhileLoc, SourceLocation LParenLoc,
  1218. Expr *Cond, SourceLocation RParenLoc) {
  1219. return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
  1220. Cond, RParenLoc);
  1221. }
  1222. /// Build a new for statement.
  1223. ///
  1224. /// By default, performs semantic analysis to build the new statement.
  1225. /// Subclasses may override this routine to provide different behavior.
  1226. StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
  1227. Stmt *Init, Sema::ConditionResult Cond,
  1228. Sema::FullExprArg Inc, SourceLocation RParenLoc,
  1229. Stmt *Body) {
  1230. return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
  1231. Inc, RParenLoc, Body);
  1232. }
  1233. /// Build a new goto statement.
  1234. ///
  1235. /// By default, performs semantic analysis to build the new statement.
  1236. /// Subclasses may override this routine to provide different behavior.
  1237. StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
  1238. LabelDecl *Label) {
  1239. return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
  1240. }
  1241. /// Build a new indirect goto statement.
  1242. ///
  1243. /// By default, performs semantic analysis to build the new statement.
  1244. /// Subclasses may override this routine to provide different behavior.
  1245. StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
  1246. SourceLocation StarLoc,
  1247. Expr *Target) {
  1248. return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
  1249. }
  1250. /// Build a new return statement.
  1251. ///
  1252. /// By default, performs semantic analysis to build the new statement.
  1253. /// Subclasses may override this routine to provide different behavior.
  1254. StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
  1255. return getSema().BuildReturnStmt(ReturnLoc, Result);
  1256. }
  1257. /// Build a new declaration statement.
  1258. ///
  1259. /// By default, performs semantic analysis to build the new statement.
  1260. /// Subclasses may override this routine to provide different behavior.
  1261. StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
  1262. SourceLocation StartLoc, SourceLocation EndLoc) {
  1263. Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
  1264. return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
  1265. }
  1266. /// Build a new inline asm statement.
  1267. ///
  1268. /// By default, performs semantic analysis to build the new statement.
  1269. /// Subclasses may override this routine to provide different behavior.
  1270. StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
  1271. bool IsVolatile, unsigned NumOutputs,
  1272. unsigned NumInputs, IdentifierInfo **Names,
  1273. MultiExprArg Constraints, MultiExprArg Exprs,
  1274. Expr *AsmString, MultiExprArg Clobbers,
  1275. unsigned NumLabels,
  1276. SourceLocation RParenLoc) {
  1277. return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
  1278. NumInputs, Names, Constraints, Exprs,
  1279. AsmString, Clobbers, NumLabels, RParenLoc);
  1280. }
  1281. /// Build a new MS style inline asm statement.
  1282. ///
  1283. /// By default, performs semantic analysis to build the new statement.
  1284. /// Subclasses may override this routine to provide different behavior.
  1285. StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
  1286. ArrayRef<Token> AsmToks,
  1287. StringRef AsmString,
  1288. unsigned NumOutputs, unsigned NumInputs,
  1289. ArrayRef<StringRef> Constraints,
  1290. ArrayRef<StringRef> Clobbers,
  1291. ArrayRef<Expr*> Exprs,
  1292. SourceLocation EndLoc) {
  1293. return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
  1294. NumOutputs, NumInputs,
  1295. Constraints, Clobbers, Exprs, EndLoc);
  1296. }
  1297. /// Build a new co_return statement.
  1298. ///
  1299. /// By default, performs semantic analysis to build the new statement.
  1300. /// Subclasses may override this routine to provide different behavior.
  1301. StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result,
  1302. bool IsImplicit) {
  1303. return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
  1304. }
  1305. /// Build a new co_await expression.
  1306. ///
  1307. /// By default, performs semantic analysis to build the new expression.
  1308. /// Subclasses may override this routine to provide different behavior.
  1309. ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result,
  1310. bool IsImplicit) {
  1311. return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit);
  1312. }
  1313. /// Build a new co_await expression.
  1314. ///
  1315. /// By default, performs semantic analysis to build the new expression.
  1316. /// Subclasses may override this routine to provide different behavior.
  1317. ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc,
  1318. Expr *Result,
  1319. UnresolvedLookupExpr *Lookup) {
  1320. return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
  1321. }
  1322. /// Build a new co_yield expression.
  1323. ///
  1324. /// By default, performs semantic analysis to build the new expression.
  1325. /// Subclasses may override this routine to provide different behavior.
  1326. ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) {
  1327. return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
  1328. }
  1329. StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) {
  1330. return getSema().BuildCoroutineBodyStmt(Args);
  1331. }
  1332. /// Build a new Objective-C \@try statement.
  1333. ///
  1334. /// By default, performs semantic analysis to build the new statement.
  1335. /// Subclasses may override this routine to provide different behavior.
  1336. StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
  1337. Stmt *TryBody,
  1338. MultiStmtArg CatchStmts,
  1339. Stmt *Finally) {
  1340. return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
  1341. Finally);
  1342. }
  1343. /// Rebuild an Objective-C exception declaration.
  1344. ///
  1345. /// By default, performs semantic analysis to build the new declaration.
  1346. /// Subclasses may override this routine to provide different behavior.
  1347. VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
  1348. TypeSourceInfo *TInfo, QualType T) {
  1349. return getSema().BuildObjCExceptionDecl(TInfo, T,
  1350. ExceptionDecl->getInnerLocStart(),
  1351. ExceptionDecl->getLocation(),
  1352. ExceptionDecl->getIdentifier());
  1353. }
  1354. /// Build a new Objective-C \@catch statement.
  1355. ///
  1356. /// By default, performs semantic analysis to build the new statement.
  1357. /// Subclasses may override this routine to provide different behavior.
  1358. StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
  1359. SourceLocation RParenLoc,
  1360. VarDecl *Var,
  1361. Stmt *Body) {
  1362. return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
  1363. Var, Body);
  1364. }
  1365. /// Build a new Objective-C \@finally statement.
  1366. ///
  1367. /// By default, performs semantic analysis to build the new statement.
  1368. /// Subclasses may override this routine to provide different behavior.
  1369. StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
  1370. Stmt *Body) {
  1371. return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
  1372. }
  1373. /// Build a new Objective-C \@throw statement.
  1374. ///
  1375. /// By default, performs semantic analysis to build the new statement.
  1376. /// Subclasses may override this routine to provide different behavior.
  1377. StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
  1378. Expr *Operand) {
  1379. return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
  1380. }
  1381. /// Build a new OpenMP Canonical loop.
  1382. ///
  1383. /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
  1384. /// OMPCanonicalLoop.
  1385. StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt) {
  1386. return getSema().ActOnOpenMPCanonicalLoop(LoopStmt);
  1387. }
  1388. /// Build a new OpenMP executable directive.
  1389. ///
  1390. /// By default, performs semantic analysis to build the new statement.
  1391. /// Subclasses may override this routine to provide different behavior.
  1392. StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
  1393. DeclarationNameInfo DirName,
  1394. OpenMPDirectiveKind CancelRegion,
  1395. ArrayRef<OMPClause *> Clauses,
  1396. Stmt *AStmt, SourceLocation StartLoc,
  1397. SourceLocation EndLoc) {
  1398. return getSema().ActOnOpenMPExecutableDirective(
  1399. Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
  1400. }
  1401. /// Build a new OpenMP 'if' clause.
  1402. ///
  1403. /// By default, performs semantic analysis to build the new OpenMP clause.
  1404. /// Subclasses may override this routine to provide different behavior.
  1405. OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
  1406. Expr *Condition, SourceLocation StartLoc,
  1407. SourceLocation LParenLoc,
  1408. SourceLocation NameModifierLoc,
  1409. SourceLocation ColonLoc,
  1410. SourceLocation EndLoc) {
  1411. return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
  1412. LParenLoc, NameModifierLoc, ColonLoc,
  1413. EndLoc);
  1414. }
  1415. /// Build a new OpenMP 'final' clause.
  1416. ///
  1417. /// By default, performs semantic analysis to build the new OpenMP clause.
  1418. /// Subclasses may override this routine to provide different behavior.
  1419. OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
  1420. SourceLocation LParenLoc,
  1421. SourceLocation EndLoc) {
  1422. return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
  1423. EndLoc);
  1424. }
  1425. /// Build a new OpenMP 'num_threads' clause.
  1426. ///
  1427. /// By default, performs semantic analysis to build the new OpenMP clause.
  1428. /// Subclasses may override this routine to provide different behavior.
  1429. OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
  1430. SourceLocation StartLoc,
  1431. SourceLocation LParenLoc,
  1432. SourceLocation EndLoc) {
  1433. return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
  1434. LParenLoc, EndLoc);
  1435. }
  1436. /// Build a new OpenMP 'safelen' clause.
  1437. ///
  1438. /// By default, performs semantic analysis to build the new OpenMP clause.
  1439. /// Subclasses may override this routine to provide different behavior.
  1440. OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
  1441. SourceLocation LParenLoc,
  1442. SourceLocation EndLoc) {
  1443. return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
  1444. }
  1445. /// Build a new OpenMP 'simdlen' clause.
  1446. ///
  1447. /// By default, performs semantic analysis to build the new OpenMP clause.
  1448. /// Subclasses may override this routine to provide different behavior.
  1449. OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
  1450. SourceLocation LParenLoc,
  1451. SourceLocation EndLoc) {
  1452. return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
  1453. }
  1454. OMPClause *RebuildOMPSizesClause(ArrayRef<Expr *> Sizes,
  1455. SourceLocation StartLoc,
  1456. SourceLocation LParenLoc,
  1457. SourceLocation EndLoc) {
  1458. return getSema().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc, EndLoc);
  1459. }
  1460. /// Build a new OpenMP 'full' clause.
  1461. OMPClause *RebuildOMPFullClause(SourceLocation StartLoc,
  1462. SourceLocation EndLoc) {
  1463. return getSema().ActOnOpenMPFullClause(StartLoc, EndLoc);
  1464. }
  1465. /// Build a new OpenMP 'partial' clause.
  1466. OMPClause *RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc,
  1467. SourceLocation LParenLoc,
  1468. SourceLocation EndLoc) {
  1469. return getSema().ActOnOpenMPPartialClause(Factor, StartLoc, LParenLoc,
  1470. EndLoc);
  1471. }
  1472. /// Build a new OpenMP 'allocator' clause.
  1473. ///
  1474. /// By default, performs semantic analysis to build the new OpenMP clause.
  1475. /// Subclasses may override this routine to provide different behavior.
  1476. OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc,
  1477. SourceLocation LParenLoc,
  1478. SourceLocation EndLoc) {
  1479. return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
  1480. }
  1481. /// Build a new OpenMP 'collapse' clause.
  1482. ///
  1483. /// By default, performs semantic analysis to build the new OpenMP clause.
  1484. /// Subclasses may override this routine to provide different behavior.
  1485. OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
  1486. SourceLocation LParenLoc,
  1487. SourceLocation EndLoc) {
  1488. return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
  1489. EndLoc);
  1490. }
  1491. /// Build a new OpenMP 'default' clause.
  1492. ///
  1493. /// By default, performs semantic analysis to build the new OpenMP clause.
  1494. /// Subclasses may override this routine to provide different behavior.
  1495. OMPClause *RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc,
  1496. SourceLocation StartLoc,
  1497. SourceLocation LParenLoc,
  1498. SourceLocation EndLoc) {
  1499. return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
  1500. StartLoc, LParenLoc, EndLoc);
  1501. }
  1502. /// Build a new OpenMP 'proc_bind' clause.
  1503. ///
  1504. /// By default, performs semantic analysis to build the new OpenMP clause.
  1505. /// Subclasses may override this routine to provide different behavior.
  1506. OMPClause *RebuildOMPProcBindClause(ProcBindKind Kind,
  1507. SourceLocation KindKwLoc,
  1508. SourceLocation StartLoc,
  1509. SourceLocation LParenLoc,
  1510. SourceLocation EndLoc) {
  1511. return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
  1512. StartLoc, LParenLoc, EndLoc);
  1513. }
  1514. /// Build a new OpenMP 'schedule' clause.
  1515. ///
  1516. /// By default, performs semantic analysis to build the new OpenMP clause.
  1517. /// Subclasses may override this routine to provide different behavior.
  1518. OMPClause *RebuildOMPScheduleClause(
  1519. OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2,
  1520. OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
  1521. SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
  1522. SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
  1523. return getSema().ActOnOpenMPScheduleClause(
  1524. M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
  1525. CommaLoc, EndLoc);
  1526. }
  1527. /// Build a new OpenMP 'ordered' clause.
  1528. ///
  1529. /// By default, performs semantic analysis to build the new OpenMP clause.
  1530. /// Subclasses may override this routine to provide different behavior.
  1531. OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
  1532. SourceLocation EndLoc,
  1533. SourceLocation LParenLoc, Expr *Num) {
  1534. return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
  1535. }
  1536. /// Build a new OpenMP 'private' clause.
  1537. ///
  1538. /// By default, performs semantic analysis to build the new OpenMP clause.
  1539. /// Subclasses may override this routine to provide different behavior.
  1540. OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
  1541. SourceLocation StartLoc,
  1542. SourceLocation LParenLoc,
  1543. SourceLocation EndLoc) {
  1544. return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
  1545. EndLoc);
  1546. }
  1547. /// Build a new OpenMP 'firstprivate' clause.
  1548. ///
  1549. /// By default, performs semantic analysis to build the new OpenMP clause.
  1550. /// Subclasses may override this routine to provide different behavior.
  1551. OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
  1552. SourceLocation StartLoc,
  1553. SourceLocation LParenLoc,
  1554. SourceLocation EndLoc) {
  1555. return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
  1556. EndLoc);
  1557. }
  1558. /// Build a new OpenMP 'lastprivate' clause.
  1559. ///
  1560. /// By default, performs semantic analysis to build the new OpenMP clause.
  1561. /// Subclasses may override this routine to provide different behavior.
  1562. OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
  1563. OpenMPLastprivateModifier LPKind,
  1564. SourceLocation LPKindLoc,
  1565. SourceLocation ColonLoc,
  1566. SourceLocation StartLoc,
  1567. SourceLocation LParenLoc,
  1568. SourceLocation EndLoc) {
  1569. return getSema().ActOnOpenMPLastprivateClause(
  1570. VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
  1571. }
  1572. /// Build a new OpenMP 'shared' clause.
  1573. ///
  1574. /// By default, performs semantic analysis to build the new OpenMP clause.
  1575. /// Subclasses may override this routine to provide different behavior.
  1576. OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
  1577. SourceLocation StartLoc,
  1578. SourceLocation LParenLoc,
  1579. SourceLocation EndLoc) {
  1580. return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
  1581. EndLoc);
  1582. }
  1583. /// Build a new OpenMP 'reduction' clause.
  1584. ///
  1585. /// By default, performs semantic analysis to build the new statement.
  1586. /// Subclasses may override this routine to provide different behavior.
  1587. OMPClause *RebuildOMPReductionClause(
  1588. ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier,
  1589. SourceLocation StartLoc, SourceLocation LParenLoc,
  1590. SourceLocation ModifierLoc, SourceLocation ColonLoc,
  1591. SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
  1592. const DeclarationNameInfo &ReductionId,
  1593. ArrayRef<Expr *> UnresolvedReductions) {
  1594. return getSema().ActOnOpenMPReductionClause(
  1595. VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
  1596. ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
  1597. }
  1598. /// Build a new OpenMP 'task_reduction' clause.
  1599. ///
  1600. /// By default, performs semantic analysis to build the new statement.
  1601. /// Subclasses may override this routine to provide different behavior.
  1602. OMPClause *RebuildOMPTaskReductionClause(
  1603. ArrayRef<Expr *> VarList, SourceLocation StartLoc,
  1604. SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
  1605. CXXScopeSpec &ReductionIdScopeSpec,
  1606. const DeclarationNameInfo &ReductionId,
  1607. ArrayRef<Expr *> UnresolvedReductions) {
  1608. return getSema().ActOnOpenMPTaskReductionClause(
  1609. VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
  1610. ReductionId, UnresolvedReductions);
  1611. }
  1612. /// Build a new OpenMP 'in_reduction' clause.
  1613. ///
  1614. /// By default, performs semantic analysis to build the new statement.
  1615. /// Subclasses may override this routine to provide different behavior.
  1616. OMPClause *
  1617. RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc,
  1618. SourceLocation LParenLoc, SourceLocation ColonLoc,
  1619. SourceLocation EndLoc,
  1620. CXXScopeSpec &ReductionIdScopeSpec,
  1621. const DeclarationNameInfo &ReductionId,
  1622. ArrayRef<Expr *> UnresolvedReductions) {
  1623. return getSema().ActOnOpenMPInReductionClause(
  1624. VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
  1625. ReductionId, UnresolvedReductions);
  1626. }
  1627. /// Build a new OpenMP 'linear' clause.
  1628. ///
  1629. /// By default, performs semantic analysis to build the new OpenMP clause.
  1630. /// Subclasses may override this routine to provide different behavior.
  1631. OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
  1632. SourceLocation StartLoc,
  1633. SourceLocation LParenLoc,
  1634. OpenMPLinearClauseKind Modifier,
  1635. SourceLocation ModifierLoc,
  1636. SourceLocation ColonLoc,
  1637. SourceLocation EndLoc) {
  1638. return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
  1639. Modifier, ModifierLoc, ColonLoc,
  1640. EndLoc);
  1641. }
  1642. /// Build a new OpenMP 'aligned' clause.
  1643. ///
  1644. /// By default, performs semantic analysis to build the new OpenMP clause.
  1645. /// Subclasses may override this routine to provide different behavior.
  1646. OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
  1647. SourceLocation StartLoc,
  1648. SourceLocation LParenLoc,
  1649. SourceLocation ColonLoc,
  1650. SourceLocation EndLoc) {
  1651. return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
  1652. LParenLoc, ColonLoc, EndLoc);
  1653. }
  1654. /// Build a new OpenMP 'copyin' clause.
  1655. ///
  1656. /// By default, performs semantic analysis to build the new OpenMP clause.
  1657. /// Subclasses may override this routine to provide different behavior.
  1658. OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
  1659. SourceLocation StartLoc,
  1660. SourceLocation LParenLoc,
  1661. SourceLocation EndLoc) {
  1662. return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
  1663. EndLoc);
  1664. }
  1665. /// Build a new OpenMP 'copyprivate' clause.
  1666. ///
  1667. /// By default, performs semantic analysis to build the new OpenMP clause.
  1668. /// Subclasses may override this routine to provide different behavior.
  1669. OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
  1670. SourceLocation StartLoc,
  1671. SourceLocation LParenLoc,
  1672. SourceLocation EndLoc) {
  1673. return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
  1674. EndLoc);
  1675. }
  1676. /// Build a new OpenMP 'flush' pseudo clause.
  1677. ///
  1678. /// By default, performs semantic analysis to build the new OpenMP clause.
  1679. /// Subclasses may override this routine to provide different behavior.
  1680. OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
  1681. SourceLocation StartLoc,
  1682. SourceLocation LParenLoc,
  1683. SourceLocation EndLoc) {
  1684. return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
  1685. EndLoc);
  1686. }
  1687. /// Build a new OpenMP 'depobj' pseudo clause.
  1688. ///
  1689. /// By default, performs semantic analysis to build the new OpenMP clause.
  1690. /// Subclasses may override this routine to provide different behavior.
  1691. OMPClause *RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc,
  1692. SourceLocation LParenLoc,
  1693. SourceLocation EndLoc) {
  1694. return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc,
  1695. EndLoc);
  1696. }
  1697. /// Build a new OpenMP 'depend' pseudo clause.
  1698. ///
  1699. /// By default, performs semantic analysis to build the new OpenMP clause.
  1700. /// Subclasses may override this routine to provide different behavior.
  1701. OMPClause *
  1702. RebuildOMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind,
  1703. SourceLocation DepLoc, SourceLocation ColonLoc,
  1704. ArrayRef<Expr *> VarList, SourceLocation StartLoc,
  1705. SourceLocation LParenLoc, SourceLocation EndLoc) {
  1706. return getSema().ActOnOpenMPDependClause(DepModifier, DepKind, DepLoc,
  1707. ColonLoc, VarList, StartLoc,
  1708. LParenLoc, EndLoc);
  1709. }
  1710. /// Build a new OpenMP 'device' clause.
  1711. ///
  1712. /// By default, performs semantic analysis to build the new statement.
  1713. /// Subclasses may override this routine to provide different behavior.
  1714. OMPClause *RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier,
  1715. Expr *Device, SourceLocation StartLoc,
  1716. SourceLocation LParenLoc,
  1717. SourceLocation ModifierLoc,
  1718. SourceLocation EndLoc) {
  1719. return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc,
  1720. LParenLoc, ModifierLoc, EndLoc);
  1721. }
  1722. /// Build a new OpenMP 'map' clause.
  1723. ///
  1724. /// By default, performs semantic analysis to build the new OpenMP clause.
  1725. /// Subclasses may override this routine to provide different behavior.
  1726. OMPClause *RebuildOMPMapClause(
  1727. ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
  1728. ArrayRef<SourceLocation> MapTypeModifiersLoc,
  1729. CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
  1730. OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
  1731. SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
  1732. const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
  1733. return getSema().ActOnOpenMPMapClause(
  1734. MapTypeModifiers, MapTypeModifiersLoc, MapperIdScopeSpec, MapperId,
  1735. MapType, IsMapTypeImplicit, MapLoc, ColonLoc, VarList, Locs,
  1736. /*NoDiagnose=*/false, UnresolvedMappers);
  1737. }
  1738. /// Build a new OpenMP 'allocate' clause.
  1739. ///
  1740. /// By default, performs semantic analysis to build the new OpenMP clause.
  1741. /// Subclasses may override this routine to provide different behavior.
  1742. OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList,
  1743. SourceLocation StartLoc,
  1744. SourceLocation LParenLoc,
  1745. SourceLocation ColonLoc,
  1746. SourceLocation EndLoc) {
  1747. return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
  1748. LParenLoc, ColonLoc, EndLoc);
  1749. }
  1750. /// Build a new OpenMP 'num_teams' clause.
  1751. ///
  1752. /// By default, performs semantic analysis to build the new statement.
  1753. /// Subclasses may override this routine to provide different behavior.
  1754. OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc,
  1755. SourceLocation LParenLoc,
  1756. SourceLocation EndLoc) {
  1757. return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
  1758. EndLoc);
  1759. }
  1760. /// Build a new OpenMP 'thread_limit' clause.
  1761. ///
  1762. /// By default, performs semantic analysis to build the new statement.
  1763. /// Subclasses may override this routine to provide different behavior.
  1764. OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit,
  1765. SourceLocation StartLoc,
  1766. SourceLocation LParenLoc,
  1767. SourceLocation EndLoc) {
  1768. return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
  1769. LParenLoc, EndLoc);
  1770. }
  1771. /// Build a new OpenMP 'priority' clause.
  1772. ///
  1773. /// By default, performs semantic analysis to build the new statement.
  1774. /// Subclasses may override this routine to provide different behavior.
  1775. OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc,
  1776. SourceLocation LParenLoc,
  1777. SourceLocation EndLoc) {
  1778. return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
  1779. EndLoc);
  1780. }
  1781. /// Build a new OpenMP 'grainsize' clause.
  1782. ///
  1783. /// By default, performs semantic analysis to build the new statement.
  1784. /// Subclasses may override this routine to provide different behavior.
  1785. OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc,
  1786. SourceLocation LParenLoc,
  1787. SourceLocation EndLoc) {
  1788. return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc,
  1789. EndLoc);
  1790. }
  1791. /// Build a new OpenMP 'num_tasks' clause.
  1792. ///
  1793. /// By default, performs semantic analysis to build the new statement.
  1794. /// Subclasses may override this routine to provide different behavior.
  1795. OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc,
  1796. SourceLocation LParenLoc,
  1797. SourceLocation EndLoc) {
  1798. return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc,
  1799. EndLoc);
  1800. }
  1801. /// Build a new OpenMP 'hint' clause.
  1802. ///
  1803. /// By default, performs semantic analysis to build the new statement.
  1804. /// Subclasses may override this routine to provide different behavior.
  1805. OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc,
  1806. SourceLocation LParenLoc,
  1807. SourceLocation EndLoc) {
  1808. return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
  1809. }
  1810. /// Build a new OpenMP 'detach' clause.
  1811. ///
  1812. /// By default, performs semantic analysis to build the new statement.
  1813. /// Subclasses may override this routine to provide different behavior.
  1814. OMPClause *RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc,
  1815. SourceLocation LParenLoc,
  1816. SourceLocation EndLoc) {
  1817. return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc);
  1818. }
  1819. /// Build a new OpenMP 'dist_schedule' clause.
  1820. ///
  1821. /// By default, performs semantic analysis to build the new OpenMP clause.
  1822. /// Subclasses may override this routine to provide different behavior.
  1823. OMPClause *
  1824. RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind,
  1825. Expr *ChunkSize, SourceLocation StartLoc,
  1826. SourceLocation LParenLoc, SourceLocation KindLoc,
  1827. SourceLocation CommaLoc, SourceLocation EndLoc) {
  1828. return getSema().ActOnOpenMPDistScheduleClause(
  1829. Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
  1830. }
  1831. /// Build a new OpenMP 'to' clause.
  1832. ///
  1833. /// By default, performs semantic analysis to build the new statement.
  1834. /// Subclasses may override this routine to provide different behavior.
  1835. OMPClause *
  1836. RebuildOMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
  1837. ArrayRef<SourceLocation> MotionModifiersLoc,
  1838. CXXScopeSpec &MapperIdScopeSpec,
  1839. DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
  1840. ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
  1841. ArrayRef<Expr *> UnresolvedMappers) {
  1842. return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc,
  1843. MapperIdScopeSpec, MapperId, ColonLoc,
  1844. VarList, Locs, UnresolvedMappers);
  1845. }
  1846. /// Build a new OpenMP 'from' clause.
  1847. ///
  1848. /// By default, performs semantic analysis to build the new statement.
  1849. /// Subclasses may override this routine to provide different behavior.
  1850. OMPClause *
  1851. RebuildOMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers,
  1852. ArrayRef<SourceLocation> MotionModifiersLoc,
  1853. CXXScopeSpec &MapperIdScopeSpec,
  1854. DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
  1855. ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
  1856. ArrayRef<Expr *> UnresolvedMappers) {
  1857. return getSema().ActOnOpenMPFromClause(
  1858. MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
  1859. ColonLoc, VarList, Locs, UnresolvedMappers);
  1860. }
  1861. /// Build a new OpenMP 'use_device_ptr' clause.
  1862. ///
  1863. /// By default, performs semantic analysis to build the new OpenMP clause.
  1864. /// Subclasses may override this routine to provide different behavior.
  1865. OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList,
  1866. const OMPVarListLocTy &Locs) {
  1867. return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
  1868. }
  1869. /// Build a new OpenMP 'use_device_addr' clause.
  1870. ///
  1871. /// By default, performs semantic analysis to build the new OpenMP clause.
  1872. /// Subclasses may override this routine to provide different behavior.
  1873. OMPClause *RebuildOMPUseDeviceAddrClause(ArrayRef<Expr *> VarList,
  1874. const OMPVarListLocTy &Locs) {
  1875. return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
  1876. }
  1877. /// Build a new OpenMP 'is_device_ptr' clause.
  1878. ///
  1879. /// By default, performs semantic analysis to build the new OpenMP clause.
  1880. /// Subclasses may override this routine to provide different behavior.
  1881. OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList,
  1882. const OMPVarListLocTy &Locs) {
  1883. return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
  1884. }
  1885. /// Build a new OpenMP 'defaultmap' clause.
  1886. ///
  1887. /// By default, performs semantic analysis to build the new OpenMP clause.
  1888. /// Subclasses may override this routine to provide different behavior.
  1889. OMPClause *RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M,
  1890. OpenMPDefaultmapClauseKind Kind,
  1891. SourceLocation StartLoc,
  1892. SourceLocation LParenLoc,
  1893. SourceLocation MLoc,
  1894. SourceLocation KindLoc,
  1895. SourceLocation EndLoc) {
  1896. return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc,
  1897. MLoc, KindLoc, EndLoc);
  1898. }
  1899. /// Build a new OpenMP 'nontemporal' clause.
  1900. ///
  1901. /// By default, performs semantic analysis to build the new OpenMP clause.
  1902. /// Subclasses may override this routine to provide different behavior.
  1903. OMPClause *RebuildOMPNontemporalClause(ArrayRef<Expr *> VarList,
  1904. SourceLocation StartLoc,
  1905. SourceLocation LParenLoc,
  1906. SourceLocation EndLoc) {
  1907. return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc,
  1908. EndLoc);
  1909. }
  1910. /// Build a new OpenMP 'inclusive' clause.
  1911. ///
  1912. /// By default, performs semantic analysis to build the new OpenMP clause.
  1913. /// Subclasses may override this routine to provide different behavior.
  1914. OMPClause *RebuildOMPInclusiveClause(ArrayRef<Expr *> VarList,
  1915. SourceLocation StartLoc,
  1916. SourceLocation LParenLoc,
  1917. SourceLocation EndLoc) {
  1918. return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc,
  1919. EndLoc);
  1920. }
  1921. /// Build a new OpenMP 'exclusive' clause.
  1922. ///
  1923. /// By default, performs semantic analysis to build the new OpenMP clause.
  1924. /// Subclasses may override this routine to provide different behavior.
  1925. OMPClause *RebuildOMPExclusiveClause(ArrayRef<Expr *> VarList,
  1926. SourceLocation StartLoc,
  1927. SourceLocation LParenLoc,
  1928. SourceLocation EndLoc) {
  1929. return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc,
  1930. EndLoc);
  1931. }
  1932. /// Build a new OpenMP 'uses_allocators' clause.
  1933. ///
  1934. /// By default, performs semantic analysis to build the new OpenMP clause.
  1935. /// Subclasses may override this routine to provide different behavior.
  1936. OMPClause *RebuildOMPUsesAllocatorsClause(
  1937. ArrayRef<Sema::UsesAllocatorsData> Data, SourceLocation StartLoc,
  1938. SourceLocation LParenLoc, SourceLocation EndLoc) {
  1939. return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc,
  1940. Data);
  1941. }
  1942. /// Build a new OpenMP 'affinity' clause.
  1943. ///
  1944. /// By default, performs semantic analysis to build the new OpenMP clause.
  1945. /// Subclasses may override this routine to provide different behavior.
  1946. OMPClause *RebuildOMPAffinityClause(SourceLocation StartLoc,
  1947. SourceLocation LParenLoc,
  1948. SourceLocation ColonLoc,
  1949. SourceLocation EndLoc, Expr *Modifier,
  1950. ArrayRef<Expr *> Locators) {
  1951. return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc,
  1952. EndLoc, Modifier, Locators);
  1953. }
  1954. /// Build a new OpenMP 'order' clause.
  1955. ///
  1956. /// By default, performs semantic analysis to build the new OpenMP clause.
  1957. /// Subclasses may override this routine to provide different behavior.
  1958. OMPClause *RebuildOMPOrderClause(OpenMPOrderClauseKind Kind,
  1959. SourceLocation KindKwLoc,
  1960. SourceLocation StartLoc,
  1961. SourceLocation LParenLoc,
  1962. SourceLocation EndLoc) {
  1963. return getSema().ActOnOpenMPOrderClause(Kind, KindKwLoc, StartLoc,
  1964. LParenLoc, EndLoc);
  1965. }
  1966. /// Build a new OpenMP 'init' clause.
  1967. ///
  1968. /// By default, performs semantic analysis to build the new OpenMP clause.
  1969. /// Subclasses may override this routine to provide different behavior.
  1970. OMPClause *RebuildOMPInitClause(Expr *InteropVar, ArrayRef<Expr *> PrefExprs,
  1971. bool IsTarget, bool IsTargetSync,
  1972. SourceLocation StartLoc,
  1973. SourceLocation LParenLoc,
  1974. SourceLocation VarLoc,
  1975. SourceLocation EndLoc) {
  1976. return getSema().ActOnOpenMPInitClause(InteropVar, PrefExprs, IsTarget,
  1977. IsTargetSync, StartLoc, LParenLoc,
  1978. VarLoc, EndLoc);
  1979. }
  1980. /// Build a new OpenMP 'use' clause.
  1981. ///
  1982. /// By default, performs semantic analysis to build the new OpenMP clause.
  1983. /// Subclasses may override this routine to provide different behavior.
  1984. OMPClause *RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc,
  1985. SourceLocation LParenLoc,
  1986. SourceLocation VarLoc, SourceLocation EndLoc) {
  1987. return getSema().ActOnOpenMPUseClause(InteropVar, StartLoc, LParenLoc,
  1988. VarLoc, EndLoc);
  1989. }
  1990. /// Build a new OpenMP 'destroy' clause.
  1991. ///
  1992. /// By default, performs semantic analysis to build the new OpenMP clause.
  1993. /// Subclasses may override this routine to provide different behavior.
  1994. OMPClause *RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc,
  1995. SourceLocation LParenLoc,
  1996. SourceLocation VarLoc,
  1997. SourceLocation EndLoc) {
  1998. return getSema().ActOnOpenMPDestroyClause(InteropVar, StartLoc, LParenLoc,
  1999. VarLoc, EndLoc);
  2000. }
  2001. /// Build a new OpenMP 'novariants' clause.
  2002. ///
  2003. /// By default, performs semantic analysis to build the new OpenMP clause.
  2004. /// Subclasses may override this routine to provide different behavior.
  2005. OMPClause *RebuildOMPNovariantsClause(Expr *Condition,
  2006. SourceLocation StartLoc,
  2007. SourceLocation LParenLoc,
  2008. SourceLocation EndLoc) {
  2009. return getSema().ActOnOpenMPNovariantsClause(Condition, StartLoc, LParenLoc,
  2010. EndLoc);
  2011. }
  2012. /// Build a new OpenMP 'nocontext' clause.
  2013. ///
  2014. /// By default, performs semantic analysis to build the new OpenMP clause.
  2015. /// Subclasses may override this routine to provide different behavior.
  2016. OMPClause *RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc,
  2017. SourceLocation LParenLoc,
  2018. SourceLocation EndLoc) {
  2019. return getSema().ActOnOpenMPNocontextClause(Condition, StartLoc, LParenLoc,
  2020. EndLoc);
  2021. }
  2022. /// Build a new OpenMP 'filter' clause.
  2023. ///
  2024. /// By default, performs semantic analysis to build the new OpenMP clause.
  2025. /// Subclasses may override this routine to provide different behavior.
  2026. OMPClause *RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc,
  2027. SourceLocation LParenLoc,
  2028. SourceLocation EndLoc) {
  2029. return getSema().ActOnOpenMPFilterClause(ThreadID, StartLoc, LParenLoc,
  2030. EndLoc);
  2031. }
  2032. /// Build a new OpenMP 'bind' clause.
  2033. ///
  2034. /// By default, performs semantic analysis to build the new OpenMP clause.
  2035. /// Subclasses may override this routine to provide different behavior.
  2036. OMPClause *RebuildOMPBindClause(OpenMPBindClauseKind Kind,
  2037. SourceLocation KindLoc,
  2038. SourceLocation StartLoc,
  2039. SourceLocation LParenLoc,
  2040. SourceLocation EndLoc) {
  2041. return getSema().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc, LParenLoc,
  2042. EndLoc);
  2043. }
  2044. /// Build a new OpenMP 'align' clause.
  2045. ///
  2046. /// By default, performs semantic analysis to build the new OpenMP clause.
  2047. /// Subclasses may override this routine to provide different behavior.
  2048. OMPClause *RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc,
  2049. SourceLocation LParenLoc,
  2050. SourceLocation EndLoc) {
  2051. return getSema().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc, EndLoc);
  2052. }
  2053. /// Rebuild the operand to an Objective-C \@synchronized statement.
  2054. ///
  2055. /// By default, performs semantic analysis to build the new statement.
  2056. /// Subclasses may override this routine to provide different behavior.
  2057. ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
  2058. Expr *object) {
  2059. return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
  2060. }
  2061. /// Build a new Objective-C \@synchronized statement.
  2062. ///
  2063. /// By default, performs semantic analysis to build the new statement.
  2064. /// Subclasses may override this routine to provide different behavior.
  2065. StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
  2066. Expr *Object, Stmt *Body) {
  2067. return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
  2068. }
  2069. /// Build a new Objective-C \@autoreleasepool statement.
  2070. ///
  2071. /// By default, performs semantic analysis to build the new statement.
  2072. /// Subclasses may override this routine to provide different behavior.
  2073. StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
  2074. Stmt *Body) {
  2075. return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
  2076. }
  2077. /// Build a new Objective-C fast enumeration statement.
  2078. ///
  2079. /// By default, performs semantic analysis to build the new statement.
  2080. /// Subclasses may override this routine to provide different behavior.
  2081. StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
  2082. Stmt *Element,
  2083. Expr *Collection,
  2084. SourceLocation RParenLoc,
  2085. Stmt *Body) {
  2086. StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
  2087. Element,
  2088. Collection,
  2089. RParenLoc);
  2090. if (ForEachStmt.isInvalid())
  2091. return StmtError();
  2092. return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
  2093. }
  2094. /// Build a new C++ exception declaration.
  2095. ///
  2096. /// By default, performs semantic analysis to build the new decaration.
  2097. /// Subclasses may override this routine to provide different behavior.
  2098. VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
  2099. TypeSourceInfo *Declarator,
  2100. SourceLocation StartLoc,
  2101. SourceLocation IdLoc,
  2102. IdentifierInfo *Id) {
  2103. VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
  2104. StartLoc, IdLoc, Id);
  2105. if (Var)
  2106. getSema().CurContext->addDecl(Var);
  2107. return Var;
  2108. }
  2109. /// Build a new C++ catch statement.
  2110. ///
  2111. /// By default, performs semantic analysis to build the new statement.
  2112. /// Subclasses may override this routine to provide different behavior.
  2113. StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
  2114. VarDecl *ExceptionDecl,
  2115. Stmt *Handler) {
  2116. return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
  2117. Handler));
  2118. }
  2119. /// Build a new C++ try statement.
  2120. ///
  2121. /// By default, performs semantic analysis to build the new statement.
  2122. /// Subclasses may override this routine to provide different behavior.
  2123. StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
  2124. ArrayRef<Stmt *> Handlers) {
  2125. return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
  2126. }
  2127. /// Build a new C++0x range-based for statement.
  2128. ///
  2129. /// By default, performs semantic analysis to build the new statement.
  2130. /// Subclasses may override this routine to provide different behavior.
  2131. StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
  2132. SourceLocation CoawaitLoc, Stmt *Init,
  2133. SourceLocation ColonLoc, Stmt *Range,
  2134. Stmt *Begin, Stmt *End, Expr *Cond,
  2135. Expr *Inc, Stmt *LoopVar,
  2136. SourceLocation RParenLoc) {
  2137. // If we've just learned that the range is actually an Objective-C
  2138. // collection, treat this as an Objective-C fast enumeration loop.
  2139. if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
  2140. if (RangeStmt->isSingleDecl()) {
  2141. if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
  2142. if (RangeVar->isInvalidDecl())
  2143. return StmtError();
  2144. Expr *RangeExpr = RangeVar->getInit();
  2145. if (!RangeExpr->isTypeDependent() &&
  2146. RangeExpr->getType()->isObjCObjectPointerType()) {
  2147. // FIXME: Support init-statements in Objective-C++20 ranged for
  2148. // statement.
  2149. if (Init) {
  2150. return SemaRef.Diag(Init->getBeginLoc(),
  2151. diag::err_objc_for_range_init_stmt)
  2152. << Init->getSourceRange();
  2153. }
  2154. return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
  2155. RangeExpr, RParenLoc);
  2156. }
  2157. }
  2158. }
  2159. }
  2160. return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc,
  2161. Range, Begin, End, Cond, Inc, LoopVar,
  2162. RParenLoc, Sema::BFRK_Rebuild);
  2163. }
  2164. /// Build a new C++0x range-based for statement.
  2165. ///
  2166. /// By default, performs semantic analysis to build the new statement.
  2167. /// Subclasses may override this routine to provide different behavior.
  2168. StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
  2169. bool IsIfExists,
  2170. NestedNameSpecifierLoc QualifierLoc,
  2171. DeclarationNameInfo NameInfo,
  2172. Stmt *Nested) {
  2173. return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
  2174. QualifierLoc, NameInfo, Nested);
  2175. }
  2176. /// Attach body to a C++0x range-based for statement.
  2177. ///
  2178. /// By default, performs semantic analysis to finish the new statement.
  2179. /// Subclasses may override this routine to provide different behavior.
  2180. StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
  2181. return getSema().FinishCXXForRangeStmt(ForRange, Body);
  2182. }
  2183. StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
  2184. Stmt *TryBlock, Stmt *Handler) {
  2185. return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
  2186. }
  2187. StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
  2188. Stmt *Block) {
  2189. return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
  2190. }
  2191. StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
  2192. return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
  2193. }
  2194. ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc,
  2195. SourceLocation LParen,
  2196. SourceLocation RParen,
  2197. TypeSourceInfo *TSI) {
  2198. return getSema().BuildSYCLUniqueStableNameExpr(OpLoc, LParen, RParen, TSI);
  2199. }
  2200. /// Build a new predefined expression.
  2201. ///
  2202. /// By default, performs semantic analysis to build the new expression.
  2203. /// Subclasses may override this routine to provide different behavior.
  2204. ExprResult RebuildPredefinedExpr(SourceLocation Loc,
  2205. PredefinedExpr::IdentKind IK) {
  2206. return getSema().BuildPredefinedExpr(Loc, IK);
  2207. }
  2208. /// Build a new expression that references a declaration.
  2209. ///
  2210. /// By default, performs semantic analysis to build the new expression.
  2211. /// Subclasses may override this routine to provide different behavior.
  2212. ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
  2213. LookupResult &R,
  2214. bool RequiresADL) {
  2215. return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
  2216. }
  2217. /// Build a new expression that references a declaration.
  2218. ///
  2219. /// By default, performs semantic analysis to build the new expression.
  2220. /// Subclasses may override this routine to provide different behavior.
  2221. ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
  2222. ValueDecl *VD,
  2223. const DeclarationNameInfo &NameInfo,
  2224. NamedDecl *Found,
  2225. TemplateArgumentListInfo *TemplateArgs) {
  2226. CXXScopeSpec SS;
  2227. SS.Adopt(QualifierLoc);
  2228. return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
  2229. TemplateArgs);
  2230. }
  2231. /// Build a new expression in parentheses.
  2232. ///
  2233. /// By default, performs semantic analysis to build the new expression.
  2234. /// Subclasses may override this routine to provide different behavior.
  2235. ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
  2236. SourceLocation RParen) {
  2237. return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
  2238. }
  2239. /// Build a new pseudo-destructor expression.
  2240. ///
  2241. /// By default, performs semantic analysis to build the new expression.
  2242. /// Subclasses may override this routine to provide different behavior.
  2243. ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
  2244. SourceLocation OperatorLoc,
  2245. bool isArrow,
  2246. CXXScopeSpec &SS,
  2247. TypeSourceInfo *ScopeType,
  2248. SourceLocation CCLoc,
  2249. SourceLocation TildeLoc,
  2250. PseudoDestructorTypeStorage Destroyed);
  2251. /// Build a new unary operator expression.
  2252. ///
  2253. /// By default, performs semantic analysis to build the new expression.
  2254. /// Subclasses may override this routine to provide different behavior.
  2255. ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
  2256. UnaryOperatorKind Opc,
  2257. Expr *SubExpr) {
  2258. return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
  2259. }
  2260. /// Build a new builtin offsetof expression.
  2261. ///
  2262. /// By default, performs semantic analysis to build the new expression.
  2263. /// Subclasses may override this routine to provide different behavior.
  2264. ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
  2265. TypeSourceInfo *Type,
  2266. ArrayRef<Sema::OffsetOfComponent> Components,
  2267. SourceLocation RParenLoc) {
  2268. return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
  2269. RParenLoc);
  2270. }
  2271. /// Build a new sizeof, alignof or vec_step expression with a
  2272. /// type argument.
  2273. ///
  2274. /// By default, performs semantic analysis to build the new expression.
  2275. /// Subclasses may override this routine to provide different behavior.
  2276. ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
  2277. SourceLocation OpLoc,
  2278. UnaryExprOrTypeTrait ExprKind,
  2279. SourceRange R) {
  2280. return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
  2281. }
  2282. /// Build a new sizeof, alignof or vec step expression with an
  2283. /// expression argument.
  2284. ///
  2285. /// By default, performs semantic analysis to build the new expression.
  2286. /// Subclasses may override this routine to provide different behavior.
  2287. ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
  2288. UnaryExprOrTypeTrait ExprKind,
  2289. SourceRange R) {
  2290. ExprResult Result
  2291. = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
  2292. if (Result.isInvalid())
  2293. return ExprError();
  2294. return Result;
  2295. }
  2296. /// Build a new array subscript expression.
  2297. ///
  2298. /// By default, performs semantic analysis to build the new expression.
  2299. /// Subclasses may override this routine to provide different behavior.
  2300. ExprResult RebuildArraySubscriptExpr(Expr *LHS,
  2301. SourceLocation LBracketLoc,
  2302. Expr *RHS,
  2303. SourceLocation RBracketLoc) {
  2304. return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
  2305. LBracketLoc, RHS,
  2306. RBracketLoc);
  2307. }
  2308. /// Build a new matrix subscript expression.
  2309. ///
  2310. /// By default, performs semantic analysis to build the new expression.
  2311. /// Subclasses may override this routine to provide different behavior.
  2312. ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx,
  2313. Expr *ColumnIdx,
  2314. SourceLocation RBracketLoc) {
  2315. return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
  2316. RBracketLoc);
  2317. }
  2318. /// Build a new array section expression.
  2319. ///
  2320. /// By default, performs semantic analysis to build the new expression.
  2321. /// Subclasses may override this routine to provide different behavior.
  2322. ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
  2323. Expr *LowerBound,
  2324. SourceLocation ColonLocFirst,
  2325. SourceLocation ColonLocSecond,
  2326. Expr *Length, Expr *Stride,
  2327. SourceLocation RBracketLoc) {
  2328. return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
  2329. ColonLocFirst, ColonLocSecond,
  2330. Length, Stride, RBracketLoc);
  2331. }
  2332. /// Build a new array shaping expression.
  2333. ///
  2334. /// By default, performs semantic analysis to build the new expression.
  2335. /// Subclasses may override this routine to provide different behavior.
  2336. ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc,
  2337. SourceLocation RParenLoc,
  2338. ArrayRef<Expr *> Dims,
  2339. ArrayRef<SourceRange> BracketsRanges) {
  2340. return getSema().ActOnOMPArrayShapingExpr(Base, LParenLoc, RParenLoc, Dims,
  2341. BracketsRanges);
  2342. }
  2343. /// Build a new iterator expression.
  2344. ///
  2345. /// By default, performs semantic analysis to build the new expression.
  2346. /// Subclasses may override this routine to provide different behavior.
  2347. ExprResult RebuildOMPIteratorExpr(
  2348. SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc,
  2349. ArrayRef<Sema::OMPIteratorData> Data) {
  2350. return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc,
  2351. LLoc, RLoc, Data);
  2352. }
  2353. /// Build a new call expression.
  2354. ///
  2355. /// By default, performs semantic analysis to build the new expression.
  2356. /// Subclasses may override this routine to provide different behavior.
  2357. ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
  2358. MultiExprArg Args,
  2359. SourceLocation RParenLoc,
  2360. Expr *ExecConfig = nullptr) {
  2361. return getSema().ActOnCallExpr(
  2362. /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
  2363. }
  2364. /// Build a new member access expression.
  2365. ///
  2366. /// By default, performs semantic analysis to build the new expression.
  2367. /// Subclasses may override this routine to provide different behavior.
  2368. ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
  2369. bool isArrow,
  2370. NestedNameSpecifierLoc QualifierLoc,
  2371. SourceLocation TemplateKWLoc,
  2372. const DeclarationNameInfo &MemberNameInfo,
  2373. ValueDecl *Member,
  2374. NamedDecl *FoundDecl,
  2375. const TemplateArgumentListInfo *ExplicitTemplateArgs,
  2376. NamedDecl *FirstQualifierInScope) {
  2377. ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
  2378. isArrow);
  2379. if (!Member->getDeclName()) {
  2380. // We have a reference to an unnamed field. This is always the
  2381. // base of an anonymous struct/union member access, i.e. the
  2382. // field is always of record type.
  2383. assert(Member->getType()->isRecordType() &&
  2384. "unnamed member not of record type?");
  2385. BaseResult =
  2386. getSema().PerformObjectMemberConversion(BaseResult.get(),
  2387. QualifierLoc.getNestedNameSpecifier(),
  2388. FoundDecl, Member);
  2389. if (BaseResult.isInvalid())
  2390. return ExprError();
  2391. Base = BaseResult.get();
  2392. CXXScopeSpec EmptySS;
  2393. return getSema().BuildFieldReferenceExpr(
  2394. Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
  2395. DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
  2396. }
  2397. CXXScopeSpec SS;
  2398. SS.Adopt(QualifierLoc);
  2399. Base = BaseResult.get();
  2400. QualType BaseType = Base->getType();
  2401. if (isArrow && !BaseType->isPointerType())
  2402. return ExprError();
  2403. // FIXME: this involves duplicating earlier analysis in a lot of
  2404. // cases; we should avoid this when possible.
  2405. LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
  2406. R.addDecl(FoundDecl);
  2407. R.resolveKind();
  2408. return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
  2409. SS, TemplateKWLoc,
  2410. FirstQualifierInScope,
  2411. R, ExplicitTemplateArgs,
  2412. /*S*/nullptr);
  2413. }
  2414. /// Build a new binary operator expression.
  2415. ///
  2416. /// By default, performs semantic analysis to build the new expression.
  2417. /// Subclasses may override this routine to provide different behavior.
  2418. ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
  2419. BinaryOperatorKind Opc,
  2420. Expr *LHS, Expr *RHS) {
  2421. return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
  2422. }
  2423. /// Build a new rewritten operator expression.
  2424. ///
  2425. /// By default, performs semantic analysis to build the new expression.
  2426. /// Subclasses may override this routine to provide different behavior.
  2427. ExprResult RebuildCXXRewrittenBinaryOperator(
  2428. SourceLocation OpLoc, BinaryOperatorKind Opcode,
  2429. const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
  2430. return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
  2431. RHS, /*RequiresADL*/false);
  2432. }
  2433. /// Build a new conditional operator expression.
  2434. ///
  2435. /// By default, performs semantic analysis to build the new expression.
  2436. /// Subclasses may override this routine to provide different behavior.
  2437. ExprResult RebuildConditionalOperator(Expr *Cond,
  2438. SourceLocation QuestionLoc,
  2439. Expr *LHS,
  2440. SourceLocation ColonLoc,
  2441. Expr *RHS) {
  2442. return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
  2443. LHS, RHS);
  2444. }
  2445. /// Build a new C-style cast expression.
  2446. ///
  2447. /// By default, performs semantic analysis to build the new expression.
  2448. /// Subclasses may override this routine to provide different behavior.
  2449. ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
  2450. TypeSourceInfo *TInfo,
  2451. SourceLocation RParenLoc,
  2452. Expr *SubExpr) {
  2453. return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
  2454. SubExpr);
  2455. }
  2456. /// Build a new compound literal expression.
  2457. ///
  2458. /// By default, performs semantic analysis to build the new expression.
  2459. /// Subclasses may override this routine to provide different behavior.
  2460. ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
  2461. TypeSourceInfo *TInfo,
  2462. SourceLocation RParenLoc,
  2463. Expr *Init) {
  2464. return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
  2465. Init);
  2466. }
  2467. /// Build a new extended vector element access expression.
  2468. ///
  2469. /// By default, performs semantic analysis to build the new expression.
  2470. /// Subclasses may override this routine to provide different behavior.
  2471. ExprResult RebuildExtVectorElementExpr(Expr *Base,
  2472. SourceLocation OpLoc,
  2473. SourceLocation AccessorLoc,
  2474. IdentifierInfo &Accessor) {
  2475. CXXScopeSpec SS;
  2476. DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
  2477. return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
  2478. OpLoc, /*IsArrow*/ false,
  2479. SS, SourceLocation(),
  2480. /*FirstQualifierInScope*/ nullptr,
  2481. NameInfo,
  2482. /* TemplateArgs */ nullptr,
  2483. /*S*/ nullptr);
  2484. }
  2485. /// Build a new initializer list expression.
  2486. ///
  2487. /// By default, performs semantic analysis to build the new expression.
  2488. /// Subclasses may override this routine to provide different behavior.
  2489. ExprResult RebuildInitList(SourceLocation LBraceLoc,
  2490. MultiExprArg Inits,
  2491. SourceLocation RBraceLoc) {
  2492. return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
  2493. }
  2494. /// Build a new designated initializer expression.
  2495. ///
  2496. /// By default, performs semantic analysis to build the new expression.
  2497. /// Subclasses may override this routine to provide different behavior.
  2498. ExprResult RebuildDesignatedInitExpr(Designation &Desig,
  2499. MultiExprArg ArrayExprs,
  2500. SourceLocation EqualOrColonLoc,
  2501. bool GNUSyntax,
  2502. Expr *Init) {
  2503. ExprResult Result
  2504. = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
  2505. Init);
  2506. if (Result.isInvalid())
  2507. return ExprError();
  2508. return Result;
  2509. }
  2510. /// Build a new value-initialized expression.
  2511. ///
  2512. /// By default, builds the implicit value initialization without performing
  2513. /// any semantic analysis. Subclasses may override this routine to provide
  2514. /// different behavior.
  2515. ExprResult RebuildImplicitValueInitExpr(QualType T) {
  2516. return new (SemaRef.Context) ImplicitValueInitExpr(T);
  2517. }
  2518. /// Build a new \c va_arg expression.
  2519. ///
  2520. /// By default, performs semantic analysis to build the new expression.
  2521. /// Subclasses may override this routine to provide different behavior.
  2522. ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
  2523. Expr *SubExpr, TypeSourceInfo *TInfo,
  2524. SourceLocation RParenLoc) {
  2525. return getSema().BuildVAArgExpr(BuiltinLoc,
  2526. SubExpr, TInfo,
  2527. RParenLoc);
  2528. }
  2529. /// Build a new expression list in parentheses.
  2530. ///
  2531. /// By default, performs semantic analysis to build the new expression.
  2532. /// Subclasses may override this routine to provide different behavior.
  2533. ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
  2534. MultiExprArg SubExprs,
  2535. SourceLocation RParenLoc) {
  2536. return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
  2537. }
  2538. /// Build a new address-of-label expression.
  2539. ///
  2540. /// By default, performs semantic analysis, using the name of the label
  2541. /// rather than attempting to map the label statement itself.
  2542. /// Subclasses may override this routine to provide different behavior.
  2543. ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
  2544. SourceLocation LabelLoc, LabelDecl *Label) {
  2545. return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
  2546. }
  2547. /// Build a new GNU statement expression.
  2548. ///
  2549. /// By default, performs semantic analysis to build the new expression.
  2550. /// Subclasses may override this routine to provide different behavior.
  2551. ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt,
  2552. SourceLocation RParenLoc, unsigned TemplateDepth) {
  2553. return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
  2554. TemplateDepth);
  2555. }
  2556. /// Build a new __builtin_choose_expr expression.
  2557. ///
  2558. /// By default, performs semantic analysis to build the new expression.
  2559. /// Subclasses may override this routine to provide different behavior.
  2560. ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
  2561. Expr *Cond, Expr *LHS, Expr *RHS,
  2562. SourceLocation RParenLoc) {
  2563. return SemaRef.ActOnChooseExpr(BuiltinLoc,
  2564. Cond, LHS, RHS,
  2565. RParenLoc);
  2566. }
  2567. /// Build a new generic selection expression.
  2568. ///
  2569. /// By default, performs semantic analysis to build the new expression.
  2570. /// Subclasses may override this routine to provide different behavior.
  2571. ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
  2572. SourceLocation DefaultLoc,
  2573. SourceLocation RParenLoc,
  2574. Expr *ControllingExpr,
  2575. ArrayRef<TypeSourceInfo *> Types,
  2576. ArrayRef<Expr *> Exprs) {
  2577. return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
  2578. ControllingExpr, Types, Exprs);
  2579. }
  2580. /// Build a new overloaded operator call expression.
  2581. ///
  2582. /// By default, performs semantic analysis to build the new expression.
  2583. /// The semantic analysis provides the behavior of template instantiation,
  2584. /// copying with transformations that turn what looks like an overloaded
  2585. /// operator call into a use of a builtin operator, performing
  2586. /// argument-dependent lookup, etc. Subclasses may override this routine to
  2587. /// provide different behavior.
  2588. ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
  2589. SourceLocation OpLoc,
  2590. Expr *Callee,
  2591. Expr *First,
  2592. Expr *Second);
  2593. /// Build a new C++ "named" cast expression, such as static_cast or
  2594. /// reinterpret_cast.
  2595. ///
  2596. /// By default, this routine dispatches to one of the more-specific routines
  2597. /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
  2598. /// Subclasses may override this routine to provide different behavior.
  2599. ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
  2600. Stmt::StmtClass Class,
  2601. SourceLocation LAngleLoc,
  2602. TypeSourceInfo *TInfo,
  2603. SourceLocation RAngleLoc,
  2604. SourceLocation LParenLoc,
  2605. Expr *SubExpr,
  2606. SourceLocation RParenLoc) {
  2607. switch (Class) {
  2608. case Stmt::CXXStaticCastExprClass:
  2609. return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
  2610. RAngleLoc, LParenLoc,
  2611. SubExpr, RParenLoc);
  2612. case Stmt::CXXDynamicCastExprClass:
  2613. return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
  2614. RAngleLoc, LParenLoc,
  2615. SubExpr, RParenLoc);
  2616. case Stmt::CXXReinterpretCastExprClass:
  2617. return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
  2618. RAngleLoc, LParenLoc,
  2619. SubExpr,
  2620. RParenLoc);
  2621. case Stmt::CXXConstCastExprClass:
  2622. return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
  2623. RAngleLoc, LParenLoc,
  2624. SubExpr, RParenLoc);
  2625. case Stmt::CXXAddrspaceCastExprClass:
  2626. return getDerived().RebuildCXXAddrspaceCastExpr(
  2627. OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
  2628. default:
  2629. llvm_unreachable("Invalid C++ named cast");
  2630. }
  2631. }
  2632. /// Build a new C++ static_cast expression.
  2633. ///
  2634. /// By default, performs semantic analysis to build the new expression.
  2635. /// Subclasses may override this routine to provide different behavior.
  2636. ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
  2637. SourceLocation LAngleLoc,
  2638. TypeSourceInfo *TInfo,
  2639. SourceLocation RAngleLoc,
  2640. SourceLocation LParenLoc,
  2641. Expr *SubExpr,
  2642. SourceLocation RParenLoc) {
  2643. return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
  2644. TInfo, SubExpr,
  2645. SourceRange(LAngleLoc, RAngleLoc),
  2646. SourceRange(LParenLoc, RParenLoc));
  2647. }
  2648. /// Build a new C++ dynamic_cast expression.
  2649. ///
  2650. /// By default, performs semantic analysis to build the new expression.
  2651. /// Subclasses may override this routine to provide different behavior.
  2652. ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
  2653. SourceLocation LAngleLoc,
  2654. TypeSourceInfo *TInfo,
  2655. SourceLocation RAngleLoc,
  2656. SourceLocation LParenLoc,
  2657. Expr *SubExpr,
  2658. SourceLocation RParenLoc) {
  2659. return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
  2660. TInfo, SubExpr,
  2661. SourceRange(LAngleLoc, RAngleLoc),
  2662. SourceRange(LParenLoc, RParenLoc));
  2663. }
  2664. /// Build a new C++ reinterpret_cast expression.
  2665. ///
  2666. /// By default, performs semantic analysis to build the new expression.
  2667. /// Subclasses may override this routine to provide different behavior.
  2668. ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
  2669. SourceLocation LAngleLoc,
  2670. TypeSourceInfo *TInfo,
  2671. SourceLocation RAngleLoc,
  2672. SourceLocation LParenLoc,
  2673. Expr *SubExpr,
  2674. SourceLocation RParenLoc) {
  2675. return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
  2676. TInfo, SubExpr,
  2677. SourceRange(LAngleLoc, RAngleLoc),
  2678. SourceRange(LParenLoc, RParenLoc));
  2679. }
  2680. /// Build a new C++ const_cast expression.
  2681. ///
  2682. /// By default, performs semantic analysis to build the new expression.
  2683. /// Subclasses may override this routine to provide different behavior.
  2684. ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
  2685. SourceLocation LAngleLoc,
  2686. TypeSourceInfo *TInfo,
  2687. SourceLocation RAngleLoc,
  2688. SourceLocation LParenLoc,
  2689. Expr *SubExpr,
  2690. SourceLocation RParenLoc) {
  2691. return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
  2692. TInfo, SubExpr,
  2693. SourceRange(LAngleLoc, RAngleLoc),
  2694. SourceRange(LParenLoc, RParenLoc));
  2695. }
  2696. ExprResult
  2697. RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc,
  2698. TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
  2699. SourceLocation LParenLoc, Expr *SubExpr,
  2700. SourceLocation RParenLoc) {
  2701. return getSema().BuildCXXNamedCast(
  2702. OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
  2703. SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
  2704. }
  2705. /// Build a new C++ functional-style cast expression.
  2706. ///
  2707. /// By default, performs semantic analysis to build the new expression.
  2708. /// Subclasses may override this routine to provide different behavior.
  2709. ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
  2710. SourceLocation LParenLoc,
  2711. Expr *Sub,
  2712. SourceLocation RParenLoc,
  2713. bool ListInitialization) {
  2714. return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
  2715. MultiExprArg(&Sub, 1), RParenLoc,
  2716. ListInitialization);
  2717. }
  2718. /// Build a new C++ __builtin_bit_cast expression.
  2719. ///
  2720. /// By default, performs semantic analysis to build the new expression.
  2721. /// Subclasses may override this routine to provide different behavior.
  2722. ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc,
  2723. TypeSourceInfo *TSI, Expr *Sub,
  2724. SourceLocation RParenLoc) {
  2725. return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
  2726. }
  2727. /// Build a new C++ typeid(type) expression.
  2728. ///
  2729. /// By default, performs semantic analysis to build the new expression.
  2730. /// Subclasses may override this routine to provide different behavior.
  2731. ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
  2732. SourceLocation TypeidLoc,
  2733. TypeSourceInfo *Operand,
  2734. SourceLocation RParenLoc) {
  2735. return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
  2736. RParenLoc);
  2737. }
  2738. /// Build a new C++ typeid(expr) expression.
  2739. ///
  2740. /// By default, performs semantic analysis to build the new expression.
  2741. /// Subclasses may override this routine to provide different behavior.
  2742. ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
  2743. SourceLocation TypeidLoc,
  2744. Expr *Operand,
  2745. SourceLocation RParenLoc) {
  2746. return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
  2747. RParenLoc);
  2748. }
  2749. /// Build a new C++ __uuidof(type) expression.
  2750. ///
  2751. /// By default, performs semantic analysis to build the new expression.
  2752. /// Subclasses may override this routine to provide different behavior.
  2753. ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc,
  2754. TypeSourceInfo *Operand,
  2755. SourceLocation RParenLoc) {
  2756. return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
  2757. }
  2758. /// Build a new C++ __uuidof(expr) expression.
  2759. ///
  2760. /// By default, performs semantic analysis to build the new expression.
  2761. /// Subclasses may override this routine to provide different behavior.
  2762. ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc,
  2763. Expr *Operand, SourceLocation RParenLoc) {
  2764. return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
  2765. }
  2766. /// Build a new C++ "this" expression.
  2767. ///
  2768. /// By default, builds a new "this" expression without performing any
  2769. /// semantic analysis. Subclasses may override this routine to provide
  2770. /// different behavior.
  2771. ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
  2772. QualType ThisType,
  2773. bool isImplicit) {
  2774. return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
  2775. }
  2776. /// Build a new C++ throw expression.
  2777. ///
  2778. /// By default, performs semantic analysis to build the new expression.
  2779. /// Subclasses may override this routine to provide different behavior.
  2780. ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
  2781. bool IsThrownVariableInScope) {
  2782. return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
  2783. }
  2784. /// Build a new C++ default-argument expression.
  2785. ///
  2786. /// By default, builds a new default-argument expression, which does not
  2787. /// require any semantic analysis. Subclasses may override this routine to
  2788. /// provide different behavior.
  2789. ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) {
  2790. return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
  2791. getSema().CurContext);
  2792. }
  2793. /// Build a new C++11 default-initialization expression.
  2794. ///
  2795. /// By default, builds a new default field initialization expression, which
  2796. /// does not require any semantic analysis. Subclasses may override this
  2797. /// routine to provide different behavior.
  2798. ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
  2799. FieldDecl *Field) {
  2800. return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
  2801. getSema().CurContext);
  2802. }
  2803. /// Build a new C++ zero-initialization expression.
  2804. ///
  2805. /// By default, performs semantic analysis to build the new expression.
  2806. /// Subclasses may override this routine to provide different behavior.
  2807. ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
  2808. SourceLocation LParenLoc,
  2809. SourceLocation RParenLoc) {
  2810. return getSema().BuildCXXTypeConstructExpr(
  2811. TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false);
  2812. }
  2813. /// Build a new C++ "new" expression.
  2814. ///
  2815. /// By default, performs semantic analysis to build the new expression.
  2816. /// Subclasses may override this routine to provide different behavior.
  2817. ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
  2818. bool UseGlobal,
  2819. SourceLocation PlacementLParen,
  2820. MultiExprArg PlacementArgs,
  2821. SourceLocation PlacementRParen,
  2822. SourceRange TypeIdParens,
  2823. QualType AllocatedType,
  2824. TypeSourceInfo *AllocatedTypeInfo,
  2825. Optional<Expr *> ArraySize,
  2826. SourceRange DirectInitRange,
  2827. Expr *Initializer) {
  2828. return getSema().BuildCXXNew(StartLoc, UseGlobal,
  2829. PlacementLParen,
  2830. PlacementArgs,
  2831. PlacementRParen,
  2832. TypeIdParens,
  2833. AllocatedType,
  2834. AllocatedTypeInfo,
  2835. ArraySize,
  2836. DirectInitRange,
  2837. Initializer);
  2838. }
  2839. /// Build a new C++ "delete" expression.
  2840. ///
  2841. /// By default, performs semantic analysis to build the new expression.
  2842. /// Subclasses may override this routine to provide different behavior.
  2843. ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
  2844. bool IsGlobalDelete,
  2845. bool IsArrayForm,
  2846. Expr *Operand) {
  2847. return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
  2848. Operand);
  2849. }
  2850. /// Build a new type trait expression.
  2851. ///
  2852. /// By default, performs semantic analysis to build the new expression.
  2853. /// Subclasses may override this routine to provide different behavior.
  2854. ExprResult RebuildTypeTrait(TypeTrait Trait,
  2855. SourceLocation StartLoc,
  2856. ArrayRef<TypeSourceInfo *> Args,
  2857. SourceLocation RParenLoc) {
  2858. return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
  2859. }
  2860. /// Build a new array type trait expression.
  2861. ///
  2862. /// By default, performs semantic analysis to build the new expression.
  2863. /// Subclasses may override this routine to provide different behavior.
  2864. ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
  2865. SourceLocation StartLoc,
  2866. TypeSourceInfo *TSInfo,
  2867. Expr *DimExpr,
  2868. SourceLocation RParenLoc) {
  2869. return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
  2870. }
  2871. /// Build a new expression trait expression.
  2872. ///
  2873. /// By default, performs semantic analysis to build the new expression.
  2874. /// Subclasses may override this routine to provide different behavior.
  2875. ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
  2876. SourceLocation StartLoc,
  2877. Expr *Queried,
  2878. SourceLocation RParenLoc) {
  2879. return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
  2880. }
  2881. /// Build a new (previously unresolved) declaration reference
  2882. /// expression.
  2883. ///
  2884. /// By default, performs semantic analysis to build the new expression.
  2885. /// Subclasses may override this routine to provide different behavior.
  2886. ExprResult RebuildDependentScopeDeclRefExpr(
  2887. NestedNameSpecifierLoc QualifierLoc,
  2888. SourceLocation TemplateKWLoc,
  2889. const DeclarationNameInfo &NameInfo,
  2890. const TemplateArgumentListInfo *TemplateArgs,
  2891. bool IsAddressOfOperand,
  2892. TypeSourceInfo **RecoveryTSI) {
  2893. CXXScopeSpec SS;
  2894. SS.Adopt(QualifierLoc);
  2895. if (TemplateArgs || TemplateKWLoc.isValid())
  2896. return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
  2897. TemplateArgs);
  2898. return getSema().BuildQualifiedDeclarationNameExpr(
  2899. SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
  2900. }
  2901. /// Build a new template-id expression.
  2902. ///
  2903. /// By default, performs semantic analysis to build the new expression.
  2904. /// Subclasses may override this routine to provide different behavior.
  2905. ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
  2906. SourceLocation TemplateKWLoc,
  2907. LookupResult &R,
  2908. bool RequiresADL,
  2909. const TemplateArgumentListInfo *TemplateArgs) {
  2910. return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
  2911. TemplateArgs);
  2912. }
  2913. /// Build a new object-construction expression.
  2914. ///
  2915. /// By default, performs semantic analysis to build the new expression.
  2916. /// Subclasses may override this routine to provide different behavior.
  2917. ExprResult RebuildCXXConstructExpr(QualType T,
  2918. SourceLocation Loc,
  2919. CXXConstructorDecl *Constructor,
  2920. bool IsElidable,
  2921. MultiExprArg Args,
  2922. bool HadMultipleCandidates,
  2923. bool ListInitialization,
  2924. bool StdInitListInitialization,
  2925. bool RequiresZeroInit,
  2926. CXXConstructExpr::ConstructionKind ConstructKind,
  2927. SourceRange ParenRange) {
  2928. // Reconstruct the constructor we originally found, which might be
  2929. // different if this is a call to an inherited constructor.
  2930. CXXConstructorDecl *FoundCtor = Constructor;
  2931. if (Constructor->isInheritingConstructor())
  2932. FoundCtor = Constructor->getInheritedConstructor().getConstructor();
  2933. SmallVector<Expr *, 8> ConvertedArgs;
  2934. if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
  2935. ConvertedArgs))
  2936. return ExprError();
  2937. return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
  2938. IsElidable,
  2939. ConvertedArgs,
  2940. HadMultipleCandidates,
  2941. ListInitialization,
  2942. StdInitListInitialization,
  2943. RequiresZeroInit, ConstructKind,
  2944. ParenRange);
  2945. }
  2946. /// Build a new implicit construction via inherited constructor
  2947. /// expression.
  2948. ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc,
  2949. CXXConstructorDecl *Constructor,
  2950. bool ConstructsVBase,
  2951. bool InheritedFromVBase) {
  2952. return new (getSema().Context) CXXInheritedCtorInitExpr(
  2953. Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
  2954. }
  2955. /// Build a new object-construction expression.
  2956. ///
  2957. /// By default, performs semantic analysis to build the new expression.
  2958. /// Subclasses may override this routine to provide different behavior.
  2959. ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
  2960. SourceLocation LParenOrBraceLoc,
  2961. MultiExprArg Args,
  2962. SourceLocation RParenOrBraceLoc,
  2963. bool ListInitialization) {
  2964. return getSema().BuildCXXTypeConstructExpr(
  2965. TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
  2966. }
  2967. /// Build a new object-construction expression.
  2968. ///
  2969. /// By default, performs semantic analysis to build the new expression.
  2970. /// Subclasses may override this routine to provide different behavior.
  2971. ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
  2972. SourceLocation LParenLoc,
  2973. MultiExprArg Args,
  2974. SourceLocation RParenLoc,
  2975. bool ListInitialization) {
  2976. return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
  2977. RParenLoc, ListInitialization);
  2978. }
  2979. /// Build a new member reference expression.
  2980. ///
  2981. /// By default, performs semantic analysis to build the new expression.
  2982. /// Subclasses may override this routine to provide different behavior.
  2983. ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
  2984. QualType BaseType,
  2985. bool IsArrow,
  2986. SourceLocation OperatorLoc,
  2987. NestedNameSpecifierLoc QualifierLoc,
  2988. SourceLocation TemplateKWLoc,
  2989. NamedDecl *FirstQualifierInScope,
  2990. const DeclarationNameInfo &MemberNameInfo,
  2991. const TemplateArgumentListInfo *TemplateArgs) {
  2992. CXXScopeSpec SS;
  2993. SS.Adopt(QualifierLoc);
  2994. return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
  2995. OperatorLoc, IsArrow,
  2996. SS, TemplateKWLoc,
  2997. FirstQualifierInScope,
  2998. MemberNameInfo,
  2999. TemplateArgs, /*S*/nullptr);
  3000. }
  3001. /// Build a new member reference expression.
  3002. ///
  3003. /// By default, performs semantic analysis to build the new expression.
  3004. /// Subclasses may override this routine to provide different behavior.
  3005. ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
  3006. SourceLocation OperatorLoc,
  3007. bool IsArrow,
  3008. NestedNameSpecifierLoc QualifierLoc,
  3009. SourceLocation TemplateKWLoc,
  3010. NamedDecl *FirstQualifierInScope,
  3011. LookupResult &R,
  3012. const TemplateArgumentListInfo *TemplateArgs) {
  3013. CXXScopeSpec SS;
  3014. SS.Adopt(QualifierLoc);
  3015. return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
  3016. OperatorLoc, IsArrow,
  3017. SS, TemplateKWLoc,
  3018. FirstQualifierInScope,
  3019. R, TemplateArgs, /*S*/nullptr);
  3020. }
  3021. /// Build a new noexcept expression.
  3022. ///
  3023. /// By default, performs semantic analysis to build the new expression.
  3024. /// Subclasses may override this routine to provide different behavior.
  3025. ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
  3026. return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
  3027. }
  3028. /// Build a new expression to compute the length of a parameter pack.
  3029. ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
  3030. NamedDecl *Pack,
  3031. SourceLocation PackLoc,
  3032. SourceLocation RParenLoc,
  3033. Optional<unsigned> Length,
  3034. ArrayRef<TemplateArgument> PartialArgs) {
  3035. return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
  3036. RParenLoc, Length, PartialArgs);
  3037. }
  3038. /// Build a new expression representing a call to a source location
  3039. /// builtin.
  3040. ///
  3041. /// By default, performs semantic analysis to build the new expression.
  3042. /// Subclasses may override this routine to provide different behavior.
  3043. ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind,
  3044. SourceLocation BuiltinLoc,
  3045. SourceLocation RPLoc,
  3046. DeclContext *ParentContext) {
  3047. return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext);
  3048. }
  3049. /// Build a new Objective-C boxed expression.
  3050. ///
  3051. /// By default, performs semantic analysis to build the new expression.
  3052. /// Subclasses may override this routine to provide different behavior.
  3053. ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS,
  3054. SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
  3055. NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
  3056. TemplateArgumentListInfo *TALI) {
  3057. CXXScopeSpec SS;
  3058. SS.Adopt(NNS);
  3059. ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
  3060. ConceptNameInfo,
  3061. FoundDecl,
  3062. NamedConcept, TALI);
  3063. if (Result.isInvalid())
  3064. return ExprError();
  3065. return Result;
  3066. }
  3067. /// \brief Build a new requires expression.
  3068. ///
  3069. /// By default, performs semantic analysis to build the new expression.
  3070. /// Subclasses may override this routine to provide different behavior.
  3071. ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc,
  3072. RequiresExprBodyDecl *Body,
  3073. ArrayRef<ParmVarDecl *> LocalParameters,
  3074. ArrayRef<concepts::Requirement *> Requirements,
  3075. SourceLocation ClosingBraceLoc) {
  3076. return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body,
  3077. LocalParameters, Requirements, ClosingBraceLoc);
  3078. }
  3079. concepts::TypeRequirement *
  3080. RebuildTypeRequirement(
  3081. concepts::Requirement::SubstitutionDiagnostic *SubstDiag) {
  3082. return SemaRef.BuildTypeRequirement(SubstDiag);
  3083. }
  3084. concepts::TypeRequirement *RebuildTypeRequirement(TypeSourceInfo *T) {
  3085. return SemaRef.BuildTypeRequirement(T);
  3086. }
  3087. concepts::ExprRequirement *
  3088. RebuildExprRequirement(
  3089. concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
  3090. SourceLocation NoexceptLoc,
  3091. concepts::ExprRequirement::ReturnTypeRequirement Ret) {
  3092. return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
  3093. std::move(Ret));
  3094. }
  3095. concepts::ExprRequirement *
  3096. RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
  3097. concepts::ExprRequirement::ReturnTypeRequirement Ret) {
  3098. return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
  3099. std::move(Ret));
  3100. }
  3101. concepts::NestedRequirement *
  3102. RebuildNestedRequirement(
  3103. concepts::Requirement::SubstitutionDiagnostic *SubstDiag) {
  3104. return SemaRef.BuildNestedRequirement(SubstDiag);
  3105. }
  3106. concepts::NestedRequirement *RebuildNestedRequirement(Expr *Constraint) {
  3107. return SemaRef.BuildNestedRequirement(Constraint);
  3108. }
  3109. /// \brief Build a new Objective-C boxed expression.
  3110. ///
  3111. /// By default, performs semantic analysis to build the new expression.
  3112. /// Subclasses may override this routine to provide different behavior.
  3113. ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
  3114. return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
  3115. }
  3116. /// Build a new Objective-C array literal.
  3117. ///
  3118. /// By default, performs semantic analysis to build the new expression.
  3119. /// Subclasses may override this routine to provide different behavior.
  3120. ExprResult RebuildObjCArrayLiteral(SourceRange Range,
  3121. Expr **Elements, unsigned NumElements) {
  3122. return getSema().BuildObjCArrayLiteral(Range,
  3123. MultiExprArg(Elements, NumElements));
  3124. }
  3125. ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
  3126. Expr *Base, Expr *Key,
  3127. ObjCMethodDecl *getterMethod,
  3128. ObjCMethodDecl *setterMethod) {
  3129. return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
  3130. getterMethod, setterMethod);
  3131. }
  3132. /// Build a new Objective-C dictionary literal.
  3133. ///
  3134. /// By default, performs semantic analysis to build the new expression.
  3135. /// Subclasses may override this routine to provide different behavior.
  3136. ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
  3137. MutableArrayRef<ObjCDictionaryElement> Elements) {
  3138. return getSema().BuildObjCDictionaryLiteral(Range, Elements);
  3139. }
  3140. /// Build a new Objective-C \@encode expression.
  3141. ///
  3142. /// By default, performs semantic analysis to build the new expression.
  3143. /// Subclasses may override this routine to provide different behavior.
  3144. ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
  3145. TypeSourceInfo *EncodeTypeInfo,
  3146. SourceLocation RParenLoc) {
  3147. return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
  3148. }
  3149. /// Build a new Objective-C class message.
  3150. ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
  3151. Selector Sel,
  3152. ArrayRef<SourceLocation> SelectorLocs,
  3153. ObjCMethodDecl *Method,
  3154. SourceLocation LBracLoc,
  3155. MultiExprArg Args,
  3156. SourceLocation RBracLoc) {
  3157. return SemaRef.BuildClassMessage(ReceiverTypeInfo,
  3158. ReceiverTypeInfo->getType(),
  3159. /*SuperLoc=*/SourceLocation(),
  3160. Sel, Method, LBracLoc, SelectorLocs,
  3161. RBracLoc, Args);
  3162. }
  3163. /// Build a new Objective-C instance message.
  3164. ExprResult RebuildObjCMessageExpr(Expr *Receiver,
  3165. Selector Sel,
  3166. ArrayRef<SourceLocation> SelectorLocs,
  3167. ObjCMethodDecl *Method,
  3168. SourceLocation LBracLoc,
  3169. MultiExprArg Args,
  3170. SourceLocation RBracLoc) {
  3171. return SemaRef.BuildInstanceMessage(Receiver,
  3172. Receiver->getType(),
  3173. /*SuperLoc=*/SourceLocation(),
  3174. Sel, Method, LBracLoc, SelectorLocs,
  3175. RBracLoc, Args);
  3176. }
  3177. /// Build a new Objective-C instance/class message to 'super'.
  3178. ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
  3179. Selector Sel,
  3180. ArrayRef<SourceLocation> SelectorLocs,
  3181. QualType SuperType,
  3182. ObjCMethodDecl *Method,
  3183. SourceLocation LBracLoc,
  3184. MultiExprArg Args,
  3185. SourceLocation RBracLoc) {
  3186. return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
  3187. SuperType,
  3188. SuperLoc,
  3189. Sel, Method, LBracLoc, SelectorLocs,
  3190. RBracLoc, Args)
  3191. : SemaRef.BuildClassMessage(nullptr,
  3192. SuperType,
  3193. SuperLoc,
  3194. Sel, Method, LBracLoc, SelectorLocs,
  3195. RBracLoc, Args);
  3196. }
  3197. /// Build a new Objective-C ivar reference expression.
  3198. ///
  3199. /// By default, performs semantic analysis to build the new expression.
  3200. /// Subclasses may override this routine to provide different behavior.
  3201. ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
  3202. SourceLocation IvarLoc,
  3203. bool IsArrow, bool IsFreeIvar) {
  3204. CXXScopeSpec SS;
  3205. DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
  3206. ExprResult Result = getSema().BuildMemberReferenceExpr(
  3207. BaseArg, BaseArg->getType(),
  3208. /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
  3209. /*FirstQualifierInScope=*/nullptr, NameInfo,
  3210. /*TemplateArgs=*/nullptr,
  3211. /*S=*/nullptr);
  3212. if (IsFreeIvar && Result.isUsable())
  3213. cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
  3214. return Result;
  3215. }
  3216. /// Build a new Objective-C property reference expression.
  3217. ///
  3218. /// By default, performs semantic analysis to build the new expression.
  3219. /// Subclasses may override this routine to provide different behavior.
  3220. ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
  3221. ObjCPropertyDecl *Property,
  3222. SourceLocation PropertyLoc) {
  3223. CXXScopeSpec SS;
  3224. DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
  3225. return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
  3226. /*FIXME:*/PropertyLoc,
  3227. /*IsArrow=*/false,
  3228. SS, SourceLocation(),
  3229. /*FirstQualifierInScope=*/nullptr,
  3230. NameInfo,
  3231. /*TemplateArgs=*/nullptr,
  3232. /*S=*/nullptr);
  3233. }
  3234. /// Build a new Objective-C property reference expression.
  3235. ///
  3236. /// By default, performs semantic analysis to build the new expression.
  3237. /// Subclasses may override this routine to provide different behavior.
  3238. ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
  3239. ObjCMethodDecl *Getter,
  3240. ObjCMethodDecl *Setter,
  3241. SourceLocation PropertyLoc) {
  3242. // Since these expressions can only be value-dependent, we do not
  3243. // need to perform semantic analysis again.
  3244. return Owned(
  3245. new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
  3246. VK_LValue, OK_ObjCProperty,
  3247. PropertyLoc, Base));
  3248. }
  3249. /// Build a new Objective-C "isa" expression.
  3250. ///
  3251. /// By default, performs semantic analysis to build the new expression.
  3252. /// Subclasses may override this routine to provide different behavior.
  3253. ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
  3254. SourceLocation OpLoc, bool IsArrow) {
  3255. CXXScopeSpec SS;
  3256. DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
  3257. return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
  3258. OpLoc, IsArrow,
  3259. SS, SourceLocation(),
  3260. /*FirstQualifierInScope=*/nullptr,
  3261. NameInfo,
  3262. /*TemplateArgs=*/nullptr,
  3263. /*S=*/nullptr);
  3264. }
  3265. /// Build a new shuffle vector expression.
  3266. ///
  3267. /// By default, performs semantic analysis to build the new expression.
  3268. /// Subclasses may override this routine to provide different behavior.
  3269. ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
  3270. MultiExprArg SubExprs,
  3271. SourceLocation RParenLoc) {
  3272. // Find the declaration for __builtin_shufflevector
  3273. const IdentifierInfo &Name
  3274. = SemaRef.Context.Idents.get("__builtin_shufflevector");
  3275. TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
  3276. DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
  3277. assert(!Lookup.empty() && "No __builtin_shufflevector?");
  3278. // Build a reference to the __builtin_shufflevector builtin
  3279. FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
  3280. Expr *Callee = new (SemaRef.Context)
  3281. DeclRefExpr(SemaRef.Context, Builtin, false,
  3282. SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
  3283. QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
  3284. Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
  3285. CK_BuiltinFnToFnPtr).get();
  3286. // Build the CallExpr
  3287. ExprResult TheCall = CallExpr::Create(
  3288. SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
  3289. Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
  3290. FPOptionsOverride());
  3291. // Type-check the __builtin_shufflevector expression.
  3292. return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
  3293. }
  3294. /// Build a new convert vector expression.
  3295. ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
  3296. Expr *SrcExpr, TypeSourceInfo *DstTInfo,
  3297. SourceLocation RParenLoc) {
  3298. return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
  3299. BuiltinLoc, RParenLoc);
  3300. }
  3301. /// Build a new template argument pack expansion.
  3302. ///
  3303. /// By default, performs semantic analysis to build a new pack expansion
  3304. /// for a template argument. Subclasses may override this routine to provide
  3305. /// different behavior.
  3306. TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
  3307. SourceLocation EllipsisLoc,
  3308. Optional<unsigned> NumExpansions) {
  3309. switch (Pattern.getArgument().getKind()) {
  3310. case TemplateArgument::Expression: {
  3311. ExprResult Result
  3312. = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
  3313. EllipsisLoc, NumExpansions);
  3314. if (Result.isInvalid())
  3315. return TemplateArgumentLoc();
  3316. return TemplateArgumentLoc(Result.get(), Result.get());
  3317. }
  3318. case TemplateArgument::Template:
  3319. return TemplateArgumentLoc(
  3320. SemaRef.Context,
  3321. TemplateArgument(Pattern.getArgument().getAsTemplate(),
  3322. NumExpansions),
  3323. Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
  3324. EllipsisLoc);
  3325. case TemplateArgument::Null:
  3326. case TemplateArgument::Integral:
  3327. case TemplateArgument::Declaration:
  3328. case TemplateArgument::Pack:
  3329. case TemplateArgument::TemplateExpansion:
  3330. case TemplateArgument::NullPtr:
  3331. llvm_unreachable("Pack expansion pattern has no parameter packs");
  3332. case TemplateArgument::Type:
  3333. if (TypeSourceInfo *Expansion
  3334. = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
  3335. EllipsisLoc,
  3336. NumExpansions))
  3337. return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
  3338. Expansion);
  3339. break;
  3340. }
  3341. return TemplateArgumentLoc();
  3342. }
  3343. /// Build a new expression pack expansion.
  3344. ///
  3345. /// By default, performs semantic analysis to build a new pack expansion
  3346. /// for an expression. Subclasses may override this routine to provide
  3347. /// different behavior.
  3348. ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
  3349. Optional<unsigned> NumExpansions) {
  3350. return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
  3351. }
  3352. /// Build a new C++1z fold-expression.
  3353. ///
  3354. /// By default, performs semantic analysis in order to build a new fold
  3355. /// expression.
  3356. ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE,
  3357. SourceLocation LParenLoc, Expr *LHS,
  3358. BinaryOperatorKind Operator,
  3359. SourceLocation EllipsisLoc, Expr *RHS,
  3360. SourceLocation RParenLoc,
  3361. Optional<unsigned> NumExpansions) {
  3362. return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
  3363. EllipsisLoc, RHS, RParenLoc,
  3364. NumExpansions);
  3365. }
  3366. /// Build an empty C++1z fold-expression with the given operator.
  3367. ///
  3368. /// By default, produces the fallback value for the fold-expression, or
  3369. /// produce an error if there is no fallback value.
  3370. ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
  3371. BinaryOperatorKind Operator) {
  3372. return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
  3373. }
  3374. /// Build a new atomic operation expression.
  3375. ///
  3376. /// By default, performs semantic analysis to build the new expression.
  3377. /// Subclasses may override this routine to provide different behavior.
  3378. ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs,
  3379. AtomicExpr::AtomicOp Op,
  3380. SourceLocation RParenLoc) {
  3381. // Use this for all of the locations, since we don't know the difference
  3382. // between the call and the expr at this point.
  3383. SourceRange Range{BuiltinLoc, RParenLoc};
  3384. return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
  3385. Sema::AtomicArgumentOrder::AST);
  3386. }
  3387. ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc,
  3388. ArrayRef<Expr *> SubExprs, QualType Type) {
  3389. return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
  3390. }
  3391. private:
  3392. TypeLoc TransformTypeInObjectScope(TypeLoc TL,
  3393. QualType ObjectType,
  3394. NamedDecl *FirstQualifierInScope,
  3395. CXXScopeSpec &SS);
  3396. TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
  3397. QualType ObjectType,
  3398. NamedDecl *FirstQualifierInScope,
  3399. CXXScopeSpec &SS);
  3400. TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
  3401. NamedDecl *FirstQualifierInScope,
  3402. CXXScopeSpec &SS);
  3403. QualType TransformDependentNameType(TypeLocBuilder &TLB,
  3404. DependentNameTypeLoc TL,
  3405. bool DeducibleTSTContext);
  3406. };
  3407. template <typename Derived>
  3408. StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) {
  3409. if (!S)
  3410. return S;
  3411. switch (S->getStmtClass()) {
  3412. case Stmt::NoStmtClass: break;
  3413. // Transform individual statement nodes
  3414. // Pass SDK into statements that can produce a value
  3415. #define STMT(Node, Parent) \
  3416. case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
  3417. #define VALUESTMT(Node, Parent) \
  3418. case Stmt::Node##Class: \
  3419. return getDerived().Transform##Node(cast<Node>(S), SDK);
  3420. #define ABSTRACT_STMT(Node)
  3421. #define EXPR(Node, Parent)
  3422. #include "clang/AST/StmtNodes.inc"
  3423. // Transform expressions by calling TransformExpr.
  3424. #define STMT(Node, Parent)
  3425. #define ABSTRACT_STMT(Stmt)
  3426. #define EXPR(Node, Parent) case Stmt::Node##Class:
  3427. #include "clang/AST/StmtNodes.inc"
  3428. {
  3429. ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
  3430. if (SDK == SDK_StmtExprResult)
  3431. E = getSema().ActOnStmtExprResult(E);
  3432. return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
  3433. }
  3434. }
  3435. return S;
  3436. }
  3437. template<typename Derived>
  3438. OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
  3439. if (!S)
  3440. return S;
  3441. switch (S->getClauseKind()) {
  3442. default: break;
  3443. // Transform individual clause nodes
  3444. #define GEN_CLANG_CLAUSE_CLASS
  3445. #define CLAUSE_CLASS(Enum, Str, Class) \
  3446. case Enum: \
  3447. return getDerived().Transform##Class(cast<Class>(S));
  3448. #include "llvm/Frontend/OpenMP/OMP.inc"
  3449. }
  3450. return S;
  3451. }
  3452. template<typename Derived>
  3453. ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
  3454. if (!E)
  3455. return E;
  3456. switch (E->getStmtClass()) {
  3457. case Stmt::NoStmtClass: break;
  3458. #define STMT(Node, Parent) case Stmt::Node##Class: break;
  3459. #define ABSTRACT_STMT(Stmt)
  3460. #define EXPR(Node, Parent) \
  3461. case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
  3462. #include "clang/AST/StmtNodes.inc"
  3463. }
  3464. return E;
  3465. }
  3466. template<typename Derived>
  3467. ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
  3468. bool NotCopyInit) {
  3469. // Initializers are instantiated like expressions, except that various outer
  3470. // layers are stripped.
  3471. if (!Init)
  3472. return Init;
  3473. if (auto *FE = dyn_cast<FullExpr>(Init))
  3474. Init = FE->getSubExpr();
  3475. if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
  3476. OpaqueValueExpr *OVE = AIL->getCommonExpr();
  3477. Init = OVE->getSourceExpr();
  3478. }
  3479. if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
  3480. Init = MTE->getSubExpr();
  3481. while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
  3482. Init = Binder->getSubExpr();
  3483. if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
  3484. Init = ICE->getSubExprAsWritten();
  3485. if (CXXStdInitializerListExpr *ILE =
  3486. dyn_cast<CXXStdInitializerListExpr>(Init))
  3487. return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
  3488. // If this is copy-initialization, we only need to reconstruct
  3489. // InitListExprs. Other forms of copy-initialization will be a no-op if
  3490. // the initializer is already the right type.
  3491. CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
  3492. if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
  3493. return getDerived().TransformExpr(Init);
  3494. // Revert value-initialization back to empty parens.
  3495. if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
  3496. SourceRange Parens = VIE->getSourceRange();
  3497. return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
  3498. Parens.getEnd());
  3499. }
  3500. // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
  3501. if (isa<ImplicitValueInitExpr>(Init))
  3502. return getDerived().RebuildParenListExpr(SourceLocation(), None,
  3503. SourceLocation());
  3504. // Revert initialization by constructor back to a parenthesized or braced list
  3505. // of expressions. Any other form of initializer can just be reused directly.
  3506. if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
  3507. return getDerived().TransformExpr(Init);
  3508. // If the initialization implicitly converted an initializer list to a
  3509. // std::initializer_list object, unwrap the std::initializer_list too.
  3510. if (Construct && Construct->isStdInitListInitialization())
  3511. return TransformInitializer(Construct->getArg(0), NotCopyInit);
  3512. // Enter a list-init context if this was list initialization.
  3513. EnterExpressionEvaluationContext Context(
  3514. getSema(), EnterExpressionEvaluationContext::InitList,
  3515. Construct->isListInitialization());
  3516. SmallVector<Expr*, 8> NewArgs;
  3517. bool ArgChanged = false;
  3518. if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
  3519. /*IsCall*/true, NewArgs, &ArgChanged))
  3520. return ExprError();
  3521. // If this was list initialization, revert to syntactic list form.
  3522. if (Construct->isListInitialization())
  3523. return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
  3524. Construct->getEndLoc());
  3525. // Build a ParenListExpr to represent anything else.
  3526. SourceRange Parens = Construct->getParenOrBraceRange();
  3527. if (Parens.isInvalid()) {
  3528. // This was a variable declaration's initialization for which no initializer
  3529. // was specified.
  3530. assert(NewArgs.empty() &&
  3531. "no parens or braces but have direct init with arguments?");
  3532. return ExprEmpty();
  3533. }
  3534. return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
  3535. Parens.getEnd());
  3536. }
  3537. template<typename Derived>
  3538. bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs,
  3539. unsigned NumInputs,
  3540. bool IsCall,
  3541. SmallVectorImpl<Expr *> &Outputs,
  3542. bool *ArgChanged) {
  3543. for (unsigned I = 0; I != NumInputs; ++I) {
  3544. // If requested, drop call arguments that need to be dropped.
  3545. if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
  3546. if (ArgChanged)
  3547. *ArgChanged = true;
  3548. break;
  3549. }
  3550. if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
  3551. Expr *Pattern = Expansion->getPattern();
  3552. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  3553. getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
  3554. assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
  3555. // Determine whether the set of unexpanded parameter packs can and should
  3556. // be expanded.
  3557. bool Expand = true;
  3558. bool RetainExpansion = false;
  3559. Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
  3560. Optional<unsigned> NumExpansions = OrigNumExpansions;
  3561. if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
  3562. Pattern->getSourceRange(),
  3563. Unexpanded,
  3564. Expand, RetainExpansion,
  3565. NumExpansions))
  3566. return true;
  3567. if (!Expand) {
  3568. // The transform has determined that we should perform a simple
  3569. // transformation on the pack expansion, producing another pack
  3570. // expansion.
  3571. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  3572. ExprResult OutPattern = getDerived().TransformExpr(Pattern);
  3573. if (OutPattern.isInvalid())
  3574. return true;
  3575. ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
  3576. Expansion->getEllipsisLoc(),
  3577. NumExpansions);
  3578. if (Out.isInvalid())
  3579. return true;
  3580. if (ArgChanged)
  3581. *ArgChanged = true;
  3582. Outputs.push_back(Out.get());
  3583. continue;
  3584. }
  3585. // Record right away that the argument was changed. This needs
  3586. // to happen even if the array expands to nothing.
  3587. if (ArgChanged) *ArgChanged = true;
  3588. // The transform has determined that we should perform an elementwise
  3589. // expansion of the pattern. Do so.
  3590. for (unsigned I = 0; I != *NumExpansions; ++I) {
  3591. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
  3592. ExprResult Out = getDerived().TransformExpr(Pattern);
  3593. if (Out.isInvalid())
  3594. return true;
  3595. if (Out.get()->containsUnexpandedParameterPack()) {
  3596. Out = getDerived().RebuildPackExpansion(
  3597. Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
  3598. if (Out.isInvalid())
  3599. return true;
  3600. }
  3601. Outputs.push_back(Out.get());
  3602. }
  3603. // If we're supposed to retain a pack expansion, do so by temporarily
  3604. // forgetting the partially-substituted parameter pack.
  3605. if (RetainExpansion) {
  3606. ForgetPartiallySubstitutedPackRAII Forget(getDerived());
  3607. ExprResult Out = getDerived().TransformExpr(Pattern);
  3608. if (Out.isInvalid())
  3609. return true;
  3610. Out = getDerived().RebuildPackExpansion(
  3611. Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
  3612. if (Out.isInvalid())
  3613. return true;
  3614. Outputs.push_back(Out.get());
  3615. }
  3616. continue;
  3617. }
  3618. ExprResult Result =
  3619. IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
  3620. : getDerived().TransformExpr(Inputs[I]);
  3621. if (Result.isInvalid())
  3622. return true;
  3623. if (Result.get() != Inputs[I] && ArgChanged)
  3624. *ArgChanged = true;
  3625. Outputs.push_back(Result.get());
  3626. }
  3627. return false;
  3628. }
  3629. template <typename Derived>
  3630. Sema::ConditionResult TreeTransform<Derived>::TransformCondition(
  3631. SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) {
  3632. if (Var) {
  3633. VarDecl *ConditionVar = cast_or_null<VarDecl>(
  3634. getDerived().TransformDefinition(Var->getLocation(), Var));
  3635. if (!ConditionVar)
  3636. return Sema::ConditionError();
  3637. return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
  3638. }
  3639. if (Expr) {
  3640. ExprResult CondExpr = getDerived().TransformExpr(Expr);
  3641. if (CondExpr.isInvalid())
  3642. return Sema::ConditionError();
  3643. return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
  3644. /*MissingOK=*/true);
  3645. }
  3646. return Sema::ConditionResult();
  3647. }
  3648. template <typename Derived>
  3649. NestedNameSpecifierLoc TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
  3650. NestedNameSpecifierLoc NNS, QualType ObjectType,
  3651. NamedDecl *FirstQualifierInScope) {
  3652. SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
  3653. for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
  3654. Qualifier = Qualifier.getPrefix())
  3655. Qualifiers.push_back(Qualifier);
  3656. CXXScopeSpec SS;
  3657. while (!Qualifiers.empty()) {
  3658. NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
  3659. NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
  3660. switch (QNNS->getKind()) {
  3661. case NestedNameSpecifier::Identifier: {
  3662. Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(),
  3663. Q.getLocalBeginLoc(), Q.getLocalEndLoc(),
  3664. ObjectType);
  3665. if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
  3666. SS, FirstQualifierInScope, false))
  3667. return NestedNameSpecifierLoc();
  3668. break;
  3669. }
  3670. case NestedNameSpecifier::Namespace: {
  3671. NamespaceDecl *NS =
  3672. cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
  3673. Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
  3674. SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
  3675. break;
  3676. }
  3677. case NestedNameSpecifier::NamespaceAlias: {
  3678. NamespaceAliasDecl *Alias =
  3679. cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
  3680. Q.getLocalBeginLoc(), QNNS->getAsNamespaceAlias()));
  3681. SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
  3682. Q.getLocalEndLoc());
  3683. break;
  3684. }
  3685. case NestedNameSpecifier::Global:
  3686. // There is no meaningful transformation that one could perform on the
  3687. // global scope.
  3688. SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
  3689. break;
  3690. case NestedNameSpecifier::Super: {
  3691. CXXRecordDecl *RD =
  3692. cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
  3693. SourceLocation(), QNNS->getAsRecordDecl()));
  3694. SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
  3695. break;
  3696. }
  3697. case NestedNameSpecifier::TypeSpecWithTemplate:
  3698. case NestedNameSpecifier::TypeSpec: {
  3699. TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
  3700. FirstQualifierInScope, SS);
  3701. if (!TL)
  3702. return NestedNameSpecifierLoc();
  3703. if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
  3704. (SemaRef.getLangOpts().CPlusPlus11 &&
  3705. TL.getType()->isEnumeralType())) {
  3706. assert(!TL.getType().hasLocalQualifiers() &&
  3707. "Can't get cv-qualifiers here");
  3708. if (TL.getType()->isEnumeralType())
  3709. SemaRef.Diag(TL.getBeginLoc(),
  3710. diag::warn_cxx98_compat_enum_nested_name_spec);
  3711. SS.Extend(SemaRef.Context, /*FIXME:*/ SourceLocation(), TL,
  3712. Q.getLocalEndLoc());
  3713. break;
  3714. }
  3715. // If the nested-name-specifier is an invalid type def, don't emit an
  3716. // error because a previous error should have already been emitted.
  3717. TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
  3718. if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
  3719. SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
  3720. << TL.getType() << SS.getRange();
  3721. }
  3722. return NestedNameSpecifierLoc();
  3723. }
  3724. }
  3725. // The qualifier-in-scope and object type only apply to the leftmost entity.
  3726. FirstQualifierInScope = nullptr;
  3727. ObjectType = QualType();
  3728. }
  3729. // Don't rebuild the nested-name-specifier if we don't have to.
  3730. if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
  3731. !getDerived().AlwaysRebuild())
  3732. return NNS;
  3733. // If we can re-use the source-location data from the original
  3734. // nested-name-specifier, do so.
  3735. if (SS.location_size() == NNS.getDataLength() &&
  3736. memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
  3737. return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
  3738. // Allocate new nested-name-specifier location information.
  3739. return SS.getWithLocInContext(SemaRef.Context);
  3740. }
  3741. template<typename Derived>
  3742. DeclarationNameInfo
  3743. TreeTransform<Derived>
  3744. ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
  3745. DeclarationName Name = NameInfo.getName();
  3746. if (!Name)
  3747. return DeclarationNameInfo();
  3748. switch (Name.getNameKind()) {
  3749. case DeclarationName::Identifier:
  3750. case DeclarationName::ObjCZeroArgSelector:
  3751. case DeclarationName::ObjCOneArgSelector:
  3752. case DeclarationName::ObjCMultiArgSelector:
  3753. case DeclarationName::CXXOperatorName:
  3754. case DeclarationName::CXXLiteralOperatorName:
  3755. case DeclarationName::CXXUsingDirective:
  3756. return NameInfo;
  3757. case DeclarationName::CXXDeductionGuideName: {
  3758. TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
  3759. TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
  3760. getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
  3761. if (!NewTemplate)
  3762. return DeclarationNameInfo();
  3763. DeclarationNameInfo NewNameInfo(NameInfo);
  3764. NewNameInfo.setName(
  3765. SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
  3766. return NewNameInfo;
  3767. }
  3768. case DeclarationName::CXXConstructorName:
  3769. case DeclarationName::CXXDestructorName:
  3770. case DeclarationName::CXXConversionFunctionName: {
  3771. TypeSourceInfo *NewTInfo;
  3772. CanQualType NewCanTy;
  3773. if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
  3774. NewTInfo = getDerived().TransformType(OldTInfo);
  3775. if (!NewTInfo)
  3776. return DeclarationNameInfo();
  3777. NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
  3778. }
  3779. else {
  3780. NewTInfo = nullptr;
  3781. TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
  3782. QualType NewT = getDerived().TransformType(Name.getCXXNameType());
  3783. if (NewT.isNull())
  3784. return DeclarationNameInfo();
  3785. NewCanTy = SemaRef.Context.getCanonicalType(NewT);
  3786. }
  3787. DeclarationName NewName
  3788. = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
  3789. NewCanTy);
  3790. DeclarationNameInfo NewNameInfo(NameInfo);
  3791. NewNameInfo.setName(NewName);
  3792. NewNameInfo.setNamedTypeInfo(NewTInfo);
  3793. return NewNameInfo;
  3794. }
  3795. }
  3796. llvm_unreachable("Unknown name kind.");
  3797. }
  3798. template<typename Derived>
  3799. TemplateName
  3800. TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
  3801. TemplateName Name,
  3802. SourceLocation NameLoc,
  3803. QualType ObjectType,
  3804. NamedDecl *FirstQualifierInScope,
  3805. bool AllowInjectedClassName) {
  3806. if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
  3807. TemplateDecl *Template = QTN->getTemplateDecl();
  3808. assert(Template && "qualified template name must refer to a template");
  3809. TemplateDecl *TransTemplate
  3810. = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
  3811. Template));
  3812. if (!TransTemplate)
  3813. return TemplateName();
  3814. if (!getDerived().AlwaysRebuild() &&
  3815. SS.getScopeRep() == QTN->getQualifier() &&
  3816. TransTemplate == Template)
  3817. return Name;
  3818. return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
  3819. TransTemplate);
  3820. }
  3821. if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
  3822. if (SS.getScopeRep()) {
  3823. // These apply to the scope specifier, not the template.
  3824. ObjectType = QualType();
  3825. FirstQualifierInScope = nullptr;
  3826. }
  3827. if (!getDerived().AlwaysRebuild() &&
  3828. SS.getScopeRep() == DTN->getQualifier() &&
  3829. ObjectType.isNull())
  3830. return Name;
  3831. // FIXME: Preserve the location of the "template" keyword.
  3832. SourceLocation TemplateKWLoc = NameLoc;
  3833. if (DTN->isIdentifier()) {
  3834. return getDerived().RebuildTemplateName(SS,
  3835. TemplateKWLoc,
  3836. *DTN->getIdentifier(),
  3837. NameLoc,
  3838. ObjectType,
  3839. FirstQualifierInScope,
  3840. AllowInjectedClassName);
  3841. }
  3842. return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
  3843. DTN->getOperator(), NameLoc,
  3844. ObjectType, AllowInjectedClassName);
  3845. }
  3846. if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
  3847. TemplateDecl *TransTemplate
  3848. = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
  3849. Template));
  3850. if (!TransTemplate)
  3851. return TemplateName();
  3852. if (!getDerived().AlwaysRebuild() &&
  3853. TransTemplate == Template)
  3854. return Name;
  3855. return TemplateName(TransTemplate);
  3856. }
  3857. if (SubstTemplateTemplateParmPackStorage *SubstPack
  3858. = Name.getAsSubstTemplateTemplateParmPack()) {
  3859. TemplateTemplateParmDecl *TransParam
  3860. = cast_or_null<TemplateTemplateParmDecl>(
  3861. getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
  3862. if (!TransParam)
  3863. return TemplateName();
  3864. if (!getDerived().AlwaysRebuild() &&
  3865. TransParam == SubstPack->getParameterPack())
  3866. return Name;
  3867. return getDerived().RebuildTemplateName(TransParam,
  3868. SubstPack->getArgumentPack());
  3869. }
  3870. // These should be getting filtered out before they reach the AST.
  3871. llvm_unreachable("overloaded function decl survived to here");
  3872. }
  3873. template<typename Derived>
  3874. void TreeTransform<Derived>::InventTemplateArgumentLoc(
  3875. const TemplateArgument &Arg,
  3876. TemplateArgumentLoc &Output) {
  3877. Output = getSema().getTrivialTemplateArgumentLoc(
  3878. Arg, QualType(), getDerived().getBaseLocation());
  3879. }
  3880. template <typename Derived>
  3881. bool TreeTransform<Derived>::TransformTemplateArgument(
  3882. const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
  3883. bool Uneval) {
  3884. const TemplateArgument &Arg = Input.getArgument();
  3885. switch (Arg.getKind()) {
  3886. case TemplateArgument::Null:
  3887. case TemplateArgument::Pack:
  3888. llvm_unreachable("Unexpected TemplateArgument");
  3889. case TemplateArgument::Integral:
  3890. case TemplateArgument::NullPtr:
  3891. case TemplateArgument::Declaration: {
  3892. // Transform a resolved template argument straight to a resolved template
  3893. // argument. We get here when substituting into an already-substituted
  3894. // template type argument during concept satisfaction checking.
  3895. QualType T = Arg.getNonTypeTemplateArgumentType();
  3896. QualType NewT = getDerived().TransformType(T);
  3897. if (NewT.isNull())
  3898. return true;
  3899. ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration
  3900. ? Arg.getAsDecl()
  3901. : nullptr;
  3902. ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
  3903. getDerived().getBaseLocation(), D))
  3904. : nullptr;
  3905. if (D && !NewD)
  3906. return true;
  3907. if (NewT == T && D == NewD)
  3908. Output = Input;
  3909. else if (Arg.getKind() == TemplateArgument::Integral)
  3910. Output = TemplateArgumentLoc(
  3911. TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
  3912. TemplateArgumentLocInfo());
  3913. else if (Arg.getKind() == TemplateArgument::NullPtr)
  3914. Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
  3915. TemplateArgumentLocInfo());
  3916. else
  3917. Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
  3918. TemplateArgumentLocInfo());
  3919. return false;
  3920. }
  3921. case TemplateArgument::Type: {
  3922. TypeSourceInfo *DI = Input.getTypeSourceInfo();
  3923. if (!DI)
  3924. DI = InventTypeSourceInfo(Input.getArgument().getAsType());
  3925. DI = getDerived().TransformType(DI);
  3926. if (!DI)
  3927. return true;
  3928. Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
  3929. return false;
  3930. }
  3931. case TemplateArgument::Template: {
  3932. NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
  3933. if (QualifierLoc) {
  3934. QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
  3935. if (!QualifierLoc)
  3936. return true;
  3937. }
  3938. CXXScopeSpec SS;
  3939. SS.Adopt(QualifierLoc);
  3940. TemplateName Template = getDerived().TransformTemplateName(
  3941. SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
  3942. if (Template.isNull())
  3943. return true;
  3944. Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
  3945. QualifierLoc, Input.getTemplateNameLoc());
  3946. return false;
  3947. }
  3948. case TemplateArgument::TemplateExpansion:
  3949. llvm_unreachable("Caller should expand pack expansions");
  3950. case TemplateArgument::Expression: {
  3951. // Template argument expressions are constant expressions.
  3952. EnterExpressionEvaluationContext Unevaluated(
  3953. getSema(),
  3954. Uneval ? Sema::ExpressionEvaluationContext::Unevaluated
  3955. : Sema::ExpressionEvaluationContext::ConstantEvaluated,
  3956. /*LambdaContextDecl=*/nullptr, /*ExprContext=*/
  3957. Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
  3958. Expr *InputExpr = Input.getSourceExpression();
  3959. if (!InputExpr)
  3960. InputExpr = Input.getArgument().getAsExpr();
  3961. ExprResult E = getDerived().TransformExpr(InputExpr);
  3962. E = SemaRef.ActOnConstantExpression(E);
  3963. if (E.isInvalid())
  3964. return true;
  3965. Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
  3966. return false;
  3967. }
  3968. }
  3969. // Work around bogus GCC warning
  3970. return true;
  3971. }
  3972. /// Iterator adaptor that invents template argument location information
  3973. /// for each of the template arguments in its underlying iterator.
  3974. template<typename Derived, typename InputIterator>
  3975. class TemplateArgumentLocInventIterator {
  3976. TreeTransform<Derived> &Self;
  3977. InputIterator Iter;
  3978. public:
  3979. typedef TemplateArgumentLoc value_type;
  3980. typedef TemplateArgumentLoc reference;
  3981. typedef typename std::iterator_traits<InputIterator>::difference_type
  3982. difference_type;
  3983. typedef std::input_iterator_tag iterator_category;
  3984. class pointer {
  3985. TemplateArgumentLoc Arg;
  3986. public:
  3987. explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
  3988. const TemplateArgumentLoc *operator->() const { return &Arg; }
  3989. };
  3990. TemplateArgumentLocInventIterator() { }
  3991. explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
  3992. InputIterator Iter)
  3993. : Self(Self), Iter(Iter) { }
  3994. TemplateArgumentLocInventIterator &operator++() {
  3995. ++Iter;
  3996. return *this;
  3997. }
  3998. TemplateArgumentLocInventIterator operator++(int) {
  3999. TemplateArgumentLocInventIterator Old(*this);
  4000. ++(*this);
  4001. return Old;
  4002. }
  4003. reference operator*() const {
  4004. TemplateArgumentLoc Result;
  4005. Self.InventTemplateArgumentLoc(*Iter, Result);
  4006. return Result;
  4007. }
  4008. pointer operator->() const { return pointer(**this); }
  4009. friend bool operator==(const TemplateArgumentLocInventIterator &X,
  4010. const TemplateArgumentLocInventIterator &Y) {
  4011. return X.Iter == Y.Iter;
  4012. }
  4013. friend bool operator!=(const TemplateArgumentLocInventIterator &X,
  4014. const TemplateArgumentLocInventIterator &Y) {
  4015. return X.Iter != Y.Iter;
  4016. }
  4017. };
  4018. template<typename Derived>
  4019. template<typename InputIterator>
  4020. bool TreeTransform<Derived>::TransformTemplateArguments(
  4021. InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
  4022. bool Uneval) {
  4023. for (; First != Last; ++First) {
  4024. TemplateArgumentLoc Out;
  4025. TemplateArgumentLoc In = *First;
  4026. if (In.getArgument().getKind() == TemplateArgument::Pack) {
  4027. // Unpack argument packs, which we translate them into separate
  4028. // arguments.
  4029. // FIXME: We could do much better if we could guarantee that the
  4030. // TemplateArgumentLocInfo for the pack expansion would be usable for
  4031. // all of the template arguments in the argument pack.
  4032. typedef TemplateArgumentLocInventIterator<Derived,
  4033. TemplateArgument::pack_iterator>
  4034. PackLocIterator;
  4035. if (TransformTemplateArguments(PackLocIterator(*this,
  4036. In.getArgument().pack_begin()),
  4037. PackLocIterator(*this,
  4038. In.getArgument().pack_end()),
  4039. Outputs, Uneval))
  4040. return true;
  4041. continue;
  4042. }
  4043. if (In.getArgument().isPackExpansion()) {
  4044. // We have a pack expansion, for which we will be substituting into
  4045. // the pattern.
  4046. SourceLocation Ellipsis;
  4047. Optional<unsigned> OrigNumExpansions;
  4048. TemplateArgumentLoc Pattern
  4049. = getSema().getTemplateArgumentPackExpansionPattern(
  4050. In, Ellipsis, OrigNumExpansions);
  4051. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  4052. getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
  4053. assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
  4054. // Determine whether the set of unexpanded parameter packs can and should
  4055. // be expanded.
  4056. bool Expand = true;
  4057. bool RetainExpansion = false;
  4058. Optional<unsigned> NumExpansions = OrigNumExpansions;
  4059. if (getDerived().TryExpandParameterPacks(Ellipsis,
  4060. Pattern.getSourceRange(),
  4061. Unexpanded,
  4062. Expand,
  4063. RetainExpansion,
  4064. NumExpansions))
  4065. return true;
  4066. if (!Expand) {
  4067. // The transform has determined that we should perform a simple
  4068. // transformation on the pack expansion, producing another pack
  4069. // expansion.
  4070. TemplateArgumentLoc OutPattern;
  4071. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  4072. if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
  4073. return true;
  4074. Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
  4075. NumExpansions);
  4076. if (Out.getArgument().isNull())
  4077. return true;
  4078. Outputs.addArgument(Out);
  4079. continue;
  4080. }
  4081. // The transform has determined that we should perform an elementwise
  4082. // expansion of the pattern. Do so.
  4083. for (unsigned I = 0; I != *NumExpansions; ++I) {
  4084. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
  4085. if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
  4086. return true;
  4087. if (Out.getArgument().containsUnexpandedParameterPack()) {
  4088. Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
  4089. OrigNumExpansions);
  4090. if (Out.getArgument().isNull())
  4091. return true;
  4092. }
  4093. Outputs.addArgument(Out);
  4094. }
  4095. // If we're supposed to retain a pack expansion, do so by temporarily
  4096. // forgetting the partially-substituted parameter pack.
  4097. if (RetainExpansion) {
  4098. ForgetPartiallySubstitutedPackRAII Forget(getDerived());
  4099. if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
  4100. return true;
  4101. Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
  4102. OrigNumExpansions);
  4103. if (Out.getArgument().isNull())
  4104. return true;
  4105. Outputs.addArgument(Out);
  4106. }
  4107. continue;
  4108. }
  4109. // The simple case:
  4110. if (getDerived().TransformTemplateArgument(In, Out, Uneval))
  4111. return true;
  4112. Outputs.addArgument(Out);
  4113. }
  4114. return false;
  4115. }
  4116. //===----------------------------------------------------------------------===//
  4117. // Type transformation
  4118. //===----------------------------------------------------------------------===//
  4119. template<typename Derived>
  4120. QualType TreeTransform<Derived>::TransformType(QualType T) {
  4121. if (getDerived().AlreadyTransformed(T))
  4122. return T;
  4123. // Temporary workaround. All of these transformations should
  4124. // eventually turn into transformations on TypeLocs.
  4125. TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
  4126. getDerived().getBaseLocation());
  4127. TypeSourceInfo *NewDI = getDerived().TransformType(DI);
  4128. if (!NewDI)
  4129. return QualType();
  4130. return NewDI->getType();
  4131. }
  4132. template<typename Derived>
  4133. TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
  4134. // Refine the base location to the type's location.
  4135. TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
  4136. getDerived().getBaseEntity());
  4137. if (getDerived().AlreadyTransformed(DI->getType()))
  4138. return DI;
  4139. TypeLocBuilder TLB;
  4140. TypeLoc TL = DI->getTypeLoc();
  4141. TLB.reserve(TL.getFullDataSize());
  4142. QualType Result = getDerived().TransformType(TLB, TL);
  4143. if (Result.isNull())
  4144. return nullptr;
  4145. return TLB.getTypeSourceInfo(SemaRef.Context, Result);
  4146. }
  4147. template<typename Derived>
  4148. QualType
  4149. TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
  4150. switch (T.getTypeLocClass()) {
  4151. #define ABSTRACT_TYPELOC(CLASS, PARENT)
  4152. #define TYPELOC(CLASS, PARENT) \
  4153. case TypeLoc::CLASS: \
  4154. return getDerived().Transform##CLASS##Type(TLB, \
  4155. T.castAs<CLASS##TypeLoc>());
  4156. #include "clang/AST/TypeLocNodes.def"
  4157. }
  4158. llvm_unreachable("unhandled type loc!");
  4159. }
  4160. template<typename Derived>
  4161. QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) {
  4162. if (!isa<DependentNameType>(T))
  4163. return TransformType(T);
  4164. if (getDerived().AlreadyTransformed(T))
  4165. return T;
  4166. TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
  4167. getDerived().getBaseLocation());
  4168. TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
  4169. return NewDI ? NewDI->getType() : QualType();
  4170. }
  4171. template<typename Derived>
  4172. TypeSourceInfo *
  4173. TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) {
  4174. if (!isa<DependentNameType>(DI->getType()))
  4175. return TransformType(DI);
  4176. // Refine the base location to the type's location.
  4177. TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
  4178. getDerived().getBaseEntity());
  4179. if (getDerived().AlreadyTransformed(DI->getType()))
  4180. return DI;
  4181. TypeLocBuilder TLB;
  4182. TypeLoc TL = DI->getTypeLoc();
  4183. TLB.reserve(TL.getFullDataSize());
  4184. auto QTL = TL.getAs<QualifiedTypeLoc>();
  4185. if (QTL)
  4186. TL = QTL.getUnqualifiedLoc();
  4187. auto DNTL = TL.castAs<DependentNameTypeLoc>();
  4188. QualType Result = getDerived().TransformDependentNameType(
  4189. TLB, DNTL, /*DeducedTSTContext*/true);
  4190. if (Result.isNull())
  4191. return nullptr;
  4192. if (QTL) {
  4193. Result = getDerived().RebuildQualifiedType(Result, QTL);
  4194. if (Result.isNull())
  4195. return nullptr;
  4196. TLB.TypeWasModifiedSafely(Result);
  4197. }
  4198. return TLB.getTypeSourceInfo(SemaRef.Context, Result);
  4199. }
  4200. template<typename Derived>
  4201. QualType
  4202. TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
  4203. QualifiedTypeLoc T) {
  4204. QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
  4205. if (Result.isNull())
  4206. return QualType();
  4207. Result = getDerived().RebuildQualifiedType(Result, T);
  4208. if (Result.isNull())
  4209. return QualType();
  4210. // RebuildQualifiedType might have updated the type, but not in a way
  4211. // that invalidates the TypeLoc. (There's no location information for
  4212. // qualifiers.)
  4213. TLB.TypeWasModifiedSafely(Result);
  4214. return Result;
  4215. }
  4216. template <typename Derived>
  4217. QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T,
  4218. QualifiedTypeLoc TL) {
  4219. SourceLocation Loc = TL.getBeginLoc();
  4220. Qualifiers Quals = TL.getType().getLocalQualifiers();
  4221. if ((T.getAddressSpace() != LangAS::Default &&
  4222. Quals.getAddressSpace() != LangAS::Default) &&
  4223. T.getAddressSpace() != Quals.getAddressSpace()) {
  4224. SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
  4225. << TL.getType() << T;
  4226. return QualType();
  4227. }
  4228. // C++ [dcl.fct]p7:
  4229. // [When] adding cv-qualifications on top of the function type [...] the
  4230. // cv-qualifiers are ignored.
  4231. if (T->isFunctionType()) {
  4232. T = SemaRef.getASTContext().getAddrSpaceQualType(T,
  4233. Quals.getAddressSpace());
  4234. return T;
  4235. }
  4236. // C++ [dcl.ref]p1:
  4237. // when the cv-qualifiers are introduced through the use of a typedef-name
  4238. // or decltype-specifier [...] the cv-qualifiers are ignored.
  4239. // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
  4240. // applied to a reference type.
  4241. if (T->isReferenceType()) {
  4242. // The only qualifier that applies to a reference type is restrict.
  4243. if (!Quals.hasRestrict())
  4244. return T;
  4245. Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict);
  4246. }
  4247. // Suppress Objective-C lifetime qualifiers if they don't make sense for the
  4248. // resulting type.
  4249. if (Quals.hasObjCLifetime()) {
  4250. if (!T->isObjCLifetimeType() && !T->isDependentType())
  4251. Quals.removeObjCLifetime();
  4252. else if (T.getObjCLifetime()) {
  4253. // Objective-C ARC:
  4254. // A lifetime qualifier applied to a substituted template parameter
  4255. // overrides the lifetime qualifier from the template argument.
  4256. const AutoType *AutoTy;
  4257. if (const SubstTemplateTypeParmType *SubstTypeParam
  4258. = dyn_cast<SubstTemplateTypeParmType>(T)) {
  4259. QualType Replacement = SubstTypeParam->getReplacementType();
  4260. Qualifiers Qs = Replacement.getQualifiers();
  4261. Qs.removeObjCLifetime();
  4262. Replacement = SemaRef.Context.getQualifiedType(
  4263. Replacement.getUnqualifiedType(), Qs);
  4264. T = SemaRef.Context.getSubstTemplateTypeParmType(
  4265. SubstTypeParam->getReplacedParameter(), Replacement);
  4266. } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
  4267. // 'auto' types behave the same way as template parameters.
  4268. QualType Deduced = AutoTy->getDeducedType();
  4269. Qualifiers Qs = Deduced.getQualifiers();
  4270. Qs.removeObjCLifetime();
  4271. Deduced =
  4272. SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
  4273. T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
  4274. AutoTy->isDependentType(),
  4275. /*isPack=*/false,
  4276. AutoTy->getTypeConstraintConcept(),
  4277. AutoTy->getTypeConstraintArguments());
  4278. } else {
  4279. // Otherwise, complain about the addition of a qualifier to an
  4280. // already-qualified type.
  4281. // FIXME: Why is this check not in Sema::BuildQualifiedType?
  4282. SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
  4283. Quals.removeObjCLifetime();
  4284. }
  4285. }
  4286. }
  4287. return SemaRef.BuildQualifiedType(T, Loc, Quals);
  4288. }
  4289. template<typename Derived>
  4290. TypeLoc
  4291. TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
  4292. QualType ObjectType,
  4293. NamedDecl *UnqualLookup,
  4294. CXXScopeSpec &SS) {
  4295. if (getDerived().AlreadyTransformed(TL.getType()))
  4296. return TL;
  4297. TypeSourceInfo *TSI =
  4298. TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
  4299. if (TSI)
  4300. return TSI->getTypeLoc();
  4301. return TypeLoc();
  4302. }
  4303. template<typename Derived>
  4304. TypeSourceInfo *
  4305. TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
  4306. QualType ObjectType,
  4307. NamedDecl *UnqualLookup,
  4308. CXXScopeSpec &SS) {
  4309. if (getDerived().AlreadyTransformed(TSInfo->getType()))
  4310. return TSInfo;
  4311. return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
  4312. UnqualLookup, SS);
  4313. }
  4314. template <typename Derived>
  4315. TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
  4316. TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
  4317. CXXScopeSpec &SS) {
  4318. QualType T = TL.getType();
  4319. assert(!getDerived().AlreadyTransformed(T));
  4320. TypeLocBuilder TLB;
  4321. QualType Result;
  4322. if (isa<TemplateSpecializationType>(T)) {
  4323. TemplateSpecializationTypeLoc SpecTL =
  4324. TL.castAs<TemplateSpecializationTypeLoc>();
  4325. TemplateName Template = getDerived().TransformTemplateName(
  4326. SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
  4327. ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
  4328. if (Template.isNull())
  4329. return nullptr;
  4330. Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
  4331. Template);
  4332. } else if (isa<DependentTemplateSpecializationType>(T)) {
  4333. DependentTemplateSpecializationTypeLoc SpecTL =
  4334. TL.castAs<DependentTemplateSpecializationTypeLoc>();
  4335. TemplateName Template
  4336. = getDerived().RebuildTemplateName(SS,
  4337. SpecTL.getTemplateKeywordLoc(),
  4338. *SpecTL.getTypePtr()->getIdentifier(),
  4339. SpecTL.getTemplateNameLoc(),
  4340. ObjectType, UnqualLookup,
  4341. /*AllowInjectedClassName*/true);
  4342. if (Template.isNull())
  4343. return nullptr;
  4344. Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
  4345. SpecTL,
  4346. Template,
  4347. SS);
  4348. } else {
  4349. // Nothing special needs to be done for these.
  4350. Result = getDerived().TransformType(TLB, TL);
  4351. }
  4352. if (Result.isNull())
  4353. return nullptr;
  4354. return TLB.getTypeSourceInfo(SemaRef.Context, Result);
  4355. }
  4356. template <class TyLoc> static inline
  4357. QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
  4358. TyLoc NewT = TLB.push<TyLoc>(T.getType());
  4359. NewT.setNameLoc(T.getNameLoc());
  4360. return T.getType();
  4361. }
  4362. template<typename Derived>
  4363. QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
  4364. BuiltinTypeLoc T) {
  4365. BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
  4366. NewT.setBuiltinLoc(T.getBuiltinLoc());
  4367. if (T.needsExtraLocalData())
  4368. NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
  4369. return T.getType();
  4370. }
  4371. template<typename Derived>
  4372. QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
  4373. ComplexTypeLoc T) {
  4374. // FIXME: recurse?
  4375. return TransformTypeSpecType(TLB, T);
  4376. }
  4377. template <typename Derived>
  4378. QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
  4379. AdjustedTypeLoc TL) {
  4380. // Adjustments applied during transformation are handled elsewhere.
  4381. return getDerived().TransformType(TLB, TL.getOriginalLoc());
  4382. }
  4383. template<typename Derived>
  4384. QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
  4385. DecayedTypeLoc TL) {
  4386. QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
  4387. if (OriginalType.isNull())
  4388. return QualType();
  4389. QualType Result = TL.getType();
  4390. if (getDerived().AlwaysRebuild() ||
  4391. OriginalType != TL.getOriginalLoc().getType())
  4392. Result = SemaRef.Context.getDecayedType(OriginalType);
  4393. TLB.push<DecayedTypeLoc>(Result);
  4394. // Nothing to set for DecayedTypeLoc.
  4395. return Result;
  4396. }
  4397. template<typename Derived>
  4398. QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
  4399. PointerTypeLoc TL) {
  4400. QualType PointeeType
  4401. = getDerived().TransformType(TLB, TL.getPointeeLoc());
  4402. if (PointeeType.isNull())
  4403. return QualType();
  4404. QualType Result = TL.getType();
  4405. if (PointeeType->getAs<ObjCObjectType>()) {
  4406. // A dependent pointer type 'T *' has is being transformed such
  4407. // that an Objective-C class type is being replaced for 'T'. The
  4408. // resulting pointer type is an ObjCObjectPointerType, not a
  4409. // PointerType.
  4410. Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
  4411. ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
  4412. NewT.setStarLoc(TL.getStarLoc());
  4413. return Result;
  4414. }
  4415. if (getDerived().AlwaysRebuild() ||
  4416. PointeeType != TL.getPointeeLoc().getType()) {
  4417. Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
  4418. if (Result.isNull())
  4419. return QualType();
  4420. }
  4421. // Objective-C ARC can add lifetime qualifiers to the type that we're
  4422. // pointing to.
  4423. TLB.TypeWasModifiedSafely(Result->getPointeeType());
  4424. PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
  4425. NewT.setSigilLoc(TL.getSigilLoc());
  4426. return Result;
  4427. }
  4428. template<typename Derived>
  4429. QualType
  4430. TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
  4431. BlockPointerTypeLoc TL) {
  4432. QualType PointeeType
  4433. = getDerived().TransformType(TLB, TL.getPointeeLoc());
  4434. if (PointeeType.isNull())
  4435. return QualType();
  4436. QualType Result = TL.getType();
  4437. if (getDerived().AlwaysRebuild() ||
  4438. PointeeType != TL.getPointeeLoc().getType()) {
  4439. Result = getDerived().RebuildBlockPointerType(PointeeType,
  4440. TL.getSigilLoc());
  4441. if (Result.isNull())
  4442. return QualType();
  4443. }
  4444. BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
  4445. NewT.setSigilLoc(TL.getSigilLoc());
  4446. return Result;
  4447. }
  4448. /// Transforms a reference type. Note that somewhat paradoxically we
  4449. /// don't care whether the type itself is an l-value type or an r-value
  4450. /// type; we only care if the type was *written* as an l-value type
  4451. /// or an r-value type.
  4452. template<typename Derived>
  4453. QualType
  4454. TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
  4455. ReferenceTypeLoc TL) {
  4456. const ReferenceType *T = TL.getTypePtr();
  4457. // Note that this works with the pointee-as-written.
  4458. QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
  4459. if (PointeeType.isNull())
  4460. return QualType();
  4461. QualType Result = TL.getType();
  4462. if (getDerived().AlwaysRebuild() ||
  4463. PointeeType != T->getPointeeTypeAsWritten()) {
  4464. Result = getDerived().RebuildReferenceType(PointeeType,
  4465. T->isSpelledAsLValue(),
  4466. TL.getSigilLoc());
  4467. if (Result.isNull())
  4468. return QualType();
  4469. }
  4470. // Objective-C ARC can add lifetime qualifiers to the type that we're
  4471. // referring to.
  4472. TLB.TypeWasModifiedSafely(
  4473. Result->castAs<ReferenceType>()->getPointeeTypeAsWritten());
  4474. // r-value references can be rebuilt as l-value references.
  4475. ReferenceTypeLoc NewTL;
  4476. if (isa<LValueReferenceType>(Result))
  4477. NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
  4478. else
  4479. NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
  4480. NewTL.setSigilLoc(TL.getSigilLoc());
  4481. return Result;
  4482. }
  4483. template<typename Derived>
  4484. QualType
  4485. TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
  4486. LValueReferenceTypeLoc TL) {
  4487. return TransformReferenceType(TLB, TL);
  4488. }
  4489. template<typename Derived>
  4490. QualType
  4491. TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
  4492. RValueReferenceTypeLoc TL) {
  4493. return TransformReferenceType(TLB, TL);
  4494. }
  4495. template<typename Derived>
  4496. QualType
  4497. TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
  4498. MemberPointerTypeLoc TL) {
  4499. QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
  4500. if (PointeeType.isNull())
  4501. return QualType();
  4502. TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
  4503. TypeSourceInfo *NewClsTInfo = nullptr;
  4504. if (OldClsTInfo) {
  4505. NewClsTInfo = getDerived().TransformType(OldClsTInfo);
  4506. if (!NewClsTInfo)
  4507. return QualType();
  4508. }
  4509. const MemberPointerType *T = TL.getTypePtr();
  4510. QualType OldClsType = QualType(T->getClass(), 0);
  4511. QualType NewClsType;
  4512. if (NewClsTInfo)
  4513. NewClsType = NewClsTInfo->getType();
  4514. else {
  4515. NewClsType = getDerived().TransformType(OldClsType);
  4516. if (NewClsType.isNull())
  4517. return QualType();
  4518. }
  4519. QualType Result = TL.getType();
  4520. if (getDerived().AlwaysRebuild() ||
  4521. PointeeType != T->getPointeeType() ||
  4522. NewClsType != OldClsType) {
  4523. Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
  4524. TL.getStarLoc());
  4525. if (Result.isNull())
  4526. return QualType();
  4527. }
  4528. // If we had to adjust the pointee type when building a member pointer, make
  4529. // sure to push TypeLoc info for it.
  4530. const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
  4531. if (MPT && PointeeType != MPT->getPointeeType()) {
  4532. assert(isa<AdjustedType>(MPT->getPointeeType()));
  4533. TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
  4534. }
  4535. MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
  4536. NewTL.setSigilLoc(TL.getSigilLoc());
  4537. NewTL.setClassTInfo(NewClsTInfo);
  4538. return Result;
  4539. }
  4540. template<typename Derived>
  4541. QualType
  4542. TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
  4543. ConstantArrayTypeLoc TL) {
  4544. const ConstantArrayType *T = TL.getTypePtr();
  4545. QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
  4546. if (ElementType.isNull())
  4547. return QualType();
  4548. // Prefer the expression from the TypeLoc; the other may have been uniqued.
  4549. Expr *OldSize = TL.getSizeExpr();
  4550. if (!OldSize)
  4551. OldSize = const_cast<Expr*>(T->getSizeExpr());
  4552. Expr *NewSize = nullptr;
  4553. if (OldSize) {
  4554. EnterExpressionEvaluationContext Unevaluated(
  4555. SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
  4556. NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
  4557. NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
  4558. }
  4559. QualType Result = TL.getType();
  4560. if (getDerived().AlwaysRebuild() ||
  4561. ElementType != T->getElementType() ||
  4562. (T->getSizeExpr() && NewSize != OldSize)) {
  4563. Result = getDerived().RebuildConstantArrayType(ElementType,
  4564. T->getSizeModifier(),
  4565. T->getSize(), NewSize,
  4566. T->getIndexTypeCVRQualifiers(),
  4567. TL.getBracketsRange());
  4568. if (Result.isNull())
  4569. return QualType();
  4570. }
  4571. // We might have either a ConstantArrayType or a VariableArrayType now:
  4572. // a ConstantArrayType is allowed to have an element type which is a
  4573. // VariableArrayType if the type is dependent. Fortunately, all array
  4574. // types have the same location layout.
  4575. ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
  4576. NewTL.setLBracketLoc(TL.getLBracketLoc());
  4577. NewTL.setRBracketLoc(TL.getRBracketLoc());
  4578. NewTL.setSizeExpr(NewSize);
  4579. return Result;
  4580. }
  4581. template<typename Derived>
  4582. QualType TreeTransform<Derived>::TransformIncompleteArrayType(
  4583. TypeLocBuilder &TLB,
  4584. IncompleteArrayTypeLoc TL) {
  4585. const IncompleteArrayType *T = TL.getTypePtr();
  4586. QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
  4587. if (ElementType.isNull())
  4588. return QualType();
  4589. QualType Result = TL.getType();
  4590. if (getDerived().AlwaysRebuild() ||
  4591. ElementType != T->getElementType()) {
  4592. Result = getDerived().RebuildIncompleteArrayType(ElementType,
  4593. T->getSizeModifier(),
  4594. T->getIndexTypeCVRQualifiers(),
  4595. TL.getBracketsRange());
  4596. if (Result.isNull())
  4597. return QualType();
  4598. }
  4599. IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
  4600. NewTL.setLBracketLoc(TL.getLBracketLoc());
  4601. NewTL.setRBracketLoc(TL.getRBracketLoc());
  4602. NewTL.setSizeExpr(nullptr);
  4603. return Result;
  4604. }
  4605. template<typename Derived>
  4606. QualType
  4607. TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
  4608. VariableArrayTypeLoc TL) {
  4609. const VariableArrayType *T = TL.getTypePtr();
  4610. QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
  4611. if (ElementType.isNull())
  4612. return QualType();
  4613. ExprResult SizeResult;
  4614. {
  4615. EnterExpressionEvaluationContext Context(
  4616. SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
  4617. SizeResult = getDerived().TransformExpr(T->getSizeExpr());
  4618. }
  4619. if (SizeResult.isInvalid())
  4620. return QualType();
  4621. SizeResult =
  4622. SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
  4623. if (SizeResult.isInvalid())
  4624. return QualType();
  4625. Expr *Size = SizeResult.get();
  4626. QualType Result = TL.getType();
  4627. if (getDerived().AlwaysRebuild() ||
  4628. ElementType != T->getElementType() ||
  4629. Size != T->getSizeExpr()) {
  4630. Result = getDerived().RebuildVariableArrayType(ElementType,
  4631. T->getSizeModifier(),
  4632. Size,
  4633. T->getIndexTypeCVRQualifiers(),
  4634. TL.getBracketsRange());
  4635. if (Result.isNull())
  4636. return QualType();
  4637. }
  4638. // We might have constant size array now, but fortunately it has the same
  4639. // location layout.
  4640. ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
  4641. NewTL.setLBracketLoc(TL.getLBracketLoc());
  4642. NewTL.setRBracketLoc(TL.getRBracketLoc());
  4643. NewTL.setSizeExpr(Size);
  4644. return Result;
  4645. }
  4646. template<typename Derived>
  4647. QualType
  4648. TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
  4649. DependentSizedArrayTypeLoc TL) {
  4650. const DependentSizedArrayType *T = TL.getTypePtr();
  4651. QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
  4652. if (ElementType.isNull())
  4653. return QualType();
  4654. // Array bounds are constant expressions.
  4655. EnterExpressionEvaluationContext Unevaluated(
  4656. SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
  4657. // Prefer the expression from the TypeLoc; the other may have been uniqued.
  4658. Expr *origSize = TL.getSizeExpr();
  4659. if (!origSize) origSize = T->getSizeExpr();
  4660. ExprResult sizeResult
  4661. = getDerived().TransformExpr(origSize);
  4662. sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
  4663. if (sizeResult.isInvalid())
  4664. return QualType();
  4665. Expr *size = sizeResult.get();
  4666. QualType Result = TL.getType();
  4667. if (getDerived().AlwaysRebuild() ||
  4668. ElementType != T->getElementType() ||
  4669. size != origSize) {
  4670. Result = getDerived().RebuildDependentSizedArrayType(ElementType,
  4671. T->getSizeModifier(),
  4672. size,
  4673. T->getIndexTypeCVRQualifiers(),
  4674. TL.getBracketsRange());
  4675. if (Result.isNull())
  4676. return QualType();
  4677. }
  4678. // We might have any sort of array type now, but fortunately they
  4679. // all have the same location layout.
  4680. ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
  4681. NewTL.setLBracketLoc(TL.getLBracketLoc());
  4682. NewTL.setRBracketLoc(TL.getRBracketLoc());
  4683. NewTL.setSizeExpr(size);
  4684. return Result;
  4685. }
  4686. template <typename Derived>
  4687. QualType TreeTransform<Derived>::TransformDependentVectorType(
  4688. TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
  4689. const DependentVectorType *T = TL.getTypePtr();
  4690. QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
  4691. if (ElementType.isNull())
  4692. return QualType();
  4693. EnterExpressionEvaluationContext Unevaluated(
  4694. SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
  4695. ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
  4696. Size = SemaRef.ActOnConstantExpression(Size);
  4697. if (Size.isInvalid())
  4698. return QualType();
  4699. QualType Result = TL.getType();
  4700. if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
  4701. Size.get() != T->getSizeExpr()) {
  4702. Result = getDerived().RebuildDependentVectorType(
  4703. ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
  4704. if (Result.isNull())
  4705. return QualType();
  4706. }
  4707. // Result might be dependent or not.
  4708. if (isa<DependentVectorType>(Result)) {
  4709. DependentVectorTypeLoc NewTL =
  4710. TLB.push<DependentVectorTypeLoc>(Result);
  4711. NewTL.setNameLoc(TL.getNameLoc());
  4712. } else {
  4713. VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
  4714. NewTL.setNameLoc(TL.getNameLoc());
  4715. }
  4716. return Result;
  4717. }
  4718. template<typename Derived>
  4719. QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
  4720. TypeLocBuilder &TLB,
  4721. DependentSizedExtVectorTypeLoc TL) {
  4722. const DependentSizedExtVectorType *T = TL.getTypePtr();
  4723. // FIXME: ext vector locs should be nested
  4724. QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
  4725. if (ElementType.isNull())
  4726. return QualType();
  4727. // Vector sizes are constant expressions.
  4728. EnterExpressionEvaluationContext Unevaluated(
  4729. SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
  4730. ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
  4731. Size = SemaRef.ActOnConstantExpression(Size);
  4732. if (Size.isInvalid())
  4733. return QualType();
  4734. QualType Result = TL.getType();
  4735. if (getDerived().AlwaysRebuild() ||
  4736. ElementType != T->getElementType() ||
  4737. Size.get() != T->getSizeExpr()) {
  4738. Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
  4739. Size.get(),
  4740. T->getAttributeLoc());
  4741. if (Result.isNull())
  4742. return QualType();
  4743. }
  4744. // Result might be dependent or not.
  4745. if (isa<DependentSizedExtVectorType>(Result)) {
  4746. DependentSizedExtVectorTypeLoc NewTL
  4747. = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
  4748. NewTL.setNameLoc(TL.getNameLoc());
  4749. } else {
  4750. ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
  4751. NewTL.setNameLoc(TL.getNameLoc());
  4752. }
  4753. return Result;
  4754. }
  4755. template <typename Derived>
  4756. QualType
  4757. TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
  4758. ConstantMatrixTypeLoc TL) {
  4759. const ConstantMatrixType *T = TL.getTypePtr();
  4760. QualType ElementType = getDerived().TransformType(T->getElementType());
  4761. if (ElementType.isNull())
  4762. return QualType();
  4763. QualType Result = TL.getType();
  4764. if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
  4765. Result = getDerived().RebuildConstantMatrixType(
  4766. ElementType, T->getNumRows(), T->getNumColumns());
  4767. if (Result.isNull())
  4768. return QualType();
  4769. }
  4770. ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
  4771. NewTL.setAttrNameLoc(TL.getAttrNameLoc());
  4772. NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
  4773. NewTL.setAttrRowOperand(TL.getAttrRowOperand());
  4774. NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
  4775. return Result;
  4776. }
  4777. template <typename Derived>
  4778. QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
  4779. TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
  4780. const DependentSizedMatrixType *T = TL.getTypePtr();
  4781. QualType ElementType = getDerived().TransformType(T->getElementType());
  4782. if (ElementType.isNull()) {
  4783. return QualType();
  4784. }
  4785. // Matrix dimensions are constant expressions.
  4786. EnterExpressionEvaluationContext Unevaluated(
  4787. SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
  4788. Expr *origRows = TL.getAttrRowOperand();
  4789. if (!origRows)
  4790. origRows = T->getRowExpr();
  4791. Expr *origColumns = TL.getAttrColumnOperand();
  4792. if (!origColumns)
  4793. origColumns = T->getColumnExpr();
  4794. ExprResult rowResult = getDerived().TransformExpr(origRows);
  4795. rowResult = SemaRef.ActOnConstantExpression(rowResult);
  4796. if (rowResult.isInvalid())
  4797. return QualType();
  4798. ExprResult columnResult = getDerived().TransformExpr(origColumns);
  4799. columnResult = SemaRef.ActOnConstantExpression(columnResult);
  4800. if (columnResult.isInvalid())
  4801. return QualType();
  4802. Expr *rows = rowResult.get();
  4803. Expr *columns = columnResult.get();
  4804. QualType Result = TL.getType();
  4805. if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
  4806. rows != origRows || columns != origColumns) {
  4807. Result = getDerived().RebuildDependentSizedMatrixType(
  4808. ElementType, rows, columns, T->getAttributeLoc());
  4809. if (Result.isNull())
  4810. return QualType();
  4811. }
  4812. // We might have any sort of matrix type now, but fortunately they
  4813. // all have the same location layout.
  4814. MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
  4815. NewTL.setAttrNameLoc(TL.getAttrNameLoc());
  4816. NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
  4817. NewTL.setAttrRowOperand(rows);
  4818. NewTL.setAttrColumnOperand(columns);
  4819. return Result;
  4820. }
  4821. template <typename Derived>
  4822. QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
  4823. TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
  4824. const DependentAddressSpaceType *T = TL.getTypePtr();
  4825. QualType pointeeType = getDerived().TransformType(T->getPointeeType());
  4826. if (pointeeType.isNull())
  4827. return QualType();
  4828. // Address spaces are constant expressions.
  4829. EnterExpressionEvaluationContext Unevaluated(
  4830. SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
  4831. ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
  4832. AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
  4833. if (AddrSpace.isInvalid())
  4834. return QualType();
  4835. QualType Result = TL.getType();
  4836. if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
  4837. AddrSpace.get() != T->getAddrSpaceExpr()) {
  4838. Result = getDerived().RebuildDependentAddressSpaceType(
  4839. pointeeType, AddrSpace.get(), T->getAttributeLoc());
  4840. if (Result.isNull())
  4841. return QualType();
  4842. }
  4843. // Result might be dependent or not.
  4844. if (isa<DependentAddressSpaceType>(Result)) {
  4845. DependentAddressSpaceTypeLoc NewTL =
  4846. TLB.push<DependentAddressSpaceTypeLoc>(Result);
  4847. NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
  4848. NewTL.setAttrExprOperand(TL.getAttrExprOperand());
  4849. NewTL.setAttrNameLoc(TL.getAttrNameLoc());
  4850. } else {
  4851. TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
  4852. Result, getDerived().getBaseLocation());
  4853. TransformType(TLB, DI->getTypeLoc());
  4854. }
  4855. return Result;
  4856. }
  4857. template <typename Derived>
  4858. QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
  4859. VectorTypeLoc TL) {
  4860. const VectorType *T = TL.getTypePtr();
  4861. QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
  4862. if (ElementType.isNull())
  4863. return QualType();
  4864. QualType Result = TL.getType();
  4865. if (getDerived().AlwaysRebuild() ||
  4866. ElementType != T->getElementType()) {
  4867. Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
  4868. T->getVectorKind());
  4869. if (Result.isNull())
  4870. return QualType();
  4871. }
  4872. VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
  4873. NewTL.setNameLoc(TL.getNameLoc());
  4874. return Result;
  4875. }
  4876. template<typename Derived>
  4877. QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
  4878. ExtVectorTypeLoc TL) {
  4879. const VectorType *T = TL.getTypePtr();
  4880. QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
  4881. if (ElementType.isNull())
  4882. return QualType();
  4883. QualType Result = TL.getType();
  4884. if (getDerived().AlwaysRebuild() ||
  4885. ElementType != T->getElementType()) {
  4886. Result = getDerived().RebuildExtVectorType(ElementType,
  4887. T->getNumElements(),
  4888. /*FIXME*/ SourceLocation());
  4889. if (Result.isNull())
  4890. return QualType();
  4891. }
  4892. ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
  4893. NewTL.setNameLoc(TL.getNameLoc());
  4894. return Result;
  4895. }
  4896. template <typename Derived>
  4897. ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
  4898. ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
  4899. bool ExpectParameterPack) {
  4900. TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
  4901. TypeSourceInfo *NewDI = nullptr;
  4902. if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
  4903. // If we're substituting into a pack expansion type and we know the
  4904. // length we want to expand to, just substitute for the pattern.
  4905. TypeLoc OldTL = OldDI->getTypeLoc();
  4906. PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
  4907. TypeLocBuilder TLB;
  4908. TypeLoc NewTL = OldDI->getTypeLoc();
  4909. TLB.reserve(NewTL.getFullDataSize());
  4910. QualType Result = getDerived().TransformType(TLB,
  4911. OldExpansionTL.getPatternLoc());
  4912. if (Result.isNull())
  4913. return nullptr;
  4914. Result = RebuildPackExpansionType(Result,
  4915. OldExpansionTL.getPatternLoc().getSourceRange(),
  4916. OldExpansionTL.getEllipsisLoc(),
  4917. NumExpansions);
  4918. if (Result.isNull())
  4919. return nullptr;
  4920. PackExpansionTypeLoc NewExpansionTL
  4921. = TLB.push<PackExpansionTypeLoc>(Result);
  4922. NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
  4923. NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
  4924. } else
  4925. NewDI = getDerived().TransformType(OldDI);
  4926. if (!NewDI)
  4927. return nullptr;
  4928. if (NewDI == OldDI && indexAdjustment == 0)
  4929. return OldParm;
  4930. ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
  4931. OldParm->getDeclContext(),
  4932. OldParm->getInnerLocStart(),
  4933. OldParm->getLocation(),
  4934. OldParm->getIdentifier(),
  4935. NewDI->getType(),
  4936. NewDI,
  4937. OldParm->getStorageClass(),
  4938. /* DefArg */ nullptr);
  4939. newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
  4940. OldParm->getFunctionScopeIndex() + indexAdjustment);
  4941. transformedLocalDecl(OldParm, {newParm});
  4942. return newParm;
  4943. }
  4944. template <typename Derived>
  4945. bool TreeTransform<Derived>::TransformFunctionTypeParams(
  4946. SourceLocation Loc, ArrayRef<ParmVarDecl *> Params,
  4947. const QualType *ParamTypes,
  4948. const FunctionProtoType::ExtParameterInfo *ParamInfos,
  4949. SmallVectorImpl<QualType> &OutParamTypes,
  4950. SmallVectorImpl<ParmVarDecl *> *PVars,
  4951. Sema::ExtParameterInfoBuilder &PInfos) {
  4952. int indexAdjustment = 0;
  4953. unsigned NumParams = Params.size();
  4954. for (unsigned i = 0; i != NumParams; ++i) {
  4955. if (ParmVarDecl *OldParm = Params[i]) {
  4956. assert(OldParm->getFunctionScopeIndex() == i);
  4957. Optional<unsigned> NumExpansions;
  4958. ParmVarDecl *NewParm = nullptr;
  4959. if (OldParm->isParameterPack()) {
  4960. // We have a function parameter pack that may need to be expanded.
  4961. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  4962. // Find the parameter packs that could be expanded.
  4963. TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
  4964. PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
  4965. TypeLoc Pattern = ExpansionTL.getPatternLoc();
  4966. SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
  4967. // Determine whether we should expand the parameter packs.
  4968. bool ShouldExpand = false;
  4969. bool RetainExpansion = false;
  4970. Optional<unsigned> OrigNumExpansions;
  4971. if (Unexpanded.size() > 0) {
  4972. OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
  4973. NumExpansions = OrigNumExpansions;
  4974. if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
  4975. Pattern.getSourceRange(),
  4976. Unexpanded,
  4977. ShouldExpand,
  4978. RetainExpansion,
  4979. NumExpansions)) {
  4980. return true;
  4981. }
  4982. } else {
  4983. #ifndef NDEBUG
  4984. const AutoType *AT =
  4985. Pattern.getType().getTypePtr()->getContainedAutoType();
  4986. assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
  4987. "Could not find parameter packs or undeduced auto type!");
  4988. #endif
  4989. }
  4990. if (ShouldExpand) {
  4991. // Expand the function parameter pack into multiple, separate
  4992. // parameters.
  4993. getDerived().ExpandingFunctionParameterPack(OldParm);
  4994. for (unsigned I = 0; I != *NumExpansions; ++I) {
  4995. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
  4996. ParmVarDecl *NewParm
  4997. = getDerived().TransformFunctionTypeParam(OldParm,
  4998. indexAdjustment++,
  4999. OrigNumExpansions,
  5000. /*ExpectParameterPack=*/false);
  5001. if (!NewParm)
  5002. return true;
  5003. if (ParamInfos)
  5004. PInfos.set(OutParamTypes.size(), ParamInfos[i]);
  5005. OutParamTypes.push_back(NewParm->getType());
  5006. if (PVars)
  5007. PVars->push_back(NewParm);
  5008. }
  5009. // If we're supposed to retain a pack expansion, do so by temporarily
  5010. // forgetting the partially-substituted parameter pack.
  5011. if (RetainExpansion) {
  5012. ForgetPartiallySubstitutedPackRAII Forget(getDerived());
  5013. ParmVarDecl *NewParm
  5014. = getDerived().TransformFunctionTypeParam(OldParm,
  5015. indexAdjustment++,
  5016. OrigNumExpansions,
  5017. /*ExpectParameterPack=*/false);
  5018. if (!NewParm)
  5019. return true;
  5020. if (ParamInfos)
  5021. PInfos.set(OutParamTypes.size(), ParamInfos[i]);
  5022. OutParamTypes.push_back(NewParm->getType());
  5023. if (PVars)
  5024. PVars->push_back(NewParm);
  5025. }
  5026. // The next parameter should have the same adjustment as the
  5027. // last thing we pushed, but we post-incremented indexAdjustment
  5028. // on every push. Also, if we push nothing, the adjustment should
  5029. // go down by one.
  5030. indexAdjustment--;
  5031. // We're done with the pack expansion.
  5032. continue;
  5033. }
  5034. // We'll substitute the parameter now without expanding the pack
  5035. // expansion.
  5036. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  5037. NewParm = getDerived().TransformFunctionTypeParam(OldParm,
  5038. indexAdjustment,
  5039. NumExpansions,
  5040. /*ExpectParameterPack=*/true);
  5041. assert(NewParm->isParameterPack() &&
  5042. "Parameter pack no longer a parameter pack after "
  5043. "transformation.");
  5044. } else {
  5045. NewParm = getDerived().TransformFunctionTypeParam(
  5046. OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
  5047. }
  5048. if (!NewParm)
  5049. return true;
  5050. if (ParamInfos)
  5051. PInfos.set(OutParamTypes.size(), ParamInfos[i]);
  5052. OutParamTypes.push_back(NewParm->getType());
  5053. if (PVars)
  5054. PVars->push_back(NewParm);
  5055. continue;
  5056. }
  5057. // Deal with the possibility that we don't have a parameter
  5058. // declaration for this parameter.
  5059. QualType OldType = ParamTypes[i];
  5060. bool IsPackExpansion = false;
  5061. Optional<unsigned> NumExpansions;
  5062. QualType NewType;
  5063. if (const PackExpansionType *Expansion
  5064. = dyn_cast<PackExpansionType>(OldType)) {
  5065. // We have a function parameter pack that may need to be expanded.
  5066. QualType Pattern = Expansion->getPattern();
  5067. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  5068. getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
  5069. // Determine whether we should expand the parameter packs.
  5070. bool ShouldExpand = false;
  5071. bool RetainExpansion = false;
  5072. if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
  5073. Unexpanded,
  5074. ShouldExpand,
  5075. RetainExpansion,
  5076. NumExpansions)) {
  5077. return true;
  5078. }
  5079. if (ShouldExpand) {
  5080. // Expand the function parameter pack into multiple, separate
  5081. // parameters.
  5082. for (unsigned I = 0; I != *NumExpansions; ++I) {
  5083. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
  5084. QualType NewType = getDerived().TransformType(Pattern);
  5085. if (NewType.isNull())
  5086. return true;
  5087. if (NewType->containsUnexpandedParameterPack()) {
  5088. NewType =
  5089. getSema().getASTContext().getPackExpansionType(NewType, None);
  5090. if (NewType.isNull())
  5091. return true;
  5092. }
  5093. if (ParamInfos)
  5094. PInfos.set(OutParamTypes.size(), ParamInfos[i]);
  5095. OutParamTypes.push_back(NewType);
  5096. if (PVars)
  5097. PVars->push_back(nullptr);
  5098. }
  5099. // We're done with the pack expansion.
  5100. continue;
  5101. }
  5102. // If we're supposed to retain a pack expansion, do so by temporarily
  5103. // forgetting the partially-substituted parameter pack.
  5104. if (RetainExpansion) {
  5105. ForgetPartiallySubstitutedPackRAII Forget(getDerived());
  5106. QualType NewType = getDerived().TransformType(Pattern);
  5107. if (NewType.isNull())
  5108. return true;
  5109. if (ParamInfos)
  5110. PInfos.set(OutParamTypes.size(), ParamInfos[i]);
  5111. OutParamTypes.push_back(NewType);
  5112. if (PVars)
  5113. PVars->push_back(nullptr);
  5114. }
  5115. // We'll substitute the parameter now without expanding the pack
  5116. // expansion.
  5117. OldType = Expansion->getPattern();
  5118. IsPackExpansion = true;
  5119. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  5120. NewType = getDerived().TransformType(OldType);
  5121. } else {
  5122. NewType = getDerived().TransformType(OldType);
  5123. }
  5124. if (NewType.isNull())
  5125. return true;
  5126. if (IsPackExpansion)
  5127. NewType = getSema().Context.getPackExpansionType(NewType,
  5128. NumExpansions);
  5129. if (ParamInfos)
  5130. PInfos.set(OutParamTypes.size(), ParamInfos[i]);
  5131. OutParamTypes.push_back(NewType);
  5132. if (PVars)
  5133. PVars->push_back(nullptr);
  5134. }
  5135. #ifndef NDEBUG
  5136. if (PVars) {
  5137. for (unsigned i = 0, e = PVars->size(); i != e; ++i)
  5138. if (ParmVarDecl *parm = (*PVars)[i])
  5139. assert(parm->getFunctionScopeIndex() == i);
  5140. }
  5141. #endif
  5142. return false;
  5143. }
  5144. template<typename Derived>
  5145. QualType
  5146. TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
  5147. FunctionProtoTypeLoc TL) {
  5148. SmallVector<QualType, 4> ExceptionStorage;
  5149. TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
  5150. return getDerived().TransformFunctionProtoType(
  5151. TLB, TL, nullptr, Qualifiers(),
  5152. [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
  5153. return This->getDerived().TransformExceptionSpec(
  5154. TL.getBeginLoc(), ESI, ExceptionStorage, Changed);
  5155. });
  5156. }
  5157. template<typename Derived> template<typename Fn>
  5158. QualType TreeTransform<Derived>::TransformFunctionProtoType(
  5159. TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
  5160. Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
  5161. // Transform the parameters and return type.
  5162. //
  5163. // We are required to instantiate the params and return type in source order.
  5164. // When the function has a trailing return type, we instantiate the
  5165. // parameters before the return type, since the return type can then refer
  5166. // to the parameters themselves (via decltype, sizeof, etc.).
  5167. //
  5168. SmallVector<QualType, 4> ParamTypes;
  5169. SmallVector<ParmVarDecl*, 4> ParamDecls;
  5170. Sema::ExtParameterInfoBuilder ExtParamInfos;
  5171. const FunctionProtoType *T = TL.getTypePtr();
  5172. QualType ResultType;
  5173. if (T->hasTrailingReturn()) {
  5174. if (getDerived().TransformFunctionTypeParams(
  5175. TL.getBeginLoc(), TL.getParams(),
  5176. TL.getTypePtr()->param_type_begin(),
  5177. T->getExtParameterInfosOrNull(),
  5178. ParamTypes, &ParamDecls, ExtParamInfos))
  5179. return QualType();
  5180. {
  5181. // C++11 [expr.prim.general]p3:
  5182. // If a declaration declares a member function or member function
  5183. // template of a class X, the expression this is a prvalue of type
  5184. // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
  5185. // and the end of the function-definition, member-declarator, or
  5186. // declarator.
  5187. Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
  5188. ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
  5189. if (ResultType.isNull())
  5190. return QualType();
  5191. }
  5192. }
  5193. else {
  5194. ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
  5195. if (ResultType.isNull())
  5196. return QualType();
  5197. if (getDerived().TransformFunctionTypeParams(
  5198. TL.getBeginLoc(), TL.getParams(),
  5199. TL.getTypePtr()->param_type_begin(),
  5200. T->getExtParameterInfosOrNull(),
  5201. ParamTypes, &ParamDecls, ExtParamInfos))
  5202. return QualType();
  5203. }
  5204. FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
  5205. bool EPIChanged = false;
  5206. if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
  5207. return QualType();
  5208. // Handle extended parameter information.
  5209. if (auto NewExtParamInfos =
  5210. ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
  5211. if (!EPI.ExtParameterInfos ||
  5212. llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams())
  5213. != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) {
  5214. EPIChanged = true;
  5215. }
  5216. EPI.ExtParameterInfos = NewExtParamInfos;
  5217. } else if (EPI.ExtParameterInfos) {
  5218. EPIChanged = true;
  5219. EPI.ExtParameterInfos = nullptr;
  5220. }
  5221. QualType Result = TL.getType();
  5222. if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
  5223. T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
  5224. Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
  5225. if (Result.isNull())
  5226. return QualType();
  5227. }
  5228. FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
  5229. NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
  5230. NewTL.setLParenLoc(TL.getLParenLoc());
  5231. NewTL.setRParenLoc(TL.getRParenLoc());
  5232. NewTL.setExceptionSpecRange(TL.getExceptionSpecRange());
  5233. NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
  5234. for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
  5235. NewTL.setParam(i, ParamDecls[i]);
  5236. return Result;
  5237. }
  5238. template<typename Derived>
  5239. bool TreeTransform<Derived>::TransformExceptionSpec(
  5240. SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
  5241. SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
  5242. assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
  5243. // Instantiate a dynamic noexcept expression, if any.
  5244. if (isComputedNoexcept(ESI.Type)) {
  5245. EnterExpressionEvaluationContext Unevaluated(
  5246. getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated);
  5247. ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
  5248. if (NoexceptExpr.isInvalid())
  5249. return true;
  5250. ExceptionSpecificationType EST = ESI.Type;
  5251. NoexceptExpr =
  5252. getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
  5253. if (NoexceptExpr.isInvalid())
  5254. return true;
  5255. if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
  5256. Changed = true;
  5257. ESI.NoexceptExpr = NoexceptExpr.get();
  5258. ESI.Type = EST;
  5259. }
  5260. if (ESI.Type != EST_Dynamic)
  5261. return false;
  5262. // Instantiate a dynamic exception specification's type.
  5263. for (QualType T : ESI.Exceptions) {
  5264. if (const PackExpansionType *PackExpansion =
  5265. T->getAs<PackExpansionType>()) {
  5266. Changed = true;
  5267. // We have a pack expansion. Instantiate it.
  5268. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  5269. SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
  5270. Unexpanded);
  5271. assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
  5272. // Determine whether the set of unexpanded parameter packs can and
  5273. // should
  5274. // be expanded.
  5275. bool Expand = false;
  5276. bool RetainExpansion = false;
  5277. Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
  5278. // FIXME: Track the location of the ellipsis (and track source location
  5279. // information for the types in the exception specification in general).
  5280. if (getDerived().TryExpandParameterPacks(
  5281. Loc, SourceRange(), Unexpanded, Expand,
  5282. RetainExpansion, NumExpansions))
  5283. return true;
  5284. if (!Expand) {
  5285. // We can't expand this pack expansion into separate arguments yet;
  5286. // just substitute into the pattern and create a new pack expansion
  5287. // type.
  5288. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  5289. QualType U = getDerived().TransformType(PackExpansion->getPattern());
  5290. if (U.isNull())
  5291. return true;
  5292. U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
  5293. Exceptions.push_back(U);
  5294. continue;
  5295. }
  5296. // Substitute into the pack expansion pattern for each slice of the
  5297. // pack.
  5298. for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
  5299. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
  5300. QualType U = getDerived().TransformType(PackExpansion->getPattern());
  5301. if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
  5302. return true;
  5303. Exceptions.push_back(U);
  5304. }
  5305. } else {
  5306. QualType U = getDerived().TransformType(T);
  5307. if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
  5308. return true;
  5309. if (T != U)
  5310. Changed = true;
  5311. Exceptions.push_back(U);
  5312. }
  5313. }
  5314. ESI.Exceptions = Exceptions;
  5315. if (ESI.Exceptions.empty())
  5316. ESI.Type = EST_DynamicNone;
  5317. return false;
  5318. }
  5319. template<typename Derived>
  5320. QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
  5321. TypeLocBuilder &TLB,
  5322. FunctionNoProtoTypeLoc TL) {
  5323. const FunctionNoProtoType *T = TL.getTypePtr();
  5324. QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
  5325. if (ResultType.isNull())
  5326. return QualType();
  5327. QualType Result = TL.getType();
  5328. if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
  5329. Result = getDerived().RebuildFunctionNoProtoType(ResultType);
  5330. FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
  5331. NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
  5332. NewTL.setLParenLoc(TL.getLParenLoc());
  5333. NewTL.setRParenLoc(TL.getRParenLoc());
  5334. NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
  5335. return Result;
  5336. }
  5337. template <typename Derived>
  5338. QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
  5339. TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
  5340. const UnresolvedUsingType *T = TL.getTypePtr();
  5341. Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
  5342. if (!D)
  5343. return QualType();
  5344. QualType Result = TL.getType();
  5345. if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
  5346. Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
  5347. if (Result.isNull())
  5348. return QualType();
  5349. }
  5350. // We might get an arbitrary type spec type back. We should at
  5351. // least always get a type spec type, though.
  5352. TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
  5353. NewTL.setNameLoc(TL.getNameLoc());
  5354. return Result;
  5355. }
  5356. template <typename Derived>
  5357. QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
  5358. UsingTypeLoc TL) {
  5359. const UsingType *T = TL.getTypePtr();
  5360. auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
  5361. TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
  5362. if (!Found)
  5363. return QualType();
  5364. QualType Underlying = getDerived().TransformType(T->desugar());
  5365. if (Underlying.isNull())
  5366. return QualType();
  5367. QualType Result = TL.getType();
  5368. if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() ||
  5369. Underlying != T->getUnderlyingType()) {
  5370. Result = getDerived().RebuildUsingType(Found, Underlying);
  5371. if (Result.isNull())
  5372. return QualType();
  5373. }
  5374. TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
  5375. return Result;
  5376. }
  5377. template<typename Derived>
  5378. QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
  5379. TypedefTypeLoc TL) {
  5380. const TypedefType *T = TL.getTypePtr();
  5381. TypedefNameDecl *Typedef
  5382. = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
  5383. T->getDecl()));
  5384. if (!Typedef)
  5385. return QualType();
  5386. QualType Result = TL.getType();
  5387. if (getDerived().AlwaysRebuild() ||
  5388. Typedef != T->getDecl()) {
  5389. Result = getDerived().RebuildTypedefType(Typedef);
  5390. if (Result.isNull())
  5391. return QualType();
  5392. }
  5393. TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
  5394. NewTL.setNameLoc(TL.getNameLoc());
  5395. return Result;
  5396. }
  5397. template<typename Derived>
  5398. QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
  5399. TypeOfExprTypeLoc TL) {
  5400. // typeof expressions are not potentially evaluated contexts
  5401. EnterExpressionEvaluationContext Unevaluated(
  5402. SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
  5403. Sema::ReuseLambdaContextDecl);
  5404. ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
  5405. if (E.isInvalid())
  5406. return QualType();
  5407. E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
  5408. if (E.isInvalid())
  5409. return QualType();
  5410. QualType Result = TL.getType();
  5411. if (getDerived().AlwaysRebuild() ||
  5412. E.get() != TL.getUnderlyingExpr()) {
  5413. Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
  5414. if (Result.isNull())
  5415. return QualType();
  5416. }
  5417. else E.get();
  5418. TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
  5419. NewTL.setTypeofLoc(TL.getTypeofLoc());
  5420. NewTL.setLParenLoc(TL.getLParenLoc());
  5421. NewTL.setRParenLoc(TL.getRParenLoc());
  5422. return Result;
  5423. }
  5424. template<typename Derived>
  5425. QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
  5426. TypeOfTypeLoc TL) {
  5427. TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
  5428. TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
  5429. if (!New_Under_TI)
  5430. return QualType();
  5431. QualType Result = TL.getType();
  5432. if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
  5433. Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
  5434. if (Result.isNull())
  5435. return QualType();
  5436. }
  5437. TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
  5438. NewTL.setTypeofLoc(TL.getTypeofLoc());
  5439. NewTL.setLParenLoc(TL.getLParenLoc());
  5440. NewTL.setRParenLoc(TL.getRParenLoc());
  5441. NewTL.setUnderlyingTInfo(New_Under_TI);
  5442. return Result;
  5443. }
  5444. template<typename Derived>
  5445. QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
  5446. DecltypeTypeLoc TL) {
  5447. const DecltypeType *T = TL.getTypePtr();
  5448. // decltype expressions are not potentially evaluated contexts
  5449. EnterExpressionEvaluationContext Unevaluated(
  5450. SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr,
  5451. Sema::ExpressionEvaluationContextRecord::EK_Decltype);
  5452. ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
  5453. if (E.isInvalid())
  5454. return QualType();
  5455. E = getSema().ActOnDecltypeExpression(E.get());
  5456. if (E.isInvalid())
  5457. return QualType();
  5458. QualType Result = TL.getType();
  5459. if (getDerived().AlwaysRebuild() ||
  5460. E.get() != T->getUnderlyingExpr()) {
  5461. Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
  5462. if (Result.isNull())
  5463. return QualType();
  5464. }
  5465. else E.get();
  5466. DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
  5467. NewTL.setDecltypeLoc(TL.getDecltypeLoc());
  5468. NewTL.setRParenLoc(TL.getRParenLoc());
  5469. return Result;
  5470. }
  5471. template<typename Derived>
  5472. QualType TreeTransform<Derived>::TransformUnaryTransformType(
  5473. TypeLocBuilder &TLB,
  5474. UnaryTransformTypeLoc TL) {
  5475. QualType Result = TL.getType();
  5476. if (Result->isDependentType()) {
  5477. const UnaryTransformType *T = TL.getTypePtr();
  5478. QualType NewBase =
  5479. getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
  5480. Result = getDerived().RebuildUnaryTransformType(NewBase,
  5481. T->getUTTKind(),
  5482. TL.getKWLoc());
  5483. if (Result.isNull())
  5484. return QualType();
  5485. }
  5486. UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
  5487. NewTL.setKWLoc(TL.getKWLoc());
  5488. NewTL.setParensRange(TL.getParensRange());
  5489. NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
  5490. return Result;
  5491. }
  5492. template<typename Derived>
  5493. QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
  5494. TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
  5495. const DeducedTemplateSpecializationType *T = TL.getTypePtr();
  5496. CXXScopeSpec SS;
  5497. TemplateName TemplateName = getDerived().TransformTemplateName(
  5498. SS, T->getTemplateName(), TL.getTemplateNameLoc());
  5499. if (TemplateName.isNull())
  5500. return QualType();
  5501. QualType OldDeduced = T->getDeducedType();
  5502. QualType NewDeduced;
  5503. if (!OldDeduced.isNull()) {
  5504. NewDeduced = getDerived().TransformType(OldDeduced);
  5505. if (NewDeduced.isNull())
  5506. return QualType();
  5507. }
  5508. QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
  5509. TemplateName, NewDeduced);
  5510. if (Result.isNull())
  5511. return QualType();
  5512. DeducedTemplateSpecializationTypeLoc NewTL =
  5513. TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
  5514. NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
  5515. return Result;
  5516. }
  5517. template<typename Derived>
  5518. QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
  5519. RecordTypeLoc TL) {
  5520. const RecordType *T = TL.getTypePtr();
  5521. RecordDecl *Record
  5522. = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
  5523. T->getDecl()));
  5524. if (!Record)
  5525. return QualType();
  5526. QualType Result = TL.getType();
  5527. if (getDerived().AlwaysRebuild() ||
  5528. Record != T->getDecl()) {
  5529. Result = getDerived().RebuildRecordType(Record);
  5530. if (Result.isNull())
  5531. return QualType();
  5532. }
  5533. RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
  5534. NewTL.setNameLoc(TL.getNameLoc());
  5535. return Result;
  5536. }
  5537. template<typename Derived>
  5538. QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
  5539. EnumTypeLoc TL) {
  5540. const EnumType *T = TL.getTypePtr();
  5541. EnumDecl *Enum
  5542. = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
  5543. T->getDecl()));
  5544. if (!Enum)
  5545. return QualType();
  5546. QualType Result = TL.getType();
  5547. if (getDerived().AlwaysRebuild() ||
  5548. Enum != T->getDecl()) {
  5549. Result = getDerived().RebuildEnumType(Enum);
  5550. if (Result.isNull())
  5551. return QualType();
  5552. }
  5553. EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
  5554. NewTL.setNameLoc(TL.getNameLoc());
  5555. return Result;
  5556. }
  5557. template<typename Derived>
  5558. QualType TreeTransform<Derived>::TransformInjectedClassNameType(
  5559. TypeLocBuilder &TLB,
  5560. InjectedClassNameTypeLoc TL) {
  5561. Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
  5562. TL.getTypePtr()->getDecl());
  5563. if (!D) return QualType();
  5564. QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
  5565. TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
  5566. return T;
  5567. }
  5568. template<typename Derived>
  5569. QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
  5570. TypeLocBuilder &TLB,
  5571. TemplateTypeParmTypeLoc TL) {
  5572. return TransformTypeSpecType(TLB, TL);
  5573. }
  5574. template<typename Derived>
  5575. QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
  5576. TypeLocBuilder &TLB,
  5577. SubstTemplateTypeParmTypeLoc TL) {
  5578. const SubstTemplateTypeParmType *T = TL.getTypePtr();
  5579. // Substitute into the replacement type, which itself might involve something
  5580. // that needs to be transformed. This only tends to occur with default
  5581. // template arguments of template template parameters.
  5582. TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
  5583. QualType Replacement = getDerived().TransformType(T->getReplacementType());
  5584. if (Replacement.isNull())
  5585. return QualType();
  5586. // Always canonicalize the replacement type.
  5587. Replacement = SemaRef.Context.getCanonicalType(Replacement);
  5588. QualType Result
  5589. = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
  5590. Replacement);
  5591. // Propagate type-source information.
  5592. SubstTemplateTypeParmTypeLoc NewTL
  5593. = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
  5594. NewTL.setNameLoc(TL.getNameLoc());
  5595. return Result;
  5596. }
  5597. template<typename Derived>
  5598. QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
  5599. TypeLocBuilder &TLB,
  5600. SubstTemplateTypeParmPackTypeLoc TL) {
  5601. return TransformTypeSpecType(TLB, TL);
  5602. }
  5603. template<typename Derived>
  5604. QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
  5605. TypeLocBuilder &TLB,
  5606. TemplateSpecializationTypeLoc TL) {
  5607. const TemplateSpecializationType *T = TL.getTypePtr();
  5608. // The nested-name-specifier never matters in a TemplateSpecializationType,
  5609. // because we can't have a dependent nested-name-specifier anyway.
  5610. CXXScopeSpec SS;
  5611. TemplateName Template
  5612. = getDerived().TransformTemplateName(SS, T->getTemplateName(),
  5613. TL.getTemplateNameLoc());
  5614. if (Template.isNull())
  5615. return QualType();
  5616. return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
  5617. }
  5618. template<typename Derived>
  5619. QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
  5620. AtomicTypeLoc TL) {
  5621. QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
  5622. if (ValueType.isNull())
  5623. return QualType();
  5624. QualType Result = TL.getType();
  5625. if (getDerived().AlwaysRebuild() ||
  5626. ValueType != TL.getValueLoc().getType()) {
  5627. Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
  5628. if (Result.isNull())
  5629. return QualType();
  5630. }
  5631. AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
  5632. NewTL.setKWLoc(TL.getKWLoc());
  5633. NewTL.setLParenLoc(TL.getLParenLoc());
  5634. NewTL.setRParenLoc(TL.getRParenLoc());
  5635. return Result;
  5636. }
  5637. template <typename Derived>
  5638. QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
  5639. PipeTypeLoc TL) {
  5640. QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
  5641. if (ValueType.isNull())
  5642. return QualType();
  5643. QualType Result = TL.getType();
  5644. if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
  5645. const PipeType *PT = Result->castAs<PipeType>();
  5646. bool isReadPipe = PT->isReadOnly();
  5647. Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
  5648. if (Result.isNull())
  5649. return QualType();
  5650. }
  5651. PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
  5652. NewTL.setKWLoc(TL.getKWLoc());
  5653. return Result;
  5654. }
  5655. template <typename Derived>
  5656. QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
  5657. BitIntTypeLoc TL) {
  5658. const BitIntType *EIT = TL.getTypePtr();
  5659. QualType Result = TL.getType();
  5660. if (getDerived().AlwaysRebuild()) {
  5661. Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
  5662. EIT->getNumBits(), TL.getNameLoc());
  5663. if (Result.isNull())
  5664. return QualType();
  5665. }
  5666. BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
  5667. NewTL.setNameLoc(TL.getNameLoc());
  5668. return Result;
  5669. }
  5670. template <typename Derived>
  5671. QualType TreeTransform<Derived>::TransformDependentBitIntType(
  5672. TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
  5673. const DependentBitIntType *EIT = TL.getTypePtr();
  5674. EnterExpressionEvaluationContext Unevaluated(
  5675. SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
  5676. ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
  5677. BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
  5678. if (BitsExpr.isInvalid())
  5679. return QualType();
  5680. QualType Result = TL.getType();
  5681. if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
  5682. Result = getDerived().RebuildDependentBitIntType(
  5683. EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
  5684. if (Result.isNull())
  5685. return QualType();
  5686. }
  5687. if (isa<DependentBitIntType>(Result)) {
  5688. DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
  5689. NewTL.setNameLoc(TL.getNameLoc());
  5690. } else {
  5691. BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
  5692. NewTL.setNameLoc(TL.getNameLoc());
  5693. }
  5694. return Result;
  5695. }
  5696. /// Simple iterator that traverses the template arguments in a
  5697. /// container that provides a \c getArgLoc() member function.
  5698. ///
  5699. /// This iterator is intended to be used with the iterator form of
  5700. /// \c TreeTransform<Derived>::TransformTemplateArguments().
  5701. template<typename ArgLocContainer>
  5702. class TemplateArgumentLocContainerIterator {
  5703. ArgLocContainer *Container;
  5704. unsigned Index;
  5705. public:
  5706. typedef TemplateArgumentLoc value_type;
  5707. typedef TemplateArgumentLoc reference;
  5708. typedef int difference_type;
  5709. typedef std::input_iterator_tag iterator_category;
  5710. class pointer {
  5711. TemplateArgumentLoc Arg;
  5712. public:
  5713. explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
  5714. const TemplateArgumentLoc *operator->() const {
  5715. return &Arg;
  5716. }
  5717. };
  5718. TemplateArgumentLocContainerIterator() {}
  5719. TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
  5720. unsigned Index)
  5721. : Container(&Container), Index(Index) { }
  5722. TemplateArgumentLocContainerIterator &operator++() {
  5723. ++Index;
  5724. return *this;
  5725. }
  5726. TemplateArgumentLocContainerIterator operator++(int) {
  5727. TemplateArgumentLocContainerIterator Old(*this);
  5728. ++(*this);
  5729. return Old;
  5730. }
  5731. TemplateArgumentLoc operator*() const {
  5732. return Container->getArgLoc(Index);
  5733. }
  5734. pointer operator->() const {
  5735. return pointer(Container->getArgLoc(Index));
  5736. }
  5737. friend bool operator==(const TemplateArgumentLocContainerIterator &X,
  5738. const TemplateArgumentLocContainerIterator &Y) {
  5739. return X.Container == Y.Container && X.Index == Y.Index;
  5740. }
  5741. friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
  5742. const TemplateArgumentLocContainerIterator &Y) {
  5743. return !(X == Y);
  5744. }
  5745. };
  5746. template<typename Derived>
  5747. QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
  5748. AutoTypeLoc TL) {
  5749. const AutoType *T = TL.getTypePtr();
  5750. QualType OldDeduced = T->getDeducedType();
  5751. QualType NewDeduced;
  5752. if (!OldDeduced.isNull()) {
  5753. NewDeduced = getDerived().TransformType(OldDeduced);
  5754. if (NewDeduced.isNull())
  5755. return QualType();
  5756. }
  5757. ConceptDecl *NewCD = nullptr;
  5758. TemplateArgumentListInfo NewTemplateArgs;
  5759. NestedNameSpecifierLoc NewNestedNameSpec;
  5760. if (T->isConstrained()) {
  5761. NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
  5762. TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
  5763. NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
  5764. NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
  5765. typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
  5766. if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
  5767. ArgIterator(TL,
  5768. TL.getNumArgs()),
  5769. NewTemplateArgs))
  5770. return QualType();
  5771. if (TL.getNestedNameSpecifierLoc()) {
  5772. NewNestedNameSpec
  5773. = getDerived().TransformNestedNameSpecifierLoc(
  5774. TL.getNestedNameSpecifierLoc());
  5775. if (!NewNestedNameSpec)
  5776. return QualType();
  5777. }
  5778. }
  5779. QualType Result = TL.getType();
  5780. if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
  5781. T->isDependentType() || T->isConstrained()) {
  5782. // FIXME: Maybe don't rebuild if all template arguments are the same.
  5783. llvm::SmallVector<TemplateArgument, 4> NewArgList;
  5784. NewArgList.reserve(NewTemplateArgs.size());
  5785. for (const auto &ArgLoc : NewTemplateArgs.arguments())
  5786. NewArgList.push_back(ArgLoc.getArgument());
  5787. Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
  5788. NewArgList);
  5789. if (Result.isNull())
  5790. return QualType();
  5791. }
  5792. AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
  5793. NewTL.setNameLoc(TL.getNameLoc());
  5794. NewTL.setNestedNameSpecifierLoc(NewNestedNameSpec);
  5795. NewTL.setTemplateKWLoc(TL.getTemplateKWLoc());
  5796. NewTL.setConceptNameLoc(TL.getConceptNameLoc());
  5797. NewTL.setFoundDecl(TL.getFoundDecl());
  5798. NewTL.setLAngleLoc(TL.getLAngleLoc());
  5799. NewTL.setRAngleLoc(TL.getRAngleLoc());
  5800. NewTL.setRParenLoc(TL.getRParenLoc());
  5801. for (unsigned I = 0; I < NewTL.getNumArgs(); ++I)
  5802. NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo());
  5803. return Result;
  5804. }
  5805. template <typename Derived>
  5806. QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
  5807. TypeLocBuilder &TLB,
  5808. TemplateSpecializationTypeLoc TL,
  5809. TemplateName Template) {
  5810. TemplateArgumentListInfo NewTemplateArgs;
  5811. NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
  5812. NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
  5813. typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
  5814. ArgIterator;
  5815. if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
  5816. ArgIterator(TL, TL.getNumArgs()),
  5817. NewTemplateArgs))
  5818. return QualType();
  5819. // FIXME: maybe don't rebuild if all the template arguments are the same.
  5820. QualType Result =
  5821. getDerived().RebuildTemplateSpecializationType(Template,
  5822. TL.getTemplateNameLoc(),
  5823. NewTemplateArgs);
  5824. if (!Result.isNull()) {
  5825. // Specializations of template template parameters are represented as
  5826. // TemplateSpecializationTypes, and substitution of type alias templates
  5827. // within a dependent context can transform them into
  5828. // DependentTemplateSpecializationTypes.
  5829. if (isa<DependentTemplateSpecializationType>(Result)) {
  5830. DependentTemplateSpecializationTypeLoc NewTL
  5831. = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
  5832. NewTL.setElaboratedKeywordLoc(SourceLocation());
  5833. NewTL.setQualifierLoc(NestedNameSpecifierLoc());
  5834. NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
  5835. NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
  5836. NewTL.setLAngleLoc(TL.getLAngleLoc());
  5837. NewTL.setRAngleLoc(TL.getRAngleLoc());
  5838. for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
  5839. NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
  5840. return Result;
  5841. }
  5842. TemplateSpecializationTypeLoc NewTL
  5843. = TLB.push<TemplateSpecializationTypeLoc>(Result);
  5844. NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
  5845. NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
  5846. NewTL.setLAngleLoc(TL.getLAngleLoc());
  5847. NewTL.setRAngleLoc(TL.getRAngleLoc());
  5848. for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
  5849. NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
  5850. }
  5851. return Result;
  5852. }
  5853. template <typename Derived>
  5854. QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
  5855. TypeLocBuilder &TLB,
  5856. DependentTemplateSpecializationTypeLoc TL,
  5857. TemplateName Template,
  5858. CXXScopeSpec &SS) {
  5859. TemplateArgumentListInfo NewTemplateArgs;
  5860. NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
  5861. NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
  5862. typedef TemplateArgumentLocContainerIterator<
  5863. DependentTemplateSpecializationTypeLoc> ArgIterator;
  5864. if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
  5865. ArgIterator(TL, TL.getNumArgs()),
  5866. NewTemplateArgs))
  5867. return QualType();
  5868. // FIXME: maybe don't rebuild if all the template arguments are the same.
  5869. if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
  5870. QualType Result
  5871. = getSema().Context.getDependentTemplateSpecializationType(
  5872. TL.getTypePtr()->getKeyword(),
  5873. DTN->getQualifier(),
  5874. DTN->getIdentifier(),
  5875. NewTemplateArgs);
  5876. DependentTemplateSpecializationTypeLoc NewTL
  5877. = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
  5878. NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
  5879. NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
  5880. NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
  5881. NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
  5882. NewTL.setLAngleLoc(TL.getLAngleLoc());
  5883. NewTL.setRAngleLoc(TL.getRAngleLoc());
  5884. for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
  5885. NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
  5886. return Result;
  5887. }
  5888. QualType Result
  5889. = getDerived().RebuildTemplateSpecializationType(Template,
  5890. TL.getTemplateNameLoc(),
  5891. NewTemplateArgs);
  5892. if (!Result.isNull()) {
  5893. /// FIXME: Wrap this in an elaborated-type-specifier?
  5894. TemplateSpecializationTypeLoc NewTL
  5895. = TLB.push<TemplateSpecializationTypeLoc>(Result);
  5896. NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
  5897. NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
  5898. NewTL.setLAngleLoc(TL.getLAngleLoc());
  5899. NewTL.setRAngleLoc(TL.getRAngleLoc());
  5900. for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
  5901. NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
  5902. }
  5903. return Result;
  5904. }
  5905. template<typename Derived>
  5906. QualType
  5907. TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
  5908. ElaboratedTypeLoc TL) {
  5909. const ElaboratedType *T = TL.getTypePtr();
  5910. NestedNameSpecifierLoc QualifierLoc;
  5911. // NOTE: the qualifier in an ElaboratedType is optional.
  5912. if (TL.getQualifierLoc()) {
  5913. QualifierLoc
  5914. = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
  5915. if (!QualifierLoc)
  5916. return QualType();
  5917. }
  5918. QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
  5919. if (NamedT.isNull())
  5920. return QualType();
  5921. // C++0x [dcl.type.elab]p2:
  5922. // If the identifier resolves to a typedef-name or the simple-template-id
  5923. // resolves to an alias template specialization, the
  5924. // elaborated-type-specifier is ill-formed.
  5925. if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
  5926. if (const TemplateSpecializationType *TST =
  5927. NamedT->getAs<TemplateSpecializationType>()) {
  5928. TemplateName Template = TST->getTemplateName();
  5929. if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
  5930. Template.getAsTemplateDecl())) {
  5931. SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
  5932. diag::err_tag_reference_non_tag)
  5933. << TAT << Sema::NTK_TypeAliasTemplate
  5934. << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword());
  5935. SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
  5936. }
  5937. }
  5938. }
  5939. QualType Result = TL.getType();
  5940. if (getDerived().AlwaysRebuild() ||
  5941. QualifierLoc != TL.getQualifierLoc() ||
  5942. NamedT != T->getNamedType()) {
  5943. Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
  5944. T->getKeyword(),
  5945. QualifierLoc, NamedT);
  5946. if (Result.isNull())
  5947. return QualType();
  5948. }
  5949. ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
  5950. NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
  5951. NewTL.setQualifierLoc(QualifierLoc);
  5952. return Result;
  5953. }
  5954. template<typename Derived>
  5955. QualType TreeTransform<Derived>::TransformAttributedType(
  5956. TypeLocBuilder &TLB,
  5957. AttributedTypeLoc TL) {
  5958. const AttributedType *oldType = TL.getTypePtr();
  5959. QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
  5960. if (modifiedType.isNull())
  5961. return QualType();
  5962. // oldAttr can be null if we started with a QualType rather than a TypeLoc.
  5963. const Attr *oldAttr = TL.getAttr();
  5964. const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
  5965. if (oldAttr && !newAttr)
  5966. return QualType();
  5967. QualType result = TL.getType();
  5968. // FIXME: dependent operand expressions?
  5969. if (getDerived().AlwaysRebuild() ||
  5970. modifiedType != oldType->getModifiedType()) {
  5971. // TODO: this is really lame; we should really be rebuilding the
  5972. // equivalent type from first principles.
  5973. QualType equivalentType
  5974. = getDerived().TransformType(oldType->getEquivalentType());
  5975. if (equivalentType.isNull())
  5976. return QualType();
  5977. // Check whether we can add nullability; it is only represented as
  5978. // type sugar, and therefore cannot be diagnosed in any other way.
  5979. if (auto nullability = oldType->getImmediateNullability()) {
  5980. if (!modifiedType->canHaveNullability()) {
  5981. SemaRef.Diag(TL.getAttr()->getLocation(),
  5982. diag::err_nullability_nonpointer)
  5983. << DiagNullabilityKind(*nullability, false) << modifiedType;
  5984. return QualType();
  5985. }
  5986. }
  5987. result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
  5988. modifiedType,
  5989. equivalentType);
  5990. }
  5991. AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
  5992. newTL.setAttr(newAttr);
  5993. return result;
  5994. }
  5995. template<typename Derived>
  5996. QualType
  5997. TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
  5998. ParenTypeLoc TL) {
  5999. QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
  6000. if (Inner.isNull())
  6001. return QualType();
  6002. QualType Result = TL.getType();
  6003. if (getDerived().AlwaysRebuild() ||
  6004. Inner != TL.getInnerLoc().getType()) {
  6005. Result = getDerived().RebuildParenType(Inner);
  6006. if (Result.isNull())
  6007. return QualType();
  6008. }
  6009. ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
  6010. NewTL.setLParenLoc(TL.getLParenLoc());
  6011. NewTL.setRParenLoc(TL.getRParenLoc());
  6012. return Result;
  6013. }
  6014. template <typename Derived>
  6015. QualType
  6016. TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
  6017. MacroQualifiedTypeLoc TL) {
  6018. QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
  6019. if (Inner.isNull())
  6020. return QualType();
  6021. QualType Result = TL.getType();
  6022. if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
  6023. Result =
  6024. getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
  6025. if (Result.isNull())
  6026. return QualType();
  6027. }
  6028. MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
  6029. NewTL.setExpansionLoc(TL.getExpansionLoc());
  6030. return Result;
  6031. }
  6032. template<typename Derived>
  6033. QualType TreeTransform<Derived>::TransformDependentNameType(
  6034. TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
  6035. return TransformDependentNameType(TLB, TL, false);
  6036. }
  6037. template<typename Derived>
  6038. QualType TreeTransform<Derived>::TransformDependentNameType(
  6039. TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
  6040. const DependentNameType *T = TL.getTypePtr();
  6041. NestedNameSpecifierLoc QualifierLoc
  6042. = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
  6043. if (!QualifierLoc)
  6044. return QualType();
  6045. QualType Result
  6046. = getDerived().RebuildDependentNameType(T->getKeyword(),
  6047. TL.getElaboratedKeywordLoc(),
  6048. QualifierLoc,
  6049. T->getIdentifier(),
  6050. TL.getNameLoc(),
  6051. DeducedTSTContext);
  6052. if (Result.isNull())
  6053. return QualType();
  6054. if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
  6055. QualType NamedT = ElabT->getNamedType();
  6056. TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
  6057. ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
  6058. NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
  6059. NewTL.setQualifierLoc(QualifierLoc);
  6060. } else {
  6061. DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
  6062. NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
  6063. NewTL.setQualifierLoc(QualifierLoc);
  6064. NewTL.setNameLoc(TL.getNameLoc());
  6065. }
  6066. return Result;
  6067. }
  6068. template<typename Derived>
  6069. QualType TreeTransform<Derived>::
  6070. TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
  6071. DependentTemplateSpecializationTypeLoc TL) {
  6072. NestedNameSpecifierLoc QualifierLoc;
  6073. if (TL.getQualifierLoc()) {
  6074. QualifierLoc
  6075. = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
  6076. if (!QualifierLoc)
  6077. return QualType();
  6078. }
  6079. return getDerived()
  6080. .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
  6081. }
  6082. template<typename Derived>
  6083. QualType TreeTransform<Derived>::
  6084. TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
  6085. DependentTemplateSpecializationTypeLoc TL,
  6086. NestedNameSpecifierLoc QualifierLoc) {
  6087. const DependentTemplateSpecializationType *T = TL.getTypePtr();
  6088. TemplateArgumentListInfo NewTemplateArgs;
  6089. NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
  6090. NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
  6091. typedef TemplateArgumentLocContainerIterator<
  6092. DependentTemplateSpecializationTypeLoc> ArgIterator;
  6093. if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
  6094. ArgIterator(TL, TL.getNumArgs()),
  6095. NewTemplateArgs))
  6096. return QualType();
  6097. QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
  6098. T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
  6099. T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
  6100. /*AllowInjectedClassName*/ false);
  6101. if (Result.isNull())
  6102. return QualType();
  6103. if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
  6104. QualType NamedT = ElabT->getNamedType();
  6105. // Copy information relevant to the template specialization.
  6106. TemplateSpecializationTypeLoc NamedTL
  6107. = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
  6108. NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
  6109. NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
  6110. NamedTL.setLAngleLoc(TL.getLAngleLoc());
  6111. NamedTL.setRAngleLoc(TL.getRAngleLoc());
  6112. for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
  6113. NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
  6114. // Copy information relevant to the elaborated type.
  6115. ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
  6116. NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
  6117. NewTL.setQualifierLoc(QualifierLoc);
  6118. } else if (isa<DependentTemplateSpecializationType>(Result)) {
  6119. DependentTemplateSpecializationTypeLoc SpecTL
  6120. = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
  6121. SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
  6122. SpecTL.setQualifierLoc(QualifierLoc);
  6123. SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
  6124. SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
  6125. SpecTL.setLAngleLoc(TL.getLAngleLoc());
  6126. SpecTL.setRAngleLoc(TL.getRAngleLoc());
  6127. for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
  6128. SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
  6129. } else {
  6130. TemplateSpecializationTypeLoc SpecTL
  6131. = TLB.push<TemplateSpecializationTypeLoc>(Result);
  6132. SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
  6133. SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
  6134. SpecTL.setLAngleLoc(TL.getLAngleLoc());
  6135. SpecTL.setRAngleLoc(TL.getRAngleLoc());
  6136. for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
  6137. SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
  6138. }
  6139. return Result;
  6140. }
  6141. template<typename Derived>
  6142. QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
  6143. PackExpansionTypeLoc TL) {
  6144. QualType Pattern
  6145. = getDerived().TransformType(TLB, TL.getPatternLoc());
  6146. if (Pattern.isNull())
  6147. return QualType();
  6148. QualType Result = TL.getType();
  6149. if (getDerived().AlwaysRebuild() ||
  6150. Pattern != TL.getPatternLoc().getType()) {
  6151. Result = getDerived().RebuildPackExpansionType(Pattern,
  6152. TL.getPatternLoc().getSourceRange(),
  6153. TL.getEllipsisLoc(),
  6154. TL.getTypePtr()->getNumExpansions());
  6155. if (Result.isNull())
  6156. return QualType();
  6157. }
  6158. PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
  6159. NewT.setEllipsisLoc(TL.getEllipsisLoc());
  6160. return Result;
  6161. }
  6162. template<typename Derived>
  6163. QualType
  6164. TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
  6165. ObjCInterfaceTypeLoc TL) {
  6166. // ObjCInterfaceType is never dependent.
  6167. TLB.pushFullCopy(TL);
  6168. return TL.getType();
  6169. }
  6170. template<typename Derived>
  6171. QualType
  6172. TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
  6173. ObjCTypeParamTypeLoc TL) {
  6174. const ObjCTypeParamType *T = TL.getTypePtr();
  6175. ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
  6176. getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
  6177. if (!OTP)
  6178. return QualType();
  6179. QualType Result = TL.getType();
  6180. if (getDerived().AlwaysRebuild() ||
  6181. OTP != T->getDecl()) {
  6182. Result = getDerived().RebuildObjCTypeParamType(OTP,
  6183. TL.getProtocolLAngleLoc(),
  6184. llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
  6185. TL.getNumProtocols()),
  6186. TL.getProtocolLocs(),
  6187. TL.getProtocolRAngleLoc());
  6188. if (Result.isNull())
  6189. return QualType();
  6190. }
  6191. ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
  6192. if (TL.getNumProtocols()) {
  6193. NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
  6194. for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
  6195. NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
  6196. NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
  6197. }
  6198. return Result;
  6199. }
  6200. template<typename Derived>
  6201. QualType
  6202. TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
  6203. ObjCObjectTypeLoc TL) {
  6204. // Transform base type.
  6205. QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
  6206. if (BaseType.isNull())
  6207. return QualType();
  6208. bool AnyChanged = BaseType != TL.getBaseLoc().getType();
  6209. // Transform type arguments.
  6210. SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
  6211. for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
  6212. TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
  6213. TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
  6214. QualType TypeArg = TypeArgInfo->getType();
  6215. if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
  6216. AnyChanged = true;
  6217. // We have a pack expansion. Instantiate it.
  6218. const auto *PackExpansion = PackExpansionLoc.getType()
  6219. ->castAs<PackExpansionType>();
  6220. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  6221. SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
  6222. Unexpanded);
  6223. assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
  6224. // Determine whether the set of unexpanded parameter packs can
  6225. // and should be expanded.
  6226. TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
  6227. bool Expand = false;
  6228. bool RetainExpansion = false;
  6229. Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
  6230. if (getDerived().TryExpandParameterPacks(
  6231. PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
  6232. Unexpanded, Expand, RetainExpansion, NumExpansions))
  6233. return QualType();
  6234. if (!Expand) {
  6235. // We can't expand this pack expansion into separate arguments yet;
  6236. // just substitute into the pattern and create a new pack expansion
  6237. // type.
  6238. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  6239. TypeLocBuilder TypeArgBuilder;
  6240. TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
  6241. QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
  6242. PatternLoc);
  6243. if (NewPatternType.isNull())
  6244. return QualType();
  6245. QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
  6246. NewPatternType, NumExpansions);
  6247. auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
  6248. NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
  6249. NewTypeArgInfos.push_back(
  6250. TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
  6251. continue;
  6252. }
  6253. // Substitute into the pack expansion pattern for each slice of the
  6254. // pack.
  6255. for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
  6256. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
  6257. TypeLocBuilder TypeArgBuilder;
  6258. TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
  6259. QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
  6260. PatternLoc);
  6261. if (NewTypeArg.isNull())
  6262. return QualType();
  6263. NewTypeArgInfos.push_back(
  6264. TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
  6265. }
  6266. continue;
  6267. }
  6268. TypeLocBuilder TypeArgBuilder;
  6269. TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
  6270. QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
  6271. if (NewTypeArg.isNull())
  6272. return QualType();
  6273. // If nothing changed, just keep the old TypeSourceInfo.
  6274. if (NewTypeArg == TypeArg) {
  6275. NewTypeArgInfos.push_back(TypeArgInfo);
  6276. continue;
  6277. }
  6278. NewTypeArgInfos.push_back(
  6279. TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
  6280. AnyChanged = true;
  6281. }
  6282. QualType Result = TL.getType();
  6283. if (getDerived().AlwaysRebuild() || AnyChanged) {
  6284. // Rebuild the type.
  6285. Result = getDerived().RebuildObjCObjectType(
  6286. BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
  6287. TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
  6288. llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
  6289. TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
  6290. if (Result.isNull())
  6291. return QualType();
  6292. }
  6293. ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
  6294. NewT.setHasBaseTypeAsWritten(true);
  6295. NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
  6296. for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
  6297. NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
  6298. NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
  6299. NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
  6300. for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
  6301. NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
  6302. NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
  6303. return Result;
  6304. }
  6305. template<typename Derived>
  6306. QualType
  6307. TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
  6308. ObjCObjectPointerTypeLoc TL) {
  6309. QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
  6310. if (PointeeType.isNull())
  6311. return QualType();
  6312. QualType Result = TL.getType();
  6313. if (getDerived().AlwaysRebuild() ||
  6314. PointeeType != TL.getPointeeLoc().getType()) {
  6315. Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
  6316. TL.getStarLoc());
  6317. if (Result.isNull())
  6318. return QualType();
  6319. }
  6320. ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
  6321. NewT.setStarLoc(TL.getStarLoc());
  6322. return Result;
  6323. }
  6324. //===----------------------------------------------------------------------===//
  6325. // Statement transformation
  6326. //===----------------------------------------------------------------------===//
  6327. template<typename Derived>
  6328. StmtResult
  6329. TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
  6330. return S;
  6331. }
  6332. template<typename Derived>
  6333. StmtResult
  6334. TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
  6335. return getDerived().TransformCompoundStmt(S, false);
  6336. }
  6337. template<typename Derived>
  6338. StmtResult
  6339. TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
  6340. bool IsStmtExpr) {
  6341. Sema::CompoundScopeRAII CompoundScope(getSema());
  6342. const Stmt *ExprResult = S->getStmtExprResult();
  6343. bool SubStmtInvalid = false;
  6344. bool SubStmtChanged = false;
  6345. SmallVector<Stmt*, 8> Statements;
  6346. for (auto *B : S->body()) {
  6347. StmtResult Result = getDerived().TransformStmt(
  6348. B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
  6349. if (Result.isInvalid()) {
  6350. // Immediately fail if this was a DeclStmt, since it's very
  6351. // likely that this will cause problems for future statements.
  6352. if (isa<DeclStmt>(B))
  6353. return StmtError();
  6354. // Otherwise, just keep processing substatements and fail later.
  6355. SubStmtInvalid = true;
  6356. continue;
  6357. }
  6358. SubStmtChanged = SubStmtChanged || Result.get() != B;
  6359. Statements.push_back(Result.getAs<Stmt>());
  6360. }
  6361. if (SubStmtInvalid)
  6362. return StmtError();
  6363. if (!getDerived().AlwaysRebuild() &&
  6364. !SubStmtChanged)
  6365. return S;
  6366. return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
  6367. Statements,
  6368. S->getRBracLoc(),
  6369. IsStmtExpr);
  6370. }
  6371. template<typename Derived>
  6372. StmtResult
  6373. TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
  6374. ExprResult LHS, RHS;
  6375. {
  6376. EnterExpressionEvaluationContext Unevaluated(
  6377. SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated);
  6378. // Transform the left-hand case value.
  6379. LHS = getDerived().TransformExpr(S->getLHS());
  6380. LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
  6381. if (LHS.isInvalid())
  6382. return StmtError();
  6383. // Transform the right-hand case value (for the GNU case-range extension).
  6384. RHS = getDerived().TransformExpr(S->getRHS());
  6385. RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
  6386. if (RHS.isInvalid())
  6387. return StmtError();
  6388. }
  6389. // Build the case statement.
  6390. // Case statements are always rebuilt so that they will attached to their
  6391. // transformed switch statement.
  6392. StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
  6393. LHS.get(),
  6394. S->getEllipsisLoc(),
  6395. RHS.get(),
  6396. S->getColonLoc());
  6397. if (Case.isInvalid())
  6398. return StmtError();
  6399. // Transform the statement following the case
  6400. StmtResult SubStmt =
  6401. getDerived().TransformStmt(S->getSubStmt());
  6402. if (SubStmt.isInvalid())
  6403. return StmtError();
  6404. // Attach the body to the case statement
  6405. return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
  6406. }
  6407. template <typename Derived>
  6408. StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
  6409. // Transform the statement following the default case
  6410. StmtResult SubStmt =
  6411. getDerived().TransformStmt(S->getSubStmt());
  6412. if (SubStmt.isInvalid())
  6413. return StmtError();
  6414. // Default statements are always rebuilt
  6415. return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
  6416. SubStmt.get());
  6417. }
  6418. template<typename Derived>
  6419. StmtResult
  6420. TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
  6421. StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
  6422. if (SubStmt.isInvalid())
  6423. return StmtError();
  6424. Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
  6425. S->getDecl());
  6426. if (!LD)
  6427. return StmtError();
  6428. // If we're transforming "in-place" (we're not creating new local
  6429. // declarations), assume we're replacing the old label statement
  6430. // and clear out the reference to it.
  6431. if (LD == S->getDecl())
  6432. S->getDecl()->setStmt(nullptr);
  6433. // FIXME: Pass the real colon location in.
  6434. return getDerived().RebuildLabelStmt(S->getIdentLoc(),
  6435. cast<LabelDecl>(LD), SourceLocation(),
  6436. SubStmt.get());
  6437. }
  6438. template <typename Derived>
  6439. const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
  6440. if (!R)
  6441. return R;
  6442. switch (R->getKind()) {
  6443. // Transform attributes with a pragma spelling by calling TransformXXXAttr.
  6444. #define ATTR(X)
  6445. #define PRAGMA_SPELLING_ATTR(X) \
  6446. case attr::X: \
  6447. return getDerived().Transform##X##Attr(cast<X##Attr>(R));
  6448. #include "clang/Basic/AttrList.inc"
  6449. default:
  6450. return R;
  6451. }
  6452. }
  6453. template <typename Derived>
  6454. StmtResult
  6455. TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S,
  6456. StmtDiscardKind SDK) {
  6457. bool AttrsChanged = false;
  6458. SmallVector<const Attr *, 1> Attrs;
  6459. // Visit attributes and keep track if any are transformed.
  6460. for (const auto *I : S->getAttrs()) {
  6461. const Attr *R = getDerived().TransformAttr(I);
  6462. AttrsChanged |= (I != R);
  6463. if (R)
  6464. Attrs.push_back(R);
  6465. }
  6466. StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
  6467. if (SubStmt.isInvalid())
  6468. return StmtError();
  6469. if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
  6470. return S;
  6471. // If transforming the attributes failed for all of the attributes in the
  6472. // statement, don't make an AttributedStmt without attributes.
  6473. if (Attrs.empty())
  6474. return SubStmt;
  6475. return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
  6476. SubStmt.get());
  6477. }
  6478. template<typename Derived>
  6479. StmtResult
  6480. TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
  6481. // Transform the initialization statement
  6482. StmtResult Init = getDerived().TransformStmt(S->getInit());
  6483. if (Init.isInvalid())
  6484. return StmtError();
  6485. Sema::ConditionResult Cond;
  6486. if (!S->isConsteval()) {
  6487. // Transform the condition
  6488. Cond = getDerived().TransformCondition(
  6489. S->getIfLoc(), S->getConditionVariable(), S->getCond(),
  6490. S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
  6491. : Sema::ConditionKind::Boolean);
  6492. if (Cond.isInvalid())
  6493. return StmtError();
  6494. }
  6495. // If this is a constexpr if, determine which arm we should instantiate.
  6496. llvm::Optional<bool> ConstexprConditionValue;
  6497. if (S->isConstexpr())
  6498. ConstexprConditionValue = Cond.getKnownValue();
  6499. // Transform the "then" branch.
  6500. StmtResult Then;
  6501. if (!ConstexprConditionValue || *ConstexprConditionValue) {
  6502. Then = getDerived().TransformStmt(S->getThen());
  6503. if (Then.isInvalid())
  6504. return StmtError();
  6505. } else {
  6506. Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc());
  6507. }
  6508. // Transform the "else" branch.
  6509. StmtResult Else;
  6510. if (!ConstexprConditionValue || !*ConstexprConditionValue) {
  6511. Else = getDerived().TransformStmt(S->getElse());
  6512. if (Else.isInvalid())
  6513. return StmtError();
  6514. }
  6515. if (!getDerived().AlwaysRebuild() &&
  6516. Init.get() == S->getInit() &&
  6517. Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
  6518. Then.get() == S->getThen() &&
  6519. Else.get() == S->getElse())
  6520. return S;
  6521. return getDerived().RebuildIfStmt(
  6522. S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
  6523. S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
  6524. }
  6525. template<typename Derived>
  6526. StmtResult
  6527. TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
  6528. // Transform the initialization statement
  6529. StmtResult Init = getDerived().TransformStmt(S->getInit());
  6530. if (Init.isInvalid())
  6531. return StmtError();
  6532. // Transform the condition.
  6533. Sema::ConditionResult Cond = getDerived().TransformCondition(
  6534. S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
  6535. Sema::ConditionKind::Switch);
  6536. if (Cond.isInvalid())
  6537. return StmtError();
  6538. // Rebuild the switch statement.
  6539. StmtResult Switch =
  6540. getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
  6541. Init.get(), Cond, S->getRParenLoc());
  6542. if (Switch.isInvalid())
  6543. return StmtError();
  6544. // Transform the body of the switch statement.
  6545. StmtResult Body = getDerived().TransformStmt(S->getBody());
  6546. if (Body.isInvalid())
  6547. return StmtError();
  6548. // Complete the switch statement.
  6549. return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
  6550. Body.get());
  6551. }
  6552. template<typename Derived>
  6553. StmtResult
  6554. TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
  6555. // Transform the condition
  6556. Sema::ConditionResult Cond = getDerived().TransformCondition(
  6557. S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
  6558. Sema::ConditionKind::Boolean);
  6559. if (Cond.isInvalid())
  6560. return StmtError();
  6561. // Transform the body
  6562. StmtResult Body = getDerived().TransformStmt(S->getBody());
  6563. if (Body.isInvalid())
  6564. return StmtError();
  6565. if (!getDerived().AlwaysRebuild() &&
  6566. Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
  6567. Body.get() == S->getBody())
  6568. return Owned(S);
  6569. return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
  6570. Cond, S->getRParenLoc(), Body.get());
  6571. }
  6572. template<typename Derived>
  6573. StmtResult
  6574. TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
  6575. // Transform the body
  6576. StmtResult Body = getDerived().TransformStmt(S->getBody());
  6577. if (Body.isInvalid())
  6578. return StmtError();
  6579. // Transform the condition
  6580. ExprResult Cond = getDerived().TransformExpr(S->getCond());
  6581. if (Cond.isInvalid())
  6582. return StmtError();
  6583. if (!getDerived().AlwaysRebuild() &&
  6584. Cond.get() == S->getCond() &&
  6585. Body.get() == S->getBody())
  6586. return S;
  6587. return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
  6588. /*FIXME:*/S->getWhileLoc(), Cond.get(),
  6589. S->getRParenLoc());
  6590. }
  6591. template<typename Derived>
  6592. StmtResult
  6593. TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
  6594. if (getSema().getLangOpts().OpenMP)
  6595. getSema().startOpenMPLoop();
  6596. // Transform the initialization statement
  6597. StmtResult Init = getDerived().TransformStmt(S->getInit());
  6598. if (Init.isInvalid())
  6599. return StmtError();
  6600. // In OpenMP loop region loop control variable must be captured and be
  6601. // private. Perform analysis of first part (if any).
  6602. if (getSema().getLangOpts().OpenMP && Init.isUsable())
  6603. getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
  6604. // Transform the condition
  6605. Sema::ConditionResult Cond = getDerived().TransformCondition(
  6606. S->getForLoc(), S->getConditionVariable(), S->getCond(),
  6607. Sema::ConditionKind::Boolean);
  6608. if (Cond.isInvalid())
  6609. return StmtError();
  6610. // Transform the increment
  6611. ExprResult Inc = getDerived().TransformExpr(S->getInc());
  6612. if (Inc.isInvalid())
  6613. return StmtError();
  6614. Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
  6615. if (S->getInc() && !FullInc.get())
  6616. return StmtError();
  6617. // Transform the body
  6618. StmtResult Body = getDerived().TransformStmt(S->getBody());
  6619. if (Body.isInvalid())
  6620. return StmtError();
  6621. if (!getDerived().AlwaysRebuild() &&
  6622. Init.get() == S->getInit() &&
  6623. Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
  6624. Inc.get() == S->getInc() &&
  6625. Body.get() == S->getBody())
  6626. return S;
  6627. return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
  6628. Init.get(), Cond, FullInc,
  6629. S->getRParenLoc(), Body.get());
  6630. }
  6631. template<typename Derived>
  6632. StmtResult
  6633. TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
  6634. Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
  6635. S->getLabel());
  6636. if (!LD)
  6637. return StmtError();
  6638. // Goto statements must always be rebuilt, to resolve the label.
  6639. return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
  6640. cast<LabelDecl>(LD));
  6641. }
  6642. template<typename Derived>
  6643. StmtResult
  6644. TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
  6645. ExprResult Target = getDerived().TransformExpr(S->getTarget());
  6646. if (Target.isInvalid())
  6647. return StmtError();
  6648. Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
  6649. if (!getDerived().AlwaysRebuild() &&
  6650. Target.get() == S->getTarget())
  6651. return S;
  6652. return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
  6653. Target.get());
  6654. }
  6655. template<typename Derived>
  6656. StmtResult
  6657. TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
  6658. return S;
  6659. }
  6660. template<typename Derived>
  6661. StmtResult
  6662. TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
  6663. return S;
  6664. }
  6665. template<typename Derived>
  6666. StmtResult
  6667. TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
  6668. ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
  6669. /*NotCopyInit*/false);
  6670. if (Result.isInvalid())
  6671. return StmtError();
  6672. // FIXME: We always rebuild the return statement because there is no way
  6673. // to tell whether the return type of the function has changed.
  6674. return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
  6675. }
  6676. template<typename Derived>
  6677. StmtResult
  6678. TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
  6679. bool DeclChanged = false;
  6680. SmallVector<Decl *, 4> Decls;
  6681. for (auto *D : S->decls()) {
  6682. Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
  6683. if (!Transformed)
  6684. return StmtError();
  6685. if (Transformed != D)
  6686. DeclChanged = true;
  6687. Decls.push_back(Transformed);
  6688. }
  6689. if (!getDerived().AlwaysRebuild() && !DeclChanged)
  6690. return S;
  6691. return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
  6692. }
  6693. template<typename Derived>
  6694. StmtResult
  6695. TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
  6696. SmallVector<Expr*, 8> Constraints;
  6697. SmallVector<Expr*, 8> Exprs;
  6698. SmallVector<IdentifierInfo *, 4> Names;
  6699. ExprResult AsmString;
  6700. SmallVector<Expr*, 8> Clobbers;
  6701. bool ExprsChanged = false;
  6702. // Go through the outputs.
  6703. for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
  6704. Names.push_back(S->getOutputIdentifier(I));
  6705. // No need to transform the constraint literal.
  6706. Constraints.push_back(S->getOutputConstraintLiteral(I));
  6707. // Transform the output expr.
  6708. Expr *OutputExpr = S->getOutputExpr(I);
  6709. ExprResult Result = getDerived().TransformExpr(OutputExpr);
  6710. if (Result.isInvalid())
  6711. return StmtError();
  6712. ExprsChanged |= Result.get() != OutputExpr;
  6713. Exprs.push_back(Result.get());
  6714. }
  6715. // Go through the inputs.
  6716. for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
  6717. Names.push_back(S->getInputIdentifier(I));
  6718. // No need to transform the constraint literal.
  6719. Constraints.push_back(S->getInputConstraintLiteral(I));
  6720. // Transform the input expr.
  6721. Expr *InputExpr = S->getInputExpr(I);
  6722. ExprResult Result = getDerived().TransformExpr(InputExpr);
  6723. if (Result.isInvalid())
  6724. return StmtError();
  6725. ExprsChanged |= Result.get() != InputExpr;
  6726. Exprs.push_back(Result.get());
  6727. }
  6728. // Go through the Labels.
  6729. for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
  6730. Names.push_back(S->getLabelIdentifier(I));
  6731. ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
  6732. if (Result.isInvalid())
  6733. return StmtError();
  6734. ExprsChanged |= Result.get() != S->getLabelExpr(I);
  6735. Exprs.push_back(Result.get());
  6736. }
  6737. if (!getDerived().AlwaysRebuild() && !ExprsChanged)
  6738. return S;
  6739. // Go through the clobbers.
  6740. for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
  6741. Clobbers.push_back(S->getClobberStringLiteral(I));
  6742. // No need to transform the asm string literal.
  6743. AsmString = S->getAsmString();
  6744. return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
  6745. S->isVolatile(), S->getNumOutputs(),
  6746. S->getNumInputs(), Names.data(),
  6747. Constraints, Exprs, AsmString.get(),
  6748. Clobbers, S->getNumLabels(),
  6749. S->getRParenLoc());
  6750. }
  6751. template<typename Derived>
  6752. StmtResult
  6753. TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
  6754. ArrayRef<Token> AsmToks =
  6755. llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
  6756. bool HadError = false, HadChange = false;
  6757. ArrayRef<Expr*> SrcExprs = S->getAllExprs();
  6758. SmallVector<Expr*, 8> TransformedExprs;
  6759. TransformedExprs.reserve(SrcExprs.size());
  6760. for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
  6761. ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
  6762. if (!Result.isUsable()) {
  6763. HadError = true;
  6764. } else {
  6765. HadChange |= (Result.get() != SrcExprs[i]);
  6766. TransformedExprs.push_back(Result.get());
  6767. }
  6768. }
  6769. if (HadError) return StmtError();
  6770. if (!HadChange && !getDerived().AlwaysRebuild())
  6771. return Owned(S);
  6772. return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
  6773. AsmToks, S->getAsmString(),
  6774. S->getNumOutputs(), S->getNumInputs(),
  6775. S->getAllConstraints(), S->getClobbers(),
  6776. TransformedExprs, S->getEndLoc());
  6777. }
  6778. // C++ Coroutines TS
  6779. template<typename Derived>
  6780. StmtResult
  6781. TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
  6782. auto *ScopeInfo = SemaRef.getCurFunction();
  6783. auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
  6784. assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
  6785. ScopeInfo->NeedsCoroutineSuspends &&
  6786. ScopeInfo->CoroutineSuspends.first == nullptr &&
  6787. ScopeInfo->CoroutineSuspends.second == nullptr &&
  6788. "expected clean scope info");
  6789. // Set that we have (possibly-invalid) suspend points before we do anything
  6790. // that may fail.
  6791. ScopeInfo->setNeedsCoroutineSuspends(false);
  6792. // We re-build the coroutine promise object (and the coroutine parameters its
  6793. // type and constructor depend on) based on the types used in our current
  6794. // function. We must do so, and set it on the current FunctionScopeInfo,
  6795. // before attempting to transform the other parts of the coroutine body
  6796. // statement, such as the implicit suspend statements (because those
  6797. // statements reference the FunctionScopeInfo::CoroutinePromise).
  6798. if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
  6799. return StmtError();
  6800. auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
  6801. if (!Promise)
  6802. return StmtError();
  6803. getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
  6804. ScopeInfo->CoroutinePromise = Promise;
  6805. // Transform the implicit coroutine statements constructed using dependent
  6806. // types during the previous parse: initial and final suspensions, the return
  6807. // object, and others. We also transform the coroutine function's body.
  6808. StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
  6809. if (InitSuspend.isInvalid())
  6810. return StmtError();
  6811. StmtResult FinalSuspend =
  6812. getDerived().TransformStmt(S->getFinalSuspendStmt());
  6813. if (FinalSuspend.isInvalid() ||
  6814. !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
  6815. return StmtError();
  6816. ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
  6817. assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
  6818. StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
  6819. if (BodyRes.isInvalid())
  6820. return StmtError();
  6821. CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
  6822. if (Builder.isInvalid())
  6823. return StmtError();
  6824. Expr *ReturnObject = S->getReturnValueInit();
  6825. assert(ReturnObject && "the return object is expected to be valid");
  6826. ExprResult Res = getDerived().TransformInitializer(ReturnObject,
  6827. /*NoCopyInit*/ false);
  6828. if (Res.isInvalid())
  6829. return StmtError();
  6830. Builder.ReturnValue = Res.get();
  6831. // If during the previous parse the coroutine still had a dependent promise
  6832. // statement, we may need to build some implicit coroutine statements
  6833. // (such as exception and fallthrough handlers) for the first time.
  6834. if (S->hasDependentPromiseType()) {
  6835. // We can only build these statements, however, if the current promise type
  6836. // is not dependent.
  6837. if (!Promise->getType()->isDependentType()) {
  6838. assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
  6839. !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
  6840. "these nodes should not have been built yet");
  6841. if (!Builder.buildDependentStatements())
  6842. return StmtError();
  6843. }
  6844. } else {
  6845. if (auto *OnFallthrough = S->getFallthroughHandler()) {
  6846. StmtResult Res = getDerived().TransformStmt(OnFallthrough);
  6847. if (Res.isInvalid())
  6848. return StmtError();
  6849. Builder.OnFallthrough = Res.get();
  6850. }
  6851. if (auto *OnException = S->getExceptionHandler()) {
  6852. StmtResult Res = getDerived().TransformStmt(OnException);
  6853. if (Res.isInvalid())
  6854. return StmtError();
  6855. Builder.OnException = Res.get();
  6856. }
  6857. if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
  6858. StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
  6859. if (Res.isInvalid())
  6860. return StmtError();
  6861. Builder.ReturnStmtOnAllocFailure = Res.get();
  6862. }
  6863. // Transform any additional statements we may have already built
  6864. assert(S->getAllocate() && S->getDeallocate() &&
  6865. "allocation and deallocation calls must already be built");
  6866. ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
  6867. if (AllocRes.isInvalid())
  6868. return StmtError();
  6869. Builder.Allocate = AllocRes.get();
  6870. ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
  6871. if (DeallocRes.isInvalid())
  6872. return StmtError();
  6873. Builder.Deallocate = DeallocRes.get();
  6874. assert(S->getResultDecl() && "ResultDecl must already be built");
  6875. StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl());
  6876. if (ResultDecl.isInvalid())
  6877. return StmtError();
  6878. Builder.ResultDecl = ResultDecl.get();
  6879. if (auto *ReturnStmt = S->getReturnStmt()) {
  6880. StmtResult Res = getDerived().TransformStmt(ReturnStmt);
  6881. if (Res.isInvalid())
  6882. return StmtError();
  6883. Builder.ReturnStmt = Res.get();
  6884. }
  6885. }
  6886. return getDerived().RebuildCoroutineBodyStmt(Builder);
  6887. }
  6888. template<typename Derived>
  6889. StmtResult
  6890. TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
  6891. ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
  6892. /*NotCopyInit*/false);
  6893. if (Result.isInvalid())
  6894. return StmtError();
  6895. // Always rebuild; we don't know if this needs to be injected into a new
  6896. // context or if the promise type has changed.
  6897. return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
  6898. S->isImplicit());
  6899. }
  6900. template<typename Derived>
  6901. ExprResult
  6902. TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
  6903. ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
  6904. /*NotCopyInit*/false);
  6905. if (Result.isInvalid())
  6906. return ExprError();
  6907. // Always rebuild; we don't know if this needs to be injected into a new
  6908. // context or if the promise type has changed.
  6909. return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(),
  6910. E->isImplicit());
  6911. }
  6912. template <typename Derived>
  6913. ExprResult
  6914. TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
  6915. ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
  6916. /*NotCopyInit*/ false);
  6917. if (OperandResult.isInvalid())
  6918. return ExprError();
  6919. ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
  6920. E->getOperatorCoawaitLookup());
  6921. if (LookupResult.isInvalid())
  6922. return ExprError();
  6923. // Always rebuild; we don't know if this needs to be injected into a new
  6924. // context or if the promise type has changed.
  6925. return getDerived().RebuildDependentCoawaitExpr(
  6926. E->getKeywordLoc(), OperandResult.get(),
  6927. cast<UnresolvedLookupExpr>(LookupResult.get()));
  6928. }
  6929. template<typename Derived>
  6930. ExprResult
  6931. TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
  6932. ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
  6933. /*NotCopyInit*/false);
  6934. if (Result.isInvalid())
  6935. return ExprError();
  6936. // Always rebuild; we don't know if this needs to be injected into a new
  6937. // context or if the promise type has changed.
  6938. return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
  6939. }
  6940. // Objective-C Statements.
  6941. template<typename Derived>
  6942. StmtResult
  6943. TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
  6944. // Transform the body of the @try.
  6945. StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
  6946. if (TryBody.isInvalid())
  6947. return StmtError();
  6948. // Transform the @catch statements (if present).
  6949. bool AnyCatchChanged = false;
  6950. SmallVector<Stmt*, 8> CatchStmts;
  6951. for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
  6952. StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
  6953. if (Catch.isInvalid())
  6954. return StmtError();
  6955. if (Catch.get() != S->getCatchStmt(I))
  6956. AnyCatchChanged = true;
  6957. CatchStmts.push_back(Catch.get());
  6958. }
  6959. // Transform the @finally statement (if present).
  6960. StmtResult Finally;
  6961. if (S->getFinallyStmt()) {
  6962. Finally = getDerived().TransformStmt(S->getFinallyStmt());
  6963. if (Finally.isInvalid())
  6964. return StmtError();
  6965. }
  6966. // If nothing changed, just retain this statement.
  6967. if (!getDerived().AlwaysRebuild() &&
  6968. TryBody.get() == S->getTryBody() &&
  6969. !AnyCatchChanged &&
  6970. Finally.get() == S->getFinallyStmt())
  6971. return S;
  6972. // Build a new statement.
  6973. return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
  6974. CatchStmts, Finally.get());
  6975. }
  6976. template<typename Derived>
  6977. StmtResult
  6978. TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
  6979. // Transform the @catch parameter, if there is one.
  6980. VarDecl *Var = nullptr;
  6981. if (VarDecl *FromVar = S->getCatchParamDecl()) {
  6982. TypeSourceInfo *TSInfo = nullptr;
  6983. if (FromVar->getTypeSourceInfo()) {
  6984. TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
  6985. if (!TSInfo)
  6986. return StmtError();
  6987. }
  6988. QualType T;
  6989. if (TSInfo)
  6990. T = TSInfo->getType();
  6991. else {
  6992. T = getDerived().TransformType(FromVar->getType());
  6993. if (T.isNull())
  6994. return StmtError();
  6995. }
  6996. Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
  6997. if (!Var)
  6998. return StmtError();
  6999. }
  7000. StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
  7001. if (Body.isInvalid())
  7002. return StmtError();
  7003. return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
  7004. S->getRParenLoc(),
  7005. Var, Body.get());
  7006. }
  7007. template<typename Derived>
  7008. StmtResult
  7009. TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
  7010. // Transform the body.
  7011. StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
  7012. if (Body.isInvalid())
  7013. return StmtError();
  7014. // If nothing changed, just retain this statement.
  7015. if (!getDerived().AlwaysRebuild() &&
  7016. Body.get() == S->getFinallyBody())
  7017. return S;
  7018. // Build a new statement.
  7019. return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
  7020. Body.get());
  7021. }
  7022. template<typename Derived>
  7023. StmtResult
  7024. TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
  7025. ExprResult Operand;
  7026. if (S->getThrowExpr()) {
  7027. Operand = getDerived().TransformExpr(S->getThrowExpr());
  7028. if (Operand.isInvalid())
  7029. return StmtError();
  7030. }
  7031. if (!getDerived().AlwaysRebuild() &&
  7032. Operand.get() == S->getThrowExpr())
  7033. return S;
  7034. return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
  7035. }
  7036. template<typename Derived>
  7037. StmtResult
  7038. TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
  7039. ObjCAtSynchronizedStmt *S) {
  7040. // Transform the object we are locking.
  7041. ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
  7042. if (Object.isInvalid())
  7043. return StmtError();
  7044. Object =
  7045. getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
  7046. Object.get());
  7047. if (Object.isInvalid())
  7048. return StmtError();
  7049. // Transform the body.
  7050. StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
  7051. if (Body.isInvalid())
  7052. return StmtError();
  7053. // If nothing change, just retain the current statement.
  7054. if (!getDerived().AlwaysRebuild() &&
  7055. Object.get() == S->getSynchExpr() &&
  7056. Body.get() == S->getSynchBody())
  7057. return S;
  7058. // Build a new statement.
  7059. return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
  7060. Object.get(), Body.get());
  7061. }
  7062. template<typename Derived>
  7063. StmtResult
  7064. TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
  7065. ObjCAutoreleasePoolStmt *S) {
  7066. // Transform the body.
  7067. StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
  7068. if (Body.isInvalid())
  7069. return StmtError();
  7070. // If nothing changed, just retain this statement.
  7071. if (!getDerived().AlwaysRebuild() &&
  7072. Body.get() == S->getSubStmt())
  7073. return S;
  7074. // Build a new statement.
  7075. return getDerived().RebuildObjCAutoreleasePoolStmt(
  7076. S->getAtLoc(), Body.get());
  7077. }
  7078. template<typename Derived>
  7079. StmtResult
  7080. TreeTransform<Derived>::TransformObjCForCollectionStmt(
  7081. ObjCForCollectionStmt *S) {
  7082. // Transform the element statement.
  7083. StmtResult Element =
  7084. getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
  7085. if (Element.isInvalid())
  7086. return StmtError();
  7087. // Transform the collection expression.
  7088. ExprResult Collection = getDerived().TransformExpr(S->getCollection());
  7089. if (Collection.isInvalid())
  7090. return StmtError();
  7091. // Transform the body.
  7092. StmtResult Body = getDerived().TransformStmt(S->getBody());
  7093. if (Body.isInvalid())
  7094. return StmtError();
  7095. // If nothing changed, just retain this statement.
  7096. if (!getDerived().AlwaysRebuild() &&
  7097. Element.get() == S->getElement() &&
  7098. Collection.get() == S->getCollection() &&
  7099. Body.get() == S->getBody())
  7100. return S;
  7101. // Build a new statement.
  7102. return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
  7103. Element.get(),
  7104. Collection.get(),
  7105. S->getRParenLoc(),
  7106. Body.get());
  7107. }
  7108. template <typename Derived>
  7109. StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
  7110. // Transform the exception declaration, if any.
  7111. VarDecl *Var = nullptr;
  7112. if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
  7113. TypeSourceInfo *T =
  7114. getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
  7115. if (!T)
  7116. return StmtError();
  7117. Var = getDerived().RebuildExceptionDecl(
  7118. ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
  7119. ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
  7120. if (!Var || Var->isInvalidDecl())
  7121. return StmtError();
  7122. }
  7123. // Transform the actual exception handler.
  7124. StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
  7125. if (Handler.isInvalid())
  7126. return StmtError();
  7127. if (!getDerived().AlwaysRebuild() && !Var &&
  7128. Handler.get() == S->getHandlerBlock())
  7129. return S;
  7130. return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
  7131. }
  7132. template <typename Derived>
  7133. StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
  7134. // Transform the try block itself.
  7135. StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
  7136. if (TryBlock.isInvalid())
  7137. return StmtError();
  7138. // Transform the handlers.
  7139. bool HandlerChanged = false;
  7140. SmallVector<Stmt *, 8> Handlers;
  7141. for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
  7142. StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
  7143. if (Handler.isInvalid())
  7144. return StmtError();
  7145. HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
  7146. Handlers.push_back(Handler.getAs<Stmt>());
  7147. }
  7148. if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
  7149. !HandlerChanged)
  7150. return S;
  7151. return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
  7152. Handlers);
  7153. }
  7154. template<typename Derived>
  7155. StmtResult
  7156. TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
  7157. StmtResult Init =
  7158. S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
  7159. if (Init.isInvalid())
  7160. return StmtError();
  7161. StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
  7162. if (Range.isInvalid())
  7163. return StmtError();
  7164. StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
  7165. if (Begin.isInvalid())
  7166. return StmtError();
  7167. StmtResult End = getDerived().TransformStmt(S->getEndStmt());
  7168. if (End.isInvalid())
  7169. return StmtError();
  7170. ExprResult Cond = getDerived().TransformExpr(S->getCond());
  7171. if (Cond.isInvalid())
  7172. return StmtError();
  7173. if (Cond.get())
  7174. Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
  7175. if (Cond.isInvalid())
  7176. return StmtError();
  7177. if (Cond.get())
  7178. Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
  7179. ExprResult Inc = getDerived().TransformExpr(S->getInc());
  7180. if (Inc.isInvalid())
  7181. return StmtError();
  7182. if (Inc.get())
  7183. Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
  7184. StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
  7185. if (LoopVar.isInvalid())
  7186. return StmtError();
  7187. StmtResult NewStmt = S;
  7188. if (getDerived().AlwaysRebuild() ||
  7189. Init.get() != S->getInit() ||
  7190. Range.get() != S->getRangeStmt() ||
  7191. Begin.get() != S->getBeginStmt() ||
  7192. End.get() != S->getEndStmt() ||
  7193. Cond.get() != S->getCond() ||
  7194. Inc.get() != S->getInc() ||
  7195. LoopVar.get() != S->getLoopVarStmt()) {
  7196. NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
  7197. S->getCoawaitLoc(), Init.get(),
  7198. S->getColonLoc(), Range.get(),
  7199. Begin.get(), End.get(),
  7200. Cond.get(),
  7201. Inc.get(), LoopVar.get(),
  7202. S->getRParenLoc());
  7203. if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
  7204. // Might not have attached any initializer to the loop variable.
  7205. getSema().ActOnInitializerError(
  7206. cast<DeclStmt>(LoopVar.get())->getSingleDecl());
  7207. return StmtError();
  7208. }
  7209. }
  7210. StmtResult Body = getDerived().TransformStmt(S->getBody());
  7211. if (Body.isInvalid())
  7212. return StmtError();
  7213. // Body has changed but we didn't rebuild the for-range statement. Rebuild
  7214. // it now so we have a new statement to attach the body to.
  7215. if (Body.get() != S->getBody() && NewStmt.get() == S) {
  7216. NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
  7217. S->getCoawaitLoc(), Init.get(),
  7218. S->getColonLoc(), Range.get(),
  7219. Begin.get(), End.get(),
  7220. Cond.get(),
  7221. Inc.get(), LoopVar.get(),
  7222. S->getRParenLoc());
  7223. if (NewStmt.isInvalid())
  7224. return StmtError();
  7225. }
  7226. if (NewStmt.get() == S)
  7227. return S;
  7228. return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
  7229. }
  7230. template<typename Derived>
  7231. StmtResult
  7232. TreeTransform<Derived>::TransformMSDependentExistsStmt(
  7233. MSDependentExistsStmt *S) {
  7234. // Transform the nested-name-specifier, if any.
  7235. NestedNameSpecifierLoc QualifierLoc;
  7236. if (S->getQualifierLoc()) {
  7237. QualifierLoc
  7238. = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
  7239. if (!QualifierLoc)
  7240. return StmtError();
  7241. }
  7242. // Transform the declaration name.
  7243. DeclarationNameInfo NameInfo = S->getNameInfo();
  7244. if (NameInfo.getName()) {
  7245. NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
  7246. if (!NameInfo.getName())
  7247. return StmtError();
  7248. }
  7249. // Check whether anything changed.
  7250. if (!getDerived().AlwaysRebuild() &&
  7251. QualifierLoc == S->getQualifierLoc() &&
  7252. NameInfo.getName() == S->getNameInfo().getName())
  7253. return S;
  7254. // Determine whether this name exists, if we can.
  7255. CXXScopeSpec SS;
  7256. SS.Adopt(QualifierLoc);
  7257. bool Dependent = false;
  7258. switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
  7259. case Sema::IER_Exists:
  7260. if (S->isIfExists())
  7261. break;
  7262. return new (getSema().Context) NullStmt(S->getKeywordLoc());
  7263. case Sema::IER_DoesNotExist:
  7264. if (S->isIfNotExists())
  7265. break;
  7266. return new (getSema().Context) NullStmt(S->getKeywordLoc());
  7267. case Sema::IER_Dependent:
  7268. Dependent = true;
  7269. break;
  7270. case Sema::IER_Error:
  7271. return StmtError();
  7272. }
  7273. // We need to continue with the instantiation, so do so now.
  7274. StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
  7275. if (SubStmt.isInvalid())
  7276. return StmtError();
  7277. // If we have resolved the name, just transform to the substatement.
  7278. if (!Dependent)
  7279. return SubStmt;
  7280. // The name is still dependent, so build a dependent expression again.
  7281. return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
  7282. S->isIfExists(),
  7283. QualifierLoc,
  7284. NameInfo,
  7285. SubStmt.get());
  7286. }
  7287. template<typename Derived>
  7288. ExprResult
  7289. TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
  7290. NestedNameSpecifierLoc QualifierLoc;
  7291. if (E->getQualifierLoc()) {
  7292. QualifierLoc
  7293. = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
  7294. if (!QualifierLoc)
  7295. return ExprError();
  7296. }
  7297. MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
  7298. getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
  7299. if (!PD)
  7300. return ExprError();
  7301. ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
  7302. if (Base.isInvalid())
  7303. return ExprError();
  7304. return new (SemaRef.getASTContext())
  7305. MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
  7306. SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
  7307. QualifierLoc, E->getMemberLoc());
  7308. }
  7309. template <typename Derived>
  7310. ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
  7311. MSPropertySubscriptExpr *E) {
  7312. auto BaseRes = getDerived().TransformExpr(E->getBase());
  7313. if (BaseRes.isInvalid())
  7314. return ExprError();
  7315. auto IdxRes = getDerived().TransformExpr(E->getIdx());
  7316. if (IdxRes.isInvalid())
  7317. return ExprError();
  7318. if (!getDerived().AlwaysRebuild() &&
  7319. BaseRes.get() == E->getBase() &&
  7320. IdxRes.get() == E->getIdx())
  7321. return E;
  7322. return getDerived().RebuildArraySubscriptExpr(
  7323. BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
  7324. }
  7325. template <typename Derived>
  7326. StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
  7327. StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
  7328. if (TryBlock.isInvalid())
  7329. return StmtError();
  7330. StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
  7331. if (Handler.isInvalid())
  7332. return StmtError();
  7333. if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
  7334. Handler.get() == S->getHandler())
  7335. return S;
  7336. return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
  7337. TryBlock.get(), Handler.get());
  7338. }
  7339. template <typename Derived>
  7340. StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
  7341. StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
  7342. if (Block.isInvalid())
  7343. return StmtError();
  7344. return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
  7345. }
  7346. template <typename Derived>
  7347. StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
  7348. ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
  7349. if (FilterExpr.isInvalid())
  7350. return StmtError();
  7351. StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
  7352. if (Block.isInvalid())
  7353. return StmtError();
  7354. return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
  7355. Block.get());
  7356. }
  7357. template <typename Derived>
  7358. StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
  7359. if (isa<SEHFinallyStmt>(Handler))
  7360. return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
  7361. else
  7362. return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
  7363. }
  7364. template<typename Derived>
  7365. StmtResult
  7366. TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
  7367. return S;
  7368. }
  7369. //===----------------------------------------------------------------------===//
  7370. // OpenMP directive transformation
  7371. //===----------------------------------------------------------------------===//
  7372. template <typename Derived>
  7373. StmtResult
  7374. TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
  7375. // OMPCanonicalLoops are eliminated during transformation, since they will be
  7376. // recomputed by semantic analysis of the associated OMPLoopBasedDirective
  7377. // after transformation.
  7378. return getDerived().TransformStmt(L->getLoopStmt());
  7379. }
  7380. template <typename Derived>
  7381. StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
  7382. OMPExecutableDirective *D) {
  7383. // Transform the clauses
  7384. llvm::SmallVector<OMPClause *, 16> TClauses;
  7385. ArrayRef<OMPClause *> Clauses = D->clauses();
  7386. TClauses.reserve(Clauses.size());
  7387. for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
  7388. I != E; ++I) {
  7389. if (*I) {
  7390. getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
  7391. OMPClause *Clause = getDerived().TransformOMPClause(*I);
  7392. getDerived().getSema().EndOpenMPClause();
  7393. if (Clause)
  7394. TClauses.push_back(Clause);
  7395. } else {
  7396. TClauses.push_back(nullptr);
  7397. }
  7398. }
  7399. StmtResult AssociatedStmt;
  7400. if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
  7401. getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
  7402. /*CurScope=*/nullptr);
  7403. StmtResult Body;
  7404. {
  7405. Sema::CompoundScopeRAII CompoundScope(getSema());
  7406. Stmt *CS;
  7407. if (D->getDirectiveKind() == OMPD_atomic ||
  7408. D->getDirectiveKind() == OMPD_critical ||
  7409. D->getDirectiveKind() == OMPD_section ||
  7410. D->getDirectiveKind() == OMPD_master)
  7411. CS = D->getAssociatedStmt();
  7412. else
  7413. CS = D->getRawStmt();
  7414. Body = getDerived().TransformStmt(CS);
  7415. if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
  7416. getSema().getLangOpts().OpenMPIRBuilder)
  7417. Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
  7418. }
  7419. AssociatedStmt =
  7420. getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
  7421. if (AssociatedStmt.isInvalid()) {
  7422. return StmtError();
  7423. }
  7424. }
  7425. if (TClauses.size() != Clauses.size()) {
  7426. return StmtError();
  7427. }
  7428. // Transform directive name for 'omp critical' directive.
  7429. DeclarationNameInfo DirName;
  7430. if (D->getDirectiveKind() == OMPD_critical) {
  7431. DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
  7432. DirName = getDerived().TransformDeclarationNameInfo(DirName);
  7433. }
  7434. OpenMPDirectiveKind CancelRegion = OMPD_unknown;
  7435. if (D->getDirectiveKind() == OMPD_cancellation_point) {
  7436. CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
  7437. } else if (D->getDirectiveKind() == OMPD_cancel) {
  7438. CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
  7439. }
  7440. return getDerived().RebuildOMPExecutableDirective(
  7441. D->getDirectiveKind(), DirName, CancelRegion, TClauses,
  7442. AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
  7443. }
  7444. template <typename Derived>
  7445. StmtResult
  7446. TreeTransform<Derived>::TransformOMPMetaDirective(OMPMetaDirective *D) {
  7447. // TODO: Fix This
  7448. SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
  7449. << getOpenMPDirectiveName(D->getDirectiveKind());
  7450. return StmtError();
  7451. }
  7452. template <typename Derived>
  7453. StmtResult
  7454. TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
  7455. DeclarationNameInfo DirName;
  7456. getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
  7457. D->getBeginLoc());
  7458. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7459. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7460. return Res;
  7461. }
  7462. template <typename Derived>
  7463. StmtResult
  7464. TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
  7465. DeclarationNameInfo DirName;
  7466. getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
  7467. D->getBeginLoc());
  7468. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7469. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7470. return Res;
  7471. }
  7472. template <typename Derived>
  7473. StmtResult
  7474. TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
  7475. DeclarationNameInfo DirName;
  7476. getDerived().getSema().StartOpenMPDSABlock(D->getDirectiveKind(), DirName,
  7477. nullptr, D->getBeginLoc());
  7478. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7479. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7480. return Res;
  7481. }
  7482. template <typename Derived>
  7483. StmtResult
  7484. TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
  7485. DeclarationNameInfo DirName;
  7486. getDerived().getSema().StartOpenMPDSABlock(D->getDirectiveKind(), DirName,
  7487. nullptr, D->getBeginLoc());
  7488. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7489. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7490. return Res;
  7491. }
  7492. template <typename Derived>
  7493. StmtResult
  7494. TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
  7495. DeclarationNameInfo DirName;
  7496. getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
  7497. D->getBeginLoc());
  7498. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7499. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7500. return Res;
  7501. }
  7502. template <typename Derived>
  7503. StmtResult
  7504. TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
  7505. DeclarationNameInfo DirName;
  7506. getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
  7507. D->getBeginLoc());
  7508. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7509. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7510. return Res;
  7511. }
  7512. template <typename Derived>
  7513. StmtResult
  7514. TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
  7515. DeclarationNameInfo DirName;
  7516. getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
  7517. D->getBeginLoc());
  7518. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7519. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7520. return Res;
  7521. }
  7522. template <typename Derived>
  7523. StmtResult
  7524. TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
  7525. DeclarationNameInfo DirName;
  7526. getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
  7527. D->getBeginLoc());
  7528. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7529. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7530. return Res;
  7531. }
  7532. template <typename Derived>
  7533. StmtResult
  7534. TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
  7535. DeclarationNameInfo DirName;
  7536. getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
  7537. D->getBeginLoc());
  7538. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7539. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7540. return Res;
  7541. }
  7542. template <typename Derived>
  7543. StmtResult
  7544. TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
  7545. DeclarationNameInfo DirName;
  7546. getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
  7547. D->getBeginLoc());
  7548. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7549. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7550. return Res;
  7551. }
  7552. template <typename Derived>
  7553. StmtResult
  7554. TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
  7555. getDerived().getSema().StartOpenMPDSABlock(
  7556. OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
  7557. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7558. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7559. return Res;
  7560. }
  7561. template <typename Derived>
  7562. StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
  7563. OMPParallelForDirective *D) {
  7564. DeclarationNameInfo DirName;
  7565. getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
  7566. nullptr, D->getBeginLoc());
  7567. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7568. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7569. return Res;
  7570. }
  7571. template <typename Derived>
  7572. StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
  7573. OMPParallelForSimdDirective *D) {
  7574. DeclarationNameInfo DirName;
  7575. getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
  7576. nullptr, D->getBeginLoc());
  7577. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7578. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7579. return Res;
  7580. }
  7581. template <typename Derived>
  7582. StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
  7583. OMPParallelMasterDirective *D) {
  7584. DeclarationNameInfo DirName;
  7585. getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master, DirName,
  7586. nullptr, D->getBeginLoc());
  7587. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7588. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7589. return Res;
  7590. }
  7591. template <typename Derived>
  7592. StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
  7593. OMPParallelSectionsDirective *D) {
  7594. DeclarationNameInfo DirName;
  7595. getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
  7596. nullptr, D->getBeginLoc());
  7597. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7598. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7599. return Res;
  7600. }
  7601. template <typename Derived>
  7602. StmtResult
  7603. TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
  7604. DeclarationNameInfo DirName;
  7605. getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
  7606. D->getBeginLoc());
  7607. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7608. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7609. return Res;
  7610. }
  7611. template <typename Derived>
  7612. StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
  7613. OMPTaskyieldDirective *D) {
  7614. DeclarationNameInfo DirName;
  7615. getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
  7616. D->getBeginLoc());
  7617. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7618. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7619. return Res;
  7620. }
  7621. template <typename Derived>
  7622. StmtResult
  7623. TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
  7624. DeclarationNameInfo DirName;
  7625. getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
  7626. D->getBeginLoc());
  7627. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7628. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7629. return Res;
  7630. }
  7631. template <typename Derived>
  7632. StmtResult
  7633. TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
  7634. DeclarationNameInfo DirName;
  7635. getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
  7636. D->getBeginLoc());
  7637. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7638. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7639. return Res;
  7640. }
  7641. template <typename Derived>
  7642. StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
  7643. OMPTaskgroupDirective *D) {
  7644. DeclarationNameInfo DirName;
  7645. getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
  7646. D->getBeginLoc());
  7647. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7648. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7649. return Res;
  7650. }
  7651. template <typename Derived>
  7652. StmtResult
  7653. TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
  7654. DeclarationNameInfo DirName;
  7655. getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
  7656. D->getBeginLoc());
  7657. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7658. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7659. return Res;
  7660. }
  7661. template <typename Derived>
  7662. StmtResult
  7663. TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
  7664. DeclarationNameInfo DirName;
  7665. getDerived().getSema().StartOpenMPDSABlock(OMPD_depobj, DirName, nullptr,
  7666. D->getBeginLoc());
  7667. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7668. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7669. return Res;
  7670. }
  7671. template <typename Derived>
  7672. StmtResult
  7673. TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
  7674. DeclarationNameInfo DirName;
  7675. getDerived().getSema().StartOpenMPDSABlock(OMPD_scan, DirName, nullptr,
  7676. D->getBeginLoc());
  7677. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7678. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7679. return Res;
  7680. }
  7681. template <typename Derived>
  7682. StmtResult
  7683. TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
  7684. DeclarationNameInfo DirName;
  7685. getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
  7686. D->getBeginLoc());
  7687. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7688. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7689. return Res;
  7690. }
  7691. template <typename Derived>
  7692. StmtResult
  7693. TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
  7694. DeclarationNameInfo DirName;
  7695. getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
  7696. D->getBeginLoc());
  7697. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7698. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7699. return Res;
  7700. }
  7701. template <typename Derived>
  7702. StmtResult
  7703. TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
  7704. DeclarationNameInfo DirName;
  7705. getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
  7706. D->getBeginLoc());
  7707. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7708. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7709. return Res;
  7710. }
  7711. template <typename Derived>
  7712. StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
  7713. OMPTargetDataDirective *D) {
  7714. DeclarationNameInfo DirName;
  7715. getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
  7716. D->getBeginLoc());
  7717. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7718. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7719. return Res;
  7720. }
  7721. template <typename Derived>
  7722. StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
  7723. OMPTargetEnterDataDirective *D) {
  7724. DeclarationNameInfo DirName;
  7725. getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
  7726. nullptr, D->getBeginLoc());
  7727. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7728. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7729. return Res;
  7730. }
  7731. template <typename Derived>
  7732. StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
  7733. OMPTargetExitDataDirective *D) {
  7734. DeclarationNameInfo DirName;
  7735. getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
  7736. nullptr, D->getBeginLoc());
  7737. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7738. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7739. return Res;
  7740. }
  7741. template <typename Derived>
  7742. StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
  7743. OMPTargetParallelDirective *D) {
  7744. DeclarationNameInfo DirName;
  7745. getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
  7746. nullptr, D->getBeginLoc());
  7747. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7748. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7749. return Res;
  7750. }
  7751. template <typename Derived>
  7752. StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
  7753. OMPTargetParallelForDirective *D) {
  7754. DeclarationNameInfo DirName;
  7755. getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
  7756. nullptr, D->getBeginLoc());
  7757. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7758. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7759. return Res;
  7760. }
  7761. template <typename Derived>
  7762. StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
  7763. OMPTargetUpdateDirective *D) {
  7764. DeclarationNameInfo DirName;
  7765. getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
  7766. nullptr, D->getBeginLoc());
  7767. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7768. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7769. return Res;
  7770. }
  7771. template <typename Derived>
  7772. StmtResult
  7773. TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
  7774. DeclarationNameInfo DirName;
  7775. getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
  7776. D->getBeginLoc());
  7777. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7778. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7779. return Res;
  7780. }
  7781. template <typename Derived>
  7782. StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
  7783. OMPCancellationPointDirective *D) {
  7784. DeclarationNameInfo DirName;
  7785. getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
  7786. nullptr, D->getBeginLoc());
  7787. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7788. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7789. return Res;
  7790. }
  7791. template <typename Derived>
  7792. StmtResult
  7793. TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
  7794. DeclarationNameInfo DirName;
  7795. getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
  7796. D->getBeginLoc());
  7797. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7798. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7799. return Res;
  7800. }
  7801. template <typename Derived>
  7802. StmtResult
  7803. TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
  7804. DeclarationNameInfo DirName;
  7805. getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
  7806. D->getBeginLoc());
  7807. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7808. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7809. return Res;
  7810. }
  7811. template <typename Derived>
  7812. StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
  7813. OMPTaskLoopSimdDirective *D) {
  7814. DeclarationNameInfo DirName;
  7815. getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
  7816. nullptr, D->getBeginLoc());
  7817. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7818. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7819. return Res;
  7820. }
  7821. template <typename Derived>
  7822. StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
  7823. OMPMasterTaskLoopDirective *D) {
  7824. DeclarationNameInfo DirName;
  7825. getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop, DirName,
  7826. nullptr, D->getBeginLoc());
  7827. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7828. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7829. return Res;
  7830. }
  7831. template <typename Derived>
  7832. StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
  7833. OMPMasterTaskLoopSimdDirective *D) {
  7834. DeclarationNameInfo DirName;
  7835. getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop_simd, DirName,
  7836. nullptr, D->getBeginLoc());
  7837. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7838. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7839. return Res;
  7840. }
  7841. template <typename Derived>
  7842. StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
  7843. OMPParallelMasterTaskLoopDirective *D) {
  7844. DeclarationNameInfo DirName;
  7845. getDerived().getSema().StartOpenMPDSABlock(
  7846. OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
  7847. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7848. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7849. return Res;
  7850. }
  7851. template <typename Derived>
  7852. StmtResult
  7853. TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
  7854. OMPParallelMasterTaskLoopSimdDirective *D) {
  7855. DeclarationNameInfo DirName;
  7856. getDerived().getSema().StartOpenMPDSABlock(
  7857. OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
  7858. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7859. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7860. return Res;
  7861. }
  7862. template <typename Derived>
  7863. StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
  7864. OMPDistributeDirective *D) {
  7865. DeclarationNameInfo DirName;
  7866. getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
  7867. D->getBeginLoc());
  7868. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7869. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7870. return Res;
  7871. }
  7872. template <typename Derived>
  7873. StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
  7874. OMPDistributeParallelForDirective *D) {
  7875. DeclarationNameInfo DirName;
  7876. getDerived().getSema().StartOpenMPDSABlock(
  7877. OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
  7878. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7879. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7880. return Res;
  7881. }
  7882. template <typename Derived>
  7883. StmtResult
  7884. TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
  7885. OMPDistributeParallelForSimdDirective *D) {
  7886. DeclarationNameInfo DirName;
  7887. getDerived().getSema().StartOpenMPDSABlock(
  7888. OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
  7889. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7890. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7891. return Res;
  7892. }
  7893. template <typename Derived>
  7894. StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
  7895. OMPDistributeSimdDirective *D) {
  7896. DeclarationNameInfo DirName;
  7897. getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
  7898. nullptr, D->getBeginLoc());
  7899. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7900. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7901. return Res;
  7902. }
  7903. template <typename Derived>
  7904. StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
  7905. OMPTargetParallelForSimdDirective *D) {
  7906. DeclarationNameInfo DirName;
  7907. getDerived().getSema().StartOpenMPDSABlock(
  7908. OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
  7909. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7910. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7911. return Res;
  7912. }
  7913. template <typename Derived>
  7914. StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
  7915. OMPTargetSimdDirective *D) {
  7916. DeclarationNameInfo DirName;
  7917. getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
  7918. D->getBeginLoc());
  7919. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7920. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7921. return Res;
  7922. }
  7923. template <typename Derived>
  7924. StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
  7925. OMPTeamsDistributeDirective *D) {
  7926. DeclarationNameInfo DirName;
  7927. getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
  7928. nullptr, D->getBeginLoc());
  7929. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7930. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7931. return Res;
  7932. }
  7933. template <typename Derived>
  7934. StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
  7935. OMPTeamsDistributeSimdDirective *D) {
  7936. DeclarationNameInfo DirName;
  7937. getDerived().getSema().StartOpenMPDSABlock(
  7938. OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
  7939. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7940. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7941. return Res;
  7942. }
  7943. template <typename Derived>
  7944. StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
  7945. OMPTeamsDistributeParallelForSimdDirective *D) {
  7946. DeclarationNameInfo DirName;
  7947. getDerived().getSema().StartOpenMPDSABlock(
  7948. OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
  7949. D->getBeginLoc());
  7950. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7951. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7952. return Res;
  7953. }
  7954. template <typename Derived>
  7955. StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
  7956. OMPTeamsDistributeParallelForDirective *D) {
  7957. DeclarationNameInfo DirName;
  7958. getDerived().getSema().StartOpenMPDSABlock(
  7959. OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
  7960. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  7961. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7962. return Res;
  7963. }
  7964. template <typename Derived>
  7965. StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
  7966. OMPTargetTeamsDirective *D) {
  7967. DeclarationNameInfo DirName;
  7968. getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
  7969. nullptr, D->getBeginLoc());
  7970. auto Res = getDerived().TransformOMPExecutableDirective(D);
  7971. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7972. return Res;
  7973. }
  7974. template <typename Derived>
  7975. StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
  7976. OMPTargetTeamsDistributeDirective *D) {
  7977. DeclarationNameInfo DirName;
  7978. getDerived().getSema().StartOpenMPDSABlock(
  7979. OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
  7980. auto Res = getDerived().TransformOMPExecutableDirective(D);
  7981. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7982. return Res;
  7983. }
  7984. template <typename Derived>
  7985. StmtResult
  7986. TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
  7987. OMPTargetTeamsDistributeParallelForDirective *D) {
  7988. DeclarationNameInfo DirName;
  7989. getDerived().getSema().StartOpenMPDSABlock(
  7990. OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
  7991. D->getBeginLoc());
  7992. auto Res = getDerived().TransformOMPExecutableDirective(D);
  7993. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  7994. return Res;
  7995. }
  7996. template <typename Derived>
  7997. StmtResult TreeTransform<Derived>::
  7998. TransformOMPTargetTeamsDistributeParallelForSimdDirective(
  7999. OMPTargetTeamsDistributeParallelForSimdDirective *D) {
  8000. DeclarationNameInfo DirName;
  8001. getDerived().getSema().StartOpenMPDSABlock(
  8002. OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
  8003. D->getBeginLoc());
  8004. auto Res = getDerived().TransformOMPExecutableDirective(D);
  8005. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  8006. return Res;
  8007. }
  8008. template <typename Derived>
  8009. StmtResult
  8010. TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
  8011. OMPTargetTeamsDistributeSimdDirective *D) {
  8012. DeclarationNameInfo DirName;
  8013. getDerived().getSema().StartOpenMPDSABlock(
  8014. OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
  8015. auto Res = getDerived().TransformOMPExecutableDirective(D);
  8016. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  8017. return Res;
  8018. }
  8019. template <typename Derived>
  8020. StmtResult
  8021. TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
  8022. DeclarationNameInfo DirName;
  8023. getDerived().getSema().StartOpenMPDSABlock(OMPD_interop, DirName, nullptr,
  8024. D->getBeginLoc());
  8025. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  8026. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  8027. return Res;
  8028. }
  8029. template <typename Derived>
  8030. StmtResult
  8031. TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
  8032. DeclarationNameInfo DirName;
  8033. getDerived().getSema().StartOpenMPDSABlock(OMPD_dispatch, DirName, nullptr,
  8034. D->getBeginLoc());
  8035. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  8036. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  8037. return Res;
  8038. }
  8039. template <typename Derived>
  8040. StmtResult
  8041. TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
  8042. DeclarationNameInfo DirName;
  8043. getDerived().getSema().StartOpenMPDSABlock(OMPD_masked, DirName, nullptr,
  8044. D->getBeginLoc());
  8045. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  8046. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  8047. return Res;
  8048. }
  8049. template <typename Derived>
  8050. StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
  8051. OMPGenericLoopDirective *D) {
  8052. DeclarationNameInfo DirName;
  8053. getDerived().getSema().StartOpenMPDSABlock(OMPD_loop, DirName, nullptr,
  8054. D->getBeginLoc());
  8055. StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
  8056. getDerived().getSema().EndOpenMPDSABlock(Res.get());
  8057. return Res;
  8058. }
  8059. //===----------------------------------------------------------------------===//
  8060. // OpenMP clause transformation
  8061. //===----------------------------------------------------------------------===//
  8062. template <typename Derived>
  8063. OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
  8064. ExprResult Cond = getDerived().TransformExpr(C->getCondition());
  8065. if (Cond.isInvalid())
  8066. return nullptr;
  8067. return getDerived().RebuildOMPIfClause(
  8068. C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
  8069. C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
  8070. }
  8071. template <typename Derived>
  8072. OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
  8073. ExprResult Cond = getDerived().TransformExpr(C->getCondition());
  8074. if (Cond.isInvalid())
  8075. return nullptr;
  8076. return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
  8077. C->getLParenLoc(), C->getEndLoc());
  8078. }
  8079. template <typename Derived>
  8080. OMPClause *
  8081. TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
  8082. ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
  8083. if (NumThreads.isInvalid())
  8084. return nullptr;
  8085. return getDerived().RebuildOMPNumThreadsClause(
  8086. NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8087. }
  8088. template <typename Derived>
  8089. OMPClause *
  8090. TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
  8091. ExprResult E = getDerived().TransformExpr(C->getSafelen());
  8092. if (E.isInvalid())
  8093. return nullptr;
  8094. return getDerived().RebuildOMPSafelenClause(
  8095. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8096. }
  8097. template <typename Derived>
  8098. OMPClause *
  8099. TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
  8100. ExprResult E = getDerived().TransformExpr(C->getAllocator());
  8101. if (E.isInvalid())
  8102. return nullptr;
  8103. return getDerived().RebuildOMPAllocatorClause(
  8104. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8105. }
  8106. template <typename Derived>
  8107. OMPClause *
  8108. TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
  8109. ExprResult E = getDerived().TransformExpr(C->getSimdlen());
  8110. if (E.isInvalid())
  8111. return nullptr;
  8112. return getDerived().RebuildOMPSimdlenClause(
  8113. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8114. }
  8115. template <typename Derived>
  8116. OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
  8117. SmallVector<Expr *, 4> TransformedSizes;
  8118. TransformedSizes.reserve(C->getNumSizes());
  8119. bool Changed = false;
  8120. for (Expr *E : C->getSizesRefs()) {
  8121. if (!E) {
  8122. TransformedSizes.push_back(nullptr);
  8123. continue;
  8124. }
  8125. ExprResult T = getDerived().TransformExpr(E);
  8126. if (T.isInvalid())
  8127. return nullptr;
  8128. if (E != T.get())
  8129. Changed = true;
  8130. TransformedSizes.push_back(T.get());
  8131. }
  8132. if (!Changed && !getDerived().AlwaysRebuild())
  8133. return C;
  8134. return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
  8135. C->getLParenLoc(), C->getEndLoc());
  8136. }
  8137. template <typename Derived>
  8138. OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
  8139. if (!getDerived().AlwaysRebuild())
  8140. return C;
  8141. return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
  8142. }
  8143. template <typename Derived>
  8144. OMPClause *
  8145. TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
  8146. ExprResult T = getDerived().TransformExpr(C->getFactor());
  8147. if (T.isInvalid())
  8148. return nullptr;
  8149. Expr *Factor = T.get();
  8150. bool Changed = Factor != C->getFactor();
  8151. if (!Changed && !getDerived().AlwaysRebuild())
  8152. return C;
  8153. return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
  8154. C->getEndLoc());
  8155. }
  8156. template <typename Derived>
  8157. OMPClause *
  8158. TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
  8159. ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
  8160. if (E.isInvalid())
  8161. return nullptr;
  8162. return getDerived().RebuildOMPCollapseClause(
  8163. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8164. }
  8165. template <typename Derived>
  8166. OMPClause *
  8167. TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
  8168. return getDerived().RebuildOMPDefaultClause(
  8169. C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
  8170. C->getLParenLoc(), C->getEndLoc());
  8171. }
  8172. template <typename Derived>
  8173. OMPClause *
  8174. TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
  8175. return getDerived().RebuildOMPProcBindClause(
  8176. C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
  8177. C->getLParenLoc(), C->getEndLoc());
  8178. }
  8179. template <typename Derived>
  8180. OMPClause *
  8181. TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
  8182. ExprResult E = getDerived().TransformExpr(C->getChunkSize());
  8183. if (E.isInvalid())
  8184. return nullptr;
  8185. return getDerived().RebuildOMPScheduleClause(
  8186. C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
  8187. C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
  8188. C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
  8189. C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
  8190. }
  8191. template <typename Derived>
  8192. OMPClause *
  8193. TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
  8194. ExprResult E;
  8195. if (auto *Num = C->getNumForLoops()) {
  8196. E = getDerived().TransformExpr(Num);
  8197. if (E.isInvalid())
  8198. return nullptr;
  8199. }
  8200. return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
  8201. C->getLParenLoc(), E.get());
  8202. }
  8203. template <typename Derived>
  8204. OMPClause *
  8205. TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
  8206. ExprResult E;
  8207. if (Expr *Evt = C->getEventHandler()) {
  8208. E = getDerived().TransformExpr(Evt);
  8209. if (E.isInvalid())
  8210. return nullptr;
  8211. }
  8212. return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
  8213. C->getLParenLoc(), C->getEndLoc());
  8214. }
  8215. template <typename Derived>
  8216. OMPClause *
  8217. TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
  8218. // No need to rebuild this clause, no template-dependent parameters.
  8219. return C;
  8220. }
  8221. template <typename Derived>
  8222. OMPClause *
  8223. TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
  8224. // No need to rebuild this clause, no template-dependent parameters.
  8225. return C;
  8226. }
  8227. template <typename Derived>
  8228. OMPClause *
  8229. TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
  8230. // No need to rebuild this clause, no template-dependent parameters.
  8231. return C;
  8232. }
  8233. template <typename Derived>
  8234. OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
  8235. // No need to rebuild this clause, no template-dependent parameters.
  8236. return C;
  8237. }
  8238. template <typename Derived>
  8239. OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
  8240. // No need to rebuild this clause, no template-dependent parameters.
  8241. return C;
  8242. }
  8243. template <typename Derived>
  8244. OMPClause *
  8245. TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
  8246. // No need to rebuild this clause, no template-dependent parameters.
  8247. return C;
  8248. }
  8249. template <typename Derived>
  8250. OMPClause *
  8251. TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
  8252. // No need to rebuild this clause, no template-dependent parameters.
  8253. return C;
  8254. }
  8255. template <typename Derived>
  8256. OMPClause *
  8257. TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
  8258. // No need to rebuild this clause, no template-dependent parameters.
  8259. return C;
  8260. }
  8261. template <typename Derived>
  8262. OMPClause *
  8263. TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
  8264. // No need to rebuild this clause, no template-dependent parameters.
  8265. return C;
  8266. }
  8267. template <typename Derived>
  8268. OMPClause *
  8269. TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
  8270. // No need to rebuild this clause, no template-dependent parameters.
  8271. return C;
  8272. }
  8273. template <typename Derived>
  8274. OMPClause *
  8275. TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
  8276. // No need to rebuild this clause, no template-dependent parameters.
  8277. return C;
  8278. }
  8279. template <typename Derived>
  8280. OMPClause *
  8281. TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
  8282. // No need to rebuild this clause, no template-dependent parameters.
  8283. return C;
  8284. }
  8285. template <typename Derived>
  8286. OMPClause *
  8287. TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
  8288. // No need to rebuild this clause, no template-dependent parameters.
  8289. return C;
  8290. }
  8291. template <typename Derived>
  8292. OMPClause *
  8293. TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
  8294. // No need to rebuild this clause, no template-dependent parameters.
  8295. return C;
  8296. }
  8297. template <typename Derived>
  8298. OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
  8299. // No need to rebuild this clause, no template-dependent parameters.
  8300. return C;
  8301. }
  8302. template <typename Derived>
  8303. OMPClause *
  8304. TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
  8305. // No need to rebuild this clause, no template-dependent parameters.
  8306. return C;
  8307. }
  8308. template <typename Derived>
  8309. OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
  8310. ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
  8311. if (IVR.isInvalid())
  8312. return nullptr;
  8313. llvm::SmallVector<Expr *, 8> PrefExprs;
  8314. PrefExprs.reserve(C->varlist_size() - 1);
  8315. for (Expr *E : llvm::drop_begin(C->varlists())) {
  8316. ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
  8317. if (ER.isInvalid())
  8318. return nullptr;
  8319. PrefExprs.push_back(ER.get());
  8320. }
  8321. return getDerived().RebuildOMPInitClause(
  8322. IVR.get(), PrefExprs, C->getIsTarget(), C->getIsTargetSync(),
  8323. C->getBeginLoc(), C->getLParenLoc(), C->getVarLoc(), C->getEndLoc());
  8324. }
  8325. template <typename Derived>
  8326. OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
  8327. ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
  8328. if (ER.isInvalid())
  8329. return nullptr;
  8330. return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
  8331. C->getLParenLoc(), C->getVarLoc(),
  8332. C->getEndLoc());
  8333. }
  8334. template <typename Derived>
  8335. OMPClause *
  8336. TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
  8337. ExprResult ER;
  8338. if (Expr *IV = C->getInteropVar()) {
  8339. ER = getDerived().TransformExpr(IV);
  8340. if (ER.isInvalid())
  8341. return nullptr;
  8342. }
  8343. return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
  8344. C->getLParenLoc(), C->getVarLoc(),
  8345. C->getEndLoc());
  8346. }
  8347. template <typename Derived>
  8348. OMPClause *
  8349. TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
  8350. ExprResult Cond = getDerived().TransformExpr(C->getCondition());
  8351. if (Cond.isInvalid())
  8352. return nullptr;
  8353. return getDerived().RebuildOMPNovariantsClause(
  8354. Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8355. }
  8356. template <typename Derived>
  8357. OMPClause *
  8358. TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
  8359. ExprResult Cond = getDerived().TransformExpr(C->getCondition());
  8360. if (Cond.isInvalid())
  8361. return nullptr;
  8362. return getDerived().RebuildOMPNocontextClause(
  8363. Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8364. }
  8365. template <typename Derived>
  8366. OMPClause *
  8367. TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
  8368. ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
  8369. if (ThreadID.isInvalid())
  8370. return nullptr;
  8371. return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
  8372. C->getLParenLoc(), C->getEndLoc());
  8373. }
  8374. template <typename Derived>
  8375. OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
  8376. ExprResult E = getDerived().TransformExpr(C->getAlignment());
  8377. if (E.isInvalid())
  8378. return nullptr;
  8379. return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
  8380. C->getLParenLoc(), C->getEndLoc());
  8381. }
  8382. template <typename Derived>
  8383. OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
  8384. OMPUnifiedAddressClause *C) {
  8385. llvm_unreachable("unified_address clause cannot appear in dependent context");
  8386. }
  8387. template <typename Derived>
  8388. OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
  8389. OMPUnifiedSharedMemoryClause *C) {
  8390. llvm_unreachable(
  8391. "unified_shared_memory clause cannot appear in dependent context");
  8392. }
  8393. template <typename Derived>
  8394. OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
  8395. OMPReverseOffloadClause *C) {
  8396. llvm_unreachable("reverse_offload clause cannot appear in dependent context");
  8397. }
  8398. template <typename Derived>
  8399. OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
  8400. OMPDynamicAllocatorsClause *C) {
  8401. llvm_unreachable(
  8402. "dynamic_allocators clause cannot appear in dependent context");
  8403. }
  8404. template <typename Derived>
  8405. OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
  8406. OMPAtomicDefaultMemOrderClause *C) {
  8407. llvm_unreachable(
  8408. "atomic_default_mem_order clause cannot appear in dependent context");
  8409. }
  8410. template <typename Derived>
  8411. OMPClause *
  8412. TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
  8413. llvm::SmallVector<Expr *, 16> Vars;
  8414. Vars.reserve(C->varlist_size());
  8415. for (auto *VE : C->varlists()) {
  8416. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8417. if (EVar.isInvalid())
  8418. return nullptr;
  8419. Vars.push_back(EVar.get());
  8420. }
  8421. return getDerived().RebuildOMPPrivateClause(
  8422. Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8423. }
  8424. template <typename Derived>
  8425. OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
  8426. OMPFirstprivateClause *C) {
  8427. llvm::SmallVector<Expr *, 16> Vars;
  8428. Vars.reserve(C->varlist_size());
  8429. for (auto *VE : C->varlists()) {
  8430. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8431. if (EVar.isInvalid())
  8432. return nullptr;
  8433. Vars.push_back(EVar.get());
  8434. }
  8435. return getDerived().RebuildOMPFirstprivateClause(
  8436. Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8437. }
  8438. template <typename Derived>
  8439. OMPClause *
  8440. TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
  8441. llvm::SmallVector<Expr *, 16> Vars;
  8442. Vars.reserve(C->varlist_size());
  8443. for (auto *VE : C->varlists()) {
  8444. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8445. if (EVar.isInvalid())
  8446. return nullptr;
  8447. Vars.push_back(EVar.get());
  8448. }
  8449. return getDerived().RebuildOMPLastprivateClause(
  8450. Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
  8451. C->getLParenLoc(), C->getEndLoc());
  8452. }
  8453. template <typename Derived>
  8454. OMPClause *
  8455. TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
  8456. llvm::SmallVector<Expr *, 16> Vars;
  8457. Vars.reserve(C->varlist_size());
  8458. for (auto *VE : C->varlists()) {
  8459. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8460. if (EVar.isInvalid())
  8461. return nullptr;
  8462. Vars.push_back(EVar.get());
  8463. }
  8464. return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
  8465. C->getLParenLoc(), C->getEndLoc());
  8466. }
  8467. template <typename Derived>
  8468. OMPClause *
  8469. TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
  8470. llvm::SmallVector<Expr *, 16> Vars;
  8471. Vars.reserve(C->varlist_size());
  8472. for (auto *VE : C->varlists()) {
  8473. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8474. if (EVar.isInvalid())
  8475. return nullptr;
  8476. Vars.push_back(EVar.get());
  8477. }
  8478. CXXScopeSpec ReductionIdScopeSpec;
  8479. ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
  8480. DeclarationNameInfo NameInfo = C->getNameInfo();
  8481. if (NameInfo.getName()) {
  8482. NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
  8483. if (!NameInfo.getName())
  8484. return nullptr;
  8485. }
  8486. // Build a list of all UDR decls with the same names ranged by the Scopes.
  8487. // The Scope boundary is a duplication of the previous decl.
  8488. llvm::SmallVector<Expr *, 16> UnresolvedReductions;
  8489. for (auto *E : C->reduction_ops()) {
  8490. // Transform all the decls.
  8491. if (E) {
  8492. auto *ULE = cast<UnresolvedLookupExpr>(E);
  8493. UnresolvedSet<8> Decls;
  8494. for (auto *D : ULE->decls()) {
  8495. NamedDecl *InstD =
  8496. cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
  8497. Decls.addDecl(InstD, InstD->getAccess());
  8498. }
  8499. UnresolvedReductions.push_back(
  8500. UnresolvedLookupExpr::Create(
  8501. SemaRef.Context, /*NamingClass=*/nullptr,
  8502. ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
  8503. NameInfo, /*ADL=*/true, ULE->isOverloaded(),
  8504. Decls.begin(), Decls.end()));
  8505. } else
  8506. UnresolvedReductions.push_back(nullptr);
  8507. }
  8508. return getDerived().RebuildOMPReductionClause(
  8509. Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(),
  8510. C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
  8511. ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
  8512. }
  8513. template <typename Derived>
  8514. OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
  8515. OMPTaskReductionClause *C) {
  8516. llvm::SmallVector<Expr *, 16> Vars;
  8517. Vars.reserve(C->varlist_size());
  8518. for (auto *VE : C->varlists()) {
  8519. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8520. if (EVar.isInvalid())
  8521. return nullptr;
  8522. Vars.push_back(EVar.get());
  8523. }
  8524. CXXScopeSpec ReductionIdScopeSpec;
  8525. ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
  8526. DeclarationNameInfo NameInfo = C->getNameInfo();
  8527. if (NameInfo.getName()) {
  8528. NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
  8529. if (!NameInfo.getName())
  8530. return nullptr;
  8531. }
  8532. // Build a list of all UDR decls with the same names ranged by the Scopes.
  8533. // The Scope boundary is a duplication of the previous decl.
  8534. llvm::SmallVector<Expr *, 16> UnresolvedReductions;
  8535. for (auto *E : C->reduction_ops()) {
  8536. // Transform all the decls.
  8537. if (E) {
  8538. auto *ULE = cast<UnresolvedLookupExpr>(E);
  8539. UnresolvedSet<8> Decls;
  8540. for (auto *D : ULE->decls()) {
  8541. NamedDecl *InstD =
  8542. cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
  8543. Decls.addDecl(InstD, InstD->getAccess());
  8544. }
  8545. UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
  8546. SemaRef.Context, /*NamingClass=*/nullptr,
  8547. ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
  8548. /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
  8549. } else
  8550. UnresolvedReductions.push_back(nullptr);
  8551. }
  8552. return getDerived().RebuildOMPTaskReductionClause(
  8553. Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
  8554. C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
  8555. }
  8556. template <typename Derived>
  8557. OMPClause *
  8558. TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
  8559. llvm::SmallVector<Expr *, 16> Vars;
  8560. Vars.reserve(C->varlist_size());
  8561. for (auto *VE : C->varlists()) {
  8562. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8563. if (EVar.isInvalid())
  8564. return nullptr;
  8565. Vars.push_back(EVar.get());
  8566. }
  8567. CXXScopeSpec ReductionIdScopeSpec;
  8568. ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
  8569. DeclarationNameInfo NameInfo = C->getNameInfo();
  8570. if (NameInfo.getName()) {
  8571. NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
  8572. if (!NameInfo.getName())
  8573. return nullptr;
  8574. }
  8575. // Build a list of all UDR decls with the same names ranged by the Scopes.
  8576. // The Scope boundary is a duplication of the previous decl.
  8577. llvm::SmallVector<Expr *, 16> UnresolvedReductions;
  8578. for (auto *E : C->reduction_ops()) {
  8579. // Transform all the decls.
  8580. if (E) {
  8581. auto *ULE = cast<UnresolvedLookupExpr>(E);
  8582. UnresolvedSet<8> Decls;
  8583. for (auto *D : ULE->decls()) {
  8584. NamedDecl *InstD =
  8585. cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
  8586. Decls.addDecl(InstD, InstD->getAccess());
  8587. }
  8588. UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
  8589. SemaRef.Context, /*NamingClass=*/nullptr,
  8590. ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
  8591. /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
  8592. } else
  8593. UnresolvedReductions.push_back(nullptr);
  8594. }
  8595. return getDerived().RebuildOMPInReductionClause(
  8596. Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
  8597. C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
  8598. }
  8599. template <typename Derived>
  8600. OMPClause *
  8601. TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
  8602. llvm::SmallVector<Expr *, 16> Vars;
  8603. Vars.reserve(C->varlist_size());
  8604. for (auto *VE : C->varlists()) {
  8605. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8606. if (EVar.isInvalid())
  8607. return nullptr;
  8608. Vars.push_back(EVar.get());
  8609. }
  8610. ExprResult Step = getDerived().TransformExpr(C->getStep());
  8611. if (Step.isInvalid())
  8612. return nullptr;
  8613. return getDerived().RebuildOMPLinearClause(
  8614. Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
  8615. C->getModifierLoc(), C->getColonLoc(), C->getEndLoc());
  8616. }
  8617. template <typename Derived>
  8618. OMPClause *
  8619. TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
  8620. llvm::SmallVector<Expr *, 16> Vars;
  8621. Vars.reserve(C->varlist_size());
  8622. for (auto *VE : C->varlists()) {
  8623. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8624. if (EVar.isInvalid())
  8625. return nullptr;
  8626. Vars.push_back(EVar.get());
  8627. }
  8628. ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
  8629. if (Alignment.isInvalid())
  8630. return nullptr;
  8631. return getDerived().RebuildOMPAlignedClause(
  8632. Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
  8633. C->getColonLoc(), C->getEndLoc());
  8634. }
  8635. template <typename Derived>
  8636. OMPClause *
  8637. TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
  8638. llvm::SmallVector<Expr *, 16> Vars;
  8639. Vars.reserve(C->varlist_size());
  8640. for (auto *VE : C->varlists()) {
  8641. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8642. if (EVar.isInvalid())
  8643. return nullptr;
  8644. Vars.push_back(EVar.get());
  8645. }
  8646. return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
  8647. C->getLParenLoc(), C->getEndLoc());
  8648. }
  8649. template <typename Derived>
  8650. OMPClause *
  8651. TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
  8652. llvm::SmallVector<Expr *, 16> Vars;
  8653. Vars.reserve(C->varlist_size());
  8654. for (auto *VE : C->varlists()) {
  8655. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8656. if (EVar.isInvalid())
  8657. return nullptr;
  8658. Vars.push_back(EVar.get());
  8659. }
  8660. return getDerived().RebuildOMPCopyprivateClause(
  8661. Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8662. }
  8663. template <typename Derived>
  8664. OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
  8665. llvm::SmallVector<Expr *, 16> Vars;
  8666. Vars.reserve(C->varlist_size());
  8667. for (auto *VE : C->varlists()) {
  8668. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8669. if (EVar.isInvalid())
  8670. return nullptr;
  8671. Vars.push_back(EVar.get());
  8672. }
  8673. return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
  8674. C->getLParenLoc(), C->getEndLoc());
  8675. }
  8676. template <typename Derived>
  8677. OMPClause *
  8678. TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
  8679. ExprResult E = getDerived().TransformExpr(C->getDepobj());
  8680. if (E.isInvalid())
  8681. return nullptr;
  8682. return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
  8683. C->getLParenLoc(), C->getEndLoc());
  8684. }
  8685. template <typename Derived>
  8686. OMPClause *
  8687. TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
  8688. llvm::SmallVector<Expr *, 16> Vars;
  8689. Expr *DepModifier = C->getModifier();
  8690. if (DepModifier) {
  8691. ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
  8692. if (DepModRes.isInvalid())
  8693. return nullptr;
  8694. DepModifier = DepModRes.get();
  8695. }
  8696. Vars.reserve(C->varlist_size());
  8697. for (auto *VE : C->varlists()) {
  8698. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8699. if (EVar.isInvalid())
  8700. return nullptr;
  8701. Vars.push_back(EVar.get());
  8702. }
  8703. return getDerived().RebuildOMPDependClause(
  8704. DepModifier, C->getDependencyKind(), C->getDependencyLoc(),
  8705. C->getColonLoc(), Vars, C->getBeginLoc(), C->getLParenLoc(),
  8706. C->getEndLoc());
  8707. }
  8708. template <typename Derived>
  8709. OMPClause *
  8710. TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
  8711. ExprResult E = getDerived().TransformExpr(C->getDevice());
  8712. if (E.isInvalid())
  8713. return nullptr;
  8714. return getDerived().RebuildOMPDeviceClause(
  8715. C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
  8716. C->getModifierLoc(), C->getEndLoc());
  8717. }
  8718. template <typename Derived, class T>
  8719. bool transformOMPMappableExprListClause(
  8720. TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C,
  8721. llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
  8722. DeclarationNameInfo &MapperIdInfo,
  8723. llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
  8724. // Transform expressions in the list.
  8725. Vars.reserve(C->varlist_size());
  8726. for (auto *VE : C->varlists()) {
  8727. ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
  8728. if (EVar.isInvalid())
  8729. return true;
  8730. Vars.push_back(EVar.get());
  8731. }
  8732. // Transform mapper scope specifier and identifier.
  8733. NestedNameSpecifierLoc QualifierLoc;
  8734. if (C->getMapperQualifierLoc()) {
  8735. QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
  8736. C->getMapperQualifierLoc());
  8737. if (!QualifierLoc)
  8738. return true;
  8739. }
  8740. MapperIdScopeSpec.Adopt(QualifierLoc);
  8741. MapperIdInfo = C->getMapperIdInfo();
  8742. if (MapperIdInfo.getName()) {
  8743. MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
  8744. if (!MapperIdInfo.getName())
  8745. return true;
  8746. }
  8747. // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
  8748. // the previous user-defined mapper lookup in dependent environment.
  8749. for (auto *E : C->mapperlists()) {
  8750. // Transform all the decls.
  8751. if (E) {
  8752. auto *ULE = cast<UnresolvedLookupExpr>(E);
  8753. UnresolvedSet<8> Decls;
  8754. for (auto *D : ULE->decls()) {
  8755. NamedDecl *InstD =
  8756. cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
  8757. Decls.addDecl(InstD, InstD->getAccess());
  8758. }
  8759. UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
  8760. TT.getSema().Context, /*NamingClass=*/nullptr,
  8761. MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
  8762. MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(),
  8763. Decls.end()));
  8764. } else {
  8765. UnresolvedMappers.push_back(nullptr);
  8766. }
  8767. }
  8768. return false;
  8769. }
  8770. template <typename Derived>
  8771. OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
  8772. OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8773. llvm::SmallVector<Expr *, 16> Vars;
  8774. CXXScopeSpec MapperIdScopeSpec;
  8775. DeclarationNameInfo MapperIdInfo;
  8776. llvm::SmallVector<Expr *, 16> UnresolvedMappers;
  8777. if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
  8778. *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
  8779. return nullptr;
  8780. return getDerived().RebuildOMPMapClause(
  8781. C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec,
  8782. MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(),
  8783. C->getColonLoc(), Vars, Locs, UnresolvedMappers);
  8784. }
  8785. template <typename Derived>
  8786. OMPClause *
  8787. TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
  8788. Expr *Allocator = C->getAllocator();
  8789. if (Allocator) {
  8790. ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
  8791. if (AllocatorRes.isInvalid())
  8792. return nullptr;
  8793. Allocator = AllocatorRes.get();
  8794. }
  8795. llvm::SmallVector<Expr *, 16> Vars;
  8796. Vars.reserve(C->varlist_size());
  8797. for (auto *VE : C->varlists()) {
  8798. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8799. if (EVar.isInvalid())
  8800. return nullptr;
  8801. Vars.push_back(EVar.get());
  8802. }
  8803. return getDerived().RebuildOMPAllocateClause(
  8804. Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
  8805. C->getEndLoc());
  8806. }
  8807. template <typename Derived>
  8808. OMPClause *
  8809. TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
  8810. ExprResult E = getDerived().TransformExpr(C->getNumTeams());
  8811. if (E.isInvalid())
  8812. return nullptr;
  8813. return getDerived().RebuildOMPNumTeamsClause(
  8814. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8815. }
  8816. template <typename Derived>
  8817. OMPClause *
  8818. TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
  8819. ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
  8820. if (E.isInvalid())
  8821. return nullptr;
  8822. return getDerived().RebuildOMPThreadLimitClause(
  8823. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8824. }
  8825. template <typename Derived>
  8826. OMPClause *
  8827. TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
  8828. ExprResult E = getDerived().TransformExpr(C->getPriority());
  8829. if (E.isInvalid())
  8830. return nullptr;
  8831. return getDerived().RebuildOMPPriorityClause(
  8832. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8833. }
  8834. template <typename Derived>
  8835. OMPClause *
  8836. TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
  8837. ExprResult E = getDerived().TransformExpr(C->getGrainsize());
  8838. if (E.isInvalid())
  8839. return nullptr;
  8840. return getDerived().RebuildOMPGrainsizeClause(
  8841. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8842. }
  8843. template <typename Derived>
  8844. OMPClause *
  8845. TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
  8846. ExprResult E = getDerived().TransformExpr(C->getNumTasks());
  8847. if (E.isInvalid())
  8848. return nullptr;
  8849. return getDerived().RebuildOMPNumTasksClause(
  8850. E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8851. }
  8852. template <typename Derived>
  8853. OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
  8854. ExprResult E = getDerived().TransformExpr(C->getHint());
  8855. if (E.isInvalid())
  8856. return nullptr;
  8857. return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
  8858. C->getLParenLoc(), C->getEndLoc());
  8859. }
  8860. template <typename Derived>
  8861. OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
  8862. OMPDistScheduleClause *C) {
  8863. ExprResult E = getDerived().TransformExpr(C->getChunkSize());
  8864. if (E.isInvalid())
  8865. return nullptr;
  8866. return getDerived().RebuildOMPDistScheduleClause(
  8867. C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
  8868. C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
  8869. }
  8870. template <typename Derived>
  8871. OMPClause *
  8872. TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
  8873. // Rebuild Defaultmap Clause since we need to invoke the checking of
  8874. // defaultmap(none:variable-category) after template initialization.
  8875. return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
  8876. C->getDefaultmapKind(),
  8877. C->getBeginLoc(),
  8878. C->getLParenLoc(),
  8879. C->getDefaultmapModifierLoc(),
  8880. C->getDefaultmapKindLoc(),
  8881. C->getEndLoc());
  8882. }
  8883. template <typename Derived>
  8884. OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
  8885. OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8886. llvm::SmallVector<Expr *, 16> Vars;
  8887. CXXScopeSpec MapperIdScopeSpec;
  8888. DeclarationNameInfo MapperIdInfo;
  8889. llvm::SmallVector<Expr *, 16> UnresolvedMappers;
  8890. if (transformOMPMappableExprListClause<Derived, OMPToClause>(
  8891. *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
  8892. return nullptr;
  8893. return getDerived().RebuildOMPToClause(
  8894. C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
  8895. MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
  8896. }
  8897. template <typename Derived>
  8898. OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
  8899. OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8900. llvm::SmallVector<Expr *, 16> Vars;
  8901. CXXScopeSpec MapperIdScopeSpec;
  8902. DeclarationNameInfo MapperIdInfo;
  8903. llvm::SmallVector<Expr *, 16> UnresolvedMappers;
  8904. if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
  8905. *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
  8906. return nullptr;
  8907. return getDerived().RebuildOMPFromClause(
  8908. C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
  8909. MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
  8910. }
  8911. template <typename Derived>
  8912. OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
  8913. OMPUseDevicePtrClause *C) {
  8914. llvm::SmallVector<Expr *, 16> Vars;
  8915. Vars.reserve(C->varlist_size());
  8916. for (auto *VE : C->varlists()) {
  8917. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8918. if (EVar.isInvalid())
  8919. return nullptr;
  8920. Vars.push_back(EVar.get());
  8921. }
  8922. OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8923. return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
  8924. }
  8925. template <typename Derived>
  8926. OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
  8927. OMPUseDeviceAddrClause *C) {
  8928. llvm::SmallVector<Expr *, 16> Vars;
  8929. Vars.reserve(C->varlist_size());
  8930. for (auto *VE : C->varlists()) {
  8931. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8932. if (EVar.isInvalid())
  8933. return nullptr;
  8934. Vars.push_back(EVar.get());
  8935. }
  8936. OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8937. return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
  8938. }
  8939. template <typename Derived>
  8940. OMPClause *
  8941. TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
  8942. llvm::SmallVector<Expr *, 16> Vars;
  8943. Vars.reserve(C->varlist_size());
  8944. for (auto *VE : C->varlists()) {
  8945. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8946. if (EVar.isInvalid())
  8947. return nullptr;
  8948. Vars.push_back(EVar.get());
  8949. }
  8950. OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8951. return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
  8952. }
  8953. template <typename Derived>
  8954. OMPClause *
  8955. TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) {
  8956. llvm::SmallVector<Expr *, 16> Vars;
  8957. Vars.reserve(C->varlist_size());
  8958. for (auto *VE : C->varlists()) {
  8959. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8960. if (EVar.isInvalid())
  8961. return nullptr;
  8962. Vars.push_back(EVar.get());
  8963. }
  8964. return getDerived().RebuildOMPNontemporalClause(
  8965. Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8966. }
  8967. template <typename Derived>
  8968. OMPClause *
  8969. TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
  8970. llvm::SmallVector<Expr *, 16> Vars;
  8971. Vars.reserve(C->varlist_size());
  8972. for (auto *VE : C->varlists()) {
  8973. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8974. if (EVar.isInvalid())
  8975. return nullptr;
  8976. Vars.push_back(EVar.get());
  8977. }
  8978. return getDerived().RebuildOMPInclusiveClause(
  8979. Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8980. }
  8981. template <typename Derived>
  8982. OMPClause *
  8983. TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
  8984. llvm::SmallVector<Expr *, 16> Vars;
  8985. Vars.reserve(C->varlist_size());
  8986. for (auto *VE : C->varlists()) {
  8987. ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
  8988. if (EVar.isInvalid())
  8989. return nullptr;
  8990. Vars.push_back(EVar.get());
  8991. }
  8992. return getDerived().RebuildOMPExclusiveClause(
  8993. Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  8994. }
  8995. template <typename Derived>
  8996. OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
  8997. OMPUsesAllocatorsClause *C) {
  8998. SmallVector<Sema::UsesAllocatorsData, 16> Data;
  8999. Data.reserve(C->getNumberOfAllocators());
  9000. for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
  9001. OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
  9002. ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
  9003. if (Allocator.isInvalid())
  9004. continue;
  9005. ExprResult AllocatorTraits;
  9006. if (Expr *AT = D.AllocatorTraits) {
  9007. AllocatorTraits = getDerived().TransformExpr(AT);
  9008. if (AllocatorTraits.isInvalid())
  9009. continue;
  9010. }
  9011. Sema::UsesAllocatorsData &NewD = Data.emplace_back();
  9012. NewD.Allocator = Allocator.get();
  9013. NewD.AllocatorTraits = AllocatorTraits.get();
  9014. NewD.LParenLoc = D.LParenLoc;
  9015. NewD.RParenLoc = D.RParenLoc;
  9016. }
  9017. return getDerived().RebuildOMPUsesAllocatorsClause(
  9018. Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
  9019. }
  9020. template <typename Derived>
  9021. OMPClause *
  9022. TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
  9023. SmallVector<Expr *, 4> Locators;
  9024. Locators.reserve(C->varlist_size());
  9025. ExprResult ModifierRes;
  9026. if (Expr *Modifier = C->getModifier()) {
  9027. ModifierRes = getDerived().TransformExpr(Modifier);
  9028. if (ModifierRes.isInvalid())
  9029. return nullptr;
  9030. }
  9031. for (Expr *E : C->varlists()) {
  9032. ExprResult Locator = getDerived().TransformExpr(E);
  9033. if (Locator.isInvalid())
  9034. continue;
  9035. Locators.push_back(Locator.get());
  9036. }
  9037. return getDerived().RebuildOMPAffinityClause(
  9038. C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
  9039. ModifierRes.get(), Locators);
  9040. }
  9041. template <typename Derived>
  9042. OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
  9043. return getDerived().RebuildOMPOrderClause(C->getKind(), C->getKindKwLoc(),
  9044. C->getBeginLoc(), C->getLParenLoc(),
  9045. C->getEndLoc());
  9046. }
  9047. template <typename Derived>
  9048. OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
  9049. return getDerived().RebuildOMPBindClause(
  9050. C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
  9051. C->getLParenLoc(), C->getEndLoc());
  9052. }
  9053. //===----------------------------------------------------------------------===//
  9054. // Expression transformation
  9055. //===----------------------------------------------------------------------===//
  9056. template<typename Derived>
  9057. ExprResult
  9058. TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
  9059. return TransformExpr(E->getSubExpr());
  9060. }
  9061. template <typename Derived>
  9062. ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
  9063. SYCLUniqueStableNameExpr *E) {
  9064. if (!E->isTypeDependent())
  9065. return E;
  9066. TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
  9067. if (!NewT)
  9068. return ExprError();
  9069. if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
  9070. return E;
  9071. return getDerived().RebuildSYCLUniqueStableNameExpr(
  9072. E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
  9073. }
  9074. template<typename Derived>
  9075. ExprResult
  9076. TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
  9077. if (!E->isTypeDependent())
  9078. return E;
  9079. return getDerived().RebuildPredefinedExpr(E->getLocation(),
  9080. E->getIdentKind());
  9081. }
  9082. template<typename Derived>
  9083. ExprResult
  9084. TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
  9085. NestedNameSpecifierLoc QualifierLoc;
  9086. if (E->getQualifierLoc()) {
  9087. QualifierLoc
  9088. = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
  9089. if (!QualifierLoc)
  9090. return ExprError();
  9091. }
  9092. ValueDecl *ND
  9093. = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
  9094. E->getDecl()));
  9095. if (!ND)
  9096. return ExprError();
  9097. NamedDecl *Found = ND;
  9098. if (E->getFoundDecl() != E->getDecl()) {
  9099. Found = cast_or_null<NamedDecl>(
  9100. getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
  9101. if (!Found)
  9102. return ExprError();
  9103. }
  9104. DeclarationNameInfo NameInfo = E->getNameInfo();
  9105. if (NameInfo.getName()) {
  9106. NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
  9107. if (!NameInfo.getName())
  9108. return ExprError();
  9109. }
  9110. if (!getDerived().AlwaysRebuild() &&
  9111. QualifierLoc == E->getQualifierLoc() &&
  9112. ND == E->getDecl() &&
  9113. Found == E->getFoundDecl() &&
  9114. NameInfo.getName() == E->getDecl()->getDeclName() &&
  9115. !E->hasExplicitTemplateArgs()) {
  9116. // Mark it referenced in the new context regardless.
  9117. // FIXME: this is a bit instantiation-specific.
  9118. SemaRef.MarkDeclRefReferenced(E);
  9119. return E;
  9120. }
  9121. TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
  9122. if (E->hasExplicitTemplateArgs()) {
  9123. TemplateArgs = &TransArgs;
  9124. TransArgs.setLAngleLoc(E->getLAngleLoc());
  9125. TransArgs.setRAngleLoc(E->getRAngleLoc());
  9126. if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
  9127. E->getNumTemplateArgs(),
  9128. TransArgs))
  9129. return ExprError();
  9130. }
  9131. return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
  9132. Found, TemplateArgs);
  9133. }
  9134. template<typename Derived>
  9135. ExprResult
  9136. TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
  9137. return E;
  9138. }
  9139. template <typename Derived>
  9140. ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
  9141. FixedPointLiteral *E) {
  9142. return E;
  9143. }
  9144. template<typename Derived>
  9145. ExprResult
  9146. TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
  9147. return E;
  9148. }
  9149. template<typename Derived>
  9150. ExprResult
  9151. TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
  9152. return E;
  9153. }
  9154. template<typename Derived>
  9155. ExprResult
  9156. TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
  9157. return E;
  9158. }
  9159. template<typename Derived>
  9160. ExprResult
  9161. TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
  9162. return E;
  9163. }
  9164. template<typename Derived>
  9165. ExprResult
  9166. TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
  9167. if (FunctionDecl *FD = E->getDirectCallee())
  9168. SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD);
  9169. return SemaRef.MaybeBindToTemporary(E);
  9170. }
  9171. template<typename Derived>
  9172. ExprResult
  9173. TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
  9174. ExprResult ControllingExpr =
  9175. getDerived().TransformExpr(E->getControllingExpr());
  9176. if (ControllingExpr.isInvalid())
  9177. return ExprError();
  9178. SmallVector<Expr *, 4> AssocExprs;
  9179. SmallVector<TypeSourceInfo *, 4> AssocTypes;
  9180. for (const GenericSelectionExpr::Association Assoc : E->associations()) {
  9181. TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
  9182. if (TSI) {
  9183. TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
  9184. if (!AssocType)
  9185. return ExprError();
  9186. AssocTypes.push_back(AssocType);
  9187. } else {
  9188. AssocTypes.push_back(nullptr);
  9189. }
  9190. ExprResult AssocExpr =
  9191. getDerived().TransformExpr(Assoc.getAssociationExpr());
  9192. if (AssocExpr.isInvalid())
  9193. return ExprError();
  9194. AssocExprs.push_back(AssocExpr.get());
  9195. }
  9196. return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
  9197. E->getDefaultLoc(),
  9198. E->getRParenLoc(),
  9199. ControllingExpr.get(),
  9200. AssocTypes,
  9201. AssocExprs);
  9202. }
  9203. template<typename Derived>
  9204. ExprResult
  9205. TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
  9206. ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
  9207. if (SubExpr.isInvalid())
  9208. return ExprError();
  9209. if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
  9210. return E;
  9211. return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
  9212. E->getRParen());
  9213. }
  9214. /// The operand of a unary address-of operator has special rules: it's
  9215. /// allowed to refer to a non-static member of a class even if there's no 'this'
  9216. /// object available.
  9217. template<typename Derived>
  9218. ExprResult
  9219. TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
  9220. if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
  9221. return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
  9222. else
  9223. return getDerived().TransformExpr(E);
  9224. }
  9225. template<typename Derived>
  9226. ExprResult
  9227. TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
  9228. ExprResult SubExpr;
  9229. if (E->getOpcode() == UO_AddrOf)
  9230. SubExpr = TransformAddressOfOperand(E->getSubExpr());
  9231. else
  9232. SubExpr = TransformExpr(E->getSubExpr());
  9233. if (SubExpr.isInvalid())
  9234. return ExprError();
  9235. if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
  9236. return E;
  9237. return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
  9238. E->getOpcode(),
  9239. SubExpr.get());
  9240. }
  9241. template<typename Derived>
  9242. ExprResult
  9243. TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
  9244. // Transform the type.
  9245. TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
  9246. if (!Type)
  9247. return ExprError();
  9248. // Transform all of the components into components similar to what the
  9249. // parser uses.
  9250. // FIXME: It would be slightly more efficient in the non-dependent case to
  9251. // just map FieldDecls, rather than requiring the rebuilder to look for
  9252. // the fields again. However, __builtin_offsetof is rare enough in
  9253. // template code that we don't care.
  9254. bool ExprChanged = false;
  9255. typedef Sema::OffsetOfComponent Component;
  9256. SmallVector<Component, 4> Components;
  9257. for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
  9258. const OffsetOfNode &ON = E->getComponent(I);
  9259. Component Comp;
  9260. Comp.isBrackets = true;
  9261. Comp.LocStart = ON.getSourceRange().getBegin();
  9262. Comp.LocEnd = ON.getSourceRange().getEnd();
  9263. switch (ON.getKind()) {
  9264. case OffsetOfNode::Array: {
  9265. Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
  9266. ExprResult Index = getDerived().TransformExpr(FromIndex);
  9267. if (Index.isInvalid())
  9268. return ExprError();
  9269. ExprChanged = ExprChanged || Index.get() != FromIndex;
  9270. Comp.isBrackets = true;
  9271. Comp.U.E = Index.get();
  9272. break;
  9273. }
  9274. case OffsetOfNode::Field:
  9275. case OffsetOfNode::Identifier:
  9276. Comp.isBrackets = false;
  9277. Comp.U.IdentInfo = ON.getFieldName();
  9278. if (!Comp.U.IdentInfo)
  9279. continue;
  9280. break;
  9281. case OffsetOfNode::Base:
  9282. // Will be recomputed during the rebuild.
  9283. continue;
  9284. }
  9285. Components.push_back(Comp);
  9286. }
  9287. // If nothing changed, retain the existing expression.
  9288. if (!getDerived().AlwaysRebuild() &&
  9289. Type == E->getTypeSourceInfo() &&
  9290. !ExprChanged)
  9291. return E;
  9292. // Build a new offsetof expression.
  9293. return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
  9294. Components, E->getRParenLoc());
  9295. }
  9296. template<typename Derived>
  9297. ExprResult
  9298. TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
  9299. assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
  9300. "opaque value expression requires transformation");
  9301. return E;
  9302. }
  9303. template<typename Derived>
  9304. ExprResult
  9305. TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
  9306. return E;
  9307. }
  9308. template <typename Derived>
  9309. ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
  9310. llvm::SmallVector<Expr *, 8> Children;
  9311. bool Changed = false;
  9312. for (Expr *C : E->subExpressions()) {
  9313. ExprResult NewC = getDerived().TransformExpr(C);
  9314. if (NewC.isInvalid())
  9315. return ExprError();
  9316. Children.push_back(NewC.get());
  9317. Changed |= NewC.get() != C;
  9318. }
  9319. if (!getDerived().AlwaysRebuild() && !Changed)
  9320. return E;
  9321. return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
  9322. Children, E->getType());
  9323. }
  9324. template<typename Derived>
  9325. ExprResult
  9326. TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
  9327. // Rebuild the syntactic form. The original syntactic form has
  9328. // opaque-value expressions in it, so strip those away and rebuild
  9329. // the result. This is a really awful way of doing this, but the
  9330. // better solution (rebuilding the semantic expressions and
  9331. // rebinding OVEs as necessary) doesn't work; we'd need
  9332. // TreeTransform to not strip away implicit conversions.
  9333. Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
  9334. ExprResult result = getDerived().TransformExpr(newSyntacticForm);
  9335. if (result.isInvalid()) return ExprError();
  9336. // If that gives us a pseudo-object result back, the pseudo-object
  9337. // expression must have been an lvalue-to-rvalue conversion which we
  9338. // should reapply.
  9339. if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
  9340. result = SemaRef.checkPseudoObjectRValue(result.get());
  9341. return result;
  9342. }
  9343. template<typename Derived>
  9344. ExprResult
  9345. TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
  9346. UnaryExprOrTypeTraitExpr *E) {
  9347. if (E->isArgumentType()) {
  9348. TypeSourceInfo *OldT = E->getArgumentTypeInfo();
  9349. TypeSourceInfo *NewT = getDerived().TransformType(OldT);
  9350. if (!NewT)
  9351. return ExprError();
  9352. if (!getDerived().AlwaysRebuild() && OldT == NewT)
  9353. return E;
  9354. return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
  9355. E->getKind(),
  9356. E->getSourceRange());
  9357. }
  9358. // C++0x [expr.sizeof]p1:
  9359. // The operand is either an expression, which is an unevaluated operand
  9360. // [...]
  9361. EnterExpressionEvaluationContext Unevaluated(
  9362. SemaRef, Sema::ExpressionEvaluationContext::Unevaluated,
  9363. Sema::ReuseLambdaContextDecl);
  9364. // Try to recover if we have something like sizeof(T::X) where X is a type.
  9365. // Notably, there must be *exactly* one set of parens if X is a type.
  9366. TypeSourceInfo *RecoveryTSI = nullptr;
  9367. ExprResult SubExpr;
  9368. auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
  9369. if (auto *DRE =
  9370. PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
  9371. SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
  9372. PE, DRE, false, &RecoveryTSI);
  9373. else
  9374. SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
  9375. if (RecoveryTSI) {
  9376. return getDerived().RebuildUnaryExprOrTypeTrait(
  9377. RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
  9378. } else if (SubExpr.isInvalid())
  9379. return ExprError();
  9380. if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
  9381. return E;
  9382. return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
  9383. E->getOperatorLoc(),
  9384. E->getKind(),
  9385. E->getSourceRange());
  9386. }
  9387. template<typename Derived>
  9388. ExprResult
  9389. TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
  9390. ExprResult LHS = getDerived().TransformExpr(E->getLHS());
  9391. if (LHS.isInvalid())
  9392. return ExprError();
  9393. ExprResult RHS = getDerived().TransformExpr(E->getRHS());
  9394. if (RHS.isInvalid())
  9395. return ExprError();
  9396. if (!getDerived().AlwaysRebuild() &&
  9397. LHS.get() == E->getLHS() &&
  9398. RHS.get() == E->getRHS())
  9399. return E;
  9400. return getDerived().RebuildArraySubscriptExpr(
  9401. LHS.get(),
  9402. /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
  9403. }
  9404. template <typename Derived>
  9405. ExprResult
  9406. TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
  9407. ExprResult Base = getDerived().TransformExpr(E->getBase());
  9408. if (Base.isInvalid())
  9409. return ExprError();
  9410. ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
  9411. if (RowIdx.isInvalid())
  9412. return ExprError();
  9413. ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
  9414. if (ColumnIdx.isInvalid())
  9415. return ExprError();
  9416. if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
  9417. RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
  9418. return E;
  9419. return getDerived().RebuildMatrixSubscriptExpr(
  9420. Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
  9421. }
  9422. template <typename Derived>
  9423. ExprResult
  9424. TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
  9425. ExprResult Base = getDerived().TransformExpr(E->getBase());
  9426. if (Base.isInvalid())
  9427. return ExprError();
  9428. ExprResult LowerBound;
  9429. if (E->getLowerBound()) {
  9430. LowerBound = getDerived().TransformExpr(E->getLowerBound());
  9431. if (LowerBound.isInvalid())
  9432. return ExprError();
  9433. }
  9434. ExprResult Length;
  9435. if (E->getLength()) {
  9436. Length = getDerived().TransformExpr(E->getLength());
  9437. if (Length.isInvalid())
  9438. return ExprError();
  9439. }
  9440. ExprResult Stride;
  9441. if (Expr *Str = E->getStride()) {
  9442. Stride = getDerived().TransformExpr(Str);
  9443. if (Stride.isInvalid())
  9444. return ExprError();
  9445. }
  9446. if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
  9447. LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
  9448. return E;
  9449. return getDerived().RebuildOMPArraySectionExpr(
  9450. Base.get(), E->getBase()->getEndLoc(), LowerBound.get(),
  9451. E->getColonLocFirst(), E->getColonLocSecond(), Length.get(), Stride.get(),
  9452. E->getRBracketLoc());
  9453. }
  9454. template <typename Derived>
  9455. ExprResult
  9456. TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
  9457. ExprResult Base = getDerived().TransformExpr(E->getBase());
  9458. if (Base.isInvalid())
  9459. return ExprError();
  9460. SmallVector<Expr *, 4> Dims;
  9461. bool ErrorFound = false;
  9462. for (Expr *Dim : E->getDimensions()) {
  9463. ExprResult DimRes = getDerived().TransformExpr(Dim);
  9464. if (DimRes.isInvalid()) {
  9465. ErrorFound = true;
  9466. continue;
  9467. }
  9468. Dims.push_back(DimRes.get());
  9469. }
  9470. if (ErrorFound)
  9471. return ExprError();
  9472. return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
  9473. E->getRParenLoc(), Dims,
  9474. E->getBracketsRanges());
  9475. }
  9476. template <typename Derived>
  9477. ExprResult
  9478. TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
  9479. unsigned NumIterators = E->numOfIterators();
  9480. SmallVector<Sema::OMPIteratorData, 4> Data(NumIterators);
  9481. bool ErrorFound = false;
  9482. bool NeedToRebuild = getDerived().AlwaysRebuild();
  9483. for (unsigned I = 0; I < NumIterators; ++I) {
  9484. auto *D = cast<VarDecl>(E->getIteratorDecl(I));
  9485. Data[I].DeclIdent = D->getIdentifier();
  9486. Data[I].DeclIdentLoc = D->getLocation();
  9487. if (D->getLocation() == D->getBeginLoc()) {
  9488. assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
  9489. "Implicit type must be int.");
  9490. } else {
  9491. TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
  9492. QualType DeclTy = getDerived().TransformType(D->getType());
  9493. Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
  9494. }
  9495. OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
  9496. ExprResult Begin = getDerived().TransformExpr(Range.Begin);
  9497. ExprResult End = getDerived().TransformExpr(Range.End);
  9498. ExprResult Step = getDerived().TransformExpr(Range.Step);
  9499. ErrorFound = ErrorFound ||
  9500. !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
  9501. !Data[I].Type.get().isNull())) ||
  9502. Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
  9503. if (ErrorFound)
  9504. continue;
  9505. Data[I].Range.Begin = Begin.get();
  9506. Data[I].Range.End = End.get();
  9507. Data[I].Range.Step = Step.get();
  9508. Data[I].AssignLoc = E->getAssignLoc(I);
  9509. Data[I].ColonLoc = E->getColonLoc(I);
  9510. Data[I].SecColonLoc = E->getSecondColonLoc(I);
  9511. NeedToRebuild =
  9512. NeedToRebuild ||
  9513. (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
  9514. D->getType().getTypePtrOrNull()) ||
  9515. Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
  9516. Range.Step != Data[I].Range.Step;
  9517. }
  9518. if (ErrorFound)
  9519. return ExprError();
  9520. if (!NeedToRebuild)
  9521. return E;
  9522. ExprResult Res = getDerived().RebuildOMPIteratorExpr(
  9523. E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
  9524. if (!Res.isUsable())
  9525. return Res;
  9526. auto *IE = cast<OMPIteratorExpr>(Res.get());
  9527. for (unsigned I = 0; I < NumIterators; ++I)
  9528. getDerived().transformedLocalDecl(E->getIteratorDecl(I),
  9529. IE->getIteratorDecl(I));
  9530. return Res;
  9531. }
  9532. template<typename Derived>
  9533. ExprResult
  9534. TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
  9535. // Transform the callee.
  9536. ExprResult Callee = getDerived().TransformExpr(E->getCallee());
  9537. if (Callee.isInvalid())
  9538. return ExprError();
  9539. // Transform arguments.
  9540. bool ArgChanged = false;
  9541. SmallVector<Expr*, 8> Args;
  9542. if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
  9543. &ArgChanged))
  9544. return ExprError();
  9545. if (!getDerived().AlwaysRebuild() &&
  9546. Callee.get() == E->getCallee() &&
  9547. !ArgChanged)
  9548. return SemaRef.MaybeBindToTemporary(E);
  9549. // FIXME: Wrong source location information for the '('.
  9550. SourceLocation FakeLParenLoc
  9551. = ((Expr *)Callee.get())->getSourceRange().getBegin();
  9552. Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
  9553. if (E->hasStoredFPFeatures()) {
  9554. FPOptionsOverride NewOverrides = E->getFPFeatures();
  9555. getSema().CurFPFeatures =
  9556. NewOverrides.applyOverrides(getSema().getLangOpts());
  9557. getSema().FpPragmaStack.CurrentValue = NewOverrides;
  9558. }
  9559. return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
  9560. Args,
  9561. E->getRParenLoc());
  9562. }
  9563. template<typename Derived>
  9564. ExprResult
  9565. TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
  9566. ExprResult Base = getDerived().TransformExpr(E->getBase());
  9567. if (Base.isInvalid())
  9568. return ExprError();
  9569. NestedNameSpecifierLoc QualifierLoc;
  9570. if (E->hasQualifier()) {
  9571. QualifierLoc
  9572. = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
  9573. if (!QualifierLoc)
  9574. return ExprError();
  9575. }
  9576. SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
  9577. ValueDecl *Member
  9578. = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
  9579. E->getMemberDecl()));
  9580. if (!Member)
  9581. return ExprError();
  9582. NamedDecl *FoundDecl = E->getFoundDecl();
  9583. if (FoundDecl == E->getMemberDecl()) {
  9584. FoundDecl = Member;
  9585. } else {
  9586. FoundDecl = cast_or_null<NamedDecl>(
  9587. getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
  9588. if (!FoundDecl)
  9589. return ExprError();
  9590. }
  9591. if (!getDerived().AlwaysRebuild() &&
  9592. Base.get() == E->getBase() &&
  9593. QualifierLoc == E->getQualifierLoc() &&
  9594. Member == E->getMemberDecl() &&
  9595. FoundDecl == E->getFoundDecl() &&
  9596. !E->hasExplicitTemplateArgs()) {
  9597. // Mark it referenced in the new context regardless.
  9598. // FIXME: this is a bit instantiation-specific.
  9599. SemaRef.MarkMemberReferenced(E);
  9600. return E;
  9601. }
  9602. TemplateArgumentListInfo TransArgs;
  9603. if (E->hasExplicitTemplateArgs()) {
  9604. TransArgs.setLAngleLoc(E->getLAngleLoc());
  9605. TransArgs.setRAngleLoc(E->getRAngleLoc());
  9606. if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
  9607. E->getNumTemplateArgs(),
  9608. TransArgs))
  9609. return ExprError();
  9610. }
  9611. // FIXME: Bogus source location for the operator
  9612. SourceLocation FakeOperatorLoc =
  9613. SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
  9614. // FIXME: to do this check properly, we will need to preserve the
  9615. // first-qualifier-in-scope here, just in case we had a dependent
  9616. // base (and therefore couldn't do the check) and a
  9617. // nested-name-qualifier (and therefore could do the lookup).
  9618. NamedDecl *FirstQualifierInScope = nullptr;
  9619. DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
  9620. if (MemberNameInfo.getName()) {
  9621. MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
  9622. if (!MemberNameInfo.getName())
  9623. return ExprError();
  9624. }
  9625. return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
  9626. E->isArrow(),
  9627. QualifierLoc,
  9628. TemplateKWLoc,
  9629. MemberNameInfo,
  9630. Member,
  9631. FoundDecl,
  9632. (E->hasExplicitTemplateArgs()
  9633. ? &TransArgs : nullptr),
  9634. FirstQualifierInScope);
  9635. }
  9636. template<typename Derived>
  9637. ExprResult
  9638. TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
  9639. ExprResult LHS = getDerived().TransformExpr(E->getLHS());
  9640. if (LHS.isInvalid())
  9641. return ExprError();
  9642. ExprResult RHS = getDerived().TransformExpr(E->getRHS());
  9643. if (RHS.isInvalid())
  9644. return ExprError();
  9645. if (!getDerived().AlwaysRebuild() &&
  9646. LHS.get() == E->getLHS() &&
  9647. RHS.get() == E->getRHS())
  9648. return E;
  9649. if (E->isCompoundAssignmentOp())
  9650. // FPFeatures has already been established from trailing storage
  9651. return getDerived().RebuildBinaryOperator(
  9652. E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
  9653. Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
  9654. FPOptionsOverride NewOverrides(E->getFPFeatures(getSema().getLangOpts()));
  9655. getSema().CurFPFeatures =
  9656. NewOverrides.applyOverrides(getSema().getLangOpts());
  9657. getSema().FpPragmaStack.CurrentValue = NewOverrides;
  9658. return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
  9659. LHS.get(), RHS.get());
  9660. }
  9661. template <typename Derived>
  9662. ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
  9663. CXXRewrittenBinaryOperator *E) {
  9664. CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
  9665. ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
  9666. if (LHS.isInvalid())
  9667. return ExprError();
  9668. ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
  9669. if (RHS.isInvalid())
  9670. return ExprError();
  9671. // Extract the already-resolved callee declarations so that we can restrict
  9672. // ourselves to using them as the unqualified lookup results when rebuilding.
  9673. UnresolvedSet<2> UnqualLookups;
  9674. bool ChangedAnyLookups = false;
  9675. Expr *PossibleBinOps[] = {E->getSemanticForm(),
  9676. const_cast<Expr *>(Decomp.InnerBinOp)};
  9677. for (Expr *PossibleBinOp : PossibleBinOps) {
  9678. auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
  9679. if (!Op)
  9680. continue;
  9681. auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
  9682. if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
  9683. continue;
  9684. // Transform the callee in case we built a call to a local extern
  9685. // declaration.
  9686. NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
  9687. E->getOperatorLoc(), Callee->getFoundDecl()));
  9688. if (!Found)
  9689. return ExprError();
  9690. if (Found != Callee->getFoundDecl())
  9691. ChangedAnyLookups = true;
  9692. UnqualLookups.addDecl(Found);
  9693. }
  9694. if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
  9695. LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
  9696. // Mark all functions used in the rewrite as referenced. Note that when
  9697. // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
  9698. // function calls, and/or there might be a user-defined conversion sequence
  9699. // applied to the operands of the <.
  9700. // FIXME: this is a bit instantiation-specific.
  9701. const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
  9702. SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
  9703. return E;
  9704. }
  9705. return getDerived().RebuildCXXRewrittenBinaryOperator(
  9706. E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
  9707. }
  9708. template<typename Derived>
  9709. ExprResult
  9710. TreeTransform<Derived>::TransformCompoundAssignOperator(
  9711. CompoundAssignOperator *E) {
  9712. Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
  9713. FPOptionsOverride NewOverrides(E->getFPFeatures(getSema().getLangOpts()));
  9714. getSema().CurFPFeatures =
  9715. NewOverrides.applyOverrides(getSema().getLangOpts());
  9716. getSema().FpPragmaStack.CurrentValue = NewOverrides;
  9717. return getDerived().TransformBinaryOperator(E);
  9718. }
  9719. template<typename Derived>
  9720. ExprResult TreeTransform<Derived>::
  9721. TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
  9722. // Just rebuild the common and RHS expressions and see whether we
  9723. // get any changes.
  9724. ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
  9725. if (commonExpr.isInvalid())
  9726. return ExprError();
  9727. ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
  9728. if (rhs.isInvalid())
  9729. return ExprError();
  9730. if (!getDerived().AlwaysRebuild() &&
  9731. commonExpr.get() == e->getCommon() &&
  9732. rhs.get() == e->getFalseExpr())
  9733. return e;
  9734. return getDerived().RebuildConditionalOperator(commonExpr.get(),
  9735. e->getQuestionLoc(),
  9736. nullptr,
  9737. e->getColonLoc(),
  9738. rhs.get());
  9739. }
  9740. template<typename Derived>
  9741. ExprResult
  9742. TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
  9743. ExprResult Cond = getDerived().TransformExpr(E->getCond());
  9744. if (Cond.isInvalid())
  9745. return ExprError();
  9746. ExprResult LHS = getDerived().TransformExpr(E->getLHS());
  9747. if (LHS.isInvalid())
  9748. return ExprError();
  9749. ExprResult RHS = getDerived().TransformExpr(E->getRHS());
  9750. if (RHS.isInvalid())
  9751. return ExprError();
  9752. if (!getDerived().AlwaysRebuild() &&
  9753. Cond.get() == E->getCond() &&
  9754. LHS.get() == E->getLHS() &&
  9755. RHS.get() == E->getRHS())
  9756. return E;
  9757. return getDerived().RebuildConditionalOperator(Cond.get(),
  9758. E->getQuestionLoc(),
  9759. LHS.get(),
  9760. E->getColonLoc(),
  9761. RHS.get());
  9762. }
  9763. template<typename Derived>
  9764. ExprResult
  9765. TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
  9766. // Implicit casts are eliminated during transformation, since they
  9767. // will be recomputed by semantic analysis after transformation.
  9768. return getDerived().TransformExpr(E->getSubExprAsWritten());
  9769. }
  9770. template<typename Derived>
  9771. ExprResult
  9772. TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
  9773. TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
  9774. if (!Type)
  9775. return ExprError();
  9776. ExprResult SubExpr
  9777. = getDerived().TransformExpr(E->getSubExprAsWritten());
  9778. if (SubExpr.isInvalid())
  9779. return ExprError();
  9780. if (!getDerived().AlwaysRebuild() &&
  9781. Type == E->getTypeInfoAsWritten() &&
  9782. SubExpr.get() == E->getSubExpr())
  9783. return E;
  9784. return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
  9785. Type,
  9786. E->getRParenLoc(),
  9787. SubExpr.get());
  9788. }
  9789. template<typename Derived>
  9790. ExprResult
  9791. TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
  9792. TypeSourceInfo *OldT = E->getTypeSourceInfo();
  9793. TypeSourceInfo *NewT = getDerived().TransformType(OldT);
  9794. if (!NewT)
  9795. return ExprError();
  9796. ExprResult Init = getDerived().TransformExpr(E->getInitializer());
  9797. if (Init.isInvalid())
  9798. return ExprError();
  9799. if (!getDerived().AlwaysRebuild() &&
  9800. OldT == NewT &&
  9801. Init.get() == E->getInitializer())
  9802. return SemaRef.MaybeBindToTemporary(E);
  9803. // Note: the expression type doesn't necessarily match the
  9804. // type-as-written, but that's okay, because it should always be
  9805. // derivable from the initializer.
  9806. return getDerived().RebuildCompoundLiteralExpr(
  9807. E->getLParenLoc(), NewT,
  9808. /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
  9809. }
  9810. template<typename Derived>
  9811. ExprResult
  9812. TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
  9813. ExprResult Base = getDerived().TransformExpr(E->getBase());
  9814. if (Base.isInvalid())
  9815. return ExprError();
  9816. if (!getDerived().AlwaysRebuild() &&
  9817. Base.get() == E->getBase())
  9818. return E;
  9819. // FIXME: Bad source location
  9820. SourceLocation FakeOperatorLoc =
  9821. SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
  9822. return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
  9823. E->getAccessorLoc(),
  9824. E->getAccessor());
  9825. }
  9826. template<typename Derived>
  9827. ExprResult
  9828. TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
  9829. if (InitListExpr *Syntactic = E->getSyntacticForm())
  9830. E = Syntactic;
  9831. bool InitChanged = false;
  9832. EnterExpressionEvaluationContext Context(
  9833. getSema(), EnterExpressionEvaluationContext::InitList);
  9834. SmallVector<Expr*, 4> Inits;
  9835. if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
  9836. Inits, &InitChanged))
  9837. return ExprError();
  9838. if (!getDerived().AlwaysRebuild() && !InitChanged) {
  9839. // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
  9840. // in some cases. We can't reuse it in general, because the syntactic and
  9841. // semantic forms are linked, and we can't know that semantic form will
  9842. // match even if the syntactic form does.
  9843. }
  9844. return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
  9845. E->getRBraceLoc());
  9846. }
  9847. template<typename Derived>
  9848. ExprResult
  9849. TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
  9850. Designation Desig;
  9851. // transform the initializer value
  9852. ExprResult Init = getDerived().TransformExpr(E->getInit());
  9853. if (Init.isInvalid())
  9854. return ExprError();
  9855. // transform the designators.
  9856. SmallVector<Expr*, 4> ArrayExprs;
  9857. bool ExprChanged = false;
  9858. for (const DesignatedInitExpr::Designator &D : E->designators()) {
  9859. if (D.isFieldDesignator()) {
  9860. Desig.AddDesignator(Designator::getField(D.getFieldName(),
  9861. D.getDotLoc(),
  9862. D.getFieldLoc()));
  9863. if (D.getField()) {
  9864. FieldDecl *Field = cast_or_null<FieldDecl>(
  9865. getDerived().TransformDecl(D.getFieldLoc(), D.getField()));
  9866. if (Field != D.getField())
  9867. // Rebuild the expression when the transformed FieldDecl is
  9868. // different to the already assigned FieldDecl.
  9869. ExprChanged = true;
  9870. } else {
  9871. // Ensure that the designator expression is rebuilt when there isn't
  9872. // a resolved FieldDecl in the designator as we don't want to assign
  9873. // a FieldDecl to a pattern designator that will be instantiated again.
  9874. ExprChanged = true;
  9875. }
  9876. continue;
  9877. }
  9878. if (D.isArrayDesignator()) {
  9879. ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
  9880. if (Index.isInvalid())
  9881. return ExprError();
  9882. Desig.AddDesignator(
  9883. Designator::getArray(Index.get(), D.getLBracketLoc()));
  9884. ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
  9885. ArrayExprs.push_back(Index.get());
  9886. continue;
  9887. }
  9888. assert(D.isArrayRangeDesignator() && "New kind of designator?");
  9889. ExprResult Start
  9890. = getDerived().TransformExpr(E->getArrayRangeStart(D));
  9891. if (Start.isInvalid())
  9892. return ExprError();
  9893. ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
  9894. if (End.isInvalid())
  9895. return ExprError();
  9896. Desig.AddDesignator(Designator::getArrayRange(Start.get(),
  9897. End.get(),
  9898. D.getLBracketLoc(),
  9899. D.getEllipsisLoc()));
  9900. ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
  9901. End.get() != E->getArrayRangeEnd(D);
  9902. ArrayExprs.push_back(Start.get());
  9903. ArrayExprs.push_back(End.get());
  9904. }
  9905. if (!getDerived().AlwaysRebuild() &&
  9906. Init.get() == E->getInit() &&
  9907. !ExprChanged)
  9908. return E;
  9909. return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
  9910. E->getEqualOrColonLoc(),
  9911. E->usesGNUSyntax(), Init.get());
  9912. }
  9913. // Seems that if TransformInitListExpr() only works on the syntactic form of an
  9914. // InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
  9915. template<typename Derived>
  9916. ExprResult
  9917. TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
  9918. DesignatedInitUpdateExpr *E) {
  9919. llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
  9920. "initializer");
  9921. return ExprError();
  9922. }
  9923. template<typename Derived>
  9924. ExprResult
  9925. TreeTransform<Derived>::TransformNoInitExpr(
  9926. NoInitExpr *E) {
  9927. llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
  9928. return ExprError();
  9929. }
  9930. template<typename Derived>
  9931. ExprResult
  9932. TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
  9933. llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
  9934. return ExprError();
  9935. }
  9936. template<typename Derived>
  9937. ExprResult
  9938. TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
  9939. llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
  9940. return ExprError();
  9941. }
  9942. template<typename Derived>
  9943. ExprResult
  9944. TreeTransform<Derived>::TransformImplicitValueInitExpr(
  9945. ImplicitValueInitExpr *E) {
  9946. TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
  9947. // FIXME: Will we ever have proper type location here? Will we actually
  9948. // need to transform the type?
  9949. QualType T = getDerived().TransformType(E->getType());
  9950. if (T.isNull())
  9951. return ExprError();
  9952. if (!getDerived().AlwaysRebuild() &&
  9953. T == E->getType())
  9954. return E;
  9955. return getDerived().RebuildImplicitValueInitExpr(T);
  9956. }
  9957. template<typename Derived>
  9958. ExprResult
  9959. TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
  9960. TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
  9961. if (!TInfo)
  9962. return ExprError();
  9963. ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
  9964. if (SubExpr.isInvalid())
  9965. return ExprError();
  9966. if (!getDerived().AlwaysRebuild() &&
  9967. TInfo == E->getWrittenTypeInfo() &&
  9968. SubExpr.get() == E->getSubExpr())
  9969. return E;
  9970. return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
  9971. TInfo, E->getRParenLoc());
  9972. }
  9973. template<typename Derived>
  9974. ExprResult
  9975. TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
  9976. bool ArgumentChanged = false;
  9977. SmallVector<Expr*, 4> Inits;
  9978. if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
  9979. &ArgumentChanged))
  9980. return ExprError();
  9981. return getDerived().RebuildParenListExpr(E->getLParenLoc(),
  9982. Inits,
  9983. E->getRParenLoc());
  9984. }
  9985. /// Transform an address-of-label expression.
  9986. ///
  9987. /// By default, the transformation of an address-of-label expression always
  9988. /// rebuilds the expression, so that the label identifier can be resolved to
  9989. /// the corresponding label statement by semantic analysis.
  9990. template<typename Derived>
  9991. ExprResult
  9992. TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
  9993. Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
  9994. E->getLabel());
  9995. if (!LD)
  9996. return ExprError();
  9997. return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
  9998. cast<LabelDecl>(LD));
  9999. }
  10000. template<typename Derived>
  10001. ExprResult
  10002. TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
  10003. SemaRef.ActOnStartStmtExpr();
  10004. StmtResult SubStmt
  10005. = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
  10006. if (SubStmt.isInvalid()) {
  10007. SemaRef.ActOnStmtExprError();
  10008. return ExprError();
  10009. }
  10010. unsigned OldDepth = E->getTemplateDepth();
  10011. unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
  10012. if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
  10013. SubStmt.get() == E->getSubStmt()) {
  10014. // Calling this an 'error' is unintuitive, but it does the right thing.
  10015. SemaRef.ActOnStmtExprError();
  10016. return SemaRef.MaybeBindToTemporary(E);
  10017. }
  10018. return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
  10019. E->getRParenLoc(), NewDepth);
  10020. }
  10021. template<typename Derived>
  10022. ExprResult
  10023. TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
  10024. ExprResult Cond = getDerived().TransformExpr(E->getCond());
  10025. if (Cond.isInvalid())
  10026. return ExprError();
  10027. ExprResult LHS = getDerived().TransformExpr(E->getLHS());
  10028. if (LHS.isInvalid())
  10029. return ExprError();
  10030. ExprResult RHS = getDerived().TransformExpr(E->getRHS());
  10031. if (RHS.isInvalid())
  10032. return ExprError();
  10033. if (!getDerived().AlwaysRebuild() &&
  10034. Cond.get() == E->getCond() &&
  10035. LHS.get() == E->getLHS() &&
  10036. RHS.get() == E->getRHS())
  10037. return E;
  10038. return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
  10039. Cond.get(), LHS.get(), RHS.get(),
  10040. E->getRParenLoc());
  10041. }
  10042. template<typename Derived>
  10043. ExprResult
  10044. TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
  10045. return E;
  10046. }
  10047. template<typename Derived>
  10048. ExprResult
  10049. TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
  10050. switch (E->getOperator()) {
  10051. case OO_New:
  10052. case OO_Delete:
  10053. case OO_Array_New:
  10054. case OO_Array_Delete:
  10055. llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
  10056. case OO_Call: {
  10057. // This is a call to an object's operator().
  10058. assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
  10059. // Transform the object itself.
  10060. ExprResult Object = getDerived().TransformExpr(E->getArg(0));
  10061. if (Object.isInvalid())
  10062. return ExprError();
  10063. // FIXME: Poor location information
  10064. SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
  10065. static_cast<Expr *>(Object.get())->getEndLoc());
  10066. // Transform the call arguments.
  10067. SmallVector<Expr*, 8> Args;
  10068. if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
  10069. Args))
  10070. return ExprError();
  10071. return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
  10072. E->getEndLoc());
  10073. }
  10074. #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
  10075. case OO_##Name:
  10076. #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
  10077. #include "clang/Basic/OperatorKinds.def"
  10078. case OO_Subscript:
  10079. // Handled below.
  10080. break;
  10081. case OO_Conditional:
  10082. llvm_unreachable("conditional operator is not actually overloadable");
  10083. case OO_None:
  10084. case NUM_OVERLOADED_OPERATORS:
  10085. llvm_unreachable("not an overloaded operator?");
  10086. }
  10087. ExprResult Callee = getDerived().TransformExpr(E->getCallee());
  10088. if (Callee.isInvalid())
  10089. return ExprError();
  10090. ExprResult First;
  10091. if (E->getOperator() == OO_Amp)
  10092. First = getDerived().TransformAddressOfOperand(E->getArg(0));
  10093. else
  10094. First = getDerived().TransformExpr(E->getArg(0));
  10095. if (First.isInvalid())
  10096. return ExprError();
  10097. ExprResult Second;
  10098. if (E->getNumArgs() == 2) {
  10099. Second = getDerived().TransformExpr(E->getArg(1));
  10100. if (Second.isInvalid())
  10101. return ExprError();
  10102. }
  10103. if (!getDerived().AlwaysRebuild() &&
  10104. Callee.get() == E->getCallee() &&
  10105. First.get() == E->getArg(0) &&
  10106. (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
  10107. return SemaRef.MaybeBindToTemporary(E);
  10108. Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
  10109. FPOptionsOverride NewOverrides(E->getFPFeatures());
  10110. getSema().CurFPFeatures =
  10111. NewOverrides.applyOverrides(getSema().getLangOpts());
  10112. getSema().FpPragmaStack.CurrentValue = NewOverrides;
  10113. return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
  10114. E->getOperatorLoc(),
  10115. Callee.get(),
  10116. First.get(),
  10117. Second.get());
  10118. }
  10119. template<typename Derived>
  10120. ExprResult
  10121. TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
  10122. return getDerived().TransformCallExpr(E);
  10123. }
  10124. template <typename Derived>
  10125. ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
  10126. bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function &&
  10127. getSema().CurContext != E->getParentContext();
  10128. if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
  10129. return E;
  10130. return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(),
  10131. E->getEndLoc(),
  10132. getSema().CurContext);
  10133. }
  10134. template<typename Derived>
  10135. ExprResult
  10136. TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
  10137. // Transform the callee.
  10138. ExprResult Callee = getDerived().TransformExpr(E->getCallee());
  10139. if (Callee.isInvalid())
  10140. return ExprError();
  10141. // Transform exec config.
  10142. ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
  10143. if (EC.isInvalid())
  10144. return ExprError();
  10145. // Transform arguments.
  10146. bool ArgChanged = false;
  10147. SmallVector<Expr*, 8> Args;
  10148. if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
  10149. &ArgChanged))
  10150. return ExprError();
  10151. if (!getDerived().AlwaysRebuild() &&
  10152. Callee.get() == E->getCallee() &&
  10153. !ArgChanged)
  10154. return SemaRef.MaybeBindToTemporary(E);
  10155. // FIXME: Wrong source location information for the '('.
  10156. SourceLocation FakeLParenLoc
  10157. = ((Expr *)Callee.get())->getSourceRange().getBegin();
  10158. return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
  10159. Args,
  10160. E->getRParenLoc(), EC.get());
  10161. }
  10162. template<typename Derived>
  10163. ExprResult
  10164. TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
  10165. TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
  10166. if (!Type)
  10167. return ExprError();
  10168. ExprResult SubExpr
  10169. = getDerived().TransformExpr(E->getSubExprAsWritten());
  10170. if (SubExpr.isInvalid())
  10171. return ExprError();
  10172. if (!getDerived().AlwaysRebuild() &&
  10173. Type == E->getTypeInfoAsWritten() &&
  10174. SubExpr.get() == E->getSubExpr())
  10175. return E;
  10176. return getDerived().RebuildCXXNamedCastExpr(
  10177. E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
  10178. Type, E->getAngleBrackets().getEnd(),
  10179. // FIXME. this should be '(' location
  10180. E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
  10181. }
  10182. template<typename Derived>
  10183. ExprResult
  10184. TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) {
  10185. TypeSourceInfo *TSI =
  10186. getDerived().TransformType(BCE->getTypeInfoAsWritten());
  10187. if (!TSI)
  10188. return ExprError();
  10189. ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
  10190. if (Sub.isInvalid())
  10191. return ExprError();
  10192. return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
  10193. Sub.get(), BCE->getEndLoc());
  10194. }
  10195. template<typename Derived>
  10196. ExprResult
  10197. TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
  10198. return getDerived().TransformCXXNamedCastExpr(E);
  10199. }
  10200. template<typename Derived>
  10201. ExprResult
  10202. TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
  10203. return getDerived().TransformCXXNamedCastExpr(E);
  10204. }
  10205. template<typename Derived>
  10206. ExprResult
  10207. TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
  10208. CXXReinterpretCastExpr *E) {
  10209. return getDerived().TransformCXXNamedCastExpr(E);
  10210. }
  10211. template<typename Derived>
  10212. ExprResult
  10213. TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
  10214. return getDerived().TransformCXXNamedCastExpr(E);
  10215. }
  10216. template<typename Derived>
  10217. ExprResult
  10218. TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
  10219. return getDerived().TransformCXXNamedCastExpr(E);
  10220. }
  10221. template<typename Derived>
  10222. ExprResult
  10223. TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
  10224. CXXFunctionalCastExpr *E) {
  10225. TypeSourceInfo *Type =
  10226. getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
  10227. if (!Type)
  10228. return ExprError();
  10229. ExprResult SubExpr
  10230. = getDerived().TransformExpr(E->getSubExprAsWritten());
  10231. if (SubExpr.isInvalid())
  10232. return ExprError();
  10233. if (!getDerived().AlwaysRebuild() &&
  10234. Type == E->getTypeInfoAsWritten() &&
  10235. SubExpr.get() == E->getSubExpr())
  10236. return E;
  10237. return getDerived().RebuildCXXFunctionalCastExpr(Type,
  10238. E->getLParenLoc(),
  10239. SubExpr.get(),
  10240. E->getRParenLoc(),
  10241. E->isListInitialization());
  10242. }
  10243. template<typename Derived>
  10244. ExprResult
  10245. TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
  10246. if (E->isTypeOperand()) {
  10247. TypeSourceInfo *TInfo
  10248. = getDerived().TransformType(E->getTypeOperandSourceInfo());
  10249. if (!TInfo)
  10250. return ExprError();
  10251. if (!getDerived().AlwaysRebuild() &&
  10252. TInfo == E->getTypeOperandSourceInfo())
  10253. return E;
  10254. return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
  10255. TInfo, E->getEndLoc());
  10256. }
  10257. // Typeid's operand is an unevaluated context, unless it's a polymorphic
  10258. // type. We must not unilaterally enter unevaluated context here, as then
  10259. // semantic processing can re-transform an already transformed operand.
  10260. Expr *Op = E->getExprOperand();
  10261. auto EvalCtx = Sema::ExpressionEvaluationContext::Unevaluated;
  10262. if (E->isGLValue())
  10263. if (auto *RecordT = Op->getType()->getAs<RecordType>())
  10264. if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic())
  10265. EvalCtx = SemaRef.ExprEvalContexts.back().Context;
  10266. EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
  10267. Sema::ReuseLambdaContextDecl);
  10268. ExprResult SubExpr = getDerived().TransformExpr(Op);
  10269. if (SubExpr.isInvalid())
  10270. return ExprError();
  10271. if (!getDerived().AlwaysRebuild() &&
  10272. SubExpr.get() == E->getExprOperand())
  10273. return E;
  10274. return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
  10275. SubExpr.get(), E->getEndLoc());
  10276. }
  10277. template<typename Derived>
  10278. ExprResult
  10279. TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
  10280. if (E->isTypeOperand()) {
  10281. TypeSourceInfo *TInfo
  10282. = getDerived().TransformType(E->getTypeOperandSourceInfo());
  10283. if (!TInfo)
  10284. return ExprError();
  10285. if (!getDerived().AlwaysRebuild() &&
  10286. TInfo == E->getTypeOperandSourceInfo())
  10287. return E;
  10288. return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
  10289. TInfo, E->getEndLoc());
  10290. }
  10291. EnterExpressionEvaluationContext Unevaluated(
  10292. SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
  10293. ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
  10294. if (SubExpr.isInvalid())
  10295. return ExprError();
  10296. if (!getDerived().AlwaysRebuild() &&
  10297. SubExpr.get() == E->getExprOperand())
  10298. return E;
  10299. return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
  10300. SubExpr.get(), E->getEndLoc());
  10301. }
  10302. template<typename Derived>
  10303. ExprResult
  10304. TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
  10305. return E;
  10306. }
  10307. template<typename Derived>
  10308. ExprResult
  10309. TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
  10310. CXXNullPtrLiteralExpr *E) {
  10311. return E;
  10312. }
  10313. template<typename Derived>
  10314. ExprResult
  10315. TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
  10316. QualType T = getSema().getCurrentThisType();
  10317. if (!getDerived().AlwaysRebuild() && T == E->getType()) {
  10318. // Mark it referenced in the new context regardless.
  10319. // FIXME: this is a bit instantiation-specific.
  10320. getSema().MarkThisReferenced(E);
  10321. return E;
  10322. }
  10323. return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
  10324. }
  10325. template<typename Derived>
  10326. ExprResult
  10327. TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
  10328. ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
  10329. if (SubExpr.isInvalid())
  10330. return ExprError();
  10331. if (!getDerived().AlwaysRebuild() &&
  10332. SubExpr.get() == E->getSubExpr())
  10333. return E;
  10334. return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
  10335. E->isThrownVariableInScope());
  10336. }
  10337. template<typename Derived>
  10338. ExprResult
  10339. TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
  10340. ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
  10341. getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
  10342. if (!Param)
  10343. return ExprError();
  10344. if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
  10345. E->getUsedContext() == SemaRef.CurContext)
  10346. return E;
  10347. return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
  10348. }
  10349. template<typename Derived>
  10350. ExprResult
  10351. TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
  10352. FieldDecl *Field = cast_or_null<FieldDecl>(
  10353. getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
  10354. if (!Field)
  10355. return ExprError();
  10356. if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
  10357. E->getUsedContext() == SemaRef.CurContext)
  10358. return E;
  10359. return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
  10360. }
  10361. template<typename Derived>
  10362. ExprResult
  10363. TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
  10364. CXXScalarValueInitExpr *E) {
  10365. TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
  10366. if (!T)
  10367. return ExprError();
  10368. if (!getDerived().AlwaysRebuild() &&
  10369. T == E->getTypeSourceInfo())
  10370. return E;
  10371. return getDerived().RebuildCXXScalarValueInitExpr(T,
  10372. /*FIXME:*/T->getTypeLoc().getEndLoc(),
  10373. E->getRParenLoc());
  10374. }
  10375. template<typename Derived>
  10376. ExprResult
  10377. TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
  10378. // Transform the type that we're allocating
  10379. TypeSourceInfo *AllocTypeInfo =
  10380. getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
  10381. if (!AllocTypeInfo)
  10382. return ExprError();
  10383. // Transform the size of the array we're allocating (if any).
  10384. Optional<Expr *> ArraySize;
  10385. if (Optional<Expr *> OldArraySize = E->getArraySize()) {
  10386. ExprResult NewArraySize;
  10387. if (*OldArraySize) {
  10388. NewArraySize = getDerived().TransformExpr(*OldArraySize);
  10389. if (NewArraySize.isInvalid())
  10390. return ExprError();
  10391. }
  10392. ArraySize = NewArraySize.get();
  10393. }
  10394. // Transform the placement arguments (if any).
  10395. bool ArgumentChanged = false;
  10396. SmallVector<Expr*, 8> PlacementArgs;
  10397. if (getDerived().TransformExprs(E->getPlacementArgs(),
  10398. E->getNumPlacementArgs(), true,
  10399. PlacementArgs, &ArgumentChanged))
  10400. return ExprError();
  10401. // Transform the initializer (if any).
  10402. Expr *OldInit = E->getInitializer();
  10403. ExprResult NewInit;
  10404. if (OldInit)
  10405. NewInit = getDerived().TransformInitializer(OldInit, true);
  10406. if (NewInit.isInvalid())
  10407. return ExprError();
  10408. // Transform new operator and delete operator.
  10409. FunctionDecl *OperatorNew = nullptr;
  10410. if (E->getOperatorNew()) {
  10411. OperatorNew = cast_or_null<FunctionDecl>(
  10412. getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
  10413. if (!OperatorNew)
  10414. return ExprError();
  10415. }
  10416. FunctionDecl *OperatorDelete = nullptr;
  10417. if (E->getOperatorDelete()) {
  10418. OperatorDelete = cast_or_null<FunctionDecl>(
  10419. getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
  10420. if (!OperatorDelete)
  10421. return ExprError();
  10422. }
  10423. if (!getDerived().AlwaysRebuild() &&
  10424. AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
  10425. ArraySize == E->getArraySize() &&
  10426. NewInit.get() == OldInit &&
  10427. OperatorNew == E->getOperatorNew() &&
  10428. OperatorDelete == E->getOperatorDelete() &&
  10429. !ArgumentChanged) {
  10430. // Mark any declarations we need as referenced.
  10431. // FIXME: instantiation-specific.
  10432. if (OperatorNew)
  10433. SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
  10434. if (OperatorDelete)
  10435. SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
  10436. if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
  10437. QualType ElementType
  10438. = SemaRef.Context.getBaseElementType(E->getAllocatedType());
  10439. if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
  10440. CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
  10441. if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
  10442. SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
  10443. }
  10444. }
  10445. }
  10446. return E;
  10447. }
  10448. QualType AllocType = AllocTypeInfo->getType();
  10449. if (!ArraySize) {
  10450. // If no array size was specified, but the new expression was
  10451. // instantiated with an array type (e.g., "new T" where T is
  10452. // instantiated with "int[4]"), extract the outer bound from the
  10453. // array type as our array size. We do this with constant and
  10454. // dependently-sized array types.
  10455. const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
  10456. if (!ArrayT) {
  10457. // Do nothing
  10458. } else if (const ConstantArrayType *ConsArrayT
  10459. = dyn_cast<ConstantArrayType>(ArrayT)) {
  10460. ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
  10461. SemaRef.Context.getSizeType(),
  10462. /*FIXME:*/ E->getBeginLoc());
  10463. AllocType = ConsArrayT->getElementType();
  10464. } else if (const DependentSizedArrayType *DepArrayT
  10465. = dyn_cast<DependentSizedArrayType>(ArrayT)) {
  10466. if (DepArrayT->getSizeExpr()) {
  10467. ArraySize = DepArrayT->getSizeExpr();
  10468. AllocType = DepArrayT->getElementType();
  10469. }
  10470. }
  10471. }
  10472. return getDerived().RebuildCXXNewExpr(
  10473. E->getBeginLoc(), E->isGlobalNew(),
  10474. /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
  10475. /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
  10476. AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
  10477. }
  10478. template<typename Derived>
  10479. ExprResult
  10480. TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
  10481. ExprResult Operand = getDerived().TransformExpr(E->getArgument());
  10482. if (Operand.isInvalid())
  10483. return ExprError();
  10484. // Transform the delete operator, if known.
  10485. FunctionDecl *OperatorDelete = nullptr;
  10486. if (E->getOperatorDelete()) {
  10487. OperatorDelete = cast_or_null<FunctionDecl>(
  10488. getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
  10489. if (!OperatorDelete)
  10490. return ExprError();
  10491. }
  10492. if (!getDerived().AlwaysRebuild() &&
  10493. Operand.get() == E->getArgument() &&
  10494. OperatorDelete == E->getOperatorDelete()) {
  10495. // Mark any declarations we need as referenced.
  10496. // FIXME: instantiation-specific.
  10497. if (OperatorDelete)
  10498. SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
  10499. if (!E->getArgument()->isTypeDependent()) {
  10500. QualType Destroyed = SemaRef.Context.getBaseElementType(
  10501. E->getDestroyedType());
  10502. if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
  10503. CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
  10504. SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
  10505. SemaRef.LookupDestructor(Record));
  10506. }
  10507. }
  10508. return E;
  10509. }
  10510. return getDerived().RebuildCXXDeleteExpr(
  10511. E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
  10512. }
  10513. template<typename Derived>
  10514. ExprResult
  10515. TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
  10516. CXXPseudoDestructorExpr *E) {
  10517. ExprResult Base = getDerived().TransformExpr(E->getBase());
  10518. if (Base.isInvalid())
  10519. return ExprError();
  10520. ParsedType ObjectTypePtr;
  10521. bool MayBePseudoDestructor = false;
  10522. Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
  10523. E->getOperatorLoc(),
  10524. E->isArrow()? tok::arrow : tok::period,
  10525. ObjectTypePtr,
  10526. MayBePseudoDestructor);
  10527. if (Base.isInvalid())
  10528. return ExprError();
  10529. QualType ObjectType = ObjectTypePtr.get();
  10530. NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
  10531. if (QualifierLoc) {
  10532. QualifierLoc
  10533. = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
  10534. if (!QualifierLoc)
  10535. return ExprError();
  10536. }
  10537. CXXScopeSpec SS;
  10538. SS.Adopt(QualifierLoc);
  10539. PseudoDestructorTypeStorage Destroyed;
  10540. if (E->getDestroyedTypeInfo()) {
  10541. TypeSourceInfo *DestroyedTypeInfo
  10542. = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
  10543. ObjectType, nullptr, SS);
  10544. if (!DestroyedTypeInfo)
  10545. return ExprError();
  10546. Destroyed = DestroyedTypeInfo;
  10547. } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
  10548. // We aren't likely to be able to resolve the identifier down to a type
  10549. // now anyway, so just retain the identifier.
  10550. Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
  10551. E->getDestroyedTypeLoc());
  10552. } else {
  10553. // Look for a destructor known with the given name.
  10554. ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
  10555. *E->getDestroyedTypeIdentifier(),
  10556. E->getDestroyedTypeLoc(),
  10557. /*Scope=*/nullptr,
  10558. SS, ObjectTypePtr,
  10559. false);
  10560. if (!T)
  10561. return ExprError();
  10562. Destroyed
  10563. = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
  10564. E->getDestroyedTypeLoc());
  10565. }
  10566. TypeSourceInfo *ScopeTypeInfo = nullptr;
  10567. if (E->getScopeTypeInfo()) {
  10568. CXXScopeSpec EmptySS;
  10569. ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
  10570. E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
  10571. if (!ScopeTypeInfo)
  10572. return ExprError();
  10573. }
  10574. return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
  10575. E->getOperatorLoc(),
  10576. E->isArrow(),
  10577. SS,
  10578. ScopeTypeInfo,
  10579. E->getColonColonLoc(),
  10580. E->getTildeLoc(),
  10581. Destroyed);
  10582. }
  10583. template <typename Derived>
  10584. bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old,
  10585. bool RequiresADL,
  10586. LookupResult &R) {
  10587. // Transform all the decls.
  10588. bool AllEmptyPacks = true;
  10589. for (auto *OldD : Old->decls()) {
  10590. Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
  10591. if (!InstD) {
  10592. // Silently ignore these if a UsingShadowDecl instantiated to nothing.
  10593. // This can happen because of dependent hiding.
  10594. if (isa<UsingShadowDecl>(OldD))
  10595. continue;
  10596. else {
  10597. R.clear();
  10598. return true;
  10599. }
  10600. }
  10601. // Expand using pack declarations.
  10602. NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
  10603. ArrayRef<NamedDecl*> Decls = SingleDecl;
  10604. if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
  10605. Decls = UPD->expansions();
  10606. // Expand using declarations.
  10607. for (auto *D : Decls) {
  10608. if (auto *UD = dyn_cast<UsingDecl>(D)) {
  10609. for (auto *SD : UD->shadows())
  10610. R.addDecl(SD);
  10611. } else {
  10612. R.addDecl(D);
  10613. }
  10614. }
  10615. AllEmptyPacks &= Decls.empty();
  10616. };
  10617. // C++ [temp.res]/8.4.2:
  10618. // The program is ill-formed, no diagnostic required, if [...] lookup for
  10619. // a name in the template definition found a using-declaration, but the
  10620. // lookup in the corresponding scope in the instantiation odoes not find
  10621. // any declarations because the using-declaration was a pack expansion and
  10622. // the corresponding pack is empty
  10623. if (AllEmptyPacks && !RequiresADL) {
  10624. getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
  10625. << isa<UnresolvedMemberExpr>(Old) << Old->getName();
  10626. return true;
  10627. }
  10628. // Resolve a kind, but don't do any further analysis. If it's
  10629. // ambiguous, the callee needs to deal with it.
  10630. R.resolveKind();
  10631. return false;
  10632. }
  10633. template<typename Derived>
  10634. ExprResult
  10635. TreeTransform<Derived>::TransformUnresolvedLookupExpr(
  10636. UnresolvedLookupExpr *Old) {
  10637. LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
  10638. Sema::LookupOrdinaryName);
  10639. // Transform the declaration set.
  10640. if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
  10641. return ExprError();
  10642. // Rebuild the nested-name qualifier, if present.
  10643. CXXScopeSpec SS;
  10644. if (Old->getQualifierLoc()) {
  10645. NestedNameSpecifierLoc QualifierLoc
  10646. = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
  10647. if (!QualifierLoc)
  10648. return ExprError();
  10649. SS.Adopt(QualifierLoc);
  10650. }
  10651. if (Old->getNamingClass()) {
  10652. CXXRecordDecl *NamingClass
  10653. = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
  10654. Old->getNameLoc(),
  10655. Old->getNamingClass()));
  10656. if (!NamingClass) {
  10657. R.clear();
  10658. return ExprError();
  10659. }
  10660. R.setNamingClass(NamingClass);
  10661. }
  10662. SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
  10663. // If we have neither explicit template arguments, nor the template keyword,
  10664. // it's a normal declaration name or member reference.
  10665. if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
  10666. NamedDecl *D = R.getAsSingle<NamedDecl>();
  10667. // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
  10668. // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
  10669. // give a good diagnostic.
  10670. if (D && D->isCXXInstanceMember()) {
  10671. return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
  10672. /*TemplateArgs=*/nullptr,
  10673. /*Scope=*/nullptr);
  10674. }
  10675. return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
  10676. }
  10677. // If we have template arguments, rebuild them, then rebuild the
  10678. // templateid expression.
  10679. TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
  10680. if (Old->hasExplicitTemplateArgs() &&
  10681. getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
  10682. Old->getNumTemplateArgs(),
  10683. TransArgs)) {
  10684. R.clear();
  10685. return ExprError();
  10686. }
  10687. return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
  10688. Old->requiresADL(), &TransArgs);
  10689. }
  10690. template<typename Derived>
  10691. ExprResult
  10692. TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
  10693. bool ArgChanged = false;
  10694. SmallVector<TypeSourceInfo *, 4> Args;
  10695. for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
  10696. TypeSourceInfo *From = E->getArg(I);
  10697. TypeLoc FromTL = From->getTypeLoc();
  10698. if (!FromTL.getAs<PackExpansionTypeLoc>()) {
  10699. TypeLocBuilder TLB;
  10700. TLB.reserve(FromTL.getFullDataSize());
  10701. QualType To = getDerived().TransformType(TLB, FromTL);
  10702. if (To.isNull())
  10703. return ExprError();
  10704. if (To == From->getType())
  10705. Args.push_back(From);
  10706. else {
  10707. Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
  10708. ArgChanged = true;
  10709. }
  10710. continue;
  10711. }
  10712. ArgChanged = true;
  10713. // We have a pack expansion. Instantiate it.
  10714. PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
  10715. TypeLoc PatternTL = ExpansionTL.getPatternLoc();
  10716. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  10717. SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
  10718. // Determine whether the set of unexpanded parameter packs can and should
  10719. // be expanded.
  10720. bool Expand = true;
  10721. bool RetainExpansion = false;
  10722. Optional<unsigned> OrigNumExpansions =
  10723. ExpansionTL.getTypePtr()->getNumExpansions();
  10724. Optional<unsigned> NumExpansions = OrigNumExpansions;
  10725. if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
  10726. PatternTL.getSourceRange(),
  10727. Unexpanded,
  10728. Expand, RetainExpansion,
  10729. NumExpansions))
  10730. return ExprError();
  10731. if (!Expand) {
  10732. // The transform has determined that we should perform a simple
  10733. // transformation on the pack expansion, producing another pack
  10734. // expansion.
  10735. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  10736. TypeLocBuilder TLB;
  10737. TLB.reserve(From->getTypeLoc().getFullDataSize());
  10738. QualType To = getDerived().TransformType(TLB, PatternTL);
  10739. if (To.isNull())
  10740. return ExprError();
  10741. To = getDerived().RebuildPackExpansionType(To,
  10742. PatternTL.getSourceRange(),
  10743. ExpansionTL.getEllipsisLoc(),
  10744. NumExpansions);
  10745. if (To.isNull())
  10746. return ExprError();
  10747. PackExpansionTypeLoc ToExpansionTL
  10748. = TLB.push<PackExpansionTypeLoc>(To);
  10749. ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
  10750. Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
  10751. continue;
  10752. }
  10753. // Expand the pack expansion by substituting for each argument in the
  10754. // pack(s).
  10755. for (unsigned I = 0; I != *NumExpansions; ++I) {
  10756. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
  10757. TypeLocBuilder TLB;
  10758. TLB.reserve(PatternTL.getFullDataSize());
  10759. QualType To = getDerived().TransformType(TLB, PatternTL);
  10760. if (To.isNull())
  10761. return ExprError();
  10762. if (To->containsUnexpandedParameterPack()) {
  10763. To = getDerived().RebuildPackExpansionType(To,
  10764. PatternTL.getSourceRange(),
  10765. ExpansionTL.getEllipsisLoc(),
  10766. NumExpansions);
  10767. if (To.isNull())
  10768. return ExprError();
  10769. PackExpansionTypeLoc ToExpansionTL
  10770. = TLB.push<PackExpansionTypeLoc>(To);
  10771. ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
  10772. }
  10773. Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
  10774. }
  10775. if (!RetainExpansion)
  10776. continue;
  10777. // If we're supposed to retain a pack expansion, do so by temporarily
  10778. // forgetting the partially-substituted parameter pack.
  10779. ForgetPartiallySubstitutedPackRAII Forget(getDerived());
  10780. TypeLocBuilder TLB;
  10781. TLB.reserve(From->getTypeLoc().getFullDataSize());
  10782. QualType To = getDerived().TransformType(TLB, PatternTL);
  10783. if (To.isNull())
  10784. return ExprError();
  10785. To = getDerived().RebuildPackExpansionType(To,
  10786. PatternTL.getSourceRange(),
  10787. ExpansionTL.getEllipsisLoc(),
  10788. NumExpansions);
  10789. if (To.isNull())
  10790. return ExprError();
  10791. PackExpansionTypeLoc ToExpansionTL
  10792. = TLB.push<PackExpansionTypeLoc>(To);
  10793. ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
  10794. Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
  10795. }
  10796. if (!getDerived().AlwaysRebuild() && !ArgChanged)
  10797. return E;
  10798. return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
  10799. E->getEndLoc());
  10800. }
  10801. template<typename Derived>
  10802. ExprResult
  10803. TreeTransform<Derived>::TransformConceptSpecializationExpr(
  10804. ConceptSpecializationExpr *E) {
  10805. const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
  10806. TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
  10807. if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
  10808. Old->NumTemplateArgs, TransArgs))
  10809. return ExprError();
  10810. return getDerived().RebuildConceptSpecializationExpr(
  10811. E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
  10812. E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
  10813. &TransArgs);
  10814. }
  10815. template<typename Derived>
  10816. ExprResult
  10817. TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
  10818. SmallVector<ParmVarDecl*, 4> TransParams;
  10819. SmallVector<QualType, 4> TransParamTypes;
  10820. Sema::ExtParameterInfoBuilder ExtParamInfos;
  10821. // C++2a [expr.prim.req]p2
  10822. // Expressions appearing within a requirement-body are unevaluated operands.
  10823. EnterExpressionEvaluationContext Ctx(
  10824. SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
  10825. RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
  10826. getSema().Context, getSema().CurContext,
  10827. E->getBody()->getBeginLoc());
  10828. Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
  10829. if (getDerived().TransformFunctionTypeParams(E->getRequiresKWLoc(),
  10830. E->getLocalParameters(),
  10831. /*ParamTypes=*/nullptr,
  10832. /*ParamInfos=*/nullptr,
  10833. TransParamTypes, &TransParams,
  10834. ExtParamInfos))
  10835. return ExprError();
  10836. for (ParmVarDecl *Param : TransParams)
  10837. Param->setDeclContext(Body);
  10838. SmallVector<concepts::Requirement *, 4> TransReqs;
  10839. if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
  10840. TransReqs))
  10841. return ExprError();
  10842. for (concepts::Requirement *Req : TransReqs) {
  10843. if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
  10844. if (ER->getReturnTypeRequirement().isTypeConstraint()) {
  10845. ER->getReturnTypeRequirement()
  10846. .getTypeConstraintTemplateParameterList()->getParam(0)
  10847. ->setDeclContext(Body);
  10848. }
  10849. }
  10850. }
  10851. return getDerived().RebuildRequiresExpr(E->getRequiresKWLoc(), Body,
  10852. TransParams, TransReqs,
  10853. E->getRBraceLoc());
  10854. }
  10855. template<typename Derived>
  10856. bool TreeTransform<Derived>::TransformRequiresExprRequirements(
  10857. ArrayRef<concepts::Requirement *> Reqs,
  10858. SmallVectorImpl<concepts::Requirement *> &Transformed) {
  10859. for (concepts::Requirement *Req : Reqs) {
  10860. concepts::Requirement *TransReq = nullptr;
  10861. if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
  10862. TransReq = getDerived().TransformTypeRequirement(TypeReq);
  10863. else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
  10864. TransReq = getDerived().TransformExprRequirement(ExprReq);
  10865. else
  10866. TransReq = getDerived().TransformNestedRequirement(
  10867. cast<concepts::NestedRequirement>(Req));
  10868. if (!TransReq)
  10869. return true;
  10870. Transformed.push_back(TransReq);
  10871. }
  10872. return false;
  10873. }
  10874. template<typename Derived>
  10875. concepts::TypeRequirement *
  10876. TreeTransform<Derived>::TransformTypeRequirement(
  10877. concepts::TypeRequirement *Req) {
  10878. if (Req->isSubstitutionFailure()) {
  10879. if (getDerived().AlwaysRebuild())
  10880. return getDerived().RebuildTypeRequirement(
  10881. Req->getSubstitutionDiagnostic());
  10882. return Req;
  10883. }
  10884. TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
  10885. if (!TransType)
  10886. return nullptr;
  10887. return getDerived().RebuildTypeRequirement(TransType);
  10888. }
  10889. template<typename Derived>
  10890. concepts::ExprRequirement *
  10891. TreeTransform<Derived>::TransformExprRequirement(concepts::ExprRequirement *Req) {
  10892. llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
  10893. if (Req->isExprSubstitutionFailure())
  10894. TransExpr = Req->getExprSubstitutionDiagnostic();
  10895. else {
  10896. ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
  10897. if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
  10898. TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
  10899. if (TransExprRes.isInvalid())
  10900. return nullptr;
  10901. TransExpr = TransExprRes.get();
  10902. }
  10903. llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
  10904. const auto &RetReq = Req->getReturnTypeRequirement();
  10905. if (RetReq.isEmpty())
  10906. TransRetReq.emplace();
  10907. else if (RetReq.isSubstitutionFailure())
  10908. TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
  10909. else if (RetReq.isTypeConstraint()) {
  10910. TemplateParameterList *OrigTPL =
  10911. RetReq.getTypeConstraintTemplateParameterList();
  10912. TemplateParameterList *TPL =
  10913. getDerived().TransformTemplateParameterList(OrigTPL);
  10914. if (!TPL)
  10915. return nullptr;
  10916. TransRetReq.emplace(TPL);
  10917. }
  10918. assert(TransRetReq.hasValue() &&
  10919. "All code paths leading here must set TransRetReq");
  10920. if (Expr *E = TransExpr.dyn_cast<Expr *>())
  10921. return getDerived().RebuildExprRequirement(E, Req->isSimple(),
  10922. Req->getNoexceptLoc(),
  10923. std::move(*TransRetReq));
  10924. return getDerived().RebuildExprRequirement(
  10925. TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(),
  10926. Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
  10927. }
  10928. template<typename Derived>
  10929. concepts::NestedRequirement *
  10930. TreeTransform<Derived>::TransformNestedRequirement(
  10931. concepts::NestedRequirement *Req) {
  10932. if (Req->isSubstitutionFailure()) {
  10933. if (getDerived().AlwaysRebuild())
  10934. return getDerived().RebuildNestedRequirement(
  10935. Req->getSubstitutionDiagnostic());
  10936. return Req;
  10937. }
  10938. ExprResult TransConstraint =
  10939. getDerived().TransformExpr(Req->getConstraintExpr());
  10940. if (TransConstraint.isInvalid())
  10941. return nullptr;
  10942. return getDerived().RebuildNestedRequirement(TransConstraint.get());
  10943. }
  10944. template<typename Derived>
  10945. ExprResult
  10946. TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
  10947. TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
  10948. if (!T)
  10949. return ExprError();
  10950. if (!getDerived().AlwaysRebuild() &&
  10951. T == E->getQueriedTypeSourceInfo())
  10952. return E;
  10953. ExprResult SubExpr;
  10954. {
  10955. EnterExpressionEvaluationContext Unevaluated(
  10956. SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
  10957. SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
  10958. if (SubExpr.isInvalid())
  10959. return ExprError();
  10960. if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
  10961. return E;
  10962. }
  10963. return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
  10964. SubExpr.get(), E->getEndLoc());
  10965. }
  10966. template<typename Derived>
  10967. ExprResult
  10968. TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
  10969. ExprResult SubExpr;
  10970. {
  10971. EnterExpressionEvaluationContext Unevaluated(
  10972. SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
  10973. SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
  10974. if (SubExpr.isInvalid())
  10975. return ExprError();
  10976. if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
  10977. return E;
  10978. }
  10979. return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
  10980. SubExpr.get(), E->getEndLoc());
  10981. }
  10982. template <typename Derived>
  10983. ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
  10984. ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
  10985. TypeSourceInfo **RecoveryTSI) {
  10986. ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
  10987. DRE, AddrTaken, RecoveryTSI);
  10988. // Propagate both errors and recovered types, which return ExprEmpty.
  10989. if (!NewDRE.isUsable())
  10990. return NewDRE;
  10991. // We got an expr, wrap it up in parens.
  10992. if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
  10993. return PE;
  10994. return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
  10995. PE->getRParen());
  10996. }
  10997. template <typename Derived>
  10998. ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
  10999. DependentScopeDeclRefExpr *E) {
  11000. return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
  11001. nullptr);
  11002. }
  11003. template <typename Derived>
  11004. ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
  11005. DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
  11006. TypeSourceInfo **RecoveryTSI) {
  11007. assert(E->getQualifierLoc());
  11008. NestedNameSpecifierLoc QualifierLoc =
  11009. getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
  11010. if (!QualifierLoc)
  11011. return ExprError();
  11012. SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
  11013. // TODO: If this is a conversion-function-id, verify that the
  11014. // destination type name (if present) resolves the same way after
  11015. // instantiation as it did in the local scope.
  11016. DeclarationNameInfo NameInfo =
  11017. getDerived().TransformDeclarationNameInfo(E->getNameInfo());
  11018. if (!NameInfo.getName())
  11019. return ExprError();
  11020. if (!E->hasExplicitTemplateArgs()) {
  11021. if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
  11022. // Note: it is sufficient to compare the Name component of NameInfo:
  11023. // if name has not changed, DNLoc has not changed either.
  11024. NameInfo.getName() == E->getDeclName())
  11025. return E;
  11026. return getDerived().RebuildDependentScopeDeclRefExpr(
  11027. QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
  11028. IsAddressOfOperand, RecoveryTSI);
  11029. }
  11030. TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
  11031. if (getDerived().TransformTemplateArguments(
  11032. E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
  11033. return ExprError();
  11034. return getDerived().RebuildDependentScopeDeclRefExpr(
  11035. QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
  11036. RecoveryTSI);
  11037. }
  11038. template<typename Derived>
  11039. ExprResult
  11040. TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
  11041. // CXXConstructExprs other than for list-initialization and
  11042. // CXXTemporaryObjectExpr are always implicit, so when we have
  11043. // a 1-argument construction we just transform that argument.
  11044. if (getDerived().AllowSkippingCXXConstructExpr() &&
  11045. ((E->getNumArgs() == 1 ||
  11046. (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
  11047. (!getDerived().DropCallArgument(E->getArg(0))) &&
  11048. !E->isListInitialization()))
  11049. return getDerived().TransformInitializer(E->getArg(0),
  11050. /*DirectInit*/ false);
  11051. TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
  11052. QualType T = getDerived().TransformType(E->getType());
  11053. if (T.isNull())
  11054. return ExprError();
  11055. CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
  11056. getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
  11057. if (!Constructor)
  11058. return ExprError();
  11059. bool ArgumentChanged = false;
  11060. SmallVector<Expr*, 8> Args;
  11061. {
  11062. EnterExpressionEvaluationContext Context(
  11063. getSema(), EnterExpressionEvaluationContext::InitList,
  11064. E->isListInitialization());
  11065. if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
  11066. &ArgumentChanged))
  11067. return ExprError();
  11068. }
  11069. if (!getDerived().AlwaysRebuild() &&
  11070. T == E->getType() &&
  11071. Constructor == E->getConstructor() &&
  11072. !ArgumentChanged) {
  11073. // Mark the constructor as referenced.
  11074. // FIXME: Instantiation-specific
  11075. SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
  11076. return E;
  11077. }
  11078. return getDerived().RebuildCXXConstructExpr(
  11079. T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
  11080. E->hadMultipleCandidates(), E->isListInitialization(),
  11081. E->isStdInitListInitialization(), E->requiresZeroInitialization(),
  11082. E->getConstructionKind(), E->getParenOrBraceRange());
  11083. }
  11084. template<typename Derived>
  11085. ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
  11086. CXXInheritedCtorInitExpr *E) {
  11087. QualType T = getDerived().TransformType(E->getType());
  11088. if (T.isNull())
  11089. return ExprError();
  11090. CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
  11091. getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
  11092. if (!Constructor)
  11093. return ExprError();
  11094. if (!getDerived().AlwaysRebuild() &&
  11095. T == E->getType() &&
  11096. Constructor == E->getConstructor()) {
  11097. // Mark the constructor as referenced.
  11098. // FIXME: Instantiation-specific
  11099. SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
  11100. return E;
  11101. }
  11102. return getDerived().RebuildCXXInheritedCtorInitExpr(
  11103. T, E->getLocation(), Constructor,
  11104. E->constructsVBase(), E->inheritedFromVBase());
  11105. }
  11106. /// Transform a C++ temporary-binding expression.
  11107. ///
  11108. /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
  11109. /// transform the subexpression and return that.
  11110. template<typename Derived>
  11111. ExprResult
  11112. TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
  11113. return getDerived().TransformExpr(E->getSubExpr());
  11114. }
  11115. /// Transform a C++ expression that contains cleanups that should
  11116. /// be run after the expression is evaluated.
  11117. ///
  11118. /// Since ExprWithCleanups nodes are implicitly generated, we
  11119. /// just transform the subexpression and return that.
  11120. template<typename Derived>
  11121. ExprResult
  11122. TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
  11123. return getDerived().TransformExpr(E->getSubExpr());
  11124. }
  11125. template<typename Derived>
  11126. ExprResult
  11127. TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
  11128. CXXTemporaryObjectExpr *E) {
  11129. TypeSourceInfo *T =
  11130. getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
  11131. if (!T)
  11132. return ExprError();
  11133. CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
  11134. getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
  11135. if (!Constructor)
  11136. return ExprError();
  11137. bool ArgumentChanged = false;
  11138. SmallVector<Expr*, 8> Args;
  11139. Args.reserve(E->getNumArgs());
  11140. {
  11141. EnterExpressionEvaluationContext Context(
  11142. getSema(), EnterExpressionEvaluationContext::InitList,
  11143. E->isListInitialization());
  11144. if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
  11145. &ArgumentChanged))
  11146. return ExprError();
  11147. }
  11148. if (!getDerived().AlwaysRebuild() &&
  11149. T == E->getTypeSourceInfo() &&
  11150. Constructor == E->getConstructor() &&
  11151. !ArgumentChanged) {
  11152. // FIXME: Instantiation-specific
  11153. SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
  11154. return SemaRef.MaybeBindToTemporary(E);
  11155. }
  11156. // FIXME: We should just pass E->isListInitialization(), but we're not
  11157. // prepared to handle list-initialization without a child InitListExpr.
  11158. SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
  11159. return getDerived().RebuildCXXTemporaryObjectExpr(
  11160. T, LParenLoc, Args, E->getEndLoc(),
  11161. /*ListInitialization=*/LParenLoc.isInvalid());
  11162. }
  11163. template<typename Derived>
  11164. ExprResult
  11165. TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
  11166. // Transform any init-capture expressions before entering the scope of the
  11167. // lambda body, because they are not semantically within that scope.
  11168. typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
  11169. struct TransformedInitCapture {
  11170. // The location of the ... if the result is retaining a pack expansion.
  11171. SourceLocation EllipsisLoc;
  11172. // Zero or more expansions of the init-capture.
  11173. SmallVector<InitCaptureInfoTy, 4> Expansions;
  11174. };
  11175. SmallVector<TransformedInitCapture, 4> InitCaptures;
  11176. InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
  11177. for (LambdaExpr::capture_iterator C = E->capture_begin(),
  11178. CEnd = E->capture_end();
  11179. C != CEnd; ++C) {
  11180. if (!E->isInitCapture(C))
  11181. continue;
  11182. TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
  11183. VarDecl *OldVD = C->getCapturedVar();
  11184. auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
  11185. Optional<unsigned> NumExpansions) {
  11186. ExprResult NewExprInitResult = getDerived().TransformInitializer(
  11187. OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
  11188. if (NewExprInitResult.isInvalid()) {
  11189. Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
  11190. return;
  11191. }
  11192. Expr *NewExprInit = NewExprInitResult.get();
  11193. QualType NewInitCaptureType =
  11194. getSema().buildLambdaInitCaptureInitialization(
  11195. C->getLocation(), OldVD->getType()->isReferenceType(),
  11196. EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
  11197. C->getCapturedVar()->getInitStyle() != VarDecl::CInit,
  11198. NewExprInit);
  11199. Result.Expansions.push_back(
  11200. InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
  11201. };
  11202. // If this is an init-capture pack, consider expanding the pack now.
  11203. if (OldVD->isParameterPack()) {
  11204. PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
  11205. ->getTypeLoc()
  11206. .castAs<PackExpansionTypeLoc>();
  11207. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  11208. SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
  11209. // Determine whether the set of unexpanded parameter packs can and should
  11210. // be expanded.
  11211. bool Expand = true;
  11212. bool RetainExpansion = false;
  11213. Optional<unsigned> OrigNumExpansions =
  11214. ExpansionTL.getTypePtr()->getNumExpansions();
  11215. Optional<unsigned> NumExpansions = OrigNumExpansions;
  11216. if (getDerived().TryExpandParameterPacks(
  11217. ExpansionTL.getEllipsisLoc(),
  11218. OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
  11219. RetainExpansion, NumExpansions))
  11220. return ExprError();
  11221. if (Expand) {
  11222. for (unsigned I = 0; I != *NumExpansions; ++I) {
  11223. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
  11224. SubstInitCapture(SourceLocation(), None);
  11225. }
  11226. }
  11227. if (!Expand || RetainExpansion) {
  11228. ForgetPartiallySubstitutedPackRAII Forget(getDerived());
  11229. SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
  11230. Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
  11231. }
  11232. } else {
  11233. SubstInitCapture(SourceLocation(), None);
  11234. }
  11235. }
  11236. LambdaScopeInfo *LSI = getSema().PushLambdaScope();
  11237. Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
  11238. // Transform the template parameters, and add them to the current
  11239. // instantiation scope. The null case is handled correctly.
  11240. auto TPL = getDerived().TransformTemplateParameterList(
  11241. E->getTemplateParameterList());
  11242. LSI->GLTemplateParameterList = TPL;
  11243. // Transform the type of the original lambda's call operator.
  11244. // The transformation MUST be done in the CurrentInstantiationScope since
  11245. // it introduces a mapping of the original to the newly created
  11246. // transformed parameters.
  11247. TypeSourceInfo *NewCallOpTSI = nullptr;
  11248. {
  11249. TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
  11250. FunctionProtoTypeLoc OldCallOpFPTL =
  11251. OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
  11252. TypeLocBuilder NewCallOpTLBuilder;
  11253. SmallVector<QualType, 4> ExceptionStorage;
  11254. TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
  11255. QualType NewCallOpType = TransformFunctionProtoType(
  11256. NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(),
  11257. [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
  11258. return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
  11259. ExceptionStorage, Changed);
  11260. });
  11261. if (NewCallOpType.isNull())
  11262. return ExprError();
  11263. NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
  11264. NewCallOpType);
  11265. }
  11266. // Transform the trailing requires clause
  11267. ExprResult NewTrailingRequiresClause;
  11268. if (Expr *TRC = E->getCallOperator()->getTrailingRequiresClause())
  11269. // FIXME: Concepts: Substitution into requires clause should only happen
  11270. // when checking satisfaction.
  11271. NewTrailingRequiresClause = getDerived().TransformExpr(TRC);
  11272. // Create the local class that will describe the lambda.
  11273. // FIXME: KnownDependent below is wrong when substituting inside a templated
  11274. // context that isn't a DeclContext (such as a variable template).
  11275. CXXRecordDecl *OldClass = E->getLambdaClass();
  11276. CXXRecordDecl *Class
  11277. = getSema().createLambdaClosureType(E->getIntroducerRange(),
  11278. NewCallOpTSI,
  11279. /*KnownDependent=*/false,
  11280. E->getCaptureDefault());
  11281. getDerived().transformedLocalDecl(OldClass, {Class});
  11282. Optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling;
  11283. if (getDerived().ReplacingOriginal())
  11284. Mangling = std::make_tuple(OldClass->hasKnownLambdaInternalLinkage(),
  11285. OldClass->getLambdaManglingNumber(),
  11286. OldClass->getDeviceLambdaManglingNumber(),
  11287. OldClass->getLambdaContextDecl());
  11288. // Build the call operator.
  11289. CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
  11290. Class, E->getIntroducerRange(), NewCallOpTSI,
  11291. E->getCallOperator()->getEndLoc(),
  11292. NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(),
  11293. E->getCallOperator()->getConstexprKind(),
  11294. NewTrailingRequiresClause.get());
  11295. LSI->CallOperator = NewCallOperator;
  11296. getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
  11297. getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
  11298. // Number the lambda for linkage purposes if necessary.
  11299. getSema().handleLambdaNumbering(Class, NewCallOperator, Mangling);
  11300. // Introduce the context of the call operator.
  11301. Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
  11302. /*NewThisContext*/false);
  11303. // Enter the scope of the lambda.
  11304. getSema().buildLambdaScope(LSI, NewCallOperator,
  11305. E->getIntroducerRange(),
  11306. E->getCaptureDefault(),
  11307. E->getCaptureDefaultLoc(),
  11308. E->hasExplicitParameters(),
  11309. E->hasExplicitResultType(),
  11310. E->isMutable());
  11311. bool Invalid = false;
  11312. // Transform captures.
  11313. for (LambdaExpr::capture_iterator C = E->capture_begin(),
  11314. CEnd = E->capture_end();
  11315. C != CEnd; ++C) {
  11316. // When we hit the first implicit capture, tell Sema that we've finished
  11317. // the list of explicit captures.
  11318. if (C->isImplicit())
  11319. break;
  11320. // Capturing 'this' is trivial.
  11321. if (C->capturesThis()) {
  11322. getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
  11323. /*BuildAndDiagnose*/ true, nullptr,
  11324. C->getCaptureKind() == LCK_StarThis);
  11325. continue;
  11326. }
  11327. // Captured expression will be recaptured during captured variables
  11328. // rebuilding.
  11329. if (C->capturesVLAType())
  11330. continue;
  11331. // Rebuild init-captures, including the implied field declaration.
  11332. if (E->isInitCapture(C)) {
  11333. TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
  11334. VarDecl *OldVD = C->getCapturedVar();
  11335. llvm::SmallVector<Decl*, 4> NewVDs;
  11336. for (InitCaptureInfoTy &Info : NewC.Expansions) {
  11337. ExprResult Init = Info.first;
  11338. QualType InitQualType = Info.second;
  11339. if (Init.isInvalid() || InitQualType.isNull()) {
  11340. Invalid = true;
  11341. break;
  11342. }
  11343. VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
  11344. OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
  11345. OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get());
  11346. if (!NewVD) {
  11347. Invalid = true;
  11348. break;
  11349. }
  11350. NewVDs.push_back(NewVD);
  11351. getSema().addInitCapture(LSI, NewVD);
  11352. }
  11353. if (Invalid)
  11354. break;
  11355. getDerived().transformedLocalDecl(OldVD, NewVDs);
  11356. continue;
  11357. }
  11358. assert(C->capturesVariable() && "unexpected kind of lambda capture");
  11359. // Determine the capture kind for Sema.
  11360. Sema::TryCaptureKind Kind
  11361. = C->isImplicit()? Sema::TryCapture_Implicit
  11362. : C->getCaptureKind() == LCK_ByCopy
  11363. ? Sema::TryCapture_ExplicitByVal
  11364. : Sema::TryCapture_ExplicitByRef;
  11365. SourceLocation EllipsisLoc;
  11366. if (C->isPackExpansion()) {
  11367. UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
  11368. bool ShouldExpand = false;
  11369. bool RetainExpansion = false;
  11370. Optional<unsigned> NumExpansions;
  11371. if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
  11372. C->getLocation(),
  11373. Unexpanded,
  11374. ShouldExpand, RetainExpansion,
  11375. NumExpansions)) {
  11376. Invalid = true;
  11377. continue;
  11378. }
  11379. if (ShouldExpand) {
  11380. // The transform has determined that we should perform an expansion;
  11381. // transform and capture each of the arguments.
  11382. // expansion of the pattern. Do so.
  11383. VarDecl *Pack = C->getCapturedVar();
  11384. for (unsigned I = 0; I != *NumExpansions; ++I) {
  11385. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
  11386. VarDecl *CapturedVar
  11387. = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
  11388. Pack));
  11389. if (!CapturedVar) {
  11390. Invalid = true;
  11391. continue;
  11392. }
  11393. // Capture the transformed variable.
  11394. getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
  11395. }
  11396. // FIXME: Retain a pack expansion if RetainExpansion is true.
  11397. continue;
  11398. }
  11399. EllipsisLoc = C->getEllipsisLoc();
  11400. }
  11401. // Transform the captured variable.
  11402. VarDecl *CapturedVar
  11403. = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
  11404. C->getCapturedVar()));
  11405. if (!CapturedVar || CapturedVar->isInvalidDecl()) {
  11406. Invalid = true;
  11407. continue;
  11408. }
  11409. // Capture the transformed variable.
  11410. getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
  11411. EllipsisLoc);
  11412. }
  11413. getSema().finishLambdaExplicitCaptures(LSI);
  11414. // FIXME: Sema's lambda-building mechanism expects us to push an expression
  11415. // evaluation context even if we're not transforming the function body.
  11416. getSema().PushExpressionEvaluationContext(
  11417. Sema::ExpressionEvaluationContext::PotentiallyEvaluated);
  11418. // Instantiate the body of the lambda expression.
  11419. StmtResult Body =
  11420. Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
  11421. // ActOnLambda* will pop the function scope for us.
  11422. FuncScopeCleanup.disable();
  11423. if (Body.isInvalid()) {
  11424. SavedContext.pop();
  11425. getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
  11426. /*IsInstantiation=*/true);
  11427. return ExprError();
  11428. }
  11429. // Copy the LSI before ActOnFinishFunctionBody removes it.
  11430. // FIXME: This is dumb. Store the lambda information somewhere that outlives
  11431. // the call operator.
  11432. auto LSICopy = *LSI;
  11433. getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
  11434. /*IsInstantiation*/ true);
  11435. SavedContext.pop();
  11436. return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
  11437. &LSICopy);
  11438. }
  11439. template<typename Derived>
  11440. StmtResult
  11441. TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) {
  11442. return TransformStmt(S);
  11443. }
  11444. template<typename Derived>
  11445. StmtResult
  11446. TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) {
  11447. // Transform captures.
  11448. for (LambdaExpr::capture_iterator C = E->capture_begin(),
  11449. CEnd = E->capture_end();
  11450. C != CEnd; ++C) {
  11451. // When we hit the first implicit capture, tell Sema that we've finished
  11452. // the list of explicit captures.
  11453. if (!C->isImplicit())
  11454. continue;
  11455. // Capturing 'this' is trivial.
  11456. if (C->capturesThis()) {
  11457. getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
  11458. /*BuildAndDiagnose*/ true, nullptr,
  11459. C->getCaptureKind() == LCK_StarThis);
  11460. continue;
  11461. }
  11462. // Captured expression will be recaptured during captured variables
  11463. // rebuilding.
  11464. if (C->capturesVLAType())
  11465. continue;
  11466. assert(C->capturesVariable() && "unexpected kind of lambda capture");
  11467. assert(!E->isInitCapture(C) && "implicit init-capture?");
  11468. // Transform the captured variable.
  11469. VarDecl *CapturedVar = cast_or_null<VarDecl>(
  11470. getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
  11471. if (!CapturedVar || CapturedVar->isInvalidDecl())
  11472. return StmtError();
  11473. // Capture the transformed variable.
  11474. getSema().tryCaptureVariable(CapturedVar, C->getLocation());
  11475. }
  11476. return S;
  11477. }
  11478. template<typename Derived>
  11479. ExprResult
  11480. TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
  11481. CXXUnresolvedConstructExpr *E) {
  11482. TypeSourceInfo *T =
  11483. getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
  11484. if (!T)
  11485. return ExprError();
  11486. bool ArgumentChanged = false;
  11487. SmallVector<Expr*, 8> Args;
  11488. Args.reserve(E->getNumArgs());
  11489. {
  11490. EnterExpressionEvaluationContext Context(
  11491. getSema(), EnterExpressionEvaluationContext::InitList,
  11492. E->isListInitialization());
  11493. if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
  11494. &ArgumentChanged))
  11495. return ExprError();
  11496. }
  11497. if (!getDerived().AlwaysRebuild() &&
  11498. T == E->getTypeSourceInfo() &&
  11499. !ArgumentChanged)
  11500. return E;
  11501. // FIXME: we're faking the locations of the commas
  11502. return getDerived().RebuildCXXUnresolvedConstructExpr(
  11503. T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
  11504. }
  11505. template<typename Derived>
  11506. ExprResult
  11507. TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
  11508. CXXDependentScopeMemberExpr *E) {
  11509. // Transform the base of the expression.
  11510. ExprResult Base((Expr*) nullptr);
  11511. Expr *OldBase;
  11512. QualType BaseType;
  11513. QualType ObjectType;
  11514. if (!E->isImplicitAccess()) {
  11515. OldBase = E->getBase();
  11516. Base = getDerived().TransformExpr(OldBase);
  11517. if (Base.isInvalid())
  11518. return ExprError();
  11519. // Start the member reference and compute the object's type.
  11520. ParsedType ObjectTy;
  11521. bool MayBePseudoDestructor = false;
  11522. Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
  11523. E->getOperatorLoc(),
  11524. E->isArrow()? tok::arrow : tok::period,
  11525. ObjectTy,
  11526. MayBePseudoDestructor);
  11527. if (Base.isInvalid())
  11528. return ExprError();
  11529. ObjectType = ObjectTy.get();
  11530. BaseType = ((Expr*) Base.get())->getType();
  11531. } else {
  11532. OldBase = nullptr;
  11533. BaseType = getDerived().TransformType(E->getBaseType());
  11534. ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
  11535. }
  11536. // Transform the first part of the nested-name-specifier that qualifies
  11537. // the member name.
  11538. NamedDecl *FirstQualifierInScope
  11539. = getDerived().TransformFirstQualifierInScope(
  11540. E->getFirstQualifierFoundInScope(),
  11541. E->getQualifierLoc().getBeginLoc());
  11542. NestedNameSpecifierLoc QualifierLoc;
  11543. if (E->getQualifier()) {
  11544. QualifierLoc
  11545. = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
  11546. ObjectType,
  11547. FirstQualifierInScope);
  11548. if (!QualifierLoc)
  11549. return ExprError();
  11550. }
  11551. SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
  11552. // TODO: If this is a conversion-function-id, verify that the
  11553. // destination type name (if present) resolves the same way after
  11554. // instantiation as it did in the local scope.
  11555. DeclarationNameInfo NameInfo
  11556. = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
  11557. if (!NameInfo.getName())
  11558. return ExprError();
  11559. if (!E->hasExplicitTemplateArgs()) {
  11560. // This is a reference to a member without an explicitly-specified
  11561. // template argument list. Optimize for this common case.
  11562. if (!getDerived().AlwaysRebuild() &&
  11563. Base.get() == OldBase &&
  11564. BaseType == E->getBaseType() &&
  11565. QualifierLoc == E->getQualifierLoc() &&
  11566. NameInfo.getName() == E->getMember() &&
  11567. FirstQualifierInScope == E->getFirstQualifierFoundInScope())
  11568. return E;
  11569. return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
  11570. BaseType,
  11571. E->isArrow(),
  11572. E->getOperatorLoc(),
  11573. QualifierLoc,
  11574. TemplateKWLoc,
  11575. FirstQualifierInScope,
  11576. NameInfo,
  11577. /*TemplateArgs*/nullptr);
  11578. }
  11579. TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
  11580. if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
  11581. E->getNumTemplateArgs(),
  11582. TransArgs))
  11583. return ExprError();
  11584. return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
  11585. BaseType,
  11586. E->isArrow(),
  11587. E->getOperatorLoc(),
  11588. QualifierLoc,
  11589. TemplateKWLoc,
  11590. FirstQualifierInScope,
  11591. NameInfo,
  11592. &TransArgs);
  11593. }
  11594. template <typename Derived>
  11595. ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
  11596. UnresolvedMemberExpr *Old) {
  11597. // Transform the base of the expression.
  11598. ExprResult Base((Expr *)nullptr);
  11599. QualType BaseType;
  11600. if (!Old->isImplicitAccess()) {
  11601. Base = getDerived().TransformExpr(Old->getBase());
  11602. if (Base.isInvalid())
  11603. return ExprError();
  11604. Base =
  11605. getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
  11606. if (Base.isInvalid())
  11607. return ExprError();
  11608. BaseType = Base.get()->getType();
  11609. } else {
  11610. BaseType = getDerived().TransformType(Old->getBaseType());
  11611. }
  11612. NestedNameSpecifierLoc QualifierLoc;
  11613. if (Old->getQualifierLoc()) {
  11614. QualifierLoc =
  11615. getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
  11616. if (!QualifierLoc)
  11617. return ExprError();
  11618. }
  11619. SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
  11620. LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
  11621. // Transform the declaration set.
  11622. if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
  11623. return ExprError();
  11624. // Determine the naming class.
  11625. if (Old->getNamingClass()) {
  11626. CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
  11627. getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
  11628. if (!NamingClass)
  11629. return ExprError();
  11630. R.setNamingClass(NamingClass);
  11631. }
  11632. TemplateArgumentListInfo TransArgs;
  11633. if (Old->hasExplicitTemplateArgs()) {
  11634. TransArgs.setLAngleLoc(Old->getLAngleLoc());
  11635. TransArgs.setRAngleLoc(Old->getRAngleLoc());
  11636. if (getDerived().TransformTemplateArguments(
  11637. Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
  11638. return ExprError();
  11639. }
  11640. // FIXME: to do this check properly, we will need to preserve the
  11641. // first-qualifier-in-scope here, just in case we had a dependent
  11642. // base (and therefore couldn't do the check) and a
  11643. // nested-name-qualifier (and therefore could do the lookup).
  11644. NamedDecl *FirstQualifierInScope = nullptr;
  11645. return getDerived().RebuildUnresolvedMemberExpr(
  11646. Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
  11647. TemplateKWLoc, FirstQualifierInScope, R,
  11648. (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
  11649. }
  11650. template<typename Derived>
  11651. ExprResult
  11652. TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
  11653. EnterExpressionEvaluationContext Unevaluated(
  11654. SemaRef, Sema::ExpressionEvaluationContext::Unevaluated);
  11655. ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
  11656. if (SubExpr.isInvalid())
  11657. return ExprError();
  11658. if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
  11659. return E;
  11660. return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
  11661. }
  11662. template<typename Derived>
  11663. ExprResult
  11664. TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
  11665. ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
  11666. if (Pattern.isInvalid())
  11667. return ExprError();
  11668. if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
  11669. return E;
  11670. return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
  11671. E->getNumExpansions());
  11672. }
  11673. template<typename Derived>
  11674. ExprResult
  11675. TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
  11676. // If E is not value-dependent, then nothing will change when we transform it.
  11677. // Note: This is an instantiation-centric view.
  11678. if (!E->isValueDependent())
  11679. return E;
  11680. EnterExpressionEvaluationContext Unevaluated(
  11681. getSema(), Sema::ExpressionEvaluationContext::Unevaluated);
  11682. ArrayRef<TemplateArgument> PackArgs;
  11683. TemplateArgument ArgStorage;
  11684. // Find the argument list to transform.
  11685. if (E->isPartiallySubstituted()) {
  11686. PackArgs = E->getPartialArguments();
  11687. } else if (E->isValueDependent()) {
  11688. UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
  11689. bool ShouldExpand = false;
  11690. bool RetainExpansion = false;
  11691. Optional<unsigned> NumExpansions;
  11692. if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
  11693. Unexpanded,
  11694. ShouldExpand, RetainExpansion,
  11695. NumExpansions))
  11696. return ExprError();
  11697. // If we need to expand the pack, build a template argument from it and
  11698. // expand that.
  11699. if (ShouldExpand) {
  11700. auto *Pack = E->getPack();
  11701. if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
  11702. ArgStorage = getSema().Context.getPackExpansionType(
  11703. getSema().Context.getTypeDeclType(TTPD), None);
  11704. } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
  11705. ArgStorage = TemplateArgument(TemplateName(TTPD), None);
  11706. } else {
  11707. auto *VD = cast<ValueDecl>(Pack);
  11708. ExprResult DRE = getSema().BuildDeclRefExpr(
  11709. VD, VD->getType().getNonLValueExprType(getSema().Context),
  11710. VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
  11711. E->getPackLoc());
  11712. if (DRE.isInvalid())
  11713. return ExprError();
  11714. ArgStorage = new (getSema().Context) PackExpansionExpr(
  11715. getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
  11716. }
  11717. PackArgs = ArgStorage;
  11718. }
  11719. }
  11720. // If we're not expanding the pack, just transform the decl.
  11721. if (!PackArgs.size()) {
  11722. auto *Pack = cast_or_null<NamedDecl>(
  11723. getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
  11724. if (!Pack)
  11725. return ExprError();
  11726. return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
  11727. E->getPackLoc(),
  11728. E->getRParenLoc(), None, None);
  11729. }
  11730. // Try to compute the result without performing a partial substitution.
  11731. Optional<unsigned> Result = 0;
  11732. for (const TemplateArgument &Arg : PackArgs) {
  11733. if (!Arg.isPackExpansion()) {
  11734. Result = *Result + 1;
  11735. continue;
  11736. }
  11737. TemplateArgumentLoc ArgLoc;
  11738. InventTemplateArgumentLoc(Arg, ArgLoc);
  11739. // Find the pattern of the pack expansion.
  11740. SourceLocation Ellipsis;
  11741. Optional<unsigned> OrigNumExpansions;
  11742. TemplateArgumentLoc Pattern =
  11743. getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
  11744. OrigNumExpansions);
  11745. // Substitute under the pack expansion. Do not expand the pack (yet).
  11746. TemplateArgumentLoc OutPattern;
  11747. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  11748. if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
  11749. /*Uneval*/ true))
  11750. return true;
  11751. // See if we can determine the number of arguments from the result.
  11752. Optional<unsigned> NumExpansions =
  11753. getSema().getFullyPackExpandedSize(OutPattern.getArgument());
  11754. if (!NumExpansions) {
  11755. // No: we must be in an alias template expansion, and we're going to need
  11756. // to actually expand the packs.
  11757. Result = None;
  11758. break;
  11759. }
  11760. Result = *Result + *NumExpansions;
  11761. }
  11762. // Common case: we could determine the number of expansions without
  11763. // substituting.
  11764. if (Result)
  11765. return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
  11766. E->getPackLoc(),
  11767. E->getRParenLoc(), *Result, None);
  11768. TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
  11769. E->getPackLoc());
  11770. {
  11771. TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
  11772. typedef TemplateArgumentLocInventIterator<
  11773. Derived, const TemplateArgument*> PackLocIterator;
  11774. if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
  11775. PackLocIterator(*this, PackArgs.end()),
  11776. TransformedPackArgs, /*Uneval*/true))
  11777. return ExprError();
  11778. }
  11779. // Check whether we managed to fully-expand the pack.
  11780. // FIXME: Is it possible for us to do so and not hit the early exit path?
  11781. SmallVector<TemplateArgument, 8> Args;
  11782. bool PartialSubstitution = false;
  11783. for (auto &Loc : TransformedPackArgs.arguments()) {
  11784. Args.push_back(Loc.getArgument());
  11785. if (Loc.getArgument().isPackExpansion())
  11786. PartialSubstitution = true;
  11787. }
  11788. if (PartialSubstitution)
  11789. return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
  11790. E->getPackLoc(),
  11791. E->getRParenLoc(), None, Args);
  11792. return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
  11793. E->getPackLoc(), E->getRParenLoc(),
  11794. Args.size(), None);
  11795. }
  11796. template<typename Derived>
  11797. ExprResult
  11798. TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
  11799. SubstNonTypeTemplateParmPackExpr *E) {
  11800. // Default behavior is to do nothing with this transformation.
  11801. return E;
  11802. }
  11803. template<typename Derived>
  11804. ExprResult
  11805. TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
  11806. SubstNonTypeTemplateParmExpr *E) {
  11807. // Default behavior is to do nothing with this transformation.
  11808. return E;
  11809. }
  11810. template<typename Derived>
  11811. ExprResult
  11812. TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
  11813. // Default behavior is to do nothing with this transformation.
  11814. return E;
  11815. }
  11816. template<typename Derived>
  11817. ExprResult
  11818. TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
  11819. MaterializeTemporaryExpr *E) {
  11820. return getDerived().TransformExpr(E->getSubExpr());
  11821. }
  11822. template<typename Derived>
  11823. ExprResult
  11824. TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
  11825. UnresolvedLookupExpr *Callee = nullptr;
  11826. if (Expr *OldCallee = E->getCallee()) {
  11827. ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
  11828. if (CalleeResult.isInvalid())
  11829. return ExprError();
  11830. Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
  11831. }
  11832. Expr *Pattern = E->getPattern();
  11833. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  11834. getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
  11835. assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
  11836. // Determine whether the set of unexpanded parameter packs can and should
  11837. // be expanded.
  11838. bool Expand = true;
  11839. bool RetainExpansion = false;
  11840. Optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
  11841. NumExpansions = OrigNumExpansions;
  11842. if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
  11843. Pattern->getSourceRange(),
  11844. Unexpanded,
  11845. Expand, RetainExpansion,
  11846. NumExpansions))
  11847. return true;
  11848. if (!Expand) {
  11849. // Do not expand any packs here, just transform and rebuild a fold
  11850. // expression.
  11851. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  11852. ExprResult LHS =
  11853. E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
  11854. if (LHS.isInvalid())
  11855. return true;
  11856. ExprResult RHS =
  11857. E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
  11858. if (RHS.isInvalid())
  11859. return true;
  11860. if (!getDerived().AlwaysRebuild() &&
  11861. LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
  11862. return E;
  11863. return getDerived().RebuildCXXFoldExpr(
  11864. Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
  11865. E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
  11866. }
  11867. // Formally a fold expression expands to nested parenthesized expressions.
  11868. // Enforce this limit to avoid creating trees so deep we can't safely traverse
  11869. // them.
  11870. if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) {
  11871. SemaRef.Diag(E->getEllipsisLoc(),
  11872. clang::diag::err_fold_expression_limit_exceeded)
  11873. << *NumExpansions << SemaRef.getLangOpts().BracketDepth
  11874. << E->getSourceRange();
  11875. SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
  11876. return ExprError();
  11877. }
  11878. // The transform has determined that we should perform an elementwise
  11879. // expansion of the pattern. Do so.
  11880. ExprResult Result = getDerived().TransformExpr(E->getInit());
  11881. if (Result.isInvalid())
  11882. return true;
  11883. bool LeftFold = E->isLeftFold();
  11884. // If we're retaining an expansion for a right fold, it is the innermost
  11885. // component and takes the init (if any).
  11886. if (!LeftFold && RetainExpansion) {
  11887. ForgetPartiallySubstitutedPackRAII Forget(getDerived());
  11888. ExprResult Out = getDerived().TransformExpr(Pattern);
  11889. if (Out.isInvalid())
  11890. return true;
  11891. Result = getDerived().RebuildCXXFoldExpr(
  11892. Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
  11893. E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
  11894. if (Result.isInvalid())
  11895. return true;
  11896. }
  11897. for (unsigned I = 0; I != *NumExpansions; ++I) {
  11898. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
  11899. getSema(), LeftFold ? I : *NumExpansions - I - 1);
  11900. ExprResult Out = getDerived().TransformExpr(Pattern);
  11901. if (Out.isInvalid())
  11902. return true;
  11903. if (Out.get()->containsUnexpandedParameterPack()) {
  11904. // We still have a pack; retain a pack expansion for this slice.
  11905. Result = getDerived().RebuildCXXFoldExpr(
  11906. Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
  11907. E->getOperator(), E->getEllipsisLoc(),
  11908. LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
  11909. OrigNumExpansions);
  11910. } else if (Result.isUsable()) {
  11911. // We've got down to a single element; build a binary operator.
  11912. Expr *LHS = LeftFold ? Result.get() : Out.get();
  11913. Expr *RHS = LeftFold ? Out.get() : Result.get();
  11914. if (Callee)
  11915. Result = getDerived().RebuildCXXOperatorCallExpr(
  11916. BinaryOperator::getOverloadedOperator(E->getOperator()),
  11917. E->getEllipsisLoc(), Callee, LHS, RHS);
  11918. else
  11919. Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
  11920. E->getOperator(), LHS, RHS);
  11921. } else
  11922. Result = Out;
  11923. if (Result.isInvalid())
  11924. return true;
  11925. }
  11926. // If we're retaining an expansion for a left fold, it is the outermost
  11927. // component and takes the complete expansion so far as its init (if any).
  11928. if (LeftFold && RetainExpansion) {
  11929. ForgetPartiallySubstitutedPackRAII Forget(getDerived());
  11930. ExprResult Out = getDerived().TransformExpr(Pattern);
  11931. if (Out.isInvalid())
  11932. return true;
  11933. Result = getDerived().RebuildCXXFoldExpr(
  11934. Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
  11935. E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
  11936. if (Result.isInvalid())
  11937. return true;
  11938. }
  11939. // If we had no init and an empty pack, and we're not retaining an expansion,
  11940. // then produce a fallback value or error.
  11941. if (Result.isUnset())
  11942. return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
  11943. E->getOperator());
  11944. return Result;
  11945. }
  11946. template<typename Derived>
  11947. ExprResult
  11948. TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
  11949. CXXStdInitializerListExpr *E) {
  11950. return getDerived().TransformExpr(E->getSubExpr());
  11951. }
  11952. template<typename Derived>
  11953. ExprResult
  11954. TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
  11955. return SemaRef.MaybeBindToTemporary(E);
  11956. }
  11957. template<typename Derived>
  11958. ExprResult
  11959. TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
  11960. return E;
  11961. }
  11962. template<typename Derived>
  11963. ExprResult
  11964. TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
  11965. ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
  11966. if (SubExpr.isInvalid())
  11967. return ExprError();
  11968. if (!getDerived().AlwaysRebuild() &&
  11969. SubExpr.get() == E->getSubExpr())
  11970. return E;
  11971. return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
  11972. }
  11973. template<typename Derived>
  11974. ExprResult
  11975. TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
  11976. // Transform each of the elements.
  11977. SmallVector<Expr *, 8> Elements;
  11978. bool ArgChanged = false;
  11979. if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
  11980. /*IsCall=*/false, Elements, &ArgChanged))
  11981. return ExprError();
  11982. if (!getDerived().AlwaysRebuild() && !ArgChanged)
  11983. return SemaRef.MaybeBindToTemporary(E);
  11984. return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
  11985. Elements.data(),
  11986. Elements.size());
  11987. }
  11988. template<typename Derived>
  11989. ExprResult
  11990. TreeTransform<Derived>::TransformObjCDictionaryLiteral(
  11991. ObjCDictionaryLiteral *E) {
  11992. // Transform each of the elements.
  11993. SmallVector<ObjCDictionaryElement, 8> Elements;
  11994. bool ArgChanged = false;
  11995. for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
  11996. ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
  11997. if (OrigElement.isPackExpansion()) {
  11998. // This key/value element is a pack expansion.
  11999. SmallVector<UnexpandedParameterPack, 2> Unexpanded;
  12000. getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
  12001. getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
  12002. assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
  12003. // Determine whether the set of unexpanded parameter packs can
  12004. // and should be expanded.
  12005. bool Expand = true;
  12006. bool RetainExpansion = false;
  12007. Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
  12008. Optional<unsigned> NumExpansions = OrigNumExpansions;
  12009. SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
  12010. OrigElement.Value->getEndLoc());
  12011. if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
  12012. PatternRange, Unexpanded, Expand,
  12013. RetainExpansion, NumExpansions))
  12014. return ExprError();
  12015. if (!Expand) {
  12016. // The transform has determined that we should perform a simple
  12017. // transformation on the pack expansion, producing another pack
  12018. // expansion.
  12019. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
  12020. ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
  12021. if (Key.isInvalid())
  12022. return ExprError();
  12023. if (Key.get() != OrigElement.Key)
  12024. ArgChanged = true;
  12025. ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
  12026. if (Value.isInvalid())
  12027. return ExprError();
  12028. if (Value.get() != OrigElement.Value)
  12029. ArgChanged = true;
  12030. ObjCDictionaryElement Expansion = {
  12031. Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
  12032. };
  12033. Elements.push_back(Expansion);
  12034. continue;
  12035. }
  12036. // Record right away that the argument was changed. This needs
  12037. // to happen even if the array expands to nothing.
  12038. ArgChanged = true;
  12039. // The transform has determined that we should perform an elementwise
  12040. // expansion of the pattern. Do so.
  12041. for (unsigned I = 0; I != *NumExpansions; ++I) {
  12042. Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
  12043. ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
  12044. if (Key.isInvalid())
  12045. return ExprError();
  12046. ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
  12047. if (Value.isInvalid())
  12048. return ExprError();
  12049. ObjCDictionaryElement Element = {
  12050. Key.get(), Value.get(), SourceLocation(), NumExpansions
  12051. };
  12052. // If any unexpanded parameter packs remain, we still have a
  12053. // pack expansion.
  12054. // FIXME: Can this really happen?
  12055. if (Key.get()->containsUnexpandedParameterPack() ||
  12056. Value.get()->containsUnexpandedParameterPack())
  12057. Element.EllipsisLoc = OrigElement.EllipsisLoc;
  12058. Elements.push_back(Element);
  12059. }
  12060. // FIXME: Retain a pack expansion if RetainExpansion is true.
  12061. // We've finished with this pack expansion.
  12062. continue;
  12063. }
  12064. // Transform and check key.
  12065. ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
  12066. if (Key.isInvalid())
  12067. return ExprError();
  12068. if (Key.get() != OrigElement.Key)
  12069. ArgChanged = true;
  12070. // Transform and check value.
  12071. ExprResult Value
  12072. = getDerived().TransformExpr(OrigElement.Value);
  12073. if (Value.isInvalid())
  12074. return ExprError();
  12075. if (Value.get() != OrigElement.Value)
  12076. ArgChanged = true;
  12077. ObjCDictionaryElement Element = {
  12078. Key.get(), Value.get(), SourceLocation(), None
  12079. };
  12080. Elements.push_back(Element);
  12081. }
  12082. if (!getDerived().AlwaysRebuild() && !ArgChanged)
  12083. return SemaRef.MaybeBindToTemporary(E);
  12084. return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
  12085. Elements);
  12086. }
  12087. template<typename Derived>
  12088. ExprResult
  12089. TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
  12090. TypeSourceInfo *EncodedTypeInfo
  12091. = getDerived().TransformType(E->getEncodedTypeSourceInfo());
  12092. if (!EncodedTypeInfo)
  12093. return ExprError();
  12094. if (!getDerived().AlwaysRebuild() &&
  12095. EncodedTypeInfo == E->getEncodedTypeSourceInfo())
  12096. return E;
  12097. return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
  12098. EncodedTypeInfo,
  12099. E->getRParenLoc());
  12100. }
  12101. template<typename Derived>
  12102. ExprResult TreeTransform<Derived>::
  12103. TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
  12104. // This is a kind of implicit conversion, and it needs to get dropped
  12105. // and recomputed for the same general reasons that ImplicitCastExprs
  12106. // do, as well a more specific one: this expression is only valid when
  12107. // it appears *immediately* as an argument expression.
  12108. return getDerived().TransformExpr(E->getSubExpr());
  12109. }
  12110. template<typename Derived>
  12111. ExprResult TreeTransform<Derived>::
  12112. TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
  12113. TypeSourceInfo *TSInfo
  12114. = getDerived().TransformType(E->getTypeInfoAsWritten());
  12115. if (!TSInfo)
  12116. return ExprError();
  12117. ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
  12118. if (Result.isInvalid())
  12119. return ExprError();
  12120. if (!getDerived().AlwaysRebuild() &&
  12121. TSInfo == E->getTypeInfoAsWritten() &&
  12122. Result.get() == E->getSubExpr())
  12123. return E;
  12124. return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
  12125. E->getBridgeKeywordLoc(), TSInfo,
  12126. Result.get());
  12127. }
  12128. template <typename Derived>
  12129. ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
  12130. ObjCAvailabilityCheckExpr *E) {
  12131. return E;
  12132. }
  12133. template<typename Derived>
  12134. ExprResult
  12135. TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
  12136. // Transform arguments.
  12137. bool ArgChanged = false;
  12138. SmallVector<Expr*, 8> Args;
  12139. Args.reserve(E->getNumArgs());
  12140. if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
  12141. &ArgChanged))
  12142. return ExprError();
  12143. if (E->getReceiverKind() == ObjCMessageExpr::Class) {
  12144. // Class message: transform the receiver type.
  12145. TypeSourceInfo *ReceiverTypeInfo
  12146. = getDerived().TransformType(E->getClassReceiverTypeInfo());
  12147. if (!ReceiverTypeInfo)
  12148. return ExprError();
  12149. // If nothing changed, just retain the existing message send.
  12150. if (!getDerived().AlwaysRebuild() &&
  12151. ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
  12152. return SemaRef.MaybeBindToTemporary(E);
  12153. // Build a new class message send.
  12154. SmallVector<SourceLocation, 16> SelLocs;
  12155. E->getSelectorLocs(SelLocs);
  12156. return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
  12157. E->getSelector(),
  12158. SelLocs,
  12159. E->getMethodDecl(),
  12160. E->getLeftLoc(),
  12161. Args,
  12162. E->getRightLoc());
  12163. }
  12164. else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
  12165. E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
  12166. if (!E->getMethodDecl())
  12167. return ExprError();
  12168. // Build a new class message send to 'super'.
  12169. SmallVector<SourceLocation, 16> SelLocs;
  12170. E->getSelectorLocs(SelLocs);
  12171. return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
  12172. E->getSelector(),
  12173. SelLocs,
  12174. E->getReceiverType(),
  12175. E->getMethodDecl(),
  12176. E->getLeftLoc(),
  12177. Args,
  12178. E->getRightLoc());
  12179. }
  12180. // Instance message: transform the receiver
  12181. assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
  12182. "Only class and instance messages may be instantiated");
  12183. ExprResult Receiver
  12184. = getDerived().TransformExpr(E->getInstanceReceiver());
  12185. if (Receiver.isInvalid())
  12186. return ExprError();
  12187. // If nothing changed, just retain the existing message send.
  12188. if (!getDerived().AlwaysRebuild() &&
  12189. Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
  12190. return SemaRef.MaybeBindToTemporary(E);
  12191. // Build a new instance message send.
  12192. SmallVector<SourceLocation, 16> SelLocs;
  12193. E->getSelectorLocs(SelLocs);
  12194. return getDerived().RebuildObjCMessageExpr(Receiver.get(),
  12195. E->getSelector(),
  12196. SelLocs,
  12197. E->getMethodDecl(),
  12198. E->getLeftLoc(),
  12199. Args,
  12200. E->getRightLoc());
  12201. }
  12202. template<typename Derived>
  12203. ExprResult
  12204. TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
  12205. return E;
  12206. }
  12207. template<typename Derived>
  12208. ExprResult
  12209. TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
  12210. return E;
  12211. }
  12212. template<typename Derived>
  12213. ExprResult
  12214. TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
  12215. // Transform the base expression.
  12216. ExprResult Base = getDerived().TransformExpr(E->getBase());
  12217. if (Base.isInvalid())
  12218. return ExprError();
  12219. // We don't need to transform the ivar; it will never change.
  12220. // If nothing changed, just retain the existing expression.
  12221. if (!getDerived().AlwaysRebuild() &&
  12222. Base.get() == E->getBase())
  12223. return E;
  12224. return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
  12225. E->getLocation(),
  12226. E->isArrow(), E->isFreeIvar());
  12227. }
  12228. template<typename Derived>
  12229. ExprResult
  12230. TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
  12231. // 'super' and types never change. Property never changes. Just
  12232. // retain the existing expression.
  12233. if (!E->isObjectReceiver())
  12234. return E;
  12235. // Transform the base expression.
  12236. ExprResult Base = getDerived().TransformExpr(E->getBase());
  12237. if (Base.isInvalid())
  12238. return ExprError();
  12239. // We don't need to transform the property; it will never change.
  12240. // If nothing changed, just retain the existing expression.
  12241. if (!getDerived().AlwaysRebuild() &&
  12242. Base.get() == E->getBase())
  12243. return E;
  12244. if (E->isExplicitProperty())
  12245. return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
  12246. E->getExplicitProperty(),
  12247. E->getLocation());
  12248. return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
  12249. SemaRef.Context.PseudoObjectTy,
  12250. E->getImplicitPropertyGetter(),
  12251. E->getImplicitPropertySetter(),
  12252. E->getLocation());
  12253. }
  12254. template<typename Derived>
  12255. ExprResult
  12256. TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
  12257. // Transform the base expression.
  12258. ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
  12259. if (Base.isInvalid())
  12260. return ExprError();
  12261. // Transform the key expression.
  12262. ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
  12263. if (Key.isInvalid())
  12264. return ExprError();
  12265. // If nothing changed, just retain the existing expression.
  12266. if (!getDerived().AlwaysRebuild() &&
  12267. Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
  12268. return E;
  12269. return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
  12270. Base.get(), Key.get(),
  12271. E->getAtIndexMethodDecl(),
  12272. E->setAtIndexMethodDecl());
  12273. }
  12274. template<typename Derived>
  12275. ExprResult
  12276. TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
  12277. // Transform the base expression.
  12278. ExprResult Base = getDerived().TransformExpr(E->getBase());
  12279. if (Base.isInvalid())
  12280. return ExprError();
  12281. // If nothing changed, just retain the existing expression.
  12282. if (!getDerived().AlwaysRebuild() &&
  12283. Base.get() == E->getBase())
  12284. return E;
  12285. return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
  12286. E->getOpLoc(),
  12287. E->isArrow());
  12288. }
  12289. template<typename Derived>
  12290. ExprResult
  12291. TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
  12292. bool ArgumentChanged = false;
  12293. SmallVector<Expr*, 8> SubExprs;
  12294. SubExprs.reserve(E->getNumSubExprs());
  12295. if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
  12296. SubExprs, &ArgumentChanged))
  12297. return ExprError();
  12298. if (!getDerived().AlwaysRebuild() &&
  12299. !ArgumentChanged)
  12300. return E;
  12301. return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
  12302. SubExprs,
  12303. E->getRParenLoc());
  12304. }
  12305. template<typename Derived>
  12306. ExprResult
  12307. TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
  12308. ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
  12309. if (SrcExpr.isInvalid())
  12310. return ExprError();
  12311. TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
  12312. if (!Type)
  12313. return ExprError();
  12314. if (!getDerived().AlwaysRebuild() &&
  12315. Type == E->getTypeSourceInfo() &&
  12316. SrcExpr.get() == E->getSrcExpr())
  12317. return E;
  12318. return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
  12319. SrcExpr.get(), Type,
  12320. E->getRParenLoc());
  12321. }
  12322. template<typename Derived>
  12323. ExprResult
  12324. TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
  12325. BlockDecl *oldBlock = E->getBlockDecl();
  12326. SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
  12327. BlockScopeInfo *blockScope = SemaRef.getCurBlock();
  12328. blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
  12329. blockScope->TheDecl->setBlockMissingReturnType(
  12330. oldBlock->blockMissingReturnType());
  12331. SmallVector<ParmVarDecl*, 4> params;
  12332. SmallVector<QualType, 4> paramTypes;
  12333. const FunctionProtoType *exprFunctionType = E->getFunctionType();
  12334. // Parameter substitution.
  12335. Sema::ExtParameterInfoBuilder extParamInfos;
  12336. if (getDerived().TransformFunctionTypeParams(
  12337. E->getCaretLocation(), oldBlock->parameters(), nullptr,
  12338. exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
  12339. extParamInfos)) {
  12340. getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
  12341. return ExprError();
  12342. }
  12343. QualType exprResultType =
  12344. getDerived().TransformType(exprFunctionType->getReturnType());
  12345. auto epi = exprFunctionType->getExtProtoInfo();
  12346. epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
  12347. QualType functionType =
  12348. getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
  12349. blockScope->FunctionType = functionType;
  12350. // Set the parameters on the block decl.
  12351. if (!params.empty())
  12352. blockScope->TheDecl->setParams(params);
  12353. if (!oldBlock->blockMissingReturnType()) {
  12354. blockScope->HasImplicitReturnType = false;
  12355. blockScope->ReturnType = exprResultType;
  12356. }
  12357. // Transform the body
  12358. StmtResult body = getDerived().TransformStmt(E->getBody());
  12359. if (body.isInvalid()) {
  12360. getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
  12361. return ExprError();
  12362. }
  12363. #ifndef NDEBUG
  12364. // In builds with assertions, make sure that we captured everything we
  12365. // captured before.
  12366. if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
  12367. for (const auto &I : oldBlock->captures()) {
  12368. VarDecl *oldCapture = I.getVariable();
  12369. // Ignore parameter packs.
  12370. if (oldCapture->isParameterPack())
  12371. continue;
  12372. VarDecl *newCapture =
  12373. cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
  12374. oldCapture));
  12375. assert(blockScope->CaptureMap.count(newCapture));
  12376. }
  12377. assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
  12378. }
  12379. #endif
  12380. return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
  12381. /*Scope=*/nullptr);
  12382. }
  12383. template<typename Derived>
  12384. ExprResult
  12385. TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
  12386. ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
  12387. if (SrcExpr.isInvalid())
  12388. return ExprError();
  12389. QualType Type = getDerived().TransformType(E->getType());
  12390. return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
  12391. E->getRParenLoc());
  12392. }
  12393. template<typename Derived>
  12394. ExprResult
  12395. TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
  12396. bool ArgumentChanged = false;
  12397. SmallVector<Expr*, 8> SubExprs;
  12398. SubExprs.reserve(E->getNumSubExprs());
  12399. if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
  12400. SubExprs, &ArgumentChanged))
  12401. return ExprError();
  12402. if (!getDerived().AlwaysRebuild() &&
  12403. !ArgumentChanged)
  12404. return E;
  12405. return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
  12406. E->getOp(), E->getRParenLoc());
  12407. }
  12408. //===----------------------------------------------------------------------===//
  12409. // Type reconstruction
  12410. //===----------------------------------------------------------------------===//
  12411. template<typename Derived>
  12412. QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
  12413. SourceLocation Star) {
  12414. return SemaRef.BuildPointerType(PointeeType, Star,
  12415. getDerived().getBaseEntity());
  12416. }
  12417. template<typename Derived>
  12418. QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
  12419. SourceLocation Star) {
  12420. return SemaRef.BuildBlockPointerType(PointeeType, Star,
  12421. getDerived().getBaseEntity());
  12422. }
  12423. template<typename Derived>
  12424. QualType
  12425. TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
  12426. bool WrittenAsLValue,
  12427. SourceLocation Sigil) {
  12428. return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
  12429. Sigil, getDerived().getBaseEntity());
  12430. }
  12431. template<typename Derived>
  12432. QualType
  12433. TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
  12434. QualType ClassType,
  12435. SourceLocation Sigil) {
  12436. return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
  12437. getDerived().getBaseEntity());
  12438. }
  12439. template<typename Derived>
  12440. QualType TreeTransform<Derived>::RebuildObjCTypeParamType(
  12441. const ObjCTypeParamDecl *Decl,
  12442. SourceLocation ProtocolLAngleLoc,
  12443. ArrayRef<ObjCProtocolDecl *> Protocols,
  12444. ArrayRef<SourceLocation> ProtocolLocs,
  12445. SourceLocation ProtocolRAngleLoc) {
  12446. return SemaRef.BuildObjCTypeParamType(Decl,
  12447. ProtocolLAngleLoc, Protocols,
  12448. ProtocolLocs, ProtocolRAngleLoc,
  12449. /*FailOnError=*/true);
  12450. }
  12451. template<typename Derived>
  12452. QualType TreeTransform<Derived>::RebuildObjCObjectType(
  12453. QualType BaseType,
  12454. SourceLocation Loc,
  12455. SourceLocation TypeArgsLAngleLoc,
  12456. ArrayRef<TypeSourceInfo *> TypeArgs,
  12457. SourceLocation TypeArgsRAngleLoc,
  12458. SourceLocation ProtocolLAngleLoc,
  12459. ArrayRef<ObjCProtocolDecl *> Protocols,
  12460. ArrayRef<SourceLocation> ProtocolLocs,
  12461. SourceLocation ProtocolRAngleLoc) {
  12462. return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
  12463. TypeArgs, TypeArgsRAngleLoc,
  12464. ProtocolLAngleLoc, Protocols, ProtocolLocs,
  12465. ProtocolRAngleLoc,
  12466. /*FailOnError=*/true);
  12467. }
  12468. template<typename Derived>
  12469. QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
  12470. QualType PointeeType,
  12471. SourceLocation Star) {
  12472. return SemaRef.Context.getObjCObjectPointerType(PointeeType);
  12473. }
  12474. template<typename Derived>
  12475. QualType
  12476. TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
  12477. ArrayType::ArraySizeModifier SizeMod,
  12478. const llvm::APInt *Size,
  12479. Expr *SizeExpr,
  12480. unsigned IndexTypeQuals,
  12481. SourceRange BracketsRange) {
  12482. if (SizeExpr || !Size)
  12483. return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
  12484. IndexTypeQuals, BracketsRange,
  12485. getDerived().getBaseEntity());
  12486. QualType Types[] = {
  12487. SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
  12488. SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
  12489. SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
  12490. };
  12491. const unsigned NumTypes = llvm::array_lengthof(Types);
  12492. QualType SizeType;
  12493. for (unsigned I = 0; I != NumTypes; ++I)
  12494. if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
  12495. SizeType = Types[I];
  12496. break;
  12497. }
  12498. // Note that we can return a VariableArrayType here in the case where
  12499. // the element type was a dependent VariableArrayType.
  12500. IntegerLiteral *ArraySize
  12501. = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
  12502. /*FIXME*/BracketsRange.getBegin());
  12503. return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
  12504. IndexTypeQuals, BracketsRange,
  12505. getDerived().getBaseEntity());
  12506. }
  12507. template<typename Derived>
  12508. QualType
  12509. TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
  12510. ArrayType::ArraySizeModifier SizeMod,
  12511. const llvm::APInt &Size,
  12512. Expr *SizeExpr,
  12513. unsigned IndexTypeQuals,
  12514. SourceRange BracketsRange) {
  12515. return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
  12516. IndexTypeQuals, BracketsRange);
  12517. }
  12518. template<typename Derived>
  12519. QualType
  12520. TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
  12521. ArrayType::ArraySizeModifier SizeMod,
  12522. unsigned IndexTypeQuals,
  12523. SourceRange BracketsRange) {
  12524. return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
  12525. IndexTypeQuals, BracketsRange);
  12526. }
  12527. template<typename Derived>
  12528. QualType
  12529. TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
  12530. ArrayType::ArraySizeModifier SizeMod,
  12531. Expr *SizeExpr,
  12532. unsigned IndexTypeQuals,
  12533. SourceRange BracketsRange) {
  12534. return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
  12535. SizeExpr,
  12536. IndexTypeQuals, BracketsRange);
  12537. }
  12538. template<typename Derived>
  12539. QualType
  12540. TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
  12541. ArrayType::ArraySizeModifier SizeMod,
  12542. Expr *SizeExpr,
  12543. unsigned IndexTypeQuals,
  12544. SourceRange BracketsRange) {
  12545. return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
  12546. SizeExpr,
  12547. IndexTypeQuals, BracketsRange);
  12548. }
  12549. template <typename Derived>
  12550. QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType(
  12551. QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
  12552. return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
  12553. AttributeLoc);
  12554. }
  12555. template <typename Derived>
  12556. QualType
  12557. TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
  12558. unsigned NumElements,
  12559. VectorType::VectorKind VecKind) {
  12560. // FIXME: semantic checking!
  12561. return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
  12562. }
  12563. template <typename Derived>
  12564. QualType TreeTransform<Derived>::RebuildDependentVectorType(
  12565. QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
  12566. VectorType::VectorKind VecKind) {
  12567. return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
  12568. }
  12569. template<typename Derived>
  12570. QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
  12571. unsigned NumElements,
  12572. SourceLocation AttributeLoc) {
  12573. llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
  12574. NumElements, true);
  12575. IntegerLiteral *VectorSize
  12576. = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
  12577. AttributeLoc);
  12578. return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
  12579. }
  12580. template<typename Derived>
  12581. QualType
  12582. TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
  12583. Expr *SizeExpr,
  12584. SourceLocation AttributeLoc) {
  12585. return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
  12586. }
  12587. template <typename Derived>
  12588. QualType TreeTransform<Derived>::RebuildConstantMatrixType(
  12589. QualType ElementType, unsigned NumRows, unsigned NumColumns) {
  12590. return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
  12591. NumColumns);
  12592. }
  12593. template <typename Derived>
  12594. QualType TreeTransform<Derived>::RebuildDependentSizedMatrixType(
  12595. QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
  12596. SourceLocation AttributeLoc) {
  12597. return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
  12598. AttributeLoc);
  12599. }
  12600. template<typename Derived>
  12601. QualType TreeTransform<Derived>::RebuildFunctionProtoType(
  12602. QualType T,
  12603. MutableArrayRef<QualType> ParamTypes,
  12604. const FunctionProtoType::ExtProtoInfo &EPI) {
  12605. return SemaRef.BuildFunctionType(T, ParamTypes,
  12606. getDerived().getBaseLocation(),
  12607. getDerived().getBaseEntity(),
  12608. EPI);
  12609. }
  12610. template<typename Derived>
  12611. QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
  12612. return SemaRef.Context.getFunctionNoProtoType(T);
  12613. }
  12614. template<typename Derived>
  12615. QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc,
  12616. Decl *D) {
  12617. assert(D && "no decl found");
  12618. if (D->isInvalidDecl()) return QualType();
  12619. // FIXME: Doesn't account for ObjCInterfaceDecl!
  12620. if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
  12621. // A valid resolved using typename pack expansion decl can have multiple
  12622. // UsingDecls, but they must each have exactly one type, and it must be
  12623. // the same type in every case. But we must have at least one expansion!
  12624. if (UPD->expansions().empty()) {
  12625. getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
  12626. << UPD->isCXXClassMember() << UPD;
  12627. return QualType();
  12628. }
  12629. // We might still have some unresolved types. Try to pick a resolved type
  12630. // if we can. The final instantiation will check that the remaining
  12631. // unresolved types instantiate to the type we pick.
  12632. QualType FallbackT;
  12633. QualType T;
  12634. for (auto *E : UPD->expansions()) {
  12635. QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
  12636. if (ThisT.isNull())
  12637. continue;
  12638. else if (ThisT->getAs<UnresolvedUsingType>())
  12639. FallbackT = ThisT;
  12640. else if (T.isNull())
  12641. T = ThisT;
  12642. else
  12643. assert(getSema().Context.hasSameType(ThisT, T) &&
  12644. "mismatched resolved types in using pack expansion");
  12645. }
  12646. return T.isNull() ? FallbackT : T;
  12647. } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
  12648. assert(Using->hasTypename() &&
  12649. "UnresolvedUsingTypenameDecl transformed to non-typename using");
  12650. // A valid resolved using typename decl points to exactly one type decl.
  12651. assert(++Using->shadow_begin() == Using->shadow_end());
  12652. UsingShadowDecl *Shadow = *Using->shadow_begin();
  12653. if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc))
  12654. return QualType();
  12655. return SemaRef.Context.getUsingType(
  12656. Shadow, SemaRef.Context.getTypeDeclType(
  12657. cast<TypeDecl>(Shadow->getTargetDecl())));
  12658. } else {
  12659. assert(isa<UnresolvedUsingTypenameDecl>(D) &&
  12660. "UnresolvedUsingTypenameDecl transformed to non-using decl");
  12661. return SemaRef.Context.getTypeDeclType(
  12662. cast<UnresolvedUsingTypenameDecl>(D));
  12663. }
  12664. }
  12665. template <typename Derived>
  12666. QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
  12667. SourceLocation) {
  12668. return SemaRef.BuildTypeofExprType(E);
  12669. }
  12670. template<typename Derived>
  12671. QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
  12672. return SemaRef.Context.getTypeOfType(Underlying);
  12673. }
  12674. template <typename Derived>
  12675. QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, SourceLocation) {
  12676. return SemaRef.BuildDecltypeType(E);
  12677. }
  12678. template<typename Derived>
  12679. QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
  12680. UnaryTransformType::UTTKind UKind,
  12681. SourceLocation Loc) {
  12682. return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
  12683. }
  12684. template<typename Derived>
  12685. QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
  12686. TemplateName Template,
  12687. SourceLocation TemplateNameLoc,
  12688. TemplateArgumentListInfo &TemplateArgs) {
  12689. return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
  12690. }
  12691. template<typename Derived>
  12692. QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
  12693. SourceLocation KWLoc) {
  12694. return SemaRef.BuildAtomicType(ValueType, KWLoc);
  12695. }
  12696. template<typename Derived>
  12697. QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType,
  12698. SourceLocation KWLoc,
  12699. bool isReadPipe) {
  12700. return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
  12701. : SemaRef.BuildWritePipeType(ValueType, KWLoc);
  12702. }
  12703. template <typename Derived>
  12704. QualType TreeTransform<Derived>::RebuildBitIntType(bool IsUnsigned,
  12705. unsigned NumBits,
  12706. SourceLocation Loc) {
  12707. llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
  12708. NumBits, true);
  12709. IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
  12710. SemaRef.Context.IntTy, Loc);
  12711. return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
  12712. }
  12713. template <typename Derived>
  12714. QualType TreeTransform<Derived>::RebuildDependentBitIntType(
  12715. bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
  12716. return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
  12717. }
  12718. template<typename Derived>
  12719. TemplateName
  12720. TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
  12721. bool TemplateKW,
  12722. TemplateDecl *Template) {
  12723. return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
  12724. Template);
  12725. }
  12726. template<typename Derived>
  12727. TemplateName
  12728. TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
  12729. SourceLocation TemplateKWLoc,
  12730. const IdentifierInfo &Name,
  12731. SourceLocation NameLoc,
  12732. QualType ObjectType,
  12733. NamedDecl *FirstQualifierInScope,
  12734. bool AllowInjectedClassName) {
  12735. UnqualifiedId TemplateName;
  12736. TemplateName.setIdentifier(&Name, NameLoc);
  12737. Sema::TemplateTy Template;
  12738. getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
  12739. TemplateName, ParsedType::make(ObjectType),
  12740. /*EnteringContext=*/false, Template,
  12741. AllowInjectedClassName);
  12742. return Template.get();
  12743. }
  12744. template<typename Derived>
  12745. TemplateName
  12746. TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
  12747. SourceLocation TemplateKWLoc,
  12748. OverloadedOperatorKind Operator,
  12749. SourceLocation NameLoc,
  12750. QualType ObjectType,
  12751. bool AllowInjectedClassName) {
  12752. UnqualifiedId Name;
  12753. // FIXME: Bogus location information.
  12754. SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
  12755. Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
  12756. Sema::TemplateTy Template;
  12757. getSema().ActOnTemplateName(
  12758. /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
  12759. /*EnteringContext=*/false, Template, AllowInjectedClassName);
  12760. return Template.get();
  12761. }
  12762. template<typename Derived>
  12763. ExprResult
  12764. TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
  12765. SourceLocation OpLoc,
  12766. Expr *OrigCallee,
  12767. Expr *First,
  12768. Expr *Second) {
  12769. Expr *Callee = OrigCallee->IgnoreParenCasts();
  12770. bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
  12771. if (First->getObjectKind() == OK_ObjCProperty) {
  12772. BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
  12773. if (BinaryOperator::isAssignmentOp(Opc))
  12774. return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
  12775. First, Second);
  12776. ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
  12777. if (Result.isInvalid())
  12778. return ExprError();
  12779. First = Result.get();
  12780. }
  12781. if (Second && Second->getObjectKind() == OK_ObjCProperty) {
  12782. ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
  12783. if (Result.isInvalid())
  12784. return ExprError();
  12785. Second = Result.get();
  12786. }
  12787. // Determine whether this should be a builtin operation.
  12788. if (Op == OO_Subscript) {
  12789. if (!First->getType()->isOverloadableType() &&
  12790. !Second->getType()->isOverloadableType())
  12791. return getSema().CreateBuiltinArraySubscriptExpr(
  12792. First, Callee->getBeginLoc(), Second, OpLoc);
  12793. } else if (Op == OO_Arrow) {
  12794. // -> is never a builtin operation.
  12795. return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
  12796. } else if (Second == nullptr || isPostIncDec) {
  12797. if (!First->getType()->isOverloadableType() ||
  12798. (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
  12799. // The argument is not of overloadable type, or this is an expression
  12800. // of the form &Class::member, so try to create a built-in unary
  12801. // operation.
  12802. UnaryOperatorKind Opc
  12803. = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
  12804. return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
  12805. }
  12806. } else {
  12807. if (!First->getType()->isOverloadableType() &&
  12808. !Second->getType()->isOverloadableType()) {
  12809. // Neither of the arguments is an overloadable type, so try to
  12810. // create a built-in binary operation.
  12811. BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
  12812. ExprResult Result
  12813. = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
  12814. if (Result.isInvalid())
  12815. return ExprError();
  12816. return Result;
  12817. }
  12818. }
  12819. // Compute the transformed set of functions (and function templates) to be
  12820. // used during overload resolution.
  12821. UnresolvedSet<16> Functions;
  12822. bool RequiresADL;
  12823. if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
  12824. Functions.append(ULE->decls_begin(), ULE->decls_end());
  12825. // If the overload could not be resolved in the template definition
  12826. // (because we had a dependent argument), ADL is performed as part of
  12827. // template instantiation.
  12828. RequiresADL = ULE->requiresADL();
  12829. } else {
  12830. // If we've resolved this to a particular non-member function, just call
  12831. // that function. If we resolved it to a member function,
  12832. // CreateOverloaded* will find that function for us.
  12833. NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
  12834. if (!isa<CXXMethodDecl>(ND))
  12835. Functions.addDecl(ND);
  12836. RequiresADL = false;
  12837. }
  12838. // Add any functions found via argument-dependent lookup.
  12839. Expr *Args[2] = { First, Second };
  12840. unsigned NumArgs = 1 + (Second != nullptr);
  12841. // Create the overloaded operator invocation for unary operators.
  12842. if (NumArgs == 1 || isPostIncDec) {
  12843. UnaryOperatorKind Opc
  12844. = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
  12845. return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
  12846. RequiresADL);
  12847. }
  12848. if (Op == OO_Subscript) {
  12849. SourceLocation LBrace;
  12850. SourceLocation RBrace;
  12851. if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
  12852. DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
  12853. LBrace = NameLoc.getCXXOperatorNameBeginLoc();
  12854. RBrace = NameLoc.getCXXOperatorNameEndLoc();
  12855. } else {
  12856. LBrace = Callee->getBeginLoc();
  12857. RBrace = OpLoc;
  12858. }
  12859. return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
  12860. First, Second);
  12861. }
  12862. // Create the overloaded operator invocation for binary operators.
  12863. BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
  12864. ExprResult Result = SemaRef.CreateOverloadedBinOp(
  12865. OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
  12866. if (Result.isInvalid())
  12867. return ExprError();
  12868. return Result;
  12869. }
  12870. template<typename Derived>
  12871. ExprResult
  12872. TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
  12873. SourceLocation OperatorLoc,
  12874. bool isArrow,
  12875. CXXScopeSpec &SS,
  12876. TypeSourceInfo *ScopeType,
  12877. SourceLocation CCLoc,
  12878. SourceLocation TildeLoc,
  12879. PseudoDestructorTypeStorage Destroyed) {
  12880. QualType BaseType = Base->getType();
  12881. if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
  12882. (!isArrow && !BaseType->getAs<RecordType>()) ||
  12883. (isArrow && BaseType->getAs<PointerType>() &&
  12884. !BaseType->castAs<PointerType>()->getPointeeType()
  12885. ->template getAs<RecordType>())){
  12886. // This pseudo-destructor expression is still a pseudo-destructor.
  12887. return SemaRef.BuildPseudoDestructorExpr(
  12888. Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
  12889. CCLoc, TildeLoc, Destroyed);
  12890. }
  12891. TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
  12892. DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
  12893. SemaRef.Context.getCanonicalType(DestroyedType->getType())));
  12894. DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
  12895. NameInfo.setNamedTypeInfo(DestroyedType);
  12896. // The scope type is now known to be a valid nested name specifier
  12897. // component. Tack it on to the end of the nested name specifier.
  12898. if (ScopeType) {
  12899. if (!ScopeType->getType()->getAs<TagType>()) {
  12900. getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
  12901. diag::err_expected_class_or_namespace)
  12902. << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
  12903. return ExprError();
  12904. }
  12905. SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
  12906. CCLoc);
  12907. }
  12908. SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
  12909. return getSema().BuildMemberReferenceExpr(Base, BaseType,
  12910. OperatorLoc, isArrow,
  12911. SS, TemplateKWLoc,
  12912. /*FIXME: FirstQualifier*/ nullptr,
  12913. NameInfo,
  12914. /*TemplateArgs*/ nullptr,
  12915. /*S*/nullptr);
  12916. }
  12917. template<typename Derived>
  12918. StmtResult
  12919. TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
  12920. SourceLocation Loc = S->getBeginLoc();
  12921. CapturedDecl *CD = S->getCapturedDecl();
  12922. unsigned NumParams = CD->getNumParams();
  12923. unsigned ContextParamPos = CD->getContextParamPosition();
  12924. SmallVector<Sema::CapturedParamNameType, 4> Params;
  12925. for (unsigned I = 0; I < NumParams; ++I) {
  12926. if (I != ContextParamPos) {
  12927. Params.push_back(
  12928. std::make_pair(
  12929. CD->getParam(I)->getName(),
  12930. getDerived().TransformType(CD->getParam(I)->getType())));
  12931. } else {
  12932. Params.push_back(std::make_pair(StringRef(), QualType()));
  12933. }
  12934. }
  12935. getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
  12936. S->getCapturedRegionKind(), Params);
  12937. StmtResult Body;
  12938. {
  12939. Sema::CompoundScopeRAII CompoundScope(getSema());
  12940. Body = getDerived().TransformStmt(S->getCapturedStmt());
  12941. }
  12942. if (Body.isInvalid()) {
  12943. getSema().ActOnCapturedRegionError();
  12944. return StmtError();
  12945. }
  12946. return getSema().ActOnCapturedRegionEnd(Body.get());
  12947. }
  12948. } // end namespace clang
  12949. #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H