symdef.pas 191 KB

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