symdef.pas 207 KB

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