symdef.pas 195 KB

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