symdef.pas 213 KB

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