pexports.pas 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. interface
  20. { reads an exports statement in a library }
  21. procedure read_exports;
  22. implementation
  23. uses
  24. globtype,systems,tokens,
  25. strings,cutils,cobjects,globals,verbose,
  26. scanner,symconst,symtable,pbase,
  27. export,GenDef,tree,pass_1,pexpr;
  28. procedure read_exports;
  29. var
  30. hp : pexported_item;
  31. DefString:string;
  32. ProcName:string;
  33. InternalProcName:string;
  34. pt : ptree;
  35. begin
  36. DefString:='';
  37. InternalProcName:='';
  38. consume(_EXPORTS);
  39. while true do
  40. begin
  41. hp:=new(pexported_item,init);
  42. if token=_ID then
  43. begin
  44. getsym(pattern,true);
  45. if srsym^.typ=unitsym then
  46. begin
  47. consume(_ID);
  48. consume(_POINT);
  49. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  50. end;
  51. consume(_ID);
  52. if assigned(srsym) then
  53. begin
  54. hp^.sym:=srsym;
  55. if ((hp^.sym^.typ<>procsym) or
  56. ((tf_need_export in target_info.flags) and
  57. not(po_exports in pprocdef(pprocsym(srsym)^.definition)^.procoptions)
  58. )
  59. ) and
  60. (srsym^.typ<>varsym) and (srsym^.typ<>typedconstsym) then
  61. Message(parser_e_illegal_symbol_exported)
  62. else
  63. begin
  64. ProcName:=hp^.sym^.name;
  65. InternalProcName:=hp^.sym^.mangledname;
  66. { This is wrong if the first is not
  67. an underline }
  68. if InternalProcName[1]='_' then
  69. delete(InternalProcName,1,1)
  70. else if (target_os.id=os_i386_win32) and UseDeffileForExport then
  71. begin
  72. Message(parser_e_dlltool_unit_var_problem);
  73. Message(parser_e_dlltool_unit_var_problem2);
  74. end;
  75. if length(InternalProcName)<2 then
  76. Message(parser_e_procname_to_short_for_export);
  77. DefString:=ProcName+'='+InternalProcName;
  78. end;
  79. if (idtoken=_INDEX) then
  80. begin
  81. consume(_INDEX);
  82. pt:=comp_expr(true);
  83. do_firstpass(pt);
  84. if pt^.treetype=ordconstn then
  85. hp^.index:=pt^.value
  86. else
  87. begin
  88. hp^.index:=0;
  89. consume(_INTCONST);
  90. end;
  91. hp^.options:=hp^.options or eo_index;
  92. disposetree(pt);
  93. if target_os.id=os_i386_win32 then
  94. DefString:=ProcName+'='+InternalProcName+' @ '+tostr(hp^.index)
  95. else
  96. DefString:=ProcName+'='+InternalProcName; {Index ignored!}
  97. end;
  98. if (idtoken=_NAME) then
  99. begin
  100. consume(_NAME);
  101. pt:=comp_expr(true);
  102. do_firstpass(pt);
  103. if pt^.treetype=stringconstn then
  104. hp^.name:=stringdup(strpas(pt^.value_str))
  105. else
  106. begin
  107. hp^.name:=stringdup('');
  108. consume(_CSTRING);
  109. end;
  110. hp^.options:=hp^.options or eo_name;
  111. disposetree(pt);
  112. DefString:=hp^.name^+'='+InternalProcName;
  113. end;
  114. if (idtoken=_RESIDENT) then
  115. begin
  116. consume(_RESIDENT);
  117. hp^.options:=hp^.options or eo_resident;
  118. DefString:=ProcName+'='+InternalProcName;{Resident ignored!}
  119. end;
  120. if (DefString<>'') and UseDeffileForExport then
  121. DefFile.AddExport(DefString);
  122. if hp^.sym^.typ=procsym then
  123. exportlib^.exportprocedure(hp)
  124. else
  125. exportlib^.exportvar(hp);
  126. end;
  127. end
  128. else
  129. consume(_ID);
  130. if token=_COMMA then
  131. consume(_COMMA)
  132. else
  133. break;
  134. end;
  135. consume(_SEMICOLON);
  136. if not DefFile.empty then
  137. DefFile.writefile;
  138. end;
  139. end.
  140. {
  141. $Log$
  142. Revision 1.3 2000-08-27 16:11:51 peter
  143. * moved some util functions from globals,cobjects to cutils
  144. * splitted files into finput,fmodule
  145. Revision 1.2 2000/07/13 11:32:44 michael
  146. + removed logs
  147. }