symdef.pas 198 KB

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