symdef.pas 330 KB

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