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