symutil.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. constint,
  53. constbool,
  54. constchar,
  55. constord :
  56. equal_constsym:=(sym1.value.valueord=sym2.value.valueord);
  57. constpointer :
  58. equal_constsym:=(sym1.value.valueordptr=sym2.value.valueordptr);
  59. conststring,constresourcestring :
  60. begin
  61. if sym1.value.len=sym2.value.len then
  62. begin
  63. p1:=pchar(sym1.value.valueptr);
  64. p2:=pchar(sym2.value.valueptr);
  65. pend:=p1+sym1.value.len;
  66. while (p1<pend) do
  67. begin
  68. if p1^<>p2^ then
  69. break;
  70. inc(p1);
  71. inc(p2);
  72. end;
  73. if (p1=pend) then
  74. equal_constsym:=true;
  75. end;
  76. end;
  77. constreal :
  78. equal_constsym:=(pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^);
  79. constset :
  80. equal_constsym:=(pnormalset(sym1.value.valueptr)^=pnormalset(sym2.value.valueptr)^);
  81. constnil :
  82. equal_constsym:=true;
  83. end;
  84. end;
  85. procedure count_locals(p:tnamedindexitem;arg:pointer);
  86. begin
  87. { Count only varsyms, but ignore the funcretsym }
  88. if (tsym(p).typ=varsym) and
  89. (tsym(p)<>current_procinfo.procdef.funcretsym) and
  90. (not(vo_is_parentfp in tvarsym(p).varoptions) or
  91. (tvarsym(p).refs>0)) then
  92. inc(plongint(arg)^);
  93. end;
  94. end.
  95. {
  96. $Log$
  97. Revision 1.3 2003-12-07 16:40:45 jonas
  98. * moved count_locals from pstatmnt to symutils
  99. * use count_locals in powerpc/cpupi to check whether we should set the
  100. first temp offset (and as such generate a stackframe)
  101. Revision 1.2 2003/04/25 20:59:35 peter
  102. * removed funcretn,funcretsym, function result is now in varsym
  103. and aliases for result and function name are added using absolutesym
  104. * vs_hidden parameter for funcret passed in parameter
  105. * vs_hidden fixes
  106. * writenode changed to printnode and released from extdebug
  107. * -vp option added to generate a tree.log with the nodetree
  108. * nicer printnode for statements, callnode
  109. Revision 1.1 2002/11/25 17:43:26 peter
  110. * splitted defbase in defutil,symutil,defcmp
  111. * merged isconvertable and is_equal into compare_defs(_ext)
  112. * made operator search faster by walking the list only once
  113. }