symdef.pas 203 KB

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