symdef.pas 241 KB

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