/src/tools/wrappers-generator/typedefs.e

http://github.com/tybor/Liberty · Specman e · 327 lines · 248 code · 49 blank · 30 comment · 3 complexity · 772e34182dffb9e32429614427d454de MD5 · raw file

  1. class TYPEDEFS
  2. -- A dictionary of C_TYPEDEFs accessible by their names
  3. -- The contained typedefs will be wrapped together as dummy queries into a deferred class
  4. -- When the wrappers generator command is invoked with the proper flag
  5. -- ("--standard-typedefs" ) it will also emit the queries for C types that
  6. -- have different sizes on different architectures and for the type
  7. -- definition of C99 standard.
  8. -- Each query is named like a C typedef and its Result type is the
  9. -- Eiffel equivalent of the fundamental type the typedef refers to.
  10. -- For example:
  11. -- gsize: INTEGER_64
  12. -- -- typedef unsigned long int gsize;
  13. -- do
  14. -- end
  15. -- Those queries shall never be invoked but rather used in other
  16. -- features as anchors like: do_stuff (a_size: like gsize)
  17. inherit
  18. LINKED_LIST[C_TYPEDEF]
  19. insert
  20. SHARED_SETTINGS
  21. SHARED_COLLECTIONS
  22. create {ANY}
  23. make
  24. feature {ANY}
  25. file: OUTPUT_STREAM
  26. emit_wrappers
  27. local
  28. path: POSIX_PATH_NAME
  29. do
  30. create path.make_from_string(directory)
  31. path.add_last(settings.typedefs.as_lower + once ".e")
  32. log(once "Outputting anchor queries (for typedefs) into #(1) on `#(2)'.%N"
  33. # settings.typedefs # path.to_string )
  34. create {TEXT_FILE_WRITE} file.connect_to(path.to_string)
  35. file.put_string(automatically_generated_header)
  36. file.put_string(deferred_class)
  37. file.put_string(settings.typedefs)
  38. file.put_new_line
  39. file.put_string(inherits_string)
  40. if settings.are_standard_typedefs_emitted then
  41. file.put_string(typedefs_features_header)
  42. emit_variable_sized_typedefs
  43. -- emit_standard_typedefs
  44. else
  45. file.put_string("%T" | settings.standard_typedefs_class | "%N%N")
  46. end
  47. file.put_string(typedefs_features_header)
  48. for_each(agent (a_typedef:C_TYPEDEF) do
  49. if a_typedef.is_to_be_emitted then
  50. log("Wrapping typedef #(1)%N" # a_typedef.c_string_name)
  51. a_typedef.wrap_on(file)
  52. else
  53. log("Typedef '#(1)' (at line #(2)) is not to be emitted%N" # a_typedef.c_string_name # &a_typedef.line )
  54. end
  55. end(?))
  56. file.put_string(footer)
  57. file.disconnect
  58. file := Void
  59. end
  60. emit_variable_sized_typedefs
  61. -- Emit dummy queries useful for anchored declarations (i.e. "like
  62. -- long") for C types that can have different sizes on different
  63. -- architectures.
  64. do
  65. file.put_string("feature {WRAPPER_HANDLER} -- variable-size types%N%
  66. % long: INTEGER_#(1)%N%
  67. % -- a query with the same type of c 'long int'. useful when dealing with%N%
  68. % -- code that uses long int variable: just insert th class and mark%N%
  69. % -- the type as 'like long'%N%
  70. % do%N%
  71. % -- empty by design%N%
  72. % end%N%
  73. %%N%
  74. % long_unsigned: NATURAL_#(2)%N%
  75. % -- a query with the same type of c 'long unsigned int'. useful when dealing with%N%
  76. % -- code that uses long int variable: just insert th class and mark%N%
  77. % -- the type as 'like long_unsigned'%N%
  78. % do%N%
  79. % -- empty by design%N%
  80. % end%N%N" # &long_int_size # &long_unsigned_int_size)
  81. end
  82. emit_standard_typedefs
  83. do
  84. file.put_string("feature {WRAPPER_HANDLER} -- Memory related type definitions%N%
  85. % size_t: NATURAL_#(1) do end%N%N%
  86. % ssize_t: INTEGER_#(2) do end%N%N%
  87. % ptrdiff_t: INTEGER_#(3) do end%N%N" # &size_t_size # &ssize_t_size # &ptrdiff_t_size)
  88. file.put_string("feature {WRAPPER_HANDLER} -- Standard C type definitions%N%
  89. % -- All those queries are empty by design, meant to be used as anchored declarations%N%N%
  90. % -- Exact-width integer types%N%
  91. % -- Integer types having exactly the specified width %N%
  92. % int8_t: INTEGER_#(1) do end%N%
  93. % uint8_t: NATURAL_#(2) do end%N%
  94. % int16_t: INTEGER_#(3) do end%N%
  95. % uint16_t: NATURAL_#(4) do end%N%
  96. % int32_t: INTEGER_#(5) do end%N%
  97. % uint32_t: NATURAL_#(6) do end%N%
  98. % int64_t: INTEGER_#(7) do end%N%
  99. % uint64_t: NATURAL_#(8) do end%N%
  100. %%N" # &int8_t_size # &uint8_t_size # &int16_t_size # &uint16_t_size # &int32_t_size # &uint32_t_size # &int64_t_size # &uint64_t_size)
  101. file.put_string(" -- Integer types capable of holding object pointers%N%
  102. % -- These allow you to declare variables of the same size as a pointer.%N%
  103. % intptr_t: INTEGER_#(1) do end%N%
  104. % uintptr_t: NATURAL_#(2) do end%N%
  105. %%N" # &intptr_t_size # &uintptr_t_size)
  106. file.put_string(" -- Minimum-width integer types%N%
  107. % -- Integer types having at least the specified width%N%
  108. % int_least8_t: INTEGER_#(1) do end%N%
  109. % uint_least8_t: NATURAL_#(2) do end%N%
  110. % int_least16_t: INTEGER_#(3) do end%N%
  111. % uint_least16_t: NATURAL_#(4) do end%N%
  112. % int_least32_t: INTEGER_#(5) do end%N%
  113. % uint_least32_t: NATURAL_#(6) do end%N%
  114. % int_least64_t: INTEGER_#(7) do end%N%
  115. % uint_least64_t: NATURAL_#(8) do end%N%
  116. %%N" # &int_least8_t_size # &uint_least8_t_size # &int_least16_t_size # &uint_least16_t_size # &int_least32_t_size # &uint_least32_t_size # &int_least64_t_size # &uint_least64_t_size)
  117. file.put_string(" -- Fastest minimum-width integer types%N%
  118. % -- Integer types being usually fastest having at least the specified width%N%
  119. % int_fast8_t: INTEGER_#(1) do end%N%
  120. % uint_fast8_t: NATURAL_#(2) do end%N%
  121. % int_fast16_t: INTEGER_#(3) do end%N%
  122. % uint_fast16_t: NATURAL_#(4) do end%N%
  123. % int_fast32_t: INTEGER_#(5) do end%N%
  124. % uint_fast32_t: NATURAL_#(6) do end%N%
  125. % int_fast64_t: INTEGER_#(7) do end%N%
  126. % uint_fast64_t: NATURAL_#(8) do end%N%
  127. %%N" # &int_fast8_t_size # &uint_fast8_t_size # &int_fast16_t_size # &uint_fast16_t_size # &int_fast32_t_size # &uint_fast32_t_size # &int_fast64_t_size # &uint_fast64_t_size)
  128. file.put_string(" -- Greatest-width integer types%N%
  129. % -- Types designating integer data capable of representing any value of any integer type in the corresponding signed or unsigned category%N%
  130. % intmax_t: INTEGER_#(1) do end%N%
  131. % uintmax_t: NATURAL_#(2) do end%N%
  132. %%N" # &intmax_t_size # &uintmax_t_size)
  133. end
  134. feature {} -- Actual size queries
  135. long_int_size: INTEGER
  136. external "C inline"
  137. alias "(8 * sizeof(long int))"
  138. end
  139. long_unsigned_int_size: INTEGER
  140. external "C inline"
  141. alias "(8 * sizeof(long unsigned int))"
  142. end
  143. size_t_size: INTEGER
  144. external "C inline use <stddef.h>"
  145. alias "(8 * sizeof(size_t))"
  146. end
  147. ssize_t_size: INTEGER
  148. external "C inline use <stddef.h>"
  149. alias "(8 * sizeof(ssize_t))"
  150. end
  151. ptrdiff_t_size: INTEGER
  152. external "C inline use <stddef.h>"
  153. alias "(8 * sizeof(ptrdiff_t))"
  154. end
  155. int8_t_size: INTEGER
  156. external "C inline use <stdint.h>"
  157. alias "(8 * sizeof(int8_t))"
  158. end
  159. uint8_t_size: INTEGER
  160. external "C inline use <stdint.h>"
  161. alias "(8 * sizeof(uint8_t))"
  162. end
  163. int16_t_size: INTEGER
  164. external "C inline use <stdint.h>"
  165. alias "(8 * sizeof(int16_t))"
  166. end
  167. uint16_t_size: INTEGER
  168. external "C inline use <stdint.h>"
  169. alias "(8 * sizeof(uint16_t))"
  170. end
  171. int32_t_size: INTEGER
  172. external "C inline use <stdint.h>"
  173. alias "(8 * sizeof(int32_t))"
  174. end
  175. uint32_t_size: INTEGER
  176. external "C inline use <stdint.h>"
  177. alias "(8 * sizeof(uint32_t))"
  178. end
  179. int64_t_size: INTEGER
  180. external "C inline use <stdint.h>"
  181. alias "(8 * sizeof(int64_t))"
  182. end
  183. uint64_t_size: INTEGER
  184. external "C inline use <stdint.h>"
  185. alias "(8 * sizeof(uint64_t))"
  186. end
  187. intptr_t_size: INTEGER
  188. external "C inline use <stdint.h>"
  189. alias "(8 * sizeof(intptr_t))"
  190. end
  191. uintptr_t_size: INTEGER
  192. external "C inline use <stdint.h>"
  193. alias "(8 * sizeof(uintptr_t))"
  194. end
  195. int_least8_t_size: INTEGER
  196. external "C inline use <stdint.h>"
  197. alias "(8 * sizeof(int_least8_t))"
  198. end
  199. uint_least8_t_size: INTEGER
  200. external "C inline use <stdint.h>"
  201. alias "(8 * sizeof(uint_least8_t))"
  202. end
  203. int_least16_t_size: INTEGER
  204. external "C inline use <stdint.h>"
  205. alias "(8 * sizeof(int_least16_t))"
  206. end
  207. uint_least16_t_size: INTEGER
  208. external "C inline use <stdint.h>"
  209. alias "(8 * sizeof(uint_least16_t))"
  210. end
  211. int_least32_t_size: INTEGER
  212. external "C inline use <stdint.h>"
  213. alias "(8 * sizeof(int_least32_t))"
  214. end
  215. uint_least32_t_size: INTEGER
  216. external "C inline use <stdint.h>"
  217. alias "(8 * sizeof(uint_least32_t))"
  218. end
  219. int_least64_t_size: INTEGER
  220. external "C inline use <stdint.h>"
  221. alias "(8 * sizeof(int_least64_t))"
  222. end
  223. uint_least64_t_size: INTEGER
  224. external "C inline use <stdint.h>"
  225. alias "(8 * sizeof(uint_least64_t))"
  226. end
  227. int_fast8_t_size: INTEGER
  228. external "C inline use <stdint.h>"
  229. alias "(8 * sizeof(int_fast8_t))"
  230. end
  231. uint_fast8_t_size: INTEGER
  232. external "C inline use <stdint.h>"
  233. alias "(8 * sizeof(uint_fast8_t))"
  234. end
  235. int_fast16_t_size: INTEGER
  236. external "C inline use <stdint.h>"
  237. alias "(8 * sizeof(int_fast16_t))"
  238. end
  239. uint_fast16_t_size: INTEGER
  240. external "C inline use <stdint.h>"
  241. alias "(8 * sizeof(uint_fast16_t))"
  242. end
  243. int_fast32_t_size: INTEGER
  244. external "C inline use <stdint.h>"
  245. alias "(8 * sizeof(int_fast32_t))"
  246. end
  247. uint_fast32_t_size: INTEGER
  248. external "C inline use <stdint.h>"
  249. alias "(8 * sizeof(uint_fast32_t))"
  250. end
  251. int_fast64_t_size: INTEGER
  252. external "C inline use <stdint.h>"
  253. alias "(8 * sizeof(int_fast64_t))"
  254. end
  255. uint_fast64_t_size: INTEGER
  256. external "C inline use <stdint.h>"
  257. alias "(8 * sizeof(uint_fast64_t))"
  258. end
  259. intmax_t_size: INTEGER
  260. external "C inline use <stdint.h>"
  261. alias "(8 * sizeof(intmax_t))"
  262. end
  263. uintmax_t_size: INTEGER
  264. external "C inline use <stdint.h>"
  265. alias "(8 * sizeof(uintmax_t))"
  266. end
  267. end -- class TYPEDEFS
  268. -- Copyright (C) 2008-2017: Paolo Redaelli
  269. -- wrappers-generator is free software: you can redistribute it and/or modify it
  270. -- under the terms of the GNU General Public License as publhed by the Free
  271. -- Software Foundation, either version 2 of the License, or (at your option)
  272. -- any later version.
  273. -- wrappers-generator is distributed in the hope that it will be useful, but
  274. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  275. -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  276. -- more details.
  277. -- You should have received a copy of the GNU General Public License along with
  278. -- th program. If not, see <http://www.gnu.org/licenses/>.