symdef.pas 188 KB

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