/src/lib/foreign_interface/foreign_types.e

http://github.com/tybor/Liberty · Specman e · 269 lines · 202 code · 43 blank · 24 comment · 0 complexity · d5e52b730e1f87935231a75f18451081 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. expanded class FOREIGN_TYPES
  5. insert
  6. FFI_EXTERNALS
  7. ANY
  8. redefine
  9. copy,
  10. is_equal
  11. end
  12. feature {ANY}
  13. copy (other: like Current)
  14. do
  15. end
  16. is_equal (other: like Current): BOOLEAN
  17. do
  18. Result := True
  19. end
  20. feature {ANY} -- Types
  21. nothing: FOREIGN_TYPE
  22. once
  23. Result.set_ffi_type(address_of_ffi_type_void, Void, "nothing")
  24. end
  25. uint8: FOREIGN_TYPE
  26. once
  27. Result.set_ffi_type(address_of_ffi_type_uint8, agent new_uint8, "uint8")
  28. end
  29. sint8: FOREIGN_TYPE
  30. once
  31. Result.set_ffi_type(address_of_ffi_type_sint8, agent new_sint8, "sint8")
  32. end
  33. uint16: FOREIGN_TYPE
  34. once
  35. Result.set_ffi_type(address_of_ffi_type_uint16, agent new_uint16, "uint16")
  36. end
  37. sint16: FOREIGN_TYPE
  38. once
  39. Result.set_ffi_type(address_of_ffi_type_sint16, agent new_sint16, "sint16")
  40. end
  41. uint32: FOREIGN_TYPE
  42. once
  43. Result.set_ffi_type(address_of_ffi_type_uint32, agent new_uint32, "uint32")
  44. end
  45. sint32: FOREIGN_TYPE
  46. once
  47. Result.set_ffi_type(address_of_ffi_type_sint32, agent new_sint32, "sint32")
  48. end
  49. uint64: FOREIGN_TYPE
  50. once
  51. Result.set_ffi_type(address_of_ffi_type_uint64, agent new_uint64, "uint64")
  52. end
  53. sint64: FOREIGN_TYPE
  54. once
  55. Result.set_ffi_type(address_of_ffi_type_sint64, agent new_sint64, "sint64")
  56. end
  57. float: FOREIGN_TYPE
  58. once
  59. Result.set_ffi_type(address_of_ffi_type_float, agent new_float, "float")
  60. end
  61. double: FOREIGN_TYPE
  62. once
  63. Result.set_ffi_type(address_of_ffi_type_double, agent new_double, "double")
  64. end
  65. schar: FOREIGN_TYPE
  66. once
  67. Result.set_ffi_type(address_of_ffi_type_sint8, agent new_schar, "schar")
  68. end
  69. c_string, pointer: FOREIGN_TYPE
  70. once
  71. Result.set_ffi_type(address_of_ffi_type_pointer, agent new_pointer, "pointer")
  72. end
  73. feature {ANY} -- Objects factory
  74. create_uint8 (data: NATURAL_8): FOREIGN_OBJECT
  75. do
  76. create {FOREIGN_TYPED_OBJECT[NATURAL_8]} Result.make(uint8, data)
  77. end
  78. create_sint8 (data: INTEGER_8): FOREIGN_OBJECT
  79. do
  80. create {FOREIGN_TYPED_OBJECT[INTEGER_8]} Result.make(sint8, data)
  81. end
  82. create_uint16 (data: NATURAL_16): FOREIGN_OBJECT
  83. do
  84. create {FOREIGN_TYPED_OBJECT[NATURAL_16]} Result.make(uint16, data)
  85. end
  86. create_sint16 (data: INTEGER_16): FOREIGN_OBJECT
  87. do
  88. create {FOREIGN_TYPED_OBJECT[INTEGER_16]} Result.make(sint16, data)
  89. end
  90. create_uint32 (data: NATURAL_32): FOREIGN_OBJECT
  91. do
  92. create {FOREIGN_TYPED_OBJECT[NATURAL_32]} Result.make(uint32, data)
  93. end
  94. create_sint32 (data: INTEGER_32): FOREIGN_OBJECT
  95. do
  96. create {FOREIGN_TYPED_OBJECT[INTEGER_32]} Result.make(sint32, data)
  97. end
  98. create_uint64 (data: NATURAL_64): FOREIGN_OBJECT
  99. do
  100. create {FOREIGN_TYPED_OBJECT[NATURAL_64]} Result.make(uint64, data)
  101. end
  102. create_sint64 (data: INTEGER_64): FOREIGN_OBJECT
  103. do
  104. create {FOREIGN_TYPED_OBJECT[INTEGER_64]} Result.make(sint64, data)
  105. end
  106. create_float (data: REAL_32): FOREIGN_OBJECT
  107. do
  108. create {FOREIGN_TYPED_OBJECT[REAL_32]} Result.make(float, data)
  109. end
  110. create_double (data: REAL_64): FOREIGN_OBJECT
  111. do
  112. create {FOREIGN_TYPED_OBJECT[REAL_64]} Result.make(double, data)
  113. end
  114. create_schar (data: CHARACTER): FOREIGN_OBJECT
  115. do
  116. create {FOREIGN_TYPED_OBJECT[CHARACTER]} Result.make(schar, data)
  117. end
  118. create_string (a_string: ABSTRACT_STRING): FOREIGN_OBJECT
  119. -- A newly allocated FOREIGN_OBJECT referring to the interned buffer of `a_string'
  120. do
  121. create {FOREIGN_TYPED_OBJECT[POINTER]} Result.make(pointer, a_string.intern.to_external)
  122. end
  123. create_pointer (data: POINTER): FOREIGN_OBJECT
  124. do
  125. create {FOREIGN_TYPED_OBJECT[POINTER]} Result.make(pointer, data)
  126. end
  127. feature {} -- Objects conversion back from the external call
  128. new_uint8: FOREIGN_OBJECT
  129. local
  130. data: NATURAL_8
  131. do
  132. create {FOREIGN_TYPED_OBJECT[NATURAL_8]} Result.make(uint8, data)
  133. end
  134. new_sint8: FOREIGN_OBJECT
  135. local
  136. data: INTEGER_8
  137. do
  138. create {FOREIGN_TYPED_OBJECT[INTEGER_8]} Result.make(sint8, data)
  139. end
  140. new_uint16: FOREIGN_OBJECT
  141. local
  142. data: NATURAL_16
  143. do
  144. create {FOREIGN_TYPED_OBJECT[NATURAL_16]} Result.make(uint16, data)
  145. end
  146. new_sint16: FOREIGN_OBJECT
  147. local
  148. data: INTEGER_16
  149. do
  150. create {FOREIGN_TYPED_OBJECT[INTEGER_16]} Result.make(sint16, data)
  151. end
  152. new_uint32: FOREIGN_OBJECT
  153. local
  154. data: NATURAL_32
  155. do
  156. create {FOREIGN_TYPED_OBJECT[NATURAL_32]} Result.make(uint32, data)
  157. end
  158. new_sint32: FOREIGN_OBJECT
  159. local
  160. data: INTEGER_32
  161. do
  162. create {FOREIGN_TYPED_OBJECT[INTEGER_32]} Result.make(sint32, data)
  163. end
  164. new_uint64: FOREIGN_OBJECT
  165. local
  166. data: NATURAL_64
  167. do
  168. create {FOREIGN_TYPED_OBJECT[NATURAL_64]} Result.make(uint64, data)
  169. end
  170. new_sint64: FOREIGN_OBJECT
  171. local
  172. data: INTEGER_64
  173. do
  174. create {FOREIGN_TYPED_OBJECT[INTEGER_64]} Result.make(sint64, data)
  175. end
  176. new_float: FOREIGN_OBJECT
  177. local
  178. data: REAL_32
  179. do
  180. create {FOREIGN_TYPED_OBJECT[REAL_32]} Result.make(float, data)
  181. end
  182. new_double: FOREIGN_OBJECT
  183. local
  184. data: REAL_64
  185. do
  186. create {FOREIGN_TYPED_OBJECT[REAL_64]} Result.make(double, data)
  187. end
  188. new_schar: FOREIGN_OBJECT
  189. local
  190. data: CHARACTER
  191. do
  192. create {FOREIGN_TYPED_OBJECT[CHARACTER]} Result.make(schar, data)
  193. end
  194. new_pointer: FOREIGN_OBJECT
  195. local
  196. data: POINTER
  197. do
  198. create {FOREIGN_TYPED_OBJECT[POINTER]} Result.make(pointer, data)
  199. end
  200. new_c_string: FOREIGN_OBJECT
  201. local
  202. data: POINTER
  203. do
  204. create {FOREIGN_TYPED_OBJECT[POINTER]} Result.make(pointer, data)
  205. end
  206. end -- class FOREIGN_TYPES
  207. --
  208. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  209. --
  210. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  211. -- of this software and associated documentation files (the "Software"), to deal
  212. -- in the Software without restriction, including without limitation the rights
  213. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  214. -- copies of the Software, and to permit persons to whom the Software is
  215. -- furnished to do so, subject to the following conditions:
  216. --
  217. -- The above copyright notice and this permission notice shall be included in
  218. -- all copies or substantial portions of the Software.
  219. --
  220. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  221. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  222. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  223. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  224. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  225. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  226. -- THE SOFTWARE.