PIPS
newgen_generic_stack.h
Go to the documentation of this file.
1 /*
2 
3  $Id: newgen_generic_stack.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  Made after the generic current mappings
24  Fabien COELHO, 05/12/94
25 */
26 
27 #define DEFINE_STACK(PREFIX, name, type) \
28  /* the stack */ \
29  static stack name##_stack = stack_undefined; \
30  /* its functions */ \
31  PREFIX void __attribute__ ((unused)) make_##name##_stack(void) \
32  { \
33  assert(name##_stack==stack_undefined); \
34  name##_stack = stack_make(type##_domain, 0, 0); \
35  } \
36  PREFIX void __attribute__ ((unused)) free_##name##_stack(void) \
37  { \
38  stack_free(&name##_stack); \
39  name##_stack = stack_undefined; \
40  } \
41  PREFIX stack __attribute__ ((unused)) get_##name##_stack(void) \
42  { \
43  return name##_stack; \
44  } \
45  PREFIX void __attribute__ ((unused)) set_##name##_stack(stack s) \
46  { \
47  assert(name##_stack==stack_undefined); \
48  name##_stack = s; \
49  } \
50  PREFIX void __attribute__ ((unused)) reset_##name##_stack(void) \
51  { \
52  assert(name##_stack!=stack_undefined); \
53  name##_stack = stack_undefined; \
54  } \
55  PREFIX void __attribute__ ((unused)) name##_push(type i) \
56  { \
57  stack_push((void *)i, name##_stack); \
58  } \
59  PREFIX bool __attribute__ ((unused)) name##_filter(type i) \
60  { \
61  stack_push((void *)i, name##_stack); \
62  return true; \
63  } \
64  PREFIX void __attribute__ ((unused)) name##_rewrite(type i) \
65  { \
66  type __attribute__ ((unused)) t = (type)stack_pop(name##_stack);\
67  assert(t==i); \
68  } \
69  PREFIX type __attribute__ ((unused)) name##_replace(type i) \
70  { \
71  return (type) stack_replace((void *)i, name##_stack); \
72  } \
73  PREFIX type __attribute__ ((unused)) name##_pop(void) \
74  { \
75  return (type) stack_pop(name##_stack); \
76  } \
77  PREFIX type __attribute__ ((unused)) name##_head(void) \
78  { \
79  return (type) stack_head(name##_stack); \
80  } \
81  PREFIX type __attribute__ ((unused)) name##_nth(int n) \
82  { \
83  return (type) stack_nth(name##_stack, n); \
84  } \
85  PREFIX bool __attribute__ ((unused)) name##_empty_p(void) \
86  { \
87  return stack_empty_p(name##_stack); \
88  } \
89  PREFIX int __attribute__ ((unused)) name##_size(void) \
90  { \
91  return stack_size(name##_stack); \
92  } \
93  PREFIX void __attribute__ ((unused)) error_reset_##name##_stack(void) \
94  { \
95  name##_stack = stack_undefined; \
96  }
97 
98 #define DEFINE_LOCAL_STACK(name, type) DEFINE_STACK(static, name, type)
99 #define DEFINE_GLOBAL_STACK(name, type) DEFINE_STACK(extern, name, type)
100 
101 /* That is all
102  */