symdef.pas 313 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332
  1. {
  2. Symbol table implementation for the definitions
  3. Copyright (c) 1998-2005 by Florian Klaempfl, Pierre Muller
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symdef;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,widestr,
  23. { global }
  24. globtype,globals,tokens,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { node }
  28. node,
  29. { aasm }
  30. aasmtai,
  31. cpuinfo,
  32. cgbase,
  33. parabase
  34. ;
  35. type
  36. {************************************************
  37. TDef
  38. ************************************************}
  39. tgenericconstraintdata=class
  40. interfaces : tfpobjectlist;
  41. interfacesderef : tfplist;
  42. flags : tgenericconstraintflags;
  43. { only required while parsing }
  44. fileinfo : tfileposinfo;
  45. constructor create;
  46. destructor destroy;override;
  47. procedure ppuload(ppufile:tcompilerppufile);
  48. procedure ppuwrite(ppufile:tcompilerppufile);
  49. procedure buildderef;
  50. procedure deref;
  51. end;
  52. { trtti_attribute_list }
  53. trtti_attribute = class
  54. typesym : tsym;
  55. typesymderef : tderef;
  56. typeconstr : tdef;
  57. typeconstrderef : tderef;
  58. { these two are not stored in PPU }
  59. constructorcall : tnode;
  60. constructorpd : tdef;
  61. paras : array of tnode;
  62. constructor ppuload(ppufile:tcompilerppufile);
  63. procedure ppuwrite(ppufile:tcompilerppufile);
  64. procedure ppuload_subentries(ppufile:tcompilerppufile);
  65. procedure ppuwrite_subentries(ppufile:tcompilerppufile);
  66. destructor destroy;override;
  67. procedure buildderef;
  68. procedure deref;
  69. end;
  70. trtti_attribute_list = class
  71. rtti_attributes : TFPObjectList;
  72. { if the attribute list is bound to a def or symbol }
  73. is_bound : Boolean;
  74. class procedure bind(var dangling,owned:trtti_attribute_list);
  75. procedure addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  76. procedure addattribute(attr:trtti_attribute);
  77. destructor destroy; override;
  78. function get_attribute_count:longint;
  79. procedure buildderef;
  80. procedure deref;
  81. class function ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  82. class procedure ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  83. class procedure ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  84. class procedure ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  85. end;
  86. { tstoreddef }
  87. tstoreddef = class(tdef)
  88. private
  89. {$ifdef symansistr}
  90. _fullownerhierarchyname : ansistring;
  91. {$else symansistr}
  92. _fullownerhierarchyname : pshortstring;
  93. {$endif symansistr}
  94. procedure writeentry(ppufile: tcompilerppufile; ibnr: byte);
  95. protected
  96. typesymderef : tderef;
  97. procedure ppuwrite_platform(ppufile:tcompilerppufile);virtual;
  98. procedure ppuload_platform(ppufile:tcompilerppufile);virtual;
  99. { a (possibly) reusable def is always created on the basis of another
  100. def, and contains a reference to this other def. If this other
  101. def is in a non-persistent symboltable, the new def cannot actually
  102. be safely reused everywhere in the current module. This routine
  103. abtracts that checking, and also restores the symtable stack
  104. (which had to be reset before creating the new def, so that the new
  105. def did not automatically get added to its top) }
  106. class procedure setup_reusable_def(origdef, newdef: tdef; res: PHashSetItem; oldsymtablestack: tsymtablestack);
  107. public
  108. {$ifdef EXTDEBUG}
  109. fileinfo : tfileposinfo;
  110. {$endif}
  111. { generic support }
  112. genericdef : tstoreddef;
  113. genericdefderef : tderef;
  114. generictokenbuf : tdynamicarray;
  115. { this list contains references to the symbols that make up the
  116. generic parameters; the symbols are not owned by this list
  117. Note: this list is allocated on demand! }
  118. genericparas : tfphashobjectlist;
  119. genericparaderefs : tfplist;
  120. { contains additional data if this def is a generic constraint
  121. Note: this class is allocated on demand! }
  122. genconstraintdata : tgenericconstraintdata;
  123. { this is Nil if the def has no RTTI attributes }
  124. rtti_attribute_list : trtti_attribute_list;
  125. constructor create(dt:tdeftyp;doregister:boolean);
  126. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  127. destructor destroy;override;
  128. function getcopy : tstoreddef;virtual;
  129. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  130. { this is called directly after ppuload }
  131. procedure ppuload_subentries(ppufile:tcompilerppufile);virtual;
  132. { this is called directly after ppuwrite }
  133. procedure ppuwrite_subentries(ppufile:tcompilerppufile);virtual;
  134. procedure buildderef;override;
  135. procedure buildderefimpl;override;
  136. procedure deref;override;
  137. procedure derefimpl;override;
  138. function size:asizeint;override;
  139. function getvardef:longint;override;
  140. function alignment:shortint;override;
  141. function is_publishable : boolean;override;
  142. function needs_inittable : boolean;override;
  143. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  144. function rtti_mangledname(rt:trttitype):TSymStr;override;
  145. function OwnerHierarchyName: string; override;
  146. function fullownerhierarchyname(skipprocparams:boolean):TSymStr;override;
  147. function needs_separate_initrtti:boolean;override;
  148. function in_currentunit: boolean;
  149. { regvars }
  150. function is_intregable : boolean;
  151. function is_fpuregable : boolean;
  152. { def can be put into a register if it is const/immutable }
  153. function is_const_intregable : boolean;
  154. { generics }
  155. procedure initgeneric;
  156. { this function can be used to determine whether a def is really a
  157. generic declaration or just a normal type declared inside another
  158. generic }
  159. function is_generic:boolean;
  160. { same as above for specializations }
  161. function is_specialization:boolean;
  162. { generic utilities }
  163. function is_generic_param_const(index:integer):boolean;inline;
  164. function get_generic_param_def(index:integer):tdef;inline;
  165. { registers this def in the unit's deflist; no-op if already registered }
  166. procedure register_def; override;
  167. { add the def to the top of the symtable stack if it's not yet owned
  168. by another symtable }
  169. procedure maybe_put_in_symtable_stack;
  170. private
  171. savesize : asizeuint;
  172. end;
  173. tfiletyp = (ft_text,ft_typed,ft_untyped);
  174. tfiledef = class(tstoreddef)
  175. filetyp : tfiletyp;
  176. typedfiledef : tdef;
  177. typedfiledefderef : tderef;
  178. constructor createtext;virtual;
  179. constructor createuntyped;virtual;
  180. constructor createtyped(def : tdef);virtual;
  181. constructor ppuload(ppufile:tcompilerppufile);
  182. function getcopy : tstoreddef;override;
  183. { do not override this routine in platform-specific subclasses,
  184. override ppuwrite_platform instead }
  185. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  186. procedure buildderef;override;
  187. procedure deref;override;
  188. function GetTypeName:string;override;
  189. function getmangledparaname:TSymStr;override;
  190. function size:asizeint;override;
  191. procedure setsize;
  192. function alignment: shortint; override;
  193. end;
  194. tfiledefclass = class of tfiledef;
  195. tvariantdef = class(tstoreddef)
  196. varianttype : tvarianttype;
  197. constructor create(v : tvarianttype);virtual;
  198. constructor ppuload(ppufile:tcompilerppufile);
  199. function getcopy : tstoreddef;override;
  200. function GetTypeName:string;override;
  201. function alignment : shortint;override;
  202. { do not override this routine in platform-specific subclasses,
  203. override ppuwrite_platform instead }
  204. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  205. function getvardef:longint;override;
  206. procedure setsize;
  207. function is_publishable : boolean;override;
  208. function needs_inittable : boolean;override;
  209. end;
  210. tvariantdefclass = class of tvariantdef;
  211. tformaldef = class(tstoreddef)
  212. typed:boolean;
  213. constructor create(Atyped:boolean);virtual;
  214. constructor ppuload(ppufile:tcompilerppufile);
  215. { do not override this routine in platform-specific subclasses,
  216. override ppuwrite_platform instead }
  217. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  218. function GetTypeName:string;override;
  219. end;
  220. tformaldefclass = class of tformaldef;
  221. tforwarddef = class(tstoreddef)
  222. tosymname : pshortstring;
  223. forwardpos : tfileposinfo;
  224. constructor create(const s:string;const pos:tfileposinfo);virtual;
  225. destructor destroy;override;
  226. function getcopy:tstoreddef;override;
  227. function GetTypeName:string;override;
  228. end;
  229. tforwarddefclass = class of tforwarddef;
  230. tundefineddef = class(tstoreddef)
  231. constructor create(doregister:boolean);virtual;
  232. constructor ppuload(ppufile:tcompilerppufile);
  233. { do not override this routine in platform-specific subclasses,
  234. override ppuwrite_platform instead }
  235. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  236. function GetTypeName:string;override;
  237. end;
  238. tundefineddefclass = class of tundefineddef;
  239. terrordef = class(tstoreddef)
  240. constructor create;virtual;
  241. { do not override this routine in platform-specific subclasses,
  242. override ppuwrite_platform instead }
  243. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  244. function GetTypeName:string;override;
  245. function getmangledparaname : TSymStr;override;
  246. end;
  247. terrordefclass = class of terrordef;
  248. tabstractpointerdef = class(tstoreddef)
  249. pointeddef : tdef;
  250. pointeddefderef : tderef;
  251. constructor create(dt:tdeftyp;def:tdef);
  252. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  253. procedure ppuwrite(ppufile:tcompilerppufile);override;
  254. procedure buildderef;override;
  255. procedure deref;override;
  256. function size:asizeint;override;
  257. function alignment:shortint;override;
  258. end;
  259. tpointerdef = class(tabstractpointerdef)
  260. has_pointer_math : boolean;
  261. constructor create(def:tdef);virtual;
  262. { returns a pointerdef for def, reusing an existing one in case it
  263. exists in the current module }
  264. class function getreusable(def: tdef): tpointerdef; virtual;
  265. { same as above, but in case the def must never be freed after the
  266. current module has been compiled -- even if the def was not written
  267. to the ppu file (for defs in para locations, as we don't reset them
  268. so we don't have to recalculate them all the time) }
  269. class function getreusable_no_free(def: tdef): tpointerdef;
  270. function size:asizeint;override;
  271. function getcopy:tstoreddef;override;
  272. constructor ppuload(ppufile:tcompilerppufile);
  273. { do not override this routine in platform-specific subclasses,
  274. override ppuwrite_platform instead }
  275. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  276. function GetTypeName:string;override;
  277. {# returns the appropriate int type for pointer arithmetic with the given pointer type.
  278. When adding or subtracting a number to/from a pointer, this function returns the
  279. int type to which that number has to be converted, before the operation can be performed.
  280. Normally, this is sinttype, except on i8086, where it takes into account the
  281. special i8086 pointer types (near, far, huge). }
  282. function pointer_arithmetic_int_type:tdef;virtual;
  283. {# the unsigned version of pointer_arithmetic_int_type. Used with inc/dec. }
  284. function pointer_arithmetic_uint_type:tdef;virtual;
  285. {# returns the int type produced when subtracting two pointers of the given type.
  286. Normally, this is sinttype, except on i8086, where it takes into account the
  287. special i8086 pointer types (near, far, huge). }
  288. function pointer_subtraction_result_type:tdef;virtual;
  289. function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual;
  290. {# the integer index type used to convert the pointer to array (i.e. denotes int_type in: ptr[int_type]) }
  291. function converted_pointer_to_array_range_type:tdef;virtual;
  292. end;
  293. tpointerdefclass = class of tpointerdef;
  294. tprocdef = class;
  295. tabstractrecorddef= class(tstoreddef)
  296. private
  297. rttistring : string;
  298. {$ifdef DEBUG_NODE_XML}
  299. protected
  300. procedure XMLPrintDefData(var T: Text; Sym: TSym); override;
  301. {$endif DEBUG_NODE_XML}
  302. public
  303. objname,
  304. objrealname : PShortString;
  305. { for C++ classes: name of the library this class is imported from }
  306. { for Java classes/records: package name }
  307. import_lib : PShortString;
  308. symtable : TSymtable;
  309. cloneddef : tabstractrecorddef;
  310. cloneddefderef : tderef;
  311. objectoptions : tobjectoptions;
  312. { for targets that initialise typed constants via explicit assignments
  313. instead of by generating an initialised data sectino }
  314. tcinitcode : tnode;
  315. constructor create(const n:string; dt:tdeftyp;doregister:boolean);
  316. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  317. procedure ppuwrite(ppufile:tcompilerppufile);override;
  318. destructor destroy; override;
  319. procedure buildderefimpl;override;
  320. procedure derefimpl;override;
  321. procedure check_forwards; virtual;
  322. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  323. function GetSymtable(t:tGetSymtable):TSymtable;override;
  324. function is_packed:boolean;
  325. function RttiName: string;
  326. { enumerator support }
  327. function search_enumerator_get: tprocdef; virtual;
  328. function search_enumerator_move: tprocdef; virtual;
  329. function search_enumerator_current: tsym; virtual;
  330. { JVM }
  331. function jvm_full_typename(with_package_name: boolean): string;
  332. { check if the symtable contains a float field }
  333. function contains_float_field : boolean;
  334. { check if the symtable contains a field that spans an aword boundary }
  335. function contains_cross_aword_field: boolean;
  336. end;
  337. pvariantrecdesc = ^tvariantrecdesc;
  338. tvariantrecbranch = record
  339. { we store only single values here and no ranges because tvariantrecdesc is only needed in iso mode
  340. which does not support range expressions in variant record definitions }
  341. values : array of Tconstexprint;
  342. nestedvariant : pvariantrecdesc;
  343. end;
  344. ppvariantrecdesc = ^pvariantrecdesc;
  345. tvariantrecdesc = record
  346. variantselector : tsym;
  347. variantselectorderef : tderef;
  348. branches : array of tvariantrecbranch;
  349. end;
  350. trecorddef = class(tabstractrecorddef)
  351. {$ifdef DEBUG_NODE_XML}
  352. protected
  353. function XMLPrintType: ansistring; override;
  354. {$endif DEBUG_NODE_XML}
  355. public
  356. variantrecdesc : pvariantrecdesc;
  357. isunion : boolean;
  358. constructor create(const n:string; p:TSymtable);virtual;
  359. constructor create_global_internal(const n: string; packrecords, recordalignmin: shortint); virtual;
  360. constructor create_internal(const n: string; packrecords, recordalignmin: shortint; where: tsymtable); virtual;
  361. function add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  362. procedure add_fields_from_deflist(fieldtypes: tfplist);
  363. constructor ppuload(ppufile:tcompilerppufile);
  364. destructor destroy;override;
  365. function getcopy : tstoreddef;override;
  366. { do not override this routine in platform-specific subclasses,
  367. override ppuwrite_platform instead }
  368. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  369. procedure buildderef;override;
  370. procedure deref;override;
  371. function size:asizeint;override;
  372. function alignment : shortint;override;
  373. function padalignment: shortint;
  374. function GetTypeName:string;override;
  375. { debug }
  376. function needs_inittable : boolean;override;
  377. function needs_separate_initrtti:boolean;override;
  378. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  379. end;
  380. trecorddefclass = class of trecorddef;
  381. tobjectdef = class;
  382. { TImplementedInterface }
  383. TImplementedInterface = class
  384. private
  385. fIOffset : longint;
  386. function GetIOffset: longint;
  387. public
  388. IntfDef : tobjectdef;
  389. IntfDefDeref : tderef;
  390. IType : tinterfaceentrytype;
  391. VtblImplIntf : TImplementedInterface;
  392. NameMappings : TFPHashList;
  393. ProcDefs : TFPObjectList;
  394. ImplementsGetter : tsym;
  395. ImplementsGetterDeref : tderef;
  396. ImplementsField : tsym;
  397. constructor create(aintf: tobjectdef);virtual;
  398. constructor create_deref(intfd,getterd:tderef);virtual;
  399. destructor destroy; override;
  400. function getcopy:TImplementedInterface;
  401. procedure buildderef;
  402. procedure deref;
  403. procedure AddMapping(const origname, newname: string);
  404. function GetMapping(const origname: string):string;
  405. procedure AddImplProc(pd:tprocdef);
  406. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  407. property IOffset: longint read GetIOffset write fIOffset;
  408. end;
  409. timplementedinterfaceclass = class of timplementedinterface;
  410. { tvmtentry }
  411. tvmtentry = record
  412. procdef : tprocdef;
  413. procdefderef : tderef;
  414. visibility : tvisibility;
  415. end;
  416. pvmtentry = ^tvmtentry;
  417. { tobjectdef }
  418. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  419. pmvcallstaticinfo = ^tmvcallstaticinfo;
  420. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  421. tobjectdef = class(tabstractrecorddef)
  422. private
  423. fcurrent_dispid: longint;
  424. {$ifdef DEBUG_NODE_XML}
  425. protected
  426. function XMLPrintType: ansistring; override;
  427. procedure XMLPrintDefInfo(var T: Text; Sym: TSym); override;
  428. procedure XMLPrintDefData(var T: Text; Sym: TSym); override;
  429. {$endif DEBUG_NODE_XML}
  430. public
  431. childof : tobjectdef;
  432. childofderef : tderef;
  433. { for Object Pascal helpers }
  434. extendeddef : tdef;
  435. extendeddefderef: tderef;
  436. helpertype : thelpertype;
  437. { for Objective-C: protocols and classes can have the same name there }
  438. objextname : pshortstring;
  439. { to be able to have a variable vmt position }
  440. { and no vmt field for objects without virtuals }
  441. vmtentries : TFPList;
  442. vmcallstaticinfo : pmvcallstaticinfo;
  443. vmt_field : tsym;
  444. vmt_fieldderef : tderef;
  445. iidguid : pguid;
  446. iidstr : pshortstring;
  447. { store implemented interfaces defs and name mappings }
  448. ImplementedInterfaces : TFPObjectList;
  449. { number of abstract methods (used by JVM target to determine whether
  450. or not the class should be marked as abstract: must be done if 1 or
  451. more abstract methods) }
  452. abstractcnt : longint;
  453. writing_class_record_dbginfo,
  454. { a class of this type has been created in this module }
  455. created_in_current_module,
  456. { a loadvmtnode for this class has been created in this
  457. module, so if a classrefdef variable of this or a parent
  458. class is used somewhere to instantiate a class, then this
  459. class may be instantiated
  460. }
  461. maybe_created_in_current_module,
  462. { a "class of" this particular class has been created in
  463. this module
  464. }
  465. classref_created_in_current_module : boolean;
  466. objecttype : tobjecttyp;
  467. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);virtual;
  468. constructor ppuload(ppufile:tcompilerppufile);
  469. destructor destroy;override;
  470. function getcopy : tstoreddef;override;
  471. { do not override this routine in platform-specific subclasses,
  472. override ppuwrite_platform instead }
  473. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  474. function GetTypeName:string;override;
  475. procedure buildderef;override;
  476. procedure deref;override;
  477. procedure derefimpl;override;
  478. procedure copyvmtentries(objdef:tobjectdef);
  479. function getparentdef:tdef;override;
  480. function size : asizeint;override;
  481. function alignment:shortint;override;
  482. function vmtmethodoffset(index:longint):longint;
  483. function members_need_inittable : boolean;
  484. { this should be called when this class implements an interface }
  485. procedure prepareguid;
  486. function is_publishable : boolean;override;
  487. function needs_inittable : boolean;override;
  488. function needs_separate_initrtti : boolean;override;
  489. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  490. function rtti_mangledname(rt:trttitype):TSymStr;override;
  491. function is_unique_objpasdef: boolean;
  492. function vmt_mangledname : TSymStr;
  493. function vmt_def: trecorddef;
  494. procedure check_forwards; override;
  495. procedure insertvmt;
  496. function vmt_offset: asizeint;
  497. procedure set_parent(c : tobjectdef);
  498. function find_destructor: tprocdef;
  499. function implements_any_interfaces: boolean;
  500. function register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface;
  501. { dispinterface support }
  502. function get_next_dispid: longint;
  503. { enumerator support }
  504. function search_enumerator_get: tprocdef; override;
  505. function search_enumerator_move: tprocdef; override;
  506. function search_enumerator_current: tsym; override;
  507. { WPO }
  508. procedure register_created_object_type;override;
  509. procedure register_maybe_created_object_type;
  510. procedure register_created_classref_type;
  511. procedure register_vmt_call(index:longint);
  512. { ObjC }
  513. procedure finish_objc_data;
  514. function check_objc_types: boolean;
  515. { C++ }
  516. procedure finish_cpp_data;
  517. end;
  518. tobjectdefclass = class of tobjectdef;
  519. tclassrefdef = class(tabstractpointerdef)
  520. constructor create(def:tdef);virtual;
  521. constructor ppuload(ppufile:tcompilerppufile);
  522. { do not override this routine in platform-specific subclasses,
  523. override ppuwrite_platform instead }
  524. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  525. function getcopy:tstoreddef;override;
  526. function GetTypeName:string;override;
  527. function is_publishable : boolean;override;
  528. function rtti_mangledname(rt:trttitype):TSymStr;override;
  529. procedure register_created_object_type;override;
  530. end;
  531. tclassrefdefclass = class of tclassrefdef;
  532. tarraydef = class(tstoreddef)
  533. lowrange,
  534. highrange : asizeint;
  535. rangedef : tdef;
  536. rangedefderef : tderef;
  537. arrayoptions : tarraydefoptions;
  538. symtable : TSymtable;
  539. protected
  540. _elementdef : tdef;
  541. _elementdefderef : tderef;
  542. procedure setelementdef(def:tdef);
  543. class function getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  544. public
  545. function elesize : asizeint;
  546. function elepackedbitsize : asizeint;
  547. function elecount : asizeuint;
  548. constructor create_from_pointer(def: tpointerdef);virtual;
  549. constructor create(l, h: asizeint; def: tdef);virtual;
  550. constructor create_vector(l,h:asizeint; def:tdef);
  551. constructor create_openarray;virtual;
  552. class function getreusable(def: tdef; elems: asizeint): tarraydef;
  553. class function getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  554. { same as above, but in case the def must never be freed after the
  555. current module has been compiled -- even if the def was not written
  556. to the ppu file (for defs in para locations, as we don't reset them
  557. so we don't have to recalculate them all the time) }
  558. class function getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  559. class function getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  560. constructor ppuload(ppufile:tcompilerppufile);
  561. destructor destroy; override;
  562. function getcopy : tstoreddef;override;
  563. { do not override this routine in platform-specific subclasses,
  564. override ppuwrite_platform instead }
  565. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  566. function GetTypeName:string;override;
  567. function getmangledparaname : TSymStr;override;
  568. procedure buildderef;override;
  569. procedure deref;override;
  570. function size : asizeint;override;
  571. function alignment : shortint;override;
  572. { returns the label of the range check string }
  573. function needs_inittable : boolean;override;
  574. function needs_separate_initrtti : boolean;override;
  575. property elementdef : tdef read _elementdef write setelementdef;
  576. function is_publishable : boolean;override;
  577. function is_hwvector: boolean;
  578. end;
  579. tarraydefclass = class of tarraydef;
  580. torddef = class(tstoreddef)
  581. low,high : TConstExprInt;
  582. ordtype : tordtype;
  583. constructor create(t : tordtype;v,b : TConstExprInt; doregister: boolean);virtual;
  584. constructor ppuload(ppufile:tcompilerppufile);
  585. function getcopy : tstoreddef;override;
  586. { do not override this routine in platform-specific subclasses,
  587. override ppuwrite_platform instead }
  588. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  589. function is_publishable : boolean;override;
  590. function GetTypeName:string;override;
  591. function alignment:shortint;override;
  592. procedure setsize;
  593. function packedbitsize: asizeint; override;
  594. function getvardef : longint;override;
  595. end;
  596. torddefclass = class of torddef;
  597. tfloatdef = class(tstoreddef)
  598. floattype : tfloattype;
  599. constructor create(t: tfloattype; doregister: boolean);virtual;
  600. constructor ppuload(ppufile:tcompilerppufile);
  601. function getcopy : tstoreddef;override;
  602. { do not override this routine in platform-specific subclasses,
  603. override ppuwrite_platform instead }
  604. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  605. function GetTypeName:string;override;
  606. function is_publishable : boolean;override;
  607. function alignment:shortint;override;
  608. function structalignment: shortint;override;
  609. procedure setsize;
  610. function getvardef:longint;override;
  611. end;
  612. tfloatdefclass = class of tfloatdef;
  613. { tabstractprocdef }
  614. tprocnameoption = (pno_showhidden, pno_proctypeoption, pno_paranames,
  615. pno_ownername, pno_noclassmarker, pno_noleadingdollar,
  616. pno_mangledname, pno_noparams);
  617. tprocnameoptions = set of tprocnameoption;
  618. tproccopytyp = (pc_normal,
  619. {$ifdef i8086}
  620. { the address in a far format }
  621. pc_far_address,
  622. { the offset part of the far address }
  623. pc_offset,
  624. {$endif i8086}
  625. { creates a procvardef describing only the code pointer
  626. of a method/netsted function/... }
  627. pc_address_only,
  628. { everything except for hidden parameters }
  629. pc_normal_no_hidden,
  630. { everything except for the parameters (because they
  631. might be moved over to the copy) }
  632. pc_normal_no_paras,
  633. { always creates a top-level function, removes all
  634. special parameters (self, vmt, parentfp, ...) }
  635. pc_bareproc
  636. );
  637. tcacheableproccopytyp = pc_normal..pc_address_only;
  638. tabstractprocdef = class(tstoreddef)
  639. { saves a definition to the return type }
  640. returndef : tdef;
  641. returndefderef : tderef;
  642. parast : TSymtable;
  643. paras : tparalist;
  644. proctypeoption : tproctypeoption;
  645. proccalloption : tproccalloption;
  646. procoptions : tprocoptions;
  647. callerargareasize,
  648. calleeargareasize: pint;
  649. {$ifdef m68k}
  650. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  651. {$endif}
  652. funcretloc : array[callerside..calleeside] of TCGPara;
  653. has_paraloc_info : tcallercallee; { paraloc info is available }
  654. { number of user visible parameters }
  655. maxparacount,
  656. minparacount : byte;
  657. constructor create(dt:tdeftyp;level:byte;doregister:boolean);
  658. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  659. destructor destroy;override;
  660. procedure ppuwrite(ppufile:tcompilerppufile);override;
  661. procedure buildderef;override;
  662. procedure deref;override;
  663. procedure calcparas;
  664. function mangledprocparanames(oldlen : longint) : string;
  665. function typename_paras(pno: tprocnameoptions): ansistring;
  666. function is_methodpointer:boolean;virtual;
  667. function is_addressonly:boolean;virtual;
  668. function no_self_node:boolean;
  669. { get either a copy as a procdef or procvardef }
  670. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; virtual;
  671. function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual;
  672. procedure check_mark_as_nested;
  673. procedure init_paraloc_info(side: tcallercallee);
  674. procedure done_paraloc_info(side: tcallercallee);
  675. function stack_tainting_parameter(side: tcallercallee): boolean;
  676. function is_pushleftright: boolean;virtual;
  677. function address_type:tdef;virtual;
  678. { address type, generated for ofs() }
  679. function ofs_address_type:tdef;virtual;
  680. procedure declared_far;virtual;
  681. procedure declared_near;virtual;
  682. function generate_safecall_wrapper: boolean; virtual;
  683. { returns true if the def is a generic param of the procdef }
  684. function is_generic_param(def:tdef): boolean;
  685. private
  686. procedure count_para(p:TObject;arg:pointer);
  687. procedure insert_para(p:TObject;arg:pointer);
  688. end;
  689. tprocvardef = class(tabstractprocdef)
  690. constructor create(level:byte;doregister:boolean);virtual;
  691. { returns a procvardef that represents the address of a proc(var)def }
  692. class function getreusableprocaddr(def: tabstractprocdef; copytyp: tcacheableproccopytyp): tprocvardef; virtual;
  693. { same as above, but in case the def must never be freed after the
  694. current module has been compiled -- even if the def was not written
  695. to the ppu file (for defs in para locations, as we don't reset them
  696. so we don't have to recalculate them all the time) }
  697. class function getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  698. constructor ppuload(ppufile:tcompilerppufile);
  699. function getcopy : tstoreddef;override;
  700. { do not override this routine in platform-specific subclasses,
  701. override ppuwrite_platform instead }
  702. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  703. function GetSymtable(t:tGetSymtable):TSymtable;override;
  704. function size : asizeint;override;
  705. function GetTypeName:string;override;
  706. function is_publishable : boolean;override;
  707. function is_methodpointer:boolean;override;
  708. function is_addressonly:boolean;override;
  709. function getmangledparaname:TSymStr;override;
  710. function getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; override;
  711. end;
  712. tprocvardefclass = class of tprocvardef;
  713. tmessageinf = record
  714. case integer of
  715. 0 : (str : pshortstring);
  716. 1 : (i : longint);
  717. end;
  718. tinlininginfo = record
  719. { node tree }
  720. code : tnode;
  721. flags : tprocinfoflags;
  722. end;
  723. pinlininginfo = ^tinlininginfo;
  724. tcapturedsyminfo = record
  725. sym : tsym;
  726. { the location where the symbol was first encountered }
  727. fileinfo : tfileposinfo;
  728. end;
  729. pcapturedsyminfo = ^tcapturedsyminfo;
  730. timplprocdefinfo = record
  731. resultname : pshortstring;
  732. parentfpstruct: tsym;
  733. parentfpstructptrtype: tdef;
  734. parentfpinitblock: tnode;
  735. procstarttai,
  736. procendtai : tai;
  737. skpara: pointer;
  738. personality: tprocdef;
  739. was_anonymous,
  740. has_capturer,
  741. forwarddef,
  742. interfacedef : boolean;
  743. hasforward : boolean;
  744. is_implemented : boolean;
  745. capturedsyms : tfplist;
  746. end;
  747. pimplprocdefinfo = ^timplprocdefinfo;
  748. { tprocdef }
  749. tprocdef = class(tabstractprocdef)
  750. protected
  751. {$ifdef symansistr}
  752. _mangledname : ansistring;
  753. {$else symansistr}
  754. _mangledname : pshortstring;
  755. {$endif}
  756. _parentfpsym : tsym;
  757. { information that is only required until the implementation of the
  758. procdef has been handled }
  759. implprocdefinfo : pimplprocdefinfo;
  760. function store_localst:boolean;
  761. function GetResultName: PShortString;
  762. procedure SetResultName(AValue: PShortString);
  763. function GetParentFPStruct: tsym;
  764. procedure SetParentFPStruct(AValue: tsym);
  765. function GetParentFPStructPtrType: tdef;
  766. procedure SetParentFPStructPtrType(AValue: tdef);
  767. function GetParentFPInitBlock: tnode;
  768. procedure SetParentFPInitBlock(AValue: tnode);
  769. function Getprocstarttai: tai;
  770. procedure Setprocstarttai(AValue: tai);
  771. function Getprocendtai: tai;
  772. procedure Setprocendtai(AValue: tai);
  773. function Getskpara: pointer;
  774. procedure Setskpara(AValue: pointer);
  775. function Getpersonality: tprocdef;
  776. procedure Setpersonality(AValue: tprocdef);
  777. function Getforwarddef: boolean;
  778. procedure Setforwarddef(AValue: boolean);
  779. function Getinterfacedef: boolean;
  780. procedure Setinterfacedef(AValue: boolean);virtual;
  781. function Gethasforward: boolean;
  782. procedure Sethasforward(AValue: boolean);
  783. function GetIsEmpty: boolean;
  784. procedure SetIsEmpty(AValue: boolean);
  785. function GetHasInliningInfo: boolean;
  786. procedure SetHasInliningInfo(AValue: boolean);
  787. function Getis_implemented: boolean;
  788. procedure Setis_implemented(AValue: boolean);
  789. function getwas_anonymous:boolean;
  790. procedure setwas_anonymous(avalue:boolean);
  791. function gethas_capturer:boolean;
  792. procedure sethas_capturer(avalue:boolean);
  793. function Getcapturedsyms:tfplist;
  794. function getparentfpsym: tsym;
  795. public
  796. messageinf : tmessageinf;
  797. dispid : longint;
  798. {$ifndef EXTDEBUG}
  799. { where is this function defined and what were the symbol
  800. flags, needed here because there
  801. is only one symbol for all overloaded functions
  802. EXTDEBUG has fileinfo in tdef (PFV) }
  803. fileinfo : tfileposinfo;
  804. {$endif}
  805. symoptions : tsymoptions;
  806. deprecatedmsg : pshortstring;
  807. { generic support }
  808. genericdecltokenbuf : tdynamicarray;
  809. { symbol owning this definition }
  810. procsym : tsym;
  811. procsymderef : tderef;
  812. { alias names }
  813. aliasnames : TCmdStrList;
  814. { symtables }
  815. localst : TSymtable;
  816. funcretsym : tsym;
  817. funcretsymderef : tderef;
  818. struct : tabstractrecorddef;
  819. structderef : tderef;
  820. implprocoptions: timplprocoptions;
  821. { import info }
  822. import_dll,
  823. import_name : pshortstring;
  824. { info for inlining the subroutine, if this pointer is nil,
  825. the procedure can't be inlined }
  826. inlininginfo : pinlininginfo;
  827. import_nr : word;
  828. extnumber : word;
  829. { set to a value different from tsk_none in case this procdef is for
  830. a routine that has to be internally generated by the compiler }
  831. synthetickind: tsynthetickind;
  832. visibility : tvisibility;
  833. {$ifndef DISABLE_FAST_OVERLOAD_PATCH}
  834. seenmarker : pointer; // used for filtering in tcandidate
  835. {$endif}
  836. {$ifdef symansistr}
  837. section: ansistring;
  838. {$else symansistr}
  839. section: pshortstring;
  840. {$endif}
  841. constructor create(level:byte;doregister:boolean);virtual;
  842. constructor ppuload(ppufile:tcompilerppufile);
  843. destructor destroy;override;
  844. procedure freeimplprocdefinfo;
  845. { do not override this routine in platform-specific subclasses,
  846. override ppuwrite_platform instead }
  847. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  848. procedure buildderef;override;
  849. procedure buildderefimpl;override;
  850. procedure deref;override;
  851. procedure derefimpl;override;
  852. function GetSymtable(t:tGetSymtable):TSymtable;override;
  853. { warnings:
  854. * the symtablestack top has to be the symtable to which the copy
  855. should be added
  856. * getcopy does not create a finished/ready-to-use procdef; it
  857. needs to be finalised afterwards by calling
  858. symcreat.finish_copied_procdef() afterwards
  859. }
  860. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef; override;
  861. function getcopy: tstoreddef; override;
  862. function GetTypeName : string;override;
  863. function mangledname : TSymStr; virtual;
  864. procedure setmangledname(const s : TSymStr);
  865. function needsglobalasmsym: boolean;
  866. procedure setcompilerprocname;
  867. function fullprocname(showhidden:boolean):string;
  868. function customprocname(pno: tprocnameoptions):ansistring;
  869. function defaultmangledname: TSymStr;
  870. function cplusplusmangledname : TSymStr;
  871. function objcmangledname : TSymStr;
  872. function is_methodpointer:boolean;override;
  873. function is_addressonly:boolean;override;
  874. procedure make_external;
  875. procedure init_genericdecl;
  876. function get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean; virtual;
  877. function get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean; virtual;
  878. procedure add_captured_sym(sym:tsym;const filepos:tfileposinfo);
  879. { returns whether the mangled name or any of its aliases is equal to
  880. s }
  881. function has_alias_name(const s: TSymStr):boolean;
  882. { aliases to fields only required when a function is implemented in
  883. the current unit }
  884. property resultname: PShortString read GetResultName write SetResultName;
  885. { temporary reference to structure containing copies of all local
  886. variables and parameters accessed by nested routines; reference to
  887. this structure is passed as "parent frame pointer" on targets that
  888. lack this concept (at least JVM and LLVM); no need to save to/
  889. restore from ppu, since nested routines are always in the same
  890. unit }
  891. property parentfpstruct: tsym read GetParentFPStruct write SetParentFPStruct;
  892. { pointer to parentfpstruct's type (not yet valid during parsing, so
  893. cannot be used for $parentfp parameter) (no need to save to ppu) }
  894. property parentfpstructptrtype: tdef read GetParentFPStructPtrType write SetParentFPStructPtrType;
  895. { code to copy the parameters accessed from nested routines into the
  896. parentfpstruct (no need to save to ppu) }
  897. property parentfpinitblock: tnode read GetParentFPInitBlock write SetParentFPInitBlock;
  898. { First/last assembler symbol/instruction in aasmoutput list.
  899. Note: initialised after compiling the code for the procdef, but
  900. not saved to/restored from ppu. Used when inserting debug info }
  901. property procstarttai: tai read Getprocstarttai write Setprocstarttai;
  902. property procendtai: tai read Getprocendtai write Setprocendtai;
  903. { optional parameter for the synthetic routine generation logic }
  904. property skpara: pointer read Getskpara write Setskpara;
  905. { ABI-conformant exception handling personality function }
  906. property personality: tprocdef read Getpersonality write Setpersonality;
  907. { true, if the procedure is only declared
  908. (forward procedure) }
  909. property forwarddef: boolean read Getforwarddef write Setforwarddef;
  910. { true if the procedure is declared in the interface }
  911. property interfacedef: boolean read Getinterfacedef write Setinterfacedef;
  912. { true if the procedure has a forward declaration }
  913. property hasforward: boolean read Gethasforward write Sethasforward;
  914. { true if the routine's body is empty }
  915. property isempty: boolean read GetIsEmpty write SetIsEmpty;
  916. { true if all information required to inline this routine is available }
  917. property has_inlininginfo: boolean read GetHasInliningInfo write SetHasInliningInfo;
  918. { returns the $parentfp parameter for nested routines }
  919. property parentfpsym: tsym read getparentfpsym;
  920. { true if the implementation part for this procdef has been handled }
  921. property is_implemented: boolean read Getis_implemented write Setis_implemented;
  922. { valid if the procdef captures any symbols from outer scopes }
  923. property capturedsyms:tfplist read Getcapturedsyms;
  924. { true if this procdef was originally an anonymous function }
  925. property was_anonymous:boolean read getwas_anonymous write setwas_anonymous;
  926. { true if the procdef has a capturer for anonymous functions }
  927. property has_capturer:boolean read gethas_capturer write sethas_capturer;
  928. end;
  929. tprocdefclass = class of tprocdef;
  930. { single linked list of overloaded procs }
  931. pprocdeflist = ^tprocdeflist;
  932. tprocdeflist = record
  933. def : tprocdef;
  934. defderef : tderef;
  935. next : pprocdeflist;
  936. end;
  937. tstringdef = class(tstoreddef)
  938. encoding : tstringencoding;
  939. stringtype : tstringtype;
  940. len : asizeint;
  941. constructor createshort(l: byte; doregister: boolean);virtual;
  942. constructor loadshort(ppufile:tcompilerppufile);
  943. constructor createlong(l: asizeint; doregister: boolean);virtual;
  944. constructor loadlong(ppufile:tcompilerppufile);
  945. constructor createansi(aencoding: tstringencoding; doregister: boolean);virtual;
  946. constructor loadansi(ppufile:tcompilerppufile);
  947. constructor createwide(doregister: boolean);virtual;
  948. constructor loadwide(ppufile:tcompilerppufile);
  949. constructor createunicode(doregister: boolean);virtual;
  950. constructor loadunicode(ppufile:tcompilerppufile);virtual;
  951. function getcopy : tstoreddef;override;
  952. function stringtypname:string;
  953. { do not override this routine in platform-specific subclasses,
  954. override ppuwrite_platform instead }
  955. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  956. function GetTypeName:string;override;
  957. function getmangledparaname:TSymStr;override;
  958. function is_publishable : boolean;override;
  959. function size:asizeint;override;
  960. function alignment : shortint;override;
  961. function needs_inittable : boolean;override;
  962. function getvardef:longint;override;
  963. { returns the default char type def for the string }
  964. function get_default_char_type: tdef;
  965. { returns the default string type }
  966. function get_default_string_type: tdef;
  967. end;
  968. tstringdefclass = class of tstringdef;
  969. { tenumdef }
  970. tenumdef = class(tstoreddef)
  971. minval,
  972. maxval : asizeint;
  973. basedef : tenumdef;
  974. basedefderef : tderef;
  975. symtable : TSymtable;
  976. has_jumps : boolean;
  977. constructor create;virtual;
  978. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);virtual;
  979. constructor ppuload(ppufile:tcompilerppufile);
  980. destructor destroy;override;
  981. function getcopy : tstoreddef;override;
  982. { do not override this routine in platform-specific subclasses,
  983. override ppuwrite_platform instead }
  984. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  985. procedure buildderef;override;
  986. procedure deref;override;
  987. function GetTypeName:string;override;
  988. function is_publishable : boolean;override;
  989. procedure calcsavesize(packenum: shortint);
  990. function packedbitsize: asizeint; override;
  991. procedure setmax(_max:asizeint);
  992. procedure setmin(_min:asizeint);
  993. function min:asizeint;
  994. function max:asizeint;
  995. function getfirstsym:tsym;
  996. function int2enumsym(l: asizeint): tsym;
  997. { returns basedef if assigned, otherwise self }
  998. function getbasedef: tenumdef;
  999. end;
  1000. tenumdefclass = class of tenumdef;
  1001. tsetdef = class(tstoreddef)
  1002. elementdef : tdef;
  1003. elementdefderef : tderef;
  1004. setbase,
  1005. setmax : asizeint;
  1006. constructor create(def: tdef; low, high: asizeint; doregister: boolean);virtual;
  1007. constructor ppuload(ppufile:tcompilerppufile);
  1008. function getcopy : tstoreddef;override;
  1009. { do not override this routine in platform-specific subclasses,
  1010. override ppuwrite_platform instead }
  1011. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  1012. procedure buildderef;override;
  1013. procedure deref;override;
  1014. function GetTypeName:string;override;
  1015. function is_publishable : boolean;override;
  1016. function alignment: shortint; override;
  1017. end;
  1018. tsetdefclass = class of tsetdef;
  1019. tgenericdummyentry = class
  1020. dummysym : tsym;
  1021. resolvedsym : tsym;
  1022. end;
  1023. tdefawaresymtablestack = class(TSymtablestack)
  1024. private
  1025. procedure add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1026. procedure remove_helpers_and_generics(st:tsymtable);inline;
  1027. procedure remove_helpers(st:tsymtable);
  1028. procedure remove_generics(st:tsymtable);
  1029. procedure pushcommon(st:tsymtable);inline;
  1030. public
  1031. procedure push(st: TSymtable); override;
  1032. procedure pushafter(st,afterst:TSymtable); override;
  1033. procedure pop(st: TSymtable); override;
  1034. end;
  1035. var
  1036. current_structdef: tabstractrecorddef; { used for private functions check !! }
  1037. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  1038. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  1039. cfiledef: tfiledefclass;
  1040. cvariantdef: tvariantdefclass;
  1041. cformaldef: tformaldefclass;
  1042. cforwarddef: tforwarddefclass;
  1043. cundefineddef: tundefineddefclass;
  1044. cerrordef: terrordefclass;
  1045. cpointerdef: tpointerdefclass;
  1046. crecorddef: trecorddefclass;
  1047. cimplementedinterface: timplementedinterfaceclass;
  1048. cobjectdef: tobjectdefclass;
  1049. cclassrefdef: tclassrefdefclass;
  1050. carraydef: tarraydefclass;
  1051. corddef: torddefclass;
  1052. cfloatdef: tfloatdefclass;
  1053. cprocvardef: tprocvardefclass;
  1054. cprocdef: tprocdefclass;
  1055. cstringdef: tstringdefclass;
  1056. cenumdef: tenumdefclass;
  1057. csetdef: tsetdefclass;
  1058. { default types }
  1059. generrordef, { error in definition }
  1060. voidpointertype, { pointer for Void-pointeddef }
  1061. charpointertype, { pointer for Char-pointeddef }
  1062. widecharpointertype, { pointer for WideChar-pointeddef }
  1063. voidcodepointertype, { pointer to code; corresponds to System.CodePointer }
  1064. voidstackpointertype, { the pointer type used for accessing parameters and local vars on the stack }
  1065. parentfpvoidpointertype, { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  1066. {$ifdef x86}
  1067. voidnearpointertype,
  1068. voidnearcspointertype,
  1069. voidneardspointertype,
  1070. voidnearsspointertype,
  1071. voidnearespointertype,
  1072. voidnearfspointertype,
  1073. voidneargspointertype,
  1074. {$ifdef i8086}
  1075. voidfarpointertype,
  1076. voidhugepointertype,
  1077. charnearpointertype,
  1078. charfarpointertype,
  1079. charhugepointertype,
  1080. bytefarpointertype, { used for Mem[] }
  1081. wordfarpointertype, { used for MemW[] }
  1082. longintfarpointertype, { used for MemL[] }
  1083. {$endif i8086}
  1084. {$endif x86}
  1085. cundefinedtype,
  1086. cformaltype, { unique formal definition }
  1087. ctypedformaltype, { unique typed formal definition }
  1088. voidtype, { Void (procedure) }
  1089. cansichartype, { Char }
  1090. cwidechartype, { WideChar }
  1091. pasbool1type, { boolean type }
  1092. pasbool8type,
  1093. pasbool16type,
  1094. pasbool32type,
  1095. pasbool64type,
  1096. bool8type,
  1097. bool16type,
  1098. bool32type,
  1099. bool64type, { implement me }
  1100. {$ifdef llvm}
  1101. llvmbool1type, { LLVM i1 type }
  1102. {$endif llvm}
  1103. u8inttype, { 8-Bit unsigned integer }
  1104. s8inttype, { 8-Bit signed integer }
  1105. u16inttype, { 16-Bit unsigned integer }
  1106. s16inttype, { 16-Bit signed integer }
  1107. u24inttype, { 24-Bit unsigned integer }
  1108. s24inttype, { 24-Bit signed integer }
  1109. u32inttype, { 32-Bit unsigned integer }
  1110. s32inttype, { 32-Bit signed integer }
  1111. u40inttype, { 40-Bit unsigned integer }
  1112. s40inttype, { 40-Bit signed integer }
  1113. u48inttype, { 48-Bit unsigned integer }
  1114. s48inttype, { 48-Bit signed integer }
  1115. u56inttype, { 56-Bit unsigned integer }
  1116. s56inttype, { 56-Bit signed integer }
  1117. u64inttype, { 64-bit unsigned integer }
  1118. s64inttype, { 64-bit signed integer }
  1119. u128inttype, { 128-bit unsigned integer }
  1120. s128inttype, { 128-bit signed integer }
  1121. s32floattype, { 32 bit floating point number }
  1122. s64floattype, { 64 bit floating point number }
  1123. s80floattype, { 80 bit floating point number }
  1124. sc80floattype, { 80 bit floating point number but stored like in C }
  1125. s64currencytype, { pointer to a currency type }
  1126. cshortstringtype, { pointer to type of short string const }
  1127. clongstringtype, { pointer to type of long string const }
  1128. cansistringtype, { pointer to type of ansi string const }
  1129. cwidestringtype, { pointer to type of wide string const }
  1130. cunicodestringtype,
  1131. openshortstringtype, { pointer to type of an open shortstring,
  1132. needed for readln() }
  1133. openchararraytype, { pointer to type of an open array of char,
  1134. needed for readln() }
  1135. cfiletype, { get the same definition for all file }
  1136. { used for stabs }
  1137. methodpointertype, { typecasting of methodpointers to extract self }
  1138. nestedprocpointertype, { typecasting of nestedprocpointers to extract parentfp }
  1139. hresultdef,
  1140. typekindtype, { def of TTypeKind for correct handling of GetTypeKind parameters }
  1141. { we use only one variant def for every variant class }
  1142. cvarianttype,
  1143. colevarianttype,
  1144. { default integer type, normally s32inttype on 32 bit systems and s64bittype on 64 bit systems }
  1145. sinttype,
  1146. uinttype,
  1147. { integer types corresponding to OS_SINT/OS_INT }
  1148. ossinttype,
  1149. osuinttype,
  1150. { integer types corresponding to the ALU size, sizeof(aint) and the ALUSInt/ALUUInt types in the system unit }
  1151. alusinttype,
  1152. aluuinttype,
  1153. { integer types corresponding to SizeInt and SizeUInt for the target platform }
  1154. sizeuinttype,
  1155. sizesinttype,
  1156. { unsigned and signed ord type with the same size as a pointer }
  1157. ptruinttype,
  1158. ptrsinttype,
  1159. { unsigned and signed ord type with the same size as a codepointer }
  1160. codeptruinttype,
  1161. codeptrsinttype,
  1162. { several types to simulate more or less C++ objects for GDB }
  1163. vmttype,
  1164. vmtarraytype,
  1165. { type of classrefs, used for stabs }
  1166. pvmttype,
  1167. { return type of the setjmp function }
  1168. exceptionreasontype : tdef;
  1169. { pointer to the anchestor of all classes }
  1170. class_tobject : tobjectdef;
  1171. { pointer to the base type for custom attributes }
  1172. class_tcustomattribute : tobjectdef;
  1173. { pointer to the ancestor of all COM interfaces }
  1174. interface_iunknown : tobjectdef;
  1175. { pointer to the ancestor of all dispinterfaces }
  1176. interface_idispatch : tobjectdef;
  1177. { pointer to the TGUID type
  1178. of all interfaces }
  1179. rec_tguid : trecorddef;
  1180. { jump buffer type, used by setjmp }
  1181. rec_jmp_buf : trecorddef;
  1182. { system.texceptaddr type, used by fpc_pushexceptaddr }
  1183. rec_exceptaddr: trecorddef;
  1184. { Objective-C base types }
  1185. objc_metaclasstype,
  1186. objc_superclasstype,
  1187. objc_idtype,
  1188. objc_seltype : tpointerdef;
  1189. objc_objecttype : trecorddef;
  1190. { base type of @protocol(protocolname) Objective-C statements }
  1191. objc_protocoltype : tobjectdef;
  1192. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  1193. objc_fastenumeration : tobjectdef;
  1194. objc_fastenumerationstate : trecorddef;
  1195. {$ifdef llvm}
  1196. { llvm types }
  1197. { a unique def to identify any kind of metadata }
  1198. llvm_metadatatype : tdef;
  1199. {$endif llvm}
  1200. { Java base types }
  1201. { java.lang.Object }
  1202. java_jlobject : tobjectdef;
  1203. { java.lang.Throwable }
  1204. java_jlthrowable : tobjectdef;
  1205. { FPC base type for records }
  1206. java_fpcbaserecordtype : tobjectdef;
  1207. { java.lang.String }
  1208. java_jlstring : tobjectdef;
  1209. { java.lang.Enum }
  1210. java_jlenum : tobjectdef;
  1211. { java.util.EnumSet }
  1212. java_juenumset : tobjectdef;
  1213. { java.util.BitSet }
  1214. java_jubitset : tobjectdef;
  1215. { FPC java implementation of ansistrings }
  1216. java_ansistring : tobjectdef;
  1217. { FPC java implementation of shortstrings }
  1218. java_shortstring : tobjectdef;
  1219. { FPC java procvar base class }
  1220. java_procvarbase : tobjectdef;
  1221. { x86 vector types }
  1222. x86_m64type,
  1223. x86_m128type,
  1224. x86_m128dtype,
  1225. x86_m128itype,
  1226. x86_m256type,
  1227. x86_m256dtype,
  1228. x86_m256itype : tdef;
  1229. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1230. function make_dllmangledname(const dllname,importname:TSymStr;
  1231. import_nr : word; pco : tproccalloption):TSymStr;
  1232. { should be in the types unit, but the types unit uses the node stuff :( }
  1233. function is_interfacecom(def: tdef): boolean;
  1234. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  1235. function is_any_interface_kind(def: tdef): boolean;
  1236. function is_interfacecorba(def: tdef): boolean;
  1237. function is_interface(def: tdef): boolean;
  1238. function is_dispinterface(def: tdef): boolean;
  1239. function is_object(def: tdef): boolean;
  1240. function is_class(def: tdef): boolean;
  1241. function is_cppclass(def: tdef): boolean;
  1242. function is_objectpascal_helper(def: tdef): boolean;
  1243. function is_objcclass(def: tdef): boolean;
  1244. function is_objcclassref(def: tdef): boolean;
  1245. function is_objcprotocol(def: tdef): boolean;
  1246. function is_objccategory(def: tdef): boolean;
  1247. function is_objc_class_or_protocol(def: tdef): boolean;
  1248. function is_objc_protocol_or_category(def: tdef): boolean;
  1249. function is_classhelper(def: tdef): boolean;
  1250. function is_class_or_interface(def: tdef): boolean;
  1251. function is_class_or_interface_or_objc(def: tdef): boolean;
  1252. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  1253. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  1254. function is_class_or_interface_or_object(def: tdef): boolean;
  1255. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  1256. function is_implicit_pointer_object_type(def: tdef): boolean;
  1257. { returns true, if def is a type which is an implicit pointer to an array (dyn. array or dyn. string) }
  1258. function is_implicit_array_pointer(def: tdef): boolean;
  1259. function is_class_or_object(def: tdef): boolean;
  1260. function is_record(def: tdef): boolean;
  1261. function is_javaclass(def: tdef): boolean;
  1262. function is_javaclassref(def: tdef): boolean;
  1263. function is_javainterface(def: tdef): boolean;
  1264. function is_java_class_or_interface(def: tdef): boolean;
  1265. procedure loadobjctypes;
  1266. procedure maybeloadcocoatypes;
  1267. function use_vectorfpu(def : tdef) : boolean;
  1268. function getansistringcodepage:tstringencoding; inline;
  1269. function getansistringdef:tstringdef;
  1270. function getparaencoding(def:tdef):tstringencoding; inline;
  1271. function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
  1272. function get_recorddef(prefix:tinternaltypeprefix;const fields:array of tdef; packrecords:shortint): trecorddef;
  1273. { get a table def of the form
  1274. record
  1275. count: countdef;
  1276. elements: array[0..count-1] of elementdef
  1277. end;
  1278. Returns both the outer record and the inner arraydef
  1279. }
  1280. procedure get_tabledef(prefix:tinternaltypeprefix;countdef,elementdef:tdef;count:longint;packrecords:shortint;out recdef:trecorddef;out arrdef:tarraydef);
  1281. function fileinfo_of_typesym_in_def(def:tdef;sym:tsym;out filepos:tfileposinfo):boolean;
  1282. implementation
  1283. uses
  1284. SysUtils,
  1285. cutils,
  1286. { global }
  1287. verbose,
  1288. { target }
  1289. systems,paramgr,
  1290. { symtable }
  1291. symsym,symtable,defutil,objcdef,
  1292. { parser }
  1293. pgenutil,
  1294. { module }
  1295. fmodule,ppu,
  1296. { other }
  1297. aasmbase,
  1298. gendef,
  1299. fpchash,
  1300. entfile
  1301. ;
  1302. {****************************************************************************
  1303. Helpers
  1304. ****************************************************************************}
  1305. function fileinfo_of_typesym_in_def(def:tdef;sym:tsym;out filepos:tfileposinfo):boolean;
  1306. var
  1307. gst : tgetsymtable;
  1308. st : tsymtable;
  1309. i : longint;
  1310. srsym : tsym;
  1311. begin
  1312. result:=false;
  1313. if sym.typ<>typesym then
  1314. exit;
  1315. for gst:=low(tgetsymtable) to high(tgetsymtable) do
  1316. begin
  1317. st:=def.getsymtable(gst);
  1318. if not assigned(st) then
  1319. continue;
  1320. for i:=0 to st.symlist.count-1 do
  1321. begin
  1322. srsym:=tsym(st.symlist[i]);
  1323. case srsym.typ of
  1324. fieldvarsym,
  1325. paravarsym:
  1326. if tabstractvarsym(srsym).vardef.typesym=sym then
  1327. begin
  1328. filepos:=srsym.fileinfo;
  1329. result:=true;
  1330. break;
  1331. end;
  1332. typesym:
  1333. begin
  1334. result:=fileinfo_of_typesym_in_def(ttypesym(srsym).typedef,sym,filepos);
  1335. if result then
  1336. break;
  1337. end
  1338. else
  1339. ;
  1340. end;
  1341. end;
  1342. if result then
  1343. break;
  1344. end;
  1345. { for this we would need the position of the result declaration :/ }
  1346. {if not result and
  1347. (def.typ in [procdef,procvardef]) and
  1348. assigned(tabstractprocdef(def).returndef) and
  1349. (tabstractprocdef(def).returndef.typesym=sym) then
  1350. begin
  1351. result:=true;
  1352. end;}
  1353. end;
  1354. function getansistringcodepage:tstringencoding; inline;
  1355. begin
  1356. if ([cs_explicit_codepage,cs_system_codepage]*current_settings.moduleswitches)<>[] then
  1357. result:=current_settings.sourcecodepage
  1358. else
  1359. result:=0;
  1360. end;
  1361. function getansistringdef:tstringdef;
  1362. var
  1363. symtable:tsymtable;
  1364. oldstack : tsymtablestack;
  1365. begin
  1366. { if a codepage is explicitly defined in this mudule we need to return
  1367. a replacement for ansistring def }
  1368. if ([cs_explicit_codepage,cs_system_codepage]*current_settings.moduleswitches)<>[] then
  1369. begin
  1370. if not assigned(current_module) then
  1371. internalerror(2011101301);
  1372. { codepage can be redeclared only once per unit so we don't need a list of
  1373. redefined ansistring but only one pointer }
  1374. if not assigned(current_module.ansistrdef) then
  1375. begin
  1376. { if we did not create it yet we need to do this now }
  1377. if current_module.in_interface then
  1378. symtable:=current_module.globalsymtable
  1379. else
  1380. symtable:=current_module.localsymtable;
  1381. { create a temporary stack as it's not good (TM) to mess around
  1382. with the order if the unit contains generics or helpers; don't
  1383. use a def aware symtablestack though }
  1384. oldstack:=symtablestack;
  1385. symtablestack:=tsymtablestack.create;
  1386. symtablestack.push(symtable);
  1387. current_module.ansistrdef:=cstringdef.createansi(current_settings.sourcecodepage,true);
  1388. symtablestack.pop(symtable);
  1389. symtablestack.free;
  1390. symtablestack:=oldstack;
  1391. end;
  1392. result:=tstringdef(current_module.ansistrdef);
  1393. end
  1394. else
  1395. result:=tstringdef(cansistringtype);
  1396. end;
  1397. function getparaencoding(def:tdef):tstringencoding; inline;
  1398. begin
  1399. { don't pass CP_NONE encoding to internal functions
  1400. they expect 0 encoding instead
  1401. exception: result of string concatenation, because if you pass the
  1402. result of a string concatenation to a rawbytestring, the result of
  1403. that concatenation shouldn't be converted to defaultsystemcodepage
  1404. if all strings have the same type }
  1405. result:=tstringdef(def).encoding;
  1406. if result=globals.CP_NONE then
  1407. result:=0
  1408. end;
  1409. function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
  1410. var
  1411. typ: ttypesym;
  1412. name: string;
  1413. begin
  1414. name:=internaltypeprefixName[itp_threadvar_record]+def.unique_id_str;
  1415. typ:=try_search_current_module_type(name);
  1416. if assigned(typ) then
  1417. begin
  1418. result:=trecorddef(ttypesym(typ).typedef);
  1419. index_field:=tsym(result.symtable.symlist[0]);
  1420. non_mt_data_field:=tsym(result.symtable.symlist[1]);
  1421. exit;
  1422. end;
  1423. { set recordalinmin to sizeof(pint), so the second field gets put at
  1424. offset = sizeof(pint) as expected }
  1425. result:=crecorddef.create_global_internal(
  1426. name,sizeof(pint),sizeof(pint));
  1427. {$ifdef cpu16bitaddr}
  1428. index_field:=result.add_field_by_def('',u16inttype);
  1429. {$else cpu16bitaddr}
  1430. index_field:=result.add_field_by_def('',u32inttype);
  1431. {$endif cpu16bitaddr}
  1432. non_mt_data_field:=result.add_field_by_def('',def);
  1433. { no need to add alignment padding, we won't create arrays of these }
  1434. end;
  1435. function get_recorddef(prefix:tinternaltypeprefix; const fields:array of tdef; packrecords:shortint): trecorddef;
  1436. var
  1437. fieldlist: tfplist;
  1438. srsym: tsym;
  1439. srsymtable: tsymtable;
  1440. i: longint;
  1441. name : TIDString;
  1442. begin
  1443. name:=copy(internaltypeprefixName[prefix],2,length(internaltypeprefixName[prefix]));
  1444. if searchsym_type(name,srsym,srsymtable) then
  1445. begin
  1446. result:=trecorddef(ttypesym(srsym).typedef);
  1447. exit
  1448. end;
  1449. { also always search in the current module (symtables are popped for
  1450. RTTI related code already) }
  1451. if searchsym_in_module(pointer(current_module),name,srsym,srsymtable) then
  1452. begin
  1453. result:=trecorddef(ttypesym(srsym).typedef);
  1454. exit;
  1455. end;
  1456. fieldlist:=tfplist.create;
  1457. for i:=low(fields) to high(fields) do
  1458. fieldlist.add(fields[i]);
  1459. result:=crecorddef.create_global_internal(internaltypeprefixName[prefix],packrecords,
  1460. targetinfos[target_info.system]^.alignment.recordalignmin);
  1461. result.add_fields_from_deflist(fieldlist);
  1462. fieldlist.free;
  1463. end;
  1464. procedure get_tabledef(prefix:tinternaltypeprefix;countdef,elementdef:tdef;count:longint;packrecords:shortint;out recdef:trecorddef;out arrdef:tarraydef);
  1465. var
  1466. fields: tfplist;
  1467. name: TIDString;
  1468. srsym: tsym;
  1469. srsymtable: tsymtable;
  1470. begin
  1471. { already created a message string table with this number of elements
  1472. in this unit -> reuse the def }
  1473. name:=internaltypeprefixName[prefix]+tostr(count);
  1474. if searchsym_type(copy(name,2,length(name)),srsym,srsymtable) then
  1475. begin
  1476. recdef:=trecorddef(ttypesym(srsym).typedef);
  1477. arrdef:=tarraydef(trecordsymtable(recdef.symtable).findfieldbyoffset(countdef.size).vardef);
  1478. exit
  1479. end;
  1480. { also always search in the current module (symtables are popped for
  1481. RTTI related code already) }
  1482. if searchsym_in_module(pointer(current_module),copy(name,2,length(name)),srsym,srsymtable) then
  1483. begin
  1484. recdef:=trecorddef(ttypesym(srsym).typedef);
  1485. arrdef:=tarraydef(trecordsymtable(recdef.symtable).findfieldbyoffset(countdef.size).vardef);
  1486. exit;
  1487. end;
  1488. recdef:=crecorddef.create_global_internal(name,packrecords,
  1489. targetinfos[target_info.system]^.alignment.recordalignmin);
  1490. fields:=tfplist.create;
  1491. fields.add(countdef);
  1492. if count>0 then
  1493. begin
  1494. arrdef:=carraydef.create(0,count-1,sizeuinttype);
  1495. arrdef.elementdef:=elementdef;
  1496. fields.add(arrdef);
  1497. end
  1498. else
  1499. arrdef:=nil;
  1500. recdef.add_fields_from_deflist(fields);
  1501. fields.free;
  1502. end;
  1503. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1504. var
  1505. s,
  1506. prefix : TSymStr;
  1507. hash : qword;
  1508. begin
  1509. prefix:='';
  1510. if not assigned(st) then
  1511. internalerror(200204212);
  1512. repeat
  1513. { sub procedures }
  1514. while (st.symtabletype in [localsymtable,parasymtable]) do
  1515. begin
  1516. if st.defowner.typ<>procdef then
  1517. internalerror(200204173);
  1518. { Add the full mangledname of the routine to prevent
  1519. conflicts with two overloads both having a local entity
  1520. -- routine (tb0314), class, interface -- with the same name }
  1521. s:=tprocdef(st.defowner).procsym.name;
  1522. s:=s+tprocdef(st.defowner).mangledprocparanames(Length(s));
  1523. if prefix<>'' then
  1524. begin
  1525. if length(prefix)>(maxidlen-length(s)-1) then
  1526. begin
  1527. hash:=0;
  1528. hash:=UpdateFnv64(hash,prefix[1],length(prefix));
  1529. prefix:='$H'+Base64Mangle(hash);
  1530. end;
  1531. prefix:=s+'_'+prefix
  1532. end
  1533. else
  1534. prefix:=s;
  1535. st:=st.defowner.owner;
  1536. end;
  1537. { object/classes symtable, nested type definitions in classes require the while loop }
  1538. while st.symtabletype in [ObjectSymtable,recordsymtable] do
  1539. begin
  1540. if not (st.defowner.typ in [objectdef,recorddef]) then
  1541. internalerror(200204174);
  1542. if length(prefix)>(maxidlen-length(tabstractrecorddef(st.defowner).objname^)-3) then
  1543. begin
  1544. hash:=0;
  1545. hash:=UpdateFnv64(hash,prefix[1],length(prefix));
  1546. prefix:='$H'+Base64Mangle(hash);
  1547. end;
  1548. prefix:=tabstractrecorddef(st.defowner).objname^+'_$_'+prefix;
  1549. st:=st.defowner.owner;
  1550. end;
  1551. { local classes & interfaces are possible (because of closures) }
  1552. if st.symtabletype<>localsymtable then
  1553. break;
  1554. prefix:='$'+prefix;
  1555. until false;
  1556. { symtable must now be static or global }
  1557. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  1558. internalerror(200204175);
  1559. { The mangled name is made out of at most 4 parts:
  1560. 1) Optional typeprefix given as first parameter
  1561. with '_$' appended if not empty
  1562. 2) Unit name or 'P$'+program name (never empty)
  1563. 3) optional prefix variable that contains a unique
  1564. name for the local symbol table (prepended with '$_$'
  1565. if not empty)
  1566. 4) suffix as given as third parameter,
  1567. also optional (i.e. can be empty)
  1568. prepended by '_$$_' if not empty }
  1569. result:='';
  1570. if typeprefix<>'' then
  1571. result:=result+typeprefix+'_$';
  1572. { Add P$ for program, which can have the same name as
  1573. a unit }
  1574. if (TSymtable(main_module.localsymtable)=st) and
  1575. (not main_module.is_unit) then
  1576. result:=result+'P$'+st.name^
  1577. else
  1578. result:=result+st.name^;
  1579. if prefix<>'' then
  1580. result:=result+'$_$'+prefix;
  1581. if suffix<>'' then
  1582. result:=result+'_$$_'+suffix;
  1583. if length(result)>(maxidlen-1) then
  1584. begin
  1585. hash:=0;
  1586. hash:=UpdateFnv64(hash,result[1],length(result));
  1587. result:=copy(result,1,maxidlen-(high(Base64OfUint64String)-low(Base64OfUint64String)+1)-2)+'$H'+Base64Mangle(hash);
  1588. end;
  1589. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  1590. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  1591. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  1592. { those in the debug map, leading to troubles with dsymutil). So always }
  1593. { add an underscore on darwin. }
  1594. if (target_info.system in systems_darwin) then
  1595. result := '_' + result;
  1596. end;
  1597. function make_dllmangledname(const dllname,importname:TSymStr;import_nr : word; pco : tproccalloption):TSymStr;
  1598. var
  1599. crc : cardinal;
  1600. i : longint;
  1601. use_crc : boolean;
  1602. dllprefix : TSymStr;
  1603. begin
  1604. if (target_info.system in (systems_all_windows + systems_nativent +
  1605. [system_i386_emx, system_i386_os2]))
  1606. and (dllname <> '') then
  1607. begin
  1608. dllprefix:=lower(ExtractFileName(dllname));
  1609. { Remove .dll suffix if present }
  1610. if copy(dllprefix,length(dllprefix)-3,length(dllprefix))='.dll' then
  1611. dllprefix:=copy(dllprefix,1,length(dllprefix)-4);
  1612. use_crc:=false;
  1613. for i:=1 to length(dllprefix) do
  1614. if not (dllprefix[i] in ['a'..'z','A'..'Z','_','0'..'9']) then
  1615. begin
  1616. use_crc:=true;
  1617. break;
  1618. end;
  1619. if use_crc then
  1620. begin
  1621. crc:=0;
  1622. crc:=UpdateCrc32(crc,dllprefix[1],length(dllprefix));
  1623. dllprefix:='_$dll$crc$'+hexstr(crc,8)+'$';
  1624. end
  1625. else
  1626. dllprefix:='_$dll$'+dllprefix+'$';
  1627. if importname<>'' then
  1628. result:=dllprefix+importname
  1629. else
  1630. result:=dllprefix+'_index_'+tostr(import_nr);
  1631. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  1632. { This allows to import VC++ mangled names from DLLs. }
  1633. { Do not perform replacement, if external symbol is not imported from DLL. }
  1634. if (dllname<>'') then
  1635. begin
  1636. Replace(result,'?','__q$$');
  1637. {$ifdef arm}
  1638. { @ symbol is not allowed in ARM assembler only }
  1639. Replace(result,'@','__a$$');
  1640. {$endif arm}
  1641. end;
  1642. end
  1643. else
  1644. begin
  1645. if importname<>'' then
  1646. begin
  1647. if not(pco in [pocall_cdecl,pocall_cppdecl]) then
  1648. result:=importname
  1649. else
  1650. result:=target_info.Cprefix+importname;
  1651. end
  1652. else
  1653. result:='_index_'+tostr(import_nr);
  1654. end;
  1655. end;
  1656. {****************************************************************************
  1657. TDEFAWARESYMTABLESTACK
  1658. (symtablestack descendant that does some special actions on
  1659. the pushed/popped symtables)
  1660. ****************************************************************************}
  1661. procedure tdefawaresymtablestack.add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1662. var
  1663. s: TSymStr;
  1664. list: TFPObjectList;
  1665. def: tdef;
  1666. sym : tsym;
  1667. i: integer;
  1668. begin
  1669. { search the symtable from first to last; the helper to use will be the
  1670. last one in the list }
  1671. for i:=0 to st.symlist.count-1 do
  1672. begin
  1673. sym:=tsym(st.symlist[i]);
  1674. if not (sym.typ in [typesym,procsym]) then
  1675. continue;
  1676. if sym.typ=typesym then
  1677. def:=ttypesym(st.SymList[i]).typedef
  1678. else
  1679. def:=nil;
  1680. if is_objectpascal_helper(def) then
  1681. begin
  1682. s:=generate_objectpascal_helper_key(tobjectdef(def).extendeddef);
  1683. Message1(sym_d_adding_helper_for,s);
  1684. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  1685. if not assigned(list) then
  1686. begin
  1687. list:=TFPObjectList.Create(false);
  1688. current_module.extendeddefs.Add(s,list);
  1689. end;
  1690. list.Add(def);
  1691. end
  1692. else
  1693. begin
  1694. if addgenerics then
  1695. add_generic_dummysym(sym);
  1696. { add nested helpers as well }
  1697. if assigned(def) and
  1698. (def.typ in [recorddef,objectdef]) and
  1699. (sto_has_helper in tabstractrecorddef(def).symtable.tableoptions) then
  1700. add_helpers_and_generics(tabstractrecorddef(def).symtable,false);
  1701. end;
  1702. end;
  1703. end;
  1704. procedure tdefawaresymtablestack.remove_helpers_and_generics(st:tsymtable);
  1705. begin
  1706. if sto_has_helper in st.tableoptions then
  1707. remove_helpers(st);
  1708. if sto_has_generic in st.tableoptions then
  1709. remove_generics(st);
  1710. end;
  1711. procedure tdefawaresymtablestack.remove_helpers(st:TSymtable);
  1712. var
  1713. i, j: integer;
  1714. tmpst: TSymtable;
  1715. list: TFPObjectList;
  1716. begin
  1717. for i:=current_module.extendeddefs.count-1 downto 0 do
  1718. begin
  1719. list:=TFPObjectList(current_module.extendeddefs[i]);
  1720. for j:=list.count-1 downto 0 do
  1721. begin
  1722. if not (list[j] is tobjectdef) then
  1723. Internalerror(2011031501);
  1724. tmpst:=tobjectdef(list[j]).owner;
  1725. repeat
  1726. if tmpst=st then
  1727. begin
  1728. list.delete(j);
  1729. break;
  1730. end
  1731. else
  1732. begin
  1733. if assigned(tmpst.defowner) then
  1734. tmpst:=tmpst.defowner.owner
  1735. else
  1736. tmpst:=nil;
  1737. end;
  1738. until not assigned(tmpst) or (tmpst.symtabletype in [globalsymtable,staticsymtable]);
  1739. end;
  1740. if list.count=0 then
  1741. current_module.extendeddefs.delete(i);
  1742. end;
  1743. end;
  1744. procedure tdefawaresymtablestack.remove_generics(st:tsymtable);
  1745. var
  1746. i,j : longint;
  1747. entry : tgenericdummyentry;
  1748. list : tfpobjectlist;
  1749. begin
  1750. for i:=current_module.genericdummysyms.count-1 downto 0 do
  1751. begin
  1752. list:=tfpobjectlist(current_module.genericdummysyms[i]);
  1753. if not assigned(list) then
  1754. continue;
  1755. for j:=list.count-1 downto 0 do
  1756. begin
  1757. entry:=tgenericdummyentry(list[j]);
  1758. if entry.dummysym.owner=st then
  1759. list.delete(j);
  1760. end;
  1761. if list.count=0 then
  1762. current_module.genericdummysyms.delete(i);
  1763. end;
  1764. end;
  1765. procedure tdefawaresymtablestack.pushcommon(st:tsymtable);
  1766. begin
  1767. if (sto_has_generic in st.tableoptions) or
  1768. (
  1769. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1770. (sto_has_helper in st.tableoptions)
  1771. ) then
  1772. { nested helpers will be added as well }
  1773. add_helpers_and_generics(st,true);
  1774. end;
  1775. procedure tdefawaresymtablestack.push(st: TSymtable);
  1776. begin
  1777. pushcommon(st);
  1778. inherited push(st);
  1779. end;
  1780. procedure tdefawaresymtablestack.pushafter(st,afterst:TSymtable);
  1781. begin
  1782. pushcommon(st);
  1783. inherited pushafter(st,afterst);
  1784. end;
  1785. procedure tdefawaresymtablestack.pop(st: TSymtable);
  1786. begin
  1787. inherited pop(st);
  1788. if (sto_has_generic in st.tableoptions) or
  1789. (
  1790. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1791. (sto_has_helper in st.tableoptions)
  1792. ) then
  1793. { nested helpers will be removed as well }
  1794. remove_helpers_and_generics(st);
  1795. end;
  1796. {****************************************************************************
  1797. TDEF (base class for definitions)
  1798. ****************************************************************************}
  1799. constructor tgenericconstraintdata.create;
  1800. begin
  1801. interfaces:=tfpobjectlist.create(false);
  1802. interfacesderef:=tfplist.create;
  1803. end;
  1804. destructor tgenericconstraintdata.destroy;
  1805. var
  1806. i : longint;
  1807. begin
  1808. for i:=0 to interfacesderef.count-1 do
  1809. dispose(pderef(interfacesderef[i]));
  1810. interfacesderef.free;
  1811. interfaces.free;
  1812. inherited destroy;
  1813. end;
  1814. procedure tgenericconstraintdata.ppuload(ppufile: tcompilerppufile);
  1815. var
  1816. cnt,i : longint;
  1817. intfderef : pderef;
  1818. begin
  1819. ppufile.getset(tppuset1(flags));
  1820. cnt:=ppufile.getlongint;
  1821. for i:=0 to cnt-1 do
  1822. begin
  1823. new(intfderef);
  1824. ppufile.getderef(intfderef^);
  1825. interfacesderef.add(intfderef);
  1826. end;
  1827. end;
  1828. procedure tgenericconstraintdata.ppuwrite(ppufile: tcompilerppufile);
  1829. var
  1830. i : longint;
  1831. begin
  1832. ppufile.putset(tppuset1(flags));
  1833. ppufile.putlongint(interfacesderef.count);
  1834. for i:=0 to interfacesderef.count-1 do
  1835. ppufile.putderef(pderef(interfacesderef[i])^);
  1836. end;
  1837. procedure tgenericconstraintdata.buildderef;
  1838. var
  1839. intfderef : pderef;
  1840. i : longint;
  1841. begin
  1842. for i:=0 to interfaces.count-1 do
  1843. begin
  1844. new(intfderef);
  1845. intfderef^.build(tobjectdef(interfaces[i]));
  1846. interfacesderef.add(intfderef);
  1847. end;
  1848. end;
  1849. procedure tgenericconstraintdata.deref;
  1850. var
  1851. i : longint;
  1852. begin
  1853. for i:=0 to interfacesderef.count-1 do
  1854. interfaces.add(pderef(interfacesderef[i])^.resolve);
  1855. end;
  1856. procedure tstoreddef.writeentry(ppufile: tcompilerppufile; ibnr: byte);
  1857. begin
  1858. ppuwrite_platform(ppufile);
  1859. ppufile.writeentry(ibnr);
  1860. end;
  1861. procedure tstoreddef.ppuwrite_platform(ppufile: tcompilerppufile);
  1862. begin
  1863. { by default: do nothing }
  1864. end;
  1865. procedure tstoreddef.ppuload_platform(ppufile: tcompilerppufile);
  1866. begin
  1867. { by default: do nothing }
  1868. end;
  1869. class procedure tstoreddef.setup_reusable_def(origdef, newdef: tdef; res: PHashSetItem; oldsymtablestack: tsymtablestack);
  1870. var
  1871. reusablesymtab: tsymtable;
  1872. begin
  1873. { must not yet belong to a symtable }
  1874. if assigned(newdef.owner) then
  1875. internalerror(2015111503);
  1876. reusablesymtab:=origdef.getreusablesymtab;
  1877. res^.Data:=newdef;
  1878. reusablesymtab.insertdef(newdef);
  1879. symtablestack:=oldsymtablestack;
  1880. end;
  1881. constructor tstoreddef.create(dt:tdeftyp;doregister:boolean);
  1882. begin
  1883. inherited create(dt);
  1884. savesize := 0;
  1885. {$ifdef EXTDEBUG}
  1886. fileinfo := current_filepos;
  1887. {$endif}
  1888. generictokenbuf:=nil;
  1889. genericdef:=nil;
  1890. typesymderef.reset;
  1891. genericdefderef.reset;
  1892. { Don't register forwarddefs, they are disposed at the
  1893. end of an type block }
  1894. if (dt=forwarddef) then
  1895. exit;
  1896. { Register in symtable stack }
  1897. if doregister then
  1898. begin
  1899. { immediately register interface defs, as they will always be
  1900. written to the ppu, their defid inlfuences the interface crc and
  1901. if we wait, depending on e.g. compiler defines they may get a
  1902. different defid (e.g. when a function is called, its procdef is
  1903. registered, so depending on whether or not, or when, an interface
  1904. procedure is called in the implementation, that may change its
  1905. defid otherwise) }
  1906. if assigned(current_module) and
  1907. current_module.in_interface then
  1908. register_def
  1909. else
  1910. maybe_put_in_symtable_stack;
  1911. end;
  1912. end;
  1913. destructor tstoreddef.destroy;
  1914. var
  1915. i : longint;
  1916. begin
  1917. { Direct calls are not allowed, use symtable.deletedef() }
  1918. if assigned(owner) then
  1919. internalerror(200612311);
  1920. if assigned(generictokenbuf) then
  1921. begin
  1922. generictokenbuf.free;
  1923. generictokenbuf:=nil;
  1924. end;
  1925. rtti_attribute_list.free;
  1926. genericparas.free;
  1927. if assigned(genericparaderefs) then
  1928. for i:=0 to genericparaderefs.count-1 do
  1929. dispose(pderef(genericparaderefs[i]));
  1930. genericparaderefs.free;
  1931. genconstraintdata.free;
  1932. {$ifndef symansistr}
  1933. stringdispose(_fullownerhierarchyname);
  1934. {$endif not symansistr}
  1935. inherited destroy;
  1936. end;
  1937. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1938. var
  1939. sizeleft,i,cnt : longint;
  1940. buf : array[0..255] of byte;
  1941. symderef : pderef;
  1942. begin
  1943. inherited create(dt);
  1944. DefId:=ppufile.getlongint;
  1945. current_module.deflist[DefId]:=self;
  1946. {$ifdef EXTDEBUG}
  1947. fillchar(fileinfo,sizeof(fileinfo),0);
  1948. {$endif}
  1949. { load }
  1950. ppufile.getderef(typesymderef);
  1951. ppufile.getset(tppuset2(defoptions));
  1952. ppufile.getset(tppuset1(defstates));
  1953. if df_genconstraint in defoptions then
  1954. begin
  1955. genconstraintdata:=tgenericconstraintdata.create;
  1956. genconstraintdata.ppuload(ppufile);
  1957. end;
  1958. if [df_generic,df_specialization]*defoptions<>[] then
  1959. begin
  1960. cnt:=ppufile.getlongint;
  1961. if cnt>0 then
  1962. begin
  1963. genericparas:=tfphashobjectlist.create(false);
  1964. genericparaderefs:=tfplist.create;
  1965. for i:=0 to cnt-1 do
  1966. begin
  1967. genericparas.add(ppufile.getstring,nil);
  1968. New(symderef);
  1969. ppufile.getderef(symderef^);
  1970. genericparaderefs.add(symderef);
  1971. end;
  1972. end;
  1973. end;
  1974. if df_generic in defoptions then
  1975. begin
  1976. sizeleft:=ppufile.getlongint;
  1977. initgeneric;
  1978. while sizeleft>0 do
  1979. begin
  1980. if sizeleft>sizeof(buf) then
  1981. i:=sizeof(buf)
  1982. else
  1983. i:=sizeleft;
  1984. ppufile.getdata(buf,i);
  1985. generictokenbuf.write(buf,i);
  1986. dec(sizeleft,i);
  1987. end;
  1988. end;
  1989. if df_specialization in defoptions then
  1990. ppufile.getderef(genericdefderef);
  1991. rtti_attribute_list:=trtti_attribute_list.ppuload(ppufile);
  1992. end;
  1993. function tstoreddef.needs_separate_initrtti:boolean;
  1994. begin
  1995. result:=false;
  1996. end;
  1997. function tstoreddef.rtti_mangledname(rt : trttitype) : TSymStr;
  1998. var
  1999. prefix : string[4];
  2000. begin
  2001. if (rt=fullrtti) or (not needs_separate_initrtti) then
  2002. begin
  2003. prefix:='RTTI';
  2004. include(defstates,ds_rtti_table_used);
  2005. end
  2006. else
  2007. begin
  2008. prefix:='INIT';
  2009. include(defstates,ds_init_table_used);
  2010. end;
  2011. if assigned(typesym) and
  2012. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  2013. result:=make_mangledname(prefix,typesym.owner,typesym.name)
  2014. else
  2015. result:=make_mangledname(prefix,findunitsymtable(owner),'def'+unique_id_str)
  2016. end;
  2017. function tstoreddef.OwnerHierarchyName: string;
  2018. var
  2019. tmp: tdef;
  2020. begin
  2021. tmp:=self;
  2022. result:='';
  2023. repeat
  2024. { can be not assigned in case of a forwarddef }
  2025. if assigned(tmp.owner) and
  2026. (tmp.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2027. tmp:=tdef(tmp.owner.defowner)
  2028. else
  2029. break;
  2030. result:=tabstractrecorddef(tmp).objrealname^+'.'+result;
  2031. until tmp=nil;
  2032. end;
  2033. function tstoreddef.fullownerhierarchyname(skipprocparams:boolean): TSymStr;
  2034. var
  2035. lastowner: tsymtable;
  2036. tmp: tdef;
  2037. pno: tprocnameoptions;
  2038. begin
  2039. {$ifdef symansistr}
  2040. if not skipprocparams and (_fullownerhierarchyname<>'') then
  2041. exit(_fullownerhierarchyname);
  2042. {$else symansistr}
  2043. if not skipprocparams and assigned(_fullownerhierarchyname) then
  2044. exit(_fullownerhierarchyname^);
  2045. {$endif symansistr}
  2046. { the def can only reside inside structured types or
  2047. procedures/functions/methods }
  2048. tmp:=self;
  2049. result:='';
  2050. repeat
  2051. lastowner:=tmp.owner;
  2052. { can be not assigned in case of a forwarddef }
  2053. if not assigned(lastowner) then
  2054. break
  2055. else
  2056. tmp:=tdef(lastowner.defowner);
  2057. if not assigned(tmp) then
  2058. break;
  2059. if tmp.typ in [recorddef,objectdef] then
  2060. result:=tabstractrecorddef(tmp).objrealname^+'.'+result
  2061. else
  2062. if tmp.typ=procdef then
  2063. begin
  2064. pno:=[pno_paranames,pno_proctypeoption];
  2065. if skipprocparams then
  2066. include(pno,pno_noparams);
  2067. result:=tprocdef(tmp).customprocname(pno)+'.'+result;
  2068. end;
  2069. until tmp=nil;
  2070. { add the unit name }
  2071. if assigned(lastowner) and
  2072. assigned(lastowner.realname) then
  2073. result:=lastowner.realname^+'.'+result;
  2074. if not skipprocparams then
  2075. { don't store the name in this case }
  2076. {$ifdef symansistr}
  2077. _fullownerhierarchyname:=result;
  2078. {$else symansistr}
  2079. _fullownerhierarchyname:=stringdup(result);
  2080. {$endif symansistr}
  2081. end;
  2082. function tstoreddef.in_currentunit: boolean;
  2083. var
  2084. st: tsymtable;
  2085. begin
  2086. st:=owner;
  2087. while not(st.symtabletype in [globalsymtable,staticsymtable]) do
  2088. st:=st.defowner.owner;
  2089. result:=st.iscurrentunit;
  2090. end;
  2091. function tstoreddef.getcopy : tstoreddef;
  2092. begin
  2093. Message(sym_e_cant_create_unique_type);
  2094. getcopy:=cerrordef.create;
  2095. end;
  2096. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  2097. var
  2098. sizeleft,i : longint;
  2099. buf : array[0..255] of byte;
  2100. oldintfcrc : boolean;
  2101. begin
  2102. if defid<0 then
  2103. internalerror(2015101401);
  2104. ppufile.putlongint(DefId);
  2105. ppufile.putderef(typesymderef);
  2106. ppufile.putset(tppuset2(defoptions));
  2107. oldintfcrc:=ppufile.do_crc;
  2108. ppufile.do_crc:=false;
  2109. ppufile.putset(tppuset1(defstates));
  2110. if df_genconstraint in defoptions then
  2111. genconstraintdata.ppuwrite(ppufile);
  2112. if [df_generic,df_specialization]*defoptions<>[] then
  2113. begin
  2114. if not assigned(genericparas) then
  2115. ppufile.putlongint(0)
  2116. else
  2117. begin
  2118. if not assigned(genericparaderefs) then
  2119. internalerror(2014052305);
  2120. ppufile.putlongint(genericparas.count);
  2121. for i:=0 to genericparas.count-1 do
  2122. begin
  2123. ppufile.putstring(genericparas.nameofindex(i));
  2124. ppufile.putderef(pderef(genericparaderefs[i])^);
  2125. end;
  2126. end;
  2127. end;
  2128. if df_generic in defoptions then
  2129. begin
  2130. if assigned(generictokenbuf) then
  2131. begin
  2132. sizeleft:=generictokenbuf.size;
  2133. generictokenbuf.seek(0);
  2134. end
  2135. else
  2136. sizeleft:=0;
  2137. ppufile.putlongint(sizeleft);
  2138. while sizeleft>0 do
  2139. begin
  2140. if sizeleft>sizeof(buf) then
  2141. i:=sizeof(buf)
  2142. else
  2143. i:=sizeleft;
  2144. generictokenbuf.read(buf,i);
  2145. ppufile.putdata(buf,i);
  2146. dec(sizeleft,i);
  2147. end;
  2148. end;
  2149. ppufile.do_crc:=oldintfcrc;
  2150. if df_specialization in defoptions then
  2151. ppufile.putderef(genericdefderef);
  2152. trtti_attribute_list.ppuwrite(rtti_attribute_list,ppufile);
  2153. end;
  2154. procedure tstoreddef.ppuload_subentries(ppufile: tcompilerppufile);
  2155. begin
  2156. trtti_attribute_list.ppuload_subentries(rtti_attribute_list,ppufile);
  2157. end;
  2158. procedure tstoreddef.ppuwrite_subentries(ppufile: tcompilerppufile);
  2159. begin
  2160. trtti_attribute_list.ppuwrite_subentries(rtti_attribute_list,ppufile);
  2161. end;
  2162. procedure tstoreddef.buildderef;
  2163. var
  2164. i : longint;
  2165. sym : tsym;
  2166. symderef : pderef;
  2167. begin
  2168. if not registered then
  2169. register_def;
  2170. typesymderef.build(typesym);
  2171. genericdefderef.build(genericdef);
  2172. if assigned(rtti_attribute_list) then
  2173. rtti_attribute_list.buildderef;
  2174. if assigned(genconstraintdata) then
  2175. genconstraintdata.buildderef;
  2176. if assigned(genericparas) then
  2177. begin
  2178. if not assigned(genericparaderefs) then
  2179. genericparaderefs:=tfplist.create;
  2180. for i:=0 to genericparas.count-1 do
  2181. begin
  2182. sym:=tsym(genericparas.items[i]);
  2183. new(symderef);
  2184. symderef^.build(sym);
  2185. genericparaderefs.add(symderef);
  2186. end;
  2187. end;
  2188. end;
  2189. procedure tstoreddef.buildderefimpl;
  2190. begin
  2191. end;
  2192. procedure tstoreddef.deref;
  2193. var
  2194. symderef : pderef;
  2195. i : longint;
  2196. begin
  2197. typesym:=ttypesym(typesymderef.resolve);
  2198. if df_specialization in defoptions then
  2199. genericdef:=tstoreddef(genericdefderef.resolve);
  2200. if assigned(rtti_attribute_list) then
  2201. rtti_attribute_list.deref;
  2202. if assigned(genconstraintdata) then
  2203. genconstraintdata.deref;
  2204. if assigned(genericparas) then
  2205. begin
  2206. if not assigned(genericparaderefs) then
  2207. internalerror(2014052302);
  2208. if genericparas.count<>genericparaderefs.count then
  2209. internalerror(2014052303);
  2210. for i:=0 to genericparaderefs.count-1 do
  2211. begin
  2212. symderef:=pderef(genericparaderefs[i]);
  2213. genericparas.items[i]:=symderef^.resolve;
  2214. end;
  2215. end;
  2216. end;
  2217. procedure tstoreddef.derefimpl;
  2218. begin
  2219. end;
  2220. function tstoreddef.size : asizeint;
  2221. begin
  2222. size:=savesize;
  2223. end;
  2224. function tstoreddef.getvardef:longint;
  2225. begin
  2226. result:=varUndefined;
  2227. end;
  2228. function tstoreddef.alignment : shortint;
  2229. begin
  2230. { natural alignment by default }
  2231. alignment:=size_2_align(savesize);
  2232. { can happen if savesize = 0, e.g. for voiddef or
  2233. an empty record
  2234. }
  2235. if (alignment=0) then
  2236. alignment:=1;
  2237. end;
  2238. { returns true, if the definition can be published }
  2239. function tstoreddef.is_publishable : boolean;
  2240. begin
  2241. is_publishable:=false;
  2242. end;
  2243. { needs an init table }
  2244. function tstoreddef.needs_inittable : boolean;
  2245. begin
  2246. needs_inittable:=false;
  2247. end;
  2248. function tstoreddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  2249. begin
  2250. result:=false;
  2251. end;
  2252. function tstoreddef.is_intregable : boolean;
  2253. {$ifndef cpuhighleveltarget}
  2254. var
  2255. recsize,temp: longint;
  2256. {$endif cpuhighleveltarget}
  2257. begin
  2258. case typ of
  2259. orddef,
  2260. pointerdef,
  2261. enumdef,
  2262. classrefdef:
  2263. is_intregable:=true;
  2264. procvardef :
  2265. is_intregable:=tprocvardef(self).is_addressonly or (po_methodpointer in tprocvardef(self).procoptions);
  2266. objectdef:
  2267. is_intregable:=(is_implicit_pointer_object_type(self)) and not needs_inittable;
  2268. setdef:
  2269. is_intregable:=is_smallset(self);
  2270. arraydef:
  2271. {$ifdef cpuhighleveltarget}
  2272. is_intregable:=false
  2273. {$else cpuhighleveltarget}
  2274. is_intregable:=not(is_special_array(self)) and
  2275. (tarraydef(self).size<=8) and (tarraydef(self).size in [1,2,4,8]) and
  2276. tstoreddef(tarraydef(self).elementdef).is_intregable
  2277. {$ifdef SUPPORT_MMX}
  2278. and not((cs_mmx in current_settings.localswitches) and
  2279. is_mmx_able_array(self))
  2280. {$endif SUPPORT_MMX}
  2281. {$endif cpuhighleveltarget}
  2282. ;
  2283. recorddef:
  2284. begin
  2285. {$ifdef cpuhighleveltarget}
  2286. is_intregable:=false;
  2287. {$else cpuhighleveltarget}
  2288. recsize:=size;
  2289. is_intregable:=
  2290. ispowerof2(recsize,temp) and
  2291. ((recsize<=sizeof(aint)*2) and
  2292. not trecorddef(self).contains_cross_aword_field and
  2293. { records cannot go into registers on 16 bit targets for now }
  2294. (sizeof(aint)>2) and
  2295. not trecorddef(self).contains_float_field
  2296. ) and
  2297. not needs_inittable;
  2298. {$endif cpuhighleveltarget}
  2299. end;
  2300. else
  2301. is_intregable:=false;
  2302. end;
  2303. end;
  2304. function tstoreddef.is_fpuregable : boolean;
  2305. begin
  2306. {$ifdef x86}
  2307. result:=use_vectorfpu(self);
  2308. {$else x86}
  2309. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches)
  2310. {$ifdef xtensa}
  2311. and (FPUXTENSA_SINGLE in fpu_capabilities[init_settings.fputype]) and (tfloatdef(self).floattype=s32real)
  2312. {$endif xtensa}
  2313. {$ifdef arm}
  2314. and (((FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[init_settings.fputype]) and (tfloatdef(self).floattype=s32real)) or
  2315. (FPUARM_HAS_VFP_DOUBLE in fpu_capabilities[init_settings.fputype]))
  2316. {$endif arm}
  2317. ;
  2318. {$endif x86}
  2319. end;
  2320. function tstoreddef.is_const_intregable : boolean;
  2321. begin
  2322. case typ of
  2323. stringdef:
  2324. result:=tstringdef(self).stringtype in [st_ansistring,st_unicodestring,st_widestring];
  2325. arraydef:
  2326. result:=is_dynamic_array(self);
  2327. objectdef:
  2328. result:=is_interface(self);
  2329. else
  2330. result:=false;
  2331. end;
  2332. end;
  2333. procedure tstoreddef.initgeneric;
  2334. begin
  2335. if assigned(generictokenbuf) then
  2336. internalerror(200512131);
  2337. generictokenbuf:=tdynamicarray.create(256);
  2338. end;
  2339. function tstoreddef.is_generic: boolean;
  2340. var
  2341. sym: tsym;
  2342. i: longint;
  2343. begin
  2344. result:=assigned(genericparas) and
  2345. (genericparas.count>0) and
  2346. (df_generic in defoptions);
  2347. if result then
  2348. { if any of the type parameters does *not* belong to as (meaning it was passed
  2349. in from outside) then we aren't a generic, but a specialization }
  2350. for i:=0 to genericparas.count-1 do
  2351. begin
  2352. sym:=tsym(genericparas[i]);
  2353. { sym must be either a type or const }
  2354. if not (sym.typ in [symconst.typesym,symconst.constsym]) then
  2355. internalerror(2014050903);
  2356. if (sym.owner.defowner<>self) or (sp_generic_unnamed_type in sym.symoptions) then
  2357. exit(false);
  2358. if (sym.typ=symconst.constsym) and (sp_generic_const in sym.symoptions) then
  2359. exit(false);
  2360. end;
  2361. end;
  2362. function tstoreddef.is_generic_param_const(index:integer):boolean;
  2363. begin
  2364. result:=tsym(genericparas[index]).typ=constsym;
  2365. end;
  2366. function tstoreddef.get_generic_param_def(index:integer):tdef;
  2367. begin
  2368. if tsym(genericparas[index]).typ=constsym then
  2369. result:=tconstsym(genericparas[index]).constdef
  2370. else
  2371. result:=ttypesym(genericparas[index]).typedef;
  2372. end;
  2373. function tstoreddef.is_specialization: boolean;
  2374. var
  2375. i : longint;
  2376. sym : tsym;
  2377. begin
  2378. result:=assigned(genericparas) and
  2379. (genericparas.count>0) and
  2380. (df_specialization in defoptions);
  2381. if result then
  2382. begin
  2383. { if at least one of the generic parameters is not owned by us (meaning it was
  2384. passed in from outside) then we have a specialization, otherwise we have a generic }
  2385. for i:=0 to genericparas.count-1 do
  2386. begin
  2387. sym:=tsym(genericparas[i]);
  2388. { sym must be either a type or const }
  2389. if not (sym.typ in [symconst.typesym,symconst.constsym]) then
  2390. internalerror(2014050904);
  2391. if (sym.owner.defowner<>self) or (sp_generic_unnamed_type in sym.symoptions) then
  2392. exit(true);
  2393. if (sym.typ=symconst.constsym) and (sp_generic_const in sym.symoptions) then
  2394. exit(true);
  2395. end;
  2396. result:=false;
  2397. end;
  2398. end;
  2399. procedure tstoreddef.register_def;
  2400. var
  2401. gst : tgetsymtable;
  2402. st : tsymtable;
  2403. begin
  2404. if registered then
  2405. exit;
  2406. { Register in current_module }
  2407. if assigned(current_module) then
  2408. begin
  2409. exclude(defoptions,df_not_registered_no_free);
  2410. for gst:=low(tgetsymtable) to high(tgetsymtable) do
  2411. begin
  2412. st:=getsymtable(gst);
  2413. if assigned(st) then
  2414. tstoredsymtable(st).register_children;
  2415. end;
  2416. if defid<defid_not_registered then
  2417. defid:=deflist_index
  2418. else
  2419. begin
  2420. current_module.deflist.Add(self);
  2421. defid:=current_module.deflist.Count-1;
  2422. registered_in_module:=current_module;
  2423. end;
  2424. maybe_put_in_symtable_stack;
  2425. end
  2426. else
  2427. DefId:=defid_registered_nost;
  2428. end;
  2429. procedure tstoreddef.maybe_put_in_symtable_stack;
  2430. var
  2431. insertstack: psymtablestackitem;
  2432. begin
  2433. if assigned(symtablestack) and
  2434. not assigned(self.owner) then
  2435. begin
  2436. insertstack:=symtablestack.stack;
  2437. { don't insert defs in exception symtables, as they are freed before
  2438. the module is compiled, so we can get crashes on high level targets
  2439. if they still need it while e.g. writing assembler code }
  2440. while assigned(insertstack) and
  2441. (insertstack^.symtable.symtabletype in [stt_exceptsymtable,withsymtable]) do
  2442. insertstack:=insertstack^.next;
  2443. if not assigned(insertstack) then
  2444. internalerror(200602044);
  2445. if insertstack^.symtable.sealed then
  2446. internalerror(2015022301);
  2447. insertstack^.symtable.insertdef(self);
  2448. end;
  2449. end;
  2450. {****************************************************************************
  2451. Tstringdef
  2452. ****************************************************************************}
  2453. constructor tstringdef.createshort(l: byte; doregister: boolean);
  2454. begin
  2455. inherited create(stringdef,doregister);
  2456. stringtype:=st_shortstring;
  2457. encoding:=0;
  2458. len:=l;
  2459. end;
  2460. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  2461. begin
  2462. inherited ppuload(stringdef,ppufile);
  2463. stringtype:=st_shortstring;
  2464. encoding:=0;
  2465. len:=ppufile.getbyte;
  2466. ppuload_platform(ppufile);
  2467. end;
  2468. constructor tstringdef.createlong(l: asizeint; doregister: boolean);
  2469. begin
  2470. inherited create(stringdef,doregister);
  2471. stringtype:=st_longstring;
  2472. encoding:=0;
  2473. len:=l;
  2474. end;
  2475. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  2476. begin
  2477. inherited ppuload(stringdef,ppufile);
  2478. stringtype:=st_longstring;
  2479. encoding:=0;
  2480. len:=ppufile.getasizeint;
  2481. ppuload_platform(ppufile);
  2482. end;
  2483. constructor tstringdef.createansi(aencoding: tstringencoding; doregister: boolean);
  2484. begin
  2485. inherited create(stringdef,doregister);
  2486. stringtype:=st_ansistring;
  2487. encoding:=aencoding;
  2488. len:=-1;
  2489. end;
  2490. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  2491. begin
  2492. inherited ppuload(stringdef,ppufile);
  2493. stringtype:=st_ansistring;
  2494. len:=ppufile.getasizeint;
  2495. encoding:=ppufile.getword;
  2496. ppuload_platform(ppufile);
  2497. end;
  2498. constructor tstringdef.createwide(doregister: boolean);
  2499. begin
  2500. inherited create(stringdef,doregister);
  2501. stringtype:=st_widestring;
  2502. if target_info.endian=endian_little then
  2503. encoding:=CP_UTF16LE
  2504. else
  2505. encoding:=CP_UTF16BE;
  2506. len:=-1;
  2507. end;
  2508. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  2509. begin
  2510. inherited ppuload(stringdef,ppufile);
  2511. stringtype:=st_widestring;
  2512. if target_info.endian=endian_little then
  2513. encoding:=CP_UTF16LE
  2514. else
  2515. encoding:=CP_UTF16BE;
  2516. len:=ppufile.getasizeint;
  2517. ppuload_platform(ppufile);
  2518. end;
  2519. constructor tstringdef.createunicode(doregister: boolean);
  2520. begin
  2521. inherited create(stringdef,doregister);
  2522. stringtype:=st_unicodestring;
  2523. if target_info.endian=endian_little then
  2524. encoding:=CP_UTF16LE
  2525. else
  2526. encoding:=CP_UTF16BE;
  2527. len:=-1;
  2528. end;
  2529. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  2530. begin
  2531. inherited ppuload(stringdef,ppufile);
  2532. stringtype:=st_unicodestring;
  2533. len:=ppufile.getasizeint;
  2534. encoding:=ppufile.getword;
  2535. ppuload_platform(ppufile);
  2536. end;
  2537. function tstringdef.getcopy : tstoreddef;
  2538. begin
  2539. result:=cstringdef.create(typ,true);
  2540. result.typ:=stringdef;
  2541. tstringdef(result).stringtype:=stringtype;
  2542. tstringdef(result).encoding:=encoding;
  2543. tstringdef(result).len:=len;
  2544. end;
  2545. function tstringdef.stringtypname:string;
  2546. const
  2547. typname:array[tstringtype] of string[10]=(
  2548. 'shortstr','longstr','ansistr','widestr','unicodestr'
  2549. );
  2550. begin
  2551. stringtypname:=typname[stringtype];
  2552. end;
  2553. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  2554. begin
  2555. inherited ppuwrite(ppufile);
  2556. if stringtype=st_shortstring then
  2557. begin
  2558. {$ifdef extdebug}
  2559. if len > 255 then internalerror(12122002);
  2560. {$endif}
  2561. ppufile.putbyte(byte(len))
  2562. end
  2563. else
  2564. ppufile.putasizeint(len);
  2565. if stringtype in [st_ansistring,st_unicodestring] then
  2566. ppufile.putword(encoding);
  2567. case stringtype of
  2568. st_shortstring : writeentry(ppufile,ibshortstringdef);
  2569. st_longstring : writeentry(ppufile,iblongstringdef);
  2570. st_ansistring : writeentry(ppufile,ibansistringdef);
  2571. st_widestring : writeentry(ppufile,ibwidestringdef);
  2572. st_unicodestring : writeentry(ppufile,ibunicodestringdef);
  2573. end;
  2574. end;
  2575. function tstringdef.needs_inittable : boolean;
  2576. begin
  2577. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  2578. end;
  2579. function tstringdef.GetTypeName : string;
  2580. const
  2581. names : array[tstringtype] of string[15] = (
  2582. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  2583. begin
  2584. GetTypeName:=names[stringtype];
  2585. case stringtype of
  2586. st_ansistring,st_unicodestring:
  2587. GetTypeName:=GetTypeName+'('+tostr(encoding)+')';
  2588. st_shortstring:
  2589. GetTypeName:=GetTypeName+'['+tostr(len)+']';
  2590. else
  2591. ;
  2592. end;
  2593. end;
  2594. function tstringdef.getvardef : longint;
  2595. const
  2596. vardef : array[tstringtype] of longint = (
  2597. varUndefined,varUndefined,varString,varOleStr,varUString);
  2598. begin
  2599. result:=vardef[stringtype];
  2600. end;
  2601. function tstringdef.get_default_char_type: tdef;
  2602. begin
  2603. case stringtype of
  2604. st_shortstring,
  2605. st_longstring,
  2606. st_ansistring:
  2607. result:=cansichartype;
  2608. st_unicodestring,
  2609. st_widestring:
  2610. result:=cwidechartype;
  2611. end;
  2612. end;
  2613. function tstringdef.get_default_string_type: tdef;
  2614. begin
  2615. case stringtype of
  2616. st_shortstring:
  2617. result:=cshortstringtype;
  2618. { st_longstring is currently not supported but
  2619. when it is this case will need to be supplied }
  2620. st_longstring:
  2621. internalerror(2021040801);
  2622. st_ansistring:
  2623. result:=cansistringtype;
  2624. st_widestring:
  2625. result:=cwidestringtype;
  2626. st_unicodestring:
  2627. result:=cunicodestringtype;
  2628. end
  2629. end;
  2630. function tstringdef.alignment : shortint;
  2631. begin
  2632. case stringtype of
  2633. st_unicodestring,
  2634. st_widestring,
  2635. st_ansistring:
  2636. alignment:=voidpointertype.alignment;
  2637. st_longstring,
  2638. st_shortstring:
  2639. { char to string accesses byte 0 and 1 with one word access }
  2640. if (tf_requires_proper_alignment in target_info.flags) or
  2641. { macpas needs an alignment of 2 (MetroWerks compatible) }
  2642. (m_mac in current_settings.modeswitches) then
  2643. alignment:=size_2_align(2)
  2644. else
  2645. alignment:=size_2_align(1);
  2646. end;
  2647. end;
  2648. function tstringdef.getmangledparaname : TSymStr;
  2649. begin
  2650. getmangledparaname:='STRING';
  2651. end;
  2652. function tstringdef.is_publishable : boolean;
  2653. begin
  2654. is_publishable:=true;
  2655. end;
  2656. function tstringdef.size: asizeint;
  2657. begin
  2658. case stringtype of
  2659. st_shortstring:
  2660. Result:=len+1;
  2661. st_longstring,
  2662. st_ansistring,
  2663. st_widestring,
  2664. st_unicodestring:
  2665. Result:=voidpointertype.size;
  2666. end;
  2667. end;
  2668. {****************************************************************************
  2669. TENUMDEF
  2670. ****************************************************************************}
  2671. constructor tenumdef.create;
  2672. begin
  2673. inherited create(enumdef,true);
  2674. minval:=0;
  2675. maxval:=0;
  2676. calcsavesize(current_settings.packenum);
  2677. has_jumps:=false;
  2678. basedef:=nil;
  2679. basedefderef.reset;
  2680. symtable:=tenumsymtable.create(self);
  2681. end;
  2682. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  2683. begin
  2684. inherited create(enumdef,true);
  2685. minval:=_min;
  2686. maxval:=_max;
  2687. basedef:=_basedef;
  2688. calcsavesize(current_settings.packenum);
  2689. has_jumps:=false;
  2690. symtable:=basedef.symtable.getcopy;
  2691. include(defoptions, df_copied_def);
  2692. end;
  2693. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  2694. begin
  2695. inherited ppuload(enumdef,ppufile);
  2696. minval:=ppufile.getaint;
  2697. maxval:=ppufile.getaint;
  2698. savesize:=ppufile.getaint;
  2699. has_jumps:=false;
  2700. if df_copied_def in defoptions then
  2701. begin
  2702. symtable:=nil;
  2703. ppufile.getderef(basedefderef);
  2704. ppuload_platform(ppufile);
  2705. end
  2706. else
  2707. begin
  2708. ppuload_platform(ppufile);
  2709. // create with nil defowner first to prevent values changes on insert
  2710. symtable:=tenumsymtable.create(nil);
  2711. tenumsymtable(symtable).ppuload(ppufile);
  2712. symtable.defowner:=self;
  2713. end;
  2714. end;
  2715. destructor tenumdef.destroy;
  2716. begin
  2717. symtable.free;
  2718. symtable:=nil;
  2719. inherited destroy;
  2720. end;
  2721. function tenumdef.getcopy : tstoreddef;
  2722. begin
  2723. if assigned(basedef) then
  2724. result:=cenumdef.create_subrange(basedef,minval,maxval)
  2725. else
  2726. begin
  2727. result:=cenumdef.create;
  2728. tenumdef(result).minval:=minval;
  2729. tenumdef(result).maxval:=maxval;
  2730. tenumdef(result).symtable.free;
  2731. tenumdef(result).symtable:=symtable.getcopy;
  2732. tenumdef(result).basedef:=self;
  2733. end;
  2734. tenumdef(result).has_jumps:=has_jumps;
  2735. tenumdef(result).basedefderef:=basedefderef;
  2736. include(tenumdef(result).defoptions,df_copied_def);
  2737. end;
  2738. procedure tenumdef.calcsavesize(packenum: shortint);
  2739. begin
  2740. {$IFNDEF cpu64bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2741. if (packenum=8) or (int64(min)<low(longint)) or (int64(max)>high(cardinal)) then
  2742. savesize:=8
  2743. {$IFNDEF cpu64bitaddr} {$pop} {$ENDIF}
  2744. else
  2745. {$IFDEF cpu16bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2746. if (packenum=4) or (min<low(smallint)) or (max>high(word)) then
  2747. savesize:=4
  2748. {$IFDEF cpu16bitaddr} {$pop} {$ENDIF}
  2749. else
  2750. if (packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  2751. savesize:=2
  2752. else
  2753. savesize:=1;
  2754. end;
  2755. function tenumdef.packedbitsize: asizeint;
  2756. var
  2757. sizeval: tconstexprint;
  2758. power: longint;
  2759. begin
  2760. result := 0;
  2761. if (minval >= 0) and
  2762. (maxval <= 1) then
  2763. result := 1
  2764. else
  2765. begin
  2766. if (minval>=0) then
  2767. sizeval:=maxval
  2768. else
  2769. { don't count 0 twice, but take into account that range goes from -n-1..n }
  2770. sizeval:=(cutils.max(-minval,maxval+1)*2)-1;
  2771. { 256 must become 512 etc. }
  2772. nextpowerof2(sizeval+1,power);
  2773. result := power;
  2774. end;
  2775. end;
  2776. procedure tenumdef.setmax(_max:asizeint);
  2777. begin
  2778. maxval:=_max;
  2779. calcsavesize(current_settings.packenum);
  2780. end;
  2781. procedure tenumdef.setmin(_min:asizeint);
  2782. begin
  2783. minval:=_min;
  2784. calcsavesize(current_settings.packenum);
  2785. end;
  2786. function tenumdef.min:asizeint;
  2787. begin
  2788. min:=minval;
  2789. end;
  2790. function tenumdef.max:asizeint;
  2791. begin
  2792. max:=maxval;
  2793. end;
  2794. function tenumdef.getfirstsym: tsym;
  2795. var
  2796. i:integer;
  2797. begin
  2798. for i := 0 to symtable.SymList.Count - 1 do
  2799. begin
  2800. result:=tsym(symtable.SymList[i]);
  2801. if tenumsym(result).value=minval then
  2802. exit;
  2803. end;
  2804. result:=nil;
  2805. end;
  2806. function tenumdef.int2enumsym(l: asizeint): tsym;
  2807. var
  2808. i: longint;
  2809. sym: tsym;
  2810. bdef: tenumdef;
  2811. begin
  2812. result:=nil;
  2813. if (l<minval) or
  2814. (l>maxval) then
  2815. exit;
  2816. bdef:=getbasedef;
  2817. for i:=0 to bdef.symtable.symlist.count-1 do
  2818. begin
  2819. sym:=tsym(bdef.symtable.symlist[i]);
  2820. if (sym.typ=enumsym) and
  2821. (tenumsym(sym).value=l) then
  2822. begin
  2823. result:=sym;
  2824. exit;
  2825. end;
  2826. end;
  2827. end;
  2828. function tenumdef.getbasedef: tenumdef;
  2829. begin
  2830. if not assigned(basedef) then
  2831. result:=self
  2832. else
  2833. result:=basedef;
  2834. end;
  2835. procedure tenumdef.buildderef;
  2836. begin
  2837. inherited buildderef;
  2838. if df_copied_def in defoptions then
  2839. basedefderef.build(basedef)
  2840. else
  2841. tenumsymtable(symtable).buildderef;
  2842. end;
  2843. procedure tenumdef.deref;
  2844. begin
  2845. inherited deref;
  2846. if df_copied_def in defoptions then
  2847. begin
  2848. basedef:=tenumdef(basedefderef.resolve);
  2849. symtable:=basedef.symtable.getcopy;
  2850. end
  2851. else
  2852. tenumsymtable(symtable).deref(false);
  2853. end;
  2854. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  2855. begin
  2856. inherited ppuwrite(ppufile);
  2857. ppufile.putaint(min);
  2858. ppufile.putaint(max);
  2859. ppufile.putaint(savesize);
  2860. if df_copied_def in defoptions then
  2861. ppufile.putderef(basedefderef);
  2862. writeentry(ppufile,ibenumdef);
  2863. if not (df_copied_def in defoptions) then
  2864. tenumsymtable(symtable).ppuwrite(ppufile);
  2865. end;
  2866. function tenumdef.is_publishable : boolean;
  2867. begin
  2868. is_publishable:=true;
  2869. end;
  2870. function tenumdef.GetTypeName : string;
  2871. begin
  2872. GetTypeName:='<enumeration type>';
  2873. end;
  2874. {****************************************************************************
  2875. TRTTI_ATTRIBUTE_LIST
  2876. ****************************************************************************}
  2877. constructor trtti_attribute.ppuload(ppufile: tcompilerppufile);
  2878. begin
  2879. ppufile.getderef(typesymderef);
  2880. ppufile.getderef(typeconstrderef);
  2881. setlength(paras,ppufile.getlongint);
  2882. end;
  2883. procedure trtti_attribute.ppuwrite(ppufile: tcompilerppufile);
  2884. begin
  2885. ppufile.putderef(typesymderef);
  2886. ppufile.putderef(typeconstrderef);
  2887. ppufile.putlongint(length(paras));
  2888. end;
  2889. procedure trtti_attribute.ppuload_subentries(ppufile: tcompilerppufile);
  2890. var
  2891. i : sizeint;
  2892. begin
  2893. for i:=0 to high(paras) do
  2894. paras[i]:=ppuloadnodetree(ppufile);
  2895. end;
  2896. procedure trtti_attribute.ppuwrite_subentries(ppufile: tcompilerppufile);
  2897. var
  2898. i : sizeint;
  2899. begin
  2900. for i:=0 to high(paras) do
  2901. ppuwritenodetree(ppufile,paras[i]);
  2902. end;
  2903. destructor trtti_attribute.destroy;
  2904. var
  2905. n : tnode;
  2906. begin
  2907. constructorcall.free;
  2908. for n in paras do
  2909. n.free;
  2910. inherited destroy;
  2911. end;
  2912. procedure trtti_attribute.buildderef;
  2913. var
  2914. i : sizeint;
  2915. begin
  2916. typesymderef.build(typesym);
  2917. typeconstrderef.build(typeconstr);
  2918. for i:=0 to high(paras) do
  2919. paras[i].buildderefimpl;
  2920. end;
  2921. procedure trtti_attribute.deref;
  2922. var
  2923. i : sizeint;
  2924. begin
  2925. typesym:=tsym(typesymderef.resolve);
  2926. typeconstr:=tdef(typeconstrderef.resolve);
  2927. for i:=0 to high(paras) do
  2928. paras[i].derefimpl;
  2929. end;
  2930. class procedure trtti_attribute_list.bind(var dangling,owned:trtti_attribute_list);
  2931. begin
  2932. if assigned(owned) then
  2933. internalerror(2019071001);
  2934. if not assigned(dangling) then
  2935. exit;
  2936. if dangling.is_bound then
  2937. internalerror(2019071002);
  2938. current_module.used_rtti_attrs.concatlistcopy(dangling.rtti_attributes);
  2939. dangling.is_bound:=true;
  2940. owned:=dangling;
  2941. dangling:=nil;
  2942. end;
  2943. procedure trtti_attribute_list.addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  2944. var
  2945. newattribute : trtti_attribute;
  2946. i : sizeint;
  2947. begin
  2948. if not assigned(rtti_attributes) then
  2949. rtti_attributes:=TFPObjectList.Create(true);
  2950. newattribute:=trtti_attribute.Create;
  2951. newattribute.typesym:=atypesym;
  2952. newattribute.typeconstr:=typeconstr;
  2953. newattribute.constructorcall:=constructorcall;
  2954. setlength(newattribute.paras,length(paras));
  2955. for i:=0 to high(paras) do
  2956. newattribute.paras[i]:=paras[i];
  2957. rtti_attributes.Add(newattribute);
  2958. end;
  2959. procedure trtti_attribute_list.addattribute(attr:trtti_attribute);
  2960. begin
  2961. if not assigned(rtti_attributes) then
  2962. rtti_attributes:=TFPObjectList.Create(true);
  2963. rtti_attributes.add(attr);
  2964. end;
  2965. destructor trtti_attribute_list.destroy;
  2966. begin
  2967. rtti_attributes.Free;
  2968. inherited destroy;
  2969. end;
  2970. function trtti_attribute_list.get_attribute_count:longint;
  2971. begin
  2972. if assigned(rtti_attributes) then
  2973. result:=rtti_attributes.Count
  2974. else
  2975. result:=0;
  2976. end;
  2977. procedure trtti_attribute_list.buildderef;
  2978. var
  2979. i : sizeint;
  2980. begin
  2981. if not assigned(rtti_attributes) then
  2982. exit;
  2983. for i:=0 to rtti_attributes.count-1 do
  2984. trtti_attribute(rtti_attributes[i]).buildderef;
  2985. end;
  2986. procedure trtti_attribute_list.deref;
  2987. var
  2988. i : sizeint;
  2989. begin
  2990. if not assigned(rtti_attributes) then
  2991. exit;
  2992. for i:=0 to rtti_attributes.count-1 do
  2993. trtti_attribute(rtti_attributes[i]).deref;
  2994. end;
  2995. class procedure trtti_attribute_list.ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  2996. var
  2997. i : sizeint;
  2998. begin
  2999. if assigned(attrlist) then
  3000. begin
  3001. if not assigned(attrlist.rtti_attributes) then
  3002. internalerror(2019071101);
  3003. for i:=0 to attrlist.rtti_attributes.count-1 do
  3004. trtti_attribute(attrlist.rtti_attributes[i]).ppuload_subentries(ppufile);
  3005. end;
  3006. end;
  3007. class procedure trtti_attribute_list.ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3008. var
  3009. i : sizeint;
  3010. begin
  3011. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  3012. begin
  3013. for i:=0 to attrlist.rtti_attributes.count-1 do
  3014. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite_subentries(ppufile);
  3015. end;
  3016. end;
  3017. class function trtti_attribute_list.ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  3018. var
  3019. cnt,i : longint;
  3020. begin
  3021. cnt:=ppufile.getlongint;
  3022. if cnt>0 then
  3023. begin
  3024. result:=trtti_attribute_list.create;
  3025. for i:=0 to cnt-1 do
  3026. result.addattribute(trtti_attribute.ppuload(ppufile));
  3027. end
  3028. else
  3029. result:=nil;
  3030. end;
  3031. class procedure trtti_attribute_list.ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  3032. var
  3033. i : longint;
  3034. begin
  3035. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  3036. begin
  3037. ppufile.putlongint(attrlist.rtti_attributes.count);
  3038. for i:=0 to attrlist.rtti_attributes.count-1 do
  3039. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite(ppufile);
  3040. end
  3041. else
  3042. ppufile.putlongint(0);
  3043. end;
  3044. {****************************************************************************
  3045. TORDDEF
  3046. ****************************************************************************}
  3047. constructor torddef.create(t : tordtype;v,b : TConstExprInt; doregister: boolean);
  3048. begin
  3049. inherited create(orddef,doregister);
  3050. low:=v;
  3051. high:=b;
  3052. ordtype:=t;
  3053. setsize;
  3054. end;
  3055. constructor torddef.ppuload(ppufile:tcompilerppufile);
  3056. begin
  3057. inherited ppuload(orddef,ppufile);
  3058. ordtype:=tordtype(ppufile.getbyte);
  3059. low:=ppufile.getexprint;
  3060. high:=ppufile.getexprint;
  3061. setsize;
  3062. ppuload_platform(ppufile);
  3063. end;
  3064. function torddef.getcopy : tstoreddef;
  3065. begin
  3066. result:=corddef.create(ordtype,low,high,true);
  3067. result.typ:=orddef;
  3068. torddef(result).low:=low;
  3069. torddef(result).high:=high;
  3070. torddef(result).ordtype:=ordtype;
  3071. torddef(result).savesize:=savesize;
  3072. end;
  3073. function torddef.alignment:shortint;
  3074. begin
  3075. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) and
  3076. (ordtype in [s64bit,u64bit]) then
  3077. result := 4
  3078. else
  3079. result := inherited alignment;
  3080. end;
  3081. procedure torddef.setsize;
  3082. const
  3083. sizetbl : array[tordtype] of longint = (
  3084. 0,
  3085. 1,2,4,8,16,
  3086. 1,2,4,8,16,
  3087. 1,1,2,4,8,
  3088. 1,2,4,8,
  3089. 1,2,8,system.high(longint)
  3090. );
  3091. begin
  3092. savesize:=sizetbl[ordtype];
  3093. if savesize=system.high(longint) then
  3094. savesize:=packedbitsize div 8;
  3095. end;
  3096. function torddef.packedbitsize: asizeint;
  3097. var
  3098. sizeval: tconstexprint;
  3099. power: longint;
  3100. begin
  3101. result := 0;
  3102. if ordtype = uvoid then
  3103. exit;
  3104. {$ifndef cpu64bitalu}
  3105. if (ordtype in [s64bit,u64bit]) then
  3106. {$else not cpu64bitalu}
  3107. if ((ordtype = u64bit) and
  3108. (high > system.high(int64))) or
  3109. ((ordtype = s64bit) and
  3110. ((low <= (system.low(int64) div 2)) or
  3111. ((low < 0) and
  3112. (high > (system.high(int64) div 2))))) then
  3113. {$endif cpu64bitalu}
  3114. result := 64
  3115. else if (
  3116. (low >= 0) and
  3117. (high <= 1)
  3118. ) or (
  3119. ordtype in [pasbool1,pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]
  3120. ) then
  3121. result := 1
  3122. else
  3123. begin
  3124. if (low>=0) then
  3125. sizeval:=high
  3126. else
  3127. { don't count 0 twice, but take into account that range goes from -n-1..n }
  3128. sizeval:=(cutils.max(-low,high+1)*2)-1;
  3129. { 256 must become 512 etc. }
  3130. nextpowerof2(sizeval+1,power);
  3131. result := power;
  3132. end;
  3133. end;
  3134. function torddef.getvardef : longint;
  3135. const
  3136. basetype2vardef : array[tordtype] of longint = (
  3137. varUndefined,
  3138. varbyte,varword,varlongword,varqword,varUndefined,
  3139. varshortint,varsmallint,varinteger,varint64,varUndefined,
  3140. varboolean,varboolean,varboolean,varboolean,varboolean,
  3141. varboolean,varboolean,varUndefined,varUndefined,
  3142. varUndefined,varUndefined,varCurrency,varEmpty);
  3143. begin
  3144. result:=basetype2vardef[ordtype];
  3145. if result=varEmpty then
  3146. result:=basetype2vardef[range_to_basetype(low,high)];
  3147. end;
  3148. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  3149. begin
  3150. inherited ppuwrite(ppufile);
  3151. ppufile.putbyte(byte(ordtype));
  3152. ppufile.putexprint(low);
  3153. ppufile.putexprint(high);
  3154. writeentry(ppufile,iborddef);
  3155. end;
  3156. function torddef.is_publishable : boolean;
  3157. begin
  3158. is_publishable:=(ordtype<>uvoid);
  3159. end;
  3160. function torddef.GetTypeName : string;
  3161. const
  3162. names : array[tordtype] of string[20] = (
  3163. 'untyped',
  3164. 'Byte','Word','DWord','QWord','UInt128',
  3165. 'ShortInt','SmallInt','LongInt','Int64','Int128',
  3166. 'Boolean','Boolean8','Boolean16','Boolean32','Boolean64',
  3167. 'ByteBool','WordBool','LongBool','QWordBool',
  3168. 'Char','WideChar','Currency','CustomRange');
  3169. begin
  3170. GetTypeName:=names[ordtype];
  3171. end;
  3172. {****************************************************************************
  3173. TFLOATDEF
  3174. ****************************************************************************}
  3175. constructor tfloatdef.create(t: tfloattype; doregister: boolean);
  3176. begin
  3177. inherited create(floatdef,doregister);
  3178. floattype:=t;
  3179. setsize;
  3180. end;
  3181. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  3182. begin
  3183. inherited ppuload(floatdef,ppufile);
  3184. floattype:=tfloattype(ppufile.getbyte);
  3185. setsize;
  3186. ppuload_platform(ppufile);
  3187. end;
  3188. function tfloatdef.getcopy : tstoreddef;
  3189. begin
  3190. result:=cfloatdef.create(floattype,true);
  3191. result.typ:=floatdef;
  3192. tfloatdef(result).savesize:=savesize;
  3193. end;
  3194. function tfloatdef.alignment:shortint;
  3195. begin
  3196. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) then
  3197. case floattype of
  3198. sc80real,
  3199. s80real: result:=16;
  3200. s64real,
  3201. s64currency,
  3202. s64comp : result:=4;
  3203. else
  3204. result := inherited alignment;
  3205. end
  3206. else
  3207. result := inherited alignment;
  3208. end;
  3209. function tfloatdef.structalignment: shortint;
  3210. begin
  3211. { aix is really annoying: the recommended scalar alignment for both
  3212. int64 and double is 64 bits, but in structs int64 has to be aligned
  3213. to 8 bytes and double to 4 bytes }
  3214. if (target_info.system in systems_aix) and
  3215. (floattype=s64real) then
  3216. result:=4
  3217. else
  3218. result:=alignment;
  3219. end;
  3220. procedure tfloatdef.setsize;
  3221. begin
  3222. case floattype of
  3223. s32real : savesize:=4;
  3224. s80real : savesize:=10;
  3225. sc80real:
  3226. if target_info.system in [system_i386_darwin,
  3227. system_i386_iphonesim,system_x86_64_darwin,
  3228. system_x86_64_iphonesim,
  3229. system_x86_64_linux,system_x86_64_freebsd,
  3230. system_x86_64_openbsd,system_x86_64_netbsd,
  3231. system_x86_64_solaris,system_x86_64_embedded,
  3232. system_x86_64_dragonfly,system_x86_64_haiku] then
  3233. savesize:=16
  3234. else
  3235. savesize:=12;
  3236. s64real,
  3237. s64currency,
  3238. s64comp : savesize:=8;
  3239. else
  3240. savesize:=0;
  3241. end;
  3242. end;
  3243. function tfloatdef.getvardef : longint;
  3244. const
  3245. floattype2vardef : array[tfloattype] of longint = (
  3246. varSingle,varDouble,varUndefined,varUndefined,
  3247. varUndefined,varCurrency,varUndefined);
  3248. begin
  3249. if (upper(typename)='TDATETIME') and
  3250. assigned(owner) and
  3251. assigned(owner.name) and
  3252. (owner.name^='SYSTEM') then
  3253. result:=varDate
  3254. else
  3255. result:=floattype2vardef[floattype];
  3256. end;
  3257. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  3258. begin
  3259. inherited ppuwrite(ppufile);
  3260. ppufile.putbyte(byte(floattype));
  3261. writeentry(ppufile,ibfloatdef);
  3262. end;
  3263. function tfloatdef.is_publishable : boolean;
  3264. begin
  3265. is_publishable:=true;
  3266. end;
  3267. function tfloatdef.GetTypeName : string;
  3268. const
  3269. names : array[tfloattype] of string[20] = (
  3270. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  3271. begin
  3272. GetTypeName:=names[floattype];
  3273. end;
  3274. {****************************************************************************
  3275. TFILEDEF
  3276. ****************************************************************************}
  3277. constructor tfiledef.createtext;
  3278. begin
  3279. inherited create(filedef,true);
  3280. filetyp:=ft_text;
  3281. typedfiledef:=nil;
  3282. typedfiledefderef.reset;
  3283. end;
  3284. constructor tfiledef.createuntyped;
  3285. begin
  3286. inherited create(filedef,true);
  3287. filetyp:=ft_untyped;
  3288. typedfiledef:=nil;
  3289. end;
  3290. constructor tfiledef.createtyped(def:tdef);
  3291. begin
  3292. inherited create(filedef,true);
  3293. filetyp:=ft_typed;
  3294. typedfiledef:=def;
  3295. end;
  3296. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  3297. begin
  3298. inherited ppuload(filedef,ppufile);
  3299. filetyp:=tfiletyp(ppufile.getbyte);
  3300. if filetyp=ft_typed then
  3301. ppufile.getderef(typedfiledefderef)
  3302. else
  3303. typedfiledef:=nil;
  3304. ppuload_platform(ppufile);
  3305. end;
  3306. function tfiledef.getcopy : tstoreddef;
  3307. begin
  3308. case filetyp of
  3309. ft_typed:
  3310. result:=cfiledef.createtyped(typedfiledef);
  3311. ft_untyped:
  3312. result:=cfiledef.createuntyped;
  3313. ft_text:
  3314. result:=cfiledef.createtext;
  3315. end;
  3316. end;
  3317. procedure tfiledef.buildderef;
  3318. begin
  3319. inherited buildderef;
  3320. if filetyp=ft_typed then
  3321. typedfiledefderef.build(typedfiledef);
  3322. end;
  3323. procedure tfiledef.deref;
  3324. begin
  3325. inherited deref;
  3326. if filetyp=ft_typed then
  3327. typedfiledef:=tdef(typedfiledefderef.resolve);
  3328. end;
  3329. function tfiledef.size:asizeint;
  3330. begin
  3331. if savesize=0 then
  3332. setsize;
  3333. size:=savesize;
  3334. end;
  3335. procedure tfiledef.setsize;
  3336. begin
  3337. case filetyp of
  3338. ft_text:
  3339. savesize:=search_system_type('TEXTREC').typedef.size;
  3340. ft_typed:
  3341. begin
  3342. savesize:=search_system_type('FILEREC').typedef.size;
  3343. { allocate put/get buffer in iso mode }
  3344. if m_isolike_io in current_settings.modeswitches then
  3345. inc(savesize,typedfiledef.size);
  3346. end;
  3347. ft_untyped:
  3348. savesize:=search_system_type('FILEREC').typedef.size;
  3349. end;
  3350. end;
  3351. function tfiledef.alignment: shortint;
  3352. begin
  3353. case filetyp of
  3354. ft_text:
  3355. result:=search_system_type('TEXTREC').typedef.alignment;
  3356. ft_typed,
  3357. ft_untyped:
  3358. result:=search_system_type('FILEREC').typedef.alignment;
  3359. end;
  3360. end;
  3361. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  3362. begin
  3363. inherited ppuwrite(ppufile);
  3364. ppufile.putbyte(byte(filetyp));
  3365. if filetyp=ft_typed then
  3366. ppufile.putderef(typedfiledefderef);
  3367. writeentry(ppufile,ibfiledef);
  3368. end;
  3369. function tfiledef.GetTypeName : string;
  3370. begin
  3371. case filetyp of
  3372. ft_untyped:
  3373. GetTypeName:='File';
  3374. ft_typed:
  3375. GetTypeName:='File Of '+typedfiledef.typename;
  3376. ft_text:
  3377. GetTypeName:='Text'
  3378. end;
  3379. end;
  3380. function tfiledef.getmangledparaname : TSymStr;
  3381. begin
  3382. case filetyp of
  3383. ft_untyped:
  3384. getmangledparaname:='FILE';
  3385. ft_typed:
  3386. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  3387. ft_text:
  3388. getmangledparaname:='TEXT'
  3389. end;
  3390. end;
  3391. {****************************************************************************
  3392. TVARIANTDEF
  3393. ****************************************************************************}
  3394. constructor tvariantdef.create(v : tvarianttype);
  3395. begin
  3396. inherited create(variantdef,true);
  3397. varianttype:=v;
  3398. setsize;
  3399. end;
  3400. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  3401. begin
  3402. inherited ppuload(variantdef,ppufile);
  3403. varianttype:=tvarianttype(ppufile.getbyte);
  3404. setsize;
  3405. ppuload_platform(ppufile);
  3406. end;
  3407. function tvariantdef.getcopy : tstoreddef;
  3408. begin
  3409. result:=cvariantdef.create(varianttype);
  3410. end;
  3411. function tvariantdef.alignment: shortint;
  3412. begin
  3413. result:=search_system_type('TVARDATA').typedef.alignment;
  3414. end;
  3415. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  3416. begin
  3417. inherited ppuwrite(ppufile);
  3418. ppufile.putbyte(byte(varianttype));
  3419. writeentry(ppufile,ibvariantdef);
  3420. end;
  3421. function tvariantdef.getvardef : longint;
  3422. begin
  3423. Result:=varVariant;
  3424. end;
  3425. procedure tvariantdef.setsize;
  3426. begin
  3427. {$ifdef cpu64bitaddr}
  3428. savesize:=24;
  3429. {$else cpu64bitaddr}
  3430. savesize:=16;
  3431. {$endif cpu64bitaddr}
  3432. end;
  3433. function tvariantdef.GetTypeName : string;
  3434. begin
  3435. case varianttype of
  3436. vt_normalvariant:
  3437. GetTypeName:='Variant';
  3438. vt_olevariant:
  3439. GetTypeName:='OleVariant';
  3440. end;
  3441. end;
  3442. function tvariantdef.needs_inittable : boolean;
  3443. begin
  3444. needs_inittable:=true;
  3445. end;
  3446. function tvariantdef.is_publishable : boolean;
  3447. begin
  3448. is_publishable:=true;
  3449. end;
  3450. {****************************************************************************
  3451. TABSTRACtpointerdef
  3452. ****************************************************************************}
  3453. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  3454. begin
  3455. inherited create(dt,true);
  3456. pointeddef:=def;
  3457. pointeddefderef.reset;
  3458. if df_generic in pointeddef.defoptions then
  3459. include(defoptions,df_generic);
  3460. if df_specialization in pointeddef.defoptions then
  3461. include(defoptions,df_specialization);
  3462. end;
  3463. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3464. begin
  3465. inherited ppuload(dt,ppufile);
  3466. ppufile.getderef(pointeddefderef);
  3467. end;
  3468. procedure tabstractpointerdef.buildderef;
  3469. begin
  3470. inherited buildderef;
  3471. pointeddefderef.build(pointeddef);
  3472. end;
  3473. procedure tabstractpointerdef.deref;
  3474. begin
  3475. inherited deref;
  3476. pointeddef:=tdef(pointeddefderef.resolve);
  3477. end;
  3478. function tabstractpointerdef.size: asizeint;
  3479. begin
  3480. Result:=voidpointertype.size;
  3481. end;
  3482. function tabstractpointerdef.alignment: shortint;
  3483. begin
  3484. alignment:=size_2_align(voidpointertype.size);
  3485. end;
  3486. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3487. begin
  3488. inherited ppuwrite(ppufile);
  3489. ppufile.putderef(pointeddefderef);
  3490. end;
  3491. {****************************************************************************
  3492. tpointerdef
  3493. ****************************************************************************}
  3494. constructor tpointerdef.create(def:tdef);
  3495. begin
  3496. inherited create(pointerdef,def);
  3497. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  3498. if (df_specialization in tstoreddef(def).defoptions)
  3499. {$ifndef genericdef_for_nested}
  3500. { currently, nested procdefs of generic routines get df_specialization,
  3501. but no genericdef }
  3502. and assigned(tstoreddef(def).genericdef)
  3503. {$endif}
  3504. then
  3505. genericdef:=cpointerdef.getreusable(tstoreddef(def).genericdef);
  3506. end;
  3507. class function tpointerdef.getreusable(def: tdef): tpointerdef;
  3508. var
  3509. res: PHashSetItem;
  3510. oldsymtablestack: tsymtablestack;
  3511. begin
  3512. if not assigned(current_module) then
  3513. internalerror(2011071101);
  3514. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  3515. if not assigned(res^.Data) then
  3516. begin
  3517. { since these pointerdefs can be reused anywhere in the current
  3518. unit, add them to the global/staticsymtable (or local symtable
  3519. if they're a local def, because otherwise they'll be saved
  3520. to the ppu referencing a local symtable entry that doesn't
  3521. exist in the ppu) }
  3522. oldsymtablestack:=symtablestack;
  3523. { do not simply push/pop current_module.localsymtable, because
  3524. that can have side-effects (e.g., it removes helpers) }
  3525. symtablestack:=nil;
  3526. result:=cpointerdef.create(def);
  3527. setup_reusable_def(def,result,res,oldsymtablestack);
  3528. { res^.Data may still be nil -> don't overwrite result }
  3529. exit;
  3530. end;
  3531. result:=tpointerdef(res^.Data);
  3532. end;
  3533. class function tpointerdef.getreusable_no_free(def: tdef): tpointerdef;
  3534. begin
  3535. result:=getreusable(def);
  3536. if not result.is_registered then
  3537. include(result.defoptions,df_not_registered_no_free);
  3538. end;
  3539. function tpointerdef.size: asizeint;
  3540. begin
  3541. result:=sizeof(pint);
  3542. end;
  3543. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  3544. begin
  3545. inherited ppuload(pointerdef,ppufile);
  3546. has_pointer_math:=(ppufile.getbyte<>0);
  3547. ppuload_platform(ppufile);
  3548. end;
  3549. function tpointerdef.getcopy : tstoreddef;
  3550. begin
  3551. { don't use direct pointeddef if it is a forwarddef because in other case
  3552. one of them will be destroyed on forward type resolve and the second will
  3553. point to garbage }
  3554. if pointeddef.typ=forwarddef then
  3555. result:=cpointerdef.create(tforwarddef(pointeddef).getcopy)
  3556. else
  3557. result:=cpointerdef.create(pointeddef);
  3558. tpointerdef(result).has_pointer_math:=has_pointer_math;
  3559. tpointerdef(result).savesize:=savesize;
  3560. end;
  3561. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3562. begin
  3563. inherited ppuwrite(ppufile);
  3564. ppufile.putbyte(byte(has_pointer_math));
  3565. writeentry(ppufile,ibpointerdef);
  3566. end;
  3567. function tpointerdef.GetTypeName : string;
  3568. begin
  3569. { parameter types and the resultdef of a procvardef can contain a
  3570. pointer to this procvardef itself, resulting in endless recursion ->
  3571. use the typesym's name instead if it exists (if it doesn't, such as
  3572. for anynonymous procedure types in macpas/iso mode, then there cannot
  3573. be any recursive references to it either) }
  3574. if (pointeddef.typ<>procvardef) or
  3575. not assigned(pointeddef.typesym) then
  3576. GetTypeName:='^'+pointeddef.typename
  3577. else
  3578. GetTypeName:='^'+pointeddef.typesym.realname;
  3579. end;
  3580. function tpointerdef.pointer_arithmetic_int_type:tdef;
  3581. begin
  3582. result:=ptrsinttype;
  3583. end;
  3584. function tpointerdef.pointer_arithmetic_uint_type:tdef;
  3585. begin
  3586. result:=ptruinttype;
  3587. end;
  3588. function tpointerdef.pointer_subtraction_result_type:tdef;
  3589. begin
  3590. result:=ptrsinttype;
  3591. end;
  3592. function tpointerdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  3593. begin
  3594. result:=true;
  3595. end;
  3596. function tpointerdef.converted_pointer_to_array_range_type:tdef;
  3597. begin
  3598. result:=ptrsinttype;
  3599. end;
  3600. {****************************************************************************
  3601. TCLASSREFDEF
  3602. ****************************************************************************}
  3603. constructor tclassrefdef.create(def:tdef);
  3604. begin
  3605. while (def.typ=objectdef) and tobjectdef(def).is_unique_objpasdef do
  3606. def:=tobjectdef(def).childof;
  3607. inherited create(classrefdef,def);
  3608. if df_specialization in tstoreddef(def).defoptions then
  3609. genericdef:=cclassrefdef.create(tstoreddef(def).genericdef);
  3610. end;
  3611. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  3612. begin
  3613. inherited ppuload(classrefdef,ppufile);
  3614. ppuload_platform(ppufile);
  3615. end;
  3616. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  3617. begin
  3618. inherited ppuwrite(ppufile);
  3619. writeentry(ppufile,ibclassrefdef);
  3620. end;
  3621. function tclassrefdef.getcopy:tstoreddef;
  3622. begin
  3623. if pointeddef.typ=forwarddef then
  3624. result:=cclassrefdef.create(tforwarddef(pointeddef).getcopy)
  3625. else
  3626. result:=cclassrefdef.create(pointeddef);
  3627. end;
  3628. function tclassrefdef.GetTypeName : string;
  3629. begin
  3630. GetTypeName:='Class Of '+pointeddef.typename;
  3631. end;
  3632. function tclassrefdef.is_publishable : boolean;
  3633. begin
  3634. result:=true;
  3635. end;
  3636. function tclassrefdef.rtti_mangledname(rt: trttitype): TSymStr;
  3637. begin
  3638. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  3639. result:=inherited rtti_mangledname(rt)
  3640. else
  3641. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  3642. end;
  3643. procedure tclassrefdef.register_created_object_type;
  3644. begin
  3645. tobjectdef(pointeddef).register_created_classref_type;
  3646. end;
  3647. {***************************************************************************
  3648. TSETDEF
  3649. ***************************************************************************}
  3650. constructor tsetdef.create(def: tdef; low, high: asizeint; doregister: boolean);
  3651. var
  3652. setallocbits: aint;
  3653. packedsavesize: aint;
  3654. actual_setalloc: ShortInt;
  3655. begin
  3656. inherited create(setdef,doregister);
  3657. elementdef:=def;
  3658. elementdefderef.reset;
  3659. setmax:=high;
  3660. actual_setalloc:=current_settings.setalloc;
  3661. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  3662. if actual_setalloc=0 then
  3663. actual_setalloc:=1;
  3664. {$endif}
  3665. if (actual_setalloc=0) then
  3666. begin
  3667. setbase:=0;
  3668. if (high<32) then
  3669. savesize:=Sizeof(longint)
  3670. else if (high<256) then
  3671. savesize:=32
  3672. else
  3673. savesize:=(high+7) div 8
  3674. end
  3675. else
  3676. begin
  3677. setallocbits:=actual_setalloc*8;
  3678. setbase:=low and not(setallocbits-1);
  3679. packedsavesize:=actual_setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  3680. savesize:=packedsavesize;
  3681. {$if not defined(cpu8bitalu) and not defined(cpu16bitalu)}
  3682. if savesize=3 then
  3683. savesize:=4;
  3684. {$endif}
  3685. end;
  3686. end;
  3687. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  3688. begin
  3689. inherited ppuload(setdef,ppufile);
  3690. ppufile.getderef(elementdefderef);
  3691. savesize:=ppufile.getasizeint;
  3692. setbase:=ppufile.getasizeint;
  3693. setmax:=ppufile.getasizeint;
  3694. ppuload_platform(ppufile);
  3695. end;
  3696. function tsetdef.getcopy : tstoreddef;
  3697. begin
  3698. result:=csetdef.create(elementdef,setbase,setmax,true);
  3699. { the copy might have been created with a different setalloc setting }
  3700. tsetdef(result).savesize:=savesize;
  3701. end;
  3702. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  3703. begin
  3704. inherited ppuwrite(ppufile);
  3705. ppufile.putderef(elementdefderef);
  3706. ppufile.putasizeint(savesize);
  3707. ppufile.putasizeint(setbase);
  3708. ppufile.putasizeint(setmax);
  3709. writeentry(ppufile,ibsetdef);
  3710. end;
  3711. procedure tsetdef.buildderef;
  3712. begin
  3713. inherited buildderef;
  3714. elementdefderef.build(elementdef);
  3715. end;
  3716. procedure tsetdef.deref;
  3717. begin
  3718. inherited deref;
  3719. elementdef:=tdef(elementdefderef.resolve);
  3720. end;
  3721. function tsetdef.is_publishable : boolean;
  3722. begin
  3723. is_publishable:=savesize in [1,2,4];
  3724. end;
  3725. function tsetdef.alignment: shortint;
  3726. begin
  3727. Result:=inherited;
  3728. if result>sizeof(aint) then
  3729. result:=sizeof(aint);
  3730. end;
  3731. function tsetdef.GetTypeName : string;
  3732. begin
  3733. if assigned(elementdef) then
  3734. GetTypeName:='Set Of '+elementdef.typename
  3735. else
  3736. GetTypeName:='Empty Set';
  3737. end;
  3738. {***************************************************************************
  3739. TFORMALDEF
  3740. ***************************************************************************}
  3741. constructor tformaldef.create(Atyped:boolean);
  3742. begin
  3743. inherited create(formaldef,true);
  3744. typed:=Atyped;
  3745. savesize:=0;
  3746. end;
  3747. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  3748. begin
  3749. inherited ppuload(formaldef,ppufile);
  3750. typed:=boolean(ppufile.getbyte);
  3751. savesize:=0;
  3752. ppuload_platform(ppufile);
  3753. end;
  3754. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  3755. begin
  3756. inherited ppuwrite(ppufile);
  3757. ppufile.putbyte(byte(typed));
  3758. writeentry(ppufile,ibformaldef);
  3759. end;
  3760. function tformaldef.GetTypeName : string;
  3761. begin
  3762. if typed then
  3763. GetTypeName:='<Typed formal type>'
  3764. else
  3765. GetTypeName:='<Formal type>';
  3766. end;
  3767. {***************************************************************************
  3768. TARRAYDEF
  3769. ***************************************************************************}
  3770. constructor tarraydef.create(l, h: asizeint; def: tdef);
  3771. begin
  3772. inherited create(arraydef,true);
  3773. lowrange:=l;
  3774. highrange:=h;
  3775. rangedef:=def;
  3776. rangedefderef.reset;
  3777. _elementdef:=nil;
  3778. _elementdefderef.reset;
  3779. arrayoptions:=[];
  3780. symtable:=tarraysymtable.create(self);
  3781. end;
  3782. constructor tarraydef.create_vector(l ,h: asizeint; def: tdef);
  3783. begin
  3784. self.create(l,h,def);
  3785. include(arrayoptions,ado_IsVector);
  3786. end;
  3787. constructor tarraydef.create_openarray;
  3788. begin
  3789. self.create(0,-1,sizesinttype);
  3790. include(arrayoptions,ado_OpenArray);
  3791. end;
  3792. class function tarraydef.getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  3793. var
  3794. res: PHashSetItem;
  3795. oldsymtablestack: tsymtablestack;
  3796. arrdesc: packed record
  3797. def: tdef;
  3798. elecount: asizeint;
  3799. options: tarraydefoptions
  3800. end;
  3801. begin
  3802. if not assigned(current_module) then
  3803. internalerror(2011081301);
  3804. arrdesc.def:=def;
  3805. arrdesc.elecount:=elems;
  3806. arrdesc.options:=options;
  3807. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  3808. if not assigned(res^.Data) then
  3809. begin
  3810. { since these pointerdefs can be reused anywhere in the current
  3811. unit, add them to the global/staticsymtable (or local symtable
  3812. if they're a local def, because otherwise they'll be saved
  3813. to the ppu referencing a local symtable entry that doesn't
  3814. exist in the ppu) }
  3815. oldsymtablestack:=symtablestack;
  3816. { do not simply push/pop current_module.localsymtable, because
  3817. that can have side-effects (e.g., it removes helpers) }
  3818. symtablestack:=nil;
  3819. result:=carraydef.create(0,elems-1,sizesinttype);
  3820. result.elementdef:=def;
  3821. result.arrayoptions:=options;
  3822. setup_reusable_def(def,result,res,oldsymtablestack);
  3823. { res^.Data may still be nil -> don't overwrite result }
  3824. exit;
  3825. end;
  3826. result:=tarraydef(res^.Data);
  3827. end;
  3828. class function tarraydef.getreusable(def: tdef; elems: asizeint): tarraydef;
  3829. begin
  3830. result:=getreusable_intern(def,elems,[]);
  3831. end;
  3832. class function tarraydef.getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  3833. begin
  3834. result:=getreusable_intern(def,elems,[ado_IsVector]);
  3835. end;
  3836. class function tarraydef.getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  3837. begin
  3838. result:=getreusable(def,elems);
  3839. if not result.is_registered then
  3840. include(result.defoptions,df_not_registered_no_free);
  3841. end;
  3842. class function tarraydef.getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  3843. begin
  3844. result:=getreusable_vector(def,elems);
  3845. if not result.is_registered then
  3846. include(result.defoptions,df_not_registered_no_free);
  3847. end;
  3848. destructor tarraydef.destroy;
  3849. begin
  3850. symtable.free;
  3851. symtable:=nil;
  3852. inherited;
  3853. end;
  3854. constructor tarraydef.create_from_pointer(def:tpointerdef);
  3855. begin
  3856. { divide by the element size and do -1 so the array will have a valid size,
  3857. further, the element size might be 0 e.g. for empty records, so use max(...,1)
  3858. to avoid a division by zero }
  3859. self.create(0,(high(asizeint) div max(def.pointeddef.size,1))-1,
  3860. def.converted_pointer_to_array_range_type);
  3861. arrayoptions:=[ado_IsConvertedPointer];
  3862. setelementdef(def.pointeddef);
  3863. end;
  3864. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  3865. begin
  3866. inherited ppuload(arraydef,ppufile);
  3867. { the addresses are calculated later }
  3868. ppufile.getderef(_elementdefderef);
  3869. ppufile.getderef(rangedefderef);
  3870. lowrange:=ppufile.getasizeint;
  3871. highrange:=ppufile.getasizeint;
  3872. ppufile.getset(tppuset2(arrayoptions));
  3873. ppuload_platform(ppufile);
  3874. symtable:=tarraysymtable.create(self);
  3875. tarraysymtable(symtable).ppuload(ppufile)
  3876. end;
  3877. function tarraydef.getcopy : tstoreddef;
  3878. begin
  3879. result:=carraydef.create(lowrange,highrange,rangedef);
  3880. tarraydef(result).arrayoptions:=arrayoptions;
  3881. tarraydef(result)._elementdef:=_elementdef;
  3882. end;
  3883. procedure tarraydef.buildderef;
  3884. begin
  3885. inherited buildderef;
  3886. tarraysymtable(symtable).buildderef;
  3887. _elementdefderef.build(_elementdef);
  3888. rangedefderef.build(rangedef);
  3889. end;
  3890. procedure tarraydef.deref;
  3891. begin
  3892. inherited deref;
  3893. tarraysymtable(symtable).deref(false);
  3894. _elementdef:=tdef(_elementdefderef.resolve);
  3895. rangedef:=tdef(rangedefderef.resolve);
  3896. end;
  3897. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  3898. begin
  3899. inherited ppuwrite(ppufile);
  3900. ppufile.putderef(_elementdefderef);
  3901. ppufile.putderef(rangedefderef);
  3902. ppufile.putasizeint(lowrange);
  3903. ppufile.putasizeint(highrange);
  3904. ppufile.putset(tppuset2(arrayoptions));
  3905. writeentry(ppufile,ibarraydef);
  3906. tarraysymtable(symtable).ppuwrite(ppufile);
  3907. end;
  3908. function tarraydef.elesize : asizeint;
  3909. begin
  3910. if (ado_IsBitPacked in arrayoptions) then
  3911. internalerror(2006080101);
  3912. if assigned(_elementdef) then
  3913. result:=_elementdef.size
  3914. else
  3915. result:=0;
  3916. end;
  3917. function tarraydef.elepackedbitsize : asizeint;
  3918. begin
  3919. if not(ado_IsBitPacked in arrayoptions) then
  3920. internalerror(2006080102);
  3921. if assigned(_elementdef) then
  3922. result:=_elementdef.packedbitsize
  3923. else
  3924. result:=0;
  3925. end;
  3926. function tarraydef.elecount : asizeuint;
  3927. var
  3928. qhigh,qlow : qword;
  3929. begin
  3930. if ado_IsDynamicArray in arrayoptions then
  3931. begin
  3932. result:=0;
  3933. exit;
  3934. end;
  3935. { check whether the range might be larger than high(asizeint). Has
  3936. to include 0..high(sizeint), since that's high(sizeint)+1 elements }
  3937. if (highrange>=0) and (lowrange<=0) then
  3938. begin
  3939. qhigh:=highrange;
  3940. if lowrange=low(asizeint) then
  3941. qlow:=high(asizeint) + 1
  3942. else
  3943. qlow:=qword(-lowrange);
  3944. { prevent overflow, return 0 to indicate overflow }
  3945. if qhigh+qlow>qword(high(asizeint)-1) then
  3946. result:=0
  3947. else
  3948. result:=qhigh+qlow+1;
  3949. end
  3950. else
  3951. result:=int64(highrange)-lowrange+1;
  3952. end;
  3953. function tarraydef.size : asizeint;
  3954. var
  3955. cachedelecount : asizeuint;
  3956. cachedelesize : asizeint;
  3957. begin
  3958. if ado_IsDynamicArray in arrayoptions then
  3959. begin
  3960. size:=voidpointertype.size;
  3961. exit;
  3962. end;
  3963. { Tarraydef.size may never be called for an open array! }
  3964. if ado_OpenArray in arrayoptions then
  3965. internalerror(99080501);
  3966. if not (ado_IsBitPacked in arrayoptions) then
  3967. cachedelesize:=elesize
  3968. else
  3969. cachedelesize := elepackedbitsize;
  3970. cachedelecount:=elecount;
  3971. if (cachedelesize = 0) then
  3972. begin
  3973. size := 0;
  3974. exit;
  3975. end;
  3976. if (cachedelecount = 0) then
  3977. begin
  3978. if ado_isconststring in arrayoptions then
  3979. size := 0
  3980. else
  3981. size := -1;
  3982. exit;
  3983. end;
  3984. { prevent overflow, return -1 to indicate overflow }
  3985. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  3986. if (cachedelecount > asizeuint(high(asizeint))) or
  3987. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  3988. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  3989. accessing the array, see ncgmem (PFV) }
  3990. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  3991. begin
  3992. result:=-1;
  3993. exit;
  3994. end;
  3995. result:=cachedelesize*asizeint(cachedelecount);
  3996. if (ado_IsBitPacked in arrayoptions) then
  3997. { can't just add 7 and divide by 8, because that may overflow }
  3998. result:=result div 8 + ord((result mod 8)<>0);
  3999. {$ifdef cpu16bitaddr}
  4000. if result>65535 then
  4001. begin
  4002. result:=-1;
  4003. exit;
  4004. end;
  4005. {$endif cpu16bitaddr}
  4006. end;
  4007. procedure tarraydef.setelementdef(def:tdef);
  4008. begin
  4009. _elementdef:=def;
  4010. if not(
  4011. (ado_IsDynamicArray in arrayoptions) or
  4012. (ado_IsConvertedPointer in arrayoptions) or
  4013. (ado_IsConstructor in arrayoptions) or
  4014. (ado_IsGeneric in arrayoptions) or
  4015. (highrange<lowrange)
  4016. ) and
  4017. (size=-1) then
  4018. Message(sym_e_segment_too_large);
  4019. end;
  4020. function tarraydef.alignment : shortint;
  4021. begin
  4022. if ado_IsVector in arrayoptions then
  4023. alignment:=size
  4024. { alignment of dyn. arrays doesn't depend on the element size }
  4025. else if ado_IsDynamicArray in arrayoptions then
  4026. alignment:=voidpointertype.alignment
  4027. { alignment is the target alignment for the used load size }
  4028. else if (ado_IsBitPacked in arrayoptions) and
  4029. (elementdef.typ in [enumdef,orddef]) then
  4030. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  4031. { alignment is the alignment of the elements }
  4032. else
  4033. alignment:=elementdef.alignment
  4034. end;
  4035. function tarraydef.needs_inittable : boolean;
  4036. begin
  4037. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  4038. end;
  4039. function tarraydef.needs_separate_initrtti : boolean;
  4040. begin
  4041. if ado_IsBitPacked in arrayoptions then
  4042. result:=false
  4043. else
  4044. result:=elementdef.needs_separate_initrtti;
  4045. end;
  4046. function tarraydef.GetTypeName : string;
  4047. begin
  4048. if (ado_IsConstString in arrayoptions) then
  4049. result:='Constant String'
  4050. else if (ado_isarrayofconst in arrayoptions) or
  4051. (ado_isConstructor in arrayoptions) then
  4052. begin
  4053. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  4054. GetTypeName:='Array Of Const'
  4055. else
  4056. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  4057. end
  4058. else if (ado_IsDynamicArray in arrayoptions) then
  4059. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  4060. else if (ado_OpenArray in arrayoptions) then
  4061. GetTypeName:='{Open} Array Of '+elementdef.typename
  4062. else
  4063. begin
  4064. result := '';
  4065. if (ado_IsBitPacked in arrayoptions) then
  4066. result:='BitPacked ';
  4067. if rangedef.typ=enumdef then
  4068. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  4069. else
  4070. result:=result+'Array['+tostr(lowrange)+'..'+
  4071. tostr(highrange)+'] Of '+elementdef.typename
  4072. end;
  4073. end;
  4074. function tarraydef.getmangledparaname : TSymStr;
  4075. begin
  4076. if ado_isarrayofconst in arrayoptions then
  4077. getmangledparaname:='array_of_const'
  4078. else
  4079. if ((highrange=-1) and (lowrange=0)) then
  4080. getmangledparaname:='array_of_'+elementdef.mangledparaname
  4081. else
  4082. internalerror(200204176);
  4083. end;
  4084. function tarraydef.is_publishable : boolean;
  4085. begin
  4086. Result:=ado_IsDynamicArray in arrayoptions;
  4087. end;
  4088. function tarraydef.is_hwvector: boolean;
  4089. begin
  4090. result:=ado_IsVector in arrayoptions;
  4091. end;
  4092. {***************************************************************************
  4093. tabstractrecorddef
  4094. ***************************************************************************}
  4095. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp;doregister:boolean);
  4096. begin
  4097. inherited create(dt,doregister);
  4098. objname:=stringdup(upper(n));
  4099. objrealname:=stringdup(n);
  4100. objectoptions:=[];
  4101. if assigned(current_module.namespace) then
  4102. begin
  4103. import_lib:=stringdup(current_module.namespace^);
  4104. replace(import_lib^,'.','/');
  4105. end;
  4106. end;
  4107. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  4108. begin
  4109. inherited ppuload(dt,ppufile);
  4110. objrealname:=ppufile.getpshortstring;
  4111. objname:=stringdup(upper(objrealname^));
  4112. import_lib:=ppufile.getpshortstring;
  4113. { only used for external C++ classes and Java classes/records }
  4114. if (import_lib^='') then
  4115. stringdispose(import_lib);
  4116. ppufile.getset(tppuset4(objectoptions));
  4117. end;
  4118. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  4119. begin
  4120. inherited ppuwrite(ppufile);
  4121. ppufile.putstring(objrealname^);
  4122. if assigned(import_lib) then
  4123. ppufile.putstring(import_lib^)
  4124. else
  4125. ppufile.putstring('');
  4126. ppufile.putset(tppuset4(objectoptions));
  4127. end;
  4128. destructor tabstractrecorddef.destroy;
  4129. begin
  4130. stringdispose(objname);
  4131. stringdispose(objrealname);
  4132. stringdispose(import_lib);
  4133. tcinitcode.free;
  4134. inherited destroy;
  4135. end;
  4136. procedure tabstractrecorddef.buildderefimpl;
  4137. begin
  4138. inherited buildderefimpl;
  4139. if not (df_copied_def in defoptions) then
  4140. tstoredsymtable(symtable).buildderefimpl;
  4141. end;
  4142. procedure tabstractrecorddef.derefimpl;
  4143. begin
  4144. inherited derefimpl;
  4145. if not (df_copied_def in defoptions) then
  4146. tstoredsymtable(symtable).derefimpl(false);
  4147. end;
  4148. procedure tabstractrecorddef.check_forwards;
  4149. begin
  4150. { the defs of a copied def are defined for the original type only }
  4151. if not(df_copied_def in defoptions) then
  4152. tstoredsymtable(symtable).check_forwards;
  4153. end;
  4154. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  4155. var
  4156. i: longint;
  4157. sym: tsym;
  4158. begin
  4159. for i:=0 to symtable.SymList.Count-1 do
  4160. begin
  4161. sym:=tsym(symtable.SymList[i]);
  4162. if sym.typ=procsym then
  4163. begin
  4164. result:=tprocsym(sym).find_procdef_bytype(pt);
  4165. if assigned(result) then
  4166. exit;
  4167. end;
  4168. end;
  4169. result:=nil;
  4170. end;
  4171. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  4172. begin
  4173. if t=gs_record then
  4174. GetSymtable:=symtable
  4175. else
  4176. GetSymtable:=nil;
  4177. end;
  4178. function tabstractrecorddef.is_packed:boolean;
  4179. begin
  4180. result:=tabstractrecordsymtable(symtable).is_packed;
  4181. end;
  4182. function tabstractrecorddef.RttiName: string;
  4183. function generate_full_paramname(maxlength:longint):string;
  4184. const
  4185. commacount : array[boolean] of longint = (0,1);
  4186. var
  4187. fullparas,
  4188. paramname : ansistring;
  4189. module : tmodule;
  4190. sym : tsym;
  4191. def : tdef;
  4192. i : longint;
  4193. begin
  4194. { we want at least enough space for an ellipsis }
  4195. if maxlength<3 then
  4196. internalerror(2014121203);
  4197. fullparas:='';
  4198. for i:=0 to genericparas.count-1 do
  4199. begin
  4200. sym:=tsym(genericparas[i]);
  4201. module:=find_module_from_symtable(sym.owner);
  4202. if not assigned(module) then
  4203. internalerror(2014121202);
  4204. if not (sym.typ in [constsym,symconst.typesym]) then
  4205. internalerror(2020042501);
  4206. if sym.typ=constsym then
  4207. def:=tconstsym(sym).constdef
  4208. else
  4209. def:=ttypesym(sym).typedef;
  4210. paramname:=module.realmodulename^;
  4211. if def.typ in [objectdef,recorddef] then
  4212. paramname:=paramname+'.'+tabstractrecorddef(def).rttiname
  4213. else
  4214. paramname:=paramname+'.'+def.typename;
  4215. if length(fullparas)+commacount[i>0]+length(paramname)>maxlength then
  4216. begin
  4217. if i>0 then
  4218. fullparas:=fullparas+',...'
  4219. else
  4220. fullparas:=fullparas+'...';
  4221. break;
  4222. end;
  4223. { could we fit an ellipsis after this parameter if it should be too long? }
  4224. if (maxlength-(length(fullparas)+commacount[i>0]+length(paramname))<4) and (i<genericparas.count-1) then
  4225. begin
  4226. { then omit already this parameter }
  4227. if i>0 then
  4228. fullparas:=fullparas+',...'
  4229. else
  4230. fullparas:=fullparas+'...';
  4231. break;
  4232. end;
  4233. if i>0 then
  4234. fullparas:=fullparas+',';
  4235. fullparas:=fullparas+paramname;
  4236. end;
  4237. result:=fullparas;
  4238. end;
  4239. var
  4240. nongeneric,
  4241. basename : string;
  4242. i,
  4243. remlength,
  4244. paramcount,
  4245. crcidx : longint;
  4246. begin
  4247. if rttistring='' then
  4248. begin
  4249. if is_specialization then
  4250. begin
  4251. rttistring:=OwnerHierarchyName;
  4252. { there should be two $ characters, one before the CRC and one before the count }
  4253. crcidx:=-1;
  4254. for i:=length(objrealname^) downto 1 do
  4255. if objrealname^[i]='$' then
  4256. begin
  4257. crcidx:=i;
  4258. break;
  4259. end;
  4260. if crcidx<0 then
  4261. internalerror(2014121201);
  4262. basename:=copy(objrealname^,1,crcidx-1);
  4263. split_generic_name(basename,nongeneric,paramcount);
  4264. rttistring:=rttistring+nongeneric+'<';
  4265. remlength:=255-length(rttistring)-1;
  4266. if remlength<4 then
  4267. rttistring:=rttistring+'>'
  4268. else
  4269. rttistring:=rttistring+generate_full_paramname(remlength)+'>';
  4270. end
  4271. else
  4272. if is_generic then
  4273. begin
  4274. rttistring:=OwnerHierarchyName;
  4275. split_generic_name(objrealname^,nongeneric,paramcount);
  4276. rttistring:=rttistring+nongeneric+'<';
  4277. { we don't want any ',' if there is only one parameter }
  4278. for i:=0 to paramcount-0 do
  4279. rttistring:=rttistring+',';
  4280. rttistring:=rttistring+'>';
  4281. end
  4282. else
  4283. rttistring:=OwnerHierarchyName+objrealname^;
  4284. end;
  4285. result:=rttistring;
  4286. end;
  4287. function tabstractrecorddef.search_enumerator_get: tprocdef;
  4288. var
  4289. sym : tsym;
  4290. i : integer;
  4291. pd : tprocdef;
  4292. hashedid : THashedIDString;
  4293. begin
  4294. result:=nil;
  4295. hashedid.id:='GETENUMERATOR';
  4296. sym:=tsym(symtable.FindWithHash(hashedid));
  4297. if assigned(sym) and (sym.typ=procsym) then
  4298. begin
  4299. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  4300. begin
  4301. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4302. if (pd.proctypeoption = potype_function) and
  4303. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  4304. (pd.visibility >= vis_public) then
  4305. begin
  4306. result:=pd;
  4307. exit;
  4308. end;
  4309. end;
  4310. end;
  4311. end;
  4312. function tabstractrecorddef.search_enumerator_move: tprocdef;
  4313. var
  4314. sym : tsym;
  4315. i : integer;
  4316. pd : tprocdef;
  4317. hashedid : THashedIDString;
  4318. begin
  4319. result:=nil;
  4320. // first search for po_enumerator_movenext method modifier
  4321. // then search for public function MoveNext: Boolean
  4322. for i:=0 to symtable.SymList.Count-1 do
  4323. begin
  4324. sym:=TSym(symtable.SymList[i]);
  4325. if (sym.typ=procsym) then
  4326. begin
  4327. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  4328. if assigned(pd) then
  4329. begin
  4330. result:=pd;
  4331. exit;
  4332. end;
  4333. end;
  4334. end;
  4335. hashedid.id:='MOVENEXT';
  4336. sym:=tsym(symtable.FindWithHash(hashedid));
  4337. if assigned(sym) and (sym.typ=procsym) then
  4338. begin
  4339. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  4340. begin
  4341. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4342. if (pd.proctypeoption = potype_function) and
  4343. is_boolean(pd.returndef) and
  4344. (pd.minparacount = 0) and
  4345. (pd.visibility >= vis_public) then
  4346. begin
  4347. result:=pd;
  4348. exit;
  4349. end;
  4350. end;
  4351. end;
  4352. end;
  4353. function tabstractrecorddef.search_enumerator_current: tsym;
  4354. var
  4355. sym: tsym;
  4356. i: integer;
  4357. hashedid : THashedIDString;
  4358. begin
  4359. result:=nil;
  4360. // first search for ppo_enumerator_current property modifier
  4361. // then search for public property Current
  4362. for i:=0 to symtable.SymList.Count-1 do
  4363. begin
  4364. sym:=TSym(symtable.SymList[i]);
  4365. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  4366. begin
  4367. result:=sym;
  4368. exit;
  4369. end;
  4370. end;
  4371. hashedid.id:='CURRENT';
  4372. sym:=tsym(symtable.FindWithHash(hashedid));
  4373. if assigned(sym) and (sym.typ=propertysym) and
  4374. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  4375. begin
  4376. result:=sym;
  4377. exit;
  4378. end;
  4379. end;
  4380. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  4381. var
  4382. st: tsymtable;
  4383. enclosingdef: tdef;
  4384. begin
  4385. if typ=objectdef then
  4386. result:=tobjectdef(self).objextname^
  4387. else if assigned(typesym) then
  4388. result:=typesym.realname
  4389. { have to generate anonymous nested type in current unit/class/record }
  4390. else
  4391. internalerror(2011032601);
  4392. { in case of specializations, add some extras to prevent name conflicts
  4393. with nested classes }
  4394. if df_specialization in defoptions then
  4395. result:='$'+result+'$specialization$';
  4396. st:=owner;
  4397. while assigned(st) and
  4398. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  4399. begin
  4400. { nested classes are named as "OuterClass$InnerClass" }
  4401. enclosingdef:=tdef(st.defowner);
  4402. if enclosingdef.typ=procdef then
  4403. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  4404. else if enclosingdef.typ=objectdef then
  4405. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  4406. else if assigned(enclosingdef.typesym) then
  4407. result:=enclosingdef.typesym.realname+'$'+result
  4408. else
  4409. internalerror(2011060305);
  4410. st:=enclosingdef.owner;
  4411. end;
  4412. if with_package_name and
  4413. assigned(import_lib) then
  4414. result:=import_lib^+'/'+result;
  4415. end;
  4416. function tabstractrecorddef.contains_float_field: boolean;
  4417. var
  4418. i : longint;
  4419. begin
  4420. result:=true;
  4421. for i:=0 to symtable.symlist.count-1 do
  4422. begin
  4423. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4424. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4425. continue;
  4426. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4427. begin
  4428. if tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  4429. exit;
  4430. { search recursively }
  4431. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4432. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_float_field) then
  4433. exit;
  4434. end;
  4435. end;
  4436. result:=false;
  4437. end;
  4438. function tabstractrecorddef.contains_cross_aword_field: boolean;
  4439. var
  4440. i : longint;
  4441. foffset, fsize: aword;
  4442. begin
  4443. result:=true;
  4444. for i:=0 to symtable.symlist.count-1 do
  4445. begin
  4446. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4447. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4448. continue;
  4449. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4450. begin
  4451. if is_packed then
  4452. begin
  4453. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset;
  4454. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.packedbitsize;
  4455. end
  4456. else
  4457. begin
  4458. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset*8;
  4459. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.size*8;
  4460. end;
  4461. if (fsize>0) and ((foffset div (sizeof(aword)*8)) <> ((foffset+fsize-1) div (sizeof(aword)*8))) then
  4462. exit;
  4463. { search recursively }
  4464. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4465. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_cross_aword_field) then
  4466. exit;
  4467. end;
  4468. end;
  4469. result:=false;
  4470. end;
  4471. {$ifdef DEBUG_NODE_XML}
  4472. procedure tabstractrecorddef.XMLPrintDefData(var T: Text; Sym: TSym);
  4473. procedure WriteSymOptions(SourceSym: TSym);
  4474. var
  4475. i: TSymOption;
  4476. first: Boolean;
  4477. begin
  4478. First := True;
  4479. for i := Low(TSymOption) to High(TSymOption) do
  4480. if i in SourceSym.symoptions then
  4481. begin
  4482. if First then
  4483. begin
  4484. Write(T, '" symoptions="', i);
  4485. First := False;
  4486. end
  4487. else
  4488. Write(T, ',', i)
  4489. end;
  4490. end;
  4491. var
  4492. List: TFPHashObjectList;
  4493. i: Integer;
  4494. begin
  4495. WriteLn(T, PrintNodeIndention, '<size>', size, '</size>');
  4496. if (alignment = structalignment) and (alignment = aggregatealignment) then
  4497. begin
  4498. { Straightforward and simple }
  4499. WriteLn(T, PrintNodeIndention, '<alignment>', alignment, '</alignment>');
  4500. end
  4501. else
  4502. begin
  4503. WriteLn(T, PrintNodeIndention, '<alignment>');
  4504. printnodeindent;
  4505. WriteLn(T, PrintNodeIndention, '<basic>', alignment, '</basic>');
  4506. if (structalignment <> alignment) then
  4507. WriteLn(T, PrintNodeIndention, '<struct>', structalignment, '</struct>');
  4508. if (aggregatealignment <> alignment) and (aggregatealignment <> structalignment) then
  4509. WriteLn(T, PrintNodeIndention, '<aggregate>', aggregatealignment, '</aggregate>');
  4510. printnodeunindent;
  4511. WriteLn(T, PrintNodeIndention, '</alignment>');
  4512. end;
  4513. { List the fields }
  4514. List := Symtable.SymList;
  4515. for i := 0 to List.Count - 1 do
  4516. case TSym(List[i]).typ of
  4517. { staticvarsym,localvarsym,paravarsym,fieldvarsym,
  4518. typesym,procsym,unitsym,}
  4519. constsym:
  4520. with TConstSym(List[i]) do
  4521. begin
  4522. Write(T, PrintNodeIndention, '<const name="', RealName, '" pos="', fileinfo.line, ',', fileinfo.column);
  4523. WriteSymOptions(TSym(List[i]));
  4524. WriteLn(T, '">');
  4525. PrintNodeIndent;
  4526. XMLPrintConstData(T);
  4527. PrintNodeUnindent;
  4528. WriteLn(T, PrintNodeIndention, '</const>');
  4529. end;
  4530. {
  4531. errorsym,syssym,labelsym,absolutevarsym,propertysym,
  4532. macrosym,namespacesym,undefinedsym,programparasym
  4533. }
  4534. fieldvarsym:
  4535. with TFieldVarSym(List[i]) do
  4536. begin
  4537. Write(T, PrintNodeIndention, '<field name="', RealName, '" pos="', fileinfo.line, ',', fileinfo.column);
  4538. WriteSymOptions(TSym(List[i]));
  4539. WriteLn(T, '">');
  4540. PrintNodeIndent;
  4541. XMLPrintFieldData(T);
  4542. PrintNodeUnindent;
  4543. WriteLn(T, PrintNodeIndention, '</field>');
  4544. end;
  4545. else
  4546. ;
  4547. end;
  4548. end;
  4549. {$endif DEBUG_NODE_XML}
  4550. {***************************************************************************
  4551. trecorddef
  4552. ***************************************************************************}
  4553. constructor trecorddef.create(const n:string; p:TSymtable);
  4554. begin
  4555. inherited create(n,recorddef,true);
  4556. symtable:=p;
  4557. { we can own the symtable only if nobody else owns a copy so far }
  4558. if symtable.refcount=1 then
  4559. symtable.defowner:=self;
  4560. isunion:=false;
  4561. cloneddefderef.reset;
  4562. end;
  4563. constructor trecorddef.create_internal(const n: string; packrecords, recordalignmin: shortint; where: tsymtable);
  4564. var
  4565. name : string;
  4566. pname : pshortstring;
  4567. oldsymtablestack: tsymtablestack;
  4568. ts: ttypesym;
  4569. begin
  4570. { construct name }
  4571. if n<>'' then
  4572. pname:=@n
  4573. else
  4574. begin
  4575. init_defid;
  4576. name:='$InternalRec'+unique_id_str;
  4577. pname:=@name;
  4578. end;
  4579. oldsymtablestack:=symtablestack;
  4580. { do not simply push/pop current_module.localsymtable, because
  4581. that can have side-effects (e.g., it removes helpers) }
  4582. symtablestack:=nil;
  4583. symtable:=trecordsymtable.create(pname^,packrecords,recordalignmin);
  4584. symtable.defowner:=self;
  4585. isunion:=false;
  4586. inherited create(pname^,recorddef,true);
  4587. where.insertdef(self);
  4588. { if we specified a name, then we'll probably want to look up the
  4589. type again by name too -> create typesym }
  4590. if n<>'' then
  4591. begin
  4592. ts:=ctypesym.create(n,self);
  4593. include(ts.symoptions,sp_internal);
  4594. { avoid hints about unused types (these may only be used for
  4595. typed constant data) }
  4596. ts.increfcount;
  4597. where.insertsym(ts);
  4598. end;
  4599. symtablestack:=oldsymtablestack;
  4600. { don't create RTTI for internal types, these are not exported }
  4601. defstates:=defstates+[ds_rtti_table_written,ds_init_table_written];
  4602. include(defoptions,df_internal);
  4603. end;
  4604. constructor trecorddef.create_global_internal(const n: string; packrecords, recordalignmin: shortint);
  4605. var
  4606. where : tsymtable;
  4607. begin
  4608. where:=current_module.localsymtable;
  4609. if not assigned(where) then
  4610. where:=current_module.globalsymtable;
  4611. create_internal(n,packrecords,recordalignmin,where);
  4612. end;
  4613. function trecorddef.add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  4614. var
  4615. sym: tfieldvarsym;
  4616. name: TIDString;
  4617. pname: ^TIDString;
  4618. begin
  4619. if optionalname='' then
  4620. begin
  4621. name:='$f'+tostr(trecordsymtable(symtable).symlist.count);
  4622. pname:=@name
  4623. end
  4624. else
  4625. pname:=@optionalname;
  4626. sym:=cfieldvarsym.create(pname^,vs_value,def,[]);
  4627. symtable.insertsym(sym);
  4628. trecordsymtable(symtable).addfield(sym,vis_hidden);
  4629. result:=sym;
  4630. end;
  4631. procedure trecorddef.add_fields_from_deflist(fieldtypes: tfplist);
  4632. var
  4633. i: longint;
  4634. begin
  4635. for i:=0 to fieldtypes.count-1 do
  4636. add_field_by_def('',tdef(fieldtypes[i]));
  4637. end;
  4638. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  4639. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  4640. var
  4641. i,j : longint;
  4642. begin
  4643. if ppufile.getbyte=1 then
  4644. begin
  4645. new(variantrecdesc);
  4646. ppufile.getderef(variantrecdesc^.variantselectorderef);
  4647. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  4648. for i:=0 to high(variantrecdesc^.branches) do
  4649. begin
  4650. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  4651. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4652. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  4653. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4654. end;
  4655. end
  4656. else
  4657. variantrecdesc:=nil;
  4658. end;
  4659. begin
  4660. inherited ppuload(recorddef,ppufile);
  4661. if df_copied_def in defoptions then
  4662. begin
  4663. ppufile.getderef(cloneddefderef);
  4664. ppuload_platform(ppufile);
  4665. end
  4666. else
  4667. begin
  4668. symtable:=trecordsymtable.create(objrealname^,0,0);
  4669. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  4670. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  4671. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  4672. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  4673. trecordsymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  4674. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  4675. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  4676. ppufile.getset(tppuset1(trecordsymtable(symtable).managementoperators));
  4677. { position of ppuload_platform call must correspond
  4678. to position of writeentry in ppuwrite method }
  4679. ppuload_platform(ppufile);
  4680. trecordsymtable(symtable).ppuload(ppufile);
  4681. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4682. but because iso mode supports no units, there is no need to store the variantrecdesc
  4683. in the ppu
  4684. }
  4685. // readvariantrecdesc(variantrecdesc);
  4686. { requires usefieldalignment to be set }
  4687. symtable.defowner:=self;
  4688. end;
  4689. isunion:=false;
  4690. end;
  4691. destructor trecorddef.destroy;
  4692. procedure free_variantrecdesc(var variantrecdesc : pvariantrecdesc);
  4693. var
  4694. i : longint;
  4695. begin
  4696. while assigned(variantrecdesc) do
  4697. begin
  4698. for i:=0 to high(variantrecdesc^.branches) do
  4699. begin
  4700. free_variantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4701. SetLength(variantrecdesc^.branches[i].values,0);
  4702. end;
  4703. SetLength(variantrecdesc^.branches,0);
  4704. dispose(variantrecdesc);
  4705. variantrecdesc:=nil;
  4706. end;
  4707. end;
  4708. begin
  4709. if assigned(variantrecdesc) then
  4710. free_variantrecdesc(variantrecdesc);
  4711. if assigned(symtable) then
  4712. begin
  4713. symtable.free;
  4714. symtable:=nil;
  4715. end;
  4716. inherited destroy;
  4717. end;
  4718. function trecorddef.getcopy : tstoreddef;
  4719. begin
  4720. result:=crecorddef.create(objrealname^,symtable.getcopy);
  4721. trecorddef(result).isunion:=isunion;
  4722. include(trecorddef(result).defoptions,df_copied_def);
  4723. if assigned(tcinitcode) then
  4724. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  4725. if assigned(import_lib) then
  4726. trecorddef(result).import_lib:=stringdup(import_lib^);
  4727. end;
  4728. function trecorddef.needs_inittable : boolean;
  4729. begin
  4730. { each record with managed field or with any management operator needs
  4731. init table }
  4732. needs_inittable:=(trecordsymtable(symtable).managementoperators<>[]) or
  4733. trecordsymtable(symtable).needs_init_final
  4734. end;
  4735. function trecorddef.needs_separate_initrtti : boolean;
  4736. begin
  4737. result:=true;
  4738. end;
  4739. function trecorddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  4740. begin
  4741. result:=trecordsymtable(symtable).has_non_trivial_init;
  4742. end;
  4743. procedure trecorddef.buildderef;
  4744. begin
  4745. inherited buildderef;
  4746. if df_copied_def in defoptions then
  4747. cloneddefderef.build(symtable.defowner)
  4748. else
  4749. tstoredsymtable(symtable).buildderef;
  4750. end;
  4751. procedure trecorddef.deref;
  4752. begin
  4753. inherited deref;
  4754. { now dereference the definitions }
  4755. if df_copied_def in defoptions then
  4756. begin
  4757. cloneddef:=trecorddef(cloneddefderef.resolve);
  4758. symtable:=cloneddef.symtable.getcopy;
  4759. end
  4760. else
  4761. tstoredsymtable(symtable).deref(false);
  4762. { internal types, only load from the system unit }
  4763. if assigned(owner) and
  4764. assigned(owner.name) and
  4765. (owner.name^='SYSTEM') then
  4766. begin
  4767. { TGUID }
  4768. if not assigned(rec_tguid) and
  4769. (upper(typename)='TGUID') then
  4770. rec_tguid:=self
  4771. { JMP_BUF }
  4772. else if not assigned(rec_jmp_buf) and
  4773. (upper(typename)='JMP_BUF') then
  4774. rec_jmp_buf:=self
  4775. else if not assigned(rec_exceptaddr) and
  4776. (upper(typename)='TEXCEPTADDR') then
  4777. rec_exceptaddr:=self;
  4778. end;
  4779. end;
  4780. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  4781. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  4782. var
  4783. i,j : longint;
  4784. begin
  4785. if assigned(variantrecdesc) then
  4786. begin
  4787. ppufile.putbyte(1);
  4788. ppufile.putderef(variantrecdesc^.variantselectorderef);
  4789. ppufile.putasizeint(length(variantrecdesc^.branches));
  4790. for i:=0 to high(variantrecdesc^.branches) do
  4791. begin
  4792. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  4793. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4794. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  4795. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4796. end;
  4797. end
  4798. else
  4799. ppufile.putbyte(0);
  4800. end;
  4801. begin
  4802. inherited ppuwrite(ppufile);
  4803. if df_copied_def in defoptions then
  4804. ppufile.putderef(cloneddefderef)
  4805. else
  4806. begin
  4807. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  4808. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  4809. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  4810. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  4811. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignmin));
  4812. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  4813. ppufile.putword(trecordsymtable(symtable).paddingsize);
  4814. ppufile.putset(tppuset1(trecordsymtable(symtable).managementoperators));
  4815. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4816. but because iso mode supports no units, there is no need to store the variantrecdesc
  4817. in the ppu
  4818. }
  4819. // writevariantrecdesc(variantrecdesc);
  4820. end;
  4821. writeentry(ppufile,ibrecorddef);
  4822. if not(df_copied_def in defoptions) then
  4823. trecordsymtable(symtable).ppuwrite(ppufile);
  4824. end;
  4825. function trecorddef.size:asizeint;
  4826. begin
  4827. result:=trecordsymtable(symtable).datasize;
  4828. end;
  4829. function trecorddef.alignment:shortint;
  4830. begin
  4831. alignment:=trecordsymtable(symtable).recordalignment;
  4832. end;
  4833. function trecorddef.padalignment:shortint;
  4834. begin
  4835. padalignment := trecordsymtable(symtable).padalignment;
  4836. end;
  4837. function trecorddef.GetTypeName : string;
  4838. begin
  4839. GetTypeName:='<record type>'
  4840. end;
  4841. {$ifdef DEBUG_NODE_XML}
  4842. function TRecordDef.XMLPrintType: ansistring;
  4843. begin
  4844. Result := '&lt;record&gt;';
  4845. end;
  4846. {$endif DEBUG_NODE_XML}
  4847. {***************************************************************************
  4848. TABSTRACTPROCDEF
  4849. ***************************************************************************}
  4850. constructor tabstractprocdef.create(dt:tdeftyp;level:byte;doregister:boolean);
  4851. begin
  4852. inherited create(dt,doregister);
  4853. parast:=tparasymtable.create(self,level);
  4854. paras:=nil;
  4855. minparacount:=0;
  4856. maxparacount:=0;
  4857. proctypeoption:=potype_none;
  4858. proccalloption:=pocall_none;
  4859. procoptions:=[];
  4860. returndef:=voidtype;
  4861. returndefderef.reset;
  4862. savesize:=sizeof(pint);
  4863. callerargareasize:=0;
  4864. calleeargareasize:=0;
  4865. has_paraloc_info:=callnoside;
  4866. funcretloc[callerside].init;
  4867. funcretloc[calleeside].init;
  4868. check_mark_as_nested;
  4869. end;
  4870. destructor tabstractprocdef.destroy;
  4871. begin
  4872. if assigned(paras) then
  4873. begin
  4874. {$ifdef MEMDEBUG}
  4875. memprocpara.start;
  4876. {$endif MEMDEBUG}
  4877. paras.free;
  4878. paras:=nil;
  4879. {$ifdef MEMDEBUG}
  4880. memprocpara.stop;
  4881. {$endif MEMDEBUG}
  4882. end;
  4883. if assigned(parast) then
  4884. begin
  4885. {$ifdef MEMDEBUG}
  4886. memprocparast.start;
  4887. {$endif MEMDEBUG}
  4888. parast.free;
  4889. parast:=nil;
  4890. {$ifdef MEMDEBUG}
  4891. memprocparast.stop;
  4892. {$endif MEMDEBUG}
  4893. end;
  4894. funcretloc[callerside].done;
  4895. funcretloc[calleeside].done;
  4896. inherited destroy;
  4897. end;
  4898. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  4899. begin
  4900. if (tsym(p).typ<>paravarsym) then
  4901. exit;
  4902. inc(plongint(arg)^);
  4903. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  4904. begin
  4905. if not assigned(tparavarsym(p).defaultconstsym) then
  4906. inc(minparacount);
  4907. inc(maxparacount);
  4908. end;
  4909. end;
  4910. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  4911. begin
  4912. if (tsym(p).typ<>paravarsym) then
  4913. exit;
  4914. paras.add(p);
  4915. end;
  4916. procedure tabstractprocdef.calcparas;
  4917. var
  4918. paracount : longint;
  4919. begin
  4920. { This can already be assigned when
  4921. we need to reresolve this unit (PFV) }
  4922. if assigned(paras) then
  4923. paras.free;
  4924. paras:=tparalist.create(false);
  4925. paracount:=0;
  4926. minparacount:=0;
  4927. maxparacount:=0;
  4928. parast.SymList.ForEachCall(@count_para,@paracount);
  4929. paras.capacity:=paracount;
  4930. { Insert parameters in table }
  4931. parast.SymList.ForEachCall(@insert_para,nil);
  4932. { Order parameters }
  4933. paras.sortparas;
  4934. end;
  4935. function tabstractprocdef.mangledprocparanames(oldlen : longint) : string;
  4936. var
  4937. hash : qword;
  4938. hp : TParavarsym;
  4939. hs : TSymStr;
  4940. newlen,
  4941. i : integer;
  4942. begin
  4943. result:='';
  4944. hp:=nil;
  4945. { add parameter types }
  4946. for i:=0 to paras.count-1 do
  4947. begin
  4948. hp:=tparavarsym(paras[i]);
  4949. if not(vo_is_hidden_para in hp.varoptions) then
  4950. result:=result+'$'+hp.vardef.mangledparaname;
  4951. end;
  4952. { add resultdef, add $$ as separator to make it unique from a
  4953. parameter separator }
  4954. if not is_void(returndef) then
  4955. result:=result+'$$'+returndef.mangledparaname;
  4956. newlen:=length(result)+oldlen;
  4957. { Replace with hash if the parameter line is very long }
  4958. if (newlen-oldlen>12) and
  4959. ((newlen>100) or (newlen-oldlen>64)) then
  4960. begin
  4961. hash:=0;
  4962. for i:=0 to paras.count-1 do
  4963. begin
  4964. hp:=tparavarsym(paras[i]);
  4965. if not(vo_is_hidden_para in hp.varoptions) then
  4966. begin
  4967. hs:=hp.vardef.mangledparaname;
  4968. hash:=UpdateFnv64(hash,hs[1],length(hs));
  4969. end;
  4970. end;
  4971. if not is_void(returndef) then
  4972. begin
  4973. { add a little prefix so that x(integer; integer) is different from x(integer):integer }
  4974. hs:='$$'+returndef.mangledparaname;
  4975. hash:=UpdateFnv64(hash,hs[1],length(hs));
  4976. end;
  4977. result:='$h'+Base64Mangle(hash);
  4978. end;
  4979. end;
  4980. procedure tabstractprocdef.buildderef;
  4981. begin
  4982. { released procdef? }
  4983. if not assigned(parast) then
  4984. exit;
  4985. inherited buildderef;
  4986. returndefderef.build(returndef);
  4987. if po_explicitparaloc in procoptions then
  4988. funcretloc[callerside].buildderef;
  4989. { parast }
  4990. tparasymtable(parast).buildderef;
  4991. end;
  4992. procedure tabstractprocdef.deref;
  4993. begin
  4994. inherited deref;
  4995. returndef:=tdef(returndefderef.resolve);
  4996. if po_explicitparaloc in procoptions then
  4997. begin
  4998. funcretloc[callerside].deref;
  4999. has_paraloc_info:=callerside;
  5000. end
  5001. else
  5002. begin
  5003. { deref is called after loading from a ppu, but also after another
  5004. unit has been reloaded/recompiled and all references must be
  5005. re-resolved. Since the funcretloc contains a reference to a tdef,
  5006. reset it so that we won't try to access the stale def }
  5007. funcretloc[callerside].init;
  5008. has_paraloc_info:=callnoside;
  5009. end;
  5010. { parast }
  5011. tparasymtable(parast).deref(false);
  5012. { recalculated parameters }
  5013. calcparas;
  5014. end;
  5015. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  5016. begin
  5017. inherited ppuload(dt,ppufile);
  5018. parast:=nil;
  5019. Paras:=nil;
  5020. minparacount:=0;
  5021. maxparacount:=0;
  5022. ppufile.getderef(returndefderef);
  5023. proctypeoption:=tproctypeoption(ppufile.getbyte);
  5024. proccalloption:=tproccalloption(ppufile.getbyte);
  5025. ppufile.getset(tppuset8(procoptions));
  5026. funcretloc[callerside].init;
  5027. if po_explicitparaloc in procoptions then
  5028. funcretloc[callerside].ppuload(ppufile);
  5029. savesize:=sizeof(pint);
  5030. if (po_explicitparaloc in procoptions) then
  5031. has_paraloc_info:=callerside;
  5032. end;
  5033. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  5034. var
  5035. oldintfcrc : boolean;
  5036. begin
  5037. { released procdef? }
  5038. if not assigned(parast) then
  5039. exit;
  5040. inherited ppuwrite(ppufile);
  5041. ppufile.putderef(returndefderef);
  5042. oldintfcrc:=ppufile.do_interface_crc;
  5043. ppufile.do_interface_crc:=false;
  5044. ppufile.putbyte(ord(proctypeoption));
  5045. ppufile.putbyte(ord(proccalloption));
  5046. ppufile.putset(tppuset8(procoptions));
  5047. ppufile.do_interface_crc:=oldintfcrc;
  5048. if (po_explicitparaloc in procoptions) then
  5049. funcretloc[callerside].ppuwrite(ppufile);
  5050. end;
  5051. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  5052. var
  5053. hs,s : ansistring;
  5054. hp : TParavarsym;
  5055. hpc : tconstsym;
  5056. first : boolean;
  5057. i,j : integer;
  5058. begin
  5059. s:='';
  5060. first:=true;
  5061. for i:=0 to paras.count-1 do
  5062. begin
  5063. hp:=tparavarsym(paras[i]);
  5064. if not(vo_is_hidden_para in hp.varoptions) or
  5065. (pno_showhidden in pno) then
  5066. begin
  5067. if first then
  5068. begin
  5069. s:=s+'(';
  5070. first:=false;
  5071. end
  5072. else
  5073. s:=s+';';
  5074. if vo_is_hidden_para in hp.varoptions then
  5075. s:=s+'<';
  5076. case hp.varspez of
  5077. vs_var :
  5078. s:=s+'var ';
  5079. vs_const :
  5080. s:=s+'const ';
  5081. vs_out :
  5082. s:=s+'out ';
  5083. vs_constref :
  5084. s:=s+'constref ';
  5085. else
  5086. ;
  5087. end;
  5088. if (pno_paranames in pno) then
  5089. s:=s+hp.realname+':';
  5090. if hp.univpara then
  5091. s:=s+'univ ';
  5092. if assigned(hp.vardef.typesym) then
  5093. begin
  5094. hs:=hp.vardef.typesym.realname;
  5095. if hs[1]<>'$' then
  5096. s:=s+hp.vardef.OwnerHierarchyName+hs
  5097. else
  5098. s:=s+hp.vardef.GetTypeName;
  5099. end
  5100. else
  5101. s:=s+hp.vardef.GetTypeName;
  5102. { default value }
  5103. if assigned(hp.defaultconstsym) then
  5104. begin
  5105. hpc:=tconstsym(hp.defaultconstsym);
  5106. hs:='';
  5107. case hpc.consttyp of
  5108. constwstring:
  5109. begin
  5110. if pcompilerwidestring(hpc.value.valueptr)^.len>0 then
  5111. begin
  5112. setlength(hs,pcompilerwidestring(hpc.value.valueptr)^.len);
  5113. for j:=0 to pcompilerwidestring(hpc.value.valueptr)^.len-1 do
  5114. begin
  5115. if (ord(pcompilerwidestring(hpc.value.valueptr)^.data[j])<127) and
  5116. not(byte(pcompilerwidestring(hpc.value.valueptr)^.data[j]) in [0,10,13]) then
  5117. hs[j+1]:=char(pcompilerwidestring(hpc.value.valueptr)^.data[j])
  5118. else
  5119. hs[j+1]:='.';
  5120. end;
  5121. end;
  5122. end;
  5123. conststring,
  5124. constresourcestring :
  5125. begin
  5126. if hpc.value.len>0 then
  5127. begin
  5128. setLength(hs,hpc.value.len);
  5129. { don't write past the end of hs if the constant
  5130. is > 255 chars }
  5131. move(hpc.value.valueptr^,hs[1],length(hs));
  5132. { make sure that constant strings with newline chars
  5133. don't create a linebreak in the assembler code,
  5134. since comments are line-based. Also remove nulls
  5135. because the comments are written as a pchar. }
  5136. ReplaceCase(hs,#0,'.');
  5137. ReplaceCase(hs,#10,'.');
  5138. ReplaceCase(hs,#13,'.');
  5139. end;
  5140. end;
  5141. constreal :
  5142. str(pbestreal(hpc.value.valueptr)^,hs);
  5143. constpointer :
  5144. hs:=tostr(hpc.value.valueordptr);
  5145. constord :
  5146. begin
  5147. if is_boolean(hpc.constdef) then
  5148. begin
  5149. if hpc.value.valueord<>0 then
  5150. hs:='TRUE'
  5151. else
  5152. hs:='FALSE';
  5153. end
  5154. else
  5155. hs:=tostr(hpc.value.valueord);
  5156. end;
  5157. constnil :
  5158. hs:='nil';
  5159. constset :
  5160. hs:='<set>';
  5161. constguid:
  5162. hs:=guid2string(pguid(hpc.value.valueptr)^);
  5163. constnone:
  5164. internalerror(2019050704);
  5165. end;
  5166. if hs<>'' then
  5167. s:=s+'=`'+hs+'`';
  5168. end;
  5169. if vo_is_hidden_para in hp.varoptions then
  5170. s:=s+'>';
  5171. end;
  5172. end;
  5173. if not first then
  5174. s:=s+')';
  5175. if (po_varargs in procoptions) then
  5176. s:=s+';VarArgs';
  5177. typename_paras:=s;
  5178. end;
  5179. function tabstractprocdef.is_methodpointer:boolean;
  5180. begin
  5181. result:=false;
  5182. end;
  5183. function tabstractprocdef.is_addressonly:boolean;
  5184. begin
  5185. result:=true;
  5186. end;
  5187. function tabstractprocdef.no_self_node: boolean;
  5188. begin
  5189. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  5190. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  5191. end;
  5192. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  5193. var
  5194. j, nestinglevel: longint;
  5195. pvs, npvs: tparavarsym;
  5196. begin
  5197. nestinglevel:=parast.symtablelevel;
  5198. if newtyp=procdef then
  5199. begin
  5200. if (copytyp<>pc_bareproc) then
  5201. result:=cprocdef.create(nestinglevel,doregister)
  5202. else
  5203. result:=cprocdef.create(normal_function_level,doregister);
  5204. tprocdef(result).visibility:=vis_public;
  5205. end
  5206. else
  5207. begin
  5208. result:=cprocvardef.create(nestinglevel,true);
  5209. end;
  5210. tabstractprocdef(result).returndef:=returndef;
  5211. tabstractprocdef(result).returndefderef:=returndefderef;
  5212. pvs:=nil;
  5213. npvs:=nil;
  5214. if copytyp<>pc_normal_no_paras then
  5215. begin
  5216. for j:=0 to parast.symlist.count-1 do
  5217. begin
  5218. case tsym(parast.symlist[j]).typ of
  5219. paravarsym:
  5220. begin
  5221. pvs:=tparavarsym(parast.symlist[j]);
  5222. { in case of bare proc, don't copy self, vmt or framepointer
  5223. parameters }
  5224. if (copytyp in [pc_bareproc,pc_normal_no_hidden]) and
  5225. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result,vo_is_funcret]*pvs.varoptions)<>[]) then
  5226. continue;
  5227. if paraprefix='' then
  5228. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  5229. pvs.vardef,pvs.varoptions)
  5230. else if not(vo_is_high_para in pvs.varoptions) then
  5231. npvs:=cparavarsym.create(paraprefix+pvs.realname,pvs.paranr,pvs.varspez,
  5232. pvs.vardef,pvs.varoptions)
  5233. else
  5234. npvs:=cparavarsym.create('$high'+paraprefix+copy(pvs.name,5,length(pvs.name)),pvs.paranr,pvs.varspez,
  5235. pvs.vardef,pvs.varoptions);
  5236. npvs.defaultconstsym:=pvs.defaultconstsym;
  5237. tabstractprocdef(result).parast.insertsym(npvs);
  5238. end;
  5239. constsym:
  5240. begin
  5241. // ignore, reuse original constym. Should also be duplicated
  5242. // be safe though
  5243. end;
  5244. symconst.typesym:
  5245. begin
  5246. // reuse original, part of generic declaration
  5247. end
  5248. else
  5249. internalerror(201160604);
  5250. end;
  5251. end;
  5252. end;
  5253. tabstractprocdef(result).savesize:=savesize;
  5254. if (typ<>procvardef) and
  5255. (newtyp=procvardef) then
  5256. begin
  5257. { procvars can't be (class)constructures/destructors etc }
  5258. if proctypeoption=potype_constructor then
  5259. begin
  5260. tabstractprocdef(result).returndef:=tdef(owner.defowner);
  5261. if not(is_implicit_pointer_object_type(returndef) or
  5262. (returndef.typ<>objectdef)) then
  5263. tabstractprocdef(result).returndef:=cpointerdef.getreusable(tabstractprocdef(result).returndef);
  5264. tabstractprocdef(result).proctypeoption:=potype_function;
  5265. end
  5266. else if is_void(returndef) then
  5267. tabstractprocdef(result).proctypeoption:=potype_procedure
  5268. else
  5269. tabstractprocdef(result).proctypeoption:=potype_function;
  5270. end
  5271. else
  5272. tabstractprocdef(result).proctypeoption:=proctypeoption;
  5273. tabstractprocdef(result).proccalloption:=proccalloption;
  5274. tabstractprocdef(result).procoptions:=procoptions;
  5275. if (copytyp=pc_bareproc) then
  5276. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  5277. if newtyp=procvardef then
  5278. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  5279. if copytyp=pc_address_only then
  5280. include(tabstractprocdef(result).procoptions,po_addressonly);
  5281. tabstractprocdef(result).callerargareasize:=callerargareasize;
  5282. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  5283. tabstractprocdef(result).maxparacount:=maxparacount;
  5284. tabstractprocdef(result).minparacount:=minparacount;
  5285. if po_explicitparaloc in procoptions then
  5286. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  5287. { recalculate parameter info }
  5288. tabstractprocdef(result).has_paraloc_info:=callnoside;
  5289. {$ifdef m68k}
  5290. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  5291. {$endif}
  5292. if (typ=procdef) and
  5293. (newtyp=procvardef) and
  5294. (owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  5295. include(tprocvardef(result).procoptions,po_methodpointer);
  5296. end;
  5297. function tabstractprocdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  5298. begin
  5299. result:=is_addressonly;
  5300. end;
  5301. procedure tabstractprocdef.check_mark_as_nested;
  5302. begin
  5303. { nested procvars require that nested functions use the Delphi-style
  5304. nested procedure calling convention }
  5305. if (parast.symtablelevel>normal_function_level) and
  5306. (m_nested_procvars in current_settings.modeswitches) then
  5307. include(procoptions,po_delphi_nested_cc);
  5308. end;
  5309. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  5310. begin
  5311. if (side in [callerside,callbothsides]) and
  5312. not(has_paraloc_info in [callerside,callbothsides]) then
  5313. begin
  5314. if not is_c_variadic(self) then
  5315. callerargareasize:=paramanager.create_paraloc_info(self,callerside)
  5316. else
  5317. callerargareasize:=paramanager.create_varargs_paraloc_info(self,callerside,nil);
  5318. if has_paraloc_info in [calleeside,callbothsides] then
  5319. has_paraloc_info:=callbothsides
  5320. else
  5321. has_paraloc_info:=callerside;
  5322. end;
  5323. if (side in [calleeside,callbothsides]) and
  5324. not(has_paraloc_info in [calleeside,callbothsides]) then
  5325. begin
  5326. if not is_c_variadic(self) then
  5327. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside)
  5328. else
  5329. callerargareasize:=paramanager.create_varargs_paraloc_info(self,calleeside,nil);
  5330. if has_paraloc_info in [callerside,callbothsides] then
  5331. has_paraloc_info:=callbothsides
  5332. else
  5333. has_paraloc_info:=calleeside;
  5334. end;
  5335. end;
  5336. procedure tabstractprocdef.done_paraloc_info(side: tcallercallee);
  5337. var
  5338. i: longint;
  5339. begin
  5340. if (side in [callerside,callbothsides]) and
  5341. (has_paraloc_info in [callerside,callbothsides]) then
  5342. begin
  5343. funcretloc[callerside].done;
  5344. for i:=0 to paras.count-1 do
  5345. tparavarsym(paras[i]).paraloc[callerside].done;
  5346. if has_paraloc_info=callerside then
  5347. has_paraloc_info:=callnoside
  5348. else
  5349. has_paraloc_info:=calleeside;
  5350. end;
  5351. if (side in [calleeside,callbothsides]) and
  5352. (has_paraloc_info in [calleeside,callbothsides]) then
  5353. begin
  5354. funcretloc[calleeside].done;
  5355. for i:=0 to paras.count-1 do
  5356. tparavarsym(paras[i]).paraloc[calleeside].done;
  5357. if has_paraloc_info=calleeside then
  5358. has_paraloc_info:=callnoside
  5359. else
  5360. has_paraloc_info:=callerside;
  5361. end;
  5362. end;
  5363. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  5364. var
  5365. p: tparavarsym;
  5366. ploc: PCGParalocation;
  5367. i: longint;
  5368. begin
  5369. result:=false;
  5370. init_paraloc_info(side);
  5371. for i:=0 to parast.SymList.Count-1 do
  5372. if tsym(parast.SymList[i]).typ=paravarsym then
  5373. begin
  5374. p:=tparavarsym(parast.SymList[i]);
  5375. if not p.is_used then
  5376. continue;
  5377. { check if no parameter is located on the stack }
  5378. if (is_open_array(p.vardef) or
  5379. is_array_of_const(p.vardef)) and (p.varspez=vs_value) then
  5380. begin
  5381. result:=true;
  5382. exit;
  5383. end;
  5384. ploc:=p.paraloc[side].location;
  5385. while assigned(ploc) do
  5386. begin
  5387. if (ploc^.loc=LOC_REFERENCE) then
  5388. begin
  5389. result:=true;
  5390. exit
  5391. end;
  5392. ploc:=ploc^.next;
  5393. end;
  5394. end;
  5395. end;
  5396. function tabstractprocdef.is_pushleftright: boolean;
  5397. begin
  5398. result:=false;
  5399. end;
  5400. function tabstractprocdef.address_type: tdef;
  5401. begin
  5402. result:=voidcodepointertype;
  5403. end;
  5404. function tabstractprocdef.ofs_address_type:tdef;
  5405. begin
  5406. result:=address_type;
  5407. end;
  5408. procedure tabstractprocdef.declared_far;
  5409. begin
  5410. Message1(parser_w_proc_directive_ignored,'FAR');
  5411. end;
  5412. procedure tabstractprocdef.declared_near;
  5413. begin
  5414. Message1(parser_w_proc_directive_ignored,'NEAR');
  5415. end;
  5416. function tabstractprocdef.generate_safecall_wrapper: boolean;
  5417. begin
  5418. {$ifdef SUPPORT_SAFECALL}
  5419. result:=
  5420. (proccalloption=pocall_safecall) and
  5421. not(po_assembler in procoptions) and
  5422. (tf_safecall_exceptions in target_info.flags);
  5423. {$else SUPPORT_SAFECALL}
  5424. result:=false;
  5425. {$endif}
  5426. end;
  5427. function tabstractprocdef.is_generic_param(def:tdef): boolean;
  5428. begin
  5429. if def.typ=undefineddef then
  5430. result:=def.owner=self.parast
  5431. else if def.typ=objectdef then
  5432. result:=(def.owner=self.parast) and (tstoreddef(def).genconstraintdata<>nil)
  5433. else
  5434. result:=false;
  5435. end;
  5436. {***************************************************************************
  5437. TPROCDEF
  5438. ***************************************************************************}
  5439. function tprocdef.getparentfpsym: tsym;
  5440. begin
  5441. if not assigned(_parentfpsym) then
  5442. begin
  5443. _parentfpsym:=tsym(parast.Find('parentfp'));
  5444. if not assigned(_parentfpsym) then
  5445. internalerror(200309281);
  5446. end;
  5447. result:=_parentfpsym;
  5448. end;
  5449. function tprocdef.Getis_implemented: boolean;
  5450. begin
  5451. result:=not assigned(implprocdefinfo) or implprocdefinfo^.is_implemented;
  5452. end;
  5453. procedure tprocdef.Setis_implemented(AValue: boolean);
  5454. begin
  5455. if not assigned(implprocdefinfo) then
  5456. internalerror(2020062101);
  5457. implprocdefinfo^.is_implemented:=AValue;
  5458. end;
  5459. function tprocdef.getwas_anonymous:boolean;
  5460. begin
  5461. result:=assigned(implprocdefinfo) and implprocdefinfo^.was_anonymous;
  5462. end;
  5463. procedure tprocdef.setwas_anonymous(avalue:boolean);
  5464. begin
  5465. if not assigned(implprocdefinfo) then
  5466. internalerror(2022020502);
  5467. implprocdefinfo^.was_anonymous:=avalue;
  5468. end;
  5469. function tprocdef.gethas_capturer:boolean;
  5470. begin
  5471. result:=assigned(implprocdefinfo) and implprocdefinfo^.has_capturer;
  5472. end;
  5473. procedure tprocdef.sethas_capturer(avalue:boolean);
  5474. begin
  5475. if not assigned(implprocdefinfo) then
  5476. internalerror(2022020503);
  5477. implprocdefinfo^.has_capturer:=avalue;
  5478. end;
  5479. function tprocdef.Getcapturedsyms:tfplist;
  5480. begin
  5481. if not assigned(implprocdefinfo) then
  5482. result:=nil
  5483. else
  5484. result:=implprocdefinfo^.capturedsyms;
  5485. end;
  5486. function tprocdef.store_localst: boolean;
  5487. begin
  5488. result:=has_inlininginfo or (df_generic in defoptions);
  5489. end;
  5490. function tprocdef.GetResultName: PShortString;
  5491. begin
  5492. if not assigned(implprocdefinfo) then
  5493. internalerror(2014010301);
  5494. result:=implprocdefinfo^.resultname;
  5495. end;
  5496. procedure tprocdef.SetResultName(AValue: PShortString);
  5497. begin
  5498. if not assigned(implprocdefinfo) then
  5499. internalerror(2014010302);
  5500. implprocdefinfo^.resultname:=AValue;
  5501. end;
  5502. function tprocdef.GetParentFPInitBlock: tnode;
  5503. begin
  5504. if not assigned(implprocdefinfo) then
  5505. internalerror(2014010303);
  5506. result:=implprocdefinfo^.parentfpinitblock;
  5507. end;
  5508. function tprocdef.GetParentFPStruct: tsym;
  5509. begin
  5510. if not assigned(implprocdefinfo) then
  5511. internalerror(2014010304);
  5512. result:=implprocdefinfo^.parentfpstruct;
  5513. end;
  5514. function tprocdef.GetParentFPStructPtrType: tdef;
  5515. begin
  5516. if not assigned(implprocdefinfo) then
  5517. internalerror(2014010305);
  5518. result:=implprocdefinfo^.parentfpstructptrtype;
  5519. end;
  5520. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  5521. begin
  5522. if not assigned(implprocdefinfo) then
  5523. internalerror(2014010306);
  5524. implprocdefinfo^.parentfpinitblock:=AValue;
  5525. end;
  5526. function tprocdef.Getprocendtai: tai;
  5527. begin
  5528. if not assigned(implprocdefinfo) then
  5529. internalerror(2014010307);
  5530. result:=implprocdefinfo^.procendtai;
  5531. end;
  5532. function tprocdef.Getprocstarttai: tai;
  5533. begin
  5534. if not assigned(implprocdefinfo) then
  5535. internalerror(2014010308);
  5536. result:=implprocdefinfo^.procstarttai;
  5537. end;
  5538. procedure tprocdef.Setprocendtai(AValue: tai);
  5539. begin
  5540. if not assigned(implprocdefinfo) then
  5541. internalerror(2014010309);
  5542. implprocdefinfo^.procendtai:=AValue;
  5543. end;
  5544. function tprocdef.Getskpara: pointer;
  5545. begin
  5546. if not assigned(implprocdefinfo) then
  5547. internalerror(2014010310);
  5548. result:=implprocdefinfo^.skpara;
  5549. end;
  5550. procedure tprocdef.Setskpara(AValue: pointer);
  5551. begin
  5552. if not assigned(implprocdefinfo) then
  5553. internalerror(2014010311);
  5554. implprocdefinfo^.skpara:=AValue;
  5555. end;
  5556. function tprocdef.Getpersonality: tprocdef;
  5557. begin
  5558. if not assigned(implprocdefinfo) then
  5559. internalerror(2016121704);
  5560. result:=implprocdefinfo^.personality;
  5561. end;
  5562. procedure tprocdef.Setpersonality(AValue: tprocdef);
  5563. begin
  5564. if not assigned(implprocdefinfo) then
  5565. internalerror(2016121705);
  5566. implprocdefinfo^.personality:=AValue;
  5567. end;
  5568. function tprocdef.Getforwarddef: boolean;
  5569. begin
  5570. if not assigned(implprocdefinfo) then
  5571. internalerror(2014010312);
  5572. result:=implprocdefinfo^.forwarddef;
  5573. end;
  5574. function tprocdef.Gethasforward: boolean;
  5575. begin
  5576. if not assigned(implprocdefinfo) then
  5577. internalerror(2014010313);
  5578. result:=implprocdefinfo^.hasforward;
  5579. end;
  5580. function tprocdef.Getinterfacedef: boolean;
  5581. begin
  5582. if not assigned(implprocdefinfo) then
  5583. internalerror(2014010314);
  5584. result:=implprocdefinfo^.interfacedef;
  5585. end;
  5586. procedure tprocdef.Setforwarddef(AValue: boolean);
  5587. begin
  5588. if not assigned(implprocdefinfo) then
  5589. internalerror(2014010315);
  5590. implprocdefinfo^.forwarddef:=AValue;
  5591. end;
  5592. procedure tprocdef.Sethasforward(AValue: boolean);
  5593. begin
  5594. if not assigned(implprocdefinfo) then
  5595. internalerror(2014010316);
  5596. implprocdefinfo^.hasforward:=AValue;
  5597. end;
  5598. function tprocdef.GetIsEmpty: boolean;
  5599. begin
  5600. result:=pio_empty in implprocoptions;
  5601. end;
  5602. procedure tprocdef.SetIsEmpty(AValue: boolean);
  5603. begin
  5604. if AValue then
  5605. include(implprocoptions,pio_empty)
  5606. else
  5607. exclude(implprocoptions,pio_empty);
  5608. end;
  5609. function tprocdef.GetHasInliningInfo: boolean;
  5610. begin
  5611. result:=pio_has_inlininginfo in implprocoptions;
  5612. end;
  5613. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  5614. begin
  5615. if AValue then
  5616. include(implprocoptions,pio_has_inlininginfo)
  5617. else
  5618. exclude(implprocoptions,pio_has_inlininginfo);
  5619. end;
  5620. procedure tprocdef.Setinterfacedef(AValue: boolean);
  5621. begin
  5622. if not assigned(implprocdefinfo) then
  5623. internalerror(2014010317);
  5624. implprocdefinfo^.interfacedef:=AValue;
  5625. end;
  5626. procedure tprocdef.Setprocstarttai(AValue: tai);
  5627. begin
  5628. if not assigned(implprocdefinfo) then
  5629. internalerror(2014010318);
  5630. implprocdefinfo^.procstarttai:=AValue;
  5631. end;
  5632. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  5633. begin
  5634. if not assigned(implprocdefinfo) then
  5635. internalerror(2014010319);
  5636. implprocdefinfo^.parentfpstruct:=AValue;
  5637. end;
  5638. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  5639. begin
  5640. if not assigned(implprocdefinfo) then
  5641. internalerror(2014010320);
  5642. implprocdefinfo^.parentfpstructptrtype:=AValue;
  5643. end;
  5644. constructor tprocdef.create(level:byte;doregister:boolean);
  5645. begin
  5646. inherited create(procdef,level,doregister);
  5647. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  5648. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  5649. {$ifdef symansistr}
  5650. _mangledname:='';
  5651. {$else symansistr}
  5652. _mangledname:=nil;
  5653. {$endif symansistr}
  5654. {$ifndef DISABLE_FAST_OVERLOAD_PATCH}
  5655. seenmarker := nil;
  5656. {$endif}
  5657. fileinfo:=current_filepos;
  5658. extnumber:=$ffff;
  5659. aliasnames:=TCmdStrList.create;
  5660. funcretsym:=nil;
  5661. funcretsymderef.reset;
  5662. procsymderef.reset;
  5663. forwarddef:=true;
  5664. interfacedef:=false;
  5665. hasforward:=false;
  5666. struct := nil;
  5667. structderef.reset;
  5668. import_dll:=nil;
  5669. import_name:=nil;
  5670. import_nr:=0;
  5671. inlininginfo:=nil;
  5672. deprecatedmsg:=nil;
  5673. genericdecltokenbuf:=nil;
  5674. if cs_opt_fastmath in current_settings.optimizerswitches then
  5675. include(implprocoptions, pio_fastmath);
  5676. end;
  5677. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  5678. var
  5679. i,aliasnamescount,sizeleft : longint;
  5680. level : byte;
  5681. buf : array[0..255] of byte;
  5682. begin
  5683. inherited ppuload(procdef,ppufile);
  5684. {$ifdef symansistr}
  5685. if po_has_mangledname in procoptions then
  5686. _mangledname:=ppufile.getansistring
  5687. else
  5688. _mangledname:='';
  5689. {$else symansistr}
  5690. if po_has_mangledname in procoptions then
  5691. _mangledname:=ppufile.getpshortstring
  5692. else
  5693. _mangledname:=nil;
  5694. {$endif symansistr}
  5695. extnumber:=ppufile.getword;
  5696. level:=ppufile.getbyte;
  5697. ppufile.getderef(structderef);
  5698. ppufile.getderef(procsymderef);
  5699. ppufile.getposinfo(fileinfo);
  5700. visibility:=tvisibility(ppufile.getbyte);
  5701. ppufile.getset(tppuset2(symoptions));
  5702. if sp_has_deprecated_msg in symoptions then
  5703. deprecatedmsg:=ppufile.getpshortstring
  5704. else
  5705. deprecatedmsg:=nil;
  5706. { import stuff }
  5707. if po_has_importdll in procoptions then
  5708. import_dll:=ppufile.getpshortstring
  5709. else
  5710. import_dll:=nil;
  5711. if po_has_importname in procoptions then
  5712. import_name:=ppufile.getpshortstring
  5713. else
  5714. import_name:=nil;
  5715. import_nr:=ppufile.getword;
  5716. if (po_msgint in procoptions) then
  5717. messageinf.i:=ppufile.getlongint;
  5718. if (po_msgstr in procoptions) then
  5719. messageinf.str:=ppufile.getpshortstring;
  5720. if (po_dispid in procoptions) then
  5721. dispid:=ppufile.getlongint;
  5722. { inline stuff }
  5723. ppufile.getset(tppuset1(implprocoptions));
  5724. if has_inlininginfo then
  5725. begin
  5726. ppufile.getderef(funcretsymderef);
  5727. new(inlininginfo);
  5728. ppufile.getset(tppuset4(inlininginfo^.flags));
  5729. end
  5730. else
  5731. begin
  5732. inlininginfo:=nil;
  5733. funcretsym:=nil;
  5734. end;
  5735. aliasnames:=TCmdStrList.create;
  5736. { count alias names }
  5737. aliasnamescount:=ppufile.getbyte;
  5738. for i:=1 to aliasnamescount do
  5739. aliasnames.insert(ppufile.getstring);
  5740. { load the token stream containing the declaration }
  5741. sizeleft:=ppufile.getlongint;
  5742. if sizeleft>0 then
  5743. begin
  5744. init_genericdecl;
  5745. while sizeleft>0 do
  5746. begin
  5747. if sizeleft>sizeof(buf) then
  5748. i:=sizeof(buf)
  5749. else
  5750. i:=sizeleft;
  5751. ppufile.getdata(buf,i);
  5752. genericdecltokenbuf.write(buf,i);
  5753. dec(sizeleft,i);
  5754. end;
  5755. end;
  5756. ppuload_platform(ppufile);
  5757. { load para symtable }
  5758. parast:=tparasymtable.create(self,level);
  5759. tparasymtable(parast).ppuload(ppufile);
  5760. { load local symtable }
  5761. if store_localst then
  5762. begin
  5763. localst:=tlocalsymtable.create(self,level);
  5764. tlocalsymtable(localst).ppuload(ppufile);
  5765. end
  5766. else
  5767. localst:=nil;
  5768. { inline stuff }
  5769. if has_inlininginfo then
  5770. inlininginfo^.code:=ppuloadnodetree(ppufile);
  5771. { default values for no persistent data }
  5772. if (cs_link_deffile in current_settings.globalswitches) and
  5773. (tf_need_export in target_info.flags) and
  5774. (po_exports in procoptions) then
  5775. deffile.AddExport(mangledname);
  5776. { Disable po_has_inlining until the derefimpl is done }
  5777. has_inlininginfo:=false;
  5778. end;
  5779. destructor tprocdef.destroy;
  5780. begin
  5781. aliasnames.free;
  5782. aliasnames:=nil;
  5783. if assigned(localst) and
  5784. (localst.symtabletype<>staticsymtable) then
  5785. begin
  5786. {$ifdef MEMDEBUG}
  5787. memproclocalst.start;
  5788. {$endif MEMDEBUG}
  5789. localst.free;
  5790. localst:=nil;
  5791. {$ifdef MEMDEBUG}
  5792. memproclocalst.start;
  5793. {$endif MEMDEBUG}
  5794. end;
  5795. if assigned(inlininginfo) then
  5796. begin
  5797. {$ifdef MEMDEBUG}
  5798. memprocnodetree.start;
  5799. {$endif MEMDEBUG}
  5800. tnode(inlininginfo^.code).free;
  5801. {$ifdef MEMDEBUG}
  5802. memprocnodetree.start;
  5803. {$endif MEMDEBUG}
  5804. dispose(inlininginfo);
  5805. inlininginfo:=nil;
  5806. end;
  5807. freeimplprocdefinfo;
  5808. genericdecltokenbuf.free;
  5809. genericdecltokenbuf:=nil;
  5810. stringdispose(import_dll);
  5811. stringdispose(import_name);
  5812. stringdispose(deprecatedmsg);
  5813. if (po_msgstr in procoptions) then
  5814. stringdispose(messageinf.str);
  5815. {$ifndef symansistr}
  5816. if assigned(_mangledname) then
  5817. begin
  5818. {$ifdef MEMDEBUG}
  5819. memmanglednames.start;
  5820. {$endif MEMDEBUG}
  5821. stringdispose(_mangledname);
  5822. {$ifdef MEMDEBUG}
  5823. memmanglednames.stop;
  5824. {$endif MEMDEBUG}
  5825. end;
  5826. {$endif symansistr}
  5827. inherited destroy;
  5828. end;
  5829. procedure tprocdef.freeimplprocdefinfo;
  5830. var
  5831. i : longint;
  5832. begin
  5833. if assigned(implprocdefinfo) then
  5834. begin
  5835. stringdispose(implprocdefinfo^.resultname);
  5836. if assigned(implprocdefinfo^.capturedsyms) then
  5837. begin
  5838. for i:=0 to implprocdefinfo^.capturedsyms.count-1 do
  5839. dispose(pcapturedsyminfo(implprocdefinfo^.capturedsyms[i]));
  5840. end;
  5841. implprocdefinfo^.capturedsyms.free;
  5842. implprocdefinfo^.capturedsyms:=nil;
  5843. freemem(implprocdefinfo);
  5844. implprocdefinfo:=nil;
  5845. end;
  5846. end;
  5847. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  5848. var
  5849. oldintfcrc : boolean;
  5850. aliasnamescount,i,sizeleft : longint;
  5851. item : TCmdStrListItem;
  5852. buf : array[0..255] of byte;
  5853. begin
  5854. { released procdef? }
  5855. if not assigned(parast) then
  5856. exit;
  5857. inherited ppuwrite(ppufile);
  5858. {$ifdef symansistr}
  5859. if po_has_mangledname in procoptions then
  5860. ppufile.putansistring(_mangledname);
  5861. {$else symansistr}
  5862. if po_has_mangledname in procoptions then
  5863. ppufile.putstring(_mangledname^);
  5864. {$endif symansistr}
  5865. ppufile.putword(extnumber);
  5866. ppufile.putbyte(parast.symtablelevel);
  5867. ppufile.putderef(structderef);
  5868. ppufile.putderef(procsymderef);
  5869. ppufile.putposinfo(fileinfo);
  5870. ppufile.putbyte(byte(visibility));
  5871. ppufile.putset(tppuset2(symoptions));
  5872. if sp_has_deprecated_msg in symoptions then
  5873. ppufile.putstring(deprecatedmsg^);
  5874. { import }
  5875. if po_has_importdll in procoptions then
  5876. ppufile.putstring(import_dll^);
  5877. if po_has_importname in procoptions then
  5878. ppufile.putstring(import_name^);
  5879. ppufile.putword(import_nr);
  5880. if (po_msgint in procoptions) then
  5881. ppufile.putlongint(messageinf.i);
  5882. if (po_msgstr in procoptions) then
  5883. ppufile.putstring(messageinf.str^);
  5884. if (po_dispid in procoptions) then
  5885. ppufile.putlongint(dispid);
  5886. { inline stuff }
  5887. oldintfcrc:=ppufile.do_crc;
  5888. ppufile.do_crc:=false;
  5889. ppufile.putset(tppuset1(implprocoptions));
  5890. if has_inlininginfo then
  5891. begin
  5892. ppufile.putderef(funcretsymderef);
  5893. ppufile.putset(tppuset4(inlininginfo^.flags));
  5894. end;
  5895. { count alias names }
  5896. aliasnamescount:=0;
  5897. item:=TCmdStrListItem(aliasnames.first);
  5898. while assigned(item) do
  5899. begin
  5900. inc(aliasnamescount);
  5901. item:=TCmdStrListItem(item.next);
  5902. end;
  5903. if aliasnamescount>255 then
  5904. internalerror(200711021);
  5905. ppufile.putbyte(aliasnamescount);
  5906. item:=TCmdStrListItem(aliasnames.first);
  5907. while assigned(item) do
  5908. begin
  5909. ppufile.putstring(item.str);
  5910. item:=TCmdStrListItem(item.next);
  5911. end;
  5912. ppufile.do_crc:=oldintfcrc;
  5913. { generic tokens for the declaration }
  5914. if assigned(genericdecltokenbuf) and (genericdecltokenbuf.size>0) then
  5915. begin
  5916. sizeleft:=genericdecltokenbuf.size;
  5917. genericdecltokenbuf.seek(0);
  5918. ppufile.putlongint(sizeleft);
  5919. while sizeleft>0 do
  5920. begin
  5921. if sizeleft>sizeof(buf) then
  5922. i:=sizeof(buf)
  5923. else
  5924. i:=sizeleft;
  5925. genericdecltokenbuf.read(buf,i);
  5926. ppufile.putdata(buf,i);
  5927. dec(sizeleft,i);
  5928. end;
  5929. end
  5930. else
  5931. ppufile.putlongint(0);
  5932. { write this entry }
  5933. writeentry(ppufile,ibprocdef);
  5934. { Save the para symtable, this is taken from the interface }
  5935. tparasymtable(parast).ppuwrite(ppufile);
  5936. { save localsymtable for inline procedures or when local
  5937. browser info is requested, this has no influence on the crc }
  5938. if store_localst and not ppufile.crc_only then
  5939. begin
  5940. oldintfcrc:=ppufile.do_crc;
  5941. ppufile.do_crc:=false;
  5942. tlocalsymtable(localst).ppuwrite(ppufile);
  5943. ppufile.do_crc:=oldintfcrc;
  5944. end;
  5945. { node tree for inlining }
  5946. oldintfcrc:=ppufile.do_crc;
  5947. ppufile.do_crc:=false;
  5948. if has_inlininginfo then
  5949. ppuwritenodetree(ppufile,inlininginfo^.code);
  5950. ppufile.do_crc:=oldintfcrc;
  5951. end;
  5952. function tprocdef.fullprocname(showhidden:boolean):string;
  5953. var
  5954. pno: tprocnameoptions;
  5955. begin
  5956. pno:=[];
  5957. if showhidden then
  5958. include(pno,pno_showhidden);
  5959. result:=customprocname(pno);
  5960. end;
  5961. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  5962. var
  5963. s, rn : ansistring;
  5964. t : ttoken;
  5965. syssym : tsyssym;
  5966. begin
  5967. {$ifdef EXTDEBUG}
  5968. include(pno,pno_showhidden);
  5969. {$endif EXTDEBUG}
  5970. s:='';
  5971. rn:='';
  5972. if proctypeoption=potype_operator then
  5973. begin
  5974. for t:=NOTOKEN to last_overloaded do
  5975. if procsym.realname='$'+overloaded_names[t] then
  5976. begin
  5977. s:='operator ';
  5978. if (pno_ownername in pno) and
  5979. assigned(struct) then
  5980. s:=s+struct.RttiName+'.';
  5981. s:=s+arraytokeninfo[t].str;
  5982. if not (pno_noparams in pno) then
  5983. s:=s+typename_paras(pno);
  5984. break;
  5985. end;
  5986. end
  5987. else
  5988. begin
  5989. if (po_classmethod in procoptions) and
  5990. not(pno_noclassmarker in pno) then
  5991. s:='class ';
  5992. case proctypeoption of
  5993. potype_constructor,
  5994. potype_class_constructor:
  5995. s:=s+'constructor ';
  5996. potype_class_destructor,
  5997. potype_destructor:
  5998. s:=s+'destructor ';
  5999. else
  6000. if (pno_proctypeoption in pno) and not (po_anonymous in procoptions) then
  6001. begin
  6002. if assigned(returndef) and
  6003. not(is_void(returndef)) then
  6004. s:=s+'function '
  6005. else
  6006. s:=s+'procedure ';
  6007. end;
  6008. end;
  6009. if (pno_ownername in pno) and
  6010. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  6011. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  6012. if (po_compilerproc in procoptions) and (extnumber<>$ffff) then
  6013. begin
  6014. syssym:=tsyssym.find_by_number(extnumber);
  6015. if not assigned(syssym) then
  6016. internalerror(2016060305);
  6017. rn:=syssym.realname;
  6018. end
  6019. else if po_anonymous in procoptions then
  6020. begin
  6021. s:=s+'anonymous ';
  6022. if assigned(returndef) and
  6023. not(is_void(returndef)) then
  6024. s:=s+'function'
  6025. else
  6026. s:=s+'procedure';
  6027. end
  6028. else
  6029. rn:=procsym.realname;
  6030. if (pno_noleadingdollar in pno) and
  6031. (rn[1]='$') then
  6032. delete(rn,1,1);
  6033. s:=s+rn;
  6034. if not (pno_noparams in pno) then
  6035. s:=s+typename_paras(pno);
  6036. end;
  6037. if not(proctypeoption in [potype_constructor,potype_destructor,
  6038. potype_class_constructor,potype_class_destructor]) and
  6039. assigned(returndef) and
  6040. not(is_void(returndef)) then
  6041. s:=s+':'+returndef.GetTypeName;
  6042. if not (po_anonymous in procoptions) then
  6043. if assigned(owner) and (owner.symtabletype=localsymtable) then
  6044. s:=s+' is nested'
  6045. else if po_is_block in procoptions then
  6046. s:=s+' is block';
  6047. s:=s+';';
  6048. if po_far in procoptions then
  6049. s:=s+' far;';
  6050. { forced calling convention? }
  6051. if (po_hascallingconvention in procoptions) then
  6052. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  6053. if (po_staticmethod in procoptions) and
  6054. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  6055. s:=s+' Static;';
  6056. if pno_mangledname in pno then
  6057. s:=s+' -- mangled name: '+mangledname;
  6058. customprocname:=s;
  6059. end;
  6060. function tprocdef.is_methodpointer:boolean;
  6061. begin
  6062. { don't check assigned(_class), that's also the case for nested
  6063. procedures inside methods }
  6064. result:=(owner.symtabletype in [recordsymtable,ObjectSymtable]) and not no_self_node;
  6065. end;
  6066. function tprocdef.is_addressonly:boolean;
  6067. begin
  6068. result:=assigned(owner) and
  6069. not is_methodpointer and
  6070. (not(m_nested_procvars in current_settings.modeswitches) or
  6071. not is_nested_pd(self)) and
  6072. (
  6073. not (po_anonymous in procoptions) or
  6074. not assigned(capturedsyms) or
  6075. (capturedsyms.count=0)
  6076. );
  6077. end;
  6078. procedure tprocdef.make_external;
  6079. begin
  6080. include(procoptions,po_external);
  6081. forwarddef:=false;
  6082. end;
  6083. procedure tprocdef.init_genericdecl;
  6084. begin
  6085. if assigned(genericdecltokenbuf) then
  6086. internalerror(2015061901);
  6087. genericdecltokenbuf:=tdynamicarray.create(256);
  6088. end;
  6089. function tprocdef.get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  6090. begin
  6091. result:=false;
  6092. if proctypeoption=potype_constructor then
  6093. begin
  6094. result:=true;
  6095. ressym:=tsym(parast.Find('self'));
  6096. resdef:=tabstractnormalvarsym(ressym).vardef;
  6097. { and TP-style constructors return a pointer to self }
  6098. if is_object(resdef) then
  6099. resdef:=cpointerdef.getreusable(resdef);
  6100. end
  6101. else if (proccalloption=pocall_safecall) and
  6102. (tf_safecall_exceptions in target_info.flags) then
  6103. begin
  6104. result:=true;
  6105. ressym:=tsym(localst.Find('safecallresult'));
  6106. resdef:=tabstractnormalvarsym(ressym).vardef;
  6107. end
  6108. else if not is_void(returndef) then
  6109. begin
  6110. result:=true;
  6111. ressym:=funcretsym;
  6112. resdef:=tabstractnormalvarsym(ressym).vardef;
  6113. end;
  6114. end;
  6115. function tprocdef.get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  6116. begin
  6117. result:=false;
  6118. if (proctypeoption<>potype_constructor) and
  6119. (proccalloption=pocall_safecall) and
  6120. (tf_safecall_exceptions in target_info.flags) then
  6121. begin
  6122. result:=true;
  6123. ressym:=tsym(localst.Find('safecallresult'));
  6124. resdef:=tabstractnormalvarsym(ressym).vardef;
  6125. end
  6126. end;
  6127. procedure tprocdef.add_captured_sym(sym:tsym;const filepos:tfileposinfo);
  6128. var
  6129. i : longint;
  6130. capturedsym : pcapturedsyminfo;
  6131. begin
  6132. if not assigned(implprocdefinfo) then
  6133. internalerror(2021052601);
  6134. if not assigned(implprocdefinfo^.capturedsyms) then
  6135. implprocdefinfo^.capturedsyms:=tfplist.create;
  6136. for i:=0 to implprocdefinfo^.capturedsyms.count-1 do
  6137. begin
  6138. capturedsym:=pcapturedsyminfo(implprocdefinfo^.capturedsyms[i]);
  6139. if capturedsym^.sym=sym then
  6140. exit;
  6141. end;
  6142. new(capturedsym);
  6143. capturedsym^.sym:=sym;
  6144. capturedsym^.fileinfo:=filepos;
  6145. implprocdefinfo^.capturedsyms.add(capturedsym);
  6146. end;
  6147. function tprocdef.has_alias_name(const s: TSymStr): boolean;
  6148. var
  6149. item : TCmdStrListItem;
  6150. begin
  6151. result:=true;
  6152. if mangledname=s then
  6153. exit;
  6154. item:=TCmdStrListItem(aliasnames.first);
  6155. while assigned(item) do
  6156. begin
  6157. if item.str=s then
  6158. exit;
  6159. item:=TCmdStrListItem(item.next);
  6160. end;
  6161. result:=false;
  6162. end;
  6163. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  6164. begin
  6165. case t of
  6166. gs_local :
  6167. GetSymtable:=localst;
  6168. gs_para :
  6169. GetSymtable:=parast;
  6170. else
  6171. GetSymtable:=nil;
  6172. end;
  6173. end;
  6174. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  6175. var
  6176. j : longint;
  6177. begin
  6178. result:=inherited;
  6179. if newtyp=procvardef then
  6180. begin
  6181. { create new paralist }
  6182. tprocvardef(result).calcparas;
  6183. exit;
  6184. end;
  6185. { don't copy mangled name, can be different }
  6186. tprocdef(result).messageinf:=messageinf;
  6187. tprocdef(result).dispid:=dispid;
  6188. if po_msgstr in procoptions then
  6189. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  6190. tprocdef(result).symoptions:=symoptions;
  6191. if assigned(deprecatedmsg) then
  6192. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  6193. { will have to be associated with appropriate procsym }
  6194. tprocdef(result).procsym:=nil;
  6195. { don't create aliases for bare copies, nor copy the funcretsym as
  6196. the function result parameter will be inserted again if necessary
  6197. (e.g. if the calling convention is changed) }
  6198. if not(copytyp in [pc_bareproc,pc_normal_no_hidden]) then
  6199. begin
  6200. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  6201. if assigned(funcretsym) then
  6202. begin
  6203. if funcretsym.owner=parast then
  6204. begin
  6205. j:=parast.symlist.indexof(funcretsym);
  6206. if j<0 then
  6207. internalerror(2011040606);
  6208. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  6209. end
  6210. else if funcretsym.owner=localst then
  6211. begin
  6212. { nothing to do, will be inserted for the new procdef while
  6213. parsing its body (by pdecsub.insert_funcret_local) }
  6214. end
  6215. else
  6216. internalerror(2011040605);
  6217. end;
  6218. end;
  6219. { will have to be associated with a new struct }
  6220. tprocdef(result).struct:=nil;
  6221. if assigned(implprocdefinfo) then
  6222. begin
  6223. if assigned(resultname) then
  6224. tprocdef(result).resultname:=stringdup(resultname^);
  6225. tprocdef(result).synthetickind:=synthetickind;
  6226. end;
  6227. if assigned(import_dll) then
  6228. tprocdef(result).import_dll:=stringdup(import_dll^);
  6229. if assigned(import_name) then
  6230. tprocdef(result).import_name:=stringdup(import_name^);
  6231. tprocdef(result).import_nr:=import_nr;
  6232. tprocdef(result).extnumber:=$ffff;
  6233. tprocdef(result).visibility:=visibility;
  6234. { we need a separate implementation for the copied def }
  6235. tprocdef(result).forwarddef:=true;
  6236. tprocdef(result).interfacedef:=true;
  6237. { create new paralist }
  6238. tprocdef(result).calcparas;
  6239. end;
  6240. function tprocdef.getcopy: tstoreddef;
  6241. begin
  6242. result:=getcopyas(procdef,pc_normal,'',true);
  6243. end;
  6244. procedure tprocdef.buildderef;
  6245. begin
  6246. inherited buildderef;
  6247. structderef.build(struct);
  6248. { procsym that originaly defined this definition, should be in the
  6249. same symtable }
  6250. procsymderef.build(procsym);
  6251. end;
  6252. procedure tprocdef.buildderefimpl;
  6253. begin
  6254. inherited buildderefimpl;
  6255. { Localst is not available for main/unit init }
  6256. if store_localst and assigned(localst) then
  6257. begin
  6258. tlocalsymtable(localst).buildderef;
  6259. tlocalsymtable(localst).buildderefimpl;
  6260. end;
  6261. { inline tree }
  6262. if has_inlininginfo then
  6263. begin
  6264. funcretsymderef.build(funcretsym);
  6265. inlininginfo^.code.buildderefimpl;
  6266. end;
  6267. end;
  6268. procedure tprocdef.deref;
  6269. begin
  6270. inherited deref;
  6271. struct:=tabstractrecorddef(structderef.resolve);
  6272. { procsym that originaly defined this definition, should be in the
  6273. same symtable }
  6274. procsym:=tprocsym(procsymderef.resolve);
  6275. end;
  6276. procedure tprocdef.derefimpl;
  6277. begin
  6278. { Enable has_inlininginfo when the inlininginfo
  6279. structure is available. The has_inlininginfo was disabled
  6280. after the load, since the data was invalid }
  6281. if assigned(inlininginfo) then
  6282. has_inlininginfo:=true;
  6283. { Locals }
  6284. if store_localst and assigned(localst) then
  6285. begin
  6286. tlocalsymtable(localst).deref(false);
  6287. tlocalsymtable(localst).derefimpl(false);
  6288. end;
  6289. { Inline }
  6290. if has_inlininginfo then
  6291. begin
  6292. inlininginfo^.code.derefimpl;
  6293. { funcretsym, this is always located in the localst }
  6294. funcretsym:=tsym(funcretsymderef.resolve);
  6295. end
  6296. else
  6297. begin
  6298. { safety }
  6299. { Not safe! A unit may be reresolved after its interface has been
  6300. parsed but before its implementation has been parsed, and in that
  6301. case the funcretsym is still required!
  6302. funcretsym:=nil; }
  6303. end;
  6304. end;
  6305. function tprocdef.GetTypeName : string;
  6306. begin
  6307. GetTypeName := FullProcName(false);
  6308. end;
  6309. function tprocdef.mangledname : TSymStr;
  6310. begin
  6311. {$ifdef symansistr}
  6312. if _mangledname='' then
  6313. begin
  6314. result:=defaultmangledname;
  6315. _mangledname:=result;
  6316. end
  6317. else
  6318. result:=_mangledname;
  6319. {$else symansistr}
  6320. if not assigned(_mangledname) then
  6321. begin
  6322. result:=defaultmangledname;
  6323. _mangledname:=stringdup(mangledname);
  6324. end
  6325. else
  6326. result:=_mangledname^;
  6327. {$endif symansistr}
  6328. end;
  6329. function tprocdef.defaultmangledname: TSymStr;
  6330. var
  6331. n : TSymStr;
  6332. begin
  6333. n:=procsym.name;
  6334. { make sure that the mangled names of these overloadable methods types is
  6335. unique even if it's made lowercase (e.g. for section names) }
  6336. if proctypeoption in [potype_operator,potype_class_constructor,potype_class_destructor] then
  6337. n:='$'+n;
  6338. { we need to use the symtable where the procsym is inserted,
  6339. because that is visible to the world }
  6340. defaultmangledname:=make_mangledname('',procsym.owner,n);
  6341. defaultmangledname:=defaultmangledname+mangledprocparanames(Length(defaultmangledname))
  6342. end;
  6343. function tprocdef.cplusplusmangledname : TSymStr;
  6344. function getcppparaname(p : tdef) : TSymStr;
  6345. const
  6346. {$ifdef NAMEMANGLING_GCC2}
  6347. ordtype2str : array[tordtype] of string[2] = (
  6348. '',
  6349. 'Uc','Us','Ui','Us','',
  6350. 'Sc','s','i','x','',
  6351. 'b','b','b','b','b','b',
  6352. 'c','w','x');
  6353. {$else NAMEMANGLING_GCC2}
  6354. ordtype2str : array[tordtype] of string[1] = (
  6355. 'v',
  6356. 'h','t','j','y','',
  6357. 'a','s','i','x','',
  6358. 'b','b','b','b','b',
  6359. 'b','b','b','b',
  6360. 'c','w','x','C');
  6361. floattype2str : array[tfloattype] of string[1] = (
  6362. 'f','d','e','e',
  6363. 'd','d','g');
  6364. {$endif NAMEMANGLING_GCC2}
  6365. var
  6366. s : TSymStr;
  6367. begin
  6368. case p.typ of
  6369. orddef:
  6370. begin
  6371. s:=ordtype2str[torddef(p).ordtype];
  6372. if s='C' then
  6373. s:=ordtype2str[range_to_basetype(torddef(p).low,torddef(p).high)];
  6374. end;
  6375. pointerdef:
  6376. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  6377. {$ifndef NAMEMANGLING_GCC2}
  6378. floatdef:
  6379. s:=floattype2str[tfloatdef(p).floattype];
  6380. {$endif NAMEMANGLING_GCC2}
  6381. else
  6382. internalerror(2103001);
  6383. end;
  6384. getcppparaname:=s;
  6385. end;
  6386. var
  6387. s,s2 : TSymStr;
  6388. hp : TParavarsym;
  6389. i : integer;
  6390. begin
  6391. {$ifdef NAMEMANGLING_GCC2}
  6392. { outdated gcc 2.x name mangling scheme }
  6393. s := procsym.realname;
  6394. if procsym.owner.symtabletype=ObjectSymtable then
  6395. begin
  6396. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  6397. case proctypeoption of
  6398. potype_destructor:
  6399. s:='_$_'+tostr(length(s2))+s2;
  6400. potype_constructor:
  6401. s:='___'+tostr(length(s2))+s2;
  6402. else
  6403. s:='_'+s+'__'+tostr(length(s2))+s2;
  6404. end;
  6405. end
  6406. else s:=s+'__';
  6407. s:=s+'F';
  6408. { concat modifiers }
  6409. { !!!!! }
  6410. { now we handle the parameters }
  6411. if maxparacount>0 then
  6412. begin
  6413. for i:=0 to paras.count-1 do
  6414. begin
  6415. hp:=tparavarsym(paras[i]);
  6416. { no hidden parameters form part of a C++ mangled name:
  6417. a) self is not included
  6418. b) there are no "high" or other hidden parameters
  6419. }
  6420. if vo_is_hidden_para in hp.varoptions then
  6421. continue;
  6422. s2:=getcppparaname(hp.vardef);
  6423. if hp.varspez in [vs_var,vs_out] then
  6424. s2:='R'+s2;
  6425. s:=s+s2;
  6426. end;
  6427. end
  6428. else
  6429. s:=s+'v';
  6430. cplusplusmangledname:=s;
  6431. {$else NAMEMANGLING_GCC2}
  6432. { gcc 3.x and 4.x name mangling scheme }
  6433. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  6434. if procsym.owner.symtabletype=ObjectSymtable then
  6435. begin
  6436. s:='_ZN';
  6437. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  6438. s:=s+tostr(length(s2))+s2;
  6439. case proctypeoption of
  6440. potype_constructor:
  6441. s:=s+'C1';
  6442. potype_destructor:
  6443. s:=s+'D1';
  6444. else
  6445. s:=s+tostr(length(procsym.realname))+procsym.realname;
  6446. end;
  6447. s:=s+'E';
  6448. end
  6449. else
  6450. s:=procsym.realname;
  6451. { now we handle the parameters }
  6452. if maxparacount>0 then
  6453. begin
  6454. for i:=0 to paras.count-1 do
  6455. begin
  6456. hp:=tparavarsym(paras[i]);
  6457. { no hidden parameters form part of a C++ mangled name:
  6458. a) self is not included
  6459. b) there are no "high" or other hidden parameters
  6460. }
  6461. if vo_is_hidden_para in hp.varoptions then
  6462. continue;
  6463. s2:=getcppparaname(hp.vardef);
  6464. if hp.varspez in [vs_var,vs_out] then
  6465. s2:='R'+s2;
  6466. s:=s+s2;
  6467. end;
  6468. end
  6469. else
  6470. s:=s+'v';
  6471. cplusplusmangledname:=s;
  6472. {$endif NAMEMANGLING_GCC2}
  6473. end;
  6474. function tprocdef.objcmangledname : TSymStr;
  6475. var
  6476. manglednamelen: longint;
  6477. iscatmethod : boolean;
  6478. begin
  6479. if not (po_msgstr in procoptions) then
  6480. internalerror(2009030901);
  6481. { we may very well need longer strings to handle these... }
  6482. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  6483. length('+"[ ]"')+length(messageinf.str^);
  6484. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  6485. if (iscatmethod) then
  6486. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  6487. if manglednamelen>255 then
  6488. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  6489. if not(po_classmethod in procoptions) then
  6490. result:='"-['
  6491. else
  6492. result:='"+[';
  6493. { quotes are necessary because the +/- otherwise confuse the assembler
  6494. into expecting a number
  6495. }
  6496. if iscatmethod then
  6497. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  6498. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  6499. if iscatmethod then
  6500. result:=result+')';
  6501. result:=result+' '+messageinf.str^+']"';
  6502. end;
  6503. procedure tprocdef.setmangledname(const s : TSymStr);
  6504. begin
  6505. { This is not allowed anymore, the forward declaration
  6506. already needs to create the correct mangledname, no changes
  6507. afterwards are allowed (PFV) }
  6508. { Exception: interface definitions in mode macpas, since in that }
  6509. { case no reference to the old name can exist yet (JM) }
  6510. {$ifdef symansistr}
  6511. if _mangledname<>'' then
  6512. if ((m_mac in current_settings.modeswitches) and
  6513. (interfacedef)) then
  6514. _mangledname:=''
  6515. else
  6516. internalerror(200411171);
  6517. {$else symansistr}
  6518. if assigned(_mangledname) then
  6519. if ((m_mac in current_settings.modeswitches) and
  6520. (interfacedef)) then
  6521. stringdispose(_mangledname)
  6522. else
  6523. internalerror(200411171);
  6524. {$endif symansistr}
  6525. {$ifdef jvm}
  6526. { this routine can be called for compilerproces. can't set mangled
  6527. name since it must be calculated, but it uses import_name when set
  6528. -> set that one }
  6529. import_name:=stringdup(s);
  6530. include(procoptions,po_has_importname);
  6531. include(procoptions,po_has_mangledname);
  6532. {$else}
  6533. {$ifdef symansistr}
  6534. _mangledname:=s;
  6535. {$else symansistr}
  6536. _mangledname:=stringdup(s);
  6537. {$endif symansistr}
  6538. {$endif jvm}
  6539. include(procoptions,po_has_mangledname);
  6540. end;
  6541. function tprocdef.needsglobalasmsym: boolean;
  6542. begin
  6543. result:=
  6544. (cs_profile in current_settings.moduleswitches) or
  6545. { smart linking using a library requires to promote
  6546. all non-nested procedures to AB_GLOBAL
  6547. otherwise you get undefined symbol error at linking
  6548. for msdos target with -CX option for instance }
  6549. (create_smartlink_library and not is_nested_pd(self)) or
  6550. (po_global in procoptions);
  6551. end;
  6552. procedure tprocdef.setcompilerprocname;
  6553. begin
  6554. procsym.realname:='$'+lower(procsym.name);
  6555. end;
  6556. {***************************************************************************
  6557. TPROCVARDEF
  6558. ***************************************************************************}
  6559. constructor tprocvardef.create(level:byte;doregister:boolean);
  6560. begin
  6561. inherited create(procvardef,level,doregister);
  6562. end;
  6563. class function tprocvardef.getreusableprocaddr(def: tabstractprocdef; copytyp: tcacheableproccopytyp): tprocvardef;
  6564. var
  6565. res: PHashSetItem;
  6566. oldsymtablestack: tsymtablestack;
  6567. key: packed record
  6568. def: tabstractprocdef;
  6569. copytyp: tcacheableproccopytyp;
  6570. end;
  6571. begin
  6572. if not assigned(current_module) then
  6573. internalerror(2011081302);
  6574. key.def:=def;
  6575. key.copytyp:=copytyp;
  6576. res:=current_module.procaddrdefs.FindOrAdd(@key,sizeof(key));
  6577. if not assigned(res^.Data) then
  6578. begin
  6579. { since these pointerdefs can be reused anywhere in the current
  6580. unit, add them to the global/staticsymtable (or local symtable
  6581. if they're a local def, because otherwise they'll be saved
  6582. to the ppu referencing a local symtable entry that doesn't
  6583. exist in the ppu) }
  6584. oldsymtablestack:=symtablestack;
  6585. { do not simply push/pop current_module.localsymtable, because
  6586. that can have side-effects (e.g., it removes helpers) }
  6587. symtablestack:=nil;
  6588. result:=tprocvardef(def.getcopyas(procvardef,copytyp,'',true));
  6589. setup_reusable_def(def,result,res,oldsymtablestack);
  6590. { res^.Data may still be nil -> don't overwrite result }
  6591. exit;
  6592. end;
  6593. result:=tprocvardef(res^.Data);
  6594. end;
  6595. class function tprocvardef.getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  6596. begin
  6597. result:=getreusableprocaddr(def,pc_address_only);
  6598. if not result.is_registered then
  6599. include(result.defoptions,df_not_registered_no_free);
  6600. end;
  6601. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  6602. begin
  6603. inherited ppuload(procvardef,ppufile);
  6604. { load para symtable }
  6605. parast:=tparasymtable.create(self,ppufile.getbyte);
  6606. ppuload_platform(ppufile);
  6607. tparasymtable(parast).ppuload(ppufile);
  6608. end;
  6609. function tprocvardef.getcopy : tstoreddef;
  6610. var
  6611. i : tcallercallee;
  6612. j : longint;
  6613. begin
  6614. result:=cprocvardef.create(parast.symtablelevel,true);
  6615. tprocvardef(result).returndef:=returndef;
  6616. tprocvardef(result).returndefderef:=returndefderef;
  6617. tprocvardef(result).parast:=parast.getcopy;
  6618. tprocvardef(result).savesize:=savesize;
  6619. { create paralist copy }
  6620. calcparas;
  6621. tprocvardef(result).paras:=tparalist.create(false);
  6622. tprocvardef(result).paras.count:=paras.count;
  6623. for j:=0 to paras.count-1 do
  6624. tprocvardef(result).paras[j]:=paras[j];
  6625. tprocvardef(result).proctypeoption:=proctypeoption;
  6626. tprocvardef(result).proccalloption:=proccalloption;
  6627. tprocvardef(result).procoptions:=procoptions;
  6628. tprocvardef(result).callerargareasize:=callerargareasize;
  6629. tprocvardef(result).calleeargareasize:=calleeargareasize;
  6630. tprocvardef(result).maxparacount:=maxparacount;
  6631. tprocvardef(result).minparacount:=minparacount;
  6632. for i:=low(funcretloc) to high(funcretloc) do
  6633. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  6634. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  6635. {$ifdef m68k}
  6636. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  6637. {$endif}
  6638. end;
  6639. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  6640. begin
  6641. inherited ppuwrite(ppufile);
  6642. { Save the para symtable level (necessary to distinguish nested
  6643. procvars) }
  6644. ppufile.putbyte(parast.symtablelevel);
  6645. { Write this entry }
  6646. writeentry(ppufile,ibprocvardef);
  6647. { Save the para symtable, this is taken from the interface }
  6648. tparasymtable(parast).ppuwrite(ppufile);
  6649. end;
  6650. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  6651. begin
  6652. case t of
  6653. gs_para :
  6654. GetSymtable:=parast;
  6655. else
  6656. GetSymtable:=nil;
  6657. end;
  6658. end;
  6659. function tprocvardef.size : asizeint;
  6660. begin
  6661. { we return false for is_addressonly for a block (because it's not a
  6662. simple pointer to a function), but they are handled as implicit
  6663. pointers to a datastructure that contains everything ->
  6664. voidpointertype.size instead of voidcodepointertype.size }
  6665. if po_is_block in procoptions then
  6666. size:=voidpointertype.size
  6667. else if not is_addressonly then
  6668. begin
  6669. if is_nested_pd(self) then
  6670. size:=voidcodepointertype.size+parentfpvoidpointertype.size
  6671. else
  6672. size:=voidcodepointertype.size+voidpointertype.size;
  6673. end
  6674. else
  6675. size:=voidcodepointertype.size;
  6676. end;
  6677. function tprocvardef.is_methodpointer:boolean;
  6678. begin
  6679. result:=(po_methodpointer in procoptions);
  6680. end;
  6681. function tprocvardef.is_addressonly:boolean;
  6682. begin
  6683. result:=((not(po_methodpointer in procoptions) or (po_staticmethod in procoptions)) and
  6684. not(po_is_block in procoptions) and
  6685. not is_nested_pd(self)) or
  6686. (po_addressonly in procoptions);
  6687. end;
  6688. function tprocvardef.getmangledparaname:TSymStr;
  6689. begin
  6690. if not(po_methodpointer in procoptions) then
  6691. if not is_nested_pd(self) then
  6692. result:='procvar'
  6693. else
  6694. { we need the manglednames here, because nestedprocvars can be anonymous, e.g.
  6695. having not a type name or not an unique one, see webtbs/tw27515.pp
  6696. Further, use $_ ... _$ delimiters to avoid ambiguous names, see webtbs/tw27515.pp }
  6697. result:='$_nestedprovar'+mangledprocparanames(0)+'_$'
  6698. else
  6699. result:='procvarofobj'
  6700. end;
  6701. function tprocvardef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string;doregister:boolean): tstoreddef;
  6702. begin
  6703. result:=inherited;
  6704. tabstractprocdef(result).calcparas;
  6705. end;
  6706. function tprocvardef.is_publishable : boolean;
  6707. begin
  6708. is_publishable:=(po_methodpointer in procoptions);
  6709. end;
  6710. function tprocvardef.GetTypeName : string;
  6711. var
  6712. s: string;
  6713. pno : tprocnameoptions;
  6714. begin
  6715. {$ifdef EXTDEBUG}
  6716. pno:=[pno_showhidden];
  6717. {$else EXTDEBUG}
  6718. pno:=[];
  6719. {$endif EXTDEBUG}
  6720. s:='<';
  6721. if po_is_block in procoptions then
  6722. s := s+'reference to'
  6723. else if po_classmethod in procoptions then
  6724. s := s+'class method type of'
  6725. else
  6726. if po_addressonly in procoptions then
  6727. s := s+'address of'
  6728. else
  6729. s := s+'procedure variable type of';
  6730. if assigned(returndef) and
  6731. (returndef<>voidtype) then
  6732. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  6733. else
  6734. s:=s+' procedure'+typename_paras(pno);
  6735. if po_methodpointer in procoptions then
  6736. s := s+' of object';
  6737. if is_nested_pd(self) then
  6738. s := s+' is nested';
  6739. if po_far in procoptions then
  6740. s := s+';far';
  6741. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  6742. end;
  6743. {***************************************************************************
  6744. TOBJECTDEF
  6745. ***************************************************************************}
  6746. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);
  6747. begin
  6748. inherited create(n,objectdef,doregister);
  6749. fcurrent_dispid:=0;
  6750. objecttype:=ot;
  6751. childof:=nil;
  6752. childofderef.reset;
  6753. vmt_fieldderef.reset;
  6754. extendeddefderef.reset;
  6755. cloneddefderef.reset;
  6756. if objecttype=odt_helper then
  6757. owner.includeoption(sto_has_helper);
  6758. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords,
  6759. current_settings.alignment.recordalignmin);
  6760. { create space for vmt !! }
  6761. vmtentries:=TFPList.Create;
  6762. set_parent(c);
  6763. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  6764. prepareguid;
  6765. { setup implemented interfaces }
  6766. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
  6767. ImplementedInterfaces:=TFPObjectList.Create(true)
  6768. else
  6769. ImplementedInterfaces:=nil;
  6770. writing_class_record_dbginfo:=false;
  6771. end;
  6772. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  6773. var
  6774. i,
  6775. implintfcount : longint;
  6776. d, getterd : tderef;
  6777. ImplIntf : TImplementedInterface;
  6778. vmtentry : pvmtentry;
  6779. begin
  6780. inherited ppuload(objectdef,ppufile);
  6781. objecttype:=tobjecttyp(ppufile.getbyte);
  6782. helpertype:=thelpertype(ppufile.getbyte);
  6783. objextname:=ppufile.getpshortstring;
  6784. { only used for external Objective-C classes/protocols }
  6785. if (objextname^='') then
  6786. stringdispose(objextname);
  6787. symtable:=tObjectSymtable.create(self,objrealname^,0,0);
  6788. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  6789. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  6790. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  6791. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  6792. tObjectSymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  6793. ppufile.getderef(vmt_fieldderef);
  6794. ppufile.getderef(childofderef);
  6795. { load guid }
  6796. iidstr:=nil;
  6797. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  6798. begin
  6799. new(iidguid);
  6800. ppufile.getguid(iidguid^);
  6801. iidstr:=ppufile.getpshortstring;
  6802. end;
  6803. abstractcnt:=ppufile.getlongint;
  6804. if objecttype=odt_helper then
  6805. ppufile.getderef(extendeddefderef);
  6806. vmtentries:=TFPList.Create;
  6807. vmtentries.count:=ppufile.getlongint;
  6808. for i:=0 to vmtentries.count-1 do
  6809. begin
  6810. ppufile.getderef(d);
  6811. new(vmtentry);
  6812. vmtentry^.procdef:=nil;
  6813. vmtentry^.procdefderef:=d;
  6814. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  6815. vmtentries[i]:=vmtentry;
  6816. end;
  6817. { load implemented interfaces }
  6818. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_objccategory,odt_javaclass,odt_interfacejava] then
  6819. begin
  6820. ImplementedInterfaces:=TFPObjectList.Create(true);
  6821. implintfcount:=ppufile.getlongint;
  6822. for i:=0 to implintfcount-1 do
  6823. begin
  6824. ppufile.getderef(d);
  6825. ppufile.getderef(getterd);
  6826. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  6827. ImplIntf.IOffset:=ppufile.getlongint;
  6828. byte(ImplIntf.IType):=ppufile.getbyte;
  6829. ImplementedInterfaces.Add(ImplIntf);
  6830. end;
  6831. end
  6832. else
  6833. ImplementedInterfaces:=nil;
  6834. if df_copied_def in defoptions then
  6835. begin
  6836. ppufile.getderef(cloneddefderef);
  6837. ppuload_platform(ppufile);
  6838. end
  6839. else
  6840. begin
  6841. ppuload_platform(ppufile);
  6842. tObjectSymtable(symtable).ppuload(ppufile);
  6843. end;
  6844. { handles the predefined class tobject }
  6845. { the last TOBJECT which is loaded gets }
  6846. { it ! }
  6847. if (childof=nil) and
  6848. (objecttype in [odt_class,odt_javaclass]) and
  6849. (objname^='TOBJECT') then
  6850. class_tobject:=self;
  6851. if (childof=nil) and
  6852. (objecttype=odt_interfacecom) then
  6853. if (objname^='IUNKNOWN') then
  6854. interface_iunknown:=self
  6855. else
  6856. if (objname^='IDISPATCH') then
  6857. interface_idispatch:=self;
  6858. if (childof=nil) and
  6859. (objecttype=odt_objcclass) and
  6860. (objname^='PROTOCOL') then
  6861. objc_protocoltype:=self;
  6862. if (objecttype=odt_javaclass) and
  6863. not(oo_is_formal in objectoptions) then
  6864. begin
  6865. if (objname^='JLOBJECT') then
  6866. java_jlobject:=self
  6867. else if (objname^='JLTHROWABLE') then
  6868. java_jlthrowable:=self
  6869. else if (objname^='FPCBASERECORDTYPE') then
  6870. java_fpcbaserecordtype:=self
  6871. else if (objname^='JLSTRING') then
  6872. java_jlstring:=self
  6873. else if (objname^='ANSISTRINGCLASS') then
  6874. java_ansistring:=self
  6875. else if (objname^='SHORTSTRINGCLASS') then
  6876. java_shortstring:=self
  6877. else if (objname^='JLENUM') then
  6878. java_jlenum:=self
  6879. else if (objname^='JUENUMSET') then
  6880. java_juenumset:=self
  6881. else if (objname^='FPCBITSET') then
  6882. java_jubitset:=self
  6883. else if (objname^='FPCBASEPROCVARTYPE') then
  6884. java_procvarbase:=self;
  6885. end;
  6886. writing_class_record_dbginfo:=false;
  6887. end;
  6888. destructor tobjectdef.destroy;
  6889. var
  6890. i: longint;
  6891. begin
  6892. if assigned(symtable) then
  6893. begin
  6894. symtable.free;
  6895. symtable:=nil;
  6896. end;
  6897. stringdispose(objextname);
  6898. stringdispose(iidstr);
  6899. if assigned(ImplementedInterfaces) then
  6900. begin
  6901. ImplementedInterfaces.free;
  6902. ImplementedInterfaces:=nil;
  6903. end;
  6904. if assigned(iidguid) then
  6905. begin
  6906. dispose(iidguid);
  6907. iidguid:=nil;
  6908. end;
  6909. if assigned(vmtentries) then
  6910. begin
  6911. for i:=0 to vmtentries.count-1 do
  6912. dispose(pvmtentry(vmtentries[i]));
  6913. vmtentries.free;
  6914. vmtentries:=nil;
  6915. end;
  6916. if assigned(vmcallstaticinfo) then
  6917. begin
  6918. freemem(vmcallstaticinfo);
  6919. vmcallstaticinfo:=nil;
  6920. end;
  6921. inherited destroy;
  6922. end;
  6923. function tobjectdef.getcopy : tstoreddef;
  6924. var
  6925. i : longint;
  6926. begin
  6927. result:=cobjectdef.create(objecttype,objrealname^,childof,true);
  6928. { the constructor allocates a symtable which we release to avoid memory leaks }
  6929. tobjectdef(result).symtable.free;
  6930. tobjectdef(result).symtable:=symtable.getcopy;
  6931. if assigned(objextname) then
  6932. tobjectdef(result).objextname:=stringdup(objextname^);
  6933. if assigned(import_lib) then
  6934. tobjectdef(result).import_lib:=stringdup(import_lib^);
  6935. tobjectdef(result).objectoptions:=objectoptions;
  6936. include(tobjectdef(result).defoptions,df_copied_def);
  6937. tobjectdef(result).extendeddef:=extendeddef;
  6938. if assigned(tcinitcode) then
  6939. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  6940. tobjectdef(result).vmt_field:=vmt_field;
  6941. if assigned(iidguid) then
  6942. begin
  6943. new(tobjectdef(result).iidguid);
  6944. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  6945. end;
  6946. if assigned(iidstr) then
  6947. tobjectdef(result).iidstr:=stringdup(iidstr^);
  6948. tobjectdef(result).abstractcnt:=abstractcnt;
  6949. if assigned(ImplementedInterfaces) then
  6950. begin
  6951. for i:=0 to ImplementedInterfaces.count-1 do
  6952. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  6953. end;
  6954. tobjectdef(result).copyvmtentries(self);
  6955. end;
  6956. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  6957. var
  6958. i : longint;
  6959. vmtentry : pvmtentry;
  6960. ImplIntf : TImplementedInterface;
  6961. old_do_indirect_crc: boolean;
  6962. begin
  6963. { if class1 in unit A changes, and class2 in unit B inherits from it
  6964. (so unit B uses unit A), then unit B with class2 will be recompiled.
  6965. However, if there is also a class3 in unit C that only depends on
  6966. unit B, then unit C will not be recompiled because nothing changed
  6967. to the interface of unit B. Nevertheless, unit C can indirectly
  6968. depend on unit A via derefs, and these must be updated -> the
  6969. indirect crc keeps track of such changes. }
  6970. old_do_indirect_crc:=ppufile.do_indirect_crc;
  6971. ppufile.do_indirect_crc:=true;
  6972. inherited ppuwrite(ppufile);
  6973. ppufile.putbyte(byte(objecttype));
  6974. ppufile.putbyte(byte(helpertype));
  6975. if assigned(objextname) then
  6976. ppufile.putstring(objextname^)
  6977. else
  6978. ppufile.putstring('');
  6979. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  6980. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  6981. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  6982. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  6983. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignmin));
  6984. ppufile.putderef(vmt_fieldderef);
  6985. ppufile.putderef(childofderef);
  6986. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  6987. begin
  6988. ppufile.putguid(iidguid^);
  6989. ppufile.putstring(iidstr^);
  6990. end;
  6991. ppufile.putlongint(abstractcnt);
  6992. if objecttype=odt_helper then
  6993. ppufile.putderef(extendeddefderef);
  6994. ppufile.putlongint(vmtentries.count);
  6995. for i:=0 to vmtentries.count-1 do
  6996. begin
  6997. vmtentry:=pvmtentry(vmtentries[i]);
  6998. ppufile.putderef(vmtentry^.procdefderef);
  6999. ppufile.putbyte(byte(vmtentry^.visibility));
  7000. end;
  7001. if assigned(ImplementedInterfaces) then
  7002. begin
  7003. ppufile.putlongint(ImplementedInterfaces.Count);
  7004. for i:=0 to ImplementedInterfaces.Count-1 do
  7005. begin
  7006. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  7007. ppufile.putderef(ImplIntf.intfdefderef);
  7008. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  7009. ppufile.putlongint(ImplIntf.Ioffset);
  7010. ppufile.putbyte(byte(ImplIntf.IType));
  7011. end;
  7012. end;
  7013. if df_copied_def in defoptions then
  7014. ppufile.putderef(cloneddefderef);
  7015. writeentry(ppufile,ibobjectdef);
  7016. if not(df_copied_def in defoptions) then
  7017. tObjectSymtable(symtable).ppuwrite(ppufile);
  7018. ppufile.do_indirect_crc:=old_do_indirect_crc;
  7019. end;
  7020. function tobjectdef.GetTypeName:string;
  7021. begin
  7022. { in this case we will go in endless recursion, because then }
  7023. { there is no tsym associated yet with the def. It can occur }
  7024. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  7025. { instead of the actual type name }
  7026. if not assigned(typesym) then
  7027. result:='<Currently Parsed Class>'
  7028. else
  7029. result:=typesymbolprettyname;
  7030. end;
  7031. procedure tobjectdef.buildderef;
  7032. var
  7033. i : longint;
  7034. vmtentry : pvmtentry;
  7035. begin
  7036. inherited buildderef;
  7037. vmt_fieldderef.build(vmt_field);
  7038. childofderef.build(childof);
  7039. if df_copied_def in defoptions then
  7040. cloneddefderef.build(symtable.defowner)
  7041. else
  7042. tstoredsymtable(symtable).buildderef;
  7043. if objecttype=odt_helper then
  7044. extendeddefderef.build(extendeddef);
  7045. for i:=0 to vmtentries.count-1 do
  7046. begin
  7047. vmtentry:=pvmtentry(vmtentries[i]);
  7048. vmtentry^.procdefderef.build(vmtentry^.procdef);
  7049. end;
  7050. if assigned(ImplementedInterfaces) then
  7051. begin
  7052. for i:=0 to ImplementedInterfaces.count-1 do
  7053. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  7054. end;
  7055. end;
  7056. procedure tobjectdef.deref;
  7057. var
  7058. i : longint;
  7059. vmtentry : pvmtentry;
  7060. begin
  7061. inherited deref;
  7062. vmt_field:=tsym(vmt_fieldderef.resolve);
  7063. childof:=tobjectdef(childofderef.resolve);
  7064. if df_copied_def in defoptions then
  7065. begin
  7066. cloneddef:=tobjectdef(cloneddefderef.resolve);
  7067. symtable:=cloneddef.symtable.getcopy;
  7068. end
  7069. else
  7070. tstoredsymtable(symtable).deref(false);
  7071. if objecttype=odt_helper then
  7072. extendeddef:=tdef(extendeddefderef.resolve);
  7073. for i:=0 to vmtentries.count-1 do
  7074. begin
  7075. vmtentry:=pvmtentry(vmtentries[i]);
  7076. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  7077. end;
  7078. if assigned(ImplementedInterfaces) then
  7079. begin
  7080. for i:=0 to ImplementedInterfaces.count-1 do
  7081. TImplementedInterface(ImplementedInterfaces[i]).deref;
  7082. end;
  7083. end;
  7084. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  7085. var
  7086. pd: tprocdef absolute def;
  7087. st: tsymtable;
  7088. psym: tsym;
  7089. nname: TIDString;
  7090. begin
  7091. if (tdef(def).typ<>procdef) then
  7092. exit;
  7093. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  7094. owner = symtable in which objcclassdef is defined
  7095. }
  7096. st:=pd.owner.defowner.owner;
  7097. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  7098. { check for an existing procsym with our special name }
  7099. psym:=tsym(st.find(nname));
  7100. if not assigned(psym) then
  7101. begin
  7102. psym:=cprocsym.create(nname);
  7103. { avoid warning about this symbol being unused }
  7104. psym.IncRefCount;
  7105. { don't check for duplicates:
  7106. a) we checked above
  7107. b) in case we are in the implementation section of a unit, this
  7108. will also check for this symbol in the interface section
  7109. (since you normally cannot have symbols with the same name
  7110. both interface and implementation), and it's possible to
  7111. have class helpers for the same class in the interface and
  7112. in the implementation, and they cannot be merged since only
  7113. the once in the interface must be saved to the ppu/visible
  7114. from other units }
  7115. st.insertsym(psym,false);
  7116. end
  7117. else if (psym.typ<>procsym) then
  7118. internalerror(2009111501);
  7119. { add ourselves to this special procsym }
  7120. tprocsym(psym).procdeflist.add(def);
  7121. end;
  7122. procedure tobjectdef.derefimpl;
  7123. begin
  7124. inherited derefimpl;
  7125. { the procdefs are not owned by the class helper procsyms, so they
  7126. are not stored/restored either -> re-add them here }
  7127. if (objecttype in [odt_objcclass,odt_objcprotocol]) or
  7128. (oo_is_classhelper in objectoptions) then
  7129. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  7130. end;
  7131. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  7132. var
  7133. i : longint;
  7134. vmtentry : pvmtentry;
  7135. begin
  7136. if vmtentries.count<>0 then
  7137. internalerror(2019081401);
  7138. vmtentries.count:=objdef.vmtentries.count;
  7139. for i:=0 to objdef.vmtentries.count-1 do
  7140. begin
  7141. new(vmtentry);
  7142. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  7143. vmtentries[i]:=vmtentry;
  7144. end;
  7145. end;
  7146. function tobjectdef.getparentdef:tdef;
  7147. begin
  7148. { TODO: Remove getparentdef hack}
  7149. { With 2 forward declared classes with the child class before the
  7150. parent class the child class is written earlier to the ppu. Leaving it
  7151. possible to have a reference to the parent class for property overriding,
  7152. but the parent class still has the childof not resolved yet (PFV) }
  7153. if childof=nil then
  7154. childof:=tobjectdef(childofderef.resolve);
  7155. result:=childof;
  7156. end;
  7157. procedure tobjectdef.prepareguid;
  7158. begin
  7159. { set up guid }
  7160. if not assigned(iidguid) then
  7161. begin
  7162. new(iidguid);
  7163. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  7164. end;
  7165. { setup iidstring }
  7166. if not assigned(iidstr) then
  7167. iidstr:=stringdup(''); { default is empty string }
  7168. end;
  7169. procedure tobjectdef.set_parent( c : tobjectdef);
  7170. begin
  7171. if assigned(childof) then
  7172. exit;
  7173. childof:=c;
  7174. if not assigned(c) then
  7175. exit;
  7176. { inherit options and status }
  7177. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  7178. { initially has the same number of abstract methods as the parent }
  7179. abstractcnt:=c.abstractcnt;
  7180. { add the data of the anchestor class/object }
  7181. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  7182. begin
  7183. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  7184. { inherit recordalignment }
  7185. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  7186. { if both the parent and this record use C-alignment, also inherit
  7187. the current field alignment }
  7188. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  7189. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  7190. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  7191. { the padding is not inherited for Objective-C classes (maybe not
  7192. for cppclass either?) }
  7193. if objecttype=odt_objcclass then
  7194. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  7195. if (oo_has_vmt in objectoptions) and
  7196. (oo_has_vmt in c.objectoptions) then
  7197. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  7198. { if parent has a vmt field then the offset is the same for the child PM }
  7199. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  7200. begin
  7201. vmt_field:=c.vmt_field;
  7202. include(objectoptions,oo_has_vmt);
  7203. end;
  7204. end;
  7205. end;
  7206. procedure tobjectdef.insertvmt;
  7207. begin
  7208. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  7209. exit;
  7210. if (oo_has_vmt in objectoptions) then
  7211. internalerror(2020100816)
  7212. else
  7213. begin
  7214. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  7215. tObjectSymtable(symtable).fieldalignment);
  7216. if (tf_requires_proper_alignment in target_info.flags) then
  7217. begin
  7218. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  7219. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  7220. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  7221. end;
  7222. vmt_field:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  7223. hidesym(vmt_field);
  7224. tObjectSymtable(symtable).insertsym(vmt_field);
  7225. tObjectSymtable(symtable).addfield(tfieldvarsym(vmt_field),vis_hidden);
  7226. include(objectoptions,oo_has_vmt);
  7227. end;
  7228. end;
  7229. function tobjectdef.vmt_offset: asizeint;
  7230. begin
  7231. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  7232. result:=0
  7233. else if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  7234. result:=tfieldvarsym(vmt_field).fieldoffset
  7235. else
  7236. result:=tfieldvarsym(vmt_field).fieldoffset div 8;
  7237. end;
  7238. procedure tobjectdef.check_forwards;
  7239. begin
  7240. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  7241. inherited;
  7242. if (oo_is_forward in objectoptions) then
  7243. begin
  7244. { ok, in future, the forward can be resolved }
  7245. Message1(sym_e_class_forward_not_resolved,objrealname^);
  7246. exclude(objectoptions,oo_is_forward);
  7247. end;
  7248. end;
  7249. function tobjectdef.find_destructor: tprocdef;
  7250. var
  7251. objdef: tobjectdef;
  7252. begin
  7253. objdef:=self;
  7254. while assigned(objdef) do
  7255. begin
  7256. result:=objdef.find_procdef_bytype(potype_destructor);
  7257. if assigned(result) then
  7258. exit;
  7259. objdef:=objdef.childof;
  7260. end;
  7261. result:=nil;
  7262. end;
  7263. function tobjectdef.implements_any_interfaces: boolean;
  7264. begin
  7265. result := (ImplementedInterfaces.Count > 0) or
  7266. (assigned(childof) and childof.implements_any_interfaces);
  7267. end;
  7268. function tobjectdef.register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface;
  7269. begin
  7270. { allocate the GUID only if the class implements at least one interface }
  7271. if useguid then
  7272. prepareguid;
  7273. result:=timplementedinterface.create(intfdef);
  7274. ImplementedInterfaces.Add(result);
  7275. end;
  7276. function tobjectdef.size : asizeint;
  7277. begin
  7278. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  7279. result:=voidpointertype.size
  7280. else
  7281. result:=tObjectSymtable(symtable).datasize;
  7282. end;
  7283. function tobjectdef.alignment:shortint;
  7284. begin
  7285. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  7286. alignment:=voidpointertype.alignment
  7287. else
  7288. alignment:=tObjectSymtable(symtable).recordalignment;
  7289. end;
  7290. function tobjectdef.vmtmethodoffset(index:longint):longint;
  7291. begin
  7292. { for offset of methods for classes, see rtl/inc/objpash.inc }
  7293. case objecttype of
  7294. odt_class:
  7295. { the +2*sizeof(pint) is size and -size }
  7296. vmtmethodoffset:=index*voidcodepointertype.size+10*voidpointertype.size+2*sizeof(pint);
  7297. odt_helper,
  7298. odt_objcclass,
  7299. odt_objcprotocol:
  7300. vmtmethodoffset:=0;
  7301. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  7302. vmtmethodoffset:=index*voidcodepointertype.size;
  7303. odt_javaclass,
  7304. odt_interfacejava:
  7305. { invalid }
  7306. vmtmethodoffset:=-1;
  7307. else
  7308. { the +2*sizeof(pint) is size and -size }
  7309. {$ifdef WITHDMT}
  7310. vmtmethodoffset:=index*voidcodepointertype.size+2*voidpointertype.size+2*sizeof(pint);
  7311. {$else WITHDMT}
  7312. vmtmethodoffset:=index*voidcodepointertype.size+1*voidpointertype.size+2*sizeof(pint);
  7313. {$endif WITHDMT}
  7314. end;
  7315. end;
  7316. function tobjectdef.vmt_mangledname : TSymStr;
  7317. begin
  7318. if not(oo_has_vmt in objectoptions) then
  7319. Message1(parser_n_object_has_no_vmt,objrealname^);
  7320. if not is_unique_objpasdef then
  7321. vmt_mangledname:=make_mangledname('VMT',owner,objname^)
  7322. else
  7323. vmt_mangledname:=childof.vmt_mangledname;
  7324. end;
  7325. function tobjectdef.vmt_def: trecorddef;
  7326. var
  7327. where: tsymtable;
  7328. vmttypesym: tsymentry;
  7329. begin
  7330. if not is_unique_objpasdef then
  7331. begin
  7332. vmttypesym:=symtable.Find('vmtdef');
  7333. if not assigned(vmttypesym) or
  7334. (vmttypesym.typ<>symconst.typesym) or
  7335. (ttypesym(vmttypesym).typedef.typ<>recorddef) then
  7336. internalerror(2015052501);
  7337. result:=trecorddef(ttypesym(vmttypesym).typedef);
  7338. end
  7339. else
  7340. result:=childof.vmt_def;
  7341. end;
  7342. function tobjectdef.needs_inittable : boolean;
  7343. var
  7344. hp : tobjectdef;
  7345. begin
  7346. case objecttype of
  7347. odt_helper,
  7348. odt_class :
  7349. needs_inittable:=false;
  7350. odt_dispinterface,
  7351. odt_interfacecom:
  7352. needs_inittable:=true;
  7353. odt_interfacecorba:
  7354. begin
  7355. hp:=childof;
  7356. while assigned(hp) do
  7357. begin
  7358. if hp=interface_iunknown then
  7359. begin
  7360. needs_inittable:=true;
  7361. exit;
  7362. end;
  7363. hp:=hp.childof;
  7364. end;
  7365. needs_inittable:=false;
  7366. end;
  7367. odt_object:
  7368. needs_inittable:=
  7369. tObjectSymtable(symtable).needs_init_final or
  7370. (assigned(childof) and
  7371. childof.needs_inittable);
  7372. odt_cppclass,
  7373. odt_objcclass,
  7374. odt_objcprotocol,
  7375. odt_javaclass,
  7376. odt_interfacejava:
  7377. needs_inittable:=false;
  7378. else
  7379. internalerror(200108267);
  7380. end;
  7381. end;
  7382. function tobjectdef.needs_separate_initrtti : boolean;
  7383. begin
  7384. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  7385. end;
  7386. function tobjectdef.has_non_trivial_init_child(check_parent:boolean):boolean;
  7387. begin
  7388. if objecttype in [odt_class,odt_object] then
  7389. begin
  7390. result:=tobjectsymtable(symtable).has_non_trivial_init or
  7391. (check_parent and assigned(childof) and childof.has_non_trivial_init_child(true));
  7392. end
  7393. else
  7394. result:=false;
  7395. end;
  7396. function tobjectdef.rtti_mangledname(rt: trttitype): TSymStr;
  7397. begin
  7398. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  7399. begin
  7400. if not is_unique_objpasdef then
  7401. result:=inherited rtti_mangledname(rt)
  7402. else
  7403. result:=childof.rtti_mangledname(rt)
  7404. end
  7405. else
  7406. begin
  7407. { necessary in case of a dynamic array of nsobject, or
  7408. if an nsobject field appears in a record that needs
  7409. init/finalisation }
  7410. if rt=initrtti then
  7411. begin
  7412. result:=voidpointertype.rtti_mangledname(rt);
  7413. exit;
  7414. end;
  7415. if not(target_info.system in systems_objc_nfabi) then
  7416. begin
  7417. result:=target_asm.labelprefix;
  7418. case objecttype of
  7419. odt_objcclass:
  7420. begin
  7421. case rt of
  7422. objcclassrtti:
  7423. if not(oo_is_classhelper in objectoptions) then
  7424. result:=result+'_OBJC_CLASS_'
  7425. else
  7426. result:=result+'_OBJC_CATEGORY_';
  7427. objcmetartti:
  7428. if not(oo_is_classhelper in objectoptions) then
  7429. result:=result+'_OBJC_METACLASS_'
  7430. else
  7431. internalerror(2009111511);
  7432. else
  7433. internalerror(2009092302);
  7434. end;
  7435. end;
  7436. odt_objcprotocol:
  7437. result:=result+'_OBJC_PROTOCOL_';
  7438. else
  7439. ;
  7440. end;
  7441. end
  7442. else
  7443. begin
  7444. case objecttype of
  7445. odt_objcclass:
  7446. begin
  7447. if (oo_is_classhelper in objectoptions) and
  7448. (rt<>objcclassrtti) then
  7449. internalerror(2009111512);
  7450. case rt of
  7451. objcclassrtti:
  7452. if not(oo_is_classhelper in objectoptions) then
  7453. result:='_OBJC_CLASS_$_'
  7454. else
  7455. result:='_OBJC_$_CATEGORY_';
  7456. objcmetartti:
  7457. result:='_OBJC_METACLASS_$_';
  7458. objcclassrortti:
  7459. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  7460. objcmetarortti:
  7461. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  7462. else
  7463. internalerror(2009092303);
  7464. end;
  7465. end;
  7466. odt_objcprotocol:
  7467. begin
  7468. result:=lower(target_asm.labelprefix);
  7469. case rt of
  7470. objcclassrtti:
  7471. result:=result+'_OBJC_PROTOCOL_$_';
  7472. objcmetartti:
  7473. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  7474. else
  7475. internalerror(2009092501);
  7476. end;
  7477. end;
  7478. else
  7479. internalerror(2013113005);
  7480. end;
  7481. end;
  7482. result:=result+objextname^;
  7483. end;
  7484. end;
  7485. function tobjectdef.is_unique_objpasdef: boolean;
  7486. begin
  7487. result:=
  7488. (df_unique in defoptions) and
  7489. is_class_or_interface_or_dispinterface(self)
  7490. end;
  7491. function tobjectdef.members_need_inittable : boolean;
  7492. begin
  7493. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  7494. end;
  7495. function tobjectdef.is_publishable : boolean;
  7496. begin
  7497. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  7498. end;
  7499. function tobjectdef.get_next_dispid: longint;
  7500. begin
  7501. inc(fcurrent_dispid);
  7502. result:=fcurrent_dispid;
  7503. end;
  7504. function tobjectdef.search_enumerator_get: tprocdef;
  7505. begin
  7506. result:=inherited;
  7507. if not assigned(result) and assigned(childof) then
  7508. result:=childof.search_enumerator_get;
  7509. end;
  7510. function tobjectdef.search_enumerator_move: tprocdef;
  7511. begin
  7512. result:=inherited;
  7513. if not assigned(result) and assigned(childof) then
  7514. result:=childof.search_enumerator_move;
  7515. end;
  7516. function tobjectdef.search_enumerator_current: tsym;
  7517. begin
  7518. result:=inherited;
  7519. if not assigned(result) and assigned(childof) then
  7520. result:=childof.search_enumerator_current;
  7521. end;
  7522. procedure tobjectdef.register_created_classref_type;
  7523. begin
  7524. if not classref_created_in_current_module then
  7525. begin
  7526. classref_created_in_current_module:=true;
  7527. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  7528. end;
  7529. end;
  7530. procedure tobjectdef.register_created_object_type;
  7531. begin
  7532. if not created_in_current_module then
  7533. begin
  7534. created_in_current_module:=true;
  7535. current_module.wpoinfo.addcreatedobjtype(self);
  7536. end;
  7537. end;
  7538. procedure tobjectdef.register_maybe_created_object_type;
  7539. begin
  7540. { if we know it has been created for sure, no need
  7541. to also record that it maybe can be created in
  7542. this module
  7543. }
  7544. if not (created_in_current_module) and
  7545. not (maybe_created_in_current_module) then
  7546. begin
  7547. maybe_created_in_current_module:=true;
  7548. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  7549. end;
  7550. end;
  7551. procedure tobjectdef.register_vmt_call(index: longint);
  7552. begin
  7553. if (is_object(self) or is_class(self)) then
  7554. current_module.wpoinfo.addcalledvmtentry(self,index);
  7555. end;
  7556. procedure check_and_finish_msg(data: tobject; arg: pointer);
  7557. var
  7558. def: tdef absolute data;
  7559. pd: tprocdef absolute data;
  7560. i,
  7561. paracount: longint;
  7562. begin
  7563. if (def.typ=procdef) then
  7564. begin
  7565. { add all messages also under a dummy name to the symtable in
  7566. which the objcclass/protocol/category is declared, so they can
  7567. be called via id.<name>
  7568. }
  7569. create_class_helper_for_procdef(pd,nil);
  7570. { we have to wait until now to set the mangled name because it
  7571. depends on the (possibly external) class name, which is defined
  7572. at the very end. }
  7573. if not(po_msgstr in pd.procoptions) then
  7574. begin
  7575. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  7576. { recover to avoid internalerror later on }
  7577. include(pd.procoptions,po_msgstr);
  7578. pd.messageinf.str:=stringdup('MissingDeclaration');
  7579. end;
  7580. { Mangled name is already set in case this is a copy of
  7581. another type. }
  7582. if not(po_has_mangledname in pd.procoptions) then
  7583. begin
  7584. { check whether the number of formal parameters is correct,
  7585. and whether they have valid Objective-C types }
  7586. paracount:=0;
  7587. for i:=1 to length(pd.messageinf.str^) do
  7588. if pd.messageinf.str^[i]=':' then
  7589. inc(paracount);
  7590. for i:=0 to pd.paras.count-1 do
  7591. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  7592. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  7593. dec(paracount);
  7594. if (paracount<>0) then
  7595. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  7596. pd.setmangledname(pd.objcmangledname);
  7597. end
  7598. else
  7599. { all checks already done }
  7600. exit;
  7601. if not(oo_is_external in pd.struct.objectoptions) then
  7602. begin
  7603. if (po_varargs in pd.procoptions) then
  7604. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  7605. else
  7606. begin
  7607. { check for "array of const" parameters }
  7608. for i:=0 to pd.parast.symlist.count-1 do
  7609. begin
  7610. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  7611. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  7612. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  7613. end;
  7614. end;
  7615. end;
  7616. end;
  7617. end;
  7618. procedure mark_private_fields_used(data: tobject; arg: pointer);
  7619. var
  7620. sym: tsym absolute data;
  7621. begin
  7622. if (sym.typ=fieldvarsym) and
  7623. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  7624. sym.IncRefCount;
  7625. end;
  7626. procedure tobjectdef.finish_objc_data;
  7627. begin
  7628. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  7629. if (oo_is_external in objectoptions) then
  7630. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  7631. end;
  7632. procedure verify_objc_vardef(data: tobject; arg: pointer);
  7633. var
  7634. sym: tabstractvarsym absolute data;
  7635. res: pboolean absolute arg;
  7636. founderrordef: tdef;
  7637. begin
  7638. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  7639. exit;
  7640. if (sym.typ=paravarsym) and
  7641. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  7642. is_array_of_const(tparavarsym(sym).vardef)) then
  7643. exit;
  7644. if not objcchecktype(sym.vardef,founderrordef) then
  7645. begin
  7646. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7647. res^:=false;
  7648. end;
  7649. end;
  7650. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  7651. var
  7652. def: tdef absolute data;
  7653. res: pboolean absolute arg;
  7654. founderrordef: tdef;
  7655. begin
  7656. if (def.typ<>procdef) then
  7657. exit;
  7658. { check parameter types for validity }
  7659. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  7660. { check the result type for validity }
  7661. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  7662. begin
  7663. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7664. res^:=false;
  7665. end;
  7666. end;
  7667. function tobjectdef.check_objc_types: boolean;
  7668. begin
  7669. { done in separate step from finish_objc_data, because when
  7670. finish_objc_data is called, not all forwarddefs have been resolved
  7671. yet and we need to know all types here }
  7672. result:=true;
  7673. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  7674. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  7675. end;
  7676. procedure do_cpp_import_info(data: tobject; arg: pointer);
  7677. var
  7678. def: tdef absolute data;
  7679. pd: tprocdef absolute data;
  7680. begin
  7681. if (def.typ=procdef) then
  7682. begin
  7683. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  7684. if (oo_is_external in pd.struct.objectoptions) then
  7685. begin
  7686. { copied from psub.read_proc }
  7687. if assigned(tobjectdef(pd.struct).import_lib) then
  7688. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  7689. else
  7690. begin
  7691. { add import name to external list for DLL scanning }
  7692. if tf_has_dllscanner in target_info.flags then
  7693. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  7694. end;
  7695. end;
  7696. end;
  7697. end;
  7698. procedure tobjectdef.finish_cpp_data;
  7699. begin
  7700. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  7701. end;
  7702. {$ifdef DEBUG_NODE_XML}
  7703. function TObjectDef.XMLPrintType: ansistring;
  7704. begin
  7705. if (oo_is_forward in objectoptions) then
  7706. Result := '&lt;class prototype&gt;'
  7707. else
  7708. Result := '&lt;class&gt;';
  7709. end;
  7710. procedure TObjectDef.XMLPrintDefInfo(var T: Text; Sym: TSym);
  7711. var
  7712. i: TObjectOption;
  7713. first: Boolean;
  7714. begin
  7715. inherited XMLPrintDefInfo(T, Sym);
  7716. First := True;
  7717. for i := Low(TObjectOption) to High(TObjectOption) do
  7718. if i in objectoptions then
  7719. begin
  7720. if First then
  7721. begin
  7722. Write(T, ' objectoptions="', i);
  7723. First := False;
  7724. end
  7725. else
  7726. Write(T, ',', i)
  7727. end;
  7728. if not first then
  7729. Write(T, '"');
  7730. end;
  7731. procedure TObjectDef.XMLPrintDefData(var T: Text; Sym: TSym);
  7732. begin
  7733. { There's nothing useful yet if the type is only forward-declared }
  7734. if not (oo_is_forward in objectoptions) then
  7735. begin
  7736. if Assigned(childof) then
  7737. WriteLn(T, printnodeindention, '<ancestor>', SanitiseXMLString(childof.typesym.RealName), '</ancestor>');
  7738. inherited XMLPrintDefData(T, Sym);
  7739. end;
  7740. end;
  7741. {$endif DEBUG_NODE_XML}
  7742. {****************************************************************************
  7743. TImplementedInterface
  7744. ****************************************************************************}
  7745. function TImplementedInterface.GetIOffset: longint;
  7746. begin
  7747. if (fIOffset=-1) and
  7748. (IType in [etFieldValue,etFieldValueClass]) then
  7749. result:=tfieldvarsym(ImplementsField).fieldoffset
  7750. else
  7751. result:=fIOffset;
  7752. end;
  7753. constructor TImplementedInterface.create(aintf: tobjectdef);
  7754. begin
  7755. inherited create;
  7756. intfdef:=aintf;
  7757. intfdefderef.reset;
  7758. IOffset:=-1;
  7759. IType:=etStandard;
  7760. NameMappings:=nil;
  7761. procdefs:=nil;
  7762. end;
  7763. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  7764. begin
  7765. inherited create;
  7766. intfdef:=nil;
  7767. intfdefderef:=intfd;
  7768. ImplementsGetterDeref:=getterd;
  7769. IOffset:=-1;
  7770. IType:=etStandard;
  7771. NameMappings:=nil;
  7772. procdefs:=nil;
  7773. end;
  7774. destructor TImplementedInterface.destroy;
  7775. var
  7776. i : longint;
  7777. mappedname : pshortstring;
  7778. begin
  7779. if assigned(NameMappings) then
  7780. begin
  7781. for i:=0 to NameMappings.Count-1 do
  7782. begin
  7783. mappedname:=pshortstring(NameMappings[i]);
  7784. stringdispose(mappedname);
  7785. end;
  7786. NameMappings.free;
  7787. NameMappings:=nil;
  7788. end;
  7789. if assigned(procdefs) then
  7790. begin
  7791. procdefs.free;
  7792. procdefs:=nil;
  7793. end;
  7794. inherited destroy;
  7795. end;
  7796. procedure TImplementedInterface.buildderef;
  7797. begin
  7798. intfdefderef.build(intfdef);
  7799. ImplementsGetterDeref.build(ImplementsGetter);
  7800. end;
  7801. procedure TImplementedInterface.deref;
  7802. begin
  7803. intfdef:=tobjectdef(intfdefderef.resolve);
  7804. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  7805. end;
  7806. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  7807. begin
  7808. if not assigned(NameMappings) then
  7809. NameMappings:=TFPHashList.Create;
  7810. NameMappings.Add(origname,stringdup(newname));
  7811. end;
  7812. function TImplementedInterface.GetMapping(const origname: string):string;
  7813. var
  7814. mappedname : pshortstring;
  7815. begin
  7816. result:='';
  7817. if not assigned(NameMappings) then
  7818. exit;
  7819. mappedname:=PShortstring(NameMappings.Find(origname));
  7820. if assigned(mappedname) then
  7821. result:=mappedname^;
  7822. end;
  7823. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  7824. begin
  7825. if not assigned(procdefs) then
  7826. procdefs:=TFPObjectList.Create(false);
  7827. { duplicate entries must be stored, because multiple }
  7828. { interfaces can declare methods with the same name }
  7829. { and all of these get their own VMT entry }
  7830. procdefs.Add(pd);
  7831. end;
  7832. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  7833. var
  7834. i : longint;
  7835. begin
  7836. result:=false;
  7837. { interfaces being implemented through delegation are not mergable (FK) }
  7838. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  7839. exit;
  7840. weight:=0;
  7841. { empty interface is mergeable }
  7842. if ProcDefs.Count=0 then
  7843. begin
  7844. result:=true;
  7845. exit;
  7846. end;
  7847. { The interface to merge must at least the number of
  7848. procedures of this interface }
  7849. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  7850. exit;
  7851. for i:=0 to ProcDefs.Count-1 do
  7852. begin
  7853. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  7854. exit;
  7855. end;
  7856. weight:=ProcDefs.Count;
  7857. result:=true;
  7858. end;
  7859. function TImplementedInterface.getcopy:TImplementedInterface;
  7860. begin
  7861. Result:=TImplementedInterface.Create(nil);
  7862. { 1) the procdefs list will be freed once for each copy
  7863. 2) since the procdefs list owns its elements, those will also be freed for each copy
  7864. 3) idem for the name mappings
  7865. }
  7866. { warning: this is completely wrong on so many levels...
  7867. Move(pointer(self)^,pointer(result)^,InstanceSize);
  7868. We need to make clean copies of the different fields
  7869. this is not implemented yet, and thus we generate an internal
  7870. error instead PM 2011-06-14 }
  7871. internalerror(2011061401);
  7872. end;
  7873. {****************************************************************************
  7874. TFORWARDDEF
  7875. ****************************************************************************}
  7876. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  7877. begin
  7878. inherited create(forwarddef,true);
  7879. tosymname:=stringdup(s);
  7880. forwardpos:=pos;
  7881. end;
  7882. function tforwarddef.GetTypeName:string;
  7883. begin
  7884. GetTypeName:='unresolved forward to '+tosymname^;
  7885. end;
  7886. destructor tforwarddef.destroy;
  7887. begin
  7888. stringdispose(tosymname);
  7889. inherited destroy;
  7890. end;
  7891. function tforwarddef.getcopy:tstoreddef;
  7892. begin
  7893. result:=cforwarddef.create(tosymname^, forwardpos);
  7894. end;
  7895. {****************************************************************************
  7896. TUNDEFINEDDEF
  7897. ****************************************************************************}
  7898. constructor tundefineddef.create(doregister:boolean);
  7899. begin
  7900. inherited create(undefineddef,doregister);
  7901. end;
  7902. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  7903. begin
  7904. inherited ppuload(undefineddef,ppufile);
  7905. ppuload_platform(ppufile);
  7906. end;
  7907. function tundefineddef.GetTypeName:string;
  7908. begin
  7909. GetTypeName:='<undefined type>';
  7910. end;
  7911. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  7912. begin
  7913. inherited ppuwrite(ppufile);
  7914. writeentry(ppufile,ibundefineddef);
  7915. end;
  7916. {****************************************************************************
  7917. TERRORDEF
  7918. ****************************************************************************}
  7919. constructor terrordef.create;
  7920. begin
  7921. inherited create(errordef,true);
  7922. { prevent consecutive faults }
  7923. savesize:=1;
  7924. end;
  7925. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  7926. begin
  7927. { Can't write errordefs to ppu }
  7928. internalerror(200411063);
  7929. end;
  7930. function terrordef.GetTypeName:string;
  7931. begin
  7932. GetTypeName:='<erroneous type>';
  7933. end;
  7934. function terrordef.getmangledparaname:TSymStr;
  7935. begin
  7936. getmangledparaname:='error';
  7937. end;
  7938. {****************************************************************************
  7939. Definition Helpers
  7940. ****************************************************************************}
  7941. function is_interfacecom(def: tdef): boolean;
  7942. begin
  7943. is_interfacecom:=
  7944. assigned(def) and
  7945. (def.typ=objectdef) and
  7946. (tobjectdef(def).objecttype=odt_interfacecom);
  7947. end;
  7948. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  7949. begin
  7950. is_interfacecom_or_dispinterface:=
  7951. assigned(def) and
  7952. (def.typ=objectdef) and
  7953. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  7954. end;
  7955. function is_any_interface_kind(def: tdef): boolean;
  7956. begin
  7957. result:=
  7958. assigned(def) and
  7959. (def.typ=objectdef) and
  7960. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  7961. is_objccategory(def));
  7962. end;
  7963. function is_interfacecorba(def: tdef): boolean;
  7964. begin
  7965. is_interfacecorba:=
  7966. assigned(def) and
  7967. (def.typ=objectdef) and
  7968. (tobjectdef(def).objecttype=odt_interfacecorba);
  7969. end;
  7970. function is_interface(def: tdef): boolean;
  7971. begin
  7972. is_interface:=
  7973. assigned(def) and
  7974. (def.typ=objectdef) and
  7975. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  7976. end;
  7977. function is_dispinterface(def: tdef): boolean;
  7978. begin
  7979. result:=
  7980. assigned(def) and
  7981. (def.typ=objectdef) and
  7982. (tobjectdef(def).objecttype=odt_dispinterface);
  7983. end;
  7984. function is_class(def: tdef): boolean;
  7985. begin
  7986. is_class:=
  7987. assigned(def) and
  7988. (def.typ=objectdef) and
  7989. (tobjectdef(def).objecttype=odt_class);
  7990. end;
  7991. function is_object(def: tdef): boolean;
  7992. begin
  7993. is_object:=
  7994. assigned(def) and
  7995. (def.typ=objectdef) and
  7996. (tobjectdef(def).objecttype=odt_object);
  7997. end;
  7998. function is_cppclass(def: tdef): boolean;
  7999. begin
  8000. is_cppclass:=
  8001. assigned(def) and
  8002. (def.typ=objectdef) and
  8003. (tobjectdef(def).objecttype=odt_cppclass);
  8004. end;
  8005. function is_objcclass(def: tdef): boolean;
  8006. begin
  8007. is_objcclass:=
  8008. assigned(def) and
  8009. (def.typ=objectdef) and
  8010. (tobjectdef(def).objecttype=odt_objcclass);
  8011. end;
  8012. function is_objectpascal_helper(def: tdef): boolean;
  8013. begin
  8014. result:=
  8015. assigned(def) and
  8016. (def.typ=objectdef) and
  8017. (tobjectdef(def).objecttype=odt_helper);
  8018. end;
  8019. function is_objcclassref(def: tdef): boolean;
  8020. begin
  8021. is_objcclassref:=
  8022. assigned(def) and
  8023. (def.typ=classrefdef) and
  8024. is_objcclass(tclassrefdef(def).pointeddef);
  8025. end;
  8026. function is_objcprotocol(def: tdef): boolean;
  8027. begin
  8028. result:=
  8029. assigned(def) and
  8030. (def.typ=objectdef) and
  8031. (tobjectdef(def).objecttype=odt_objcprotocol);
  8032. end;
  8033. function is_objccategory(def: tdef): boolean;
  8034. begin
  8035. result:=
  8036. assigned(def) and
  8037. (def.typ=objectdef) and
  8038. { if used as a forward type }
  8039. ((tobjectdef(def).objecttype=odt_objccategory) or
  8040. { if used as after it has been resolved }
  8041. ((tobjectdef(def).objecttype=odt_objcclass) and
  8042. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  8043. end;
  8044. function is_objc_class_or_protocol(def: tdef): boolean;
  8045. begin
  8046. result:=
  8047. assigned(def) and
  8048. (def.typ=objectdef) and
  8049. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  8050. end;
  8051. function is_objc_protocol_or_category(def: tdef): boolean;
  8052. begin
  8053. result:=
  8054. assigned(def) and
  8055. (def.typ=objectdef) and
  8056. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  8057. ((tobjectdef(def).objecttype = odt_objcclass) and
  8058. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  8059. end;
  8060. function is_classhelper(def: tdef): boolean;
  8061. begin
  8062. result:=
  8063. is_objectpascal_helper(def) or
  8064. is_objccategory(def);
  8065. end;
  8066. function is_class_or_interface(def: tdef): boolean;
  8067. begin
  8068. result:=
  8069. assigned(def) and
  8070. (def.typ=objectdef) and
  8071. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  8072. end;
  8073. function is_class_or_interface_or_objc(def: tdef): boolean;
  8074. begin
  8075. result:=
  8076. assigned(def) and
  8077. (def.typ=objectdef) and
  8078. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  8079. end;
  8080. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  8081. begin
  8082. result:=
  8083. assigned(def) and
  8084. (def.typ=objectdef) and
  8085. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  8086. end;
  8087. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  8088. begin
  8089. result:=
  8090. assigned(def) and
  8091. (def.typ=objectdef) and
  8092. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  8093. end;
  8094. function is_class_or_interface_or_object(def: tdef): boolean;
  8095. begin
  8096. result:=
  8097. assigned(def) and
  8098. (def.typ=objectdef) and
  8099. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  8100. end;
  8101. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  8102. begin
  8103. result:=
  8104. assigned(def) and
  8105. (def.typ=objectdef) and
  8106. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  8107. end;
  8108. function is_implicit_pointer_object_type(def: tdef): boolean;
  8109. begin
  8110. result:=
  8111. assigned(def) and
  8112. (((def.typ=objectdef) and
  8113. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  8114. ((target_info.system in systems_jvm) and
  8115. (def.typ=recorddef)));
  8116. end;
  8117. function is_implicit_array_pointer(def: tdef): boolean;
  8118. begin
  8119. result:=is_dynamic_array(def) or is_dynamicstring(def);
  8120. end;
  8121. function is_class_or_object(def: tdef): boolean;
  8122. begin
  8123. result:=
  8124. assigned(def) and
  8125. (def.typ=objectdef) and
  8126. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  8127. end;
  8128. function is_record(def: tdef): boolean;
  8129. begin
  8130. result:=
  8131. assigned(def) and
  8132. (def.typ=recorddef);
  8133. end;
  8134. function is_javaclass(def: tdef): boolean;
  8135. begin
  8136. result:=
  8137. assigned(def) and
  8138. (def.typ=objectdef) and
  8139. (tobjectdef(def).objecttype=odt_javaclass);
  8140. end;
  8141. function is_javaclassref(def: tdef): boolean;
  8142. begin
  8143. is_javaclassref:=
  8144. assigned(def) and
  8145. (def.typ=classrefdef) and
  8146. is_javaclass(tclassrefdef(def).pointeddef);
  8147. end;
  8148. function is_javainterface(def: tdef): boolean;
  8149. begin
  8150. result:=
  8151. assigned(def) and
  8152. (def.typ=objectdef) and
  8153. (tobjectdef(def).objecttype=odt_interfacejava);
  8154. end;
  8155. function is_java_class_or_interface(def: tdef): boolean;
  8156. begin
  8157. result:=
  8158. assigned(def) and
  8159. (def.typ=objectdef) and
  8160. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  8161. end;
  8162. procedure loadobjctypes;
  8163. begin
  8164. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  8165. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  8166. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  8167. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  8168. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  8169. end;
  8170. procedure maybeloadcocoatypes;
  8171. var
  8172. tsym: ttypesym;
  8173. cocoaunit: string[15];
  8174. begin
  8175. if assigned(objc_fastenumeration) then
  8176. exit;
  8177. if not(target_info.system in [system_arm_ios,system_i386_iphonesim,system_aarch64_ios,system_x86_64_iphonesim]) then
  8178. cocoaunit:='COCOAALL'
  8179. else
  8180. cocoaunit:='IPHONEALL';
  8181. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  8182. if assigned(tsym) then
  8183. objc_fastenumeration:=tobjectdef(tsym.typedef)
  8184. else
  8185. objc_fastenumeration:=nil;
  8186. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  8187. if assigned(tsym) then
  8188. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  8189. else
  8190. objc_fastenumerationstate:=nil;
  8191. end;
  8192. function use_vectorfpu(def : tdef) : boolean;
  8193. begin
  8194. {$ifdef x86}
  8195. {$define use_vectorfpuimplemented}
  8196. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  8197. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  8198. {$endif x86}
  8199. {$ifdef arm}
  8200. {$define use_vectorfpuimplemented}
  8201. use_vectorfpu:=FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[current_settings.fputype];
  8202. {$endif arm}
  8203. {$ifdef aarch64}
  8204. {$define use_vectorfpuimplemented}
  8205. use_vectorfpu:=true;
  8206. {$endif aarch64}
  8207. {$ifndef use_vectorfpuimplemented}
  8208. use_vectorfpu:=false;
  8209. {$endif}
  8210. end;
  8211. end.