symdef.pas 294 KB

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