pexports.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit handles the exports parsing
  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 pexports;
  19. {$i defines.inc}
  20. interface
  21. { reads an exports statement in a library }
  22. procedure read_exports;
  23. implementation
  24. uses
  25. globtype,systems,tokens,
  26. strings,cutils,cobjects,globals,verbose,
  27. scanner,symconst,symtable,pbase,
  28. export,GenDef,tree,pass_1,pexpr;
  29. procedure read_exports;
  30. var
  31. hp : pexported_item;
  32. DefString:string;
  33. ProcName:string;
  34. InternalProcName:string;
  35. pt : ptree;
  36. begin
  37. DefString:='';
  38. InternalProcName:='';
  39. consume(_EXPORTS);
  40. while true do
  41. begin
  42. hp:=new(pexported_item,init);
  43. if token=_ID then
  44. begin
  45. getsym(pattern,true);
  46. if srsym^.typ=unitsym then
  47. begin
  48. consume(_ID);
  49. consume(_POINT);
  50. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  51. end;
  52. consume(_ID);
  53. if assigned(srsym) then
  54. begin
  55. hp^.sym:=srsym;
  56. if ((hp^.sym^.typ<>procsym) or
  57. ((tf_need_export in target_info.flags) and
  58. not(po_exports in pprocdef(pprocsym(srsym)^.definition)^.procoptions)
  59. )
  60. ) and
  61. (srsym^.typ<>varsym) and (srsym^.typ<>typedconstsym) then
  62. Message(parser_e_illegal_symbol_exported)
  63. else
  64. begin
  65. ProcName:=hp^.sym^.name;
  66. InternalProcName:=hp^.sym^.mangledname;
  67. { This is wrong if the first is not
  68. an underline }
  69. if InternalProcName[1]='_' then
  70. delete(InternalProcName,1,1)
  71. else if (target_os.id=os_i386_win32) and UseDeffileForExport then
  72. begin
  73. Message(parser_e_dlltool_unit_var_problem);
  74. Message(parser_e_dlltool_unit_var_problem2);
  75. end;
  76. if length(InternalProcName)<2 then
  77. Message(parser_e_procname_to_short_for_export);
  78. DefString:=ProcName+'='+InternalProcName;
  79. end;
  80. if (idtoken=_INDEX) then
  81. begin
  82. consume(_INDEX);
  83. pt:=comp_expr(true);
  84. do_firstpass(pt);
  85. if pt^.treetype=ordconstn then
  86. hp^.index:=pt^.value
  87. else
  88. begin
  89. hp^.index:=0;
  90. consume(_INTCONST);
  91. end;
  92. hp^.options:=hp^.options or eo_index;
  93. disposetree(pt);
  94. if target_os.id=os_i386_win32 then
  95. DefString:=ProcName+'='+InternalProcName+' @ '+tostr(hp^.index)
  96. else
  97. DefString:=ProcName+'='+InternalProcName; {Index ignored!}
  98. end;
  99. if (idtoken=_NAME) then
  100. begin
  101. consume(_NAME);
  102. pt:=comp_expr(true);
  103. do_firstpass(pt);
  104. if pt^.treetype=stringconstn then
  105. hp^.name:=stringdup(strpas(pt^.value_str))
  106. else
  107. begin
  108. hp^.name:=stringdup('');
  109. consume(_CSTRING);
  110. end;
  111. hp^.options:=hp^.options or eo_name;
  112. disposetree(pt);
  113. DefString:=hp^.name^+'='+InternalProcName;
  114. end;
  115. if (idtoken=_RESIDENT) then
  116. begin
  117. consume(_RESIDENT);
  118. hp^.options:=hp^.options or eo_resident;
  119. DefString:=ProcName+'='+InternalProcName;{Resident ignored!}
  120. end;
  121. if (DefString<>'') and UseDeffileForExport then
  122. DefFile.AddExport(DefString);
  123. if hp^.sym^.typ=procsym then
  124. exportlib^.exportprocedure(hp)
  125. else
  126. exportlib^.exportvar(hp);
  127. end;
  128. end
  129. else
  130. consume(_ID);
  131. if token=_COMMA then
  132. consume(_COMMA)
  133. else
  134. break;
  135. end;
  136. consume(_SEMICOLON);
  137. if not DefFile.empty then
  138. DefFile.writefile;
  139. end;
  140. end.
  141. {
  142. $Log$
  143. Revision 1.4 2000-09-24 15:06:21 peter
  144. * use defines.inc
  145. Revision 1.3 2000/08/27 16:11:51 peter
  146. * moved some util functions from globals,cobjects to cutils
  147. * splitted files into finput,fmodule
  148. Revision 1.2 2000/07/13 11:32:44 michael
  149. + removed logs
  150. }