symdef.pas 191 KB

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