symdef.pas 209 KB

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