symdef.pas 215 KB

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