symdef.pas 189 KB

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