symdef.pas 276 KB

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