symdef.pas 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414
  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,aasmdata,
  33. cpubase,cpuinfo,
  34. cgbase,cgutils,
  35. parabase
  36. ;
  37. type
  38. {************************************************
  39. TDef
  40. ************************************************}
  41. { tstoreddef }
  42. tstoreddef = class(tdef)
  43. protected
  44. typesymderef : tderef;
  45. public
  46. {$ifdef EXTDEBUG}
  47. fileinfo : tfileposinfo;
  48. {$endif}
  49. { generic support }
  50. genericdef : tstoreddef;
  51. genericdefderef : tderef;
  52. generictokenbuf : tdynamicarray;
  53. constructor create(dt:tdeftyp);
  54. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  55. destructor destroy;override;
  56. procedure reset;virtual;
  57. function getcopy : tstoreddef;virtual;
  58. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  59. procedure buildderef;override;
  60. procedure buildderefimpl;override;
  61. procedure deref;override;
  62. procedure derefimpl;override;
  63. function size:aint;override;
  64. function getvardef:longint;override;
  65. function alignment:shortint;override;
  66. function is_publishable : boolean;override;
  67. function needs_inittable : boolean;override;
  68. function rtti_mangledname(rt:trttitype):string;override;
  69. { regvars }
  70. function is_intregable : boolean;
  71. function is_fpuregable : boolean;
  72. { generics }
  73. procedure initgeneric;
  74. private
  75. savesize : aint;
  76. end;
  77. tfiletyp = (ft_text,ft_typed,ft_untyped);
  78. tfiledef = class(tstoreddef)
  79. filetyp : tfiletyp;
  80. typedfiledef : tdef;
  81. typedfiledefderef : tderef;
  82. constructor createtext;
  83. constructor createuntyped;
  84. constructor createtyped(def : tdef);
  85. constructor ppuload(ppufile:tcompilerppufile);
  86. function getcopy : tstoreddef;override;
  87. procedure ppuwrite(ppufile:tcompilerppufile);override;
  88. procedure buildderef;override;
  89. procedure deref;override;
  90. function GetTypeName:string;override;
  91. function getmangledparaname:string;override;
  92. procedure setsize;
  93. end;
  94. tvariantdef = class(tstoreddef)
  95. varianttype : tvarianttype;
  96. constructor create(v : tvarianttype);
  97. constructor ppuload(ppufile:tcompilerppufile);
  98. function getcopy : tstoreddef;override;
  99. function GetTypeName:string;override;
  100. procedure ppuwrite(ppufile:tcompilerppufile);override;
  101. function getvardef:longint;override;
  102. procedure setsize;
  103. function is_publishable : boolean;override;
  104. function needs_inittable : boolean;override;
  105. end;
  106. tformaldef = class(tstoreddef)
  107. typed:boolean;
  108. constructor create(Atyped:boolean);
  109. constructor ppuload(ppufile:tcompilerppufile);
  110. procedure ppuwrite(ppufile:tcompilerppufile);override;
  111. function GetTypeName:string;override;
  112. end;
  113. tforwarddef = class(tstoreddef)
  114. tosymname : pshortstring;
  115. forwardpos : tfileposinfo;
  116. constructor create(const s:string;const pos : tfileposinfo);
  117. destructor destroy;override;
  118. function GetTypeName:string;override;
  119. end;
  120. tundefineddef = class(tstoreddef)
  121. constructor create;
  122. constructor ppuload(ppufile:tcompilerppufile);
  123. procedure ppuwrite(ppufile:tcompilerppufile);override;
  124. function GetTypeName:string;override;
  125. end;
  126. terrordef = class(tstoreddef)
  127. constructor create;
  128. procedure ppuwrite(ppufile:tcompilerppufile);override;
  129. function GetTypeName:string;override;
  130. function getmangledparaname : string;override;
  131. end;
  132. tabstractpointerdef = class(tstoreddef)
  133. pointeddef : tdef;
  134. pointeddefderef : tderef;
  135. constructor create(dt:tdeftyp;def:tdef);
  136. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  137. procedure ppuwrite(ppufile:tcompilerppufile);override;
  138. procedure buildderef;override;
  139. procedure deref;override;
  140. end;
  141. tpointerdef = class(tabstractpointerdef)
  142. is_far : boolean;
  143. constructor create(def:tdef);
  144. constructor createfar(def:tdef);
  145. function getcopy : tstoreddef;override;
  146. constructor ppuload(ppufile:tcompilerppufile);
  147. procedure ppuwrite(ppufile:tcompilerppufile);override;
  148. function GetTypeName:string;override;
  149. end;
  150. tabstractrecorddef= class(tstoreddef)
  151. symtable : TSymtable;
  152. cloneddef : tabstractrecorddef;
  153. cloneddefderef : tderef;
  154. procedure reset;override;
  155. function GetSymtable(t:tGetSymtable):TSymtable;override;
  156. function is_packed:boolean;
  157. end;
  158. trecorddef = class(tabstractrecorddef)
  159. public
  160. isunion : boolean;
  161. constructor create(p : TSymtable);
  162. constructor ppuload(ppufile:tcompilerppufile);
  163. destructor destroy;override;
  164. function getcopy : tstoreddef;override;
  165. procedure ppuwrite(ppufile:tcompilerppufile);override;
  166. procedure buildderef;override;
  167. procedure deref;override;
  168. function size:aint;override;
  169. function alignment : shortint;override;
  170. function padalignment: shortint;
  171. function GetTypeName:string;override;
  172. { debug }
  173. function needs_inittable : boolean;override;
  174. end;
  175. tprocdef = class;
  176. tobjectdef = class;
  177. { TImplementedInterface }
  178. TImplementedInterface = class
  179. IntfDef : tobjectdef;
  180. IntfDefDeref : tderef;
  181. IType : tinterfaceentrytype;
  182. IOffset : longint;
  183. VtblImplIntf : TImplementedInterface;
  184. NameMappings : TFPHashList;
  185. ProcDefs : TFPObjectList;
  186. ImplementsGetter : tsym;
  187. constructor create(aintf: tobjectdef);
  188. constructor create_deref(d:tderef);
  189. destructor destroy; override;
  190. function getcopy:TImplementedInterface;
  191. procedure buildderef;
  192. procedure deref;
  193. procedure AddMapping(const origname, newname: string);
  194. function GetMapping(const origname: string):string;
  195. procedure AddImplProc(pd:tprocdef);
  196. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  197. end;
  198. { tvmtentry }
  199. tvmtentry = record
  200. procdef : tprocdef;
  201. procdefderef : tderef;
  202. visibility : tvisibility;
  203. end;
  204. pvmtentry = ^tvmtentry;
  205. { tobjectdef }
  206. tvmcallstatic = (vmcs_default, vmcs_yes, vmcs_no, vmcs_unreachable);
  207. pmvcallstaticinfo = ^tmvcallstaticinfo;
  208. tmvcallstaticinfo = array[0..1024*1024-1] of tvmcallstatic;
  209. tobjectdef = class(tabstractrecorddef)
  210. private
  211. fcurrent_dispid: longint;
  212. public
  213. dwarf_struct_lab : tasmsymbol;
  214. childof : tobjectdef;
  215. childofderef : tderef;
  216. { for C++ classes: name of the library this class is imported from }
  217. import_lib,
  218. objname,
  219. objrealname,
  220. { for Objective-C: protocols and classes can have the same name there }
  221. objextname : pshortstring;
  222. objectoptions : tobjectoptions;
  223. { to be able to have a variable vmt position }
  224. { and no vmt field for objects without virtuals }
  225. vmtentries : TFPList;
  226. vmcallstaticinfo : pmvcallstaticinfo;
  227. vmt_offset : longint;
  228. objecttype : tobjecttyp;
  229. iidguid : pguid;
  230. iidstr : pshortstring;
  231. writing_class_record_dbginfo,
  232. { a class of this type has been created in this module }
  233. created_in_current_module,
  234. { a loadvmtnode for this class has been created in this
  235. module, so if a classrefdef variable of this or a parent
  236. class is used somewhere to instantiate a class, then this
  237. class may be instantiated
  238. }
  239. maybe_created_in_current_module,
  240. { a "class of" this particular class has been created in
  241. this module
  242. }
  243. classref_created_in_current_module : boolean;
  244. { store implemented interfaces defs and name mappings }
  245. ImplementedInterfaces : TFPObjectList;
  246. constructor create(ot : tobjecttyp;const n : string;c : tobjectdef);
  247. constructor ppuload(ppufile:tcompilerppufile);
  248. destructor destroy;override;
  249. function getcopy : tstoreddef;override;
  250. procedure ppuwrite(ppufile:tcompilerppufile);override;
  251. function GetTypeName:string;override;
  252. procedure buildderef;override;
  253. procedure deref;override;
  254. procedure buildderefimpl;override;
  255. procedure derefimpl;override;
  256. procedure resetvmtentries;
  257. procedure copyvmtentries(objdef:tobjectdef);
  258. function getparentdef:tdef;override;
  259. function size : aint;override;
  260. function alignment:shortint;override;
  261. function vmtmethodoffset(index:longint):longint;
  262. function members_need_inittable : boolean;
  263. function find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  264. { this should be called when this class implements an interface }
  265. procedure prepareguid;
  266. function is_publishable : boolean;override;
  267. function is_related(d : tdef) : boolean;override;
  268. function needs_inittable : boolean;override;
  269. function rtti_mangledname(rt:trttitype):string;override;
  270. function vmt_mangledname : string;
  271. procedure check_forwards;
  272. procedure insertvmt;
  273. procedure set_parent(c : tobjectdef);
  274. function find_procdef_bytype(pt:tproctypeoption): tprocdef;
  275. function find_destructor: tprocdef;
  276. function implements_any_interfaces: boolean;
  277. procedure reset; override;
  278. { dispinterface support }
  279. function get_next_dispid: longint;
  280. { enumerator support }
  281. function search_enumerator_get: tprocdef;
  282. function search_enumerator_move: tprocdef;
  283. function search_enumerator_current: tsym;
  284. { WPO }
  285. procedure register_created_object_type;override;
  286. procedure register_maybe_created_object_type;
  287. procedure register_created_classref_type;
  288. procedure register_vmt_call(index:longint);
  289. { ObjC & C++ }
  290. procedure make_all_methods_external;
  291. { ObjC }
  292. procedure finish_objc_data;
  293. function check_objc_types: boolean;
  294. { C++ }
  295. procedure finish_cpp_data;
  296. function RttiName: string;
  297. end;
  298. tclassrefdef = class(tabstractpointerdef)
  299. constructor create(def:tdef);
  300. constructor ppuload(ppufile:tcompilerppufile);
  301. procedure ppuwrite(ppufile:tcompilerppufile);override;
  302. function GetTypeName:string;override;
  303. function is_publishable : boolean;override;
  304. function rtti_mangledname(rt:trttitype):string;override;
  305. procedure register_created_object_type;override;
  306. procedure reset;override;
  307. end;
  308. tarraydef = class(tstoreddef)
  309. lowrange,
  310. highrange : aint;
  311. rangedef : tdef;
  312. rangedefderef : tderef;
  313. arrayoptions : tarraydefoptions;
  314. protected
  315. _elementdef : tdef;
  316. _elementdefderef : tderef;
  317. procedure setelementdef(def:tdef);
  318. public
  319. function elesize : aint;
  320. function elepackedbitsize : aint;
  321. function elecount : aword;
  322. constructor create_from_pointer(def:tdef);
  323. constructor create(l,h : aint;def:tdef);
  324. constructor ppuload(ppufile:tcompilerppufile);
  325. function getcopy : tstoreddef;override;
  326. procedure ppuwrite(ppufile:tcompilerppufile);override;
  327. function GetTypeName:string;override;
  328. function getmangledparaname : string;override;
  329. procedure buildderef;override;
  330. procedure deref;override;
  331. function size : aint;override;
  332. function alignment : shortint;override;
  333. { returns the label of the range check string }
  334. function needs_inittable : boolean;override;
  335. property elementdef : tdef read _elementdef write setelementdef;
  336. function is_publishable : boolean;override;
  337. end;
  338. torddef = class(tstoreddef)
  339. low,high : TConstExprInt;
  340. ordtype : tordtype;
  341. constructor create(t : tordtype;v,b : TConstExprInt);
  342. constructor ppuload(ppufile:tcompilerppufile);
  343. function getcopy : tstoreddef;override;
  344. procedure ppuwrite(ppufile:tcompilerppufile);override;
  345. function is_publishable : boolean;override;
  346. function GetTypeName:string;override;
  347. function alignment:shortint;override;
  348. procedure setsize;
  349. function packedbitsize: aint; override;
  350. function getvardef : longint;override;
  351. end;
  352. tfloatdef = class(tstoreddef)
  353. floattype : tfloattype;
  354. constructor create(t : tfloattype);
  355. constructor ppuload(ppufile:tcompilerppufile);
  356. function getcopy : tstoreddef;override;
  357. procedure ppuwrite(ppufile:tcompilerppufile);override;
  358. function GetTypeName:string;override;
  359. function is_publishable : boolean;override;
  360. function alignment:shortint;override;
  361. procedure setsize;
  362. function getvardef:longint;override;
  363. end;
  364. { tabstractprocdef }
  365. tabstractprocdef = class(tstoreddef)
  366. { saves a definition to the return type }
  367. returndef : tdef;
  368. returndefderef : tderef;
  369. parast : TSymtable;
  370. paras : tparalist;
  371. proctypeoption : tproctypeoption;
  372. proccalloption : tproccalloption;
  373. procoptions : tprocoptions;
  374. requiredargarea : aint;
  375. { number of user visibile parameters }
  376. maxparacount,
  377. minparacount : byte;
  378. {$ifdef m68k}
  379. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  380. {$endif}
  381. funcretloc : array[tcallercallee] of TCGPara;
  382. has_paraloc_info : boolean; { paraloc info is available }
  383. constructor create(dt:tdeftyp;level:byte);
  384. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  385. destructor destroy;override;
  386. procedure ppuwrite(ppufile:tcompilerppufile);override;
  387. procedure buildderef;override;
  388. procedure deref;override;
  389. procedure calcparas;
  390. function typename_paras(showhidden:boolean): string;
  391. function is_methodpointer:boolean;virtual;
  392. function is_addressonly:boolean;virtual;
  393. function no_self_node:boolean;
  394. private
  395. procedure count_para(p:TObject;arg:pointer);
  396. procedure insert_para(p:TObject;arg:pointer);
  397. end;
  398. tprocvardef = class(tabstractprocdef)
  399. constructor create(level:byte);
  400. constructor ppuload(ppufile:tcompilerppufile);
  401. function getcopy : tstoreddef;override;
  402. procedure ppuwrite(ppufile:tcompilerppufile);override;
  403. function GetSymtable(t:tGetSymtable):TSymtable;override;
  404. function size : aint;override;
  405. function GetTypeName:string;override;
  406. function is_publishable : boolean;override;
  407. function is_methodpointer:boolean;override;
  408. function is_addressonly:boolean;override;
  409. function getmangledparaname:string;override;
  410. end;
  411. tmessageinf = record
  412. case integer of
  413. 0 : (str : pshortstring);
  414. 1 : (i : longint);
  415. end;
  416. tinlininginfo = record
  417. { node tree }
  418. code : tnode;
  419. flags : tprocinfoflags;
  420. end;
  421. pinlininginfo = ^tinlininginfo;
  422. {$ifdef oldregvars}
  423. { register variables }
  424. pregvarinfo = ^tregvarinfo;
  425. tregvarinfo = record
  426. regvars : array[1..maxvarregs] of tsym;
  427. regvars_para : array[1..maxvarregs] of boolean;
  428. regvars_refs : array[1..maxvarregs] of longint;
  429. fpuregvars : array[1..maxfpuvarregs] of tsym;
  430. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  431. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  432. end;
  433. {$endif oldregvars}
  434. { tprocdef }
  435. tprocdef = class(tabstractprocdef)
  436. private
  437. _mangledname : pshortstring;
  438. public
  439. messageinf : tmessageinf;
  440. dispid : longint;
  441. {$ifndef EXTDEBUG}
  442. { where is this function defined and what were the symbol
  443. flags, needed here because there
  444. is only one symbol for all overloaded functions
  445. EXTDEBUG has fileinfo in tdef (PFV) }
  446. fileinfo : tfileposinfo;
  447. {$endif}
  448. symoptions : tsymoptions;
  449. deprecatedmsg : pshortstring;
  450. { symbol owning this definition }
  451. procsym : tsym;
  452. procsymderef : tderef;
  453. { alias names }
  454. aliasnames : TCmdStrList;
  455. { symtables }
  456. localst : TSymtable;
  457. funcretsym : tsym;
  458. funcretsymderef : tderef;
  459. _class : tobjectdef;
  460. _classderef : tderef;
  461. {$if defined(powerpc) or defined(m68k)}
  462. { library symbol for AmigaOS/MorphOS }
  463. libsym : tsym;
  464. libsymderef : tderef;
  465. {$endif powerpc or m68k}
  466. { name of the result variable to insert in the localsymtable }
  467. resultname : pshortstring;
  468. { import info }
  469. import_dll,
  470. import_name : pshortstring;
  471. { info for inlining the subroutine, if this pointer is nil,
  472. the procedure can't be inlined }
  473. inlininginfo : pinlininginfo;
  474. {$ifdef oldregvars}
  475. regvarinfo: pregvarinfo;
  476. {$endif oldregvars}
  477. { position in aasmoutput list }
  478. procstarttai,
  479. procendtai : tai;
  480. import_nr : word;
  481. extnumber : word;
  482. {$ifdef i386}
  483. fpu_used : byte;
  484. {$endif i386}
  485. visibility : tvisibility;
  486. { true, if the procedure is only declared
  487. (forward procedure) }
  488. forwarddef,
  489. { true if the procedure is declared in the interface }
  490. interfacedef : boolean;
  491. { true if the procedure has a forward declaration }
  492. hasforward : boolean;
  493. constructor create(level:byte);
  494. constructor ppuload(ppufile:tcompilerppufile);
  495. destructor destroy;override;
  496. procedure ppuwrite(ppufile:tcompilerppufile);override;
  497. procedure buildderef;override;
  498. procedure buildderefimpl;override;
  499. procedure deref;override;
  500. procedure derefimpl;override;
  501. procedure reset;override;
  502. function GetSymtable(t:tGetSymtable):TSymtable;override;
  503. function GetTypeName : string;override;
  504. function mangledname : string;
  505. procedure setmangledname(const s : string);
  506. function fullprocname(showhidden:boolean):string;
  507. function cplusplusmangledname : string;
  508. function objcmangledname : string;
  509. function is_methodpointer:boolean;override;
  510. function is_addressonly:boolean;override;
  511. end;
  512. { single linked list of overloaded procs }
  513. pprocdeflist = ^tprocdeflist;
  514. tprocdeflist = record
  515. def : tprocdef;
  516. defderef : tderef;
  517. next : pprocdeflist;
  518. end;
  519. tstringdef = class(tstoreddef)
  520. stringtype : tstringtype;
  521. len : aint;
  522. constructor createshort(l : byte);
  523. constructor loadshort(ppufile:tcompilerppufile);
  524. constructor createlong(l : aint);
  525. constructor loadlong(ppufile:tcompilerppufile);
  526. constructor createansi;
  527. constructor loadansi(ppufile:tcompilerppufile);
  528. constructor createwide;
  529. constructor loadwide(ppufile:tcompilerppufile);
  530. constructor createunicode;
  531. constructor loadunicode(ppufile:tcompilerppufile);
  532. function getcopy : tstoreddef;override;
  533. function stringtypname:string;
  534. procedure ppuwrite(ppufile:tcompilerppufile);override;
  535. function GetTypeName:string;override;
  536. function getmangledparaname:string;override;
  537. function is_publishable : boolean;override;
  538. function alignment : shortint;override;
  539. function needs_inittable : boolean;override;
  540. function getvardef:longint;override;
  541. end;
  542. { tenumdef }
  543. tenumdef = class(tstoreddef)
  544. minval,
  545. maxval : aint;
  546. has_jumps : boolean;
  547. basedef : tenumdef;
  548. basedefderef : tderef;
  549. symtable : TSymtable;
  550. constructor create;
  551. constructor create_subrange(_basedef:tenumdef;_min,_max:aint);
  552. constructor ppuload(ppufile:tcompilerppufile);
  553. destructor destroy;override;
  554. function getcopy : tstoreddef;override;
  555. procedure ppuwrite(ppufile:tcompilerppufile);override;
  556. procedure buildderef;override;
  557. procedure deref;override;
  558. function GetTypeName:string;override;
  559. function is_publishable : boolean;override;
  560. procedure calcsavesize;
  561. function packedbitsize: aint; override;
  562. procedure setmax(_max:aint);
  563. procedure setmin(_min:aint);
  564. function min:aint;
  565. function max:aint;
  566. function getfirstsym:tsym;
  567. end;
  568. tsetdef = class(tstoreddef)
  569. elementdef : tdef;
  570. elementdefderef : tderef;
  571. setbase,
  572. setmax : aword;
  573. constructor create(def:tdef;low, high : aint);
  574. constructor ppuload(ppufile:tcompilerppufile);
  575. function getcopy : tstoreddef;override;
  576. procedure ppuwrite(ppufile:tcompilerppufile);override;
  577. procedure buildderef;override;
  578. procedure deref;override;
  579. function GetTypeName:string;override;
  580. function is_publishable : boolean;override;
  581. end;
  582. var
  583. current_objectdef : tobjectdef; { used for private functions check !! }
  584. { default types }
  585. generrordef, { error in definition }
  586. voidpointertype, { pointer for Void-pointeddef }
  587. charpointertype, { pointer for Char-pointeddef }
  588. widecharpointertype, { pointer for WideChar-pointeddef }
  589. voidfarpointertype,
  590. cundefinedtype,
  591. cformaltype, { unique formal definition }
  592. ctypedformaltype, { unique typed formal definition }
  593. voidtype, { Void (procedure) }
  594. cchartype, { Char }
  595. cwidechartype, { WideChar }
  596. booltype, { boolean type }
  597. bool8type,
  598. bool16type,
  599. bool32type,
  600. bool64type, { implement me }
  601. u8inttype, { 8-Bit unsigned integer }
  602. s8inttype, { 8-Bit signed integer }
  603. u16inttype, { 16-Bit unsigned integer }
  604. s16inttype, { 16-Bit signed integer }
  605. u32inttype, { 32-Bit unsigned integer }
  606. s32inttype, { 32-Bit signed integer }
  607. u64inttype, { 64-bit unsigned integer }
  608. s64inttype, { 64-bit signed integer }
  609. s32floattype, { 32 bit floating point number }
  610. s64floattype, { 64 bit floating point number }
  611. s80floattype, { 80 bit floating point number }
  612. sc80floattype, { 80 bit floating point number but stored like in C }
  613. s64currencytype, { pointer to a currency type }
  614. cshortstringtype, { pointer to type of short string const }
  615. clongstringtype, { pointer to type of long string const }
  616. cansistringtype, { pointer to type of ansi string const }
  617. cwidestringtype, { pointer to type of wide string const }
  618. cunicodestringtype,
  619. openshortstringtype, { pointer to type of an open shortstring,
  620. needed for readln() }
  621. openchararraytype, { pointer to type of an open array of char,
  622. needed for readln() }
  623. cfiletype, { get the same definition for all file }
  624. { used for stabs }
  625. methodpointertype, { typecasting of methodpointers to extract self }
  626. hresultdef,
  627. { we use only one variant def for every variant class }
  628. cvarianttype,
  629. colevarianttype,
  630. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  631. sinttype,
  632. uinttype,
  633. { unsigned and signed ord type with the same size as a pointer }
  634. ptruinttype,
  635. ptrsinttype,
  636. { several types to simulate more or less C++ objects for GDB }
  637. vmttype,
  638. vmtarraytype,
  639. pvmttype : tdef; { type of classrefs, used for stabs }
  640. { pointer to the anchestor of all classes }
  641. class_tobject : tobjectdef;
  642. { pointer to the ancestor of all COM interfaces }
  643. interface_iunknown : tobjectdef;
  644. { pointer to the TGUID type
  645. of all interfaces }
  646. rec_tguid : trecorddef;
  647. { Objective-C base types }
  648. objc_metaclasstype,
  649. objc_superclasstype,
  650. objc_idtype,
  651. objc_seltype : tpointerdef;
  652. objc_objecttype : trecorddef;
  653. { base type of @protocol(protocolname) Objective-C statements }
  654. objc_protocoltype : tobjectdef;
  655. const
  656. {$ifdef i386}
  657. pbestrealtype : ^tdef = @s80floattype;
  658. {$endif}
  659. {$ifdef x86_64}
  660. pbestrealtype : ^tdef = @s80floattype;
  661. {$endif}
  662. {$ifdef m68k}
  663. pbestrealtype : ^tdef = @s64floattype;
  664. {$endif}
  665. {$ifdef alpha}
  666. pbestrealtype : ^tdef = @s64floattype;
  667. {$endif}
  668. {$ifdef powerpc}
  669. pbestrealtype : ^tdef = @s64floattype;
  670. {$endif}
  671. {$ifdef POWERPC64}
  672. pbestrealtype : ^tdef = @s64floattype;
  673. {$endif}
  674. {$ifdef ia64}
  675. pbestrealtype : ^tdef = @s64floattype;
  676. {$endif}
  677. {$ifdef SPARC}
  678. pbestrealtype : ^tdef = @s64floattype;
  679. {$endif SPARC}
  680. {$ifdef vis}
  681. pbestrealtype : ^tdef = @s64floattype;
  682. {$endif vis}
  683. {$ifdef ARM}
  684. pbestrealtype : ^tdef = @s64floattype;
  685. {$endif ARM}
  686. {$ifdef MIPS}
  687. pbestrealtype : ^tdef = @s64floattype;
  688. {$endif MIPS}
  689. {$ifdef AVR}
  690. pbestrealtype : ^tdef = @s64floattype;
  691. {$endif AVR}
  692. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  693. { should be in the types unit, but the types unit uses the node stuff :( }
  694. function is_interfacecom(def: tdef): boolean;
  695. function is_interfacecorba(def: tdef): boolean;
  696. function is_interface(def: tdef): boolean;
  697. function is_dispinterface(def: tdef): boolean;
  698. function is_object(def: tdef): boolean;
  699. function is_class(def: tdef): boolean;
  700. function is_cppclass(def: tdef): boolean;
  701. function is_objcclass(def: tdef): boolean;
  702. function is_objcclassref(def: tdef): boolean;
  703. function is_objcprotocol(def: tdef): boolean;
  704. function is_objccategory(def: tdef): boolean;
  705. function is_objc_class_or_protocol(def: tdef): boolean;
  706. function is_objc_protocol_or_category(def: tdef): boolean;
  707. function is_class_or_interface(def: tdef): boolean;
  708. function is_class_or_interface_or_objc(def: tdef): boolean;
  709. function is_class_or_interface_or_object(def: tdef): boolean;
  710. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  711. function is_class_or_interface_or_dispinterface_or_objc(def: tdef): boolean;
  712. function is_class_or_object(def: tdef): boolean;
  713. procedure loadobjctypes;
  714. function use_vectorfpu(def : tdef) : boolean;
  715. implementation
  716. uses
  717. SysUtils,
  718. cutils,
  719. { global }
  720. verbose,
  721. { target }
  722. systems,aasmcpu,paramgr,
  723. { symtable }
  724. symsym,symtable,symutil,defutil,objcdef,
  725. { module }
  726. fmodule,
  727. { other }
  728. gendef,
  729. fpccrc
  730. ;
  731. {****************************************************************************
  732. Constants
  733. ****************************************************************************}
  734. const
  735. varempty = 0;
  736. varnull = 1;
  737. varsmallint = 2;
  738. varinteger = 3;
  739. varsingle = 4;
  740. vardouble = 5;
  741. varcurrency = 6;
  742. vardate = 7;
  743. varolestr = 8;
  744. vardispatch = 9;
  745. varerror = 10;
  746. varboolean = 11;
  747. varvariant = 12;
  748. varunknown = 13;
  749. vardecimal = 14;
  750. varshortint = 16;
  751. varbyte = 17;
  752. varword = 18;
  753. varlongword = 19;
  754. varint64 = 20;
  755. varqword = 21;
  756. varunicodestr = 22;
  757. varUndefined = -1;
  758. varstrarg = $48;
  759. varstring = $100;
  760. varany = $101;
  761. vardefmask = $fff;
  762. vararray = $2000;
  763. varbyref = $4000;
  764. {****************************************************************************
  765. Helpers
  766. ****************************************************************************}
  767. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  768. var
  769. s,hs,
  770. prefix : string;
  771. oldlen,
  772. newlen,
  773. i : longint;
  774. crc : dword;
  775. hp : tparavarsym;
  776. begin
  777. prefix:='';
  778. if not assigned(st) then
  779. internalerror(200204212);
  780. { sub procedures }
  781. while (st.symtabletype=localsymtable) do
  782. begin
  783. if st.defowner.typ<>procdef then
  784. internalerror(200204173);
  785. { Add the full mangledname of procedure to prevent
  786. conflicts with 2 overloads having both a nested procedure
  787. with the same name, see tb0314 (PFV) }
  788. s:=tprocdef(st.defowner).procsym.name;
  789. oldlen:=length(s);
  790. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  791. begin
  792. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  793. if not(vo_is_hidden_para in hp.varoptions) then
  794. s:=s+'$'+hp.vardef.mangledparaname;
  795. end;
  796. if not is_void(tprocdef(st.defowner).returndef) then
  797. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  798. newlen:=length(s);
  799. { Replace with CRC if the parameter line is very long }
  800. if (newlen-oldlen>12) and
  801. ((newlen+length(prefix)>100) or (newlen-oldlen>32)) then
  802. begin
  803. crc:=0;
  804. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  805. begin
  806. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  807. if not(vo_is_hidden_para in hp.varoptions) then
  808. begin
  809. hs:=hp.vardef.mangledparaname;
  810. crc:=UpdateCrc32(crc,hs[1],length(hs));
  811. end;
  812. end;
  813. hs:=hp.vardef.mangledparaname;
  814. crc:=UpdateCrc32(crc,hs[1],length(hs));
  815. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  816. end;
  817. if prefix<>'' then
  818. prefix:=s+'_'+prefix
  819. else
  820. prefix:=s;
  821. if length(prefix)>100 then
  822. begin
  823. crc:=0;
  824. crc:=UpdateCrc32(crc,prefix[1],length(prefix));
  825. prefix:='$CRC'+hexstr(crc,8);
  826. end;
  827. st:=st.defowner.owner;
  828. end;
  829. { object/classes symtable, nested type definitions in classes require the while loop }
  830. while st.symtabletype=ObjectSymtable do
  831. begin
  832. if st.defowner.typ<>objectdef then
  833. internalerror(200204174);
  834. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  835. st:=st.defowner.owner;
  836. end;
  837. { symtable must now be static or global }
  838. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  839. internalerror(200204175);
  840. result:='';
  841. if typeprefix<>'' then
  842. result:=result+typeprefix+'_';
  843. { Add P$ for program, which can have the same name as
  844. a unit }
  845. if (TSymtable(main_module.localsymtable)=st) and
  846. (not main_module.is_unit) then
  847. result:=result+'P$'+st.name^
  848. else
  849. result:=result+st.name^;
  850. if prefix<>'' then
  851. result:=result+'_'+prefix;
  852. if suffix<>'' then
  853. result:=result+'_'+suffix;
  854. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  855. { Further, the Mac OS X 10.5 linker does not consider symbols which do not }
  856. { start with '_' as regular symbols (it does not generate N_GSYM entries }
  857. { those in the debug map, leading to troubles with dsymutil). So always }
  858. { add an underscore on darwin. }
  859. if (target_info.system in systems_darwin) then
  860. result := '_' + result;
  861. end;
  862. {****************************************************************************
  863. TDEF (base class for definitions)
  864. ****************************************************************************}
  865. constructor tstoreddef.create(dt:tdeftyp);
  866. var
  867. insertstack : psymtablestackitem;
  868. begin
  869. inherited create(dt);
  870. savesize := 0;
  871. {$ifdef EXTDEBUG}
  872. fileinfo := current_filepos;
  873. {$endif}
  874. generictokenbuf:=nil;
  875. genericdef:=nil;
  876. { Don't register forwarddefs, they are disposed at the
  877. end of an type block }
  878. if (dt=forwarddef) then
  879. exit;
  880. { Register in current_module }
  881. if assigned(current_module) then
  882. begin
  883. current_module.deflist.Add(self);
  884. DefId:=current_module.deflist.Count-1;
  885. end;
  886. { Register in symtable stack }
  887. if assigned(symtablestack) then
  888. begin
  889. insertstack:=symtablestack.stack;
  890. while assigned(insertstack) and
  891. (insertstack^.symtable.symtabletype=withsymtable) do
  892. insertstack:=insertstack^.next;
  893. if not assigned(insertstack) then
  894. internalerror(200602044);
  895. insertstack^.symtable.insertdef(self);
  896. end;
  897. end;
  898. destructor tstoreddef.destroy;
  899. begin
  900. { Direct calls are not allowed, use symtable.deletedef() }
  901. if assigned(owner) then
  902. internalerror(200612311);
  903. if assigned(generictokenbuf) then
  904. begin
  905. generictokenbuf.free;
  906. generictokenbuf:=nil;
  907. end;
  908. inherited destroy;
  909. end;
  910. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  911. var
  912. sizeleft,i : longint;
  913. buf : array[0..255] of byte;
  914. begin
  915. inherited create(dt);
  916. DefId:=ppufile.getlongint;
  917. current_module.deflist[DefId]:=self;
  918. {$ifdef EXTDEBUG}
  919. fillchar(fileinfo,sizeof(fileinfo),0);
  920. {$endif}
  921. { load }
  922. ppufile.getderef(typesymderef);
  923. ppufile.getsmallset(defoptions);
  924. ppufile.getsmallset(defstates);
  925. if df_generic in defoptions then
  926. begin
  927. sizeleft:=ppufile.getlongint;
  928. initgeneric;
  929. while sizeleft>0 do
  930. begin
  931. if sizeleft>sizeof(buf) then
  932. i:=sizeof(buf)
  933. else
  934. i:=sizeleft;
  935. ppufile.getdata(buf,i);
  936. generictokenbuf.write(buf,i);
  937. dec(sizeleft,i);
  938. end;
  939. end;
  940. if df_specialization in defoptions then
  941. ppufile.getderef(genericdefderef);
  942. end;
  943. function Tstoreddef.rtti_mangledname(rt:trttitype):string;
  944. var
  945. prefix : string[4];
  946. begin
  947. if rt=fullrtti then
  948. begin
  949. prefix:='RTTI';
  950. include(defstates,ds_rtti_table_used);
  951. end
  952. else
  953. begin
  954. prefix:='INIT';
  955. include(defstates,ds_init_table_used);
  956. end;
  957. if assigned(typesym) and
  958. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  959. result:=make_mangledname(prefix,owner,typesym.name)
  960. else
  961. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  962. end;
  963. procedure Tstoreddef.reset;
  964. begin
  965. end;
  966. function tstoreddef.getcopy : tstoreddef;
  967. begin
  968. Message(sym_e_cant_create_unique_type);
  969. getcopy:=terrordef.create;
  970. end;
  971. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  972. var
  973. sizeleft,i : longint;
  974. buf : array[0..255] of byte;
  975. oldintfcrc : boolean;
  976. begin
  977. ppufile.putlongint(DefId);
  978. ppufile.putderef(typesymderef);
  979. ppufile.putsmallset(defoptions);
  980. oldintfcrc:=ppufile.do_crc;
  981. ppufile.do_crc:=false;
  982. ppufile.putsmallset(defstates);
  983. if df_generic in defoptions then
  984. begin
  985. if assigned(generictokenbuf) then
  986. begin
  987. sizeleft:=generictokenbuf.size;
  988. generictokenbuf.seek(0);
  989. end
  990. else
  991. sizeleft:=0;
  992. ppufile.putlongint(sizeleft);
  993. while sizeleft>0 do
  994. begin
  995. if sizeleft>sizeof(buf) then
  996. i:=sizeof(buf)
  997. else
  998. i:=sizeleft;
  999. generictokenbuf.read(buf,i);
  1000. ppufile.putdata(buf,i);
  1001. dec(sizeleft,i);
  1002. end;
  1003. end;
  1004. ppufile.do_crc:=oldintfcrc;
  1005. if df_specialization in defoptions then
  1006. ppufile.putderef(genericdefderef);
  1007. end;
  1008. procedure tstoreddef.buildderef;
  1009. begin
  1010. typesymderef.build(typesym);
  1011. genericdefderef.build(genericdef);
  1012. end;
  1013. procedure tstoreddef.buildderefimpl;
  1014. begin
  1015. end;
  1016. procedure tstoreddef.deref;
  1017. begin
  1018. typesym:=ttypesym(typesymderef.resolve);
  1019. if df_specialization in defoptions then
  1020. genericdef:=tstoreddef(genericdefderef.resolve);
  1021. end;
  1022. procedure tstoreddef.derefimpl;
  1023. begin
  1024. end;
  1025. function tstoreddef.size : aint;
  1026. begin
  1027. size:=savesize;
  1028. end;
  1029. function tstoreddef.getvardef:longint;
  1030. begin
  1031. result:=varUndefined;
  1032. end;
  1033. function tstoreddef.alignment : shortint;
  1034. begin
  1035. { natural alignment by default }
  1036. alignment:=size_2_align(savesize);
  1037. { can happen if savesize = 0, e.g. for voiddef or
  1038. an empty record
  1039. }
  1040. if (alignment=0) then
  1041. alignment:=1;
  1042. end;
  1043. { returns true, if the definition can be published }
  1044. function tstoreddef.is_publishable : boolean;
  1045. begin
  1046. is_publishable:=false;
  1047. end;
  1048. { needs an init table }
  1049. function tstoreddef.needs_inittable : boolean;
  1050. begin
  1051. needs_inittable:=false;
  1052. end;
  1053. function tstoreddef.is_intregable : boolean;
  1054. var
  1055. recsize,temp: longint;
  1056. begin
  1057. is_intregable:=false;
  1058. case typ of
  1059. orddef,
  1060. pointerdef,
  1061. enumdef,
  1062. classrefdef:
  1063. is_intregable:=true;
  1064. procvardef :
  1065. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  1066. objectdef:
  1067. is_intregable:=(is_class_or_interface_or_dispinterface_or_objc(self)) and not needs_inittable;
  1068. setdef:
  1069. is_intregable:=is_smallset(self);
  1070. recorddef:
  1071. begin
  1072. recsize:=size;
  1073. is_intregable:=
  1074. ispowerof2(recsize,temp) and
  1075. (recsize <= sizeof(aint));
  1076. end;
  1077. end;
  1078. end;
  1079. function tstoreddef.is_fpuregable : boolean;
  1080. begin
  1081. {$ifdef x86}
  1082. result:=use_vectorfpu(self);
  1083. {$else x86}
  1084. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  1085. {$endif x86}
  1086. end;
  1087. procedure tstoreddef.initgeneric;
  1088. begin
  1089. if assigned(generictokenbuf) then
  1090. internalerror(200512131);
  1091. generictokenbuf:=tdynamicarray.create(256);
  1092. end;
  1093. {****************************************************************************
  1094. Tstringdef
  1095. ****************************************************************************}
  1096. constructor tstringdef.createshort(l : byte);
  1097. begin
  1098. inherited create(stringdef);
  1099. stringtype:=st_shortstring;
  1100. len:=l;
  1101. savesize:=len+1;
  1102. end;
  1103. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  1104. begin
  1105. inherited ppuload(stringdef,ppufile);
  1106. stringtype:=st_shortstring;
  1107. len:=ppufile.getbyte;
  1108. savesize:=len+1;
  1109. end;
  1110. constructor tstringdef.createlong(l : aint);
  1111. begin
  1112. inherited create(stringdef);
  1113. stringtype:=st_longstring;
  1114. len:=l;
  1115. savesize:=sizeof(pint);
  1116. end;
  1117. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1118. begin
  1119. inherited ppuload(stringdef,ppufile);
  1120. stringtype:=st_longstring;
  1121. len:=ppufile.getaint;
  1122. savesize:=sizeof(pint);
  1123. end;
  1124. constructor tstringdef.createansi;
  1125. begin
  1126. inherited create(stringdef);
  1127. stringtype:=st_ansistring;
  1128. len:=-1;
  1129. savesize:=sizeof(pint);
  1130. end;
  1131. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1132. begin
  1133. inherited ppuload(stringdef,ppufile);
  1134. stringtype:=st_ansistring;
  1135. len:=ppufile.getaint;
  1136. savesize:=sizeof(pint);
  1137. end;
  1138. constructor tstringdef.createwide;
  1139. begin
  1140. inherited create(stringdef);
  1141. stringtype:=st_widestring;
  1142. len:=-1;
  1143. savesize:=sizeof(pint);
  1144. end;
  1145. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1146. begin
  1147. inherited ppuload(stringdef,ppufile);
  1148. stringtype:=st_widestring;
  1149. len:=ppufile.getaint;
  1150. savesize:=sizeof(pint);
  1151. end;
  1152. constructor tstringdef.createunicode;
  1153. begin
  1154. inherited create(stringdef);
  1155. stringtype:=st_unicodestring;
  1156. len:=-1;
  1157. savesize:=sizeof(pint);
  1158. end;
  1159. constructor tstringdef.loadunicode(ppufile:tcompilerppufile);
  1160. begin
  1161. inherited ppuload(stringdef,ppufile);
  1162. stringtype:=st_unicodestring;
  1163. len:=ppufile.getaint;
  1164. savesize:=sizeof(pint);
  1165. end;
  1166. function tstringdef.getcopy : tstoreddef;
  1167. begin
  1168. result:=tstringdef.create(typ);
  1169. result.typ:=stringdef;
  1170. tstringdef(result).stringtype:=stringtype;
  1171. tstringdef(result).len:=len;
  1172. tstringdef(result).savesize:=savesize;
  1173. end;
  1174. function tstringdef.stringtypname:string;
  1175. const
  1176. typname:array[tstringtype] of string[10]=(
  1177. 'shortstr','longstr','ansistr','widestr','unicodestr'
  1178. );
  1179. begin
  1180. stringtypname:=typname[stringtype];
  1181. end;
  1182. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1183. begin
  1184. inherited ppuwrite(ppufile);
  1185. if stringtype=st_shortstring then
  1186. begin
  1187. {$ifdef extdebug}
  1188. if len > 255 then internalerror(12122002);
  1189. {$endif}
  1190. ppufile.putbyte(byte(len))
  1191. end
  1192. else
  1193. ppufile.putaint(len);
  1194. case stringtype of
  1195. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1196. st_longstring : ppufile.writeentry(iblongstringdef);
  1197. st_ansistring : ppufile.writeentry(ibansistringdef);
  1198. st_widestring : ppufile.writeentry(ibwidestringdef);
  1199. st_unicodestring : ppufile.writeentry(ibunicodestringdef);
  1200. end;
  1201. end;
  1202. function tstringdef.needs_inittable : boolean;
  1203. begin
  1204. needs_inittable:=stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1205. end;
  1206. function tstringdef.GetTypeName : string;
  1207. const
  1208. names : array[tstringtype] of string[15] = (
  1209. 'ShortString','LongString','AnsiString','WideString','UnicodeString');
  1210. begin
  1211. GetTypeName:=names[stringtype];
  1212. end;
  1213. function tstringdef.getvardef : longint;
  1214. const
  1215. vardef : array[tstringtype] of longint = (
  1216. varUndefined,varUndefined,varString,varOleStr,varUnicodeStr);
  1217. begin
  1218. result:=vardef[stringtype];
  1219. end;
  1220. function tstringdef.alignment : shortint;
  1221. begin
  1222. case stringtype of
  1223. st_unicodestring,
  1224. st_widestring,
  1225. st_ansistring:
  1226. alignment:=size_2_align(savesize);
  1227. st_longstring,
  1228. st_shortstring:
  1229. { char to string accesses byte 0 and 1 with one word access }
  1230. if (tf_requires_proper_alignment in target_info.flags) or
  1231. { macpas needs an alignment of 2 (MetroWerks compatible) }
  1232. (m_mac in current_settings.modeswitches) then
  1233. alignment:=size_2_align(2)
  1234. else
  1235. alignment:=size_2_align(1);
  1236. else
  1237. internalerror(200412301);
  1238. end;
  1239. end;
  1240. function tstringdef.getmangledparaname : string;
  1241. begin
  1242. getmangledparaname:='STRING';
  1243. end;
  1244. function tstringdef.is_publishable : boolean;
  1245. begin
  1246. is_publishable:=true;
  1247. end;
  1248. {****************************************************************************
  1249. TENUMDEF
  1250. ****************************************************************************}
  1251. constructor tenumdef.create;
  1252. begin
  1253. inherited create(enumdef);
  1254. minval:=0;
  1255. maxval:=0;
  1256. calcsavesize;
  1257. has_jumps:=false;
  1258. basedef:=nil;
  1259. symtable:=tenumsymtable.create(self);
  1260. end;
  1261. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1262. begin
  1263. inherited create(enumdef);
  1264. minval:=_min;
  1265. maxval:=_max;
  1266. basedef:=_basedef;
  1267. calcsavesize;
  1268. has_jumps:=false;
  1269. symtable:=basedef.symtable.getcopy;
  1270. include(defoptions, df_copied_def);
  1271. end;
  1272. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1273. begin
  1274. inherited ppuload(enumdef,ppufile);
  1275. minval:=ppufile.getaint;
  1276. maxval:=ppufile.getaint;
  1277. savesize:=ppufile.getaint;
  1278. has_jumps:=false;
  1279. if df_copied_def in defoptions then
  1280. begin
  1281. symtable:=nil;
  1282. ppufile.getderef(basedefderef);
  1283. end
  1284. else
  1285. begin
  1286. // create with nil defowner first to prevent values changes on insert
  1287. symtable:=tenumsymtable.create(nil);
  1288. tenumsymtable(symtable).ppuload(ppufile);
  1289. symtable.defowner:=self;
  1290. end;
  1291. end;
  1292. destructor tenumdef.destroy;
  1293. begin
  1294. symtable.free;
  1295. symtable:=nil;
  1296. inherited destroy;
  1297. end;
  1298. function tenumdef.getcopy : tstoreddef;
  1299. begin
  1300. if assigned(basedef) then
  1301. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1302. else
  1303. begin
  1304. result:=tenumdef.create;
  1305. tenumdef(result).minval:=minval;
  1306. tenumdef(result).maxval:=maxval;
  1307. tenumdef(result).symtable.free;
  1308. tenumdef(result).symtable:=symtable.getcopy;
  1309. tenumdef(result).basedef:=self;
  1310. end;
  1311. tenumdef(result).has_jumps:=has_jumps;
  1312. tenumdef(result).basedefderef:=basedefderef;
  1313. include(tenumdef(result).defoptions,df_copied_def);
  1314. end;
  1315. procedure tenumdef.calcsavesize;
  1316. begin
  1317. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1318. savesize:=8
  1319. else
  1320. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  1321. savesize:=4
  1322. else
  1323. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1324. savesize:=2
  1325. else
  1326. savesize:=1;
  1327. end;
  1328. function tenumdef.packedbitsize: aint;
  1329. var
  1330. sizeval: tconstexprint;
  1331. power: longint;
  1332. begin
  1333. result := 0;
  1334. if (minval >= 0) and
  1335. (maxval <= 1) then
  1336. result := 1
  1337. else
  1338. begin
  1339. if (minval>=0) then
  1340. sizeval:=maxval
  1341. else
  1342. { don't count 0 twice }
  1343. sizeval:=(cutils.max(-minval,maxval)*2)-1;
  1344. { 256 must become 512 etc. }
  1345. nextpowerof2(sizeval+1,power);
  1346. result := power;
  1347. end;
  1348. end;
  1349. procedure tenumdef.setmax(_max:aint);
  1350. begin
  1351. maxval:=_max;
  1352. calcsavesize;
  1353. end;
  1354. procedure tenumdef.setmin(_min:aint);
  1355. begin
  1356. minval:=_min;
  1357. calcsavesize;
  1358. end;
  1359. function tenumdef.min:aint;
  1360. begin
  1361. min:=minval;
  1362. end;
  1363. function tenumdef.max:aint;
  1364. begin
  1365. max:=maxval;
  1366. end;
  1367. function tenumdef.getfirstsym: tsym;
  1368. var
  1369. i:integer;
  1370. begin
  1371. for i := 0 to symtable.SymList.Count - 1 do
  1372. begin
  1373. result:=tsym(symtable.SymList[i]);
  1374. if tenumsym(result).value=minval then
  1375. exit;
  1376. end;
  1377. result:=nil;
  1378. end;
  1379. procedure tenumdef.buildderef;
  1380. begin
  1381. inherited buildderef;
  1382. if df_copied_def in defoptions then
  1383. basedefderef.build(basedef)
  1384. else
  1385. tenumsymtable(symtable).buildderef;
  1386. end;
  1387. procedure tenumdef.deref;
  1388. begin
  1389. inherited deref;
  1390. if df_copied_def in defoptions then
  1391. begin
  1392. basedef:=tenumdef(basedefderef.resolve);
  1393. symtable:=basedef.symtable.getcopy;
  1394. end
  1395. else
  1396. tenumsymtable(symtable).deref;
  1397. end;
  1398. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1399. begin
  1400. inherited ppuwrite(ppufile);
  1401. ppufile.putaint(min);
  1402. ppufile.putaint(max);
  1403. ppufile.putaint(savesize);
  1404. if df_copied_def in defoptions then
  1405. ppufile.putderef(basedefderef);
  1406. ppufile.writeentry(ibenumdef);
  1407. if not (df_copied_def in defoptions) then
  1408. tenumsymtable(symtable).ppuwrite(ppufile);
  1409. end;
  1410. function tenumdef.is_publishable : boolean;
  1411. begin
  1412. is_publishable:=true;
  1413. end;
  1414. function tenumdef.GetTypeName : string;
  1415. begin
  1416. GetTypeName:='<enumeration type>';
  1417. end;
  1418. {****************************************************************************
  1419. TORDDEF
  1420. ****************************************************************************}
  1421. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  1422. begin
  1423. inherited create(orddef);
  1424. low:=v;
  1425. high:=b;
  1426. ordtype:=t;
  1427. setsize;
  1428. end;
  1429. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1430. begin
  1431. inherited ppuload(orddef,ppufile);
  1432. ordtype:=tordtype(ppufile.getbyte);
  1433. low:=ppufile.getexprint;
  1434. high:=ppufile.getexprint;
  1435. setsize;
  1436. end;
  1437. function torddef.getcopy : tstoreddef;
  1438. begin
  1439. result:=torddef.create(ordtype,low,high);
  1440. result.typ:=orddef;
  1441. torddef(result).low:=low;
  1442. torddef(result).high:=high;
  1443. torddef(result).ordtype:=ordtype;
  1444. torddef(result).savesize:=savesize;
  1445. end;
  1446. function torddef.alignment:shortint;
  1447. begin
  1448. if (target_info.system in [system_i386_darwin,system_arm_darwin]) and
  1449. (ordtype in [s64bit,u64bit]) then
  1450. result := 4
  1451. else
  1452. result := inherited alignment;
  1453. end;
  1454. procedure torddef.setsize;
  1455. const
  1456. sizetbl : array[tordtype] of longint = (
  1457. 0,
  1458. 1,2,4,8,
  1459. 1,2,4,8,
  1460. 1,1,2,4,8,
  1461. 1,2,8
  1462. );
  1463. begin
  1464. savesize:=sizetbl[ordtype];
  1465. end;
  1466. function torddef.packedbitsize: aint;
  1467. var
  1468. sizeval: tconstexprint;
  1469. power: longint;
  1470. begin
  1471. result := 0;
  1472. if ordtype = uvoid then
  1473. exit;
  1474. {$ifndef cpu64bitalu}
  1475. if (ordtype in [s64bit,u64bit]) then
  1476. {$else not cpu64bitalu}
  1477. if (ordtype = u64bit) or
  1478. ((ordtype = s64bit) and
  1479. ((low <= (system.low(int64) div 2)) or
  1480. (high > (system.high(int64) div 2)))) then
  1481. {$endif cpu64bitalu}
  1482. result := 64
  1483. else if (low >= 0) and
  1484. (high <= 1) then
  1485. result := 1
  1486. else
  1487. begin
  1488. if (low>=0) then
  1489. sizeval:=high
  1490. else
  1491. { don't count 0 twice }
  1492. sizeval:=(cutils.max(-low,high)*2)-1;
  1493. { 256 must become 512 etc. }
  1494. nextpowerof2(sizeval+1,power);
  1495. result := power;
  1496. end;
  1497. end;
  1498. function torddef.getvardef : longint;
  1499. const
  1500. basetype2vardef : array[tordtype] of longint = (
  1501. varUndefined,
  1502. varbyte,varqword,varlongword,varqword,
  1503. varshortint,varsmallint,varinteger,varint64,
  1504. varboolean,varboolean,varboolean,varUndefined,varUndefined,
  1505. varUndefined,varUndefined,varCurrency);
  1506. begin
  1507. result:=basetype2vardef[ordtype];
  1508. end;
  1509. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1510. begin
  1511. inherited ppuwrite(ppufile);
  1512. ppufile.putbyte(byte(ordtype));
  1513. ppufile.putexprint(low);
  1514. ppufile.putexprint(high);
  1515. ppufile.writeentry(iborddef);
  1516. end;
  1517. function torddef.is_publishable : boolean;
  1518. begin
  1519. is_publishable:=(ordtype<>uvoid);
  1520. end;
  1521. function torddef.GetTypeName : string;
  1522. const
  1523. names : array[tordtype] of string[20] = (
  1524. 'untyped',
  1525. 'Byte','Word','DWord','QWord',
  1526. 'ShortInt','SmallInt','LongInt','Int64',
  1527. 'Boolean','ByteBool','WordBool','LongBool','QWordBool',
  1528. 'Char','WideChar','Currency');
  1529. begin
  1530. GetTypeName:=names[ordtype];
  1531. end;
  1532. {****************************************************************************
  1533. TFLOATDEF
  1534. ****************************************************************************}
  1535. constructor tfloatdef.create(t : tfloattype);
  1536. begin
  1537. inherited create(floatdef);
  1538. floattype:=t;
  1539. setsize;
  1540. end;
  1541. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1542. begin
  1543. inherited ppuload(floatdef,ppufile);
  1544. floattype:=tfloattype(ppufile.getbyte);
  1545. setsize;
  1546. end;
  1547. function tfloatdef.getcopy : tstoreddef;
  1548. begin
  1549. result:=tfloatdef.create(floattype);
  1550. result.typ:=floatdef;
  1551. tfloatdef(result).savesize:=savesize;
  1552. end;
  1553. function tfloatdef.alignment:shortint;
  1554. begin
  1555. if (target_info.system in [system_i386_darwin,system_arm_darwin]) then
  1556. case floattype of
  1557. s80real: result:=16;
  1558. s64real,
  1559. s64currency,
  1560. s64comp : result:=4;
  1561. else
  1562. result := inherited alignment;
  1563. end
  1564. else
  1565. result := inherited alignment;
  1566. end;
  1567. procedure tfloatdef.setsize;
  1568. begin
  1569. case floattype of
  1570. s32real : savesize:=4;
  1571. s80real : savesize:=10;
  1572. sc80real:
  1573. if target_info.system in [system_i386_darwin,system_x86_64_darwin,
  1574. system_x86_64_linux,system_x86_64_freebsd,
  1575. system_x86_64_solaris,system_x86_64_embedded] then
  1576. savesize:=16
  1577. else
  1578. savesize:=12;
  1579. s64real,
  1580. s64currency,
  1581. s64comp : savesize:=8;
  1582. else
  1583. savesize:=0;
  1584. end;
  1585. end;
  1586. function tfloatdef.getvardef : longint;
  1587. const
  1588. floattype2vardef : array[tfloattype] of longint = (
  1589. varSingle,varDouble,varUndefined,varUndefined,
  1590. varUndefined,varCurrency,varUndefined);
  1591. begin
  1592. if (upper(typename)='TDATETIME') and
  1593. assigned(owner) and
  1594. assigned(owner.name) and
  1595. (owner.name^='SYSTEM') then
  1596. result:=varDate
  1597. else
  1598. result:=floattype2vardef[floattype];
  1599. end;
  1600. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1601. begin
  1602. inherited ppuwrite(ppufile);
  1603. ppufile.putbyte(byte(floattype));
  1604. ppufile.writeentry(ibfloatdef);
  1605. end;
  1606. function tfloatdef.is_publishable : boolean;
  1607. begin
  1608. is_publishable:=true;
  1609. end;
  1610. function tfloatdef.GetTypeName : string;
  1611. const
  1612. names : array[tfloattype] of string[20] = (
  1613. 'Single','Double','Extended','CExtended','Comp','Currency','Float128');
  1614. begin
  1615. GetTypeName:=names[floattype];
  1616. end;
  1617. {****************************************************************************
  1618. TFILEDEF
  1619. ****************************************************************************}
  1620. constructor tfiledef.createtext;
  1621. begin
  1622. inherited create(filedef);
  1623. filetyp:=ft_text;
  1624. typedfiledef:=nil;
  1625. setsize;
  1626. end;
  1627. constructor tfiledef.createuntyped;
  1628. begin
  1629. inherited create(filedef);
  1630. filetyp:=ft_untyped;
  1631. typedfiledef:=nil;
  1632. setsize;
  1633. end;
  1634. constructor tfiledef.createtyped(def:tdef);
  1635. begin
  1636. inherited create(filedef);
  1637. filetyp:=ft_typed;
  1638. typedfiledef:=def;
  1639. setsize;
  1640. end;
  1641. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1642. begin
  1643. inherited ppuload(filedef,ppufile);
  1644. filetyp:=tfiletyp(ppufile.getbyte);
  1645. if filetyp=ft_typed then
  1646. ppufile.getderef(typedfiledefderef)
  1647. else
  1648. typedfiledef:=nil;
  1649. setsize;
  1650. end;
  1651. function tfiledef.getcopy : tstoreddef;
  1652. begin
  1653. case filetyp of
  1654. ft_typed:
  1655. result:=tfiledef.createtyped(typedfiledef);
  1656. ft_untyped:
  1657. result:=tfiledef.createuntyped;
  1658. ft_text:
  1659. result:=tfiledef.createtext;
  1660. else
  1661. internalerror(2004121201);
  1662. end;
  1663. end;
  1664. procedure tfiledef.buildderef;
  1665. begin
  1666. inherited buildderef;
  1667. if filetyp=ft_typed then
  1668. typedfiledefderef.build(typedfiledef);
  1669. end;
  1670. procedure tfiledef.deref;
  1671. begin
  1672. inherited deref;
  1673. if filetyp=ft_typed then
  1674. typedfiledef:=tdef(typedfiledefderef.resolve);
  1675. end;
  1676. procedure tfiledef.setsize;
  1677. begin
  1678. {$ifdef cpu64bitaddr}
  1679. case filetyp of
  1680. ft_text :
  1681. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1682. savesize:=632{+8}
  1683. else
  1684. savesize:=628{+8};
  1685. ft_typed,
  1686. ft_untyped :
  1687. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1688. savesize:=372
  1689. else
  1690. savesize:=368;
  1691. end;
  1692. {$else cpu64bitaddr}
  1693. case filetyp of
  1694. ft_text :
  1695. savesize:=592{+4};
  1696. ft_typed,
  1697. ft_untyped :
  1698. savesize:=332;
  1699. end;
  1700. {$endif cpu64bitaddr}
  1701. end;
  1702. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1703. begin
  1704. inherited ppuwrite(ppufile);
  1705. ppufile.putbyte(byte(filetyp));
  1706. if filetyp=ft_typed then
  1707. ppufile.putderef(typedfiledefderef);
  1708. ppufile.writeentry(ibfiledef);
  1709. end;
  1710. function tfiledef.GetTypeName : string;
  1711. begin
  1712. case filetyp of
  1713. ft_untyped:
  1714. GetTypeName:='File';
  1715. ft_typed:
  1716. GetTypeName:='File Of '+typedfiledef.typename;
  1717. ft_text:
  1718. GetTypeName:='Text'
  1719. end;
  1720. end;
  1721. function tfiledef.getmangledparaname : string;
  1722. begin
  1723. case filetyp of
  1724. ft_untyped:
  1725. getmangledparaname:='FILE';
  1726. ft_typed:
  1727. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  1728. ft_text:
  1729. getmangledparaname:='TEXT'
  1730. end;
  1731. end;
  1732. {****************************************************************************
  1733. TVARIANTDEF
  1734. ****************************************************************************}
  1735. constructor tvariantdef.create(v : tvarianttype);
  1736. begin
  1737. inherited create(variantdef);
  1738. varianttype:=v;
  1739. setsize;
  1740. end;
  1741. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1742. begin
  1743. inherited ppuload(variantdef,ppufile);
  1744. varianttype:=tvarianttype(ppufile.getbyte);
  1745. setsize;
  1746. end;
  1747. function tvariantdef.getcopy : tstoreddef;
  1748. begin
  1749. result:=tvariantdef.create(varianttype);
  1750. end;
  1751. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1752. begin
  1753. inherited ppuwrite(ppufile);
  1754. ppufile.putbyte(byte(varianttype));
  1755. ppufile.writeentry(ibvariantdef);
  1756. end;
  1757. function tvariantdef.getvardef : longint;
  1758. begin
  1759. Result:=varVariant;
  1760. end;
  1761. procedure tvariantdef.setsize;
  1762. begin
  1763. {$ifdef cpu64bitaddr}
  1764. savesize:=24;
  1765. {$else cpu64bitaddr}
  1766. savesize:=16;
  1767. {$endif cpu64bitaddr}
  1768. end;
  1769. function tvariantdef.GetTypeName : string;
  1770. begin
  1771. case varianttype of
  1772. vt_normalvariant:
  1773. GetTypeName:='Variant';
  1774. vt_olevariant:
  1775. GetTypeName:='OleVariant';
  1776. end;
  1777. end;
  1778. function tvariantdef.needs_inittable : boolean;
  1779. begin
  1780. needs_inittable:=true;
  1781. end;
  1782. function tvariantdef.is_publishable : boolean;
  1783. begin
  1784. is_publishable:=true;
  1785. end;
  1786. {****************************************************************************
  1787. TABSTRACtpointerdef
  1788. ****************************************************************************}
  1789. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  1790. begin
  1791. inherited create(dt);
  1792. pointeddef:=def;
  1793. savesize:=sizeof(pint);
  1794. end;
  1795. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1796. begin
  1797. inherited ppuload(dt,ppufile);
  1798. ppufile.getderef(pointeddefderef);
  1799. savesize:=sizeof(pint);
  1800. end;
  1801. procedure tabstractpointerdef.buildderef;
  1802. begin
  1803. inherited buildderef;
  1804. pointeddefderef.build(pointeddef);
  1805. end;
  1806. procedure tabstractpointerdef.deref;
  1807. begin
  1808. inherited deref;
  1809. pointeddef:=tdef(pointeddefderef.resolve);
  1810. end;
  1811. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1812. begin
  1813. inherited ppuwrite(ppufile);
  1814. ppufile.putderef(pointeddefderef);
  1815. end;
  1816. {****************************************************************************
  1817. tpointerdef
  1818. ****************************************************************************}
  1819. constructor tpointerdef.create(def:tdef);
  1820. begin
  1821. inherited create(pointerdef,def);
  1822. is_far:=false;
  1823. end;
  1824. constructor tpointerdef.createfar(def:tdef);
  1825. begin
  1826. inherited create(pointerdef,def);
  1827. is_far:=true;
  1828. end;
  1829. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  1830. begin
  1831. inherited ppuload(pointerdef,ppufile);
  1832. is_far:=(ppufile.getbyte<>0);
  1833. end;
  1834. function tpointerdef.getcopy : tstoreddef;
  1835. begin
  1836. result:=tpointerdef.create(pointeddef);
  1837. tpointerdef(result).is_far:=is_far;
  1838. tpointerdef(result).savesize:=savesize;
  1839. end;
  1840. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1841. begin
  1842. inherited ppuwrite(ppufile);
  1843. ppufile.putbyte(byte(is_far));
  1844. ppufile.writeentry(ibpointerdef);
  1845. end;
  1846. function tpointerdef.GetTypeName : string;
  1847. begin
  1848. if is_far then
  1849. GetTypeName:='^'+pointeddef.typename+';far'
  1850. else
  1851. GetTypeName:='^'+pointeddef.typename;
  1852. end;
  1853. {****************************************************************************
  1854. TCLASSREFDEF
  1855. ****************************************************************************}
  1856. constructor tclassrefdef.create(def:tdef);
  1857. begin
  1858. inherited create(classrefdef,def);
  1859. end;
  1860. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  1861. begin
  1862. inherited ppuload(classrefdef,ppufile);
  1863. end;
  1864. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  1865. begin
  1866. inherited ppuwrite(ppufile);
  1867. ppufile.writeentry(ibclassrefdef);
  1868. end;
  1869. function tclassrefdef.GetTypeName : string;
  1870. begin
  1871. GetTypeName:='Class Of '+pointeddef.typename;
  1872. end;
  1873. function tclassrefdef.is_publishable : boolean;
  1874. begin
  1875. result:=true;
  1876. end;
  1877. function tclassrefdef.rtti_mangledname(rt: trttitype): string;
  1878. begin
  1879. if (tobjectdef(pointeddef).objecttype<>odt_objcclass) then
  1880. result:=inherited rtti_mangledname(rt)
  1881. else
  1882. result:=tobjectdef(pointeddef).rtti_mangledname(objcmetartti);
  1883. end;
  1884. procedure tclassrefdef.reset;
  1885. begin
  1886. tobjectdef(pointeddef).classref_created_in_current_module:=false;
  1887. inherited reset;
  1888. end;
  1889. procedure tclassrefdef.register_created_object_type;
  1890. begin
  1891. tobjectdef(pointeddef).register_created_classref_type;
  1892. end;
  1893. {***************************************************************************
  1894. TSETDEF
  1895. ***************************************************************************}
  1896. constructor tsetdef.create(def:tdef;low, high : aint);
  1897. var
  1898. setallocbits: aint;
  1899. packedsavesize: aint;
  1900. begin
  1901. inherited create(setdef);
  1902. elementdef:=def;
  1903. setmax:=high;
  1904. if (current_settings.setalloc=0) then
  1905. begin
  1906. setbase:=0;
  1907. if (high<32) then
  1908. savesize:=Sizeof(longint)
  1909. else if (high<256) then
  1910. savesize:=32
  1911. else
  1912. savesize:=(high+7) div 8
  1913. end
  1914. else
  1915. begin
  1916. setallocbits:=current_settings.setalloc*8;
  1917. setbase:=low and not(setallocbits-1);
  1918. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  1919. savesize:=packedsavesize;
  1920. if savesize=3 then
  1921. savesize:=4;
  1922. end;
  1923. end;
  1924. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  1925. begin
  1926. inherited ppuload(setdef,ppufile);
  1927. ppufile.getderef(elementdefderef);
  1928. savesize:=ppufile.getaint;
  1929. setbase:=ppufile.getaint;
  1930. setmax:=ppufile.getaint;
  1931. end;
  1932. function tsetdef.getcopy : tstoreddef;
  1933. begin
  1934. result:=tsetdef.create(elementdef,setbase,setmax);
  1935. { the copy might have been created with a different setalloc setting }
  1936. tsetdef(result).savesize:=savesize;
  1937. end;
  1938. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  1939. begin
  1940. inherited ppuwrite(ppufile);
  1941. ppufile.putderef(elementdefderef);
  1942. ppufile.putaint(savesize);
  1943. ppufile.putaint(setbase);
  1944. ppufile.putaint(setmax);
  1945. ppufile.writeentry(ibsetdef);
  1946. end;
  1947. procedure tsetdef.buildderef;
  1948. begin
  1949. inherited buildderef;
  1950. elementdefderef.build(elementdef);
  1951. end;
  1952. procedure tsetdef.deref;
  1953. begin
  1954. inherited deref;
  1955. elementdef:=tdef(elementdefderef.resolve);
  1956. end;
  1957. function tsetdef.is_publishable : boolean;
  1958. begin
  1959. is_publishable:=savesize in [1,2,4];
  1960. end;
  1961. function tsetdef.GetTypeName : string;
  1962. begin
  1963. if assigned(elementdef) then
  1964. GetTypeName:='Set Of '+elementdef.typename
  1965. else
  1966. GetTypeName:='Empty Set';
  1967. end;
  1968. {***************************************************************************
  1969. TFORMALDEF
  1970. ***************************************************************************}
  1971. constructor tformaldef.create(Atyped:boolean);
  1972. begin
  1973. inherited create(formaldef);
  1974. typed:=Atyped;
  1975. savesize:=0;
  1976. end;
  1977. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  1978. begin
  1979. inherited ppuload(formaldef,ppufile);
  1980. typed:=boolean(ppufile.getbyte);
  1981. savesize:=0;
  1982. end;
  1983. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  1984. begin
  1985. inherited ppuwrite(ppufile);
  1986. ppufile.putbyte(byte(typed));
  1987. ppufile.writeentry(ibformaldef);
  1988. end;
  1989. function tformaldef.GetTypeName : string;
  1990. begin
  1991. if typed then
  1992. GetTypeName:='<Typed formal type>'
  1993. else
  1994. GetTypeName:='<Formal type>';
  1995. end;
  1996. {***************************************************************************
  1997. TARRAYDEF
  1998. ***************************************************************************}
  1999. constructor tarraydef.create(l,h : aint;def:tdef);
  2000. begin
  2001. inherited create(arraydef);
  2002. lowrange:=l;
  2003. highrange:=h;
  2004. rangedef:=def;
  2005. _elementdef:=nil;
  2006. arrayoptions:=[];
  2007. end;
  2008. constructor tarraydef.create_from_pointer(def:tdef);
  2009. begin
  2010. { use -1 so that the elecount will not overflow }
  2011. self.create(0,high(aint)-1,s32inttype);
  2012. arrayoptions:=[ado_IsConvertedPointer];
  2013. setelementdef(def);
  2014. end;
  2015. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  2016. begin
  2017. inherited ppuload(arraydef,ppufile);
  2018. { the addresses are calculated later }
  2019. ppufile.getderef(_elementdefderef);
  2020. ppufile.getderef(rangedefderef);
  2021. lowrange:=ppufile.getaint;
  2022. highrange:=ppufile.getaint;
  2023. ppufile.getsmallset(arrayoptions);
  2024. end;
  2025. function tarraydef.getcopy : tstoreddef;
  2026. begin
  2027. result:=tarraydef.create(lowrange,highrange,rangedef);
  2028. tarraydef(result).arrayoptions:=arrayoptions;
  2029. tarraydef(result)._elementdef:=_elementdef;
  2030. end;
  2031. procedure tarraydef.buildderef;
  2032. begin
  2033. inherited buildderef;
  2034. _elementdefderef.build(_elementdef);
  2035. rangedefderef.build(rangedef);
  2036. end;
  2037. procedure tarraydef.deref;
  2038. begin
  2039. inherited deref;
  2040. _elementdef:=tdef(_elementdefderef.resolve);
  2041. rangedef:=tdef(rangedefderef.resolve);
  2042. end;
  2043. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  2044. begin
  2045. inherited ppuwrite(ppufile);
  2046. ppufile.putderef(_elementdefderef);
  2047. ppufile.putderef(rangedefderef);
  2048. ppufile.putaint(lowrange);
  2049. ppufile.putaint(highrange);
  2050. ppufile.putsmallset(arrayoptions);
  2051. ppufile.writeentry(ibarraydef);
  2052. end;
  2053. function tarraydef.elesize : aint;
  2054. begin
  2055. if (ado_IsBitPacked in arrayoptions) then
  2056. internalerror(2006080101);
  2057. if assigned(_elementdef) then
  2058. result:=_elementdef.size
  2059. else
  2060. result:=0;
  2061. end;
  2062. function tarraydef.elepackedbitsize : aint;
  2063. begin
  2064. if not(ado_IsBitPacked in arrayoptions) then
  2065. internalerror(2006080102);
  2066. if assigned(_elementdef) then
  2067. result:=_elementdef.packedbitsize
  2068. else
  2069. result:=0;
  2070. end;
  2071. function tarraydef.elecount : aword;
  2072. var
  2073. qhigh,qlow : qword;
  2074. begin
  2075. if ado_IsDynamicArray in arrayoptions then
  2076. begin
  2077. result:=0;
  2078. exit;
  2079. end;
  2080. if (highrange>0) and (lowrange<0) then
  2081. begin
  2082. qhigh:=highrange;
  2083. qlow:=qword(-lowrange);
  2084. { prevent overflow, return 0 to indicate overflow }
  2085. if qhigh+qlow>qword(high(aint)-1) then
  2086. result:=0
  2087. else
  2088. result:=qhigh+qlow+1;
  2089. end
  2090. else
  2091. result:=int64(highrange)-lowrange+1;
  2092. end;
  2093. function tarraydef.size : aint;
  2094. var
  2095. cachedelecount : aword;
  2096. cachedelesize : aint;
  2097. begin
  2098. if ado_IsDynamicArray in arrayoptions then
  2099. begin
  2100. size:=sizeof(pint);
  2101. exit;
  2102. end;
  2103. { Tarraydef.size may never be called for an open array! }
  2104. if highrange<lowrange then
  2105. internalerror(99080501);
  2106. if not (ado_IsBitPacked in arrayoptions) then
  2107. cachedelesize:=elesize
  2108. else
  2109. cachedelesize := elepackedbitsize;
  2110. cachedelecount:=elecount;
  2111. if (cachedelesize = 0) then
  2112. begin
  2113. size := 0;
  2114. exit;
  2115. end;
  2116. if (cachedelecount = 0) then
  2117. begin
  2118. size := -1;
  2119. exit;
  2120. end;
  2121. { prevent overflow, return -1 to indicate overflow }
  2122. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  2123. if (cachedelecount > aword(high(aint))) or
  2124. ((high(aint) div cachedelesize) < aint(cachedelecount)) or
  2125. { also lowrange*elesize must be < high(aint) to prevent overflow when
  2126. accessing the array, see ncgmem (PFV) }
  2127. ((high(aint) div cachedelesize) < abs(lowrange)) then
  2128. begin
  2129. result:=-1;
  2130. exit;
  2131. end;
  2132. result:=cachedelesize*aint(cachedelecount);
  2133. if (ado_IsBitPacked in arrayoptions) then
  2134. { can't just add 7 and divide by 8, because that may overflow }
  2135. result:=result div 8 + ord((result mod 8)<>0);
  2136. end;
  2137. procedure tarraydef.setelementdef(def:tdef);
  2138. begin
  2139. _elementdef:=def;
  2140. if not(
  2141. (ado_IsDynamicArray in arrayoptions) or
  2142. (ado_IsConvertedPointer in arrayoptions) or
  2143. (highrange<lowrange)
  2144. ) and
  2145. (size=-1) then
  2146. Message(sym_e_segment_too_large);
  2147. end;
  2148. function tarraydef.alignment : shortint;
  2149. begin
  2150. { alignment of dyn. arrays doesn't depend on the element size }
  2151. if (ado_IsDynamicArray in arrayoptions) then
  2152. alignment:=size_2_align(sizeof(pint))
  2153. { alignment is the alignment of the elements }
  2154. else if (elementdef.typ in [arraydef,recorddef,orddef,enumdef,floatdef]) or
  2155. ((elementdef.typ=objectdef) and
  2156. is_object(elementdef)) then
  2157. alignment:=elementdef.alignment
  2158. { alignment is the size of the elements }
  2159. else if not (ado_IsBitPacked in arrayoptions) then
  2160. alignment:=size_2_align(elesize)
  2161. else
  2162. alignment:=packedbitsloadsize(elepackedbitsize);
  2163. end;
  2164. function tarraydef.needs_inittable : boolean;
  2165. begin
  2166. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  2167. end;
  2168. function tarraydef.GetTypeName : string;
  2169. begin
  2170. if (ado_IsConstString in arrayoptions) then
  2171. result:='Constant String'
  2172. else if (ado_isarrayofconst in arrayoptions) or
  2173. (ado_isConstructor in arrayoptions) then
  2174. begin
  2175. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  2176. GetTypeName:='Array Of Const'
  2177. else
  2178. GetTypeName:='Array Of Const/Constant Open Array of '+elementdef.typename;
  2179. end
  2180. else if (ado_IsDynamicArray in arrayoptions) then
  2181. GetTypeName:='Dynamic Array Of '+elementdef.typename
  2182. else if ((highrange=-1) and (lowrange=0)) then
  2183. GetTypeName:='Open Array Of '+elementdef.typename
  2184. else
  2185. begin
  2186. result := '';
  2187. if (ado_IsBitPacked in arrayoptions) then
  2188. result:='Packed ';
  2189. if rangedef.typ=enumdef then
  2190. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  2191. else
  2192. result:=result+'Array['+tostr(lowrange)+'..'+
  2193. tostr(highrange)+'] Of '+elementdef.typename
  2194. end;
  2195. end;
  2196. function tarraydef.getmangledparaname : string;
  2197. begin
  2198. if ado_isarrayofconst in arrayoptions then
  2199. getmangledparaname:='array_of_const'
  2200. else
  2201. if ((highrange=-1) and (lowrange=0)) then
  2202. getmangledparaname:='array_of_'+elementdef.mangledparaname
  2203. else
  2204. internalerror(200204176);
  2205. end;
  2206. function tarraydef.is_publishable : boolean;
  2207. begin
  2208. Result:=ado_IsDynamicArray in arrayoptions;
  2209. end;
  2210. {***************************************************************************
  2211. tabstractrecorddef
  2212. ***************************************************************************}
  2213. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  2214. begin
  2215. if t=gs_record then
  2216. GetSymtable:=symtable
  2217. else
  2218. GetSymtable:=nil;
  2219. end;
  2220. procedure tabstractrecorddef.reset;
  2221. begin
  2222. inherited reset;
  2223. tstoredsymtable(symtable).reset_all_defs;
  2224. end;
  2225. function tabstractrecorddef.is_packed:boolean;
  2226. begin
  2227. result:=tabstractrecordsymtable(symtable).is_packed;
  2228. end;
  2229. {***************************************************************************
  2230. trecorddef
  2231. ***************************************************************************}
  2232. constructor trecorddef.create(p : TSymtable);
  2233. begin
  2234. inherited create(recorddef);
  2235. symtable:=p;
  2236. { we can own the symtable only if nobody else owns a copy so far }
  2237. if symtable.refcount=1 then
  2238. symtable.defowner:=self;
  2239. isunion:=false;
  2240. end;
  2241. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2242. begin
  2243. inherited ppuload(recorddef,ppufile);
  2244. if df_copied_def in defoptions then
  2245. ppufile.getderef(cloneddefderef)
  2246. else
  2247. begin
  2248. symtable:=trecordsymtable.create(0);
  2249. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2250. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2251. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2252. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  2253. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2254. trecordsymtable(symtable).ppuload(ppufile);
  2255. { requires usefieldalignment to be set }
  2256. symtable.defowner:=self;
  2257. end;
  2258. isunion:=false;
  2259. end;
  2260. destructor trecorddef.destroy;
  2261. begin
  2262. if assigned(symtable) then
  2263. begin
  2264. symtable.free;
  2265. symtable:=nil;
  2266. end;
  2267. inherited destroy;
  2268. end;
  2269. function trecorddef.getcopy : tstoreddef;
  2270. begin
  2271. result:=trecorddef.create(symtable.getcopy);
  2272. trecorddef(result).isunion:=isunion;
  2273. include(trecorddef(result).defoptions,df_copied_def);
  2274. end;
  2275. function trecorddef.needs_inittable : boolean;
  2276. begin
  2277. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2278. end;
  2279. procedure trecorddef.buildderef;
  2280. begin
  2281. inherited buildderef;
  2282. if df_copied_def in defoptions then
  2283. cloneddefderef.build(symtable.defowner)
  2284. else
  2285. tstoredsymtable(symtable).buildderef;
  2286. end;
  2287. procedure trecorddef.deref;
  2288. begin
  2289. inherited deref;
  2290. { now dereference the definitions }
  2291. if df_copied_def in defoptions then
  2292. begin
  2293. cloneddef:=trecorddef(cloneddefderef.resolve);
  2294. symtable:=cloneddef.symtable.getcopy;
  2295. end
  2296. else
  2297. tstoredsymtable(symtable).deref;
  2298. { assign TGUID? load only from system unit }
  2299. if not(assigned(rec_tguid)) and
  2300. (upper(typename)='TGUID') and
  2301. assigned(owner) and
  2302. assigned(owner.name) and
  2303. (owner.name^='SYSTEM') then
  2304. rec_tguid:=self;
  2305. end;
  2306. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2307. begin
  2308. inherited ppuwrite(ppufile);
  2309. if df_copied_def in defoptions then
  2310. ppufile.putderef(cloneddefderef)
  2311. else
  2312. begin
  2313. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2314. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2315. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2316. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  2317. ppufile.putaint(trecordsymtable(symtable).datasize);
  2318. end;
  2319. ppufile.writeentry(ibrecorddef);
  2320. if not(df_copied_def in defoptions) then
  2321. trecordsymtable(symtable).ppuwrite(ppufile);
  2322. end;
  2323. function trecorddef.size:aint;
  2324. begin
  2325. result:=trecordsymtable(symtable).datasize;
  2326. end;
  2327. function trecorddef.alignment:shortint;
  2328. begin
  2329. alignment:=trecordsymtable(symtable).recordalignment;
  2330. end;
  2331. function trecorddef.padalignment:shortint;
  2332. begin
  2333. padalignment := trecordsymtable(symtable).padalignment;
  2334. end;
  2335. function trecorddef.GetTypeName : string;
  2336. begin
  2337. GetTypeName:='<record type>'
  2338. end;
  2339. {***************************************************************************
  2340. TABSTRACTPROCDEF
  2341. ***************************************************************************}
  2342. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  2343. begin
  2344. inherited create(dt);
  2345. parast:=tparasymtable.create(self,level);
  2346. paras:=nil;
  2347. minparacount:=0;
  2348. maxparacount:=0;
  2349. proctypeoption:=potype_none;
  2350. proccalloption:=pocall_none;
  2351. procoptions:=[];
  2352. returndef:=voidtype;
  2353. savesize:=sizeof(pint);
  2354. requiredargarea:=0;
  2355. has_paraloc_info:=false;
  2356. funcretloc[callerside].init;
  2357. funcretloc[calleeside].init;
  2358. end;
  2359. destructor tabstractprocdef.destroy;
  2360. begin
  2361. if assigned(paras) then
  2362. begin
  2363. {$ifdef MEMDEBUG}
  2364. memprocpara.start;
  2365. {$endif MEMDEBUG}
  2366. paras.free;
  2367. paras:=nil;
  2368. {$ifdef MEMDEBUG}
  2369. memprocpara.stop;
  2370. {$endif MEMDEBUG}
  2371. end;
  2372. if assigned(parast) then
  2373. begin
  2374. {$ifdef MEMDEBUG}
  2375. memprocparast.start;
  2376. {$endif MEMDEBUG}
  2377. parast.free;
  2378. parast:=nil;
  2379. {$ifdef MEMDEBUG}
  2380. memprocparast.stop;
  2381. {$endif MEMDEBUG}
  2382. end;
  2383. funcretloc[callerside].done;
  2384. funcretloc[calleeside].done;
  2385. inherited destroy;
  2386. end;
  2387. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  2388. begin
  2389. if (tsym(p).typ<>paravarsym) then
  2390. exit;
  2391. inc(plongint(arg)^);
  2392. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2393. begin
  2394. if not assigned(tparavarsym(p).defaultconstsym) then
  2395. inc(minparacount);
  2396. inc(maxparacount);
  2397. end;
  2398. end;
  2399. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  2400. begin
  2401. if (tsym(p).typ<>paravarsym) then
  2402. exit;
  2403. paras.add(p);
  2404. end;
  2405. procedure tabstractprocdef.calcparas;
  2406. var
  2407. paracount : longint;
  2408. begin
  2409. { This can already be assigned when
  2410. we need to reresolve this unit (PFV) }
  2411. if assigned(paras) then
  2412. paras.free;
  2413. paras:=tparalist.create(false);
  2414. paracount:=0;
  2415. minparacount:=0;
  2416. maxparacount:=0;
  2417. parast.SymList.ForEachCall(@count_para,@paracount);
  2418. paras.capacity:=paracount;
  2419. { Insert parameters in table }
  2420. parast.SymList.ForEachCall(@insert_para,nil);
  2421. { Order parameters }
  2422. paras.sortparas;
  2423. end;
  2424. procedure tabstractprocdef.buildderef;
  2425. begin
  2426. { released procdef? }
  2427. if not assigned(parast) then
  2428. exit;
  2429. inherited buildderef;
  2430. returndefderef.build(returndef);
  2431. { parast }
  2432. tparasymtable(parast).buildderef;
  2433. end;
  2434. procedure tabstractprocdef.deref;
  2435. begin
  2436. inherited deref;
  2437. returndef:=tdef(returndefderef.resolve);
  2438. { parast }
  2439. tparasymtable(parast).deref;
  2440. { recalculated parameters }
  2441. calcparas;
  2442. end;
  2443. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2444. var
  2445. b : byte;
  2446. begin
  2447. inherited ppuload(dt,ppufile);
  2448. parast:=nil;
  2449. Paras:=nil;
  2450. minparacount:=0;
  2451. maxparacount:=0;
  2452. ppufile.getderef(returndefderef);
  2453. { TODO: remove fpu_used loading}
  2454. ppufile.getbyte;
  2455. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2456. proccalloption:=tproccalloption(ppufile.getbyte);
  2457. ppufile.getnormalset(procoptions);
  2458. funcretloc[callerside].init;
  2459. if po_explicitparaloc in procoptions then
  2460. funcretloc[callerside].ppuload(ppufile);
  2461. savesize:=sizeof(pint);
  2462. has_paraloc_info:=(po_explicitparaloc in procoptions);
  2463. end;
  2464. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2465. var
  2466. oldintfcrc : boolean;
  2467. begin
  2468. { released procdef? }
  2469. if not assigned(parast) then
  2470. exit;
  2471. inherited ppuwrite(ppufile);
  2472. ppufile.putderef(returndefderef);
  2473. oldintfcrc:=ppufile.do_interface_crc;
  2474. ppufile.do_interface_crc:=false;
  2475. ppufile.putbyte(0);
  2476. ppufile.putbyte(ord(proctypeoption));
  2477. ppufile.putbyte(ord(proccalloption));
  2478. ppufile.putnormalset(procoptions);
  2479. ppufile.do_interface_crc:=oldintfcrc;
  2480. if (po_explicitparaloc in procoptions) then
  2481. funcretloc[callerside].ppuwrite(ppufile);
  2482. end;
  2483. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2484. var
  2485. hs,s : string;
  2486. hp : TParavarsym;
  2487. hpc : tconstsym;
  2488. first : boolean;
  2489. i : integer;
  2490. begin
  2491. s:='';
  2492. first:=true;
  2493. for i:=0 to paras.count-1 do
  2494. begin
  2495. hp:=tparavarsym(paras[i]);
  2496. if not(vo_is_hidden_para in hp.varoptions) or
  2497. (showhidden) then
  2498. begin
  2499. if first then
  2500. begin
  2501. s:=s+'(';
  2502. first:=false;
  2503. end
  2504. else
  2505. s:=s+',';
  2506. if vo_is_hidden_para in hp.varoptions then
  2507. s:=s+'<';
  2508. case hp.varspez of
  2509. vs_var :
  2510. s:=s+'var ';
  2511. vs_const :
  2512. s:=s+'const ';
  2513. vs_out :
  2514. s:=s+'out ';
  2515. end;
  2516. if hp.univpara then
  2517. s:=s+'univ ';
  2518. if assigned(hp.vardef.typesym) then
  2519. begin
  2520. hs:=hp.vardef.typesym.realname;
  2521. if hs[1]<>'$' then
  2522. s:=s+hs
  2523. else
  2524. s:=s+hp.vardef.GetTypeName;
  2525. end
  2526. else
  2527. s:=s+hp.vardef.GetTypeName;
  2528. { default value }
  2529. if assigned(hp.defaultconstsym) then
  2530. begin
  2531. hpc:=tconstsym(hp.defaultconstsym);
  2532. hs:='';
  2533. case hpc.consttyp of
  2534. conststring,
  2535. constresourcestring :
  2536. begin
  2537. If hpc.value.len>0 then
  2538. begin
  2539. setLength(hs,hpc.value.len);
  2540. move(hpc.value.valueptr^,hs[1],hpc.value.len);
  2541. end;
  2542. end;
  2543. constreal :
  2544. str(pbestreal(hpc.value.valueptr)^,hs);
  2545. constpointer :
  2546. hs:=tostr(hpc.value.valueordptr);
  2547. constord :
  2548. begin
  2549. if is_boolean(hpc.constdef) then
  2550. begin
  2551. if hpc.value.valueord<>0 then
  2552. hs:='TRUE'
  2553. else
  2554. hs:='FALSE';
  2555. end
  2556. else
  2557. hs:=tostr(hpc.value.valueord);
  2558. end;
  2559. constnil :
  2560. hs:='nil';
  2561. constset :
  2562. hs:='<set>';
  2563. end;
  2564. if hs<>'' then
  2565. s:=s+'="'+hs+'"';
  2566. end;
  2567. if vo_is_hidden_para in hp.varoptions then
  2568. s:=s+'>';
  2569. end;
  2570. end;
  2571. if not first then
  2572. s:=s+')';
  2573. if (po_varargs in procoptions) then
  2574. s:=s+';VarArgs';
  2575. typename_paras:=s;
  2576. end;
  2577. function tabstractprocdef.is_methodpointer:boolean;
  2578. begin
  2579. result:=false;
  2580. end;
  2581. function tabstractprocdef.is_addressonly:boolean;
  2582. begin
  2583. result:=true;
  2584. end;
  2585. function tabstractprocdef.no_self_node: boolean;
  2586. begin
  2587. Result:=([po_staticmethod,po_classmethod]<=procoptions)or
  2588. (proctypeoption in [potype_class_constructor,potype_class_destructor]);
  2589. end;
  2590. {***************************************************************************
  2591. TPROCDEF
  2592. ***************************************************************************}
  2593. constructor tprocdef.create(level:byte);
  2594. begin
  2595. inherited create(procdef,level);
  2596. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  2597. _mangledname:=nil;
  2598. fileinfo:=current_filepos;
  2599. extnumber:=$ffff;
  2600. aliasnames:=TCmdStrList.create;
  2601. funcretsym:=nil;
  2602. forwarddef:=true;
  2603. interfacedef:=false;
  2604. hasforward:=false;
  2605. _class := nil;
  2606. import_dll:=nil;
  2607. import_name:=nil;
  2608. import_nr:=0;
  2609. inlininginfo:=nil;
  2610. deprecatedmsg:=nil;
  2611. {$ifdef i386}
  2612. fpu_used:=maxfpuregs;
  2613. {$endif i386}
  2614. end;
  2615. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  2616. var
  2617. i,aliasnamescount : longint;
  2618. level : byte;
  2619. begin
  2620. inherited ppuload(procdef,ppufile);
  2621. if po_has_mangledname in procoptions then
  2622. _mangledname:=stringdup(ppufile.getstring)
  2623. else
  2624. _mangledname:=nil;
  2625. extnumber:=ppufile.getword;
  2626. level:=ppufile.getbyte;
  2627. ppufile.getderef(_classderef);
  2628. ppufile.getderef(procsymderef);
  2629. ppufile.getposinfo(fileinfo);
  2630. visibility:=tvisibility(ppufile.getbyte);
  2631. ppufile.getsmallset(symoptions);
  2632. if sp_has_deprecated_msg in symoptions then
  2633. deprecatedmsg:=stringdup(ppufile.getstring)
  2634. else
  2635. deprecatedmsg:=nil;
  2636. {$ifdef powerpc}
  2637. { library symbol for AmigaOS/MorphOS }
  2638. ppufile.getderef(libsymderef);
  2639. {$endif powerpc}
  2640. { import stuff }
  2641. if po_has_importdll in procoptions then
  2642. import_dll:=stringdup(ppufile.getstring)
  2643. else
  2644. import_dll:=nil;
  2645. if po_has_importname in procoptions then
  2646. import_name:=stringdup(ppufile.getstring)
  2647. else
  2648. import_name:=nil;
  2649. import_nr:=ppufile.getword;
  2650. if (po_msgint in procoptions) then
  2651. messageinf.i:=ppufile.getlongint;
  2652. if (po_msgstr in procoptions) then
  2653. messageinf.str:=stringdup(ppufile.getstring);
  2654. if (po_dispid in procoptions) then
  2655. dispid:=ppufile.getlongint;
  2656. { inline stuff }
  2657. if (po_has_inlininginfo in procoptions) then
  2658. begin
  2659. ppufile.getderef(funcretsymderef);
  2660. new(inlininginfo);
  2661. ppufile.getsmallset(inlininginfo^.flags);
  2662. end
  2663. else
  2664. begin
  2665. inlininginfo:=nil;
  2666. funcretsym:=nil;
  2667. end;
  2668. aliasnames:=TCmdStrList.create;
  2669. { count alias names }
  2670. aliasnamescount:=ppufile.getbyte;
  2671. for i:=1 to aliasnamescount do
  2672. aliasnames.insert(ppufile.getstring);
  2673. { load para symtable }
  2674. parast:=tparasymtable.create(self,level);
  2675. tparasymtable(parast).ppuload(ppufile);
  2676. { load local symtable }
  2677. if (po_has_inlininginfo in procoptions) then
  2678. begin
  2679. localst:=tlocalsymtable.create(self,level);
  2680. tlocalsymtable(localst).ppuload(ppufile);
  2681. end
  2682. else
  2683. localst:=nil;
  2684. { inline stuff }
  2685. if (po_has_inlininginfo in procoptions) then
  2686. inlininginfo^.code:=ppuloadnodetree(ppufile);
  2687. { default values for no persistent data }
  2688. if (cs_link_deffile in current_settings.globalswitches) and
  2689. (tf_need_export in target_info.flags) and
  2690. (po_exports in procoptions) then
  2691. deffile.AddExport(mangledname);
  2692. forwarddef:=false;
  2693. interfacedef:=false;
  2694. hasforward:=false;
  2695. { Disable po_has_inlining until the derefimpl is done }
  2696. exclude(procoptions,po_has_inlininginfo);
  2697. {$ifdef i386}
  2698. fpu_used:=maxfpuregs;
  2699. {$endif i386}
  2700. end;
  2701. destructor tprocdef.destroy;
  2702. begin
  2703. aliasnames.free;
  2704. aliasnames:=nil;
  2705. if assigned(localst) and
  2706. (localst.symtabletype<>staticsymtable) then
  2707. begin
  2708. {$ifdef MEMDEBUG}
  2709. memproclocalst.start;
  2710. {$endif MEMDEBUG}
  2711. localst.free;
  2712. localst:=nil;
  2713. {$ifdef MEMDEBUG}
  2714. memproclocalst.start;
  2715. {$endif MEMDEBUG}
  2716. end;
  2717. if assigned(inlininginfo) then
  2718. begin
  2719. {$ifdef MEMDEBUG}
  2720. memprocnodetree.start;
  2721. {$endif MEMDEBUG}
  2722. tnode(inlininginfo^.code).free;
  2723. {$ifdef MEMDEBUG}
  2724. memprocnodetree.start;
  2725. {$endif MEMDEBUG}
  2726. dispose(inlininginfo);
  2727. inlininginfo:=nil;
  2728. end;
  2729. stringdispose(resultname);
  2730. stringdispose(import_dll);
  2731. stringdispose(import_name);
  2732. stringdispose(deprecatedmsg);
  2733. if (po_msgstr in procoptions) then
  2734. stringdispose(messageinf.str);
  2735. if assigned(_mangledname) then
  2736. begin
  2737. {$ifdef MEMDEBUG}
  2738. memmanglednames.start;
  2739. {$endif MEMDEBUG}
  2740. stringdispose(_mangledname);
  2741. {$ifdef MEMDEBUG}
  2742. memmanglednames.stop;
  2743. {$endif MEMDEBUG}
  2744. end;
  2745. inherited destroy;
  2746. end;
  2747. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  2748. var
  2749. oldintfcrc : boolean;
  2750. aliasnamescount : longint;
  2751. item : TCmdStrListItem;
  2752. begin
  2753. { released procdef? }
  2754. if not assigned(parast) then
  2755. exit;
  2756. inherited ppuwrite(ppufile);
  2757. if po_has_mangledname in procoptions then
  2758. ppufile.putstring(_mangledname^);
  2759. ppufile.putword(extnumber);
  2760. ppufile.putbyte(parast.symtablelevel);
  2761. ppufile.putderef(_classderef);
  2762. ppufile.putderef(procsymderef);
  2763. ppufile.putposinfo(fileinfo);
  2764. ppufile.putbyte(byte(visibility));
  2765. ppufile.putsmallset(symoptions);
  2766. if sp_has_deprecated_msg in symoptions then
  2767. ppufile.putstring(deprecatedmsg^);
  2768. {$ifdef powerpc}
  2769. { library symbol for AmigaOS/MorphOS }
  2770. ppufile.putderef(libsymderef);
  2771. {$endif powerpc}
  2772. { import }
  2773. if po_has_importdll in procoptions then
  2774. ppufile.putstring(import_dll^);
  2775. if po_has_importname in procoptions then
  2776. ppufile.putstring(import_name^);
  2777. ppufile.putword(import_nr);
  2778. if (po_msgint in procoptions) then
  2779. ppufile.putlongint(messageinf.i);
  2780. if (po_msgstr in procoptions) then
  2781. ppufile.putstring(messageinf.str^);
  2782. if (po_dispid in procoptions) then
  2783. ppufile.putlongint(dispid);
  2784. { inline stuff }
  2785. oldintfcrc:=ppufile.do_crc;
  2786. ppufile.do_crc:=false;
  2787. if (po_has_inlininginfo in procoptions) then
  2788. begin
  2789. ppufile.putderef(funcretsymderef);
  2790. ppufile.putsmallset(inlininginfo^.flags);
  2791. end;
  2792. { count alias names }
  2793. aliasnamescount:=0;
  2794. item:=TCmdStrListItem(aliasnames.first);
  2795. while assigned(item) do
  2796. begin
  2797. inc(aliasnamescount);
  2798. item:=TCmdStrListItem(item.next);
  2799. end;
  2800. if aliasnamescount>255 then
  2801. internalerror(200711021);
  2802. ppufile.putbyte(aliasnamescount);
  2803. item:=TCmdStrListItem(aliasnames.first);
  2804. while assigned(item) do
  2805. begin
  2806. ppufile.putstring(item.str);
  2807. item:=TCmdStrListItem(item.next);
  2808. end;
  2809. ppufile.do_crc:=oldintfcrc;
  2810. { write this entry }
  2811. ppufile.writeentry(ibprocdef);
  2812. { Save the para symtable, this is taken from the interface }
  2813. tparasymtable(parast).ppuwrite(ppufile);
  2814. { save localsymtable for inline procedures or when local
  2815. browser info is requested, this has no influence on the crc }
  2816. if (po_has_inlininginfo in procoptions) then
  2817. begin
  2818. oldintfcrc:=ppufile.do_crc;
  2819. ppufile.do_crc:=false;
  2820. tlocalsymtable(localst).ppuwrite(ppufile);
  2821. ppufile.do_crc:=oldintfcrc;
  2822. end;
  2823. { node tree for inlining }
  2824. oldintfcrc:=ppufile.do_crc;
  2825. ppufile.do_crc:=false;
  2826. if (po_has_inlininginfo in procoptions) then
  2827. ppuwritenodetree(ppufile,inlininginfo^.code);
  2828. ppufile.do_crc:=oldintfcrc;
  2829. end;
  2830. procedure tprocdef.reset;
  2831. begin
  2832. inherited reset;
  2833. procstarttai:=nil;
  2834. procendtai:=nil;
  2835. end;
  2836. function tprocdef.fullprocname(showhidden:boolean):string;
  2837. var
  2838. s : string;
  2839. t : ttoken;
  2840. begin
  2841. {$ifdef EXTDEBUG}
  2842. showhidden:=true;
  2843. {$endif EXTDEBUG}
  2844. s:='';
  2845. if assigned(_class) then
  2846. begin
  2847. s:=_class.RttiName+'.';
  2848. if (po_classmethod in procoptions) and
  2849. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  2850. s:='class ' + s;
  2851. end;
  2852. if owner.symtabletype=localsymtable then
  2853. s:='local ' + s;
  2854. if proctypeoption=potype_operator then
  2855. begin
  2856. for t:=NOTOKEN to last_overloaded do
  2857. if procsym.realname='$'+overloaded_names[t] then
  2858. begin
  2859. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  2860. break;
  2861. end;
  2862. end
  2863. else
  2864. s:=s+procsym.realname+typename_paras(showhidden);
  2865. case proctypeoption of
  2866. potype_constructor:
  2867. s:='constructor '+s;
  2868. potype_destructor:
  2869. s:='destructor '+s;
  2870. potype_class_constructor:
  2871. s:='class constructor '+s;
  2872. potype_class_destructor:
  2873. s:='class destructor '+s;
  2874. else
  2875. if assigned(returndef) and
  2876. not(is_void(returndef)) then
  2877. s:=s+':'+returndef.GetTypeName;
  2878. end;
  2879. s:=s+';';
  2880. { forced calling convention? }
  2881. if (po_hascallingconvention in procoptions) then
  2882. s:=s+' '+ProcCallOptionStr[proccalloption]+';';
  2883. if (po_staticmethod in procoptions) and
  2884. not (proctypeoption in [potype_class_constructor,potype_class_destructor]) then
  2885. s:=s+' Static;';
  2886. fullprocname:=s;
  2887. end;
  2888. function tprocdef.is_methodpointer:boolean;
  2889. begin
  2890. result:=assigned(_class);
  2891. end;
  2892. function tprocdef.is_addressonly:boolean;
  2893. begin
  2894. result:=assigned(owner) and
  2895. (owner.symtabletype<>ObjectSymtable);
  2896. end;
  2897. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  2898. begin
  2899. case t of
  2900. gs_local :
  2901. GetSymtable:=localst;
  2902. gs_para :
  2903. GetSymtable:=parast;
  2904. else
  2905. GetSymtable:=nil;
  2906. end;
  2907. end;
  2908. procedure tprocdef.buildderef;
  2909. begin
  2910. inherited buildderef;
  2911. _classderef.build(_class);
  2912. { procsym that originaly defined this definition, should be in the
  2913. same symtable }
  2914. procsymderef.build(procsym);
  2915. {$ifdef powerpc}
  2916. { library symbol for AmigaOS/MorphOS }
  2917. libsymderef.build(libsym);
  2918. {$endif powerpc}
  2919. end;
  2920. procedure tprocdef.buildderefimpl;
  2921. begin
  2922. inherited buildderefimpl;
  2923. { Localst is not available for main/unit init }
  2924. if assigned(localst) then
  2925. begin
  2926. tlocalsymtable(localst).buildderef;
  2927. tlocalsymtable(localst).buildderefimpl;
  2928. end;
  2929. { inline tree }
  2930. if (po_has_inlininginfo in procoptions) then
  2931. begin
  2932. funcretsymderef.build(funcretsym);
  2933. inlininginfo^.code.buildderefimpl;
  2934. end;
  2935. end;
  2936. procedure tprocdef.deref;
  2937. begin
  2938. inherited deref;
  2939. _class:=tobjectdef(_classderef.resolve);
  2940. { procsym that originaly defined this definition, should be in the
  2941. same symtable }
  2942. procsym:=tprocsym(procsymderef.resolve);
  2943. {$ifdef powerpc}
  2944. { library symbol for AmigaOS/MorphOS }
  2945. libsym:=tsym(libsymderef.resolve);
  2946. {$endif powerpc}
  2947. end;
  2948. procedure tprocdef.derefimpl;
  2949. begin
  2950. { Enable has_inlininginfo when the inlininginfo
  2951. structure is available. The has_inlininginfo was disabled
  2952. after the load, since the data was invalid }
  2953. if assigned(inlininginfo) then
  2954. include(procoptions,po_has_inlininginfo);
  2955. { Locals }
  2956. if assigned(localst) then
  2957. begin
  2958. tlocalsymtable(localst).deref;
  2959. tlocalsymtable(localst).derefimpl;
  2960. end;
  2961. { Inline }
  2962. if (po_has_inlininginfo in procoptions) then
  2963. begin
  2964. inlininginfo^.code.derefimpl;
  2965. { funcretsym, this is always located in the localst }
  2966. funcretsym:=tsym(funcretsymderef.resolve);
  2967. end
  2968. else
  2969. begin
  2970. { safety }
  2971. { Not safe! A unit may be reresolved after its interface has been
  2972. parsed but before its implementation has been parsed, and in that
  2973. case the funcretsym is still required!
  2974. funcretsym:=nil; }
  2975. end;
  2976. end;
  2977. function tprocdef.GetTypeName : string;
  2978. begin
  2979. GetTypeName := FullProcName(false);
  2980. end;
  2981. function tprocdef.mangledname : string;
  2982. var
  2983. hp : TParavarsym;
  2984. hs : string;
  2985. crc : dword;
  2986. newlen,
  2987. oldlen,
  2988. i : integer;
  2989. begin
  2990. if assigned(_mangledname) then
  2991. begin
  2992. {$ifdef compress}
  2993. mangledname:=minilzw_decode(_mangledname^);
  2994. {$else}
  2995. mangledname:=_mangledname^;
  2996. {$endif}
  2997. exit;
  2998. end;
  2999. { we need to use the symtable where the procsym is inserted,
  3000. because that is visible to the world }
  3001. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  3002. oldlen:=length(mangledname);
  3003. { add parameter types }
  3004. for i:=0 to paras.count-1 do
  3005. begin
  3006. hp:=tparavarsym(paras[i]);
  3007. if not(vo_is_hidden_para in hp.varoptions) then
  3008. mangledname:=mangledname+'$'+hp.vardef.mangledparaname;
  3009. end;
  3010. { add resultdef, add $$ as separator to make it unique from a
  3011. parameter separator }
  3012. if not is_void(returndef) then
  3013. mangledname:=mangledname+'$$'+returndef.mangledparaname;
  3014. newlen:=length(mangledname);
  3015. { Replace with CRC if the parameter line is very long }
  3016. if (newlen-oldlen>12) and
  3017. ((newlen>100) or (newlen-oldlen>64)) then
  3018. begin
  3019. crc:=0;
  3020. for i:=0 to paras.count-1 do
  3021. begin
  3022. hp:=tparavarsym(paras[i]);
  3023. if not(vo_is_hidden_para in hp.varoptions) then
  3024. begin
  3025. hs:=hp.vardef.mangledparaname;
  3026. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3027. end;
  3028. end;
  3029. hs:=hp.vardef.mangledparaname;
  3030. crc:=UpdateCrc32(crc,hs[1],length(hs));
  3031. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  3032. end;
  3033. {$ifdef compress}
  3034. _mangledname:=stringdup(minilzw_encode(mangledname));
  3035. {$else}
  3036. _mangledname:=stringdup(mangledname);
  3037. {$endif}
  3038. end;
  3039. function tprocdef.cplusplusmangledname : string;
  3040. function getcppparaname(p : tdef) : string;
  3041. const
  3042. {$ifdef NAMEMANGLING_GCC2}
  3043. ordtype2str : array[tordtype] of string[2] = (
  3044. '',
  3045. 'Uc','Us','Ui','Us',
  3046. 'Sc','s','i','x',
  3047. 'b','b','b','b','b',
  3048. 'c','w','x');
  3049. {$else NAMEMANGLING_GCC2}
  3050. ordtype2str : array[tordtype] of string[1] = (
  3051. 'v',
  3052. 'h','t','j','y',
  3053. 'a','s','i','x',
  3054. 'b','b','b','b','b',
  3055. 'c','w','x');
  3056. floattype2str : array[tfloattype] of string[1] = (
  3057. 'f','d','e','e',
  3058. 'd','d','g');
  3059. {$endif NAMEMANGLING_GCC2}
  3060. var
  3061. s : string;
  3062. begin
  3063. case p.typ of
  3064. orddef:
  3065. s:=ordtype2str[torddef(p).ordtype];
  3066. pointerdef:
  3067. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  3068. {$ifndef NAMEMANGLING_GCC2}
  3069. floatdef:
  3070. s:=floattype2str[tfloatdef(p).floattype];
  3071. {$endif NAMEMANGLING_GCC2}
  3072. else
  3073. internalerror(2103001);
  3074. end;
  3075. getcppparaname:=s;
  3076. end;
  3077. var
  3078. s,s2 : string;
  3079. hp : TParavarsym;
  3080. i : integer;
  3081. begin
  3082. {$ifdef NAMEMANGLING_GCC2}
  3083. { outdated gcc 2.x name mangling scheme }
  3084. s := procsym.realname;
  3085. if procsym.owner.symtabletype=ObjectSymtable then
  3086. begin
  3087. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  3088. case proctypeoption of
  3089. potype_destructor:
  3090. s:='_$_'+tostr(length(s2))+s2;
  3091. potype_constructor:
  3092. s:='___'+tostr(length(s2))+s2;
  3093. else
  3094. s:='_'+s+'__'+tostr(length(s2))+s2;
  3095. end;
  3096. end
  3097. else s:=s+'__';
  3098. s:=s+'F';
  3099. { concat modifiers }
  3100. { !!!!! }
  3101. { now we handle the parameters }
  3102. if maxparacount>0 then
  3103. begin
  3104. for i:=0 to paras.count-1 do
  3105. begin
  3106. hp:=tparavarsym(paras[i]);
  3107. { no hidden parameters form part of a C++ mangled name:
  3108. a) self is not included
  3109. b) there are no "high" or other hidden parameters
  3110. }
  3111. if vo_is_hidden_para in hp.varoptions then
  3112. continue;
  3113. s2:=getcppparaname(hp.vardef);
  3114. if hp.varspez in [vs_var,vs_out] then
  3115. s2:='R'+s2;
  3116. s:=s+s2;
  3117. end;
  3118. end
  3119. else
  3120. s:=s+'v';
  3121. cplusplusmangledname:=s;
  3122. {$else NAMEMANGLING_GCC2}
  3123. { gcc 3.x and 4.x name mangling scheme }
  3124. { see http://www.codesourcery.com/public/cxx-abi/abi.html#mangling }
  3125. if procsym.owner.symtabletype=ObjectSymtable then
  3126. begin
  3127. s:='_ZN';
  3128. s2:=tobjectdef(procsym.owner.defowner).objextname^;
  3129. s:=s+tostr(length(s2))+s2;
  3130. case proctypeoption of
  3131. potype_constructor:
  3132. s:=s+'C1';
  3133. potype_destructor:
  3134. s:=s+'D1';
  3135. else
  3136. s:=s+tostr(length(procsym.realname))+procsym.realname;
  3137. end;
  3138. s:=s+'E';
  3139. end
  3140. else
  3141. s:=procsym.realname;
  3142. { now we handle the parameters }
  3143. if maxparacount>0 then
  3144. begin
  3145. for i:=0 to paras.count-1 do
  3146. begin
  3147. hp:=tparavarsym(paras[i]);
  3148. { no hidden parameters form part of a C++ mangled name:
  3149. a) self is not included
  3150. b) there are no "high" or other hidden parameters
  3151. }
  3152. if vo_is_hidden_para in hp.varoptions then
  3153. continue;
  3154. s2:=getcppparaname(hp.vardef);
  3155. if hp.varspez in [vs_var,vs_out] then
  3156. s2:='R'+s2;
  3157. s:=s+s2;
  3158. end;
  3159. end
  3160. else
  3161. s:=s+'v';
  3162. cplusplusmangledname:=s;
  3163. {$endif NAMEMANGLING_GCC2}
  3164. end;
  3165. function tprocdef.objcmangledname : string;
  3166. var
  3167. manglednamelen: longint;
  3168. iscatmethod : boolean;
  3169. begin
  3170. if not (po_msgstr in procoptions) then
  3171. internalerror(2009030901);
  3172. { we may very well need longer strings to handle these... }
  3173. manglednamelen:=length(tobjectdef(procsym.owner.defowner).objextname^)+
  3174. length('+"[ ]"')+length(messageinf.str^);
  3175. iscatmethod:=oo_is_classhelper in tobjectdef(procsym.owner.defowner).objectoptions;
  3176. if (iscatmethod) then
  3177. inc(manglednamelen,length(tobjectdef(procsym.owner.defowner).childof.objextname^)+length('()'));
  3178. if manglednamelen>255 then
  3179. Message1(parser_e_objc_message_name_too_long,messageinf.str^);
  3180. if not(po_classmethod in procoptions) then
  3181. result:='"-['
  3182. else
  3183. result:='"+[';
  3184. { quotes are necessary because the +/- otherwise confuse the assembler
  3185. into expecting a number
  3186. }
  3187. if iscatmethod then
  3188. result:=result+tobjectdef(procsym.owner.defowner).childof.objextname^+'(';
  3189. result:=result+tobjectdef(procsym.owner.defowner).objextname^;
  3190. if iscatmethod then
  3191. result:=result+')';
  3192. result:=result+' '+messageinf.str^+']"';
  3193. end;
  3194. procedure tprocdef.setmangledname(const s : string);
  3195. begin
  3196. { This is not allowed anymore, the forward declaration
  3197. already needs to create the correct mangledname, no changes
  3198. afterwards are allowed (PFV) }
  3199. { Exception: interface definitions in mode macpas, since in that }
  3200. { case no reference to the old name can exist yet (JM) }
  3201. if assigned(_mangledname) then
  3202. if ((m_mac in current_settings.modeswitches) and
  3203. (interfacedef)) then
  3204. stringdispose(_mangledname)
  3205. else
  3206. internalerror(200411171);
  3207. {$ifdef compress}
  3208. _mangledname:=stringdup(minilzw_encode(s));
  3209. {$else}
  3210. _mangledname:=stringdup(s);
  3211. {$endif}
  3212. include(procoptions,po_has_mangledname);
  3213. end;
  3214. {***************************************************************************
  3215. TPROCVARDEF
  3216. ***************************************************************************}
  3217. constructor tprocvardef.create(level:byte);
  3218. begin
  3219. inherited create(procvardef,level);
  3220. end;
  3221. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  3222. begin
  3223. inherited ppuload(procvardef,ppufile);
  3224. { load para symtable }
  3225. parast:=tparasymtable.create(self,unknown_level);
  3226. tparasymtable(parast).ppuload(ppufile);
  3227. end;
  3228. function tprocvardef.getcopy : tstoreddef;
  3229. var
  3230. i : tcallercallee;
  3231. j : longint;
  3232. begin
  3233. result:=tprocvardef.create(parast.symtablelevel);
  3234. tprocvardef(result).returndef:=returndef;
  3235. tprocvardef(result).returndefderef:=returndefderef;
  3236. tprocvardef(result).parast:=parast.getcopy;
  3237. tprocvardef(result).savesize:=savesize;
  3238. { create paralist copy }
  3239. tprocvardef(result).paras:=tparalist.create(false);
  3240. tprocvardef(result).paras.count:=paras.count;
  3241. for j:=0 to paras.count-1 do
  3242. tprocvardef(result).paras[j]:=paras[j];
  3243. tprocvardef(result).proctypeoption:=proctypeoption;
  3244. tprocvardef(result).proccalloption:=proccalloption;
  3245. tprocvardef(result).procoptions:=procoptions;
  3246. tprocvardef(result).requiredargarea:=requiredargarea;
  3247. tprocvardef(result).maxparacount:=maxparacount;
  3248. tprocvardef(result).minparacount:=minparacount;
  3249. for i:=low(tcallercallee) to high(tcallercallee) do
  3250. tprocvardef(result).funcretloc[i]:=funcretloc[i].getcopy;
  3251. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  3252. {$ifdef m68k}
  3253. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  3254. {$endif}
  3255. end;
  3256. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3257. begin
  3258. inherited ppuwrite(ppufile);
  3259. { Write this entry }
  3260. ppufile.writeentry(ibprocvardef);
  3261. { Save the para symtable, this is taken from the interface }
  3262. tparasymtable(parast).ppuwrite(ppufile);
  3263. end;
  3264. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  3265. begin
  3266. case t of
  3267. gs_para :
  3268. GetSymtable:=parast;
  3269. else
  3270. GetSymtable:=nil;
  3271. end;
  3272. end;
  3273. function tprocvardef.size : aint;
  3274. begin
  3275. if (po_methodpointer in procoptions) and
  3276. not(po_addressonly in procoptions) then
  3277. size:=2*sizeof(pint)
  3278. else
  3279. size:=sizeof(pint);
  3280. end;
  3281. function tprocvardef.is_methodpointer:boolean;
  3282. begin
  3283. result:=(po_methodpointer in procoptions);
  3284. end;
  3285. function tprocvardef.is_addressonly:boolean;
  3286. begin
  3287. result:=not(po_methodpointer in procoptions) or
  3288. (po_addressonly in procoptions);
  3289. end;
  3290. function tprocvardef.getmangledparaname:string;
  3291. begin
  3292. result:='procvar';
  3293. end;
  3294. function tprocvardef.is_publishable : boolean;
  3295. begin
  3296. is_publishable:=(po_methodpointer in procoptions);
  3297. end;
  3298. function tprocvardef.GetTypeName : string;
  3299. var
  3300. s: string;
  3301. showhidden : boolean;
  3302. begin
  3303. {$ifdef EXTDEBUG}
  3304. showhidden:=true;
  3305. {$else EXTDEBUG}
  3306. showhidden:=false;
  3307. {$endif EXTDEBUG}
  3308. s:='<';
  3309. if po_classmethod in procoptions then
  3310. s := s+'class method type of'
  3311. else
  3312. if po_addressonly in procoptions then
  3313. s := s+'address of'
  3314. else
  3315. s := s+'procedure variable type of';
  3316. if po_local in procoptions then
  3317. s := s+' local';
  3318. if assigned(returndef) and
  3319. (returndef<>voidtype) then
  3320. s:=s+' function'+typename_paras(showhidden)+':'+returndef.GetTypeName
  3321. else
  3322. s:=s+' procedure'+typename_paras(showhidden);
  3323. if po_methodpointer in procoptions then
  3324. s := s+' of object';
  3325. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3326. end;
  3327. {***************************************************************************
  3328. TOBJECTDEF
  3329. ***************************************************************************}
  3330. constructor tobjectdef.create(ot : tobjecttyp;const n : string;c : tobjectdef);
  3331. begin
  3332. inherited create(objectdef);
  3333. fcurrent_dispid:=0;
  3334. objecttype:=ot;
  3335. objectoptions:=[];
  3336. childof:=nil;
  3337. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  3338. { create space for vmt !! }
  3339. vmtentries:=TFPList.Create;
  3340. vmt_offset:=0;
  3341. set_parent(c);
  3342. objname:=stringdup(upper(n));
  3343. objrealname:=stringdup(n);
  3344. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3345. prepareguid;
  3346. { setup implemented interfaces }
  3347. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol] then
  3348. ImplementedInterfaces:=TFPObjectList.Create(true)
  3349. else
  3350. ImplementedInterfaces:=nil;
  3351. writing_class_record_dbginfo:=false;
  3352. end;
  3353. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3354. var
  3355. i,
  3356. implintfcount : longint;
  3357. d : tderef;
  3358. ImplIntf : TImplementedInterface;
  3359. vmtentry : pvmtentry;
  3360. begin
  3361. inherited ppuload(objectdef,ppufile);
  3362. objecttype:=tobjecttyp(ppufile.getbyte);
  3363. objrealname:=stringdup(ppufile.getstring);
  3364. objname:=stringdup(upper(objrealname^));
  3365. objextname:=stringdup(ppufile.getstring);
  3366. { only used for external Objective-C classes/protocols }
  3367. if (objextname^='') then
  3368. stringdispose(objextname);
  3369. import_lib:=stringdup(ppufile.getstring);
  3370. { only used for external C++ classes }
  3371. if (import_lib^='') then
  3372. stringdispose(import_lib);
  3373. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3374. tObjectSymtable(symtable).datasize:=ppufile.getaint;
  3375. tObjectSymtable(symtable).fieldalignment:=ppufile.getbyte;
  3376. tObjectSymtable(symtable).recordalignment:=ppufile.getbyte;
  3377. vmt_offset:=ppufile.getlongint;
  3378. ppufile.getderef(childofderef);
  3379. ppufile.getsmallset(objectoptions);
  3380. { load guid }
  3381. iidstr:=nil;
  3382. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3383. begin
  3384. new(iidguid);
  3385. ppufile.getguid(iidguid^);
  3386. iidstr:=stringdup(ppufile.getstring);
  3387. end;
  3388. vmtentries:=TFPList.Create;
  3389. vmtentries.count:=ppufile.getlongint;
  3390. for i:=0 to vmtentries.count-1 do
  3391. begin
  3392. ppufile.getderef(d);
  3393. new(vmtentry);
  3394. vmtentry^.procdef:=nil;
  3395. vmtentry^.procdefderef:=d;
  3396. vmtentry^.visibility:=tvisibility(ppufile.getbyte);
  3397. vmtentries[i]:=vmtentry;
  3398. end;
  3399. { load implemented interfaces }
  3400. if objecttype in [odt_class,odt_objcclass,odt_objcprotocol] then
  3401. begin
  3402. ImplementedInterfaces:=TFPObjectList.Create(true);
  3403. implintfcount:=ppufile.getlongint;
  3404. for i:=0 to implintfcount-1 do
  3405. begin
  3406. ppufile.getderef(d);
  3407. ImplIntf:=TImplementedInterface.Create_deref(d);
  3408. ImplIntf.IOffset:=ppufile.getlongint;
  3409. ImplementedInterfaces.Add(ImplIntf);
  3410. end;
  3411. end
  3412. else
  3413. ImplementedInterfaces:=nil;
  3414. if df_copied_def in defoptions then
  3415. ppufile.getderef(cloneddefderef)
  3416. else
  3417. tObjectSymtable(symtable).ppuload(ppufile);
  3418. { handles the predefined class tobject }
  3419. { the last TOBJECT which is loaded gets }
  3420. { it ! }
  3421. if (childof=nil) and
  3422. (objecttype=odt_class) and
  3423. (objname^='TOBJECT') then
  3424. class_tobject:=self;
  3425. if (childof=nil) and
  3426. (objecttype=odt_interfacecom) and
  3427. (objname^='IUNKNOWN') then
  3428. interface_iunknown:=self;
  3429. if (childof=nil) and
  3430. (objecttype=odt_objcclass) and
  3431. (objname^='PROTOCOL') then
  3432. objc_protocoltype:=self;
  3433. writing_class_record_dbginfo:=false;
  3434. end;
  3435. destructor tobjectdef.destroy;
  3436. begin
  3437. if assigned(symtable) then
  3438. begin
  3439. symtable.free;
  3440. symtable:=nil;
  3441. end;
  3442. stringdispose(objname);
  3443. stringdispose(objrealname);
  3444. stringdispose(objextname);
  3445. stringdispose(import_lib);
  3446. stringdispose(iidstr);
  3447. if assigned(ImplementedInterfaces) then
  3448. begin
  3449. ImplementedInterfaces.free;
  3450. ImplementedInterfaces:=nil;
  3451. end;
  3452. if assigned(iidguid) then
  3453. begin
  3454. dispose(iidguid);
  3455. iidguid:=nil;
  3456. end;
  3457. if assigned(vmtentries) then
  3458. begin
  3459. resetvmtentries;
  3460. vmtentries.free;
  3461. vmtentries:=nil;
  3462. end;
  3463. if assigned(vmcallstaticinfo) then
  3464. begin
  3465. freemem(vmcallstaticinfo);
  3466. vmcallstaticinfo:=nil;
  3467. end;
  3468. inherited destroy;
  3469. end;
  3470. function tobjectdef.getcopy : tstoreddef;
  3471. var
  3472. i : longint;
  3473. begin
  3474. result:=tobjectdef.create(objecttype,objname^,childof);
  3475. { the constructor allocates a symtable which we release to avoid memory leaks }
  3476. tobjectdef(result).symtable.free;
  3477. tobjectdef(result).symtable:=symtable.getcopy;
  3478. if assigned(objname) then
  3479. tobjectdef(result).objname:=stringdup(objname^);
  3480. if assigned(objrealname) then
  3481. tobjectdef(result).objrealname:=stringdup(objrealname^);
  3482. if assigned(objextname) then
  3483. tobjectdef(result).objextname:=stringdup(objextname^);
  3484. if assigned(import_lib) then
  3485. tobjectdef(result).import_lib:=stringdup(import_lib^);
  3486. tobjectdef(result).objectoptions:=objectoptions;
  3487. include(tobjectdef(result).defoptions,df_copied_def);
  3488. tobjectdef(result).vmt_offset:=vmt_offset;
  3489. if assigned(iidguid) then
  3490. begin
  3491. new(tobjectdef(result).iidguid);
  3492. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  3493. end;
  3494. if assigned(iidstr) then
  3495. tobjectdef(result).iidstr:=stringdup(iidstr^);
  3496. if assigned(ImplementedInterfaces) then
  3497. begin
  3498. for i:=0 to ImplementedInterfaces.count-1 do
  3499. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  3500. end;
  3501. if assigned(vmtentries) then
  3502. begin
  3503. tobjectdef(result).vmtentries:=TFPList.Create;
  3504. tobjectdef(result).copyvmtentries(self);
  3505. end;
  3506. end;
  3507. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3508. var
  3509. i : longint;
  3510. vmtentry : pvmtentry;
  3511. ImplIntf : TImplementedInterface;
  3512. old_do_indirect_crc: boolean;
  3513. begin
  3514. { if class1 in unit A changes, and class2 in unit B inherits from it
  3515. (so unit B uses unit A), then unit B with class2 will be recompiled.
  3516. However, if there is also a class3 in unit C that only depends on
  3517. unit B, then unit C will not be recompiled because nothing changed
  3518. to the interface of unit B. Nevertheless, unit C can indirectly
  3519. depend on unit A via derefs, and these must be updated -> the
  3520. indirect crc keeps track of such changes. }
  3521. old_do_indirect_crc:=ppufile.do_indirect_crc;
  3522. ppufile.do_indirect_crc:=true;
  3523. inherited ppuwrite(ppufile);
  3524. ppufile.putbyte(byte(objecttype));
  3525. ppufile.putstring(objrealname^);
  3526. if assigned(objextname) then
  3527. ppufile.putstring(objextname^)
  3528. else
  3529. ppufile.putstring('');
  3530. if assigned(import_lib) then
  3531. ppufile.putstring(import_lib^)
  3532. else
  3533. ppufile.putstring('');
  3534. ppufile.putaint(tObjectSymtable(symtable).datasize);
  3535. ppufile.putbyte(tObjectSymtable(symtable).fieldalignment);
  3536. ppufile.putbyte(tObjectSymtable(symtable).recordalignment);
  3537. ppufile.putlongint(vmt_offset);
  3538. ppufile.putderef(childofderef);
  3539. ppufile.putsmallset(objectoptions);
  3540. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3541. begin
  3542. ppufile.putguid(iidguid^);
  3543. ppufile.putstring(iidstr^);
  3544. end;
  3545. ppufile.putlongint(vmtentries.count);
  3546. for i:=0 to vmtentries.count-1 do
  3547. begin
  3548. vmtentry:=pvmtentry(vmtentries[i]);
  3549. ppufile.putderef(vmtentry^.procdefderef);
  3550. ppufile.putbyte(byte(vmtentry^.visibility));
  3551. end;
  3552. if assigned(ImplementedInterfaces) then
  3553. begin
  3554. ppufile.putlongint(ImplementedInterfaces.Count);
  3555. for i:=0 to ImplementedInterfaces.Count-1 do
  3556. begin
  3557. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3558. ppufile.putderef(ImplIntf.intfdefderef);
  3559. ppufile.putlongint(ImplIntf.Ioffset);
  3560. end;
  3561. end;
  3562. if df_copied_def in defoptions then
  3563. ppufile.putderef(cloneddefderef);
  3564. ppufile.writeentry(ibobjectdef);
  3565. if not(df_copied_def in defoptions) then
  3566. tObjectSymtable(symtable).ppuwrite(ppufile);
  3567. ppufile.do_indirect_crc:=old_do_indirect_crc;
  3568. end;
  3569. function tobjectdef.GetTypeName:string;
  3570. begin
  3571. { in this case we will go in endless recursion, because then }
  3572. { there is no tsym associated yet with the def. It can occur }
  3573. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  3574. { instead of the actual type name }
  3575. if not assigned(typesym) then
  3576. result:='<Currently Parsed Class>'
  3577. else
  3578. result:=typename;
  3579. end;
  3580. procedure tobjectdef.buildderef;
  3581. var
  3582. i : longint;
  3583. vmtentry : pvmtentry;
  3584. begin
  3585. inherited buildderef;
  3586. childofderef.build(childof);
  3587. if df_copied_def in defoptions then
  3588. cloneddefderef.build(symtable.defowner)
  3589. else
  3590. tstoredsymtable(symtable).buildderef;
  3591. for i:=0 to vmtentries.count-1 do
  3592. begin
  3593. vmtentry:=pvmtentry(vmtentries[i]);
  3594. vmtentry^.procdefderef.build(vmtentry^.procdef);
  3595. end;
  3596. if assigned(ImplementedInterfaces) then
  3597. begin
  3598. for i:=0 to ImplementedInterfaces.count-1 do
  3599. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  3600. end;
  3601. end;
  3602. procedure tobjectdef.deref;
  3603. var
  3604. i : longint;
  3605. vmtentry : pvmtentry;
  3606. begin
  3607. inherited deref;
  3608. childof:=tobjectdef(childofderef.resolve);
  3609. if df_copied_def in defoptions then
  3610. begin
  3611. cloneddef:=tobjectdef(cloneddefderef.resolve);
  3612. symtable:=cloneddef.symtable.getcopy;
  3613. end
  3614. else
  3615. tstoredsymtable(symtable).deref;
  3616. for i:=0 to vmtentries.count-1 do
  3617. begin
  3618. vmtentry:=pvmtentry(vmtentries[i]);
  3619. vmtentry^.procdef:=tprocdef(vmtentry^.procdefderef.resolve);
  3620. end;
  3621. if assigned(ImplementedInterfaces) then
  3622. begin
  3623. for i:=0 to ImplementedInterfaces.count-1 do
  3624. TImplementedInterface(ImplementedInterfaces[i]).deref;
  3625. end;
  3626. end;
  3627. procedure create_class_helper_for_procdef(def: tobject; arg: pointer);
  3628. var
  3629. pd: tprocdef absolute def;
  3630. st: tsymtable;
  3631. psym: tsym;
  3632. nname: TIDString;
  3633. begin
  3634. if (tdef(def).typ<>procdef) then
  3635. exit;
  3636. { pd.owner = objcclass symtable -> defowner = objcclassdef ->
  3637. owner = symtable in which objcclassdef is defined
  3638. }
  3639. st:=pd.owner.defowner.owner;
  3640. nname:=class_helper_prefix+tprocsym(pd.procsym).name;
  3641. { check for an existing procsym with our special name }
  3642. psym:=tsym(st.find(nname));
  3643. if not assigned(psym) then
  3644. begin
  3645. psym:=tprocsym.create(nname);
  3646. { avoid warning about this symbol being unused }
  3647. psym.IncRefCount;
  3648. st.insert(psym,true);
  3649. end
  3650. else if (psym.typ<>procsym) then
  3651. internalerror(2009111501);
  3652. { add ourselves to this special procsym }
  3653. tprocsym(psym).procdeflist.add(def);
  3654. end;
  3655. procedure tobjectdef.buildderefimpl;
  3656. begin
  3657. inherited buildderefimpl;
  3658. if not (df_copied_def in defoptions) then
  3659. tstoredsymtable(symtable).buildderefimpl;
  3660. end;
  3661. procedure tobjectdef.derefimpl;
  3662. begin
  3663. inherited derefimpl;
  3664. if not (df_copied_def in defoptions) then
  3665. tstoredsymtable(symtable).derefimpl;
  3666. { the procdefs are not owned by the class helper procsyms, so they
  3667. are not stored/restored either -> re-add them here }
  3668. if (objecttype=odt_objcclass) or
  3669. (oo_is_classhelper in objectoptions) then
  3670. symtable.DefList.ForEachCall(@create_class_helper_for_procdef,nil);
  3671. end;
  3672. procedure tobjectdef.resetvmtentries;
  3673. var
  3674. i : longint;
  3675. begin
  3676. for i:=0 to vmtentries.Count-1 do
  3677. Dispose(pvmtentry(vmtentries[i]));
  3678. vmtentries.clear;
  3679. end;
  3680. procedure tobjectdef.copyvmtentries(objdef:tobjectdef);
  3681. var
  3682. i : longint;
  3683. vmtentry : pvmtentry;
  3684. begin
  3685. resetvmtentries;
  3686. vmtentries.count:=objdef.vmtentries.count;
  3687. for i:=0 to objdef.vmtentries.count-1 do
  3688. begin
  3689. new(vmtentry);
  3690. vmtentry^:=pvmtentry(objdef.vmtentries[i])^;
  3691. vmtentries[i]:=vmtentry;
  3692. end;
  3693. end;
  3694. function tobjectdef.getparentdef:tdef;
  3695. begin
  3696. { TODO: Remove getparentdef hack}
  3697. { With 2 forward declared classes with the child class before the
  3698. parent class the child class is written earlier to the ppu. Leaving it
  3699. possible to have a reference to the parent class for property overriding,
  3700. but the parent class still has the childof not resolved yet (PFV) }
  3701. if childof=nil then
  3702. childof:=tobjectdef(childofderef.resolve);
  3703. result:=childof;
  3704. end;
  3705. procedure tobjectdef.prepareguid;
  3706. begin
  3707. { set up guid }
  3708. if not assigned(iidguid) then
  3709. begin
  3710. new(iidguid);
  3711. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3712. end;
  3713. { setup iidstring }
  3714. if not assigned(iidstr) then
  3715. iidstr:=stringdup(''); { default is empty string }
  3716. end;
  3717. procedure tobjectdef.set_parent( c : tobjectdef);
  3718. begin
  3719. if assigned(childof) then
  3720. exit;
  3721. childof:=c;
  3722. if not assigned(c) then
  3723. exit;
  3724. { inherit options and status }
  3725. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  3726. { add the data of the anchestor class/object }
  3727. if (objecttype in [odt_class,odt_object,odt_objcclass]) then
  3728. begin
  3729. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize+tObjectSymtable(c.symtable).datasize;
  3730. { inherit recordalignment }
  3731. tObjectSymtable(symtable).recordalignment:=tObjectSymtable(c.symtable).recordalignment;
  3732. if (oo_has_vmt in objectoptions) and
  3733. (oo_has_vmt in c.objectoptions) then
  3734. tObjectSymtable(symtable).datasize:=tObjectSymtable(symtable).datasize-sizeof(pint);
  3735. { if parent has a vmt field then the offset is the same for the child PM }
  3736. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3737. begin
  3738. vmt_offset:=c.vmt_offset;
  3739. include(objectoptions,oo_has_vmt);
  3740. end;
  3741. end;
  3742. end;
  3743. procedure tobjectdef.insertvmt;
  3744. var
  3745. vs: tfieldvarsym;
  3746. begin
  3747. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol] then
  3748. exit;
  3749. if (oo_has_vmt in objectoptions) then
  3750. internalerror(12345)
  3751. else
  3752. begin
  3753. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  3754. tObjectSymtable(symtable).fieldalignment);
  3755. if (tf_requires_proper_alignment in target_info.flags) then
  3756. begin
  3757. { Align VMT pointer and whole object instance if target CPU requires alignment. }
  3758. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(pint));
  3759. tObjectSymtable(symtable).alignrecord(tObjectSymtable(symtable).datasize,sizeof(pint));
  3760. end;
  3761. vmt_offset:=tObjectSymtable(symtable).datasize;
  3762. vs:=tfieldvarsym.create('_vptr$'+objname^,vs_value,voidpointertype,[]);
  3763. hidesym(vs);
  3764. tObjectSymtable(symtable).insert(vs);
  3765. tObjectSymtable(symtable).addfield(vs,vis_hidden);
  3766. include(objectoptions,oo_has_vmt);
  3767. end;
  3768. end;
  3769. procedure tobjectdef.check_forwards;
  3770. begin
  3771. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcprotocol]) then
  3772. tstoredsymtable(symtable).check_forwards;
  3773. if (oo_is_forward in objectoptions) then
  3774. begin
  3775. { ok, in future, the forward can be resolved }
  3776. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3777. exclude(objectoptions,oo_is_forward);
  3778. end;
  3779. end;
  3780. { true if prot implements d (or if they are equal) }
  3781. function is_related_protocol(prot: tobjectdef; d : tdef) : boolean;
  3782. var
  3783. i : longint;
  3784. begin
  3785. { objcprotocols have multiple inheritance, all protocols from which
  3786. the current protocol inherits are stored in implementedinterfaces }
  3787. result:=prot=d;
  3788. if result then
  3789. exit;
  3790. for i:=0 to prot.ImplementedInterfaces.count-1 do
  3791. begin
  3792. result:=is_related_protocol(tobjectdef(prot.ImplementedInterfaces[i]),d);
  3793. if result then
  3794. exit;
  3795. end;
  3796. end;
  3797. { true, if self inherits from d (or if they are equal) }
  3798. function tobjectdef.is_related(d : tdef) : boolean;
  3799. var
  3800. hp : tobjectdef;
  3801. begin
  3802. if (objecttype=odt_objcprotocol) then
  3803. begin
  3804. is_related:=is_related_protocol(self,d);
  3805. exit
  3806. end;
  3807. hp:=self;
  3808. while assigned(hp) do
  3809. begin
  3810. if hp=d then
  3811. begin
  3812. is_related:=true;
  3813. exit;
  3814. end;
  3815. hp:=hp.childof;
  3816. end;
  3817. is_related:=false;
  3818. end;
  3819. function tobjectdef.find_procdef_bytype(pt:tproctypeoption): tprocdef;
  3820. var
  3821. i: longint;
  3822. sym: tsym;
  3823. begin
  3824. for i:=0 to symtable.SymList.Count-1 do
  3825. begin
  3826. sym:=tsym(symtable.SymList[i]);
  3827. if sym.typ=procsym then
  3828. begin
  3829. result:=tprocsym(sym).find_procdef_bytype(pt);
  3830. if assigned(result) then
  3831. exit;
  3832. end;
  3833. end;
  3834. result:=nil;
  3835. end;
  3836. function tobjectdef.find_destructor: tprocdef;
  3837. var
  3838. objdef: tobjectdef;
  3839. begin
  3840. objdef:=self;
  3841. while assigned(objdef) do
  3842. begin
  3843. result:=find_procdef_bytype(potype_destructor);
  3844. if assigned(result) then
  3845. exit;
  3846. objdef:=objdef.childof;
  3847. end;
  3848. result:=nil;
  3849. end;
  3850. function tobjectdef.implements_any_interfaces: boolean;
  3851. begin
  3852. result := (ImplementedInterfaces.Count > 0) or
  3853. (assigned(childof) and childof.implements_any_interfaces);
  3854. end;
  3855. function tobjectdef.size : aint;
  3856. begin
  3857. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol] then
  3858. result:=sizeof(pint)
  3859. else
  3860. result:=tObjectSymtable(symtable).datasize;
  3861. end;
  3862. function tobjectdef.alignment:shortint;
  3863. begin
  3864. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol] then
  3865. alignment:=sizeof(pint)
  3866. else
  3867. alignment:=tObjectSymtable(symtable).recordalignment;
  3868. end;
  3869. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3870. begin
  3871. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3872. case objecttype of
  3873. odt_class:
  3874. { the +2*sizeof(pint) is size and -size }
  3875. vmtmethodoffset:=(index+10)*sizeof(pint)+2*sizeof(pint);
  3876. odt_objcclass,
  3877. odt_objcprotocol:
  3878. vmtmethodoffset:=0;
  3879. odt_interfacecom,odt_interfacecorba:
  3880. vmtmethodoffset:=index*sizeof(pint);
  3881. else
  3882. {$ifdef WITHDMT}
  3883. vmtmethodoffset:=(index+4)*sizeof(pint);
  3884. {$else WITHDMT}
  3885. vmtmethodoffset:=(index+3)*sizeof(pint);
  3886. {$endif WITHDMT}
  3887. end;
  3888. end;
  3889. function tobjectdef.vmt_mangledname : string;
  3890. begin
  3891. if not(oo_has_vmt in objectoptions) then
  3892. Message1(parser_n_object_has_no_vmt,objrealname^);
  3893. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  3894. end;
  3895. function tobjectdef.needs_inittable : boolean;
  3896. begin
  3897. case objecttype of
  3898. odt_dispinterface,
  3899. odt_class :
  3900. needs_inittable:=false;
  3901. odt_interfacecom:
  3902. needs_inittable:=true;
  3903. odt_interfacecorba:
  3904. needs_inittable:=is_related(interface_iunknown);
  3905. odt_object:
  3906. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  3907. odt_cppclass,
  3908. odt_objcclass,
  3909. odt_objcprotocol:
  3910. needs_inittable:=false;
  3911. else
  3912. internalerror(200108267);
  3913. end;
  3914. end;
  3915. function tobjectdef.rtti_mangledname(rt: trttitype): string;
  3916. begin
  3917. if not(objecttype in [odt_objcclass,odt_objcprotocol]) then
  3918. result:=inherited rtti_mangledname(rt)
  3919. else
  3920. begin
  3921. { necessary in case of a dynamic array of nsobject, or
  3922. if an nsobject field appears in a record that needs
  3923. init/finalisation }
  3924. if rt=initrtti then
  3925. begin
  3926. result:=voidpointertype.rtti_mangledname(rt);
  3927. exit;
  3928. end;
  3929. if not(target_info.system in systems_objc_nfabi) then
  3930. begin
  3931. result:=target_asm.labelprefix;
  3932. case objecttype of
  3933. odt_objcclass:
  3934. begin
  3935. case rt of
  3936. objcclassrtti:
  3937. if not(oo_is_classhelper in objectoptions) then
  3938. result:=result+'_OBJC_CLASS_'
  3939. else
  3940. result:=result+'_OBJC_CATEGORY_';
  3941. objcmetartti:
  3942. if not(oo_is_classhelper in objectoptions) then
  3943. result:=result+'_OBJC_METACLASS_'
  3944. else
  3945. internalerror(2009111511);
  3946. else
  3947. internalerror(2009092302);
  3948. end;
  3949. end;
  3950. odt_objcprotocol:
  3951. result:=result+'_OBJC_PROTOCOL_';
  3952. end;
  3953. end
  3954. else
  3955. begin
  3956. case objecttype of
  3957. odt_objcclass:
  3958. begin
  3959. if (oo_is_classhelper in objectoptions) and
  3960. (rt<>objcclassrtti) then
  3961. internalerror(2009111512);
  3962. case rt of
  3963. objcclassrtti:
  3964. if not(oo_is_classhelper in objectoptions) then
  3965. result:='_OBJC_CLASS_$_'
  3966. else
  3967. result:='_OBJC_$_CATEGORY_';
  3968. objcmetartti:
  3969. result:='_OBJC_METACLASS_$_';
  3970. objcclassrortti:
  3971. result:=lower(target_asm.labelprefix)+'_OBJC_CLASS_RO_$_';
  3972. objcmetarortti:
  3973. result:=lower(target_asm.labelprefix)+'_OBJC_METACLASS_RO_$_';
  3974. else
  3975. internalerror(2009092303);
  3976. end;
  3977. end;
  3978. odt_objcprotocol:
  3979. begin
  3980. result:=lower(target_asm.labelprefix);
  3981. case rt of
  3982. objcclassrtti:
  3983. result:=result+'_OBJC_PROTOCOL_$_';
  3984. objcmetartti:
  3985. result:=result+'_OBJC_LABEL_PROTOCOL_$_';
  3986. else
  3987. internalerror(2009092501);
  3988. end;
  3989. end;
  3990. end;
  3991. end;
  3992. result:=result+objextname^;
  3993. end;
  3994. end;
  3995. function tobjectdef.members_need_inittable : boolean;
  3996. begin
  3997. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  3998. end;
  3999. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  4000. var
  4001. ImplIntf : TImplementedInterface;
  4002. i : longint;
  4003. begin
  4004. result:=nil;
  4005. if not assigned(ImplementedInterfaces) then
  4006. exit;
  4007. for i:=0 to ImplementedInterfaces.Count-1 do
  4008. begin
  4009. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  4010. if ImplIntf.intfdef=aintfdef then
  4011. begin
  4012. result:=ImplIntf;
  4013. exit;
  4014. end;
  4015. end;
  4016. end;
  4017. function tobjectdef.is_publishable : boolean;
  4018. begin
  4019. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  4020. end;
  4021. procedure tobjectdef.reset;
  4022. begin
  4023. inherited reset;
  4024. created_in_current_module:=false;
  4025. maybe_created_in_current_module:=false;
  4026. classref_created_in_current_module:=false;
  4027. end;
  4028. function tobjectdef.get_next_dispid: longint;
  4029. begin
  4030. inc(fcurrent_dispid);
  4031. result:=fcurrent_dispid;
  4032. end;
  4033. function tobjectdef.search_enumerator_get: tprocdef;
  4034. var
  4035. objdef : tobjectdef;
  4036. sym : tsym;
  4037. i : integer;
  4038. pd : tprocdef;
  4039. hashedid : THashedIDString;
  4040. begin
  4041. result:=nil;
  4042. objdef:=self;
  4043. hashedid.id:='GETENUMERATOR';
  4044. while assigned(objdef) do
  4045. begin
  4046. sym:=tsym(objdef.symtable.FindWithHash(hashedid));
  4047. if assigned(sym) and (sym.typ=procsym) then
  4048. begin
  4049. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  4050. begin
  4051. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4052. if (pd.proctypeoption = potype_function) and
  4053. is_class_or_interface_or_object(pd.returndef) and
  4054. (pd.visibility >= vis_public) then
  4055. begin
  4056. result:=pd;
  4057. exit;
  4058. end;
  4059. end;
  4060. end;
  4061. objdef:=objdef.childof;
  4062. end;
  4063. end;
  4064. function tobjectdef.search_enumerator_move: tprocdef;
  4065. var
  4066. objdef : tobjectdef;
  4067. sym : tsym;
  4068. i : integer;
  4069. pd : tprocdef;
  4070. hashedid : THashedIDString;
  4071. begin
  4072. result:=nil;
  4073. objdef:=self;
  4074. // first search for po_enumerator_movenext method modifier
  4075. // then search for public function MoveNext: Boolean
  4076. hashedid.id:='MOVENEXT';
  4077. while assigned(objdef) do
  4078. begin
  4079. for i:=0 to objdef.symtable.SymList.Count-1 do
  4080. begin
  4081. sym:=TSym(objdef.symtable.SymList[i]);
  4082. if (sym.typ=procsym) then
  4083. begin
  4084. pd:=Tprocsym(sym).find_procdef_byoptions([po_enumerator_movenext]);
  4085. if assigned(pd) then
  4086. begin
  4087. result:=pd;
  4088. exit;
  4089. end;
  4090. end;
  4091. end;
  4092. sym:=tsym(objdef.symtable.FindWithHash(hashedid));
  4093. if assigned(sym) and (sym.typ=procsym) then
  4094. begin
  4095. for i := 0 to Tprocsym(sym).ProcdefList.Count - 1 do
  4096. begin
  4097. pd := tprocdef(Tprocsym(sym).ProcdefList[i]);
  4098. if (pd.proctypeoption = potype_function) and
  4099. is_boolean(pd.returndef) and
  4100. (pd.minparacount = 0) and
  4101. (pd.visibility >= vis_public) then
  4102. begin
  4103. result:=pd;
  4104. exit;
  4105. end;
  4106. end;
  4107. end;
  4108. objdef:=objdef.childof;
  4109. end;
  4110. end;
  4111. function tobjectdef.search_enumerator_current: tsym;
  4112. var
  4113. objdef : tobjectdef;
  4114. sym: tsym;
  4115. i: integer;
  4116. hashedid : THashedIDString;
  4117. begin
  4118. result:=nil;
  4119. objdef:=self;
  4120. hashedid.id:='CURRENT';
  4121. // first search for ppo_enumerator_current property modifier
  4122. // then search for public property Current
  4123. while assigned(objdef) do
  4124. begin
  4125. for i:=0 to objdef.symtable.SymList.Count-1 do
  4126. begin
  4127. sym:=TSym(objdef.symtable.SymList[i]);
  4128. if (sym.typ=propertysym) and (ppo_enumerator_current in tpropertysym(sym).propoptions) then
  4129. begin
  4130. result:=sym;
  4131. exit;
  4132. end;
  4133. end;
  4134. sym:=tsym(objdef.symtable.FindWithHash(hashedid));
  4135. if assigned(sym) and (sym.typ=propertysym) and
  4136. (sym.visibility >= vis_public) and not tpropertysym(sym).propaccesslist[palt_read].empty then
  4137. begin
  4138. result:=sym;
  4139. exit;
  4140. end;
  4141. objdef:=objdef.childof;
  4142. end;
  4143. end;
  4144. procedure tobjectdef.register_created_classref_type;
  4145. begin
  4146. if not classref_created_in_current_module then
  4147. begin
  4148. classref_created_in_current_module:=true;
  4149. current_module.wpoinfo.addcreatedobjtypeforclassref(self);
  4150. end;
  4151. end;
  4152. procedure tobjectdef.register_created_object_type;
  4153. begin
  4154. if not created_in_current_module then
  4155. begin
  4156. created_in_current_module:=true;
  4157. current_module.wpoinfo.addcreatedobjtype(self);
  4158. end;
  4159. end;
  4160. procedure tobjectdef.register_maybe_created_object_type;
  4161. begin
  4162. { if we know it has been created for sure, no need
  4163. to also record that it maybe can be created in
  4164. this module
  4165. }
  4166. if not (created_in_current_module) and
  4167. not (maybe_created_in_current_module) then
  4168. begin
  4169. maybe_created_in_current_module:=true;
  4170. current_module.wpoinfo.addmaybecreatedbyclassref(self);
  4171. end;
  4172. end;
  4173. procedure tobjectdef.register_vmt_call(index: longint);
  4174. begin
  4175. if (is_object(self) or is_class(self)) then
  4176. current_module.wpoinfo.addcalledvmtentry(self,index);
  4177. end;
  4178. procedure make_procdef_external(data: tobject; arg: pointer);
  4179. var
  4180. def: tdef absolute data;
  4181. begin
  4182. if (def.typ = procdef) then
  4183. begin
  4184. include(tprocdef(def).procoptions,po_external);
  4185. tprocdef(def).forwarddef:=false;
  4186. end;
  4187. end;
  4188. procedure tobjectdef.make_all_methods_external;
  4189. begin
  4190. self.symtable.deflist.foreachcall(@make_procdef_external,nil);
  4191. end;
  4192. procedure check_and_finish_msg(data: tobject; arg: pointer);
  4193. var
  4194. def: tdef absolute data;
  4195. pd: tprocdef absolute data;
  4196. i,
  4197. paracount: longint;
  4198. begin
  4199. if (def.typ=procdef) then
  4200. begin
  4201. { add all messages also under a dummy name to the symtable in
  4202. which the objcclass/protocol/category is declared, so they can
  4203. be called via id.<name>
  4204. }
  4205. create_class_helper_for_procdef(pd,nil);
  4206. { we have to wait until now to set the mangled name because it
  4207. depends on the (possibly external) class name, which is defined
  4208. at the very end. }
  4209. if not(po_msgstr in pd.procoptions) then
  4210. begin
  4211. CGMessagePos(pd.fileinfo,parser_e_objc_requires_msgstr);
  4212. { recover to avoid internalerror later on }
  4213. include(pd.procoptions,po_msgstr);
  4214. pd.messageinf.str:=stringdup('MissingDeclaration');
  4215. end;
  4216. { Mangled name is already set in case this is a copy of
  4217. another type. }
  4218. if not(po_has_mangledname in pd.procoptions) then
  4219. begin
  4220. { check whether the number of formal parameters is correct,
  4221. and whether they have valid Objective-C types }
  4222. paracount:=0;
  4223. for i:=1 to length(pd.messageinf.str^) do
  4224. if pd.messageinf.str^[i]=':' then
  4225. inc(paracount);
  4226. for i:=0 to pd.paras.count-1 do
  4227. if not(vo_is_hidden_para in tparavarsym(pd.paras[i]).varoptions) and
  4228. not is_array_of_const(tparavarsym(pd.paras[i]).vardef) then
  4229. dec(paracount);
  4230. if (paracount<>0) then
  4231. MessagePos(pd.fileinfo,sym_e_objc_para_mismatch);
  4232. pd.setmangledname(pd.objcmangledname);
  4233. end
  4234. else
  4235. { all checks already done }
  4236. exit;
  4237. if not(oo_is_external in pd._class.objectoptions) then
  4238. begin
  4239. if (po_varargs in pd.procoptions) then
  4240. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external)
  4241. else
  4242. begin
  4243. { check for "array of const" parameters }
  4244. for i:=0 to pd.parast.symlist.count-1 do
  4245. begin
  4246. if (tsym(pd.parast.symlist[i]).typ=paravarsym) and
  4247. is_array_of_const(tparavarsym(pd.parast.symlist[i]).vardef) then
  4248. MessagePos(pd.fileinfo,parser_e_varargs_need_cdecl_and_external);
  4249. end;
  4250. end;
  4251. end;
  4252. end;
  4253. end;
  4254. procedure mark_private_fields_used(data: tobject; arg: pointer);
  4255. var
  4256. sym: tsym absolute data;
  4257. begin
  4258. if (sym.typ=fieldvarsym) and
  4259. (tfieldvarsym(sym).visibility in [vis_private,vis_strictprivate]) then
  4260. sym.IncRefCount;
  4261. end;
  4262. procedure tobjectdef.finish_objc_data;
  4263. begin
  4264. self.symtable.DefList.foreachcall(@check_and_finish_msg,nil);
  4265. if (oo_is_external in objectoptions) then
  4266. self.symtable.SymList.ForEachCall(@mark_private_fields_used,nil);
  4267. end;
  4268. procedure verify_objc_vardef(data: tobject; arg: pointer);
  4269. var
  4270. sym: tabstractvarsym absolute data;
  4271. res: pboolean absolute arg;
  4272. founderrordef: tdef;
  4273. begin
  4274. if not(tsym(data).typ in [paravarsym,fieldvarsym]) then
  4275. exit;
  4276. if (sym.typ=paravarsym) and
  4277. ((vo_is_hidden_para in tparavarsym(sym).varoptions) or
  4278. is_array_of_const(tparavarsym(sym).vardef)) then
  4279. exit;
  4280. if not objcchecktype(sym.vardef,founderrordef) then
  4281. begin
  4282. MessagePos1(sym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  4283. res^:=false;
  4284. end;
  4285. end;
  4286. procedure verify_objc_procdef_paras(data: tobject; arg: pointer);
  4287. var
  4288. def: tdef absolute data;
  4289. res: pboolean absolute arg;
  4290. founderrordef: tdef;
  4291. begin
  4292. if (def.typ<>procdef) then
  4293. exit;
  4294. { check parameter types for validity }
  4295. tprocdef(def).paras.foreachcall(@verify_objc_vardef,arg);
  4296. { check the result type for validity }
  4297. if not objcchecktype(tprocdef(def).returndef,founderrordef) then
  4298. begin
  4299. MessagePos1(tprocdef(def).funcretsym.fileinfo,type_e_objc_type_unsupported,founderrordef.typename);
  4300. res^:=false;
  4301. end;
  4302. end;
  4303. function tobjectdef.check_objc_types: boolean;
  4304. begin
  4305. { done in separate step from finish_objc_data, because when
  4306. finish_objc_data is called, not all forwarddefs have been resolved
  4307. yet and we need to know all types here }
  4308. result:=true;
  4309. self.symtable.symlist.foreachcall(@verify_objc_vardef,@result);
  4310. self.symtable.deflist.foreachcall(@verify_objc_procdef_paras,@result);
  4311. end;
  4312. procedure do_cpp_import_info(data: tobject; arg: pointer);
  4313. var
  4314. def: tdef absolute data;
  4315. pd: tprocdef absolute data;
  4316. begin
  4317. if (def.typ=procdef) then
  4318. begin
  4319. pd.setmangledname(target_info.Cprefix+pd.cplusplusmangledname);
  4320. if (oo_is_external in pd._class.objectoptions) then
  4321. begin
  4322. { copied from psub.read_proc }
  4323. if assigned(pd._class.import_lib) then
  4324. current_module.AddExternalImport(pd._class.import_lib^,pd.mangledname,0,false,false)
  4325. else
  4326. begin
  4327. { add import name to external list for DLL scanning }
  4328. if tf_has_dllscanner in target_info.flags then
  4329. current_module.dllscannerinputlist.Add(pd.mangledname,pd);
  4330. end;
  4331. end;
  4332. end;
  4333. end;
  4334. procedure tobjectdef.finish_cpp_data;
  4335. begin
  4336. self.symtable.DefList.ForEachCall(@do_cpp_import_info,nil);
  4337. end;
  4338. function tobjectdef.RttiName: string;
  4339. var
  4340. tmp: tobjectdef;
  4341. begin
  4342. Result:=objrealname^;
  4343. tmp:=self;
  4344. repeat
  4345. if tmp.owner.symtabletype=ObjectSymtable then
  4346. tmp:=tobjectdef(tmp.owner.defowner)
  4347. else
  4348. break;
  4349. Result:=tmp.objrealname^+'.'+Result;
  4350. until tmp=nil;
  4351. end;
  4352. {****************************************************************************
  4353. TImplementedInterface
  4354. ****************************************************************************}
  4355. constructor TImplementedInterface.create(aintf: tobjectdef);
  4356. begin
  4357. inherited create;
  4358. intfdef:=aintf;
  4359. IOffset:=-1;
  4360. IType:=etStandard;
  4361. NameMappings:=nil;
  4362. procdefs:=nil;
  4363. end;
  4364. constructor TImplementedInterface.create_deref(d:tderef);
  4365. begin
  4366. inherited create;
  4367. intfdef:=nil;
  4368. intfdefderef:=d;
  4369. IOffset:=-1;
  4370. IType:=etStandard;
  4371. NameMappings:=nil;
  4372. procdefs:=nil;
  4373. end;
  4374. destructor TImplementedInterface.destroy;
  4375. var
  4376. i : longint;
  4377. mappedname : pshortstring;
  4378. begin
  4379. if assigned(NameMappings) then
  4380. begin
  4381. for i:=0 to NameMappings.Count-1 do
  4382. begin
  4383. mappedname:=pshortstring(NameMappings[i]);
  4384. stringdispose(mappedname);
  4385. end;
  4386. NameMappings.free;
  4387. NameMappings:=nil;
  4388. end;
  4389. if assigned(procdefs) then
  4390. begin
  4391. procdefs.free;
  4392. procdefs:=nil;
  4393. end;
  4394. inherited destroy;
  4395. end;
  4396. procedure TImplementedInterface.buildderef;
  4397. begin
  4398. intfdefderef.build(intfdef);
  4399. end;
  4400. procedure TImplementedInterface.deref;
  4401. begin
  4402. intfdef:=tobjectdef(intfdefderef.resolve);
  4403. end;
  4404. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  4405. begin
  4406. if not assigned(NameMappings) then
  4407. NameMappings:=TFPHashList.Create;
  4408. NameMappings.Add(origname,stringdup(newname));
  4409. end;
  4410. function TImplementedInterface.GetMapping(const origname: string):string;
  4411. var
  4412. mappedname : pshortstring;
  4413. begin
  4414. result:='';
  4415. if not assigned(NameMappings) then
  4416. exit;
  4417. mappedname:=PShortstring(NameMappings.Find(origname));
  4418. if assigned(mappedname) then
  4419. result:=mappedname^;
  4420. end;
  4421. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  4422. begin
  4423. if not assigned(procdefs) then
  4424. procdefs:=TFPObjectList.Create(false);
  4425. { duplicate entries must be stored, because multiple }
  4426. { interfaces can declare methods with the same name }
  4427. { and all of these get their own VMT entry }
  4428. procdefs.Add(pd);
  4429. end;
  4430. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  4431. var
  4432. i : longint;
  4433. begin
  4434. result:=false;
  4435. { interfaces being implemented through delegation are not mergable (FK) }
  4436. if (IType<>etStandard) or (MergingIntf.IType<>etStandard) or not(assigned(ProcDefs)) then
  4437. exit;
  4438. weight:=0;
  4439. { empty interface is mergeable }
  4440. if ProcDefs.Count=0 then
  4441. begin
  4442. result:=true;
  4443. exit;
  4444. end;
  4445. { The interface to merge must at least the number of
  4446. procedures of this interface }
  4447. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  4448. exit;
  4449. for i:=0 to ProcDefs.Count-1 do
  4450. begin
  4451. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  4452. exit;
  4453. end;
  4454. weight:=ProcDefs.Count;
  4455. result:=true;
  4456. end;
  4457. function TImplementedInterface.getcopy:TImplementedInterface;
  4458. begin
  4459. Result:=TImplementedInterface.Create(nil);
  4460. {$warning: this is completely wrong on so many levels...}
  4461. { 1) the procdefs list will be freed once for each copy
  4462. 2) since the procdefs list owns its elements, those will also be freed for each copy
  4463. 3) idem for the name mappings
  4464. }
  4465. Move(pointer(self)^,pointer(result)^,InstanceSize);
  4466. end;
  4467. {****************************************************************************
  4468. TFORWARDDEF
  4469. ****************************************************************************}
  4470. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  4471. begin
  4472. inherited create(forwarddef);
  4473. tosymname:=stringdup(s);
  4474. forwardpos:=pos;
  4475. end;
  4476. function tforwarddef.GetTypeName:string;
  4477. begin
  4478. GetTypeName:='unresolved forward to '+tosymname^;
  4479. end;
  4480. destructor tforwarddef.destroy;
  4481. begin
  4482. stringdispose(tosymname);
  4483. inherited destroy;
  4484. end;
  4485. {****************************************************************************
  4486. TUNDEFINEDDEF
  4487. ****************************************************************************}
  4488. constructor tundefineddef.create;
  4489. begin
  4490. inherited create(undefineddef);
  4491. end;
  4492. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  4493. begin
  4494. inherited ppuload(undefineddef,ppufile);
  4495. end;
  4496. function tundefineddef.GetTypeName:string;
  4497. begin
  4498. GetTypeName:='<undefined type>';
  4499. end;
  4500. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  4501. begin
  4502. inherited ppuwrite(ppufile);
  4503. ppufile.writeentry(ibundefineddef);
  4504. end;
  4505. {****************************************************************************
  4506. TERRORDEF
  4507. ****************************************************************************}
  4508. constructor terrordef.create;
  4509. begin
  4510. inherited create(errordef);
  4511. { prevent consecutive faults }
  4512. savesize:=1;
  4513. end;
  4514. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  4515. begin
  4516. { Can't write errordefs to ppu }
  4517. internalerror(200411063);
  4518. end;
  4519. function terrordef.GetTypeName:string;
  4520. begin
  4521. GetTypeName:='<erroneous type>';
  4522. end;
  4523. function terrordef.getmangledparaname:string;
  4524. begin
  4525. getmangledparaname:='error';
  4526. end;
  4527. {****************************************************************************
  4528. Definition Helpers
  4529. ****************************************************************************}
  4530. function is_interfacecom(def: tdef): boolean;
  4531. begin
  4532. is_interfacecom:=
  4533. assigned(def) and
  4534. (def.typ=objectdef) and
  4535. (tobjectdef(def).objecttype=odt_interfacecom);
  4536. end;
  4537. function is_interfacecorba(def: tdef): boolean;
  4538. begin
  4539. is_interfacecorba:=
  4540. assigned(def) and
  4541. (def.typ=objectdef) and
  4542. (tobjectdef(def).objecttype=odt_interfacecorba);
  4543. end;
  4544. function is_interface(def: tdef): boolean;
  4545. begin
  4546. is_interface:=
  4547. assigned(def) and
  4548. (def.typ=objectdef) and
  4549. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  4550. end;
  4551. function is_dispinterface(def: tdef): boolean;
  4552. begin
  4553. result:=
  4554. assigned(def) and
  4555. (def.typ=objectdef) and
  4556. (tobjectdef(def).objecttype=odt_dispinterface);
  4557. end;
  4558. function is_class(def: tdef): boolean;
  4559. begin
  4560. is_class:=
  4561. assigned(def) and
  4562. (def.typ=objectdef) and
  4563. (tobjectdef(def).objecttype=odt_class);
  4564. end;
  4565. function is_object(def: tdef): boolean;
  4566. begin
  4567. is_object:=
  4568. assigned(def) and
  4569. (def.typ=objectdef) and
  4570. (tobjectdef(def).objecttype=odt_object);
  4571. end;
  4572. function is_cppclass(def: tdef): boolean;
  4573. begin
  4574. is_cppclass:=
  4575. assigned(def) and
  4576. (def.typ=objectdef) and
  4577. (tobjectdef(def).objecttype=odt_cppclass);
  4578. end;
  4579. function is_objcclass(def: tdef): boolean;
  4580. begin
  4581. is_objcclass:=
  4582. assigned(def) and
  4583. (def.typ=objectdef) and
  4584. (tobjectdef(def).objecttype=odt_objcclass);
  4585. end;
  4586. function is_objcclassref(def: tdef): boolean;
  4587. begin
  4588. is_objcclassref:=
  4589. assigned(def) and
  4590. (def.typ=classrefdef) and
  4591. is_objcclass(tclassrefdef(def).pointeddef);
  4592. end;
  4593. function is_objcprotocol(def: tdef): boolean;
  4594. begin
  4595. result:=
  4596. assigned(def) and
  4597. (def.typ=objectdef) and
  4598. (tobjectdef(def).objecttype=odt_objcprotocol);
  4599. end;
  4600. function is_objccategory(def: tdef): boolean;
  4601. begin
  4602. result:=
  4603. assigned(def) and
  4604. (def.typ=objectdef) and
  4605. { if used as a forward type }
  4606. ((tobjectdef(def).objecttype=odt_objccategory) or
  4607. { if used as after it has been resolved }
  4608. ((tobjectdef(def).objecttype=odt_objcclass) and
  4609. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  4610. end;
  4611. function is_objc_class_or_protocol(def: tdef): boolean;
  4612. begin
  4613. result:=
  4614. assigned(def) and
  4615. (def.typ=objectdef) and
  4616. (tobjectdef(def).objecttype in [odt_objcclass,odt_objcprotocol]);
  4617. end;
  4618. function is_objc_protocol_or_category(def: tdef): boolean;
  4619. begin
  4620. result:=
  4621. assigned(def) and
  4622. (def.typ=objectdef) and
  4623. ((tobjectdef(def).objecttype = odt_objcprotocol) or
  4624. ((tobjectdef(def).objecttype = odt_objcclass) and
  4625. (oo_is_classhelper in tobjectdef(def).objectoptions)));
  4626. end;
  4627. function is_class_or_interface(def: tdef): boolean;
  4628. begin
  4629. result:=
  4630. assigned(def) and
  4631. (def.typ=objectdef) and
  4632. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  4633. end;
  4634. function is_class_or_interface_or_objc(def: tdef): boolean;
  4635. begin
  4636. result:=
  4637. assigned(def) and
  4638. (def.typ=objectdef) and
  4639. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_objcclass,odt_objcprotocol]);
  4640. end;
  4641. function is_class_or_interface_or_object(def: tdef): boolean;
  4642. begin
  4643. result:=
  4644. assigned(def) and
  4645. (def.typ=objectdef) and
  4646. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_object]);
  4647. end;
  4648. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  4649. begin
  4650. result:=
  4651. assigned(def) and
  4652. (def.typ=objectdef) and
  4653. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  4654. end;
  4655. function is_class_or_interface_or_dispinterface_or_objc(def: tdef): boolean;
  4656. begin
  4657. result:=
  4658. assigned(def) and
  4659. (def.typ=objectdef) and
  4660. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol]);
  4661. end;
  4662. function is_class_or_object(def: tdef): boolean;
  4663. begin
  4664. result:=
  4665. assigned(def) and
  4666. (def.typ=objectdef) and
  4667. (tobjectdef(def).objecttype in [odt_class,odt_object]);
  4668. end;
  4669. procedure loadobjctypes;
  4670. begin
  4671. objc_metaclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_CLASS').typedef);
  4672. objc_superclasstype:=tpointerdef(search_named_unit_globaltype('OBJC','POBJC_SUPER').typedef);
  4673. objc_idtype:=tpointerdef(search_named_unit_globaltype('OBJC','ID').typedef);
  4674. objc_seltype:=tpointerdef(search_named_unit_globaltype('OBJC','SEL').typedef);
  4675. objc_objecttype:=trecorddef(search_named_unit_globaltype('OBJC','OBJC_OBJECT').typedef);
  4676. end;
  4677. function use_vectorfpu(def : tdef) : boolean;
  4678. begin
  4679. {$ifdef x86}
  4680. {$define use_vectorfpuimplemented}
  4681. use_vectorfpu:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  4682. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  4683. {$endif x86}
  4684. {$ifdef arm}
  4685. {$define use_vectorfpuimplemented}
  4686. use_vectorfpu:=(current_settings.fputype in vfp_scalar);
  4687. {$endif arm}
  4688. {$ifndef use_vectorfpuimplemented}
  4689. use_vectorfpu:=false;
  4690. {$endif}
  4691. end;
  4692. end.