symdef.pas 188 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symdef;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,globals,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,
  28. { ppu }
  29. symppu,ppu,
  30. { node }
  31. node,
  32. { aasm }
  33. aasmbase,aasmtai,cpubase,cpuinfo
  34. {$ifdef Delphi}
  35. ,dmisc
  36. {$endif}
  37. ;
  38. type
  39. {************************************************
  40. TDef
  41. ************************************************}
  42. tstoreddef = class(tdef)
  43. { persistent (available across units) rtti and init tables }
  44. rttitablesym,
  45. inittablesym : tsym; {trttisym}
  46. { local (per module) rtti and init tables }
  47. localrttilab : array[trttitype] of tasmlabel;
  48. { linked list of global definitions }
  49. nextglobal,
  50. previousglobal : tstoreddef;
  51. {$ifdef EXTDEBUG}
  52. fileinfo : tfileposinfo;
  53. {$endif}
  54. {$ifdef GDB}
  55. globalnb : word;
  56. is_def_stab_written : tdefstabstatus;
  57. {$endif GDB}
  58. constructor create;
  59. constructor ppuloaddef(ppufile:tcompilerppufile);
  60. destructor destroy;override;
  61. function getcopy : tstoreddef;virtual;
  62. procedure ppuwritedef(ppufile:tcompilerppufile);
  63. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  64. procedure deref;override;
  65. procedure derefimpl;override;
  66. function size:longint;override;
  67. function alignment:longint;override;
  68. function is_publishable : boolean;override;
  69. function needs_inittable : boolean;override;
  70. { debug }
  71. {$ifdef GDB}
  72. function stabstring : pchar;virtual;
  73. procedure concatstabto(asmlist : taasmoutput);virtual;
  74. function NumberString:string;
  75. procedure set_globalnb;virtual;
  76. function allstabstring : pchar;virtual;
  77. {$endif GDB}
  78. { rtti generation }
  79. procedure write_rtti_name;
  80. procedure write_rtti_data(rt:trttitype);virtual;
  81. procedure write_child_rtti_data(rt:trttitype);virtual;
  82. function get_rtti_label(rt:trttitype):tasmsymbol;
  83. { regvars }
  84. function is_intregable : boolean;
  85. function is_fpuregable : boolean;
  86. private
  87. savesize : longint;
  88. end;
  89. tparaitem = class(TLinkedListItem)
  90. paratype : ttype; { required for procvar }
  91. parasym : tsym;
  92. defaultvalue : tsym; { tconstsym }
  93. paratyp : tvarspez; { required for procvar }
  94. paraloc : tparalocation;
  95. is_hidden : boolean; { is this a hidden (implicit) parameter }
  96. {$ifdef EXTDEBUG}
  97. eqval : tequaltype;
  98. {$endif EXTDEBUG}
  99. end;
  100. tfiletyp = (ft_text,ft_typed,ft_untyped);
  101. tfiledef = class(tstoreddef)
  102. filetyp : tfiletyp;
  103. typedfiletype : ttype;
  104. constructor createtext;
  105. constructor createuntyped;
  106. constructor createtyped(const tt : ttype);
  107. constructor ppuload(ppufile:tcompilerppufile);
  108. procedure ppuwrite(ppufile:tcompilerppufile);override;
  109. procedure deref;override;
  110. function gettypename:string;override;
  111. function getmangledparaname:string;override;
  112. procedure setsize;
  113. { debug }
  114. {$ifdef GDB}
  115. function stabstring : pchar;override;
  116. procedure concatstabto(asmlist : taasmoutput);override;
  117. {$endif GDB}
  118. end;
  119. tvariantdef = class(tstoreddef)
  120. constructor create;
  121. constructor ppuload(ppufile:tcompilerppufile);
  122. function gettypename:string;override;
  123. procedure ppuwrite(ppufile:tcompilerppufile);override;
  124. procedure setsize;
  125. function needs_inittable : boolean;override;
  126. procedure write_rtti_data(rt:trttitype);override;
  127. {$ifdef GDB}
  128. procedure concatstabto(asmlist : taasmoutput);override;
  129. {$endif GDB}
  130. end;
  131. tformaldef = class(tstoreddef)
  132. constructor create;
  133. constructor ppuload(ppufile:tcompilerppufile);
  134. procedure ppuwrite(ppufile:tcompilerppufile);override;
  135. function gettypename:string;override;
  136. {$ifdef GDB}
  137. function stabstring : pchar;override;
  138. procedure concatstabto(asmlist : taasmoutput);override;
  139. {$endif GDB}
  140. end;
  141. tforwarddef = class(tstoreddef)
  142. tosymname : pstring;
  143. forwardpos : tfileposinfo;
  144. constructor create(const s:string;const pos : tfileposinfo);
  145. destructor destroy;override;
  146. function gettypename:string;override;
  147. end;
  148. terrordef = class(tstoreddef)
  149. constructor create;
  150. function gettypename:string;override;
  151. function getmangledparaname : string;override;
  152. { debug }
  153. {$ifdef GDB}
  154. function stabstring : pchar;override;
  155. procedure concatstabto(asmlist : taasmoutput);override;
  156. {$endif GDB}
  157. end;
  158. { tpointerdef and tclassrefdef should get a common
  159. base class, but I derived tclassrefdef from tpointerdef
  160. to avoid problems with bugs (FK)
  161. }
  162. tpointerdef = class(tstoreddef)
  163. pointertype : ttype;
  164. is_far : boolean;
  165. constructor create(const tt : ttype);
  166. constructor createfar(const tt : ttype);
  167. constructor ppuload(ppufile:tcompilerppufile);
  168. procedure ppuwrite(ppufile:tcompilerppufile);override;
  169. procedure deref;override;
  170. function gettypename:string;override;
  171. { debug }
  172. {$ifdef GDB}
  173. function stabstring : pchar;override;
  174. procedure concatstabto(asmlist : taasmoutput);override;
  175. {$endif GDB}
  176. end;
  177. tabstractrecorddef = class(tstoreddef)
  178. private
  179. Count : integer;
  180. FRTTIType : trttitype;
  181. {$ifdef GDB}
  182. StabRecString : pchar;
  183. StabRecSize : Integer;
  184. RecOffset : Integer;
  185. procedure addname(p : tnamedindexitem;arg:pointer);
  186. {$endif}
  187. procedure count_field_rtti(sym : tnamedindexitem;arg:pointer);
  188. procedure write_field_rtti(sym : tnamedindexitem;arg:pointer);
  189. procedure generate_field_rtti(sym : tnamedindexitem;arg:pointer);
  190. public
  191. symtable : tsymtable;
  192. function getsymtable(t:tgetsymtable):tsymtable;override;
  193. end;
  194. trecorddef = class(tabstractrecorddef)
  195. public
  196. isunion : boolean;
  197. constructor create(p : tsymtable);
  198. constructor ppuload(ppufile:tcompilerppufile);
  199. destructor destroy;override;
  200. procedure ppuwrite(ppufile:tcompilerppufile);override;
  201. procedure deref;override;
  202. function size:longint;override;
  203. function alignment : longint;override;
  204. function gettypename:string;override;
  205. { debug }
  206. {$ifdef GDB}
  207. function stabstring : pchar;override;
  208. procedure concatstabto(asmlist : taasmoutput);override;
  209. {$endif GDB}
  210. function needs_inittable : boolean;override;
  211. { rtti }
  212. procedure write_child_rtti_data(rt:trttitype);override;
  213. procedure write_rtti_data(rt:trttitype);override;
  214. end;
  215. tprocdef = class;
  216. timplementedinterfaces = class;
  217. tobjectdef = class(tabstractrecorddef)
  218. private
  219. {$ifdef GDB}
  220. procedure addprocname(p :tnamedindexitem;arg:pointer);
  221. {$endif GDB}
  222. procedure count_published_properties(sym:tnamedindexitem;arg:pointer);
  223. procedure write_property_info(sym : tnamedindexitem;arg:pointer);
  224. procedure generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  225. procedure count_published_fields(sym:tnamedindexitem;arg:pointer);
  226. procedure writefields(sym:tnamedindexitem;arg:pointer);
  227. public
  228. childof : tobjectdef;
  229. objname,
  230. objrealname : pstring;
  231. objectoptions : tobjectoptions;
  232. { to be able to have a variable vmt position }
  233. { and no vmt field for objects without virtuals }
  234. vmt_offset : longint;
  235. {$ifdef GDB}
  236. writing_class_record_stab : boolean;
  237. {$endif GDB}
  238. objecttype : tobjectdeftype;
  239. iidguid: pguid;
  240. iidstr: pstring;
  241. lastvtableindex: longint;
  242. { store implemented interfaces defs and name mappings }
  243. implementedinterfaces: timplementedinterfaces;
  244. constructor create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  245. constructor ppuload(ppufile:tcompilerppufile);
  246. destructor destroy;override;
  247. procedure ppuwrite(ppufile:tcompilerppufile);override;
  248. procedure deref;override;
  249. function size : longint;override;
  250. function alignment:longint;override;
  251. function vmtmethodoffset(index:longint):longint;
  252. function members_need_inittable : boolean;
  253. { this should be called when this class implements an interface }
  254. procedure prepareguid;
  255. function is_publishable : boolean;override;
  256. function needs_inittable : boolean;override;
  257. function vmt_mangledname : string;
  258. function rtti_name : string;
  259. procedure check_forwards;
  260. function is_related(d : tobjectdef) : boolean;
  261. function next_free_name_index : longint;
  262. procedure insertvmt;
  263. procedure set_parent(c : tobjectdef);
  264. function searchdestructor : tprocdef;
  265. { debug }
  266. {$ifdef GDB}
  267. function stabstring : pchar;override;
  268. procedure set_globalnb;override;
  269. function classnumberstring : string;
  270. procedure concatstabto(asmlist : taasmoutput);override;
  271. function allstabstring : pchar;override;
  272. {$endif GDB}
  273. { rtti }
  274. procedure write_child_rtti_data(rt:trttitype);override;
  275. procedure write_rtti_data(rt:trttitype);override;
  276. function generate_field_table : tasmlabel;
  277. end;
  278. timplementedinterfaces = class
  279. constructor create;
  280. destructor destroy; override;
  281. function count: longint;
  282. function interfaces(intfindex: longint): tobjectdef;
  283. function ioffsets(intfindex: longint): plongint;
  284. function searchintf(def: tdef): longint;
  285. procedure addintf(def: tdef);
  286. procedure deref;
  287. { add interface reference loaded from ppu }
  288. procedure addintfref(def: pointer);
  289. procedure clearmappings;
  290. procedure addmappings(intfindex: longint; const name, newname: string);
  291. function getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  292. procedure clearimplprocs;
  293. procedure addimplproc(intfindex: longint; procdef: tprocdef);
  294. function implproccount(intfindex: longint): longint;
  295. function implprocs(intfindex: longint; procindex: longint): tprocdef;
  296. function isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  297. private
  298. finterfaces: tindexarray;
  299. procedure checkindex(intfindex: longint);
  300. end;
  301. tclassrefdef = class(tpointerdef)
  302. constructor create(const t:ttype);
  303. constructor ppuload(ppufile:tcompilerppufile);
  304. procedure ppuwrite(ppufile:tcompilerppufile);override;
  305. function gettypename:string;override;
  306. { debug }
  307. {$ifdef GDB}
  308. function stabstring : pchar;override;
  309. procedure concatstabto(asmlist : taasmoutput);override;
  310. {$endif GDB}
  311. end;
  312. tarraydef = class(tstoreddef)
  313. lowrange,
  314. highrange : longint;
  315. rangetype : ttype;
  316. IsDynamicArray,
  317. IsVariant,
  318. IsConstructor,
  319. IsArrayOfConst : boolean;
  320. protected
  321. _elementtype : ttype;
  322. public
  323. function elesize : longint;
  324. constructor create(l,h : longint;const t : ttype);
  325. constructor ppuload(ppufile:tcompilerppufile);
  326. procedure ppuwrite(ppufile:tcompilerppufile);override;
  327. function gettypename:string;override;
  328. function getmangledparaname : string;override;
  329. procedure setelementtype(t: ttype);
  330. {$ifdef GDB}
  331. function stabstring : pchar;override;
  332. procedure concatstabto(asmlist : taasmoutput);override;
  333. {$endif GDB}
  334. procedure deref;override;
  335. function size : longint;override;
  336. function alignment : longint;override;
  337. { returns the label of the range check string }
  338. function needs_inittable : boolean;override;
  339. procedure write_child_rtti_data(rt:trttitype);override;
  340. procedure write_rtti_data(rt:trttitype);override;
  341. property elementtype : ttype Read _ElementType;
  342. end;
  343. torddef = class(tstoreddef)
  344. low,high : TConstExprInt;
  345. typ : tbasetype;
  346. constructor create(t : tbasetype;v,b : TConstExprInt);
  347. constructor ppuload(ppufile:tcompilerppufile);
  348. function getcopy : tstoreddef;override;
  349. procedure ppuwrite(ppufile:tcompilerppufile);override;
  350. function is_publishable : boolean;override;
  351. function gettypename:string;override;
  352. procedure setsize;
  353. { debug }
  354. {$ifdef GDB}
  355. function stabstring : pchar;override;
  356. {$endif GDB}
  357. { rtti }
  358. procedure write_rtti_data(rt:trttitype);override;
  359. end;
  360. tfloatdef = class(tstoreddef)
  361. typ : tfloattype;
  362. constructor create(t : tfloattype);
  363. constructor ppuload(ppufile:tcompilerppufile);
  364. function getcopy : tstoreddef;override;
  365. procedure ppuwrite(ppufile:tcompilerppufile);override;
  366. function gettypename:string;override;
  367. function is_publishable : boolean;override;
  368. procedure setsize;
  369. { debug }
  370. {$ifdef GDB}
  371. function stabstring : pchar;override;
  372. {$endif GDB}
  373. { rtti }
  374. procedure write_rtti_data(rt:trttitype);override;
  375. end;
  376. tabstractprocdef = class(tstoreddef)
  377. { saves a definition to the return type }
  378. rettype : ttype;
  379. parast : tsymtable;
  380. para : tlinkedlist;
  381. proctypeoption : tproctypeoption;
  382. proccalloption : tproccalloption;
  383. procoptions : tprocoptions;
  384. maxparacount,
  385. minparacount : byte;
  386. fpu_used : byte; { how many stack fpu must be empty }
  387. constructor create(level:byte);
  388. constructor ppuload(ppufile:tcompilerppufile);
  389. destructor destroy;override;
  390. procedure ppuwrite(ppufile:tcompilerppufile);override;
  391. procedure deref;override;
  392. procedure releasemem;
  393. function concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  394. function insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  395. procedure removepara(currpara:tparaitem);
  396. function typename_paras(showhidden:boolean): string;
  397. procedure test_if_fpu_result;
  398. function is_methodpointer:boolean;virtual;
  399. function is_addressonly:boolean;virtual;
  400. { debug }
  401. {$ifdef GDB}
  402. function stabstring : pchar;override;
  403. procedure concatstabto(asmlist : taasmoutput);override;
  404. {$endif GDB}
  405. end;
  406. tprocvardef = class(tabstractprocdef)
  407. constructor create(level:byte);
  408. constructor ppuload(ppufile:tcompilerppufile);
  409. procedure ppuwrite(ppufile:tcompilerppufile);override;
  410. function getsymtable(t:tgetsymtable):tsymtable;override;
  411. function size : longint;override;
  412. function gettypename:string;override;
  413. function is_publishable : boolean;override;
  414. function is_methodpointer:boolean;override;
  415. function is_addressonly:boolean;override;
  416. { debug }
  417. {$ifdef GDB}
  418. function stabstring : pchar;override;
  419. procedure concatstabto(asmlist : taasmoutput); override;
  420. {$endif GDB}
  421. { rtti }
  422. procedure write_rtti_data(rt:trttitype);override;
  423. end;
  424. tmessageinf = record
  425. case integer of
  426. 0 : (str : pchar);
  427. 1 : (i : longint);
  428. end;
  429. tprocdef = class(tabstractprocdef)
  430. private
  431. _mangledname : pstring;
  432. {$ifdef GDB}
  433. isstabwritten : boolean;
  434. {$endif GDB}
  435. public
  436. extnumber : word;
  437. overloadnumber : word;
  438. messageinf : tmessageinf;
  439. {$ifndef EXTDEBUG}
  440. { where is this function defined and what were the symbol
  441. flags, needed here because there
  442. is only one symbol for all overloaded functions
  443. EXTDEBUG has fileinfo in tdef (PFV) }
  444. fileinfo : tfileposinfo;
  445. {$endif}
  446. symoptions : tsymoptions;
  447. { symbol owning this definition }
  448. procsym : tsym;
  449. { alias names }
  450. aliasnames : tstringlist;
  451. { symtables }
  452. localst : tsymtable;
  453. funcretsym : tsym;
  454. { browser info }
  455. lastref,
  456. defref,
  457. lastwritten : tref;
  458. refcount : longint;
  459. _class : tobjectdef;
  460. { it's a tree, but this not easy to handle }
  461. { used for inlined procs }
  462. code : tnode;
  463. { info about register variables (JM) }
  464. regvarinfo: pointer;
  465. { name of the result variable to insert in the localsymtable }
  466. resultname : stringid;
  467. { true, if the procedure is only declared }
  468. { (forward procedure) }
  469. forwarddef,
  470. { true if the procedure is declared in the interface }
  471. interfacedef : boolean;
  472. { true if the procedure has a forward declaration }
  473. hasforward : boolean;
  474. { check the problems of manglednames }
  475. has_mangledname : boolean;
  476. { small set which contains the modified registers }
  477. usedintregisters:Tsupregset;
  478. usedotherregisters:Tregisterset;
  479. constructor create(level:byte);
  480. constructor ppuload(ppufile:tcompilerppufile);
  481. destructor destroy;override;
  482. procedure ppuwrite(ppufile:tcompilerppufile);override;
  483. procedure deref;override;
  484. procedure derefimpl;override;
  485. function getsymtable(t:tgetsymtable):tsymtable;override;
  486. function gettypename : string;override;
  487. function mangledname : string;
  488. procedure setmangledname(const s : string);
  489. procedure load_references(ppufile:tcompilerppufile;locals:boolean);
  490. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  491. { inserts the local symbol table, if this is not
  492. no local symbol table is built. Should be called only
  493. when we are sure that a local symbol table will be required.
  494. }
  495. procedure insert_localst;
  496. function fullprocname(showhidden:boolean):string;
  497. function cplusplusmangledname : string;
  498. function is_methodpointer:boolean;override;
  499. function is_addressonly:boolean;override;
  500. function is_visible_for_proc(currprocdef:tprocdef):boolean;
  501. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  502. { debug }
  503. {$ifdef GDB}
  504. function stabstring : pchar;override;
  505. procedure concatstabto(asmlist : taasmoutput);override;
  506. {$endif GDB}
  507. end;
  508. { single linked list of overloaded procs }
  509. pprocdeflist = ^tprocdeflist;
  510. tprocdeflist = record
  511. def : tprocdef;
  512. next : pprocdeflist;
  513. end;
  514. tstringdef = class(tstoreddef)
  515. string_typ : tstringtype;
  516. len : longint;
  517. constructor createshort(l : byte);
  518. constructor loadshort(ppufile:tcompilerppufile);
  519. constructor createlong(l : longint);
  520. constructor loadlong(ppufile:tcompilerppufile);
  521. constructor createansi(l : longint);
  522. constructor loadansi(ppufile:tcompilerppufile);
  523. constructor createwide(l : longint);
  524. constructor loadwide(ppufile:tcompilerppufile);
  525. function getcopy : tstoreddef;override;
  526. function stringtypname:string;
  527. function size : longint;override;
  528. procedure ppuwrite(ppufile:tcompilerppufile);override;
  529. function gettypename:string;override;
  530. function getmangledparaname:string;override;
  531. function is_publishable : boolean;override;
  532. { debug }
  533. {$ifdef GDB}
  534. function stabstring : pchar;override;
  535. procedure concatstabto(asmlist : taasmoutput);override;
  536. {$endif GDB}
  537. { init/final }
  538. function needs_inittable : boolean;override;
  539. { rtti }
  540. procedure write_rtti_data(rt:trttitype);override;
  541. end;
  542. tenumdef = class(tstoreddef)
  543. minval,
  544. maxval : longint;
  545. has_jumps : boolean;
  546. firstenum : tsym; {tenumsym}
  547. basedef : tenumdef;
  548. constructor create;
  549. constructor create_subrange(_basedef:tenumdef;_min,_max:longint);
  550. constructor ppuload(ppufile:tcompilerppufile);
  551. destructor destroy;override;
  552. procedure ppuwrite(ppufile:tcompilerppufile);override;
  553. procedure deref;override;
  554. function gettypename:string;override;
  555. function is_publishable : boolean;override;
  556. procedure calcsavesize;
  557. procedure setmax(_max:longint);
  558. procedure setmin(_min:longint);
  559. function min:longint;
  560. function max:longint;
  561. { debug }
  562. {$ifdef GDB}
  563. function stabstring : pchar;override;
  564. {$endif GDB}
  565. { rtti }
  566. procedure write_rtti_data(rt:trttitype);override;
  567. procedure write_child_rtti_data(rt:trttitype);override;
  568. private
  569. procedure correct_owner_symtable;
  570. end;
  571. tsetdef = class(tstoreddef)
  572. elementtype : ttype;
  573. settype : tsettype;
  574. constructor create(const t:ttype;high : longint);
  575. constructor ppuload(ppufile:tcompilerppufile);
  576. destructor destroy;override;
  577. procedure ppuwrite(ppufile:tcompilerppufile);override;
  578. procedure deref;override;
  579. function gettypename:string;override;
  580. function is_publishable : boolean;override;
  581. procedure changesettype(s:tsettype);
  582. { debug }
  583. {$ifdef GDB}
  584. function stabstring : pchar;override;
  585. procedure concatstabto(asmlist : taasmoutput);override;
  586. {$endif GDB}
  587. { rtti }
  588. procedure write_rtti_data(rt:trttitype);override;
  589. procedure write_child_rtti_data(rt:trttitype);override;
  590. end;
  591. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  592. var
  593. aktobjectdef : tobjectdef; { used for private functions check !! }
  594. firstglobaldef, { linked list of all globals defs }
  595. lastglobaldef : tstoreddef; { used to reset stabs/ranges }
  596. {$ifdef GDB}
  597. { for STAB debugging }
  598. globaltypecount : word;
  599. pglobaltypecount : pword;
  600. {$endif GDB}
  601. { default types }
  602. generrortype, { error in definition }
  603. voidpointertype, { pointer for Void-Pointerdef }
  604. charpointertype, { pointer for Char-Pointerdef }
  605. voidfarpointertype,
  606. cformaltype, { unique formal definition }
  607. voidtype, { Pointer to Void (procedure) }
  608. cchartype, { Pointer to Char }
  609. cwidechartype, { Pointer to WideChar }
  610. booltype, { pointer to boolean type }
  611. u8bittype, { Pointer to 8-Bit unsigned }
  612. u16bittype, { Pointer to 16-Bit unsigned }
  613. u32bittype, { Pointer to 32-Bit unsigned }
  614. s32bittype, { Pointer to 32-Bit signed }
  615. cu64bittype, { pointer to 64 bit unsigned def }
  616. cs64bittype, { pointer to 64 bit signed def, }
  617. s32floattype, { pointer for realconstn }
  618. s64floattype, { pointer for realconstn }
  619. s80floattype, { pointer to type of temp. floats }
  620. s64currencytype, { pointer to a currency type }
  621. s32fixedtype, { pointer to type of temp. fixed }
  622. cshortstringtype, { pointer to type of short string const }
  623. clongstringtype, { pointer to type of long string const }
  624. cansistringtype, { pointer to type of ansi string const }
  625. cwidestringtype, { pointer to type of wide string const }
  626. openshortstringtype, { pointer to type of an open shortstring,
  627. needed for readln() }
  628. openchararraytype, { pointer to type of an open array of char,
  629. needed for readln() }
  630. cfiletype, { get the same definition for all file }
  631. { used for stabs }
  632. methodpointertype, { typecasting of methodpointers to extract self }
  633. { we use only one variant def }
  634. cvarianttype,
  635. { unsigned ord type with the same size as a pointer }
  636. ordpointertype,
  637. defaultordconsttype, { pointer to type of ordinal constants }
  638. pvmttype : ttype; { type of classrefs, used for stabs }
  639. { pointer to the anchestor of all classes }
  640. class_tobject : tobjectdef;
  641. { pointer to the ancestor of all COM interfaces }
  642. interface_iunknown : tobjectdef;
  643. { pointer to the TGUID type
  644. of all interfaces }
  645. rec_tguid : trecorddef;
  646. { Pointer to a procdef with no parameters and no return value.
  647. This is used for procedures which are generated automatically
  648. by the compiler.
  649. }
  650. voidprocdef : tprocdef;
  651. const
  652. {$ifdef i386}
  653. pbestrealtype : ^ttype = @s80floattype;
  654. {$endif}
  655. {$ifdef x86_64}
  656. pbestrealtype : ^ttype = @s80floattype;
  657. {$endif}
  658. {$ifdef m68k}
  659. pbestrealtype : ^ttype = @s64floattype;
  660. {$endif}
  661. {$ifdef alpha}
  662. pbestrealtype : ^ttype = @s64floattype;
  663. {$endif}
  664. {$ifdef powerpc}
  665. pbestrealtype : ^ttype = @s64floattype;
  666. {$endif}
  667. {$ifdef ia64}
  668. pbestrealtype : ^ttype = @s64floattype;
  669. {$endif}
  670. {$ifdef SPARC}
  671. pbestrealtype : ^ttype = @s64floattype;
  672. {$endif SPARC}
  673. {$ifdef vis}
  674. pbestrealtype : ^ttype = @s64floattype;
  675. {$endif vis}
  676. function mangledname_prefix(typeprefix:string;st:tsymtable):string;
  677. {$ifdef GDB}
  678. { GDB Helpers }
  679. function typeglobalnumber(const s : string) : string;
  680. {$endif GDB}
  681. { should be in the types unit, but the types unit uses the node stuff :( }
  682. function is_interfacecom(def: tdef): boolean;
  683. function is_interfacecorba(def: tdef): boolean;
  684. function is_interface(def: tdef): boolean;
  685. function is_object(def: tdef): boolean;
  686. function is_class(def: tdef): boolean;
  687. function is_cppclass(def: tdef): boolean;
  688. function is_class_or_interface(def: tdef): boolean;
  689. procedure reset_global_defs;
  690. implementation
  691. uses
  692. {$ifdef Delphi}
  693. sysutils,
  694. {$else Delphi}
  695. strings,
  696. {$endif Delphi}
  697. { global }
  698. verbose,
  699. { target }
  700. systems,aasmcpu,paramgr,
  701. { symtable }
  702. symsym,symtable,symutil,defutil,
  703. { module }
  704. {$ifdef GDB}
  705. gdb,
  706. {$endif GDB}
  707. fmodule,
  708. { other }
  709. gendef
  710. ;
  711. {****************************************************************************
  712. Helpers
  713. ****************************************************************************}
  714. function mangledname_prefix(typeprefix:string;st:tsymtable):string;
  715. var
  716. s,
  717. prefix : string;
  718. begin
  719. prefix:='';
  720. if not assigned(st) then
  721. internalerror(200204212);
  722. { sub procedures }
  723. while (st.symtabletype=localsymtable) do
  724. begin
  725. if st.defowner.deftype<>procdef then
  726. internalerror(200204173);
  727. s:=tprocdef(st.defowner).procsym.name;
  728. if tprocdef(st.defowner).overloadnumber>0 then
  729. s:=s+'$'+tostr(tprocdef(st.defowner).overloadnumber);
  730. prefix:=s+'$'+prefix;
  731. st:=st.defowner.owner;
  732. end;
  733. { object/classes symtable }
  734. if (st.symtabletype=objectsymtable) then
  735. begin
  736. if st.defowner.deftype<>objectdef then
  737. internalerror(200204174);
  738. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  739. st:=st.defowner.owner;
  740. end;
  741. { symtable must now be static or global }
  742. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  743. internalerror(200204175);
  744. mangledname_prefix:=typeprefix+'_'+st.name^+'_'+prefix;
  745. end;
  746. {$ifdef GDB}
  747. procedure forcestabto(asmlist : taasmoutput; pd : tdef);
  748. begin
  749. if tstoreddef(pd).is_def_stab_written = not_written then
  750. begin
  751. if assigned(pd.typesym) then
  752. ttypesym(pd.typesym).isusedinstab := true;
  753. tstoreddef(pd).concatstabto(asmlist);
  754. end;
  755. end;
  756. {$endif GDB}
  757. {****************************************************************************
  758. TDEF (base class for definitions)
  759. ****************************************************************************}
  760. constructor tstoreddef.create;
  761. begin
  762. inherited create;
  763. savesize := 0;
  764. {$ifdef EXTDEBUG}
  765. fileinfo := aktfilepos;
  766. {$endif}
  767. if registerdef then
  768. symtablestack.registerdef(self);
  769. {$ifdef GDB}
  770. is_def_stab_written := not_written;
  771. globalnb := 0;
  772. {$endif GDB}
  773. if assigned(lastglobaldef) then
  774. begin
  775. lastglobaldef.nextglobal := self;
  776. previousglobal:=lastglobaldef;
  777. end
  778. else
  779. begin
  780. firstglobaldef := self;
  781. previousglobal := nil;
  782. end;
  783. lastglobaldef := self;
  784. nextglobal := nil;
  785. fillchar(localrttilab,sizeof(localrttilab),0);
  786. end;
  787. constructor tstoreddef.ppuloaddef(ppufile:tcompilerppufile);
  788. begin
  789. inherited create;
  790. {$ifdef EXTDEBUG}
  791. fillchar(fileinfo,sizeof(fileinfo),0);
  792. {$endif}
  793. {$ifdef GDB}
  794. is_def_stab_written := not_written;
  795. globalnb := 0;
  796. {$endif GDB}
  797. if assigned(lastglobaldef) then
  798. begin
  799. lastglobaldef.nextglobal := self;
  800. previousglobal:=lastglobaldef;
  801. end
  802. else
  803. begin
  804. firstglobaldef := self;
  805. previousglobal:=nil;
  806. end;
  807. lastglobaldef := self;
  808. nextglobal := nil;
  809. fillchar(localrttilab,sizeof(localrttilab),0);
  810. { load }
  811. indexnr:=ppufile.getword;
  812. typesym:=ttypesym(pointer(ppufile.getderef));
  813. ppufile.getsmallset(defoptions);
  814. if df_has_rttitable in defoptions then
  815. rttitablesym:=tsym(ppufile.getderef);
  816. if df_has_inittable in defoptions then
  817. inittablesym:=tsym(ppufile.getderef);
  818. end;
  819. destructor tstoreddef.destroy;
  820. begin
  821. { first element ? }
  822. if not(assigned(previousglobal)) then
  823. begin
  824. firstglobaldef := nextglobal;
  825. if assigned(firstglobaldef) then
  826. firstglobaldef.previousglobal:=nil;
  827. end
  828. else
  829. begin
  830. { remove reference in the element before }
  831. previousglobal.nextglobal:=nextglobal;
  832. end;
  833. { last element ? }
  834. if not(assigned(nextglobal)) then
  835. begin
  836. lastglobaldef := previousglobal;
  837. if assigned(lastglobaldef) then
  838. lastglobaldef.nextglobal:=nil;
  839. end
  840. else
  841. nextglobal.previousglobal:=previousglobal;
  842. previousglobal:=nil;
  843. nextglobal:=nil;
  844. end;
  845. function tstoreddef.getcopy : tstoreddef;
  846. begin
  847. Message(sym_e_cant_create_unique_type);
  848. getcopy:=nil;
  849. end;
  850. procedure tstoreddef.ppuwritedef(ppufile:tcompilerppufile);
  851. begin
  852. ppufile.putword(indexnr);
  853. ppufile.putderef(typesym);
  854. ppufile.putsmallset(defoptions);
  855. if df_has_rttitable in defoptions then
  856. ppufile.putderef(rttitablesym);
  857. if df_has_inittable in defoptions then
  858. ppufile.putderef(inittablesym);
  859. {$ifdef GDB}
  860. if globalnb = 0 then
  861. begin
  862. if assigned(owner) then
  863. globalnb := owner.getnewtypecount
  864. else
  865. begin
  866. globalnb := PGlobalTypeCount^;
  867. Inc(PGlobalTypeCount^);
  868. end;
  869. end;
  870. {$endif GDB}
  871. end;
  872. procedure tstoreddef.deref;
  873. begin
  874. resolvesym(pointer(typesym));
  875. resolvesym(pointer(rttitablesym));
  876. resolvesym(pointer(inittablesym));
  877. end;
  878. procedure tstoreddef.derefimpl;
  879. begin
  880. end;
  881. function tstoreddef.size : longint;
  882. begin
  883. size:=savesize;
  884. end;
  885. function tstoreddef.alignment : longint;
  886. begin
  887. { normal alignment by default }
  888. alignment:=0;
  889. end;
  890. {$ifdef GDB}
  891. procedure tstoreddef.set_globalnb;
  892. begin
  893. globalnb :=PGlobalTypeCount^;
  894. inc(PglobalTypeCount^);
  895. end;
  896. function tstoreddef.stabstring : pchar;
  897. begin
  898. stabstring := strpnew('t'+numberstring+';');
  899. end;
  900. function tstoreddef.numberstring : string;
  901. var table : tsymtable;
  902. begin
  903. {formal def have no type !}
  904. if deftype = formaldef then
  905. begin
  906. numberstring := tstoreddef(voidtype.def).numberstring;
  907. exit;
  908. end;
  909. if (not assigned(typesym)) or (not ttypesym(typesym).isusedinstab) then
  910. begin
  911. {set even if debuglist is not defined}
  912. if assigned(typesym) then
  913. ttypesym(typesym).isusedinstab := true;
  914. if assigned(debuglist) and (is_def_stab_written = not_written) then
  915. concatstabto(debuglist);
  916. end;
  917. if not (cs_gdb_dbx in aktglobalswitches) then
  918. begin
  919. if globalnb = 0 then
  920. set_globalnb;
  921. numberstring := tostr(globalnb);
  922. end
  923. else
  924. begin
  925. if globalnb = 0 then
  926. begin
  927. if assigned(owner) then
  928. globalnb := owner.getnewtypecount
  929. else
  930. begin
  931. globalnb := PGlobalTypeCount^;
  932. Inc(PGlobalTypeCount^);
  933. end;
  934. end;
  935. if assigned(typesym) then
  936. begin
  937. table := ttypesym(typesym).owner;
  938. if table.unitid > 0 then
  939. numberstring := '('+tostr(table.unitid)+','+tostr(tstoreddef(ttypesym(typesym).restype.def).globalnb)+')'
  940. else
  941. numberstring := tostr(globalnb);
  942. exit;
  943. end;
  944. numberstring := tostr(globalnb);
  945. end;
  946. end;
  947. function tstoreddef.allstabstring : pchar;
  948. var stabchar : string[2];
  949. ss,st : pchar;
  950. sname : string;
  951. sym_line_no : longint;
  952. begin
  953. ss := stabstring;
  954. getmem(st,strlen(ss)+512);
  955. stabchar := 't';
  956. if deftype in tagtypes then
  957. stabchar := 'Tt';
  958. if assigned(typesym) then
  959. begin
  960. sname := ttypesym(typesym).name;
  961. sym_line_no:=ttypesym(typesym).fileinfo.line;
  962. end
  963. else
  964. begin
  965. sname := ' ';
  966. sym_line_no:=0;
  967. end;
  968. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  969. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  970. allstabstring := strnew(st);
  971. freemem(st,strlen(ss)+512);
  972. strdispose(ss);
  973. end;
  974. procedure tstoreddef.concatstabto(asmlist : taasmoutput);
  975. var stab_str : pchar;
  976. begin
  977. if ((typesym = nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  978. and (is_def_stab_written = not_written) then
  979. begin
  980. If cs_gdb_dbx in aktglobalswitches then
  981. begin
  982. { otherwise you get two of each def }
  983. If assigned(typesym) then
  984. begin
  985. if ttypesym(typesym).typ=symconst.typesym then
  986. ttypesym(typesym).isusedinstab:=true;
  987. if (ttypesym(typesym).owner = nil) or
  988. ((ttypesym(typesym).owner.symtabletype = globalsymtable) and
  989. tglobalsymtable(ttypesym(typesym).owner).dbx_count_ok) then
  990. begin
  991. {with DBX we get the definition from the other objects }
  992. is_def_stab_written := written;
  993. exit;
  994. end;
  995. end;
  996. end;
  997. { to avoid infinite loops }
  998. is_def_stab_written := being_written;
  999. stab_str := allstabstring;
  1000. asmList.concat(Tai_stabs.Create(stab_str));
  1001. is_def_stab_written := written;
  1002. end;
  1003. end;
  1004. {$endif GDB}
  1005. procedure tstoreddef.write_rtti_name;
  1006. var
  1007. str : string;
  1008. begin
  1009. { name }
  1010. if assigned(typesym) then
  1011. begin
  1012. str:=ttypesym(typesym).realname;
  1013. rttiList.concat(Tai_string.Create(chr(length(str))+str));
  1014. end
  1015. else
  1016. rttiList.concat(Tai_string.Create(#0))
  1017. end;
  1018. procedure tstoreddef.write_rtti_data(rt:trttitype);
  1019. begin
  1020. rttilist.concat(tai_const.create_8bit(tkUnknown));
  1021. write_rtti_name;
  1022. end;
  1023. procedure tstoreddef.write_child_rtti_data(rt:trttitype);
  1024. begin
  1025. end;
  1026. function tstoreddef.get_rtti_label(rt:trttitype) : tasmsymbol;
  1027. begin
  1028. { try to reuse persistent rtti data }
  1029. if (rt=fullrtti) and (df_has_rttitable in defoptions) then
  1030. get_rtti_label:=trttisym(rttitablesym).get_label
  1031. else
  1032. if (rt=initrtti) and (df_has_inittable in defoptions) then
  1033. get_rtti_label:=trttisym(inittablesym).get_label
  1034. else
  1035. begin
  1036. if not assigned(localrttilab[rt]) then
  1037. begin
  1038. objectlibrary.getdatalabel(localrttilab[rt]);
  1039. write_child_rtti_data(rt);
  1040. if (cs_create_smart in aktmoduleswitches) then
  1041. rttiList.concat(Tai_cut.Create);
  1042. rttiList.concat(Tai_align.create(const_align(pointer_size)));
  1043. if (cs_create_smart in aktmoduleswitches) then
  1044. rttiList.concat(Tai_symbol.Create_global(localrttilab[rt],0))
  1045. else
  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. minparacount:=0;
  2663. maxparacount:=0;
  2664. proctypeoption:=potype_none;
  2665. proccalloption:=pocall_none;
  2666. procoptions:=[];
  2667. rettype:=voidtype;
  2668. fpu_used:=0;
  2669. savesize:=POINTER_SIZE;
  2670. end;
  2671. destructor tabstractprocdef.destroy;
  2672. begin
  2673. if assigned(para) then
  2674. para.free;
  2675. if assigned(parast) then
  2676. begin
  2677. {$ifdef MEMDEBUG}
  2678. memprocparast.start;
  2679. {$endif MEMDEBUG}
  2680. parast.free;
  2681. {$ifdef MEMDEBUG}
  2682. memprocparast.stop;
  2683. {$endif MEMDEBUG}
  2684. end;
  2685. inherited destroy;
  2686. end;
  2687. procedure tabstractprocdef.releasemem;
  2688. begin
  2689. para.free;
  2690. para:=nil;
  2691. parast.free;
  2692. parast:=nil;
  2693. end;
  2694. function tabstractprocdef.concatpara(afterpara:tparaitem;const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2695. var
  2696. hp : TParaItem;
  2697. begin
  2698. hp:=TParaItem.Create;
  2699. hp.paratyp:=tvarsym(sym).varspez;
  2700. hp.parasym:=sym;
  2701. hp.paratype:=tt;
  2702. hp.is_hidden:=vhidden;
  2703. hp.defaultvalue:=defval;
  2704. { Parameters are stored from left to right }
  2705. if assigned(afterpara) then
  2706. Para.insertafter(hp,afterpara)
  2707. else
  2708. Para.concat(hp);
  2709. { Don't count hidden parameters }
  2710. if not vhidden then
  2711. begin
  2712. if not assigned(defval) then
  2713. inc(minparacount);
  2714. inc(maxparacount);
  2715. end;
  2716. concatpara:=hp;
  2717. end;
  2718. function tabstractprocdef.insertpara(const tt:ttype;sym : tsym;defval:tsym;vhidden:boolean):tparaitem;
  2719. var
  2720. hp : TParaItem;
  2721. begin
  2722. hp:=TParaItem.Create;
  2723. hp.paratyp:=tvarsym(sym).varspez;
  2724. hp.parasym:=sym;
  2725. hp.paratype:=tt;
  2726. hp.is_hidden:=vhidden;
  2727. hp.defaultvalue:=defval;
  2728. { Parameters are stored from left to right }
  2729. Para.insert(hp);
  2730. { Don't count hidden parameters }
  2731. if (not vhidden) then
  2732. begin
  2733. if not assigned(defval) then
  2734. inc(minparacount);
  2735. inc(maxparacount);
  2736. end;
  2737. insertpara:=hp;
  2738. end;
  2739. procedure tabstractprocdef.removepara(currpara:tparaitem);
  2740. begin
  2741. { Don't count hidden parameters }
  2742. if (not currpara.is_hidden) then
  2743. begin
  2744. if not assigned(currpara.defaultvalue) then
  2745. dec(minparacount);
  2746. dec(maxparacount);
  2747. end;
  2748. Para.Remove(currpara);
  2749. currpara.free;
  2750. end;
  2751. { all functions returning in FPU are
  2752. assume to use 2 FPU registers
  2753. until the function implementation
  2754. is processed PM }
  2755. procedure tabstractprocdef.test_if_fpu_result;
  2756. begin
  2757. if assigned(rettype.def) and
  2758. (rettype.def.deftype=floatdef) then
  2759. fpu_used:=maxfpuregs;
  2760. end;
  2761. procedure tabstractprocdef.deref;
  2762. var
  2763. hp : TParaItem;
  2764. oldlocalsymtable : tsymtable;
  2765. begin
  2766. inherited deref;
  2767. rettype.resolve;
  2768. { parast }
  2769. oldlocalsymtable:=aktlocalsymtable;
  2770. aktlocalsymtable:=parast;
  2771. tparasymtable(parast).deref;
  2772. aktlocalsymtable:=oldlocalsymtable;
  2773. { paraitems }
  2774. hp:=TParaItem(Para.first);
  2775. while assigned(hp) do
  2776. begin
  2777. hp.paratype.resolve;
  2778. resolvesym(pointer(hp.defaultvalue));
  2779. resolvesym(pointer(hp.parasym));
  2780. hp:=TParaItem(hp.next);
  2781. end;
  2782. end;
  2783. constructor tabstractprocdef.ppuload(ppufile:tcompilerppufile);
  2784. var
  2785. hp : TParaItem;
  2786. count,i : word;
  2787. paraloclen : byte;
  2788. begin
  2789. inherited ppuloaddef(ppufile);
  2790. parast:=nil;
  2791. Para:=TLinkedList.Create;
  2792. minparacount:=0;
  2793. maxparacount:=0;
  2794. ppufile.gettype(rettype);
  2795. fpu_used:=ppufile.getbyte;
  2796. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2797. proccalloption:=tproccalloption(ppufile.getbyte);
  2798. ppufile.getsmallset(procoptions);
  2799. { get the number of parameters }
  2800. count:=ppufile.getbyte;
  2801. savesize:=POINTER_SIZE;
  2802. for i:=1 to count do
  2803. begin
  2804. hp:=TParaItem.Create;
  2805. hp.paratyp:=tvarspez(ppufile.getbyte);
  2806. ppufile.gettype(hp.paratype);
  2807. hp.defaultvalue:=tsym(ppufile.getderef);
  2808. hp.parasym:=tsym(ppufile.getderef);
  2809. hp.is_hidden:=boolean(ppufile.getbyte);
  2810. { later, we'll gerate this on the fly (FK) }
  2811. paraloclen:=ppufile.getbyte;
  2812. if paraloclen<>sizeof(tparalocation) then
  2813. internalerror(200304261);
  2814. ppufile.getdata(hp.paraloc,sizeof(tparalocation));
  2815. { Don't count hidden parameters }
  2816. if (not hp.is_hidden) then
  2817. begin
  2818. if not assigned(hp.defaultvalue) then
  2819. inc(minparacount);
  2820. inc(maxparacount);
  2821. end;
  2822. { Parameters are stored left to right in both ppu and memory }
  2823. Para.concat(hp);
  2824. end;
  2825. end;
  2826. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2827. var
  2828. hp : TParaItem;
  2829. oldintfcrc : boolean;
  2830. begin
  2831. inherited ppuwritedef(ppufile);
  2832. ppufile.puttype(rettype);
  2833. oldintfcrc:=ppufile.do_interface_crc;
  2834. ppufile.do_interface_crc:=false;
  2835. if simplify_ppu then
  2836. fpu_used:=0;
  2837. ppufile.putbyte(fpu_used);
  2838. ppufile.putbyte(ord(proctypeoption));
  2839. ppufile.putbyte(ord(proccalloption));
  2840. ppufile.putsmallset(procoptions);
  2841. ppufile.do_interface_crc:=oldintfcrc;
  2842. { we need to store the count including vs_hidden }
  2843. ppufile.putbyte(para.count);
  2844. hp:=TParaItem(Para.first);
  2845. while assigned(hp) do
  2846. begin
  2847. ppufile.putbyte(byte(hp.paratyp));
  2848. ppufile.puttype(hp.paratype);
  2849. ppufile.putderef(hp.defaultvalue);
  2850. ppufile.putderef(hp.parasym);
  2851. ppufile.putbyte(byte(hp.is_hidden));
  2852. { write the length of tparalocation so ppudump can
  2853. parse the .ppu without knowing the tparalocation size }
  2854. ppufile.putbyte(sizeof(tparalocation));
  2855. ppufile.putdata(hp.paraloc,sizeof(tparalocation));
  2856. hp:=TParaItem(hp.next);
  2857. end;
  2858. end;
  2859. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2860. var
  2861. hs,s : string;
  2862. hp : TParaItem;
  2863. hpc : tconstsym;
  2864. first : boolean;
  2865. begin
  2866. hp:=TParaItem(Para.first);
  2867. s:='';
  2868. first:=true;
  2869. while assigned(hp) do
  2870. begin
  2871. if (not hp.is_hidden) or
  2872. (showhidden) then
  2873. begin
  2874. if first then
  2875. begin
  2876. s:=s+'(';
  2877. first:=false;
  2878. end
  2879. else
  2880. s:=s+',';
  2881. case hp.paratyp of
  2882. vs_var :
  2883. s:=s+'var';
  2884. vs_const :
  2885. s:=s+'const';
  2886. vs_out :
  2887. s:=s+'out';
  2888. end;
  2889. if assigned(hp.paratype.def.typesym) then
  2890. begin
  2891. if s<>'(' then
  2892. s:=s+' ';
  2893. hs:=hp.paratype.def.typesym.realname;
  2894. if hs[1]<>'$' then
  2895. s:=s+hp.paratype.def.typesym.realname
  2896. else
  2897. s:=s+hp.paratype.def.gettypename;
  2898. end
  2899. else
  2900. s:=s+hp.paratype.def.gettypename;
  2901. { default value }
  2902. if assigned(hp.defaultvalue) then
  2903. begin
  2904. hpc:=tconstsym(hp.defaultvalue);
  2905. hs:='';
  2906. case hpc.consttyp of
  2907. conststring,
  2908. constresourcestring :
  2909. hs:=strpas(pchar(hpc.value.valueptr));
  2910. constreal :
  2911. str(pbestreal(hpc.value.valueptr)^,hs);
  2912. constord :
  2913. hs:=tostr(hpc.value.valueord);
  2914. constpointer :
  2915. hs:=tostr(hpc.value.valueordptr);
  2916. constbool :
  2917. begin
  2918. if hpc.value.valueord<>0 then
  2919. hs:='TRUE'
  2920. else
  2921. hs:='FALSE';
  2922. end;
  2923. constnil :
  2924. hs:='nil';
  2925. constchar :
  2926. hs:=chr(hpc.value.valueord);
  2927. constset :
  2928. hs:='<set>';
  2929. end;
  2930. if hs<>'' then
  2931. s:=s+'="'+hs+'"';
  2932. end;
  2933. end;
  2934. hp:=TParaItem(hp.next);
  2935. end;
  2936. if not first then
  2937. s:=s+')';
  2938. if (po_varargs in procoptions) then
  2939. s:=s+';VarArgs';
  2940. typename_paras:=s;
  2941. end;
  2942. function tabstractprocdef.is_methodpointer:boolean;
  2943. begin
  2944. result:=false;
  2945. end;
  2946. function tabstractprocdef.is_addressonly:boolean;
  2947. begin
  2948. result:=true;
  2949. end;
  2950. {$ifdef GDB}
  2951. function tabstractprocdef.stabstring : pchar;
  2952. begin
  2953. stabstring := strpnew('abstractproc'+numberstring+';');
  2954. end;
  2955. procedure tabstractprocdef.concatstabto(asmlist : taasmoutput);
  2956. begin
  2957. if (not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2958. and (is_def_stab_written = not_written) then
  2959. begin
  2960. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  2961. inherited concatstabto(asmlist);
  2962. end;
  2963. end;
  2964. {$endif GDB}
  2965. {***************************************************************************
  2966. TPROCDEF
  2967. ***************************************************************************}
  2968. constructor tprocdef.create(level:byte);
  2969. begin
  2970. inherited create(level);
  2971. deftype:=procdef;
  2972. has_mangledname:=false;
  2973. _mangledname:=nil;
  2974. fileinfo:=aktfilepos;
  2975. extnumber:=$ffff;
  2976. aliasnames:=tstringlist.create;
  2977. funcretsym:=nil;
  2978. localst := nil;
  2979. defref:=nil;
  2980. lastwritten:=nil;
  2981. refcount:=0;
  2982. if (cs_browser in aktmoduleswitches) and make_ref then
  2983. begin
  2984. defref:=tref.create(defref,@akttokenpos);
  2985. inc(refcount);
  2986. end;
  2987. lastref:=defref;
  2988. { first, we assume that all registers are used }
  2989. usedintregisters:=ALL_INTREGISTERS;
  2990. usedotherregisters:=ALL_REGISTERS;
  2991. forwarddef:=true;
  2992. interfacedef:=false;
  2993. hasforward:=false;
  2994. _class := nil;
  2995. code:=nil;
  2996. regvarinfo := nil;
  2997. overloadnumber:=0;
  2998. {$ifdef GDB}
  2999. isstabwritten := false;
  3000. {$endif GDB}
  3001. end;
  3002. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3003. begin
  3004. inherited ppuload(ppufile);
  3005. deftype:=procdef;
  3006. ppufile.getnormalset(usedintregisters);
  3007. ppufile.getnormalset(usedotherregisters);
  3008. has_mangledname:=boolean(ppufile.getbyte);
  3009. if has_mangledname then
  3010. _mangledname:=stringdup(ppufile.getstring)
  3011. else
  3012. _mangledname:=nil;
  3013. overloadnumber:=ppufile.getword;
  3014. extnumber:=ppufile.getword;
  3015. _class := tobjectdef(ppufile.getderef);
  3016. procsym := tsym(ppufile.getderef);
  3017. ppufile.getposinfo(fileinfo);
  3018. ppufile.getsmallset(symoptions);
  3019. { inline stuff }
  3020. if proccalloption=pocall_inline then
  3021. begin
  3022. funcretsym:=tsym(ppufile.getderef);
  3023. code:=ppuloadnode(ppufile);
  3024. end
  3025. else
  3026. begin
  3027. code := nil;
  3028. funcretsym:=nil;
  3029. end;
  3030. { load para symtable }
  3031. parast:=tparasymtable.create(unknown_level);
  3032. tparasymtable(parast).ppuload(ppufile);
  3033. parast.defowner:=self;
  3034. { load local symtable }
  3035. if (proccalloption=pocall_inline) or
  3036. ((current_module.flags and uf_local_browser)<>0) then
  3037. begin
  3038. localst:=tlocalsymtable.create(unknown_level);
  3039. tlocalsymtable(localst).ppuload(ppufile);
  3040. localst.defowner:=self;
  3041. end
  3042. else
  3043. localst:=nil;
  3044. { default values for no persistent data }
  3045. if (cs_link_deffile in aktglobalswitches) and
  3046. (tf_need_export in target_info.flags) and
  3047. (po_exports in procoptions) then
  3048. deffile.AddExport(mangledname);
  3049. aliasnames:=tstringlist.create;
  3050. forwarddef:=false;
  3051. interfacedef:=false;
  3052. hasforward:=false;
  3053. regvarinfo := nil;
  3054. lastref:=nil;
  3055. lastwritten:=nil;
  3056. defref:=nil;
  3057. refcount:=0;
  3058. {$ifdef GDB}
  3059. isstabwritten := false;
  3060. {$endif GDB}
  3061. end;
  3062. destructor tprocdef.destroy;
  3063. begin
  3064. if assigned(defref) then
  3065. begin
  3066. defref.freechain;
  3067. defref.free;
  3068. end;
  3069. aliasnames.free;
  3070. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3071. begin
  3072. {$ifdef MEMDEBUG}
  3073. memproclocalst.start;
  3074. {$endif MEMDEBUG}
  3075. localst.free;
  3076. {$ifdef MEMDEBUG}
  3077. memproclocalst.start;
  3078. {$endif MEMDEBUG}
  3079. end;
  3080. if (proccalloption=pocall_inline) and assigned(code) then
  3081. begin
  3082. {$ifdef MEMDEBUG}
  3083. memprocnodetree.start;
  3084. {$endif MEMDEBUG}
  3085. tnode(code).free;
  3086. {$ifdef MEMDEBUG}
  3087. memprocnodetree.start;
  3088. {$endif MEMDEBUG}
  3089. end;
  3090. if assigned(regvarinfo) then
  3091. dispose(pregvarinfo(regvarinfo));
  3092. if (po_msgstr in procoptions) then
  3093. strdispose(messageinf.str);
  3094. if assigned(_mangledname) then
  3095. begin
  3096. {$ifdef MEMDEBUG}
  3097. memmanglednames.start;
  3098. {$endif MEMDEBUG}
  3099. stringdispose(_mangledname);
  3100. {$ifdef MEMDEBUG}
  3101. memmanglednames.stop;
  3102. {$endif MEMDEBUG}
  3103. end;
  3104. inherited destroy;
  3105. end;
  3106. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3107. var
  3108. oldintfcrc : boolean;
  3109. begin
  3110. inherited ppuwrite(ppufile);
  3111. oldintfcrc:=ppufile.do_interface_crc;
  3112. ppufile.do_interface_crc:=false;
  3113. { set all registers to used for simplified compilation PM }
  3114. if simplify_ppu then
  3115. begin
  3116. usedintregisters:=ALL_INTREGISTERS;
  3117. usedotherregisters:=ALL_REGISTERS;
  3118. end;
  3119. ppufile.putnormalset(usedintregisters);
  3120. ppufile.putnormalset(usedotherregisters);
  3121. ppufile.do_interface_crc:=oldintfcrc;
  3122. ppufile.putbyte(byte(has_mangledname));
  3123. if has_mangledname then
  3124. ppufile.putstring(mangledname);
  3125. ppufile.putword(overloadnumber);
  3126. ppufile.putword(extnumber);
  3127. ppufile.putderef(_class);
  3128. ppufile.putderef(procsym);
  3129. ppufile.putposinfo(fileinfo);
  3130. ppufile.putsmallset(symoptions);
  3131. { inline stuff references to localsymtable, no influence
  3132. on the crc }
  3133. oldintfcrc:=ppufile.do_crc;
  3134. ppufile.do_crc:=false;
  3135. { inline stuff }
  3136. if proccalloption=pocall_inline then
  3137. begin
  3138. ppufile.putderef(funcretsym);
  3139. ppuwritenode(ppufile,code);
  3140. end;
  3141. ppufile.do_crc:=oldintfcrc;
  3142. { write this entry }
  3143. ppufile.writeentry(ibprocdef);
  3144. { Save the para symtable, this is taken from the interface }
  3145. tparasymtable(parast).ppuwrite(ppufile);
  3146. { save localsymtable for inline procedures or when local
  3147. browser info is requested, this has no influence on the crc }
  3148. if (proccalloption=pocall_inline) or
  3149. ((current_module.flags and uf_local_browser)<>0) then
  3150. begin
  3151. oldintfcrc:=ppufile.do_crc;
  3152. ppufile.do_crc:=false;
  3153. if not assigned(localst) then
  3154. begin
  3155. localst:=tlocalsymtable.create(unknown_level);
  3156. localst.defowner:=self;
  3157. end;
  3158. tlocalsymtable(localst).ppuwrite(ppufile);
  3159. ppufile.do_crc:=oldintfcrc;
  3160. end;
  3161. end;
  3162. procedure tprocdef.insert_localst;
  3163. begin
  3164. localst:=tlocalsymtable.create(parast.symtablelevel);
  3165. localst.defowner:=self;
  3166. { this is used by insert
  3167. to check same names in parast and localst }
  3168. localst.next:=parast;
  3169. end;
  3170. function tprocdef.fullprocname(showhidden:boolean):string;
  3171. var
  3172. s : string;
  3173. begin
  3174. {$ifdef EXTDEBUG}
  3175. showhidden:=true;
  3176. {$endif EXTDEBUG}
  3177. s:='';
  3178. if assigned(_class) then
  3179. begin
  3180. if po_classmethod in procoptions then
  3181. s:=s+'class ';
  3182. s:=s+_class.objrealname^+'.';
  3183. end;
  3184. s:=s+procsym.realname+typename_paras(showhidden);
  3185. if assigned(rettype.def) and
  3186. not(is_void(rettype.def)) then
  3187. s:=s+':'+rettype.def.gettypename;
  3188. fullprocname:=s;
  3189. end;
  3190. function tprocdef.is_methodpointer:boolean;
  3191. begin
  3192. result:=assigned(_class);
  3193. end;
  3194. function tprocdef.is_addressonly:boolean;
  3195. begin
  3196. result:=assigned(owner) and
  3197. (owner.symtabletype<>objectsymtable);
  3198. end;
  3199. function tprocdef.is_visible_for_proc(currprocdef:tprocdef):boolean;
  3200. begin
  3201. is_visible_for_proc:=false;
  3202. { private symbols are allowed when we are in the same
  3203. module as they are defined }
  3204. if (sp_private in symoptions) and
  3205. assigned(owner.defowner) and
  3206. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3207. (owner.defowner.owner.unitid<>0) then
  3208. exit;
  3209. { protected symbols are vissible in the module that defines them and
  3210. also visible to related objects }
  3211. if (sp_protected in symoptions) and
  3212. (
  3213. (
  3214. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3215. (owner.defowner.owner.unitid<>0)
  3216. ) and
  3217. not(
  3218. assigned(currprocdef) and
  3219. assigned(currprocdef._class) and
  3220. currprocdef._class.is_related(tobjectdef(owner.defowner))
  3221. )
  3222. ) then
  3223. exit;
  3224. is_visible_for_proc:=true;
  3225. end;
  3226. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3227. begin
  3228. is_visible_for_object:=false;
  3229. { private symbols are allowed when we are in the same
  3230. module as they are defined }
  3231. if (sp_private in symoptions) and
  3232. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3233. (owner.defowner.owner.unitid<>0) then
  3234. exit;
  3235. { protected symbols are vissible in the module that defines them and
  3236. also visible to related objects }
  3237. if (sp_protected in symoptions) and
  3238. (
  3239. (
  3240. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3241. (owner.defowner.owner.unitid<>0)
  3242. ) and
  3243. not(
  3244. assigned(currobjdef) and
  3245. currobjdef.is_related(tobjectdef(owner.defowner))
  3246. )
  3247. ) then
  3248. exit;
  3249. is_visible_for_object:=true;
  3250. end;
  3251. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3252. begin
  3253. case t of
  3254. gs_local :
  3255. getsymtable:=localst;
  3256. gs_para :
  3257. getsymtable:=parast;
  3258. else
  3259. getsymtable:=nil;
  3260. end;
  3261. end;
  3262. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3263. var
  3264. pos : tfileposinfo;
  3265. move_last : boolean;
  3266. begin
  3267. move_last:=lastwritten=lastref;
  3268. while (not ppufile.endofentry) do
  3269. begin
  3270. ppufile.getposinfo(pos);
  3271. inc(refcount);
  3272. lastref:=tref.create(lastref,@pos);
  3273. lastref.is_written:=true;
  3274. if refcount=1 then
  3275. defref:=lastref;
  3276. end;
  3277. if move_last then
  3278. lastwritten:=lastref;
  3279. if ((current_module.flags and uf_local_browser)<>0) and
  3280. locals then
  3281. begin
  3282. tparasymtable(parast).load_references(ppufile,locals);
  3283. tlocalsymtable(localst).load_references(ppufile,locals);
  3284. end;
  3285. end;
  3286. Const
  3287. local_symtable_index : word = $8001;
  3288. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3289. var
  3290. ref : tref;
  3291. pdo : tobjectdef;
  3292. move_last : boolean;
  3293. begin
  3294. move_last:=lastwritten=lastref;
  3295. if move_last and
  3296. (((current_module.flags and uf_local_browser)=0) or
  3297. not locals) then
  3298. exit;
  3299. { write address of this symbol }
  3300. ppufile.putderef(self);
  3301. { write refs }
  3302. if assigned(lastwritten) then
  3303. ref:=lastwritten
  3304. else
  3305. ref:=defref;
  3306. while assigned(ref) do
  3307. begin
  3308. if ref.moduleindex=current_module.unit_index then
  3309. begin
  3310. ppufile.putposinfo(ref.posinfo);
  3311. ref.is_written:=true;
  3312. if move_last then
  3313. lastwritten:=ref;
  3314. end
  3315. else if not ref.is_written then
  3316. move_last:=false
  3317. else if move_last then
  3318. lastwritten:=ref;
  3319. ref:=ref.nextref;
  3320. end;
  3321. ppufile.writeentry(ibdefref);
  3322. write_references:=true;
  3323. if ((current_module.flags and uf_local_browser)<>0) and
  3324. locals then
  3325. begin
  3326. pdo:=_class;
  3327. if (owner.symtabletype<>localsymtable) then
  3328. while assigned(pdo) do
  3329. begin
  3330. if pdo.symtable<>aktrecordsymtable then
  3331. begin
  3332. pdo.symtable.unitid:=local_symtable_index;
  3333. inc(local_symtable_index);
  3334. end;
  3335. pdo:=pdo.childof;
  3336. end;
  3337. parast.unitid:=local_symtable_index;
  3338. inc(local_symtable_index);
  3339. localst.unitid:=local_symtable_index;
  3340. inc(local_symtable_index);
  3341. tstoredsymtable(parast).write_references(ppufile,locals);
  3342. tstoredsymtable(localst).write_references(ppufile,locals);
  3343. { decrement for }
  3344. local_symtable_index:=local_symtable_index-2;
  3345. pdo:=_class;
  3346. if (owner.symtabletype<>localsymtable) then
  3347. while assigned(pdo) do
  3348. begin
  3349. if pdo.symtable<>aktrecordsymtable then
  3350. dec(local_symtable_index);
  3351. pdo:=pdo.childof;
  3352. end;
  3353. end;
  3354. end;
  3355. {$ifdef GDB}
  3356. {$ifdef unused}
  3357. { procedure addparaname(p : tsym);
  3358. var vs : char;
  3359. begin
  3360. if tvarsym(p).varspez = vs_value then vs := '1'
  3361. else vs := '0';
  3362. strpcopy(strend(StabRecString),p^.name+':'+tstoreddef(tvarsym(p).vartype.def).numberstring+','+vs+';');
  3363. end; }
  3364. function tprocdef.stabstring : pchar;
  3365. var
  3366. i : longint;
  3367. stabrecstring : pchar;
  3368. begin
  3369. getmem(StabRecString,1024);
  3370. strpcopy(StabRecString,'f'+tstoreddef(rettype.def).numberstring);
  3371. i:=maxparacount;
  3372. if i>0 then
  3373. begin
  3374. strpcopy(strend(StabRecString),','+tostr(i)+';');
  3375. (* confuse gdb !! PM
  3376. if assigned(parast) then
  3377. parast.foreach({$ifdef FPCPROCVAR}@{$endif}addparaname)
  3378. else
  3379. begin
  3380. param := para1;
  3381. i := 0;
  3382. while assigned(param) do
  3383. begin
  3384. inc(i);
  3385. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3386. {Here we have lost the parameter names !!}
  3387. {using lower case parameters }
  3388. strpcopy(strend(stabrecstring),'p'+tostr(i)
  3389. +':'+param^.paratype.def.numberstring+','+vartyp+';');
  3390. param := param^.next;
  3391. end;
  3392. end; *)
  3393. {strpcopy(strend(StabRecString),';');}
  3394. end;
  3395. stabstring := strnew(stabrecstring);
  3396. freemem(stabrecstring,1024);
  3397. end;
  3398. {$endif unused}
  3399. function tprocdef.stabstring: pchar;
  3400. Var RType : Char;
  3401. Obj,Info : String;
  3402. stabsstr : string;
  3403. p : pchar;
  3404. begin
  3405. obj := procsym.name;
  3406. info := '';
  3407. if tprocsym(procsym).is_global then
  3408. RType := 'F'
  3409. else
  3410. RType := 'f';
  3411. if assigned(owner) then
  3412. begin
  3413. if (owner.symtabletype = objectsymtable) then
  3414. obj := owner.name^+'__'+procsym.name;
  3415. { this code was correct only as long as the local symboltable
  3416. of the parent had the same name as the function
  3417. but this is no true anymore !! PM
  3418. if (owner.symtabletype=localsymtable) and assigned(owner.name) then
  3419. info := ','+name+','+owner.name^; }
  3420. if (owner.symtabletype=localsymtable) and
  3421. assigned(owner.defowner) and
  3422. assigned(tprocdef(owner.defowner).procsym) then
  3423. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3424. end;
  3425. stabsstr:=mangledname;
  3426. getmem(p,length(stabsstr)+255);
  3427. strpcopy(p,'"'+obj+':'+RType
  3428. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3429. +',0,'+
  3430. tostr(fileinfo.line)
  3431. +',');
  3432. strpcopy(strend(p),stabsstr);
  3433. stabstring:=strnew(p);
  3434. freemem(p,length(stabsstr)+255);
  3435. end;
  3436. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3437. begin
  3438. if (proccalloption=pocall_internproc) then
  3439. exit;
  3440. if not isstabwritten then
  3441. asmList.concat(Tai_stabs.Create(stabstring));
  3442. isstabwritten := true;
  3443. if assigned(parast) then
  3444. tstoredsymtable(parast).concatstabto(asmlist);
  3445. { local type defs and vars should not be written
  3446. inside the main proc stab }
  3447. if assigned(localst) and
  3448. (localst.symtablelevel>main_program_level) then
  3449. tstoredsymtable(localst).concatstabto(asmlist);
  3450. is_def_stab_written := written;
  3451. end;
  3452. {$endif GDB}
  3453. procedure tprocdef.deref;
  3454. begin
  3455. inherited deref;
  3456. resolvedef(pointer(_class));
  3457. { procsym that originaly defined this definition, should be in the
  3458. same symtable }
  3459. resolvesym(pointer(procsym));
  3460. end;
  3461. procedure tprocdef.derefimpl;
  3462. var
  3463. oldlocalsymtable : tsymtable;
  3464. begin
  3465. { locals }
  3466. if assigned(localst) then
  3467. begin
  3468. { localst }
  3469. oldlocalsymtable:=aktlocalsymtable;
  3470. aktlocalsymtable:=localst;
  3471. { we can deref both interface and implementation parts }
  3472. tlocalsymtable(localst).deref;
  3473. tlocalsymtable(localst).derefimpl;
  3474. aktlocalsymtable:=oldlocalsymtable;
  3475. { funcretsym, this is always located in the localst }
  3476. resolvesym(pointer(funcretsym));
  3477. end
  3478. else
  3479. begin
  3480. { safety }
  3481. funcretsym:=nil;
  3482. end;
  3483. { inline tree }
  3484. if (proccalloption=pocall_inline) then
  3485. code.derefimpl;
  3486. end;
  3487. function tprocdef.gettypename : string;
  3488. begin
  3489. gettypename := FullProcName(false)+';'+ProcCallOptionStr[proccalloption];
  3490. end;
  3491. function tprocdef.mangledname : string;
  3492. var
  3493. s : string;
  3494. hp : TParaItem;
  3495. begin
  3496. if assigned(_mangledname) then
  3497. begin
  3498. mangledname:=_mangledname^;
  3499. exit;
  3500. end;
  3501. { we need to use the symtable where the procsym is inserted,
  3502. because that is visible to the world }
  3503. s:=mangledname_prefix('',procsym.owner)+procsym.name;
  3504. if overloadnumber>0 then
  3505. s:=s+'$'+tostr(overloadnumber);
  3506. { add parameter types }
  3507. hp:=TParaItem(Para.first);
  3508. while assigned(hp) do
  3509. begin
  3510. if not hp.is_hidden then
  3511. s:=s+'$'+hp.paratype.def.mangledparaname;
  3512. hp:=TParaItem(hp.next);
  3513. end;
  3514. _mangledname:=stringdup(s);
  3515. mangledname:=_mangledname^;
  3516. end;
  3517. function tprocdef.cplusplusmangledname : string;
  3518. function getcppparaname(p : tdef) : string;
  3519. const
  3520. ordtype2str : array[tbasetype] of string[2] = (
  3521. '',
  3522. 'Uc','Us','Ui','Us',
  3523. 'Sc','s','i','x',
  3524. 'b','b','b',
  3525. 'c','w','x');
  3526. var
  3527. s : string;
  3528. begin
  3529. case p.deftype of
  3530. orddef:
  3531. s:=ordtype2str[torddef(p).typ];
  3532. pointerdef:
  3533. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3534. else
  3535. internalerror(2103001);
  3536. end;
  3537. getcppparaname:=s;
  3538. end;
  3539. var
  3540. s,s2 : string;
  3541. param : TParaItem;
  3542. begin
  3543. s := procsym.realname;
  3544. if procsym.owner.symtabletype=objectsymtable then
  3545. begin
  3546. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3547. case proctypeoption of
  3548. potype_destructor:
  3549. s:='_$_'+tostr(length(s2))+s2;
  3550. potype_constructor:
  3551. s:='___'+tostr(length(s2))+s2;
  3552. else
  3553. s:='_'+s+'__'+tostr(length(s2))+s2;
  3554. end;
  3555. end
  3556. else s:=s+'__';
  3557. s:=s+'F';
  3558. { concat modifiers }
  3559. { !!!!! }
  3560. { now we handle the parameters }
  3561. param := TParaItem(Para.first);
  3562. if assigned(param) then
  3563. while assigned(param) do
  3564. begin
  3565. s2:=getcppparaname(param.paratype.def);
  3566. if param.paratyp in [vs_var,vs_out] then
  3567. s2:='R'+s2;
  3568. s:=s+s2;
  3569. param:=TParaItem(param.next);
  3570. end
  3571. else
  3572. s:=s+'v';
  3573. cplusplusmangledname:=s;
  3574. end;
  3575. procedure tprocdef.setmangledname(const s : string);
  3576. begin
  3577. stringdispose(_mangledname);
  3578. _mangledname:=stringdup(s);
  3579. has_mangledname:=true;
  3580. end;
  3581. {***************************************************************************
  3582. TPROCVARDEF
  3583. ***************************************************************************}
  3584. constructor tprocvardef.create(level:byte);
  3585. begin
  3586. inherited create(level);
  3587. deftype:=procvardef;
  3588. end;
  3589. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3590. begin
  3591. inherited ppuload(ppufile);
  3592. deftype:=procvardef;
  3593. { load para symtable }
  3594. parast:=tparasymtable.create(unknown_level);
  3595. tparasymtable(parast).ppuload(ppufile);
  3596. parast.defowner:=self;
  3597. end;
  3598. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3599. begin
  3600. { here we cannot get a real good value so just give something }
  3601. { plausible (PM) }
  3602. { a more secure way would be
  3603. to allways store in a temp }
  3604. if is_fpu(rettype.def) then
  3605. fpu_used:={2}maxfpuregs
  3606. else
  3607. fpu_used:=0;
  3608. inherited ppuwrite(ppufile);
  3609. { Write this entry }
  3610. ppufile.writeentry(ibprocvardef);
  3611. { Save the para symtable, this is taken from the interface }
  3612. tparasymtable(parast).ppuwrite(ppufile);
  3613. end;
  3614. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3615. begin
  3616. case t of
  3617. gs_para :
  3618. getsymtable:=parast;
  3619. else
  3620. getsymtable:=nil;
  3621. end;
  3622. end;
  3623. function tprocvardef.size : longint;
  3624. begin
  3625. if (po_methodpointer in procoptions) and
  3626. not(po_addressonly in procoptions) then
  3627. size:=2*POINTER_SIZE
  3628. else
  3629. size:=POINTER_SIZE;
  3630. end;
  3631. function tprocvardef.is_methodpointer:boolean;
  3632. begin
  3633. result:=(po_methodpointer in procoptions);
  3634. end;
  3635. function tprocvardef.is_addressonly:boolean;
  3636. begin
  3637. result:=not(po_methodpointer in procoptions) or
  3638. (po_addressonly in procoptions);
  3639. end;
  3640. {$ifdef GDB}
  3641. function tprocvardef.stabstring : pchar;
  3642. var
  3643. nss : pchar;
  3644. { i : longint; }
  3645. begin
  3646. { i := maxparacount; }
  3647. getmem(nss,1024);
  3648. { it is not a function but a function pointer !! (PM) }
  3649. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)}+';');
  3650. { this confuses gdb !!
  3651. we should use 'F' instead of 'f' but
  3652. as we use c++ language mode
  3653. it does not like that either
  3654. Please do not remove this part
  3655. might be used once
  3656. gdb for pascal is ready PM }
  3657. (*
  3658. param := para1;
  3659. i := 0;
  3660. while assigned(param) do
  3661. begin
  3662. inc(i);
  3663. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3664. {Here we have lost the parameter names !!}
  3665. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3666. strcat(nss,pst);
  3667. strdispose(pst);
  3668. param := param^.next;
  3669. end; *)
  3670. {strpcopy(strend(nss),';');}
  3671. stabstring := strnew(nss);
  3672. freemem(nss,1024);
  3673. end;
  3674. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3675. begin
  3676. if ( not assigned(typesym) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  3677. and (is_def_stab_written = not_written) then
  3678. inherited concatstabto(asmlist);
  3679. is_def_stab_written:=written;
  3680. end;
  3681. {$endif GDB}
  3682. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3683. var
  3684. pdc : TParaItem;
  3685. methodkind, paraspec : byte;
  3686. begin
  3687. if po_methodpointer in procoptions then
  3688. begin
  3689. { write method id and name }
  3690. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3691. write_rtti_name;
  3692. { write kind of method (can only be function or procedure)}
  3693. if rettype.def = voidtype.def then
  3694. methodkind := mkProcedure
  3695. else
  3696. methodkind := mkFunction;
  3697. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3698. { get # of parameters }
  3699. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3700. { write parameter info. The parameters must be written in reverse order
  3701. if this method uses right to left parameter pushing! }
  3702. if (po_leftright in procoptions) then
  3703. pdc:=TParaItem(Para.first)
  3704. else
  3705. pdc:=TParaItem(Para.last);
  3706. while assigned(pdc) do
  3707. begin
  3708. case pdc.paratyp of
  3709. vs_value: paraspec := 0;
  3710. vs_const: paraspec := pfConst;
  3711. vs_var : paraspec := pfVar;
  3712. vs_out : paraspec := pfOut;
  3713. end;
  3714. { write flags for current parameter }
  3715. rttiList.concat(Tai_const.Create_8bit(paraspec));
  3716. { write name of current parameter ### how can I get this??? (sg)}
  3717. rttiList.concat(Tai_const.Create_8bit(0));
  3718. { write name of type of current parameter }
  3719. tstoreddef(pdc.paratype.def).write_rtti_name;
  3720. if (po_leftright in procoptions) then
  3721. pdc:=TParaItem(pdc.next)
  3722. else
  3723. pdc:=TParaItem(pdc.previous);
  3724. end;
  3725. { write name of result type }
  3726. tstoreddef(rettype.def).write_rtti_name;
  3727. end;
  3728. end;
  3729. function tprocvardef.is_publishable : boolean;
  3730. begin
  3731. is_publishable:=(po_methodpointer in procoptions);
  3732. end;
  3733. function tprocvardef.gettypename : string;
  3734. var
  3735. s: string;
  3736. showhidden : boolean;
  3737. begin
  3738. {$ifdef EXTDEBUG}
  3739. showhidden:=true;
  3740. {$else EXTDEBUG}
  3741. showhidden:=false;
  3742. {$endif EXTDEBUG}
  3743. s:='<';
  3744. if po_classmethod in procoptions then
  3745. s := s+'class method type of'
  3746. else
  3747. if po_addressonly in procoptions then
  3748. s := s+'address of'
  3749. else
  3750. s := s+'procedure variable type of';
  3751. if assigned(rettype.def) and
  3752. (rettype.def<>voidtype.def) then
  3753. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  3754. else
  3755. s:=s+' procedure'+typename_paras(showhidden);
  3756. if po_methodpointer in procoptions then
  3757. s := s+' of object';
  3758. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3759. end;
  3760. {***************************************************************************
  3761. TOBJECTDEF
  3762. ***************************************************************************}
  3763. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  3764. begin
  3765. inherited create;
  3766. objecttype:=ot;
  3767. deftype:=objectdef;
  3768. objectoptions:=[];
  3769. childof:=nil;
  3770. symtable:=tobjectsymtable.create(n);
  3771. { create space for vmt !! }
  3772. vmt_offset:=0;
  3773. symtable.datasize:=0;
  3774. symtable.defowner:=self;
  3775. { recordalign -1 means C record packing, that starts
  3776. with an alignment of 1 }
  3777. if aktalignment.recordalignmax=-1 then
  3778. symtable.dataalignment:=1
  3779. else
  3780. symtable.dataalignment:=aktalignment.recordalignmax;
  3781. lastvtableindex:=0;
  3782. set_parent(c);
  3783. objname:=stringdup(upper(n));
  3784. objrealname:=stringdup(n);
  3785. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  3786. prepareguid;
  3787. { setup implemented interfaces }
  3788. if objecttype in [odt_class,odt_interfacecorba] then
  3789. implementedinterfaces:=timplementedinterfaces.create
  3790. else
  3791. implementedinterfaces:=nil;
  3792. {$ifdef GDB}
  3793. writing_class_record_stab:=false;
  3794. {$endif GDB}
  3795. end;
  3796. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3797. var
  3798. i,implintfcount: longint;
  3799. begin
  3800. inherited ppuloaddef(ppufile);
  3801. deftype:=objectdef;
  3802. objecttype:=tobjectdeftype(ppufile.getbyte);
  3803. savesize:=ppufile.getlongint;
  3804. vmt_offset:=ppufile.getlongint;
  3805. objrealname:=stringdup(ppufile.getstring);
  3806. objname:=stringdup(upper(objrealname^));
  3807. childof:=tobjectdef(ppufile.getderef);
  3808. ppufile.getsmallset(objectoptions);
  3809. { load guid }
  3810. iidstr:=nil;
  3811. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3812. begin
  3813. new(iidguid);
  3814. ppufile.getguid(iidguid^);
  3815. iidstr:=stringdup(ppufile.getstring);
  3816. lastvtableindex:=ppufile.getlongint;
  3817. end;
  3818. { load implemented interfaces }
  3819. if objecttype in [odt_class,odt_interfacecorba] then
  3820. begin
  3821. implementedinterfaces:=timplementedinterfaces.create;
  3822. implintfcount:=ppufile.getlongint;
  3823. for i:=1 to implintfcount do
  3824. begin
  3825. implementedinterfaces.addintfref(ppufile.getderef);
  3826. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  3827. end;
  3828. end
  3829. else
  3830. implementedinterfaces:=nil;
  3831. symtable:=tobjectsymtable.create(objrealname^);
  3832. tobjectsymtable(symtable).ppuload(ppufile);
  3833. symtable.defowner:=self;
  3834. { handles the predefined class tobject }
  3835. { the last TOBJECT which is loaded gets }
  3836. { it ! }
  3837. if (childof=nil) and
  3838. (objecttype=odt_class) and
  3839. (objname^='TOBJECT') then
  3840. class_tobject:=self;
  3841. if (childof=nil) and
  3842. (objecttype=odt_interfacecom) and
  3843. (objname^='IUNKNOWN') then
  3844. interface_iunknown:=self;
  3845. {$ifdef GDB}
  3846. writing_class_record_stab:=false;
  3847. {$endif GDB}
  3848. end;
  3849. destructor tobjectdef.destroy;
  3850. begin
  3851. if assigned(symtable) then
  3852. symtable.free;
  3853. stringdispose(objname);
  3854. stringdispose(objrealname);
  3855. if assigned(iidstr) then
  3856. stringdispose(iidstr);
  3857. if assigned(implementedinterfaces) then
  3858. implementedinterfaces.free;
  3859. if assigned(iidguid) then
  3860. dispose(iidguid);
  3861. inherited destroy;
  3862. end;
  3863. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3864. var
  3865. implintfcount : longint;
  3866. i : longint;
  3867. begin
  3868. inherited ppuwritedef(ppufile);
  3869. ppufile.putbyte(byte(objecttype));
  3870. ppufile.putlongint(size);
  3871. ppufile.putlongint(vmt_offset);
  3872. ppufile.putstring(objrealname^);
  3873. ppufile.putderef(childof);
  3874. ppufile.putsmallset(objectoptions);
  3875. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3876. begin
  3877. ppufile.putguid(iidguid^);
  3878. ppufile.putstring(iidstr^);
  3879. ppufile.putlongint(lastvtableindex);
  3880. end;
  3881. if objecttype in [odt_class,odt_interfacecorba] then
  3882. begin
  3883. implintfcount:=implementedinterfaces.count;
  3884. ppufile.putlongint(implintfcount);
  3885. for i:=1 to implintfcount do
  3886. begin
  3887. ppufile.putderef(implementedinterfaces.interfaces(i));
  3888. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  3889. end;
  3890. end;
  3891. ppufile.writeentry(ibobjectdef);
  3892. tobjectsymtable(symtable).ppuwrite(ppufile);
  3893. end;
  3894. procedure tobjectdef.deref;
  3895. var
  3896. oldrecsyms : tsymtable;
  3897. begin
  3898. inherited deref;
  3899. resolvedef(pointer(childof));
  3900. oldrecsyms:=aktrecordsymtable;
  3901. aktrecordsymtable:=symtable;
  3902. tstoredsymtable(symtable).deref;
  3903. aktrecordsymtable:=oldrecsyms;
  3904. if objecttype in [odt_class,odt_interfacecorba] then
  3905. implementedinterfaces.deref;
  3906. end;
  3907. procedure tobjectdef.prepareguid;
  3908. begin
  3909. { set up guid }
  3910. if not assigned(iidguid) then
  3911. begin
  3912. new(iidguid);
  3913. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3914. end;
  3915. { setup iidstring }
  3916. if not assigned(iidstr) then
  3917. iidstr:=stringdup(''); { default is empty string }
  3918. end;
  3919. procedure tobjectdef.set_parent( c : tobjectdef);
  3920. begin
  3921. { nothing to do if the parent was not forward !}
  3922. if assigned(childof) then
  3923. exit;
  3924. childof:=c;
  3925. { some options are inherited !! }
  3926. if assigned(c) then
  3927. begin
  3928. { only important for classes }
  3929. lastvtableindex:=c.lastvtableindex;
  3930. objectoptions:=objectoptions+(c.objectoptions*
  3931. [oo_has_virtual,oo_has_private,oo_has_protected,
  3932. oo_has_constructor,oo_has_destructor]);
  3933. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3934. begin
  3935. { add the data of the anchestor class }
  3936. inc(symtable.datasize,c.symtable.datasize);
  3937. if (oo_has_vmt in objectoptions) and
  3938. (oo_has_vmt in c.objectoptions) then
  3939. dec(symtable.datasize,POINTER_SIZE);
  3940. { if parent has a vmt field then
  3941. the offset is the same for the child PM }
  3942. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3943. begin
  3944. vmt_offset:=c.vmt_offset;
  3945. include(objectoptions,oo_has_vmt);
  3946. end;
  3947. end;
  3948. end;
  3949. savesize := symtable.datasize;
  3950. end;
  3951. procedure tobjectdef.insertvmt;
  3952. begin
  3953. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  3954. exit;
  3955. if (oo_has_vmt in objectoptions) then
  3956. internalerror(12345)
  3957. else
  3958. begin
  3959. symtable.datasize:=align(symtable.datasize,symtable.dataalignment);
  3960. vmt_offset:=symtable.datasize;
  3961. inc(symtable.datasize,POINTER_SIZE);
  3962. include(objectoptions,oo_has_vmt);
  3963. end;
  3964. end;
  3965. procedure tobjectdef.check_forwards;
  3966. begin
  3967. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  3968. tstoredsymtable(symtable).check_forwards;
  3969. if (oo_is_forward in objectoptions) then
  3970. begin
  3971. { ok, in future, the forward can be resolved }
  3972. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3973. exclude(objectoptions,oo_is_forward);
  3974. end;
  3975. end;
  3976. { true, if self inherits from d (or if they are equal) }
  3977. function tobjectdef.is_related(d : tobjectdef) : boolean;
  3978. var
  3979. hp : tobjectdef;
  3980. begin
  3981. hp:=self;
  3982. while assigned(hp) do
  3983. begin
  3984. if hp=d then
  3985. begin
  3986. is_related:=true;
  3987. exit;
  3988. end;
  3989. hp:=hp.childof;
  3990. end;
  3991. is_related:=false;
  3992. end;
  3993. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  3994. var
  3995. p : pprocdeflist;
  3996. begin
  3997. { if we found already a destructor, then we exit }
  3998. if assigned(sd) then
  3999. exit;
  4000. if tsym(sym).typ=procsym then
  4001. begin
  4002. p:=tprocsym(sym).defs;
  4003. while assigned(p) do
  4004. begin
  4005. if p^.def.proctypeoption=potype_destructor then
  4006. begin
  4007. sd:=p^.def;
  4008. exit;
  4009. end;
  4010. p:=p^.next;
  4011. end;
  4012. end;
  4013. end;*)
  4014. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4015. begin
  4016. { if we found already a destructor, then we exit }
  4017. if (ppointer(sd)^=nil) and
  4018. (Tsym(sym).typ=procsym) then
  4019. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4020. end;
  4021. function tobjectdef.searchdestructor : tprocdef;
  4022. var
  4023. o : tobjectdef;
  4024. sd : tprocdef;
  4025. begin
  4026. searchdestructor:=nil;
  4027. o:=self;
  4028. sd:=nil;
  4029. while assigned(o) do
  4030. begin
  4031. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4032. if assigned(sd) then
  4033. begin
  4034. searchdestructor:=sd;
  4035. exit;
  4036. end;
  4037. o:=o.childof;
  4038. end;
  4039. end;
  4040. function tobjectdef.size : longint;
  4041. var
  4042. _resultsize : longint;
  4043. begin
  4044. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4045. _resultsize:=POINTER_SIZE
  4046. else
  4047. _resultsize:=symtable.datasize;
  4048. size := _resultsize;
  4049. end;
  4050. function tobjectdef.alignment:longint;
  4051. begin
  4052. alignment:=symtable.dataalignment;
  4053. end;
  4054. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4055. begin
  4056. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4057. case objecttype of
  4058. odt_class:
  4059. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  4060. odt_interfacecom,odt_interfacecorba:
  4061. vmtmethodoffset:=index*POINTER_SIZE;
  4062. else
  4063. {$ifdef WITHDMT}
  4064. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  4065. {$else WITHDMT}
  4066. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  4067. {$endif WITHDMT}
  4068. end;
  4069. end;
  4070. function tobjectdef.vmt_mangledname : string;
  4071. begin
  4072. if not(oo_has_vmt in objectoptions) then
  4073. Message1(parser_n_object_has_no_vmt,objrealname^);
  4074. vmt_mangledname:=mangledname_prefix('VMT',owner)+objname^;
  4075. end;
  4076. function tobjectdef.rtti_name : string;
  4077. begin
  4078. rtti_name:=mangledname_prefix('RTTI',owner)+objname^;
  4079. end;
  4080. {$ifdef GDB}
  4081. procedure tobjectdef.addprocname(p :tnamedindexitem;arg:pointer);
  4082. var virtualind,argnames : string;
  4083. news, newrec : pchar;
  4084. pd,ipd : tprocdef;
  4085. lindex : longint;
  4086. para : TParaItem;
  4087. arglength : byte;
  4088. sp : char;
  4089. begin
  4090. If tsym(p).typ = procsym then
  4091. begin
  4092. pd := tprocsym(p).first_procdef;
  4093. { this will be used for full implementation of object stabs
  4094. not yet done }
  4095. ipd := Tprocsym(p).last_procdef;
  4096. if (po_virtualmethod in pd.procoptions) then
  4097. begin
  4098. lindex := pd.extnumber;
  4099. {doesnt seem to be necessary
  4100. lindex := lindex or $80000000;}
  4101. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  4102. end
  4103. else
  4104. virtualind := '.';
  4105. { used by gdbpas to recognize constructor and destructors }
  4106. if (pd.proctypeoption=potype_constructor) then
  4107. argnames:='__ct__'
  4108. else if (pd.proctypeoption=potype_destructor) then
  4109. argnames:='__dt__'
  4110. else
  4111. argnames := '';
  4112. { arguments are not listed here }
  4113. {we don't need another definition}
  4114. para := TParaItem(pd.Para.first);
  4115. while assigned(para) do
  4116. begin
  4117. if Para.paratype.def.deftype = formaldef then
  4118. begin
  4119. if Para.paratyp=vs_var then
  4120. argnames := argnames+'3var'
  4121. else if Para.paratyp=vs_const then
  4122. argnames:=argnames+'5const'
  4123. else if Para.paratyp=vs_out then
  4124. argnames:=argnames+'3out';
  4125. end
  4126. else
  4127. begin
  4128. { if the arg definition is like (v: ^byte;..
  4129. there is no sym attached to data !!! }
  4130. if assigned(Para.paratype.def.typesym) then
  4131. begin
  4132. arglength := length(Para.paratype.def.typesym.name);
  4133. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4134. end
  4135. else
  4136. begin
  4137. argnames:=argnames+'11unnamedtype';
  4138. end;
  4139. end;
  4140. para := TParaItem(Para.next);
  4141. end;
  4142. ipd.is_def_stab_written := written;
  4143. { here 2A must be changed for private and protected }
  4144. { 0 is private 1 protected and 2 public }
  4145. if (sp_private in tsym(p).symoptions) then sp:='0'
  4146. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  4147. else sp:='2';
  4148. newrec := strpnew(p.name+'::'+ipd.numberstring
  4149. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  4150. +virtualind+';');
  4151. { get spare place for a string at the end }
  4152. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  4153. begin
  4154. getmem(news,stabrecsize+memsizeinc);
  4155. strcopy(news,stabrecstring);
  4156. freemem(stabrecstring,stabrecsize);
  4157. stabrecsize:=stabrecsize+memsizeinc;
  4158. stabrecstring:=news;
  4159. end;
  4160. strcat(StabRecstring,newrec);
  4161. {freemem(newrec,memsizeinc); }
  4162. strdispose(newrec);
  4163. {This should be used for case !!
  4164. RecOffset := RecOffset + pd.size;}
  4165. end;
  4166. end;
  4167. function tobjectdef.stabstring : pchar;
  4168. var anc : tobjectdef;
  4169. oldrec : pchar;
  4170. oldrecsize,oldrecoffset : longint;
  4171. str_end : string;
  4172. begin
  4173. if not (objecttype=odt_class) or writing_class_record_stab then
  4174. begin
  4175. oldrec := stabrecstring;
  4176. oldrecsize:=stabrecsize;
  4177. stabrecsize:=memsizeinc;
  4178. GetMem(stabrecstring,stabrecsize);
  4179. strpcopy(stabRecString,'s'+tostr(symtable.datasize));
  4180. if assigned(childof) then
  4181. begin
  4182. {only one ancestor not virtual, public, at base offset 0 }
  4183. { !1 , 0 2 0 , }
  4184. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  4185. end;
  4186. {virtual table to implement yet}
  4187. OldRecOffset:=RecOffset;
  4188. RecOffset := 0;
  4189. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  4190. RecOffset:=OldRecOffset;
  4191. if (oo_has_vmt in objectoptions) then
  4192. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4193. begin
  4194. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  4195. +','+tostr(vmt_offset*8)+';');
  4196. end;
  4197. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname,nil);
  4198. if (oo_has_vmt in objectoptions) then
  4199. begin
  4200. anc := self;
  4201. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4202. anc := anc.childof;
  4203. { just in case anc = self }
  4204. str_end:=';~%'+anc.classnumberstring+';';
  4205. end
  4206. else
  4207. str_end:=';';
  4208. strpcopy(strend(stabrecstring),str_end);
  4209. stabstring := strnew(StabRecString);
  4210. freemem(stabrecstring,stabrecsize);
  4211. stabrecstring := oldrec;
  4212. stabrecsize:=oldrecsize;
  4213. end
  4214. else
  4215. begin
  4216. stabstring:=strpnew('*'+classnumberstring);
  4217. end;
  4218. end;
  4219. procedure tobjectdef.set_globalnb;
  4220. begin
  4221. globalnb:=PglobalTypeCount^;
  4222. inc(PglobalTypeCount^);
  4223. { classes need two type numbers, the globalnb is set to the ptr }
  4224. if objecttype=odt_class then
  4225. begin
  4226. globalnb:=PGlobalTypeCount^;
  4227. inc(PglobalTypeCount^);
  4228. end;
  4229. end;
  4230. function tobjectdef.classnumberstring : string;
  4231. begin
  4232. { write stabs again if needed }
  4233. numberstring;
  4234. if objecttype=odt_class then
  4235. begin
  4236. dec(globalnb);
  4237. classnumberstring:=numberstring;
  4238. inc(globalnb);
  4239. end
  4240. else
  4241. classnumberstring:=numberstring;
  4242. end;
  4243. function tobjectdef.allstabstring : pchar;
  4244. var stabchar : string[2];
  4245. ss,st : pchar;
  4246. sname : string;
  4247. sym_line_no : longint;
  4248. begin
  4249. ss := stabstring;
  4250. getmem(st,strlen(ss)+512);
  4251. stabchar := 't';
  4252. if deftype in tagtypes then
  4253. stabchar := 'Tt';
  4254. if assigned(typesym) then
  4255. begin
  4256. sname := typesym.name;
  4257. sym_line_no:=typesym.fileinfo.line;
  4258. end
  4259. else
  4260. begin
  4261. sname := ' ';
  4262. sym_line_no:=0;
  4263. end;
  4264. if writing_class_record_stab then
  4265. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4266. else
  4267. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4268. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4269. allstabstring := strnew(st);
  4270. freemem(st,strlen(ss)+512);
  4271. strdispose(ss);
  4272. end;
  4273. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4274. var st : pstring;
  4275. begin
  4276. if objecttype<>odt_class then
  4277. begin
  4278. inherited concatstabto(asmlist);
  4279. exit;
  4280. end;
  4281. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4282. (is_def_stab_written = not_written) then
  4283. begin
  4284. if globalnb=0 then
  4285. set_globalnb;
  4286. { Write the record class itself }
  4287. writing_class_record_stab:=true;
  4288. inherited concatstabto(asmlist);
  4289. writing_class_record_stab:=false;
  4290. { Write the invisible pointer class }
  4291. is_def_stab_written:=not_written;
  4292. if assigned(typesym) then
  4293. begin
  4294. st:=typesym.FName;
  4295. typesym.FName:=stringdup(' ');
  4296. end;
  4297. inherited concatstabto(asmlist);
  4298. if assigned(typesym) then
  4299. begin
  4300. stringdispose(typesym.FName);
  4301. typesym.FName:=st;
  4302. end;
  4303. end;
  4304. end;
  4305. {$endif GDB}
  4306. function tobjectdef.needs_inittable : boolean;
  4307. begin
  4308. case objecttype of
  4309. odt_class :
  4310. needs_inittable:=false;
  4311. odt_interfacecom:
  4312. needs_inittable:=true;
  4313. odt_interfacecorba:
  4314. needs_inittable:=is_related(interface_iunknown);
  4315. odt_object:
  4316. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4317. else
  4318. internalerror(200108267);
  4319. end;
  4320. end;
  4321. function tobjectdef.members_need_inittable : boolean;
  4322. begin
  4323. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4324. end;
  4325. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4326. begin
  4327. if needs_prop_entry(tsym(sym)) and
  4328. (tsym(sym).typ<>varsym) then
  4329. inc(count);
  4330. end;
  4331. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4332. var
  4333. proctypesinfo : byte;
  4334. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4335. var
  4336. typvalue : byte;
  4337. hp : psymlistitem;
  4338. address : longint;
  4339. begin
  4340. if not(assigned(proc) and assigned(proc.firstsym)) then
  4341. begin
  4342. rttiList.concat(Tai_const.Create_32bit(1));
  4343. typvalue:=3;
  4344. end
  4345. else if proc.firstsym^.sym.typ=varsym then
  4346. begin
  4347. address:=0;
  4348. hp:=proc.firstsym;
  4349. while assigned(hp) do
  4350. begin
  4351. inc(address,tvarsym(hp^.sym).address);
  4352. hp:=hp^.next;
  4353. end;
  4354. rttiList.concat(Tai_const.Create_32bit(address));
  4355. typvalue:=0;
  4356. end
  4357. else
  4358. begin
  4359. if not(po_virtualmethod in tprocdef(proc.def).procoptions) then
  4360. begin
  4361. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.def).mangledname));
  4362. typvalue:=1;
  4363. end
  4364. else
  4365. begin
  4366. { virtual method, write vmt offset }
  4367. rttiList.concat(Tai_const.Create_32bit(
  4368. tprocdef(proc.def)._class.vmtmethodoffset(tprocdef(proc.def).extnumber)));
  4369. typvalue:=2;
  4370. end;
  4371. end;
  4372. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4373. end;
  4374. begin
  4375. if needs_prop_entry(tsym(sym)) then
  4376. case tsym(sym).typ of
  4377. varsym:
  4378. begin
  4379. {$ifdef dummy}
  4380. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4381. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4382. internalerror(1509992);
  4383. { access to implicit class property as field }
  4384. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4385. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4386. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4387. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4388. { per default stored }
  4389. rttiList.concat(Tai_const.Create_32bit(1));
  4390. { index as well as ... }
  4391. rttiList.concat(Tai_const.Create_32bit(0));
  4392. { default value are zero }
  4393. rttiList.concat(Tai_const.Create_32bit(0));
  4394. rttiList.concat(Tai_const.Create_16bit(count));
  4395. inc(count);
  4396. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4397. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4398. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4399. {$endif dummy}
  4400. end;
  4401. propertysym:
  4402. begin
  4403. if ppo_indexed in tpropertysym(sym).propoptions then
  4404. proctypesinfo:=$40
  4405. else
  4406. proctypesinfo:=0;
  4407. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4408. writeproc(tpropertysym(sym).readaccess,0);
  4409. writeproc(tpropertysym(sym).writeaccess,2);
  4410. { isn't it stored ? }
  4411. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4412. begin
  4413. rttiList.concat(Tai_const.Create_32bit(0));
  4414. proctypesinfo:=proctypesinfo or (3 shl 4);
  4415. end
  4416. else
  4417. writeproc(tpropertysym(sym).storedaccess,4);
  4418. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4419. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4420. rttiList.concat(Tai_const.Create_16bit(count));
  4421. inc(count);
  4422. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4423. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4424. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4425. end;
  4426. else internalerror(1509992);
  4427. end;
  4428. end;
  4429. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4430. begin
  4431. if needs_prop_entry(tsym(sym)) then
  4432. begin
  4433. case tsym(sym).typ of
  4434. propertysym:
  4435. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4436. varsym:
  4437. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4438. else
  4439. internalerror(1509991);
  4440. end;
  4441. end;
  4442. end;
  4443. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4444. begin
  4445. FRTTIType:=rt;
  4446. case rt of
  4447. initrtti :
  4448. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4449. fullrtti :
  4450. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4451. else
  4452. internalerror(200108301);
  4453. end;
  4454. end;
  4455. type
  4456. tclasslistitem = class(TLinkedListItem)
  4457. index : longint;
  4458. p : tobjectdef;
  4459. end;
  4460. var
  4461. classtablelist : tlinkedlist;
  4462. tablecount : longint;
  4463. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4464. var
  4465. hp : tclasslistitem;
  4466. begin
  4467. hp:=tclasslistitem(classtablelist.first);
  4468. while assigned(hp) do
  4469. if hp.p=p then
  4470. begin
  4471. searchclasstablelist:=hp;
  4472. exit;
  4473. end
  4474. else
  4475. hp:=tclasslistitem(hp.next);
  4476. searchclasstablelist:=nil;
  4477. end;
  4478. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4479. var
  4480. hp : tclasslistitem;
  4481. begin
  4482. if needs_prop_entry(tsym(sym)) and
  4483. (tsym(sym).typ=varsym) then
  4484. begin
  4485. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4486. internalerror(0206001);
  4487. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4488. if not(assigned(hp)) then
  4489. begin
  4490. hp:=tclasslistitem.create;
  4491. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4492. hp.index:=tablecount;
  4493. classtablelist.concat(hp);
  4494. inc(tablecount);
  4495. end;
  4496. inc(count);
  4497. end;
  4498. end;
  4499. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4500. var
  4501. hp : tclasslistitem;
  4502. begin
  4503. if needs_prop_entry(tsym(sym)) and
  4504. (tsym(sym).typ=varsym) then
  4505. begin
  4506. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).address));
  4507. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4508. if not(assigned(hp)) then
  4509. internalerror(0206002);
  4510. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4511. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4512. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4513. end;
  4514. end;
  4515. function tobjectdef.generate_field_table : tasmlabel;
  4516. var
  4517. fieldtable,
  4518. classtable : tasmlabel;
  4519. hp : tclasslistitem;
  4520. begin
  4521. classtablelist:=TLinkedList.Create;
  4522. objectlibrary.getdatalabel(fieldtable);
  4523. objectlibrary.getdatalabel(classtable);
  4524. count:=0;
  4525. tablecount:=0;
  4526. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4527. if (cs_create_smart in aktmoduleswitches) then
  4528. rttiList.concat(Tai_cut.Create);
  4529. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4530. rttiList.concat(Tai_label.Create(fieldtable));
  4531. rttiList.concat(Tai_const.Create_16bit(count));
  4532. rttiList.concat(Tai_const_symbol.Create(classtable));
  4533. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4534. { generate the class table }
  4535. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4536. rttiList.concat(Tai_label.Create(classtable));
  4537. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4538. hp:=tclasslistitem(classtablelist.first);
  4539. while assigned(hp) do
  4540. begin
  4541. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4542. hp:=tclasslistitem(hp.next);
  4543. end;
  4544. generate_field_table:=fieldtable;
  4545. classtablelist.free;
  4546. end;
  4547. function tobjectdef.next_free_name_index : longint;
  4548. var
  4549. i : longint;
  4550. begin
  4551. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4552. i:=childof.next_free_name_index
  4553. else
  4554. i:=0;
  4555. count:=0;
  4556. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4557. next_free_name_index:=i+count;
  4558. end;
  4559. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4560. begin
  4561. case objecttype of
  4562. odt_class:
  4563. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4564. odt_object:
  4565. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4566. odt_interfacecom:
  4567. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4568. odt_interfacecorba:
  4569. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4570. else
  4571. exit;
  4572. end;
  4573. { generate the name }
  4574. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4575. rttiList.concat(Tai_string.Create(objrealname^));
  4576. case rt of
  4577. initrtti :
  4578. begin
  4579. rttiList.concat(Tai_const.Create_32bit(size));
  4580. if objecttype in [odt_class,odt_object] then
  4581. begin
  4582. count:=0;
  4583. FRTTIType:=rt;
  4584. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4585. rttiList.concat(Tai_const.Create_32bit(count));
  4586. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4587. end;
  4588. end;
  4589. fullrtti :
  4590. begin
  4591. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4592. rttiList.concat(Tai_const.Create_32bit(0))
  4593. else
  4594. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname));
  4595. { write owner typeinfo }
  4596. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4597. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4598. else
  4599. rttiList.concat(Tai_const.Create_32bit(0));
  4600. { count total number of properties }
  4601. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4602. count:=childof.next_free_name_index
  4603. else
  4604. count:=0;
  4605. { write it }
  4606. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4607. rttiList.concat(Tai_const.Create_16bit(count));
  4608. { write unit name }
  4609. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4610. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4611. { write published properties count }
  4612. count:=0;
  4613. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4614. rttiList.concat(Tai_const.Create_16bit(count));
  4615. { count is used to write nameindex }
  4616. { but we need an offset of the owner }
  4617. { to give each property an own slot }
  4618. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4619. count:=childof.next_free_name_index
  4620. else
  4621. count:=0;
  4622. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4623. end;
  4624. end;
  4625. end;
  4626. function tobjectdef.is_publishable : boolean;
  4627. begin
  4628. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4629. end;
  4630. {****************************************************************************
  4631. TIMPLEMENTEDINTERFACES
  4632. ****************************************************************************}
  4633. type
  4634. tnamemap = class(TNamedIndexItem)
  4635. newname: pstring;
  4636. constructor create(const aname, anewname: string);
  4637. destructor destroy; override;
  4638. end;
  4639. constructor tnamemap.create(const aname, anewname: string);
  4640. begin
  4641. inherited createname(name);
  4642. newname:=stringdup(anewname);
  4643. end;
  4644. destructor tnamemap.destroy;
  4645. begin
  4646. stringdispose(newname);
  4647. inherited destroy;
  4648. end;
  4649. type
  4650. tprocdefstore = class(TNamedIndexItem)
  4651. procdef: tprocdef;
  4652. constructor create(aprocdef: tprocdef);
  4653. end;
  4654. constructor tprocdefstore.create(aprocdef: tprocdef);
  4655. begin
  4656. inherited create;
  4657. procdef:=aprocdef;
  4658. end;
  4659. type
  4660. timplintfentry = class(TNamedIndexItem)
  4661. intf: tobjectdef;
  4662. ioffs: longint;
  4663. namemappings: tdictionary;
  4664. procdefs: TIndexArray;
  4665. constructor create(aintf: tobjectdef);
  4666. destructor destroy; override;
  4667. end;
  4668. constructor timplintfentry.create(aintf: tobjectdef);
  4669. begin
  4670. inherited create;
  4671. intf:=aintf;
  4672. ioffs:=-1;
  4673. namemappings:=nil;
  4674. procdefs:=nil;
  4675. end;
  4676. destructor timplintfentry.destroy;
  4677. begin
  4678. if assigned(namemappings) then
  4679. namemappings.free;
  4680. if assigned(procdefs) then
  4681. procdefs.free;
  4682. inherited destroy;
  4683. end;
  4684. constructor timplementedinterfaces.create;
  4685. begin
  4686. finterfaces:=tindexarray.create(1);
  4687. end;
  4688. destructor timplementedinterfaces.destroy;
  4689. begin
  4690. finterfaces.destroy;
  4691. end;
  4692. function timplementedinterfaces.count: longint;
  4693. begin
  4694. count:=finterfaces.count;
  4695. end;
  4696. procedure timplementedinterfaces.checkindex(intfindex: longint);
  4697. begin
  4698. if (intfindex<1) or (intfindex>count) then
  4699. InternalError(200006123);
  4700. end;
  4701. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  4702. begin
  4703. checkindex(intfindex);
  4704. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  4705. end;
  4706. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  4707. begin
  4708. checkindex(intfindex);
  4709. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  4710. end;
  4711. function timplementedinterfaces.searchintf(def: tdef): longint;
  4712. var
  4713. i: longint;
  4714. begin
  4715. i:=1;
  4716. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  4717. if i<=count then
  4718. searchintf:=i
  4719. else
  4720. searchintf:=-1;
  4721. end;
  4722. procedure timplementedinterfaces.deref;
  4723. var
  4724. i: longint;
  4725. begin
  4726. for i:=1 to count do
  4727. with timplintfentry(finterfaces.search(i)) do
  4728. resolvedef(pointer(intf));
  4729. end;
  4730. procedure timplementedinterfaces.addintfref(def: pointer);
  4731. begin
  4732. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4733. end;
  4734. procedure timplementedinterfaces.addintf(def: tdef);
  4735. begin
  4736. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  4737. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4738. internalerror(200006124);
  4739. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  4740. end;
  4741. procedure timplementedinterfaces.clearmappings;
  4742. var
  4743. i: longint;
  4744. begin
  4745. for i:=1 to count do
  4746. with timplintfentry(finterfaces.search(i)) do
  4747. begin
  4748. if assigned(namemappings) then
  4749. namemappings.free;
  4750. namemappings:=nil;
  4751. end;
  4752. end;
  4753. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  4754. begin
  4755. checkindex(intfindex);
  4756. with timplintfentry(finterfaces.search(intfindex)) do
  4757. begin
  4758. if not assigned(namemappings) then
  4759. namemappings:=tdictionary.create;
  4760. namemappings.insert(tnamemap.create(name,newname));
  4761. end;
  4762. end;
  4763. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  4764. begin
  4765. checkindex(intfindex);
  4766. if not assigned(nextexist) then
  4767. with timplintfentry(finterfaces.search(intfindex)) do
  4768. begin
  4769. if assigned(namemappings) then
  4770. nextexist:=namemappings.search(name)
  4771. else
  4772. nextexist:=nil;
  4773. end;
  4774. if assigned(nextexist) then
  4775. begin
  4776. getmappings:=tnamemap(nextexist).newname^;
  4777. nextexist:=tnamemap(nextexist).listnext;
  4778. end
  4779. else
  4780. getmappings:='';
  4781. end;
  4782. procedure timplementedinterfaces.clearimplprocs;
  4783. var
  4784. i: longint;
  4785. begin
  4786. for i:=1 to count do
  4787. with timplintfentry(finterfaces.search(i)) do
  4788. begin
  4789. if assigned(procdefs) then
  4790. procdefs.free;
  4791. procdefs:=nil;
  4792. end;
  4793. end;
  4794. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  4795. begin
  4796. checkindex(intfindex);
  4797. with timplintfentry(finterfaces.search(intfindex)) do
  4798. begin
  4799. if not assigned(procdefs) then
  4800. procdefs:=tindexarray.create(4);
  4801. procdefs.insert(tprocdefstore.create(procdef));
  4802. end;
  4803. end;
  4804. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  4805. begin
  4806. checkindex(intfindex);
  4807. with timplintfentry(finterfaces.search(intfindex)) do
  4808. if assigned(procdefs) then
  4809. implproccount:=procdefs.count
  4810. else
  4811. implproccount:=0;
  4812. end;
  4813. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  4814. begin
  4815. checkindex(intfindex);
  4816. with timplintfentry(finterfaces.search(intfindex)) do
  4817. if assigned(procdefs) then
  4818. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  4819. else
  4820. internalerror(200006131);
  4821. end;
  4822. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  4823. var
  4824. possible: boolean;
  4825. i: longint;
  4826. iiep1: TIndexArray;
  4827. iiep2: TIndexArray;
  4828. begin
  4829. checkindex(intfindex);
  4830. checkindex(remainindex);
  4831. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  4832. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  4833. if not assigned(iiep1) then { empty interface is mergeable :-) }
  4834. begin
  4835. possible:=true;
  4836. weight:=0;
  4837. end
  4838. else
  4839. begin
  4840. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  4841. i:=1;
  4842. while (possible) and (i<=iiep1.count) do
  4843. begin
  4844. possible:=
  4845. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  4846. inc(i);
  4847. end;
  4848. if possible then
  4849. weight:=iiep1.count;
  4850. end;
  4851. isimplmergepossible:=possible;
  4852. end;
  4853. {****************************************************************************
  4854. TFORWARDDEF
  4855. ****************************************************************************}
  4856. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4857. var
  4858. oldregisterdef : boolean;
  4859. begin
  4860. { never register the forwarddefs, they are disposed at the
  4861. end of the type declaration block }
  4862. oldregisterdef:=registerdef;
  4863. registerdef:=false;
  4864. inherited create;
  4865. registerdef:=oldregisterdef;
  4866. deftype:=forwarddef;
  4867. tosymname:=stringdup(s);
  4868. forwardpos:=pos;
  4869. end;
  4870. function tforwarddef.gettypename:string;
  4871. begin
  4872. gettypename:='unresolved forward to '+tosymname^;
  4873. end;
  4874. destructor tforwarddef.destroy;
  4875. begin
  4876. if assigned(tosymname) then
  4877. stringdispose(tosymname);
  4878. inherited destroy;
  4879. end;
  4880. {****************************************************************************
  4881. TERRORDEF
  4882. ****************************************************************************}
  4883. constructor terrordef.create;
  4884. begin
  4885. inherited create;
  4886. deftype:=errordef;
  4887. end;
  4888. {$ifdef GDB}
  4889. function terrordef.stabstring : pchar;
  4890. begin
  4891. stabstring:=strpnew('error'+numberstring);
  4892. end;
  4893. procedure terrordef.concatstabto(asmlist : taasmoutput);
  4894. begin
  4895. { No internal error needed, an normal error is already
  4896. thrown }
  4897. end;
  4898. {$endif GDB}
  4899. function terrordef.gettypename:string;
  4900. begin
  4901. gettypename:='<erroneous type>';
  4902. end;
  4903. function terrordef.getmangledparaname:string;
  4904. begin
  4905. getmangledparaname:='error';
  4906. end;
  4907. {****************************************************************************
  4908. GDB Helpers
  4909. ****************************************************************************}
  4910. {$ifdef GDB}
  4911. function typeglobalnumber(const s : string) : string;
  4912. var st : string;
  4913. symt : tsymtable;
  4914. srsym : tsym;
  4915. srsymtable : tsymtable;
  4916. old_make_ref : boolean;
  4917. begin
  4918. old_make_ref:=make_ref;
  4919. make_ref:=false;
  4920. typeglobalnumber := '0';
  4921. srsym := nil;
  4922. if pos('.',s) > 0 then
  4923. begin
  4924. st := copy(s,1,pos('.',s)-1);
  4925. searchsym(st,srsym,srsymtable);
  4926. st := copy(s,pos('.',s)+1,255);
  4927. if assigned(srsym) then
  4928. begin
  4929. if srsym.typ = unitsym then
  4930. begin
  4931. symt := tunitsym(srsym).unitsymtable;
  4932. srsym := tsym(symt.search(st));
  4933. end else srsym := nil;
  4934. end;
  4935. end else st := s;
  4936. if srsym = nil then
  4937. searchsym(st,srsym,srsymtable);
  4938. if (srsym=nil) or
  4939. (srsym.typ<>typesym) then
  4940. begin
  4941. Message(type_e_type_id_expected);
  4942. exit;
  4943. end;
  4944. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  4945. make_ref:=old_make_ref;
  4946. end;
  4947. {$endif GDB}
  4948. {****************************************************************************
  4949. Definition Helpers
  4950. ****************************************************************************}
  4951. procedure reset_global_defs;
  4952. var
  4953. def : tstoreddef;
  4954. {$ifdef debug}
  4955. prevdef : tstoreddef;
  4956. {$endif debug}
  4957. begin
  4958. {$ifdef debug}
  4959. prevdef:=nil;
  4960. {$endif debug}
  4961. {$ifdef GDB}
  4962. pglobaltypecount:=@globaltypecount;
  4963. {$endif GDB}
  4964. def:=firstglobaldef;
  4965. while assigned(def) do
  4966. begin
  4967. {$ifdef GDB}
  4968. if assigned(def.typesym) then
  4969. ttypesym(def.typesym).isusedinstab:=false;
  4970. def.is_def_stab_written:=not_written;
  4971. {$endif GDB}
  4972. if assigned(def.rttitablesym) then
  4973. trttisym(def.rttitablesym).lab := nil;
  4974. if assigned(def.inittablesym) then
  4975. trttisym(def.inittablesym).lab := nil;
  4976. def.localrttilab[initrtti]:=nil;
  4977. def.localrttilab[fullrtti]:=nil;
  4978. {$ifdef debug}
  4979. prevdef:=def;
  4980. {$endif debug}
  4981. def:=def.nextglobal;
  4982. end;
  4983. end;
  4984. function is_interfacecom(def: tdef): boolean;
  4985. begin
  4986. is_interfacecom:=
  4987. assigned(def) and
  4988. (def.deftype=objectdef) and
  4989. (tobjectdef(def).objecttype=odt_interfacecom);
  4990. end;
  4991. function is_interfacecorba(def: tdef): boolean;
  4992. begin
  4993. is_interfacecorba:=
  4994. assigned(def) and
  4995. (def.deftype=objectdef) and
  4996. (tobjectdef(def).objecttype=odt_interfacecorba);
  4997. end;
  4998. function is_interface(def: tdef): boolean;
  4999. begin
  5000. is_interface:=
  5001. assigned(def) and
  5002. (def.deftype=objectdef) and
  5003. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5004. end;
  5005. function is_class(def: tdef): boolean;
  5006. begin
  5007. is_class:=
  5008. assigned(def) and
  5009. (def.deftype=objectdef) and
  5010. (tobjectdef(def).objecttype=odt_class);
  5011. end;
  5012. function is_object(def: tdef): boolean;
  5013. begin
  5014. is_object:=
  5015. assigned(def) and
  5016. (def.deftype=objectdef) and
  5017. (tobjectdef(def).objecttype=odt_object);
  5018. end;
  5019. function is_cppclass(def: tdef): boolean;
  5020. begin
  5021. is_cppclass:=
  5022. assigned(def) and
  5023. (def.deftype=objectdef) and
  5024. (tobjectdef(def).objecttype=odt_cppclass);
  5025. end;
  5026. function is_class_or_interface(def: tdef): boolean;
  5027. begin
  5028. is_class_or_interface:=
  5029. assigned(def) and
  5030. (def.deftype=objectdef) and
  5031. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5032. end;
  5033. end.
  5034. {
  5035. $Log$
  5036. Revision 1.146 2003-05-26 21:17:18 peter
  5037. * procinlinenode removed
  5038. * aktexit2label removed, fast exit removed
  5039. + tcallnode.inlined_pass_2 added
  5040. Revision 1.145 2003/05/25 11:34:17 peter
  5041. * methodpointer self pushing fixed
  5042. Revision 1.144 2003/05/15 18:58:53 peter
  5043. * removed selfpointer_offset, vmtpointer_offset
  5044. * tvarsym.adjusted_address
  5045. * address in localsymtable is now in the real direction
  5046. * removed some obsolete globals
  5047. Revision 1.143 2003/05/13 08:13:16 jonas
  5048. * patch from Peter for rtti symbols
  5049. Revision 1.142 2003/05/11 21:37:03 peter
  5050. * moved implicit exception frame from ncgutil to psub
  5051. * constructor/destructor helpers moved from cobj/ncgutil to psub
  5052. Revision 1.141 2003/05/09 17:47:03 peter
  5053. * self moved to hidden parameter
  5054. * removed hdisposen,hnewn,selfn
  5055. Revision 1.140 2003/05/05 14:53:16 peter
  5056. * vs_hidden replaced by is_hidden boolean
  5057. Revision 1.139 2003/05/01 07:59:43 florian
  5058. * introduced defaultordconsttype to decribe the default size of ordinal constants
  5059. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  5060. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  5061. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  5062. Revision 1.138 2003/04/27 11:21:34 peter
  5063. * aktprocdef renamed to current_procdef
  5064. * procinfo renamed to current_procinfo
  5065. * procinfo will now be stored in current_module so it can be
  5066. cleaned up properly
  5067. * gen_main_procsym changed to create_main_proc and release_main_proc
  5068. to also generate a tprocinfo structure
  5069. * fixed unit implicit initfinal
  5070. Revision 1.137 2003/04/27 07:29:51 peter
  5071. * current_procdef cleanup, current_procdef is now always nil when parsing
  5072. a new procdef declaration
  5073. * aktprocsym removed
  5074. * lexlevel removed, use symtable.symtablelevel instead
  5075. * implicit init/final code uses the normal genentry/genexit
  5076. * funcret state checking updated for new funcret handling
  5077. Revision 1.136 2003/04/25 20:59:35 peter
  5078. * removed funcretn,funcretsym, function result is now in varsym
  5079. and aliases for result and function name are added using absolutesym
  5080. * vs_hidden parameter for funcret passed in parameter
  5081. * vs_hidden fixes
  5082. * writenode changed to printnode and released from extdebug
  5083. * -vp option added to generate a tree.log with the nodetree
  5084. * nicer printnode for statements, callnode
  5085. Revision 1.135 2003/04/23 20:16:04 peter
  5086. + added currency support based on int64
  5087. + is_64bit for use in cg units instead of is_64bitint
  5088. * removed cgmessage from n386add, replace with internalerrors
  5089. Revision 1.134 2003/04/23 12:35:34 florian
  5090. * fixed several issues with powerpc
  5091. + applied a patch from Jonas for nested function calls (PowerPC only)
  5092. * ...
  5093. Revision 1.133 2003/04/10 17:57:53 peter
  5094. * vs_hidden released
  5095. Revision 1.132 2003/03/18 16:25:50 peter
  5096. * no itnernalerror for errordef.concatstabto()
  5097. Revision 1.131 2003/03/17 16:54:41 peter
  5098. * support DefaultHandler and anonymous inheritance fixed
  5099. for message methods
  5100. Revision 1.130 2003/03/17 15:54:22 peter
  5101. * store symoptions also for procdef
  5102. * check symoptions (private,public) when calculating possible
  5103. overload candidates
  5104. Revision 1.129 2003/02/19 22:00:14 daniel
  5105. * Code generator converted to new register notation
  5106. - Horribily outdated todo.txt removed
  5107. Revision 1.128 2003/02/02 19:25:54 carl
  5108. * Several bugfixes for m68k target (register alloc., opcode emission)
  5109. + VIS target
  5110. + Generic add more complete (still not verified)
  5111. Revision 1.127 2003/01/21 14:36:44 pierre
  5112. * set sizes needs to be passes in bits not bytes to stabs info
  5113. Revision 1.126 2003/01/16 22:11:33 peter
  5114. * fixed tprocdef.is_addressonly
  5115. Revision 1.125 2003/01/15 01:44:33 peter
  5116. * merged methodpointer fixes from 1.0.x
  5117. Revision 1.124 2003/01/09 21:52:37 peter
  5118. * merged some verbosity options.
  5119. * V_LineInfo is a verbosity flag to include line info
  5120. Revision 1.123 2003/01/06 21:16:52 peter
  5121. * po_addressonly added to retrieve the address of a methodpointer
  5122. only, this is used for @tclass.method which has no self pointer
  5123. Revision 1.122 2003/01/05 15:54:15 florian
  5124. + added proper support of type = type <type>; for simple types
  5125. Revision 1.121 2003/01/05 13:36:53 florian
  5126. * x86-64 compiles
  5127. + very basic support for float128 type (x86-64 only)
  5128. Revision 1.120 2003/01/02 19:49:00 peter
  5129. * update self parameter only for methodpointer and methods
  5130. Revision 1.119 2002/12/29 18:25:59 peter
  5131. * tprocdef.gettypename implemented
  5132. Revision 1.118 2002/12/27 15:23:09 peter
  5133. * write class methods in fullname
  5134. Revision 1.117 2002/12/15 19:34:31 florian
  5135. + some front end stuff for vs_hidden added
  5136. Revision 1.116 2002/12/15 11:26:02 peter
  5137. * ignore vs_hidden parameters when choosing overloaded proc
  5138. Revision 1.115 2002/12/07 14:27:09 carl
  5139. * 3% memory optimization
  5140. * changed some types
  5141. + added type checking with different size for call node and for
  5142. parameters
  5143. Revision 1.114 2002/12/01 22:05:27 carl
  5144. * no more warnings for structures over 32K since this is
  5145. handled correctly in this version of the compiler.
  5146. Revision 1.113 2002/11/27 20:04:09 peter
  5147. * tvarsym.get_push_size replaced by paramanager.push_size
  5148. Revision 1.112 2002/11/25 21:05:53 carl
  5149. * several mistakes fixed in message files
  5150. Revision 1.111 2002/11/25 18:43:33 carl
  5151. - removed the invalid if <> checking (Delphi is strange on this)
  5152. + implemented abstract warning on instance creation of class with
  5153. abstract methods.
  5154. * some error message cleanups
  5155. Revision 1.110 2002/11/25 17:43:24 peter
  5156. * splitted defbase in defutil,symutil,defcmp
  5157. * merged isconvertable and is_equal into compare_defs(_ext)
  5158. * made operator search faster by walking the list only once
  5159. Revision 1.109 2002/11/23 22:50:06 carl
  5160. * some small speed optimizations
  5161. + added several new warnings/hints
  5162. Revision 1.108 2002/11/22 22:48:10 carl
  5163. * memory optimization with tconstsym (1.5%)
  5164. Revision 1.107 2002/11/19 16:21:29 pierre
  5165. * correct several stabs generation problems
  5166. Revision 1.106 2002/11/18 17:31:59 peter
  5167. * pass proccalloption to ret_in_xxx and push_xxx functions
  5168. Revision 1.105 2002/11/17 16:31:57 carl
  5169. * memory optimization (3-4%) : cleanup of tai fields,
  5170. cleanup of tdef and tsym fields.
  5171. * make it work for m68k
  5172. Revision 1.104 2002/11/16 19:53:18 carl
  5173. * avoid Range check errors
  5174. Revision 1.103 2002/11/15 16:29:09 peter
  5175. * fixed rtti for int64 (merged)
  5176. Revision 1.102 2002/11/15 01:58:54 peter
  5177. * merged changes from 1.0.7 up to 04-11
  5178. - -V option for generating bug report tracing
  5179. - more tracing for option parsing
  5180. - errors for cdecl and high()
  5181. - win32 import stabs
  5182. - win32 records<=8 are returned in eax:edx (turned off by default)
  5183. - heaptrc update
  5184. - more info for temp management in .s file with EXTDEBUG
  5185. Revision 1.101 2002/11/09 15:31:02 carl
  5186. + align RTTI tables
  5187. Revision 1.100 2002/10/19 15:09:25 peter
  5188. + tobjectdef.members_need_inittable that is used to generate only the
  5189. inittable when it is really used. This saves a lot of useless calls
  5190. to fpc_finalize when destroying classes
  5191. Revision 1.99 2002/10/07 21:30:27 peter
  5192. * removed obsolete rangecheck stuff
  5193. Revision 1.98 2002/10/05 15:14:26 peter
  5194. * getparamangeldname for errordef
  5195. Revision 1.97 2002/10/05 12:43:28 carl
  5196. * fixes for Delphi 6 compilation
  5197. (warning : Some features do not work under Delphi)
  5198. Revision 1.96 2002/09/27 21:13:29 carl
  5199. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  5200. Revision 1.95 2002/09/16 09:31:10 florian
  5201. * fixed currency size
  5202. Revision 1.94 2002/09/09 17:34:15 peter
  5203. * tdicationary.replace added to replace and item in a dictionary. This
  5204. is only allowed for the same name
  5205. * varsyms are inserted in symtable before the types are parsed. This
  5206. fixes the long standing "var longint : longint" bug
  5207. - consume_idlist and idstringlist removed. The loops are inserted
  5208. at the callers place and uses the symtable for duplicate id checking
  5209. Revision 1.93 2002/09/07 15:25:07 peter
  5210. * old logs removed and tabs fixed
  5211. Revision 1.92 2002/09/05 19:29:42 peter
  5212. * memdebug enhancements
  5213. Revision 1.91 2002/08/25 19:25:20 peter
  5214. * sym.insert_in_data removed
  5215. * symtable.insertvardata/insertconstdata added
  5216. * removed insert_in_data call from symtable.insert, it needs to be
  5217. called separatly. This allows to deref the address calculation
  5218. * procedures now calculate the parast addresses after the procedure
  5219. directives are parsed. This fixes the cdecl parast problem
  5220. * push_addr_param has an extra argument that specifies if cdecl is used
  5221. or not
  5222. Revision 1.90 2002/08/18 20:06:25 peter
  5223. * inlining is now also allowed in interface
  5224. * renamed write/load to ppuwrite/ppuload
  5225. * tnode storing in ppu
  5226. * nld,ncon,nbas are already updated for storing in ppu
  5227. Revision 1.89 2002/08/11 15:28:00 florian
  5228. + support of explicit type case <any ordinal type>->pointer
  5229. (delphi mode only)
  5230. Revision 1.88 2002/08/11 14:32:28 peter
  5231. * renamed current_library to objectlibrary
  5232. Revision 1.87 2002/08/11 13:24:13 peter
  5233. * saving of asmsymbols in ppu supported
  5234. * asmsymbollist global is removed and moved into a new class
  5235. tasmlibrarydata that will hold the info of a .a file which
  5236. corresponds with a single module. Added librarydata to tmodule
  5237. to keep the library info stored for the module. In the future the
  5238. objectfiles will also be stored to the tasmlibrarydata class
  5239. * all getlabel/newasmsymbol and friends are moved to the new class
  5240. Revision 1.86 2002/08/09 07:33:03 florian
  5241. * a couple of interface related fixes
  5242. Revision 1.85 2002/07/23 09:51:24 daniel
  5243. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  5244. are worth comitting.
  5245. Revision 1.84 2002/07/20 11:57:57 florian
  5246. * types.pas renamed to defbase.pas because D6 contains a types
  5247. unit so this would conflicts if D6 programms are compiled
  5248. + Willamette/SSE2 instructions to assembler added
  5249. Revision 1.83 2002/07/11 14:41:30 florian
  5250. * start of the new generic parameter handling
  5251. Revision 1.82 2002/07/07 09:52:32 florian
  5252. * powerpc target fixed, very simple units can be compiled
  5253. * some basic stuff for better callparanode handling, far from being finished
  5254. Revision 1.81 2002/07/01 18:46:26 peter
  5255. * internal linker
  5256. * reorganized aasm layer
  5257. Revision 1.80 2002/07/01 16:23:54 peter
  5258. * cg64 patch
  5259. * basics for currency
  5260. * asnode updates for class and interface (not finished)
  5261. Revision 1.79 2002/05/18 13:34:18 peter
  5262. * readded missing revisions
  5263. Revision 1.78 2002/05/16 19:46:44 carl
  5264. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  5265. + try to fix temp allocation (still in ifdef)
  5266. + generic constructor calls
  5267. + start of tassembler / tmodulebase class cleanup
  5268. Revision 1.76 2002/05/12 16:53:10 peter
  5269. * moved entry and exitcode to ncgutil and cgobj
  5270. * foreach gets extra argument for passing local data to the
  5271. iterator function
  5272. * -CR checks also class typecasts at runtime by changing them
  5273. into as
  5274. * fixed compiler to cycle with the -CR option
  5275. * fixed stabs with elf writer, finally the global variables can
  5276. be watched
  5277. * removed a lot of routines from cga unit and replaced them by
  5278. calls to cgobj
  5279. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  5280. u32bit then the other is typecasted also to u32bit without giving
  5281. a rangecheck warning/error.
  5282. * fixed pascal calling method with reversing also the high tree in
  5283. the parast, detected by tcalcst3 test
  5284. Revision 1.75 2002/04/25 20:16:39 peter
  5285. * moved more routines from cga/n386util
  5286. Revision 1.74 2002/04/23 19:16:35 peter
  5287. * add pinline unit that inserts compiler supported functions using
  5288. one or more statements
  5289. * moved finalize and setlength from ninl to pinline
  5290. Revision 1.73 2002/04/21 19:02:05 peter
  5291. * removed newn and disposen nodes, the code is now directly
  5292. inlined from pexpr
  5293. * -an option that will write the secondpass nodes to the .s file, this
  5294. requires EXTDEBUG define to actually write the info
  5295. * fixed various internal errors and crashes due recent code changes
  5296. Revision 1.72 2002/04/20 21:32:25 carl
  5297. + generic FPC_CHECKPOINTER
  5298. + first parameter offset in stack now portable
  5299. * rename some constants
  5300. + move some cpu stuff to other units
  5301. - remove unused constents
  5302. * fix stacksize for some targets
  5303. * fix generic size problems which depend now on EXTEND_SIZE constant
  5304. }