symdef.pas 199 KB

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