symdef.pas 293 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766
  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. cclasses,widestr,
  23. { global }
  24. globtype,globals,tokens,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { node }
  28. node,
  29. { aasm }
  30. aasmtai,
  31. cpuinfo,
  32. cgbase,
  33. parabase
  34. ;
  35. type
  36. {************************************************
  37. TDef
  38. ************************************************}
  39. tgenericconstraintdata=class
  40. interfaces : tfpobjectlist;
  41. interfacesderef : tfplist;
  42. flags : tgenericconstraintflags;
  43. constructor create;
  44. destructor destroy;override;
  45. procedure ppuload(ppufile:tcompilerppufile);
  46. procedure ppuwrite(ppufile:tcompilerppufile);
  47. procedure buildderef;
  48. procedure deref;
  49. end;
  50. { trtti_attribute_list }
  51. trtti_attribute = class
  52. typesym : tsym;
  53. typesymderef : tderef;
  54. typeconstr : tdef;
  55. typeconstrderef : tderef;
  56. { these two are not stored in PPU }
  57. constructorcall : tnode;
  58. constructorpd : tdef;
  59. paras : array of tnode;
  60. constructor ppuload(ppufile:tcompilerppufile);
  61. procedure ppuwrite(ppufile:tcompilerppufile);
  62. procedure ppuload_subentries(ppufile:tcompilerppufile);
  63. procedure ppuwrite_subentries(ppufile:tcompilerppufile);
  64. destructor destroy;override;
  65. procedure buildderef;
  66. procedure deref;
  67. end;
  68. trtti_attribute_list = class
  69. rtti_attributes : TFPObjectList;
  70. { if the attribute list is bound to a def or symbol }
  71. is_bound : Boolean;
  72. class procedure bind(var dangling,owned:trtti_attribute_list);
  73. procedure addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  74. procedure addattribute(attr:trtti_attribute);
  75. destructor destroy; override;
  76. function get_attribute_count:longint;
  77. procedure buildderef;
  78. procedure deref;
  79. class function ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  80. class procedure ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  81. class procedure ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  82. class procedure ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  83. end;
  84. { tstoreddef }
  85. tstoreddef = class(tdef)
  86. private
  87. {$ifdef symansistr}
  88. _fullownerhierarchyname : ansistring;
  89. {$else symansistr}
  90. _fullownerhierarchyname : pshortstring;
  91. {$endif symansistr}
  92. procedure writeentry(ppufile: tcompilerppufile; ibnr: byte);
  93. protected
  94. typesymderef : tderef;
  95. procedure ppuwrite_platform(ppufile:tcompilerppufile);virtual;
  96. procedure ppuload_platform(ppufile:tcompilerppufile);virtual;
  97. { a (possibly) reusable def is always created on the basis of another
  98. def, and contains a reference to this other def. If this other
  99. def is in a non-persistent symboltable, the new def cannot actually
  100. be safely reused everywhere in the current module. This routine
  101. abtracts that checking, and also restores the symtable stack
  102. (which had to be reset before creating the new def, so that the new
  103. def did not automatically get added to its top) }
  104. class procedure setup_reusable_def(origdef, newdef: tdef; res: PHashSetItem; oldsymtablestack: tsymtablestack);
  105. public
  106. {$ifdef EXTDEBUG}
  107. fileinfo : tfileposinfo;
  108. {$endif}
  109. { generic support }
  110. genericdef : tstoreddef;
  111. genericdefderef : tderef;
  112. generictokenbuf : tdynamicarray;
  113. { this list contains references to the symbols that make up the
  114. generic parameters; the symbols are not owned by this list
  115. Note: this list is allocated on demand! }
  116. genericparas : tfphashobjectlist;
  117. genericparaderefs : tfplist;
  118. { contains additional data if this def is a generic constraint
  119. Note: this class is allocated on demand! }
  120. genconstraintdata : tgenericconstraintdata;
  121. { this is Nil if the def has no RTTI attributes }
  122. rtti_attribute_list : trtti_attribute_list;
  123. constructor create(dt:tdeftyp;doregister:boolean);
  124. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  125. destructor destroy;override;
  126. function getcopy : tstoreddef;virtual;
  127. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  128. { this is called directly after ppuload }
  129. procedure ppuload_subentries(ppufile:tcompilerppufile);virtual;
  130. { this is called directly after ppuwrite }
  131. procedure ppuwrite_subentries(ppufile:tcompilerppufile);virtual;
  132. procedure buildderef;override;
  133. procedure buildderefimpl;override;
  134. procedure deref;override;
  135. procedure derefimpl;override;
  136. function size:asizeint;override;
  137. function getvardef:longint;override;
  138. function alignment:shortint;override;
  139. function is_publishable : boolean;override;
  140. function needs_inittable : boolean;override;
  141. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  142. function rtti_mangledname(rt:trttitype):TSymStr;override;
  143. function OwnerHierarchyName: string; override;
  144. function fullownerhierarchyname(skipprocparams:boolean):TSymStr;override;
  145. function needs_separate_initrtti:boolean;override;
  146. function in_currentunit: boolean;
  147. { regvars }
  148. function is_intregable : boolean;
  149. function is_fpuregable : boolean;
  150. { def can be put into a register if it is const/immutable }
  151. function is_const_intregable : boolean;
  152. { generics }
  153. procedure initgeneric;
  154. { this function can be used to determine whether a def is really a
  155. generic declaration or just a normal type declared inside another
  156. generic }
  157. function is_generic:boolean;
  158. { same as above for specializations }
  159. function is_specialization:boolean;
  160. { registers this def in the unit's deflist; no-op if already registered }
  161. procedure register_def; override;
  162. { add the def to the top of the symtable stack if it's not yet owned
  163. by another symtable }
  164. procedure maybe_put_in_symtable_stack;
  165. private
  166. savesize : asizeuint;
  167. end;
  168. tfiletyp = (ft_text,ft_typed,ft_untyped);
  169. tfiledef = class(tstoreddef)
  170. filetyp : tfiletyp;
  171. typedfiledef : tdef;
  172. typedfiledefderef : tderef;
  173. constructor createtext;virtual;
  174. constructor createuntyped;virtual;
  175. constructor createtyped(def : tdef);virtual;
  176. constructor ppuload(ppufile:tcompilerppufile);
  177. function getcopy : tstoreddef;override;
  178. { do not override this routine in platform-specific subclasses,
  179. override ppuwrite_platform instead }
  180. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  181. procedure buildderef;override;
  182. procedure deref;override;
  183. function GetTypeName:string;override;
  184. function getmangledparaname:TSymStr;override;
  185. function size:asizeint;override;
  186. procedure setsize;
  187. function alignment: shortint; override;
  188. end;
  189. tfiledefclass = class of tfiledef;
  190. tvariantdef = class(tstoreddef)
  191. varianttype : tvarianttype;
  192. constructor create(v : tvarianttype);virtual;
  193. constructor ppuload(ppufile:tcompilerppufile);
  194. function getcopy : tstoreddef;override;
  195. function GetTypeName:string;override;
  196. { do not override this routine in platform-specific subclasses,
  197. override ppuwrite_platform instead }
  198. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  199. function getvardef:longint;override;
  200. procedure setsize;
  201. function is_publishable : boolean;override;
  202. function needs_inittable : boolean;override;
  203. end;
  204. tvariantdefclass = class of tvariantdef;
  205. tformaldef = class(tstoreddef)
  206. typed:boolean;
  207. constructor create(Atyped:boolean);virtual;
  208. constructor ppuload(ppufile:tcompilerppufile);
  209. { do not override this routine in platform-specific subclasses,
  210. override ppuwrite_platform instead }
  211. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  212. function GetTypeName:string;override;
  213. end;
  214. tformaldefclass = class of tformaldef;
  215. tforwarddef = class(tstoreddef)
  216. tosymname : pshortstring;
  217. forwardpos : tfileposinfo;
  218. constructor create(const s:string;const pos:tfileposinfo);virtual;
  219. destructor destroy;override;
  220. function getcopy:tstoreddef;override;
  221. function GetTypeName:string;override;
  222. end;
  223. tforwarddefclass = class of tforwarddef;
  224. tundefineddef = class(tstoreddef)
  225. constructor create(doregister:boolean);virtual;
  226. constructor ppuload(ppufile:tcompilerppufile);
  227. { do not override this routine in platform-specific subclasses,
  228. override ppuwrite_platform instead }
  229. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  230. function GetTypeName:string;override;
  231. end;
  232. tundefineddefclass = class of tundefineddef;
  233. terrordef = class(tstoreddef)
  234. constructor create;virtual;
  235. { do not override this routine in platform-specific subclasses,
  236. override ppuwrite_platform instead }
  237. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  238. function GetTypeName:string;override;
  239. function getmangledparaname : TSymStr;override;
  240. end;
  241. terrordefclass = class of terrordef;
  242. tabstractpointerdef = class(tstoreddef)
  243. pointeddef : tdef;
  244. pointeddefderef : tderef;
  245. constructor create(dt:tdeftyp;def:tdef);
  246. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  247. procedure ppuwrite(ppufile:tcompilerppufile);override;
  248. procedure buildderef;override;
  249. procedure deref;override;
  250. function size:asizeint;override;
  251. function alignment:shortint;override;
  252. end;
  253. tpointerdef = class(tabstractpointerdef)
  254. has_pointer_math : boolean;
  255. constructor create(def:tdef);virtual;
  256. { returns a pointerdef for def, reusing an existing one in case it
  257. exists in the current module }
  258. class function getreusable(def: tdef): tpointerdef; virtual;
  259. { same as above, but in case the def must never be freed after the
  260. current module has been compiled -- even if the def was not written
  261. to the ppu file (for defs in para locations, as we don't reset them
  262. so we don't have to recalculate them all the time) }
  263. class function getreusable_no_free(def: tdef): tpointerdef;
  264. function size:asizeint;override;
  265. function getcopy:tstoreddef;override;
  266. constructor ppuload(ppufile:tcompilerppufile);
  267. { do not override this routine in platform-specific subclasses,
  268. override ppuwrite_platform instead }
  269. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  270. function GetTypeName:string;override;
  271. {# returns the appropriate int type for pointer arithmetic with the given pointer type.
  272. When adding or subtracting a number to/from a pointer, this function returns the
  273. int type to which that number has to be converted, before the operation can be performed.
  274. Normally, this is sinttype, except on i8086, where it takes into account the
  275. special i8086 pointer types (near, far, huge). }
  276. function pointer_arithmetic_int_type:tdef;virtual;
  277. {# the unsigned version of pointer_arithmetic_int_type. Used with inc/dec. }
  278. function pointer_arithmetic_uint_type:tdef;virtual;
  279. {# returns the int type produced when subtracting two pointers of the given type.
  280. Normally, this is sinttype, except on i8086, where it takes into account the
  281. special i8086 pointer types (near, far, huge). }
  282. function pointer_subtraction_result_type:tdef;virtual;
  283. function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual;
  284. {# the integer index type used to convert the pointer to array (i.e. denotes int_type in: ptr[int_type]) }
  285. function converted_pointer_to_array_range_type:tdef;virtual;
  286. end;
  287. tpointerdefclass = class of tpointerdef;
  288. tprocdef = class;
  289. tabstractrecorddef= class(tstoreddef)
  290. private
  291. rttistring : string;
  292. public
  293. objname,
  294. objrealname : PShortString;
  295. { for C++ classes: name of the library this class is imported from }
  296. { for Java classes/records: package name }
  297. import_lib : PShortString;
  298. symtable : TSymtable;
  299. cloneddef : tabstractrecorddef;
  300. cloneddefderef : tderef;
  301. objectoptions : tobjectoptions;
  302. { for targets that initialise typed constants via explicit assignments
  303. instead of by generating an initialised data sectino }
  304. tcinitcode : tnode;
  305. constructor create(const n:string; dt:tdeftyp;doregister:boolean);
  306. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  307. procedure ppuwrite(ppufile:tcompilerppufile);override;
  308. destructor destroy; override;
  309. procedure buildderefimpl;override;
  310. procedure derefimpl;override;
  311. procedure check_forwards; virtual;
  312. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  313. function GetSymtable(t:tGetSymtable):TSymtable;override;
  314. function is_packed:boolean;
  315. function RttiName: string;
  316. { enumerator support }
  317. function search_enumerator_get: tprocdef; virtual;
  318. function search_enumerator_move: tprocdef; virtual;
  319. function search_enumerator_current: tsym; virtual;
  320. { JVM }
  321. function jvm_full_typename(with_package_name: boolean): string;
  322. { check if the symtable contains a float field }
  323. function contains_float_field : boolean;
  324. { check if the symtable contains a field that spans an aword boundary }
  325. function contains_cross_aword_field: boolean;
  326. end;
  327. pvariantrecdesc = ^tvariantrecdesc;
  328. tvariantrecbranch = record
  329. { we store only single values here and no ranges because tvariantrecdesc is only needed in iso mode
  330. which does not support range expressions in variant record definitions }
  331. values : array of Tconstexprint;
  332. nestedvariant : pvariantrecdesc;
  333. end;
  334. ppvariantrecdesc = ^pvariantrecdesc;
  335. tvariantrecdesc = record
  336. variantselector : tsym;
  337. variantselectorderef : tderef;
  338. branches : array of tvariantrecbranch;
  339. end;
  340. trecorddef = class(tabstractrecorddef)
  341. public
  342. variantrecdesc : pvariantrecdesc;
  343. isunion : boolean;
  344. constructor create(const n:string; p:TSymtable);virtual;
  345. constructor create_global_internal(const n: string; packrecords, recordalignmin: shortint); virtual;
  346. function add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  347. procedure add_fields_from_deflist(fieldtypes: tfplist);
  348. constructor ppuload(ppufile:tcompilerppufile);
  349. destructor destroy;override;
  350. function getcopy : tstoreddef;override;
  351. { do not override this routine in platform-specific subclasses,
  352. override ppuwrite_platform instead }
  353. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  354. procedure buildderef;override;
  355. procedure deref;override;
  356. function size:asizeint;override;
  357. function alignment : shortint;override;
  358. function padalignment: shortint;
  359. function GetTypeName:string;override;
  360. { debug }
  361. function needs_inittable : boolean;override;
  362. function needs_separate_initrtti:boolean;override;
  363. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  364. end;
  365. trecorddefclass = class of trecorddef;
  366. tobjectdef = class;
  367. { TImplementedInterface }
  368. TImplementedInterface = class
  369. private
  370. fIOffset : longint;
  371. function GetIOffset: longint;
  372. public
  373. IntfDef : tobjectdef;
  374. IntfDefDeref : tderef;
  375. IType : tinterfaceentrytype;
  376. VtblImplIntf : TImplementedInterface;
  377. NameMappings : TFPHashList;
  378. ProcDefs : TFPObjectList;
  379. ImplementsGetter : tsym;
  380. ImplementsGetterDeref : tderef;
  381. ImplementsField : tsym;
  382. constructor create(aintf: tobjectdef);virtual;
  383. constructor create_deref(intfd,getterd:tderef);virtual;
  384. destructor destroy; override;
  385. function getcopy:TImplementedInterface;
  386. procedure buildderef;
  387. procedure deref;
  388. procedure AddMapping(const origname, newname: string);
  389. function GetMapping(const origname: string):string;
  390. procedure AddImplProc(pd:tprocdef);
  391. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  392. property IOffset: longint read GetIOffset write fIOffset;
  393. end;
  394. timplementedinterfaceclass = class of timplementedinterface;
  395. { tvmtentry }
  396. tvmtentry = record
  397. procdef : tprocdef;
  398. procdefderef : tderef;
  399. visibility : tvisibility;
  400. end;
  401. pvmtentry = ^tvmtentry;
  402. { tobjectdef }
  403. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  404. pmvcallstaticinfo = ^tmvcallstaticinfo;
  405. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  406. tobjectdef = class(tabstractrecorddef)
  407. private
  408. fcurrent_dispid: longint;
  409. public
  410. childof : tobjectdef;
  411. childofderef : tderef;
  412. { for Object Pascal helpers }
  413. extendeddef : tdef;
  414. extendeddefderef: tderef;
  415. helpertype : thelpertype;
  416. { for Objective-C: protocols and classes can have the same name there }
  417. objextname : pshortstring;
  418. { to be able to have a variable vmt position }
  419. { and no vmt field for objects without virtuals }
  420. vmtentries : TFPList;
  421. vmcallstaticinfo : pmvcallstaticinfo;
  422. vmt_field : tsym;
  423. vmt_fieldderef : tderef;
  424. iidguid : pguid;
  425. iidstr : pshortstring;
  426. { store implemented interfaces defs and name mappings }
  427. ImplementedInterfaces : TFPObjectList;
  428. { number of abstract methods (used by JVM target to determine whether
  429. or not the class should be marked as abstract: must be done if 1 or
  430. more abstract methods) }
  431. abstractcnt : longint;
  432. writing_class_record_dbginfo,
  433. { a class of this type has been created in this module }
  434. created_in_current_module,
  435. { a loadvmtnode for this class has been created in this
  436. module, so if a classrefdef variable of this or a parent
  437. class is used somewhere to instantiate a class, then this
  438. class may be instantiated
  439. }
  440. maybe_created_in_current_module,
  441. { a "class of" this particular class has been created in
  442. this module
  443. }
  444. classref_created_in_current_module : boolean;
  445. objecttype : tobjecttyp;
  446. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);virtual;
  447. constructor ppuload(ppufile:tcompilerppufile);
  448. destructor destroy;override;
  449. function getcopy : tstoreddef;override;
  450. { do not override this routine in platform-specific subclasses,
  451. override ppuwrite_platform instead }
  452. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  453. function GetTypeName:string;override;
  454. procedure buildderef;override;
  455. procedure deref;override;
  456. procedure derefimpl;override;
  457. procedure copyvmtentries(objdef:tobjectdef);
  458. function getparentdef:tdef;override;
  459. function size : asizeint;override;
  460. function alignment:shortint;override;
  461. function vmtmethodoffset(index:longint):longint;
  462. function members_need_inittable : boolean;
  463. { this should be called when this class implements an interface }
  464. procedure prepareguid;
  465. function is_publishable : boolean;override;
  466. function needs_inittable : boolean;override;
  467. function needs_separate_initrtti : boolean;override;
  468. function has_non_trivial_init_child(check_parent:boolean):boolean;override;
  469. function rtti_mangledname(rt:trttitype):TSymStr;override;
  470. function vmt_mangledname : TSymStr;
  471. function vmt_def: trecorddef;
  472. procedure check_forwards; override;
  473. procedure insertvmt;
  474. function vmt_offset: asizeint;
  475. procedure set_parent(c : tobjectdef);
  476. function find_destructor: tprocdef;
  477. function implements_any_interfaces: boolean;
  478. { dispinterface support }
  479. function get_next_dispid: longint;
  480. { enumerator support }
  481. function search_enumerator_get: tprocdef; override;
  482. function search_enumerator_move: tprocdef; override;
  483. function search_enumerator_current: tsym; override;
  484. { WPO }
  485. procedure register_created_object_type;override;
  486. procedure register_maybe_created_object_type;
  487. procedure register_created_classref_type;
  488. procedure register_vmt_call(index:longint);
  489. { ObjC }
  490. procedure finish_objc_data;
  491. function check_objc_types: boolean;
  492. { C++ }
  493. procedure finish_cpp_data;
  494. end;
  495. tobjectdefclass = class of tobjectdef;
  496. tclassrefdef = class(tabstractpointerdef)
  497. constructor create(def:tdef);virtual;
  498. constructor ppuload(ppufile:tcompilerppufile);
  499. { do not override this routine in platform-specific subclasses,
  500. override ppuwrite_platform instead }
  501. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  502. function getcopy:tstoreddef;override;
  503. function GetTypeName:string;override;
  504. function is_publishable : boolean;override;
  505. function rtti_mangledname(rt:trttitype):TSymStr;override;
  506. procedure register_created_object_type;override;
  507. end;
  508. tclassrefdefclass = class of tclassrefdef;
  509. tarraydef = class(tstoreddef)
  510. lowrange,
  511. highrange : asizeint;
  512. rangedef : tdef;
  513. rangedefderef : tderef;
  514. arrayoptions : tarraydefoptions;
  515. symtable : TSymtable;
  516. protected
  517. _elementdef : tdef;
  518. _elementdefderef : tderef;
  519. procedure setelementdef(def:tdef);
  520. class function getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  521. public
  522. function elesize : asizeint;
  523. function elepackedbitsize : asizeint;
  524. function elecount : asizeuint;
  525. constructor create_from_pointer(def: tpointerdef);virtual;
  526. constructor create(l, h: asizeint; def: tdef);virtual;
  527. constructor create_vector(l,h:asizeint; def:tdef);
  528. constructor create_openarray;virtual;
  529. class function getreusable(def: tdef; elems: asizeint): tarraydef;
  530. class function getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  531. { same as above, but in case the def must never be freed after the
  532. current module has been compiled -- even if the def was not written
  533. to the ppu file (for defs in para locations, as we don't reset them
  534. so we don't have to recalculate them all the time) }
  535. class function getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  536. class function getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  537. constructor ppuload(ppufile:tcompilerppufile);
  538. destructor destroy; override;
  539. function getcopy : tstoreddef;override;
  540. { do not override this routine in platform-specific subclasses,
  541. override ppuwrite_platform instead }
  542. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  543. function GetTypeName:string;override;
  544. function getmangledparaname : TSymStr;override;
  545. procedure buildderef;override;
  546. procedure deref;override;
  547. function size : asizeint;override;
  548. function alignment : shortint;override;
  549. { returns the label of the range check string }
  550. function needs_inittable : boolean;override;
  551. function needs_separate_initrtti : boolean;override;
  552. property elementdef : tdef read _elementdef write setelementdef;
  553. function is_publishable : boolean;override;
  554. function is_hwvector: boolean;
  555. end;
  556. tarraydefclass = class of tarraydef;
  557. torddef = class(tstoreddef)
  558. low,high : TConstExprInt;
  559. ordtype : tordtype;
  560. constructor create(t : tordtype;v,b : TConstExprInt; doregister: boolean);virtual;
  561. constructor ppuload(ppufile:tcompilerppufile);
  562. function getcopy : tstoreddef;override;
  563. { do not override this routine in platform-specific subclasses,
  564. override ppuwrite_platform instead }
  565. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  566. function is_publishable : boolean;override;
  567. function GetTypeName:string;override;
  568. function alignment:shortint;override;
  569. procedure setsize;
  570. function packedbitsize: asizeint; override;
  571. function getvardef : longint;override;
  572. end;
  573. torddefclass = class of torddef;
  574. tfloatdef = class(tstoreddef)
  575. floattype : tfloattype;
  576. constructor create(t: tfloattype; doregister: boolean);virtual;
  577. constructor ppuload(ppufile:tcompilerppufile);
  578. function getcopy : tstoreddef;override;
  579. { do not override this routine in platform-specific subclasses,
  580. override ppuwrite_platform instead }
  581. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  582. function GetTypeName:string;override;
  583. function is_publishable : boolean;override;
  584. function alignment:shortint;override;
  585. function structalignment: shortint;override;
  586. procedure setsize;
  587. function getvardef:longint;override;
  588. end;
  589. tfloatdefclass = class of tfloatdef;
  590. { tabstractprocdef }
  591. tprocnameoption = (pno_showhidden, pno_proctypeoption, pno_paranames,
  592. pno_ownername, pno_noclassmarker, pno_noleadingdollar,
  593. pno_mangledname, pno_noparams);
  594. tprocnameoptions = set of tprocnameoption;
  595. tproccopytyp = (pc_normal,
  596. { everything except for hidden parameters }
  597. pc_normal_no_hidden,
  598. { always creates a top-level function, removes all
  599. special parameters (self, vmt, parentfp, ...) }
  600. pc_bareproc,
  601. { creates a procvardef describing only the code pointer
  602. of a method/netsted function/... }
  603. pc_address_only
  604. );
  605. tabstractprocdef = class(tstoreddef)
  606. { saves a definition to the return type }
  607. returndef : tdef;
  608. returndefderef : tderef;
  609. parast : TSymtable;
  610. paras : tparalist;
  611. proctypeoption : tproctypeoption;
  612. proccalloption : tproccalloption;
  613. procoptions : tprocoptions;
  614. callerargareasize,
  615. calleeargareasize: pint;
  616. {$ifdef m68k}
  617. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  618. {$endif}
  619. funcretloc : array[callerside..calleeside] of TCGPara;
  620. has_paraloc_info : tcallercallee; { paraloc info is available }
  621. { number of user visible parameters }
  622. maxparacount,
  623. minparacount : byte;
  624. constructor create(dt:tdeftyp;level:byte;doregister:boolean);
  625. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  626. destructor destroy;override;
  627. procedure ppuwrite(ppufile:tcompilerppufile);override;
  628. procedure buildderef;override;
  629. procedure deref;override;
  630. procedure calcparas;
  631. function mangledprocparanames(oldlen : longint) : string;
  632. function typename_paras(pno: tprocnameoptions): ansistring;
  633. function is_methodpointer:boolean;virtual;
  634. function is_addressonly:boolean;virtual;
  635. function no_self_node:boolean;
  636. { get either a copy as a procdef or procvardef }
  637. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string): tstoreddef; virtual;
  638. function compatible_with_pointerdef_size(ptr: tpointerdef): boolean; virtual;
  639. procedure check_mark_as_nested;
  640. procedure init_paraloc_info(side: tcallercallee);
  641. procedure done_paraloc_info(side: tcallercallee);
  642. function stack_tainting_parameter(side: tcallercallee): boolean;
  643. function is_pushleftright: boolean;virtual;
  644. function address_type:tdef;virtual;
  645. { address type, generated for ofs() }
  646. function ofs_address_type:tdef;virtual;
  647. procedure declared_far;virtual;
  648. procedure declared_near;virtual;
  649. function generate_safecall_wrapper: boolean; virtual;
  650. private
  651. procedure count_para(p:TObject;arg:pointer);
  652. procedure insert_para(p:TObject;arg:pointer);
  653. end;
  654. tprocvardef = class(tabstractprocdef)
  655. constructor create(level:byte);virtual;
  656. { returns a procvardef that represents the address of a proc(var)def }
  657. class function getreusableprocaddr(def: tabstractprocdef): tprocvardef; virtual;
  658. { same as above, but in case the def must never be freed after the
  659. current module has been compiled -- even if the def was not written
  660. to the ppu file (for defs in para locations, as we don't reset them
  661. so we don't have to recalculate them all the time) }
  662. class function getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  663. constructor ppuload(ppufile:tcompilerppufile);
  664. function getcopy : tstoreddef;override;
  665. { do not override this routine in platform-specific subclasses,
  666. override ppuwrite_platform instead }
  667. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  668. function GetSymtable(t:tGetSymtable):TSymtable;override;
  669. function size : asizeint;override;
  670. function GetTypeName:string;override;
  671. function is_publishable : boolean;override;
  672. function is_methodpointer:boolean;override;
  673. function is_addressonly:boolean;override;
  674. function getmangledparaname:TSymStr;override;
  675. function getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string): tstoreddef; override;
  676. end;
  677. tprocvardefclass = class of tprocvardef;
  678. tmessageinf = record
  679. case integer of
  680. 0 : (str : pshortstring);
  681. 1 : (i : longint);
  682. end;
  683. tinlininginfo = record
  684. { node tree }
  685. code : tnode;
  686. flags : tprocinfoflags;
  687. end;
  688. pinlininginfo = ^tinlininginfo;
  689. {$ifdef oldregvars}
  690. { register variables }
  691. pregvarinfo = ^tregvarinfo;
  692. tregvarinfo = record
  693. regvars : array[1..maxvarregs] of tsym;
  694. regvars_para : array[1..maxvarregs] of boolean;
  695. regvars_refs : array[1..maxvarregs] of longint;
  696. fpuregvars : array[1..maxfpuvarregs] of tsym;
  697. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  698. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  699. end;
  700. {$endif oldregvars}
  701. timplprocdefinfo = record
  702. resultname : pshortstring;
  703. parentfpstruct: tsym;
  704. parentfpstructptrtype: tdef;
  705. parentfpinitblock: tnode;
  706. procstarttai,
  707. procendtai : tai;
  708. skpara: pointer;
  709. personality: tprocdef;
  710. forwarddef,
  711. interfacedef : boolean;
  712. hasforward : boolean;
  713. end;
  714. pimplprocdefinfo = ^timplprocdefinfo;
  715. { tprocdef }
  716. tprocdef = class(tabstractprocdef)
  717. protected
  718. {$ifdef symansistr}
  719. _mangledname : ansistring;
  720. {$else symansistr}
  721. _mangledname : pshortstring;
  722. {$endif}
  723. { information that is only required until the implementation of the
  724. procdef has been handled }
  725. implprocdefinfo : pimplprocdefinfo;
  726. function store_localst:boolean;
  727. function GetResultName: PShortString;
  728. procedure SetResultName(AValue: PShortString);
  729. function GetParentFPStruct: tsym;
  730. procedure SetParentFPStruct(AValue: tsym);
  731. function GetParentFPStructPtrType: tdef;
  732. procedure SetParentFPStructPtrType(AValue: tdef);
  733. function GetParentFPInitBlock: tnode;
  734. procedure SetParentFPInitBlock(AValue: tnode);
  735. function Getprocstarttai: tai;
  736. procedure Setprocstarttai(AValue: tai);
  737. function Getprocendtai: tai;
  738. procedure Setprocendtai(AValue: tai);
  739. function Getskpara: pointer;
  740. procedure Setskpara(AValue: pointer);
  741. function Getpersonality: tprocdef;
  742. procedure Setpersonality(AValue: tprocdef);
  743. function Getforwarddef: boolean;
  744. procedure Setforwarddef(AValue: boolean);
  745. function Getinterfacedef: boolean;
  746. procedure Setinterfacedef(AValue: boolean);virtual;
  747. function Gethasforward: boolean;
  748. procedure Sethasforward(AValue: boolean);
  749. function GetIsEmpty: boolean;
  750. procedure SetIsEmpty(AValue: boolean);
  751. function GetHasInliningInfo: boolean;
  752. procedure SetHasInliningInfo(AValue: boolean);
  753. public
  754. messageinf : tmessageinf;
  755. dispid : longint;
  756. {$ifndef EXTDEBUG}
  757. { where is this function defined and what were the symbol
  758. flags, needed here because there
  759. is only one symbol for all overloaded functions
  760. EXTDEBUG has fileinfo in tdef (PFV) }
  761. fileinfo : tfileposinfo;
  762. {$endif}
  763. symoptions : tsymoptions;
  764. deprecatedmsg : pshortstring;
  765. { generic support }
  766. genericdecltokenbuf : tdynamicarray;
  767. { symbol owning this definition }
  768. procsym : tsym;
  769. procsymderef : tderef;
  770. { alias names }
  771. aliasnames : TCmdStrList;
  772. { symtables }
  773. localst : TSymtable;
  774. funcretsym : tsym;
  775. funcretsymderef : tderef;
  776. struct : tabstractrecorddef;
  777. structderef : tderef;
  778. implprocoptions: timplprocoptions;
  779. { import info }
  780. import_dll,
  781. import_name : pshortstring;
  782. { info for inlining the subroutine, if this pointer is nil,
  783. the procedure can't be inlined }
  784. inlininginfo : pinlininginfo;
  785. {$ifdef oldregvars}
  786. regvarinfo: pregvarinfo;
  787. {$endif oldregvars}
  788. import_nr : word;
  789. extnumber : word;
  790. { set to a value different from tsk_none in case this procdef is for
  791. a routine that has to be internally generated by the compiler }
  792. synthetickind: tsynthetickind;
  793. visibility : tvisibility;
  794. constructor create(level:byte;doregister:boolean);virtual;
  795. constructor ppuload(ppufile:tcompilerppufile);
  796. destructor destroy;override;
  797. procedure freeimplprocdefinfo;
  798. { do not override this routine in platform-specific subclasses,
  799. override ppuwrite_platform instead }
  800. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  801. procedure buildderef;override;
  802. procedure buildderefimpl;override;
  803. procedure deref;override;
  804. procedure derefimpl;override;
  805. function GetSymtable(t:tGetSymtable):TSymtable;override;
  806. { warnings:
  807. * the symtablestack top has to be the symtable to which the copy
  808. should be added
  809. * getcopy does not create a finished/ready-to-use procdef; it
  810. needs to be finalised afterwards by calling
  811. symcreat.finish_copied_procdef() afterwards
  812. }
  813. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string): tstoreddef; override;
  814. function getcopy: tstoreddef; override;
  815. function GetTypeName : string;override;
  816. function mangledname : TSymStr; virtual;
  817. procedure setmangledname(const s : TSymStr);
  818. function needsglobalasmsym: boolean;
  819. procedure setcompilerprocname;
  820. function fullprocname(showhidden:boolean):string;
  821. function customprocname(pno: tprocnameoptions):ansistring;
  822. function defaultmangledname: TSymStr;
  823. function cplusplusmangledname : TSymStr;
  824. function objcmangledname : TSymStr;
  825. function is_methodpointer:boolean;override;
  826. function is_addressonly:boolean;override;
  827. procedure make_external;
  828. procedure init_genericdecl;
  829. function get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean; virtual;
  830. function get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean; virtual;
  831. { returns whether the mangled name or any of its aliases is equal to
  832. s }
  833. function has_alias_name(const s: TSymStr):boolean;
  834. { aliases to fields only required when a function is implemented in
  835. the current unit }
  836. property resultname: PShortString read GetResultName write SetResultName;
  837. { temporary reference to structure containing copies of all local
  838. variables and parameters accessed by nested routines; reference to
  839. this structure is passed as "parent frame pointer" on targets that
  840. lack this concept (at least JVM and LLVM); no need to save to/
  841. restore from ppu, since nested routines are always in the same
  842. unit }
  843. property parentfpstruct: tsym read GetParentFPStruct write SetParentFPStruct;
  844. { pointer to parentfpstruct's type (not yet valid during parsing, so
  845. cannot be used for $parentfp parameter) (no need to save to ppu) }
  846. property parentfpstructptrtype: tdef read GetParentFPStructPtrType write SetParentFPStructPtrType;
  847. { code to copy the parameters accessed from nested routines into the
  848. parentfpstruct (no need to save to ppu) }
  849. property parentfpinitblock: tnode read GetParentFPInitBlock write SetParentFPInitBlock;
  850. { First/last assembler symbol/instruction in aasmoutput list.
  851. Note: initialised after compiling the code for the procdef, but
  852. not saved to/restored from ppu. Used when inserting debug info }
  853. property procstarttai: tai read Getprocstarttai write Setprocstarttai;
  854. property procendtai: tai read Getprocendtai write Setprocendtai;
  855. { optional parameter for the synthetic routine generation logic }
  856. property skpara: pointer read Getskpara write Setskpara;
  857. { ABI-conformant exception handling personality function }
  858. property personality: tprocdef read Getpersonality write Setpersonality;
  859. { true, if the procedure is only declared
  860. (forward procedure) }
  861. property forwarddef: boolean read Getforwarddef write Setforwarddef;
  862. { true if the procedure is declared in the interface }
  863. property interfacedef: boolean read Getinterfacedef write Setinterfacedef;
  864. { true if the procedure has a forward declaration }
  865. property hasforward: boolean read Gethasforward write Sethasforward;
  866. { true if the routine's body is empty }
  867. property isempty: boolean read GetIsEmpty write SetIsEmpty;
  868. { true if all information required to inline this routine is available }
  869. property has_inlininginfo: boolean read GetHasInliningInfo write SetHasInliningInfo;
  870. end;
  871. tprocdefclass = class of tprocdef;
  872. { single linked list of overloaded procs }
  873. pprocdeflist = ^tprocdeflist;
  874. tprocdeflist = record
  875. def : tprocdef;
  876. defderef : tderef;
  877. next : pprocdeflist;
  878. end;
  879. tstringdef = class(tstoreddef)
  880. encoding : tstringencoding;
  881. stringtype : tstringtype;
  882. len : asizeint;
  883. constructor createshort(l: byte; doregister: boolean);virtual;
  884. constructor loadshort(ppufile:tcompilerppufile);
  885. constructor createlong(l: asizeint; doregister: boolean);virtual;
  886. constructor loadlong(ppufile:tcompilerppufile);
  887. constructor createansi(aencoding: tstringencoding; doregister: boolean);virtual;
  888. constructor loadansi(ppufile:tcompilerppufile);
  889. constructor createwide(doregister: boolean);virtual;
  890. constructor loadwide(ppufile:tcompilerppufile);
  891. constructor createunicode(doregister: boolean);virtual;
  892. constructor loadunicode(ppufile:tcompilerppufile);virtual;
  893. function getcopy : tstoreddef;override;
  894. function stringtypname:string;
  895. { do not override this routine in platform-specific subclasses,
  896. override ppuwrite_platform instead }
  897. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  898. function GetTypeName:string;override;
  899. function getmangledparaname:TSymStr;override;
  900. function is_publishable : boolean;override;
  901. function size:asizeint;override;
  902. function alignment : shortint;override;
  903. function needs_inittable : boolean;override;
  904. function getvardef:longint;override;
  905. end;
  906. tstringdefclass = class of tstringdef;
  907. { tenumdef }
  908. tenumdef = class(tstoreddef)
  909. minval,
  910. maxval : asizeint;
  911. basedef : tenumdef;
  912. basedefderef : tderef;
  913. symtable : TSymtable;
  914. has_jumps : boolean;
  915. constructor create;virtual;
  916. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);virtual;
  917. constructor ppuload(ppufile:tcompilerppufile);
  918. destructor destroy;override;
  919. function getcopy : tstoreddef;override;
  920. { do not override this routine in platform-specific subclasses,
  921. override ppuwrite_platform instead }
  922. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  923. procedure buildderef;override;
  924. procedure deref;override;
  925. function GetTypeName:string;override;
  926. function is_publishable : boolean;override;
  927. procedure calcsavesize(packenum: shortint);
  928. function packedbitsize: asizeint; override;
  929. procedure setmax(_max:asizeint);
  930. procedure setmin(_min:asizeint);
  931. function min:asizeint;
  932. function max:asizeint;
  933. function getfirstsym:tsym;
  934. function int2enumsym(l: asizeint): tsym;
  935. { returns basedef if assigned, otherwise self }
  936. function getbasedef: tenumdef;
  937. end;
  938. tenumdefclass = class of tenumdef;
  939. tsetdef = class(tstoreddef)
  940. elementdef : tdef;
  941. elementdefderef : tderef;
  942. setbase,
  943. setmax : asizeint;
  944. constructor create(def: tdef; low, high: asizeint; doregister: boolean);virtual;
  945. constructor ppuload(ppufile:tcompilerppufile);
  946. function getcopy : tstoreddef;override;
  947. { do not override this routine in platform-specific subclasses,
  948. override ppuwrite_platform instead }
  949. procedure ppuwrite(ppufile:tcompilerppufile);override;final;
  950. procedure buildderef;override;
  951. procedure deref;override;
  952. function GetTypeName:string;override;
  953. function is_publishable : boolean;override;
  954. function alignment: shortint; override;
  955. end;
  956. tsetdefclass = class of tsetdef;
  957. tgenericdummyentry = class
  958. dummysym : tsym;
  959. resolvedsym : tsym;
  960. end;
  961. tdefawaresymtablestack = class(TSymtablestack)
  962. private
  963. procedure add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  964. procedure remove_helpers_and_generics(st:tsymtable);inline;
  965. procedure remove_helpers(st:tsymtable);
  966. procedure remove_generics(st:tsymtable);
  967. procedure pushcommon(st:tsymtable);inline;
  968. public
  969. procedure push(st: TSymtable); override;
  970. procedure pushafter(st,afterst:TSymtable); override;
  971. procedure pop(st: TSymtable); override;
  972. end;
  973. var
  974. current_structdef: tabstractrecorddef; { used for private functions check !! }
  975. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  976. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  977. cfiledef: tfiledefclass;
  978. cvariantdef: tvariantdefclass;
  979. cformaldef: tformaldefclass;
  980. cforwarddef: tforwarddefclass;
  981. cundefineddef: tundefineddefclass;
  982. cerrordef: terrordefclass;
  983. cpointerdef: tpointerdefclass;
  984. crecorddef: trecorddefclass;
  985. cimplementedinterface: timplementedinterfaceclass;
  986. cobjectdef: tobjectdefclass;
  987. cclassrefdef: tclassrefdefclass;
  988. carraydef: tarraydefclass;
  989. corddef: torddefclass;
  990. cfloatdef: tfloatdefclass;
  991. cprocvardef: tprocvardefclass;
  992. cprocdef: tprocdefclass;
  993. cstringdef: tstringdefclass;
  994. cenumdef: tenumdefclass;
  995. csetdef: tsetdefclass;
  996. { default types }
  997. generrordef, { error in definition }
  998. voidpointertype, { pointer for Void-pointeddef }
  999. charpointertype, { pointer for Char-pointeddef }
  1000. widecharpointertype, { pointer for WideChar-pointeddef }
  1001. voidcodepointertype, { pointer to code; corresponds to System.CodePointer }
  1002. voidstackpointertype, { the pointer type used for accessing parameters and local vars on the stack }
  1003. parentfpvoidpointertype, { void pointer with the size of the hidden parentfp parameter, passed to nested functions }
  1004. {$ifdef x86}
  1005. voidnearpointertype,
  1006. voidnearcspointertype,
  1007. voidneardspointertype,
  1008. voidnearsspointertype,
  1009. voidnearespointertype,
  1010. voidnearfspointertype,
  1011. voidneargspointertype,
  1012. {$ifdef i8086}
  1013. voidfarpointertype,
  1014. voidhugepointertype,
  1015. charnearpointertype,
  1016. charfarpointertype,
  1017. charhugepointertype,
  1018. bytefarpointertype, { used for Mem[] }
  1019. wordfarpointertype, { used for MemW[] }
  1020. longintfarpointertype, { used for MemL[] }
  1021. {$endif i8086}
  1022. {$endif x86}
  1023. cundefinedtype,
  1024. cformaltype, { unique formal definition }
  1025. ctypedformaltype, { unique typed formal definition }
  1026. voidtype, { Void (procedure) }
  1027. cansichartype, { Char }
  1028. cwidechartype, { WideChar }
  1029. pasbool1type, { boolean type }
  1030. pasbool8type,
  1031. pasbool16type,
  1032. pasbool32type,
  1033. pasbool64type,
  1034. bool8type,
  1035. bool16type,
  1036. bool32type,
  1037. bool64type, { implement me }
  1038. {$ifdef llvm}
  1039. llvmbool1type, { LLVM i1 type }
  1040. {$endif llvm}
  1041. u8inttype, { 8-Bit unsigned integer }
  1042. s8inttype, { 8-Bit signed integer }
  1043. u16inttype, { 16-Bit unsigned integer }
  1044. s16inttype, { 16-Bit signed integer }
  1045. u24inttype, { 24-Bit unsigned integer }
  1046. s24inttype, { 24-Bit signed integer }
  1047. u32inttype, { 32-Bit unsigned integer }
  1048. s32inttype, { 32-Bit signed integer }
  1049. u40inttype, { 40-Bit unsigned integer }
  1050. s40inttype, { 40-Bit signed integer }
  1051. u48inttype, { 48-Bit unsigned integer }
  1052. s48inttype, { 48-Bit signed integer }
  1053. u56inttype, { 56-Bit unsigned integer }
  1054. s56inttype, { 56-Bit signed integer }
  1055. u64inttype, { 64-bit unsigned integer }
  1056. s64inttype, { 64-bit signed integer }
  1057. u128inttype, { 128-bit unsigned integer }
  1058. s128inttype, { 128-bit signed integer }
  1059. s32floattype, { 32 bit floating point number }
  1060. s64floattype, { 64 bit floating point number }
  1061. s80floattype, { 80 bit floating point number }
  1062. sc80floattype, { 80 bit floating point number but stored like in C }
  1063. s64currencytype, { pointer to a currency type }
  1064. cshortstringtype, { pointer to type of short string const }
  1065. clongstringtype, { pointer to type of long string const }
  1066. cansistringtype, { pointer to type of ansi string const }
  1067. cwidestringtype, { pointer to type of wide string const }
  1068. cunicodestringtype,
  1069. openshortstringtype, { pointer to type of an open shortstring,
  1070. needed for readln() }
  1071. openchararraytype, { pointer to type of an open array of char,
  1072. needed for readln() }
  1073. cfiletype, { get the same definition for all file }
  1074. { used for stabs }
  1075. methodpointertype, { typecasting of methodpointers to extract self }
  1076. nestedprocpointertype, { typecasting of nestedprocpointers to extract parentfp }
  1077. hresultdef,
  1078. typekindtype, { def of TTypeKind for correct handling of GetTypeKind parameters }
  1079. { we use only one variant def for every variant class }
  1080. cvarianttype,
  1081. colevarianttype,
  1082. { default integer type, normally s32inttype on 32 bit systems and s64bittype on 64 bit systems }
  1083. sinttype,
  1084. uinttype,
  1085. { integer types corresponding to OS_SINT/OS_INT }
  1086. ossinttype,
  1087. osuinttype,
  1088. { integer types corresponding to the ALU size, sizeof(aint) and the ALUSInt/ALUUInt types in the system unit }
  1089. alusinttype,
  1090. aluuinttype,
  1091. { integer types corresponding to SizeInt and SizeUInt for the target platform }
  1092. sizeuinttype,
  1093. sizesinttype,
  1094. { unsigned and signed ord type with the same size as a pointer }
  1095. ptruinttype,
  1096. ptrsinttype,
  1097. { unsigned and signed ord type with the same size as a codepointer }
  1098. codeptruinttype,
  1099. codeptrsinttype,
  1100. { several types to simulate more or less C++ objects for GDB }
  1101. vmttype,
  1102. vmtarraytype,
  1103. pvmttype : tdef; { type of classrefs, used for stabs }
  1104. { pointer to the anchestor of all classes }
  1105. class_tobject : tobjectdef;
  1106. { pointer to the base type for custom attributes }
  1107. class_tcustomattribute : tobjectdef;
  1108. { pointer to the ancestor of all COM interfaces }
  1109. interface_iunknown : tobjectdef;
  1110. { pointer to the ancestor of all dispinterfaces }
  1111. interface_idispatch : tobjectdef;
  1112. { pointer to the TGUID type
  1113. of all interfaces }
  1114. rec_tguid : trecorddef;
  1115. { jump buffer type, used by setjmp }
  1116. rec_jmp_buf : trecorddef;
  1117. { system.texceptaddr type, used by fpc_pushexceptaddr }
  1118. rec_exceptaddr: trecorddef;
  1119. { Objective-C base types }
  1120. objc_metaclasstype,
  1121. objc_superclasstype,
  1122. objc_idtype,
  1123. objc_seltype : tpointerdef;
  1124. objc_objecttype : trecorddef;
  1125. { base type of @protocol(protocolname) Objective-C statements }
  1126. objc_protocoltype : tobjectdef;
  1127. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  1128. objc_fastenumeration : tobjectdef;
  1129. objc_fastenumerationstate : trecorddef;
  1130. {$ifdef llvm}
  1131. { llvm types }
  1132. { a unique def to identify any kind of metadata }
  1133. llvm_metadatatype : tdef;
  1134. {$endif llvm}
  1135. { Java base types }
  1136. { java.lang.Object }
  1137. java_jlobject : tobjectdef;
  1138. { java.lang.Throwable }
  1139. java_jlthrowable : tobjectdef;
  1140. { FPC base type for records }
  1141. java_fpcbaserecordtype : tobjectdef;
  1142. { java.lang.String }
  1143. java_jlstring : tobjectdef;
  1144. { java.lang.Enum }
  1145. java_jlenum : tobjectdef;
  1146. { java.util.EnumSet }
  1147. java_juenumset : tobjectdef;
  1148. { java.util.BitSet }
  1149. java_jubitset : tobjectdef;
  1150. { FPC java implementation of ansistrings }
  1151. java_ansistring : tobjectdef;
  1152. { FPC java implementation of shortstrings }
  1153. java_shortstring : tobjectdef;
  1154. { FPC java procvar base class }
  1155. java_procvarbase : tobjectdef;
  1156. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1157. function make_dllmangledname(const dllname,importname:TSymStr;
  1158. import_nr : word; pco : tproccalloption):TSymStr;
  1159. { should be in the types unit, but the types unit uses the node stuff :( }
  1160. function is_interfacecom(def: tdef): boolean;
  1161. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  1162. function is_any_interface_kind(def: tdef): boolean;
  1163. function is_interfacecorba(def: tdef): boolean;
  1164. function is_interface(def: tdef): boolean;
  1165. function is_dispinterface(def: tdef): boolean;
  1166. function is_object(def: tdef): boolean;
  1167. function is_class(def: tdef): boolean;
  1168. function is_cppclass(def: tdef): boolean;
  1169. function is_objectpascal_helper(def: tdef): boolean;
  1170. function is_objcclass(def: tdef): boolean;
  1171. function is_objcclassref(def: tdef): boolean;
  1172. function is_objcprotocol(def: tdef): boolean;
  1173. function is_objccategory(def: tdef): boolean;
  1174. function is_objc_class_or_protocol(def: tdef): boolean;
  1175. function is_objc_protocol_or_category(def: tdef): boolean;
  1176. function is_classhelper(def: tdef): boolean;
  1177. function is_class_or_interface(def: tdef): boolean;
  1178. function is_class_or_interface_or_objc(def: tdef): boolean;
  1179. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  1180. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  1181. function is_class_or_interface_or_object(def: tdef): boolean;
  1182. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  1183. function is_implicit_pointer_object_type(def: tdef): boolean;
  1184. { returns true, if def is a type which is an implicit pointer to an array (dyn. array or dyn. string) }
  1185. function is_implicit_array_pointer(def: tdef): boolean;
  1186. function is_class_or_object(def: tdef): boolean;
  1187. function is_record(def: tdef): boolean;
  1188. function is_javaclass(def: tdef): boolean;
  1189. function is_javaclassref(def: tdef): boolean;
  1190. function is_javainterface(def: tdef): boolean;
  1191. function is_java_class_or_interface(def: tdef): boolean;
  1192. procedure loadobjctypes;
  1193. procedure maybeloadcocoatypes;
  1194. function use_vectorfpu(def : tdef) : boolean;
  1195. function getansistringcodepage:tstringencoding; inline;
  1196. function getansistringdef:tstringdef;
  1197. function getparaencoding(def:tdef):tstringencoding; inline;
  1198. function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
  1199. function get_recorddef(prefix:tinternaltypeprefix;const fields:array of tdef; packrecords:shortint): trecorddef;
  1200. { get a table def of the form
  1201. record
  1202. count: countdef;
  1203. elements: array[0..count-1] of elementdef
  1204. end;
  1205. Returns both the outer record and the inner arraydef
  1206. }
  1207. procedure get_tabledef(prefix:tinternaltypeprefix;countdef,elementdef:tdef;count:longint;packrecords:shortint;out recdef:trecorddef;out arrdef:tarraydef);
  1208. implementation
  1209. uses
  1210. SysUtils,
  1211. cutils,
  1212. { global }
  1213. verbose,
  1214. { target }
  1215. systems,paramgr,
  1216. { symtable }
  1217. symsym,symtable,defutil,objcdef,
  1218. { parser }
  1219. pgenutil,
  1220. { module }
  1221. fmodule,ppu,
  1222. { other }
  1223. aasmbase,
  1224. gendef,
  1225. fpccrc,
  1226. entfile
  1227. ;
  1228. {****************************************************************************
  1229. Helpers
  1230. ****************************************************************************}
  1231. function getansistringcodepage:tstringencoding; inline;
  1232. begin
  1233. if ([cs_explicit_codepage,cs_system_codepage]*current_settings.moduleswitches)<>[] then
  1234. result:=current_settings.sourcecodepage
  1235. else
  1236. result:=0;
  1237. end;
  1238. function getansistringdef:tstringdef;
  1239. var
  1240. symtable:tsymtable;
  1241. oldstack : tsymtablestack;
  1242. begin
  1243. { if a codepage is explicitly defined in this mudule we need to return
  1244. a replacement for ansistring def }
  1245. if ([cs_explicit_codepage,cs_system_codepage]*current_settings.moduleswitches)<>[] then
  1246. begin
  1247. if not assigned(current_module) then
  1248. internalerror(2011101301);
  1249. { codepage can be redeclared only once per unit so we don't need a list of
  1250. redefined ansistring but only one pointer }
  1251. if not assigned(current_module.ansistrdef) then
  1252. begin
  1253. { if we did not create it yet we need to do this now }
  1254. if current_module.in_interface then
  1255. symtable:=current_module.globalsymtable
  1256. else
  1257. symtable:=current_module.localsymtable;
  1258. { create a temporary stack as it's not good (TM) to mess around
  1259. with the order if the unit contains generics or helpers; don't
  1260. use a def aware symtablestack though }
  1261. oldstack:=symtablestack;
  1262. symtablestack:=tsymtablestack.create;
  1263. symtablestack.push(symtable);
  1264. current_module.ansistrdef:=cstringdef.createansi(current_settings.sourcecodepage,true);
  1265. symtablestack.pop(symtable);
  1266. symtablestack.free;
  1267. symtablestack:=oldstack;
  1268. end;
  1269. result:=tstringdef(current_module.ansistrdef);
  1270. end
  1271. else
  1272. result:=tstringdef(cansistringtype);
  1273. end;
  1274. function getparaencoding(def:tdef):tstringencoding; inline;
  1275. begin
  1276. { don't pass CP_NONE encoding to internal functions
  1277. they expect 0 encoding instead
  1278. exception: result of string concatenation, because if you pass the
  1279. result of a string concatenation to a rawbytestring, the result of
  1280. that concatenation shouldn't be converted to defaultsystemcodepage
  1281. if all strings have the same type }
  1282. result:=tstringdef(def).encoding;
  1283. if result=globals.CP_NONE then
  1284. result:=0
  1285. end;
  1286. function get_threadvar_record(def: tdef; out index_field, non_mt_data_field: tsym): trecorddef;
  1287. var
  1288. typ: ttypesym;
  1289. name: string;
  1290. begin
  1291. name:=internaltypeprefixName[itp_threadvar_record]+def.unique_id_str;
  1292. typ:=try_search_current_module_type(name);
  1293. if assigned(typ) then
  1294. begin
  1295. result:=trecorddef(ttypesym(typ).typedef);
  1296. index_field:=tsym(result.symtable.symlist[0]);
  1297. non_mt_data_field:=tsym(result.symtable.symlist[1]);
  1298. exit;
  1299. end;
  1300. { set recordalinmin to sizeof(pint), so the second field gets put at
  1301. offset = sizeof(pint) as expected }
  1302. result:=crecorddef.create_global_internal(
  1303. name,sizeof(pint),sizeof(pint));
  1304. {$ifdef cpu16bitaddr}
  1305. index_field:=result.add_field_by_def('',u16inttype);
  1306. {$else cpu16bitaddr}
  1307. index_field:=result.add_field_by_def('',u32inttype);
  1308. {$endif cpu16bitaddr}
  1309. non_mt_data_field:=result.add_field_by_def('',def);
  1310. { no need to add alignment padding, we won't create arrays of these }
  1311. end;
  1312. function get_recorddef(prefix:tinternaltypeprefix; const fields:array of tdef; packrecords:shortint): trecorddef;
  1313. var
  1314. fieldlist: tfplist;
  1315. srsym: tsym;
  1316. srsymtable: tsymtable;
  1317. i: longint;
  1318. name : TIDString;
  1319. begin
  1320. name:=copy(internaltypeprefixName[prefix],2,length(internaltypeprefixName[prefix]));
  1321. if searchsym_type(name,srsym,srsymtable) then
  1322. begin
  1323. result:=trecorddef(ttypesym(srsym).typedef);
  1324. exit
  1325. end;
  1326. { also always search in the current module (symtables are popped for
  1327. RTTI related code already) }
  1328. if searchsym_in_module(pointer(current_module),name,srsym,srsymtable) then
  1329. begin
  1330. result:=trecorddef(ttypesym(srsym).typedef);
  1331. exit;
  1332. end;
  1333. fieldlist:=tfplist.create;
  1334. for i:=low(fields) to high(fields) do
  1335. fieldlist.add(fields[i]);
  1336. result:=crecorddef.create_global_internal(internaltypeprefixName[prefix],packrecords,
  1337. targetinfos[target_info.system]^.alignment.recordalignmin);
  1338. result.add_fields_from_deflist(fieldlist);
  1339. fieldlist.free;
  1340. end;
  1341. procedure get_tabledef(prefix:tinternaltypeprefix;countdef,elementdef:tdef;count:longint;packrecords:shortint;out recdef:trecorddef;out arrdef:tarraydef);
  1342. var
  1343. fields: tfplist;
  1344. name: TIDString;
  1345. srsym: tsym;
  1346. srsymtable: tsymtable;
  1347. begin
  1348. { already created a message string table with this number of elements
  1349. in this unit -> reuse the def }
  1350. name:=internaltypeprefixName[prefix]+tostr(count);
  1351. if searchsym_type(copy(name,2,length(name)),srsym,srsymtable) then
  1352. begin
  1353. recdef:=trecorddef(ttypesym(srsym).typedef);
  1354. arrdef:=tarraydef(trecordsymtable(recdef.symtable).findfieldbyoffset(countdef.size).vardef);
  1355. exit
  1356. end;
  1357. { also always search in the current module (symtables are popped for
  1358. RTTI related code already) }
  1359. if searchsym_in_module(pointer(current_module),copy(name,2,length(name)),srsym,srsymtable) then
  1360. begin
  1361. recdef:=trecorddef(ttypesym(srsym).typedef);
  1362. arrdef:=tarraydef(trecordsymtable(recdef.symtable).findfieldbyoffset(countdef.size).vardef);
  1363. exit;
  1364. end;
  1365. recdef:=crecorddef.create_global_internal(name,packrecords,
  1366. targetinfos[target_info.system]^.alignment.recordalignmin);
  1367. fields:=tfplist.create;
  1368. fields.add(countdef);
  1369. if count>0 then
  1370. begin
  1371. arrdef:=carraydef.create(0,count-1,sizeuinttype);
  1372. arrdef.elementdef:=elementdef;
  1373. fields.add(arrdef);
  1374. end
  1375. else
  1376. arrdef:=nil;
  1377. recdef.add_fields_from_deflist(fields);
  1378. fields.free;
  1379. end;
  1380. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  1381. var
  1382. s,
  1383. prefix : TSymStr;
  1384. crc : dword;
  1385. begin
  1386. prefix:='';
  1387. if not assigned(st) then
  1388. internalerror(200204212);
  1389. { sub procedures }
  1390. while (st.symtabletype in [localsymtable,parasymtable]) do
  1391. begin
  1392. if st.defowner.typ<>procdef then
  1393. internalerror(200204173);
  1394. { Add the full mangledname of procedure to prevent
  1395. conflicts with 2 overloads having both a nested procedure
  1396. with the same name, see tb0314 (PFV) }
  1397. s:=tprocdef(st.defowner).procsym.name;
  1398. s:=s+tprocdef(st.defowner).mangledprocparanames(Length(s));
  1399. if prefix<>'' then
  1400. prefix:=s+'_'+prefix
  1401. else
  1402. prefix:=s;
  1403. if length(prefix)>100 then
  1404. begin
  1405. crc:=0;
  1406. crc:=UpdateCrc32(crc,prefix[1],length(prefix));
  1407. prefix:='$CRC'+hexstr(crc,8);
  1408. end;
  1409. st:=st.defowner.owner;
  1410. end;
  1411. { object/classes symtable, nested type definitions in classes require the while loop }
  1412. while st.symtabletype in [ObjectSymtable,recordsymtable] do
  1413. begin
  1414. if not (st.defowner.typ in [objectdef,recorddef]) then
  1415. internalerror(200204174);
  1416. prefix:=tabstractrecorddef(st.defowner).objname^+'_$_'+prefix;
  1417. st:=st.defowner.owner;
  1418. end;
  1419. { symtable must now be static or global }
  1420. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  1421. internalerror(200204175);
  1422. { The mangled name is made out of at most 4 parts:
  1423. 1) Optional typeprefix given as first parameter
  1424. with '_$' appended if not empty
  1425. 2) Unit name or 'P$'+program name (never empty)
  1426. 3) optional prefix variable that contains a unique
  1427. name for the local symbol table (prepended with '$_$'
  1428. if not empty)
  1429. 4) suffix as given as third parameter,
  1430. also optional (i.e. can be empty)
  1431. prepended by '_$$_' if not empty }
  1432. result:='';
  1433. if typeprefix<>'' then
  1434. result:=result+typeprefix+'_$';
  1435. { Add P$ for program, which can have the same name as
  1436. a unit }
  1437. if (TSymtable(main_module.localsymtable)=st) and
  1438. (not main_module.is_unit) then
  1439. result:=result+'P$'+st.name^
  1440. else
  1441. result:=result+st.name^;
  1442. if prefix<>'' then
  1443. result:=result+'$_$'+prefix;
  1444. if suffix<>'' then
  1445. result:=result+'_$$_'+suffix;
  1446. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  1447. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  1448. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  1449. { those in the debug map, leading to troubles with dsymutil). So always }
  1450. { add an underscore on darwin. }
  1451. if (target_info.system in systems_darwin) then
  1452. result := '_' + result;
  1453. end;
  1454. function make_dllmangledname(const dllname,importname:TSymStr;import_nr : word; pco : tproccalloption):TSymStr;
  1455. var
  1456. crc : cardinal;
  1457. i : longint;
  1458. use_crc : boolean;
  1459. dllprefix : TSymStr;
  1460. begin
  1461. if (target_info.system in (systems_all_windows + systems_nativent +
  1462. [system_i386_emx, system_i386_os2]))
  1463. and (dllname <> '') then
  1464. begin
  1465. dllprefix:=lower(ExtractFileName(dllname));
  1466. { Remove .dll suffix if present }
  1467. if copy(dllprefix,length(dllprefix)-3,length(dllprefix))='.dll' then
  1468. dllprefix:=copy(dllprefix,1,length(dllprefix)-4);
  1469. use_crc:=false;
  1470. for i:=1 to length(dllprefix) do
  1471. if not (dllprefix[i] in ['a'..'z','A'..'Z','_','0'..'9']) then
  1472. begin
  1473. use_crc:=true;
  1474. break;
  1475. end;
  1476. if use_crc then
  1477. begin
  1478. crc:=0;
  1479. crc:=UpdateCrc32(crc,dllprefix[1],length(dllprefix));
  1480. dllprefix:='_$dll$crc$'+hexstr(crc,8)+'$';
  1481. end
  1482. else
  1483. dllprefix:='_$dll$'+dllprefix+'$';
  1484. if importname<>'' then
  1485. result:=dllprefix+importname
  1486. else
  1487. result:=dllprefix+'_index_'+tostr(import_nr);
  1488. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  1489. { This allows to import VC++ mangled names from DLLs. }
  1490. { Do not perform replacement, if external symbol is not imported from DLL. }
  1491. if (dllname<>'') then
  1492. begin
  1493. Replace(result,'?','__q$$');
  1494. {$ifdef arm}
  1495. { @ symbol is not allowed in ARM assembler only }
  1496. Replace(result,'@','__a$$');
  1497. {$endif arm}
  1498. end;
  1499. end
  1500. else
  1501. begin
  1502. if importname<>'' then
  1503. begin
  1504. if not(pco in [pocall_cdecl,pocall_cppdecl]) then
  1505. result:=importname
  1506. else
  1507. result:=target_info.Cprefix+importname;
  1508. end
  1509. else
  1510. result:='_index_'+tostr(import_nr);
  1511. end;
  1512. end;
  1513. {****************************************************************************
  1514. TDEFAWARESYMTABLESTACK
  1515. (symtablestack descendant that does some special actions on
  1516. the pushed/popped symtables)
  1517. ****************************************************************************}
  1518. procedure tdefawaresymtablestack.add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  1519. var
  1520. i: integer;
  1521. s: string;
  1522. list: TFPObjectList;
  1523. def: tdef;
  1524. sym : tsym;
  1525. begin
  1526. { search the symtable from first to last; the helper to use will be the
  1527. last one in the list }
  1528. for i:=0 to st.symlist.count-1 do
  1529. begin
  1530. sym:=tsym(st.symlist[i]);
  1531. if not (sym.typ in [typesym,procsym]) then
  1532. continue;
  1533. if sym.typ=typesym then
  1534. def:=ttypesym(st.SymList[i]).typedef
  1535. else
  1536. def:=nil;
  1537. if is_objectpascal_helper(def) then
  1538. begin
  1539. s:=generate_objectpascal_helper_key(tobjectdef(def).extendeddef);
  1540. Message1(sym_d_adding_helper_for,s);
  1541. list:=TFPObjectList(current_module.extendeddefs.Find(s));
  1542. if not assigned(list) then
  1543. begin
  1544. list:=TFPObjectList.Create(false);
  1545. current_module.extendeddefs.Add(s,list);
  1546. end;
  1547. list.Add(def);
  1548. end
  1549. else
  1550. begin
  1551. if addgenerics then
  1552. add_generic_dummysym(sym);
  1553. { add nested helpers as well }
  1554. if assigned(def) and
  1555. (def.typ in [recorddef,objectdef]) and
  1556. (sto_has_helper in tabstractrecorddef(def).symtable.tableoptions) then
  1557. add_helpers_and_generics(tabstractrecorddef(def).symtable,false);
  1558. end;
  1559. end;
  1560. end;
  1561. procedure tdefawaresymtablestack.remove_helpers_and_generics(st:tsymtable);
  1562. begin
  1563. if sto_has_helper in st.tableoptions then
  1564. remove_helpers(st);
  1565. if sto_has_generic in st.tableoptions then
  1566. remove_generics(st);
  1567. end;
  1568. procedure tdefawaresymtablestack.remove_helpers(st:TSymtable);
  1569. var
  1570. i, j: integer;
  1571. tmpst: TSymtable;
  1572. list: TFPObjectList;
  1573. begin
  1574. for i:=current_module.extendeddefs.count-1 downto 0 do
  1575. begin
  1576. list:=TFPObjectList(current_module.extendeddefs[i]);
  1577. for j:=list.count-1 downto 0 do
  1578. begin
  1579. if not (list[j] is tobjectdef) then
  1580. Internalerror(2011031501);
  1581. tmpst:=tobjectdef(list[j]).owner;
  1582. repeat
  1583. if tmpst=st then
  1584. begin
  1585. list.delete(j);
  1586. break;
  1587. end
  1588. else
  1589. begin
  1590. if assigned(tmpst.defowner) then
  1591. tmpst:=tmpst.defowner.owner
  1592. else
  1593. tmpst:=nil;
  1594. end;
  1595. until not assigned(tmpst) or (tmpst.symtabletype in [globalsymtable,staticsymtable]);
  1596. end;
  1597. if list.count=0 then
  1598. current_module.extendeddefs.delete(i);
  1599. end;
  1600. end;
  1601. procedure tdefawaresymtablestack.remove_generics(st:tsymtable);
  1602. var
  1603. i,j : longint;
  1604. entry : tgenericdummyentry;
  1605. list : tfpobjectlist;
  1606. begin
  1607. for i:=current_module.genericdummysyms.count-1 downto 0 do
  1608. begin
  1609. list:=tfpobjectlist(current_module.genericdummysyms[i]);
  1610. if not assigned(list) then
  1611. continue;
  1612. for j:=list.count-1 downto 0 do
  1613. begin
  1614. entry:=tgenericdummyentry(list[j]);
  1615. if entry.dummysym.owner=st then
  1616. list.delete(j);
  1617. end;
  1618. if list.count=0 then
  1619. current_module.genericdummysyms.delete(i);
  1620. end;
  1621. end;
  1622. procedure tdefawaresymtablestack.pushcommon(st:tsymtable);
  1623. begin
  1624. if (sto_has_generic in st.tableoptions) or
  1625. (
  1626. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1627. (sto_has_helper in st.tableoptions)
  1628. ) then
  1629. { nested helpers will be added as well }
  1630. add_helpers_and_generics(st,true);
  1631. end;
  1632. procedure tdefawaresymtablestack.push(st: TSymtable);
  1633. begin
  1634. pushcommon(st);
  1635. inherited push(st);
  1636. end;
  1637. procedure tdefawaresymtablestack.pushafter(st,afterst:TSymtable);
  1638. begin
  1639. pushcommon(st);
  1640. inherited pushafter(st,afterst);
  1641. end;
  1642. procedure tdefawaresymtablestack.pop(st: TSymtable);
  1643. begin
  1644. inherited pop(st);
  1645. if (sto_has_generic in st.tableoptions) or
  1646. (
  1647. (st.symtabletype in [globalsymtable,staticsymtable]) and
  1648. (sto_has_helper in st.tableoptions)
  1649. ) then
  1650. { nested helpers will be removed as well }
  1651. remove_helpers_and_generics(st);
  1652. end;
  1653. {****************************************************************************
  1654. TDEF (base class for definitions)
  1655. ****************************************************************************}
  1656. constructor tgenericconstraintdata.create;
  1657. begin
  1658. interfaces:=tfpobjectlist.create(false);
  1659. interfacesderef:=tfplist.create;
  1660. end;
  1661. destructor tgenericconstraintdata.destroy;
  1662. var
  1663. i : longint;
  1664. begin
  1665. for i:=0 to interfacesderef.count-1 do
  1666. dispose(pderef(interfacesderef[i]));
  1667. interfacesderef.free;
  1668. interfaces.free;
  1669. inherited destroy;
  1670. end;
  1671. procedure tgenericconstraintdata.ppuload(ppufile: tcompilerppufile);
  1672. var
  1673. cnt,i : longint;
  1674. intfderef : pderef;
  1675. begin
  1676. ppufile.getset(tppuset1(flags));
  1677. cnt:=ppufile.getlongint;
  1678. for i:=0 to cnt-1 do
  1679. begin
  1680. new(intfderef);
  1681. ppufile.getderef(intfderef^);
  1682. interfacesderef.add(intfderef);
  1683. end;
  1684. end;
  1685. procedure tgenericconstraintdata.ppuwrite(ppufile: tcompilerppufile);
  1686. var
  1687. i : longint;
  1688. begin
  1689. ppufile.putset(tppuset1(flags));
  1690. ppufile.putlongint(interfacesderef.count);
  1691. for i:=0 to interfacesderef.count-1 do
  1692. ppufile.putderef(pderef(interfacesderef[i])^);
  1693. end;
  1694. procedure tgenericconstraintdata.buildderef;
  1695. var
  1696. intfderef : pderef;
  1697. i : longint;
  1698. begin
  1699. for i:=0 to interfaces.count-1 do
  1700. begin
  1701. new(intfderef);
  1702. intfderef^.build(tobjectdef(interfaces[i]));
  1703. interfacesderef.add(intfderef);
  1704. end;
  1705. end;
  1706. procedure tgenericconstraintdata.deref;
  1707. var
  1708. i : longint;
  1709. begin
  1710. for i:=0 to interfacesderef.count-1 do
  1711. interfaces.add(pderef(interfacesderef[i])^.resolve);
  1712. end;
  1713. procedure tstoreddef.writeentry(ppufile: tcompilerppufile; ibnr: byte);
  1714. begin
  1715. ppuwrite_platform(ppufile);
  1716. ppufile.writeentry(ibnr);
  1717. end;
  1718. procedure tstoreddef.ppuwrite_platform(ppufile: tcompilerppufile);
  1719. begin
  1720. { by default: do nothing }
  1721. end;
  1722. procedure tstoreddef.ppuload_platform(ppufile: tcompilerppufile);
  1723. begin
  1724. { by default: do nothing }
  1725. end;
  1726. class procedure tstoreddef.setup_reusable_def(origdef, newdef: tdef; res: PHashSetItem; oldsymtablestack: tsymtablestack);
  1727. var
  1728. reusablesymtab: tsymtable;
  1729. begin
  1730. { must not yet belong to a symtable }
  1731. if assigned(newdef.owner) then
  1732. internalerror(2015111503);
  1733. reusablesymtab:=origdef.getreusablesymtab;
  1734. res^.Data:=newdef;
  1735. reusablesymtab.insertdef(newdef);
  1736. symtablestack:=oldsymtablestack;
  1737. end;
  1738. constructor tstoreddef.create(dt:tdeftyp;doregister:boolean);
  1739. begin
  1740. inherited create(dt);
  1741. savesize := 0;
  1742. {$ifdef EXTDEBUG}
  1743. fileinfo := current_filepos;
  1744. {$endif}
  1745. generictokenbuf:=nil;
  1746. genericdef:=nil;
  1747. typesymderef.reset;
  1748. genericdefderef.reset;
  1749. { Don't register forwarddefs, they are disposed at the
  1750. end of an type block }
  1751. if (dt=forwarddef) then
  1752. exit;
  1753. { Register in symtable stack }
  1754. if doregister then
  1755. begin
  1756. { immediately register interface defs, as they will always be
  1757. written to the ppu, their defid inlfuences the interface crc and
  1758. if we wait, depending on e.g. compiler defines they may get a
  1759. different defid (e.g. when a function is called, its procdef is
  1760. registered, so depending on whether or not, or when, an interface
  1761. procedure is called in the implementation, that may change its
  1762. defid otherwise) }
  1763. if assigned(current_module) and
  1764. current_module.in_interface then
  1765. register_def
  1766. else
  1767. maybe_put_in_symtable_stack;
  1768. end;
  1769. end;
  1770. destructor tstoreddef.destroy;
  1771. var
  1772. i : longint;
  1773. begin
  1774. { Direct calls are not allowed, use symtable.deletedef() }
  1775. if assigned(owner) then
  1776. internalerror(200612311);
  1777. if assigned(generictokenbuf) then
  1778. begin
  1779. generictokenbuf.free;
  1780. generictokenbuf:=nil;
  1781. end;
  1782. rtti_attribute_list.free;
  1783. genericparas.free;
  1784. if assigned(genericparaderefs) then
  1785. for i:=0 to genericparaderefs.count-1 do
  1786. dispose(pderef(genericparaderefs[i]));
  1787. genericparaderefs.free;
  1788. genconstraintdata.free;
  1789. {$ifndef symansistr}
  1790. stringdispose(_fullownerhierarchyname);
  1791. {$endif not symansistr}
  1792. inherited destroy;
  1793. end;
  1794. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1795. var
  1796. sizeleft,i,cnt : longint;
  1797. buf : array[0..255] of byte;
  1798. symderef : pderef;
  1799. begin
  1800. inherited create(dt);
  1801. DefId:=ppufile.getlongint;
  1802. current_module.deflist[DefId]:=self;
  1803. {$ifdef EXTDEBUG}
  1804. fillchar(fileinfo,sizeof(fileinfo),0);
  1805. {$endif}
  1806. { load }
  1807. ppufile.getderef(typesymderef);
  1808. ppufile.getset(tppuset2(defoptions));
  1809. ppufile.getset(tppuset1(defstates));
  1810. if df_genconstraint in defoptions then
  1811. begin
  1812. genconstraintdata:=tgenericconstraintdata.create;
  1813. genconstraintdata.ppuload(ppufile);
  1814. end;
  1815. if [df_generic,df_specialization]*defoptions<>[] then
  1816. begin
  1817. cnt:=ppufile.getlongint;
  1818. if cnt>0 then
  1819. begin
  1820. genericparas:=tfphashobjectlist.create(false);
  1821. genericparaderefs:=tfplist.create;
  1822. for i:=0 to cnt-1 do
  1823. begin
  1824. genericparas.add(ppufile.getstring,nil);
  1825. New(symderef);
  1826. ppufile.getderef(symderef^);
  1827. genericparaderefs.add(symderef);
  1828. end;
  1829. end;
  1830. end;
  1831. if df_generic in defoptions then
  1832. begin
  1833. sizeleft:=ppufile.getlongint;
  1834. initgeneric;
  1835. while sizeleft>0 do
  1836. begin
  1837. if sizeleft>sizeof(buf) then
  1838. i:=sizeof(buf)
  1839. else
  1840. i:=sizeleft;
  1841. ppufile.getdata(buf,i);
  1842. generictokenbuf.write(buf,i);
  1843. dec(sizeleft,i);
  1844. end;
  1845. end;
  1846. if df_specialization in defoptions then
  1847. ppufile.getderef(genericdefderef);
  1848. rtti_attribute_list:=trtti_attribute_list.ppuload(ppufile);
  1849. end;
  1850. function tstoreddef.needs_separate_initrtti:boolean;
  1851. begin
  1852. result:=false;
  1853. end;
  1854. function tstoreddef.rtti_mangledname(rt : trttitype) : TSymStr;
  1855. var
  1856. prefix : string[4];
  1857. begin
  1858. if (rt=fullrtti) or (not needs_separate_initrtti) then
  1859. begin
  1860. prefix:='RTTI';
  1861. include(defstates,ds_rtti_table_used);
  1862. end
  1863. else
  1864. begin
  1865. prefix:='INIT';
  1866. include(defstates,ds_init_table_used);
  1867. end;
  1868. if assigned(typesym) and
  1869. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  1870. result:=make_mangledname(prefix,typesym.owner,typesym.name)
  1871. else
  1872. result:=make_mangledname(prefix,findunitsymtable(owner),'def'+unique_id_str)
  1873. end;
  1874. function tstoreddef.OwnerHierarchyName: string;
  1875. var
  1876. tmp: tdef;
  1877. begin
  1878. tmp:=self;
  1879. result:='';
  1880. repeat
  1881. { can be not assigned in case of a forwarddef }
  1882. if assigned(tmp.owner) and
  1883. (tmp.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  1884. tmp:=tdef(tmp.owner.defowner)
  1885. else
  1886. break;
  1887. result:=tabstractrecorddef(tmp).objrealname^+'.'+result;
  1888. until tmp=nil;
  1889. end;
  1890. function tstoreddef.fullownerhierarchyname(skipprocparams:boolean): TSymStr;
  1891. var
  1892. lastowner: tsymtable;
  1893. tmp: tdef;
  1894. pno: tprocnameoptions;
  1895. begin
  1896. {$ifdef symansistr}
  1897. if not skipprocparams and (_fullownerhierarchyname<>'') then
  1898. exit(_fullownerhierarchyname);
  1899. {$else symansistr}
  1900. if not skipprocparams and assigned(_fullownerhierarchyname) then
  1901. exit(_fullownerhierarchyname^);
  1902. {$endif symansistr}
  1903. { the def can only reside inside structured types or
  1904. procedures/functions/methods }
  1905. tmp:=self;
  1906. result:='';
  1907. repeat
  1908. lastowner:=tmp.owner;
  1909. { can be not assigned in case of a forwarddef }
  1910. if not assigned(lastowner) then
  1911. break
  1912. else
  1913. tmp:=tdef(lastowner.defowner);
  1914. if not assigned(tmp) then
  1915. break;
  1916. if tmp.typ in [recorddef,objectdef] then
  1917. result:=tabstractrecorddef(tmp).objrealname^+'.'+result
  1918. else
  1919. if tmp.typ=procdef then
  1920. begin
  1921. pno:=[pno_paranames,pno_proctypeoption];
  1922. if skipprocparams then
  1923. include(pno,pno_noparams);
  1924. result:=tprocdef(tmp).customprocname(pno)+'.'+result;
  1925. end;
  1926. until tmp=nil;
  1927. { add the unit name }
  1928. if assigned(lastowner) and
  1929. assigned(lastowner.realname) then
  1930. result:=lastowner.realname^+'.'+result;
  1931. if not skipprocparams then
  1932. { don't store the name in this case }
  1933. {$ifdef symansistr}
  1934. _fullownerhierarchyname:=result;
  1935. {$else symansistr}
  1936. _fullownerhierarchyname:=stringdup(result);
  1937. {$endif symansistr}
  1938. end;
  1939. function tstoreddef.in_currentunit: boolean;
  1940. var
  1941. st: tsymtable;
  1942. begin
  1943. st:=owner;
  1944. while not(st.symtabletype in [globalsymtable,staticsymtable]) do
  1945. st:=st.defowner.owner;
  1946. result:=st.iscurrentunit;
  1947. end;
  1948. function tstoreddef.getcopy : tstoreddef;
  1949. begin
  1950. Message(sym_e_cant_create_unique_type);
  1951. getcopy:=cerrordef.create;
  1952. end;
  1953. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  1954. var
  1955. sizeleft,i : longint;
  1956. buf : array[0..255] of byte;
  1957. oldintfcrc : boolean;
  1958. begin
  1959. if defid<0 then
  1960. internalerror(2015101401);
  1961. ppufile.putlongint(DefId);
  1962. ppufile.putderef(typesymderef);
  1963. ppufile.putset(tppuset2(defoptions));
  1964. oldintfcrc:=ppufile.do_crc;
  1965. ppufile.do_crc:=false;
  1966. ppufile.putset(tppuset1(defstates));
  1967. if df_genconstraint in defoptions then
  1968. genconstraintdata.ppuwrite(ppufile);
  1969. if [df_generic,df_specialization]*defoptions<>[] then
  1970. begin
  1971. if not assigned(genericparas) then
  1972. ppufile.putlongint(0)
  1973. else
  1974. begin
  1975. if not assigned(genericparaderefs) then
  1976. internalerror(2014052305);
  1977. ppufile.putlongint(genericparas.count);
  1978. for i:=0 to genericparas.count-1 do
  1979. begin
  1980. ppufile.putstring(genericparas.nameofindex(i));
  1981. ppufile.putderef(pderef(genericparaderefs[i])^);
  1982. end;
  1983. end;
  1984. end;
  1985. if df_generic in defoptions then
  1986. begin
  1987. if assigned(generictokenbuf) then
  1988. begin
  1989. sizeleft:=generictokenbuf.size;
  1990. generictokenbuf.seek(0);
  1991. end
  1992. else
  1993. sizeleft:=0;
  1994. ppufile.putlongint(sizeleft);
  1995. while sizeleft>0 do
  1996. begin
  1997. if sizeleft>sizeof(buf) then
  1998. i:=sizeof(buf)
  1999. else
  2000. i:=sizeleft;
  2001. generictokenbuf.read(buf,i);
  2002. ppufile.putdata(buf,i);
  2003. dec(sizeleft,i);
  2004. end;
  2005. end;
  2006. ppufile.do_crc:=oldintfcrc;
  2007. if df_specialization in defoptions then
  2008. ppufile.putderef(genericdefderef);
  2009. trtti_attribute_list.ppuwrite(rtti_attribute_list,ppufile);
  2010. end;
  2011. procedure tstoreddef.ppuload_subentries(ppufile: tcompilerppufile);
  2012. begin
  2013. trtti_attribute_list.ppuload_subentries(rtti_attribute_list,ppufile);
  2014. end;
  2015. procedure tstoreddef.ppuwrite_subentries(ppufile: tcompilerppufile);
  2016. begin
  2017. trtti_attribute_list.ppuwrite_subentries(rtti_attribute_list,ppufile);
  2018. end;
  2019. procedure tstoreddef.buildderef;
  2020. var
  2021. i : longint;
  2022. sym : tsym;
  2023. symderef : pderef;
  2024. begin
  2025. if not registered then
  2026. register_def;
  2027. typesymderef.build(typesym);
  2028. genericdefderef.build(genericdef);
  2029. if assigned(rtti_attribute_list) then
  2030. rtti_attribute_list.buildderef;
  2031. if assigned(genconstraintdata) then
  2032. genconstraintdata.buildderef;
  2033. if assigned(genericparas) then
  2034. begin
  2035. if not assigned(genericparaderefs) then
  2036. genericparaderefs:=tfplist.create;
  2037. for i:=0 to genericparas.count-1 do
  2038. begin
  2039. sym:=tsym(genericparas.items[i]);
  2040. new(symderef);
  2041. symderef^.build(sym);
  2042. genericparaderefs.add(symderef);
  2043. end;
  2044. end;
  2045. end;
  2046. procedure tstoreddef.buildderefimpl;
  2047. begin
  2048. end;
  2049. procedure tstoreddef.deref;
  2050. var
  2051. symderef : pderef;
  2052. i : longint;
  2053. begin
  2054. typesym:=ttypesym(typesymderef.resolve);
  2055. if df_specialization in defoptions then
  2056. genericdef:=tstoreddef(genericdefderef.resolve);
  2057. if assigned(rtti_attribute_list) then
  2058. rtti_attribute_list.deref;
  2059. if assigned(genconstraintdata) then
  2060. genconstraintdata.deref;
  2061. if assigned(genericparas) then
  2062. begin
  2063. if not assigned(genericparaderefs) then
  2064. internalerror(2014052302);
  2065. if genericparas.count<>genericparaderefs.count then
  2066. internalerror(2014052303);
  2067. for i:=0 to genericparaderefs.count-1 do
  2068. begin
  2069. symderef:=pderef(genericparaderefs[i]);
  2070. genericparas.items[i]:=symderef^.resolve;
  2071. end;
  2072. end;
  2073. end;
  2074. procedure tstoreddef.derefimpl;
  2075. begin
  2076. end;
  2077. function tstoreddef.size : asizeint;
  2078. begin
  2079. size:=savesize;
  2080. end;
  2081. function tstoreddef.getvardef:longint;
  2082. begin
  2083. result:=varUndefined;
  2084. end;
  2085. function tstoreddef.alignment : shortint;
  2086. begin
  2087. { natural alignment by default }
  2088. alignment:=size_2_align(savesize);
  2089. { can happen if savesize = 0, e.g. for voiddef or
  2090. an empty record
  2091. }
  2092. if (alignment=0) then
  2093. alignment:=1;
  2094. end;
  2095. { returns true, if the definition can be published }
  2096. function tstoreddef.is_publishable : boolean;
  2097. begin
  2098. is_publishable:=false;
  2099. end;
  2100. { needs an init table }
  2101. function tstoreddef.needs_inittable : boolean;
  2102. begin
  2103. needs_inittable:=false;
  2104. end;
  2105. function tstoreddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  2106. begin
  2107. result:=false;
  2108. end;
  2109. function tstoreddef.is_intregable : boolean;
  2110. var
  2111. recsize,temp: longint;
  2112. begin
  2113. case typ of
  2114. orddef,
  2115. pointerdef,
  2116. enumdef,
  2117. classrefdef:
  2118. is_intregable:=true;
  2119. procvardef :
  2120. is_intregable:=tprocvardef(self).is_addressonly or (po_methodpointer in tprocvardef(self).procoptions);
  2121. objectdef:
  2122. is_intregable:=(is_implicit_pointer_object_type(self)) and not needs_inittable;
  2123. setdef:
  2124. is_intregable:=is_smallset(self);
  2125. arraydef:
  2126. {$ifdef cpuhighleveltarget}
  2127. is_intregable:=false
  2128. {$else cpuhighleveltarget}
  2129. is_intregable:=not(is_special_array(self)) and
  2130. (tarraydef(self).size<=8) and (tarraydef(self).size in [1,2,4,8]) and
  2131. tstoreddef(tarraydef(self).elementdef).is_intregable
  2132. {$ifdef SUPPORT_MMX}
  2133. and not((cs_mmx in current_settings.localswitches) and
  2134. is_mmx_able_array(self))
  2135. {$endif SUPPORT_MMX}
  2136. {$endif cpuhighleveltarget}
  2137. ;
  2138. recorddef:
  2139. begin
  2140. {$ifdef cpuhighleveltarget}
  2141. is_intregable:=false;
  2142. {$else cpuhighleveltarget}
  2143. recsize:=size;
  2144. is_intregable:=
  2145. ispowerof2(recsize,temp) and
  2146. ((recsize<=sizeof(aint)*2) and
  2147. not trecorddef(self).contains_cross_aword_field and
  2148. { records cannot go into registers on 16 bit targets for now }
  2149. (sizeof(aint)>2) and
  2150. (not trecorddef(self).contains_float_field) or
  2151. (recsize <= sizeof(aint))
  2152. ) and
  2153. not needs_inittable;
  2154. {$endif cpuhighleveltarget}
  2155. end;
  2156. else
  2157. is_intregable:=false;
  2158. end;
  2159. end;
  2160. function tstoreddef.is_fpuregable : boolean;
  2161. begin
  2162. {$ifdef x86}
  2163. result:=use_vectorfpu(self);
  2164. {$else x86}
  2165. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  2166. {$endif x86}
  2167. end;
  2168. function tstoreddef.is_const_intregable : boolean;
  2169. begin
  2170. case typ of
  2171. stringdef:
  2172. result:=tstringdef(self).stringtype in [st_ansistring,st_unicodestring,st_widestring];
  2173. arraydef:
  2174. result:=is_dynamic_array(self);
  2175. objectdef:
  2176. result:=is_interface(self);
  2177. else
  2178. result:=false;
  2179. end;
  2180. end;
  2181. procedure tstoreddef.initgeneric;
  2182. begin
  2183. if assigned(generictokenbuf) then
  2184. internalerror(200512131);
  2185. generictokenbuf:=tdynamicarray.create(256);
  2186. end;
  2187. function tstoreddef.is_generic: boolean;
  2188. var
  2189. sym: tsym;
  2190. i: longint;
  2191. begin
  2192. result:=assigned(genericparas) and
  2193. (genericparas.count>0) and
  2194. (df_generic in defoptions);
  2195. if result then
  2196. { if any of the type parameters does *not* belong to as (meaning it was passed
  2197. in from outside) then we aren't a generic, but a specialization }
  2198. for i:=0 to genericparas.count-1 do
  2199. begin
  2200. sym:=tsym(genericparas[i]);
  2201. if sym.typ<>symconst.typesym then
  2202. internalerror(2014050903);
  2203. if sym.owner.defowner<>self then
  2204. exit(false);
  2205. end;
  2206. end;
  2207. function tstoreddef.is_specialization: boolean;
  2208. var
  2209. i : longint;
  2210. sym : tsym;
  2211. begin
  2212. result:=assigned(genericparas) and
  2213. (genericparas.count>0) and
  2214. (df_specialization in defoptions);
  2215. if result then
  2216. begin
  2217. { if at least one of the generic parameters is not owned by us (meaning it was
  2218. passed in from outside) then we have a specialization, otherwise we have a generic }
  2219. for i:=0 to genericparas.count-1 do
  2220. begin
  2221. sym:=tsym(genericparas[i]);
  2222. if sym.typ<>symconst.typesym then
  2223. internalerror(2014050904);
  2224. if sym.owner.defowner<>self then
  2225. exit(true);
  2226. end;
  2227. result:=false;
  2228. end;
  2229. end;
  2230. procedure tstoreddef.register_def;
  2231. var
  2232. gst : tgetsymtable;
  2233. st : tsymtable;
  2234. begin
  2235. if registered then
  2236. exit;
  2237. { Register in current_module }
  2238. if assigned(current_module) then
  2239. begin
  2240. exclude(defoptions,df_not_registered_no_free);
  2241. for gst:=low(tgetsymtable) to high(tgetsymtable) do
  2242. begin
  2243. st:=getsymtable(gst);
  2244. if assigned(st) then
  2245. tstoredsymtable(st).register_children;
  2246. end;
  2247. if defid<defid_not_registered then
  2248. defid:=deflist_index
  2249. else
  2250. begin
  2251. current_module.deflist.Add(self);
  2252. defid:=current_module.deflist.Count-1;
  2253. end;
  2254. maybe_put_in_symtable_stack;
  2255. end
  2256. else
  2257. DefId:=defid_registered_nost;
  2258. end;
  2259. procedure tstoreddef.maybe_put_in_symtable_stack;
  2260. var
  2261. insertstack: psymtablestackitem;
  2262. begin
  2263. if assigned(symtablestack) and
  2264. not assigned(self.owner) then
  2265. begin
  2266. insertstack:=symtablestack.stack;
  2267. { don't insert defs in exception symtables, as they are freed before
  2268. the module is compiled, so we can get crashes on high level targets
  2269. if they still need it while e.g. writing assembler code }
  2270. while assigned(insertstack) and
  2271. (insertstack^.symtable.symtabletype in [stt_exceptsymtable,withsymtable]) do
  2272. insertstack:=insertstack^.next;
  2273. if not assigned(insertstack) then
  2274. internalerror(200602044);
  2275. if insertstack^.symtable.sealed then
  2276. internalerror(2015022301);
  2277. insertstack^.symtable.insertdef(self);
  2278. end;
  2279. end;
  2280. {****************************************************************************
  2281. Tstringdef
  2282. ****************************************************************************}
  2283. constructor tstringdef.createshort(l: byte; doregister: boolean);
  2284. begin
  2285. inherited create(stringdef,doregister);
  2286. stringtype:=st_shortstring;
  2287. encoding:=0;
  2288. len:=l;
  2289. end;
  2290. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  2291. begin
  2292. inherited ppuload(stringdef,ppufile);
  2293. stringtype:=st_shortstring;
  2294. encoding:=0;
  2295. len:=ppufile.getbyte;
  2296. ppuload_platform(ppufile);
  2297. end;
  2298. constructor tstringdef.createlong(l: asizeint; doregister: boolean);
  2299. begin
  2300. inherited create(stringdef,doregister);
  2301. stringtype:=st_longstring;
  2302. encoding:=0;
  2303. len:=l;
  2304. end;
  2305. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  2306. begin
  2307. inherited ppuload(stringdef,ppufile);
  2308. stringtype:=st_longstring;
  2309. encoding:=0;
  2310. len:=ppufile.getasizeint;
  2311. ppuload_platform(ppufile);
  2312. end;
  2313. constructor tstringdef.createansi(aencoding: tstringencoding; doregister: boolean);
  2314. begin
  2315. inherited create(stringdef,doregister);
  2316. stringtype:=st_ansistring;
  2317. encoding:=aencoding;
  2318. len:=-1;
  2319. end;
  2320. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  2321. begin
  2322. inherited ppuload(stringdef,ppufile);
  2323. stringtype:=st_ansistring;
  2324. len:=ppufile.getasizeint;
  2325. encoding:=ppufile.getword;
  2326. ppuload_platform(ppufile);
  2327. end;
  2328. constructor tstringdef.createwide(doregister: boolean);
  2329. begin
  2330. inherited create(stringdef,doregister);
  2331. stringtype:=st_widestring;
  2332. if target_info.endian=endian_little then
  2333. encoding:=CP_UTF16LE
  2334. else
  2335. encoding:=CP_UTF16BE;
  2336. len:=-1;
  2337. end;
  2338. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  2339. begin
  2340. inherited ppuload(stringdef,ppufile);
  2341. stringtype:=st_widestring;
  2342. if target_info.endian=endian_little then
  2343. encoding:=CP_UTF16LE
  2344. else
  2345. encoding:=CP_UTF16BE;
  2346. len:=ppufile.getasizeint;
  2347. ppuload_platform(ppufile);
  2348. end;
  2349. constructor tstringdef.createunicode(doregister: boolean);
  2350. begin
  2351. inherited create(stringdef,doregister);
  2352. stringtype:=st_unicodestring;
  2353. if target_info.endian=endian_little then
  2354. encoding:=CP_UTF16LE
  2355. else
  2356. encoding:=CP_UTF16BE;
  2357. len:=-1;
  2358. end;
  2359. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  2360. begin
  2361. inherited ppuload(stringdef,ppufile);
  2362. stringtype:=st_unicodestring;
  2363. len:=ppufile.getasizeint;
  2364. encoding:=ppufile.getword;
  2365. ppuload_platform(ppufile);
  2366. end;
  2367. function tstringdef.getcopy : tstoreddef;
  2368. begin
  2369. result:=cstringdef.create(typ,true);
  2370. result.typ:=stringdef;
  2371. tstringdef(result).stringtype:=stringtype;
  2372. tstringdef(result).encoding:=encoding;
  2373. tstringdef(result).len:=len;
  2374. end;
  2375. function tstringdef.stringtypname:string;
  2376. const
  2377. typname:array[tstringtype] of string[10]=(
  2378. 'shortstr','longstr','ansistr','widestr','unicodestr'
  2379. );
  2380. begin
  2381. stringtypname:=typname[stringtype];
  2382. end;
  2383. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  2384. begin
  2385. inherited ppuwrite(ppufile);
  2386. if stringtype=st_shortstring then
  2387. begin
  2388. {$ifdef extdebug}
  2389. if len > 255 then internalerror(12122002);
  2390. {$endif}
  2391. ppufile.putbyte(byte(len))
  2392. end
  2393. else
  2394. ppufile.putasizeint(len);
  2395. if stringtype in [st_ansistring,st_unicodestring] then
  2396. ppufile.putword(encoding);
  2397. case stringtype of
  2398. st_shortstring : writeentry(ppufile,ibshortstringdef);
  2399. st_longstring : writeentry(ppufile,iblongstringdef);
  2400. st_ansistring : writeentry(ppufile,ibansistringdef);
  2401. st_widestring : writeentry(ppufile,ibwidestringdef);
  2402. st_unicodestring : writeentry(ppufile,ibunicodestringdef);
  2403. end;
  2404. end;
  2405. function tstringdef.needs_inittable : boolean;
  2406. begin
  2407. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  2408. end;
  2409. function tstringdef.GetTypeName : string;
  2410. const
  2411. names : array[tstringtype] of string[15] = (
  2412. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  2413. begin
  2414. GetTypeName:=names[stringtype];
  2415. end;
  2416. function tstringdef.getvardef : longint;
  2417. const
  2418. vardef : array[tstringtype] of longint = (
  2419. varUndefined,varUndefined,varString,varOleStr,varUString);
  2420. begin
  2421. result:=vardef[stringtype];
  2422. end;
  2423. function tstringdef.alignment : shortint;
  2424. begin
  2425. case stringtype of
  2426. st_unicodestring,
  2427. st_widestring,
  2428. st_ansistring:
  2429. alignment:=voidpointertype.alignment;
  2430. st_longstring,
  2431. st_shortstring:
  2432. { char to string accesses byte 0 and 1 with one word access }
  2433. if (tf_requires_proper_alignment in target_info.flags) or
  2434. { macpas needs an alignment of 2 (MetroWerks compatible) }
  2435. (m_mac in current_settings.modeswitches) then
  2436. alignment:=size_2_align(2)
  2437. else
  2438. alignment:=size_2_align(1);
  2439. end;
  2440. end;
  2441. function tstringdef.getmangledparaname : TSymStr;
  2442. begin
  2443. getmangledparaname:='STRING';
  2444. end;
  2445. function tstringdef.is_publishable : boolean;
  2446. begin
  2447. is_publishable:=true;
  2448. end;
  2449. function tstringdef.size: asizeint;
  2450. begin
  2451. case stringtype of
  2452. st_shortstring:
  2453. Result:=len+1;
  2454. st_longstring,
  2455. st_ansistring,
  2456. st_widestring,
  2457. st_unicodestring:
  2458. Result:=voidpointertype.size;
  2459. end;
  2460. end;
  2461. {****************************************************************************
  2462. TENUMDEF
  2463. ****************************************************************************}
  2464. constructor tenumdef.create;
  2465. begin
  2466. inherited create(enumdef,true);
  2467. minval:=0;
  2468. maxval:=0;
  2469. calcsavesize(current_settings.packenum);
  2470. has_jumps:=false;
  2471. basedef:=nil;
  2472. basedefderef.reset;
  2473. symtable:=tenumsymtable.create(self);
  2474. end;
  2475. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  2476. begin
  2477. inherited create(enumdef,true);
  2478. minval:=_min;
  2479. maxval:=_max;
  2480. basedef:=_basedef;
  2481. calcsavesize(current_settings.packenum);
  2482. has_jumps:=false;
  2483. symtable:=basedef.symtable.getcopy;
  2484. include(defoptions, df_copied_def);
  2485. end;
  2486. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  2487. begin
  2488. inherited ppuload(enumdef,ppufile);
  2489. minval:=ppufile.getaint;
  2490. maxval:=ppufile.getaint;
  2491. savesize:=ppufile.getaint;
  2492. has_jumps:=false;
  2493. if df_copied_def in defoptions then
  2494. begin
  2495. symtable:=nil;
  2496. ppufile.getderef(basedefderef);
  2497. ppuload_platform(ppufile);
  2498. end
  2499. else
  2500. begin
  2501. ppuload_platform(ppufile);
  2502. // create with nil defowner first to prevent values changes on insert
  2503. symtable:=tenumsymtable.create(nil);
  2504. tenumsymtable(symtable).ppuload(ppufile);
  2505. symtable.defowner:=self;
  2506. end;
  2507. end;
  2508. destructor tenumdef.destroy;
  2509. begin
  2510. symtable.free;
  2511. symtable:=nil;
  2512. inherited destroy;
  2513. end;
  2514. function tenumdef.getcopy : tstoreddef;
  2515. begin
  2516. if assigned(basedef) then
  2517. result:=cenumdef.create_subrange(basedef,minval,maxval)
  2518. else
  2519. begin
  2520. result:=cenumdef.create;
  2521. tenumdef(result).minval:=minval;
  2522. tenumdef(result).maxval:=maxval;
  2523. tenumdef(result).symtable.free;
  2524. tenumdef(result).symtable:=symtable.getcopy;
  2525. tenumdef(result).basedef:=self;
  2526. end;
  2527. tenumdef(result).has_jumps:=has_jumps;
  2528. tenumdef(result).basedefderef:=basedefderef;
  2529. include(tenumdef(result).defoptions,df_copied_def);
  2530. end;
  2531. procedure tenumdef.calcsavesize(packenum: shortint);
  2532. begin
  2533. {$IFNDEF cpu64bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2534. if (packenum=8) or (int64(min)<low(longint)) or (int64(max)>high(cardinal)) then
  2535. savesize:=8
  2536. {$IFNDEF cpu64bitaddr} {$pop} {$ENDIF}
  2537. else
  2538. {$IFDEF cpu16bitaddr} {$push}{$warnings off} {$ENDIF} //comparison always false warning
  2539. if (packenum=4) or (min<low(smallint)) or (max>high(word)) then
  2540. savesize:=4
  2541. {$IFDEF cpu16bitaddr} {$pop} {$ENDIF}
  2542. else
  2543. if (packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  2544. savesize:=2
  2545. else
  2546. savesize:=1;
  2547. end;
  2548. function tenumdef.packedbitsize: asizeint;
  2549. var
  2550. sizeval: tconstexprint;
  2551. power: longint;
  2552. begin
  2553. result := 0;
  2554. if (minval >= 0) and
  2555. (maxval <= 1) then
  2556. result := 1
  2557. else
  2558. begin
  2559. if (minval>=0) then
  2560. sizeval:=maxval
  2561. else
  2562. { don't count 0 twice, but take into account that range goes from -n-1..n }
  2563. sizeval:=(cutils.max(-minval,maxval+1)*2)-1;
  2564. { 256 must become 512 etc. }
  2565. nextpowerof2(sizeval+1,power);
  2566. result := power;
  2567. end;
  2568. end;
  2569. procedure tenumdef.setmax(_max:asizeint);
  2570. begin
  2571. maxval:=_max;
  2572. calcsavesize(current_settings.packenum);
  2573. end;
  2574. procedure tenumdef.setmin(_min:asizeint);
  2575. begin
  2576. minval:=_min;
  2577. calcsavesize(current_settings.packenum);
  2578. end;
  2579. function tenumdef.min:asizeint;
  2580. begin
  2581. min:=minval;
  2582. end;
  2583. function tenumdef.max:asizeint;
  2584. begin
  2585. max:=maxval;
  2586. end;
  2587. function tenumdef.getfirstsym: tsym;
  2588. var
  2589. i:integer;
  2590. begin
  2591. for i := 0 to symtable.SymList.Count - 1 do
  2592. begin
  2593. result:=tsym(symtable.SymList[i]);
  2594. if tenumsym(result).value=minval then
  2595. exit;
  2596. end;
  2597. result:=nil;
  2598. end;
  2599. function tenumdef.int2enumsym(l: asizeint): tsym;
  2600. var
  2601. i: longint;
  2602. sym: tsym;
  2603. bdef: tenumdef;
  2604. begin
  2605. result:=nil;
  2606. if (l<minval) or
  2607. (l>maxval) then
  2608. exit;
  2609. bdef:=getbasedef;
  2610. for i:=0 to bdef.symtable.symlist.count-1 do
  2611. begin
  2612. sym:=tsym(bdef.symtable.symlist[i]);
  2613. if (sym.typ=enumsym) and
  2614. (tenumsym(sym).value=l) then
  2615. begin
  2616. result:=sym;
  2617. exit;
  2618. end;
  2619. end;
  2620. end;
  2621. function tenumdef.getbasedef: tenumdef;
  2622. begin
  2623. if not assigned(basedef) then
  2624. result:=self
  2625. else
  2626. result:=basedef;
  2627. end;
  2628. procedure tenumdef.buildderef;
  2629. begin
  2630. inherited buildderef;
  2631. if df_copied_def in defoptions then
  2632. basedefderef.build(basedef)
  2633. else
  2634. tenumsymtable(symtable).buildderef;
  2635. end;
  2636. procedure tenumdef.deref;
  2637. begin
  2638. inherited deref;
  2639. if df_copied_def in defoptions then
  2640. begin
  2641. basedef:=tenumdef(basedefderef.resolve);
  2642. symtable:=basedef.symtable.getcopy;
  2643. end
  2644. else
  2645. tenumsymtable(symtable).deref(false);
  2646. end;
  2647. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  2648. begin
  2649. inherited ppuwrite(ppufile);
  2650. ppufile.putaint(min);
  2651. ppufile.putaint(max);
  2652. ppufile.putaint(savesize);
  2653. if df_copied_def in defoptions then
  2654. ppufile.putderef(basedefderef);
  2655. writeentry(ppufile,ibenumdef);
  2656. if not (df_copied_def in defoptions) then
  2657. tenumsymtable(symtable).ppuwrite(ppufile);
  2658. end;
  2659. function tenumdef.is_publishable : boolean;
  2660. begin
  2661. is_publishable:=true;
  2662. end;
  2663. function tenumdef.GetTypeName : string;
  2664. begin
  2665. GetTypeName:='<enumeration type>';
  2666. end;
  2667. {****************************************************************************
  2668. TRTTI_ATTRIBUTE_LIST
  2669. ****************************************************************************}
  2670. constructor trtti_attribute.ppuload(ppufile: tcompilerppufile);
  2671. begin
  2672. ppufile.getderef(typesymderef);
  2673. ppufile.getderef(typeconstrderef);
  2674. setlength(paras,ppufile.getlongint);
  2675. end;
  2676. procedure trtti_attribute.ppuwrite(ppufile: tcompilerppufile);
  2677. begin
  2678. ppufile.putderef(typesymderef);
  2679. ppufile.putderef(typeconstrderef);
  2680. ppufile.putlongint(length(paras));
  2681. end;
  2682. procedure trtti_attribute.ppuload_subentries(ppufile: tcompilerppufile);
  2683. var
  2684. i : sizeint;
  2685. begin
  2686. for i:=0 to high(paras) do
  2687. paras[i]:=ppuloadnodetree(ppufile);
  2688. end;
  2689. procedure trtti_attribute.ppuwrite_subentries(ppufile: tcompilerppufile);
  2690. var
  2691. i : sizeint;
  2692. begin
  2693. for i:=0 to high(paras) do
  2694. ppuwritenodetree(ppufile,paras[i]);
  2695. end;
  2696. destructor trtti_attribute.destroy;
  2697. var
  2698. n : tnode;
  2699. begin
  2700. constructorcall.free;
  2701. for n in paras do
  2702. n.free;
  2703. inherited destroy;
  2704. end;
  2705. procedure trtti_attribute.buildderef;
  2706. var
  2707. i : sizeint;
  2708. begin
  2709. typesymderef.build(typesym);
  2710. typeconstrderef.build(typeconstr);
  2711. for i:=0 to high(paras) do
  2712. paras[i].buildderefimpl;
  2713. end;
  2714. procedure trtti_attribute.deref;
  2715. var
  2716. i : sizeint;
  2717. begin
  2718. typesym:=tsym(typesymderef.resolve);
  2719. typeconstr:=tdef(typeconstrderef.resolve);
  2720. for i:=0 to high(paras) do
  2721. paras[i].derefimpl;
  2722. end;
  2723. class procedure trtti_attribute_list.bind(var dangling,owned:trtti_attribute_list);
  2724. begin
  2725. if assigned(owned) then
  2726. internalerror(2019071001);
  2727. if not assigned(dangling) then
  2728. exit;
  2729. if dangling.is_bound then
  2730. internalerror(2019071002);
  2731. current_module.used_rtti_attrs.concatlistcopy(dangling.rtti_attributes);
  2732. dangling.is_bound:=true;
  2733. owned:=dangling;
  2734. dangling:=nil;
  2735. end;
  2736. procedure trtti_attribute_list.addattribute(atypesym:tsym;typeconstr:tdef;constructorcall:tnode;constref paras:array of tnode);
  2737. var
  2738. newattribute : trtti_attribute;
  2739. i : sizeint;
  2740. begin
  2741. if not assigned(rtti_attributes) then
  2742. rtti_attributes:=TFPObjectList.Create(true);
  2743. newattribute:=trtti_attribute.Create;
  2744. newattribute.typesym:=atypesym;
  2745. newattribute.typeconstr:=typeconstr;
  2746. newattribute.constructorcall:=constructorcall;
  2747. setlength(newattribute.paras,length(paras));
  2748. for i:=0 to high(paras) do
  2749. newattribute.paras[i]:=paras[i];
  2750. rtti_attributes.Add(newattribute);
  2751. end;
  2752. procedure trtti_attribute_list.addattribute(attr:trtti_attribute);
  2753. begin
  2754. if not assigned(rtti_attributes) then
  2755. rtti_attributes:=TFPObjectList.Create(true);
  2756. rtti_attributes.add(attr);
  2757. end;
  2758. destructor trtti_attribute_list.destroy;
  2759. begin
  2760. rtti_attributes.Free;
  2761. inherited destroy;
  2762. end;
  2763. function trtti_attribute_list.get_attribute_count:longint;
  2764. begin
  2765. if assigned(rtti_attributes) then
  2766. result:=rtti_attributes.Count
  2767. else
  2768. result:=0;
  2769. end;
  2770. procedure trtti_attribute_list.buildderef;
  2771. var
  2772. i : sizeint;
  2773. begin
  2774. if not assigned(rtti_attributes) then
  2775. exit;
  2776. for i:=0 to rtti_attributes.count-1 do
  2777. trtti_attribute(rtti_attributes[i]).buildderef;
  2778. end;
  2779. procedure trtti_attribute_list.deref;
  2780. var
  2781. i : sizeint;
  2782. begin
  2783. if not assigned(rtti_attributes) then
  2784. exit;
  2785. for i:=0 to rtti_attributes.count-1 do
  2786. trtti_attribute(rtti_attributes[i]).deref;
  2787. end;
  2788. class procedure trtti_attribute_list.ppuload_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  2789. var
  2790. i : sizeint;
  2791. begin
  2792. if assigned(attrlist) then
  2793. begin
  2794. if not assigned(attrlist.rtti_attributes) then
  2795. internalerror(2019071101);
  2796. for i:=0 to attrlist.rtti_attributes.count-1 do
  2797. trtti_attribute(attrlist.rtti_attributes[i]).ppuload_subentries(ppufile);
  2798. end;
  2799. end;
  2800. class procedure trtti_attribute_list.ppuwrite_subentries(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  2801. var
  2802. i : sizeint;
  2803. begin
  2804. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  2805. begin
  2806. for i:=0 to attrlist.rtti_attributes.count-1 do
  2807. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite_subentries(ppufile);
  2808. end;
  2809. end;
  2810. class function trtti_attribute_list.ppuload(ppufile:tcompilerppufile):trtti_attribute_list;
  2811. var
  2812. cnt,i : longint;
  2813. begin
  2814. cnt:=ppufile.getlongint;
  2815. if cnt>0 then
  2816. begin
  2817. result:=trtti_attribute_list.create;
  2818. for i:=0 to cnt-1 do
  2819. result.addattribute(trtti_attribute.ppuload(ppufile));
  2820. end
  2821. else
  2822. result:=nil;
  2823. end;
  2824. class procedure trtti_attribute_list.ppuwrite(attrlist:trtti_attribute_list;ppufile:tcompilerppufile);
  2825. var
  2826. i : longint;
  2827. begin
  2828. if assigned(attrlist) and assigned(attrlist.rtti_attributes) then
  2829. begin
  2830. ppufile.putlongint(attrlist.rtti_attributes.count);
  2831. for i:=0 to attrlist.rtti_attributes.count-1 do
  2832. trtti_attribute(attrlist.rtti_attributes[i]).ppuwrite(ppufile);
  2833. end
  2834. else
  2835. ppufile.putlongint(0);
  2836. end;
  2837. {****************************************************************************
  2838. TORDDEF
  2839. ****************************************************************************}
  2840. constructor torddef.create(t : tordtype;v,b : TConstExprInt; doregister: boolean);
  2841. begin
  2842. inherited create(orddef,doregister);
  2843. low:=v;
  2844. high:=b;
  2845. ordtype:=t;
  2846. setsize;
  2847. end;
  2848. constructor torddef.ppuload(ppufile:tcompilerppufile);
  2849. begin
  2850. inherited ppuload(orddef,ppufile);
  2851. ordtype:=tordtype(ppufile.getbyte);
  2852. low:=ppufile.getexprint;
  2853. high:=ppufile.getexprint;
  2854. setsize;
  2855. ppuload_platform(ppufile);
  2856. end;
  2857. function torddef.getcopy : tstoreddef;
  2858. begin
  2859. result:=corddef.create(ordtype,low,high,true);
  2860. result.typ:=orddef;
  2861. torddef(result).low:=low;
  2862. torddef(result).high:=high;
  2863. torddef(result).ordtype:=ordtype;
  2864. torddef(result).savesize:=savesize;
  2865. end;
  2866. function torddef.alignment:shortint;
  2867. begin
  2868. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) and
  2869. (ordtype in [s64bit,u64bit]) then
  2870. result := 4
  2871. else
  2872. result := inherited alignment;
  2873. end;
  2874. procedure torddef.setsize;
  2875. const
  2876. sizetbl : array[tordtype] of longint = (
  2877. 0,
  2878. 1,2,4,8,16,
  2879. 1,2,4,8,16,
  2880. 1,1,2,4,8,
  2881. 1,2,4,8,
  2882. 1,2,8,system.high(longint)
  2883. );
  2884. begin
  2885. savesize:=sizetbl[ordtype];
  2886. if savesize=system.high(longint) then
  2887. savesize:=packedbitsize div 8;
  2888. end;
  2889. function torddef.packedbitsize: asizeint;
  2890. var
  2891. sizeval: tconstexprint;
  2892. power: longint;
  2893. begin
  2894. result := 0;
  2895. if ordtype = uvoid then
  2896. exit;
  2897. {$ifndef cpu64bitalu}
  2898. if (ordtype in [s64bit,u64bit]) then
  2899. {$else not cpu64bitalu}
  2900. if (ordtype = u64bit) or
  2901. ((ordtype = s64bit) and
  2902. ((low <= (system.low(int64) div 2)) or
  2903. (high > (system.high(int64) div 2)))) then
  2904. {$endif cpu64bitalu}
  2905. result := 64
  2906. else if (
  2907. (low >= 0) and
  2908. (high <= 1)
  2909. ) or (
  2910. ordtype in [pasbool1,pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]
  2911. ) then
  2912. result := 1
  2913. else
  2914. begin
  2915. if (low>=0) then
  2916. sizeval:=high
  2917. else
  2918. { don't count 0 twice, but take into account that range goes from -n-1..n }
  2919. sizeval:=(cutils.max(-low,high+1)*2)-1;
  2920. { 256 must become 512 etc. }
  2921. nextpowerof2(sizeval+1,power);
  2922. result := power;
  2923. end;
  2924. end;
  2925. function torddef.getvardef : longint;
  2926. const
  2927. basetype2vardef : array[tordtype] of longint = (
  2928. varUndefined,
  2929. varbyte,varword,varlongword,varqword,varUndefined,
  2930. varshortint,varsmallint,varinteger,varint64,varUndefined,
  2931. varboolean,varboolean,varboolean,varboolean,varboolean,
  2932. varboolean,varboolean,varUndefined,varUndefined,
  2933. varUndefined,varUndefined,varCurrency,varEmpty);
  2934. begin
  2935. result:=basetype2vardef[ordtype];
  2936. if result=varEmpty then
  2937. result:=basetype2vardef[range_to_basetype(low,high)];
  2938. end;
  2939. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  2940. begin
  2941. inherited ppuwrite(ppufile);
  2942. ppufile.putbyte(byte(ordtype));
  2943. ppufile.putexprint(low);
  2944. ppufile.putexprint(high);
  2945. writeentry(ppufile,iborddef);
  2946. end;
  2947. function torddef.is_publishable : boolean;
  2948. begin
  2949. is_publishable:=(ordtype<>uvoid);
  2950. end;
  2951. function torddef.GetTypeName : string;
  2952. const
  2953. names : array[tordtype] of string[20] = (
  2954. 'untyped',
  2955. 'Byte','Word','DWord','QWord','UInt128',
  2956. 'ShortInt','SmallInt','LongInt','Int64','Int128',
  2957. 'Boolean','Boolean8','Boolean16','Boolean32','Boolean64',
  2958. 'ByteBool','WordBool','LongBool','QWordBool',
  2959. 'Char','WideChar','Currency','CustomRange');
  2960. begin
  2961. GetTypeName:=names[ordtype];
  2962. end;
  2963. {****************************************************************************
  2964. TFLOATDEF
  2965. ****************************************************************************}
  2966. constructor tfloatdef.create(t: tfloattype; doregister: boolean);
  2967. begin
  2968. inherited create(floatdef,doregister);
  2969. floattype:=t;
  2970. setsize;
  2971. end;
  2972. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  2973. begin
  2974. inherited ppuload(floatdef,ppufile);
  2975. floattype:=tfloattype(ppufile.getbyte);
  2976. setsize;
  2977. ppuload_platform(ppufile);
  2978. end;
  2979. function tfloatdef.getcopy : tstoreddef;
  2980. begin
  2981. result:=cfloatdef.create(floattype,true);
  2982. result.typ:=floatdef;
  2983. tfloatdef(result).savesize:=savesize;
  2984. end;
  2985. function tfloatdef.alignment:shortint;
  2986. begin
  2987. if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) then
  2988. case floattype of
  2989. sc80real,
  2990. s80real: result:=16;
  2991. s64real,
  2992. s64currency,
  2993. s64comp : result:=4;
  2994. else
  2995. result := inherited alignment;
  2996. end
  2997. else
  2998. result := inherited alignment;
  2999. end;
  3000. function tfloatdef.structalignment: shortint;
  3001. begin
  3002. { aix is really annoying: the recommended scalar alignment for both
  3003. int64 and double is 64 bits, but in structs int64 has to be aligned
  3004. to 8 bytes and double to 4 bytes }
  3005. if (target_info.system in systems_aix) and
  3006. (floattype=s64real) then
  3007. result:=4
  3008. else
  3009. result:=alignment;
  3010. end;
  3011. procedure tfloatdef.setsize;
  3012. begin
  3013. case floattype of
  3014. s32real : savesize:=4;
  3015. s80real : savesize:=10;
  3016. sc80real:
  3017. if target_info.system in [system_i386_darwin,
  3018. system_i386_iphonesim,system_x86_64_darwin,
  3019. system_x86_64_iphonesim,
  3020. system_x86_64_linux,system_x86_64_freebsd,
  3021. system_x86_64_openbsd,system_x86_64_netbsd,
  3022. system_x86_64_solaris,system_x86_64_embedded,
  3023. system_x86_64_dragonfly,system_x86_64_haiku] then
  3024. savesize:=16
  3025. else
  3026. savesize:=12;
  3027. s64real,
  3028. s64currency,
  3029. s64comp : savesize:=8;
  3030. else
  3031. savesize:=0;
  3032. end;
  3033. end;
  3034. function tfloatdef.getvardef : longint;
  3035. const
  3036. floattype2vardef : array[tfloattype] of longint = (
  3037. varSingle,varDouble,varUndefined,varUndefined,
  3038. varUndefined,varCurrency,varUndefined);
  3039. begin
  3040. if (upper(typename)='TDATETIME') and
  3041. assigned(owner) and
  3042. assigned(owner.name) and
  3043. (owner.name^='SYSTEM') then
  3044. result:=varDate
  3045. else
  3046. result:=floattype2vardef[floattype];
  3047. end;
  3048. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  3049. begin
  3050. inherited ppuwrite(ppufile);
  3051. ppufile.putbyte(byte(floattype));
  3052. writeentry(ppufile,ibfloatdef);
  3053. end;
  3054. function tfloatdef.is_publishable : boolean;
  3055. begin
  3056. is_publishable:=true;
  3057. end;
  3058. function tfloatdef.GetTypeName : string;
  3059. const
  3060. names : array[tfloattype] of string[20] = (
  3061. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  3062. begin
  3063. GetTypeName:=names[floattype];
  3064. end;
  3065. {****************************************************************************
  3066. TFILEDEF
  3067. ****************************************************************************}
  3068. constructor tfiledef.createtext;
  3069. begin
  3070. inherited create(filedef,true);
  3071. filetyp:=ft_text;
  3072. typedfiledef:=nil;
  3073. typedfiledefderef.reset;
  3074. end;
  3075. constructor tfiledef.createuntyped;
  3076. begin
  3077. inherited create(filedef,true);
  3078. filetyp:=ft_untyped;
  3079. typedfiledef:=nil;
  3080. end;
  3081. constructor tfiledef.createtyped(def:tdef);
  3082. begin
  3083. inherited create(filedef,true);
  3084. filetyp:=ft_typed;
  3085. typedfiledef:=def;
  3086. end;
  3087. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  3088. begin
  3089. inherited ppuload(filedef,ppufile);
  3090. filetyp:=tfiletyp(ppufile.getbyte);
  3091. if filetyp=ft_typed then
  3092. ppufile.getderef(typedfiledefderef)
  3093. else
  3094. typedfiledef:=nil;
  3095. ppuload_platform(ppufile);
  3096. end;
  3097. function tfiledef.getcopy : tstoreddef;
  3098. begin
  3099. case filetyp of
  3100. ft_typed:
  3101. result:=cfiledef.createtyped(typedfiledef);
  3102. ft_untyped:
  3103. result:=cfiledef.createuntyped;
  3104. ft_text:
  3105. result:=cfiledef.createtext;
  3106. end;
  3107. end;
  3108. procedure tfiledef.buildderef;
  3109. begin
  3110. inherited buildderef;
  3111. if filetyp=ft_typed then
  3112. typedfiledefderef.build(typedfiledef);
  3113. end;
  3114. procedure tfiledef.deref;
  3115. begin
  3116. inherited deref;
  3117. if filetyp=ft_typed then
  3118. typedfiledef:=tdef(typedfiledefderef.resolve);
  3119. end;
  3120. function tfiledef.size:asizeint;
  3121. begin
  3122. if savesize=0 then
  3123. setsize;
  3124. size:=savesize;
  3125. end;
  3126. procedure tfiledef.setsize;
  3127. begin
  3128. case filetyp of
  3129. ft_text:
  3130. savesize:=search_system_type('TEXTREC').typedef.size;
  3131. ft_typed:
  3132. begin
  3133. savesize:=search_system_type('FILEREC').typedef.size;
  3134. { allocate put/get buffer in iso mode }
  3135. if m_isolike_io in current_settings.modeswitches then
  3136. inc(savesize,typedfiledef.size);
  3137. end;
  3138. ft_untyped:
  3139. savesize:=search_system_type('FILEREC').typedef.size;
  3140. end;
  3141. end;
  3142. function tfiledef.alignment: shortint;
  3143. begin
  3144. case filetyp of
  3145. ft_text:
  3146. result:=search_system_type('TEXTREC').typedef.alignment;
  3147. ft_typed,
  3148. ft_untyped:
  3149. result:=search_system_type('FILEREC').typedef.alignment;
  3150. end;
  3151. end;
  3152. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  3153. begin
  3154. inherited ppuwrite(ppufile);
  3155. ppufile.putbyte(byte(filetyp));
  3156. if filetyp=ft_typed then
  3157. ppufile.putderef(typedfiledefderef);
  3158. writeentry(ppufile,ibfiledef);
  3159. end;
  3160. function tfiledef.GetTypeName : string;
  3161. begin
  3162. case filetyp of
  3163. ft_untyped:
  3164. GetTypeName:='File';
  3165. ft_typed:
  3166. GetTypeName:='File Of '+typedfiledef.typename;
  3167. ft_text:
  3168. GetTypeName:='Text'
  3169. end;
  3170. end;
  3171. function tfiledef.getmangledparaname : TSymStr;
  3172. begin
  3173. case filetyp of
  3174. ft_untyped:
  3175. getmangledparaname:='FILE';
  3176. ft_typed:
  3177. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  3178. ft_text:
  3179. getmangledparaname:='TEXT'
  3180. end;
  3181. end;
  3182. {****************************************************************************
  3183. TVARIANTDEF
  3184. ****************************************************************************}
  3185. constructor tvariantdef.create(v : tvarianttype);
  3186. begin
  3187. inherited create(variantdef,true);
  3188. varianttype:=v;
  3189. setsize;
  3190. end;
  3191. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  3192. begin
  3193. inherited ppuload(variantdef,ppufile);
  3194. varianttype:=tvarianttype(ppufile.getbyte);
  3195. setsize;
  3196. ppuload_platform(ppufile);
  3197. end;
  3198. function tvariantdef.getcopy : tstoreddef;
  3199. begin
  3200. result:=cvariantdef.create(varianttype);
  3201. end;
  3202. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  3203. begin
  3204. inherited ppuwrite(ppufile);
  3205. ppufile.putbyte(byte(varianttype));
  3206. writeentry(ppufile,ibvariantdef);
  3207. end;
  3208. function tvariantdef.getvardef : longint;
  3209. begin
  3210. Result:=varVariant;
  3211. end;
  3212. procedure tvariantdef.setsize;
  3213. begin
  3214. {$ifdef cpu64bitaddr}
  3215. savesize:=24;
  3216. {$else cpu64bitaddr}
  3217. savesize:=16;
  3218. {$endif cpu64bitaddr}
  3219. end;
  3220. function tvariantdef.GetTypeName : string;
  3221. begin
  3222. case varianttype of
  3223. vt_normalvariant:
  3224. GetTypeName:='Variant';
  3225. vt_olevariant:
  3226. GetTypeName:='OleVariant';
  3227. end;
  3228. end;
  3229. function tvariantdef.needs_inittable : boolean;
  3230. begin
  3231. needs_inittable:=true;
  3232. end;
  3233. function tvariantdef.is_publishable : boolean;
  3234. begin
  3235. is_publishable:=true;
  3236. end;
  3237. {****************************************************************************
  3238. TABSTRACtpointerdef
  3239. ****************************************************************************}
  3240. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  3241. begin
  3242. inherited create(dt,true);
  3243. pointeddef:=def;
  3244. pointeddefderef.reset;
  3245. if df_generic in pointeddef.defoptions then
  3246. include(defoptions,df_generic);
  3247. if df_specialization in pointeddef.defoptions then
  3248. include(defoptions,df_specialization);
  3249. end;
  3250. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3251. begin
  3252. inherited ppuload(dt,ppufile);
  3253. ppufile.getderef(pointeddefderef);
  3254. end;
  3255. procedure tabstractpointerdef.buildderef;
  3256. begin
  3257. inherited buildderef;
  3258. pointeddefderef.build(pointeddef);
  3259. end;
  3260. procedure tabstractpointerdef.deref;
  3261. begin
  3262. inherited deref;
  3263. pointeddef:=tdef(pointeddefderef.resolve);
  3264. end;
  3265. function tabstractpointerdef.size: asizeint;
  3266. begin
  3267. Result:=voidpointertype.size;
  3268. end;
  3269. function tabstractpointerdef.alignment: shortint;
  3270. begin
  3271. alignment:=size_2_align(voidpointertype.size);
  3272. end;
  3273. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3274. begin
  3275. inherited ppuwrite(ppufile);
  3276. ppufile.putderef(pointeddefderef);
  3277. end;
  3278. {****************************************************************************
  3279. tpointerdef
  3280. ****************************************************************************}
  3281. constructor tpointerdef.create(def:tdef);
  3282. begin
  3283. inherited create(pointerdef,def);
  3284. has_pointer_math:=cs_pointermath in current_settings.localswitches;
  3285. if (df_specialization in tstoreddef(def).defoptions)
  3286. {$ifndef genericdef_for_nested}
  3287. { currently, nested procdefs of generic routines get df_specialisation,
  3288. but no genericdef }
  3289. and assigned(tstoreddef(def).genericdef)
  3290. {$endif}
  3291. then
  3292. genericdef:=cpointerdef.getreusable(tstoreddef(def).genericdef);
  3293. end;
  3294. class function tpointerdef.getreusable(def: tdef): tpointerdef;
  3295. var
  3296. res: PHashSetItem;
  3297. oldsymtablestack: tsymtablestack;
  3298. begin
  3299. if not assigned(current_module) then
  3300. internalerror(2011071101);
  3301. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  3302. if not assigned(res^.Data) then
  3303. begin
  3304. { since these pointerdefs can be reused anywhere in the current
  3305. unit, add them to the global/staticsymtable (or local symtable
  3306. if they're a local def, because otherwise they'll be saved
  3307. to the ppu referencing a local symtable entry that doesn't
  3308. exist in the ppu) }
  3309. oldsymtablestack:=symtablestack;
  3310. { do not simply push/pop current_module.localsymtable, because
  3311. that can have side-effects (e.g., it removes helpers) }
  3312. symtablestack:=nil;
  3313. result:=cpointerdef.create(def);
  3314. setup_reusable_def(def,result,res,oldsymtablestack);
  3315. { res^.Data may still be nil -> don't overwrite result }
  3316. exit;
  3317. end;
  3318. result:=tpointerdef(res^.Data);
  3319. end;
  3320. class function tpointerdef.getreusable_no_free(def: tdef): tpointerdef;
  3321. begin
  3322. result:=getreusable(def);
  3323. if not result.is_registered then
  3324. include(result.defoptions,df_not_registered_no_free);
  3325. end;
  3326. function tpointerdef.size: asizeint;
  3327. begin
  3328. result:=sizeof(pint);
  3329. end;
  3330. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  3331. begin
  3332. inherited ppuload(pointerdef,ppufile);
  3333. has_pointer_math:=(ppufile.getbyte<>0);
  3334. ppuload_platform(ppufile);
  3335. end;
  3336. function tpointerdef.getcopy : tstoreddef;
  3337. begin
  3338. { don't use direct pointeddef if it is a forwarddef because in other case
  3339. one of them will be destroyed on forward type resolve and the second will
  3340. point to garbage }
  3341. if pointeddef.typ=forwarddef then
  3342. result:=cpointerdef.create(tforwarddef(pointeddef).getcopy)
  3343. else
  3344. result:=cpointerdef.create(pointeddef);
  3345. tpointerdef(result).has_pointer_math:=has_pointer_math;
  3346. tpointerdef(result).savesize:=savesize;
  3347. end;
  3348. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  3349. begin
  3350. inherited ppuwrite(ppufile);
  3351. ppufile.putbyte(byte(has_pointer_math));
  3352. writeentry(ppufile,ibpointerdef);
  3353. end;
  3354. function tpointerdef.GetTypeName : string;
  3355. begin
  3356. { parameter types and the resultdef of a procvardef can contain a
  3357. pointer to this procvardef itself, resulting in endless recursion ->
  3358. use the typesym's name instead if it exists (if it doesn't, such as
  3359. for anynonymous procedure types in macpas/iso mode, then there cannot
  3360. be any recursive references to it either) }
  3361. if (pointeddef.typ<>procvardef) or
  3362. not assigned(pointeddef.typesym) then
  3363. GetTypeName:='^'+pointeddef.typename
  3364. else
  3365. GetTypeName:='^'+pointeddef.typesym.realname;
  3366. end;
  3367. function tpointerdef.pointer_arithmetic_int_type:tdef;
  3368. begin
  3369. result:=ptrsinttype;
  3370. end;
  3371. function tpointerdef.pointer_arithmetic_uint_type:tdef;
  3372. begin
  3373. result:=ptruinttype;
  3374. end;
  3375. function tpointerdef.pointer_subtraction_result_type:tdef;
  3376. begin
  3377. result:=ptrsinttype;
  3378. end;
  3379. function tpointerdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  3380. begin
  3381. result:=true;
  3382. end;
  3383. function tpointerdef.converted_pointer_to_array_range_type:tdef;
  3384. begin
  3385. result:=ptrsinttype;
  3386. end;
  3387. {****************************************************************************
  3388. TCLASSREFDEF
  3389. ****************************************************************************}
  3390. constructor tclassrefdef.create(def:tdef);
  3391. begin
  3392. inherited create(classrefdef,def);
  3393. if df_specialization in tstoreddef(def).defoptions then
  3394. genericdef:=cclassrefdef.create(tstoreddef(def).genericdef);
  3395. end;
  3396. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  3397. begin
  3398. inherited ppuload(classrefdef,ppufile);
  3399. ppuload_platform(ppufile);
  3400. end;
  3401. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  3402. begin
  3403. inherited ppuwrite(ppufile);
  3404. writeentry(ppufile,ibclassrefdef);
  3405. end;
  3406. function tclassrefdef.getcopy:tstoreddef;
  3407. begin
  3408. if pointeddef.typ=forwarddef then
  3409. result:=cclassrefdef.create(tforwarddef(pointeddef).getcopy)
  3410. else
  3411. result:=cclassrefdef.create(pointeddef);
  3412. end;
  3413. function tclassrefdef.GetTypeName : string;
  3414. begin
  3415. GetTypeName:='Class Of '+pointeddef.typename;
  3416. end;
  3417. function tclassrefdef.is_publishable : boolean;
  3418. begin
  3419. result:=true;
  3420. end;
  3421. function tclassrefdef.rtti_mangledname(rt: trttitype): TSymStr;
  3422. begin
  3423. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  3424. result:=inherited rtti_mangledname(rt)
  3425. else
  3426. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  3427. end;
  3428. procedure tclassrefdef.register_created_object_type;
  3429. begin
  3430. tobjectdef(pointeddef).register_created_classref_type;
  3431. end;
  3432. {***************************************************************************
  3433. TSETDEF
  3434. ***************************************************************************}
  3435. constructor tsetdef.create(def: tdef; low, high: asizeint; doregister: boolean);
  3436. var
  3437. setallocbits: aint;
  3438. packedsavesize: aint;
  3439. actual_setalloc: ShortInt;
  3440. begin
  3441. inherited create(setdef,doregister);
  3442. elementdef:=def;
  3443. elementdefderef.reset;
  3444. setmax:=high;
  3445. actual_setalloc:=current_settings.setalloc;
  3446. {$if defined(cpu8bitalu) or defined(cpu16bitalu)}
  3447. if actual_setalloc=0 then
  3448. actual_setalloc:=1;
  3449. {$endif}
  3450. if (actual_setalloc=0) then
  3451. begin
  3452. setbase:=0;
  3453. if (high<32) then
  3454. savesize:=Sizeof(longint)
  3455. else if (high<256) then
  3456. savesize:=32
  3457. else
  3458. savesize:=(high+7) div 8
  3459. end
  3460. else
  3461. begin
  3462. setallocbits:=actual_setalloc*8;
  3463. setbase:=low and not(setallocbits-1);
  3464. packedsavesize:=actual_setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  3465. savesize:=packedsavesize;
  3466. {$if not defined(cpu8bitalu) and not defined(cpu16bitalu)}
  3467. if savesize=3 then
  3468. savesize:=4;
  3469. {$endif}
  3470. end;
  3471. end;
  3472. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  3473. begin
  3474. inherited ppuload(setdef,ppufile);
  3475. ppufile.getderef(elementdefderef);
  3476. savesize:=ppufile.getasizeint;
  3477. setbase:=ppufile.getasizeint;
  3478. setmax:=ppufile.getasizeint;
  3479. ppuload_platform(ppufile);
  3480. end;
  3481. function tsetdef.getcopy : tstoreddef;
  3482. begin
  3483. result:=csetdef.create(elementdef,setbase,setmax,true);
  3484. { the copy might have been created with a different setalloc setting }
  3485. tsetdef(result).savesize:=savesize;
  3486. end;
  3487. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  3488. begin
  3489. inherited ppuwrite(ppufile);
  3490. ppufile.putderef(elementdefderef);
  3491. ppufile.putasizeint(savesize);
  3492. ppufile.putasizeint(setbase);
  3493. ppufile.putasizeint(setmax);
  3494. writeentry(ppufile,ibsetdef);
  3495. end;
  3496. procedure tsetdef.buildderef;
  3497. begin
  3498. inherited buildderef;
  3499. elementdefderef.build(elementdef);
  3500. end;
  3501. procedure tsetdef.deref;
  3502. begin
  3503. inherited deref;
  3504. elementdef:=tdef(elementdefderef.resolve);
  3505. end;
  3506. function tsetdef.is_publishable : boolean;
  3507. begin
  3508. is_publishable:=savesize in [1,2,4];
  3509. end;
  3510. function tsetdef.alignment: shortint;
  3511. begin
  3512. Result:=inherited;
  3513. if result>sizeof(aint) then
  3514. result:=sizeof(aint);
  3515. end;
  3516. function tsetdef.GetTypeName : string;
  3517. begin
  3518. if assigned(elementdef) then
  3519. GetTypeName:='Set Of '+elementdef.typename
  3520. else
  3521. GetTypeName:='Empty Set';
  3522. end;
  3523. {***************************************************************************
  3524. TFORMALDEF
  3525. ***************************************************************************}
  3526. constructor tformaldef.create(Atyped:boolean);
  3527. begin
  3528. inherited create(formaldef,true);
  3529. typed:=Atyped;
  3530. savesize:=0;
  3531. end;
  3532. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  3533. begin
  3534. inherited ppuload(formaldef,ppufile);
  3535. typed:=boolean(ppufile.getbyte);
  3536. savesize:=0;
  3537. ppuload_platform(ppufile);
  3538. end;
  3539. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  3540. begin
  3541. inherited ppuwrite(ppufile);
  3542. ppufile.putbyte(byte(typed));
  3543. writeentry(ppufile,ibformaldef);
  3544. end;
  3545. function tformaldef.GetTypeName : string;
  3546. begin
  3547. if typed then
  3548. GetTypeName:='<Typed formal type>'
  3549. else
  3550. GetTypeName:='<Formal type>';
  3551. end;
  3552. {***************************************************************************
  3553. TARRAYDEF
  3554. ***************************************************************************}
  3555. constructor tarraydef.create(l, h: asizeint; def: tdef);
  3556. begin
  3557. inherited create(arraydef,true);
  3558. lowrange:=l;
  3559. highrange:=h;
  3560. rangedef:=def;
  3561. rangedefderef.reset;
  3562. _elementdef:=nil;
  3563. _elementdefderef.reset;
  3564. arrayoptions:=[];
  3565. symtable:=tarraysymtable.create(self);
  3566. end;
  3567. constructor tarraydef.create_vector(l ,h: asizeint; def: tdef);
  3568. begin
  3569. self.create(l,h,def);
  3570. include(arrayoptions,ado_IsVector);
  3571. end;
  3572. constructor tarraydef.create_openarray;
  3573. begin
  3574. self.create(0,-1,sizesinttype)
  3575. end;
  3576. class function tarraydef.getreusable_intern(def: tdef; elems: asizeint; const options: tarraydefoptions): tarraydef;
  3577. var
  3578. res: PHashSetItem;
  3579. oldsymtablestack: tsymtablestack;
  3580. arrdesc: packed record
  3581. def: tdef;
  3582. elecount: asizeint;
  3583. options: tarraydefoptions
  3584. end;
  3585. begin
  3586. if not assigned(current_module) then
  3587. internalerror(2011081301);
  3588. arrdesc.def:=def;
  3589. arrdesc.elecount:=elems;
  3590. arrdesc.options:=options;
  3591. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  3592. if not assigned(res^.Data) then
  3593. begin
  3594. { since these pointerdefs can be reused anywhere in the current
  3595. unit, add them to the global/staticsymtable (or local symtable
  3596. if they're a local def, because otherwise they'll be saved
  3597. to the ppu referencing a local symtable entry that doesn't
  3598. exist in the ppu) }
  3599. oldsymtablestack:=symtablestack;
  3600. { do not simply push/pop current_module.localsymtable, because
  3601. that can have side-effects (e.g., it removes helpers) }
  3602. symtablestack:=nil;
  3603. result:=carraydef.create(0,elems-1,sizesinttype);
  3604. result.elementdef:=def;
  3605. result.arrayoptions:=options;
  3606. setup_reusable_def(def,result,res,oldsymtablestack);
  3607. { res^.Data may still be nil -> don't overwrite result }
  3608. exit;
  3609. end;
  3610. result:=tarraydef(res^.Data);
  3611. end;
  3612. class function tarraydef.getreusable(def: tdef; elems: asizeint): tarraydef;
  3613. begin
  3614. result:=getreusable_intern(def,elems,[]);
  3615. end;
  3616. class function tarraydef.getreusable_vector(def: tdef; elems: asizeint): tarraydef;
  3617. begin
  3618. result:=getreusable_intern(def,elems,[ado_IsVector]);
  3619. end;
  3620. class function tarraydef.getreusable_no_free(def: tdef; elems: asizeint): tarraydef;
  3621. begin
  3622. result:=getreusable(def,elems);
  3623. if not result.is_registered then
  3624. include(result.defoptions,df_not_registered_no_free);
  3625. end;
  3626. class function tarraydef.getreusable_no_free_vector(def: tdef; elems: asizeint): tarraydef;
  3627. begin
  3628. result:=getreusable_vector(def,elems);
  3629. if not result.is_registered then
  3630. include(result.defoptions,df_not_registered_no_free);
  3631. end;
  3632. destructor tarraydef.destroy;
  3633. begin
  3634. symtable.free;
  3635. symtable:=nil;
  3636. inherited;
  3637. end;
  3638. constructor tarraydef.create_from_pointer(def:tpointerdef);
  3639. begin
  3640. { divide by the element size and do -1 so the array will have a valid size,
  3641. further, the element size might be 0 e.g. for empty records, so use max(...,1)
  3642. to avoid a division by zero }
  3643. self.create(0,(high(asizeint) div max(def.pointeddef.size,1))-1,
  3644. def.converted_pointer_to_array_range_type);
  3645. arrayoptions:=[ado_IsConvertedPointer];
  3646. setelementdef(def.pointeddef);
  3647. end;
  3648. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  3649. begin
  3650. inherited ppuload(arraydef,ppufile);
  3651. { the addresses are calculated later }
  3652. ppufile.getderef(_elementdefderef);
  3653. ppufile.getderef(rangedefderef);
  3654. lowrange:=ppufile.getasizeint;
  3655. highrange:=ppufile.getasizeint;
  3656. ppufile.getset(tppuset1(arrayoptions));
  3657. ppuload_platform(ppufile);
  3658. symtable:=tarraysymtable.create(self);
  3659. tarraysymtable(symtable).ppuload(ppufile)
  3660. end;
  3661. function tarraydef.getcopy : tstoreddef;
  3662. begin
  3663. result:=carraydef.create(lowrange,highrange,rangedef);
  3664. tarraydef(result).arrayoptions:=arrayoptions;
  3665. tarraydef(result)._elementdef:=_elementdef;
  3666. end;
  3667. procedure tarraydef.buildderef;
  3668. begin
  3669. inherited buildderef;
  3670. tarraysymtable(symtable).buildderef;
  3671. _elementdefderef.build(_elementdef);
  3672. rangedefderef.build(rangedef);
  3673. end;
  3674. procedure tarraydef.deref;
  3675. begin
  3676. inherited deref;
  3677. tarraysymtable(symtable).deref(false);
  3678. _elementdef:=tdef(_elementdefderef.resolve);
  3679. rangedef:=tdef(rangedefderef.resolve);
  3680. end;
  3681. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  3682. begin
  3683. inherited ppuwrite(ppufile);
  3684. ppufile.putderef(_elementdefderef);
  3685. ppufile.putderef(rangedefderef);
  3686. ppufile.putasizeint(lowrange);
  3687. ppufile.putasizeint(highrange);
  3688. ppufile.putset(tppuset1(arrayoptions));
  3689. writeentry(ppufile,ibarraydef);
  3690. tarraysymtable(symtable).ppuwrite(ppufile);
  3691. end;
  3692. function tarraydef.elesize : asizeint;
  3693. begin
  3694. if (ado_IsBitPacked in arrayoptions) then
  3695. internalerror(2006080101);
  3696. if assigned(_elementdef) then
  3697. result:=_elementdef.size
  3698. else
  3699. result:=0;
  3700. end;
  3701. function tarraydef.elepackedbitsize : asizeint;
  3702. begin
  3703. if not(ado_IsBitPacked in arrayoptions) then
  3704. internalerror(2006080102);
  3705. if assigned(_elementdef) then
  3706. result:=_elementdef.packedbitsize
  3707. else
  3708. result:=0;
  3709. end;
  3710. function tarraydef.elecount : asizeuint;
  3711. var
  3712. qhigh,qlow : qword;
  3713. begin
  3714. if ado_IsDynamicArray in arrayoptions then
  3715. begin
  3716. result:=0;
  3717. exit;
  3718. end;
  3719. if (highrange>0) and (lowrange<0) then
  3720. begin
  3721. qhigh:=highrange;
  3722. if lowrange=low(asizeint) then
  3723. qlow:=high(asizeint) + 1
  3724. else
  3725. qlow:=qword(-lowrange);
  3726. { prevent overflow, return 0 to indicate overflow }
  3727. if qhigh+qlow>qword(high(asizeint)-1) then
  3728. result:=0
  3729. else
  3730. result:=qhigh+qlow+1;
  3731. end
  3732. else
  3733. result:=int64(highrange)-lowrange+1;
  3734. end;
  3735. function tarraydef.size : asizeint;
  3736. var
  3737. cachedelecount : asizeuint;
  3738. cachedelesize : asizeint;
  3739. begin
  3740. if ado_IsDynamicArray in arrayoptions then
  3741. begin
  3742. size:=voidpointertype.size;
  3743. exit;
  3744. end;
  3745. { Tarraydef.size may never be called for an open array! }
  3746. if (highrange=-1) and (lowrange=0) then
  3747. internalerror(99080501);
  3748. if not (ado_IsBitPacked in arrayoptions) then
  3749. cachedelesize:=elesize
  3750. else
  3751. cachedelesize := elepackedbitsize;
  3752. cachedelecount:=elecount;
  3753. if (cachedelesize = 0) then
  3754. begin
  3755. size := 0;
  3756. exit;
  3757. end;
  3758. if (cachedelecount = 0) then
  3759. begin
  3760. size := -1;
  3761. exit;
  3762. end;
  3763. { prevent overflow, return -1 to indicate overflow }
  3764. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  3765. if (cachedelecount > asizeuint(high(asizeint))) or
  3766. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  3767. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  3768. accessing the array, see ncgmem (PFV) }
  3769. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  3770. begin
  3771. result:=-1;
  3772. exit;
  3773. end;
  3774. result:=cachedelesize*asizeint(cachedelecount);
  3775. if (ado_IsBitPacked in arrayoptions) then
  3776. { can't just add 7 and divide by 8, because that may overflow }
  3777. result:=result div 8 + ord((result mod 8)<>0);
  3778. {$ifdef cpu16bitaddr}
  3779. if result>65535 then
  3780. begin
  3781. result:=-1;
  3782. exit;
  3783. end;
  3784. {$endif cpu16bitaddr}
  3785. end;
  3786. procedure tarraydef.setelementdef(def:tdef);
  3787. begin
  3788. _elementdef:=def;
  3789. if not(
  3790. (ado_IsDynamicArray in arrayoptions) or
  3791. (ado_IsConvertedPointer in arrayoptions) or
  3792. (ado_IsConstructor in arrayoptions) or
  3793. (highrange<lowrange)
  3794. ) and
  3795. (size=-1) then
  3796. Message(sym_e_segment_too_large);
  3797. end;
  3798. function tarraydef.alignment : shortint;
  3799. begin
  3800. if ado_IsVector in arrayoptions then
  3801. alignment:=size
  3802. { alignment of dyn. arrays doesn't depend on the element size }
  3803. else if ado_IsDynamicArray in arrayoptions then
  3804. alignment:=voidpointertype.alignment
  3805. { alignment is the target alignment for the used load size }
  3806. else if (ado_IsBitPacked in arrayoptions) and
  3807. (elementdef.typ in [enumdef,orddef]) then
  3808. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  3809. { alignment is the alignment of the elements }
  3810. else
  3811. alignment:=elementdef.alignment
  3812. end;
  3813. function tarraydef.needs_inittable : boolean;
  3814. begin
  3815. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  3816. end;
  3817. function tarraydef.needs_separate_initrtti : boolean;
  3818. begin
  3819. if ado_IsBitPacked in arrayoptions then
  3820. result:=false
  3821. else
  3822. result:=elementdef.needs_separate_initrtti;
  3823. end;
  3824. function tarraydef.GetTypeName : string;
  3825. begin
  3826. if (ado_IsConstString in arrayoptions) then
  3827. result:='Constant String'
  3828. else if (ado_isarrayofconst in arrayoptions) or
  3829. (ado_isConstructor in arrayoptions) then
  3830. begin
  3831. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  3832. GetTypeName:='Array Of Const'
  3833. else
  3834. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  3835. end
  3836. else if (ado_IsDynamicArray in arrayoptions) then
  3837. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  3838. else if ((highrange=-1) and (lowrange=0)) then
  3839. GetTypeName:='{Open} Array Of '+elementdef.typename
  3840. else
  3841. begin
  3842. result := '';
  3843. if (ado_IsBitPacked in arrayoptions) then
  3844. result:='BitPacked ';
  3845. if rangedef.typ=enumdef then
  3846. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  3847. else
  3848. result:=result+'Array['+tostr(lowrange)+'..'+
  3849. tostr(highrange)+'] Of '+elementdef.typename
  3850. end;
  3851. end;
  3852. function tarraydef.getmangledparaname : TSymStr;
  3853. begin
  3854. if ado_isarrayofconst in arrayoptions then
  3855. getmangledparaname:='array_of_const'
  3856. else
  3857. if ((highrange=-1) and (lowrange=0)) then
  3858. getmangledparaname:='array_of_'+elementdef.mangledparaname
  3859. else
  3860. internalerror(200204176);
  3861. end;
  3862. function tarraydef.is_publishable : boolean;
  3863. begin
  3864. Result:=ado_IsDynamicArray in arrayoptions;
  3865. end;
  3866. function tarraydef.is_hwvector: boolean;
  3867. begin
  3868. result:=ado_IsVector in arrayoptions;
  3869. end;
  3870. {***************************************************************************
  3871. tabstractrecorddef
  3872. ***************************************************************************}
  3873. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp;doregister:boolean);
  3874. begin
  3875. inherited create(dt,doregister);
  3876. objname:=stringdup(upper(n));
  3877. objrealname:=stringdup(n);
  3878. objectoptions:=[];
  3879. if assigned(current_module.namespace) then
  3880. begin
  3881. import_lib:=stringdup(current_module.namespace^);
  3882. replace(import_lib^,'.','/');
  3883. end;
  3884. end;
  3885. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3886. begin
  3887. inherited ppuload(dt,ppufile);
  3888. objrealname:=ppufile.getpshortstring;
  3889. objname:=stringdup(upper(objrealname^));
  3890. import_lib:=ppufile.getpshortstring;
  3891. { only used for external C++ classes and Java classes/records }
  3892. if (import_lib^='') then
  3893. stringdispose(import_lib);
  3894. ppufile.getset(tppuset4(objectoptions));
  3895. end;
  3896. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  3897. begin
  3898. inherited ppuwrite(ppufile);
  3899. ppufile.putstring(objrealname^);
  3900. if assigned(import_lib) then
  3901. ppufile.putstring(import_lib^)
  3902. else
  3903. ppufile.putstring('');
  3904. ppufile.putset(tppuset4(objectoptions));
  3905. end;
  3906. destructor tabstractrecorddef.destroy;
  3907. begin
  3908. stringdispose(objname);
  3909. stringdispose(objrealname);
  3910. stringdispose(import_lib);
  3911. tcinitcode.free;
  3912. inherited destroy;
  3913. end;
  3914. procedure tabstractrecorddef.buildderefimpl;
  3915. begin
  3916. inherited buildderefimpl;
  3917. if not (df_copied_def in defoptions) then
  3918. tstoredsymtable(symtable).buildderefimpl;
  3919. end;
  3920. procedure tabstractrecorddef.derefimpl;
  3921. begin
  3922. inherited derefimpl;
  3923. if not (df_copied_def in defoptions) then
  3924. tstoredsymtable(symtable).derefimpl(false);
  3925. end;
  3926. procedure tabstractrecorddef.check_forwards;
  3927. begin
  3928. { the defs of a copied def are defined for the original type only }
  3929. if not(df_copied_def in defoptions) then
  3930. tstoredsymtable(symtable).check_forwards;
  3931. end;
  3932. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  3933. var
  3934. i: longint;
  3935. sym: tsym;
  3936. begin
  3937. for i:=0 to symtable.SymList.Count-1 do
  3938. begin
  3939. sym:=tsym(symtable.SymList[i]);
  3940. if sym.typ=procsym then
  3941. begin
  3942. result:=tprocsym(sym).find_procdef_bytype(pt);
  3943. if assigned(result) then
  3944. exit;
  3945. end;
  3946. end;
  3947. result:=nil;
  3948. end;
  3949. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  3950. begin
  3951. if t=gs_record then
  3952. GetSymtable:=symtable
  3953. else
  3954. GetSymtable:=nil;
  3955. end;
  3956. function tabstractrecorddef.is_packed:boolean;
  3957. begin
  3958. result:=tabstractrecordsymtable(symtable).is_packed;
  3959. end;
  3960. function tabstractrecorddef.RttiName: string;
  3961. function generate_full_paramname(maxlength:longint):string;
  3962. const
  3963. commacount : array[boolean] of longint = (0,1);
  3964. var
  3965. fullparas,
  3966. paramname : ansistring;
  3967. module : tmodule;
  3968. sym : ttypesym;
  3969. i : longint;
  3970. begin
  3971. { we want at least enough space for an ellipsis }
  3972. if maxlength<3 then
  3973. internalerror(2014121203);
  3974. fullparas:='';
  3975. for i:=0 to genericparas.count-1 do
  3976. begin
  3977. sym:=ttypesym(genericparas[i]);
  3978. module:=find_module_from_symtable(sym.owner);
  3979. if not assigned(module) then
  3980. internalerror(2014121202);
  3981. paramname:=module.realmodulename^;
  3982. if sym.typedef.typ in [objectdef,recorddef] then
  3983. paramname:=paramname+'.'+tabstractrecorddef(sym.typedef).rttiname
  3984. else
  3985. paramname:=paramname+'.'+sym.typedef.typename;
  3986. if length(fullparas)+commacount[i>0]+length(paramname)>maxlength then
  3987. begin
  3988. if i>0 then
  3989. fullparas:=fullparas+',...'
  3990. else
  3991. fullparas:=fullparas+'...';
  3992. break;
  3993. end;
  3994. { could we fit an ellipsis after this parameter if it should be too long? }
  3995. if (maxlength-(length(fullparas)+commacount[i>0]+length(paramname))<4) and (i<genericparas.count-1) then
  3996. begin
  3997. { then omit already this parameter }
  3998. if i>0 then
  3999. fullparas:=fullparas+',...'
  4000. else
  4001. fullparas:=fullparas+'...';
  4002. break;
  4003. end;
  4004. if i>0 then
  4005. fullparas:=fullparas+',';
  4006. fullparas:=fullparas+paramname;
  4007. end;
  4008. result:=fullparas;
  4009. end;
  4010. var
  4011. nongeneric,
  4012. basename : string;
  4013. i,
  4014. remlength,
  4015. paramcount,
  4016. crcidx : longint;
  4017. begin
  4018. if rttistring='' then
  4019. begin
  4020. if is_specialization then
  4021. begin
  4022. rttistring:=OwnerHierarchyName;
  4023. { there should be two $ characters, one before the CRC and one before the count }
  4024. crcidx:=-1;
  4025. for i:=length(objrealname^) downto 1 do
  4026. if objrealname^[i]='$' then
  4027. begin
  4028. crcidx:=i;
  4029. break;
  4030. end;
  4031. if crcidx<0 then
  4032. internalerror(2014121201);
  4033. basename:=copy(objrealname^,1,crcidx-1);
  4034. split_generic_name(basename,nongeneric,paramcount);
  4035. rttistring:=rttistring+nongeneric+'<';
  4036. remlength:=255-length(rttistring)-1;
  4037. if remlength<4 then
  4038. rttistring:=rttistring+'>'
  4039. else
  4040. rttistring:=rttistring+generate_full_paramname(remlength)+'>';
  4041. end
  4042. else
  4043. if is_generic then
  4044. begin
  4045. rttistring:=OwnerHierarchyName;
  4046. split_generic_name(objrealname^,nongeneric,paramcount);
  4047. rttistring:=rttistring+nongeneric+'<';
  4048. { we don't want any ',' if there is only one parameter }
  4049. for i:=0 to paramcount-0 do
  4050. rttistring:=rttistring+',';
  4051. rttistring:=rttistring+'>';
  4052. end
  4053. else
  4054. rttistring:=OwnerHierarchyName+objrealname^;
  4055. end;
  4056. result:=rttistring;
  4057. end;
  4058. function tabstractrecorddef.search_enumerator_get: tprocdef;
  4059. var
  4060. sym : tsym;
  4061. i : integer;
  4062. pd : tprocdef;
  4063. hashedid : THashedIDString;
  4064. begin
  4065. result:=nil;
  4066. hashedid.id:='GETENUMERATOR';
  4067. sym:=tsym(symtable.FindWithHash(hashedid));
  4068. if assigned(sym) and (sym.typ=procsym) then
  4069. begin
  4070. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  4071. begin
  4072. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4073. if (pd.proctypeoption = potype_function) and
  4074. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  4075. (pd.visibility >= vis_public) then
  4076. begin
  4077. result:=pd;
  4078. exit;
  4079. end;
  4080. end;
  4081. end;
  4082. end;
  4083. function tabstractrecorddef.search_enumerator_move: tprocdef;
  4084. var
  4085. sym : tsym;
  4086. i : integer;
  4087. pd : tprocdef;
  4088. hashedid : THashedIDString;
  4089. begin
  4090. result:=nil;
  4091. // first search for po_enumerator_movenext method modifier
  4092. // then search for public function MoveNext: Boolean
  4093. for i:=0 to symtable.SymList.Count-1 do
  4094. begin
  4095. sym:=TSym(symtable.SymList[i]);
  4096. if (sym.typ=procsym) then
  4097. begin
  4098. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  4099. if assigned(pd) then
  4100. begin
  4101. result:=pd;
  4102. exit;
  4103. end;
  4104. end;
  4105. end;
  4106. hashedid.id:='MOVENEXT';
  4107. sym:=tsym(symtable.FindWithHash(hashedid));
  4108. if assigned(sym) and (sym.typ=procsym) then
  4109. begin
  4110. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  4111. begin
  4112. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4113. if (pd.proctypeoption = potype_function) and
  4114. is_boolean(pd.returndef) and
  4115. (pd.minparacount = 0) and
  4116. (pd.visibility >= vis_public) then
  4117. begin
  4118. result:=pd;
  4119. exit;
  4120. end;
  4121. end;
  4122. end;
  4123. end;
  4124. function tabstractrecorddef.search_enumerator_current: tsym;
  4125. var
  4126. sym: tsym;
  4127. i: integer;
  4128. hashedid : THashedIDString;
  4129. begin
  4130. result:=nil;
  4131. // first search for ppo_enumerator_current property modifier
  4132. // then search for public property Current
  4133. for i:=0 to symtable.SymList.Count-1 do
  4134. begin
  4135. sym:=TSym(symtable.SymList[i]);
  4136. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  4137. begin
  4138. result:=sym;
  4139. exit;
  4140. end;
  4141. end;
  4142. hashedid.id:='CURRENT';
  4143. sym:=tsym(symtable.FindWithHash(hashedid));
  4144. if assigned(sym) and (sym.typ=propertysym) and
  4145. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  4146. begin
  4147. result:=sym;
  4148. exit;
  4149. end;
  4150. end;
  4151. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  4152. var
  4153. st: tsymtable;
  4154. enclosingdef: tdef;
  4155. begin
  4156. if typ=objectdef then
  4157. result:=tobjectdef(self).objextname^
  4158. else if assigned(typesym) then
  4159. result:=typesym.realname
  4160. { have to generate anonymous nested type in current unit/class/record }
  4161. else
  4162. internalerror(2011032601);
  4163. { in case of specializations, add some extras to prevent name conflicts
  4164. with nested classes }
  4165. if df_specialization in defoptions then
  4166. result:='$'+result+'$specialization$';
  4167. st:=owner;
  4168. while assigned(st) and
  4169. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  4170. begin
  4171. { nested classes are named as "OuterClass$InnerClass" }
  4172. enclosingdef:=tdef(st.defowner);
  4173. if enclosingdef.typ=procdef then
  4174. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  4175. else if enclosingdef.typ=objectdef then
  4176. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  4177. else if assigned(enclosingdef.typesym) then
  4178. result:=enclosingdef.typesym.realname+'$'+result
  4179. else
  4180. internalerror(2011060305);
  4181. st:=enclosingdef.owner;
  4182. end;
  4183. if with_package_name and
  4184. assigned(import_lib) then
  4185. result:=import_lib^+'/'+result;
  4186. end;
  4187. function tabstractrecorddef.contains_float_field: boolean;
  4188. var
  4189. i : longint;
  4190. begin
  4191. result:=true;
  4192. for i:=0 to symtable.symlist.count-1 do
  4193. begin
  4194. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4195. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4196. continue;
  4197. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4198. begin
  4199. if tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  4200. exit;
  4201. { search recursively }
  4202. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4203. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_float_field) then
  4204. exit;
  4205. end;
  4206. end;
  4207. result:=false;
  4208. end;
  4209. function tabstractrecorddef.contains_cross_aword_field: boolean;
  4210. var
  4211. i : longint;
  4212. foffset, fsize: aword;
  4213. begin
  4214. result:=true;
  4215. for i:=0 to symtable.symlist.count-1 do
  4216. begin
  4217. if (tsym(symtable.symlist[i]).typ<>fieldvarsym) or
  4218. (sp_static in tsym(symtable.symlist[i]).symoptions) then
  4219. continue;
  4220. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) then
  4221. begin
  4222. if is_packed then
  4223. begin
  4224. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset;
  4225. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.packedbitsize;
  4226. end
  4227. else
  4228. begin
  4229. foffset:=tfieldvarsym(symtable.symlist[i]).fieldoffset*8;
  4230. fsize:=tfieldvarsym(symtable.symlist[i]).vardef.size*8;
  4231. end;
  4232. if (fsize>0) and ((foffset div (sizeof(aword)*8)) <> ((foffset+fsize-1) div (sizeof(aword)*8))) then
  4233. exit;
  4234. { search recursively }
  4235. if (tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).typ=recorddef) and
  4236. (tabstractrecorddef(tfieldvarsym(symtable.symlist[i]).vardef).contains_cross_aword_field) then
  4237. exit;
  4238. end;
  4239. end;
  4240. result:=false;
  4241. end;
  4242. {***************************************************************************
  4243. trecorddef
  4244. ***************************************************************************}
  4245. constructor trecorddef.create(const n:string; p:TSymtable);
  4246. begin
  4247. inherited create(n,recorddef,true);
  4248. symtable:=p;
  4249. { we can own the symtable only if nobody else owns a copy so far }
  4250. if symtable.refcount=1 then
  4251. symtable.defowner:=self;
  4252. isunion:=false;
  4253. cloneddefderef.reset;
  4254. end;
  4255. constructor trecorddef.create_global_internal(const n: string; packrecords, recordalignmin: shortint);
  4256. var
  4257. name : string;
  4258. pname : pshortstring;
  4259. oldsymtablestack: tsymtablestack;
  4260. where : tsymtable;
  4261. ts: ttypesym;
  4262. begin
  4263. { construct name }
  4264. if n<>'' then
  4265. pname:=@n
  4266. else
  4267. begin
  4268. init_defid;
  4269. name:='$InternalRec'+unique_id_str;
  4270. pname:=@name;
  4271. end;
  4272. oldsymtablestack:=symtablestack;
  4273. { do not simply push/pop current_module.localsymtable, because
  4274. that can have side-effects (e.g., it removes helpers) }
  4275. symtablestack:=nil;
  4276. symtable:=trecordsymtable.create(pname^,packrecords,recordalignmin);
  4277. symtable.defowner:=self;
  4278. isunion:=false;
  4279. inherited create(pname^,recorddef,true);
  4280. where:=current_module.localsymtable;
  4281. if not assigned(where) then
  4282. where:=current_module.globalsymtable;
  4283. where.insertdef(self);
  4284. { if we specified a name, then we'll probably want to look up the
  4285. type again by name too -> create typesym }
  4286. if n<>'' then
  4287. begin
  4288. ts:=ctypesym.create(n,self);
  4289. { avoid hints about unused types (these may only be used for
  4290. typed constant data) }
  4291. ts.increfcount;
  4292. where.insert(ts);
  4293. end;
  4294. symtablestack:=oldsymtablestack;
  4295. { don't create RTTI for internal types, these are not exported }
  4296. defstates:=defstates+[ds_rtti_table_written,ds_init_table_written];
  4297. include(defoptions,df_internal);
  4298. end;
  4299. function trecorddef.add_field_by_def(const optionalname: TIDString; def: tdef): tsym;
  4300. var
  4301. sym: tfieldvarsym;
  4302. name: TIDString;
  4303. pname: ^TIDString;
  4304. begin
  4305. if optionalname='' then
  4306. begin
  4307. name:='$f'+tostr(trecordsymtable(symtable).symlist.count);
  4308. pname:=@name
  4309. end
  4310. else
  4311. pname:=@optionalname;
  4312. sym:=cfieldvarsym.create(pname^,vs_value,def,[]);
  4313. symtable.insert(sym);
  4314. trecordsymtable(symtable).addfield(sym,vis_hidden);
  4315. result:=sym;
  4316. end;
  4317. procedure trecorddef.add_fields_from_deflist(fieldtypes: tfplist);
  4318. var
  4319. i: longint;
  4320. begin
  4321. for i:=0 to fieldtypes.count-1 do
  4322. add_field_by_def('',tdef(fieldtypes[i]));
  4323. end;
  4324. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  4325. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  4326. var
  4327. i,j : longint;
  4328. begin
  4329. if ppufile.getbyte=1 then
  4330. begin
  4331. new(variantrecdesc);
  4332. ppufile.getderef(variantrecdesc^.variantselectorderef);
  4333. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  4334. for i:=0 to high(variantrecdesc^.branches) do
  4335. begin
  4336. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  4337. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4338. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  4339. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4340. end;
  4341. end
  4342. else
  4343. variantrecdesc:=nil;
  4344. end;
  4345. begin
  4346. inherited ppuload(recorddef,ppufile);
  4347. if df_copied_def in defoptions then
  4348. begin
  4349. ppufile.getderef(cloneddefderef);
  4350. ppuload_platform(ppufile);
  4351. end
  4352. else
  4353. begin
  4354. symtable:=trecordsymtable.create(objrealname^,0,0);
  4355. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  4356. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  4357. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  4358. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  4359. trecordsymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  4360. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  4361. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  4362. ppufile.getset(tppuset1(trecordsymtable(symtable).managementoperators));
  4363. { position of ppuload_platform call must correspond
  4364. to position of writeentry in ppuwrite method }
  4365. ppuload_platform(ppufile);
  4366. trecordsymtable(symtable).ppuload(ppufile);
  4367. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4368. but because iso mode supports no units, there is no need to store the variantrecdesc
  4369. in the ppu
  4370. }
  4371. // readvariantrecdesc(variantrecdesc);
  4372. { requires usefieldalignment to be set }
  4373. symtable.defowner:=self;
  4374. end;
  4375. isunion:=false;
  4376. end;
  4377. destructor trecorddef.destroy;
  4378. procedure free_variantrecdesc(var variantrecdesc : pvariantrecdesc);
  4379. var
  4380. i : longint;
  4381. begin
  4382. while assigned(variantrecdesc) do
  4383. begin
  4384. for i:=0 to high(variantrecdesc^.branches) do
  4385. begin
  4386. free_variantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4387. SetLength(variantrecdesc^.branches[i].values,0);
  4388. end;
  4389. SetLength(variantrecdesc^.branches,0);
  4390. dispose(variantrecdesc);
  4391. variantrecdesc:=nil;
  4392. end;
  4393. end;
  4394. begin
  4395. if assigned(variantrecdesc) then
  4396. free_variantrecdesc(variantrecdesc);
  4397. if assigned(symtable) then
  4398. begin
  4399. symtable.free;
  4400. symtable:=nil;
  4401. end;
  4402. inherited destroy;
  4403. end;
  4404. function trecorddef.getcopy : tstoreddef;
  4405. begin
  4406. result:=crecorddef.create(objrealname^,symtable.getcopy);
  4407. trecorddef(result).isunion:=isunion;
  4408. include(trecorddef(result).defoptions,df_copied_def);
  4409. if assigned(tcinitcode) then
  4410. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  4411. if assigned(import_lib) then
  4412. trecorddef(result).import_lib:=stringdup(import_lib^);
  4413. end;
  4414. function trecorddef.needs_inittable : boolean;
  4415. begin
  4416. { each record with managed field or with any management operator needs
  4417. init table }
  4418. needs_inittable:=(trecordsymtable(symtable).managementoperators<>[]) or
  4419. trecordsymtable(symtable).needs_init_final
  4420. end;
  4421. function trecorddef.needs_separate_initrtti : boolean;
  4422. begin
  4423. result:=true;
  4424. end;
  4425. function trecorddef.has_non_trivial_init_child(check_parent:boolean):boolean;
  4426. begin
  4427. result:=trecordsymtable(symtable).has_non_trivial_init;
  4428. end;
  4429. procedure trecorddef.buildderef;
  4430. begin
  4431. inherited buildderef;
  4432. if df_copied_def in defoptions then
  4433. cloneddefderef.build(symtable.defowner)
  4434. else
  4435. tstoredsymtable(symtable).buildderef;
  4436. end;
  4437. procedure trecorddef.deref;
  4438. begin
  4439. inherited deref;
  4440. { now dereference the definitions }
  4441. if df_copied_def in defoptions then
  4442. begin
  4443. cloneddef:=trecorddef(cloneddefderef.resolve);
  4444. symtable:=cloneddef.symtable.getcopy;
  4445. end
  4446. else
  4447. tstoredsymtable(symtable).deref(false);
  4448. { internal types, only load from the system unit }
  4449. if assigned(owner) and
  4450. assigned(owner.name) and
  4451. (owner.name^='SYSTEM') then
  4452. begin
  4453. { TGUID }
  4454. if not assigned(rec_tguid) and
  4455. (upper(typename)='TGUID') then
  4456. rec_tguid:=self
  4457. { JMP_BUF }
  4458. else if not assigned(rec_jmp_buf) and
  4459. (upper(typename)='JMP_BUF') then
  4460. rec_jmp_buf:=self
  4461. else if not assigned(rec_exceptaddr) and
  4462. (upper(typename)='TEXCEPTADDR') then
  4463. rec_exceptaddr:=self;
  4464. end;
  4465. end;
  4466. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  4467. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  4468. var
  4469. i,j : longint;
  4470. begin
  4471. if assigned(variantrecdesc) then
  4472. begin
  4473. ppufile.putbyte(1);
  4474. ppufile.putderef(variantrecdesc^.variantselectorderef);
  4475. ppufile.putasizeint(length(variantrecdesc^.branches));
  4476. for i:=0 to high(variantrecdesc^.branches) do
  4477. begin
  4478. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  4479. for j:=0 to high(variantrecdesc^.branches[i].values) do
  4480. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  4481. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  4482. end;
  4483. end
  4484. else
  4485. ppufile.putbyte(0);
  4486. end;
  4487. begin
  4488. inherited ppuwrite(ppufile);
  4489. if df_copied_def in defoptions then
  4490. ppufile.putderef(cloneddefderef)
  4491. else
  4492. begin
  4493. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  4494. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  4495. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  4496. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  4497. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignmin));
  4498. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  4499. ppufile.putword(trecordsymtable(symtable).paddingsize);
  4500. ppufile.putset(tppuset1(trecordsymtable(symtable).managementoperators));
  4501. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  4502. but because iso mode supports no units, there is no need to store the variantrecdesc
  4503. in the ppu
  4504. }
  4505. // writevariantrecdesc(variantrecdesc);
  4506. end;
  4507. writeentry(ppufile,ibrecorddef);
  4508. if not(df_copied_def in defoptions) then
  4509. trecordsymtable(symtable).ppuwrite(ppufile);
  4510. end;
  4511. function trecorddef.size:asizeint;
  4512. begin
  4513. result:=trecordsymtable(symtable).datasize;
  4514. end;
  4515. function trecorddef.alignment:shortint;
  4516. begin
  4517. alignment:=trecordsymtable(symtable).recordalignment;
  4518. end;
  4519. function trecorddef.padalignment:shortint;
  4520. begin
  4521. padalignment := trecordsymtable(symtable).padalignment;
  4522. end;
  4523. function trecorddef.GetTypeName : string;
  4524. begin
  4525. GetTypeName:='<record type>'
  4526. end;
  4527. {***************************************************************************
  4528. TABSTRACTPROCDEF
  4529. ***************************************************************************}
  4530. constructor tabstractprocdef.create(dt:tdeftyp;level:byte;doregister:boolean);
  4531. begin
  4532. inherited create(dt,doregister);
  4533. parast:=tparasymtable.create(self,level);
  4534. paras:=nil;
  4535. minparacount:=0;
  4536. maxparacount:=0;
  4537. proctypeoption:=potype_none;
  4538. proccalloption:=pocall_none;
  4539. procoptions:=[];
  4540. returndef:=voidtype;
  4541. returndefderef.reset;
  4542. savesize:=sizeof(pint);
  4543. callerargareasize:=0;
  4544. calleeargareasize:=0;
  4545. has_paraloc_info:=callnoside;
  4546. funcretloc[callerside].init;
  4547. funcretloc[calleeside].init;
  4548. check_mark_as_nested;
  4549. end;
  4550. destructor tabstractprocdef.destroy;
  4551. begin
  4552. if assigned(paras) then
  4553. begin
  4554. {$ifdef MEMDEBUG}
  4555. memprocpara.start;
  4556. {$endif MEMDEBUG}
  4557. paras.free;
  4558. paras:=nil;
  4559. {$ifdef MEMDEBUG}
  4560. memprocpara.stop;
  4561. {$endif MEMDEBUG}
  4562. end;
  4563. if assigned(parast) then
  4564. begin
  4565. {$ifdef MEMDEBUG}
  4566. memprocparast.start;
  4567. {$endif MEMDEBUG}
  4568. parast.free;
  4569. parast:=nil;
  4570. {$ifdef MEMDEBUG}
  4571. memprocparast.stop;
  4572. {$endif MEMDEBUG}
  4573. end;
  4574. funcretloc[callerside].done;
  4575. funcretloc[calleeside].done;
  4576. inherited destroy;
  4577. end;
  4578. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  4579. begin
  4580. if (tsym(p).typ<>paravarsym) then
  4581. exit;
  4582. inc(plongint(arg)^);
  4583. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  4584. begin
  4585. if not assigned(tparavarsym(p).defaultconstsym) then
  4586. inc(minparacount);
  4587. inc(maxparacount);
  4588. end;
  4589. end;
  4590. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  4591. begin
  4592. if (tsym(p).typ<>paravarsym) then
  4593. exit;
  4594. paras.add(p);
  4595. end;
  4596. procedure tabstractprocdef.calcparas;
  4597. var
  4598. paracount : longint;
  4599. begin
  4600. { This can already be assigned when
  4601. we need to reresolve this unit (PFV) }
  4602. if assigned(paras) then
  4603. paras.free;
  4604. paras:=tparalist.create(false);
  4605. paracount:=0;
  4606. minparacount:=0;
  4607. maxparacount:=0;
  4608. parast.SymList.ForEachCall(@count_para,@paracount);
  4609. paras.capacity:=paracount;
  4610. { Insert parameters in table }
  4611. parast.SymList.ForEachCall(@insert_para,nil);
  4612. { Order parameters }
  4613. paras.sortparas;
  4614. end;
  4615. function tabstractprocdef.mangledprocparanames(oldlen : longint) : string;
  4616. var
  4617. crc : dword;
  4618. hp : TParavarsym;
  4619. hs : TSymStr;
  4620. newlen,
  4621. i : integer;
  4622. begin
  4623. result:='';
  4624. hp:=nil;
  4625. { add parameter types }
  4626. for i:=0 to paras.count-1 do
  4627. begin
  4628. hp:=tparavarsym(paras[i]);
  4629. if not(vo_is_hidden_para in hp.varoptions) then
  4630. result:=result+'$'+hp.vardef.mangledparaname;
  4631. end;
  4632. { add resultdef, add $$ as separator to make it unique from a
  4633. parameter separator }
  4634. if not is_void(returndef) then
  4635. result:=result+'$$'+returndef.mangledparaname;
  4636. newlen:=length(result)+oldlen;
  4637. { Replace with CRC if the parameter line is very long }
  4638. if (newlen-oldlen>12) and
  4639. ((newlen>100) or (newlen-oldlen>64)) then
  4640. begin
  4641. crc:=0;
  4642. for i:=0 to paras.count-1 do
  4643. begin
  4644. hp:=tparavarsym(paras[i]);
  4645. if not(vo_is_hidden_para in hp.varoptions) then
  4646. begin
  4647. hs:=hp.vardef.mangledparaname;
  4648. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4649. end;
  4650. end;
  4651. if not is_void(returndef) then
  4652. begin
  4653. { add a little prefix so that x(integer; integer) is different from x(integer):integer }
  4654. hs:='$$'+returndef.mangledparaname;
  4655. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4656. end;
  4657. result:='$crc'+hexstr(crc,8);
  4658. end;
  4659. end;
  4660. procedure tabstractprocdef.buildderef;
  4661. begin
  4662. { released procdef? }
  4663. if not assigned(parast) then
  4664. exit;
  4665. inherited buildderef;
  4666. returndefderef.build(returndef);
  4667. if po_explicitparaloc in procoptions then
  4668. funcretloc[callerside].buildderef;
  4669. { parast }
  4670. tparasymtable(parast).buildderef;
  4671. end;
  4672. procedure tabstractprocdef.deref;
  4673. begin
  4674. inherited deref;
  4675. returndef:=tdef(returndefderef.resolve);
  4676. if po_explicitparaloc in procoptions then
  4677. begin
  4678. funcretloc[callerside].deref;
  4679. has_paraloc_info:=callerside;
  4680. end
  4681. else
  4682. begin
  4683. { deref is called after loading from a ppu, but also after another
  4684. unit has been reloaded/recompiled and all references must be
  4685. re-resolved. Since the funcretloc contains a reference to a tdef,
  4686. reset it so that we won't try to access the stale def }
  4687. funcretloc[callerside].init;
  4688. has_paraloc_info:=callnoside;
  4689. end;
  4690. { parast }
  4691. tparasymtable(parast).deref(false);
  4692. { recalculated parameters }
  4693. calcparas;
  4694. end;
  4695. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  4696. begin
  4697. inherited ppuload(dt,ppufile);
  4698. parast:=nil;
  4699. Paras:=nil;
  4700. minparacount:=0;
  4701. maxparacount:=0;
  4702. ppufile.getderef(returndefderef);
  4703. proctypeoption:=tproctypeoption(ppufile.getbyte);
  4704. proccalloption:=tproccalloption(ppufile.getbyte);
  4705. ppufile.getset(tppuset8(procoptions));
  4706. funcretloc[callerside].init;
  4707. if po_explicitparaloc in procoptions then
  4708. funcretloc[callerside].ppuload(ppufile);
  4709. savesize:=sizeof(pint);
  4710. if (po_explicitparaloc in procoptions) then
  4711. has_paraloc_info:=callerside;
  4712. end;
  4713. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  4714. var
  4715. oldintfcrc : boolean;
  4716. begin
  4717. { released procdef? }
  4718. if not assigned(parast) then
  4719. exit;
  4720. inherited ppuwrite(ppufile);
  4721. ppufile.putderef(returndefderef);
  4722. oldintfcrc:=ppufile.do_interface_crc;
  4723. ppufile.do_interface_crc:=false;
  4724. ppufile.putbyte(ord(proctypeoption));
  4725. ppufile.putbyte(ord(proccalloption));
  4726. ppufile.putset(tppuset8(procoptions));
  4727. ppufile.do_interface_crc:=oldintfcrc;
  4728. if (po_explicitparaloc in procoptions) then
  4729. funcretloc[callerside].ppuwrite(ppufile);
  4730. end;
  4731. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  4732. var
  4733. hs,s : ansistring;
  4734. hp : TParavarsym;
  4735. hpc : tconstsym;
  4736. first : boolean;
  4737. i,j : integer;
  4738. begin
  4739. s:='';
  4740. first:=true;
  4741. for i:=0 to paras.count-1 do
  4742. begin
  4743. hp:=tparavarsym(paras[i]);
  4744. if not(vo_is_hidden_para in hp.varoptions) or
  4745. (pno_showhidden in pno) then
  4746. begin
  4747. if first then
  4748. begin
  4749. s:=s+'(';
  4750. first:=false;
  4751. end
  4752. else
  4753. s:=s+';';
  4754. if vo_is_hidden_para in hp.varoptions then
  4755. s:=s+'<';
  4756. case hp.varspez of
  4757. vs_var :
  4758. s:=s+'var ';
  4759. vs_const :
  4760. s:=s+'const ';
  4761. vs_out :
  4762. s:=s+'out ';
  4763. vs_constref :
  4764. s:=s+'constref ';
  4765. else
  4766. ;
  4767. end;
  4768. if (pno_paranames in pno) then
  4769. s:=s+hp.realname+':';
  4770. if hp.univpara then
  4771. s:=s+'univ ';
  4772. if assigned(hp.vardef.typesym) then
  4773. begin
  4774. hs:=hp.vardef.typesym.realname;
  4775. if hs[1]<>'$' then
  4776. s:=s+hp.vardef.OwnerHierarchyName+hs
  4777. else
  4778. s:=s+hp.vardef.GetTypeName;
  4779. end
  4780. else
  4781. s:=s+hp.vardef.GetTypeName;
  4782. { default value }
  4783. if assigned(hp.defaultconstsym) then
  4784. begin
  4785. hpc:=tconstsym(hp.defaultconstsym);
  4786. hs:='';
  4787. case hpc.consttyp of
  4788. constwstring:
  4789. begin
  4790. if pcompilerwidestring(hpc.value.valueptr)^.len>0 then
  4791. begin
  4792. setlength(hs,pcompilerwidestring(hpc.value.valueptr)^.len);
  4793. for j:=0 to pcompilerwidestring(hpc.value.valueptr)^.len-1 do
  4794. begin
  4795. if (ord(pcompilerwidestring(hpc.value.valueptr)^.data[j])<127) and
  4796. not(byte(pcompilerwidestring(hpc.value.valueptr)^.data[j]) in [0,10,13]) then
  4797. hs[j+1]:=char(pcompilerwidestring(hpc.value.valueptr)^.data[j])
  4798. else
  4799. hs[j+1]:='.';
  4800. end;
  4801. end;
  4802. end;
  4803. conststring,
  4804. constresourcestring :
  4805. begin
  4806. if hpc.value.len>0 then
  4807. begin
  4808. setLength(hs,hpc.value.len);
  4809. { don't write past the end of hs if the constant
  4810. is > 255 chars }
  4811. move(hpc.value.valueptr^,hs[1],length(hs));
  4812. { make sure that constant strings with newline chars
  4813. don't create a linebreak in the assembler code,
  4814. since comments are line-based. Also remove nulls
  4815. because the comments are written as a pchar. }
  4816. ReplaceCase(hs,#0,'.');
  4817. ReplaceCase(hs,#10,'.');
  4818. ReplaceCase(hs,#13,'.');
  4819. end;
  4820. end;
  4821. constreal :
  4822. str(pbestreal(hpc.value.valueptr)^,hs);
  4823. constpointer :
  4824. hs:=tostr(hpc.value.valueordptr);
  4825. constord :
  4826. begin
  4827. if is_boolean(hpc.constdef) then
  4828. begin
  4829. if hpc.value.valueord<>0 then
  4830. hs:='TRUE'
  4831. else
  4832. hs:='FALSE';
  4833. end
  4834. else
  4835. hs:=tostr(hpc.value.valueord);
  4836. end;
  4837. constnil :
  4838. hs:='nil';
  4839. constset :
  4840. hs:='<set>';
  4841. constguid:
  4842. hs:=guid2string(pguid(hpc.value.valueptr)^);
  4843. constnone:
  4844. internalerror(2019050704);
  4845. end;
  4846. if hs<>'' then
  4847. s:=s+'=`'+hs+'`';
  4848. end;
  4849. if vo_is_hidden_para in hp.varoptions then
  4850. s:=s+'>';
  4851. end;
  4852. end;
  4853. if not first then
  4854. s:=s+')';
  4855. if (po_varargs in procoptions) then
  4856. s:=s+';VarArgs';
  4857. typename_paras:=s;
  4858. end;
  4859. function tabstractprocdef.is_methodpointer:boolean;
  4860. begin
  4861. result:=false;
  4862. end;
  4863. function tabstractprocdef.is_addressonly:boolean;
  4864. begin
  4865. result:=true;
  4866. end;
  4867. function tabstractprocdef.no_self_node: boolean;
  4868. begin
  4869. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  4870. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  4871. end;
  4872. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp; const paraprefix: string): tstoreddef;
  4873. var
  4874. j, nestinglevel: longint;
  4875. pvs, npvs: tparavarsym;
  4876. begin
  4877. nestinglevel:=parast.symtablelevel;
  4878. if newtyp=procdef then
  4879. begin
  4880. if (copytyp<>pc_bareproc) then
  4881. result:=cprocdef.create(nestinglevel,true)
  4882. else
  4883. result:=cprocdef.create(normal_function_level,true);
  4884. tprocdef(result).visibility:=vis_public;
  4885. end
  4886. else
  4887. begin
  4888. result:=cprocvardef.create(nestinglevel);
  4889. end;
  4890. tabstractprocdef(result).returndef:=returndef;
  4891. tabstractprocdef(result).returndefderef:=returndefderef;
  4892. pvs:=nil;
  4893. npvs:=nil;
  4894. for j:=0 to parast.symlist.count-1 do
  4895. begin
  4896. case tsym(parast.symlist[j]).typ of
  4897. paravarsym:
  4898. begin
  4899. pvs:=tparavarsym(parast.symlist[j]);
  4900. { in case of bare proc, don't copy self, vmt or framepointer
  4901. parameters }
  4902. if (copytyp in [pc_bareproc,pc_normal_no_hidden]) and
  4903. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result,vo_is_funcret]*pvs.varoptions)<>[]) then
  4904. continue;
  4905. if paraprefix='' then
  4906. npvs:=cparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  4907. pvs.vardef,pvs.varoptions)
  4908. else if not(vo_is_high_para in pvs.varoptions) then
  4909. npvs:=cparavarsym.create(paraprefix+pvs.realname,pvs.paranr,pvs.varspez,
  4910. pvs.vardef,pvs.varoptions)
  4911. else
  4912. npvs:=cparavarsym.create('$high'+paraprefix+copy(pvs.name,5,length(pvs.name)),pvs.paranr,pvs.varspez,
  4913. pvs.vardef,pvs.varoptions);
  4914. npvs.defaultconstsym:=pvs.defaultconstsym;
  4915. tabstractprocdef(result).parast.insert(npvs);
  4916. end;
  4917. constsym:
  4918. begin
  4919. // ignore, reuse original constym. Should also be duplicated
  4920. // be safe though
  4921. end;
  4922. symconst.typesym:
  4923. begin
  4924. // reuse original, part of generic declaration
  4925. end
  4926. else
  4927. internalerror(201160604);
  4928. end;
  4929. end;
  4930. tabstractprocdef(result).savesize:=savesize;
  4931. if (typ<>procvardef) and
  4932. (newtyp=procvardef) then
  4933. begin
  4934. { procvars can't be (class)constructures/destructors etc }
  4935. if proctypeoption=potype_constructor then
  4936. begin
  4937. tabstractprocdef(result).returndef:=tdef(owner.defowner);
  4938. if not(is_implicit_pointer_object_type(returndef) or
  4939. (returndef.typ<>objectdef)) then
  4940. tabstractprocdef(result).returndef:=cpointerdef.getreusable(tabstractprocdef(result).returndef);
  4941. tabstractprocdef(result).proctypeoption:=potype_function;
  4942. end
  4943. else if is_void(returndef) then
  4944. tabstractprocdef(result).proctypeoption:=potype_procedure
  4945. else
  4946. tabstractprocdef(result).proctypeoption:=potype_function;
  4947. end
  4948. else
  4949. tabstractprocdef(result).proctypeoption:=proctypeoption;
  4950. tabstractprocdef(result).proccalloption:=proccalloption;
  4951. tabstractprocdef(result).procoptions:=procoptions;
  4952. if (copytyp=pc_bareproc) then
  4953. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  4954. if newtyp=procvardef then
  4955. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  4956. if copytyp=pc_address_only then
  4957. include(tabstractprocdef(result).procoptions,po_addressonly);
  4958. tabstractprocdef(result).callerargareasize:=callerargareasize;
  4959. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  4960. tabstractprocdef(result).maxparacount:=maxparacount;
  4961. tabstractprocdef(result).minparacount:=minparacount;
  4962. if po_explicitparaloc in procoptions then
  4963. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  4964. { recalculate parameter info }
  4965. tabstractprocdef(result).has_paraloc_info:=callnoside;
  4966. {$ifdef m68k}
  4967. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  4968. {$endif}
  4969. if (typ=procdef) and
  4970. (newtyp=procvardef) and
  4971. (owner.symtabletype=ObjectSymtable) then
  4972. include(tprocvardef(result).procoptions,po_methodpointer);
  4973. end;
  4974. function tabstractprocdef.compatible_with_pointerdef_size(ptr: tpointerdef): boolean;
  4975. begin
  4976. result:=is_addressonly;
  4977. end;
  4978. procedure tabstractprocdef.check_mark_as_nested;
  4979. begin
  4980. { nested procvars require that nested functions use the Delphi-style
  4981. nested procedure calling convention }
  4982. if (parast.symtablelevel>normal_function_level) and
  4983. (m_nested_procvars in current_settings.modeswitches) then
  4984. include(procoptions,po_delphi_nested_cc);
  4985. end;
  4986. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  4987. begin
  4988. if (side in [callerside,callbothsides]) and
  4989. not(has_paraloc_info in [callerside,callbothsides]) then
  4990. begin
  4991. if not is_c_variadic(self) then
  4992. callerargareasize:=paramanager.create_paraloc_info(self,callerside)
  4993. else
  4994. callerargareasize:=paramanager.create_varargs_paraloc_info(self,callerside,nil);
  4995. if has_paraloc_info in [calleeside,callbothsides] then
  4996. has_paraloc_info:=callbothsides
  4997. else
  4998. has_paraloc_info:=callerside;
  4999. end;
  5000. if (side in [calleeside,callbothsides]) and
  5001. not(has_paraloc_info in [calleeside,callbothsides]) then
  5002. begin
  5003. if not is_c_variadic(self) then
  5004. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside)
  5005. else
  5006. callerargareasize:=paramanager.create_varargs_paraloc_info(self,calleeside,nil);
  5007. if has_paraloc_info in [callerside,callbothsides] then
  5008. has_paraloc_info:=callbothsides
  5009. else
  5010. has_paraloc_info:=calleeside;
  5011. end;
  5012. end;
  5013. procedure tabstractprocdef.done_paraloc_info(side: tcallercallee);
  5014. var
  5015. i: longint;
  5016. begin
  5017. if (side in [callerside,callbothsides]) and
  5018. (has_paraloc_info in [callerside,callbothsides]) then
  5019. begin
  5020. funcretloc[callerside].done;
  5021. for i:=0 to paras.count-1 do
  5022. tparavarsym(paras[i]).paraloc[callerside].done;
  5023. if has_paraloc_info=callerside then
  5024. has_paraloc_info:=callnoside
  5025. else
  5026. has_paraloc_info:=calleeside;
  5027. end;
  5028. if (side in [calleeside,callbothsides]) and
  5029. (has_paraloc_info in [calleeside,callbothsides]) then
  5030. begin
  5031. funcretloc[calleeside].done;
  5032. for i:=0 to paras.count-1 do
  5033. tparavarsym(paras[i]).paraloc[calleeside].done;
  5034. if has_paraloc_info=calleeside then
  5035. has_paraloc_info:=callnoside
  5036. else
  5037. has_paraloc_info:=callerside;
  5038. end;
  5039. end;
  5040. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  5041. var
  5042. p: tparavarsym;
  5043. ploc: PCGParalocation;
  5044. i: longint;
  5045. begin
  5046. result:=false;
  5047. init_paraloc_info(side);
  5048. for i:=0 to parast.SymList.Count-1 do
  5049. if tsym(parast.SymList[i]).typ=paravarsym then
  5050. begin
  5051. p:=tparavarsym(parast.SymList[i]);
  5052. { check if no parameter is located on the stack }
  5053. if (is_open_array(p.vardef) or
  5054. is_array_of_const(p.vardef)) and (p.varspez=vs_value) then
  5055. begin
  5056. result:=true;
  5057. exit;
  5058. end;
  5059. ploc:=p.paraloc[side].location;
  5060. while assigned(ploc) do
  5061. begin
  5062. if (ploc^.loc=LOC_REFERENCE) then
  5063. begin
  5064. result:=true;
  5065. exit
  5066. end;
  5067. ploc:=ploc^.next;
  5068. end;
  5069. end;
  5070. end;
  5071. function tabstractprocdef.is_pushleftright: boolean;
  5072. begin
  5073. result:=false;
  5074. end;
  5075. function tabstractprocdef.address_type: tdef;
  5076. begin
  5077. result:=voidcodepointertype;
  5078. end;
  5079. function tabstractprocdef.ofs_address_type:tdef;
  5080. begin
  5081. result:=address_type;
  5082. end;
  5083. procedure tabstractprocdef.declared_far;
  5084. begin
  5085. Message1(parser_w_proc_directive_ignored,'FAR');
  5086. end;
  5087. procedure tabstractprocdef.declared_near;
  5088. begin
  5089. Message1(parser_w_proc_directive_ignored,'NEAR');
  5090. end;
  5091. function tabstractprocdef.generate_safecall_wrapper: boolean;
  5092. begin
  5093. {$ifdef SUPPORT_SAFECALL}
  5094. result:=
  5095. (proccalloption=pocall_safecall) and
  5096. not(po_assembler in procoptions) and
  5097. (tf_safecall_exceptions in target_info.flags);
  5098. {$else SUPPORT_SAFECALL}
  5099. result:=false;
  5100. {$endif}
  5101. end;
  5102. {***************************************************************************
  5103. TPROCDEF
  5104. ***************************************************************************}
  5105. function tprocdef.store_localst: boolean;
  5106. begin
  5107. result:=has_inlininginfo or (df_generic in defoptions);
  5108. end;
  5109. function tprocdef.GetResultName: PShortString;
  5110. begin
  5111. if not assigned(implprocdefinfo) then
  5112. internalerror(2014010301);
  5113. result:=implprocdefinfo^.resultname;
  5114. end;
  5115. procedure tprocdef.SetResultName(AValue: PShortString);
  5116. begin
  5117. if not assigned(implprocdefinfo) then
  5118. internalerror(2014010302);
  5119. implprocdefinfo^.resultname:=AValue;
  5120. end;
  5121. function tprocdef.GetParentFPInitBlock: tnode;
  5122. begin
  5123. if not assigned(implprocdefinfo) then
  5124. internalerror(2014010303);
  5125. result:=implprocdefinfo^.parentfpinitblock;
  5126. end;
  5127. function tprocdef.GetParentFPStruct: tsym;
  5128. begin
  5129. if not assigned(implprocdefinfo) then
  5130. internalerror(2014010304);
  5131. result:=implprocdefinfo^.parentfpstruct;
  5132. end;
  5133. function tprocdef.GetParentFPStructPtrType: tdef;
  5134. begin
  5135. if not assigned(implprocdefinfo) then
  5136. internalerror(2014010305);
  5137. result:=implprocdefinfo^.parentfpstructptrtype;
  5138. end;
  5139. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  5140. begin
  5141. if not assigned(implprocdefinfo) then
  5142. internalerror(2014010306);
  5143. implprocdefinfo^.parentfpinitblock:=AValue;
  5144. end;
  5145. function tprocdef.Getprocendtai: tai;
  5146. begin
  5147. if not assigned(implprocdefinfo) then
  5148. internalerror(2014010307);
  5149. result:=implprocdefinfo^.procendtai;
  5150. end;
  5151. function tprocdef.Getprocstarttai: tai;
  5152. begin
  5153. if not assigned(implprocdefinfo) then
  5154. internalerror(2014010308);
  5155. result:=implprocdefinfo^.procstarttai;
  5156. end;
  5157. procedure tprocdef.Setprocendtai(AValue: tai);
  5158. begin
  5159. if not assigned(implprocdefinfo) then
  5160. internalerror(2014010309);
  5161. implprocdefinfo^.procendtai:=AValue;
  5162. end;
  5163. function tprocdef.Getskpara: pointer;
  5164. begin
  5165. if not assigned(implprocdefinfo) then
  5166. internalerror(2014010310);
  5167. result:=implprocdefinfo^.skpara;
  5168. end;
  5169. procedure tprocdef.Setskpara(AValue: pointer);
  5170. begin
  5171. if not assigned(implprocdefinfo) then
  5172. internalerror(2014010311);
  5173. implprocdefinfo^.skpara:=AValue;
  5174. end;
  5175. function tprocdef.Getpersonality: tprocdef;
  5176. begin
  5177. if not assigned(implprocdefinfo) then
  5178. internalerror(2016121701);
  5179. result:=implprocdefinfo^.personality;
  5180. end;
  5181. procedure tprocdef.Setpersonality(AValue: tprocdef);
  5182. begin
  5183. if not assigned(implprocdefinfo) then
  5184. internalerror(2016121702);
  5185. implprocdefinfo^.personality:=AValue;
  5186. end;
  5187. function tprocdef.Getforwarddef: boolean;
  5188. begin
  5189. if not assigned(implprocdefinfo) then
  5190. internalerror(2014010312);
  5191. result:=implprocdefinfo^.forwarddef;
  5192. end;
  5193. function tprocdef.Gethasforward: boolean;
  5194. begin
  5195. if not assigned(implprocdefinfo) then
  5196. internalerror(2014010313);
  5197. result:=implprocdefinfo^.hasforward;
  5198. end;
  5199. function tprocdef.Getinterfacedef: boolean;
  5200. begin
  5201. if not assigned(implprocdefinfo) then
  5202. internalerror(2014010314);
  5203. result:=implprocdefinfo^.interfacedef;
  5204. end;
  5205. procedure tprocdef.Setforwarddef(AValue: boolean);
  5206. begin
  5207. if not assigned(implprocdefinfo) then
  5208. internalerror(2014010315);
  5209. implprocdefinfo^.forwarddef:=AValue;
  5210. end;
  5211. procedure tprocdef.Sethasforward(AValue: boolean);
  5212. begin
  5213. if not assigned(implprocdefinfo) then
  5214. internalerror(2014010316);
  5215. implprocdefinfo^.hasforward:=AValue;
  5216. end;
  5217. function tprocdef.GetIsEmpty: boolean;
  5218. begin
  5219. result:=pio_empty in implprocoptions;
  5220. end;
  5221. procedure tprocdef.SetIsEmpty(AValue: boolean);
  5222. begin
  5223. if AValue then
  5224. include(implprocoptions,pio_empty)
  5225. else
  5226. include(implprocoptions,pio_empty);
  5227. end;
  5228. function tprocdef.GetHasInliningInfo: boolean;
  5229. begin
  5230. result:=pio_has_inlininginfo in implprocoptions;
  5231. end;
  5232. procedure tprocdef.SetHasInliningInfo(AValue: boolean);
  5233. begin
  5234. if AValue then
  5235. include(implprocoptions,pio_has_inlininginfo)
  5236. else
  5237. exclude(implprocoptions,pio_has_inlininginfo);
  5238. end;
  5239. procedure tprocdef.Setinterfacedef(AValue: boolean);
  5240. begin
  5241. if not assigned(implprocdefinfo) then
  5242. internalerror(2014010317);
  5243. implprocdefinfo^.interfacedef:=AValue;
  5244. end;
  5245. procedure tprocdef.Setprocstarttai(AValue: tai);
  5246. begin
  5247. if not assigned(implprocdefinfo) then
  5248. internalerror(2014010318);
  5249. implprocdefinfo^.procstarttai:=AValue;
  5250. end;
  5251. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  5252. begin
  5253. if not assigned(implprocdefinfo) then
  5254. internalerror(2014010319);
  5255. implprocdefinfo^.parentfpstruct:=AValue;
  5256. end;
  5257. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  5258. begin
  5259. if not assigned(implprocdefinfo) then
  5260. internalerror(2014010320);
  5261. implprocdefinfo^.parentfpstructptrtype:=AValue;
  5262. end;
  5263. constructor tprocdef.create(level:byte;doregister:boolean);
  5264. begin
  5265. inherited create(procdef,level,doregister);
  5266. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  5267. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  5268. {$ifdef symansistr}
  5269. _mangledname:='';
  5270. {$else symansistr}
  5271. _mangledname:=nil;
  5272. {$endif symansistr}
  5273. fileinfo:=current_filepos;
  5274. extnumber:=$ffff;
  5275. aliasnames:=TCmdStrList.create;
  5276. funcretsym:=nil;
  5277. funcretsymderef.reset;
  5278. procsymderef.reset;
  5279. forwarddef:=true;
  5280. interfacedef:=false;
  5281. hasforward:=false;
  5282. struct := nil;
  5283. structderef.reset;
  5284. import_dll:=nil;
  5285. import_name:=nil;
  5286. import_nr:=0;
  5287. inlininginfo:=nil;
  5288. deprecatedmsg:=nil;
  5289. end;
  5290. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  5291. var
  5292. i,aliasnamescount,sizeleft : longint;
  5293. level : byte;
  5294. buf : array[0..255] of byte;
  5295. begin
  5296. inherited ppuload(procdef,ppufile);
  5297. {$ifdef symansistr}
  5298. if po_has_mangledname in procoptions then
  5299. _mangledname:=ppufile.getansistring
  5300. else
  5301. _mangledname:='';
  5302. {$else symansistr}
  5303. if po_has_mangledname in procoptions then
  5304. _mangledname:=ppufile.getpshortstring
  5305. else
  5306. _mangledname:=nil;
  5307. {$endif symansistr}
  5308. extnumber:=ppufile.getword;
  5309. level:=ppufile.getbyte;
  5310. ppufile.getderef(structderef);
  5311. ppufile.getderef(procsymderef);
  5312. ppufile.getposinfo(fileinfo);
  5313. visibility:=tvisibility(ppufile.getbyte);
  5314. ppufile.getset(tppuset2(symoptions));
  5315. if sp_has_deprecated_msg in symoptions then
  5316. deprecatedmsg:=ppufile.getpshortstring
  5317. else
  5318. deprecatedmsg:=nil;
  5319. { import stuff }
  5320. if po_has_importdll in procoptions then
  5321. import_dll:=ppufile.getpshortstring
  5322. else
  5323. import_dll:=nil;
  5324. if po_has_importname in procoptions then
  5325. import_name:=ppufile.getpshortstring
  5326. else
  5327. import_name:=nil;
  5328. import_nr:=ppufile.getword;
  5329. if (po_msgint in procoptions) then
  5330. messageinf.i:=ppufile.getlongint;
  5331. if (po_msgstr in procoptions) then
  5332. messageinf.str:=ppufile.getpshortstring;
  5333. if (po_dispid in procoptions) then
  5334. dispid:=ppufile.getlongint;
  5335. { inline stuff }
  5336. ppufile.getset(tppuset1(implprocoptions));
  5337. if has_inlininginfo then
  5338. begin
  5339. ppufile.getderef(funcretsymderef);
  5340. new(inlininginfo);
  5341. ppufile.getset(tppuset4(inlininginfo^.flags));
  5342. end
  5343. else
  5344. begin
  5345. inlininginfo:=nil;
  5346. funcretsym:=nil;
  5347. end;
  5348. aliasnames:=TCmdStrList.create;
  5349. { count alias names }
  5350. aliasnamescount:=ppufile.getbyte;
  5351. for i:=1 to aliasnamescount do
  5352. aliasnames.insert(ppufile.getstring);
  5353. { load the token stream containing the declaration }
  5354. sizeleft:=ppufile.getlongint;
  5355. if sizeleft>0 then
  5356. begin
  5357. init_genericdecl;
  5358. while sizeleft>0 do
  5359. begin
  5360. if sizeleft>sizeof(buf) then
  5361. i:=sizeof(buf)
  5362. else
  5363. i:=sizeleft;
  5364. ppufile.getdata(buf,i);
  5365. genericdecltokenbuf.write(buf,i);
  5366. dec(sizeleft,i);
  5367. end;
  5368. end;
  5369. ppuload_platform(ppufile);
  5370. { load para symtable }
  5371. parast:=tparasymtable.create(self,level);
  5372. tparasymtable(parast).ppuload(ppufile);
  5373. { load local symtable }
  5374. if store_localst then
  5375. begin
  5376. localst:=tlocalsymtable.create(self,level);
  5377. tlocalsymtable(localst).ppuload(ppufile);
  5378. end
  5379. else
  5380. localst:=nil;
  5381. { inline stuff }
  5382. if has_inlininginfo then
  5383. inlininginfo^.code:=ppuloadnodetree(ppufile);
  5384. { default values for no persistent data }
  5385. if (cs_link_deffile in current_settings.globalswitches) and
  5386. (tf_need_export in target_info.flags) and
  5387. (po_exports in procoptions) then
  5388. deffile.AddExport(mangledname);
  5389. { Disable po_has_inlining until the derefimpl is done }
  5390. has_inlininginfo:=false;
  5391. end;
  5392. destructor tprocdef.destroy;
  5393. begin
  5394. aliasnames.free;
  5395. aliasnames:=nil;
  5396. if assigned(localst) and
  5397. (localst.symtabletype<>staticsymtable) then
  5398. begin
  5399. {$ifdef MEMDEBUG}
  5400. memproclocalst.start;
  5401. {$endif MEMDEBUG}
  5402. localst.free;
  5403. localst:=nil;
  5404. {$ifdef MEMDEBUG}
  5405. memproclocalst.start;
  5406. {$endif MEMDEBUG}
  5407. end;
  5408. if assigned(inlininginfo) then
  5409. begin
  5410. {$ifdef MEMDEBUG}
  5411. memprocnodetree.start;
  5412. {$endif MEMDEBUG}
  5413. tnode(inlininginfo^.code).free;
  5414. {$ifdef MEMDEBUG}
  5415. memprocnodetree.start;
  5416. {$endif MEMDEBUG}
  5417. dispose(inlininginfo);
  5418. inlininginfo:=nil;
  5419. end;
  5420. freeimplprocdefinfo;
  5421. genericdecltokenbuf.free;
  5422. genericdecltokenbuf:=nil;
  5423. stringdispose(import_dll);
  5424. stringdispose(import_name);
  5425. stringdispose(deprecatedmsg);
  5426. if (po_msgstr in procoptions) then
  5427. stringdispose(messageinf.str);
  5428. {$ifndef symansistr}
  5429. if assigned(_mangledname) then
  5430. begin
  5431. {$ifdef MEMDEBUG}
  5432. memmanglednames.start;
  5433. {$endif MEMDEBUG}
  5434. stringdispose(_mangledname);
  5435. {$ifdef MEMDEBUG}
  5436. memmanglednames.stop;
  5437. {$endif MEMDEBUG}
  5438. end;
  5439. {$endif symansistr}
  5440. inherited destroy;
  5441. end;
  5442. procedure tprocdef.freeimplprocdefinfo;
  5443. begin
  5444. if assigned(implprocdefinfo) then
  5445. begin
  5446. stringdispose(implprocdefinfo^.resultname);
  5447. freemem(implprocdefinfo);
  5448. implprocdefinfo:=nil;
  5449. end;
  5450. end;
  5451. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  5452. var
  5453. oldintfcrc : boolean;
  5454. aliasnamescount,i,sizeleft : longint;
  5455. item : TCmdStrListItem;
  5456. buf : array[0..255] of byte;
  5457. begin
  5458. { released procdef? }
  5459. if not assigned(parast) then
  5460. exit;
  5461. inherited ppuwrite(ppufile);
  5462. {$ifdef symansistr}
  5463. if po_has_mangledname in procoptions then
  5464. ppufile.putansistring(_mangledname);
  5465. {$else symansistr}
  5466. if po_has_mangledname in procoptions then
  5467. ppufile.putstring(_mangledname^);
  5468. {$endif symansistr}
  5469. ppufile.putword(extnumber);
  5470. ppufile.putbyte(parast.symtablelevel);
  5471. ppufile.putderef(structderef);
  5472. ppufile.putderef(procsymderef);
  5473. ppufile.putposinfo(fileinfo);
  5474. ppufile.putbyte(byte(visibility));
  5475. ppufile.putset(tppuset2(symoptions));
  5476. if sp_has_deprecated_msg in symoptions then
  5477. ppufile.putstring(deprecatedmsg^);
  5478. { import }
  5479. if po_has_importdll in procoptions then
  5480. ppufile.putstring(import_dll^);
  5481. if po_has_importname in procoptions then
  5482. ppufile.putstring(import_name^);
  5483. ppufile.putword(import_nr);
  5484. if (po_msgint in procoptions) then
  5485. ppufile.putlongint(messageinf.i);
  5486. if (po_msgstr in procoptions) then
  5487. ppufile.putstring(messageinf.str^);
  5488. if (po_dispid in procoptions) then
  5489. ppufile.putlongint(dispid);
  5490. { inline stuff }
  5491. oldintfcrc:=ppufile.do_crc;
  5492. ppufile.do_crc:=false;
  5493. ppufile.putset(tppuset1(implprocoptions));
  5494. if has_inlininginfo then
  5495. begin
  5496. ppufile.putderef(funcretsymderef);
  5497. ppufile.putset(tppuset4(inlininginfo^.flags));
  5498. end;
  5499. { count alias names }
  5500. aliasnamescount:=0;
  5501. item:=TCmdStrListItem(aliasnames.first);
  5502. while assigned(item) do
  5503. begin
  5504. inc(aliasnamescount);
  5505. item:=TCmdStrListItem(item.next);
  5506. end;
  5507. if aliasnamescount>255 then
  5508. internalerror(200711021);
  5509. ppufile.putbyte(aliasnamescount);
  5510. item:=TCmdStrListItem(aliasnames.first);
  5511. while assigned(item) do
  5512. begin
  5513. ppufile.putstring(item.str);
  5514. item:=TCmdStrListItem(item.next);
  5515. end;
  5516. ppufile.do_crc:=oldintfcrc;
  5517. { generic tokens for the declaration }
  5518. if assigned(genericdecltokenbuf) and (genericdecltokenbuf.size>0) then
  5519. begin
  5520. sizeleft:=genericdecltokenbuf.size;
  5521. genericdecltokenbuf.seek(0);
  5522. ppufile.putlongint(sizeleft);
  5523. while sizeleft>0 do
  5524. begin
  5525. if sizeleft>sizeof(buf) then
  5526. i:=sizeof(buf)
  5527. else
  5528. i:=sizeleft;
  5529. genericdecltokenbuf.read(buf,i);
  5530. ppufile.putdata(buf,i);
  5531. dec(sizeleft,i);
  5532. end;
  5533. end
  5534. else
  5535. ppufile.putlongint(0);
  5536. { write this entry }
  5537. writeentry(ppufile,ibprocdef);
  5538. { Save the para symtable, this is taken from the interface }
  5539. tparasymtable(parast).ppuwrite(ppufile);
  5540. { save localsymtable for inline procedures or when local
  5541. browser info is requested, this has no influence on the crc }
  5542. if store_localst and not ppufile.crc_only then
  5543. begin
  5544. oldintfcrc:=ppufile.do_crc;
  5545. ppufile.do_crc:=false;
  5546. tlocalsymtable(localst).ppuwrite(ppufile);
  5547. ppufile.do_crc:=oldintfcrc;
  5548. end;
  5549. { node tree for inlining }
  5550. oldintfcrc:=ppufile.do_crc;
  5551. ppufile.do_crc:=false;
  5552. if has_inlininginfo then
  5553. ppuwritenodetree(ppufile,inlininginfo^.code);
  5554. ppufile.do_crc:=oldintfcrc;
  5555. end;
  5556. function tprocdef.fullprocname(showhidden:boolean):string;
  5557. var
  5558. pno: tprocnameoptions;
  5559. begin
  5560. pno:=[];
  5561. if showhidden then
  5562. include(pno,pno_showhidden);
  5563. result:=customprocname(pno);
  5564. end;
  5565. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  5566. var
  5567. s, rn : ansistring;
  5568. t : ttoken;
  5569. syssym : tsyssym;
  5570. begin
  5571. {$ifdef EXTDEBUG}
  5572. include(pno,pno_showhidden);
  5573. {$endif EXTDEBUG}
  5574. s:='';
  5575. if proctypeoption=potype_operator then
  5576. begin
  5577. for t:=NOTOKEN to last_overloaded do
  5578. if procsym.realname='$'+overloaded_names[t] then
  5579. begin
  5580. s:='operator ';
  5581. if (pno_ownername in pno) and
  5582. assigned(struct) then
  5583. s:=s+struct.RttiName+'.';
  5584. s:=s+arraytokeninfo[t].str;
  5585. if not (pno_noparams in pno) then
  5586. s:=s+typename_paras(pno);
  5587. break;
  5588. end;
  5589. end
  5590. else
  5591. begin
  5592. if (po_classmethod in procoptions) and
  5593. not(pno_noclassmarker in pno) then
  5594. s:='class ';
  5595. case proctypeoption of
  5596. potype_constructor,
  5597. potype_class_constructor:
  5598. s:=s+'constructor ';
  5599. potype_class_destructor,
  5600. potype_destructor:
  5601. s:=s+'destructor ';
  5602. else
  5603. if (pno_proctypeoption in pno) then
  5604. begin
  5605. if assigned(returndef) and
  5606. not(is_void(returndef)) then
  5607. s:=s+'function '
  5608. else
  5609. s:=s+'procedure ';
  5610. end;
  5611. end;
  5612. if (pno_ownername in pno) and
  5613. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  5614. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  5615. if (po_compilerproc in procoptions) and (extnumber<>$ffff) then
  5616. begin
  5617. syssym:=tsyssym.find_by_number(extnumber);
  5618. if not assigned(syssym) then
  5619. internalerror(2016060305);
  5620. rn:=syssym.realname;
  5621. end
  5622. else
  5623. rn:=procsym.realname;
  5624. if (pno_noleadingdollar in pno) and
  5625. (rn[1]='$') then
  5626. delete(rn,1,1);
  5627. s:=s+rn;
  5628. if not (pno_noparams in pno) then
  5629. s:=s+typename_paras(pno);
  5630. end;
  5631. if not(proctypeoption in [potype_constructor,potype_destructor,
  5632. potype_class_constructor,potype_class_destructor]) and
  5633. assigned(returndef) and
  5634. not(is_void(returndef)) then
  5635. s:=s+':'+returndef.GetTypeName;
  5636. if assigned(owner) and (owner.symtabletype=localsymtable) then
  5637. s:=s+' is nested'
  5638. else if po_is_block in procoptions then
  5639. s:=s+' is block';
  5640. s:=s+';';
  5641. if po_far in procoptions then
  5642. s:=s+' far;';
  5643. { forced calling convention? }
  5644. if (po_hascallingconvention in procoptions) then
  5645. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  5646. if (po_staticmethod in procoptions) and
  5647. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  5648. s:=s+' Static;';
  5649. if pno_mangledname in pno then
  5650. s:=s+' -- mangled name: '+mangledname;
  5651. customprocname:=s;
  5652. end;
  5653. function tprocdef.is_methodpointer:boolean;
  5654. begin
  5655. { don't check assigned(_class), that's also the case for nested
  5656. procedures inside methods }
  5657. result:=(owner.symtabletype=ObjectSymtable)and not no_self_node;
  5658. end;
  5659. function tprocdef.is_addressonly:boolean;
  5660. begin
  5661. result:=assigned(owner) and
  5662. not is_methodpointer and
  5663. (not(m_nested_procvars in current_settings.modeswitches) or
  5664. not is_nested_pd(self));
  5665. end;
  5666. procedure tprocdef.make_external;
  5667. begin
  5668. include(procoptions,po_external);
  5669. forwarddef:=false;
  5670. end;
  5671. procedure tprocdef.init_genericdecl;
  5672. begin
  5673. if assigned(genericdecltokenbuf) then
  5674. internalerror(2015061901);
  5675. genericdecltokenbuf:=tdynamicarray.create(256);
  5676. end;
  5677. function tprocdef.get_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  5678. begin
  5679. result:=false;
  5680. if proctypeoption=potype_constructor then
  5681. begin
  5682. result:=true;
  5683. ressym:=tsym(parast.Find('self'));
  5684. resdef:=tabstractnormalvarsym(ressym).vardef;
  5685. { and TP-style constructors return a pointer to self }
  5686. if is_object(resdef) then
  5687. resdef:=cpointerdef.getreusable(resdef);
  5688. end
  5689. else if (proccalloption=pocall_safecall) and
  5690. (tf_safecall_exceptions in target_info.flags) then
  5691. begin
  5692. result:=true;
  5693. ressym:=tsym(localst.Find('safecallresult'));
  5694. resdef:=tabstractnormalvarsym(ressym).vardef;
  5695. end
  5696. else if not is_void(returndef) then
  5697. begin
  5698. result:=true;
  5699. ressym:=funcretsym;
  5700. resdef:=tabstractnormalvarsym(ressym).vardef;
  5701. end;
  5702. end;
  5703. function tprocdef.get_safecall_funcretsym_info(out ressym: tsym; out resdef: tdef): boolean;
  5704. begin
  5705. result:=false;
  5706. if (proctypeoption<>potype_constructor) and
  5707. (proccalloption=pocall_safecall) and
  5708. (tf_safecall_exceptions in target_info.flags) then
  5709. begin
  5710. result:=true;
  5711. ressym:=tsym(localst.Find('safecallresult'));
  5712. resdef:=tabstractnormalvarsym(ressym).vardef;
  5713. end
  5714. end;
  5715. function tprocdef.has_alias_name(const s: TSymStr): boolean;
  5716. var
  5717. item : TCmdStrListItem;
  5718. begin
  5719. result:=true;
  5720. if mangledname=s then
  5721. exit;
  5722. item:=TCmdStrListItem(aliasnames.first);
  5723. while assigned(item) do
  5724. begin
  5725. if item.str=s then
  5726. exit;
  5727. item:=TCmdStrListItem(item.next);
  5728. end;
  5729. result:=false;
  5730. end;
  5731. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  5732. begin
  5733. case t of
  5734. gs_local :
  5735. GetSymtable:=localst;
  5736. gs_para :
  5737. GetSymtable:=parast;
  5738. else
  5739. GetSymtable:=nil;
  5740. end;
  5741. end;
  5742. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string): tstoreddef;
  5743. var
  5744. j : longint;
  5745. begin
  5746. result:=inherited;
  5747. if newtyp=procvardef then
  5748. begin
  5749. { create new paralist }
  5750. tprocvardef(result).calcparas;
  5751. exit;
  5752. end;
  5753. { don't copy mangled name, can be different }
  5754. tprocdef(result).messageinf:=messageinf;
  5755. tprocdef(result).dispid:=dispid;
  5756. if po_msgstr in procoptions then
  5757. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  5758. tprocdef(result).symoptions:=symoptions;
  5759. if assigned(deprecatedmsg) then
  5760. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  5761. { will have to be associated with appropriate procsym }
  5762. tprocdef(result).procsym:=nil;
  5763. { don't create aliases for bare copies, nor copy the funcretsym as
  5764. the function result parameter will be inserted again if necessary
  5765. (e.g. if the calling convention is changed) }
  5766. if not(copytyp in [pc_bareproc,pc_normal_no_hidden]) then
  5767. begin
  5768. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  5769. if assigned(funcretsym) then
  5770. begin
  5771. if funcretsym.owner=parast then
  5772. begin
  5773. j:=parast.symlist.indexof(funcretsym);
  5774. if j<0 then
  5775. internalerror(2011040606);
  5776. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  5777. end
  5778. else if funcretsym.owner=localst then
  5779. begin
  5780. { nothing to do, will be inserted for the new procdef while
  5781. parsing its body (by pdecsub.insert_funcret_local) }
  5782. end
  5783. else
  5784. internalerror(2011040605);
  5785. end;
  5786. end;
  5787. { will have to be associated with a new struct }
  5788. tprocdef(result).struct:=nil;
  5789. if assigned(implprocdefinfo) then
  5790. begin
  5791. if assigned(resultname) then
  5792. tprocdef(result).resultname:=stringdup(resultname^);
  5793. tprocdef(result).synthetickind:=synthetickind;
  5794. end;
  5795. if assigned(import_dll) then
  5796. tprocdef(result).import_dll:=stringdup(import_dll^);
  5797. if assigned(import_name) then
  5798. tprocdef(result).import_name:=stringdup(import_name^);
  5799. tprocdef(result).import_nr:=import_nr;
  5800. tprocdef(result).extnumber:=$ffff;
  5801. tprocdef(result).visibility:=visibility;
  5802. { we need a separate implementation for the copied def }
  5803. tprocdef(result).forwarddef:=true;
  5804. tprocdef(result).interfacedef:=true;
  5805. { create new paralist }
  5806. tprocdef(result).calcparas;
  5807. end;
  5808. function tprocdef.getcopy: tstoreddef;
  5809. begin
  5810. result:=getcopyas(procdef,pc_normal,'');
  5811. end;
  5812. procedure tprocdef.buildderef;
  5813. begin
  5814. inherited buildderef;
  5815. structderef.build(struct);
  5816. { procsym that originaly defined this definition, should be in the
  5817. same symtable }
  5818. procsymderef.build(procsym);
  5819. end;
  5820. procedure tprocdef.buildderefimpl;
  5821. begin
  5822. inherited buildderefimpl;
  5823. { Localst is not available for main/unit init }
  5824. if store_localst and assigned(localst) then
  5825. begin
  5826. tlocalsymtable(localst).buildderef;
  5827. tlocalsymtable(localst).buildderefimpl;
  5828. end;
  5829. { inline tree }
  5830. if has_inlininginfo then
  5831. begin
  5832. funcretsymderef.build(funcretsym);
  5833. inlininginfo^.code.buildderefimpl;
  5834. end;
  5835. end;
  5836. procedure tprocdef.deref;
  5837. begin
  5838. inherited deref;
  5839. struct:=tabstractrecorddef(structderef.resolve);
  5840. { procsym that originaly defined this definition, should be in the
  5841. same symtable }
  5842. procsym:=tprocsym(procsymderef.resolve);
  5843. end;
  5844. procedure tprocdef.derefimpl;
  5845. begin
  5846. { Enable has_inlininginfo when the inlininginfo
  5847. structure is available. The has_inlininginfo was disabled
  5848. after the load, since the data was invalid }
  5849. if assigned(inlininginfo) then
  5850. has_inlininginfo:=true;
  5851. { Locals }
  5852. if store_localst and assigned(localst) then
  5853. begin
  5854. tlocalsymtable(localst).deref(false);
  5855. tlocalsymtable(localst).derefimpl(false);
  5856. end;
  5857. { Inline }
  5858. if has_inlininginfo then
  5859. begin
  5860. inlininginfo^.code.derefimpl;
  5861. { funcretsym, this is always located in the localst }
  5862. funcretsym:=tsym(funcretsymderef.resolve);
  5863. end
  5864. else
  5865. begin
  5866. { safety }
  5867. { Not safe! A unit may be reresolved after its interface has been
  5868. parsed but before its implementation has been parsed, and in that
  5869. case the funcretsym is still required!
  5870. funcretsym:=nil; }
  5871. end;
  5872. end;
  5873. function tprocdef.GetTypeName : string;
  5874. begin
  5875. GetTypeName := FullProcName(false);
  5876. end;
  5877. function tprocdef.mangledname : TSymStr;
  5878. begin
  5879. {$ifdef symansistr}
  5880. if _mangledname='' then
  5881. begin
  5882. result:=defaultmangledname;
  5883. _mangledname:=result;
  5884. end
  5885. else
  5886. result:=_mangledname;
  5887. {$else symansistr}
  5888. if not assigned(_mangledname) then
  5889. begin
  5890. result:=defaultmangledname;
  5891. _mangledname:=stringdup(mangledname);
  5892. end
  5893. else
  5894. result:=_mangledname^;
  5895. {$endif symansistr}
  5896. end;
  5897. function tprocdef.defaultmangledname: TSymStr;
  5898. begin
  5899. { we need to use the symtable where the procsym is inserted,
  5900. because that is visible to the world }
  5901. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  5902. defaultmangledname:=defaultmangledname+mangledprocparanames(Length(defaultmangledname))
  5903. end;
  5904. function tprocdef.cplusplusmangledname : TSymStr;
  5905. function getcppparaname(p : tdef) : TSymStr;
  5906. const
  5907. {$ifdef NAMEMANGLING_GCC2}
  5908. ordtype2str : array[tordtype] of string[2] = (
  5909. '',
  5910. 'Uc','Us','Ui','Us','',
  5911. 'Sc','s','i','x','',
  5912. 'b','b','b','b','b','b',
  5913. 'c','w','x');
  5914. {$else NAMEMANGLING_GCC2}
  5915. ordtype2str : array[tordtype] of string[1] = (
  5916. 'v',
  5917. 'h','t','j','y','',
  5918. 'a','s','i','x','',
  5919. 'b','b','b','b','b',
  5920. 'b','b','b','b',
  5921. 'c','w','x','C');
  5922. floattype2str : array[tfloattype] of string[1] = (
  5923. 'f','d','e','e',
  5924. 'd','d','g');
  5925. {$endif NAMEMANGLING_GCC2}
  5926. var
  5927. s : TSymStr;
  5928. begin
  5929. case p.typ of
  5930. orddef:
  5931. begin
  5932. s:=ordtype2str[torddef(p).ordtype];
  5933. if s='C' then
  5934. s:=ordtype2str[range_to_basetype(torddef(p).low,torddef(p).high)];
  5935. end;
  5936. pointerdef:
  5937. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  5938. {$ifndef NAMEMANGLING_GCC2}
  5939. floatdef:
  5940. s:=floattype2str[tfloatdef(p).floattype];
  5941. {$endif NAMEMANGLING_GCC2}
  5942. else
  5943. internalerror(2103001);
  5944. end;
  5945. getcppparaname:=s;
  5946. end;
  5947. var
  5948. s,s2 : TSymStr;
  5949. hp : TParavarsym;
  5950. i : integer;
  5951. begin
  5952. {$ifdef NAMEMANGLING_GCC2}
  5953. { outdated gcc 2.x name mangling scheme }
  5954. s := procsym.realname;
  5955. if procsym.owner.symtabletype=ObjectSymtable then
  5956. begin
  5957. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  5958. case proctypeoption of
  5959. potype_destructor:
  5960. s:='_$_'+tostr(length(s2))+s2;
  5961. potype_constructor:
  5962. s:='___'+tostr(length(s2))+s2;
  5963. else
  5964. s:='_'+s+'__'+tostr(length(s2))+s2;
  5965. end;
  5966. end
  5967. else s:=s+'__';
  5968. s:=s+'F';
  5969. { concat modifiers }
  5970. { !!!!! }
  5971. { now we handle the parameters }
  5972. if maxparacount>0 then
  5973. begin
  5974. for i:=0 to paras.count-1 do
  5975. begin
  5976. hp:=tparavarsym(paras[i]);
  5977. { no hidden parameters form part of a C++ mangled name:
  5978. a) self is not included
  5979. b) there are no "high" or other hidden parameters
  5980. }
  5981. if vo_is_hidden_para in hp.varoptions then
  5982. continue;
  5983. s2:=getcppparaname(hp.vardef);
  5984. if hp.varspez in [vs_var,vs_out] then
  5985. s2:='R'+s2;
  5986. s:=s+s2;
  5987. end;
  5988. end
  5989. else
  5990. s:=s+'v';
  5991. cplusplusmangledname:=s;
  5992. {$else NAMEMANGLING_GCC2}
  5993. { gcc 3.x and 4.x name mangling scheme }
  5994. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  5995. if procsym.owner.symtabletype=ObjectSymtable then
  5996. begin
  5997. s:='_ZN';
  5998. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  5999. s:=s+tostr(length(s2))+s2;
  6000. case proctypeoption of
  6001. potype_constructor:
  6002. s:=s+'C1';
  6003. potype_destructor:
  6004. s:=s+'D1';
  6005. else
  6006. s:=s+tostr(length(procsym.realname))+procsym.realname;
  6007. end;
  6008. s:=s+'E';
  6009. end
  6010. else
  6011. s:=procsym.realname;
  6012. { now we handle the parameters }
  6013. if maxparacount>0 then
  6014. begin
  6015. for i:=0 to paras.count-1 do
  6016. begin
  6017. hp:=tparavarsym(paras[i]);
  6018. { no hidden parameters form part of a C++ mangled name:
  6019. a) self is not included
  6020. b) there are no "high" or other hidden parameters
  6021. }
  6022. if vo_is_hidden_para in hp.varoptions then
  6023. continue;
  6024. s2:=getcppparaname(hp.vardef);
  6025. if hp.varspez in [vs_var,vs_out] then
  6026. s2:='R'+s2;
  6027. s:=s+s2;
  6028. end;
  6029. end
  6030. else
  6031. s:=s+'v';
  6032. cplusplusmangledname:=s;
  6033. {$endif NAMEMANGLING_GCC2}
  6034. end;
  6035. function tprocdef.objcmangledname : TSymStr;
  6036. var
  6037. manglednamelen: longint;
  6038. iscatmethod : boolean;
  6039. begin
  6040. if not (po_msgstr in procoptions) then
  6041. internalerror(2009030901);
  6042. { we may very well need longer strings to handle these... }
  6043. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  6044. length('+"[ ]"')+length(messageinf.str^);
  6045. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  6046. if (iscatmethod) then
  6047. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  6048. if manglednamelen>255 then
  6049. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  6050. if not(po_classmethod in procoptions) then
  6051. result:='"-['
  6052. else
  6053. result:='"+[';
  6054. { quotes are necessary because the +/- otherwise confuse the assembler
  6055. into expecting a number
  6056. }
  6057. if iscatmethod then
  6058. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  6059. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  6060. if iscatmethod then
  6061. result:=result+')';
  6062. result:=result+' '+messageinf.str^+']"';
  6063. end;
  6064. procedure tprocdef.setmangledname(const s : TSymStr);
  6065. begin
  6066. { This is not allowed anymore, the forward declaration
  6067. already needs to create the correct mangledname, no changes
  6068. afterwards are allowed (PFV) }
  6069. { Exception: interface definitions in mode macpas, since in that }
  6070. { case no reference to the old name can exist yet (JM) }
  6071. {$ifdef symansistr}
  6072. if _mangledname<>'' then
  6073. if ((m_mac in current_settings.modeswitches) and
  6074. (interfacedef)) then
  6075. _mangledname:=''
  6076. else
  6077. internalerror(200411171);
  6078. {$else symansistr}
  6079. if assigned(_mangledname) then
  6080. if ((m_mac in current_settings.modeswitches) and
  6081. (interfacedef)) then
  6082. stringdispose(_mangledname)
  6083. else
  6084. internalerror(200411171);
  6085. {$endif symansistr}
  6086. {$ifdef jvm}
  6087. { this routine can be called for compilerproces. can't set mangled
  6088. name since it must be calculated, but it uses import_name when set
  6089. -> set that one }
  6090. import_name:=stringdup(s);
  6091. include(procoptions,po_has_importname);
  6092. include(procoptions,po_has_mangledname);
  6093. {$else}
  6094. {$ifdef symansistr}
  6095. _mangledname:=s;
  6096. {$else symansistr}
  6097. _mangledname:=stringdup(s);
  6098. {$endif symansistr}
  6099. {$endif jvm}
  6100. include(procoptions,po_has_mangledname);
  6101. end;
  6102. function tprocdef.needsglobalasmsym: boolean;
  6103. begin
  6104. result:=
  6105. (cs_profile in current_settings.moduleswitches) or
  6106. { smart linking using a library requires to promote
  6107. all non-nested procedures to AB_GLOBAL
  6108. otherwise you get undefined symbol error at linking
  6109. for msdos target with -CX option for instance }
  6110. (create_smartlink_library and not is_nested_pd(self)) or
  6111. (po_global in procoptions);
  6112. end;
  6113. procedure tprocdef.setcompilerprocname;
  6114. begin
  6115. procsym.realname:='$'+lower(procsym.name);
  6116. end;
  6117. {***************************************************************************
  6118. TPROCVARDEF
  6119. ***************************************************************************}
  6120. constructor tprocvardef.create(level:byte);
  6121. begin
  6122. inherited create(procvardef,level,true);
  6123. end;
  6124. class function tprocvardef.getreusableprocaddr(def: tabstractprocdef): tprocvardef;
  6125. var
  6126. res: PHashSetItem;
  6127. oldsymtablestack: tsymtablestack;
  6128. begin
  6129. if not assigned(current_module) then
  6130. internalerror(2011081301);
  6131. res:=current_module.procaddrdefs.FindOrAdd(@def,sizeof(def));
  6132. if not assigned(res^.Data) then
  6133. begin
  6134. { since these pointerdefs can be reused anywhere in the current
  6135. unit, add them to the global/staticsymtable (or local symtable
  6136. if they're a local def, because otherwise they'll be saved
  6137. to the ppu referencing a local symtable entry that doesn't
  6138. exist in the ppu) }
  6139. oldsymtablestack:=symtablestack;
  6140. { do not simply push/pop current_module.localsymtable, because
  6141. that can have side-effects (e.g., it removes helpers) }
  6142. symtablestack:=nil;
  6143. result:=tprocvardef(def.getcopyas(procvardef,pc_address_only,''));
  6144. setup_reusable_def(def,result,res,oldsymtablestack);
  6145. { res^.Data may still be nil -> don't overwrite result }
  6146. exit;
  6147. end;
  6148. result:=tprocvardef(res^.Data);
  6149. end;
  6150. class function tprocvardef.getreusableprocaddr_no_free(def: tabstractprocdef): tprocvardef;
  6151. begin
  6152. result:=getreusableprocaddr(def);
  6153. if not result.is_registered then
  6154. include(result.defoptions,df_not_registered_no_free);
  6155. end;
  6156. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  6157. begin
  6158. inherited ppuload(procvardef,ppufile);
  6159. { load para symtable }
  6160. parast:=tparasymtable.create(self,ppufile.getbyte);
  6161. ppuload_platform(ppufile);
  6162. tparasymtable(parast).ppuload(ppufile);
  6163. end;
  6164. function tprocvardef.getcopy : tstoreddef;
  6165. var
  6166. i : tcallercallee;
  6167. j : longint;
  6168. begin
  6169. result:=cprocvardef.create(parast.symtablelevel);
  6170. tprocvardef(result).returndef:=returndef;
  6171. tprocvardef(result).returndefderef:=returndefderef;
  6172. tprocvardef(result).parast:=parast.getcopy;
  6173. tprocvardef(result).savesize:=savesize;
  6174. { create paralist copy }
  6175. calcparas;
  6176. tprocvardef(result).paras:=tparalist.create(false);
  6177. tprocvardef(result).paras.count:=paras.count;
  6178. for j:=0 to paras.count-1 do
  6179. tprocvardef(result).paras[j]:=paras[j];
  6180. tprocvardef(result).proctypeoption:=proctypeoption;
  6181. tprocvardef(result).proccalloption:=proccalloption;
  6182. tprocvardef(result).procoptions:=procoptions;
  6183. tprocvardef(result).callerargareasize:=callerargareasize;
  6184. tprocvardef(result).calleeargareasize:=calleeargareasize;
  6185. tprocvardef(result).maxparacount:=maxparacount;
  6186. tprocvardef(result).minparacount:=minparacount;
  6187. for i:=low(funcretloc) to high(funcretloc) do
  6188. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  6189. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  6190. {$ifdef m68k}
  6191. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  6192. {$endif}
  6193. end;
  6194. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  6195. begin
  6196. inherited ppuwrite(ppufile);
  6197. { Save the para symtable level (necessary to distinguish nested
  6198. procvars) }
  6199. ppufile.putbyte(parast.symtablelevel);
  6200. { Write this entry }
  6201. writeentry(ppufile,ibprocvardef);
  6202. { Save the para symtable, this is taken from the interface }
  6203. tparasymtable(parast).ppuwrite(ppufile);
  6204. end;
  6205. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  6206. begin
  6207. case t of
  6208. gs_para :
  6209. GetSymtable:=parast;
  6210. else
  6211. GetSymtable:=nil;
  6212. end;
  6213. end;
  6214. function tprocvardef.size : asizeint;
  6215. begin
  6216. { we return false for is_addressonly for a block (because it's not a
  6217. simple pointer to a function), but they are handled as implicit
  6218. pointers to a datastructure that contains everything ->
  6219. voidpointertype.size instead of voidcodepointertype.size }
  6220. if po_is_block in procoptions then
  6221. size:=voidpointertype.size
  6222. else if not is_addressonly then
  6223. begin
  6224. if is_nested_pd(self) then
  6225. size:=voidcodepointertype.size+parentfpvoidpointertype.size
  6226. else
  6227. size:=voidcodepointertype.size+voidpointertype.size;
  6228. end
  6229. else
  6230. size:=voidcodepointertype.size;
  6231. end;
  6232. function tprocvardef.is_methodpointer:boolean;
  6233. begin
  6234. result:=(po_methodpointer in procoptions);
  6235. end;
  6236. function tprocvardef.is_addressonly:boolean;
  6237. begin
  6238. result:=((not(po_methodpointer in procoptions) or (po_staticmethod in procoptions)) and
  6239. not(po_is_block in procoptions) and
  6240. not is_nested_pd(self)) or
  6241. (po_addressonly in procoptions);
  6242. end;
  6243. function tprocvardef.getmangledparaname:TSymStr;
  6244. begin
  6245. if not(po_methodpointer in procoptions) then
  6246. if not is_nested_pd(self) then
  6247. result:='procvar'
  6248. else
  6249. { we need the manglednames here, because nestedprocvars can be anonymous, e.g.
  6250. having not a type name or not an unique one, see webtbs/tw27515.pp
  6251. Further, use $_ ... _$ delimiters to avoid ambiguous names, see webtbs/tw27515.pp }
  6252. result:='$_nestedprovar'+mangledprocparanames(0)+'_$'
  6253. else
  6254. result:='procvarofobj'
  6255. end;
  6256. function tprocvardef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp; const paraprefix: string): tstoreddef;
  6257. begin
  6258. result:=inherited;
  6259. tabstractprocdef(result).calcparas;
  6260. end;
  6261. function tprocvardef.is_publishable : boolean;
  6262. begin
  6263. is_publishable:=(po_methodpointer in procoptions);
  6264. end;
  6265. function tprocvardef.GetTypeName : string;
  6266. var
  6267. s: string;
  6268. pno : tprocnameoptions;
  6269. begin
  6270. {$ifdef EXTDEBUG}
  6271. pno:=[pno_showhidden];
  6272. {$else EXTDEBUG}
  6273. pno:=[];
  6274. {$endif EXTDEBUG}
  6275. s:='<';
  6276. if po_is_block in procoptions then
  6277. s := s+'reference to'
  6278. else if po_classmethod in procoptions then
  6279. s := s+'class method type of'
  6280. else
  6281. if po_addressonly in procoptions then
  6282. s := s+'address of'
  6283. else
  6284. s := s+'procedure variable type of';
  6285. if assigned(returndef) and
  6286. (returndef<>voidtype) then
  6287. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  6288. else
  6289. s:=s+' procedure'+typename_paras(pno);
  6290. if po_methodpointer in procoptions then
  6291. s := s+' of object';
  6292. if is_nested_pd(self) then
  6293. s := s+' is nested';
  6294. if po_far in procoptions then
  6295. s := s+';far';
  6296. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  6297. end;
  6298. {***************************************************************************
  6299. TOBJECTDEF
  6300. ***************************************************************************}
  6301. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef;doregister:boolean);
  6302. begin
  6303. inherited create(n,objectdef,doregister);
  6304. fcurrent_dispid:=0;
  6305. objecttype:=ot;
  6306. childof:=nil;
  6307. childofderef.reset;
  6308. vmt_fieldderef.reset;
  6309. extendeddefderef.reset;
  6310. cloneddefderef.reset;
  6311. if objecttype=odt_helper then
  6312. owner.includeoption(sto_has_helper);
  6313. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords,
  6314. current_settings.alignment.recordalignmin);
  6315. { create space for vmt !! }
  6316. vmtentries:=TFPList.Create;
  6317. set_parent(c);
  6318. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  6319. prepareguid;
  6320. { setup implemented interfaces }
  6321. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  6322. ImplementedInterfaces:=TFPObjectList.Create(true)
  6323. else
  6324. ImplementedInterfaces:=nil;
  6325. writing_class_record_dbginfo:=false;
  6326. end;
  6327. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  6328. var
  6329. i,
  6330. implintfcount : longint;
  6331. d, getterd : tderef;
  6332. ImplIntf : TImplementedInterface;
  6333. vmtentry : pvmtentry;
  6334. begin
  6335. inherited ppuload(objectdef,ppufile);
  6336. objecttype:=tobjecttyp(ppufile.getbyte);
  6337. helpertype:=thelpertype(ppufile.getbyte);
  6338. objextname:=ppufile.getpshortstring;
  6339. { only used for external Objective-C classes/protocols }
  6340. if (objextname^='') then
  6341. stringdispose(objextname);
  6342. symtable:=tObjectSymtable.create(self,objrealname^,0,0);
  6343. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  6344. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  6345. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  6346. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  6347. tObjectSymtable(symtable).recordalignmin:=shortint(ppufile.getbyte);
  6348. ppufile.getderef(vmt_fieldderef);
  6349. ppufile.getderef(childofderef);
  6350. { load guid }
  6351. iidstr:=nil;
  6352. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  6353. begin
  6354. new(iidguid);
  6355. ppufile.getguid(iidguid^);
  6356. iidstr:=ppufile.getpshortstring;
  6357. end;
  6358. abstractcnt:=ppufile.getlongint;
  6359. if objecttype=odt_helper then
  6360. ppufile.getderef(extendeddefderef);
  6361. vmtentries:=TFPList.Create;
  6362. vmtentries.count:=ppufile.getlongint;
  6363. for i:=0 to vmtentries.count-1 do
  6364. begin
  6365. ppufile.getderef(d);
  6366. new(vmtentry);
  6367. vmtentry^.procdef:=nil;
  6368. vmtentry^.procdefderef:=d;
  6369. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  6370. vmtentries[i]:=vmtentry;
  6371. end;
  6372. { load implemented interfaces }
  6373. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  6374. begin
  6375. ImplementedInterfaces:=TFPObjectList.Create(true);
  6376. implintfcount:=ppufile.getlongint;
  6377. for i:=0 to implintfcount-1 do
  6378. begin
  6379. ppufile.getderef(d);
  6380. ppufile.getderef(getterd);
  6381. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  6382. ImplIntf.IOffset:=ppufile.getlongint;
  6383. byte(ImplIntf.IType):=ppufile.getbyte;
  6384. ImplementedInterfaces.Add(ImplIntf);
  6385. end;
  6386. end
  6387. else
  6388. ImplementedInterfaces:=nil;
  6389. if df_copied_def in defoptions then
  6390. begin
  6391. ppufile.getderef(cloneddefderef);
  6392. ppuload_platform(ppufile);
  6393. end
  6394. else
  6395. begin
  6396. ppuload_platform(ppufile);
  6397. tObjectSymtable(symtable).ppuload(ppufile);
  6398. end;
  6399. { handles the predefined class tobject }
  6400. { the last TOBJECT which is loaded gets }
  6401. { it ! }
  6402. if (childof=nil) and
  6403. (objecttype in [odt_class,odt_javaclass]) and
  6404. (objname^='TOBJECT') then
  6405. class_tobject:=self;
  6406. if (childof=nil) and
  6407. (objecttype=odt_interfacecom) then
  6408. if (objname^='IUNKNOWN') then
  6409. interface_iunknown:=self
  6410. else
  6411. if (objname^='IDISPATCH') then
  6412. interface_idispatch:=self;
  6413. if (childof=nil) and
  6414. (objecttype=odt_objcclass) and
  6415. (objname^='PROTOCOL') then
  6416. objc_protocoltype:=self;
  6417. if (objecttype=odt_javaclass) and
  6418. not(oo_is_formal in objectoptions) then
  6419. begin
  6420. if (objname^='JLOBJECT') then
  6421. java_jlobject:=self
  6422. else if (objname^='JLTHROWABLE') then
  6423. java_jlthrowable:=self
  6424. else if (objname^='FPCBASERECORDTYPE') then
  6425. java_fpcbaserecordtype:=self
  6426. else if (objname^='JLSTRING') then
  6427. java_jlstring:=self
  6428. else if (objname^='ANSISTRINGCLASS') then
  6429. java_ansistring:=self
  6430. else if (objname^='SHORTSTRINGCLASS') then
  6431. java_shortstring:=self
  6432. else if (objname^='JLENUM') then
  6433. java_jlenum:=self
  6434. else if (objname^='JUENUMSET') then
  6435. java_juenumset:=self
  6436. else if (objname^='FPCBITSET') then
  6437. java_jubitset:=self
  6438. else if (objname^='FPCBASEPROCVARTYPE') then
  6439. java_procvarbase:=self;
  6440. end;
  6441. writing_class_record_dbginfo:=false;
  6442. end;
  6443. destructor tobjectdef.destroy;
  6444. var
  6445. i: longint;
  6446. begin
  6447. if assigned(symtable) then
  6448. begin
  6449. symtable.free;
  6450. symtable:=nil;
  6451. end;
  6452. stringdispose(objextname);
  6453. stringdispose(iidstr);
  6454. if assigned(ImplementedInterfaces) then
  6455. begin
  6456. ImplementedInterfaces.free;
  6457. ImplementedInterfaces:=nil;
  6458. end;
  6459. if assigned(iidguid) then
  6460. begin
  6461. dispose(iidguid);
  6462. iidguid:=nil;
  6463. end;
  6464. if assigned(vmtentries) then
  6465. begin
  6466. for i:=0 to vmtentries.count-1 do
  6467. dispose(pvmtentry(vmtentries[i]));
  6468. vmtentries.free;
  6469. vmtentries:=nil;
  6470. end;
  6471. if assigned(vmcallstaticinfo) then
  6472. begin
  6473. freemem(vmcallstaticinfo);
  6474. vmcallstaticinfo:=nil;
  6475. end;
  6476. inherited destroy;
  6477. end;
  6478. function tobjectdef.getcopy : tstoreddef;
  6479. var
  6480. i : longint;
  6481. begin
  6482. result:=cobjectdef.create(objecttype,objrealname^,childof,true);
  6483. { the constructor allocates a symtable which we release to avoid memory leaks }
  6484. tobjectdef(result).symtable.free;
  6485. tobjectdef(result).symtable:=symtable.getcopy;
  6486. if assigned(objextname) then
  6487. tobjectdef(result).objextname:=stringdup(objextname^);
  6488. if assigned(import_lib) then
  6489. tobjectdef(result).import_lib:=stringdup(import_lib^);
  6490. tobjectdef(result).objectoptions:=objectoptions;
  6491. include(tobjectdef(result).defoptions,df_copied_def);
  6492. tobjectdef(result).extendeddef:=extendeddef;
  6493. if assigned(tcinitcode) then
  6494. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  6495. tobjectdef(result).vmt_field:=vmt_field;
  6496. if assigned(iidguid) then
  6497. begin
  6498. new(tobjectdef(result).iidguid);
  6499. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  6500. end;
  6501. if assigned(iidstr) then
  6502. tobjectdef(result).iidstr:=stringdup(iidstr^);
  6503. tobjectdef(result).abstractcnt:=abstractcnt;
  6504. if assigned(ImplementedInterfaces) then
  6505. begin
  6506. for i:=0 to ImplementedInterfaces.count-1 do
  6507. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  6508. end;
  6509. tobjectdef(result).copyvmtentries(self);
  6510. end;
  6511. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  6512. var
  6513. i : longint;
  6514. vmtentry : pvmtentry;
  6515. ImplIntf : TImplementedInterface;
  6516. old_do_indirect_crc: boolean;
  6517. begin
  6518. { if class1 in unit A changes, and class2 in unit B inherits from it
  6519. (so unit B uses unit A), then unit B with class2 will be recompiled.
  6520. However, if there is also a class3 in unit C that only depends on
  6521. unit B, then unit C will not be recompiled because nothing changed
  6522. to the interface of unit B. Nevertheless, unit C can indirectly
  6523. depend on unit A via derefs, and these must be updated -> the
  6524. indirect crc keeps track of such changes. }
  6525. old_do_indirect_crc:=ppufile.do_indirect_crc;
  6526. ppufile.do_indirect_crc:=true;
  6527. inherited ppuwrite(ppufile);
  6528. ppufile.putbyte(byte(objecttype));
  6529. ppufile.putbyte(byte(helpertype));
  6530. if assigned(objextname) then
  6531. ppufile.putstring(objextname^)
  6532. else
  6533. ppufile.putstring('');
  6534. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  6535. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  6536. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  6537. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  6538. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignmin));
  6539. ppufile.putderef(vmt_fieldderef);
  6540. ppufile.putderef(childofderef);
  6541. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  6542. begin
  6543. ppufile.putguid(iidguid^);
  6544. ppufile.putstring(iidstr^);
  6545. end;
  6546. ppufile.putlongint(abstractcnt);
  6547. if objecttype=odt_helper then
  6548. ppufile.putderef(extendeddefderef);
  6549. ppufile.putlongint(vmtentries.count);
  6550. for i:=0 to vmtentries.count-1 do
  6551. begin
  6552. vmtentry:=pvmtentry(vmtentries[i]);
  6553. ppufile.putderef(vmtentry^.procdefderef);
  6554. ppufile.putbyte(byte(vmtentry^.visibility));
  6555. end;
  6556. if assigned(ImplementedInterfaces) then
  6557. begin
  6558. ppufile.putlongint(ImplementedInterfaces.Count);
  6559. for i:=0 to ImplementedInterfaces.Count-1 do
  6560. begin
  6561. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  6562. ppufile.putderef(ImplIntf.intfdefderef);
  6563. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  6564. ppufile.putlongint(ImplIntf.Ioffset);
  6565. ppufile.putbyte(byte(ImplIntf.IType));
  6566. end;
  6567. end;
  6568. if df_copied_def in defoptions then
  6569. ppufile.putderef(cloneddefderef);
  6570. writeentry(ppufile,ibobjectdef);
  6571. if not(df_copied_def in defoptions) then
  6572. tObjectSymtable(symtable).ppuwrite(ppufile);
  6573. ppufile.do_indirect_crc:=old_do_indirect_crc;
  6574. end;
  6575. function tobjectdef.GetTypeName:string;
  6576. begin
  6577. { in this case we will go in endless recursion, because then }
  6578. { there is no tsym associated yet with the def. It can occur }
  6579. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  6580. { instead of the actual type name }
  6581. if not assigned(typesym) then
  6582. result:='<Currently Parsed Class>'
  6583. else
  6584. result:=typesymbolprettyname;
  6585. end;
  6586. procedure tobjectdef.buildderef;
  6587. var
  6588. i : longint;
  6589. vmtentry : pvmtentry;
  6590. begin
  6591. inherited buildderef;
  6592. vmt_fieldderef.build(vmt_field);
  6593. childofderef.build(childof);
  6594. if df_copied_def in defoptions then
  6595. cloneddefderef.build(symtable.defowner)
  6596. else
  6597. tstoredsymtable(symtable).buildderef;
  6598. if objecttype=odt_helper then
  6599. extendeddefderef.build(extendeddef);
  6600. for i:=0 to vmtentries.count-1 do
  6601. begin
  6602. vmtentry:=pvmtentry(vmtentries[i]);
  6603. vmtentry^.procdefderef.build(vmtentry^.procdef);
  6604. end;
  6605. if assigned(ImplementedInterfaces) then
  6606. begin
  6607. for i:=0 to ImplementedInterfaces.count-1 do
  6608. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  6609. end;
  6610. end;
  6611. procedure tobjectdef.deref;
  6612. var
  6613. i : longint;
  6614. vmtentry : pvmtentry;
  6615. begin
  6616. inherited deref;
  6617. vmt_field:=tsym(vmt_fieldderef.resolve);
  6618. childof:=tobjectdef(childofderef.resolve);
  6619. if df_copied_def in defoptions then
  6620. begin
  6621. cloneddef:=tobjectdef(cloneddefderef.resolve);
  6622. symtable:=cloneddef.symtable.getcopy;
  6623. end
  6624. else
  6625. tstoredsymtable(symtable).deref(false);
  6626. if objecttype=odt_helper then
  6627. extendeddef:=tdef(extendeddefderef.resolve);
  6628. for i:=0 to vmtentries.count-1 do
  6629. begin
  6630. vmtentry:=pvmtentry(vmtentries[i]);
  6631. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  6632. end;
  6633. if assigned(ImplementedInterfaces) then
  6634. begin
  6635. for i:=0 to ImplementedInterfaces.count-1 do
  6636. TImplementedInterface(ImplementedInterfaces[i]).deref;
  6637. end;
  6638. end;
  6639. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  6640. var
  6641. pd: tprocdef absolute def;
  6642. st: tsymtable;
  6643. psym: tsym;
  6644. nname: TIDString;
  6645. begin
  6646. if (tdef(def).typ<>procdef) then
  6647. exit;
  6648. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  6649. owner = symtable in which objcclassdef is defined
  6650. }
  6651. st:=pd.owner.defowner.owner;
  6652. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  6653. { check for an existing procsym with our special name }
  6654. psym:=tsym(st.find(nname));
  6655. if not assigned(psym) then
  6656. begin
  6657. psym:=cprocsym.create(nname);
  6658. { avoid warning about this symbol being unused }
  6659. psym.IncRefCount;
  6660. { don't check for duplicates:
  6661. a) we checked above
  6662. b) in case we are in the implementation section of a unit, this
  6663. will also check for this symbol in the interface section
  6664. (since you normally cannot have symbols with the same name
  6665. both interface and implementation), and it's possible to
  6666. have class helpers for the same class in the interface and
  6667. in the implementation, and they cannot be merged since only
  6668. the once in the interface must be saved to the ppu/visible
  6669. from other units }
  6670. st.insert(psym,false);
  6671. end
  6672. else if (psym.typ<>procsym) then
  6673. internalerror(2009111501);
  6674. { add ourselves to this special procsym }
  6675. tprocsym(psym).procdeflist.add(def);
  6676. end;
  6677. procedure tobjectdef.derefimpl;
  6678. begin
  6679. inherited derefimpl;
  6680. { the procdefs are not owned by the class helper procsyms, so they
  6681. are not stored/restored either -> re-add them here }
  6682. if (objecttype in [odt_objcclass,odt_objcprotocol]) or
  6683. (oo_is_classhelper in objectoptions) then
  6684. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  6685. end;
  6686. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  6687. var
  6688. i : longint;
  6689. vmtentry : pvmtentry;
  6690. begin
  6691. if vmtentries.count<>0 then
  6692. internalerror(2019081401);
  6693. vmtentries.count:=objdef.vmtentries.count;
  6694. for i:=0 to objdef.vmtentries.count-1 do
  6695. begin
  6696. new(vmtentry);
  6697. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  6698. vmtentries[i]:=vmtentry;
  6699. end;
  6700. end;
  6701. function tobjectdef.getparentdef:tdef;
  6702. begin
  6703. { TODO: Remove getparentdef hack}
  6704. { With 2 forward declared classes with the child class before the
  6705. parent class the child class is written earlier to the ppu. Leaving it
  6706. possible to have a reference to the parent class for property overriding,
  6707. but the parent class still has the childof not resolved yet (PFV) }
  6708. if childof=nil then
  6709. childof:=tobjectdef(childofderef.resolve);
  6710. result:=childof;
  6711. end;
  6712. procedure tobjectdef.prepareguid;
  6713. begin
  6714. { set up guid }
  6715. if not assigned(iidguid) then
  6716. begin
  6717. new(iidguid);
  6718. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  6719. end;
  6720. { setup iidstring }
  6721. if not assigned(iidstr) then
  6722. iidstr:=stringdup(''); { default is empty string }
  6723. end;
  6724. procedure tobjectdef.set_parent( c : tobjectdef);
  6725. begin
  6726. if assigned(childof) then
  6727. exit;
  6728. childof:=c;
  6729. if not assigned(c) then
  6730. exit;
  6731. { inherit options and status }
  6732. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  6733. { initially has the same number of abstract methods as the parent }
  6734. abstractcnt:=c.abstractcnt;
  6735. { add the data of the anchestor class/object }
  6736. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  6737. begin
  6738. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  6739. { inherit recordalignment }
  6740. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  6741. { if both the parent and this record use C-alignment, also inherit
  6742. the current field alignment }
  6743. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  6744. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  6745. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  6746. { the padding is not inherited for Objective-C classes (maybe not
  6747. for cppclass either?) }
  6748. if objecttype=odt_objcclass then
  6749. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  6750. if (oo_has_vmt in objectoptions) and
  6751. (oo_has_vmt in c.objectoptions) then
  6752. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  6753. { if parent has a vmt field then the offset is the same for the child PM }
  6754. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  6755. begin
  6756. vmt_field:=c.vmt_field;
  6757. include(objectoptions,oo_has_vmt);
  6758. end;
  6759. end;
  6760. end;
  6761. procedure tobjectdef.insertvmt;
  6762. begin
  6763. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  6764. exit;
  6765. if (oo_has_vmt in objectoptions) then
  6766. internalerror(12345)
  6767. else
  6768. begin
  6769. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  6770. tObjectSymtable(symtable).fieldalignment);
  6771. if (tf_requires_proper_alignment in target_info.flags) then
  6772. begin
  6773. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  6774. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  6775. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  6776. end;
  6777. vmt_field:=cfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  6778. hidesym(vmt_field);
  6779. tObjectSymtable(symtable).insert(vmt_field);
  6780. tObjectSymtable(symtable).addfield(tfieldvarsym(vmt_field),vis_hidden);
  6781. include(objectoptions,oo_has_vmt);
  6782. end;
  6783. end;
  6784. function tobjectdef.vmt_offset: asizeint;
  6785. begin
  6786. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  6787. result:=0
  6788. else if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  6789. result:=tfieldvarsym(vmt_field).fieldoffset
  6790. else
  6791. result:=tfieldvarsym(vmt_field).fieldoffset div 8;
  6792. end;
  6793. procedure tobjectdef.check_forwards;
  6794. begin
  6795. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  6796. inherited;
  6797. if (oo_is_forward in objectoptions) then
  6798. begin
  6799. { ok, in future, the forward can be resolved }
  6800. Message1(sym_e_class_forward_not_resolved,objrealname^);
  6801. exclude(objectoptions,oo_is_forward);
  6802. end;
  6803. end;
  6804. function tobjectdef.find_destructor: tprocdef;
  6805. var
  6806. objdef: tobjectdef;
  6807. begin
  6808. objdef:=self;
  6809. while assigned(objdef) do
  6810. begin
  6811. result:=objdef.find_procdef_bytype(potype_destructor);
  6812. if assigned(result) then
  6813. exit;
  6814. objdef:=objdef.childof;
  6815. end;
  6816. result:=nil;
  6817. end;
  6818. function tobjectdef.implements_any_interfaces: boolean;
  6819. begin
  6820. result := (ImplementedInterfaces.Count > 0) or
  6821. (assigned(childof) and childof.implements_any_interfaces);
  6822. end;
  6823. function tobjectdef.size : asizeint;
  6824. begin
  6825. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  6826. result:=voidpointertype.size
  6827. else
  6828. result:=tObjectSymtable(symtable).datasize;
  6829. end;
  6830. function tobjectdef.alignment:shortint;
  6831. begin
  6832. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  6833. alignment:=voidpointertype.alignment
  6834. else
  6835. alignment:=tObjectSymtable(symtable).recordalignment;
  6836. end;
  6837. function tobjectdef.vmtmethodoffset(index:longint):longint;
  6838. begin
  6839. { for offset of methods for classes, see rtl/inc/objpash.inc }
  6840. case objecttype of
  6841. odt_class:
  6842. { the +2*sizeof(pint) is size and -size }
  6843. vmtmethodoffset:=index*voidcodepointertype.size+10*voidpointertype.size+2*sizeof(pint);
  6844. odt_helper,
  6845. odt_objcclass,
  6846. odt_objcprotocol:
  6847. vmtmethodoffset:=0;
  6848. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  6849. vmtmethodoffset:=index*voidcodepointertype.size;
  6850. odt_javaclass,
  6851. odt_interfacejava:
  6852. { invalid }
  6853. vmtmethodoffset:=-1;
  6854. else
  6855. { the +2*sizeof(pint) is size and -size }
  6856. {$ifdef WITHDMT}
  6857. vmtmethodoffset:=index*voidcodepointertype.size+2*voidpointertype.size+2*sizeof(pint);
  6858. {$else WITHDMT}
  6859. vmtmethodoffset:=index*voidcodepointertype.size+1*voidpointertype.size+2*sizeof(pint);
  6860. {$endif WITHDMT}
  6861. end;
  6862. end;
  6863. function tobjectdef.vmt_mangledname : TSymStr;
  6864. begin
  6865. if not(oo_has_vmt in objectoptions) then
  6866. Message1(parser_n_object_has_no_vmt,objrealname^);
  6867. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  6868. end;
  6869. function tobjectdef.vmt_def: trecorddef;
  6870. var
  6871. vmttypesym: tsymentry;
  6872. begin
  6873. if not(typesym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  6874. vmttypesym:=typesym.owner.Find('vmtdef$'+mangledparaname)
  6875. else
  6876. { Use common parent of trecordsymtable and tobjectsymtable
  6877. to avoid invalid typecast error when compiled with -CR option }
  6878. vmttypesym:=tabstractrecordsymtable(typesym.owner).get_unit_symtable.Find('vmtdef$'+mangledparaname);
  6879. if not assigned(vmttypesym) or
  6880. (vmttypesym.typ<>symconst.typesym) or
  6881. (ttypesym(vmttypesym).typedef.typ<>recorddef) then
  6882. internalerror(2015052501);
  6883. result:=trecorddef(ttypesym(vmttypesym).typedef);
  6884. end;
  6885. function tobjectdef.needs_inittable : boolean;
  6886. var
  6887. hp : tobjectdef;
  6888. begin
  6889. case objecttype of
  6890. odt_helper,
  6891. odt_class :
  6892. needs_inittable:=false;
  6893. odt_dispinterface,
  6894. odt_interfacecom:
  6895. needs_inittable:=true;
  6896. odt_interfacecorba:
  6897. begin
  6898. hp:=childof;
  6899. while assigned(hp) do
  6900. begin
  6901. if hp=interface_iunknown then
  6902. begin
  6903. needs_inittable:=true;
  6904. exit;
  6905. end;
  6906. hp:=hp.childof;
  6907. end;
  6908. needs_inittable:=false;
  6909. end;
  6910. odt_object:
  6911. needs_inittable:=
  6912. tObjectSymtable(symtable).needs_init_final or
  6913. (assigned(childof) and
  6914. childof.needs_inittable);
  6915. odt_cppclass,
  6916. odt_objcclass,
  6917. odt_objcprotocol,
  6918. odt_javaclass,
  6919. odt_interfacejava:
  6920. needs_inittable:=false;
  6921. else
  6922. internalerror(200108267);
  6923. end;
  6924. end;
  6925. function tobjectdef.needs_separate_initrtti : boolean;
  6926. begin
  6927. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  6928. end;
  6929. function tobjectdef.has_non_trivial_init_child(check_parent:boolean):boolean;
  6930. begin
  6931. if objecttype in [odt_class,odt_object] then
  6932. begin
  6933. result:=tobjectsymtable(symtable).has_non_trivial_init or
  6934. (check_parent and assigned(childof) and childof.has_non_trivial_init_child(true));
  6935. end
  6936. else
  6937. result:=false;
  6938. end;
  6939. function tobjectdef.rtti_mangledname(rt: trttitype): TSymStr;
  6940. begin
  6941. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  6942. result:=inherited rtti_mangledname(rt)
  6943. else
  6944. begin
  6945. { necessary in case of a dynamic array of nsobject, or
  6946. if an nsobject field appears in a record that needs
  6947. init/finalisation }
  6948. if rt=initrtti then
  6949. begin
  6950. result:=voidpointertype.rtti_mangledname(rt);
  6951. exit;
  6952. end;
  6953. if not(target_info.system in systems_objc_nfabi) then
  6954. begin
  6955. result:=target_asm.labelprefix;
  6956. case objecttype of
  6957. odt_objcclass:
  6958. begin
  6959. case rt of
  6960. objcclassrtti:
  6961. if not(oo_is_classhelper in objectoptions) then
  6962. result:=result+'_OBJC_CLASS_'
  6963. else
  6964. result:=result+'_OBJC_CATEGORY_';
  6965. objcmetartti:
  6966. if not(oo_is_classhelper in objectoptions) then
  6967. result:=result+'_OBJC_METACLASS_'
  6968. else
  6969. internalerror(2009111511);
  6970. else
  6971. internalerror(2009092302);
  6972. end;
  6973. end;
  6974. odt_objcprotocol:
  6975. result:=result+'_OBJC_PROTOCOL_';
  6976. else
  6977. ;
  6978. end;
  6979. end
  6980. else
  6981. begin
  6982. case objecttype of
  6983. odt_objcclass:
  6984. begin
  6985. if (oo_is_classhelper in objectoptions) and
  6986. (rt<>objcclassrtti) then
  6987. internalerror(2009111512);
  6988. case rt of
  6989. objcclassrtti:
  6990. if not(oo_is_classhelper in objectoptions) then
  6991. result:='_OBJC_CLASS_$_'
  6992. else
  6993. result:='_OBJC_$_CATEGORY_';
  6994. objcmetartti:
  6995. result:='_OBJC_METACLASS_$_';
  6996. objcclassrortti:
  6997. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  6998. objcmetarortti:
  6999. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  7000. else
  7001. internalerror(2009092303);
  7002. end;
  7003. end;
  7004. odt_objcprotocol:
  7005. begin
  7006. result:=lower(target_asm.labelprefix);
  7007. case rt of
  7008. objcclassrtti:
  7009. result:=result+'_OBJC_PROTOCOL_$_';
  7010. objcmetartti:
  7011. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  7012. else
  7013. internalerror(2009092501);
  7014. end;
  7015. end;
  7016. else
  7017. internalerror(2013113005);
  7018. end;
  7019. end;
  7020. result:=result+objextname^;
  7021. end;
  7022. end;
  7023. function tobjectdef.members_need_inittable : boolean;
  7024. begin
  7025. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  7026. end;
  7027. function tobjectdef.is_publishable : boolean;
  7028. begin
  7029. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  7030. end;
  7031. function tobjectdef.get_next_dispid: longint;
  7032. begin
  7033. inc(fcurrent_dispid);
  7034. result:=fcurrent_dispid;
  7035. end;
  7036. function tobjectdef.search_enumerator_get: tprocdef;
  7037. begin
  7038. result:=inherited;
  7039. if not assigned(result) and assigned(childof) then
  7040. result:=childof.search_enumerator_get;
  7041. end;
  7042. function tobjectdef.search_enumerator_move: tprocdef;
  7043. begin
  7044. result:=inherited;
  7045. if not assigned(result) and assigned(childof) then
  7046. result:=childof.search_enumerator_move;
  7047. end;
  7048. function tobjectdef.search_enumerator_current: tsym;
  7049. begin
  7050. result:=inherited;
  7051. if not assigned(result) and assigned(childof) then
  7052. result:=childof.search_enumerator_current;
  7053. end;
  7054. procedure tobjectdef.register_created_classref_type;
  7055. begin
  7056. if not classref_created_in_current_module then
  7057. begin
  7058. classref_created_in_current_module:=true;
  7059. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  7060. end;
  7061. end;
  7062. procedure tobjectdef.register_created_object_type;
  7063. begin
  7064. if not created_in_current_module then
  7065. begin
  7066. created_in_current_module:=true;
  7067. current_module.wpoinfo.addcreatedobjtype(self);
  7068. end;
  7069. end;
  7070. procedure tobjectdef.register_maybe_created_object_type;
  7071. begin
  7072. { if we know it has been created for sure, no need
  7073. to also record that it maybe can be created in
  7074. this module
  7075. }
  7076. if not (created_in_current_module) and
  7077. not (maybe_created_in_current_module) then
  7078. begin
  7079. maybe_created_in_current_module:=true;
  7080. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  7081. end;
  7082. end;
  7083. procedure tobjectdef.register_vmt_call(index: longint);
  7084. begin
  7085. if (is_object(self) or is_class(self)) then
  7086. current_module.wpoinfo.addcalledvmtentry(self,index);
  7087. end;
  7088. procedure check_and_finish_msg(data: tobject; arg: pointer);
  7089. var
  7090. def: tdef absolute data;
  7091. pd: tprocdef absolute data;
  7092. i,
  7093. paracount: longint;
  7094. begin
  7095. if (def.typ=procdef) then
  7096. begin
  7097. { add all messages also under a dummy name to the symtable in
  7098. which the objcclass/protocol/category is declared, so they can
  7099. be called via id.<name>
  7100. }
  7101. create_class_helper_for_procdef(pd,nil);
  7102. { we have to wait until now to set the mangled name because it
  7103. depends on the (possibly external) class name, which is defined
  7104. at the very end. }
  7105. if not(po_msgstr in pd.procoptions) then
  7106. begin
  7107. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  7108. { recover to avoid internalerror later on }
  7109. include(pd.procoptions,po_msgstr);
  7110. pd.messageinf.str:=stringdup('MissingDeclaration');
  7111. end;
  7112. { Mangled name is already set in case this is a copy of
  7113. another type. }
  7114. if not(po_has_mangledname in pd.procoptions) then
  7115. begin
  7116. { check whether the number of formal parameters is correct,
  7117. and whether they have valid Objective-C types }
  7118. paracount:=0;
  7119. for i:=1 to length(pd.messageinf.str^) do
  7120. if pd.messageinf.str^[i]=':' then
  7121. inc(paracount);
  7122. for i:=0 to pd.paras.count-1 do
  7123. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  7124. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  7125. dec(paracount);
  7126. if (paracount<>0) then
  7127. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  7128. pd.setmangledname(pd.objcmangledname);
  7129. end
  7130. else
  7131. { all checks already done }
  7132. exit;
  7133. if not(oo_is_external in pd.struct.objectoptions) then
  7134. begin
  7135. if (po_varargs in pd.procoptions) then
  7136. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  7137. else
  7138. begin
  7139. { check for "array of const" parameters }
  7140. for i:=0 to pd.parast.symlist.count-1 do
  7141. begin
  7142. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  7143. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  7144. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  7145. end;
  7146. end;
  7147. end;
  7148. end;
  7149. end;
  7150. procedure mark_private_fields_used(data: tobject; arg: pointer);
  7151. var
  7152. sym: tsym absolute data;
  7153. begin
  7154. if (sym.typ=fieldvarsym) and
  7155. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  7156. sym.IncRefCount;
  7157. end;
  7158. procedure tobjectdef.finish_objc_data;
  7159. begin
  7160. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  7161. if (oo_is_external in objectoptions) then
  7162. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  7163. end;
  7164. procedure verify_objc_vardef(data: tobject; arg: pointer);
  7165. var
  7166. sym: tabstractvarsym absolute data;
  7167. res: pboolean absolute arg;
  7168. founderrordef: tdef;
  7169. begin
  7170. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  7171. exit;
  7172. if (sym.typ=paravarsym) and
  7173. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  7174. is_array_of_const(tparavarsym(sym).vardef)) then
  7175. exit;
  7176. if not objcchecktype(sym.vardef,founderrordef) then
  7177. begin
  7178. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7179. res^:=false;
  7180. end;
  7181. end;
  7182. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  7183. var
  7184. def: tdef absolute data;
  7185. res: pboolean absolute arg;
  7186. founderrordef: tdef;
  7187. begin
  7188. if (def.typ<>procdef) then
  7189. exit;
  7190. { check parameter types for validity }
  7191. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  7192. { check the result type for validity }
  7193. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  7194. begin
  7195. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  7196. res^:=false;
  7197. end;
  7198. end;
  7199. function tobjectdef.check_objc_types: boolean;
  7200. begin
  7201. { done in separate step from finish_objc_data, because when
  7202. finish_objc_data is called, not all forwarddefs have been resolved
  7203. yet and we need to know all types here }
  7204. result:=true;
  7205. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  7206. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  7207. end;
  7208. procedure do_cpp_import_info(data: tobject; arg: pointer);
  7209. var
  7210. def: tdef absolute data;
  7211. pd: tprocdef absolute data;
  7212. begin
  7213. if (def.typ=procdef) then
  7214. begin
  7215. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  7216. if (oo_is_external in pd.struct.objectoptions) then
  7217. begin
  7218. { copied from psub.read_proc }
  7219. if assigned(tobjectdef(pd.struct).import_lib) then
  7220. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  7221. else
  7222. begin
  7223. { add import name to external list for DLL scanning }
  7224. if tf_has_dllscanner in target_info.flags then
  7225. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  7226. end;
  7227. end;
  7228. end;
  7229. end;
  7230. procedure tobjectdef.finish_cpp_data;
  7231. begin
  7232. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  7233. end;
  7234. {****************************************************************************
  7235. TImplementedInterface
  7236. ****************************************************************************}
  7237. function TImplementedInterface.GetIOffset: longint;
  7238. begin
  7239. if (fIOffset=-1) and
  7240. (IType in [etFieldValue,etFieldValueClass]) then
  7241. result:=tfieldvarsym(ImplementsField).fieldoffset
  7242. else
  7243. result:=fIOffset;
  7244. end;
  7245. constructor TImplementedInterface.create(aintf: tobjectdef);
  7246. begin
  7247. inherited create;
  7248. intfdef:=aintf;
  7249. intfdefderef.reset;
  7250. IOffset:=-1;
  7251. IType:=etStandard;
  7252. NameMappings:=nil;
  7253. procdefs:=nil;
  7254. end;
  7255. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  7256. begin
  7257. inherited create;
  7258. intfdef:=nil;
  7259. intfdefderef:=intfd;
  7260. ImplementsGetterDeref:=getterd;
  7261. IOffset:=-1;
  7262. IType:=etStandard;
  7263. NameMappings:=nil;
  7264. procdefs:=nil;
  7265. end;
  7266. destructor TImplementedInterface.destroy;
  7267. var
  7268. i : longint;
  7269. mappedname : pshortstring;
  7270. begin
  7271. if assigned(NameMappings) then
  7272. begin
  7273. for i:=0 to NameMappings.Count-1 do
  7274. begin
  7275. mappedname:=pshortstring(NameMappings[i]);
  7276. stringdispose(mappedname);
  7277. end;
  7278. NameMappings.free;
  7279. NameMappings:=nil;
  7280. end;
  7281. if assigned(procdefs) then
  7282. begin
  7283. procdefs.free;
  7284. procdefs:=nil;
  7285. end;
  7286. inherited destroy;
  7287. end;
  7288. procedure TImplementedInterface.buildderef;
  7289. begin
  7290. intfdefderef.build(intfdef);
  7291. ImplementsGetterDeref.build(ImplementsGetter);
  7292. end;
  7293. procedure TImplementedInterface.deref;
  7294. begin
  7295. intfdef:=tobjectdef(intfdefderef.resolve);
  7296. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  7297. end;
  7298. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  7299. begin
  7300. if not assigned(NameMappings) then
  7301. NameMappings:=TFPHashList.Create;
  7302. NameMappings.Add(origname,stringdup(newname));
  7303. end;
  7304. function TImplementedInterface.GetMapping(const origname: string):string;
  7305. var
  7306. mappedname : pshortstring;
  7307. begin
  7308. result:='';
  7309. if not assigned(NameMappings) then
  7310. exit;
  7311. mappedname:=PShortstring(NameMappings.Find(origname));
  7312. if assigned(mappedname) then
  7313. result:=mappedname^;
  7314. end;
  7315. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  7316. begin
  7317. if not assigned(procdefs) then
  7318. procdefs:=TFPObjectList.Create(false);
  7319. { duplicate entries must be stored, because multiple }
  7320. { interfaces can declare methods with the same name }
  7321. { and all of these get their own VMT entry }
  7322. procdefs.Add(pd);
  7323. end;
  7324. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  7325. var
  7326. i : longint;
  7327. begin
  7328. result:=false;
  7329. { interfaces being implemented through delegation are not mergable (FK) }
  7330. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  7331. exit;
  7332. weight:=0;
  7333. { empty interface is mergeable }
  7334. if ProcDefs.Count=0 then
  7335. begin
  7336. result:=true;
  7337. exit;
  7338. end;
  7339. { The interface to merge must at least the number of
  7340. procedures of this interface }
  7341. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  7342. exit;
  7343. for i:=0 to ProcDefs.Count-1 do
  7344. begin
  7345. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  7346. exit;
  7347. end;
  7348. weight:=ProcDefs.Count;
  7349. result:=true;
  7350. end;
  7351. function TImplementedInterface.getcopy:TImplementedInterface;
  7352. begin
  7353. Result:=TImplementedInterface.Create(nil);
  7354. { 1) the procdefs list will be freed once for each copy
  7355. 2) since the procdefs list owns its elements, those will also be freed for each copy
  7356. 3) idem for the name mappings
  7357. }
  7358. { warning: this is completely wrong on so many levels...
  7359. Move(pointer(self)^,pointer(result)^,InstanceSize);
  7360. We need to make clean copies of the different fields
  7361. this is not implemented yet, and thus we generate an internal
  7362. error instead PM 2011-06-14 }
  7363. internalerror(2011061401);
  7364. end;
  7365. {****************************************************************************
  7366. TFORWARDDEF
  7367. ****************************************************************************}
  7368. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  7369. begin
  7370. inherited create(forwarddef,true);
  7371. tosymname:=stringdup(s);
  7372. forwardpos:=pos;
  7373. end;
  7374. function tforwarddef.GetTypeName:string;
  7375. begin
  7376. GetTypeName:='unresolved forward to '+tosymname^;
  7377. end;
  7378. destructor tforwarddef.destroy;
  7379. begin
  7380. stringdispose(tosymname);
  7381. inherited destroy;
  7382. end;
  7383. function tforwarddef.getcopy:tstoreddef;
  7384. begin
  7385. result:=cforwarddef.create(tosymname^, forwardpos);
  7386. end;
  7387. {****************************************************************************
  7388. TUNDEFINEDDEF
  7389. ****************************************************************************}
  7390. constructor tundefineddef.create(doregister:boolean);
  7391. begin
  7392. inherited create(undefineddef,doregister);
  7393. end;
  7394. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  7395. begin
  7396. inherited ppuload(undefineddef,ppufile);
  7397. ppuload_platform(ppufile);
  7398. end;
  7399. function tundefineddef.GetTypeName:string;
  7400. begin
  7401. GetTypeName:='<undefined type>';
  7402. end;
  7403. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  7404. begin
  7405. inherited ppuwrite(ppufile);
  7406. writeentry(ppufile,ibundefineddef);
  7407. end;
  7408. {****************************************************************************
  7409. TERRORDEF
  7410. ****************************************************************************}
  7411. constructor terrordef.create;
  7412. begin
  7413. inherited create(errordef,true);
  7414. { prevent consecutive faults }
  7415. savesize:=1;
  7416. end;
  7417. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  7418. begin
  7419. { Can't write errordefs to ppu }
  7420. internalerror(200411063);
  7421. end;
  7422. function terrordef.GetTypeName:string;
  7423. begin
  7424. GetTypeName:='<erroneous type>';
  7425. end;
  7426. function terrordef.getmangledparaname:TSymStr;
  7427. begin
  7428. getmangledparaname:='error';
  7429. end;
  7430. {****************************************************************************
  7431. Definition Helpers
  7432. ****************************************************************************}
  7433. function is_interfacecom(def: tdef): boolean;
  7434. begin
  7435. is_interfacecom:=
  7436. assigned(def) and
  7437. (def.typ=objectdef) and
  7438. (tobjectdef(def).objecttype=odt_interfacecom);
  7439. end;
  7440. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  7441. begin
  7442. is_interfacecom_or_dispinterface:=
  7443. assigned(def) and
  7444. (def.typ=objectdef) and
  7445. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  7446. end;
  7447. function is_any_interface_kind(def: tdef): boolean;
  7448. begin
  7449. result:=
  7450. assigned(def) and
  7451. (def.typ=objectdef) and
  7452. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  7453. is_objccategory(def));
  7454. end;
  7455. function is_interfacecorba(def: tdef): boolean;
  7456. begin
  7457. is_interfacecorba:=
  7458. assigned(def) and
  7459. (def.typ=objectdef) and
  7460. (tobjectdef(def).objecttype=odt_interfacecorba);
  7461. end;
  7462. function is_interface(def: tdef): boolean;
  7463. begin
  7464. is_interface:=
  7465. assigned(def) and
  7466. (def.typ=objectdef) and
  7467. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  7468. end;
  7469. function is_dispinterface(def: tdef): boolean;
  7470. begin
  7471. result:=
  7472. assigned(def) and
  7473. (def.typ=objectdef) and
  7474. (tobjectdef(def).objecttype=odt_dispinterface);
  7475. end;
  7476. function is_class(def: tdef): boolean;
  7477. begin
  7478. is_class:=
  7479. assigned(def) and
  7480. (def.typ=objectdef) and
  7481. (tobjectdef(def).objecttype=odt_class);
  7482. end;
  7483. function is_object(def: tdef): boolean;
  7484. begin
  7485. is_object:=
  7486. assigned(def) and
  7487. (def.typ=objectdef) and
  7488. (tobjectdef(def).objecttype=odt_object);
  7489. end;
  7490. function is_cppclass(def: tdef): boolean;
  7491. begin
  7492. is_cppclass:=
  7493. assigned(def) and
  7494. (def.typ=objectdef) and
  7495. (tobjectdef(def).objecttype=odt_cppclass);
  7496. end;
  7497. function is_objcclass(def: tdef): boolean;
  7498. begin
  7499. is_objcclass:=
  7500. assigned(def) and
  7501. (def.typ=objectdef) and
  7502. (tobjectdef(def).objecttype=odt_objcclass);
  7503. end;
  7504. function is_objectpascal_helper(def: tdef): boolean;
  7505. begin
  7506. result:=
  7507. assigned(def) and
  7508. (def.typ=objectdef) and
  7509. (tobjectdef(def).objecttype=odt_helper);
  7510. end;
  7511. function is_objcclassref(def: tdef): boolean;
  7512. begin
  7513. is_objcclassref:=
  7514. assigned(def) and
  7515. (def.typ=classrefdef) and
  7516. is_objcclass(tclassrefdef(def).pointeddef);
  7517. end;
  7518. function is_objcprotocol(def: tdef): boolean;
  7519. begin
  7520. result:=
  7521. assigned(def) and
  7522. (def.typ=objectdef) and
  7523. (tobjectdef(def).objecttype=odt_objcprotocol);
  7524. end;
  7525. function is_objccategory(def: tdef): boolean;
  7526. begin
  7527. result:=
  7528. assigned(def) and
  7529. (def.typ=objectdef) and
  7530. { if used as a forward type }
  7531. ((tobjectdef(def).objecttype=odt_objccategory) or
  7532. { if used as after it has been resolved }
  7533. ((tobjectdef(def).objecttype=odt_objcclass) and
  7534. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  7535. end;
  7536. function is_objc_class_or_protocol(def: tdef): boolean;
  7537. begin
  7538. result:=
  7539. assigned(def) and
  7540. (def.typ=objectdef) and
  7541. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  7542. end;
  7543. function is_objc_protocol_or_category(def: tdef): boolean;
  7544. begin
  7545. result:=
  7546. assigned(def) and
  7547. (def.typ=objectdef) and
  7548. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  7549. ((tobjectdef(def).objecttype = odt_objcclass) and
  7550. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  7551. end;
  7552. function is_classhelper(def: tdef): boolean;
  7553. begin
  7554. result:=
  7555. is_objectpascal_helper(def) or
  7556. is_objccategory(def);
  7557. end;
  7558. function is_class_or_interface(def: tdef): boolean;
  7559. begin
  7560. result:=
  7561. assigned(def) and
  7562. (def.typ=objectdef) and
  7563. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  7564. end;
  7565. function is_class_or_interface_or_objc(def: tdef): boolean;
  7566. begin
  7567. result:=
  7568. assigned(def) and
  7569. (def.typ=objectdef) and
  7570. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  7571. end;
  7572. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  7573. begin
  7574. result:=
  7575. assigned(def) and
  7576. (def.typ=objectdef) and
  7577. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  7578. end;
  7579. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  7580. begin
  7581. result:=
  7582. assigned(def) and
  7583. (def.typ=objectdef) and
  7584. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  7585. end;
  7586. function is_class_or_interface_or_object(def: tdef): boolean;
  7587. begin
  7588. result:=
  7589. assigned(def) and
  7590. (def.typ=objectdef) and
  7591. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  7592. end;
  7593. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  7594. begin
  7595. result:=
  7596. assigned(def) and
  7597. (def.typ=objectdef) and
  7598. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  7599. end;
  7600. function is_implicit_pointer_object_type(def: tdef): boolean;
  7601. begin
  7602. result:=
  7603. assigned(def) and
  7604. (((def.typ=objectdef) and
  7605. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  7606. ((target_info.system in systems_jvm) and
  7607. (def.typ=recorddef)));
  7608. end;
  7609. function is_implicit_array_pointer(def: tdef): boolean;
  7610. begin
  7611. result:=is_dynamic_array(def) or is_dynamicstring(def);
  7612. end;
  7613. function is_class_or_object(def: tdef): boolean;
  7614. begin
  7615. result:=
  7616. assigned(def) and
  7617. (def.typ=objectdef) and
  7618. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  7619. end;
  7620. function is_record(def: tdef): boolean;
  7621. begin
  7622. result:=
  7623. assigned(def) and
  7624. (def.typ=recorddef);
  7625. end;
  7626. function is_javaclass(def: tdef): boolean;
  7627. begin
  7628. result:=
  7629. assigned(def) and
  7630. (def.typ=objectdef) and
  7631. (tobjectdef(def).objecttype=odt_javaclass);
  7632. end;
  7633. function is_javaclassref(def: tdef): boolean;
  7634. begin
  7635. is_javaclassref:=
  7636. assigned(def) and
  7637. (def.typ=classrefdef) and
  7638. is_javaclass(tclassrefdef(def).pointeddef);
  7639. end;
  7640. function is_javainterface(def: tdef): boolean;
  7641. begin
  7642. result:=
  7643. assigned(def) and
  7644. (def.typ=objectdef) and
  7645. (tobjectdef(def).objecttype=odt_interfacejava);
  7646. end;
  7647. function is_java_class_or_interface(def: tdef): boolean;
  7648. begin
  7649. result:=
  7650. assigned(def) and
  7651. (def.typ=objectdef) and
  7652. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  7653. end;
  7654. procedure loadobjctypes;
  7655. begin
  7656. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  7657. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  7658. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  7659. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  7660. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  7661. end;
  7662. procedure maybeloadcocoatypes;
  7663. var
  7664. tsym: ttypesym;
  7665. cocoaunit: string[15];
  7666. begin
  7667. if assigned(objc_fastenumeration) then
  7668. exit;
  7669. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim,system_aarch64_darwin,system_x86_64_iphonesim]) then
  7670. cocoaunit:='COCOAALL'
  7671. else
  7672. cocoaunit:='IPHONEALL';
  7673. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  7674. if assigned(tsym) then
  7675. objc_fastenumeration:=tobjectdef(tsym.typedef)
  7676. else
  7677. objc_fastenumeration:=nil;
  7678. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  7679. if assigned(tsym) then
  7680. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  7681. else
  7682. objc_fastenumerationstate:=nil;
  7683. end;
  7684. function use_vectorfpu(def : tdef) : boolean;
  7685. begin
  7686. {$ifdef x86}
  7687. {$define use_vectorfpuimplemented}
  7688. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  7689. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  7690. {$endif x86}
  7691. {$ifdef arm}
  7692. {$define use_vectorfpuimplemented}
  7693. use_vectorfpu:=FPUARM_HAS_VFP_EXTENSION in fpu_capabilities[current_settings.fputype];
  7694. {$endif arm}
  7695. {$ifdef aarch64}
  7696. {$define use_vectorfpuimplemented}
  7697. use_vectorfpu:=true;
  7698. {$endif aarch64}
  7699. {$ifndef use_vectorfpuimplemented}
  7700. use_vectorfpu:=false;
  7701. {$endif}
  7702. end;
  7703. end.