symdef.inc 97 KB

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