symdef.pas 188 KB

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