symdef.pas 243 KB

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