symutil.pas 3.1 KB

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