symdef.pas 202 KB

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