symdef.pas 250 KB

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