symutil.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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(var 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 (sym1.value.len=sym2.value.len) and
  71. (comparewidestrings(sym1.value.valueptr,sym2.value.valueptr)=0) then
  72. equal_constsym:=true;
  73. end;
  74. constreal :
  75. if nanequal then
  76. equal_constsym:=CompareByte(pbestreal(sym1.value.valueptr)^,pbestreal(sym2.value.valueptr)^,sizeof(pbestreal^))=0
  77. else
  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. else
  84. ;
  85. end;
  86. end;
  87. { get_first_proc_str - returns the token string of the first option that
  88. appears in the list }
  89. function get_first_proc_str(Options: TProcOptions): ShortString;
  90. var
  91. X: TProcOption;
  92. begin
  93. if Options = [] then
  94. InternalError(2018051700);
  95. get_first_proc_str := '';
  96. for X in Options do
  97. begin
  98. get_first_proc_str := ProcOptionKeywords[X];
  99. Exit;
  100. end;
  101. end;
  102. procedure maybe_guarantee_record_typesym(var def: tdef; st: tsymtable);
  103. var
  104. ts: ttypesym;
  105. begin
  106. { create a dummy typesym for the JVM target, because the record
  107. has to be wrapped by a class }
  108. if (target_info.system in systems_jvm) and
  109. (def.typ=recorddef) and
  110. not assigned(def.typesym) then
  111. begin
  112. ts:=ctypesym.create(trecorddef(def).symtable.realname^,def);
  113. st.insert(ts);
  114. ts.visibility:=vis_strictprivate;
  115. { this typesym can't be used by any Pascal code, so make sure we don't
  116. print a hint about it being unused }
  117. include(ts.symoptions,sp_internal);
  118. end;
  119. end;
  120. function is_normal_fieldvarsym(sym: tsym): boolean; inline;
  121. begin
  122. result:=
  123. (sym.typ=fieldvarsym) and
  124. not(sp_static in sym.symoptions);
  125. end;
  126. end.