pexports.pas 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. {$ifdef delphi}
  26. sysutils,
  27. {$else}
  28. strings,
  29. {$endif}
  30. globtype,systems,tokens,
  31. cutils,cobjects,globals,verbose,
  32. scanner,symconst,symtable,pbase,
  33. export,GenDef,tree,pass_1,pexpr;
  34. procedure read_exports;
  35. var
  36. hp : pexported_item;
  37. DefString:string;
  38. ProcName:string;
  39. InternalProcName:string;
  40. pt : ptree;
  41. begin
  42. DefString:='';
  43. InternalProcName:='';
  44. consume(_EXPORTS);
  45. while true do
  46. begin
  47. hp:=new(pexported_item,init);
  48. if token=_ID then
  49. begin
  50. getsym(pattern,true);
  51. if srsym^.typ=unitsym then
  52. begin
  53. consume(_ID);
  54. consume(_POINT);
  55. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  56. end;
  57. consume(_ID);
  58. if assigned(srsym) then
  59. begin
  60. hp^.sym:=srsym;
  61. if ((hp^.sym^.typ<>procsym) or
  62. ((tf_need_export in target_info.flags) and
  63. not(po_exports in pprocdef(pprocsym(srsym)^.definition)^.procoptions)
  64. )
  65. ) and
  66. (srsym^.typ<>varsym) and (srsym^.typ<>typedconstsym) then
  67. Message(parser_e_illegal_symbol_exported)
  68. else
  69. begin
  70. ProcName:=hp^.sym^.name;
  71. InternalProcName:=hp^.sym^.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_os.id=os_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:=ProcName+'='+InternalProcName;
  84. end;
  85. if (idtoken=_INDEX) then
  86. begin
  87. consume(_INDEX);
  88. pt:=comp_expr(true);
  89. do_firstpass(pt);
  90. if pt^.treetype=ordconstn then
  91. hp^.index:=pt^.value
  92. else
  93. begin
  94. hp^.index:=0;
  95. consume(_INTCONST);
  96. end;
  97. hp^.options:=hp^.options or eo_index;
  98. disposetree(pt);
  99. if target_os.id=os_i386_win32 then
  100. DefString:=ProcName+'='+InternalProcName+' @ '+tostr(hp^.index)
  101. else
  102. DefString:=ProcName+'='+InternalProcName; {Index ignored!}
  103. end;
  104. if (idtoken=_NAME) then
  105. begin
  106. consume(_NAME);
  107. pt:=comp_expr(true);
  108. do_firstpass(pt);
  109. if pt^.treetype=stringconstn then
  110. hp^.name:=stringdup(strpas(pt^.value_str))
  111. else
  112. begin
  113. hp^.name:=stringdup('');
  114. consume(_CSTRING);
  115. end;
  116. hp^.options:=hp^.options or eo_name;
  117. disposetree(pt);
  118. DefString:=hp^.name^+'='+InternalProcName;
  119. end;
  120. if (idtoken=_RESIDENT) then
  121. begin
  122. consume(_RESIDENT);
  123. hp^.options:=hp^.options or eo_resident;
  124. DefString:=ProcName+'='+InternalProcName;{Resident ignored!}
  125. end;
  126. if (DefString<>'') and UseDeffileForExport then
  127. DefFile.AddExport(DefString);
  128. if hp^.sym^.typ=procsym then
  129. exportlib^.exportprocedure(hp)
  130. else
  131. exportlib^.exportvar(hp);
  132. end;
  133. end
  134. else
  135. consume(_ID);
  136. if token=_COMMA then
  137. consume(_COMMA)
  138. else
  139. break;
  140. end;
  141. consume(_SEMICOLON);
  142. if not DefFile.empty then
  143. DefFile.writefile;
  144. end;
  145. end.
  146. {
  147. $Log$
  148. Revision 1.5 2000-09-24 21:19:50 peter
  149. * delphi compile fixes
  150. Revision 1.4 2000/09/24 15:06:21 peter
  151. * use defines.inc
  152. Revision 1.3 2000/08/27 16:11:51 peter
  153. * moved some util functions from globals,cobjects to cutils
  154. * splitted files into finput,fmodule
  155. Revision 1.2 2000/07/13 11:32:44 michael
  156. + removed logs
  157. }