symdef.pas 195 KB

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