1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/*
**********************************************************************
* Copyright (c) 2002-2016, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
*
**********************************************************************
* Legacy version of RBBITableBuilder from ICU 57,
* only for use by Apple RuleBasedTokenizer.
* originally added per rdar://37249396 Add ICU 57 version of RBBI classes,
* urbtok57 interfaces for access via RBT, and better tests
**********************************************************************
*/
#ifndef RBBITBLB57_H
#define RBBITBLB57_H
#include <_foundation_unicode/utypes.h>
#include <_foundation_unicode/uobject.h>
#include "uvectr32.h"
#include "rbbitblb.h"
#include "rbbi57.h"
#include "rbbinode.h"
U_NAMESPACE_BEGIN
class RBBIRuleScanner57;
class RBBIRuleBuilder57;
class UVector32;
//
// class RBBITableBuilder57 is part of the RBBI rule compiler.
// It builds the state transition table used by the RBBI runtime
// from the expression syntax tree generated by the rule scanner.
//
// This class is part of the RBBI implementation only.
// There is no user-visible public API here.
//
class RBBITableBuilder57 : public UMemory {
public:
RBBITableBuilder57(RBBIRuleBuilder57 *rb, RBBINode **rootNode);
~RBBITableBuilder57();
void build();
int32_t getTableSize() const; // Return the runtime size in bytes of
// the built state table
void exportTable(void *where); // fill in the runtime state table.
// Sufficient memory must exist at
// the specified location.
private:
void calcNullable(RBBINode *n);
void calcFirstPos(RBBINode *n);
void calcLastPos(RBBINode *n);
void calcFollowPos(RBBINode *n);
void calcChainedFollowPos(RBBINode *n);
void bofFixup();
void buildStateTable();
void flagAcceptingStates();
void flagLookAheadStates();
void flagTaggedStates();
void mergeRuleStatusVals();
void addRuleRootNodes(UVector *dest, RBBINode *node);
// Set functions for UVector.
// TODO: make a USet subclass of UVector
void setAdd(UVector *dest, UVector *source);
UBool setEquals(UVector *a, UVector *b);
void sortedAdd(UVector **dest, int32_t val);
public:
#ifdef RBBI_DEBUG
void printSet(UVector *s);
void printPosSets(RBBINode *n /* = NULL*/);
void printStates();
void printRuleStatusTable();
#else
#define printSet(s)
#define printPosSets(n)
#define printStates()
#define printRuleStatusTable()
#endif
private:
RBBIRuleBuilder57 *fRB;
RBBINode *&fTree; // The root node of the parse tree to build a
// table for.
UErrorCode *fStatus;
UVector *fDStates; // D states (Aho's terminology)
// Index is state number
// Contents are RBBIStateDescriptor pointers.
RBBITableBuilder57(const RBBITableBuilder57 &other) = delete; // forbid copying of this class
RBBITableBuilder57 &operator=(const RBBITableBuilder57 &other) = delete; // forbid copying of this class
};
// class RBBIStateDescriptor - use standard rbbitblb.h
U_NAMESPACE_END
#endif
|