import.pas 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Peter Vreman
  4. This unit implements an uniform import object
  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. unit import;
  18. interface
  19. uses
  20. cobjects{$IFDEF NEWST},objects{$ENDIF NEWST};
  21. type
  22. pimported_item = ^timported_item;
  23. timported_item = object(tlinkedlist_item)
  24. ordnr : word;
  25. name,
  26. func : pstring;
  27. lab : pointer; { should be plabel, but this gaves problems with circular units }
  28. is_var : boolean;
  29. constructor init(const n,s : string;o : word);
  30. constructor init_var(const n,s : string);
  31. destructor done;virtual;
  32. end;
  33. pimportlist = ^timportlist;
  34. timportlist = object(tlinkedlist_item)
  35. dllname : pstring;
  36. imported_items : plinkedlist;
  37. constructor init(const n : string);
  38. destructor done;virtual;
  39. end;
  40. pimportlib=^timportlib;
  41. timportlib=object
  42. private
  43. notsupmsg : boolean;
  44. procedure NotSupported;
  45. public
  46. constructor Init;
  47. destructor Done;
  48. procedure preparelib(const s:string);virtual;
  49. procedure importprocedure(const func,module:string;index:longint;const name:string);virtual;
  50. procedure importvariable(const varname,module:string;const name:string);virtual;
  51. procedure generatelib;virtual;
  52. procedure generatesmartlib;virtual;
  53. end;
  54. var
  55. importlib : pimportlib;
  56. procedure InitImport;
  57. procedure DoneImport;
  58. implementation
  59. uses
  60. systems,verbose,globals
  61. {$ifdef i386}
  62. {$ifndef NOTARGETLINUX}
  63. ,t_linux
  64. {$endif}
  65. {$ifndef NOTARGETOS2}
  66. ,t_os2
  67. {$endif}
  68. {$ifndef NOTARGETWIN32}
  69. ,t_win32
  70. {$endif}
  71. {$ifndef NOTARGETGO32V2}
  72. ,t_go32v2
  73. {$endif}
  74. {$endif}
  75. {$ifdef m68k}
  76. {$ifndef NOTARGETLINUX}
  77. ,t_linux
  78. {$endif}
  79. {$endif}
  80. {$ifdef powerpc}
  81. {$ifndef NOTARGETLINUX}
  82. ,t_linux
  83. {$endif}
  84. {$endif}
  85. {$ifdef alpha}
  86. {$ifndef NOTARGETLINUX}
  87. ,t_linux
  88. {$endif}
  89. {$endif}
  90. ;
  91. {****************************************************************************
  92. Timported_item
  93. ****************************************************************************}
  94. constructor timported_item.init(const n,s : string;o : word);
  95. begin
  96. inherited init;
  97. func:=stringdup(n);
  98. name:=stringdup(s);
  99. ordnr:=o;
  100. lab:=nil;
  101. is_var:=false;
  102. end;
  103. constructor timported_item.init_var(const n,s : string);
  104. begin
  105. inherited init;
  106. func:=stringdup(n);
  107. name:=stringdup(s);
  108. ordnr:=0;
  109. lab:=nil;
  110. is_var:=true;
  111. end;
  112. destructor timported_item.done;
  113. begin
  114. stringdispose(name);
  115. stringdispose(func);
  116. inherited done;
  117. end;
  118. {****************************************************************************
  119. TImportlist
  120. ****************************************************************************}
  121. constructor timportlist.init(const n : string);
  122. begin
  123. inherited init;
  124. dllname:=stringdup(n);
  125. imported_items:=new(plinkedlist,init);
  126. end;
  127. destructor timportlist.done;
  128. begin
  129. dispose(imported_items,done);
  130. stringdispose(dllname);
  131. end;
  132. {****************************************************************************
  133. TImportLib
  134. ****************************************************************************}
  135. constructor timportlib.Init;
  136. begin
  137. notsupmsg:=false;
  138. end;
  139. destructor timportlib.Done;
  140. begin
  141. end;
  142. procedure timportlib.NotSupported;
  143. begin
  144. { show the message only once }
  145. if not notsupmsg then
  146. begin
  147. Message(exec_e_dll_not_supported);
  148. notsupmsg:=true;
  149. end;
  150. end;
  151. procedure timportlib.preparelib(const s:string);
  152. begin
  153. NotSupported;
  154. end;
  155. procedure timportlib.importprocedure(const func,module:string;index:longint;const name:string);
  156. begin
  157. NotSupported;
  158. end;
  159. procedure timportlib.importvariable(const varname,module:string;const name:string);
  160. begin
  161. NotSupported;
  162. end;
  163. procedure timportlib.generatelib;
  164. begin
  165. NotSupported;
  166. end;
  167. procedure timportlib.generatesmartlib;
  168. begin
  169. NotSupported;
  170. end;
  171. procedure DoneImport;
  172. begin
  173. if assigned(importlib) then
  174. dispose(importlib,done);
  175. end;
  176. procedure InitImport;
  177. begin
  178. case target_info.target of
  179. {$ifdef i386}
  180. target_i386_Linux :
  181. importlib:=new(pimportliblinux,Init);
  182. target_i386_Win32 :
  183. importlib:=new(pimportlibwin32,Init);
  184. target_i386_OS2 :
  185. importlib:=new(pimportlibos2,Init);
  186. {$endif i386}
  187. {$ifdef m68k}
  188. target_m68k_Linux :
  189. importlib:=new(pimportliblinux,Init);
  190. {$endif m68k}
  191. {$ifdef alpha}
  192. target_alpha_Linux :
  193. importlib:=new(pimportliblinux,Init);
  194. {$endif alpha}
  195. {$ifdef powerpc}
  196. target_alpha_Linux :
  197. importlib:=new(pimportliblinux,Init);
  198. {$endif powerpc}
  199. else
  200. importlib:=new(pimportlib,Init);
  201. end;
  202. end;
  203. end.
  204. {
  205. $Log$
  206. Revision 1.19 2000-02-28 17:23:57 daniel
  207. * Current work of symtable integration committed. The symtable can be
  208. activated by defining 'newst', but doesn't compile yet. Changes in type
  209. checking and oop are completed. What is left is to write a new
  210. symtablestack and adapt the parser to use it.
  211. Revision 1.18 2000/02/09 13:22:54 peter
  212. * log truncated
  213. Revision 1.17 2000/01/12 10:34:29 peter
  214. * only give unsupported error once
  215. Revision 1.16 2000/01/07 01:14:27 peter
  216. * updated copyright to 2000
  217. Revision 1.15 1999/11/06 14:34:21 peter
  218. * truncated log to 20 revs
  219. Revision 1.14 1999/11/02 15:06:57 peter
  220. * import library fixes for win32
  221. * alignment works again
  222. Revision 1.13 1999/10/21 14:29:34 peter
  223. * redesigned linker object
  224. + library support for linux (only procedures can be exported)
  225. Revision 1.12 1999/08/04 13:02:44 jonas
  226. * all tokens now start with an underscore
  227. * PowerPC compiles!!
  228. Revision 1.11 1999/08/03 13:50:16 michael
  229. + Changes for alpha
  230. }