symdef.pas 229 KB

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