symdef.pas 234 KB

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