symutil.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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,cclasses;
  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. procedure count_locals(p:tnamedindexitem;arg:pointer);
  28. implementation
  29. uses
  30. globtype,
  31. cpuinfo,
  32. procinfo,
  33. symconst;
  34. function is_funcret_sym(p:tsymentry):boolean;
  35. begin
  36. is_funcret_sym:=(p.typ in [absolutesym,varsym]) and
  37. (vo_is_funcret in tvarsym(p).varoptions);
  38. end;
  39. function needs_prop_entry(sym : tsym) : boolean;
  40. begin
  41. needs_prop_entry:=(sp_published in tsym(sym).symoptions) and
  42. (sym.typ in [propertysym,varsym]);
  43. end;
  44. function equal_constsym(sym1,sym2:tconstsym):boolean;
  45. var
  46. p1,p2,pend : pchar;
  47. begin
  48. equal_constsym:=false;
  49. if sym1.consttyp<>sym2.consttyp then
  50. exit;
  51. case sym1.consttyp of
  52. constord :
  53. equal_constsym:=(sym1.value.valueord=sym2.value.valueord);
  54. constpointer :
  55. equal_constsym:=(sym1.value.valueordptr=sym2.value.valueordptr);
  56. conststring,constresourcestring :
  57. begin
  58. if sym1.value.len=sym2.value.len then
  59. begin
  60. p1:=pchar(sym1.value.valueptr);
  61. p2:=pchar(sym2.value.valueptr);
  62. pend:=p1+sym1.value.len;
  63. while (p1<pend) do
  64. begin
  65. if p1^<>p2^ then
  66. break;
  67. inc(p1);
  68. inc(p2);
  69. end;
  70. if (p1=pend) then
  71. equal_constsym:=true;
  72. end;
  73. end;
  74. constreal :
  75. equal_constsym:=(pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^);
  76. constset :
  77. equal_constsym:=(pnormalset(sym1.value.valueptr)^=pnormalset(sym2.value.valueptr)^);
  78. constnil :
  79. equal_constsym:=true;
  80. end;
  81. end;
  82. procedure count_locals(p:tnamedindexitem;arg:pointer);
  83. begin
  84. { Count only varsyms, but ignore the funcretsym }
  85. if (tsym(p).typ=varsym) and
  86. (tsym(p)<>current_procinfo.procdef.funcretsym) and
  87. (not(vo_is_parentfp in tvarsym(p).varoptions) or
  88. (tvarsym(p).refs>0)) then
  89. inc(plongint(arg)^);
  90. end;
  91. end.
  92. {
  93. $Log$
  94. Revision 1.4 2004-03-23 22:34:50 peter
  95. * constants ordinals now always have a type assigned
  96. * integer constants have the smallest type, unsigned prefered over
  97. signed
  98. Revision 1.3 2003/12/07 16:40:45 jonas
  99. * moved count_locals from pstatmnt to symutils
  100. * use count_locals in powerpc/cpupi to check whether we should set the
  101. first temp offset (and as such generate a stackframe)
  102. Revision 1.2 2003/04/25 20:59:35 peter
  103. * removed funcretn,funcretsym, function result is now in varsym
  104. and aliases for result and function name are added using absolutesym
  105. * vs_hidden parameter for funcret passed in parameter
  106. * vs_hidden fixes
  107. * writenode changed to printnode and released from extdebug
  108. * -vp option added to generate a tree.log with the nodetree
  109. * nicer printnode for statements, callnode
  110. Revision 1.1 2002/11/25 17:43:26 peter
  111. * splitted defbase in defutil,symutil,defcmp
  112. * merged isconvertable and is_equal into compare_defs(_ext)
  113. * made operator search faster by walking the list only once
  114. }