symutil.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit provides some help routines for symbol handling
  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 symutil;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. cpuinfo,
  24. globals,
  25. node,
  26. symconst,symbase,symtype,symdef,symsym;
  27. function equal_constsym(sym1,sym2:tconstsym):boolean;
  28. { returns true, if sym needs an entry in the proplist of a class rtti }
  29. function needs_prop_entry(sym : tsym) : boolean;
  30. implementation
  31. uses
  32. globtype,tokens,systems,verbose,
  33. symtable;
  34. function needs_prop_entry(sym : tsym) : boolean;
  35. begin
  36. needs_prop_entry:=(sp_published in tsym(sym).symoptions) and
  37. (sym.typ in [propertysym,varsym]);
  38. end;
  39. function equal_constsym(sym1,sym2:tconstsym):boolean;
  40. var
  41. p1,p2,pend : pchar;
  42. begin
  43. equal_constsym:=false;
  44. if sym1.consttyp<>sym2.consttyp then
  45. exit;
  46. case sym1.consttyp of
  47. constint,
  48. constbool,
  49. constchar,
  50. constord :
  51. equal_constsym:=(sym1.value.valueord=sym2.value.valueord);
  52. constpointer :
  53. equal_constsym:=(sym1.value.valueordptr=sym2.value.valueordptr);
  54. conststring,constresourcestring :
  55. begin
  56. if sym1.value.len=sym2.value.len then
  57. begin
  58. p1:=pchar(sym1.value.valueptr);
  59. p2:=pchar(sym2.value.valueptr);
  60. pend:=p1+sym1.value.len;
  61. while (p1<pend) do
  62. begin
  63. if p1^<>p2^ then
  64. break;
  65. inc(p1);
  66. inc(p2);
  67. end;
  68. if (p1=pend) then
  69. equal_constsym:=true;
  70. end;
  71. end;
  72. constreal :
  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.
  81. {
  82. $Log$
  83. Revision 1.1 2002-11-25 17:43:26 peter
  84. * splitted defbase in defutil,symutil,defcmp
  85. * merged isconvertable and is_equal into compare_defs(_ext)
  86. * made operator search faster by walking the list only once
  87. }