symutil.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. symbase,symtype,symsym;
  23. function is_funcret_sym(p:tsymentry):boolean;
  24. { returns true, if sym needs an entry in the proplist of a class rtti }
  25. function needs_prop_entry(sym : tsym) : boolean;
  26. function equal_constsym(sym1,sym2:tconstsym):boolean;
  27. implementation
  28. uses
  29. globtype,
  30. cpuinfo,
  31. symconst;
  32. function is_funcret_sym(p:tsymentry):boolean;
  33. begin
  34. is_funcret_sym:=(p.typ in [absolutesym,varsym]) and
  35. (vo_is_funcret in tvarsym(p).varoptions);
  36. end;
  37. function needs_prop_entry(sym : tsym) : boolean;
  38. begin
  39. needs_prop_entry:=(sp_published in tsym(sym).symoptions) and
  40. (sym.typ in [propertysym,varsym]);
  41. end;
  42. function equal_constsym(sym1,sym2:tconstsym):boolean;
  43. var
  44. p1,p2,pend : pchar;
  45. begin
  46. equal_constsym:=false;
  47. if sym1.consttyp<>sym2.consttyp then
  48. exit;
  49. case sym1.consttyp of
  50. constint,
  51. constbool,
  52. constchar,
  53. constord :
  54. equal_constsym:=(sym1.value.valueord=sym2.value.valueord);
  55. constpointer :
  56. equal_constsym:=(sym1.value.valueordptr=sym2.value.valueordptr);
  57. conststring,constresourcestring :
  58. begin
  59. if sym1.value.len=sym2.value.len then
  60. begin
  61. p1:=pchar(sym1.value.valueptr);
  62. p2:=pchar(sym2.value.valueptr);
  63. pend:=p1+sym1.value.len;
  64. while (p1<pend) do
  65. begin
  66. if p1^<>p2^ then
  67. break;
  68. inc(p1);
  69. inc(p2);
  70. end;
  71. if (p1=pend) then
  72. equal_constsym:=true;
  73. end;
  74. end;
  75. constreal :
  76. equal_constsym:=(pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^);
  77. constset :
  78. equal_constsym:=(pnormalset(sym1.value.valueptr)^=pnormalset(sym2.value.valueptr)^);
  79. constnil :
  80. equal_constsym:=true;
  81. end;
  82. end;
  83. end.
  84. {
  85. $Log$
  86. Revision 1.2 2003-04-25 20:59:35 peter
  87. * removed funcretn,funcretsym, function result is now in varsym
  88. and aliases for result and function name are added using absolutesym
  89. * vs_hidden parameter for funcret passed in parameter
  90. * vs_hidden fixes
  91. * writenode changed to printnode and released from extdebug
  92. * -vp option added to generate a tree.log with the nodetree
  93. * nicer printnode for statements, callnode
  94. Revision 1.1 2002/11/25 17:43:26 peter
  95. * splitted defbase in defutil,symutil,defcmp
  96. * merged isconvertable and is_equal into compare_defs(_ext)
  97. * made operator search faster by walking the list only once
  98. }