symdef.pas 189 KB

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