symdef.pas 209 KB

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