symdef.pas 278 KB

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