symdef.pas 189 KB

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