symsym.pas 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Implementation for the symbols types of the symtable
  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. unit symsym;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,
  24. { target }
  25. globtype,globals,
  26. { symtable }
  27. symconst,symbase,symtype,symdef,defcmp,
  28. { ppu }
  29. ppu,symppu,
  30. cclasses,symnot,
  31. { aasm }
  32. aasmbase,aasmtai,
  33. cpuinfo,cpubase,cgbase
  34. ;
  35. type
  36. {************************************************
  37. TSym
  38. ************************************************}
  39. { this object is the base for all symbol objects }
  40. tstoredsym = class(tsym)
  41. protected
  42. _mangledname : pstring;
  43. public
  44. refs : longint;
  45. lastref,
  46. defref,
  47. lastwritten : tref;
  48. refcount : longint;
  49. {$ifdef GDB}
  50. isstabwritten : boolean;
  51. {$endif GDB}
  52. constructor create(const n : string);
  53. constructor loadsym(ppufile:tcompilerppufile);
  54. destructor destroy;override;
  55. procedure ppuwrite(ppufile:tcompilerppufile);virtual;abstract;
  56. procedure writesym(ppufile:tcompilerppufile);
  57. procedure buildderef;override;
  58. procedure deref;override;
  59. {$ifdef GDB}
  60. function stabstring : pchar;virtual;
  61. procedure concatstabto(asmlist : taasmoutput);virtual;
  62. {$endif GDB}
  63. procedure load_references(ppufile:tcompilerppufile;locals:boolean);virtual;
  64. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;virtual;
  65. function is_visible_for_object(currobjdef:tobjectdef):boolean;
  66. function mangledname : string;
  67. procedure generate_mangledname;virtual;abstract;
  68. end;
  69. tlabelsym = class(tstoredsym)
  70. lab : tasmlabel;
  71. used,
  72. defined : boolean;
  73. code : pointer; { should be tnode }
  74. constructor create(const n : string; l : tasmlabel);
  75. destructor destroy;override;
  76. constructor ppuload(ppufile:tcompilerppufile);
  77. procedure generate_mangledname;override;
  78. procedure ppuwrite(ppufile:tcompilerppufile);override;
  79. end;
  80. tunitsym = class(tstoredsym)
  81. unitsymtable : tsymtable;
  82. constructor create(const n : string;ref : tsymtable);
  83. constructor ppuload(ppufile:tcompilerppufile);
  84. destructor destroy;override;
  85. procedure ppuwrite(ppufile:tcompilerppufile);override;
  86. {$ifdef GDB}
  87. procedure concatstabto(asmlist : taasmoutput);override;
  88. {$endif GDB}
  89. end;
  90. terrorsym = class(tstoredsym)
  91. constructor create;
  92. end;
  93. Tprocdefcallback = procedure(p:Tprocdef;arg:pointer);
  94. tprocsym = class(tstoredsym)
  95. protected
  96. pdlistfirst,
  97. pdlistlast : pprocdeflist; { linked list of overloaded procdefs }
  98. function getprocdef(nr:cardinal):Tprocdef;
  99. public
  100. procdef_count : byte;
  101. {$ifdef GDB}
  102. is_global : boolean;
  103. {$endif GDB}
  104. overloadchecked : boolean;
  105. overloadcount : word; { amount of overloaded functions in this module }
  106. property procdef[nr:cardinal]:Tprocdef read getprocdef;
  107. constructor create(const n : string);
  108. constructor ppuload(ppufile:tcompilerppufile);
  109. destructor destroy;override;
  110. { writes all declarations except the specified one }
  111. procedure write_parameter_lists(skipdef:tprocdef);
  112. { tests, if all procedures definitions are defined and not }
  113. { only forward }
  114. procedure check_forward;
  115. procedure unchain_overload;
  116. procedure ppuwrite(ppufile:tcompilerppufile);override;
  117. procedure buildderef;override;
  118. procedure deref;override;
  119. procedure addprocdef(p:tprocdef);
  120. procedure addprocdef_deref(const d:tderef);
  121. procedure add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  122. procedure concat_procdefs_to(s:Tprocsym);
  123. procedure foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  124. function first_procdef:Tprocdef;
  125. function last_procdef:Tprocdef;
  126. function search_procdef_nopara_boolret:Tprocdef;
  127. function search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  128. function search_procdef_bypara(params:Tlinkedlist;
  129. retdef:tdef;
  130. cpoptions:tcompare_paras_options):Tprocdef;
  131. function search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  132. function search_procdef_unary_operator(firstpara:Tdef):Tprocdef;
  133. function search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
  134. function search_procdef_binary_operator(def1,def2:tdef):Tprocdef;
  135. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  136. {$ifdef GDB}
  137. function stabstring : pchar;override;
  138. procedure concatstabto(asmlist : taasmoutput);override;
  139. {$endif GDB}
  140. end;
  141. ttypesym = class(tstoredsym)
  142. restype : ttype;
  143. {$ifdef GDB}
  144. isusedinstab : boolean;
  145. {$endif GDB}
  146. constructor create(const n : string;const tt : ttype);
  147. constructor ppuload(ppufile:tcompilerppufile);
  148. procedure ppuwrite(ppufile:tcompilerppufile);override;
  149. procedure buildderef;override;
  150. procedure deref;override;
  151. function gettypedef:tdef;override;
  152. procedure load_references(ppufile:tcompilerppufile;locals:boolean);override;
  153. function write_references(ppufile:tcompilerppufile;locals:boolean):boolean;override;
  154. {$ifdef GDB}
  155. function stabstring : pchar;override;
  156. procedure concatstabto(asmlist : taasmoutput);override;
  157. {$endif GDB}
  158. end;
  159. tvarsym = class(tstoredsym)
  160. highvarsym : tvarsym;
  161. defaultconstsym : tsym;
  162. varoptions : tvaroptions;
  163. varspez : tvarspez; { sets the type of access }
  164. varstate : tvarstate;
  165. localloc : tparalocation; { register/reference for local var }
  166. fieldoffset : longint; { offset in record/object }
  167. paraitem : tparaitem;
  168. notifications : Tlinkedlist;
  169. constructor create(const n : string;vsp:tvarspez;const tt : ttype);
  170. constructor create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  171. constructor create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  172. constructor ppuload(ppufile:tcompilerppufile);
  173. destructor destroy;override;
  174. procedure ppuwrite(ppufile:tcompilerppufile);override;
  175. procedure buildderef;override;
  176. procedure deref;override;
  177. procedure generate_mangledname;override;
  178. procedure set_mangledname(const s:string);
  179. function getsize : longint;
  180. function getvaluesize : longint;
  181. procedure trigger_notifications(what:Tnotification_flag);
  182. function register_notification(flags:Tnotification_flags;
  183. callback:Tnotification_callback):cardinal;
  184. procedure unregister_notification(id:cardinal);
  185. {$ifdef GDB}
  186. function stabstring : pchar;override;
  187. procedure concatstabto(asmlist : taasmoutput);override;
  188. {$endif GDB}
  189. private
  190. procedure setvartype(const newtype: ttype);
  191. _vartype : ttype;
  192. public
  193. property vartype: ttype read _vartype write setvartype;
  194. end;
  195. tpropertysym = class(tstoredsym)
  196. propoptions : tpropertyoptions;
  197. propoverriden : tpropertysym;
  198. propoverridenderef : tderef;
  199. proptype,
  200. indextype : ttype;
  201. index,
  202. default : longint;
  203. readaccess,
  204. writeaccess,
  205. storedaccess : tsymlist;
  206. constructor create(const n : string);
  207. destructor destroy;override;
  208. constructor ppuload(ppufile:tcompilerppufile);
  209. function getsize : longint;
  210. procedure ppuwrite(ppufile:tcompilerppufile);override;
  211. function gettypedef:tdef;override;
  212. procedure buildderef;override;
  213. procedure deref;override;
  214. procedure dooverride(overriden:tpropertysym);
  215. {$ifdef GDB}
  216. function stabstring : pchar;override;
  217. procedure concatstabto(asmlist : taasmoutput);override;
  218. {$endif GDB}
  219. end;
  220. tabsolutesym = class(tvarsym)
  221. abstyp : absolutetyp;
  222. absseg : boolean;
  223. asmname : pstring;
  224. ref : tsymlist;
  225. constructor create(const n : string;const tt : ttype);
  226. constructor create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  227. destructor destroy;override;
  228. constructor ppuload(ppufile:tcompilerppufile);
  229. procedure buildderef;override;
  230. procedure deref;override;
  231. function mangledname : string;
  232. procedure ppuwrite(ppufile:tcompilerppufile);override;
  233. {$ifdef GDB}
  234. procedure concatstabto(asmlist : taasmoutput);override;
  235. {$endif GDB}
  236. end;
  237. ttypedconstsym = class(tstoredsym)
  238. typedconsttype : ttype;
  239. is_writable : boolean;
  240. constructor create(const n : string;p : tdef;writable : boolean);
  241. constructor createtype(const n : string;const tt : ttype;writable : boolean);
  242. constructor ppuload(ppufile:tcompilerppufile);
  243. destructor destroy;override;
  244. procedure generate_mangledname;override;
  245. procedure ppuwrite(ppufile:tcompilerppufile);override;
  246. procedure buildderef;override;
  247. procedure deref;override;
  248. function getsize:longint;
  249. {$ifdef GDB}
  250. function stabstring : pchar;override;
  251. {$endif GDB}
  252. end;
  253. tconstvalue = record
  254. case integer of
  255. 0: (valueord : tconstexprint);
  256. 1: (valueordptr : tconstptruint);
  257. 2: (valueptr : pointer; len : longint);
  258. end;
  259. tconstsym = class(tstoredsym)
  260. consttype : ttype;
  261. consttyp : tconsttyp;
  262. value : tconstvalue;
  263. resstrindex : longint; { needed for resource strings }
  264. constructor create_ord(const n : string;t : tconsttyp;v : tconstexprint);
  265. constructor create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  266. constructor create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  267. constructor create_ptr(const n : string;t : tconsttyp;v : pointer);
  268. constructor create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  269. constructor create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  270. constructor ppuload(ppufile:tcompilerppufile);
  271. destructor destroy;override;
  272. function mangledname : string;
  273. procedure buildderef;override;
  274. procedure deref;override;
  275. procedure ppuwrite(ppufile:tcompilerppufile);override;
  276. {$ifdef GDB}
  277. function stabstring : pchar;override;
  278. procedure concatstabto(asmlist : taasmoutput);override;
  279. {$endif GDB}
  280. end;
  281. tenumsym = class(tstoredsym)
  282. value : longint;
  283. definition : tenumdef;
  284. definitionderef : tderef;
  285. nextenum : tenumsym;
  286. constructor create(const n : string;def : tenumdef;v : longint);
  287. constructor ppuload(ppufile:tcompilerppufile);
  288. procedure ppuwrite(ppufile:tcompilerppufile);override;
  289. procedure buildderef;override;
  290. procedure deref;override;
  291. procedure order;
  292. {$ifdef GDB}
  293. procedure concatstabto(asmlist : taasmoutput);override;
  294. {$endif GDB}
  295. end;
  296. tsyssym = class(tstoredsym)
  297. number : longint;
  298. constructor create(const n : string;l : longint);
  299. constructor ppuload(ppufile:tcompilerppufile);
  300. destructor destroy;override;
  301. procedure ppuwrite(ppufile:tcompilerppufile);override;
  302. {$ifdef GDB}
  303. procedure concatstabto(asmlist : taasmoutput);override;
  304. {$endif GDB}
  305. end;
  306. { compiler generated symbol to point to rtti and init/finalize tables }
  307. trttisym = class(tstoredsym)
  308. lab : tasmsymbol;
  309. rttityp : trttitype;
  310. constructor create(const n:string;rt:trttitype);
  311. constructor ppuload(ppufile:tcompilerppufile);
  312. procedure ppuwrite(ppufile:tcompilerppufile);override;
  313. function mangledname:string;
  314. function get_label:tasmsymbol;
  315. end;
  316. (*
  317. { register variables }
  318. pregvarinfo = ^tregvarinfo;
  319. tregvarinfo = record
  320. regvars : array[1..maxvarregs] of tvarsym;
  321. regvars_para : array[1..maxvarregs] of boolean;
  322. regvars_refs : array[1..maxvarregs] of longint;
  323. fpuregvars : array[1..maxfpuvarregs] of tvarsym;
  324. fpuregvars_para : array[1..maxfpuvarregs] of boolean;
  325. fpuregvars_refs : array[1..maxfpuvarregs] of longint;
  326. end;
  327. *)
  328. var
  329. generrorsym : tsym;
  330. const
  331. current_object_option : tsymoptions = [sp_public];
  332. { rtti and init/final }
  333. procedure generate_rtti(p:tsym);
  334. procedure generate_inittable(p:tsym);
  335. implementation
  336. uses
  337. {$ifdef Delphi}
  338. sysutils,
  339. {$else Delphi}
  340. strings,
  341. {$endif Delphi}
  342. { global }
  343. verbose,
  344. { target }
  345. systems,
  346. { symtable }
  347. defutil,symtable,
  348. {$ifdef GDB}
  349. gdb,
  350. {$endif GDB}
  351. { tree }
  352. node,
  353. { aasm }
  354. aasmcpu,
  355. { module }
  356. fmodule,
  357. { codegen }
  358. paramgr,cresstr,
  359. procinfo
  360. ;
  361. {****************************************************************************
  362. Helpers
  363. ****************************************************************************}
  364. {****************************************************************************
  365. TSYM (base for all symtypes)
  366. ****************************************************************************}
  367. constructor tstoredsym.create(const n : string);
  368. begin
  369. inherited create(n);
  370. symoptions:=current_object_option;
  371. {$ifdef GDB}
  372. isstabwritten := false;
  373. {$endif GDB}
  374. fileinfo:=akttokenpos;
  375. defref:=nil;
  376. refs:=0;
  377. lastwritten:=nil;
  378. refcount:=0;
  379. if (cs_browser in aktmoduleswitches) and make_ref then
  380. begin
  381. defref:=tref.create(defref,@akttokenpos);
  382. inc(refcount);
  383. end;
  384. lastref:=defref;
  385. _mangledname:=nil;
  386. end;
  387. constructor tstoredsym.loadsym(ppufile:tcompilerppufile);
  388. var
  389. s : string;
  390. nr : word;
  391. begin
  392. nr:=ppufile.getword;
  393. s:=ppufile.getstring;
  394. inherited create(s);
  395. { force the correct indexnr. must be after create! }
  396. indexnr:=nr;
  397. ppufile.getposinfo(fileinfo);
  398. ppufile.getsmallset(symoptions);
  399. lastref:=nil;
  400. defref:=nil;
  401. refs:=0;
  402. lastwritten:=nil;
  403. refcount:=0;
  404. _mangledname:=nil;
  405. {$ifdef GDB}
  406. isstabwritten := false;
  407. {$endif GDB}
  408. end;
  409. procedure tstoredsym.buildderef;
  410. begin
  411. end;
  412. procedure tstoredsym.deref;
  413. begin
  414. end;
  415. procedure tstoredsym.load_references(ppufile:tcompilerppufile;locals:boolean);
  416. var
  417. pos : tfileposinfo;
  418. move_last : boolean;
  419. begin
  420. move_last:=lastwritten=lastref;
  421. while (not ppufile.endofentry) do
  422. begin
  423. ppufile.getposinfo(pos);
  424. inc(refcount);
  425. lastref:=tref.create(lastref,@pos);
  426. lastref.is_written:=true;
  427. if refcount=1 then
  428. defref:=lastref;
  429. end;
  430. if move_last then
  431. lastwritten:=lastref;
  432. end;
  433. { big problem here :
  434. wrong refs were written because of
  435. interface parsing of other units PM
  436. moduleindex must be checked !! }
  437. function tstoredsym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  438. var
  439. d : tderef;
  440. ref : tref;
  441. symref_written,move_last : boolean;
  442. begin
  443. write_references:=false;
  444. if lastwritten=lastref then
  445. exit;
  446. { should we update lastref }
  447. move_last:=true;
  448. symref_written:=false;
  449. { write symbol refs }
  450. d.reset;
  451. if assigned(lastwritten) then
  452. ref:=lastwritten
  453. else
  454. ref:=defref;
  455. while assigned(ref) do
  456. begin
  457. if ref.moduleindex=current_module.unit_index then
  458. begin
  459. { write address to this symbol }
  460. if not symref_written then
  461. begin
  462. d.build(self);
  463. ppufile.putderef(d);
  464. symref_written:=true;
  465. end;
  466. ppufile.putposinfo(ref.posinfo);
  467. ref.is_written:=true;
  468. if move_last then
  469. lastwritten:=ref;
  470. end
  471. else if not ref.is_written then
  472. move_last:=false
  473. else if move_last then
  474. lastwritten:=ref;
  475. ref:=ref.nextref;
  476. end;
  477. if symref_written then
  478. ppufile.writeentry(ibsymref);
  479. write_references:=symref_written;
  480. end;
  481. destructor tstoredsym.destroy;
  482. begin
  483. if assigned(_mangledname) then
  484. begin
  485. {$ifdef MEMDEBUG}
  486. memmanglednames.start;
  487. {$endif MEMDEBUG}
  488. stringdispose(_mangledname);
  489. {$ifdef MEMDEBUG}
  490. memmanglednames.stop;
  491. {$endif MEMDEBUG}
  492. end;
  493. if assigned(defref) then
  494. begin
  495. {$ifdef MEMDEBUG}
  496. membrowser.start;
  497. {$endif MEMDEBUG}
  498. defref.freechain;
  499. defref.free;
  500. {$ifdef MEMDEBUG}
  501. membrowser.stop;
  502. {$endif MEMDEBUG}
  503. end;
  504. inherited destroy;
  505. end;
  506. procedure tstoredsym.writesym(ppufile:tcompilerppufile);
  507. begin
  508. ppufile.putword(indexnr);
  509. ppufile.putstring(_realname^);
  510. ppufile.putposinfo(fileinfo);
  511. ppufile.putsmallset(symoptions);
  512. end;
  513. {$ifdef GDB}
  514. function tstoredsym.stabstring : pchar;
  515. begin
  516. stabstring:=strpnew('"'+name+'",'+tostr(N_LSYM)+',0,'+
  517. tostr(fileinfo.line)+',0');
  518. end;
  519. procedure tstoredsym.concatstabto(asmlist : taasmoutput);
  520. var
  521. stab_str : pchar;
  522. begin
  523. if not isstabwritten then
  524. begin
  525. stab_str := stabstring;
  526. if assigned(stab_str) then
  527. asmList.concat(Tai_stabs.Create(stab_str));
  528. isstabwritten:=true;
  529. end;
  530. end;
  531. {$endif GDB}
  532. function tstoredsym.is_visible_for_object(currobjdef:tobjectdef):boolean;
  533. begin
  534. is_visible_for_object:=false;
  535. { private symbols are allowed when we are in the same
  536. module as they are defined }
  537. if (sp_private in symoptions) and
  538. assigned(owner.defowner) and
  539. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  540. (owner.defowner.owner.unitid<>0) then
  541. exit;
  542. { protected symbols are vissible in the module that defines them and
  543. also visible to related objects }
  544. if (sp_protected in symoptions) and
  545. (
  546. (
  547. assigned(owner.defowner) and
  548. (owner.defowner.owner.symtabletype in [globalsymtable,staticsymtable]) and
  549. (owner.defowner.owner.unitid<>0)
  550. ) and
  551. not(
  552. assigned(currobjdef) and
  553. currobjdef.is_related(tobjectdef(owner.defowner))
  554. )
  555. ) then
  556. exit;
  557. is_visible_for_object:=true;
  558. end;
  559. function tstoredsym.mangledname : string;
  560. begin
  561. if not assigned(_mangledname) then
  562. begin
  563. generate_mangledname;
  564. if not assigned(_mangledname) then
  565. internalerror(200204171);
  566. end;
  567. mangledname:=_mangledname^
  568. end;
  569. {****************************************************************************
  570. TLABELSYM
  571. ****************************************************************************}
  572. constructor tlabelsym.create(const n : string; l : tasmlabel);
  573. begin
  574. inherited create(n);
  575. typ:=labelsym;
  576. lab:=l;
  577. used:=false;
  578. defined:=false;
  579. code:=nil;
  580. end;
  581. constructor tlabelsym.ppuload(ppufile:tcompilerppufile);
  582. begin
  583. inherited loadsym(ppufile);
  584. typ:=labelsym;
  585. { this is all dummy
  586. it is only used for local browsing }
  587. lab:=nil;
  588. code:=nil;
  589. used:=false;
  590. defined:=true;
  591. end;
  592. destructor tlabelsym.destroy;
  593. begin
  594. inherited destroy;
  595. end;
  596. procedure tlabelsym.generate_mangledname;
  597. begin
  598. _mangledname:=stringdup(lab.name);
  599. end;
  600. procedure tlabelsym.ppuwrite(ppufile:tcompilerppufile);
  601. begin
  602. if owner.symtabletype=globalsymtable then
  603. Message(sym_e_ill_label_decl)
  604. else
  605. begin
  606. inherited writesym(ppufile);
  607. ppufile.writeentry(iblabelsym);
  608. end;
  609. end;
  610. {****************************************************************************
  611. TUNITSYM
  612. ****************************************************************************}
  613. constructor tunitsym.create(const n : string;ref : tsymtable);
  614. var
  615. old_make_ref : boolean;
  616. begin
  617. old_make_ref:=make_ref;
  618. make_ref:=false;
  619. inherited create(n);
  620. make_ref:=old_make_ref;
  621. typ:=unitsym;
  622. unitsymtable:=ref;
  623. end;
  624. constructor tunitsym.ppuload(ppufile:tcompilerppufile);
  625. begin
  626. inherited loadsym(ppufile);
  627. typ:=unitsym;
  628. unitsymtable:=nil;
  629. refs:=0;
  630. end;
  631. destructor tunitsym.destroy;
  632. begin
  633. inherited destroy;
  634. end;
  635. procedure tunitsym.ppuwrite(ppufile:tcompilerppufile);
  636. begin
  637. inherited writesym(ppufile);
  638. ppufile.writeentry(ibunitsym);
  639. end;
  640. {$ifdef GDB}
  641. procedure tunitsym.concatstabto(asmlist : taasmoutput);
  642. begin
  643. {Nothing to write to stabs !}
  644. end;
  645. {$endif GDB}
  646. {****************************************************************************
  647. TPROCSYM
  648. ****************************************************************************}
  649. constructor tprocsym.create(const n : string);
  650. begin
  651. inherited create(n);
  652. typ:=procsym;
  653. pdlistfirst:=nil;
  654. pdlistlast:=nil;
  655. owner:=nil;
  656. {$ifdef GDB}
  657. is_global:=false;
  658. {$endif GDB}
  659. overloadchecked:=false;
  660. overloadcount:=0;
  661. procdef_count:=0;
  662. end;
  663. constructor tprocsym.ppuload(ppufile:tcompilerppufile);
  664. var
  665. pdderef : tderef;
  666. i,n : longint;
  667. begin
  668. inherited loadsym(ppufile);
  669. typ:=procsym;
  670. pdlistfirst:=nil;
  671. pdlistlast:=nil;
  672. procdef_count:=0;
  673. n:=ppufile.getword;
  674. for i:=1to n do
  675. begin
  676. ppufile.getderef(pdderef);
  677. addprocdef_deref(pdderef);
  678. end;
  679. {$ifdef GDB}
  680. is_global:=false;
  681. {$endif GDB}
  682. overloadchecked:=false;
  683. overloadcount:=$ffff; { invalid, not used anymore }
  684. end;
  685. destructor tprocsym.destroy;
  686. var
  687. hp,p : pprocdeflist;
  688. begin
  689. p:=pdlistfirst;
  690. while assigned(p) do
  691. begin
  692. hp:=p^.next;
  693. dispose(p);
  694. p:=hp;
  695. end;
  696. inherited destroy;
  697. end;
  698. procedure tprocsym.ppuwrite(ppufile:tcompilerppufile);
  699. var
  700. p : pprocdeflist;
  701. n : word;
  702. begin
  703. inherited writesym(ppufile);
  704. { count procdefs }
  705. n:=0;
  706. p:=pdlistfirst;
  707. while assigned(p) do
  708. begin
  709. { only write the proc definitions that belong
  710. to this procsym and are in the global symtable }
  711. if p^.own and
  712. (p^.def.owner.symtabletype in [globalsymtable,objectsymtable]) then
  713. inc(n);
  714. p:=p^.next;
  715. end;
  716. ppufile.putword(n);
  717. { write procdefs }
  718. p:=pdlistfirst;
  719. while assigned(p) do
  720. begin
  721. { only write the proc definitions that belong
  722. to this procsym and are in the global symtable }
  723. if p^.own and
  724. (p^.def.owner.symtabletype in [globalsymtable,objectsymtable]) then
  725. ppufile.putderef(p^.defderef);
  726. p:=p^.next;
  727. end;
  728. ppufile.writeentry(ibprocsym);
  729. end;
  730. procedure tprocsym.write_parameter_lists(skipdef:tprocdef);
  731. var
  732. p : pprocdeflist;
  733. begin
  734. p:=pdlistfirst;
  735. while assigned(p) do
  736. begin
  737. if p^.def<>skipdef then
  738. MessagePos1(p^.def.fileinfo,sym_h_param_list,p^.def.fullprocname(false));
  739. p:=p^.next;
  740. end;
  741. end;
  742. procedure tprocsym.check_forward;
  743. var
  744. p : pprocdeflist;
  745. begin
  746. p:=pdlistfirst;
  747. while assigned(p) do
  748. begin
  749. if p^.own and
  750. (p^.def.forwarddef) then
  751. begin
  752. MessagePos1(p^.def.fileinfo,sym_e_forward_not_resolved,p^.def.fullprocname(false));
  753. { Turn futher error messages off }
  754. p^.def.forwarddef:=false;
  755. end;
  756. p:=p^.next;
  757. end;
  758. end;
  759. procedure tprocsym.buildderef;
  760. var
  761. p : pprocdeflist;
  762. begin
  763. p:=pdlistfirst;
  764. while assigned(p) do
  765. begin
  766. if p^.own then
  767. p^.defderef.build(p^.def);
  768. p:=p^.next;
  769. end;
  770. end;
  771. procedure tprocsym.deref;
  772. var
  773. p : pprocdeflist;
  774. begin
  775. { We have removed the overloaded entries, because they
  776. are not valid anymore and we can't deref them because
  777. the unit were they come from is not necessary in
  778. our uses clause (PFV) }
  779. unchain_overload;
  780. { Deref our own procdefs }
  781. p:=pdlistfirst;
  782. while assigned(p) do
  783. begin
  784. if not p^.own then
  785. internalerror(200310291);
  786. p^.def:=tprocdef(p^.defderef.resolve);
  787. p:=p^.next;
  788. end;
  789. end;
  790. procedure tprocsym.addprocdef(p:tprocdef);
  791. var
  792. pd : pprocdeflist;
  793. begin
  794. new(pd);
  795. pd^.def:=p;
  796. pd^.defderef.reset;
  797. pd^.next:=nil;
  798. pd^.own:=(pd^.def.procsym=self);
  799. { Add at end of list to keep always
  800. a correct order, also after loading from ppu }
  801. if assigned(pdlistlast) then
  802. begin
  803. pdlistlast^.next:=pd;
  804. pdlistlast:=pd;
  805. end
  806. else
  807. begin
  808. pdlistfirst:=pd;
  809. pdlistlast:=pd;
  810. end;
  811. inc(procdef_count);
  812. end;
  813. procedure tprocsym.addprocdef_deref(const d:tderef);
  814. var
  815. pd : pprocdeflist;
  816. begin
  817. new(pd);
  818. pd^.def:=nil;
  819. pd^.defderef:=d;
  820. pd^.next:=nil;
  821. pd^.own:=true;
  822. { Add at end of list to keep always
  823. a correct order, also after loading from ppu }
  824. if assigned(pdlistlast) then
  825. begin
  826. pdlistlast^.next:=pd;
  827. pdlistlast:=pd;
  828. end
  829. else
  830. begin
  831. pdlistfirst:=pd;
  832. pdlistlast:=pd;
  833. end;
  834. inc(procdef_count);
  835. end;
  836. function Tprocsym.getprocdef(nr:cardinal):Tprocdef;
  837. var
  838. i : cardinal;
  839. pd : pprocdeflist;
  840. begin
  841. pd:=pdlistfirst;
  842. for i:=2 to nr do
  843. begin
  844. if not assigned(pd) then
  845. internalerror(200209051);
  846. pd:=pd^.next;
  847. end;
  848. getprocdef:=pd^.def;
  849. end;
  850. procedure Tprocsym.add_para_match_to(Aprocsym:Tprocsym;cpoptions:tcompare_paras_options);
  851. var
  852. pd:pprocdeflist;
  853. begin
  854. pd:=pdlistfirst;
  855. while assigned(pd) do
  856. begin
  857. if Aprocsym.search_procdef_bypara(pd^.def.para,nil,cpoptions)=nil then
  858. Aprocsym.addprocdef(pd^.def);
  859. pd:=pd^.next;
  860. end;
  861. end;
  862. procedure Tprocsym.concat_procdefs_to(s:Tprocsym);
  863. var
  864. pd : pprocdeflist;
  865. begin
  866. pd:=pdlistfirst;
  867. while assigned(pd) do
  868. begin
  869. s.addprocdef(pd^.def);
  870. pd:=pd^.next;
  871. end;
  872. end;
  873. function Tprocsym.first_procdef:Tprocdef;
  874. begin
  875. if assigned(pdlistfirst) then
  876. first_procdef:=pdlistfirst^.def
  877. else
  878. first_procdef:=nil;
  879. end;
  880. function Tprocsym.last_procdef:Tprocdef;
  881. begin
  882. if assigned(pdlistlast) then
  883. last_procdef:=pdlistlast^.def
  884. else
  885. last_procdef:=nil;
  886. end;
  887. procedure Tprocsym.foreach_procdef_static(proc2call:Tprocdefcallback;arg:pointer);
  888. var
  889. p : pprocdeflist;
  890. begin
  891. p:=pdlistfirst;
  892. while assigned(p) do
  893. begin
  894. proc2call(p^.def,arg);
  895. p:=p^.next;
  896. end;
  897. end;
  898. function Tprocsym.search_procdef_nopara_boolret:Tprocdef;
  899. var
  900. p : pprocdeflist;
  901. begin
  902. search_procdef_nopara_boolret:=nil;
  903. p:=pdlistfirst;
  904. while p<>nil do
  905. begin
  906. if (p^.def.maxparacount=0) and
  907. is_boolean(p^.def.rettype.def) then
  908. begin
  909. search_procdef_nopara_boolret:=p^.def;
  910. break;
  911. end;
  912. p:=p^.next;
  913. end;
  914. end;
  915. function Tprocsym.search_procdef_bytype(pt:Tproctypeoption):Tprocdef;
  916. var
  917. p : pprocdeflist;
  918. begin
  919. search_procdef_bytype:=nil;
  920. p:=pdlistfirst;
  921. while p<>nil do
  922. begin
  923. if p^.def.proctypeoption=pt then
  924. begin
  925. search_procdef_bytype:=p^.def;
  926. break;
  927. end;
  928. p:=p^.next;
  929. end;
  930. end;
  931. function Tprocsym.search_procdef_bypara(params:Tlinkedlist;
  932. retdef:tdef;
  933. cpoptions:tcompare_paras_options):Tprocdef;
  934. var
  935. pd : pprocdeflist;
  936. eq : tequaltype;
  937. begin
  938. search_procdef_bypara:=nil;
  939. pd:=pdlistfirst;
  940. while assigned(pd) do
  941. begin
  942. if assigned(retdef) then
  943. eq:=compare_defs(retdef,pd^.def.rettype.def,nothingn)
  944. else
  945. eq:=te_equal;
  946. if (eq>=te_equal) or
  947. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  948. begin
  949. eq:=compare_paras(pd^.def.para,params,cp_value_equal_const,cpoptions);
  950. if (eq>=te_equal) or
  951. ((cpo_allowconvert in cpoptions) and (eq>te_incompatible)) then
  952. begin
  953. search_procdef_bypara:=pd^.def;
  954. break;
  955. end;
  956. end;
  957. pd:=pd^.next;
  958. end;
  959. end;
  960. function Tprocsym.search_procdef_byprocvardef(d:Tprocvardef):Tprocdef;
  961. var
  962. pd : pprocdeflist;
  963. eq,besteq : tequaltype;
  964. bestpd : tprocdef;
  965. begin
  966. { This function will return the pprocdef of pprocsym that
  967. is the best match for procvardef. When there are multiple
  968. matches it returns nil.}
  969. search_procdef_byprocvardef:=nil;
  970. bestpd:=nil;
  971. besteq:=te_incompatible;
  972. pd:=pdlistfirst;
  973. while assigned(pd) do
  974. begin
  975. eq:=proc_to_procvar_equal(pd^.def,d,false);
  976. if eq>=te_equal then
  977. begin
  978. { multiple procvars with the same equal level }
  979. if assigned(bestpd) and
  980. (besteq=eq) then
  981. exit;
  982. if eq>besteq then
  983. begin
  984. besteq:=eq;
  985. bestpd:=pd^.def;
  986. end;
  987. end;
  988. pd:=pd^.next;
  989. end;
  990. search_procdef_byprocvardef:=bestpd;
  991. end;
  992. function Tprocsym.search_procdef_unary_operator(firstpara:Tdef):Tprocdef;
  993. var
  994. pd : pprocdeflist;
  995. currpara : tparaitem;
  996. begin
  997. search_procdef_unary_operator:=nil;
  998. pd:=pdlistfirst;
  999. while assigned(pd) do
  1000. begin
  1001. currpara:=tparaitem(pd^.def.para.first);
  1002. { ignore vs_hidden parameters }
  1003. while assigned(currpara) and (currpara.is_hidden) do
  1004. currpara:=tparaitem(currpara.next);
  1005. if assigned(currpara) then
  1006. begin
  1007. if equal_defs(currpara.paratype.def,firstpara) then
  1008. begin
  1009. { This must be the last not hidden parameter }
  1010. currpara:=tparaitem(currpara.next);
  1011. while assigned(currpara) and (currpara.is_hidden) do
  1012. currpara:=tparaitem(currpara.next);
  1013. if currpara=nil then
  1014. begin
  1015. search_procdef_unary_operator:=pd^.def;
  1016. break;
  1017. end;
  1018. end;
  1019. end;
  1020. pd:=pd^.next;
  1021. end;
  1022. end;
  1023. function Tprocsym.search_procdef_assignment_operator(fromdef,todef:tdef):Tprocdef;
  1024. var
  1025. convtyp : tconverttype;
  1026. pd : pprocdeflist;
  1027. bestpd : tprocdef;
  1028. eq,
  1029. besteq : tequaltype;
  1030. hpd : tprocdef;
  1031. currpara : tparaitem;
  1032. begin
  1033. search_procdef_assignment_operator:=nil;
  1034. bestpd:=nil;
  1035. besteq:=te_incompatible;
  1036. pd:=pdlistfirst;
  1037. while assigned(pd) do
  1038. begin
  1039. if equal_defs(todef,pd^.def.rettype.def) then
  1040. begin
  1041. currpara:=Tparaitem(pd^.def.para.first);
  1042. { ignore vs_hidden parameters }
  1043. while assigned(currpara) and (currpara.is_hidden) do
  1044. currpara:=tparaitem(currpara.next);
  1045. if assigned(currpara) then
  1046. begin
  1047. eq:=compare_defs_ext(fromdef,currpara.paratype.def,
  1048. nothingn,false,false,convtyp,hpd);
  1049. if eq=te_exact then
  1050. begin
  1051. search_procdef_assignment_operator:=pd^.def;
  1052. exit;
  1053. end;
  1054. if eq>besteq then
  1055. begin
  1056. bestpd:=pd^.def;
  1057. besteq:=eq;
  1058. end;
  1059. end;
  1060. end;
  1061. pd:=pd^.next;
  1062. end;
  1063. search_procdef_assignment_operator:=bestpd;
  1064. end;
  1065. function Tprocsym.search_procdef_binary_operator(def1,def2:tdef):Tprocdef;
  1066. var
  1067. convtyp : tconverttype;
  1068. pd : pprocdeflist;
  1069. bestpd : tprocdef;
  1070. eq1,eq2 : tequaltype;
  1071. eqlev,
  1072. bestlev : byte;
  1073. hpd : tprocdef;
  1074. nextpara,
  1075. currpara : tparaitem;
  1076. begin
  1077. search_procdef_binary_operator:=nil;
  1078. bestpd:=nil;
  1079. bestlev:=0;
  1080. pd:=pdlistfirst;
  1081. while assigned(pd) do
  1082. begin
  1083. currpara:=Tparaitem(pd^.def.para.first);
  1084. { ignore vs_hidden parameters }
  1085. while assigned(currpara) and (currpara.is_hidden) do
  1086. currpara:=tparaitem(currpara.next);
  1087. if assigned(currpara) then
  1088. begin
  1089. { Compare def1 with the first para }
  1090. eq1:=compare_defs_ext(def1,currpara.paratype.def,
  1091. nothingn,false,false,convtyp,hpd);
  1092. if eq1<>te_incompatible then
  1093. begin
  1094. { Ignore vs_hidden parameters }
  1095. repeat
  1096. currpara:=tparaitem(currpara.next);
  1097. until (not assigned(currpara)) or (not currpara.is_hidden);
  1098. if assigned(currpara) then
  1099. begin
  1100. { Ignore vs_hidden parameters }
  1101. nextpara:=currpara;
  1102. repeat
  1103. nextpara:=tparaitem(nextpara.next);
  1104. until (not assigned(nextpara)) or (not nextpara.is_hidden);
  1105. { There should be no other parameters left }
  1106. if not assigned(nextpara) then
  1107. begin
  1108. { Compare def2 with the last para }
  1109. eq2:=compare_defs_ext(def2,currpara.paratype.def,
  1110. nothingn,false,false,convtyp,hpd);
  1111. if (eq2<>te_incompatible) then
  1112. begin
  1113. { check level }
  1114. eqlev:=byte(eq1)+byte(eq2);
  1115. if eqlev=(byte(te_exact)+byte(te_exact)) then
  1116. begin
  1117. search_procdef_binary_operator:=pd^.def;
  1118. exit;
  1119. end;
  1120. if eqlev>bestlev then
  1121. begin
  1122. bestpd:=pd^.def;
  1123. bestlev:=eqlev;
  1124. end;
  1125. end;
  1126. end;
  1127. end;
  1128. end;
  1129. end;
  1130. pd:=pd^.next;
  1131. end;
  1132. search_procdef_binary_operator:=bestpd;
  1133. end;
  1134. function tprocsym.write_references(ppufile:tcompilerppufile;locals:boolean) : boolean;
  1135. var
  1136. p : pprocdeflist;
  1137. begin
  1138. write_references:=false;
  1139. if not inherited write_references(ppufile,locals) then
  1140. exit;
  1141. write_references:=true;
  1142. p:=pdlistfirst;
  1143. while assigned(p) do
  1144. begin
  1145. if p^.own then
  1146. p^.def.write_references(ppufile,locals);
  1147. p:=p^.next;
  1148. end;
  1149. end;
  1150. procedure tprocsym.unchain_overload;
  1151. var
  1152. p,hp : pprocdeflist;
  1153. begin
  1154. { remove all overloaded procdefs from the
  1155. procdeflist that are not in the current symtable }
  1156. overloadchecked:=false;
  1157. p:=pdlistfirst;
  1158. { reset new lists }
  1159. pdlistfirst:=nil;
  1160. pdlistlast:=nil;
  1161. while assigned(p) do
  1162. begin
  1163. hp:=p^.next;
  1164. if p^.own then
  1165. begin
  1166. { keep, add to list }
  1167. if assigned(pdlistlast) then
  1168. begin
  1169. pdlistlast^.next:=p;
  1170. pdlistlast:=p;
  1171. end
  1172. else
  1173. begin
  1174. pdlistfirst:=p;
  1175. pdlistlast:=p;
  1176. end;
  1177. p^.next:=nil;
  1178. end
  1179. else
  1180. begin
  1181. { remove }
  1182. dispose(p);
  1183. dec(procdef_count);
  1184. end;
  1185. p:=hp;
  1186. end;
  1187. end;
  1188. {$ifdef GDB}
  1189. function tprocsym.stabstring : pchar;
  1190. begin
  1191. internalerror(200111171);
  1192. stabstring:=nil;
  1193. end;
  1194. procedure tprocsym.concatstabto(asmlist : taasmoutput);
  1195. begin
  1196. internalerror(200111172);
  1197. end;
  1198. {$endif GDB}
  1199. {****************************************************************************
  1200. TERRORSYM
  1201. ****************************************************************************}
  1202. constructor terrorsym.create;
  1203. begin
  1204. inherited create('');
  1205. typ:=errorsym;
  1206. end;
  1207. {****************************************************************************
  1208. TPROPERTYSYM
  1209. ****************************************************************************}
  1210. constructor tpropertysym.create(const n : string);
  1211. begin
  1212. inherited create(n);
  1213. typ:=propertysym;
  1214. propoptions:=[];
  1215. index:=0;
  1216. default:=0;
  1217. proptype.reset;
  1218. indextype.reset;
  1219. readaccess:=tsymlist.create;
  1220. writeaccess:=tsymlist.create;
  1221. storedaccess:=tsymlist.create;
  1222. end;
  1223. constructor tpropertysym.ppuload(ppufile:tcompilerppufile);
  1224. begin
  1225. inherited loadsym(ppufile);
  1226. typ:=propertysym;
  1227. ppufile.getsmallset(propoptions);
  1228. if (ppo_is_override in propoptions) then
  1229. begin
  1230. ppufile.getderef(propoverridenderef);
  1231. { we need to have these objects initialized }
  1232. readaccess:=tsymlist.create;
  1233. writeaccess:=tsymlist.create;
  1234. storedaccess:=tsymlist.create;
  1235. end
  1236. else
  1237. begin
  1238. ppufile.gettype(proptype);
  1239. index:=ppufile.getlongint;
  1240. default:=ppufile.getlongint;
  1241. ppufile.gettype(indextype);
  1242. readaccess:=ppufile.getsymlist;
  1243. writeaccess:=ppufile.getsymlist;
  1244. storedaccess:=ppufile.getsymlist;
  1245. end;
  1246. end;
  1247. destructor tpropertysym.destroy;
  1248. begin
  1249. readaccess.free;
  1250. writeaccess.free;
  1251. storedaccess.free;
  1252. inherited destroy;
  1253. end;
  1254. function tpropertysym.gettypedef:tdef;
  1255. begin
  1256. gettypedef:=proptype.def;
  1257. end;
  1258. procedure tpropertysym.buildderef;
  1259. begin
  1260. if (ppo_is_override in propoptions) then
  1261. begin
  1262. propoverridenderef.build(propoverriden);
  1263. end
  1264. else
  1265. begin
  1266. proptype.buildderef;
  1267. indextype.buildderef;
  1268. readaccess.buildderef;
  1269. writeaccess.buildderef;
  1270. storedaccess.buildderef;
  1271. end;
  1272. end;
  1273. procedure tpropertysym.deref;
  1274. begin
  1275. if (ppo_is_override in propoptions) then
  1276. begin
  1277. propoverriden:=tpropertysym(propoverridenderef.resolve);
  1278. dooverride(propoverriden);
  1279. end
  1280. else
  1281. begin
  1282. proptype.resolve;
  1283. indextype.resolve;
  1284. readaccess.resolve;
  1285. writeaccess.resolve;
  1286. storedaccess.resolve;
  1287. end;
  1288. end;
  1289. function tpropertysym.getsize : longint;
  1290. begin
  1291. getsize:=0;
  1292. end;
  1293. procedure tpropertysym.ppuwrite(ppufile:tcompilerppufile);
  1294. begin
  1295. inherited writesym(ppufile);
  1296. ppufile.putsmallset(propoptions);
  1297. if (ppo_is_override in propoptions) then
  1298. ppufile.putderef(propoverridenderef)
  1299. else
  1300. begin
  1301. ppufile.puttype(proptype);
  1302. ppufile.putlongint(index);
  1303. ppufile.putlongint(default);
  1304. ppufile.puttype(indextype);
  1305. ppufile.putsymlist(readaccess);
  1306. ppufile.putsymlist(writeaccess);
  1307. ppufile.putsymlist(storedaccess);
  1308. end;
  1309. ppufile.writeentry(ibpropertysym);
  1310. end;
  1311. procedure tpropertysym.dooverride(overriden:tpropertysym);
  1312. begin
  1313. propoverriden:=overriden;
  1314. proptype:=overriden.proptype;
  1315. propoptions:=overriden.propoptions+[ppo_is_override];
  1316. index:=overriden.index;
  1317. default:=overriden.default;
  1318. indextype:=overriden.indextype;
  1319. readaccess.free;
  1320. readaccess:=overriden.readaccess.getcopy;
  1321. writeaccess.free;
  1322. writeaccess:=overriden.writeaccess.getcopy;
  1323. storedaccess.free;
  1324. storedaccess:=overriden.storedaccess.getcopy;
  1325. end;
  1326. {$ifdef GDB}
  1327. function tpropertysym.stabstring : pchar;
  1328. begin
  1329. { !!!! don't know how to handle }
  1330. stabstring:=nil;
  1331. end;
  1332. procedure tpropertysym.concatstabto(asmlist : taasmoutput);
  1333. begin
  1334. { !!!! don't know how to handle }
  1335. end;
  1336. {$endif GDB}
  1337. {****************************************************************************
  1338. TABSOLUTESYM
  1339. ****************************************************************************}
  1340. constructor tabsolutesym.create(const n : string;const tt : ttype);
  1341. begin
  1342. inherited create(n,vs_value,tt);
  1343. typ:=absolutesym;
  1344. ref:=nil;
  1345. end;
  1346. constructor tabsolutesym.create_ref(const n : string;const tt : ttype;_ref:tsymlist);
  1347. begin
  1348. inherited create(n,vs_value,tt);
  1349. typ:=absolutesym;
  1350. ref:=_ref;
  1351. end;
  1352. destructor tabsolutesym.destroy;
  1353. begin
  1354. if assigned(ref) then
  1355. ref.free;
  1356. inherited destroy;
  1357. end;
  1358. constructor tabsolutesym.ppuload(ppufile:tcompilerppufile);
  1359. begin
  1360. { Note: This needs to load everything of tvarsym.write }
  1361. inherited ppuload(ppufile);
  1362. { load absolute }
  1363. typ:=absolutesym;
  1364. ref:=nil;
  1365. fieldoffset:=0;
  1366. asmname:=nil;
  1367. abstyp:=absolutetyp(ppufile.getbyte);
  1368. absseg:=false;
  1369. case abstyp of
  1370. tovar :
  1371. ref:=ppufile.getsymlist;
  1372. toasm :
  1373. asmname:=stringdup(ppufile.getstring);
  1374. toaddr :
  1375. begin
  1376. fieldoffset:=ppufile.getlongint;
  1377. absseg:=boolean(ppufile.getbyte);
  1378. end;
  1379. end;
  1380. end;
  1381. procedure tabsolutesym.ppuwrite(ppufile:tcompilerppufile);
  1382. var
  1383. hvo : tvaroptions;
  1384. begin
  1385. { Note: This needs to write everything of tvarsym.write }
  1386. inherited writesym(ppufile);
  1387. ppufile.putbyte(byte(varspez));
  1388. ppufile.putlongint(fieldoffset);
  1389. { write only definition or definitionsym }
  1390. ppufile.puttype(vartype);
  1391. hvo:=varoptions-[vo_regable,vo_fpuregable];
  1392. ppufile.putsmallset(hvo);
  1393. ppufile.putbyte(byte(abstyp));
  1394. case abstyp of
  1395. tovar :
  1396. ppufile.putsymlist(ref);
  1397. toasm :
  1398. ppufile.putstring(asmname^);
  1399. toaddr :
  1400. begin
  1401. ppufile.putlongint(fieldoffset);
  1402. ppufile.putbyte(byte(absseg));
  1403. end;
  1404. end;
  1405. ppufile.writeentry(ibabsolutesym);
  1406. end;
  1407. procedure tabsolutesym.buildderef;
  1408. begin
  1409. { inheritance of varsym.deref ! }
  1410. vartype.buildderef;
  1411. if (abstyp=tovar) then
  1412. ref.buildderef;
  1413. end;
  1414. procedure tabsolutesym.deref;
  1415. begin
  1416. { inheritance of varsym.deref ! }
  1417. vartype.resolve;
  1418. { own absolute deref }
  1419. if (abstyp=tovar) then
  1420. ref.resolve;
  1421. end;
  1422. function tabsolutesym.mangledname : string;
  1423. begin
  1424. case abstyp of
  1425. toasm :
  1426. mangledname:=asmname^;
  1427. toaddr :
  1428. mangledname:='$'+tostr(fieldoffset);
  1429. else
  1430. internalerror(10002);
  1431. end;
  1432. end;
  1433. {$ifdef GDB}
  1434. procedure tabsolutesym.concatstabto(asmlist : taasmoutput);
  1435. begin
  1436. { I don't know how to handle this !! }
  1437. end;
  1438. {$endif GDB}
  1439. {****************************************************************************
  1440. TVARSYM
  1441. ****************************************************************************}
  1442. constructor tvarsym.create(const n : string;vsp:tvarspez;const tt : ttype);
  1443. begin
  1444. inherited create(n);
  1445. typ:=varsym;
  1446. vartype:=tt;
  1447. _mangledname:=nil;
  1448. varspez:=vsp;
  1449. fieldoffset:=0;
  1450. fillchar(localloc,sizeof(localloc),0);
  1451. highvarsym:=nil;
  1452. defaultconstsym:=nil;
  1453. refs:=0;
  1454. varstate:=vs_declared;
  1455. varoptions:=[];
  1456. end;
  1457. constructor tvarsym.create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  1458. begin
  1459. tvarsym(self).create(n,vsp,tt);
  1460. include(varoptions,vo_is_dll_var);
  1461. end;
  1462. constructor tvarsym.create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  1463. begin
  1464. tvarsym(self).create(n,vsp,tt);
  1465. stringdispose(_mangledname);
  1466. _mangledname:=stringdup(mangled);
  1467. end;
  1468. constructor tvarsym.ppuload(ppufile:tcompilerppufile);
  1469. begin
  1470. inherited loadsym(ppufile);
  1471. typ:=varsym;
  1472. fillchar(localloc,sizeof(localloc),0);
  1473. refs := 0;
  1474. varstate:=vs_used;
  1475. varspez:=tvarspez(ppufile.getbyte);
  1476. fieldoffset:=ppufile.getlongint;
  1477. highvarsym:=nil;
  1478. defaultconstsym:=nil;
  1479. ppufile.gettype(_vartype);
  1480. ppufile.getsmallset(varoptions);
  1481. if (vo_is_C_var in varoptions) then
  1482. _mangledname:=stringdup(ppufile.getstring);
  1483. end;
  1484. destructor tvarsym.destroy;
  1485. begin
  1486. if assigned(notifications) then
  1487. notifications.destroy;
  1488. inherited destroy;
  1489. end;
  1490. procedure tvarsym.buildderef;
  1491. begin
  1492. vartype.buildderef;
  1493. end;
  1494. procedure tvarsym.deref;
  1495. begin
  1496. vartype.resolve;
  1497. end;
  1498. procedure tvarsym.ppuwrite(ppufile:tcompilerppufile);
  1499. var
  1500. hvo : tvaroptions;
  1501. begin
  1502. inherited writesym(ppufile);
  1503. ppufile.putbyte(byte(varspez));
  1504. ppufile.putlongint(fieldoffset);
  1505. ppufile.puttype(vartype);
  1506. { symbols which are load are never candidates for a register,
  1507. turn off the regable }
  1508. hvo:=varoptions-[vo_regable,vo_fpuregable];
  1509. ppufile.putsmallset(hvo);
  1510. if (vo_is_C_var in varoptions) then
  1511. ppufile.putstring(mangledname);
  1512. ppufile.writeentry(ibvarsym);
  1513. end;
  1514. procedure tvarsym.generate_mangledname;
  1515. begin
  1516. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1517. end;
  1518. procedure tvarsym.set_mangledname(const s:string);
  1519. begin
  1520. stringdispose(_mangledname);
  1521. _mangledname:=stringdup(s);
  1522. end;
  1523. function tvarsym.getsize : longint;
  1524. begin
  1525. if assigned(vartype.def) then
  1526. getsize:=vartype.def.size
  1527. else
  1528. getsize:=0;
  1529. end;
  1530. function tvarsym.getvaluesize : longint;
  1531. begin
  1532. if assigned(vartype.def) and
  1533. (varspez=vs_value) and
  1534. ((vartype.def.deftype<>arraydef) or
  1535. tarraydef(vartype.def).isDynamicArray or
  1536. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1537. getvaluesize:=vartype.def.size
  1538. else
  1539. getvaluesize:=0;
  1540. end;
  1541. procedure Tvarsym.trigger_notifications(what:Tnotification_flag);
  1542. var n:Tnotification;
  1543. begin
  1544. if assigned(notifications) then
  1545. begin
  1546. n:=Tnotification(notifications.first);
  1547. while assigned(n) do
  1548. begin
  1549. if what in n.flags then
  1550. n.callback(what,self);
  1551. n:=Tnotification(n.next);
  1552. end;
  1553. end;
  1554. end;
  1555. function Tvarsym.register_notification(flags:Tnotification_flags;callback:
  1556. Tnotification_callback):cardinal;
  1557. var n:Tnotification;
  1558. begin
  1559. if not assigned(notifications) then
  1560. notifications:=Tlinkedlist.create;
  1561. n:=Tnotification.create(flags,callback);
  1562. register_notification:=n.id;
  1563. notifications.concat(n);
  1564. end;
  1565. procedure Tvarsym.unregister_notification(id:cardinal);
  1566. var n:Tnotification;
  1567. begin
  1568. if not assigned(notifications) then
  1569. internalerror(200212311)
  1570. else
  1571. begin
  1572. n:=Tnotification(notifications.first);
  1573. while assigned(n) do
  1574. begin
  1575. if n.id=id then
  1576. begin
  1577. notifications.remove(n);
  1578. n.destroy;
  1579. exit;
  1580. end;
  1581. n:=Tnotification(n.next);
  1582. end;
  1583. internalerror(200212311)
  1584. end;
  1585. end;
  1586. {$ifdef GDB}
  1587. function tvarsym.stabstring : pchar;
  1588. var
  1589. st : string;
  1590. threadvaroffset : string;
  1591. regidx : tregisterindex;
  1592. begin
  1593. stabstring:=nil;
  1594. st:=tstoreddef(vartype.def).numberstring;
  1595. if (vo_is_thread_var in varoptions) then
  1596. threadvaroffset:='+'+tostr(pointer_size)
  1597. else
  1598. threadvaroffset:='';
  1599. case owner.symtabletype of
  1600. objectsymtable :
  1601. begin
  1602. if (sp_static in symoptions) then
  1603. begin
  1604. if (cs_gdb_gsym in aktglobalswitches) then
  1605. st := 'G'+st
  1606. else
  1607. st := 'S'+st;
  1608. stabstring := strpnew('"'+owner.name^+'__'+name+':'+st+
  1609. '",'+
  1610. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)
  1611. +','+mangledname+threadvaroffset);
  1612. end;
  1613. end;
  1614. globalsymtable :
  1615. begin
  1616. { Here we used S instead of
  1617. because with G GDB doesn't look at the address field
  1618. but searches the same name or with a leading underscore
  1619. but these names don't exist in pascal !}
  1620. if (cs_gdb_gsym in aktglobalswitches) then
  1621. st := 'G'+st
  1622. else
  1623. st := 'S'+st;
  1624. stabstring := strpnew('"'+name+':'+st+'",'+
  1625. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+
  1626. ','+mangledname+threadvaroffset);
  1627. end;
  1628. staticsymtable :
  1629. begin
  1630. stabstring := strpnew('"'+name+':S'+st+'",'+
  1631. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+
  1632. ','+mangledname+threadvaroffset);
  1633. end;
  1634. parasymtable,
  1635. localsymtable :
  1636. begin
  1637. { There is no space allocated for not referenced locals }
  1638. if (owner.symtabletype=localsymtable) and
  1639. (refs=0) then
  1640. begin
  1641. exit;
  1642. end;
  1643. if (vo_is_C_var in varoptions) then
  1644. begin
  1645. stabstring := strpnew('"'+name+':S'+st+'",'+
  1646. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1647. exit;
  1648. end;
  1649. if (owner.symtabletype=parasymtable) and
  1650. paramanager.push_addr_param(varspez,vartype.def,tprocdef(owner.defowner).proccalloption) and
  1651. not(vo_has_local_copy in varoptions) then
  1652. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1653. else
  1654. st := 'p'+st;
  1655. case localloc.loc of
  1656. LOC_REGISTER, LOC_FPUREGISTER :
  1657. begin
  1658. regidx:=findreg_by_number(localloc.register);
  1659. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1660. { this is the register order for GDB}
  1661. stabstring:=strpnew('"'+name+':r'+st+'",'+
  1662. tostr(N_RSYM)+',0,'+
  1663. tostr(fileinfo.line)+','+tostr(regstabs_table[regidx]));
  1664. end;
  1665. LOC_REFERENCE :
  1666. begin
  1667. { offset to ebp => will not work if the framepointer is esp
  1668. so some optimizing will make things harder to debug }
  1669. stabstring := strpnew('"'+name+':'+st+'",'+
  1670. tostr(N_tsym)+',0,'+tostr(fileinfo.line)+','+
  1671. tostr(localloc.reference.offset));
  1672. end;
  1673. else
  1674. internalerror(2003091814);
  1675. end;
  1676. end;
  1677. else
  1678. stabstring := inherited stabstring;
  1679. end;
  1680. end;
  1681. procedure tvarsym.concatstabto(asmlist : taasmoutput);
  1682. var
  1683. regidx : tregisterindex;
  1684. stab_str : pchar;
  1685. c : char;
  1686. begin
  1687. if (owner.symtabletype=parasymtable) and
  1688. (copy(name,1,6)='hidden') then
  1689. exit;
  1690. if (vo_is_self in varoptions) then
  1691. begin
  1692. if localloc.loc<>LOC_REFERENCE then
  1693. internalerror(2003091815);
  1694. if (po_classmethod in current_procinfo.procdef.procoptions) or
  1695. (po_staticmethod in current_procinfo.procdef.procoptions) then
  1696. begin
  1697. asmlist.concat(Tai_stabs.Create(strpnew(
  1698. '"pvmt:p'+tstoreddef(pvmttype.def).numberstring+'",'+
  1699. tostr(N_tsym)+',0,0,'+tostr(localloc.reference.offset))));
  1700. end
  1701. else
  1702. begin
  1703. if not(is_class(current_procinfo.procdef._class)) then
  1704. c:='v'
  1705. else
  1706. c:='p';
  1707. asmlist.concat(Tai_stabs.Create(strpnew(
  1708. '"$t:'+c+current_procinfo.procdef._class.numberstring+'",'+
  1709. tostr(N_tsym)+',0,0,'+tostr(localloc.reference.offset))));
  1710. end;
  1711. end
  1712. else
  1713. if (localloc.loc=LOC_REGISTER) then
  1714. begin
  1715. regidx:=findreg_by_number(localloc.register);
  1716. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1717. { this is the register order for GDB}
  1718. stab_str:=strpnew('"'+name+':r'
  1719. +tstoreddef(vartype.def).numberstring+'",'+
  1720. tostr(N_RSYM)+',0,'+
  1721. tostr(fileinfo.line)+','+tostr(regstabs_table[regidx]));
  1722. asmList.concat(Tai_stabs.Create(stab_str));
  1723. end
  1724. else
  1725. inherited concatstabto(asmlist);
  1726. end;
  1727. {$endif GDB}
  1728. procedure tvarsym.setvartype(const newtype: ttype);
  1729. begin
  1730. _vartype := newtype;
  1731. { can we load the value into a register ? }
  1732. if not assigned(owner) or
  1733. (owner.symtabletype in [localsymtable,parasymtable]) then
  1734. begin
  1735. if tstoreddef(vartype.def).is_intregable then
  1736. include(varoptions,vo_regable)
  1737. else
  1738. exclude(varoptions,vo_regable);
  1739. if tstoreddef(vartype.def).is_fpuregable then
  1740. include(varoptions,vo_fpuregable)
  1741. else
  1742. exclude(varoptions,vo_fpuregable);
  1743. end;
  1744. end;
  1745. {****************************************************************************
  1746. TTYPEDCONSTSYM
  1747. *****************************************************************************}
  1748. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1749. begin
  1750. inherited create(n);
  1751. typ:=typedconstsym;
  1752. typedconsttype.setdef(p);
  1753. is_writable:=writable;
  1754. end;
  1755. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1756. begin
  1757. inherited create(n);
  1758. typ:=typedconstsym;
  1759. typedconsttype:=tt;
  1760. is_writable:=writable;
  1761. end;
  1762. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1763. begin
  1764. inherited loadsym(ppufile);
  1765. typ:=typedconstsym;
  1766. ppufile.gettype(typedconsttype);
  1767. is_writable:=boolean(ppufile.getbyte);
  1768. end;
  1769. destructor ttypedconstsym.destroy;
  1770. begin
  1771. inherited destroy;
  1772. end;
  1773. procedure ttypedconstsym.generate_mangledname;
  1774. begin
  1775. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1776. end;
  1777. function ttypedconstsym.getsize : longint;
  1778. begin
  1779. if assigned(typedconsttype.def) then
  1780. getsize:=typedconsttype.def.size
  1781. else
  1782. getsize:=0;
  1783. end;
  1784. procedure ttypedconstsym.buildderef;
  1785. begin
  1786. typedconsttype.buildderef;
  1787. end;
  1788. procedure ttypedconstsym.deref;
  1789. begin
  1790. typedconsttype.resolve;
  1791. end;
  1792. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1793. begin
  1794. inherited writesym(ppufile);
  1795. ppufile.puttype(typedconsttype);
  1796. ppufile.putbyte(byte(is_writable));
  1797. ppufile.writeentry(ibtypedconstsym);
  1798. end;
  1799. {$ifdef GDB}
  1800. function ttypedconstsym.stabstring : pchar;
  1801. var
  1802. st : char;
  1803. begin
  1804. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1805. st := 'G'
  1806. else
  1807. st := 'S';
  1808. stabstring := strpnew('"'+name+':'+st+
  1809. tstoreddef(typedconsttype.def).numberstring+'",'+tostr(n_STSYM)+',0,'+
  1810. tostr(fileinfo.line)+','+mangledname);
  1811. end;
  1812. {$endif GDB}
  1813. {****************************************************************************
  1814. TCONSTSYM
  1815. ****************************************************************************}
  1816. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : TConstExprInt);
  1817. begin
  1818. inherited create(n);
  1819. fillchar(value, sizeof(value), #0);
  1820. typ:=constsym;
  1821. consttyp:=t;
  1822. value.valueord:=v;
  1823. ResStrIndex:=0;
  1824. consttype.reset;
  1825. end;
  1826. constructor tconstsym.create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1827. begin
  1828. inherited create(n);
  1829. fillchar(value, sizeof(value), #0);
  1830. typ:=constsym;
  1831. consttyp:=t;
  1832. value.valueord:=v;
  1833. ResStrIndex:=0;
  1834. consttype:=tt;
  1835. end;
  1836. constructor tconstsym.create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1837. begin
  1838. inherited create(n);
  1839. fillchar(value, sizeof(value), #0);
  1840. typ:=constsym;
  1841. consttyp:=t;
  1842. value.valueordptr:=v;
  1843. ResStrIndex:=0;
  1844. consttype:=tt;
  1845. end;
  1846. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer);
  1847. begin
  1848. inherited create(n);
  1849. fillchar(value, sizeof(value), #0);
  1850. typ:=constsym;
  1851. consttyp:=t;
  1852. value.valueptr:=v;
  1853. ResStrIndex:=0;
  1854. consttype.reset;
  1855. end;
  1856. constructor tconstsym.create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1857. begin
  1858. inherited create(n);
  1859. fillchar(value, sizeof(value), #0);
  1860. typ:=constsym;
  1861. consttyp:=t;
  1862. value.valueptr:=v;
  1863. ResStrIndex:=0;
  1864. consttype:=tt;
  1865. end;
  1866. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1867. begin
  1868. inherited create(n);
  1869. fillchar(value, sizeof(value), #0);
  1870. typ:=constsym;
  1871. consttyp:=t;
  1872. value.valueptr:=str;
  1873. consttype.reset;
  1874. value.len:=l;
  1875. if t=constresourcestring then
  1876. ResStrIndex:=ResourceStrings.Register(name,pchar(value.valueptr),value.len);
  1877. end;
  1878. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1879. var
  1880. pd : pbestreal;
  1881. ps : pnormalset;
  1882. pc : pchar;
  1883. begin
  1884. inherited loadsym(ppufile);
  1885. typ:=constsym;
  1886. consttype.reset;
  1887. consttyp:=tconsttyp(ppufile.getbyte);
  1888. fillchar(value, sizeof(value), #0);
  1889. case consttyp of
  1890. constint:
  1891. value.valueord:=ppufile.getexprint;
  1892. constwchar,
  1893. constbool,
  1894. constchar :
  1895. value.valueord:=ppufile.getlongint;
  1896. constord :
  1897. begin
  1898. ppufile.gettype(consttype);
  1899. value.valueord:=ppufile.getexprint;
  1900. end;
  1901. constpointer :
  1902. begin
  1903. ppufile.gettype(consttype);
  1904. value.valueordptr:=ppufile.getptruint;
  1905. end;
  1906. conststring,
  1907. constresourcestring :
  1908. begin
  1909. value.len:=ppufile.getlongint;
  1910. getmem(pc,value.len+1);
  1911. ppufile.getdata(pc^,value.len);
  1912. if consttyp=constresourcestring then
  1913. ResStrIndex:=ppufile.getlongint;
  1914. value.valueptr:=pc;
  1915. end;
  1916. constreal :
  1917. begin
  1918. new(pd);
  1919. pd^:=ppufile.getreal;
  1920. value.valueptr:=pd;
  1921. end;
  1922. constset :
  1923. begin
  1924. ppufile.gettype(consttype);
  1925. new(ps);
  1926. ppufile.getnormalset(ps^);
  1927. value.valueptr:=ps;
  1928. end;
  1929. constguid :
  1930. begin
  1931. new(pguid(value.valueptr));
  1932. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1933. end;
  1934. constnil : ;
  1935. else
  1936. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1937. end;
  1938. end;
  1939. destructor tconstsym.destroy;
  1940. begin
  1941. case consttyp of
  1942. conststring,
  1943. constresourcestring :
  1944. freemem(pchar(value.valueptr),value.len+1);
  1945. constreal :
  1946. dispose(pbestreal(value.valueptr));
  1947. constset :
  1948. dispose(pnormalset(value.valueptr));
  1949. constguid :
  1950. dispose(pguid(value.valueptr));
  1951. end;
  1952. inherited destroy;
  1953. end;
  1954. function tconstsym.mangledname : string;
  1955. begin
  1956. mangledname:=name;
  1957. end;
  1958. procedure tconstsym.buildderef;
  1959. begin
  1960. if consttyp in [constord,constpointer,constset] then
  1961. consttype.buildderef;
  1962. end;
  1963. procedure tconstsym.deref;
  1964. begin
  1965. if consttyp in [constord,constpointer,constset] then
  1966. consttype.resolve;
  1967. end;
  1968. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1969. begin
  1970. inherited writesym(ppufile);
  1971. ppufile.putbyte(byte(consttyp));
  1972. case consttyp of
  1973. constnil : ;
  1974. constint:
  1975. ppufile.putexprint(value.valueord);
  1976. constbool,
  1977. constchar,
  1978. constwchar :
  1979. ppufile.putlongint(value.valueord);
  1980. constord :
  1981. begin
  1982. ppufile.puttype(consttype);
  1983. ppufile.putexprint(value.valueord);
  1984. end;
  1985. constpointer :
  1986. begin
  1987. ppufile.puttype(consttype);
  1988. ppufile.putptruint(value.valueordptr);
  1989. end;
  1990. conststring,
  1991. constresourcestring :
  1992. begin
  1993. ppufile.putlongint(value.len);
  1994. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1995. if consttyp=constresourcestring then
  1996. ppufile.putlongint(ResStrIndex);
  1997. end;
  1998. constreal :
  1999. ppufile.putreal(pbestreal(value.valueptr)^);
  2000. constset :
  2001. begin
  2002. ppufile.puttype(consttype);
  2003. ppufile.putnormalset(value.valueptr^);
  2004. end;
  2005. constguid :
  2006. ppufile.putdata(value.valueptr^,sizeof(tguid));
  2007. else
  2008. internalerror(13);
  2009. end;
  2010. ppufile.writeentry(ibconstsym);
  2011. end;
  2012. {$ifdef GDB}
  2013. function tconstsym.stabstring : pchar;
  2014. var st : string;
  2015. begin
  2016. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  2017. case consttyp of
  2018. conststring : begin
  2019. st := 's'''+strpas(pchar(value.valueptr))+'''';
  2020. end;
  2021. constbool,
  2022. constint,
  2023. constord,
  2024. constwchar,
  2025. constchar : st := 'i'+int64tostr(value.valueord);
  2026. constpointer :
  2027. st := 'i'+int64tostr(value.valueordptr);
  2028. constreal : begin
  2029. system.str(pbestreal(value.valueptr)^,st);
  2030. st := 'r'+st;
  2031. end;
  2032. { if we don't know just put zero !! }
  2033. else st:='i0';
  2034. {***SETCONST}
  2035. {constset:;} {*** I don't know what to do with a set.}
  2036. { sets are not recognized by GDB}
  2037. {***}
  2038. end;
  2039. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  2040. tostr(fileinfo.line)+',0');
  2041. end;
  2042. procedure tconstsym.concatstabto(asmlist : taasmoutput);
  2043. begin
  2044. if consttyp <> conststring then
  2045. inherited concatstabto(asmlist);
  2046. end;
  2047. {$endif GDB}
  2048. {****************************************************************************
  2049. TENUMSYM
  2050. ****************************************************************************}
  2051. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2052. begin
  2053. inherited create(n);
  2054. typ:=enumsym;
  2055. definition:=def;
  2056. value:=v;
  2057. { check for jumps }
  2058. if v>def.max+1 then
  2059. def.has_jumps:=true;
  2060. { update low and high }
  2061. if def.min>v then
  2062. def.setmin(v);
  2063. if def.max<v then
  2064. def.setmax(v);
  2065. order;
  2066. end;
  2067. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2068. begin
  2069. inherited loadsym(ppufile);
  2070. typ:=enumsym;
  2071. ppufile.getderef(definitionderef);
  2072. value:=ppufile.getlongint;
  2073. nextenum := Nil;
  2074. end;
  2075. procedure tenumsym.buildderef;
  2076. begin
  2077. definitionderef.build(definition);
  2078. end;
  2079. procedure tenumsym.deref;
  2080. begin
  2081. definition:=tenumdef(definitionderef.resolve);
  2082. order;
  2083. end;
  2084. procedure tenumsym.order;
  2085. var
  2086. sym : tenumsym;
  2087. begin
  2088. sym := tenumsym(definition.firstenum);
  2089. if sym = nil then
  2090. begin
  2091. definition.firstenum := self;
  2092. nextenum := nil;
  2093. exit;
  2094. end;
  2095. { reorder the symbols in increasing value }
  2096. if value < sym.value then
  2097. begin
  2098. nextenum := sym;
  2099. definition.firstenum := self;
  2100. end
  2101. else
  2102. begin
  2103. while (sym.value <= value) and assigned(sym.nextenum) do
  2104. sym := sym.nextenum;
  2105. nextenum := sym.nextenum;
  2106. sym.nextenum := self;
  2107. end;
  2108. end;
  2109. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2110. begin
  2111. inherited writesym(ppufile);
  2112. ppufile.putderef(definitionderef);
  2113. ppufile.putlongint(value);
  2114. ppufile.writeentry(ibenumsym);
  2115. end;
  2116. {$ifdef GDB}
  2117. procedure tenumsym.concatstabto(asmlist : taasmoutput);
  2118. begin
  2119. {enum elements have no stab !}
  2120. end;
  2121. {$EndIf GDB}
  2122. {****************************************************************************
  2123. TTYPESYM
  2124. ****************************************************************************}
  2125. constructor ttypesym.create(const n : string;const tt : ttype);
  2126. begin
  2127. inherited create(n);
  2128. typ:=typesym;
  2129. restype:=tt;
  2130. {$ifdef GDB}
  2131. isusedinstab := false;
  2132. {$endif GDB}
  2133. { register the typesym for the definition }
  2134. if assigned(restype.def) and
  2135. (restype.def.deftype<>errordef) and
  2136. not(assigned(restype.def.typesym)) then
  2137. restype.def.typesym:=self;
  2138. end;
  2139. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2140. begin
  2141. inherited loadsym(ppufile);
  2142. typ:=typesym;
  2143. {$ifdef GDB}
  2144. isusedinstab := false;
  2145. {$endif GDB}
  2146. ppufile.gettype(restype);
  2147. end;
  2148. function ttypesym.gettypedef:tdef;
  2149. begin
  2150. gettypedef:=restype.def;
  2151. end;
  2152. procedure ttypesym.buildderef;
  2153. begin
  2154. restype.buildderef;
  2155. end;
  2156. procedure ttypesym.deref;
  2157. begin
  2158. restype.resolve;
  2159. end;
  2160. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2161. begin
  2162. inherited writesym(ppufile);
  2163. ppufile.puttype(restype);
  2164. ppufile.writeentry(ibtypesym);
  2165. end;
  2166. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  2167. begin
  2168. inherited load_references(ppufile,locals);
  2169. if (restype.def.deftype=recorddef) then
  2170. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  2171. if (restype.def.deftype=objectdef) then
  2172. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  2173. end;
  2174. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  2175. var
  2176. d : tderef;
  2177. begin
  2178. d.reset;
  2179. if not inherited write_references(ppufile,locals) then
  2180. begin
  2181. { write address of this symbol if record or object
  2182. even if no real refs are there
  2183. because we need it for the symtable }
  2184. if (restype.def.deftype in [recorddef,objectdef]) then
  2185. begin
  2186. d.build(self);
  2187. ppufile.putderef(d);
  2188. ppufile.writeentry(ibsymref);
  2189. end;
  2190. end;
  2191. write_references:=true;
  2192. if (restype.def.deftype=recorddef) then
  2193. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  2194. if (restype.def.deftype=objectdef) then
  2195. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  2196. end;
  2197. {$ifdef GDB}
  2198. function ttypesym.stabstring : pchar;
  2199. var
  2200. stabchar : string[2];
  2201. short : string;
  2202. begin
  2203. if restype.def.deftype in tagtypes then
  2204. stabchar := 'Tt'
  2205. else
  2206. stabchar := 't';
  2207. short := '"'+name+':'+stabchar+tstoreddef(restype.def).numberstring
  2208. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  2209. stabstring := strpnew(short);
  2210. end;
  2211. procedure ttypesym.concatstabto(asmlist : taasmoutput);
  2212. begin
  2213. {not stabs for forward defs }
  2214. if assigned(restype.def) then
  2215. if (restype.def.typesym = self) then
  2216. tstoreddef(restype.def).concatstabto(asmlist)
  2217. else
  2218. inherited concatstabto(asmlist);
  2219. end;
  2220. {$endif GDB}
  2221. {****************************************************************************
  2222. TSYSSYM
  2223. ****************************************************************************}
  2224. constructor tsyssym.create(const n : string;l : longint);
  2225. begin
  2226. inherited create(n);
  2227. typ:=syssym;
  2228. number:=l;
  2229. end;
  2230. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2231. begin
  2232. inherited loadsym(ppufile);
  2233. typ:=syssym;
  2234. number:=ppufile.getlongint;
  2235. end;
  2236. destructor tsyssym.destroy;
  2237. begin
  2238. inherited destroy;
  2239. end;
  2240. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2241. begin
  2242. inherited writesym(ppufile);
  2243. ppufile.putlongint(number);
  2244. ppufile.writeentry(ibsyssym);
  2245. end;
  2246. {$ifdef GDB}
  2247. procedure tsyssym.concatstabto(asmlist : taasmoutput);
  2248. begin
  2249. end;
  2250. {$endif GDB}
  2251. {****************************************************************************
  2252. TRTTISYM
  2253. ****************************************************************************}
  2254. constructor trttisym.create(const n:string;rt:trttitype);
  2255. const
  2256. prefix : array[trttitype] of string[5]=('$rtti','$init');
  2257. begin
  2258. inherited create(prefix[rt]+n);
  2259. typ:=rttisym;
  2260. lab:=nil;
  2261. rttityp:=rt;
  2262. end;
  2263. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  2264. begin
  2265. inherited loadsym(ppufile);
  2266. typ:=rttisym;
  2267. lab:=nil;
  2268. rttityp:=trttitype(ppufile.getbyte);
  2269. end;
  2270. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2271. begin
  2272. inherited writesym(ppufile);
  2273. ppufile.putbyte(byte(rttityp));
  2274. ppufile.writeentry(ibrttisym);
  2275. end;
  2276. function trttisym.mangledname : string;
  2277. const
  2278. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2279. begin
  2280. result:=make_mangledname(prefix[rttityp],owner,Copy(name,5,255));
  2281. end;
  2282. function trttisym.get_label:tasmsymbol;
  2283. begin
  2284. { the label is always a global label }
  2285. if not assigned(lab) then
  2286. lab:=objectlibrary.newasmsymboldata(mangledname);
  2287. get_label:=lab;
  2288. end;
  2289. { persistent rtti generation }
  2290. procedure generate_rtti(p:tsym);
  2291. var
  2292. rsym : trttisym;
  2293. def : tstoreddef;
  2294. begin
  2295. { rtti can only be generated for classes that are always typesyms }
  2296. if not(p.typ=typesym) then
  2297. internalerror(200108261);
  2298. def:=tstoreddef(ttypesym(p).restype.def);
  2299. { only create rtti once for each definition }
  2300. if not(df_has_rttitable in def.defoptions) then
  2301. begin
  2302. { definition should be in the same symtable as the symbol }
  2303. if p.owner<>def.owner then
  2304. internalerror(200108262);
  2305. { create rttisym }
  2306. rsym:=trttisym.create(p.name,fullrtti);
  2307. p.owner.insert(rsym);
  2308. { register rttisym in definition }
  2309. include(def.defoptions,df_has_rttitable);
  2310. def.rttitablesym:=rsym;
  2311. { write rtti data }
  2312. def.write_child_rtti_data(fullrtti);
  2313. if (cs_create_smart in aktmoduleswitches) then
  2314. rttiList.concat(Tai_cut.Create);
  2315. rttilist.concat(tai_align.create(const_align(pointer_size)));
  2316. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  2317. def.write_rtti_data(fullrtti);
  2318. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2319. end;
  2320. end;
  2321. { persistent init table generation }
  2322. procedure generate_inittable(p:tsym);
  2323. var
  2324. rsym : trttisym;
  2325. def : tstoreddef;
  2326. begin
  2327. { anonymous types are also allowed for records that can be varsym }
  2328. case p.typ of
  2329. typesym :
  2330. def:=tstoreddef(ttypesym(p).restype.def);
  2331. varsym :
  2332. def:=tstoreddef(tvarsym(p).vartype.def);
  2333. else
  2334. internalerror(200108263);
  2335. end;
  2336. { only create inittable once for each definition }
  2337. if not(df_has_inittable in def.defoptions) then
  2338. begin
  2339. { definition should be in the same symtable as the symbol }
  2340. if p.owner<>def.owner then
  2341. internalerror(200108264);
  2342. { create rttisym }
  2343. rsym:=trttisym.create(p.name,initrtti);
  2344. p.owner.insert(rsym);
  2345. { register rttisym in definition }
  2346. include(def.defoptions,df_has_inittable);
  2347. def.inittablesym:=rsym;
  2348. { write inittable data }
  2349. def.write_child_rtti_data(initrtti);
  2350. if (cs_create_smart in aktmoduleswitches) then
  2351. rttiList.concat(Tai_cut.Create);
  2352. rttilist.concat(tai_align.create(const_align(pointer_size)));
  2353. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  2354. def.write_rtti_data(initrtti);
  2355. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2356. end;
  2357. end;
  2358. end.
  2359. {
  2360. $Log$
  2361. Revision 1.138 2003-12-12 12:09:40 marco
  2362. * always generate RTTI patch from peter
  2363. Revision 1.137 2003/12/01 18:44:15 peter
  2364. * fixed some crashes
  2365. * fixed varargs and register calling probs
  2366. Revision 1.136 2003/11/29 18:16:39 jonas
  2367. * don't internalerror when emitting debuginfo for LOC_FPUREGISTER
  2368. Revision 1.135 2003/11/23 17:05:16 peter
  2369. * register calling is left-right
  2370. * parameter ordering
  2371. * left-right calling inserts result parameter last
  2372. Revision 1.134 2003/10/30 16:23:13 peter
  2373. * don't search for overloads in parents for constructors
  2374. Revision 1.133 2003/10/29 21:56:28 peter
  2375. * procsym.deref derefs only own procdefs
  2376. * reset paracount in procdef.deref so a second deref doesn't increase
  2377. the paracounts to invalid values
  2378. Revision 1.132 2003/10/29 19:48:51 peter
  2379. * renamed mangeldname_prefix to make_mangledname and made it more
  2380. generic
  2381. * make_mangledname is now also used for internal threadvar/resstring
  2382. lists
  2383. * Add P$ in front of program modulename to prevent duplicated symbols
  2384. at assembler level, because the main program can have the same name
  2385. as a unit, see webtbs/tw1251b
  2386. Revision 1.131 2003/10/28 15:36:01 peter
  2387. * absolute to object field supported, fixes tb0458
  2388. Revision 1.130 2003/10/22 20:40:00 peter
  2389. * write derefdata in a separate ppu entry
  2390. Revision 1.129 2003/10/22 15:22:33 peter
  2391. * fixed unitsym-globalsymtable relation so the uses of a unit
  2392. is counted correctly
  2393. Revision 1.128 2003/10/21 18:14:30 peter
  2394. * fix writing of widechar to ppu
  2395. Revision 1.127 2003/10/17 14:38:32 peter
  2396. * 64k registers supported
  2397. * fixed some memory leaks
  2398. Revision 1.126 2003/10/13 14:05:12 peter
  2399. * removed is_visible_for_proc
  2400. * search also for class overloads when finding interface
  2401. implementations
  2402. Revision 1.125 2003/10/08 19:19:45 peter
  2403. * set_varstate cleanup
  2404. Revision 1.124 2003/10/07 21:14:33 peter
  2405. * compare_paras() has a parameter to ignore hidden parameters
  2406. * cross unit overload searching ignores hidden parameters when
  2407. comparing parameter lists. Now function(string):string is
  2408. not overriden with procedure(string) which has the same visible
  2409. parameter list
  2410. Revision 1.123 2003/10/07 15:17:07 peter
  2411. * inline supported again, LOC_REFERENCEs are used to pass the
  2412. parameters
  2413. * inlineparasymtable,inlinelocalsymtable removed
  2414. * exitlabel inserting fixed
  2415. Revision 1.122 2003/10/01 20:34:49 peter
  2416. * procinfo unit contains tprocinfo
  2417. * cginfo renamed to cgbase
  2418. * moved cgmessage to verbose
  2419. * fixed ppc and sparc compiles
  2420. Revision 1.121 2003/09/25 21:25:37 peter
  2421. * has_local_copy gdb fix
  2422. Revision 1.120 2003/09/25 16:18:54 peter
  2423. * fixed stabs for globals,static
  2424. Revision 1.119 2003/09/23 17:56:06 peter
  2425. * locals and paras are allocated in the code generation
  2426. * tvarsym.localloc contains the location of para/local when
  2427. generating code for the current procedure
  2428. Revision 1.118 2003/09/16 16:17:01 peter
  2429. * varspez in calls to push_addr_param
  2430. Revision 1.117 2003/09/14 13:20:12 peter
  2431. * fix previous commit, also include objectsymtable
  2432. Revision 1.116 2003/09/14 12:58:00 peter
  2433. * support mulitple overloads in implementation, this is delphi
  2434. compatible
  2435. * procsym only stores the overloads available in the interface
  2436. Revision 1.115 2003/09/03 15:55:01 peter
  2437. * NEWRA branch merged
  2438. Revision 1.114 2003/09/03 11:18:37 florian
  2439. * fixed arm concatcopy
  2440. + arm support in the common compiler sources added
  2441. * moved some generic cg code around
  2442. + tfputype added
  2443. * ...
  2444. Revision 1.113.2.2 2003/08/29 17:28:59 peter
  2445. * next batch of updates
  2446. Revision 1.113.2.1 2003/08/27 19:55:54 peter
  2447. * first tregister patch
  2448. Revision 1.113 2003/08/20 20:29:06 daniel
  2449. * Some more R_NO changes
  2450. * Preventive code to loadref added
  2451. Revision 1.112 2003/07/05 22:41:59 peter
  2452. * check if owner.defowner is valid when checking private/protected
  2453. Revision 1.111 2003/07/04 22:41:41 pierre
  2454. * single threadvar debugging support
  2455. Revision 1.110 2003/06/13 21:19:31 peter
  2456. * current_procdef removed, use current_procinfo.procdef instead
  2457. Revision 1.109 2003/06/07 20:26:32 peter
  2458. * re-resolving added instead of reloading from ppu
  2459. * tderef object added to store deref info for resolving
  2460. Revision 1.108 2003/06/05 17:53:30 peter
  2461. * fix to compile without gdb
  2462. Revision 1.107 2003/06/02 22:59:17 florian
  2463. * absolutesyms aren't fpuregable either
  2464. Revision 1.106 2003/05/30 18:48:17 jonas
  2465. * fixed intregister bug
  2466. * fixed error in my previous commit: vo_(fpu)regable should only be set
  2467. for (inline)localsymtable and (inline)parasymtable entries
  2468. Revision 1.105 2003/05/30 13:35:10 jonas
  2469. * the vartype field of tvarsym is now a property, because is_XXXregable
  2470. must be updated when the vartype is changed
  2471. Revision 1.104 2003/05/15 18:58:53 peter
  2472. * removed selfpointer_offset, vmtpointer_offset
  2473. * tvarsym.adjusted_address
  2474. * address in localsymtable is now in the real direction
  2475. * removed some obsolete globals
  2476. Revision 1.103 2003/05/12 18:13:57 peter
  2477. * create rtti label using newasmsymboldata and update binding
  2478. only when calling tai_symbol.create
  2479. * tai_symbol.create_global added
  2480. Revision 1.102 2003/05/09 17:47:03 peter
  2481. * self moved to hidden parameter
  2482. * removed hdisposen,hnewn,selfn
  2483. Revision 1.101 2003/05/05 14:53:16 peter
  2484. * vs_hidden replaced by is_hidden boolean
  2485. Revision 1.100 2003/04/27 11:21:34 peter
  2486. * aktprocdef renamed to current_procinfo.procdef
  2487. * procinfo renamed to current_procinfo
  2488. * procinfo will now be stored in current_module so it can be
  2489. cleaned up properly
  2490. * gen_main_procsym changed to create_main_proc and release_main_proc
  2491. to also generate a tprocinfo structure
  2492. * fixed unit implicit initfinal
  2493. Revision 1.99 2003/04/27 10:03:18 jonas
  2494. * fixed stabs generation for local variables on systems where they have
  2495. a positive offset relative to the stack/framepointer
  2496. Revision 1.98 2003/04/27 07:29:51 peter
  2497. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2498. a new procdef declaration
  2499. * aktprocsym removed
  2500. * lexlevel removed, use symtable.symtablelevel instead
  2501. * implicit init/final code uses the normal genentry/genexit
  2502. * funcret state checking updated for new funcret handling
  2503. Revision 1.97 2003/04/25 20:59:35 peter
  2504. * removed funcretn,funcretsym, function result is now in varsym
  2505. and aliases for result and function name are added using absolutesym
  2506. * vs_hidden parameter for funcret passed in parameter
  2507. * vs_hidden fixes
  2508. * writenode changed to printnode and released from extdebug
  2509. * -vp option added to generate a tree.log with the nodetree
  2510. * nicer printnode for statements, callnode
  2511. Revision 1.96 2003/04/23 13:13:58 peter
  2512. * fix operator overload search parameter order
  2513. Revision 1.95 2003/04/10 17:57:53 peter
  2514. * vs_hidden released
  2515. Revision 1.94 2003/03/17 15:54:22 peter
  2516. * store symoptions also for procdef
  2517. * check symoptions (private,public) when calculating possible
  2518. overload candidates
  2519. Revision 1.93 2003/01/15 01:44:33 peter
  2520. * merged methodpointer fixes from 1.0.x
  2521. Revision 1.92 2003/01/09 21:52:38 peter
  2522. * merged some verbosity options.
  2523. * V_LineInfo is a verbosity flag to include line info
  2524. Revision 1.91 2003/01/08 18:43:57 daniel
  2525. * Tregister changed into a record
  2526. Revision 1.90 2003/01/03 12:15:56 daniel
  2527. * Removed ifdefs around notifications
  2528. ifdefs around for loop optimizations remain
  2529. Revision 1.89 2003/01/02 11:14:02 michael
  2530. + Patch from peter to support initial values for local variables
  2531. Revision 1.88 2003/01/01 22:51:03 peter
  2532. * high value insertion changed so it works also when 2 parameters
  2533. are passed
  2534. Revision 1.87 2002/12/31 09:55:58 daniel
  2535. + Notification implementation complete
  2536. + Add for loop code optimization using notifications
  2537. results in 1.5-1.9% speed improvement in nestloop benchmark
  2538. Optimization incomplete, compiler does not cycle yet with
  2539. notifications enabled.
  2540. Revision 1.86 2002/12/30 22:44:53 daniel
  2541. * Some work on notifications
  2542. Revision 1.85 2002/12/27 18:07:44 peter
  2543. * fix crashes when searching symbols
  2544. Revision 1.84 2002/12/20 16:02:22 peter
  2545. * fix stupid copy&paste bug in binary operator search
  2546. Revision 1.83 2002/12/16 22:08:31 peter
  2547. * fix order of procdefs in procsym, procdefs are now always appended
  2548. so that loading from a ppu will keep the same order. This is
  2549. important for the generation of VMTs
  2550. Revision 1.82 2002/12/11 22:39:23 peter
  2551. * better error message when no operator is found for equal
  2552. Revision 1.81 2002/12/07 14:27:10 carl
  2553. * 3% memory optimization
  2554. * changed some types
  2555. + added type checking with different size for call node and for
  2556. parameters
  2557. Revision 1.80 2002/12/06 17:51:11 peter
  2558. * merged cdecl and array fixes
  2559. Revision 1.79 2002/11/27 20:04:10 peter
  2560. * tvarsym.get_push_size replaced by paramanager.push_size
  2561. Revision 1.78 2002/11/27 02:34:20 peter
  2562. * only find real equal procvars
  2563. Revision 1.77 2002/11/25 18:43:34 carl
  2564. - removed the invalid if <> checking (Delphi is strange on this)
  2565. + implemented abstract warning on instance creation of class with
  2566. abstract methods.
  2567. * some error message cleanups
  2568. Revision 1.76 2002/11/25 17:43:26 peter
  2569. * splitted defbase in defutil,symutil,defcmp
  2570. * merged isconvertable and is_equal into compare_defs(_ext)
  2571. * made operator search faster by walking the list only once
  2572. Revision 1.75 2002/11/23 22:50:09 carl
  2573. * some small speed optimizations
  2574. + added several new warnings/hints
  2575. Revision 1.74 2002/11/22 22:48:11 carl
  2576. * memory optimization with tconstsym (1.5%)
  2577. Revision 1.73 2002/11/18 17:31:59 peter
  2578. * pass proccalloption to ret_in_xxx and push_xxx functions
  2579. Revision 1.72 2002/11/17 16:31:57 carl
  2580. * memory optimization (3-4%) : cleanup of tai fields,
  2581. cleanup of tdef and tsym fields.
  2582. * make it work for m68k
  2583. Revision 1.71 2002/11/09 15:30:07 carl
  2584. + align RTTI tables
  2585. Revision 1.70 2002/10/13 21:33:37 peter
  2586. * give correct fileposition for undefined forward procs
  2587. Revision 1.69 2002/10/05 12:43:29 carl
  2588. * fixes for Delphi 6 compilation
  2589. (warning : Some features do not work under Delphi)
  2590. Revision 1.68 2002/10/05 00:52:20 peter
  2591. * split boolean check in two lines for easier debugging
  2592. Revision 1.67 2002/09/26 12:04:53 florian
  2593. + constsym with type=constguid can be written to ppu now,
  2594. fixes web bug 1820
  2595. Revision 1.66 2002/09/16 14:11:13 peter
  2596. * add argument to equal_paras() to support default values or not
  2597. Revision 1.65 2002/09/09 17:34:16 peter
  2598. * tdicationary.replace added to replace and item in a dictionary. This
  2599. is only allowed for the same name
  2600. * varsyms are inserted in symtable before the types are parsed. This
  2601. fixes the long standing "var longint : longint" bug
  2602. - consume_idlist and idstringlist removed. The loops are inserted
  2603. at the callers place and uses the symtable for duplicate id checking
  2604. Revision 1.64 2002/09/08 11:10:17 carl
  2605. * bugfix 2109 (bad imho, but only way)
  2606. Revision 1.63 2002/09/07 18:17:41 florian
  2607. + tvarsym.paraitem added
  2608. Revision 1.62 2002/09/07 15:25:10 peter
  2609. * old logs removed and tabs fixed
  2610. Revision 1.61 2002/09/05 19:29:45 peter
  2611. * memdebug enhancements
  2612. Revision 1.60 2002/09/05 14:51:42 peter
  2613. * internalerror instead of crash in getprocdef
  2614. Revision 1.59 2002/09/03 16:26:27 daniel
  2615. * Make Tprocdef.defs protected
  2616. Revision 1.58 2002/09/01 08:01:16 daniel
  2617. * Removed sets from Tcallnode.det_resulttype
  2618. + Added read/write notifications of variables. These will be usefull
  2619. for providing information for several optimizations. For example
  2620. the value of the loop variable of a for loop does matter is the
  2621. variable is read after the for loop, but if it's no longer used
  2622. or written, it doesn't matter and this can be used to optimize
  2623. the loop code generation.
  2624. Revision 1.57 2002/08/25 19:25:21 peter
  2625. * sym.insert_in_data removed
  2626. * symtable.insertvardata/insertconstdata added
  2627. * removed insert_in_data call from symtable.insert, it needs to be
  2628. called separatly. This allows to deref the address calculation
  2629. * procedures now calculate the parast addresses after the procedure
  2630. directives are parsed. This fixes the cdecl parast problem
  2631. * push_addr_param has an extra argument that specifies if cdecl is used
  2632. or not
  2633. Revision 1.56 2002/08/25 09:06:21 peter
  2634. * fixed loop in concat_procdefs
  2635. Revision 1.55 2002/08/20 16:54:40 peter
  2636. * write address of varsym always
  2637. Revision 1.54 2002/08/20 10:31:26 daniel
  2638. * Tcallnode.det_resulttype rewritten
  2639. Revision 1.53 2002/08/18 20:06:27 peter
  2640. * inlining is now also allowed in interface
  2641. * renamed write/load to ppuwrite/ppuload
  2642. * tnode storing in ppu
  2643. * nld,ncon,nbas are already updated for storing in ppu
  2644. Revision 1.52 2002/08/17 09:23:42 florian
  2645. * first part of procinfo rewrite
  2646. Revision 1.51 2002/08/16 14:24:59 carl
  2647. * issameref() to test if two references are the same (then emit no opcodes)
  2648. + ret_in_reg to replace ret_in_acc
  2649. (fix some register allocation bugs at the same time)
  2650. + save_std_register now has an extra parameter which is the
  2651. usedinproc registers
  2652. Revision 1.50 2002/08/13 21:40:57 florian
  2653. * more fixes for ppc calling conventions
  2654. Revision 1.49 2002/08/12 15:08:40 carl
  2655. + stab register indexes for powerpc (moved from gdb to cpubase)
  2656. + tprocessor enumeration moved to cpuinfo
  2657. + linker in target_info is now a class
  2658. * many many updates for m68k (will soon start to compile)
  2659. - removed some ifdef or correct them for correct cpu
  2660. Revision 1.48 2002/08/11 14:32:28 peter
  2661. * renamed current_library to objectlibrary
  2662. Revision 1.47 2002/08/11 13:24:14 peter
  2663. * saving of asmsymbols in ppu supported
  2664. * asmsymbollist global is removed and moved into a new class
  2665. tasmlibrarydata that will hold the info of a .a file which
  2666. corresponds with a single module. Added librarydata to tmodule
  2667. to keep the library info stored for the module. In the future the
  2668. objectfiles will also be stored to the tasmlibrarydata class
  2669. * all getlabel/newasmsymbol and friends are moved to the new class
  2670. Revision 1.46 2002/07/23 10:13:23 daniel
  2671. * Added important comment
  2672. Revision 1.45 2002/07/23 09:51:26 daniel
  2673. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2674. are worth comitting.
  2675. Revision 1.44 2002/07/20 17:45:29 daniel
  2676. * Register variables are now possible for global variables too. This is
  2677. important for small programs without procedures.
  2678. Revision 1.43 2002/07/20 11:57:58 florian
  2679. * types.pas renamed to defbase.pas because D6 contains a types
  2680. unit so this would conflicts if D6 programms are compiled
  2681. + Willamette/SSE2 instructions to assembler added
  2682. Revision 1.42 2002/07/11 14:41:31 florian
  2683. * start of the new generic parameter handling
  2684. }