symdef.inc 114 KB

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