symdef.pas 209 KB

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