symdef.pas 241 KB

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