xref: /aosp_15_r20/external/icu/libicu/cts_headers/rbbinode.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /********************************************************************
4  * COPYRIGHT:
5  * Copyright (c) 2001-2016, International Business Machines Corporation and
6  * others. All Rights Reserved.
7  ********************************************************************/
8 
9 #ifndef RBBINODE_H
10 #define RBBINODE_H
11 
12 #include "unicode/utypes.h"
13 #include "unicode/unistr.h"
14 #include "unicode/uobject.h"
15 
16 //
17 //  class RBBINode
18 //
19 //                    Represents a node in the parse tree generated when reading
20 //                    a rule file.
21 //
22 
23 U_NAMESPACE_BEGIN
24 
25 class    UnicodeSet;
26 class    UVector;
27 
28 class RBBINode : public UMemory {
29     public:
30         enum NodeType {
31             setRef,
32             uset,
33             varRef,
34             leafChar,
35             lookAhead,
36             tag,
37             endMark,
38             opStart,
39             opCat,
40             opOr,
41             opStar,
42             opPlus,
43             opQuestion,
44             opBreak,
45             opReverse,
46             opLParen
47         };
48 
49         enum OpPrecedence {
50             precZero,
51             precStart,
52             precLParen,
53             precOpOr,
54             precOpCat
55         };
56 
57         NodeType      fType;
58         RBBINode      *fParent;
59         RBBINode      *fLeftChild;
60         RBBINode      *fRightChild;
61         UnicodeSet    *fInputSet;           // For uset nodes only.
62         OpPrecedence  fPrecedence;          // For binary ops only.
63 
64         UnicodeString fText;                // Text corresponding to this node.
65                                             //   May be lazily evaluated when (if) needed
66                                             //   for some node types.
67         int           fFirstPos;            // Position in the rule source string of the
68                                             //   first text associated with the node.
69                                             //   If there's a left child, this will be the same
70                                             //   as that child's left pos.
71         int           fLastPos;             //  Last position in the rule source string
72                                             //    of any text associated with this node.
73                                             //    If there's a right child, this will be the same
74                                             //    as that child's last position.
75 
76         UBool         fNullable;            // See Aho.
77         int32_t       fVal;                 // For leafChar nodes, the value.
78                                             //   Values are the character category,
79                                             //   corresponds to columns in the final
80                                             //   state transition table.
81 
82         UBool         fLookAheadEnd;        // For endMark nodes, set true if
83                                             //   marking the end of a look-ahead rule.
84 
85         UBool         fRuleRoot;            // True if this node is the root of a rule.
86         UBool         fChainIn;             // True if chaining into this rule is allowed
87                                             //     (no '^' present).
88 
89         UVector       *fFirstPosSet;
90         UVector       *fLastPosSet;         // TODO: rename fFirstPos & fLastPos to avoid confusion.
91         UVector       *fFollowPos;
92 
93 
94         RBBINode(NodeType t);
95         RBBINode(const RBBINode &other);
96         ~RBBINode();
97         static void  NRDeleteNode(RBBINode *node);
98 
99         RBBINode    *cloneTree();
100         RBBINode    *flattenVariables(UErrorCode &status, int depth=0);
101         void         flattenSets();
102         void         findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &status);
103 
104 #ifdef RBBI_DEBUG
105         static void printNodeHeader();
106         static void printNode(const RBBINode *n);
107         static void printTree(const RBBINode *n, UBool withHeading);
108 #endif
109 
110     private:
111         RBBINode &operator = (const RBBINode &other); // No defs.
112         bool operator == (const RBBINode &other);     // Private, so these functions won't accidentally be used.
113 
114 #ifdef RBBI_DEBUG
115     public:
116         int           fSerialNum;           //  Debugging aids.
117 #endif
118 };
119 
120 #ifdef RBBI_DEBUG
121 U_CFUNC void
122 RBBI_DEBUG_printUnicodeString(const UnicodeString &s, int minWidth=0);
123 #endif
124 
125 U_NAMESPACE_END
126 
127 #endif
128 
129