symdef.inc 97 KB

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