PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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