pexports.pas 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. ;
  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. repeat
  55. hp:=texported_item.create;
  56. if token=_ID then
  57. begin
  58. orgs:=orgpattern;
  59. consume_sym(srsym,srsymtable);
  60. hp.sym:=srsym;
  61. InternalProcName:='';
  62. case srsym.typ of
  63. varsym :
  64. InternalProcName:=tvarsym(srsym).mangledname;
  65. typedconstsym :
  66. InternalProcName:=ttypedconstsym(srsym).mangledname;
  67. procsym :
  68. begin
  69. if (Tprocsym(srsym).procdef_count>1) or
  70. ((tf_need_export in target_info.flags) and
  71. not(po_exports in tprocsym(srsym).first_procdef.procoptions)) then
  72. Message(parser_e_illegal_symbol_exported)
  73. else
  74. InternalProcName:=tprocsym(srsym).first_procdef.mangledname;
  75. end;
  76. else
  77. Message(parser_e_illegal_symbol_exported)
  78. end;
  79. if InternalProcName<>'' then
  80. begin
  81. { This is wrong if the first is not
  82. an underline }
  83. if InternalProcName[1]='_' then
  84. delete(InternalProcName,1,1)
  85. else if (target_info.system in [system_i386_win32,system_i386_wdosx]) and UseDeffileForExport then
  86. begin
  87. Message(parser_e_dlltool_unit_var_problem);
  88. Message(parser_e_dlltool_unit_var_problem2);
  89. end;
  90. if length(InternalProcName)<2 then
  91. Message(parser_e_procname_to_short_for_export);
  92. DefString:=srsym.realname+'='+InternalProcName;
  93. end;
  94. if try_to_consume(_INDEX) then
  95. begin
  96. pt:=comp_expr(true);
  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_info.system in [system_i386_win32,system_i386_wdosx] then
  107. DefString:=srsym.realname+'='+InternalProcName+' @ '+tostr(hp.index)
  108. else
  109. DefString:=srsym.realname+'='+InternalProcName; {Index ignored!}
  110. end;
  111. if try_to_consume(_NAME) then
  112. begin
  113. pt:=comp_expr(true);
  114. if pt.nodetype=stringconstn then
  115. hp.name:=stringdup(strpas(tstringconstnode(pt).value_str))
  116. else
  117. begin
  118. hp.name:=stringdup('');
  119. consume(_CSTRING);
  120. end;
  121. hp.options:=hp.options or eo_name;
  122. pt.free;
  123. DefString:=hp.name^+'='+InternalProcName;
  124. end;
  125. if try_to_consume(_RESIDENT) then
  126. begin
  127. hp.options:=hp.options or eo_resident;
  128. DefString:=srsym.realname+'='+InternalProcName;{Resident ignored!}
  129. end;
  130. if (DefString<>'') and UseDeffileForExport then
  131. DefFile.AddExport(DefString);
  132. { Default to generate a name entry with the provided name }
  133. if not assigned(hp.name) then
  134. begin
  135. hp.name:=stringdup(orgs);
  136. hp.options:=hp.options or eo_name;
  137. end;
  138. if hp.sym.typ=procsym then
  139. exportlib.exportprocedure(hp)
  140. else
  141. exportlib.exportvar(hp);
  142. end
  143. else
  144. consume(_ID);
  145. until not try_to_consume(_COMMA);
  146. consume(_SEMICOLON);
  147. if not DefFile.empty then
  148. DefFile.writefile;
  149. end;
  150. end.
  151. {
  152. $Log$
  153. Revision 1.23 2002-09-03 16:26:27 daniel
  154. * Make Tprocdef.defs protected
  155. Revision 1.22 2002/07/26 21:15:41 florian
  156. * rewrote the system handling
  157. Revision 1.21 2002/05/18 13:34:12 peter
  158. * readded missing revisions
  159. Revision 1.20 2002/05/16 19:46:43 carl
  160. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  161. + try to fix temp allocation (still in ifdef)
  162. + generic constructor calls
  163. + start of tassembler / tmodulebase class cleanup
  164. Revision 1.18 2002/04/04 19:06:03 peter
  165. * removed unused units
  166. * use tlocation.size in cg.a_*loc*() routines
  167. Revision 1.17 2002/04/04 18:41:07 carl
  168. + added wdosx support (patch from Pavel)
  169. }