symdef.inc 88 KB

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