symdef.pas 209 KB

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