symdef.inc 118 KB

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