symdef.pas 197 KB

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