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