sl@0: // sl@0: // rbbitblb.h sl@0: // sl@0: sl@0: /* sl@0: ********************************************************************** sl@0: * Copyright (c) 2002-2004, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: ********************************************************************** sl@0: */ sl@0: sl@0: #ifndef RBBITBLB_H sl@0: #define RBBITBLB_H sl@0: sl@0: #include "unicode/utypes.h" sl@0: #include "unicode/uobject.h" sl@0: #include "unicode/rbbi.h" sl@0: #include "rbbinode.h" sl@0: sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: class RBBIRuleScanner; sl@0: class RBBIRuleBuilder; sl@0: sl@0: // sl@0: // class RBBITableBuilder is part of the RBBI rule compiler. sl@0: // It builds the state transition table used by the RBBI runtime sl@0: // from the expression syntax tree generated by the rule scanner. sl@0: // sl@0: // This class is part of the RBBI implementation only. sl@0: // There is no user-visible public API here. sl@0: // sl@0: sl@0: class RBBITableBuilder : public UMemory { sl@0: public: sl@0: RBBITableBuilder(RBBIRuleBuilder *rb, RBBINode **rootNode); sl@0: ~RBBITableBuilder(); sl@0: sl@0: void build(); sl@0: int32_t getTableSize() const; // Return the runtime size in bytes of sl@0: // the built state table sl@0: void exportTable(void *where); // fill in the runtime state table. sl@0: // Sufficient memory must exist at sl@0: // the specified location. sl@0: sl@0: sl@0: private: sl@0: void calcNullable(RBBINode *n); sl@0: void calcFirstPos(RBBINode *n); sl@0: void calcLastPos(RBBINode *n); sl@0: void calcFollowPos(RBBINode *n); sl@0: void calcChainedFollowPos(RBBINode *n); sl@0: void buildStateTable(); sl@0: void flagAcceptingStates(); sl@0: void flagLookAheadStates(); sl@0: void flagTaggedStates(); sl@0: void mergeRuleStatusVals(); sl@0: sl@0: // Set functions for UVector. sl@0: // TODO: make a USet subclass of UVector sl@0: sl@0: void setAdd(UVector *dest, UVector *source); sl@0: UBool setEquals(UVector *a, UVector *b); sl@0: sl@0: void sortedAdd(UVector **dest, int32_t val); sl@0: sl@0: public: sl@0: #ifdef RBBI_DEBUG sl@0: void printSet(UVector *s); sl@0: void printPosSets(RBBINode *n /* = NULL*/); sl@0: void printStates(); sl@0: void printRuleStatusTable(); sl@0: #else sl@0: #define printSet(s) sl@0: #define printPosSets(n) sl@0: #define printStates() sl@0: #define printRuleStatusTable() sl@0: #endif sl@0: sl@0: private: sl@0: RBBIRuleBuilder *fRB; sl@0: RBBINode *&fTree; // The root node of the parse tree to build a sl@0: // table for. sl@0: UErrorCode *fStatus; sl@0: sl@0: UVector *fDStates; // D states (Aho's terminology) sl@0: // Index is state number sl@0: // Contents are RBBIStateDescriptor pointers. sl@0: sl@0: sl@0: RBBITableBuilder(const RBBITableBuilder &other); // forbid copying of this class sl@0: RBBITableBuilder &operator=(const RBBITableBuilder &other); // forbid copying of this class sl@0: }; sl@0: sl@0: // sl@0: // RBBIStateDescriptor - The DFA is constructed as a set of these descriptors, sl@0: // one for each state. sl@0: class RBBIStateDescriptor : public UMemory { sl@0: public: sl@0: UBool fMarked; sl@0: int32_t fAccepting; sl@0: int32_t fLookAhead; sl@0: UVector *fTagVals; sl@0: int32_t fTagsIdx; sl@0: UVector *fPositions; // Set of parse tree positions associated sl@0: // with this state. Unordered (it's a set). sl@0: // UVector contents are RBBINode * sl@0: sl@0: UVector *fDtran; // Transitions out of this state. sl@0: // indexed by input character sl@0: // contents is int index of dest state sl@0: // in RBBITableBuilder.fDStates sl@0: sl@0: RBBIStateDescriptor(int maxInputSymbol, UErrorCode *fStatus); sl@0: ~RBBIStateDescriptor(); sl@0: sl@0: private: sl@0: RBBIStateDescriptor(const RBBIStateDescriptor &other); // forbid copying of this class sl@0: RBBIStateDescriptor &operator=(const RBBIStateDescriptor &other); // forbid copying of this class sl@0: }; sl@0: sl@0: sl@0: sl@0: U_NAMESPACE_END sl@0: #endif