pexports.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. { common }
  26. cutils,
  27. { global }
  28. globals,tokens,verbose,
  29. systems,
  30. { symtable }
  31. symconst,symdef,symsym,symtable,
  32. { pass 1 }
  33. node,pass_1,
  34. ncon,
  35. { parser }
  36. scanner,
  37. pbase,pexpr,
  38. { link }
  39. gendef,export
  40. ;
  41. procedure read_exports;
  42. var
  43. hp : pexported_item;
  44. DefString : string;
  45. ProcName : string;
  46. InternalProcName : string;
  47. pt : tnode;
  48. begin
  49. DefString:='';
  50. InternalProcName:='';
  51. consume(_EXPORTS);
  52. while true do
  53. begin
  54. hp:=new(pexported_item,init);
  55. if token=_ID then
  56. begin
  57. getsym(pattern,true);
  58. if srsym^.typ=unitsym then
  59. begin
  60. consume(_ID);
  61. consume(_POINT);
  62. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  63. end;
  64. consume(_ID);
  65. if assigned(srsym) then
  66. begin
  67. hp^.sym:=srsym;
  68. if ((hp^.sym^.typ<>procsym) or
  69. ((tf_need_export in target_info.flags) and
  70. not(po_exports in pprocdef(pprocsym(srsym)^.definition)^.procoptions)
  71. )
  72. ) and
  73. (srsym^.typ<>varsym) and (srsym^.typ<>typedconstsym) then
  74. Message(parser_e_illegal_symbol_exported)
  75. else
  76. begin
  77. ProcName:=hp^.sym^.name;
  78. InternalProcName:=hp^.sym^.mangledname;
  79. { This is wrong if the first is not
  80. an underline }
  81. if InternalProcName[1]='_' then
  82. delete(InternalProcName,1,1)
  83. else if (target_os.id=os_i386_win32) and UseDeffileForExport then
  84. begin
  85. Message(parser_e_dlltool_unit_var_problem);
  86. Message(parser_e_dlltool_unit_var_problem2);
  87. end;
  88. if length(InternalProcName)<2 then
  89. Message(parser_e_procname_to_short_for_export);
  90. DefString:=ProcName+'='+InternalProcName;
  91. end;
  92. if (idtoken=_INDEX) then
  93. begin
  94. consume(_INDEX);
  95. pt:=comp_expr(true);
  96. do_firstpass(pt);
  97. if pt.nodetype=ordconstn then
  98. hp^.index:=tordconstnode(pt).value
  99. else
  100. begin
  101. hp^.index:=0;
  102. consume(_INTCONST);
  103. end;
  104. hp^.options:=hp^.options or eo_index;
  105. pt.free;
  106. if target_os.id=os_i386_win32 then
  107. DefString:=ProcName+'='+InternalProcName+' @ '+tostr(hp^.index)
  108. else
  109. DefString:=ProcName+'='+InternalProcName; {Index ignored!}
  110. end;
  111. if (idtoken=_NAME) then
  112. begin
  113. consume(_NAME);
  114. pt:=comp_expr(true);
  115. do_firstpass(pt);
  116. if pt.nodetype=stringconstn then
  117. hp^.name:=stringdup(strpas(tstringconstnode(pt).value_str))
  118. else
  119. begin
  120. hp^.name:=stringdup('');
  121. consume(_CSTRING);
  122. end;
  123. hp^.options:=hp^.options or eo_name;
  124. pt.free;
  125. DefString:=hp^.name^+'='+InternalProcName;
  126. end;
  127. if (idtoken=_RESIDENT) then
  128. begin
  129. consume(_RESIDENT);
  130. hp^.options:=hp^.options or eo_resident;
  131. DefString:=ProcName+'='+InternalProcName;{Resident ignored!}
  132. end;
  133. if (DefString<>'') and UseDeffileForExport then
  134. DefFile.AddExport(DefString);
  135. if hp^.sym^.typ=procsym then
  136. exportlib^.exportprocedure(hp)
  137. else
  138. exportlib^.exportvar(hp);
  139. end;
  140. end
  141. else
  142. consume(_ID);
  143. if token=_COMMA then
  144. consume(_COMMA)
  145. else
  146. break;
  147. end;
  148. consume(_SEMICOLON);
  149. if not DefFile.empty then
  150. DefFile.writefile;
  151. end;
  152. end.
  153. {
  154. $Log$
  155. Revision 1.8 2000-11-29 00:30:36 florian
  156. * unused units removed from uses clause
  157. * some changes for widestrings
  158. Revision 1.7 2000/10/31 22:02:49 peter
  159. * symtable splitted, no real code changes
  160. Revision 1.6 2000/10/14 10:14:51 peter
  161. * moehrendorf oct 2000 rewrite
  162. Revision 1.5 2000/09/24 21:19:50 peter
  163. * delphi compile fixes
  164. Revision 1.4 2000/09/24 15:06:21 peter
  165. * use defines.inc
  166. Revision 1.3 2000/08/27 16:11:51 peter
  167. * moved some util functions from globals,cobjects to cutils
  168. * splitted files into finput,fmodule
  169. Revision 1.2 2000/07/13 11:32:44 michael
  170. + removed logs
  171. }