symdef.inc 112 KB

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