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