symdef.inc 118 KB

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