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