symdef.pas 204 KB

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