symdef.pas 167 KB

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