pexports.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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,cobjects,
  27. { global }
  28. globtype,globals,tokens,verbose,
  29. systems,cpuinfo,
  30. { aasm }
  31. aasm,
  32. { symtable }
  33. symconst,symtable,types,
  34. { pass 1 }
  35. node,pass_1,
  36. ncon,
  37. { parser }
  38. scanner,
  39. pbase,pexpr,pdecl,pdecsub,pdecvar,
  40. { link }
  41. gendef,export
  42. ;
  43. procedure read_exports;
  44. var
  45. hp : pexported_item;
  46. DefString : string;
  47. ProcName : string;
  48. InternalProcName : string;
  49. pt : tnode;
  50. begin
  51. DefString:='';
  52. InternalProcName:='';
  53. consume(_EXPORTS);
  54. while true do
  55. begin
  56. hp:=new(pexported_item,init);
  57. if token=_ID then
  58. begin
  59. getsym(pattern,true);
  60. if srsym^.typ=unitsym then
  61. begin
  62. consume(_ID);
  63. consume(_POINT);
  64. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  65. end;
  66. consume(_ID);
  67. if assigned(srsym) then
  68. begin
  69. hp^.sym:=srsym;
  70. if ((hp^.sym^.typ<>procsym) or
  71. ((tf_need_export in target_info.flags) and
  72. not(po_exports in pprocdef(pprocsym(srsym)^.definition)^.procoptions)
  73. )
  74. ) and
  75. (srsym^.typ<>varsym) and (srsym^.typ<>typedconstsym) then
  76. Message(parser_e_illegal_symbol_exported)
  77. else
  78. begin
  79. ProcName:=hp^.sym^.name;
  80. InternalProcName:=hp^.sym^.mangledname;
  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_os.id=os_i386_win32) 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:=ProcName+'='+InternalProcName;
  93. end;
  94. if (idtoken=_INDEX) then
  95. begin
  96. consume(_INDEX);
  97. pt:=comp_expr(true);
  98. do_firstpass(pt);
  99. if pt.nodetype=ordconstn then
  100. hp^.index:=tordconstnode(pt).value
  101. else
  102. begin
  103. hp^.index:=0;
  104. consume(_INTCONST);
  105. end;
  106. hp^.options:=hp^.options or eo_index;
  107. pt.free;
  108. if target_os.id=os_i386_win32 then
  109. DefString:=ProcName+'='+InternalProcName+' @ '+tostr(hp^.index)
  110. else
  111. DefString:=ProcName+'='+InternalProcName; {Index ignored!}
  112. end;
  113. if (idtoken=_NAME) then
  114. begin
  115. consume(_NAME);
  116. pt:=comp_expr(true);
  117. do_firstpass(pt);
  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 (idtoken=_RESIDENT) then
  130. begin
  131. consume(_RESIDENT);
  132. hp^.options:=hp^.options or eo_resident;
  133. DefString:=ProcName+'='+InternalProcName;{Resident ignored!}
  134. end;
  135. if (DefString<>'') and UseDeffileForExport then
  136. DefFile.AddExport(DefString);
  137. if hp^.sym^.typ=procsym then
  138. exportlib^.exportprocedure(hp)
  139. else
  140. exportlib^.exportvar(hp);
  141. end;
  142. end
  143. else
  144. consume(_ID);
  145. if token=_COMMA then
  146. consume(_COMMA)
  147. else
  148. break;
  149. end;
  150. consume(_SEMICOLON);
  151. if not DefFile.empty then
  152. DefFile.writefile;
  153. end;
  154. end.
  155. {
  156. $Log$
  157. Revision 1.6 2000-10-14 10:14:51 peter
  158. * moehrendorf oct 2000 rewrite
  159. Revision 1.5 2000/09/24 21:19:50 peter
  160. * delphi compile fixes
  161. Revision 1.4 2000/09/24 15:06:21 peter
  162. * use defines.inc
  163. Revision 1.3 2000/08/27 16:11:51 peter
  164. * moved some util functions from globals,cobjects to cutils
  165. * splitted files into finput,fmodule
  166. Revision 1.2 2000/07/13 11:32:44 michael
  167. + removed logs
  168. }