symdef.pas 203 KB

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