symdef.inc 113 KB

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