.gitignore
[prop.git] / prop-src / basics.h
bloba00ba32a432cba97841fb9cf9475c1ccd8eb96fd
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>
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
23 #include <iostream>
25 ///////////////////////////////////////////////////////////////////////////////
27 // The following is used to deal with the new ANSI conformance
28 // of the "for" statement involving scoping of variables defined in
29 // an "if". Variables defined inside a for statement are not visible
30 // only with the scope of the construct.
32 ///////////////////////////////////////////////////////////////////////////////
33 #define for if (0) ; else for
35 ///////////////////////////////////////////////////////////////////////////////
37 // Two memory pools are kept for fast memory allocation.
38 // Memory allocated from the global pool is persistent during the run
39 // of the translator, while memory allocated from the local pool can
40 // be deallocated in a stack-like fashion. Also, there is a pool for
41 // string objects. These are persistent like the global pool.
43 ///////////////////////////////////////////////////////////////////////////////
44 extern MemPool mem_pool; // memory pool for local objects
45 extern MemPool global_pool; // memory pool for global objects
46 extern StringPool str_pool; // string pool for strings
48 ///////////////////////////////////////////////////////////////////////////////
50 // Class 'MEM' is a memory management class. Objects deriving from
51 // this class are allocates from the memory pools. By default,
52 // the local memory pool is used. The methods 'use_global_pools'
53 // and 'use_local_pools' can be used to switch between the global
54 // and local pools.
56 ///////////////////////////////////////////////////////////////////////////////
57 class MEM {
58 public:
59 void * operator new (size_t); // allocation member
60 // void operator delete(void *); // disable deletion
61 static void use_global_pools(); // switch to the global pool
62 static void use_local_pools(); // switch to the local pol
63 // allocate a vector from the pool
66 ///////////////////////////////////////////////////////////////////////////////
68 // The input/output/logging streams and the output file name(if applicable).
70 ///////////////////////////////////////////////////////////////////////////////
71 extern std::istream * input_stream; // The current input stream
72 extern std::ostream * output_stream; // The current output stream
73 extern std::ostream * log_stream; // The current logging stream
74 extern std::ostream& open_logfile(); // Open the logfile
75 extern std::ostream* open_output_file(const char []); // open a file for output
76 extern void encode_string(char *, const char *); // Encode a string.
78 ///////////////////////////////////////////////////////////////////////////////
80 // Errors and messages routines.
82 ///////////////////////////////////////////////////////////////////////////////
83 extern int errors; // number of errors found
84 std::ostream& pr_msg (const char *, va_list); // generic print message routine
85 std::ostream& error (const char *, ...); // error message
86 std::ostream& msg (const char *, ...); // generic message
87 std::ostream& debug_msg(const char *, ...); // debugging message
88 void bug (const char *, ...); // abort and generate a bug report
90 ///////////////////////////////////////////////////////////////////////////////
92 // Polymorphic lists, pairs and identifiers. These are used throughout the
93 // rest of the translator.
95 ///////////////////////////////////////////////////////////////////////////////
96 #line 96 "basics.ph"
97 #line 100 "basics.ph"
98 ///////////////////////////////////////////////////////////////////////////////
100 // Forward class definition for List<T>
102 ///////////////////////////////////////////////////////////////////////////////
103 #ifndef datatype_List_defined
104 #define datatype_List_defined
105 template <class T> class a_List;
106 #define List(T) a_List<T> *
107 #endif
109 # define nil_1_ 0
111 ///////////////////////////////////////////////////////////////////////////////
113 // Forward class definition for Pair<A, B>
115 ///////////////////////////////////////////////////////////////////////////////
116 #ifndef datatype_Pair_defined
117 #define datatype_Pair_defined
118 template <class A, class B> class a_Pair;
119 #define Pair(A, B) a_Pair<A, B> *
120 #endif
122 ///////////////////////////////////////////////////////////////////////////////
123 // Definition of type Id
124 ///////////////////////////////////////////////////////////////////////////////
125 #line 98 "basics.ph"
126 typedef char const * Id;
128 ///////////////////////////////////////////////////////////////////////////////
129 // Definition of type Ids
130 ///////////////////////////////////////////////////////////////////////////////
131 #line 99 "basics.ph"
132 typedef a_List<Id> * Ids;
134 ///////////////////////////////////////////////////////////////////////////////
136 // Class for datatype constructor List<T>::#[...]
138 ///////////////////////////////////////////////////////////////////////////////
139 template <class T> class a_List : public MEM {
140 public:
141 #line 96 "basics.ph"
142 T _1; a_List<T> * _2;
143 inline a_List (T x_1, a_List<T> * x_2)
144 : _1(x_1), _2(x_2)
147 inline a_List (T x_1)
148 : _1(x_1), _2((a_List<T> *)0)
152 template <class T> inline int boxed(const a_List<T> * x) { return x != 0; }
153 template <class T> inline int untag(const a_List<T> * x) { return x ? 1 : 0; }
154 ///////////////////////////////////////////////////////////////////////////////
156 // Datatype constructor functions for List<T>
158 ///////////////////////////////////////////////////////////////////////////////
159 template <class T> inline a_List<T> * list_1_ (T x_1, a_List<T> * x_2)
161 return new a_List<T> (x_1, x_2);
163 template <class T> inline a_List<T> * list_1_ (T x_1)
165 return new a_List<T> (x_1);
167 ///////////////////////////////////////////////////////////////////////////////
169 // Downcasting functions for List<T>
171 ///////////////////////////////////////////////////////////////////////////////
174 ///////////////////////////////////////////////////////////////////////////////
176 // Class for datatype constructor Pair<A, B>::pair
178 ///////////////////////////////////////////////////////////////////////////////
179 template <class A, class B> class a_Pair : public MEM {
180 public:
181 #line 97 "basics.ph"
182 A fst; B snd;
183 inline a_Pair (A x_fst, B x_snd)
184 : fst(x_fst), snd(x_snd)
188 template <class A, class B> inline int boxed(const a_Pair<A, B> *) { return 1; }
189 template <class A, class B> inline int untag(const a_Pair<A, B> *) { return 0; }
190 ///////////////////////////////////////////////////////////////////////////////
192 // Datatype constructor functions for Pair<A, B>
194 ///////////////////////////////////////////////////////////////////////////////
195 template <class A, class B> inline a_Pair<A, B> * pair (A x_fst, B x_snd)
197 return new a_Pair<A, B> (x_fst, x_snd);
199 ///////////////////////////////////////////////////////////////////////////////
201 // Downcasting functions for Pair<A, B>
203 ///////////////////////////////////////////////////////////////////////////////
206 #line 100 "basics.ph"
207 #line 100 "basics.ph"
210 ///////////////////////////////////////////////////////////////////////////////
212 // Macro to iterate over a list.
214 ///////////////////////////////////////////////////////////////////////////////
215 #define APPEND_(a,b) a ## b
216 #define NEWVAR2_(a,b) APPEND_(a,b)
217 #define NEWVAR(a) NEWVAR2_(a,__LINE__)
218 #define for_each(T,i,l) \
219 T i; \
220 for (List(T) NEWVAR(_i_) = l; \
221 NEWVAR(_i_) && (i = NEWVAR(_i_)->_1, 1); \
222 NEWVAR(_i_) = NEWVAR(_i_)->_2)
224 ///////////////////////////////////////////////////////////////////////////////
226 // We keep track of the current source location in the following global
227 // variables. These are updated continuously by the parser, lexer and the
228 // semantic processing routines.
230 ///////////////////////////////////////////////////////////////////////////////
231 extern int line; // the current line number
232 extern int first_line; // the first line of the current construct
233 extern Id file; // the current input file.
235 ///////////////////////////////////////////////////////////////////////////////
237 // The following class, Loc, is used to keep track of the source location.
238 // Objects derived from this class will contain the source location in
239 // which it is constructed; useful for AST nodes.
241 ///////////////////////////////////////////////////////////////////////////////
242 struct Loc : public MEM {
243 public:
244 Id file_name;
245 int begin_line, end_line;
246 Loc();
247 Loc(int, int);
248 inline const Loc * loc() const { return this; }
249 void set_loc() const;
252 #endif
253 #line 145 "basics.ph"
255 ------------------------------- Statistics -------------------------------
256 Merge matching rules = yes
257 Number of DFA nodes merged = 0
258 Number of ifs generated = 0
259 Number of switches generated = 0
260 Number of labels = 0
261 Number of gotos = 0
262 Adaptive matching = enabled
263 Fast string matching = disabled
264 Inline downcasts = enabled
265 --------------------------------------------------------------------------