OpenIndiana and Solaris port
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Basic / ParseTree.hh
1 /*
2  * $XConsortium: ParseTree.hh /main/3 1996/06/11 16:21:45 cde-hal $
3  *
4  * Copyright (c) 1991 HaL Computer Systems, Inc.  All rights reserved.
5  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
6  * States.  Use of a copyright notice is precautionary only and does not
7  * imply publication or disclosure.
8  * 
9  * This software contains confidential information and trade secrets of HaL
10  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
11  * without the prior express written permission of HaL Computer Systems, Inc.
12  * 
13  *                         RESTRICTED RIGHTS LEGEND
14  * Use, duplication, or disclosure by the Government is subject to
15  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
16  * Technical Data and Computer Software clause at DFARS 252.227-7013.
17  *                        HaL Computer Systems, Inc.
18  *                  1315 Dell Avenue, Campbell, CA  95008
19  * 
20  */
21
22 #ifndef _ParseTree_hh
23 #define _ParseTree_hh
24
25 typedef void *ClassType;
26
27 /* Class Tree: */
28 class     PNode;
29 class       PStart;
30 class       PEnd;
31 class       PText;
32 class         PNumber;
33 class         PString;
34 class       PGroup;
35 class         PRoot;
36 class       PBooleanOp;
37 class         POr;
38 class         PAnd;
39 class         PRelation;
40 class           PNear;
41 class           PBefore;
42 class       PPrefixOp;
43 class         PNot;
44 class       PPostfixOp;
45 class         PWeight;
46 class         PProximity;
47 class         PNotBoth;
48
49 typedef enum { USER_REQUEST, OBJECT_REQUEST } delete_request_t;
50
51 /* -------- PNode -------- */
52
53 class PNode {
54 public: // variables
55   static const ClassType PNodeClass;
56   void *f_user_data;            // allow app to attach misc data to nodes
57   /* we're dead in multi-threaded environment with statics like this */
58   static bool f_recursive_delete;
59
60   PNode *f_parent;              // parent in parse tree
61   PNode *f_previous;            // next symbol in linear ordering
62   PNode *f_next;                // previous symbol in linear ordering
63
64 public: // functions
65   virtual ~PNode ();
66   
67   virtual bool isa (ClassType type)
68     { return (type == PNodeClass ? TRUE : FALSE); }
69   virtual const ClassType type () = 0;
70   virtual char *symbol ()
71     { return " *ERROR* "; }
72   virtual const int precedence ()
73     { abort (); return (0); }
74   virtual void replace_child (PNode *, PNode *)
75     { puts ("ERROR: BOGUS replace_child CALLED!!"); abort (); }
76   static void insert (PRoot *root, long position);
77   static bool can_insert (PRoot *root, long position);
78   virtual void delete_self (delete_request_t)
79     { puts ("*** Tried to delete something without delete method ***"); }
80
81 protected: // functions
82   PNode (PNode *parent, PNode *previous, PNode *next);
83 };
84
85 /* -------- PStart -------- */
86
87 class PStart : public PNode {
88 public: // variables
89   static const ClassType PStartClass;
90   
91 public: // functions
92   PStart (PNode *parent, PNode *previous, PNode *next)
93     : PNode (parent, previous, next) { };
94
95   virtual bool isa (ClassType type)
96     { return (type == PStartClass ? TRUE : PNode::isa (type)); }
97   virtual const ClassType type ()
98     { return PStartClass; }
99   virtual char *symbol ()
100     { return f_symbol; }
101
102 protected: // variables
103   static char *f_symbol;
104   static const int f_precedence;
105 };
106
107 /* -------- PEnd -------- */
108
109 class PEnd : public PNode {
110 public: // variables
111   static const ClassType PEndClass;
112
113 public: //functions
114   PEnd (PNode *parent, PNode *previous, PNode *next)
115     : PNode (parent, previous, next) { };
116
117   virtual bool isa (ClassType type)
118     { return (type == PEndClass ? TRUE : PNode::isa (type)); }
119   virtual const ClassType type ()
120     { return PEndClass; }
121   virtual char *symbol ()
122     { return f_symbol; }
123
124 protected: // variables
125   static char *f_symbol;
126   static const int f_precedence;
127 };
128
129 /* -------- PText -------- */
130
131 class PText : public PNode {
132 public: // variables
133   static const ClassType PTextClass;
134   bool f_empty;
135
136 public: // functions
137   PText (PNode *parent, PNode *previous, PNode *next, char *str);
138   ~PText ();
139   void insert_chars (int where, char *text, int length);
140   void remove_chars (int where, int len);
141   virtual bool isa (ClassType type)
142     { return (type == PTextClass ? TRUE : PNode::isa (type)); }
143   virtual char *symbol()
144     { return f_symbol; }
145   virtual void delete_self (delete_request_t);
146
147 protected: // variables
148   char *f_symbol;
149   int f_symbol_len;
150   int f_symbol_space;
151 };
152
153 /* -------- PNumber -------- */
154
155 class PNumber : public PText {
156 public: // variables
157   PNumber (PNode *parent, PNode *previous, PNode *next, char *str = "#");
158   static const ClassType PNumberClass;
159
160 public: // functions
161   virtual bool isa (ClassType type)
162     { return (type == PNumberClass ? TRUE : PText::isa (type)); }
163   virtual const ClassType type ()
164     { return PNumberClass; }
165
166 protected: // variables
167   static const int f_precedence;
168 };
169
170 /* -------- PString -------- */
171
172 class PString : public PText {
173 public: // variables
174   static const ClassType PStringClass;
175
176 public: // functions
177   PString (char *str = "\"?\"");
178   PString (PNode *parent, PNode *previous, PNode *next, char *str = "\"?\"");
179   virtual ~PString ();
180
181   virtual bool isa (ClassType type)
182     { return (type == PStringClass ? TRUE : PText::isa (type)); }
183   virtual const ClassType type ()
184     { return PStringClass; }
185
186 protected: // variables
187   static const int f_precedence;
188 };
189
190 /* -------- PGroup -------- */
191
192 class PGroup : public PNode {
193 public: // variables
194   static const ClassType PGroupClass;
195
196   PNode *f_left;
197   PNode *f_subexpr;
198   PNode *f_right;
199
200 public: // functions
201   PGroup (PNode *parent, PNode *previous, PNode *next, PNode *subexpr);
202   virtual ~PGroup ();
203   
204   virtual bool isa (ClassType type)
205     { return (type == PGroupClass ? TRUE : PNode::isa (type)); }
206   virtual const ClassType type ()
207     { return PGroupClass; }
208   virtual void replace_child (PNode *, PNode *replacement)
209     { f_subexpr = replacement;
210       if (replacement != NULL) replacement->f_parent = this; }
211   virtual const int precedence ()
212     { return f_precedence; }
213   virtual char *symbol ()
214     { return ("Group"); }
215
216 protected: // variables
217   static const int f_precedence;
218 };
219
220 /* -------- PRoot -------- */
221 /* root of a parse tree */
222
223 class PRoot : public PGroup {
224 public: // variables
225   static const ClassType PRootClass;
226
227   int f_old_length;
228   int f_length;
229   char *f_char_of;
230   PNode **f_node_of;
231
232 public: // functions
233   PRoot (PNode *subexpr);
234   virtual ~PRoot ();
235   void generate ();
236   virtual bool isa (ClassType type)
237     { return (type == PRootClass ? TRUE : PGroup::isa (type)); }
238   virtual const ClassType type ()
239     { return PRootClass; }
240
241 protected: // variables
242   int f_space;
243   PNode **f_node_of_real;
244 };
245
246 /* -------- PBooleanOp -------- */
247
248 class PBooleanOp : public PNode {
249 public: // variables
250   static const ClassType PBooleanOpClass;
251
252   PNode *f_left;
253   PNode *f_right;
254
255 public: // functions
256   PBooleanOp ();
257   virtual bool isa (ClassType type)
258     { return (type == PBooleanOpClass ? TRUE : PNode::isa (type)); }
259   virtual void replace_child (PNode *old, PNode *replacement);
260   static bool can_insert (PRoot *root, long position);
261   virtual void init (PRoot *, long pos);
262   virtual void delete_self (delete_request_t);
263
264 protected: // variables
265 };
266
267 /* -------- POr -------- */
268
269 class POr : public PBooleanOp {
270 public: // variables
271   static const ClassType POrClass;
272
273   PNotBoth *f_not_both;
274
275 public: // functions
276   POr (PRoot *root, long pos)
277     :  f_not_both (NULL) { init (root, pos); }
278   virtual bool isa (ClassType type)
279     { return (type == POrClass ? TRUE : PBooleanOp::isa (type)); }
280   virtual const ClassType type ()
281     { return POrClass; }
282   virtual char *symbol()
283     { return f_symbol; }
284   static void insert (PRoot *root, long pos);
285   virtual const int precedence ()
286     { return f_precedence; }
287
288 protected: // variables
289   static char *f_symbol;
290   static const int f_precedence;
291 };
292
293 /* -------- PAnd -------- */
294
295 class PAnd : public PBooleanOp {
296 public: // variables
297   static const ClassType PAndClass;
298
299 public: // functions
300   PAnd (PRoot *root, long pos)
301     { init (root, pos); }
302   virtual bool isa (ClassType type)
303     { return (type == PAndClass ? TRUE : PBooleanOp::isa (type)); }
304   virtual const ClassType type ()
305     { return PAndClass; }
306   virtual char *symbol()
307     { return f_symbol; }
308   static void insert (PRoot *root, long pos);
309   virtual const int precedence ()
310     { return f_precedence; }
311
312 protected: // variables
313   static char *f_symbol;
314   static const int f_precedence;
315 };
316
317 /* -------- PRelation -------- */
318
319 class PRelation : public PBooleanOp {
320 public: // variables
321   static const ClassType PRelationClass;
322
323   PPostfixOp *f_proximity;
324
325 public: // functions
326   PRelation ()
327     : f_proximity (NULL) { }
328   virtual bool isa (ClassType type)
329     { return (type == PRelationClass ? TRUE : PBooleanOp::isa (type)); }
330
331 protected: // variables
332 };
333
334 /* -------- PNear -------- */
335
336 class PNear : public PRelation {
337 public: // variables
338   static const ClassType PNearClass;
339
340 public: // functions
341   PNear (PRoot *root, long pos)
342     { init (root, pos); }
343   virtual bool isa (ClassType type)
344     { return (type == PNearClass ? TRUE : PRelation::isa (type)); }
345   virtual const ClassType type ()
346     { return PNearClass; }
347   virtual char *symbol ()
348     { return f_symbol; }
349   static void insert (PRoot *root, long pos);
350   virtual const int precedence ()
351     { return f_precedence; }
352
353 protected: // variables
354   static char *f_symbol;
355   static const int f_precedence;
356 };
357
358 /* -------- PBefore -------- */
359
360 class PBefore : public PRelation {
361 public: // variables
362   static const ClassType PBeforeClass;
363
364 public: // functions
365   PBefore (PRoot *root, long pos)
366     { init (root, pos); }
367   virtual bool isa (ClassType type)
368     { return (type == PBeforeClass ? TRUE : PRelation::isa (type)); }
369   virtual const ClassType type ()
370     { return PBeforeClass; }
371   virtual char *symbol ()
372     { return f_symbol; }
373   static void insert (PRoot *root, long pos);
374   virtual const int precedence ()
375     { return f_precedence; }
376
377 protected: // variables
378   static char *f_symbol;
379   static const int f_precedence;
380 };
381
382 /* -------- PPrefixOp -------- */
383
384 class PPrefixOp : public PNode {
385 public: // variables
386   static const ClassType PPrefixOpClass;
387
388   PNode *f_operand;
389
390 public: // functions
391   PPrefixOp (PNode *rhs);
392   virtual bool isa (ClassType type)
393     { return (type == PPrefixOpClass ? TRUE : PNode::isa (type)); }
394   virtual void replace_child (PNode *, PNode *replacement)
395     { f_operand = replacement;
396       if (replacement != NULL) replacement->f_parent = this; }
397 };
398
399 /* -------- PNot -------- */
400
401 class PNot : public PPrefixOp {
402 public: // variables
403   static const ClassType PNotClass;
404
405 public: // functions
406   PNot (PNode *rhs);
407   ~PNot ();
408   virtual bool isa (ClassType type)
409     { return (type == PNotClass ? TRUE : PPrefixOp::isa (type)); }
410   virtual const ClassType type ()
411     { return PNotClass; }
412   virtual char *symbol()
413     { return f_symbol; }
414   virtual const int precedence ()
415     { return f_precedence; }
416   static void insert (PRoot *root, long position);
417   static bool can_insert (PRoot *root, long position);
418   virtual void delete_self (delete_request_t request);
419
420 protected: // variables
421   static char *f_symbol;
422   static const int f_precedence;
423 };
424
425
426 /* -------- PPostfixOp -------- */
427 /* Postfix ops are bound by the thing they operation on. */
428 /* In other words, they can't apply to arbitrary things,
429    so the things they apply to will point to them. */
430
431 class PPostfixOp : public PNode {
432 public: // variables
433   static const ClassType PPostfixOpClass;
434
435 public: // functions
436   virtual bool isa (ClassType type)
437     { return (type == PPostfixOpClass ? TRUE : PNode::isa (type)); }
438 };
439
440 /* -------- PWeight -------- */
441
442 class PWeight : public PPostfixOp {
443 public: // variables
444   static const ClassType PWeightClass;
445
446 public: // functions
447   virtual bool isa (ClassType type)
448     { return (type == PWeightClass ? TRUE : PPostfixOp::isa (type)); }
449   virtual const ClassType type ()
450     { return PWeightClass; }
451   virtual char *symbol ()
452     { return f_symbol; }
453   static bool can_insert (PRoot *root, long position);
454   virtual const int precedence ()
455     { return f_precedence; }
456
457 protected: // variables
458   static char *f_symbol;
459   static const int f_precedence;
460 };
461
462 /* -------- PProximity -------- */
463
464 class PProximity : public PPostfixOp {
465 public: // variables
466   static const ClassType PProximityClass;
467
468 public: // functions
469   virtual bool isa (ClassType type)
470     { return (type == PProximityClass ? TRUE : PPostfixOp::isa (type)); }
471   virtual const ClassType type ()
472     { return PProximityClass; }
473   virtual char *symbol()
474     { return f_symbol; }
475   virtual const int precedence ()
476     { return f_precedence; }
477
478 protected: // variables
479   static char *f_symbol;
480   static const int f_precedence;
481 };
482 /* -------- PProximity -------- */
483
484 class PNotBoth : public PPostfixOp {
485 public: // variables
486   static const ClassType PNotBothClass;
487
488 public: // functions
489   virtual bool isa (ClassType type)
490     { return (type == PNotBothClass ? TRUE : PPostfixOp::isa (type)); }
491   virtual const ClassType type ()
492     { return PNotBothClass; }
493   virtual char *symbol()
494     { return f_symbol; }
495   virtual const int precedence ()
496     { return f_precedence; }
497   static bool can_insert (PRoot *root, int position);
498   
499 protected: // variables
500   static char *f_symbol;
501   static const int f_precedence;
502 };
503
504 #endif /* _ParseTree_hh */
505 /* DO NOT ADD ANY LINES AFTER THIS #endif */
506