symdef.inc 89 KB

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