symdef.pas 128 KB

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