symdef.pas 165 KB

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