symdef.pas 188 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071
  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. s:=s+' ';
  2915. hs:=hp.paratype.def.typesym.realname;
  2916. if hs[1]<>'$' then
  2917. s:=s+hp.paratype.def.typesym.realname
  2918. else
  2919. s:=s+hp.paratype.def.gettypename;
  2920. end;
  2921. { default value }
  2922. if assigned(hp.defaultvalue) then
  2923. begin
  2924. hpc:=tconstsym(hp.defaultvalue);
  2925. hs:='';
  2926. case hpc.consttyp of
  2927. conststring,
  2928. constresourcestring :
  2929. hs:=strpas(pchar(hpc.value.valueptr));
  2930. constreal :
  2931. str(pbestreal(hpc.value.valueptr)^,hs);
  2932. constord :
  2933. hs:=tostr(hpc.value.valueord);
  2934. constpointer :
  2935. hs:=tostr(hpc.value.valueordptr);
  2936. constbool :
  2937. begin
  2938. if hpc.value.valueord<>0 then
  2939. hs:='TRUE'
  2940. else
  2941. hs:='FALSE';
  2942. end;
  2943. constnil :
  2944. hs:='nil';
  2945. constchar :
  2946. hs:=chr(hpc.value.valueord);
  2947. constset :
  2948. hs:='<set>';
  2949. end;
  2950. if hs<>'' then
  2951. s:=s+'="'+hs+'"';
  2952. end;
  2953. end;
  2954. hp:=TParaItem(hp.next);
  2955. end;
  2956. if not first then
  2957. s:=s+')';
  2958. if (po_varargs in procoptions) then
  2959. s:=s+';VarArgs';
  2960. typename_paras:=s;
  2961. end;
  2962. function tabstractprocdef.is_methodpointer:boolean;
  2963. begin
  2964. result:=false;
  2965. end;
  2966. function tabstractprocdef.is_addressonly:boolean;
  2967. begin
  2968. result:=true;
  2969. end;
  2970. {$ifdef GDB}
  2971. function tabstractprocdef.stabstring : pchar;
  2972. begin
  2973. stabstring := strpnew('abstractproc'+numberstring+';');
  2974. end;
  2975. procedure tabstractprocdef.concatstabto(asmlist : taasmoutput);
  2976. begin
  2977. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2978. and (is_def_stab_written = not_written) then
  2979. begin
  2980. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  2981. inherited concatstabto(asmlist);
  2982. end;
  2983. end;
  2984. {$endif GDB}
  2985. {***************************************************************************
  2986. TPROCDEF
  2987. ***************************************************************************}
  2988. constructor tprocdef.create(level:byte);
  2989. begin
  2990. inherited create(level);
  2991. deftype:=procdef;
  2992. has_mangledname:=false;
  2993. _mangledname:=nil;
  2994. fileinfo:=aktfilepos;
  2995. extnumber:=$ffff;
  2996. aliasnames:=tstringlist.create;
  2997. funcretsym:=nil;
  2998. localst := nil;
  2999. defref:=nil;
  3000. lastwritten:=nil;
  3001. refcount:=0;
  3002. if (cs_browser in aktmoduleswitches) and make_ref then
  3003. begin
  3004. defref:=tref.create(defref,@akttokenpos);
  3005. inc(refcount);
  3006. end;
  3007. lastref:=defref;
  3008. { first, we assume that all registers are used }
  3009. usedintregisters:=ALL_INTREGISTERS;
  3010. usedotherregisters:=ALL_REGISTERS;
  3011. forwarddef:=true;
  3012. interfacedef:=false;
  3013. hasforward:=false;
  3014. _class := nil;
  3015. code:=nil;
  3016. regvarinfo := nil;
  3017. overloadnumber:=0;
  3018. {$ifdef GDB}
  3019. isstabwritten := false;
  3020. {$endif GDB}
  3021. end;
  3022. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3023. begin
  3024. inherited ppuload(ppufile);
  3025. deftype:=procdef;
  3026. ppufile.getnormalset(usedintregisters);
  3027. ppufile.getnormalset(usedotherregisters);
  3028. has_mangledname:=boolean(ppufile.getbyte);
  3029. if has_mangledname then
  3030. _mangledname:=stringdup(ppufile.getstring)
  3031. else
  3032. _mangledname:=nil;
  3033. overloadnumber:=ppufile.getword;
  3034. extnumber:=ppufile.getword;
  3035. _class := tobjectdef(ppufile.getderef);
  3036. procsym := tsym(ppufile.getderef);
  3037. ppufile.getposinfo(fileinfo);
  3038. ppufile.getsmallset(symoptions);
  3039. { inline stuff }
  3040. if proccalloption=pocall_inline then
  3041. begin
  3042. funcretsym:=tsym(ppufile.getderef);
  3043. code:=ppuloadnode(ppufile);
  3044. end
  3045. else
  3046. begin
  3047. code := nil;
  3048. funcretsym:=nil;
  3049. end;
  3050. { load para symtable }
  3051. parast:=tparasymtable.create(unknown_level);
  3052. tparasymtable(parast).ppuload(ppufile);
  3053. parast.defowner:=self;
  3054. { load local symtable }
  3055. if (proccalloption=pocall_inline) or
  3056. ((current_module.flags and uf_local_browser)<>0) then
  3057. begin
  3058. localst:=tlocalsymtable.create(unknown_level);
  3059. tlocalsymtable(localst).ppuload(ppufile);
  3060. localst.defowner:=self;
  3061. end
  3062. else
  3063. localst:=nil;
  3064. { default values for no persistent data }
  3065. if (cs_link_deffile in aktglobalswitches) and
  3066. (tf_need_export in target_info.flags) and
  3067. (po_exports in procoptions) then
  3068. deffile.AddExport(mangledname);
  3069. aliasnames:=tstringlist.create;
  3070. forwarddef:=false;
  3071. interfacedef:=false;
  3072. hasforward:=false;
  3073. regvarinfo := nil;
  3074. lastref:=nil;
  3075. lastwritten:=nil;
  3076. defref:=nil;
  3077. refcount:=0;
  3078. {$ifdef GDB}
  3079. isstabwritten := false;
  3080. {$endif GDB}
  3081. end;
  3082. destructor tprocdef.destroy;
  3083. begin
  3084. if assigned(defref) then
  3085. begin
  3086. defref.freechain;
  3087. defref.free;
  3088. end;
  3089. aliasnames.free;
  3090. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3091. begin
  3092. {$ifdef MEMDEBUG}
  3093. memproclocalst.start;
  3094. {$endif MEMDEBUG}
  3095. localst.free;
  3096. {$ifdef MEMDEBUG}
  3097. memproclocalst.start;
  3098. {$endif MEMDEBUG}
  3099. end;
  3100. if (proccalloption=pocall_inline) and assigned(code) then
  3101. begin
  3102. {$ifdef MEMDEBUG}
  3103. memprocnodetree.start;
  3104. {$endif MEMDEBUG}
  3105. tnode(code).free;
  3106. {$ifdef MEMDEBUG}
  3107. memprocnodetree.start;
  3108. {$endif MEMDEBUG}
  3109. end;
  3110. if assigned(regvarinfo) then
  3111. dispose(pregvarinfo(regvarinfo));
  3112. if (po_msgstr in procoptions) then
  3113. strdispose(messageinf.str);
  3114. if assigned(_mangledname) then
  3115. begin
  3116. {$ifdef MEMDEBUG}
  3117. memmanglednames.start;
  3118. {$endif MEMDEBUG}
  3119. stringdispose(_mangledname);
  3120. {$ifdef MEMDEBUG}
  3121. memmanglednames.stop;
  3122. {$endif MEMDEBUG}
  3123. end;
  3124. inherited destroy;
  3125. end;
  3126. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3127. var
  3128. oldintfcrc : boolean;
  3129. begin
  3130. inherited ppuwrite(ppufile);
  3131. oldintfcrc:=ppufile.do_interface_crc;
  3132. ppufile.do_interface_crc:=false;
  3133. { set all registers to used for simplified compilation PM }
  3134. if simplify_ppu then
  3135. begin
  3136. usedintregisters:=ALL_INTREGISTERS;
  3137. usedotherregisters:=ALL_REGISTERS;
  3138. end;
  3139. ppufile.putnormalset(usedintregisters);
  3140. ppufile.putnormalset(usedotherregisters);
  3141. ppufile.do_interface_crc:=oldintfcrc;
  3142. ppufile.putbyte(byte(has_mangledname));
  3143. if has_mangledname then
  3144. ppufile.putstring(mangledname);
  3145. ppufile.putword(overloadnumber);
  3146. ppufile.putword(extnumber);
  3147. ppufile.putderef(_class);
  3148. ppufile.putderef(procsym);
  3149. ppufile.putposinfo(fileinfo);
  3150. ppufile.putsmallset(symoptions);
  3151. { inline stuff references to localsymtable, no influence
  3152. on the crc }
  3153. oldintfcrc:=ppufile.do_crc;
  3154. ppufile.do_crc:=false;
  3155. { inline stuff }
  3156. if proccalloption=pocall_inline then
  3157. begin
  3158. ppufile.putderef(funcretsym);
  3159. ppuwritenode(ppufile,code);
  3160. end;
  3161. ppufile.do_crc:=oldintfcrc;
  3162. { write this entry }
  3163. ppufile.writeentry(ibprocdef);
  3164. { Save the para symtable, this is taken from the interface }
  3165. tparasymtable(parast).ppuwrite(ppufile);
  3166. { save localsymtable for inline procedures or when local
  3167. browser info is requested, this has no influence on the crc }
  3168. if (proccalloption=pocall_inline) or
  3169. ((current_module.flags and uf_local_browser)<>0) then
  3170. begin
  3171. oldintfcrc:=ppufile.do_crc;
  3172. ppufile.do_crc:=false;
  3173. if not assigned(localst) then
  3174. begin
  3175. localst:=tlocalsymtable.create(unknown_level);
  3176. localst.defowner:=self;
  3177. end;
  3178. tlocalsymtable(localst).ppuwrite(ppufile);
  3179. ppufile.do_crc:=oldintfcrc;
  3180. end;
  3181. end;
  3182. procedure tprocdef.insert_localst;
  3183. begin
  3184. localst:=tlocalsymtable.create(parast.symtablelevel);
  3185. localst.defowner:=self;
  3186. { this is used by insert
  3187. to check same names in parast and localst }
  3188. localst.next:=parast;
  3189. end;
  3190. function tprocdef.fullprocname(showhidden:boolean):string;
  3191. var
  3192. s : string;
  3193. begin
  3194. s:='';
  3195. if assigned(_class) then
  3196. begin
  3197. if po_classmethod in procoptions then
  3198. s:=s+'class ';
  3199. s:=s+_class.objrealname^+'.';
  3200. end;
  3201. s:=s+procsym.realname+typename_paras(showhidden);
  3202. if assigned(rettype.def) and
  3203. not(is_void(rettype.def)) then
  3204. s:=s+':'+rettype.def.gettypename;
  3205. fullprocname:=s;
  3206. end;
  3207. function tprocdef.is_methodpointer:boolean;
  3208. begin
  3209. result:=assigned(owner) and
  3210. (owner.symtabletype=objectsymtable);
  3211. end;
  3212. function tprocdef.is_addressonly:boolean;
  3213. begin
  3214. result:=assigned(owner) and
  3215. (owner.symtabletype<>objectsymtable);
  3216. end;
  3217. function tprocdef.is_visible_for_proc(currprocdef:tprocdef):boolean;
  3218. begin
  3219. is_visible_for_proc:=false;
  3220. { private symbols are allowed when we are in the same
  3221. module as they are defined }
  3222. if (sp_private in symoptions) and
  3223. assigned(owner.defowner) and
  3224. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3225. (owner.defowner.owner.unitid<>0) then
  3226. exit;
  3227. { protected symbols are vissible in the module that defines them and
  3228. also visible to related objects }
  3229. if (sp_protected in symoptions) and
  3230. (
  3231. (
  3232. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3233. (owner.defowner.owner.unitid<>0)
  3234. ) and
  3235. not(
  3236. assigned(currprocdef) and
  3237. assigned(currprocdef._class) and
  3238. currprocdef._class.is_related(tobjectdef(owner.defowner))
  3239. )
  3240. ) then
  3241. exit;
  3242. is_visible_for_proc:=true;
  3243. end;
  3244. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3245. begin
  3246. is_visible_for_object:=false;
  3247. { private symbols are allowed when we are in the same
  3248. module as they are defined }
  3249. if (sp_private in symoptions) and
  3250. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3251. (owner.defowner.owner.unitid<>0) then
  3252. exit;
  3253. { protected symbols are vissible in the module that defines them and
  3254. also visible to related objects }
  3255. if (sp_protected in symoptions) and
  3256. (
  3257. (
  3258. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3259. (owner.defowner.owner.unitid<>0)
  3260. ) and
  3261. not(
  3262. assigned(currobjdef) and
  3263. currobjdef.is_related(tobjectdef(owner.defowner))
  3264. )
  3265. ) then
  3266. exit;
  3267. is_visible_for_object:=true;
  3268. end;
  3269. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3270. begin
  3271. case t of
  3272. gs_local :
  3273. getsymtable:=localst;
  3274. gs_para :
  3275. getsymtable:=parast;
  3276. else
  3277. getsymtable:=nil;
  3278. end;
  3279. end;
  3280. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3281. var
  3282. pos : tfileposinfo;
  3283. move_last : boolean;
  3284. begin
  3285. move_last:=lastwritten=lastref;
  3286. while (not ppufile.endofentry) do
  3287. begin
  3288. ppufile.getposinfo(pos);
  3289. inc(refcount);
  3290. lastref:=tref.create(lastref,@pos);
  3291. lastref.is_written:=true;
  3292. if refcount=1 then
  3293. defref:=lastref;
  3294. end;
  3295. if move_last then
  3296. lastwritten:=lastref;
  3297. if ((current_module.flags and uf_local_browser)<>0) and
  3298. locals then
  3299. begin
  3300. tparasymtable(parast).load_references(ppufile,locals);
  3301. tlocalsymtable(localst).load_references(ppufile,locals);
  3302. end;
  3303. end;
  3304. Const
  3305. local_symtable_index : word = $8001;
  3306. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3307. var
  3308. ref : tref;
  3309. pdo : tobjectdef;
  3310. move_last : boolean;
  3311. begin
  3312. move_last:=lastwritten=lastref;
  3313. if move_last and
  3314. (((current_module.flags and uf_local_browser)=0) or
  3315. not locals) then
  3316. exit;
  3317. { write address of this symbol }
  3318. ppufile.putderef(self);
  3319. { write refs }
  3320. if assigned(lastwritten) then
  3321. ref:=lastwritten
  3322. else
  3323. ref:=defref;
  3324. while assigned(ref) do
  3325. begin
  3326. if ref.moduleindex=current_module.unit_index then
  3327. begin
  3328. ppufile.putposinfo(ref.posinfo);
  3329. ref.is_written:=true;
  3330. if move_last then
  3331. lastwritten:=ref;
  3332. end
  3333. else if not ref.is_written then
  3334. move_last:=false
  3335. else if move_last then
  3336. lastwritten:=ref;
  3337. ref:=ref.nextref;
  3338. end;
  3339. ppufile.writeentry(ibdefref);
  3340. write_references:=true;
  3341. if ((current_module.flags and uf_local_browser)<>0) and
  3342. locals then
  3343. begin
  3344. pdo:=_class;
  3345. if (owner.symtabletype<>localsymtable) then
  3346. while assigned(pdo) do
  3347. begin
  3348. if pdo.symtable<>aktrecordsymtable then
  3349. begin
  3350. pdo.symtable.unitid:=local_symtable_index;
  3351. inc(local_symtable_index);
  3352. end;
  3353. pdo:=pdo.childof;
  3354. end;
  3355. parast.unitid:=local_symtable_index;
  3356. inc(local_symtable_index);
  3357. localst.unitid:=local_symtable_index;
  3358. inc(local_symtable_index);
  3359. tstoredsymtable(parast).write_references(ppufile,locals);
  3360. tstoredsymtable(localst).write_references(ppufile,locals);
  3361. { decrement for }
  3362. local_symtable_index:=local_symtable_index-2;
  3363. pdo:=_class;
  3364. if (owner.symtabletype<>localsymtable) then
  3365. while assigned(pdo) do
  3366. begin
  3367. if pdo.symtable<>aktrecordsymtable then
  3368. dec(local_symtable_index);
  3369. pdo:=pdo.childof;
  3370. end;
  3371. end;
  3372. end;
  3373. {$ifdef GDB}
  3374. {$ifdef unused}
  3375. { procedure addparaname(p : tsym);
  3376. var vs : char;
  3377. begin
  3378. if tvarsym(p).varspez = vs_value then vs := '1'
  3379. else vs := '0';
  3380. strpcopy(strend(StabRecString),p^.name+':'+tstoreddef(tvarsym(p).vartype.def).numberstring+','+vs+';');
  3381. end; }
  3382. function tprocdef.stabstring : pchar;
  3383. var
  3384. i : longint;
  3385. stabrecstring : pchar;
  3386. begin
  3387. getmem(StabRecString,1024);
  3388. strpcopy(StabRecString,'f'+tstoreddef(rettype.def).numberstring);
  3389. i:=maxparacount;
  3390. if i>0 then
  3391. begin
  3392. strpcopy(strend(StabRecString),','+tostr(i)+';');
  3393. (* confuse gdb !! PM
  3394. if assigned(parast) then
  3395. parast.foreach({$ifdef FPCPROCVAR}@{$endif}addparaname)
  3396. else
  3397. begin
  3398. param := para1;
  3399. i := 0;
  3400. while assigned(param) do
  3401. begin
  3402. inc(i);
  3403. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3404. {Here we have lost the parameter names !!}
  3405. {using lower case parameters }
  3406. strpcopy(strend(stabrecstring),'p'+tostr(i)
  3407. +':'+param^.paratype.def.numberstring+','+vartyp+';');
  3408. param := param^.next;
  3409. end;
  3410. end; *)
  3411. {strpcopy(strend(StabRecString),';');}
  3412. end;
  3413. stabstring := strnew(stabrecstring);
  3414. freemem(stabrecstring,1024);
  3415. end;
  3416. {$endif unused}
  3417. function tprocdef.stabstring: pchar;
  3418. Var RType : Char;
  3419. Obj,Info : String;
  3420. stabsstr : string;
  3421. p : pchar;
  3422. begin
  3423. obj := procsym.name;
  3424. info := '';
  3425. if tprocsym(procsym).is_global then
  3426. RType := 'F'
  3427. else
  3428. RType := 'f';
  3429. if assigned(owner) then
  3430. begin
  3431. if (owner.symtabletype = objectsymtable) then
  3432. obj := owner.name^+'__'+procsym.name;
  3433. { this code was correct only as long as the local symboltable
  3434. of the parent had the same name as the function
  3435. but this is no true anymore !! PM
  3436. if (owner.symtabletype=localsymtable) and assigned(owner.name) then
  3437. info := ','+name+','+owner.name^; }
  3438. if (owner.symtabletype=localsymtable) and
  3439. assigned(owner.defowner) and
  3440. assigned(tprocdef(owner.defowner).procsym) then
  3441. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3442. end;
  3443. stabsstr:=mangledname;
  3444. getmem(p,length(stabsstr)+255);
  3445. strpcopy(p,'"'+obj+':'+RType
  3446. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3447. +',0,'+
  3448. tostr(fileinfo.line)
  3449. +',');
  3450. strpcopy(strend(p),stabsstr);
  3451. stabstring:=strnew(p);
  3452. freemem(p,length(stabsstr)+255);
  3453. end;
  3454. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3455. begin
  3456. if (proccalloption=pocall_internproc) then
  3457. exit;
  3458. if not isstabwritten then
  3459. asmList.concat(Tai_stabs.Create(stabstring));
  3460. isstabwritten := true;
  3461. if assigned(parast) then
  3462. tstoredsymtable(parast).concatstabto(asmlist);
  3463. { local type defs and vars should not be written
  3464. inside the main proc stab }
  3465. if assigned(localst) and
  3466. (localst.symtablelevel>main_program_level) then
  3467. tstoredsymtable(localst).concatstabto(asmlist);
  3468. is_def_stab_written := written;
  3469. end;
  3470. {$endif GDB}
  3471. procedure tprocdef.deref;
  3472. begin
  3473. inherited deref;
  3474. resolvedef(pointer(_class));
  3475. { procsym that originaly defined this definition, should be in the
  3476. same symtable }
  3477. resolvesym(pointer(procsym));
  3478. end;
  3479. procedure tprocdef.derefimpl;
  3480. var
  3481. oldlocalsymtable : tsymtable;
  3482. begin
  3483. { locals }
  3484. if assigned(localst) then
  3485. begin
  3486. { localst }
  3487. oldlocalsymtable:=aktlocalsymtable;
  3488. aktlocalsymtable:=localst;
  3489. { we can deref both interface and implementation parts }
  3490. tlocalsymtable(localst).deref;
  3491. tlocalsymtable(localst).derefimpl;
  3492. aktlocalsymtable:=oldlocalsymtable;
  3493. { funcretsym, this is always located in the localst }
  3494. resolvesym(pointer(funcretsym));
  3495. end
  3496. else
  3497. begin
  3498. { safety }
  3499. funcretsym:=nil;
  3500. end;
  3501. { inline tree }
  3502. if (proccalloption=pocall_inline) then
  3503. code.derefimpl;
  3504. end;
  3505. function tprocdef.gettypename : string;
  3506. begin
  3507. gettypename := FullProcName(false)+';'+ProcCallOptionStr[proccalloption];
  3508. end;
  3509. function tprocdef.mangledname : string;
  3510. var
  3511. s : string;
  3512. hp : TParaItem;
  3513. begin
  3514. if assigned(_mangledname) then
  3515. begin
  3516. mangledname:=_mangledname^;
  3517. exit;
  3518. end;
  3519. { we need to use the symtable where the procsym is inserted,
  3520. because that is visible to the world }
  3521. s:=mangledname_prefix('',procsym.owner)+procsym.name;
  3522. if overloadnumber>0 then
  3523. s:=s+'$'+tostr(overloadnumber);
  3524. { add parameter types }
  3525. hp:=TParaItem(Para.first);
  3526. while assigned(hp) do
  3527. begin
  3528. if not hp.is_hidden then
  3529. s:=s+'$'+hp.paratype.def.mangledparaname;
  3530. hp:=TParaItem(hp.next);
  3531. end;
  3532. _mangledname:=stringdup(s);
  3533. mangledname:=_mangledname^;
  3534. end;
  3535. function tprocdef.cplusplusmangledname : string;
  3536. function getcppparaname(p : tdef) : string;
  3537. const
  3538. ordtype2str : array[tbasetype] of string[2] = (
  3539. '',
  3540. 'Uc','Us','Ui','Us',
  3541. 'Sc','s','i','x',
  3542. 'b','b','b',
  3543. 'c','w','x');
  3544. var
  3545. s : string;
  3546. begin
  3547. case p.deftype of
  3548. orddef:
  3549. s:=ordtype2str[torddef(p).typ];
  3550. pointerdef:
  3551. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3552. else
  3553. internalerror(2103001);
  3554. end;
  3555. getcppparaname:=s;
  3556. end;
  3557. var
  3558. s,s2 : string;
  3559. param : TParaItem;
  3560. begin
  3561. s := procsym.realname;
  3562. if procsym.owner.symtabletype=objectsymtable then
  3563. begin
  3564. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3565. case proctypeoption of
  3566. potype_destructor:
  3567. s:='_$_'+tostr(length(s2))+s2;
  3568. potype_constructor:
  3569. s:='___'+tostr(length(s2))+s2;
  3570. else
  3571. s:='_'+s+'__'+tostr(length(s2))+s2;
  3572. end;
  3573. end
  3574. else s:=s+'__';
  3575. s:=s+'F';
  3576. { concat modifiers }
  3577. { !!!!! }
  3578. { now we handle the parameters }
  3579. param := TParaItem(Para.first);
  3580. if assigned(param) then
  3581. while assigned(param) do
  3582. begin
  3583. s2:=getcppparaname(param.paratype.def);
  3584. if param.paratyp in [vs_var,vs_out] then
  3585. s2:='R'+s2;
  3586. s:=s+s2;
  3587. param:=TParaItem(param.next);
  3588. end
  3589. else
  3590. s:=s+'v';
  3591. cplusplusmangledname:=s;
  3592. end;
  3593. procedure tprocdef.setmangledname(const s : string);
  3594. begin
  3595. stringdispose(_mangledname);
  3596. _mangledname:=stringdup(s);
  3597. has_mangledname:=true;
  3598. end;
  3599. {***************************************************************************
  3600. TPROCVARDEF
  3601. ***************************************************************************}
  3602. constructor tprocvardef.create(level:byte);
  3603. begin
  3604. inherited create(level);
  3605. deftype:=procvardef;
  3606. end;
  3607. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3608. begin
  3609. inherited ppuload(ppufile);
  3610. deftype:=procvardef;
  3611. { load para symtable }
  3612. parast:=tparasymtable.create(unknown_level);
  3613. tparasymtable(parast).ppuload(ppufile);
  3614. parast.defowner:=self;
  3615. end;
  3616. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3617. begin
  3618. { here we cannot get a real good value so just give something }
  3619. { plausible (PM) }
  3620. { a more secure way would be
  3621. to allways store in a temp }
  3622. if is_fpu(rettype.def) then
  3623. fpu_used:={2}maxfpuregs
  3624. else
  3625. fpu_used:=0;
  3626. inherited ppuwrite(ppufile);
  3627. { Write this entry }
  3628. ppufile.writeentry(ibprocvardef);
  3629. { Save the para symtable, this is taken from the interface }
  3630. tparasymtable(parast).ppuwrite(ppufile);
  3631. end;
  3632. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3633. begin
  3634. case t of
  3635. gs_para :
  3636. getsymtable:=parast;
  3637. else
  3638. getsymtable:=nil;
  3639. end;
  3640. end;
  3641. function tprocvardef.size : longint;
  3642. begin
  3643. if (po_methodpointer in procoptions) and
  3644. not(po_addressonly in procoptions) then
  3645. size:=2*POINTER_SIZE
  3646. else
  3647. size:=POINTER_SIZE;
  3648. end;
  3649. function tprocvardef.is_methodpointer:boolean;
  3650. begin
  3651. result:=(po_methodpointer in procoptions);
  3652. end;
  3653. function tprocvardef.is_addressonly:boolean;
  3654. begin
  3655. result:=not(po_methodpointer in procoptions) or
  3656. (po_addressonly in procoptions);
  3657. end;
  3658. {$ifdef GDB}
  3659. function tprocvardef.stabstring : pchar;
  3660. var
  3661. nss : pchar;
  3662. { i : longint; }
  3663. begin
  3664. { i := maxparacount; }
  3665. getmem(nss,1024);
  3666. { it is not a function but a function pointer !! (PM) }
  3667. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)}+';');
  3668. { this confuses gdb !!
  3669. we should use 'F' instead of 'f' but
  3670. as we use c++ language mode
  3671. it does not like that either
  3672. Please do not remove this part
  3673. might be used once
  3674. gdb for pascal is ready PM }
  3675. (*
  3676. param := para1;
  3677. i := 0;
  3678. while assigned(param) do
  3679. begin
  3680. inc(i);
  3681. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3682. {Here we have lost the parameter names !!}
  3683. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3684. strcat(nss,pst);
  3685. strdispose(pst);
  3686. param := param^.next;
  3687. end; *)
  3688. {strpcopy(strend(nss),';');}
  3689. stabstring := strnew(nss);
  3690. freemem(nss,1024);
  3691. end;
  3692. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3693. begin
  3694. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3695. and (is_def_stab_written = not_written) then
  3696. inherited concatstabto(asmlist);
  3697. is_def_stab_written:=written;
  3698. end;
  3699. {$endif GDB}
  3700. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3701. var
  3702. pdc : TParaItem;
  3703. methodkind, paraspec : byte;
  3704. begin
  3705. if po_methodpointer in procoptions then
  3706. begin
  3707. { write method id and name }
  3708. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3709. write_rtti_name;
  3710. { write kind of method (can only be function or procedure)}
  3711. if rettype.def = voidtype.def then
  3712. methodkind := mkProcedure
  3713. else
  3714. methodkind := mkFunction;
  3715. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3716. { get # of parameters }
  3717. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3718. { write parameter info. The parameters must be written in reverse order
  3719. if this method uses right to left parameter pushing! }
  3720. if (po_leftright in procoptions) then
  3721. pdc:=TParaItem(Para.first)
  3722. else
  3723. pdc:=TParaItem(Para.last);
  3724. while assigned(pdc) do
  3725. begin
  3726. case pdc.paratyp of
  3727. vs_value: paraspec := 0;
  3728. vs_const: paraspec := pfConst;
  3729. vs_var : paraspec := pfVar;
  3730. vs_out : paraspec := pfOut;
  3731. end;
  3732. { write flags for current parameter }
  3733. rttiList.concat(Tai_const.Create_8bit(paraspec));
  3734. { write name of current parameter ### how can I get this??? (sg)}
  3735. rttiList.concat(Tai_const.Create_8bit(0));
  3736. { write name of type of current parameter }
  3737. tstoreddef(pdc.paratype.def).write_rtti_name;
  3738. if (po_leftright in procoptions) then
  3739. pdc:=TParaItem(pdc.next)
  3740. else
  3741. pdc:=TParaItem(pdc.previous);
  3742. end;
  3743. { write name of result type }
  3744. tstoreddef(rettype.def).write_rtti_name;
  3745. end;
  3746. end;
  3747. function tprocvardef.is_publishable : boolean;
  3748. begin
  3749. is_publishable:=(po_methodpointer in procoptions);
  3750. end;
  3751. function tprocvardef.gettypename : string;
  3752. var
  3753. s: string;
  3754. begin
  3755. s:='<';
  3756. if po_classmethod in procoptions then
  3757. s := s+'class method type of'
  3758. else
  3759. if po_addressonly in procoptions then
  3760. s := s+'address of'
  3761. else
  3762. s := s+'procedure variable type of';
  3763. if assigned(rettype.def) and
  3764. (rettype.def<>voidtype.def) then
  3765. s:=s+' function'+typename_paras(false)+':'+rettype.def.gettypename
  3766. else
  3767. s:=s+' procedure'+typename_paras(false);
  3768. if po_methodpointer in procoptions then
  3769. s := s+' of object';
  3770. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3771. end;
  3772. {***************************************************************************
  3773. TOBJECTDEF
  3774. ***************************************************************************}
  3775. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3776. begin
  3777. inherited create;
  3778. objecttype:=ot;
  3779. deftype:=objectdef;
  3780. objectoptions:=[];
  3781. childof:=nil;
  3782. symtable:=tobjectsymtable.create(n);
  3783. { create space for vmt !! }
  3784. vmt_offset:=0;
  3785. symtable.datasize:=0;
  3786. symtable.defowner:=self;
  3787. { recordalign -1 means C record packing, that starts
  3788. with an alignment of 1 }
  3789. if aktalignment.recordalignmax=-1 then
  3790. symtable.dataalignment:=1
  3791. else
  3792. symtable.dataalignment:=aktalignment.recordalignmax;
  3793. lastvtableindex:=0;
  3794. set_parent(c);
  3795. objname:=stringdup(upper(n));
  3796. objrealname:=stringdup(n);
  3797. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  3798. prepareguid;
  3799. { setup implemented interfaces }
  3800. if objecttype in [odt_class,odt_interfacecorba] then
  3801. implementedinterfaces:=timplementedinterfaces.create
  3802. else
  3803. implementedinterfaces:=nil;
  3804. {$ifdef GDB}
  3805. writing_class_record_stab:=false;
  3806. {$endif GDB}
  3807. end;
  3808. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3809. var
  3810. i,implintfcount: longint;
  3811. begin
  3812. inherited ppuloaddef(ppufile);
  3813. deftype:=objectdef;
  3814. objecttype:=tobjectdeftype(ppufile.getbyte);
  3815. savesize:=ppufile.getlongint;
  3816. vmt_offset:=ppufile.getlongint;
  3817. objrealname:=stringdup(ppufile.getstring);
  3818. objname:=stringdup(upper(objrealname^));
  3819. childof:=tobjectdef(ppufile.getderef);
  3820. ppufile.getsmallset(objectoptions);
  3821. { load guid }
  3822. iidstr:=nil;
  3823. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3824. begin
  3825. new(iidguid);
  3826. ppufile.getguid(iidguid^);
  3827. iidstr:=stringdup(ppufile.getstring);
  3828. lastvtableindex:=ppufile.getlongint;
  3829. end;
  3830. { load implemented interfaces }
  3831. if objecttype in [odt_class,odt_interfacecorba] then
  3832. begin
  3833. implementedinterfaces:=timplementedinterfaces.create;
  3834. implintfcount:=ppufile.getlongint;
  3835. for i:=1 to implintfcount do
  3836. begin
  3837. implementedinterfaces.addintfref(ppufile.getderef);
  3838. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  3839. end;
  3840. end
  3841. else
  3842. implementedinterfaces:=nil;
  3843. symtable:=tobjectsymtable.create(objrealname^);
  3844. tobjectsymtable(symtable).ppuload(ppufile);
  3845. symtable.defowner:=self;
  3846. { handles the predefined class tobject }
  3847. { the last TOBJECT which is loaded gets }
  3848. { it ! }
  3849. if (childof=nil) and
  3850. (objecttype=odt_class) and
  3851. (objname^='TOBJECT') then
  3852. class_tobject:=self;
  3853. if (childof=nil) and
  3854. (objecttype=odt_interfacecom) and
  3855. (objname^='IUNKNOWN') then
  3856. interface_iunknown:=self;
  3857. {$ifdef GDB}
  3858. writing_class_record_stab:=false;
  3859. {$endif GDB}
  3860. end;
  3861. destructor tobjectdef.destroy;
  3862. begin
  3863. if assigned(symtable) then
  3864. symtable.free;
  3865. stringdispose(objname);
  3866. stringdispose(objrealname);
  3867. if assigned(iidstr) then
  3868. stringdispose(iidstr);
  3869. if assigned(implementedinterfaces) then
  3870. implementedinterfaces.free;
  3871. if assigned(iidguid) then
  3872. dispose(iidguid);
  3873. inherited destroy;
  3874. end;
  3875. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3876. var
  3877. implintfcount : longint;
  3878. i : longint;
  3879. begin
  3880. inherited ppuwritedef(ppufile);
  3881. ppufile.putbyte(byte(objecttype));
  3882. ppufile.putlongint(size);
  3883. ppufile.putlongint(vmt_offset);
  3884. ppufile.putstring(objrealname^);
  3885. ppufile.putderef(childof);
  3886. ppufile.putsmallset(objectoptions);
  3887. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3888. begin
  3889. ppufile.putguid(iidguid^);
  3890. ppufile.putstring(iidstr^);
  3891. ppufile.putlongint(lastvtableindex);
  3892. end;
  3893. if objecttype in [odt_class,odt_interfacecorba] then
  3894. begin
  3895. implintfcount:=implementedinterfaces.count;
  3896. ppufile.putlongint(implintfcount);
  3897. for i:=1 to implintfcount do
  3898. begin
  3899. ppufile.putderef(implementedinterfaces.interfaces(i));
  3900. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  3901. end;
  3902. end;
  3903. ppufile.writeentry(ibobjectdef);
  3904. tobjectsymtable(symtable).ppuwrite(ppufile);
  3905. end;
  3906. procedure tobjectdef.deref;
  3907. var
  3908. oldrecsyms : tsymtable;
  3909. begin
  3910. inherited deref;
  3911. resolvedef(pointer(childof));
  3912. oldrecsyms:=aktrecordsymtable;
  3913. aktrecordsymtable:=symtable;
  3914. tstoredsymtable(symtable).deref;
  3915. aktrecordsymtable:=oldrecsyms;
  3916. if objecttype in [odt_class,odt_interfacecorba] then
  3917. implementedinterfaces.deref;
  3918. end;
  3919. procedure tobjectdef.prepareguid;
  3920. begin
  3921. { set up guid }
  3922. if not assigned(iidguid) then
  3923. begin
  3924. new(iidguid);
  3925. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3926. end;
  3927. { setup iidstring }
  3928. if not assigned(iidstr) then
  3929. iidstr:=stringdup(''); { default is empty string }
  3930. end;
  3931. procedure tobjectdef.set_parent( c : tobjectdef);
  3932. begin
  3933. { nothing to do if the parent was not forward !}
  3934. if assigned(childof) then
  3935. exit;
  3936. childof:=c;
  3937. { some options are inherited !! }
  3938. if assigned(c) then
  3939. begin
  3940. { only important for classes }
  3941. lastvtableindex:=c.lastvtableindex;
  3942. objectoptions:=objectoptions+(c.objectoptions*
  3943. [oo_has_virtual,oo_has_private,oo_has_protected,
  3944. oo_has_constructor,oo_has_destructor]);
  3945. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3946. begin
  3947. { add the data of the anchestor class }
  3948. inc(symtable.datasize,c.symtable.datasize);
  3949. if (oo_has_vmt in objectoptions) and
  3950. (oo_has_vmt in c.objectoptions) then
  3951. dec(symtable.datasize,POINTER_SIZE);
  3952. { if parent has a vmt field then
  3953. the offset is the same for the child PM }
  3954. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3955. begin
  3956. vmt_offset:=c.vmt_offset;
  3957. include(objectoptions,oo_has_vmt);
  3958. end;
  3959. end;
  3960. end;
  3961. savesize := symtable.datasize;
  3962. end;
  3963. procedure tobjectdef.insertvmt;
  3964. begin
  3965. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3966. exit;
  3967. if (oo_has_vmt in objectoptions) then
  3968. internalerror(12345)
  3969. else
  3970. begin
  3971. symtable.datasize:=align(symtable.datasize,symtable.dataalignment);
  3972. vmt_offset:=symtable.datasize;
  3973. inc(symtable.datasize,POINTER_SIZE);
  3974. include(objectoptions,oo_has_vmt);
  3975. end;
  3976. end;
  3977. procedure tobjectdef.check_forwards;
  3978. begin
  3979. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3980. tstoredsymtable(symtable).check_forwards;
  3981. if (oo_is_forward in objectoptions) then
  3982. begin
  3983. { ok, in future, the forward can be resolved }
  3984. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3985. exclude(objectoptions,oo_is_forward);
  3986. end;
  3987. end;
  3988. { true, if self inherits from d (or if they are equal) }
  3989. function tobjectdef.is_related(d : tobjectdef) : boolean;
  3990. var
  3991. hp : tobjectdef;
  3992. begin
  3993. hp:=self;
  3994. while assigned(hp) do
  3995. begin
  3996. if hp=d then
  3997. begin
  3998. is_related:=true;
  3999. exit;
  4000. end;
  4001. hp:=hp.childof;
  4002. end;
  4003. is_related:=false;
  4004. end;
  4005. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4006. var
  4007. p : pprocdeflist;
  4008. begin
  4009. { if we found already a destructor, then we exit }
  4010. if assigned(sd) then
  4011. exit;
  4012. if tsym(sym).typ=procsym then
  4013. begin
  4014. p:=tprocsym(sym).defs;
  4015. while assigned(p) do
  4016. begin
  4017. if p^.def.proctypeoption=potype_destructor then
  4018. begin
  4019. sd:=p^.def;
  4020. exit;
  4021. end;
  4022. p:=p^.next;
  4023. end;
  4024. end;
  4025. end;*)
  4026. procedure Tobjectdef._searchdestructor(sym:Tnamedindexitem;arg:pointer);
  4027. begin
  4028. { if we found already a destructor, then we exit }
  4029. if (sd=nil) and (Tsym(sym).typ=procsym) then
  4030. sd:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4031. end;
  4032. function tobjectdef.searchdestructor : tprocdef;
  4033. var
  4034. o : tobjectdef;
  4035. begin
  4036. searchdestructor:=nil;
  4037. o:=self;
  4038. sd:=nil;
  4039. while assigned(o) do
  4040. begin
  4041. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,nil);
  4042. if assigned(sd) then
  4043. begin
  4044. searchdestructor:=sd;
  4045. exit;
  4046. end;
  4047. o:=o.childof;
  4048. end;
  4049. end;
  4050. function tobjectdef.size : longint;
  4051. var
  4052. _resultsize : longint;
  4053. begin
  4054. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4055. _resultsize:=POINTER_SIZE
  4056. else
  4057. _resultsize:=symtable.datasize;
  4058. size := _resultsize;
  4059. end;
  4060. function tobjectdef.alignment:longint;
  4061. begin
  4062. alignment:=symtable.dataalignment;
  4063. end;
  4064. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4065. begin
  4066. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4067. case objecttype of
  4068. odt_class:
  4069. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  4070. odt_interfacecom,odt_interfacecorba:
  4071. vmtmethodoffset:=index*POINTER_SIZE;
  4072. else
  4073. {$ifdef WITHDMT}
  4074. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  4075. {$else WITHDMT}
  4076. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  4077. {$endif WITHDMT}
  4078. end;
  4079. end;
  4080. function tobjectdef.vmt_mangledname : string;
  4081. begin
  4082. if not(oo_has_vmt in objectoptions) then
  4083. Message1(parser_n_object_has_no_vmt,objrealname^);
  4084. vmt_mangledname:=mangledname_prefix('VMT',owner)+objname^;
  4085. end;
  4086. function tobjectdef.rtti_name : string;
  4087. begin
  4088. rtti_name:=mangledname_prefix('RTTI',owner)+objname^;
  4089. end;
  4090. {$ifdef GDB}
  4091. procedure tobjectdef.addprocname(p :tnamedindexitem;arg:pointer);
  4092. var virtualind,argnames : string;
  4093. news, newrec : pchar;
  4094. pd,ipd : tprocdef;
  4095. lindex : longint;
  4096. para : TParaItem;
  4097. arglength : byte;
  4098. sp : char;
  4099. begin
  4100. If tsym(p).typ = procsym then
  4101. begin
  4102. pd := tprocsym(p).first_procdef;
  4103. { this will be used for full implementation of object stabs
  4104. not yet done }
  4105. ipd := Tprocsym(p).last_procdef;
  4106. if (po_virtualmethod in pd.procoptions) then
  4107. begin
  4108. lindex := pd.extnumber;
  4109. {doesnt seem to be necessary
  4110. lindex := lindex or $80000000;}
  4111. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  4112. end
  4113. else
  4114. virtualind := '.';
  4115. { used by gdbpas to recognize constructor and destructors }
  4116. if (pd.proctypeoption=potype_constructor) then
  4117. argnames:='__ct__'
  4118. else if (pd.proctypeoption=potype_destructor) then
  4119. argnames:='__dt__'
  4120. else
  4121. argnames := '';
  4122. { arguments are not listed here }
  4123. {we don't need another definition}
  4124. para := TParaItem(pd.Para.first);
  4125. while assigned(para) do
  4126. begin
  4127. if Para.paratype.def.deftype = formaldef then
  4128. begin
  4129. if Para.paratyp=vs_var then
  4130. argnames := argnames+'3var'
  4131. else if Para.paratyp=vs_const then
  4132. argnames:=argnames+'5const'
  4133. else if Para.paratyp=vs_out then
  4134. argnames:=argnames+'3out';
  4135. end
  4136. else
  4137. begin
  4138. { if the arg definition is like (v: ^byte;..
  4139. there is no sym attached to data !!! }
  4140. if assigned(Para.paratype.def.typesym) then
  4141. begin
  4142. arglength := length(Para.paratype.def.typesym.name);
  4143. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4144. end
  4145. else
  4146. begin
  4147. argnames:=argnames+'11unnamedtype';
  4148. end;
  4149. end;
  4150. para := TParaItem(Para.next);
  4151. end;
  4152. ipd.is_def_stab_written := written;
  4153. { here 2A must be changed for private and protected }
  4154. { 0 is private 1 protected and 2 public }
  4155. if (sp_private in tsym(p).symoptions) then sp:='0'
  4156. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  4157. else sp:='2';
  4158. newrec := strpnew(p.name+'::'+ipd.numberstring
  4159. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  4160. +virtualind+';');
  4161. { get spare place for a string at the end }
  4162. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  4163. begin
  4164. getmem(news,stabrecsize+memsizeinc);
  4165. strcopy(news,stabrecstring);
  4166. freemem(stabrecstring,stabrecsize);
  4167. stabrecsize:=stabrecsize+memsizeinc;
  4168. stabrecstring:=news;
  4169. end;
  4170. strcat(StabRecstring,newrec);
  4171. {freemem(newrec,memsizeinc); }
  4172. strdispose(newrec);
  4173. {This should be used for case !!
  4174. RecOffset := RecOffset + pd.size;}
  4175. end;
  4176. end;
  4177. function tobjectdef.stabstring : pchar;
  4178. var anc : tobjectdef;
  4179. oldrec : pchar;
  4180. oldrecsize,oldrecoffset : longint;
  4181. str_end : string;
  4182. begin
  4183. if not (objecttype=odt_class) or writing_class_record_stab then
  4184. begin
  4185. oldrec := stabrecstring;
  4186. oldrecsize:=stabrecsize;
  4187. stabrecsize:=memsizeinc;
  4188. GetMem(stabrecstring,stabrecsize);
  4189. strpcopy(stabRecString,'s'+tostr(symtable.datasize));
  4190. if assigned(childof) then
  4191. begin
  4192. {only one ancestor not virtual, public, at base offset 0 }
  4193. { !1 , 0 2 0 , }
  4194. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  4195. end;
  4196. {virtual table to implement yet}
  4197. OldRecOffset:=RecOffset;
  4198. RecOffset := 0;
  4199. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  4200. RecOffset:=OldRecOffset;
  4201. if (oo_has_vmt in objectoptions) then
  4202. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4203. begin
  4204. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  4205. +','+tostr(vmt_offset*8)+';');
  4206. end;
  4207. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname,nil);
  4208. if (oo_has_vmt in objectoptions) then
  4209. begin
  4210. anc := self;
  4211. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4212. anc := anc.childof;
  4213. { just in case anc = self }
  4214. str_end:=';~%'+anc.classnumberstring+';';
  4215. end
  4216. else
  4217. str_end:=';';
  4218. strpcopy(strend(stabrecstring),str_end);
  4219. stabstring := strnew(StabRecString);
  4220. freemem(stabrecstring,stabrecsize);
  4221. stabrecstring := oldrec;
  4222. stabrecsize:=oldrecsize;
  4223. end
  4224. else
  4225. begin
  4226. stabstring:=strpnew('*'+classnumberstring);
  4227. end;
  4228. end;
  4229. procedure tobjectdef.set_globalnb;
  4230. begin
  4231. globalnb:=PglobalTypeCount^;
  4232. inc(PglobalTypeCount^);
  4233. { classes need two type numbers, the globalnb is set to the ptr }
  4234. if objecttype=odt_class then
  4235. begin
  4236. globalnb:=PGlobalTypeCount^;
  4237. inc(PglobalTypeCount^);
  4238. end;
  4239. end;
  4240. function tobjectdef.classnumberstring : string;
  4241. begin
  4242. { write stabs again if needed }
  4243. numberstring;
  4244. if objecttype=odt_class then
  4245. begin
  4246. dec(globalnb);
  4247. classnumberstring:=numberstring;
  4248. inc(globalnb);
  4249. end
  4250. else
  4251. classnumberstring:=numberstring;
  4252. end;
  4253. function tobjectdef.allstabstring : pchar;
  4254. var stabchar : string[2];
  4255. ss,st : pchar;
  4256. sname : string;
  4257. sym_line_no : longint;
  4258. begin
  4259. ss := stabstring;
  4260. getmem(st,strlen(ss)+512);
  4261. stabchar := 't';
  4262. if deftype in tagtypes then
  4263. stabchar := 'Tt';
  4264. if assigned(typesym) then
  4265. begin
  4266. sname := typesym.name;
  4267. sym_line_no:=typesym.fileinfo.line;
  4268. end
  4269. else
  4270. begin
  4271. sname := ' ';
  4272. sym_line_no:=0;
  4273. end;
  4274. if writing_class_record_stab then
  4275. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4276. else
  4277. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4278. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4279. allstabstring := strnew(st);
  4280. freemem(st,strlen(ss)+512);
  4281. strdispose(ss);
  4282. end;
  4283. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4284. var st : pstring;
  4285. begin
  4286. if objecttype<>odt_class then
  4287. begin
  4288. inherited concatstabto(asmlist);
  4289. exit;
  4290. end;
  4291. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4292. (is_def_stab_written = not_written) then
  4293. begin
  4294. if globalnb=0 then
  4295. set_globalnb;
  4296. { Write the record class itself }
  4297. writing_class_record_stab:=true;
  4298. inherited concatstabto(asmlist);
  4299. writing_class_record_stab:=false;
  4300. { Write the invisible pointer class }
  4301. is_def_stab_written:=not_written;
  4302. if assigned(typesym) then
  4303. begin
  4304. st:=typesym.FName;
  4305. typesym.FName:=stringdup(' ');
  4306. end;
  4307. inherited concatstabto(asmlist);
  4308. if assigned(typesym) then
  4309. begin
  4310. stringdispose(typesym.FName);
  4311. typesym.FName:=st;
  4312. end;
  4313. end;
  4314. end;
  4315. {$endif GDB}
  4316. function tobjectdef.needs_inittable : boolean;
  4317. begin
  4318. case objecttype of
  4319. odt_class :
  4320. needs_inittable:=false;
  4321. odt_interfacecom:
  4322. needs_inittable:=true;
  4323. odt_interfacecorba:
  4324. needs_inittable:=is_related(interface_iunknown);
  4325. odt_object:
  4326. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4327. else
  4328. internalerror(200108267);
  4329. end;
  4330. end;
  4331. function tobjectdef.members_need_inittable : boolean;
  4332. begin
  4333. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4334. end;
  4335. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4336. begin
  4337. if needs_prop_entry(tsym(sym)) and
  4338. (tsym(sym).typ<>varsym) then
  4339. inc(count);
  4340. end;
  4341. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4342. var
  4343. proctypesinfo : byte;
  4344. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4345. var
  4346. typvalue : byte;
  4347. hp : psymlistitem;
  4348. address : longint;
  4349. begin
  4350. if not(assigned(proc) and assigned(proc.firstsym)) then
  4351. begin
  4352. rttiList.concat(Tai_const.Create_32bit(1));
  4353. typvalue:=3;
  4354. end
  4355. else if proc.firstsym^.sym.typ=varsym then
  4356. begin
  4357. address:=0;
  4358. hp:=proc.firstsym;
  4359. while assigned(hp) do
  4360. begin
  4361. inc(address,tvarsym(hp^.sym).address);
  4362. hp:=hp^.next;
  4363. end;
  4364. rttiList.concat(Tai_const.Create_32bit(address));
  4365. typvalue:=0;
  4366. end
  4367. else
  4368. begin
  4369. if not(po_virtualmethod in tprocdef(proc.def).procoptions) then
  4370. begin
  4371. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.def).mangledname));
  4372. typvalue:=1;
  4373. end
  4374. else
  4375. begin
  4376. { virtual method, write vmt offset }
  4377. rttiList.concat(Tai_const.Create_32bit(
  4378. tprocdef(proc.def)._class.vmtmethodoffset(tprocdef(proc.def).extnumber)));
  4379. typvalue:=2;
  4380. end;
  4381. end;
  4382. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4383. end;
  4384. begin
  4385. if needs_prop_entry(tsym(sym)) then
  4386. case tsym(sym).typ of
  4387. varsym:
  4388. begin
  4389. {$ifdef dummy}
  4390. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4391. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4392. internalerror(1509992);
  4393. { access to implicit class property as field }
  4394. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4395. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4396. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4397. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4398. { per default stored }
  4399. rttiList.concat(Tai_const.Create_32bit(1));
  4400. { index as well as ... }
  4401. rttiList.concat(Tai_const.Create_32bit(0));
  4402. { default value are zero }
  4403. rttiList.concat(Tai_const.Create_32bit(0));
  4404. rttiList.concat(Tai_const.Create_16bit(count));
  4405. inc(count);
  4406. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4407. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4408. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4409. {$endif dummy}
  4410. end;
  4411. propertysym:
  4412. begin
  4413. if ppo_indexed in tpropertysym(sym).propoptions then
  4414. proctypesinfo:=$40
  4415. else
  4416. proctypesinfo:=0;
  4417. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4418. writeproc(tpropertysym(sym).readaccess,0);
  4419. writeproc(tpropertysym(sym).writeaccess,2);
  4420. { isn't it stored ? }
  4421. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4422. begin
  4423. rttiList.concat(Tai_const.Create_32bit(0));
  4424. proctypesinfo:=proctypesinfo or (3 shl 4);
  4425. end
  4426. else
  4427. writeproc(tpropertysym(sym).storedaccess,4);
  4428. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4429. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4430. rttiList.concat(Tai_const.Create_16bit(count));
  4431. inc(count);
  4432. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4433. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4434. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4435. end;
  4436. else internalerror(1509992);
  4437. end;
  4438. end;
  4439. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4440. begin
  4441. if needs_prop_entry(tsym(sym)) then
  4442. begin
  4443. case tsym(sym).typ of
  4444. propertysym:
  4445. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4446. varsym:
  4447. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4448. else
  4449. internalerror(1509991);
  4450. end;
  4451. end;
  4452. end;
  4453. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4454. begin
  4455. FRTTIType:=rt;
  4456. case rt of
  4457. initrtti :
  4458. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4459. fullrtti :
  4460. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4461. else
  4462. internalerror(200108301);
  4463. end;
  4464. end;
  4465. type
  4466. tclasslistitem = class(TLinkedListItem)
  4467. index : longint;
  4468. p : tobjectdef;
  4469. end;
  4470. var
  4471. classtablelist : tlinkedlist;
  4472. tablecount : longint;
  4473. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4474. var
  4475. hp : tclasslistitem;
  4476. begin
  4477. hp:=tclasslistitem(classtablelist.first);
  4478. while assigned(hp) do
  4479. if hp.p=p then
  4480. begin
  4481. searchclasstablelist:=hp;
  4482. exit;
  4483. end
  4484. else
  4485. hp:=tclasslistitem(hp.next);
  4486. searchclasstablelist:=nil;
  4487. end;
  4488. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4489. var
  4490. hp : tclasslistitem;
  4491. begin
  4492. if needs_prop_entry(tsym(sym)) and
  4493. (tsym(sym).typ=varsym) then
  4494. begin
  4495. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4496. internalerror(0206001);
  4497. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4498. if not(assigned(hp)) then
  4499. begin
  4500. hp:=tclasslistitem.create;
  4501. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4502. hp.index:=tablecount;
  4503. classtablelist.concat(hp);
  4504. inc(tablecount);
  4505. end;
  4506. inc(count);
  4507. end;
  4508. end;
  4509. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4510. var
  4511. hp : tclasslistitem;
  4512. begin
  4513. if needs_prop_entry(tsym(sym)) and
  4514. (tsym(sym).typ=varsym) then
  4515. begin
  4516. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  4517. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4518. if not(assigned(hp)) then
  4519. internalerror(0206002);
  4520. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4521. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4522. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4523. end;
  4524. end;
  4525. function tobjectdef.generate_field_table : tasmlabel;
  4526. var
  4527. fieldtable,
  4528. classtable : tasmlabel;
  4529. hp : tclasslistitem;
  4530. begin
  4531. classtablelist:=TLinkedList.Create;
  4532. objectlibrary.getdatalabel(fieldtable);
  4533. objectlibrary.getdatalabel(classtable);
  4534. count:=0;
  4535. tablecount:=0;
  4536. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4537. if (cs_create_smart in aktmoduleswitches) then
  4538. rttiList.concat(Tai_cut.Create);
  4539. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4540. rttiList.concat(Tai_label.Create(fieldtable));
  4541. rttiList.concat(Tai_const.Create_16bit(count));
  4542. rttiList.concat(Tai_const_symbol.Create(classtable));
  4543. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4544. { generate the class table }
  4545. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4546. rttiList.concat(Tai_label.Create(classtable));
  4547. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4548. hp:=tclasslistitem(classtablelist.first);
  4549. while assigned(hp) do
  4550. begin
  4551. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4552. hp:=tclasslistitem(hp.next);
  4553. end;
  4554. generate_field_table:=fieldtable;
  4555. classtablelist.free;
  4556. end;
  4557. function tobjectdef.next_free_name_index : longint;
  4558. var
  4559. i : longint;
  4560. begin
  4561. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4562. i:=childof.next_free_name_index
  4563. else
  4564. i:=0;
  4565. count:=0;
  4566. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4567. next_free_name_index:=i+count;
  4568. end;
  4569. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4570. begin
  4571. case objecttype of
  4572. odt_class:
  4573. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4574. odt_object:
  4575. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4576. odt_interfacecom:
  4577. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4578. odt_interfacecorba:
  4579. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4580. else
  4581. exit;
  4582. end;
  4583. { generate the name }
  4584. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4585. rttiList.concat(Tai_string.Create(objrealname^));
  4586. case rt of
  4587. initrtti :
  4588. begin
  4589. rttiList.concat(Tai_const.Create_32bit(size));
  4590. if objecttype in [odt_class,odt_object] then
  4591. begin
  4592. count:=0;
  4593. FRTTIType:=rt;
  4594. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4595. rttiList.concat(Tai_const.Create_32bit(count));
  4596. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4597. end;
  4598. end;
  4599. fullrtti :
  4600. begin
  4601. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4602. rttiList.concat(Tai_const.Create_32bit(0))
  4603. else
  4604. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname));
  4605. { write owner typeinfo }
  4606. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4607. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4608. else
  4609. rttiList.concat(Tai_const.Create_32bit(0));
  4610. { count total number of properties }
  4611. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4612. count:=childof.next_free_name_index
  4613. else
  4614. count:=0;
  4615. { write it }
  4616. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4617. rttiList.concat(Tai_const.Create_16bit(count));
  4618. { write unit name }
  4619. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4620. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4621. { write published properties count }
  4622. count:=0;
  4623. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4624. rttiList.concat(Tai_const.Create_16bit(count));
  4625. { count is used to write nameindex }
  4626. { but we need an offset of the owner }
  4627. { to give each property an own slot }
  4628. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4629. count:=childof.next_free_name_index
  4630. else
  4631. count:=0;
  4632. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4633. end;
  4634. end;
  4635. end;
  4636. function tobjectdef.is_publishable : boolean;
  4637. begin
  4638. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4639. end;
  4640. {****************************************************************************
  4641. TIMPLEMENTEDINTERFACES
  4642. ****************************************************************************}
  4643. type
  4644. tnamemap = class(TNamedIndexItem)
  4645. newname: pstring;
  4646. constructor create(const aname, anewname: string);
  4647. destructor destroy; override;
  4648. end;
  4649. constructor tnamemap.create(const aname, anewname: string);
  4650. begin
  4651. inherited createname(name);
  4652. newname:=stringdup(anewname);
  4653. end;
  4654. destructor tnamemap.destroy;
  4655. begin
  4656. stringdispose(newname);
  4657. inherited destroy;
  4658. end;
  4659. type
  4660. tprocdefstore = class(TNamedIndexItem)
  4661. procdef: tprocdef;
  4662. constructor create(aprocdef: tprocdef);
  4663. end;
  4664. constructor tprocdefstore.create(aprocdef: tprocdef);
  4665. begin
  4666. inherited create;
  4667. procdef:=aprocdef;
  4668. end;
  4669. type
  4670. timplintfentry = class(TNamedIndexItem)
  4671. intf: tobjectdef;
  4672. ioffs: longint;
  4673. namemappings: tdictionary;
  4674. procdefs: TIndexArray;
  4675. constructor create(aintf: tobjectdef);
  4676. destructor destroy; override;
  4677. end;
  4678. constructor timplintfentry.create(aintf: tobjectdef);
  4679. begin
  4680. inherited create;
  4681. intf:=aintf;
  4682. ioffs:=-1;
  4683. namemappings:=nil;
  4684. procdefs:=nil;
  4685. end;
  4686. destructor timplintfentry.destroy;
  4687. begin
  4688. if assigned(namemappings) then
  4689. namemappings.free;
  4690. if assigned(procdefs) then
  4691. procdefs.free;
  4692. inherited destroy;
  4693. end;
  4694. constructor timplementedinterfaces.create;
  4695. begin
  4696. finterfaces:=tindexarray.create(1);
  4697. end;
  4698. destructor timplementedinterfaces.destroy;
  4699. begin
  4700. finterfaces.destroy;
  4701. end;
  4702. function timplementedinterfaces.count: longint;
  4703. begin
  4704. count:=finterfaces.count;
  4705. end;
  4706. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4707. begin
  4708. if (intfindex<1) or (intfindex>count) then
  4709. InternalError(200006123);
  4710. end;
  4711. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4712. begin
  4713. checkindex(intfindex);
  4714. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4715. end;
  4716. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  4717. begin
  4718. checkindex(intfindex);
  4719. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  4720. end;
  4721. function timplementedinterfaces.searchintf(def: tdef): longint;
  4722. var
  4723. i: longint;
  4724. begin
  4725. i:=1;
  4726. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4727. if i<=count then
  4728. searchintf:=i
  4729. else
  4730. searchintf:=-1;
  4731. end;
  4732. procedure timplementedinterfaces.deref;
  4733. var
  4734. i: longint;
  4735. begin
  4736. for i:=1 to count do
  4737. with timplintfentry(finterfaces.search(i)) do
  4738. resolvedef(pointer(intf));
  4739. end;
  4740. procedure timplementedinterfaces.addintfref(def: pointer);
  4741. begin
  4742. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4743. end;
  4744. procedure timplementedinterfaces.addintf(def: tdef);
  4745. begin
  4746. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4747. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4748. internalerror(200006124);
  4749. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4750. end;
  4751. procedure timplementedinterfaces.clearmappings;
  4752. var
  4753. i: longint;
  4754. begin
  4755. for i:=1 to count do
  4756. with timplintfentry(finterfaces.search(i)) do
  4757. begin
  4758. if assigned(namemappings) then
  4759. namemappings.free;
  4760. namemappings:=nil;
  4761. end;
  4762. end;
  4763. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  4764. begin
  4765. checkindex(intfindex);
  4766. with timplintfentry(finterfaces.search(intfindex)) do
  4767. begin
  4768. if not assigned(namemappings) then
  4769. namemappings:=tdictionary.create;
  4770. namemappings.insert(tnamemap.create(name,newname));
  4771. end;
  4772. end;
  4773. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  4774. begin
  4775. checkindex(intfindex);
  4776. if not assigned(nextexist) then
  4777. with timplintfentry(finterfaces.search(intfindex)) do
  4778. begin
  4779. if assigned(namemappings) then
  4780. nextexist:=namemappings.search(name)
  4781. else
  4782. nextexist:=nil;
  4783. end;
  4784. if assigned(nextexist) then
  4785. begin
  4786. getmappings:=tnamemap(nextexist).newname^;
  4787. nextexist:=tnamemap(nextexist).listnext;
  4788. end
  4789. else
  4790. getmappings:='';
  4791. end;
  4792. procedure timplementedinterfaces.clearimplprocs;
  4793. var
  4794. i: longint;
  4795. begin
  4796. for i:=1 to count do
  4797. with timplintfentry(finterfaces.search(i)) do
  4798. begin
  4799. if assigned(procdefs) then
  4800. procdefs.free;
  4801. procdefs:=nil;
  4802. end;
  4803. end;
  4804. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4805. begin
  4806. checkindex(intfindex);
  4807. with timplintfentry(finterfaces.search(intfindex)) do
  4808. begin
  4809. if not assigned(procdefs) then
  4810. procdefs:=tindexarray.create(4);
  4811. procdefs.insert(tprocdefstore.create(procdef));
  4812. end;
  4813. end;
  4814. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4815. begin
  4816. checkindex(intfindex);
  4817. with timplintfentry(finterfaces.search(intfindex)) do
  4818. if assigned(procdefs) then
  4819. implproccount:=procdefs.count
  4820. else
  4821. implproccount:=0;
  4822. end;
  4823. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4824. begin
  4825. checkindex(intfindex);
  4826. with timplintfentry(finterfaces.search(intfindex)) do
  4827. if assigned(procdefs) then
  4828. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4829. else
  4830. internalerror(200006131);
  4831. end;
  4832. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4833. var
  4834. possible: boolean;
  4835. i: longint;
  4836. iiep1: TIndexArray;
  4837. iiep2: TIndexArray;
  4838. begin
  4839. checkindex(intfindex);
  4840. checkindex(remainindex);
  4841. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4842. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4843. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4844. begin
  4845. possible:=true;
  4846. weight:=0;
  4847. end
  4848. else
  4849. begin
  4850. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4851. i:=1;
  4852. while (possible) and (i<=iiep1.count) do
  4853. begin
  4854. possible:=
  4855. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4856. inc(i);
  4857. end;
  4858. if possible then
  4859. weight:=iiep1.count;
  4860. end;
  4861. isimplmergepossible:=possible;
  4862. end;
  4863. {****************************************************************************
  4864. TFORWARDDEF
  4865. ****************************************************************************}
  4866. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4867. var
  4868. oldregisterdef : boolean;
  4869. begin
  4870. { never register the forwarddefs, they are disposed at the
  4871. end of the type declaration block }
  4872. oldregisterdef:=registerdef;
  4873. registerdef:=false;
  4874. inherited create;
  4875. registerdef:=oldregisterdef;
  4876. deftype:=forwarddef;
  4877. tosymname:=stringdup(s);
  4878. forwardpos:=pos;
  4879. end;
  4880. function tforwarddef.gettypename:string;
  4881. begin
  4882. gettypename:='unresolved forward to '+tosymname^;
  4883. end;
  4884. destructor tforwarddef.destroy;
  4885. begin
  4886. if assigned(tosymname) then
  4887. stringdispose(tosymname);
  4888. inherited destroy;
  4889. end;
  4890. {****************************************************************************
  4891. TERRORDEF
  4892. ****************************************************************************}
  4893. constructor terrordef.create;
  4894. begin
  4895. inherited create;
  4896. deftype:=errordef;
  4897. end;
  4898. {$ifdef GDB}
  4899. function terrordef.stabstring : pchar;
  4900. begin
  4901. stabstring:=strpnew('error'+numberstring);
  4902. end;
  4903. procedure terrordef.concatstabto(asmlist : taasmoutput);
  4904. begin
  4905. { No internal error needed, an normal error is already
  4906. thrown }
  4907. end;
  4908. {$endif GDB}
  4909. function terrordef.gettypename:string;
  4910. begin
  4911. gettypename:='<erroneous type>';
  4912. end;
  4913. function terrordef.getmangledparaname:string;
  4914. begin
  4915. getmangledparaname:='error';
  4916. end;
  4917. {****************************************************************************
  4918. GDB Helpers
  4919. ****************************************************************************}
  4920. {$ifdef GDB}
  4921. function typeglobalnumber(const s : string) : string;
  4922. var st : string;
  4923. symt : tsymtable;
  4924. srsym : tsym;
  4925. srsymtable : tsymtable;
  4926. old_make_ref : boolean;
  4927. begin
  4928. old_make_ref:=make_ref;
  4929. make_ref:=false;
  4930. typeglobalnumber := '0';
  4931. srsym := nil;
  4932. if pos('.',s) > 0 then
  4933. begin
  4934. st := copy(s,1,pos('.',s)-1);
  4935. searchsym(st,srsym,srsymtable);
  4936. st := copy(s,pos('.',s)+1,255);
  4937. if assigned(srsym) then
  4938. begin
  4939. if srsym.typ = unitsym then
  4940. begin
  4941. symt := tunitsym(srsym).unitsymtable;
  4942. srsym := tsym(symt.search(st));
  4943. end else srsym := nil;
  4944. end;
  4945. end else st := s;
  4946. if srsym = nil then
  4947. searchsym(st,srsym,srsymtable);
  4948. if (srsym=nil) or
  4949. (srsym.typ<>typesym) then
  4950. begin
  4951. Message(type_e_type_id_expected);
  4952. exit;
  4953. end;
  4954. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  4955. make_ref:=old_make_ref;
  4956. end;
  4957. {$endif GDB}
  4958. {****************************************************************************
  4959. Definition Helpers
  4960. ****************************************************************************}
  4961. procedure reset_global_defs;
  4962. var
  4963. def : tstoreddef;
  4964. {$ifdef debug}
  4965. prevdef : tstoreddef;
  4966. {$endif debug}
  4967. begin
  4968. {$ifdef debug}
  4969. prevdef:=nil;
  4970. {$endif debug}
  4971. {$ifdef GDB}
  4972. pglobaltypecount:=@globaltypecount;
  4973. {$endif GDB}
  4974. def:=firstglobaldef;
  4975. while assigned(def) do
  4976. begin
  4977. {$ifdef GDB}
  4978. if assigned(def.typesym) then
  4979. ttypesym(def.typesym).isusedinstab:=false;
  4980. def.is_def_stab_written:=not_written;
  4981. {$endif GDB}
  4982. if assigned(def.rttitablesym) then
  4983. trttisym(def.rttitablesym).lab := nil;
  4984. if assigned(def.inittablesym) then
  4985. trttisym(def.inittablesym).lab := nil;
  4986. def.localrttilab[initrtti]:=nil;
  4987. def.localrttilab[fullrtti]:=nil;
  4988. {$ifdef debug}
  4989. prevdef:=def;
  4990. {$endif debug}
  4991. def:=def.nextglobal;
  4992. end;
  4993. end;
  4994. function is_interfacecom(def: tdef): boolean;
  4995. begin
  4996. is_interfacecom:=
  4997. assigned(def) and
  4998. (def.deftype=objectdef) and
  4999. (tobjectdef(def).objecttype=odt_interfacecom);
  5000. end;
  5001. function is_interfacecorba(def: tdef): boolean;
  5002. begin
  5003. is_interfacecorba:=
  5004. assigned(def) and
  5005. (def.deftype=objectdef) and
  5006. (tobjectdef(def).objecttype=odt_interfacecorba);
  5007. end;
  5008. function is_interface(def: tdef): boolean;
  5009. begin
  5010. is_interface:=
  5011. assigned(def) and
  5012. (def.deftype=objectdef) and
  5013. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5014. end;
  5015. function is_class(def: tdef): boolean;
  5016. begin
  5017. is_class:=
  5018. assigned(def) and
  5019. (def.deftype=objectdef) and
  5020. (tobjectdef(def).objecttype=odt_class);
  5021. end;
  5022. function is_object(def: tdef): boolean;
  5023. begin
  5024. is_object:=
  5025. assigned(def) and
  5026. (def.deftype=objectdef) and
  5027. (tobjectdef(def).objecttype=odt_object);
  5028. end;
  5029. function is_cppclass(def: tdef): boolean;
  5030. begin
  5031. is_cppclass:=
  5032. assigned(def) and
  5033. (def.deftype=objectdef) and
  5034. (tobjectdef(def).objecttype=odt_cppclass);
  5035. end;
  5036. function is_class_or_interface(def: tdef): boolean;
  5037. begin
  5038. is_class_or_interface:=
  5039. assigned(def) and
  5040. (def.deftype=objectdef) and
  5041. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5042. end;
  5043. end.
  5044. {
  5045. $Log$
  5046. Revision 1.140 2003-05-05 14:53:16 peter
  5047. * vs_hidden replaced by is_hidden boolean
  5048. Revision 1.139 2003/05/01 07:59:43 florian
  5049. * introduced defaultordconsttype to decribe the default size of ordinal constants
  5050. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  5051. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  5052. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  5053. Revision 1.138 2003/04/27 11:21:34 peter
  5054. * aktprocdef renamed to current_procdef
  5055. * procinfo renamed to current_procinfo
  5056. * procinfo will now be stored in current_module so it can be
  5057. cleaned up properly
  5058. * gen_main_procsym changed to create_main_proc and release_main_proc
  5059. to also generate a tprocinfo structure
  5060. * fixed unit implicit initfinal
  5061. Revision 1.137 2003/04/27 07:29:51 peter
  5062. * current_procdef cleanup, current_procdef is now always nil when parsing
  5063. a new procdef declaration
  5064. * aktprocsym removed
  5065. * lexlevel removed, use symtable.symtablelevel instead
  5066. * implicit init/final code uses the normal genentry/genexit
  5067. * funcret state checking updated for new funcret handling
  5068. Revision 1.136 2003/04/25 20:59:35 peter
  5069. * removed funcretn,funcretsym, function result is now in varsym
  5070. and aliases for result and function name are added using absolutesym
  5071. * vs_hidden parameter for funcret passed in parameter
  5072. * vs_hidden fixes
  5073. * writenode changed to printnode and released from extdebug
  5074. * -vp option added to generate a tree.log with the nodetree
  5075. * nicer printnode for statements, callnode
  5076. Revision 1.135 2003/04/23 20:16:04 peter
  5077. + added currency support based on int64
  5078. + is_64bit for use in cg units instead of is_64bitint
  5079. * removed cgmessage from n386add, replace with internalerrors
  5080. Revision 1.134 2003/04/23 12:35:34 florian
  5081. * fixed several issues with powerpc
  5082. + applied a patch from Jonas for nested function calls (PowerPC only)
  5083. * ...
  5084. Revision 1.133 2003/04/10 17:57:53 peter
  5085. * vs_hidden released
  5086. Revision 1.132 2003/03/18 16:25:50 peter
  5087. * no itnernalerror for errordef.concatstabto()
  5088. Revision 1.131 2003/03/17 16:54:41 peter
  5089. * support DefaultHandler and anonymous inheritance fixed
  5090. for message methods
  5091. Revision 1.130 2003/03/17 15:54:22 peter
  5092. * store symoptions also for procdef
  5093. * check symoptions (private,public) when calculating possible
  5094. overload candidates
  5095. Revision 1.129 2003/02/19 22:00:14 daniel
  5096. * Code generator converted to new register notation
  5097. - Horribily outdated todo.txt removed
  5098. Revision 1.128 2003/02/02 19:25:54 carl
  5099. * Several bugfixes for m68k target (register alloc., opcode emission)
  5100. + VIS target
  5101. + Generic add more complete (still not verified)
  5102. Revision 1.127 2003/01/21 14:36:44 pierre
  5103. * set sizes needs to be passes in bits not bytes to stabs info
  5104. Revision 1.126 2003/01/16 22:11:33 peter
  5105. * fixed tprocdef.is_addressonly
  5106. Revision 1.125 2003/01/15 01:44:33 peter
  5107. * merged methodpointer fixes from 1.0.x
  5108. Revision 1.124 2003/01/09 21:52:37 peter
  5109. * merged some verbosity options.
  5110. * V_LineInfo is a verbosity flag to include line info
  5111. Revision 1.123 2003/01/06 21:16:52 peter
  5112. * po_addressonly added to retrieve the address of a methodpointer
  5113. only, this is used for @tclass.method which has no self pointer
  5114. Revision 1.122 2003/01/05 15:54:15 florian
  5115. + added proper support of type = type <type>; for simple types
  5116. Revision 1.121 2003/01/05 13:36:53 florian
  5117. * x86-64 compiles
  5118. + very basic support for float128 type (x86-64 only)
  5119. Revision 1.120 2003/01/02 19:49:00 peter
  5120. * update self parameter only for methodpointer and methods
  5121. Revision 1.119 2002/12/29 18:25:59 peter
  5122. * tprocdef.gettypename implemented
  5123. Revision 1.118 2002/12/27 15:23:09 peter
  5124. * write class methods in fullname
  5125. Revision 1.117 2002/12/15 19:34:31 florian
  5126. + some front end stuff for vs_hidden added
  5127. Revision 1.116 2002/12/15 11:26:02 peter
  5128. * ignore vs_hidden parameters when choosing overloaded proc
  5129. Revision 1.115 2002/12/07 14:27:09 carl
  5130. * 3% memory optimization
  5131. * changed some types
  5132. + added type checking with different size for call node and for
  5133. parameters
  5134. Revision 1.114 2002/12/01 22:05:27 carl
  5135. * no more warnings for structures over 32K since this is
  5136. handled correctly in this version of the compiler.
  5137. Revision 1.113 2002/11/27 20:04:09 peter
  5138. * tvarsym.get_push_size replaced by paramanager.push_size
  5139. Revision 1.112 2002/11/25 21:05:53 carl
  5140. * several mistakes fixed in message files
  5141. Revision 1.111 2002/11/25 18:43:33 carl
  5142. - removed the invalid if <> checking (Delphi is strange on this)
  5143. + implemented abstract warning on instance creation of class with
  5144. abstract methods.
  5145. * some error message cleanups
  5146. Revision 1.110 2002/11/25 17:43:24 peter
  5147. * splitted defbase in defutil,symutil,defcmp
  5148. * merged isconvertable and is_equal into compare_defs(_ext)
  5149. * made operator search faster by walking the list only once
  5150. Revision 1.109 2002/11/23 22:50:06 carl
  5151. * some small speed optimizations
  5152. + added several new warnings/hints
  5153. Revision 1.108 2002/11/22 22:48:10 carl
  5154. * memory optimization with tconstsym (1.5%)
  5155. Revision 1.107 2002/11/19 16:21:29 pierre
  5156. * correct several stabs generation problems
  5157. Revision 1.106 2002/11/18 17:31:59 peter
  5158. * pass proccalloption to ret_in_xxx and push_xxx functions
  5159. Revision 1.105 2002/11/17 16:31:57 carl
  5160. * memory optimization (3-4%) : cleanup of tai fields,
  5161. cleanup of tdef and tsym fields.
  5162. * make it work for m68k
  5163. Revision 1.104 2002/11/16 19:53:18 carl
  5164. * avoid Range check errors
  5165. Revision 1.103 2002/11/15 16:29:09 peter
  5166. * fixed rtti for int64 (merged)
  5167. Revision 1.102 2002/11/15 01:58:54 peter
  5168. * merged changes from 1.0.7 up to 04-11
  5169. - -V option for generating bug report tracing
  5170. - more tracing for option parsing
  5171. - errors for cdecl and high()
  5172. - win32 import stabs
  5173. - win32 records<=8 are returned in eax:edx (turned off by default)
  5174. - heaptrc update
  5175. - more info for temp management in .s file with EXTDEBUG
  5176. Revision 1.101 2002/11/09 15:31:02 carl
  5177. + align RTTI tables
  5178. Revision 1.100 2002/10/19 15:09:25 peter
  5179. + tobjectdef.members_need_inittable that is used to generate only the
  5180. inittable when it is really used. This saves a lot of useless calls
  5181. to fpc_finalize when destroying classes
  5182. Revision 1.99 2002/10/07 21:30:27 peter
  5183. * removed obsolete rangecheck stuff
  5184. Revision 1.98 2002/10/05 15:14:26 peter
  5185. * getparamangeldname for errordef
  5186. Revision 1.97 2002/10/05 12:43:28 carl
  5187. * fixes for Delphi 6 compilation
  5188. (warning : Some features do not work under Delphi)
  5189. Revision 1.96 2002/09/27 21:13:29 carl
  5190. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  5191. Revision 1.95 2002/09/16 09:31:10 florian
  5192. * fixed currency size
  5193. Revision 1.94 2002/09/09 17:34:15 peter
  5194. * tdicationary.replace added to replace and item in a dictionary. This
  5195. is only allowed for the same name
  5196. * varsyms are inserted in symtable before the types are parsed. This
  5197. fixes the long standing "var longint : longint" bug
  5198. - consume_idlist and idstringlist removed. The loops are inserted
  5199. at the callers place and uses the symtable for duplicate id checking
  5200. Revision 1.93 2002/09/07 15:25:07 peter
  5201. * old logs removed and tabs fixed
  5202. Revision 1.92 2002/09/05 19:29:42 peter
  5203. * memdebug enhancements
  5204. Revision 1.91 2002/08/25 19:25:20 peter
  5205. * sym.insert_in_data removed
  5206. * symtable.insertvardata/insertconstdata added
  5207. * removed insert_in_data call from symtable.insert, it needs to be
  5208. called separatly. This allows to deref the address calculation
  5209. * procedures now calculate the parast addresses after the procedure
  5210. directives are parsed. This fixes the cdecl parast problem
  5211. * push_addr_param has an extra argument that specifies if cdecl is used
  5212. or not
  5213. Revision 1.90 2002/08/18 20:06:25 peter
  5214. * inlining is now also allowed in interface
  5215. * renamed write/load to ppuwrite/ppuload
  5216. * tnode storing in ppu
  5217. * nld,ncon,nbas are already updated for storing in ppu
  5218. Revision 1.89 2002/08/11 15:28:00 florian
  5219. + support of explicit type case <any ordinal type>->pointer
  5220. (delphi mode only)
  5221. Revision 1.88 2002/08/11 14:32:28 peter
  5222. * renamed current_library to objectlibrary
  5223. Revision 1.87 2002/08/11 13:24:13 peter
  5224. * saving of asmsymbols in ppu supported
  5225. * asmsymbollist global is removed and moved into a new class
  5226. tasmlibrarydata that will hold the info of a .a file which
  5227. corresponds with a single module. Added librarydata to tmodule
  5228. to keep the library info stored for the module. In the future the
  5229. objectfiles will also be stored to the tasmlibrarydata class
  5230. * all getlabel/newasmsymbol and friends are moved to the new class
  5231. Revision 1.86 2002/08/09 07:33:03 florian
  5232. * a couple of interface related fixes
  5233. Revision 1.85 2002/07/23 09:51:24 daniel
  5234. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  5235. are worth comitting.
  5236. Revision 1.84 2002/07/20 11:57:57 florian
  5237. * types.pas renamed to defbase.pas because D6 contains a types
  5238. unit so this would conflicts if D6 programms are compiled
  5239. + Willamette/SSE2 instructions to assembler added
  5240. Revision 1.83 2002/07/11 14:41:30 florian
  5241. * start of the new generic parameter handling
  5242. Revision 1.82 2002/07/07 09:52:32 florian
  5243. * powerpc target fixed, very simple units can be compiled
  5244. * some basic stuff for better callparanode handling, far from being finished
  5245. Revision 1.81 2002/07/01 18:46:26 peter
  5246. * internal linker
  5247. * reorganized aasm layer
  5248. Revision 1.80 2002/07/01 16:23:54 peter
  5249. * cg64 patch
  5250. * basics for currency
  5251. * asnode updates for class and interface (not finished)
  5252. Revision 1.79 2002/05/18 13:34:18 peter
  5253. * readded missing revisions
  5254. Revision 1.78 2002/05/16 19:46:44 carl
  5255. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  5256. + try to fix temp allocation (still in ifdef)
  5257. + generic constructor calls
  5258. + start of tassembler / tmodulebase class cleanup
  5259. Revision 1.76 2002/05/12 16:53:10 peter
  5260. * moved entry and exitcode to ncgutil and cgobj
  5261. * foreach gets extra argument for passing local data to the
  5262. iterator function
  5263. * -CR checks also class typecasts at runtime by changing them
  5264. into as
  5265. * fixed compiler to cycle with the -CR option
  5266. * fixed stabs with elf writer, finally the global variables can
  5267. be watched
  5268. * removed a lot of routines from cga unit and replaced them by
  5269. calls to cgobj
  5270. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  5271. u32bit then the other is typecasted also to u32bit without giving
  5272. a rangecheck warning/error.
  5273. * fixed pascal calling method with reversing also the high tree in
  5274. the parast, detected by tcalcst3 test
  5275. Revision 1.75 2002/04/25 20:16:39 peter
  5276. * moved more routines from cga/n386util
  5277. Revision 1.74 2002/04/23 19:16:35 peter
  5278. * add pinline unit that inserts compiler supported functions using
  5279. one or more statements
  5280. * moved finalize and setlength from ninl to pinline
  5281. Revision 1.73 2002/04/21 19:02:05 peter
  5282. * removed newn and disposen nodes, the code is now directly
  5283. inlined from pexpr
  5284. * -an option that will write the secondpass nodes to the .s file, this
  5285. requires EXTDEBUG define to actually write the info
  5286. * fixed various internal errors and crashes due recent code changes
  5287. Revision 1.72 2002/04/20 21:32:25 carl
  5288. + generic FPC_CHECKPOINTER
  5289. + first parameter offset in stack now portable
  5290. * rename some constants
  5291. + move some cpu stuff to other units
  5292. - remove unused constents
  5293. * fix stacksize for some targets
  5294. * fix generic size problems which depend now on EXTEND_SIZE constant
  5295. }