defs.pas 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 by Daniel Mantione
  4. and other members of the Free Pascal development team
  5. This unit handles definitions
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. {$ifdef TP}
  20. {$N+,E+,F+}
  21. {$endif}
  22. unit defs;
  23. interface
  24. uses symtable,objects,{$IFDEF TP}xobjects,{$ENDIF}
  25. cobjects,symtablt,globtype
  26. {$ifdef i386}
  27. ,cpubase
  28. {$endif}
  29. {$ifdef m68k}
  30. ,m68k
  31. {$endif}
  32. {$ifdef alpha}
  33. ,alpha
  34. {$endif};
  35. type Targconvtyp=(act_convertable,act_equal,act_exact);
  36. Tvarspez=(vs_value,vs_const,vs_var);
  37. Tobjprop=(sp_public,sp_private,sp_protected,sp_published,sp_static);
  38. Tobjpropset=set of Tobjprop;
  39. Tobjoption=(oo_has_abstract, {The object/class has
  40. an abstract method => no
  41. instances can be created.}
  42. oo_is_class, {The object is a class.}
  43. oo_has_virtual, {The object/class has
  44. virtual methods.}
  45. oo_has_private, {The object has private members.}
  46. oo_has_protected, {The obejct has protected
  47. members.}
  48. oo_isforward, {The class is only a forward
  49. declared yet.}
  50. oo_can_have_published, {True, if the class has rtti, i.e.
  51. you can publish properties.}
  52. oo_has_constructor, {The object/class has a
  53. constructor.}
  54. oo_has_destructor, {The object/class has a
  55. destructor.}
  56. oo_has_vmt, {The object/class has a vmt.}
  57. oo_has_msgstr,
  58. oo_has_msgint,
  59. oo_cppvmt); {The object/class uses an C++
  60. compatible vmt, all members of
  61. the same class tree, must use
  62. then a C++ compatible vmt.}
  63. Tobjoptionset=set of Tobjoption;
  64. {Calling convention for tprocdef and Tprocvardef.}
  65. Tproccalloption=(pocall_none,
  66. pocall_clearstack, {Use IBM flat calling
  67. convention. (Used by GCC.)}
  68. pocall_leftright, {Push parameters from left to
  69. right.}
  70. pocall_cdecl, {Procedure uses C styled
  71. calling.}
  72. pocall_register, {Procedure uses register
  73. (fastcall) calling.}
  74. pocall_stdcall, {Procedure uses stdcall
  75. call.}
  76. pocall_safecall, {Safe call calling
  77. conventions.}
  78. pocall_palmossyscall, {Procedure is a PalmOS
  79. system call.}
  80. pocall_system,
  81. pocall_inline, {Procedure is an assembler
  82. macro.}
  83. pocall_internproc, {Procedure has compiler
  84. magic.}
  85. pocall_internconst); {Procedure has constant
  86. evaluator intern.}
  87. Tproccalloptionset=set of Tproccalloption;
  88. {Basic type for tprocdef and tprocvardef }
  89. Tproctypeoption=(potype_none,
  90. potype_proginit, {Program initialization.}
  91. potype_unitinit, {Unit initialization.}
  92. potype_unitfinalize, {Unit finalization.}
  93. potype_constructor, {Procedure is a constructor.}
  94. potype_destructor, {Procedure is a destructor.}
  95. potype_operator); {Procedure defines an
  96. operator.}
  97. {Other options for Tprocdef and Tprocvardef.}
  98. Tprocoption=(po_none,
  99. poclassmethod, {Class method.}
  100. povirtualmethod, {Procedure is a virtual method.}
  101. poabstractmethod, {Procedure is an abstract method.}
  102. postaticmethod, {Static method.}
  103. pooverridingmethod, {Method with override directive.}
  104. pomethodpointer, {Method pointer, only in procvardef, also used for 'with object do'.}
  105. pocontainsself, {Self is passed explicit to the compiler.}
  106. pointerrupt, {Procedure is an interrupt handler.}
  107. poiocheck, {IO checking should be done after a call to the procedure.}
  108. poassembler, {Procedure is written in assembler.}
  109. pomsgstr, {Method for string message handling.}
  110. pomsgint, {Method for int message handling.}
  111. poexports, {Procedure has export directive (needed for OS/2).}
  112. poexternal, {Procedure is external (in other object or lib).}
  113. posavestdregs, {Save std regs cdecl and stdcall need that !}
  114. posaveregisters); {Save all registers }
  115. Tprocoptionset=set of Tprocoption;
  116. Tarrayoption=(ap_variant,ap_constructor,ap_arrayofconst);
  117. Tarrayoptionset=set of Tarrayoption;
  118. Pparameter=^Tparameter;
  119. Tparameter=object(Tobject)
  120. data:Psym;
  121. paratyp:Tvarspez;
  122. argconvtyp:Targconvtyp;
  123. convertlevel:byte;
  124. register:Tregister;
  125. end;
  126. Tfiletype=(ft_text,ft_typed,ft_untyped);
  127. Pfiledef=^Tfiledef;
  128. Tfiledef=object(Tdef)
  129. filetype:Tfiletype;
  130. definition:Pdef;
  131. constructor init(Aowner:Pcontainingsymtable;
  132. ft:Tfiletype;tas:Pdef);
  133. constructor load(var s:Tstream);
  134. procedure deref;virtual;
  135. function gettypename:string;virtual;
  136. procedure setsize;
  137. {$ifdef GDB}
  138. function stabstring:Pchar;virtual;
  139. procedure concatstabto(asmlist:Paasmoutput);virtual;
  140. {$endif GDB}
  141. procedure store(var s:Tstream);virtual;
  142. end;
  143. Pformaldef=^Tformaldef;
  144. Tformaldef=object(Tdef)
  145. constructor init(Aowner:Pcontainingsymtable);
  146. constructor load(var s:Tstream);
  147. procedure store(var s:Tstream);virtual;
  148. {$ifdef GDB}
  149. function stabstring:Pchar;virtual;
  150. procedure concatstabto(asmlist:Paasmoutput);virtual;
  151. {$endif GDB}
  152. function gettypename:string;virtual;
  153. end;
  154. Perrordef=^Terrordef;
  155. Terrordef=object(Tdef)
  156. {$IFDEF TP}
  157. constructor init(Aowner:Pcontainingsymtable);
  158. {$ENDIF}
  159. {$ifdef GDB}
  160. function stabstring:Pchar;virtual;
  161. {$endif GDB}
  162. function gettypename:string;virtual;
  163. end;
  164. Pabstractpointerdef=^Tabstractpointerdef;
  165. Tabstractpointerdef=object(Tdef)
  166. definition:Pdef;
  167. defsym:Psym;
  168. constructor init(Aowner:Pcontainingsymtable;def:Pdef);
  169. constructor load(var s:Tstream);
  170. procedure deref;virtual;
  171. procedure store(var s:Tstream);virtual;
  172. {$ifdef GDB}
  173. function stabstring:Pchar;virtual;
  174. procedure concatstabto(asmlist:Paasmoutput);virtual;
  175. {$endif GDB}
  176. end;
  177. Ppointerdef=^Tpointerdef;
  178. Tpointerdef=object(Tabstractpointerdef)
  179. is_far:boolean;
  180. constructor initfar(Aowner:Pcontainingsymtable;def:Pdef);
  181. constructor load(var s:Tstream);
  182. procedure store(var s:Tstream);virtual;
  183. function gettypename:string;virtual;
  184. end;
  185. Pclassrefdef=^Tclassrefdef;
  186. Tclassrefdef=object(Tpointerdef)
  187. {$IFDEF TP}
  188. constructor init(Aowner:Pcontainingsymtable;def:Pdef);
  189. {$ENDIF TP}
  190. {$ifdef GDB}
  191. function stabstring : pchar;virtual;
  192. procedure concatstabto(asmlist : paasmoutput);virtual;
  193. {$endif GDB}
  194. function gettypename:string;virtual;
  195. end;
  196. Pobjectdef=^Tobjectdef;
  197. Tobjectdef=object(Tdef)
  198. childof:Pobjectdef;
  199. objname:Pstring;
  200. privatesyms,
  201. protectedsyms,
  202. publicsyms:Pobjectsymtable;
  203. options:Tobjoptionset;
  204. {To be able to have a variable vmt position
  205. and no vmt field for objects without virtuals }
  206. vmt_offset:longint;
  207. constructor init(const n:string;Aowner:Pcontainingsymtable;
  208. parent:Pobjectdef;isclass:boolean);
  209. constructor load(var s:Tstream);
  210. procedure check_forwards;
  211. procedure insertvmt;
  212. function is_related(d:Pobjectdef):boolean;
  213. function search(const s:string):Psym;
  214. function speedsearch(const s:string;
  215. speedvalue:longint):Psym;virtual;
  216. function size:longint;virtual;
  217. procedure store(var s:Tstream);virtual;
  218. function vmt_mangledname : string;
  219. function rtti_name : string;
  220. procedure set_parent(parent:Pobjectdef);
  221. {$ifdef GDB}
  222. function stabstring : pchar;virtual;
  223. {$endif GDB}
  224. procedure deref;virtual;
  225. function needs_inittable:boolean;virtual;
  226. procedure write_init_data;virtual;
  227. procedure write_child_init_data;virtual;
  228. {Rtti }
  229. function get_rtti_label:string;virtual;
  230. procedure generate_rtti;virtual;
  231. procedure write_rtti_data;virtual;
  232. procedure write_child_rtti_data;virtual;
  233. function next_free_name_index:longint;
  234. function is_publishable:boolean;virtual;
  235. destructor done;virtual;
  236. end;
  237. Parraydef=^Tarraydef;
  238. Tarraydef=object(Tdef)
  239. lowrange,
  240. highrange:Tconstant;
  241. definition:Pdef;
  242. rangedef:Pdef;
  243. options:Tarrayoptionset;
  244. constructor init(const l,h:Tconstant;rd:Pdef;
  245. Aowner:Pcontainingsymtable);
  246. constructor load(var s:Tstream);
  247. function elesize:longint;
  248. function gettypename:string;virtual;
  249. procedure store(var s:Tstream);virtual;
  250. {$ifdef GDB}
  251. function stabstring : pchar;virtual;
  252. procedure concatstabto(asmlist : paasmoutput);virtual;
  253. {$endif GDB}
  254. procedure deref;virtual;
  255. function size : longint;virtual;
  256. { generates the ranges needed by the asm instruction BOUND (i386)
  257. or CMP2 (Motorola) }
  258. procedure genrangecheck;
  259. { returns the label of the range check string }
  260. function getrangecheckstring : string;
  261. function needs_inittable : boolean;virtual;
  262. procedure write_rtti_data;virtual;
  263. procedure write_child_rtti_data;virtual;
  264. private
  265. rangenr:longint;
  266. end;
  267. Penumdef=^Tenumdef;
  268. Tenumdef=object(Tdef)
  269. rangenr,
  270. minval,
  271. maxval:longint;
  272. has_jumps:boolean;
  273. symbols:Pcollection;
  274. basedef:Penumdef;
  275. constructor init(Aowner:Pcontainingsymtable);
  276. constructor init_subrange(Abasedef:Penumdef;Amin,Amax:longint;
  277. Aowner:Pcontainingsymtable);
  278. constructor load(var s:Tstream);
  279. procedure deref;virtual;
  280. procedure calcsavesize;
  281. function getrangecheckstring:string;
  282. procedure genrangecheck;
  283. procedure setmax(Amax:longint);
  284. procedure setmin(Amin:longint);
  285. procedure store(var s:Tstream);virtual;
  286. {$ifdef GDB}
  287. function stabstring:Pchar;virtual;
  288. {$endif GDB}
  289. procedure write_child_rtti_data;virtual;
  290. procedure write_rtti_data;virtual;
  291. function is_publishable : boolean;virtual;
  292. function gettypename:string;virtual;
  293. end;
  294. Tbasetype=(uauto,uvoid,uchar,
  295. u8bit,u16bit,u32bit,
  296. s8bit,s16bit,s32bit,
  297. bool8bit,bool16bit,bool32bit,
  298. s64bit,u64bit,s64bitint,uwidechar);
  299. Porddef=^Torddef;
  300. Torddef=object(Tdef)
  301. low,high:Tconstant;
  302. rangenr:longint;
  303. typ:Tbasetype;
  304. constructor init(t:tbasetype;l,h:Tconstant;
  305. Aowner:Pcontainingsymtable);
  306. constructor load(var s:Tstream);
  307. procedure store(var s:Tstream);virtual;
  308. procedure setsize;
  309. { generates the ranges needed by the asm instruction BOUND }
  310. { or CMP2 (Motorola) }
  311. procedure genrangecheck;
  312. { returns the label of the range check string }
  313. function getrangecheckstring : string;
  314. procedure write_rtti_data;virtual;
  315. function is_publishable:boolean;virtual;
  316. function gettypename:string;virtual;
  317. {$ifdef GDB}
  318. function stabstring:Pchar;virtual;
  319. {$endif GDB}
  320. end;
  321. {S80real is dependant on the cpu, s64comp is also
  322. dependant on the size (tp = 80bit for both)
  323. The EXTENDED format exists on the motorola FPU
  324. but it uses 96 bits instead of 80, with some
  325. unused bits within the number itself! Pretty
  326. complicated to support, so no support for the
  327. moment.
  328. S64comp is considered as a real because all
  329. calculations are done by the fpu.}
  330. Tfloattype=(s32real,s64real,s80real,s64comp,f16bit,f32bit);
  331. Pfloatdef=^Tfloatdef;
  332. Tfloatdef=object(tdef)
  333. typ:Tfloattype;
  334. constructor init(t:Tfloattype;Aowner:Pcontainingsymtable);
  335. constructor load(var s:Tstream);
  336. function is_publishable : boolean;virtual;
  337. procedure setsize;
  338. {$ifdef GDB}
  339. function stabstring:Pchar;virtual;
  340. {$endif GDB}
  341. procedure store(var s:Tstream);virtual;
  342. procedure write_rtti_data;virtual;
  343. function gettypename:string;virtual;
  344. end;
  345. Tsettype=(normset,smallset,varset);
  346. Psetdef=^Tsetdef;
  347. Tsetdef=object(Tdef)
  348. definition:Pdef;
  349. settype:Tsettype;
  350. constructor init(s:Pdef;high:longint;Aowner:Pcontainingsymtable);
  351. constructor load(var s:Tstream);
  352. procedure store(var s:Tstream);virtual;
  353. {$ifdef GDB}
  354. function stabstring : pchar;virtual;
  355. procedure concatstabto(asmlist : paasmoutput);virtual;
  356. {$endif GDB}
  357. procedure deref;virtual;
  358. function is_publishable : boolean;virtual;
  359. procedure write_rtti_data;virtual;
  360. procedure write_child_rtti_data;virtual;
  361. function gettypename:string;virtual;
  362. end;
  363. Precorddef=^Trecorddef;
  364. Trecorddef=object(Tdef)
  365. symtable:Precordsymtable;
  366. constructor init(s:Precordsymtable;Aowner:Pcontainingsymtable);
  367. constructor load(var s:Tstream);
  368. procedure store(var s:Tstream);virtual;
  369. {$ifdef GDB}
  370. function stabstring : pchar;virtual;
  371. procedure concatstabto(asmlist : paasmoutput);virtual;
  372. {$endif GDB}
  373. procedure deref;virtual;
  374. function needs_inittable : boolean;virtual;
  375. procedure write_rtti_data;virtual;
  376. procedure write_init_data;virtual;
  377. procedure write_child_rtti_data;virtual;
  378. procedure write_child_init_data;virtual;
  379. function gettypename:string;virtual;
  380. destructor done;virtual;
  381. end;
  382. {String types}
  383. Tstringtype=(st_default,st_shortstring,st_longstring,
  384. st_ansistring,st_widestring);
  385. {This object needs to be splitted into multiple objects,
  386. one for each stringtype. This is because all code in this
  387. object is different for all string types.}
  388. Pstringdef=^Tstringdef;
  389. Tstringdef=object(Tdef)
  390. string_typ:Tstringtype;
  391. len:longint;
  392. constructor shortinit(l:byte;Aowner:Pcontainingsymtable);
  393. constructor shortload(var s:Tstream);
  394. constructor longinit(l:longint;Aowner:Pcontainingsymtable);
  395. constructor longload(var s:Tstream);
  396. constructor ansiinit(l:longint;Aowner:Pcontainingsymtable);
  397. constructor ansiload(var s:Tstream);
  398. constructor wideinit(l:longint;Aowner:Pcontainingsymtable);
  399. constructor wideload(var s:Tstream);
  400. function stringtypname:string;
  401. function size:longint;virtual;
  402. procedure store(var s:Tstream);virtual;
  403. function gettypename:string;virtual;
  404. function is_publishable : boolean;virtual;
  405. { debug }
  406. {$ifdef GDB}
  407. function stabstring:Pchar;virtual;
  408. procedure concatstabto(asmlist : Paasmoutput);virtual;
  409. {$endif GDB}
  410. { init/final }
  411. function needs_inittable : boolean;virtual;
  412. { rtti }
  413. procedure write_rtti_data;virtual;
  414. end;
  415. Pabstractprocdef=^Pabstractprocdef;
  416. Tabstractprocdef=object(Tdef)
  417. {Saves a definition to the return type }
  418. retdef:Pdef;
  419. fpu_used:byte; {How many stack fpu must be empty.}
  420. proctype:Tproctypeoption;
  421. options:Tprocoptionset; {Save the procedure options.}
  422. calloptions:Tproccalloptionset;
  423. parameters:Pcollection;
  424. constructor init(Aowner:Pcontainingsymtable);
  425. constructor load(var s:Tstream);
  426. destructor done;virtual;
  427. procedure deref;virtual;
  428. function demangled_paras:string;
  429. function para_size:longint;
  430. procedure store(var s:Tstream);virtual;
  431. procedure test_if_fpu_result;
  432. {$ifdef GDB}
  433. function stabstring : pchar;virtual;
  434. procedure concatstabto(asmlist : paasmoutput);virtual;
  435. {$endif GDB}
  436. end;
  437. Pprocvardef=^Tprocvardef;
  438. Tprocvardef=object(Tabstractprocdef)
  439. {$IFDEF TP}
  440. constructor init(Aowner:Pcontainingsymtable);
  441. {$ENDIF TP}
  442. function size:longint;virtual;
  443. {$ifdef GDB}
  444. function stabstring:Pchar;virtual;
  445. procedure concatstabto(asmlist:Paasmoutput); virtual;
  446. {$endif GDB}
  447. procedure write_child_rtti_data;virtual;
  448. function is_publishable:boolean;virtual;
  449. procedure write_rtti_data;virtual;
  450. function gettypename:string;virtual;
  451. end;
  452. {This datastructure is used to store the message information
  453. when a procedure is declared as:
  454. ;message 'str';
  455. ;message int;
  456. ;virtual int;
  457. }
  458. Tmessageinf=record
  459. case integer of
  460. 0:(str:Pchar);
  461. 1:(i:longint);
  462. end;
  463. {This object can be splitted into a Tprocdef, for normal procedures,
  464. a Tmethoddef for methods, and a Tinlinedprocdef and a
  465. Tinlinedmethoddef for inlined procedures.}
  466. Pprocdef = ^Tprocdef;
  467. Tprocdef = object(tabstractprocdef)
  468. objprop:Tobjpropset;
  469. extnumber:longint;
  470. messageinf:Tmessageinf;
  471. { where is this function defined, needed here because there
  472. is only one symbol for all overloaded functions }
  473. fileinfo:Tfileposinfo;
  474. { pointer to the local symbol table }
  475. localst:Pprocsymtable;
  476. _mangledname:Pstring;
  477. { it's a tree, but this not easy to handle }
  478. { used for inlined procs }
  479. code : pointer;
  480. { true, if the procedure is only declared }
  481. { (forward procedure) }
  482. references:Pcollection;
  483. forwarddef,
  484. { true if the procedure is declared in the interface }
  485. interfacedef : boolean;
  486. { check the problems of manglednames }
  487. count : boolean;
  488. is_used : boolean;
  489. { set which contains the modified registers }
  490. usedregisters:Tregisterset;
  491. constructor init(Aowner:Pcontainingsymtable);
  492. constructor load(var s:Tstream);
  493. procedure store(var s:Tstream);virtual;
  494. {$ifdef GDB}
  495. function cplusplusmangledname : string;
  496. function stabstring : pchar;virtual;
  497. procedure concatstabto(asmlist : paasmoutput);virtual;
  498. {$endif GDB}
  499. procedure deref;virtual;
  500. function mangledname:string;
  501. procedure setmangledname(const s:string);
  502. procedure load_references;
  503. function write_references:boolean;
  504. destructor done;virtual;
  505. end;
  506. Pforwarddef=^Tforwarddef;
  507. Tforwarddef=object(Tdef)
  508. tosymname:string;
  509. forwardpos:Tfileposinfo;
  510. constructor init(Aowner:Pcontainingsymtable;
  511. const s:string;const pos:Tfileposinfo);
  512. function gettypename:string;virtual;
  513. end;
  514. {Relevant options for assigning a proc or a procvar to a procvar.}
  515. const po_compatibility_options=[
  516. poclassmethod,
  517. postaticmethod,
  518. pomethodpointer,
  519. pocontainsself,
  520. pointerrupt,
  521. poiocheck,
  522. poexports
  523. ];
  524. var cformaldef:Pformaldef; {Unique formal definition.}
  525. voiddef:Porddef; {Pointer to void (procedure) type.}
  526. cchardef:Porddef; {Pointer to char type.}
  527. booldef:Porddef; {Pointer to boolean type.}
  528. u8bitdef:Porddef; {Pointer to 8-bit unsigned type.}
  529. u16bitdef:Porddef; {Pointer to 16-bit unsigned type.}
  530. u32bitdef:Porddef; {Pointer to 32-bit unsigned type.}
  531. s32bitdef:Porddef; {Pointer to 32-bit signed type.}
  532. cu64bitdef:Porddef; {Pointer to 64 bit unsigned def.}
  533. cs64bitdef:Porddef; {Pointer to 64 bit signed def.}
  534. voidpointerdef, {Pointer for Void-Pointerdef.}
  535. charpointerdef, {Pointer for Char-Pointerdef.}
  536. voidfarpointerdef:ppointerdef;
  537. s32floatdef : pfloatdef; {Pointer for realconstn.}
  538. s64floatdef : pfloatdef; {Pointer for realconstn.}
  539. s80floatdef : pfloatdef; {Pointer to type of temp. floats.}
  540. s32fixeddef : pfloatdef; {Pointer to type of temp. fixed.}
  541. cshortstringdef, {Pointer to type of short string const.}
  542. openshortstringdef, {Pointer to type of an openshortstring,
  543. needed for readln().}
  544. clongstringdef, {Pointer to type of long string const.}
  545. cansistringdef, {Pointer to type of ansi string const.}
  546. cwidestringdef:Pstringdef; {Pointer to type of wide string const.}
  547. openchararraydef:Parraydef; {Pointer to type of an open array of
  548. char, needed for readln().}
  549. cfiledef:Pfiledef; {Get the same definition for all files
  550. used for stabs.}
  551. implementation
  552. uses systems,symbols,verbose,globals,aasm,files,strings;
  553. const {If you change one of the following contants,
  554. you have also to change the typinfo unit
  555. and the rtl/i386,template/rttip.inc files.}
  556. tkunknown = 0;
  557. tkinteger = 1;
  558. tkchar = 2;
  559. tkenumeration = 3;
  560. tkfloat = 4;
  561. tkset = 5;
  562. tkmethod = 6;
  563. tksstring = 7;
  564. tkstring = tksstring;
  565. tklstring = 8;
  566. tkastring = 9;
  567. tkwstring = 10;
  568. tkvariant = 11;
  569. tkarray = 12;
  570. tkrecord = 13;
  571. tkinterface = 14;
  572. tkclass = 15;
  573. tkobject = 16;
  574. tkwchar = 17;
  575. tkbool = 18;
  576. otsbyte = 0;
  577. otubyte = 1;
  578. otsword = 2;
  579. otuword = 3;
  580. otslong = 4;
  581. otulong = 5;
  582. ftsingle = 0;
  583. ftdouble = 1;
  584. ftextended = 2;
  585. ftcomp = 3;
  586. ftcurr = 4;
  587. ftfixed16 = 5;
  588. ftfixed32 = 6;
  589. {****************************************************************************
  590. Tfiledef
  591. ****************************************************************************}
  592. constructor Tfiledef.init(Aowner:Pcontainingsymtable;ft:Tfiletype;tas:Pdef);
  593. begin
  594. inherited init(Aowner);
  595. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  596. filetype:=ft;
  597. definition:=tas;
  598. setsize;
  599. end;
  600. constructor Tfiledef.load(var s:Tstream);
  601. begin
  602. inherited load(s);
  603. { filetype:=tfiletype(readbyte);
  604. if filetype=ft_typed then
  605. typed_as:=readdefref
  606. else
  607. typed_as:=nil;}
  608. setsize;
  609. end;
  610. procedure Tfiledef.deref;
  611. begin
  612. { if filetype=ft_typed then
  613. resolvedef(typed_as);}
  614. end;
  615. procedure Tfiledef.setsize;
  616. begin
  617. case filetype of
  618. ft_text:
  619. savesize:=572;
  620. ft_typed,ft_untyped:
  621. savesize:=316;
  622. end;
  623. end;
  624. procedure Tfiledef.store(var s:Tstream);
  625. begin
  626. { inherited store(s);
  627. writebyte(byte(filetype));
  628. if filetype=ft_typed then
  629. writedefref(typed_as);
  630. current_ppu^.writeentry(ibfiledef);}
  631. end;
  632. function Tfiledef.gettypename : string;
  633. begin
  634. case filetype of
  635. ft_untyped:
  636. gettypename:='File';
  637. ft_typed:
  638. gettypename:='File Of '+definition^.typename;
  639. ft_text:
  640. gettypename:='Text'
  641. end;
  642. end;
  643. {****************************************************************************
  644. Tformaldef
  645. ****************************************************************************}
  646. {Tformaldef is used for var parameters without a type.}
  647. constructor Tformaldef.init(Aowner:Pcontainingsymtable);
  648. begin
  649. inherited init(Aowner);
  650. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  651. savesize:=target_os.size_of_pointer;
  652. end;
  653. constructor Tformaldef.load(var s:Tstream);
  654. begin
  655. inherited load(s);
  656. savesize:=target_os.size_of_pointer;
  657. end;
  658. procedure Tformaldef.store(var s:Tstream);
  659. begin
  660. inherited store(s);
  661. { current_ppu^.writeentry(ibformaldef);}
  662. end;
  663. function Tformaldef.gettypename:string;
  664. begin
  665. gettypename:='Var';
  666. end;
  667. {****************************************************************************
  668. Terrordef
  669. ****************************************************************************}
  670. {$IFDEF TP}
  671. constructor Terrordef.init(Aowner:Pcontainingsymtable);
  672. begin
  673. inherited init(Aowner);
  674. setparent(typeof(Tdef));
  675. end;
  676. {$ENDIF TP}
  677. function Terrordef.gettypename:string;
  678. begin
  679. gettypename:='<erroneous type>';
  680. end;
  681. {****************************************************************************
  682. Tabstractpointerdef
  683. ****************************************************************************}
  684. constructor Tabstractpointerdef.init(Aowner:Pcontainingsymtable;def:Pdef);
  685. begin
  686. inherited init(Aowner);
  687. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  688. include(properties,dp_ret_in_acc);
  689. definition:=def;
  690. savesize:=target_os.size_of_pointer;
  691. end;
  692. constructor Tabstractpointerdef.load(var s:Tstream);
  693. begin
  694. inherited load(s);
  695. (* {The real address in memory is calculated later (deref).}
  696. definition:=readdefref; *)
  697. savesize:=target_os.size_of_pointer;
  698. end;
  699. procedure Tabstractpointerdef.deref;
  700. begin
  701. { resolvedef(definition);}
  702. end;
  703. procedure Tabstractpointerdef.store(var s:Tstream);
  704. begin
  705. inherited store(s);
  706. { writedefref(definition);
  707. current_ppu^.writeentry(ibpointerdef);}
  708. end;
  709. {****************************************************************************
  710. Tpointerdef
  711. ****************************************************************************}
  712. constructor Tpointerdef.initfar(Aowner:Pcontainingsymtable;def:Pdef);
  713. begin
  714. inherited init(Aowner,def);
  715. {$IFDEF TP}setparent(typeof(Tabstractpointerdef));{$ENDIF}
  716. is_far:=true;
  717. end;
  718. constructor Tpointerdef.load(var s:Tstream);
  719. begin
  720. inherited load(s);
  721. { is_far:=(readbyte<>0);}
  722. end;
  723. function Tpointerdef.gettypename : string;
  724. begin
  725. gettypename:='^'+definition^.typename;
  726. end;
  727. procedure Tpointerdef.store(var s:Tstream);
  728. begin
  729. inherited store(s);
  730. { writebyte(byte(is_far));}
  731. end;
  732. {****************************************************************************
  733. Tclassrefdef
  734. ****************************************************************************}
  735. {$IFDEF TP}
  736. constructor Tclassrefdef.init(Aowner:Pcontainingsymtable;def:Pdef);
  737. begin
  738. inherited init(Aowner,def);
  739. setparent(typeof(Tpointerdef));
  740. end;
  741. {$ENDIF TP}
  742. function Tclassrefdef.gettypename:string;
  743. begin
  744. gettypename:='Class of '+definition^.typename;
  745. end;
  746. {***************************************************************************
  747. TOBJECTDEF
  748. ***************************************************************************}
  749. constructor Tobjectdef.init(const n:string;Aowner:Pcontainingsymtable;
  750. parent:Pobjectdef;isclass:boolean);
  751. begin
  752. inherited init(Aowner);
  753. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  754. new(publicsyms,init);
  755. publicsyms^.name:=stringdup(n);
  756. publicsyms^.defowner:=@self;
  757. set_parent(parent);
  758. objname:=stringdup(n);
  759. if isclass then
  760. begin
  761. include(properties,dp_ret_in_acc);
  762. include(options,oo_is_class);
  763. end;
  764. end;
  765. procedure tobjectdef.set_parent(parent:Pobjectdef);
  766. const inherited_options=[oo_has_virtual,oo_has_private,oo_has_protected,
  767. oo_has_constructor,oo_has_destructor];
  768. begin
  769. {Nothing to do if the parent was not forward !}
  770. if childof=nil then
  771. begin
  772. childof:=parent;
  773. {Some options are inherited...}
  774. if parent<>nil then
  775. begin
  776. options:=options+parent^.options*inherited_options;
  777. {Add the data of the anchestor class.}
  778. inc(publicsyms^.datasize,parent^.publicsyms^.datasize);
  779. if parent^.privatesyms<>nil then
  780. begin
  781. if privatesyms=nil then
  782. new(privatesyms,init);
  783. inc(privatesyms^.datasize,
  784. parent^.privatesyms^.datasize);
  785. end;
  786. if parent^.protectedsyms<>nil then
  787. begin
  788. if protectedsyms<>nil then
  789. new(protectedsyms,init);
  790. inc(protectedsyms^.datasize,
  791. parent^.protectedsyms^.datasize);
  792. end;
  793. if oo_has_vmt in (options*parent^.options) then
  794. publicsyms^.datasize:=publicsyms^.datasize-
  795. target_os.size_of_pointer;
  796. {If parent has a vmt field then
  797. the offset is the same for the child PM }
  798. if [oo_has_vmt,oo_is_class]*parent^.options<>[] then
  799. begin
  800. vmt_offset:=parent^.vmt_offset;
  801. include(options,oo_has_vmt);
  802. end;
  803. end;
  804. savesize:=publicsyms^.datasize;
  805. end;
  806. end;
  807. constructor Tobjectdef.load(var s:Tstream);
  808. var oldread_member:boolean;
  809. begin
  810. inherited load(s);
  811. (* savesize:=readlong;
  812. vmt_offset:=readlong;
  813. objname:=stringdup(readstring);
  814. childof:=pobjectdef(readdefref);
  815. options:=readlong;
  816. oldread_member:=read_member;
  817. read_member:=true;
  818. publicsyms:=new(psymtable,loadas(objectsymtable));
  819. read_member:=oldread_member;
  820. publicsyms^.defowner:=@self;
  821. { publicsyms^.datasize:=savesize; }
  822. publicsyms^.name := stringdup(objname^);
  823. { handles the predefined class tobject }
  824. { the last TOBJECT which is loaded gets }
  825. { it ! }
  826. if (objname^='TOBJECT') and
  827. isclass and (childof=nil) then
  828. class_tobject:=@self;
  829. has_rtti:=true;*)
  830. end;
  831. procedure Tobjectdef.insertvmt;
  832. begin
  833. if oo_has_vmt in options then
  834. internalerror($990803)
  835. else
  836. begin
  837. {First round up to aktpakrecords.}
  838. publicsyms^.datasize:=align(publicsyms^.datasize,
  839. packrecordalignment[aktpackrecords]);
  840. vmt_offset:=publicsyms^.datasize;
  841. publicsyms^.datasize:=publicsyms^.datasize+
  842. target_os.size_of_pointer;
  843. include(options,oo_has_vmt);
  844. end;
  845. end;
  846. procedure Tobjectdef.check_forwards;
  847. begin
  848. publicsyms^.check_forwards;
  849. if oo_isforward in options then
  850. begin
  851. { ok, in future, the forward can be resolved }
  852. message1(sym_e_class_forward_not_resolved,objname^);
  853. exclude(options,oo_isforward);
  854. end;
  855. end;
  856. { true, if self inherits from d (or if they are equal) }
  857. function Tobjectdef.is_related(d:Pobjectdef):boolean;
  858. var hp:Pobjectdef;
  859. begin
  860. hp:=@self;
  861. is_related:=false;
  862. while assigned(hp) do
  863. begin
  864. if hp=d then
  865. begin
  866. is_related:=true;
  867. break;
  868. end;
  869. hp:=hp^.childof;
  870. end;
  871. end;
  872. function Tobjectdef.search(const s:string):Psym;
  873. begin
  874. search:=speedsearch(s,getspeedvalue(s));
  875. end;
  876. function Tobjectdef.speedsearch(const s:string;speedvalue:longint):Psym;
  877. var r:Psym;
  878. begin
  879. r:=publicsyms^.speedsearch(s,speedvalue);
  880. {Privatesyms should be set to nil after compilation of the unit.
  881. This way, private syms are not found by objects in other units.}
  882. if (r=nil) and (privatesyms<>nil) then
  883. r:=privatesyms^.speedsearch(s,speedvalue);
  884. if (r=nil) and (protectedsyms<>nil) then
  885. r:=protectedsyms^.speedsearch(s,speedvalue);
  886. end;
  887. function Tobjectdef.size:longint;
  888. begin
  889. if oo_is_class in options then
  890. size:=target_os.size_of_pointer
  891. else
  892. size:=publicsyms^.datasize;
  893. end;
  894. procedure tobjectdef.deref;
  895. var oldrecsyms:Psymtable;
  896. begin
  897. { resolvedef(pdef(childof));
  898. oldrecsyms:=aktrecordsymtable;
  899. aktrecordsymtable:=publicsyms;
  900. publicsyms^.deref;
  901. aktrecordsymtable:=oldrecsyms;}
  902. end;
  903. function Tobjectdef.vmt_mangledname:string;
  904. begin
  905. if oo_has_vmt in options then
  906. message1(parser_object_has_no_vmt,objname^);
  907. vmt_mangledname:='VMT_'+owner^.name^+'$_'+objname^;
  908. end;
  909. function Tobjectdef.rtti_name:string;
  910. begin
  911. rtti_name:='RTTI_'+owner^.name^+'$_'+objname^;
  912. end;
  913. procedure Tobjectdef.store(var s:Tstream);
  914. var oldread_member:boolean;
  915. begin
  916. inherited store(s);
  917. (* writelong(size);
  918. writelong(vmt_offset);
  919. writestring(objname^);
  920. writedefref(childof);
  921. writelong(options);
  922. current_ppu^.writeentry(ibobjectdef);
  923. oldread_member:=read_member;
  924. read_member:=true;
  925. publicsyms^.writeas;
  926. read_member:=oldread_member;*)
  927. end;
  928. procedure tobjectdef.write_child_init_data;
  929. begin
  930. end;
  931. procedure Tobjectdef.write_init_data;
  932. var b:byte;
  933. begin
  934. if oo_is_class in options then
  935. b:=tkclass
  936. else
  937. b:=tkobject;
  938. rttilist^.concat(new(Pai_const,init_8bit(b)));
  939. { generate the name }
  940. rttilist^.concat(new(Pai_const,init_8bit(length(objname^))));
  941. rttilist^.concat(new(Pai_string,init(objname^)));
  942. (* rttilist^.concat(new(Pai_const,init_32bit(size)));
  943. publicsyms^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  944. rttilist^.concat(new(Pai_const,init_32bit(count)));
  945. publicsyms^.foreach({$ifndef TP}@{$endif}write_field_inittable);*)
  946. end;
  947. function Tobjectdef.needs_inittable:boolean;
  948. var oldb:boolean;
  949. begin
  950. { there are recursive calls to needs_inittable possible, }
  951. { so we have to change to old value how else should }
  952. { we do that ? check_rec_rtti can't be a nested }
  953. { procedure of needs_rtti ! }
  954. (* oldb:=binittable;
  955. binittable:=false;
  956. publicsyms^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  957. needs_inittable:=binittable;
  958. binittable:=oldb;*)
  959. end;
  960. destructor Tobjectdef.done;
  961. begin
  962. if publicsyms<>nil then
  963. dispose(publicsyms,done);
  964. if privatesyms<>nil then
  965. dispose(privatesyms,done);
  966. if protectedsyms<>nil then
  967. dispose(protectedsyms,done);
  968. if oo_isforward in options then
  969. message1(sym_e_class_forward_not_resolved,objname^);
  970. stringdispose(objname);
  971. inherited done;
  972. end;
  973. var count:longint;
  974. procedure count_published_properties(sym:Pnamedindexobject);
  975. {$ifndef fpc}far;{$endif}
  976. begin
  977. if (typeof(sym^)=typeof(Tpropertysym)) and
  978. (ppo_published in Ppropertysym(sym)^.properties) then
  979. inc(count);
  980. end;
  981. procedure write_property_info(sym:Pnamedindexobject);{$ifndef fpc}far;{$endif}
  982. var proctypesinfo : byte;
  983. procedure writeproc(sym:Psym;def:Pdef;shiftvalue:byte);
  984. var typvalue:byte;
  985. begin
  986. if not(assigned(sym)) then
  987. begin
  988. rttilist^.concat(new(pai_const,init_32bit(1)));
  989. typvalue:=3;
  990. end
  991. else if typeof(sym^)=typeof(Tvarsym) then
  992. begin
  993. rttilist^.concat(new(pai_const,init_32bit(
  994. Pvarsym(sym)^.address)));
  995. typvalue:=0;
  996. end
  997. else
  998. begin
  999. (* if (pprocdef(def)^.options and povirtualmethod)=0 then
  1000. begin
  1001. rttilist^.concat(new(pai_const_symbol,initname(pprocdef(def)^.mangledname)));
  1002. typvalue:=1;
  1003. end
  1004. else
  1005. begin
  1006. {Virtual method, write vmt offset.}
  1007. rttilist^.concat(new(pai_const,
  1008. init_32bit(Pprocdef(def)^.extnumber*4+12)));
  1009. typvalue:=2;
  1010. end;*)
  1011. end;
  1012. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  1013. end;
  1014. begin
  1015. if (typeof(sym^)=typeof(Tpropertysym)) and
  1016. (ppo_indexed in Ppropertysym(sym)^.properties) then
  1017. proctypesinfo:=$40
  1018. else
  1019. proctypesinfo:=0;
  1020. if (typeof(sym^)=typeof(Tpropertysym)) and
  1021. (ppo_published in Ppropertysym(sym)^.properties) then
  1022. begin
  1023. rttilist^.concat(new(pai_const_symbol,initname(
  1024. Ppropertysym(sym)^.definition^.get_rtti_label)));
  1025. writeproc(Ppropertysym(sym)^.readaccesssym,ppropertysym(sym)^.readaccessdef,0);
  1026. writeproc(Ppropertysym(sym)^.writeaccesssym,ppropertysym(sym)^.writeaccessdef,2);
  1027. { isn't it stored ? }
  1028. if (ppo_stored in Ppropertysym(sym)^.properties) then
  1029. begin
  1030. rttilist^.concat(new(pai_const,init_32bit(1)));
  1031. proctypesinfo:=proctypesinfo or (3 shl 4);
  1032. end
  1033. else
  1034. writeproc(ppropertysym(sym)^.storedsym,ppropertysym(sym)^.storeddef,4);
  1035. rttilist^.concat(new(pai_const,
  1036. init_32bit(ppropertysym(sym)^.index)));
  1037. rttilist^.concat(new(pai_const,
  1038. init_32bit(ppropertysym(sym)^.default)));
  1039. rttilist^.concat(new(pai_const,
  1040. init_16bit(count)));
  1041. inc(count);
  1042. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  1043. rttilist^.concat(new(pai_const,
  1044. init_8bit(length(ppropertysym(sym)^.name))));
  1045. rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
  1046. end;
  1047. end;
  1048. procedure generate_published_child_rtti(sym:Pnamedindexobject);
  1049. {$ifndef fpc}far;{$endif}
  1050. begin
  1051. if (typeof(sym^)=typeof(Tpropertysym)) and
  1052. (ppo_published in Ppropertysym(sym)^.properties) then
  1053. Ppropertysym(sym)^.definition^.get_rtti_label;
  1054. end;
  1055. procedure tobjectdef.write_child_rtti_data;
  1056. begin
  1057. publicsyms^.foreach({$ifndef TP}@{$endif}generate_published_child_rtti);
  1058. end;
  1059. procedure Tobjectdef.generate_rtti;
  1060. begin
  1061. { getdatalabel(rtti_label);
  1062. write_child_rtti_data;
  1063. rttilist^.concat(new(pai_symbol,initname_global(rtti_name)));
  1064. rttilist^.concat(new(pai_label,init(rtti_label)));
  1065. write_rtti_data;}
  1066. end;
  1067. function Tobjectdef.next_free_name_index : longint;
  1068. var i:longint;
  1069. begin
  1070. if (childof<>nil) and (oo_can_have_published in childof^.options) then
  1071. i:=childof^.next_free_name_index
  1072. else
  1073. i:=0;
  1074. count:=0;
  1075. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  1076. next_free_name_index:=i+count;
  1077. end;
  1078. procedure tobjectdef.write_rtti_data;
  1079. begin
  1080. if oo_is_class in options then
  1081. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  1082. else
  1083. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  1084. {Generate the name }
  1085. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  1086. rttilist^.concat(new(pai_string,init(objname^)));
  1087. {Write class type }
  1088. rttilist^.concat(new(pai_const_symbol,initname(vmt_mangledname)));
  1089. { write owner typeinfo }
  1090. if (childof<>nil) and (oo_can_have_published in childof^.options) then
  1091. rttilist^.concat(new(pai_const_symbol,
  1092. initname(childof^.get_rtti_label)))
  1093. else
  1094. rttilist^.concat(new(pai_const,init_32bit(0)));
  1095. {Count total number of properties }
  1096. if (childof<>nil) and (oo_can_have_published in childof^.options) then
  1097. count:=childof^.next_free_name_index
  1098. else
  1099. count:=0;
  1100. {Write it>}
  1101. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  1102. rttilist^.concat(new(Pai_const,init_16bit(count)));
  1103. { write unit name }
  1104. if owner^.name<>nil then
  1105. begin
  1106. rttilist^.concat(new(Pai_const,init_8bit(length(owner^.name^))));
  1107. rttilist^.concat(new(Pai_string,init(owner^.name^)));
  1108. end
  1109. else
  1110. rttilist^.concat(new(Pai_const,init_8bit(0)));
  1111. { write published properties count }
  1112. count:=0;
  1113. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  1114. rttilist^.concat(new(pai_const,init_16bit(count)));
  1115. { count is used to write nameindex }
  1116. { but we need an offset of the owner }
  1117. { to give each property an own slot }
  1118. if (childof<>nil) and (oo_can_have_published in childof^.options) then
  1119. count:=childof^.next_free_name_index
  1120. else
  1121. count:=0;
  1122. publicsyms^.foreach({$ifndef TP}@{$endif}write_property_info);
  1123. end;
  1124. function Tobjectdef.is_publishable:boolean;
  1125. begin
  1126. is_publishable:=oo_is_class in options;
  1127. end;
  1128. function Tobjectdef.get_rtti_label:string;
  1129. begin
  1130. get_rtti_label:=rtti_name;
  1131. end;
  1132. {***************************************************************************
  1133. TARRAYDEF
  1134. ***************************************************************************}
  1135. constructor Tarraydef.init(const l,h:Tconstant;rd:Pdef;
  1136. Aowner:Pcontainingsymtable);
  1137. begin
  1138. inherited init(Aowner);
  1139. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  1140. lowrange:=l;
  1141. highrange:=h;
  1142. rangedef:=rd;
  1143. end;
  1144. constructor Tarraydef.load(var s:Tstream);
  1145. begin
  1146. inherited load(s);
  1147. (* deftype:=arraydef;
  1148. { the addresses are calculated later }
  1149. definition:=readdefref;
  1150. rangedef:=readdefref;
  1151. lowrange:=readlong;
  1152. highrange:=readlong;
  1153. IsArrayOfConst:=boolean(readbyte);*)
  1154. end;
  1155. function Tarraydef.getrangecheckstring:string;
  1156. begin
  1157. if (cs_create_smart in aktmoduleswitches) then
  1158. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1159. else
  1160. getrangecheckstring:='R_'+tostr(rangenr);
  1161. end;
  1162. procedure Tarraydef.genrangecheck;
  1163. begin
  1164. if rangenr=0 then
  1165. begin
  1166. {Generates the data for range checking }
  1167. getlabelnr(rangenr);
  1168. if (cs_create_smart in aktmoduleswitches) then
  1169. datasegment^.concat(new(pai_symbol,
  1170. initname_global(getrangecheckstring,10)))
  1171. else
  1172. datasegment^.concat(new(pai_symbol,
  1173. initname(getrangecheckstring,10)));
  1174. datasegment^.concat(new(Pai_const,
  1175. init_8bit(byte(lowrange.signed))));
  1176. datasegment^.concat(new(Pai_const,
  1177. init_32bit(lowrange.values)));
  1178. datasegment^.concat(new(Pai_const,
  1179. init_8bit(byte(highrange.signed))));
  1180. datasegment^.concat(new(Pai_const,
  1181. init_32bit(highrange.values)));
  1182. end;
  1183. end;
  1184. procedure Tarraydef.deref;
  1185. begin
  1186. { resolvedef(definition);
  1187. resolvedef(rangedef);}
  1188. end;
  1189. procedure Tarraydef.store(var s:Tstream);
  1190. begin
  1191. inherited store(s);
  1192. (* writedefref(definition);
  1193. writedefref(rangedef);
  1194. writelong(lowrange);
  1195. writelong(highrange);
  1196. writebyte(byte(IsArrayOfConst));
  1197. current_ppu^.writeentry(ibarraydef);*)
  1198. end;
  1199. function Tarraydef.elesize:longint;
  1200. begin
  1201. elesize:=definition^.size;
  1202. end;
  1203. function Tarraydef.size:longint;
  1204. begin
  1205. if (lowrange.signed) and (lowrange.values=-1) then
  1206. internalerror($990804);
  1207. if highrange.signed then
  1208. begin
  1209. {Check for overflow.}
  1210. if (highrange.values-lowrange.values=$7fffffff) or
  1211. (($7fffffff div elesize+elesize-1)>
  1212. (highrange.values-lowrange.values)) then
  1213. begin
  1214. { message(sym_segment_too_large);}
  1215. size:=1;
  1216. end
  1217. else
  1218. size:=(highrange.values-lowrange.values+1)*elesize;
  1219. end
  1220. else
  1221. begin
  1222. {Check for overflow.}
  1223. if (highrange.valueu-lowrange.valueu=$7fffffff) or
  1224. (($7fffffff div elesize+elesize-1)>
  1225. (highrange.valueu-lowrange.valueu)) then
  1226. begin
  1227. { message(sym_segment_too_small);}
  1228. size:=1;
  1229. end
  1230. else
  1231. size:=(highrange.valueu-lowrange.valueu+1)*elesize;
  1232. end;
  1233. end;
  1234. function Tarraydef.needs_inittable:boolean;
  1235. begin
  1236. needs_inittable:=definition^.needs_inittable;
  1237. end;
  1238. procedure Tarraydef.write_child_rtti_data;
  1239. begin
  1240. definition^.get_rtti_label;
  1241. end;
  1242. procedure tarraydef.write_rtti_data;
  1243. begin
  1244. rttilist^.concat(new(Pai_const,init_8bit(13)));
  1245. write_rtti_name;
  1246. { size of elements }
  1247. rttilist^.concat(new(Pai_const,init_32bit(definition^.size)));
  1248. { count of elements }
  1249. rttilist^.concat(new(Pai_const,
  1250. init_32bit(highrange.values-lowrange.values+1)));
  1251. { element type }
  1252. rttilist^.concat(new(Pai_const_symbol,
  1253. initname(definition^.get_rtti_label)));
  1254. end;
  1255. function Tarraydef.gettypename:string;
  1256. var r:string;
  1257. begin
  1258. if [ap_arrayofconst,ap_constructor]*options<>[] then
  1259. gettypename:='array of const'
  1260. else if (lowrange.signed) and (lowrange.values=-1) then
  1261. gettypename:='Array Of '+definition^.typename
  1262. else
  1263. begin
  1264. r:='array[$1..$2 Of $3]';
  1265. if typeof(rangedef^)=typeof(Tenumdef) then
  1266. with Penumdef(rangedef)^.symbols^ do
  1267. begin
  1268. replace(r,'$1',Penumsym(at(0))^.name);
  1269. replace(r,'$2',Penumsym(at(count-1))^.name);
  1270. end
  1271. else
  1272. begin
  1273. if lowrange.signed then
  1274. replace(r,'$1',tostr(lowrange.values))
  1275. else
  1276. replace(r,'$1',tostru(lowrange.valueu));
  1277. if highrange.signed then
  1278. replace(r,'$2',tostr(highrange.values))
  1279. else
  1280. replace(r,'$2',tostr(highrange.valueu));
  1281. replace(r,'$3',definition^.typename);
  1282. end;
  1283. gettypename:=r;
  1284. end;
  1285. end;
  1286. {****************************************************************************
  1287. Tenumdef
  1288. ****************************************************************************}
  1289. constructor Tenumdef.init(Aowner:Pcontainingsymtable);
  1290. begin
  1291. inherited init(Aowner);
  1292. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  1293. include(properties,dp_ret_in_acc);
  1294. new(symbols,init(8,8));
  1295. calcsavesize;
  1296. end;
  1297. constructor Tenumdef.init_subrange(Abasedef:Penumdef;Amin,Amax:longint;
  1298. Aowner:Pcontainingsymtable);
  1299. begin
  1300. inherited init(Aowner);
  1301. minval:=Amin;
  1302. maxval:=Amax;
  1303. basedef:=Abasedef;
  1304. symbols:=Abasedef^.symbols;
  1305. calcsavesize;
  1306. end;
  1307. constructor Tenumdef.load(var s:Tstream);
  1308. begin
  1309. inherited load(s);
  1310. (* basedef:=penumdef(readdefref);
  1311. minval:=readlong;
  1312. maxval:=readlong;
  1313. savesize:=readlong;*)
  1314. end;
  1315. procedure Tenumdef.calcsavesize;
  1316. begin
  1317. if (aktpackenum=4) or (minval<0) or (maxval>65535) then
  1318. savesize:=4
  1319. else if (aktpackenum=2) or (minval<0) or (maxval>255) then
  1320. savesize:=2
  1321. else
  1322. savesize:=1;
  1323. end;
  1324. procedure Tenumdef.setmax(Amax:longint);
  1325. begin
  1326. maxval:=Amax;
  1327. calcsavesize;
  1328. end;
  1329. procedure Tenumdef.setmin(Amin:longint);
  1330. begin
  1331. minval:=Amin;
  1332. calcsavesize;
  1333. end;
  1334. procedure tenumdef.deref;
  1335. begin
  1336. { resolvedef(pdef(basedef));}
  1337. end;
  1338. procedure Tenumdef.store(var s:Tstream);
  1339. begin
  1340. inherited store(s);
  1341. (* writedefref(basedef);
  1342. writelong(min);
  1343. writelong(max);
  1344. writelong(savesize);
  1345. current_ppu^.writeentry(ibenumdef);*)
  1346. end;
  1347. function tenumdef.getrangecheckstring : string;
  1348. begin
  1349. if (cs_create_smart in aktmoduleswitches) then
  1350. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1351. else
  1352. getrangecheckstring:='R_'+tostr(rangenr);
  1353. end;
  1354. procedure tenumdef.genrangecheck;
  1355. begin
  1356. if rangenr=0 then
  1357. begin
  1358. { generate two constant for bounds }
  1359. getlabelnr(rangenr);
  1360. if (cs_create_smart in aktmoduleswitches) then
  1361. datasegment^.concat(new(Pai_symbol,
  1362. initname_global(getrangecheckstring,8)))
  1363. else
  1364. datasegment^.concat(new(Pai_symbol,
  1365. initname(getrangecheckstring,8)));
  1366. datasegment^.concat(new(pai_const,init_32bit(minval)));
  1367. datasegment^.concat(new(pai_const,init_32bit(maxval)));
  1368. end;
  1369. end;
  1370. procedure Tenumdef.write_child_rtti_data;
  1371. begin
  1372. if assigned(basedef) then
  1373. basedef^.get_rtti_label;
  1374. end;
  1375. procedure Tenumdef.write_rtti_data;
  1376. var i:word;
  1377. begin
  1378. rttilist^.concat(new(pai_const,init_8bit(tkEnumeration)));
  1379. write_rtti_name;
  1380. case savesize of
  1381. 1:
  1382. rttilist^.concat(new(Pai_const,init_8bit(otUByte)));
  1383. 2:
  1384. rttilist^.concat(new(Pai_const,init_8bit(otUWord)));
  1385. 4:
  1386. rttilist^.concat(new(Pai_const,init_8bit(otULong)));
  1387. end;
  1388. rttilist^.concat(new(pai_const,init_32bit(minval)));
  1389. rttilist^.concat(new(pai_const,init_32bit(maxval)));
  1390. if assigned(basedef) then
  1391. rttilist^.concat(new(pai_const_symbol,initname(basedef^.get_rtti_label)))
  1392. else
  1393. rttilist^.concat(new(pai_const,init_32bit(0)));
  1394. for i:=0 to symbols^.count-1 do
  1395. begin
  1396. rttilist^.concat(new(Pai_const,
  1397. init_8bit(length(Penumsym(symbols^.at(i))^.name))));
  1398. rttilist^.concat(new(Pai_string,
  1399. init(globals.lower(Penumsym(symbols^.at(i))^.name))));
  1400. end;
  1401. rttilist^.concat(new(pai_const,init_8bit(0)));
  1402. end;
  1403. function Tenumdef.is_publishable:boolean;
  1404. begin
  1405. is_publishable:=true;
  1406. end;
  1407. function Tenumdef.gettypename:string;
  1408. var i:word;
  1409. v:longint;
  1410. r:string;
  1411. begin
  1412. r:='(';
  1413. for i:=0 to symbols^.count-1 do
  1414. begin
  1415. v:=Penumsym(symbols^.at(i))^.value;
  1416. if (v>=minval) and (v<=maxval) then
  1417. r:=r+Penumsym(symbols^.at(i))^.name+',';
  1418. end;
  1419. {Turn ',' into ')'.}
  1420. r[length(r)]:=')';
  1421. end;
  1422. {****************************************************************************
  1423. Torddef
  1424. ****************************************************************************}
  1425. constructor Torddef.init(t:Tbasetype;l,h:Tconstant;
  1426. Aowner:Pcontainingsymtable);
  1427. begin
  1428. inherited init(Aowner);
  1429. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  1430. include(properties,dp_ret_in_acc);
  1431. low:=l;
  1432. high:=h;
  1433. typ:=t;
  1434. setsize;
  1435. end;
  1436. constructor Torddef.load(var s:Tstream);
  1437. begin
  1438. inherited load(s);
  1439. (* typ:=tbasetype(readbyte);
  1440. low:=readlong;
  1441. high:=readlong;*)
  1442. setsize;
  1443. end;
  1444. procedure Torddef.setsize;
  1445. begin
  1446. if typ=uauto then
  1447. begin
  1448. {Generate a unsigned range if high<0 and low>=0 }
  1449. if (low.values>=0) and (high.values<=255) then
  1450. typ:=u8bit
  1451. else if (low.signed) and (low.values>=-128) and (high.values<=127) then
  1452. typ:=s8bit
  1453. else if (low.values>=0) and (high.values<=65536) then
  1454. typ:=u16bit
  1455. else if (low.signed) and (low.values>=-32768) and (high.values<=32767) then
  1456. typ:=s16bit
  1457. else if low.signed then
  1458. typ:=s32bit
  1459. else
  1460. typ:=u32bit
  1461. end;
  1462. case typ of
  1463. u8bit,s8bit,uchar,bool8bit:
  1464. savesize:=1;
  1465. u16bit,s16bit,bool16bit:
  1466. savesize:=2;
  1467. s32bit,u32bit,bool32bit:
  1468. savesize:=4;
  1469. u64bit,s64bitint:
  1470. savesize:=8;
  1471. else
  1472. savesize:=0;
  1473. end;
  1474. rangenr:=0;
  1475. end;
  1476. function Torddef.getrangecheckstring:string;
  1477. begin
  1478. if (cs_create_smart in aktmoduleswitches) then
  1479. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1480. else
  1481. getrangecheckstring:='R_'+tostr(rangenr);
  1482. end;
  1483. procedure Torddef.genrangecheck;
  1484. begin
  1485. if rangenr=0 then
  1486. begin
  1487. {Generate two constant for bounds.}
  1488. getlabelnr(rangenr);
  1489. if (cs_create_smart in aktmoduleswitches) then
  1490. datasegment^.concat(new(Pai_symbol,
  1491. initname_global(getrangecheckstring,10)))
  1492. else
  1493. datasegment^.concat(new(Pai_symbol,
  1494. initname(getrangecheckstring,10)));
  1495. datasegment^.concat(new(Pai_const,init_8bit(byte(low.signed))));
  1496. datasegment^.concat(new(Pai_const,init_32bit(low.values)));
  1497. datasegment^.concat(new(Pai_const,init_8bit(byte(high.signed))));
  1498. datasegment^.concat(new(Pai_const,init_32bit(high.values)));
  1499. end;
  1500. end;
  1501. procedure Torddef.store(var s:Tstream);
  1502. begin
  1503. inherited store(s);
  1504. (* writebyte(byte(typ));
  1505. writelong(low);
  1506. writelong(high);
  1507. current_ppu^.writeentry(iborddef);*)
  1508. end;
  1509. procedure Torddef.write_rtti_data;
  1510. const trans:array[uchar..bool8bit] of byte=
  1511. (otubyte,otubyte,otuword,otulong,
  1512. otsbyte,otsword,otslong,otubyte);
  1513. begin
  1514. case typ of
  1515. bool8bit:
  1516. rttilist^.concat(new(Pai_const,init_8bit(tkbool)));
  1517. uchar:
  1518. rttilist^.concat(new(Pai_const,init_8bit(tkchar)));
  1519. else
  1520. rttilist^.concat(new(Pai_const,init_8bit(tkinteger)));
  1521. end;
  1522. write_rtti_name;
  1523. rttilist^.concat(new(Pai_const,init_8bit(byte(trans[typ]))));
  1524. rttilist^.concat(new(Pai_const,init_32bit(low.values)));
  1525. rttilist^.concat(new(Pai_const,init_32bit(high.values)));
  1526. end;
  1527. function Torddef.is_publishable:boolean;
  1528. begin
  1529. is_publishable:=typ in [uchar..bool8bit];
  1530. end;
  1531. function Torddef.gettypename:string;
  1532. const names:array[Tbasetype] of string[20]=('<unknown type>',
  1533. 'untyped','char','byte','word','dword','shortInt',
  1534. 'smallint','longInt','boolean','wordbool',
  1535. 'longbool','qword','int64','card64','widechar');
  1536. begin
  1537. gettypename:=names[typ];
  1538. end;
  1539. {****************************************************************************
  1540. Tfloatdef
  1541. ****************************************************************************}
  1542. constructor Tfloatdef.init(t:Tfloattype;Aowner:Pcontainingsymtable);
  1543. begin
  1544. inherited init(Aowner);
  1545. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  1546. if t=f32bit then
  1547. include(properties,dp_ret_in_acc);
  1548. typ:=t;
  1549. setsize;
  1550. end;
  1551. constructor Tfloatdef.load(var s:Tstream);
  1552. begin
  1553. inherited load(s);
  1554. (* typ:=Tfloattype(readbyte);*)
  1555. setsize;
  1556. end;
  1557. procedure tfloatdef.setsize;
  1558. begin
  1559. case typ of
  1560. f16bit:
  1561. savesize:=2;
  1562. f32bit,
  1563. s32real:
  1564. savesize:=4;
  1565. s64real:
  1566. savesize:=8;
  1567. s80real:
  1568. savesize:=extended_size;
  1569. s64comp:
  1570. savesize:=8;
  1571. else
  1572. savesize:=0;
  1573. end;
  1574. end;
  1575. procedure Tfloatdef.store(var s:Tstream);
  1576. begin
  1577. inherited store(s);
  1578. (* writebyte(byte(typ));
  1579. current_ppu^.writeentry(ibfloatdef);*)
  1580. end;
  1581. procedure Tfloatdef.write_rtti_data;
  1582. const translate:array[Tfloattype] of byte=
  1583. (ftsingle,ftdouble,ftextended,ftcomp,ftfixed16,ftfixed32);
  1584. begin
  1585. rttilist^.concat(new(Pai_const,init_8bit(tkfloat)));
  1586. write_rtti_name;
  1587. rttilist^.concat(new(Pai_const,init_8bit(translate[typ])));
  1588. end;
  1589. function Tfloatdef.is_publishable:boolean;
  1590. begin
  1591. is_publishable:=true;
  1592. end;
  1593. function Tfloatdef.gettypename:string;
  1594. const names:array[Tfloattype] of string[20]=(
  1595. 'single','double','extended','comp','fixed','shortfixed');
  1596. begin
  1597. gettypename:=names[typ];
  1598. end;
  1599. {***************************************************************************
  1600. Tsetdef
  1601. ***************************************************************************}
  1602. { For i386 smallsets work,
  1603. for m68k there are problems
  1604. can be test by compiling with -dusesmallset PM }
  1605. {$ifdef i386}
  1606. {$define usesmallset}
  1607. {$endif i386}
  1608. constructor Tsetdef.init(s:Pdef;high:longint;Aowner:Pcontainingsymtable);
  1609. begin
  1610. inherited init(Aowner);
  1611. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  1612. definition:=s;
  1613. if high<32 then
  1614. begin
  1615. settype:=smallset;
  1616. savesize:=4;
  1617. include(properties,dp_ret_in_acc);
  1618. end
  1619. else if high<256 then
  1620. begin
  1621. settype:=normset;
  1622. savesize:=32;
  1623. end
  1624. {$ifdef testvarsets}
  1625. else if high<$10000 then
  1626. begin
  1627. settype:=varset;
  1628. savesize:=4*((high+31) div 32);
  1629. end
  1630. {$endif testvarsets}
  1631. else
  1632. message(sym_e_ill_type_decl_set);
  1633. end;
  1634. constructor Tsetdef.load(var s:Tstream);
  1635. begin
  1636. inherited load(s);
  1637. (* setof:=readdefref;
  1638. settype:=tsettype(readbyte);
  1639. case settype of
  1640. normset:
  1641. savesize:=32;
  1642. varset:
  1643. savesize:=readlong;
  1644. smallset:
  1645. savesize:=sizeof(longint);
  1646. end;*)
  1647. end;
  1648. procedure Tsetdef.store(var s:Tstream);
  1649. begin
  1650. inherited store(s);
  1651. (* writedefref(setof);
  1652. writebyte(byte(settype));
  1653. if settype=varset then
  1654. writelong(savesize);
  1655. current_ppu^.writeentry(ibsetdef);*)
  1656. end;
  1657. procedure Tsetdef.deref;
  1658. begin
  1659. { resolvedef(setof);}
  1660. end;
  1661. procedure Tsetdef.write_rtti_data;
  1662. begin
  1663. rttilist^.concat(new(pai_const,init_8bit(tkset)));
  1664. write_rtti_name;
  1665. rttilist^.concat(new(pai_const,init_8bit(otuLong)));
  1666. rttilist^.concat(new(pai_const_symbol,initname(definition^.get_rtti_label)));
  1667. end;
  1668. procedure Tsetdef.write_child_rtti_data;
  1669. begin
  1670. definition^.get_rtti_label;
  1671. end;
  1672. function Tsetdef.is_publishable:boolean;
  1673. begin
  1674. is_publishable:=settype=smallset;
  1675. end;
  1676. function Tsetdef.gettypename:string;
  1677. begin
  1678. gettypename:='set of '+definition^.typename;
  1679. end;
  1680. {***************************************************************************
  1681. Trecorddef
  1682. ***************************************************************************}
  1683. constructor Trecorddef.init(s:Precordsymtable;Aowner:Pcontainingsymtable);
  1684. begin
  1685. inherited init(Aowner);
  1686. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  1687. symtable:=s;
  1688. savesize:=symtable^.datasize;
  1689. end;
  1690. constructor Trecorddef.load(var s:Tstream);
  1691. var oldread_member:boolean;
  1692. begin
  1693. (* inherited load(s);
  1694. savesize:=readlong;
  1695. oldread_member:=read_member;
  1696. read_member:=true;
  1697. symtable:=new(psymtable,loadas(recordsymtable));
  1698. read_member:=oldread_member;
  1699. symtable^.defowner := @self;*)
  1700. end;
  1701. destructor Trecorddef.done;
  1702. begin
  1703. if symtable<>nil then
  1704. dispose(symtable,done);
  1705. inherited done;
  1706. end;
  1707. var
  1708. binittable : boolean;
  1709. procedure check_rec_inittable(s:Pnamedindexobject);
  1710. begin
  1711. if (typeof(s^)=typeof(Tvarsym)) and
  1712. ((typeof((Pvarsym(s)^.definition^))<>typeof(Tobjectdef)) or
  1713. not (oo_is_class in Pobjectdef(Pvarsym(s)^.definition)^.options)) then
  1714. binittable:=pvarsym(s)^.definition^.needs_inittable;
  1715. end;
  1716. function Trecorddef.needs_inittable:boolean;
  1717. var oldb:boolean;
  1718. begin
  1719. { there are recursive calls to needs_rtti possible, }
  1720. { so we have to change to old value how else should }
  1721. { we do that ? check_rec_rtti can't be a nested }
  1722. { procedure of needs_rtti ! }
  1723. oldb:=binittable;
  1724. binittable:=false;
  1725. symtable^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  1726. needs_inittable:=binittable;
  1727. binittable:=oldb;
  1728. end;
  1729. procedure Trecorddef.deref;
  1730. var oldrecsyms:Psymtable;
  1731. begin
  1732. (* oldrecsyms:=aktrecordsymtable;
  1733. aktrecordsymtable:=symtable;
  1734. { now dereference the definitions }
  1735. symtable^.deref;
  1736. aktrecordsymtable:=oldrecsyms;*)
  1737. end;
  1738. procedure Trecorddef.store(var s:Tstream);
  1739. var oldread_member:boolean;
  1740. begin
  1741. (* oldread_member:=read_member;
  1742. read_member:=true;
  1743. inherited store(s);
  1744. writelong(savesize);
  1745. current_ppu^.writeentry(ibrecorddef);
  1746. self.symtable^.writeas;
  1747. read_member:=oldread_member;*)
  1748. end;
  1749. procedure count_inittable_fields(sym:Pnamedindexobject);
  1750. {$ifndef fpc}far;{$endif}
  1751. begin
  1752. if (typeof(sym^)=typeof(Tvarsym)) and
  1753. (Pvarsym(sym)^.definition^.needs_inittable) then
  1754. inc(count);
  1755. end;
  1756. procedure count_fields(sym:Pnamedindexobject);{$ifndef fpc}far;{$endif}
  1757. begin
  1758. inc(count);
  1759. end;
  1760. procedure write_field_inittable(sym:Pnamedindexobject);
  1761. {$ifndef fpc}far;{$endif}
  1762. begin
  1763. if (typeof(sym^)=typeof(Tvarsym)) and
  1764. Pvarsym(sym)^.definition^.needs_inittable then
  1765. begin
  1766. rttilist^.concat(new(Pai_const_symbol,
  1767. init(pvarsym(sym)^.definition^.get_inittable_label)));
  1768. rttilist^.concat(new(Pai_const,
  1769. init_32bit(pvarsym(sym)^.address)));
  1770. end;
  1771. end;
  1772. procedure write_field_rtti(sym:Pnamedindexobject);{$ifndef fpc}far;{$endif}
  1773. begin
  1774. rttilist^.concat(new(Pai_const_symbol,
  1775. initname(Pvarsym(sym)^.definition^.get_rtti_label)));
  1776. rttilist^.concat(new(Pai_const,
  1777. init_32bit(Pvarsym(sym)^.address)));
  1778. end;
  1779. procedure generate_child_inittable(sym:Pnamedindexobject);
  1780. {$ifndef fpc}far;{$endif}
  1781. begin
  1782. if (typeof(sym^)=typeof(Tvarsym)) and
  1783. Pvarsym(sym)^.definition^.needs_inittable then
  1784. {Force inittable generation }
  1785. Pvarsym(sym)^.definition^.get_inittable_label;
  1786. end;
  1787. procedure generate_child_rtti(sym:Pnamedindexobject);
  1788. {$ifndef fpc}far;{$endif}
  1789. begin
  1790. Pvarsym(sym)^.definition^.get_rtti_label;
  1791. end;
  1792. procedure Trecorddef.write_child_rtti_data;
  1793. begin
  1794. symtable^.foreach({$ifndef TP}@{$endif}generate_child_rtti);
  1795. end;
  1796. procedure Trecorddef.write_child_init_data;
  1797. begin
  1798. symtable^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  1799. end;
  1800. procedure Trecorddef.write_rtti_data;
  1801. begin
  1802. rttilist^.concat(new(pai_const,init_8bit(tkrecord)));
  1803. write_rtti_name;
  1804. rttilist^.concat(new(pai_const,init_32bit(size)));
  1805. count:=0;
  1806. symtable^.foreach({$ifndef TP}@{$endif}count_fields);
  1807. rttilist^.concat(new(pai_const,init_32bit(count)));
  1808. symtable^.foreach({$ifndef TP}@{$endif}write_field_rtti);
  1809. end;
  1810. procedure Trecorddef.write_init_data;
  1811. begin
  1812. rttilist^.concat(new(pai_const,init_8bit(14)));
  1813. write_rtti_name;
  1814. rttilist^.concat(new(pai_const,init_32bit(size)));
  1815. count:=0;
  1816. symtable^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  1817. rttilist^.concat(new(pai_const,init_32bit(count)));
  1818. symtable^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  1819. end;
  1820. function Trecorddef.gettypename:string;
  1821. begin
  1822. gettypename:='<record type>'
  1823. end;
  1824. {***************************************************************************
  1825. Tstringprocdef
  1826. ***************************************************************************}
  1827. constructor Tstringdef.shortinit(l:byte;Aowner:Pcontainingsymtable);
  1828. begin
  1829. inherited init(Aowner);
  1830. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  1831. string_typ:=st_shortstring;
  1832. len:=l;
  1833. savesize:=len+1;
  1834. end;
  1835. constructor Tstringdef.shortload(var s:Tstream);
  1836. begin
  1837. inherited load(s);
  1838. string_typ:=st_shortstring;
  1839. { len:=readbyte;
  1840. savesize:=len+1;}
  1841. end;
  1842. constructor Tstringdef.longinit(l:longint;Aowner:Pcontainingsymtable);
  1843. begin
  1844. inherited init(Aowner);
  1845. string_typ:=st_longstring;
  1846. len:=l;
  1847. savesize:=target_os.size_of_pointer;
  1848. end;
  1849. constructor Tstringdef.longload(var s:Tstream);
  1850. begin
  1851. inherited load(s);
  1852. string_typ:=st_longstring;
  1853. { len:=readlong;
  1854. savesize:=target_os.size_of_pointer;}
  1855. end;
  1856. constructor tstringdef.ansiinit(l:longint;Aowner:Pcontainingsymtable);
  1857. begin
  1858. inherited init(Aowner);
  1859. include(properties,dp_ret_in_acc);
  1860. string_typ:=st_ansistring;
  1861. len:=l;
  1862. savesize:=target_os.size_of_pointer;
  1863. end;
  1864. constructor Tstringdef.ansiload(var s:Tstream);
  1865. begin
  1866. inherited load(s);
  1867. string_typ:=st_ansistring;
  1868. { len:=readlong;
  1869. savesize:=target_os.size_of_pointer;}
  1870. end;
  1871. constructor Tstringdef.wideinit(l:longint;Aowner:Pcontainingsymtable);
  1872. begin
  1873. inherited init(Aowner);
  1874. include(properties,dp_ret_in_acc);
  1875. string_typ:=st_widestring;
  1876. len:=l;
  1877. savesize:=target_os.size_of_pointer;
  1878. end;
  1879. constructor Tstringdef.wideload(var s:Tstream);
  1880. begin
  1881. inherited load(s);
  1882. string_typ:=st_widestring;
  1883. { len:=readlong;
  1884. savesize:=target_os.size_of_pointer;}
  1885. end;
  1886. function Tstringdef.stringtypname:string;
  1887. const typname:array[tstringtype] of string[8]=
  1888. ('','SHORTSTR','LONGSTR','ANSISTR','WIDESTR');
  1889. begin
  1890. stringtypname:=typname[string_typ];
  1891. end;
  1892. function tstringdef.size:longint;
  1893. begin
  1894. size:=savesize;
  1895. end;
  1896. procedure Tstringdef.store(var s:Tstream);
  1897. begin
  1898. inherited store(s);
  1899. { if string_typ=st_shortstring then
  1900. writebyte(len)
  1901. else
  1902. writelong(len);
  1903. case string_typ of
  1904. st_shortstring:
  1905. current_ppu^.writeentry(ibshortstringdef);
  1906. st_longstring:
  1907. current_ppu^.writeentry(iblongstringdef);
  1908. st_ansistring:
  1909. current_ppu^.writeentry(ibansistringdef);
  1910. st_widestring:
  1911. current_ppu^.writeentry(ibwidestringdef);
  1912. end;}
  1913. end;
  1914. {$ifdef GDB}
  1915. function tstringdef.stabstring : pchar;
  1916. var
  1917. bytest,charst,longst : string;
  1918. begin
  1919. case string_typ of
  1920. st_shortstring:
  1921. begin
  1922. charst := typeglobalnumber('char');
  1923. { this is what I found in stabs.texinfo but
  1924. gdb 4.12 for go32 doesn't understand that !! }
  1925. {$IfDef GDBknowsstrings}
  1926. stabstring := strpnew('n'+charst+';'+tostr(len));
  1927. {$else}
  1928. bytest := typeglobalnumber('byte');
  1929. stabstring := strpnew('s'+tostr(len+1)+'length:'+bytest
  1930. +',0,8;st:ar'+bytest
  1931. +';1;'+tostr(len)+';'+charst+',8,'+tostr(len*8)+';;');
  1932. {$EndIf}
  1933. end;
  1934. st_longstring:
  1935. begin
  1936. charst := typeglobalnumber('char');
  1937. { this is what I found in stabs.texinfo but
  1938. gdb 4.12 for go32 doesn't understand that !! }
  1939. {$IfDef GDBknowsstrings}
  1940. stabstring := strpnew('n'+charst+';'+tostr(len));
  1941. {$else}
  1942. bytest := typeglobalnumber('byte');
  1943. longst := typeglobalnumber('longint');
  1944. stabstring := strpnew('s'+tostr(len+5)+'length:'+longst
  1945. +',0,32;dummy:'+bytest+',32,8;st:ar'+bytest
  1946. +';1;'+tostr(len)+';'+charst+',40,'+tostr(len*8)+';;');
  1947. {$EndIf}
  1948. end;
  1949. st_ansistring:
  1950. begin
  1951. { an ansi string looks like a pchar easy !! }
  1952. stabstring:=strpnew('*'+typeglobalnumber('char'));
  1953. end;
  1954. st_widestring:
  1955. begin
  1956. { an ansi string looks like a pchar easy !! }
  1957. stabstring:=strpnew('*'+typeglobalnumber('char'));
  1958. end;
  1959. end;
  1960. end;
  1961. procedure tstringdef.concatstabto(asmlist : paasmoutput);
  1962. begin
  1963. inherited concatstabto(asmlist);
  1964. end;
  1965. {$endif GDB}
  1966. function tstringdef.needs_inittable : boolean;
  1967. begin
  1968. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  1969. end;
  1970. function tstringdef.gettypename : string;
  1971. const
  1972. names : array[tstringtype] of string[20] = ('',
  1973. 'ShortString','LongString','AnsiString','WideString');
  1974. begin
  1975. gettypename:=names[string_typ];
  1976. end;
  1977. procedure tstringdef.write_rtti_data;
  1978. begin
  1979. case string_typ of
  1980. st_ansistring:
  1981. begin
  1982. rttilist^.concat(new(pai_const,init_8bit(tkAString)));
  1983. write_rtti_name;
  1984. end;
  1985. st_widestring:
  1986. begin
  1987. rttilist^.concat(new(pai_const,init_8bit(tkWString)));
  1988. write_rtti_name;
  1989. end;
  1990. st_longstring:
  1991. begin
  1992. rttilist^.concat(new(pai_const,init_8bit(tkLString)));
  1993. write_rtti_name;
  1994. end;
  1995. st_shortstring:
  1996. begin
  1997. rttilist^.concat(new(pai_const,init_8bit(tkSString)));
  1998. write_rtti_name;
  1999. rttilist^.concat(new(pai_const,init_8bit(len)));
  2000. end;
  2001. end;
  2002. end;
  2003. function tstringdef.is_publishable : boolean;
  2004. begin
  2005. is_publishable:=true;
  2006. end;
  2007. {***************************************************************************
  2008. Tabstractprocdef
  2009. ***************************************************************************}
  2010. constructor Tabstractprocdef.init(Aowner:Pcontainingsymtable);
  2011. begin
  2012. inherited init(Aowner);
  2013. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  2014. include(properties,dp_ret_in_acc);
  2015. retdef:=voiddef;
  2016. savesize:=target_os.size_of_pointer;
  2017. end;
  2018. constructor Tabstractprocdef.load(var s:Tstream);
  2019. var count,i:word;
  2020. begin
  2021. inherited load(s);
  2022. (* retdef:=readdefref;
  2023. fpu_used:=readbyte;
  2024. options:=readlong;
  2025. count:=readword;
  2026. new(parameters);
  2027. savesize:=target_os.size_of_pointer;
  2028. for i:=1 to count do
  2029. parameters^.readsymref;*)
  2030. end;
  2031. { all functions returning in FPU are
  2032. assume to use 2 FPU registers
  2033. until the function implementation
  2034. is processed PM }
  2035. procedure Tabstractprocdef.test_if_fpu_result;
  2036. begin
  2037. if (retdef<>nil) and (typeof(retdef^)=typeof(Tfloatdef)) and
  2038. (Pfloatdef(retdef)^.typ in [f32bit,f16bit]) then
  2039. fpu_used:=2;
  2040. end;
  2041. procedure Tabstractprocdef.deref;
  2042. var i:longint;
  2043. begin
  2044. inherited deref;
  2045. { resolvedef(retdef);}
  2046. for i:=0 to parameters^.count-1 do
  2047. Psym(parameters^.at(i))^.deref;
  2048. end;
  2049. function Tabstractprocdef.para_size:longint;
  2050. var i,l:longint;
  2051. begin
  2052. l:=0;
  2053. for i:=0 to parameters^.count-1 do
  2054. inc(l,Pparamsym(parameters^.at(i))^.getpushsize);
  2055. para_size:=l;
  2056. end;
  2057. procedure Tabstractprocdef.store(var s:Tstream);
  2058. var count,i:word;
  2059. begin
  2060. inherited store(s);
  2061. { writedefref(retdef);
  2062. current_ppu^.do_interface_crc:=false;
  2063. writebyte(fpu_used);
  2064. writelong(options);
  2065. writeword(parameters^.count);
  2066. for i:=0 to parameters^.count-1 do
  2067. begin
  2068. writebyte(byte(hp^.paratyp));
  2069. writesymfref(hp^.data);
  2070. end;}
  2071. end;
  2072. function Tabstractprocdef.demangled_paras:string;
  2073. var i:longint;
  2074. s:string;
  2075. procedure doconcat(p:Pparameter);
  2076. begin
  2077. s:=s+p^.data^.name;
  2078. if p^.paratyp=vs_var then
  2079. s:=s+'var'
  2080. else if p^.paratyp=vs_const then
  2081. s:=s+'const';
  2082. end;
  2083. begin
  2084. s:='(';
  2085. for i:=0 to parameters^.count-1 do
  2086. doconcat(parameters^.at(i));
  2087. s[length(s)]:=')';
  2088. demangled_paras:=s;
  2089. end;
  2090. destructor Tabstractprocdef.done;
  2091. begin
  2092. dispose(parameters,done);
  2093. inherited done;
  2094. end;
  2095. {***************************************************************************
  2096. TPROCDEF
  2097. ***************************************************************************}
  2098. constructor Tprocdef.init(Aowner:Pcontainingsymtable);
  2099. begin
  2100. inherited init(Aowner);
  2101. {$IFDEF TP}setparent(typeof(Tabstractprocdef));{$ENDIF}
  2102. fileinfo:=aktfilepos;
  2103. extnumber:=-1;
  2104. new(localst,init);
  2105. if (cs_browser in aktmoduleswitches) and make_ref then
  2106. begin
  2107. new(references,init(2*owner^.index_growsize,
  2108. owner^.index_growsize));
  2109. references^.insert(new(Pref,init(tokenpos)));
  2110. end;
  2111. {First, we assume that all registers are used }
  2112. usedregisters:=[low(Tregister)..high(Tregister)];
  2113. forwarddef:=true;
  2114. end;
  2115. constructor Tprocdef.load(var s:Tstream);
  2116. var a:string;
  2117. begin
  2118. inherited load(s);
  2119. (* usedregisters:=readlong;
  2120. a:=readstring;
  2121. setstring(_mangledname,s);
  2122. extnumber:=readlong;
  2123. nextoerloaded:=pprocdef(readdefref);
  2124. _class := pobjectdef(readdefref);
  2125. readposinfo(fileinfo);
  2126. if (cs_link_deffile in aktglobalswitches)
  2127. and (poexports in options) then
  2128. deffile.ddexport(mangledname);
  2129. count:=true;*)
  2130. end;
  2131. const local_symtable_index : longint = $8001;
  2132. procedure tprocdef.load_references;
  2133. var pos:Tfileposinfo;
  2134. pdo:Pobjectdef;
  2135. move_last:boolean;
  2136. begin
  2137. (* move_last:=lastwritten=lastref;
  2138. while (not current_ppu^.endofentry) do
  2139. begin
  2140. readposinfo(pos);
  2141. inc(refcount);
  2142. lastref:=new(pref,init(lastref,@pos));
  2143. lastref^.is_written:=true;
  2144. if refcount=1 then
  2145. defref:=lastref;
  2146. end;
  2147. if move_last then
  2148. lastwritten:=lastref;
  2149. if ((current_module^.flags and uf_local_browser)<>0)
  2150. and is_in_current then
  2151. begin
  2152. {$ifndef NOLOCALBROWSER}
  2153. pdo:=_class;
  2154. new(parast,loadas(parasymtable));
  2155. parast^.next:=owner;
  2156. parast^.load_browser;
  2157. new(localst,loadas(localsymtable));
  2158. localst^.next:=parast;
  2159. localst^.load_browser;
  2160. {$endif NOLOCALBROWSER}
  2161. end;*)
  2162. end;
  2163. function Tprocdef.write_references:boolean;
  2164. var ref:Pref;
  2165. pdo:Pobjectdef;
  2166. move_last:boolean;
  2167. begin
  2168. (* move_last:=lastwritten=lastref;
  2169. if move_last and (((current_module^.flags and uf_local_browser)=0)
  2170. or not is_in_current) then
  2171. exit;
  2172. {Write address of this symbol }
  2173. writedefref(@self);
  2174. {Write refs }
  2175. if assigned(lastwritten) then
  2176. ref:=lastwritten
  2177. else
  2178. ref:=defref;
  2179. while assigned(ref) do
  2180. begin
  2181. if ref^.moduleindex=current_module^.unit_index then
  2182. begin
  2183. writeposinfo(ref^.posinfo);
  2184. ref^.is_written:=true;
  2185. if move_last then
  2186. lastwritten:=ref;
  2187. end
  2188. else if not ref^.is_written then
  2189. move_last:=false
  2190. else if move_last then
  2191. lastwritten:=ref;
  2192. ref:=ref^.nextref;
  2193. end;
  2194. current_ppu^.writeentry(ibdefref);
  2195. write_references:=true;
  2196. if ((current_module^.flags and uf_local_browser)<>0)
  2197. and is_in_current then
  2198. begin
  2199. pdo:=_class;
  2200. if (owner^.symtabletype<>localsymtable) then
  2201. while assigned(pdo) do
  2202. begin
  2203. if pdo^.publicsyms<>aktrecordsymtable then
  2204. begin
  2205. pdo^.publicsyms^.unitid:=local_symtable_index;
  2206. inc(local_symtable_index);
  2207. end;
  2208. pdo:=pdo^.childof;
  2209. end;
  2210. {We need TESTLOCALBROWSER para and local symtables
  2211. PPU files are then easier to read PM.}
  2212. inc(local_symtable_index);
  2213. parast^.write_browser;
  2214. if not assigned(localst) then
  2215. localst:=new(psymtable,init);
  2216. localst^.writeas;
  2217. localst^.unitid:=local_symtable_index;
  2218. inc(local_symtable_index);
  2219. localst^.write_browser;
  2220. {Decrement for.}
  2221. local_symtable_index:=local_symtable_index-2;
  2222. pdo:=_class;
  2223. if (owner^.symtabletype<>localsymtable) then
  2224. while assigned(pdo) do
  2225. begin
  2226. if pdo^.publicsyms<>aktrecordsymtable then
  2227. dec(local_symtable_index);
  2228. pdo:=pdo^.childof;
  2229. end;
  2230. end;*)
  2231. end;
  2232. destructor Tprocdef.done;
  2233. begin
  2234. if pomsgstr in options then
  2235. strdispose(messageinf.str);
  2236. if references<>nil then
  2237. dispose(references,done);
  2238. if (localst<>nil) and (typeof(localst^)<>typeof(Timplsymtable)) then
  2239. dispose(localst,done);
  2240. { if (poinline in options) and (code,nil) then
  2241. disposetree(ptree(code));}
  2242. if _mangledname<>nil then
  2243. disposestr(_mangledname);
  2244. inherited done;
  2245. end;
  2246. procedure Tprocdef.store(var s:Tstream);
  2247. begin
  2248. (* inherited store(s);
  2249. current_ppu^.do_interface_crc:=false;
  2250. writelong(usedregisters);
  2251. writestring(mangledname);
  2252. current_ppu^.do_interface_crc:=true;
  2253. writelong(extnumber);
  2254. if (options and pooperator) = 0 then
  2255. writedefref(nextoverloaded)
  2256. else
  2257. begin
  2258. {Only write the overloads from the same unit }
  2259. if assigned(nextoverloaded) and
  2260. (nextoverloaded^.owner=owner) then
  2261. writedefref(nextoverloaded)
  2262. else
  2263. writedefref(nil);
  2264. end;
  2265. writedefref(_class);
  2266. writeposinfo(fileinfo);
  2267. if (poinline and options) then
  2268. begin
  2269. {We need to save
  2270. - the para and the local symtable
  2271. - the code ptree !! PM
  2272. writesymtable(parast);
  2273. writesymtable(localst);
  2274. writeptree(ptree(code));
  2275. }
  2276. end;
  2277. current_ppu^.writeentry(ibprocdef);*)
  2278. end;
  2279. procedure Tprocdef.deref;
  2280. begin
  2281. { inherited deref;
  2282. resolvedef(pdef(nextoverloaded));
  2283. resolvedef(pdef(_class));}
  2284. end;
  2285. function Tprocdef.mangledname:string;
  2286. var i:word;
  2287. a:byte;
  2288. s:Pprocsym;
  2289. r:string;
  2290. begin
  2291. if _mangledname<>nil then
  2292. mangledname:=_mangledname^
  2293. else
  2294. begin
  2295. {If the procedure is in a unit, we start with the unitname.}
  2296. if current_module^.is_unit then
  2297. r:='_'+current_module^.modulename^
  2298. else
  2299. r:='';
  2300. a:=length(r);
  2301. {If we are a method we add the name of the object we are
  2302. belonging to.}
  2303. if (Pprocsym(sym)^._class<>nil) then
  2304. r:=r+'_M'+Pprocsym(sym)^._class^.sym^.name+'_M';
  2305. {Then we add the names of the procedures we are defined in
  2306. (for the case we are a nested procedure).}
  2307. s:=Pprocsym(sym)^.sub_of;
  2308. while typeof(s^.owner^)=typeof(Tprocsymtable) do
  2309. begin
  2310. insert('_$'+s^.name,r,a);
  2311. s:=s^.sub_of;
  2312. end;
  2313. r:=r+'_'+sym^.name;
  2314. {Add the types of all parameters.}
  2315. for i:=0 to parameters^.count-1 do
  2316. begin
  2317. r:=r+'$'+Pparameter(parameters^.at(i))^.data^.name;
  2318. end;
  2319. end;
  2320. end;
  2321. procedure Tprocdef.setmangledname(const s:string);
  2322. begin
  2323. if _mangledname<>nil then
  2324. disposestr(_mangledname);
  2325. _mangledname:=stringdup(s);
  2326. if localst<>nil then
  2327. begin
  2328. stringdispose(localst^.name);
  2329. localst^.name:=stringdup('locals of '+s);
  2330. end;
  2331. end;
  2332. {***************************************************************************
  2333. Tprocvardef
  2334. ***************************************************************************}
  2335. {$IFDEF TP}
  2336. constructor Tprocvardef.init(Aowner:Pcontainingsymtable);
  2337. begin
  2338. setparent(typeof(Tabstractprocdef));
  2339. end;
  2340. {$ENDIF TP}
  2341. function Tprocvardef.size:longint;
  2342. begin
  2343. if pomethodpointer in options then
  2344. size:=2*target_os.size_of_pointer
  2345. else
  2346. size:=target_os.size_of_pointer;
  2347. end;
  2348. {$ifdef GDB}
  2349. function tprocvardef.stabstring : pchar;
  2350. var
  2351. nss : pchar;
  2352. i : word;
  2353. param : pdefcoll;
  2354. begin
  2355. i := 0;
  2356. param := para1;
  2357. while assigned(param) do
  2358. begin
  2359. inc(i);
  2360. param := param^.next;
  2361. end;
  2362. getmem(nss,1024);
  2363. { it is not a function but a function pointer !! (PM) }
  2364. strpcopy(nss,'*f'+retdef^.numberstring{+','+tostr(i)}+';');
  2365. param := para1;
  2366. i := 0;
  2367. { this confuses gdb !!
  2368. we should use 'F' instead of 'f' but
  2369. as we use c++ language mode
  2370. it does not like that either
  2371. Please do not remove this part
  2372. might be used once
  2373. gdb for pascal is ready PM }
  2374. (* while assigned(param) do
  2375. begin
  2376. inc(i);
  2377. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2378. {Here we have lost the parameter names !!}
  2379. pst := strpnew('p'+tostr(i)+':'+param^.data^.numberstring+','+vartyp+';');
  2380. strcat(nss,pst);
  2381. strdispose(pst);
  2382. param := param^.next;
  2383. end; *)
  2384. {strpcopy(strend(nss),';');}
  2385. stabstring := strnew(nss);
  2386. freemem(nss,1024);
  2387. end;
  2388. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  2389. begin
  2390. if ( not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2391. and not is_def_stab_written then
  2392. inherited concatstabto(asmlist);
  2393. is_def_stab_written:=true;
  2394. end;
  2395. {$endif GDB}
  2396. procedure Tprocvardef.write_rtti_data;
  2397. begin
  2398. {!!!!!!!}
  2399. end;
  2400. procedure Tprocvardef.write_child_rtti_data;
  2401. begin
  2402. {!!!!!!!!}
  2403. end;
  2404. function Tprocvardef.is_publishable:boolean;
  2405. begin
  2406. is_publishable:=pomethodpointer in options;
  2407. end;
  2408. function Tprocvardef.gettypename:string;
  2409. begin
  2410. gettypename:='<procedure variable type>'
  2411. end;
  2412. {****************************************************************************
  2413. Tforwarddef
  2414. ****************************************************************************}
  2415. constructor tforwarddef.init(Aowner:Pcontainingsymtable;
  2416. const s:string;const pos:Tfileposinfo);
  2417. var oldregisterdef:boolean;
  2418. begin
  2419. { never register the forwarddefs, they are disposed at the
  2420. end of the type declaration block }
  2421. { oldregisterdef:=registerdef;
  2422. registerdef:=false;}
  2423. inherited init(Aowner);
  2424. {$IFDEF TP}setparent(typeof(Tdef));{$ENDIF}
  2425. { registerdef:=oldregisterdef;}
  2426. tosymname:=s;
  2427. forwardpos:=pos;
  2428. end;
  2429. function tforwarddef.gettypename:string;
  2430. begin
  2431. gettypename:='unresolved forward to '+tosymname;
  2432. end;
  2433. end.
  2434. {
  2435. $Log$
  2436. Revision 1.5 2000-03-11 21:11:24 daniel
  2437. * Ported hcgdata to new symtable.
  2438. * Alignment code changed as suggested by Peter
  2439. + Usage of my is operator replacement, is_object
  2440. Revision 1.4 2000/03/01 11:43:55 daniel
  2441. * Some more work on the new symtable.
  2442. + Symtable stack unit 'symstack' added.
  2443. }