symdef.pas 281 KB

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