symdef.pas 208 KB

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