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