symutil.pas 4.5 KB

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