]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/rbbitblb.h
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / common / rbbitblb.h
CommitLineData
b75a7d8f
A
1//
2// rbbitblb.h
3//
4
5/*
6**********************************************************************
374ca955 7* Copyright (c) 2002-2004, International Business Machines
b75a7d8f
A
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
21U_NAMESPACE_BEGIN
22
23class RBBIRuleScanner;
24class 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
35class RBBITableBuilder : public UMemory {
36public:
37 RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode);
38 ~RBBITableBuilder();
39
40 void build();
374ca955 41 int32_t getTableSize() const; // Return the runtime size in bytes of
b75a7d8f
A
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
374ca955 47
b75a7d8f
A
48private:
49 void calcNullable(RBBINode *n);
50 void calcFirstPos(RBBINode *n);
51 void calcLastPos(RBBINode *n);
52 void calcFollowPos(RBBINode *n);
374ca955 53 void calcChainedFollowPos(RBBINode *n);
b75a7d8f
A
54 void buildStateTable();
55 void flagAcceptingStates();
56 void flagLookAheadStates();
57 void flagTaggedStates();
374ca955 58 void mergeRuleStatusVals();
b75a7d8f
A
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
374ca955
A
66 void sortedAdd(UVector **dest, int32_t val);
67
68public:
69#ifdef RBBI_DEBUG
b75a7d8f 70 void printSet(UVector *s);
374ca955 71 void printPosSets(RBBINode *n /* = NULL*/);
b75a7d8f 72 void printStates();
374ca955
A
73 void printRuleStatusTable();
74#else
75 #define printSet(s)
76 #define printPosSets(n)
77 #define printStates()
78 #define printRuleStatusTable()
79#endif
b75a7d8f
A
80
81private:
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
374ca955 91
b75a7d8f
A
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.
99class RBBIStateDescriptor : public UMemory {
100public:
101 UBool fMarked;
102 int32_t fAccepting;
103 int32_t fLookAhead;
374ca955
A
104 UVector *fTagVals;
105 int32_t fTagsIdx;
b75a7d8f
A
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
118private:
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
125U_NAMESPACE_END
126#endif