symdef.pas 209 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752
  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. if po_explicitparaloc in procoptions then
  2968. begin
  2969. if po_explicitparaloc in procoptions then
  2970. ppufile.getdata(hp.paraloc,sizeof(hp.paraloc));
  2971. has_paraloc_info:=true;
  2972. end;
  2973. { Parameters are stored left to right in both ppu and memory }
  2974. Para.concat(hp);
  2975. end;
  2976. end;
  2977. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2978. var
  2979. hp : TParaItem;
  2980. oldintfcrc : boolean;
  2981. begin
  2982. { released procdef? }
  2983. if not assigned(parast) then
  2984. exit;
  2985. inherited ppuwritedef(ppufile);
  2986. ppufile.puttype(rettype);
  2987. oldintfcrc:=ppufile.do_interface_crc;
  2988. ppufile.do_interface_crc:=false;
  2989. {$ifdef i386}
  2990. if simplify_ppu then
  2991. fpu_used:=0;
  2992. ppufile.putbyte(fpu_used);
  2993. {$else}
  2994. ppufile.putbyte(0);
  2995. {$endif}
  2996. ppufile.putbyte(ord(proctypeoption));
  2997. ppufile.putbyte(ord(proccalloption));
  2998. ppufile.putsmallset(procoptions);
  2999. ppufile.do_interface_crc:=oldintfcrc;
  3000. { we need to store the count including vs_hidden }
  3001. ppufile.putbyte(para.count);
  3002. hp:=TParaItem(Para.first);
  3003. while assigned(hp) do
  3004. begin
  3005. ppufile.putbyte(byte(hp.paratyp));
  3006. ppufile.puttype(hp.paratype);
  3007. ppufile.putderef(hp.defaultvaluederef);
  3008. ppufile.putderef(hp.parasymderef);
  3009. ppufile.putbyte(byte(hp.is_hidden));
  3010. if po_explicitparaloc in procoptions then
  3011. ppufile.putdata(hp.paraloc,sizeof(hp.paraloc));
  3012. hp:=TParaItem(hp.next);
  3013. end;
  3014. end;
  3015. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  3016. var
  3017. hs,s : string;
  3018. hp : TParaItem;
  3019. hpc : tconstsym;
  3020. first : boolean;
  3021. begin
  3022. hp:=TParaItem(Para.first);
  3023. s:='';
  3024. first:=true;
  3025. while assigned(hp) do
  3026. begin
  3027. if (not hp.is_hidden) or
  3028. (showhidden) then
  3029. begin
  3030. if first then
  3031. begin
  3032. s:=s+'(';
  3033. first:=false;
  3034. end
  3035. else
  3036. s:=s+',';
  3037. case hp.paratyp of
  3038. vs_var :
  3039. s:=s+'var';
  3040. vs_const :
  3041. s:=s+'const';
  3042. vs_out :
  3043. s:=s+'out';
  3044. end;
  3045. if assigned(hp.paratype.def.typesym) then
  3046. begin
  3047. if s<>'(' then
  3048. s:=s+' ';
  3049. hs:=hp.paratype.def.typesym.realname;
  3050. if hs[1]<>'$' then
  3051. s:=s+hp.paratype.def.typesym.realname
  3052. else
  3053. s:=s+hp.paratype.def.gettypename;
  3054. end
  3055. else
  3056. s:=s+hp.paratype.def.gettypename;
  3057. { default value }
  3058. if assigned(hp.defaultvalue) then
  3059. begin
  3060. hpc:=tconstsym(hp.defaultvalue);
  3061. hs:='';
  3062. case hpc.consttyp of
  3063. conststring,
  3064. constresourcestring :
  3065. hs:=strpas(pchar(hpc.value.valueptr));
  3066. constreal :
  3067. str(pbestreal(hpc.value.valueptr)^,hs);
  3068. constpointer :
  3069. hs:=tostr(hpc.value.valueordptr);
  3070. constord :
  3071. begin
  3072. if is_boolean(hpc.consttype.def) then
  3073. begin
  3074. if hpc.value.valueord<>0 then
  3075. hs:='TRUE'
  3076. else
  3077. hs:='FALSE';
  3078. end
  3079. else
  3080. hs:=tostr(hpc.value.valueord);
  3081. end;
  3082. constnil :
  3083. hs:='nil';
  3084. constset :
  3085. hs:='<set>';
  3086. end;
  3087. if hs<>'' then
  3088. s:=s+'="'+hs+'"';
  3089. end;
  3090. end;
  3091. hp:=TParaItem(hp.next);
  3092. end;
  3093. if not first then
  3094. s:=s+')';
  3095. if (po_varargs in procoptions) then
  3096. s:=s+';VarArgs';
  3097. typename_paras:=s;
  3098. end;
  3099. function tabstractprocdef.is_methodpointer:boolean;
  3100. begin
  3101. result:=false;
  3102. end;
  3103. function tabstractprocdef.is_addressonly:boolean;
  3104. begin
  3105. result:=true;
  3106. end;
  3107. {$ifdef GDB}
  3108. function tabstractprocdef.stabstring : pchar;
  3109. begin
  3110. stabstring := strpnew('abstractproc'+numberstring+';');
  3111. end;
  3112. {$endif GDB}
  3113. {***************************************************************************
  3114. TPROCDEF
  3115. ***************************************************************************}
  3116. constructor tprocdef.create(level:byte);
  3117. begin
  3118. inherited create(level);
  3119. deftype:=procdef;
  3120. has_mangledname:=false;
  3121. _mangledname:=nil;
  3122. fileinfo:=aktfilepos;
  3123. extnumber:=$ffff;
  3124. aliasnames:=tstringlist.create;
  3125. funcretsym:=nil;
  3126. localst := nil;
  3127. defref:=nil;
  3128. lastwritten:=nil;
  3129. refcount:=0;
  3130. if (cs_browser in aktmoduleswitches) and make_ref then
  3131. begin
  3132. defref:=tref.create(defref,@akttokenpos);
  3133. inc(refcount);
  3134. end;
  3135. lastref:=defref;
  3136. forwarddef:=true;
  3137. interfacedef:=false;
  3138. hasforward:=false;
  3139. _class := nil;
  3140. new(inlininginfo);
  3141. fillchar(inlininginfo^,sizeof(tinlininginfo),0);
  3142. overloadnumber:=0;
  3143. {$ifdef GDB}
  3144. isstabwritten := false;
  3145. {$endif GDB}
  3146. end;
  3147. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  3148. var
  3149. level : byte;
  3150. begin
  3151. inherited ppuload(ppufile);
  3152. deftype:=procdef;
  3153. has_mangledname:=boolean(ppufile.getbyte);
  3154. if has_mangledname then
  3155. _mangledname:=stringdup(ppufile.getstring)
  3156. else
  3157. _mangledname:=nil;
  3158. overloadnumber:=ppufile.getword;
  3159. extnumber:=ppufile.getword;
  3160. level:=ppufile.getbyte;
  3161. ppufile.getderef(_classderef);
  3162. ppufile.getderef(procsymderef);
  3163. ppufile.getposinfo(fileinfo);
  3164. ppufile.getsmallset(symoptions);
  3165. { inline stuff }
  3166. if proccalloption=pocall_inline then
  3167. begin
  3168. ppufile.getderef(funcretsymderef);
  3169. new(inlininginfo);
  3170. ppufile.getsmallset(inlininginfo^.flags);
  3171. end
  3172. else
  3173. funcretsym:=nil;
  3174. { load para symtable }
  3175. parast:=tparasymtable.create(level);
  3176. tparasymtable(parast).ppuload(ppufile);
  3177. parast.defowner:=self;
  3178. { load local symtable }
  3179. if (proccalloption=pocall_inline) or
  3180. ((current_module.flags and uf_local_browser)<>0) then
  3181. begin
  3182. localst:=tlocalsymtable.create(level);
  3183. tlocalsymtable(localst).ppuload(ppufile);
  3184. localst.defowner:=self;
  3185. end
  3186. else
  3187. localst:=nil;
  3188. { inline stuff }
  3189. if proccalloption=pocall_inline then
  3190. inlininginfo^.code:=ppuloadnodetree(ppufile)
  3191. else
  3192. inlininginfo := nil;
  3193. { default values for no persistent data }
  3194. if (cs_link_deffile in aktglobalswitches) and
  3195. (tf_need_export in target_info.flags) and
  3196. (po_exports in procoptions) then
  3197. deffile.AddExport(mangledname);
  3198. aliasnames:=tstringlist.create;
  3199. forwarddef:=false;
  3200. interfacedef:=false;
  3201. hasforward:=false;
  3202. lastref:=nil;
  3203. lastwritten:=nil;
  3204. defref:=nil;
  3205. refcount:=0;
  3206. {$ifdef GDB}
  3207. isstabwritten := false;
  3208. {$endif GDB}
  3209. end;
  3210. destructor tprocdef.destroy;
  3211. begin
  3212. if assigned(defref) then
  3213. begin
  3214. defref.freechain;
  3215. defref.free;
  3216. end;
  3217. aliasnames.free;
  3218. if assigned(localst) and (localst.symtabletype<>staticsymtable) then
  3219. begin
  3220. {$ifdef MEMDEBUG}
  3221. memproclocalst.start;
  3222. {$endif MEMDEBUG}
  3223. localst.free;
  3224. {$ifdef MEMDEBUG}
  3225. memproclocalst.start;
  3226. {$endif MEMDEBUG}
  3227. end;
  3228. if (proccalloption=pocall_inline) and assigned(inlininginfo) then
  3229. begin
  3230. {$ifdef MEMDEBUG}
  3231. memprocnodetree.start;
  3232. {$endif MEMDEBUG}
  3233. tnode(inlininginfo^.code).free;
  3234. {$ifdef MEMDEBUG}
  3235. memprocnodetree.start;
  3236. {$endif MEMDEBUG}
  3237. end;
  3238. if assigned(inlininginfo) then
  3239. dispose(inlininginfo);
  3240. if (po_msgstr in procoptions) then
  3241. strdispose(messageinf.str);
  3242. if assigned(_mangledname) then
  3243. begin
  3244. {$ifdef MEMDEBUG}
  3245. memmanglednames.start;
  3246. {$endif MEMDEBUG}
  3247. stringdispose(_mangledname);
  3248. {$ifdef MEMDEBUG}
  3249. memmanglednames.stop;
  3250. {$endif MEMDEBUG}
  3251. end;
  3252. inherited destroy;
  3253. end;
  3254. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  3255. var
  3256. oldintfcrc : boolean;
  3257. oldparasymtable,
  3258. oldlocalsymtable : tsymtable;
  3259. begin
  3260. { released procdef? }
  3261. if not assigned(parast) then
  3262. exit;
  3263. oldparasymtable:=aktparasymtable;
  3264. oldlocalsymtable:=aktlocalsymtable;
  3265. aktparasymtable:=parast;
  3266. aktlocalsymtable:=localst;
  3267. inherited ppuwrite(ppufile);
  3268. oldintfcrc:=ppufile.do_interface_crc;
  3269. ppufile.do_interface_crc:=false;
  3270. ppufile.do_interface_crc:=oldintfcrc;
  3271. ppufile.putbyte(byte(has_mangledname));
  3272. if has_mangledname then
  3273. ppufile.putstring(_mangledname^);
  3274. ppufile.putword(overloadnumber);
  3275. ppufile.putword(extnumber);
  3276. ppufile.putbyte(parast.symtablelevel);
  3277. ppufile.putderef(_classderef);
  3278. ppufile.putderef(procsymderef);
  3279. ppufile.putposinfo(fileinfo);
  3280. ppufile.putsmallset(symoptions);
  3281. { inline stuff }
  3282. oldintfcrc:=ppufile.do_crc;
  3283. ppufile.do_crc:=false;
  3284. if proccalloption=pocall_inline then
  3285. begin
  3286. ppufile.putderef(funcretsymderef);
  3287. ppufile.putsmallset(inlininginfo^.flags);
  3288. end;
  3289. ppufile.do_crc:=oldintfcrc;
  3290. { write this entry }
  3291. ppufile.writeentry(ibprocdef);
  3292. { Save the para symtable, this is taken from the interface }
  3293. tparasymtable(parast).ppuwrite(ppufile);
  3294. { save localsymtable for inline procedures or when local
  3295. browser info is requested, this has no influence on the crc }
  3296. if (proccalloption=pocall_inline) or
  3297. ((current_module.flags and uf_local_browser)<>0) then
  3298. begin
  3299. oldintfcrc:=ppufile.do_crc;
  3300. ppufile.do_crc:=false;
  3301. if not assigned(localst) then
  3302. insert_localst;
  3303. tlocalsymtable(localst).ppuwrite(ppufile);
  3304. ppufile.do_crc:=oldintfcrc;
  3305. end;
  3306. { node tree for inlining }
  3307. oldintfcrc:=ppufile.do_crc;
  3308. ppufile.do_crc:=false;
  3309. if proccalloption=pocall_inline then
  3310. ppuwritenodetree(ppufile,inlininginfo^.code);
  3311. ppufile.do_crc:=oldintfcrc;
  3312. aktparasymtable:=oldparasymtable;
  3313. aktlocalsymtable:=oldlocalsymtable;
  3314. end;
  3315. procedure tprocdef.insert_localst;
  3316. begin
  3317. localst:=tlocalsymtable.create(parast.symtablelevel);
  3318. localst.defowner:=self;
  3319. { this is used by insert
  3320. to check same names in parast and localst }
  3321. localst.next:=parast;
  3322. end;
  3323. function tprocdef.fullprocname(showhidden:boolean):string;
  3324. var
  3325. s : string;
  3326. t : ttoken;
  3327. begin
  3328. {$ifdef EXTDEBUG}
  3329. showhidden:=true;
  3330. {$endif EXTDEBUG}
  3331. s:='';
  3332. if assigned(_class) then
  3333. begin
  3334. if po_classmethod in procoptions then
  3335. s:=s+'class ';
  3336. s:=s+_class.objrealname^+'.';
  3337. end;
  3338. if proctypeoption=potype_operator then
  3339. begin
  3340. for t:=NOTOKEN to last_overloaded do
  3341. if procsym.realname='$'+overloaded_names[t] then
  3342. begin
  3343. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  3344. break;
  3345. end;
  3346. end
  3347. else
  3348. s:=s+procsym.realname+typename_paras(showhidden);
  3349. case proctypeoption of
  3350. potype_constructor:
  3351. s:='constructor '+s;
  3352. potype_destructor:
  3353. s:='destructor '+s;
  3354. else
  3355. if assigned(rettype.def) and
  3356. not(is_void(rettype.def)) then
  3357. s:=s+':'+rettype.def.gettypename;
  3358. end;
  3359. { forced calling convention? }
  3360. if (po_hascallingconvention in procoptions) then
  3361. s:=s+';'+ProcCallOptionStr[proccalloption];
  3362. fullprocname:=s;
  3363. end;
  3364. function tprocdef.is_methodpointer:boolean;
  3365. begin
  3366. result:=assigned(_class);
  3367. end;
  3368. function tprocdef.is_addressonly:boolean;
  3369. begin
  3370. result:=assigned(owner) and
  3371. (owner.symtabletype<>objectsymtable);
  3372. end;
  3373. function tprocdef.is_visible_for_object(currobjdef:tobjectdef):boolean;
  3374. begin
  3375. is_visible_for_object:=false;
  3376. { private symbols are allowed when we are in the same
  3377. module as they are defined }
  3378. if (sp_private in symoptions) and
  3379. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3380. (owner.defowner.owner.unitid<>0) then
  3381. exit;
  3382. { protected symbols are vissible in the module that defines them and
  3383. also visible to related objects. The related object must be defined
  3384. in the current module }
  3385. if (sp_protected in symoptions) and
  3386. (
  3387. (
  3388. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  3389. (owner.defowner.owner.unitid<>0)
  3390. ) and
  3391. not(
  3392. assigned(currobjdef) and
  3393. (currobjdef.owner.unitid=0) and
  3394. currobjdef.is_related(tobjectdef(owner.defowner))
  3395. )
  3396. ) then
  3397. exit;
  3398. is_visible_for_object:=true;
  3399. end;
  3400. function tprocdef.getsymtable(t:tgetsymtable):tsymtable;
  3401. begin
  3402. case t of
  3403. gs_local :
  3404. getsymtable:=localst;
  3405. gs_para :
  3406. getsymtable:=parast;
  3407. else
  3408. getsymtable:=nil;
  3409. end;
  3410. end;
  3411. procedure tprocdef.load_references(ppufile:tcompilerppufile;locals:boolean);
  3412. var
  3413. pos : tfileposinfo;
  3414. move_last : boolean;
  3415. oldparasymtable,
  3416. oldlocalsymtable : tsymtable;
  3417. begin
  3418. oldparasymtable:=aktparasymtable;
  3419. oldlocalsymtable:=aktlocalsymtable;
  3420. aktparasymtable:=parast;
  3421. aktlocalsymtable:=localst;
  3422. move_last:=lastwritten=lastref;
  3423. while (not ppufile.endofentry) do
  3424. begin
  3425. ppufile.getposinfo(pos);
  3426. inc(refcount);
  3427. lastref:=tref.create(lastref,@pos);
  3428. lastref.is_written:=true;
  3429. if refcount=1 then
  3430. defref:=lastref;
  3431. end;
  3432. if move_last then
  3433. lastwritten:=lastref;
  3434. if ((current_module.flags and uf_local_browser)<>0) and
  3435. locals then
  3436. begin
  3437. tparasymtable(parast).load_references(ppufile,locals);
  3438. tlocalsymtable(localst).load_references(ppufile,locals);
  3439. end;
  3440. aktparasymtable:=oldparasymtable;
  3441. aktlocalsymtable:=oldlocalsymtable;
  3442. end;
  3443. Const
  3444. local_symtable_index : word = $8001;
  3445. function tprocdef.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  3446. var
  3447. ref : tref;
  3448. pdo : tobjectdef;
  3449. move_last : boolean;
  3450. d : tderef;
  3451. oldparasymtable,
  3452. oldlocalsymtable : tsymtable;
  3453. begin
  3454. d.reset;
  3455. move_last:=lastwritten=lastref;
  3456. if move_last and
  3457. (((current_module.flags and uf_local_browser)=0) or
  3458. not locals) then
  3459. exit;
  3460. oldparasymtable:=aktparasymtable;
  3461. oldlocalsymtable:=aktlocalsymtable;
  3462. aktparasymtable:=parast;
  3463. aktlocalsymtable:=localst;
  3464. { write address of this symbol }
  3465. d.build(self);
  3466. ppufile.putderef(d);
  3467. { write refs }
  3468. if assigned(lastwritten) then
  3469. ref:=lastwritten
  3470. else
  3471. ref:=defref;
  3472. while assigned(ref) do
  3473. begin
  3474. if ref.moduleindex=current_module.unit_index then
  3475. begin
  3476. ppufile.putposinfo(ref.posinfo);
  3477. ref.is_written:=true;
  3478. if move_last then
  3479. lastwritten:=ref;
  3480. end
  3481. else if not ref.is_written then
  3482. move_last:=false
  3483. else if move_last then
  3484. lastwritten:=ref;
  3485. ref:=ref.nextref;
  3486. end;
  3487. ppufile.writeentry(ibdefref);
  3488. write_references:=true;
  3489. if ((current_module.flags and uf_local_browser)<>0) and
  3490. locals then
  3491. begin
  3492. pdo:=_class;
  3493. if (owner.symtabletype<>localsymtable) then
  3494. while assigned(pdo) do
  3495. begin
  3496. if pdo.symtable<>aktrecordsymtable then
  3497. begin
  3498. pdo.symtable.unitid:=local_symtable_index;
  3499. inc(local_symtable_index);
  3500. end;
  3501. pdo:=pdo.childof;
  3502. end;
  3503. parast.unitid:=local_symtable_index;
  3504. inc(local_symtable_index);
  3505. localst.unitid:=local_symtable_index;
  3506. inc(local_symtable_index);
  3507. tstoredsymtable(parast).write_references(ppufile,locals);
  3508. tstoredsymtable(localst).write_references(ppufile,locals);
  3509. { decrement for }
  3510. local_symtable_index:=local_symtable_index-2;
  3511. pdo:=_class;
  3512. if (owner.symtabletype<>localsymtable) then
  3513. while assigned(pdo) do
  3514. begin
  3515. if pdo.symtable<>aktrecordsymtable then
  3516. dec(local_symtable_index);
  3517. pdo:=pdo.childof;
  3518. end;
  3519. end;
  3520. aktparasymtable:=oldparasymtable;
  3521. aktlocalsymtable:=oldlocalsymtable;
  3522. end;
  3523. {$ifdef GDB}
  3524. function tprocdef.numberstring : string;
  3525. begin
  3526. { procdefs are always available }
  3527. stab_state:=stab_state_written;
  3528. result:=inherited numberstring;
  3529. end;
  3530. function tprocdef.stabstring: pchar;
  3531. Var
  3532. RType : Char;
  3533. Obj,Info : String;
  3534. stabsstr : string;
  3535. p : pchar;
  3536. begin
  3537. obj := procsym.name;
  3538. info := '';
  3539. if tprocsym(procsym).is_global then
  3540. RType := 'F'
  3541. else
  3542. RType := 'f';
  3543. if assigned(owner) then
  3544. begin
  3545. if (owner.symtabletype = objectsymtable) then
  3546. obj := owner.name^+'__'+procsym.name;
  3547. if not(cs_gdb_valgrind in aktglobalswitches) and
  3548. (owner.symtabletype=localsymtable) and
  3549. assigned(owner.defowner) and
  3550. assigned(tprocdef(owner.defowner).procsym) then
  3551. info := ','+procsym.name+','+tprocdef(owner.defowner).procsym.name;
  3552. end;
  3553. stabsstr:=mangledname;
  3554. getmem(p,length(stabsstr)+255);
  3555. strpcopy(p,'"'+obj+':'+RType
  3556. +tstoreddef(rettype.def).numberstring+info+'",'+tostr(n_function)
  3557. +',0,'+
  3558. tostr(fileinfo.line)
  3559. +',');
  3560. strpcopy(strend(p),stabsstr);
  3561. stabstring:=strnew(p);
  3562. freemem(p,length(stabsstr)+255);
  3563. end;
  3564. procedure tprocdef.concatstabto(asmlist : taasmoutput);
  3565. begin
  3566. { released procdef? }
  3567. if not assigned(parast) then
  3568. exit;
  3569. if (proccalloption=pocall_internproc) then
  3570. exit;
  3571. { be sure to have a number assigned for this def }
  3572. numberstring;
  3573. { write stabs }
  3574. stab_state:=stab_state_writing;
  3575. asmList.concat(Tai_stabs.Create(stabstring));
  3576. if not(po_external in procoptions) then
  3577. begin
  3578. tstoredsymtable(parast).concatstabto(asmlist);
  3579. { local type defs and vars should not be written
  3580. inside the main proc stab }
  3581. if assigned(localst) and
  3582. (localst.symtablelevel>main_program_level) then
  3583. tstoredsymtable(localst).concatstabto(asmlist);
  3584. end;
  3585. stab_state:=stab_state_written;
  3586. end;
  3587. {$endif GDB}
  3588. procedure tprocdef.buildderef;
  3589. var
  3590. oldparasymtable,
  3591. oldlocalsymtable : tsymtable;
  3592. begin
  3593. oldparasymtable:=aktparasymtable;
  3594. oldlocalsymtable:=aktlocalsymtable;
  3595. aktparasymtable:=parast;
  3596. aktlocalsymtable:=localst;
  3597. inherited buildderef;
  3598. _classderef.build(_class);
  3599. { procsym that originaly defined this definition, should be in the
  3600. same symtable }
  3601. procsymderef.build(procsym);
  3602. aktparasymtable:=oldparasymtable;
  3603. aktlocalsymtable:=oldlocalsymtable;
  3604. end;
  3605. procedure tprocdef.buildderefimpl;
  3606. var
  3607. oldparasymtable,
  3608. oldlocalsymtable : tsymtable;
  3609. begin
  3610. { released procdef? }
  3611. if not assigned(parast) then
  3612. exit;
  3613. oldparasymtable:=aktparasymtable;
  3614. oldlocalsymtable:=aktlocalsymtable;
  3615. aktparasymtable:=parast;
  3616. aktlocalsymtable:=localst;
  3617. inherited buildderefimpl;
  3618. { locals }
  3619. if assigned(localst) then
  3620. begin
  3621. tlocalsymtable(localst).buildderef;
  3622. tlocalsymtable(localst).buildderefimpl;
  3623. funcretsymderef.build(funcretsym);
  3624. end;
  3625. { inline tree }
  3626. if (proccalloption=pocall_inline) then
  3627. inlininginfo^.code.buildderefimpl;
  3628. aktparasymtable:=oldparasymtable;
  3629. aktlocalsymtable:=oldlocalsymtable;
  3630. end;
  3631. procedure tprocdef.deref;
  3632. var
  3633. oldparasymtable,
  3634. oldlocalsymtable : tsymtable;
  3635. begin
  3636. { released procdef? }
  3637. if not assigned(parast) then
  3638. exit;
  3639. oldparasymtable:=aktparasymtable;
  3640. oldlocalsymtable:=aktlocalsymtable;
  3641. aktparasymtable:=parast;
  3642. aktlocalsymtable:=localst;
  3643. inherited deref;
  3644. _class:=tobjectdef(_classderef.resolve);
  3645. { procsym that originaly defined this definition, should be in the
  3646. same symtable }
  3647. procsym:=tprocsym(procsymderef.resolve);
  3648. aktparasymtable:=oldparasymtable;
  3649. aktlocalsymtable:=oldlocalsymtable;
  3650. end;
  3651. procedure tprocdef.derefimpl;
  3652. var
  3653. oldparasymtable,
  3654. oldlocalsymtable : tsymtable;
  3655. begin
  3656. oldparasymtable:=aktparasymtable;
  3657. oldlocalsymtable:=aktlocalsymtable;
  3658. aktparasymtable:=parast;
  3659. aktlocalsymtable:=localst;
  3660. { locals }
  3661. if assigned(localst) then
  3662. begin
  3663. { localst }
  3664. { we can deref both interface and implementation parts }
  3665. tlocalsymtable(localst).deref;
  3666. tlocalsymtable(localst).derefimpl;
  3667. { funcretsym, this is always located in the localst }
  3668. funcretsym:=tsym(funcretsymderef.resolve);
  3669. end
  3670. else
  3671. begin
  3672. { safety }
  3673. funcretsym:=nil;
  3674. end;
  3675. { inline tree }
  3676. if (proccalloption=pocall_inline) then
  3677. inlininginfo^.code.derefimpl;
  3678. aktparasymtable:=oldparasymtable;
  3679. aktlocalsymtable:=oldlocalsymtable;
  3680. end;
  3681. function tprocdef.gettypename : string;
  3682. begin
  3683. gettypename := FullProcName(false);
  3684. end;
  3685. function tprocdef.mangledname : string;
  3686. var
  3687. hp : TParaItem;
  3688. begin
  3689. if assigned(_mangledname) then
  3690. begin
  3691. {$ifdef compress}
  3692. mangledname:=minilzw_decode(_mangledname^);
  3693. {$else}
  3694. mangledname:=_mangledname^;
  3695. {$endif}
  3696. exit;
  3697. end;
  3698. { we need to use the symtable where the procsym is inserted,
  3699. because that is visible to the world }
  3700. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3701. if overloadnumber>0 then
  3702. mangledname:=mangledname+'$'+tostr(overloadnumber);
  3703. { add parameter types }
  3704. hp:=TParaItem(Para.first);
  3705. while assigned(hp) do
  3706. begin
  3707. if not hp.is_hidden then
  3708. mangledname:=mangledname+'$'+hp.paratype.def.mangledparaname;
  3709. hp:=TParaItem(hp.next);
  3710. end;
  3711. {$ifdef compress}
  3712. _mangledname:=stringdup(minilzw_encode(mangledname));
  3713. {$else}
  3714. _mangledname:=stringdup(mangledname);
  3715. {$endif}
  3716. end;
  3717. function tprocdef.cplusplusmangledname : string;
  3718. function getcppparaname(p : tdef) : string;
  3719. const
  3720. ordtype2str : array[tbasetype] of string[2] = (
  3721. '',
  3722. 'Uc','Us','Ui','Us',
  3723. 'Sc','s','i','x',
  3724. 'b','b','b',
  3725. 'c','w','x');
  3726. var
  3727. s : string;
  3728. begin
  3729. case p.deftype of
  3730. orddef:
  3731. s:=ordtype2str[torddef(p).typ];
  3732. pointerdef:
  3733. s:='P'+getcppparaname(tpointerdef(p).pointertype.def);
  3734. else
  3735. internalerror(2103001);
  3736. end;
  3737. getcppparaname:=s;
  3738. end;
  3739. var
  3740. s,s2 : string;
  3741. param : TParaItem;
  3742. begin
  3743. s := procsym.realname;
  3744. if procsym.owner.symtabletype=objectsymtable then
  3745. begin
  3746. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  3747. case proctypeoption of
  3748. potype_destructor:
  3749. s:='_$_'+tostr(length(s2))+s2;
  3750. potype_constructor:
  3751. s:='___'+tostr(length(s2))+s2;
  3752. else
  3753. s:='_'+s+'__'+tostr(length(s2))+s2;
  3754. end;
  3755. end
  3756. else s:=s+'__';
  3757. s:=s+'F';
  3758. { concat modifiers }
  3759. { !!!!! }
  3760. { now we handle the parameters }
  3761. param := TParaItem(Para.first);
  3762. if assigned(param) then
  3763. while assigned(param) do
  3764. begin
  3765. s2:=getcppparaname(param.paratype.def);
  3766. if param.paratyp in [vs_var,vs_out] then
  3767. s2:='R'+s2;
  3768. s:=s+s2;
  3769. param:=TParaItem(param.next);
  3770. end
  3771. else
  3772. s:=s+'v';
  3773. cplusplusmangledname:=s;
  3774. end;
  3775. procedure tprocdef.setmangledname(const s : string);
  3776. begin
  3777. stringdispose(_mangledname);
  3778. {$ifdef compress}
  3779. _mangledname:=stringdup(minilzw_encode(s));
  3780. {$else}
  3781. _mangledname:=stringdup(s);
  3782. {$endif}
  3783. has_mangledname:=true;
  3784. end;
  3785. {***************************************************************************
  3786. TPROCVARDEF
  3787. ***************************************************************************}
  3788. constructor tprocvardef.create(level:byte);
  3789. begin
  3790. inherited create(level);
  3791. deftype:=procvardef;
  3792. end;
  3793. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3794. begin
  3795. inherited ppuload(ppufile);
  3796. deftype:=procvardef;
  3797. { load para symtable }
  3798. parast:=tparasymtable.create(unknown_level);
  3799. tparasymtable(parast).ppuload(ppufile);
  3800. parast.defowner:=self;
  3801. end;
  3802. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3803. var
  3804. oldparasymtable,
  3805. oldlocalsymtable : tsymtable;
  3806. begin
  3807. oldparasymtable:=aktparasymtable;
  3808. oldlocalsymtable:=aktlocalsymtable;
  3809. aktparasymtable:=parast;
  3810. aktlocalsymtable:=nil;
  3811. { here we cannot get a real good value so just give something }
  3812. { plausible (PM) }
  3813. { a more secure way would be
  3814. to allways store in a temp }
  3815. {$ifdef i386}
  3816. if is_fpu(rettype.def) then
  3817. fpu_used:={2}maxfpuregs
  3818. else
  3819. fpu_used:=0;
  3820. {$endif i386}
  3821. inherited ppuwrite(ppufile);
  3822. { Write this entry }
  3823. ppufile.writeentry(ibprocvardef);
  3824. { Save the para symtable, this is taken from the interface }
  3825. tparasymtable(parast).ppuwrite(ppufile);
  3826. aktparasymtable:=oldparasymtable;
  3827. aktlocalsymtable:=oldlocalsymtable;
  3828. end;
  3829. procedure tprocvardef.buildderef;
  3830. var
  3831. oldparasymtable,
  3832. oldlocalsymtable : tsymtable;
  3833. begin
  3834. oldparasymtable:=aktparasymtable;
  3835. oldlocalsymtable:=aktlocalsymtable;
  3836. aktparasymtable:=parast;
  3837. aktlocalsymtable:=nil;
  3838. inherited buildderef;
  3839. aktparasymtable:=oldparasymtable;
  3840. aktlocalsymtable:=oldlocalsymtable;
  3841. end;
  3842. procedure tprocvardef.deref;
  3843. var
  3844. oldparasymtable,
  3845. oldlocalsymtable : tsymtable;
  3846. begin
  3847. oldparasymtable:=aktparasymtable;
  3848. oldlocalsymtable:=aktlocalsymtable;
  3849. aktparasymtable:=parast;
  3850. aktlocalsymtable:=nil;
  3851. inherited deref;
  3852. aktparasymtable:=oldparasymtable;
  3853. aktlocalsymtable:=oldlocalsymtable;
  3854. end;
  3855. function tprocvardef.getsymtable(t:tgetsymtable):tsymtable;
  3856. begin
  3857. case t of
  3858. gs_para :
  3859. getsymtable:=parast;
  3860. else
  3861. getsymtable:=nil;
  3862. end;
  3863. end;
  3864. function tprocvardef.size : longint;
  3865. begin
  3866. if (po_methodpointer in procoptions) and
  3867. not(po_addressonly in procoptions) then
  3868. size:=2*POINTER_SIZE
  3869. else
  3870. size:=POINTER_SIZE;
  3871. end;
  3872. function tprocvardef.is_methodpointer:boolean;
  3873. begin
  3874. result:=(po_methodpointer in procoptions);
  3875. end;
  3876. function tprocvardef.is_addressonly:boolean;
  3877. begin
  3878. result:=not(po_methodpointer in procoptions) or
  3879. (po_addressonly in procoptions);
  3880. end;
  3881. {$ifdef GDB}
  3882. function tprocvardef.stabstring : pchar;
  3883. var
  3884. nss : pchar;
  3885. { i : longint; }
  3886. begin
  3887. { i := maxparacount; }
  3888. getmem(nss,1024);
  3889. { it is not a function but a function pointer !! (PM) }
  3890. strpcopy(nss,'*f'+tstoreddef(rettype.def).numberstring{+','+tostr(i)});
  3891. { this confuses gdb !!
  3892. we should use 'F' instead of 'f' but
  3893. as we use c++ language mode
  3894. it does not like that either
  3895. Please do not remove this part
  3896. might be used once
  3897. gdb for pascal is ready PM }
  3898. {$ifdef disabled}
  3899. param := para1;
  3900. i := 0;
  3901. while assigned(param) do
  3902. begin
  3903. inc(i);
  3904. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  3905. {Here we have lost the parameter names !!}
  3906. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def.numberstring+','+vartyp+';');
  3907. strcat(nss,pst);
  3908. strdispose(pst);
  3909. param := param^.next;
  3910. end;
  3911. {$endif}
  3912. {strpcopy(strend(nss),';');}
  3913. stabstring := strnew(nss);
  3914. freemem(nss,1024);
  3915. end;
  3916. procedure tprocvardef.concatstabto(asmlist : taasmoutput);
  3917. begin
  3918. if (stab_state in [stab_state_writing,stab_state_written]) then
  3919. exit;
  3920. tstoreddef(rettype.def).concatstabto(asmlist);
  3921. inherited concatstabto(asmlist);
  3922. end;
  3923. {$endif GDB}
  3924. procedure tprocvardef.write_rtti_data(rt:trttitype);
  3925. var
  3926. pdc : TParaItem;
  3927. methodkind, paraspec : byte;
  3928. begin
  3929. if po_methodpointer in procoptions then
  3930. begin
  3931. { write method id and name }
  3932. rttiList.concat(Tai_const.Create_8bit(tkmethod));
  3933. write_rtti_name;
  3934. { write kind of method (can only be function or procedure)}
  3935. if rettype.def = voidtype.def then
  3936. methodkind := mkProcedure
  3937. else
  3938. methodkind := mkFunction;
  3939. rttiList.concat(Tai_const.Create_8bit(methodkind));
  3940. { get # of parameters }
  3941. rttiList.concat(Tai_const.Create_8bit(maxparacount));
  3942. { write parameter info. The parameters must be written in reverse order
  3943. if this method uses right to left parameter pushing! }
  3944. if proccalloption in pushleftright_pocalls then
  3945. pdc:=TParaItem(Para.first)
  3946. else
  3947. pdc:=TParaItem(Para.last);
  3948. while assigned(pdc) do
  3949. begin
  3950. { only store user visible parameters }
  3951. if not pdc.is_hidden then
  3952. begin
  3953. case pdc.paratyp of
  3954. vs_value: paraspec := 0;
  3955. vs_const: paraspec := pfConst;
  3956. vs_var : paraspec := pfVar;
  3957. vs_out : paraspec := pfOut;
  3958. end;
  3959. { write flags for current parameter }
  3960. rttiList.concat(Tai_const.Create_8bit(paraspec));
  3961. { write name of current parameter }
  3962. if assigned(pdc.parasym) then
  3963. begin
  3964. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  3965. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  3966. end
  3967. else
  3968. rttiList.concat(Tai_const.Create_8bit(0));
  3969. { write name of type of current parameter }
  3970. tstoreddef(pdc.paratype.def).write_rtti_name;
  3971. end;
  3972. if proccalloption in pushleftright_pocalls then
  3973. pdc:=TParaItem(pdc.next)
  3974. else
  3975. pdc:=TParaItem(pdc.previous);
  3976. end;
  3977. { write name of result type }
  3978. tstoreddef(rettype.def).write_rtti_name;
  3979. end;
  3980. end;
  3981. function tprocvardef.is_publishable : boolean;
  3982. begin
  3983. is_publishable:=(po_methodpointer in procoptions);
  3984. end;
  3985. function tprocvardef.gettypename : string;
  3986. var
  3987. s: string;
  3988. showhidden : boolean;
  3989. begin
  3990. {$ifdef EXTDEBUG}
  3991. showhidden:=true;
  3992. {$else EXTDEBUG}
  3993. showhidden:=false;
  3994. {$endif EXTDEBUG}
  3995. s:='<';
  3996. if po_classmethod in procoptions then
  3997. s := s+'class method type of'
  3998. else
  3999. if po_addressonly in procoptions then
  4000. s := s+'address of'
  4001. else
  4002. s := s+'procedure variable type of';
  4003. if assigned(rettype.def) and
  4004. (rettype.def<>voidtype.def) then
  4005. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4006. else
  4007. s:=s+' procedure'+typename_paras(showhidden);
  4008. if po_methodpointer in procoptions then
  4009. s := s+' of object';
  4010. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4011. end;
  4012. {***************************************************************************
  4013. TOBJECTDEF
  4014. ***************************************************************************}
  4015. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4016. begin
  4017. inherited create;
  4018. objecttype:=ot;
  4019. deftype:=objectdef;
  4020. objectoptions:=[];
  4021. childof:=nil;
  4022. symtable:=tobjectsymtable.create(n,aktpackrecords);
  4023. { create space for vmt !! }
  4024. vmt_offset:=0;
  4025. symtable.defowner:=self;
  4026. lastvtableindex:=0;
  4027. set_parent(c);
  4028. objname:=stringdup(upper(n));
  4029. objrealname:=stringdup(n);
  4030. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4031. prepareguid;
  4032. { setup implemented interfaces }
  4033. if objecttype in [odt_class,odt_interfacecorba] then
  4034. implementedinterfaces:=timplementedinterfaces.create
  4035. else
  4036. implementedinterfaces:=nil;
  4037. {$ifdef GDB}
  4038. writing_class_record_stab:=false;
  4039. {$endif GDB}
  4040. end;
  4041. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4042. var
  4043. i,implintfcount: longint;
  4044. d : tderef;
  4045. begin
  4046. inherited ppuloaddef(ppufile);
  4047. deftype:=objectdef;
  4048. objecttype:=tobjectdeftype(ppufile.getbyte);
  4049. savesize:=ppufile.getlongint;
  4050. vmt_offset:=ppufile.getlongint;
  4051. objrealname:=stringdup(ppufile.getstring);
  4052. objname:=stringdup(upper(objrealname^));
  4053. ppufile.getderef(childofderef);
  4054. ppufile.getsmallset(objectoptions);
  4055. { load guid }
  4056. iidstr:=nil;
  4057. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4058. begin
  4059. new(iidguid);
  4060. ppufile.getguid(iidguid^);
  4061. iidstr:=stringdup(ppufile.getstring);
  4062. lastvtableindex:=ppufile.getlongint;
  4063. end;
  4064. { load implemented interfaces }
  4065. if objecttype in [odt_class,odt_interfacecorba] then
  4066. begin
  4067. implementedinterfaces:=timplementedinterfaces.create;
  4068. implintfcount:=ppufile.getlongint;
  4069. for i:=1 to implintfcount do
  4070. begin
  4071. ppufile.getderef(d);
  4072. implementedinterfaces.addintf_deref(d);
  4073. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4074. end;
  4075. end
  4076. else
  4077. implementedinterfaces:=nil;
  4078. symtable:=tobjectsymtable.create(objrealname^,aktpackrecords);
  4079. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  4080. tobjectsymtable(symtable).fieldalignment:=ppufile.getbyte;
  4081. tobjectsymtable(symtable).recordalignment:=ppufile.getbyte;
  4082. tobjectsymtable(symtable).ppuload(ppufile);
  4083. symtable.defowner:=self;
  4084. { handles the predefined class tobject }
  4085. { the last TOBJECT which is loaded gets }
  4086. { it ! }
  4087. if (childof=nil) and
  4088. (objecttype=odt_class) and
  4089. (objname^='TOBJECT') then
  4090. class_tobject:=self;
  4091. if (childof=nil) and
  4092. (objecttype=odt_interfacecom) and
  4093. (objname^='IUNKNOWN') then
  4094. interface_iunknown:=self;
  4095. {$ifdef GDB}
  4096. writing_class_record_stab:=false;
  4097. {$endif GDB}
  4098. end;
  4099. destructor tobjectdef.destroy;
  4100. begin
  4101. if assigned(symtable) then
  4102. symtable.free;
  4103. stringdispose(objname);
  4104. stringdispose(objrealname);
  4105. if assigned(iidstr) then
  4106. stringdispose(iidstr);
  4107. if assigned(implementedinterfaces) then
  4108. implementedinterfaces.free;
  4109. if assigned(iidguid) then
  4110. dispose(iidguid);
  4111. inherited destroy;
  4112. end;
  4113. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4114. var
  4115. implintfcount : longint;
  4116. i : longint;
  4117. begin
  4118. inherited ppuwritedef(ppufile);
  4119. ppufile.putbyte(byte(objecttype));
  4120. ppufile.putlongint(size);
  4121. ppufile.putlongint(vmt_offset);
  4122. ppufile.putstring(objrealname^);
  4123. ppufile.putderef(childofderef);
  4124. ppufile.putsmallset(objectoptions);
  4125. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4126. begin
  4127. ppufile.putguid(iidguid^);
  4128. ppufile.putstring(iidstr^);
  4129. ppufile.putlongint(lastvtableindex);
  4130. end;
  4131. if objecttype in [odt_class,odt_interfacecorba] then
  4132. begin
  4133. implintfcount:=implementedinterfaces.count;
  4134. ppufile.putlongint(implintfcount);
  4135. for i:=1 to implintfcount do
  4136. begin
  4137. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4138. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4139. end;
  4140. end;
  4141. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4142. ppufile.putbyte(tobjectsymtable(symtable).fieldalignment);
  4143. ppufile.putbyte(tobjectsymtable(symtable).recordalignment);
  4144. ppufile.writeentry(ibobjectdef);
  4145. tobjectsymtable(symtable).ppuwrite(ppufile);
  4146. end;
  4147. function tobjectdef.gettypename:string;
  4148. begin
  4149. gettypename:=typename;
  4150. end;
  4151. procedure tobjectdef.buildderef;
  4152. var
  4153. oldrecsyms : tsymtable;
  4154. begin
  4155. inherited buildderef;
  4156. childofderef.build(childof);
  4157. oldrecsyms:=aktrecordsymtable;
  4158. aktrecordsymtable:=symtable;
  4159. tstoredsymtable(symtable).buildderef;
  4160. aktrecordsymtable:=oldrecsyms;
  4161. if objecttype in [odt_class,odt_interfacecorba] then
  4162. implementedinterfaces.buildderef;
  4163. end;
  4164. procedure tobjectdef.deref;
  4165. var
  4166. oldrecsyms : tsymtable;
  4167. begin
  4168. inherited deref;
  4169. childof:=tobjectdef(childofderef.resolve);
  4170. oldrecsyms:=aktrecordsymtable;
  4171. aktrecordsymtable:=symtable;
  4172. tstoredsymtable(symtable).deref;
  4173. aktrecordsymtable:=oldrecsyms;
  4174. if objecttype in [odt_class,odt_interfacecorba] then
  4175. implementedinterfaces.deref;
  4176. end;
  4177. function tobjectdef.getparentdef:tdef;
  4178. begin
  4179. result:=childof;
  4180. end;
  4181. procedure tobjectdef.prepareguid;
  4182. begin
  4183. { set up guid }
  4184. if not assigned(iidguid) then
  4185. begin
  4186. new(iidguid);
  4187. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4188. end;
  4189. { setup iidstring }
  4190. if not assigned(iidstr) then
  4191. iidstr:=stringdup(''); { default is empty string }
  4192. end;
  4193. procedure tobjectdef.set_parent( c : tobjectdef);
  4194. begin
  4195. { nothing to do if the parent was not forward !}
  4196. if assigned(childof) then
  4197. exit;
  4198. childof:=c;
  4199. { some options are inherited !! }
  4200. if assigned(c) then
  4201. begin
  4202. { only important for classes }
  4203. lastvtableindex:=c.lastvtableindex;
  4204. objectoptions:=objectoptions+(c.objectoptions*
  4205. [oo_has_virtual,oo_has_private,oo_has_protected,
  4206. oo_has_constructor,oo_has_destructor]);
  4207. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4208. begin
  4209. { add the data of the anchestor class }
  4210. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4211. if (oo_has_vmt in objectoptions) and
  4212. (oo_has_vmt in c.objectoptions) then
  4213. dec(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4214. { if parent has a vmt field then
  4215. the offset is the same for the child PM }
  4216. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4217. begin
  4218. vmt_offset:=c.vmt_offset;
  4219. include(objectoptions,oo_has_vmt);
  4220. end;
  4221. end;
  4222. end;
  4223. savesize := tobjectsymtable(symtable).datasize;
  4224. end;
  4225. procedure tobjectdef.insertvmt;
  4226. begin
  4227. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4228. exit;
  4229. if (oo_has_vmt in objectoptions) then
  4230. internalerror(12345)
  4231. else
  4232. begin
  4233. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4234. tobjectsymtable(symtable).fieldalignment);
  4235. vmt_offset:=tobjectsymtable(symtable).datasize;
  4236. inc(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4237. include(objectoptions,oo_has_vmt);
  4238. end;
  4239. end;
  4240. procedure tobjectdef.check_forwards;
  4241. begin
  4242. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4243. tstoredsymtable(symtable).check_forwards;
  4244. if (oo_is_forward in objectoptions) then
  4245. begin
  4246. { ok, in future, the forward can be resolved }
  4247. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4248. exclude(objectoptions,oo_is_forward);
  4249. end;
  4250. end;
  4251. { true, if self inherits from d (or if they are equal) }
  4252. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4253. var
  4254. hp : tobjectdef;
  4255. begin
  4256. hp:=self;
  4257. while assigned(hp) do
  4258. begin
  4259. if hp=d then
  4260. begin
  4261. is_related:=true;
  4262. exit;
  4263. end;
  4264. hp:=hp.childof;
  4265. end;
  4266. is_related:=false;
  4267. end;
  4268. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4269. var
  4270. p : pprocdeflist;
  4271. begin
  4272. { if we found already a destructor, then we exit }
  4273. if assigned(sd) then
  4274. exit;
  4275. if tsym(sym).typ=procsym then
  4276. begin
  4277. p:=tprocsym(sym).defs;
  4278. while assigned(p) do
  4279. begin
  4280. if p^.def.proctypeoption=potype_destructor then
  4281. begin
  4282. sd:=p^.def;
  4283. exit;
  4284. end;
  4285. p:=p^.next;
  4286. end;
  4287. end;
  4288. end;*)
  4289. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4290. begin
  4291. { if we found already a destructor, then we exit }
  4292. if (ppointer(sd)^=nil) and
  4293. (Tsym(sym).typ=procsym) then
  4294. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4295. end;
  4296. function tobjectdef.searchdestructor : tprocdef;
  4297. var
  4298. o : tobjectdef;
  4299. sd : tprocdef;
  4300. begin
  4301. searchdestructor:=nil;
  4302. o:=self;
  4303. sd:=nil;
  4304. while assigned(o) do
  4305. begin
  4306. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4307. if assigned(sd) then
  4308. begin
  4309. searchdestructor:=sd;
  4310. exit;
  4311. end;
  4312. o:=o.childof;
  4313. end;
  4314. end;
  4315. function tobjectdef.size : longint;
  4316. begin
  4317. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4318. result:=POINTER_SIZE
  4319. else
  4320. result:=tobjectsymtable(symtable).datasize;
  4321. end;
  4322. function tobjectdef.alignment:longint;
  4323. begin
  4324. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4325. alignment:=POINTER_SIZE
  4326. else
  4327. alignment:=tobjectsymtable(symtable).recordalignment;
  4328. end;
  4329. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4330. begin
  4331. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4332. case objecttype of
  4333. odt_class:
  4334. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  4335. odt_interfacecom,odt_interfacecorba:
  4336. vmtmethodoffset:=index*POINTER_SIZE;
  4337. else
  4338. {$ifdef WITHDMT}
  4339. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  4340. {$else WITHDMT}
  4341. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  4342. {$endif WITHDMT}
  4343. end;
  4344. end;
  4345. function tobjectdef.vmt_mangledname : string;
  4346. begin
  4347. if not(oo_has_vmt in objectoptions) then
  4348. Message1(parser_n_object_has_no_vmt,objrealname^);
  4349. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4350. end;
  4351. function tobjectdef.rtti_name : string;
  4352. begin
  4353. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4354. end;
  4355. {$ifdef GDB}
  4356. procedure tobjectdef.proc_addname(p :tnamedindexitem;arg:pointer);
  4357. var virtualind,argnames : string;
  4358. newrec : pchar;
  4359. pd : tprocdef;
  4360. lindex : longint;
  4361. para : TParaItem;
  4362. arglength : byte;
  4363. sp : char;
  4364. state:^Trecord_stabgen_state;
  4365. olds:integer;
  4366. begin
  4367. state:=arg;
  4368. if tsym(p).typ = procsym then
  4369. begin
  4370. pd := tprocsym(p).first_procdef;
  4371. if (po_virtualmethod in pd.procoptions) then
  4372. begin
  4373. lindex := pd.extnumber;
  4374. {doesnt seem to be necessary
  4375. lindex := lindex or $80000000;}
  4376. virtualind := '*'+tostr(lindex)+';'+pd._class.classnumberstring+';'
  4377. end
  4378. else
  4379. virtualind := '.';
  4380. { used by gdbpas to recognize constructor and destructors }
  4381. if (pd.proctypeoption=potype_constructor) then
  4382. argnames:='__ct__'
  4383. else if (pd.proctypeoption=potype_destructor) then
  4384. argnames:='__dt__'
  4385. else
  4386. argnames := '';
  4387. { arguments are not listed here }
  4388. {we don't need another definition}
  4389. para := TParaItem(pd.Para.first);
  4390. while assigned(para) do
  4391. begin
  4392. if Para.paratype.def.deftype = formaldef then
  4393. begin
  4394. case Para.paratyp of
  4395. vs_var :
  4396. argnames := argnames+'3var';
  4397. vs_const :
  4398. argnames:=argnames+'5const';
  4399. vs_out :
  4400. argnames:=argnames+'3out';
  4401. end;
  4402. end
  4403. else
  4404. begin
  4405. { if the arg definition is like (v: ^byte;..
  4406. there is no sym attached to data !!! }
  4407. if assigned(Para.paratype.def.typesym) then
  4408. begin
  4409. arglength := length(Para.paratype.def.typesym.name);
  4410. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4411. end
  4412. else
  4413. argnames:=argnames+'11unnamedtype';
  4414. end;
  4415. para := TParaItem(Para.next);
  4416. end;
  4417. { here 2A must be changed for private and protected }
  4418. { 0 is private 1 protected and 2 public }
  4419. if (sp_private in tsym(p).symoptions) then
  4420. sp:='0'
  4421. else if (sp_protected in tsym(p).symoptions) then
  4422. sp:='1'
  4423. else
  4424. sp:='2';
  4425. newrec:=stabstr_evaluate('$1::$2=##$3;:$4;$5A$6;',[p.name,pd.numberstring,
  4426. Tstoreddef(pd.rettype.def).numberstring,argnames,sp,
  4427. virtualind]);
  4428. { get spare place for a string at the end }
  4429. olds:=state^.stabsize;
  4430. inc(state^.stabsize,strlen(newrec));
  4431. if state^.stabsize>=state^.staballoc-256 then
  4432. begin
  4433. inc(state^.staballoc,memsizeinc);
  4434. reallocmem(state^.stabstring,state^.staballoc);
  4435. end;
  4436. strcopy(state^.stabstring+olds,newrec);
  4437. strdispose(newrec);
  4438. {This should be used for case !!
  4439. RecOffset := RecOffset + pd.size;}
  4440. end;
  4441. end;
  4442. procedure tobjectdef.proc_concatstabto(p :tnamedindexitem;arg:pointer);
  4443. var
  4444. pd : tprocdef;
  4445. begin
  4446. if tsym(p).typ = procsym then
  4447. begin
  4448. pd := tprocsym(p).first_procdef;
  4449. tstoreddef(pd.rettype.def).concatstabto(taasmoutput(arg));
  4450. end;
  4451. end;
  4452. function tobjectdef.stabstring : pchar;
  4453. var anc : tobjectdef;
  4454. state:Trecord_stabgen_state;
  4455. ts : string;
  4456. begin
  4457. if not (objecttype=odt_class) or writing_class_record_stab then
  4458. begin
  4459. state.staballoc:=memsizeinc;
  4460. getmem(state.stabstring,state.staballoc);
  4461. strpcopy(state.stabstring,'s'+tostr(tobjectsymtable(symtable).datasize));
  4462. if assigned(childof) then
  4463. begin
  4464. {only one ancestor not virtual, public, at base offset 0 }
  4465. { !1 , 0 2 0 , }
  4466. strpcopy(strend(state.stabstring),'!1,020,'+childof.classnumberstring+';');
  4467. end;
  4468. {virtual table to implement yet}
  4469. state.recoffset:=0;
  4470. state.stabsize:=strlen(state.stabstring);
  4471. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_addname,@state);
  4472. if (oo_has_vmt in objectoptions) then
  4473. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4474. begin
  4475. ts:='$vf'+classnumberstring+':'+tstoreddef(vmtarraytype.def).numberstring+','+tostr(vmt_offset*8)+';';
  4476. strpcopy(state.stabstring+state.stabsize,ts);
  4477. inc(state.stabsize,length(ts));
  4478. end;
  4479. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_addname,@state);
  4480. if (oo_has_vmt in objectoptions) then
  4481. begin
  4482. anc := self;
  4483. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4484. anc := anc.childof;
  4485. { just in case anc = self }
  4486. ts:=';~%'+anc.classnumberstring+';';
  4487. end
  4488. else
  4489. ts:=';';
  4490. strpcopy(state.stabstring+state.stabsize,ts);
  4491. inc(state.stabsize,length(ts));
  4492. reallocmem(state.stabstring,state.stabsize+1);
  4493. stabstring:=state.stabstring;
  4494. end
  4495. else
  4496. begin
  4497. stabstring:=strpnew('*'+classnumberstring);
  4498. end;
  4499. end;
  4500. procedure tobjectdef.set_globalnb;
  4501. begin
  4502. globalnb:=PglobalTypeCount^;
  4503. inc(PglobalTypeCount^);
  4504. { classes need two type numbers, the globalnb is set to the ptr }
  4505. if objecttype=odt_class then
  4506. begin
  4507. globalnb:=PGlobalTypeCount^;
  4508. inc(PglobalTypeCount^);
  4509. end;
  4510. end;
  4511. function tobjectdef.classnumberstring : string;
  4512. begin
  4513. if objecttype=odt_class then
  4514. begin
  4515. if globalnb=0 then
  4516. numberstring;
  4517. dec(globalnb);
  4518. classnumberstring:=numberstring;
  4519. inc(globalnb);
  4520. end
  4521. else
  4522. classnumberstring:=numberstring;
  4523. end;
  4524. function tobjectdef.allstabstring : pchar;
  4525. var
  4526. stabchar : string[2];
  4527. ss,st : pchar;
  4528. sname : string;
  4529. begin
  4530. ss := stabstring;
  4531. getmem(st,strlen(ss)+512);
  4532. stabchar := 't';
  4533. if deftype in tagtypes then
  4534. stabchar := 'Tt';
  4535. if assigned(typesym) then
  4536. sname := typesym.name
  4537. else
  4538. sname := ' ';
  4539. if writing_class_record_stab then
  4540. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4541. else
  4542. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4543. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,0,0');
  4544. allstabstring := strnew(st);
  4545. freemem(st,strlen(ss)+512);
  4546. strdispose(ss);
  4547. end;
  4548. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4549. var
  4550. oldtypesym : tsym;
  4551. stab_str : pchar;
  4552. anc : tobjectdef;
  4553. begin
  4554. if (stab_state in [stab_state_writing,stab_state_written]) then
  4555. exit;
  4556. stab_state:=stab_state_writing;
  4557. tstoreddef(vmtarraytype.def).concatstabto(asmlist);
  4558. { first the parents }
  4559. anc:=self;
  4560. while assigned(anc.childof) do
  4561. begin
  4562. anc:=anc.childof;
  4563. anc.concatstabto(asmlist);
  4564. end;
  4565. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}field_concatstabto,asmlist);
  4566. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}proc_concatstabto,asmlist);
  4567. stab_state:=stab_state_used;
  4568. if objecttype=odt_class then
  4569. begin
  4570. { Write the record class itself }
  4571. writing_class_record_stab:=true;
  4572. inherited concatstabto(asmlist);
  4573. writing_class_record_stab:=false;
  4574. { Write the invisible pointer class }
  4575. oldtypesym:=typesym;
  4576. typesym:=nil;
  4577. stab_str := allstabstring;
  4578. asmList.concat(Tai_stabs.Create(stab_str));
  4579. typesym:=oldtypesym;
  4580. end
  4581. else
  4582. inherited concatstabto(asmlist);
  4583. end;
  4584. {$endif GDB}
  4585. function tobjectdef.needs_inittable : boolean;
  4586. begin
  4587. case objecttype of
  4588. odt_class :
  4589. needs_inittable:=false;
  4590. odt_interfacecom:
  4591. needs_inittable:=true;
  4592. odt_interfacecorba:
  4593. needs_inittable:=is_related(interface_iunknown);
  4594. odt_object:
  4595. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4596. else
  4597. internalerror(200108267);
  4598. end;
  4599. end;
  4600. function tobjectdef.members_need_inittable : boolean;
  4601. begin
  4602. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4603. end;
  4604. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4605. begin
  4606. if needs_prop_entry(tsym(sym)) and
  4607. (tsym(sym).typ<>varsym) then
  4608. inc(count);
  4609. end;
  4610. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4611. var
  4612. proctypesinfo : byte;
  4613. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4614. var
  4615. typvalue : byte;
  4616. hp : psymlistitem;
  4617. address : longint;
  4618. def : tdef;
  4619. begin
  4620. if not(assigned(proc) and assigned(proc.firstsym)) then
  4621. begin
  4622. rttiList.concat(Tai_const.Create_32bit(1));
  4623. typvalue:=3;
  4624. end
  4625. else if proc.firstsym^.sym.typ=varsym then
  4626. begin
  4627. address:=0;
  4628. hp:=proc.firstsym;
  4629. def:=nil;
  4630. while assigned(hp) do
  4631. begin
  4632. case hp^.sltype of
  4633. sl_load :
  4634. begin
  4635. def:=tvarsym(hp^.sym).vartype.def;
  4636. inc(address,tvarsym(hp^.sym).fieldoffset);
  4637. end;
  4638. sl_subscript :
  4639. begin
  4640. if not(assigned(def) and (def.deftype=recorddef)) then
  4641. internalerror(200402171);
  4642. inc(address,tvarsym(hp^.sym).fieldoffset);
  4643. def:=tvarsym(hp^.sym).vartype.def;
  4644. end;
  4645. sl_vec :
  4646. begin
  4647. if not(assigned(def) and (def.deftype=arraydef)) then
  4648. internalerror(200402172);
  4649. def:=tarraydef(def).elementtype.def;
  4650. inc(address,def.size*hp^.value);
  4651. end;
  4652. end;
  4653. hp:=hp^.next;
  4654. end;
  4655. rttiList.concat(Tai_const.Create_32bit(address));
  4656. typvalue:=0;
  4657. end
  4658. else
  4659. begin
  4660. { When there was an error then procdef is not assigned }
  4661. if not assigned(proc.procdef) then
  4662. exit;
  4663. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4664. begin
  4665. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.procdef).mangledname,AT_FUNCTION,0));
  4666. typvalue:=1;
  4667. end
  4668. else
  4669. begin
  4670. { virtual method, write vmt offset }
  4671. rttiList.concat(Tai_const.Create_32bit(
  4672. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4673. typvalue:=2;
  4674. end;
  4675. end;
  4676. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4677. end;
  4678. begin
  4679. if needs_prop_entry(tsym(sym)) then
  4680. case tsym(sym).typ of
  4681. varsym:
  4682. begin
  4683. {$ifdef dummy}
  4684. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4685. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4686. internalerror(1509992);
  4687. { access to implicit class property as field }
  4688. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4689. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label),AT_DATA,0));
  4690. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4691. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4692. { per default stored }
  4693. rttiList.concat(Tai_const.Create_32bit(1));
  4694. { index as well as ... }
  4695. rttiList.concat(Tai_const.Create_32bit(0));
  4696. { default value are zero }
  4697. rttiList.concat(Tai_const.Create_32bit(0));
  4698. rttiList.concat(Tai_const.Create_16bit(count));
  4699. inc(count);
  4700. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4701. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4702. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4703. {$endif dummy}
  4704. end;
  4705. propertysym:
  4706. begin
  4707. if ppo_indexed in tpropertysym(sym).propoptions then
  4708. proctypesinfo:=$40
  4709. else
  4710. proctypesinfo:=0;
  4711. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4712. writeproc(tpropertysym(sym).readaccess,0);
  4713. writeproc(tpropertysym(sym).writeaccess,2);
  4714. { isn't it stored ? }
  4715. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4716. begin
  4717. rttiList.concat(Tai_const.Create_ptr(0));
  4718. proctypesinfo:=proctypesinfo or (3 shl 4);
  4719. end
  4720. else
  4721. writeproc(tpropertysym(sym).storedaccess,4);
  4722. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4723. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4724. rttiList.concat(Tai_const.Create_16bit(count));
  4725. inc(count);
  4726. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4727. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4728. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4729. end;
  4730. else internalerror(1509992);
  4731. end;
  4732. end;
  4733. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4734. begin
  4735. if needs_prop_entry(tsym(sym)) then
  4736. begin
  4737. case tsym(sym).typ of
  4738. propertysym:
  4739. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4740. varsym:
  4741. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4742. else
  4743. internalerror(1509991);
  4744. end;
  4745. end;
  4746. end;
  4747. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4748. begin
  4749. FRTTIType:=rt;
  4750. case rt of
  4751. initrtti :
  4752. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4753. fullrtti :
  4754. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4755. else
  4756. internalerror(200108301);
  4757. end;
  4758. end;
  4759. type
  4760. tclasslistitem = class(TLinkedListItem)
  4761. index : longint;
  4762. p : tobjectdef;
  4763. end;
  4764. var
  4765. classtablelist : tlinkedlist;
  4766. tablecount : longint;
  4767. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4768. var
  4769. hp : tclasslistitem;
  4770. begin
  4771. hp:=tclasslistitem(classtablelist.first);
  4772. while assigned(hp) do
  4773. if hp.p=p then
  4774. begin
  4775. searchclasstablelist:=hp;
  4776. exit;
  4777. end
  4778. else
  4779. hp:=tclasslistitem(hp.next);
  4780. searchclasstablelist:=nil;
  4781. end;
  4782. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4783. var
  4784. hp : tclasslistitem;
  4785. begin
  4786. if needs_prop_entry(tsym(sym)) and
  4787. (tsym(sym).typ=varsym) then
  4788. begin
  4789. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4790. internalerror(0206001);
  4791. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4792. if not(assigned(hp)) then
  4793. begin
  4794. hp:=tclasslistitem.create;
  4795. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4796. hp.index:=tablecount;
  4797. classtablelist.concat(hp);
  4798. inc(tablecount);
  4799. end;
  4800. inc(count);
  4801. end;
  4802. end;
  4803. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4804. var
  4805. hp : tclasslistitem;
  4806. begin
  4807. if needs_prop_entry(tsym(sym)) and
  4808. (tsym(sym).typ=varsym) then
  4809. begin
  4810. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4811. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4812. if not(assigned(hp)) then
  4813. internalerror(0206002);
  4814. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4815. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4816. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4817. end;
  4818. end;
  4819. function tobjectdef.generate_field_table : tasmlabel;
  4820. var
  4821. fieldtable,
  4822. classtable : tasmlabel;
  4823. hp : tclasslistitem;
  4824. begin
  4825. classtablelist:=TLinkedList.Create;
  4826. objectlibrary.getdatalabel(fieldtable);
  4827. objectlibrary.getdatalabel(classtable);
  4828. count:=0;
  4829. tablecount:=0;
  4830. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4831. if (cs_create_smart in aktmoduleswitches) then
  4832. rttiList.concat(Tai_cut.Create);
  4833. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4834. rttiList.concat(Tai_label.Create(fieldtable));
  4835. rttiList.concat(Tai_const.Create_16bit(count));
  4836. rttiList.concat(Tai_const_symbol.Create(classtable));
  4837. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4838. { generate the class table }
  4839. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4840. rttiList.concat(Tai_label.Create(classtable));
  4841. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4842. hp:=tclasslistitem(classtablelist.first);
  4843. while assigned(hp) do
  4844. begin
  4845. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname,AT_DATA,0));
  4846. hp:=tclasslistitem(hp.next);
  4847. end;
  4848. generate_field_table:=fieldtable;
  4849. classtablelist.free;
  4850. end;
  4851. function tobjectdef.next_free_name_index : longint;
  4852. var
  4853. i : longint;
  4854. begin
  4855. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4856. i:=childof.next_free_name_index
  4857. else
  4858. i:=0;
  4859. count:=0;
  4860. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4861. next_free_name_index:=i+count;
  4862. end;
  4863. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4864. begin
  4865. case objecttype of
  4866. odt_class:
  4867. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4868. odt_object:
  4869. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4870. odt_interfacecom:
  4871. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4872. odt_interfacecorba:
  4873. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4874. else
  4875. exit;
  4876. end;
  4877. { generate the name }
  4878. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4879. rttiList.concat(Tai_string.Create(objrealname^));
  4880. case rt of
  4881. initrtti :
  4882. begin
  4883. rttiList.concat(Tai_const.Create_32bit(size));
  4884. if objecttype in [odt_class,odt_object] then
  4885. begin
  4886. count:=0;
  4887. FRTTIType:=rt;
  4888. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4889. rttiList.concat(Tai_const.Create_32bit(count));
  4890. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4891. end;
  4892. end;
  4893. fullrtti :
  4894. begin
  4895. if (oo_has_vmt in objectoptions) and
  4896. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4897. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname,AT_DATA,0))
  4898. else
  4899. rttiList.concat(Tai_const.Create_ptr(0));
  4900. { write owner typeinfo }
  4901. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4902. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4903. else
  4904. rttiList.concat(Tai_const.Create_ptr(0));
  4905. { count total number of properties }
  4906. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4907. count:=childof.next_free_name_index
  4908. else
  4909. count:=0;
  4910. { write it }
  4911. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4912. rttiList.concat(Tai_const.Create_16bit(count));
  4913. { write unit name }
  4914. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4915. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4916. { write published properties count }
  4917. count:=0;
  4918. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4919. rttiList.concat(Tai_const.Create_16bit(count));
  4920. { count is used to write nameindex }
  4921. { but we need an offset of the owner }
  4922. { to give each property an own slot }
  4923. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4924. count:=childof.next_free_name_index
  4925. else
  4926. count:=0;
  4927. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4928. end;
  4929. end;
  4930. end;
  4931. function tobjectdef.is_publishable : boolean;
  4932. begin
  4933. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4934. end;
  4935. {****************************************************************************
  4936. TIMPLEMENTEDINTERFACES
  4937. ****************************************************************************}
  4938. type
  4939. tnamemap = class(TNamedIndexItem)
  4940. newname: pstring;
  4941. constructor create(const aname, anewname: string);
  4942. destructor destroy; override;
  4943. end;
  4944. constructor tnamemap.create(const aname, anewname: string);
  4945. begin
  4946. inherited createname(name);
  4947. newname:=stringdup(anewname);
  4948. end;
  4949. destructor tnamemap.destroy;
  4950. begin
  4951. stringdispose(newname);
  4952. inherited destroy;
  4953. end;
  4954. type
  4955. tprocdefstore = class(TNamedIndexItem)
  4956. procdef: tprocdef;
  4957. constructor create(aprocdef: tprocdef);
  4958. end;
  4959. constructor tprocdefstore.create(aprocdef: tprocdef);
  4960. begin
  4961. inherited create;
  4962. procdef:=aprocdef;
  4963. end;
  4964. type
  4965. timplintfentry = class(TNamedIndexItem)
  4966. intf: tobjectdef;
  4967. intfderef : tderef;
  4968. ioffs: longint;
  4969. namemappings: tdictionary;
  4970. procdefs: TIndexArray;
  4971. constructor create(aintf: tobjectdef);
  4972. constructor create_deref(const d:tderef);
  4973. destructor destroy; override;
  4974. end;
  4975. constructor timplintfentry.create(aintf: tobjectdef);
  4976. begin
  4977. inherited create;
  4978. intf:=aintf;
  4979. ioffs:=-1;
  4980. namemappings:=nil;
  4981. procdefs:=nil;
  4982. end;
  4983. constructor timplintfentry.create_deref(const d:tderef);
  4984. begin
  4985. inherited create;
  4986. intf:=nil;
  4987. intfderef:=d;
  4988. ioffs:=-1;
  4989. namemappings:=nil;
  4990. procdefs:=nil;
  4991. end;
  4992. destructor timplintfentry.destroy;
  4993. begin
  4994. if assigned(namemappings) then
  4995. namemappings.free;
  4996. if assigned(procdefs) then
  4997. procdefs.free;
  4998. inherited destroy;
  4999. end;
  5000. constructor timplementedinterfaces.create;
  5001. begin
  5002. finterfaces:=tindexarray.create(1);
  5003. end;
  5004. destructor timplementedinterfaces.destroy;
  5005. begin
  5006. finterfaces.destroy;
  5007. end;
  5008. function timplementedinterfaces.count: longint;
  5009. begin
  5010. count:=finterfaces.count;
  5011. end;
  5012. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5013. begin
  5014. if (intfindex<1) or (intfindex>count) then
  5015. InternalError(200006123);
  5016. end;
  5017. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5018. begin
  5019. checkindex(intfindex);
  5020. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5021. end;
  5022. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5023. begin
  5024. checkindex(intfindex);
  5025. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5026. end;
  5027. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5028. begin
  5029. checkindex(intfindex);
  5030. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5031. end;
  5032. function timplementedinterfaces.searchintf(def: tdef): longint;
  5033. var
  5034. i: longint;
  5035. begin
  5036. i:=1;
  5037. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5038. if i<=count then
  5039. searchintf:=i
  5040. else
  5041. searchintf:=-1;
  5042. end;
  5043. procedure timplementedinterfaces.buildderef;
  5044. var
  5045. i: longint;
  5046. begin
  5047. for i:=1 to count do
  5048. with timplintfentry(finterfaces.search(i)) do
  5049. intfderef.build(intf);
  5050. end;
  5051. procedure timplementedinterfaces.deref;
  5052. var
  5053. i: longint;
  5054. begin
  5055. for i:=1 to count do
  5056. with timplintfentry(finterfaces.search(i)) do
  5057. intf:=tobjectdef(intfderef.resolve);
  5058. end;
  5059. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5060. begin
  5061. finterfaces.insert(timplintfentry.create_deref(d));
  5062. end;
  5063. procedure timplementedinterfaces.addintf(def: tdef);
  5064. begin
  5065. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5066. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5067. internalerror(200006124);
  5068. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5069. end;
  5070. procedure timplementedinterfaces.clearmappings;
  5071. var
  5072. i: longint;
  5073. begin
  5074. for i:=1 to count do
  5075. with timplintfentry(finterfaces.search(i)) do
  5076. begin
  5077. if assigned(namemappings) then
  5078. namemappings.free;
  5079. namemappings:=nil;
  5080. end;
  5081. end;
  5082. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5083. begin
  5084. checkindex(intfindex);
  5085. with timplintfentry(finterfaces.search(intfindex)) do
  5086. begin
  5087. if not assigned(namemappings) then
  5088. namemappings:=tdictionary.create;
  5089. namemappings.insert(tnamemap.create(name,newname));
  5090. end;
  5091. end;
  5092. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5093. begin
  5094. checkindex(intfindex);
  5095. if not assigned(nextexist) then
  5096. with timplintfentry(finterfaces.search(intfindex)) do
  5097. begin
  5098. if assigned(namemappings) then
  5099. nextexist:=namemappings.search(name)
  5100. else
  5101. nextexist:=nil;
  5102. end;
  5103. if assigned(nextexist) then
  5104. begin
  5105. getmappings:=tnamemap(nextexist).newname^;
  5106. nextexist:=tnamemap(nextexist).listnext;
  5107. end
  5108. else
  5109. getmappings:='';
  5110. end;
  5111. procedure timplementedinterfaces.clearimplprocs;
  5112. var
  5113. i: longint;
  5114. begin
  5115. for i:=1 to count do
  5116. with timplintfentry(finterfaces.search(i)) do
  5117. begin
  5118. if assigned(procdefs) then
  5119. procdefs.free;
  5120. procdefs:=nil;
  5121. end;
  5122. end;
  5123. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5124. begin
  5125. checkindex(intfindex);
  5126. with timplintfentry(finterfaces.search(intfindex)) do
  5127. begin
  5128. if not assigned(procdefs) then
  5129. procdefs:=tindexarray.create(4);
  5130. procdefs.insert(tprocdefstore.create(procdef));
  5131. end;
  5132. end;
  5133. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5134. begin
  5135. checkindex(intfindex);
  5136. with timplintfentry(finterfaces.search(intfindex)) do
  5137. if assigned(procdefs) then
  5138. implproccount:=procdefs.count
  5139. else
  5140. implproccount:=0;
  5141. end;
  5142. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5143. begin
  5144. checkindex(intfindex);
  5145. with timplintfentry(finterfaces.search(intfindex)) do
  5146. if assigned(procdefs) then
  5147. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5148. else
  5149. internalerror(200006131);
  5150. end;
  5151. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5152. var
  5153. possible: boolean;
  5154. i: longint;
  5155. iiep1: TIndexArray;
  5156. iiep2: TIndexArray;
  5157. begin
  5158. checkindex(intfindex);
  5159. checkindex(remainindex);
  5160. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5161. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5162. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5163. begin
  5164. possible:=true;
  5165. weight:=0;
  5166. end
  5167. else
  5168. begin
  5169. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5170. i:=1;
  5171. while (possible) and (i<=iiep1.count) do
  5172. begin
  5173. possible:=
  5174. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5175. inc(i);
  5176. end;
  5177. if possible then
  5178. weight:=iiep1.count;
  5179. end;
  5180. isimplmergepossible:=possible;
  5181. end;
  5182. {****************************************************************************
  5183. TFORWARDDEF
  5184. ****************************************************************************}
  5185. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5186. var
  5187. oldregisterdef : boolean;
  5188. begin
  5189. { never register the forwarddefs, they are disposed at the
  5190. end of the type declaration block }
  5191. oldregisterdef:=registerdef;
  5192. registerdef:=false;
  5193. inherited create;
  5194. registerdef:=oldregisterdef;
  5195. deftype:=forwarddef;
  5196. tosymname:=stringdup(s);
  5197. forwardpos:=pos;
  5198. end;
  5199. function tforwarddef.gettypename:string;
  5200. begin
  5201. gettypename:='unresolved forward to '+tosymname^;
  5202. end;
  5203. destructor tforwarddef.destroy;
  5204. begin
  5205. if assigned(tosymname) then
  5206. stringdispose(tosymname);
  5207. inherited destroy;
  5208. end;
  5209. {****************************************************************************
  5210. TERRORDEF
  5211. ****************************************************************************}
  5212. constructor terrordef.create;
  5213. begin
  5214. inherited create;
  5215. deftype:=errordef;
  5216. end;
  5217. {$ifdef GDB}
  5218. function terrordef.stabstring : pchar;
  5219. begin
  5220. stabstring:=strpnew('error'+numberstring);
  5221. end;
  5222. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5223. begin
  5224. { No internal error needed, an normal error is already
  5225. thrown }
  5226. end;
  5227. {$endif GDB}
  5228. function terrordef.gettypename:string;
  5229. begin
  5230. gettypename:='<erroneous type>';
  5231. end;
  5232. function terrordef.getmangledparaname:string;
  5233. begin
  5234. getmangledparaname:='error';
  5235. end;
  5236. {****************************************************************************
  5237. Definition Helpers
  5238. ****************************************************************************}
  5239. function is_interfacecom(def: tdef): boolean;
  5240. begin
  5241. is_interfacecom:=
  5242. assigned(def) and
  5243. (def.deftype=objectdef) and
  5244. (tobjectdef(def).objecttype=odt_interfacecom);
  5245. end;
  5246. function is_interfacecorba(def: tdef): boolean;
  5247. begin
  5248. is_interfacecorba:=
  5249. assigned(def) and
  5250. (def.deftype=objectdef) and
  5251. (tobjectdef(def).objecttype=odt_interfacecorba);
  5252. end;
  5253. function is_interface(def: tdef): boolean;
  5254. begin
  5255. is_interface:=
  5256. assigned(def) and
  5257. (def.deftype=objectdef) and
  5258. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5259. end;
  5260. function is_class(def: tdef): boolean;
  5261. begin
  5262. is_class:=
  5263. assigned(def) and
  5264. (def.deftype=objectdef) and
  5265. (tobjectdef(def).objecttype=odt_class);
  5266. end;
  5267. function is_object(def: tdef): boolean;
  5268. begin
  5269. is_object:=
  5270. assigned(def) and
  5271. (def.deftype=objectdef) and
  5272. (tobjectdef(def).objecttype=odt_object);
  5273. end;
  5274. function is_cppclass(def: tdef): boolean;
  5275. begin
  5276. is_cppclass:=
  5277. assigned(def) and
  5278. (def.deftype=objectdef) and
  5279. (tobjectdef(def).objecttype=odt_cppclass);
  5280. end;
  5281. function is_class_or_interface(def: tdef): boolean;
  5282. begin
  5283. is_class_or_interface:=
  5284. assigned(def) and
  5285. (def.deftype=objectdef) and
  5286. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5287. end;
  5288. end.
  5289. {
  5290. $Log$
  5291. Revision 1.234 2004-04-18 15:22:24 florian
  5292. + location support for arguments, currently PowerPC/MorphOS only
  5293. Revision 1.233 2004/03/23 22:34:49 peter
  5294. * constants ordinals now always have a type assigned
  5295. * integer constants have the smallest type, unsigned prefered over
  5296. signed
  5297. Revision 1.232 2004/03/18 11:43:57 olle
  5298. * change AT_FUNCTION to AT_DATA where appropriate
  5299. Revision 1.231 2004/03/14 22:51:46 peter
  5300. * valgrind doesn't like nested procedure info in stabs
  5301. Revision 1.230 2004/03/14 20:06:40 peter
  5302. * don't write line numbers in stabs for defs
  5303. Revision 1.229 2004/03/10 22:52:57 peter
  5304. * more stabs fixes
  5305. * special mode -gv for valgrind compatible stabs
  5306. Revision 1.228 2004/03/09 22:18:22 peter
  5307. * first write parent classes
  5308. Revision 1.227 2004/03/09 20:45:04 peter
  5309. * more stabs updates
  5310. Revision 1.226 2004/03/08 22:07:47 peter
  5311. * stabs updates to write stabs for def for all implictly used
  5312. units
  5313. Revision 1.225 2004/03/03 22:01:44 peter
  5314. * fix hidden pointer for stabs
  5315. Revision 1.224 2004/03/02 00:36:33 olle
  5316. * big transformation of Tai_[const_]Symbol.Create[data]name*
  5317. Revision 1.223 2004/02/26 16:16:38 peter
  5318. * tai_const.create_ptr added
  5319. Revision 1.222 2004/02/22 19:55:25 daniel
  5320. * Revert my latest change
  5321. Revision 1.221 2004/02/22 18:49:03 daniel
  5322. * Fixed minor bug in Tenumdef.stabstring
  5323. Revision 1.220 2004/02/19 17:07:42 florian
  5324. * fixed arg. area calculation
  5325. Revision 1.219 2004/02/17 15:57:49 peter
  5326. - fix rtti generation for properties containing sl_vec
  5327. - fix crash when overloaded operator is not available
  5328. - fix record alignment for C style variant records
  5329. Revision 1.218 2004/02/12 15:54:03 peter
  5330. * make extcycle is working again
  5331. Revision 1.217 2004/02/08 18:08:59 jonas
  5332. * fixed regvars support. Needs -doldregvars to activate. Only tested with
  5333. ppc, other processors should however only require maxregvars and
  5334. maxfpuregvars constants in cpubase.pas. Remember to take scratch-
  5335. registers into account when defining that value.
  5336. Revision 1.216 2004/02/06 22:37:00 daniel
  5337. * Removed not very usefull nextglobal & previousglobal fields from
  5338. Tstoreddef, saving 78 kb of memory
  5339. Revision 1.215 2004/02/05 01:24:08 florian
  5340. * several fixes to compile x86-64 system
  5341. Revision 1.214 2004/02/03 22:32:54 peter
  5342. * renamed xNNbittype to xNNinttype
  5343. * renamed registers32 to registersint
  5344. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  5345. Revision 1.213 2004/01/28 22:16:31 peter
  5346. * more record alignment fixes
  5347. Revision 1.212 2004/01/28 21:05:56 florian
  5348. * fixed alignment of classes
  5349. Revision 1.211 2004/01/28 20:30:18 peter
  5350. * record alignment splitted in fieldalignment and recordalignment,
  5351. the latter is used when this record is inserted in another record.
  5352. Revision 1.210 2004/01/27 10:29:32 daniel
  5353. * Fix string type stab generation. String constant still unsupported.
  5354. Revision 1.209 2004/01/26 19:54:42 daniel
  5355. * Typo
  5356. Revision 1.208 2004/01/26 19:43:49 daniel
  5357. * Try to recude stack usage of Tpointerdef.concatstabsto
  5358. Revision 1.207 2004/01/26 16:12:28 daniel
  5359. * reginfo now also only allocated during register allocation
  5360. * third round of gdb cleanups: kick out most of concatstabto
  5361. Revision 1.206 2004/01/25 20:23:28 daniel
  5362. * More gdb cleanup: make record & object stab generation linear instead
  5363. of quadratic.
  5364. Revision 1.205 2004/01/25 13:18:59 daniel
  5365. * Made varags parameter constant
  5366. Revision 1.204 2004/01/25 12:37:15 daniel
  5367. * Last commit broke debug info for records. Fixed.
  5368. Revision 1.203 2004/01/25 11:33:48 daniel
  5369. * 2nd round of gdb cleanup
  5370. Revision 1.202 2004/01/22 21:33:54 peter
  5371. * procvardef rtti fixed
  5372. Revision 1.201 2004/01/22 16:33:22 peter
  5373. * enum value rtti is now in orginal case
  5374. Revision 1.200 2004/01/20 12:59:37 florian
  5375. * common addnode code for x86-64 and i386
  5376. Revision 1.199 2004/01/15 15:16:18 daniel
  5377. * Some minor stuff
  5378. * Managed to eliminate speed effects of string compression
  5379. Revision 1.198 2004/01/11 23:56:20 daniel
  5380. * Experiment: Compress strings to save memory
  5381. Did not save a single byte of mem; clearly the core size is boosted by
  5382. temporary memory usage...
  5383. Revision 1.197 2004/01/04 21:10:04 jonas
  5384. * Darwin's assembler assumes that all labels starting with 'L' are local
  5385. -> rename symbols starting with 'L'
  5386. Revision 1.196 2003/12/24 20:51:11 peter
  5387. * don't lowercase enumnames
  5388. Revision 1.195 2003/12/24 01:47:22 florian
  5389. * first fixes to compile the x86-64 system unit
  5390. Revision 1.194 2003/12/21 19:42:43 florian
  5391. * fixed ppc inlining stuff
  5392. * fixed wrong unit writing
  5393. + added some sse stuff
  5394. Revision 1.193 2003/12/16 21:29:24 florian
  5395. + inlined procedures inherit procinfo flags
  5396. Revision 1.192 2003/12/12 12:09:40 marco
  5397. * always generate RTTI patch from peter
  5398. Revision 1.191 2003/12/08 22:34:24 peter
  5399. * tai_const.create_32bit changed to cardinal
  5400. Revision 1.190 2003/11/10 22:02:52 peter
  5401. * cross unit inlining fixed
  5402. Revision 1.189 2003/11/08 23:31:27 florian
  5403. * tstoreddef.getcopy returns now an errordef instead of nil; this
  5404. allows easier error recovery
  5405. Revision 1.188 2003/11/05 14:18:03 marco
  5406. * fix from Peter arraysize warning (nav Newsgroup msg)
  5407. Revision 1.187 2003/11/01 15:50:03 peter
  5408. * fix check for valid procdef in property rtti
  5409. Revision 1.186 2003/10/29 21:56:28 peter
  5410. * procsym.deref derefs only own procdefs
  5411. * reset paracount in procdef.deref so a second deref doesn't increase
  5412. the paracounts to invalid values
  5413. Revision 1.185 2003/10/29 19:48:51 peter
  5414. * renamed mangeldname_prefix to make_mangledname and made it more
  5415. generic
  5416. * make_mangledname is now also used for internal threadvar/resstring
  5417. lists
  5418. * Add P$ in front of program modulename to prevent duplicated symbols
  5419. at assembler level, because the main program can have the same name
  5420. as a unit, see webtbs/tw1251b
  5421. Revision 1.184 2003/10/23 14:44:07 peter
  5422. * splitted buildderef and buildderefimpl to fix interface crc
  5423. calculation
  5424. Revision 1.183 2003/10/22 20:40:00 peter
  5425. * write derefdata in a separate ppu entry
  5426. Revision 1.182 2003/10/21 18:14:49 peter
  5427. * fix counting of parameters when loading ppu
  5428. Revision 1.181 2003/10/17 15:08:34 peter
  5429. * commented out more obsolete constants
  5430. Revision 1.180 2003/10/17 14:52:07 peter
  5431. * fixed ppc build
  5432. Revision 1.179 2003/10/17 14:38:32 peter
  5433. * 64k registers supported
  5434. * fixed some memory leaks
  5435. Revision 1.178 2003/10/13 14:05:12 peter
  5436. * removed is_visible_for_proc
  5437. * search also for class overloads when finding interface
  5438. implementations
  5439. Revision 1.177 2003/10/11 16:06:42 florian
  5440. * fixed some MMX<->SSE
  5441. * started to fix ppc, needs an overhaul
  5442. + stabs info improve for spilling, not sure if it works correctly/completly
  5443. - MMX_SUPPORT removed from Makefile.fpc
  5444. Revision 1.176 2003/10/10 17:48:14 peter
  5445. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  5446. * tregisteralloctor renamed to trgobj
  5447. * removed rgobj from a lot of units
  5448. * moved location_* and reference_* to cgobj
  5449. * first things for mmx register allocation
  5450. Revision 1.175 2003/10/07 20:43:49 peter
  5451. * Add calling convention in fullprocname when it is specified
  5452. Revision 1.174 2003/10/07 16:06:30 peter
  5453. * tsymlist.def renamed to tsymlist.procdef
  5454. * tsymlist.procdef is now only used to store the procdef
  5455. Revision 1.173 2003/10/06 22:23:41 florian
  5456. + added basic olevariant support
  5457. Revision 1.172 2003/10/05 21:21:52 peter
  5458. * c style array of const generates callparanodes
  5459. * varargs paraloc fixes
  5460. Revision 1.171 2003/10/05 12:56:35 peter
  5461. * don't write procdefs that are released to ppu
  5462. Revision 1.170 2003/10/03 22:00:33 peter
  5463. * parameter alignment fixes
  5464. Revision 1.169 2003/10/02 21:19:42 peter
  5465. * protected visibility fixes
  5466. Revision 1.168 2003/10/01 20:34:49 peter
  5467. * procinfo unit contains tprocinfo
  5468. * cginfo renamed to cgbase
  5469. * moved cgmessage to verbose
  5470. * fixed ppc and sparc compiles
  5471. Revision 1.167 2003/10/01 16:49:05 florian
  5472. * para items are now reversed for pascal calling conventions
  5473. Revision 1.166 2003/10/01 15:32:58 florian
  5474. * fixed FullProcName to handle constructors, destructors and operators correctly
  5475. Revision 1.165 2003/10/01 15:00:02 peter
  5476. * don't write parast,localst debug info for externals
  5477. Revision 1.164 2003/09/23 21:03:35 peter
  5478. * connect parasym to paraitem
  5479. Revision 1.163 2003/09/23 17:56:06 peter
  5480. * locals and paras are allocated in the code generation
  5481. * tvarsym.localloc contains the location of para/local when
  5482. generating code for the current procedure
  5483. Revision 1.162 2003/09/07 22:09:35 peter
  5484. * preparations for different default calling conventions
  5485. * various RA fixes
  5486. Revision 1.161 2003/09/06 22:27:09 florian
  5487. * fixed web bug 2669
  5488. * cosmetic fix in printnode
  5489. * tobjectdef.gettypename implemented
  5490. Revision 1.160 2003/09/03 15:55:01 peter
  5491. * NEWRA branch merged
  5492. Revision 1.159 2003/09/03 11:18:37 florian
  5493. * fixed arm concatcopy
  5494. + arm support in the common compiler sources added
  5495. * moved some generic cg code around
  5496. + tfputype added
  5497. * ...
  5498. Revision 1.158.2.2 2003/08/29 17:28:59 peter
  5499. * next batch of updates
  5500. Revision 1.158.2.1 2003/08/27 19:55:54 peter
  5501. * first tregister patch
  5502. Revision 1.158 2003/08/11 21:18:20 peter
  5503. * start of sparc support for newra
  5504. Revision 1.157 2003/07/08 15:20:56 peter
  5505. * don't allow add/assignments for formaldef
  5506. * formaldef size changed to 0
  5507. Revision 1.156 2003/07/06 21:50:33 jonas
  5508. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  5509. so that it doesn't include ebp and esp anymore
  5510. Revision 1.155 2003/07/06 15:31:21 daniel
  5511. * Fixed register allocator. *Lots* of fixes.
  5512. Revision 1.154 2003/07/02 22:18:04 peter
  5513. * paraloc splitted in callerparaloc,calleeparaloc
  5514. * sparc calling convention updates
  5515. Revision 1.153 2003/06/25 18:31:23 peter
  5516. * sym,def resolving partly rewritten to support also parent objects
  5517. not directly available through the uses clause
  5518. Revision 1.152 2003/06/17 16:34:44 jonas
  5519. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  5520. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  5521. processor dependent
  5522. Revision 1.151 2003/06/08 11:41:21 peter
  5523. * set parast.next to the owner of the procdef
  5524. Revision 1.150 2003/06/07 20:26:32 peter
  5525. * re-resolving added instead of reloading from ppu
  5526. * tderef object added to store deref info for resolving
  5527. Revision 1.149 2003/06/05 20:05:55 peter
  5528. * removed changesettype because that will change the definition
  5529. of the setdef forever and can result in a different between
  5530. original interface and current implementation definition
  5531. Revision 1.148 2003/06/03 13:01:59 daniel
  5532. * Register allocator finished
  5533. Revision 1.147 2003/06/02 22:55:28 florian
  5534. * classes and interfaces can be stored in integer registers
  5535. Revision 1.146 2003/05/26 21:17:18 peter
  5536. * procinlinenode removed
  5537. * aktexit2label removed, fast exit removed
  5538. + tcallnode.inlined_pass_2 added
  5539. Revision 1.145 2003/05/25 11:34:17 peter
  5540. * methodpointer self pushing fixed
  5541. Revision 1.144 2003/05/15 18:58:53 peter
  5542. * removed selfpointer_offset, vmtpointer_offset
  5543. * tvarsym.adjusted_address
  5544. * address in localsymtable is now in the real direction
  5545. * removed some obsolete globals
  5546. Revision 1.143 2003/05/13 08:13:16 jonas
  5547. * patch from Peter for rtti symbols
  5548. Revision 1.142 2003/05/11 21:37:03 peter
  5549. * moved implicit exception frame from ncgutil to psub
  5550. * constructor/destructor helpers moved from cobj/ncgutil to psub
  5551. Revision 1.141 2003/05/09 17:47:03 peter
  5552. * self moved to hidden parameter
  5553. * removed hdisposen,hnewn,selfn
  5554. Revision 1.140 2003/05/05 14:53:16 peter
  5555. * vs_hidden replaced by is_hidden boolean
  5556. Revision 1.139 2003/05/01 07:59:43 florian
  5557. * introduced defaultordconsttype to decribe the default size of ordinal constants
  5558. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  5559. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  5560. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  5561. Revision 1.138 2003/04/27 11:21:34 peter
  5562. * aktprocdef renamed to current_procdef
  5563. * procinfo renamed to current_procinfo
  5564. * procinfo will now be stored in current_module so it can be
  5565. cleaned up properly
  5566. * gen_main_procsym changed to create_main_proc and release_main_proc
  5567. to also generate a tprocinfo structure
  5568. * fixed unit implicit initfinal
  5569. Revision 1.137 2003/04/27 07:29:51 peter
  5570. * current_procdef cleanup, current_procdef is now always nil when parsing
  5571. a new procdef declaration
  5572. * aktprocsym removed
  5573. * lexlevel removed, use symtable.symtablelevel instead
  5574. * implicit init/final code uses the normal genentry/genexit
  5575. * funcret state checking updated for new funcret handling
  5576. Revision 1.136 2003/04/25 20:59:35 peter
  5577. * removed funcretn,funcretsym, function result is now in varsym
  5578. and aliases for result and function name are added using absolutesym
  5579. * vs_hidden parameter for funcret passed in parameter
  5580. * vs_hidden fixes
  5581. * writenode changed to printnode and released from extdebug
  5582. * -vp option added to generate a tree.log with the nodetree
  5583. * nicer printnode for statements, callnode
  5584. Revision 1.135 2003/04/23 20:16:04 peter
  5585. + added currency support based on int64
  5586. + is_64bit for use in cg units instead of is_64bitint
  5587. * removed cgmessage from n386add, replace with internalerrors
  5588. Revision 1.134 2003/04/23 12:35:34 florian
  5589. * fixed several issues with powerpc
  5590. + applied a patch from Jonas for nested function calls (PowerPC only)
  5591. * ...
  5592. Revision 1.133 2003/04/10 17:57:53 peter
  5593. * vs_hidden released
  5594. Revision 1.132 2003/03/18 16:25:50 peter
  5595. * no itnernalerror for errordef.concatstabto()
  5596. Revision 1.131 2003/03/17 16:54:41 peter
  5597. * support DefaultHandler and anonymous inheritance fixed
  5598. for message methods
  5599. Revision 1.130 2003/03/17 15:54:22 peter
  5600. * store symoptions also for procdef
  5601. * check symoptions (private,public) when calculating possible
  5602. overload candidates
  5603. Revision 1.129 2003/02/19 22:00:14 daniel
  5604. * Code generator converted to new register notation
  5605. - Horribily outdated todo.txt removed
  5606. Revision 1.128 2003/02/02 19:25:54 carl
  5607. * Several bugfixes for m68k target (register alloc., opcode emission)
  5608. + VIS target
  5609. + Generic add more complete (still not verified)
  5610. Revision 1.127 2003/01/21 14:36:44 pierre
  5611. * set sizes needs to be passes in bits not bytes to stabs info
  5612. Revision 1.126 2003/01/16 22:11:33 peter
  5613. * fixed tprocdef.is_addressonly
  5614. Revision 1.125 2003/01/15 01:44:33 peter
  5615. * merged methodpointer fixes from 1.0.x
  5616. Revision 1.124 2003/01/09 21:52:37 peter
  5617. * merged some verbosity options.
  5618. * V_LineInfo is a verbosity flag to include line info
  5619. Revision 1.123 2003/01/06 21:16:52 peter
  5620. * po_addressonly added to retrieve the address of a methodpointer
  5621. only, this is used for @tclass.method which has no self pointer
  5622. Revision 1.122 2003/01/05 15:54:15 florian
  5623. + added proper support of type = type <type>; for simple types
  5624. Revision 1.121 2003/01/05 13:36:53 florian
  5625. * x86-64 compiles
  5626. + very basic support for float128 type (x86-64 only)
  5627. Revision 1.120 2003/01/02 19:49:00 peter
  5628. * update self parameter only for methodpointer and methods
  5629. Revision 1.119 2002/12/29 18:25:59 peter
  5630. * tprocdef.gettypename implemented
  5631. Revision 1.118 2002/12/27 15:23:09 peter
  5632. * write class methods in fullname
  5633. Revision 1.117 2002/12/15 19:34:31 florian
  5634. + some front end stuff for vs_hidden added
  5635. Revision 1.116 2002/12/15 11:26:02 peter
  5636. * ignore vs_hidden parameters when choosing overloaded proc
  5637. Revision 1.115 2002/12/07 14:27:09 carl
  5638. * 3% memory optimization
  5639. * changed some types
  5640. + added type checking with different size for call node and for
  5641. parameters
  5642. Revision 1.114 2002/12/01 22:05:27 carl
  5643. * no more warnings for structures over 32K since this is
  5644. handled correctly in this version of the compiler.
  5645. Revision 1.113 2002/11/27 20:04:09 peter
  5646. * tvarsym.get_push_size replaced by paramanager.push_size
  5647. Revision 1.112 2002/11/25 21:05:53 carl
  5648. * several mistakes fixed in message files
  5649. Revision 1.111 2002/11/25 18:43:33 carl
  5650. - removed the invalid if <> checking (Delphi is strange on this)
  5651. + implemented abstract warning on instance creation of class with
  5652. abstract methods.
  5653. * some error message cleanups
  5654. Revision 1.110 2002/11/25 17:43:24 peter
  5655. * splitted defbase in defutil,symutil,defcmp
  5656. * merged isconvertable and is_equal into compare_defs(_ext)
  5657. * made operator search faster by walking the list only once
  5658. Revision 1.109 2002/11/23 22:50:06 carl
  5659. * some small speed optimizations
  5660. + added several new warnings/hints
  5661. Revision 1.108 2002/11/22 22:48:10 carl
  5662. * memory optimization with tconstsym (1.5%)
  5663. Revision 1.107 2002/11/19 16:21:29 pierre
  5664. * correct several stabs generation problems
  5665. Revision 1.106 2002/11/18 17:31:59 peter
  5666. * pass proccalloption to ret_in_xxx and push_xxx functions
  5667. Revision 1.105 2002/11/17 16:31:57 carl
  5668. * memory optimization (3-4%) : cleanup of tai fields,
  5669. cleanup of tdef and tsym fields.
  5670. * make it work for m68k
  5671. Revision 1.104 2002/11/16 19:53:18 carl
  5672. * avoid Range check errors
  5673. Revision 1.103 2002/11/15 16:29:09 peter
  5674. * fixed rtti for int64 (merged)
  5675. Revision 1.102 2002/11/15 01:58:54 peter
  5676. * merged changes from 1.0.7 up to 04-11
  5677. - -V option for generating bug report tracing
  5678. - more tracing for option parsing
  5679. - errors for cdecl and high()
  5680. - win32 import stabs
  5681. - win32 records<=8 are returned in eax:edx (turned off by default)
  5682. - heaptrc update
  5683. - more info for temp management in .s file with EXTDEBUG
  5684. Revision 1.101 2002/11/09 15:31:02 carl
  5685. + align RTTI tables
  5686. Revision 1.100 2002/10/19 15:09:25 peter
  5687. + tobjectdef.members_need_inittable that is used to generate only the
  5688. inittable when it is really used. This saves a lot of useless calls
  5689. to fpc_finalize when destroying classes
  5690. Revision 1.99 2002/10/07 21:30:27 peter
  5691. * removed obsolete rangecheck stuff
  5692. Revision 1.98 2002/10/05 15:14:26 peter
  5693. * getparamangeldname for errordef
  5694. Revision 1.97 2002/10/05 12:43:28 carl
  5695. * fixes for Delphi 6 compilation
  5696. (warning : Some features do not work under Delphi)
  5697. Revision 1.96 2002/09/27 21:13:29 carl
  5698. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  5699. Revision 1.95 2002/09/16 09:31:10 florian
  5700. * fixed currency size
  5701. Revision 1.94 2002/09/09 17:34:15 peter
  5702. * tdicationary.replace added to replace and item in a dictionary. This
  5703. is only allowed for the same name
  5704. * varsyms are inserted in symtable before the types are parsed. This
  5705. fixes the long standing "var longint : longint" bug
  5706. - consume_idlist and idstringlist removed. The loops are inserted
  5707. at the callers place and uses the symtable for duplicate id checking
  5708. Revision 1.93 2002/09/07 15:25:07 peter
  5709. * old logs removed and tabs fixed
  5710. Revision 1.92 2002/09/05 19:29:42 peter
  5711. * memdebug enhancements
  5712. Revision 1.91 2002/08/25 19:25:20 peter
  5713. * sym.insert_in_data removed
  5714. * symtable.insertvardata/insertconstdata added
  5715. * removed insert_in_data call from symtable.insert, it needs to be
  5716. called separatly. This allows to deref the address calculation
  5717. * procedures now calculate the parast addresses after the procedure
  5718. directives are parsed. This fixes the cdecl parast problem
  5719. * push_addr_param has an extra argument that specifies if cdecl is used
  5720. or not
  5721. Revision 1.90 2002/08/18 20:06:25 peter
  5722. * inlining is now also allowed in interface
  5723. * renamed write/load to ppuwrite/ppuload
  5724. * tnode storing in ppu
  5725. * nld,ncon,nbas are already updated for storing in ppu
  5726. Revision 1.89 2002/08/11 15:28:00 florian
  5727. + support of explicit type case <any ordinal type>->pointer
  5728. (delphi mode only)
  5729. Revision 1.88 2002/08/11 14:32:28 peter
  5730. * renamed current_library to objectlibrary
  5731. Revision 1.87 2002/08/11 13:24:13 peter
  5732. * saving of asmsymbols in ppu supported
  5733. * asmsymbollist global is removed and moved into a new class
  5734. tasmlibrarydata that will hold the info of a .a file which
  5735. corresponds with a single module. Added librarydata to tmodule
  5736. to keep the library info stored for the module. In the future the
  5737. objectfiles will also be stored to the tasmlibrarydata class
  5738. * all getlabel/newasmsymbol and friends are moved to the new class
  5739. Revision 1.86 2002/08/09 07:33:03 florian
  5740. * a couple of interface related fixes
  5741. Revision 1.85 2002/07/23 09:51:24 daniel
  5742. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  5743. are worth comitting.
  5744. Revision 1.84 2002/07/20 11:57:57 florian
  5745. * types.pas renamed to defbase.pas because D6 contains a types
  5746. unit so this would conflicts if D6 programms are compiled
  5747. + Willamette/SSE2 instructions to assembler added
  5748. Revision 1.83 2002/07/11 14:41:30 florian
  5749. * start of the new generic parameter handling
  5750. Revision 1.82 2002/07/07 09:52:32 florian
  5751. * powerpc target fixed, very simple units can be compiled
  5752. * some basic stuff for better callparanode handling, far from being finished
  5753. Revision 1.81 2002/07/01 18:46:26 peter
  5754. * internal linker
  5755. * reorganized aasm layer
  5756. Revision 1.80 2002/07/01 16:23:54 peter
  5757. * cg64 patch
  5758. * basics for currency
  5759. * asnode updates for class and interface (not finished)
  5760. Revision 1.79 2002/05/18 13:34:18 peter
  5761. * readded missing revisions
  5762. Revision 1.78 2002/05/16 19:46:44 carl
  5763. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  5764. + try to fix temp allocation (still in ifdef)
  5765. + generic constructor calls
  5766. + start of tassembler / tmodulebase class cleanup
  5767. Revision 1.76 2002/05/12 16:53:10 peter
  5768. * moved entry and exitcode to ncgutil and cgobj
  5769. * foreach gets extra argument for passing local data to the
  5770. iterator function
  5771. * -CR checks also class typecasts at runtime by changing them
  5772. into as
  5773. * fixed compiler to cycle with the -CR option
  5774. * fixed stabs with elf writer, finally the global variables can
  5775. be watched
  5776. * removed a lot of routines from cga unit and replaced them by
  5777. calls to cgobj
  5778. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  5779. u32bit then the other is typecasted also to u32bit without giving
  5780. a rangecheck warning/error.
  5781. * fixed pascal calling method with reversing also the high tree in
  5782. the parast, detected by tcalcst3 test
  5783. Revision 1.75 2002/04/25 20:16:39 peter
  5784. * moved more routines from cga/n386util
  5785. Revision 1.74 2002/04/23 19:16:35 peter
  5786. * add pinline unit that inserts compiler supported functions using
  5787. one or more statements
  5788. * moved finalize and setlength from ninl to pinline
  5789. Revision 1.73 2002/04/21 19:02:05 peter
  5790. * removed newn and disposen nodes, the code is now directly
  5791. inlined from pexpr
  5792. * -an option that will write the secondpass nodes to the .s file, this
  5793. requires EXTDEBUG define to actually write the info
  5794. * fixed various internal errors and crashes due recent code changes
  5795. Revision 1.72 2002/04/20 21:32:25 carl
  5796. + generic FPC_CHECKPOINTER
  5797. + first parameter offset in stack now portable
  5798. * rename some constants
  5799. + move some cpu stuff to other units
  5800. - remove unused constents
  5801. * fix stacksize for some targets
  5802. * fix generic size problems which depend now on EXTEND_SIZE constant
  5803. }