symdef.pas 200 KB

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