2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
24 * $XConsortium: ParseTree.hh /main/3 1996/06/11 16:21:45 cde-hal $
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.
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.
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
47 typedef void *ClassType;
71 typedef enum { USER_REQUEST, OBJECT_REQUEST } delete_request_t;
73 /* -------- PNode -------- */
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;
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
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 ***"); }
103 protected: // functions
104 PNode (PNode *parent, PNode *previous, PNode *next);
107 /* -------- PStart -------- */
109 class PStart : public PNode {
111 static const ClassType PStartClass;
114 PStart (PNode *parent, PNode *previous, PNode *next)
115 : PNode (parent, previous, next) { };
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 ()
124 protected: // variables
125 static char *f_symbol;
126 static const int f_precedence;
129 /* -------- PEnd -------- */
131 class PEnd : public PNode {
133 static const ClassType PEndClass;
136 PEnd (PNode *parent, PNode *previous, PNode *next)
137 : PNode (parent, previous, next) { };
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 ()
146 protected: // variables
147 static char *f_symbol;
148 static const int f_precedence;
151 /* -------- PText -------- */
153 class PText : public PNode {
155 static const ClassType PTextClass;
159 PText (PNode *parent, PNode *previous, PNode *next, char *str);
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()
167 virtual void delete_self (delete_request_t);
169 protected: // variables
175 /* -------- PNumber -------- */
177 class PNumber : public PText {
179 PNumber (PNode *parent, PNode *previous, PNode *next, char *str = "#");
180 static const ClassType PNumberClass;
183 virtual bool isa (ClassType type)
184 { return (type == PNumberClass ? TRUE : PText::isa (type)); }
185 virtual const ClassType type ()
186 { return PNumberClass; }
188 protected: // variables
189 static const int f_precedence;
192 /* -------- PString -------- */
194 class PString : public PText {
196 static const ClassType PStringClass;
199 PString (char *str = "\"?\"");
200 PString (PNode *parent, PNode *previous, PNode *next, char *str = "\"?\"");
203 virtual bool isa (ClassType type)
204 { return (type == PStringClass ? TRUE : PText::isa (type)); }
205 virtual const ClassType type ()
206 { return PStringClass; }
208 protected: // variables
209 static const int f_precedence;
212 /* -------- PGroup -------- */
214 class PGroup : public PNode {
216 static const ClassType PGroupClass;
223 PGroup (PNode *parent, PNode *previous, PNode *next, PNode *subexpr);
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"); }
238 protected: // variables
239 static const int f_precedence;
242 /* -------- PRoot -------- */
243 /* root of a parse tree */
245 class PRoot : public PGroup {
247 static const ClassType PRootClass;
255 PRoot (PNode *subexpr);
258 virtual bool isa (ClassType type)
259 { return (type == PRootClass ? TRUE : PGroup::isa (type)); }
260 virtual const ClassType type ()
261 { return PRootClass; }
263 protected: // variables
265 PNode **f_node_of_real;
268 /* -------- PBooleanOp -------- */
270 class PBooleanOp : public PNode {
272 static const ClassType PBooleanOpClass;
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);
286 protected: // variables
289 /* -------- POr -------- */
291 class POr : public PBooleanOp {
293 static const ClassType POrClass;
295 PNotBoth *f_not_both;
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 ()
304 virtual char *symbol()
306 static void insert (PRoot *root, long pos);
307 virtual const int precedence ()
308 { return f_precedence; }
310 protected: // variables
311 static char *f_symbol;
312 static const int f_precedence;
315 /* -------- PAnd -------- */
317 class PAnd : public PBooleanOp {
319 static const ClassType PAndClass;
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()
330 static void insert (PRoot *root, long pos);
331 virtual const int precedence ()
332 { return f_precedence; }
334 protected: // variables
335 static char *f_symbol;
336 static const int f_precedence;
339 /* -------- PRelation -------- */
341 class PRelation : public PBooleanOp {
343 static const ClassType PRelationClass;
345 PPostfixOp *f_proximity;
349 : f_proximity (NULL) { }
350 virtual bool isa (ClassType type)
351 { return (type == PRelationClass ? TRUE : PBooleanOp::isa (type)); }
353 protected: // variables
356 /* -------- PNear -------- */
358 class PNear : public PRelation {
360 static const ClassType PNearClass;
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 ()
371 static void insert (PRoot *root, long pos);
372 virtual const int precedence ()
373 { return f_precedence; }
375 protected: // variables
376 static char *f_symbol;
377 static const int f_precedence;
380 /* -------- PBefore -------- */
382 class PBefore : public PRelation {
384 static const ClassType PBeforeClass;
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 ()
395 static void insert (PRoot *root, long pos);
396 virtual const int precedence ()
397 { return f_precedence; }
399 protected: // variables
400 static char *f_symbol;
401 static const int f_precedence;
404 /* -------- PPrefixOp -------- */
406 class PPrefixOp : public PNode {
408 static const ClassType PPrefixOpClass;
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; }
421 /* -------- PNot -------- */
423 class PNot : public PPrefixOp {
425 static const ClassType PNotClass;
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()
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);
442 protected: // variables
443 static char *f_symbol;
444 static const int f_precedence;
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. */
453 class PPostfixOp : public PNode {
455 static const ClassType PPostfixOpClass;
458 virtual bool isa (ClassType type)
459 { return (type == PPostfixOpClass ? TRUE : PNode::isa (type)); }
462 /* -------- PWeight -------- */
464 class PWeight : public PPostfixOp {
466 static const ClassType PWeightClass;
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 ()
475 static bool can_insert (PRoot *root, long position);
476 virtual const int precedence ()
477 { return f_precedence; }
479 protected: // variables
480 static char *f_symbol;
481 static const int f_precedence;
484 /* -------- PProximity -------- */
486 class PProximity : public PPostfixOp {
488 static const ClassType PProximityClass;
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()
497 virtual const int precedence ()
498 { return f_precedence; }
500 protected: // variables
501 static char *f_symbol;
502 static const int f_precedence;
504 /* -------- PProximity -------- */
506 class PNotBoth : public PPostfixOp {
508 static const ClassType PNotBothClass;
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()
517 virtual const int precedence ()
518 { return f_precedence; }
519 static bool can_insert (PRoot *root, int position);
521 protected: // variables
522 static char *f_symbol;
523 static const int f_precedence;
526 #endif /* _ParseTree_hh */
527 /* DO NOT ADD ANY LINES AFTER THIS #endif */