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