symdef.pas 253 KB

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