symdef.pas 169 KB

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