symdef.pas 209 KB

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