symdef.pas 128 KB

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