defs.pas 81 KB

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