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