symdef.inc 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096
  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,s64bitint:
  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. s64bitint : 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. stabstring := strpnew('S'+setof^.numberstring);
  1342. end;
  1343. procedure tsetdef.concatstabto(asmlist : paasmoutput);
  1344. begin
  1345. if ( not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1346. not is_def_stab_written then
  1347. begin
  1348. if assigned(setof) then
  1349. forcestabto(asmlist,setof);
  1350. inherited concatstabto(asmlist);
  1351. end;
  1352. end;
  1353. {$endif GDB}
  1354. procedure tsetdef.deref;
  1355. begin
  1356. resolvedef(setof);
  1357. end;
  1358. procedure tsetdef.write_rtti_data;
  1359. begin
  1360. rttilist^.concat(new(pai_const,init_8bit(tkSet)));
  1361. write_rtti_name;
  1362. rttilist^.concat(new(pai_const,init_8bit(otULong)));
  1363. rttilist^.concat(new(pai_const_symbol,initname(setof^.get_rtti_label)));
  1364. end;
  1365. procedure tsetdef.write_child_rtti_data;
  1366. begin
  1367. setof^.get_rtti_label;
  1368. end;
  1369. function tsetdef.is_publishable : boolean;
  1370. begin
  1371. is_publishable:=settype=smallset;
  1372. end;
  1373. function tsetdef.gettypename : string;
  1374. begin
  1375. gettypename:='Set Of '+setof^.typename;
  1376. end;
  1377. {***************************************************************************
  1378. TFORMALDEF
  1379. ***************************************************************************}
  1380. constructor tformaldef.init;
  1381. var
  1382. stregdef : boolean;
  1383. begin
  1384. stregdef:=registerdef;
  1385. registerdef:=false;
  1386. inherited init;
  1387. deftype:=formaldef;
  1388. registerdef:=stregdef;
  1389. { formaldef must be registered at unit level !! }
  1390. if registerdef and assigned(current_module) then
  1391. if assigned(current_module^.localsymtable) then
  1392. psymtable(current_module^.localsymtable)^.registerdef(@self)
  1393. else if assigned(current_module^.globalsymtable) then
  1394. psymtable(current_module^.globalsymtable)^.registerdef(@self);
  1395. savesize:=target_os.size_of_pointer;
  1396. end;
  1397. constructor tformaldef.load;
  1398. begin
  1399. inherited load;
  1400. deftype:=formaldef;
  1401. savesize:=target_os.size_of_pointer;
  1402. end;
  1403. procedure tformaldef.write;
  1404. begin
  1405. inherited write;
  1406. current_ppu^.writeentry(ibformaldef);
  1407. end;
  1408. {$ifdef GDB}
  1409. function tformaldef.stabstring : pchar;
  1410. begin
  1411. stabstring := strpnew('formal'+numberstring+';');
  1412. end;
  1413. procedure tformaldef.concatstabto(asmlist : paasmoutput);
  1414. begin
  1415. { formaldef can't be stab'ed !}
  1416. end;
  1417. {$endif GDB}
  1418. function tformaldef.gettypename : string;
  1419. begin
  1420. gettypename:='Var';
  1421. end;
  1422. {***************************************************************************
  1423. TARRAYDEF
  1424. ***************************************************************************}
  1425. constructor tarraydef.init(l,h : longint;rd : pdef);
  1426. begin
  1427. inherited init;
  1428. deftype:=arraydef;
  1429. lowrange:=l;
  1430. highrange:=h;
  1431. rangedef:=rd;
  1432. definition:=nil;
  1433. IsVariant:=false;
  1434. IsConstructor:=false;
  1435. IsArrayOfConst:=false;
  1436. rangenr:=0;
  1437. end;
  1438. constructor tarraydef.load;
  1439. begin
  1440. inherited load;
  1441. deftype:=arraydef;
  1442. { the addresses are calculated later }
  1443. definition:=readdefref;
  1444. rangedef:=readdefref;
  1445. lowrange:=readlong;
  1446. highrange:=readlong;
  1447. IsArrayOfConst:=boolean(readbyte);
  1448. IsVariant:=false;
  1449. IsConstructor:=false;
  1450. rangenr:=0;
  1451. end;
  1452. function tarraydef.getrangecheckstring : string;
  1453. begin
  1454. if (cs_smartlink in aktmoduleswitches) then
  1455. getrangecheckstring:='R_'+current_module^.modulename^+tostr(rangenr)
  1456. else
  1457. getrangecheckstring:='R_'+tostr(rangenr);
  1458. end;
  1459. procedure tarraydef.genrangecheck;
  1460. begin
  1461. if rangenr=0 then
  1462. begin
  1463. { generates the data for range checking }
  1464. getlabelnr(rangenr);
  1465. if (cs_smartlink in aktmoduleswitches) then
  1466. datasegment^.concat(new(pai_symbol,initname_global(getrangecheckstring,8)))
  1467. else
  1468. datasegment^.concat(new(pai_symbol,initname(getrangecheckstring,8)));
  1469. datasegment^.concat(new(pai_const,init_32bit(lowrange)));
  1470. datasegment^.concat(new(pai_const,init_32bit(highrange)));
  1471. end;
  1472. end;
  1473. procedure tarraydef.deref;
  1474. begin
  1475. resolvedef(definition);
  1476. resolvedef(rangedef);
  1477. end;
  1478. procedure tarraydef.write;
  1479. begin
  1480. inherited write;
  1481. writedefref(definition);
  1482. writedefref(rangedef);
  1483. writelong(lowrange);
  1484. writelong(highrange);
  1485. writebyte(byte(IsArrayOfConst));
  1486. current_ppu^.writeentry(ibarraydef);
  1487. end;
  1488. {$ifdef GDB}
  1489. function tarraydef.stabstring : pchar;
  1490. begin
  1491. stabstring := strpnew('ar'+rangedef^.numberstring+';'
  1492. +tostr(lowrange)+';'+tostr(highrange)+';'+definition^.numberstring);
  1493. end;
  1494. procedure tarraydef.concatstabto(asmlist : paasmoutput);
  1495. begin
  1496. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  1497. and not is_def_stab_written then
  1498. begin
  1499. {when array are inserted they have no definition yet !!}
  1500. if assigned(definition) then
  1501. inherited concatstabto(asmlist);
  1502. end;
  1503. end;
  1504. {$endif GDB}
  1505. function tarraydef.elesize : longint;
  1506. begin
  1507. elesize:=definition^.size;
  1508. end;
  1509. function tarraydef.size : longint;
  1510. begin
  1511. { dirty hack to overcome an overflow (PFV) }
  1512. if highrange=$7fffffff then
  1513. size:=$7fffffff
  1514. else
  1515. size:=(highrange-lowrange+1)*elesize;
  1516. end;
  1517. function tarraydef.alignment : longint;
  1518. begin
  1519. { alignment is the size of the elements }
  1520. alignment:=definition^.size;
  1521. end;
  1522. function tarraydef.needs_inittable : boolean;
  1523. begin
  1524. needs_inittable:=definition^.needs_inittable;
  1525. end;
  1526. procedure tarraydef.write_child_rtti_data;
  1527. begin
  1528. definition^.get_rtti_label;
  1529. end;
  1530. procedure tarraydef.write_rtti_data;
  1531. begin
  1532. rttilist^.concat(new(pai_const,init_8bit(13)));
  1533. write_rtti_name;
  1534. { size of elements }
  1535. rttilist^.concat(new(pai_const,init_32bit(definition^.size)));
  1536. { count of elements }
  1537. rttilist^.concat(new(pai_const,init_32bit(highrange-lowrange+1)));
  1538. { element type }
  1539. rttilist^.concat(new(pai_const_symbol,initname(definition^.get_rtti_label)));
  1540. end;
  1541. function tarraydef.gettypename : string;
  1542. begin
  1543. if isarrayofconst or isConstructor then
  1544. gettypename:='Array Of Const'
  1545. else if is_open_array(@self) then
  1546. gettypename:='Array Of '+definition^.typename
  1547. else
  1548. begin
  1549. if rangedef^.deftype=enumdef then
  1550. gettypename:='Array['+rangedef^.typename+'] Of '+definition^.typename
  1551. else
  1552. gettypename:='Array['+tostr(lowrange)+'..'+
  1553. tostr(highrange)+'] Of '+definition^.typename
  1554. end;
  1555. end;
  1556. {***************************************************************************
  1557. TRECDEF
  1558. ***************************************************************************}
  1559. constructor trecdef.init(p : psymtable);
  1560. begin
  1561. inherited init;
  1562. deftype:=recorddef;
  1563. symtable:=p;
  1564. symtable^.defowner := @self;
  1565. symtable^.dataalignment:=packrecordalignment[aktpackrecords];
  1566. end;
  1567. constructor trecdef.load;
  1568. var
  1569. oldread_member : boolean;
  1570. begin
  1571. inherited load;
  1572. deftype:=recorddef;
  1573. savesize:=readlong;
  1574. oldread_member:=read_member;
  1575. read_member:=true;
  1576. symtable:=new(psymtable,loadas(recordsymtable));
  1577. read_member:=oldread_member;
  1578. symtable^.defowner := @self;
  1579. end;
  1580. destructor trecdef.done;
  1581. begin
  1582. if assigned(symtable) then
  1583. dispose(symtable,done);
  1584. inherited done;
  1585. end;
  1586. var
  1587. binittable : boolean;
  1588. procedure check_rec_inittable(s : pnamedindexobject);
  1589. begin
  1590. if (psym(s)^.typ=varsym) and
  1591. ((pvarsym(s)^.definition^.deftype<>objectdef) or
  1592. not(pobjectdef(pvarsym(s)^.definition)^.isclass)) then
  1593. binittable:=pvarsym(s)^.definition^.needs_inittable;
  1594. end;
  1595. function trecdef.needs_inittable : boolean;
  1596. var
  1597. oldb : boolean;
  1598. begin
  1599. { there are recursive calls to needs_rtti possible, }
  1600. { so we have to change to old value how else should }
  1601. { we do that ? check_rec_rtti can't be a nested }
  1602. { procedure of needs_rtti ! }
  1603. oldb:=binittable;
  1604. binittable:=false;
  1605. symtable^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  1606. needs_inittable:=binittable;
  1607. binittable:=oldb;
  1608. end;
  1609. procedure trecdef.deref;
  1610. var
  1611. oldrecsyms : psymtable;
  1612. begin
  1613. oldrecsyms:=aktrecordsymtable;
  1614. aktrecordsymtable:=symtable;
  1615. { now dereference the definitions }
  1616. symtable^.deref;
  1617. aktrecordsymtable:=oldrecsyms;
  1618. end;
  1619. procedure trecdef.write;
  1620. var
  1621. oldread_member : boolean;
  1622. begin
  1623. oldread_member:=read_member;
  1624. read_member:=true;
  1625. inherited write;
  1626. writelong(savesize);
  1627. current_ppu^.writeentry(ibrecorddef);
  1628. self.symtable^.writeas;
  1629. read_member:=oldread_member;
  1630. end;
  1631. function trecdef.size:longint;
  1632. begin
  1633. size:=symtable^.datasize;
  1634. end;
  1635. function trecdef.alignment:longint;
  1636. begin
  1637. alignment:=symtable^.dataalignment;
  1638. end;
  1639. {$ifdef GDB}
  1640. Const StabRecString : pchar = Nil;
  1641. StabRecSize : longint = 0;
  1642. RecOffset : Longint = 0;
  1643. procedure addname(p : pnamedindexobject);
  1644. var
  1645. news, newrec : pchar;
  1646. spec : string[2];
  1647. size : longint;
  1648. begin
  1649. { static variables from objects are like global objects }
  1650. if ((psym(p)^.properties and sp_static)<>0) then
  1651. exit;
  1652. if ((psym(p)^.properties and sp_protected)<>0) then
  1653. spec:='/1'
  1654. else if ((psym(p)^.properties and sp_private)<>0) then
  1655. spec:='/0'
  1656. else
  1657. spec:='';
  1658. If psym(p)^.typ = varsym then
  1659. begin
  1660. size:=pvarsym(p)^.definition^.size;
  1661. { open arrays made overflows !! }
  1662. if size>$fffffff then
  1663. size:=$fffffff;
  1664. newrec := strpnew(p^.name+':'+spec+pvarsym(p)^.definition^.numberstring
  1665. +','+tostr(pvarsym(p)^.address*8)+','
  1666. +tostr(size*8)+';');
  1667. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  1668. begin
  1669. getmem(news,stabrecsize+memsizeinc);
  1670. strcopy(news,stabrecstring);
  1671. freemem(stabrecstring,stabrecsize);
  1672. stabrecsize:=stabrecsize+memsizeinc;
  1673. stabrecstring:=news;
  1674. end;
  1675. strcat(StabRecstring,newrec);
  1676. strdispose(newrec);
  1677. {This should be used for case !!}
  1678. RecOffset := RecOffset + pvarsym(p)^.definition^.size;
  1679. end;
  1680. end;
  1681. function trecdef.stabstring : pchar;
  1682. Var oldrec : pchar;
  1683. oldsize : longint;
  1684. begin
  1685. oldrec := stabrecstring;
  1686. oldsize:=stabrecsize;
  1687. GetMem(stabrecstring,memsizeinc);
  1688. stabrecsize:=memsizeinc;
  1689. strpcopy(stabRecString,'s'+tostr(size));
  1690. RecOffset := 0;
  1691. symtable^.foreach({$ifndef TP}@{$endif}addname);
  1692. { FPC doesn't want to convert a char to a pchar}
  1693. { is this a bug ? }
  1694. strpcopy(strend(StabRecString),';');
  1695. stabstring := strnew(StabRecString);
  1696. Freemem(stabrecstring,stabrecsize);
  1697. stabrecstring := oldrec;
  1698. stabrecsize:=oldsize;
  1699. end;
  1700. procedure trecdef.concatstabto(asmlist : paasmoutput);
  1701. begin
  1702. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches)) and
  1703. (not is_def_stab_written) then
  1704. inherited concatstabto(asmlist);
  1705. end;
  1706. {$endif GDB}
  1707. var
  1708. count : longint;
  1709. procedure count_inittable_fields(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1710. begin
  1711. if (psym(sym)^.typ=varsym) and
  1712. (pvarsym(sym)^.definition^.needs_inittable) then
  1713. inc(count);
  1714. end;
  1715. procedure count_fields(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1716. begin
  1717. inc(count);
  1718. end;
  1719. procedure write_field_inittable(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1720. begin
  1721. if (psym(sym)^.typ=varsym) and
  1722. pvarsym(sym)^.definition^.needs_inittable then
  1723. begin
  1724. rttilist^.concat(new(pai_const_symbol,init(pvarsym(sym)^.definition^.get_inittable_label)));
  1725. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1726. end;
  1727. end;
  1728. procedure write_field_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1729. begin
  1730. rttilist^.concat(new(pai_const_symbol,initname(pvarsym(sym)^.definition^.get_rtti_label)));
  1731. rttilist^.concat(new(pai_const,init_32bit(pvarsym(sym)^.address)));
  1732. end;
  1733. procedure generate_child_inittable(sym:pnamedindexobject);{$ifndef fpc}far;{$endif}
  1734. begin
  1735. if (psym(sym)^.typ=varsym) and
  1736. pvarsym(sym)^.definition^.needs_inittable then
  1737. { force inittable generation }
  1738. pvarsym(sym)^.definition^.get_inittable_label;
  1739. end;
  1740. procedure generate_child_rtti(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  1741. begin
  1742. pvarsym(sym)^.definition^.get_rtti_label;
  1743. end;
  1744. procedure trecdef.write_child_rtti_data;
  1745. begin
  1746. symtable^.foreach({$ifndef TP}@{$endif}generate_child_rtti);
  1747. end;
  1748. procedure trecdef.write_child_init_data;
  1749. begin
  1750. symtable^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  1751. end;
  1752. procedure trecdef.write_rtti_data;
  1753. begin
  1754. rttilist^.concat(new(pai_const,init_8bit(tkrecord)));
  1755. write_rtti_name;
  1756. rttilist^.concat(new(pai_const,init_32bit(size)));
  1757. count:=0;
  1758. symtable^.foreach({$ifndef TP}@{$endif}count_fields);
  1759. rttilist^.concat(new(pai_const,init_32bit(count)));
  1760. symtable^.foreach({$ifndef TP}@{$endif}write_field_rtti);
  1761. end;
  1762. procedure trecdef.write_init_data;
  1763. begin
  1764. rttilist^.concat(new(pai_const,init_8bit(14)));
  1765. write_rtti_name;
  1766. rttilist^.concat(new(pai_const,init_32bit(size)));
  1767. count:=0;
  1768. symtable^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  1769. rttilist^.concat(new(pai_const,init_32bit(count)));
  1770. symtable^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  1771. end;
  1772. function trecdef.gettypename : string;
  1773. begin
  1774. gettypename:='<record type>'
  1775. end;
  1776. {***************************************************************************
  1777. TABSTRACTPROCDEF
  1778. ***************************************************************************}
  1779. constructor tabstractprocdef.init;
  1780. begin
  1781. inherited init;
  1782. para1:=nil;
  1783. fpu_used:=0;
  1784. options:=0;
  1785. retdef:=voiddef;
  1786. savesize:=target_os.size_of_pointer;
  1787. end;
  1788. procedure disposepdefcoll(var para1 : pdefcoll);
  1789. var
  1790. hp : pdefcoll;
  1791. begin
  1792. hp:=para1;
  1793. while assigned(hp) do
  1794. begin
  1795. para1:=hp^.next;
  1796. dispose(hp);
  1797. hp:=para1;
  1798. end;
  1799. end;
  1800. destructor tabstractprocdef.done;
  1801. begin
  1802. disposepdefcoll(para1);
  1803. inherited done;
  1804. end;
  1805. procedure tabstractprocdef.concatdef(p : pdef;vsp : tvarspez);
  1806. var
  1807. hp : pdefcoll;
  1808. begin
  1809. new(hp);
  1810. hp^.paratyp:=vsp;
  1811. hp^.datasym:=nil;
  1812. hp^.data:=p;
  1813. hp^.next:=para1;
  1814. hp^.register:=R_NO;
  1815. para1:=hp;
  1816. end;
  1817. procedure tabstractprocdef.concattypesym(p : ptypesym;vsp : tvarspez);
  1818. var
  1819. hp : pdefcoll;
  1820. begin
  1821. new(hp);
  1822. hp^.paratyp:=vsp;
  1823. hp^.datasym:=p;
  1824. hp^.data:=p^.definition;
  1825. hp^.next:=para1;
  1826. hp^.register:=R_NO;
  1827. para1:=hp;
  1828. end;
  1829. { all functions returning in FPU are
  1830. assume to use 2 FPU registers
  1831. until the function implementation
  1832. is processed PM }
  1833. procedure tabstractprocdef.test_if_fpu_result;
  1834. begin
  1835. if assigned(retdef) and is_fpu(retdef) then
  1836. fpu_used:=2;
  1837. end;
  1838. procedure tabstractprocdef.deref;
  1839. var
  1840. hp : pdefcoll;
  1841. begin
  1842. inherited deref;
  1843. resolvedef(retdef);
  1844. hp:=para1;
  1845. while assigned(hp) do
  1846. begin
  1847. if assigned(hp^.datasym) then
  1848. begin
  1849. resolvesym(psym(hp^.datasym));
  1850. hp^.data:=hp^.datasym^.definition;
  1851. end
  1852. else
  1853. resolvedef(hp^.data);
  1854. hp:=hp^.next;
  1855. end;
  1856. end;
  1857. constructor tabstractprocdef.load;
  1858. var
  1859. last,hp : pdefcoll;
  1860. count,i : word;
  1861. begin
  1862. inherited load;
  1863. retdef:=readdefref;
  1864. fpu_used:=readbyte;
  1865. options:=readlong;
  1866. count:=readword;
  1867. para1:=nil;
  1868. savesize:=target_os.size_of_pointer;
  1869. for i:=1 to count do
  1870. begin
  1871. new(hp);
  1872. hp^.paratyp:=tvarspez(readbyte);
  1873. { hp^.register:=tregister(readbyte); }
  1874. hp^.register:=R_NO;
  1875. hp^.data:=readdefref;
  1876. hp^.datasym:=ptypesym(readsymref);
  1877. hp^.next:=nil;
  1878. if para1=nil then
  1879. para1:=hp
  1880. else
  1881. last^.next:=hp;
  1882. last:=hp;
  1883. end;
  1884. end;
  1885. function tabstractprocdef.para_size : longint;
  1886. var
  1887. pdc : pdefcoll;
  1888. l : longint;
  1889. begin
  1890. l:=0;
  1891. pdc:=para1;
  1892. while assigned(pdc) do
  1893. begin
  1894. case pdc^.paratyp of
  1895. vs_var : inc(l,target_os.size_of_pointer);
  1896. vs_value,
  1897. vs_const : if push_addr_param(pdc^.data) then
  1898. inc(l,target_os.size_of_pointer)
  1899. else
  1900. inc(l,align(pdc^.data^.size,target_os.stackalignment));
  1901. end;
  1902. pdc:=pdc^.next;
  1903. end;
  1904. para_size:=l;
  1905. end;
  1906. procedure tabstractprocdef.write;
  1907. var
  1908. count : word;
  1909. hp : pdefcoll;
  1910. begin
  1911. inherited write;
  1912. writedefref(retdef);
  1913. current_ppu^.do_interface_crc:=false;
  1914. writebyte(fpu_used);
  1915. writelong(options);
  1916. hp:=para1;
  1917. count:=0;
  1918. while assigned(hp) do
  1919. begin
  1920. inc(count);
  1921. hp:=hp^.next;
  1922. end;
  1923. writeword(count);
  1924. hp:=para1;
  1925. while assigned(hp) do
  1926. begin
  1927. writebyte(byte(hp^.paratyp));
  1928. { writebyte(byte(hp^.register)); }
  1929. if assigned(hp^.datasym) then
  1930. begin
  1931. writedefref(nil);
  1932. writesymref(psym(hp^.datasym));
  1933. end
  1934. else
  1935. begin
  1936. writedefref(hp^.data);
  1937. writesymref(nil);
  1938. end;
  1939. hp:=hp^.next;
  1940. end;
  1941. end;
  1942. function tabstractprocdef.demangled_paras : string;
  1943. var s : string;
  1944. procedure doconcat(p : pdefcoll);
  1945. begin
  1946. if assigned(p^.next) then
  1947. doconcat(p^.next)
  1948. else
  1949. s:='(';
  1950. if assigned(p^.data^.sym) then
  1951. s:=s+p^.data^.sym^.name
  1952. else if p^.paratyp=vs_var then
  1953. s:=s+'var'
  1954. else if p^.paratyp=vs_const then
  1955. s:=s+'const';
  1956. if p<>para1 then
  1957. s:=s+','
  1958. else
  1959. s:=s+')';
  1960. end;
  1961. begin
  1962. s:='';
  1963. { a recursive solution is the easiest way to inverse the parameter }
  1964. { collection }
  1965. if assigned(para1) then
  1966. doconcat(para1);
  1967. demangled_paras:=s;
  1968. end;
  1969. {$ifdef GDB}
  1970. function tabstractprocdef.stabstring : pchar;
  1971. begin
  1972. stabstring := strpnew('abstractproc'+numberstring+';');
  1973. end;
  1974. procedure tabstractprocdef.concatstabto(asmlist : paasmoutput);
  1975. begin
  1976. if (not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  1977. and not is_def_stab_written then
  1978. begin
  1979. if assigned(retdef) then forcestabto(asmlist,retdef);
  1980. inherited concatstabto(asmlist);
  1981. end;
  1982. end;
  1983. {$endif GDB}
  1984. {***************************************************************************
  1985. TPROCDEF
  1986. ***************************************************************************}
  1987. constructor tprocdef.init;
  1988. begin
  1989. inherited init;
  1990. deftype:=procdef;
  1991. _mangledname:=nil;
  1992. nextoverloaded:=nil;
  1993. fileinfo:=aktfilepos;
  1994. extnumber:=-1;
  1995. localst:=new(psymtable,init(localsymtable));
  1996. parast:=new(psymtable,init(parasymtable));
  1997. localst^.defowner:=@self;
  1998. parast^.defowner:=@self;
  1999. { this is used by insert
  2000. to check same names in parast and localst }
  2001. localst^.next:=parast;
  2002. defref:=nil;
  2003. crossref:=nil;
  2004. lastwritten:=nil;
  2005. refcount:=0;
  2006. if (cs_browser in aktmoduleswitches) and make_ref then
  2007. begin
  2008. defref:=new(pref,init(defref,@tokenpos));
  2009. inc(refcount);
  2010. end;
  2011. lastref:=defref;
  2012. { first, we assume that all registers are used }
  2013. {$ifdef newcg}
  2014. usedregisters:=[firstreg..lastreg];
  2015. {$else newcg}
  2016. {$ifdef i386}
  2017. usedregisters:=$ff;
  2018. {$endif i386}
  2019. {$ifdef m68k}
  2020. usedregisters:=$FFFF;
  2021. {$endif}
  2022. {$ifdef alpha}
  2023. usedregisters_int:=$ffffffff;
  2024. usedregisters_fpu:=$ffffffff;
  2025. {$endif alpha}
  2026. {$endif newcg}
  2027. forwarddef:=true;
  2028. interfacedef:=false;
  2029. _class := nil;
  2030. code:=nil;
  2031. count:=false;
  2032. is_used:=false;
  2033. end;
  2034. constructor tprocdef.load;
  2035. var
  2036. s : string;
  2037. begin
  2038. inherited load;
  2039. deftype:=procdef;
  2040. {$ifdef newcg}
  2041. readnormalset(usedregisters);
  2042. {$else newcg}
  2043. {$ifdef i386}
  2044. usedregisters:=readbyte;
  2045. {$endif i386}
  2046. {$ifdef m68k}
  2047. usedregisters:=readword;
  2048. {$endif}
  2049. {$ifdef alpha}
  2050. usedregisters_int:=readlong;
  2051. usedregisters_fpu:=readlong;
  2052. {$endif alpha}
  2053. {$endif newcg}
  2054. s:=readstring;
  2055. setstring(_mangledname,s);
  2056. extnumber:=readlong;
  2057. nextoverloaded:=pprocdef(readdefref);
  2058. _class := pobjectdef(readdefref);
  2059. readposinfo(fileinfo);
  2060. if (cs_link_deffile in aktglobalswitches) and ((options and poexports)<>0) then
  2061. deffile.AddExport(mangledname);
  2062. parast:=nil;
  2063. localst:=nil;
  2064. forwarddef:=false;
  2065. interfacedef:=false;
  2066. lastref:=nil;
  2067. lastwritten:=nil;
  2068. defref:=nil;
  2069. refcount:=0;
  2070. count:=true;
  2071. is_used:=false;
  2072. end;
  2073. Const local_symtable_index : longint = $8001;
  2074. procedure tprocdef.load_references;
  2075. var
  2076. pos : tfileposinfo;
  2077. {$ifndef NOLOCALBROWSER}
  2078. pdo : pobjectdef;
  2079. {$endif ndef NOLOCALBROWSER}
  2080. move_last : boolean;
  2081. begin
  2082. move_last:=lastwritten=lastref;
  2083. while (not current_ppu^.endofentry) do
  2084. begin
  2085. readposinfo(pos);
  2086. inc(refcount);
  2087. lastref:=new(pref,init(lastref,@pos));
  2088. lastref^.is_written:=true;
  2089. if refcount=1 then
  2090. defref:=lastref;
  2091. end;
  2092. if move_last then
  2093. lastwritten:=lastref;
  2094. if ((current_module^.flags and uf_local_browser)<>0)
  2095. and is_in_current then
  2096. begin
  2097. {$ifndef NOLOCALBROWSER}
  2098. pdo:=_class;
  2099. new(parast,loadas(parasymtable));
  2100. parast^.next:=owner;
  2101. parast^.load_browser;
  2102. new(localst,loadas(localsymtable));
  2103. localst^.next:=parast;
  2104. localst^.load_browser;
  2105. {$endif ndef NOLOCALBROWSER}
  2106. end;
  2107. end;
  2108. function tprocdef.write_references : boolean;
  2109. var
  2110. ref : pref;
  2111. {$ifndef NOLOCALBROWSER}
  2112. pdo : pobjectdef;
  2113. {$endif ndef NOLOCALBROWSER}
  2114. move_last : boolean;
  2115. begin
  2116. move_last:=lastwritten=lastref;
  2117. if move_last and (((current_module^.flags and uf_local_browser)=0)
  2118. or not is_in_current) then
  2119. exit;
  2120. { write address of this symbol }
  2121. writedefref(@self);
  2122. { write refs }
  2123. if assigned(lastwritten) then
  2124. ref:=lastwritten
  2125. else
  2126. ref:=defref;
  2127. while assigned(ref) do
  2128. begin
  2129. if ref^.moduleindex=current_module^.unit_index then
  2130. begin
  2131. writeposinfo(ref^.posinfo);
  2132. ref^.is_written:=true;
  2133. if move_last then
  2134. lastwritten:=ref;
  2135. end
  2136. else if not ref^.is_written then
  2137. move_last:=false
  2138. else if move_last then
  2139. lastwritten:=ref;
  2140. ref:=ref^.nextref;
  2141. end;
  2142. current_ppu^.writeentry(ibdefref);
  2143. write_references:=true;
  2144. if ((current_module^.flags and uf_local_browser)<>0)
  2145. and is_in_current then
  2146. begin
  2147. {$ifndef NOLOCALBROWSER}
  2148. pdo:=_class;
  2149. if (owner^.symtabletype<>localsymtable) then
  2150. while assigned(pdo) do
  2151. begin
  2152. if pdo^.publicsyms<>aktrecordsymtable then
  2153. begin
  2154. pdo^.publicsyms^.unitid:=local_symtable_index;
  2155. inc(local_symtable_index);
  2156. end;
  2157. pdo:=pdo^.childof;
  2158. end;
  2159. { we need TESTLOCALBROWSER para and local symtables
  2160. PPU files are then easier to read PM }
  2161. if not assigned(parast) then
  2162. parast:=new(psymtable,init(parasymtable));
  2163. parast^.writeas;
  2164. parast^.unitid:=local_symtable_index;
  2165. inc(local_symtable_index);
  2166. parast^.write_browser;
  2167. if not assigned(localst) then
  2168. localst:=new(psymtable,init(localsymtable));
  2169. localst^.writeas;
  2170. localst^.unitid:=local_symtable_index;
  2171. inc(local_symtable_index);
  2172. localst^.write_browser;
  2173. { decrement for }
  2174. local_symtable_index:=local_symtable_index-2;
  2175. pdo:=_class;
  2176. if (owner^.symtabletype<>localsymtable) then
  2177. while assigned(pdo) do
  2178. begin
  2179. if pdo^.publicsyms<>aktrecordsymtable then
  2180. dec(local_symtable_index);
  2181. pdo:=pdo^.childof;
  2182. end;
  2183. {$endif ndef NOLOCALBROWSER}
  2184. end;
  2185. end;
  2186. {$ifdef BrowserLog}
  2187. procedure tprocdef.add_to_browserlog;
  2188. begin
  2189. if assigned(defref) then
  2190. begin
  2191. browserlog.AddLog('***'+mangledname);
  2192. browserlog.AddLogRefs(defref);
  2193. if (current_module^.flags and uf_local_browser)<>0 then
  2194. begin
  2195. if assigned(parast) then
  2196. parast^.writebrowserlog;
  2197. if assigned(localst) then
  2198. localst^.writebrowserlog;
  2199. end;
  2200. end;
  2201. end;
  2202. {$endif BrowserLog}
  2203. destructor tprocdef.done;
  2204. begin
  2205. if assigned(defref) then
  2206. dispose(defref,done);
  2207. if assigned(parast) then
  2208. dispose(parast,done);
  2209. if assigned(localst) and (localst^.symtabletype<>staticsymtable) then
  2210. dispose(localst,done);
  2211. if ((options and poinline) <> 0) and assigned(code) then
  2212. disposetree(ptree(code));
  2213. if (options and pomsgstr)<>0 then
  2214. strdispose(messageinf.str);
  2215. if
  2216. {$ifdef tp}
  2217. not(use_big) and
  2218. {$endif}
  2219. assigned(_mangledname) then
  2220. globals.strdispose(_mangledname);
  2221. inherited done;
  2222. end;
  2223. procedure tprocdef.write;
  2224. begin
  2225. inherited write;
  2226. current_ppu^.do_interface_crc:=false;
  2227. {$ifdef newcg}
  2228. writenormalset(usedregisters);
  2229. {$else newcg}
  2230. {$ifdef i386}
  2231. writebyte(usedregisters);
  2232. {$endif i386}
  2233. {$ifdef m68k}
  2234. writeword(usedregisters);
  2235. {$endif}
  2236. {$ifdef alpha}
  2237. writelong(usedregisters_int);
  2238. writelong(usedregisters_fpu);
  2239. {$endif alpha}
  2240. {$endif newcg}
  2241. writestring(mangledname);
  2242. current_ppu^.do_interface_crc:=true;
  2243. writelong(extnumber);
  2244. if (options and pooperator) = 0 then
  2245. writedefref(nextoverloaded)
  2246. else
  2247. begin
  2248. { only write the overloads from the same unit }
  2249. if assigned(nextoverloaded) and
  2250. (nextoverloaded^.owner=owner) then
  2251. writedefref(nextoverloaded)
  2252. else
  2253. writedefref(nil);
  2254. end;
  2255. writedefref(_class);
  2256. writeposinfo(fileinfo);
  2257. if (options and poinline) <> 0 then
  2258. begin
  2259. { we need to save
  2260. - the para and the local symtable
  2261. - the code ptree !! PM
  2262. writesymtable(parast);
  2263. writesymtable(localst);
  2264. writeptree(ptree(code));
  2265. }
  2266. end;
  2267. current_ppu^.writeentry(ibprocdef);
  2268. end;
  2269. function tprocdef.haspara:boolean;
  2270. begin
  2271. haspara:=assigned(aktprocsym^.definition^.parast^.symindex^.first);
  2272. end;
  2273. {$ifdef GDB}
  2274. procedure addparaname(p : psym);
  2275. var vs : char;
  2276. begin
  2277. if pvarsym(p)^.varspez = vs_value then vs := '1'
  2278. else vs := '0';
  2279. strpcopy(strend(StabRecString),p^.name+':'+pvarsym(p)^.definition^.numberstring+','+vs+';');
  2280. end;
  2281. function tprocdef.stabstring : pchar;
  2282. var param : pdefcoll;
  2283. i : word;
  2284. oldrec : pchar;
  2285. begin
  2286. oldrec := stabrecstring;
  2287. getmem(StabRecString,1024);
  2288. param := para1;
  2289. i := 0;
  2290. while assigned(param) do
  2291. begin
  2292. inc(i);
  2293. param := param^.next;
  2294. end;
  2295. strpcopy(StabRecString,'f'+retdef^.numberstring);
  2296. if i>0 then
  2297. begin
  2298. strpcopy(strend(StabRecString),','+tostr(i)+';');
  2299. (* confuse gdb !! PM
  2300. if assigned(parast) then
  2301. parast^.foreach({$ifndef TP}@{$endif}addparaname)
  2302. else
  2303. begin
  2304. param := para1;
  2305. i := 0;
  2306. while assigned(param) do
  2307. begin
  2308. inc(i);
  2309. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2310. {Here we have lost the parameter names !!}
  2311. {using lower case parameters }
  2312. strpcopy(strend(stabrecstring),'p'+tostr(i)
  2313. +':'+param^.data^.numberstring+','+vartyp+';');
  2314. param := param^.next;
  2315. end;
  2316. end; *)
  2317. {strpcopy(strend(StabRecString),';');}
  2318. end;
  2319. stabstring := strnew(stabrecstring);
  2320. freemem(stabrecstring,1024);
  2321. stabrecstring := oldrec;
  2322. end;
  2323. procedure tprocdef.concatstabto(asmlist : paasmoutput);
  2324. begin
  2325. end;
  2326. {$endif GDB}
  2327. procedure tprocdef.deref;
  2328. begin
  2329. inherited deref;
  2330. resolvedef(pdef(nextoverloaded));
  2331. resolvedef(pdef(_class));
  2332. end;
  2333. function tprocdef.mangledname : string;
  2334. {$ifdef tp}
  2335. var
  2336. oldpos : longint;
  2337. s : string;
  2338. b : byte;
  2339. {$endif tp}
  2340. begin
  2341. {$ifndef Delphi}
  2342. {$ifdef tp}
  2343. if use_big then
  2344. begin
  2345. symbolstream.seek(longint(_mangledname));
  2346. symbolstream.read(b,1);
  2347. symbolstream.read(s[1],b);
  2348. s[0]:=chr(b);
  2349. mangledname:=s;
  2350. end
  2351. else
  2352. {$endif}
  2353. {$endif Delphi}
  2354. mangledname:=strpas(_mangledname);
  2355. if count then
  2356. is_used:=true;
  2357. end;
  2358. {$IfDef GDB}
  2359. function tprocdef.cplusplusmangledname : string;
  2360. var
  2361. s,s2 : string;
  2362. param : pdefcoll;
  2363. begin
  2364. s := sym^.name;
  2365. if _class <> nil then
  2366. begin
  2367. s2 := _class^.objname^;
  2368. s := s+'__'+tostr(length(s2))+s2;
  2369. end else s := s + '_';
  2370. param := para1;
  2371. while assigned(param) do
  2372. begin
  2373. s2 := param^.data^.sym^.name;
  2374. s := s+tostr(length(s2))+s2;
  2375. param := param^.next;
  2376. end;
  2377. cplusplusmangledname:=s;
  2378. end;
  2379. {$EndIf GDB}
  2380. procedure tprocdef.setmangledname(const s : string);
  2381. begin
  2382. if {$ifdef tp}not(use_big) and{$endif} (assigned(_mangledname)) then
  2383. strdispose(_mangledname);
  2384. setstring(_mangledname,s);
  2385. if assigned(parast) then
  2386. begin
  2387. stringdispose(parast^.name);
  2388. parast^.name:=stringdup('args of '+s);
  2389. end;
  2390. if assigned(localst) then
  2391. begin
  2392. stringdispose(localst^.name);
  2393. localst^.name:=stringdup('locals of '+s);
  2394. end;
  2395. end;
  2396. {***************************************************************************
  2397. TPROCVARDEF
  2398. ***************************************************************************}
  2399. constructor tprocvardef.init;
  2400. begin
  2401. inherited init;
  2402. deftype:=procvardef;
  2403. end;
  2404. constructor tprocvardef.load;
  2405. begin
  2406. inherited load;
  2407. deftype:=procvardef;
  2408. end;
  2409. procedure tprocvardef.write;
  2410. begin
  2411. { here we cannot get a real good value so just give something }
  2412. { plausible (PM) }
  2413. { a more secure way would be
  2414. to allways store in a temp }
  2415. if is_fpu(retdef) then
  2416. fpu_used:=2
  2417. else
  2418. fpu_used:=0;
  2419. inherited write;
  2420. current_ppu^.writeentry(ibprocvardef);
  2421. end;
  2422. function tprocvardef.size : longint;
  2423. begin
  2424. if (options and pomethodpointer)=0 then
  2425. size:=target_os.size_of_pointer
  2426. else
  2427. size:=2*target_os.size_of_pointer;
  2428. end;
  2429. {$ifdef GDB}
  2430. function tprocvardef.stabstring : pchar;
  2431. var
  2432. nss : pchar;
  2433. i : word;
  2434. param : pdefcoll;
  2435. begin
  2436. i := 0;
  2437. param := para1;
  2438. while assigned(param) do
  2439. begin
  2440. inc(i);
  2441. param := param^.next;
  2442. end;
  2443. getmem(nss,1024);
  2444. { it is not a function but a function pointer !! (PM) }
  2445. strpcopy(nss,'*f'+retdef^.numberstring{+','+tostr(i)}+';');
  2446. param := para1;
  2447. i := 0;
  2448. { this confuses gdb !!
  2449. we should use 'F' instead of 'f' but
  2450. as we use c++ language mode
  2451. it does not like that either
  2452. Please do not remove this part
  2453. might be used once
  2454. gdb for pascal is ready PM }
  2455. (* while assigned(param) do
  2456. begin
  2457. inc(i);
  2458. if param^.paratyp = vs_value then vartyp := '1' else vartyp := '0';
  2459. {Here we have lost the parameter names !!}
  2460. pst := strpnew('p'+tostr(i)+':'+param^.data^.numberstring+','+vartyp+';');
  2461. strcat(nss,pst);
  2462. strdispose(pst);
  2463. param := param^.next;
  2464. end; *)
  2465. {strpcopy(strend(nss),';');}
  2466. stabstring := strnew(nss);
  2467. freemem(nss,1024);
  2468. end;
  2469. procedure tprocvardef.concatstabto(asmlist : paasmoutput);
  2470. begin
  2471. if ( not assigned(sym) or sym^.isusedinstab or (cs_gdb_dbx in aktglobalswitches))
  2472. and not is_def_stab_written then
  2473. inherited concatstabto(asmlist);
  2474. is_def_stab_written:=true;
  2475. end;
  2476. {$endif GDB}
  2477. procedure tprocvardef.write_rtti_data;
  2478. begin
  2479. {!!!!!!!}
  2480. end;
  2481. procedure tprocvardef.write_child_rtti_data;
  2482. begin
  2483. {!!!!!!!!}
  2484. end;
  2485. function tprocvardef.is_publishable : boolean;
  2486. begin
  2487. is_publishable:=(options and pomethodpointer)<>0;
  2488. end;
  2489. function tprocvardef.gettypename : string;
  2490. begin
  2491. if assigned(retdef) then
  2492. gettypename:='<procedure variable type of function'+demangled_paras+':'+retdef^.gettypename+'>'
  2493. else
  2494. gettypename:='<procedure variable type of procedure'+demangled_paras+'>';
  2495. end;
  2496. {***************************************************************************
  2497. TOBJECTDEF
  2498. ***************************************************************************}
  2499. {$ifdef GDB}
  2500. const
  2501. vtabletype : word = 0;
  2502. vtableassigned : boolean = false;
  2503. {$endif GDB}
  2504. constructor tobjectdef.init(const n : string;c : pobjectdef);
  2505. begin
  2506. tdef.init;
  2507. deftype:=objectdef;
  2508. options:=0;
  2509. childof:=nil;
  2510. publicsyms:=new(psymtable,init(objectsymtable));
  2511. publicsyms^.name := stringdup(n);
  2512. { create space for vmt !! }
  2513. options:=0;
  2514. vmt_offset:=0;
  2515. publicsyms^.datasize:=0;
  2516. publicsyms^.defowner:=@self;
  2517. publicsyms^.dataalignment:=packrecordalignment[aktpackrecords];
  2518. set_parent(c);
  2519. objname:=stringdup(n);
  2520. end;
  2521. procedure tobjectdef.set_parent( c : pobjectdef);
  2522. begin
  2523. { nothing to do if the parent was not forward !}
  2524. if assigned(childof) then
  2525. exit;
  2526. childof:=c;
  2527. { some options are inherited !! }
  2528. if assigned(c) then
  2529. begin
  2530. options:= options or (c^.options and
  2531. (oo_hasvirtual or oo_hasprivate or
  2532. oo_hasprotected or
  2533. oo_hasconstructor or oo_hasdestructor
  2534. ));
  2535. { add the data of the anchestor class }
  2536. publicsyms^.datasize:=publicsyms^.datasize
  2537. +childof^.publicsyms^.datasize;
  2538. if ((options and oo_hasvmt)<>0) and
  2539. ((c^.options and oo_hasvmt)<>0) then
  2540. publicsyms^.datasize:=publicsyms^.datasize-target_os.size_of_pointer;
  2541. { if parent has a vmt field then
  2542. the offset is the same for the child PM }
  2543. if ((c^.options and oo_hasvmt)<>0) or isclass then
  2544. begin
  2545. vmt_offset:=c^.vmt_offset;
  2546. options:=options or oo_hasvmt;
  2547. end;
  2548. end;
  2549. savesize := publicsyms^.datasize;
  2550. end;
  2551. constructor tobjectdef.load;
  2552. var
  2553. oldread_member : boolean;
  2554. begin
  2555. tdef.load;
  2556. deftype:=objectdef;
  2557. savesize:=readlong;
  2558. vmt_offset:=readlong;
  2559. objname:=stringdup(readstring);
  2560. childof:=pobjectdef(readdefref);
  2561. options:=readlong;
  2562. oldread_member:=read_member;
  2563. read_member:=true;
  2564. publicsyms:=new(psymtable,loadas(objectsymtable));
  2565. read_member:=oldread_member;
  2566. publicsyms^.defowner:=@self;
  2567. publicsyms^.name := stringdup(objname^);
  2568. { handles the predefined class tobject }
  2569. { the last TOBJECT which is loaded gets }
  2570. { it ! }
  2571. if (objname^='TOBJECT') and
  2572. isclass and (childof=nil) then
  2573. class_tobject:=@self;
  2574. has_rtti:=true;
  2575. end;
  2576. procedure tobjectdef.insertvmt;
  2577. begin
  2578. if (options and oo_hasvmt)<>0 then
  2579. internalerror(12345)
  2580. else
  2581. begin
  2582. { first round up to multiple of 4 }
  2583. if (publicsyms^.dataalignment=2) then
  2584. begin
  2585. if (publicsyms^.datasize and 1)<>0 then
  2586. inc(publicsyms^.datasize);
  2587. end
  2588. else
  2589. if (publicsyms^.dataalignment>=4) then
  2590. begin
  2591. if (publicsyms^.datasize mod 4) <> 0 then
  2592. publicsyms^.datasize:=publicsyms^.datasize+4-(publicsyms^.datasize mod 4);
  2593. end;
  2594. vmt_offset:=publicsyms^.datasize;
  2595. publicsyms^.datasize:=publicsyms^.datasize+target_os.size_of_pointer;
  2596. options:=options or oo_hasvmt;
  2597. end;
  2598. end;
  2599. procedure tobjectdef.check_forwards;
  2600. begin
  2601. publicsyms^.check_forwards;
  2602. if (options and oo_isforward)<>0 then
  2603. begin
  2604. { ok, in future, the forward can be resolved }
  2605. Message1(sym_e_class_forward_not_resolved,objname^);
  2606. options:=options and not(oo_isforward);
  2607. end;
  2608. end;
  2609. destructor tobjectdef.done;
  2610. begin
  2611. if assigned(publicsyms) then
  2612. dispose(publicsyms,done);
  2613. if (options and oo_isforward)<>0 then
  2614. Message1(sym_e_class_forward_not_resolved,objname^);
  2615. stringdispose(objname);
  2616. tdef.done;
  2617. end;
  2618. { true, if self inherits from d (or if they are equal) }
  2619. function tobjectdef.isrelated(d : pobjectdef) : boolean;
  2620. var
  2621. hp : pobjectdef;
  2622. begin
  2623. hp:=@self;
  2624. while assigned(hp) do
  2625. begin
  2626. if hp=d then
  2627. begin
  2628. isrelated:=true;
  2629. exit;
  2630. end;
  2631. hp:=hp^.childof;
  2632. end;
  2633. isrelated:=false;
  2634. end;
  2635. function tobjectdef.size : longint;
  2636. begin
  2637. if (options and oo_is_class)<>0 then
  2638. size:=target_os.size_of_pointer
  2639. else
  2640. size:=publicsyms^.datasize;
  2641. end;
  2642. function tobjectdef.alignment:longint;
  2643. begin
  2644. alignment:=publicsyms^.dataalignment;
  2645. end;
  2646. procedure tobjectdef.deref;
  2647. var
  2648. oldrecsyms : psymtable;
  2649. begin
  2650. resolvedef(pdef(childof));
  2651. oldrecsyms:=aktrecordsymtable;
  2652. aktrecordsymtable:=publicsyms;
  2653. publicsyms^.deref;
  2654. aktrecordsymtable:=oldrecsyms;
  2655. end;
  2656. function tobjectdef.vmt_mangledname : string;
  2657. {DM: I get a nil pointer on the owner name. I don't know if this
  2658. mayhappen, and I have therefore fixed the problem by doing nil pointer
  2659. checks.}
  2660. var
  2661. s1,s2:string;
  2662. begin
  2663. if (options and oo_hasvmt)=0 then
  2664. {internalerror(12346);}
  2665. Message1(parser_object_has_no_vmt,objname^);
  2666. if owner^.name=nil then
  2667. s1:=''
  2668. else
  2669. s1:=owner^.name^;
  2670. if objname=nil then
  2671. s2:=''
  2672. else
  2673. s2:=objname^;
  2674. vmt_mangledname:='VMT_'+s1+'$_'+s2;
  2675. end;
  2676. function tobjectdef.rtti_name : string;
  2677. var
  2678. s1,s2:string;
  2679. begin
  2680. if owner^.name=nil then
  2681. s1:=''
  2682. else
  2683. s1:=owner^.name^;
  2684. if objname=nil then
  2685. s2:=''
  2686. else
  2687. s2:=objname^;
  2688. rtti_name:='RTTI_'+s1+'$_'+s2;
  2689. end;
  2690. function tobjectdef.isclass : boolean;
  2691. begin
  2692. isclass:=(options and oo_is_class)<>0;
  2693. end;
  2694. procedure tobjectdef.write;
  2695. var
  2696. oldread_member : boolean;
  2697. begin
  2698. tdef.write;
  2699. writelong(size);
  2700. writelong(vmt_offset);
  2701. writestring(objname^);
  2702. writedefref(childof);
  2703. writelong(options);
  2704. current_ppu^.writeentry(ibobjectdef);
  2705. oldread_member:=read_member;
  2706. read_member:=true;
  2707. publicsyms^.writeas;
  2708. read_member:=oldread_member;
  2709. end;
  2710. {$ifdef GDB}
  2711. procedure addprocname(p :pnamedindexobject);
  2712. var virtualind,argnames : string;
  2713. news, newrec : pchar;
  2714. pd,ipd : pprocdef;
  2715. lindex : longint;
  2716. para : pdefcoll;
  2717. arglength : byte;
  2718. sp : char;
  2719. begin
  2720. If psym(p)^.typ = procsym then
  2721. begin
  2722. pd := pprocsym(p)^.definition;
  2723. { this will be used for full implementation of object stabs
  2724. not yet done }
  2725. ipd := pd;
  2726. while assigned(ipd^.nextoverloaded) do ipd := ipd^.nextoverloaded;
  2727. if (pd^.options and povirtualmethod) <> 0 then
  2728. begin
  2729. lindex := pd^.extnumber;
  2730. {doesnt seem to be necessary
  2731. lindex := lindex or $80000000;}
  2732. virtualind := '*'+tostr(lindex)+';'+ipd^._class^.numberstring+';'
  2733. end else virtualind := '.';
  2734. { arguments are not listed here }
  2735. {we don't need another definition}
  2736. para := pd^.para1;
  2737. { used by gdbpas to recognize constructor and destructors }
  2738. if (pd^.options and poconstructor) <> 0 then
  2739. argnames:='__ct__'
  2740. else if (pd^.options and podestructor) <> 0 then
  2741. argnames:='__dt__'
  2742. else
  2743. argnames := '';
  2744. while assigned(para) do
  2745. begin
  2746. if para^.data^.deftype = formaldef then
  2747. begin
  2748. if para^.paratyp=vs_var then
  2749. argnames := argnames+'3var'
  2750. else if para^.paratyp=vs_const then
  2751. argnames:=argnames+'5const';
  2752. end
  2753. else
  2754. begin
  2755. { if the arg definition is like (v: ^byte;..
  2756. there is no sym attached to data !!! }
  2757. if assigned(para^.data^.sym) then
  2758. begin
  2759. arglength := length(para^.data^.sym^.name);
  2760. argnames := argnames + tostr(arglength)+para^.data^.sym^.name;
  2761. end
  2762. else
  2763. begin
  2764. argnames:=argnames+'11unnamedtype';
  2765. end;
  2766. end;
  2767. para := para^.next;
  2768. end;
  2769. ipd^.is_def_stab_written := true;
  2770. { here 2A must be changed for private and protected }
  2771. { 0 is private 1 protected and 2 public }
  2772. if (psym(p)^.properties and sp_private)<>0 then sp:='0'
  2773. else if (psym(p)^.properties and sp_protected)<>0 then sp:='1'
  2774. else sp:='2';
  2775. newrec := strpnew(p^.name+'::'+ipd^.numberstring
  2776. +'=##'+pd^.retdef^.numberstring+';:'+argnames+';'+sp+'A'
  2777. +virtualind+';');
  2778. { get spare place for a string at the end }
  2779. if strlen(StabRecString) + strlen(newrec) >= StabRecSize-256 then
  2780. begin
  2781. getmem(news,stabrecsize+memsizeinc);
  2782. strcopy(news,stabrecstring);
  2783. freemem(stabrecstring,stabrecsize);
  2784. stabrecsize:=stabrecsize+memsizeinc;
  2785. stabrecstring:=news;
  2786. end;
  2787. strcat(StabRecstring,newrec);
  2788. {freemem(newrec,memsizeinc); }
  2789. strdispose(newrec);
  2790. {This should be used for case !!}
  2791. RecOffset := RecOffset + pd^.size;
  2792. end;
  2793. end;
  2794. function tobjectdef.stabstring : pchar;
  2795. var anc : pobjectdef;
  2796. oldrec : pchar;
  2797. oldrecsize : longint;
  2798. str_end : string;
  2799. begin
  2800. oldrec := stabrecstring;
  2801. oldrecsize:=stabrecsize;
  2802. stabrecsize:=memsizeinc;
  2803. GetMem(stabrecstring,stabrecsize);
  2804. strpcopy(stabRecString,'s'+tostr(size));
  2805. if assigned(childof) then
  2806. {only one ancestor not virtual, public, at base offset 0 }
  2807. { !1 , 0 2 0 , }
  2808. strpcopy(strend(stabrecstring),'!1,020,'+childof^.numberstring+';');
  2809. {virtual table to implement yet}
  2810. RecOffset := 0;
  2811. publicsyms^.foreach({$ifndef TP}@{$endif}addname);
  2812. if (options and oo_hasvmt) <> 0 then
  2813. if not assigned(childof) or ((childof^.options and oo_hasvmt) = 0) then
  2814. begin
  2815. strpcopy(strend(stabrecstring),'$vf'+numberstring+':'+typeglobalnumber('vtblarray')
  2816. +','+tostr(vmt_offset*8)+';');
  2817. end;
  2818. publicsyms^.foreach({$ifndef TP}@{$endif}addprocname);
  2819. if (options and oo_hasvmt) <> 0 then
  2820. begin
  2821. anc := @self;
  2822. while assigned(anc^.childof) and ((anc^.childof^.options and oo_hasvmt) <> 0) do
  2823. anc := anc^.childof;
  2824. str_end:=';~%'+anc^.numberstring+';';
  2825. end
  2826. else
  2827. str_end:=';';
  2828. strpcopy(strend(stabrecstring),str_end);
  2829. stabstring := strnew(StabRecString);
  2830. freemem(stabrecstring,stabrecsize);
  2831. stabrecstring := oldrec;
  2832. stabrecsize:=oldrecsize;
  2833. end;
  2834. {$endif GDB}
  2835. procedure tobjectdef.write_child_init_data;
  2836. begin
  2837. publicsyms^.foreach({$ifndef TP}@{$endif}generate_child_inittable);
  2838. end;
  2839. procedure tobjectdef.write_init_data;
  2840. begin
  2841. if isclass then
  2842. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2843. else
  2844. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2845. { generate the name }
  2846. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  2847. rttilist^.concat(new(pai_string,init(objname^)));
  2848. rttilist^.concat(new(pai_const,init_32bit(size)));
  2849. count:=0;
  2850. publicsyms^.foreach({$ifndef TP}@{$endif}count_inittable_fields);
  2851. rttilist^.concat(new(pai_const,init_32bit(count)));
  2852. publicsyms^.foreach({$ifndef TP}@{$endif}write_field_inittable);
  2853. end;
  2854. function tobjectdef.needs_inittable : boolean;
  2855. var
  2856. oldb : boolean;
  2857. begin
  2858. { there are recursive calls to needs_inittable possible, }
  2859. { so we have to change to old value how else should }
  2860. { we do that ? check_rec_rtti can't be a nested }
  2861. { procedure of needs_rtti ! }
  2862. oldb:=binittable;
  2863. binittable:=false;
  2864. publicsyms^.foreach({$ifndef TP}@{$endif}check_rec_inittable);
  2865. needs_inittable:=binittable;
  2866. binittable:=oldb;
  2867. end;
  2868. procedure count_published_properties(sym:pnamedindexobject);
  2869. {$ifndef fpc}far;{$endif}
  2870. begin
  2871. if (psym(sym)^.typ=propertysym) and ((psym(sym)^.properties and sp_published)<>0) then
  2872. inc(count);
  2873. end;
  2874. procedure write_property_info(sym : pnamedindexobject);{$ifndef fpc}far;{$endif}
  2875. var
  2876. proctypesinfo : byte;
  2877. procedure writeproc(sym : psym;def : pdef;shiftvalue : byte);
  2878. var
  2879. typvalue : byte;
  2880. begin
  2881. if not(assigned(sym)) then
  2882. begin
  2883. rttilist^.concat(new(pai_const,init_32bit(1)));
  2884. typvalue:=3;
  2885. end
  2886. else if sym^.typ=varsym then
  2887. begin
  2888. rttilist^.concat(new(pai_const,init_32bit(
  2889. pvarsym(sym)^.address)));
  2890. typvalue:=0;
  2891. end
  2892. else
  2893. begin
  2894. if (pprocdef(def)^.options and povirtualmethod)=0 then
  2895. begin
  2896. rttilist^.concat(new(pai_const_symbol,initname(pprocdef(def)^.mangledname)));
  2897. typvalue:=1;
  2898. end
  2899. else
  2900. begin
  2901. { virtual method, write vmt offset }
  2902. rttilist^.concat(new(pai_const,init_32bit(pprocdef(def)^.extnumber*4+12)));
  2903. typvalue:=2;
  2904. end;
  2905. end;
  2906. proctypesinfo:=proctypesinfo or (typvalue shl shiftvalue);
  2907. end;
  2908. begin
  2909. if (psym(sym)^.typ=propertysym) and
  2910. ((ppropertysym(sym)^.options and ppo_indexed)<>0) then
  2911. proctypesinfo:=$40
  2912. else
  2913. proctypesinfo:=0;
  2914. if (psym(sym)^.typ=propertysym) and
  2915. ((psym(sym)^.properties and sp_published)<>0) then
  2916. begin
  2917. rttilist^.concat(new(pai_const_symbol,initname(ppropertysym(sym)^.proptype^.get_rtti_label)));
  2918. writeproc(ppropertysym(sym)^.readaccesssym,ppropertysym(sym)^.readaccessdef,0);
  2919. writeproc(ppropertysym(sym)^.writeaccesssym,ppropertysym(sym)^.writeaccessdef,2);
  2920. { isn't it stored ? }
  2921. if (ppropertysym(sym)^.options and ppo_stored)=0 then
  2922. begin
  2923. rttilist^.concat(new(pai_const,init_32bit(1)));
  2924. proctypesinfo:=proctypesinfo or (3 shl 4);
  2925. end
  2926. else
  2927. writeproc(ppropertysym(sym)^.storedsym,ppropertysym(sym)^.storeddef,4);
  2928. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.index)));
  2929. rttilist^.concat(new(pai_const,init_32bit(ppropertysym(sym)^.default)));
  2930. rttilist^.concat(new(pai_const,init_16bit(count)));
  2931. inc(count);
  2932. rttilist^.concat(new(pai_const,init_8bit(proctypesinfo)));
  2933. rttilist^.concat(new(pai_const,init_8bit(length(ppropertysym(sym)^.name))));
  2934. rttilist^.concat(new(pai_string,init(ppropertysym(sym)^.name)));
  2935. end;
  2936. end;
  2937. procedure generate_published_child_rtti(sym : pnamedindexobject);
  2938. {$ifndef fpc}far;{$endif}
  2939. begin
  2940. if (psym(sym)^.typ=propertysym) and
  2941. ((psym(sym)^.properties and sp_published)<>0) then
  2942. ppropertysym(sym)^.proptype^.get_rtti_label;
  2943. end;
  2944. procedure tobjectdef.write_child_rtti_data;
  2945. begin
  2946. publicsyms^.foreach({$ifndef TP}@{$endif}generate_published_child_rtti);
  2947. end;
  2948. procedure tobjectdef.generate_rtti;
  2949. begin
  2950. has_rtti:=true;
  2951. getdatalabel(rtti_label);
  2952. write_child_rtti_data;
  2953. rttilist^.concat(new(pai_symbol,initname_global(rtti_name,0)));
  2954. rttilist^.concat(new(pai_label,init(rtti_label)));
  2955. write_rtti_data;
  2956. rttilist^.concat(new(pai_symbol_end,initname(rtti_name)));
  2957. end;
  2958. function tobjectdef.next_free_name_index : longint;
  2959. var
  2960. i : longint;
  2961. begin
  2962. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2963. i:=childof^.next_free_name_index
  2964. else
  2965. i:=0;
  2966. count:=0;
  2967. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  2968. next_free_name_index:=i+count;
  2969. end;
  2970. procedure tobjectdef.write_rtti_data;
  2971. begin
  2972. if isclass then
  2973. rttilist^.concat(new(pai_const,init_8bit(tkclass)))
  2974. else
  2975. rttilist^.concat(new(pai_const,init_8bit(tkobject)));
  2976. { generate the name }
  2977. rttilist^.concat(new(pai_const,init_8bit(length(objname^))));
  2978. rttilist^.concat(new(pai_string,init(objname^)));
  2979. { write class type }
  2980. rttilist^.concat(new(pai_const_symbol,initname(vmt_mangledname)));
  2981. { write owner typeinfo }
  2982. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2983. rttilist^.concat(new(pai_const_symbol,initname(childof^.get_rtti_label)))
  2984. else
  2985. rttilist^.concat(new(pai_const,init_32bit(0)));
  2986. { count total number of properties }
  2987. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  2988. count:=childof^.next_free_name_index
  2989. else
  2990. count:=0;
  2991. { write it }
  2992. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  2993. rttilist^.concat(new(pai_const,init_16bit(count)));
  2994. { write unit name }
  2995. if assigned(owner^.name) then
  2996. begin
  2997. rttilist^.concat(new(pai_const,init_8bit(length(owner^.name^))));
  2998. rttilist^.concat(new(pai_string,init(owner^.name^)));
  2999. end
  3000. else
  3001. rttilist^.concat(new(pai_const,init_8bit(0)));
  3002. { write published properties count }
  3003. count:=0;
  3004. publicsyms^.foreach({$ifndef TP}@{$endif}count_published_properties);
  3005. rttilist^.concat(new(pai_const,init_16bit(count)));
  3006. { count is used to write nameindex }
  3007. { but we need an offset of the owner }
  3008. { to give each property an own slot }
  3009. if assigned(childof) and ((childof^.options and oo_can_have_published)<>0) then
  3010. count:=childof^.next_free_name_index
  3011. else
  3012. count:=0;
  3013. publicsyms^.foreach({$ifndef TP}@{$endif}write_property_info);
  3014. end;
  3015. function tobjectdef.is_publishable : boolean;
  3016. begin
  3017. is_publishable:=isclass;
  3018. end;
  3019. function tobjectdef.get_rtti_label : string;
  3020. begin
  3021. get_rtti_label:=rtti_name;
  3022. end;
  3023. {****************************************************************************
  3024. TERRORDEF
  3025. ****************************************************************************}
  3026. constructor terrordef.init;
  3027. begin
  3028. inherited init;
  3029. deftype:=errordef;
  3030. end;
  3031. {$ifdef GDB}
  3032. function terrordef.stabstring : pchar;
  3033. begin
  3034. stabstring:=strpnew('error'+numberstring);
  3035. end;
  3036. {$endif GDB}
  3037. function terrordef.gettypename:string;
  3038. begin
  3039. gettypename:='<erroneous type>';
  3040. end;
  3041. {
  3042. $Log$
  3043. Revision 1.138 1999-08-02 21:29:02 florian
  3044. * the main branch psub.pas is now used for
  3045. newcg compiler
  3046. Revision 1.137 1999/07/31 22:37:17 michael
  3047. * Fix of initialization information generation
  3048. Revision 1.136 1999/07/29 20:54:07 peter
  3049. * write .size also
  3050. Revision 1.135 1999/07/27 23:42:18 peter
  3051. * indirect type referencing is now allowed
  3052. Revision 1.134 1999/07/23 23:07:03 peter
  3053. * fixed stabs for record which still used savesize
  3054. Revision 1.133 1999/07/23 16:05:28 peter
  3055. * alignment is now saved in the symtable
  3056. * C alignment added for records
  3057. * PPU version increased to solve .12 <-> .13 probs
  3058. Revision 1.132 1999/07/18 14:47:32 florian
  3059. * bug 487 fixed, (inc(<property>) isn't allowed)
  3060. * more fixes to compile with Delphi
  3061. Revision 1.131 1999/07/06 21:48:27 florian
  3062. * a lot bug fixes:
  3063. - po_external isn't any longer necessary for procedure compatibility
  3064. - m_tp_procvar is in -Sd now available
  3065. - error messages of procedure variables improved
  3066. - return values with init./finalization fixed
  3067. - data types with init./finalization aren't any longer allowed in variant
  3068. record
  3069. Revision 1.130 1999/06/22 16:24:44 pierre
  3070. * local browser stuff corrected
  3071. Revision 1.129 1999/06/02 22:44:21 pierre
  3072. * previous wrong log corrected
  3073. Revision 1.128 1999/06/02 22:25:52 pierre
  3074. * changed $ifdef FPC @ into $ifndef TP
  3075. Revision 1.127 1999/06/02 10:26:50 florian
  3076. * corrected order of parameter type for -vb
  3077. Revision 1.126 1999/06/02 10:11:50 florian
  3078. * make cycle fixed i.e. compilation with 0.99.10
  3079. * some fixes for qword
  3080. * start of register calling conventions
  3081. Revision 1.125 1999/06/01 14:45:56 peter
  3082. * @procvar is now always needed for FPC
  3083. Revision 1.124 1999/05/31 16:42:33 peter
  3084. * interfacedef flag for procdef if it's defined in the interface, to
  3085. make a difference with 'forward;' directive forwarddef. Fixes 253
  3086. Revision 1.123 1999/05/27 19:45:02 peter
  3087. * removed oldasm
  3088. * plabel -> pasmlabel
  3089. * -a switches to source writing automaticly
  3090. * assembler readers OOPed
  3091. * asmsymbol automaticly external
  3092. * jumptables and other label fixes for asm readers
  3093. Revision 1.122 1999/05/23 18:42:14 florian
  3094. * better error recovering in typed constants
  3095. * some problems with arrays of const fixed, some problems
  3096. due my previous
  3097. - the location type of array constructor is now LOC_MEM
  3098. - the pushing of high fixed
  3099. - parameter copying fixed
  3100. - zero temp. allocation removed
  3101. * small problem in the assembler writers fixed:
  3102. ref to nil wasn't written correctly
  3103. Revision 1.121 1999/05/21 13:55:19 peter
  3104. * NEWLAB for label as symbol
  3105. Revision 1.120 1999/05/20 22:22:43 pierre
  3106. + added synonym filed for ttypesym
  3107. allows a clean disposal of tdefs and related ttypesyms
  3108. Revision 1.119 1999/05/19 16:48:26 florian
  3109. * tdef.typename: returns a now a proper type name for the most types
  3110. Revision 1.118 1999/05/19 12:08:11 florian
  3111. * tobject wasn't set as default anchestor, was a problem with the new ppu
  3112. handling
  3113. Revision 1.117 1999/05/17 21:57:15 florian
  3114. * new temporary ansistring handling
  3115. Revision 1.116 1999/05/16 02:26:51 peter
  3116. * fixed loading of classrefdef
  3117. Revision 1.115 1999/05/14 17:52:26 peter
  3118. * new deref code
  3119. Revision 1.114 1999/05/13 21:59:41 peter
  3120. * removed oldppu code
  3121. * warning if objpas is loaded from uses
  3122. * first things for new deref writing
  3123. Revision 1.113 1999/05/12 00:19:58 peter
  3124. * removed R_DEFAULT_SEG
  3125. * uniform float names
  3126. Revision 1.112 1999/05/08 19:52:35 peter
  3127. + MessagePos() which is enhanced Message() function but also gets the
  3128. position info
  3129. * Removed comp warnings
  3130. Revision 1.111 1999/05/07 11:06:37 florian
  3131. * enumeration type names are now written in lowercase (rtti)
  3132. Revision 1.110 1999/05/06 09:05:28 peter
  3133. * generic write_float and str_float
  3134. * fixed constant float conversions
  3135. Revision 1.109 1999/05/05 10:05:56 florian
  3136. * a delphi compiled compiler recompiles ppc
  3137. Revision 1.108 1999/04/28 22:30:52 pierre
  3138. * delete -> deleteindex in tdef.correct_owner_symtable
  3139. Revision 1.107 1999/04/28 06:02:11 florian
  3140. * changes of Bruessel:
  3141. + message handler can now take an explicit self
  3142. * typinfo fixed: sometimes the type names weren't written
  3143. * the type checking for pointer comparisations and subtraction
  3144. and are now more strict (was also buggy)
  3145. * small bug fix to link.pas to support compiling on another
  3146. drive
  3147. * probable bug in popt386 fixed: call/jmp => push/jmp
  3148. transformation didn't count correctly the jmp references
  3149. + threadvar support
  3150. * warning if ln/sqrt gets an invalid constant argument
  3151. Revision 1.106 1999/04/26 18:30:01 peter
  3152. * farpointerdef moved into pointerdef.is_far
  3153. Revision 1.105 1999/04/26 13:31:47 peter
  3154. * release storenumber,double_checksum
  3155. Revision 1.104 1999/04/21 09:43:50 peter
  3156. * storenumber works
  3157. * fixed some typos in double_checksum
  3158. + incompatible types type1 and type2 message (with storenumber)
  3159. Revision 1.103 1999/04/19 09:28:20 peter
  3160. * fixed crash when writing overload operator to ppu
  3161. Revision 1.102 1999/04/17 22:01:28 pierre
  3162. * typo error fix in STORENUMBER code
  3163. Revision 1.101 1999/04/14 09:14:58 peter
  3164. * first things to store the symbol/def number in the ppu
  3165. Revision 1.100 1999/04/08 15:57:51 peter
  3166. + subrange checking for readln()
  3167. Revision 1.99 1999/04/07 15:39:32 pierre
  3168. + double_checksum code added
  3169. Revision 1.98 1999/03/06 17:24:16 peter
  3170. * reset savesize in tdef.init
  3171. Revision 1.97 1999/03/01 13:45:04 pierre
  3172. + added staticppusymtable symtable type for local browsing
  3173. Revision 1.96 1999/02/25 21:02:52 peter
  3174. * ag386bin updates
  3175. + coff writer
  3176. Revision 1.95 1999/02/23 18:29:23 pierre
  3177. * win32 compilation error fix
  3178. + some work for local browser (not cl=omplete yet)
  3179. Revision 1.94 1999/02/22 20:13:38 florian
  3180. + first implementation of message keyword
  3181. Revision 1.93 1999/02/22 13:07:07 pierre
  3182. + -b and -bl options work !
  3183. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  3184. is not enabled when quitting global section
  3185. * local vars and procedures are not yet stored into PPU
  3186. Revision 1.92 1999/02/17 10:14:20 peter
  3187. * set the first enumsym also for subrange types
  3188. Revision 1.91 1999/02/08 09:51:21 pierre
  3189. * gdb info for local functions was wrong
  3190. Revision 1.90 1999/01/26 09:57:29 pierre
  3191. * open arrays stabs changed
  3192. Revision 1.89 1999/01/22 17:29:30 pierre
  3193. * overflow in addname for open arrays removed
  3194. Revision 1.88 1999/01/20 14:18:39 pierre
  3195. * bugs related to mangledname solved
  3196. - linux external without name
  3197. -external procs already used
  3198. (added count and is_used boolean fiels in tprocvar)
  3199. Revision 1.87 1999/01/19 10:56:05 pierre
  3200. typeof(object) without vmt generates an error instead of an internalerror
  3201. Revision 1.86 1999/01/12 14:25:32 peter
  3202. + BrowserLog for browser.log generation
  3203. + BrowserCol for browser info in TCollections
  3204. * released all other UseBrowser
  3205. Revision 1.85 1998/12/30 22:15:52 peter
  3206. + farpointer type
  3207. * absolutesym now also stores if its far
  3208. Revision 1.84 1998/12/30 13:41:12 peter
  3209. * released valuepara
  3210. Revision 1.83 1998/12/21 14:03:08 pierre
  3211. * procvar stabs correction
  3212. Revision 1.82 1998/12/19 00:23:52 florian
  3213. * ansistring memory leaks fixed
  3214. Revision 1.81 1998/12/11 08:57:22 pierre
  3215. * internal gdb types for booleans and 64bit integers
  3216. Revision 1.80 1998/12/10 09:47:26 florian
  3217. + basic operations with int64/qord (compiler with -dint64)
  3218. + rtti of enumerations extended: names are now written
  3219. Revision 1.79 1998/12/08 10:18:12 peter
  3220. + -gh for heaptrc unit
  3221. Revision 1.78 1998/12/08 09:06:30 pierre
  3222. + constructor destructor info for gdbpas
  3223. Revision 1.77 1998/12/01 23:37:39 pierre
  3224. * function type problem for gdb fix
  3225. Revision 1.76 1998/11/29 21:45:48 florian
  3226. * problem with arrays with init tables fixed
  3227. Revision 1.75 1998/11/29 12:45:59 peter
  3228. * hack for arraydef.size overflow
  3229. Revision 1.74 1998/11/27 14:50:47 peter
  3230. + open strings, $P switch support
  3231. Revision 1.73 1998/11/26 14:47:00 michael
  3232. + Fixed RTTI constants
  3233. Revision 1.72 1998/11/25 14:35:28 florian
  3234. * writting of rtti for properties fixed
  3235. Revision 1.71 1998/11/20 15:35:59 florian
  3236. * problems with rtti fixed, hope it works
  3237. Revision 1.70 1998/11/18 15:44:16 peter
  3238. * VALUEPARA for tp7 compatible value parameters
  3239. Revision 1.69 1998/11/10 17:54:56 peter
  3240. * removed warning
  3241. Revision 1.68 1998/11/05 23:34:36 peter
  3242. * don't dispose staticsymtable (caused crash under tp7 after a fatal
  3243. error)
  3244. Revision 1.67 1998/11/05 12:02:56 peter
  3245. * released useansistring
  3246. * removed -Sv, its now available in fpc modes
  3247. Revision 1.66 1998/10/26 22:58:22 florian
  3248. * new introduded problem with classes fix, the parent class wasn't set
  3249. correct, if the class was defined forward before
  3250. Revision 1.65 1998/10/26 14:19:28 pierre
  3251. + added options -lS and -lT for source and target os output
  3252. (to have a easier way to test OS_SOURCE abd OS_TARGET in makefiles)
  3253. * several problems with rtti data
  3254. (type of sym was not checked)
  3255. assumed to be varsym when they could be procsym or property syms !!
  3256. Revision 1.64 1998/10/22 17:11:21 pierre
  3257. + terminated the include exclude implementation for i386
  3258. * enums inside records fixed
  3259. Revision 1.63 1998/10/20 09:32:56 peter
  3260. * removed some unused vars
  3261. Revision 1.62 1998/10/20 08:06:58 pierre
  3262. * several memory corruptions due to double freemem solved
  3263. => never use p^.loc.location:=p^.left^.loc.location;
  3264. + finally I added now by default
  3265. that ra386dir translates global and unit symbols
  3266. + added a first field in tsymtable and
  3267. a nextsym field in tsym
  3268. (this allows to obtain ordered type info for
  3269. records and objects in gdb !)
  3270. Revision 1.61 1998/10/19 08:55:05 pierre
  3271. * wrong stabs info corrected once again !!
  3272. + variable vmt offset with vmt field only if required
  3273. implemented now !!!
  3274. Revision 1.60 1998/10/16 13:12:53 pierre
  3275. * added vmt_offsets in destructors code also !!!
  3276. * vmt_offset code for m68k
  3277. Revision 1.59 1998/10/16 08:51:51 peter
  3278. + target_os.stackalignment
  3279. + stack can be aligned at 2 or 4 byte boundaries
  3280. Revision 1.58 1998/10/15 15:13:30 pierre
  3281. + added oo_hasconstructor and oo_hasdestructor
  3282. for objects options
  3283. Revision 1.57 1998/10/14 15:54:20 pierre
  3284. * smallsets are not entirely implemented for
  3285. m68k added a ifdef usesmallset
  3286. that is allways defined for i386
  3287. (enables testing for m68k)
  3288. Revision 1.56 1998/10/09 11:47:56 pierre
  3289. * still more memory leaks fixes !!
  3290. Revision 1.55 1998/10/06 17:16:55 pierre
  3291. * some memory leaks fixed (thanks to Peter for heaptrc !)
  3292. Revision 1.54 1998/10/05 21:33:28 peter
  3293. * fixed 161,165,166,167,168
  3294. Revision 1.53 1998/10/05 12:48:39 pierre
  3295. * wrong handling of range check for arrays fixed
  3296. Revision 1.52 1998/10/02 07:20:38 florian
  3297. * range checking in units doesn't work if the units are smartlinked, fixed
  3298. Revision 1.51 1998/09/25 12:01:41 florian
  3299. * tobjectdef.publicsyms.datasize was set to savesize, this is wrong now
  3300. because the symtable size is read from the ppu file
  3301. Revision 1.50 1998/09/23 15:46:40 florian
  3302. * problem with with and classes fixed
  3303. Revision 1.49 1998/09/23 12:03:55 peter
  3304. * overloading fix for array of const
  3305. Revision 1.48 1998/09/22 15:37:23 peter
  3306. + array of const start
  3307. Revision 1.47 1998/09/21 15:46:01 michael
  3308. Applied florians fix for check_rec_inittable
  3309. Revision 1.46 1998/09/21 08:45:21 pierre
  3310. + added vmt_offset in tobjectdef.write for fututre use
  3311. (first steps to have objects without vmt if no virtual !!)
  3312. + added fpu_used field for tabstractprocdef :
  3313. sets this level to 2 if the functions return with value in FPU
  3314. (is then set to correct value at parsing of implementation)
  3315. THIS MIGHT refuse some code with FPU expression too complex
  3316. that were accepted before and even in some cases
  3317. that don't overflow in fact
  3318. ( like if f : float; is a forward that finally in implementation
  3319. only uses one fpu register !!)
  3320. Nevertheless I think that it will improve security on
  3321. FPU operations !!
  3322. * most other changes only for UseBrowser code
  3323. (added symtable references for record and objects)
  3324. local switch for refs to args and local of each function
  3325. (static symtable still missing)
  3326. UseBrowser still not stable and probably broken by
  3327. the definition hash array !!
  3328. Revision 1.45 1998/09/20 08:31:29 florian
  3329. + bit 6 of tpropinfo.propprocs is set, if the property contains a
  3330. constant index
  3331. Revision 1.44 1998/09/19 15:23:58 florian
  3332. * rtti for ordtypes corrected
  3333. Revision 1.43 1998/09/18 17:12:40 florian
  3334. * problem with writing of class references fixed
  3335. Revision 1.42 1998/09/17 13:41:20 pierre
  3336. sizeof(TPOINT) problem
  3337. Revision 1.40.2.2 1998/09/17 08:42:33 pierre
  3338. TPOINT sizeof fix
  3339. Revision 1.41 1998/09/15 17:39:30 jonas
  3340. + bugfix from bugfix branch
  3341. Revision 1.40.2.1 1998/09/15 17:35:32 jonas
  3342. * chenged string_typ in tstringdef.wideload from ansistring to widestring
  3343. Revision 1.40 1998/09/09 15:34:00 peter
  3344. * removed warnings
  3345. Revision 1.39 1998/09/08 10:23:44 pierre
  3346. * name field of filedef corrected
  3347. Revision 1.38 1998/09/07 23:10:23 florian
  3348. * a lot of stuff fixed regarding rtti and publishing of properties,
  3349. basics should now work
  3350. Revision 1.37 1998/09/07 19:33:24 florian
  3351. + some stuff for property rtti added:
  3352. - NameIndex of the TPropInfo record is now written correctly
  3353. - the DEFAULT/NODEFAULT keyword is supported now
  3354. - the default value and the storedsym/def are now written to
  3355. the PPU fiel
  3356. Revision 1.36 1998/09/07 17:37:01 florian
  3357. * first fixes for published properties
  3358. Revision 1.35 1998/09/06 22:42:02 florian
  3359. + rtti genreation for properties added
  3360. Revision 1.34 1998/09/04 18:15:02 peter
  3361. * filedef updated
  3362. Revision 1.33 1998/09/03 17:08:49 pierre
  3363. * better lines for stabs
  3364. (no scroll back to if before else part
  3365. no return to case line at jump outside case)
  3366. + source lines also if not in order
  3367. Revision 1.32 1998/09/03 16:03:20 florian
  3368. + rtti generation
  3369. * init table generation changed
  3370. Revision 1.31 1998/09/02 15:14:28 peter
  3371. * enum packing changed from len to max
  3372. Revision 1.30 1998/09/01 17:37:29 peter
  3373. * removed debug writeln :(
  3374. Revision 1.29 1998/09/01 12:53:25 peter
  3375. + aktpackenum
  3376. Revision 1.28 1998/09/01 07:54:22 pierre
  3377. * UseBrowser a little updated (might still be buggy !!)
  3378. * bug in psub.pas in function specifier removed
  3379. * stdcall allowed in interface and in implementation
  3380. (FPC will not yet complain if it is missing in either part
  3381. because stdcall is only a dummy !!)
  3382. Revision 1.27 1998/08/28 12:51:43 florian
  3383. + ansistring to pchar type cast fixed
  3384. Revision 1.26 1998/08/25 12:42:44 pierre
  3385. * CDECL changed to CVAR for variables
  3386. specifications are read in structures also
  3387. + started adding GPC compatibility mode ( option -Sp)
  3388. * names changed to lowercase
  3389. Revision 1.25 1998/08/23 21:04:38 florian
  3390. + rtti generation for classes added
  3391. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  3392. Revision 1.24 1998/08/20 12:53:26 peter
  3393. * object_options are always written for object syms
  3394. Revision 1.23 1998/08/19 00:42:42 peter
  3395. + subrange types for enums
  3396. + checking for bounds type with ranges
  3397. Revision 1.22 1998/08/17 10:10:10 peter
  3398. - removed OLDPPU
  3399. Revision 1.21 1998/08/10 14:50:28 peter
  3400. + localswitches, moduleswitches, globalswitches splitting
  3401. Revision 1.20 1998/07/18 22:54:30 florian
  3402. * some ansi/wide/longstring support fixed:
  3403. o parameter passing
  3404. o returning as result from functions
  3405. Revision 1.19 1998/07/14 14:47:05 peter
  3406. * released NEWINPUT
  3407. Revision 1.18 1998/07/10 10:51:04 peter
  3408. * m68k updates
  3409. Revision 1.16 1998/07/07 11:20:13 peter
  3410. + NEWINPUT for a better inputfile and scanner object
  3411. Revision 1.15 1998/06/24 14:48:37 peter
  3412. * ifdef newppu -> ifndef oldppu
  3413. Revision 1.14 1998/06/16 08:56:31 peter
  3414. + targetcpu
  3415. * cleaner pmodules for newppu
  3416. Revision 1.13 1998/06/15 15:38:09 pierre
  3417. * small bug in systems.pas corrected
  3418. + operators in different units better hanlded
  3419. Revision 1.12 1998/06/15 14:30:12 daniel
  3420. * Reverted my changes.
  3421. Revision 1.10 1998/06/13 00:10:16 peter
  3422. * working browser and newppu
  3423. * some small fixes against crashes which occured in bp7 (but not in
  3424. fpc?!)
  3425. Revision 1.9 1998/06/12 14:10:37 michael
  3426. * Fixed wrong code for ansistring
  3427. Revision 1.8 1998/06/11 10:11:58 peter
  3428. * -gb works again
  3429. Revision 1.7 1998/06/07 15:30:25 florian
  3430. + first working rtti
  3431. + data init/final. for local variables
  3432. Revision 1.6 1998/06/05 14:37:37 pierre
  3433. * fixes for inline for operators
  3434. * inline procedure more correctly restricted
  3435. Revision 1.5 1998/06/04 23:52:01 peter
  3436. * m68k compiles
  3437. + .def file creation moved to gendef.pas so it could also be used
  3438. for win32
  3439. Revision 1.4 1998/06/04 09:55:45 pierre
  3440. * demangled name of procsym reworked to become independant of the mangling
  3441. scheme
  3442. Revision 1.3 1998/06/03 22:49:03 peter
  3443. + wordbool,longbool
  3444. * rename bis,von -> high,low
  3445. * moved some systemunit loading/creating to psystem.pas
  3446. Revision 1.2 1998/05/31 14:13:37 peter
  3447. * fixed call bugs with assembler readers
  3448. + OPR_SYMBOL to hold a symbol in the asm parser
  3449. * fixed staticsymtable vars which were acessed through %ebp instead of
  3450. name
  3451. Revision 1.1 1998/05/27 19:45:09 peter
  3452. * symtable.pas splitted into includefiles
  3453. * symtable adapted for $ifndef OLDPPU
  3454. }