symdef.pas 207 KB

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