symdef.pas 242 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485
  1. {
  2. Symbol table implementation for the definitions
  3. Copyright (c) 1998-2005 by Florian Klaempfl, Pierre Muller
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symdef;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,
  23. { global }
  24. globtype,globals,tokens,constexp,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { ppu }
  28. ppu,
  29. { node }
  30. node,
  31. { aasm }
  32. aasmbase,aasmtai,
  33. {$ifdef jvm}
  34. aasmdata,
  35. {$endif}
  36. cpubase,cpuinfo,
  37. cgbase,
  38. parabase
  39. ;
  40. type
  41. {************************************************
  42. TDef
  43. ************************************************}
  44. tgenericconstraintdata=class
  45. interfaces : tfpobjectlist;
  46. interfacesderef : tfplist;
  47. flags : tgenericconstraintflags;
  48. constructor create;
  49. destructor destroy;override;
  50. procedure ppuload(ppufile:tcompilerppufile);
  51. procedure ppuwrite(ppufile:tcompilerppufile);
  52. procedure buildderef;
  53. procedure deref;
  54. end;
  55. { tstoreddef }
  56. tstoreddef = class(tdef)
  57. private
  58. _fullownerhierarchyname : pshortstring;
  59. protected
  60. typesymderef : tderef;
  61. procedure fillgenericparas(symtable:tsymtable);
  62. public
  63. {$ifdef EXTDEBUG}
  64. fileinfo : tfileposinfo;
  65. {$endif}
  66. { generic support }
  67. genericdef : tstoreddef;
  68. genericdefderef : tderef;
  69. generictokenbuf : tdynamicarray;
  70. { this list contains references to the symbols that make up the
  71. generic parameters; the symbols are not owned by this list
  72. Note: this list is allocated on demand! }
  73. genericparas : tfphashobjectlist;
  74. { contains additional data if this def is a generic constraint
  75. Note: this class is allocated on demand! }
  76. genconstraintdata : tgenericconstraintdata;
  77. constructor create(dt:tdeftyp);
  78. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  79. destructor destroy;override;
  80. function getcopy : tstoreddef;virtual;
  81. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  82. procedure buildderef;override;
  83. procedure buildderefimpl;override;
  84. procedure deref;override;
  85. procedure derefimpl;override;
  86. function size:asizeint;override;
  87. function getvardef:longint;override;
  88. function alignment:shortint;override;
  89. function is_publishable : boolean;override;
  90. function needs_inittable : boolean;override;
  91. function rtti_mangledname(rt:trttitype):string;override;
  92. function OwnerHierarchyName: string; override;
  93. function fullownerhierarchyname:string;override;
  94. function needs_separate_initrtti:boolean;override;
  95. function in_currentunit: boolean;
  96. { regvars }
  97. function is_intregable : boolean;
  98. function is_fpuregable : boolean;
  99. { def can be put into a register if it is const/immutable }
  100. function is_const_intregable : boolean;
  101. { generics }
  102. procedure initgeneric;
  103. { this function can be used to determine whether a def is really a
  104. generic declaration or just a normal type declared inside another
  105. generic }
  106. function is_generic:boolean;inline;
  107. { same as above for specializations }
  108. function is_specialization:boolean;inline;
  109. private
  110. savesize : asizeuint;
  111. end;
  112. tfiletyp = (ft_text,ft_typed,ft_untyped);
  113. tfiledef = class(tstoreddef)
  114. filetyp : tfiletyp;
  115. typedfiledef : tdef;
  116. typedfiledefderef : tderef;
  117. constructor createtext;
  118. constructor createuntyped;
  119. constructor createtyped(def : tdef);
  120. constructor ppuload(ppufile:tcompilerppufile);
  121. function getcopy : tstoreddef;override;
  122. procedure ppuwrite(ppufile:tcompilerppufile);override;
  123. procedure buildderef;override;
  124. procedure deref;override;
  125. function GetTypeName:string;override;
  126. function getmangledparaname:TSymStr;override;
  127. function size:asizeint;override;
  128. procedure setsize;
  129. end;
  130. tvariantdef = class(tstoreddef)
  131. varianttype : tvarianttype;
  132. constructor create(v : tvarianttype);
  133. constructor ppuload(ppufile:tcompilerppufile);
  134. function getcopy : tstoreddef;override;
  135. function GetTypeName:string;override;
  136. procedure ppuwrite(ppufile:tcompilerppufile);override;
  137. function getvardef:longint;override;
  138. procedure setsize;
  139. function is_publishable : boolean;override;
  140. function needs_inittable : boolean;override;
  141. end;
  142. tformaldef = class(tstoreddef)
  143. typed:boolean;
  144. constructor create(Atyped:boolean);
  145. constructor ppuload(ppufile:tcompilerppufile);
  146. procedure ppuwrite(ppufile:tcompilerppufile);override;
  147. function GetTypeName:string;override;
  148. end;
  149. tforwarddef = class(tstoreddef)
  150. tosymname : pshortstring;
  151. forwardpos : tfileposinfo;
  152. constructor create(const s:string;const pos:tfileposinfo);
  153. destructor destroy;override;
  154. function getcopy:tstoreddef;override;
  155. function GetTypeName:string;override;
  156. end;
  157. tundefineddef = class(tstoreddef)
  158. constructor create;
  159. constructor ppuload(ppufile:tcompilerppufile);
  160. procedure ppuwrite(ppufile:tcompilerppufile);override;
  161. function GetTypeName:string;override;
  162. end;
  163. terrordef = class(tstoreddef)
  164. constructor create;
  165. procedure ppuwrite(ppufile:tcompilerppufile);override;
  166. function GetTypeName:string;override;
  167. function getmangledparaname : TSymStr;override;
  168. end;
  169. tabstractpointerdef = class(tstoreddef)
  170. pointeddef : tdef;
  171. pointeddefderef : tderef;
  172. constructor create(dt:tdeftyp;def:tdef);
  173. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  174. procedure ppuwrite(ppufile:tcompilerppufile);override;
  175. procedure buildderef;override;
  176. procedure deref;override;
  177. end;
  178. {$ifdef x86}
  179. const
  180. { TODO: make this depend on the memory model, when other memory models are supported }
  181. default_x86_data_pointer_type = x86pt_near;
  182. type
  183. {$endif x86}
  184. { tpointerdef }
  185. tpointerdef = class(tabstractpointerdef)
  186. {$ifdef x86}
  187. x86pointertyp : tx86pointertyp;
  188. {$endif x86}
  189. has_pointer_math : boolean;
  190. constructor create(def:tdef);
  191. {$ifdef x86}
  192. constructor createx86(def:tdef;x86typ:tx86pointertyp);
  193. {$endif x86}
  194. function size:asizeint;override;
  195. function getcopy:tstoreddef;override;
  196. constructor ppuload(ppufile:tcompilerppufile);
  197. procedure ppuwrite(ppufile:tcompilerppufile);override;
  198. function GetTypeName:string;override;
  199. end;
  200. tprocdef = class;
  201. tabstractrecorddef= class(tstoreddef)
  202. objname,
  203. objrealname : PShortString;
  204. { for C++ classes: name of the library this class is imported from }
  205. { for Java classes/records: package name }
  206. import_lib : PShortString;
  207. symtable : TSymtable;
  208. cloneddef : tabstractrecorddef;
  209. cloneddefderef : tderef;
  210. objectoptions : tobjectoptions;
  211. { for targets that initialise typed constants via explicit assignments
  212. instead of by generating an initialised data sectino }
  213. tcinitcode : tnode;
  214. constructor create(const n:string; dt:tdeftyp);
  215. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  216. procedure ppuwrite(ppufile:tcompilerppufile);override;
  217. destructor destroy; override;
  218. procedure check_forwards; virtual;
  219. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  220. function GetSymtable(t:tGetSymtable):TSymtable;override;
  221. function is_packed:boolean;
  222. function RttiName: string;
  223. { enumerator support }
  224. function search_enumerator_get: tprocdef; virtual;
  225. function search_enumerator_move: tprocdef; virtual;
  226. function search_enumerator_current: tsym; virtual;
  227. { JVM }
  228. function jvm_full_typename(with_package_name: boolean): string;
  229. { check if the symtable contains a float field }
  230. function contains_float_field : boolean;
  231. end;
  232. pvariantrecdesc = ^tvariantrecdesc;
  233. tvariantrecbranch = record
  234. { we store only single values here and no ranges because tvariantrecdesc is only needed in iso mode
  235. which does not support range expressions in variant record definitions }
  236. values : array of Tconstexprint;
  237. nestedvariant : pvariantrecdesc;
  238. end;
  239. ppvariantrecdesc = ^pvariantrecdesc;
  240. tvariantrecdesc = record
  241. variantselector : tsym;
  242. variantselectorderef : tderef;
  243. branches : array of tvariantrecbranch;
  244. end;
  245. trecorddef = class(tabstractrecorddef)
  246. public
  247. variantrecdesc : pvariantrecdesc;
  248. isunion : boolean;
  249. constructor create(const n:string; p:TSymtable);
  250. constructor ppuload(ppufile:tcompilerppufile);
  251. destructor destroy;override;
  252. function getcopy : tstoreddef;override;
  253. procedure ppuwrite(ppufile:tcompilerppufile);override;
  254. procedure buildderef;override;
  255. procedure buildderefimpl;override;
  256. procedure deref;override;
  257. function size:asizeint;override;
  258. function alignment : shortint;override;
  259. function padalignment: shortint;
  260. function GetTypeName:string;override;
  261. { debug }
  262. function needs_inittable : boolean;override;
  263. function needs_separate_initrtti:boolean;override;
  264. end;
  265. tobjectdef = class;
  266. { TImplementedInterface }
  267. TImplementedInterface = class
  268. private
  269. fIOffset : longint;
  270. function GetIOffset: longint;
  271. public
  272. IntfDef : tobjectdef;
  273. IntfDefDeref : tderef;
  274. IType : tinterfaceentrytype;
  275. VtblImplIntf : TImplementedInterface;
  276. NameMappings : TFPHashList;
  277. ProcDefs : TFPObjectList;
  278. ImplementsGetter : tsym;
  279. ImplementsGetterDeref : tderef;
  280. ImplementsField : tsym;
  281. constructor create(aintf: tobjectdef);
  282. constructor create_deref(intfd,getterd:tderef);
  283. destructor destroy; override;
  284. function getcopy:TImplementedInterface;
  285. procedure buildderef;
  286. procedure deref;
  287. procedure AddMapping(const origname, newname: string);
  288. function GetMapping(const origname: string):string;
  289. procedure AddImplProc(pd:tprocdef);
  290. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  291. property IOffset: longint read GetIOffset write fIOffset;
  292. end;
  293. { tvmtentry }
  294. tvmtentry = record
  295. procdef : tprocdef;
  296. procdefderef : tderef;
  297. visibility : tvisibility;
  298. end;
  299. pvmtentry = ^tvmtentry;
  300. { tobjectdef }
  301. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  302. pmvcallstaticinfo = ^tmvcallstaticinfo;
  303. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  304. tobjectdef = class(tabstractrecorddef)
  305. private
  306. fcurrent_dispid: longint;
  307. public
  308. dwarf_struct_lab : tasmsymbol;
  309. childof : tobjectdef;
  310. childofderef : tderef;
  311. { for Object Pascal helpers }
  312. extendeddef : tdef;
  313. extendeddefderef: tderef;
  314. { for Objective-C: protocols and classes can have the same name there }
  315. objextname : pshortstring;
  316. { to be able to have a variable vmt position }
  317. { and no vmt field for objects without virtuals }
  318. vmtentries : TFPList;
  319. vmcallstaticinfo : pmvcallstaticinfo;
  320. vmt_offset : longint;
  321. iidguid : pguid;
  322. iidstr : pshortstring;
  323. { store implemented interfaces defs and name mappings }
  324. ImplementedInterfaces : TFPObjectList;
  325. { number of abstract methods (used by JVM target to determine whether
  326. or not the class should be marked as abstract: must be done if 1 or
  327. more abstract methods) }
  328. abstractcnt : longint;
  329. writing_class_record_dbginfo,
  330. { a class of this type has been created in this module }
  331. created_in_current_module,
  332. { a loadvmtnode for this class has been created in this
  333. module, so if a classrefdef variable of this or a parent
  334. class is used somewhere to instantiate a class, then this
  335. class may be instantiated
  336. }
  337. maybe_created_in_current_module,
  338. { a "class of" this particular class has been created in
  339. this module
  340. }
  341. classref_created_in_current_module : boolean;
  342. objecttype : tobjecttyp;
  343. constructor create(ot:tobjecttyp;const n:string;c:tobjectdef);
  344. constructor ppuload(ppufile:tcompilerppufile);
  345. destructor destroy;override;
  346. function getcopy : tstoreddef;override;
  347. procedure ppuwrite(ppufile:tcompilerppufile);override;
  348. function GetTypeName:string;override;
  349. procedure buildderef;override;
  350. procedure deref;override;
  351. procedure buildderefimpl;override;
  352. procedure derefimpl;override;
  353. procedure resetvmtentries;
  354. procedure copyvmtentries(objdef:tobjectdef);
  355. function getparentdef:tdef;override;
  356. function size : asizeint;override;
  357. function alignment:shortint;override;
  358. function vmtmethodoffset(index:longint):longint;
  359. function members_need_inittable : boolean;
  360. { this should be called when this class implements an interface }
  361. procedure prepareguid;
  362. function is_publishable : boolean;override;
  363. function needs_inittable : boolean;override;
  364. function needs_separate_initrtti : boolean;override;
  365. function rtti_mangledname(rt:trttitype):string;override;
  366. function vmt_mangledname : TSymStr;
  367. procedure check_forwards; override;
  368. procedure insertvmt;
  369. procedure set_parent(c : tobjectdef);
  370. function find_destructor: tprocdef;
  371. function implements_any_interfaces: boolean;
  372. { dispinterface support }
  373. function get_next_dispid: longint;
  374. { enumerator support }
  375. function search_enumerator_get: tprocdef; override;
  376. function search_enumerator_move: tprocdef; override;
  377. function search_enumerator_current: tsym; override;
  378. { WPO }
  379. procedure register_created_object_type;override;
  380. procedure register_maybe_created_object_type;
  381. procedure register_created_classref_type;
  382. procedure register_vmt_call(index:longint);
  383. { ObjC }
  384. procedure finish_objc_data;
  385. function check_objc_types: boolean;
  386. { C++ }
  387. procedure finish_cpp_data;
  388. end;
  389. tclassrefdef = class(tabstractpointerdef)
  390. constructor create(def:tdef);
  391. constructor ppuload(ppufile:tcompilerppufile);
  392. procedure ppuwrite(ppufile:tcompilerppufile);override;
  393. function getcopy:tstoreddef;override;
  394. function GetTypeName:string;override;
  395. function is_publishable : boolean;override;
  396. function rtti_mangledname(rt:trttitype):string;override;
  397. procedure register_created_object_type;override;
  398. end;
  399. tarraydef = class(tstoreddef)
  400. lowrange,
  401. highrange : asizeint;
  402. rangedef : tdef;
  403. rangedefderef : tderef;
  404. arrayoptions : tarraydefoptions;
  405. symtable : TSymtable;
  406. protected
  407. _elementdef : tdef;
  408. _elementdefderef : tderef;
  409. procedure setelementdef(def:tdef);
  410. public
  411. function elesize : asizeint;
  412. function elepackedbitsize : asizeint;
  413. function elecount : asizeuint;
  414. constructor create_from_pointer(def:tdef);
  415. constructor create(l,h:asizeint;def:tdef);
  416. constructor ppuload(ppufile:tcompilerppufile);
  417. destructor destroy; override;
  418. function getcopy : tstoreddef;override;
  419. procedure ppuwrite(ppufile:tcompilerppufile);override;
  420. function GetTypeName:string;override;
  421. function getmangledparaname : TSymStr;override;
  422. procedure buildderef;override;
  423. procedure deref;override;
  424. function size : asizeint;override;
  425. function alignment : shortint;override;
  426. { returns the label of the range check string }
  427. function needs_inittable : boolean;override;
  428. function needs_separate_initrtti : boolean;override;
  429. property elementdef : tdef read _elementdef write setelementdef;
  430. function is_publishable : boolean;override;
  431. end;
  432. torddef = class(tstoreddef)
  433. low,high : TConstExprInt;
  434. ordtype : tordtype;
  435. constructor create(t : tordtype;v,b : TConstExprInt);
  436. constructor ppuload(ppufile:tcompilerppufile);
  437. function getcopy : tstoreddef;override;
  438. procedure ppuwrite(ppufile:tcompilerppufile);override;
  439. function is_publishable : boolean;override;
  440. function GetTypeName:string;override;
  441. function alignment:shortint;override;
  442. procedure setsize;
  443. function packedbitsize: asizeint; override;
  444. function getvardef : longint;override;
  445. end;
  446. tfloatdef = class(tstoreddef)
  447. floattype : tfloattype;
  448. constructor create(t : tfloattype);
  449. constructor ppuload(ppufile:tcompilerppufile);
  450. function getcopy : tstoreddef;override;
  451. procedure ppuwrite(ppufile:tcompilerppufile);override;
  452. function GetTypeName:string;override;
  453. function is_publishable : boolean;override;
  454. function alignment:shortint;override;
  455. function structalignment: shortint;override;
  456. procedure setsize;
  457. function getvardef:longint;override;
  458. end;
  459. { tabstractprocdef }
  460. tprocnameoption = (pno_showhidden, pno_proctypeoption, pno_paranames,
  461. pno_ownername, pno_noclassmarker, pno_noleadingdollar);
  462. tprocnameoptions = set of tprocnameoption;
  463. tproccopytyp = (pc_normal,
  464. { always creates a top-level function, removes all
  465. special parameters (self, vmt, parentfp, ...) }
  466. pc_bareproc
  467. );
  468. tabstractprocdef = class(tstoreddef)
  469. { saves a definition to the return type }
  470. returndef : tdef;
  471. returndefderef : tderef;
  472. parast : TSymtable;
  473. paras : tparalist;
  474. proctypeoption : tproctypeoption;
  475. proccalloption : tproccalloption;
  476. procoptions : tprocoptions;
  477. callerargareasize,
  478. calleeargareasize: pint;
  479. {$ifdef m68k}
  480. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  481. {$endif}
  482. funcretloc : array[tcallercallee] of TCGPara;
  483. has_paraloc_info : tcallercallee; { paraloc info is available }
  484. { number of user visible parameters }
  485. maxparacount,
  486. minparacount : byte;
  487. constructor create(dt:tdeftyp;level:byte);
  488. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  489. destructor destroy;override;
  490. procedure ppuwrite(ppufile:tcompilerppufile);override;
  491. procedure buildderef;override;
  492. procedure deref;override;
  493. procedure calcparas;
  494. function typename_paras(pno: tprocnameoptions): ansistring;
  495. function is_methodpointer:boolean;virtual;
  496. function is_addressonly:boolean;virtual;
  497. function no_self_node:boolean;
  498. { get either a copy as a procdef or procvardef }
  499. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef; virtual;
  500. procedure check_mark_as_nested;
  501. procedure init_paraloc_info(side: tcallercallee);
  502. function stack_tainting_parameter(side: tcallercallee): boolean;
  503. function is_pushleftright: boolean;
  504. function address_size:asizeint;
  505. private
  506. procedure count_para(p:TObject;arg:pointer);
  507. procedure insert_para(p:TObject;arg:pointer);
  508. end;
  509. tprocvardef = class(tabstractprocdef)
  510. {$ifdef jvm}
  511. { class representing this procvar on the Java side }
  512. classdef : tobjectdef;
  513. classdefderef : tderef;
  514. {$endif}
  515. constructor create(level:byte);
  516. constructor ppuload(ppufile:tcompilerppufile);
  517. function getcopy : tstoreddef;override;
  518. procedure ppuwrite(ppufile:tcompilerppufile);override;
  519. {$ifdef jvm}
  520. procedure buildderef;override;
  521. procedure deref;override;
  522. {$endif}
  523. function GetSymtable(t:tGetSymtable):TSymtable;override;
  524. function size : asizeint;override;
  525. function GetTypeName:string;override;
  526. function is_publishable : boolean;override;
  527. function is_methodpointer:boolean;override;
  528. function is_addressonly:boolean;override;
  529. function getmangledparaname:TSymStr;override;
  530. end;
  531. tmessageinf = record
  532. case integer of
  533. 0 : (str : pshortstring);
  534. 1 : (i : longint);
  535. end;
  536. tinlininginfo = record
  537. { node tree }
  538. code : tnode;
  539. flags : tprocinfoflags;
  540. end;
  541. pinlininginfo = ^tinlininginfo;
  542. {$ifdef oldregvars}
  543. { register variables }
  544. pregvarinfo = ^tregvarinfo;
  545. tregvarinfo = record
  546. regvars : array[1..maxvarregs] of tsym;
  547. regvars_para : array[1..maxvarregs] of boolean;
  548. regvars_refs : array[1..maxvarregs] of longint;
  549. fpuregvars : array[1..maxfpuvarregs] of tsym;
  550. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  551. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  552. end;
  553. {$endif oldregvars}
  554. timplprocdefinfo = record
  555. resultname : pshortstring;
  556. parentfpstruct: tsym;
  557. parentfpstructptrtype: tdef;
  558. parentfpinitblock: tnode;
  559. procstarttai,
  560. procendtai : tai;
  561. skpara: pointer;
  562. forwarddef,
  563. interfacedef : boolean;
  564. hasforward : boolean;
  565. end;
  566. pimplprocdefinfo = ^timplprocdefinfo;
  567. { tprocdef }
  568. tprocdef = class(tabstractprocdef)
  569. private
  570. {$ifdef symansistr}
  571. _mangledname : ansistring;
  572. {$else symansistr}
  573. _mangledname : pshortstring;
  574. {$endif}
  575. { information that is only required until the implementation of the
  576. procdef has been handled }
  577. implprocdefinfo : pimplprocdefinfo;
  578. function GetResultName: PShortString;
  579. procedure SetResultName(AValue: PShortString);
  580. function GetParentFPStruct: tsym;
  581. procedure SetParentFPStruct(AValue: tsym);
  582. function GetParentFPStructPtrType: tdef;
  583. procedure SetParentFPStructPtrType(AValue: tdef);
  584. function GetParentFPInitBlock: tnode;
  585. procedure SetParentFPInitBlock(AValue: tnode);
  586. function Getprocstarttai: tai;
  587. procedure Setprocstarttai(AValue: tai);
  588. function Getprocendtai: tai;
  589. procedure Setprocendtai(AValue: tai);
  590. function Getskpara: pointer;
  591. procedure Setskpara(AValue: pointer);
  592. function Getforwarddef: boolean;
  593. procedure Setforwarddef(AValue: boolean);
  594. function Getinterfacedef: boolean;
  595. procedure Setinterfacedef(AValue: boolean);
  596. function Gethasforward: boolean;
  597. procedure Sethasforward(AValue: boolean);
  598. public
  599. messageinf : tmessageinf;
  600. dispid : longint;
  601. {$ifndef EXTDEBUG}
  602. { where is this function defined and what were the symbol
  603. flags, needed here because there
  604. is only one symbol for all overloaded functions
  605. EXTDEBUG has fileinfo in tdef (PFV) }
  606. fileinfo : tfileposinfo;
  607. {$endif}
  608. symoptions : tsymoptions;
  609. deprecatedmsg : pshortstring;
  610. { symbol owning this definition }
  611. procsym : tsym;
  612. procsymderef : tderef;
  613. { alias names }
  614. aliasnames : TCmdStrList;
  615. { symtables }
  616. localst : TSymtable;
  617. funcretsym : tsym;
  618. funcretsymderef : tderef;
  619. struct : tabstractrecorddef;
  620. structderef : tderef;
  621. {$if defined(powerpc) or defined(m68k)}
  622. { library symbol for AmigaOS/MorphOS }
  623. libsym : tsym;
  624. libsymderef : tderef;
  625. {$endif powerpc or m68k}
  626. { import info }
  627. import_dll,
  628. import_name : pshortstring;
  629. { info for inlining the subroutine, if this pointer is nil,
  630. the procedure can't be inlined }
  631. inlininginfo : pinlininginfo;
  632. {$ifdef jvm}
  633. { generated assembler code; used by JVM backend so it can afterwards
  634. easily write out all methods grouped per class }
  635. exprasmlist : TAsmList;
  636. {$endif jvm}
  637. {$ifdef oldregvars}
  638. regvarinfo: pregvarinfo;
  639. {$endif oldregvars}
  640. import_nr : word;
  641. extnumber : word;
  642. {$if defined(i386) or defined(i8086)}
  643. fpu_used : byte;
  644. {$endif i386 or i8086}
  645. {$if defined(arm)}
  646. { the arm paramanager might need to know the total size of the stackframe
  647. to avoid cyclic unit dependencies or global variables, this infomatation is
  648. stored in total_stackframe_size }
  649. total_stackframe_size : aint;
  650. {$endif defined(arm)}
  651. {$ifdef mips}
  652. { needed for stabs debugging }
  653. total_local_size : longint;
  654. {$endif mips}
  655. visibility : tvisibility;
  656. { set to a value different from tsk_none in case this procdef is for
  657. a routine that has to be internally generated by the compiler }
  658. synthetickind : tsynthetickind;
  659. { true, if the procedure contains no code }
  660. isempty: boolean;
  661. constructor create(level:byte);
  662. constructor ppuload(ppufile:tcompilerppufile);
  663. destructor destroy;override;
  664. procedure ppuwrite(ppufile:tcompilerppufile);override;
  665. procedure buildderef;override;
  666. procedure buildderefimpl;override;
  667. procedure deref;override;
  668. procedure derefimpl;override;
  669. function GetSymtable(t:tGetSymtable):TSymtable;override;
  670. { warnings:
  671. * the symtablestack top has to be the symtable to which the copy
  672. should be added
  673. * getcopy does not create a finished/ready-to-use procdef; it
  674. needs to be finalised afterwards by calling
  675. symcreat.finish_copied_procdef() afterwards
  676. }
  677. function getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef; override;
  678. function getcopy: tstoreddef; override;
  679. function GetTypeName : string;override;
  680. function mangledname : TSymStr;
  681. procedure setmangledname(const s : TSymStr);
  682. function fullprocname(showhidden:boolean):string;
  683. function customprocname(pno: tprocnameoptions):ansistring;
  684. function defaultmangledname: TSymStr;
  685. function cplusplusmangledname : TSymStr;
  686. function objcmangledname : TSymStr;
  687. {$ifdef jvm}
  688. function jvmmangledbasename(signature: boolean): TSymStr;
  689. {$endif}
  690. function is_methodpointer:boolean;override;
  691. function is_addressonly:boolean;override;
  692. procedure make_external;
  693. { aliases to fields only required when a function is implemented in
  694. the current unit }
  695. property resultname: PShortString read GetResultName write SetResultName;
  696. { temporary reference to structure containing copies of all local
  697. variables and parameters accessed by nested routines; reference to
  698. this structure is passed as "parent frame pointer" on targets that
  699. lack this concept (at least JVM and LLVM); no need to save to/
  700. restore from ppu, since nested routines are always in the same
  701. unit }
  702. property parentfpstruct: tsym read GetParentFPStruct write SetParentFPStruct;
  703. { pointer to parentfpstruct's type (not yet valid during parsing, so
  704. cannot be used for $parentfp parameter) (no need to save to ppu) }
  705. property parentfpstructptrtype: tdef read GetParentFPStructPtrType write SetParentFPStructPtrType;
  706. { code to copy the parameters accessed from nested routines into the
  707. parentfpstruct (no need to save to ppu) }
  708. property parentfpinitblock: tnode read GetParentFPInitBlock write SetParentFPInitBlock;
  709. { First/last assembler symbol/instruction in aasmoutput list.
  710. Note: initialised after compiling the code for the procdef, but
  711. not saved to/restored from ppu. Used when inserting debug info }
  712. property procstarttai: tai read Getprocstarttai write Setprocstarttai;
  713. property procendtai: tai read Getprocendtai write Setprocendtai;
  714. { optional parameter for the synthetic routine generation logic }
  715. property skpara: pointer read Getskpara write Setskpara;
  716. { true, if the procedure is only declared
  717. (forward procedure) }
  718. property forwarddef: boolean read Getforwarddef write Setforwarddef;
  719. { true if the procedure is declared in the interface }
  720. property interfacedef: boolean read Getinterfacedef write Setinterfacedef;
  721. { true if the procedure has a forward declaration }
  722. property hasforward: boolean read Gethasforward write Sethasforward;
  723. end;
  724. { single linked list of overloaded procs }
  725. pprocdeflist = ^tprocdeflist;
  726. tprocdeflist = record
  727. def : tprocdef;
  728. defderef : tderef;
  729. next : pprocdeflist;
  730. end;
  731. tstringdef = class(tstoreddef)
  732. encoding : tstringencoding;
  733. stringtype : tstringtype;
  734. len : asizeint;
  735. constructor createshort(l : byte);
  736. constructor loadshort(ppufile:tcompilerppufile);
  737. constructor createlong(l : asizeint);
  738. constructor loadlong(ppufile:tcompilerppufile);
  739. constructor createansi(aencoding:tstringencoding);
  740. constructor loadansi(ppufile:tcompilerppufile);
  741. constructor createwide;
  742. constructor loadwide(ppufile:tcompilerppufile);
  743. constructor createunicode;
  744. constructor loadunicode(ppufile:tcompilerppufile);
  745. function getcopy : tstoreddef;override;
  746. function stringtypname:string;
  747. procedure ppuwrite(ppufile:tcompilerppufile);override;
  748. function GetTypeName:string;override;
  749. function getmangledparaname:TSymStr;override;
  750. function is_publishable : boolean;override;
  751. function alignment : shortint;override;
  752. function needs_inittable : boolean;override;
  753. function getvardef:longint;override;
  754. end;
  755. { tenumdef }
  756. tenumdef = class(tstoreddef)
  757. minval,
  758. maxval : asizeint;
  759. basedef : tenumdef;
  760. basedefderef : tderef;
  761. symtable : TSymtable;
  762. {$ifdef jvm}
  763. { class representing this enum on the Java side }
  764. classdef : tobjectdef;
  765. classdefderef : tderef;
  766. {$endif}
  767. has_jumps : boolean;
  768. constructor create;
  769. constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);
  770. constructor ppuload(ppufile:tcompilerppufile);
  771. destructor destroy;override;
  772. function getcopy : tstoreddef;override;
  773. procedure ppuwrite(ppufile:tcompilerppufile);override;
  774. procedure buildderef;override;
  775. procedure deref;override;
  776. function GetTypeName:string;override;
  777. function is_publishable : boolean;override;
  778. procedure calcsavesize;
  779. function packedbitsize: asizeint; override;
  780. procedure setmax(_max:asizeint);
  781. procedure setmin(_min:asizeint);
  782. function min:asizeint;
  783. function max:asizeint;
  784. function getfirstsym:tsym;
  785. function int2enumsym(l: asizeint): tsym;
  786. { returns basedef if assigned, otherwise self }
  787. function getbasedef: tenumdef;
  788. end;
  789. tsetdef = class(tstoreddef)
  790. elementdef : tdef;
  791. elementdefderef : tderef;
  792. setbase,
  793. setmax : aword;
  794. constructor create(def:tdef;low, high : asizeint);
  795. constructor ppuload(ppufile:tcompilerppufile);
  796. function getcopy : tstoreddef;override;
  797. procedure ppuwrite(ppufile:tcompilerppufile);override;
  798. procedure buildderef;override;
  799. procedure deref;override;
  800. function GetTypeName:string;override;
  801. function is_publishable : boolean;override;
  802. end;
  803. tgenericdummyentry = class
  804. dummysym : tsym;
  805. resolvedsym : tsym;
  806. end;
  807. tdefawaresymtablestack = class(TSymtablestack)
  808. private
  809. procedure add_helpers_and_generics(st:tsymtable;addgenerics:boolean);
  810. procedure remove_helpers_and_generics(st:tsymtable);inline;
  811. procedure remove_helpers(st:tsymtable);
  812. procedure remove_generics(st:tsymtable);
  813. procedure pushcommon(st:tsymtable);inline;
  814. public
  815. procedure push(st: TSymtable); override;
  816. procedure pushafter(st,afterst:TSymtable); override;
  817. procedure pop(st: TSymtable); override;
  818. end;
  819. var
  820. current_structdef: tabstractrecorddef; { used for private functions check !! }
  821. current_genericdef: tstoreddef; { used to reject declaration of generic class inside generic class }
  822. current_specializedef: tstoreddef; { used to implement usage of generic class in itself }
  823. { default types }
  824. generrordef, { error in definition }
  825. voidpointertype, { pointer for Void-pointeddef }
  826. charpointertype, { pointer for Char-pointeddef }
  827. widecharpointertype, { pointer for WideChar-pointeddef }
  828. {$ifdef x86}
  829. voidnearpointertype,
  830. voidnearcspointertype,
  831. voidneardspointertype,
  832. voidnearsspointertype,
  833. voidnearespointertype,
  834. voidnearfspointertype,
  835. voidneargspointertype,
  836. {$ifdef i8086}
  837. voidfarpointertype,
  838. voidhugepointertype,
  839. bytefarpointertype, { used for Mem[] }
  840. wordfarpointertype, { used for MemW[] }
  841. longintfarpointertype, { used for MemL[] }
  842. {$endif i8086}
  843. {$endif x86}
  844. cundefinedtype,
  845. cformaltype, { unique formal definition }
  846. ctypedformaltype, { unique typed formal definition }
  847. voidtype, { Void (procedure) }
  848. cansichartype, { Char }
  849. cwidechartype, { WideChar }
  850. pasbool8type, { boolean type }
  851. pasbool16type,
  852. pasbool32type,
  853. pasbool64type,
  854. bool8type,
  855. bool16type,
  856. bool32type,
  857. bool64type, { implement me }
  858. u8inttype, { 8-Bit unsigned integer }
  859. s8inttype, { 8-Bit signed integer }
  860. u16inttype, { 16-Bit unsigned integer }
  861. s16inttype, { 16-Bit signed integer }
  862. u32inttype, { 32-Bit unsigned integer }
  863. s32inttype, { 32-Bit signed integer }
  864. u64inttype, { 64-bit unsigned integer }
  865. s64inttype, { 64-bit signed integer }
  866. s32floattype, { 32 bit floating point number }
  867. s64floattype, { 64 bit floating point number }
  868. s80floattype, { 80 bit floating point number }
  869. sc80floattype, { 80 bit floating point number but stored like in C }
  870. s64currencytype, { pointer to a currency type }
  871. cshortstringtype, { pointer to type of short string const }
  872. clongstringtype, { pointer to type of long string const }
  873. cansistringtype, { pointer to type of ansi string const }
  874. cwidestringtype, { pointer to type of wide string const }
  875. cunicodestringtype,
  876. openshortstringtype, { pointer to type of an open shortstring,
  877. needed for readln() }
  878. openchararraytype, { pointer to type of an open array of char,
  879. needed for readln() }
  880. cfiletype, { get the same definition for all file }
  881. { used for stabs }
  882. methodpointertype, { typecasting of methodpointers to extract self }
  883. hresultdef,
  884. { we use only one variant def for every variant class }
  885. cvarianttype,
  886. colevarianttype,
  887. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  888. sinttype,
  889. uinttype,
  890. { integer types corresponding to OS_SINT/OS_INT }
  891. ossinttype,
  892. osuinttype,
  893. { unsigned and signed ord type with the same size as a pointer }
  894. ptruinttype,
  895. ptrsinttype,
  896. { several types to simulate more or less C++ objects for GDB }
  897. vmttype,
  898. vmtarraytype,
  899. pvmttype : tdef; { type of classrefs, used for stabs }
  900. { pointer to the anchestor of all classes }
  901. class_tobject : tobjectdef;
  902. { pointer to the ancestor of all COM interfaces }
  903. interface_iunknown : tobjectdef;
  904. { pointer to the ancestor of all dispinterfaces }
  905. interface_idispatch : tobjectdef;
  906. { pointer to the TGUID type
  907. of all interfaces }
  908. rec_tguid : trecorddef;
  909. { pointer to jump buffer }
  910. rec_jmp_buf : trecorddef;
  911. { Objective-C base types }
  912. objc_metaclasstype,
  913. objc_superclasstype,
  914. objc_idtype,
  915. objc_seltype : tpointerdef;
  916. objc_objecttype : trecorddef;
  917. { base type of @protocol(protocolname) Objective-C statements }
  918. objc_protocoltype : tobjectdef;
  919. { helper types for for-in "fast enumeration" support in Objective-C 2.0 }
  920. objc_fastenumeration : tobjectdef;
  921. objc_fastenumerationstate : trecorddef;
  922. { Java base types }
  923. { java.lang.Object }
  924. java_jlobject : tobjectdef;
  925. { java.lang.Throwable }
  926. java_jlthrowable : tobjectdef;
  927. { FPC base type for records }
  928. java_fpcbaserecordtype : tobjectdef;
  929. { java.lang.String }
  930. java_jlstring : tobjectdef;
  931. { java.lang.Enum }
  932. java_jlenum : tobjectdef;
  933. { java.util.EnumSet }
  934. java_juenumset : tobjectdef;
  935. { java.util.BitSet }
  936. java_jubitset : tobjectdef;
  937. { FPC java implementation of ansistrings }
  938. java_ansistring : tobjectdef;
  939. { FPC java implementation of shortstrings }
  940. java_shortstring : tobjectdef;
  941. { FPC java procvar base class }
  942. java_procvarbase : tobjectdef;
  943. const
  944. {$ifdef i8086}
  945. pbestrealtype : ^tdef = @s80floattype;
  946. {$endif}
  947. {$ifdef i386}
  948. pbestrealtype : ^tdef = @s80floattype;
  949. {$endif}
  950. {$ifdef x86_64}
  951. pbestrealtype : ^tdef = @s80floattype;
  952. {$endif}
  953. {$ifdef m68k}
  954. pbestrealtype : ^tdef = @s64floattype;
  955. {$endif}
  956. {$ifdef alpha}
  957. pbestrealtype : ^tdef = @s64floattype;
  958. {$endif}
  959. {$ifdef powerpc}
  960. pbestrealtype : ^tdef = @s64floattype;
  961. {$endif}
  962. {$ifdef POWERPC64}
  963. pbestrealtype : ^tdef = @s64floattype;
  964. {$endif}
  965. {$ifdef ia64}
  966. pbestrealtype : ^tdef = @s64floattype;
  967. {$endif}
  968. {$ifdef SPARC}
  969. pbestrealtype : ^tdef = @s64floattype;
  970. {$endif SPARC}
  971. {$ifdef vis}
  972. pbestrealtype : ^tdef = @s64floattype;
  973. {$endif vis}
  974. {$ifdef ARM}
  975. pbestrealtype : ^tdef = @s64floattype;
  976. {$endif ARM}
  977. {$ifdef MIPS}
  978. pbestrealtype : ^tdef = @s64floattype;
  979. {$endif MIPS}
  980. {$ifdef AVR}
  981. pbestrealtype : ^tdef = @s64floattype;
  982. {$endif AVR}
  983. {$ifdef JVM}
  984. pbestrealtype : ^tdef = @s64floattype;
  985. {$endif JVM}
  986. {$ifdef AARCH64}
  987. pbestrealtype : ^tdef = @s64floattype;
  988. {$endif AARCH64}
  989. function make_mangledname(const typeprefix:TSymStr;st:TSymtable;const suffix:TSymStr):TSymStr;
  990. function make_dllmangledname(const dllname,importname:TSymStr;
  991. import_nr : word; pco : tproccalloption):TSymStr;
  992. { should be in the types unit, but the types unit uses the node stuff :( }
  993. function is_interfacecom(def: tdef): boolean;
  994. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  995. function is_any_interface_kind(def: tdef): boolean;
  996. function is_interfacecorba(def: tdef): boolean;
  997. function is_interface(def: tdef): boolean;
  998. function is_dispinterface(def: tdef): boolean;
  999. function is_object(def: tdef): boolean;
  1000. function is_class(def: tdef): boolean;
  1001. function is_cppclass(def: tdef): boolean;
  1002. function is_objectpascal_helper(def: tdef): boolean;
  1003. function is_objcclass(def: tdef): boolean;
  1004. function is_objcclassref(def: tdef): boolean;
  1005. function is_objcprotocol(def: tdef): boolean;
  1006. function is_objccategory(def: tdef): boolean;
  1007. function is_objc_class_or_protocol(def: tdef): boolean;
  1008. function is_objc_protocol_or_category(def: tdef): boolean;
  1009. function is_classhelper(def: tdef): boolean;
  1010. function is_class_or_interface(def: tdef): boolean;
  1011. function is_class_or_interface_or_objc(def: tdef): boolean;
  1012. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  1013. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  1014. function is_class_or_interface_or_object(def: tdef): boolean;
  1015. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  1016. function is_implicit_pointer_object_type(def: tdef): boolean;
  1017. function is_class_or_object(def: tdef): boolean;
  1018. function is_record(def: tdef): boolean;
  1019. function is_javaclass(def: tdef): boolean;
  1020. function is_javaclassref(def: tdef): boolean;
  1021. function is_javainterface(def: tdef): boolean;
  1022. function is_java_class_or_interface(def: tdef): boolean;
  1023. procedure loadobjctypes;
  1024. procedure maybeloadcocoatypes;
  1025. function use_vectorfpu(def : tdef) : boolean;
  1026. { returns a pointerdef for def, reusing an existing one in case it exists
  1027. in the current module }
  1028. function getpointerdef(def: tdef): tpointerdef;
  1029. { returns an arraydef for an array containing a single array of def, resuing
  1030. an existing one in case it exists in the current module }
  1031. function getsingletonarraydef(def: tdef): tarraydef;
  1032. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  1033. function getansistringcodepage:tstringencoding; inline;
  1034. function getansistringdef:tstringdef;
  1035. function getparaencoding(def:tdef):tstringencoding; inline;
  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. begin
  2810. inherited create(setdef);
  2811. elementdef:=def;
  2812. setmax:=high;
  2813. if (current_settings.setalloc=0) then
  2814. begin
  2815. setbase:=0;
  2816. if (high<32) then
  2817. savesize:=Sizeof(longint)
  2818. else if (high<256) then
  2819. savesize:=32
  2820. else
  2821. savesize:=(high+7) div 8
  2822. end
  2823. else
  2824. begin
  2825. setallocbits:=current_settings.setalloc*8;
  2826. setbase:=low and not(setallocbits-1);
  2827. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  2828. savesize:=packedsavesize;
  2829. if savesize=3 then
  2830. savesize:=4;
  2831. end;
  2832. end;
  2833. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  2834. begin
  2835. inherited ppuload(setdef,ppufile);
  2836. ppufile.getderef(elementdefderef);
  2837. savesize:=ppufile.getaint;
  2838. setbase:=ppufile.getaint;
  2839. setmax:=ppufile.getaint;
  2840. end;
  2841. function tsetdef.getcopy : tstoreddef;
  2842. begin
  2843. result:=tsetdef.create(elementdef,setbase,setmax);
  2844. { the copy might have been created with a different setalloc setting }
  2845. tsetdef(result).savesize:=savesize;
  2846. end;
  2847. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  2848. begin
  2849. inherited ppuwrite(ppufile);
  2850. ppufile.putderef(elementdefderef);
  2851. ppufile.putaint(savesize);
  2852. ppufile.putaint(setbase);
  2853. ppufile.putaint(setmax);
  2854. ppufile.writeentry(ibsetdef);
  2855. end;
  2856. procedure tsetdef.buildderef;
  2857. begin
  2858. inherited buildderef;
  2859. elementdefderef.build(elementdef);
  2860. end;
  2861. procedure tsetdef.deref;
  2862. begin
  2863. inherited deref;
  2864. elementdef:=tdef(elementdefderef.resolve);
  2865. end;
  2866. function tsetdef.is_publishable : boolean;
  2867. begin
  2868. is_publishable:=savesize in [1,2,4];
  2869. end;
  2870. function tsetdef.GetTypeName : string;
  2871. begin
  2872. if assigned(elementdef) then
  2873. GetTypeName:='Set Of '+elementdef.typename
  2874. else
  2875. GetTypeName:='Empty Set';
  2876. end;
  2877. {***************************************************************************
  2878. TFORMALDEF
  2879. ***************************************************************************}
  2880. constructor tformaldef.create(Atyped:boolean);
  2881. begin
  2882. inherited create(formaldef);
  2883. typed:=Atyped;
  2884. savesize:=0;
  2885. end;
  2886. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  2887. begin
  2888. inherited ppuload(formaldef,ppufile);
  2889. typed:=boolean(ppufile.getbyte);
  2890. savesize:=0;
  2891. end;
  2892. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  2893. begin
  2894. inherited ppuwrite(ppufile);
  2895. ppufile.putbyte(byte(typed));
  2896. ppufile.writeentry(ibformaldef);
  2897. end;
  2898. function tformaldef.GetTypeName : string;
  2899. begin
  2900. if typed then
  2901. GetTypeName:='<Typed formal type>'
  2902. else
  2903. GetTypeName:='<Formal type>';
  2904. end;
  2905. {***************************************************************************
  2906. TARRAYDEF
  2907. ***************************************************************************}
  2908. constructor tarraydef.create(l,h:asizeint;def:tdef);
  2909. begin
  2910. inherited create(arraydef);
  2911. lowrange:=l;
  2912. highrange:=h;
  2913. rangedef:=def;
  2914. _elementdef:=nil;
  2915. arrayoptions:=[];
  2916. symtable:=tarraysymtable.create(self);
  2917. end;
  2918. destructor tarraydef.destroy;
  2919. begin
  2920. symtable.free;
  2921. symtable:=nil;
  2922. inherited;
  2923. end;
  2924. constructor tarraydef.create_from_pointer(def:tdef);
  2925. begin
  2926. { use -1 so that the elecount will not overflow }
  2927. self.create(0,high(asizeint)-1,ptrsinttype);
  2928. arrayoptions:=[ado_IsConvertedPointer];
  2929. setelementdef(def);
  2930. end;
  2931. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2932. begin
  2933. inherited ppuload(arraydef,ppufile);
  2934. { the addresses are calculated later }
  2935. ppufile.getderef(_elementdefderef);
  2936. ppufile.getderef(rangedefderef);
  2937. lowrange:=ppufile.getasizeint;
  2938. highrange:=ppufile.getasizeint;
  2939. ppufile.getsmallset(arrayoptions);
  2940. symtable:=tarraysymtable.create(self);
  2941. tarraysymtable(symtable).ppuload(ppufile)
  2942. end;
  2943. function tarraydef.getcopy : tstoreddef;
  2944. begin
  2945. result:=tarraydef.create(lowrange,highrange,rangedef);
  2946. tarraydef(result).arrayoptions:=arrayoptions;
  2947. tarraydef(result)._elementdef:=_elementdef;
  2948. end;
  2949. procedure tarraydef.buildderef;
  2950. begin
  2951. inherited buildderef;
  2952. tarraysymtable(symtable).buildderef;
  2953. _elementdefderef.build(_elementdef);
  2954. rangedefderef.build(rangedef);
  2955. end;
  2956. procedure tarraydef.deref;
  2957. begin
  2958. inherited deref;
  2959. tarraysymtable(symtable).deref;
  2960. _elementdef:=tdef(_elementdefderef.resolve);
  2961. rangedef:=tdef(rangedefderef.resolve);
  2962. fillgenericparas(symtable);
  2963. end;
  2964. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2965. begin
  2966. inherited ppuwrite(ppufile);
  2967. ppufile.putderef(_elementdefderef);
  2968. ppufile.putderef(rangedefderef);
  2969. ppufile.putasizeint(lowrange);
  2970. ppufile.putasizeint(highrange);
  2971. ppufile.putsmallset(arrayoptions);
  2972. ppufile.writeentry(ibarraydef);
  2973. tarraysymtable(symtable).ppuwrite(ppufile);
  2974. end;
  2975. function tarraydef.elesize : asizeint;
  2976. begin
  2977. if (ado_IsBitPacked in arrayoptions) then
  2978. internalerror(2006080101);
  2979. if assigned(_elementdef) then
  2980. result:=_elementdef.size
  2981. else
  2982. result:=0;
  2983. end;
  2984. function tarraydef.elepackedbitsize : asizeint;
  2985. begin
  2986. if not(ado_IsBitPacked in arrayoptions) then
  2987. internalerror(2006080102);
  2988. if assigned(_elementdef) then
  2989. result:=_elementdef.packedbitsize
  2990. else
  2991. result:=0;
  2992. end;
  2993. function tarraydef.elecount : asizeuint;
  2994. var
  2995. qhigh,qlow : qword;
  2996. begin
  2997. if ado_IsDynamicArray in arrayoptions then
  2998. begin
  2999. result:=0;
  3000. exit;
  3001. end;
  3002. if (highrange>0) and (lowrange<0) then
  3003. begin
  3004. qhigh:=highrange;
  3005. qlow:=qword(-lowrange);
  3006. { prevent overflow, return 0 to indicate overflow }
  3007. if qhigh+qlow>qword(high(asizeint)-1) then
  3008. result:=0
  3009. else
  3010. result:=qhigh+qlow+1;
  3011. end
  3012. else
  3013. result:=int64(highrange)-lowrange+1;
  3014. end;
  3015. function tarraydef.size : asizeint;
  3016. var
  3017. cachedelecount : asizeuint;
  3018. cachedelesize : asizeint;
  3019. begin
  3020. if ado_IsDynamicArray in arrayoptions then
  3021. begin
  3022. size:=sizeof(pint);
  3023. exit;
  3024. end;
  3025. { Tarraydef.size may never be called for an open array! }
  3026. if highrange<lowrange then
  3027. internalerror(99080501);
  3028. if not (ado_IsBitPacked in arrayoptions) then
  3029. cachedelesize:=elesize
  3030. else
  3031. cachedelesize := elepackedbitsize;
  3032. cachedelecount:=elecount;
  3033. if (cachedelesize = 0) then
  3034. begin
  3035. size := 0;
  3036. exit;
  3037. end;
  3038. if (cachedelecount = 0) then
  3039. begin
  3040. size := -1;
  3041. exit;
  3042. end;
  3043. { prevent overflow, return -1 to indicate overflow }
  3044. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  3045. if (cachedelecount > asizeuint(high(asizeint))) or
  3046. ((high(asizeint) div cachedelesize) < asizeint(cachedelecount)) or
  3047. { also lowrange*elesize must be < high(asizeint) to prevent overflow when
  3048. accessing the array, see ncgmem (PFV) }
  3049. ((high(asizeint) div cachedelesize) < abs(lowrange)) then
  3050. begin
  3051. result:=-1;
  3052. exit;
  3053. end;
  3054. result:=cachedelesize*asizeint(cachedelecount);
  3055. if (ado_IsBitPacked in arrayoptions) then
  3056. { can't just add 7 and divide by 8, because that may overflow }
  3057. result:=result div 8 + ord((result mod 8)<>0);
  3058. end;
  3059. procedure tarraydef.setelementdef(def:tdef);
  3060. begin
  3061. _elementdef:=def;
  3062. if not(
  3063. (ado_IsDynamicArray in arrayoptions) or
  3064. (ado_IsConvertedPointer in arrayoptions) or
  3065. (highrange<lowrange)
  3066. ) and
  3067. (size=-1) then
  3068. Message(sym_e_segment_too_large);
  3069. end;
  3070. function tarraydef.alignment : shortint;
  3071. begin
  3072. { alignment of dyn. arrays doesn't depend on the element size }
  3073. if (ado_IsDynamicArray in arrayoptions) then
  3074. alignment:=size_2_align(sizeof(pint))
  3075. { alignment is the target alignment for the used load size }
  3076. else if (ado_IsBitPacked in arrayoptions) and
  3077. (elementdef.typ in [enumdef,orddef]) then
  3078. alignment:=cgsize_orddef(int_cgsize(packedbitsloadsize(elepackedbitsize))).alignment
  3079. { alignment is the alignment of the elements }
  3080. else
  3081. alignment:=elementdef.alignment
  3082. end;
  3083. function tarraydef.needs_inittable : boolean;
  3084. begin
  3085. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  3086. end;
  3087. function tarraydef.needs_separate_initrtti : boolean;
  3088. begin
  3089. if ado_IsBitPacked in arrayoptions then
  3090. result:=false
  3091. else
  3092. result:=elementdef.needs_separate_initrtti;
  3093. end;
  3094. function tarraydef.GetTypeName : string;
  3095. begin
  3096. if (ado_IsConstString in arrayoptions) then
  3097. result:='Constant String'
  3098. else if (ado_isarrayofconst in arrayoptions) or
  3099. (ado_isConstructor in arrayoptions) then
  3100. begin
  3101. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  3102. GetTypeName:='Array Of Const'
  3103. else
  3104. GetTypeName:='{Array Of Const/Constant Open} Array of '+elementdef.typename;
  3105. end
  3106. else if (ado_IsDynamicArray in arrayoptions) then
  3107. GetTypeName:='{Dynamic} Array Of '+elementdef.typename
  3108. else if ((highrange=-1) and (lowrange=0)) then
  3109. GetTypeName:='{Open} Array Of '+elementdef.typename
  3110. else
  3111. begin
  3112. result := '';
  3113. if (ado_IsBitPacked in arrayoptions) then
  3114. result:='BitPacked ';
  3115. if rangedef.typ=enumdef then
  3116. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  3117. else
  3118. result:=result+'Array['+tostr(lowrange)+'..'+
  3119. tostr(highrange)+'] Of '+elementdef.typename
  3120. end;
  3121. end;
  3122. function tarraydef.getmangledparaname : TSymStr;
  3123. begin
  3124. if ado_isarrayofconst in arrayoptions then
  3125. getmangledparaname:='array_of_const'
  3126. else
  3127. if ((highrange=-1) and (lowrange=0)) then
  3128. getmangledparaname:='array_of_'+elementdef.mangledparaname
  3129. else
  3130. internalerror(200204176);
  3131. end;
  3132. function tarraydef.is_publishable : boolean;
  3133. begin
  3134. Result:=ado_IsDynamicArray in arrayoptions;
  3135. end;
  3136. {***************************************************************************
  3137. tabstractrecorddef
  3138. ***************************************************************************}
  3139. constructor tabstractrecorddef.create(const n:string; dt:tdeftyp);
  3140. begin
  3141. inherited create(dt);
  3142. objname:=stringdup(upper(n));
  3143. objrealname:=stringdup(n);
  3144. objectoptions:=[];
  3145. if assigned(current_module.namespace) then
  3146. begin
  3147. import_lib:=stringdup(current_module.namespace^);
  3148. replace(import_lib^,'.','/');
  3149. end;
  3150. end;
  3151. constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3152. begin
  3153. inherited ppuload(dt,ppufile);
  3154. objrealname:=stringdup(ppufile.getstring);
  3155. objname:=stringdup(upper(objrealname^));
  3156. import_lib:=stringdup(ppufile.getstring);
  3157. { only used for external C++ classes and Java classes/records }
  3158. if (import_lib^='') then
  3159. stringdispose(import_lib);
  3160. ppufile.getsmallset(objectoptions);
  3161. end;
  3162. procedure tabstractrecorddef.ppuwrite(ppufile: tcompilerppufile);
  3163. begin
  3164. inherited ppuwrite(ppufile);
  3165. ppufile.putstring(objrealname^);
  3166. if assigned(import_lib) then
  3167. ppufile.putstring(import_lib^)
  3168. else
  3169. ppufile.putstring('');
  3170. ppufile.putsmallset(objectoptions);
  3171. end;
  3172. destructor tabstractrecorddef.destroy;
  3173. begin
  3174. stringdispose(objname);
  3175. stringdispose(objrealname);
  3176. stringdispose(import_lib);
  3177. tcinitcode.free;
  3178. inherited destroy;
  3179. end;
  3180. procedure tabstractrecorddef.check_forwards;
  3181. begin
  3182. { the defs of a copied def are defined for the original type only }
  3183. if not(df_copied_def in defoptions) then
  3184. tstoredsymtable(symtable).check_forwards;
  3185. end;
  3186. function tabstractrecorddef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  3187. var
  3188. i: longint;
  3189. sym: tsym;
  3190. begin
  3191. for i:=0 to symtable.SymList.Count-1 do
  3192. begin
  3193. sym:=tsym(symtable.SymList[i]);
  3194. if sym.typ=procsym then
  3195. begin
  3196. result:=tprocsym(sym).find_procdef_bytype(pt);
  3197. if assigned(result) then
  3198. exit;
  3199. end;
  3200. end;
  3201. result:=nil;
  3202. end;
  3203. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  3204. begin
  3205. if t=gs_record then
  3206. GetSymtable:=symtable
  3207. else
  3208. GetSymtable:=nil;
  3209. end;
  3210. function tabstractrecorddef.is_packed:boolean;
  3211. begin
  3212. result:=tabstractrecordsymtable(symtable).is_packed;
  3213. end;
  3214. function tabstractrecorddef.RttiName: string;
  3215. begin
  3216. Result:=OwnerHierarchyName+objrealname^;
  3217. end;
  3218. function tabstractrecorddef.search_enumerator_get: tprocdef;
  3219. var
  3220. sym : tsym;
  3221. i : integer;
  3222. pd : tprocdef;
  3223. hashedid : THashedIDString;
  3224. begin
  3225. result:=nil;
  3226. hashedid.id:='GETENUMERATOR';
  3227. sym:=tsym(symtable.FindWithHash(hashedid));
  3228. if assigned(sym) and (sym.typ=procsym) then
  3229. begin
  3230. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  3231. begin
  3232. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3233. if (pd.proctypeoption = potype_function) and
  3234. (is_class_or_interface_or_object(pd.returndef) or is_record(pd.returndef)) and
  3235. (pd.visibility >= vis_public) then
  3236. begin
  3237. result:=pd;
  3238. exit;
  3239. end;
  3240. end;
  3241. end;
  3242. end;
  3243. function tabstractrecorddef.search_enumerator_move: tprocdef;
  3244. var
  3245. sym : tsym;
  3246. i : integer;
  3247. pd : tprocdef;
  3248. hashedid : THashedIDString;
  3249. begin
  3250. result:=nil;
  3251. // first search for po_enumerator_movenext method modifier
  3252. // then search for public function MoveNext: Boolean
  3253. for i:=0 to symtable.SymList.Count-1 do
  3254. begin
  3255. sym:=TSym(symtable.SymList[i]);
  3256. if (sym.typ=procsym) then
  3257. begin
  3258. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  3259. if assigned(pd) then
  3260. begin
  3261. result:=pd;
  3262. exit;
  3263. end;
  3264. end;
  3265. end;
  3266. hashedid.id:='MOVENEXT';
  3267. sym:=tsym(symtable.FindWithHash(hashedid));
  3268. if assigned(sym) and (sym.typ=procsym) then
  3269. begin
  3270. for i:=0 to Tprocsym(sym).ProcdefList.Count-1 do
  3271. begin
  3272. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  3273. if (pd.proctypeoption = potype_function) and
  3274. is_boolean(pd.returndef) and
  3275. (pd.minparacount = 0) and
  3276. (pd.visibility >= vis_public) then
  3277. begin
  3278. result:=pd;
  3279. exit;
  3280. end;
  3281. end;
  3282. end;
  3283. end;
  3284. function tabstractrecorddef.search_enumerator_current: tsym;
  3285. var
  3286. sym: tsym;
  3287. i: integer;
  3288. hashedid : THashedIDString;
  3289. begin
  3290. result:=nil;
  3291. // first search for ppo_enumerator_current property modifier
  3292. // then search for public property Current
  3293. for i:=0 to symtable.SymList.Count-1 do
  3294. begin
  3295. sym:=TSym(symtable.SymList[i]);
  3296. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  3297. begin
  3298. result:=sym;
  3299. exit;
  3300. end;
  3301. end;
  3302. hashedid.id:='CURRENT';
  3303. sym:=tsym(symtable.FindWithHash(hashedid));
  3304. if assigned(sym) and (sym.typ=propertysym) and
  3305. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  3306. begin
  3307. result:=sym;
  3308. exit;
  3309. end;
  3310. end;
  3311. function tabstractrecorddef.jvm_full_typename(with_package_name: boolean): string;
  3312. var
  3313. st: tsymtable;
  3314. enclosingdef: tdef;
  3315. begin
  3316. if typ=objectdef then
  3317. result:=tobjectdef(self).objextname^
  3318. else if assigned(typesym) then
  3319. result:=typesym.realname
  3320. { have to generate anonymous nested type in current unit/class/record }
  3321. else
  3322. internalerror(2011032601);
  3323. { in case of specializations, add some extras to prevent name conflicts
  3324. with nested classes }
  3325. if df_specialization in defoptions then
  3326. result:='$'+result+'$specialization$';
  3327. st:=owner;
  3328. while assigned(st) and
  3329. (st.symtabletype in [objectsymtable,recordsymtable,localsymtable]) do
  3330. begin
  3331. { nested classes are named as "OuterClass$InnerClass" }
  3332. enclosingdef:=tdef(st.defowner);
  3333. if enclosingdef.typ=procdef then
  3334. result:=result+tprocdef(enclosingdef).procsym.realname+'$$'+tostr(tprocdef(enclosingdef).procsym.symid)+'$'
  3335. else if enclosingdef.typ=objectdef then
  3336. result:=tobjectdef(enclosingdef).objextname^+'$'+result
  3337. else if assigned(enclosingdef.typesym) then
  3338. result:=enclosingdef.typesym.realname+'$'+result
  3339. else
  3340. internalerror(2011060305);
  3341. st:=enclosingdef.owner;
  3342. end;
  3343. if with_package_name and
  3344. assigned(import_lib) then
  3345. result:=import_lib^+'/'+result;
  3346. end;
  3347. function tabstractrecorddef.contains_float_field: boolean;
  3348. var
  3349. i : longint;
  3350. begin
  3351. result:=true;
  3352. for i:=0 to symtable.symlist.count-1 do
  3353. begin
  3354. if tsym(symtable.symlist[i]).typ<>fieldvarsym then
  3355. continue;
  3356. if assigned(tfieldvarsym(symtable.symlist[i]).vardef) and
  3357. tstoreddef(tfieldvarsym(symtable.symlist[i]).vardef).is_fpuregable then
  3358. exit;
  3359. end;
  3360. result:=false;
  3361. end;
  3362. {***************************************************************************
  3363. trecorddef
  3364. ***************************************************************************}
  3365. constructor trecorddef.create(const n:string; p:TSymtable);
  3366. begin
  3367. inherited create(n,recorddef);
  3368. symtable:=p;
  3369. { we can own the symtable only if nobody else owns a copy so far }
  3370. if symtable.refcount=1 then
  3371. symtable.defowner:=self;
  3372. isunion:=false;
  3373. end;
  3374. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  3375. procedure readvariantrecdesc(var variantrecdesc : pvariantrecdesc);
  3376. var
  3377. i,j : longint;
  3378. begin
  3379. if ppufile.getbyte=1 then
  3380. begin
  3381. new(variantrecdesc);
  3382. ppufile.getderef(variantrecdesc^.variantselectorderef);
  3383. SetLength(variantrecdesc^.branches,ppufile.getasizeint);
  3384. for i:=0 to high(variantrecdesc^.branches) do
  3385. begin
  3386. SetLength(variantrecdesc^.branches[i].values,ppufile.getasizeint);
  3387. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3388. variantrecdesc^.branches[i].values[j]:=ppufile.getexprint;
  3389. readvariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3390. end;
  3391. end
  3392. else
  3393. variantrecdesc:=nil;
  3394. end;
  3395. begin
  3396. inherited ppuload(recorddef,ppufile);
  3397. if df_copied_def in defoptions then
  3398. ppufile.getderef(cloneddefderef)
  3399. else
  3400. begin
  3401. symtable:=trecordsymtable.create(objrealname^,0);
  3402. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  3403. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  3404. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  3405. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  3406. trecordsymtable(symtable).datasize:=ppufile.getasizeint;
  3407. trecordsymtable(symtable).paddingsize:=ppufile.getword;
  3408. trecordsymtable(symtable).ppuload(ppufile);
  3409. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3410. but because iso mode supports no units, there is no need to store the variantrecdesc
  3411. in the ppu
  3412. }
  3413. // readvariantrecdesc(variantrecdesc);
  3414. { requires usefieldalignment to be set }
  3415. symtable.defowner:=self;
  3416. end;
  3417. isunion:=false;
  3418. end;
  3419. destructor trecorddef.destroy;
  3420. begin
  3421. if assigned(symtable) then
  3422. begin
  3423. symtable.free;
  3424. symtable:=nil;
  3425. end;
  3426. inherited destroy;
  3427. end;
  3428. function trecorddef.getcopy : tstoreddef;
  3429. begin
  3430. result:=trecorddef.create(objrealname^,symtable.getcopy);
  3431. trecorddef(result).isunion:=isunion;
  3432. include(trecorddef(result).defoptions,df_copied_def);
  3433. if assigned(tcinitcode) then
  3434. trecorddef(result).tcinitcode:=tcinitcode.getcopy;
  3435. if assigned(import_lib) then
  3436. trecorddef(result).import_lib:=stringdup(import_lib^);
  3437. end;
  3438. function trecorddef.needs_inittable : boolean;
  3439. begin
  3440. needs_inittable:=trecordsymtable(symtable).needs_init_final
  3441. end;
  3442. function trecorddef.needs_separate_initrtti : boolean;
  3443. begin
  3444. result:=true;
  3445. end;
  3446. procedure trecorddef.buildderef;
  3447. begin
  3448. inherited buildderef;
  3449. if df_copied_def in defoptions then
  3450. cloneddefderef.build(symtable.defowner)
  3451. else
  3452. tstoredsymtable(symtable).buildderef;
  3453. end;
  3454. procedure trecorddef.buildderefimpl;
  3455. begin
  3456. inherited buildderefimpl;
  3457. if not (df_copied_def in defoptions) then
  3458. tstoredsymtable(symtable).buildderefimpl;
  3459. end;
  3460. procedure trecorddef.deref;
  3461. begin
  3462. inherited deref;
  3463. { now dereference the definitions }
  3464. if df_copied_def in defoptions then
  3465. begin
  3466. cloneddef:=trecorddef(cloneddefderef.resolve);
  3467. symtable:=cloneddef.symtable.getcopy;
  3468. end
  3469. else
  3470. tstoredsymtable(symtable).deref;
  3471. fillgenericparas(symtable);
  3472. { assign TGUID? load only from system unit }
  3473. if not(assigned(rec_tguid)) and
  3474. (upper(typename)='TGUID') and
  3475. assigned(owner) and
  3476. assigned(owner.name) and
  3477. (owner.name^='SYSTEM') then
  3478. rec_tguid:=self;
  3479. { assign JMP_BUF? load only from system unit }
  3480. if not(assigned(rec_jmp_buf)) and
  3481. (upper(typename)='JMP_BUF') and
  3482. assigned(owner) and
  3483. assigned(owner.name) and
  3484. (owner.name^='SYSTEM') then
  3485. rec_jmp_buf:=self;
  3486. end;
  3487. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  3488. procedure writevariantrecdesc(variantrecdesc : pvariantrecdesc);
  3489. var
  3490. i,j : longint;
  3491. begin
  3492. if assigned(variantrecdesc) then
  3493. begin
  3494. ppufile.putbyte(1);
  3495. ppufile.putderef(variantrecdesc^.variantselectorderef);
  3496. ppufile.putasizeint(length(variantrecdesc^.branches));
  3497. for i:=0 to high(variantrecdesc^.branches) do
  3498. begin
  3499. ppufile.putasizeint(length(variantrecdesc^.branches[i].values));
  3500. for j:=0 to high(variantrecdesc^.branches[i].values) do
  3501. ppufile.putexprint(variantrecdesc^.branches[i].values[j]);
  3502. writevariantrecdesc(variantrecdesc^.branches[i].nestedvariant);
  3503. end;
  3504. end
  3505. else
  3506. ppufile.putbyte(0);
  3507. end;
  3508. begin
  3509. inherited ppuwrite(ppufile);
  3510. if df_copied_def in defoptions then
  3511. ppufile.putderef(cloneddefderef)
  3512. else
  3513. begin
  3514. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  3515. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  3516. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  3517. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  3518. ppufile.putasizeint(trecordsymtable(symtable).datasize);
  3519. ppufile.putword(trecordsymtable(symtable).paddingsize);
  3520. { the variantrecdesc is needed only for iso-like new statements new(prec,1,2,3 ...);
  3521. but because iso mode supports no units, there is no need to store the variantrecdesc
  3522. in the ppu
  3523. }
  3524. // writevariantrecdesc(variantrecdesc);
  3525. end;
  3526. ppufile.writeentry(ibrecorddef);
  3527. if not(df_copied_def in defoptions) then
  3528. trecordsymtable(symtable).ppuwrite(ppufile);
  3529. end;
  3530. function trecorddef.size:asizeint;
  3531. begin
  3532. result:=trecordsymtable(symtable).datasize;
  3533. end;
  3534. function trecorddef.alignment:shortint;
  3535. begin
  3536. alignment:=trecordsymtable(symtable).recordalignment;
  3537. end;
  3538. function trecorddef.padalignment:shortint;
  3539. begin
  3540. padalignment := trecordsymtable(symtable).padalignment;
  3541. end;
  3542. function trecorddef.GetTypeName : string;
  3543. begin
  3544. GetTypeName:='<record type>'
  3545. end;
  3546. {***************************************************************************
  3547. TABSTRACTPROCDEF
  3548. ***************************************************************************}
  3549. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  3550. begin
  3551. inherited create(dt);
  3552. parast:=tparasymtable.create(self,level);
  3553. paras:=nil;
  3554. minparacount:=0;
  3555. maxparacount:=0;
  3556. proctypeoption:=potype_none;
  3557. proccalloption:=pocall_none;
  3558. procoptions:=[];
  3559. {$ifdef i8086}
  3560. if current_settings.x86memorymodel in x86_far_code_models then
  3561. procoptions:=procoptions+[po_far];
  3562. {$endif i8086}
  3563. returndef:=voidtype;
  3564. savesize:=sizeof(pint);
  3565. callerargareasize:=0;
  3566. calleeargareasize:=0;
  3567. has_paraloc_info:=callnoside;
  3568. funcretloc[callerside].init;
  3569. funcretloc[calleeside].init;
  3570. check_mark_as_nested;
  3571. end;
  3572. destructor tabstractprocdef.destroy;
  3573. begin
  3574. if assigned(paras) then
  3575. begin
  3576. {$ifdef MEMDEBUG}
  3577. memprocpara.start;
  3578. {$endif MEMDEBUG}
  3579. paras.free;
  3580. paras:=nil;
  3581. {$ifdef MEMDEBUG}
  3582. memprocpara.stop;
  3583. {$endif MEMDEBUG}
  3584. end;
  3585. if assigned(parast) then
  3586. begin
  3587. {$ifdef MEMDEBUG}
  3588. memprocparast.start;
  3589. {$endif MEMDEBUG}
  3590. parast.free;
  3591. parast:=nil;
  3592. {$ifdef MEMDEBUG}
  3593. memprocparast.stop;
  3594. {$endif MEMDEBUG}
  3595. end;
  3596. funcretloc[callerside].done;
  3597. funcretloc[calleeside].done;
  3598. inherited destroy;
  3599. end;
  3600. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  3601. begin
  3602. if (tsym(p).typ<>paravarsym) then
  3603. exit;
  3604. inc(plongint(arg)^);
  3605. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  3606. begin
  3607. if not assigned(tparavarsym(p).defaultconstsym) then
  3608. inc(minparacount);
  3609. inc(maxparacount);
  3610. end;
  3611. end;
  3612. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  3613. begin
  3614. if (tsym(p).typ<>paravarsym) then
  3615. exit;
  3616. paras.add(p);
  3617. end;
  3618. procedure tabstractprocdef.calcparas;
  3619. var
  3620. paracount : longint;
  3621. begin
  3622. { This can already be assigned when
  3623. we need to reresolve this unit (PFV) }
  3624. if assigned(paras) then
  3625. paras.free;
  3626. paras:=tparalist.create(false);
  3627. paracount:=0;
  3628. minparacount:=0;
  3629. maxparacount:=0;
  3630. parast.SymList.ForEachCall(@count_para,@paracount);
  3631. paras.capacity:=paracount;
  3632. { Insert parameters in table }
  3633. parast.SymList.ForEachCall(@insert_para,nil);
  3634. { Order parameters }
  3635. paras.sortparas;
  3636. end;
  3637. procedure tabstractprocdef.buildderef;
  3638. begin
  3639. { released procdef? }
  3640. if not assigned(parast) then
  3641. exit;
  3642. inherited buildderef;
  3643. returndefderef.build(returndef);
  3644. if po_explicitparaloc in procoptions then
  3645. funcretloc[callerside].buildderef;
  3646. { parast }
  3647. tparasymtable(parast).buildderef;
  3648. end;
  3649. procedure tabstractprocdef.deref;
  3650. begin
  3651. inherited deref;
  3652. returndef:=tdef(returndefderef.resolve);
  3653. if po_explicitparaloc in procoptions then
  3654. begin
  3655. funcretloc[callerside].deref;
  3656. has_paraloc_info:=callerside;
  3657. end
  3658. else
  3659. begin
  3660. { deref is called after loading from a ppu, but also after another
  3661. unit has been reloaded/recompiled and all references must be
  3662. re-resolved. Since the funcretloc contains a reference to a tdef,
  3663. reset it so that we won't try to access the stale def }
  3664. funcretloc[callerside].init;
  3665. has_paraloc_info:=callnoside;
  3666. end;
  3667. { parast }
  3668. tparasymtable(parast).deref;
  3669. { recalculated parameters }
  3670. calcparas;
  3671. fillgenericparas(parast);
  3672. end;
  3673. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  3674. begin
  3675. inherited ppuload(dt,ppufile);
  3676. parast:=nil;
  3677. Paras:=nil;
  3678. minparacount:=0;
  3679. maxparacount:=0;
  3680. ppufile.getderef(returndefderef);
  3681. { TODO: remove fpu_used loading}
  3682. ppufile.getbyte;
  3683. proctypeoption:=tproctypeoption(ppufile.getbyte);
  3684. proccalloption:=tproccalloption(ppufile.getbyte);
  3685. ppufile.getnormalset(procoptions);
  3686. funcretloc[callerside].init;
  3687. if po_explicitparaloc in procoptions then
  3688. funcretloc[callerside].ppuload(ppufile);
  3689. savesize:=sizeof(pint);
  3690. if (po_explicitparaloc in procoptions) then
  3691. has_paraloc_info:=callerside;
  3692. end;
  3693. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  3694. var
  3695. oldintfcrc : boolean;
  3696. begin
  3697. { released procdef? }
  3698. if not assigned(parast) then
  3699. exit;
  3700. inherited ppuwrite(ppufile);
  3701. ppufile.putderef(returndefderef);
  3702. oldintfcrc:=ppufile.do_interface_crc;
  3703. ppufile.do_interface_crc:=false;
  3704. ppufile.putbyte(0);
  3705. ppufile.putbyte(ord(proctypeoption));
  3706. ppufile.putbyte(ord(proccalloption));
  3707. ppufile.putnormalset(procoptions);
  3708. ppufile.do_interface_crc:=oldintfcrc;
  3709. if (po_explicitparaloc in procoptions) then
  3710. funcretloc[callerside].ppuwrite(ppufile);
  3711. end;
  3712. function tabstractprocdef.typename_paras(pno: tprocnameoptions) : ansistring;
  3713. var
  3714. hs,s : ansistring;
  3715. hp : TParavarsym;
  3716. hpc : tconstsym;
  3717. first : boolean;
  3718. i : integer;
  3719. begin
  3720. s:='';
  3721. first:=true;
  3722. for i:=0 to paras.count-1 do
  3723. begin
  3724. hp:=tparavarsym(paras[i]);
  3725. if not(vo_is_hidden_para in hp.varoptions) or
  3726. (pno_showhidden in pno) then
  3727. begin
  3728. if first then
  3729. begin
  3730. s:=s+'(';
  3731. first:=false;
  3732. end
  3733. else
  3734. s:=s+';';
  3735. if vo_is_hidden_para in hp.varoptions then
  3736. s:=s+'<';
  3737. case hp.varspez of
  3738. vs_var :
  3739. s:=s+'var ';
  3740. vs_const :
  3741. s:=s+'const ';
  3742. vs_out :
  3743. s:=s+'out ';
  3744. vs_constref :
  3745. s:=s+'constref ';
  3746. end;
  3747. if (pno_paranames in pno) then
  3748. s:=s+hp.realname+':';
  3749. if hp.univpara then
  3750. s:=s+'univ ';
  3751. if assigned(hp.vardef.typesym) then
  3752. begin
  3753. hs:=hp.vardef.typesym.realname;
  3754. if hs[1]<>'$' then
  3755. s:=s+hp.vardef.OwnerHierarchyName+hs
  3756. else
  3757. s:=s+hp.vardef.GetTypeName;
  3758. end
  3759. else
  3760. s:=s+hp.vardef.GetTypeName;
  3761. { default value }
  3762. if assigned(hp.defaultconstsym) then
  3763. begin
  3764. hpc:=tconstsym(hp.defaultconstsym);
  3765. hs:='';
  3766. case hpc.consttyp of
  3767. conststring,
  3768. constresourcestring :
  3769. begin
  3770. If hpc.value.len>0 then
  3771. begin
  3772. setLength(hs,hpc.value.len);
  3773. { don't write past the end of hs if the constant
  3774. is > 255 chars }
  3775. move(hpc.value.valueptr^,hs[1],length(hs));
  3776. { make sure that constant strings with newline chars
  3777. don't create a linebreak in the assembler code,
  3778. since comments are line-based. Also remove nulls
  3779. because the comments are written as a pchar. }
  3780. ReplaceCase(hs,#0,'.');
  3781. ReplaceCase(hs,#10,'.');
  3782. ReplaceCase(hs,#13,'.');
  3783. end;
  3784. end;
  3785. constreal :
  3786. str(pbestreal(hpc.value.valueptr)^,hs);
  3787. constpointer :
  3788. hs:=tostr(hpc.value.valueordptr);
  3789. constord :
  3790. begin
  3791. if is_boolean(hpc.constdef) then
  3792. begin
  3793. if hpc.value.valueord<>0 then
  3794. hs:='TRUE'
  3795. else
  3796. hs:='FALSE';
  3797. end
  3798. else
  3799. hs:=tostr(hpc.value.valueord);
  3800. end;
  3801. constnil :
  3802. hs:='nil';
  3803. constset :
  3804. hs:='<set>';
  3805. end;
  3806. if hs<>'' then
  3807. s:=s+'="'+hs+'"';
  3808. end;
  3809. if vo_is_hidden_para in hp.varoptions then
  3810. s:=s+'>';
  3811. end;
  3812. end;
  3813. if not first then
  3814. s:=s+')';
  3815. if (po_varargs in procoptions) then
  3816. s:=s+';VarArgs';
  3817. typename_paras:=s;
  3818. end;
  3819. function tabstractprocdef.is_methodpointer:boolean;
  3820. begin
  3821. result:=false;
  3822. end;
  3823. function tabstractprocdef.is_addressonly:boolean;
  3824. begin
  3825. result:=true;
  3826. end;
  3827. function tabstractprocdef.no_self_node: boolean;
  3828. begin
  3829. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  3830. (proctypeoption in [potype_class_constructor,potype_class_destructor,potype_operator]);
  3831. end;
  3832. function tabstractprocdef.getcopyas(newtyp:tdeftyp;copytyp:tproccopytyp): tstoreddef;
  3833. var
  3834. j, nestinglevel: longint;
  3835. pvs, npvs: tparavarsym;
  3836. begin
  3837. nestinglevel:=parast.symtablelevel;
  3838. if newtyp=procdef then
  3839. begin
  3840. if (copytyp<>pc_bareproc) then
  3841. result:=tprocdef.create(nestinglevel)
  3842. else
  3843. result:=tprocdef.create(normal_function_level);
  3844. tprocdef(result).visibility:=vis_public;
  3845. end
  3846. else
  3847. begin
  3848. result:=tprocvardef.create(nestinglevel);
  3849. end;
  3850. tabstractprocdef(result).returndef:=returndef;
  3851. tabstractprocdef(result).returndefderef:=returndefderef;
  3852. pvs:=nil;
  3853. npvs:=nil;
  3854. for j:=0 to parast.symlist.count-1 do
  3855. begin
  3856. case tsym(parast.symlist[j]).typ of
  3857. paravarsym:
  3858. begin
  3859. pvs:=tparavarsym(parast.symlist[j]);
  3860. { in case of bare proc, don't copy self, vmt or framepointer
  3861. parameters }
  3862. if (copytyp=pc_bareproc) and
  3863. (([vo_is_self,vo_is_vmt,vo_is_parentfp,vo_is_result]*pvs.varoptions)<>[]) then
  3864. continue;
  3865. npvs:=tparavarsym.create(pvs.realname,pvs.paranr,pvs.varspez,
  3866. pvs.vardef,pvs.varoptions);
  3867. npvs.defaultconstsym:=pvs.defaultconstsym;
  3868. tabstractprocdef(result).parast.insert(npvs);
  3869. end;
  3870. constsym:
  3871. begin
  3872. // ignore, reuse original constym. Should also be duplicated
  3873. // be safe though
  3874. end;
  3875. symconst.typesym:
  3876. begin
  3877. // reuse original, part of generic declaration
  3878. end
  3879. else
  3880. internalerror(201160604);
  3881. end;
  3882. end;
  3883. tabstractprocdef(result).savesize:=savesize;
  3884. tabstractprocdef(result).proctypeoption:=proctypeoption;
  3885. tabstractprocdef(result).proccalloption:=proccalloption;
  3886. tabstractprocdef(result).procoptions:=procoptions;
  3887. if (copytyp=pc_bareproc) then
  3888. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions*[po_explicitparaloc,po_hascallingconvention,po_varargs,po_iocheck,po_has_importname,po_has_importdll];
  3889. if newtyp=procvardef then
  3890. tabstractprocdef(result).procoptions:=tabstractprocdef(result).procoptions-[po_has_importname,po_has_importdll];
  3891. tabstractprocdef(result).callerargareasize:=callerargareasize;
  3892. tabstractprocdef(result).calleeargareasize:=calleeargareasize;
  3893. tabstractprocdef(result).maxparacount:=maxparacount;
  3894. tabstractprocdef(result).minparacount:=minparacount;
  3895. if po_explicitparaloc in procoptions then
  3896. tabstractprocdef(result).funcretloc[callerside]:=funcretloc[callerside].getcopy;
  3897. { recalculate parameter info }
  3898. tabstractprocdef(result).has_paraloc_info:=callnoside;
  3899. {$ifdef m68k}
  3900. tabstractprocdef(result).exp_funcretloc:=exp_funcretloc;
  3901. {$endif}
  3902. if (typ=procdef) and
  3903. (newtyp=procvardef) and
  3904. (owner.symtabletype=ObjectSymtable) then
  3905. include(tprocvardef(result).procoptions,po_methodpointer);
  3906. end;
  3907. procedure tabstractprocdef.check_mark_as_nested;
  3908. begin
  3909. { nested procvars require that nested functions use the Delphi-style
  3910. nested procedure calling convention }
  3911. if (parast.symtablelevel>normal_function_level) and
  3912. (m_nested_procvars in current_settings.modeswitches) then
  3913. include(procoptions,po_delphi_nested_cc);
  3914. end;
  3915. procedure tabstractprocdef.init_paraloc_info(side: tcallercallee);
  3916. begin
  3917. if (side in [callerside,callbothsides]) and
  3918. not(has_paraloc_info in [callerside,callbothsides]) then
  3919. begin
  3920. callerargareasize:=paramanager.create_paraloc_info(self,callerside);
  3921. if has_paraloc_info in [calleeside,callbothsides] then
  3922. has_paraloc_info:=callbothsides
  3923. else
  3924. has_paraloc_info:=callerside;
  3925. end;
  3926. if (side in [calleeside,callbothsides]) and
  3927. not(has_paraloc_info in [calleeside,callbothsides]) then
  3928. begin
  3929. calleeargareasize:=paramanager.create_paraloc_info(self,calleeside);
  3930. if has_paraloc_info in [callerside,callbothsides] then
  3931. has_paraloc_info:=callbothsides
  3932. else
  3933. has_paraloc_info:=calleeside;
  3934. end;
  3935. end;
  3936. function tabstractprocdef.stack_tainting_parameter(side: tcallercallee): boolean;
  3937. var
  3938. p: tparavarsym;
  3939. ploc: PCGParalocation;
  3940. i: longint;
  3941. begin
  3942. result:=false;
  3943. init_paraloc_info(side);
  3944. for i:=0 to parast.SymList.Count-1 do
  3945. if tsym(parast.SymList[i]).typ=paravarsym then
  3946. begin
  3947. p:=tparavarsym(parast.SymList[i]);
  3948. { check if no parameter is located on the stack }
  3949. if is_open_array(p.vardef) or
  3950. is_array_of_const(p.vardef) then
  3951. begin
  3952. result:=true;
  3953. exit;
  3954. end;
  3955. ploc:=p.paraloc[side].location;
  3956. while assigned(ploc) do
  3957. begin
  3958. if (ploc^.loc=LOC_REFERENCE) then
  3959. begin
  3960. result:=true;
  3961. exit
  3962. end;
  3963. ploc:=ploc^.next;
  3964. end;
  3965. end;
  3966. end;
  3967. function tabstractprocdef.is_pushleftright: boolean;
  3968. begin
  3969. {$if defined(i8086) or defined(i386)}
  3970. result:=proccalloption in pushleftright_pocalls;
  3971. {$else}
  3972. result:=false;
  3973. {$endif}
  3974. end;
  3975. function tabstractprocdef.address_size: asizeint;
  3976. begin
  3977. {$ifdef i8086}
  3978. if po_far in procoptions then
  3979. result:=sizeof(pint)+2
  3980. else
  3981. {$endif i8086}
  3982. result:=sizeof(pint);
  3983. end;
  3984. {***************************************************************************
  3985. TPROCDEF
  3986. ***************************************************************************}
  3987. function tprocdef.GetResultName: PShortString;
  3988. begin
  3989. if not assigned(implprocdefinfo) then
  3990. internalerror(2014010301);
  3991. result:=implprocdefinfo^.resultname;
  3992. end;
  3993. procedure tprocdef.SetResultName(AValue: PShortString);
  3994. begin
  3995. if not assigned(implprocdefinfo) then
  3996. internalerror(2014010302);
  3997. implprocdefinfo^.resultname:=AValue;
  3998. end;
  3999. function tprocdef.GetParentFPInitBlock: tnode;
  4000. begin
  4001. if not assigned(implprocdefinfo) then
  4002. internalerror(2014010303);
  4003. result:=implprocdefinfo^.parentfpinitblock;
  4004. end;
  4005. function tprocdef.GetParentFPStruct: tsym;
  4006. begin
  4007. if not assigned(implprocdefinfo) then
  4008. internalerror(2014010304);
  4009. result:=implprocdefinfo^.parentfpstruct;
  4010. end;
  4011. function tprocdef.GetParentFPStructPtrType: tdef;
  4012. begin
  4013. if not assigned(implprocdefinfo) then
  4014. internalerror(2014010305);
  4015. result:=implprocdefinfo^.parentfpstructptrtype;
  4016. end;
  4017. procedure tprocdef.SetParentFPInitBlock(AValue: tnode);
  4018. begin
  4019. if not assigned(implprocdefinfo) then
  4020. internalerror(2014010306);
  4021. implprocdefinfo^.parentfpinitblock:=AValue;
  4022. end;
  4023. function tprocdef.Getprocendtai: tai;
  4024. begin
  4025. if not assigned(implprocdefinfo) then
  4026. internalerror(2014010307);
  4027. result:=implprocdefinfo^.procendtai;
  4028. end;
  4029. function tprocdef.Getprocstarttai: tai;
  4030. begin
  4031. if not assigned(implprocdefinfo) then
  4032. internalerror(2014010308);
  4033. result:=implprocdefinfo^.procstarttai;
  4034. end;
  4035. procedure tprocdef.Setprocendtai(AValue: tai);
  4036. begin
  4037. if not assigned(implprocdefinfo) then
  4038. internalerror(2014010309);
  4039. implprocdefinfo^.procendtai:=AValue;
  4040. end;
  4041. function tprocdef.Getskpara: pointer;
  4042. begin
  4043. if not assigned(implprocdefinfo) then
  4044. internalerror(2014010310);
  4045. result:=implprocdefinfo^.skpara;
  4046. end;
  4047. procedure tprocdef.Setskpara(AValue: pointer);
  4048. begin
  4049. if not assigned(implprocdefinfo) then
  4050. internalerror(2014010311);
  4051. implprocdefinfo^.skpara:=AValue;
  4052. end;
  4053. function tprocdef.Getforwarddef: boolean;
  4054. begin
  4055. if not assigned(implprocdefinfo) then
  4056. internalerror(2014010312);
  4057. result:=implprocdefinfo^.forwarddef;
  4058. end;
  4059. function tprocdef.Gethasforward: boolean;
  4060. begin
  4061. if not assigned(implprocdefinfo) then
  4062. internalerror(2014010313);
  4063. result:=implprocdefinfo^.hasforward;
  4064. end;
  4065. function tprocdef.Getinterfacedef: boolean;
  4066. begin
  4067. if not assigned(implprocdefinfo) then
  4068. internalerror(2014010314);
  4069. result:=implprocdefinfo^.interfacedef;
  4070. end;
  4071. procedure tprocdef.Setforwarddef(AValue: boolean);
  4072. begin
  4073. if not assigned(implprocdefinfo) then
  4074. internalerror(2014010315);
  4075. implprocdefinfo^.forwarddef:=AValue;
  4076. end;
  4077. procedure tprocdef.Sethasforward(AValue: boolean);
  4078. begin
  4079. if not assigned(implprocdefinfo) then
  4080. internalerror(2014010316);
  4081. implprocdefinfo^.hasforward:=AValue;
  4082. end;
  4083. procedure tprocdef.Setinterfacedef(AValue: boolean);
  4084. begin
  4085. if not assigned(implprocdefinfo) then
  4086. internalerror(2014010317);
  4087. implprocdefinfo^.interfacedef:=AValue;
  4088. end;
  4089. procedure tprocdef.Setprocstarttai(AValue: tai);
  4090. begin
  4091. if not assigned(implprocdefinfo) then
  4092. internalerror(2014010318);
  4093. implprocdefinfo^.procstarttai:=AValue;
  4094. end;
  4095. procedure tprocdef.SetParentFPStruct(AValue: tsym);
  4096. begin
  4097. if not assigned(implprocdefinfo) then
  4098. internalerror(2014010319);
  4099. implprocdefinfo^.parentfpstruct:=AValue;
  4100. end;
  4101. procedure tprocdef.SetParentFPStructPtrType(AValue: tdef);
  4102. begin
  4103. if not assigned(implprocdefinfo) then
  4104. internalerror(2014010320);
  4105. implprocdefinfo^.parentfpstructptrtype:=AValue;
  4106. end;
  4107. constructor tprocdef.create(level:byte);
  4108. begin
  4109. inherited create(procdef,level);
  4110. implprocdefinfo:=allocmem(sizeof(implprocdefinfo^));
  4111. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  4112. {$ifdef symansistr}
  4113. _mangledname:='';
  4114. {$else symansistr}
  4115. _mangledname:=nil;
  4116. {$endif symansistr}
  4117. fileinfo:=current_filepos;
  4118. extnumber:=$ffff;
  4119. aliasnames:=TCmdStrList.create;
  4120. funcretsym:=nil;
  4121. forwarddef:=true;
  4122. interfacedef:=false;
  4123. hasforward:=false;
  4124. struct := nil;
  4125. import_dll:=nil;
  4126. import_name:=nil;
  4127. import_nr:=0;
  4128. inlininginfo:=nil;
  4129. deprecatedmsg:=nil;
  4130. {$if defined(i386) or defined(i8086)}
  4131. fpu_used:=maxfpuregs;
  4132. {$endif i386 or i8086}
  4133. end;
  4134. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  4135. var
  4136. i,aliasnamescount : longint;
  4137. level : byte;
  4138. begin
  4139. inherited ppuload(procdef,ppufile);
  4140. {$ifdef symansistr}
  4141. if po_has_mangledname in procoptions then
  4142. _mangledname:=ppufile.getansistring
  4143. else
  4144. _mangledname:='';
  4145. {$else symansistr}
  4146. if po_has_mangledname in procoptions then
  4147. _mangledname:=stringdup(ppufile.getstring)
  4148. else
  4149. _mangledname:=nil;
  4150. {$endif symansistr}
  4151. extnumber:=ppufile.getword;
  4152. level:=ppufile.getbyte;
  4153. ppufile.getderef(structderef);
  4154. ppufile.getderef(procsymderef);
  4155. ppufile.getposinfo(fileinfo);
  4156. visibility:=tvisibility(ppufile.getbyte);
  4157. ppufile.getsmallset(symoptions);
  4158. if sp_has_deprecated_msg in symoptions then
  4159. deprecatedmsg:=stringdup(ppufile.getstring)
  4160. else
  4161. deprecatedmsg:=nil;
  4162. synthetickind:=tsynthetickind(ppufile.getbyte);
  4163. {$ifdef powerpc}
  4164. { library symbol for AmigaOS/MorphOS }
  4165. ppufile.getderef(libsymderef);
  4166. {$endif powerpc}
  4167. { import stuff }
  4168. if po_has_importdll in procoptions then
  4169. import_dll:=stringdup(ppufile.getstring)
  4170. else
  4171. import_dll:=nil;
  4172. if po_has_importname in procoptions then
  4173. import_name:=stringdup(ppufile.getstring)
  4174. else
  4175. import_name:=nil;
  4176. import_nr:=ppufile.getword;
  4177. if (po_msgint in procoptions) then
  4178. messageinf.i:=ppufile.getlongint;
  4179. if (po_msgstr in procoptions) then
  4180. messageinf.str:=stringdup(ppufile.getstring);
  4181. if (po_dispid in procoptions) then
  4182. dispid:=ppufile.getlongint;
  4183. { inline stuff }
  4184. if (po_has_inlininginfo in procoptions) then
  4185. begin
  4186. ppufile.getderef(funcretsymderef);
  4187. new(inlininginfo);
  4188. ppufile.getsmallset(inlininginfo^.flags);
  4189. end
  4190. else
  4191. begin
  4192. inlininginfo:=nil;
  4193. funcretsym:=nil;
  4194. end;
  4195. aliasnames:=TCmdStrList.create;
  4196. { count alias names }
  4197. aliasnamescount:=ppufile.getbyte;
  4198. for i:=1 to aliasnamescount do
  4199. aliasnames.insert(ppufile.getstring);
  4200. isempty:=ppufile.getbyte<>0;
  4201. { load para symtable }
  4202. parast:=tparasymtable.create(self,level);
  4203. tparasymtable(parast).ppuload(ppufile);
  4204. { load local symtable }
  4205. if (po_has_inlininginfo in procoptions) then
  4206. begin
  4207. localst:=tlocalsymtable.create(self,level);
  4208. tlocalsymtable(localst).ppuload(ppufile);
  4209. end
  4210. else
  4211. localst:=nil;
  4212. { inline stuff }
  4213. if (po_has_inlininginfo in procoptions) then
  4214. inlininginfo^.code:=ppuloadnodetree(ppufile);
  4215. { default values for no persistent data }
  4216. if (cs_link_deffile in current_settings.globalswitches) and
  4217. (tf_need_export in target_info.flags) and
  4218. (po_exports in procoptions) then
  4219. deffile.AddExport(mangledname);
  4220. { Disable po_has_inlining until the derefimpl is done }
  4221. exclude(procoptions,po_has_inlininginfo);
  4222. {$ifdef i386}
  4223. fpu_used:=maxfpuregs;
  4224. {$endif i386}
  4225. end;
  4226. destructor tprocdef.destroy;
  4227. begin
  4228. aliasnames.free;
  4229. aliasnames:=nil;
  4230. if assigned(localst) and
  4231. (localst.symtabletype<>staticsymtable) then
  4232. begin
  4233. {$ifdef MEMDEBUG}
  4234. memproclocalst.start;
  4235. {$endif MEMDEBUG}
  4236. localst.free;
  4237. localst:=nil;
  4238. {$ifdef MEMDEBUG}
  4239. memproclocalst.start;
  4240. {$endif MEMDEBUG}
  4241. end;
  4242. if assigned(inlininginfo) then
  4243. begin
  4244. {$ifdef MEMDEBUG}
  4245. memprocnodetree.start;
  4246. {$endif MEMDEBUG}
  4247. tnode(inlininginfo^.code).free;
  4248. {$ifdef MEMDEBUG}
  4249. memprocnodetree.start;
  4250. {$endif MEMDEBUG}
  4251. dispose(inlininginfo);
  4252. inlininginfo:=nil;
  4253. end;
  4254. {$ifdef jvm}
  4255. exprasmlist.free;
  4256. {$endif}
  4257. if assigned(implprocdefinfo) then
  4258. begin
  4259. stringdispose(implprocdefinfo^.resultname);
  4260. freemem(implprocdefinfo);
  4261. implprocdefinfo:=nil;
  4262. end;
  4263. stringdispose(import_dll);
  4264. stringdispose(import_name);
  4265. stringdispose(deprecatedmsg);
  4266. if (po_msgstr in procoptions) then
  4267. stringdispose(messageinf.str);
  4268. {$ifndef symansistr}
  4269. if assigned(_mangledname) then
  4270. begin
  4271. {$ifdef MEMDEBUG}
  4272. memmanglednames.start;
  4273. {$endif MEMDEBUG}
  4274. stringdispose(_mangledname);
  4275. {$ifdef MEMDEBUG}
  4276. memmanglednames.stop;
  4277. {$endif MEMDEBUG}
  4278. end;
  4279. {$endif symansistr}
  4280. inherited destroy;
  4281. end;
  4282. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  4283. var
  4284. oldintfcrc : boolean;
  4285. aliasnamescount : longint;
  4286. item : TCmdStrListItem;
  4287. begin
  4288. { released procdef? }
  4289. if not assigned(parast) then
  4290. exit;
  4291. inherited ppuwrite(ppufile);
  4292. {$ifdef symansistr}
  4293. if po_has_mangledname in procoptions then
  4294. ppufile.putansistring(_mangledname);
  4295. {$else symansistr}
  4296. if po_has_mangledname in procoptions then
  4297. ppufile.putstring(_mangledname^);
  4298. {$endif symansistr}
  4299. ppufile.putword(extnumber);
  4300. ppufile.putbyte(parast.symtablelevel);
  4301. ppufile.putderef(structderef);
  4302. ppufile.putderef(procsymderef);
  4303. ppufile.putposinfo(fileinfo);
  4304. ppufile.putbyte(byte(visibility));
  4305. ppufile.putsmallset(symoptions);
  4306. if sp_has_deprecated_msg in symoptions then
  4307. ppufile.putstring(deprecatedmsg^);
  4308. ppufile.putbyte(byte(synthetickind));
  4309. {$ifdef powerpc}
  4310. { library symbol for AmigaOS/MorphOS }
  4311. ppufile.putderef(libsymderef);
  4312. {$endif powerpc}
  4313. { import }
  4314. if po_has_importdll in procoptions then
  4315. ppufile.putstring(import_dll^);
  4316. if po_has_importname in procoptions then
  4317. ppufile.putstring(import_name^);
  4318. ppufile.putword(import_nr);
  4319. if (po_msgint in procoptions) then
  4320. ppufile.putlongint(messageinf.i);
  4321. if (po_msgstr in procoptions) then
  4322. ppufile.putstring(messageinf.str^);
  4323. if (po_dispid in procoptions) then
  4324. ppufile.putlongint(dispid);
  4325. { inline stuff }
  4326. oldintfcrc:=ppufile.do_crc;
  4327. ppufile.do_crc:=false;
  4328. if (po_has_inlininginfo in procoptions) then
  4329. begin
  4330. ppufile.putderef(funcretsymderef);
  4331. ppufile.putsmallset(inlininginfo^.flags);
  4332. end;
  4333. { count alias names }
  4334. aliasnamescount:=0;
  4335. item:=TCmdStrListItem(aliasnames.first);
  4336. while assigned(item) do
  4337. begin
  4338. inc(aliasnamescount);
  4339. item:=TCmdStrListItem(item.next);
  4340. end;
  4341. if aliasnamescount>255 then
  4342. internalerror(200711021);
  4343. ppufile.putbyte(aliasnamescount);
  4344. item:=TCmdStrListItem(aliasnames.first);
  4345. while assigned(item) do
  4346. begin
  4347. ppufile.putstring(item.str);
  4348. item:=TCmdStrListItem(item.next);
  4349. end;
  4350. ppufile.putbyte(ord(isempty));
  4351. ppufile.do_crc:=oldintfcrc;
  4352. { write this entry }
  4353. ppufile.writeentry(ibprocdef);
  4354. { Save the para symtable, this is taken from the interface }
  4355. tparasymtable(parast).ppuwrite(ppufile);
  4356. { save localsymtable for inline procedures or when local
  4357. browser info is requested, this has no influence on the crc }
  4358. if (po_has_inlininginfo in procoptions) then
  4359. begin
  4360. oldintfcrc:=ppufile.do_crc;
  4361. ppufile.do_crc:=false;
  4362. tlocalsymtable(localst).ppuwrite(ppufile);
  4363. ppufile.do_crc:=oldintfcrc;
  4364. end;
  4365. { node tree for inlining }
  4366. oldintfcrc:=ppufile.do_crc;
  4367. ppufile.do_crc:=false;
  4368. if (po_has_inlininginfo in procoptions) then
  4369. ppuwritenodetree(ppufile,inlininginfo^.code);
  4370. ppufile.do_crc:=oldintfcrc;
  4371. end;
  4372. function tprocdef.fullprocname(showhidden:boolean):string;
  4373. var
  4374. pno: tprocnameoptions;
  4375. begin
  4376. pno:=[];
  4377. if showhidden then
  4378. include(pno,pno_showhidden);
  4379. result:=customprocname(pno);
  4380. end;
  4381. function tprocdef.customprocname(pno: tprocnameoptions):ansistring;
  4382. var
  4383. s, rn : ansistring;
  4384. t : ttoken;
  4385. begin
  4386. {$ifdef EXTDEBUG}
  4387. include(pno,pno_showhidden);
  4388. {$endif EXTDEBUG}
  4389. s:='';
  4390. if proctypeoption=potype_operator then
  4391. begin
  4392. for t:=NOTOKEN to last_overloaded do
  4393. if procsym.realname='$'+overloaded_names[t] then
  4394. begin
  4395. s:='operator ';
  4396. if (pno_ownername in pno) and
  4397. assigned(struct) then
  4398. s:=s+struct.RttiName+'.';
  4399. s:=s+arraytokeninfo[t].str+typename_paras(pno);
  4400. break;
  4401. end;
  4402. end
  4403. else
  4404. begin
  4405. if (po_classmethod in procoptions) and
  4406. not(pno_noclassmarker in pno) then
  4407. s:='class ';
  4408. case proctypeoption of
  4409. potype_constructor,
  4410. potype_class_constructor:
  4411. s:=s+'constructor ';
  4412. potype_class_destructor,
  4413. potype_destructor:
  4414. s:=s+'destructor ';
  4415. else
  4416. if (pno_proctypeoption in pno) then
  4417. begin
  4418. if assigned(returndef) and
  4419. not(is_void(returndef)) then
  4420. s:=s+'function '
  4421. else
  4422. s:=s+'procedure ';
  4423. end;
  4424. end;
  4425. if (pno_ownername in pno) and
  4426. (owner.symtabletype in [recordsymtable,objectsymtable]) then
  4427. s:=s+tabstractrecorddef(owner.defowner).RttiName+'.';
  4428. rn:=procsym.realname;
  4429. if (pno_noleadingdollar in pno) and
  4430. (rn[1]='$') then
  4431. delete(rn,1,1);
  4432. s:=s+rn+typename_paras(pno);
  4433. end;
  4434. if not(proctypeoption in [potype_constructor,potype_destructor,
  4435. potype_class_constructor,potype_class_destructor]) and
  4436. assigned(returndef) and
  4437. not(is_void(returndef)) then
  4438. s:=s+':'+returndef.GetTypeName;
  4439. if owner.symtabletype=localsymtable then
  4440. s:=s+' is nested';
  4441. s:=s+';';
  4442. { forced calling convention? }
  4443. if (po_hascallingconvention in procoptions) then
  4444. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  4445. if (po_staticmethod in procoptions) and
  4446. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  4447. s:=s+' Static;';
  4448. customprocname:=s;
  4449. end;
  4450. function tprocdef.is_methodpointer:boolean;
  4451. begin
  4452. { don't check assigned(_class), that's also the case for nested
  4453. procedures inside methods }
  4454. result:=(owner.symtabletype=ObjectSymtable)and not no_self_node;
  4455. end;
  4456. function tprocdef.is_addressonly:boolean;
  4457. begin
  4458. result:=assigned(owner) and
  4459. not is_methodpointer and
  4460. (not(m_nested_procvars in current_settings.modeswitches) or
  4461. not is_nested_pd(self));
  4462. end;
  4463. procedure tprocdef.make_external;
  4464. begin
  4465. include(procoptions,po_external);
  4466. forwarddef:=false;
  4467. end;
  4468. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  4469. begin
  4470. case t of
  4471. gs_local :
  4472. GetSymtable:=localst;
  4473. gs_para :
  4474. GetSymtable:=parast;
  4475. else
  4476. GetSymtable:=nil;
  4477. end;
  4478. end;
  4479. function tprocdef.getcopyas(newtyp: tdeftyp; copytyp: tproccopytyp): tstoreddef;
  4480. var
  4481. j : longint;
  4482. begin
  4483. result:=inherited getcopyas(newtyp,copytyp);
  4484. if newtyp=procvardef then
  4485. exit;
  4486. { don't copy mangled name, can be different }
  4487. tprocdef(result).messageinf:=messageinf;
  4488. tprocdef(result).dispid:=dispid;
  4489. if po_msgstr in procoptions then
  4490. tprocdef(result).messageinf.str:=stringdup(messageinf.str^);
  4491. tprocdef(result).symoptions:=symoptions;
  4492. if assigned(deprecatedmsg) then
  4493. tprocdef(result).deprecatedmsg:=stringdup(deprecatedmsg^);
  4494. { will have to be associated with appropriate procsym }
  4495. tprocdef(result).procsym:=nil;
  4496. if copytyp<>pc_bareproc then
  4497. tprocdef(result).aliasnames.concatListcopy(aliasnames);
  4498. if assigned(funcretsym) then
  4499. begin
  4500. if funcretsym.owner=parast then
  4501. begin
  4502. j:=parast.symlist.indexof(funcretsym);
  4503. if j<0 then
  4504. internalerror(2011040606);
  4505. tprocdef(result).funcretsym:=tsym(tprocdef(result).parast.symlist[j]);
  4506. end
  4507. else if funcretsym.owner=localst then
  4508. begin
  4509. { nothing to do, will be inserted for the new procdef while
  4510. parsing its body (by pdecsub.insert_funcret_local) }
  4511. end
  4512. else
  4513. internalerror(2011040605);
  4514. end;
  4515. { will have to be associated with a new struct }
  4516. tprocdef(result).struct:=nil;
  4517. {$if defined(powerpc) or defined(m68k)}
  4518. tprocdef(result).libsym:=libsym;
  4519. {$endif powerpc or m68k}
  4520. if assigned(implprocdefinfo) then
  4521. begin
  4522. if assigned(resultname) then
  4523. tprocdef(result).resultname:=stringdup(resultname^);
  4524. end;
  4525. if assigned(import_dll) then
  4526. tprocdef(result).import_dll:=stringdup(import_dll^);
  4527. if assigned(import_name) then
  4528. tprocdef(result).import_name:=stringdup(import_name^);
  4529. tprocdef(result).import_nr:=import_nr;
  4530. tprocdef(result).extnumber:=$ffff;
  4531. {$if defined(i386) or defined(i8086)}
  4532. tprocdef(result).fpu_used:=fpu_used;
  4533. {$endif i386 or i8086}
  4534. tprocdef(result).visibility:=visibility;
  4535. tprocdef(result).synthetickind:=synthetickind;
  4536. { we need a separate implementation for the copied def }
  4537. tprocdef(result).forwarddef:=true;
  4538. tprocdef(result).interfacedef:=true;
  4539. { create new paralist }
  4540. tprocdef(result).calcparas;
  4541. end;
  4542. function tprocdef.getcopy: tstoreddef;
  4543. begin
  4544. result:=getcopyas(procdef,pc_normal);
  4545. end;
  4546. procedure tprocdef.buildderef;
  4547. begin
  4548. inherited buildderef;
  4549. structderef.build(struct);
  4550. { procsym that originaly defined this definition, should be in the
  4551. same symtable }
  4552. procsymderef.build(procsym);
  4553. {$ifdef powerpc}
  4554. { library symbol for AmigaOS/MorphOS }
  4555. libsymderef.build(libsym);
  4556. {$endif powerpc}
  4557. end;
  4558. procedure tprocdef.buildderefimpl;
  4559. begin
  4560. inherited buildderefimpl;
  4561. { inline tree }
  4562. if (po_has_inlininginfo in procoptions) then
  4563. begin
  4564. { Localst is not available for main/unit init }
  4565. if assigned(localst) then
  4566. begin
  4567. tlocalsymtable(localst).buildderef;
  4568. tlocalsymtable(localst).buildderefimpl;
  4569. end;
  4570. funcretsymderef.build(funcretsym);
  4571. inlininginfo^.code.buildderefimpl;
  4572. end;
  4573. end;
  4574. procedure tprocdef.deref;
  4575. begin
  4576. inherited deref;
  4577. struct:=tabstractrecorddef(structderef.resolve);
  4578. { procsym that originaly defined this definition, should be in the
  4579. same symtable }
  4580. procsym:=tprocsym(procsymderef.resolve);
  4581. {$ifdef powerpc}
  4582. { library symbol for AmigaOS/MorphOS }
  4583. libsym:=tsym(libsymderef.resolve);
  4584. {$endif powerpc}
  4585. end;
  4586. procedure tprocdef.derefimpl;
  4587. begin
  4588. { Enable has_inlininginfo when the inlininginfo
  4589. structure is available. The has_inlininginfo was disabled
  4590. after the load, since the data was invalid }
  4591. if assigned(inlininginfo) then
  4592. include(procoptions,po_has_inlininginfo);
  4593. { Locals }
  4594. if assigned(localst) then
  4595. begin
  4596. tlocalsymtable(localst).deref;
  4597. tlocalsymtable(localst).derefimpl;
  4598. end;
  4599. { Inline }
  4600. if (po_has_inlininginfo in procoptions) then
  4601. begin
  4602. inlininginfo^.code.derefimpl;
  4603. { funcretsym, this is always located in the localst }
  4604. funcretsym:=tsym(funcretsymderef.resolve);
  4605. end
  4606. else
  4607. begin
  4608. { safety }
  4609. { Not safe! A unit may be reresolved after its interface has been
  4610. parsed but before its implementation has been parsed, and in that
  4611. case the funcretsym is still required!
  4612. funcretsym:=nil; }
  4613. end;
  4614. end;
  4615. function tprocdef.GetTypeName : string;
  4616. begin
  4617. GetTypeName := FullProcName(false);
  4618. end;
  4619. function tprocdef.mangledname : TSymStr;
  4620. begin
  4621. {$ifdef symansistr}
  4622. if _mangledname<>'' then
  4623. {$else symansistr}
  4624. if assigned(_mangledname) then
  4625. {$endif symansistr}
  4626. begin
  4627. {$ifdef compress}
  4628. {$error add support for ansistrings in case of symansistr}
  4629. mangledname:=minilzw_decode(_mangledname^);
  4630. {$else}
  4631. {$ifdef symansistr}
  4632. mangledname:=_mangledname;
  4633. {$else symansistr}
  4634. mangledname:=_mangledname^;
  4635. {$endif symansistr}
  4636. {$endif}
  4637. exit;
  4638. end;
  4639. {$ifndef jvm}
  4640. mangledname:=defaultmangledname;
  4641. {$else not jvm}
  4642. mangledname:=jvmmangledbasename(false);
  4643. if (po_has_importdll in procoptions) then
  4644. begin
  4645. { import_dll comes from "external 'import_dll_name' name 'external_name'" }
  4646. if assigned(import_dll) then
  4647. mangledname:=import_dll^+'/'+mangledname
  4648. else
  4649. internalerror(2010122607);
  4650. end
  4651. else
  4652. jvmaddtypeownerprefix(owner,mangledname);
  4653. {$endif not jvm}
  4654. {$ifdef compress}
  4655. {$error add support for ansistrings in case of symansistr}
  4656. _mangledname:=stringdup(minilzw_encode(mangledname));
  4657. {$else}
  4658. {$ifdef symansistr}
  4659. _mangledname:=mangledname;
  4660. {$else symansistr}
  4661. _mangledname:=stringdup(mangledname);
  4662. {$endif symansistr}
  4663. {$endif}
  4664. end;
  4665. function tprocdef.defaultmangledname: TSymStr;
  4666. var
  4667. hp : TParavarsym;
  4668. hs : TSymStr;
  4669. crc : dword;
  4670. newlen,
  4671. oldlen,
  4672. i : integer;
  4673. begin
  4674. hp:=nil;
  4675. { we need to use the symtable where the procsym is inserted,
  4676. because that is visible to the world }
  4677. defaultmangledname:=make_mangledname('',procsym.owner,procsym.name);
  4678. oldlen:=length(defaultmangledname);
  4679. { add parameter types }
  4680. for i:=0 to paras.count-1 do
  4681. begin
  4682. hp:=tparavarsym(paras[i]);
  4683. if not(vo_is_hidden_para in hp.varoptions) then
  4684. defaultmangledname:=defaultmangledname+'$'+hp.vardef.mangledparaname;
  4685. end;
  4686. { add resultdef, add $$ as separator to make it unique from a
  4687. parameter separator }
  4688. if not is_void(returndef) then
  4689. defaultmangledname:=defaultmangledname+'$$'+returndef.mangledparaname;
  4690. newlen:=length(defaultmangledname);
  4691. { Replace with CRC if the parameter line is very long }
  4692. if (newlen-oldlen>12) and
  4693. ((newlen>100) or (newlen-oldlen>64)) then
  4694. begin
  4695. crc:=0;
  4696. for i:=0 to paras.count-1 do
  4697. begin
  4698. hp:=tparavarsym(paras[i]);
  4699. if not(vo_is_hidden_para in hp.varoptions) then
  4700. begin
  4701. hs:=hp.vardef.mangledparaname;
  4702. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4703. end;
  4704. end;
  4705. hs:=hp.vardef.mangledparaname;
  4706. crc:=UpdateCrc32(crc,hs[1],length(hs));
  4707. defaultmangledname:=Copy(defaultmangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  4708. end;
  4709. end;
  4710. function tprocdef.cplusplusmangledname : TSymStr;
  4711. function getcppparaname(p : tdef) : TSymStr;
  4712. const
  4713. {$ifdef NAMEMANGLING_GCC2}
  4714. ordtype2str : array[tordtype] of string[2] = (
  4715. '',
  4716. 'Uc','Us','Ui','Us',
  4717. 'Sc','s','i','x',
  4718. 'b','b','b','b','b',
  4719. 'c','w','x');
  4720. {$else NAMEMANGLING_GCC2}
  4721. ordtype2str : array[tordtype] of string[1] = (
  4722. 'v',
  4723. 'h','t','j','y',
  4724. 'a','s','i','x',
  4725. 'b','b','b','b',
  4726. 'b','b','b','b',
  4727. 'c','w','x');
  4728. floattype2str : array[tfloattype] of string[1] = (
  4729. 'f','d','e','e',
  4730. 'd','d','g');
  4731. {$endif NAMEMANGLING_GCC2}
  4732. var
  4733. s : TSymStr;
  4734. begin
  4735. case p.typ of
  4736. orddef:
  4737. s:=ordtype2str[torddef(p).ordtype];
  4738. pointerdef:
  4739. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  4740. {$ifndef NAMEMANGLING_GCC2}
  4741. floatdef:
  4742. s:=floattype2str[tfloatdef(p).floattype];
  4743. {$endif NAMEMANGLING_GCC2}
  4744. else
  4745. internalerror(2103001);
  4746. end;
  4747. getcppparaname:=s;
  4748. end;
  4749. var
  4750. s,s2 : TSymStr;
  4751. hp : TParavarsym;
  4752. i : integer;
  4753. begin
  4754. {$ifdef NAMEMANGLING_GCC2}
  4755. { outdated gcc 2.x name mangling scheme }
  4756. s := procsym.realname;
  4757. if procsym.owner.symtabletype=ObjectSymtable then
  4758. begin
  4759. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  4760. case proctypeoption of
  4761. potype_destructor:
  4762. s:='_$_'+tostr(length(s2))+s2;
  4763. potype_constructor:
  4764. s:='___'+tostr(length(s2))+s2;
  4765. else
  4766. s:='_'+s+'__'+tostr(length(s2))+s2;
  4767. end;
  4768. end
  4769. else s:=s+'__';
  4770. s:=s+'F';
  4771. { concat modifiers }
  4772. { !!!!! }
  4773. { now we handle the parameters }
  4774. if maxparacount>0 then
  4775. begin
  4776. for i:=0 to paras.count-1 do
  4777. begin
  4778. hp:=tparavarsym(paras[i]);
  4779. { no hidden parameters form part of a C++ mangled name:
  4780. a) self is not included
  4781. b) there are no "high" or other hidden parameters
  4782. }
  4783. if vo_is_hidden_para in hp.varoptions then
  4784. continue;
  4785. s2:=getcppparaname(hp.vardef);
  4786. if hp.varspez in [vs_var,vs_out] then
  4787. s2:='R'+s2;
  4788. s:=s+s2;
  4789. end;
  4790. end
  4791. else
  4792. s:=s+'v';
  4793. cplusplusmangledname:=s;
  4794. {$else NAMEMANGLING_GCC2}
  4795. { gcc 3.x and 4.x name mangling scheme }
  4796. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  4797. if procsym.owner.symtabletype=ObjectSymtable then
  4798. begin
  4799. s:='_ZN';
  4800. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  4801. s:=s+tostr(length(s2))+s2;
  4802. case proctypeoption of
  4803. potype_constructor:
  4804. s:=s+'C1';
  4805. potype_destructor:
  4806. s:=s+'D1';
  4807. else
  4808. s:=s+tostr(length(procsym.realname))+procsym.realname;
  4809. end;
  4810. s:=s+'E';
  4811. end
  4812. else
  4813. s:=procsym.realname;
  4814. { now we handle the parameters }
  4815. if maxparacount>0 then
  4816. begin
  4817. for i:=0 to paras.count-1 do
  4818. begin
  4819. hp:=tparavarsym(paras[i]);
  4820. { no hidden parameters form part of a C++ mangled name:
  4821. a) self is not included
  4822. b) there are no "high" or other hidden parameters
  4823. }
  4824. if vo_is_hidden_para in hp.varoptions then
  4825. continue;
  4826. s2:=getcppparaname(hp.vardef);
  4827. if hp.varspez in [vs_var,vs_out] then
  4828. s2:='R'+s2;
  4829. s:=s+s2;
  4830. end;
  4831. end
  4832. else
  4833. s:=s+'v';
  4834. cplusplusmangledname:=s;
  4835. {$endif NAMEMANGLING_GCC2}
  4836. end;
  4837. function tprocdef.objcmangledname : TSymStr;
  4838. var
  4839. manglednamelen: longint;
  4840. iscatmethod : boolean;
  4841. begin
  4842. if not (po_msgstr in procoptions) then
  4843. internalerror(2009030901);
  4844. { we may very well need longer strings to handle these... }
  4845. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  4846. length('+"[ ]"')+length(messageinf.str^);
  4847. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  4848. if (iscatmethod) then
  4849. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  4850. if manglednamelen>255 then
  4851. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  4852. if not(po_classmethod in procoptions) then
  4853. result:='"-['
  4854. else
  4855. result:='"+[';
  4856. { quotes are necessary because the +/- otherwise confuse the assembler
  4857. into expecting a number
  4858. }
  4859. if iscatmethod then
  4860. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  4861. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  4862. if iscatmethod then
  4863. result:=result+')';
  4864. result:=result+' '+messageinf.str^+']"';
  4865. end;
  4866. {$ifdef jvm}
  4867. function tprocdef.jvmmangledbasename(signature: boolean): TSymStr;
  4868. var
  4869. vs: tparavarsym;
  4870. i: longint;
  4871. founderror: tdef;
  4872. tmpresult: TSymStr;
  4873. container: tsymtable;
  4874. begin
  4875. { format:
  4876. * method definition (in Jasmin):
  4877. (private|protected|public) [static] method(parametertypes)returntype
  4878. * method invocation
  4879. package/class/method(parametertypes)returntype
  4880. -> store common part: method(parametertypes)returntype and
  4881. adorn as required when using it.
  4882. }
  4883. if not signature then
  4884. begin
  4885. { method name }
  4886. { special names for constructors and class constructors }
  4887. if proctypeoption=potype_constructor then
  4888. tmpresult:='<init>'
  4889. else if proctypeoption in [potype_class_constructor,potype_unitinit] then
  4890. tmpresult:='<clinit>'
  4891. else if po_has_importname in procoptions then
  4892. begin
  4893. if assigned(import_name) then
  4894. tmpresult:=import_name^
  4895. else
  4896. internalerror(2010122608);
  4897. end
  4898. else
  4899. begin
  4900. tmpresult:=procsym.realname;
  4901. if tmpresult[1]='$' then
  4902. tmpresult:=copy(tmpresult,2,length(tmpresult)-1);
  4903. { nested functions }
  4904. container:=owner;
  4905. while container.symtabletype=localsymtable do
  4906. begin
  4907. tmpresult:='$'+tprocdef(owner.defowner).procsym.realname+'$'+tostr(tprocdef(owner.defowner).procsym.symid)+'$'+tmpresult;
  4908. container:=container.defowner.owner;
  4909. end;
  4910. end;
  4911. end
  4912. else
  4913. tmpresult:='';
  4914. { parameter types }
  4915. tmpresult:=tmpresult+'(';
  4916. { not the case for the main program (not required for defaultmangledname
  4917. because setmangledname() is called for the main program; in case of
  4918. the JVM, this only sets the importname, however) }
  4919. if assigned(paras) then
  4920. begin
  4921. init_paraloc_info(callerside);
  4922. for i:=0 to paras.count-1 do
  4923. begin
  4924. vs:=tparavarsym(paras[i]);
  4925. { function result is not part of the mangled name }
  4926. if vo_is_funcret in vs.varoptions then
  4927. continue;
  4928. { self pointer neither, except for class methods (the JVM only
  4929. supports static class methods natively, so the self pointer
  4930. here is a regular parameter as far as the JVM is concerned }
  4931. if not(po_classmethod in procoptions) and
  4932. (vo_is_self in vs.varoptions) then
  4933. continue;
  4934. { passing by reference is emulated by passing an array of one
  4935. element containing the value; for types that aren't pointers
  4936. in regular Pascal, simply passing the underlying pointer type
  4937. does achieve regular call-by-reference semantics though;
  4938. formaldefs always have to be passed like that because their
  4939. contents can be replaced }
  4940. if paramanager.push_copyout_param(vs.varspez,vs.vardef,proccalloption) then
  4941. tmpresult:=tmpresult+'[';
  4942. { Add the parameter type. }
  4943. if not jvmaddencodedtype(vs.vardef,false,tmpresult,signature,founderror) then
  4944. { an internalerror here is also triggered in case of errors in the source code }
  4945. tmpresult:='<error>';
  4946. end;
  4947. end;
  4948. tmpresult:=tmpresult+')';
  4949. { And the type of the function result (void in case of a procedure and
  4950. constructor). }
  4951. if (proctypeoption in [potype_constructor,potype_class_constructor]) then
  4952. jvmaddencodedtype(voidtype,false,tmpresult,signature,founderror)
  4953. else if not jvmaddencodedtype(returndef,false,tmpresult,signature,founderror) then
  4954. { an internalerror here is also triggered in case of errors in the source code }
  4955. tmpresult:='<error>';
  4956. result:=tmpresult;
  4957. end;
  4958. {$endif jvm}
  4959. procedure tprocdef.setmangledname(const s : TSymStr);
  4960. begin
  4961. { This is not allowed anymore, the forward declaration
  4962. already needs to create the correct mangledname, no changes
  4963. afterwards are allowed (PFV) }
  4964. { Exception: interface definitions in mode macpas, since in that }
  4965. { case no reference to the old name can exist yet (JM) }
  4966. {$ifdef symansistr}
  4967. if _mangledname<>'' then
  4968. if ((m_mac in current_settings.modeswitches) and
  4969. (interfacedef)) then
  4970. _mangledname:=''
  4971. else
  4972. internalerror(200411171);
  4973. {$else symansistr}
  4974. if assigned(_mangledname) then
  4975. if ((m_mac in current_settings.modeswitches) and
  4976. (interfacedef)) then
  4977. stringdispose(_mangledname)
  4978. else
  4979. internalerror(200411171);
  4980. {$endif symansistr}
  4981. {$ifdef jvm}
  4982. { this routine can be called for compilerproces. can't set mangled
  4983. name since it must be calculated, but it uses import_name when set
  4984. -> set that one }
  4985. import_name:=stringdup(s);
  4986. include(procoptions,po_has_importname);
  4987. include(procoptions,po_has_mangledname);
  4988. {$else}
  4989. {$ifdef compress}
  4990. {$error add support for symansistr}
  4991. _mangledname:=stringdup(minilzw_encode(s));
  4992. {$else}
  4993. {$ifdef symansistr}
  4994. _mangledname:=s;
  4995. {$else symansistr}
  4996. _mangledname:=stringdup(s);
  4997. {$endif symansistr}
  4998. {$endif}
  4999. {$endif jvm}
  5000. include(procoptions,po_has_mangledname);
  5001. end;
  5002. {***************************************************************************
  5003. TPROCVARDEF
  5004. ***************************************************************************}
  5005. constructor tprocvardef.create(level:byte);
  5006. begin
  5007. inherited create(procvardef,level);
  5008. end;
  5009. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  5010. begin
  5011. inherited ppuload(procvardef,ppufile);
  5012. { load para symtable }
  5013. parast:=tparasymtable.create(self,ppufile.getbyte);
  5014. {$ifdef jvm}
  5015. ppufile.getderef(classdefderef);
  5016. {$endif}
  5017. tparasymtable(parast).ppuload(ppufile);
  5018. end;
  5019. function tprocvardef.getcopy : tstoreddef;
  5020. var
  5021. i : tcallercallee;
  5022. j : longint;
  5023. begin
  5024. result:=tprocvardef.create(parast.symtablelevel);
  5025. tprocvardef(result).returndef:=returndef;
  5026. tprocvardef(result).returndefderef:=returndefderef;
  5027. tprocvardef(result).parast:=parast.getcopy;
  5028. tprocvardef(result).savesize:=savesize;
  5029. { create paralist copy }
  5030. calcparas;
  5031. tprocvardef(result).paras:=tparalist.create(false);
  5032. tprocvardef(result).paras.count:=paras.count;
  5033. for j:=0 to paras.count-1 do
  5034. tprocvardef(result).paras[j]:=paras[j];
  5035. tprocvardef(result).proctypeoption:=proctypeoption;
  5036. tprocvardef(result).proccalloption:=proccalloption;
  5037. tprocvardef(result).procoptions:=procoptions;
  5038. tprocvardef(result).callerargareasize:=callerargareasize;
  5039. tprocvardef(result).calleeargareasize:=calleeargareasize;
  5040. tprocvardef(result).maxparacount:=maxparacount;
  5041. tprocvardef(result).minparacount:=minparacount;
  5042. for i:=low(tcallercallee) to high(tcallercallee) do
  5043. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  5044. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  5045. {$ifdef m68k}
  5046. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  5047. {$endif}
  5048. {$ifdef jvm}
  5049. tprocvardef(result).classdef:=classdef;
  5050. {$endif}
  5051. end;
  5052. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  5053. begin
  5054. inherited ppuwrite(ppufile);
  5055. { Save the para symtable level (necessary to distinguish nested
  5056. procvars) }
  5057. ppufile.putbyte(parast.symtablelevel);
  5058. {$ifdef jvm}
  5059. ppufile.putderef(classdefderef);
  5060. {$endif}
  5061. { Write this entry }
  5062. ppufile.writeentry(ibprocvardef);
  5063. { Save the para symtable, this is taken from the interface }
  5064. tparasymtable(parast).ppuwrite(ppufile);
  5065. end;
  5066. {$ifdef jvm}
  5067. procedure tprocvardef.buildderef;
  5068. begin
  5069. inherited buildderef;
  5070. classdefderef.build(classdef);
  5071. end;
  5072. procedure tprocvardef.deref;
  5073. begin
  5074. inherited deref;
  5075. classdef:=tobjectdef(classdefderef.resolve);
  5076. end;
  5077. {$endif}
  5078. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  5079. begin
  5080. case t of
  5081. gs_para :
  5082. GetSymtable:=parast;
  5083. else
  5084. GetSymtable:=nil;
  5085. end;
  5086. end;
  5087. function tprocvardef.size : asizeint;
  5088. var
  5089. far_code_extra_bytes: integer = 0;
  5090. far_data_extra_bytes: integer = 0;
  5091. begin
  5092. {$ifdef i8086}
  5093. if po_far in procoptions then
  5094. far_code_extra_bytes:=2;
  5095. if current_settings.x86memorymodel in x86_far_data_models then
  5096. far_data_extra_bytes:=2;
  5097. {$endif i8086}
  5098. if ((po_methodpointer in procoptions) or
  5099. is_nested_pd(self)) and
  5100. not(po_addressonly in procoptions) then
  5101. size:=2*sizeof(pint)+far_code_extra_bytes+far_data_extra_bytes
  5102. else
  5103. size:=sizeof(pint)+far_code_extra_bytes;
  5104. end;
  5105. function tprocvardef.is_methodpointer:boolean;
  5106. begin
  5107. result:=(po_methodpointer in procoptions);
  5108. end;
  5109. function tprocvardef.is_addressonly:boolean;
  5110. begin
  5111. result:=(not(po_methodpointer in procoptions) and
  5112. not is_nested_pd(self)) or
  5113. (po_addressonly in procoptions);
  5114. end;
  5115. function tprocvardef.getmangledparaname:TSymStr;
  5116. begin
  5117. if not(po_methodpointer in procoptions) then
  5118. if not is_nested_pd(self) then
  5119. result:='procvar'
  5120. else
  5121. result:='nestedprovar'
  5122. else
  5123. result:='procvarofobj'
  5124. end;
  5125. function tprocvardef.is_publishable : boolean;
  5126. begin
  5127. is_publishable:=(po_methodpointer in procoptions);
  5128. end;
  5129. function tprocvardef.GetTypeName : string;
  5130. var
  5131. s: string;
  5132. pno : tprocnameoptions;
  5133. begin
  5134. {$ifdef EXTDEBUG}
  5135. pno:=[pno_showhidden];
  5136. {$else EXTDEBUG}
  5137. pno:=[];
  5138. {$endif EXTDEBUG}
  5139. s:='<';
  5140. if po_classmethod in procoptions then
  5141. s := s+'class method type of'
  5142. else
  5143. if po_addressonly in procoptions then
  5144. s := s+'address of'
  5145. else
  5146. s := s+'procedure variable type of';
  5147. if assigned(returndef) and
  5148. (returndef<>voidtype) then
  5149. s:=s+' function'+typename_paras(pno)+':'+returndef.GetTypeName
  5150. else
  5151. s:=s+' procedure'+typename_paras(pno);
  5152. if po_methodpointer in procoptions then
  5153. s := s+' of object';
  5154. if is_nested_pd(self) then
  5155. s := s+' is nested';
  5156. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  5157. end;
  5158. {***************************************************************************
  5159. TOBJECTDEF
  5160. ***************************************************************************}
  5161. constructor tobjectdef.create(ot:tobjecttyp;const n:string;c:tobjectdef);
  5162. begin
  5163. inherited create(n,objectdef);
  5164. fcurrent_dispid:=0;
  5165. objecttype:=ot;
  5166. childof:=nil;
  5167. if objecttype=odt_helper then
  5168. owner.includeoption(sto_has_helper);
  5169. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  5170. { create space for vmt !! }
  5171. vmtentries:=TFPList.Create;
  5172. vmt_offset:=0;
  5173. set_parent(c);
  5174. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  5175. prepareguid;
  5176. { setup implemented interfaces }
  5177. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5178. ImplementedInterfaces:=TFPObjectList.Create(true)
  5179. else
  5180. ImplementedInterfaces:=nil;
  5181. writing_class_record_dbginfo:=false;
  5182. end;
  5183. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  5184. var
  5185. i,
  5186. implintfcount : longint;
  5187. d, getterd : tderef;
  5188. ImplIntf : TImplementedInterface;
  5189. vmtentry : pvmtentry;
  5190. begin
  5191. inherited ppuload(objectdef,ppufile);
  5192. objecttype:=tobjecttyp(ppufile.getbyte);
  5193. objextname:=stringdup(ppufile.getstring);
  5194. { only used for external Objective-C classes/protocols }
  5195. if (objextname^='') then
  5196. stringdispose(objextname);
  5197. symtable:=tObjectSymtable.create(self,objrealname^,0);
  5198. tObjectSymtable(symtable).datasize:=ppufile.getasizeint;
  5199. tObjectSymtable(symtable).paddingsize:=ppufile.getword;
  5200. tObjectSymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  5201. tObjectSymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  5202. vmt_offset:=ppufile.getlongint;
  5203. ppufile.getderef(childofderef);
  5204. { load guid }
  5205. iidstr:=nil;
  5206. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5207. begin
  5208. new(iidguid);
  5209. ppufile.getguid(iidguid^);
  5210. iidstr:=stringdup(ppufile.getstring);
  5211. end;
  5212. abstractcnt:=ppufile.getlongint;
  5213. if objecttype=odt_helper then
  5214. ppufile.getderef(extendeddefderef);
  5215. vmtentries:=TFPList.Create;
  5216. vmtentries.count:=ppufile.getlongint;
  5217. for i:=0 to vmtentries.count-1 do
  5218. begin
  5219. ppufile.getderef(d);
  5220. new(vmtentry);
  5221. vmtentry^.procdef:=nil;
  5222. vmtentry^.procdefderef:=d;
  5223. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  5224. vmtentries[i]:=vmtentry;
  5225. end;
  5226. { load implemented interfaces }
  5227. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5228. begin
  5229. ImplementedInterfaces:=TFPObjectList.Create(true);
  5230. implintfcount:=ppufile.getlongint;
  5231. for i:=0 to implintfcount-1 do
  5232. begin
  5233. ppufile.getderef(d);
  5234. ppufile.getderef(getterd);
  5235. ImplIntf:=TImplementedInterface.Create_deref(d,getterd);
  5236. ImplIntf.IOffset:=ppufile.getlongint;
  5237. byte(ImplIntf.IType):=ppufile.getbyte;
  5238. ImplementedInterfaces.Add(ImplIntf);
  5239. end;
  5240. end
  5241. else
  5242. ImplementedInterfaces:=nil;
  5243. if df_copied_def in defoptions then
  5244. ppufile.getderef(cloneddefderef)
  5245. else
  5246. tObjectSymtable(symtable).ppuload(ppufile);
  5247. { handles the predefined class tobject }
  5248. { the last TOBJECT which is loaded gets }
  5249. { it ! }
  5250. if (childof=nil) and
  5251. (objecttype in [odt_class,odt_javaclass]) and
  5252. (objname^='TOBJECT') then
  5253. class_tobject:=self;
  5254. if (childof=nil) and
  5255. (objecttype=odt_interfacecom) then
  5256. if (objname^='IUNKNOWN') then
  5257. interface_iunknown:=self
  5258. else
  5259. if (objname^='IDISPATCH') then
  5260. interface_idispatch:=self;
  5261. if (childof=nil) and
  5262. (objecttype=odt_objcclass) and
  5263. (objname^='PROTOCOL') then
  5264. objc_protocoltype:=self;
  5265. if (objecttype=odt_javaclass) and
  5266. not(oo_is_formal in objectoptions) then
  5267. begin
  5268. if (objname^='JLOBJECT') then
  5269. java_jlobject:=self
  5270. else if (objname^='JLTHROWABLE') then
  5271. java_jlthrowable:=self
  5272. else if (objname^='FPCBASERECORDTYPE') then
  5273. java_fpcbaserecordtype:=self
  5274. else if (objname^='JLSTRING') then
  5275. java_jlstring:=self
  5276. else if (objname^='ANSISTRINGCLASS') then
  5277. java_ansistring:=self
  5278. else if (objname^='SHORTSTRINGCLASS') then
  5279. java_shortstring:=self
  5280. else if (objname^='JLENUM') then
  5281. java_jlenum:=self
  5282. else if (objname^='JUENUMSET') then
  5283. java_juenumset:=self
  5284. else if (objname^='FPCBITSET') then
  5285. java_jubitset:=self
  5286. else if (objname^='FPCBASEPROCVARTYPE') then
  5287. java_procvarbase:=self;
  5288. end;
  5289. writing_class_record_dbginfo:=false;
  5290. end;
  5291. destructor tobjectdef.destroy;
  5292. begin
  5293. if assigned(symtable) then
  5294. begin
  5295. symtable.free;
  5296. symtable:=nil;
  5297. end;
  5298. stringdispose(objextname);
  5299. stringdispose(iidstr);
  5300. if assigned(ImplementedInterfaces) then
  5301. begin
  5302. ImplementedInterfaces.free;
  5303. ImplementedInterfaces:=nil;
  5304. end;
  5305. if assigned(iidguid) then
  5306. begin
  5307. dispose(iidguid);
  5308. iidguid:=nil;
  5309. end;
  5310. if assigned(vmtentries) then
  5311. begin
  5312. resetvmtentries;
  5313. vmtentries.free;
  5314. vmtentries:=nil;
  5315. end;
  5316. if assigned(vmcallstaticinfo) then
  5317. begin
  5318. freemem(vmcallstaticinfo);
  5319. vmcallstaticinfo:=nil;
  5320. end;
  5321. inherited destroy;
  5322. end;
  5323. function tobjectdef.getcopy : tstoreddef;
  5324. var
  5325. i : longint;
  5326. begin
  5327. result:=tobjectdef.create(objecttype,objrealname^,childof);
  5328. { the constructor allocates a symtable which we release to avoid memory leaks }
  5329. tobjectdef(result).symtable.free;
  5330. tobjectdef(result).symtable:=symtable.getcopy;
  5331. if assigned(objextname) then
  5332. tobjectdef(result).objextname:=stringdup(objextname^);
  5333. if assigned(import_lib) then
  5334. tobjectdef(result).import_lib:=stringdup(import_lib^);
  5335. tobjectdef(result).objectoptions:=objectoptions;
  5336. include(tobjectdef(result).defoptions,df_copied_def);
  5337. tobjectdef(result).extendeddef:=extendeddef;
  5338. if assigned(tcinitcode) then
  5339. tobjectdef(result).tcinitcode:=tcinitcode.getcopy;
  5340. tobjectdef(result).vmt_offset:=vmt_offset;
  5341. if assigned(iidguid) then
  5342. begin
  5343. new(tobjectdef(result).iidguid);
  5344. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  5345. end;
  5346. if assigned(iidstr) then
  5347. tobjectdef(result).iidstr:=stringdup(iidstr^);
  5348. tobjectdef(result).abstractcnt:=abstractcnt;
  5349. if assigned(ImplementedInterfaces) then
  5350. begin
  5351. for i:=0 to ImplementedInterfaces.count-1 do
  5352. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  5353. end;
  5354. if assigned(vmtentries) then
  5355. begin
  5356. tobjectdef(result).vmtentries:=TFPList.Create;
  5357. tobjectdef(result).copyvmtentries(self);
  5358. end;
  5359. end;
  5360. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  5361. var
  5362. i : longint;
  5363. vmtentry : pvmtentry;
  5364. ImplIntf : TImplementedInterface;
  5365. old_do_indirect_crc: boolean;
  5366. begin
  5367. { if class1 in unit A changes, and class2 in unit B inherits from it
  5368. (so unit B uses unit A), then unit B with class2 will be recompiled.
  5369. However, if there is also a class3 in unit C that only depends on
  5370. unit B, then unit C will not be recompiled because nothing changed
  5371. to the interface of unit B. Nevertheless, unit C can indirectly
  5372. depend on unit A via derefs, and these must be updated -> the
  5373. indirect crc keeps track of such changes. }
  5374. old_do_indirect_crc:=ppufile.do_indirect_crc;
  5375. ppufile.do_indirect_crc:=true;
  5376. inherited ppuwrite(ppufile);
  5377. ppufile.putbyte(byte(objecttype));
  5378. if assigned(objextname) then
  5379. ppufile.putstring(objextname^)
  5380. else
  5381. ppufile.putstring('');
  5382. ppufile.putasizeint(tObjectSymtable(symtable).datasize);
  5383. ppufile.putword(tObjectSymtable(symtable).paddingsize);
  5384. ppufile.putbyte(byte(tObjectSymtable(symtable).fieldalignment));
  5385. ppufile.putbyte(byte(tObjectSymtable(symtable).recordalignment));
  5386. ppufile.putlongint(vmt_offset);
  5387. ppufile.putderef(childofderef);
  5388. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  5389. begin
  5390. ppufile.putguid(iidguid^);
  5391. ppufile.putstring(iidstr^);
  5392. end;
  5393. ppufile.putlongint(abstractcnt);
  5394. if objecttype=odt_helper then
  5395. ppufile.putderef(extendeddefderef);
  5396. ppufile.putlongint(vmtentries.count);
  5397. for i:=0 to vmtentries.count-1 do
  5398. begin
  5399. vmtentry:=pvmtentry(vmtentries[i]);
  5400. ppufile.putderef(vmtentry^.procdefderef);
  5401. ppufile.putbyte(byte(vmtentry^.visibility));
  5402. end;
  5403. if assigned(ImplementedInterfaces) then
  5404. begin
  5405. ppufile.putlongint(ImplementedInterfaces.Count);
  5406. for i:=0 to ImplementedInterfaces.Count-1 do
  5407. begin
  5408. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  5409. ppufile.putderef(ImplIntf.intfdefderef);
  5410. ppufile.putderef(ImplIntf.ImplementsGetterDeref);
  5411. ppufile.putlongint(ImplIntf.Ioffset);
  5412. ppufile.putbyte(byte(ImplIntf.IType));
  5413. end;
  5414. end;
  5415. if df_copied_def in defoptions then
  5416. ppufile.putderef(cloneddefderef);
  5417. ppufile.writeentry(ibobjectdef);
  5418. if not(df_copied_def in defoptions) then
  5419. tObjectSymtable(symtable).ppuwrite(ppufile);
  5420. ppufile.do_indirect_crc:=old_do_indirect_crc;
  5421. end;
  5422. function tobjectdef.GetTypeName:string;
  5423. begin
  5424. { in this case we will go in endless recursion, because then }
  5425. { there is no tsym associated yet with the def. It can occur }
  5426. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  5427. { instead of the actual type name }
  5428. if not assigned(typesym) then
  5429. result:='<Currently Parsed Class>'
  5430. else
  5431. result:=typesymbolprettyname;
  5432. end;
  5433. procedure tobjectdef.buildderef;
  5434. var
  5435. i : longint;
  5436. vmtentry : pvmtentry;
  5437. begin
  5438. inherited buildderef;
  5439. childofderef.build(childof);
  5440. if df_copied_def in defoptions then
  5441. cloneddefderef.build(symtable.defowner)
  5442. else
  5443. tstoredsymtable(symtable).buildderef;
  5444. if objecttype=odt_helper then
  5445. extendeddefderef.build(extendeddef);
  5446. for i:=0 to vmtentries.count-1 do
  5447. begin
  5448. vmtentry:=pvmtentry(vmtentries[i]);
  5449. vmtentry^.procdefderef.build(vmtentry^.procdef);
  5450. end;
  5451. if assigned(ImplementedInterfaces) then
  5452. begin
  5453. for i:=0 to ImplementedInterfaces.count-1 do
  5454. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  5455. end;
  5456. end;
  5457. procedure tobjectdef.deref;
  5458. var
  5459. i : longint;
  5460. vmtentry : pvmtentry;
  5461. begin
  5462. inherited deref;
  5463. childof:=tobjectdef(childofderef.resolve);
  5464. if df_copied_def in defoptions then
  5465. begin
  5466. cloneddef:=tobjectdef(cloneddefderef.resolve);
  5467. symtable:=cloneddef.symtable.getcopy;
  5468. end
  5469. else
  5470. tstoredsymtable(symtable).deref;
  5471. fillgenericparas(symtable);
  5472. if objecttype=odt_helper then
  5473. extendeddef:=tdef(extendeddefderef.resolve);
  5474. for i:=0 to vmtentries.count-1 do
  5475. begin
  5476. vmtentry:=pvmtentry(vmtentries[i]);
  5477. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  5478. end;
  5479. if assigned(ImplementedInterfaces) then
  5480. begin
  5481. for i:=0 to ImplementedInterfaces.count-1 do
  5482. TImplementedInterface(ImplementedInterfaces[i]).deref;
  5483. end;
  5484. end;
  5485. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  5486. var
  5487. pd: tprocdef absolute def;
  5488. st: tsymtable;
  5489. psym: tsym;
  5490. nname: TIDString;
  5491. begin
  5492. if (tdef(def).typ<>procdef) then
  5493. exit;
  5494. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  5495. owner = symtable in which objcclassdef is defined
  5496. }
  5497. st:=pd.owner.defowner.owner;
  5498. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  5499. { check for an existing procsym with our special name }
  5500. psym:=tsym(st.find(nname));
  5501. if not assigned(psym) then
  5502. begin
  5503. psym:=tprocsym.create(nname);
  5504. { avoid warning about this symbol being unused }
  5505. psym.IncRefCount;
  5506. { don't check for duplicates:
  5507. a) we checked above
  5508. b) in case we are in the implementation section of a unit, this
  5509. will also check for this symbol in the interface section
  5510. (since you normally cannot have symbols with the same name
  5511. both interface and implementation), and it's possible to
  5512. have class helpers for the same class in the interface and
  5513. in the implementation, and they cannot be merged since only
  5514. the once in the interface must be saved to the ppu/visible
  5515. from other units }
  5516. st.insert(psym,false);
  5517. end
  5518. else if (psym.typ<>procsym) then
  5519. internalerror(2009111501);
  5520. { add ourselves to this special procsym }
  5521. tprocsym(psym).procdeflist.add(def);
  5522. end;
  5523. procedure tobjectdef.buildderefimpl;
  5524. begin
  5525. inherited buildderefimpl;
  5526. if not (df_copied_def in defoptions) then
  5527. tstoredsymtable(symtable).buildderefimpl;
  5528. end;
  5529. procedure tobjectdef.derefimpl;
  5530. begin
  5531. inherited derefimpl;
  5532. if not (df_copied_def in defoptions) then
  5533. tstoredsymtable(symtable).derefimpl;
  5534. { the procdefs are not owned by the class helper procsyms, so they
  5535. are not stored/restored either -> re-add them here }
  5536. if (objecttype=odt_objcclass) or
  5537. (oo_is_classhelper in objectoptions) then
  5538. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  5539. end;
  5540. procedure tobjectdef.resetvmtentries;
  5541. var
  5542. i : longint;
  5543. begin
  5544. for i:=0 to vmtentries.Count-1 do
  5545. Dispose(pvmtentry(vmtentries[i]));
  5546. vmtentries.clear;
  5547. end;
  5548. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  5549. var
  5550. i : longint;
  5551. vmtentry : pvmtentry;
  5552. begin
  5553. resetvmtentries;
  5554. vmtentries.count:=objdef.vmtentries.count;
  5555. for i:=0 to objdef.vmtentries.count-1 do
  5556. begin
  5557. new(vmtentry);
  5558. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  5559. vmtentries[i]:=vmtentry;
  5560. end;
  5561. end;
  5562. function tobjectdef.getparentdef:tdef;
  5563. begin
  5564. { TODO: Remove getparentdef hack}
  5565. { With 2 forward declared classes with the child class before the
  5566. parent class the child class is written earlier to the ppu. Leaving it
  5567. possible to have a reference to the parent class for property overriding,
  5568. but the parent class still has the childof not resolved yet (PFV) }
  5569. if childof=nil then
  5570. childof:=tobjectdef(childofderef.resolve);
  5571. result:=childof;
  5572. end;
  5573. procedure tobjectdef.prepareguid;
  5574. begin
  5575. { set up guid }
  5576. if not assigned(iidguid) then
  5577. begin
  5578. new(iidguid);
  5579. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  5580. end;
  5581. { setup iidstring }
  5582. if not assigned(iidstr) then
  5583. iidstr:=stringdup(''); { default is empty string }
  5584. end;
  5585. procedure tobjectdef.set_parent( c : tobjectdef);
  5586. begin
  5587. if assigned(childof) then
  5588. exit;
  5589. childof:=c;
  5590. if not assigned(c) then
  5591. exit;
  5592. { inherit options and status }
  5593. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  5594. { initially has the same number of abstract methods as the parent }
  5595. abstractcnt:=c.abstractcnt;
  5596. { add the data of the anchestor class/object }
  5597. if (objecttype in [odt_class,odt_object,odt_objcclass,odt_javaclass]) then
  5598. begin
  5599. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  5600. { inherit recordalignment }
  5601. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  5602. { if both the parent and this record use C-alignment, also inherit
  5603. the current field alignment }
  5604. if (tObjectSymtable(c.symtable).usefieldalignment=C_alignment) and
  5605. (tObjectSymtable(symtable).usefieldalignment=C_alignment) then
  5606. tObjectSymtable(symtable).fieldalignment:=tObjectSymtable(c.symtable).fieldalignment;
  5607. { the padding is not inherited for Objective-C classes (maybe not
  5608. for cppclass either?) }
  5609. if objecttype=odt_objcclass then
  5610. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-tObjectSymtable(c.symtable).paddingsize;
  5611. if (oo_has_vmt in objectoptions) and
  5612. (oo_has_vmt in c.objectoptions) then
  5613. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  5614. { if parent has a vmt field then the offset is the same for the child PM }
  5615. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  5616. begin
  5617. vmt_offset:=c.vmt_offset;
  5618. include(objectoptions,oo_has_vmt);
  5619. end;
  5620. end;
  5621. end;
  5622. procedure tobjectdef.insertvmt;
  5623. var
  5624. vs: tfieldvarsym;
  5625. begin
  5626. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava] then
  5627. exit;
  5628. if (oo_has_vmt in objectoptions) then
  5629. internalerror(12345)
  5630. else
  5631. begin
  5632. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  5633. tObjectSymtable(symtable).fieldalignment);
  5634. if (tf_requires_proper_alignment in target_info.flags) then
  5635. begin
  5636. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  5637. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  5638. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  5639. end;
  5640. vs:=tfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  5641. hidesym(vs);
  5642. tObjectSymtable(symtable).insert(vs);
  5643. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  5644. if (tObjectSymtable(symtable).usefieldalignment<>bit_alignment) then
  5645. vmt_offset:=vs.fieldoffset
  5646. else
  5647. vmt_offset:=vs.fieldoffset div 8;
  5648. include(objectoptions,oo_has_vmt);
  5649. end;
  5650. end;
  5651. procedure tobjectdef.check_forwards;
  5652. begin
  5653. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol,odt_interfacejava]) then
  5654. inherited;
  5655. if (oo_is_forward in objectoptions) then
  5656. begin
  5657. { ok, in future, the forward can be resolved }
  5658. Message1(sym_e_class_forward_not_resolved,objrealname^);
  5659. exclude(objectoptions,oo_is_forward);
  5660. end;
  5661. end;
  5662. function tobjectdef.find_destructor: tprocdef;
  5663. var
  5664. objdef: tobjectdef;
  5665. begin
  5666. objdef:=self;
  5667. while assigned(objdef) do
  5668. begin
  5669. result:=objdef.find_procdef_bytype(potype_destructor);
  5670. if assigned(result) then
  5671. exit;
  5672. objdef:=objdef.childof;
  5673. end;
  5674. result:=nil;
  5675. end;
  5676. function tobjectdef.implements_any_interfaces: boolean;
  5677. begin
  5678. result := (ImplementedInterfaces.Count > 0) or
  5679. (assigned(childof) and childof.implements_any_interfaces);
  5680. end;
  5681. function tobjectdef.size : asizeint;
  5682. begin
  5683. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5684. result:=sizeof(pint)
  5685. else
  5686. result:=tObjectSymtable(symtable).datasize;
  5687. end;
  5688. function tobjectdef.alignment:shortint;
  5689. begin
  5690. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then
  5691. alignment:=sizeof(pint)
  5692. else
  5693. alignment:=tObjectSymtable(symtable).recordalignment;
  5694. end;
  5695. function tobjectdef.vmtmethodoffset(index:longint):longint;
  5696. var
  5697. codeptrsize: Integer;
  5698. begin
  5699. {$ifdef i8086}
  5700. if current_settings.x86memorymodel in x86_far_code_models then
  5701. codeptrsize:=4
  5702. else
  5703. codeptrsize:=2;
  5704. {$else i8086}
  5705. codeptrsize:=sizeof(pint);
  5706. {$endif i8086}
  5707. { for offset of methods for classes, see rtl/inc/objpash.inc }
  5708. case objecttype of
  5709. odt_class:
  5710. { the +2*sizeof(pint) is size and -size }
  5711. vmtmethodoffset:=index*codeptrsize+10*sizeof(pint)+2*sizeof(pint);
  5712. odt_helper,
  5713. odt_objcclass,
  5714. odt_objcprotocol:
  5715. vmtmethodoffset:=0;
  5716. odt_interfacecom,odt_interfacecorba,odt_dispinterface:
  5717. vmtmethodoffset:=index*codeptrsize;
  5718. odt_javaclass,
  5719. odt_interfacejava:
  5720. { invalid }
  5721. vmtmethodoffset:=-1;
  5722. else
  5723. {$ifdef WITHDMT}
  5724. vmtmethodoffset:=index*codeptrsize+4*sizeof(pint);
  5725. {$else WITHDMT}
  5726. vmtmethodoffset:=index*codeptrsize+3*sizeof(pint);
  5727. {$endif WITHDMT}
  5728. end;
  5729. end;
  5730. function tobjectdef.vmt_mangledname : TSymStr;
  5731. begin
  5732. if not(oo_has_vmt in objectoptions) then
  5733. Message1(parser_n_object_has_no_vmt,objrealname^);
  5734. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  5735. end;
  5736. function tobjectdef.needs_inittable : boolean;
  5737. var
  5738. hp : tobjectdef;
  5739. begin
  5740. case objecttype of
  5741. odt_helper,
  5742. odt_class :
  5743. needs_inittable:=false;
  5744. odt_dispinterface,
  5745. odt_interfacecom:
  5746. needs_inittable:=true;
  5747. odt_interfacecorba:
  5748. begin
  5749. hp:=childof;
  5750. while assigned(hp) do
  5751. begin
  5752. if hp=interface_iunknown then
  5753. begin
  5754. needs_inittable:=true;
  5755. exit;
  5756. end;
  5757. hp:=hp.childof;
  5758. end;
  5759. needs_inittable:=false;
  5760. end;
  5761. odt_object:
  5762. needs_inittable:=
  5763. tObjectSymtable(symtable).needs_init_final or
  5764. (assigned(childof) and
  5765. childof.needs_inittable);
  5766. odt_cppclass,
  5767. odt_objcclass,
  5768. odt_objcprotocol,
  5769. odt_javaclass,
  5770. odt_interfacejava:
  5771. needs_inittable:=false;
  5772. else
  5773. internalerror(200108267);
  5774. end;
  5775. end;
  5776. function tobjectdef.needs_separate_initrtti : boolean;
  5777. begin
  5778. result:=not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  5779. end;
  5780. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  5781. begin
  5782. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  5783. result:=inherited rtti_mangledname(rt)
  5784. else
  5785. begin
  5786. { necessary in case of a dynamic array of nsobject, or
  5787. if an nsobject field appears in a record that needs
  5788. init/finalisation }
  5789. if rt=initrtti then
  5790. begin
  5791. result:=voidpointertype.rtti_mangledname(rt);
  5792. exit;
  5793. end;
  5794. if not(target_info.system in systems_objc_nfabi) then
  5795. begin
  5796. result:=target_asm.labelprefix;
  5797. case objecttype of
  5798. odt_objcclass:
  5799. begin
  5800. case rt of
  5801. objcclassrtti:
  5802. if not(oo_is_classhelper in objectoptions) then
  5803. result:=result+'_OBJC_CLASS_'
  5804. else
  5805. result:=result+'_OBJC_CATEGORY_';
  5806. objcmetartti:
  5807. if not(oo_is_classhelper in objectoptions) then
  5808. result:=result+'_OBJC_METACLASS_'
  5809. else
  5810. internalerror(2009111511);
  5811. else
  5812. internalerror(2009092302);
  5813. end;
  5814. end;
  5815. odt_objcprotocol:
  5816. result:=result+'_OBJC_PROTOCOL_';
  5817. end;
  5818. end
  5819. else
  5820. begin
  5821. case objecttype of
  5822. odt_objcclass:
  5823. begin
  5824. if (oo_is_classhelper in objectoptions) and
  5825. (rt<>objcclassrtti) then
  5826. internalerror(2009111512);
  5827. case rt of
  5828. objcclassrtti:
  5829. if not(oo_is_classhelper in objectoptions) then
  5830. result:='_OBJC_CLASS_$_'
  5831. else
  5832. result:='_OBJC_$_CATEGORY_';
  5833. objcmetartti:
  5834. result:='_OBJC_METACLASS_$_';
  5835. objcclassrortti:
  5836. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  5837. objcmetarortti:
  5838. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  5839. else
  5840. internalerror(2009092303);
  5841. end;
  5842. end;
  5843. odt_objcprotocol:
  5844. begin
  5845. result:=lower(target_asm.labelprefix);
  5846. case rt of
  5847. objcclassrtti:
  5848. result:=result+'_OBJC_PROTOCOL_$_';
  5849. objcmetartti:
  5850. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  5851. else
  5852. internalerror(2009092501);
  5853. end;
  5854. end;
  5855. else
  5856. internalerror(2013113005);
  5857. end;
  5858. end;
  5859. result:=result+objextname^;
  5860. end;
  5861. end;
  5862. function tobjectdef.members_need_inittable : boolean;
  5863. begin
  5864. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  5865. end;
  5866. function tobjectdef.is_publishable : boolean;
  5867. begin
  5868. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  5869. end;
  5870. function tobjectdef.get_next_dispid: longint;
  5871. begin
  5872. inc(fcurrent_dispid);
  5873. result:=fcurrent_dispid;
  5874. end;
  5875. function tobjectdef.search_enumerator_get: tprocdef;
  5876. begin
  5877. result:=inherited;
  5878. if not assigned(result) and assigned(childof) then
  5879. result:=childof.search_enumerator_get;
  5880. end;
  5881. function tobjectdef.search_enumerator_move: tprocdef;
  5882. begin
  5883. result:=inherited;
  5884. if not assigned(result) and assigned(childof) then
  5885. result:=childof.search_enumerator_move;
  5886. end;
  5887. function tobjectdef.search_enumerator_current: tsym;
  5888. begin
  5889. result:=inherited;
  5890. if not assigned(result) and assigned(childof) then
  5891. result:=childof.search_enumerator_current;
  5892. end;
  5893. procedure tobjectdef.register_created_classref_type;
  5894. begin
  5895. if not classref_created_in_current_module then
  5896. begin
  5897. classref_created_in_current_module:=true;
  5898. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  5899. end;
  5900. end;
  5901. procedure tobjectdef.register_created_object_type;
  5902. begin
  5903. if not created_in_current_module then
  5904. begin
  5905. created_in_current_module:=true;
  5906. current_module.wpoinfo.addcreatedobjtype(self);
  5907. end;
  5908. end;
  5909. procedure tobjectdef.register_maybe_created_object_type;
  5910. begin
  5911. { if we know it has been created for sure, no need
  5912. to also record that it maybe can be created in
  5913. this module
  5914. }
  5915. if not (created_in_current_module) and
  5916. not (maybe_created_in_current_module) then
  5917. begin
  5918. maybe_created_in_current_module:=true;
  5919. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  5920. end;
  5921. end;
  5922. procedure tobjectdef.register_vmt_call(index: longint);
  5923. begin
  5924. if (is_object(self) or is_class(self)) then
  5925. current_module.wpoinfo.addcalledvmtentry(self,index);
  5926. end;
  5927. procedure check_and_finish_msg(data: tobject; arg: pointer);
  5928. var
  5929. def: tdef absolute data;
  5930. pd: tprocdef absolute data;
  5931. i,
  5932. paracount: longint;
  5933. begin
  5934. if (def.typ=procdef) then
  5935. begin
  5936. { add all messages also under a dummy name to the symtable in
  5937. which the objcclass/protocol/category is declared, so they can
  5938. be called via id.<name>
  5939. }
  5940. create_class_helper_for_procdef(pd,nil);
  5941. { we have to wait until now to set the mangled name because it
  5942. depends on the (possibly external) class name, which is defined
  5943. at the very end. }
  5944. if not(po_msgstr in pd.procoptions) then
  5945. begin
  5946. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  5947. { recover to avoid internalerror later on }
  5948. include(pd.procoptions,po_msgstr);
  5949. pd.messageinf.str:=stringdup('MissingDeclaration');
  5950. end;
  5951. { Mangled name is already set in case this is a copy of
  5952. another type. }
  5953. if not(po_has_mangledname in pd.procoptions) then
  5954. begin
  5955. { check whether the number of formal parameters is correct,
  5956. and whether they have valid Objective-C types }
  5957. paracount:=0;
  5958. for i:=1 to length(pd.messageinf.str^) do
  5959. if pd.messageinf.str^[i]=':' then
  5960. inc(paracount);
  5961. for i:=0 to pd.paras.count-1 do
  5962. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  5963. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  5964. dec(paracount);
  5965. if (paracount<>0) then
  5966. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  5967. pd.setmangledname(pd.objcmangledname);
  5968. end
  5969. else
  5970. { all checks already done }
  5971. exit;
  5972. if not(oo_is_external in pd.struct.objectoptions) then
  5973. begin
  5974. if (po_varargs in pd.procoptions) then
  5975. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  5976. else
  5977. begin
  5978. { check for "array of const" parameters }
  5979. for i:=0 to pd.parast.symlist.count-1 do
  5980. begin
  5981. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  5982. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  5983. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  5984. end;
  5985. end;
  5986. end;
  5987. end;
  5988. end;
  5989. procedure mark_private_fields_used(data: tobject; arg: pointer);
  5990. var
  5991. sym: tsym absolute data;
  5992. begin
  5993. if (sym.typ=fieldvarsym) and
  5994. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  5995. sym.IncRefCount;
  5996. end;
  5997. procedure tobjectdef.finish_objc_data;
  5998. begin
  5999. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  6000. if (oo_is_external in objectoptions) then
  6001. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  6002. end;
  6003. procedure verify_objc_vardef(data: tobject; arg: pointer);
  6004. var
  6005. sym: tabstractvarsym absolute data;
  6006. res: pboolean absolute arg;
  6007. founderrordef: tdef;
  6008. begin
  6009. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  6010. exit;
  6011. if (sym.typ=paravarsym) and
  6012. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  6013. is_array_of_const(tparavarsym(sym).vardef)) then
  6014. exit;
  6015. if not objcchecktype(sym.vardef,founderrordef) then
  6016. begin
  6017. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6018. res^:=false;
  6019. end;
  6020. end;
  6021. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  6022. var
  6023. def: tdef absolute data;
  6024. res: pboolean absolute arg;
  6025. founderrordef: tdef;
  6026. begin
  6027. if (def.typ<>procdef) then
  6028. exit;
  6029. { check parameter types for validity }
  6030. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  6031. { check the result type for validity }
  6032. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  6033. begin
  6034. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  6035. res^:=false;
  6036. end;
  6037. end;
  6038. function tobjectdef.check_objc_types: boolean;
  6039. begin
  6040. { done in separate step from finish_objc_data, because when
  6041. finish_objc_data is called, not all forwarddefs have been resolved
  6042. yet and we need to know all types here }
  6043. result:=true;
  6044. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  6045. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  6046. end;
  6047. procedure do_cpp_import_info(data: tobject; arg: pointer);
  6048. var
  6049. def: tdef absolute data;
  6050. pd: tprocdef absolute data;
  6051. begin
  6052. if (def.typ=procdef) then
  6053. begin
  6054. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  6055. if (oo_is_external in pd.struct.objectoptions) then
  6056. begin
  6057. { copied from psub.read_proc }
  6058. if assigned(tobjectdef(pd.struct).import_lib) then
  6059. current_module.AddExternalImport(tobjectdef(pd.struct).import_lib^,pd.mangledname,pd.mangledname,0,false,false)
  6060. else
  6061. begin
  6062. { add import name to external list for DLL scanning }
  6063. if tf_has_dllscanner in target_info.flags then
  6064. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  6065. end;
  6066. end;
  6067. end;
  6068. end;
  6069. procedure tobjectdef.finish_cpp_data;
  6070. begin
  6071. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  6072. end;
  6073. {****************************************************************************
  6074. TImplementedInterface
  6075. ****************************************************************************}
  6076. function TImplementedInterface.GetIOffset: longint;
  6077. begin
  6078. if (fIOffset=-1) and
  6079. (IType in [etFieldValue,etFieldValueClass]) then
  6080. result:=tfieldvarsym(ImplementsField).fieldoffset
  6081. else
  6082. result:=fIOffset;
  6083. end;
  6084. constructor TImplementedInterface.create(aintf: tobjectdef);
  6085. begin
  6086. inherited create;
  6087. intfdef:=aintf;
  6088. IOffset:=-1;
  6089. IType:=etStandard;
  6090. NameMappings:=nil;
  6091. procdefs:=nil;
  6092. end;
  6093. constructor TImplementedInterface.create_deref(intfd,getterd:tderef);
  6094. begin
  6095. inherited create;
  6096. intfdef:=nil;
  6097. intfdefderef:=intfd;
  6098. ImplementsGetterDeref:=getterd;
  6099. IOffset:=-1;
  6100. IType:=etStandard;
  6101. NameMappings:=nil;
  6102. procdefs:=nil;
  6103. end;
  6104. destructor TImplementedInterface.destroy;
  6105. var
  6106. i : longint;
  6107. mappedname : pshortstring;
  6108. begin
  6109. if assigned(NameMappings) then
  6110. begin
  6111. for i:=0 to NameMappings.Count-1 do
  6112. begin
  6113. mappedname:=pshortstring(NameMappings[i]);
  6114. stringdispose(mappedname);
  6115. end;
  6116. NameMappings.free;
  6117. NameMappings:=nil;
  6118. end;
  6119. if assigned(procdefs) then
  6120. begin
  6121. procdefs.free;
  6122. procdefs:=nil;
  6123. end;
  6124. inherited destroy;
  6125. end;
  6126. procedure TImplementedInterface.buildderef;
  6127. begin
  6128. intfdefderef.build(intfdef);
  6129. ImplementsGetterDeref.build(ImplementsGetter);
  6130. end;
  6131. procedure TImplementedInterface.deref;
  6132. begin
  6133. intfdef:=tobjectdef(intfdefderef.resolve);
  6134. ImplementsGetter:=tsym(ImplementsGetterDeref.resolve);
  6135. end;
  6136. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  6137. begin
  6138. if not assigned(NameMappings) then
  6139. NameMappings:=TFPHashList.Create;
  6140. NameMappings.Add(origname,stringdup(newname));
  6141. end;
  6142. function TImplementedInterface.GetMapping(const origname: string):string;
  6143. var
  6144. mappedname : pshortstring;
  6145. begin
  6146. result:='';
  6147. if not assigned(NameMappings) then
  6148. exit;
  6149. mappedname:=PShortstring(NameMappings.Find(origname));
  6150. if assigned(mappedname) then
  6151. result:=mappedname^;
  6152. end;
  6153. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  6154. begin
  6155. if not assigned(procdefs) then
  6156. procdefs:=TFPObjectList.Create(false);
  6157. { duplicate entries must be stored, because multiple }
  6158. { interfaces can declare methods with the same name }
  6159. { and all of these get their own VMT entry }
  6160. procdefs.Add(pd);
  6161. end;
  6162. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  6163. var
  6164. i : longint;
  6165. begin
  6166. result:=false;
  6167. { interfaces being implemented through delegation are not mergable (FK) }
  6168. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) or not(assigned(MergingIntf.ProcDefs)) then
  6169. exit;
  6170. weight:=0;
  6171. { empty interface is mergeable }
  6172. if ProcDefs.Count=0 then
  6173. begin
  6174. result:=true;
  6175. exit;
  6176. end;
  6177. { The interface to merge must at least the number of
  6178. procedures of this interface }
  6179. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  6180. exit;
  6181. for i:=0 to ProcDefs.Count-1 do
  6182. begin
  6183. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  6184. exit;
  6185. end;
  6186. weight:=ProcDefs.Count;
  6187. result:=true;
  6188. end;
  6189. function TImplementedInterface.getcopy:TImplementedInterface;
  6190. begin
  6191. Result:=TImplementedInterface.Create(nil);
  6192. { 1) the procdefs list will be freed once for each copy
  6193. 2) since the procdefs list owns its elements, those will also be freed for each copy
  6194. 3) idem for the name mappings
  6195. }
  6196. { warning: this is completely wrong on so many levels...
  6197. Move(pointer(self)^,pointer(result)^,InstanceSize);
  6198. We need to make clean copies of the different fields
  6199. this is not implemented yet, and thus we generate an internal
  6200. error instead PM 2011-06-14 }
  6201. internalerror(2011061401);
  6202. end;
  6203. {****************************************************************************
  6204. TFORWARDDEF
  6205. ****************************************************************************}
  6206. constructor tforwarddef.create(const s:string;const pos:tfileposinfo);
  6207. begin
  6208. inherited create(forwarddef);
  6209. tosymname:=stringdup(s);
  6210. forwardpos:=pos;
  6211. end;
  6212. function tforwarddef.GetTypeName:string;
  6213. begin
  6214. GetTypeName:='unresolved forward to '+tosymname^;
  6215. end;
  6216. destructor tforwarddef.destroy;
  6217. begin
  6218. stringdispose(tosymname);
  6219. inherited destroy;
  6220. end;
  6221. function tforwarddef.getcopy:tstoreddef;
  6222. begin
  6223. result:=tforwarddef.create(tosymname^, forwardpos);
  6224. end;
  6225. {****************************************************************************
  6226. TUNDEFINEDDEF
  6227. ****************************************************************************}
  6228. constructor tundefineddef.create;
  6229. begin
  6230. inherited create(undefineddef);
  6231. end;
  6232. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  6233. begin
  6234. inherited ppuload(undefineddef,ppufile);
  6235. end;
  6236. function tundefineddef.GetTypeName:string;
  6237. begin
  6238. GetTypeName:='<undefined type>';
  6239. end;
  6240. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  6241. begin
  6242. inherited ppuwrite(ppufile);
  6243. ppufile.writeentry(ibundefineddef);
  6244. end;
  6245. {****************************************************************************
  6246. TERRORDEF
  6247. ****************************************************************************}
  6248. constructor terrordef.create;
  6249. begin
  6250. inherited create(errordef);
  6251. { prevent consecutive faults }
  6252. savesize:=1;
  6253. end;
  6254. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  6255. begin
  6256. { Can't write errordefs to ppu }
  6257. internalerror(200411063);
  6258. end;
  6259. function terrordef.GetTypeName:string;
  6260. begin
  6261. GetTypeName:='<erroneous type>';
  6262. end;
  6263. function terrordef.getmangledparaname:TSymStr;
  6264. begin
  6265. getmangledparaname:='error';
  6266. end;
  6267. {****************************************************************************
  6268. Definition Helpers
  6269. ****************************************************************************}
  6270. function is_interfacecom(def: tdef): boolean;
  6271. begin
  6272. is_interfacecom:=
  6273. assigned(def) and
  6274. (def.typ=objectdef) and
  6275. (tobjectdef(def).objecttype=odt_interfacecom);
  6276. end;
  6277. function is_interfacecom_or_dispinterface(def: tdef): boolean;
  6278. begin
  6279. is_interfacecom_or_dispinterface:=
  6280. assigned(def) and
  6281. (def.typ=objectdef) and
  6282. (tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface]);
  6283. end;
  6284. function is_any_interface_kind(def: tdef): boolean;
  6285. begin
  6286. result:=
  6287. assigned(def) and
  6288. (def.typ=objectdef) and
  6289. ((tobjectdef(def).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba,odt_interfacejava,odt_objcprotocol]) or
  6290. is_objccategory(def));
  6291. end;
  6292. function is_interfacecorba(def: tdef): boolean;
  6293. begin
  6294. is_interfacecorba:=
  6295. assigned(def) and
  6296. (def.typ=objectdef) and
  6297. (tobjectdef(def).objecttype=odt_interfacecorba);
  6298. end;
  6299. function is_interface(def: tdef): boolean;
  6300. begin
  6301. is_interface:=
  6302. assigned(def) and
  6303. (def.typ=objectdef) and
  6304. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  6305. end;
  6306. function is_dispinterface(def: tdef): boolean;
  6307. begin
  6308. result:=
  6309. assigned(def) and
  6310. (def.typ=objectdef) and
  6311. (tobjectdef(def).objecttype=odt_dispinterface);
  6312. end;
  6313. function is_class(def: tdef): boolean;
  6314. begin
  6315. is_class:=
  6316. assigned(def) and
  6317. (def.typ=objectdef) and
  6318. (tobjectdef(def).objecttype=odt_class);
  6319. end;
  6320. function is_object(def: tdef): boolean;
  6321. begin
  6322. is_object:=
  6323. assigned(def) and
  6324. (def.typ=objectdef) and
  6325. (tobjectdef(def).objecttype=odt_object);
  6326. end;
  6327. function is_cppclass(def: tdef): boolean;
  6328. begin
  6329. is_cppclass:=
  6330. assigned(def) and
  6331. (def.typ=objectdef) and
  6332. (tobjectdef(def).objecttype=odt_cppclass);
  6333. end;
  6334. function is_objcclass(def: tdef): boolean;
  6335. begin
  6336. is_objcclass:=
  6337. assigned(def) and
  6338. (def.typ=objectdef) and
  6339. (tobjectdef(def).objecttype=odt_objcclass);
  6340. end;
  6341. function is_objectpascal_helper(def: tdef): boolean;
  6342. begin
  6343. result:=
  6344. assigned(def) and
  6345. (def.typ=objectdef) and
  6346. (tobjectdef(def).objecttype=odt_helper);
  6347. end;
  6348. function is_objcclassref(def: tdef): boolean;
  6349. begin
  6350. is_objcclassref:=
  6351. assigned(def) and
  6352. (def.typ=classrefdef) and
  6353. is_objcclass(tclassrefdef(def).pointeddef);
  6354. end;
  6355. function is_objcprotocol(def: tdef): boolean;
  6356. begin
  6357. result:=
  6358. assigned(def) and
  6359. (def.typ=objectdef) and
  6360. (tobjectdef(def).objecttype=odt_objcprotocol);
  6361. end;
  6362. function is_objccategory(def: tdef): boolean;
  6363. begin
  6364. result:=
  6365. assigned(def) and
  6366. (def.typ=objectdef) and
  6367. { if used as a forward type }
  6368. ((tobjectdef(def).objecttype=odt_objccategory) or
  6369. { if used as after it has been resolved }
  6370. ((tobjectdef(def).objecttype=odt_objcclass) and
  6371. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6372. end;
  6373. function is_objc_class_or_protocol(def: tdef): boolean;
  6374. begin
  6375. result:=
  6376. assigned(def) and
  6377. (def.typ=objectdef) and
  6378. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  6379. end;
  6380. function is_objc_protocol_or_category(def: tdef): boolean;
  6381. begin
  6382. result:=
  6383. assigned(def) and
  6384. (def.typ=objectdef) and
  6385. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  6386. ((tobjectdef(def).objecttype = odt_objcclass) and
  6387. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  6388. end;
  6389. function is_classhelper(def: tdef): boolean;
  6390. begin
  6391. result:=
  6392. is_objectpascal_helper(def) or
  6393. is_objccategory(def);
  6394. end;
  6395. function is_class_or_interface(def: tdef): boolean;
  6396. begin
  6397. result:=
  6398. assigned(def) and
  6399. (def.typ=objectdef) and
  6400. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  6401. end;
  6402. function is_class_or_interface_or_objc(def: tdef): boolean;
  6403. begin
  6404. result:=
  6405. assigned(def) and
  6406. (def.typ=objectdef) and
  6407. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  6408. end;
  6409. function is_class_or_interface_or_objc_or_java(def: tdef): boolean;
  6410. begin
  6411. result:=
  6412. assigned(def) and
  6413. (def.typ=objectdef) and
  6414. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6415. end;
  6416. function is_class_or_interface_or_dispinterface_or_objc_or_java(def: tdef): boolean;
  6417. begin
  6418. result:=
  6419. assigned(def) and
  6420. (def.typ=objectdef) and
  6421. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_javaclass,odt_interfacejava]);
  6422. end;
  6423. function is_class_or_interface_or_object(def: tdef): boolean;
  6424. begin
  6425. result:=
  6426. assigned(def) and
  6427. (def.typ=objectdef) and
  6428. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  6429. end;
  6430. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  6431. begin
  6432. result:=
  6433. assigned(def) and
  6434. (def.typ=objectdef) and
  6435. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  6436. end;
  6437. function is_implicit_pointer_object_type(def: tdef): boolean;
  6438. begin
  6439. result:=
  6440. assigned(def) and
  6441. (((def.typ=objectdef) and
  6442. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava])) or
  6443. ((target_info.system in systems_jvm) and
  6444. (def.typ=recorddef)));
  6445. end;
  6446. function is_class_or_object(def: tdef): boolean;
  6447. begin
  6448. result:=
  6449. assigned(def) and
  6450. (def.typ=objectdef) and
  6451. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  6452. end;
  6453. function is_record(def: tdef): boolean;
  6454. begin
  6455. result:=
  6456. assigned(def) and
  6457. (def.typ=recorddef);
  6458. end;
  6459. function is_javaclass(def: tdef): boolean;
  6460. begin
  6461. result:=
  6462. assigned(def) and
  6463. (def.typ=objectdef) and
  6464. (tobjectdef(def).objecttype=odt_javaclass);
  6465. end;
  6466. function is_javaclassref(def: tdef): boolean;
  6467. begin
  6468. is_javaclassref:=
  6469. assigned(def) and
  6470. (def.typ=classrefdef) and
  6471. is_javaclass(tclassrefdef(def).pointeddef);
  6472. end;
  6473. function is_javainterface(def: tdef): boolean;
  6474. begin
  6475. result:=
  6476. assigned(def) and
  6477. (def.typ=objectdef) and
  6478. (tobjectdef(def).objecttype=odt_interfacejava);
  6479. end;
  6480. function is_java_class_or_interface(def: tdef): boolean;
  6481. begin
  6482. result:=
  6483. assigned(def) and
  6484. (def.typ=objectdef) and
  6485. (tobjectdef(def).objecttype in [odt_javaclass,odt_interfacejava]);
  6486. end;
  6487. procedure loadobjctypes;
  6488. begin
  6489. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS',true).typedef);
  6490. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER',true).typedef);
  6491. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID',true).typedef);
  6492. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL',true).typedef);
  6493. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT',true).typedef);
  6494. end;
  6495. procedure maybeloadcocoatypes;
  6496. var
  6497. tsym: ttypesym;
  6498. cocoaunit: string[15];
  6499. begin
  6500. if assigned(objc_fastenumeration) then
  6501. exit;
  6502. if not(target_info.system in [system_arm_darwin,system_i386_iphonesim]) then
  6503. cocoaunit:='COCOAALL'
  6504. else
  6505. cocoaunit:='IPHONEALL';
  6506. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONPROTOCOL',false);
  6507. if assigned(tsym) then
  6508. objc_fastenumeration:=tobjectdef(tsym.typedef)
  6509. else
  6510. objc_fastenumeration:=nil;
  6511. tsym:=search_named_unit_globaltype(cocoaunit,'NSFASTENUMERATIONSTATE',false);
  6512. if assigned(tsym) then
  6513. objc_fastenumerationstate:=trecorddef(tsym.typedef)
  6514. else
  6515. objc_fastenumerationstate:=nil;
  6516. end;
  6517. function use_vectorfpu(def : tdef) : boolean;
  6518. begin
  6519. {$ifdef x86}
  6520. {$define use_vectorfpuimplemented}
  6521. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  6522. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  6523. {$endif x86}
  6524. {$ifdef arm}
  6525. {$define use_vectorfpuimplemented}
  6526. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  6527. {$endif arm}
  6528. {$ifndef use_vectorfpuimplemented}
  6529. use_vectorfpu:=false;
  6530. {$endif}
  6531. end;
  6532. function getpointerdef(def: tdef): tpointerdef;
  6533. var
  6534. res: PHashSetItem;
  6535. oldsymtablestack: tsymtablestack;
  6536. begin
  6537. if not assigned(current_module) then
  6538. internalerror(2011071101);
  6539. res:=current_module.ptrdefs.FindOrAdd(@def,sizeof(def));
  6540. if not assigned(res^.Data) then
  6541. begin
  6542. { since these pointerdefs can be reused anywhere in the current
  6543. unit, add them to the global/staticsymtable }
  6544. oldsymtablestack:=symtablestack;
  6545. { do not simply push/pop current_module.localsymtable, because
  6546. that can have side-effects (e.g., it removes helpers) }
  6547. symtablestack:=nil;
  6548. res^.Data:=tpointerdef.create(def);
  6549. if assigned(current_module.localsymtable) then
  6550. current_module.localsymtable.insertdef(tdef(res^.Data))
  6551. else
  6552. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6553. symtablestack:=oldsymtablestack;
  6554. end;
  6555. result:=tpointerdef(res^.Data);
  6556. end;
  6557. function getsingletonarraydef(def: tdef): tarraydef;
  6558. begin
  6559. result:=getarraydef(def,1);
  6560. end;
  6561. function getarraydef(def: tdef; elecount: asizeint): tarraydef;
  6562. var
  6563. res: PHashSetItem;
  6564. oldsymtablestack: tsymtablestack;
  6565. arrdesc: packed record
  6566. def: tdef;
  6567. elecount: asizeint;
  6568. end;
  6569. begin
  6570. if not assigned(current_module) then
  6571. internalerror(2011081301);
  6572. arrdesc.def:=def;
  6573. arrdesc.elecount:=elecount;
  6574. res:=current_module.arraydefs.FindOrAdd(@arrdesc,sizeof(arrdesc));
  6575. if not assigned(res^.Data) then
  6576. begin
  6577. { since these arraydef can be reused anywhere in the current
  6578. unit, add them to the global/staticsymtable }
  6579. oldsymtablestack:=symtablestack;
  6580. symtablestack:=nil;
  6581. res^.Data:=tarraydef.create(0,elecount-1,ptrsinttype);
  6582. tarraydef(res^.Data).elementdef:=def;
  6583. if assigned(current_module.localsymtable) then
  6584. current_module.localsymtable.insertdef(tdef(res^.Data))
  6585. else
  6586. current_module.globalsymtable.insertdef(tdef(res^.Data));
  6587. symtablestack:=oldsymtablestack;
  6588. end;
  6589. result:=tarraydef(res^.Data);
  6590. end;
  6591. end.