symdef.pas 205 KB

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