symdef.pas 202 KB

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