symdef.pas 204 KB

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