symdef.inc 115 KB

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