pexports.pas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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 fpcdefs.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,symsym,
  32. { pass 1 }
  33. node,
  34. ncon,
  35. { parser }
  36. scanner,
  37. pbase,pexpr,
  38. { link }
  39. gendef,export
  40. {$ifdef Delphi}
  41. ,dmisc
  42. ,sysutils
  43. {$endif}
  44. ;
  45. procedure read_exports;
  46. var
  47. hp : texported_item;
  48. orgs,
  49. DefString : string;
  50. InternalProcName : string;
  51. pt : tnode;
  52. srsym : tsym;
  53. srsymtable : tsymtable;
  54. begin
  55. DefString:='';
  56. InternalProcName:='';
  57. consume(_EXPORTS);
  58. repeat
  59. hp:=texported_item.create;
  60. if token=_ID then
  61. begin
  62. orgs:=orgpattern;
  63. consume_sym(srsym,srsymtable);
  64. hp.sym:=srsym;
  65. InternalProcName:='';
  66. case srsym.typ of
  67. varsym :
  68. InternalProcName:=tvarsym(srsym).mangledname;
  69. typedconstsym :
  70. InternalProcName:=ttypedconstsym(srsym).mangledname;
  71. procsym :
  72. begin
  73. if (Tprocsym(srsym).procdef_count>1) or
  74. ((tf_need_export in target_info.flags) and
  75. not(po_exports in tprocsym(srsym).first_procdef.procoptions)) then
  76. Message(parser_e_illegal_symbol_exported)
  77. else
  78. InternalProcName:=tprocsym(srsym).first_procdef.mangledname;
  79. end;
  80. else
  81. Message(parser_e_illegal_symbol_exported)
  82. end;
  83. if InternalProcName<>'' then
  84. begin
  85. { This is wrong if the first is not
  86. an underline }
  87. if InternalProcName[1]='_' then
  88. delete(InternalProcName,1,1)
  89. else if (target_info.system in [system_i386_win32,system_i386_wdosx]) and UseDeffileForExport then
  90. begin
  91. Message(parser_e_dlltool_unit_var_problem);
  92. Message(parser_e_dlltool_unit_var_problem2);
  93. end;
  94. if length(InternalProcName)<2 then
  95. Message(parser_e_procname_to_short_for_export);
  96. DefString:=srsym.realname+'='+InternalProcName;
  97. end;
  98. if try_to_consume(_INDEX) then
  99. begin
  100. pt:=comp_expr(true);
  101. if pt.nodetype=ordconstn then
  102. hp.index:=tordconstnode(pt).value
  103. else
  104. begin
  105. hp.index:=0;
  106. consume(_INTCONST);
  107. end;
  108. hp.options:=hp.options or eo_index;
  109. pt.free;
  110. if target_info.system in [system_i386_win32,system_i386_wdosx] then
  111. DefString:=srsym.realname+'='+InternalProcName+' @ '+tostr(hp.index)
  112. else
  113. DefString:=srsym.realname+'='+InternalProcName; {Index ignored!}
  114. end;
  115. if try_to_consume(_NAME) then
  116. begin
  117. pt:=comp_expr(true);
  118. if pt.nodetype=stringconstn then
  119. hp.name:=stringdup(strpas(tstringconstnode(pt).value_str))
  120. else
  121. begin
  122. hp.name:=stringdup('');
  123. consume(_CSTRING);
  124. end;
  125. hp.options:=hp.options or eo_name;
  126. pt.free;
  127. DefString:=hp.name^+'='+InternalProcName;
  128. end;
  129. if try_to_consume(_RESIDENT) then
  130. begin
  131. hp.options:=hp.options or eo_resident;
  132. DefString:=srsym.realname+'='+InternalProcName;{Resident ignored!}
  133. end;
  134. if (DefString<>'') and UseDeffileForExport then
  135. DefFile.AddExport(DefString);
  136. { Default to generate a name entry with the provided name }
  137. if not assigned(hp.name) then
  138. begin
  139. hp.name:=stringdup(orgs);
  140. hp.options:=hp.options or eo_name;
  141. end;
  142. if hp.sym.typ=procsym then
  143. exportlib.exportprocedure(hp)
  144. else
  145. exportlib.exportvar(hp);
  146. end
  147. else
  148. consume(_ID);
  149. until not try_to_consume(_COMMA);
  150. consume(_SEMICOLON);
  151. if not DefFile.empty then
  152. DefFile.writefile;
  153. end;
  154. end.
  155. {
  156. $Log$
  157. Revision 1.24 2002-10-05 12:43:26 carl
  158. * fixes for Delphi 6 compilation
  159. (warning : Some features do not work under Delphi)
  160. Revision 1.23 2002/09/03 16:26:27 daniel
  161. * Make Tprocdef.defs protected
  162. Revision 1.22 2002/07/26 21:15:41 florian
  163. * rewrote the system handling
  164. Revision 1.21 2002/05/18 13:34:12 peter
  165. * readded missing revisions
  166. Revision 1.20 2002/05/16 19:46:43 carl
  167. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  168. + try to fix temp allocation (still in ifdef)
  169. + generic constructor calls
  170. + start of tassembler / tmodulebase class cleanup
  171. Revision 1.18 2002/04/04 19:06:03 peter
  172. * removed unused units
  173. * use tlocation.size in cg.a_*loc*() routines
  174. Revision 1.17 2002/04/04 18:41:07 carl
  175. + added wdosx support (patch from Pavel)
  176. }