symdef.pas 197 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335
  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. function tprocdef.is_visible_for_proc(currprocdef:tprocdef):boolean;
  3255. begin
  3256. is_visible_for_proc:=false;
  3257. { private symbols are allowed when we are in the same
  3258. module as they are defined }
  3259. if (sp_private in symoptions) and
  3260. assigned(owner.defowner) and
  3261. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3262. (owner.defowner.owner.unitid<>0) then
  3263. exit;
  3264. { protected symbols are vissible in the module that defines them and
  3265. also visible to related objects }
  3266. if (sp_protected in symoptions) and
  3267. (
  3268. (
  3269. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3270. (owner.defowner.owner.unitid<>0)
  3271. ) and
  3272. not(
  3273. assigned(currprocdef) and
  3274. assigned(currprocdef._class) and
  3275. currprocdef._class.is_related(tobjectdef(owner.defowner))
  3276. )
  3277. ) then
  3278. exit;
  3279. is_visible_for_proc:=true;
  3280. end;
  3281. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3282. begin
  3283. is_visible_for_object:=false;
  3284. { private symbols are allowed when we are in the same
  3285. module as they are defined }
  3286. if (sp_private in symoptions) and
  3287. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3288. (owner.defowner.owner.unitid<>0) then
  3289. exit;
  3290. { protected symbols are vissible in the module that defines them and
  3291. also visible to related objects }
  3292. if (sp_protected in symoptions) and
  3293. (
  3294. (
  3295. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3296. (owner.defowner.owner.unitid<>0)
  3297. ) and
  3298. not(
  3299. assigned(currobjdef) and
  3300. currobjdef.is_related(tobjectdef(owner.defowner))
  3301. )
  3302. ) then
  3303. exit;
  3304. is_visible_for_object:=true;
  3305. end;
  3306. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3307. begin
  3308. case t of
  3309. gs_local :
  3310. getsymtable:=localst;
  3311. gs_para :
  3312. getsymtable:=parast;
  3313. else
  3314. getsymtable:=nil;
  3315. end;
  3316. end;
  3317. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3318. var
  3319. pos : tfileposinfo;
  3320. move_last : boolean;
  3321. oldparasymtable,
  3322. oldlocalsymtable : tsymtable;
  3323. begin
  3324. oldparasymtable:=aktparasymtable;
  3325. oldlocalsymtable:=aktlocalsymtable;
  3326. aktparasymtable:=parast;
  3327. aktlocalsymtable:=localst;
  3328. move_last:=lastwritten=lastref;
  3329. while (not ppufile.endofentry) do
  3330. begin
  3331. ppufile.getposinfo(pos);
  3332. inc(refcount);
  3333. lastref:=tref.create(lastref,@pos);
  3334. lastref.is_written:=true;
  3335. if refcount=1 then
  3336. defref:=lastref;
  3337. end;
  3338. if move_last then
  3339. lastwritten:=lastref;
  3340. if ((current_module.flags and uf_local_browser)<>0) and
  3341. locals then
  3342. begin
  3343. tparasymtable(parast).load_references(ppufile,locals);
  3344. tlocalsymtable(localst).load_references(ppufile,locals);
  3345. end;
  3346. aktparasymtable:=oldparasymtable;
  3347. aktlocalsymtable:=oldlocalsymtable;
  3348. end;
  3349. Const
  3350. local_symtable_index : word = $8001;
  3351. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3352. var
  3353. ref : tref;
  3354. pdo : tobjectdef;
  3355. move_last : boolean;
  3356. d : tderef;
  3357. oldparasymtable,
  3358. oldlocalsymtable : tsymtable;
  3359. begin
  3360. d.reset;
  3361. move_last:=lastwritten=lastref;
  3362. if move_last and
  3363. (((current_module.flags and uf_local_browser)=0) or
  3364. not locals) then
  3365. exit;
  3366. oldparasymtable:=aktparasymtable;
  3367. oldlocalsymtable:=aktlocalsymtable;
  3368. aktparasymtable:=parast;
  3369. aktlocalsymtable:=localst;
  3370. { write address of this symbol }
  3371. ppufile.putderef(self,d);
  3372. { write refs }
  3373. if assigned(lastwritten) then
  3374. ref:=lastwritten
  3375. else
  3376. ref:=defref;
  3377. while assigned(ref) do
  3378. begin
  3379. if ref.moduleindex=current_module.unit_index then
  3380. begin
  3381. ppufile.putposinfo(ref.posinfo);
  3382. ref.is_written:=true;
  3383. if move_last then
  3384. lastwritten:=ref;
  3385. end
  3386. else if not ref.is_written then
  3387. move_last:=false
  3388. else if move_last then
  3389. lastwritten:=ref;
  3390. ref:=ref.nextref;
  3391. end;
  3392. ppufile.writeentry(ibdefref);
  3393. write_references:=true;
  3394. if ((current_module.flags and uf_local_browser)<>0) and
  3395. locals then
  3396. begin
  3397. pdo:=_class;
  3398. if (owner.symtabletype<>localsymtable) then
  3399. while assigned(pdo) do
  3400. begin
  3401. if pdo.symtable<>aktrecordsymtable then
  3402. begin
  3403. pdo.symtable.unitid:=local_symtable_index;
  3404. inc(local_symtable_index);
  3405. end;
  3406. pdo:=pdo.childof;
  3407. end;
  3408. parast.unitid:=local_symtable_index;
  3409. inc(local_symtable_index);
  3410. localst.unitid:=local_symtable_index;
  3411. inc(local_symtable_index);
  3412. tstoredsymtable(parast).write_references(ppufile,locals);
  3413. tstoredsymtable(localst).write_references(ppufile,locals);
  3414. { decrement for }
  3415. local_symtable_index:=local_symtable_index-2;
  3416. pdo:=_class;
  3417. if (owner.symtabletype<>localsymtable) then
  3418. while assigned(pdo) do
  3419. begin
  3420. if pdo.symtable<>aktrecordsymtable then
  3421. dec(local_symtable_index);
  3422. pdo:=pdo.childof;
  3423. end;
  3424. end;
  3425. aktparasymtable:=oldparasymtable;
  3426. aktlocalsymtable:=oldlocalsymtable;
  3427. end;
  3428. {$ifdef GDB}
  3429. {$ifdef unused}
  3430. { procedure addparaname(p : tsym);
  3431. var vs : char;
  3432. begin
  3433. if tvarsym(p).varspez = vs_value then vs := '1'
  3434. else vs := '0';
  3435. strpcopy(strend(StabRecString),p^.name+':'+tstoreddef(tvarsym(p).vartype.def).numberstring+','+vs+';');
  3436. end; }
  3437. function tprocdef.stabstring : pchar;
  3438. var
  3439. i : longint;
  3440. stabrecstring : pchar;
  3441. begin
  3442. getmem(StabRecString,1024);
  3443. strpcopy(StabRecString,'f'+tstoreddef(rettype.def).numberstring);
  3444. i:=maxparacount;
  3445. if i>0 then
  3446. begin
  3447. strpcopy(strend(StabRecString),','+tostr(i)+';');
  3448. (* confuse gdb !! PM
  3449. if assigned(parast) then
  3450. parast.foreach({$ifdef FPCPROCVAR}@{$endif}addparaname)
  3451. else
  3452. begin
  3453. param := para1;
  3454. i := 0;
  3455. while assigned(param) do
  3456. begin
  3457. inc(i);
  3458. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3459. {Here we have lost the parameter names !!}
  3460. {using lower case parameters }
  3461. strpcopy(strend(stabrecstring),'p'+tostr(i)
  3462. +':'+param^.paratype.def.numberstring+','+vartyp+';');
  3463. param := param^.next;
  3464. end;
  3465. end; *)
  3466. {strpcopy(strend(StabRecString),';');}
  3467. end;
  3468. stabstring := strnew(stabrecstring);
  3469. freemem(stabrecstring,1024);
  3470. end;
  3471. {$endif unused}
  3472. function tprocdef.stabstring: pchar;
  3473. Var RType : Char;
  3474. Obj,Info : String;
  3475. stabsstr : string;
  3476. p : pchar;
  3477. begin
  3478. obj := procsym.name;
  3479. info := '';
  3480. if tprocsym(procsym).is_global then
  3481. RType := 'F'
  3482. else
  3483. RType := 'f';
  3484. if assigned(owner) then
  3485. begin
  3486. if (owner.symtabletype = objectsymtable) then
  3487. obj := owner.name^+'__'+procsym.name;
  3488. { this code was correct only as long as the local symboltable
  3489. of the parent had the same name as the function
  3490. but this is no true anymore !! PM
  3491. if (owner.symtabletype=localsymtable) and assigned(owner.name) then
  3492. info := ','+name+','+owner.name^; }
  3493. if (owner.symtabletype=localsymtable) and
  3494. assigned(owner.defowner) and
  3495. assigned(tprocdef(owner.defowner).procsym) then
  3496. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3497. end;
  3498. stabsstr:=mangledname;
  3499. getmem(p,length(stabsstr)+255);
  3500. strpcopy(p,'"'+obj+':'+RType
  3501. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3502. +',0,'+
  3503. tostr(fileinfo.line)
  3504. +',');
  3505. strpcopy(strend(p),stabsstr);
  3506. stabstring:=strnew(p);
  3507. freemem(p,length(stabsstr)+255);
  3508. end;
  3509. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3510. begin
  3511. if (proccalloption=pocall_internproc) then
  3512. exit;
  3513. if not isstabwritten then
  3514. asmList.concat(Tai_stabs.Create(stabstring));
  3515. isstabwritten := true;
  3516. if not(po_external in procoptions) then
  3517. begin
  3518. tstoredsymtable(parast).concatstabto(asmlist);
  3519. { local type defs and vars should not be written
  3520. inside the main proc stab }
  3521. if assigned(localst) and
  3522. (localst.symtablelevel>main_program_level) then
  3523. tstoredsymtable(localst).concatstabto(asmlist);
  3524. end;
  3525. is_def_stab_written := written;
  3526. end;
  3527. {$endif GDB}
  3528. procedure tprocdef.deref;
  3529. var
  3530. oldparasymtable,
  3531. oldlocalsymtable : tsymtable;
  3532. begin
  3533. oldparasymtable:=aktparasymtable;
  3534. oldlocalsymtable:=aktlocalsymtable;
  3535. aktparasymtable:=parast;
  3536. aktlocalsymtable:=localst;
  3537. inherited deref;
  3538. _class:=tobjectdef(_classderef.resolve);
  3539. { procsym that originaly defined this definition, should be in the
  3540. same symtable }
  3541. procsym:=tprocsym(procsymderef.resolve);
  3542. aktparasymtable:=oldparasymtable;
  3543. aktlocalsymtable:=oldlocalsymtable;
  3544. end;
  3545. procedure tprocdef.derefimpl;
  3546. var
  3547. oldparasymtable,
  3548. oldlocalsymtable : tsymtable;
  3549. begin
  3550. oldparasymtable:=aktparasymtable;
  3551. oldlocalsymtable:=aktlocalsymtable;
  3552. aktparasymtable:=parast;
  3553. aktlocalsymtable:=localst;
  3554. { locals }
  3555. if assigned(localst) then
  3556. begin
  3557. { localst }
  3558. { we can deref both interface and implementation parts }
  3559. tlocalsymtable(localst).deref;
  3560. tlocalsymtable(localst).derefimpl;
  3561. { funcretsym, this is always located in the localst }
  3562. funcretsym:=tsym(funcretsymderef.resolve);
  3563. end
  3564. else
  3565. begin
  3566. { safety }
  3567. funcretsym:=nil;
  3568. end;
  3569. { inline tree }
  3570. if (proccalloption=pocall_inline) then
  3571. code.derefimpl;
  3572. aktparasymtable:=oldparasymtable;
  3573. aktlocalsymtable:=oldlocalsymtable;
  3574. end;
  3575. function tprocdef.gettypename : string;
  3576. begin
  3577. gettypename := FullProcName(false)+';'+ProcCallOptionStr[proccalloption];
  3578. end;
  3579. function tprocdef.mangledname : string;
  3580. var
  3581. s : string;
  3582. hp : TParaItem;
  3583. begin
  3584. if assigned(_mangledname) then
  3585. begin
  3586. mangledname:=_mangledname^;
  3587. exit;
  3588. end;
  3589. { we need to use the symtable where the procsym is inserted,
  3590. because that is visible to the world }
  3591. s:=mangledname_prefix('',procsym.owner)+procsym.name;
  3592. if overloadnumber>0 then
  3593. s:=s+'$'+tostr(overloadnumber);
  3594. { add parameter types }
  3595. hp:=TParaItem(Para.first);
  3596. while assigned(hp) do
  3597. begin
  3598. if not hp.is_hidden then
  3599. s:=s+'$'+hp.paratype.def.mangledparaname;
  3600. hp:=TParaItem(hp.next);
  3601. end;
  3602. _mangledname:=stringdup(s);
  3603. mangledname:=_mangledname^;
  3604. end;
  3605. function tprocdef.cplusplusmangledname : string;
  3606. function getcppparaname(p : tdef) : string;
  3607. const
  3608. ordtype2str : array[tbasetype] of string[2] = (
  3609. '',
  3610. 'Uc','Us','Ui','Us',
  3611. 'Sc','s','i','x',
  3612. 'b','b','b',
  3613. 'c','w','x');
  3614. var
  3615. s : string;
  3616. begin
  3617. case p.deftype of
  3618. orddef:
  3619. s:=ordtype2str[torddef(p).typ];
  3620. pointerdef:
  3621. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3622. else
  3623. internalerror(2103001);
  3624. end;
  3625. getcppparaname:=s;
  3626. end;
  3627. var
  3628. s,s2 : string;
  3629. param : TParaItem;
  3630. begin
  3631. s := procsym.realname;
  3632. if procsym.owner.symtabletype=objectsymtable then
  3633. begin
  3634. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3635. case proctypeoption of
  3636. potype_destructor:
  3637. s:='_$_'+tostr(length(s2))+s2;
  3638. potype_constructor:
  3639. s:='___'+tostr(length(s2))+s2;
  3640. else
  3641. s:='_'+s+'__'+tostr(length(s2))+s2;
  3642. end;
  3643. end
  3644. else s:=s+'__';
  3645. s:=s+'F';
  3646. { concat modifiers }
  3647. { !!!!! }
  3648. { now we handle the parameters }
  3649. param := TParaItem(Para.first);
  3650. if assigned(param) then
  3651. while assigned(param) do
  3652. begin
  3653. s2:=getcppparaname(param.paratype.def);
  3654. if param.paratyp in [vs_var,vs_out] then
  3655. s2:='R'+s2;
  3656. s:=s+s2;
  3657. param:=TParaItem(param.next);
  3658. end
  3659. else
  3660. s:=s+'v';
  3661. cplusplusmangledname:=s;
  3662. end;
  3663. procedure tprocdef.setmangledname(const s : string);
  3664. begin
  3665. stringdispose(_mangledname);
  3666. _mangledname:=stringdup(s);
  3667. has_mangledname:=true;
  3668. end;
  3669. {***************************************************************************
  3670. TPROCVARDEF
  3671. ***************************************************************************}
  3672. constructor tprocvardef.create(level:byte);
  3673. begin
  3674. inherited create(level);
  3675. deftype:=procvardef;
  3676. end;
  3677. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3678. begin
  3679. inherited ppuload(ppufile);
  3680. deftype:=procvardef;
  3681. { load para symtable }
  3682. parast:=tparasymtable.create(unknown_level);
  3683. tparasymtable(parast).ppuload(ppufile);
  3684. parast.defowner:=self;
  3685. end;
  3686. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3687. var
  3688. oldparasymtable,
  3689. oldlocalsymtable : tsymtable;
  3690. begin
  3691. oldparasymtable:=aktparasymtable;
  3692. oldlocalsymtable:=aktlocalsymtable;
  3693. aktparasymtable:=parast;
  3694. aktlocalsymtable:=nil;
  3695. { here we cannot get a real good value so just give something }
  3696. { plausible (PM) }
  3697. { a more secure way would be
  3698. to allways store in a temp }
  3699. if is_fpu(rettype.def) then
  3700. fpu_used:={2}maxfpuregs
  3701. else
  3702. fpu_used:=0;
  3703. inherited ppuwrite(ppufile);
  3704. { Write this entry }
  3705. ppufile.writeentry(ibprocvardef);
  3706. { Save the para symtable, this is taken from the interface }
  3707. tparasymtable(parast).ppuwrite(ppufile);
  3708. aktparasymtable:=oldparasymtable;
  3709. aktlocalsymtable:=oldlocalsymtable;
  3710. end;
  3711. procedure tprocvardef.deref;
  3712. var
  3713. oldparasymtable,
  3714. oldlocalsymtable : tsymtable;
  3715. begin
  3716. oldparasymtable:=aktparasymtable;
  3717. oldlocalsymtable:=aktlocalsymtable;
  3718. aktparasymtable:=parast;
  3719. aktlocalsymtable:=nil;
  3720. inherited deref;
  3721. aktparasymtable:=oldparasymtable;
  3722. aktlocalsymtable:=oldlocalsymtable;
  3723. end;
  3724. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3725. begin
  3726. case t of
  3727. gs_para :
  3728. getsymtable:=parast;
  3729. else
  3730. getsymtable:=nil;
  3731. end;
  3732. end;
  3733. function tprocvardef.size : longint;
  3734. begin
  3735. if (po_methodpointer in procoptions) and
  3736. not(po_addressonly in procoptions) then
  3737. size:=2*POINTER_SIZE
  3738. else
  3739. size:=POINTER_SIZE;
  3740. end;
  3741. function tprocvardef.is_methodpointer:boolean;
  3742. begin
  3743. result:=(po_methodpointer in procoptions);
  3744. end;
  3745. function tprocvardef.is_addressonly:boolean;
  3746. begin
  3747. result:=not(po_methodpointer in procoptions) or
  3748. (po_addressonly in procoptions);
  3749. end;
  3750. {$ifdef GDB}
  3751. function tprocvardef.stabstring : pchar;
  3752. var
  3753. nss : pchar;
  3754. { i : longint; }
  3755. begin
  3756. { i := maxparacount; }
  3757. getmem(nss,1024);
  3758. { it is not a function but a function pointer !! (PM) }
  3759. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)}+';');
  3760. { this confuses gdb !!
  3761. we should use 'F' instead of 'f' but
  3762. as we use c++ language mode
  3763. it does not like that either
  3764. Please do not remove this part
  3765. might be used once
  3766. gdb for pascal is ready PM }
  3767. (*
  3768. param := para1;
  3769. i := 0;
  3770. while assigned(param) do
  3771. begin
  3772. inc(i);
  3773. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3774. {Here we have lost the parameter names !!}
  3775. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3776. strcat(nss,pst);
  3777. strdispose(pst);
  3778. param := param^.next;
  3779. end; *)
  3780. {strpcopy(strend(nss),';');}
  3781. stabstring := strnew(nss);
  3782. freemem(nss,1024);
  3783. end;
  3784. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3785. begin
  3786. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3787. and (is_def_stab_written = not_written) then
  3788. inherited concatstabto(asmlist);
  3789. is_def_stab_written:=written;
  3790. end;
  3791. {$endif GDB}
  3792. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3793. var
  3794. pdc : TParaItem;
  3795. methodkind, paraspec : byte;
  3796. begin
  3797. if po_methodpointer in procoptions then
  3798. begin
  3799. { write method id and name }
  3800. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3801. write_rtti_name;
  3802. { write kind of method (can only be function or procedure)}
  3803. if rettype.def = voidtype.def then
  3804. methodkind := mkProcedure
  3805. else
  3806. methodkind := mkFunction;
  3807. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3808. { get # of parameters }
  3809. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3810. { write parameter info. The parameters must be written in reverse order
  3811. if this method uses right to left parameter pushing! }
  3812. if proccalloption in pushleftright_pocalls then
  3813. pdc:=TParaItem(Para.first)
  3814. else
  3815. pdc:=TParaItem(Para.last);
  3816. while assigned(pdc) do
  3817. begin
  3818. case pdc.paratyp of
  3819. vs_value: paraspec := 0;
  3820. vs_const: paraspec := pfConst;
  3821. vs_var : paraspec := pfVar;
  3822. vs_out : paraspec := pfOut;
  3823. end;
  3824. { write flags for current parameter }
  3825. rttiList.concat(Tai_const.Create_8bit(paraspec));
  3826. { write name of current parameter ### how can I get this??? (sg)}
  3827. rttiList.concat(Tai_const.Create_8bit(0));
  3828. { write name of type of current parameter }
  3829. tstoreddef(pdc.paratype.def).write_rtti_name;
  3830. if proccalloption in pushleftright_pocalls then
  3831. pdc:=TParaItem(pdc.next)
  3832. else
  3833. pdc:=TParaItem(pdc.previous);
  3834. end;
  3835. { write name of result type }
  3836. tstoreddef(rettype.def).write_rtti_name;
  3837. end;
  3838. end;
  3839. function tprocvardef.is_publishable : boolean;
  3840. begin
  3841. is_publishable:=(po_methodpointer in procoptions);
  3842. end;
  3843. function tprocvardef.gettypename : string;
  3844. var
  3845. s: string;
  3846. showhidden : boolean;
  3847. begin
  3848. {$ifdef EXTDEBUG}
  3849. showhidden:=true;
  3850. {$else EXTDEBUG}
  3851. showhidden:=false;
  3852. {$endif EXTDEBUG}
  3853. s:='<';
  3854. if po_classmethod in procoptions then
  3855. s := s+'class method type of'
  3856. else
  3857. if po_addressonly in procoptions then
  3858. s := s+'address of'
  3859. else
  3860. s := s+'procedure variable type of';
  3861. if assigned(rettype.def) and
  3862. (rettype.def<>voidtype.def) then
  3863. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  3864. else
  3865. s:=s+' procedure'+typename_paras(showhidden);
  3866. if po_methodpointer in procoptions then
  3867. s := s+' of object';
  3868. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3869. end;
  3870. {***************************************************************************
  3871. TOBJECTDEF
  3872. ***************************************************************************}
  3873. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3874. begin
  3875. inherited create;
  3876. objecttype:=ot;
  3877. deftype:=objectdef;
  3878. objectoptions:=[];
  3879. childof:=nil;
  3880. symtable:=tobjectsymtable.create(n);
  3881. { create space for vmt !! }
  3882. vmt_offset:=0;
  3883. symtable.defowner:=self;
  3884. { recordalign -1 means C record packing, that starts
  3885. with an alignment of 1 }
  3886. if aktalignment.recordalignmax=-1 then
  3887. tobjectsymtable(symtable).dataalignment:=1
  3888. else
  3889. tobjectsymtable(symtable).dataalignment:=aktalignment.recordalignmax;
  3890. lastvtableindex:=0;
  3891. set_parent(c);
  3892. objname:=stringdup(upper(n));
  3893. objrealname:=stringdup(n);
  3894. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  3895. prepareguid;
  3896. { setup implemented interfaces }
  3897. if objecttype in [odt_class,odt_interfacecorba] then
  3898. implementedinterfaces:=timplementedinterfaces.create
  3899. else
  3900. implementedinterfaces:=nil;
  3901. {$ifdef GDB}
  3902. writing_class_record_stab:=false;
  3903. {$endif GDB}
  3904. end;
  3905. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3906. var
  3907. i,implintfcount: longint;
  3908. d : tderef;
  3909. begin
  3910. inherited ppuloaddef(ppufile);
  3911. deftype:=objectdef;
  3912. objecttype:=tobjectdeftype(ppufile.getbyte);
  3913. savesize:=ppufile.getlongint;
  3914. vmt_offset:=ppufile.getlongint;
  3915. objrealname:=stringdup(ppufile.getstring);
  3916. objname:=stringdup(upper(objrealname^));
  3917. ppufile.getderef(childofderef);
  3918. ppufile.getsmallset(objectoptions);
  3919. { load guid }
  3920. iidstr:=nil;
  3921. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3922. begin
  3923. new(iidguid);
  3924. ppufile.getguid(iidguid^);
  3925. iidstr:=stringdup(ppufile.getstring);
  3926. lastvtableindex:=ppufile.getlongint;
  3927. end;
  3928. { load implemented interfaces }
  3929. if objecttype in [odt_class,odt_interfacecorba] then
  3930. begin
  3931. implementedinterfaces:=timplementedinterfaces.create;
  3932. implintfcount:=ppufile.getlongint;
  3933. for i:=1 to implintfcount do
  3934. begin
  3935. ppufile.getderef(d);
  3936. implementedinterfaces.addintf_deref(d);
  3937. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  3938. end;
  3939. end
  3940. else
  3941. implementedinterfaces:=nil;
  3942. symtable:=tobjectsymtable.create(objrealname^);
  3943. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  3944. tobjectsymtable(symtable).dataalignment:=ppufile.getbyte;
  3945. tobjectsymtable(symtable).ppuload(ppufile);
  3946. symtable.defowner:=self;
  3947. { handles the predefined class tobject }
  3948. { the last TOBJECT which is loaded gets }
  3949. { it ! }
  3950. if (childof=nil) and
  3951. (objecttype=odt_class) and
  3952. (objname^='TOBJECT') then
  3953. class_tobject:=self;
  3954. if (childof=nil) and
  3955. (objecttype=odt_interfacecom) and
  3956. (objname^='IUNKNOWN') then
  3957. interface_iunknown:=self;
  3958. {$ifdef GDB}
  3959. writing_class_record_stab:=false;
  3960. {$endif GDB}
  3961. end;
  3962. destructor tobjectdef.destroy;
  3963. begin
  3964. if assigned(symtable) then
  3965. symtable.free;
  3966. stringdispose(objname);
  3967. stringdispose(objrealname);
  3968. if assigned(iidstr) then
  3969. stringdispose(iidstr);
  3970. if assigned(implementedinterfaces) then
  3971. implementedinterfaces.free;
  3972. if assigned(iidguid) then
  3973. dispose(iidguid);
  3974. inherited destroy;
  3975. end;
  3976. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3977. var
  3978. implintfcount : longint;
  3979. i : longint;
  3980. begin
  3981. inherited ppuwritedef(ppufile);
  3982. ppufile.putbyte(byte(objecttype));
  3983. ppufile.putlongint(size);
  3984. ppufile.putlongint(vmt_offset);
  3985. ppufile.putstring(objrealname^);
  3986. ppufile.putderef(childof,childofderef);
  3987. ppufile.putsmallset(objectoptions);
  3988. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3989. begin
  3990. ppufile.putguid(iidguid^);
  3991. ppufile.putstring(iidstr^);
  3992. ppufile.putlongint(lastvtableindex);
  3993. end;
  3994. if objecttype in [odt_class,odt_interfacecorba] then
  3995. begin
  3996. implintfcount:=implementedinterfaces.count;
  3997. ppufile.putlongint(implintfcount);
  3998. for i:=1 to implintfcount do
  3999. begin
  4000. ppufile.putderef(implementedinterfaces.interfaces(i),implementedinterfaces.interfacesderef(i));
  4001. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4002. end;
  4003. end;
  4004. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4005. ppufile.putbyte(tobjectsymtable(symtable).dataalignment);
  4006. ppufile.writeentry(ibobjectdef);
  4007. tobjectsymtable(symtable).ppuwrite(ppufile);
  4008. end;
  4009. function tobjectdef.gettypename:string;
  4010. begin
  4011. gettypename:=typename;
  4012. end;
  4013. procedure tobjectdef.deref;
  4014. var
  4015. oldrecsyms : tsymtable;
  4016. begin
  4017. inherited deref;
  4018. childof:=tobjectdef(childofderef.resolve);
  4019. oldrecsyms:=aktrecordsymtable;
  4020. aktrecordsymtable:=symtable;
  4021. tstoredsymtable(symtable).deref;
  4022. aktrecordsymtable:=oldrecsyms;
  4023. if objecttype in [odt_class,odt_interfacecorba] then
  4024. implementedinterfaces.deref;
  4025. end;
  4026. function tobjectdef.getparentdef:tdef;
  4027. begin
  4028. result:=childof;
  4029. end;
  4030. procedure tobjectdef.prepareguid;
  4031. begin
  4032. { set up guid }
  4033. if not assigned(iidguid) then
  4034. begin
  4035. new(iidguid);
  4036. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4037. end;
  4038. { setup iidstring }
  4039. if not assigned(iidstr) then
  4040. iidstr:=stringdup(''); { default is empty string }
  4041. end;
  4042. procedure tobjectdef.set_parent( c : tobjectdef);
  4043. begin
  4044. { nothing to do if the parent was not forward !}
  4045. if assigned(childof) then
  4046. exit;
  4047. childof:=c;
  4048. { some options are inherited !! }
  4049. if assigned(c) then
  4050. begin
  4051. { only important for classes }
  4052. lastvtableindex:=c.lastvtableindex;
  4053. objectoptions:=objectoptions+(c.objectoptions*
  4054. [oo_has_virtual,oo_has_private,oo_has_protected,
  4055. oo_has_constructor,oo_has_destructor]);
  4056. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4057. begin
  4058. { add the data of the anchestor class }
  4059. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4060. if (oo_has_vmt in objectoptions) and
  4061. (oo_has_vmt in c.objectoptions) then
  4062. dec(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4063. { if parent has a vmt field then
  4064. the offset is the same for the child PM }
  4065. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4066. begin
  4067. vmt_offset:=c.vmt_offset;
  4068. include(objectoptions,oo_has_vmt);
  4069. end;
  4070. end;
  4071. end;
  4072. savesize := tobjectsymtable(symtable).datasize;
  4073. end;
  4074. procedure tobjectdef.insertvmt;
  4075. begin
  4076. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4077. exit;
  4078. if (oo_has_vmt in objectoptions) then
  4079. internalerror(12345)
  4080. else
  4081. begin
  4082. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4083. tobjectsymtable(symtable).dataalignment);
  4084. vmt_offset:=tobjectsymtable(symtable).datasize;
  4085. inc(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4086. include(objectoptions,oo_has_vmt);
  4087. end;
  4088. end;
  4089. procedure tobjectdef.check_forwards;
  4090. begin
  4091. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4092. tstoredsymtable(symtable).check_forwards;
  4093. if (oo_is_forward in objectoptions) then
  4094. begin
  4095. { ok, in future, the forward can be resolved }
  4096. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4097. exclude(objectoptions,oo_is_forward);
  4098. end;
  4099. end;
  4100. { true, if self inherits from d (or if they are equal) }
  4101. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4102. var
  4103. hp : tobjectdef;
  4104. begin
  4105. hp:=self;
  4106. while assigned(hp) do
  4107. begin
  4108. if hp=d then
  4109. begin
  4110. is_related:=true;
  4111. exit;
  4112. end;
  4113. hp:=hp.childof;
  4114. end;
  4115. is_related:=false;
  4116. end;
  4117. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4118. var
  4119. p : pprocdeflist;
  4120. begin
  4121. { if we found already a destructor, then we exit }
  4122. if assigned(sd) then
  4123. exit;
  4124. if tsym(sym).typ=procsym then
  4125. begin
  4126. p:=tprocsym(sym).defs;
  4127. while assigned(p) do
  4128. begin
  4129. if p^.def.proctypeoption=potype_destructor then
  4130. begin
  4131. sd:=p^.def;
  4132. exit;
  4133. end;
  4134. p:=p^.next;
  4135. end;
  4136. end;
  4137. end;*)
  4138. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4139. begin
  4140. { if we found already a destructor, then we exit }
  4141. if (ppointer(sd)^=nil) and
  4142. (Tsym(sym).typ=procsym) then
  4143. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4144. end;
  4145. function tobjectdef.searchdestructor : tprocdef;
  4146. var
  4147. o : tobjectdef;
  4148. sd : tprocdef;
  4149. begin
  4150. searchdestructor:=nil;
  4151. o:=self;
  4152. sd:=nil;
  4153. while assigned(o) do
  4154. begin
  4155. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4156. if assigned(sd) then
  4157. begin
  4158. searchdestructor:=sd;
  4159. exit;
  4160. end;
  4161. o:=o.childof;
  4162. end;
  4163. end;
  4164. function tobjectdef.size : longint;
  4165. begin
  4166. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4167. result:=POINTER_SIZE
  4168. else
  4169. result:=tobjectsymtable(symtable).datasize;
  4170. end;
  4171. function tobjectdef.alignment:longint;
  4172. begin
  4173. alignment:=tobjectsymtable(symtable).dataalignment;
  4174. end;
  4175. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4176. begin
  4177. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4178. case objecttype of
  4179. odt_class:
  4180. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  4181. odt_interfacecom,odt_interfacecorba:
  4182. vmtmethodoffset:=index*POINTER_SIZE;
  4183. else
  4184. {$ifdef WITHDMT}
  4185. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  4186. {$else WITHDMT}
  4187. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  4188. {$endif WITHDMT}
  4189. end;
  4190. end;
  4191. function tobjectdef.vmt_mangledname : string;
  4192. begin
  4193. if not(oo_has_vmt in objectoptions) then
  4194. Message1(parser_n_object_has_no_vmt,objrealname^);
  4195. vmt_mangledname:=mangledname_prefix('VMT',owner)+objname^;
  4196. end;
  4197. function tobjectdef.rtti_name : string;
  4198. begin
  4199. rtti_name:=mangledname_prefix('RTTI',owner)+objname^;
  4200. end;
  4201. {$ifdef GDB}
  4202. procedure tobjectdef.addprocname(p :tnamedindexitem;arg:pointer);
  4203. var virtualind,argnames : string;
  4204. news, newrec : pchar;
  4205. pd,ipd : tprocdef;
  4206. lindex : longint;
  4207. para : TParaItem;
  4208. arglength : byte;
  4209. sp : char;
  4210. begin
  4211. If tsym(p).typ = procsym then
  4212. begin
  4213. pd := tprocsym(p).first_procdef;
  4214. { this will be used for full implementation of object stabs
  4215. not yet done }
  4216. ipd := Tprocsym(p).last_procdef;
  4217. if (po_virtualmethod in pd.procoptions) then
  4218. begin
  4219. lindex := pd.extnumber;
  4220. {doesnt seem to be necessary
  4221. lindex := lindex or $80000000;}
  4222. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  4223. end
  4224. else
  4225. virtualind := '.';
  4226. { used by gdbpas to recognize constructor and destructors }
  4227. if (pd.proctypeoption=potype_constructor) then
  4228. argnames:='__ct__'
  4229. else if (pd.proctypeoption=potype_destructor) then
  4230. argnames:='__dt__'
  4231. else
  4232. argnames := '';
  4233. { arguments are not listed here }
  4234. {we don't need another definition}
  4235. para := TParaItem(pd.Para.first);
  4236. while assigned(para) do
  4237. begin
  4238. if Para.paratype.def.deftype = formaldef then
  4239. begin
  4240. if Para.paratyp=vs_var then
  4241. argnames := argnames+'3var'
  4242. else if Para.paratyp=vs_const then
  4243. argnames:=argnames+'5const'
  4244. else if Para.paratyp=vs_out then
  4245. argnames:=argnames+'3out';
  4246. end
  4247. else
  4248. begin
  4249. { if the arg definition is like (v: ^byte;..
  4250. there is no sym attached to data !!! }
  4251. if assigned(Para.paratype.def.typesym) then
  4252. begin
  4253. arglength := length(Para.paratype.def.typesym.name);
  4254. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4255. end
  4256. else
  4257. begin
  4258. argnames:=argnames+'11unnamedtype';
  4259. end;
  4260. end;
  4261. para := TParaItem(Para.next);
  4262. end;
  4263. ipd.is_def_stab_written := written;
  4264. { here 2A must be changed for private and protected }
  4265. { 0 is private 1 protected and 2 public }
  4266. if (sp_private in tsym(p).symoptions) then sp:='0'
  4267. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  4268. else sp:='2';
  4269. newrec := strpnew(p.name+'::'+ipd.numberstring
  4270. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  4271. +virtualind+';');
  4272. { get spare place for a string at the end }
  4273. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  4274. begin
  4275. getmem(news,stabrecsize+memsizeinc);
  4276. strcopy(news,stabrecstring);
  4277. freemem(stabrecstring,stabrecsize);
  4278. stabrecsize:=stabrecsize+memsizeinc;
  4279. stabrecstring:=news;
  4280. end;
  4281. strcat(StabRecstring,newrec);
  4282. {freemem(newrec,memsizeinc); }
  4283. strdispose(newrec);
  4284. {This should be used for case !!
  4285. RecOffset := RecOffset + pd.size;}
  4286. end;
  4287. end;
  4288. function tobjectdef.stabstring : pchar;
  4289. var anc : tobjectdef;
  4290. oldrec : pchar;
  4291. oldrecsize,oldrecoffset : longint;
  4292. str_end : string;
  4293. begin
  4294. if not (objecttype=odt_class) or writing_class_record_stab then
  4295. begin
  4296. oldrec := stabrecstring;
  4297. oldrecsize:=stabrecsize;
  4298. stabrecsize:=memsizeinc;
  4299. GetMem(stabrecstring,stabrecsize);
  4300. strpcopy(stabRecString,'s'+tostr(tobjectsymtable(symtable).datasize));
  4301. if assigned(childof) then
  4302. begin
  4303. {only one ancestor not virtual, public, at base offset 0 }
  4304. { !1 , 0 2 0 , }
  4305. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  4306. end;
  4307. {virtual table to implement yet}
  4308. OldRecOffset:=RecOffset;
  4309. RecOffset := 0;
  4310. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  4311. RecOffset:=OldRecOffset;
  4312. if (oo_has_vmt in objectoptions) then
  4313. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4314. begin
  4315. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  4316. +','+tostr(vmt_offset*8)+';');
  4317. end;
  4318. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname,nil);
  4319. if (oo_has_vmt in objectoptions) then
  4320. begin
  4321. anc := self;
  4322. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4323. anc := anc.childof;
  4324. { just in case anc = self }
  4325. str_end:=';~%'+anc.classnumberstring+';';
  4326. end
  4327. else
  4328. str_end:=';';
  4329. strpcopy(strend(stabrecstring),str_end);
  4330. stabstring := strnew(StabRecString);
  4331. freemem(stabrecstring,stabrecsize);
  4332. stabrecstring := oldrec;
  4333. stabrecsize:=oldrecsize;
  4334. end
  4335. else
  4336. begin
  4337. stabstring:=strpnew('*'+classnumberstring);
  4338. end;
  4339. end;
  4340. procedure tobjectdef.set_globalnb;
  4341. begin
  4342. globalnb:=PglobalTypeCount^;
  4343. inc(PglobalTypeCount^);
  4344. { classes need two type numbers, the globalnb is set to the ptr }
  4345. if objecttype=odt_class then
  4346. begin
  4347. globalnb:=PGlobalTypeCount^;
  4348. inc(PglobalTypeCount^);
  4349. end;
  4350. end;
  4351. function tobjectdef.classnumberstring : string;
  4352. begin
  4353. { write stabs again if needed }
  4354. numberstring;
  4355. if objecttype=odt_class then
  4356. begin
  4357. dec(globalnb);
  4358. classnumberstring:=numberstring;
  4359. inc(globalnb);
  4360. end
  4361. else
  4362. classnumberstring:=numberstring;
  4363. end;
  4364. function tobjectdef.allstabstring : pchar;
  4365. var stabchar : string[2];
  4366. ss,st : pchar;
  4367. sname : string;
  4368. sym_line_no : longint;
  4369. begin
  4370. ss := stabstring;
  4371. getmem(st,strlen(ss)+512);
  4372. stabchar := 't';
  4373. if deftype in tagtypes then
  4374. stabchar := 'Tt';
  4375. if assigned(typesym) then
  4376. begin
  4377. sname := typesym.name;
  4378. sym_line_no:=typesym.fileinfo.line;
  4379. end
  4380. else
  4381. begin
  4382. sname := ' ';
  4383. sym_line_no:=0;
  4384. end;
  4385. if writing_class_record_stab then
  4386. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4387. else
  4388. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4389. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4390. allstabstring := strnew(st);
  4391. freemem(st,strlen(ss)+512);
  4392. strdispose(ss);
  4393. end;
  4394. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4395. var st : pstring;
  4396. begin
  4397. if objecttype<>odt_class then
  4398. begin
  4399. inherited concatstabto(asmlist);
  4400. exit;
  4401. end;
  4402. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4403. (is_def_stab_written = not_written) then
  4404. begin
  4405. if globalnb=0 then
  4406. set_globalnb;
  4407. { Write the record class itself }
  4408. writing_class_record_stab:=true;
  4409. inherited concatstabto(asmlist);
  4410. writing_class_record_stab:=false;
  4411. { Write the invisible pointer class }
  4412. is_def_stab_written:=not_written;
  4413. if assigned(typesym) then
  4414. begin
  4415. st:=typesym.FName;
  4416. typesym.FName:=stringdup(' ');
  4417. end;
  4418. inherited concatstabto(asmlist);
  4419. if assigned(typesym) then
  4420. begin
  4421. stringdispose(typesym.FName);
  4422. typesym.FName:=st;
  4423. end;
  4424. end;
  4425. end;
  4426. {$endif GDB}
  4427. function tobjectdef.needs_inittable : boolean;
  4428. begin
  4429. case objecttype of
  4430. odt_class :
  4431. needs_inittable:=false;
  4432. odt_interfacecom:
  4433. needs_inittable:=true;
  4434. odt_interfacecorba:
  4435. needs_inittable:=is_related(interface_iunknown);
  4436. odt_object:
  4437. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4438. else
  4439. internalerror(200108267);
  4440. end;
  4441. end;
  4442. function tobjectdef.members_need_inittable : boolean;
  4443. begin
  4444. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4445. end;
  4446. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4447. begin
  4448. if needs_prop_entry(tsym(sym)) and
  4449. (tsym(sym).typ<>varsym) then
  4450. inc(count);
  4451. end;
  4452. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4453. var
  4454. proctypesinfo : byte;
  4455. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4456. var
  4457. typvalue : byte;
  4458. hp : psymlistitem;
  4459. address : longint;
  4460. begin
  4461. if not(assigned(proc) and assigned(proc.firstsym)) then
  4462. begin
  4463. rttiList.concat(Tai_const.Create_32bit(1));
  4464. typvalue:=3;
  4465. end
  4466. else if proc.firstsym^.sym.typ=varsym then
  4467. begin
  4468. address:=0;
  4469. hp:=proc.firstsym;
  4470. while assigned(hp) do
  4471. begin
  4472. inc(address,tvarsym(hp^.sym).fieldoffset);
  4473. hp:=hp^.next;
  4474. end;
  4475. rttiList.concat(Tai_const.Create_32bit(address));
  4476. typvalue:=0;
  4477. end
  4478. else
  4479. begin
  4480. if not(po_virtualmethod in tprocdef(proc.def).procoptions) then
  4481. begin
  4482. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.def).mangledname));
  4483. typvalue:=1;
  4484. end
  4485. else
  4486. begin
  4487. { virtual method, write vmt offset }
  4488. rttiList.concat(Tai_const.Create_32bit(
  4489. tprocdef(proc.def)._class.vmtmethodoffset(tprocdef(proc.def).extnumber)));
  4490. typvalue:=2;
  4491. end;
  4492. end;
  4493. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4494. end;
  4495. begin
  4496. if needs_prop_entry(tsym(sym)) then
  4497. case tsym(sym).typ of
  4498. varsym:
  4499. begin
  4500. {$ifdef dummy}
  4501. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4502. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4503. internalerror(1509992);
  4504. { access to implicit class property as field }
  4505. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4506. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4507. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4508. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4509. { per default stored }
  4510. rttiList.concat(Tai_const.Create_32bit(1));
  4511. { index as well as ... }
  4512. rttiList.concat(Tai_const.Create_32bit(0));
  4513. { default value are zero }
  4514. rttiList.concat(Tai_const.Create_32bit(0));
  4515. rttiList.concat(Tai_const.Create_16bit(count));
  4516. inc(count);
  4517. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4518. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4519. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4520. {$endif dummy}
  4521. end;
  4522. propertysym:
  4523. begin
  4524. if ppo_indexed in tpropertysym(sym).propoptions then
  4525. proctypesinfo:=$40
  4526. else
  4527. proctypesinfo:=0;
  4528. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4529. writeproc(tpropertysym(sym).readaccess,0);
  4530. writeproc(tpropertysym(sym).writeaccess,2);
  4531. { isn't it stored ? }
  4532. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4533. begin
  4534. rttiList.concat(Tai_const.Create_32bit(0));
  4535. proctypesinfo:=proctypesinfo or (3 shl 4);
  4536. end
  4537. else
  4538. writeproc(tpropertysym(sym).storedaccess,4);
  4539. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4540. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4541. rttiList.concat(Tai_const.Create_16bit(count));
  4542. inc(count);
  4543. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4544. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4545. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4546. end;
  4547. else internalerror(1509992);
  4548. end;
  4549. end;
  4550. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4551. begin
  4552. if needs_prop_entry(tsym(sym)) then
  4553. begin
  4554. case tsym(sym).typ of
  4555. propertysym:
  4556. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4557. varsym:
  4558. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4559. else
  4560. internalerror(1509991);
  4561. end;
  4562. end;
  4563. end;
  4564. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4565. begin
  4566. FRTTIType:=rt;
  4567. case rt of
  4568. initrtti :
  4569. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4570. fullrtti :
  4571. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4572. else
  4573. internalerror(200108301);
  4574. end;
  4575. end;
  4576. type
  4577. tclasslistitem = class(TLinkedListItem)
  4578. index : longint;
  4579. p : tobjectdef;
  4580. end;
  4581. var
  4582. classtablelist : tlinkedlist;
  4583. tablecount : longint;
  4584. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4585. var
  4586. hp : tclasslistitem;
  4587. begin
  4588. hp:=tclasslistitem(classtablelist.first);
  4589. while assigned(hp) do
  4590. if hp.p=p then
  4591. begin
  4592. searchclasstablelist:=hp;
  4593. exit;
  4594. end
  4595. else
  4596. hp:=tclasslistitem(hp.next);
  4597. searchclasstablelist:=nil;
  4598. end;
  4599. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4600. var
  4601. hp : tclasslistitem;
  4602. begin
  4603. if needs_prop_entry(tsym(sym)) and
  4604. (tsym(sym).typ=varsym) then
  4605. begin
  4606. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4607. internalerror(0206001);
  4608. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4609. if not(assigned(hp)) then
  4610. begin
  4611. hp:=tclasslistitem.create;
  4612. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4613. hp.index:=tablecount;
  4614. classtablelist.concat(hp);
  4615. inc(tablecount);
  4616. end;
  4617. inc(count);
  4618. end;
  4619. end;
  4620. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4621. var
  4622. hp : tclasslistitem;
  4623. begin
  4624. if needs_prop_entry(tsym(sym)) and
  4625. (tsym(sym).typ=varsym) then
  4626. begin
  4627. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4628. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4629. if not(assigned(hp)) then
  4630. internalerror(0206002);
  4631. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4632. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4633. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4634. end;
  4635. end;
  4636. function tobjectdef.generate_field_table : tasmlabel;
  4637. var
  4638. fieldtable,
  4639. classtable : tasmlabel;
  4640. hp : tclasslistitem;
  4641. begin
  4642. classtablelist:=TLinkedList.Create;
  4643. objectlibrary.getdatalabel(fieldtable);
  4644. objectlibrary.getdatalabel(classtable);
  4645. count:=0;
  4646. tablecount:=0;
  4647. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4648. if (cs_create_smart in aktmoduleswitches) then
  4649. rttiList.concat(Tai_cut.Create);
  4650. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4651. rttiList.concat(Tai_label.Create(fieldtable));
  4652. rttiList.concat(Tai_const.Create_16bit(count));
  4653. rttiList.concat(Tai_const_symbol.Create(classtable));
  4654. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4655. { generate the class table }
  4656. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4657. rttiList.concat(Tai_label.Create(classtable));
  4658. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4659. hp:=tclasslistitem(classtablelist.first);
  4660. while assigned(hp) do
  4661. begin
  4662. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4663. hp:=tclasslistitem(hp.next);
  4664. end;
  4665. generate_field_table:=fieldtable;
  4666. classtablelist.free;
  4667. end;
  4668. function tobjectdef.next_free_name_index : longint;
  4669. var
  4670. i : longint;
  4671. begin
  4672. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4673. i:=childof.next_free_name_index
  4674. else
  4675. i:=0;
  4676. count:=0;
  4677. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4678. next_free_name_index:=i+count;
  4679. end;
  4680. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4681. begin
  4682. case objecttype of
  4683. odt_class:
  4684. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4685. odt_object:
  4686. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4687. odt_interfacecom:
  4688. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4689. odt_interfacecorba:
  4690. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4691. else
  4692. exit;
  4693. end;
  4694. { generate the name }
  4695. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4696. rttiList.concat(Tai_string.Create(objrealname^));
  4697. case rt of
  4698. initrtti :
  4699. begin
  4700. rttiList.concat(Tai_const.Create_32bit(size));
  4701. if objecttype in [odt_class,odt_object] then
  4702. begin
  4703. count:=0;
  4704. FRTTIType:=rt;
  4705. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4706. rttiList.concat(Tai_const.Create_32bit(count));
  4707. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4708. end;
  4709. end;
  4710. fullrtti :
  4711. begin
  4712. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4713. rttiList.concat(Tai_const.Create_32bit(0))
  4714. else
  4715. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname));
  4716. { write owner typeinfo }
  4717. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4718. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4719. else
  4720. rttiList.concat(Tai_const.Create_32bit(0));
  4721. { count total number of properties }
  4722. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4723. count:=childof.next_free_name_index
  4724. else
  4725. count:=0;
  4726. { write it }
  4727. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4728. rttiList.concat(Tai_const.Create_16bit(count));
  4729. { write unit name }
  4730. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4731. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4732. { write published properties count }
  4733. count:=0;
  4734. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4735. rttiList.concat(Tai_const.Create_16bit(count));
  4736. { count is used to write nameindex }
  4737. { but we need an offset of the owner }
  4738. { to give each property an own slot }
  4739. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4740. count:=childof.next_free_name_index
  4741. else
  4742. count:=0;
  4743. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4744. end;
  4745. end;
  4746. end;
  4747. function tobjectdef.is_publishable : boolean;
  4748. begin
  4749. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4750. end;
  4751. {****************************************************************************
  4752. TIMPLEMENTEDINTERFACES
  4753. ****************************************************************************}
  4754. type
  4755. tnamemap = class(TNamedIndexItem)
  4756. newname: pstring;
  4757. constructor create(const aname, anewname: string);
  4758. destructor destroy; override;
  4759. end;
  4760. constructor tnamemap.create(const aname, anewname: string);
  4761. begin
  4762. inherited createname(name);
  4763. newname:=stringdup(anewname);
  4764. end;
  4765. destructor tnamemap.destroy;
  4766. begin
  4767. stringdispose(newname);
  4768. inherited destroy;
  4769. end;
  4770. type
  4771. tprocdefstore = class(TNamedIndexItem)
  4772. procdef: tprocdef;
  4773. constructor create(aprocdef: tprocdef);
  4774. end;
  4775. constructor tprocdefstore.create(aprocdef: tprocdef);
  4776. begin
  4777. inherited create;
  4778. procdef:=aprocdef;
  4779. end;
  4780. type
  4781. timplintfentry = class(TNamedIndexItem)
  4782. intf: tobjectdef;
  4783. intfderef : tderef;
  4784. ioffs: longint;
  4785. namemappings: tdictionary;
  4786. procdefs: TIndexArray;
  4787. constructor create(aintf: tobjectdef);
  4788. constructor create_deref(const d:tderef);
  4789. destructor destroy; override;
  4790. end;
  4791. constructor timplintfentry.create(aintf: tobjectdef);
  4792. begin
  4793. inherited create;
  4794. intf:=aintf;
  4795. ioffs:=-1;
  4796. namemappings:=nil;
  4797. procdefs:=nil;
  4798. end;
  4799. constructor timplintfentry.create_deref(const d:tderef);
  4800. begin
  4801. inherited create;
  4802. intf:=nil;
  4803. intfderef:=d;
  4804. ioffs:=-1;
  4805. namemappings:=nil;
  4806. procdefs:=nil;
  4807. end;
  4808. destructor timplintfentry.destroy;
  4809. begin
  4810. if assigned(namemappings) then
  4811. namemappings.free;
  4812. if assigned(procdefs) then
  4813. procdefs.free;
  4814. inherited destroy;
  4815. end;
  4816. constructor timplementedinterfaces.create;
  4817. begin
  4818. finterfaces:=tindexarray.create(1);
  4819. end;
  4820. destructor timplementedinterfaces.destroy;
  4821. begin
  4822. finterfaces.destroy;
  4823. end;
  4824. function timplementedinterfaces.count: longint;
  4825. begin
  4826. count:=finterfaces.count;
  4827. end;
  4828. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4829. begin
  4830. if (intfindex<1) or (intfindex>count) then
  4831. InternalError(200006123);
  4832. end;
  4833. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4834. begin
  4835. checkindex(intfindex);
  4836. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4837. end;
  4838. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  4839. begin
  4840. checkindex(intfindex);
  4841. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  4842. end;
  4843. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  4844. begin
  4845. checkindex(intfindex);
  4846. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  4847. end;
  4848. function timplementedinterfaces.searchintf(def: tdef): longint;
  4849. var
  4850. i: longint;
  4851. begin
  4852. i:=1;
  4853. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4854. if i<=count then
  4855. searchintf:=i
  4856. else
  4857. searchintf:=-1;
  4858. end;
  4859. procedure timplementedinterfaces.deref;
  4860. var
  4861. i: longint;
  4862. begin
  4863. for i:=1 to count do
  4864. with timplintfentry(finterfaces.search(i)) do
  4865. intf:=tobjectdef(intfderef.resolve);
  4866. end;
  4867. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  4868. begin
  4869. finterfaces.insert(timplintfentry.create_deref(d));
  4870. end;
  4871. procedure timplementedinterfaces.addintf(def: tdef);
  4872. begin
  4873. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4874. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4875. internalerror(200006124);
  4876. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4877. end;
  4878. procedure timplementedinterfaces.clearmappings;
  4879. var
  4880. i: longint;
  4881. begin
  4882. for i:=1 to count do
  4883. with timplintfentry(finterfaces.search(i)) do
  4884. begin
  4885. if assigned(namemappings) then
  4886. namemappings.free;
  4887. namemappings:=nil;
  4888. end;
  4889. end;
  4890. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  4891. begin
  4892. checkindex(intfindex);
  4893. with timplintfentry(finterfaces.search(intfindex)) do
  4894. begin
  4895. if not assigned(namemappings) then
  4896. namemappings:=tdictionary.create;
  4897. namemappings.insert(tnamemap.create(name,newname));
  4898. end;
  4899. end;
  4900. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  4901. begin
  4902. checkindex(intfindex);
  4903. if not assigned(nextexist) then
  4904. with timplintfentry(finterfaces.search(intfindex)) do
  4905. begin
  4906. if assigned(namemappings) then
  4907. nextexist:=namemappings.search(name)
  4908. else
  4909. nextexist:=nil;
  4910. end;
  4911. if assigned(nextexist) then
  4912. begin
  4913. getmappings:=tnamemap(nextexist).newname^;
  4914. nextexist:=tnamemap(nextexist).listnext;
  4915. end
  4916. else
  4917. getmappings:='';
  4918. end;
  4919. procedure timplementedinterfaces.clearimplprocs;
  4920. var
  4921. i: longint;
  4922. begin
  4923. for i:=1 to count do
  4924. with timplintfentry(finterfaces.search(i)) do
  4925. begin
  4926. if assigned(procdefs) then
  4927. procdefs.free;
  4928. procdefs:=nil;
  4929. end;
  4930. end;
  4931. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4932. begin
  4933. checkindex(intfindex);
  4934. with timplintfentry(finterfaces.search(intfindex)) do
  4935. begin
  4936. if not assigned(procdefs) then
  4937. procdefs:=tindexarray.create(4);
  4938. procdefs.insert(tprocdefstore.create(procdef));
  4939. end;
  4940. end;
  4941. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4942. begin
  4943. checkindex(intfindex);
  4944. with timplintfentry(finterfaces.search(intfindex)) do
  4945. if assigned(procdefs) then
  4946. implproccount:=procdefs.count
  4947. else
  4948. implproccount:=0;
  4949. end;
  4950. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4951. begin
  4952. checkindex(intfindex);
  4953. with timplintfentry(finterfaces.search(intfindex)) do
  4954. if assigned(procdefs) then
  4955. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4956. else
  4957. internalerror(200006131);
  4958. end;
  4959. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4960. var
  4961. possible: boolean;
  4962. i: longint;
  4963. iiep1: TIndexArray;
  4964. iiep2: TIndexArray;
  4965. begin
  4966. checkindex(intfindex);
  4967. checkindex(remainindex);
  4968. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4969. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4970. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4971. begin
  4972. possible:=true;
  4973. weight:=0;
  4974. end
  4975. else
  4976. begin
  4977. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4978. i:=1;
  4979. while (possible) and (i<=iiep1.count) do
  4980. begin
  4981. possible:=
  4982. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4983. inc(i);
  4984. end;
  4985. if possible then
  4986. weight:=iiep1.count;
  4987. end;
  4988. isimplmergepossible:=possible;
  4989. end;
  4990. {****************************************************************************
  4991. TFORWARDDEF
  4992. ****************************************************************************}
  4993. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4994. var
  4995. oldregisterdef : boolean;
  4996. begin
  4997. { never register the forwarddefs, they are disposed at the
  4998. end of the type declaration block }
  4999. oldregisterdef:=registerdef;
  5000. registerdef:=false;
  5001. inherited create;
  5002. registerdef:=oldregisterdef;
  5003. deftype:=forwarddef;
  5004. tosymname:=stringdup(s);
  5005. forwardpos:=pos;
  5006. end;
  5007. function tforwarddef.gettypename:string;
  5008. begin
  5009. gettypename:='unresolved forward to '+tosymname^;
  5010. end;
  5011. destructor tforwarddef.destroy;
  5012. begin
  5013. if assigned(tosymname) then
  5014. stringdispose(tosymname);
  5015. inherited destroy;
  5016. end;
  5017. {****************************************************************************
  5018. TERRORDEF
  5019. ****************************************************************************}
  5020. constructor terrordef.create;
  5021. begin
  5022. inherited create;
  5023. deftype:=errordef;
  5024. end;
  5025. {$ifdef GDB}
  5026. function terrordef.stabstring : pchar;
  5027. begin
  5028. stabstring:=strpnew('error'+numberstring);
  5029. end;
  5030. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5031. begin
  5032. { No internal error needed, an normal error is already
  5033. thrown }
  5034. end;
  5035. {$endif GDB}
  5036. function terrordef.gettypename:string;
  5037. begin
  5038. gettypename:='<erroneous type>';
  5039. end;
  5040. function terrordef.getmangledparaname:string;
  5041. begin
  5042. getmangledparaname:='error';
  5043. end;
  5044. {****************************************************************************
  5045. GDB Helpers
  5046. ****************************************************************************}
  5047. {$ifdef GDB}
  5048. function typeglobalnumber(const s : string) : string;
  5049. var st : string;
  5050. symt : tsymtable;
  5051. srsym : tsym;
  5052. srsymtable : tsymtable;
  5053. old_make_ref : boolean;
  5054. begin
  5055. old_make_ref:=make_ref;
  5056. make_ref:=false;
  5057. typeglobalnumber := '0';
  5058. srsym := nil;
  5059. if pos('.',s) > 0 then
  5060. begin
  5061. st := copy(s,1,pos('.',s)-1);
  5062. searchsym(st,srsym,srsymtable);
  5063. st := copy(s,pos('.',s)+1,255);
  5064. if assigned(srsym) then
  5065. begin
  5066. if srsym.typ = unitsym then
  5067. begin
  5068. symt := tunitsym(srsym).unitsymtable;
  5069. srsym := tsym(symt.search(st));
  5070. end else srsym := nil;
  5071. end;
  5072. end else st := s;
  5073. if srsym = nil then
  5074. searchsym(st,srsym,srsymtable);
  5075. if (srsym=nil) or
  5076. (srsym.typ<>typesym) then
  5077. begin
  5078. Message(type_e_type_id_expected);
  5079. exit;
  5080. end;
  5081. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  5082. make_ref:=old_make_ref;
  5083. end;
  5084. {$endif GDB}
  5085. {****************************************************************************
  5086. Definition Helpers
  5087. ****************************************************************************}
  5088. procedure reset_global_defs;
  5089. var
  5090. def : tstoreddef;
  5091. {$ifdef debug}
  5092. prevdef : tstoreddef;
  5093. {$endif debug}
  5094. begin
  5095. {$ifdef debug}
  5096. prevdef:=nil;
  5097. {$endif debug}
  5098. {$ifdef GDB}
  5099. pglobaltypecount:=@globaltypecount;
  5100. {$endif GDB}
  5101. def:=firstglobaldef;
  5102. while assigned(def) do
  5103. begin
  5104. {$ifdef GDB}
  5105. if assigned(def.typesym) then
  5106. ttypesym(def.typesym).isusedinstab:=false;
  5107. def.is_def_stab_written:=not_written;
  5108. {$endif GDB}
  5109. if assigned(def.rttitablesym) then
  5110. trttisym(def.rttitablesym).lab := nil;
  5111. if assigned(def.inittablesym) then
  5112. trttisym(def.inittablesym).lab := nil;
  5113. def.localrttilab[initrtti]:=nil;
  5114. def.localrttilab[fullrtti]:=nil;
  5115. {$ifdef debug}
  5116. prevdef:=def;
  5117. {$endif debug}
  5118. def:=def.nextglobal;
  5119. end;
  5120. end;
  5121. function is_interfacecom(def: tdef): boolean;
  5122. begin
  5123. is_interfacecom:=
  5124. assigned(def) and
  5125. (def.deftype=objectdef) and
  5126. (tobjectdef(def).objecttype=odt_interfacecom);
  5127. end;
  5128. function is_interfacecorba(def: tdef): boolean;
  5129. begin
  5130. is_interfacecorba:=
  5131. assigned(def) and
  5132. (def.deftype=objectdef) and
  5133. (tobjectdef(def).objecttype=odt_interfacecorba);
  5134. end;
  5135. function is_interface(def: tdef): boolean;
  5136. begin
  5137. is_interface:=
  5138. assigned(def) and
  5139. (def.deftype=objectdef) and
  5140. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5141. end;
  5142. function is_class(def: tdef): boolean;
  5143. begin
  5144. is_class:=
  5145. assigned(def) and
  5146. (def.deftype=objectdef) and
  5147. (tobjectdef(def).objecttype=odt_class);
  5148. end;
  5149. function is_object(def: tdef): boolean;
  5150. begin
  5151. is_object:=
  5152. assigned(def) and
  5153. (def.deftype=objectdef) and
  5154. (tobjectdef(def).objecttype=odt_object);
  5155. end;
  5156. function is_cppclass(def: tdef): boolean;
  5157. begin
  5158. is_cppclass:=
  5159. assigned(def) and
  5160. (def.deftype=objectdef) and
  5161. (tobjectdef(def).objecttype=odt_cppclass);
  5162. end;
  5163. function is_class_or_interface(def: tdef): boolean;
  5164. begin
  5165. is_class_or_interface:=
  5166. assigned(def) and
  5167. (def.deftype=objectdef) and
  5168. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5169. end;
  5170. end.
  5171. {
  5172. $Log$
  5173. Revision 1.168 2003-10-01 20:34:49 peter
  5174. * procinfo unit contains tprocinfo
  5175. * cginfo renamed to cgbase
  5176. * moved cgmessage to verbose
  5177. * fixed ppc and sparc compiles
  5178. Revision 1.167 2003/10/01 16:49:05 florian
  5179. * para items are now reversed for pascal calling conventions
  5180. Revision 1.166 2003/10/01 15:32:58 florian
  5181. * fixed FullProcName to handle constructors, destructors and operators correctly
  5182. Revision 1.165 2003/10/01 15:00:02 peter
  5183. * don't write parast,localst debug info for externals
  5184. Revision 1.164 2003/09/23 21:03:35 peter
  5185. * connect parasym to paraitem
  5186. Revision 1.163 2003/09/23 17:56:06 peter
  5187. * locals and paras are allocated in the code generation
  5188. * tvarsym.localloc contains the location of para/local when
  5189. generating code for the current procedure
  5190. Revision 1.162 2003/09/07 22:09:35 peter
  5191. * preparations for different default calling conventions
  5192. * various RA fixes
  5193. Revision 1.161 2003/09/06 22:27:09 florian
  5194. * fixed web bug 2669
  5195. * cosmetic fix in printnode
  5196. * tobjectdef.gettypename implemented
  5197. Revision 1.160 2003/09/03 15:55:01 peter
  5198. * NEWRA branch merged
  5199. Revision 1.159 2003/09/03 11:18:37 florian
  5200. * fixed arm concatcopy
  5201. + arm support in the common compiler sources added
  5202. * moved some generic cg code around
  5203. + tfputype added
  5204. * ...
  5205. Revision 1.158.2.2 2003/08/29 17:28:59 peter
  5206. * next batch of updates
  5207. Revision 1.158.2.1 2003/08/27 19:55:54 peter
  5208. * first tregister patch
  5209. Revision 1.158 2003/08/11 21:18:20 peter
  5210. * start of sparc support for newra
  5211. Revision 1.157 2003/07/08 15:20:56 peter
  5212. * don't allow add/assignments for formaldef
  5213. * formaldef size changed to 0
  5214. Revision 1.156 2003/07/06 21:50:33 jonas
  5215. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  5216. so that it doesn't include ebp and esp anymore
  5217. Revision 1.155 2003/07/06 15:31:21 daniel
  5218. * Fixed register allocator. *Lots* of fixes.
  5219. Revision 1.154 2003/07/02 22:18:04 peter
  5220. * paraloc splitted in callerparaloc,calleeparaloc
  5221. * sparc calling convention updates
  5222. Revision 1.153 2003/06/25 18:31:23 peter
  5223. * sym,def resolving partly rewritten to support also parent objects
  5224. not directly available through the uses clause
  5225. Revision 1.152 2003/06/17 16:34:44 jonas
  5226. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  5227. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  5228. processor dependent
  5229. Revision 1.151 2003/06/08 11:41:21 peter
  5230. * set parast.next to the owner of the procdef
  5231. Revision 1.150 2003/06/07 20:26:32 peter
  5232. * re-resolving added instead of reloading from ppu
  5233. * tderef object added to store deref info for resolving
  5234. Revision 1.149 2003/06/05 20:05:55 peter
  5235. * removed changesettype because that will change the definition
  5236. of the setdef forever and can result in a different between
  5237. original interface and current implementation definition
  5238. Revision 1.148 2003/06/03 13:01:59 daniel
  5239. * Register allocator finished
  5240. Revision 1.147 2003/06/02 22:55:28 florian
  5241. * classes and interfaces can be stored in integer registers
  5242. Revision 1.146 2003/05/26 21:17:18 peter
  5243. * procinlinenode removed
  5244. * aktexit2label removed, fast exit removed
  5245. + tcallnode.inlined_pass_2 added
  5246. Revision 1.145 2003/05/25 11:34:17 peter
  5247. * methodpointer self pushing fixed
  5248. Revision 1.144 2003/05/15 18:58:53 peter
  5249. * removed selfpointer_offset, vmtpointer_offset
  5250. * tvarsym.adjusted_address
  5251. * address in localsymtable is now in the real direction
  5252. * removed some obsolete globals
  5253. Revision 1.143 2003/05/13 08:13:16 jonas
  5254. * patch from Peter for rtti symbols
  5255. Revision 1.142 2003/05/11 21:37:03 peter
  5256. * moved implicit exception frame from ncgutil to psub
  5257. * constructor/destructor helpers moved from cobj/ncgutil to psub
  5258. Revision 1.141 2003/05/09 17:47:03 peter
  5259. * self moved to hidden parameter
  5260. * removed hdisposen,hnewn,selfn
  5261. Revision 1.140 2003/05/05 14:53:16 peter
  5262. * vs_hidden replaced by is_hidden boolean
  5263. Revision 1.139 2003/05/01 07:59:43 florian
  5264. * introduced defaultordconsttype to decribe the default size of ordinal constants
  5265. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  5266. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  5267. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  5268. Revision 1.138 2003/04/27 11:21:34 peter
  5269. * aktprocdef renamed to current_procdef
  5270. * procinfo renamed to current_procinfo
  5271. * procinfo will now be stored in current_module so it can be
  5272. cleaned up properly
  5273. * gen_main_procsym changed to create_main_proc and release_main_proc
  5274. to also generate a tprocinfo structure
  5275. * fixed unit implicit initfinal
  5276. Revision 1.137 2003/04/27 07:29:51 peter
  5277. * current_procdef cleanup, current_procdef is now always nil when parsing
  5278. a new procdef declaration
  5279. * aktprocsym removed
  5280. * lexlevel removed, use symtable.symtablelevel instead
  5281. * implicit init/final code uses the normal genentry/genexit
  5282. * funcret state checking updated for new funcret handling
  5283. Revision 1.136 2003/04/25 20:59:35 peter
  5284. * removed funcretn,funcretsym, function result is now in varsym
  5285. and aliases for result and function name are added using absolutesym
  5286. * vs_hidden parameter for funcret passed in parameter
  5287. * vs_hidden fixes
  5288. * writenode changed to printnode and released from extdebug
  5289. * -vp option added to generate a tree.log with the nodetree
  5290. * nicer printnode for statements, callnode
  5291. Revision 1.135 2003/04/23 20:16:04 peter
  5292. + added currency support based on int64
  5293. + is_64bit for use in cg units instead of is_64bitint
  5294. * removed cgmessage from n386add, replace with internalerrors
  5295. Revision 1.134 2003/04/23 12:35:34 florian
  5296. * fixed several issues with powerpc
  5297. + applied a patch from Jonas for nested function calls (PowerPC only)
  5298. * ...
  5299. Revision 1.133 2003/04/10 17:57:53 peter
  5300. * vs_hidden released
  5301. Revision 1.132 2003/03/18 16:25:50 peter
  5302. * no itnernalerror for errordef.concatstabto()
  5303. Revision 1.131 2003/03/17 16:54:41 peter
  5304. * support DefaultHandler and anonymous inheritance fixed
  5305. for message methods
  5306. Revision 1.130 2003/03/17 15:54:22 peter
  5307. * store symoptions also for procdef
  5308. * check symoptions (private,public) when calculating possible
  5309. overload candidates
  5310. Revision 1.129 2003/02/19 22:00:14 daniel
  5311. * Code generator converted to new register notation
  5312. - Horribily outdated todo.txt removed
  5313. Revision 1.128 2003/02/02 19:25:54 carl
  5314. * Several bugfixes for m68k target (register alloc., opcode emission)
  5315. + VIS target
  5316. + Generic add more complete (still not verified)
  5317. Revision 1.127 2003/01/21 14:36:44 pierre
  5318. * set sizes needs to be passes in bits not bytes to stabs info
  5319. Revision 1.126 2003/01/16 22:11:33 peter
  5320. * fixed tprocdef.is_addressonly
  5321. Revision 1.125 2003/01/15 01:44:33 peter
  5322. * merged methodpointer fixes from 1.0.x
  5323. Revision 1.124 2003/01/09 21:52:37 peter
  5324. * merged some verbosity options.
  5325. * V_LineInfo is a verbosity flag to include line info
  5326. Revision 1.123 2003/01/06 21:16:52 peter
  5327. * po_addressonly added to retrieve the address of a methodpointer
  5328. only, this is used for @tclass.method which has no self pointer
  5329. Revision 1.122 2003/01/05 15:54:15 florian
  5330. + added proper support of type = type <type>; for simple types
  5331. Revision 1.121 2003/01/05 13:36:53 florian
  5332. * x86-64 compiles
  5333. + very basic support for float128 type (x86-64 only)
  5334. Revision 1.120 2003/01/02 19:49:00 peter
  5335. * update self parameter only for methodpointer and methods
  5336. Revision 1.119 2002/12/29 18:25:59 peter
  5337. * tprocdef.gettypename implemented
  5338. Revision 1.118 2002/12/27 15:23:09 peter
  5339. * write class methods in fullname
  5340. Revision 1.117 2002/12/15 19:34:31 florian
  5341. + some front end stuff for vs_hidden added
  5342. Revision 1.116 2002/12/15 11:26:02 peter
  5343. * ignore vs_hidden parameters when choosing overloaded proc
  5344. Revision 1.115 2002/12/07 14:27:09 carl
  5345. * 3% memory optimization
  5346. * changed some types
  5347. + added type checking with different size for call node and for
  5348. parameters
  5349. Revision 1.114 2002/12/01 22:05:27 carl
  5350. * no more warnings for structures over 32K since this is
  5351. handled correctly in this version of the compiler.
  5352. Revision 1.113 2002/11/27 20:04:09 peter
  5353. * tvarsym.get_push_size replaced by paramanager.push_size
  5354. Revision 1.112 2002/11/25 21:05:53 carl
  5355. * several mistakes fixed in message files
  5356. Revision 1.111 2002/11/25 18:43:33 carl
  5357. - removed the invalid if <> checking (Delphi is strange on this)
  5358. + implemented abstract warning on instance creation of class with
  5359. abstract methods.
  5360. * some error message cleanups
  5361. Revision 1.110 2002/11/25 17:43:24 peter
  5362. * splitted defbase in defutil,symutil,defcmp
  5363. * merged isconvertable and is_equal into compare_defs(_ext)
  5364. * made operator search faster by walking the list only once
  5365. Revision 1.109 2002/11/23 22:50:06 carl
  5366. * some small speed optimizations
  5367. + added several new warnings/hints
  5368. Revision 1.108 2002/11/22 22:48:10 carl
  5369. * memory optimization with tconstsym (1.5%)
  5370. Revision 1.107 2002/11/19 16:21:29 pierre
  5371. * correct several stabs generation problems
  5372. Revision 1.106 2002/11/18 17:31:59 peter
  5373. * pass proccalloption to ret_in_xxx and push_xxx functions
  5374. Revision 1.105 2002/11/17 16:31:57 carl
  5375. * memory optimization (3-4%) : cleanup of tai fields,
  5376. cleanup of tdef and tsym fields.
  5377. * make it work for m68k
  5378. Revision 1.104 2002/11/16 19:53:18 carl
  5379. * avoid Range check errors
  5380. Revision 1.103 2002/11/15 16:29:09 peter
  5381. * fixed rtti for int64 (merged)
  5382. Revision 1.102 2002/11/15 01:58:54 peter
  5383. * merged changes from 1.0.7 up to 04-11
  5384. - -V option for generating bug report tracing
  5385. - more tracing for option parsing
  5386. - errors for cdecl and high()
  5387. - win32 import stabs
  5388. - win32 records<=8 are returned in eax:edx (turned off by default)
  5389. - heaptrc update
  5390. - more info for temp management in .s file with EXTDEBUG
  5391. Revision 1.101 2002/11/09 15:31:02 carl
  5392. + align RTTI tables
  5393. Revision 1.100 2002/10/19 15:09:25 peter
  5394. + tobjectdef.members_need_inittable that is used to generate only the
  5395. inittable when it is really used. This saves a lot of useless calls
  5396. to fpc_finalize when destroying classes
  5397. Revision 1.99 2002/10/07 21:30:27 peter
  5398. * removed obsolete rangecheck stuff
  5399. Revision 1.98 2002/10/05 15:14:26 peter
  5400. * getparamangeldname for errordef
  5401. Revision 1.97 2002/10/05 12:43:28 carl
  5402. * fixes for Delphi 6 compilation
  5403. (warning : Some features do not work under Delphi)
  5404. Revision 1.96 2002/09/27 21:13:29 carl
  5405. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  5406. Revision 1.95 2002/09/16 09:31:10 florian
  5407. * fixed currency size
  5408. Revision 1.94 2002/09/09 17:34:15 peter
  5409. * tdicationary.replace added to replace and item in a dictionary. This
  5410. is only allowed for the same name
  5411. * varsyms are inserted in symtable before the types are parsed. This
  5412. fixes the long standing "var longint : longint" bug
  5413. - consume_idlist and idstringlist removed. The loops are inserted
  5414. at the callers place and uses the symtable for duplicate id checking
  5415. Revision 1.93 2002/09/07 15:25:07 peter
  5416. * old logs removed and tabs fixed
  5417. Revision 1.92 2002/09/05 19:29:42 peter
  5418. * memdebug enhancements
  5419. Revision 1.91 2002/08/25 19:25:20 peter
  5420. * sym.insert_in_data removed
  5421. * symtable.insertvardata/insertconstdata added
  5422. * removed insert_in_data call from symtable.insert, it needs to be
  5423. called separatly. This allows to deref the address calculation
  5424. * procedures now calculate the parast addresses after the procedure
  5425. directives are parsed. This fixes the cdecl parast problem
  5426. * push_addr_param has an extra argument that specifies if cdecl is used
  5427. or not
  5428. Revision 1.90 2002/08/18 20:06:25 peter
  5429. * inlining is now also allowed in interface
  5430. * renamed write/load to ppuwrite/ppuload
  5431. * tnode storing in ppu
  5432. * nld,ncon,nbas are already updated for storing in ppu
  5433. Revision 1.89 2002/08/11 15:28:00 florian
  5434. + support of explicit type case <any ordinal type>->pointer
  5435. (delphi mode only)
  5436. Revision 1.88 2002/08/11 14:32:28 peter
  5437. * renamed current_library to objectlibrary
  5438. Revision 1.87 2002/08/11 13:24:13 peter
  5439. * saving of asmsymbols in ppu supported
  5440. * asmsymbollist global is removed and moved into a new class
  5441. tasmlibrarydata that will hold the info of a .a file which
  5442. corresponds with a single module. Added librarydata to tmodule
  5443. to keep the library info stored for the module. In the future the
  5444. objectfiles will also be stored to the tasmlibrarydata class
  5445. * all getlabel/newasmsymbol and friends are moved to the new class
  5446. Revision 1.86 2002/08/09 07:33:03 florian
  5447. * a couple of interface related fixes
  5448. Revision 1.85 2002/07/23 09:51:24 daniel
  5449. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  5450. are worth comitting.
  5451. Revision 1.84 2002/07/20 11:57:57 florian
  5452. * types.pas renamed to defbase.pas because D6 contains a types
  5453. unit so this would conflicts if D6 programms are compiled
  5454. + Willamette/SSE2 instructions to assembler added
  5455. Revision 1.83 2002/07/11 14:41:30 florian
  5456. * start of the new generic parameter handling
  5457. Revision 1.82 2002/07/07 09:52:32 florian
  5458. * powerpc target fixed, very simple units can be compiled
  5459. * some basic stuff for better callparanode handling, far from being finished
  5460. Revision 1.81 2002/07/01 18:46:26 peter
  5461. * internal linker
  5462. * reorganized aasm layer
  5463. Revision 1.80 2002/07/01 16:23:54 peter
  5464. * cg64 patch
  5465. * basics for currency
  5466. * asnode updates for class and interface (not finished)
  5467. Revision 1.79 2002/05/18 13:34:18 peter
  5468. * readded missing revisions
  5469. Revision 1.78 2002/05/16 19:46:44 carl
  5470. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  5471. + try to fix temp allocation (still in ifdef)
  5472. + generic constructor calls
  5473. + start of tassembler / tmodulebase class cleanup
  5474. Revision 1.76 2002/05/12 16:53:10 peter
  5475. * moved entry and exitcode to ncgutil and cgobj
  5476. * foreach gets extra argument for passing local data to the
  5477. iterator function
  5478. * -CR checks also class typecasts at runtime by changing them
  5479. into as
  5480. * fixed compiler to cycle with the -CR option
  5481. * fixed stabs with elf writer, finally the global variables can
  5482. be watched
  5483. * removed a lot of routines from cga unit and replaced them by
  5484. calls to cgobj
  5485. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  5486. u32bit then the other is typecasted also to u32bit without giving
  5487. a rangecheck warning/error.
  5488. * fixed pascal calling method with reversing also the high tree in
  5489. the parast, detected by tcalcst3 test
  5490. Revision 1.75 2002/04/25 20:16:39 peter
  5491. * moved more routines from cga/n386util
  5492. Revision 1.74 2002/04/23 19:16:35 peter
  5493. * add pinline unit that inserts compiler supported functions using
  5494. one or more statements
  5495. * moved finalize and setlength from ninl to pinline
  5496. Revision 1.73 2002/04/21 19:02:05 peter
  5497. * removed newn and disposen nodes, the code is now directly
  5498. inlined from pexpr
  5499. * -an option that will write the secondpass nodes to the .s file, this
  5500. requires EXTDEBUG define to actually write the info
  5501. * fixed various internal errors and crashes due recent code changes
  5502. Revision 1.72 2002/04/20 21:32:25 carl
  5503. + generic FPC_CHECKPOINTER
  5504. + first parameter offset in stack now portable
  5505. * rename some constants
  5506. + move some cpu stuff to other units
  5507. - remove unused constents
  5508. * fix stacksize for some targets
  5509. * fix generic size problems which depend now on EXTEND_SIZE constant
  5510. }