symdef.pas 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400
  1. {
  2. Symbol table implementation for the definitions
  3. Copyright (c) 1998-2005 by Florian Klaempfl, Pierre Muller
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symdef;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,
  23. { global }
  24. globtype,globals,tokens,
  25. { symtable }
  26. symconst,symbase,symtype,
  27. { ppu }
  28. ppu,
  29. { node }
  30. node,
  31. { aasm }
  32. aasmbase,aasmtai,aasmdata,
  33. cpubase,cpuinfo,
  34. cgbase,cgutils,
  35. parabase
  36. ;
  37. type
  38. {************************************************
  39. TDef
  40. ************************************************}
  41. { tstoreddef }
  42. tstoreddef = class(tdef)
  43. protected
  44. typesymderef : tderef;
  45. public
  46. {$ifdef EXTDEBUG}
  47. fileinfo : tfileposinfo;
  48. {$endif}
  49. { generic support }
  50. genericdef : tstoreddef;
  51. genericdefderef : tderef;
  52. generictokenbuf : tdynamicarray;
  53. constructor create(dt:tdeftyp);
  54. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  55. destructor destroy;override;
  56. procedure reset;virtual;
  57. function getcopy : tstoreddef;virtual;
  58. procedure ppuwrite(ppufile:tcompilerppufile);virtual;
  59. procedure buildderef;override;
  60. procedure buildderefimpl;override;
  61. procedure deref;override;
  62. procedure derefimpl;override;
  63. function size:aint;override;
  64. function getvardef:longint;override;
  65. function alignment:shortint;override;
  66. function is_publishable : boolean;override;
  67. function needs_inittable : boolean;override;
  68. function rtti_mangledname(rt:trttitype):string;override;
  69. { regvars }
  70. function is_intregable : boolean;
  71. function is_fpuregable : boolean;
  72. { generics }
  73. procedure initgeneric;
  74. private
  75. savesize : aint;
  76. end;
  77. tfiletyp = (ft_text,ft_typed,ft_untyped);
  78. tfiledef = class(tstoreddef)
  79. filetyp : tfiletyp;
  80. typedfiledef : tdef;
  81. typedfiledefderef : tderef;
  82. constructor createtext;
  83. constructor createuntyped;
  84. constructor createtyped(def : tdef);
  85. constructor ppuload(ppufile:tcompilerppufile);
  86. function getcopy : tstoreddef;override;
  87. procedure ppuwrite(ppufile:tcompilerppufile);override;
  88. procedure buildderef;override;
  89. procedure deref;override;
  90. function GetTypeName:string;override;
  91. function getmangledparaname:string;override;
  92. procedure setsize;
  93. end;
  94. tvariantdef = class(tstoreddef)
  95. varianttype : tvarianttype;
  96. constructor create(v : tvarianttype);
  97. constructor ppuload(ppufile:tcompilerppufile);
  98. function getcopy : tstoreddef;override;
  99. function GetTypeName:string;override;
  100. procedure ppuwrite(ppufile:tcompilerppufile);override;
  101. function getvardef:longint;override;
  102. procedure setsize;
  103. function is_publishable : boolean;override;
  104. function needs_inittable : boolean;override;
  105. end;
  106. tformaldef = class(tstoreddef)
  107. constructor create;
  108. constructor ppuload(ppufile:tcompilerppufile);
  109. procedure ppuwrite(ppufile:tcompilerppufile);override;
  110. function GetTypeName:string;override;
  111. end;
  112. tforwarddef = class(tstoreddef)
  113. tosymname : pshortstring;
  114. forwardpos : tfileposinfo;
  115. constructor create(const s:string;const pos : tfileposinfo);
  116. destructor destroy;override;
  117. function GetTypeName:string;override;
  118. end;
  119. tundefineddef = class(tstoreddef)
  120. constructor create;
  121. constructor ppuload(ppufile:tcompilerppufile);
  122. procedure ppuwrite(ppufile:tcompilerppufile);override;
  123. function GetTypeName:string;override;
  124. end;
  125. terrordef = class(tstoreddef)
  126. constructor create;
  127. procedure ppuwrite(ppufile:tcompilerppufile);override;
  128. function GetTypeName:string;override;
  129. function getmangledparaname : string;override;
  130. end;
  131. tabstractpointerdef = class(tstoreddef)
  132. pointeddef : tdef;
  133. pointeddefderef : tderef;
  134. constructor create(dt:tdeftyp;def:tdef);
  135. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  136. procedure ppuwrite(ppufile:tcompilerppufile);override;
  137. procedure buildderef;override;
  138. procedure deref;override;
  139. end;
  140. tpointerdef = class(tabstractpointerdef)
  141. is_far : boolean;
  142. constructor create(def:tdef);
  143. constructor createfar(def:tdef);
  144. function getcopy : tstoreddef;override;
  145. constructor ppuload(ppufile:tcompilerppufile);
  146. procedure ppuwrite(ppufile:tcompilerppufile);override;
  147. function GetTypeName:string;override;
  148. end;
  149. tabstractrecorddef= class(tstoreddef)
  150. symtable : TSymtable;
  151. procedure reset;override;
  152. function GetSymtable(t:tGetSymtable):TSymtable;override;
  153. function is_packed:boolean;
  154. end;
  155. trecorddef = class(tabstractrecorddef)
  156. public
  157. isunion : boolean;
  158. constructor create(p : TSymtable);
  159. constructor ppuload(ppufile:tcompilerppufile);
  160. destructor destroy;override;
  161. function getcopy : tstoreddef;override;
  162. procedure ppuwrite(ppufile:tcompilerppufile);override;
  163. procedure buildderef;override;
  164. procedure deref;override;
  165. function size:aint;override;
  166. function alignment : shortint;override;
  167. function padalignment: shortint;
  168. function GetTypeName:string;override;
  169. { debug }
  170. function needs_inittable : boolean;override;
  171. end;
  172. tprocdef = class;
  173. tobjectdef = class;
  174. { TImplementedInterface }
  175. TImplementedInterface = class
  176. IntfDef : tobjectdef;
  177. IntfDefDeref : tderef;
  178. IType : tinterfaceentrytype;
  179. IOffset : longint;
  180. VtblImplIntf : TImplementedInterface;
  181. NameMappings : TFPHashList;
  182. ProcDefs : TFPObjectList;
  183. // FieldOffset can be merged with IOffset. But then, fpc is not allowed to genrate a vmtentry.
  184. // Right now, fpc generate an entry for all implemented interfaces (but it should just for etStandard ones)
  185. // - Ivo Steinmann
  186. FieldOffset : longint;
  187. constructor create(aintf: tobjectdef);
  188. constructor create_deref(d:tderef);
  189. destructor destroy; override;
  190. function getcopy:TImplementedInterface;
  191. procedure buildderef;
  192. procedure deref;
  193. procedure AddMapping(const origname, newname: string);
  194. function GetMapping(const origname: string):string;
  195. procedure AddImplProc(pd:tprocdef);
  196. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  197. end;
  198. { tobjectdef }
  199. tobjectdef = class(tabstractrecorddef)
  200. public
  201. dwarf_struct_lab : tasmsymbol;
  202. childof : tobjectdef;
  203. childofderef : tderef;
  204. objname,
  205. objrealname : pshortstring;
  206. objectoptions : tobjectoptions;
  207. { to be able to have a variable vmt position }
  208. { and no vmt field for objects without virtuals }
  209. vmtentries : TFPObjectList;
  210. vmt_offset : longint;
  211. writing_class_record_dbginfo : boolean;
  212. objecttype : tobjecttyp;
  213. iidguid : pguid;
  214. iidstr : pshortstring;
  215. { store implemented interfaces defs and name mappings }
  216. ImplementedInterfaces : TFPObjectList;
  217. constructor create(ot : tobjecttyp;const n : string;c : tobjectdef);
  218. constructor ppuload(ppufile:tcompilerppufile);
  219. destructor destroy;override;
  220. function getcopy : tstoreddef;override;
  221. procedure ppuwrite(ppufile:tcompilerppufile);override;
  222. function GetTypeName:string;override;
  223. procedure buildderef;override;
  224. procedure deref;override;
  225. function getparentdef:tdef;override;
  226. function size : aint;override;
  227. function alignment:shortint;override;
  228. function vmtmethodoffset(index:longint):longint;
  229. function members_need_inittable : boolean;
  230. function find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  231. { this should be called when this class implements an interface }
  232. procedure prepareguid;
  233. function is_publishable : boolean;override;
  234. function needs_inittable : boolean;override;
  235. function vmt_mangledname : string;
  236. procedure check_forwards;
  237. function is_related(d : tdef) : boolean;override;
  238. procedure insertvmt;
  239. procedure set_parent(c : tobjectdef);
  240. function FindDestructor : tprocdef;
  241. end;
  242. tclassrefdef = class(tabstractpointerdef)
  243. constructor create(def:tdef);
  244. constructor ppuload(ppufile:tcompilerppufile);
  245. procedure ppuwrite(ppufile:tcompilerppufile);override;
  246. function GetTypeName:string;override;
  247. function is_publishable : boolean;override;
  248. end;
  249. tarraydef = class(tstoreddef)
  250. lowrange,
  251. highrange : aint;
  252. rangedef : tdef;
  253. rangedefderef : tderef;
  254. arrayoptions : tarraydefoptions;
  255. protected
  256. _elementdef : tdef;
  257. _elementdefderef : tderef;
  258. procedure setelementdef(def:tdef);
  259. public
  260. function elesize : aint;
  261. function elepackedbitsize : aint;
  262. function elecount : aword;
  263. constructor create_from_pointer(def:tdef);
  264. constructor create(l,h : aint;def:tdef);
  265. constructor ppuload(ppufile:tcompilerppufile);
  266. function getcopy : tstoreddef;override;
  267. procedure ppuwrite(ppufile:tcompilerppufile);override;
  268. function GetTypeName:string;override;
  269. function getmangledparaname : string;override;
  270. procedure buildderef;override;
  271. procedure deref;override;
  272. function size : aint;override;
  273. function alignment : shortint;override;
  274. { returns the label of the range check string }
  275. function needs_inittable : boolean;override;
  276. property elementdef : tdef read _elementdef write setelementdef;
  277. end;
  278. torddef = class(tstoreddef)
  279. low,high : TConstExprInt;
  280. ordtype : tordtype;
  281. constructor create(t : tordtype;v,b : TConstExprInt);
  282. constructor ppuload(ppufile:tcompilerppufile);
  283. function getcopy : tstoreddef;override;
  284. procedure ppuwrite(ppufile:tcompilerppufile);override;
  285. function is_publishable : boolean;override;
  286. function GetTypeName:string;override;
  287. function alignment:shortint;override;
  288. procedure setsize;
  289. function packedbitsize: aint; override;
  290. function getvardef : longint;override;
  291. end;
  292. tfloatdef = class(tstoreddef)
  293. floattype : tfloattype;
  294. constructor create(t : tfloattype);
  295. constructor ppuload(ppufile:tcompilerppufile);
  296. function getcopy : tstoreddef;override;
  297. procedure ppuwrite(ppufile:tcompilerppufile);override;
  298. function GetTypeName:string;override;
  299. function is_publishable : boolean;override;
  300. function alignment:shortint;override;
  301. procedure setsize;
  302. function getvardef:longint;override;
  303. end;
  304. tabstractprocdef = class(tstoreddef)
  305. { saves a definition to the return type }
  306. returndef : tdef;
  307. returndefderef : tderef;
  308. parast : TSymtable;
  309. paras : tparalist;
  310. proctypeoption : tproctypeoption;
  311. proccalloption : tproccalloption;
  312. procoptions : tprocoptions;
  313. requiredargarea : aint;
  314. { number of user visibile parameters }
  315. maxparacount,
  316. minparacount : byte;
  317. {$ifdef i386}
  318. fpu_used : longint; { how many stack fpu must be empty }
  319. {$endif i386}
  320. {$ifdef m68k}
  321. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  322. {$endif}
  323. funcretloc : array[tcallercallee] of TLocation;
  324. has_paraloc_info : boolean; { paraloc info is available }
  325. constructor create(dt:tdeftyp;level:byte);
  326. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  327. destructor destroy;override;
  328. procedure ppuwrite(ppufile:tcompilerppufile);override;
  329. procedure buildderef;override;
  330. procedure deref;override;
  331. procedure calcparas;
  332. function typename_paras(showhidden:boolean): string;
  333. procedure test_if_fpu_result;
  334. function is_methodpointer:boolean;virtual;
  335. function is_addressonly:boolean;virtual;
  336. private
  337. procedure count_para(p:TObject;arg:pointer);
  338. procedure insert_para(p:TObject;arg:pointer);
  339. end;
  340. tprocvardef = class(tabstractprocdef)
  341. constructor create(level:byte);
  342. constructor ppuload(ppufile:tcompilerppufile);
  343. function getcopy : tstoreddef;override;
  344. procedure ppuwrite(ppufile:tcompilerppufile);override;
  345. function GetSymtable(t:tGetSymtable):TSymtable;override;
  346. function size : aint;override;
  347. function GetTypeName:string;override;
  348. function is_publishable : boolean;override;
  349. function is_methodpointer:boolean;override;
  350. function is_addressonly:boolean;override;
  351. function getmangledparaname:string;override;
  352. end;
  353. tmessageinf = record
  354. case integer of
  355. 0 : (str : pshortstring);
  356. 1 : (i : longint);
  357. end;
  358. tinlininginfo = record
  359. { node tree }
  360. code : tnode;
  361. flags : tprocinfoflags;
  362. end;
  363. pinlininginfo = ^tinlininginfo;
  364. {$ifdef oldregvars}
  365. { register variables }
  366. pregvarinfo = ^tregvarinfo;
  367. tregvarinfo = record
  368. regvars : array[1..maxvarregs] of tsym;
  369. regvars_para : array[1..maxvarregs] of boolean;
  370. regvars_refs : array[1..maxvarregs] of longint;
  371. fpuregvars : array[1..maxfpuvarregs] of tsym;
  372. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  373. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  374. end;
  375. {$endif oldregvars}
  376. tprocdef = class(tabstractprocdef)
  377. private
  378. _mangledname : pshortstring;
  379. public
  380. messageinf : tmessageinf;
  381. dispid : longint;
  382. extnumber : word;
  383. {$ifndef EXTDEBUG}
  384. { where is this function defined and what were the symbol
  385. flags, needed here because there
  386. is only one symbol for all overloaded functions
  387. EXTDEBUG has fileinfo in tdef (PFV) }
  388. fileinfo : tfileposinfo;
  389. {$endif}
  390. symoptions : tsymoptions;
  391. { symbol owning this definition }
  392. procsym : tsym;
  393. procsymderef : tderef;
  394. { alias names }
  395. aliasnames : TCmdStrList;
  396. { symtables }
  397. localst : TSymtable;
  398. funcretsym : tsym;
  399. funcretsymderef : tderef;
  400. _class : tobjectdef;
  401. _classderef : tderef;
  402. {$if defined(powerpc) or defined(m68k)}
  403. { library symbol for AmigaOS/MorphOS }
  404. libsym : tsym;
  405. libsymderef : tderef;
  406. {$endif powerpc or m68k}
  407. { name of the result variable to insert in the localsymtable }
  408. resultname : pshortstring;
  409. { true, if the procedure is only declared
  410. (forward procedure) }
  411. forwarddef,
  412. { true if the procedure is declared in the interface }
  413. interfacedef : boolean;
  414. { true if the procedure has a forward declaration }
  415. hasforward : boolean;
  416. { import info }
  417. import_dll,
  418. import_name : pshortstring;
  419. import_nr : word;
  420. { info for inlining the subroutine, if this pointer is nil,
  421. the procedure can't be inlined }
  422. inlininginfo : pinlininginfo;
  423. {$ifdef oldregvars}
  424. regvarinfo: pregvarinfo;
  425. {$endif oldregvars}
  426. { position in aasmoutput list }
  427. procstarttai,
  428. procendtai : tai;
  429. constructor create(level:byte);
  430. constructor ppuload(ppufile:tcompilerppufile);
  431. destructor destroy;override;
  432. procedure ppuwrite(ppufile:tcompilerppufile);override;
  433. procedure buildderef;override;
  434. procedure buildderefimpl;override;
  435. procedure deref;override;
  436. procedure derefimpl;override;
  437. procedure reset;override;
  438. function GetSymtable(t:tGetSymtable):TSymtable;override;
  439. function GetTypeName : string;override;
  440. function mangledname : string;
  441. procedure setmangledname(const s : string);
  442. function fullprocname(showhidden:boolean):string;
  443. function cplusplusmangledname : string;
  444. function is_methodpointer:boolean;override;
  445. function is_addressonly:boolean;override;
  446. function is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
  447. end;
  448. { single linked list of overloaded procs }
  449. pprocdeflist = ^tprocdeflist;
  450. tprocdeflist = record
  451. def : tprocdef;
  452. defderef : tderef;
  453. next : pprocdeflist;
  454. end;
  455. tstringdef = class(tstoreddef)
  456. stringtype : tstringtype;
  457. len : aint;
  458. constructor createshort(l : byte);
  459. constructor loadshort(ppufile:tcompilerppufile);
  460. constructor createlong(l : aint);
  461. constructor loadlong(ppufile:tcompilerppufile);
  462. constructor createansi(l : aint);
  463. constructor loadansi(ppufile:tcompilerppufile);
  464. constructor createwide(l : aint);
  465. constructor loadwide(ppufile:tcompilerppufile);
  466. function getcopy : tstoreddef;override;
  467. function stringtypname:string;
  468. procedure ppuwrite(ppufile:tcompilerppufile);override;
  469. function GetTypeName:string;override;
  470. function getmangledparaname:string;override;
  471. function is_publishable : boolean;override;
  472. function alignment : shortint;override;
  473. function needs_inittable : boolean;override;
  474. function getvardef:longint;override;
  475. end;
  476. tenumdef = class(tstoreddef)
  477. minval,
  478. maxval : aint;
  479. has_jumps : boolean;
  480. firstenum : tsym; {tenumsym}
  481. basedef : tenumdef;
  482. basedefderef : tderef;
  483. constructor create;
  484. constructor create_subrange(_basedef:tenumdef;_min,_max:aint);
  485. constructor ppuload(ppufile:tcompilerppufile);
  486. function getcopy : tstoreddef;override;
  487. procedure ppuwrite(ppufile:tcompilerppufile);override;
  488. procedure buildderef;override;
  489. procedure deref;override;
  490. procedure derefimpl;override;
  491. function GetTypeName:string;override;
  492. function is_publishable : boolean;override;
  493. procedure calcsavesize;
  494. function packedbitsize: aint; override;
  495. procedure setmax(_max:aint);
  496. procedure setmin(_min:aint);
  497. function min:aint;
  498. function max:aint;
  499. end;
  500. tsetdef = class(tstoreddef)
  501. elementdef : tdef;
  502. elementdefderef : tderef;
  503. settype : tsettype;
  504. setbase,
  505. setmax : aint;
  506. constructor create(def:tdef;low, high : aint);
  507. constructor ppuload(ppufile:tcompilerppufile);
  508. function getcopy : tstoreddef;override;
  509. procedure ppuwrite(ppufile:tcompilerppufile);override;
  510. procedure buildderef;override;
  511. procedure deref;override;
  512. function GetTypeName:string;override;
  513. function is_publishable : boolean;override;
  514. end;
  515. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  516. var
  517. aktobjectdef : tobjectdef; { used for private functions check !! }
  518. { default types }
  519. generrordef, { error in definition }
  520. voidpointertype, { pointer for Void-pointeddef }
  521. charpointertype, { pointer for Char-pointeddef }
  522. widecharpointertype, { pointer for WideChar-pointeddef }
  523. voidfarpointertype,
  524. cundefinedtype,
  525. cformaltype, { unique formal definition }
  526. voidtype, { Void (procedure) }
  527. cchartype, { Char }
  528. cwidechartype, { WideChar }
  529. booltype, { boolean type }
  530. bool16type,
  531. bool32type,
  532. bool64type, { implement me }
  533. u8inttype, { 8-Bit unsigned integer }
  534. s8inttype, { 8-Bit signed integer }
  535. u16inttype, { 16-Bit unsigned integer }
  536. s16inttype, { 16-Bit signed integer }
  537. u32inttype, { 32-Bit unsigned integer }
  538. s32inttype, { 32-Bit signed integer }
  539. u64inttype, { 64-bit unsigned integer }
  540. s64inttype, { 64-bit signed integer }
  541. s32floattype, { pointer for realconstn }
  542. s64floattype, { pointer for realconstn }
  543. s80floattype, { pointer to type of temp. floats }
  544. s64currencytype, { pointer to a currency type }
  545. cshortstringtype, { pointer to type of short string const }
  546. clongstringtype, { pointer to type of long string const }
  547. cansistringtype, { pointer to type of ansi string const }
  548. cwidestringtype, { pointer to type of wide string const }
  549. openshortstringtype, { pointer to type of an open shortstring,
  550. needed for readln() }
  551. openchararraytype, { pointer to type of an open array of char,
  552. needed for readln() }
  553. cfiletype, { get the same definition for all file }
  554. { used for stabs }
  555. methodpointertype, { typecasting of methodpointers to extract self }
  556. hresultdef,
  557. { we use only one variant def for every variant class }
  558. cvarianttype,
  559. colevarianttype,
  560. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  561. sinttype,
  562. uinttype,
  563. { unsigned and signed ord type with the same size as a pointer }
  564. ptruinttype,
  565. ptrsinttype,
  566. { several types to simulate more or less C++ objects for GDB }
  567. vmttype,
  568. vmtarraytype,
  569. pvmttype : tdef; { type of classrefs, used for stabs }
  570. { pointer to the anchestor of all classes }
  571. class_tobject : tobjectdef;
  572. { pointer to the ancestor of all COM interfaces }
  573. interface_iunknown : tobjectdef;
  574. { pointer to the TGUID type
  575. of all interfaces }
  576. rec_tguid : trecorddef;
  577. const
  578. {$ifdef i386}
  579. pbestrealtype : ^tdef = @s80floattype;
  580. {$endif}
  581. {$ifdef x86_64}
  582. pbestrealtype : ^tdef = @s80floattype;
  583. {$endif}
  584. {$ifdef m68k}
  585. pbestrealtype : ^tdef = @s64floattype;
  586. {$endif}
  587. {$ifdef alpha}
  588. pbestrealtype : ^tdef = @s64floattype;
  589. {$endif}
  590. {$ifdef powerpc}
  591. pbestrealtype : ^tdef = @s64floattype;
  592. {$endif}
  593. {$ifdef POWERPC64}
  594. pbestrealtype : ^tdef = @s64floattype;
  595. {$endif}
  596. {$ifdef ia64}
  597. pbestrealtype : ^tdef = @s64floattype;
  598. {$endif}
  599. {$ifdef SPARC}
  600. pbestrealtype : ^tdef = @s64floattype;
  601. {$endif SPARC}
  602. {$ifdef vis}
  603. pbestrealtype : ^tdef = @s64floattype;
  604. {$endif vis}
  605. {$ifdef ARM}
  606. pbestrealtype : ^tdef = @s64floattype;
  607. {$endif ARM}
  608. {$ifdef MIPS}
  609. pbestrealtype : ^tdef = @s64floattype;
  610. {$endif MIPS}
  611. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  612. { should be in the types unit, but the types unit uses the node stuff :( }
  613. function is_interfacecom(def: tdef): boolean;
  614. function is_interfacecorba(def: tdef): boolean;
  615. function is_interface(def: tdef): boolean;
  616. function is_dispinterface(def: tdef): boolean;
  617. function is_object(def: tdef): boolean;
  618. function is_class(def: tdef): boolean;
  619. function is_cppclass(def: tdef): boolean;
  620. function is_class_or_interface(def: tdef): boolean;
  621. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  622. {$ifdef x86}
  623. function use_sse(def : tdef) : boolean;
  624. {$endif x86}
  625. implementation
  626. uses
  627. SysUtils,
  628. cutils,
  629. { global }
  630. verbose,
  631. { target }
  632. systems,aasmcpu,paramgr,
  633. { symtable }
  634. symsym,symtable,symutil,defutil,
  635. { module }
  636. fmodule,
  637. { other }
  638. gendef,
  639. fpccrc
  640. ;
  641. {****************************************************************************
  642. Constants
  643. ****************************************************************************}
  644. const
  645. varempty = 0;
  646. varnull = 1;
  647. varsmallint = 2;
  648. varinteger = 3;
  649. varsingle = 4;
  650. vardouble = 5;
  651. varcurrency = 6;
  652. vardate = 7;
  653. varolestr = 8;
  654. vardispatch = 9;
  655. varerror = 10;
  656. varboolean = 11;
  657. varvariant = 12;
  658. varunknown = 13;
  659. vardecimal = 14;
  660. varshortint = 16;
  661. varbyte = 17;
  662. varword = 18;
  663. varlongword = 19;
  664. varint64 = 20;
  665. varqword = 21;
  666. varUndefined = -1;
  667. varstrarg = $48;
  668. varstring = $100;
  669. varany = $101;
  670. vardefmask = $fff;
  671. vararray = $2000;
  672. varbyref = $4000;
  673. {****************************************************************************
  674. Helpers
  675. ****************************************************************************}
  676. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  677. var
  678. s,hs,
  679. prefix : string;
  680. oldlen,
  681. newlen,
  682. i : longint;
  683. crc : dword;
  684. hp : tparavarsym;
  685. begin
  686. prefix:='';
  687. if not assigned(st) then
  688. internalerror(200204212);
  689. { sub procedures }
  690. while (st.symtabletype=localsymtable) do
  691. begin
  692. if st.defowner.typ<>procdef then
  693. internalerror(200204173);
  694. { Add the full mangledname of procedure to prevent
  695. conflicts with 2 overloads having both a nested procedure
  696. with the same name, see tb0314 (PFV) }
  697. s:=tprocdef(st.defowner).procsym.name;
  698. oldlen:=length(s);
  699. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  700. begin
  701. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  702. if not(vo_is_hidden_para in hp.varoptions) then
  703. s:=s+'$'+hp.vardef.mangledparaname;
  704. end;
  705. if not is_void(tprocdef(st.defowner).returndef) then
  706. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  707. newlen:=length(s);
  708. { Replace with CRC if the parameter line is very long }
  709. if (newlen-oldlen>12) and
  710. ((newlen+length(prefix)>128) or (newlen-oldlen>32)) then
  711. begin
  712. crc:=$ffffffff;
  713. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  714. begin
  715. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  716. if not(vo_is_hidden_para in hp.varoptions) then
  717. begin
  718. hs:=hp.vardef.mangledparaname;
  719. crc:=UpdateCrc32(crc,hs[1],length(hs));
  720. end;
  721. end;
  722. hs:=hp.vardef.mangledparaname;
  723. crc:=UpdateCrc32(crc,hs[1],length(hs));
  724. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  725. end;
  726. if prefix<>'' then
  727. prefix:=s+'_'+prefix
  728. else
  729. prefix:=s;
  730. st:=st.defowner.owner;
  731. end;
  732. { object/classes symtable }
  733. if (st.symtabletype=ObjectSymtable) then
  734. begin
  735. if st.defowner.typ<>objectdef then
  736. internalerror(200204174);
  737. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  738. st:=st.defowner.owner;
  739. end;
  740. { symtable must now be static or global }
  741. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  742. internalerror(200204175);
  743. result:='';
  744. if typeprefix<>'' then
  745. result:=result+typeprefix+'_';
  746. { Add P$ for program, which can have the same name as
  747. a unit }
  748. if (TSymtable(main_module.localsymtable)=st) and
  749. (not main_module.is_unit) then
  750. result:=result+'P$'+st.name^
  751. else
  752. result:=result+st.name^;
  753. if prefix<>'' then
  754. result:=result+'_'+prefix;
  755. if suffix<>'' then
  756. result:=result+'_'+suffix;
  757. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  758. if (target_info.system in systems_darwin) and
  759. (result[1] = 'L') then
  760. result := '_' + result;
  761. end;
  762. {****************************************************************************
  763. TDEF (base class for definitions)
  764. ****************************************************************************}
  765. constructor tstoreddef.create(dt:tdeftyp);
  766. var
  767. insertstack : psymtablestackitem;
  768. begin
  769. inherited create(dt);
  770. savesize := 0;
  771. {$ifdef EXTDEBUG}
  772. fileinfo := current_filepos;
  773. {$endif}
  774. generictokenbuf:=nil;
  775. genericdef:=nil;
  776. { Don't register forwarddefs, they are disposed at the
  777. end of an type block }
  778. if (dt=forwarddef) then
  779. exit;
  780. { Register in current_module }
  781. if assigned(current_module) then
  782. begin
  783. current_module.deflist.Add(self);
  784. DefId:=current_module.deflist.Count-1;
  785. end;
  786. { Register in symtable stack }
  787. if assigned(symtablestack) then
  788. begin
  789. insertstack:=symtablestack.stack;
  790. while assigned(insertstack) and
  791. (insertstack^.symtable.symtabletype=withsymtable) do
  792. insertstack:=insertstack^.next;
  793. if not assigned(insertstack) then
  794. internalerror(200602044);
  795. insertstack^.symtable.insertdef(self);
  796. end;
  797. end;
  798. destructor tstoreddef.destroy;
  799. begin
  800. { Direct calls are not allowed, use symtable.deletedef() }
  801. if assigned(owner) then
  802. internalerror(200612311);
  803. if assigned(generictokenbuf) then
  804. begin
  805. generictokenbuf.free;
  806. generictokenbuf:=nil;
  807. end;
  808. inherited destroy;
  809. end;
  810. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  811. var
  812. sizeleft,i : longint;
  813. buf : array[0..255] of byte;
  814. begin
  815. inherited create(dt);
  816. DefId:=ppufile.getlongint;
  817. current_module.deflist[DefId]:=self;
  818. {$ifdef EXTDEBUG}
  819. fillchar(fileinfo,sizeof(fileinfo),0);
  820. {$endif}
  821. { load }
  822. ppufile.getderef(typesymderef);
  823. ppufile.getsmallset(defoptions);
  824. if df_generic in defoptions then
  825. begin
  826. sizeleft:=ppufile.getlongint;
  827. initgeneric;
  828. while sizeleft>0 do
  829. begin
  830. if sizeleft>sizeof(buf) then
  831. i:=sizeof(buf)
  832. else
  833. i:=sizeleft;
  834. ppufile.getdata(buf,i);
  835. generictokenbuf.write(buf,i);
  836. dec(sizeleft,i);
  837. end;
  838. end;
  839. if df_specialization in defoptions then
  840. ppufile.getderef(genericdefderef);
  841. end;
  842. function Tstoreddef.rtti_mangledname(rt:trttitype):string;
  843. var
  844. prefix : string[4];
  845. begin
  846. if rt=fullrtti then
  847. begin
  848. prefix:='RTTI';
  849. include(defstates,ds_rtti_table_used);
  850. end
  851. else
  852. begin
  853. prefix:='INIT';
  854. include(defstates,ds_init_table_used);
  855. end;
  856. if assigned(typesym) and
  857. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  858. result:=make_mangledname(prefix,owner,typesym.name)
  859. else
  860. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  861. end;
  862. procedure Tstoreddef.reset;
  863. begin
  864. end;
  865. function tstoreddef.getcopy : tstoreddef;
  866. begin
  867. Message(sym_e_cant_create_unique_type);
  868. getcopy:=terrordef.create;
  869. end;
  870. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  871. var
  872. sizeleft,i : longint;
  873. buf : array[0..255] of byte;
  874. oldintfcrc : boolean;
  875. begin
  876. ppufile.putlongint(DefId);
  877. ppufile.putderef(typesymderef);
  878. ppufile.putsmallset(defoptions);
  879. if df_generic in defoptions then
  880. begin
  881. oldintfcrc:=ppufile.do_interface_crc;
  882. ppufile.do_interface_crc:=false;
  883. if assigned(generictokenbuf) then
  884. begin
  885. sizeleft:=generictokenbuf.size;
  886. generictokenbuf.seek(0);
  887. end
  888. else
  889. sizeleft:=0;
  890. ppufile.putlongint(sizeleft);
  891. while sizeleft>0 do
  892. begin
  893. if sizeleft>sizeof(buf) then
  894. i:=sizeof(buf)
  895. else
  896. i:=sizeleft;
  897. generictokenbuf.read(buf,i);
  898. ppufile.putdata(buf,i);
  899. dec(sizeleft,i);
  900. end;
  901. ppufile.do_interface_crc:=oldintfcrc;
  902. end;
  903. if df_specialization in defoptions then
  904. ppufile.putderef(genericdefderef);
  905. end;
  906. procedure tstoreddef.buildderef;
  907. begin
  908. typesymderef.build(typesym);
  909. genericdefderef.build(genericdef);
  910. end;
  911. procedure tstoreddef.buildderefimpl;
  912. begin
  913. end;
  914. procedure tstoreddef.deref;
  915. begin
  916. typesym:=ttypesym(typesymderef.resolve);
  917. if df_specialization in defoptions then
  918. genericdef:=tstoreddef(genericdefderef.resolve);
  919. end;
  920. procedure tstoreddef.derefimpl;
  921. begin
  922. end;
  923. function tstoreddef.size : aint;
  924. begin
  925. size:=savesize;
  926. end;
  927. function tstoreddef.getvardef:longint;
  928. begin
  929. result:=varUndefined;
  930. end;
  931. function tstoreddef.alignment : shortint;
  932. begin
  933. { natural alignment by default }
  934. alignment:=size_2_align(savesize);
  935. end;
  936. { returns true, if the definition can be published }
  937. function tstoreddef.is_publishable : boolean;
  938. begin
  939. is_publishable:=false;
  940. end;
  941. { needs an init table }
  942. function tstoreddef.needs_inittable : boolean;
  943. begin
  944. needs_inittable:=false;
  945. end;
  946. function tstoreddef.is_intregable : boolean;
  947. var
  948. recsize,temp: longint;
  949. begin
  950. is_intregable:=false;
  951. case typ of
  952. orddef,
  953. pointerdef,
  954. enumdef,
  955. classrefdef:
  956. is_intregable:=true;
  957. procvardef :
  958. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  959. objectdef:
  960. is_intregable:=(is_class(self) or is_interface(self)) and not needs_inittable;
  961. setdef:
  962. is_intregable:=(tsetdef(self).settype=smallset);
  963. recorddef:
  964. begin
  965. recsize:=size;
  966. is_intregable:=
  967. ispowerof2(recsize,temp) and
  968. (recsize <= sizeof(aint));
  969. end;
  970. end;
  971. end;
  972. function tstoreddef.is_fpuregable : boolean;
  973. begin
  974. {$ifdef x86}
  975. result:=use_sse(self);
  976. {$else x86}
  977. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  978. {$endif x86}
  979. end;
  980. procedure tstoreddef.initgeneric;
  981. begin
  982. if assigned(generictokenbuf) then
  983. internalerror(200512131);
  984. generictokenbuf:=tdynamicarray.create(256);
  985. end;
  986. {****************************************************************************
  987. Tstringdef
  988. ****************************************************************************}
  989. constructor tstringdef.createshort(l : byte);
  990. begin
  991. inherited create(stringdef);
  992. stringtype:=st_shortstring;
  993. len:=l;
  994. savesize:=len+1;
  995. end;
  996. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  997. begin
  998. inherited ppuload(stringdef,ppufile);
  999. stringtype:=st_shortstring;
  1000. len:=ppufile.getbyte;
  1001. savesize:=len+1;
  1002. end;
  1003. constructor tstringdef.createlong(l : aint);
  1004. begin
  1005. inherited create(stringdef);
  1006. stringtype:=st_longstring;
  1007. len:=l;
  1008. savesize:=sizeof(aint);
  1009. end;
  1010. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1011. begin
  1012. inherited ppuload(stringdef,ppufile);
  1013. stringtype:=st_longstring;
  1014. len:=ppufile.getaint;
  1015. savesize:=sizeof(aint);
  1016. end;
  1017. constructor tstringdef.createansi(l:aint);
  1018. begin
  1019. inherited create(stringdef);
  1020. stringtype:=st_ansistring;
  1021. len:=l;
  1022. savesize:=sizeof(aint);
  1023. end;
  1024. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1025. begin
  1026. inherited ppuload(stringdef,ppufile);
  1027. stringtype:=st_ansistring;
  1028. len:=ppufile.getaint;
  1029. savesize:=sizeof(aint);
  1030. end;
  1031. constructor tstringdef.createwide(l : aint);
  1032. begin
  1033. inherited create(stringdef);
  1034. stringtype:=st_widestring;
  1035. len:=l;
  1036. savesize:=sizeof(aint);
  1037. end;
  1038. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1039. begin
  1040. inherited ppuload(stringdef,ppufile);
  1041. stringtype:=st_widestring;
  1042. len:=ppufile.getaint;
  1043. savesize:=sizeof(aint);
  1044. end;
  1045. function tstringdef.getcopy : tstoreddef;
  1046. begin
  1047. result:=tstringdef.create(typ);
  1048. result.typ:=stringdef;
  1049. tstringdef(result).stringtype:=stringtype;
  1050. tstringdef(result).len:=len;
  1051. tstringdef(result).savesize:=savesize;
  1052. end;
  1053. function tstringdef.stringtypname:string;
  1054. const
  1055. typname:array[tstringtype] of string[8]=(
  1056. 'shortstr','longstr','ansistr','widestr'
  1057. );
  1058. begin
  1059. stringtypname:=typname[stringtype];
  1060. end;
  1061. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1062. begin
  1063. inherited ppuwrite(ppufile);
  1064. if stringtype=st_shortstring then
  1065. begin
  1066. {$ifdef extdebug}
  1067. if len > 255 then internalerror(12122002);
  1068. {$endif}
  1069. ppufile.putbyte(byte(len))
  1070. end
  1071. else
  1072. ppufile.putaint(len);
  1073. case stringtype of
  1074. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1075. st_longstring : ppufile.writeentry(iblongstringdef);
  1076. st_ansistring : ppufile.writeentry(ibansistringdef);
  1077. st_widestring : ppufile.writeentry(ibwidestringdef);
  1078. end;
  1079. end;
  1080. function tstringdef.needs_inittable : boolean;
  1081. begin
  1082. needs_inittable:=stringtype in [st_ansistring,st_widestring];
  1083. end;
  1084. function tstringdef.GetTypeName : string;
  1085. const
  1086. names : array[tstringtype] of string[11] = (
  1087. 'ShortString','LongString','AnsiString','WideString');
  1088. begin
  1089. GetTypeName:=names[stringtype];
  1090. end;
  1091. function tstringdef.getvardef : longint;
  1092. const
  1093. vardef : array[tstringtype] of longint = (
  1094. varUndefined,varUndefined,varString,varOleStr);
  1095. begin
  1096. result:=vardef[stringtype];
  1097. end;
  1098. function tstringdef.alignment : shortint;
  1099. begin
  1100. case stringtype of
  1101. st_widestring,
  1102. st_ansistring:
  1103. alignment:=size_2_align(savesize);
  1104. st_longstring,
  1105. st_shortstring:
  1106. if (tf_requires_proper_alignment in target_info.flags) then
  1107. { char to string accesses byte 0 and 1 with one word access }
  1108. alignment:=size_2_align(2)
  1109. else
  1110. alignment:=size_2_align(1);
  1111. else
  1112. internalerror(200412301);
  1113. end;
  1114. end;
  1115. function tstringdef.getmangledparaname : string;
  1116. begin
  1117. getmangledparaname:='STRING';
  1118. end;
  1119. function tstringdef.is_publishable : boolean;
  1120. begin
  1121. is_publishable:=true;
  1122. end;
  1123. {****************************************************************************
  1124. TENUMDEF
  1125. ****************************************************************************}
  1126. constructor tenumdef.create;
  1127. begin
  1128. inherited create(enumdef);
  1129. minval:=0;
  1130. maxval:=0;
  1131. calcsavesize;
  1132. has_jumps:=false;
  1133. basedef:=nil;
  1134. firstenum:=nil;
  1135. end;
  1136. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1137. begin
  1138. inherited create(enumdef);
  1139. minval:=_min;
  1140. maxval:=_max;
  1141. basedef:=_basedef;
  1142. calcsavesize;
  1143. has_jumps:=false;
  1144. firstenum:=basedef.firstenum;
  1145. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1146. firstenum:=tenumsym(firstenum).nextenum;
  1147. end;
  1148. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1149. begin
  1150. inherited ppuload(enumdef,ppufile);
  1151. ppufile.getderef(basedefderef);
  1152. minval:=ppufile.getaint;
  1153. maxval:=ppufile.getaint;
  1154. savesize:=ppufile.getaint;
  1155. has_jumps:=false;
  1156. firstenum:=Nil;
  1157. end;
  1158. function tenumdef.getcopy : tstoreddef;
  1159. begin
  1160. if assigned(basedef) then
  1161. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1162. else
  1163. begin
  1164. result:=tenumdef.create;
  1165. tenumdef(result).minval:=minval;
  1166. tenumdef(result).maxval:=maxval;
  1167. end;
  1168. tenumdef(result).has_jumps:=has_jumps;
  1169. tenumdef(result).firstenum:=firstenum;
  1170. tenumdef(result).basedefderef:=basedefderef;
  1171. end;
  1172. procedure tenumdef.calcsavesize;
  1173. begin
  1174. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1175. savesize:=8
  1176. else
  1177. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  1178. savesize:=4
  1179. else
  1180. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1181. savesize:=2
  1182. else
  1183. savesize:=1;
  1184. end;
  1185. function tenumdef.packedbitsize: aint;
  1186. var
  1187. sizeval: tconstexprint;
  1188. power: longint;
  1189. begin
  1190. result := 0;
  1191. if (minval >= 0) and
  1192. (maxval <= 1) then
  1193. result := 1
  1194. else
  1195. begin
  1196. if (minval>=0) then
  1197. sizeval:=maxval
  1198. else
  1199. { don't count 0 twice }
  1200. sizeval:=(cutils.max(-minval,maxval)*2)-1;
  1201. { 256 must become 512 etc. }
  1202. nextpowerof2(sizeval+1,power);
  1203. result := power;
  1204. end;
  1205. end;
  1206. procedure tenumdef.setmax(_max:aint);
  1207. begin
  1208. maxval:=_max;
  1209. calcsavesize;
  1210. end;
  1211. procedure tenumdef.setmin(_min:aint);
  1212. begin
  1213. minval:=_min;
  1214. calcsavesize;
  1215. end;
  1216. function tenumdef.min:aint;
  1217. begin
  1218. min:=minval;
  1219. end;
  1220. function tenumdef.max:aint;
  1221. begin
  1222. max:=maxval;
  1223. end;
  1224. procedure tenumdef.buildderef;
  1225. begin
  1226. inherited buildderef;
  1227. basedefderef.build(basedef);
  1228. end;
  1229. procedure tenumdef.deref;
  1230. begin
  1231. inherited deref;
  1232. basedef:=tenumdef(basedefderef.resolve);
  1233. { restart ordering }
  1234. firstenum:=nil;
  1235. end;
  1236. procedure tenumdef.derefimpl;
  1237. begin
  1238. if assigned(basedef) and
  1239. (firstenum=nil) then
  1240. begin
  1241. firstenum:=basedef.firstenum;
  1242. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1243. firstenum:=tenumsym(firstenum).nextenum;
  1244. end;
  1245. end;
  1246. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1247. begin
  1248. inherited ppuwrite(ppufile);
  1249. ppufile.putderef(basedefderef);
  1250. ppufile.putaint(min);
  1251. ppufile.putaint(max);
  1252. ppufile.putaint(savesize);
  1253. ppufile.writeentry(ibenumdef);
  1254. end;
  1255. function tenumdef.is_publishable : boolean;
  1256. begin
  1257. is_publishable:=true;
  1258. end;
  1259. function tenumdef.GetTypeName : string;
  1260. begin
  1261. GetTypeName:='<enumeration type>';
  1262. end;
  1263. {****************************************************************************
  1264. TORDDEF
  1265. ****************************************************************************}
  1266. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  1267. begin
  1268. inherited create(orddef);
  1269. low:=v;
  1270. high:=b;
  1271. ordtype:=t;
  1272. setsize;
  1273. end;
  1274. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1275. begin
  1276. inherited ppuload(orddef,ppufile);
  1277. ordtype:=tordtype(ppufile.getbyte);
  1278. if sizeof(TConstExprInt)=8 then
  1279. begin
  1280. low:=ppufile.getint64;
  1281. high:=ppufile.getint64;
  1282. end
  1283. else
  1284. begin
  1285. low:=ppufile.getlongint;
  1286. high:=ppufile.getlongint;
  1287. end;
  1288. setsize;
  1289. end;
  1290. function torddef.getcopy : tstoreddef;
  1291. begin
  1292. result:=torddef.create(ordtype,low,high);
  1293. result.typ:=orddef;
  1294. torddef(result).low:=low;
  1295. torddef(result).high:=high;
  1296. torddef(result).ordtype:=ordtype;
  1297. torddef(result).savesize:=savesize;
  1298. end;
  1299. function torddef.alignment:shortint;
  1300. begin
  1301. if (target_info.system = system_i386_darwin) and
  1302. (ordtype in [s64bit,u64bit]) then
  1303. result := 4
  1304. else
  1305. result := inherited alignment;
  1306. end;
  1307. procedure torddef.setsize;
  1308. const
  1309. sizetbl : array[tordtype] of longint = (
  1310. 0,
  1311. 1,2,4,8,
  1312. 1,2,4,8,
  1313. 1,2,4,8,
  1314. 1,2,8
  1315. );
  1316. begin
  1317. savesize:=sizetbl[ordtype];
  1318. end;
  1319. function torddef.packedbitsize: aint;
  1320. var
  1321. sizeval: tconstexprint;
  1322. power: longint;
  1323. begin
  1324. result := 0;
  1325. if ordtype = uvoid then
  1326. exit;
  1327. if (ordtype = u64bit) or
  1328. ((ordtype = s64bit) and
  1329. ((low <= (system.low(int64) div 2)) or
  1330. (high > (system.high(int64) div 2)))) then
  1331. result := 64
  1332. else if (low >= 0) and
  1333. (high <= 1) then
  1334. result := 1
  1335. else
  1336. begin
  1337. if (low>=0) then
  1338. sizeval:=high
  1339. else
  1340. { don't count 0 twice }
  1341. sizeval:=(cutils.max(-low,high)*2)-1;
  1342. { 256 must become 512 etc. }
  1343. nextpowerof2(sizeval+1,power);
  1344. result := power;
  1345. end;
  1346. end;
  1347. function torddef.getvardef : longint;
  1348. const
  1349. basetype2vardef : array[tordtype] of longint = (
  1350. varUndefined,
  1351. varbyte,varqword,varlongword,varqword,
  1352. varshortint,varsmallint,varinteger,varint64,
  1353. varboolean,varboolean,varUndefined,varUndefined,
  1354. varUndefined,varUndefined,varCurrency);
  1355. begin
  1356. result:=basetype2vardef[ordtype];
  1357. end;
  1358. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1359. begin
  1360. inherited ppuwrite(ppufile);
  1361. ppufile.putbyte(byte(ordtype));
  1362. if sizeof(TConstExprInt)=8 then
  1363. begin
  1364. ppufile.putint64(low);
  1365. ppufile.putint64(high);
  1366. end
  1367. else
  1368. begin
  1369. ppufile.putlongint(low);
  1370. ppufile.putlongint(high);
  1371. end;
  1372. ppufile.writeentry(iborddef);
  1373. end;
  1374. function torddef.is_publishable : boolean;
  1375. begin
  1376. is_publishable:=(ordtype<>uvoid);
  1377. end;
  1378. function torddef.GetTypeName : string;
  1379. const
  1380. names : array[tordtype] of string[20] = (
  1381. 'untyped',
  1382. 'Byte','Word','DWord','QWord',
  1383. 'ShortInt','SmallInt','LongInt','Int64',
  1384. 'Boolean','WordBool','LongBool','QWordBool',
  1385. 'Char','WideChar','Currency');
  1386. begin
  1387. GetTypeName:=names[ordtype];
  1388. end;
  1389. {****************************************************************************
  1390. TFLOATDEF
  1391. ****************************************************************************}
  1392. constructor tfloatdef.create(t : tfloattype);
  1393. begin
  1394. inherited create(floatdef);
  1395. floattype:=t;
  1396. setsize;
  1397. end;
  1398. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1399. begin
  1400. inherited ppuload(floatdef,ppufile);
  1401. floattype:=tfloattype(ppufile.getbyte);
  1402. setsize;
  1403. end;
  1404. function tfloatdef.getcopy : tstoreddef;
  1405. begin
  1406. result:=tfloatdef.create(floattype);
  1407. result.typ:=floatdef;
  1408. tfloatdef(result).savesize:=savesize;
  1409. end;
  1410. function tfloatdef.alignment:shortint;
  1411. begin
  1412. if (target_info.system = system_i386_darwin) then
  1413. case floattype of
  1414. s80real : result:=16;
  1415. s64real,
  1416. s64currency,
  1417. s64comp : result:=4;
  1418. else
  1419. result := inherited alignment;
  1420. end
  1421. else
  1422. result := inherited alignment;
  1423. end;
  1424. procedure tfloatdef.setsize;
  1425. begin
  1426. case floattype of
  1427. s32real : savesize:=4;
  1428. s80real : savesize:=10;
  1429. s64real,
  1430. s64currency,
  1431. s64comp : savesize:=8;
  1432. else
  1433. savesize:=0;
  1434. end;
  1435. end;
  1436. function tfloatdef.getvardef : longint;
  1437. const
  1438. floattype2vardef : array[tfloattype] of longint = (
  1439. varSingle,varDouble,varUndefined,
  1440. varUndefined,varCurrency,varUndefined);
  1441. begin
  1442. if (upper(typename)='TDATETIME') and
  1443. assigned(owner) and
  1444. assigned(owner.name) and
  1445. (owner.name^='SYSTEM') then
  1446. result:=varDate
  1447. else
  1448. result:=floattype2vardef[floattype];
  1449. end;
  1450. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1451. begin
  1452. inherited ppuwrite(ppufile);
  1453. ppufile.putbyte(byte(floattype));
  1454. ppufile.writeentry(ibfloatdef);
  1455. end;
  1456. function tfloatdef.is_publishable : boolean;
  1457. begin
  1458. is_publishable:=true;
  1459. end;
  1460. function tfloatdef.GetTypeName : string;
  1461. const
  1462. names : array[tfloattype] of string[20] = (
  1463. 'Single','Double','Extended','Comp','Currency','Float128');
  1464. begin
  1465. GetTypeName:=names[floattype];
  1466. end;
  1467. {****************************************************************************
  1468. TFILEDEF
  1469. ****************************************************************************}
  1470. constructor tfiledef.createtext;
  1471. begin
  1472. inherited create(filedef);
  1473. filetyp:=ft_text;
  1474. typedfiledef:=nil;
  1475. setsize;
  1476. end;
  1477. constructor tfiledef.createuntyped;
  1478. begin
  1479. inherited create(filedef);
  1480. filetyp:=ft_untyped;
  1481. typedfiledef:=nil;
  1482. setsize;
  1483. end;
  1484. constructor tfiledef.createtyped(def:tdef);
  1485. begin
  1486. inherited create(filedef);
  1487. filetyp:=ft_typed;
  1488. typedfiledef:=def;
  1489. setsize;
  1490. end;
  1491. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1492. begin
  1493. inherited ppuload(filedef,ppufile);
  1494. filetyp:=tfiletyp(ppufile.getbyte);
  1495. if filetyp=ft_typed then
  1496. ppufile.getderef(typedfiledefderef)
  1497. else
  1498. typedfiledef:=nil;
  1499. setsize;
  1500. end;
  1501. function tfiledef.getcopy : tstoreddef;
  1502. begin
  1503. case filetyp of
  1504. ft_typed:
  1505. result:=tfiledef.createtyped(typedfiledef);
  1506. ft_untyped:
  1507. result:=tfiledef.createuntyped;
  1508. ft_text:
  1509. result:=tfiledef.createtext;
  1510. else
  1511. internalerror(2004121201);
  1512. end;
  1513. end;
  1514. procedure tfiledef.buildderef;
  1515. begin
  1516. inherited buildderef;
  1517. if filetyp=ft_typed then
  1518. typedfiledefderef.build(typedfiledef);
  1519. end;
  1520. procedure tfiledef.deref;
  1521. begin
  1522. inherited deref;
  1523. if filetyp=ft_typed then
  1524. typedfiledef:=tdef(typedfiledefderef.resolve);
  1525. end;
  1526. procedure tfiledef.setsize;
  1527. begin
  1528. {$ifdef cpu64bit}
  1529. case filetyp of
  1530. ft_text :
  1531. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1532. savesize:=632
  1533. else
  1534. savesize:=628;
  1535. ft_typed,
  1536. ft_untyped :
  1537. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1538. savesize:=372
  1539. else
  1540. savesize:=368;
  1541. end;
  1542. {$else cpu64bit}
  1543. case filetyp of
  1544. ft_text :
  1545. savesize:=592;
  1546. ft_typed,
  1547. ft_untyped :
  1548. savesize:=332;
  1549. end;
  1550. {$endif cpu64bit}
  1551. end;
  1552. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1553. begin
  1554. inherited ppuwrite(ppufile);
  1555. ppufile.putbyte(byte(filetyp));
  1556. if filetyp=ft_typed then
  1557. ppufile.putderef(typedfiledefderef);
  1558. ppufile.writeentry(ibfiledef);
  1559. end;
  1560. function tfiledef.GetTypeName : string;
  1561. begin
  1562. case filetyp of
  1563. ft_untyped:
  1564. GetTypeName:='File';
  1565. ft_typed:
  1566. GetTypeName:='File Of '+typedfiledef.typename;
  1567. ft_text:
  1568. GetTypeName:='Text'
  1569. end;
  1570. end;
  1571. function tfiledef.getmangledparaname : string;
  1572. begin
  1573. case filetyp of
  1574. ft_untyped:
  1575. getmangledparaname:='FILE';
  1576. ft_typed:
  1577. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  1578. ft_text:
  1579. getmangledparaname:='TEXT'
  1580. end;
  1581. end;
  1582. {****************************************************************************
  1583. TVARIANTDEF
  1584. ****************************************************************************}
  1585. constructor tvariantdef.create(v : tvarianttype);
  1586. begin
  1587. inherited create(variantdef);
  1588. varianttype:=v;
  1589. setsize;
  1590. end;
  1591. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1592. begin
  1593. inherited ppuload(variantdef,ppufile);
  1594. varianttype:=tvarianttype(ppufile.getbyte);
  1595. setsize;
  1596. end;
  1597. function tvariantdef.getcopy : tstoreddef;
  1598. begin
  1599. result:=tvariantdef.create(varianttype);
  1600. end;
  1601. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1602. begin
  1603. inherited ppuwrite(ppufile);
  1604. ppufile.putbyte(byte(varianttype));
  1605. ppufile.writeentry(ibvariantdef);
  1606. end;
  1607. function tvariantdef.getvardef : longint;
  1608. begin
  1609. Result:=varVariant;
  1610. end;
  1611. procedure tvariantdef.setsize;
  1612. begin
  1613. {$ifdef cpu64bit}
  1614. savesize:=24;
  1615. {$else cpu64bit}
  1616. savesize:=16;
  1617. {$endif cpu64bit}
  1618. end;
  1619. function tvariantdef.GetTypeName : string;
  1620. begin
  1621. case varianttype of
  1622. vt_normalvariant:
  1623. GetTypeName:='Variant';
  1624. vt_olevariant:
  1625. GetTypeName:='OleVariant';
  1626. end;
  1627. end;
  1628. function tvariantdef.needs_inittable : boolean;
  1629. begin
  1630. needs_inittable:=true;
  1631. end;
  1632. function tvariantdef.is_publishable : boolean;
  1633. begin
  1634. is_publishable:=true;
  1635. end;
  1636. {****************************************************************************
  1637. TABSTRACtpointerdef
  1638. ****************************************************************************}
  1639. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  1640. begin
  1641. inherited create(dt);
  1642. pointeddef:=def;
  1643. savesize:=sizeof(aint);
  1644. end;
  1645. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1646. begin
  1647. inherited ppuload(dt,ppufile);
  1648. ppufile.getderef(pointeddefderef);
  1649. savesize:=sizeof(aint);
  1650. end;
  1651. procedure tabstractpointerdef.buildderef;
  1652. begin
  1653. inherited buildderef;
  1654. pointeddefderef.build(pointeddef);
  1655. end;
  1656. procedure tabstractpointerdef.deref;
  1657. begin
  1658. inherited deref;
  1659. pointeddef:=tdef(pointeddefderef.resolve);
  1660. end;
  1661. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1662. begin
  1663. inherited ppuwrite(ppufile);
  1664. ppufile.putderef(pointeddefderef);
  1665. end;
  1666. {****************************************************************************
  1667. tpointerdef
  1668. ****************************************************************************}
  1669. constructor tpointerdef.create(def:tdef);
  1670. begin
  1671. inherited create(pointerdef,def);
  1672. is_far:=false;
  1673. end;
  1674. constructor tpointerdef.createfar(def:tdef);
  1675. begin
  1676. inherited create(pointerdef,def);
  1677. is_far:=true;
  1678. end;
  1679. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  1680. begin
  1681. inherited ppuload(pointerdef,ppufile);
  1682. is_far:=(ppufile.getbyte<>0);
  1683. end;
  1684. function tpointerdef.getcopy : tstoreddef;
  1685. begin
  1686. result:=tpointerdef.create(pointeddef);
  1687. tpointerdef(result).is_far:=is_far;
  1688. tpointerdef(result).savesize:=savesize;
  1689. end;
  1690. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1691. begin
  1692. inherited ppuwrite(ppufile);
  1693. ppufile.putbyte(byte(is_far));
  1694. ppufile.writeentry(ibpointerdef);
  1695. end;
  1696. function tpointerdef.GetTypeName : string;
  1697. begin
  1698. if is_far then
  1699. GetTypeName:='^'+pointeddef.typename+';far'
  1700. else
  1701. GetTypeName:='^'+pointeddef.typename;
  1702. end;
  1703. {****************************************************************************
  1704. TCLASSREFDEF
  1705. ****************************************************************************}
  1706. constructor tclassrefdef.create(def:tdef);
  1707. begin
  1708. inherited create(classrefdef,def);
  1709. end;
  1710. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  1711. begin
  1712. inherited ppuload(classrefdef,ppufile);
  1713. end;
  1714. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  1715. begin
  1716. inherited ppuwrite(ppufile);
  1717. ppufile.writeentry(ibclassrefdef);
  1718. end;
  1719. function tclassrefdef.GetTypeName : string;
  1720. begin
  1721. GetTypeName:='Class Of '+pointeddef.typename;
  1722. end;
  1723. function tclassrefdef.is_publishable : boolean;
  1724. begin
  1725. result:=true;
  1726. end;
  1727. {***************************************************************************
  1728. TSETDEF
  1729. ***************************************************************************}
  1730. constructor tsetdef.create(def:tdef;low, high : aint);
  1731. var
  1732. setallocbits: aint;
  1733. packedsavesize: aint;
  1734. begin
  1735. inherited create(setdef);
  1736. elementdef:=def;
  1737. setmax:=high;
  1738. if (current_settings.setalloc=0) then
  1739. begin
  1740. setbase:=0;
  1741. if (high<32) then
  1742. begin
  1743. settype:=smallset;
  1744. savesize:=Sizeof(longint)
  1745. end
  1746. else if (high<256) then
  1747. begin
  1748. settype:=normset;
  1749. savesize:=32
  1750. end
  1751. else
  1752. savesize:=(high+7) div 8
  1753. end
  1754. else
  1755. begin
  1756. setallocbits:=current_settings.setalloc*8;
  1757. setbase:=low and not(setallocbits-1);
  1758. packedsavesize:=current_settings.setalloc*((((high+setallocbits)-setbase)) DIV setallocbits);
  1759. savesize:=packedsavesize;
  1760. if (packedsavesize<=4) then
  1761. begin
  1762. settype:=smallset;
  1763. if savesize=3 then
  1764. savesize:=4;
  1765. end
  1766. else if (packedsavesize<=32) then
  1767. settype:=normset;
  1768. end;
  1769. end;
  1770. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  1771. begin
  1772. inherited ppuload(setdef,ppufile);
  1773. ppufile.getderef(elementdefderef);
  1774. settype:=tsettype(ppufile.getbyte);
  1775. savesize:=ppufile.getaint;
  1776. setbase:=ppufile.getaint;
  1777. setmax:=ppufile.getaint;
  1778. end;
  1779. function tsetdef.getcopy : tstoreddef;
  1780. begin
  1781. result:=tsetdef.create(elementdef,setbase,setmax);
  1782. { the copy might have been created with a different setalloc setting }
  1783. tsetdef(result).settype:=settype;
  1784. tsetdef(result).savesize:=savesize;
  1785. end;
  1786. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  1787. begin
  1788. inherited ppuwrite(ppufile);
  1789. ppufile.putderef(elementdefderef);
  1790. ppufile.putbyte(byte(settype));
  1791. ppufile.putaint(savesize);
  1792. ppufile.putaint(setbase);
  1793. ppufile.putaint(setmax);
  1794. ppufile.writeentry(ibsetdef);
  1795. end;
  1796. procedure tsetdef.buildderef;
  1797. begin
  1798. inherited buildderef;
  1799. elementdefderef.build(elementdef);
  1800. end;
  1801. procedure tsetdef.deref;
  1802. begin
  1803. inherited deref;
  1804. elementdef:=tdef(elementdefderef.resolve);
  1805. end;
  1806. function tsetdef.is_publishable : boolean;
  1807. begin
  1808. is_publishable:=savesize in [1,2,4];
  1809. end;
  1810. function tsetdef.GetTypeName : string;
  1811. begin
  1812. if assigned(elementdef) then
  1813. GetTypeName:='Set Of '+elementdef.typename
  1814. else
  1815. GetTypeName:='Empty Set';
  1816. end;
  1817. {***************************************************************************
  1818. TFORMALDEF
  1819. ***************************************************************************}
  1820. constructor tformaldef.create;
  1821. begin
  1822. inherited create(formaldef);
  1823. savesize:=0;
  1824. end;
  1825. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  1826. begin
  1827. inherited ppuload(formaldef,ppufile);
  1828. savesize:=0;
  1829. end;
  1830. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  1831. begin
  1832. inherited ppuwrite(ppufile);
  1833. ppufile.writeentry(ibformaldef);
  1834. end;
  1835. function tformaldef.GetTypeName : string;
  1836. begin
  1837. GetTypeName:='<Formal type>';
  1838. end;
  1839. {***************************************************************************
  1840. TARRAYDEF
  1841. ***************************************************************************}
  1842. constructor tarraydef.create(l,h : aint;def:tdef);
  1843. begin
  1844. inherited create(arraydef);
  1845. lowrange:=l;
  1846. highrange:=h;
  1847. rangedef:=def;
  1848. _elementdef:=nil;
  1849. arrayoptions:=[];
  1850. end;
  1851. constructor tarraydef.create_from_pointer(def:tdef);
  1852. begin
  1853. { use -1 so that the elecount will not overflow }
  1854. self.create(0,high(aint)-1,s32inttype);
  1855. arrayoptions:=[ado_IsConvertedPointer];
  1856. setelementdef(def);
  1857. end;
  1858. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  1859. begin
  1860. inherited ppuload(arraydef,ppufile);
  1861. { the addresses are calculated later }
  1862. ppufile.getderef(_elementdefderef);
  1863. ppufile.getderef(rangedefderef);
  1864. lowrange:=ppufile.getaint;
  1865. highrange:=ppufile.getaint;
  1866. ppufile.getsmallset(arrayoptions);
  1867. end;
  1868. function tarraydef.getcopy : tstoreddef;
  1869. begin
  1870. result:=tarraydef.create(lowrange,highrange,rangedef);
  1871. tarraydef(result).arrayoptions:=arrayoptions;
  1872. tarraydef(result)._elementdef:=_elementdef;
  1873. end;
  1874. procedure tarraydef.buildderef;
  1875. begin
  1876. inherited buildderef;
  1877. _elementdefderef.build(_elementdef);
  1878. rangedefderef.build(rangedef);
  1879. end;
  1880. procedure tarraydef.deref;
  1881. begin
  1882. inherited deref;
  1883. _elementdef:=tdef(_elementdefderef.resolve);
  1884. rangedef:=tdef(rangedefderef.resolve);
  1885. end;
  1886. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  1887. begin
  1888. inherited ppuwrite(ppufile);
  1889. ppufile.putderef(_elementdefderef);
  1890. ppufile.putderef(rangedefderef);
  1891. ppufile.putaint(lowrange);
  1892. ppufile.putaint(highrange);
  1893. ppufile.putsmallset(arrayoptions);
  1894. ppufile.writeentry(ibarraydef);
  1895. end;
  1896. function tarraydef.elesize : aint;
  1897. begin
  1898. if (ado_IsBitPacked in arrayoptions) then
  1899. internalerror(2006080101);
  1900. if assigned(_elementdef) then
  1901. result:=_elementdef.size
  1902. else
  1903. result:=0;
  1904. end;
  1905. function tarraydef.elepackedbitsize : aint;
  1906. begin
  1907. if not(ado_IsBitPacked in arrayoptions) then
  1908. internalerror(2006080102);
  1909. if assigned(_elementdef) then
  1910. result:=_elementdef.packedbitsize
  1911. else
  1912. result:=0;
  1913. end;
  1914. function tarraydef.elecount : aword;
  1915. var
  1916. qhigh,qlow : qword;
  1917. begin
  1918. if ado_IsDynamicArray in arrayoptions then
  1919. begin
  1920. result:=0;
  1921. exit;
  1922. end;
  1923. if (highrange>0) and (lowrange<0) then
  1924. begin
  1925. qhigh:=highrange;
  1926. qlow:=qword(-lowrange);
  1927. { prevent overflow, return 0 to indicate overflow }
  1928. if qhigh+qlow>qword(high(aint)-1) then
  1929. result:=0
  1930. else
  1931. result:=qhigh+qlow+1;
  1932. end
  1933. else
  1934. result:=int64(highrange)-lowrange+1;
  1935. end;
  1936. function tarraydef.size : aint;
  1937. var
  1938. cachedelecount : aword;
  1939. cachedelesize : aint;
  1940. begin
  1941. if ado_IsDynamicArray in arrayoptions then
  1942. begin
  1943. size:=sizeof(aint);
  1944. exit;
  1945. end;
  1946. { Tarraydef.size may never be called for an open array! }
  1947. if highrange<lowrange then
  1948. internalerror(99080501);
  1949. if not (ado_IsBitPacked in arrayoptions) then
  1950. cachedelesize:=elesize
  1951. else
  1952. cachedelesize := elepackedbitsize;
  1953. cachedelecount:=elecount;
  1954. if (cachedelesize = 0) then
  1955. begin
  1956. size := 0;
  1957. exit;
  1958. end;
  1959. if (cachedelecount = 0) then
  1960. begin
  1961. size := -1;
  1962. exit;
  1963. end;
  1964. { prevent overflow, return -1 to indicate overflow }
  1965. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  1966. if (cachedelecount > high(aint)) or
  1967. ((high(aint) div cachedelesize) < cachedelecount) or
  1968. { also lowrange*elesize must be < high(aint) to prevent overflow when
  1969. accessing the array, see ncgmem (PFV) }
  1970. ((high(aint) div cachedelesize) < abs(lowrange)) then
  1971. begin
  1972. result:=-1;
  1973. exit;
  1974. end;
  1975. if (ado_IsBitPacked in arrayoptions) then
  1976. size:=(cachedelesize * cachedelecount + 7) div 8
  1977. else
  1978. result:=cachedelesize*cachedelecount;
  1979. end;
  1980. procedure tarraydef.setelementdef(def:tdef);
  1981. begin
  1982. _elementdef:=def;
  1983. if not(
  1984. (ado_IsDynamicArray in arrayoptions) or
  1985. (ado_IsConvertedPointer in arrayoptions) or
  1986. (highrange<lowrange)
  1987. ) and
  1988. (size=-1) then
  1989. Message(sym_e_segment_too_large);
  1990. end;
  1991. function tarraydef.alignment : shortint;
  1992. begin
  1993. { alignment of dyn. arrays doesn't depend on the element size }
  1994. if (ado_IsDynamicArray in arrayoptions) then
  1995. alignment:=size_2_align(sizeof(aint))
  1996. { alignment is the size of the elements }
  1997. else if (elementdef.typ in [arraydef,recorddef]) or
  1998. ((elementdef.typ=objectdef) and
  1999. is_object(elementdef)) then
  2000. alignment:=elementdef.alignment
  2001. else if not (ado_IsBitPacked in arrayoptions) then
  2002. alignment:=size_2_align(elesize)
  2003. else
  2004. alignment:=packedbitsloadsize(elepackedbitsize);
  2005. end;
  2006. function tarraydef.needs_inittable : boolean;
  2007. begin
  2008. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  2009. end;
  2010. function tarraydef.GetTypeName : string;
  2011. begin
  2012. if (ado_IsConstString in arrayoptions) then
  2013. result:='Constant String'
  2014. else if (ado_isarrayofconst in arrayoptions) or
  2015. (ado_isConstructor in arrayoptions) then
  2016. begin
  2017. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  2018. GetTypeName:='Array Of Const'
  2019. else
  2020. GetTypeName:='Array Of Const/Constant Open Array of '+elementdef.typename;
  2021. end
  2022. else if (ado_IsDynamicArray in arrayoptions) then
  2023. GetTypeName:='Dynamic Array Of '+elementdef.typename
  2024. else if ((highrange=-1) and (lowrange=0)) then
  2025. GetTypeName:='Open Array Of '+elementdef.typename
  2026. else
  2027. begin
  2028. result := '';
  2029. if (ado_IsBitPacked in arrayoptions) then
  2030. result:='Packed ';
  2031. if rangedef.typ=enumdef then
  2032. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  2033. else
  2034. result:=result+'Array['+tostr(lowrange)+'..'+
  2035. tostr(highrange)+'] Of '+elementdef.typename
  2036. end;
  2037. end;
  2038. function tarraydef.getmangledparaname : string;
  2039. begin
  2040. if ado_isarrayofconst in arrayoptions then
  2041. getmangledparaname:='array_of_const'
  2042. else
  2043. if ((highrange=-1) and (lowrange=0)) then
  2044. getmangledparaname:='array_of_'+elementdef.mangledparaname
  2045. else
  2046. internalerror(200204176);
  2047. end;
  2048. {***************************************************************************
  2049. tabstractrecorddef
  2050. ***************************************************************************}
  2051. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  2052. begin
  2053. if t=gs_record then
  2054. GetSymtable:=symtable
  2055. else
  2056. GetSymtable:=nil;
  2057. end;
  2058. procedure tabstractrecorddef.reset;
  2059. begin
  2060. inherited reset;
  2061. tstoredsymtable(symtable).reset_all_defs;
  2062. end;
  2063. function tabstractrecorddef.is_packed:boolean;
  2064. begin
  2065. result:=tabstractrecordsymtable(symtable).is_packed;
  2066. end;
  2067. {***************************************************************************
  2068. trecorddef
  2069. ***************************************************************************}
  2070. constructor trecorddef.create(p : TSymtable);
  2071. begin
  2072. inherited create(recorddef);
  2073. symtable:=p;
  2074. symtable.defowner:=self;
  2075. isunion:=false;
  2076. end;
  2077. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2078. begin
  2079. inherited ppuload(recorddef,ppufile);
  2080. symtable:=trecordsymtable.create(0);
  2081. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2082. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2083. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2084. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  2085. { requires usefieldalignment to be set }
  2086. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2087. trecordsymtable(symtable).ppuload(ppufile);
  2088. symtable.defowner:=self;
  2089. isunion:=false;
  2090. end;
  2091. destructor trecorddef.destroy;
  2092. begin
  2093. if assigned(symtable) then
  2094. begin
  2095. symtable.free;
  2096. symtable:=nil;
  2097. end;
  2098. inherited destroy;
  2099. end;
  2100. function trecorddef.getcopy : tstoreddef;
  2101. begin
  2102. result:=trecorddef.create(symtable.getcopy);
  2103. trecorddef(result).isunion:=isunion;
  2104. end;
  2105. function trecorddef.needs_inittable : boolean;
  2106. begin
  2107. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2108. end;
  2109. procedure trecorddef.buildderef;
  2110. begin
  2111. inherited buildderef;
  2112. tstoredsymtable(symtable).buildderef;
  2113. end;
  2114. procedure trecorddef.deref;
  2115. begin
  2116. inherited deref;
  2117. { now dereference the definitions }
  2118. tstoredsymtable(symtable).deref;
  2119. { assign TGUID? load only from system unit }
  2120. if not(assigned(rec_tguid)) and
  2121. (upper(typename)='TGUID') and
  2122. assigned(owner) and
  2123. assigned(owner.name) and
  2124. (owner.name^='SYSTEM') then
  2125. rec_tguid:=self;
  2126. end;
  2127. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2128. begin
  2129. inherited ppuwrite(ppufile);
  2130. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2131. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2132. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2133. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  2134. ppufile.putaint(trecordsymtable(symtable).datasize);
  2135. ppufile.writeentry(ibrecorddef);
  2136. trecordsymtable(symtable).ppuwrite(ppufile);
  2137. end;
  2138. function trecorddef.size:aint;
  2139. begin
  2140. result:=trecordsymtable(symtable).datasize;
  2141. end;
  2142. function trecorddef.alignment:shortint;
  2143. begin
  2144. alignment:=trecordsymtable(symtable).recordalignment;
  2145. end;
  2146. function trecorddef.padalignment:shortint;
  2147. begin
  2148. padalignment := trecordsymtable(symtable).padalignment;
  2149. end;
  2150. function trecorddef.GetTypeName : string;
  2151. begin
  2152. GetTypeName:='<record type>'
  2153. end;
  2154. {***************************************************************************
  2155. TABSTRACTPROCDEF
  2156. ***************************************************************************}
  2157. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  2158. begin
  2159. inherited create(dt);
  2160. parast:=tparasymtable.create(self,level);
  2161. paras:=nil;
  2162. minparacount:=0;
  2163. maxparacount:=0;
  2164. proctypeoption:=potype_none;
  2165. proccalloption:=pocall_none;
  2166. procoptions:=[];
  2167. returndef:=voidtype;
  2168. {$ifdef i386}
  2169. fpu_used:=0;
  2170. {$endif i386}
  2171. savesize:=sizeof(aint);
  2172. requiredargarea:=0;
  2173. has_paraloc_info:=false;
  2174. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2175. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2176. end;
  2177. destructor tabstractprocdef.destroy;
  2178. begin
  2179. if assigned(paras) then
  2180. begin
  2181. {$ifdef MEMDEBUG}
  2182. memprocpara.start;
  2183. {$endif MEMDEBUG}
  2184. paras.free;
  2185. paras:=nil;
  2186. {$ifdef MEMDEBUG}
  2187. memprocpara.stop;
  2188. {$endif MEMDEBUG}
  2189. end;
  2190. if assigned(parast) then
  2191. begin
  2192. {$ifdef MEMDEBUG}
  2193. memprocparast.start;
  2194. {$endif MEMDEBUG}
  2195. parast.free;
  2196. parast:=nil;
  2197. {$ifdef MEMDEBUG}
  2198. memprocparast.stop;
  2199. {$endif MEMDEBUG}
  2200. end;
  2201. inherited destroy;
  2202. end;
  2203. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  2204. begin
  2205. if (tsym(p).typ<>paravarsym) then
  2206. exit;
  2207. inc(plongint(arg)^);
  2208. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2209. begin
  2210. if not assigned(tparavarsym(p).defaultconstsym) then
  2211. inc(minparacount);
  2212. inc(maxparacount);
  2213. end;
  2214. end;
  2215. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  2216. begin
  2217. if (tsym(p).typ<>paravarsym) then
  2218. exit;
  2219. paras.add(p);
  2220. end;
  2221. procedure tabstractprocdef.calcparas;
  2222. var
  2223. paracount : longint;
  2224. begin
  2225. { This can already be assigned when
  2226. we need to reresolve this unit (PFV) }
  2227. if assigned(paras) then
  2228. paras.free;
  2229. paras:=tparalist.create(false);
  2230. paracount:=0;
  2231. minparacount:=0;
  2232. maxparacount:=0;
  2233. parast.SymList.ForEachCall(@count_para,@paracount);
  2234. paras.capacity:=paracount;
  2235. { Insert parameters in table }
  2236. parast.SymList.ForEachCall(@insert_para,nil);
  2237. { Order parameters }
  2238. paras.sortparas;
  2239. end;
  2240. { all functions returning in FPU are
  2241. assume to use 2 FPU registers
  2242. until the function implementation
  2243. is processed PM }
  2244. procedure tabstractprocdef.test_if_fpu_result;
  2245. begin
  2246. {$ifdef i386}
  2247. if assigned(returndef) and
  2248. (returndef.typ=floatdef) then
  2249. fpu_used:=maxfpuregs;
  2250. {$endif i386}
  2251. end;
  2252. procedure tabstractprocdef.buildderef;
  2253. begin
  2254. { released procdef? }
  2255. if not assigned(parast) then
  2256. exit;
  2257. inherited buildderef;
  2258. returndefderef.build(returndef);
  2259. { parast }
  2260. tparasymtable(parast).buildderef;
  2261. end;
  2262. procedure tabstractprocdef.deref;
  2263. begin
  2264. inherited deref;
  2265. returndef:=tdef(returndefderef.resolve);
  2266. { parast }
  2267. tparasymtable(parast).deref;
  2268. { recalculated parameters }
  2269. calcparas;
  2270. end;
  2271. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2272. var
  2273. b : byte;
  2274. begin
  2275. inherited ppuload(dt,ppufile);
  2276. parast:=nil;
  2277. Paras:=nil;
  2278. minparacount:=0;
  2279. maxparacount:=0;
  2280. ppufile.getderef(returndefderef);
  2281. {$ifdef i386}
  2282. fpu_used:=ppufile.getbyte;
  2283. {$else}
  2284. ppufile.getbyte;
  2285. {$endif i386}
  2286. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2287. proccalloption:=tproccalloption(ppufile.getbyte);
  2288. ppufile.getnormalset(procoptions);
  2289. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2290. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2291. if po_explicitparaloc in procoptions then
  2292. begin
  2293. b:=ppufile.getbyte;
  2294. if b<>sizeof(funcretloc[callerside]) then
  2295. internalerror(200411154);
  2296. ppufile.getdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2297. end;
  2298. savesize:=sizeof(aint);
  2299. has_paraloc_info:=(po_explicitparaloc in procoptions);
  2300. end;
  2301. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2302. var
  2303. oldintfcrc : boolean;
  2304. begin
  2305. { released procdef? }
  2306. if not assigned(parast) then
  2307. exit;
  2308. inherited ppuwrite(ppufile);
  2309. ppufile.putderef(returndefderef);
  2310. oldintfcrc:=ppufile.do_interface_crc;
  2311. ppufile.do_interface_crc:=false;
  2312. {$ifdef i386}
  2313. if simplify_ppu then
  2314. fpu_used:=0;
  2315. ppufile.putbyte(fpu_used);
  2316. {$else}
  2317. ppufile.putbyte(0);
  2318. {$endif}
  2319. ppufile.putbyte(ord(proctypeoption));
  2320. ppufile.putbyte(ord(proccalloption));
  2321. ppufile.putnormalset(procoptions);
  2322. ppufile.do_interface_crc:=oldintfcrc;
  2323. if (po_explicitparaloc in procoptions) then
  2324. begin
  2325. { Make a 'valid' funcretloc for procedures }
  2326. ppufile.putbyte(sizeof(funcretloc[callerside]));
  2327. ppufile.putdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2328. end;
  2329. end;
  2330. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2331. var
  2332. hs,s : string;
  2333. hp : TParavarsym;
  2334. hpc : tconstsym;
  2335. first : boolean;
  2336. i : integer;
  2337. begin
  2338. s:='';
  2339. first:=true;
  2340. for i:=0 to paras.count-1 do
  2341. begin
  2342. hp:=tparavarsym(paras[i]);
  2343. if not(vo_is_hidden_para in hp.varoptions) or
  2344. (showhidden) then
  2345. begin
  2346. if first then
  2347. begin
  2348. s:=s+'(';
  2349. first:=false;
  2350. end
  2351. else
  2352. s:=s+',';
  2353. if vo_is_hidden_para in hp.varoptions then
  2354. s:=s+'<';
  2355. case hp.varspez of
  2356. vs_var :
  2357. s:=s+'var';
  2358. vs_const :
  2359. s:=s+'const';
  2360. vs_out :
  2361. s:=s+'out';
  2362. end;
  2363. if assigned(hp.vardef.typesym) then
  2364. begin
  2365. if s<>'(' then
  2366. s:=s+' ';
  2367. hs:=hp.vardef.typesym.realname;
  2368. if hs[1]<>'$' then
  2369. s:=s+hp.vardef.typesym.realname
  2370. else
  2371. s:=s+hp.vardef.GetTypeName;
  2372. end
  2373. else
  2374. s:=s+hp.vardef.GetTypeName;
  2375. { default value }
  2376. if assigned(hp.defaultconstsym) then
  2377. begin
  2378. hpc:=tconstsym(hp.defaultconstsym);
  2379. hs:='';
  2380. case hpc.consttyp of
  2381. conststring,
  2382. constresourcestring :
  2383. hs:=strpas(pchar(hpc.value.valueptr));
  2384. constreal :
  2385. str(pbestreal(hpc.value.valueptr)^,hs);
  2386. constpointer :
  2387. hs:=tostr(hpc.value.valueordptr);
  2388. constord :
  2389. begin
  2390. if is_boolean(hpc.constdef) then
  2391. begin
  2392. if hpc.value.valueord<>0 then
  2393. hs:='TRUE'
  2394. else
  2395. hs:='FALSE';
  2396. end
  2397. else
  2398. hs:=tostr(hpc.value.valueord);
  2399. end;
  2400. constnil :
  2401. hs:='nil';
  2402. constset :
  2403. hs:='<set>';
  2404. end;
  2405. if hs<>'' then
  2406. s:=s+'="'+hs+'"';
  2407. end;
  2408. if vo_is_hidden_para in hp.varoptions then
  2409. s:=s+'>';
  2410. end;
  2411. end;
  2412. if not first then
  2413. s:=s+')';
  2414. if (po_varargs in procoptions) then
  2415. s:=s+';VarArgs';
  2416. typename_paras:=s;
  2417. end;
  2418. function tabstractprocdef.is_methodpointer:boolean;
  2419. begin
  2420. result:=false;
  2421. end;
  2422. function tabstractprocdef.is_addressonly:boolean;
  2423. begin
  2424. result:=true;
  2425. end;
  2426. {***************************************************************************
  2427. TPROCDEF
  2428. ***************************************************************************}
  2429. constructor tprocdef.create(level:byte);
  2430. begin
  2431. inherited create(procdef,level);
  2432. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  2433. _mangledname:=nil;
  2434. fileinfo:=current_filepos;
  2435. extnumber:=$ffff;
  2436. aliasnames:=TCmdStrList.create;
  2437. funcretsym:=nil;
  2438. forwarddef:=true;
  2439. interfacedef:=false;
  2440. hasforward:=false;
  2441. _class := nil;
  2442. import_dll:=nil;
  2443. import_name:=nil;
  2444. import_nr:=0;
  2445. inlininginfo:=nil;
  2446. end;
  2447. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  2448. var
  2449. level : byte;
  2450. begin
  2451. inherited ppuload(procdef,ppufile);
  2452. if po_has_mangledname in procoptions then
  2453. _mangledname:=stringdup(ppufile.getstring)
  2454. else
  2455. _mangledname:=nil;
  2456. extnumber:=ppufile.getword;
  2457. level:=ppufile.getbyte;
  2458. ppufile.getderef(_classderef);
  2459. ppufile.getderef(procsymderef);
  2460. ppufile.getposinfo(fileinfo);
  2461. ppufile.getsmallset(symoptions);
  2462. {$ifdef powerpc}
  2463. { library symbol for AmigaOS/MorphOS }
  2464. ppufile.getderef(libsymderef);
  2465. {$endif powerpc}
  2466. { import stuff }
  2467. if po_has_importdll in procoptions then
  2468. import_dll:=stringdup(ppufile.getstring)
  2469. else
  2470. import_dll:=nil;
  2471. if po_has_importname in procoptions then
  2472. import_name:=stringdup(ppufile.getstring)
  2473. else
  2474. import_name:=nil;
  2475. import_nr:=ppufile.getword;
  2476. if (po_msgint in procoptions) then
  2477. messageinf.i:=ppufile.getlongint;
  2478. if (po_msgstr in procoptions) then
  2479. messageinf.str:=stringdup(ppufile.getstring);
  2480. if (po_dispid in procoptions) then
  2481. dispid:=ppufile.getlongint;
  2482. { inline stuff }
  2483. if (po_has_inlininginfo in procoptions) then
  2484. begin
  2485. ppufile.getderef(funcretsymderef);
  2486. new(inlininginfo);
  2487. ppufile.getsmallset(inlininginfo^.flags);
  2488. end
  2489. else
  2490. begin
  2491. inlininginfo:=nil;
  2492. funcretsym:=nil;
  2493. end;
  2494. { load para symtable }
  2495. parast:=tparasymtable.create(self,level);
  2496. tparasymtable(parast).ppuload(ppufile);
  2497. { load local symtable }
  2498. if (po_has_inlininginfo in procoptions) then
  2499. begin
  2500. localst:=tlocalsymtable.create(self,level);
  2501. tlocalsymtable(localst).ppuload(ppufile);
  2502. end
  2503. else
  2504. localst:=nil;
  2505. { inline stuff }
  2506. if (po_has_inlininginfo in procoptions) then
  2507. inlininginfo^.code:=ppuloadnodetree(ppufile);
  2508. { default values for no persistent data }
  2509. if (cs_link_deffile in current_settings.globalswitches) and
  2510. (tf_need_export in target_info.flags) and
  2511. (po_exports in procoptions) then
  2512. deffile.AddExport(mangledname);
  2513. aliasnames:=TCmdStrList.create;
  2514. forwarddef:=false;
  2515. interfacedef:=false;
  2516. hasforward:=false;
  2517. { Disable po_has_inlining until the derefimpl is done }
  2518. exclude(procoptions,po_has_inlininginfo);
  2519. end;
  2520. destructor tprocdef.destroy;
  2521. begin
  2522. aliasnames.free;
  2523. aliasnames:=nil;
  2524. if assigned(localst) and
  2525. (localst.symtabletype<>staticsymtable) then
  2526. begin
  2527. {$ifdef MEMDEBUG}
  2528. memproclocalst.start;
  2529. {$endif MEMDEBUG}
  2530. localst.free;
  2531. localst:=nil;
  2532. {$ifdef MEMDEBUG}
  2533. memproclocalst.start;
  2534. {$endif MEMDEBUG}
  2535. end;
  2536. if assigned(inlininginfo) then
  2537. begin
  2538. {$ifdef MEMDEBUG}
  2539. memprocnodetree.start;
  2540. {$endif MEMDEBUG}
  2541. tnode(inlininginfo^.code).free;
  2542. {$ifdef MEMDEBUG}
  2543. memprocnodetree.start;
  2544. {$endif MEMDEBUG}
  2545. dispose(inlininginfo);
  2546. inlininginfo:=nil;
  2547. end;
  2548. stringdispose(resultname);
  2549. stringdispose(import_dll);
  2550. stringdispose(import_name);
  2551. if (po_msgstr in procoptions) then
  2552. stringdispose(messageinf.str);
  2553. if assigned(_mangledname) then
  2554. begin
  2555. {$ifdef MEMDEBUG}
  2556. memmanglednames.start;
  2557. {$endif MEMDEBUG}
  2558. stringdispose(_mangledname);
  2559. {$ifdef MEMDEBUG}
  2560. memmanglednames.stop;
  2561. {$endif MEMDEBUG}
  2562. end;
  2563. inherited destroy;
  2564. end;
  2565. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  2566. var
  2567. oldintfcrc : boolean;
  2568. begin
  2569. { released procdef? }
  2570. if not assigned(parast) then
  2571. exit;
  2572. inherited ppuwrite(ppufile);
  2573. if po_has_mangledname in procoptions then
  2574. ppufile.putstring(_mangledname^);
  2575. ppufile.putword(extnumber);
  2576. ppufile.putbyte(parast.symtablelevel);
  2577. ppufile.putderef(_classderef);
  2578. ppufile.putderef(procsymderef);
  2579. ppufile.putposinfo(fileinfo);
  2580. ppufile.putsmallset(symoptions);
  2581. {$ifdef powerpc}
  2582. { library symbol for AmigaOS/MorphOS }
  2583. ppufile.putderef(libsymderef);
  2584. {$endif powerpc}
  2585. { import }
  2586. if po_has_importdll in procoptions then
  2587. ppufile.putstring(import_dll^);
  2588. if po_has_importname in procoptions then
  2589. ppufile.putstring(import_name^);
  2590. ppufile.putword(import_nr);
  2591. if (po_msgint in procoptions) then
  2592. ppufile.putlongint(messageinf.i);
  2593. if (po_msgstr in procoptions) then
  2594. ppufile.putstring(messageinf.str^);
  2595. if (po_dispid in procoptions) then
  2596. ppufile.putlongint(dispid);
  2597. { inline stuff }
  2598. oldintfcrc:=ppufile.do_crc;
  2599. ppufile.do_crc:=false;
  2600. if (po_has_inlininginfo in procoptions) then
  2601. begin
  2602. ppufile.putderef(funcretsymderef);
  2603. ppufile.putsmallset(inlininginfo^.flags);
  2604. end;
  2605. ppufile.do_crc:=oldintfcrc;
  2606. { write this entry }
  2607. ppufile.writeentry(ibprocdef);
  2608. { Save the para symtable, this is taken from the interface }
  2609. tparasymtable(parast).ppuwrite(ppufile);
  2610. { save localsymtable for inline procedures or when local
  2611. browser info is requested, this has no influence on the crc }
  2612. if (po_has_inlininginfo in procoptions) then
  2613. begin
  2614. oldintfcrc:=ppufile.do_crc;
  2615. ppufile.do_crc:=false;
  2616. tlocalsymtable(localst).ppuwrite(ppufile);
  2617. ppufile.do_crc:=oldintfcrc;
  2618. end;
  2619. { node tree for inlining }
  2620. oldintfcrc:=ppufile.do_crc;
  2621. ppufile.do_crc:=false;
  2622. if (po_has_inlininginfo in procoptions) then
  2623. ppuwritenodetree(ppufile,inlininginfo^.code);
  2624. ppufile.do_crc:=oldintfcrc;
  2625. end;
  2626. procedure tprocdef.reset;
  2627. begin
  2628. inherited reset;
  2629. procstarttai:=nil;
  2630. procendtai:=nil;
  2631. end;
  2632. function tprocdef.fullprocname(showhidden:boolean):string;
  2633. var
  2634. s : string;
  2635. t : ttoken;
  2636. begin
  2637. {$ifdef EXTDEBUG}
  2638. showhidden:=true;
  2639. {$endif EXTDEBUG}
  2640. s:='';
  2641. if owner.symtabletype=localsymtable then
  2642. s:=s+'local ';
  2643. if assigned(_class) then
  2644. begin
  2645. if po_classmethod in procoptions then
  2646. s:=s+'class ';
  2647. s:=s+_class.objrealname^+'.';
  2648. end;
  2649. if proctypeoption=potype_operator then
  2650. begin
  2651. for t:=NOTOKEN to last_overloaded do
  2652. if procsym.realname='$'+overloaded_names[t] then
  2653. begin
  2654. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  2655. break;
  2656. end;
  2657. end
  2658. else
  2659. s:=s+procsym.realname+typename_paras(showhidden);
  2660. case proctypeoption of
  2661. potype_constructor:
  2662. s:='constructor '+s;
  2663. potype_destructor:
  2664. s:='destructor '+s;
  2665. else
  2666. if assigned(returndef) and
  2667. not(is_void(returndef)) then
  2668. s:=s+':'+returndef.GetTypeName;
  2669. end;
  2670. { forced calling convention? }
  2671. if (po_hascallingconvention in procoptions) then
  2672. s:=s+';'+ProcCallOptionStr[proccalloption];
  2673. fullprocname:=s;
  2674. end;
  2675. function tprocdef.is_methodpointer:boolean;
  2676. begin
  2677. result:=assigned(_class);
  2678. end;
  2679. function tprocdef.is_addressonly:boolean;
  2680. begin
  2681. result:=assigned(owner) and
  2682. (owner.symtabletype<>ObjectSymtable);
  2683. end;
  2684. function tprocdef.is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
  2685. var
  2686. contextst : TSymtable;
  2687. begin
  2688. result:=false;
  2689. { Support passing a context in which module we are to find protected members }
  2690. if assigned(contextobjdef) then
  2691. contextst:=contextobjdef.owner
  2692. else
  2693. contextst:=nil;
  2694. { private symbols are allowed when we are in the same
  2695. module as they are defined }
  2696. if (sp_private in symoptions) and
  2697. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2698. not(owner.defowner.owner.iscurrentunit or (owner.defowner.owner=contextst)) then
  2699. exit;
  2700. if (sp_strictprivate in symoptions) then
  2701. begin
  2702. result:=currobjdef=tobjectdef(owner.defowner);
  2703. exit;
  2704. end;
  2705. if (sp_strictprotected in symoptions) then
  2706. begin
  2707. result:=assigned(currobjdef) and
  2708. currobjdef.is_related(tobjectdef(owner.defowner));
  2709. exit;
  2710. end;
  2711. { protected symbols are visible in the module that defines them and
  2712. also visible to related objects. The related object must be defined
  2713. in the current module }
  2714. if (sp_protected in symoptions) and
  2715. (
  2716. (
  2717. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2718. not((owner.defowner.owner.iscurrentunit) or (owner.defowner.owner=contextst))
  2719. ) and
  2720. not(
  2721. assigned(currobjdef) and
  2722. (currobjdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2723. (currobjdef.owner.iscurrentunit) and
  2724. currobjdef.is_related(tobjectdef(owner.defowner))
  2725. )
  2726. ) then
  2727. exit;
  2728. result:=true;
  2729. end;
  2730. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  2731. begin
  2732. case t of
  2733. gs_local :
  2734. GetSymtable:=localst;
  2735. gs_para :
  2736. GetSymtable:=parast;
  2737. else
  2738. GetSymtable:=nil;
  2739. end;
  2740. end;
  2741. procedure tprocdef.buildderef;
  2742. begin
  2743. inherited buildderef;
  2744. _classderef.build(_class);
  2745. { procsym that originaly defined this definition, should be in the
  2746. same symtable }
  2747. procsymderef.build(procsym);
  2748. {$ifdef powerpc}
  2749. { library symbol for AmigaOS/MorphOS }
  2750. libsymderef.build(libsym);
  2751. {$endif powerpc}
  2752. end;
  2753. procedure tprocdef.buildderefimpl;
  2754. begin
  2755. inherited buildderefimpl;
  2756. { Localst is not available for main/unit init }
  2757. if assigned(localst) then
  2758. begin
  2759. tlocalsymtable(localst).buildderef;
  2760. tlocalsymtable(localst).buildderefimpl;
  2761. end;
  2762. { inline tree }
  2763. if (po_has_inlininginfo in procoptions) then
  2764. begin
  2765. funcretsymderef.build(funcretsym);
  2766. inlininginfo^.code.buildderefimpl;
  2767. end;
  2768. end;
  2769. procedure tprocdef.deref;
  2770. begin
  2771. inherited deref;
  2772. _class:=tobjectdef(_classderef.resolve);
  2773. { procsym that originaly defined this definition, should be in the
  2774. same symtable }
  2775. procsym:=tprocsym(procsymderef.resolve);
  2776. {$ifdef powerpc}
  2777. { library symbol for AmigaOS/MorphOS }
  2778. libsym:=tsym(libsymderef.resolve);
  2779. {$endif powerpc}
  2780. end;
  2781. procedure tprocdef.derefimpl;
  2782. begin
  2783. { Enable has_inlininginfo when the inlininginfo
  2784. structure is available. The has_inlininginfo was disabled
  2785. after the load, since the data was invalid }
  2786. if assigned(inlininginfo) then
  2787. include(procoptions,po_has_inlininginfo);
  2788. { Locals }
  2789. if assigned(localst) then
  2790. begin
  2791. tlocalsymtable(localst).deref;
  2792. tlocalsymtable(localst).derefimpl;
  2793. end;
  2794. { Inline }
  2795. if (po_has_inlininginfo in procoptions) then
  2796. begin
  2797. inlininginfo^.code.derefimpl;
  2798. { funcretsym, this is always located in the localst }
  2799. funcretsym:=tsym(funcretsymderef.resolve);
  2800. end
  2801. else
  2802. begin
  2803. { safety }
  2804. funcretsym:=nil;
  2805. end;
  2806. end;
  2807. function tprocdef.GetTypeName : string;
  2808. begin
  2809. GetTypeName := FullProcName(false);
  2810. end;
  2811. function tprocdef.mangledname : string;
  2812. var
  2813. hp : TParavarsym;
  2814. hs : string;
  2815. crc : dword;
  2816. newlen,
  2817. oldlen,
  2818. i : integer;
  2819. begin
  2820. if assigned(_mangledname) then
  2821. begin
  2822. {$ifdef compress}
  2823. mangledname:=minilzw_decode(_mangledname^);
  2824. {$else}
  2825. mangledname:=_mangledname^;
  2826. {$endif}
  2827. exit;
  2828. end;
  2829. { we need to use the symtable where the procsym is inserted,
  2830. because that is visible to the world }
  2831. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  2832. oldlen:=length(mangledname);
  2833. { add parameter types }
  2834. for i:=0 to paras.count-1 do
  2835. begin
  2836. hp:=tparavarsym(paras[i]);
  2837. if not(vo_is_hidden_para in hp.varoptions) then
  2838. mangledname:=mangledname+'$'+hp.vardef.mangledparaname;
  2839. end;
  2840. { add resultdef, add $$ as separator to make it unique from a
  2841. parameter separator }
  2842. if not is_void(returndef) then
  2843. mangledname:=mangledname+'$$'+returndef.mangledparaname;
  2844. newlen:=length(mangledname);
  2845. { Replace with CRC if the parameter line is very long }
  2846. if (newlen-oldlen>12) and
  2847. ((newlen>128) or (newlen-oldlen>64)) then
  2848. begin
  2849. crc:=$ffffffff;
  2850. for i:=0 to paras.count-1 do
  2851. begin
  2852. hp:=tparavarsym(paras[i]);
  2853. if not(vo_is_hidden_para in hp.varoptions) then
  2854. begin
  2855. hs:=hp.vardef.mangledparaname;
  2856. crc:=UpdateCrc32(crc,hs[1],length(hs));
  2857. end;
  2858. end;
  2859. hs:=hp.vardef.mangledparaname;
  2860. crc:=UpdateCrc32(crc,hs[1],length(hs));
  2861. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  2862. end;
  2863. {$ifdef compress}
  2864. _mangledname:=stringdup(minilzw_encode(mangledname));
  2865. {$else}
  2866. _mangledname:=stringdup(mangledname);
  2867. {$endif}
  2868. end;
  2869. function tprocdef.cplusplusmangledname : string;
  2870. function getcppparaname(p : tdef) : string;
  2871. const
  2872. ordtype2str : array[tordtype] of string[2] = (
  2873. '',
  2874. 'Uc','Us','Ui','Us',
  2875. 'Sc','s','i','x',
  2876. 'b','b','b','b',
  2877. 'c','w','x');
  2878. var
  2879. s : string;
  2880. begin
  2881. case p.typ of
  2882. orddef:
  2883. s:=ordtype2str[torddef(p).ordtype];
  2884. pointerdef:
  2885. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  2886. else
  2887. internalerror(2103001);
  2888. end;
  2889. getcppparaname:=s;
  2890. end;
  2891. var
  2892. s,s2 : string;
  2893. hp : TParavarsym;
  2894. i : integer;
  2895. begin
  2896. { outdated gcc 2.x name mangling scheme }
  2897. {$ifdef NAMEMANGLING_GCC2}
  2898. s := procsym.realname;
  2899. if procsym.owner.symtabletype=ObjectSymtable then
  2900. begin
  2901. s2:=upper(tobjectdef(procsym.owner.defowner).objrealname^);
  2902. case proctypeoption of
  2903. potype_destructor:
  2904. s:='_$_'+tostr(length(s2))+s2;
  2905. potype_constructor:
  2906. s:='___'+tostr(length(s2))+s2;
  2907. else
  2908. s:='_'+s+'__'+tostr(length(s2))+s2;
  2909. end;
  2910. end
  2911. else s:=s+'__';
  2912. s:=s+'F';
  2913. { concat modifiers }
  2914. { !!!!! }
  2915. { now we handle the parameters }
  2916. if maxparacount>0 then
  2917. begin
  2918. for i:=0 to paras.count-1 do
  2919. begin
  2920. hp:=tparavarsym(paras[i]);
  2921. s2:=getcppparaname(hp.vardef);
  2922. if hp.varspez in [vs_var,vs_out] then
  2923. s2:='R'+s2;
  2924. s:=s+s2;
  2925. end;
  2926. end
  2927. else
  2928. s:=s+'v';
  2929. cplusplusmangledname:=s;
  2930. {$endif NAMEMANGLING_GCC2}
  2931. { gcc 3.x name mangling scheme }
  2932. if procsym.owner.symtabletype=ObjectSymtable then
  2933. begin
  2934. s:='_ZN';
  2935. s2:=tobjectdef(procsym.owner.defowner).objrealname^;
  2936. s:=s+tostr(length(s2))+s2;
  2937. case proctypeoption of
  2938. potype_constructor:
  2939. s:=s+'C1';
  2940. potype_destructor:
  2941. s:=s+'D1';
  2942. else
  2943. s:=s+tostr(length(procsym.realname))+procsym.realname;
  2944. end;
  2945. s:=s+'E';
  2946. end
  2947. else
  2948. s:=procsym.realname;
  2949. { now we handle the parameters }
  2950. if maxparacount>0 then
  2951. begin
  2952. for i:=0 to paras.count-1 do
  2953. begin
  2954. hp:=tparavarsym(paras[i]);
  2955. s2:=getcppparaname(hp.vardef);
  2956. if hp.varspez in [vs_var,vs_out] then
  2957. s2:='R'+s2;
  2958. s:=s+s2;
  2959. end;
  2960. end
  2961. else
  2962. s:=s+'v';
  2963. cplusplusmangledname:=s;
  2964. end;
  2965. procedure tprocdef.setmangledname(const s : string);
  2966. begin
  2967. { This is not allowed anymore, the forward declaration
  2968. already needs to create the correct mangledname, no changes
  2969. afterwards are allowed (PFV) }
  2970. { Exception: interface definitions in mode macpas, since in that }
  2971. { case no reference to the old name can exist yet (JM) }
  2972. if assigned(_mangledname) then
  2973. if ((m_mac in current_settings.modeswitches) and
  2974. (interfacedef)) then
  2975. stringdispose(_mangledname)
  2976. else
  2977. internalerror(200411171);
  2978. {$ifdef compress}
  2979. _mangledname:=stringdup(minilzw_encode(s));
  2980. {$else}
  2981. _mangledname:=stringdup(s);
  2982. {$endif}
  2983. include(procoptions,po_has_mangledname);
  2984. end;
  2985. {***************************************************************************
  2986. TPROCVARDEF
  2987. ***************************************************************************}
  2988. constructor tprocvardef.create(level:byte);
  2989. begin
  2990. inherited create(procvardef,level);
  2991. end;
  2992. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  2993. begin
  2994. inherited ppuload(procvardef,ppufile);
  2995. { load para symtable }
  2996. parast:=tparasymtable.create(self,unknown_level);
  2997. tparasymtable(parast).ppuload(ppufile);
  2998. end;
  2999. function tprocvardef.getcopy : tstoreddef;
  3000. var
  3001. i : tcallercallee;
  3002. j : longint;
  3003. begin
  3004. result:=tprocvardef.create(parast.symtablelevel);
  3005. tprocvardef(result).returndef:=returndef;
  3006. tprocvardef(result).returndefderef:=returndefderef;
  3007. tprocvardef(result).parast:=parast.getcopy;
  3008. tprocvardef(result).savesize:=savesize;
  3009. { create paralist copy }
  3010. tprocvardef(result).paras:=tparalist.create(false);
  3011. tprocvardef(result).paras.count:=paras.count;
  3012. for j:=0 to paras.count-1 do
  3013. tprocvardef(result).paras[j]:=paras[j];
  3014. tprocvardef(result).proctypeoption:=proctypeoption;
  3015. tprocvardef(result).proccalloption:=proccalloption;
  3016. tprocvardef(result).procoptions:=procoptions;
  3017. tprocvardef(result).requiredargarea:=requiredargarea;
  3018. tprocvardef(result).maxparacount:=maxparacount;
  3019. tprocvardef(result).minparacount:=minparacount;
  3020. for i:=low(tcallercallee) to high(tcallercallee) do
  3021. location_copy(tprocvardef(result).funcretloc[i],funcretloc[i]);
  3022. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  3023. {$ifdef i386}
  3024. tprocvardef(result).fpu_used:=fpu_used;
  3025. {$endif i386}
  3026. {$ifdef m68k}
  3027. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  3028. {$endif}
  3029. end;
  3030. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  3031. begin
  3032. { here we cannot get a real good value so just give something }
  3033. { plausible (PM) }
  3034. { a more secure way would be
  3035. to allways store in a temp }
  3036. {$ifdef i386}
  3037. if is_fpu(returndef) then
  3038. fpu_used:={2}maxfpuregs
  3039. else
  3040. fpu_used:=0;
  3041. {$endif i386}
  3042. inherited ppuwrite(ppufile);
  3043. { Write this entry }
  3044. ppufile.writeentry(ibprocvardef);
  3045. { Save the para symtable, this is taken from the interface }
  3046. tparasymtable(parast).ppuwrite(ppufile);
  3047. end;
  3048. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  3049. begin
  3050. case t of
  3051. gs_para :
  3052. GetSymtable:=parast;
  3053. else
  3054. GetSymtable:=nil;
  3055. end;
  3056. end;
  3057. function tprocvardef.size : aint;
  3058. begin
  3059. if (po_methodpointer in procoptions) and
  3060. not(po_addressonly in procoptions) then
  3061. size:=2*sizeof(aint)
  3062. else
  3063. size:=sizeof(aint);
  3064. end;
  3065. function tprocvardef.is_methodpointer:boolean;
  3066. begin
  3067. result:=(po_methodpointer in procoptions);
  3068. end;
  3069. function tprocvardef.is_addressonly:boolean;
  3070. begin
  3071. result:=not(po_methodpointer in procoptions) or
  3072. (po_addressonly in procoptions);
  3073. end;
  3074. function tprocvardef.getmangledparaname:string;
  3075. begin
  3076. result:='procvar';
  3077. end;
  3078. function tprocvardef.is_publishable : boolean;
  3079. begin
  3080. is_publishable:=(po_methodpointer in procoptions);
  3081. end;
  3082. function tprocvardef.GetTypeName : string;
  3083. var
  3084. s: string;
  3085. showhidden : boolean;
  3086. begin
  3087. {$ifdef EXTDEBUG}
  3088. showhidden:=true;
  3089. {$else EXTDEBUG}
  3090. showhidden:=false;
  3091. {$endif EXTDEBUG}
  3092. s:='<';
  3093. if po_classmethod in procoptions then
  3094. s := s+'class method type of'
  3095. else
  3096. if po_addressonly in procoptions then
  3097. s := s+'address of'
  3098. else
  3099. s := s+'procedure variable type of';
  3100. if po_local in procoptions then
  3101. s := s+' local';
  3102. if assigned(returndef) and
  3103. (returndef<>voidtype) then
  3104. s:=s+' function'+typename_paras(showhidden)+':'+returndef.GetTypeName
  3105. else
  3106. s:=s+' procedure'+typename_paras(showhidden);
  3107. if po_methodpointer in procoptions then
  3108. s := s+' of object';
  3109. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3110. end;
  3111. {***************************************************************************
  3112. TOBJECTDEF
  3113. ***************************************************************************}
  3114. constructor tobjectdef.create(ot : tobjecttyp;const n : string;c : tobjectdef);
  3115. begin
  3116. inherited create(objectdef);
  3117. objecttype:=ot;
  3118. objectoptions:=[];
  3119. childof:=nil;
  3120. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  3121. { create space for vmt !! }
  3122. vmtentries:=nil;
  3123. vmt_offset:=0;
  3124. set_parent(c);
  3125. objname:=stringdup(upper(n));
  3126. objrealname:=stringdup(n);
  3127. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3128. prepareguid;
  3129. { setup implemented interfaces }
  3130. if objecttype in [odt_class,odt_interfacecorba] then
  3131. ImplementedInterfaces:=TFPObjectList.Create(true)
  3132. else
  3133. ImplementedInterfaces:=nil;
  3134. writing_class_record_dbginfo:=false;
  3135. end;
  3136. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3137. var
  3138. i,
  3139. implintfcount : longint;
  3140. d : tderef;
  3141. ImplIntf : TImplementedInterface;
  3142. begin
  3143. inherited ppuload(objectdef,ppufile);
  3144. objecttype:=tobjecttyp(ppufile.getbyte);
  3145. objrealname:=stringdup(ppufile.getstring);
  3146. objname:=stringdup(upper(objrealname^));
  3147. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3148. tObjectSymtable(symtable).datasize:=ppufile.getaint;
  3149. tObjectSymtable(symtable).fieldalignment:=ppufile.getbyte;
  3150. tObjectSymtable(symtable).recordalignment:=ppufile.getbyte;
  3151. vmt_offset:=ppufile.getlongint;
  3152. vmtentries:=nil;
  3153. ppufile.getderef(childofderef);
  3154. ppufile.getsmallset(objectoptions);
  3155. { load guid }
  3156. iidstr:=nil;
  3157. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3158. begin
  3159. new(iidguid);
  3160. ppufile.getguid(iidguid^);
  3161. iidstr:=stringdup(ppufile.getstring);
  3162. end;
  3163. { load implemented interfaces }
  3164. if objecttype in [odt_class,odt_interfacecorba] then
  3165. begin
  3166. ImplementedInterfaces:=TFPObjectList.Create(true);
  3167. implintfcount:=ppufile.getlongint;
  3168. for i:=0 to implintfcount-1 do
  3169. begin
  3170. ppufile.getderef(d);
  3171. ImplIntf:=TImplementedInterface.Create_deref(d);
  3172. ImplIntf.IOffset:=ppufile.getlongint;
  3173. ImplementedInterfaces.Add(ImplIntf);
  3174. end;
  3175. end
  3176. else
  3177. ImplementedInterfaces:=nil;
  3178. tObjectSymtable(symtable).ppuload(ppufile);
  3179. { handles the predefined class tobject }
  3180. { the last TOBJECT which is loaded gets }
  3181. { it ! }
  3182. if (childof=nil) and
  3183. (objecttype=odt_class) and
  3184. (objname^='TOBJECT') then
  3185. class_tobject:=self;
  3186. if (childof=nil) and
  3187. (objecttype=odt_interfacecom) and
  3188. (objname^='IUNKNOWN') then
  3189. interface_iunknown:=self;
  3190. writing_class_record_dbginfo:=false;
  3191. end;
  3192. destructor tobjectdef.destroy;
  3193. begin
  3194. if assigned(symtable) then
  3195. begin
  3196. symtable.free;
  3197. symtable:=nil;
  3198. end;
  3199. stringdispose(objname);
  3200. stringdispose(objrealname);
  3201. stringdispose(iidstr);
  3202. if assigned(ImplementedInterfaces) then
  3203. begin
  3204. ImplementedInterfaces.free;
  3205. ImplementedInterfaces:=nil;
  3206. end;
  3207. if assigned(iidguid) then
  3208. begin
  3209. dispose(iidguid);
  3210. iidguid:=nil;
  3211. end;
  3212. if assigned(vmtentries) then
  3213. begin
  3214. vmtentries.free;
  3215. vmtentries:=nil;
  3216. end;
  3217. inherited destroy;
  3218. end;
  3219. function tobjectdef.getcopy : tstoreddef;
  3220. var
  3221. i : longint;
  3222. begin
  3223. result:=tobjectdef.create(objecttype,objname^,childof);
  3224. tobjectdef(result).symtable:=symtable.getcopy;
  3225. if assigned(objname) then
  3226. tobjectdef(result).objname:=stringdup(objname^);
  3227. if assigned(objrealname) then
  3228. tobjectdef(result).objrealname:=stringdup(objrealname^);
  3229. tobjectdef(result).objectoptions:=objectoptions;
  3230. tobjectdef(result).vmt_offset:=vmt_offset;
  3231. if assigned(iidguid) then
  3232. begin
  3233. new(tobjectdef(result).iidguid);
  3234. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  3235. end;
  3236. if assigned(iidstr) then
  3237. tobjectdef(result).iidstr:=stringdup(iidstr^);
  3238. if assigned(ImplementedInterfaces) then
  3239. begin
  3240. for i:=0 to ImplementedInterfaces.count-1 do
  3241. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  3242. end;
  3243. if assigned(vmtentries) then
  3244. begin
  3245. tobjectdef(result).vmtentries:=TFPobjectList.Create(false);
  3246. tobjectdef(result).vmtentries.Assign(vmtentries);
  3247. end;
  3248. end;
  3249. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3250. var
  3251. i : longint;
  3252. ImplIntf : TImplementedInterface;
  3253. begin
  3254. inherited ppuwrite(ppufile);
  3255. ppufile.putbyte(byte(objecttype));
  3256. ppufile.putstring(objrealname^);
  3257. ppufile.putaint(tObjectSymtable(symtable).datasize);
  3258. ppufile.putbyte(tObjectSymtable(symtable).fieldalignment);
  3259. ppufile.putbyte(tObjectSymtable(symtable).recordalignment);
  3260. ppufile.putlongint(vmt_offset);
  3261. ppufile.putderef(childofderef);
  3262. ppufile.putsmallset(objectoptions);
  3263. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3264. begin
  3265. ppufile.putguid(iidguid^);
  3266. ppufile.putstring(iidstr^);
  3267. end;
  3268. if objecttype in [odt_class,odt_interfacecorba] then
  3269. begin
  3270. ppufile.putlongint(ImplementedInterfaces.Count);
  3271. for i:=0 to ImplementedInterfaces.Count-1 do
  3272. begin
  3273. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3274. ppufile.putderef(ImplIntf.intfdefderef);
  3275. ppufile.putlongint(ImplIntf.Ioffset);
  3276. end;
  3277. end;
  3278. ppufile.writeentry(ibobjectdef);
  3279. tObjectSymtable(symtable).ppuwrite(ppufile);
  3280. end;
  3281. function tobjectdef.GetTypeName:string;
  3282. begin
  3283. if (self <> aktobjectdef) then
  3284. GetTypeName:=typename
  3285. else
  3286. { in this case we will go in endless recursion, because then }
  3287. { there is no tsym associated yet with the def. It can occur }
  3288. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  3289. { instead of the actual type name }
  3290. GetTypeName:='<Currently Parsed Class>';
  3291. end;
  3292. procedure tobjectdef.buildderef;
  3293. var
  3294. i : longint;
  3295. begin
  3296. inherited buildderef;
  3297. childofderef.build(childof);
  3298. tstoredsymtable(symtable).buildderef;
  3299. if objecttype in [odt_class,odt_interfacecorba] then
  3300. begin
  3301. for i:=0 to ImplementedInterfaces.count-1 do
  3302. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  3303. end;
  3304. end;
  3305. procedure tobjectdef.deref;
  3306. var
  3307. i : longint;
  3308. begin
  3309. inherited deref;
  3310. childof:=tobjectdef(childofderef.resolve);
  3311. tstoredsymtable(symtable).deref;
  3312. if objecttype in [odt_class,odt_interfacecorba] then
  3313. begin
  3314. for i:=0 to ImplementedInterfaces.count-1 do
  3315. TImplementedInterface(ImplementedInterfaces[i]).deref;
  3316. end;
  3317. end;
  3318. function tobjectdef.getparentdef:tdef;
  3319. begin
  3320. {$warning TODO Remove getparentdef hack}
  3321. { With 2 forward declared classes with the child class before the
  3322. parent class the child class is written earlier to the ppu. Leaving it
  3323. possible to have a reference to the parent class for property overriding,
  3324. but the parent class still has the childof not resolved yet (PFV) }
  3325. if childof=nil then
  3326. childof:=tobjectdef(childofderef.resolve);
  3327. result:=childof;
  3328. end;
  3329. procedure tobjectdef.prepareguid;
  3330. begin
  3331. { set up guid }
  3332. if not assigned(iidguid) then
  3333. begin
  3334. new(iidguid);
  3335. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3336. end;
  3337. { setup iidstring }
  3338. if not assigned(iidstr) then
  3339. iidstr:=stringdup(''); { default is empty string }
  3340. end;
  3341. procedure tobjectdef.set_parent( c : tobjectdef);
  3342. begin
  3343. { nothing to do if the parent was not forward !}
  3344. if assigned(childof) then
  3345. exit;
  3346. childof:=c;
  3347. { some options are inherited !! }
  3348. if assigned(c) then
  3349. begin
  3350. { only important for classes }
  3351. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  3352. if not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3353. begin
  3354. { add the data of the anchestor class }
  3355. tObjectSymtable(symtable).datasize:=
  3356. tObjectSymtable(symtable).datasize+
  3357. tObjectSymtable(c.symtable).datasize;
  3358. if (oo_has_vmt in objectoptions) and
  3359. (oo_has_vmt in c.objectoptions) then
  3360. tObjectSymtable(symtable).datasize:=
  3361. tObjectSymtable(symtable).datasize-sizeof(aint);
  3362. { if parent has a vmt field then
  3363. the offset is the same for the child PM }
  3364. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3365. begin
  3366. vmt_offset:=c.vmt_offset;
  3367. include(objectoptions,oo_has_vmt);
  3368. end;
  3369. end;
  3370. end;
  3371. end;
  3372. procedure tobjectdef.insertvmt;
  3373. begin
  3374. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3375. exit;
  3376. if (oo_has_vmt in objectoptions) then
  3377. internalerror(12345)
  3378. else
  3379. begin
  3380. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  3381. tObjectSymtable(symtable).fieldalignment);
  3382. if (tf_requires_proper_alignment in target_info.flags) then
  3383. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(aint));
  3384. vmt_offset:=tObjectSymtable(symtable).datasize;
  3385. tObjectSymtable(symtable).datasize:=
  3386. tObjectSymtable(symtable).datasize+sizeof(aint);
  3387. include(objectoptions,oo_has_vmt);
  3388. end;
  3389. end;
  3390. procedure tobjectdef.check_forwards;
  3391. begin
  3392. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3393. tstoredsymtable(symtable).check_forwards;
  3394. if (oo_is_forward in objectoptions) then
  3395. begin
  3396. { ok, in future, the forward can be resolved }
  3397. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3398. exclude(objectoptions,oo_is_forward);
  3399. end;
  3400. end;
  3401. { true, if self inherits from d (or if they are equal) }
  3402. function tobjectdef.is_related(d : tdef) : boolean;
  3403. var
  3404. hp : tobjectdef;
  3405. begin
  3406. hp:=self;
  3407. while assigned(hp) do
  3408. begin
  3409. if hp=d then
  3410. begin
  3411. is_related:=true;
  3412. exit;
  3413. end;
  3414. hp:=hp.childof;
  3415. end;
  3416. is_related:=false;
  3417. end;
  3418. function tobjectdef.FindDestructor : tprocdef;
  3419. var
  3420. objdef : tobjectdef;
  3421. i : longint;
  3422. sym : tsym;
  3423. pd : tprocdef;
  3424. begin
  3425. result:=nil;
  3426. objdef:=self;
  3427. while assigned(objdef) do
  3428. begin
  3429. for i:=0 to objdef.symtable.SymList.Count-1 do
  3430. begin
  3431. sym:=TSym(objdef.symtable.SymList[i]);
  3432. if sym.typ=procsym then
  3433. begin
  3434. pd:=Tprocsym(sym).Find_procdef_bytype(potype_destructor);
  3435. if assigned(pd) then
  3436. begin
  3437. result:=pd;
  3438. exit;
  3439. end;
  3440. end;
  3441. end;
  3442. objdef:=objdef.childof;
  3443. end;
  3444. end;
  3445. function tobjectdef.size : aint;
  3446. begin
  3447. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3448. result:=sizeof(aint)
  3449. else
  3450. result:=tObjectSymtable(symtable).datasize;
  3451. end;
  3452. function tobjectdef.alignment:shortint;
  3453. begin
  3454. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3455. alignment:=sizeof(aint)
  3456. else
  3457. alignment:=tObjectSymtable(symtable).recordalignment;
  3458. end;
  3459. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3460. begin
  3461. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3462. case objecttype of
  3463. odt_class:
  3464. { the +2*sizeof(Aint) is size and -size }
  3465. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  3466. odt_interfacecom,odt_interfacecorba:
  3467. vmtmethodoffset:=index*sizeof(aint);
  3468. else
  3469. {$ifdef WITHDMT}
  3470. vmtmethodoffset:=(index+4)*sizeof(aint);
  3471. {$else WITHDMT}
  3472. vmtmethodoffset:=(index+3)*sizeof(aint);
  3473. {$endif WITHDMT}
  3474. end;
  3475. end;
  3476. function tobjectdef.vmt_mangledname : string;
  3477. begin
  3478. if not(oo_has_vmt in objectoptions) then
  3479. Message1(parser_n_object_has_no_vmt,objrealname^);
  3480. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  3481. end;
  3482. function tobjectdef.needs_inittable : boolean;
  3483. begin
  3484. case objecttype of
  3485. odt_dispinterface,
  3486. odt_class :
  3487. needs_inittable:=false;
  3488. odt_interfacecom:
  3489. needs_inittable:=true;
  3490. odt_interfacecorba:
  3491. needs_inittable:=is_related(interface_iunknown);
  3492. odt_object:
  3493. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  3494. odt_cppclass:
  3495. needs_inittable:=false;
  3496. else
  3497. internalerror(200108267);
  3498. end;
  3499. end;
  3500. function tobjectdef.members_need_inittable : boolean;
  3501. begin
  3502. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  3503. end;
  3504. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  3505. var
  3506. ImplIntf : TImplementedInterface;
  3507. i : longint;
  3508. begin
  3509. result:=nil;
  3510. if not assigned(ImplementedInterfaces) then
  3511. exit;
  3512. for i:=0 to ImplementedInterfaces.Count-1 do
  3513. begin
  3514. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3515. if ImplIntf.intfdef=aintfdef then
  3516. begin
  3517. result:=ImplIntf;
  3518. exit;
  3519. end;
  3520. end;
  3521. end;
  3522. function tobjectdef.is_publishable : boolean;
  3523. begin
  3524. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  3525. end;
  3526. {****************************************************************************
  3527. TImplementedInterface
  3528. ****************************************************************************}
  3529. constructor TImplementedInterface.create(aintf: tobjectdef);
  3530. begin
  3531. inherited create;
  3532. intfdef:=aintf;
  3533. IOffset:=-1;
  3534. IType:=etStandard;
  3535. FieldOffset:=-1;
  3536. NameMappings:=nil;
  3537. procdefs:=nil;
  3538. end;
  3539. constructor TImplementedInterface.create_deref(d:tderef);
  3540. begin
  3541. inherited create;
  3542. intfdef:=nil;
  3543. intfdefderef:=d;
  3544. IOffset:=-1;
  3545. IType:=etStandard;
  3546. FieldOffset:=-1;
  3547. NameMappings:=nil;
  3548. procdefs:=nil;
  3549. end;
  3550. destructor TImplementedInterface.destroy;
  3551. var
  3552. i : longint;
  3553. mappedname : pshortstring;
  3554. begin
  3555. if assigned(NameMappings) then
  3556. begin
  3557. for i:=0 to NameMappings.Count-1 do
  3558. begin
  3559. mappedname:=pshortstring(NameMappings[i]);
  3560. stringdispose(mappedname);
  3561. end;
  3562. NameMappings.free;
  3563. NameMappings:=nil;
  3564. end;
  3565. if assigned(procdefs) then
  3566. begin
  3567. procdefs.free;
  3568. procdefs:=nil;
  3569. end;
  3570. inherited destroy;
  3571. end;
  3572. procedure TImplementedInterface.buildderef;
  3573. begin
  3574. intfdefderef.build(intfdef);
  3575. end;
  3576. procedure TImplementedInterface.deref;
  3577. begin
  3578. intfdef:=tobjectdef(intfdefderef.resolve);
  3579. end;
  3580. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  3581. begin
  3582. if not assigned(NameMappings) then
  3583. NameMappings:=TFPHashList.Create;
  3584. NameMappings.Add(origname,stringdup(newname));
  3585. end;
  3586. function TImplementedInterface.GetMapping(const origname: string):string;
  3587. var
  3588. mappedname : pshortstring;
  3589. begin
  3590. result:='';
  3591. if not assigned(NameMappings) then
  3592. exit;
  3593. mappedname:=PShortstring(NameMappings.Find(origname));
  3594. if assigned(mappedname) then
  3595. result:=mappedname^;
  3596. end;
  3597. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  3598. var
  3599. i : longint;
  3600. found : boolean;
  3601. begin
  3602. if not assigned(procdefs) then
  3603. procdefs:=TFPObjectList.Create(false);
  3604. { No duplicate entries of the same procdef }
  3605. found:=false;
  3606. for i:=0 to procdefs.count-1 do
  3607. if tprocdef(procdefs[i])=pd then
  3608. begin
  3609. found:=true;
  3610. break;
  3611. end;
  3612. if not found then
  3613. procdefs.Add(pd);
  3614. end;
  3615. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  3616. var
  3617. i : longint;
  3618. begin
  3619. result:=false;
  3620. weight:=0;
  3621. { empty interface is mergeable }
  3622. if ProcDefs.Count=0 then
  3623. begin
  3624. result:=true;
  3625. exit;
  3626. end;
  3627. { The interface to merge must at least the number of
  3628. procedures of this interface }
  3629. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  3630. exit;
  3631. for i:=0 to ProcDefs.Count-1 do
  3632. begin
  3633. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  3634. exit;
  3635. end;
  3636. weight:=ProcDefs.Count;
  3637. result:=true;
  3638. end;
  3639. function TImplementedInterface.getcopy:TImplementedInterface;
  3640. begin
  3641. Result:=TImplementedInterface.Create(nil);
  3642. Move(pointer(self)^,pointer(result)^,InstanceSize);
  3643. end;
  3644. {****************************************************************************
  3645. TFORWARDDEF
  3646. ****************************************************************************}
  3647. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  3648. begin
  3649. inherited create(forwarddef);
  3650. tosymname:=stringdup(s);
  3651. forwardpos:=pos;
  3652. end;
  3653. function tforwarddef.GetTypeName:string;
  3654. begin
  3655. GetTypeName:='unresolved forward to '+tosymname^;
  3656. end;
  3657. destructor tforwarddef.destroy;
  3658. begin
  3659. stringdispose(tosymname);
  3660. inherited destroy;
  3661. end;
  3662. {****************************************************************************
  3663. TUNDEFINEDDEF
  3664. ****************************************************************************}
  3665. constructor tundefineddef.create;
  3666. begin
  3667. inherited create(undefineddef);
  3668. end;
  3669. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  3670. begin
  3671. inherited ppuload(undefineddef,ppufile);
  3672. end;
  3673. function tundefineddef.GetTypeName:string;
  3674. begin
  3675. GetTypeName:='<undefined type>';
  3676. end;
  3677. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  3678. begin
  3679. inherited ppuwrite(ppufile);
  3680. ppufile.writeentry(ibundefineddef);
  3681. end;
  3682. {****************************************************************************
  3683. TERRORDEF
  3684. ****************************************************************************}
  3685. constructor terrordef.create;
  3686. begin
  3687. inherited create(errordef);
  3688. end;
  3689. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  3690. begin
  3691. { Can't write errordefs to ppu }
  3692. internalerror(200411063);
  3693. end;
  3694. function terrordef.GetTypeName:string;
  3695. begin
  3696. GetTypeName:='<erroneous type>';
  3697. end;
  3698. function terrordef.getmangledparaname:string;
  3699. begin
  3700. getmangledparaname:='error';
  3701. end;
  3702. {****************************************************************************
  3703. Definition Helpers
  3704. ****************************************************************************}
  3705. function is_interfacecom(def: tdef): boolean;
  3706. begin
  3707. is_interfacecom:=
  3708. assigned(def) and
  3709. (def.typ=objectdef) and
  3710. (tobjectdef(def).objecttype=odt_interfacecom);
  3711. end;
  3712. function is_interfacecorba(def: tdef): boolean;
  3713. begin
  3714. is_interfacecorba:=
  3715. assigned(def) and
  3716. (def.typ=objectdef) and
  3717. (tobjectdef(def).objecttype=odt_interfacecorba);
  3718. end;
  3719. function is_interface(def: tdef): boolean;
  3720. begin
  3721. is_interface:=
  3722. assigned(def) and
  3723. (def.typ=objectdef) and
  3724. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  3725. end;
  3726. function is_dispinterface(def: tdef): boolean;
  3727. begin
  3728. result:=
  3729. assigned(def) and
  3730. (def.typ=objectdef) and
  3731. (tobjectdef(def).objecttype=odt_dispinterface);
  3732. end;
  3733. function is_class(def: tdef): boolean;
  3734. begin
  3735. is_class:=
  3736. assigned(def) and
  3737. (def.typ=objectdef) and
  3738. (tobjectdef(def).objecttype=odt_class);
  3739. end;
  3740. function is_object(def: tdef): boolean;
  3741. begin
  3742. is_object:=
  3743. assigned(def) and
  3744. (def.typ=objectdef) and
  3745. (tobjectdef(def).objecttype=odt_object);
  3746. end;
  3747. function is_cppclass(def: tdef): boolean;
  3748. begin
  3749. is_cppclass:=
  3750. assigned(def) and
  3751. (def.typ=objectdef) and
  3752. (tobjectdef(def).objecttype=odt_cppclass);
  3753. end;
  3754. function is_class_or_interface(def: tdef): boolean;
  3755. begin
  3756. is_class_or_interface:=
  3757. assigned(def) and
  3758. (def.typ=objectdef) and
  3759. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  3760. end;
  3761. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  3762. begin
  3763. result:=
  3764. assigned(def) and
  3765. (def.typ=objectdef) and
  3766. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  3767. end;
  3768. {$ifdef x86}
  3769. function use_sse(def : tdef) : boolean;
  3770. begin
  3771. use_sse:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  3772. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  3773. end;
  3774. {$endif x86}
  3775. end.