symdef.pas 209 KB

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