symdef.pas 188 KB

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