symdef.inc 140 KB

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