symdef.pas 188 KB

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