symdef.pas 243 KB

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