symdef.pas 208 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit symdef;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,globals,tokens,
  26. { symtable }
  27. symconst,symbase,symtype,
  28. { ppu }
  29. 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. { only store user visible parameters }
  4023. if not pdc.is_hidden then
  4024. begin
  4025. case pdc.paratyp of
  4026. vs_value: paraspec := 0;
  4027. vs_const: paraspec := pfConst;
  4028. vs_var : paraspec := pfVar;
  4029. vs_out : paraspec := pfOut;
  4030. end;
  4031. { write flags for current parameter }
  4032. rttiList.concat(Tai_const.Create_8bit(paraspec));
  4033. { write name of current parameter }
  4034. if assigned(pdc.parasym) then
  4035. begin
  4036. rttiList.concat(Tai_const.Create_8bit(length(pdc.parasym.realname)));
  4037. rttiList.concat(Tai_string.Create(pdc.parasym.realname));
  4038. end
  4039. else
  4040. rttiList.concat(Tai_const.Create_8bit(0));
  4041. { write name of type of current parameter }
  4042. tstoreddef(pdc.paratype.def).write_rtti_name;
  4043. end;
  4044. if proccalloption in pushleftright_pocalls then
  4045. pdc:=TParaItem(pdc.next)
  4046. else
  4047. pdc:=TParaItem(pdc.previous);
  4048. end;
  4049. { write name of result type }
  4050. tstoreddef(rettype.def).write_rtti_name;
  4051. end;
  4052. end;
  4053. function tprocvardef.is_publishable : boolean;
  4054. begin
  4055. is_publishable:=(po_methodpointer in procoptions);
  4056. end;
  4057. function tprocvardef.gettypename : string;
  4058. var
  4059. s: string;
  4060. showhidden : boolean;
  4061. begin
  4062. {$ifdef EXTDEBUG}
  4063. showhidden:=true;
  4064. {$else EXTDEBUG}
  4065. showhidden:=false;
  4066. {$endif EXTDEBUG}
  4067. s:='<';
  4068. if po_classmethod in procoptions then
  4069. s := s+'class method type of'
  4070. else
  4071. if po_addressonly in procoptions then
  4072. s := s+'address of'
  4073. else
  4074. s := s+'procedure variable type of';
  4075. if assigned(rettype.def) and
  4076. (rettype.def<>voidtype.def) then
  4077. s:=s+' function'+typename_paras(showhidden)+':'+rettype.def.gettypename
  4078. else
  4079. s:=s+' procedure'+typename_paras(showhidden);
  4080. if po_methodpointer in procoptions then
  4081. s := s+' of object';
  4082. gettypename := s+';'+ProcCallOptionStr[proccalloption]+'>';
  4083. end;
  4084. {***************************************************************************
  4085. TOBJECTDEF
  4086. ***************************************************************************}
  4087. constructor tobjectdef.create(ot : tobjectdeftype;const n : string;c : tobjectdef);
  4088. begin
  4089. inherited create;
  4090. objecttype:=ot;
  4091. deftype:=objectdef;
  4092. objectoptions:=[];
  4093. childof:=nil;
  4094. symtable:=tobjectsymtable.create(n);
  4095. { create space for vmt !! }
  4096. vmt_offset:=0;
  4097. symtable.defowner:=self;
  4098. { recordalign -1 means C record packing, that starts
  4099. with an alignment of 1 }
  4100. if aktalignment.recordalignmax=-1 then
  4101. tobjectsymtable(symtable).dataalignment:=1
  4102. else
  4103. tobjectsymtable(symtable).dataalignment:=aktalignment.recordalignmax;
  4104. lastvtableindex:=0;
  4105. set_parent(c);
  4106. objname:=stringdup(upper(n));
  4107. objrealname:=stringdup(n);
  4108. if objecttype in [odt_interfacecorba,odt_interfacecom] then
  4109. prepareguid;
  4110. { setup implemented interfaces }
  4111. if objecttype in [odt_class,odt_interfacecorba] then
  4112. implementedinterfaces:=timplementedinterfaces.create
  4113. else
  4114. implementedinterfaces:=nil;
  4115. {$ifdef GDB}
  4116. writing_class_record_stab:=false;
  4117. {$endif GDB}
  4118. end;
  4119. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  4120. var
  4121. i,implintfcount: longint;
  4122. d : tderef;
  4123. begin
  4124. inherited ppuloaddef(ppufile);
  4125. deftype:=objectdef;
  4126. objecttype:=tobjectdeftype(ppufile.getbyte);
  4127. savesize:=ppufile.getlongint;
  4128. vmt_offset:=ppufile.getlongint;
  4129. objrealname:=stringdup(ppufile.getstring);
  4130. objname:=stringdup(upper(objrealname^));
  4131. ppufile.getderef(childofderef);
  4132. ppufile.getsmallset(objectoptions);
  4133. { load guid }
  4134. iidstr:=nil;
  4135. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4136. begin
  4137. new(iidguid);
  4138. ppufile.getguid(iidguid^);
  4139. iidstr:=stringdup(ppufile.getstring);
  4140. lastvtableindex:=ppufile.getlongint;
  4141. end;
  4142. { load implemented interfaces }
  4143. if objecttype in [odt_class,odt_interfacecorba] then
  4144. begin
  4145. implementedinterfaces:=timplementedinterfaces.create;
  4146. implintfcount:=ppufile.getlongint;
  4147. for i:=1 to implintfcount do
  4148. begin
  4149. ppufile.getderef(d);
  4150. implementedinterfaces.addintf_deref(d);
  4151. implementedinterfaces.ioffsets(i)^:=ppufile.getlongint;
  4152. end;
  4153. end
  4154. else
  4155. implementedinterfaces:=nil;
  4156. symtable:=tobjectsymtable.create(objrealname^);
  4157. tobjectsymtable(symtable).datasize:=ppufile.getlongint;
  4158. tobjectsymtable(symtable).dataalignment:=ppufile.getbyte;
  4159. tobjectsymtable(symtable).ppuload(ppufile);
  4160. symtable.defowner:=self;
  4161. { handles the predefined class tobject }
  4162. { the last TOBJECT which is loaded gets }
  4163. { it ! }
  4164. if (childof=nil) and
  4165. (objecttype=odt_class) and
  4166. (objname^='TOBJECT') then
  4167. class_tobject:=self;
  4168. if (childof=nil) and
  4169. (objecttype=odt_interfacecom) and
  4170. (objname^='IUNKNOWN') then
  4171. interface_iunknown:=self;
  4172. {$ifdef GDB}
  4173. writing_class_record_stab:=false;
  4174. {$endif GDB}
  4175. end;
  4176. destructor tobjectdef.destroy;
  4177. begin
  4178. if assigned(symtable) then
  4179. symtable.free;
  4180. stringdispose(objname);
  4181. stringdispose(objrealname);
  4182. if assigned(iidstr) then
  4183. stringdispose(iidstr);
  4184. if assigned(implementedinterfaces) then
  4185. implementedinterfaces.free;
  4186. if assigned(iidguid) then
  4187. dispose(iidguid);
  4188. inherited destroy;
  4189. end;
  4190. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  4191. var
  4192. implintfcount : longint;
  4193. i : longint;
  4194. begin
  4195. inherited ppuwritedef(ppufile);
  4196. ppufile.putbyte(byte(objecttype));
  4197. ppufile.putlongint(size);
  4198. ppufile.putlongint(vmt_offset);
  4199. ppufile.putstring(objrealname^);
  4200. ppufile.putderef(childofderef);
  4201. ppufile.putsmallset(objectoptions);
  4202. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4203. begin
  4204. ppufile.putguid(iidguid^);
  4205. ppufile.putstring(iidstr^);
  4206. ppufile.putlongint(lastvtableindex);
  4207. end;
  4208. if objecttype in [odt_class,odt_interfacecorba] then
  4209. begin
  4210. implintfcount:=implementedinterfaces.count;
  4211. ppufile.putlongint(implintfcount);
  4212. for i:=1 to implintfcount do
  4213. begin
  4214. ppufile.putderef(implementedinterfaces.interfacesderef(i));
  4215. ppufile.putlongint(implementedinterfaces.ioffsets(i)^);
  4216. end;
  4217. end;
  4218. ppufile.putlongint(tobjectsymtable(symtable).datasize);
  4219. ppufile.putbyte(tobjectsymtable(symtable).dataalignment);
  4220. ppufile.writeentry(ibobjectdef);
  4221. tobjectsymtable(symtable).ppuwrite(ppufile);
  4222. end;
  4223. function tobjectdef.gettypename:string;
  4224. begin
  4225. gettypename:=typename;
  4226. end;
  4227. procedure tobjectdef.buildderef;
  4228. var
  4229. oldrecsyms : tsymtable;
  4230. begin
  4231. inherited buildderef;
  4232. childofderef.build(childof);
  4233. oldrecsyms:=aktrecordsymtable;
  4234. aktrecordsymtable:=symtable;
  4235. tstoredsymtable(symtable).buildderef;
  4236. aktrecordsymtable:=oldrecsyms;
  4237. if objecttype in [odt_class,odt_interfacecorba] then
  4238. implementedinterfaces.buildderef;
  4239. end;
  4240. procedure tobjectdef.deref;
  4241. var
  4242. oldrecsyms : tsymtable;
  4243. begin
  4244. inherited deref;
  4245. childof:=tobjectdef(childofderef.resolve);
  4246. oldrecsyms:=aktrecordsymtable;
  4247. aktrecordsymtable:=symtable;
  4248. tstoredsymtable(symtable).deref;
  4249. aktrecordsymtable:=oldrecsyms;
  4250. if objecttype in [odt_class,odt_interfacecorba] then
  4251. implementedinterfaces.deref;
  4252. end;
  4253. function tobjectdef.getparentdef:tdef;
  4254. begin
  4255. result:=childof;
  4256. end;
  4257. procedure tobjectdef.prepareguid;
  4258. begin
  4259. { set up guid }
  4260. if not assigned(iidguid) then
  4261. begin
  4262. new(iidguid);
  4263. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  4264. end;
  4265. { setup iidstring }
  4266. if not assigned(iidstr) then
  4267. iidstr:=stringdup(''); { default is empty string }
  4268. end;
  4269. procedure tobjectdef.set_parent( c : tobjectdef);
  4270. begin
  4271. { nothing to do if the parent was not forward !}
  4272. if assigned(childof) then
  4273. exit;
  4274. childof:=c;
  4275. { some options are inherited !! }
  4276. if assigned(c) then
  4277. begin
  4278. { only important for classes }
  4279. lastvtableindex:=c.lastvtableindex;
  4280. objectoptions:=objectoptions+(c.objectoptions*
  4281. [oo_has_virtual,oo_has_private,oo_has_protected,
  4282. oo_has_constructor,oo_has_destructor]);
  4283. if not (objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4284. begin
  4285. { add the data of the anchestor class }
  4286. inc(tobjectsymtable(symtable).datasize,tobjectsymtable(c.symtable).datasize);
  4287. if (oo_has_vmt in objectoptions) and
  4288. (oo_has_vmt in c.objectoptions) then
  4289. dec(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4290. { if parent has a vmt field then
  4291. the offset is the same for the child PM }
  4292. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  4293. begin
  4294. vmt_offset:=c.vmt_offset;
  4295. include(objectoptions,oo_has_vmt);
  4296. end;
  4297. end;
  4298. end;
  4299. savesize := tobjectsymtable(symtable).datasize;
  4300. end;
  4301. procedure tobjectdef.insertvmt;
  4302. begin
  4303. if objecttype in [odt_interfacecom,odt_interfacecorba] then
  4304. exit;
  4305. if (oo_has_vmt in objectoptions) then
  4306. internalerror(12345)
  4307. else
  4308. begin
  4309. tobjectsymtable(symtable).datasize:=align(tobjectsymtable(symtable).datasize,
  4310. tobjectsymtable(symtable).dataalignment);
  4311. vmt_offset:=tobjectsymtable(symtable).datasize;
  4312. inc(tobjectsymtable(symtable).datasize,POINTER_SIZE);
  4313. include(objectoptions,oo_has_vmt);
  4314. end;
  4315. end;
  4316. procedure tobjectdef.check_forwards;
  4317. begin
  4318. if not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4319. tstoredsymtable(symtable).check_forwards;
  4320. if (oo_is_forward in objectoptions) then
  4321. begin
  4322. { ok, in future, the forward can be resolved }
  4323. Message1(sym_e_class_forward_not_resolved,objrealname^);
  4324. exclude(objectoptions,oo_is_forward);
  4325. end;
  4326. end;
  4327. { true, if self inherits from d (or if they are equal) }
  4328. function tobjectdef.is_related(d : tobjectdef) : boolean;
  4329. var
  4330. hp : tobjectdef;
  4331. begin
  4332. hp:=self;
  4333. while assigned(hp) do
  4334. begin
  4335. if hp=d then
  4336. begin
  4337. is_related:=true;
  4338. exit;
  4339. end;
  4340. hp:=hp.childof;
  4341. end;
  4342. is_related:=false;
  4343. end;
  4344. (* procedure tobjectdef._searchdestructor(sym : tnamedindexitem;arg:pointer);
  4345. var
  4346. p : pprocdeflist;
  4347. begin
  4348. { if we found already a destructor, then we exit }
  4349. if assigned(sd) then
  4350. exit;
  4351. if tsym(sym).typ=procsym then
  4352. begin
  4353. p:=tprocsym(sym).defs;
  4354. while assigned(p) do
  4355. begin
  4356. if p^.def.proctypeoption=potype_destructor then
  4357. begin
  4358. sd:=p^.def;
  4359. exit;
  4360. end;
  4361. p:=p^.next;
  4362. end;
  4363. end;
  4364. end;*)
  4365. procedure _searchdestructor(sym:Tnamedindexitem;sd:pointer);
  4366. begin
  4367. { if we found already a destructor, then we exit }
  4368. if (ppointer(sd)^=nil) and
  4369. (Tsym(sym).typ=procsym) then
  4370. ppointer(sd)^:=Tprocsym(sym).search_procdef_bytype(potype_destructor);
  4371. end;
  4372. function tobjectdef.searchdestructor : tprocdef;
  4373. var
  4374. o : tobjectdef;
  4375. sd : tprocdef;
  4376. begin
  4377. searchdestructor:=nil;
  4378. o:=self;
  4379. sd:=nil;
  4380. while assigned(o) do
  4381. begin
  4382. o.symtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}_searchdestructor,@sd);
  4383. if assigned(sd) then
  4384. begin
  4385. searchdestructor:=sd;
  4386. exit;
  4387. end;
  4388. o:=o.childof;
  4389. end;
  4390. end;
  4391. function tobjectdef.size : longint;
  4392. begin
  4393. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba] then
  4394. result:=POINTER_SIZE
  4395. else
  4396. result:=tobjectsymtable(symtable).datasize;
  4397. end;
  4398. function tobjectdef.alignment:longint;
  4399. begin
  4400. alignment:=tobjectsymtable(symtable).dataalignment;
  4401. end;
  4402. function tobjectdef.vmtmethodoffset(index:longint):longint;
  4403. begin
  4404. { for offset of methods for classes, see rtl/inc/objpash.inc }
  4405. case objecttype of
  4406. odt_class:
  4407. vmtmethodoffset:=(index+12)*POINTER_SIZE;
  4408. odt_interfacecom,odt_interfacecorba:
  4409. vmtmethodoffset:=index*POINTER_SIZE;
  4410. else
  4411. {$ifdef WITHDMT}
  4412. vmtmethodoffset:=(index+4)*POINTER_SIZE;
  4413. {$else WITHDMT}
  4414. vmtmethodoffset:=(index+3)*POINTER_SIZE;
  4415. {$endif WITHDMT}
  4416. end;
  4417. end;
  4418. function tobjectdef.vmt_mangledname : string;
  4419. begin
  4420. if not(oo_has_vmt in objectoptions) then
  4421. Message1(parser_n_object_has_no_vmt,objrealname^);
  4422. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  4423. end;
  4424. function tobjectdef.rtti_name : string;
  4425. begin
  4426. rtti_name:=make_mangledname('RTTI',owner,objname^);
  4427. end;
  4428. {$ifdef GDB}
  4429. procedure tobjectdef.addprocname(p :tnamedindexitem;arg:pointer);
  4430. var virtualind,argnames : string;
  4431. news, newrec : pchar;
  4432. pd,ipd : tprocdef;
  4433. lindex : longint;
  4434. para : TParaItem;
  4435. arglength : byte;
  4436. sp : char;
  4437. begin
  4438. If tsym(p).typ = procsym then
  4439. begin
  4440. pd := tprocsym(p).first_procdef;
  4441. { this will be used for full implementation of object stabs
  4442. not yet done }
  4443. ipd := Tprocsym(p).last_procdef;
  4444. if (po_virtualmethod in pd.procoptions) then
  4445. begin
  4446. lindex := pd.extnumber;
  4447. {doesnt seem to be necessary
  4448. lindex := lindex or $80000000;}
  4449. virtualind := '*'+tostr(lindex)+';'+ipd._class.classnumberstring+';'
  4450. end
  4451. else
  4452. virtualind := '.';
  4453. { used by gdbpas to recognize constructor and destructors }
  4454. if (pd.proctypeoption=potype_constructor) then
  4455. argnames:='__ct__'
  4456. else if (pd.proctypeoption=potype_destructor) then
  4457. argnames:='__dt__'
  4458. else
  4459. argnames := '';
  4460. { arguments are not listed here }
  4461. {we don't need another definition}
  4462. para := TParaItem(pd.Para.first);
  4463. while assigned(para) do
  4464. begin
  4465. if Para.paratype.def.deftype = formaldef then
  4466. begin
  4467. if Para.paratyp=vs_var then
  4468. argnames := argnames+'3var'
  4469. else if Para.paratyp=vs_const then
  4470. argnames:=argnames+'5const'
  4471. else if Para.paratyp=vs_out then
  4472. argnames:=argnames+'3out';
  4473. end
  4474. else
  4475. begin
  4476. { if the arg definition is like (v: ^byte;..
  4477. there is no sym attached to data !!! }
  4478. if assigned(Para.paratype.def.typesym) then
  4479. begin
  4480. arglength := length(Para.paratype.def.typesym.name);
  4481. argnames := argnames + tostr(arglength)+Para.paratype.def.typesym.name;
  4482. end
  4483. else
  4484. begin
  4485. argnames:=argnames+'11unnamedtype';
  4486. end;
  4487. end;
  4488. para := TParaItem(Para.next);
  4489. end;
  4490. ipd.is_def_stab_written := written;
  4491. { here 2A must be changed for private and protected }
  4492. { 0 is private 1 protected and 2 public }
  4493. if (sp_private in tsym(p).symoptions) then sp:='0'
  4494. else if (sp_protected in tsym(p).symoptions) then sp:='1'
  4495. else sp:='2';
  4496. newrec := strpnew(p.name+'::'+ipd.numberstring
  4497. +'=##'+tstoreddef(pd.rettype.def).numberstring+';:'+argnames+';'+sp+'A'
  4498. +virtualind+';');
  4499. { get spare place for a string at the end }
  4500. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  4501. begin
  4502. getmem(news,stabrecsize+memsizeinc);
  4503. strcopy(news,stabrecstring);
  4504. freemem(stabrecstring,stabrecsize);
  4505. stabrecsize:=stabrecsize+memsizeinc;
  4506. stabrecstring:=news;
  4507. end;
  4508. strcat(StabRecstring,newrec);
  4509. {freemem(newrec,memsizeinc); }
  4510. strdispose(newrec);
  4511. {This should be used for case !!
  4512. RecOffset := RecOffset + pd.size;}
  4513. end;
  4514. end;
  4515. function tobjectdef.stabstring : pchar;
  4516. var anc : tobjectdef;
  4517. oldrec : pchar;
  4518. oldrecsize,oldrecoffset : longint;
  4519. str_end : string;
  4520. begin
  4521. if not (objecttype=odt_class) or writing_class_record_stab then
  4522. begin
  4523. oldrec := stabrecstring;
  4524. oldrecsize:=stabrecsize;
  4525. stabrecsize:=memsizeinc;
  4526. GetMem(stabrecstring,stabrecsize);
  4527. strpcopy(stabRecString,'s'+tostr(tobjectsymtable(symtable).datasize));
  4528. if assigned(childof) then
  4529. begin
  4530. {only one ancestor not virtual, public, at base offset 0 }
  4531. { !1 , 0 2 0 , }
  4532. strpcopy(strend(stabrecstring),'!1,020,'+childof.classnumberstring+';');
  4533. end;
  4534. {virtual table to implement yet}
  4535. OldRecOffset:=RecOffset;
  4536. RecOffset := 0;
  4537. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addname,nil);
  4538. RecOffset:=OldRecOffset;
  4539. if (oo_has_vmt in objectoptions) then
  4540. if not assigned(childof) or not(oo_has_vmt in childof.objectoptions) then
  4541. begin
  4542. strpcopy(strend(stabrecstring),'$vf'+classnumberstring+':'+typeglobalnumber('vtblarray')
  4543. +','+tostr(vmt_offset*8)+';');
  4544. end;
  4545. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}addprocname,nil);
  4546. if (oo_has_vmt in objectoptions) then
  4547. begin
  4548. anc := self;
  4549. while assigned(anc.childof) and (oo_has_vmt in anc.childof.objectoptions) do
  4550. anc := anc.childof;
  4551. { just in case anc = self }
  4552. str_end:=';~%'+anc.classnumberstring+';';
  4553. end
  4554. else
  4555. str_end:=';';
  4556. strpcopy(strend(stabrecstring),str_end);
  4557. stabstring := strnew(StabRecString);
  4558. freemem(stabrecstring,stabrecsize);
  4559. stabrecstring := oldrec;
  4560. stabrecsize:=oldrecsize;
  4561. end
  4562. else
  4563. begin
  4564. stabstring:=strpnew('*'+classnumberstring);
  4565. end;
  4566. end;
  4567. procedure tobjectdef.set_globalnb;
  4568. begin
  4569. globalnb:=PglobalTypeCount^;
  4570. inc(PglobalTypeCount^);
  4571. { classes need two type numbers, the globalnb is set to the ptr }
  4572. if objecttype=odt_class then
  4573. begin
  4574. globalnb:=PGlobalTypeCount^;
  4575. inc(PglobalTypeCount^);
  4576. end;
  4577. end;
  4578. function tobjectdef.classnumberstring : string;
  4579. begin
  4580. { write stabs again if needed }
  4581. numberstring;
  4582. if objecttype=odt_class then
  4583. begin
  4584. dec(globalnb);
  4585. classnumberstring:=numberstring;
  4586. inc(globalnb);
  4587. end
  4588. else
  4589. classnumberstring:=numberstring;
  4590. end;
  4591. function tobjectdef.allstabstring : pchar;
  4592. var stabchar : string[2];
  4593. ss,st : pchar;
  4594. sname : string;
  4595. sym_line_no : longint;
  4596. begin
  4597. ss := stabstring;
  4598. getmem(st,strlen(ss)+512);
  4599. stabchar := 't';
  4600. if deftype in tagtypes then
  4601. stabchar := 'Tt';
  4602. if assigned(typesym) then
  4603. begin
  4604. sname := typesym.name;
  4605. sym_line_no:=typesym.fileinfo.line;
  4606. end
  4607. else
  4608. begin
  4609. sname := ' ';
  4610. sym_line_no:=0;
  4611. end;
  4612. if writing_class_record_stab then
  4613. strpcopy(st,'"'+sname+':'+stabchar+classnumberstring+'=')
  4614. else
  4615. strpcopy(st,'"'+sname+':'+stabchar+numberstring+'=');
  4616. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  4617. allstabstring := strnew(st);
  4618. freemem(st,strlen(ss)+512);
  4619. strdispose(ss);
  4620. end;
  4621. procedure tobjectdef.concatstabto(asmlist : taasmoutput);
  4622. var st:string;
  4623. begin
  4624. if objecttype<>odt_class then
  4625. begin
  4626. inherited concatstabto(asmlist);
  4627. exit;
  4628. end;
  4629. if ((typesym=nil) or ttypesym(typesym).isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  4630. (is_def_stab_written = not_written) then
  4631. begin
  4632. if globalnb=0 then
  4633. set_globalnb;
  4634. { Write the record class itself }
  4635. writing_class_record_stab:=true;
  4636. inherited concatstabto(asmlist);
  4637. writing_class_record_stab:=false;
  4638. { Write the invisible pointer class }
  4639. is_def_stab_written:=not_written;
  4640. if assigned(typesym) then
  4641. begin
  4642. st:=typesym.name;
  4643. typesym.name:=' ';
  4644. end;
  4645. inherited concatstabto(asmlist);
  4646. if assigned(typesym) then
  4647. typesym.name:=st;
  4648. end;
  4649. end;
  4650. {$endif GDB}
  4651. function tobjectdef.needs_inittable : boolean;
  4652. begin
  4653. case objecttype of
  4654. odt_class :
  4655. needs_inittable:=false;
  4656. odt_interfacecom:
  4657. needs_inittable:=true;
  4658. odt_interfacecorba:
  4659. needs_inittable:=is_related(interface_iunknown);
  4660. odt_object:
  4661. needs_inittable:=tobjectsymtable(symtable).needs_init_final;
  4662. else
  4663. internalerror(200108267);
  4664. end;
  4665. end;
  4666. function tobjectdef.members_need_inittable : boolean;
  4667. begin
  4668. members_need_inittable:=tobjectsymtable(symtable).needs_init_final;
  4669. end;
  4670. procedure tobjectdef.count_published_properties(sym:tnamedindexitem;arg:pointer);
  4671. begin
  4672. if needs_prop_entry(tsym(sym)) and
  4673. (tsym(sym).typ<>varsym) then
  4674. inc(count);
  4675. end;
  4676. procedure tobjectdef.write_property_info(sym : tnamedindexitem;arg:pointer);
  4677. var
  4678. proctypesinfo : byte;
  4679. procedure writeproc(proc : tsymlist; shiftvalue : byte);
  4680. var
  4681. typvalue : byte;
  4682. hp : psymlistitem;
  4683. address : longint;
  4684. begin
  4685. if not(assigned(proc) and assigned(proc.firstsym)) then
  4686. begin
  4687. rttiList.concat(Tai_const.Create_32bit(1));
  4688. typvalue:=3;
  4689. end
  4690. else if proc.firstsym^.sym.typ=varsym then
  4691. begin
  4692. address:=0;
  4693. hp:=proc.firstsym;
  4694. while assigned(hp) do
  4695. begin
  4696. inc(address,tvarsym(hp^.sym).fieldoffset);
  4697. hp:=hp^.next;
  4698. end;
  4699. rttiList.concat(Tai_const.Create_32bit(address));
  4700. typvalue:=0;
  4701. end
  4702. else
  4703. begin
  4704. { When there was an error then procdef is not assigned }
  4705. if not assigned(proc.procdef) then
  4706. exit;
  4707. if not(po_virtualmethod in tprocdef(proc.procdef).procoptions) then
  4708. begin
  4709. rttiList.concat(Tai_const_symbol.Createname(tprocdef(proc.procdef).mangledname));
  4710. typvalue:=1;
  4711. end
  4712. else
  4713. begin
  4714. { virtual method, write vmt offset }
  4715. rttiList.concat(Tai_const.Create_32bit(
  4716. tprocdef(proc.procdef)._class.vmtmethodoffset(tprocdef(proc.procdef).extnumber)));
  4717. typvalue:=2;
  4718. end;
  4719. end;
  4720. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  4721. end;
  4722. begin
  4723. if needs_prop_entry(tsym(sym)) then
  4724. case tsym(sym).typ of
  4725. varsym:
  4726. begin
  4727. {$ifdef dummy}
  4728. if not(tvarsym(sym).vartype.def.deftype=objectdef) or
  4729. not(tobjectdef(tvarsym(sym).vartype.def).is_class) then
  4730. internalerror(1509992);
  4731. { access to implicit class property as field }
  4732. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  4733. rttiList.concat(Tai_const_symbol.Createname(tvarsym(sym.vartype.def.get_rtti_label)));
  4734. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4735. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym.address)));
  4736. { per default stored }
  4737. rttiList.concat(Tai_const.Create_32bit(1));
  4738. { index as well as ... }
  4739. rttiList.concat(Tai_const.Create_32bit(0));
  4740. { default value are zero }
  4741. rttiList.concat(Tai_const.Create_32bit(0));
  4742. rttiList.concat(Tai_const.Create_16bit(count));
  4743. inc(count);
  4744. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4745. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym.realname))));
  4746. rttiList.concat(Tai_string.Create(tvarsym(sym.realname)));
  4747. {$endif dummy}
  4748. end;
  4749. propertysym:
  4750. begin
  4751. if ppo_indexed in tpropertysym(sym).propoptions then
  4752. proctypesinfo:=$40
  4753. else
  4754. proctypesinfo:=0;
  4755. rttiList.concat(Tai_const_symbol.Create(tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti)));
  4756. writeproc(tpropertysym(sym).readaccess,0);
  4757. writeproc(tpropertysym(sym).writeaccess,2);
  4758. { isn't it stored ? }
  4759. if not(ppo_stored in tpropertysym(sym).propoptions) then
  4760. begin
  4761. rttiList.concat(Tai_const.Create_32bit(0));
  4762. proctypesinfo:=proctypesinfo or (3 shl 4);
  4763. end
  4764. else
  4765. writeproc(tpropertysym(sym).storedaccess,4);
  4766. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).index));
  4767. rttiList.concat(Tai_const.Create_32bit(tpropertysym(sym).default));
  4768. rttiList.concat(Tai_const.Create_16bit(count));
  4769. inc(count);
  4770. rttiList.concat(Tai_const.Create_8bit(proctypesinfo));
  4771. rttiList.concat(Tai_const.Create_8bit(length(tpropertysym(sym).realname)));
  4772. rttiList.concat(Tai_string.Create(tpropertysym(sym).realname));
  4773. end;
  4774. else internalerror(1509992);
  4775. end;
  4776. end;
  4777. procedure tobjectdef.generate_published_child_rtti(sym : tnamedindexitem;arg:pointer);
  4778. begin
  4779. if needs_prop_entry(tsym(sym)) then
  4780. begin
  4781. case tsym(sym).typ of
  4782. propertysym:
  4783. tstoreddef(tpropertysym(sym).proptype.def).get_rtti_label(fullrtti);
  4784. varsym:
  4785. tstoreddef(tvarsym(sym).vartype.def).get_rtti_label(fullrtti);
  4786. else
  4787. internalerror(1509991);
  4788. end;
  4789. end;
  4790. end;
  4791. procedure tobjectdef.write_child_rtti_data(rt:trttitype);
  4792. begin
  4793. FRTTIType:=rt;
  4794. case rt of
  4795. initrtti :
  4796. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_field_rtti,nil);
  4797. fullrtti :
  4798. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}generate_published_child_rtti,nil);
  4799. else
  4800. internalerror(200108301);
  4801. end;
  4802. end;
  4803. type
  4804. tclasslistitem = class(TLinkedListItem)
  4805. index : longint;
  4806. p : tobjectdef;
  4807. end;
  4808. var
  4809. classtablelist : tlinkedlist;
  4810. tablecount : longint;
  4811. function searchclasstablelist(p : tobjectdef) : tclasslistitem;
  4812. var
  4813. hp : tclasslistitem;
  4814. begin
  4815. hp:=tclasslistitem(classtablelist.first);
  4816. while assigned(hp) do
  4817. if hp.p=p then
  4818. begin
  4819. searchclasstablelist:=hp;
  4820. exit;
  4821. end
  4822. else
  4823. hp:=tclasslistitem(hp.next);
  4824. searchclasstablelist:=nil;
  4825. end;
  4826. procedure tobjectdef.count_published_fields(sym:tnamedindexitem;arg:pointer);
  4827. var
  4828. hp : tclasslistitem;
  4829. begin
  4830. if needs_prop_entry(tsym(sym)) and
  4831. (tsym(sym).typ=varsym) then
  4832. begin
  4833. if tvarsym(sym).vartype.def.deftype<>objectdef then
  4834. internalerror(0206001);
  4835. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4836. if not(assigned(hp)) then
  4837. begin
  4838. hp:=tclasslistitem.create;
  4839. hp.p:=tobjectdef(tvarsym(sym).vartype.def);
  4840. hp.index:=tablecount;
  4841. classtablelist.concat(hp);
  4842. inc(tablecount);
  4843. end;
  4844. inc(count);
  4845. end;
  4846. end;
  4847. procedure tobjectdef.writefields(sym:tnamedindexitem;arg:pointer);
  4848. var
  4849. hp : tclasslistitem;
  4850. begin
  4851. if needs_prop_entry(tsym(sym)) and
  4852. (tsym(sym).typ=varsym) then
  4853. begin
  4854. rttiList.concat(Tai_const.Create_32bit(tvarsym(sym).fieldoffset));
  4855. hp:=searchclasstablelist(tobjectdef(tvarsym(sym).vartype.def));
  4856. if not(assigned(hp)) then
  4857. internalerror(0206002);
  4858. rttiList.concat(Tai_const.Create_16bit(hp.index));
  4859. rttiList.concat(Tai_const.Create_8bit(length(tvarsym(sym).realname)));
  4860. rttiList.concat(Tai_string.Create(tvarsym(sym).realname));
  4861. end;
  4862. end;
  4863. function tobjectdef.generate_field_table : tasmlabel;
  4864. var
  4865. fieldtable,
  4866. classtable : tasmlabel;
  4867. hp : tclasslistitem;
  4868. begin
  4869. classtablelist:=TLinkedList.Create;
  4870. objectlibrary.getdatalabel(fieldtable);
  4871. objectlibrary.getdatalabel(classtable);
  4872. count:=0;
  4873. tablecount:=0;
  4874. symtable.foreach({$ifdef FPC}@{$endif}count_published_fields,nil);
  4875. if (cs_create_smart in aktmoduleswitches) then
  4876. rttiList.concat(Tai_cut.Create);
  4877. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4878. rttiList.concat(Tai_label.Create(fieldtable));
  4879. rttiList.concat(Tai_const.Create_16bit(count));
  4880. rttiList.concat(Tai_const_symbol.Create(classtable));
  4881. symtable.foreach({$ifdef FPC}@{$endif}writefields,nil);
  4882. { generate the class table }
  4883. rttilist.concat(tai_align.create(const_align(pointer_size)));
  4884. rttiList.concat(Tai_label.Create(classtable));
  4885. rttiList.concat(Tai_const.Create_16bit(tablecount));
  4886. hp:=tclasslistitem(classtablelist.first);
  4887. while assigned(hp) do
  4888. begin
  4889. rttiList.concat(Tai_const_symbol.Createname(tobjectdef(hp.p).vmt_mangledname));
  4890. hp:=tclasslistitem(hp.next);
  4891. end;
  4892. generate_field_table:=fieldtable;
  4893. classtablelist.free;
  4894. end;
  4895. function tobjectdef.next_free_name_index : longint;
  4896. var
  4897. i : longint;
  4898. begin
  4899. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4900. i:=childof.next_free_name_index
  4901. else
  4902. i:=0;
  4903. count:=0;
  4904. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4905. next_free_name_index:=i+count;
  4906. end;
  4907. procedure tobjectdef.write_rtti_data(rt:trttitype);
  4908. begin
  4909. case objecttype of
  4910. odt_class:
  4911. rttiList.concat(Tai_const.Create_8bit(tkclass));
  4912. odt_object:
  4913. rttiList.concat(Tai_const.Create_8bit(tkobject));
  4914. odt_interfacecom:
  4915. rttiList.concat(Tai_const.Create_8bit(tkinterface));
  4916. odt_interfacecorba:
  4917. rttiList.concat(Tai_const.Create_8bit(tkinterfaceCorba));
  4918. else
  4919. exit;
  4920. end;
  4921. { generate the name }
  4922. rttiList.concat(Tai_const.Create_8bit(length(objrealname^)));
  4923. rttiList.concat(Tai_string.Create(objrealname^));
  4924. case rt of
  4925. initrtti :
  4926. begin
  4927. rttiList.concat(Tai_const.Create_32bit(size));
  4928. if objecttype in [odt_class,odt_object] then
  4929. begin
  4930. count:=0;
  4931. FRTTIType:=rt;
  4932. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_field_rtti,nil);
  4933. rttiList.concat(Tai_const.Create_32bit(count));
  4934. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_field_rtti,nil);
  4935. end;
  4936. end;
  4937. fullrtti :
  4938. begin
  4939. if (oo_has_vmt in objectoptions) and
  4940. not(objecttype in [odt_interfacecom,odt_interfacecorba]) then
  4941. rttiList.concat(Tai_const_symbol.Createname(vmt_mangledname))
  4942. else
  4943. rttiList.concat(Tai_const.Create_32bit(0));
  4944. { write owner typeinfo }
  4945. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4946. rttiList.concat(Tai_const_symbol.Create(childof.get_rtti_label(fullrtti)))
  4947. else
  4948. rttiList.concat(Tai_const.Create_32bit(0));
  4949. { count total number of properties }
  4950. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4951. count:=childof.next_free_name_index
  4952. else
  4953. count:=0;
  4954. { write it }
  4955. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4956. rttiList.concat(Tai_const.Create_16bit(count));
  4957. { write unit name }
  4958. rttiList.concat(Tai_const.Create_8bit(length(current_module.realmodulename^)));
  4959. rttiList.concat(Tai_string.Create(current_module.realmodulename^));
  4960. { write published properties count }
  4961. count:=0;
  4962. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}count_published_properties,nil);
  4963. rttiList.concat(Tai_const.Create_16bit(count));
  4964. { count is used to write nameindex }
  4965. { but we need an offset of the owner }
  4966. { to give each property an own slot }
  4967. if assigned(childof) and (oo_can_have_published in childof.objectoptions) then
  4968. count:=childof.next_free_name_index
  4969. else
  4970. count:=0;
  4971. symtable.foreach({$ifdef FPCPROCVAR}@{$endif}write_property_info,nil);
  4972. end;
  4973. end;
  4974. end;
  4975. function tobjectdef.is_publishable : boolean;
  4976. begin
  4977. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba];
  4978. end;
  4979. {****************************************************************************
  4980. TIMPLEMENTEDINTERFACES
  4981. ****************************************************************************}
  4982. type
  4983. tnamemap = class(TNamedIndexItem)
  4984. newname: pstring;
  4985. constructor create(const aname, anewname: string);
  4986. destructor destroy; override;
  4987. end;
  4988. constructor tnamemap.create(const aname, anewname: string);
  4989. begin
  4990. inherited createname(name);
  4991. newname:=stringdup(anewname);
  4992. end;
  4993. destructor tnamemap.destroy;
  4994. begin
  4995. stringdispose(newname);
  4996. inherited destroy;
  4997. end;
  4998. type
  4999. tprocdefstore = class(TNamedIndexItem)
  5000. procdef: tprocdef;
  5001. constructor create(aprocdef: tprocdef);
  5002. end;
  5003. constructor tprocdefstore.create(aprocdef: tprocdef);
  5004. begin
  5005. inherited create;
  5006. procdef:=aprocdef;
  5007. end;
  5008. type
  5009. timplintfentry = class(TNamedIndexItem)
  5010. intf: tobjectdef;
  5011. intfderef : tderef;
  5012. ioffs: longint;
  5013. namemappings: tdictionary;
  5014. procdefs: TIndexArray;
  5015. constructor create(aintf: tobjectdef);
  5016. constructor create_deref(const d:tderef);
  5017. destructor destroy; override;
  5018. end;
  5019. constructor timplintfentry.create(aintf: tobjectdef);
  5020. begin
  5021. inherited create;
  5022. intf:=aintf;
  5023. ioffs:=-1;
  5024. namemappings:=nil;
  5025. procdefs:=nil;
  5026. end;
  5027. constructor timplintfentry.create_deref(const d:tderef);
  5028. begin
  5029. inherited create;
  5030. intf:=nil;
  5031. intfderef:=d;
  5032. ioffs:=-1;
  5033. namemappings:=nil;
  5034. procdefs:=nil;
  5035. end;
  5036. destructor timplintfentry.destroy;
  5037. begin
  5038. if assigned(namemappings) then
  5039. namemappings.free;
  5040. if assigned(procdefs) then
  5041. procdefs.free;
  5042. inherited destroy;
  5043. end;
  5044. constructor timplementedinterfaces.create;
  5045. begin
  5046. finterfaces:=tindexarray.create(1);
  5047. end;
  5048. destructor timplementedinterfaces.destroy;
  5049. begin
  5050. finterfaces.destroy;
  5051. end;
  5052. function timplementedinterfaces.count: longint;
  5053. begin
  5054. count:=finterfaces.count;
  5055. end;
  5056. procedure timplementedinterfaces.checkindex(intfindex: longint);
  5057. begin
  5058. if (intfindex<1) or (intfindex>count) then
  5059. InternalError(200006123);
  5060. end;
  5061. function timplementedinterfaces.interfaces(intfindex: longint): tobjectdef;
  5062. begin
  5063. checkindex(intfindex);
  5064. interfaces:=timplintfentry(finterfaces.search(intfindex)).intf;
  5065. end;
  5066. function timplementedinterfaces.interfacesderef(intfindex: longint): tderef;
  5067. begin
  5068. checkindex(intfindex);
  5069. interfacesderef:=timplintfentry(finterfaces.search(intfindex)).intfderef;
  5070. end;
  5071. function timplementedinterfaces.ioffsets(intfindex: longint): plongint;
  5072. begin
  5073. checkindex(intfindex);
  5074. ioffsets:=@timplintfentry(finterfaces.search(intfindex)).ioffs;
  5075. end;
  5076. function timplementedinterfaces.searchintf(def: tdef): longint;
  5077. var
  5078. i: longint;
  5079. begin
  5080. i:=1;
  5081. while (i<=count) and (tdef(interfaces(i))<>def) do inc(i);
  5082. if i<=count then
  5083. searchintf:=i
  5084. else
  5085. searchintf:=-1;
  5086. end;
  5087. procedure timplementedinterfaces.buildderef;
  5088. var
  5089. i: longint;
  5090. begin
  5091. for i:=1 to count do
  5092. with timplintfentry(finterfaces.search(i)) do
  5093. intfderef.build(intf);
  5094. end;
  5095. procedure timplementedinterfaces.deref;
  5096. var
  5097. i: longint;
  5098. begin
  5099. for i:=1 to count do
  5100. with timplintfentry(finterfaces.search(i)) do
  5101. intf:=tobjectdef(intfderef.resolve);
  5102. end;
  5103. procedure timplementedinterfaces.addintf_deref(const d:tderef);
  5104. begin
  5105. finterfaces.insert(timplintfentry.create_deref(d));
  5106. end;
  5107. procedure timplementedinterfaces.addintf(def: tdef);
  5108. begin
  5109. if not assigned(def) or (searchintf(def)<>-1) or (def.deftype<>objectdef) or
  5110. not (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]) then
  5111. internalerror(200006124);
  5112. finterfaces.insert(timplintfentry.create(tobjectdef(def)));
  5113. end;
  5114. procedure timplementedinterfaces.clearmappings;
  5115. var
  5116. i: longint;
  5117. begin
  5118. for i:=1 to count do
  5119. with timplintfentry(finterfaces.search(i)) do
  5120. begin
  5121. if assigned(namemappings) then
  5122. namemappings.free;
  5123. namemappings:=nil;
  5124. end;
  5125. end;
  5126. procedure timplementedinterfaces.addmappings(intfindex: longint; const name, newname: string);
  5127. begin
  5128. checkindex(intfindex);
  5129. with timplintfentry(finterfaces.search(intfindex)) do
  5130. begin
  5131. if not assigned(namemappings) then
  5132. namemappings:=tdictionary.create;
  5133. namemappings.insert(tnamemap.create(name,newname));
  5134. end;
  5135. end;
  5136. function timplementedinterfaces.getmappings(intfindex: longint; const name: string; var nextexist: pointer): string;
  5137. begin
  5138. checkindex(intfindex);
  5139. if not assigned(nextexist) then
  5140. with timplintfentry(finterfaces.search(intfindex)) do
  5141. begin
  5142. if assigned(namemappings) then
  5143. nextexist:=namemappings.search(name)
  5144. else
  5145. nextexist:=nil;
  5146. end;
  5147. if assigned(nextexist) then
  5148. begin
  5149. getmappings:=tnamemap(nextexist).newname^;
  5150. nextexist:=tnamemap(nextexist).listnext;
  5151. end
  5152. else
  5153. getmappings:='';
  5154. end;
  5155. procedure timplementedinterfaces.clearimplprocs;
  5156. var
  5157. i: longint;
  5158. begin
  5159. for i:=1 to count do
  5160. with timplintfentry(finterfaces.search(i)) do
  5161. begin
  5162. if assigned(procdefs) then
  5163. procdefs.free;
  5164. procdefs:=nil;
  5165. end;
  5166. end;
  5167. procedure timplementedinterfaces.addimplproc(intfindex: longint; procdef: tprocdef);
  5168. begin
  5169. checkindex(intfindex);
  5170. with timplintfentry(finterfaces.search(intfindex)) do
  5171. begin
  5172. if not assigned(procdefs) then
  5173. procdefs:=tindexarray.create(4);
  5174. procdefs.insert(tprocdefstore.create(procdef));
  5175. end;
  5176. end;
  5177. function timplementedinterfaces.implproccount(intfindex: longint): longint;
  5178. begin
  5179. checkindex(intfindex);
  5180. with timplintfentry(finterfaces.search(intfindex)) do
  5181. if assigned(procdefs) then
  5182. implproccount:=procdefs.count
  5183. else
  5184. implproccount:=0;
  5185. end;
  5186. function timplementedinterfaces.implprocs(intfindex: longint; procindex: longint): tprocdef;
  5187. begin
  5188. checkindex(intfindex);
  5189. with timplintfentry(finterfaces.search(intfindex)) do
  5190. if assigned(procdefs) then
  5191. implprocs:=tprocdefstore(procdefs.search(procindex)).procdef
  5192. else
  5193. internalerror(200006131);
  5194. end;
  5195. function timplementedinterfaces.isimplmergepossible(intfindex, remainindex: longint; var weight: longint): boolean;
  5196. var
  5197. possible: boolean;
  5198. i: longint;
  5199. iiep1: TIndexArray;
  5200. iiep2: TIndexArray;
  5201. begin
  5202. checkindex(intfindex);
  5203. checkindex(remainindex);
  5204. iiep1:=timplintfentry(finterfaces.search(intfindex)).procdefs;
  5205. iiep2:=timplintfentry(finterfaces.search(remainindex)).procdefs;
  5206. if not assigned(iiep1) then { empty interface is mergeable :-) }
  5207. begin
  5208. possible:=true;
  5209. weight:=0;
  5210. end
  5211. else
  5212. begin
  5213. possible:=assigned(iiep2) and (iiep1.count<=iiep2.count);
  5214. i:=1;
  5215. while (possible) and (i<=iiep1.count) do
  5216. begin
  5217. possible:=
  5218. (tprocdefstore(iiep1.search(i)).procdef=tprocdefstore(iiep2.search(i)).procdef);
  5219. inc(i);
  5220. end;
  5221. if possible then
  5222. weight:=iiep1.count;
  5223. end;
  5224. isimplmergepossible:=possible;
  5225. end;
  5226. {****************************************************************************
  5227. TFORWARDDEF
  5228. ****************************************************************************}
  5229. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  5230. var
  5231. oldregisterdef : boolean;
  5232. begin
  5233. { never register the forwarddefs, they are disposed at the
  5234. end of the type declaration block }
  5235. oldregisterdef:=registerdef;
  5236. registerdef:=false;
  5237. inherited create;
  5238. registerdef:=oldregisterdef;
  5239. deftype:=forwarddef;
  5240. tosymname:=stringdup(s);
  5241. forwardpos:=pos;
  5242. end;
  5243. function tforwarddef.gettypename:string;
  5244. begin
  5245. gettypename:='unresolved forward to '+tosymname^;
  5246. end;
  5247. destructor tforwarddef.destroy;
  5248. begin
  5249. if assigned(tosymname) then
  5250. stringdispose(tosymname);
  5251. inherited destroy;
  5252. end;
  5253. {****************************************************************************
  5254. TERRORDEF
  5255. ****************************************************************************}
  5256. constructor terrordef.create;
  5257. begin
  5258. inherited create;
  5259. deftype:=errordef;
  5260. end;
  5261. {$ifdef GDB}
  5262. function terrordef.stabstring : pchar;
  5263. begin
  5264. stabstring:=strpnew('error'+numberstring);
  5265. end;
  5266. procedure terrordef.concatstabto(asmlist : taasmoutput);
  5267. begin
  5268. { No internal error needed, an normal error is already
  5269. thrown }
  5270. end;
  5271. {$endif GDB}
  5272. function terrordef.gettypename:string;
  5273. begin
  5274. gettypename:='<erroneous type>';
  5275. end;
  5276. function terrordef.getmangledparaname:string;
  5277. begin
  5278. getmangledparaname:='error';
  5279. end;
  5280. {****************************************************************************
  5281. GDB Helpers
  5282. ****************************************************************************}
  5283. {$ifdef GDB}
  5284. function typeglobalnumber(const s : string) : string;
  5285. var st : string;
  5286. symt : tsymtable;
  5287. srsym : tsym;
  5288. srsymtable : tsymtable;
  5289. old_make_ref : boolean;
  5290. begin
  5291. old_make_ref:=make_ref;
  5292. make_ref:=false;
  5293. typeglobalnumber := '0';
  5294. srsym := nil;
  5295. if pos('.',s) > 0 then
  5296. begin
  5297. st := copy(s,1,pos('.',s)-1);
  5298. searchsym(st,srsym,srsymtable);
  5299. st := copy(s,pos('.',s)+1,255);
  5300. if assigned(srsym) then
  5301. begin
  5302. if srsym.typ = unitsym then
  5303. begin
  5304. symt := tunitsym(srsym).unitsymtable;
  5305. srsym := tsym(symt.search(st));
  5306. end else srsym := nil;
  5307. end;
  5308. end else st := s;
  5309. if srsym = nil then
  5310. searchsym(st,srsym,srsymtable);
  5311. if (srsym=nil) or
  5312. (srsym.typ<>typesym) then
  5313. begin
  5314. Message(type_e_type_id_expected);
  5315. exit;
  5316. end;
  5317. typeglobalnumber := tstoreddef(ttypesym(srsym).restype.def).numberstring;
  5318. make_ref:=old_make_ref;
  5319. end;
  5320. {$endif GDB}
  5321. {****************************************************************************
  5322. Definition Helpers
  5323. ****************************************************************************}
  5324. procedure reset_global_defs;
  5325. var
  5326. def : tstoreddef;
  5327. {$ifdef debug}
  5328. prevdef : tstoreddef;
  5329. {$endif debug}
  5330. begin
  5331. {$ifdef debug}
  5332. prevdef:=nil;
  5333. {$endif debug}
  5334. {$ifdef GDB}
  5335. pglobaltypecount:=@globaltypecount;
  5336. {$endif GDB}
  5337. def:=firstglobaldef;
  5338. while assigned(def) do
  5339. begin
  5340. {$ifdef GDB}
  5341. if assigned(def.typesym) then
  5342. ttypesym(def.typesym).isusedinstab:=false;
  5343. def.is_def_stab_written:=not_written;
  5344. {$endif GDB}
  5345. if assigned(def.rttitablesym) then
  5346. trttisym(def.rttitablesym).lab := nil;
  5347. if assigned(def.inittablesym) then
  5348. trttisym(def.inittablesym).lab := nil;
  5349. def.localrttilab[initrtti]:=nil;
  5350. def.localrttilab[fullrtti]:=nil;
  5351. {$ifdef debug}
  5352. prevdef:=def;
  5353. {$endif debug}
  5354. def:=def.nextglobal;
  5355. end;
  5356. end;
  5357. function is_interfacecom(def: tdef): boolean;
  5358. begin
  5359. is_interfacecom:=
  5360. assigned(def) and
  5361. (def.deftype=objectdef) and
  5362. (tobjectdef(def).objecttype=odt_interfacecom);
  5363. end;
  5364. function is_interfacecorba(def: tdef): boolean;
  5365. begin
  5366. is_interfacecorba:=
  5367. assigned(def) and
  5368. (def.deftype=objectdef) and
  5369. (tobjectdef(def).objecttype=odt_interfacecorba);
  5370. end;
  5371. function is_interface(def: tdef): boolean;
  5372. begin
  5373. is_interface:=
  5374. assigned(def) and
  5375. (def.deftype=objectdef) and
  5376. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  5377. end;
  5378. function is_class(def: tdef): boolean;
  5379. begin
  5380. is_class:=
  5381. assigned(def) and
  5382. (def.deftype=objectdef) and
  5383. (tobjectdef(def).objecttype=odt_class);
  5384. end;
  5385. function is_object(def: tdef): boolean;
  5386. begin
  5387. is_object:=
  5388. assigned(def) and
  5389. (def.deftype=objectdef) and
  5390. (tobjectdef(def).objecttype=odt_object);
  5391. end;
  5392. function is_cppclass(def: tdef): boolean;
  5393. begin
  5394. is_cppclass:=
  5395. assigned(def) and
  5396. (def.deftype=objectdef) and
  5397. (tobjectdef(def).objecttype=odt_cppclass);
  5398. end;
  5399. function is_class_or_interface(def: tdef): boolean;
  5400. begin
  5401. is_class_or_interface:=
  5402. assigned(def) and
  5403. (def.deftype=objectdef) and
  5404. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  5405. end;
  5406. end.
  5407. {
  5408. $Log$
  5409. Revision 1.202 2004-01-22 21:33:54 peter
  5410. * procvardef rtti fixed
  5411. Revision 1.201 2004/01/22 16:33:22 peter
  5412. * enum value rtti is now in orginal case
  5413. Revision 1.200 2004/01/20 12:59:37 florian
  5414. * common addnode code for x86-64 and i386
  5415. Revision 1.199 2004/01/15 15:16:18 daniel
  5416. * Some minor stuff
  5417. * Managed to eliminate speed effects of string compression
  5418. Revision 1.198 2004/01/11 23:56:20 daniel
  5419. * Experiment: Compress strings to save memory
  5420. Did not save a single byte of mem; clearly the core size is boosted by
  5421. temporary memory usage...
  5422. Revision 1.197 2004/01/04 21:10:04 jonas
  5423. * Darwin's assembler assumes that all labels starting with 'L' are local
  5424. -> rename symbols starting with 'L'
  5425. Revision 1.196 2003/12/24 20:51:11 peter
  5426. * don't lowercase enumnames
  5427. Revision 1.195 2003/12/24 01:47:22 florian
  5428. * first fixes to compile the x86-64 system unit
  5429. Revision 1.194 2003/12/21 19:42:43 florian
  5430. * fixed ppc inlining stuff
  5431. * fixed wrong unit writing
  5432. + added some sse stuff
  5433. Revision 1.193 2003/12/16 21:29:24 florian
  5434. + inlined procedures inherit procinfo flags
  5435. Revision 1.192 2003/12/12 12:09:40 marco
  5436. * always generate RTTI patch from peter
  5437. Revision 1.191 2003/12/08 22:34:24 peter
  5438. * tai_const.create_32bit changed to cardinal
  5439. Revision 1.190 2003/11/10 22:02:52 peter
  5440. * cross unit inlining fixed
  5441. Revision 1.189 2003/11/08 23:31:27 florian
  5442. * tstoreddef.getcopy returns now an errordef instead of nil; this
  5443. allows easier error recovery
  5444. Revision 1.188 2003/11/05 14:18:03 marco
  5445. * fix from Peter arraysize warning (nav Newsgroup msg)
  5446. Revision 1.187 2003/11/01 15:50:03 peter
  5447. * fix check for valid procdef in property rtti
  5448. Revision 1.186 2003/10/29 21:56:28 peter
  5449. * procsym.deref derefs only own procdefs
  5450. * reset paracount in procdef.deref so a second deref doesn't increase
  5451. the paracounts to invalid values
  5452. Revision 1.185 2003/10/29 19:48:51 peter
  5453. * renamed mangeldname_prefix to make_mangledname and made it more
  5454. generic
  5455. * make_mangledname is now also used for internal threadvar/resstring
  5456. lists
  5457. * Add P$ in front of program modulename to prevent duplicated symbols
  5458. at assembler level, because the main program can have the same name
  5459. as a unit, see webtbs/tw1251b
  5460. Revision 1.184 2003/10/23 14:44:07 peter
  5461. * splitted buildderef and buildderefimpl to fix interface crc
  5462. calculation
  5463. Revision 1.183 2003/10/22 20:40:00 peter
  5464. * write derefdata in a separate ppu entry
  5465. Revision 1.182 2003/10/21 18:14:49 peter
  5466. * fix counting of parameters when loading ppu
  5467. Revision 1.181 2003/10/17 15:08:34 peter
  5468. * commented out more obsolete constants
  5469. Revision 1.180 2003/10/17 14:52:07 peter
  5470. * fixed ppc build
  5471. Revision 1.179 2003/10/17 14:38:32 peter
  5472. * 64k registers supported
  5473. * fixed some memory leaks
  5474. Revision 1.178 2003/10/13 14:05:12 peter
  5475. * removed is_visible_for_proc
  5476. * search also for class overloads when finding interface
  5477. implementations
  5478. Revision 1.177 2003/10/11 16:06:42 florian
  5479. * fixed some MMX<->SSE
  5480. * started to fix ppc, needs an overhaul
  5481. + stabs info improve for spilling, not sure if it works correctly/completly
  5482. - MMX_SUPPORT removed from Makefile.fpc
  5483. Revision 1.176 2003/10/10 17:48:14 peter
  5484. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  5485. * tregisteralloctor renamed to trgobj
  5486. * removed rgobj from a lot of units
  5487. * moved location_* and reference_* to cgobj
  5488. * first things for mmx register allocation
  5489. Revision 1.175 2003/10/07 20:43:49 peter
  5490. * Add calling convention in fullprocname when it is specified
  5491. Revision 1.174 2003/10/07 16:06:30 peter
  5492. * tsymlist.def renamed to tsymlist.procdef
  5493. * tsymlist.procdef is now only used to store the procdef
  5494. Revision 1.173 2003/10/06 22:23:41 florian
  5495. + added basic olevariant support
  5496. Revision 1.172 2003/10/05 21:21:52 peter
  5497. * c style array of const generates callparanodes
  5498. * varargs paraloc fixes
  5499. Revision 1.171 2003/10/05 12:56:35 peter
  5500. * don't write procdefs that are released to ppu
  5501. Revision 1.170 2003/10/03 22:00:33 peter
  5502. * parameter alignment fixes
  5503. Revision 1.169 2003/10/02 21:19:42 peter
  5504. * protected visibility fixes
  5505. Revision 1.168 2003/10/01 20:34:49 peter
  5506. * procinfo unit contains tprocinfo
  5507. * cginfo renamed to cgbase
  5508. * moved cgmessage to verbose
  5509. * fixed ppc and sparc compiles
  5510. Revision 1.167 2003/10/01 16:49:05 florian
  5511. * para items are now reversed for pascal calling conventions
  5512. Revision 1.166 2003/10/01 15:32:58 florian
  5513. * fixed FullProcName to handle constructors, destructors and operators correctly
  5514. Revision 1.165 2003/10/01 15:00:02 peter
  5515. * don't write parast,localst debug info for externals
  5516. Revision 1.164 2003/09/23 21:03:35 peter
  5517. * connect parasym to paraitem
  5518. Revision 1.163 2003/09/23 17:56:06 peter
  5519. * locals and paras are allocated in the code generation
  5520. * tvarsym.localloc contains the location of para/local when
  5521. generating code for the current procedure
  5522. Revision 1.162 2003/09/07 22:09:35 peter
  5523. * preparations for different default calling conventions
  5524. * various RA fixes
  5525. Revision 1.161 2003/09/06 22:27:09 florian
  5526. * fixed web bug 2669
  5527. * cosmetic fix in printnode
  5528. * tobjectdef.gettypename implemented
  5529. Revision 1.160 2003/09/03 15:55:01 peter
  5530. * NEWRA branch merged
  5531. Revision 1.159 2003/09/03 11:18:37 florian
  5532. * fixed arm concatcopy
  5533. + arm support in the common compiler sources added
  5534. * moved some generic cg code around
  5535. + tfputype added
  5536. * ...
  5537. Revision 1.158.2.2 2003/08/29 17:28:59 peter
  5538. * next batch of updates
  5539. Revision 1.158.2.1 2003/08/27 19:55:54 peter
  5540. * first tregister patch
  5541. Revision 1.158 2003/08/11 21:18:20 peter
  5542. * start of sparc support for newra
  5543. Revision 1.157 2003/07/08 15:20:56 peter
  5544. * don't allow add/assignments for formaldef
  5545. * formaldef size changed to 0
  5546. Revision 1.156 2003/07/06 21:50:33 jonas
  5547. * fixed ppc compilation problems and changed VOLATILE_REGISTERS for x86
  5548. so that it doesn't include ebp and esp anymore
  5549. Revision 1.155 2003/07/06 15:31:21 daniel
  5550. * Fixed register allocator. *Lots* of fixes.
  5551. Revision 1.154 2003/07/02 22:18:04 peter
  5552. * paraloc splitted in callerparaloc,calleeparaloc
  5553. * sparc calling convention updates
  5554. Revision 1.153 2003/06/25 18:31:23 peter
  5555. * sym,def resolving partly rewritten to support also parent objects
  5556. not directly available through the uses clause
  5557. Revision 1.152 2003/06/17 16:34:44 jonas
  5558. * lots of newra fixes (need getfuncretparaloc implementation for i386)!
  5559. * renamed all_intregisters to paramanager.get_volatile_registers_int(pocall_default) and made it
  5560. processor dependent
  5561. Revision 1.151 2003/06/08 11:41:21 peter
  5562. * set parast.next to the owner of the procdef
  5563. Revision 1.150 2003/06/07 20:26:32 peter
  5564. * re-resolving added instead of reloading from ppu
  5565. * tderef object added to store deref info for resolving
  5566. Revision 1.149 2003/06/05 20:05:55 peter
  5567. * removed changesettype because that will change the definition
  5568. of the setdef forever and can result in a different between
  5569. original interface and current implementation definition
  5570. Revision 1.148 2003/06/03 13:01:59 daniel
  5571. * Register allocator finished
  5572. Revision 1.147 2003/06/02 22:55:28 florian
  5573. * classes and interfaces can be stored in integer registers
  5574. Revision 1.146 2003/05/26 21:17:18 peter
  5575. * procinlinenode removed
  5576. * aktexit2label removed, fast exit removed
  5577. + tcallnode.inlined_pass_2 added
  5578. Revision 1.145 2003/05/25 11:34:17 peter
  5579. * methodpointer self pushing fixed
  5580. Revision 1.144 2003/05/15 18:58:53 peter
  5581. * removed selfpointer_offset, vmtpointer_offset
  5582. * tvarsym.adjusted_address
  5583. * address in localsymtable is now in the real direction
  5584. * removed some obsolete globals
  5585. Revision 1.143 2003/05/13 08:13:16 jonas
  5586. * patch from Peter for rtti symbols
  5587. Revision 1.142 2003/05/11 21:37:03 peter
  5588. * moved implicit exception frame from ncgutil to psub
  5589. * constructor/destructor helpers moved from cobj/ncgutil to psub
  5590. Revision 1.141 2003/05/09 17:47:03 peter
  5591. * self moved to hidden parameter
  5592. * removed hdisposen,hnewn,selfn
  5593. Revision 1.140 2003/05/05 14:53:16 peter
  5594. * vs_hidden replaced by is_hidden boolean
  5595. Revision 1.139 2003/05/01 07:59:43 florian
  5596. * introduced defaultordconsttype to decribe the default size of ordinal constants
  5597. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  5598. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  5599. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  5600. Revision 1.138 2003/04/27 11:21:34 peter
  5601. * aktprocdef renamed to current_procdef
  5602. * procinfo renamed to current_procinfo
  5603. * procinfo will now be stored in current_module so it can be
  5604. cleaned up properly
  5605. * gen_main_procsym changed to create_main_proc and release_main_proc
  5606. to also generate a tprocinfo structure
  5607. * fixed unit implicit initfinal
  5608. Revision 1.137 2003/04/27 07:29:51 peter
  5609. * current_procdef cleanup, current_procdef is now always nil when parsing
  5610. a new procdef declaration
  5611. * aktprocsym removed
  5612. * lexlevel removed, use symtable.symtablelevel instead
  5613. * implicit init/final code uses the normal genentry/genexit
  5614. * funcret state checking updated for new funcret handling
  5615. Revision 1.136 2003/04/25 20:59:35 peter
  5616. * removed funcretn,funcretsym, function result is now in varsym
  5617. and aliases for result and function name are added using absolutesym
  5618. * vs_hidden parameter for funcret passed in parameter
  5619. * vs_hidden fixes
  5620. * writenode changed to printnode and released from extdebug
  5621. * -vp option added to generate a tree.log with the nodetree
  5622. * nicer printnode for statements, callnode
  5623. Revision 1.135 2003/04/23 20:16:04 peter
  5624. + added currency support based on int64
  5625. + is_64bit for use in cg units instead of is_64bitint
  5626. * removed cgmessage from n386add, replace with internalerrors
  5627. Revision 1.134 2003/04/23 12:35:34 florian
  5628. * fixed several issues with powerpc
  5629. + applied a patch from Jonas for nested function calls (PowerPC only)
  5630. * ...
  5631. Revision 1.133 2003/04/10 17:57:53 peter
  5632. * vs_hidden released
  5633. Revision 1.132 2003/03/18 16:25:50 peter
  5634. * no itnernalerror for errordef.concatstabto()
  5635. Revision 1.131 2003/03/17 16:54:41 peter
  5636. * support DefaultHandler and anonymous inheritance fixed
  5637. for message methods
  5638. Revision 1.130 2003/03/17 15:54:22 peter
  5639. * store symoptions also for procdef
  5640. * check symoptions (private,public) when calculating possible
  5641. overload candidates
  5642. Revision 1.129 2003/02/19 22:00:14 daniel
  5643. * Code generator converted to new register notation
  5644. - Horribily outdated todo.txt removed
  5645. Revision 1.128 2003/02/02 19:25:54 carl
  5646. * Several bugfixes for m68k target (register alloc., opcode emission)
  5647. + VIS target
  5648. + Generic add more complete (still not verified)
  5649. Revision 1.127 2003/01/21 14:36:44 pierre
  5650. * set sizes needs to be passes in bits not bytes to stabs info
  5651. Revision 1.126 2003/01/16 22:11:33 peter
  5652. * fixed tprocdef.is_addressonly
  5653. Revision 1.125 2003/01/15 01:44:33 peter
  5654. * merged methodpointer fixes from 1.0.x
  5655. Revision 1.124 2003/01/09 21:52:37 peter
  5656. * merged some verbosity options.
  5657. * V_LineInfo is a verbosity flag to include line info
  5658. Revision 1.123 2003/01/06 21:16:52 peter
  5659. * po_addressonly added to retrieve the address of a methodpointer
  5660. only, this is used for @tclass.method which has no self pointer
  5661. Revision 1.122 2003/01/05 15:54:15 florian
  5662. + added proper support of type = type <type>; for simple types
  5663. Revision 1.121 2003/01/05 13:36:53 florian
  5664. * x86-64 compiles
  5665. + very basic support for float128 type (x86-64 only)
  5666. Revision 1.120 2003/01/02 19:49:00 peter
  5667. * update self parameter only for methodpointer and methods
  5668. Revision 1.119 2002/12/29 18:25:59 peter
  5669. * tprocdef.gettypename implemented
  5670. Revision 1.118 2002/12/27 15:23:09 peter
  5671. * write class methods in fullname
  5672. Revision 1.117 2002/12/15 19:34:31 florian
  5673. + some front end stuff for vs_hidden added
  5674. Revision 1.116 2002/12/15 11:26:02 peter
  5675. * ignore vs_hidden parameters when choosing overloaded proc
  5676. Revision 1.115 2002/12/07 14:27:09 carl
  5677. * 3% memory optimization
  5678. * changed some types
  5679. + added type checking with different size for call node and for
  5680. parameters
  5681. Revision 1.114 2002/12/01 22:05:27 carl
  5682. * no more warnings for structures over 32K since this is
  5683. handled correctly in this version of the compiler.
  5684. Revision 1.113 2002/11/27 20:04:09 peter
  5685. * tvarsym.get_push_size replaced by paramanager.push_size
  5686. Revision 1.112 2002/11/25 21:05:53 carl
  5687. * several mistakes fixed in message files
  5688. Revision 1.111 2002/11/25 18:43:33 carl
  5689. - removed the invalid if <> checking (Delphi is strange on this)
  5690. + implemented abstract warning on instance creation of class with
  5691. abstract methods.
  5692. * some error message cleanups
  5693. Revision 1.110 2002/11/25 17:43:24 peter
  5694. * splitted defbase in defutil,symutil,defcmp
  5695. * merged isconvertable and is_equal into compare_defs(_ext)
  5696. * made operator search faster by walking the list only once
  5697. Revision 1.109 2002/11/23 22:50:06 carl
  5698. * some small speed optimizations
  5699. + added several new warnings/hints
  5700. Revision 1.108 2002/11/22 22:48:10 carl
  5701. * memory optimization with tconstsym (1.5%)
  5702. Revision 1.107 2002/11/19 16:21:29 pierre
  5703. * correct several stabs generation problems
  5704. Revision 1.106 2002/11/18 17:31:59 peter
  5705. * pass proccalloption to ret_in_xxx and push_xxx functions
  5706. Revision 1.105 2002/11/17 16:31:57 carl
  5707. * memory optimization (3-4%) : cleanup of tai fields,
  5708. cleanup of tdef and tsym fields.
  5709. * make it work for m68k
  5710. Revision 1.104 2002/11/16 19:53:18 carl
  5711. * avoid Range check errors
  5712. Revision 1.103 2002/11/15 16:29:09 peter
  5713. * fixed rtti for int64 (merged)
  5714. Revision 1.102 2002/11/15 01:58:54 peter
  5715. * merged changes from 1.0.7 up to 04-11
  5716. - -V option for generating bug report tracing
  5717. - more tracing for option parsing
  5718. - errors for cdecl and high()
  5719. - win32 import stabs
  5720. - win32 records<=8 are returned in eax:edx (turned off by default)
  5721. - heaptrc update
  5722. - more info for temp management in .s file with EXTDEBUG
  5723. Revision 1.101 2002/11/09 15:31:02 carl
  5724. + align RTTI tables
  5725. Revision 1.100 2002/10/19 15:09:25 peter
  5726. + tobjectdef.members_need_inittable that is used to generate only the
  5727. inittable when it is really used. This saves a lot of useless calls
  5728. to fpc_finalize when destroying classes
  5729. Revision 1.99 2002/10/07 21:30:27 peter
  5730. * removed obsolete rangecheck stuff
  5731. Revision 1.98 2002/10/05 15:14:26 peter
  5732. * getparamangeldname for errordef
  5733. Revision 1.97 2002/10/05 12:43:28 carl
  5734. * fixes for Delphi 6 compilation
  5735. (warning : Some features do not work under Delphi)
  5736. Revision 1.96 2002/09/27 21:13:29 carl
  5737. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  5738. Revision 1.95 2002/09/16 09:31:10 florian
  5739. * fixed currency size
  5740. Revision 1.94 2002/09/09 17:34:15 peter
  5741. * tdicationary.replace added to replace and item in a dictionary. This
  5742. is only allowed for the same name
  5743. * varsyms are inserted in symtable before the types are parsed. This
  5744. fixes the long standing "var longint : longint" bug
  5745. - consume_idlist and idstringlist removed. The loops are inserted
  5746. at the callers place and uses the symtable for duplicate id checking
  5747. Revision 1.93 2002/09/07 15:25:07 peter
  5748. * old logs removed and tabs fixed
  5749. Revision 1.92 2002/09/05 19:29:42 peter
  5750. * memdebug enhancements
  5751. Revision 1.91 2002/08/25 19:25:20 peter
  5752. * sym.insert_in_data removed
  5753. * symtable.insertvardata/insertconstdata added
  5754. * removed insert_in_data call from symtable.insert, it needs to be
  5755. called separatly. This allows to deref the address calculation
  5756. * procedures now calculate the parast addresses after the procedure
  5757. directives are parsed. This fixes the cdecl parast problem
  5758. * push_addr_param has an extra argument that specifies if cdecl is used
  5759. or not
  5760. Revision 1.90 2002/08/18 20:06:25 peter
  5761. * inlining is now also allowed in interface
  5762. * renamed write/load to ppuwrite/ppuload
  5763. * tnode storing in ppu
  5764. * nld,ncon,nbas are already updated for storing in ppu
  5765. Revision 1.89 2002/08/11 15:28:00 florian
  5766. + support of explicit type case <any ordinal type>->pointer
  5767. (delphi mode only)
  5768. Revision 1.88 2002/08/11 14:32:28 peter
  5769. * renamed current_library to objectlibrary
  5770. Revision 1.87 2002/08/11 13:24:13 peter
  5771. * saving of asmsymbols in ppu supported
  5772. * asmsymbollist global is removed and moved into a new class
  5773. tasmlibrarydata that will hold the info of a .a file which
  5774. corresponds with a single module. Added librarydata to tmodule
  5775. to keep the library info stored for the module. In the future the
  5776. objectfiles will also be stored to the tasmlibrarydata class
  5777. * all getlabel/newasmsymbol and friends are moved to the new class
  5778. Revision 1.86 2002/08/09 07:33:03 florian
  5779. * a couple of interface related fixes
  5780. Revision 1.85 2002/07/23 09:51:24 daniel
  5781. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  5782. are worth comitting.
  5783. Revision 1.84 2002/07/20 11:57:57 florian
  5784. * types.pas renamed to defbase.pas because D6 contains a types
  5785. unit so this would conflicts if D6 programms are compiled
  5786. + Willamette/SSE2 instructions to assembler added
  5787. Revision 1.83 2002/07/11 14:41:30 florian
  5788. * start of the new generic parameter handling
  5789. Revision 1.82 2002/07/07 09:52:32 florian
  5790. * powerpc target fixed, very simple units can be compiled
  5791. * some basic stuff for better callparanode handling, far from being finished
  5792. Revision 1.81 2002/07/01 18:46:26 peter
  5793. * internal linker
  5794. * reorganized aasm layer
  5795. Revision 1.80 2002/07/01 16:23:54 peter
  5796. * cg64 patch
  5797. * basics for currency
  5798. * asnode updates for class and interface (not finished)
  5799. Revision 1.79 2002/05/18 13:34:18 peter
  5800. * readded missing revisions
  5801. Revision 1.78 2002/05/16 19:46:44 carl
  5802. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  5803. + try to fix temp allocation (still in ifdef)
  5804. + generic constructor calls
  5805. + start of tassembler / tmodulebase class cleanup
  5806. Revision 1.76 2002/05/12 16:53:10 peter
  5807. * moved entry and exitcode to ncgutil and cgobj
  5808. * foreach gets extra argument for passing local data to the
  5809. iterator function
  5810. * -CR checks also class typecasts at runtime by changing them
  5811. into as
  5812. * fixed compiler to cycle with the -CR option
  5813. * fixed stabs with elf writer, finally the global variables can
  5814. be watched
  5815. * removed a lot of routines from cga unit and replaced them by
  5816. calls to cgobj
  5817. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  5818. u32bit then the other is typecasted also to u32bit without giving
  5819. a rangecheck warning/error.
  5820. * fixed pascal calling method with reversing also the high tree in
  5821. the parast, detected by tcalcst3 test
  5822. Revision 1.75 2002/04/25 20:16:39 peter
  5823. * moved more routines from cga/n386util
  5824. Revision 1.74 2002/04/23 19:16:35 peter
  5825. * add pinline unit that inserts compiler supported functions using
  5826. one or more statements
  5827. * moved finalize and setlength from ninl to pinline
  5828. Revision 1.73 2002/04/21 19:02:05 peter
  5829. * removed newn and disposen nodes, the code is now directly
  5830. inlined from pexpr
  5831. * -an option that will write the secondpass nodes to the .s file, this
  5832. requires EXTDEBUG define to actually write the info
  5833. * fixed various internal errors and crashes due recent code changes
  5834. Revision 1.72 2002/04/20 21:32:25 carl
  5835. + generic FPC_CHECKPOINTER
  5836. + first parameter offset in stack now portable
  5837. * rename some constants
  5838. + move some cpu stuff to other units
  5839. - remove unused constents
  5840. * fix stacksize for some targets
  5841. * fix generic size problems which depend now on EXTEND_SIZE constant
  5842. }