symdef.pas 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325
  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. IOffset : longint;
  178. VtblImplIntf : TImplementedInterface;
  179. NameMappings : TFPHashList;
  180. ProcDefs : TFPObjectList;
  181. constructor create(aintf: tobjectdef);
  182. constructor create_deref(d:tderef);
  183. destructor destroy; override;
  184. function getcopy:TImplementedInterface;
  185. procedure buildderef;
  186. procedure deref;
  187. procedure AddMapping(const origname, newname: string);
  188. function GetMapping(const origname: string):string;
  189. procedure AddImplProc(pd:tprocdef);
  190. function IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  191. end;
  192. { tobjectdef }
  193. tobjectdef = class(tabstractrecorddef)
  194. public
  195. childof : tobjectdef;
  196. childofderef : tderef;
  197. objname,
  198. objrealname : pshortstring;
  199. objectoptions : tobjectoptions;
  200. { to be able to have a variable vmt position }
  201. { and no vmt field for objects without virtuals }
  202. vmtentries : TFPObjectList;
  203. vmt_offset : longint;
  204. writing_class_record_dbginfo : boolean;
  205. objecttype : tobjecttyp;
  206. iidguid : pguid;
  207. iidstr : pshortstring;
  208. iitype : tinterfaceentrytype;
  209. iioffset : longint;
  210. { store implemented interfaces defs and name mappings }
  211. ImplementedInterfaces : TFPObjectList;
  212. constructor create(ot : tobjecttyp;const n : string;c : tobjectdef);
  213. constructor ppuload(ppufile:tcompilerppufile);
  214. destructor destroy;override;
  215. function getcopy : tstoreddef;override;
  216. procedure ppuwrite(ppufile:tcompilerppufile);override;
  217. function GetTypeName:string;override;
  218. procedure buildderef;override;
  219. procedure deref;override;
  220. function getparentdef:tdef;override;
  221. function size : aint;override;
  222. function alignment:shortint;override;
  223. function vmtmethodoffset(index:longint):longint;
  224. function members_need_inittable : boolean;
  225. function find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  226. { this should be called when this class implements an interface }
  227. procedure prepareguid;
  228. function is_publishable : boolean;override;
  229. function needs_inittable : boolean;override;
  230. function vmt_mangledname : string;
  231. procedure check_forwards;
  232. function is_related(d : tdef) : boolean;override;
  233. procedure insertvmt;
  234. procedure set_parent(c : tobjectdef);
  235. function FindDestructor : tprocdef;
  236. end;
  237. tclassrefdef = class(tabstractpointerdef)
  238. constructor create(def:tdef);
  239. constructor ppuload(ppufile:tcompilerppufile);
  240. procedure ppuwrite(ppufile:tcompilerppufile);override;
  241. function GetTypeName:string;override;
  242. function is_publishable : boolean;override;
  243. end;
  244. tarraydef = class(tstoreddef)
  245. lowrange,
  246. highrange : aint;
  247. rangedef : tdef;
  248. rangedefderef : tderef;
  249. arrayoptions : tarraydefoptions;
  250. protected
  251. _elementdef : tdef;
  252. _elementdefderef : tderef;
  253. procedure setelementdef(def:tdef);
  254. public
  255. function elesize : aint;
  256. function elepackedbitsize : aint;
  257. function elecount : aint;
  258. constructor create_from_pointer(def:tdef);
  259. constructor create(l,h : aint;def:tdef);
  260. constructor ppuload(ppufile:tcompilerppufile);
  261. function getcopy : tstoreddef;override;
  262. procedure ppuwrite(ppufile:tcompilerppufile);override;
  263. function GetTypeName:string;override;
  264. function getmangledparaname : string;override;
  265. procedure buildderef;override;
  266. procedure deref;override;
  267. function size : aint;override;
  268. function alignment : shortint;override;
  269. { returns the label of the range check string }
  270. function needs_inittable : boolean;override;
  271. property elementdef : tdef read _elementdef write setelementdef;
  272. end;
  273. torddef = class(tstoreddef)
  274. low,high : TConstExprInt;
  275. ordtype : tordtype;
  276. constructor create(t : tordtype;v,b : TConstExprInt);
  277. constructor ppuload(ppufile:tcompilerppufile);
  278. function getcopy : tstoreddef;override;
  279. procedure ppuwrite(ppufile:tcompilerppufile);override;
  280. function is_publishable : boolean;override;
  281. function GetTypeName:string;override;
  282. function alignment:shortint;override;
  283. procedure setsize;
  284. function packedbitsize: aint; override;
  285. function getvardef : longint;override;
  286. end;
  287. tfloatdef = class(tstoreddef)
  288. floattype : tfloattype;
  289. constructor create(t : tfloattype);
  290. constructor ppuload(ppufile:tcompilerppufile);
  291. function getcopy : tstoreddef;override;
  292. procedure ppuwrite(ppufile:tcompilerppufile);override;
  293. function GetTypeName:string;override;
  294. function is_publishable : boolean;override;
  295. function alignment:shortint;override;
  296. procedure setsize;
  297. function getvardef:longint;override;
  298. end;
  299. tabstractprocdef = class(tstoreddef)
  300. { saves a definition to the return type }
  301. returndef : tdef;
  302. returndefderef : tderef;
  303. parast : TSymtable;
  304. paras : tparalist;
  305. proctypeoption : tproctypeoption;
  306. proccalloption : tproccalloption;
  307. procoptions : tprocoptions;
  308. requiredargarea : aint;
  309. { number of user visibile parameters }
  310. maxparacount,
  311. minparacount : byte;
  312. {$ifdef i386}
  313. fpu_used : longint; { how many stack fpu must be empty }
  314. {$endif i386}
  315. {$ifdef m68k}
  316. exp_funcretloc : tregister; { explicit funcretloc for AmigaOS }
  317. {$endif}
  318. funcretloc : array[tcallercallee] of TLocation;
  319. has_paraloc_info : boolean; { paraloc info is available }
  320. constructor create(dt:tdeftyp;level:byte);
  321. constructor ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  322. destructor destroy;override;
  323. procedure ppuwrite(ppufile:tcompilerppufile);override;
  324. procedure buildderef;override;
  325. procedure deref;override;
  326. procedure calcparas;
  327. function typename_paras(showhidden:boolean): string;
  328. procedure test_if_fpu_result;
  329. function is_methodpointer:boolean;virtual;
  330. function is_addressonly:boolean;virtual;
  331. private
  332. procedure count_para(p:TObject;arg:pointer);
  333. procedure insert_para(p:TObject;arg:pointer);
  334. end;
  335. tprocvardef = class(tabstractprocdef)
  336. constructor create(level:byte);
  337. constructor ppuload(ppufile:tcompilerppufile);
  338. function getcopy : tstoreddef;override;
  339. procedure ppuwrite(ppufile:tcompilerppufile);override;
  340. function GetSymtable(t:tGetSymtable):TSymtable;override;
  341. function size : aint;override;
  342. function GetTypeName:string;override;
  343. function is_publishable : boolean;override;
  344. function is_methodpointer:boolean;override;
  345. function is_addressonly:boolean;override;
  346. function getmangledparaname:string;override;
  347. end;
  348. tmessageinf = record
  349. case integer of
  350. 0 : (str : pshortstring);
  351. 1 : (i : longint);
  352. end;
  353. tinlininginfo = record
  354. { node tree }
  355. code : tnode;
  356. flags : tprocinfoflags;
  357. end;
  358. pinlininginfo = ^tinlininginfo;
  359. {$ifdef oldregvars}
  360. { register variables }
  361. pregvarinfo = ^tregvarinfo;
  362. tregvarinfo = record
  363. regvars : array[1..maxvarregs] of tsym;
  364. regvars_para : array[1..maxvarregs] of boolean;
  365. regvars_refs : array[1..maxvarregs] of longint;
  366. fpuregvars : array[1..maxfpuvarregs] of tsym;
  367. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  368. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  369. end;
  370. {$endif oldregvars}
  371. tprocdef = class(tabstractprocdef)
  372. private
  373. _mangledname : pshortstring;
  374. public
  375. messageinf : tmessageinf;
  376. dispid : longint;
  377. extnumber : word;
  378. {$ifndef EXTDEBUG}
  379. { where is this function defined and what were the symbol
  380. flags, needed here because there
  381. is only one symbol for all overloaded functions
  382. EXTDEBUG has fileinfo in tdef (PFV) }
  383. fileinfo : tfileposinfo;
  384. {$endif}
  385. symoptions : tsymoptions;
  386. { symbol owning this definition }
  387. procsym : tsym;
  388. procsymderef : tderef;
  389. { alias names }
  390. aliasnames : tstringlist;
  391. { symtables }
  392. localst : TSymtable;
  393. funcretsym : tsym;
  394. funcretsymderef : tderef;
  395. _class : tobjectdef;
  396. _classderef : tderef;
  397. {$if defined(powerpc) or defined(m68k)}
  398. { library symbol for AmigaOS/MorphOS }
  399. libsym : tsym;
  400. libsymderef : tderef;
  401. {$endif powerpc or m68k}
  402. { name of the result variable to insert in the localsymtable }
  403. resultname : pshortstring;
  404. { true, if the procedure is only declared
  405. (forward procedure) }
  406. forwarddef,
  407. { true if the procedure is declared in the interface }
  408. interfacedef : boolean;
  409. { true if the procedure has a forward declaration }
  410. hasforward : boolean;
  411. { import info }
  412. import_dll,
  413. import_name : pshortstring;
  414. import_nr : word;
  415. { info for inlining the subroutine, if this pointer is nil,
  416. the procedure can't be inlined }
  417. inlininginfo : pinlininginfo;
  418. {$ifdef oldregvars}
  419. regvarinfo: pregvarinfo;
  420. {$endif oldregvars}
  421. { position in aasmoutput list }
  422. procstarttai,
  423. procendtai : tai;
  424. constructor create(level:byte);
  425. constructor ppuload(ppufile:tcompilerppufile);
  426. destructor destroy;override;
  427. procedure ppuwrite(ppufile:tcompilerppufile);override;
  428. procedure buildderef;override;
  429. procedure buildderefimpl;override;
  430. procedure deref;override;
  431. procedure derefimpl;override;
  432. procedure reset;override;
  433. function GetSymtable(t:tGetSymtable):TSymtable;override;
  434. function GetTypeName : string;override;
  435. function mangledname : string;
  436. procedure setmangledname(const s : string);
  437. function fullprocname(showhidden:boolean):string;
  438. function cplusplusmangledname : string;
  439. function is_methodpointer:boolean;override;
  440. function is_addressonly:boolean;override;
  441. function is_visible_for_object(currobjdef,contextobjdef:tobjectdef):boolean;
  442. end;
  443. { single linked list of overloaded procs }
  444. pprocdeflist = ^tprocdeflist;
  445. tprocdeflist = record
  446. def : tprocdef;
  447. defderef : tderef;
  448. next : pprocdeflist;
  449. end;
  450. tstringdef = class(tstoreddef)
  451. stringtype : tstringtype;
  452. len : aint;
  453. constructor createshort(l : byte);
  454. constructor loadshort(ppufile:tcompilerppufile);
  455. constructor createlong(l : aint);
  456. constructor loadlong(ppufile:tcompilerppufile);
  457. constructor createansi(l : aint);
  458. constructor loadansi(ppufile:tcompilerppufile);
  459. constructor createwide(l : aint);
  460. constructor loadwide(ppufile:tcompilerppufile);
  461. function getcopy : tstoreddef;override;
  462. function stringtypname:string;
  463. procedure ppuwrite(ppufile:tcompilerppufile);override;
  464. function GetTypeName:string;override;
  465. function getmangledparaname:string;override;
  466. function is_publishable : boolean;override;
  467. function alignment : shortint;override;
  468. function needs_inittable : boolean;override;
  469. function getvardef:longint;override;
  470. end;
  471. tenumdef = class(tstoreddef)
  472. minval,
  473. maxval : aint;
  474. has_jumps : boolean;
  475. firstenum : tsym; {tenumsym}
  476. basedef : tenumdef;
  477. basedefderef : tderef;
  478. constructor create;
  479. constructor create_subrange(_basedef:tenumdef;_min,_max:aint);
  480. constructor ppuload(ppufile:tcompilerppufile);
  481. function getcopy : tstoreddef;override;
  482. procedure ppuwrite(ppufile:tcompilerppufile);override;
  483. procedure buildderef;override;
  484. procedure deref;override;
  485. procedure derefimpl;override;
  486. function GetTypeName:string;override;
  487. function is_publishable : boolean;override;
  488. procedure calcsavesize;
  489. function packedbitsize: aint; override;
  490. procedure setmax(_max:aint);
  491. procedure setmin(_min:aint);
  492. function min:aint;
  493. function max:aint;
  494. end;
  495. tsetdef = class(tstoreddef)
  496. elementdef : tdef;
  497. elementdefderef : tderef;
  498. settype : tsettype;
  499. setbase,
  500. setmax : aint;
  501. constructor create(def:tdef;high : aint);
  502. constructor ppuload(ppufile:tcompilerppufile);
  503. function getcopy : tstoreddef;override;
  504. procedure ppuwrite(ppufile:tcompilerppufile);override;
  505. procedure buildderef;override;
  506. procedure deref;override;
  507. function GetTypeName:string;override;
  508. function is_publishable : boolean;override;
  509. end;
  510. Tdefmatch=(dm_exact,dm_equal,dm_convertl1);
  511. var
  512. aktobjectdef : tobjectdef; { used for private functions check !! }
  513. { default types }
  514. generrordef, { error in definition }
  515. voidpointertype, { pointer for Void-pointeddef }
  516. charpointertype, { pointer for Char-pointeddef }
  517. widecharpointertype, { pointer for WideChar-pointeddef }
  518. voidfarpointertype,
  519. cundefinedtype,
  520. cformaltype, { unique formal definition }
  521. voidtype, { Void (procedure) }
  522. cchartype, { Char }
  523. cwidechartype, { WideChar }
  524. booltype, { boolean type }
  525. bool16type,
  526. bool32type,
  527. bool64type, { implement me }
  528. u8inttype, { 8-Bit unsigned integer }
  529. s8inttype, { 8-Bit signed integer }
  530. u16inttype, { 16-Bit unsigned integer }
  531. s16inttype, { 16-Bit signed integer }
  532. u32inttype, { 32-Bit unsigned integer }
  533. s32inttype, { 32-Bit signed integer }
  534. u64inttype, { 64-bit unsigned integer }
  535. s64inttype, { 64-bit signed integer }
  536. s32floattype, { pointer for realconstn }
  537. s64floattype, { pointer for realconstn }
  538. s80floattype, { pointer to type of temp. floats }
  539. s64currencytype, { pointer to a currency type }
  540. cshortstringtype, { pointer to type of short string const }
  541. clongstringtype, { pointer to type of long string const }
  542. cansistringtype, { pointer to type of ansi string const }
  543. cwidestringtype, { pointer to type of wide string const }
  544. openshortstringtype, { pointer to type of an open shortstring,
  545. needed for readln() }
  546. openchararraytype, { pointer to type of an open array of char,
  547. needed for readln() }
  548. cfiletype, { get the same definition for all file }
  549. { used for stabs }
  550. methodpointertype, { typecasting of methodpointers to extract self }
  551. hresultdef,
  552. { we use only one variant def for every variant class }
  553. cvarianttype,
  554. colevarianttype,
  555. { default integer type s32inttype on 32 bit systems, s64bittype on 64 bit systems }
  556. sinttype,
  557. uinttype,
  558. { unsigned ord type with the same size as a pointer }
  559. ptrinttype,
  560. { several types to simulate more or less C++ objects for GDB }
  561. vmttype,
  562. vmtarraytype,
  563. pvmttype : tdef; { type of classrefs, used for stabs }
  564. { pointer to the anchestor of all classes }
  565. class_tobject : tobjectdef;
  566. { pointer to the ancestor of all COM interfaces }
  567. interface_iunknown : tobjectdef;
  568. { pointer to the TGUID type
  569. of all interfaces }
  570. rec_tguid : trecorddef;
  571. const
  572. {$ifdef i386}
  573. pbestrealtype : ^tdef = @s80floattype;
  574. {$endif}
  575. {$ifdef x86_64}
  576. pbestrealtype : ^tdef = @s80floattype;
  577. {$endif}
  578. {$ifdef m68k}
  579. pbestrealtype : ^tdef = @s64floattype;
  580. {$endif}
  581. {$ifdef alpha}
  582. pbestrealtype : ^tdef = @s64floattype;
  583. {$endif}
  584. {$ifdef powerpc}
  585. pbestrealtype : ^tdef = @s64floattype;
  586. {$endif}
  587. {$ifdef POWERPC64}
  588. pbestrealtype : ^tdef = @s64floattype;
  589. {$endif}
  590. {$ifdef ia64}
  591. pbestrealtype : ^tdef = @s64floattype;
  592. {$endif}
  593. {$ifdef SPARC}
  594. pbestrealtype : ^tdef = @s64floattype;
  595. {$endif SPARC}
  596. {$ifdef vis}
  597. pbestrealtype : ^tdef = @s64floattype;
  598. {$endif vis}
  599. {$ifdef ARM}
  600. pbestrealtype : ^tdef = @s64floattype;
  601. {$endif ARM}
  602. {$ifdef MIPS}
  603. pbestrealtype : ^tdef = @s64floattype;
  604. {$endif MIPS}
  605. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  606. { should be in the types unit, but the types unit uses the node stuff :( }
  607. function is_interfacecom(def: tdef): boolean;
  608. function is_interfacecorba(def: tdef): boolean;
  609. function is_interface(def: tdef): boolean;
  610. function is_dispinterface(def: tdef): boolean;
  611. function is_object(def: tdef): boolean;
  612. function is_class(def: tdef): boolean;
  613. function is_cppclass(def: tdef): boolean;
  614. function is_class_or_interface(def: tdef): boolean;
  615. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  616. {$ifdef x86}
  617. function use_sse(def : tdef) : boolean;
  618. {$endif x86}
  619. implementation
  620. uses
  621. SysUtils,
  622. cutils,
  623. { global }
  624. verbose,
  625. { target }
  626. systems,aasmcpu,paramgr,
  627. { symtable }
  628. symsym,symtable,symutil,defutil,
  629. { module }
  630. fmodule,
  631. { other }
  632. gendef,
  633. fpccrc
  634. ;
  635. {****************************************************************************
  636. Constants
  637. ****************************************************************************}
  638. const
  639. varempty = 0;
  640. varnull = 1;
  641. varsmallint = 2;
  642. varinteger = 3;
  643. varsingle = 4;
  644. vardouble = 5;
  645. varcurrency = 6;
  646. vardate = 7;
  647. varolestr = 8;
  648. vardispatch = 9;
  649. varerror = 10;
  650. varboolean = 11;
  651. varvariant = 12;
  652. varunknown = 13;
  653. vardecimal = 14;
  654. varshortint = 16;
  655. varbyte = 17;
  656. varword = 18;
  657. varlongword = 19;
  658. varint64 = 20;
  659. varqword = 21;
  660. varUndefined = -1;
  661. varstrarg = $48;
  662. varstring = $100;
  663. varany = $101;
  664. vardefmask = $fff;
  665. vararray = $2000;
  666. varbyref = $4000;
  667. {****************************************************************************
  668. Helpers
  669. ****************************************************************************}
  670. function make_mangledname(const typeprefix:string;st:TSymtable;const suffix:string):string;
  671. var
  672. s,hs,
  673. prefix : string;
  674. oldlen,
  675. newlen,
  676. i : longint;
  677. crc : dword;
  678. hp : tparavarsym;
  679. begin
  680. prefix:='';
  681. if not assigned(st) then
  682. internalerror(200204212);
  683. { sub procedures }
  684. while (st.symtabletype=localsymtable) do
  685. begin
  686. if st.defowner.typ<>procdef then
  687. internalerror(200204173);
  688. { Add the full mangledname of procedure to prevent
  689. conflicts with 2 overloads having both a nested procedure
  690. with the same name, see tb0314 (PFV) }
  691. s:=tprocdef(st.defowner).procsym.name;
  692. oldlen:=length(s);
  693. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  694. begin
  695. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  696. if not(vo_is_hidden_para in hp.varoptions) then
  697. s:=s+'$'+hp.vardef.mangledparaname;
  698. end;
  699. if not is_void(tprocdef(st.defowner).returndef) then
  700. s:=s+'$$'+tprocdef(st.defowner).returndef.mangledparaname;
  701. newlen:=length(s);
  702. { Replace with CRC if the parameter line is very long }
  703. if (newlen-oldlen>12) and
  704. ((newlen>128) or (newlen-oldlen>64)) then
  705. begin
  706. crc:=$ffffffff;
  707. for i:=0 to tprocdef(st.defowner).paras.count-1 do
  708. begin
  709. hp:=tparavarsym(tprocdef(st.defowner).paras[i]);
  710. if not(vo_is_hidden_para in hp.varoptions) then
  711. begin
  712. hs:=hp.vardef.mangledparaname;
  713. crc:=UpdateCrc32(crc,hs[1],length(hs));
  714. end;
  715. end;
  716. hs:=hp.vardef.mangledparaname;
  717. crc:=UpdateCrc32(crc,hs[1],length(hs));
  718. s:=Copy(s,1,oldlen)+'$crc'+hexstr(crc,8);
  719. end;
  720. if prefix<>'' then
  721. prefix:=s+'_'+prefix
  722. else
  723. prefix:=s;
  724. st:=st.defowner.owner;
  725. end;
  726. { object/classes symtable }
  727. if (st.symtabletype=ObjectSymtable) then
  728. begin
  729. if st.defowner.typ<>objectdef then
  730. internalerror(200204174);
  731. prefix:=tobjectdef(st.defowner).objname^+'_$_'+prefix;
  732. st:=st.defowner.owner;
  733. end;
  734. { symtable must now be static or global }
  735. if not(st.symtabletype in [staticsymtable,globalsymtable]) then
  736. internalerror(200204175);
  737. result:='';
  738. if typeprefix<>'' then
  739. result:=result+typeprefix+'_';
  740. { Add P$ for program, which can have the same name as
  741. a unit }
  742. if (TSymtable(main_module.localsymtable)=st) and
  743. (not main_module.is_unit) then
  744. result:=result+'P$'+st.name^
  745. else
  746. result:=result+st.name^;
  747. if prefix<>'' then
  748. result:=result+'_'+prefix;
  749. if suffix<>'' then
  750. result:=result+'_'+suffix;
  751. { the Darwin assembler assumes that all symbols starting with 'L' are local }
  752. if (target_info.system in [system_powerpc_darwin,system_i386_darwin]) and
  753. (result[1] = 'L') then
  754. result := '_' + result;
  755. end;
  756. {****************************************************************************
  757. TDEF (base class for definitions)
  758. ****************************************************************************}
  759. constructor tstoreddef.create(dt:tdeftyp);
  760. var
  761. insertstack : psymtablestackitem;
  762. begin
  763. inherited create(dt);
  764. savesize := 0;
  765. {$ifdef EXTDEBUG}
  766. fileinfo := current_filepos;
  767. {$endif}
  768. generictokenbuf:=nil;
  769. genericdef:=nil;
  770. { Don't register forwarddefs, they are disposed at the
  771. end of an type block }
  772. if (dt=forwarddef) then
  773. exit;
  774. { Register in current_module }
  775. if assigned(current_module) then
  776. begin
  777. current_module.deflist.Add(self);
  778. DefId:=current_module.deflist.Count-1;
  779. end;
  780. { Register in symtable stack }
  781. if assigned(symtablestack) then
  782. begin
  783. insertstack:=symtablestack.stack;
  784. while assigned(insertstack) and
  785. (insertstack^.symtable.symtabletype=withsymtable) do
  786. insertstack:=insertstack^.next;
  787. if not assigned(insertstack) then
  788. internalerror(200602044);
  789. insertstack^.symtable.insertdef(self);
  790. end;
  791. end;
  792. destructor tstoreddef.destroy;
  793. begin
  794. { Direct calls are not allowed, use symtable.deletedef() }
  795. if assigned(owner) then
  796. internalerror(200612311);
  797. if assigned(generictokenbuf) then
  798. begin
  799. generictokenbuf.free;
  800. generictokenbuf:=nil;
  801. end;
  802. inherited destroy;
  803. end;
  804. constructor tstoreddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  805. var
  806. sizeleft,i : longint;
  807. buf : array[0..255] of byte;
  808. begin
  809. inherited create(dt);
  810. DefId:=ppufile.getlongint;
  811. current_module.deflist[DefId]:=self;
  812. {$ifdef EXTDEBUG}
  813. fillchar(fileinfo,sizeof(fileinfo),0);
  814. {$endif}
  815. { load }
  816. ppufile.getderef(typesymderef);
  817. ppufile.getsmallset(defoptions);
  818. if df_generic in defoptions then
  819. begin
  820. sizeleft:=ppufile.getlongint;
  821. initgeneric;
  822. while sizeleft>0 do
  823. begin
  824. if sizeleft>sizeof(buf) then
  825. i:=sizeof(buf)
  826. else
  827. i:=sizeleft;
  828. ppufile.getdata(buf,i);
  829. generictokenbuf.write(buf,i);
  830. dec(sizeleft,i);
  831. end;
  832. end;
  833. if df_specialization in defoptions then
  834. ppufile.getderef(genericdefderef);
  835. end;
  836. function Tstoreddef.rtti_mangledname(rt:trttitype):string;
  837. var
  838. prefix : string[4];
  839. begin
  840. if rt=fullrtti then
  841. begin
  842. prefix:='RTTI';
  843. include(defstates,ds_rtti_table_used);
  844. end
  845. else
  846. begin
  847. prefix:='INIT';
  848. include(defstates,ds_init_table_used);
  849. end;
  850. if assigned(typesym) and
  851. (owner.symtabletype in [staticsymtable,globalsymtable]) then
  852. result:=make_mangledname(prefix,owner,typesym.name)
  853. else
  854. result:=make_mangledname(prefix,findunitsymtable(owner),'DEF'+tostr(DefId))
  855. end;
  856. procedure Tstoreddef.reset;
  857. begin
  858. end;
  859. function tstoreddef.getcopy : tstoreddef;
  860. begin
  861. Message(sym_e_cant_create_unique_type);
  862. getcopy:=terrordef.create;
  863. end;
  864. procedure tstoreddef.ppuwrite(ppufile:tcompilerppufile);
  865. var
  866. sizeleft,i : longint;
  867. buf : array[0..255] of byte;
  868. oldintfcrc : boolean;
  869. begin
  870. ppufile.putlongint(DefId);
  871. ppufile.putderef(typesymderef);
  872. ppufile.putsmallset(defoptions);
  873. if df_generic in defoptions then
  874. begin
  875. oldintfcrc:=ppufile.do_interface_crc;
  876. ppufile.do_interface_crc:=false;
  877. if assigned(generictokenbuf) then
  878. begin
  879. sizeleft:=generictokenbuf.size;
  880. generictokenbuf.seek(0);
  881. end
  882. else
  883. sizeleft:=0;
  884. ppufile.putlongint(sizeleft);
  885. while sizeleft>0 do
  886. begin
  887. if sizeleft>sizeof(buf) then
  888. i:=sizeof(buf)
  889. else
  890. i:=sizeleft;
  891. generictokenbuf.read(buf,i);
  892. ppufile.putdata(buf,i);
  893. dec(sizeleft,i);
  894. end;
  895. ppufile.do_interface_crc:=oldintfcrc;
  896. end;
  897. if df_specialization in defoptions then
  898. ppufile.putderef(genericdefderef);
  899. end;
  900. procedure tstoreddef.buildderef;
  901. begin
  902. typesymderef.build(typesym);
  903. genericdefderef.build(genericdef);
  904. end;
  905. procedure tstoreddef.buildderefimpl;
  906. begin
  907. end;
  908. procedure tstoreddef.deref;
  909. begin
  910. typesym:=ttypesym(typesymderef.resolve);
  911. if df_specialization in defoptions then
  912. genericdef:=tstoreddef(genericdefderef.resolve);
  913. end;
  914. procedure tstoreddef.derefimpl;
  915. begin
  916. end;
  917. function tstoreddef.size : aint;
  918. begin
  919. size:=savesize;
  920. end;
  921. function tstoreddef.getvardef:longint;
  922. begin
  923. result:=varUndefined;
  924. end;
  925. function tstoreddef.alignment : shortint;
  926. begin
  927. { natural alignment by default }
  928. alignment:=size_2_align(savesize);
  929. end;
  930. { returns true, if the definition can be published }
  931. function tstoreddef.is_publishable : boolean;
  932. begin
  933. is_publishable:=false;
  934. end;
  935. { needs an init table }
  936. function tstoreddef.needs_inittable : boolean;
  937. begin
  938. needs_inittable:=false;
  939. end;
  940. function tstoreddef.is_intregable : boolean;
  941. var
  942. recsize,temp: longint;
  943. begin
  944. is_intregable:=false;
  945. case typ of
  946. orddef,
  947. pointerdef,
  948. enumdef,
  949. classrefdef:
  950. is_intregable:=true;
  951. procvardef :
  952. is_intregable:=not(po_methodpointer in tprocvardef(self).procoptions);
  953. objectdef:
  954. is_intregable:=(is_class(self) or is_interface(self)) and not needs_inittable;
  955. setdef:
  956. is_intregable:=(tsetdef(self).settype=smallset);
  957. recorddef:
  958. begin
  959. recsize:=size;
  960. is_intregable:=
  961. ispowerof2(recsize,temp) and
  962. (recsize <= sizeof(aint));
  963. end;
  964. end;
  965. end;
  966. function tstoreddef.is_fpuregable : boolean;
  967. begin
  968. {$ifdef x86}
  969. result:=use_sse(self);
  970. {$else x86}
  971. result:=(typ=floatdef) and not(cs_fp_emulation in current_settings.moduleswitches);
  972. {$endif x86}
  973. end;
  974. procedure tstoreddef.initgeneric;
  975. begin
  976. if assigned(generictokenbuf) then
  977. internalerror(200512131);
  978. generictokenbuf:=tdynamicarray.create(256);
  979. end;
  980. {****************************************************************************
  981. Tstringdef
  982. ****************************************************************************}
  983. constructor tstringdef.createshort(l : byte);
  984. begin
  985. inherited create(stringdef);
  986. stringtype:=st_shortstring;
  987. len:=l;
  988. savesize:=len+1;
  989. end;
  990. constructor tstringdef.loadshort(ppufile:tcompilerppufile);
  991. begin
  992. inherited ppuload(stringdef,ppufile);
  993. stringtype:=st_shortstring;
  994. len:=ppufile.getbyte;
  995. savesize:=len+1;
  996. end;
  997. constructor tstringdef.createlong(l : aint);
  998. begin
  999. inherited create(stringdef);
  1000. stringtype:=st_longstring;
  1001. len:=l;
  1002. savesize:=sizeof(aint);
  1003. end;
  1004. constructor tstringdef.loadlong(ppufile:tcompilerppufile);
  1005. begin
  1006. inherited ppuload(stringdef,ppufile);
  1007. stringtype:=st_longstring;
  1008. len:=ppufile.getaint;
  1009. savesize:=sizeof(aint);
  1010. end;
  1011. constructor tstringdef.createansi(l:aint);
  1012. begin
  1013. inherited create(stringdef);
  1014. stringtype:=st_ansistring;
  1015. len:=l;
  1016. savesize:=sizeof(aint);
  1017. end;
  1018. constructor tstringdef.loadansi(ppufile:tcompilerppufile);
  1019. begin
  1020. inherited ppuload(stringdef,ppufile);
  1021. stringtype:=st_ansistring;
  1022. len:=ppufile.getaint;
  1023. savesize:=sizeof(aint);
  1024. end;
  1025. constructor tstringdef.createwide(l : aint);
  1026. begin
  1027. inherited create(stringdef);
  1028. stringtype:=st_widestring;
  1029. len:=l;
  1030. savesize:=sizeof(aint);
  1031. end;
  1032. constructor tstringdef.loadwide(ppufile:tcompilerppufile);
  1033. begin
  1034. inherited ppuload(stringdef,ppufile);
  1035. stringtype:=st_widestring;
  1036. len:=ppufile.getaint;
  1037. savesize:=sizeof(aint);
  1038. end;
  1039. function tstringdef.getcopy : tstoreddef;
  1040. begin
  1041. result:=tstringdef.create(typ);
  1042. result.typ:=stringdef;
  1043. tstringdef(result).stringtype:=stringtype;
  1044. tstringdef(result).len:=len;
  1045. tstringdef(result).savesize:=savesize;
  1046. end;
  1047. function tstringdef.stringtypname:string;
  1048. const
  1049. typname:array[tstringtype] of string[8]=(
  1050. 'shortstr','longstr','ansistr','widestr'
  1051. );
  1052. begin
  1053. stringtypname:=typname[stringtype];
  1054. end;
  1055. procedure tstringdef.ppuwrite(ppufile:tcompilerppufile);
  1056. begin
  1057. inherited ppuwrite(ppufile);
  1058. if stringtype=st_shortstring then
  1059. begin
  1060. {$ifdef extdebug}
  1061. if len > 255 then internalerror(12122002);
  1062. {$endif}
  1063. ppufile.putbyte(byte(len))
  1064. end
  1065. else
  1066. ppufile.putaint(len);
  1067. case stringtype of
  1068. st_shortstring : ppufile.writeentry(ibshortstringdef);
  1069. st_longstring : ppufile.writeentry(iblongstringdef);
  1070. st_ansistring : ppufile.writeentry(ibansistringdef);
  1071. st_widestring : ppufile.writeentry(ibwidestringdef);
  1072. end;
  1073. end;
  1074. function tstringdef.needs_inittable : boolean;
  1075. begin
  1076. needs_inittable:=stringtype in [st_ansistring,st_widestring];
  1077. end;
  1078. function tstringdef.GetTypeName : string;
  1079. const
  1080. names : array[tstringtype] of string[11] = (
  1081. 'ShortString','LongString','AnsiString','WideString');
  1082. begin
  1083. GetTypeName:=names[stringtype];
  1084. end;
  1085. function tstringdef.getvardef : longint;
  1086. const
  1087. vardef : array[tstringtype] of longint = (
  1088. varUndefined,varUndefined,varString,varOleStr);
  1089. begin
  1090. result:=vardef[stringtype];
  1091. end;
  1092. function tstringdef.alignment : shortint;
  1093. begin
  1094. case stringtype of
  1095. st_widestring,
  1096. st_ansistring:
  1097. alignment:=size_2_align(savesize);
  1098. st_longstring,
  1099. st_shortstring:
  1100. {$ifdef cpurequiresproperalignment}
  1101. { char to string accesses byte 0 and 1 with one word access }
  1102. alignment:=size_2_align(2);
  1103. {$else cpurequiresproperalignment}
  1104. alignment:=size_2_align(1);
  1105. {$endif cpurequiresproperalignment}
  1106. else
  1107. internalerror(200412301);
  1108. end;
  1109. end;
  1110. function tstringdef.getmangledparaname : string;
  1111. begin
  1112. getmangledparaname:='STRING';
  1113. end;
  1114. function tstringdef.is_publishable : boolean;
  1115. begin
  1116. is_publishable:=true;
  1117. end;
  1118. {****************************************************************************
  1119. TENUMDEF
  1120. ****************************************************************************}
  1121. constructor tenumdef.create;
  1122. begin
  1123. inherited create(enumdef);
  1124. minval:=0;
  1125. maxval:=0;
  1126. calcsavesize;
  1127. has_jumps:=false;
  1128. basedef:=nil;
  1129. firstenum:=nil;
  1130. end;
  1131. constructor tenumdef.create_subrange(_basedef:tenumdef;_min,_max:aint);
  1132. begin
  1133. inherited create(enumdef);
  1134. minval:=_min;
  1135. maxval:=_max;
  1136. basedef:=_basedef;
  1137. calcsavesize;
  1138. has_jumps:=false;
  1139. firstenum:=basedef.firstenum;
  1140. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1141. firstenum:=tenumsym(firstenum).nextenum;
  1142. end;
  1143. constructor tenumdef.ppuload(ppufile:tcompilerppufile);
  1144. begin
  1145. inherited ppuload(enumdef,ppufile);
  1146. ppufile.getderef(basedefderef);
  1147. minval:=ppufile.getaint;
  1148. maxval:=ppufile.getaint;
  1149. savesize:=ppufile.getaint;
  1150. has_jumps:=false;
  1151. firstenum:=Nil;
  1152. end;
  1153. function tenumdef.getcopy : tstoreddef;
  1154. begin
  1155. if assigned(basedef) then
  1156. result:=tenumdef.create_subrange(basedef,minval,maxval)
  1157. else
  1158. begin
  1159. result:=tenumdef.create;
  1160. tenumdef(result).minval:=minval;
  1161. tenumdef(result).maxval:=maxval;
  1162. end;
  1163. tenumdef(result).has_jumps:=has_jumps;
  1164. tenumdef(result).firstenum:=firstenum;
  1165. tenumdef(result).basedefderef:=basedefderef;
  1166. end;
  1167. procedure tenumdef.calcsavesize;
  1168. begin
  1169. if (current_settings.packenum=8) or (min<low(longint)) or (int64(max)>high(cardinal)) then
  1170. savesize:=8
  1171. else
  1172. if (current_settings.packenum=4) or (min<low(smallint)) or (max>high(word)) then
  1173. savesize:=4
  1174. else
  1175. if (current_settings.packenum=2) or (min<low(shortint)) or (max>high(byte)) then
  1176. savesize:=2
  1177. else
  1178. savesize:=1;
  1179. end;
  1180. function tenumdef.packedbitsize: aint;
  1181. var
  1182. power: longint;
  1183. begin
  1184. result := 0;
  1185. if (minval < 0) then
  1186. result := inherited packedbitsize
  1187. else
  1188. begin
  1189. if (maxval <= 1) then
  1190. result := 1
  1191. else
  1192. begin
  1193. { 256 must become 512 etc. }
  1194. nextpowerof2(maxval+1,power);
  1195. result := power;
  1196. end;
  1197. end;
  1198. end;
  1199. procedure tenumdef.setmax(_max:aint);
  1200. begin
  1201. maxval:=_max;
  1202. calcsavesize;
  1203. end;
  1204. procedure tenumdef.setmin(_min:aint);
  1205. begin
  1206. minval:=_min;
  1207. calcsavesize;
  1208. end;
  1209. function tenumdef.min:aint;
  1210. begin
  1211. min:=minval;
  1212. end;
  1213. function tenumdef.max:aint;
  1214. begin
  1215. max:=maxval;
  1216. end;
  1217. procedure tenumdef.buildderef;
  1218. begin
  1219. inherited buildderef;
  1220. basedefderef.build(basedef);
  1221. end;
  1222. procedure tenumdef.deref;
  1223. begin
  1224. inherited deref;
  1225. basedef:=tenumdef(basedefderef.resolve);
  1226. { restart ordering }
  1227. firstenum:=nil;
  1228. end;
  1229. procedure tenumdef.derefimpl;
  1230. begin
  1231. if assigned(basedef) and
  1232. (firstenum=nil) then
  1233. begin
  1234. firstenum:=basedef.firstenum;
  1235. while assigned(firstenum) and (tenumsym(firstenum).value<>minval) do
  1236. firstenum:=tenumsym(firstenum).nextenum;
  1237. end;
  1238. end;
  1239. procedure tenumdef.ppuwrite(ppufile:tcompilerppufile);
  1240. begin
  1241. inherited ppuwrite(ppufile);
  1242. ppufile.putderef(basedefderef);
  1243. ppufile.putaint(min);
  1244. ppufile.putaint(max);
  1245. ppufile.putaint(savesize);
  1246. ppufile.writeentry(ibenumdef);
  1247. end;
  1248. function tenumdef.is_publishable : boolean;
  1249. begin
  1250. is_publishable:=true;
  1251. end;
  1252. function tenumdef.GetTypeName : string;
  1253. begin
  1254. GetTypeName:='<enumeration type>';
  1255. end;
  1256. {****************************************************************************
  1257. TORDDEF
  1258. ****************************************************************************}
  1259. constructor torddef.create(t : tordtype;v,b : TConstExprInt);
  1260. begin
  1261. inherited create(orddef);
  1262. low:=v;
  1263. high:=b;
  1264. ordtype:=t;
  1265. setsize;
  1266. end;
  1267. constructor torddef.ppuload(ppufile:tcompilerppufile);
  1268. begin
  1269. inherited ppuload(orddef,ppufile);
  1270. ordtype:=tordtype(ppufile.getbyte);
  1271. if sizeof(TConstExprInt)=8 then
  1272. begin
  1273. low:=ppufile.getint64;
  1274. high:=ppufile.getint64;
  1275. end
  1276. else
  1277. begin
  1278. low:=ppufile.getlongint;
  1279. high:=ppufile.getlongint;
  1280. end;
  1281. setsize;
  1282. end;
  1283. function torddef.getcopy : tstoreddef;
  1284. begin
  1285. result:=torddef.create(ordtype,low,high);
  1286. result.typ:=orddef;
  1287. torddef(result).low:=low;
  1288. torddef(result).high:=high;
  1289. torddef(result).ordtype:=ordtype;
  1290. torddef(result).savesize:=savesize;
  1291. end;
  1292. function torddef.alignment:shortint;
  1293. begin
  1294. if (target_info.system = system_i386_darwin) and
  1295. (ordtype in [s64bit,u64bit]) then
  1296. result := 4
  1297. else
  1298. result := inherited alignment;
  1299. end;
  1300. procedure torddef.setsize;
  1301. const
  1302. sizetbl : array[tordtype] of longint = (
  1303. 0,
  1304. 1,2,4,8,
  1305. 1,2,4,8,
  1306. 1,2,4,8,
  1307. 1,2,8
  1308. );
  1309. begin
  1310. savesize:=sizetbl[ordtype];
  1311. end;
  1312. function torddef.packedbitsize: aint;
  1313. var
  1314. power: longint;
  1315. begin
  1316. result := 0;
  1317. if ordtype = uvoid then
  1318. exit;
  1319. if (low < 0) then
  1320. result := inherited packedbitsize
  1321. else
  1322. begin
  1323. if (high <= 1) then
  1324. result := 1
  1325. else if (ordtype = u64bit) then
  1326. result := 64
  1327. else
  1328. begin
  1329. { 256 must become 512 etc. }
  1330. nextpowerof2(high+1,power);
  1331. result := power;
  1332. end;
  1333. end;
  1334. end;
  1335. function torddef.getvardef : longint;
  1336. const
  1337. basetype2vardef : array[tordtype] of longint = (
  1338. varUndefined,
  1339. varbyte,varqword,varlongword,varqword,
  1340. varshortint,varsmallint,varinteger,varint64,
  1341. varboolean,varUndefined,varUndefined,varUndefined,
  1342. varUndefined,varUndefined,varCurrency);
  1343. begin
  1344. result:=basetype2vardef[ordtype];
  1345. end;
  1346. procedure torddef.ppuwrite(ppufile:tcompilerppufile);
  1347. begin
  1348. inherited ppuwrite(ppufile);
  1349. ppufile.putbyte(byte(ordtype));
  1350. if sizeof(TConstExprInt)=8 then
  1351. begin
  1352. ppufile.putint64(low);
  1353. ppufile.putint64(high);
  1354. end
  1355. else
  1356. begin
  1357. ppufile.putlongint(low);
  1358. ppufile.putlongint(high);
  1359. end;
  1360. ppufile.writeentry(iborddef);
  1361. end;
  1362. function torddef.is_publishable : boolean;
  1363. begin
  1364. is_publishable:=(ordtype<>uvoid);
  1365. end;
  1366. function torddef.GetTypeName : string;
  1367. const
  1368. names : array[tordtype] of string[20] = (
  1369. 'untyped',
  1370. 'Byte','Word','DWord','QWord',
  1371. 'ShortInt','SmallInt','LongInt','Int64',
  1372. 'Boolean','WordBool','LongBool','QWordBool',
  1373. 'Char','WideChar','Currency');
  1374. begin
  1375. GetTypeName:=names[ordtype];
  1376. end;
  1377. {****************************************************************************
  1378. TFLOATDEF
  1379. ****************************************************************************}
  1380. constructor tfloatdef.create(t : tfloattype);
  1381. begin
  1382. inherited create(floatdef);
  1383. floattype:=t;
  1384. setsize;
  1385. end;
  1386. constructor tfloatdef.ppuload(ppufile:tcompilerppufile);
  1387. begin
  1388. inherited ppuload(floatdef,ppufile);
  1389. floattype:=tfloattype(ppufile.getbyte);
  1390. setsize;
  1391. end;
  1392. function tfloatdef.getcopy : tstoreddef;
  1393. begin
  1394. result:=tfloatdef.create(floattype);
  1395. result.typ:=floatdef;
  1396. tfloatdef(result).savesize:=savesize;
  1397. end;
  1398. function tfloatdef.alignment:shortint;
  1399. begin
  1400. if (target_info.system = system_i386_darwin) then
  1401. case floattype of
  1402. s80real : result:=16;
  1403. s64real,
  1404. s64currency,
  1405. s64comp : result:=4;
  1406. else
  1407. result := inherited alignment;
  1408. end
  1409. else
  1410. result := inherited alignment;
  1411. end;
  1412. procedure tfloatdef.setsize;
  1413. begin
  1414. case floattype of
  1415. s32real : savesize:=4;
  1416. s80real : savesize:=10;
  1417. s64real,
  1418. s64currency,
  1419. s64comp : savesize:=8;
  1420. else
  1421. savesize:=0;
  1422. end;
  1423. end;
  1424. function tfloatdef.getvardef : longint;
  1425. const
  1426. floattype2vardef : array[tfloattype] of longint = (
  1427. varSingle,varDouble,varUndefined,
  1428. varUndefined,varCurrency,varUndefined);
  1429. begin
  1430. if (upper(typename)='TDATETIME') and
  1431. assigned(owner) and
  1432. assigned(owner.name) and
  1433. (owner.name^='SYSTEM') then
  1434. result:=varDate
  1435. else
  1436. result:=floattype2vardef[floattype];
  1437. end;
  1438. procedure tfloatdef.ppuwrite(ppufile:tcompilerppufile);
  1439. begin
  1440. inherited ppuwrite(ppufile);
  1441. ppufile.putbyte(byte(floattype));
  1442. ppufile.writeentry(ibfloatdef);
  1443. end;
  1444. function tfloatdef.is_publishable : boolean;
  1445. begin
  1446. is_publishable:=true;
  1447. end;
  1448. function tfloatdef.GetTypeName : string;
  1449. const
  1450. names : array[tfloattype] of string[20] = (
  1451. 'Single','Double','Extended','Comp','Currency','Float128');
  1452. begin
  1453. GetTypeName:=names[floattype];
  1454. end;
  1455. {****************************************************************************
  1456. TFILEDEF
  1457. ****************************************************************************}
  1458. constructor tfiledef.createtext;
  1459. begin
  1460. inherited create(filedef);
  1461. filetyp:=ft_text;
  1462. typedfiledef:=nil;
  1463. setsize;
  1464. end;
  1465. constructor tfiledef.createuntyped;
  1466. begin
  1467. inherited create(filedef);
  1468. filetyp:=ft_untyped;
  1469. typedfiledef:=nil;
  1470. setsize;
  1471. end;
  1472. constructor tfiledef.createtyped(def:tdef);
  1473. begin
  1474. inherited create(filedef);
  1475. filetyp:=ft_typed;
  1476. typedfiledef:=def;
  1477. setsize;
  1478. end;
  1479. constructor tfiledef.ppuload(ppufile:tcompilerppufile);
  1480. begin
  1481. inherited ppuload(filedef,ppufile);
  1482. filetyp:=tfiletyp(ppufile.getbyte);
  1483. if filetyp=ft_typed then
  1484. ppufile.getderef(typedfiledefderef)
  1485. else
  1486. typedfiledef:=nil;
  1487. setsize;
  1488. end;
  1489. function tfiledef.getcopy : tstoreddef;
  1490. begin
  1491. case filetyp of
  1492. ft_typed:
  1493. result:=tfiledef.createtyped(typedfiledef);
  1494. ft_untyped:
  1495. result:=tfiledef.createuntyped;
  1496. ft_text:
  1497. result:=tfiledef.createtext;
  1498. else
  1499. internalerror(2004121201);
  1500. end;
  1501. end;
  1502. procedure tfiledef.buildderef;
  1503. begin
  1504. inherited buildderef;
  1505. if filetyp=ft_typed then
  1506. typedfiledefderef.build(typedfiledef);
  1507. end;
  1508. procedure tfiledef.deref;
  1509. begin
  1510. inherited deref;
  1511. if filetyp=ft_typed then
  1512. typedfiledef:=tdef(typedfiledefderef.resolve);
  1513. end;
  1514. procedure tfiledef.setsize;
  1515. begin
  1516. {$ifdef cpu64bit}
  1517. case filetyp of
  1518. ft_text :
  1519. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1520. savesize:=632
  1521. else
  1522. savesize:=628;
  1523. ft_typed,
  1524. ft_untyped :
  1525. if target_info.system in [system_x86_64_win64,system_ia64_win64] then
  1526. savesize:=372
  1527. else
  1528. savesize:=368;
  1529. end;
  1530. {$else cpu64bit}
  1531. case filetyp of
  1532. ft_text :
  1533. savesize:=592;
  1534. ft_typed,
  1535. ft_untyped :
  1536. savesize:=332;
  1537. end;
  1538. {$endif cpu64bit}
  1539. end;
  1540. procedure tfiledef.ppuwrite(ppufile:tcompilerppufile);
  1541. begin
  1542. inherited ppuwrite(ppufile);
  1543. ppufile.putbyte(byte(filetyp));
  1544. if filetyp=ft_typed then
  1545. ppufile.putderef(typedfiledefderef);
  1546. ppufile.writeentry(ibfiledef);
  1547. end;
  1548. function tfiledef.GetTypeName : string;
  1549. begin
  1550. case filetyp of
  1551. ft_untyped:
  1552. GetTypeName:='File';
  1553. ft_typed:
  1554. GetTypeName:='File Of '+typedfiledef.typename;
  1555. ft_text:
  1556. GetTypeName:='Text'
  1557. end;
  1558. end;
  1559. function tfiledef.getmangledparaname : string;
  1560. begin
  1561. case filetyp of
  1562. ft_untyped:
  1563. getmangledparaname:='FILE';
  1564. ft_typed:
  1565. getmangledparaname:='FILE$OF$'+typedfiledef.mangledparaname;
  1566. ft_text:
  1567. getmangledparaname:='TEXT'
  1568. end;
  1569. end;
  1570. {****************************************************************************
  1571. TVARIANTDEF
  1572. ****************************************************************************}
  1573. constructor tvariantdef.create(v : tvarianttype);
  1574. begin
  1575. inherited create(variantdef);
  1576. varianttype:=v;
  1577. setsize;
  1578. end;
  1579. constructor tvariantdef.ppuload(ppufile:tcompilerppufile);
  1580. begin
  1581. inherited ppuload(variantdef,ppufile);
  1582. varianttype:=tvarianttype(ppufile.getbyte);
  1583. setsize;
  1584. end;
  1585. function tvariantdef.getcopy : tstoreddef;
  1586. begin
  1587. result:=tvariantdef.create(varianttype);
  1588. end;
  1589. procedure tvariantdef.ppuwrite(ppufile:tcompilerppufile);
  1590. begin
  1591. inherited ppuwrite(ppufile);
  1592. ppufile.putbyte(byte(varianttype));
  1593. ppufile.writeentry(ibvariantdef);
  1594. end;
  1595. procedure tvariantdef.setsize;
  1596. begin
  1597. {$ifdef cpu64bit}
  1598. savesize:=24;
  1599. {$else cpu64bit}
  1600. savesize:=16;
  1601. {$endif cpu64bit}
  1602. end;
  1603. function tvariantdef.GetTypeName : string;
  1604. begin
  1605. case varianttype of
  1606. vt_normalvariant:
  1607. GetTypeName:='Variant';
  1608. vt_olevariant:
  1609. GetTypeName:='OleVariant';
  1610. end;
  1611. end;
  1612. function tvariantdef.needs_inittable : boolean;
  1613. begin
  1614. needs_inittable:=true;
  1615. end;
  1616. function tvariantdef.is_publishable : boolean;
  1617. begin
  1618. is_publishable:=true;
  1619. end;
  1620. {****************************************************************************
  1621. TABSTRACtpointerdef
  1622. ****************************************************************************}
  1623. constructor tabstractpointerdef.create(dt:tdeftyp;def:tdef);
  1624. begin
  1625. inherited create(dt);
  1626. pointeddef:=def;
  1627. savesize:=sizeof(aint);
  1628. end;
  1629. constructor tabstractpointerdef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
  1630. begin
  1631. inherited ppuload(dt,ppufile);
  1632. ppufile.getderef(pointeddefderef);
  1633. savesize:=sizeof(aint);
  1634. end;
  1635. procedure tabstractpointerdef.buildderef;
  1636. begin
  1637. inherited buildderef;
  1638. pointeddefderef.build(pointeddef);
  1639. end;
  1640. procedure tabstractpointerdef.deref;
  1641. begin
  1642. inherited deref;
  1643. pointeddef:=tdef(pointeddefderef.resolve);
  1644. end;
  1645. procedure tabstractpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1646. begin
  1647. inherited ppuwrite(ppufile);
  1648. ppufile.putderef(pointeddefderef);
  1649. end;
  1650. {****************************************************************************
  1651. tpointerdef
  1652. ****************************************************************************}
  1653. constructor tpointerdef.create(def:tdef);
  1654. begin
  1655. inherited create(pointerdef,def);
  1656. is_far:=false;
  1657. end;
  1658. constructor tpointerdef.createfar(def:tdef);
  1659. begin
  1660. inherited create(pointerdef,def);
  1661. is_far:=true;
  1662. end;
  1663. constructor tpointerdef.ppuload(ppufile:tcompilerppufile);
  1664. begin
  1665. inherited ppuload(pointerdef,ppufile);
  1666. is_far:=(ppufile.getbyte<>0);
  1667. end;
  1668. function tpointerdef.getcopy : tstoreddef;
  1669. begin
  1670. result:=tpointerdef.create(pointeddef);
  1671. tpointerdef(result).is_far:=is_far;
  1672. tpointerdef(result).savesize:=savesize;
  1673. end;
  1674. procedure tpointerdef.ppuwrite(ppufile:tcompilerppufile);
  1675. begin
  1676. inherited ppuwrite(ppufile);
  1677. ppufile.putbyte(byte(is_far));
  1678. ppufile.writeentry(ibpointerdef);
  1679. end;
  1680. function tpointerdef.GetTypeName : string;
  1681. begin
  1682. if is_far then
  1683. GetTypeName:='^'+pointeddef.typename+';far'
  1684. else
  1685. GetTypeName:='^'+pointeddef.typename;
  1686. end;
  1687. {****************************************************************************
  1688. TCLASSREFDEF
  1689. ****************************************************************************}
  1690. constructor tclassrefdef.create(def:tdef);
  1691. begin
  1692. inherited create(classrefdef,def);
  1693. end;
  1694. constructor tclassrefdef.ppuload(ppufile:tcompilerppufile);
  1695. begin
  1696. inherited ppuload(classrefdef,ppufile);
  1697. end;
  1698. procedure tclassrefdef.ppuwrite(ppufile:tcompilerppufile);
  1699. begin
  1700. inherited ppuwrite(ppufile);
  1701. ppufile.writeentry(ibclassrefdef);
  1702. end;
  1703. function tclassrefdef.GetTypeName : string;
  1704. begin
  1705. GetTypeName:='Class Of '+pointeddef.typename;
  1706. end;
  1707. function tclassrefdef.is_publishable : boolean;
  1708. begin
  1709. result:=true;
  1710. end;
  1711. {***************************************************************************
  1712. TSETDEF
  1713. ***************************************************************************}
  1714. constructor tsetdef.create(def:tdef;high : aint);
  1715. begin
  1716. inherited create(setdef);
  1717. elementdef:=def;
  1718. // setbase:=low;
  1719. setmax:=high;
  1720. if high<32 then
  1721. begin
  1722. settype:=smallset;
  1723. if current_settings.setalloc=0 then { $PACKSET Fixed?}
  1724. savesize:=Sizeof(longint)
  1725. else
  1726. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1727. if savesize=3 then
  1728. savesize:=4;
  1729. end
  1730. else
  1731. if high<256 then
  1732. begin
  1733. settype:=normset;
  1734. if current_settings.setalloc=0 then { $PACKSET Fixed?}
  1735. savesize:=32
  1736. else {No, use $PACKSET VALUE for rounding}
  1737. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1738. end
  1739. else
  1740. savesize:=current_settings.setalloc*(((high+1)+current_settings.setalloc*8-1) DIV (current_settings.setalloc*8));
  1741. end;
  1742. constructor tsetdef.ppuload(ppufile:tcompilerppufile);
  1743. begin
  1744. inherited ppuload(setdef,ppufile);
  1745. ppufile.getderef(elementdefderef);
  1746. settype:=tsettype(ppufile.getbyte);
  1747. case settype of
  1748. normset :
  1749. savesize:=ppufile.getaint;
  1750. varset,
  1751. smallset :
  1752. savesize:=ppufile.getlongint;
  1753. end;
  1754. end;
  1755. function tsetdef.getcopy : tstoreddef;
  1756. begin
  1757. result:=tsetdef.create(elementdef,setmax);
  1758. { the copy might have been created with a different setalloc setting }
  1759. tsetdef(result).settype:=settype;
  1760. tsetdef(result).savesize:=savesize;
  1761. end;
  1762. procedure tsetdef.ppuwrite(ppufile:tcompilerppufile);
  1763. begin
  1764. inherited ppuwrite(ppufile);
  1765. ppufile.putderef(elementdefderef);
  1766. ppufile.putbyte(byte(settype));
  1767. case settype of
  1768. varset,
  1769. smallset:
  1770. ppufile.putlongint(savesize);
  1771. normset:
  1772. ppufile.putaint(savesize);
  1773. end;
  1774. ppufile.writeentry(ibsetdef);
  1775. end;
  1776. procedure tsetdef.buildderef;
  1777. begin
  1778. inherited buildderef;
  1779. elementdefderef.build(elementdef);
  1780. end;
  1781. procedure tsetdef.deref;
  1782. begin
  1783. inherited deref;
  1784. elementdef:=tdef(elementdefderef.resolve);
  1785. end;
  1786. function tsetdef.is_publishable : boolean;
  1787. begin
  1788. is_publishable:=(settype=smallset);
  1789. end;
  1790. function tsetdef.GetTypeName : string;
  1791. begin
  1792. if assigned(elementdef) then
  1793. GetTypeName:='Set Of '+elementdef.typename
  1794. else
  1795. GetTypeName:='Empty Set';
  1796. end;
  1797. {***************************************************************************
  1798. TFORMALDEF
  1799. ***************************************************************************}
  1800. constructor tformaldef.create;
  1801. begin
  1802. inherited create(formaldef);
  1803. savesize:=0;
  1804. end;
  1805. constructor tformaldef.ppuload(ppufile:tcompilerppufile);
  1806. begin
  1807. inherited ppuload(formaldef,ppufile);
  1808. savesize:=0;
  1809. end;
  1810. procedure tformaldef.ppuwrite(ppufile:tcompilerppufile);
  1811. begin
  1812. inherited ppuwrite(ppufile);
  1813. ppufile.writeentry(ibformaldef);
  1814. end;
  1815. function tformaldef.GetTypeName : string;
  1816. begin
  1817. GetTypeName:='<Formal type>';
  1818. end;
  1819. {***************************************************************************
  1820. TARRAYDEF
  1821. ***************************************************************************}
  1822. constructor tarraydef.create(l,h : aint;def:tdef);
  1823. begin
  1824. inherited create(arraydef);
  1825. lowrange:=l;
  1826. highrange:=h;
  1827. rangedef:=def;
  1828. _elementdef:=nil;
  1829. arrayoptions:=[];
  1830. end;
  1831. constructor tarraydef.create_from_pointer(def:tdef);
  1832. begin
  1833. { use -1 so that the elecount will not overflow }
  1834. self.create(0,$7fffffff-1,s32inttype);
  1835. arrayoptions:=[ado_IsConvertedPointer];
  1836. setelementdef(def);
  1837. end;
  1838. constructor tarraydef.ppuload(ppufile:tcompilerppufile);
  1839. begin
  1840. inherited ppuload(arraydef,ppufile);
  1841. { the addresses are calculated later }
  1842. ppufile.getderef(_elementdefderef);
  1843. ppufile.getderef(rangedefderef);
  1844. lowrange:=ppufile.getaint;
  1845. highrange:=ppufile.getaint;
  1846. ppufile.getsmallset(arrayoptions);
  1847. end;
  1848. function tarraydef.getcopy : tstoreddef;
  1849. begin
  1850. result:=tarraydef.create(lowrange,highrange,rangedef);
  1851. tarraydef(result).arrayoptions:=arrayoptions;
  1852. tarraydef(result)._elementdef:=_elementdef;
  1853. end;
  1854. procedure tarraydef.buildderef;
  1855. begin
  1856. inherited buildderef;
  1857. _elementdefderef.build(_elementdef);
  1858. rangedefderef.build(rangedef);
  1859. end;
  1860. procedure tarraydef.deref;
  1861. begin
  1862. inherited deref;
  1863. _elementdef:=tdef(_elementdefderef.resolve);
  1864. rangedef:=tdef(rangedefderef.resolve);
  1865. end;
  1866. procedure tarraydef.ppuwrite(ppufile:tcompilerppufile);
  1867. begin
  1868. inherited ppuwrite(ppufile);
  1869. ppufile.putderef(_elementdefderef);
  1870. ppufile.putderef(rangedefderef);
  1871. ppufile.putaint(lowrange);
  1872. ppufile.putaint(highrange);
  1873. ppufile.putsmallset(arrayoptions);
  1874. ppufile.writeentry(ibarraydef);
  1875. end;
  1876. function tarraydef.elesize : aint;
  1877. begin
  1878. if (ado_IsBitPacked in arrayoptions) then
  1879. internalerror(2006080101);
  1880. if assigned(_elementdef) then
  1881. result:=_elementdef.size
  1882. else
  1883. result:=0;
  1884. end;
  1885. function tarraydef.elepackedbitsize : aint;
  1886. begin
  1887. if not(ado_IsBitPacked in arrayoptions) then
  1888. internalerror(2006080102);
  1889. if assigned(_elementdef) then
  1890. result:=_elementdef.packedbitsize
  1891. else
  1892. result:=0;
  1893. end;
  1894. function tarraydef.elecount : aint;
  1895. var
  1896. qhigh,qlow : qword;
  1897. begin
  1898. if ado_IsDynamicArray in arrayoptions then
  1899. begin
  1900. result:=0;
  1901. exit;
  1902. end;
  1903. if (highrange>0) and (lowrange<0) then
  1904. begin
  1905. qhigh:=highrange;
  1906. qlow:=qword(-lowrange);
  1907. { prevent overflow, return -1 to indicate overflow }
  1908. if qhigh+qlow>qword(high(aint)-1) then
  1909. result:=-1
  1910. else
  1911. result:=qhigh+qlow+1;
  1912. end
  1913. else
  1914. result:=int64(highrange)-lowrange+1;
  1915. end;
  1916. function tarraydef.size : aint;
  1917. var
  1918. cachedelecount,
  1919. cachedelesize : aint;
  1920. begin
  1921. if ado_IsDynamicArray in arrayoptions then
  1922. begin
  1923. size:=sizeof(aint);
  1924. exit;
  1925. end;
  1926. { Tarraydef.size may never be called for an open array! }
  1927. if highrange<lowrange then
  1928. internalerror(99080501);
  1929. if not (ado_IsBitPacked in arrayoptions) then
  1930. cachedelesize:=elesize
  1931. else
  1932. cachedelesize := elepackedbitsize;
  1933. cachedelecount:=elecount;
  1934. if (cachedelesize = 0) then
  1935. begin
  1936. size := 0;
  1937. exit;
  1938. end;
  1939. if (cachedelecount = -1) then
  1940. begin
  1941. size := -1;
  1942. exit;
  1943. end;
  1944. { prevent overflow, return -1 to indicate overflow }
  1945. { also make sure we don't need 64/128 bit arithmetic to calculate offsets }
  1946. if (cachedelecount > high(aint)) or
  1947. ((high(aint) div cachedelesize) < cachedelecount) or
  1948. { also lowrange*elesize must be < high(aint) to prevent overflow when
  1949. accessing the array, see ncgmem (PFV) }
  1950. ((high(aint) div cachedelesize) < abs(lowrange)) then
  1951. begin
  1952. result:=-1;
  1953. exit;
  1954. end;
  1955. if (ado_IsBitPacked in arrayoptions) then
  1956. size:=(cachedelesize * cachedelecount + 7) div 8
  1957. else
  1958. result:=cachedelesize*cachedelecount;
  1959. end;
  1960. procedure tarraydef.setelementdef(def:tdef);
  1961. begin
  1962. _elementdef:=def;
  1963. if not(
  1964. (ado_IsDynamicArray in arrayoptions) or
  1965. (ado_IsConvertedPointer in arrayoptions) or
  1966. (highrange<lowrange)
  1967. ) and
  1968. (size=-1) then
  1969. Message(sym_e_segment_too_large);
  1970. end;
  1971. function tarraydef.alignment : shortint;
  1972. begin
  1973. { alignment is the size of the elements }
  1974. 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:=tstringlist.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:=tstringlist.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. iitype := etStandard;
  3077. end;
  3078. constructor tobjectdef.ppuload(ppufile:tcompilerppufile);
  3079. var
  3080. i,
  3081. implintfcount : longint;
  3082. d : tderef;
  3083. ImplIntf : TImplementedInterface;
  3084. begin
  3085. inherited ppuload(objectdef,ppufile);
  3086. objecttype:=tobjecttyp(ppufile.getbyte);
  3087. objrealname:=stringdup(ppufile.getstring);
  3088. objname:=stringdup(upper(objrealname^));
  3089. symtable:=tObjectSymtable.create(self,objrealname^,0);
  3090. tObjectSymtable(symtable).datasize:=ppufile.getaint;
  3091. tObjectSymtable(symtable).fieldalignment:=ppufile.getbyte;
  3092. tObjectSymtable(symtable).recordalignment:=ppufile.getbyte;
  3093. vmt_offset:=ppufile.getlongint;
  3094. vmtentries:=nil;
  3095. ppufile.getderef(childofderef);
  3096. ppufile.getsmallset(objectoptions);
  3097. { load guid }
  3098. iidstr:=nil;
  3099. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3100. begin
  3101. new(iidguid);
  3102. ppufile.getguid(iidguid^);
  3103. iidstr:=stringdup(ppufile.getstring);
  3104. end;
  3105. { load implemented interfaces }
  3106. if objecttype in [odt_class,odt_interfacecorba] then
  3107. begin
  3108. ImplementedInterfaces:=TFPObjectList.Create(true);
  3109. implintfcount:=ppufile.getlongint;
  3110. for i:=0 to implintfcount-1 do
  3111. begin
  3112. ppufile.getderef(d);
  3113. ImplIntf:=TImplementedInterface.Create_deref(d);
  3114. ImplIntf.IOffset:=ppufile.getlongint;
  3115. ImplementedInterfaces.Add(ImplIntf);
  3116. end;
  3117. end
  3118. else
  3119. ImplementedInterfaces:=nil;
  3120. tObjectSymtable(symtable).ppuload(ppufile);
  3121. { handles the predefined class tobject }
  3122. { the last TOBJECT which is loaded gets }
  3123. { it ! }
  3124. if (childof=nil) and
  3125. (objecttype=odt_class) and
  3126. (objname^='TOBJECT') then
  3127. class_tobject:=self;
  3128. if (childof=nil) and
  3129. (objecttype=odt_interfacecom) and
  3130. (objname^='IUNKNOWN') then
  3131. interface_iunknown:=self;
  3132. writing_class_record_dbginfo:=false;
  3133. end;
  3134. destructor tobjectdef.destroy;
  3135. begin
  3136. if assigned(symtable) then
  3137. begin
  3138. symtable.free;
  3139. symtable:=nil;
  3140. end;
  3141. stringdispose(objname);
  3142. stringdispose(objrealname);
  3143. stringdispose(iidstr);
  3144. if assigned(ImplementedInterfaces) then
  3145. begin
  3146. ImplementedInterfaces.free;
  3147. ImplementedInterfaces:=nil;
  3148. end;
  3149. if assigned(iidguid) then
  3150. begin
  3151. dispose(iidguid);
  3152. iidguid:=nil;
  3153. end;
  3154. if assigned(vmtentries) then
  3155. begin
  3156. vmtentries.free;
  3157. vmtentries:=nil;
  3158. end;
  3159. inherited destroy;
  3160. end;
  3161. function tobjectdef.getcopy : tstoreddef;
  3162. var
  3163. i : longint;
  3164. begin
  3165. result:=tobjectdef.create(objecttype,objname^,childof);
  3166. tobjectdef(result).symtable:=symtable.getcopy;
  3167. if assigned(objname) then
  3168. tobjectdef(result).objname:=stringdup(objname^);
  3169. if assigned(objrealname) then
  3170. tobjectdef(result).objrealname:=stringdup(objrealname^);
  3171. tobjectdef(result).objectoptions:=objectoptions;
  3172. tobjectdef(result).vmt_offset:=vmt_offset;
  3173. if assigned(iidguid) then
  3174. begin
  3175. new(tobjectdef(result).iidguid);
  3176. move(iidguid^,tobjectdef(result).iidguid^,sizeof(iidguid^));
  3177. end;
  3178. if assigned(iidstr) then
  3179. tobjectdef(result).iidstr:=stringdup(iidstr^);
  3180. if assigned(ImplementedInterfaces) then
  3181. begin
  3182. for i:=0 to ImplementedInterfaces.count-1 do
  3183. tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
  3184. end;
  3185. if assigned(vmtentries) then
  3186. begin
  3187. tobjectdef(result).vmtentries:=TFPobjectList.Create(false);
  3188. tobjectdef(result).vmtentries.Assign(vmtentries);
  3189. end;
  3190. end;
  3191. procedure tobjectdef.ppuwrite(ppufile:tcompilerppufile);
  3192. var
  3193. i : longint;
  3194. ImplIntf : TImplementedInterface;
  3195. begin
  3196. inherited ppuwrite(ppufile);
  3197. ppufile.putbyte(byte(objecttype));
  3198. ppufile.putstring(objrealname^);
  3199. ppufile.putaint(tObjectSymtable(symtable).datasize);
  3200. ppufile.putbyte(tObjectSymtable(symtable).fieldalignment);
  3201. ppufile.putbyte(tObjectSymtable(symtable).recordalignment);
  3202. ppufile.putlongint(vmt_offset);
  3203. ppufile.putderef(childofderef);
  3204. ppufile.putsmallset(objectoptions);
  3205. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3206. begin
  3207. ppufile.putguid(iidguid^);
  3208. ppufile.putstring(iidstr^);
  3209. end;
  3210. if objecttype in [odt_class,odt_interfacecorba] then
  3211. begin
  3212. ppufile.putlongint(ImplementedInterfaces.Count);
  3213. for i:=0 to ImplementedInterfaces.Count-1 do
  3214. begin
  3215. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3216. ppufile.putderef(ImplIntf.intfdefderef);
  3217. ppufile.putlongint(ImplIntf.Ioffset);
  3218. end;
  3219. end;
  3220. ppufile.writeentry(ibobjectdef);
  3221. tObjectSymtable(symtable).ppuwrite(ppufile);
  3222. end;
  3223. function tobjectdef.GetTypeName:string;
  3224. begin
  3225. if (self <> aktobjectdef) then
  3226. GetTypeName:=typename
  3227. else
  3228. { in this case we will go in endless recursion, because then }
  3229. { there is no tsym associated yet with the def. It can occur }
  3230. { (tests/webtbf/tw4757.pp), so for now give a generic name }
  3231. { instead of the actual type name }
  3232. GetTypeName:='<Currently Parsed Class>';
  3233. end;
  3234. procedure tobjectdef.buildderef;
  3235. var
  3236. i : longint;
  3237. begin
  3238. inherited buildderef;
  3239. childofderef.build(childof);
  3240. tstoredsymtable(symtable).buildderef;
  3241. if objecttype in [odt_class,odt_interfacecorba] then
  3242. begin
  3243. for i:=0 to ImplementedInterfaces.count-1 do
  3244. TImplementedInterface(ImplementedInterfaces[i]).buildderef;
  3245. end;
  3246. end;
  3247. procedure tobjectdef.deref;
  3248. var
  3249. i : longint;
  3250. begin
  3251. inherited deref;
  3252. childof:=tobjectdef(childofderef.resolve);
  3253. tstoredsymtable(symtable).deref;
  3254. if objecttype in [odt_class,odt_interfacecorba] then
  3255. begin
  3256. for i:=0 to ImplementedInterfaces.count-1 do
  3257. TImplementedInterface(ImplementedInterfaces[i]).deref;
  3258. end;
  3259. end;
  3260. function tobjectdef.getparentdef:tdef;
  3261. begin
  3262. {$warning TODO Remove getparentdef hack}
  3263. { With 2 forward declared classes with the child class before the
  3264. parent class the child class is written earlier to the ppu. Leaving it
  3265. possible to have a reference to the parent class for property overriding,
  3266. but the parent class still has the childof not resolved yet (PFV) }
  3267. if childof=nil then
  3268. childof:=tobjectdef(childofderef.resolve);
  3269. result:=childof;
  3270. end;
  3271. procedure tobjectdef.prepareguid;
  3272. begin
  3273. { set up guid }
  3274. if not assigned(iidguid) then
  3275. begin
  3276. new(iidguid);
  3277. fillchar(iidguid^,sizeof(iidguid^),0); { default null guid }
  3278. end;
  3279. { setup iidstring }
  3280. if not assigned(iidstr) then
  3281. iidstr:=stringdup(''); { default is empty string }
  3282. end;
  3283. procedure tobjectdef.set_parent( c : tobjectdef);
  3284. begin
  3285. { nothing to do if the parent was not forward !}
  3286. if assigned(childof) then
  3287. exit;
  3288. childof:=c;
  3289. { some options are inherited !! }
  3290. if assigned(c) then
  3291. begin
  3292. { only important for classes }
  3293. objectoptions:=objectoptions+(c.objectoptions*inherited_objectoptions);
  3294. if not (objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3295. begin
  3296. { add the data of the anchestor class }
  3297. inc(tObjectSymtable(symtable).datasize,tObjectSymtable(c.symtable).datasize);
  3298. if (oo_has_vmt in objectoptions) and
  3299. (oo_has_vmt in c.objectoptions) then
  3300. dec(tObjectSymtable(symtable).datasize,sizeof(aint));
  3301. { if parent has a vmt field then
  3302. the offset is the same for the child PM }
  3303. if (oo_has_vmt in c.objectoptions) or is_class(self) then
  3304. begin
  3305. vmt_offset:=c.vmt_offset;
  3306. include(objectoptions,oo_has_vmt);
  3307. end;
  3308. end;
  3309. end;
  3310. end;
  3311. procedure tobjectdef.insertvmt;
  3312. begin
  3313. if objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3314. exit;
  3315. if (oo_has_vmt in objectoptions) then
  3316. internalerror(12345)
  3317. else
  3318. begin
  3319. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,
  3320. tObjectSymtable(symtable).fieldalignment);
  3321. {$ifdef cpurequiresproperalignment}
  3322. tObjectSymtable(symtable).datasize:=align(tObjectSymtable(symtable).datasize,sizeof(aint));
  3323. {$endif cpurequiresproperalignment}
  3324. vmt_offset:=tObjectSymtable(symtable).datasize;
  3325. inc(tObjectSymtable(symtable).datasize,sizeof(aint));
  3326. include(objectoptions,oo_has_vmt);
  3327. end;
  3328. end;
  3329. procedure tobjectdef.check_forwards;
  3330. begin
  3331. if not(objecttype in [odt_interfacecom,odt_interfacecorba,odt_dispinterface]) then
  3332. tstoredsymtable(symtable).check_forwards;
  3333. if (oo_is_forward in objectoptions) then
  3334. begin
  3335. { ok, in future, the forward can be resolved }
  3336. Message1(sym_e_class_forward_not_resolved,objrealname^);
  3337. exclude(objectoptions,oo_is_forward);
  3338. end;
  3339. end;
  3340. { true, if self inherits from d (or if they are equal) }
  3341. function tobjectdef.is_related(d : tdef) : boolean;
  3342. var
  3343. hp : tobjectdef;
  3344. begin
  3345. hp:=self;
  3346. while assigned(hp) do
  3347. begin
  3348. if hp=d then
  3349. begin
  3350. is_related:=true;
  3351. exit;
  3352. end;
  3353. hp:=hp.childof;
  3354. end;
  3355. is_related:=false;
  3356. end;
  3357. function tobjectdef.FindDestructor : tprocdef;
  3358. var
  3359. objdef : tobjectdef;
  3360. i : longint;
  3361. sym : tsym;
  3362. pd : tprocdef;
  3363. begin
  3364. result:=nil;
  3365. objdef:=self;
  3366. while assigned(objdef) do
  3367. begin
  3368. for i:=0 to objdef.symtable.SymList.Count-1 do
  3369. begin
  3370. sym:=TSym(objdef.symtable.SymList[i]);
  3371. if sym.typ=procsym then
  3372. begin
  3373. pd:=Tprocsym(sym).Find_procdef_bytype(potype_destructor);
  3374. if assigned(pd) then
  3375. begin
  3376. result:=pd;
  3377. exit;
  3378. end;
  3379. end;
  3380. end;
  3381. objdef:=objdef.childof;
  3382. end;
  3383. end;
  3384. function tobjectdef.size : aint;
  3385. begin
  3386. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3387. result:=sizeof(aint)
  3388. else
  3389. result:=tObjectSymtable(symtable).datasize;
  3390. end;
  3391. function tobjectdef.alignment:shortint;
  3392. begin
  3393. if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface] then
  3394. alignment:=sizeof(aint)
  3395. else
  3396. alignment:=tObjectSymtable(symtable).recordalignment;
  3397. end;
  3398. function tobjectdef.vmtmethodoffset(index:longint):longint;
  3399. begin
  3400. { for offset of methods for classes, see rtl/inc/objpash.inc }
  3401. case objecttype of
  3402. odt_class:
  3403. { the +2*sizeof(Aint) is size and -size }
  3404. vmtmethodoffset:=(index+10)*sizeof(aint)+2*sizeof(AInt);
  3405. odt_interfacecom,odt_interfacecorba:
  3406. vmtmethodoffset:=index*sizeof(aint);
  3407. else
  3408. {$ifdef WITHDMT}
  3409. vmtmethodoffset:=(index+4)*sizeof(aint);
  3410. {$else WITHDMT}
  3411. vmtmethodoffset:=(index+3)*sizeof(aint);
  3412. {$endif WITHDMT}
  3413. end;
  3414. end;
  3415. function tobjectdef.vmt_mangledname : string;
  3416. begin
  3417. if not(oo_has_vmt in objectoptions) then
  3418. Message1(parser_n_object_has_no_vmt,objrealname^);
  3419. vmt_mangledname:=make_mangledname('VMT',owner,objname^);
  3420. end;
  3421. function tobjectdef.needs_inittable : boolean;
  3422. begin
  3423. case objecttype of
  3424. odt_dispinterface,
  3425. odt_class :
  3426. needs_inittable:=false;
  3427. odt_interfacecom:
  3428. needs_inittable:=true;
  3429. odt_interfacecorba:
  3430. needs_inittable:=is_related(interface_iunknown);
  3431. odt_object:
  3432. needs_inittable:=tObjectSymtable(symtable).needs_init_final;
  3433. else
  3434. internalerror(200108267);
  3435. end;
  3436. end;
  3437. function tobjectdef.members_need_inittable : boolean;
  3438. begin
  3439. members_need_inittable:=tObjectSymtable(symtable).needs_init_final;
  3440. end;
  3441. function tobjectdef.find_implemented_interface(aintfdef:tobjectdef):TImplementedInterface;
  3442. var
  3443. ImplIntf : TImplementedInterface;
  3444. i : longint;
  3445. begin
  3446. result:=nil;
  3447. if not assigned(ImplementedInterfaces) then
  3448. exit;
  3449. for i:=0 to ImplementedInterfaces.Count-1 do
  3450. begin
  3451. ImplIntf:=TImplementedInterface(ImplementedInterfaces[i]);
  3452. if ImplIntf.intfdef=aintfdef then
  3453. begin
  3454. result:=ImplIntf;
  3455. exit;
  3456. end;
  3457. end;
  3458. end;
  3459. function tobjectdef.is_publishable : boolean;
  3460. begin
  3461. is_publishable:=objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface];
  3462. end;
  3463. {****************************************************************************
  3464. TImplementedInterface
  3465. ****************************************************************************}
  3466. constructor TImplementedInterface.create(aintf: tobjectdef);
  3467. begin
  3468. inherited create;
  3469. intfdef:=aintf;
  3470. ioffset:=-1;
  3471. NameMappings:=nil;
  3472. procdefs:=nil;
  3473. end;
  3474. constructor TImplementedInterface.create_deref(d:tderef);
  3475. begin
  3476. inherited create;
  3477. intfdef:=nil;
  3478. intfdefderef:=d;
  3479. ioffset:=-1;
  3480. NameMappings:=nil;
  3481. procdefs:=nil;
  3482. end;
  3483. destructor TImplementedInterface.destroy;
  3484. var
  3485. i : longint;
  3486. mappedname : pshortstring;
  3487. begin
  3488. if assigned(NameMappings) then
  3489. begin
  3490. for i:=0 to NameMappings.Count-1 do
  3491. begin
  3492. mappedname:=pshortstring(NameMappings[i]);
  3493. stringdispose(mappedname);
  3494. end;
  3495. NameMappings.free;
  3496. NameMappings:=nil;
  3497. end;
  3498. if assigned(procdefs) then
  3499. begin
  3500. procdefs.free;
  3501. procdefs:=nil;
  3502. end;
  3503. inherited destroy;
  3504. end;
  3505. procedure TImplementedInterface.buildderef;
  3506. begin
  3507. intfdefderef.build(intfdef);
  3508. end;
  3509. procedure TImplementedInterface.deref;
  3510. begin
  3511. intfdef:=tobjectdef(intfdefderef.resolve);
  3512. end;
  3513. procedure TImplementedInterface.AddMapping(const origname,newname: string);
  3514. begin
  3515. if not assigned(NameMappings) then
  3516. NameMappings:=TFPHashList.Create;
  3517. NameMappings.Add(origname,stringdup(newname));
  3518. end;
  3519. function TImplementedInterface.GetMapping(const origname: string):string;
  3520. var
  3521. mappedname : pshortstring;
  3522. begin
  3523. result:='';
  3524. if not assigned(NameMappings) then
  3525. exit;
  3526. mappedname:=PShortstring(NameMappings.Find(origname));
  3527. if assigned(mappedname) then
  3528. result:=mappedname^;
  3529. end;
  3530. procedure TImplementedInterface.AddImplProc(pd:tprocdef);
  3531. var
  3532. i : longint;
  3533. found : boolean;
  3534. begin
  3535. if not assigned(procdefs) then
  3536. procdefs:=TFPObjectList.Create(false);
  3537. { No duplicate entries of the same procdef }
  3538. found:=false;
  3539. for i:=0 to procdefs.count-1 do
  3540. if tprocdef(procdefs[i])=pd then
  3541. begin
  3542. found:=true;
  3543. break;
  3544. end;
  3545. if not found then
  3546. procdefs.Add(pd);
  3547. end;
  3548. function TImplementedInterface.IsImplMergePossible(MergingIntf:TImplementedInterface;out weight: longint): boolean;
  3549. var
  3550. i : longint;
  3551. begin
  3552. result:=false;
  3553. weight:=0;
  3554. { empty interface is mergeable }
  3555. if ProcDefs.Count=0 then
  3556. begin
  3557. result:=true;
  3558. exit;
  3559. end;
  3560. { The interface to merge must at least the number of
  3561. procedures of this interface }
  3562. if MergingIntf.ProcDefs.Count<ProcDefs.Count then
  3563. exit;
  3564. for i:=0 to ProcDefs.Count-1 do
  3565. begin
  3566. if MergingIntf.ProcDefs[i]<>ProcDefs[i] then
  3567. exit;
  3568. end;
  3569. weight:=ProcDefs.Count;
  3570. result:=true;
  3571. end;
  3572. function TImplementedInterface.getcopy:TImplementedInterface;
  3573. begin
  3574. Result:=TImplementedInterface.Create(nil);
  3575. Move(pointer(self)^,pointer(result)^,InstanceSize);
  3576. end;
  3577. {****************************************************************************
  3578. TFORWARDDEF
  3579. ****************************************************************************}
  3580. constructor tforwarddef.create(const s:string;const pos : tfileposinfo);
  3581. begin
  3582. inherited create(forwarddef);
  3583. tosymname:=stringdup(s);
  3584. forwardpos:=pos;
  3585. end;
  3586. function tforwarddef.GetTypeName:string;
  3587. begin
  3588. GetTypeName:='unresolved forward to '+tosymname^;
  3589. end;
  3590. destructor tforwarddef.destroy;
  3591. begin
  3592. stringdispose(tosymname);
  3593. inherited destroy;
  3594. end;
  3595. {****************************************************************************
  3596. TUNDEFINEDDEF
  3597. ****************************************************************************}
  3598. constructor tundefineddef.create;
  3599. begin
  3600. inherited create(undefineddef);
  3601. end;
  3602. constructor tundefineddef.ppuload(ppufile:tcompilerppufile);
  3603. begin
  3604. inherited ppuload(undefineddef,ppufile);
  3605. end;
  3606. function tundefineddef.GetTypeName:string;
  3607. begin
  3608. GetTypeName:='<undefined type>';
  3609. end;
  3610. procedure tundefineddef.ppuwrite(ppufile:tcompilerppufile);
  3611. begin
  3612. inherited ppuwrite(ppufile);
  3613. ppufile.writeentry(ibundefineddef);
  3614. end;
  3615. {****************************************************************************
  3616. TERRORDEF
  3617. ****************************************************************************}
  3618. constructor terrordef.create;
  3619. begin
  3620. inherited create(errordef);
  3621. end;
  3622. procedure terrordef.ppuwrite(ppufile:tcompilerppufile);
  3623. begin
  3624. { Can't write errordefs to ppu }
  3625. internalerror(200411063);
  3626. end;
  3627. function terrordef.GetTypeName:string;
  3628. begin
  3629. GetTypeName:='<erroneous type>';
  3630. end;
  3631. function terrordef.getmangledparaname:string;
  3632. begin
  3633. getmangledparaname:='error';
  3634. end;
  3635. {****************************************************************************
  3636. Definition Helpers
  3637. ****************************************************************************}
  3638. function is_interfacecom(def: tdef): boolean;
  3639. begin
  3640. is_interfacecom:=
  3641. assigned(def) and
  3642. (def.typ=objectdef) and
  3643. (tobjectdef(def).objecttype=odt_interfacecom);
  3644. end;
  3645. function is_interfacecorba(def: tdef): boolean;
  3646. begin
  3647. is_interfacecorba:=
  3648. assigned(def) and
  3649. (def.typ=objectdef) and
  3650. (tobjectdef(def).objecttype=odt_interfacecorba);
  3651. end;
  3652. function is_interface(def: tdef): boolean;
  3653. begin
  3654. is_interface:=
  3655. assigned(def) and
  3656. (def.typ=objectdef) and
  3657. (tobjectdef(def).objecttype in [odt_interfacecom,odt_interfacecorba]);
  3658. end;
  3659. function is_dispinterface(def: tdef): boolean;
  3660. begin
  3661. result:=
  3662. assigned(def) and
  3663. (def.typ=objectdef) and
  3664. (tobjectdef(def).objecttype=odt_dispinterface);
  3665. end;
  3666. function is_class(def: tdef): boolean;
  3667. begin
  3668. is_class:=
  3669. assigned(def) and
  3670. (def.typ=objectdef) and
  3671. (tobjectdef(def).objecttype=odt_class);
  3672. end;
  3673. function is_object(def: tdef): boolean;
  3674. begin
  3675. is_object:=
  3676. assigned(def) and
  3677. (def.typ=objectdef) and
  3678. (tobjectdef(def).objecttype=odt_object);
  3679. end;
  3680. function is_cppclass(def: tdef): boolean;
  3681. begin
  3682. is_cppclass:=
  3683. assigned(def) and
  3684. (def.typ=objectdef) and
  3685. (tobjectdef(def).objecttype=odt_cppclass);
  3686. end;
  3687. function is_class_or_interface(def: tdef): boolean;
  3688. begin
  3689. is_class_or_interface:=
  3690. assigned(def) and
  3691. (def.typ=objectdef) and
  3692. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba]);
  3693. end;
  3694. function is_class_or_interface_or_dispinterface(def: tdef): boolean;
  3695. begin
  3696. result:=
  3697. assigned(def) and
  3698. (def.typ=objectdef) and
  3699. (tobjectdef(def).objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface]);
  3700. end;
  3701. {$ifdef x86}
  3702. function use_sse(def : tdef) : boolean;
  3703. begin
  3704. use_sse:=(is_single(def) and (current_settings.fputype in sse_singlescalar)) or
  3705. (is_double(def) and (current_settings.fputype in sse_doublescalar));
  3706. end;
  3707. {$endif x86}
  3708. end.