symdef.pas 202 KB

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