symdef.pas 248 KB

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