symdef.pas 208 KB

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