2
0

symdef.pas 127 KB

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