symdef.pas 128 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328
  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 [system_powerpc_darwin,system_i386_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. {$ifdef cpurequiresproperalignment}
  1106. { char to string accesses byte 0 and 1 with one word access }
  1107. alignment:=size_2_align(2);
  1108. {$else cpurequiresproperalignment}
  1109. alignment:=size_2_align(1);
  1110. {$endif cpurequiresproperalignment}
  1111. else
  1112. internalerror(200412301);
  1113. end;
  1114. end;
  1115. function tstringdef.getmangledparaname : string;
  1116. begin
  1117. getmangledparaname:='STRING';
  1118. end;
  1119. function tstringdef.is_publishable : boolean;
  1120. begin
  1121. is_publishable:=true;
  1122. end;
  1123. {****************************************************************************
  1124. TENUMDEF
  1125. ****************************************************************************}
  1126. constructor tenumdef.create;
  1127. begin
  1128. inherited create(enumdef);
  1129. minval:=0;
  1130. maxval:=0;
  1131. calcsavesize;
  1132. has_jumps:=false;
  1133. basedef:=nil;
  1134. firstenum:=nil;
  1135. end;
  1136. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1137. begin
  1138. inherited create(enumdef);
  1139. minval:=_min;
  1140. maxval:=_max;
  1141. basedef:=_basedef;
  1142. calcsavesize;
  1143. has_jumps:=false;
  1144. firstenum:=basedef.firstenum;
  1145. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1146. firstenum:=tenumsym(firstenum).nextenum;
  1147. end;
  1148. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1149. begin
  1150. inherited ppuload(enumdef,ppufile);
  1151. ppufile.getderef(basedefderef);
  1152. minval:=ppufile.getaint;
  1153. maxval:=ppufile.getaint;
  1154. savesize:=ppufile.getaint;
  1155. has_jumps:=false;
  1156. firstenum:=Nil;
  1157. end;
  1158. function tenumdef.getcopy : tstoreddef;
  1159. begin
  1160. if assigned(basedef) then
  1161. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1162. else
  1163. begin
  1164. result:=tenumdef.create;
  1165. tenumdef(result).minval:=minval;
  1166. tenumdef(result).maxval:=maxval;
  1167. end;
  1168. tenumdef(result).has_jumps:=has_jumps;
  1169. tenumdef(result).firstenum:=firstenum;
  1170. tenumdef(result).basedefderef:=basedefderef;
  1171. end;
  1172. procedure tenumdef.calcsavesize;
  1173. begin
  1174. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1175. savesize:=8
  1176. else
  1177. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  1178. savesize:=4
  1179. else
  1180. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1181. savesize:=2
  1182. else
  1183. savesize:=1;
  1184. end;
  1185. function tenumdef.packedbitsize: aint;
  1186. var
  1187. power: longint;
  1188. begin
  1189. result := 0;
  1190. if (minval < 0) then
  1191. result := inherited packedbitsize
  1192. else
  1193. begin
  1194. if (maxval <= 1) then
  1195. result := 1
  1196. else
  1197. begin
  1198. { 256 must become 512 etc. }
  1199. nextpowerof2(maxval+1,power);
  1200. result := power;
  1201. end;
  1202. end;
  1203. end;
  1204. procedure tenumdef.setmax(_max:aint);
  1205. begin
  1206. maxval:=_max;
  1207. calcsavesize;
  1208. end;
  1209. procedure tenumdef.setmin(_min:aint);
  1210. begin
  1211. minval:=_min;
  1212. calcsavesize;
  1213. end;
  1214. function tenumdef.min:aint;
  1215. begin
  1216. min:=minval;
  1217. end;
  1218. function tenumdef.max:aint;
  1219. begin
  1220. max:=maxval;
  1221. end;
  1222. procedure tenumdef.buildderef;
  1223. begin
  1224. inherited buildderef;
  1225. basedefderef.build(basedef);
  1226. end;
  1227. procedure tenumdef.deref;
  1228. begin
  1229. inherited deref;
  1230. basedef:=tenumdef(basedefderef.resolve);
  1231. { restart ordering }
  1232. firstenum:=nil;
  1233. end;
  1234. procedure tenumdef.derefimpl;
  1235. begin
  1236. if assigned(basedef) and
  1237. (firstenum=nil) then
  1238. begin
  1239. firstenum:=basedef.firstenum;
  1240. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1241. firstenum:=tenumsym(firstenum).nextenum;
  1242. end;
  1243. end;
  1244. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1245. begin
  1246. inherited ppuwrite(ppufile);
  1247. ppufile.putderef(basedefderef);
  1248. ppufile.putaint(min);
  1249. ppufile.putaint(max);
  1250. ppufile.putaint(savesize);
  1251. ppufile.writeentry(ibenumdef);
  1252. end;
  1253. function tenumdef.is_publishable : boolean;
  1254. begin
  1255. is_publishable:=true;
  1256. end;
  1257. function tenumdef.GetTypeName : string;
  1258. begin
  1259. GetTypeName:='<enumeration type>';
  1260. end;
  1261. {****************************************************************************
  1262. TORDDEF
  1263. ****************************************************************************}
  1264. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  1265. begin
  1266. inherited create(orddef);
  1267. low:=v;
  1268. high:=b;
  1269. ordtype:=t;
  1270. setsize;
  1271. end;
  1272. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1273. begin
  1274. inherited ppuload(orddef,ppufile);
  1275. ordtype:=tordtype(ppufile.getbyte);
  1276. if sizeof(TConstExprInt)=8 then
  1277. begin
  1278. low:=ppufile.getint64;
  1279. high:=ppufile.getint64;
  1280. end
  1281. else
  1282. begin
  1283. low:=ppufile.getlongint;
  1284. high:=ppufile.getlongint;
  1285. end;
  1286. setsize;
  1287. end;
  1288. function torddef.getcopy : tstoreddef;
  1289. begin
  1290. result:=torddef.create(ordtype,low,high);
  1291. result.typ:=orddef;
  1292. torddef(result).low:=low;
  1293. torddef(result).high:=high;
  1294. torddef(result).ordtype:=ordtype;
  1295. torddef(result).savesize:=savesize;
  1296. end;
  1297. function torddef.alignment:shortint;
  1298. begin
  1299. if (target_info.system = system_i386_darwin) and
  1300. (ordtype in [s64bit,u64bit]) then
  1301. result := 4
  1302. else
  1303. result := inherited alignment;
  1304. end;
  1305. procedure torddef.setsize;
  1306. const
  1307. sizetbl : array[tordtype] of longint = (
  1308. 0,
  1309. 1,2,4,8,
  1310. 1,2,4,8,
  1311. 1,2,4,8,
  1312. 1,2,8
  1313. );
  1314. begin
  1315. savesize:=sizetbl[ordtype];
  1316. end;
  1317. function torddef.packedbitsize: aint;
  1318. var
  1319. power: longint;
  1320. begin
  1321. result := 0;
  1322. if ordtype = uvoid then
  1323. exit;
  1324. if (low < 0) then
  1325. result := inherited packedbitsize
  1326. else
  1327. begin
  1328. if (high <= 1) then
  1329. result := 1
  1330. else if (ordtype = u64bit) then
  1331. result := 64
  1332. else
  1333. begin
  1334. { 256 must become 512 etc. }
  1335. nextpowerof2(high+1,power);
  1336. result := power;
  1337. end;
  1338. end;
  1339. end;
  1340. function torddef.getvardef : longint;
  1341. const
  1342. basetype2vardef : array[tordtype] of longint = (
  1343. varUndefined,
  1344. varbyte,varqword,varlongword,varqword,
  1345. varshortint,varsmallint,varinteger,varint64,
  1346. varboolean,varUndefined,varUndefined,varUndefined,
  1347. varUndefined,varUndefined,varCurrency);
  1348. begin
  1349. result:=basetype2vardef[ordtype];
  1350. end;
  1351. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1352. begin
  1353. inherited ppuwrite(ppufile);
  1354. ppufile.putbyte(byte(ordtype));
  1355. if sizeof(TConstExprInt)=8 then
  1356. begin
  1357. ppufile.putint64(low);
  1358. ppufile.putint64(high);
  1359. end
  1360. else
  1361. begin
  1362. ppufile.putlongint(low);
  1363. ppufile.putlongint(high);
  1364. end;
  1365. ppufile.writeentry(iborddef);
  1366. end;
  1367. function torddef.is_publishable : boolean;
  1368. begin
  1369. is_publishable:=(ordtype<>uvoid);
  1370. end;
  1371. function torddef.GetTypeName : string;
  1372. const
  1373. names : array[tordtype] of string[20] = (
  1374. 'untyped',
  1375. 'Byte','Word','DWord','QWord',
  1376. 'ShortInt','SmallInt','LongInt','Int64',
  1377. 'Boolean','WordBool','LongBool','QWordBool',
  1378. 'Char','WideChar','Currency');
  1379. begin
  1380. GetTypeName:=names[ordtype];
  1381. end;
  1382. {****************************************************************************
  1383. TFLOATDEF
  1384. ****************************************************************************}
  1385. constructor tfloatdef.create(t : tfloattype);
  1386. begin
  1387. inherited create(floatdef);
  1388. floattype:=t;
  1389. setsize;
  1390. end;
  1391. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1392. begin
  1393. inherited ppuload(floatdef,ppufile);
  1394. floattype:=tfloattype(ppufile.getbyte);
  1395. setsize;
  1396. end;
  1397. function tfloatdef.getcopy : tstoreddef;
  1398. begin
  1399. result:=tfloatdef.create(floattype);
  1400. result.typ:=floatdef;
  1401. tfloatdef(result).savesize:=savesize;
  1402. end;
  1403. function tfloatdef.alignment:shortint;
  1404. begin
  1405. if (target_info.system = system_i386_darwin) then
  1406. case floattype of
  1407. s80real : result:=16;
  1408. s64real,
  1409. s64currency,
  1410. s64comp : result:=4;
  1411. else
  1412. result := inherited alignment;
  1413. end
  1414. else
  1415. result := inherited alignment;
  1416. end;
  1417. procedure tfloatdef.setsize;
  1418. begin
  1419. case floattype of
  1420. s32real : savesize:=4;
  1421. s80real : savesize:=10;
  1422. s64real,
  1423. s64currency,
  1424. s64comp : savesize:=8;
  1425. else
  1426. savesize:=0;
  1427. end;
  1428. end;
  1429. function tfloatdef.getvardef : longint;
  1430. const
  1431. floattype2vardef : array[tfloattype] of longint = (
  1432. varSingle,varDouble,varUndefined,
  1433. varUndefined,varCurrency,varUndefined);
  1434. begin
  1435. if (upper(typename)='TDATETIME') and
  1436. assigned(owner) and
  1437. assigned(owner.name) and
  1438. (owner.name^='SYSTEM') then
  1439. result:=varDate
  1440. else
  1441. result:=floattype2vardef[floattype];
  1442. end;
  1443. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1444. begin
  1445. inherited ppuwrite(ppufile);
  1446. ppufile.putbyte(byte(floattype));
  1447. ppufile.writeentry(ibfloatdef);
  1448. end;
  1449. function tfloatdef.is_publishable : boolean;
  1450. begin
  1451. is_publishable:=true;
  1452. end;
  1453. function tfloatdef.GetTypeName : string;
  1454. const
  1455. names : array[tfloattype] of string[20] = (
  1456. 'Single','Double','Extended','Comp','Currency','Float128');
  1457. begin
  1458. GetTypeName:=names[floattype];
  1459. end;
  1460. {****************************************************************************
  1461. TFILEDEF
  1462. ****************************************************************************}
  1463. constructor tfiledef.createtext;
  1464. begin
  1465. inherited create(filedef);
  1466. filetyp:=ft_text;
  1467. typedfiledef:=nil;
  1468. setsize;
  1469. end;
  1470. constructor tfiledef.createuntyped;
  1471. begin
  1472. inherited create(filedef);
  1473. filetyp:=ft_untyped;
  1474. typedfiledef:=nil;
  1475. setsize;
  1476. end;
  1477. constructor tfiledef.createtyped(def:tdef);
  1478. begin
  1479. inherited create(filedef);
  1480. filetyp:=ft_typed;
  1481. typedfiledef:=def;
  1482. setsize;
  1483. end;
  1484. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1485. begin
  1486. inherited ppuload(filedef,ppufile);
  1487. filetyp:=tfiletyp(ppufile.getbyte);
  1488. if filetyp=ft_typed then
  1489. ppufile.getderef(typedfiledefderef)
  1490. else
  1491. typedfiledef:=nil;
  1492. setsize;
  1493. end;
  1494. function tfiledef.getcopy : tstoreddef;
  1495. begin
  1496. case filetyp of
  1497. ft_typed:
  1498. result:=tfiledef.createtyped(typedfiledef);
  1499. ft_untyped:
  1500. result:=tfiledef.createuntyped;
  1501. ft_text:
  1502. result:=tfiledef.createtext;
  1503. else
  1504. internalerror(2004121201);
  1505. end;
  1506. end;
  1507. procedure tfiledef.buildderef;
  1508. begin
  1509. inherited buildderef;
  1510. if filetyp=ft_typed then
  1511. typedfiledefderef.build(typedfiledef);
  1512. end;
  1513. procedure tfiledef.deref;
  1514. begin
  1515. inherited deref;
  1516. if filetyp=ft_typed then
  1517. typedfiledef:=tdef(typedfiledefderef.resolve);
  1518. end;
  1519. procedure tfiledef.setsize;
  1520. begin
  1521. {$ifdef cpu64bit}
  1522. case filetyp of
  1523. ft_text :
  1524. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1525. savesize:=632
  1526. else
  1527. savesize:=628;
  1528. ft_typed,
  1529. ft_untyped :
  1530. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1531. savesize:=372
  1532. else
  1533. savesize:=368;
  1534. end;
  1535. {$else cpu64bit}
  1536. case filetyp of
  1537. ft_text :
  1538. savesize:=592;
  1539. ft_typed,
  1540. ft_untyped :
  1541. savesize:=332;
  1542. end;
  1543. {$endif cpu64bit}
  1544. end;
  1545. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1546. begin
  1547. inherited ppuwrite(ppufile);
  1548. ppufile.putbyte(byte(filetyp));
  1549. if filetyp=ft_typed then
  1550. ppufile.putderef(typedfiledefderef);
  1551. ppufile.writeentry(ibfiledef);
  1552. end;
  1553. function tfiledef.GetTypeName : string;
  1554. begin
  1555. case filetyp of
  1556. ft_untyped:
  1557. GetTypeName:='File';
  1558. ft_typed:
  1559. GetTypeName:='File Of '+typedfiledef.typename;
  1560. ft_text:
  1561. GetTypeName:='Text'
  1562. end;
  1563. end;
  1564. function tfiledef.getmangledparaname : string;
  1565. begin
  1566. case filetyp of
  1567. ft_untyped:
  1568. getmangledparaname:='FILE';
  1569. ft_typed:
  1570. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  1571. ft_text:
  1572. getmangledparaname:='TEXT'
  1573. end;
  1574. end;
  1575. {****************************************************************************
  1576. TVARIANTDEF
  1577. ****************************************************************************}
  1578. constructor tvariantdef.create(v : tvarianttype);
  1579. begin
  1580. inherited create(variantdef);
  1581. varianttype:=v;
  1582. setsize;
  1583. end;
  1584. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1585. begin
  1586. inherited ppuload(variantdef,ppufile);
  1587. varianttype:=tvarianttype(ppufile.getbyte);
  1588. setsize;
  1589. end;
  1590. function tvariantdef.getcopy : tstoreddef;
  1591. begin
  1592. result:=tvariantdef.create(varianttype);
  1593. end;
  1594. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1595. begin
  1596. inherited ppuwrite(ppufile);
  1597. ppufile.putbyte(byte(varianttype));
  1598. ppufile.writeentry(ibvariantdef);
  1599. end;
  1600. procedure tvariantdef.setsize;
  1601. begin
  1602. {$ifdef cpu64bit}
  1603. savesize:=24;
  1604. {$else cpu64bit}
  1605. savesize:=16;
  1606. {$endif cpu64bit}
  1607. end;
  1608. function tvariantdef.GetTypeName : string;
  1609. begin
  1610. case varianttype of
  1611. vt_normalvariant:
  1612. GetTypeName:='Variant';
  1613. vt_olevariant:
  1614. GetTypeName:='OleVariant';
  1615. end;
  1616. end;
  1617. function tvariantdef.needs_inittable : boolean;
  1618. begin
  1619. needs_inittable:=true;
  1620. end;
  1621. function tvariantdef.is_publishable : boolean;
  1622. begin
  1623. is_publishable:=true;
  1624. end;
  1625. {****************************************************************************
  1626. TABSTRACtpointerdef
  1627. ****************************************************************************}
  1628. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  1629. begin
  1630. inherited create(dt);
  1631. pointeddef:=def;
  1632. savesize:=sizeof(aint);
  1633. end;
  1634. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1635. begin
  1636. inherited ppuload(dt,ppufile);
  1637. ppufile.getderef(pointeddefderef);
  1638. savesize:=sizeof(aint);
  1639. end;
  1640. procedure tabstractpointerdef.buildderef;
  1641. begin
  1642. inherited buildderef;
  1643. pointeddefderef.build(pointeddef);
  1644. end;
  1645. procedure tabstractpointerdef.deref;
  1646. begin
  1647. inherited deref;
  1648. pointeddef:=tdef(pointeddefderef.resolve);
  1649. end;
  1650. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1651. begin
  1652. inherited ppuwrite(ppufile);
  1653. ppufile.putderef(pointeddefderef);
  1654. end;
  1655. {****************************************************************************
  1656. tpointerdef
  1657. ****************************************************************************}
  1658. constructor tpointerdef.create(def:tdef);
  1659. begin
  1660. inherited create(pointerdef,def);
  1661. is_far:=false;
  1662. end;
  1663. constructor tpointerdef.createfar(def:tdef);
  1664. begin
  1665. inherited create(pointerdef,def);
  1666. is_far:=true;
  1667. end;
  1668. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  1669. begin
  1670. inherited ppuload(pointerdef,ppufile);
  1671. is_far:=(ppufile.getbyte<>0);
  1672. end;
  1673. function tpointerdef.getcopy : tstoreddef;
  1674. begin
  1675. result:=tpointerdef.create(pointeddef);
  1676. tpointerdef(result).is_far:=is_far;
  1677. tpointerdef(result).savesize:=savesize;
  1678. end;
  1679. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1680. begin
  1681. inherited ppuwrite(ppufile);
  1682. ppufile.putbyte(byte(is_far));
  1683. ppufile.writeentry(ibpointerdef);
  1684. end;
  1685. function tpointerdef.GetTypeName : string;
  1686. begin
  1687. if is_far then
  1688. GetTypeName:='^'+pointeddef.typename+';far'
  1689. else
  1690. GetTypeName:='^'+pointeddef.typename;
  1691. end;
  1692. {****************************************************************************
  1693. TCLASSREFDEF
  1694. ****************************************************************************}
  1695. constructor tclassrefdef.create(def:tdef);
  1696. begin
  1697. inherited create(classrefdef,def);
  1698. end;
  1699. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  1700. begin
  1701. inherited ppuload(classrefdef,ppufile);
  1702. end;
  1703. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  1704. begin
  1705. inherited ppuwrite(ppufile);
  1706. ppufile.writeentry(ibclassrefdef);
  1707. end;
  1708. function tclassrefdef.GetTypeName : string;
  1709. begin
  1710. GetTypeName:='Class Of '+pointeddef.typename;
  1711. end;
  1712. function tclassrefdef.is_publishable : boolean;
  1713. begin
  1714. result:=true;
  1715. end;
  1716. {***************************************************************************
  1717. TSETDEF
  1718. ***************************************************************************}
  1719. constructor tsetdef.create(def:tdef;high : aint);
  1720. begin
  1721. inherited create(setdef);
  1722. elementdef:=def;
  1723. setbase:=0;
  1724. setmax:=high;
  1725. if high<32 then
  1726. begin
  1727. settype:=smallset;
  1728. if current_settings.setalloc=0 then { $PACKSET Fixed?}
  1729. savesize:=Sizeof(longint)
  1730. else
  1731. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1732. if savesize=3 then
  1733. savesize:=4;
  1734. end
  1735. else
  1736. if high<256 then
  1737. begin
  1738. settype:=normset;
  1739. if current_settings.setalloc=0 then { $PACKSET Fixed?}
  1740. savesize:=32
  1741. else {No, use $PACKSET VALUE for rounding}
  1742. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1743. end
  1744. else
  1745. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1746. end;
  1747. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  1748. begin
  1749. inherited ppuload(setdef,ppufile);
  1750. ppufile.getderef(elementdefderef);
  1751. settype:=tsettype(ppufile.getbyte);
  1752. savesize:=ppufile.getaint;
  1753. setbase:=ppufile.getaint;
  1754. setmax:=ppufile.getaint;
  1755. end;
  1756. function tsetdef.getcopy : tstoreddef;
  1757. begin
  1758. result:=tsetdef.create(elementdef,setmax);
  1759. { the copy might have been created with a different setalloc setting }
  1760. tsetdef(result).settype:=settype;
  1761. tsetdef(result).savesize:=savesize;
  1762. end;
  1763. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  1764. begin
  1765. inherited ppuwrite(ppufile);
  1766. ppufile.putderef(elementdefderef);
  1767. ppufile.putbyte(byte(settype));
  1768. ppufile.putaint(savesize);
  1769. ppufile.putaint(setbase);
  1770. ppufile.putaint(setmax);
  1771. ppufile.writeentry(ibsetdef);
  1772. end;
  1773. procedure tsetdef.buildderef;
  1774. begin
  1775. inherited buildderef;
  1776. elementdefderef.build(elementdef);
  1777. end;
  1778. procedure tsetdef.deref;
  1779. begin
  1780. inherited deref;
  1781. elementdef:=tdef(elementdefderef.resolve);
  1782. end;
  1783. function tsetdef.is_publishable : boolean;
  1784. begin
  1785. is_publishable:=(settype=smallset);
  1786. end;
  1787. function tsetdef.GetTypeName : string;
  1788. begin
  1789. if assigned(elementdef) then
  1790. GetTypeName:='Set Of '+elementdef.typename
  1791. else
  1792. GetTypeName:='Empty Set';
  1793. end;
  1794. {***************************************************************************
  1795. TFORMALDEF
  1796. ***************************************************************************}
  1797. constructor tformaldef.create;
  1798. begin
  1799. inherited create(formaldef);
  1800. savesize:=0;
  1801. end;
  1802. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  1803. begin
  1804. inherited ppuload(formaldef,ppufile);
  1805. savesize:=0;
  1806. end;
  1807. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  1808. begin
  1809. inherited ppuwrite(ppufile);
  1810. ppufile.writeentry(ibformaldef);
  1811. end;
  1812. function tformaldef.GetTypeName : string;
  1813. begin
  1814. GetTypeName:='<Formal type>';
  1815. end;
  1816. {***************************************************************************
  1817. TARRAYDEF
  1818. ***************************************************************************}
  1819. constructor tarraydef.create(l,h : aint;def:tdef);
  1820. begin
  1821. inherited create(arraydef);
  1822. lowrange:=l;
  1823. highrange:=h;
  1824. rangedef:=def;
  1825. _elementdef:=nil;
  1826. arrayoptions:=[];
  1827. end;
  1828. constructor tarraydef.create_from_pointer(def:tdef);
  1829. begin
  1830. { use -1 so that the elecount will not overflow }
  1831. self.create(0,$7fffffff-1,s32inttype);
  1832. arrayoptions:=[ado_IsConvertedPointer];
  1833. setelementdef(def);
  1834. end;
  1835. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  1836. begin
  1837. inherited ppuload(arraydef,ppufile);
  1838. { the addresses are calculated later }
  1839. ppufile.getderef(_elementdefderef);
  1840. ppufile.getderef(rangedefderef);
  1841. lowrange:=ppufile.getaint;
  1842. highrange:=ppufile.getaint;
  1843. ppufile.getsmallset(arrayoptions);
  1844. end;
  1845. function tarraydef.getcopy : tstoreddef;
  1846. begin
  1847. result:=tarraydef.create(lowrange,highrange,rangedef);
  1848. tarraydef(result).arrayoptions:=arrayoptions;
  1849. tarraydef(result)._elementdef:=_elementdef;
  1850. end;
  1851. procedure tarraydef.buildderef;
  1852. begin
  1853. inherited buildderef;
  1854. _elementdefderef.build(_elementdef);
  1855. rangedefderef.build(rangedef);
  1856. end;
  1857. procedure tarraydef.deref;
  1858. begin
  1859. inherited deref;
  1860. _elementdef:=tdef(_elementdefderef.resolve);
  1861. rangedef:=tdef(rangedefderef.resolve);
  1862. end;
  1863. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  1864. begin
  1865. inherited ppuwrite(ppufile);
  1866. ppufile.putderef(_elementdefderef);
  1867. ppufile.putderef(rangedefderef);
  1868. ppufile.putaint(lowrange);
  1869. ppufile.putaint(highrange);
  1870. ppufile.putsmallset(arrayoptions);
  1871. ppufile.writeentry(ibarraydef);
  1872. end;
  1873. function tarraydef.elesize : aint;
  1874. begin
  1875. if (ado_IsBitPacked in arrayoptions) then
  1876. internalerror(2006080101);
  1877. if assigned(_elementdef) then
  1878. result:=_elementdef.size
  1879. else
  1880. result:=0;
  1881. end;
  1882. function tarraydef.elepackedbitsize : aint;
  1883. begin
  1884. if not(ado_IsBitPacked in arrayoptions) then
  1885. internalerror(2006080102);
  1886. if assigned(_elementdef) then
  1887. result:=_elementdef.packedbitsize
  1888. else
  1889. result:=0;
  1890. end;
  1891. function tarraydef.elecount : aint;
  1892. var
  1893. qhigh,qlow : qword;
  1894. begin
  1895. if ado_IsDynamicArray in arrayoptions then
  1896. begin
  1897. result:=0;
  1898. exit;
  1899. end;
  1900. if (highrange>0) and (lowrange<0) then
  1901. begin
  1902. qhigh:=highrange;
  1903. qlow:=qword(-lowrange);
  1904. { prevent overflow, return -1 to indicate overflow }
  1905. if qhigh+qlow>qword(high(aint)-1) then
  1906. result:=-1
  1907. else
  1908. result:=qhigh+qlow+1;
  1909. end
  1910. else
  1911. result:=int64(highrange)-lowrange+1;
  1912. end;
  1913. function tarraydef.size : aint;
  1914. var
  1915. cachedelecount,
  1916. cachedelesize : aint;
  1917. begin
  1918. if ado_IsDynamicArray in arrayoptions then
  1919. begin
  1920. size:=sizeof(aint);
  1921. exit;
  1922. end;
  1923. { Tarraydef.size may never be called for an open array! }
  1924. if highrange<lowrange then
  1925. internalerror(99080501);
  1926. if not (ado_IsBitPacked in arrayoptions) then
  1927. cachedelesize:=elesize
  1928. else
  1929. cachedelesize := elepackedbitsize;
  1930. cachedelecount:=elecount;
  1931. if (cachedelesize = 0) then
  1932. begin
  1933. size := 0;
  1934. exit;
  1935. end;
  1936. if (cachedelecount = -1) then
  1937. begin
  1938. size := -1;
  1939. exit;
  1940. end;
  1941. { prevent overflow, return -1 to indicate overflow }
  1942. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  1943. if (cachedelecount > high(aint)) or
  1944. ((high(aint) div cachedelesize) < cachedelecount) or
  1945. { also lowrange*elesize must be < high(aint) to prevent overflow when
  1946. accessing the array, see ncgmem (PFV) }
  1947. ((high(aint) div cachedelesize) < abs(lowrange)) then
  1948. begin
  1949. result:=-1;
  1950. exit;
  1951. end;
  1952. if (ado_IsBitPacked in arrayoptions) then
  1953. size:=(cachedelesize * cachedelecount + 7) div 8
  1954. else
  1955. result:=cachedelesize*cachedelecount;
  1956. end;
  1957. procedure tarraydef.setelementdef(def:tdef);
  1958. begin
  1959. _elementdef:=def;
  1960. if not(
  1961. (ado_IsDynamicArray in arrayoptions) or
  1962. (ado_IsConvertedPointer in arrayoptions) or
  1963. (highrange<lowrange)
  1964. ) and
  1965. (size=-1) then
  1966. Message(sym_e_segment_too_large);
  1967. end;
  1968. function tarraydef.alignment : shortint;
  1969. begin
  1970. { alignment of dyn. arrays doesn't depend on the element size }
  1971. if (ado_IsDynamicArray in arrayoptions) then
  1972. alignment:=size_2_align(sizeof(aint))
  1973. { alignment is the size of the elements }
  1974. else if (elementdef.typ in [arraydef,recorddef]) or
  1975. ((elementdef.typ=objectdef) and
  1976. is_object(elementdef)) then
  1977. alignment:=elementdef.alignment
  1978. else if not (ado_IsBitPacked in arrayoptions) then
  1979. alignment:=size_2_align(elesize)
  1980. else
  1981. alignment:=packedbitsloadsize(elepackedbitsize);
  1982. end;
  1983. function tarraydef.needs_inittable : boolean;
  1984. begin
  1985. needs_inittable:=(ado_IsDynamicArray in arrayoptions) or elementdef.needs_inittable;
  1986. end;
  1987. function tarraydef.GetTypeName : string;
  1988. begin
  1989. if (ado_IsConstString in arrayoptions) then
  1990. result:='Constant String'
  1991. else if (ado_isarrayofconst in arrayoptions) or
  1992. (ado_isConstructor in arrayoptions) then
  1993. begin
  1994. if (ado_isvariant in arrayoptions) or ((highrange=-1) and (lowrange=0)) then
  1995. GetTypeName:='Array Of Const'
  1996. else
  1997. GetTypeName:='Array Of Const/Constant Open Array of '+elementdef.typename;
  1998. end
  1999. else if (ado_IsDynamicArray in arrayoptions) then
  2000. GetTypeName:='Dynamic Array Of '+elementdef.typename
  2001. else if ((highrange=-1) and (lowrange=0)) then
  2002. GetTypeName:='Open Array Of '+elementdef.typename
  2003. else
  2004. begin
  2005. result := '';
  2006. if (ado_IsBitPacked in arrayoptions) then
  2007. result:='Packed ';
  2008. if rangedef.typ=enumdef then
  2009. result:=result+'Array['+rangedef.typename+'] Of '+elementdef.typename
  2010. else
  2011. result:=result+'Array['+tostr(lowrange)+'..'+
  2012. tostr(highrange)+'] Of '+elementdef.typename
  2013. end;
  2014. end;
  2015. function tarraydef.getmangledparaname : string;
  2016. begin
  2017. if ado_isarrayofconst in arrayoptions then
  2018. getmangledparaname:='array_of_const'
  2019. else
  2020. if ((highrange=-1) and (lowrange=0)) then
  2021. getmangledparaname:='array_of_'+elementdef.mangledparaname
  2022. else
  2023. internalerror(200204176);
  2024. end;
  2025. {***************************************************************************
  2026. tabstractrecorddef
  2027. ***************************************************************************}
  2028. function tabstractrecorddef.GetSymtable(t:tGetSymtable):TSymtable;
  2029. begin
  2030. if t=gs_record then
  2031. GetSymtable:=symtable
  2032. else
  2033. GetSymtable:=nil;
  2034. end;
  2035. procedure tabstractrecorddef.reset;
  2036. begin
  2037. inherited reset;
  2038. tstoredsymtable(symtable).reset_all_defs;
  2039. end;
  2040. function tabstractrecorddef.is_packed:boolean;
  2041. begin
  2042. result:=tabstractrecordsymtable(symtable).is_packed;
  2043. end;
  2044. {***************************************************************************
  2045. trecorddef
  2046. ***************************************************************************}
  2047. constructor trecorddef.create(p : TSymtable);
  2048. begin
  2049. inherited create(recorddef);
  2050. symtable:=p;
  2051. symtable.defowner:=self;
  2052. isunion:=false;
  2053. end;
  2054. constructor trecorddef.ppuload(ppufile:tcompilerppufile);
  2055. begin
  2056. inherited ppuload(recorddef,ppufile);
  2057. symtable:=trecordsymtable.create(0);
  2058. trecordsymtable(symtable).fieldalignment:=shortint(ppufile.getbyte);
  2059. trecordsymtable(symtable).recordalignment:=shortint(ppufile.getbyte);
  2060. trecordsymtable(symtable).padalignment:=shortint(ppufile.getbyte);
  2061. trecordsymtable(symtable).usefieldalignment:=shortint(ppufile.getbyte);
  2062. { requires usefieldalignment to be set }
  2063. trecordsymtable(symtable).datasize:=ppufile.getaint;
  2064. trecordsymtable(symtable).ppuload(ppufile);
  2065. symtable.defowner:=self;
  2066. isunion:=false;
  2067. end;
  2068. destructor trecorddef.destroy;
  2069. begin
  2070. if assigned(symtable) then
  2071. begin
  2072. symtable.free;
  2073. symtable:=nil;
  2074. end;
  2075. inherited destroy;
  2076. end;
  2077. function trecorddef.getcopy : tstoreddef;
  2078. begin
  2079. result:=trecorddef.create(symtable.getcopy);
  2080. trecorddef(result).isunion:=isunion;
  2081. end;
  2082. function trecorddef.needs_inittable : boolean;
  2083. begin
  2084. needs_inittable:=trecordsymtable(symtable).needs_init_final
  2085. end;
  2086. procedure trecorddef.buildderef;
  2087. begin
  2088. inherited buildderef;
  2089. tstoredsymtable(symtable).buildderef;
  2090. end;
  2091. procedure trecorddef.deref;
  2092. begin
  2093. inherited deref;
  2094. { now dereference the definitions }
  2095. tstoredsymtable(symtable).deref;
  2096. { assign TGUID? load only from system unit }
  2097. if not(assigned(rec_tguid)) and
  2098. (upper(typename)='TGUID') and
  2099. assigned(owner) and
  2100. assigned(owner.name) and
  2101. (owner.name^='SYSTEM') then
  2102. rec_tguid:=self;
  2103. end;
  2104. procedure trecorddef.ppuwrite(ppufile:tcompilerppufile);
  2105. begin
  2106. inherited ppuwrite(ppufile);
  2107. ppufile.putbyte(byte(trecordsymtable(symtable).fieldalignment));
  2108. ppufile.putbyte(byte(trecordsymtable(symtable).recordalignment));
  2109. ppufile.putbyte(byte(trecordsymtable(symtable).padalignment));
  2110. ppufile.putbyte(byte(trecordsymtable(symtable).usefieldalignment));
  2111. ppufile.putaint(trecordsymtable(symtable).datasize);
  2112. ppufile.writeentry(ibrecorddef);
  2113. trecordsymtable(symtable).ppuwrite(ppufile);
  2114. end;
  2115. function trecorddef.size:aint;
  2116. begin
  2117. result:=trecordsymtable(symtable).datasize;
  2118. end;
  2119. function trecorddef.alignment:shortint;
  2120. begin
  2121. alignment:=trecordsymtable(symtable).recordalignment;
  2122. end;
  2123. function trecorddef.padalignment:shortint;
  2124. begin
  2125. padalignment := trecordsymtable(symtable).padalignment;
  2126. end;
  2127. function trecorddef.GetTypeName : string;
  2128. begin
  2129. GetTypeName:='<record type>'
  2130. end;
  2131. {***************************************************************************
  2132. TABSTRACTPROCDEF
  2133. ***************************************************************************}
  2134. constructor tabstractprocdef.create(dt:tdeftyp;level:byte);
  2135. begin
  2136. inherited create(dt);
  2137. parast:=tparasymtable.create(self,level);
  2138. paras:=nil;
  2139. minparacount:=0;
  2140. maxparacount:=0;
  2141. proctypeoption:=potype_none;
  2142. proccalloption:=pocall_none;
  2143. procoptions:=[];
  2144. returndef:=voidtype;
  2145. {$ifdef i386}
  2146. fpu_used:=0;
  2147. {$endif i386}
  2148. savesize:=sizeof(aint);
  2149. requiredargarea:=0;
  2150. has_paraloc_info:=false;
  2151. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2152. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2153. end;
  2154. destructor tabstractprocdef.destroy;
  2155. begin
  2156. if assigned(paras) then
  2157. begin
  2158. {$ifdef MEMDEBUG}
  2159. memprocpara.start;
  2160. {$endif MEMDEBUG}
  2161. paras.free;
  2162. paras:=nil;
  2163. {$ifdef MEMDEBUG}
  2164. memprocpara.stop;
  2165. {$endif MEMDEBUG}
  2166. end;
  2167. if assigned(parast) then
  2168. begin
  2169. {$ifdef MEMDEBUG}
  2170. memprocparast.start;
  2171. {$endif MEMDEBUG}
  2172. parast.free;
  2173. parast:=nil;
  2174. {$ifdef MEMDEBUG}
  2175. memprocparast.stop;
  2176. {$endif MEMDEBUG}
  2177. end;
  2178. inherited destroy;
  2179. end;
  2180. procedure tabstractprocdef.count_para(p:TObject;arg:pointer);
  2181. begin
  2182. if (tsym(p).typ<>paravarsym) then
  2183. exit;
  2184. inc(plongint(arg)^);
  2185. if not(vo_is_hidden_para in tparavarsym(p).varoptions) then
  2186. begin
  2187. if not assigned(tparavarsym(p).defaultconstsym) then
  2188. inc(minparacount);
  2189. inc(maxparacount);
  2190. end;
  2191. end;
  2192. procedure tabstractprocdef.insert_para(p:TObject;arg:pointer);
  2193. begin
  2194. if (tsym(p).typ<>paravarsym) then
  2195. exit;
  2196. paras.add(p);
  2197. end;
  2198. procedure tabstractprocdef.calcparas;
  2199. var
  2200. paracount : longint;
  2201. begin
  2202. { This can already be assigned when
  2203. we need to reresolve this unit (PFV) }
  2204. if assigned(paras) then
  2205. paras.free;
  2206. paras:=tparalist.create(false);
  2207. paracount:=0;
  2208. minparacount:=0;
  2209. maxparacount:=0;
  2210. parast.SymList.ForEachCall(@count_para,@paracount);
  2211. paras.capacity:=paracount;
  2212. { Insert parameters in table }
  2213. parast.SymList.ForEachCall(@insert_para,nil);
  2214. { Order parameters }
  2215. paras.sortparas;
  2216. end;
  2217. { all functions returning in FPU are
  2218. assume to use 2 FPU registers
  2219. until the function implementation
  2220. is processed PM }
  2221. procedure tabstractprocdef.test_if_fpu_result;
  2222. begin
  2223. {$ifdef i386}
  2224. if assigned(returndef) and
  2225. (returndef.typ=floatdef) then
  2226. fpu_used:=maxfpuregs;
  2227. {$endif i386}
  2228. end;
  2229. procedure tabstractprocdef.buildderef;
  2230. begin
  2231. { released procdef? }
  2232. if not assigned(parast) then
  2233. exit;
  2234. inherited buildderef;
  2235. returndefderef.build(returndef);
  2236. { parast }
  2237. tparasymtable(parast).buildderef;
  2238. end;
  2239. procedure tabstractprocdef.deref;
  2240. begin
  2241. inherited deref;
  2242. returndef:=tdef(returndefderef.resolve);
  2243. { parast }
  2244. tparasymtable(parast).deref;
  2245. { recalculated parameters }
  2246. calcparas;
  2247. end;
  2248. constructor tabstractprocdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  2249. var
  2250. b : byte;
  2251. begin
  2252. inherited ppuload(dt,ppufile);
  2253. parast:=nil;
  2254. Paras:=nil;
  2255. minparacount:=0;
  2256. maxparacount:=0;
  2257. ppufile.getderef(returndefderef);
  2258. {$ifdef i386}
  2259. fpu_used:=ppufile.getbyte;
  2260. {$else}
  2261. ppufile.getbyte;
  2262. {$endif i386}
  2263. proctypeoption:=tproctypeoption(ppufile.getbyte);
  2264. proccalloption:=tproccalloption(ppufile.getbyte);
  2265. ppufile.getnormalset(procoptions);
  2266. location_reset(funcretloc[callerside],LOC_INVALID,OS_NO);
  2267. location_reset(funcretloc[calleeside],LOC_INVALID,OS_NO);
  2268. if po_explicitparaloc in procoptions then
  2269. begin
  2270. b:=ppufile.getbyte;
  2271. if b<>sizeof(funcretloc[callerside]) then
  2272. internalerror(200411154);
  2273. ppufile.getdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2274. end;
  2275. savesize:=sizeof(aint);
  2276. has_paraloc_info:=(po_explicitparaloc in procoptions);
  2277. end;
  2278. procedure tabstractprocdef.ppuwrite(ppufile:tcompilerppufile);
  2279. var
  2280. oldintfcrc : boolean;
  2281. begin
  2282. { released procdef? }
  2283. if not assigned(parast) then
  2284. exit;
  2285. inherited ppuwrite(ppufile);
  2286. ppufile.putderef(returndefderef);
  2287. oldintfcrc:=ppufile.do_interface_crc;
  2288. ppufile.do_interface_crc:=false;
  2289. {$ifdef i386}
  2290. if simplify_ppu then
  2291. fpu_used:=0;
  2292. ppufile.putbyte(fpu_used);
  2293. {$else}
  2294. ppufile.putbyte(0);
  2295. {$endif}
  2296. ppufile.putbyte(ord(proctypeoption));
  2297. ppufile.putbyte(ord(proccalloption));
  2298. ppufile.putnormalset(procoptions);
  2299. ppufile.do_interface_crc:=oldintfcrc;
  2300. if (po_explicitparaloc in procoptions) then
  2301. begin
  2302. { Make a 'valid' funcretloc for procedures }
  2303. ppufile.putbyte(sizeof(funcretloc[callerside]));
  2304. ppufile.putdata(funcretloc[callerside],sizeof(funcretloc[callerside]));
  2305. end;
  2306. end;
  2307. function tabstractprocdef.typename_paras(showhidden:boolean) : string;
  2308. var
  2309. hs,s : string;
  2310. hp : TParavarsym;
  2311. hpc : tconstsym;
  2312. first : boolean;
  2313. i : integer;
  2314. begin
  2315. s:='';
  2316. first:=true;
  2317. for i:=0 to paras.count-1 do
  2318. begin
  2319. hp:=tparavarsym(paras[i]);
  2320. if not(vo_is_hidden_para in hp.varoptions) or
  2321. (showhidden) then
  2322. begin
  2323. if first then
  2324. begin
  2325. s:=s+'(';
  2326. first:=false;
  2327. end
  2328. else
  2329. s:=s+',';
  2330. if vo_is_hidden_para in hp.varoptions then
  2331. s:=s+'<';
  2332. case hp.varspez of
  2333. vs_var :
  2334. s:=s+'var';
  2335. vs_const :
  2336. s:=s+'const';
  2337. vs_out :
  2338. s:=s+'out';
  2339. end;
  2340. if assigned(hp.vardef.typesym) then
  2341. begin
  2342. if s<>'(' then
  2343. s:=s+' ';
  2344. hs:=hp.vardef.typesym.realname;
  2345. if hs[1]<>'$' then
  2346. s:=s+hp.vardef.typesym.realname
  2347. else
  2348. s:=s+hp.vardef.GetTypeName;
  2349. end
  2350. else
  2351. s:=s+hp.vardef.GetTypeName;
  2352. { default value }
  2353. if assigned(hp.defaultconstsym) then
  2354. begin
  2355. hpc:=tconstsym(hp.defaultconstsym);
  2356. hs:='';
  2357. case hpc.consttyp of
  2358. conststring,
  2359. constresourcestring :
  2360. hs:=strpas(pchar(hpc.value.valueptr));
  2361. constreal :
  2362. str(pbestreal(hpc.value.valueptr)^,hs);
  2363. constpointer :
  2364. hs:=tostr(hpc.value.valueordptr);
  2365. constord :
  2366. begin
  2367. if is_boolean(hpc.constdef) then
  2368. begin
  2369. if hpc.value.valueord<>0 then
  2370. hs:='TRUE'
  2371. else
  2372. hs:='FALSE';
  2373. end
  2374. else
  2375. hs:=tostr(hpc.value.valueord);
  2376. end;
  2377. constnil :
  2378. hs:='nil';
  2379. constset :
  2380. hs:='<set>';
  2381. end;
  2382. if hs<>'' then
  2383. s:=s+'="'+hs+'"';
  2384. end;
  2385. if vo_is_hidden_para in hp.varoptions then
  2386. s:=s+'>';
  2387. end;
  2388. end;
  2389. if not first then
  2390. s:=s+')';
  2391. if (po_varargs in procoptions) then
  2392. s:=s+';VarArgs';
  2393. typename_paras:=s;
  2394. end;
  2395. function tabstractprocdef.is_methodpointer:boolean;
  2396. begin
  2397. result:=false;
  2398. end;
  2399. function tabstractprocdef.is_addressonly:boolean;
  2400. begin
  2401. result:=true;
  2402. end;
  2403. {***************************************************************************
  2404. TPROCDEF
  2405. ***************************************************************************}
  2406. constructor tprocdef.create(level:byte);
  2407. begin
  2408. inherited create(procdef,level);
  2409. localst:=tlocalsymtable.create(self,parast.symtablelevel);
  2410. _mangledname:=nil;
  2411. fileinfo:=current_filepos;
  2412. extnumber:=$ffff;
  2413. aliasnames:=TCmdStrList.create;
  2414. funcretsym:=nil;
  2415. forwarddef:=true;
  2416. interfacedef:=false;
  2417. hasforward:=false;
  2418. _class := nil;
  2419. import_dll:=nil;
  2420. import_name:=nil;
  2421. import_nr:=0;
  2422. inlininginfo:=nil;
  2423. end;
  2424. constructor tprocdef.ppuload(ppufile:tcompilerppufile);
  2425. var
  2426. level : byte;
  2427. begin
  2428. inherited ppuload(procdef,ppufile);
  2429. if po_has_mangledname in procoptions then
  2430. _mangledname:=stringdup(ppufile.getstring)
  2431. else
  2432. _mangledname:=nil;
  2433. extnumber:=ppufile.getword;
  2434. level:=ppufile.getbyte;
  2435. ppufile.getderef(_classderef);
  2436. ppufile.getderef(procsymderef);
  2437. ppufile.getposinfo(fileinfo);
  2438. ppufile.getsmallset(symoptions);
  2439. {$ifdef powerpc}
  2440. { library symbol for AmigaOS/MorphOS }
  2441. ppufile.getderef(libsymderef);
  2442. {$endif powerpc}
  2443. { import stuff }
  2444. if po_has_importdll in procoptions then
  2445. import_dll:=stringdup(ppufile.getstring)
  2446. else
  2447. import_dll:=nil;
  2448. if po_has_importname in procoptions then
  2449. import_name:=stringdup(ppufile.getstring)
  2450. else
  2451. import_name:=nil;
  2452. import_nr:=ppufile.getword;
  2453. if (po_msgint in procoptions) then
  2454. messageinf.i:=ppufile.getlongint;
  2455. if (po_msgstr in procoptions) then
  2456. messageinf.str:=stringdup(ppufile.getstring);
  2457. if (po_dispid in procoptions) then
  2458. dispid:=ppufile.getlongint;
  2459. { inline stuff }
  2460. if (po_has_inlininginfo in procoptions) then
  2461. begin
  2462. ppufile.getderef(funcretsymderef);
  2463. new(inlininginfo);
  2464. ppufile.getsmallset(inlininginfo^.flags);
  2465. end
  2466. else
  2467. begin
  2468. inlininginfo:=nil;
  2469. funcretsym:=nil;
  2470. end;
  2471. { load para symtable }
  2472. parast:=tparasymtable.create(self,level);
  2473. tparasymtable(parast).ppuload(ppufile);
  2474. { load local symtable }
  2475. if (po_has_inlininginfo in procoptions) then
  2476. begin
  2477. localst:=tlocalsymtable.create(self,level);
  2478. tlocalsymtable(localst).ppuload(ppufile);
  2479. end
  2480. else
  2481. localst:=nil;
  2482. { inline stuff }
  2483. if (po_has_inlininginfo in procoptions) then
  2484. inlininginfo^.code:=ppuloadnodetree(ppufile);
  2485. { default values for no persistent data }
  2486. if (cs_link_deffile in current_settings.globalswitches) and
  2487. (tf_need_export in target_info.flags) and
  2488. (po_exports in procoptions) then
  2489. deffile.AddExport(mangledname);
  2490. aliasnames:=TCmdStrList.create;
  2491. forwarddef:=false;
  2492. interfacedef:=false;
  2493. hasforward:=false;
  2494. { Disable po_has_inlining until the derefimpl is done }
  2495. exclude(procoptions,po_has_inlininginfo);
  2496. end;
  2497. destructor tprocdef.destroy;
  2498. begin
  2499. aliasnames.free;
  2500. aliasnames:=nil;
  2501. if assigned(localst) and
  2502. (localst.symtabletype<>staticsymtable) then
  2503. begin
  2504. {$ifdef MEMDEBUG}
  2505. memproclocalst.start;
  2506. {$endif MEMDEBUG}
  2507. localst.free;
  2508. localst:=nil;
  2509. {$ifdef MEMDEBUG}
  2510. memproclocalst.start;
  2511. {$endif MEMDEBUG}
  2512. end;
  2513. if assigned(inlininginfo) then
  2514. begin
  2515. {$ifdef MEMDEBUG}
  2516. memprocnodetree.start;
  2517. {$endif MEMDEBUG}
  2518. tnode(inlininginfo^.code).free;
  2519. {$ifdef MEMDEBUG}
  2520. memprocnodetree.start;
  2521. {$endif MEMDEBUG}
  2522. dispose(inlininginfo);
  2523. inlininginfo:=nil;
  2524. end;
  2525. stringdispose(resultname);
  2526. stringdispose(import_dll);
  2527. stringdispose(import_name);
  2528. if (po_msgstr in procoptions) then
  2529. stringdispose(messageinf.str);
  2530. if assigned(_mangledname) then
  2531. begin
  2532. {$ifdef MEMDEBUG}
  2533. memmanglednames.start;
  2534. {$endif MEMDEBUG}
  2535. stringdispose(_mangledname);
  2536. {$ifdef MEMDEBUG}
  2537. memmanglednames.stop;
  2538. {$endif MEMDEBUG}
  2539. end;
  2540. inherited destroy;
  2541. end;
  2542. procedure tprocdef.ppuwrite(ppufile:tcompilerppufile);
  2543. var
  2544. oldintfcrc : boolean;
  2545. begin
  2546. { released procdef? }
  2547. if not assigned(parast) then
  2548. exit;
  2549. inherited ppuwrite(ppufile);
  2550. if po_has_mangledname in procoptions then
  2551. ppufile.putstring(_mangledname^);
  2552. ppufile.putword(extnumber);
  2553. ppufile.putbyte(parast.symtablelevel);
  2554. ppufile.putderef(_classderef);
  2555. ppufile.putderef(procsymderef);
  2556. ppufile.putposinfo(fileinfo);
  2557. ppufile.putsmallset(symoptions);
  2558. {$ifdef powerpc}
  2559. { library symbol for AmigaOS/MorphOS }
  2560. ppufile.putderef(libsymderef);
  2561. {$endif powerpc}
  2562. { import }
  2563. if po_has_importdll in procoptions then
  2564. ppufile.putstring(import_dll^);
  2565. if po_has_importname in procoptions then
  2566. ppufile.putstring(import_name^);
  2567. ppufile.putword(import_nr);
  2568. if (po_msgint in procoptions) then
  2569. ppufile.putlongint(messageinf.i);
  2570. if (po_msgstr in procoptions) then
  2571. ppufile.putstring(messageinf.str^);
  2572. if (po_dispid in procoptions) then
  2573. ppufile.putlongint(dispid);
  2574. { inline stuff }
  2575. oldintfcrc:=ppufile.do_crc;
  2576. ppufile.do_crc:=false;
  2577. if (po_has_inlininginfo in procoptions) then
  2578. begin
  2579. ppufile.putderef(funcretsymderef);
  2580. ppufile.putsmallset(inlininginfo^.flags);
  2581. end;
  2582. ppufile.do_crc:=oldintfcrc;
  2583. { write this entry }
  2584. ppufile.writeentry(ibprocdef);
  2585. { Save the para symtable, this is taken from the interface }
  2586. tparasymtable(parast).ppuwrite(ppufile);
  2587. { save localsymtable for inline procedures or when local
  2588. browser info is requested, this has no influence on the crc }
  2589. if (po_has_inlininginfo in procoptions) then
  2590. begin
  2591. oldintfcrc:=ppufile.do_crc;
  2592. ppufile.do_crc:=false;
  2593. tlocalsymtable(localst).ppuwrite(ppufile);
  2594. ppufile.do_crc:=oldintfcrc;
  2595. end;
  2596. { node tree for inlining }
  2597. oldintfcrc:=ppufile.do_crc;
  2598. ppufile.do_crc:=false;
  2599. if (po_has_inlininginfo in procoptions) then
  2600. ppuwritenodetree(ppufile,inlininginfo^.code);
  2601. ppufile.do_crc:=oldintfcrc;
  2602. end;
  2603. procedure tprocdef.reset;
  2604. begin
  2605. inherited reset;
  2606. procstarttai:=nil;
  2607. procendtai:=nil;
  2608. end;
  2609. function tprocdef.fullprocname(showhidden:boolean):string;
  2610. var
  2611. s : string;
  2612. t : ttoken;
  2613. begin
  2614. {$ifdef EXTDEBUG}
  2615. showhidden:=true;
  2616. {$endif EXTDEBUG}
  2617. s:='';
  2618. if owner.symtabletype=localsymtable then
  2619. s:=s+'local ';
  2620. if assigned(_class) then
  2621. begin
  2622. if po_classmethod in procoptions then
  2623. s:=s+'class ';
  2624. s:=s+_class.objrealname^+'.';
  2625. end;
  2626. if proctypeoption=potype_operator then
  2627. begin
  2628. for t:=NOTOKEN to last_overloaded do
  2629. if procsym.realname='$'+overloaded_names[t] then
  2630. begin
  2631. s:='operator '+arraytokeninfo[t].str+typename_paras(showhidden);
  2632. break;
  2633. end;
  2634. end
  2635. else
  2636. s:=s+procsym.realname+typename_paras(showhidden);
  2637. case proctypeoption of
  2638. potype_constructor:
  2639. s:='constructor '+s;
  2640. potype_destructor:
  2641. s:='destructor '+s;
  2642. else
  2643. if assigned(returndef) and
  2644. not(is_void(returndef)) then
  2645. s:=s+':'+returndef.GetTypeName;
  2646. end;
  2647. { forced calling convention? }
  2648. if (po_hascallingconvention in procoptions) then
  2649. s:=s+';'+ProcCallOptionStr[proccalloption];
  2650. fullprocname:=s;
  2651. end;
  2652. function tprocdef.is_methodpointer:boolean;
  2653. begin
  2654. result:=assigned(_class);
  2655. end;
  2656. function tprocdef.is_addressonly:boolean;
  2657. begin
  2658. result:=assigned(owner) and
  2659. (owner.symtabletype<>ObjectSymtable);
  2660. end;
  2661. function tprocdef.is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
  2662. var
  2663. contextst : TSymtable;
  2664. begin
  2665. result:=false;
  2666. { Support passing a context in which module we are to find protected members }
  2667. if assigned(contextobjdef) then
  2668. contextst:=contextobjdef.owner
  2669. else
  2670. contextst:=nil;
  2671. { private symbols are allowed when we are in the same
  2672. module as they are defined }
  2673. if (sp_private in symoptions) and
  2674. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2675. not(owner.defowner.owner.iscurrentunit or (owner.defowner.owner=contextst)) then
  2676. exit;
  2677. if (sp_strictprivate in symoptions) then
  2678. begin
  2679. result:=currobjdef=tobjectdef(owner.defowner);
  2680. exit;
  2681. end;
  2682. if (sp_strictprotected in symoptions) then
  2683. begin
  2684. result:=assigned(currobjdef) and
  2685. currobjdef.is_related(tobjectdef(owner.defowner));
  2686. exit;
  2687. end;
  2688. { protected symbols are visible in the module that defines them and
  2689. also visible to related objects. The related object must be defined
  2690. in the current module }
  2691. if (sp_protected in symoptions) and
  2692. (
  2693. (
  2694. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2695. not((owner.defowner.owner.iscurrentunit) or (owner.defowner.owner=contextst))
  2696. ) and
  2697. not(
  2698. assigned(currobjdef) and
  2699. (currobjdef.owner.symtabletype in [globalsymtable,staticsymtable]) and
  2700. (currobjdef.owner.iscurrentunit) and
  2701. currobjdef.is_related(tobjectdef(owner.defowner))
  2702. )
  2703. ) then
  2704. exit;
  2705. result:=true;
  2706. end;
  2707. function tprocdef.GetSymtable(t:tGetSymtable):TSymtable;
  2708. begin
  2709. case t of
  2710. gs_local :
  2711. GetSymtable:=localst;
  2712. gs_para :
  2713. GetSymtable:=parast;
  2714. else
  2715. GetSymtable:=nil;
  2716. end;
  2717. end;
  2718. procedure tprocdef.buildderef;
  2719. begin
  2720. inherited buildderef;
  2721. _classderef.build(_class);
  2722. { procsym that originaly defined this definition, should be in the
  2723. same symtable }
  2724. procsymderef.build(procsym);
  2725. {$ifdef powerpc}
  2726. { library symbol for AmigaOS/MorphOS }
  2727. libsymderef.build(libsym);
  2728. {$endif powerpc}
  2729. end;
  2730. procedure tprocdef.buildderefimpl;
  2731. begin
  2732. inherited buildderefimpl;
  2733. { Localst is not available for main/unit init }
  2734. if assigned(localst) then
  2735. begin
  2736. tlocalsymtable(localst).buildderef;
  2737. tlocalsymtable(localst).buildderefimpl;
  2738. end;
  2739. { inline tree }
  2740. if (po_has_inlininginfo in procoptions) then
  2741. begin
  2742. funcretsymderef.build(funcretsym);
  2743. inlininginfo^.code.buildderefimpl;
  2744. end;
  2745. end;
  2746. procedure tprocdef.deref;
  2747. begin
  2748. inherited deref;
  2749. _class:=tobjectdef(_classderef.resolve);
  2750. { procsym that originaly defined this definition, should be in the
  2751. same symtable }
  2752. procsym:=tprocsym(procsymderef.resolve);
  2753. {$ifdef powerpc}
  2754. { library symbol for AmigaOS/MorphOS }
  2755. libsym:=tsym(libsymderef.resolve);
  2756. {$endif powerpc}
  2757. end;
  2758. procedure tprocdef.derefimpl;
  2759. begin
  2760. { Enable has_inlininginfo when the inlininginfo
  2761. structure is available. The has_inlininginfo was disabled
  2762. after the load, since the data was invalid }
  2763. if assigned(inlininginfo) then
  2764. include(procoptions,po_has_inlininginfo);
  2765. { Locals }
  2766. if assigned(localst) then
  2767. begin
  2768. tlocalsymtable(localst).deref;
  2769. tlocalsymtable(localst).derefimpl;
  2770. end;
  2771. { Inline }
  2772. if (po_has_inlininginfo in procoptions) then
  2773. begin
  2774. inlininginfo^.code.derefimpl;
  2775. { funcretsym, this is always located in the localst }
  2776. funcretsym:=tsym(funcretsymderef.resolve);
  2777. end
  2778. else
  2779. begin
  2780. { safety }
  2781. funcretsym:=nil;
  2782. end;
  2783. end;
  2784. function tprocdef.GetTypeName : string;
  2785. begin
  2786. GetTypeName := FullProcName(false);
  2787. end;
  2788. function tprocdef.mangledname : string;
  2789. var
  2790. hp : TParavarsym;
  2791. hs : string;
  2792. crc : dword;
  2793. newlen,
  2794. oldlen,
  2795. i : integer;
  2796. begin
  2797. if assigned(_mangledname) then
  2798. begin
  2799. {$ifdef compress}
  2800. mangledname:=minilzw_decode(_mangledname^);
  2801. {$else}
  2802. mangledname:=_mangledname^;
  2803. {$endif}
  2804. exit;
  2805. end;
  2806. { we need to use the symtable where the procsym is inserted,
  2807. because that is visible to the world }
  2808. mangledname:=make_mangledname('',procsym.owner,procsym.name);
  2809. oldlen:=length(mangledname);
  2810. { add parameter types }
  2811. for i:=0 to paras.count-1 do
  2812. begin
  2813. hp:=tparavarsym(paras[i]);
  2814. if not(vo_is_hidden_para in hp.varoptions) then
  2815. mangledname:=mangledname+'$'+hp.vardef.mangledparaname;
  2816. end;
  2817. { add resultdef, add $$ as separator to make it unique from a
  2818. parameter separator }
  2819. if not is_void(returndef) then
  2820. mangledname:=mangledname+'$$'+returndef.mangledparaname;
  2821. newlen:=length(mangledname);
  2822. { Replace with CRC if the parameter line is very long }
  2823. if (newlen-oldlen>12) and
  2824. ((newlen>128) or (newlen-oldlen>64)) then
  2825. begin
  2826. crc:=$ffffffff;
  2827. for i:=0 to paras.count-1 do
  2828. begin
  2829. hp:=tparavarsym(paras[i]);
  2830. if not(vo_is_hidden_para in hp.varoptions) then
  2831. begin
  2832. hs:=hp.vardef.mangledparaname;
  2833. crc:=UpdateCrc32(crc,hs[1],length(hs));
  2834. end;
  2835. end;
  2836. hs:=hp.vardef.mangledparaname;
  2837. crc:=UpdateCrc32(crc,hs[1],length(hs));
  2838. mangledname:=Copy(mangledname,1,oldlen)+'$crc'+hexstr(crc,8);
  2839. end;
  2840. {$ifdef compress}
  2841. _mangledname:=stringdup(minilzw_encode(mangledname));
  2842. {$else}
  2843. _mangledname:=stringdup(mangledname);
  2844. {$endif}
  2845. end;
  2846. function tprocdef.cplusplusmangledname : string;
  2847. function getcppparaname(p : tdef) : string;
  2848. const
  2849. ordtype2str : array[tordtype] of string[2] = (
  2850. '',
  2851. 'Uc','Us','Ui','Us',
  2852. 'Sc','s','i','x',
  2853. 'b','b','b','b',
  2854. 'c','w','x');
  2855. var
  2856. s : string;
  2857. begin
  2858. case p.typ of
  2859. orddef:
  2860. s:=ordtype2str[torddef(p).ordtype];
  2861. pointerdef:
  2862. s:='P'+getcppparaname(tpointerdef(p).pointeddef);
  2863. else
  2864. internalerror(2103001);
  2865. end;
  2866. getcppparaname:=s;
  2867. end;
  2868. var
  2869. s,s2 : string;
  2870. hp : TParavarsym;
  2871. i : integer;
  2872. begin
  2873. s := procsym.realname;
  2874. if procsym.owner.symtabletype=ObjectSymtable then
  2875. begin
  2876. s2:=upper(tobjectdef(procsym.owner.defowner).typesym.realname);
  2877. case proctypeoption of
  2878. potype_destructor:
  2879. s:='_$_'+tostr(length(s2))+s2;
  2880. potype_constructor:
  2881. s:='___'+tostr(length(s2))+s2;
  2882. else
  2883. s:='_'+s+'__'+tostr(length(s2))+s2;
  2884. end;
  2885. end
  2886. else s:=s+'__';
  2887. s:=s+'F';
  2888. { concat modifiers }
  2889. { !!!!! }
  2890. { now we handle the parameters }
  2891. if maxparacount>0 then
  2892. begin
  2893. for i:=0 to paras.count-1 do
  2894. begin
  2895. hp:=tparavarsym(paras[i]);
  2896. s2:=getcppparaname(hp.vardef);
  2897. if hp.varspez in [vs_var,vs_out] then
  2898. s2:='R'+s2;
  2899. s:=s+s2;
  2900. end;
  2901. end
  2902. else
  2903. s:=s+'v';
  2904. cplusplusmangledname:=s;
  2905. end;
  2906. procedure tprocdef.setmangledname(const s : string);
  2907. begin
  2908. { This is not allowed anymore, the forward declaration
  2909. already needs to create the correct mangledname, no changes
  2910. afterwards are allowed (PFV) }
  2911. { Exception: interface definitions in mode macpas, since in that }
  2912. { case no reference to the old name can exist yet (JM) }
  2913. if assigned(_mangledname) then
  2914. if ((m_mac in current_settings.modeswitches) and
  2915. (interfacedef)) then
  2916. stringdispose(_mangledname)
  2917. else
  2918. internalerror(200411171);
  2919. {$ifdef compress}
  2920. _mangledname:=stringdup(minilzw_encode(s));
  2921. {$else}
  2922. _mangledname:=stringdup(s);
  2923. {$endif}
  2924. include(procoptions,po_has_mangledname);
  2925. end;
  2926. {***************************************************************************
  2927. TPROCVARDEF
  2928. ***************************************************************************}
  2929. constructor tprocvardef.create(level:byte);
  2930. begin
  2931. inherited create(procvardef,level);
  2932. end;
  2933. constructor tprocvardef.ppuload(ppufile:tcompilerppufile);
  2934. begin
  2935. inherited ppuload(procvardef,ppufile);
  2936. { load para symtable }
  2937. parast:=tparasymtable.create(self,unknown_level);
  2938. tparasymtable(parast).ppuload(ppufile);
  2939. end;
  2940. function tprocvardef.getcopy : tstoreddef;
  2941. var
  2942. i : tcallercallee;
  2943. j : longint;
  2944. begin
  2945. result:=tprocvardef.create(parast.symtablelevel);
  2946. tprocvardef(result).returndef:=returndef;
  2947. tprocvardef(result).returndefderef:=returndefderef;
  2948. tprocvardef(result).parast:=parast.getcopy;
  2949. tprocvardef(result).savesize:=savesize;
  2950. { create paralist copy }
  2951. tprocvardef(result).paras:=tparalist.create(false);
  2952. tprocvardef(result).paras.count:=paras.count;
  2953. for j:=0 to paras.count-1 do
  2954. tprocvardef(result).paras[j]:=paras[j];
  2955. tprocvardef(result).proctypeoption:=proctypeoption;
  2956. tprocvardef(result).proccalloption:=proccalloption;
  2957. tprocvardef(result).procoptions:=procoptions;
  2958. tprocvardef(result).requiredargarea:=requiredargarea;
  2959. tprocvardef(result).maxparacount:=maxparacount;
  2960. tprocvardef(result).minparacount:=minparacount;
  2961. for i:=low(tcallercallee) to high(tcallercallee) do
  2962. location_copy(tprocvardef(result).funcretloc[i],funcretloc[i]);
  2963. tprocvardef(result).has_paraloc_info:=has_paraloc_info;
  2964. {$ifdef i386}
  2965. tprocvardef(result).fpu_used:=fpu_used;
  2966. {$endif i386}
  2967. {$ifdef m68k}
  2968. tprocvardef(result).exp_funcretloc:=exp_funcretloc;
  2969. {$endif}
  2970. end;
  2971. procedure tprocvardef.ppuwrite(ppufile:tcompilerppufile);
  2972. begin
  2973. { here we cannot get a real good value so just give something }
  2974. { plausible (PM) }
  2975. { a more secure way would be
  2976. to allways store in a temp }
  2977. {$ifdef i386}
  2978. if is_fpu(returndef) then
  2979. fpu_used:={2}maxfpuregs
  2980. else
  2981. fpu_used:=0;
  2982. {$endif i386}
  2983. inherited ppuwrite(ppufile);
  2984. { Write this entry }
  2985. ppufile.writeentry(ibprocvardef);
  2986. { Save the para symtable, this is taken from the interface }
  2987. tparasymtable(parast).ppuwrite(ppufile);
  2988. end;
  2989. function tprocvardef.GetSymtable(t:tGetSymtable):TSymtable;
  2990. begin
  2991. case t of
  2992. gs_para :
  2993. GetSymtable:=parast;
  2994. else
  2995. GetSymtable:=nil;
  2996. end;
  2997. end;
  2998. function tprocvardef.size : aint;
  2999. begin
  3000. if (po_methodpointer in procoptions) and
  3001. not(po_addressonly in procoptions) then
  3002. size:=2*sizeof(aint)
  3003. else
  3004. size:=sizeof(aint);
  3005. end;
  3006. function tprocvardef.is_methodpointer:boolean;
  3007. begin
  3008. result:=(po_methodpointer in procoptions);
  3009. end;
  3010. function tprocvardef.is_addressonly:boolean;
  3011. begin
  3012. result:=not(po_methodpointer in procoptions) or
  3013. (po_addressonly in procoptions);
  3014. end;
  3015. function tprocvardef.getmangledparaname:string;
  3016. begin
  3017. result:='procvar';
  3018. end;
  3019. function tprocvardef.is_publishable : boolean;
  3020. begin
  3021. is_publishable:=(po_methodpointer in procoptions);
  3022. end;
  3023. function tprocvardef.GetTypeName : string;
  3024. var
  3025. s: string;
  3026. showhidden : boolean;
  3027. begin
  3028. {$ifdef EXTDEBUG}
  3029. showhidden:=true;
  3030. {$else EXTDEBUG}
  3031. showhidden:=false;
  3032. {$endif EXTDEBUG}
  3033. s:='<';
  3034. if po_classmethod in procoptions then
  3035. s := s+'class method type of'
  3036. else
  3037. if po_addressonly in procoptions then
  3038. s := s+'address of'
  3039. else
  3040. s := s+'procedure variable type of';
  3041. if po_local in procoptions then
  3042. s := s+' local';
  3043. if assigned(returndef) and
  3044. (returndef<>voidtype) then
  3045. s:=s+' function'+typename_paras(showhidden)+':'+returndef.GetTypeName
  3046. else
  3047. s:=s+' procedure'+typename_paras(showhidden);
  3048. if po_methodpointer in procoptions then
  3049. s := s+' of object';
  3050. GetTypeName := s+';'+ProcCallOptionStr[proccalloption]+'>';
  3051. end;
  3052. {***************************************************************************
  3053. TOBJECTDEF
  3054. ***************************************************************************}
  3055. constructor tobjectdef.create(ot : tobjecttyp;const n : string;c : tobjectdef);
  3056. begin
  3057. inherited create(objectdef);
  3058. objecttype:=ot;
  3059. objectoptions:=[];
  3060. childof:=nil;
  3061. symtable:=tObjectSymtable.create(self,n,current_settings.packrecords);
  3062. { create space for vmt !! }
  3063. vmtentries:=nil;
  3064. vmt_offset:=0;
  3065. set_parent(c);
  3066. objname:=stringdup(upper(n));
  3067. objrealname:=stringdup(n);
  3068. if objecttype in [odt_interfacecorba,odt_interfacecom,odt_dispinterface] then
  3069. prepareguid;
  3070. { setup implemented interfaces }
  3071. if objecttype in [odt_class,odt_interfacecorba] then
  3072. ImplementedInterfaces:=TFPObjectList.Create(true)
  3073. else
  3074. ImplementedInterfaces:=nil;
  3075. writing_class_record_dbginfo:=false;
  3076. end;
  3077. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3078. var
  3079. i,
  3080. implintfcount : longint;
  3081. d : tderef;
  3082. ImplIntf : TImplementedInterface;
  3083. begin
  3084. inherited ppuload(objectdef,ppufile);
  3085. objecttype:=tobjecttyp(ppufile.getbyte);
  3086. objrealname:=stringdup(ppufile.getstring);
  3087. objname:=stringdup(upper(objrealname^));
  3088. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3089. tObjectSymtable(symtable).datasize:=ppufile.getaint;
  3090. tObjectSymtable(symtable).fieldalignment:=ppufile.getbyte;
  3091. tObjectSymtable(symtable).recordalignment:=ppufile.getbyte;
  3092. vmt_offset:=ppufile.getlongint;
  3093. vmtentries:=nil;
  3094. ppufile.getderef(childofderef);
  3095. ppufile.getsmallset(objectoptions);
  3096. { load guid }
  3097. iidstr:=nil;
  3098. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3099. begin
  3100. new(iidguid);
  3101. ppufile.getguid(iidguid^);
  3102. iidstr:=stringdup(ppufile.getstring);
  3103. end;
  3104. { load implemented interfaces }
  3105. if objecttype in [odt_class,odt_interfacecorba] then
  3106. begin
  3107. ImplementedInterfaces:=TFPObjectList.Create(true);
  3108. implintfcount:=ppufile.getlongint;
  3109. for i:=0 to implintfcount-1 do
  3110. begin
  3111. ppufile.getderef(d);
  3112. ImplIntf:=TImplementedInterface.Create_deref(d);
  3113. ImplIntf.IOffset:=ppufile.getlongint;
  3114. ImplementedInterfaces.Add(ImplIntf);
  3115. end;
  3116. end
  3117. else
  3118. ImplementedInterfaces:=nil;
  3119. tObjectSymtable(symtable).ppuload(ppufile);
  3120. { handles the predefined class tobject }
  3121. { the last TOBJECT which is loaded gets }
  3122. { it ! }
  3123. if (childof=nil) and
  3124. (objecttype=odt_class) and
  3125. (objname^='TOBJECT') then
  3126. class_tobject:=self;
  3127. if (childof=nil) and
  3128. (objecttype=odt_interfacecom) and
  3129. (objname^='IUNKNOWN') then
  3130. interface_iunknown:=self;
  3131. writing_class_record_dbginfo:=false;
  3132. end;
  3133. destructor tobjectdef.destroy;
  3134. begin
  3135. if assigned(symtable) then
  3136. begin
  3137. symtable.free;
  3138. symtable:=nil;
  3139. end;
  3140. stringdispose(objname);
  3141. stringdispose(objrealname);
  3142. stringdispose(iidstr);
  3143. if assigned(ImplementedInterfaces) then
  3144. begin
  3145. ImplementedInterfaces.free;
  3146. ImplementedInterfaces:=nil;
  3147. end;
  3148. if assigned(iidguid) then
  3149. begin
  3150. dispose(iidguid);
  3151. iidguid:=nil;
  3152. end;
  3153. if assigned(vmtentries) then
  3154. begin
  3155. vmtentries.free;
  3156. vmtentries:=nil;
  3157. end;
  3158. inherited destroy;
  3159. end;
  3160. function tobjectdef.getcopy : tstoreddef;
  3161. var
  3162. i : longint;
  3163. begin
  3164. result:=tobjectdef.create(objecttype,objname^,childof);
  3165. tobjectdef(result).symtable:=symtable.getcopy;
  3166. if assigned(objname) then
  3167. tobjectdef(result).objname:=stringdup(objname^);
  3168. if assigned(objrealname) then
  3169. tobjectdef(result).objrealname:=stringdup(objrealname^);
  3170. tobjectdef(result).objectoptions:=objectoptions;
  3171. tobjectdef(result).vmt_offset:=vmt_offset;
  3172. if assigned(iidguid) then
  3173. begin
  3174. new(tobjectdef(result).iidguid);
  3175. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  3176. end;
  3177. if assigned(iidstr) then
  3178. tobjectdef(result).iidstr:=stringdup(iidstr^);
  3179. if assigned(ImplementedInterfaces) then
  3180. begin
  3181. for i:=0 to ImplementedInterfaces.count-1 do
  3182. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  3183. end;
  3184. if assigned(vmtentries) then
  3185. begin
  3186. tobjectdef(result).vmtentries:=TFPobjectList.Create(false);
  3187. tobjectdef(result).vmtentries.Assign(vmtentries);
  3188. end;
  3189. end;
  3190. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3191. var
  3192. i : longint;
  3193. ImplIntf : TImplementedInterface;
  3194. begin
  3195. inherited ppuwrite(ppufile);
  3196. ppufile.putbyte(byte(objecttype));
  3197. ppufile.putstring(objrealname^);
  3198. ppufile.putaint(tObjectSymtable(symtable).datasize);
  3199. ppufile.putbyte(tObjectSymtable(symtable).fieldalignment);
  3200. ppufile.putbyte(tObjectSymtable(symtable).recordalignment);
  3201. ppufile.putlongint(vmt_offset);
  3202. ppufile.putderef(childofderef);
  3203. ppufile.putsmallset(objectoptions);
  3204. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3205. begin
  3206. ppufile.putguid(iidguid^);
  3207. ppufile.putstring(iidstr^);
  3208. end;
  3209. if objecttype in [odt_class,odt_interfacecorba] then
  3210. begin
  3211. ppufile.putlongint(ImplementedInterfaces.Count);
  3212. for i:=0 to ImplementedInterfaces.Count-1 do
  3213. begin
  3214. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3215. ppufile.putderef(ImplIntf.intfdefderef);
  3216. ppufile.putlongint(ImplIntf.Ioffset);
  3217. end;
  3218. end;
  3219. ppufile.writeentry(ibobjectdef);
  3220. tObjectSymtable(symtable).ppuwrite(ppufile);
  3221. end;
  3222. function tobjectdef.GetTypeName:string;
  3223. begin
  3224. if (self <> aktobjectdef) then
  3225. GetTypeName:=typename
  3226. else
  3227. { in this case we will go in endless recursion, because then }
  3228. { there is no tsym associated yet with the def. It can occur }
  3229. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  3230. { instead of the actual type name }
  3231. GetTypeName:='<Currently Parsed Class>';
  3232. end;
  3233. procedure tobjectdef.buildderef;
  3234. var
  3235. i : longint;
  3236. begin
  3237. inherited buildderef;
  3238. childofderef.build(childof);
  3239. tstoredsymtable(symtable).buildderef;
  3240. if objecttype in [odt_class,odt_interfacecorba] then
  3241. begin
  3242. for i:=0 to ImplementedInterfaces.count-1 do
  3243. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  3244. end;
  3245. end;
  3246. procedure tobjectdef.deref;
  3247. var
  3248. i : longint;
  3249. begin
  3250. inherited deref;
  3251. childof:=tobjectdef(childofderef.resolve);
  3252. tstoredsymtable(symtable).deref;
  3253. if objecttype in [odt_class,odt_interfacecorba] then
  3254. begin
  3255. for i:=0 to ImplementedInterfaces.count-1 do
  3256. TImplementedInterface(ImplementedInterfaces[i]).deref;
  3257. end;
  3258. end;
  3259. function tobjectdef.getparentdef:tdef;
  3260. begin
  3261. {$warning TODO Remove getparentdef hack}
  3262. { With 2 forward declared classes with the child class before the
  3263. parent class the child class is written earlier to the ppu. Leaving it
  3264. possible to have a reference to the parent class for property overriding,
  3265. but the parent class still has the childof not resolved yet (PFV) }
  3266. if childof=nil then
  3267. childof:=tobjectdef(childofderef.resolve);
  3268. result:=childof;
  3269. end;
  3270. procedure tobjectdef.prepareguid;
  3271. begin
  3272. { set up guid }
  3273. if not assigned(iidguid) then
  3274. begin
  3275. new(iidguid);
  3276. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3277. end;
  3278. { setup iidstring }
  3279. if not assigned(iidstr) then
  3280. iidstr:=stringdup(''); { default is empty string }
  3281. end;
  3282. procedure tobjectdef.set_parent( c : tobjectdef);
  3283. begin
  3284. { nothing to do if the parent was not forward !}
  3285. if assigned(childof) then
  3286. exit;
  3287. childof:=c;
  3288. { some options are inherited !! }
  3289. if assigned(c) then
  3290. begin
  3291. { only important for classes }
  3292. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  3293. if not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3294. begin
  3295. { add the data of the anchestor class }
  3296. inc(tObjectSymtable(symtable).datasize,tObjectSymtable(c.symtable).datasize);
  3297. if (oo_has_vmt in objectoptions) and
  3298. (oo_has_vmt in c.objectoptions) then
  3299. dec(tObjectSymtable(symtable).datasize,sizeof(aint));
  3300. { if parent has a vmt field then
  3301. the offset is the same for the child PM }
  3302. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3303. begin
  3304. vmt_offset:=c.vmt_offset;
  3305. include(objectoptions,oo_has_vmt);
  3306. end;
  3307. end;
  3308. end;
  3309. end;
  3310. procedure tobjectdef.insertvmt;
  3311. begin
  3312. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3313. exit;
  3314. if (oo_has_vmt in objectoptions) then
  3315. internalerror(12345)
  3316. else
  3317. begin
  3318. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  3319. tObjectSymtable(symtable).fieldalignment);
  3320. {$ifdef cpurequiresproperalignment}
  3321. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(aint));
  3322. {$endif cpurequiresproperalignment}
  3323. vmt_offset:=tObjectSymtable(symtable).datasize;
  3324. inc(tObjectSymtable(symtable).datasize,sizeof(aint));
  3325. include(objectoptions,oo_has_vmt);
  3326. end;
  3327. end;
  3328. procedure tobjectdef.check_forwards;
  3329. begin
  3330. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3331. tstoredsymtable(symtable).check_forwards;
  3332. if (oo_is_forward in objectoptions) then
  3333. begin
  3334. { ok, in future, the forward can be resolved }
  3335. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3336. exclude(objectoptions,oo_is_forward);
  3337. end;
  3338. end;
  3339. { true, if self inherits from d (or if they are equal) }
  3340. function tobjectdef.is_related(d : tdef) : boolean;
  3341. var
  3342. hp : tobjectdef;
  3343. begin
  3344. hp:=self;
  3345. while assigned(hp) do
  3346. begin
  3347. if hp=d then
  3348. begin
  3349. is_related:=true;
  3350. exit;
  3351. end;
  3352. hp:=hp.childof;
  3353. end;
  3354. is_related:=false;
  3355. end;
  3356. function tobjectdef.FindDestructor : tprocdef;
  3357. var
  3358. objdef : tobjectdef;
  3359. i : longint;
  3360. sym : tsym;
  3361. pd : tprocdef;
  3362. begin
  3363. result:=nil;
  3364. objdef:=self;
  3365. while assigned(objdef) do
  3366. begin
  3367. for i:=0 to objdef.symtable.SymList.Count-1 do
  3368. begin
  3369. sym:=TSym(objdef.symtable.SymList[i]);
  3370. if sym.typ=procsym then
  3371. begin
  3372. pd:=Tprocsym(sym).Find_procdef_bytype(potype_destructor);
  3373. if assigned(pd) then
  3374. begin
  3375. result:=pd;
  3376. exit;
  3377. end;
  3378. end;
  3379. end;
  3380. objdef:=objdef.childof;
  3381. end;
  3382. end;
  3383. function tobjectdef.size : aint;
  3384. begin
  3385. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3386. result:=sizeof(aint)
  3387. else
  3388. result:=tObjectSymtable(symtable).datasize;
  3389. end;
  3390. function tobjectdef.alignment:shortint;
  3391. begin
  3392. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3393. alignment:=sizeof(aint)
  3394. else
  3395. alignment:=tObjectSymtable(symtable).recordalignment;
  3396. end;
  3397. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3398. begin
  3399. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3400. case objecttype of
  3401. odt_class:
  3402. { the +2*sizeof(Aint) is size and -size }
  3403. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  3404. odt_interfacecom,odt_interfacecorba:
  3405. vmtmethodoffset:=index*sizeof(aint);
  3406. else
  3407. {$ifdef WITHDMT}
  3408. vmtmethodoffset:=(index+4)*sizeof(aint);
  3409. {$else WITHDMT}
  3410. vmtmethodoffset:=(index+3)*sizeof(aint);
  3411. {$endif WITHDMT}
  3412. end;
  3413. end;
  3414. function tobjectdef.vmt_mangledname : string;
  3415. begin
  3416. if not(oo_has_vmt in objectoptions) then
  3417. Message1(parser_n_object_has_no_vmt,objrealname^);
  3418. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  3419. end;
  3420. function tobjectdef.needs_inittable : boolean;
  3421. begin
  3422. case objecttype of
  3423. odt_dispinterface,
  3424. odt_class :
  3425. needs_inittable:=false;
  3426. odt_interfacecom:
  3427. needs_inittable:=true;
  3428. odt_interfacecorba:
  3429. needs_inittable:=is_related(interface_iunknown);
  3430. odt_object:
  3431. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  3432. else
  3433. internalerror(200108267);
  3434. end;
  3435. end;
  3436. function tobjectdef.members_need_inittable : boolean;
  3437. begin
  3438. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  3439. end;
  3440. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  3441. var
  3442. ImplIntf : TImplementedInterface;
  3443. i : longint;
  3444. begin
  3445. result:=nil;
  3446. if not assigned(ImplementedInterfaces) then
  3447. exit;
  3448. for i:=0 to ImplementedInterfaces.Count-1 do
  3449. begin
  3450. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3451. if ImplIntf.intfdef=aintfdef then
  3452. begin
  3453. result:=ImplIntf;
  3454. exit;
  3455. end;
  3456. end;
  3457. end;
  3458. function tobjectdef.is_publishable : boolean;
  3459. begin
  3460. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  3461. end;
  3462. {****************************************************************************
  3463. TImplementedInterface
  3464. ****************************************************************************}
  3465. constructor TImplementedInterface.create(aintf: tobjectdef);
  3466. begin
  3467. inherited create;
  3468. intfdef:=aintf;
  3469. IOffset:=-1;
  3470. IType:=etStandard;
  3471. FieldOffset:=-1;
  3472. NameMappings:=nil;
  3473. procdefs:=nil;
  3474. end;
  3475. constructor TImplementedInterface.create_deref(d:tderef);
  3476. begin
  3477. inherited create;
  3478. intfdef:=nil;
  3479. intfdefderef:=d;
  3480. IOffset:=-1;
  3481. IType:=etStandard;
  3482. FieldOffset:=-1;
  3483. NameMappings:=nil;
  3484. procdefs:=nil;
  3485. end;
  3486. destructor TImplementedInterface.destroy;
  3487. var
  3488. i : longint;
  3489. mappedname : pshortstring;
  3490. begin
  3491. if assigned(NameMappings) then
  3492. begin
  3493. for i:=0 to NameMappings.Count-1 do
  3494. begin
  3495. mappedname:=pshortstring(NameMappings[i]);
  3496. stringdispose(mappedname);
  3497. end;
  3498. NameMappings.free;
  3499. NameMappings:=nil;
  3500. end;
  3501. if assigned(procdefs) then
  3502. begin
  3503. procdefs.free;
  3504. procdefs:=nil;
  3505. end;
  3506. inherited destroy;
  3507. end;
  3508. procedure TImplementedInterface.buildderef;
  3509. begin
  3510. intfdefderef.build(intfdef);
  3511. end;
  3512. procedure TImplementedInterface.deref;
  3513. begin
  3514. intfdef:=tobjectdef(intfdefderef.resolve);
  3515. end;
  3516. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  3517. begin
  3518. if not assigned(NameMappings) then
  3519. NameMappings:=TFPHashList.Create;
  3520. NameMappings.Add(origname,stringdup(newname));
  3521. end;
  3522. function TImplementedInterface.GetMapping(const origname: string):string;
  3523. var
  3524. mappedname : pshortstring;
  3525. begin
  3526. result:='';
  3527. if not assigned(NameMappings) then
  3528. exit;
  3529. mappedname:=PShortstring(NameMappings.Find(origname));
  3530. if assigned(mappedname) then
  3531. result:=mappedname^;
  3532. end;
  3533. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  3534. var
  3535. i : longint;
  3536. found : boolean;
  3537. begin
  3538. if not assigned(procdefs) then
  3539. procdefs:=TFPObjectList.Create(false);
  3540. { No duplicate entries of the same procdef }
  3541. found:=false;
  3542. for i:=0 to procdefs.count-1 do
  3543. if tprocdef(procdefs[i])=pd then
  3544. begin
  3545. found:=true;
  3546. break;
  3547. end;
  3548. if not found then
  3549. procdefs.Add(pd);
  3550. end;
  3551. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  3552. var
  3553. i : longint;
  3554. begin
  3555. result:=false;
  3556. weight:=0;
  3557. { empty interface is mergeable }
  3558. if ProcDefs.Count=0 then
  3559. begin
  3560. result:=true;
  3561. exit;
  3562. end;
  3563. { The interface to merge must at least the number of
  3564. procedures of this interface }
  3565. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  3566. exit;
  3567. for i:=0 to ProcDefs.Count-1 do
  3568. begin
  3569. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  3570. exit;
  3571. end;
  3572. weight:=ProcDefs.Count;
  3573. result:=true;
  3574. end;
  3575. function TImplementedInterface.getcopy:TImplementedInterface;
  3576. begin
  3577. Result:=TImplementedInterface.Create(nil);
  3578. Move(pointer(self)^,pointer(result)^,InstanceSize);
  3579. end;
  3580. {****************************************************************************
  3581. TFORWARDDEF
  3582. ****************************************************************************}
  3583. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  3584. begin
  3585. inherited create(forwarddef);
  3586. tosymname:=stringdup(s);
  3587. forwardpos:=pos;
  3588. end;
  3589. function tforwarddef.GetTypeName:string;
  3590. begin
  3591. GetTypeName:='unresolved forward to '+tosymname^;
  3592. end;
  3593. destructor tforwarddef.destroy;
  3594. begin
  3595. stringdispose(tosymname);
  3596. inherited destroy;
  3597. end;
  3598. {****************************************************************************
  3599. TUNDEFINEDDEF
  3600. ****************************************************************************}
  3601. constructor tundefineddef.create;
  3602. begin
  3603. inherited create(undefineddef);
  3604. end;
  3605. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  3606. begin
  3607. inherited ppuload(undefineddef,ppufile);
  3608. end;
  3609. function tundefineddef.GetTypeName:string;
  3610. begin
  3611. GetTypeName:='<undefined type>';
  3612. end;
  3613. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  3614. begin
  3615. inherited ppuwrite(ppufile);
  3616. ppufile.writeentry(ibundefineddef);
  3617. end;
  3618. {****************************************************************************
  3619. TERRORDEF
  3620. ****************************************************************************}
  3621. constructor terrordef.create;
  3622. begin
  3623. inherited create(errordef);
  3624. end;
  3625. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  3626. begin
  3627. { Can't write errordefs to ppu }
  3628. internalerror(200411063);
  3629. end;
  3630. function terrordef.GetTypeName:string;
  3631. begin
  3632. GetTypeName:='<erroneous type>';
  3633. end;
  3634. function terrordef.getmangledparaname:string;
  3635. begin
  3636. getmangledparaname:='error';
  3637. end;
  3638. {****************************************************************************
  3639. Definition Helpers
  3640. ****************************************************************************}
  3641. function is_interfacecom(def: tdef): boolean;
  3642. begin
  3643. is_interfacecom:=
  3644. assigned(def) and
  3645. (def.typ=objectdef) and
  3646. (tobjectdef(def).objecttype=odt_interfacecom);
  3647. end;
  3648. function is_interfacecorba(def: tdef): boolean;
  3649. begin
  3650. is_interfacecorba:=
  3651. assigned(def) and
  3652. (def.typ=objectdef) and
  3653. (tobjectdef(def).objecttype=odt_interfacecorba);
  3654. end;
  3655. function is_interface(def: tdef): boolean;
  3656. begin
  3657. is_interface:=
  3658. assigned(def) and
  3659. (def.typ=objectdef) and
  3660. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  3661. end;
  3662. function is_dispinterface(def: tdef): boolean;
  3663. begin
  3664. result:=
  3665. assigned(def) and
  3666. (def.typ=objectdef) and
  3667. (tobjectdef(def).objecttype=odt_dispinterface);
  3668. end;
  3669. function is_class(def: tdef): boolean;
  3670. begin
  3671. is_class:=
  3672. assigned(def) and
  3673. (def.typ=objectdef) and
  3674. (tobjectdef(def).objecttype=odt_class);
  3675. end;
  3676. function is_object(def: tdef): boolean;
  3677. begin
  3678. is_object:=
  3679. assigned(def) and
  3680. (def.typ=objectdef) and
  3681. (tobjectdef(def).objecttype=odt_object);
  3682. end;
  3683. function is_cppclass(def: tdef): boolean;
  3684. begin
  3685. is_cppclass:=
  3686. assigned(def) and
  3687. (def.typ=objectdef) and
  3688. (tobjectdef(def).objecttype=odt_cppclass);
  3689. end;
  3690. function is_class_or_interface(def: tdef): boolean;
  3691. begin
  3692. is_class_or_interface:=
  3693. assigned(def) and
  3694. (def.typ=objectdef) and
  3695. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  3696. end;
  3697. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  3698. begin
  3699. result:=
  3700. assigned(def) and
  3701. (def.typ=objectdef) and
  3702. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  3703. end;
  3704. {$ifdef x86}
  3705. function use_sse(def : tdef) : boolean;
  3706. begin
  3707. use_sse:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  3708. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  3709. end;
  3710. {$endif x86}
  3711. end.