symdef.pas 203 KB

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