symdef.pas 242 KB

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