symdef.pas 244 KB

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