pexports.pas 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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,symbase,symtype,symdef,symsym,
  32. { pass 1 }
  33. node,
  34. ncon,
  35. { parser }
  36. scanner,
  37. pbase,pexpr,
  38. { link }
  39. gendef,export
  40. ;
  41. procedure read_exports;
  42. var
  43. hp : texported_item;
  44. orgs,
  45. DefString : string;
  46. InternalProcName : string;
  47. pt : tnode;
  48. srsym : tsym;
  49. srsymtable : tsymtable;
  50. begin
  51. DefString:='';
  52. InternalProcName:='';
  53. consume(_EXPORTS);
  54. while true do
  55. begin
  56. hp:=texported_item.create;
  57. if token=_ID then
  58. begin
  59. orgs:=orgpattern;
  60. consume_sym(srsym,srsymtable);
  61. hp.sym:=srsym;
  62. if ((hp.sym.typ<>procsym) or
  63. ((tf_need_export in target_info.flags) and
  64. not(po_exports in tprocdef(tprocsym(srsym).definition).procoptions)
  65. )
  66. ) and
  67. (srsym.typ<>varsym) and (srsym.typ<>typedconstsym) then
  68. Message(parser_e_illegal_symbol_exported)
  69. else
  70. begin
  71. InternalProcName:=srsym.mangledname;
  72. { This is wrong if the first is not
  73. an underline }
  74. if InternalProcName[1]='_' then
  75. delete(InternalProcName,1,1)
  76. else if (target_info.target=target_i386_win32) and UseDeffileForExport then
  77. begin
  78. Message(parser_e_dlltool_unit_var_problem);
  79. Message(parser_e_dlltool_unit_var_problem2);
  80. end;
  81. if length(InternalProcName)<2 then
  82. Message(parser_e_procname_to_short_for_export);
  83. DefString:=srsym.realname+'='+InternalProcName;
  84. end;
  85. if (idtoken=_INDEX) then
  86. begin
  87. consume(_INDEX);
  88. pt:=comp_expr(true);
  89. if pt.nodetype=ordconstn then
  90. hp.index:=tordconstnode(pt).value
  91. else
  92. begin
  93. hp.index:=0;
  94. consume(_INTCONST);
  95. end;
  96. hp.options:=hp.options or eo_index;
  97. pt.free;
  98. if target_info.target=target_i386_win32 then
  99. DefString:=srsym.realname+'='+InternalProcName+' @ '+tostr(hp.index)
  100. else
  101. DefString:=srsym.realname+'='+InternalProcName; {Index ignored!}
  102. end;
  103. if (idtoken=_NAME) then
  104. begin
  105. consume(_NAME);
  106. pt:=comp_expr(true);
  107. if pt.nodetype=stringconstn then
  108. hp.name:=stringdup(strpas(tstringconstnode(pt).value_str))
  109. else
  110. begin
  111. hp.name:=stringdup('');
  112. consume(_CSTRING);
  113. end;
  114. hp.options:=hp.options or eo_name;
  115. pt.free;
  116. DefString:=hp.name^+'='+InternalProcName;
  117. end;
  118. if (idtoken=_RESIDENT) then
  119. begin
  120. consume(_RESIDENT);
  121. hp.options:=hp.options or eo_resident;
  122. DefString:=srsym.realname+'='+InternalProcName;{Resident ignored!}
  123. end;
  124. if (DefString<>'') and UseDeffileForExport then
  125. DefFile.AddExport(DefString);
  126. { Default to generate a name entry with the provided name }
  127. if not assigned(hp.name) then
  128. begin
  129. hp.name:=stringdup(orgs);
  130. hp.options:=hp.options or eo_name;
  131. end;
  132. if hp.sym.typ=procsym then
  133. exportlib.exportprocedure(hp)
  134. else
  135. exportlib.exportvar(hp);
  136. end
  137. else
  138. consume(_ID);
  139. if token=_COMMA then
  140. consume(_COMMA)
  141. else
  142. break;
  143. end;
  144. consume(_SEMICOLON);
  145. if not DefFile.empty then
  146. DefFile.writefile;
  147. end;
  148. end.
  149. {
  150. $Log$
  151. Revision 1.15 2001-04-18 22:01:57 peter
  152. * registration of targets and assemblers
  153. Revision 1.14 2001/04/13 01:22:12 peter
  154. * symtable change to classes
  155. * range check generation and errors fixed, make cycle DEBUG=1 works
  156. * memory leaks fixed
  157. Revision 1.13 2001/04/04 22:43:52 peter
  158. * remove unnecessary calls to firstpass
  159. Revision 1.12 2001/03/11 22:58:50 peter
  160. * getsym redesign, removed the globals srsym,srsymtable
  161. Revision 1.11 2001/01/03 13:12:50 jonas
  162. * fixed copy/past bugs
  163. Revision 1.10 2000/12/30 22:53:25 peter
  164. * export with the case provided in the exports section
  165. Revision 1.9 2000/12/25 00:07:27 peter
  166. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  167. tlinkedlist objects)
  168. Revision 1.8 2000/11/29 00:30:36 florian
  169. * unused units removed from uses clause
  170. * some changes for widestrings
  171. Revision 1.7 2000/10/31 22:02:49 peter
  172. * symtable splitted, no real code changes
  173. Revision 1.6 2000/10/14 10:14:51 peter
  174. * moehrendorf oct 2000 rewrite
  175. Revision 1.5 2000/09/24 21:19:50 peter
  176. * delphi compile fixes
  177. Revision 1.4 2000/09/24 15:06:21 peter
  178. * use defines.inc
  179. Revision 1.3 2000/08/27 16:11:51 peter
  180. * moved some util functions from globals,cobjects to cutils
  181. * splitted files into finput,fmodule
  182. Revision 1.2 2000/07/13 11:32:44 michael
  183. + removed logs
  184. }