symutil.pas 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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;
  22. function is_funcret_sym(p:TSymEntry):boolean;
  23. function equal_constsym(sym1,sym2:tconstsym):boolean;
  24. implementation
  25. uses
  26. cclasses,
  27. globtype,cpuinfo,procinfo,
  28. symconst,widestr;
  29. function is_funcret_sym(p:TSymEntry):boolean;
  30. begin
  31. is_funcret_sym:=(p.typ in [absolutevarsym,localvarsym,paravarsym]) and
  32. (vo_is_funcret in tabstractvarsym(p).varoptions);
  33. end;
  34. function equal_constsym(sym1,sym2:tconstsym):boolean;
  35. var
  36. p1,p2,pend : pchar;
  37. begin
  38. equal_constsym:=false;
  39. if sym1.consttyp<>sym2.consttyp then
  40. exit;
  41. case sym1.consttyp of
  42. constord :
  43. equal_constsym:=(sym1.value.valueord=sym2.value.valueord);
  44. constpointer :
  45. equal_constsym:=(sym1.value.valueordptr=sym2.value.valueordptr);
  46. conststring,constresourcestring :
  47. begin
  48. if sym1.value.len=sym2.value.len then
  49. begin
  50. p1:=pchar(sym1.value.valueptr);
  51. p2:=pchar(sym2.value.valueptr);
  52. pend:=p1+sym1.value.len;
  53. while (p1<pend) do
  54. begin
  55. if p1^<>p2^ then
  56. break;
  57. inc(p1);
  58. inc(p2);
  59. end;
  60. if (p1=pend) then
  61. equal_constsym:=true;
  62. end;
  63. end;
  64. constwstring :
  65. begin
  66. if (sym1.value.len=sym2.value.len) and
  67. (comparewidestrings(sym1.value.valueptr,sym2.value.valueptr)=0) then
  68. equal_constsym:=true;
  69. end;
  70. constreal :
  71. equal_constsym:=(pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^);
  72. constset :
  73. equal_constsym:=(pnormalset(sym1.value.valueptr)^=pnormalset(sym2.value.valueptr)^);
  74. constnil :
  75. equal_constsym:=true;
  76. end;
  77. end;
  78. end.