symdef.pas 189 KB

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