symdef.pas 213 KB

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