symdef.pas 193 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symdef;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,globals,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,
  28. { ppu }
  29. ppu,
  30. { node }
  31. node,
  32. { aasm }
  33. aasmbase,aasmtai,
  34. cpubase,cpuinfo,
  35. cgbase,parabase
  36. ;
  37. type
  38. {************************************************
  39. TDef
  40. ************************************************}
  41. tstoreddef = class(tdef)
  42. protected
  43. typesymderef : tderef;
  44. public
  45. { persistent (available across units) rtti and init tables }
  46. rttitablesym,
  47. inittablesym : tsym; {trttisym}
  48. rttitablesymderef,
  49. inittablesymderef : tderef;
  50. { local (per module) rtti and init tables }
  51. localrttilab : array[trttitype] of tasmlabel;
  52. { linked list of global definitions }
  53. {$ifdef EXTDEBUG}
  54. fileinfo : tfileposinfo;
  55. {$endif}
  56. {$ifdef GDB}
  57. globalnb : word;
  58. stab_state : tdefstabstatus;
  59. {$endif GDB}
  60. constructor create;
  61. constructor ppuloaddef(ppufile:tcompilerppufile);
  62. procedure reset;
  63. function getcopy : tstoreddef;virtual;
  64. procedure ppuwritedef(ppufile:tcompilerppufile);
  65. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  66. procedure buildderef;override;
  67. procedure buildderefimpl;override;
  68. procedure deref;override;
  69. procedure derefimpl;override;
  70. function size:aint;override;
  71. function alignment:longint;override;
  72. function is_publishable : boolean;override;
  73. function needs_inittable : boolean;override;
  74. { debug }
  75. {$ifdef GDB}
  76. function get_var_value(const s:string):string;
  77. function stabstr_evaluate(const s:string;const vars:array of string):Pchar;
  78. function stabstring : pchar;virtual;
  79. procedure concatstabto(asmlist : taasmoutput);virtual;
  80. function numberstring:string;virtual;
  81. procedure set_globalnb;virtual;
  82. function allstabstring : pchar;virtual;
  83. {$endif GDB}
  84. { rtti generation }
  85. procedure write_rtti_name;
  86. procedure write_rtti_data(rt:trttitype);virtual;
  87. procedure write_child_rtti_data(rt:trttitype);virtual;
  88. function get_rtti_label(rt:trttitype):tasmsymbol;
  89. { regvars }
  90. function is_intregable : boolean;
  91. function is_fpuregable : boolean;
  92. private
  93. savesize : aint;
  94. end;
  95. tparaitem = class(TLinkedListItem)
  96. paratype : ttype; { required for procvar }
  97. parasym : tsym;
  98. parasymderef : tderef;
  99. defaultvalue : tsym; { tconstsym }
  100. defaultvaluederef : tderef;
  101. paratyp : tvarspez; { required for procvar }
  102. paraloc : array[tcallercallee] of TCGPara;
  103. is_hidden : boolean; { is this a hidden (implicit) parameter }
  104. {$ifdef EXTDEBUG}
  105. eqval : tequaltype;
  106. {$endif EXTDEBUG}
  107. constructor create;
  108. destructor destroy;override;
  109. end;
  110. tfiletyp = (ft_text,ft_typed,ft_untyped);
  111. tfiledef = class(tstoreddef)
  112. filetyp : tfiletyp;
  113. typedfiletype : ttype;
  114. constructor createtext;
  115. constructor createuntyped;
  116. constructor createtyped(const tt : ttype);
  117. constructor ppuload(ppufile:tcompilerppufile);
  118. procedure ppuwrite(ppufile:tcompilerppufile);override;
  119. procedure buildderef;override;
  120. procedure deref;override;
  121. function gettypename:string;override;
  122. function getmangledparaname:string;override;
  123. procedure setsize;
  124. { debug }
  125. {$ifdef GDB}
  126. function stabstring : pchar;override;
  127. procedure concatstabto(asmlist : taasmoutput);override;
  128. {$endif GDB}
  129. end;
  130. tvariantdef = class(tstoreddef)
  131. varianttype : tvarianttype;
  132. constructor create(v : tvarianttype);
  133. constructor ppuload(ppufile:tcompilerppufile);
  134. function gettypename:string;override;
  135. procedure ppuwrite(ppufile:tcompilerppufile);override;
  136. procedure setsize;
  137. function needs_inittable : boolean;override;
  138. procedure write_rtti_data(rt:trttitype);override;
  139. {$ifdef GDB}
  140. function numberstring:string;override;
  141. function stabstring : pchar;override;
  142. procedure concatstabto(asmlist : taasmoutput);override;
  143. {$endif GDB}
  144. end;
  145. tformaldef = class(tstoreddef)
  146. constructor create;
  147. constructor ppuload(ppufile:tcompilerppufile);
  148. procedure ppuwrite(ppufile:tcompilerppufile);override;
  149. function gettypename:string;override;
  150. {$ifdef GDB}
  151. function numberstring:string;override;
  152. function stabstring : pchar;override;
  153. procedure concatstabto(asmlist : taasmoutput);override;
  154. {$endif GDB}
  155. end;
  156. tforwarddef = class(tstoreddef)
  157. tosymname : pstring;
  158. forwardpos : tfileposinfo;
  159. constructor create(const s:string;const pos : tfileposinfo);
  160. destructor destroy;override;
  161. function gettypename:string;override;
  162. end;
  163. terrordef = class(tstoreddef)
  164. constructor create;
  165. function gettypename:string;override;
  166. function getmangledparaname : string;override;
  167. { debug }
  168. {$ifdef GDB}
  169. function stabstring : pchar;override;
  170. procedure concatstabto(asmlist : taasmoutput);override;
  171. {$endif GDB}
  172. end;
  173. { tpointerdef and tclassrefdef should get a common
  174. base class, but I derived tclassrefdef from tpointerdef
  175. to avoid problems with bugs (FK)
  176. }
  177. tpointerdef = class(tstoreddef)
  178. pointertype : ttype;
  179. is_far : boolean;
  180. constructor create(const tt : ttype);
  181. constructor createfar(const tt : ttype);
  182. function getcopy : tstoreddef;override;
  183. constructor ppuload(ppufile:tcompilerppufile);
  184. procedure ppuwrite(ppufile:tcompilerppufile);override;
  185. procedure buildderef;override;
  186. procedure deref;override;
  187. function gettypename:string;override;
  188. { debug }
  189. {$ifdef GDB}
  190. function stabstring : pchar;override;
  191. procedure concatstabto(asmlist : taasmoutput);override;
  192. {$endif GDB}
  193. end;
  194. Trecord_stabgen_state=record
  195. stabstring:Pchar;
  196. stabsize,staballoc,recoffset:integer;
  197. end;
  198. tabstractrecorddef= class(tstoreddef)
  199. private
  200. Count : integer;
  201. FRTTIType : trttitype;
  202. {$ifdef GDB}
  203. procedure field_addname(p:Tnamedindexitem;arg:pointer);
  204. procedure field_concatstabto(p:Tnamedindexitem;arg:pointer);
  205. {$endif}
  206. procedure count_field_rtti(sym : tnamedindexitem;arg:pointer);
  207. procedure write_field_rtti(sym : tnamedindexitem;arg:pointer);
  208. procedure generate_field_rtti(sym : tnamedindexitem;arg:pointer);
  209. public
  210. symtable : tsymtable;
  211. function getsymtable(t:tgetsymtable):tsymtable;override;
  212. end;
  213. trecorddef = class(tabstractrecorddef)
  214. public
  215. isunion : boolean;
  216. constructor create(p : tsymtable);
  217. constructor ppuload(ppufile:tcompilerppufile);
  218. destructor destroy;override;
  219. procedure ppuwrite(ppufile:tcompilerppufile);override;
  220. procedure buildderef;override;
  221. procedure deref;override;
  222. function size:aint;override;
  223. function alignment : longint;override;
  224. function padalignment: longint;
  225. function gettypename:string;override;
  226. { debug }
  227. {$ifdef GDB}
  228. function stabstring : pchar;override;
  229. procedure concatstabto(asmlist:taasmoutput);override;
  230. {$endif GDB}
  231. function needs_inittable : boolean;override;
  232. { rtti }
  233. procedure write_child_rtti_data(rt:trttitype);override;
  234. procedure write_rtti_data(rt:trttitype);override;
  235. end;
  236. tprocdef = class;
  237. timplementedinterfaces = class;
  238. tobjectdef = class(tabstractrecorddef)
  239. private
  240. {$ifdef GDB}
  241. procedure proc_addname(p :tnamedindexitem;arg:pointer);
  242. procedure proc_concatstabto(p :tnamedindexitem;arg:pointer);
  243. {$endif GDB}
  244. procedure count_published_properties(sym:tnamedindexitem;arg:pointer);
  245. procedure write_property_info(sym : tnamedindexitem;arg:pointer);
  246. procedure generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  247. procedure count_published_fields(sym:tnamedindexitem;arg:pointer);
  248. procedure writefields(sym:tnamedindexitem;arg:pointer);
  249. public
  250. childof : tobjectdef;
  251. childofderef : tderef;
  252. objname,
  253. objrealname : pstring;
  254. objectoptions : tobjectoptions;
  255. { to be able to have a variable vmt position }
  256. { and no vmt field for objects without virtuals }
  257. vmt_offset : longint;
  258. {$ifdef GDB}
  259. writing_class_record_stab : boolean;
  260. {$endif GDB}
  261. objecttype : tobjectdeftype;
  262. iidguid: pguid;
  263. iidstr: pstring;
  264. lastvtableindex: longint;
  265. { store implemented interfaces defs and name mappings }
  266. implementedinterfaces: timplementedinterfaces;
  267. constructor create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  268. constructor ppuload(ppufile:tcompilerppufile);
  269. destructor destroy;override;
  270. procedure ppuwrite(ppufile:tcompilerppufile);override;
  271. function gettypename:string;override;
  272. procedure buildderef;override;
  273. procedure deref;override;
  274. function getparentdef:tdef;override;
  275. function size : aint;override;
  276. function alignment:longint;override;
  277. function vmtmethodoffset(index:longint):longint;
  278. function members_need_inittable : boolean;
  279. { this should be called when this class implements an interface }
  280. procedure prepareguid;
  281. function is_publishable : boolean;override;
  282. function needs_inittable : boolean;override;
  283. function vmt_mangledname : string;
  284. function rtti_name : string;
  285. procedure check_forwards;
  286. function is_related(d : tobjectdef) : boolean;
  287. function next_free_name_index : longint;
  288. procedure insertvmt;
  289. procedure set_parent(c : tobjectdef);
  290. function searchdestructor : tprocdef;
  291. { debug }
  292. {$ifdef GDB}
  293. function stabstring : pchar;override;
  294. procedure set_globalnb;override;
  295. function classnumberstring : string;
  296. procedure concatstabto(asmlist : taasmoutput);override;
  297. function allstabstring : pchar;override;
  298. {$endif GDB}
  299. { rtti }
  300. procedure write_child_rtti_data(rt:trttitype);override;
  301. procedure write_rtti_data(rt:trttitype);override;
  302. function generate_field_table : tasmlabel;
  303. end;
  304. timplementedinterfaces = class
  305. constructor create;
  306. destructor destroy; override;
  307. function count: longint;
  308. function interfaces(intfindex: longint): tobjectdef;
  309. function interfacesderef(intfindex: longint): tderef;
  310. function ioffsets(intfindex: longint): plongint;
  311. function searchintf(def: tdef): longint;
  312. procedure addintf(def: tdef);
  313. procedure buildderef;
  314. procedure deref;
  315. { add interface reference loaded from ppu }
  316. procedure addintf_deref(const d:tderef);
  317. procedure clearmappings;
  318. procedure addmappings(intfindex: longint; const name, newname: string);
  319. function getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  320. procedure clearimplprocs;
  321. procedure addimplproc(intfindex: longint; procdef: tprocdef);
  322. function implproccount(intfindex: longint): longint;
  323. function implprocs(intfindex: longint; procindex: longint): tprocdef;
  324. function isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  325. private
  326. finterfaces: tindexarray;
  327. procedure checkindex(intfindex: longint);
  328. end;
  329. tclassrefdef = class(tpointerdef)
  330. constructor create(const t:ttype);
  331. constructor ppuload(ppufile:tcompilerppufile);
  332. procedure ppuwrite(ppufile:tcompilerppufile);override;
  333. function gettypename:string;override;
  334. { debug }
  335. {$ifdef GDB}
  336. function stabstring : pchar;override;
  337. {$endif GDB}
  338. end;
  339. tarraydef = class(tstoreddef)
  340. lowrange,
  341. highrange : aint;
  342. rangetype : ttype;
  343. IsConvertedPointer,
  344. IsDynamicArray,
  345. IsVariant,
  346. IsConstructor,
  347. IsArrayOfConst : boolean;
  348. protected
  349. _elementtype : ttype;
  350. public
  351. function elesize : aint;
  352. function elecount : aint;
  353. constructor create_from_pointer(const elemt : ttype);
  354. constructor create(l,h : aint;const t : ttype);
  355. constructor ppuload(ppufile:tcompilerppufile);
  356. procedure ppuwrite(ppufile:tcompilerppufile);override;
  357. function gettypename:string;override;
  358. function getmangledparaname : string;override;
  359. procedure setelementtype(t: ttype);
  360. {$ifdef GDB}
  361. function stabstring : pchar;override;
  362. procedure concatstabto(asmlist : taasmoutput);override;
  363. {$endif GDB}
  364. procedure buildderef;override;
  365. procedure deref;override;
  366. function size : aint;override;
  367. function alignment : longint;override;
  368. { returns the label of the range check string }
  369. function needs_inittable : boolean;override;
  370. procedure write_child_rtti_data(rt:trttitype);override;
  371. procedure write_rtti_data(rt:trttitype);override;
  372. property elementtype : ttype Read _ElementType;
  373. end;
  374. torddef = class(tstoreddef)
  375. low,high : TConstExprInt;
  376. typ : tbasetype;
  377. constructor create(t : tbasetype;v,b : TConstExprInt);
  378. constructor ppuload(ppufile:tcompilerppufile);
  379. function getcopy : tstoreddef;override;
  380. procedure ppuwrite(ppufile:tcompilerppufile);override;
  381. function is_publishable : boolean;override;
  382. function gettypename:string;override;
  383. procedure setsize;
  384. { debug }
  385. {$ifdef GDB}
  386. function stabstring : pchar;override;
  387. {$endif GDB}
  388. { rtti }
  389. procedure write_rtti_data(rt:trttitype);override;
  390. end;
  391. tfloatdef = class(tstoreddef)
  392. typ : tfloattype;
  393. constructor create(t : tfloattype);
  394. constructor ppuload(ppufile:tcompilerppufile);
  395. function getcopy : tstoreddef;override;
  396. procedure ppuwrite(ppufile:tcompilerppufile);override;
  397. function gettypename:string;override;
  398. function is_publishable : boolean;override;
  399. procedure setsize;
  400. { debug }
  401. {$ifdef GDB}
  402. function stabstring : pchar;override;
  403. procedure concatstabto(asmlist:taasmoutput);override;
  404. {$endif GDB}
  405. { rtti }
  406. procedure write_rtti_data(rt:trttitype);override;
  407. end;
  408. tabstractprocdef = class(tstoreddef)
  409. { saves a definition to the return type }
  410. rettype : ttype;
  411. parast : tsymtable;
  412. para : tlinkedlist;
  413. proctypeoption : tproctypeoption;
  414. proccalloption : tproccalloption;
  415. procoptions : tprocoptions;
  416. requiredargarea : aint;
  417. maxparacount,
  418. minparacount : byte;
  419. {$ifdef i386}
  420. fpu_used : byte; { how many stack fpu must be empty }
  421. {$endif i386}
  422. funcret_paraloc : array[tcallercallee] of TCGPara;
  423. has_paraloc_info : boolean; { paraloc info is available }
  424. constructor create(level:byte);
  425. constructor ppuload(ppufile:tcompilerppufile);
  426. destructor destroy;override;
  427. procedure ppuwrite(ppufile:tcompilerppufile);override;
  428. procedure buildderef;override;
  429. procedure deref;override;
  430. procedure releasemem;
  431. function concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  432. function insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  433. procedure removepara(currpara:tparaitem);
  434. function typename_paras(showhidden:boolean): string;
  435. procedure test_if_fpu_result;
  436. function is_methodpointer:boolean;virtual;
  437. function is_addressonly:boolean;virtual;
  438. { debug }
  439. {$ifdef GDB}
  440. function stabstring : pchar;override;
  441. {$endif GDB}
  442. end;
  443. tprocvardef = class(tabstractprocdef)
  444. constructor create(level:byte);
  445. constructor ppuload(ppufile:tcompilerppufile);
  446. procedure ppuwrite(ppufile:tcompilerppufile);override;
  447. procedure buildderef;override;
  448. procedure deref;override;
  449. function getsymtable(t:tgetsymtable):tsymtable;override;
  450. function size : aint;override;
  451. function gettypename:string;override;
  452. function is_publishable : boolean;override;
  453. function is_methodpointer:boolean;override;
  454. function is_addressonly:boolean;override;
  455. { debug }
  456. {$ifdef GDB}
  457. function stabstring : pchar;override;
  458. procedure concatstabto(asmlist:taasmoutput);override;
  459. {$endif GDB}
  460. { rtti }
  461. procedure write_rtti_data(rt:trttitype);override;
  462. end;
  463. tmessageinf = record
  464. case integer of
  465. 0 : (str : pchar);
  466. 1 : (i : longint);
  467. end;
  468. tinlininginfo = record
  469. { node tree }
  470. code : tnode;
  471. flags : tprocinfoflags;
  472. inlinenode : boolean;
  473. end;
  474. pinlininginfo = ^tinlininginfo;
  475. {$ifdef oldregvars}
  476. { register variables }
  477. pregvarinfo = ^tregvarinfo;
  478. tregvarinfo = record
  479. regvars : array[1..maxvarregs] of tsym;
  480. regvars_para : array[1..maxvarregs] of boolean;
  481. regvars_refs : array[1..maxvarregs] of longint;
  482. fpuregvars : array[1..maxfpuvarregs] of tsym;
  483. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  484. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  485. end;
  486. {$endif oldregvars}
  487. tprocdef = class(tabstractprocdef)
  488. private
  489. _mangledname : pstring;
  490. {$ifdef GDB}
  491. isstabwritten : boolean;
  492. {$endif GDB}
  493. public
  494. extnumber : word;
  495. overloadnumber : word;
  496. messageinf : tmessageinf;
  497. {$ifndef EXTDEBUG}
  498. { where is this function defined and what were the symbol
  499. flags, needed here because there
  500. is only one symbol for all overloaded functions
  501. EXTDEBUG has fileinfo in tdef (PFV) }
  502. fileinfo : tfileposinfo;
  503. {$endif}
  504. symoptions : tsymoptions;
  505. { symbol owning this definition }
  506. procsym : tsym;
  507. procsymderef : tderef;
  508. { alias names }
  509. aliasnames : tstringlist;
  510. { symtables }
  511. localst : tsymtable;
  512. funcretsym : tsym;
  513. funcretsymderef : tderef;
  514. { browser info }
  515. lastref,
  516. defref,
  517. lastwritten : tref;
  518. refcount : longint;
  519. _class : tobjectdef;
  520. _classderef : tderef;
  521. {$ifdef powerpc}
  522. { library symbol for AmigaOS/MorphOS }
  523. libsym : tsym;
  524. libsymderef : tderef;
  525. {$endif powerpc}
  526. { name of the result variable to insert in the localsymtable }
  527. resultname : stringid;
  528. { true, if the procedure is only declared
  529. (forward procedure) }
  530. forwarddef,
  531. { true if the procedure is declared in the interface }
  532. interfacedef : boolean;
  533. { true if the procedure has a forward declaration }
  534. hasforward : boolean;
  535. { check the problems of manglednames }
  536. has_mangledname : boolean;
  537. { info for inlining the subroutine, if this pointer is nil,
  538. the procedure can't be inlined }
  539. inlininginfo : pinlininginfo;
  540. {$ifdef oldregvars}
  541. regvarinfo: pregvarinfo;
  542. {$endif oldregvars}
  543. constructor create(level:byte);
  544. constructor ppuload(ppufile:tcompilerppufile);
  545. destructor destroy;override;
  546. procedure ppuwrite(ppufile:tcompilerppufile);override;
  547. procedure buildderef;override;
  548. procedure buildderefimpl;override;
  549. procedure deref;override;
  550. procedure derefimpl;override;
  551. function getsymtable(t:tgetsymtable):tsymtable;override;
  552. function gettypename : string;override;
  553. function mangledname : string;
  554. procedure setmangledname(const s : string);
  555. procedure load_references(ppufile:tcompilerppufile;locals:boolean);
  556. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  557. { inserts the local symbol table, if this is not
  558. no local symbol table is built. Should be called only
  559. when we are sure that a local symbol table will be required.
  560. }
  561. procedure insert_localst;
  562. function fullprocname(showhidden:boolean):string;
  563. function cplusplusmangledname : string;
  564. function is_methodpointer:boolean;override;
  565. function is_addressonly:boolean;override;
  566. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  567. { debug }
  568. {$ifdef GDB}
  569. function numberstring:string;override;
  570. function stabstring : pchar;override;
  571. procedure concatstabto(asmlist : taasmoutput);override;
  572. {$endif GDB}
  573. end;
  574. { single linked list of overloaded procs }
  575. pprocdeflist = ^tprocdeflist;
  576. tprocdeflist = record
  577. def : tprocdef;
  578. defderef : tderef;
  579. own : boolean;
  580. next : pprocdeflist;
  581. end;
  582. tstringdef = class(tstoreddef)
  583. string_typ : tstringtype;
  584. len : aint;
  585. constructor createshort(l : byte);
  586. constructor loadshort(ppufile:tcompilerppufile);
  587. constructor createlong(l : aint);
  588. constructor loadlong(ppufile:tcompilerppufile);
  589. {$ifdef ansistring_bits}
  590. constructor createansi(l:aint;bits:Tstringbits);
  591. constructor loadansi(ppufile:tcompilerppufile;bits:Tstringbits);
  592. {$else}
  593. constructor createansi(l : aint);
  594. constructor loadansi(ppufile:tcompilerppufile);
  595. {$endif}
  596. constructor createwide(l : aint);
  597. constructor loadwide(ppufile:tcompilerppufile);
  598. function getcopy : tstoreddef;override;
  599. function stringtypname:string;
  600. procedure ppuwrite(ppufile:tcompilerppufile);override;
  601. function gettypename:string;override;
  602. function getmangledparaname:string;override;
  603. function is_publishable : boolean;override;
  604. { debug }
  605. {$ifdef GDB}
  606. function stabstring : pchar;override;
  607. procedure concatstabto(asmlist : taasmoutput);override;
  608. {$endif GDB}
  609. { init/final }
  610. function needs_inittable : boolean;override;
  611. { rtti }
  612. procedure write_rtti_data(rt:trttitype);override;
  613. end;
  614. tenumdef = class(tstoreddef)
  615. minval,
  616. maxval : aint;
  617. has_jumps : boolean;
  618. firstenum : tsym; {tenumsym}
  619. basedef : tenumdef;
  620. basedefderef : tderef;
  621. constructor create;
  622. constructor create_subrange(_basedef:tenumdef;_min,_max:aint);
  623. constructor ppuload(ppufile:tcompilerppufile);
  624. destructor destroy;override;
  625. procedure ppuwrite(ppufile:tcompilerppufile);override;
  626. procedure buildderef;override;
  627. procedure deref;override;
  628. function gettypename:string;override;
  629. function is_publishable : boolean;override;
  630. procedure calcsavesize;
  631. procedure setmax(_max:aint);
  632. procedure setmin(_min:aint);
  633. function min:aint;
  634. function max:aint;
  635. { debug }
  636. {$ifdef GDB}
  637. function stabstring : pchar;override;
  638. {$endif GDB}
  639. { rtti }
  640. procedure write_rtti_data(rt:trttitype);override;
  641. procedure write_child_rtti_data(rt:trttitype);override;
  642. private
  643. procedure correct_owner_symtable;
  644. end;
  645. tsetdef = class(tstoreddef)
  646. elementtype : ttype;
  647. settype : tsettype;
  648. constructor create(const t:ttype;high : longint);
  649. constructor ppuload(ppufile:tcompilerppufile);
  650. destructor destroy;override;
  651. procedure ppuwrite(ppufile:tcompilerppufile);override;
  652. procedure buildderef;override;
  653. procedure deref;override;
  654. function gettypename:string;override;
  655. function is_publishable : boolean;override;
  656. { debug }
  657. {$ifdef GDB}
  658. function stabstring : pchar;override;
  659. procedure concatstabto(asmlist : taasmoutput);override;
  660. {$endif GDB}
  661. { rtti }
  662. procedure write_rtti_data(rt:trttitype);override;
  663. procedure write_child_rtti_data(rt:trttitype);override;
  664. end;
  665. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  666. var
  667. aktobjectdef : tobjectdef; { used for private functions check !! }
  668. {$ifdef GDB}
  669. writing_def_stabs : boolean;
  670. { for STAB debugging }
  671. globaltypecount : word;
  672. pglobaltypecount : pword;
  673. {$endif GDB}
  674. { default types }
  675. generrortype, { error in definition }
  676. voidpointertype, { pointer for Void-Pointerdef }
  677. charpointertype, { pointer for Char-Pointerdef }
  678. voidfarpointertype,
  679. cformaltype, { unique formal definition }
  680. voidtype, { Void (procedure) }
  681. cchartype, { Char }
  682. cwidechartype, { WideChar }
  683. booltype, { boolean type }
  684. u8inttype, { 8-Bit unsigned integer }
  685. s8inttype, { 8-Bit signed integer }
  686. u16inttype, { 16-Bit unsigned integer }
  687. s16inttype, { 16-Bit signed integer }
  688. u32inttype, { 32-Bit unsigned integer }
  689. s32inttype, { 32-Bit signed integer }
  690. u64inttype, { 64-bit unsigned integer }
  691. s64inttype, { 64-bit signed integer }
  692. s32floattype, { pointer for realconstn }
  693. s64floattype, { pointer for realconstn }
  694. s80floattype, { pointer to type of temp. floats }
  695. s64currencytype, { pointer to a currency type }
  696. cshortstringtype, { pointer to type of short string const }
  697. clongstringtype, { pointer to type of long string const }
  698. {$ifdef ansistring_bits}
  699. cansistringtype16, { pointer to type of ansi string const }
  700. cansistringtype32, { pointer to type of ansi string const }
  701. cansistringtype64, { pointer to type of ansi string const }
  702. {$else}
  703. cansistringtype, { pointer to type of ansi string const }
  704. {$endif}
  705. cwidestringtype, { pointer to type of wide string const }
  706. openshortstringtype, { pointer to type of an open shortstring,
  707. needed for readln() }
  708. openchararraytype, { pointer to type of an open array of char,
  709. needed for readln() }
  710. cfiletype, { get the same definition for all file }
  711. { used for stabs }
  712. methodpointertype, { typecasting of methodpointers to extract self }
  713. { we use only one variant def for every variant class }
  714. cvarianttype,
  715. colevarianttype,
  716. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  717. sinttype,
  718. uinttype,
  719. { unsigned ord type with the same size as a pointer }
  720. ptrinttype,
  721. { several types to simulate more or less C++ objects for GDB }
  722. vmttype,
  723. vmtarraytype,
  724. pvmttype : ttype; { type of classrefs, used for stabs }
  725. { pointer to the anchestor of all classes }
  726. class_tobject : tobjectdef;
  727. { pointer to the ancestor of all COM interfaces }
  728. interface_iunknown : tobjectdef;
  729. { pointer to the TGUID type
  730. of all interfaces }
  731. rec_tguid : trecorddef;
  732. const
  733. {$ifdef i386}
  734. pbestrealtype : ^ttype = @s80floattype;
  735. {$endif}
  736. {$ifdef x86_64}
  737. pbestrealtype : ^ttype = @s80floattype;
  738. {$endif}
  739. {$ifdef m68k}
  740. pbestrealtype : ^ttype = @s64floattype;
  741. {$endif}
  742. {$ifdef alpha}
  743. pbestrealtype : ^ttype = @s64floattype;
  744. {$endif}
  745. {$ifdef powerpc}
  746. pbestrealtype : ^ttype = @s64floattype;
  747. {$endif}
  748. {$ifdef ia64}
  749. pbestrealtype : ^ttype = @s64floattype;
  750. {$endif}
  751. {$ifdef SPARC}
  752. pbestrealtype : ^ttype = @s64floattype;
  753. {$endif SPARC}
  754. {$ifdef vis}
  755. pbestrealtype : ^ttype = @s64floattype;
  756. {$endif vis}
  757. {$ifdef ARM}
  758. pbestrealtype : ^ttype = @s64floattype;
  759. {$endif ARM}
  760. function reverseparaitems(p: tparaitem): tparaitem;
  761. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  762. { should be in the types unit, but the types unit uses the node stuff :( }
  763. function is_interfacecom(def: tdef): boolean;
  764. function is_interfacecorba(def: tdef): boolean;
  765. function is_interface(def: tdef): boolean;
  766. function is_object(def: tdef): boolean;
  767. function is_class(def: tdef): boolean;
  768. function is_cppclass(def: tdef): boolean;
  769. function is_class_or_interface(def: tdef): boolean;
  770. implementation
  771. uses
  772. strings,
  773. { global }
  774. verbose,
  775. { target }
  776. systems,aasmcpu,paramgr,
  777. { symtable }
  778. symsym,symtable,symutil,defutil,
  779. { module }
  780. {$ifdef GDB}
  781. gdb,
  782. {$endif GDB}
  783. fmodule,
  784. { other }
  785. gendef
  786. ;
  787. {****************************************************************************
  788. Helpers
  789. ****************************************************************************}
  790. function reverseparaitems(p: tparaitem): tparaitem;
  791. var
  792. hp1, hp2: tparaitem;
  793. begin
  794. hp1:=nil;
  795. while assigned(p) do
  796. begin
  797. { pull out }
  798. hp2:=p;
  799. p:=tparaitem(p.next);
  800. { pull in }
  801. hp2.next:=hp1;
  802. hp1:=hp2;
  803. end;
  804. reverseparaitems:=hp1;
  805. end;
  806. function make_mangledname(const typeprefix:string;st:tsymtable;const suffix:string):string;
  807. var
  808. s,
  809. prefix : string;
  810. begin
  811. prefix:='';
  812. if not assigned(st) then
  813. internalerror(200204212);
  814. { sub procedures }
  815. while (st.symtabletype=localsymtable) do
  816. begin
  817. if st.defowner.deftype<>procdef then
  818. internalerror(200204173);
  819. s:=tprocdef(st.defowner).procsym.name;
  820. if tprocdef(st.defowner).overloadnumber>0 then
  821. s:=s+'$'+tostr(tprocdef(st.defowner).overloadnumber);
  822. prefix:=s+'$'+prefix;
  823. st:=st.defowner.owner;
  824. end;
  825. { object/classes symtable }
  826. if (st.symtabletype=objectsymtable) then
  827. begin
  828. if st.defowner.deftype<>objectdef then
  829. internalerror(200204174);
  830. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  831. st:=st.defowner.owner;
  832. end;
  833. { symtable must now be static or global }
  834. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  835. internalerror(200204175);
  836. result:='';
  837. if typeprefix<>'' then
  838. result:=result+typeprefix+'_';
  839. { Add P$ for program, which can have the same name as
  840. a unit }
  841. if (tsymtable(main_module.localsymtable)=st) and
  842. (not main_module.is_unit) then
  843. result:=result+'P$'+st.name^
  844. else
  845. result:=result+st.name^;
  846. if prefix<>'' then
  847. result:=result+'_'+prefix;
  848. if suffix<>'' then
  849. result:=result+'_'+suffix;
  850. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  851. if (target_info.system = system_powerpc_darwin) and
  852. (result[1] = 'L') then
  853. result := '_' + result;
  854. end;
  855. {****************************************************************************
  856. TParaItem
  857. ****************************************************************************}
  858. constructor tparaitem.create;
  859. begin
  860. inherited create;
  861. paraloc[calleeside].init;
  862. paraloc[callerside].init;
  863. end;
  864. destructor tparaitem.destroy;
  865. begin
  866. paraloc[calleeside].done;
  867. paraloc[callerside].done;
  868. inherited destroy;
  869. end;
  870. {****************************************************************************
  871. TDEF (base class for definitions)
  872. ****************************************************************************}
  873. constructor tstoreddef.create;
  874. begin
  875. inherited create;
  876. savesize := 0;
  877. {$ifdef EXTDEBUG}
  878. fileinfo := aktfilepos;
  879. {$endif}
  880. if registerdef then
  881. symtablestack.registerdef(self);
  882. {$ifdef GDB}
  883. stab_state:=stab_state_unused;
  884. globalnb := 0;
  885. {$endif GDB}
  886. fillchar(localrttilab,sizeof(localrttilab),0);
  887. end;
  888. constructor tstoreddef.ppuloaddef(ppufile:tcompilerppufile);
  889. begin
  890. inherited create;
  891. {$ifdef EXTDEBUG}
  892. fillchar(fileinfo,sizeof(fileinfo),0);
  893. {$endif}
  894. {$ifdef GDB}
  895. stab_state:=stab_state_unused;
  896. globalnb := 0;
  897. {$endif GDB}
  898. fillchar(localrttilab,sizeof(localrttilab),0);
  899. { load }
  900. indexnr:=ppufile.getword;
  901. ppufile.getderef(typesymderef);
  902. ppufile.getsmallset(defoptions);
  903. if df_has_rttitable in defoptions then
  904. ppufile.getderef(rttitablesymderef);
  905. if df_has_inittable in defoptions then
  906. ppufile.getderef(inittablesymderef);
  907. end;
  908. procedure Tstoreddef.reset;
  909. begin
  910. {$ifdef GDB}
  911. stab_state:=stab_state_unused;
  912. {$endif GDB}
  913. if assigned(rttitablesym) then
  914. trttisym(rttitablesym).lab := nil;
  915. if assigned(inittablesym) then
  916. trttisym(inittablesym).lab := nil;
  917. localrttilab[initrtti]:=nil;
  918. localrttilab[fullrtti]:=nil;
  919. end;
  920. function tstoreddef.getcopy : tstoreddef;
  921. begin
  922. Message(sym_e_cant_create_unique_type);
  923. getcopy:=terrordef.create;
  924. end;
  925. procedure tstoreddef.ppuwritedef(ppufile:tcompilerppufile);
  926. begin
  927. ppufile.putword(indexnr);
  928. ppufile.putderef(typesymderef);
  929. ppufile.putsmallset(defoptions);
  930. if df_has_rttitable in defoptions then
  931. ppufile.putderef(rttitablesymderef);
  932. if df_has_inittable in defoptions then
  933. ppufile.putderef(inittablesymderef);
  934. {$ifdef GDB}
  935. if globalnb=0 then
  936. begin
  937. if (cs_gdb_dbx in aktglobalswitches) and
  938. assigned(owner) then
  939. globalnb := owner.getnewtypecount
  940. else
  941. set_globalnb;
  942. end;
  943. {$endif GDB}
  944. end;
  945. procedure tstoreddef.buildderef;
  946. begin
  947. typesymderef.build(typesym);
  948. rttitablesymderef.build(rttitablesym);
  949. inittablesymderef.build(inittablesym);
  950. end;
  951. procedure tstoreddef.buildderefimpl;
  952. begin
  953. end;
  954. procedure tstoreddef.deref;
  955. begin
  956. typesym:=ttypesym(typesymderef.resolve);
  957. if df_has_rttitable in defoptions then
  958. rttitablesym:=trttisym(rttitablesymderef.resolve);
  959. if df_has_inittable in defoptions then
  960. inittablesym:=trttisym(inittablesymderef.resolve);
  961. end;
  962. procedure tstoreddef.derefimpl;
  963. begin
  964. end;
  965. function tstoreddef.size : aint;
  966. begin
  967. size:=savesize;
  968. end;
  969. function tstoreddef.alignment : longint;
  970. begin
  971. { natural alignment by default }
  972. alignment:=size_2_align(savesize);
  973. end;
  974. {$ifdef GDB}
  975. procedure tstoreddef.set_globalnb;
  976. begin
  977. globalnb:=PGlobalTypeCount^;
  978. inc(PglobalTypeCount^);
  979. end;
  980. function Tstoreddef.get_var_value(const s:string):string;
  981. begin
  982. if s='numberstring' then
  983. get_var_value:=numberstring
  984. else if s='sym_name' then
  985. if assigned(typesym) then
  986. get_var_value:=Ttypesym(typesym).name
  987. else
  988. get_var_value:=' '
  989. else if s='N_LSYM' then
  990. get_var_value:=tostr(N_LSYM)
  991. else if s='savesize' then
  992. get_var_value:=tostr(savesize);
  993. end;
  994. function Tstoreddef.stabstr_evaluate(const s:string;const vars:array of string):Pchar;
  995. begin
  996. stabstr_evaluate:=string_evaluate(s,@get_var_value,vars);
  997. end;
  998. function tstoreddef.stabstring : pchar;
  999. begin
  1000. stabstring:=stabstr_evaluate('t${numberstring};',[]);
  1001. end;
  1002. function tstoreddef.numberstring : string;
  1003. begin
  1004. { Stab must already be written, or we must be busy writing it }
  1005. if writing_def_stabs and
  1006. not(stab_state in [stab_state_writing,stab_state_written]) then
  1007. internalerror(200403091);
  1008. { Keep track of used stabs, this info is only usefull for stabs
  1009. referenced by the symbols. Definitions will always include all
  1010. required stabs }
  1011. if stab_state=stab_state_unused then
  1012. stab_state:=stab_state_used;
  1013. { Need a new number? }
  1014. if globalnb=0 then
  1015. begin
  1016. if (cs_gdb_dbx in aktglobalswitches) and
  1017. assigned(owner) then
  1018. globalnb := owner.getnewtypecount
  1019. else
  1020. set_globalnb;
  1021. end;
  1022. if (cs_gdb_dbx in aktglobalswitches) and
  1023. assigned(typesym) and
  1024. (ttypesym(typesym).owner.unitid<>0) then
  1025. result:='('+tostr(ttypesym(typesym).owner.unitid)+','+tostr(tstoreddef(ttypesym(typesym).restype.def).globalnb)+')'
  1026. else
  1027. result:=tostr(globalnb);
  1028. end;
  1029. function tstoreddef.allstabstring : pchar;
  1030. var
  1031. stabchar : string[2];
  1032. ss,st,su : pchar;
  1033. begin
  1034. ss := stabstring;
  1035. stabchar := 't';
  1036. if deftype in tagtypes then
  1037. stabchar := 'Tt';
  1038. { Here we maybe generate a type, so we have to use numberstring }
  1039. st:=stabstr_evaluate('"${sym_name}:$1$2=',[stabchar,numberstring]);
  1040. reallocmem(st,strlen(ss)+512);
  1041. { line info is set to 0 for all defs, because the def can be in an other
  1042. unit and then the linenumber is invalid in the current sourcefile }
  1043. su:=stabstr_evaluate('",${N_LSYM},0,0,0',[]);
  1044. strcopy(strecopy(strend(st),ss),su);
  1045. reallocmem(st,strlen(st)+1);
  1046. allstabstring:=st;
  1047. strdispose(ss);
  1048. strdispose(su);
  1049. end;
  1050. procedure tstoreddef.concatstabto(asmlist : taasmoutput);
  1051. var
  1052. stab_str : pchar;
  1053. begin
  1054. if (stab_state in [stab_state_writing,stab_state_written]) then
  1055. exit;
  1056. If cs_gdb_dbx in aktglobalswitches then
  1057. begin
  1058. { otherwise you get two of each def }
  1059. If assigned(typesym) then
  1060. begin
  1061. if (ttypesym(typesym).owner = nil) or
  1062. ((ttypesym(typesym).owner.symtabletype = globalsymtable) and
  1063. tglobalsymtable(ttypesym(typesym).owner).dbx_count_ok) then
  1064. begin
  1065. {with DBX we get the definition from the other objects }
  1066. stab_state := stab_state_written;
  1067. exit;
  1068. end;
  1069. end;
  1070. end;
  1071. { to avoid infinite loops }
  1072. stab_state := stab_state_writing;
  1073. stab_str := allstabstring;
  1074. asmList.concat(Tai_stabs.Create(stab_str));
  1075. stab_state := stab_state_written;
  1076. end;
  1077. {$endif GDB}
  1078. procedure tstoreddef.write_rtti_name;
  1079. var
  1080. str : string;
  1081. begin
  1082. { name }
  1083. if assigned(typesym) then
  1084. begin
  1085. str:=ttypesym(typesym).realname;
  1086. rttiList.concat(Tai_string.Create(chr(length(str))+str));
  1087. end
  1088. else
  1089. rttiList.concat(Tai_string.Create(#0))
  1090. end;
  1091. procedure tstoreddef.write_rtti_data(rt:trttitype);
  1092. begin
  1093. rttilist.concat(tai_const.create_8bit(tkUnknown));
  1094. write_rtti_name;
  1095. end;
  1096. procedure tstoreddef.write_child_rtti_data(rt:trttitype);
  1097. begin
  1098. end;
  1099. function tstoreddef.get_rtti_label(rt:trttitype) : tasmsymbol;
  1100. begin
  1101. { try to reuse persistent rtti data }
  1102. if (rt=fullrtti) and (df_has_rttitable in defoptions) then
  1103. get_rtti_label:=trttisym(rttitablesym).get_label
  1104. else
  1105. if (rt=initrtti) and (df_has_inittable in defoptions) then
  1106. get_rtti_label:=trttisym(inittablesym).get_label
  1107. else
  1108. begin
  1109. if not assigned(localrttilab[rt]) then
  1110. begin
  1111. objectlibrary.getdatalabel(localrttilab[rt]);
  1112. write_child_rtti_data(rt);
  1113. maybe_new_object_file(rttiList);
  1114. new_section(rttiList,sec_rodata,localrttilab[rt].name,const_align(sizeof(aint)));
  1115. rttiList.concat(Tai_symbol.Create_global(localrttilab[rt],0));
  1116. write_rtti_data(rt);
  1117. rttiList.concat(Tai_symbol_end.Create(localrttilab[rt]));
  1118. end;
  1119. get_rtti_label:=localrttilab[rt];
  1120. end;
  1121. end;
  1122. { returns true, if the definition can be published }
  1123. function tstoreddef.is_publishable : boolean;
  1124. begin
  1125. is_publishable:=false;
  1126. end;
  1127. { needs an init table }
  1128. function tstoreddef.needs_inittable : boolean;
  1129. begin
  1130. needs_inittable:=false;
  1131. end;
  1132. function tstoreddef.is_intregable : boolean;
  1133. begin
  1134. is_intregable:=false;
  1135. case deftype of
  1136. pointerdef,
  1137. enumdef:
  1138. is_intregable:=true;
  1139. procvardef :
  1140. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  1141. orddef :
  1142. case torddef(self).typ of
  1143. bool8bit,bool16bit,bool32bit,
  1144. u8bit,u16bit,u32bit,
  1145. s8bit,s16bit,s32bit,
  1146. uchar, uwidechar:
  1147. is_intregable:=true;
  1148. end;
  1149. objectdef:
  1150. is_intregable:=is_class(self) or is_interface(self);
  1151. setdef:
  1152. is_intregable:=(tsetdef(self).settype=smallset);
  1153. end;
  1154. end;
  1155. function tstoreddef.is_fpuregable : boolean;
  1156. begin
  1157. {$ifdef x86}
  1158. result:=false;
  1159. {$else x86}
  1160. result:=(deftype=floatdef);
  1161. {$endif x86}
  1162. end;
  1163. {****************************************************************************
  1164. Tstringdef
  1165. ****************************************************************************}
  1166. constructor tstringdef.createshort(l : byte);
  1167. begin
  1168. inherited create;
  1169. string_typ:=st_shortstring;
  1170. deftype:=stringdef;
  1171. len:=l;
  1172. savesize:=len+1;
  1173. end;
  1174. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1175. begin
  1176. inherited ppuloaddef(ppufile);
  1177. string_typ:=st_shortstring;
  1178. deftype:=stringdef;
  1179. len:=ppufile.getbyte;
  1180. savesize:=len+1;
  1181. end;
  1182. constructor tstringdef.createlong(l : aint);
  1183. begin
  1184. inherited create;
  1185. string_typ:=st_longstring;
  1186. deftype:=stringdef;
  1187. len:=l;
  1188. savesize:=sizeof(aint);
  1189. end;
  1190. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1191. begin
  1192. inherited ppuloaddef(ppufile);
  1193. deftype:=stringdef;
  1194. string_typ:=st_longstring;
  1195. len:=ppufile.getaint;
  1196. savesize:=sizeof(aint);
  1197. end;
  1198. {$ifdef ansistring_bits}
  1199. constructor tstringdef.createansi(l:aint;bits:Tstringbits);
  1200. begin
  1201. inherited create;
  1202. case bits of
  1203. sb_16:
  1204. string_typ:=st_ansistring16;
  1205. sb_32:
  1206. string_typ:=st_ansistring32;
  1207. sb_64:
  1208. string_typ:=st_ansistring64;
  1209. end;
  1210. deftype:=stringdef;
  1211. len:=l;
  1212. savesize:=POINTER_SIZE;
  1213. end;
  1214. constructor tstringdef.loadansi(ppufile:tcompilerppufile;bits:Tstringbits);
  1215. begin
  1216. inherited ppuloaddef(ppufile);
  1217. deftype:=stringdef;
  1218. case bits of
  1219. sb_16:
  1220. string_typ:=st_ansistring16;
  1221. sb_32:
  1222. string_typ:=st_ansistring32;
  1223. sb_64:
  1224. string_typ:=st_ansistring64;
  1225. end;
  1226. len:=ppufile.getaint;
  1227. savesize:=POINTER_SIZE;
  1228. end;
  1229. {$else}
  1230. constructor tstringdef.createansi(l:aint);
  1231. begin
  1232. inherited create;
  1233. string_typ:=st_ansistring;
  1234. deftype:=stringdef;
  1235. len:=l;
  1236. savesize:=sizeof(aint);
  1237. end;
  1238. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1239. begin
  1240. inherited ppuloaddef(ppufile);
  1241. deftype:=stringdef;
  1242. string_typ:=st_ansistring;
  1243. len:=ppufile.getaint;
  1244. savesize:=sizeof(aint);
  1245. end;
  1246. {$endif}
  1247. constructor tstringdef.createwide(l : aint);
  1248. begin
  1249. inherited create;
  1250. string_typ:=st_widestring;
  1251. deftype:=stringdef;
  1252. len:=l;
  1253. savesize:=sizeof(aint);
  1254. end;
  1255. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1256. begin
  1257. inherited ppuloaddef(ppufile);
  1258. deftype:=stringdef;
  1259. string_typ:=st_widestring;
  1260. len:=ppufile.getaint;
  1261. savesize:=sizeof(aint);
  1262. end;
  1263. function tstringdef.getcopy : tstoreddef;
  1264. begin
  1265. result:=tstringdef.create;
  1266. result.deftype:=stringdef;
  1267. tstringdef(result).string_typ:=string_typ;
  1268. tstringdef(result).len:=len;
  1269. tstringdef(result).savesize:=savesize;
  1270. end;
  1271. function tstringdef.stringtypname:string;
  1272. {$ifdef ansistring_bits}
  1273. const
  1274. typname:array[tstringtype] of string[9]=('',
  1275. 'shortstr','longstr','ansistr16','ansistr32','ansistr64','widestr'
  1276. );
  1277. {$else}
  1278. const
  1279. typname:array[tstringtype] of string[8]=('',
  1280. 'shortstr','longstr','ansistr','widestr'
  1281. );
  1282. {$endif}
  1283. begin
  1284. stringtypname:=typname[string_typ];
  1285. end;
  1286. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1287. begin
  1288. inherited ppuwritedef(ppufile);
  1289. if string_typ=st_shortstring then
  1290. begin
  1291. {$ifdef extdebug}
  1292. if len > 255 then internalerror(12122002);
  1293. {$endif}
  1294. ppufile.putbyte(byte(len))
  1295. end
  1296. else
  1297. ppufile.putaint(len);
  1298. case string_typ of
  1299. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1300. st_longstring : ppufile.writeentry(iblongstringdef);
  1301. {$ifdef ansistring_bits}
  1302. st_ansistring16 : ppufile.writeentry(ibansistring16def);
  1303. st_ansistring32 : ppufile.writeentry(ibansistring32def);
  1304. st_ansistring64 : ppufile.writeentry(ibansistring64def);
  1305. {$else}
  1306. st_ansistring : ppufile.writeentry(ibansistringdef);
  1307. {$endif}
  1308. st_widestring : ppufile.writeentry(ibwidestringdef);
  1309. end;
  1310. end;
  1311. {$ifdef GDB}
  1312. function tstringdef.stabstring : pchar;
  1313. var
  1314. bytest,charst,longst : string;
  1315. slen : aint;
  1316. begin
  1317. case string_typ of
  1318. st_shortstring:
  1319. begin
  1320. charst:=tstoreddef(cchartype.def).numberstring;
  1321. { this is what I found in stabs.texinfo but
  1322. gdb 4.12 for go32 doesn't understand that !! }
  1323. {$IfDef GDBknowsstrings}
  1324. stabstring:=stabstr_evaluate('n$1;$2',[charst,tostr(len)]);
  1325. {$else}
  1326. { fix length of openshortstring }
  1327. slen:=len;
  1328. if slen=0 then
  1329. slen:=255;
  1330. bytest:=tstoreddef(u8inttype.def).numberstring;
  1331. stabstring:=stabstr_evaluate('s$1length:$2,0,8;st:ar$2;1;$3;$4,8,$5;;',
  1332. [tostr(slen+1),bytest,tostr(slen),charst,tostr(slen*8)]);
  1333. {$EndIf}
  1334. end;
  1335. st_longstring:
  1336. begin
  1337. charst:=tstoreddef(cchartype.def).numberstring;
  1338. { this is what I found in stabs.texinfo but
  1339. gdb 4.12 for go32 doesn't understand that !! }
  1340. {$IfDef GDBknowsstrings}
  1341. stabstring:=stabstr_evaluate('n$1;$2',[charst,tostr(len)]);
  1342. {$else}
  1343. bytest:=tstoreddef(u8inttype.def).numberstring;
  1344. longst:=tstoreddef(u32inttype.def).numberstring;
  1345. stabstring:=stabstr_evaluate('s$1length:$2,0,32;dummy:$6,32,8;st:ar$2;1;$3;$4,40,$5;;',
  1346. [tostr(len+5),longst,tostr(len),charst,tostr(len*8),bytest]);
  1347. {$EndIf}
  1348. end;
  1349. {$ifdef ansistring_bits}
  1350. st_ansistring16,st_ansistring32,st_ansistring64:
  1351. {$else}
  1352. st_ansistring:
  1353. {$endif}
  1354. begin
  1355. { an ansi string looks like a pchar easy !! }
  1356. charst:=tstoreddef(cchartype.def).numberstring;
  1357. stabstring:=strpnew('*'+charst);
  1358. end;
  1359. st_widestring:
  1360. begin
  1361. { an ansi string looks like a pwidechar easy !! }
  1362. charst:=tstoreddef(cwidechartype.def).numberstring;
  1363. stabstring:=strpnew('*'+charst);
  1364. end;
  1365. end;
  1366. end;
  1367. procedure tstringdef.concatstabto(asmlist:taasmoutput);
  1368. begin
  1369. if (stab_state in [stab_state_writing,stab_state_written]) then
  1370. exit;
  1371. case string_typ of
  1372. st_shortstring:
  1373. begin
  1374. tstoreddef(cchartype.def).concatstabto(asmlist);
  1375. {$IfNDef GDBknowsstrings}
  1376. tstoreddef(u8inttype.def).concatstabto(asmlist);
  1377. {$EndIf}
  1378. end;
  1379. st_longstring:
  1380. begin
  1381. tstoreddef(cchartype.def).concatstabto(asmlist);
  1382. {$IfNDef GDBknowsstrings}
  1383. tstoreddef(u8inttype.def).concatstabto(asmlist);
  1384. tstoreddef(u32inttype.def).concatstabto(asmlist);
  1385. {$EndIf}
  1386. end;
  1387. {$ifdef ansistring_bits}
  1388. st_ansistring16,st_ansistring32,st_ansistring64:
  1389. {$else}
  1390. st_ansistring:
  1391. {$endif}
  1392. tstoreddef(cchartype.def).concatstabto(asmlist);
  1393. st_widestring:
  1394. tstoreddef(cwidechartype.def).concatstabto(asmlist);
  1395. end;
  1396. inherited concatstabto(asmlist);
  1397. end;
  1398. {$endif GDB}
  1399. function tstringdef.needs_inittable : boolean;
  1400. begin
  1401. {$ifdef ansistring_bits}
  1402. needs_inittable:=string_typ in [st_ansistring16,st_ansistring32,st_ansistring64,st_widestring];
  1403. {$else}
  1404. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  1405. {$endif}
  1406. end;
  1407. function tstringdef.gettypename : string;
  1408. {$ifdef ansistring_bits}
  1409. const
  1410. names : array[tstringtype] of string[20] = ('',
  1411. 'shortstring','longstring','ansistring16','ansistring32','ansistring64','widestring');
  1412. {$else}
  1413. const
  1414. names : array[tstringtype] of string[20] = ('',
  1415. 'ShortString','LongString','AnsiString','WideString');
  1416. {$endif}
  1417. begin
  1418. gettypename:=names[string_typ];
  1419. end;
  1420. procedure tstringdef.write_rtti_data(rt:trttitype);
  1421. begin
  1422. case string_typ of
  1423. {$ifdef ansistring_bits}
  1424. st_ansistring16:
  1425. begin
  1426. rttiList.concat(Tai_const.Create_8bit(tkA16String));
  1427. write_rtti_name;
  1428. end;
  1429. st_ansistring32:
  1430. begin
  1431. rttiList.concat(Tai_const.Create_8bit(tkA32String));
  1432. write_rtti_name;
  1433. end;
  1434. st_ansistring64:
  1435. begin
  1436. rttiList.concat(Tai_const.Create_8bit(tkA64String));
  1437. write_rtti_name;
  1438. end;
  1439. {$else}
  1440. st_ansistring:
  1441. begin
  1442. rttiList.concat(Tai_const.Create_8bit(tkAString));
  1443. write_rtti_name;
  1444. end;
  1445. {$endif}
  1446. st_widestring:
  1447. begin
  1448. rttiList.concat(Tai_const.Create_8bit(tkWString));
  1449. write_rtti_name;
  1450. end;
  1451. st_longstring:
  1452. begin
  1453. rttiList.concat(Tai_const.Create_8bit(tkLString));
  1454. write_rtti_name;
  1455. end;
  1456. st_shortstring:
  1457. begin
  1458. rttiList.concat(Tai_const.Create_8bit(tkSString));
  1459. write_rtti_name;
  1460. rttiList.concat(Tai_const.Create_8bit(len));
  1461. end;
  1462. end;
  1463. end;
  1464. function tstringdef.getmangledparaname : string;
  1465. begin
  1466. getmangledparaname:='STRING';
  1467. end;
  1468. function tstringdef.is_publishable : boolean;
  1469. begin
  1470. is_publishable:=true;
  1471. end;
  1472. {****************************************************************************
  1473. TENUMDEF
  1474. ****************************************************************************}
  1475. constructor tenumdef.create;
  1476. begin
  1477. inherited create;
  1478. deftype:=enumdef;
  1479. minval:=0;
  1480. maxval:=0;
  1481. calcsavesize;
  1482. has_jumps:=false;
  1483. basedef:=nil;
  1484. firstenum:=nil;
  1485. correct_owner_symtable;
  1486. end;
  1487. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1488. begin
  1489. inherited create;
  1490. deftype:=enumdef;
  1491. minval:=_min;
  1492. maxval:=_max;
  1493. basedef:=_basedef;
  1494. calcsavesize;
  1495. has_jumps:=false;
  1496. firstenum:=basedef.firstenum;
  1497. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1498. firstenum:=tenumsym(firstenum).nextenum;
  1499. correct_owner_symtable;
  1500. end;
  1501. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1502. begin
  1503. inherited ppuloaddef(ppufile);
  1504. deftype:=enumdef;
  1505. ppufile.getderef(basedefderef);
  1506. minval:=ppufile.getaint;
  1507. maxval:=ppufile.getaint;
  1508. savesize:=ppufile.getaint;
  1509. has_jumps:=false;
  1510. firstenum:=Nil;
  1511. end;
  1512. procedure tenumdef.calcsavesize;
  1513. begin
  1514. if (aktpackenum=8) or (min<low(longint)) or (max>high(cardinal)) then
  1515. savesize:=8
  1516. else
  1517. if (aktpackenum=4) or (min<low(smallint)) or (max>high(word)) then
  1518. savesize:=4
  1519. else
  1520. if (aktpackenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1521. savesize:=2
  1522. else
  1523. savesize:=1;
  1524. end;
  1525. procedure tenumdef.setmax(_max:aint);
  1526. begin
  1527. maxval:=_max;
  1528. calcsavesize;
  1529. end;
  1530. procedure tenumdef.setmin(_min:aint);
  1531. begin
  1532. minval:=_min;
  1533. calcsavesize;
  1534. end;
  1535. function tenumdef.min:aint;
  1536. begin
  1537. min:=minval;
  1538. end;
  1539. function tenumdef.max:aint;
  1540. begin
  1541. max:=maxval;
  1542. end;
  1543. procedure tenumdef.buildderef;
  1544. begin
  1545. inherited buildderef;
  1546. basedefderef.build(basedef);
  1547. end;
  1548. procedure tenumdef.deref;
  1549. begin
  1550. inherited deref;
  1551. basedef:=tenumdef(basedefderef.resolve);
  1552. { restart ordering }
  1553. firstenum:=nil;
  1554. end;
  1555. destructor tenumdef.destroy;
  1556. begin
  1557. inherited destroy;
  1558. end;
  1559. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1560. begin
  1561. inherited ppuwritedef(ppufile);
  1562. ppufile.putderef(basedefderef);
  1563. ppufile.putaint(min);
  1564. ppufile.putaint(max);
  1565. ppufile.putaint(savesize);
  1566. ppufile.writeentry(ibenumdef);
  1567. end;
  1568. { used for enumdef because the symbols are
  1569. inserted in the owner symtable }
  1570. procedure tenumdef.correct_owner_symtable;
  1571. var
  1572. st : tsymtable;
  1573. begin
  1574. if assigned(owner) and
  1575. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  1576. begin
  1577. owner.defindex.deleteindex(self);
  1578. st:=owner;
  1579. while (st.symtabletype in [recordsymtable,objectsymtable]) do
  1580. st:=st.next;
  1581. st.registerdef(self);
  1582. end;
  1583. end;
  1584. {$ifdef GDB}
  1585. function tenumdef.stabstring : pchar;
  1586. var st:Pchar;
  1587. p:Tenumsym;
  1588. s:string;
  1589. memsize,stl:cardinal;
  1590. begin
  1591. memsize:=memsizeinc;
  1592. getmem(st,memsize);
  1593. { we can specify the size with @s<size>; prefix PM }
  1594. if savesize <> std_param_align then
  1595. strpcopy(st,'@s'+tostr(savesize*8)+';e')
  1596. else
  1597. strpcopy(st,'e');
  1598. p := tenumsym(firstenum);
  1599. stl:=strlen(st);
  1600. while assigned(p) do
  1601. begin
  1602. s :=p.name+':'+tostr(p.value)+',';
  1603. { place for the ending ';' also }
  1604. if (stl+length(s)+1>=memsize) then
  1605. begin
  1606. inc(memsize,memsizeinc);
  1607. reallocmem(st,memsize);
  1608. end;
  1609. strpcopy(st+stl,s);
  1610. inc(stl,length(s));
  1611. p:=p.nextenum;
  1612. end;
  1613. st[stl]:=';';
  1614. st[stl+1]:=#0;
  1615. reallocmem(st,stl+2);
  1616. stabstring:=st;
  1617. end;
  1618. {$endif GDB}
  1619. procedure tenumdef.write_child_rtti_data(rt:trttitype);
  1620. begin
  1621. if assigned(basedef) then
  1622. basedef.get_rtti_label(rt);
  1623. end;
  1624. procedure tenumdef.write_rtti_data(rt:trttitype);
  1625. var
  1626. hp : tenumsym;
  1627. begin
  1628. rttiList.concat(Tai_const.Create_8bit(tkEnumeration));
  1629. write_rtti_name;
  1630. case longint(savesize) of
  1631. 1:
  1632. rttiList.concat(Tai_const.Create_8bit(otUByte));
  1633. 2:
  1634. rttiList.concat(Tai_const.Create_8bit(otUWord));
  1635. 4:
  1636. rttiList.concat(Tai_const.Create_8bit(otULong));
  1637. end;
  1638. rttiList.concat(Tai_const.Create_32bit(min));
  1639. rttiList.concat(Tai_const.Create_32bit(max));
  1640. if assigned(basedef) then
  1641. rttiList.concat(Tai_const.Create_sym(basedef.get_rtti_label(rt)))
  1642. else
  1643. rttiList.concat(Tai_const.create_sym(nil));
  1644. hp:=tenumsym(firstenum);
  1645. while assigned(hp) do
  1646. begin
  1647. rttiList.concat(Tai_const.Create_8bit(length(hp.realname)));
  1648. rttiList.concat(Tai_string.Create(hp.realname));
  1649. hp:=hp.nextenum;
  1650. end;
  1651. rttiList.concat(Tai_const.Create_8bit(0));
  1652. end;
  1653. function tenumdef.is_publishable : boolean;
  1654. begin
  1655. is_publishable:=true;
  1656. end;
  1657. function tenumdef.gettypename : string;
  1658. begin
  1659. gettypename:='<enumeration type>';
  1660. end;
  1661. {****************************************************************************
  1662. TORDDEF
  1663. ****************************************************************************}
  1664. constructor torddef.create(t : tbasetype;v,b : TConstExprInt);
  1665. begin
  1666. inherited create;
  1667. deftype:=orddef;
  1668. low:=v;
  1669. high:=b;
  1670. typ:=t;
  1671. setsize;
  1672. end;
  1673. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1674. begin
  1675. inherited ppuloaddef(ppufile);
  1676. deftype:=orddef;
  1677. typ:=tbasetype(ppufile.getbyte);
  1678. if sizeof(TConstExprInt)=8 then
  1679. begin
  1680. low:=ppufile.getint64;
  1681. high:=ppufile.getint64;
  1682. end
  1683. else
  1684. begin
  1685. low:=ppufile.getlongint;
  1686. high:=ppufile.getlongint;
  1687. end;
  1688. setsize;
  1689. end;
  1690. function torddef.getcopy : tstoreddef;
  1691. begin
  1692. result:=torddef.create(typ,low,high);
  1693. result.deftype:=orddef;
  1694. torddef(result).low:=low;
  1695. torddef(result).high:=high;
  1696. torddef(result).typ:=typ;
  1697. torddef(result).savesize:=savesize;
  1698. end;
  1699. procedure torddef.setsize;
  1700. const
  1701. sizetbl : array[tbasetype] of longint = (
  1702. 0,
  1703. 1,2,4,8,
  1704. 1,2,4,8,
  1705. 1,2,4,
  1706. 1,2,8
  1707. );
  1708. begin
  1709. savesize:=sizetbl[typ];
  1710. end;
  1711. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1712. begin
  1713. inherited ppuwritedef(ppufile);
  1714. ppufile.putbyte(byte(typ));
  1715. if sizeof(TConstExprInt)=8 then
  1716. begin
  1717. ppufile.putint64(low);
  1718. ppufile.putint64(high);
  1719. end
  1720. else
  1721. begin
  1722. ppufile.putlongint(low);
  1723. ppufile.putlongint(high);
  1724. end;
  1725. ppufile.writeentry(iborddef);
  1726. end;
  1727. {$ifdef GDB}
  1728. function torddef.stabstring : pchar;
  1729. begin
  1730. if cs_gdb_valgrind in aktglobalswitches then
  1731. begin
  1732. case typ of
  1733. uvoid :
  1734. stabstring := strpnew(numberstring);
  1735. bool8bit,
  1736. bool16bit,
  1737. bool32bit :
  1738. stabstring := stabstr_evaluate('r${numberstring};0;255;',[]);
  1739. u32bit,
  1740. s64bit,
  1741. u64bit :
  1742. stabstring:=stabstr_evaluate('r${numberstring};0;-1;',[]);
  1743. else
  1744. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1745. end;
  1746. end
  1747. else
  1748. begin
  1749. case typ of
  1750. uvoid :
  1751. stabstring := strpnew(numberstring);
  1752. uchar :
  1753. stabstring := strpnew('-20;');
  1754. uwidechar :
  1755. stabstring := strpnew('-30;');
  1756. bool8bit :
  1757. stabstring := strpnew('-21;');
  1758. bool16bit :
  1759. stabstring := strpnew('-22;');
  1760. bool32bit :
  1761. stabstring := strpnew('-23;');
  1762. u64bit :
  1763. stabstring := strpnew('-32;');
  1764. s64bit :
  1765. stabstring := strpnew('-31;');
  1766. {u32bit : stabstring := tstoreddef(s32inttype.def).numberstring+';0;-1;'); }
  1767. else
  1768. stabstring:=stabstr_evaluate('r${numberstring};$1;$2;',[tostr(longint(low)),tostr(longint(high))]);
  1769. end;
  1770. end;
  1771. end;
  1772. {$endif GDB}
  1773. procedure torddef.write_rtti_data(rt:trttitype);
  1774. procedure dointeger;
  1775. const
  1776. trans : array[tbasetype] of byte =
  1777. (otUByte{otNone},
  1778. otUByte,otUWord,otULong,otUByte{otNone},
  1779. otSByte,otSWord,otSLong,otUByte{otNone},
  1780. otUByte,otUWord,otULong,
  1781. otUByte,otUWord,otUByte);
  1782. begin
  1783. write_rtti_name;
  1784. rttiList.concat(Tai_const.Create_8bit(byte(trans[typ])));
  1785. rttiList.concat(Tai_const.Create_32bit(longint(low)));
  1786. rttiList.concat(Tai_const.Create_32bit(longint(high)));
  1787. end;
  1788. begin
  1789. case typ of
  1790. s64bit :
  1791. begin
  1792. rttiList.concat(Tai_const.Create_8bit(tkInt64));
  1793. write_rtti_name;
  1794. { low }
  1795. rttiList.concat(Tai_const.Create_64bit(int64($80000000) shl 32));
  1796. { high }
  1797. rttiList.concat(Tai_const.Create_64bit((int64($7fffffff) shl 32) or int64($ffffffff)));
  1798. end;
  1799. u64bit :
  1800. begin
  1801. rttiList.concat(Tai_const.Create_8bit(tkQWord));
  1802. write_rtti_name;
  1803. { low }
  1804. rttiList.concat(Tai_const.Create_64bit(0));
  1805. { high }
  1806. rttiList.concat(Tai_const.Create_64bit(int64((int64($ffffffff) shl 32) or int64($ffffffff))));
  1807. end;
  1808. bool8bit:
  1809. begin
  1810. rttiList.concat(Tai_const.Create_8bit(tkBool));
  1811. dointeger;
  1812. end;
  1813. uchar:
  1814. begin
  1815. rttiList.concat(Tai_const.Create_8bit(tkChar));
  1816. dointeger;
  1817. end;
  1818. uwidechar:
  1819. begin
  1820. rttiList.concat(Tai_const.Create_8bit(tkWChar));
  1821. dointeger;
  1822. end;
  1823. else
  1824. begin
  1825. rttiList.concat(Tai_const.Create_8bit(tkInteger));
  1826. dointeger;
  1827. end;
  1828. end;
  1829. end;
  1830. function torddef.is_publishable : boolean;
  1831. begin
  1832. is_publishable:=(typ<>uvoid);
  1833. end;
  1834. function torddef.gettypename : string;
  1835. const
  1836. names : array[tbasetype] of string[20] = (
  1837. 'untyped',
  1838. 'Byte','Word','DWord','QWord',
  1839. 'ShortInt','SmallInt','LongInt','Int64',
  1840. 'Boolean','WordBool','LongBool',
  1841. 'Char','WideChar','Currency');
  1842. begin
  1843. gettypename:=names[typ];
  1844. end;
  1845. {****************************************************************************
  1846. TFLOATDEF
  1847. ****************************************************************************}
  1848. constructor tfloatdef.create(t : tfloattype);
  1849. begin
  1850. inherited create;
  1851. deftype:=floatdef;
  1852. typ:=t;
  1853. setsize;
  1854. end;
  1855. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1856. begin
  1857. inherited ppuloaddef(ppufile);
  1858. deftype:=floatdef;
  1859. typ:=tfloattype(ppufile.getbyte);
  1860. setsize;
  1861. end;
  1862. function tfloatdef.getcopy : tstoreddef;
  1863. begin
  1864. result:=tfloatdef.create(typ);
  1865. result.deftype:=floatdef;
  1866. tfloatdef(result).savesize:=savesize;
  1867. end;
  1868. procedure tfloatdef.setsize;
  1869. begin
  1870. case typ of
  1871. s32real : savesize:=4;
  1872. s80real : savesize:=10;
  1873. s64real,
  1874. s64currency,
  1875. s64comp : savesize:=8;
  1876. else
  1877. savesize:=0;
  1878. end;
  1879. end;
  1880. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1881. begin
  1882. inherited ppuwritedef(ppufile);
  1883. ppufile.putbyte(byte(typ));
  1884. ppufile.writeentry(ibfloatdef);
  1885. end;
  1886. {$ifdef GDB}
  1887. function Tfloatdef.stabstring:Pchar;
  1888. begin
  1889. case typ of
  1890. s32real,s64real:
  1891. { found this solution in stabsread.c from GDB v4.16 }
  1892. stabstring:=stabstr_evaluate('r$1;${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1893. s64currency,s64comp:
  1894. stabstring:=stabstr_evaluate('r$1;-${savesize};0;',[tstoreddef(s32inttype.def).numberstring]);
  1895. s80real:
  1896. { under dos at least you must give a size of twelve instead of 10 !! }
  1897. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  1898. stabstring:=stabstr_evaluate('r$1;12;0;',[tstoreddef(s32inttype.def).numberstring]);
  1899. else
  1900. internalerror(10005);
  1901. end;
  1902. end;
  1903. procedure tfloatdef.concatstabto(asmlist:taasmoutput);
  1904. begin
  1905. if (stab_state in [stab_state_writing,stab_state_written]) then
  1906. exit;
  1907. tstoreddef(s32inttype.def).concatstabto(asmlist);
  1908. inherited concatstabto(asmlist);
  1909. end;
  1910. {$endif GDB}
  1911. procedure tfloatdef.write_rtti_data(rt:trttitype);
  1912. const
  1913. {tfloattype = (s32real,s64real,s80real,s64bit,s128bit);}
  1914. translate : array[tfloattype] of byte =
  1915. (ftSingle,ftDouble,ftExtended,ftComp,ftCurr,ftFloat128);
  1916. begin
  1917. rttiList.concat(Tai_const.Create_8bit(tkFloat));
  1918. write_rtti_name;
  1919. rttiList.concat(Tai_const.Create_8bit(translate[typ]));
  1920. end;
  1921. function tfloatdef.is_publishable : boolean;
  1922. begin
  1923. is_publishable:=true;
  1924. end;
  1925. function tfloatdef.gettypename : string;
  1926. const
  1927. names : array[tfloattype] of string[20] = (
  1928. 'Single','Double','Extended','Comp','Currency','Float128');
  1929. begin
  1930. gettypename:=names[typ];
  1931. end;
  1932. {****************************************************************************
  1933. TFILEDEF
  1934. ****************************************************************************}
  1935. constructor tfiledef.createtext;
  1936. begin
  1937. inherited create;
  1938. deftype:=filedef;
  1939. filetyp:=ft_text;
  1940. typedfiletype.reset;
  1941. setsize;
  1942. end;
  1943. constructor tfiledef.createuntyped;
  1944. begin
  1945. inherited create;
  1946. deftype:=filedef;
  1947. filetyp:=ft_untyped;
  1948. typedfiletype.reset;
  1949. setsize;
  1950. end;
  1951. constructor tfiledef.createtyped(const tt : ttype);
  1952. begin
  1953. inherited create;
  1954. deftype:=filedef;
  1955. filetyp:=ft_typed;
  1956. typedfiletype:=tt;
  1957. setsize;
  1958. end;
  1959. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1960. begin
  1961. inherited ppuloaddef(ppufile);
  1962. deftype:=filedef;
  1963. filetyp:=tfiletyp(ppufile.getbyte);
  1964. if filetyp=ft_typed then
  1965. ppufile.gettype(typedfiletype)
  1966. else
  1967. typedfiletype.reset;
  1968. setsize;
  1969. end;
  1970. procedure tfiledef.buildderef;
  1971. begin
  1972. inherited buildderef;
  1973. if filetyp=ft_typed then
  1974. typedfiletype.buildderef;
  1975. end;
  1976. procedure tfiledef.deref;
  1977. begin
  1978. inherited deref;
  1979. if filetyp=ft_typed then
  1980. typedfiletype.resolve;
  1981. end;
  1982. procedure tfiledef.setsize;
  1983. begin
  1984. {$ifdef cpu64bit}
  1985. case filetyp of
  1986. ft_text :
  1987. savesize:=612;
  1988. ft_typed,
  1989. ft_untyped :
  1990. savesize:=352;
  1991. end;
  1992. {$else cpu64bit}
  1993. case filetyp of
  1994. ft_text :
  1995. savesize:=576;
  1996. ft_typed,
  1997. ft_untyped :
  1998. savesize:=316;
  1999. end;
  2000. {$endif cpu64bit}
  2001. end;
  2002. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  2003. begin
  2004. inherited ppuwritedef(ppufile);
  2005. ppufile.putbyte(byte(filetyp));
  2006. if filetyp=ft_typed then
  2007. ppufile.puttype(typedfiletype);
  2008. ppufile.writeentry(ibfiledef);
  2009. end;
  2010. {$ifdef GDB}
  2011. function tfiledef.stabstring : pchar;
  2012. begin
  2013. {$IfDef GDBknowsfiles}
  2014. case filetyp of
  2015. ft_typed :
  2016. stabstring := strpnew('d'+typedfiletype.def.numberstring{+';'});
  2017. ft_untyped :
  2018. stabstring := strpnew('d'+voiddef.numberstring{+';'});
  2019. ft_text :
  2020. stabstring := strpnew('d'+cchartype^.numberstring{+';'});
  2021. end;
  2022. {$Else}
  2023. {$ifdef cpu64bit}
  2024. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$2,64,64;'+
  2025. '_PRIVATE:ar$1;1;64;$3,128,256;USERDATA:ar$1;1;16;$3,384,128;'+
  2026. 'NAME:ar$1;0;255;$4,512,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2027. tstoreddef(s64inttype.def).numberstring,
  2028. tstoreddef(u8inttype.def).numberstring,
  2029. tstoreddef(cchartype.def).numberstring]);
  2030. {$else cpu64bit}
  2031. stabstring:=stabstr_evaluate('s${savesize}HANDLE:$1,0,32;MODE:$1,32,32;RECSIZE:$1,64,32;'+
  2032. '_PRIVATE:ar$1;1;32;$3,96,256;USERDATA:ar$1;1;16;$2,352,128;'+
  2033. 'NAME:ar$1;0;255;$3,480,2048;;',[tstoreddef(s32inttype.def).numberstring,
  2034. tstoreddef(u8inttype.def).numberstring,
  2035. tstoreddef(cchartype.def).numberstring]);
  2036. {$endif cpu64bit}
  2037. {$EndIf}
  2038. end;
  2039. procedure tfiledef.concatstabto(asmlist:taasmoutput);
  2040. begin
  2041. if (stab_state in [stab_state_writing,stab_state_written]) then
  2042. exit;
  2043. {$IfDef GDBknowsfiles}
  2044. case filetyp of
  2045. ft_typed :
  2046. tstoreddef(typedfiletype.def).concatstabto(asmlist);
  2047. ft_untyped :
  2048. tstoreddef(voidtype.def).concatstabto(asmlist);
  2049. ft_text :
  2050. tstoreddef(cchartype.def).concatstabto(asmlist);
  2051. end;
  2052. {$Else}
  2053. tstoreddef(s32inttype.def).concatstabto(asmlist);
  2054. {$ifdef cpu64bit}
  2055. tstoreddef(s64inttype.def).concatstabto(asmlist);
  2056. {$endif cpu64bit}
  2057. tstoreddef(u8inttype.def).concatstabto(asmlist);
  2058. tstoreddef(cchartype.def).concatstabto(asmlist);
  2059. {$EndIf}
  2060. inherited concatstabto(asmlist);
  2061. end;
  2062. {$endif GDB}
  2063. function tfiledef.gettypename : string;
  2064. begin
  2065. case filetyp of
  2066. ft_untyped:
  2067. gettypename:='File';
  2068. ft_typed:
  2069. gettypename:='File Of '+typedfiletype.def.typename;
  2070. ft_text:
  2071. gettypename:='Text'
  2072. end;
  2073. end;
  2074. function tfiledef.getmangledparaname : string;
  2075. begin
  2076. case filetyp of
  2077. ft_untyped:
  2078. getmangledparaname:='FILE';
  2079. ft_typed:
  2080. getmangledparaname:='FILE$OF$'+typedfiletype.def.mangledparaname;
  2081. ft_text:
  2082. getmangledparaname:='TEXT'
  2083. end;
  2084. end;
  2085. {****************************************************************************
  2086. TVARIANTDEF
  2087. ****************************************************************************}
  2088. constructor tvariantdef.create(v : tvarianttype);
  2089. begin
  2090. inherited create;
  2091. varianttype:=v;
  2092. deftype:=variantdef;
  2093. setsize;
  2094. end;
  2095. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  2096. begin
  2097. inherited ppuloaddef(ppufile);
  2098. varianttype:=tvarianttype(ppufile.getbyte);
  2099. deftype:=variantdef;
  2100. setsize;
  2101. end;
  2102. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  2103. begin
  2104. inherited ppuwritedef(ppufile);
  2105. ppufile.putbyte(byte(varianttype));
  2106. ppufile.writeentry(ibvariantdef);
  2107. end;
  2108. procedure tvariantdef.setsize;
  2109. begin
  2110. savesize:=16;
  2111. end;
  2112. function tvariantdef.gettypename : string;
  2113. begin
  2114. case varianttype of
  2115. vt_normalvariant:
  2116. gettypename:='Variant';
  2117. vt_olevariant:
  2118. gettypename:='OleVariant';
  2119. end;
  2120. end;
  2121. procedure tvariantdef.write_rtti_data(rt:trttitype);
  2122. begin
  2123. rttiList.concat(Tai_const.Create_8bit(tkVariant));
  2124. end;
  2125. function tvariantdef.needs_inittable : boolean;
  2126. begin
  2127. needs_inittable:=true;
  2128. end;
  2129. {$ifdef GDB}
  2130. function tvariantdef.stabstring : pchar;
  2131. begin
  2132. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2133. end;
  2134. function tvariantdef.numberstring:string;
  2135. begin
  2136. result:=tstoreddef(voidtype.def).numberstring;
  2137. end;
  2138. procedure tvariantdef.concatstabto(asmlist : taasmoutput);
  2139. begin
  2140. { don't know how to handle this }
  2141. end;
  2142. {$endif GDB}
  2143. {****************************************************************************
  2144. TPOINTERDEF
  2145. ****************************************************************************}
  2146. constructor tpointerdef.create(const tt : ttype);
  2147. begin
  2148. inherited create;
  2149. deftype:=pointerdef;
  2150. pointertype:=tt;
  2151. is_far:=false;
  2152. savesize:=sizeof(aint);
  2153. end;
  2154. constructor tpointerdef.createfar(const tt : ttype);
  2155. begin
  2156. inherited create;
  2157. deftype:=pointerdef;
  2158. pointertype:=tt;
  2159. is_far:=true;
  2160. savesize:=sizeof(aint);
  2161. end;
  2162. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  2163. begin
  2164. inherited ppuloaddef(ppufile);
  2165. deftype:=pointerdef;
  2166. ppufile.gettype(pointertype);
  2167. is_far:=(ppufile.getbyte<>0);
  2168. savesize:=sizeof(aint);
  2169. end;
  2170. function tpointerdef.getcopy : tstoreddef;
  2171. begin
  2172. result:=tpointerdef.create(pointertype);
  2173. tpointerdef(result).is_far:=is_far;
  2174. tpointerdef(result).savesize:=savesize;
  2175. end;
  2176. procedure tpointerdef.buildderef;
  2177. begin
  2178. inherited buildderef;
  2179. pointertype.buildderef;
  2180. end;
  2181. procedure tpointerdef.deref;
  2182. begin
  2183. inherited deref;
  2184. pointertype.resolve;
  2185. end;
  2186. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  2187. begin
  2188. inherited ppuwritedef(ppufile);
  2189. ppufile.puttype(pointertype);
  2190. ppufile.putbyte(byte(is_far));
  2191. ppufile.writeentry(ibpointerdef);
  2192. end;
  2193. {$ifdef GDB}
  2194. function tpointerdef.stabstring : pchar;
  2195. begin
  2196. stabstring := strpnew('*'+tstoreddef(pointertype.def).numberstring);
  2197. end;
  2198. procedure tpointerdef.concatstabto(asmlist : taasmoutput);
  2199. var st,nb : string;
  2200. begin
  2201. if (stab_state in [stab_state_writing,stab_state_written]) then
  2202. exit;
  2203. stab_state:=stab_state_writing;
  2204. tstoreddef(pointertype.def).concatstabto(asmlist);
  2205. if (pointertype.def.deftype in [recorddef,objectdef]) then
  2206. begin
  2207. if pointertype.def.deftype=objectdef then
  2208. nb:=tobjectdef(pointertype.def).classnumberstring
  2209. else
  2210. nb:=tstoreddef(pointertype.def).numberstring;
  2211. {to avoid infinite recursion in record with next-like fields }
  2212. if tstoreddef(pointertype.def).stab_state=stab_state_writing then
  2213. begin
  2214. if assigned(pointertype.def.typesym) then
  2215. begin
  2216. if assigned(typesym) then
  2217. st := ttypesym(typesym).name
  2218. else
  2219. st := ' ';
  2220. asmlist.concat(Tai_stabs.create(stabstr_evaluate(
  2221. '"$1:t${numberstring}=*$2=xs$3:",${N_LSYM},0,0,0',
  2222. [st,nb,pointertype.def.typesym.name])));
  2223. end;
  2224. stab_state:=stab_state_written;
  2225. end
  2226. else
  2227. begin
  2228. stab_state:=stab_state_used;
  2229. inherited concatstabto(asmlist);
  2230. end;
  2231. end
  2232. else
  2233. begin
  2234. stab_state:=stab_state_used;
  2235. inherited concatstabto(asmlist);
  2236. end;
  2237. end;
  2238. {$endif GDB}
  2239. function tpointerdef.gettypename : string;
  2240. begin
  2241. if is_far then
  2242. gettypename:='^'+pointertype.def.typename+';far'
  2243. else
  2244. gettypename:='^'+pointertype.def.typename;
  2245. end;
  2246. {****************************************************************************
  2247. TCLASSREFDEF
  2248. ****************************************************************************}
  2249. constructor tclassrefdef.create(const t:ttype);
  2250. begin
  2251. inherited create(t);
  2252. deftype:=classrefdef;
  2253. end;
  2254. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  2255. begin
  2256. { be careful, tclassdefref inherits from tpointerdef }
  2257. inherited ppuloaddef(ppufile);
  2258. deftype:=classrefdef;
  2259. ppufile.gettype(pointertype);
  2260. is_far:=false;
  2261. savesize:=sizeof(aint);
  2262. end;
  2263. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  2264. begin
  2265. { be careful, tclassdefref inherits from tpointerdef }
  2266. inherited ppuwritedef(ppufile);
  2267. ppufile.puttype(pointertype);
  2268. ppufile.writeentry(ibclassrefdef);
  2269. end;
  2270. {$ifdef GDB}
  2271. function tclassrefdef.stabstring : pchar;
  2272. begin
  2273. stabstring:=strpnew(tstoreddef(pvmttype.def).numberstring);
  2274. end;
  2275. {$endif GDB}
  2276. function tclassrefdef.gettypename : string;
  2277. begin
  2278. gettypename:='Class Of '+pointertype.def.typename;
  2279. end;
  2280. {***************************************************************************
  2281. TSETDEF
  2282. ***************************************************************************}
  2283. constructor tsetdef.create(const t:ttype;high : longint);
  2284. begin
  2285. inherited create;
  2286. deftype:=setdef;
  2287. elementtype:=t;
  2288. if high<32 then
  2289. begin
  2290. settype:=smallset;
  2291. {$ifdef testvarsets}
  2292. if aktsetalloc=0 THEN { $PACKSET Fixed?}
  2293. {$endif}
  2294. savesize:=Sizeof(longint)
  2295. {$ifdef testvarsets}
  2296. else {No, use $PACKSET VALUE for rounding}
  2297. savesize:=aktsetalloc*((high+aktsetalloc*8-1) DIV (aktsetalloc*8))
  2298. {$endif}
  2299. ;
  2300. end
  2301. else
  2302. if high<256 then
  2303. begin
  2304. settype:=normset;
  2305. savesize:=32;
  2306. end
  2307. else
  2308. {$ifdef testvarsets}
  2309. if high<$10000 then
  2310. begin
  2311. settype:=varset;
  2312. savesize:=4*((high+31) div 32);
  2313. end
  2314. else
  2315. {$endif testvarsets}
  2316. Message(sym_e_ill_type_decl_set);
  2317. end;
  2318. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2319. begin
  2320. inherited ppuloaddef(ppufile);
  2321. deftype:=setdef;
  2322. ppufile.gettype(elementtype);
  2323. settype:=tsettype(ppufile.getbyte);
  2324. case settype of
  2325. normset : savesize:=32;
  2326. varset : savesize:=ppufile.getlongint;
  2327. smallset : savesize:=Sizeof(longint);
  2328. end;
  2329. end;
  2330. destructor tsetdef.destroy;
  2331. begin
  2332. inherited destroy;
  2333. end;
  2334. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2335. begin
  2336. inherited ppuwritedef(ppufile);
  2337. ppufile.puttype(elementtype);
  2338. ppufile.putbyte(byte(settype));
  2339. if settype=varset then
  2340. ppufile.putlongint(savesize);
  2341. ppufile.writeentry(ibsetdef);
  2342. end;
  2343. {$ifdef GDB}
  2344. function tsetdef.stabstring : pchar;
  2345. begin
  2346. stabstring:=stabstr_evaluate('@s$1;S$2',[tostr(savesize*8),tstoreddef(elementtype.def).numberstring]);
  2347. end;
  2348. procedure tsetdef.concatstabto(asmlist:taasmoutput);
  2349. begin
  2350. if (stab_state in [stab_state_writing,stab_state_written]) then
  2351. exit;
  2352. tstoreddef(elementtype.def).concatstabto(asmlist);
  2353. inherited concatstabto(asmlist);
  2354. end;
  2355. {$endif GDB}
  2356. procedure tsetdef.buildderef;
  2357. begin
  2358. inherited buildderef;
  2359. elementtype.buildderef;
  2360. end;
  2361. procedure tsetdef.deref;
  2362. begin
  2363. inherited deref;
  2364. elementtype.resolve;
  2365. end;
  2366. procedure tsetdef.write_child_rtti_data(rt:trttitype);
  2367. begin
  2368. tstoreddef(elementtype.def).get_rtti_label(rt);
  2369. end;
  2370. procedure tsetdef.write_rtti_data(rt:trttitype);
  2371. begin
  2372. rttiList.concat(Tai_const.Create_8bit(tkSet));
  2373. write_rtti_name;
  2374. rttiList.concat(Tai_const.Create_8bit(otULong));
  2375. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2376. end;
  2377. function tsetdef.is_publishable : boolean;
  2378. begin
  2379. is_publishable:=(settype=smallset);
  2380. end;
  2381. function tsetdef.gettypename : string;
  2382. begin
  2383. if assigned(elementtype.def) then
  2384. gettypename:='Set Of '+elementtype.def.typename
  2385. else
  2386. gettypename:='Empty Set';
  2387. end;
  2388. {***************************************************************************
  2389. TFORMALDEF
  2390. ***************************************************************************}
  2391. constructor tformaldef.create;
  2392. var
  2393. stregdef : boolean;
  2394. begin
  2395. stregdef:=registerdef;
  2396. registerdef:=false;
  2397. inherited create;
  2398. deftype:=formaldef;
  2399. registerdef:=stregdef;
  2400. { formaldef must be registered at unit level !! }
  2401. if registerdef and assigned(current_module) then
  2402. if assigned(current_module.localsymtable) then
  2403. tsymtable(current_module.localsymtable).registerdef(self)
  2404. else if assigned(current_module.globalsymtable) then
  2405. tsymtable(current_module.globalsymtable).registerdef(self);
  2406. savesize:=0;
  2407. end;
  2408. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2409. begin
  2410. inherited ppuloaddef(ppufile);
  2411. deftype:=formaldef;
  2412. savesize:=0;
  2413. end;
  2414. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2415. begin
  2416. inherited ppuwritedef(ppufile);
  2417. ppufile.writeentry(ibformaldef);
  2418. end;
  2419. {$ifdef GDB}
  2420. function tformaldef.stabstring : pchar;
  2421. begin
  2422. stabstring:=stabstr_evaluate('formal${numberstring};',[]);
  2423. end;
  2424. function tformaldef.numberstring:string;
  2425. begin
  2426. result:=tstoreddef(voidtype.def).numberstring;
  2427. end;
  2428. procedure tformaldef.concatstabto(asmlist : taasmoutput);
  2429. begin
  2430. { formaldef can't be stab'ed !}
  2431. end;
  2432. {$endif GDB}
  2433. function tformaldef.gettypename : string;
  2434. begin
  2435. gettypename:='<Formal type>';
  2436. end;
  2437. {***************************************************************************
  2438. TARRAYDEF
  2439. ***************************************************************************}
  2440. constructor tarraydef.create(l,h : aint;const t : ttype);
  2441. begin
  2442. inherited create;
  2443. deftype:=arraydef;
  2444. lowrange:=l;
  2445. highrange:=h;
  2446. rangetype:=t;
  2447. elementtype.reset;
  2448. IsVariant:=false;
  2449. IsConstructor:=false;
  2450. IsArrayOfConst:=false;
  2451. IsDynamicArray:=false;
  2452. IsConvertedPointer:=false;
  2453. end;
  2454. constructor tarraydef.create_from_pointer(const elemt : ttype);
  2455. begin
  2456. self.create(0,$7fffffff,s32inttype);
  2457. IsConvertedPointer:=true;
  2458. setelementtype(elemt);
  2459. end;
  2460. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2461. begin
  2462. inherited ppuloaddef(ppufile);
  2463. deftype:=arraydef;
  2464. { the addresses are calculated later }
  2465. ppufile.gettype(_elementtype);
  2466. ppufile.gettype(rangetype);
  2467. lowrange:=ppufile.getaint;
  2468. highrange:=ppufile.getaint;
  2469. IsArrayOfConst:=boolean(ppufile.getbyte);
  2470. IsDynamicArray:=boolean(ppufile.getbyte);
  2471. IsVariant:=false;
  2472. IsConstructor:=false;
  2473. end;
  2474. procedure tarraydef.buildderef;
  2475. begin
  2476. inherited buildderef;
  2477. _elementtype.buildderef;
  2478. rangetype.buildderef;
  2479. end;
  2480. procedure tarraydef.deref;
  2481. begin
  2482. inherited deref;
  2483. _elementtype.resolve;
  2484. rangetype.resolve;
  2485. end;
  2486. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2487. begin
  2488. inherited ppuwritedef(ppufile);
  2489. ppufile.puttype(_elementtype);
  2490. ppufile.puttype(rangetype);
  2491. ppufile.putaint(lowrange);
  2492. ppufile.putaint(highrange);
  2493. ppufile.putbyte(byte(IsArrayOfConst));
  2494. ppufile.putbyte(byte(IsDynamicArray));
  2495. ppufile.writeentry(ibarraydef);
  2496. end;
  2497. {$ifdef GDB}
  2498. function tarraydef.stabstring : pchar;
  2499. begin
  2500. stabstring:=stabstr_evaluate('ar$1;$2;$3;$4',[Tstoreddef(rangetype.def).numberstring,
  2501. tostr(lowrange),tostr(highrange),Tstoreddef(_elementtype.def).numberstring]);
  2502. end;
  2503. procedure tarraydef.concatstabto(asmlist:taasmoutput);
  2504. begin
  2505. if (stab_state in [stab_state_writing,stab_state_written]) then
  2506. exit;
  2507. tstoreddef(rangetype.def).concatstabto(asmlist);
  2508. tstoreddef(_elementtype.def).concatstabto(asmlist);
  2509. inherited concatstabto(asmlist);
  2510. end;
  2511. {$endif GDB}
  2512. function tarraydef.elesize : aint;
  2513. begin
  2514. elesize:=_elementtype.def.size;
  2515. end;
  2516. function tarraydef.elecount : aint;
  2517. var
  2518. qhigh,qlow : qword;
  2519. begin
  2520. if IsDynamicArray then
  2521. begin
  2522. result:=0;
  2523. exit;
  2524. end;
  2525. if (highrange>0) and (lowrange<0) then
  2526. begin
  2527. qhigh:=highrange;
  2528. qlow:=qword(-lowrange);
  2529. { prevent overflow, return -1 to indicate overflow }
  2530. if qhigh+qlow>qword(high(aint)-1) then
  2531. result:=-1
  2532. else
  2533. result:=qhigh+qlow+1;
  2534. end
  2535. else
  2536. result:=int64(highrange)-lowrange+1;
  2537. end;
  2538. function tarraydef.size : aint;
  2539. var
  2540. cachedelecount,
  2541. cachedelesize : aint;
  2542. begin
  2543. if IsDynamicArray then
  2544. begin
  2545. size:=sizeof(aint);
  2546. exit;
  2547. end;
  2548. { Tarraydef.size may never be called for an open array! }
  2549. if highrange<lowrange then
  2550. internalerror(99080501);
  2551. cachedelesize:=elesize;
  2552. cachedelecount:=elecount;
  2553. { prevent overflow, return -1 to indicate overflow }
  2554. if (cachedelesize <> 0) and
  2555. (
  2556. (cachedelecount < 0) or
  2557. ((high(aint) div cachedelesize) < cachedelecount) or
  2558. { also lowrange*elesize must be < high(aint) to prevent overflow when
  2559. accessing the array, see ncgmem (PFV) }
  2560. ((high(aint) div cachedelesize) < abs(lowrange))
  2561. ) then
  2562. result:=-1
  2563. else
  2564. result:=cachedelesize*cachedelecount;
  2565. end;
  2566. procedure tarraydef.setelementtype(t: ttype);
  2567. begin
  2568. _elementtype:=t;
  2569. if not(IsDynamicArray or
  2570. IsConvertedPointer or
  2571. (highrange<lowrange)) then
  2572. begin
  2573. if (size=-1) then
  2574. Message(sym_e_segment_too_large);
  2575. end;
  2576. end;
  2577. function tarraydef.alignment : longint;
  2578. begin
  2579. { alignment is the size of the elements }
  2580. if elementtype.def.deftype=recorddef then
  2581. alignment:=elementtype.def.alignment
  2582. else
  2583. alignment:=elesize;
  2584. end;
  2585. function tarraydef.needs_inittable : boolean;
  2586. begin
  2587. needs_inittable:=IsDynamicArray or elementtype.def.needs_inittable;
  2588. end;
  2589. procedure tarraydef.write_child_rtti_data(rt:trttitype);
  2590. begin
  2591. tstoreddef(elementtype.def).get_rtti_label(rt);
  2592. end;
  2593. procedure tarraydef.write_rtti_data(rt:trttitype);
  2594. begin
  2595. if IsDynamicArray then
  2596. rttiList.concat(Tai_const.Create_8bit(tkdynarray))
  2597. else
  2598. rttiList.concat(Tai_const.Create_8bit(tkarray));
  2599. write_rtti_name;
  2600. {$ifdef cpurequiresproperalignment}
  2601. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2602. {$endif cpurequiresproperalignment}
  2603. { size of elements }
  2604. rttiList.concat(Tai_const.Create_aint(elesize));
  2605. if not(IsDynamicArray) then
  2606. rttiList.concat(Tai_const.Create_aint(elecount));
  2607. { element type }
  2608. rttiList.concat(Tai_const.Create_sym(tstoreddef(elementtype.def).get_rtti_label(rt)));
  2609. { variant type }
  2610. // !!!!!!!!!!!!!!!!
  2611. end;
  2612. function tarraydef.gettypename : string;
  2613. begin
  2614. if isarrayofconst or isConstructor then
  2615. begin
  2616. if isvariant or ((highrange=-1) and (lowrange=0)) then
  2617. gettypename:='Array Of Const'
  2618. else
  2619. gettypename:='Array Of '+elementtype.def.typename;
  2620. end
  2621. else if ((highrange=-1) and (lowrange=0)) or IsDynamicArray then
  2622. gettypename:='Array Of '+elementtype.def.typename
  2623. else
  2624. begin
  2625. if rangetype.def.deftype=enumdef then
  2626. gettypename:='Array['+rangetype.def.typename+'] Of '+elementtype.def.typename
  2627. else
  2628. gettypename:='Array['+tostr(lowrange)+'..'+
  2629. tostr(highrange)+'] Of '+elementtype.def.typename
  2630. end;
  2631. end;
  2632. function tarraydef.getmangledparaname : string;
  2633. begin
  2634. if isarrayofconst then
  2635. getmangledparaname:='array_of_const'
  2636. else
  2637. if ((highrange=-1) and (lowrange=0)) then
  2638. getmangledparaname:='array_of_'+elementtype.def.mangledparaname
  2639. else
  2640. internalerror(200204176);
  2641. end;
  2642. {***************************************************************************
  2643. tabstractrecorddef
  2644. ***************************************************************************}
  2645. function tabstractrecorddef.getsymtable(t:tgetsymtable):tsymtable;
  2646. begin
  2647. if t=gs_record then
  2648. getsymtable:=symtable
  2649. else
  2650. getsymtable:=nil;
  2651. end;
  2652. {$ifdef GDB}
  2653. procedure tabstractrecorddef.field_addname(p:Tnamedindexitem;arg:pointer);
  2654. var
  2655. newrec:Pchar;
  2656. spec:string[3];
  2657. varsize : aint;
  2658. state : ^Trecord_stabgen_state;
  2659. begin
  2660. state:=arg;
  2661. { static variables from objects are like global objects }
  2662. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2663. begin
  2664. if (sp_protected in tsym(p).symoptions) then
  2665. spec:='/1'
  2666. else if (sp_private in tsym(p).symoptions) then
  2667. spec:='/0'
  2668. else
  2669. spec:='';
  2670. varsize:=tvarsym(p).vartype.def.size;
  2671. { open arrays made overflows !! }
  2672. if varsize>$fffffff then
  2673. varsize:=$fffffff;
  2674. newrec:=stabstr_evaluate('$1:$2,$3,$4;',[p.name,
  2675. spec+tstoreddef(tvarsym(p).vartype.def).numberstring,
  2676. tostr(tvarsym(p).fieldoffset*8),tostr(varsize*8)]);
  2677. if state^.stabsize+strlen(newrec)>=state^.staballoc-256 then
  2678. begin
  2679. inc(state^.staballoc,memsizeinc);
  2680. reallocmem(state^.stabstring,state^.staballoc);
  2681. end;
  2682. strcopy(state^.stabstring+state^.stabsize,newrec);
  2683. inc(state^.stabsize,strlen(newrec));
  2684. strdispose(newrec);
  2685. {This should be used for case !!}
  2686. inc(state^.recoffset,Tvarsym(p).vartype.def.size);
  2687. end;
  2688. end;
  2689. procedure tabstractrecorddef.field_concatstabto(p:Tnamedindexitem;arg:pointer);
  2690. begin
  2691. if (Tsym(p).typ=varsym) and not (sp_static in Tsym(p).symoptions) then
  2692. tstoreddef(tvarsym(p).vartype.def).concatstabto(taasmoutput(arg));
  2693. end;
  2694. {$endif GDB}
  2695. procedure tabstractrecorddef.count_field_rtti(sym : tnamedindexitem;arg:pointer);
  2696. begin
  2697. if (FRTTIType=fullrtti) or
  2698. ((tsym(sym).typ=varsym) and
  2699. tvarsym(sym).vartype.def.needs_inittable) then
  2700. inc(Count);
  2701. end;
  2702. procedure tabstractrecorddef.generate_field_rtti(sym:tnamedindexitem;arg:pointer);
  2703. begin
  2704. if (FRTTIType=fullrtti) or
  2705. ((tsym(sym).typ=varsym) and
  2706. tvarsym(sym).vartype.def.needs_inittable) then
  2707. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType);
  2708. end;
  2709. procedure tabstractrecorddef.write_field_rtti(sym : tnamedindexitem;arg:pointer);
  2710. begin
  2711. if (FRTTIType=fullrtti) or
  2712. ((tsym(sym).typ=varsym) and
  2713. tvarsym(sym).vartype.def.needs_inittable) then
  2714. begin
  2715. rttiList.concat(Tai_const.Create_sym(tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(FRTTIType)));
  2716. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  2717. end;
  2718. end;
  2719. {***************************************************************************
  2720. trecorddef
  2721. ***************************************************************************}
  2722. constructor trecorddef.create(p : tsymtable);
  2723. begin
  2724. inherited create;
  2725. deftype:=recorddef;
  2726. symtable:=p;
  2727. symtable.defowner:=self;
  2728. isunion:=false;
  2729. end;
  2730. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2731. begin
  2732. inherited ppuloaddef(ppufile);
  2733. deftype:=recorddef;
  2734. symtable:=trecordsymtable.create(0);
  2735. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2736. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2737. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2738. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2739. trecordsymtable(symtable).ppuload(ppufile);
  2740. symtable.defowner:=self;
  2741. isunion:=false;
  2742. end;
  2743. destructor trecorddef.destroy;
  2744. begin
  2745. if assigned(symtable) then
  2746. symtable.free;
  2747. inherited destroy;
  2748. end;
  2749. function trecorddef.needs_inittable : boolean;
  2750. begin
  2751. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2752. end;
  2753. procedure trecorddef.buildderef;
  2754. var
  2755. oldrecsyms : tsymtable;
  2756. begin
  2757. inherited buildderef;
  2758. oldrecsyms:=aktrecordsymtable;
  2759. aktrecordsymtable:=symtable;
  2760. { now build the definitions }
  2761. tstoredsymtable(symtable).buildderef;
  2762. aktrecordsymtable:=oldrecsyms;
  2763. end;
  2764. procedure trecorddef.deref;
  2765. var
  2766. oldrecsyms : tsymtable;
  2767. begin
  2768. inherited deref;
  2769. oldrecsyms:=aktrecordsymtable;
  2770. aktrecordsymtable:=symtable;
  2771. { now dereference the definitions }
  2772. tstoredsymtable(symtable).deref;
  2773. aktrecordsymtable:=oldrecsyms;
  2774. { assign TGUID? load only from system unit (unitid=1) }
  2775. if not(assigned(rec_tguid)) and
  2776. (upper(typename)='TGUID') and
  2777. assigned(owner) and
  2778. assigned(owner.name) and
  2779. (owner.name^='SYSTEM') then
  2780. rec_tguid:=self;
  2781. end;
  2782. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2783. begin
  2784. inherited ppuwritedef(ppufile);
  2785. ppufile.putaint(trecordsymtable(symtable).datasize);
  2786. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2787. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2788. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2789. ppufile.writeentry(ibrecorddef);
  2790. trecordsymtable(symtable).ppuwrite(ppufile);
  2791. end;
  2792. function trecorddef.size:aint;
  2793. begin
  2794. result:=trecordsymtable(symtable).datasize;
  2795. end;
  2796. function trecorddef.alignment:longint;
  2797. begin
  2798. alignment:=trecordsymtable(symtable).recordalignment;
  2799. end;
  2800. function trecorddef.padalignment:longint;
  2801. begin
  2802. padalignment := trecordsymtable(symtable).padalignment;
  2803. end;
  2804. {$ifdef GDB}
  2805. function trecorddef.stabstring : pchar;
  2806. var
  2807. state:Trecord_stabgen_state;
  2808. begin
  2809. getmem(state.stabstring,memsizeinc);
  2810. state.staballoc:=memsizeinc;
  2811. strpcopy(state.stabstring,'s'+tostr(size));
  2812. state.recoffset:=0;
  2813. state.stabsize:=strlen(state.stabstring);
  2814. symtable.foreach(@field_addname,@state);
  2815. state.stabstring[state.stabsize]:=';';
  2816. state.stabstring[state.stabsize+1]:=#0;
  2817. reallocmem(state.stabstring,state.stabsize+2);
  2818. stabstring:=state.stabstring;
  2819. end;
  2820. procedure trecorddef.concatstabto(asmlist:taasmoutput);
  2821. begin
  2822. if (stab_state in [stab_state_writing,stab_state_written]) then
  2823. exit;
  2824. symtable.foreach(@field_concatstabto,asmlist);
  2825. inherited concatstabto(asmlist);
  2826. end;
  2827. {$endif GDB}
  2828. procedure trecorddef.write_child_rtti_data(rt:trttitype);
  2829. begin
  2830. FRTTIType:=rt;
  2831. symtable.foreach(@generate_field_rtti,nil);
  2832. end;
  2833. procedure trecorddef.write_rtti_data(rt:trttitype);
  2834. begin
  2835. rttiList.concat(Tai_const.Create_8bit(tkrecord));
  2836. write_rtti_name;
  2837. {$ifdef cpurequiresproperalignment}
  2838. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  2839. {$endif cpurequiresproperalignment}
  2840. rttiList.concat(Tai_const.Create_32bit(size));
  2841. Count:=0;
  2842. FRTTIType:=rt;
  2843. symtable.foreach(@count_field_rtti,nil);
  2844. rttiList.concat(Tai_const.Create_32bit(Count));
  2845. symtable.foreach(@write_field_rtti,nil);
  2846. end;
  2847. function trecorddef.gettypename : string;
  2848. begin
  2849. gettypename:='<record type>'
  2850. end;
  2851. {***************************************************************************
  2852. TABSTRACTPROCDEF
  2853. ***************************************************************************}
  2854. constructor tabstractprocdef.create(level:byte);
  2855. begin
  2856. inherited create;
  2857. parast:=tparasymtable.create(level);
  2858. parast.defowner:=self;
  2859. parast.next:=owner;
  2860. para:=TLinkedList.Create;
  2861. minparacount:=0;
  2862. maxparacount:=0;
  2863. proctypeoption:=potype_none;
  2864. proccalloption:=pocall_none;
  2865. procoptions:=[];
  2866. rettype:=voidtype;
  2867. {$ifdef i386}
  2868. fpu_used:=0;
  2869. {$endif i386}
  2870. savesize:=sizeof(aint);
  2871. requiredargarea:=0;
  2872. has_paraloc_info:=false;
  2873. funcret_paraloc[callerside].init;
  2874. funcret_paraloc[calleeside].init;
  2875. end;
  2876. destructor tabstractprocdef.destroy;
  2877. begin
  2878. if assigned(para) then
  2879. begin
  2880. {$ifdef MEMDEBUG}
  2881. memprocpara.start;
  2882. {$endif MEMDEBUG}
  2883. para.free;
  2884. {$ifdef MEMDEBUG}
  2885. memprocpara.stop;
  2886. {$endif MEMDEBUG}
  2887. end;
  2888. if assigned(parast) then
  2889. begin
  2890. {$ifdef MEMDEBUG}
  2891. memprocparast.start;
  2892. {$endif MEMDEBUG}
  2893. parast.free;
  2894. {$ifdef MEMDEBUG}
  2895. memprocparast.stop;
  2896. {$endif MEMDEBUG}
  2897. end;
  2898. funcret_paraloc[callerside].done;
  2899. funcret_paraloc[calleeside].done;
  2900. inherited destroy;
  2901. end;
  2902. procedure tabstractprocdef.releasemem;
  2903. begin
  2904. para.free;
  2905. para:=nil;
  2906. parast.free;
  2907. parast:=nil;
  2908. end;
  2909. function tabstractprocdef.concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2910. var
  2911. hp : TParaItem;
  2912. begin
  2913. hp:=TParaItem.Create;
  2914. hp.paratyp:=tvarsym(sym).varspez;
  2915. hp.parasym:=sym;
  2916. hp.paratype:=tt;
  2917. hp.is_hidden:=vhidden;
  2918. hp.defaultvalue:=defval;
  2919. { Parameters are stored from left to right }
  2920. if assigned(afterpara) then
  2921. Para.insertafter(hp,afterpara)
  2922. else
  2923. Para.concat(hp);
  2924. { Don't count hidden parameters }
  2925. if not vhidden then
  2926. begin
  2927. if not assigned(defval) then
  2928. inc(minparacount);
  2929. inc(maxparacount);
  2930. end;
  2931. concatpara:=hp;
  2932. end;
  2933. function tabstractprocdef.insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2934. var
  2935. hp : TParaItem;
  2936. begin
  2937. hp:=TParaItem.Create;
  2938. hp.paratyp:=tvarsym(sym).varspez;
  2939. hp.parasym:=sym;
  2940. hp.paratype:=tt;
  2941. hp.is_hidden:=vhidden;
  2942. hp.defaultvalue:=defval;
  2943. { Parameters are stored from left to right }
  2944. Para.insert(hp);
  2945. { Don't count hidden parameters }
  2946. if (not vhidden) then
  2947. begin
  2948. if not assigned(defval) then
  2949. inc(minparacount);
  2950. inc(maxparacount);
  2951. end;
  2952. insertpara:=hp;
  2953. end;
  2954. procedure tabstractprocdef.removepara(currpara:tparaitem);
  2955. begin
  2956. { Don't count hidden parameters }
  2957. if (not currpara.is_hidden) then
  2958. begin
  2959. if not assigned(currpara.defaultvalue) then
  2960. dec(minparacount);
  2961. dec(maxparacount);
  2962. end;
  2963. Para.Remove(currpara);
  2964. currpara.free;
  2965. end;
  2966. { all functions returning in FPU are
  2967. assume to use 2 FPU registers
  2968. until the function implementation
  2969. is processed PM }
  2970. procedure tabstractprocdef.test_if_fpu_result;
  2971. begin
  2972. {$ifdef i386}
  2973. if assigned(rettype.def) and
  2974. (rettype.def.deftype=floatdef) then
  2975. fpu_used:=maxfpuregs;
  2976. {$endif i386}
  2977. end;
  2978. procedure tabstractprocdef.buildderef;
  2979. var
  2980. hp : TParaItem;
  2981. begin
  2982. { released procdef? }
  2983. if not assigned(parast) then
  2984. exit;
  2985. inherited buildderef;
  2986. rettype.buildderef;
  2987. { parast }
  2988. tparasymtable(parast).buildderef;
  2989. { paraitems }
  2990. hp:=TParaItem(Para.first);
  2991. while assigned(hp) do
  2992. begin
  2993. hp.paratype.buildderef;
  2994. hp.defaultvaluederef.build(hp.defaultvalue);
  2995. hp.parasymderef.build(hp.parasym);
  2996. hp:=TParaItem(hp.next);
  2997. end;
  2998. end;
  2999. procedure tabstractprocdef.deref;
  3000. var
  3001. hp : TParaItem;
  3002. begin
  3003. inherited deref;
  3004. rettype.resolve;
  3005. { parast }
  3006. tparasymtable(parast).deref;
  3007. { paraitems }
  3008. minparacount:=0;
  3009. maxparacount:=0;
  3010. hp:=TParaItem(Para.first);
  3011. while assigned(hp) do
  3012. begin
  3013. hp.paratype.resolve;
  3014. hp.defaultvalue:=tsym(hp.defaultvaluederef.resolve);
  3015. hp.parasym:=tvarsym(hp.parasymderef.resolve);
  3016. { connect parasym to paraitem }
  3017. tvarsym(hp.parasym).paraitem:=hp;
  3018. { Don't count hidden parameters }
  3019. if (not hp.is_hidden) then
  3020. begin
  3021. if not assigned(hp.defaultvalue) then
  3022. inc(minparacount);
  3023. inc(maxparacount);
  3024. end;
  3025. hp:=TParaItem(hp.next);
  3026. end;
  3027. end;
  3028. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  3029. var
  3030. hp : TParaItem;
  3031. count,i : word;
  3032. begin
  3033. inherited ppuloaddef(ppufile);
  3034. parast:=nil;
  3035. Para:=TLinkedList.Create;
  3036. minparacount:=0;
  3037. maxparacount:=0;
  3038. ppufile.gettype(rettype);
  3039. {$ifdef i386}
  3040. fpu_used:=ppufile.getbyte;
  3041. {$else}
  3042. ppufile.getbyte;
  3043. {$endif i386}
  3044. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3045. proccalloption:=tproccalloption(ppufile.getbyte);
  3046. ppufile.getsmallset(procoptions);
  3047. if po_explicitparaloc in procoptions then
  3048. ppufile.getdata(funcret_paraloc,sizeof(funcret_paraloc));
  3049. { get the number of parameters }
  3050. count:=ppufile.getbyte;
  3051. savesize:=sizeof(aint);
  3052. has_paraloc_info:=false;
  3053. for i:=1 to count do
  3054. begin
  3055. hp:=TParaItem.Create;
  3056. hp.paratyp:=tvarspez(ppufile.getbyte);
  3057. ppufile.gettype(hp.paratype);
  3058. ppufile.getderef(hp.defaultvaluederef);
  3059. hp.defaultvalue:=nil;
  3060. ppufile.getderef(hp.parasymderef);
  3061. hp.parasym:=nil;
  3062. hp.is_hidden:=boolean(ppufile.getbyte);
  3063. if po_explicitparaloc in procoptions then
  3064. begin
  3065. ppufile.getdata(hp.paraloc[callerside].add_location^,sizeof(hp.paraloc[callerside].location^));
  3066. has_paraloc_info:=true;
  3067. end;
  3068. { Parameters are stored left to right in both ppu and memory }
  3069. Para.concat(hp);
  3070. end;
  3071. end;
  3072. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3073. var
  3074. hp : TParaItem;
  3075. oldintfcrc : boolean;
  3076. begin
  3077. { released procdef? }
  3078. if not assigned(parast) then
  3079. exit;
  3080. inherited ppuwritedef(ppufile);
  3081. ppufile.puttype(rettype);
  3082. oldintfcrc:=ppufile.do_interface_crc;
  3083. ppufile.do_interface_crc:=false;
  3084. {$ifdef i386}
  3085. if simplify_ppu then
  3086. fpu_used:=0;
  3087. ppufile.putbyte(fpu_used);
  3088. {$else}
  3089. ppufile.putbyte(0);
  3090. {$endif}
  3091. ppufile.putbyte(ord(proctypeoption));
  3092. ppufile.putbyte(ord(proccalloption));
  3093. ppufile.putsmallset(procoptions);
  3094. ppufile.do_interface_crc:=oldintfcrc;
  3095. if po_explicitparaloc in procoptions then
  3096. ppufile.putdata(funcret_paraloc,sizeof(funcret_paraloc));
  3097. { we need to store the count including vs_hidden }
  3098. ppufile.putbyte(para.count);
  3099. hp:=TParaItem(Para.first);
  3100. while assigned(hp) do
  3101. begin
  3102. ppufile.putbyte(byte(hp.paratyp));
  3103. ppufile.puttype(hp.paratype);
  3104. ppufile.putderef(hp.defaultvaluederef);
  3105. ppufile.putderef(hp.parasymderef);
  3106. ppufile.putbyte(byte(hp.is_hidden));
  3107. if po_explicitparaloc in procoptions then
  3108. begin
  3109. hp.paraloc[callerside].check_simple_location;
  3110. ppufile.putdata(hp.paraloc[callerside].location^,sizeof(hp.paraloc[callerside].location^));
  3111. end;
  3112. hp:=TParaItem(hp.next);
  3113. end;
  3114. end;
  3115. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3116. var
  3117. hs,s : string;
  3118. hp : TParaItem;
  3119. hpc : tconstsym;
  3120. first : boolean;
  3121. begin
  3122. hp:=TParaItem(Para.first);
  3123. s:='';
  3124. first:=true;
  3125. while assigned(hp) do
  3126. begin
  3127. if (not hp.is_hidden) or
  3128. (showhidden) then
  3129. begin
  3130. if first then
  3131. begin
  3132. s:=s+'(';
  3133. first:=false;
  3134. end
  3135. else
  3136. s:=s+',';
  3137. case hp.paratyp of
  3138. vs_var :
  3139. s:=s+'var';
  3140. vs_const :
  3141. s:=s+'const';
  3142. vs_out :
  3143. s:=s+'out';
  3144. end;
  3145. if assigned(hp.paratype.def.typesym) then
  3146. begin
  3147. if s<>'(' then
  3148. s:=s+' ';
  3149. hs:=hp.paratype.def.typesym.realname;
  3150. if hs[1]<>'$' then
  3151. s:=s+hp.paratype.def.typesym.realname
  3152. else
  3153. s:=s+hp.paratype.def.gettypename;
  3154. end
  3155. else
  3156. s:=s+hp.paratype.def.gettypename;
  3157. { default value }
  3158. if assigned(hp.defaultvalue) then
  3159. begin
  3160. hpc:=tconstsym(hp.defaultvalue);
  3161. hs:='';
  3162. case hpc.consttyp of
  3163. conststring,
  3164. constresourcestring :
  3165. hs:=strpas(pchar(hpc.value.valueptr));
  3166. constreal :
  3167. str(pbestreal(hpc.value.valueptr)^,hs);
  3168. constpointer :
  3169. hs:=tostr(hpc.value.valueordptr);
  3170. constord :
  3171. begin
  3172. if is_boolean(hpc.consttype.def) then
  3173. begin
  3174. if hpc.value.valueord<>0 then
  3175. hs:='TRUE'
  3176. else
  3177. hs:='FALSE';
  3178. end
  3179. else
  3180. hs:=tostr(hpc.value.valueord);
  3181. end;
  3182. constnil :
  3183. hs:='nil';
  3184. constset :
  3185. hs:='<set>';
  3186. end;
  3187. if hs<>'' then
  3188. s:=s+'="'+hs+'"';
  3189. end;
  3190. end;
  3191. hp:=TParaItem(hp.next);
  3192. end;
  3193. if not first then
  3194. s:=s+')';
  3195. if (po_varargs in procoptions) then
  3196. s:=s+';VarArgs';
  3197. typename_paras:=s;
  3198. end;
  3199. function tabstractprocdef.is_methodpointer:boolean;
  3200. begin
  3201. result:=false;
  3202. end;
  3203. function tabstractprocdef.is_addressonly:boolean;
  3204. begin
  3205. result:=true;
  3206. end;
  3207. {$ifdef GDB}
  3208. function tabstractprocdef.stabstring : pchar;
  3209. begin
  3210. stabstring := strpnew('abstractproc'+numberstring+';');
  3211. end;
  3212. {$endif GDB}
  3213. {***************************************************************************
  3214. TPROCDEF
  3215. ***************************************************************************}
  3216. constructor tprocdef.create(level:byte);
  3217. begin
  3218. inherited create(level);
  3219. deftype:=procdef;
  3220. has_mangledname:=false;
  3221. _mangledname:=nil;
  3222. fileinfo:=aktfilepos;
  3223. extnumber:=$ffff;
  3224. aliasnames:=tstringlist.create;
  3225. funcretsym:=nil;
  3226. localst := nil;
  3227. defref:=nil;
  3228. lastwritten:=nil;
  3229. refcount:=0;
  3230. if (cs_browser in aktmoduleswitches) and make_ref then
  3231. begin
  3232. defref:=tref.create(defref,@akttokenpos);
  3233. inc(refcount);
  3234. end;
  3235. lastref:=defref;
  3236. forwarddef:=true;
  3237. interfacedef:=false;
  3238. hasforward:=false;
  3239. _class := nil;
  3240. new(inlininginfo);
  3241. fillchar(inlininginfo^,sizeof(tinlininginfo),0);
  3242. overloadnumber:=0;
  3243. {$ifdef GDB}
  3244. isstabwritten := false;
  3245. {$endif GDB}
  3246. end;
  3247. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3248. var
  3249. level : byte;
  3250. begin
  3251. inherited ppuload(ppufile);
  3252. deftype:=procdef;
  3253. has_mangledname:=boolean(ppufile.getbyte);
  3254. if has_mangledname then
  3255. _mangledname:=stringdup(ppufile.getstring)
  3256. else
  3257. _mangledname:=nil;
  3258. overloadnumber:=ppufile.getword;
  3259. extnumber:=ppufile.getword;
  3260. level:=ppufile.getbyte;
  3261. ppufile.getderef(_classderef);
  3262. ppufile.getderef(procsymderef);
  3263. ppufile.getposinfo(fileinfo);
  3264. ppufile.getsmallset(symoptions);
  3265. {$ifdef powerpc}
  3266. { library symbol for AmigaOS/MorphOS }
  3267. ppufile.getderef(libsymderef);
  3268. {$endif powerpc}
  3269. { inline stuff }
  3270. if proccalloption=pocall_inline then
  3271. begin
  3272. ppufile.getderef(funcretsymderef);
  3273. new(inlininginfo);
  3274. ppufile.getsmallset(inlininginfo^.flags);
  3275. inlininginfo^.inlinenode:=boolean(ppufile.getbyte);
  3276. end
  3277. else
  3278. funcretsym:=nil;
  3279. { load para symtable }
  3280. parast:=tparasymtable.create(level);
  3281. tparasymtable(parast).ppuload(ppufile);
  3282. parast.defowner:=self;
  3283. { load local symtable }
  3284. if ((proccalloption=pocall_inline) or
  3285. ((current_module.flags and uf_local_browser)<>0)) then
  3286. begin
  3287. localst:=tlocalsymtable.create(level);
  3288. tlocalsymtable(localst).ppuload(ppufile);
  3289. localst.defowner:=self;
  3290. end
  3291. else
  3292. localst:=nil;
  3293. { inline stuff }
  3294. if proccalloption=pocall_inline then
  3295. inlininginfo^.code:=ppuloadnodetree(ppufile)
  3296. else
  3297. inlininginfo := nil;
  3298. { default values for no persistent data }
  3299. if (cs_link_deffile in aktglobalswitches) and
  3300. (tf_need_export in target_info.flags) and
  3301. (po_exports in procoptions) then
  3302. deffile.AddExport(mangledname);
  3303. aliasnames:=tstringlist.create;
  3304. forwarddef:=false;
  3305. interfacedef:=false;
  3306. hasforward:=false;
  3307. lastref:=nil;
  3308. lastwritten:=nil;
  3309. defref:=nil;
  3310. refcount:=0;
  3311. {$ifdef GDB}
  3312. isstabwritten := false;
  3313. {$endif GDB}
  3314. end;
  3315. destructor tprocdef.destroy;
  3316. begin
  3317. if assigned(defref) then
  3318. begin
  3319. defref.freechain;
  3320. defref.free;
  3321. end;
  3322. aliasnames.free;
  3323. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3324. begin
  3325. {$ifdef MEMDEBUG}
  3326. memproclocalst.start;
  3327. {$endif MEMDEBUG}
  3328. localst.free;
  3329. {$ifdef MEMDEBUG}
  3330. memproclocalst.start;
  3331. {$endif MEMDEBUG}
  3332. end;
  3333. if (proccalloption=pocall_inline) and assigned(inlininginfo) then
  3334. begin
  3335. {$ifdef MEMDEBUG}
  3336. memprocnodetree.start;
  3337. {$endif MEMDEBUG}
  3338. tnode(inlininginfo^.code).free;
  3339. {$ifdef MEMDEBUG}
  3340. memprocnodetree.start;
  3341. {$endif MEMDEBUG}
  3342. end;
  3343. if assigned(inlininginfo) then
  3344. dispose(inlininginfo);
  3345. if (po_msgstr in procoptions) then
  3346. strdispose(messageinf.str);
  3347. if assigned(_mangledname) then
  3348. begin
  3349. {$ifdef MEMDEBUG}
  3350. memmanglednames.start;
  3351. {$endif MEMDEBUG}
  3352. stringdispose(_mangledname);
  3353. {$ifdef MEMDEBUG}
  3354. memmanglednames.stop;
  3355. {$endif MEMDEBUG}
  3356. end;
  3357. inherited destroy;
  3358. end;
  3359. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3360. var
  3361. oldintfcrc : boolean;
  3362. oldparasymtable,
  3363. oldlocalsymtable : tsymtable;
  3364. begin
  3365. { released procdef? }
  3366. if not assigned(parast) then
  3367. exit;
  3368. oldparasymtable:=aktparasymtable;
  3369. oldlocalsymtable:=aktlocalsymtable;
  3370. aktparasymtable:=parast;
  3371. aktlocalsymtable:=localst;
  3372. inherited ppuwrite(ppufile);
  3373. oldintfcrc:=ppufile.do_interface_crc;
  3374. ppufile.do_interface_crc:=false;
  3375. ppufile.do_interface_crc:=oldintfcrc;
  3376. ppufile.putbyte(byte(has_mangledname));
  3377. if has_mangledname then
  3378. ppufile.putstring(_mangledname^);
  3379. ppufile.putword(overloadnumber);
  3380. ppufile.putword(extnumber);
  3381. ppufile.putbyte(parast.symtablelevel);
  3382. ppufile.putderef(_classderef);
  3383. ppufile.putderef(procsymderef);
  3384. ppufile.putposinfo(fileinfo);
  3385. ppufile.putsmallset(symoptions);
  3386. {$ifdef powerpc}
  3387. { library symbol for AmigaOS/MorphOS }
  3388. ppufile.putderef(libsymderef);
  3389. {$endif powerpc}
  3390. { inline stuff }
  3391. oldintfcrc:=ppufile.do_crc;
  3392. ppufile.do_crc:=false;
  3393. if proccalloption=pocall_inline then
  3394. begin
  3395. ppufile.putderef(funcretsymderef);
  3396. ppufile.putsmallset(inlininginfo^.flags);
  3397. ppufile.putbyte(byte(inlininginfo^.inlinenode));
  3398. end;
  3399. ppufile.do_crc:=oldintfcrc;
  3400. { write this entry }
  3401. ppufile.writeentry(ibprocdef);
  3402. { Save the para symtable, this is taken from the interface }
  3403. tparasymtable(parast).ppuwrite(ppufile);
  3404. { save localsymtable for inline procedures or when local
  3405. browser info is requested, this has no influence on the crc }
  3406. if (proccalloption=pocall_inline) or
  3407. ((current_module.flags and uf_local_browser)<>0) then
  3408. begin
  3409. { we must write a localsymtable }
  3410. if not assigned(localst) then
  3411. insert_localst;
  3412. oldintfcrc:=ppufile.do_crc;
  3413. ppufile.do_crc:=false;
  3414. tlocalsymtable(localst).ppuwrite(ppufile);
  3415. ppufile.do_crc:=oldintfcrc;
  3416. end;
  3417. { node tree for inlining }
  3418. oldintfcrc:=ppufile.do_crc;
  3419. ppufile.do_crc:=false;
  3420. if proccalloption=pocall_inline then
  3421. ppuwritenodetree(ppufile,inlininginfo^.code);
  3422. ppufile.do_crc:=oldintfcrc;
  3423. aktparasymtable:=oldparasymtable;
  3424. aktlocalsymtable:=oldlocalsymtable;
  3425. end;
  3426. procedure tprocdef.insert_localst;
  3427. begin
  3428. localst:=tlocalsymtable.create(parast.symtablelevel);
  3429. localst.defowner:=self;
  3430. { this is used by insert
  3431. to check same names in parast and localst }
  3432. localst.next:=parast;
  3433. end;
  3434. function tprocdef.fullprocname(showhidden:boolean):string;
  3435. var
  3436. s : string;
  3437. t : ttoken;
  3438. begin
  3439. {$ifdef EXTDEBUG}
  3440. showhidden:=true;
  3441. {$endif EXTDEBUG}
  3442. s:='';
  3443. if assigned(_class) then
  3444. begin
  3445. if po_classmethod in procoptions then
  3446. s:=s+'class ';
  3447. s:=s+_class.objrealname^+'.';
  3448. end;
  3449. if proctypeoption=potype_operator then
  3450. begin
  3451. for t:=NOTOKEN to last_overloaded do
  3452. if procsym.realname='$'+overloaded_names[t] then
  3453. begin
  3454. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3455. break;
  3456. end;
  3457. end
  3458. else
  3459. s:=s+procsym.realname+typename_paras(showhidden);
  3460. case proctypeoption of
  3461. potype_constructor:
  3462. s:='constructor '+s;
  3463. potype_destructor:
  3464. s:='destructor '+s;
  3465. else
  3466. if assigned(rettype.def) and
  3467. not(is_void(rettype.def)) then
  3468. s:=s+':'+rettype.def.gettypename;
  3469. end;
  3470. { forced calling convention? }
  3471. if (po_hascallingconvention in procoptions) then
  3472. s:=s+';'+ProcCallOptionStr[proccalloption];
  3473. fullprocname:=s;
  3474. end;
  3475. function tprocdef.is_methodpointer:boolean;
  3476. begin
  3477. result:=assigned(_class);
  3478. end;
  3479. function tprocdef.is_addressonly:boolean;
  3480. begin
  3481. result:=assigned(owner) and
  3482. (owner.symtabletype<>objectsymtable);
  3483. end;
  3484. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3485. begin
  3486. is_visible_for_object:=false;
  3487. { private symbols are allowed when we are in the same
  3488. module as they are defined }
  3489. if (sp_private in symoptions) and
  3490. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3491. (owner.defowner.owner.unitid<>0) then
  3492. exit;
  3493. { protected symbols are vissible in the module that defines them and
  3494. also visible to related objects. The related object must be defined
  3495. in the current module }
  3496. if (sp_protected in symoptions) and
  3497. (
  3498. (
  3499. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3500. (owner.defowner.owner.unitid<>0)
  3501. ) and
  3502. not(
  3503. assigned(currobjdef) and
  3504. (currobjdef.owner.unitid=0) and
  3505. currobjdef.is_related(tobjectdef(owner.defowner))
  3506. )
  3507. ) then
  3508. exit;
  3509. is_visible_for_object:=true;
  3510. end;
  3511. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3512. begin
  3513. case t of
  3514. gs_local :
  3515. getsymtable:=localst;
  3516. gs_para :
  3517. getsymtable:=parast;
  3518. else
  3519. getsymtable:=nil;
  3520. end;
  3521. end;
  3522. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3523. var
  3524. pos : tfileposinfo;
  3525. move_last : boolean;
  3526. oldparasymtable,
  3527. oldlocalsymtable : tsymtable;
  3528. begin
  3529. oldparasymtable:=aktparasymtable;
  3530. oldlocalsymtable:=aktlocalsymtable;
  3531. aktparasymtable:=parast;
  3532. aktlocalsymtable:=localst;
  3533. move_last:=lastwritten=lastref;
  3534. while (not ppufile.endofentry) do
  3535. begin
  3536. ppufile.getposinfo(pos);
  3537. inc(refcount);
  3538. lastref:=tref.create(lastref,@pos);
  3539. lastref.is_written:=true;
  3540. if refcount=1 then
  3541. defref:=lastref;
  3542. end;
  3543. if move_last then
  3544. lastwritten:=lastref;
  3545. if ((current_module.flags and uf_local_browser)<>0) and
  3546. assigned(localst) and
  3547. locals then
  3548. begin
  3549. tparasymtable(parast).load_references(ppufile,locals);
  3550. tlocalsymtable(localst).load_references(ppufile,locals);
  3551. end;
  3552. aktparasymtable:=oldparasymtable;
  3553. aktlocalsymtable:=oldlocalsymtable;
  3554. end;
  3555. Const
  3556. local_symtable_index : word = $8001;
  3557. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3558. var
  3559. ref : tref;
  3560. pdo : tobjectdef;
  3561. move_last : boolean;
  3562. d : tderef;
  3563. oldparasymtable,
  3564. oldlocalsymtable : tsymtable;
  3565. begin
  3566. d.reset;
  3567. move_last:=lastwritten=lastref;
  3568. if move_last and
  3569. (((current_module.flags and uf_local_browser)=0) or
  3570. not locals) then
  3571. exit;
  3572. oldparasymtable:=aktparasymtable;
  3573. oldlocalsymtable:=aktlocalsymtable;
  3574. aktparasymtable:=parast;
  3575. aktlocalsymtable:=localst;
  3576. { write address of this symbol }
  3577. d.build(self);
  3578. ppufile.putderef(d);
  3579. { write refs }
  3580. if assigned(lastwritten) then
  3581. ref:=lastwritten
  3582. else
  3583. ref:=defref;
  3584. while assigned(ref) do
  3585. begin
  3586. if ref.moduleindex=current_module.unit_index then
  3587. begin
  3588. ppufile.putposinfo(ref.posinfo);
  3589. ref.is_written:=true;
  3590. if move_last then
  3591. lastwritten:=ref;
  3592. end
  3593. else if not ref.is_written then
  3594. move_last:=false
  3595. else if move_last then
  3596. lastwritten:=ref;
  3597. ref:=ref.nextref;
  3598. end;
  3599. ppufile.writeentry(ibdefref);
  3600. write_references:=true;
  3601. if ((current_module.flags and uf_local_browser)<>0) and
  3602. assigned(localst) and
  3603. locals then
  3604. begin
  3605. pdo:=_class;
  3606. if (owner.symtabletype<>localsymtable) then
  3607. while assigned(pdo) do
  3608. begin
  3609. if pdo.symtable<>aktrecordsymtable then
  3610. begin
  3611. pdo.symtable.unitid:=local_symtable_index;
  3612. inc(local_symtable_index);
  3613. end;
  3614. pdo:=pdo.childof;
  3615. end;
  3616. parast.unitid:=local_symtable_index;
  3617. inc(local_symtable_index);
  3618. localst.unitid:=local_symtable_index;
  3619. inc(local_symtable_index);
  3620. tstoredsymtable(parast).write_references(ppufile,locals);
  3621. tstoredsymtable(localst).write_references(ppufile,locals);
  3622. { decrement for }
  3623. local_symtable_index:=local_symtable_index-2;
  3624. pdo:=_class;
  3625. if (owner.symtabletype<>localsymtable) then
  3626. while assigned(pdo) do
  3627. begin
  3628. if pdo.symtable<>aktrecordsymtable then
  3629. dec(local_symtable_index);
  3630. pdo:=pdo.childof;
  3631. end;
  3632. end;
  3633. aktparasymtable:=oldparasymtable;
  3634. aktlocalsymtable:=oldlocalsymtable;
  3635. end;
  3636. {$ifdef GDB}
  3637. function tprocdef.numberstring : string;
  3638. begin
  3639. { procdefs are always available }
  3640. stab_state:=stab_state_written;
  3641. result:=inherited numberstring;
  3642. end;
  3643. function tprocdef.stabstring: pchar;
  3644. Var
  3645. RType : Char;
  3646. Obj,Info : String;
  3647. stabsstr : string;
  3648. p : pchar;
  3649. begin
  3650. obj := procsym.name;
  3651. info := '';
  3652. if tprocsym(procsym).is_global then
  3653. RType := 'F'
  3654. else
  3655. RType := 'f';
  3656. if assigned(owner) then
  3657. begin
  3658. if (owner.symtabletype = objectsymtable) then
  3659. obj := owner.name^+'__'+procsym.name;
  3660. if not(cs_gdb_valgrind in aktglobalswitches) and
  3661. (owner.symtabletype=localsymtable) and
  3662. assigned(owner.defowner) and
  3663. assigned(tprocdef(owner.defowner).procsym) then
  3664. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3665. end;
  3666. stabsstr:=mangledname;
  3667. getmem(p,length(stabsstr)+255);
  3668. strpcopy(p,'"'+obj+':'+RType
  3669. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3670. +',0,'+
  3671. tostr(fileinfo.line)
  3672. +',');
  3673. strpcopy(strend(p),stabsstr);
  3674. stabstring:=strnew(p);
  3675. freemem(p,length(stabsstr)+255);
  3676. end;
  3677. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3678. begin
  3679. { released procdef? }
  3680. if not assigned(parast) then
  3681. exit;
  3682. if (proccalloption=pocall_internproc) then
  3683. exit;
  3684. { be sure to have a number assigned for this def }
  3685. numberstring;
  3686. { write stabs }
  3687. stab_state:=stab_state_writing;
  3688. asmList.concat(Tai_stabs.Create(stabstring));
  3689. if not(po_external in procoptions) then
  3690. begin
  3691. tparasymtable(parast).concatstabto(asmlist);
  3692. { local type defs and vars should not be written
  3693. inside the main proc stab }
  3694. if assigned(localst) and
  3695. (localst.symtabletype=localsymtable) then
  3696. tlocalsymtable(localst).concatstabto(asmlist);
  3697. end;
  3698. stab_state:=stab_state_written;
  3699. end;
  3700. {$endif GDB}
  3701. procedure tprocdef.buildderef;
  3702. var
  3703. oldparasymtable,
  3704. oldlocalsymtable : tsymtable;
  3705. begin
  3706. oldparasymtable:=aktparasymtable;
  3707. oldlocalsymtable:=aktlocalsymtable;
  3708. aktparasymtable:=parast;
  3709. aktlocalsymtable:=localst;
  3710. inherited buildderef;
  3711. _classderef.build(_class);
  3712. { procsym that originaly defined this definition, should be in the
  3713. same symtable }
  3714. procsymderef.build(procsym);
  3715. {$ifdef powerpc}
  3716. { library symbol for AmigaOS/MorphOS }
  3717. libsymderef.build(libsym);
  3718. {$endif powerpc}
  3719. aktparasymtable:=oldparasymtable;
  3720. aktlocalsymtable:=oldlocalsymtable;
  3721. end;
  3722. procedure tprocdef.buildderefimpl;
  3723. var
  3724. oldparasymtable,
  3725. oldlocalsymtable : tsymtable;
  3726. begin
  3727. { released procdef? }
  3728. if not assigned(parast) then
  3729. exit;
  3730. oldparasymtable:=aktparasymtable;
  3731. oldlocalsymtable:=aktlocalsymtable;
  3732. aktparasymtable:=parast;
  3733. aktlocalsymtable:=localst;
  3734. inherited buildderefimpl;
  3735. { Locals }
  3736. if assigned(localst) and
  3737. ((proccalloption=pocall_inline) or
  3738. ((current_module.flags and uf_local_browser)<>0)) then
  3739. begin
  3740. tlocalsymtable(localst).buildderef;
  3741. tlocalsymtable(localst).buildderefimpl;
  3742. end;
  3743. { inline tree }
  3744. if (proccalloption=pocall_inline) then
  3745. begin
  3746. funcretsymderef.build(funcretsym);
  3747. inlininginfo^.code.buildderefimpl;
  3748. end;
  3749. aktparasymtable:=oldparasymtable;
  3750. aktlocalsymtable:=oldlocalsymtable;
  3751. end;
  3752. procedure tprocdef.deref;
  3753. var
  3754. oldparasymtable,
  3755. oldlocalsymtable : tsymtable;
  3756. begin
  3757. { released procdef? }
  3758. if not assigned(parast) then
  3759. exit;
  3760. oldparasymtable:=aktparasymtable;
  3761. oldlocalsymtable:=aktlocalsymtable;
  3762. aktparasymtable:=parast;
  3763. aktlocalsymtable:=localst;
  3764. inherited deref;
  3765. _class:=tobjectdef(_classderef.resolve);
  3766. { procsym that originaly defined this definition, should be in the
  3767. same symtable }
  3768. procsym:=tprocsym(procsymderef.resolve);
  3769. {$ifdef powerpc}
  3770. { library symbol for AmigaOS/MorphOS }
  3771. libsym:=tvarsym(libsymderef.resolve);
  3772. {$endif powerpc}
  3773. aktparasymtable:=oldparasymtable;
  3774. aktlocalsymtable:=oldlocalsymtable;
  3775. end;
  3776. procedure tprocdef.derefimpl;
  3777. var
  3778. oldparasymtable,
  3779. oldlocalsymtable : tsymtable;
  3780. begin
  3781. oldparasymtable:=aktparasymtable;
  3782. oldlocalsymtable:=aktlocalsymtable;
  3783. aktparasymtable:=parast;
  3784. aktlocalsymtable:=localst;
  3785. { Locals }
  3786. if assigned(localst) then
  3787. begin
  3788. tlocalsymtable(localst).deref;
  3789. tlocalsymtable(localst).derefimpl;
  3790. end;
  3791. { Inline }
  3792. if (proccalloption=pocall_inline) then
  3793. begin
  3794. inlininginfo^.code.derefimpl;
  3795. { funcretsym, this is always located in the localst }
  3796. funcretsym:=tsym(funcretsymderef.resolve);
  3797. end
  3798. else
  3799. begin
  3800. { safety }
  3801. funcretsym:=nil;
  3802. end;
  3803. aktparasymtable:=oldparasymtable;
  3804. aktlocalsymtable:=oldlocalsymtable;
  3805. end;
  3806. function tprocdef.gettypename : string;
  3807. begin
  3808. gettypename := FullProcName(false);
  3809. end;
  3810. function tprocdef.mangledname : string;
  3811. var
  3812. hp : TParaItem;
  3813. begin
  3814. if assigned(_mangledname) then
  3815. begin
  3816. {$ifdef compress}
  3817. mangledname:=minilzw_decode(_mangledname^);
  3818. {$else}
  3819. mangledname:=_mangledname^;
  3820. {$endif}
  3821. exit;
  3822. end;
  3823. { we need to use the symtable where the procsym is inserted,
  3824. because that is visible to the world }
  3825. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3826. if overloadnumber>0 then
  3827. mangledname:=mangledname+'$'+tostr(overloadnumber);
  3828. { add parameter types }
  3829. hp:=TParaItem(Para.first);
  3830. while assigned(hp) do
  3831. begin
  3832. if not hp.is_hidden then
  3833. mangledname:=mangledname+'$'+hp.paratype.def.mangledparaname;
  3834. hp:=TParaItem(hp.next);
  3835. end;
  3836. {$ifdef compress}
  3837. _mangledname:=stringdup(minilzw_encode(mangledname));
  3838. {$else}
  3839. _mangledname:=stringdup(mangledname);
  3840. {$endif}
  3841. end;
  3842. function tprocdef.cplusplusmangledname : string;
  3843. function getcppparaname(p : tdef) : string;
  3844. const
  3845. ordtype2str : array[tbasetype] of string[2] = (
  3846. '',
  3847. 'Uc','Us','Ui','Us',
  3848. 'Sc','s','i','x',
  3849. 'b','b','b',
  3850. 'c','w','x');
  3851. var
  3852. s : string;
  3853. begin
  3854. case p.deftype of
  3855. orddef:
  3856. s:=ordtype2str[torddef(p).typ];
  3857. pointerdef:
  3858. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3859. else
  3860. internalerror(2103001);
  3861. end;
  3862. getcppparaname:=s;
  3863. end;
  3864. var
  3865. s,s2 : string;
  3866. param : TParaItem;
  3867. begin
  3868. s := procsym.realname;
  3869. if procsym.owner.symtabletype=objectsymtable then
  3870. begin
  3871. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3872. case proctypeoption of
  3873. potype_destructor:
  3874. s:='_$_'+tostr(length(s2))+s2;
  3875. potype_constructor:
  3876. s:='___'+tostr(length(s2))+s2;
  3877. else
  3878. s:='_'+s+'__'+tostr(length(s2))+s2;
  3879. end;
  3880. end
  3881. else s:=s+'__';
  3882. s:=s+'F';
  3883. { concat modifiers }
  3884. { !!!!! }
  3885. { now we handle the parameters }
  3886. param := TParaItem(Para.first);
  3887. if assigned(param) then
  3888. while assigned(param) do
  3889. begin
  3890. s2:=getcppparaname(param.paratype.def);
  3891. if param.paratyp in [vs_var,vs_out] then
  3892. s2:='R'+s2;
  3893. s:=s+s2;
  3894. param:=TParaItem(param.next);
  3895. end
  3896. else
  3897. s:=s+'v';
  3898. cplusplusmangledname:=s;
  3899. end;
  3900. procedure tprocdef.setmangledname(const s : string);
  3901. begin
  3902. stringdispose(_mangledname);
  3903. {$ifdef compress}
  3904. _mangledname:=stringdup(minilzw_encode(s));
  3905. {$else}
  3906. _mangledname:=stringdup(s);
  3907. {$endif}
  3908. has_mangledname:=true;
  3909. end;
  3910. {***************************************************************************
  3911. TPROCVARDEF
  3912. ***************************************************************************}
  3913. constructor tprocvardef.create(level:byte);
  3914. begin
  3915. inherited create(level);
  3916. deftype:=procvardef;
  3917. end;
  3918. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3919. begin
  3920. inherited ppuload(ppufile);
  3921. deftype:=procvardef;
  3922. { load para symtable }
  3923. parast:=tparasymtable.create(unknown_level);
  3924. tparasymtable(parast).ppuload(ppufile);
  3925. parast.defowner:=self;
  3926. end;
  3927. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3928. var
  3929. oldparasymtable,
  3930. oldlocalsymtable : tsymtable;
  3931. begin
  3932. oldparasymtable:=aktparasymtable;
  3933. oldlocalsymtable:=aktlocalsymtable;
  3934. aktparasymtable:=parast;
  3935. aktlocalsymtable:=nil;
  3936. { here we cannot get a real good value so just give something }
  3937. { plausible (PM) }
  3938. { a more secure way would be
  3939. to allways store in a temp }
  3940. {$ifdef i386}
  3941. if is_fpu(rettype.def) then
  3942. fpu_used:={2}maxfpuregs
  3943. else
  3944. fpu_used:=0;
  3945. {$endif i386}
  3946. inherited ppuwrite(ppufile);
  3947. { Write this entry }
  3948. ppufile.writeentry(ibprocvardef);
  3949. { Save the para symtable, this is taken from the interface }
  3950. tparasymtable(parast).ppuwrite(ppufile);
  3951. aktparasymtable:=oldparasymtable;
  3952. aktlocalsymtable:=oldlocalsymtable;
  3953. end;
  3954. procedure tprocvardef.buildderef;
  3955. var
  3956. oldparasymtable,
  3957. oldlocalsymtable : tsymtable;
  3958. begin
  3959. oldparasymtable:=aktparasymtable;
  3960. oldlocalsymtable:=aktlocalsymtable;
  3961. aktparasymtable:=parast;
  3962. aktlocalsymtable:=nil;
  3963. inherited buildderef;
  3964. aktparasymtable:=oldparasymtable;
  3965. aktlocalsymtable:=oldlocalsymtable;
  3966. end;
  3967. procedure tprocvardef.deref;
  3968. var
  3969. oldparasymtable,
  3970. oldlocalsymtable : tsymtable;
  3971. begin
  3972. oldparasymtable:=aktparasymtable;
  3973. oldlocalsymtable:=aktlocalsymtable;
  3974. aktparasymtable:=parast;
  3975. aktlocalsymtable:=nil;
  3976. inherited deref;
  3977. aktparasymtable:=oldparasymtable;
  3978. aktlocalsymtable:=oldlocalsymtable;
  3979. end;
  3980. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3981. begin
  3982. case t of
  3983. gs_para :
  3984. getsymtable:=parast;
  3985. else
  3986. getsymtable:=nil;
  3987. end;
  3988. end;
  3989. function tprocvardef.size : aint;
  3990. begin
  3991. if (po_methodpointer in procoptions) and
  3992. not(po_addressonly in procoptions) then
  3993. size:=2*sizeof(aint)
  3994. else
  3995. size:=sizeof(aint);
  3996. end;
  3997. function tprocvardef.is_methodpointer:boolean;
  3998. begin
  3999. result:=(po_methodpointer in procoptions);
  4000. end;
  4001. function tprocvardef.is_addressonly:boolean;
  4002. begin
  4003. result:=not(po_methodpointer in procoptions) or
  4004. (po_addressonly in procoptions);
  4005. end;
  4006. {$ifdef GDB}
  4007. function tprocvardef.stabstring : pchar;
  4008. var
  4009. nss : pchar;
  4010. { i : longint; }
  4011. begin
  4012. { i := maxparacount; }
  4013. getmem(nss,1024);
  4014. { it is not a function but a function pointer !! (PM) }
  4015. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  4016. { this confuses gdb !!
  4017. we should use 'F' instead of 'f' but
  4018. as we use c++ language mode
  4019. it does not like that either
  4020. Please do not remove this part
  4021. might be used once
  4022. gdb for pascal is ready PM }
  4023. {$ifdef disabled}
  4024. param := para1;
  4025. i := 0;
  4026. while assigned(param) do
  4027. begin
  4028. inc(i);
  4029. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  4030. {Here we have lost the parameter names !!}
  4031. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  4032. strcat(nss,pst);
  4033. strdispose(pst);
  4034. param := param^.next;
  4035. end;
  4036. {$endif}
  4037. {strpcopy(strend(nss),';');}
  4038. stabstring := strnew(nss);
  4039. freemem(nss,1024);
  4040. end;
  4041. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  4042. begin
  4043. if (stab_state in [stab_state_writing,stab_state_written]) then
  4044. exit;
  4045. tstoreddef(rettype.def).concatstabto(asmlist);
  4046. inherited concatstabto(asmlist);
  4047. end;
  4048. {$endif GDB}
  4049. procedure tprocvardef.write_rtti_data(rt:trttitype);
  4050. var
  4051. pdc : TParaItem;
  4052. methodkind, paraspec : byte;
  4053. begin
  4054. if po_methodpointer in procoptions then
  4055. begin
  4056. { write method id and name }
  4057. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  4058. write_rtti_name;
  4059. { write kind of method (can only be function or procedure)}
  4060. if rettype.def = voidtype.def then
  4061. methodkind := mkProcedure
  4062. else
  4063. methodkind := mkFunction;
  4064. rttiList.concat(Tai_const.Create_8bit(methodkind));
  4065. { get # of parameters }
  4066. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  4067. { write parameter info. The parameters must be written in reverse order
  4068. if this method uses right to left parameter pushing! }
  4069. if proccalloption in pushleftright_pocalls then
  4070. pdc:=TParaItem(Para.first)
  4071. else
  4072. pdc:=TParaItem(Para.last);
  4073. while assigned(pdc) do
  4074. begin
  4075. { only store user visible parameters }
  4076. if not pdc.is_hidden then
  4077. begin
  4078. case pdc.paratyp of
  4079. vs_value: paraspec := 0;
  4080. vs_const: paraspec := pfConst;
  4081. vs_var : paraspec := pfVar;
  4082. vs_out : paraspec := pfOut;
  4083. end;
  4084. { write flags for current parameter }
  4085. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4086. { write name of current parameter }
  4087. if assigned(pdc.parasym) then
  4088. begin
  4089. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  4090. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  4091. end
  4092. else
  4093. rttiList.concat(Tai_const.Create_8bit(0));
  4094. { write name of type of current parameter }
  4095. tstoreddef(pdc.paratype.def).write_rtti_name;
  4096. end;
  4097. if proccalloption in pushleftright_pocalls then
  4098. pdc:=TParaItem(pdc.next)
  4099. else
  4100. pdc:=TParaItem(pdc.previous);
  4101. end;
  4102. { write name of result type }
  4103. tstoreddef(rettype.def).write_rtti_name;
  4104. end;
  4105. end;
  4106. function tprocvardef.is_publishable : boolean;
  4107. begin
  4108. is_publishable:=(po_methodpointer in procoptions);
  4109. end;
  4110. function tprocvardef.gettypename : string;
  4111. var
  4112. s: string;
  4113. showhidden : boolean;
  4114. begin
  4115. {$ifdef EXTDEBUG}
  4116. showhidden:=true;
  4117. {$else EXTDEBUG}
  4118. showhidden:=false;
  4119. {$endif EXTDEBUG}
  4120. s:='<';
  4121. if po_classmethod in procoptions then
  4122. s := s+'class method type of'
  4123. else
  4124. if po_addressonly in procoptions then
  4125. s := s+'address of'
  4126. else
  4127. s := s+'procedure variable type of';
  4128. if assigned(rettype.def) and
  4129. (rettype.def<>voidtype.def) then
  4130. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4131. else
  4132. s:=s+' procedure'+typename_paras(showhidden);
  4133. if po_methodpointer in procoptions then
  4134. s := s+' of object';
  4135. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4136. end;
  4137. {***************************************************************************
  4138. TOBJECTDEF
  4139. ***************************************************************************}
  4140. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4141. begin
  4142. inherited create;
  4143. objecttype:=ot;
  4144. deftype:=objectdef;
  4145. objectoptions:=[];
  4146. childof:=nil;
  4147. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4148. { create space for vmt !! }
  4149. vmt_offset:=0;
  4150. symtable.defowner:=self;
  4151. lastvtableindex:=0;
  4152. set_parent(c);
  4153. objname:=stringdup(upper(n));
  4154. objrealname:=stringdup(n);
  4155. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4156. prepareguid;
  4157. { setup implemented interfaces }
  4158. if objecttype in [odt_class,odt_interfacecorba] then
  4159. implementedinterfaces:=timplementedinterfaces.create
  4160. else
  4161. implementedinterfaces:=nil;
  4162. {$ifdef GDB}
  4163. writing_class_record_stab:=false;
  4164. {$endif GDB}
  4165. end;
  4166. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4167. var
  4168. i,implintfcount: longint;
  4169. d : tderef;
  4170. begin
  4171. inherited ppuloaddef(ppufile);
  4172. deftype:=objectdef;
  4173. objecttype:=tobjectdeftype(ppufile.getbyte);
  4174. objrealname:=stringdup(ppufile.getstring);
  4175. objname:=stringdup(upper(objrealname^));
  4176. symtable:=tobjectsymtable.create(objrealname^,0);
  4177. tobjectsymtable(symtable).datasize:=ppufile.getaint;
  4178. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4179. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4180. vmt_offset:=ppufile.getlongint;
  4181. ppufile.getderef(childofderef);
  4182. ppufile.getsmallset(objectoptions);
  4183. { load guid }
  4184. iidstr:=nil;
  4185. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4186. begin
  4187. new(iidguid);
  4188. ppufile.getguid(iidguid^);
  4189. iidstr:=stringdup(ppufile.getstring);
  4190. lastvtableindex:=ppufile.getlongint;
  4191. end;
  4192. { load implemented interfaces }
  4193. if objecttype in [odt_class,odt_interfacecorba] then
  4194. begin
  4195. implementedinterfaces:=timplementedinterfaces.create;
  4196. implintfcount:=ppufile.getlongint;
  4197. for i:=1 to implintfcount do
  4198. begin
  4199. ppufile.getderef(d);
  4200. implementedinterfaces.addintf_deref(d);
  4201. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4202. end;
  4203. end
  4204. else
  4205. implementedinterfaces:=nil;
  4206. tobjectsymtable(symtable).ppuload(ppufile);
  4207. symtable.defowner:=self;
  4208. { handles the predefined class tobject }
  4209. { the last TOBJECT which is loaded gets }
  4210. { it ! }
  4211. if (childof=nil) and
  4212. (objecttype=odt_class) and
  4213. (objname^='TOBJECT') then
  4214. class_tobject:=self;
  4215. if (childof=nil) and
  4216. (objecttype=odt_interfacecom) and
  4217. (objname^='IUNKNOWN') then
  4218. interface_iunknown:=self;
  4219. {$ifdef GDB}
  4220. writing_class_record_stab:=false;
  4221. {$endif GDB}
  4222. end;
  4223. destructor tobjectdef.destroy;
  4224. begin
  4225. if assigned(symtable) then
  4226. symtable.free;
  4227. stringdispose(objname);
  4228. stringdispose(objrealname);
  4229. if assigned(iidstr) then
  4230. stringdispose(iidstr);
  4231. if assigned(implementedinterfaces) then
  4232. implementedinterfaces.free;
  4233. if assigned(iidguid) then
  4234. dispose(iidguid);
  4235. inherited destroy;
  4236. end;
  4237. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4238. var
  4239. implintfcount : longint;
  4240. i : longint;
  4241. begin
  4242. inherited ppuwritedef(ppufile);
  4243. ppufile.putbyte(byte(objecttype));
  4244. ppufile.putstring(objrealname^);
  4245. ppufile.putaint(tobjectsymtable(symtable).datasize);
  4246. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4247. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4248. ppufile.putlongint(vmt_offset);
  4249. ppufile.putderef(childofderef);
  4250. ppufile.putsmallset(objectoptions);
  4251. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4252. begin
  4253. ppufile.putguid(iidguid^);
  4254. ppufile.putstring(iidstr^);
  4255. ppufile.putlongint(lastvtableindex);
  4256. end;
  4257. if objecttype in [odt_class,odt_interfacecorba] then
  4258. begin
  4259. implintfcount:=implementedinterfaces.count;
  4260. ppufile.putlongint(implintfcount);
  4261. for i:=1 to implintfcount do
  4262. begin
  4263. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4264. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4265. end;
  4266. end;
  4267. ppufile.writeentry(ibobjectdef);
  4268. tobjectsymtable(symtable).ppuwrite(ppufile);
  4269. end;
  4270. function tobjectdef.gettypename:string;
  4271. begin
  4272. gettypename:=typename;
  4273. end;
  4274. procedure tobjectdef.buildderef;
  4275. var
  4276. oldrecsyms : tsymtable;
  4277. begin
  4278. inherited buildderef;
  4279. childofderef.build(childof);
  4280. oldrecsyms:=aktrecordsymtable;
  4281. aktrecordsymtable:=symtable;
  4282. tstoredsymtable(symtable).buildderef;
  4283. aktrecordsymtable:=oldrecsyms;
  4284. if objecttype in [odt_class,odt_interfacecorba] then
  4285. implementedinterfaces.buildderef;
  4286. end;
  4287. procedure tobjectdef.deref;
  4288. var
  4289. oldrecsyms : tsymtable;
  4290. begin
  4291. inherited deref;
  4292. childof:=tobjectdef(childofderef.resolve);
  4293. oldrecsyms:=aktrecordsymtable;
  4294. aktrecordsymtable:=symtable;
  4295. tstoredsymtable(symtable).deref;
  4296. aktrecordsymtable:=oldrecsyms;
  4297. if objecttype in [odt_class,odt_interfacecorba] then
  4298. implementedinterfaces.deref;
  4299. end;
  4300. function tobjectdef.getparentdef:tdef;
  4301. begin
  4302. result:=childof;
  4303. end;
  4304. procedure tobjectdef.prepareguid;
  4305. begin
  4306. { set up guid }
  4307. if not assigned(iidguid) then
  4308. begin
  4309. new(iidguid);
  4310. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4311. end;
  4312. { setup iidstring }
  4313. if not assigned(iidstr) then
  4314. iidstr:=stringdup(''); { default is empty string }
  4315. end;
  4316. procedure tobjectdef.set_parent( c : tobjectdef);
  4317. begin
  4318. { nothing to do if the parent was not forward !}
  4319. if assigned(childof) then
  4320. exit;
  4321. childof:=c;
  4322. { some options are inherited !! }
  4323. if assigned(c) then
  4324. begin
  4325. { only important for classes }
  4326. lastvtableindex:=c.lastvtableindex;
  4327. objectoptions:=objectoptions+(c.objectoptions*
  4328. [oo_has_virtual,oo_has_private,oo_has_protected,
  4329. oo_has_constructor,oo_has_destructor]);
  4330. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4331. begin
  4332. { add the data of the anchestor class }
  4333. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4334. if (oo_has_vmt in objectoptions) and
  4335. (oo_has_vmt in c.objectoptions) then
  4336. dec(tobjectsymtable(symtable).datasize,sizeof(aint));
  4337. { if parent has a vmt field then
  4338. the offset is the same for the child PM }
  4339. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4340. begin
  4341. vmt_offset:=c.vmt_offset;
  4342. include(objectoptions,oo_has_vmt);
  4343. end;
  4344. end;
  4345. end;
  4346. end;
  4347. procedure tobjectdef.insertvmt;
  4348. begin
  4349. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4350. exit;
  4351. if (oo_has_vmt in objectoptions) then
  4352. internalerror(12345)
  4353. else
  4354. begin
  4355. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4356. tobjectsymtable(symtable).fieldalignment);
  4357. vmt_offset:=tobjectsymtable(symtable).datasize;
  4358. inc(tobjectsymtable(symtable).datasize,sizeof(aint));
  4359. include(objectoptions,oo_has_vmt);
  4360. end;
  4361. end;
  4362. procedure tobjectdef.check_forwards;
  4363. begin
  4364. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4365. tstoredsymtable(symtable).check_forwards;
  4366. if (oo_is_forward in objectoptions) then
  4367. begin
  4368. { ok, in future, the forward can be resolved }
  4369. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4370. exclude(objectoptions,oo_is_forward);
  4371. end;
  4372. end;
  4373. { true, if self inherits from d (or if they are equal) }
  4374. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4375. var
  4376. hp : tobjectdef;
  4377. begin
  4378. hp:=self;
  4379. while assigned(hp) do
  4380. begin
  4381. if hp=d then
  4382. begin
  4383. is_related:=true;
  4384. exit;
  4385. end;
  4386. hp:=hp.childof;
  4387. end;
  4388. is_related:=false;
  4389. end;
  4390. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4391. var
  4392. p : pprocdeflist;
  4393. begin
  4394. { if we found already a destructor, then we exit }
  4395. if assigned(sd) then
  4396. exit;
  4397. if tsym(sym).typ=procsym then
  4398. begin
  4399. p:=tprocsym(sym).defs;
  4400. while assigned(p) do
  4401. begin
  4402. if p^.def.proctypeoption=potype_destructor then
  4403. begin
  4404. sd:=p^.def;
  4405. exit;
  4406. end;
  4407. p:=p^.next;
  4408. end;
  4409. end;
  4410. end;*)
  4411. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4412. begin
  4413. { if we found already a destructor, then we exit }
  4414. if (ppointer(sd)^=nil) and
  4415. (Tsym(sym).typ=procsym) then
  4416. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4417. end;
  4418. function tobjectdef.searchdestructor : tprocdef;
  4419. var
  4420. o : tobjectdef;
  4421. sd : tprocdef;
  4422. begin
  4423. searchdestructor:=nil;
  4424. o:=self;
  4425. sd:=nil;
  4426. while assigned(o) do
  4427. begin
  4428. o.symtable.foreach_static(@_searchdestructor,@sd);
  4429. if assigned(sd) then
  4430. begin
  4431. searchdestructor:=sd;
  4432. exit;
  4433. end;
  4434. o:=o.childof;
  4435. end;
  4436. end;
  4437. function tobjectdef.size : aint;
  4438. begin
  4439. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4440. result:=sizeof(aint)
  4441. else
  4442. result:=tobjectsymtable(symtable).datasize;
  4443. end;
  4444. function tobjectdef.alignment:longint;
  4445. begin
  4446. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4447. alignment:=sizeof(aint)
  4448. else
  4449. alignment:=tobjectsymtable(symtable).recordalignment;
  4450. end;
  4451. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4452. begin
  4453. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4454. case objecttype of
  4455. odt_class:
  4456. { the +2*sizeof(Aint) is size and -size }
  4457. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  4458. odt_interfacecom,odt_interfacecorba:
  4459. vmtmethodoffset:=index*sizeof(aint);
  4460. else
  4461. {$ifdef WITHDMT}
  4462. vmtmethodoffset:=(index+4)*sizeof(aint);
  4463. {$else WITHDMT}
  4464. vmtmethodoffset:=(index+3)*sizeof(aint);
  4465. {$endif WITHDMT}
  4466. end;
  4467. end;
  4468. function tobjectdef.vmt_mangledname : string;
  4469. begin
  4470. if not(oo_has_vmt in objectoptions) then
  4471. Message1(parser_n_object_has_no_vmt,objrealname^);
  4472. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4473. end;
  4474. function tobjectdef.rtti_name : string;
  4475. begin
  4476. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4477. end;
  4478. {$ifdef GDB}
  4479. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4480. var virtualind,argnames : string;
  4481. newrec : pchar;
  4482. pd : tprocdef;
  4483. lindex : longint;
  4484. para : TParaItem;
  4485. arglength : byte;
  4486. sp : char;
  4487. state:^Trecord_stabgen_state;
  4488. olds:integer;
  4489. begin
  4490. state:=arg;
  4491. if tsym(p).typ = procsym then
  4492. begin
  4493. pd := tprocsym(p).first_procdef;
  4494. if (po_virtualmethod in pd.procoptions) then
  4495. begin
  4496. lindex := pd.extnumber;
  4497. {doesnt seem to be necessary
  4498. lindex := lindex or $80000000;}
  4499. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4500. end
  4501. else
  4502. virtualind := '.';
  4503. { used by gdbpas to recognize constructor and destructors }
  4504. if (pd.proctypeoption=potype_constructor) then
  4505. argnames:='__ct__'
  4506. else if (pd.proctypeoption=potype_destructor) then
  4507. argnames:='__dt__'
  4508. else
  4509. argnames := '';
  4510. { arguments are not listed here }
  4511. {we don't need another definition}
  4512. para := TParaItem(pd.Para.first);
  4513. while assigned(para) do
  4514. begin
  4515. if Para.paratype.def.deftype = formaldef then
  4516. begin
  4517. case Para.paratyp of
  4518. vs_var :
  4519. argnames := argnames+'3var';
  4520. vs_const :
  4521. argnames:=argnames+'5const';
  4522. vs_out :
  4523. argnames:=argnames+'3out';
  4524. end;
  4525. end
  4526. else
  4527. begin
  4528. { if the arg definition is like (v: ^byte;..
  4529. there is no sym attached to data !!! }
  4530. if assigned(Para.paratype.def.typesym) then
  4531. begin
  4532. arglength := length(Para.paratype.def.typesym.name);
  4533. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4534. end
  4535. else
  4536. argnames:=argnames+'11unnamedtype';
  4537. end;
  4538. para := TParaItem(Para.next);
  4539. end;
  4540. { here 2A must be changed for private and protected }
  4541. { 0 is private 1 protected and 2 public }
  4542. if (sp_private in tsym(p).symoptions) then
  4543. sp:='0'
  4544. else if (sp_protected in tsym(p).symoptions) then
  4545. sp:='1'
  4546. else
  4547. sp:='2';
  4548. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4549. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4550. virtualind]);
  4551. { get spare place for a string at the end }
  4552. olds:=state^.stabsize;
  4553. inc(state^.stabsize,strlen(newrec));
  4554. if state^.stabsize>=state^.staballoc-256 then
  4555. begin
  4556. inc(state^.staballoc,memsizeinc);
  4557. reallocmem(state^.stabstring,state^.staballoc);
  4558. end;
  4559. strcopy(state^.stabstring+olds,newrec);
  4560. strdispose(newrec);
  4561. {This should be used for case !!
  4562. RecOffset := RecOffset + pd.size;}
  4563. end;
  4564. end;
  4565. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4566. var
  4567. pd : tprocdef;
  4568. begin
  4569. if tsym(p).typ = procsym then
  4570. begin
  4571. pd := tprocsym(p).first_procdef;
  4572. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4573. end;
  4574. end;
  4575. function tobjectdef.stabstring : pchar;
  4576. var anc : tobjectdef;
  4577. state:Trecord_stabgen_state;
  4578. ts : string;
  4579. begin
  4580. if not (objecttype=odt_class) or writing_class_record_stab then
  4581. begin
  4582. state.staballoc:=memsizeinc;
  4583. getmem(state.stabstring,state.staballoc);
  4584. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4585. if assigned(childof) then
  4586. begin
  4587. {only one ancestor not virtual, public, at base offset 0 }
  4588. { !1 , 0 2 0 , }
  4589. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4590. end;
  4591. {virtual table to implement yet}
  4592. state.recoffset:=0;
  4593. state.stabsize:=strlen(state.stabstring);
  4594. symtable.foreach(@field_addname,@state);
  4595. if (oo_has_vmt in objectoptions) then
  4596. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4597. begin
  4598. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4599. strpcopy(state.stabstring+state.stabsize,ts);
  4600. inc(state.stabsize,length(ts));
  4601. end;
  4602. symtable.foreach(@proc_addname,@state);
  4603. if (oo_has_vmt in objectoptions) then
  4604. begin
  4605. anc := self;
  4606. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4607. anc := anc.childof;
  4608. { just in case anc = self }
  4609. ts:=';~%'+anc.classnumberstring+';';
  4610. end
  4611. else
  4612. ts:=';';
  4613. strpcopy(state.stabstring+state.stabsize,ts);
  4614. inc(state.stabsize,length(ts));
  4615. reallocmem(state.stabstring,state.stabsize+1);
  4616. stabstring:=state.stabstring;
  4617. end
  4618. else
  4619. begin
  4620. stabstring:=strpnew('*'+classnumberstring);
  4621. end;
  4622. end;
  4623. procedure tobjectdef.set_globalnb;
  4624. begin
  4625. globalnb:=PglobalTypeCount^;
  4626. inc(PglobalTypeCount^);
  4627. { classes need two type numbers, the globalnb is set to the ptr }
  4628. if objecttype=odt_class then
  4629. begin
  4630. globalnb:=PGlobalTypeCount^;
  4631. inc(PglobalTypeCount^);
  4632. end;
  4633. end;
  4634. function tobjectdef.classnumberstring : string;
  4635. begin
  4636. if objecttype=odt_class then
  4637. begin
  4638. if globalnb=0 then
  4639. numberstring;
  4640. dec(globalnb);
  4641. classnumberstring:=numberstring;
  4642. inc(globalnb);
  4643. end
  4644. else
  4645. classnumberstring:=numberstring;
  4646. end;
  4647. function tobjectdef.allstabstring : pchar;
  4648. var
  4649. stabchar : string[2];
  4650. ss,st : pchar;
  4651. sname : string;
  4652. begin
  4653. ss := stabstring;
  4654. getmem(st,strlen(ss)+512);
  4655. stabchar := 't';
  4656. if deftype in tagtypes then
  4657. stabchar := 'Tt';
  4658. if assigned(typesym) then
  4659. sname := typesym.name
  4660. else
  4661. sname := ' ';
  4662. if writing_class_record_stab then
  4663. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4664. else
  4665. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4666. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4667. allstabstring := strnew(st);
  4668. freemem(st,strlen(ss)+512);
  4669. strdispose(ss);
  4670. end;
  4671. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4672. var
  4673. oldtypesym : tsym;
  4674. stab_str : pchar;
  4675. anc : tobjectdef;
  4676. begin
  4677. if (stab_state in [stab_state_writing,stab_state_written]) then
  4678. exit;
  4679. stab_state:=stab_state_writing;
  4680. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4681. { first the parents }
  4682. anc:=self;
  4683. while assigned(anc.childof) do
  4684. begin
  4685. anc:=anc.childof;
  4686. anc.concatstabto(asmlist);
  4687. end;
  4688. symtable.foreach(@field_concatstabto,asmlist);
  4689. symtable.foreach(@proc_concatstabto,asmlist);
  4690. stab_state:=stab_state_used;
  4691. if objecttype=odt_class then
  4692. begin
  4693. { Write the record class itself }
  4694. writing_class_record_stab:=true;
  4695. inherited concatstabto(asmlist);
  4696. writing_class_record_stab:=false;
  4697. { Write the invisible pointer class }
  4698. oldtypesym:=typesym;
  4699. typesym:=nil;
  4700. stab_str := allstabstring;
  4701. asmList.concat(Tai_stabs.Create(stab_str));
  4702. typesym:=oldtypesym;
  4703. end
  4704. else
  4705. inherited concatstabto(asmlist);
  4706. end;
  4707. {$endif GDB}
  4708. function tobjectdef.needs_inittable : boolean;
  4709. begin
  4710. case objecttype of
  4711. odt_class :
  4712. needs_inittable:=false;
  4713. odt_interfacecom:
  4714. needs_inittable:=true;
  4715. odt_interfacecorba:
  4716. needs_inittable:=is_related(interface_iunknown);
  4717. odt_object:
  4718. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4719. else
  4720. internalerror(200108267);
  4721. end;
  4722. end;
  4723. function tobjectdef.members_need_inittable : boolean;
  4724. begin
  4725. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4726. end;
  4727. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4728. begin
  4729. if needs_prop_entry(tsym(sym)) and
  4730. (tsym(sym).typ<>varsym) then
  4731. inc(count);
  4732. end;
  4733. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4734. var
  4735. proctypesinfo : byte;
  4736. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4737. var
  4738. typvalue : byte;
  4739. hp : psymlistitem;
  4740. address : longint;
  4741. def : tdef;
  4742. begin
  4743. if not(assigned(proc) and assigned(proc.firstsym)) then
  4744. begin
  4745. rttiList.concat(Tai_const.create(ait_const_ptr,1));
  4746. typvalue:=3;
  4747. end
  4748. else if proc.firstsym^.sym.typ=varsym then
  4749. begin
  4750. address:=0;
  4751. hp:=proc.firstsym;
  4752. def:=nil;
  4753. while assigned(hp) do
  4754. begin
  4755. case hp^.sltype of
  4756. sl_load :
  4757. begin
  4758. def:=tvarsym(hp^.sym).vartype.def;
  4759. inc(address,tvarsym(hp^.sym).fieldoffset);
  4760. end;
  4761. sl_subscript :
  4762. begin
  4763. if not(assigned(def) and (def.deftype=recorddef)) then
  4764. internalerror(200402171);
  4765. inc(address,tvarsym(hp^.sym).fieldoffset);
  4766. def:=tvarsym(hp^.sym).vartype.def;
  4767. end;
  4768. sl_vec :
  4769. begin
  4770. if not(assigned(def) and (def.deftype=arraydef)) then
  4771. internalerror(200402172);
  4772. def:=tarraydef(def).elementtype.def;
  4773. inc(address,def.size*hp^.value);
  4774. end;
  4775. end;
  4776. hp:=hp^.next;
  4777. end;
  4778. rttiList.concat(Tai_const.create(ait_const_ptr,address));
  4779. typvalue:=0;
  4780. end
  4781. else
  4782. begin
  4783. { When there was an error then procdef is not assigned }
  4784. if not assigned(proc.procdef) then
  4785. exit;
  4786. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4787. begin
  4788. rttiList.concat(Tai_const.createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4789. typvalue:=1;
  4790. end
  4791. else
  4792. begin
  4793. { virtual method, write vmt offset }
  4794. rttiList.concat(Tai_const.create(ait_const_ptr,
  4795. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4796. typvalue:=2;
  4797. end;
  4798. end;
  4799. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4800. end;
  4801. begin
  4802. if needs_prop_entry(tsym(sym)) then
  4803. case tsym(sym).typ of
  4804. varsym:
  4805. begin
  4806. {$ifdef dummy}
  4807. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4808. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4809. internalerror(1509992);
  4810. { access to implicit class property as field }
  4811. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4812. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4813. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4814. rttiList.concat(Tai_const.create(ait_const_ptr,tvarsym(sym.address)));
  4815. { by default stored }
  4816. rttiList.concat(Tai_const.Create_32bit(1));
  4817. { index as well as ... }
  4818. rttiList.concat(Tai_const.Create_32bit(0));
  4819. { default value are zero }
  4820. rttiList.concat(Tai_const.Create_32bit(0));
  4821. rttiList.concat(Tai_const.Create_16bit(count));
  4822. inc(count);
  4823. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4824. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4825. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4826. {$endif dummy}
  4827. end;
  4828. propertysym:
  4829. begin
  4830. if ppo_indexed in tpropertysym(sym).propoptions then
  4831. proctypesinfo:=$40
  4832. else
  4833. proctypesinfo:=0;
  4834. rttiList.concat(Tai_const.Create_sym(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4835. writeproc(tpropertysym(sym).readaccess,0);
  4836. writeproc(tpropertysym(sym).writeaccess,2);
  4837. { isn't it stored ? }
  4838. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4839. begin
  4840. rttiList.concat(Tai_const.create_sym(nil));
  4841. proctypesinfo:=proctypesinfo or (3 shl 4);
  4842. end
  4843. else
  4844. writeproc(tpropertysym(sym).storedaccess,4);
  4845. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4846. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4847. rttiList.concat(Tai_const.Create_16bit(count));
  4848. inc(count);
  4849. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4850. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4851. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4852. {$ifdef cpurequiresproperalignment}
  4853. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  4854. {$endif cpurequiresproperalignment}
  4855. end;
  4856. else internalerror(1509992);
  4857. end;
  4858. end;
  4859. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4860. begin
  4861. if needs_prop_entry(tsym(sym)) then
  4862. begin
  4863. case tsym(sym).typ of
  4864. propertysym:
  4865. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4866. varsym:
  4867. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4868. else
  4869. internalerror(1509991);
  4870. end;
  4871. end;
  4872. end;
  4873. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4874. begin
  4875. FRTTIType:=rt;
  4876. case rt of
  4877. initrtti :
  4878. symtable.foreach(@generate_field_rtti,nil);
  4879. fullrtti :
  4880. symtable.foreach(@generate_published_child_rtti,nil);
  4881. else
  4882. internalerror(200108301);
  4883. end;
  4884. end;
  4885. type
  4886. tclasslistitem = class(TLinkedListItem)
  4887. index : longint;
  4888. p : tobjectdef;
  4889. end;
  4890. var
  4891. classtablelist : tlinkedlist;
  4892. tablecount : longint;
  4893. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4894. var
  4895. hp : tclasslistitem;
  4896. begin
  4897. hp:=tclasslistitem(classtablelist.first);
  4898. while assigned(hp) do
  4899. if hp.p=p then
  4900. begin
  4901. searchclasstablelist:=hp;
  4902. exit;
  4903. end
  4904. else
  4905. hp:=tclasslistitem(hp.next);
  4906. searchclasstablelist:=nil;
  4907. end;
  4908. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4909. var
  4910. hp : tclasslistitem;
  4911. begin
  4912. if needs_prop_entry(tsym(sym)) and
  4913. (tsym(sym).typ=varsym) then
  4914. begin
  4915. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4916. internalerror(0206001);
  4917. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4918. if not(assigned(hp)) then
  4919. begin
  4920. hp:=tclasslistitem.create;
  4921. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4922. hp.index:=tablecount;
  4923. classtablelist.concat(hp);
  4924. inc(tablecount);
  4925. end;
  4926. inc(count);
  4927. end;
  4928. end;
  4929. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4930. var
  4931. hp : tclasslistitem;
  4932. begin
  4933. if needs_prop_entry(tsym(sym)) and
  4934. (tsym(sym).typ=varsym) then
  4935. begin
  4936. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4937. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4938. if not(assigned(hp)) then
  4939. internalerror(0206002);
  4940. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4941. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4942. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4943. end;
  4944. end;
  4945. function tobjectdef.generate_field_table : tasmlabel;
  4946. var
  4947. fieldtable,
  4948. classtable : tasmlabel;
  4949. hp : tclasslistitem;
  4950. begin
  4951. classtablelist:=TLinkedList.Create;
  4952. objectlibrary.getdatalabel(fieldtable);
  4953. objectlibrary.getdatalabel(classtable);
  4954. count:=0;
  4955. tablecount:=0;
  4956. maybe_new_object_file(rttiList);
  4957. new_section(rttiList,sec_rodata,classtable.name,const_align(sizeof(aint)));
  4958. { fields }
  4959. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4960. rttiList.concat(Tai_label.Create(fieldtable));
  4961. rttiList.concat(Tai_const.Create_16bit(count));
  4962. rttiList.concat(Tai_const.Create_sym(classtable));
  4963. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4964. { generate the class table }
  4965. rttilist.concat(tai_align.create(const_align(sizeof(aint))));
  4966. rttiList.concat(Tai_label.Create(classtable));
  4967. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4968. hp:=tclasslistitem(classtablelist.first);
  4969. while assigned(hp) do
  4970. begin
  4971. rttiList.concat(Tai_const.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  4972. hp:=tclasslistitem(hp.next);
  4973. end;
  4974. generate_field_table:=fieldtable;
  4975. classtablelist.free;
  4976. end;
  4977. function tobjectdef.next_free_name_index : longint;
  4978. var
  4979. i : longint;
  4980. begin
  4981. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4982. i:=childof.next_free_name_index
  4983. else
  4984. i:=0;
  4985. count:=0;
  4986. symtable.foreach(@count_published_properties,nil);
  4987. next_free_name_index:=i+count;
  4988. end;
  4989. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4990. begin
  4991. case objecttype of
  4992. odt_class:
  4993. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4994. odt_object:
  4995. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4996. odt_interfacecom:
  4997. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4998. odt_interfacecorba:
  4999. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  5000. else
  5001. exit;
  5002. end;
  5003. { generate the name }
  5004. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  5005. rttiList.concat(Tai_string.Create(objrealname^));
  5006. {$ifdef cpurequiresproperalignment}
  5007. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5008. {$endif cpurequiresproperalignment}
  5009. case rt of
  5010. initrtti :
  5011. begin
  5012. rttiList.concat(Tai_const.Create_32bit(size));
  5013. if objecttype in [odt_class,odt_object] then
  5014. begin
  5015. count:=0;
  5016. FRTTIType:=rt;
  5017. symtable.foreach(@count_field_rtti,nil);
  5018. rttiList.concat(Tai_const.Create_32bit(count));
  5019. symtable.foreach(@write_field_rtti,nil);
  5020. end;
  5021. end;
  5022. fullrtti :
  5023. begin
  5024. if (oo_has_vmt in objectoptions) and
  5025. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5026. rttiList.concat(Tai_const.Createname(vmt_mangledname,AT_DATA,0))
  5027. else
  5028. rttiList.concat(Tai_const.create_sym(nil));
  5029. { write owner typeinfo }
  5030. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5031. rttiList.concat(Tai_const.Create_sym(childof.get_rtti_label(fullrtti)))
  5032. else
  5033. rttiList.concat(Tai_const.create_sym(nil));
  5034. { count total number of properties }
  5035. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5036. count:=childof.next_free_name_index
  5037. else
  5038. count:=0;
  5039. { write it }
  5040. symtable.foreach(@count_published_properties,nil);
  5041. rttiList.concat(Tai_const.Create_16bit(count));
  5042. { write unit name }
  5043. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  5044. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  5045. {$ifdef cpurequiresproperalignment}
  5046. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5047. {$endif cpurequiresproperalignment}
  5048. { write published properties count }
  5049. count:=0;
  5050. symtable.foreach(@count_published_properties,nil);
  5051. rttiList.concat(Tai_const.Create_16bit(count));
  5052. {$ifdef cpurequiresproperalignment}
  5053. rttilist.concat(Tai_align.Create(sizeof(TConstPtrUInt)));
  5054. {$endif cpurequiresproperalignment}
  5055. { count is used to write nameindex }
  5056. { but we need an offset of the owner }
  5057. { to give each property an own slot }
  5058. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  5059. count:=childof.next_free_name_index
  5060. else
  5061. count:=0;
  5062. symtable.foreach(@write_property_info,nil);
  5063. end;
  5064. end;
  5065. end;
  5066. function tobjectdef.is_publishable : boolean;
  5067. begin
  5068. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  5069. end;
  5070. {****************************************************************************
  5071. TIMPLEMENTEDINTERFACES
  5072. ****************************************************************************}
  5073. type
  5074. tnamemap = class(TNamedIndexItem)
  5075. newname: pstring;
  5076. constructor create(const aname, anewname: string);
  5077. destructor destroy; override;
  5078. end;
  5079. constructor tnamemap.create(const aname, anewname: string);
  5080. begin
  5081. inherited createname(name);
  5082. newname:=stringdup(anewname);
  5083. end;
  5084. destructor tnamemap.destroy;
  5085. begin
  5086. stringdispose(newname);
  5087. inherited destroy;
  5088. end;
  5089. type
  5090. tprocdefstore = class(TNamedIndexItem)
  5091. procdef: tprocdef;
  5092. constructor create(aprocdef: tprocdef);
  5093. end;
  5094. constructor tprocdefstore.create(aprocdef: tprocdef);
  5095. begin
  5096. inherited create;
  5097. procdef:=aprocdef;
  5098. end;
  5099. type
  5100. timplintfentry = class(TNamedIndexItem)
  5101. intf: tobjectdef;
  5102. intfderef : tderef;
  5103. ioffs: longint;
  5104. namemappings: tdictionary;
  5105. procdefs: TIndexArray;
  5106. constructor create(aintf: tobjectdef);
  5107. constructor create_deref(const d:tderef);
  5108. destructor destroy; override;
  5109. end;
  5110. constructor timplintfentry.create(aintf: tobjectdef);
  5111. begin
  5112. inherited create;
  5113. intf:=aintf;
  5114. ioffs:=-1;
  5115. namemappings:=nil;
  5116. procdefs:=nil;
  5117. end;
  5118. constructor timplintfentry.create_deref(const d:tderef);
  5119. begin
  5120. inherited create;
  5121. intf:=nil;
  5122. intfderef:=d;
  5123. ioffs:=-1;
  5124. namemappings:=nil;
  5125. procdefs:=nil;
  5126. end;
  5127. destructor timplintfentry.destroy;
  5128. begin
  5129. if assigned(namemappings) then
  5130. namemappings.free;
  5131. if assigned(procdefs) then
  5132. procdefs.free;
  5133. inherited destroy;
  5134. end;
  5135. constructor timplementedinterfaces.create;
  5136. begin
  5137. finterfaces:=tindexarray.create(1);
  5138. end;
  5139. destructor timplementedinterfaces.destroy;
  5140. begin
  5141. finterfaces.destroy;
  5142. end;
  5143. function timplementedinterfaces.count: longint;
  5144. begin
  5145. count:=finterfaces.count;
  5146. end;
  5147. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5148. begin
  5149. if (intfindex<1) or (intfindex>count) then
  5150. InternalError(200006123);
  5151. end;
  5152. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5153. begin
  5154. checkindex(intfindex);
  5155. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5156. end;
  5157. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5158. begin
  5159. checkindex(intfindex);
  5160. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5161. end;
  5162. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5163. begin
  5164. checkindex(intfindex);
  5165. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5166. end;
  5167. function timplementedinterfaces.searchintf(def: tdef): longint;
  5168. var
  5169. i: longint;
  5170. begin
  5171. i:=1;
  5172. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5173. if i<=count then
  5174. searchintf:=i
  5175. else
  5176. searchintf:=-1;
  5177. end;
  5178. procedure timplementedinterfaces.buildderef;
  5179. var
  5180. i: longint;
  5181. begin
  5182. for i:=1 to count do
  5183. with timplintfentry(finterfaces.search(i)) do
  5184. intfderef.build(intf);
  5185. end;
  5186. procedure timplementedinterfaces.deref;
  5187. var
  5188. i: longint;
  5189. begin
  5190. for i:=1 to count do
  5191. with timplintfentry(finterfaces.search(i)) do
  5192. intf:=tobjectdef(intfderef.resolve);
  5193. end;
  5194. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5195. begin
  5196. finterfaces.insert(timplintfentry.create_deref(d));
  5197. end;
  5198. procedure timplementedinterfaces.addintf(def: tdef);
  5199. begin
  5200. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5201. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5202. internalerror(200006124);
  5203. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5204. end;
  5205. procedure timplementedinterfaces.clearmappings;
  5206. var
  5207. i: longint;
  5208. begin
  5209. for i:=1 to count do
  5210. with timplintfentry(finterfaces.search(i)) do
  5211. begin
  5212. if assigned(namemappings) then
  5213. namemappings.free;
  5214. namemappings:=nil;
  5215. end;
  5216. end;
  5217. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5218. begin
  5219. checkindex(intfindex);
  5220. with timplintfentry(finterfaces.search(intfindex)) do
  5221. begin
  5222. if not assigned(namemappings) then
  5223. namemappings:=tdictionary.create;
  5224. namemappings.insert(tnamemap.create(name,newname));
  5225. end;
  5226. end;
  5227. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5228. begin
  5229. checkindex(intfindex);
  5230. if not assigned(nextexist) then
  5231. with timplintfentry(finterfaces.search(intfindex)) do
  5232. begin
  5233. if assigned(namemappings) then
  5234. nextexist:=namemappings.search(name)
  5235. else
  5236. nextexist:=nil;
  5237. end;
  5238. if assigned(nextexist) then
  5239. begin
  5240. getmappings:=tnamemap(nextexist).newname^;
  5241. nextexist:=tnamemap(nextexist).listnext;
  5242. end
  5243. else
  5244. getmappings:='';
  5245. end;
  5246. procedure timplementedinterfaces.clearimplprocs;
  5247. var
  5248. i: longint;
  5249. begin
  5250. for i:=1 to count do
  5251. with timplintfentry(finterfaces.search(i)) do
  5252. begin
  5253. if assigned(procdefs) then
  5254. procdefs.free;
  5255. procdefs:=nil;
  5256. end;
  5257. end;
  5258. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5259. begin
  5260. checkindex(intfindex);
  5261. with timplintfentry(finterfaces.search(intfindex)) do
  5262. begin
  5263. if not assigned(procdefs) then
  5264. procdefs:=tindexarray.create(4);
  5265. procdefs.insert(tprocdefstore.create(procdef));
  5266. end;
  5267. end;
  5268. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5269. begin
  5270. checkindex(intfindex);
  5271. with timplintfentry(finterfaces.search(intfindex)) do
  5272. if assigned(procdefs) then
  5273. implproccount:=procdefs.count
  5274. else
  5275. implproccount:=0;
  5276. end;
  5277. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5278. begin
  5279. checkindex(intfindex);
  5280. with timplintfentry(finterfaces.search(intfindex)) do
  5281. if assigned(procdefs) then
  5282. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5283. else
  5284. internalerror(200006131);
  5285. end;
  5286. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5287. var
  5288. possible: boolean;
  5289. i: longint;
  5290. iiep1: TIndexArray;
  5291. iiep2: TIndexArray;
  5292. begin
  5293. checkindex(intfindex);
  5294. checkindex(remainindex);
  5295. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5296. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5297. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5298. begin
  5299. possible:=true;
  5300. weight:=0;
  5301. end
  5302. else
  5303. begin
  5304. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5305. i:=1;
  5306. while (possible) and (i<=iiep1.count) do
  5307. begin
  5308. possible:=
  5309. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5310. inc(i);
  5311. end;
  5312. if possible then
  5313. weight:=iiep1.count;
  5314. end;
  5315. isimplmergepossible:=possible;
  5316. end;
  5317. {****************************************************************************
  5318. TFORWARDDEF
  5319. ****************************************************************************}
  5320. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5321. var
  5322. oldregisterdef : boolean;
  5323. begin
  5324. { never register the forwarddefs, they are disposed at the
  5325. end of the type declaration block }
  5326. oldregisterdef:=registerdef;
  5327. registerdef:=false;
  5328. inherited create;
  5329. registerdef:=oldregisterdef;
  5330. deftype:=forwarddef;
  5331. tosymname:=stringdup(s);
  5332. forwardpos:=pos;
  5333. end;
  5334. function tforwarddef.gettypename:string;
  5335. begin
  5336. gettypename:='unresolved forward to '+tosymname^;
  5337. end;
  5338. destructor tforwarddef.destroy;
  5339. begin
  5340. if assigned(tosymname) then
  5341. stringdispose(tosymname);
  5342. inherited destroy;
  5343. end;
  5344. {****************************************************************************
  5345. TERRORDEF
  5346. ****************************************************************************}
  5347. constructor terrordef.create;
  5348. begin
  5349. inherited create;
  5350. deftype:=errordef;
  5351. end;
  5352. {$ifdef GDB}
  5353. function terrordef.stabstring : pchar;
  5354. begin
  5355. stabstring:=strpnew('error'+numberstring);
  5356. end;
  5357. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5358. begin
  5359. { No internal error needed, an normal error is already
  5360. thrown }
  5361. end;
  5362. {$endif GDB}
  5363. function terrordef.gettypename:string;
  5364. begin
  5365. gettypename:='<erroneous type>';
  5366. end;
  5367. function terrordef.getmangledparaname:string;
  5368. begin
  5369. getmangledparaname:='error';
  5370. end;
  5371. {****************************************************************************
  5372. Definition Helpers
  5373. ****************************************************************************}
  5374. function is_interfacecom(def: tdef): boolean;
  5375. begin
  5376. is_interfacecom:=
  5377. assigned(def) and
  5378. (def.deftype=objectdef) and
  5379. (tobjectdef(def).objecttype=odt_interfacecom);
  5380. end;
  5381. function is_interfacecorba(def: tdef): boolean;
  5382. begin
  5383. is_interfacecorba:=
  5384. assigned(def) and
  5385. (def.deftype=objectdef) and
  5386. (tobjectdef(def).objecttype=odt_interfacecorba);
  5387. end;
  5388. function is_interface(def: tdef): boolean;
  5389. begin
  5390. is_interface:=
  5391. assigned(def) and
  5392. (def.deftype=objectdef) and
  5393. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5394. end;
  5395. function is_class(def: tdef): boolean;
  5396. begin
  5397. is_class:=
  5398. assigned(def) and
  5399. (def.deftype=objectdef) and
  5400. (tobjectdef(def).objecttype=odt_class);
  5401. end;
  5402. function is_object(def: tdef): boolean;
  5403. begin
  5404. is_object:=
  5405. assigned(def) and
  5406. (def.deftype=objectdef) and
  5407. (tobjectdef(def).objecttype=odt_object);
  5408. end;
  5409. function is_cppclass(def: tdef): boolean;
  5410. begin
  5411. is_cppclass:=
  5412. assigned(def) and
  5413. (def.deftype=objectdef) and
  5414. (tobjectdef(def).objecttype=odt_cppclass);
  5415. end;
  5416. function is_class_or_interface(def: tdef): boolean;
  5417. begin
  5418. is_class_or_interface:=
  5419. assigned(def) and
  5420. (def.deftype=objectdef) and
  5421. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5422. end;
  5423. end.
  5424. {
  5425. $Log$
  5426. Revision 1.266 2004-11-04 17:58:48 peter
  5427. elecount also on 32bit needs the qword part to prevent overflow
  5428. Revision 1.265 2004/11/04 17:09:54 peter
  5429. fixed debuginfo for variables in staticsymtable
  5430. Revision 1.264 2004/11/03 09:46:34 florian
  5431. * fixed writing of para locations for procedures with explicit locations for parameters
  5432. Revision 1.263 2004/11/01 23:30:11 peter
  5433. * support > 32bit accesses for x86_64
  5434. * rewrote array size checking to support 64bit
  5435. Revision 1.262 2004/11/01 15:33:12 florian
  5436. * fixed type information for dyn. arrays on 64 bit systems
  5437. Revision 1.261 2004/10/31 21:45:03 peter
  5438. * generic tlocation
  5439. * move tlocation to cgutils
  5440. Revision 1.260 2004/10/26 15:02:33 peter
  5441. * align arraydef rtti
  5442. Revision 1.259 2004/10/15 09:14:17 mazen
  5443. - remove $IFDEF DELPHI and related code
  5444. - remove $IFDEF FPCPROCVAR and related code
  5445. Revision 1.258 2004/10/10 21:08:55 peter
  5446. * parameter regvar fixes
  5447. Revision 1.257 2004/10/04 21:23:15 florian
  5448. * rtti alignment fixed
  5449. Revision 1.256 2004/09/21 23:36:51 hajny
  5450. * SetTextLineEnding implemented, FileRec.Name position alignment for CPU64
  5451. Revision 1.255 2004/09/21 17:25:12 peter
  5452. * paraloc branch merged
  5453. Revision 1.254 2004/09/14 16:33:17 peter
  5454. * restart sorting of enums when deref is called, this is needed when
  5455. a unit is reloaded
  5456. Revision 1.253.4.1 2004/08/31 20:43:06 peter
  5457. * paraloc patch
  5458. Revision 1.253 2004/08/27 21:59:26 peter
  5459. browser disabled
  5460. uf_local_symtable ppu flag when a localsymtable is stored
  5461. Revision 1.252 2004/08/17 16:29:21 jonas
  5462. + padalgingment field for recordsymtables (saved by recorddefs)
  5463. + support for Macintosh PowerPC alignment (if the first field of a record
  5464. or union has an alignment > 4, then the record or union size must be
  5465. padded to a multiple of this size)
  5466. Revision 1.251 2004/08/15 15:05:16 peter
  5467. * fixed padding of records to alignment
  5468. Revision 1.250 2004/08/14 14:50:42 florian
  5469. * fixed several sparc alignment issues
  5470. + Jonas' inline node patch; non functional yet
  5471. Revision 1.249 2004/08/07 14:52:45 florian
  5472. * fixed web bug 3226: type p = type pointer;
  5473. Revision 1.248 2004/07/19 19:15:50 florian
  5474. * fixed funcret_paraloc writing in units
  5475. Revision 1.247 2004/07/14 21:37:41 olle
  5476. - removed unused types
  5477. Revision 1.246 2004/07/12 09:14:04 jonas
  5478. * inline procedures at the node tree level, but only under some very
  5479. limited circumstances for now (only procedures, and only if they have
  5480. no or only vs_out/vs_var parameters).
  5481. * fixed ppudump for inline procedures
  5482. * fixed ppudump for ppc
  5483. Revision 1.245 2004/07/09 22:17:32 peter
  5484. * revert has_localst patch
  5485. * replace aktstaticsymtable/aktglobalsymtable with current_module
  5486. Revision 1.244 2004/07/06 19:52:04 peter
  5487. * fix storing of localst in ppu
  5488. Revision 1.243 2004/06/20 08:55:30 florian
  5489. * logs truncated
  5490. Revision 1.242 2004/06/18 15:16:46 peter
  5491. * remove obsolete cardinal() typecasts
  5492. Revision 1.241 2004/06/16 20:07:09 florian
  5493. * dwarf branch merged
  5494. Revision 1.240 2004/05/25 18:51:14 peter
  5495. * range check error
  5496. Revision 1.239 2004/05/23 20:57:10 peter
  5497. * removed unused voidprocdef
  5498. Revision 1.238 2004/05/23 15:23:30 peter
  5499. * fixed qword(longint) that removed sign from the number
  5500. * removed code in the compiler that relied on wrong qword(longint)
  5501. code generation
  5502. }