symdef.pas 206 KB

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