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