symdef.inc 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971
  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) and
  1705. assigned(pvarsym(s)^.vartype.def) then
  1706. begin
  1707. if ((pvarsym(s)^.vartype.def^.deftype<>objectdef) or
  1708. not(pobjectdef(pvarsym(s)^.vartype.def)^.is_class)) then
  1709. binittable:=pvarsym(s)^.vartype.def^.needs_inittable;
  1710. end;
  1711. end;
  1712. function trecorddef.needs_inittable : boolean;
  1713. var
  1714. oldb : boolean;
  1715. begin
  1716. { there are recursive calls to needs_rtti possible, }
  1717. { so we have to change to old value how else should }
  1718. { we do that ? check_rec_rtti can't be a nested }
  1719. { procedure of needs_rtti ! }
  1720. oldb:=binittable;
  1721. binittable:=false;
  1722. symtable^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  1723. needs_inittable:=binittable;
  1724. binittable:=oldb;
  1725. end;
  1726. procedure trecorddef.deref;
  1727. var
  1728. oldrecsyms : psymtable;
  1729. begin
  1730. oldrecsyms:=aktrecordsymtable;
  1731. aktrecordsymtable:=symtable;
  1732. { now dereference the definitions }
  1733. symtable^.deref;
  1734. aktrecordsymtable:=oldrecsyms;
  1735. end;
  1736. procedure trecorddef.write;
  1737. var
  1738. oldread_member : boolean;
  1739. begin
  1740. oldread_member:=read_member;
  1741. read_member:=true;
  1742. inherited write;
  1743. writelong(savesize);
  1744. current_ppu^.writeentry(ibrecorddef);
  1745. self.symtable^.writeas;
  1746. read_member:=oldread_member;
  1747. end;
  1748. function trecorddef.size:longint;
  1749. begin
  1750. size:=symtable^.datasize;
  1751. end;
  1752. function trecorddef.alignment:longint;
  1753. begin
  1754. alignment:=symtable^.dataalignment;
  1755. end;
  1756. {$ifdef GDB}
  1757. Const StabRecString : pchar = Nil;
  1758. StabRecSize : longint = 0;
  1759. RecOffset : Longint = 0;
  1760. procedure addname(p : pnamedindexobject);
  1761. var
  1762. news, newrec : pchar;
  1763. spec : string[3];
  1764. size : longint;
  1765. begin
  1766. { static variables from objects are like global objects }
  1767. if (sp_static in psym(p)^.symoptions) then
  1768. exit;
  1769. If psym(p)^.typ = varsym then
  1770. begin
  1771. if (sp_protected in psym(p)^.symoptions) then
  1772. spec:='/1'
  1773. else if (sp_private in psym(p)^.symoptions) then
  1774. spec:='/0'
  1775. else
  1776. spec:='';
  1777. { class fields are pointers PM }
  1778. if (pvarsym(p)^.vartype.def^.deftype=objectdef) and
  1779. pobjectdef(pvarsym(p)^.vartype.def)^.is_class then
  1780. spec:=spec+'*';
  1781. size:=pvarsym(p)^.vartype.def^.size;
  1782. { open arrays made overflows !! }
  1783. if size>$fffffff then
  1784. size:=$fffffff;
  1785. newrec := strpnew(p^.name+':'+spec+pvarsym(p)^.vartype.def^.numberstring
  1786. +','+tostr(pvarsym(p)^.address*8)+','
  1787. +tostr(size*8)+';');
  1788. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  1789. begin
  1790. getmem(news,stabrecsize+memsizeinc);
  1791. strcopy(news,stabrecstring);
  1792. freemem(stabrecstring,stabrecsize);
  1793. stabrecsize:=stabrecsize+memsizeinc;
  1794. stabrecstring:=news;
  1795. end;
  1796. strcat(StabRecstring,newrec);
  1797. strdispose(newrec);
  1798. {This should be used for case !!}
  1799. RecOffset := RecOffset + pvarsym(p)^.vartype.def^.size;
  1800. end;
  1801. end;
  1802. function trecorddef.stabstring : pchar;
  1803. Var oldrec : pchar;
  1804. oldsize : longint;
  1805. begin
  1806. oldrec := stabrecstring;
  1807. oldsize:=stabrecsize;
  1808. GetMem(stabrecstring,memsizeinc);
  1809. stabrecsize:=memsizeinc;
  1810. strpcopy(stabRecString,'s'+tostr(size));
  1811. RecOffset := 0;
  1812. symtable^.foreach({$ifndef TP}@{$endif}addname);
  1813. { FPC doesn't want to convert a char to a pchar}
  1814. { is this a bug ? }
  1815. strpcopy(strend(StabRecString),';');
  1816. stabstring := strnew(StabRecString);
  1817. Freemem(stabrecstring,stabrecsize);
  1818. stabrecstring := oldrec;
  1819. stabrecsize:=oldsize;
  1820. end;
  1821. procedure trecorddef.concatstabto(asmlist : paasmoutput);
  1822. begin
  1823. if (not assigned(typesym) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1824. (not is_def_stab_written) then
  1825. inherited concatstabto(asmlist);
  1826. end;
  1827. {$endif GDB}
  1828. var
  1829. count : longint;
  1830. procedure count_inittable_fields(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1831. begin
  1832. if ((psym(sym)^.typ=varsym) and
  1833. pvarsym(sym)^.vartype.def^.needs_inittable)
  1834. and ((pvarsym(sym)^.vartype.def^.deftype<>objectdef) or
  1835. (not pobjectdef(pvarsym(sym)^.vartype.def)^.is_class)) then
  1836. inc(count);
  1837. end;
  1838. procedure count_fields(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1839. begin
  1840. inc(count);
  1841. end;
  1842. procedure write_field_inittable(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1843. begin
  1844. if ((psym(sym)^.typ=varsym) and
  1845. pvarsym(sym)^.vartype.def^.needs_inittable) and
  1846. ((pvarsym(sym)^.vartype.def^.deftype<>objectdef) or
  1847. (not pobjectdef(pvarsym(sym)^.vartype.def)^.is_class)) then
  1848. begin
  1849. rttilist^.concat(new(pai_const_symbol,init(pvarsym(sym)^.vartype.def^.get_inittable_label)));
  1850. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1851. end;
  1852. end;
  1853. procedure write_field_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1854. begin
  1855. rttilist^.concat(new(pai_const_symbol,initname(pvarsym(sym)^.vartype.def^.get_rtti_label)));
  1856. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1857. end;
  1858. procedure generate_child_inittable(sym:pnamedindexobject);{$ifndef fpc}far;{$endif}
  1859. begin
  1860. if (psym(sym)^.typ=varsym) and
  1861. pvarsym(sym)^.vartype.def^.needs_inittable then
  1862. { force inittable generation }
  1863. pvarsym(sym)^.vartype.def^.get_inittable_label;
  1864. end;
  1865. procedure generate_child_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1866. begin
  1867. pvarsym(sym)^.vartype.def^.get_rtti_label;
  1868. end;
  1869. procedure trecorddef.write_child_rtti_data;
  1870. begin
  1871. symtable^.foreach({$ifndef TP}@{$endif}generate_child_rtti);
  1872. end;
  1873. procedure trecorddef.write_child_init_data;
  1874. begin
  1875. symtable^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  1876. end;
  1877. procedure trecorddef.write_rtti_data;
  1878. begin
  1879. rttilist^.concat(new(pai_const,init_8bit(tkrecord)));
  1880. write_rtti_name;
  1881. rttilist^.concat(new(pai_const,init_32bit(size)));
  1882. count:=0;
  1883. symtable^.foreach({$ifndef TP}@{$endif}count_fields);
  1884. rttilist^.concat(new(pai_const,init_32bit(count)));
  1885. symtable^.foreach({$ifndef TP}@{$endif}write_field_rtti);
  1886. end;
  1887. procedure trecorddef.write_init_data;
  1888. begin
  1889. rttilist^.concat(new(pai_const,init_8bit(14)));
  1890. write_rtti_name;
  1891. rttilist^.concat(new(pai_const,init_32bit(size)));
  1892. count:=0;
  1893. symtable^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  1894. rttilist^.concat(new(pai_const,init_32bit(count)));
  1895. symtable^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  1896. end;
  1897. function trecorddef.gettypename : string;
  1898. begin
  1899. gettypename:='<record type>'
  1900. end;
  1901. {***************************************************************************
  1902. TABSTRACTPROCDEF
  1903. ***************************************************************************}
  1904. constructor tabstractprocdef.init;
  1905. begin
  1906. inherited init;
  1907. new(para,init);
  1908. fpu_used:=0;
  1909. proctypeoption:=potype_none;
  1910. proccalloptions:=[];
  1911. procoptions:=[];
  1912. rettype.setdef(voiddef);
  1913. symtablelevel:=0;
  1914. savesize:=target_os.size_of_pointer;
  1915. end;
  1916. destructor tabstractprocdef.done;
  1917. begin
  1918. dispose(para,done);
  1919. inherited done;
  1920. end;
  1921. procedure tabstractprocdef.concatpara(tt:ttype;vsp : tvarspez);
  1922. var
  1923. hp : pparaitem;
  1924. begin
  1925. new(hp,init);
  1926. hp^.paratyp:=vsp;
  1927. hp^.paratype:=tt;
  1928. hp^.register:=R_NO;
  1929. para^.insert(hp);
  1930. end;
  1931. { all functions returning in FPU are
  1932. assume to use 2 FPU registers
  1933. until the function implementation
  1934. is processed PM }
  1935. procedure tabstractprocdef.test_if_fpu_result;
  1936. begin
  1937. if assigned(rettype.def) and is_fpu(rettype.def) then
  1938. fpu_used:=2;
  1939. end;
  1940. procedure tabstractprocdef.deref;
  1941. var
  1942. hp : pparaitem;
  1943. begin
  1944. inherited deref;
  1945. rettype.resolve;
  1946. hp:=pparaitem(para^.first);
  1947. while assigned(hp) do
  1948. begin
  1949. hp^.paratype.resolve;
  1950. hp:=pparaitem(hp^.next);
  1951. end;
  1952. end;
  1953. constructor tabstractprocdef.load;
  1954. var
  1955. hp : pparaitem;
  1956. count,i : word;
  1957. begin
  1958. inherited load;
  1959. new(para,init);
  1960. rettype.load;
  1961. fpu_used:=readbyte;
  1962. proctypeoption:=tproctypeoption(readlong);
  1963. readsmallset(proccalloptions);
  1964. readsmallset(procoptions);
  1965. count:=readword;
  1966. savesize:=target_os.size_of_pointer;
  1967. for i:=1 to count do
  1968. begin
  1969. new(hp,init);
  1970. hp^.paratyp:=tvarspez(readbyte);
  1971. { hp^.register:=tregister(readbyte); }
  1972. hp^.register:=R_NO;
  1973. hp^.paratype.load;
  1974. para^.concat(hp);
  1975. end;
  1976. end;
  1977. procedure tabstractprocdef.write;
  1978. var
  1979. hp : pparaitem;
  1980. begin
  1981. inherited write;
  1982. rettype.write;
  1983. current_ppu^.do_interface_crc:=false;
  1984. writebyte(fpu_used);
  1985. writelong(ord(proctypeoption));
  1986. writesmallset(proccalloptions);
  1987. writesmallset(procoptions);
  1988. writeword(para^.count);
  1989. hp:=pparaitem(para^.first);
  1990. while assigned(hp) do
  1991. begin
  1992. writebyte(byte(hp^.paratyp));
  1993. { writebyte(byte(hp^.register)); }
  1994. hp^.paratype.write;
  1995. hp:=pparaitem(hp^.next);
  1996. end;
  1997. end;
  1998. function tabstractprocdef.para_size : longint;
  1999. var
  2000. pdc : pparaitem;
  2001. l : longint;
  2002. begin
  2003. l:=0;
  2004. pdc:=pparaitem(para^.first);
  2005. while assigned(pdc) do
  2006. begin
  2007. case pdc^.paratyp of
  2008. vs_var : inc(l,target_os.size_of_pointer);
  2009. vs_value,
  2010. vs_const : if push_addr_param(pdc^.paratype.def) then
  2011. inc(l,target_os.size_of_pointer)
  2012. else
  2013. inc(l,align(pdc^.paratype.def^.size,target_os.stackalignment));
  2014. end;
  2015. pdc:=pparaitem(pdc^.next);
  2016. end;
  2017. para_size:=l;
  2018. end;
  2019. function tabstractprocdef.demangled_paras : string;
  2020. var
  2021. s : string;
  2022. hp : pparaitem;
  2023. begin
  2024. s:='(';
  2025. hp:=pparaitem(para^.last);
  2026. while assigned(hp) do
  2027. begin
  2028. if assigned(hp^.paratype.def^.typesym) then
  2029. s:=s+hp^.paratype.def^.typesym^.name
  2030. else if hp^.paratyp=vs_var then
  2031. s:=s+'var'
  2032. else if hp^.paratyp=vs_const then
  2033. s:=s+'const';
  2034. hp:=pparaitem(hp^.previous);
  2035. if assigned(hp) then
  2036. s:=s+',';
  2037. end;
  2038. s:=s+')';
  2039. demangled_paras:=s;
  2040. end;
  2041. function tabstractprocdef.proccalloption2str : string;
  2042. type
  2043. tproccallopt=record
  2044. mask : tproccalloption;
  2045. str : string[30];
  2046. end;
  2047. const
  2048. proccallopts=12;
  2049. proccallopt : array[1..proccallopts] of tproccallopt=(
  2050. (mask:pocall_none; str:''),
  2051. (mask:pocall_clearstack; str:'ClearStack'),
  2052. (mask:pocall_leftright; str:'LeftRight'),
  2053. (mask:pocall_cdecl; str:'Cdecl'),
  2054. (mask:pocall_register; str:'Register'),
  2055. (mask:pocall_stdcall; str:'StdCall'),
  2056. (mask:pocall_safecall; str:'SafeCall'),
  2057. (mask:pocall_palmossyscall;str:'PalmOSSysCall'),
  2058. (mask:pocall_system; str:'System'),
  2059. (mask:pocall_inline; str:'Inline'),
  2060. (mask:pocall_internproc; str:'InternProc'),
  2061. (mask:pocall_internconst; str:'InternConst')
  2062. );
  2063. var
  2064. s : string;
  2065. i : longint;
  2066. first : boolean;
  2067. begin
  2068. s:='';
  2069. first:=true;
  2070. for i:=1to proccallopts do
  2071. if (proccallopt[i].mask in proccalloptions) then
  2072. begin
  2073. if first then
  2074. first:=false
  2075. else
  2076. s:=s+';';
  2077. s:=s+proccallopt[i].str;
  2078. end;
  2079. proccalloption2str:=s;
  2080. end;
  2081. {$ifdef GDB}
  2082. function tabstractprocdef.stabstring : pchar;
  2083. begin
  2084. stabstring := strpnew('abstractproc'+numberstring+';');
  2085. end;
  2086. procedure tabstractprocdef.concatstabto(asmlist : paasmoutput);
  2087. begin
  2088. if (not assigned(typesym) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2089. and not is_def_stab_written then
  2090. begin
  2091. if assigned(rettype.def) then forcestabto(asmlist,rettype.def);
  2092. inherited concatstabto(asmlist);
  2093. end;
  2094. end;
  2095. {$endif GDB}
  2096. {***************************************************************************
  2097. TPROCDEF
  2098. ***************************************************************************}
  2099. constructor tprocdef.init;
  2100. begin
  2101. inherited init;
  2102. deftype:=procdef;
  2103. _mangledname:=nil;
  2104. nextoverloaded:=nil;
  2105. fileinfo:=aktfilepos;
  2106. extnumber:=-1;
  2107. localst:=new(psymtable,init(localsymtable));
  2108. parast:=new(psymtable,init(parasymtable));
  2109. localst^.defowner:=@self;
  2110. parast^.defowner:=@self;
  2111. { this is used by insert
  2112. to check same names in parast and localst }
  2113. localst^.next:=parast;
  2114. defref:=nil;
  2115. crossref:=nil;
  2116. lastwritten:=nil;
  2117. refcount:=0;
  2118. if (cs_browser in aktmoduleswitches) and make_ref then
  2119. begin
  2120. defref:=new(pref,init(defref,@tokenpos));
  2121. inc(refcount);
  2122. end;
  2123. lastref:=defref;
  2124. { first, we assume that all registers are used }
  2125. {$ifdef newcg}
  2126. usedregisters:=[firstreg..lastreg];
  2127. {$else newcg}
  2128. {$ifdef i386}
  2129. usedregisters:=$ff;
  2130. {$endif i386}
  2131. {$ifdef m68k}
  2132. usedregisters:=$FFFF;
  2133. {$endif}
  2134. {$endif newcg}
  2135. forwarddef:=true;
  2136. interfacedef:=false;
  2137. _class := nil;
  2138. code:=nil;
  2139. count:=false;
  2140. is_used:=false;
  2141. end;
  2142. constructor tprocdef.load;
  2143. var
  2144. s : string;
  2145. begin
  2146. inherited load;
  2147. deftype:=procdef;
  2148. {$ifdef newcg}
  2149. readnormalset(usedregisters);
  2150. {$else newcg}
  2151. {$ifdef i386}
  2152. usedregisters:=readbyte;
  2153. {$endif i386}
  2154. {$ifdef m68k}
  2155. usedregisters:=readword;
  2156. {$endif}
  2157. {$endif newcg}
  2158. s:=readstring;
  2159. setstring(_mangledname,s);
  2160. extnumber:=readlong;
  2161. nextoverloaded:=pprocdef(readdefref);
  2162. _class := pobjectdef(readdefref);
  2163. readposinfo(fileinfo);
  2164. if (cs_link_deffile in aktglobalswitches) and
  2165. (tf_need_export in target_info.flags) and
  2166. (po_exports in procoptions) then
  2167. deffile.AddExport(mangledname);
  2168. parast:=nil;
  2169. localst:=nil;
  2170. forwarddef:=false;
  2171. interfacedef:=false;
  2172. lastref:=nil;
  2173. lastwritten:=nil;
  2174. defref:=nil;
  2175. refcount:=0;
  2176. count:=true;
  2177. is_used:=false;
  2178. end;
  2179. Const local_symtable_index : longint = $8001;
  2180. procedure tprocdef.load_references;
  2181. var
  2182. pos : tfileposinfo;
  2183. {$ifndef NOLOCALBROWSER}
  2184. st : psymtable;
  2185. {$endif ndef NOLOCALBROWSER}
  2186. move_last : boolean;
  2187. begin
  2188. move_last:=lastwritten=lastref;
  2189. while (not current_ppu^.endofentry) do
  2190. begin
  2191. readposinfo(pos);
  2192. inc(refcount);
  2193. lastref:=new(pref,init(lastref,@pos));
  2194. lastref^.is_written:=true;
  2195. if refcount=1 then
  2196. defref:=lastref;
  2197. end;
  2198. if move_last then
  2199. lastwritten:=lastref;
  2200. if ((current_module^.flags and uf_local_browser)<>0)
  2201. and is_in_current then
  2202. begin
  2203. {$ifndef NOLOCALBROWSER}
  2204. st:=aktlocalsymtable;
  2205. new(parast,loadas(parasymtable));
  2206. parast^.defowner:=@self;
  2207. aktlocalsymtable:=parast;
  2208. parast^.deref;
  2209. parast^.next:=owner;
  2210. parast^.load_browser;
  2211. aktlocalsymtable:=st;
  2212. new(localst,loadas(localsymtable));
  2213. localst^.defowner:=@self;
  2214. aktlocalsymtable:=localst;
  2215. localst^.deref;
  2216. localst^.next:=parast;
  2217. localst^.load_browser;
  2218. aktlocalsymtable:=st;
  2219. {$endif ndef NOLOCALBROWSER}
  2220. end;
  2221. end;
  2222. function tprocdef.write_references : boolean;
  2223. var
  2224. ref : pref;
  2225. {$ifndef NOLOCALBROWSER}
  2226. st : psymtable;
  2227. pdo : pobjectdef;
  2228. {$endif ndef NOLOCALBROWSER}
  2229. move_last : boolean;
  2230. begin
  2231. move_last:=lastwritten=lastref;
  2232. if move_last and (((current_module^.flags and uf_local_browser)=0)
  2233. or not is_in_current) then
  2234. exit;
  2235. { write address of this symbol }
  2236. writedefref(@self);
  2237. { write refs }
  2238. if assigned(lastwritten) then
  2239. ref:=lastwritten
  2240. else
  2241. ref:=defref;
  2242. while assigned(ref) do
  2243. begin
  2244. if ref^.moduleindex=current_module^.unit_index then
  2245. begin
  2246. writeposinfo(ref^.posinfo);
  2247. ref^.is_written:=true;
  2248. if move_last then
  2249. lastwritten:=ref;
  2250. end
  2251. else if not ref^.is_written then
  2252. move_last:=false
  2253. else if move_last then
  2254. lastwritten:=ref;
  2255. ref:=ref^.nextref;
  2256. end;
  2257. current_ppu^.writeentry(ibdefref);
  2258. write_references:=true;
  2259. if ((current_module^.flags and uf_local_browser)<>0)
  2260. and is_in_current then
  2261. begin
  2262. {$ifndef NOLOCALBROWSER}
  2263. pdo:=_class;
  2264. if (owner^.symtabletype<>localsymtable) then
  2265. while assigned(pdo) do
  2266. begin
  2267. if pdo^.symtable<>aktrecordsymtable then
  2268. begin
  2269. pdo^.symtable^.unitid:=local_symtable_index;
  2270. inc(local_symtable_index);
  2271. end;
  2272. pdo:=pdo^.childof;
  2273. end;
  2274. { we need TESTLOCALBROWSER para and local symtables
  2275. PPU files are then easier to read PM }
  2276. if not assigned(parast) then
  2277. parast:=new(psymtable,init(parasymtable));
  2278. parast^.defowner:=@self;
  2279. st:=aktlocalsymtable;
  2280. aktlocalsymtable:=parast;
  2281. parast^.writeas;
  2282. parast^.unitid:=local_symtable_index;
  2283. inc(local_symtable_index);
  2284. parast^.write_browser;
  2285. if not assigned(localst) then
  2286. localst:=new(psymtable,init(localsymtable));
  2287. localst^.defowner:=@self;
  2288. aktlocalsymtable:=localst;
  2289. localst^.writeas;
  2290. localst^.unitid:=local_symtable_index;
  2291. inc(local_symtable_index);
  2292. localst^.write_browser;
  2293. aktlocalsymtable:=st;
  2294. { decrement for }
  2295. local_symtable_index:=local_symtable_index-2;
  2296. pdo:=_class;
  2297. if (owner^.symtabletype<>localsymtable) then
  2298. while assigned(pdo) do
  2299. begin
  2300. if pdo^.symtable<>aktrecordsymtable then
  2301. dec(local_symtable_index);
  2302. pdo:=pdo^.childof;
  2303. end;
  2304. {$endif ndef NOLOCALBROWSER}
  2305. end;
  2306. end;
  2307. {$ifdef BrowserLog}
  2308. procedure tprocdef.add_to_browserlog;
  2309. begin
  2310. if assigned(defref) then
  2311. begin
  2312. browserlog.AddLog('***'+mangledname);
  2313. browserlog.AddLogRefs(defref);
  2314. if (current_module^.flags and uf_local_browser)<>0 then
  2315. begin
  2316. if assigned(parast) then
  2317. parast^.writebrowserlog;
  2318. if assigned(localst) then
  2319. localst^.writebrowserlog;
  2320. end;
  2321. end;
  2322. end;
  2323. {$endif BrowserLog}
  2324. destructor tprocdef.done;
  2325. begin
  2326. if assigned(defref) then
  2327. dispose(defref,done);
  2328. if assigned(parast) then
  2329. dispose(parast,done);
  2330. if assigned(localst) and (localst^.symtabletype<>staticsymtable) then
  2331. dispose(localst,done);
  2332. if (pocall_inline in proccalloptions) and assigned(code) then
  2333. disposetree(ptree(code));
  2334. if (po_msgstr in procoptions) then
  2335. strdispose(messageinf.str);
  2336. if
  2337. {$ifdef tp}
  2338. not(use_big) and
  2339. {$endif}
  2340. assigned(_mangledname) then
  2341. strdispose(_mangledname);
  2342. inherited done;
  2343. end;
  2344. procedure tprocdef.write;
  2345. begin
  2346. inherited write;
  2347. current_ppu^.do_interface_crc:=false;
  2348. { set all registers to used for simplified compilation PM }
  2349. if simplify_ppu then
  2350. begin
  2351. {$ifdef newcg}
  2352. usedregisters:=[firstreg..lastreg];
  2353. {$else newcg}
  2354. {$ifdef i386}
  2355. usedregisters:=$ff;
  2356. {$endif i386}
  2357. {$ifdef m68k}
  2358. usedregisters:=$ffff;
  2359. {$endif}
  2360. {$endif newcg}
  2361. end;
  2362. {$ifdef newcg}
  2363. writenormalset(usedregisters);
  2364. {$else newcg}
  2365. {$ifdef i386}
  2366. writebyte(usedregisters);
  2367. {$endif i386}
  2368. {$ifdef m68k}
  2369. writeword(usedregisters);
  2370. {$endif}
  2371. {$endif newcg}
  2372. current_ppu^.do_interface_crc:=true;
  2373. writestring(mangledname);
  2374. writelong(extnumber);
  2375. if (proctypeoption<>potype_operator) then
  2376. writedefref(nextoverloaded)
  2377. else
  2378. begin
  2379. { only write the overloads from the same unit }
  2380. if assigned(nextoverloaded) and
  2381. (nextoverloaded^.owner=owner) then
  2382. writedefref(nextoverloaded)
  2383. else
  2384. writedefref(nil);
  2385. end;
  2386. writedefref(_class);
  2387. writeposinfo(fileinfo);
  2388. if (pocall_inline in proccalloptions) then
  2389. begin
  2390. { we need to save
  2391. - the para and the local symtable
  2392. - the code ptree !! PM
  2393. writesymtable(parast);
  2394. writesymtable(localst);
  2395. writeptree(ptree(code));
  2396. }
  2397. end;
  2398. current_ppu^.writeentry(ibprocdef);
  2399. end;
  2400. function tprocdef.haspara:boolean;
  2401. begin
  2402. haspara:=assigned(aktprocsym^.definition^.parast^.symindex^.first);
  2403. end;
  2404. {$ifdef GDB}
  2405. procedure addparaname(p : psym);
  2406. var vs : char;
  2407. begin
  2408. if pvarsym(p)^.varspez = vs_value then vs := '1'
  2409. else vs := '0';
  2410. strpcopy(strend(StabRecString),p^.name+':'+pvarsym(p)^.vartype.def^.numberstring+','+vs+';');
  2411. end;
  2412. function tprocdef.stabstring : pchar;
  2413. var
  2414. i : longint;
  2415. oldrec : pchar;
  2416. begin
  2417. oldrec := stabrecstring;
  2418. getmem(StabRecString,1024);
  2419. strpcopy(StabRecString,'f'+rettype.def^.numberstring);
  2420. i:=para^.count;
  2421. if i>0 then
  2422. begin
  2423. strpcopy(strend(StabRecString),','+tostr(i)+';');
  2424. (* confuse gdb !! PM
  2425. if assigned(parast) then
  2426. parast^.foreach({$ifndef TP}@{$endif}addparaname)
  2427. else
  2428. begin
  2429. param := para1;
  2430. i := 0;
  2431. while assigned(param) do
  2432. begin
  2433. inc(i);
  2434. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2435. {Here we have lost the parameter names !!}
  2436. {using lower case parameters }
  2437. strpcopy(strend(stabrecstring),'p'+tostr(i)
  2438. +':'+param^.paratype.def^.numberstring+','+vartyp+';');
  2439. param := param^.next;
  2440. end;
  2441. end; *)
  2442. {strpcopy(strend(StabRecString),';');}
  2443. end;
  2444. stabstring := strnew(stabrecstring);
  2445. freemem(stabrecstring,1024);
  2446. stabrecstring := oldrec;
  2447. end;
  2448. procedure tprocdef.concatstabto(asmlist : paasmoutput);
  2449. begin
  2450. end;
  2451. {$endif GDB}
  2452. procedure tprocdef.deref;
  2453. begin
  2454. inherited deref;
  2455. resolvedef(pdef(nextoverloaded));
  2456. resolvedef(pdef(_class));
  2457. end;
  2458. function tprocdef.mangledname : string;
  2459. {$ifdef tp}
  2460. var
  2461. oldpos : longint;
  2462. s : string;
  2463. b : byte;
  2464. {$endif tp}
  2465. begin
  2466. {$ifndef Delphi}
  2467. {$ifdef tp}
  2468. if use_big then
  2469. begin
  2470. symbolstream.seek(longint(_mangledname));
  2471. symbolstream.read(b,1);
  2472. symbolstream.read(s[1],b);
  2473. s[0]:=chr(b);
  2474. mangledname:=s;
  2475. end
  2476. else
  2477. {$endif}
  2478. {$endif Delphi}
  2479. mangledname:=strpas(_mangledname);
  2480. if count then
  2481. is_used:=true;
  2482. end;
  2483. function tprocdef.procname: string;
  2484. var
  2485. s : string;
  2486. l : longint;
  2487. begin
  2488. s:=mangledname;
  2489. { delete leading $$'s }
  2490. l:=pos('$$',s);
  2491. while l<>0 do
  2492. begin
  2493. delete(s,1,l+1);
  2494. l:=pos('$$',s);
  2495. end;
  2496. { delete leading _$'s }
  2497. l:=pos('_$',s);
  2498. while l<>0 do
  2499. begin
  2500. delete(s,1,l+1);
  2501. l:=pos('_$',s);
  2502. end;
  2503. l:=pos('$',s);
  2504. if l=0 then
  2505. procname:=s
  2506. else
  2507. procname:=Copy(s,1,l-1);
  2508. end;
  2509. {$IfDef GDB}
  2510. function tprocdef.cplusplusmangledname : string;
  2511. var
  2512. s,s2 : string;
  2513. param : pparaitem;
  2514. begin
  2515. s := typesym^.name;
  2516. if _class <> nil then
  2517. begin
  2518. s2 := _class^.objname^;
  2519. s := s+'__'+tostr(length(s2))+s2;
  2520. end else s := s + '_';
  2521. param := pparaitem(para^.first);
  2522. while assigned(param) do
  2523. begin
  2524. s2 := param^.paratype.def^.typesym^.name;
  2525. s := s+tostr(length(s2))+s2;
  2526. param := pparaitem(param^.next);
  2527. end;
  2528. cplusplusmangledname:=s;
  2529. end;
  2530. {$EndIf GDB}
  2531. procedure tprocdef.setmangledname(const s : string);
  2532. begin
  2533. if {$ifdef tp}not(use_big) and{$endif} (assigned(_mangledname)) then
  2534. strdispose(_mangledname);
  2535. setstring(_mangledname,s);
  2536. if assigned(parast) then
  2537. begin
  2538. stringdispose(parast^.name);
  2539. parast^.name:=stringdup('args of '+s);
  2540. end;
  2541. if assigned(localst) then
  2542. begin
  2543. stringdispose(localst^.name);
  2544. localst^.name:=stringdup('locals of '+s);
  2545. end;
  2546. end;
  2547. {***************************************************************************
  2548. TPROCVARDEF
  2549. ***************************************************************************}
  2550. constructor tprocvardef.init;
  2551. begin
  2552. inherited init;
  2553. deftype:=procvardef;
  2554. end;
  2555. constructor tprocvardef.load;
  2556. begin
  2557. inherited load;
  2558. deftype:=procvardef;
  2559. end;
  2560. procedure tprocvardef.write;
  2561. begin
  2562. { here we cannot get a real good value so just give something }
  2563. { plausible (PM) }
  2564. { a more secure way would be
  2565. to allways store in a temp }
  2566. if is_fpu(rettype.def) then
  2567. fpu_used:=2
  2568. else
  2569. fpu_used:=0;
  2570. inherited write;
  2571. current_ppu^.writeentry(ibprocvardef);
  2572. end;
  2573. function tprocvardef.size : longint;
  2574. begin
  2575. if (po_methodpointer in procoptions) then
  2576. size:=2*target_os.size_of_pointer
  2577. else
  2578. size:=target_os.size_of_pointer;
  2579. end;
  2580. {$ifdef GDB}
  2581. function tprocvardef.stabstring : pchar;
  2582. var
  2583. nss : pchar;
  2584. { i : longint; }
  2585. begin
  2586. { i := para^.count; }
  2587. getmem(nss,1024);
  2588. { it is not a function but a function pointer !! (PM) }
  2589. strpcopy(nss,'*f'+rettype.def^.numberstring{+','+tostr(i)}+';');
  2590. { this confuses gdb !!
  2591. we should use 'F' instead of 'f' but
  2592. as we use c++ language mode
  2593. it does not like that either
  2594. Please do not remove this part
  2595. might be used once
  2596. gdb for pascal is ready PM }
  2597. (*
  2598. param := para1;
  2599. i := 0;
  2600. while assigned(param) do
  2601. begin
  2602. inc(i);
  2603. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2604. {Here we have lost the parameter names !!}
  2605. pst := strpnew('p'+tostr(i)+':'+param^.paratype.def^.numberstring+','+vartyp+';');
  2606. strcat(nss,pst);
  2607. strdispose(pst);
  2608. param := param^.next;
  2609. end; *)
  2610. {strpcopy(strend(nss),';');}
  2611. stabstring := strnew(nss);
  2612. freemem(nss,1024);
  2613. end;
  2614. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  2615. begin
  2616. if ( not assigned(typesym) or typesym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2617. and not is_def_stab_written then
  2618. inherited concatstabto(asmlist);
  2619. is_def_stab_written:=true;
  2620. end;
  2621. {$endif GDB}
  2622. procedure tprocvardef.write_rtti_data;
  2623. var
  2624. pdc : pparaitem;
  2625. methodkind, paraspec : byte;
  2626. begin
  2627. if po_methodpointer in procoptions then
  2628. begin
  2629. { write method id and name }
  2630. rttilist^.concat(new(pai_const,init_8bit(tkmethod)));
  2631. write_rtti_name;
  2632. { write kind of method (can only be function or procedure)}
  2633. if rettype.def = pdef(voiddef) then { ### typecast shoudln't be necessary! (sg) }
  2634. methodkind := mkProcedure
  2635. else
  2636. methodkind := mkFunction;
  2637. rttilist^.concat(new(pai_const,init_8bit(methodkind)));
  2638. { get # of parameters }
  2639. rttilist^.concat(new(pai_const,init_8bit(para^.count)));
  2640. { write parameter info. The parameters must be written in reverse order
  2641. if this method uses right to left parameter pushing! }
  2642. if (pocall_leftright in proccalloptions) then
  2643. pdc:=pparaitem(para^.last)
  2644. else
  2645. pdc:=pparaitem(para^.first);
  2646. while assigned(pdc) do
  2647. begin
  2648. case pdc^.paratyp of
  2649. vs_value: paraspec := 0;
  2650. vs_const: paraspec := pfConst;
  2651. vs_var : paraspec := pfVar;
  2652. end;
  2653. { write flags for current parameter }
  2654. rttilist^.concat(new(pai_const,init_8bit(paraspec)));
  2655. { write name of current parameter ### how can I get this??? (sg)}
  2656. rttilist^.concat(new(pai_const,init_8bit(0)));
  2657. { write name of type of current parameter }
  2658. pdc^.paratype.def^.write_rtti_name;
  2659. if (pocall_leftright in proccalloptions) then
  2660. pdc:=pparaitem(pdc^.previous)
  2661. else
  2662. pdc:=pparaitem(pdc^.next);
  2663. end;
  2664. { write name of result type }
  2665. rettype.def^.write_rtti_name;
  2666. end;
  2667. end;
  2668. procedure tprocvardef.write_child_rtti_data;
  2669. begin
  2670. {!!!!!!!!}
  2671. end;
  2672. function tprocvardef.is_publishable : boolean;
  2673. begin
  2674. is_publishable:=(po_methodpointer in procoptions);
  2675. end;
  2676. function tprocvardef.gettypename : string;
  2677. begin
  2678. if assigned(rettype.def) and
  2679. (rettype.def<>pdef(voiddef)) then
  2680. gettypename:='<procedure variable type of function'+demangled_paras+
  2681. ':'+rettype.def^.gettypename+';'+proccalloption2str+'>'
  2682. else
  2683. gettypename:='<procedure variable type of procedure'+demangled_paras+
  2684. ';'+proccalloption2str+'>';
  2685. end;
  2686. {***************************************************************************
  2687. TOBJECTDEF
  2688. ***************************************************************************}
  2689. {$ifdef GDB}
  2690. const
  2691. vtabletype : word = 0;
  2692. vtableassigned : boolean = false;
  2693. {$endif GDB}
  2694. constructor tobjectdef.init(const n : string;c : pobjectdef);
  2695. begin
  2696. tdef.init;
  2697. deftype:=objectdef;
  2698. objectoptions:=[];
  2699. childof:=nil;
  2700. symtable:=new(psymtable,init(objectsymtable));
  2701. symtable^.name := stringdup(n);
  2702. { create space for vmt !! }
  2703. vmt_offset:=0;
  2704. symtable^.datasize:=0;
  2705. symtable^.defowner:=@self;
  2706. symtable^.dataalignment:=packrecordalignment[aktpackrecords];
  2707. set_parent(c);
  2708. objname:=stringdup(n);
  2709. end;
  2710. constructor tobjectdef.load;
  2711. var
  2712. oldread_member : boolean;
  2713. begin
  2714. tdef.load;
  2715. deftype:=objectdef;
  2716. savesize:=readlong;
  2717. vmt_offset:=readlong;
  2718. objname:=stringdup(readstring);
  2719. childof:=pobjectdef(readdefref);
  2720. readsmallset(objectoptions);
  2721. has_rtti:=boolean(readbyte);
  2722. oldread_member:=read_member;
  2723. read_member:=true;
  2724. symtable:=new(psymtable,loadas(objectsymtable));
  2725. read_member:=oldread_member;
  2726. symtable^.defowner:=@self;
  2727. symtable^.name := stringdup(objname^);
  2728. { handles the predefined class tobject }
  2729. { the last TOBJECT which is loaded gets }
  2730. { it ! }
  2731. if (childof=nil) and
  2732. is_class and
  2733. (objname^='TOBJECT') then
  2734. class_tobject:=@self;
  2735. end;
  2736. destructor tobjectdef.done;
  2737. begin
  2738. if assigned(symtable) then
  2739. dispose(symtable,done);
  2740. if (oo_is_forward in objectoptions) then
  2741. Message1(sym_e_class_forward_not_resolved,objname^);
  2742. stringdispose(objname);
  2743. tdef.done;
  2744. end;
  2745. procedure tobjectdef.write;
  2746. var
  2747. oldread_member : boolean;
  2748. begin
  2749. tdef.write;
  2750. writelong(size);
  2751. writelong(vmt_offset);
  2752. writestring(objname^);
  2753. writedefref(childof);
  2754. writesmallset(objectoptions);
  2755. writebyte(byte(has_rtti));
  2756. current_ppu^.writeentry(ibobjectdef);
  2757. oldread_member:=read_member;
  2758. read_member:=true;
  2759. symtable^.writeas;
  2760. read_member:=oldread_member;
  2761. end;
  2762. procedure tobjectdef.deref;
  2763. var
  2764. oldrecsyms : psymtable;
  2765. begin
  2766. resolvedef(pdef(childof));
  2767. oldrecsyms:=aktrecordsymtable;
  2768. aktrecordsymtable:=symtable;
  2769. symtable^.deref;
  2770. aktrecordsymtable:=oldrecsyms;
  2771. end;
  2772. procedure tobjectdef.set_parent( c : pobjectdef);
  2773. begin
  2774. { nothing to do if the parent was not forward !}
  2775. if assigned(childof) then
  2776. exit;
  2777. childof:=c;
  2778. { some options are inherited !! }
  2779. if assigned(c) then
  2780. begin
  2781. objectoptions:=objectoptions+(c^.objectoptions*
  2782. [oo_has_virtual,oo_has_private,oo_has_protected,oo_has_constructor,oo_has_destructor]);
  2783. { add the data of the anchestor class }
  2784. inc(symtable^.datasize,c^.symtable^.datasize);
  2785. if (oo_has_vmt in objectoptions) and
  2786. (oo_has_vmt in c^.objectoptions) then
  2787. dec(symtable^.datasize,target_os.size_of_pointer);
  2788. { if parent has a vmt field then
  2789. the offset is the same for the child PM }
  2790. if (oo_has_vmt in c^.objectoptions) or is_class then
  2791. begin
  2792. vmt_offset:=c^.vmt_offset;
  2793. {$ifdef INCLUDEOK}
  2794. include(objectoptions,oo_has_vmt);
  2795. {$else}
  2796. objectoptions:=objectoptions+[oo_has_vmt];
  2797. {$endif}
  2798. end;
  2799. end;
  2800. savesize := symtable^.datasize;
  2801. end;
  2802. procedure tobjectdef.insertvmt;
  2803. begin
  2804. if (oo_has_vmt in objectoptions) then
  2805. internalerror(12345)
  2806. else
  2807. begin
  2808. { first round up to multiple of 4 }
  2809. if (symtable^.dataalignment=2) then
  2810. begin
  2811. if (symtable^.datasize and 1)<>0 then
  2812. inc(symtable^.datasize);
  2813. end
  2814. else
  2815. if (symtable^.dataalignment>=4) then
  2816. begin
  2817. if (symtable^.datasize mod 4) <> 0 then
  2818. inc(symtable^.datasize,4-(symtable^.datasize mod 4));
  2819. end;
  2820. vmt_offset:=symtable^.datasize;
  2821. inc(symtable^.datasize,target_os.size_of_pointer);
  2822. {$ifdef INCLUDEOK}
  2823. include(objectoptions,oo_has_vmt);
  2824. {$else}
  2825. objectoptions:=objectoptions+[oo_has_vmt];
  2826. {$endif}
  2827. end;
  2828. end;
  2829. procedure tobjectdef.check_forwards;
  2830. begin
  2831. symtable^.check_forwards;
  2832. if (oo_is_forward in objectoptions) then
  2833. begin
  2834. { ok, in future, the forward can be resolved }
  2835. Message1(sym_e_class_forward_not_resolved,objname^);
  2836. {$ifdef INCLUDEOK}
  2837. exclude(objectoptions,oo_is_forward);
  2838. {$else}
  2839. objectoptions:=objectoptions-[oo_is_forward];
  2840. {$endif}
  2841. end;
  2842. end;
  2843. { true, if self inherits from d (or if they are equal) }
  2844. function tobjectdef.is_related(d : pobjectdef) : boolean;
  2845. var
  2846. hp : pobjectdef;
  2847. begin
  2848. hp:=@self;
  2849. while assigned(hp) do
  2850. begin
  2851. if hp=d then
  2852. begin
  2853. is_related:=true;
  2854. exit;
  2855. end;
  2856. hp:=hp^.childof;
  2857. end;
  2858. is_related:=false;
  2859. end;
  2860. function tobjectdef.size : longint;
  2861. begin
  2862. if (oo_is_class in objectoptions) then
  2863. size:=target_os.size_of_pointer
  2864. else
  2865. size:=symtable^.datasize;
  2866. end;
  2867. function tobjectdef.alignment:longint;
  2868. begin
  2869. alignment:=symtable^.dataalignment;
  2870. end;
  2871. function tobjectdef.vmtmethodoffset(index:longint):longint;
  2872. begin
  2873. { for offset of methods for classes, see rtl/inc/objpash.inc }
  2874. if is_class then
  2875. vmtmethodoffset:=(index+12)*target_os.size_of_pointer
  2876. else
  2877. vmtmethodoffset:=(index+3)*target_os.size_of_pointer;
  2878. end;
  2879. function tobjectdef.vmt_mangledname : string;
  2880. {DM: I get a nil pointer on the owner name. I don't know if this
  2881. mayhappen, and I have therefore fixed the problem by doing nil pointer
  2882. checks.}
  2883. var
  2884. s1,s2:string;
  2885. begin
  2886. if not(oo_has_vmt in objectoptions) then
  2887. Message1(parser_object_has_no_vmt,objname^);
  2888. if owner^.name=nil then
  2889. s1:=''
  2890. else
  2891. s1:=owner^.name^;
  2892. if objname=nil then
  2893. s2:=''
  2894. else
  2895. s2:=objname^;
  2896. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  2897. end;
  2898. function tobjectdef.rtti_name : string;
  2899. var
  2900. s1,s2:string;
  2901. begin
  2902. if owner^.name=nil then
  2903. s1:=''
  2904. else
  2905. s1:=owner^.name^;
  2906. if objname=nil then
  2907. s2:=''
  2908. else
  2909. s2:=objname^;
  2910. rtti_name:='RTTI_'+s1+'$_'+s2;
  2911. end;
  2912. function tobjectdef.is_class : boolean;
  2913. begin
  2914. is_class:=(oo_is_class in objectoptions);
  2915. end;
  2916. {$ifdef GDB}
  2917. procedure addprocname(p :pnamedindexobject);
  2918. var virtualind,argnames : string;
  2919. news, newrec : pchar;
  2920. pd,ipd : pprocdef;
  2921. lindex : longint;
  2922. para : pparaitem;
  2923. arglength : byte;
  2924. sp : char;
  2925. begin
  2926. If psym(p)^.typ = procsym then
  2927. begin
  2928. pd := pprocsym(p)^.definition;
  2929. { this will be used for full implementation of object stabs
  2930. not yet done }
  2931. ipd := pd;
  2932. while assigned(ipd^.nextoverloaded) do ipd := ipd^.nextoverloaded;
  2933. if (po_virtualmethod in pd^.procoptions) then
  2934. begin
  2935. lindex := pd^.extnumber;
  2936. {doesnt seem to be necessary
  2937. lindex := lindex or $80000000;}
  2938. virtualind := '*'+tostr(lindex)+';'+ipd^._class^.numberstring+';'
  2939. end else virtualind := '.';
  2940. { used by gdbpas to recognize constructor and destructors }
  2941. if (pd^.proctypeoption=potype_constructor) then
  2942. argnames:='__ct__'
  2943. else if (pd^.proctypeoption=potype_destructor) then
  2944. argnames:='__dt__'
  2945. else
  2946. argnames := '';
  2947. { arguments are not listed here }
  2948. {we don't need another definition}
  2949. para := pparaitem(pd^.para^.first);
  2950. while assigned(para) do
  2951. begin
  2952. if para^.paratype.def^.deftype = formaldef then
  2953. begin
  2954. if para^.paratyp=vs_var then
  2955. argnames := argnames+'3var'
  2956. else if para^.paratyp=vs_const then
  2957. argnames:=argnames+'5const';
  2958. end
  2959. else
  2960. begin
  2961. { if the arg definition is like (v: ^byte;..
  2962. there is no sym attached to data !!! }
  2963. if assigned(para^.paratype.def^.typesym) then
  2964. begin
  2965. arglength := length(para^.paratype.def^.typesym^.name);
  2966. argnames := argnames + tostr(arglength)+para^.paratype.def^.typesym^.name;
  2967. end
  2968. else
  2969. begin
  2970. argnames:=argnames+'11unnamedtype';
  2971. end;
  2972. end;
  2973. para := pparaitem(para^.next);
  2974. end;
  2975. ipd^.is_def_stab_written := true;
  2976. { here 2A must be changed for private and protected }
  2977. { 0 is private 1 protected and 2 public }
  2978. if (sp_private in psym(p)^.symoptions) then sp:='0'
  2979. else if (sp_protected in psym(p)^.symoptions) then sp:='1'
  2980. else sp:='2';
  2981. newrec := strpnew(p^.name+'::'+ipd^.numberstring
  2982. +'=##'+pd^.rettype.def^.numberstring+';:'+argnames+';'+sp+'A'
  2983. +virtualind+';');
  2984. { get spare place for a string at the end }
  2985. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2986. begin
  2987. getmem(news,stabrecsize+memsizeinc);
  2988. strcopy(news,stabrecstring);
  2989. freemem(stabrecstring,stabrecsize);
  2990. stabrecsize:=stabrecsize+memsizeinc;
  2991. stabrecstring:=news;
  2992. end;
  2993. strcat(StabRecstring,newrec);
  2994. {freemem(newrec,memsizeinc); }
  2995. strdispose(newrec);
  2996. {This should be used for case !!}
  2997. RecOffset := RecOffset + pd^.size;
  2998. end;
  2999. end;
  3000. function tobjectdef.stabstring : pchar;
  3001. var anc : pobjectdef;
  3002. oldrec : pchar;
  3003. oldrecsize : longint;
  3004. str_end : string;
  3005. begin
  3006. oldrec := stabrecstring;
  3007. oldrecsize:=stabrecsize;
  3008. stabrecsize:=memsizeinc;
  3009. GetMem(stabrecstring,stabrecsize);
  3010. strpcopy(stabRecString,'s'+tostr(symtable^.datasize));
  3011. if assigned(childof) then
  3012. {only one ancestor not virtual, public, at base offset 0 }
  3013. { !1 , 0 2 0 , }
  3014. strpcopy(strend(stabrecstring),'!1,020,'+childof^.numberstring+';');
  3015. {virtual table to implement yet}
  3016. RecOffset := 0;
  3017. symtable^.foreach({$ifndef TP}@{$endif}addname);
  3018. if (oo_has_vmt in objectoptions) then
  3019. if not assigned(childof) or not(oo_has_vmt in childof^.objectoptions) then
  3020. begin
  3021. strpcopy(strend(stabrecstring),'$vf'+numberstring+':'+typeglobalnumber('vtblarray')
  3022. +','+tostr(vmt_offset*8)+';');
  3023. end;
  3024. symtable^.foreach({$ifndef TP}@{$endif}addprocname);
  3025. if (oo_has_vmt in objectoptions) then
  3026. begin
  3027. anc := @self;
  3028. while assigned(anc^.childof) and (oo_has_vmt in anc^.childof^.objectoptions) do
  3029. anc := anc^.childof;
  3030. str_end:=';~%'+anc^.numberstring+';';
  3031. end
  3032. else
  3033. str_end:=';';
  3034. strpcopy(strend(stabrecstring),str_end);
  3035. stabstring := strnew(StabRecString);
  3036. freemem(stabrecstring,stabrecsize);
  3037. stabrecstring := oldrec;
  3038. stabrecsize:=oldrecsize;
  3039. end;
  3040. {$endif GDB}
  3041. procedure tobjectdef.write_child_init_data;
  3042. begin
  3043. symtable^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  3044. end;
  3045. procedure tobjectdef.write_init_data;
  3046. begin
  3047. if is_class then
  3048. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  3049. else
  3050. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  3051. { generate the name }
  3052. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  3053. rttilist^.concat(new(pai_string,init(objname^)));
  3054. rttilist^.concat(new(pai_const,init_32bit(size)));
  3055. count:=0;
  3056. symtable^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  3057. rttilist^.concat(new(pai_const,init_32bit(count)));
  3058. symtable^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  3059. end;
  3060. function tobjectdef.needs_inittable : boolean;
  3061. var
  3062. oldb : boolean;
  3063. begin
  3064. { there are recursive calls to needs_inittable possible, }
  3065. { so we have to change to old value how else should }
  3066. { we do that ? check_rec_rtti can't be a nested }
  3067. { procedure of needs_rtti ! }
  3068. oldb:=binittable;
  3069. binittable:=false;
  3070. symtable^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  3071. needs_inittable:=binittable;
  3072. binittable:=oldb;
  3073. end;
  3074. procedure count_published_properties(sym:pnamedindexobject);
  3075. {$ifndef fpc}far;{$endif}
  3076. begin
  3077. if needs_prop_entry(psym(sym)) then
  3078. inc(count);
  3079. end;
  3080. procedure write_property_info(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  3081. var
  3082. proctypesinfo : byte;
  3083. procedure writeproc(proc : psymlist; shiftvalue : byte);
  3084. var
  3085. typvalue : byte;
  3086. hp : psymlistitem;
  3087. address : longint;
  3088. begin
  3089. if not(assigned(proc) and assigned(proc^.firstsym)) then
  3090. begin
  3091. rttilist^.concat(new(pai_const,init_32bit(1)));
  3092. typvalue:=3;
  3093. end
  3094. else if proc^.firstsym^.sym^.typ=varsym then
  3095. begin
  3096. address:=0;
  3097. hp:=proc^.firstsym;
  3098. while assigned(hp) do
  3099. begin
  3100. inc(address,pvarsym(hp^.sym)^.address);
  3101. hp:=hp^.next;
  3102. end;
  3103. rttilist^.concat(new(pai_const,init_32bit(address)));
  3104. typvalue:=0;
  3105. end
  3106. else
  3107. begin
  3108. if not(po_virtualmethod in pprocdef(proc^.def)^.procoptions) then
  3109. begin
  3110. rttilist^.concat(new(pai_const_symbol,initname(pprocdef(proc^.def)^.mangledname)));
  3111. typvalue:=1;
  3112. end
  3113. else
  3114. begin
  3115. { virtual method, write vmt offset }
  3116. rttilist^.concat(new(pai_const,init_32bit(
  3117. pprocdef(proc^.def)^._class^.vmtmethodoffset(pprocdef(proc^.def)^.extnumber))));
  3118. typvalue:=2;
  3119. end;
  3120. end;
  3121. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  3122. end;
  3123. begin
  3124. if needs_prop_entry(psym(sym)) then
  3125. case psym(sym)^.typ of
  3126. varsym:
  3127. begin
  3128. if not(pvarsym(sym)^.vartype.def^.deftype=objectdef) or
  3129. not(pobjectdef(pvarsym(sym)^.vartype.def)^.is_class) then
  3130. internalerror(1509992);
  3131. { access to implicit class property as field }
  3132. proctypesinfo:=(0 shl 0) or (0 shl 2) or (0 shl 4);
  3133. rttilist^.concat(new(pai_const_symbol,initname(pvarsym(sym)^.vartype.def^.get_rtti_label)));
  3134. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  3135. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  3136. { per default stored }
  3137. rttilist^.concat(new(pai_const,init_32bit(1)));
  3138. { index as well as ... }
  3139. rttilist^.concat(new(pai_const,init_32bit(0)));
  3140. { default value are zero }
  3141. rttilist^.concat(new(pai_const,init_32bit(0)));
  3142. rttilist^.concat(new(pai_const,init_16bit(count)));
  3143. inc(count);
  3144. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  3145. rttilist^.concat(new(pai_const,init_8bit(length(pvarsym(sym)^.name))));
  3146. rttilist^.concat(new(pai_string,init(pvarsym(sym)^.name)));
  3147. end;
  3148. propertysym:
  3149. begin
  3150. if ppo_indexed in ppropertysym(sym)^.propoptions then
  3151. proctypesinfo:=$40
  3152. else
  3153. proctypesinfo:=0;
  3154. rttilist^.concat(new(pai_const_symbol,initname(ppropertysym(sym)^.proptype.def^.get_rtti_label)));
  3155. writeproc(ppropertysym(sym)^.readaccess,0);
  3156. writeproc(ppropertysym(sym)^.writeaccess,2);
  3157. { isn't it stored ? }
  3158. if not(ppo_stored in ppropertysym(sym)^.propoptions) then
  3159. begin
  3160. rttilist^.concat(new(pai_const,init_32bit(0)));
  3161. proctypesinfo:=proctypesinfo or (3 shl 4);
  3162. end
  3163. else
  3164. writeproc(ppropertysym(sym)^.storedaccess,4);
  3165. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.index)));
  3166. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.default)));
  3167. rttilist^.concat(new(pai_const,init_16bit(count)));
  3168. inc(count);
  3169. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  3170. rttilist^.concat(new(pai_const,init_8bit(length(ppropertysym(sym)^.name))));
  3171. rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
  3172. end;
  3173. else internalerror(1509992);
  3174. end;
  3175. end;
  3176. procedure generate_published_child_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  3177. begin
  3178. if needs_prop_entry(psym(sym)) then
  3179. case psym(sym)^.typ of
  3180. varsym:
  3181. pvarsym(sym)^.vartype.def^.get_rtti_label;
  3182. propertysym:
  3183. ppropertysym(sym)^.proptype.def^.get_rtti_label;
  3184. else
  3185. internalerror(1509991);
  3186. end;
  3187. end;
  3188. procedure tobjectdef.write_child_rtti_data;
  3189. begin
  3190. symtable^.foreach({$ifndef TP}@{$endif}generate_published_child_rtti);
  3191. end;
  3192. procedure tobjectdef.generate_rtti;
  3193. begin
  3194. has_rtti:=true;
  3195. getdatalabel(rtti_label);
  3196. write_child_rtti_data;
  3197. rttilist^.concat(new(pai_symbol,initname_global(rtti_name,0)));
  3198. rttilist^.concat(new(pai_label,init(rtti_label)));
  3199. write_rtti_data;
  3200. rttilist^.concat(new(pai_symbol_end,initname(rtti_name)));
  3201. end;
  3202. function tobjectdef.next_free_name_index : longint;
  3203. var
  3204. i : longint;
  3205. begin
  3206. if assigned(childof) and (oo_can_have_published in childof^.objectoptions) then
  3207. i:=childof^.next_free_name_index
  3208. else
  3209. i:=0;
  3210. count:=0;
  3211. symtable^.foreach({$ifndef TP}@{$endif}count_published_properties);
  3212. next_free_name_index:=i+count;
  3213. end;
  3214. procedure tobjectdef.write_rtti_data;
  3215. begin
  3216. if is_class then
  3217. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  3218. else
  3219. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  3220. { generate the name }
  3221. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  3222. rttilist^.concat(new(pai_string,init(objname^)));
  3223. { write class type }
  3224. rttilist^.concat(new(pai_const_symbol,initname(vmt_mangledname)));
  3225. { write owner typeinfo }
  3226. if assigned(childof) and (oo_can_have_published in childof^.objectoptions) then
  3227. rttilist^.concat(new(pai_const_symbol,initname(childof^.get_rtti_label)))
  3228. else
  3229. rttilist^.concat(new(pai_const,init_32bit(0)));
  3230. { count total number of properties }
  3231. if assigned(childof) and (oo_can_have_published in childof^.objectoptions) then
  3232. count:=childof^.next_free_name_index
  3233. else
  3234. count:=0;
  3235. { write it }
  3236. symtable^.foreach({$ifndef TP}@{$endif}count_published_properties);
  3237. rttilist^.concat(new(pai_const,init_16bit(count)));
  3238. { write unit name }
  3239. if assigned(owner^.name) then
  3240. begin
  3241. rttilist^.concat(new(pai_const,init_8bit(length(owner^.name^))));
  3242. rttilist^.concat(new(pai_string,init(owner^.name^)));
  3243. end
  3244. else
  3245. rttilist^.concat(new(pai_const,init_8bit(0)));
  3246. { write published properties count }
  3247. count:=0;
  3248. symtable^.foreach({$ifndef TP}@{$endif}count_published_properties);
  3249. rttilist^.concat(new(pai_const,init_16bit(count)));
  3250. { count is used to write nameindex }
  3251. { but we need an offset of the owner }
  3252. { to give each property an own slot }
  3253. if assigned(childof) and (oo_can_have_published in childof^.objectoptions) then
  3254. count:=childof^.next_free_name_index
  3255. else
  3256. count:=0;
  3257. symtable^.foreach({$ifndef TP}@{$endif}write_property_info);
  3258. end;
  3259. function tobjectdef.is_publishable : boolean;
  3260. begin
  3261. is_publishable:=is_class;
  3262. end;
  3263. function tobjectdef.get_rtti_label : string;
  3264. begin
  3265. if not(has_rtti) then
  3266. generate_rtti;
  3267. get_rtti_label:=rtti_name;
  3268. end;
  3269. {****************************************************************************
  3270. TFORWARDDEF
  3271. ****************************************************************************}
  3272. constructor tforwarddef.init(const s:string;const pos : tfileposinfo);
  3273. var
  3274. oldregisterdef : boolean;
  3275. begin
  3276. { never register the forwarddefs, they are disposed at the
  3277. end of the type declaration block }
  3278. oldregisterdef:=registerdef;
  3279. registerdef:=false;
  3280. inherited init;
  3281. registerdef:=oldregisterdef;
  3282. deftype:=forwarddef;
  3283. tosymname:=s;
  3284. forwardpos:=pos;
  3285. end;
  3286. function tforwarddef.gettypename:string;
  3287. begin
  3288. gettypename:='unresolved forward to '+tosymname;
  3289. end;
  3290. {****************************************************************************
  3291. TERRORDEF
  3292. ****************************************************************************}
  3293. constructor terrordef.init;
  3294. begin
  3295. inherited init;
  3296. deftype:=errordef;
  3297. end;
  3298. {$ifdef GDB}
  3299. function terrordef.stabstring : pchar;
  3300. begin
  3301. stabstring:=strpnew('error'+numberstring);
  3302. end;
  3303. {$endif GDB}
  3304. function terrordef.gettypename:string;
  3305. begin
  3306. gettypename:='<erroneous type>';
  3307. end;
  3308. {
  3309. $Log$
  3310. Revision 1.184 1999-12-31 14:24:34 peter
  3311. * fixed rtti generation for classes with no published section
  3312. Revision 1.183 1999/12/23 12:19:42 peter
  3313. * check_rec_inittable fix from sg
  3314. Revision 1.182 1999/12/19 17:00:27 peter
  3315. * has_rtti should be saved in the ppu for objects
  3316. Revision 1.181 1999/12/18 14:55:21 florian
  3317. * very basic widestring support
  3318. Revision 1.180 1999/12/06 18:21:03 peter
  3319. * support !ENVVAR for long commandlines
  3320. * win32/go32v2 write short pathnames to link.res so c:\Program Files\ is
  3321. finally supported as installdir.
  3322. Revision 1.179 1999/12/01 12:42:33 peter
  3323. * fixed bug 698
  3324. * removed some notes about unused vars
  3325. Revision 1.178 1999/12/01 10:26:38 pierre
  3326. * restore the correct way for stabs of forward defs
  3327. Revision 1.177 1999/11/30 10:40:54 peter
  3328. + ttype, tsymlist
  3329. Revision 1.176 1999/11/09 23:35:49 pierre
  3330. + better reference pos for forward defs
  3331. Revision 1.175 1999/11/07 23:57:36 pierre
  3332. + higher level browser
  3333. Revision 1.174 1999/11/06 14:34:26 peter
  3334. * truncated log to 20 revs
  3335. Revision 1.173 1999/11/05 17:18:02 pierre
  3336. * local browsing works at first level
  3337. ie for function defined in interface or implementation
  3338. not yet for functions inside other functions
  3339. Revision 1.172 1999/10/26 12:30:45 peter
  3340. * const parameter is now checked
  3341. * better and generic check if a node can be used for assigning
  3342. * export fixes
  3343. * procvar equal works now (it never had worked at least from 0.99.8)
  3344. * defcoll changed to linkedlist with pparaitem so it can easily be
  3345. walked both directions
  3346. Revision 1.171 1999/10/06 17:39:15 peter
  3347. * fixed stabs writting for forward types
  3348. Revision 1.170 1999/10/04 13:46:04 michael
  3349. * patch from peter for classes
  3350. Revision 1.169 1999/10/03 19:41:38 peter
  3351. * inittable for record fixed (it was only checking for classes)
  3352. Revision 1.168 1999/10/01 10:05:44 peter
  3353. + procedure directive support in const declarations, fixes bug 232
  3354. Revision 1.167 1999/10/01 08:02:48 peter
  3355. * forward type declaration rewritten
  3356. Revision 1.166 1999/09/26 21:30:21 peter
  3357. + constant pointer support which can happend with typecasting like
  3358. const p=pointer(1)
  3359. * better procvar parsing in typed consts
  3360. Revision 1.165 1999/09/20 16:39:02 peter
  3361. * cs_create_smart instead of cs_smartlink
  3362. * -CX is create smartlink
  3363. * -CD is create dynamic, but does nothing atm.
  3364. Revision 1.164 1999/09/15 22:09:26 florian
  3365. + rtti is now automatically generated for published classes, i.e.
  3366. they are handled like an implicit property
  3367. Revision 1.163 1999/09/15 20:35:44 florian
  3368. * small fix to operator overloading when in MMX mode
  3369. + the compiler uses now fldz and fld1 if possible
  3370. + some fixes to floating point registers
  3371. + some math. functions (arctan, ln, sin, cos, sqrt, sqr, pi) are now inlined
  3372. * .... ???
  3373. Revision 1.162 1999/09/12 08:48:09 florian
  3374. * bugs 593 and 607 fixed
  3375. * some other potential bugs with array constructors fixed
  3376. * for classes compiled in $M+ and it's childs, the default access method
  3377. is now published
  3378. * fixed copyright message (it is now 1993-99)
  3379. Revision 1.161 1999/09/10 18:48:09 florian
  3380. * some bug fixes (e.g. must_be_valid and procinfo.funcret_is_valid)
  3381. * most things for stored properties fixed
  3382. Revision 1.160 1999/09/02 17:07:40 florian
  3383. * problems with -Or fixed: tdef.isfpuregable was wrong!
  3384. Revision 1.159 1999/08/27 10:52:19 pierre
  3385. + simplify_ppu code added :
  3386. sets all registers used at PPU writing
  3387. * tprocdef mangledname writing is CRC relevant
  3388. Revision 1.158 1999/08/27 10:24:34 michael
  3389. + Inittables should not contain fields which are classes
  3390. Revision 1.157 1999/08/26 21:13:58 peter
  3391. * array elementsize of 0 doesn't crash anymore
  3392. Revision 1.156 1999/08/17 13:58:56 michael
  3393. RTTI writing patch
  3394. Revision 1.155 1999/08/16 16:26:04 pierre
  3395. * error in stabs for tclassrefdef corrected
  3396. Revision 1.154 1999/08/14 00:38:58 peter
  3397. * hack to support property with record fields
  3398. }