symdef.inc 114 KB

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