symdef.inc 120 KB

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