symdef.pas 203 KB

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