symdef.pas 199 KB

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