pexports.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. function IsGreater(hp1,hp2:texported_item):boolean;
  51. var
  52. i2 : boolean;
  53. begin
  54. i2:=(hp2.options and eo_index)<>0;
  55. if (hp1.options and eo_index)<>0 then
  56. begin
  57. if i2 then
  58. IsGreater:=hp1.index>hp2.index
  59. else
  60. IsGreater:=false;
  61. end
  62. else
  63. IsGreater:=i2;
  64. end;
  65. begin
  66. DefString:='';
  67. InternalProcName:='';
  68. consume(_EXPORTS);
  69. repeat
  70. hp:=texported_item.create;
  71. if token=_ID then
  72. begin
  73. orgs:=orgpattern;
  74. consume_sym(srsym,srsymtable);
  75. hp.sym:=srsym;
  76. InternalProcName:='';
  77. case srsym.typ of
  78. globalvarsym :
  79. InternalProcName:=tglobalvarsym(srsym).mangledname;
  80. typedconstsym :
  81. InternalProcName:=ttypedconstsym(srsym).mangledname;
  82. procsym :
  83. begin
  84. if (Tprocsym(srsym).procdef_count>1) or
  85. ((tf_need_export in target_info.flags) and
  86. not(po_exports in tprocsym(srsym).first_procdef.procoptions)) then
  87. Message(parser_e_illegal_symbol_exported)
  88. else
  89. InternalProcName:=tprocsym(srsym).first_procdef.mangledname;
  90. end;
  91. else
  92. Message(parser_e_illegal_symbol_exported)
  93. end;
  94. if InternalProcName<>'' then
  95. begin
  96. { This is wrong if the first is not
  97. an underline }
  98. if InternalProcName[1]='_' then
  99. delete(InternalProcName,1,1)
  100. else if (target_info.system in [system_i386_win32,system_i386_wdosx]) and UseDeffileForExports then
  101. begin
  102. Message(parser_e_dlltool_unit_var_problem);
  103. Message(parser_e_dlltool_unit_var_problem2);
  104. end;
  105. if length(InternalProcName)<2 then
  106. Message(parser_e_procname_to_short_for_export);
  107. DefString:=srsym.realname+'='+InternalProcName;
  108. end;
  109. if try_to_consume(_INDEX) then
  110. begin
  111. pt:=comp_expr(true);
  112. if pt.nodetype=ordconstn then
  113. hp.index:=tordconstnode(pt).value
  114. else
  115. begin
  116. hp.index:=0;
  117. consume(_INTCONST);
  118. end;
  119. hp.options:=hp.options or eo_index;
  120. pt.free;
  121. if target_info.system in [system_i386_win32,system_i386_wdosx] then
  122. DefString:=srsym.realname+'='+InternalProcName+' @ '+tostr(hp.index)
  123. else
  124. DefString:=srsym.realname+'='+InternalProcName; {Index ignored!}
  125. end;
  126. if try_to_consume(_NAME) then
  127. begin
  128. pt:=comp_expr(true);
  129. if pt.nodetype=stringconstn then
  130. hp.name:=stringdup(strpas(tstringconstnode(pt).value_str))
  131. else
  132. begin
  133. hp.name:=stringdup('');
  134. consume(_CSTRING);
  135. end;
  136. hp.options:=hp.options or eo_name;
  137. pt.free;
  138. DefString:=hp.name^+'='+InternalProcName;
  139. end;
  140. if try_to_consume(_RESIDENT) then
  141. begin
  142. hp.options:=hp.options or eo_resident;
  143. DefString:=srsym.realname+'='+InternalProcName;{Resident ignored!}
  144. end;
  145. if (DefString<>'') and UseDeffileForExports then
  146. DefFile.AddExport(DefString);
  147. { Default to generate a name entry with the provided name }
  148. if not assigned(hp.name) then
  149. begin
  150. hp.name:=stringdup(orgs);
  151. hp.options:=hp.options or eo_name;
  152. end;
  153. if hp.sym.typ=procsym then
  154. exportlib.exportprocedure(hp)
  155. else
  156. exportlib.exportvar(hp);
  157. end
  158. else
  159. consume(_ID);
  160. until not try_to_consume(_COMMA);
  161. consume(_SEMICOLON);
  162. if not DefFile.empty then
  163. DefFile.writefile;
  164. end;
  165. end.
  166. {
  167. $Log$
  168. Revision 1.30 2004-11-08 22:09:59 peter
  169. * tvarsym splitted
  170. Revision 1.29 2004/10/15 09:14:17 mazen
  171. - remove $IFDEF DELPHI and related code
  172. - remove $IFDEF FPCPROCVAR and related code
  173. Revision 1.28 2004/06/20 08:55:30 florian
  174. * logs truncated
  175. Revision 1.27 2004/06/16 20:07:09 florian
  176. * dwarf branch merged
  177. Revision 1.26 2004/04/24 17:32:05 peter
  178. index number generation for mixed index-nonindexed fixed, patch by Pavel V. Ozerski
  179. Revision 1.25.2.1 2004/05/03 14:59:57 peter
  180. * no dlltool needed for win32 linking executables
  181. Revision 1.25 2004/04/08 11:07:05 michael
  182. indexed exports needs to be sorted (patch from Pavel)
  183. }