initial
[prop.git] / prop-src / basics.h
blobff86b87a87f13922ab0329909c63ba211cea5842
1 ///////////////////////////////////////////////////////////////////////////////
2 // This file is generated automatically using Prop (version 2.3.6),
3 // last updated on Nov 2, 1999.
4 // The original source file is "basics.ph".
5 ///////////////////////////////////////////////////////////////////////////////
7 #line 1 "basics.ph"
8 ///////////////////////////////////////////////////////////////////////////////
9 //
10 // This file contains the basic definitions used in the
11 // Prop -> C++ translator, including various flags and memory
12 // pools definitions.
14 ///////////////////////////////////////////////////////////////////////////////
15 #ifndef basic_definitions_h
16 #define basic_definitions_h
18 #include <new.h>
19 #include <stdarg.h>
20 #include <AD/generic/generic.h> // generic definitions from the library
21 #include <AD/memory/mempool.h> // memory pool
22 #include <AD/memory/strpool.h> // string pool
24 ///////////////////////////////////////////////////////////////////////////////
26 // Forward declaration for the input/output streams.
28 ///////////////////////////////////////////////////////////////////////////////
29 class istream;
30 class ostream;
32 ///////////////////////////////////////////////////////////////////////////////
34 // The following is used to deal with the new ANSI conformance
35 // of the "for" statement involving scoping of variables defined in
36 // an "if". Variables defined inside a for statement are not visible
37 // only with the scope of the construct.
39 ///////////////////////////////////////////////////////////////////////////////
40 #define for if (0) ; else for
42 ///////////////////////////////////////////////////////////////////////////////
44 // Two memory pools are kept for fast memory allocation.
45 // Memory allocated from the global pool is persistent during the run
46 // of the translator, while memory allocated from the local pool can
47 // be deallocated in a stack-like fashion. Also, there is a pool for
48 // string objects. These are persistent like the global pool.
50 ///////////////////////////////////////////////////////////////////////////////
51 extern MemPool mem_pool; // memory pool for local objects
52 extern MemPool global_pool; // memory pool for global objects
53 extern StringPool str_pool; // string pool for strings
55 ///////////////////////////////////////////////////////////////////////////////
57 // Class 'MEM' is a memory management class. Objects deriving from
58 // this class are allocates from the memory pools. By default,
59 // the local memory pool is used. The methods 'use_global_pools'
60 // and 'use_local_pools' can be used to switch between the global
61 // and local pools.
63 ///////////////////////////////////////////////////////////////////////////////
64 class MEM {
65 public:
66 void * operator new (size_t); // allocation member
67 // void operator delete(void *); // disable deletion
68 static void use_global_pools(); // switch to the global pool
69 static void use_local_pools(); // switch to the local pol
70 // allocate a vector from the pool
73 ///////////////////////////////////////////////////////////////////////////////
75 // The input/output/logging streams and the output file name(if applicable).
77 ///////////////////////////////////////////////////////////////////////////////
78 extern istream * input_stream; // The current input stream
79 extern ostream * output_stream; // The current output stream
80 extern ostream * log_stream; // The current logging stream
81 extern ostream& open_logfile(); // Open the logfile
82 extern ostream* open_output_file(const char []); // open a file for output
83 extern void encode_string(char *, const char *); // Encode a string.
85 ///////////////////////////////////////////////////////////////////////////////
87 // Errors and messages routines.
89 ///////////////////////////////////////////////////////////////////////////////
90 extern int errors; // number of errors found
91 ostream& pr_msg (const char *, va_list); // generic print message routine
92 ostream& error (const char *, ...); // error message
93 ostream& msg (const char *, ...); // generic message
94 ostream& debug_msg(const char *, ...); // debugging message
95 void bug (const char *, ...); // abort and generate a bug report
97 ///////////////////////////////////////////////////////////////////////////////
99 // Polymorphic lists, pairs and identifiers. These are used throughout the
100 // rest of the translator.
102 ///////////////////////////////////////////////////////////////////////////////
103 #line 96 "basics.ph"
104 #line 100 "basics.ph"
105 ///////////////////////////////////////////////////////////////////////////////
107 // Forward class definition for List<T>
109 ///////////////////////////////////////////////////////////////////////////////
110 #ifndef datatype_List_defined
111 #define datatype_List_defined
112 template <class T> class a_List;
113 #define List(T) a_List<T> *
114 #endif
116 # define nil_1_ 0
118 ///////////////////////////////////////////////////////////////////////////////
120 // Forward class definition for Pair<A, B>
122 ///////////////////////////////////////////////////////////////////////////////
123 #ifndef datatype_Pair_defined
124 #define datatype_Pair_defined
125 template <class A, class B> class a_Pair;
126 #define Pair(A, B) a_Pair<A, B> *
127 #endif
129 ///////////////////////////////////////////////////////////////////////////////
130 // Definition of type Id
131 ///////////////////////////////////////////////////////////////////////////////
132 #line 98 "basics.ph"
133 typedef char const * Id;
135 ///////////////////////////////////////////////////////////////////////////////
136 // Definition of type Ids
137 ///////////////////////////////////////////////////////////////////////////////
138 #line 99 "basics.ph"
139 typedef a_List<Id> * Ids;
141 ///////////////////////////////////////////////////////////////////////////////
143 // Class for datatype constructor List<T>::#[...]
145 ///////////////////////////////////////////////////////////////////////////////
146 template <class T> class a_List : public MEM {
147 public:
148 #line 96 "basics.ph"
149 T _1; a_List<T> * _2;
150 inline a_List (T x_1, a_List<T> * x_2)
151 : _1(x_1), _2(x_2)
154 inline a_List (T x_1)
155 : _1(x_1), _2((a_List<T> *)0)
159 template <class T> inline int boxed(const a_List<T> * x) { return x != 0; }
160 template <class T> inline int untag(const a_List<T> * x) { return x ? 1 : 0; }
161 ///////////////////////////////////////////////////////////////////////////////
163 // Datatype constructor functions for List<T>
165 ///////////////////////////////////////////////////////////////////////////////
166 template <class T> inline a_List<T> * list_1_ (T x_1, a_List<T> * x_2)
168 return new a_List<T> (x_1, x_2);
170 template <class T> inline a_List<T> * list_1_ (T x_1)
172 return new a_List<T> (x_1);
174 ///////////////////////////////////////////////////////////////////////////////
176 // Downcasting functions for List<T>
178 ///////////////////////////////////////////////////////////////////////////////
181 ///////////////////////////////////////////////////////////////////////////////
183 // Class for datatype constructor Pair<A, B>::pair
185 ///////////////////////////////////////////////////////////////////////////////
186 template <class A, class B> class a_Pair : public MEM {
187 public:
188 #line 97 "basics.ph"
189 A fst; B snd;
190 inline a_Pair (A x_fst, B x_snd)
191 : fst(x_fst), snd(x_snd)
195 template <class A, class B> inline int boxed(const a_Pair<A, B> *) { return 1; }
196 template <class A, class B> inline int untag(const a_Pair<A, B> *) { return 0; }
197 ///////////////////////////////////////////////////////////////////////////////
199 // Datatype constructor functions for Pair<A, B>
201 ///////////////////////////////////////////////////////////////////////////////
202 template <class A, class B> inline a_Pair<A, B> * pair (A x_fst, B x_snd)
204 return new a_Pair<A, B> (x_fst, x_snd);
206 ///////////////////////////////////////////////////////////////////////////////
208 // Downcasting functions for Pair<A, B>
210 ///////////////////////////////////////////////////////////////////////////////
213 #line 100 "basics.ph"
214 #line 100 "basics.ph"
217 ///////////////////////////////////////////////////////////////////////////////
219 // Macro to iterate over a list.
221 ///////////////////////////////////////////////////////////////////////////////
222 #define APPEND_(a,b) a ## b
223 #define NEWVAR2_(a,b) APPEND_(a,b)
224 #define NEWVAR(a) NEWVAR2_(a,__LINE__)
225 #define for_each(T,i,l) \
226 T i; \
227 for (List(T) NEWVAR(_i_) = l; \
228 NEWVAR(_i_) && (i = NEWVAR(_i_)->_1, 1); \
229 NEWVAR(_i_) = NEWVAR(_i_)->_2)
231 ///////////////////////////////////////////////////////////////////////////////
233 // We keep track of the current source location in the following global
234 // variables. These are updated continuously by the parser, lexer and the
235 // semantic processing routines.
237 ///////////////////////////////////////////////////////////////////////////////
238 extern int line; // the current line number
239 extern int first_line; // the first line of the current construct
240 extern Id file; // the current input file.
242 ///////////////////////////////////////////////////////////////////////////////
244 // The following class, Loc, is used to keep track of the source location.
245 // Objects derived from this class will contain the source location in
246 // which it is constructed; useful for AST nodes.
248 ///////////////////////////////////////////////////////////////////////////////
249 struct Loc : public MEM {
250 public:
251 Id file_name;
252 int begin_line, end_line;
253 Loc();
254 Loc(int, int);
255 inline const Loc * loc() const { return this; }
256 void set_loc() const;
259 #endif
260 #line 145 "basics.ph"
262 ------------------------------- Statistics -------------------------------
263 Merge matching rules = yes
264 Number of DFA nodes merged = 0
265 Number of ifs generated = 0
266 Number of switches generated = 0
267 Number of labels = 0
268 Number of gotos = 0
269 Adaptive matching = enabled
270 Fast string matching = disabled
271 Inline downcasts = enabled
272 --------------------------------------------------------------------------