symdef.pas 208 KB

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