symdef.pas 202 KB

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