symdef.pas 253 KB

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