2
0

symdef.inc 115 KB

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