1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
8 **********************************************************************
9 * Copyright (c) 2002-2016, International Business Machines
10 * Corporation and others. All Rights Reserved.
11 **********************************************************************
17 #include "unicode/utypes.h"
18 #include "unicode/uobject.h"
19 #include "unicode/rbbi.h"
25 class RBBIRuleScanner;
26 class RBBIRuleBuilder;
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.
33 // This class is part of the RBBI implementation only.
34 // There is no user-visible public API here.
37 class RBBITableBuilder : public UMemory {
39 RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode);
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.
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);
57 void buildStateTable();
58 void flagAcceptingStates();
59 void flagLookAheadStates();
60 void flagTaggedStates();
61 void mergeRuleStatusVals();
63 void addRuleRootNodes(UVector *dest, RBBINode *node);
65 // Set functions for UVector.
66 // TODO: make a USet subclass of UVector
68 void setAdd(UVector *dest, UVector *source);
69 UBool setEquals(UVector *a, UVector *b);
71 void sortedAdd(UVector **dest, int32_t val);
75 void printSet(UVector *s);
76 void printPosSets(RBBINode *n /* = NULL*/);
78 void printRuleStatusTable();
81 #define printPosSets(n)
83 #define printRuleStatusTable()
88 RBBINode *&fTree; // The root node of the parse tree to build a
92 UVector *fDStates; // D states (Aho's terminology)
93 // Index is state number
94 // Contents are RBBIStateDescriptor pointers.
97 RBBITableBuilder(const RBBITableBuilder &other); // forbid copying of this class
98 RBBITableBuilder &operator=(const RBBITableBuilder &other); // forbid copying of this class
102 // RBBIStateDescriptor - The DFA is constructed as a set of these descriptors,
103 // one for each state.
104 class RBBIStateDescriptor : public UMemory {
111 UVector *fPositions; // Set of parse tree positions associated
112 // with this state. Unordered (it's a set).
113 // UVector contents are RBBINode *
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
120 RBBIStateDescriptor(int maxInputSymbol, UErrorCode *fStatus);
121 ~RBBIStateDescriptor();
124 RBBIStateDescriptor(const RBBIStateDescriptor &other); // forbid copying of this class
125 RBBIStateDescriptor &operator=(const RBBIStateDescriptor &other); // forbid copying of this class