PIPS
newgen_include.h
Go to the documentation of this file.
1 /*
2 
3  $Id: newgen_include.h 1387 2020-07-06 08:36:33Z 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 #include "newgen_types.h"
24 #include "newgen_set.h"
25 
26 /* Types of domain
27  */
29  UNDEF_DT = 0,
31  BASIS_DT = 2,
32  LIST_DT = 3,
33  ARRAY_DT = 4,
35  IMPORT_DT = 6,
36  SET_DT = 7
37 };
38 
39 /* Operators for CONSTRUCTED domains
40  */
42  UNDEF_OP = 0,
43  AND_OP = 1,
44  OR_OP = 2,
45  ARROW_OP = 3
46 };
47 
48 /* The UNIT_TYPE_NAME is the used to type expressions which only perform
49  side-effects. It is mainly used to build sets. */
50 
51 #define UNIT_TYPE_NAME "unit"
52 
53 /* A list type constructor */
54 
55 #define DEFLIST(type,cartype,carname)\
56  struct type {\
57  cartype carname ;\
58  struct type *cdr ;\
59  }
60 
61 DEFLIST(namelist,char *,name) ;
62 DEFLIST(intlist,int,val) ;
63 DEFLIST(domainlist,union domain *,domain) ;
64 
65 /* actually defined in tabulated.c */
66 typedef struct _gtp * gen_tabulated_p;
67 
68 union domain ;
69 struct inlinable ;
70 struct gen_binding {
71  char * name;
72  int compiled;
73  size_t size; /* number of chunks to hold this data. */
75  union domain *domain ;
76  struct inlinable *inlined ;
77 } ;
78 
79 /* The implementation of tabulated domains */
80 extern struct gen_binding Domains[], *Tabulated_bp ;
81 
82 /* The root of the gen_chunk read with READ_CHUNK. */
83 extern gen_chunk *Read_chunk ;
84 
85 /* A DOMAIN union describes the structure of a user type.
86 
87  The (STRUCT BINDING *) are used either to point to strings (during
88  the parsing of the specifications), or to gen_bindings (after compilation).
89 
90  TYPE and CONSTRUCTOR members have to be at the same offset */
91 
92 /* FC, 10/06/1994, set_type in se moved.
93  *
94  * common part assumed for all: type
95  * common part assumed for ba, li, se, ar:
96  * type, constructor, persistant and one gen_binding
97  *
98  */
99 union domain {
100  struct { /* EXTERNAL */
101  int type ;
102  void* (*read)(FILE*, int(*)(void)) ;
103  void (*write)(FILE*, void*) ;
104  void (*free)(void*) ;
105  void* (*copy)(void*) ;
107  } ex ;
108  struct { /* BASIC */
109  enum type_of_domain type;
110  char *constructor ;
113  } ba ;
114  struct { /* LIST */
115  int type ;
116  char *constructor ;
117  int persistant ;
119  } li ;
120  struct { /* SET */
121  int type ;
122  char *constructor ;
123  int persistant ;
124  struct gen_binding *element ;
126  } se ;
127  struct { /* ARRAY */
128  int type;
129  char *constructor;
130  int persistant;
131  struct gen_binding * element;
132  struct intlist * dimensions;
133  } ar ;
134  struct { /* CONSTRUCTED */
135  int type ;
136  enum domain_operator op ;
137  int first ;
138  struct domainlist *components ;
139  } co ;
140  struct { /* IMPORT (another newgen type, not yet defined) */
141  int type ;
142  char *filename ;
143  } im ;
144 } ;
145 
146 /* MAX_DOMAIN is the maximum number of entries in the DOMAINS table */
147 #define MAX_DOMAIN 300
148 
149 /* hack to walk thru tabulateds... */
150 extern struct gen_binding *Tabulated_bp ;
151 
152 /* Different kinds of BINDING structure pointers */
153 
154 #define IS_INLINABLE(bp) ((bp)->inlined != NULL)
155 #define IS_EXTERNAL(bp) ((bp)->domain->ba.type == EXTERNAL_DT)
156 #define IS_TABULATED(bp) ((bp)->tabulated!=NULL)
157 #define IS_IMPORT(bp) ((bp)->domain->ba.type == IMPORT_DT)
158 #define IS_NORMAL(bp) \
159  (!IS_INLINABLE(bp)&&!IS_EXTERNAL(bp)&&!IS_TABULATED(bp))
160 
161 /* Domains is the symbol table for user defined types. COMPILED refers to
162  inlined data types. INDEX is used whenever the type is used with
163  refs and defs (ALLOC is the next place to allocate tabulated values). */
164 
165 extern struct gen_binding Domains[] ;
166 
167 /* Action parameter to the LOOKUP() function in the symbol table. Are
168  looking for a new symbol or an old one ? */
169 
170 #define NEW_BINDING 1
171 #define OLD_BINDING 2
172 
173 extern struct gen_binding *lookup() ;
174 extern struct gen_binding *new_binding() ;
175 
176 /* Used to check, while parsing specs, that a constructed domain use
177  only one operator type. */
178 
179 extern int Current_op ;
180 
181 /* To manage imported domains:
182 
183  - NUMBER_IMPORTS is the number of imported domains (for which no
184  access functions have to be generated - see TYPE in genC.c)
185  - CURRENT_START is the beginning index (after TABULATED_BP) in Domains
186  - CURRENT_FIRST **WAS**, for each OR_OP domain, the first tag number (used
187  only in READ_SPEC_MODE). It is now 0.
188 */
189 
190 extern int Number_imports ;
191 extern int Current_start ;
192 /* extern int Current_first ; */
193 extern int Read_spec_mode ;
194 
195 /* For tabulated objects, the offset HASH_OFFSET of the hashed subdomain */
196 #define HASH_OFFSET 2
197 
198 #define same_string_p(s1, s2) (strcmp((s1), (s2)) == 0)
199 
200 #define IS_UNIT_TYPE(n) ((n)==unit_domain)
201 #define IS_BOOL_TYPE(n) ((n)==bool_domain)
202 #define IS_CHAR_TYPE(n) ((n)==char_domain)
203 #define IS_INT_TYPE(n) ((n)==int_domain)
204 #define IS_FLOAT_TYPE(n) ((n)==float_domain)
205 #define IS_STRING_TYPE(n) ((n)==string_domain)
206 
207 /*
208  * MACROS added for code checking
209  *
210  * Fabien COELHO 10/06/94
211  */
212 #define check_domain(dom) \
213  message_assert("Consistant domain number",\
214  (dom)>=0 && (dom)<MAX_DOMAIN)
215 
216 #define check_read_spec_performed() \
217  message_assert("gen_read_spec performed prior to use", \
218  Read_spec_performed);
219 
220 #define NEWGEN_FREED ((void*)NULL)
221 
222 #define newgen_free(p) (*((char*)(p))='\0',free(p)) /* just to hide bugs */
223 
224 /* inlined version of domain_index. what is done by optimizing compilers?
225  */
226 #define quick_domain_index(obj) \
227  (((! (obj)) || ((obj)==gen_chunk_undefined) || \
228  ((obj)->i<0) || ((obj)->i>MAX_DOMAIN)) ? \
229  newgen_domain_index(obj) : (obj)->i) \
230  /* prints the error message or returns */
231 
232 /* External routines. */
233 extern void user(char *, ...) ;
234 
235 extern void gencode(string);
236 extern void fatal(char *, ...) ;
237 extern char *i2a(int);
238 extern void print_domains(FILE *);
239 extern void init(void) ;
240 extern void compile(void) ;
241 extern int gen_size(int);
242 extern void print_domain(FILE *, union domain *);
243 extern string concatenate(const char*, ...);
244 
245 extern int genspec_parse(void);
246 extern int genspec_lex(void);
247 extern int genread_parse(void);
248 extern int genread_lex(void);
249 
251 extern gen_chunk * gen_enter_tabulated(int, char *, gen_chunk *, bool);
252 extern gen_chunk * gen_do_enter_tabulated(int, char *, gen_chunk *, bool);
254 
255 extern int newgen_domain_index(gen_chunk *);
void const char const char const int
domain_operator
Operators for CONSTRUCTED domains.
@ ARROW_OP
@ OR_OP
@ AND_OP
@ UNDEF_OP
int Number_imports
To manage imported domains:
Definition: genspec_yacc.c:115
void init(void)
INIT initializes global data structures.
Definition: build.c:130
gen_chunk * gen_tabulated_fake_object_hack(int)
WARNING: it is not reentrant...
Definition: tabulated.c:107
#define DEFLIST(type, cartype, carname)
A list type constructor.
gen_tabulated_p gen_init_tabulated(int)
Definition: tabulated.c:66
void print_domain(FILE *, union domain *)
PRINT_DOMAIN prints on the OUT stream a domain denoted by the DP pointer.
Definition: build.c:294
char * i2a(int)
I2A (Integer TO Ascii) yields a string for a given Integer.
Definition: string.c:121
struct gen_binding * new_binding()
int genread_parse(void)
struct gen_binding Domains[]
The implementation of tabulated domains.
struct gen_binding * Tabulated_bp
hack to walk thru tabulateds...
void gencode(string)
generate the code necessary to manipulate every internal non-inlinable type in the Domains table.
Definition: genC.c:928
gen_chunk * gen_do_enter_tabulated(int, char *, gen_chunk *, bool)
Definition: tabulated.c:265
int Current_op
Used to check, while parsing specs, that a constructed domain use only one operator type.
Definition: build.c:62
type_of_domain
Types of domain.
@ EXTERNAL_DT
@ SET_DT
@ ARRAY_DT
@ LIST_DT
@ UNDEF_DT
@ BASIS_DT
@ IMPORT_DT
@ CONSTRUCTED_DT
int genspec_lex(void)
int genspec_parse(void)
int newgen_domain_index(gen_chunk *)
DOMAIN_INDEX returns the index in the Domain table for object OBJ.
Definition: genClib.c:105
int genread_lex(void)
void fatal(char *,...)
int gen_size(int)
GEN_SIZE returns the size (in gen_chunks) of an object of type defined by the BP type.
Definition: genC.c:71
void user(char *,...)
External routines.
int Current_start
Definition: build.c:62
gen_chunk * gen_enter_tabulated(int, char *, gen_chunk *, bool)
ENTER_TABULATED_DEF enters a new definition (previous refs are allowed if ALLOW_REF) in the INDEX tab...
Definition: tabulated.c:279
struct gen_binding * lookup()
void compile(void)
COMPILE reconnects the Domains table (for not compiled types – note that an inlined type is already c...
Definition: build.c:422
int Read_spec_mode
extern int Current_first ;
Definition: genClib.c:60
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void print_domains(FILE *)
PRINT_DOMAINS prints on the OUT stream the Domains table.
Definition: build.c:352
gen_chunk * Read_chunk
The root of the gen_chunk read with READ_CHUNK.
Definition: genread_yacc.c:134
struct _gtp * gen_tabulated_p
actually defined in tabulated.c
set_type
Note: hash_chunk is not included in set_type.
Definition: newgen_set.h:41
Definition: tabulated.c:51
union domain * domain
struct inlinable * inlined
gen_tabulated_p tabulated
number of chunks to hold this data.
INLINE[] gives, for each inlinable (i.e., unboxed) type, its NAME, its initial VALUE and its printing...
Definition: build.c:45
A DOMAIN union describes the structure of a user type.
int(* allocated_memory)(void *)
char * constructor
struct gen_binding * element
enum domain_operator op
set_type what
struct domainlist * components
struct domain::@2 ex
int persistant
struct domain::@7 co
struct domain::@5 se
int type
EXTERNAL.
struct domain::@3 ba
struct domain::@8 im
struct intlist * dimensions
struct domain::@4 li
void(* free)(void *)
struct gen_binding * constructand
char * filename
void(* write)(FILE *, void *)
struct domain::@6 ar
A gen_chunk is used to store every object.
Definition: genC.h:58