symdef.pas 271 KB

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