symdef.inc 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl, Pierre Muller
  4. Symbol table implementation for the definitions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. {****************************************************************************
  19. TDEF (base class for definitions)
  20. ****************************************************************************}
  21. const
  22. { if you change one of the following contants, }
  23. { you have also to change the typinfo unit }
  24. tkUnknown = 0;
  25. tkInteger = 1;
  26. tkChar = 2;
  27. tkEnumeration = 3;
  28. tkFloat = 4;
  29. tkSet = 6;
  30. tkMethod = 7;
  31. tkSString = 8;
  32. tkString = tkSString;
  33. tkLString = 9;
  34. tkAString = 10;
  35. tkWString = 11;
  36. tkVariant = 12;
  37. tkArray = 13;
  38. tkRecord = 14;
  39. tkInterface = 15;
  40. tkClass = 16;
  41. tkObject = 17;
  42. tkWChar = 18;
  43. tkBool = 19;
  44. otSByte = 0;
  45. otUByte = 1;
  46. otSWord = 2;
  47. otUWord = 3;
  48. otSLong = 4;
  49. otULong = 5;
  50. ftSingle = 0;
  51. ftDouble = 1;
  52. ftExtended = 2;
  53. ftComp = 3;
  54. ftCurr = 4;
  55. ftFixed16 = 5;
  56. ftFixed32 = 6;
  57. constructor tdef.init;
  58. begin
  59. deftype:=abstractdef;
  60. owner := nil;
  61. next := nil;
  62. sym := nil;
  63. indexnb := 0;
  64. if registerdef then
  65. symtablestack^.registerdef(@self);
  66. has_rtti:=false;
  67. has_inittable:=false;
  68. {$ifdef GDB}
  69. is_def_stab_written := false;
  70. globalnb := 0;
  71. if assigned(lastglobaldef) then
  72. begin
  73. lastglobaldef^.nextglobal := @self;
  74. previousglobal:=lastglobaldef;
  75. end
  76. else
  77. begin
  78. firstglobaldef := @self;
  79. previousglobal := nil;
  80. end;
  81. lastglobaldef := @self;
  82. nextglobal := nil;
  83. {$endif GDB}
  84. end;
  85. constructor tdef.load;
  86. begin
  87. deftype:=abstractdef;
  88. indexnb := 0;
  89. sym := nil;
  90. owner := nil;
  91. next := nil;
  92. has_rtti:=false;
  93. has_inittable:=false;
  94. {$ifdef GDB}
  95. is_def_stab_written := false;
  96. globalnb := 0;
  97. if assigned(lastglobaldef) then
  98. begin
  99. lastglobaldef^.nextglobal := @self;
  100. previousglobal:=lastglobaldef;
  101. end
  102. else
  103. begin
  104. firstglobaldef := @self;
  105. previousglobal:=nil;
  106. end;
  107. lastglobaldef := @self;
  108. nextglobal := nil;
  109. {$endif GDB}
  110. end;
  111. destructor tdef.done;
  112. begin
  113. {$ifdef GDB}
  114. { first element ? }
  115. if not(assigned(previousglobal)) then
  116. begin
  117. firstglobaldef := nextglobal;
  118. if assigned(firstglobaldef) then
  119. firstglobaldef^.previousglobal:=nil;
  120. end
  121. else
  122. begin
  123. { remove reference in the element before }
  124. previousglobal^.nextglobal:=nextglobal;
  125. end;
  126. { last element ? }
  127. if not(assigned(nextglobal)) then
  128. begin
  129. lastglobaldef := previousglobal;
  130. if assigned(lastglobaldef) then
  131. lastglobaldef^.nextglobal:=nil;
  132. end
  133. else
  134. nextglobal^.previousglobal:=previousglobal;
  135. previousglobal:=nil;
  136. nextglobal:=nil;
  137. {$endif GDB}
  138. end;
  139. procedure tdef.write;
  140. begin
  141. {$ifdef GDB}
  142. if globalnb = 0 then
  143. begin
  144. if assigned(owner) then
  145. globalnb := owner^.getnewtypecount
  146. else
  147. begin
  148. globalnb := PGlobalTypeCount^;
  149. Inc(PGlobalTypeCount^);
  150. end;
  151. end;
  152. {$endif GDB}
  153. end;
  154. function tdef.size : longint;
  155. begin
  156. size:=savesize;
  157. end;
  158. {$ifdef GDB}
  159. procedure tdef.set_globalnb;
  160. begin
  161. globalnb :=PGlobalTypeCount^;
  162. inc(PglobalTypeCount^);
  163. end;
  164. function tdef.stabstring : pchar;
  165. begin
  166. stabstring := strpnew('t'+numberstring+';');
  167. end;
  168. function tdef.numberstring : string;
  169. var table : psymtable;
  170. begin
  171. {formal def have no type !}
  172. if deftype = formaldef then
  173. begin
  174. numberstring := voiddef^.numberstring;
  175. exit;
  176. end;
  177. if (not assigned(sym)) or (not sym^.isusedinstab) then
  178. begin
  179. {set even if debuglist is not defined}
  180. if assigned(sym) then
  181. sym^.isusedinstab := true;
  182. if assigned(debuglist) and not is_def_stab_written then
  183. concatstabto(debuglist);
  184. end;
  185. if not use_dbx then
  186. begin
  187. if globalnb = 0 then
  188. set_globalnb;
  189. numberstring := tostr(globalnb);
  190. end
  191. else
  192. begin
  193. if globalnb = 0 then
  194. begin
  195. if assigned(owner) then
  196. globalnb := owner^.getnewtypecount
  197. else
  198. begin
  199. globalnb := PGlobalTypeCount^;
  200. Inc(PGlobalTypeCount^);
  201. end;
  202. end;
  203. if assigned(sym) then
  204. begin
  205. table := sym^.owner;
  206. if table^.unitid > 0 then
  207. numberstring := '('+tostr(table^.unitid)+','
  208. +tostr(sym^.definition^.globalnb)+')'
  209. else
  210. numberstring := tostr(globalnb);
  211. exit;
  212. end;
  213. numberstring := tostr(globalnb);
  214. end;
  215. end;
  216. function tdef.allstabstring : pchar;
  217. var stabchar : string[2];
  218. ss,st : pchar;
  219. name : string;
  220. sym_line_no : longint;
  221. begin
  222. ss := stabstring;
  223. getmem(st,strlen(ss)+512);
  224. stabchar := 't';
  225. if deftype in tagtypes then
  226. stabchar := 'Tt';
  227. if assigned(sym) then
  228. begin
  229. name := sym^.name;
  230. sym_line_no:=sym^.fileinfo.line;
  231. end
  232. else
  233. begin
  234. name := ' ';
  235. sym_line_no:=0;
  236. end;
  237. strpcopy(st,'"'+name+':'+stabchar+numberstring+'=');
  238. strpcopy(strecopy(strend(st),ss),'",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0');
  239. allstabstring := strnew(st);
  240. freemem(st,strlen(ss)+512);
  241. strdispose(ss);
  242. end;
  243. procedure tdef.concatstabto(asmlist : paasmoutput);
  244. var stab_str : pchar;
  245. begin
  246. if ((sym = nil) or sym^.isusedinstab or use_dbx)
  247. and not is_def_stab_written then
  248. begin
  249. If use_dbx then
  250. begin
  251. { otherwise you get two of each def }
  252. If assigned(sym) then
  253. begin
  254. if sym^.typ=typesym then
  255. sym^.isusedinstab:=true;
  256. if (sym^.owner = nil) or
  257. ((sym^.owner^.symtabletype = unitsymtable) and
  258. punitsymtable(sym^.owner)^.dbx_count_ok) then
  259. begin
  260. {with DBX we get the definition from the other objects }
  261. is_def_stab_written := true;
  262. exit;
  263. end;
  264. end;
  265. end;
  266. { to avoid infinite loops }
  267. is_def_stab_written := true;
  268. stab_str := allstabstring;
  269. if asmlist = debuglist then do_count_dbx := true;
  270. { count_dbx(stab_str); moved to GDB.PAS}
  271. asmlist^.concat(new(pai_stabs,init(stab_str)));
  272. end;
  273. end;
  274. {$endif GDB}
  275. procedure tdef.deref;
  276. begin
  277. end;
  278. { rtti generation }
  279. procedure tdef.generate_rtti;
  280. begin
  281. has_rtti:=true;
  282. getlabel(rtti_label);
  283. write_child_rtti_data;
  284. rttilist^.concat(new(pai_label,init(rtti_label)));
  285. write_rtti_data;
  286. end;
  287. function tdef.get_rtti_label : plabel;
  288. begin
  289. if not(has_rtti) then
  290. generate_rtti;
  291. get_rtti_label:=rtti_label;
  292. end;
  293. { init table handling }
  294. function tdef.needs_inittable : boolean;
  295. begin
  296. needs_inittable:=false;
  297. end;
  298. procedure tdef.generate_inittable;
  299. begin
  300. has_inittable:=true;
  301. getlabel(inittable_label);
  302. write_child_init_data;
  303. rttilist^.concat(new(pai_label,init(inittable_label)));
  304. write_init_data;
  305. end;
  306. procedure tdef.write_init_data;
  307. begin
  308. write_rtti_data;
  309. end;
  310. procedure tdef.write_child_init_data;
  311. begin
  312. write_child_rtti_data;
  313. end;
  314. function tdef.get_inittable_label : plabel;
  315. begin
  316. if not(has_inittable) then
  317. generate_inittable;
  318. get_inittable_label:=inittable_label;
  319. end;
  320. procedure tdef.writename;
  321. var
  322. str : string;
  323. begin
  324. { name }
  325. if assigned(sym) then
  326. begin
  327. str:=sym^.name;
  328. rttilist^.concat(new(pai_string,init(chr(length(str))+str)));
  329. end
  330. else
  331. rttilist^.concat(new(pai_string,init(#0)))
  332. end;
  333. { returns true, if the definition can be published }
  334. function tdef.is_publishable : boolean;
  335. begin
  336. is_publishable:=false;
  337. end;
  338. procedure tdef.write_rtti_data;
  339. begin
  340. end;
  341. procedure tdef.write_child_rtti_data;
  342. begin
  343. end;
  344. {****************************************************************************
  345. TSTRINGDEF
  346. ****************************************************************************}
  347. constructor tstringdef.init(l : byte);
  348. begin
  349. tdef.init;
  350. string_typ:=st_shortstring;
  351. deftype:=stringdef;
  352. len:=l;
  353. savesize:=len+1;
  354. end;
  355. constructor tstringdef.load;
  356. begin
  357. tdef.load;
  358. string_typ:=st_shortstring;
  359. deftype:=stringdef;
  360. len:=readbyte;
  361. savesize:=len+1;
  362. end;
  363. constructor tstringdef.longinit(l : longint);
  364. begin
  365. tdef.init;
  366. string_typ:=st_longstring;
  367. deftype:=stringdef;
  368. len:=l;
  369. savesize:=Sizeof(pointer);
  370. end;
  371. constructor tstringdef.longload;
  372. begin
  373. tdef.load;
  374. deftype:=stringdef;
  375. string_typ:=st_longstring;
  376. len:=readlong;
  377. savesize:=Sizeof(pointer);
  378. end;
  379. constructor tstringdef.ansiinit(l : longint);
  380. begin
  381. tdef.init;
  382. string_typ:=st_ansistring;
  383. deftype:=stringdef;
  384. len:=l;
  385. savesize:=sizeof(pointer);
  386. end;
  387. constructor tstringdef.ansiload;
  388. begin
  389. tdef.load;
  390. deftype:=stringdef;
  391. string_typ:=st_ansistring;
  392. len:=readlong;
  393. savesize:=sizeof(pointer);
  394. end;
  395. constructor tstringdef.wideinit(l : longint);
  396. begin
  397. tdef.init;
  398. string_typ:=st_widestring;
  399. deftype:=stringdef;
  400. len:=l;
  401. savesize:=sizeof(pointer);
  402. end;
  403. constructor tstringdef.wideload;
  404. begin
  405. tdef.load;
  406. deftype:=stringdef;
  407. string_typ:=st_widestring;
  408. len:=readlong;
  409. savesize:=sizeof(pointer);
  410. end;
  411. function tstringdef.size : longint;
  412. begin
  413. size:=savesize;
  414. end;
  415. procedure tstringdef.write;
  416. begin
  417. tdef.write;
  418. if string_typ=st_shortstring then
  419. writebyte(len)
  420. else
  421. writelong(len);
  422. case string_typ of
  423. st_shortstring : current_ppu^.writeentry(ibstringdef);
  424. st_longstring : current_ppu^.writeentry(iblongstringdef);
  425. st_ansistring : current_ppu^.writeentry(ibansistringdef);
  426. st_widestring : current_ppu^.writeentry(ibwidestringdef);
  427. end;
  428. end;
  429. {$ifdef GDB}
  430. function tstringdef.stabstring : pchar;
  431. var
  432. bytest,charst,longst : string;
  433. begin
  434. case string_typ of
  435. st_shortstring:
  436. begin
  437. charst := typeglobalnumber('char');
  438. { this is what I found in stabs.texinfo but
  439. gdb 4.12 for go32 doesn't understand that !! }
  440. {$IfDef GDBknowsstrings}
  441. stabstring := strpnew('n'+charst+';'+tostr(len));
  442. {$else}
  443. bytest := typeglobalnumber('byte');
  444. stabstring := strpnew('s'+tostr(len+1)+'length:'+bytest
  445. +',0,8;st:ar'+bytest
  446. +';1;'+tostr(len)+';'+charst+',8,'+tostr(len*8)+';;');
  447. {$EndIf}
  448. end;
  449. st_longstring:
  450. begin
  451. charst := typeglobalnumber('char');
  452. { this is what I found in stabs.texinfo but
  453. gdb 4.12 for go32 doesn't understand that !! }
  454. {$IfDef GDBknowsstrings}
  455. stabstring := strpnew('n'+charst+';'+tostr(len));
  456. {$else}
  457. bytest := typeglobalnumber('byte');
  458. longst := typeglobalnumber('longint');
  459. stabstring := strpnew('s'+tostr(len+5)+'length:'+longst
  460. +',0,32;dummy:'+bytest+',32,8;st:ar'+bytest
  461. +';1;'+tostr(len)+';'+charst+',40,'+tostr(len*8)+';;');
  462. {$EndIf}
  463. end;
  464. st_ansistring:
  465. begin
  466. { an ansi string looks like a pchar easy !! }
  467. stabstring:=strpnew('*'+typeglobalnumber('char'));
  468. end;
  469. st_widestring:
  470. begin
  471. { an ansi string looks like a pchar easy !! }
  472. stabstring:=strpnew('*'+typeglobalnumber('char'));
  473. end;
  474. end;
  475. end;
  476. procedure tstringdef.concatstabto(asmlist : paasmoutput);
  477. begin
  478. inherited concatstabto(asmlist);
  479. end;
  480. {$endif GDB}
  481. function tstringdef.needs_inittable : boolean;
  482. begin
  483. needs_inittable:=string_typ in [st_ansistring,st_widestring];
  484. end;
  485. procedure tstringdef.write_rtti_data;
  486. begin
  487. case string_typ of
  488. st_ansistring:
  489. begin
  490. rttilist^.concat(new(pai_const,init_8bit(tkAString)));
  491. end;
  492. st_widestring:
  493. begin
  494. rttilist^.concat(new(pai_const,init_8bit(tkWString)));
  495. end;
  496. st_longstring:
  497. begin
  498. rttilist^.concat(new(pai_const,init_8bit(tkLString)));
  499. end;
  500. st_shortstring:
  501. begin
  502. rttilist^.concat(new(pai_const,init_8bit(tkSString)));
  503. rttilist^.concat(new(pai_const,init_8bit(len)));
  504. end;
  505. end;
  506. end;
  507. function tstringdef.is_publishable : boolean;
  508. begin
  509. is_publishable:=true;
  510. end;
  511. {****************************************************************************
  512. TENUMDEF
  513. ****************************************************************************}
  514. constructor tenumdef.init;
  515. begin
  516. tdef.init;
  517. deftype:=enumdef;
  518. minval:=0;
  519. maxval:=0;
  520. calcsavesize;
  521. has_jumps:=false;
  522. basedef:=nil;
  523. rangenr:=0;
  524. first:=nil;
  525. end;
  526. constructor tenumdef.init_subrange(_basedef:penumdef;_min,_max:longint);
  527. begin
  528. tdef.init;
  529. deftype:=enumdef;
  530. minval:=_min;
  531. maxval:=_max;
  532. basedef:=_basedef;
  533. calcsavesize;
  534. has_jumps:=false;
  535. rangenr:=0;
  536. first:=nil;
  537. end;
  538. constructor tenumdef.load;
  539. begin
  540. tdef.load;
  541. deftype:=enumdef;
  542. basedef:=penumdef(readdefref);
  543. minval:=readlong;
  544. maxval:=readlong;
  545. savesize:=readlong;
  546. has_jumps:=false;
  547. first:=Nil;
  548. end;
  549. procedure tenumdef.calcsavesize;
  550. begin
  551. if (aktpackenum=4) or (min<0) or (max>65535) then
  552. savesize:=4
  553. else
  554. if (aktpackenum=2) or (min<0) or (max>255) then
  555. savesize:=2
  556. else
  557. savesize:=1;
  558. end;
  559. procedure tenumdef.setmax(_max:longint);
  560. begin
  561. maxval:=_max;
  562. calcsavesize;
  563. end;
  564. procedure tenumdef.setmin(_min:longint);
  565. begin
  566. minval:=_min;
  567. calcsavesize;
  568. end;
  569. function tenumdef.min:longint;
  570. begin
  571. min:=minval;
  572. end;
  573. function tenumdef.max:longint;
  574. begin
  575. max:=maxval;
  576. end;
  577. procedure tenumdef.deref;
  578. begin
  579. resolvedef(pdef(basedef));
  580. end;
  581. destructor tenumdef.done;
  582. begin
  583. inherited done;
  584. end;
  585. procedure tenumdef.write;
  586. begin
  587. tdef.write;
  588. writedefref(basedef);
  589. writelong(min);
  590. writelong(max);
  591. writelong(savesize);
  592. current_ppu^.writeentry(ibenumdef);
  593. end;
  594. function tenumdef.getrangecheckstring : string;
  595. begin
  596. if (cs_smartlink in aktmoduleswitches) then
  597. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  598. else
  599. getrangecheckstring:='R_'+tostr(rangenr);
  600. end;
  601. procedure tenumdef.genrangecheck;
  602. begin
  603. if rangenr=0 then
  604. begin
  605. { generate two constant for bounds }
  606. getlabelnr(rangenr);
  607. if (cs_smartlink in aktmoduleswitches) then
  608. datasegment^.concat(new(pai_symbol,init_global(getrangecheckstring)))
  609. else
  610. datasegment^.concat(new(pai_symbol,init(getrangecheckstring)));
  611. datasegment^.concat(new(pai_const,init_32bit(min)));
  612. datasegment^.concat(new(pai_const,init_32bit(max)));
  613. end;
  614. end;
  615. {$ifdef GDB}
  616. function tenumdef.stabstring : pchar;
  617. var st,st2 : pchar;
  618. p : penumsym;
  619. s : string;
  620. memsize : word;
  621. begin
  622. memsize := memsizeinc;
  623. getmem(st,memsize);
  624. strpcopy(st,'e');
  625. p := first;
  626. while assigned(p) do
  627. begin
  628. s :=p^.name+':'+tostr(p^.value)+',';
  629. { place for the ending ';' also }
  630. if (strlen(st)+length(s)+1<memsize) then
  631. strpcopy(strend(st),s)
  632. else
  633. begin
  634. getmem(st2,memsize+memsizeinc);
  635. strcopy(st2,st);
  636. freemem(st,memsize);
  637. st := st2;
  638. memsize := memsize+memsizeinc;
  639. strpcopy(strend(st),s);
  640. end;
  641. p := p^.next;
  642. end;
  643. strpcopy(strend(st),';');
  644. stabstring := strnew(st);
  645. freemem(st,memsize);
  646. end;
  647. {$endif GDB}
  648. procedure tenumdef.write_child_rtti_data;
  649. begin
  650. if assigned(basedef) then
  651. basedef^.get_rtti_label;
  652. end;
  653. procedure tenumdef.write_rtti_data;
  654. begin
  655. rttilist^.concat(new(pai_const,init_8bit(tkEnumeration)));
  656. case savesize of
  657. 1:
  658. rttilist^.concat(new(pai_const,init_8bit(otUByte)));
  659. 2:
  660. rttilist^.concat(new(pai_const,init_8bit(otUWord)));
  661. 4:
  662. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  663. end;
  664. rttilist^.concat(new(pai_const,init_32bit(min)));
  665. rttilist^.concat(new(pai_const,init_32bit(max)));
  666. if assigned(basedef) then
  667. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(basedef^.get_rtti_label)))))
  668. else
  669. rttilist^.concat(new(pai_const,init_32bit(0)));
  670. {!!!!!!! Name list }
  671. end;
  672. function tenumdef.is_publishable : boolean;
  673. begin
  674. is_publishable:=true;
  675. end;
  676. {****************************************************************************
  677. TORDDEF
  678. ****************************************************************************}
  679. constructor torddef.init(t : tbasetype;v,b : longint);
  680. begin
  681. inherited init;
  682. deftype:=orddef;
  683. low:=v;
  684. high:=b;
  685. typ:=t;
  686. rangenr:=0;
  687. setsize;
  688. end;
  689. constructor torddef.load;
  690. begin
  691. inherited load;
  692. deftype:=orddef;
  693. typ:=tbasetype(readbyte);
  694. low:=readlong;
  695. high:=readlong;
  696. rangenr:=0;
  697. setsize;
  698. end;
  699. procedure torddef.setsize;
  700. begin
  701. if typ=uauto then
  702. begin
  703. { generate a unsigned range if high<0 and low>=0 }
  704. if (low>=0) and (high<0) then
  705. begin
  706. savesize:=4;
  707. typ:=u32bit;
  708. end
  709. else if (low>=0) and (high<=255) then
  710. begin
  711. savesize:=1;
  712. typ:=u8bit;
  713. end
  714. else if (low>=-128) and (high<=127) then
  715. begin
  716. savesize:=1;
  717. typ:=s8bit;
  718. end
  719. else if (low>=0) and (high<=65536) then
  720. begin
  721. savesize:=2;
  722. typ:=u16bit;
  723. end
  724. else if (low>=-32768) and (high<=32767) then
  725. begin
  726. savesize:=2;
  727. typ:=s16bit;
  728. end
  729. else
  730. begin
  731. savesize:=4;
  732. typ:=s32bit;
  733. end;
  734. end
  735. else
  736. begin
  737. case typ of
  738. u8bit,s8bit,
  739. uchar,bool8bit : savesize:=1;
  740. u16bit,s16bit,
  741. bool16bit : savesize:=2;
  742. s32bit,u32bit,
  743. bool32bit : savesize:=4;
  744. else
  745. savesize:=0;
  746. end;
  747. end;
  748. { there are no entrys for range checking }
  749. rangenr:=0;
  750. end;
  751. function torddef.getrangecheckstring : string;
  752. begin
  753. if (cs_smartlink in aktmoduleswitches) then
  754. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  755. else
  756. getrangecheckstring:='R_'+tostr(rangenr);
  757. end;
  758. procedure torddef.genrangecheck;
  759. begin
  760. if rangenr=0 then
  761. begin
  762. { generate two constant for bounds }
  763. getlabelnr(rangenr);
  764. if (cs_smartlink in aktmoduleswitches) then
  765. datasegment^.concat(new(pai_symbol,init_global(getrangecheckstring)))
  766. else
  767. datasegment^.concat(new(pai_symbol,init(getrangecheckstring)));
  768. if low<=high then
  769. begin
  770. datasegment^.concat(new(pai_const,init_32bit(low)));
  771. datasegment^.concat(new(pai_const,init_32bit(high)));
  772. end
  773. { for u32bit we need two bounds }
  774. else
  775. begin
  776. datasegment^.concat(new(pai_const,init_32bit(low)));
  777. datasegment^.concat(new(pai_const,init_32bit($7fffffff)));
  778. inc(nextlabelnr);
  779. if (cs_smartlink in aktmoduleswitches) then
  780. datasegment^.concat(new(pai_symbol,init_global('R_'+current_module^.modulename^+tostr(rangenr+1))))
  781. else
  782. datasegment^.concat(new(pai_symbol,init('R_'+tostr(rangenr+1))));
  783. datasegment^.concat(new(pai_const,init_32bit($80000000)));
  784. datasegment^.concat(new(pai_const,init_32bit(high)));
  785. end;
  786. end;
  787. end;
  788. procedure torddef.write;
  789. begin
  790. tdef.write;
  791. writebyte(byte(typ));
  792. writelong(low);
  793. writelong(high);
  794. current_ppu^.writeentry(iborddef);
  795. end;
  796. {$ifdef GDB}
  797. function torddef.stabstring : pchar;
  798. begin
  799. case typ of
  800. uvoid : stabstring := strpnew(numberstring+';');
  801. {GDB 4.12 for go32 doesn't like boolean as range for 0 to 1 !!!}
  802. bool8bit,
  803. bool16bit,
  804. bool32bit : stabstring := strpnew('r'+numberstring+';0;255;');
  805. { u32bit : stabstring := strpnew('r'+
  806. s32bitdef^.numberstring+';0;-1;'); }
  807. else
  808. stabstring := strpnew('r'+s32bitdef^.numberstring+';'+tostr(low)+';'+tostr(high)+';');
  809. end;
  810. end;
  811. {$endif GDB}
  812. procedure torddef.write_rtti_data;
  813. const
  814. trans : array[uchar..bool8bit] of byte =
  815. (otUByte,otUByte,otUWord,otULong,otSByte,otSWord,otSLong,otUByte);
  816. begin
  817. case typ of
  818. bool8bit:
  819. rttilist^.concat(new(pai_const,init_8bit(tkBool)));
  820. uchar:
  821. rttilist^.concat(new(pai_const,init_8bit(tkChar)));
  822. else
  823. rttilist^.concat(new(pai_const,init_8bit(tkInteger)));
  824. end;
  825. rttilist^.concat(new(pai_const,init_8bit(byte(trans[typ]))));
  826. rttilist^.concat(new(pai_const,init_32bit(low)));
  827. rttilist^.concat(new(pai_const,init_32bit(high)));
  828. end;
  829. function torddef.is_publishable : boolean;
  830. begin
  831. is_publishable:=typ in [uchar..bool8bit];
  832. end;
  833. {****************************************************************************
  834. TFLOATDEF
  835. ****************************************************************************}
  836. constructor tfloatdef.init(t : tfloattype);
  837. begin
  838. inherited init;
  839. deftype:=floatdef;
  840. typ:=t;
  841. setsize;
  842. end;
  843. constructor tfloatdef.load;
  844. begin
  845. inherited load;
  846. deftype:=floatdef;
  847. typ:=tfloattype(readbyte);
  848. setsize;
  849. end;
  850. procedure tfloatdef.setsize;
  851. begin
  852. case typ of
  853. f16bit : savesize:=2;
  854. f32bit,
  855. s32real : savesize:=4;
  856. s64real : savesize:=8;
  857. s64bit : savesize:=8;
  858. s80real : savesize:=extended_size;
  859. else
  860. savesize:=0;
  861. end;
  862. end;
  863. procedure tfloatdef.write;
  864. begin
  865. inherited write;
  866. writebyte(byte(typ));
  867. current_ppu^.writeentry(ibfloatdef);
  868. end;
  869. {$ifdef GDB}
  870. function tfloatdef.stabstring : pchar;
  871. begin
  872. case typ of
  873. s32real,
  874. s64real : stabstring := strpnew('r'+
  875. s32bitdef^.numberstring+';'+tostr(savesize)+';0;');
  876. { for fixed real use longint instead to be able to }
  877. { debug something at least }
  878. f32bit:
  879. stabstring := s32bitdef^.stabstring;
  880. f16bit:
  881. stabstring := strpnew('r'+s32bitdef^.numberstring+';0;'+
  882. tostr($ffff)+';');
  883. { found this solution in stabsread.c from GDB v4.16 }
  884. s64bit : stabstring := strpnew('r'+
  885. s32bitdef^.numberstring+';-'+tostr(savesize)+';0;');
  886. {$ifdef i386}
  887. { under dos at least you must give a size of twelve instead of 10 !! }
  888. { this is probably do to the fact that in gcc all is pushed in 4 bytes size }
  889. s80real : stabstring := strpnew('r'+s32bitdef^.numberstring+';12;0;');
  890. {$endif i386}
  891. else
  892. internalerror(10005);
  893. end;
  894. end;
  895. {$endif GDB}
  896. procedure tfloatdef.write_rtti_data;
  897. const
  898. translate : array[tfloattype] of byte =
  899. (ftFixed32,ftSingle,ftDouble,ftExtended,ftComp,ftFixed16);
  900. begin
  901. rttilist^.concat(new(pai_const,init_8bit(tkFloat)));
  902. rttilist^.concat(new(pai_const,init_8bit(translate[typ])));
  903. end;
  904. function tfloatdef.is_publishable : boolean;
  905. begin
  906. is_publishable:=true;
  907. end;
  908. {****************************************************************************
  909. TFILEDEF
  910. ****************************************************************************}
  911. constructor tfiledef.init(ft : tfiletype;tas : pdef);
  912. begin
  913. inherited init;
  914. deftype:=filedef;
  915. filetype:=ft;
  916. typed_as:=tas;
  917. setsize;
  918. end;
  919. constructor tfiledef.load;
  920. begin
  921. inherited load;
  922. deftype:=filedef;
  923. filetype:=tfiletype(readbyte);
  924. if filetype=ft_typed then
  925. typed_as:=readdefref
  926. else
  927. typed_as:=nil;
  928. setsize;
  929. end;
  930. procedure tfiledef.deref;
  931. begin
  932. if filetype=ft_typed then
  933. resolvedef(typed_as);
  934. end;
  935. procedure tfiledef.setsize;
  936. begin
  937. case filetype of
  938. ft_text : savesize:=572;
  939. ft_typed,
  940. ft_untyped : savesize:=316;
  941. end;
  942. end;
  943. procedure tfiledef.write;
  944. begin
  945. inherited write;
  946. writebyte(byte(filetype));
  947. if filetype=ft_typed then
  948. writedefref(typed_as);
  949. current_ppu^.writeentry(ibfiledef);
  950. end;
  951. {$ifdef GDB}
  952. function tfiledef.stabstring : pchar;
  953. begin
  954. {$IfDef GDBknowsfiles}
  955. case filetyp of
  956. ft_typed : stabstring := strpnew('d'+typed_as^.numberstring{+';'});
  957. ft_untyped : stabstring := strpnew('d'+voiddef^.numberstring{+';'});
  958. ft_text : stabstring := strpnew('d'+cchardef^.numberstring{+';'});
  959. end;
  960. {$Else}
  961. {based on
  962. FileRec = Packed Record
  963. Handle,
  964. Mode,
  965. RecSize : longint;
  966. _private : array[1..32] of byte;
  967. UserData : array[1..16] of byte;
  968. name : array[0..255] of char;
  969. End; }
  970. { the buffer part is still missing !! (PM) }
  971. { but the string could become too long !! }
  972. stabstring := strpnew('s'+tostr(savesize)+
  973. 'HANDLE:'+typeglobalnumber('longint')+',0,32;'+
  974. 'MODE:'+typeglobalnumber('longint')+',32,32;'+
  975. 'RECSIZE:'+typeglobalnumber('longint')+',64,32;'+
  976. '_PRIVATE:ar'+typeglobalnumber('word')+';1;32;'+typeglobalnumber('byte')
  977. +',96,256;'+
  978. 'USERDATA:ar'+typeglobalnumber('word')+';1;16;'+typeglobalnumber('byte')
  979. +',352,128;'+
  980. 'NAME:ar'+typeglobalnumber('word')+';0;255;'+typeglobalnumber('char')
  981. +',480,2048;;');
  982. {$EndIf}
  983. end;
  984. procedure tfiledef.concatstabto(asmlist : paasmoutput);
  985. begin
  986. { most file defs are unnamed !!! }
  987. if ((sym = nil) or sym^.isusedinstab or use_dbx) and not is_def_stab_written then
  988. begin
  989. if assigned(typed_as) then forcestabto(asmlist,typed_as);
  990. inherited concatstabto(asmlist);
  991. end;
  992. end;
  993. {$endif GDB}
  994. {****************************************************************************
  995. TPOINTERDEF
  996. ****************************************************************************}
  997. constructor tpointerdef.init(def : pdef);
  998. begin
  999. inherited init;
  1000. deftype:=pointerdef;
  1001. definition:=def;
  1002. savesize:=Sizeof(pointer);
  1003. end;
  1004. constructor tpointerdef.load;
  1005. begin
  1006. inherited load;
  1007. deftype:=pointerdef;
  1008. { the real address in memory is calculated later (deref) }
  1009. definition:=readdefref;
  1010. savesize:=Sizeof(pointer);
  1011. end;
  1012. procedure tpointerdef.deref;
  1013. begin
  1014. resolvedef(definition);
  1015. end;
  1016. procedure tpointerdef.write;
  1017. begin
  1018. inherited write;
  1019. writedefref(definition);
  1020. current_ppu^.writeentry(ibpointerdef);
  1021. end;
  1022. {$ifdef GDB}
  1023. function tpointerdef.stabstring : pchar;
  1024. begin
  1025. stabstring := strpnew('*'+definition^.numberstring);
  1026. end;
  1027. procedure tpointerdef.concatstabto(asmlist : paasmoutput);
  1028. var st,nb : string;
  1029. sym_line_no : longint;
  1030. begin
  1031. if ( (sym=nil) or sym^.isusedinstab or use_dbx) and not is_def_stab_written then
  1032. begin
  1033. if assigned(definition) then
  1034. if definition^.deftype in [recorddef,objectdef] then
  1035. begin
  1036. is_def_stab_written := true;
  1037. {to avoid infinite recursion in record with next-like fields }
  1038. nb := definition^.numberstring;
  1039. is_def_stab_written := false;
  1040. if not definition^.is_def_stab_written then
  1041. begin
  1042. if assigned(definition^.sym) then
  1043. begin
  1044. if assigned(sym) then
  1045. begin
  1046. st := sym^.name;
  1047. sym_line_no:=sym^.fileinfo.line;
  1048. end
  1049. else
  1050. begin
  1051. st := ' ';
  1052. sym_line_no:=0;
  1053. end;
  1054. st := '"'+st+':t'+numberstring+'=*'+definition^.numberstring
  1055. +'=xs'+definition^.sym^.name+':",'+tostr(N_LSYM)+',0,'+tostr(sym_line_no)+',0';
  1056. if asmlist = debuglist then do_count_dbx := true;
  1057. asmlist^.concat(new(pai_stabs,init(strpnew(st))));
  1058. end;
  1059. end else inherited concatstabto(asmlist);
  1060. is_def_stab_written := true;
  1061. end else
  1062. begin
  1063. forcestabto(asmlist,definition);
  1064. inherited concatstabto(asmlist);
  1065. end;
  1066. end;
  1067. end;
  1068. {$endif GDB}
  1069. {****************************************************************************
  1070. TCLASSREFDEF
  1071. ****************************************************************************}
  1072. constructor tclassrefdef.init(def : pdef);
  1073. begin
  1074. inherited init(def);
  1075. deftype:=classrefdef;
  1076. definition:=def;
  1077. savesize:=Sizeof(pointer);
  1078. end;
  1079. constructor tclassrefdef.load;
  1080. begin
  1081. inherited load;
  1082. deftype:=classrefdef;
  1083. end;
  1084. procedure tclassrefdef.write;
  1085. begin
  1086. { be careful, tclassdefref inherits from tpointerdef }
  1087. tdef.write;
  1088. writedefref(definition);
  1089. current_ppu^.writeentry(ibclassrefdef);
  1090. end;
  1091. {$ifdef GDB}
  1092. function tclassrefdef.stabstring : pchar;
  1093. begin
  1094. stabstring:=strpnew('');
  1095. end;
  1096. procedure tclassrefdef.concatstabto(asmlist : paasmoutput);
  1097. begin
  1098. end;
  1099. {$endif GDB}
  1100. {***************************************************************************
  1101. TSETDEF
  1102. ***************************************************************************}
  1103. constructor tsetdef.init(s : pdef;high : longint);
  1104. begin
  1105. inherited init;
  1106. deftype:=setdef;
  1107. setof:=s;
  1108. if high<32 then
  1109. begin
  1110. settype:=smallset;
  1111. savesize:=Sizeof(longint);
  1112. end
  1113. else
  1114. if high<256 then
  1115. begin
  1116. settype:=normset;
  1117. savesize:=32;
  1118. end
  1119. else
  1120. {$ifdef testvarsets}
  1121. if high<$10000 then
  1122. begin
  1123. settype:=varset;
  1124. savesize:=4*((high+31) div 32);
  1125. end
  1126. else
  1127. {$endif testvarsets}
  1128. Message(sym_e_ill_type_decl_set);
  1129. end;
  1130. constructor tsetdef.load;
  1131. begin
  1132. inherited load;
  1133. deftype:=setdef;
  1134. setof:=readdefref;
  1135. settype:=tsettype(readbyte);
  1136. case settype of
  1137. normset : savesize:=32;
  1138. varset : savesize:=readlong;
  1139. smallset : savesize:=Sizeof(longint);
  1140. end;
  1141. end;
  1142. procedure tsetdef.write;
  1143. begin
  1144. inherited write;
  1145. writedefref(setof);
  1146. writebyte(byte(settype));
  1147. if settype=varset then
  1148. writelong(savesize);
  1149. current_ppu^.writeentry(ibsetdef);
  1150. end;
  1151. {$ifdef GDB}
  1152. function tsetdef.stabstring : pchar;
  1153. begin
  1154. stabstring := strpnew('S'+setof^.numberstring);
  1155. end;
  1156. procedure tsetdef.concatstabto(asmlist : paasmoutput);
  1157. begin
  1158. if ( not assigned(sym) or sym^.isusedinstab or use_dbx) and
  1159. not is_def_stab_written then
  1160. begin
  1161. if assigned(setof) then
  1162. forcestabto(asmlist,setof);
  1163. inherited concatstabto(asmlist);
  1164. end;
  1165. end;
  1166. {$endif GDB}
  1167. procedure tsetdef.deref;
  1168. begin
  1169. resolvedef(setof);
  1170. end;
  1171. procedure tsetdef.write_rtti_data;
  1172. begin
  1173. rttilist^.concat(new(pai_const,init_8bit(tkSet)));
  1174. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  1175. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(setof^.get_rtti_label)))));
  1176. end;
  1177. procedure tsetdef.write_child_rtti_data;
  1178. begin
  1179. setof^.get_rtti_label;
  1180. end;
  1181. function tsetdef.is_publishable : boolean;
  1182. begin
  1183. is_publishable:=settype=smallset;
  1184. end;
  1185. {***************************************************************************
  1186. TFORMALDEF
  1187. ***************************************************************************}
  1188. constructor tformaldef.init;
  1189. begin
  1190. inherited init;
  1191. deftype:=formaldef;
  1192. savesize:=Sizeof(pointer);
  1193. end;
  1194. constructor tformaldef.load;
  1195. begin
  1196. inherited load;
  1197. deftype:=formaldef;
  1198. savesize:=Sizeof(pointer);
  1199. end;
  1200. procedure tformaldef.write;
  1201. begin
  1202. inherited write;
  1203. current_ppu^.writeentry(ibformaldef);
  1204. end;
  1205. {$ifdef GDB}
  1206. function tformaldef.stabstring : pchar;
  1207. begin
  1208. stabstring := strpnew('formal'+numberstring+';');
  1209. end;
  1210. procedure tformaldef.concatstabto(asmlist : paasmoutput);
  1211. begin
  1212. { formaldef can't be stab'ed !}
  1213. end;
  1214. {$endif GDB}
  1215. {***************************************************************************
  1216. TARRAYDEF
  1217. ***************************************************************************}
  1218. constructor tarraydef.init(l,h : longint;rd : pdef);
  1219. begin
  1220. inherited init;
  1221. deftype:=arraydef;
  1222. lowrange:=l;
  1223. highrange:=h;
  1224. rangedef:=rd;
  1225. definition:=nil;
  1226. IsVariant:=false;
  1227. IsConstructor:=false;
  1228. IsArrayOfConst:=false;
  1229. rangenr:=0;
  1230. end;
  1231. constructor tarraydef.load;
  1232. begin
  1233. inherited load;
  1234. deftype:=arraydef;
  1235. { the addresses are calculated later }
  1236. definition:=readdefref;
  1237. rangedef:=readdefref;
  1238. lowrange:=readlong;
  1239. highrange:=readlong;
  1240. IsArrayOfConst:=boolean(readbyte);
  1241. IsVariant:=false;
  1242. IsConstructor:=false;
  1243. rangenr:=0;
  1244. end;
  1245. function tarraydef.getrangecheckstring : string;
  1246. begin
  1247. if (cs_smartlink in aktmoduleswitches) then
  1248. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1249. else
  1250. getrangecheckstring:='R_'+tostr(rangenr);
  1251. end;
  1252. procedure tarraydef.genrangecheck;
  1253. begin
  1254. if rangenr=0 then
  1255. begin
  1256. { generates the data for range checking }
  1257. getlabelnr(rangenr);
  1258. if (cs_smartlink in aktmoduleswitches) then
  1259. datasegment^.concat(new(pai_symbol,init_global(getrangecheckstring)))
  1260. else
  1261. datasegment^.concat(new(pai_symbol,init(getrangecheckstring)));
  1262. datasegment^.concat(new(pai_const,init_32bit(lowrange)));
  1263. datasegment^.concat(new(pai_const,init_32bit(highrange)));
  1264. end;
  1265. end;
  1266. procedure tarraydef.deref;
  1267. begin
  1268. resolvedef(definition);
  1269. resolvedef(rangedef);
  1270. end;
  1271. procedure tarraydef.write;
  1272. begin
  1273. inherited write;
  1274. writedefref(definition);
  1275. writedefref(rangedef);
  1276. writelong(lowrange);
  1277. writelong(highrange);
  1278. writebyte(byte(IsArrayOfConst));
  1279. current_ppu^.writeentry(ibarraydef);
  1280. end;
  1281. {$ifdef GDB}
  1282. function tarraydef.stabstring : pchar;
  1283. begin
  1284. stabstring := strpnew('ar'+rangedef^.numberstring+';'
  1285. +tostr(lowrange)+';'+tostr(highrange)+';'+definition^.numberstring);
  1286. end;
  1287. procedure tarraydef.concatstabto(asmlist : paasmoutput);
  1288. begin
  1289. if (not assigned(sym) or sym^.isusedinstab or use_dbx)
  1290. and not is_def_stab_written then
  1291. begin
  1292. {when array are inserted they have no definition yet !!}
  1293. if assigned(definition) then
  1294. inherited concatstabto(asmlist);
  1295. end;
  1296. end;
  1297. {$endif GDB}
  1298. function tarraydef.elesize : longint;
  1299. begin
  1300. elesize:=definition^.size;
  1301. end;
  1302. function tarraydef.size : longint;
  1303. begin
  1304. size:=(highrange-lowrange+1)*elesize;
  1305. end;
  1306. function tarraydef.needs_inittable : boolean;
  1307. begin
  1308. needs_inittable:=definition^.needs_inittable;
  1309. end;
  1310. procedure tarraydef.write_child_rtti_table;
  1311. begin
  1312. definition^.get_rtti_label;
  1313. end;
  1314. procedure tarraydef.write_rtti_data;
  1315. begin
  1316. rttilist^.concat(new(pai_const,init_8bit(13)));
  1317. writename;
  1318. { size of elements }
  1319. rttilist^.concat(new(pai_const,init_32bit(definition^.size)));
  1320. { count of elements }
  1321. rttilist^.concat(new(pai_const,init_32bit(highrange-lowrange+1)));
  1322. { element type }
  1323. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(definition^.get_rtti_label)))));
  1324. end;
  1325. {***************************************************************************
  1326. TRECDEF
  1327. ***************************************************************************}
  1328. constructor trecdef.init(p : psymtable);
  1329. begin
  1330. inherited init;
  1331. deftype:=recorddef;
  1332. symtable:=p;
  1333. savesize:=symtable^.datasize;
  1334. symtable^.defowner := @self;
  1335. end;
  1336. constructor trecdef.load;
  1337. var
  1338. oldread_member : boolean;
  1339. begin
  1340. inherited load;
  1341. deftype:=recorddef;
  1342. savesize:=readlong;
  1343. oldread_member:=read_member;
  1344. read_member:=true;
  1345. symtable:=new(psymtable,loadasstruct(recordsymtable));
  1346. read_member:=oldread_member;
  1347. symtable^.defowner := @self;
  1348. end;
  1349. destructor trecdef.done;
  1350. begin
  1351. if assigned(symtable) then dispose(symtable,done);
  1352. inherited done;
  1353. end;
  1354. var
  1355. binittable : boolean;
  1356. procedure check_rec_inittable(s : psym);
  1357. begin
  1358. if (s^.typ=varsym) and
  1359. ((pvarsym(s)^.definition^.deftype<>objectdef)
  1360. or not(pobjectdef(pvarsym(s)^.definition)^.isclass)) then
  1361. binittable:=pvarsym(s)^.definition^.needs_inittable;
  1362. end;
  1363. function trecdef.needs_inittable : boolean;
  1364. var
  1365. oldb : boolean;
  1366. begin
  1367. { there are recursive calls to needs_rtti possible, }
  1368. { so we have to change to old value how else should }
  1369. { we do that ? check_rec_rtti can't be a nested }
  1370. { procedure of needs_rtti ! }
  1371. oldb:=binittable;
  1372. binittable:=false;
  1373. symtable^.foreach(check_rec_inittable);
  1374. needs_inittable:=binittable;
  1375. binittable:=oldb;
  1376. end;
  1377. procedure trecdef.deref;
  1378. var
  1379. hp : pdef;
  1380. oldrecsyms : psymtable;
  1381. begin
  1382. oldrecsyms:=aktrecordsymtable;
  1383. aktrecordsymtable:=symtable;
  1384. { now dereference the definitions }
  1385. hp:=symtable^.rootdef;
  1386. while assigned(hp) do
  1387. begin
  1388. hp^.deref;
  1389. { set owner }
  1390. hp^.owner:=symtable;
  1391. hp:=hp^.next;
  1392. end;
  1393. {$ifdef tp}
  1394. symtable^.foreach(derefsym);
  1395. {$else}
  1396. symtable^.foreach(@derefsym);
  1397. {$endif}
  1398. aktrecordsymtable:=oldrecsyms;
  1399. end;
  1400. procedure trecdef.write;
  1401. var
  1402. oldread_member : boolean;
  1403. begin
  1404. oldread_member:=read_member;
  1405. read_member:=true;
  1406. inherited write;
  1407. writelong(savesize);
  1408. current_ppu^.writeentry(ibrecorddef);
  1409. self.symtable^.writeasstruct;
  1410. read_member:=oldread_member;
  1411. end;
  1412. {$ifdef GDB}
  1413. Const StabRecString : pchar = Nil;
  1414. StabRecSize : longint = 0;
  1415. RecOffset : Longint = 0;
  1416. procedure addname(p : psym);
  1417. var
  1418. news, newrec : pchar;
  1419. begin
  1420. { static variables from objects are like global objects }
  1421. if ((p^.properties and sp_static)<>0) then
  1422. exit;
  1423. If p^.typ = varsym then
  1424. begin
  1425. newrec := strpnew(p^.name+':'+pvarsym(p)^.definition^.numberstring
  1426. +','+tostr(pvarsym(p)^.address*8)+','
  1427. +tostr(pvarsym(p)^.definition^.size*8)+';');
  1428. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  1429. begin
  1430. getmem(news,stabrecsize+memsizeinc);
  1431. strcopy(news,stabrecstring);
  1432. freemem(stabrecstring,stabrecsize);
  1433. stabrecsize:=stabrecsize+memsizeinc;
  1434. stabrecstring:=news;
  1435. end;
  1436. strcat(StabRecstring,newrec);
  1437. strdispose(newrec);
  1438. {This should be used for case !!}
  1439. RecOffset := RecOffset + pvarsym(p)^.definition^.size;
  1440. end;
  1441. end;
  1442. function trecdef.stabstring : pchar;
  1443. Var oldrec : pchar;
  1444. oldsize : longint;
  1445. begin
  1446. oldrec := stabrecstring;
  1447. oldsize:=stabrecsize;
  1448. GetMem(stabrecstring,memsizeinc);
  1449. stabrecsize:=memsizeinc;
  1450. strpcopy(stabRecString,'s'+tostr(savesize));
  1451. RecOffset := 0;
  1452. {$ifdef tp}
  1453. symtable^.foreach(addname);
  1454. {$else}
  1455. symtable^.foreach(@addname);
  1456. {$endif}
  1457. { FPC doesn't want to convert a char to a pchar}
  1458. { is this a bug ? }
  1459. strpcopy(strend(StabRecString),';');
  1460. stabstring := strnew(StabRecString);
  1461. Freemem(stabrecstring,stabrecsize);
  1462. stabrecstring := oldrec;
  1463. stabrecsize:=oldsize;
  1464. end;
  1465. procedure trecdef.concatstabto(asmlist : paasmoutput);
  1466. begin
  1467. if (not assigned(sym) or sym^.isusedinstab or use_dbx) and
  1468. (not is_def_stab_written) then
  1469. inherited concatstabto(asmlist);
  1470. end;
  1471. {$endif GDB}
  1472. var
  1473. count : longint;
  1474. procedure count_inittable_fields(sym : psym);{$ifndef fpc}far;{$endif}
  1475. begin
  1476. if pvarsym(sym)^.definition^.needs_inittable then
  1477. inc(count);
  1478. end;
  1479. procedure count_fields(sym : psym);{$ifndef fpc}far;{$endif}
  1480. begin
  1481. inc(count);
  1482. end;
  1483. procedure write_field_inittable(sym : psym);{$ifndef fpc}far;{$endif}
  1484. begin
  1485. if pvarsym(sym)^.definition^.needs_inittable then
  1486. begin
  1487. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(pvarsym(sym)^.definition^.get_inittable_label)))));
  1488. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1489. end;
  1490. end;
  1491. procedure write_field_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  1492. begin
  1493. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(pvarsym(sym)^.definition^.get_rtti_label)))));
  1494. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1495. end;
  1496. procedure generate_child_inittable(sym : psym);{$ifndef fpc}far;{$endif}
  1497. begin
  1498. if (sym^.typ=varsym) and pvarsym(sym)^.definition^.needs_inittable then
  1499. { force inittable generation }
  1500. pvarsym(sym)^.definition^.get_inittable_label;
  1501. end;
  1502. procedure generate_child_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  1503. begin
  1504. pvarsym(sym)^.definition^.get_rtti_label;
  1505. end;
  1506. procedure trecdef.write_child_rtti_data;
  1507. begin
  1508. symtable^.foreach(generate_child_rtti);
  1509. end;
  1510. procedure trecdef.write_child_init_data;
  1511. begin
  1512. symtable^.foreach(generate_child_inittable);
  1513. end;
  1514. procedure trecdef.write_rtti_data;
  1515. begin
  1516. rttilist^.concat(new(pai_const,init_8bit(14)));
  1517. writename;
  1518. rttilist^.concat(new(pai_const,init_32bit(size)));
  1519. count:=0;
  1520. symtable^.foreach(count_fields);
  1521. rttilist^.concat(new(pai_const,init_32bit(count)));
  1522. symtable^.foreach(write_field_rtti);
  1523. end;
  1524. procedure trecdef.write_init_data;
  1525. begin
  1526. rttilist^.concat(new(pai_const,init_8bit(14)));
  1527. writename;
  1528. rttilist^.concat(new(pai_const,init_32bit(size)));
  1529. count:=0;
  1530. symtable^.foreach(count_inittable_fields);
  1531. rttilist^.concat(new(pai_const,init_32bit(count)));
  1532. symtable^.foreach(write_field_inittable);
  1533. end;
  1534. {***************************************************************************
  1535. TABSTRACTPROCDEF
  1536. ***************************************************************************}
  1537. constructor tabstractprocdef.init;
  1538. begin
  1539. inherited init;
  1540. para1:=nil;
  1541. fpu_used:=0;
  1542. options:=0;
  1543. retdef:=voiddef;
  1544. savesize:=Sizeof(pointer);
  1545. end;
  1546. procedure disposepdefcoll(var para1 : pdefcoll);
  1547. var
  1548. hp : pdefcoll;
  1549. begin
  1550. hp:=para1;
  1551. while assigned(hp) do
  1552. begin
  1553. para1:=hp^.next;
  1554. dispose(hp);
  1555. hp:=para1;
  1556. end;
  1557. end;
  1558. destructor tabstractprocdef.done;
  1559. begin
  1560. disposepdefcoll(para1);
  1561. inherited done;
  1562. end;
  1563. procedure tabstractprocdef.concatdef(p : pdef;vsp : tvarspez);
  1564. var
  1565. hp : pdefcoll;
  1566. begin
  1567. new(hp);
  1568. hp^.paratyp:=vsp;
  1569. hp^.data:=p;
  1570. hp^.next:=para1;
  1571. para1:=hp;
  1572. end;
  1573. { all functions returning in FPU are
  1574. assume to use 2 FPU registers
  1575. until the function implementation
  1576. is processed PM }
  1577. procedure tabstractprocdef.test_if_fpu_result;
  1578. begin
  1579. if assigned(retdef) and is_fpu(retdef) then
  1580. fpu_used:=2;
  1581. end;
  1582. procedure tabstractprocdef.deref;
  1583. var
  1584. hp : pdefcoll;
  1585. begin
  1586. inherited deref;
  1587. resolvedef(retdef);
  1588. hp:=para1;
  1589. while assigned(hp) do
  1590. begin
  1591. resolvedef(hp^.data);
  1592. hp:=hp^.next;
  1593. end;
  1594. end;
  1595. constructor tabstractprocdef.load;
  1596. var
  1597. last,hp : pdefcoll;
  1598. count,i : word;
  1599. begin
  1600. inherited load;
  1601. retdef:=readdefref;
  1602. fpu_used:=readbyte;
  1603. options:=readlong;
  1604. count:=readword;
  1605. para1:=nil;
  1606. savesize:=Sizeof(pointer);
  1607. for i:=1 to count do
  1608. begin
  1609. new(hp);
  1610. hp^.paratyp:=tvarspez(readbyte);
  1611. hp^.data:=readdefref;
  1612. hp^.next:=nil;
  1613. if para1=nil then
  1614. para1:=hp
  1615. else
  1616. last^.next:=hp;
  1617. last:=hp;
  1618. end;
  1619. end;
  1620. function tabstractprocdef.para_size : longint;
  1621. var
  1622. pdc : pdefcoll;
  1623. l : longint;
  1624. begin
  1625. l:=0;
  1626. pdc:=para1;
  1627. while assigned(pdc) do
  1628. begin
  1629. case pdc^.paratyp of
  1630. vs_value :
  1631. l:=l+pdc^.data^.size+(pdc^.data^.size mod 2);
  1632. vs_var :
  1633. l:=l+sizeof(pointer);
  1634. vs_const :
  1635. if dont_copy_const_param(pdc^.data) then
  1636. l:=l+sizeof(pointer)
  1637. else
  1638. l:=l+pdc^.data^.size+(pdc^.data^.size mod 2);
  1639. end;
  1640. pdc:=pdc^.next;
  1641. end;
  1642. para_size:=l;
  1643. end;
  1644. procedure tabstractprocdef.write;
  1645. var
  1646. count : word;
  1647. hp : pdefcoll;
  1648. begin
  1649. inherited write;
  1650. writedefref(retdef);
  1651. writebyte(fpu_used);
  1652. writelong(options);
  1653. hp:=para1;
  1654. count:=0;
  1655. while assigned(hp) do
  1656. begin
  1657. inc(count);
  1658. hp:=hp^.next;
  1659. end;
  1660. writeword(count);
  1661. hp:=para1;
  1662. while assigned(hp) do
  1663. begin
  1664. writebyte(byte(hp^.paratyp));
  1665. writedefref(hp^.data);
  1666. hp:=hp^.next;
  1667. end;
  1668. end;
  1669. function tabstractprocdef.demangled_paras : string;
  1670. var s : string;
  1671. p : pdefcoll;
  1672. begin
  1673. s:='';
  1674. p:=para1;
  1675. if assigned(p) then
  1676. begin
  1677. s:=s+'(';
  1678. while assigned(p) do
  1679. begin
  1680. if assigned(p^.data^.sym) then
  1681. s:=s+p^.data^.sym^.name
  1682. else if p^.paratyp=vs_var then
  1683. s:=s+'var'
  1684. else if p^.paratyp=vs_const then
  1685. s:=s+'const';
  1686. p:=p^.next;
  1687. if assigned(p) then
  1688. s:=s+','
  1689. else
  1690. s:=s+')';
  1691. end;
  1692. end;
  1693. demangled_paras:=s;
  1694. end;
  1695. {$ifdef GDB}
  1696. function tabstractprocdef.stabstring : pchar;
  1697. begin
  1698. stabstring := strpnew('abstractproc'+numberstring+';');
  1699. end;
  1700. procedure tabstractprocdef.concatstabto(asmlist : paasmoutput);
  1701. begin
  1702. if (not assigned(sym) or sym^.isusedinstab or use_dbx)
  1703. and not is_def_stab_written then
  1704. begin
  1705. if assigned(retdef) then forcestabto(asmlist,retdef);
  1706. inherited concatstabto(asmlist);
  1707. end;
  1708. end;
  1709. {$endif GDB}
  1710. {***************************************************************************
  1711. TPROCDEF
  1712. ***************************************************************************}
  1713. constructor tprocdef.init;
  1714. begin
  1715. inherited init;
  1716. deftype:=procdef;
  1717. _mangledname:=nil;
  1718. nextoverloaded:=nil;
  1719. extnumber:=-1;
  1720. localst:=new(psymtable,init(localsymtable));
  1721. parast:=new(psymtable,init(parasymtable));
  1722. { this is used by insert
  1723. to check same names in parast and localst }
  1724. localst^.next:=parast;
  1725. {$ifdef UseBrowser}
  1726. defref:=nil;
  1727. lastwritten:=nil;
  1728. refcount:=0;
  1729. if (cs_browser in aktmoduleswitches) and make_ref then
  1730. begin
  1731. defref:=new(pref,init(defref,@tokenpos));
  1732. inc(refcount);
  1733. end;
  1734. lastref:=defref;
  1735. {$endif UseBrowser}
  1736. { first, we assume, that all registers are used }
  1737. {$ifdef i386}
  1738. usedregisters:=$ff;
  1739. {$endif i386}
  1740. {$ifdef m68k}
  1741. usedregisters:=$FFFF;
  1742. {$endif}
  1743. {$ifdef alpha}
  1744. usedregisters_int:=$ffffffff;
  1745. usedregisters_fpu:=$ffffffff;
  1746. {$endif alpha}
  1747. forwarddef:=true;
  1748. _class := nil;
  1749. code:=nil;
  1750. end;
  1751. constructor tprocdef.load;
  1752. var
  1753. s : string;
  1754. begin
  1755. inherited load;
  1756. deftype:=procdef;
  1757. {$ifdef i386}
  1758. usedregisters:=readbyte;
  1759. {$endif i386}
  1760. {$ifdef m68k}
  1761. usedregisters:=readword;
  1762. {$endif}
  1763. {$ifdef alpha}
  1764. usedregisters_int:=readlong;
  1765. usedregisters_fpu:=readlong;
  1766. {$endif alpha}
  1767. s:=readstring;
  1768. setstring(_mangledname,s);
  1769. extnumber:=readlong;
  1770. nextoverloaded:=pprocdef(readdefref);
  1771. _class := pobjectdef(readdefref);
  1772. if (cs_link_deffile in aktglobalswitches) and ((options and poexports)<>0) then
  1773. deffile.AddExport(mangledname);
  1774. parast:=nil;
  1775. localst:=nil;
  1776. forwarddef:=false;
  1777. {$ifdef UseBrowser}
  1778. lastref:=nil;
  1779. lastwritten:=nil;
  1780. defref:=nil;
  1781. refcount:=0;
  1782. {$endif UseBrowser}
  1783. end;
  1784. {$ifdef UseBrowser}
  1785. procedure tprocdef.load_references;
  1786. var
  1787. pos : tfileposinfo;
  1788. move_last : boolean;
  1789. begin
  1790. move_last:=lastwritten=lastref;
  1791. while (not current_ppu^.endofentry) do
  1792. begin
  1793. readposinfo(pos);
  1794. inc(refcount);
  1795. lastref:=new(pref,init(lastref,@pos));
  1796. lastref^.is_written:=true;
  1797. if refcount=1 then
  1798. defref:=lastref;
  1799. end;
  1800. if move_last then
  1801. lastwritten:=lastref;
  1802. if (current_module^.flags and uf_local_browser)<>0 then
  1803. begin
  1804. new(parast,load);
  1805. parast^.load_browser;
  1806. new(localst,load);
  1807. localst^.load_browser;
  1808. end;
  1809. end;
  1810. function tprocdef.write_references : boolean;
  1811. var
  1812. ref : pref;
  1813. move_last : boolean;
  1814. begin
  1815. move_last:=lastwritten=lastref;
  1816. if move_last and ((current_module^.flags and uf_local_browser)=0) then
  1817. exit;
  1818. { write address of this symbol }
  1819. writedefref(@self);
  1820. { write refs }
  1821. if assigned(lastwritten) then
  1822. ref:=lastwritten
  1823. else
  1824. ref:=defref;
  1825. while assigned(ref) do
  1826. begin
  1827. if ref^.moduleindex=current_module^.unit_index then
  1828. begin
  1829. writeposinfo(ref^.posinfo);
  1830. ref^.is_written:=true;
  1831. if move_last then
  1832. lastwritten:=ref;
  1833. end
  1834. else if not ref^.is_written then
  1835. move_last:=false
  1836. else if move_last then
  1837. lastwritten:=ref;
  1838. ref:=ref^.nextref;
  1839. end;
  1840. current_ppu^.writeentry(ibdefref);
  1841. write_references:=true;
  1842. if (current_module^.flags and uf_local_browser)<>0 then
  1843. begin
  1844. { we need dummy para and local symtables
  1845. PPU files are then easier to read PM }
  1846. if not assigned(parast) then
  1847. parast:=new(psymtable,init(parasymtable));
  1848. parast^.write;
  1849. parast^.write_browser;
  1850. if not assigned(localst) then
  1851. localst:=new(psymtable,init(localsymtable));
  1852. localst^.write;
  1853. localst^.write_browser;
  1854. end;
  1855. end;
  1856. procedure tprocdef.add_to_browserlog;
  1857. begin
  1858. if assigned(defref) then
  1859. begin
  1860. Browse.AddLog('***'+mangledname);
  1861. Browse.AddLogRefs(defref);
  1862. if (current_module^.flags and uf_local_browser)<>0 then
  1863. begin
  1864. if assigned(parast) then
  1865. parast^.writebrowserlog;
  1866. if assigned(localst) then
  1867. localst^.writebrowserlog;
  1868. end;
  1869. end;
  1870. end;
  1871. {$endif UseBrowser}
  1872. destructor tprocdef.done;
  1873. begin
  1874. {$ifdef UseBrowser}
  1875. if assigned(defref) then
  1876. dispose(defref,done);
  1877. {$endif UseBrowser}
  1878. if assigned(parast) then
  1879. dispose(parast,done);
  1880. if assigned(localst) then
  1881. dispose(localst,done);
  1882. if assigned(code) and ((options and poinline) <> 0) then
  1883. disposetree(ptree(code));
  1884. if
  1885. {$ifdef tp}
  1886. not(use_big) and
  1887. {$endif}
  1888. assigned(_mangledname) then
  1889. strdispose(_mangledname);
  1890. inherited done;
  1891. end;
  1892. procedure tprocdef.write;
  1893. begin
  1894. inherited write;
  1895. {$ifdef i386}
  1896. writebyte(usedregisters);
  1897. {$endif i386}
  1898. {$ifdef m68k}
  1899. writeword(usedregisters);
  1900. {$endif}
  1901. {$ifdef alpha}
  1902. writelong(usedregisters_int);
  1903. writelong(usedregisters_fpu);
  1904. {$endif alpha}
  1905. writestring(mangledname);
  1906. writelong(extnumber);
  1907. if (options and pooperator) = 0 then
  1908. writedefref(nextoverloaded)
  1909. else
  1910. begin
  1911. { only write the overloads from the same unit }
  1912. if nextoverloaded^.owner=owner then
  1913. writedefref(nextoverloaded)
  1914. else
  1915. writedefref(nil);
  1916. end;
  1917. writedefref(_class);
  1918. if (options and poinline) <> 0 then
  1919. begin
  1920. { we need to save
  1921. - the para and the local symtable
  1922. - the code ptree !! PM
  1923. writesymtable(parast);
  1924. writesymtable(localst);
  1925. writeptree(ptree(code));
  1926. }
  1927. end;
  1928. current_ppu^.writeentry(ibprocdef);
  1929. end;
  1930. {$ifdef GDB}
  1931. procedure addparaname(p : psym);
  1932. var vs : char;
  1933. begin
  1934. if pvarsym(p)^.varspez = vs_value then vs := '1'
  1935. else vs := '0';
  1936. strpcopy(strend(StabRecString),p^.name+':'+pvarsym(p)^.definition^.numberstring+','+vs+';');
  1937. end;
  1938. function tprocdef.stabstring : pchar;
  1939. var param : pdefcoll;
  1940. i : word;
  1941. vartyp : char;
  1942. oldrec : pchar;
  1943. begin
  1944. oldrec := stabrecstring;
  1945. getmem(StabRecString,1024);
  1946. param := para1;
  1947. i := 0;
  1948. while assigned(param) do
  1949. begin
  1950. inc(i);
  1951. param := param^.next;
  1952. end;
  1953. strpcopy(StabRecString,'f'+retdef^.numberstring);
  1954. if i>0 then
  1955. begin
  1956. strpcopy(strend(StabRecString),','+tostr(i)+';');
  1957. if assigned(parast) then
  1958. {$IfDef TP}
  1959. parast^.foreach(addparaname)
  1960. {$Else}
  1961. parast^.foreach(@addparaname)
  1962. {$EndIf}
  1963. else
  1964. begin
  1965. param := para1;
  1966. i := 0;
  1967. while assigned(param) do
  1968. begin
  1969. inc(i);
  1970. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  1971. {Here we have lost the parameter names !!}
  1972. {using lower case parameters }
  1973. strpcopy(strend(stabrecstring),'p'+tostr(i)
  1974. +':'+param^.data^.numberstring+','+vartyp+';');
  1975. param := param^.next;
  1976. end;
  1977. end;
  1978. {strpcopy(strend(StabRecString),';');}
  1979. end;
  1980. stabstring := strnew(stabrecstring);
  1981. freemem(stabrecstring,1024);
  1982. stabrecstring := oldrec;
  1983. end;
  1984. procedure tprocdef.concatstabto(asmlist : paasmoutput);
  1985. begin
  1986. end;
  1987. {$endif GDB}
  1988. procedure tprocdef.deref;
  1989. begin
  1990. inherited deref;
  1991. resolvedef(pdef(nextoverloaded));
  1992. resolvedef(pdef(_class));
  1993. end;
  1994. function tprocdef.mangledname : string;
  1995. {$ifdef tp}
  1996. var
  1997. oldpos : longint;
  1998. s : string;
  1999. b : byte;
  2000. {$endif tp}
  2001. begin
  2002. {$ifdef tp}
  2003. if use_big then
  2004. begin
  2005. symbolstream.seek(longint(_mangledname));
  2006. symbolstream.read(b,1);
  2007. symbolstream.read(s[1],b);
  2008. s[0]:=chr(b);
  2009. mangledname:=s;
  2010. end
  2011. else
  2012. {$endif}
  2013. mangledname:=strpas(_mangledname);
  2014. end;
  2015. {$IfDef GDB}
  2016. function tprocdef.cplusplusmangledname : string;
  2017. var
  2018. s,s2 : string;
  2019. param : pdefcoll;
  2020. begin
  2021. s := sym^.name;
  2022. if _class <> nil then
  2023. begin
  2024. s2 := _class^.name^;
  2025. s := s+'__'+tostr(length(s2))+s2;
  2026. end else s := s + '_';
  2027. param := para1;
  2028. while assigned(param) do
  2029. begin
  2030. s2 := param^.data^.sym^.name;
  2031. s := s+tostr(length(s2))+s2;
  2032. param := param^.next;
  2033. end;
  2034. cplusplusmangledname:=s;
  2035. end;
  2036. {$EndIf GDB}
  2037. procedure tprocdef.setmangledname(const s : string);
  2038. begin
  2039. if {$ifdef tp}not(use_big) and{$endif} (assigned(_mangledname)) then
  2040. strdispose(_mangledname);
  2041. setstring(_mangledname,s);
  2042. {$ifdef UseBrowser}
  2043. if assigned(parast) then
  2044. begin
  2045. stringdispose(parast^.name);
  2046. parast^.name:=stringdup('args of '+s);
  2047. end;
  2048. if assigned(localst) then
  2049. begin
  2050. stringdispose(localst^.name);
  2051. localst^.name:=stringdup('locals of '+s);
  2052. end;
  2053. {$endif UseBrowser}
  2054. end;
  2055. {***************************************************************************
  2056. TPROCVARDEF
  2057. ***************************************************************************}
  2058. constructor tprocvardef.init;
  2059. begin
  2060. inherited init;
  2061. deftype:=procvardef;
  2062. end;
  2063. constructor tprocvardef.load;
  2064. begin
  2065. inherited load;
  2066. deftype:=procvardef;
  2067. end;
  2068. procedure tprocvardef.write;
  2069. begin
  2070. { here we cannot get a real good value so just give something }
  2071. { plausible (PM) }
  2072. { a more secure way would be
  2073. to allways store in a temp }
  2074. if is_fpu(retdef) then
  2075. fpu_used:=2
  2076. else
  2077. fpu_used:=0;
  2078. inherited write;
  2079. current_ppu^.writeentry(ibprocvardef);
  2080. end;
  2081. function tprocvardef.size : longint;
  2082. begin
  2083. if (options and pomethodpointer)=0 then
  2084. size:=sizeof(pointer)
  2085. else
  2086. size:=2*sizeof(pointer);
  2087. end;
  2088. {$ifdef GDB}
  2089. function tprocvardef.stabstring : pchar;
  2090. var
  2091. nss : pchar;
  2092. i : word;
  2093. vartyp : char;
  2094. pst : pchar;
  2095. param : pdefcoll;
  2096. begin
  2097. i := 0;
  2098. param := para1;
  2099. while assigned(param) do
  2100. begin
  2101. inc(i);
  2102. param := param^.next;
  2103. end;
  2104. getmem(nss,1024);
  2105. strpcopy(nss,'f'+retdef^.numberstring+','+tostr(i)+';');
  2106. param := para1;
  2107. i := 0;
  2108. while assigned(param) do
  2109. begin
  2110. inc(i);
  2111. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2112. {Here we have lost the parameter names !!}
  2113. pst := strpnew('p'+tostr(i)+':'+param^.data^.numberstring+','+vartyp+';');
  2114. strcat(nss,pst);
  2115. strdispose(pst);
  2116. param := param^.next;
  2117. end;
  2118. {strpcopy(strend(nss),';');}
  2119. stabstring := strnew(nss);
  2120. freemem(nss,1024);
  2121. end;
  2122. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  2123. begin
  2124. if ( not assigned(sym) or sym^.isusedinstab or use_dbx)
  2125. and not is_def_stab_written then
  2126. inherited concatstabto(asmlist);
  2127. is_def_stab_written:=true;
  2128. end;
  2129. {$endif GDB}
  2130. procedure tprocvardef.write_rtti_data;
  2131. begin
  2132. {!!!!!!!}
  2133. end;
  2134. procedure tprocvardef.write_child_rtti_data;
  2135. begin
  2136. {!!!!!!!!}
  2137. end;
  2138. function tprocvardef.is_publishable : boolean;
  2139. begin
  2140. is_publishable:=(options and pomethodpointer)<>0;
  2141. end;
  2142. {***************************************************************************
  2143. TOBJECTDEF
  2144. ***************************************************************************}
  2145. {$ifdef GDB}
  2146. const
  2147. vtabletype : word = 0;
  2148. vtableassigned : boolean = false;
  2149. {$endif GDB}
  2150. constructor tobjectdef.init(const n : string;c : pobjectdef);
  2151. begin
  2152. tdef.init;
  2153. deftype:=objectdef;
  2154. childof:=c;
  2155. options:=0;
  2156. vmt_offset:=0;
  2157. { some options are inherited !! }
  2158. if assigned(c) then
  2159. options:= c^.options and
  2160. (oo_hasvirtual or oo_hasprivate or
  2161. oo_hasprotected
  2162. {or oo_can_have_published treated in pdecl }
  2163. );
  2164. { privatesyms:=new(psymtable,init(objectsymtable));
  2165. protectedsyms:=new(psymtable,init(objectsymtable)); }
  2166. publicsyms:=new(psymtable,init(objectsymtable));
  2167. publicsyms^.name := stringdup(n);
  2168. { add the data of the anchestor class }
  2169. if assigned(childof) then
  2170. begin
  2171. publicsyms^.datasize:=
  2172. publicsyms^.datasize-4+childof^.publicsyms^.datasize;
  2173. end;
  2174. name:=stringdup(n);
  2175. savesize := publicsyms^.datasize;
  2176. publicsyms^.defowner:=@self;
  2177. end;
  2178. constructor tobjectdef.load;
  2179. var
  2180. oldread_member : boolean;
  2181. begin
  2182. tdef.load;
  2183. deftype:=objectdef;
  2184. savesize:=readlong;
  2185. vmt_offset:=readlong;
  2186. name:=stringdup(readstring);
  2187. childof:=pobjectdef(readdefref);
  2188. options:=readlong;
  2189. oldread_member:=read_member;
  2190. read_member:=true;
  2191. object_options:=true;
  2192. publicsyms:=new(psymtable,loadasstruct(objectsymtable));
  2193. object_options:=false;
  2194. read_member:=oldread_member;
  2195. publicsyms^.defowner:=@self;
  2196. { publicsyms^.datasize:=savesize; }
  2197. publicsyms^.name := stringdup(name^);
  2198. { handles the predefined class tobject }
  2199. { the last TOBJECT which is loaded gets }
  2200. { it ! }
  2201. if (name^='TOBJECT') and not(cs_compilesystem in aktmoduleswitches) and
  2202. isclass and (childof=pointer($ffffffff)) then
  2203. class_tobject:=@self;
  2204. end;
  2205. procedure tobjectdef.check_forwards;
  2206. begin
  2207. publicsyms^.check_forwards;
  2208. if (options and oo_isforward)<>0 then
  2209. begin
  2210. { ok, in future, the forward can be resolved }
  2211. Message1(sym_e_class_forward_not_resolved,name^);
  2212. options:=options and not(oo_isforward);
  2213. end;
  2214. end;
  2215. destructor tobjectdef.done;
  2216. begin
  2217. {!!!!
  2218. if assigned(privatesyms) then
  2219. dispose(privatesyms,done);
  2220. if assigned(protectedsyms) then
  2221. dispose(protectedsyms,done); }
  2222. if assigned(publicsyms) then
  2223. dispose(publicsyms,done);
  2224. if (options and oo_isforward)<>0 then
  2225. Message1(sym_e_class_forward_not_resolved,name^);
  2226. stringdispose(name);
  2227. tdef.done;
  2228. end;
  2229. { true, if self inherits from d (or if they are equal) }
  2230. function tobjectdef.isrelated(d : pobjectdef) : boolean;
  2231. var
  2232. hp : pobjectdef;
  2233. begin
  2234. hp:=@self;
  2235. while assigned(hp) do
  2236. begin
  2237. if hp=d then
  2238. begin
  2239. isrelated:=true;
  2240. exit;
  2241. end;
  2242. hp:=hp^.childof;
  2243. end;
  2244. isrelated:=false;
  2245. end;
  2246. function tobjectdef.size : longint;
  2247. begin
  2248. if (options and oois_class)<>0 then
  2249. size:=sizeof(pointer)
  2250. else
  2251. size:=publicsyms^.datasize;
  2252. end;
  2253. procedure tobjectdef.deref;
  2254. var
  2255. hp : pdef;
  2256. oldrecsyms : psymtable;
  2257. begin
  2258. resolvedef(pdef(childof));
  2259. oldrecsyms:=aktrecordsymtable;
  2260. aktrecordsymtable:=publicsyms;
  2261. { nun die Definitionen dereferenzieren }
  2262. hp:=publicsyms^.rootdef;
  2263. while assigned(hp) do
  2264. begin
  2265. hp^.deref;
  2266. { set owner }
  2267. hp^.owner:=publicsyms;
  2268. hp:=hp^.next;
  2269. end;
  2270. {$ifdef tp}
  2271. publicsyms^.foreach(derefsym);
  2272. {$else}
  2273. publicsyms^.foreach(@derefsym);
  2274. {$endif}
  2275. aktrecordsymtable:=oldrecsyms;
  2276. end;
  2277. function tobjectdef.vmt_mangledname : string;
  2278. {DM: I get a nil pointer on the owner name. I don't know if this
  2279. mayhappen, and I have therefore fixed the problem by doing nil pointer
  2280. checks.}
  2281. var
  2282. s1,s2:string;
  2283. begin
  2284. if owner^.name=nil then
  2285. s1:=''
  2286. else
  2287. s1:=owner^.name^;
  2288. if name=nil then
  2289. s2:=''
  2290. else
  2291. s2:=name^;
  2292. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  2293. end;
  2294. function tobjectdef.rtti_name : string;
  2295. var
  2296. s1,s2:string;
  2297. begin
  2298. if owner^.name=nil then
  2299. s1:=''
  2300. else
  2301. s1:=owner^.name^;
  2302. if name=nil then
  2303. s2:=''
  2304. else
  2305. s2:=name^;
  2306. rtti_name:='RTTI_'+s1+'$_'+s2;
  2307. end;
  2308. function tobjectdef.isclass : boolean;
  2309. begin
  2310. isclass:=(options and oois_class)<>0;
  2311. end;
  2312. procedure tobjectdef.write;
  2313. var
  2314. oldread_member : boolean;
  2315. begin
  2316. tdef.write;
  2317. writelong(size);
  2318. writelong(vmt_offset);
  2319. writestring(name^);
  2320. writedefref(childof);
  2321. writelong(options);
  2322. current_ppu^.writeentry(ibobjectdef);
  2323. oldread_member:=read_member;
  2324. read_member:=true;
  2325. object_options:=true;
  2326. publicsyms^.writeasstruct;
  2327. object_options:=false;
  2328. read_member:=oldread_member;
  2329. end;
  2330. {$ifdef GDB}
  2331. procedure addprocname(p :psym);
  2332. var virtualind,argnames : string;
  2333. news, newrec : pchar;
  2334. pd,ipd : pprocdef;
  2335. lindex : longint;
  2336. para : pdefcoll;
  2337. arglength : byte;
  2338. sp : char;
  2339. begin
  2340. If p^.typ = procsym then
  2341. begin
  2342. pd := pprocsym(p)^.definition;
  2343. { this will be used for full implementation of object stabs
  2344. not yet done }
  2345. ipd := pd;
  2346. while assigned(ipd^.nextoverloaded) do ipd := ipd^.nextoverloaded;
  2347. if (pd^.options and povirtualmethod) <> 0 then
  2348. begin
  2349. lindex := pd^.extnumber;
  2350. {doesnt seem to be necessary
  2351. lindex := lindex or $80000000;}
  2352. virtualind := '*'+tostr(lindex)+';'+ipd^._class^.numberstring+';'
  2353. end else virtualind := '.';
  2354. { arguments are not listed here }
  2355. {we don't need another definition}
  2356. para := pd^.para1;
  2357. argnames := '';
  2358. while assigned(para) do
  2359. begin
  2360. if para^.data^.deftype = formaldef then
  2361. begin
  2362. if para^.paratyp=vs_var then
  2363. argnames := argnames+'3var'
  2364. else if para^.paratyp=vs_const then
  2365. argnames:=argnames+'5const';
  2366. end
  2367. else
  2368. begin
  2369. { if the arg definition is like (v: ^byte;..
  2370. there is no sym attached to data !!! }
  2371. if assigned(para^.data^.sym) then
  2372. begin
  2373. arglength := length(para^.data^.sym^.name);
  2374. argnames := argnames + tostr(arglength)+para^.data^.sym^.name;
  2375. end
  2376. else
  2377. begin
  2378. argnames:=argnames+'11unnamedtype';
  2379. end;
  2380. end;
  2381. para := para^.next;
  2382. end;
  2383. ipd^.is_def_stab_written := true;
  2384. { here 2A must be changed for private and protected }
  2385. { 0 is private 1 protected and 2 public }
  2386. if (p^.properties and sp_private)<>0 then sp:='0'
  2387. else if (p^.properties and sp_protected)<>0 then sp:='1'
  2388. else sp:='2';
  2389. newrec := strpnew(p^.name+'::'+ipd^.numberstring
  2390. +'=##'+pd^.retdef^.numberstring+';:'+argnames+';'+sp+'A'
  2391. +virtualind+';');
  2392. { get spare place for a string at the end }
  2393. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2394. begin
  2395. getmem(news,stabrecsize+memsizeinc);
  2396. strcopy(news,stabrecstring);
  2397. freemem(stabrecstring,stabrecsize);
  2398. stabrecsize:=stabrecsize+memsizeinc;
  2399. stabrecstring:=news;
  2400. end;
  2401. strcat(StabRecstring,newrec);
  2402. {freemem(newrec,memsizeinc); }
  2403. strdispose(newrec);
  2404. {This should be used for case !!}
  2405. RecOffset := RecOffset + pd^.size;
  2406. end;
  2407. end;
  2408. function tobjectdef.stabstring : pchar;
  2409. var anc : pobjectdef;
  2410. oldrec : pchar;
  2411. oldrecsize : longint;
  2412. str_end : string;
  2413. begin
  2414. oldrec := stabrecstring;
  2415. oldrecsize:=stabrecsize;
  2416. stabrecsize:=memsizeinc;
  2417. GetMem(stabrecstring,stabrecsize);
  2418. strpcopy(stabRecString,'s'+tostr(size));
  2419. if assigned(childof) then
  2420. {only one ancestor not virtual, public, at base offset 0 }
  2421. { !1 , 0 2 0 , }
  2422. strpcopy(strend(stabrecstring),'!1,020,'+childof^.numberstring+';');
  2423. {virtual table to implement yet}
  2424. RecOffset := 0;
  2425. {$ifdef tp}
  2426. publicsyms^.foreach(addname);
  2427. {$else}
  2428. publicsyms^.foreach(@addname);
  2429. {$endif tp}
  2430. if (options and oo_hasvirtual) <> 0 then
  2431. if not assigned(childof) or ((childof^.options and oo_hasvirtual) = 0) then
  2432. begin
  2433. str_end:='$vf'+numberstring+':'+typeglobalnumber('vtblarray')+',0;';
  2434. strpcopy(strend(stabrecstring),'$vf'+numberstring+':'+typeglobalnumber('vtblarray')+',0;');
  2435. end;
  2436. {$ifdef tp}
  2437. publicsyms^.foreach(addprocname);
  2438. {$else}
  2439. publicsyms^.foreach(@addprocname);
  2440. {$endif tp }
  2441. if (options and oo_hasvirtual) <> 0 then
  2442. begin
  2443. anc := @self;
  2444. while assigned(anc^.childof) and ((anc^.childof^.options and oo_hasvirtual) <> 0) do
  2445. anc := anc^.childof;
  2446. str_end:=';~%'+anc^.numberstring+';';
  2447. end
  2448. else
  2449. str_end:=';';
  2450. strpcopy(strend(stabrecstring),str_end);
  2451. stabstring := strnew(StabRecString);
  2452. freemem(stabrecstring,stabrecsize);
  2453. stabrecstring := oldrec;
  2454. stabrecsize:=oldrecsize;
  2455. end;
  2456. {$endif GDB}
  2457. procedure tobjectdef.write_child_init_data;
  2458. begin
  2459. end;
  2460. procedure tobjectdef.write_init_data;
  2461. begin
  2462. if isclass then
  2463. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2464. else
  2465. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2466. { generate the name }
  2467. rttilist^.concat(new(pai_const,init_8bit(length(name^))));
  2468. rttilist^.concat(new(pai_string,init(name^)));
  2469. rttilist^.concat(new(pai_const,init_32bit(size)));
  2470. count:=0;
  2471. publicsyms^.foreach(count_inittable_fields);
  2472. rttilist^.concat(new(pai_const,init_32bit(count)));
  2473. publicsyms^.foreach(write_field_inittable);
  2474. end;
  2475. function tobjectdef.needs_inittable : boolean;
  2476. var
  2477. oldb : boolean;
  2478. begin
  2479. { there are recursive calls to needs_inittable possible, }
  2480. { so we have to change to old value how else should }
  2481. { we do that ? check_rec_rtti can't be a nested }
  2482. { procedure of needs_rtti ! }
  2483. oldb:=binittable;
  2484. binittable:=false;
  2485. publicsyms^.foreach(check_rec_inittable);
  2486. needs_inittable:=binittable;
  2487. binittable:=oldb;
  2488. end;
  2489. procedure count_published_properties(sym : psym);{$ifndef fpc}far;{$endif}
  2490. begin
  2491. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2492. inc(count);
  2493. end;
  2494. procedure write_property_info(sym : psym);{$ifndef fpc}far;{$endif}
  2495. var
  2496. proctypesinfo : byte;
  2497. procedure writeproc(sym : psym;def : pdef;shiftvalue : byte);
  2498. var
  2499. typvalue : byte;
  2500. begin
  2501. if not(assigned(sym)) then
  2502. begin
  2503. rttilist^.concat(new(pai_const,init_32bit(1)));
  2504. typvalue:=3;
  2505. end
  2506. else if sym^.typ=varsym then
  2507. begin
  2508. rttilist^.concat(new(pai_const,init_32bit(
  2509. pvarsym(sym)^.address)));
  2510. typvalue:=0;
  2511. end
  2512. else
  2513. begin
  2514. if (pprocdef(def)^.options and povirtualmethod)=0 then
  2515. begin
  2516. rttilist^.concat(new(pai_const,init_symbol(strpnew(pprocdef(def)^.mangledname))));
  2517. typvalue:=1;
  2518. end
  2519. else
  2520. begin
  2521. { virtual method, write vmt offset }
  2522. rttilist^.concat(new(pai_const,init_32bit(pprocdef(def)^.extnumber*4+12)));
  2523. typvalue:=2;
  2524. end;
  2525. end;
  2526. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  2527. end;
  2528. begin
  2529. if (ppropertysym(sym)^.options and ppo_indexed)<>0 then
  2530. proctypesinfo:=$40
  2531. else
  2532. proctypesinfo:=0;
  2533. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2534. begin
  2535. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(ppropertysym(sym)^.proptype^.get_rtti_label)))));
  2536. writeproc(ppropertysym(sym)^.readaccesssym,ppropertysym(sym)^.readaccessdef,0);
  2537. writeproc(ppropertysym(sym)^.writeaccesssym,ppropertysym(sym)^.writeaccessdef,2);
  2538. { isn't it stored ? }
  2539. if (ppropertysym(sym)^.options and ppo_stored)=0 then
  2540. begin
  2541. rttilist^.concat(new(pai_const,init_32bit(1)));
  2542. proctypesinfo:=proctypesinfo or (3 shl 4);
  2543. end
  2544. else
  2545. writeproc(ppropertysym(sym)^.storedsym,ppropertysym(sym)^.storeddef,4);
  2546. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.index)));
  2547. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.default)));
  2548. rttilist^.concat(new(pai_const,init_16bit(count)));
  2549. inc(count);
  2550. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  2551. rttilist^.concat(new(pai_const,init_8bit(length(ppropertysym(sym)^.name))));
  2552. rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
  2553. end;
  2554. end;
  2555. procedure generate_published_child_rtti(sym : psym);{$ifndef fpc}far;{$endif}
  2556. begin
  2557. if (sym^.typ=propertysym) and ((sym^.properties and sp_published)<>0) then
  2558. ppropertysym(sym)^.proptype^.get_rtti_label;
  2559. end;
  2560. procedure tobjectdef.write_child_rtti_data;
  2561. begin
  2562. publicsyms^.foreach(generate_published_child_rtti);
  2563. end;
  2564. procedure tobjectdef.generate_rtti;
  2565. begin
  2566. has_rtti:=true;
  2567. getlabel(rtti_label);
  2568. write_child_rtti_data;
  2569. rttilist^.concat(new(pai_symbol,init_global(rtti_name)));
  2570. rttilist^.concat(new(pai_label,init(rtti_label)));
  2571. write_rtti_data;
  2572. end;
  2573. function tobjectdef.next_free_name_index : longint;
  2574. var
  2575. i : longint;
  2576. begin
  2577. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2578. i:=childof^.next_free_name_index
  2579. else
  2580. i:=0;
  2581. count:=0;
  2582. publicsyms^.foreach(count_published_properties);
  2583. next_free_name_index:=i+count;
  2584. end;
  2585. procedure tobjectdef.write_rtti_data;
  2586. begin
  2587. if isclass then
  2588. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2589. else
  2590. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2591. { generate the name }
  2592. rttilist^.concat(new(pai_const,init_8bit(length(name^))));
  2593. rttilist^.concat(new(pai_string,init(name^)));
  2594. { write class type }
  2595. rttilist^.concat(new(pai_const,init_symbol(strpnew(vmt_mangledname))));
  2596. { write owner typeinfo }
  2597. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2598. rttilist^.concat(new(pai_const,init_symbol(strpnew(lab2str(childof^.get_rtti_label)))))
  2599. else
  2600. rttilist^.concat(new(pai_const,init_32bit(0)));
  2601. { write published properties count }
  2602. count:=0;
  2603. publicsyms^.foreach(count_published_properties);
  2604. rttilist^.concat(new(pai_const,init_16bit(count)));
  2605. { write unit name }
  2606. if assigned(owner^.name) then
  2607. begin
  2608. rttilist^.concat(new(pai_const,init_8bit(length(owner^.name^))));
  2609. rttilist^.concat(new(pai_string,init(owner^.name^)));
  2610. end
  2611. else
  2612. rttilist^.concat(new(pai_const,init_8bit(0)));
  2613. { count is used to write nameindex }
  2614. { but we need an offset of the owner }
  2615. { to give each property an own slot }
  2616. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2617. count:=childof^.next_free_name_index
  2618. else
  2619. count:=0;
  2620. publicsyms^.foreach(write_property_info);
  2621. end;
  2622. function tobjectdef.is_publishable : boolean;
  2623. begin
  2624. is_publishable:=isclass;
  2625. end;
  2626. {****************************************************************************
  2627. TERRORDEF
  2628. ****************************************************************************}
  2629. constructor terrordef.init;
  2630. begin
  2631. inherited init;
  2632. deftype:=errordef;
  2633. end;
  2634. {$ifdef GDB}
  2635. function terrordef.stabstring : pchar;
  2636. begin
  2637. stabstring:=strpnew('error'+numberstring);
  2638. end;
  2639. {$endif GDB}
  2640. {
  2641. $Log$
  2642. Revision 1.56 1998-10-09 11:47:56 pierre
  2643. * still more memory leaks fixes !!
  2644. Revision 1.55 1998/10/06 17:16:55 pierre
  2645. * some memory leaks fixed (thanks to Peter for heaptrc !)
  2646. Revision 1.54 1998/10/05 21:33:28 peter
  2647. * fixed 161,165,166,167,168
  2648. Revision 1.53 1998/10/05 12:48:39 pierre
  2649. * wrong handling of range check for arrays fixed
  2650. Revision 1.52 1998/10/02 07:20:38 florian
  2651. * range checking in units doesn't work if the units are smartlinked, fixed
  2652. Revision 1.51 1998/09/25 12:01:41 florian
  2653. * tobjectdef.publicsyms.datasize was set to savesize, this is wrong now
  2654. because the symtable size is read from the ppu file
  2655. Revision 1.50 1998/09/23 15:46:40 florian
  2656. * problem with with and classes fixed
  2657. Revision 1.49 1998/09/23 12:03:55 peter
  2658. * overloading fix for array of const
  2659. Revision 1.48 1998/09/22 15:37:23 peter
  2660. + array of const start
  2661. Revision 1.47 1998/09/21 15:46:01 michael
  2662. Applied florians fix for check_rec_inittable
  2663. Revision 1.46 1998/09/21 08:45:21 pierre
  2664. + added vmt_offset in tobjectdef.write for fututre use
  2665. (first steps to have objects without vmt if no virtual !!)
  2666. + added fpu_used field for tabstractprocdef :
  2667. sets this level to 2 if the functions return with value in FPU
  2668. (is then set to correct value at parsing of implementation)
  2669. THIS MIGHT refuse some code with FPU expression too complex
  2670. that were accepted before and even in some cases
  2671. that don't overflow in fact
  2672. ( like if f : float; is a forward that finally in implementation
  2673. only uses one fpu register !!)
  2674. Nevertheless I think that it will improve security on
  2675. FPU operations !!
  2676. * most other changes only for UseBrowser code
  2677. (added symtable references for record and objects)
  2678. local switch for refs to args and local of each function
  2679. (static symtable still missing)
  2680. UseBrowser still not stable and probably broken by
  2681. the definition hash array !!
  2682. Revision 1.45 1998/09/20 08:31:29 florian
  2683. + bit 6 of tpropinfo.propprocs is set, if the property contains a
  2684. constant index
  2685. Revision 1.44 1998/09/19 15:23:58 florian
  2686. * rtti for ordtypes corrected
  2687. Revision 1.43 1998/09/18 17:12:40 florian
  2688. * problem with writing of class references fixed
  2689. Revision 1.42 1998/09/17 13:41:20 pierre
  2690. sizeof(TPOINT) problem
  2691. Revision 1.40.2.2 1998/09/17 08:42:33 pierre
  2692. TPOINT sizeof fix
  2693. Revision 1.41 1998/09/15 17:39:30 jonas
  2694. + bugfix from bugfix branch
  2695. Revision 1.40.2.1 1998/09/15 17:35:32 jonas
  2696. * chenged string_typ in tstringdef.wideload from ansistring to widestring
  2697. Revision 1.40 1998/09/09 15:34:00 peter
  2698. * removed warnings
  2699. Revision 1.39 1998/09/08 10:23:44 pierre
  2700. * name field of filedef corrected
  2701. Revision 1.38 1998/09/07 23:10:23 florian
  2702. * a lot of stuff fixed regarding rtti and publishing of properties,
  2703. basics should now work
  2704. Revision 1.37 1998/09/07 19:33:24 florian
  2705. + some stuff for property rtti added:
  2706. - NameIndex of the TPropInfo record is now written correctly
  2707. - the DEFAULT/NODEFAULT keyword is supported now
  2708. - the default value and the storedsym/def are now written to
  2709. the PPU fiel
  2710. Revision 1.36 1998/09/07 17:37:01 florian
  2711. * first fixes for published properties
  2712. Revision 1.35 1998/09/06 22:42:02 florian
  2713. + rtti genreation for properties added
  2714. Revision 1.34 1998/09/04 18:15:02 peter
  2715. * filedef updated
  2716. Revision 1.33 1998/09/03 17:08:49 pierre
  2717. * better lines for stabs
  2718. (no scroll back to if before else part
  2719. no return to case line at jump outside case)
  2720. + source lines also if not in order
  2721. Revision 1.32 1998/09/03 16:03:20 florian
  2722. + rtti generation
  2723. * init table generation changed
  2724. Revision 1.31 1998/09/02 15:14:28 peter
  2725. * enum packing changed from len to max
  2726. Revision 1.30 1998/09/01 17:37:29 peter
  2727. * removed debug writeln :(
  2728. Revision 1.29 1998/09/01 12:53:25 peter
  2729. + aktpackenum
  2730. Revision 1.28 1998/09/01 07:54:22 pierre
  2731. * UseBrowser a little updated (might still be buggy !!)
  2732. * bug in psub.pas in function specifier removed
  2733. * stdcall allowed in interface and in implementation
  2734. (FPC will not yet complain if it is missing in either part
  2735. because stdcall is only a dummy !!)
  2736. Revision 1.27 1998/08/28 12:51:43 florian
  2737. + ansistring to pchar type cast fixed
  2738. Revision 1.26 1998/08/25 12:42:44 pierre
  2739. * CDECL changed to CVAR for variables
  2740. specifications are read in structures also
  2741. + started adding GPC compatibility mode ( option -Sp)
  2742. * names changed to lowercase
  2743. Revision 1.25 1998/08/23 21:04:38 florian
  2744. + rtti generation for classes added
  2745. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  2746. Revision 1.24 1998/08/20 12:53:26 peter
  2747. * object_options are always written for object syms
  2748. Revision 1.23 1998/08/19 00:42:42 peter
  2749. + subrange types for enums
  2750. + checking for bounds type with ranges
  2751. Revision 1.22 1998/08/17 10:10:10 peter
  2752. - removed OLDPPU
  2753. Revision 1.21 1998/08/10 14:50:28 peter
  2754. + localswitches, moduleswitches, globalswitches splitting
  2755. Revision 1.20 1998/07/18 22:54:30 florian
  2756. * some ansi/wide/longstring support fixed:
  2757. o parameter passing
  2758. o returning as result from functions
  2759. Revision 1.19 1998/07/14 14:47:05 peter
  2760. * released NEWINPUT
  2761. Revision 1.18 1998/07/10 10:51:04 peter
  2762. * m68k updates
  2763. Revision 1.16 1998/07/07 11:20:13 peter
  2764. + NEWINPUT for a better inputfile and scanner object
  2765. Revision 1.15 1998/06/24 14:48:37 peter
  2766. * ifdef newppu -> ifndef oldppu
  2767. Revision 1.14 1998/06/16 08:56:31 peter
  2768. + targetcpu
  2769. * cleaner pmodules for newppu
  2770. Revision 1.13 1998/06/15 15:38:09 pierre
  2771. * small bug in systems.pas corrected
  2772. + operators in different units better hanlded
  2773. Revision 1.12 1998/06/15 14:30:12 daniel
  2774. * Reverted my changes.
  2775. Revision 1.10 1998/06/13 00:10:16 peter
  2776. * working browser and newppu
  2777. * some small fixes against crashes which occured in bp7 (but not in
  2778. fpc?!)
  2779. Revision 1.9 1998/06/12 14:10:37 michael
  2780. * Fixed wrong code for ansistring
  2781. Revision 1.8 1998/06/11 10:11:58 peter
  2782. * -gb works again
  2783. Revision 1.7 1998/06/07 15:30:25 florian
  2784. + first working rtti
  2785. + data init/final. for local variables
  2786. Revision 1.6 1998/06/05 14:37:37 pierre
  2787. * fixes for inline for operators
  2788. * inline procedure more correctly restricted
  2789. Revision 1.5 1998/06/04 23:52:01 peter
  2790. * m68k compiles
  2791. + .def file creation moved to gendef.pas so it could also be used
  2792. for win32
  2793. Revision 1.4 1998/06/04 09:55:45 pierre
  2794. * demangled name of procsym reworked to become independant of the mangling
  2795. scheme
  2796. Revision 1.3 1998/06/03 22:49:03 peter
  2797. + wordbool,longbool
  2798. * rename bis,von -> high,low
  2799. * moved some systemunit loading/creating to psystem.pas
  2800. Revision 1.2 1998/05/31 14:13:37 peter
  2801. * fixed call bugs with assembler readers
  2802. + OPR_SYMBOL to hold a symbol in the asm parser
  2803. * fixed staticsymtable vars which were acessed through %ebp instead of
  2804. name
  2805. Revision 1.1 1998/05/27 19:45:09 peter
  2806. * symtable.pas splitted into includefiles
  2807. * symtable adapted for $ifndef OLDPPU
  2808. }