symutil.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit provides some help routines for symbol handling
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit symutil;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symbase,symtype,symsym,cclasses;
  22. function is_funcret_sym(p:tsymentry):boolean;
  23. { returns true, if sym needs an entry in the proplist of a class rtti }
  24. function needs_prop_entry(sym : tsym) : boolean;
  25. function equal_constsym(sym1,sym2:tconstsym):boolean;
  26. procedure count_locals(p:tnamedindexitem;arg:pointer);
  27. implementation
  28. uses
  29. globtype,cpuinfo,procinfo,
  30. symconst,widestr;
  31. function is_funcret_sym(p:tsymentry):boolean;
  32. begin
  33. is_funcret_sym:=(p.typ in [absolutevarsym,localvarsym,paravarsym]) and
  34. (vo_is_funcret in tabstractvarsym(p).varoptions);
  35. end;
  36. function needs_prop_entry(sym : tsym) : boolean;
  37. begin
  38. needs_prop_entry:=(sp_published in tsym(sym).symoptions) and
  39. (sym.typ in [propertysym,fieldvarsym]);
  40. end;
  41. function equal_constsym(sym1,sym2:tconstsym):boolean;
  42. var
  43. p1,p2,pend : pchar;
  44. begin
  45. equal_constsym:=false;
  46. if sym1.consttyp<>sym2.consttyp then
  47. exit;
  48. case sym1.consttyp of
  49. constord :
  50. equal_constsym:=(sym1.value.valueord=sym2.value.valueord);
  51. constpointer :
  52. equal_constsym:=(sym1.value.valueordptr=sym2.value.valueordptr);
  53. conststring,constresourcestring :
  54. begin
  55. if sym1.value.len=sym2.value.len then
  56. begin
  57. p1:=pchar(sym1.value.valueptr);
  58. p2:=pchar(sym2.value.valueptr);
  59. pend:=p1+sym1.value.len;
  60. while (p1<pend) do
  61. begin
  62. if p1^<>p2^ then
  63. break;
  64. inc(p1);
  65. inc(p2);
  66. end;
  67. if (p1=pend) then
  68. equal_constsym:=true;
  69. end;
  70. end;
  71. constwstring :
  72. begin
  73. if (sym1.value.len=sym2.value.len) and
  74. (comparewidestrings(sym1.value.valueptr,sym2.value.valueptr)=0) then
  75. equal_constsym:=true;
  76. end;
  77. constreal :
  78. equal_constsym:=(pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^);
  79. constset :
  80. equal_constsym:=(pnormalset(sym1.value.valueptr)^=pnormalset(sym2.value.valueptr)^);
  81. constnil :
  82. equal_constsym:=true;
  83. end;
  84. end;
  85. procedure count_locals(p:tnamedindexitem;arg:pointer);
  86. begin
  87. { Count only varsyms, but ignore the funcretsym }
  88. if (tsym(p).typ in [localvarsym,paravarsym]) and
  89. (tsym(p)<>current_procinfo.procdef.funcretsym) and
  90. (not(vo_is_parentfp in tabstractvarsym(p).varoptions) or
  91. (tstoredsym(p).refs>0)) then
  92. inc(plongint(arg)^);
  93. end;
  94. end.