symdef.pas 208 KB

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