symdef.pas 184 KB

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