symutil.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. symconst,symbase,symtype,symsym;
  22. function is_funcret_sym(p:TSymEntry):boolean;
  23. function equal_constsym(sym1,sym2:tconstsym; nanequal: boolean):boolean;
  24. function get_first_proc_str(Options: TProcOptions): ShortString;
  25. procedure maybe_guarantee_record_typesym(def: tdef; st: tsymtable);
  26. function is_normal_fieldvarsym(sym: tsym): boolean; inline;
  27. implementation
  28. uses
  29. systems,
  30. globtype,cpuinfo,constexp,verbose,
  31. widestr,
  32. symdef;
  33. function is_funcret_sym(p:TSymEntry):boolean;
  34. begin
  35. is_funcret_sym:=(p.typ in [absolutevarsym,localvarsym,paravarsym]) and
  36. (vo_is_funcret in tabstractvarsym(p).varoptions);
  37. end;
  38. function equal_constsym(sym1,sym2:tconstsym; nanequal: boolean):boolean;
  39. var
  40. p1,p2,pend : pchar;
  41. begin
  42. equal_constsym:=false;
  43. if sym1.consttyp<>sym2.consttyp then
  44. exit;
  45. case sym1.consttyp of
  46. constord :
  47. equal_constsym:=(sym1.value.valueord=sym2.value.valueord);
  48. constpointer :
  49. equal_constsym:=(sym1.value.valueordptr=sym2.value.valueordptr);
  50. conststring,constresourcestring :
  51. begin
  52. if sym1.value.len=sym2.value.len then
  53. begin
  54. p1:=pchar(sym1.value.valueptr);
  55. p2:=pchar(sym2.value.valueptr);
  56. pend:=p1+sym1.value.len;
  57. while (p1<pend) do
  58. begin
  59. if p1^<>p2^ then
  60. break;
  61. inc(p1);
  62. inc(p2);
  63. end;
  64. if (p1=pend) then
  65. equal_constsym:=true;
  66. end;
  67. end;
  68. constwstring :
  69. begin
  70. if (comparewidestrings(sym1.value.valuews,sym2.value.valuews)=0) then
  71. equal_constsym:=true;
  72. end;
  73. constreal :
  74. if nanequal then
  75. equal_constsym:=CompareByte(pbestreal(sym1.value.valueptr)^,pbestreal(sym2.value.valueptr)^,sizeof(pbestreal^))=0
  76. else
  77. equal_constsym:=pbestreal(sym1.value.valueptr)^=pbestreal(sym2.value.valueptr)^;
  78. constset :
  79. equal_constsym:=(pnormalset(sym1.value.valueptr)^=pnormalset(sym2.value.valueptr)^);
  80. constnil :
  81. equal_constsym:=true;
  82. else
  83. ;
  84. end;
  85. end;
  86. { get_first_proc_str - returns the token string of the first option that
  87. appears in the list }
  88. function get_first_proc_str(Options: TProcOptions): ShortString;
  89. var
  90. X: TProcOption;
  91. begin
  92. if Options = [] then
  93. InternalError(2018051700);
  94. get_first_proc_str := '';
  95. for X in Options do
  96. begin
  97. get_first_proc_str := ProcOptionKeywords[X];
  98. Exit;
  99. end;
  100. end;
  101. procedure maybe_guarantee_record_typesym(def: tdef; st: tsymtable);
  102. var
  103. ts: ttypesym;
  104. begin
  105. { create a dummy typesym for the JVM target, because the record
  106. has to be wrapped by a class }
  107. if (target_info.system in systems_jvm) and
  108. (def.typ=recorddef) and
  109. not assigned(def.typesym) then
  110. begin
  111. ts:=ctypesym.create(trecorddef(def).symtable.realname^,def);
  112. st.insertsym(ts);
  113. ts.visibility:=vis_strictprivate;
  114. { this typesym can't be used by any Pascal code, so make sure we don't
  115. print a hint about it being unused }
  116. include(ts.symoptions,sp_internal);
  117. end;
  118. end;
  119. function is_normal_fieldvarsym(sym: tsym): boolean; inline;
  120. begin
  121. result:=
  122. (sym.typ=fieldvarsym) and
  123. not(sp_static in sym.symoptions);
  124. end;
  125. end.