PIPS
newgen_types.h
Go to the documentation of this file.
1 /*
2 
3  $Id: newgen_types.h 1357 2016-03-02 08:18:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of NewGen.
8 
9  NewGen is free software: you can redistribute it and/or modify it under the
10  terms of the GNU General Public License as published by the Free Software
11  Foundation, either version 3 of the License, or any later version.
12 
13  NewGen is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16  License for more details.
17 
18  You should have received a copy of the GNU General Public License along with
19  NewGen. If not, see <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifndef newgen_types_included
24 #define newgen_types_included
25 
26 /*
27 
28  The implementation of the basic types UNIT, BOOL, TAG and STRING. The
29  others CHAR, INT and FLOAT are provided by C.
30 
31 */
32 
33 
34 /* STRING
35  */
36 #ifdef string
37 #undef string
38 #endif
39 typedef char *string ;
40 #define string_undefined ((string)-15)
41 #define string_undefined_p(s) ((s)==string_undefined)
42 #define copy_string(s) strdup(s)
43 
44 /* _INT
45  */
46 #ifndef _int_undefined
47 /* RK wants an "int" which is the size of a "pointer".
48  * However, the use of the relevant "intptr_t" type in the code
49  * amounts to source file defacing, hence this definition. FC.
50  * The ifndef macro is to avoid a double definition if the type
51  * needs to be defined in the C3/linear library as well.
52  */
53 typedef intptr_t _int;
54 typedef uintptr_t _uint;
55 // also add corresponding format string
56 #include <inttypes.h>
57 #define _intFMT PRIuPTR
58 #define _uintFMT "u" PRIuPTR
59 #define _int_undefined ((_int)-15) /* SG: this is dangerous: a valid value is used to state an invalid value */
60 #define _int_undefined_p(i) ((i)==_int_undefined)
61 
62 #endif /* _int_undefined */
63 
64 /* BOOL
65  */
66 
67 /* SG: _Bool is not compatible with newgen because it does not permit the definition of an `undefined' state
68  we use the int type for compatible behavior */
69 #ifndef BOOLEAN_INCLUDED /* similar to linear ... */
70 #define BOOLEAN_INCLUDED
71 
72 #ifdef bool
73  #error newgen header not compatible with stdbool.h
74 #endif
75 
76 /* we cannot use an enum or stdbool because we need to be compatible with newgen,
77  * thus boolean need to handle 3 states : true, false, and undefined */
78 typedef int bool;
79 
80 #define false 0
81 #define true 1
82 #endif
83 
84 #define bool_undefined ((bool)-15) /* SG: this is a dangerous semantic: bool_undefined evaluates to true ... */
85 #define bool_undefined_p(b) ((b)==bool_undefined)
86 
87 
88 
89 
90 /* TAG
91  */
92 typedef int tag;
93 #define tag_undefined (-3)
94 
95 /* UNIT
96  */
97 typedef int unit ;
98 #define UU ((void*)0)
99 #define UUINT(i) ((void*)(i))
100 
101 /* ARRAY
102  */
103 #define array_undefined NULL
104 #define array_undefined_p(a) ((a)==NULL)
105 
106 typedef struct cons * list;
107 
108 // functional types
109 typedef bool (*gen_filter_func_t)(const void *);
110 typedef bool (*gen_filter2_func_t)(const void *, const void *);
111 typedef string (*gen_string_func_t)(const void *);
112 // for qsort: void * points to a pointer to the newgen type
113 // so it is really "gen_chunk**", i.e. "entity*" or "statement*"
114 typedef int (*gen_cmp_func_t)(const void *, const void *);
115 typedef bool (*gen_eq_func_t)(const void *, const void *);
116 typedef void (*gen_iter_func_t)(void *);
117 
118 /* Some CPP magics to get a line-number-dependent "unique" identifier to
119  have list iteration variable with unique names and avoid conflicts if
120  we have multiple FOREACH in the same statement block:
121 */
122 // some magic is needed so that __LINE__ is really substituted with ##
123 #define NEWGEN_MACRO_NAME_1(prefix, x) prefix##x
124 #define NEWGEN_MACRO_NAME_2(prefix, x) NEWGEN_MACRO_NAME_1 (prefix, x)
125 // NGMID = NewGen Macro-generated IDitenfier
126 #define NGMID(f) NEWGEN_MACRO_NAME_2(_ ## f ## _, __LINE__)
127 
128 // obsolete?
129 #ifdef __STRICT_ANSI__
130 #define GEN_PROTO(x) x
131 #else
132 #ifdef __STDC__
133 #define GEN_PROTO(x) x
134 #else
135 #define GEN_PROTO(x) ()
136 #endif /* __STDC__ */
137 #endif /* __STRICT_ANSI__ */
138 
139 #endif /* newgen_types_included */
void const char const char const int
int bool
we cannot use an enum or stdbool because we need to be compatible with newgen, thus boolean need to h...
Definition: newgen_types.h:78
bool(* gen_filter2_func_t)(const void *, const void *)
Definition: newgen_types.h:110
int tag
TAG.
Definition: newgen_types.h:92
string(* gen_string_func_t)(const void *)
Definition: newgen_types.h:111
char * string
STRING.
Definition: newgen_types.h:39
void(* gen_iter_func_t)(void *)
Definition: newgen_types.h:116
intptr_t _int
_INT
Definition: newgen_types.h:53
int unit
UNIT.
Definition: newgen_types.h:97
struct cons * list
Definition: newgen_types.h:106
uintptr_t _uint
Definition: newgen_types.h:54
bool(* gen_filter_func_t)(const void *)
Definition: newgen_types.h:109
bool(* gen_eq_func_t)(const void *, const void *)
Definition: newgen_types.h:115
int(* gen_cmp_func_t)(const void *, const void *)
Definition: newgen_types.h:114
#define intptr_t
Definition: stdint.in.h:294
#define uintptr_t
Definition: stdint.in.h:295
The structure used to build lists in NewGen.
Definition: newgen_list.h:41