symdef.pas 206 KB

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