Debian Codegraph @

3rdparty/flite_hts_engine/flite/include/cst_val_const.h

raw symbols SCIP
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2001 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 /* Author: Alan W Black ([email protected]) */
34 /* Date: January 2001 */
35 /*************************************************************************/
36 /* */
37 /* Const Vals, and macros to define them */
38 /* */
39 /* Before you give up in disgust bear with me on this. Every single */
40 /* line in this file has been *very* carefully decided on after much */
41 /* thought, experimentation and reading more specs of the C language */
42 /* than most people even thought existed. However inspite of that, the */
43 /* result is still unsatisfying from an elegance point of view but the */
44 /* given all the constraints this is probably the best compromise. */
45 /* */
46 /* This file offers macros for defining const cst_vals. I know many */
47 /* are already laughing at me for wanting runtime types on objects and */
48 /* will use this code as exemplars of why this should be done in C++, I */
49 /* say good luck to them with their 4M footprint while I go for my */
50 /* 50K footprint. But I *will* do cst_vals in 8 bytes and I *will* */
51 /* have them defined const so they are in the text segment */
52 /* */
53 /* The problem here is that there is not yet a standard way to do */
54 /* initialization of unions. There is one in the C99 standard and GCC */
55 /* already supports it, but other compilers do not so I can't use that */
56 /* */
57 /* So I need a way to make an object that will have the right 8 bytes */
58 /* for ints, floats, strings and cons cells that will work on any C */
59 /* compiler and will be of type const cst_val. That unfortunately */
60 /* isn't trivial. */
61 /* */
62 /* For the time being ignoring byte order, and address size, which */
63 /* will be ignored in the particular discuss (though dealt with below) */
64 /* I'd like to do something like */
65 /* */
66 /* const cst_val fredi = { CST_VAL_TYPE_INT,-1, 42 }; */
67 /* const cst_val fredf = { CST_VAL_TYPE_FLOAT,-1, 4.2 }; */
68 /* const cst_val freds = { CST_VAL_TYPE_STRING,-1, "42" }; */
69 /* */
70 /* Even if you accept warnings this isn't going to work, if you add */
71 /* extra {} you can get rid of some warnings but the fval/ival/ *vval */
72 /* part isn't going to work, the compiler *may* try to take the value */
73 /* and assign it using the type of the first field defined in the */
74 /* union. This could be made to work for ints and void* as pointers */
75 /* can be used as ints (even of 64 bit architectures) but the float */
76 /* isn't going to work. Casting will cause the float to be changed to */
77 /* an int by CPP which isn't what you want, what you want is that the */
78 /* four byte region gets filled with the four bytes that represent the */
79 /* float itself. Now you could get the four byte represention of the */
80 /* float and pretend that is an int (0xbfff9a4 for 4.2 on intel), that */
81 /* would work but that doesn't seem satifying and I'd need to have a */
82 /* preprocessor that could convert that. You could make atoms always */
83 /* have a pointer to another piece of memory, but that would take up */
84 /* another 4 bytes not just for these constants but all other cst_vals */
85 /* create */
86 /* */
87 /* So you could do */
88 /* */
89 /* const cst_val_int fredi = { CST_VAL_TYPE_INT,-1, 42 }; */
90 /* const cst_val_float fredf = { CST_VAL_TYPE_FLOAT,-1, 4.2 }; */
91 /* const cst_val_string freds = { CST_VAL_TYPE_STRING,-1, "42" }; */
92 /* */
93 /* Though that's a slippery slope I don't want to have these explicit */
94 /* new types, the first short defines the type perfectly adequately */
95 /* and the whole point of runtime types is that there is one object */
96 /* type. */
97 /* */
98 /* Well just initialize them at runtime, but, that isn't thread safe, */
99 /* slows down startup, requires a instance implicitly in the code and */
100 /* on the heap. As these are const, they should go in ROM. */
101 /* */
102 /* At this moment, I think the second version is the least problematic */
103 /* though it makes defining val_consts more unpleasant than they should */
104 /* be and forces changes elsewhere in the code even when the compiler */
105 /* does support initialization of unions */
106 /* */
107 /* */
108 /*************************************************************************/
109
110 /* ----------------------------------------------------------------- */
111 /* The English TTS System "Flite+hts_engine" */
112 /* developed by HTS Working Group */
113 /* http://hts-engine.sourceforge.net/ */
114 /* ----------------------------------------------------------------- */
115 /* */
116 /* Copyright (c) 2005-2013 Nagoya Institute of Technology */
117 /* Department of Computer Science */
118 /* */
119 /* 2005-2008 Tokyo Institute of Technology */
120 /* Interdisciplinary Graduate School of */
121 /* Science and Engineering */
122 /* */
123 /* All rights reserved. */
124 /* */
125 /* Redistribution and use in source and binary forms, with or */
126 /* without modification, are permitted provided that the following */
127 /* conditions are met: */
128 /* */
129 /* - Redistributions of source code must retain the above copyright */
130 /* notice, this list of conditions and the following disclaimer. */
131 /* - Redistributions in binary form must reproduce the above */
132 /* copyright notice, this list of conditions and the following */
133 /* disclaimer in the documentation and/or other materials provided */
134 /* with the distribution. */
135 /* - Neither the name of the HTS working group nor the names of its */
136 /* contributors may be used to endorse or promote products derived */
137 /* from this software without specific prior written permission. */
138 /* */
139 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND */
140 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, */
141 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
142 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
143 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS */
144 /* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, */
145 /* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
146 /* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, */
147 /* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
148 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, */
149 /* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY */
150 /* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
151 /* POSSIBILITY OF SUCH DAMAGE. */
152 /* ----------------------------------------------------------------- */
153
154 #ifndef _CST_VAL_CONSTS_H__
155 #define _CST_VAL_CONSTS_H__
156
157 #include "cst_val_defs.h"
158
159 /* There is built-in int to string conversions here for numbers */
160 /* up to 20, note if you make this bigger you have to hand change */
161 /* other things too */
162 #define CST_CONST_INT_MAX 19
163
164 #ifndef NO_UNION_INITIALIZATION
165
166 /* This is the simple way when initialization of unions is supported */
167
168 #define DEF_CONST_VAL_INT(N,V) const cst_val N = {{.a={.type=CST_VAL_TYPE_INT,.ref_count=-1,.v={.ival=V}}}}
169 #define DEF_CONST_VAL_STRING(N,S) const cst_val N = {{.a={.type=CST_VAL_TYPE_STRING,.ref_count=-1,.v={.vval= (void *)S}}}}
170 #define DEF_CONST_VAL_FLOAT(N,F) const cst_val N = {{.a={.type=CST_VAL_TYPE_FLOAT,.ref_count=-1,.v={.fval=F}}}}
171 #define DEF_CONST_VAL_CONS(N,A,D) const cst_val N = {{.cc={.car=A,.cdr=D }}}
172
173 extern const cst_val val_int_0;
174 extern const cst_val val_int_1;
175 extern const cst_val val_int_2;
176 extern const cst_val val_int_3;
177 extern const cst_val val_int_4;
178 extern const cst_val val_int_5;
179 extern const cst_val val_int_6;
180 extern const cst_val val_int_7;
181 extern const cst_val val_int_8;
182 extern const cst_val val_int_9;
183 extern const cst_val val_int_10;
184 extern const cst_val val_int_11;
185 extern const cst_val val_int_12;
186 extern const cst_val val_int_13;
187 extern const cst_val val_int_14;
188 extern const cst_val val_int_15;
189 extern const cst_val val_int_16;
190 extern const cst_val val_int_17;
191 extern const cst_val val_int_18;
192 extern const cst_val val_int_19;
193
194 extern const cst_val val_string_0;
195 extern const cst_val val_string_1;
196 extern const cst_val val_string_2;
197 extern const cst_val val_string_3;
198 extern const cst_val val_string_4;
199 extern const cst_val val_string_5;
200 extern const cst_val val_string_6;
201 extern const cst_val val_string_7;
202 extern const cst_val val_string_8;
203 extern const cst_val val_string_9;
204 extern const cst_val val_string_10;
205 extern const cst_val val_string_11;
206 extern const cst_val val_string_12;
207 extern const cst_val val_string_13;
208 extern const cst_val val_string_14;
209 extern const cst_val val_string_15;
210 extern const cst_val val_string_16;
211 extern const cst_val val_string_17;
212 extern const cst_val val_string_18;
213 extern const cst_val val_string_19;
214
215 #else
216 /* Only GCC seems to currently support the C99 standard for giving */
217 /* explicit names for fields for initializing unions, because we want */
218 /* things to be const, and to be small structures this is really useful */
219 /* thus for compilers not supporting no_union_initization we use other */
220 /* structure that we know (hope ?) are the same size and use agressive */
221 /* casting. The goal here is wholly justified by the method here isn't */
222 /* pretty */
223
224 /* These structures are defined *solely* to get round initialization */
225 /* problems if you need to use these in any code you are using your are */
226 /* unquestionably doing the wrong thing */
227 typedef struct cst_val_atom_struct_float {
228 #ifdef WORDS_BIGENDIAN
229 #if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8
230 int ref_count;
231 int type;
232 #else
233 short ref_count;
234 short type; /* order is here important */
235 #endif
236 #else
237 #if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8
238 int type;
239 int ref_count;
240 #else
241 short type; /* order is here important */
242 short ref_count;
243 #endif
244 #endif
245 float fval;
246 } cst_val_float;
247
248 typedef struct cst_val_atom_struct_int {
249 #ifdef WORDS_BIGENDIAN
250 #if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8
251 int ref_count;
252 int type;
253 #else
254 short ref_count;
255 short type; /* order is here important (and unintuitive) */
256 #endif
257 #else
258 #if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8
259 int type;
260 int ref_count;
261 #else
262 short type; /* order is here important */
263 short ref_count;
264 #endif
265 #endif
266 int ival;
267 } cst_val_int;
268
269 typedef struct cst_val_atom_struct_void {
270 #ifdef WORDS_BIGENDIAN
271 #if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8
272 int ref_count;
273 int type;
274 #else
275 short ref_count;
276 short type; /* order is here important */
277 #endif
278 #else
279 #if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P == 8
280 int type;
281 int ref_count;
282 #else
283 short type; /* order is here important */
284 short ref_count;
285 #endif
286 #endif
287 void *vval;
288 } cst_val_void;
289
290 #ifdef WORDS_BIGENDIAN
291 #define DEF_CONST_VAL_INT(N,V) const cst_val_int N={-1, CST_VAL_TYPE_INT, V}
292 #define DEF_CONST_VAL_STRING(N,S) const cst_val_void N={-1,CST_VAL_TYPE_STRING,(void *)S}
293 #define DEF_CONST_VAL_FLOAT(N,F) const cst_val_float N={-1,CST_VAL_TYPE_FLOAT,(float)F}
294 #else
295 #define DEF_CONST_VAL_INT(N,V) const cst_val_int N={CST_VAL_TYPE_INT,-1,V}
296 #define DEF_CONST_VAL_STRING(N,S) const cst_val_void N={CST_VAL_TYPE_STRING,-1,(void *)S}
297 #define DEF_CONST_VAL_FLOAT(N,F) const cst_val_float N={CST_VAL_TYPE_FLOAT,-1,(float)F}
298 #endif
299 #define DEF_CONST_VAL_CONS(N,A,D) const cst_val_cons N={A,D}
300
301 /* in the non-union intialization version we these consts have to be */
302 /* more typed than need, we'll cast the back later */
303 extern const cst_val_int val_int_0;
304 extern const cst_val_int val_int_1;
305 extern const cst_val_int val_int_2;
306 extern const cst_val_int val_int_3;
307 extern const cst_val_int val_int_4;
308 extern const cst_val_int val_int_5;
309 extern const cst_val_int val_int_6;
310 extern const cst_val_int val_int_7;
311 extern const cst_val_int val_int_8;
312 extern const cst_val_int val_int_9;
313 extern const cst_val_int val_int_10;
314 extern const cst_val_int val_int_11;
315 extern const cst_val_int val_int_12;
316 extern const cst_val_int val_int_13;
317 extern const cst_val_int val_int_14;
318 extern const cst_val_int val_int_15;
319 extern const cst_val_int val_int_16;
320 extern const cst_val_int val_int_17;
321 extern const cst_val_int val_int_18;
322 extern const cst_val_int val_int_19;
323
324 extern const cst_val_void val_string_0;
325 extern const cst_val_void val_string_1;
326 extern const cst_val_void val_string_2;
327 extern const cst_val_void val_string_3;
328 extern const cst_val_void val_string_4;
329 extern const cst_val_void val_string_5;
330 extern const cst_val_void val_string_6;
331 extern const cst_val_void val_string_7;
332 extern const cst_val_void val_string_8;
333 extern const cst_val_void val_string_9;
334 extern const cst_val_void val_string_10;
335 extern const cst_val_void val_string_11;
336 extern const cst_val_void val_string_12;
337 extern const cst_val_void val_string_13;
338 extern const cst_val_void val_string_14;
339 extern const cst_val_void val_string_15;
340 extern const cst_val_void val_string_16;
341 extern const cst_val_void val_string_17;
342 extern const cst_val_void val_string_18;
343 extern const cst_val_void val_string_19;
344
345 #endif
346
347 #define DEF_STATIC_CONST_VAL_INT(N,V) static DEF_CONST_VAL_INT(N,V)
348 #define DEF_STATIC_CONST_VAL_STRING(N,S) static DEF_CONST_VAL_STRING(N,S)
349 #define DEF_STATIC_CONST_VAL_FLOAT(N,F) static DEF_CONST_VAL_FLOAT(N,F)
350 #define DEF_STATIC_CONST_VAL_CONS(N,A,D) static DEF_CONST_VAL_CONS(N,A,D)
351
352 /* Some actual val consts */
353 /* The have casts as in the non-union intialize case the casts are necessary */
354 /* but in the union initial case these casts are harmless */
355
356 #define VAL_INT_0 (cst_val *)&val_int_0
357 #define VAL_INT_1 (cst_val *)&val_int_1
358 #define VAL_INT_2 (cst_val *)&val_int_2
359 #define VAL_INT_3 (cst_val *)&val_int_3
360 #define VAL_INT_4 (cst_val *)&val_int_4
361 #define VAL_INT_5 (cst_val *)&val_int_5
362 #define VAL_INT_6 (cst_val *)&val_int_6
363 #define VAL_INT_7 (cst_val *)&val_int_7
364 #define VAL_INT_8 (cst_val *)&val_int_8
365 #define VAL_INT_9 (cst_val *)&val_int_9
366 #define VAL_INT_10 (cst_val *)&val_int_10
367 #define VAL_INT_11 (cst_val *)&val_int_11
368 #define VAL_INT_12 (cst_val *)&val_int_12
369 #define VAL_INT_13 (cst_val *)&val_int_13
370 #define VAL_INT_14 (cst_val *)&val_int_14
371 #define VAL_INT_15 (cst_val *)&val_int_15
372 #define VAL_INT_16 (cst_val *)&val_int_16
373 #define VAL_INT_17 (cst_val *)&val_int_17
374 #define VAL_INT_18 (cst_val *)&val_int_18
375 #define VAL_INT_19 (cst_val *)&val_int_19
376
377 const cst_val *val_int_n(int n);
378
379 #define VAL_STRING_0 (cst_val *)&val_string_0
380 #define VAL_STRING_1 (cst_val *)&val_string_1
381 #define VAL_STRING_2 (cst_val *)&val_string_2
382 #define VAL_STRING_3 (cst_val *)&val_string_3
383 #define VAL_STRING_4 (cst_val *)&val_string_4
384 #define VAL_STRING_5 (cst_val *)&val_string_5
385 #define VAL_STRING_6 (cst_val *)&val_string_6
386 #define VAL_STRING_7 (cst_val *)&val_string_7
387 #define VAL_STRING_8 (cst_val *)&val_string_8
388 #define VAL_STRING_9 (cst_val *)&val_string_9
389 #define VAL_STRING_10 (cst_val *)&val_string_10
390 #define VAL_STRING_11 (cst_val *)&val_string_11
391 #define VAL_STRING_12 (cst_val *)&val_string_12
392 #define VAL_STRING_13 (cst_val *)&val_string_13
393 #define VAL_STRING_14 (cst_val *)&val_string_14
394 #define VAL_STRING_15 (cst_val *)&val_string_15
395 #define VAL_STRING_16 (cst_val *)&val_string_16
396 #define VAL_STRING_17 (cst_val *)&val_string_17
397 #define VAL_STRING_18 (cst_val *)&val_string_18
398 #define VAL_STRING_19 (cst_val *)&val_string_19
399
400 const cst_val *val_string_n(int n);
401
402
403 #endif