symdef.pas 207 KB

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