]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/rbbitblb.h
ICU-6.2.8.tar.gz
[apple/icu.git] / icuSources / common / rbbitblb.h
1 //
2 // rbbitblb.h
3 //
4
5 /*
6 **********************************************************************
7 * Copyright (c) 2002-2004, International Business Machines
8 * Corporation and others. All Rights Reserved.
9 **********************************************************************
10 */
11
12 #ifndef RBBITBLB_H
13 #define RBBITBLB_H
14
15 #include "unicode/utypes.h"
16 #include "unicode/uobject.h"
17 #include "unicode/rbbi.h"
18 #include "rbbinode.h"
19
20
21 U_NAMESPACE_BEGIN
22
23 class RBBIRuleScanner;
24 class RBBIRuleBuilder;
25
26 //
27 // class RBBITableBuilder is part of the RBBI rule compiler.
28 // It builds the state transition table used by the RBBI runtime
29 // from the expression syntax tree generated by the rule scanner.
30 //
31 // This class is part of the RBBI implementation only.
32 // There is no user-visible public API here.
33 //
34
35 class RBBITableBuilder : public UMemory {
36 public:
37 RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode);
38 ~RBBITableBuilder();
39
40 void build();
41 int32_t getTableSize() const; // Return the runtime size in bytes of
42 // the built state table
43 void exportTable(void *where); // fill in the runtime state table.
44 // Sufficient memory must exist at
45 // the specified location.
46
47
48 private:
49 void calcNullable(RBBINode *n);
50 void calcFirstPos(RBBINode *n);
51 void calcLastPos(RBBINode *n);
52 void calcFollowPos(RBBINode *n);
53 void calcChainedFollowPos(RBBINode *n);
54 void buildStateTable();
55 void flagAcceptingStates();
56 void flagLookAheadStates();
57 void flagTaggedStates();
58 void mergeRuleStatusVals();
59
60 // Set functions for UVector.
61 // TODO: make a USet subclass of UVector
62
63 void setAdd(UVector *dest, UVector *source);
64 UBool setEquals(UVector *a, UVector *b);
65
66 void sortedAdd(UVector **dest, int32_t val);
67
68 public:
69 #ifdef RBBI_DEBUG
70 void printSet(UVector *s);
71 void printPosSets(RBBINode *n /* = NULL*/);
72 void printStates();
73 void printRuleStatusTable();
74 #else
75 #define printSet(s)
76 #define printPosSets(n)
77 #define printStates()
78 #define printRuleStatusTable()
79 #endif
80
81 private:
82 RBBIRuleBuilder *fRB;
83 RBBINode *&fTree; // The root node of the parse tree to build a
84 // table for.
85 UErrorCode *fStatus;
86
87 UVector *fDStates; // D states (Aho's terminology)
88 // Index is state number
89 // Contents are RBBIStateDescriptor pointers.
90
91
92 RBBITableBuilder(const RBBITableBuilder &other); // forbid copying of this class
93 RBBITableBuilder &operator=(const RBBITableBuilder &other); // forbid copying of this class
94 };
95
96 //
97 // RBBIStateDescriptor - The DFA is constructed as a set of these descriptors,
98 // one for each state.
99 class RBBIStateDescriptor : public UMemory {
100 public:
101 UBool fMarked;
102 int32_t fAccepting;
103 int32_t fLookAhead;
104 UVector *fTagVals;
105 int32_t fTagsIdx;
106 UVector *fPositions; // Set of parse tree positions associated
107 // with this state. Unordered (it's a set).
108 // UVector contents are RBBINode *
109
110 UVector *fDtran; // Transitions out of this state.
111 // indexed by input character
112 // contents is int index of dest state
113 // in RBBITableBuilder.fDStates
114
115 RBBIStateDescriptor(int maxInputSymbol, UErrorCode *fStatus);
116 ~RBBIStateDescriptor();
117
118 private:
119 RBBIStateDescriptor(const RBBIStateDescriptor &other); // forbid copying of this class
120 RBBIStateDescriptor &operator=(const RBBIStateDescriptor &other); // forbid copying of this class
121 };
122
123
124
125 U_NAMESPACE_END
126 #endif