symdef.inc 116 KB

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