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