symdef.pas 185 KB

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