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