symdef.pas 209 KB

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