sl@0: /********************************************************************
sl@0:  * COPYRIGHT:
sl@0:  * Copyright (c) 2001-2003, International Business Machines Corporation and
sl@0:  * others. All Rights Reserved.
sl@0:  ********************************************************************/
sl@0: 
sl@0: #ifndef RBBINODE_H
sl@0: #define RBBINODE_H
sl@0: 
sl@0: #include "unicode/utypes.h"
sl@0: #include "unicode/uobject.h"
sl@0: 
sl@0: //
sl@0: //  class RBBINode
sl@0: //
sl@0: //                    Represents a node in the parse tree generated when reading
sl@0: //                    a rule file.
sl@0: //
sl@0: 
sl@0: U_NAMESPACE_BEGIN
sl@0: 
sl@0: class    UnicodeSet;
sl@0: class    UVector;
sl@0: 
sl@0: class RBBINode : public UMemory {
sl@0:     public:
sl@0:         enum NodeType {
sl@0:             setRef,
sl@0:             uset,
sl@0:             varRef,
sl@0:             leafChar,
sl@0:             lookAhead,
sl@0:             tag,
sl@0:             endMark,
sl@0:             opStart,
sl@0:             opCat,
sl@0:             opOr,
sl@0:             opStar,
sl@0:             opPlus,
sl@0:             opQuestion,
sl@0:             opBreak,
sl@0:             opReverse,
sl@0:             opLParen
sl@0:         };
sl@0: 
sl@0:         enum OpPrecedence {      
sl@0:             precZero,
sl@0:             precStart,
sl@0:             precLParen,
sl@0:             precOpOr,
sl@0:             precOpCat
sl@0:         };
sl@0:             
sl@0:         NodeType      fType;
sl@0:         RBBINode      *fParent;
sl@0:         RBBINode      *fLeftChild;
sl@0:         RBBINode      *fRightChild;
sl@0:         UnicodeSet    *fInputSet;           // For uset nodes only.
sl@0:         OpPrecedence  fPrecedence;          // For binary ops only.
sl@0:         
sl@0:         UnicodeString fText;                // Text corresponding to this node.
sl@0:                                             //   May be lazily evaluated when (if) needed
sl@0:                                             //   for some node types.
sl@0:         int           fFirstPos;            // Position in the rule source string of the
sl@0:                                             //   first text associated with the node.
sl@0:                                             //   If there's a left child, this will be the same
sl@0:                                             //   as that child's left pos.
sl@0:         int           fLastPos;             //  Last position in the rule source string
sl@0:                                             //    of any text associated with this node.
sl@0:                                             //    If there's a right child, this will be the same
sl@0:                                             //    as that child's last postion.
sl@0: 
sl@0:         UBool         fNullable;            // See Aho.
sl@0:         int32_t       fVal;                 // For leafChar nodes, the value.
sl@0:                                             //   Values are the character category,
sl@0:                                             //   corresponds to columns in the final
sl@0:                                             //   state transition table.
sl@0: 
sl@0:         UBool         fLookAheadEnd;        // For endMark nodes, set TRUE if
sl@0:                                             //   marking the end of a look-ahead rule.
sl@0: 
sl@0:         UVector       *fFirstPosSet;
sl@0:         UVector       *fLastPosSet;         // TODO: rename fFirstPos & fLastPos to avoid confusion.
sl@0:         UVector       *fFollowPos;
sl@0: 
sl@0: 
sl@0:         RBBINode(NodeType t);
sl@0:         RBBINode(const RBBINode &other);
sl@0:         ~RBBINode();
sl@0:         
sl@0:         RBBINode    *cloneTree();
sl@0:         RBBINode    *flattenVariables();
sl@0:         void         flattenSets();
sl@0:         void         findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &status);
sl@0: 
sl@0: #ifdef RBBI_DEBUG
sl@0:         void        printNode();
sl@0:         void        printTree(UBool withHeading);
sl@0: #else
sl@0:         // Do-nothing inline functions for non-debug builds.  Can't make empty defines for member
sl@0:         //   functions - they won't compile at the call sites.
sl@0:         int         fakeField;
sl@0:         #define printNode() fakeField=0;
sl@0:         #define printTree(withHeading) fakeField=0;
sl@0: #endif
sl@0: 
sl@0:     private:
sl@0:         RBBINode &operator = (const RBBINode &other); // No defs.
sl@0:         UBool operator == (const RBBINode &other);    // Private, so these functions won't accidently be used.
sl@0: 
sl@0:         int           fSerialNum;           //  Debugging aids.
sl@0:         static int    gLastSerial;
sl@0: };
sl@0: 
sl@0: #ifdef RBBI_DEBUG
sl@0: U_CFUNC void 
sl@0: RBBI_DEBUG_printUnicodeString(const UnicodeString &s, int minWidth=0);
sl@0: #endif
sl@0: 
sl@0: U_NAMESPACE_END
sl@0: 
sl@0: #endif
sl@0: