symsym.pas 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121
  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. var
  1416. srsym : tsym;
  1417. srsymtable : tsymtable;
  1418. begin
  1419. { inheritance of varsym.deref ! }
  1420. vartype.resolve;
  1421. { own absolute deref }
  1422. if (abstyp=tovar) then
  1423. ref.resolve;
  1424. end;
  1425. function tabsolutesym.mangledname : string;
  1426. begin
  1427. case abstyp of
  1428. toasm :
  1429. mangledname:=asmname^;
  1430. toaddr :
  1431. mangledname:='$'+tostr(fieldoffset);
  1432. else
  1433. internalerror(10002);
  1434. end;
  1435. end;
  1436. {$ifdef GDB}
  1437. procedure tabsolutesym.concatstabto(asmlist : taasmoutput);
  1438. begin
  1439. { I don't know how to handle this !! }
  1440. end;
  1441. {$endif GDB}
  1442. {****************************************************************************
  1443. TVARSYM
  1444. ****************************************************************************}
  1445. constructor tvarsym.create(const n : string;vsp:tvarspez;const tt : ttype);
  1446. begin
  1447. inherited create(n);
  1448. typ:=varsym;
  1449. vartype:=tt;
  1450. _mangledname:=nil;
  1451. varspez:=vsp;
  1452. fieldoffset:=0;
  1453. fillchar(localloc,sizeof(localloc),0);
  1454. highvarsym:=nil;
  1455. defaultconstsym:=nil;
  1456. refs:=0;
  1457. varstate:=vs_declared;
  1458. varoptions:=[];
  1459. end;
  1460. constructor tvarsym.create_dll(const n : string;vsp:tvarspez;const tt : ttype);
  1461. begin
  1462. tvarsym(self).create(n,vsp,tt);
  1463. include(varoptions,vo_is_dll_var);
  1464. end;
  1465. constructor tvarsym.create_C(const n,mangled : string;vsp:tvarspez;const tt : ttype);
  1466. begin
  1467. tvarsym(self).create(n,vsp,tt);
  1468. stringdispose(_mangledname);
  1469. _mangledname:=stringdup(mangled);
  1470. end;
  1471. constructor tvarsym.ppuload(ppufile:tcompilerppufile);
  1472. begin
  1473. inherited loadsym(ppufile);
  1474. typ:=varsym;
  1475. fillchar(localloc,sizeof(localloc),0);
  1476. refs := 0;
  1477. varstate:=vs_used;
  1478. varspez:=tvarspez(ppufile.getbyte);
  1479. fieldoffset:=ppufile.getlongint;
  1480. highvarsym:=nil;
  1481. defaultconstsym:=nil;
  1482. ppufile.gettype(_vartype);
  1483. ppufile.getsmallset(varoptions);
  1484. if (vo_is_C_var in varoptions) then
  1485. _mangledname:=stringdup(ppufile.getstring);
  1486. end;
  1487. destructor tvarsym.destroy;
  1488. begin
  1489. if assigned(notifications) then
  1490. notifications.destroy;
  1491. inherited destroy;
  1492. end;
  1493. procedure tvarsym.buildderef;
  1494. begin
  1495. vartype.buildderef;
  1496. end;
  1497. procedure tvarsym.deref;
  1498. begin
  1499. vartype.resolve;
  1500. end;
  1501. procedure tvarsym.ppuwrite(ppufile:tcompilerppufile);
  1502. var
  1503. hvo : tvaroptions;
  1504. begin
  1505. inherited writesym(ppufile);
  1506. ppufile.putbyte(byte(varspez));
  1507. ppufile.putlongint(fieldoffset);
  1508. ppufile.puttype(vartype);
  1509. { symbols which are load are never candidates for a register,
  1510. turn off the regable }
  1511. hvo:=varoptions-[vo_regable,vo_fpuregable];
  1512. ppufile.putsmallset(hvo);
  1513. if (vo_is_C_var in varoptions) then
  1514. ppufile.putstring(mangledname);
  1515. ppufile.writeentry(ibvarsym);
  1516. end;
  1517. procedure tvarsym.generate_mangledname;
  1518. begin
  1519. _mangledname:=stringdup(make_mangledname('U',owner,name));
  1520. end;
  1521. procedure tvarsym.set_mangledname(const s:string);
  1522. begin
  1523. stringdispose(_mangledname);
  1524. _mangledname:=stringdup(s);
  1525. end;
  1526. function tvarsym.getsize : longint;
  1527. begin
  1528. if assigned(vartype.def) then
  1529. getsize:=vartype.def.size
  1530. else
  1531. getsize:=0;
  1532. end;
  1533. function tvarsym.getvaluesize : longint;
  1534. begin
  1535. if assigned(vartype.def) and
  1536. (varspez=vs_value) and
  1537. ((vartype.def.deftype<>arraydef) or
  1538. tarraydef(vartype.def).isDynamicArray or
  1539. (tarraydef(vartype.def).highrange>=tarraydef(vartype.def).lowrange)) then
  1540. getvaluesize:=vartype.def.size
  1541. else
  1542. getvaluesize:=0;
  1543. end;
  1544. procedure Tvarsym.trigger_notifications(what:Tnotification_flag);
  1545. var n:Tnotification;
  1546. begin
  1547. if assigned(notifications) then
  1548. begin
  1549. n:=Tnotification(notifications.first);
  1550. while assigned(n) do
  1551. begin
  1552. if what in n.flags then
  1553. n.callback(what,self);
  1554. n:=Tnotification(n.next);
  1555. end;
  1556. end;
  1557. end;
  1558. function Tvarsym.register_notification(flags:Tnotification_flags;callback:
  1559. Tnotification_callback):cardinal;
  1560. var n:Tnotification;
  1561. begin
  1562. if not assigned(notifications) then
  1563. notifications:=Tlinkedlist.create;
  1564. n:=Tnotification.create(flags,callback);
  1565. register_notification:=n.id;
  1566. notifications.concat(n);
  1567. end;
  1568. procedure Tvarsym.unregister_notification(id:cardinal);
  1569. var n:Tnotification;
  1570. begin
  1571. if not assigned(notifications) then
  1572. internalerror(200212311)
  1573. else
  1574. begin
  1575. n:=Tnotification(notifications.first);
  1576. while assigned(n) do
  1577. begin
  1578. if n.id=id then
  1579. begin
  1580. notifications.remove(n);
  1581. n.destroy;
  1582. exit;
  1583. end;
  1584. n:=Tnotification(n.next);
  1585. end;
  1586. internalerror(200212311)
  1587. end;
  1588. end;
  1589. {$ifdef GDB}
  1590. function tvarsym.stabstring : pchar;
  1591. var
  1592. st : string;
  1593. threadvaroffset : string;
  1594. regidx : tregisterindex;
  1595. begin
  1596. stabstring:=nil;
  1597. st:=tstoreddef(vartype.def).numberstring;
  1598. if (vo_is_thread_var in varoptions) then
  1599. threadvaroffset:='+'+tostr(pointer_size)
  1600. else
  1601. threadvaroffset:='';
  1602. case owner.symtabletype of
  1603. objectsymtable :
  1604. begin
  1605. if (sp_static in symoptions) then
  1606. begin
  1607. if (cs_gdb_gsym in aktglobalswitches) then
  1608. st := 'G'+st
  1609. else
  1610. st := 'S'+st;
  1611. stabstring := strpnew('"'+owner.name^+'__'+name+':'+st+
  1612. '",'+
  1613. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)
  1614. +','+mangledname+threadvaroffset);
  1615. end;
  1616. end;
  1617. globalsymtable :
  1618. begin
  1619. { Here we used S instead of
  1620. because with G GDB doesn't look at the address field
  1621. but searches the same name or with a leading underscore
  1622. but these names don't exist in pascal !}
  1623. if (cs_gdb_gsym in aktglobalswitches) then
  1624. st := 'G'+st
  1625. else
  1626. st := 'S'+st;
  1627. stabstring := strpnew('"'+name+':'+st+'",'+
  1628. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+
  1629. ','+mangledname+threadvaroffset);
  1630. end;
  1631. staticsymtable :
  1632. begin
  1633. stabstring := strpnew('"'+name+':S'+st+'",'+
  1634. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+
  1635. ','+mangledname+threadvaroffset);
  1636. end;
  1637. parasymtable,
  1638. localsymtable :
  1639. begin
  1640. { There is no space allocated for not referenced locals }
  1641. if (owner.symtabletype=localsymtable) and
  1642. (refs=0) then
  1643. begin
  1644. exit;
  1645. end;
  1646. if (vo_is_C_var in varoptions) then
  1647. begin
  1648. stabstring := strpnew('"'+name+':S'+st+'",'+
  1649. tostr(N_LCSYM)+',0,'+tostr(fileinfo.line)+','+mangledname);
  1650. exit;
  1651. end;
  1652. if (owner.symtabletype=parasymtable) and
  1653. paramanager.push_addr_param(varspez,vartype.def,tprocdef(owner.defowner).proccalloption) and
  1654. not(vo_has_local_copy in varoptions) then
  1655. st := 'v'+st { should be 'i' but 'i' doesn't work }
  1656. else
  1657. st := 'p'+st;
  1658. case localloc.loc of
  1659. LOC_REGISTER, LOC_FPUREGISTER :
  1660. begin
  1661. regidx:=findreg_by_number(localloc.register);
  1662. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1663. { this is the register order for GDB}
  1664. stabstring:=strpnew('"'+name+':r'+st+'",'+
  1665. tostr(N_RSYM)+',0,'+
  1666. tostr(fileinfo.line)+','+tostr(regstabs_table[regidx]));
  1667. end;
  1668. LOC_REFERENCE :
  1669. begin
  1670. { offset to ebp => will not work if the framepointer is esp
  1671. so some optimizing will make things harder to debug }
  1672. stabstring := strpnew('"'+name+':'+st+'",'+
  1673. tostr(N_tsym)+',0,'+tostr(fileinfo.line)+','+
  1674. tostr(localloc.reference.offset));
  1675. end;
  1676. else
  1677. internalerror(2003091814);
  1678. end;
  1679. end;
  1680. else
  1681. stabstring := inherited stabstring;
  1682. end;
  1683. end;
  1684. procedure tvarsym.concatstabto(asmlist : taasmoutput);
  1685. var
  1686. regidx : tregisterindex;
  1687. stab_str : pchar;
  1688. c : char;
  1689. begin
  1690. if (owner.symtabletype=parasymtable) and
  1691. (copy(name,1,6)='hidden') then
  1692. exit;
  1693. if (vo_is_self in varoptions) then
  1694. begin
  1695. if localloc.loc<>LOC_REFERENCE then
  1696. internalerror(2003091815);
  1697. if (po_classmethod in current_procinfo.procdef.procoptions) or
  1698. (po_staticmethod in current_procinfo.procdef.procoptions) then
  1699. begin
  1700. asmlist.concat(Tai_stabs.Create(strpnew(
  1701. '"pvmt:p'+tstoreddef(pvmttype.def).numberstring+'",'+
  1702. tostr(N_tsym)+',0,0,'+tostr(localloc.reference.offset))));
  1703. end
  1704. else
  1705. begin
  1706. if not(is_class(current_procinfo.procdef._class)) then
  1707. c:='v'
  1708. else
  1709. c:='p';
  1710. asmlist.concat(Tai_stabs.Create(strpnew(
  1711. '"$t:'+c+current_procinfo.procdef._class.numberstring+'",'+
  1712. tostr(N_tsym)+',0,0,'+tostr(localloc.reference.offset))));
  1713. end;
  1714. end
  1715. else
  1716. if (localloc.loc=LOC_REGISTER) then
  1717. begin
  1718. regidx:=findreg_by_number(localloc.register);
  1719. { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi", "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  1720. { this is the register order for GDB}
  1721. stab_str:=strpnew('"'+name+':r'
  1722. +tstoreddef(vartype.def).numberstring+'",'+
  1723. tostr(N_RSYM)+',0,'+
  1724. tostr(fileinfo.line)+','+tostr(regstabs_table[regidx]));
  1725. asmList.concat(Tai_stabs.Create(stab_str));
  1726. end
  1727. else
  1728. inherited concatstabto(asmlist);
  1729. end;
  1730. {$endif GDB}
  1731. procedure tvarsym.setvartype(const newtype: ttype);
  1732. begin
  1733. _vartype := newtype;
  1734. { can we load the value into a register ? }
  1735. if not assigned(owner) or
  1736. (owner.symtabletype in [localsymtable,parasymtable]) then
  1737. begin
  1738. if tstoreddef(vartype.def).is_intregable then
  1739. include(varoptions,vo_regable)
  1740. else
  1741. exclude(varoptions,vo_regable);
  1742. if tstoreddef(vartype.def).is_fpuregable then
  1743. include(varoptions,vo_fpuregable)
  1744. else
  1745. exclude(varoptions,vo_fpuregable);
  1746. end;
  1747. end;
  1748. {****************************************************************************
  1749. TTYPEDCONSTSYM
  1750. *****************************************************************************}
  1751. constructor ttypedconstsym.create(const n : string;p : tdef;writable : boolean);
  1752. begin
  1753. inherited create(n);
  1754. typ:=typedconstsym;
  1755. typedconsttype.setdef(p);
  1756. is_writable:=writable;
  1757. end;
  1758. constructor ttypedconstsym.createtype(const n : string;const tt : ttype;writable : boolean);
  1759. begin
  1760. inherited create(n);
  1761. typ:=typedconstsym;
  1762. typedconsttype:=tt;
  1763. is_writable:=writable;
  1764. end;
  1765. constructor ttypedconstsym.ppuload(ppufile:tcompilerppufile);
  1766. begin
  1767. inherited loadsym(ppufile);
  1768. typ:=typedconstsym;
  1769. ppufile.gettype(typedconsttype);
  1770. is_writable:=boolean(ppufile.getbyte);
  1771. end;
  1772. destructor ttypedconstsym.destroy;
  1773. begin
  1774. inherited destroy;
  1775. end;
  1776. procedure ttypedconstsym.generate_mangledname;
  1777. begin
  1778. _mangledname:=stringdup(make_mangledname('TC',owner,name));
  1779. end;
  1780. function ttypedconstsym.getsize : longint;
  1781. begin
  1782. if assigned(typedconsttype.def) then
  1783. getsize:=typedconsttype.def.size
  1784. else
  1785. getsize:=0;
  1786. end;
  1787. procedure ttypedconstsym.buildderef;
  1788. begin
  1789. typedconsttype.buildderef;
  1790. end;
  1791. procedure ttypedconstsym.deref;
  1792. begin
  1793. typedconsttype.resolve;
  1794. end;
  1795. procedure ttypedconstsym.ppuwrite(ppufile:tcompilerppufile);
  1796. begin
  1797. inherited writesym(ppufile);
  1798. ppufile.puttype(typedconsttype);
  1799. ppufile.putbyte(byte(is_writable));
  1800. ppufile.writeentry(ibtypedconstsym);
  1801. end;
  1802. {$ifdef GDB}
  1803. function ttypedconstsym.stabstring : pchar;
  1804. var
  1805. st : char;
  1806. begin
  1807. if (cs_gdb_gsym in aktglobalswitches) and (owner.symtabletype=globalsymtable) then
  1808. st := 'G'
  1809. else
  1810. st := 'S';
  1811. stabstring := strpnew('"'+name+':'+st+
  1812. tstoreddef(typedconsttype.def).numberstring+'",'+tostr(n_STSYM)+',0,'+
  1813. tostr(fileinfo.line)+','+mangledname);
  1814. end;
  1815. {$endif GDB}
  1816. {****************************************************************************
  1817. TCONSTSYM
  1818. ****************************************************************************}
  1819. constructor tconstsym.create_ord(const n : string;t : tconsttyp;v : TConstExprInt);
  1820. begin
  1821. inherited create(n);
  1822. fillchar(value, sizeof(value), #0);
  1823. typ:=constsym;
  1824. consttyp:=t;
  1825. value.valueord:=v;
  1826. ResStrIndex:=0;
  1827. consttype.reset;
  1828. end;
  1829. constructor tconstsym.create_ord_typed(const n : string;t : tconsttyp;v : tconstexprint;const tt:ttype);
  1830. begin
  1831. inherited create(n);
  1832. fillchar(value, sizeof(value), #0);
  1833. typ:=constsym;
  1834. consttyp:=t;
  1835. value.valueord:=v;
  1836. ResStrIndex:=0;
  1837. consttype:=tt;
  1838. end;
  1839. constructor tconstsym.create_ordptr_typed(const n : string;t : tconsttyp;v : tconstptruint;const tt:ttype);
  1840. begin
  1841. inherited create(n);
  1842. fillchar(value, sizeof(value), #0);
  1843. typ:=constsym;
  1844. consttyp:=t;
  1845. value.valueordptr:=v;
  1846. ResStrIndex:=0;
  1847. consttype:=tt;
  1848. end;
  1849. constructor tconstsym.create_ptr(const n : string;t : tconsttyp;v : pointer);
  1850. begin
  1851. inherited create(n);
  1852. fillchar(value, sizeof(value), #0);
  1853. typ:=constsym;
  1854. consttyp:=t;
  1855. value.valueptr:=v;
  1856. ResStrIndex:=0;
  1857. consttype.reset;
  1858. end;
  1859. constructor tconstsym.create_ptr_typed(const n : string;t : tconsttyp;v : pointer;const tt:ttype);
  1860. begin
  1861. inherited create(n);
  1862. fillchar(value, sizeof(value), #0);
  1863. typ:=constsym;
  1864. consttyp:=t;
  1865. value.valueptr:=v;
  1866. ResStrIndex:=0;
  1867. consttype:=tt;
  1868. end;
  1869. constructor tconstsym.create_string(const n : string;t : tconsttyp;str:pchar;l:longint);
  1870. begin
  1871. inherited create(n);
  1872. fillchar(value, sizeof(value), #0);
  1873. typ:=constsym;
  1874. consttyp:=t;
  1875. value.valueptr:=str;
  1876. consttype.reset;
  1877. value.len:=l;
  1878. if t=constresourcestring then
  1879. ResStrIndex:=ResourceStrings.Register(name,pchar(value.valueptr),value.len);
  1880. end;
  1881. constructor tconstsym.ppuload(ppufile:tcompilerppufile);
  1882. var
  1883. pd : pbestreal;
  1884. ps : pnormalset;
  1885. pc : pchar;
  1886. begin
  1887. inherited loadsym(ppufile);
  1888. typ:=constsym;
  1889. consttype.reset;
  1890. consttyp:=tconsttyp(ppufile.getbyte);
  1891. fillchar(value, sizeof(value), #0);
  1892. case consttyp of
  1893. constint:
  1894. value.valueord:=ppufile.getexprint;
  1895. constwchar,
  1896. constbool,
  1897. constchar :
  1898. value.valueord:=ppufile.getlongint;
  1899. constord :
  1900. begin
  1901. ppufile.gettype(consttype);
  1902. value.valueord:=ppufile.getexprint;
  1903. end;
  1904. constpointer :
  1905. begin
  1906. ppufile.gettype(consttype);
  1907. value.valueordptr:=ppufile.getptruint;
  1908. end;
  1909. conststring,
  1910. constresourcestring :
  1911. begin
  1912. value.len:=ppufile.getlongint;
  1913. getmem(pc,value.len+1);
  1914. ppufile.getdata(pc^,value.len);
  1915. if consttyp=constresourcestring then
  1916. ResStrIndex:=ppufile.getlongint;
  1917. value.valueptr:=pc;
  1918. end;
  1919. constreal :
  1920. begin
  1921. new(pd);
  1922. pd^:=ppufile.getreal;
  1923. value.valueptr:=pd;
  1924. end;
  1925. constset :
  1926. begin
  1927. ppufile.gettype(consttype);
  1928. new(ps);
  1929. ppufile.getnormalset(ps^);
  1930. value.valueptr:=ps;
  1931. end;
  1932. constguid :
  1933. begin
  1934. new(pguid(value.valueptr));
  1935. ppufile.getdata(value.valueptr^,sizeof(tguid));
  1936. end;
  1937. constnil : ;
  1938. else
  1939. Message1(unit_f_ppu_invalid_entry,tostr(ord(consttyp)));
  1940. end;
  1941. end;
  1942. destructor tconstsym.destroy;
  1943. begin
  1944. case consttyp of
  1945. conststring,
  1946. constresourcestring :
  1947. freemem(pchar(value.valueptr),value.len+1);
  1948. constreal :
  1949. dispose(pbestreal(value.valueptr));
  1950. constset :
  1951. dispose(pnormalset(value.valueptr));
  1952. constguid :
  1953. dispose(pguid(value.valueptr));
  1954. end;
  1955. inherited destroy;
  1956. end;
  1957. function tconstsym.mangledname : string;
  1958. begin
  1959. mangledname:=name;
  1960. end;
  1961. procedure tconstsym.buildderef;
  1962. begin
  1963. if consttyp in [constord,constpointer,constset] then
  1964. consttype.buildderef;
  1965. end;
  1966. procedure tconstsym.deref;
  1967. begin
  1968. if consttyp in [constord,constpointer,constset] then
  1969. consttype.resolve;
  1970. end;
  1971. procedure tconstsym.ppuwrite(ppufile:tcompilerppufile);
  1972. begin
  1973. inherited writesym(ppufile);
  1974. ppufile.putbyte(byte(consttyp));
  1975. case consttyp of
  1976. constnil : ;
  1977. constint:
  1978. ppufile.putexprint(value.valueord);
  1979. constbool,
  1980. constchar,
  1981. constwchar :
  1982. ppufile.putlongint(value.valueord);
  1983. constord :
  1984. begin
  1985. ppufile.puttype(consttype);
  1986. ppufile.putexprint(value.valueord);
  1987. end;
  1988. constpointer :
  1989. begin
  1990. ppufile.puttype(consttype);
  1991. ppufile.putptruint(value.valueordptr);
  1992. end;
  1993. conststring,
  1994. constresourcestring :
  1995. begin
  1996. ppufile.putlongint(value.len);
  1997. ppufile.putdata(pchar(value.valueptr)^,value.len);
  1998. if consttyp=constresourcestring then
  1999. ppufile.putlongint(ResStrIndex);
  2000. end;
  2001. constreal :
  2002. ppufile.putreal(pbestreal(value.valueptr)^);
  2003. constset :
  2004. begin
  2005. ppufile.puttype(consttype);
  2006. ppufile.putnormalset(value.valueptr^);
  2007. end;
  2008. constguid :
  2009. ppufile.putdata(value.valueptr^,sizeof(tguid));
  2010. else
  2011. internalerror(13);
  2012. end;
  2013. ppufile.writeentry(ibconstsym);
  2014. end;
  2015. {$ifdef GDB}
  2016. function tconstsym.stabstring : pchar;
  2017. var st : string;
  2018. begin
  2019. {even GDB v4.16 only now 'i' 'r' and 'e' !!!}
  2020. case consttyp of
  2021. conststring : begin
  2022. st := 's'''+strpas(pchar(value.valueptr))+'''';
  2023. end;
  2024. constbool,
  2025. constint,
  2026. constord,
  2027. constwchar,
  2028. constchar : st := 'i'+int64tostr(value.valueord);
  2029. constpointer :
  2030. st := 'i'+int64tostr(value.valueordptr);
  2031. constreal : begin
  2032. system.str(pbestreal(value.valueptr)^,st);
  2033. st := 'r'+st;
  2034. end;
  2035. { if we don't know just put zero !! }
  2036. else st:='i0';
  2037. {***SETCONST}
  2038. {constset:;} {*** I don't know what to do with a set.}
  2039. { sets are not recognized by GDB}
  2040. {***}
  2041. end;
  2042. stabstring := strpnew('"'+name+':c='+st+'",'+tostr(N_function)+',0,'+
  2043. tostr(fileinfo.line)+',0');
  2044. end;
  2045. procedure tconstsym.concatstabto(asmlist : taasmoutput);
  2046. begin
  2047. if consttyp <> conststring then
  2048. inherited concatstabto(asmlist);
  2049. end;
  2050. {$endif GDB}
  2051. {****************************************************************************
  2052. TENUMSYM
  2053. ****************************************************************************}
  2054. constructor tenumsym.create(const n : string;def : tenumdef;v : longint);
  2055. begin
  2056. inherited create(n);
  2057. typ:=enumsym;
  2058. definition:=def;
  2059. value:=v;
  2060. { check for jumps }
  2061. if v>def.max+1 then
  2062. def.has_jumps:=true;
  2063. { update low and high }
  2064. if def.min>v then
  2065. def.setmin(v);
  2066. if def.max<v then
  2067. def.setmax(v);
  2068. order;
  2069. end;
  2070. constructor tenumsym.ppuload(ppufile:tcompilerppufile);
  2071. begin
  2072. inherited loadsym(ppufile);
  2073. typ:=enumsym;
  2074. ppufile.getderef(definitionderef);
  2075. value:=ppufile.getlongint;
  2076. nextenum := Nil;
  2077. end;
  2078. procedure tenumsym.buildderef;
  2079. begin
  2080. definitionderef.build(definition);
  2081. end;
  2082. procedure tenumsym.deref;
  2083. begin
  2084. definition:=tenumdef(definitionderef.resolve);
  2085. order;
  2086. end;
  2087. procedure tenumsym.order;
  2088. var
  2089. sym : tenumsym;
  2090. begin
  2091. sym := tenumsym(definition.firstenum);
  2092. if sym = nil then
  2093. begin
  2094. definition.firstenum := self;
  2095. nextenum := nil;
  2096. exit;
  2097. end;
  2098. { reorder the symbols in increasing value }
  2099. if value < sym.value then
  2100. begin
  2101. nextenum := sym;
  2102. definition.firstenum := self;
  2103. end
  2104. else
  2105. begin
  2106. while (sym.value <= value) and assigned(sym.nextenum) do
  2107. sym := sym.nextenum;
  2108. nextenum := sym.nextenum;
  2109. sym.nextenum := self;
  2110. end;
  2111. end;
  2112. procedure tenumsym.ppuwrite(ppufile:tcompilerppufile);
  2113. begin
  2114. inherited writesym(ppufile);
  2115. ppufile.putderef(definitionderef);
  2116. ppufile.putlongint(value);
  2117. ppufile.writeentry(ibenumsym);
  2118. end;
  2119. {$ifdef GDB}
  2120. procedure tenumsym.concatstabto(asmlist : taasmoutput);
  2121. begin
  2122. {enum elements have no stab !}
  2123. end;
  2124. {$EndIf GDB}
  2125. {****************************************************************************
  2126. TTYPESYM
  2127. ****************************************************************************}
  2128. constructor ttypesym.create(const n : string;const tt : ttype);
  2129. begin
  2130. inherited create(n);
  2131. typ:=typesym;
  2132. restype:=tt;
  2133. {$ifdef GDB}
  2134. isusedinstab := false;
  2135. {$endif GDB}
  2136. { register the typesym for the definition }
  2137. if assigned(restype.def) and
  2138. (restype.def.deftype<>errordef) and
  2139. not(assigned(restype.def.typesym)) then
  2140. restype.def.typesym:=self;
  2141. end;
  2142. constructor ttypesym.ppuload(ppufile:tcompilerppufile);
  2143. begin
  2144. inherited loadsym(ppufile);
  2145. typ:=typesym;
  2146. {$ifdef GDB}
  2147. isusedinstab := false;
  2148. {$endif GDB}
  2149. ppufile.gettype(restype);
  2150. end;
  2151. function ttypesym.gettypedef:tdef;
  2152. begin
  2153. gettypedef:=restype.def;
  2154. end;
  2155. procedure ttypesym.buildderef;
  2156. begin
  2157. restype.buildderef;
  2158. end;
  2159. procedure ttypesym.deref;
  2160. begin
  2161. restype.resolve;
  2162. end;
  2163. procedure ttypesym.ppuwrite(ppufile:tcompilerppufile);
  2164. begin
  2165. inherited writesym(ppufile);
  2166. ppufile.puttype(restype);
  2167. ppufile.writeentry(ibtypesym);
  2168. end;
  2169. procedure ttypesym.load_references(ppufile:tcompilerppufile;locals:boolean);
  2170. begin
  2171. inherited load_references(ppufile,locals);
  2172. if (restype.def.deftype=recorddef) then
  2173. tstoredsymtable(trecorddef(restype.def).symtable).load_references(ppufile,locals);
  2174. if (restype.def.deftype=objectdef) then
  2175. tstoredsymtable(tobjectdef(restype.def).symtable).load_references(ppufile,locals);
  2176. end;
  2177. function ttypesym.write_references(ppufile:tcompilerppufile;locals:boolean):boolean;
  2178. var
  2179. d : tderef;
  2180. begin
  2181. d.reset;
  2182. if not inherited write_references(ppufile,locals) then
  2183. begin
  2184. { write address of this symbol if record or object
  2185. even if no real refs are there
  2186. because we need it for the symtable }
  2187. if (restype.def.deftype in [recorddef,objectdef]) then
  2188. begin
  2189. d.build(self);
  2190. ppufile.putderef(d);
  2191. ppufile.writeentry(ibsymref);
  2192. end;
  2193. end;
  2194. write_references:=true;
  2195. if (restype.def.deftype=recorddef) then
  2196. tstoredsymtable(trecorddef(restype.def).symtable).write_references(ppufile,locals);
  2197. if (restype.def.deftype=objectdef) then
  2198. tstoredsymtable(tobjectdef(restype.def).symtable).write_references(ppufile,locals);
  2199. end;
  2200. {$ifdef GDB}
  2201. function ttypesym.stabstring : pchar;
  2202. var
  2203. stabchar : string[2];
  2204. short : string;
  2205. begin
  2206. if restype.def.deftype in tagtypes then
  2207. stabchar := 'Tt'
  2208. else
  2209. stabchar := 't';
  2210. short := '"'+name+':'+stabchar+tstoreddef(restype.def).numberstring
  2211. +'",'+tostr(N_LSYM)+',0,'+tostr(fileinfo.line)+',0';
  2212. stabstring := strpnew(short);
  2213. end;
  2214. procedure ttypesym.concatstabto(asmlist : taasmoutput);
  2215. begin
  2216. {not stabs for forward defs }
  2217. if assigned(restype.def) then
  2218. if (restype.def.typesym = self) then
  2219. tstoreddef(restype.def).concatstabto(asmlist)
  2220. else
  2221. inherited concatstabto(asmlist);
  2222. end;
  2223. {$endif GDB}
  2224. {****************************************************************************
  2225. TSYSSYM
  2226. ****************************************************************************}
  2227. constructor tsyssym.create(const n : string;l : longint);
  2228. begin
  2229. inherited create(n);
  2230. typ:=syssym;
  2231. number:=l;
  2232. end;
  2233. constructor tsyssym.ppuload(ppufile:tcompilerppufile);
  2234. begin
  2235. inherited loadsym(ppufile);
  2236. typ:=syssym;
  2237. number:=ppufile.getlongint;
  2238. end;
  2239. destructor tsyssym.destroy;
  2240. begin
  2241. inherited destroy;
  2242. end;
  2243. procedure tsyssym.ppuwrite(ppufile:tcompilerppufile);
  2244. begin
  2245. inherited writesym(ppufile);
  2246. ppufile.putlongint(number);
  2247. ppufile.writeentry(ibsyssym);
  2248. end;
  2249. {$ifdef GDB}
  2250. procedure tsyssym.concatstabto(asmlist : taasmoutput);
  2251. begin
  2252. end;
  2253. {$endif GDB}
  2254. {****************************************************************************
  2255. TRTTISYM
  2256. ****************************************************************************}
  2257. constructor trttisym.create(const n:string;rt:trttitype);
  2258. const
  2259. prefix : array[trttitype] of string[5]=('$rtti','$init');
  2260. begin
  2261. inherited create(prefix[rt]+n);
  2262. typ:=rttisym;
  2263. lab:=nil;
  2264. rttityp:=rt;
  2265. end;
  2266. constructor trttisym.ppuload(ppufile:tcompilerppufile);
  2267. begin
  2268. inherited loadsym(ppufile);
  2269. typ:=rttisym;
  2270. lab:=nil;
  2271. rttityp:=trttitype(ppufile.getbyte);
  2272. end;
  2273. procedure trttisym.ppuwrite(ppufile:tcompilerppufile);
  2274. begin
  2275. inherited writesym(ppufile);
  2276. ppufile.putbyte(byte(rttityp));
  2277. ppufile.writeentry(ibrttisym);
  2278. end;
  2279. function trttisym.mangledname : string;
  2280. const
  2281. prefix : array[trttitype] of string[5]=('RTTI_','INIT_');
  2282. var
  2283. s : string;
  2284. p : tsymtable;
  2285. begin
  2286. s:='';
  2287. p:=owner;
  2288. while assigned(p) and (p.symtabletype=localsymtable) do
  2289. begin
  2290. s:=s+'_'+p.defowner.name;
  2291. p:=p.defowner.owner;
  2292. end;
  2293. if not(p.symtabletype in [globalsymtable,staticsymtable]) then
  2294. internalerror(200108265);
  2295. mangledname:=prefix[rttityp]+p.name^+s+'$_'+Copy(name,5,255);
  2296. end;
  2297. function trttisym.get_label:tasmsymbol;
  2298. begin
  2299. { the label is always a global label }
  2300. if not assigned(lab) then
  2301. lab:=objectlibrary.newasmsymboldata(mangledname);
  2302. get_label:=lab;
  2303. end;
  2304. { persistent rtti generation }
  2305. procedure generate_rtti(p:tsym);
  2306. var
  2307. rsym : trttisym;
  2308. def : tstoreddef;
  2309. begin
  2310. { rtti can only be generated for classes that are always typesyms }
  2311. if not(p.typ=typesym) then
  2312. internalerror(200108261);
  2313. def:=tstoreddef(ttypesym(p).restype.def);
  2314. { only create rtti once for each definition }
  2315. if not(df_has_rttitable in def.defoptions) then
  2316. begin
  2317. { definition should be in the same symtable as the symbol }
  2318. if p.owner<>def.owner then
  2319. internalerror(200108262);
  2320. { create rttisym }
  2321. rsym:=trttisym.create(p.name,fullrtti);
  2322. p.owner.insert(rsym);
  2323. { register rttisym in definition }
  2324. include(def.defoptions,df_has_rttitable);
  2325. def.rttitablesym:=rsym;
  2326. { write rtti data }
  2327. def.write_child_rtti_data(fullrtti);
  2328. if (cs_create_smart in aktmoduleswitches) then
  2329. rttiList.concat(Tai_cut.Create);
  2330. rttilist.concat(tai_align.create(const_align(pointer_size)));
  2331. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  2332. def.write_rtti_data(fullrtti);
  2333. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2334. end;
  2335. end;
  2336. { persistent init table generation }
  2337. procedure generate_inittable(p:tsym);
  2338. var
  2339. rsym : trttisym;
  2340. def : tstoreddef;
  2341. begin
  2342. { anonymous types are also allowed for records that can be varsym }
  2343. case p.typ of
  2344. typesym :
  2345. def:=tstoreddef(ttypesym(p).restype.def);
  2346. varsym :
  2347. def:=tstoreddef(tvarsym(p).vartype.def);
  2348. else
  2349. internalerror(200108263);
  2350. end;
  2351. { only create inittable once for each definition }
  2352. if not(df_has_inittable in def.defoptions) then
  2353. begin
  2354. { definition should be in the same symtable as the symbol }
  2355. if p.owner<>def.owner then
  2356. internalerror(200108264);
  2357. { create rttisym }
  2358. rsym:=trttisym.create(p.name,initrtti);
  2359. p.owner.insert(rsym);
  2360. { register rttisym in definition }
  2361. include(def.defoptions,df_has_inittable);
  2362. def.inittablesym:=rsym;
  2363. { write inittable data }
  2364. def.write_child_rtti_data(initrtti);
  2365. if (cs_create_smart in aktmoduleswitches) then
  2366. rttiList.concat(Tai_cut.Create);
  2367. rttilist.concat(tai_align.create(const_align(pointer_size)));
  2368. rttiList.concat(Tai_symbol.Create_global(rsym.get_label,0));
  2369. def.write_rtti_data(initrtti);
  2370. rttiList.concat(Tai_symbol_end.Create(rsym.get_label));
  2371. end;
  2372. end;
  2373. end.
  2374. {
  2375. $Log$
  2376. Revision 1.137 2003-12-01 18:44:15 peter
  2377. * fixed some crashes
  2378. * fixed varargs and register calling probs
  2379. Revision 1.136 2003/11/29 18:16:39 jonas
  2380. * don't internalerror when emitting debuginfo for LOC_FPUREGISTER
  2381. Revision 1.135 2003/11/23 17:05:16 peter
  2382. * register calling is left-right
  2383. * parameter ordering
  2384. * left-right calling inserts result parameter last
  2385. Revision 1.134 2003/10/30 16:23:13 peter
  2386. * don't search for overloads in parents for constructors
  2387. Revision 1.133 2003/10/29 21:56:28 peter
  2388. * procsym.deref derefs only own procdefs
  2389. * reset paracount in procdef.deref so a second deref doesn't increase
  2390. the paracounts to invalid values
  2391. Revision 1.132 2003/10/29 19:48:51 peter
  2392. * renamed mangeldname_prefix to make_mangledname and made it more
  2393. generic
  2394. * make_mangledname is now also used for internal threadvar/resstring
  2395. lists
  2396. * Add P$ in front of program modulename to prevent duplicated symbols
  2397. at assembler level, because the main program can have the same name
  2398. as a unit, see webtbs/tw1251b
  2399. Revision 1.131 2003/10/28 15:36:01 peter
  2400. * absolute to object field supported, fixes tb0458
  2401. Revision 1.130 2003/10/22 20:40:00 peter
  2402. * write derefdata in a separate ppu entry
  2403. Revision 1.129 2003/10/22 15:22:33 peter
  2404. * fixed unitsym-globalsymtable relation so the uses of a unit
  2405. is counted correctly
  2406. Revision 1.128 2003/10/21 18:14:30 peter
  2407. * fix writing of widechar to ppu
  2408. Revision 1.127 2003/10/17 14:38:32 peter
  2409. * 64k registers supported
  2410. * fixed some memory leaks
  2411. Revision 1.126 2003/10/13 14:05:12 peter
  2412. * removed is_visible_for_proc
  2413. * search also for class overloads when finding interface
  2414. implementations
  2415. Revision 1.125 2003/10/08 19:19:45 peter
  2416. * set_varstate cleanup
  2417. Revision 1.124 2003/10/07 21:14:33 peter
  2418. * compare_paras() has a parameter to ignore hidden parameters
  2419. * cross unit overload searching ignores hidden parameters when
  2420. comparing parameter lists. Now function(string):string is
  2421. not overriden with procedure(string) which has the same visible
  2422. parameter list
  2423. Revision 1.123 2003/10/07 15:17:07 peter
  2424. * inline supported again, LOC_REFERENCEs are used to pass the
  2425. parameters
  2426. * inlineparasymtable,inlinelocalsymtable removed
  2427. * exitlabel inserting fixed
  2428. Revision 1.122 2003/10/01 20:34:49 peter
  2429. * procinfo unit contains tprocinfo
  2430. * cginfo renamed to cgbase
  2431. * moved cgmessage to verbose
  2432. * fixed ppc and sparc compiles
  2433. Revision 1.121 2003/09/25 21:25:37 peter
  2434. * has_local_copy gdb fix
  2435. Revision 1.120 2003/09/25 16:18:54 peter
  2436. * fixed stabs for globals,static
  2437. Revision 1.119 2003/09/23 17:56:06 peter
  2438. * locals and paras are allocated in the code generation
  2439. * tvarsym.localloc contains the location of para/local when
  2440. generating code for the current procedure
  2441. Revision 1.118 2003/09/16 16:17:01 peter
  2442. * varspez in calls to push_addr_param
  2443. Revision 1.117 2003/09/14 13:20:12 peter
  2444. * fix previous commit, also include objectsymtable
  2445. Revision 1.116 2003/09/14 12:58:00 peter
  2446. * support mulitple overloads in implementation, this is delphi
  2447. compatible
  2448. * procsym only stores the overloads available in the interface
  2449. Revision 1.115 2003/09/03 15:55:01 peter
  2450. * NEWRA branch merged
  2451. Revision 1.114 2003/09/03 11:18:37 florian
  2452. * fixed arm concatcopy
  2453. + arm support in the common compiler sources added
  2454. * moved some generic cg code around
  2455. + tfputype added
  2456. * ...
  2457. Revision 1.113.2.2 2003/08/29 17:28:59 peter
  2458. * next batch of updates
  2459. Revision 1.113.2.1 2003/08/27 19:55:54 peter
  2460. * first tregister patch
  2461. Revision 1.113 2003/08/20 20:29:06 daniel
  2462. * Some more R_NO changes
  2463. * Preventive code to loadref added
  2464. Revision 1.112 2003/07/05 22:41:59 peter
  2465. * check if owner.defowner is valid when checking private/protected
  2466. Revision 1.111 2003/07/04 22:41:41 pierre
  2467. * single threadvar debugging support
  2468. Revision 1.110 2003/06/13 21:19:31 peter
  2469. * current_procdef removed, use current_procinfo.procdef instead
  2470. Revision 1.109 2003/06/07 20:26:32 peter
  2471. * re-resolving added instead of reloading from ppu
  2472. * tderef object added to store deref info for resolving
  2473. Revision 1.108 2003/06/05 17:53:30 peter
  2474. * fix to compile without gdb
  2475. Revision 1.107 2003/06/02 22:59:17 florian
  2476. * absolutesyms aren't fpuregable either
  2477. Revision 1.106 2003/05/30 18:48:17 jonas
  2478. * fixed intregister bug
  2479. * fixed error in my previous commit: vo_(fpu)regable should only be set
  2480. for (inline)localsymtable and (inline)parasymtable entries
  2481. Revision 1.105 2003/05/30 13:35:10 jonas
  2482. * the vartype field of tvarsym is now a property, because is_XXXregable
  2483. must be updated when the vartype is changed
  2484. Revision 1.104 2003/05/15 18:58:53 peter
  2485. * removed selfpointer_offset, vmtpointer_offset
  2486. * tvarsym.adjusted_address
  2487. * address in localsymtable is now in the real direction
  2488. * removed some obsolete globals
  2489. Revision 1.103 2003/05/12 18:13:57 peter
  2490. * create rtti label using newasmsymboldata and update binding
  2491. only when calling tai_symbol.create
  2492. * tai_symbol.create_global added
  2493. Revision 1.102 2003/05/09 17:47:03 peter
  2494. * self moved to hidden parameter
  2495. * removed hdisposen,hnewn,selfn
  2496. Revision 1.101 2003/05/05 14:53:16 peter
  2497. * vs_hidden replaced by is_hidden boolean
  2498. Revision 1.100 2003/04/27 11:21:34 peter
  2499. * aktprocdef renamed to current_procinfo.procdef
  2500. * procinfo renamed to current_procinfo
  2501. * procinfo will now be stored in current_module so it can be
  2502. cleaned up properly
  2503. * gen_main_procsym changed to create_main_proc and release_main_proc
  2504. to also generate a tprocinfo structure
  2505. * fixed unit implicit initfinal
  2506. Revision 1.99 2003/04/27 10:03:18 jonas
  2507. * fixed stabs generation for local variables on systems where they have
  2508. a positive offset relative to the stack/framepointer
  2509. Revision 1.98 2003/04/27 07:29:51 peter
  2510. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2511. a new procdef declaration
  2512. * aktprocsym removed
  2513. * lexlevel removed, use symtable.symtablelevel instead
  2514. * implicit init/final code uses the normal genentry/genexit
  2515. * funcret state checking updated for new funcret handling
  2516. Revision 1.97 2003/04/25 20:59:35 peter
  2517. * removed funcretn,funcretsym, function result is now in varsym
  2518. and aliases for result and function name are added using absolutesym
  2519. * vs_hidden parameter for funcret passed in parameter
  2520. * vs_hidden fixes
  2521. * writenode changed to printnode and released from extdebug
  2522. * -vp option added to generate a tree.log with the nodetree
  2523. * nicer printnode for statements, callnode
  2524. Revision 1.96 2003/04/23 13:13:58 peter
  2525. * fix operator overload search parameter order
  2526. Revision 1.95 2003/04/10 17:57:53 peter
  2527. * vs_hidden released
  2528. Revision 1.94 2003/03/17 15:54:22 peter
  2529. * store symoptions also for procdef
  2530. * check symoptions (private,public) when calculating possible
  2531. overload candidates
  2532. Revision 1.93 2003/01/15 01:44:33 peter
  2533. * merged methodpointer fixes from 1.0.x
  2534. Revision 1.92 2003/01/09 21:52:38 peter
  2535. * merged some verbosity options.
  2536. * V_LineInfo is a verbosity flag to include line info
  2537. Revision 1.91 2003/01/08 18:43:57 daniel
  2538. * Tregister changed into a record
  2539. Revision 1.90 2003/01/03 12:15:56 daniel
  2540. * Removed ifdefs around notifications
  2541. ifdefs around for loop optimizations remain
  2542. Revision 1.89 2003/01/02 11:14:02 michael
  2543. + Patch from peter to support initial values for local variables
  2544. Revision 1.88 2003/01/01 22:51:03 peter
  2545. * high value insertion changed so it works also when 2 parameters
  2546. are passed
  2547. Revision 1.87 2002/12/31 09:55:58 daniel
  2548. + Notification implementation complete
  2549. + Add for loop code optimization using notifications
  2550. results in 1.5-1.9% speed improvement in nestloop benchmark
  2551. Optimization incomplete, compiler does not cycle yet with
  2552. notifications enabled.
  2553. Revision 1.86 2002/12/30 22:44:53 daniel
  2554. * Some work on notifications
  2555. Revision 1.85 2002/12/27 18:07:44 peter
  2556. * fix crashes when searching symbols
  2557. Revision 1.84 2002/12/20 16:02:22 peter
  2558. * fix stupid copy&paste bug in binary operator search
  2559. Revision 1.83 2002/12/16 22:08:31 peter
  2560. * fix order of procdefs in procsym, procdefs are now always appended
  2561. so that loading from a ppu will keep the same order. This is
  2562. important for the generation of VMTs
  2563. Revision 1.82 2002/12/11 22:39:23 peter
  2564. * better error message when no operator is found for equal
  2565. Revision 1.81 2002/12/07 14:27:10 carl
  2566. * 3% memory optimization
  2567. * changed some types
  2568. + added type checking with different size for call node and for
  2569. parameters
  2570. Revision 1.80 2002/12/06 17:51:11 peter
  2571. * merged cdecl and array fixes
  2572. Revision 1.79 2002/11/27 20:04:10 peter
  2573. * tvarsym.get_push_size replaced by paramanager.push_size
  2574. Revision 1.78 2002/11/27 02:34:20 peter
  2575. * only find real equal procvars
  2576. Revision 1.77 2002/11/25 18:43:34 carl
  2577. - removed the invalid if <> checking (Delphi is strange on this)
  2578. + implemented abstract warning on instance creation of class with
  2579. abstract methods.
  2580. * some error message cleanups
  2581. Revision 1.76 2002/11/25 17:43:26 peter
  2582. * splitted defbase in defutil,symutil,defcmp
  2583. * merged isconvertable and is_equal into compare_defs(_ext)
  2584. * made operator search faster by walking the list only once
  2585. Revision 1.75 2002/11/23 22:50:09 carl
  2586. * some small speed optimizations
  2587. + added several new warnings/hints
  2588. Revision 1.74 2002/11/22 22:48:11 carl
  2589. * memory optimization with tconstsym (1.5%)
  2590. Revision 1.73 2002/11/18 17:31:59 peter
  2591. * pass proccalloption to ret_in_xxx and push_xxx functions
  2592. Revision 1.72 2002/11/17 16:31:57 carl
  2593. * memory optimization (3-4%) : cleanup of tai fields,
  2594. cleanup of tdef and tsym fields.
  2595. * make it work for m68k
  2596. Revision 1.71 2002/11/09 15:30:07 carl
  2597. + align RTTI tables
  2598. Revision 1.70 2002/10/13 21:33:37 peter
  2599. * give correct fileposition for undefined forward procs
  2600. Revision 1.69 2002/10/05 12:43:29 carl
  2601. * fixes for Delphi 6 compilation
  2602. (warning : Some features do not work under Delphi)
  2603. Revision 1.68 2002/10/05 00:52:20 peter
  2604. * split boolean check in two lines for easier debugging
  2605. Revision 1.67 2002/09/26 12:04:53 florian
  2606. + constsym with type=constguid can be written to ppu now,
  2607. fixes web bug 1820
  2608. Revision 1.66 2002/09/16 14:11:13 peter
  2609. * add argument to equal_paras() to support default values or not
  2610. Revision 1.65 2002/09/09 17:34:16 peter
  2611. * tdicationary.replace added to replace and item in a dictionary. This
  2612. is only allowed for the same name
  2613. * varsyms are inserted in symtable before the types are parsed. This
  2614. fixes the long standing "var longint : longint" bug
  2615. - consume_idlist and idstringlist removed. The loops are inserted
  2616. at the callers place and uses the symtable for duplicate id checking
  2617. Revision 1.64 2002/09/08 11:10:17 carl
  2618. * bugfix 2109 (bad imho, but only way)
  2619. Revision 1.63 2002/09/07 18:17:41 florian
  2620. + tvarsym.paraitem added
  2621. Revision 1.62 2002/09/07 15:25:10 peter
  2622. * old logs removed and tabs fixed
  2623. Revision 1.61 2002/09/05 19:29:45 peter
  2624. * memdebug enhancements
  2625. Revision 1.60 2002/09/05 14:51:42 peter
  2626. * internalerror instead of crash in getprocdef
  2627. Revision 1.59 2002/09/03 16:26:27 daniel
  2628. * Make Tprocdef.defs protected
  2629. Revision 1.58 2002/09/01 08:01:16 daniel
  2630. * Removed sets from Tcallnode.det_resulttype
  2631. + Added read/write notifications of variables. These will be usefull
  2632. for providing information for several optimizations. For example
  2633. the value of the loop variable of a for loop does matter is the
  2634. variable is read after the for loop, but if it's no longer used
  2635. or written, it doesn't matter and this can be used to optimize
  2636. the loop code generation.
  2637. Revision 1.57 2002/08/25 19:25:21 peter
  2638. * sym.insert_in_data removed
  2639. * symtable.insertvardata/insertconstdata added
  2640. * removed insert_in_data call from symtable.insert, it needs to be
  2641. called separatly. This allows to deref the address calculation
  2642. * procedures now calculate the parast addresses after the procedure
  2643. directives are parsed. This fixes the cdecl parast problem
  2644. * push_addr_param has an extra argument that specifies if cdecl is used
  2645. or not
  2646. Revision 1.56 2002/08/25 09:06:21 peter
  2647. * fixed loop in concat_procdefs
  2648. Revision 1.55 2002/08/20 16:54:40 peter
  2649. * write address of varsym always
  2650. Revision 1.54 2002/08/20 10:31:26 daniel
  2651. * Tcallnode.det_resulttype rewritten
  2652. Revision 1.53 2002/08/18 20:06:27 peter
  2653. * inlining is now also allowed in interface
  2654. * renamed write/load to ppuwrite/ppuload
  2655. * tnode storing in ppu
  2656. * nld,ncon,nbas are already updated for storing in ppu
  2657. Revision 1.52 2002/08/17 09:23:42 florian
  2658. * first part of procinfo rewrite
  2659. Revision 1.51 2002/08/16 14:24:59 carl
  2660. * issameref() to test if two references are the same (then emit no opcodes)
  2661. + ret_in_reg to replace ret_in_acc
  2662. (fix some register allocation bugs at the same time)
  2663. + save_std_register now has an extra parameter which is the
  2664. usedinproc registers
  2665. Revision 1.50 2002/08/13 21:40:57 florian
  2666. * more fixes for ppc calling conventions
  2667. Revision 1.49 2002/08/12 15:08:40 carl
  2668. + stab register indexes for powerpc (moved from gdb to cpubase)
  2669. + tprocessor enumeration moved to cpuinfo
  2670. + linker in target_info is now a class
  2671. * many many updates for m68k (will soon start to compile)
  2672. - removed some ifdef or correct them for correct cpu
  2673. Revision 1.48 2002/08/11 14:32:28 peter
  2674. * renamed current_library to objectlibrary
  2675. Revision 1.47 2002/08/11 13:24:14 peter
  2676. * saving of asmsymbols in ppu supported
  2677. * asmsymbollist global is removed and moved into a new class
  2678. tasmlibrarydata that will hold the info of a .a file which
  2679. corresponds with a single module. Added librarydata to tmodule
  2680. to keep the library info stored for the module. In the future the
  2681. objectfiles will also be stored to the tasmlibrarydata class
  2682. * all getlabel/newasmsymbol and friends are moved to the new class
  2683. Revision 1.46 2002/07/23 10:13:23 daniel
  2684. * Added important comment
  2685. Revision 1.45 2002/07/23 09:51:26 daniel
  2686. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2687. are worth comitting.
  2688. Revision 1.44 2002/07/20 17:45:29 daniel
  2689. * Register variables are now possible for global variables too. This is
  2690. important for small programs without procedures.
  2691. Revision 1.43 2002/07/20 11:57:58 florian
  2692. * types.pas renamed to defbase.pas because D6 contains a types
  2693. unit so this would conflicts if D6 programms are compiled
  2694. + Willamette/SSE2 instructions to assembler added
  2695. Revision 1.42 2002/07/11 14:41:31 florian
  2696. * start of the new generic parameter handling
  2697. }