symdef.pas 186 KB

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