]> git.saurik.com Git - apple/icu.git/blob - icuSources/common/rbbitblb.h
ICU-511.35.tar.gz
[apple/icu.git] / icuSources / common / rbbitblb.h
1 //
2 // rbbitblb.h
3 //
4
5 /*
6 **********************************************************************
7 * Copyright (c) 2002-2005, 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 bofFixup();
55 void buildStateTable();
56 void flagAcceptingStates();
57 void flagLookAheadStates();
58 void flagTaggedStates();
59 void mergeRuleStatusVals();
60
61 // Set functions for UVector.
62 // TODO: make a USet subclass of UVector
63
64 void setAdd(UVector *dest, UVector *source);
65 UBool setEquals(UVector *a, UVector *b);
66
67 void sortedAdd(UVector **dest, int32_t val);
68
69 public:
70 #ifdef RBBI_DEBUG
71 void printSet(UVector *s);
72 void printPosSets(RBBINode *n /* = NULL*/);
73 void printStates();
74 void printRuleStatusTable();
75 #else
76 #define printSet(s)
77 #define printPosSets(n)
78 #define printStates()
79 #define printRuleStatusTable()
80 #endif
81
82 private:
83 RBBIRuleBuilder *fRB;
84 RBBINode *&fTree; // The root node of the parse tree to build a
85 // table for.
86 UErrorCode *fStatus;
87
88 UVector *fDStates; // D states (Aho's terminology)
89 // Index is state number
90 // Contents are RBBIStateDescriptor pointers.
91
92
93 RBBITableBuilder(const RBBITableBuilder &other); // forbid copying of this class
94 RBBITableBuilder &operator=(const RBBITableBuilder &other); // forbid copying of this class
95 };
96
97 //
98 // RBBIStateDescriptor - The DFA is constructed as a set of these descriptors,
99 // one for each state.
100 class RBBIStateDescriptor : public UMemory {
101 public:
102 UBool fMarked;
103 int32_t fAccepting;
104 int32_t fLookAhead;
105 UVector *fTagVals;
106 int32_t fTagsIdx;
107 UVector *fPositions; // Set of parse tree positions associated
108 // with this state. Unordered (it's a set).
109 // UVector contents are RBBINode *
110
111 UVector *fDtran; // Transitions out of this state.
112 // indexed by input character
113 // contents is int index of dest state
114 // in RBBITableBuilder.fDStates
115
116 RBBIStateDescriptor(int maxInputSymbol, UErrorCode *fStatus);
117 ~RBBIStateDescriptor();
118
119 private:
120 RBBIStateDescriptor(const RBBIStateDescriptor &other); // forbid copying of this class
121 RBBIStateDescriptor &operator=(const RBBIStateDescriptor &other); // forbid copying of this class
122 };
123
124
125
126 U_NAMESPACE_END
127 #endif