ICU-45 RBBI: conditionalize / remove stdio and stdlib dependencies.

Remove dead code.  Clean up some comments.

X-SVN-Rev: 9509
This commit is contained in:
Andy Heninger 2002-08-01 16:17:41 +00:00
parent e7fd8044f4
commit 7ab245e6e9
15 changed files with 377 additions and 390 deletions

View file

@ -23,11 +23,10 @@
#include "unicode/udata.h"
#include "unicode/resbund.h"
#include "cstring.h"
#include <string.h>
// *****************************************************************************
// class BreakIterator
// This class implements methods for finding the location of boundaries in text.
// This class implements methods for finding the location of boundaries in text.
// Instances of BreakIterator maintain a current position and scan over text
// returning the index of characters where boundaries occur.
// *****************************************************************************
@ -187,7 +186,7 @@ BreakIterator*
BreakIterator::createTitleInstance(const Locale& /* key */, UErrorCode& status)
{
// WARNING: This routine is currently written specifically to handle only the
// default rules files. This function will have to be made fully general
// default rules files. This function will have to be made fully general
// at some time in the future!
BreakIterator* result = NULL;
static const char filename[] = "title";

View file

@ -29,11 +29,6 @@
#include <string.h>
/*
#define uprv_malloc(size) U_STANDARD_CPP_NAMESPACE malloc(size)
#define uprv_realloc(buffer, size) U_STANDARD_CPP_NAMESPACE realloc(buffer, size)
#define uprv_free(buffer) U_STANDARD_CPP_NAMESPACE free(buffer)
*/
#define uprv_memcpy(dst, src, size) U_STANDARD_CPP_NAMESPACE memcpy(dst, src, size)
#define uprv_memmove(dst, src, size) U_STANDARD_CPP_NAMESPACE memmove(dst, src, size)
#define uprv_memset(buffer, mark, size) U_STANDARD_CPP_NAMESPACE memset(buffer, mark, size)

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,6 @@
#include "filestrm.h"
#include "cmemory.h"
#include "stdio.h"
#include "uassert.h"
U_NAMESPACE_BEGIN
@ -177,10 +176,12 @@ void RuleBasedBreakIterator::init() {
fDictionaryCharCount = 0;
if (debugInitDone == FALSE) {
#ifdef RBBI_DEBUG
char *debugEnv = getenv("U_RBBIDEBUG");
if (debugEnv && strstr(debugEnv, "trace")) {
fTrace = TRUE;
}
#endif
debugInitDone = TRUE;
}
}
@ -537,7 +538,7 @@ int32_t RuleBasedBreakIterator::current(void) const {
//-----------------------------------------------------------------------------------
int32_t RuleBasedBreakIterator::handleNext(void) {
if (fTrace) {
printf("Handle Next pos char state category \n");
RBBIDebugPrintf("Handle Next pos char state category \n");
}
// No matter what, handleNext alway correctly sets the break tag value.
@ -597,13 +598,13 @@ int32_t RuleBasedBreakIterator::handleNext(void) {
}
if (fTrace) {
printf(" %4d ", fText->getIndex());
RBBIDebugPrintf(" %4d ", fText->getIndex());
if (0x20<=c && c<0x7f) {
printf("\"%c\" ", c);
RBBIDebugPrintf("\"%c\" ", c);
} else {
printf("%5x ", c);
RBBIDebugPrintf("%5x ", c);
}
printf("%3d %3d\n", state, category);
RBBIDebugPrintf("%3d %3d\n", state, category);
}
// look up a state transition in the state table
@ -680,7 +681,7 @@ continueOn:
fText->setIndex(result);
if (fTrace) {
printf("result = %d\n\n", result);
RBBIDebugPrintf("result = %d\n\n", result);
}
return result;
}
@ -723,7 +724,7 @@ int32_t RuleBasedBreakIterator::handlePrevious(void) {
}
if (fTrace) {
printf("Handle Prev pos char state category \n");
RBBIDebugPrintf("Handle Prev pos char state category \n");
}
// loop until we reach the beginning of the text or transition to state 0
@ -746,13 +747,13 @@ int32_t RuleBasedBreakIterator::handlePrevious(void) {
}
if (fTrace) {
printf(" %4d ", fText->getIndex());
RBBIDebugPrintf(" %4d ", fText->getIndex());
if (0x20<=c && c<0x7f) {
printf("\"%c\" ", c);
RBBIDebugPrintf("\"%c\" ", c);
} else {
printf("%5x ", c);
RBBIDebugPrintf("%5x ", c);
}
printf("%3d %3d\n", state, category);
RBBIDebugPrintf("%3d %3d\n", state, category);
}
// look up a state transition in the backwards state table
@ -949,19 +950,6 @@ BreakIterator * RuleBasedBreakIterator::createBufferClone(void *stackBuffer,
//-------------------------------------------------------------------------------
//
// debugDumpTables Debugging Function
//
//-------------------------------------------------------------------------------
#ifdef RBBI_DEBUG
void RuleBasedBreakIterator::debugDumpTables() const {
fData->debugDumpTables();
}
#endif
//-------------------------------------------------------------------------------
//
// isDictionaryChar Return true if the category lookup for this char

View file

@ -7,12 +7,13 @@
#include "unicode/utypes.h"
#include "rbbidata.h"
#include "rbbirb.h"
#include "utrie.h"
#include "udatamem.h"
#include "cmemory.h"
#include "cstring.h"
#include "uassert.h"
#include <stdio.h>
U_NAMESPACE_BEGIN
@ -21,7 +22,7 @@ const char RBBIDataWrapper::fgClassID=0;
//-----------------------------------------------------------------------------
//
// Constructors.
// Constructors.
//
//-----------------------------------------------------------------------------
RBBIDataWrapper::RBBIDataWrapper(const RBBIDataHeader *data, UErrorCode &status) {
@ -57,7 +58,7 @@ U_CDECL_END
//-----------------------------------------------------------------------------
//
// init(). Does most of the work of construction, shared between the
// constructors.
// constructors.
//
//-----------------------------------------------------------------------------
void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) {
@ -91,11 +92,12 @@ void RBBIDataWrapper::init(const RBBIDataHeader *data, UErrorCode &status) {
fRuleSource = (UChar *)((char *)data + fHeader->fRuleSource);
fRuleString.setTo(TRUE, fRuleSource, -1);
fRefCount = 1;
char *debugEnv = getenv("U_RBBIDEBUG"); // TODO: make conditional on some compile time setting
if (debugEnv && strstr(debugEnv, "data")) {this->printData();}
fRefCount = 1;
#ifdef RBBI_DEBUG
char *debugEnv = getenv("U_RBBIDEBUG");
if (debugEnv && uprv_strstr(debugEnv, "data")) {this->printData();}
#endif
}
@ -114,7 +116,7 @@ RBBIDataWrapper::~RBBIDataWrapper() {
}
//-----------------------------------------------------------------------------
//
// Operator == Consider two RBBIDataWrappers to be equal if they
@ -184,36 +186,36 @@ const UnicodeString &RBBIDataWrapper::getRuleSourceString() {
void RBBIDataWrapper::printData() {
uint32_t c, s;
printf("RBBI Data at %p\n", (void *)fHeader);
printf(" Version = %d\n", fHeader->fVersion);
printf(" total length of data = %d\n", fHeader->fLength);
printf(" number of character categories = %d\n\n", fHeader->fCatCount);
RBBIDebugPrintf("RBBI Data at %p\n", (void *)fHeader);
RBBIDebugPrintf(" Version = %d\n", fHeader->fVersion);
RBBIDebugPrintf(" total length of data = %d\n", fHeader->fLength);
RBBIDebugPrintf(" number of character categories = %d\n\n", fHeader->fCatCount);
printf(" Forward State Transition Table\n");
printf("State | Acc LA Tag");
for (c=0; c<fHeader->fCatCount; c++) {printf("%3d ", c);};
printf("\n------|---------------"); for (c=0;c<fHeader->fCatCount; c++) {printf("----");}
printf("\n");
RBBIDebugPrintf(" Forward State Transition Table\n");
RBBIDebugPrintf("State | Acc LA Tag");
for (c=0; c<fHeader->fCatCount; c++) {RBBIDebugPrintf("%3d ", c);};
RBBIDebugPrintf("\n------|---------------"); for (c=0;c<fHeader->fCatCount; c++) {RBBIDebugPrintf("----");}
RBBIDebugPrintf("\n");
for (s=0; s<fForwardTable->fNumStates; s++) {
RBBIStateTableRow *row = (RBBIStateTableRow *)
(fForwardTable->fTableData + (fForwardTable->fRowLen * s));
printf("%4d | %3d %3d %3d ", s, row->fAccepting, row->fLookAhead, row->fTag);
RBBIDebugPrintf("%4d | %3d %3d %3d ", s, row->fAccepting, row->fLookAhead, row->fTag);
for (c=0; c<fHeader->fCatCount; c++) {
printf("%3d ", row->fNextState[c]);
RBBIDebugPrintf("%3d ", row->fNextState[c]);
};
printf("\n");
RBBIDebugPrintf("\n");
}
printf("\nOrignal Rules source:\n");
RBBIDebugPrintf("\nOrignal Rules source:\n");
c = 0;
for (;;) {
if (fRuleSource[c] == 0)
break;
putchar(fRuleSource[c]);
RBBIDebugPrintf("%c", fRuleSource[c]);
c++;
}
printf("\n\n");
RBBIDebugPrintf("\n\n");
}

View file

@ -26,8 +26,6 @@
#include "uassert.h"
#include <stdio.h> // TODO - getrid of this.
U_NAMESPACE_BEGIN
@ -291,13 +289,13 @@ static const char *nodeTypeNames[] = {
};
void RBBINode::print() {
printf("%10p %12s %10p %10p %10p %4d %6d %d ",
RBBIDebugPrintf("%10p %12s %10p %10p %10p %4d %6d %d ",
(void *)this, nodeTypeNames[fType], (void *)fParent, (void *)fLeftChild, (void *)fRightChild,
fSerialNum, fFirstPos, fVal);
if (fType == varRef) {
printUnicodeString(fText);
}
putc('\n', stdout);
RBBIDebugPrintf("\n");
}
@ -305,10 +303,11 @@ void RBBINode::printUnicodeString(const UnicodeString &s, int minWidth)
{
int i;
for (i=0; i<s.length(); i++) {
putc(s.charAt(i), stdout);
RBBIDebugPrintf("%c", s.charAt(i));
// putc(s.charAt(i), stdout);
}
for (i=s.length(); i<minWidth; i++) {
putc(' ', stdout);
RBBIDebugPrintf(" ");
}
}
@ -320,8 +319,8 @@ void RBBINode::printUnicodeString(const UnicodeString &s, int minWidth)
//-------------------------------------------------------------------------
void RBBINode::printTree(UBool printHeading, UBool doVars) {
if (printHeading) {
printf( "-------------------------------------------------------------------\n"
" Address type Parent LeftChild RightChild serial position value\n"
RBBIDebugPrintf( "-------------------------------------------------------------------\n"
" Address type Parent LeftChild RightChild serial position value\n"
);
}
this->print();

View file

@ -20,6 +20,7 @@
#include "unicode/parsepos.h"
#include "unicode/parseerr.h"
#include "cmemory.h"
#include "cstring.h"
#include "rbbirb.h"
#include "rbbinode.h"
@ -29,9 +30,10 @@
#include "rbbitblb.h"
#include "rbbidata.h"
#include <stdio.h> // TODO - getrid of this.
#include <stdlib.h>
#include <string.h>
#ifdef RBBI_DEBUG
#include <stdio.h>
#include <stdarg.h>
#endif
U_NAMESPACE_BEGIN
@ -51,7 +53,10 @@ RBBIRuleBuilder::RBBIRuleBuilder(const UnicodeString &rules,
{
fStatus = &status;
fParseError = &parseErr;
fDebugEnv = getenv("U_RBBIDEBUG"); // TODO: make conditional on some compile time setting
fDebugEnv = NULL;
#ifdef RBBI_DEBUG
fDebugEnv = getenv("U_RBBIDEBUG");
#endif
fScanner = new RBBIRuleScanner(this);
fSetBuilder = new RBBISetBuilder(this);
@ -245,4 +250,22 @@ RBBIRuleBuilder::createRuleBasedBreakIterator( const UnicodeString &rules,
//----------------------------------------------------------------------------
//
// RBBIDebugPrintf Printf equivalent, for debugging output.
// Conditional compilation of the implementation lets us
// get rid of the stdio dependency in environments where it
// is unavailable.
//
//----------------------------------------------------------------------------
void RBBIDebugPrintf(const char *fmt, ...) {
#ifdef RBBI_DEBUG
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
#endif
}
U_NAMESPACE_END

View file

@ -20,8 +20,6 @@
#include "uvector.h"
#include "symtable.h" // For UnicodeSet parsing, is the interface that
// looks up references to $variables within a set.
// #include "rbbinode.h"
// #include "rbbitblb.h"
@ -213,6 +211,16 @@ struct RBBISetTableEl {
};
//----------------------------------------------------------------------------
//
// RBBIDebugPrintf Printf equivalent, for debugging output.
// Conditional compilation of the implementation lets us
// get rid of the stdio dependency in environments where it
// is unavailable.
//
//----------------------------------------------------------------------------
void RBBIDebugPrintf(const char *fmt, ...);
U_NAMESPACE_END
#endif

View file

@ -10,7 +10,7 @@
// of compiling the rules.
//
// The overall of the rules is managed by class RBBIRuleBuilder, which will
// create and use an instance of this class as part of the process.
// create and use an instance of this class as part of the process.
//
@ -22,6 +22,7 @@
#include "unicode/parseerr.h"
#include "upropset.h"
#include "cmemory.h"
#include "cstring.h"
#include "rbbirpt.h" // Contains state table for the rbbi rules parser.
// generated by a Perl script.
@ -29,10 +30,6 @@
#include "rbbinode.h"
#include "rbbiscan.h"
#include <stdio.h> // TODO - getrid of this, or make conditional on debugging
#include <stdlib.h>
#include <string.h>
#include "uassert.h"
@ -62,7 +59,7 @@ static const UChar gRuleSet_rule_char_pattern[] = {
0x5b, 0x5e, 0x5b, 0x5c, 0x70, 0x7b, 0x5a, 0x7d, 0x5c, 0x75, 0x30, 0x30, 0x32, 0x30,
// - \ u 0 0 7 f ] - [ \ p
0x2d, 0x5c, 0x75, 0x30, 0x30, 0x37, 0x66, 0x5d, 0x2d, 0x5b, 0x5c, 0x70,
// { L } ] - [ \ p { N } ] ]
// { L } ] - [ \ p { N } ] ]
0x7b, 0x4c, 0x7d, 0x5d, 0x2d, 0x5b, 0x5c, 0x70, 0x7b, 0x4e, 0x7d, 0x5d, 0x5d, 0};
static const UChar gRuleSet_name_char_pattern[] = {
@ -157,19 +154,6 @@ RBBIRuleScanner::~RBBIRuleScanner() {
}
#if 0
// TODO: does the rule builder class own this?
// Delete the linked lest of USet nodes and the corresponding UnicodeSets.
// (Deleting a node deletes its children, so deleting the head node of
// this list will take out the whole list.)
RBBINode *n, *nextN;
for (n=fSetsListHead; n!=NULL; n=nextN) {
nextN = n->fRightChild;
delete n;
}
fSetsListHead = NULL;
#endif
// Node Stack.
// Normally has one entry, which is the entire parse tree for the rules.
@ -298,14 +282,14 @@ UBool RBBIRuleScanner::doParseActions(EParseAction action)
fNodeStackPtr-=3;
break;
}
case doEndOfRule:
{
fixOpStack(RBBINode::precStart); // Terminate expression, leaves expression
if (U_FAILURE(*fRB->fStatus)) { // parse tree rooted in TOS node.
break;
}
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "rtree")) {printNodeStack("end of rule");}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "rtree")) {printNodeStack("end of rule");}
U_ASSERT(fNodeStackPtr == 1);
// If this rule includes a look-ahead '/', add a endMark node to the
@ -567,11 +551,11 @@ void RBBIRuleScanner::fixOpStack(RBBINode::OpPrecedence p) {
for (;;) {
n = fNodeStack[fNodeStackPtr-1]; // an operator node
if (n->fPrecedence == 0) {
fprintf(stderr, "RBBIRuleScanner::fixOpStack, bad operator node\n");
RBBIDebugPrintf("RBBIRuleScanner::fixOpStack, bad operator node\n");
error(U_BRK_INTERNAL_ERROR);
return;
}
if (n->fPrecedence < p || n->fPrecedence <= RBBINode::precLParen) {
// The most recent operand goes with the current operator,
// not with the previously stacked one.
@ -699,8 +683,8 @@ void RBBIRuleScanner::findSetFor(const UnicodeString &s, RBBINode *node, Unicode
//
// Assorted Unicode character constants.
// Numeric because there is no portable way to enter them as literals.
// (Think EBCDIC).
//
// (Think EBCDIC).
//
static const UChar chCR = 0x0d; // New lines, for terminating comments.
static const UChar chLF = 0x0a;
static const UChar chNEL = 0x85; // NEL newline variant
@ -883,13 +867,13 @@ void RBBIRuleScanner::parse() {
// the search will stop there, if not before.
//
tableEl = &gRuleParseStateTable[state];
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "scan")) {
printf("char, line, col = (\'%c\', %d, %d) state=%s ",
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) {
RBBIDebugPrintf("char, line, col = (\'%c\', %d, %d) state=%s ",
fC.fChar, fLineNum, fCharNum, RBBIRuleStateNames[state]);
}
for (;;) {
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "scan")) { printf(".");}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPrintf(".");}
if (tableEl->fCharClass < 127 && tableEl->fCharClass == fC.fChar) {
// Table row specified an individual character, not a set, and
// the input character matched it.
@ -925,7 +909,7 @@ void RBBIRuleScanner::parse() {
// No match on this row, advance to the next row for this state,
tableEl++;
}
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "scan")) { printf("\n");}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "scan")) { RBBIDebugPrintf("\n");}
//
// We've found the row of the state table that matches the current input
@ -942,7 +926,7 @@ void RBBIRuleScanner::parse() {
fStackPtr++;
if (fStackPtr >= kStackSize) {
error(U_BRK_INTERNAL_ERROR);
fprintf(stderr, "RBBIRuleScanner::parse() - state stack overflow.\n");
RBBIDebugPrintf("RBBIRuleScanner::parse() - state stack overflow.\n");
fStackPtr--;
}
fStack[fStackPtr] = tableEl->fPushState;
@ -961,7 +945,7 @@ void RBBIRuleScanner::parse() {
fStackPtr--;
if (fStackPtr < 0) {
error(U_BRK_INTERNAL_ERROR);
fprintf(stderr, "RBBIRuleScanner::parse() - state stack underflow.\n");
RBBIDebugPrintf("RBBIRuleScanner::parse() - state stack underflow.\n");
fStackPtr++;
}
}
@ -986,12 +970,12 @@ void RBBIRuleScanner::parse() {
// We now have a parse tree for the rule expressions
// and a list of all UnicodeSets that are referenced.
//
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "symbols")) {fSymbolTable->print();}
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "ptree"))
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "symbols")) {fSymbolTable->print();}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "ptree"))
{
printf("Completed Forward Rules Parse Tree...\n");
RBBIDebugPrintf("Completed Forward Rules Parse Tree...\n");
fRB->fForwardTree->printTree();
printf("\nCompleted Reverse Rules Parse Tree...\n");
RBBIDebugPrintf("\nCompleted Reverse Rules Parse Tree...\n");
fRB->fReverseTree->printTree();
}
@ -1005,7 +989,7 @@ void RBBIRuleScanner::parse() {
//---------------------------------------------------------------------------------
void RBBIRuleScanner::printNodeStack(const char *title) {
int i;
printf("%s. Dumping node stack...\n", title);
RBBIDebugPrintf("%s. Dumping node stack...\n", title);
for (i=fNodeStackPtr; i>0; i--) {fNodeStack[i]->printTree();};
}
@ -1022,7 +1006,7 @@ RBBINode *RBBIRuleScanner::pushNewNode(RBBINode::NodeType t) {
fNodeStackPtr++;
if (fNodeStackPtr >= kStackSize) {
error(U_BRK_INTERNAL_ERROR);
fprintf(stderr, "RBBIRuleScanner::pushNewNode - stack overflow.\n");
RBBIDebugPrintf("RBBIRuleScanner::pushNewNode - stack overflow.\n");
*fRB->fStatus = U_BRK_INTERNAL_ERROR;
return NULL;
}
@ -1068,7 +1052,7 @@ void RBBIRuleScanner::scanSet() {
if (U_FAILURE(localStatus)) {
// TODO: Get more accurate position of the error from UnicodeSet's return info.
// UnicodeSet appears to not be reporting correctly at this time.
printf("UnicodeSet parse postion.ErrorIndex = %d\n", pos.getIndex());
RBBIDebugPrintf("UnicodeSet parse postion.ErrorIndex = %d\n", pos.getIndex());
error(localStatus);
return;
}

View file

@ -33,7 +33,7 @@
#include "uvector.h"
#include "uassert.h"
#include "cmemory.h"
#include <stdio.h>
#include "cstring.h"
#include "rbbisetb.h"
#include "rbbinode.h"
@ -127,7 +127,7 @@ void RBBISetBuilder::build() {
RBBINode *usetNode;
RangeDescriptor *rlRange;
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "usets")) {printSets();}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "usets")) {printSets();}
//
// Initialize the process by creating a single range encompassing all characters
@ -194,7 +194,7 @@ void RBBISetBuilder::build() {
}
}
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "range")) { printRanges();}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "range")) { printRanges();}
//
// Group the above ranges, with each group consisting of one or more
@ -218,8 +218,8 @@ void RBBISetBuilder::build() {
}
}
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "rgroup")) {printRangeGroups();}
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "esets")) {printSets();}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "rgroup")) {printRangeGroups();}
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "esets")) {printSets();}
//
// Build the Trie table for mapping UChar32 values to the corresponding
@ -251,7 +251,7 @@ int32_t RBBISetBuilder::getTrieSize() {
getFoldedRBBIValue,
TRUE, // Reduce to 16 bits
fStatus);
// printf("Trie table size is %d\n", trieSize);
// RBBIDebugPrintf("Trie table size is %d\n", trieSize);
return fTrieSize;
}
@ -334,13 +334,13 @@ void RBBISetBuilder::printRanges() {
RangeDescriptor *rlRange;
int i;
printf("\n\n Nonoverlapping Ranges ...\n");
RBBIDebugPrintf("\n\n Nonoverlapping Ranges ...\n");
for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
printf("%2i %4x-%4x ", rlRange->fNum, rlRange->fStartChar, rlRange->fEndChar);
RBBIDebugPrintf("%2i %4x-%4x ", rlRange->fNum, rlRange->fStartChar, rlRange->fEndChar);
for (i=0; i<rlRange->fIncludesSets->size(); i++) {
RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i);
UnicodeString setName = "anon"; // TODO: no string literals.
UnicodeString setName = "anon";
RBBINode *setRef = usetNode->fParent;
if (setRef != NULL) {
RBBINode *varRef = setRef->fParent;
@ -348,9 +348,9 @@ void RBBISetBuilder::printRanges() {
setName = varRef->fText;
}
}
RBBINode::printUnicodeString(setName); printf(" ");
RBBINode::printUnicodeString(setName); RBBIDebugPrintf(" ");
}
printf("\n");
RBBIDebugPrintf("\n");
}
}
@ -367,14 +367,14 @@ void RBBISetBuilder::printRangeGroups() {
int i;
int lastPrintedGroupNum = 0;
printf("\nRanges grouped by Unicode Set Membership...\n");
RBBIDebugPrintf("\nRanges grouped by Unicode Set Membership...\n");
for (rlRange = fRangeList; rlRange!=0; rlRange=rlRange->fNext) {
int groupNum = rlRange->fNum & 0xbfff;
if (groupNum > lastPrintedGroupNum) {
lastPrintedGroupNum = groupNum;
printf("%2i ", groupNum);
RBBIDebugPrintf("%2i ", groupNum);
if (rlRange->fNum & 0x4000) { printf(" <DICT> ");};
if (rlRange->fNum & 0x4000) { RBBIDebugPrintf(" <DICT> ");};
for (i=0; i<rlRange->fIncludesSets->size(); i++) {
RBBINode *usetNode = (RBBINode *)rlRange->fIncludesSets->elementAt(i);
@ -386,22 +386,22 @@ void RBBISetBuilder::printRangeGroups() {
setName = varRef->fText;
}
}
RBBINode::printUnicodeString(setName); printf(" ");
RBBINode::printUnicodeString(setName); RBBIDebugPrintf(" ");
}
i = 0;
for (tRange = rlRange; tRange != 0; tRange = tRange->fNext) {
if (tRange->fNum == rlRange->fNum) {
if (i++ % 5 == 0) {
printf("\n ");
RBBIDebugPrintf("\n ");
}
printf(" %05x-%05x", tRange->fStartChar, tRange->fEndChar);
RBBIDebugPrintf(" %05x-%05x", tRange->fStartChar, tRange->fEndChar);
}
}
printf("\n");
RBBIDebugPrintf("\n");
}
}
printf("\n");
RBBIDebugPrintf("\n");
}
@ -417,7 +417,7 @@ void RBBISetBuilder::printSets() {
int i;
UnicodeSet inputSet;
printf("\n\nUnicode Sets List\n------------------\n");
RBBIDebugPrintf("\n\nUnicode Sets List\n------------------\n");
i = 0;
for (usetNode=fRB->fSetsListHead; usetNode!=NULL; usetNode=usetNode->fRightChild) {
RBBINode *setRef;
@ -425,7 +425,7 @@ void RBBISetBuilder::printSets() {
UnicodeString setName;
i++;
printf("%3d ", i);
RBBIDebugPrintf("%3d ", i);
setName = "anonymous";
setRef = usetNode->fParent;
if (setRef != NULL) {
@ -435,14 +435,14 @@ void RBBISetBuilder::printSets() {
}
}
RBBINode::printUnicodeString(setName);
printf(" ");
RBBIDebugPrintf(" ");
RBBINode::printUnicodeString(usetNode->fText);
printf("\n");
RBBIDebugPrintf("\n");
if (usetNode->fLeftChild != NULL) {
usetNode->fLeftChild->printTree();
}
}
printf("\n");
RBBIDebugPrintf("\n");
}
@ -468,7 +468,7 @@ RangeDescriptor::RangeDescriptor(const RangeDescriptor &other, UErrorCode &statu
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
for (i=0; i<other.fIncludesSets->size(); i++) {
this->fIncludesSets->addElement(other.fIncludesSets->elementAt(i), status);
}
@ -491,7 +491,7 @@ RangeDescriptor::RangeDescriptor(UErrorCode &status) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
}
@ -518,7 +518,7 @@ void RangeDescriptor::split(UChar32 where, UErrorCode &status) {
status = U_MEMORY_ALLOCATION_ERROR;
return;
}
// RangeDescriptor copy constructor copies all fields.
// Only need to update those that are different after the split.
nr->fStartChar = where;

View file

@ -95,7 +95,7 @@ public:
RBBISetBuilder(RBBIRuleBuilder *rb);
~RBBISetBuilder();
void build(); // TODO: needs an out parameter for the TRIE.
void build();
void addValToSets(UVector *sets, uint32_t val);
int32_t getNumCharCategories(); // CharCategories are the same as input symbol set to the
// runtime state machine, which are the same as

View file

@ -18,8 +18,6 @@
#include "rbbirb.h"
#include "rbbinode.h"
#include <stdio.h> // TODO - getrid of this.
U_NAMESPACE_BEGIN
@ -232,7 +230,7 @@ RBBISymbolTableEntry::~RBBISymbolTableEntry() {
// RBBISymbolTable::print Debugging function, dump out the symbol table contents.
//
void RBBISymbolTable::print() const {
printf("Variable Definitions\n"
RBBIDebugPrintf("Variable Definitions\n"
"Name Node Val String Val\n"
"----------------------------------------------------------------------\n");
@ -246,12 +244,12 @@ void RBBISymbolTable::print() const {
RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer;
RBBINode::printUnicodeString(s->key, 15);
printf(" %8p ", (void *)s->val);
RBBIDebugPrintf(" %8p ", (void *)s->val);
RBBINode::printUnicodeString(s->val->fLeftChild->fText);
printf("\n");
RBBIDebugPrintf("\n");
}
printf("\nParsed Variable Definitions\n");
RBBIDebugPrintf("\nParsed Variable Definitions\n");
pos = -1;
for (;;) {
e = uhash_nextElement(fHashTable, &pos);
@ -261,7 +259,7 @@ void RBBISymbolTable::print() const {
RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer;
RBBINode::printUnicodeString(s->key);
s->val->fLeftChild->printTree();
printf("\n");
RBBIDebugPrintf("\n");
}
}

View file

@ -15,9 +15,7 @@
#include "rbbirb.h"
#include "rbbisetb.h"
#include "rbbidata.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "cstring.h"
#include "uassert.h"
U_NAMESPACE_BEGIN
@ -65,8 +63,8 @@ void RBBITableBuilder::build() {
// parse tree for the substition expression.
//
fTree->flattenVariables();
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "ftree")) {
printf("Parse tree after flattening variable references.\n");
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "ftree")) {
RBBIDebugPrintf("Parse tree after flattening variable references.\n");
fTree->printTree(TRUE);
}
@ -87,8 +85,8 @@ void RBBITableBuilder::build() {
// expression.
//
fTree->flattenSets();
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "stree")) {
printf("Parse tree after flattening Unicode Set references.\n");
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "stree")) {
RBBIDebugPrintf("Parse tree after flattening Unicode Set references.\n");
fTree->printTree(TRUE);
}
@ -104,8 +102,8 @@ void RBBITableBuilder::build() {
calcFirstPos(fTree);
calcLastPos(fTree);
calcFollowPos(fTree);
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "pos")) {
printf("\n\n");
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "pos")) {
RBBIDebugPrintf("\n\n");
printPosSets(fTree);
}
@ -116,7 +114,7 @@ void RBBITableBuilder::build() {
flagAcceptingStates();
flagLookAheadStates();
flagTaggedStates();
if (fRB->fDebugEnv && strstr(fRB->fDebugEnv, "states")) {printStates();};
if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "states")) {printStates();};
}
@ -401,8 +399,10 @@ void RBBITableBuilder::buildStateTable() {
//-----------------------------------------------------------------------------
//
// flagAcceptingStates Identify accepting states.
// TODO: implementation for tagging of rule match values
// will probably end up here.
// First get a list of all of the end marker nodes.
// Then, for each state s,
// if s contains one of the end marker nodes in its list of tree positions then
// s is an accepting state.
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::flagAcceptingStates() {
@ -439,7 +439,7 @@ void RBBITableBuilder::flagAcceptingStates() {
//-----------------------------------------------------------------------------
//
// flagLookAheadStates
// flagLookAheadStates Very similar to flagAcceptingStates, above.
//
//-----------------------------------------------------------------------------
void RBBITableBuilder::flagLookAheadStates() {
@ -481,10 +481,10 @@ void RBBITableBuilder::flagTaggedStates() {
for (n=0; n<fDStates->size(); n++) { // For each state s (row in the state table)
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
if (sd->fPositions->indexOf(tagNode) >= 0) { // if s include the tag node t
if (sd->fPositions->indexOf(tagNode) >= 0) { // if s include the tag node t
if (sd->fTagVal < tagNode->fVal) {
// If more than one rule tag applies to this state, the larger
// tag takes precedence.
// tag takes precedence.
sd->fTagVal = tagNode->fVal;
}
}
@ -571,15 +571,15 @@ void RBBITableBuilder::printPosSets(RBBINode *n) {
return;
}
n->print();
printf(" Nullable: %s\n", n->fNullable?"TRUE":"FALSE");
RBBIDebugPrintf(" Nullable: %s\n", n->fNullable?"TRUE":"FALSE");
printf(" firstpos: ");
RBBIDebugPrintf(" firstpos: ");
printSet(n->fFirstPosSet);
printf(" lastpos: ");
RBBIDebugPrintf(" lastpos: ");
printSet(n->fLastPosSet);
printf(" followpos: ");
RBBIDebugPrintf(" followpos: ");
printSet(n->fFollowPos);
printPosSets(n->fLeftChild);
@ -670,9 +670,9 @@ void RBBITableBuilder::printSet(UVector *s) {
int32_t i;
for (i=0; i<s->size(); i++) {
void *v = s->elementAt(i);
printf("%10p", v);
RBBIDebugPrintf("%10p", v);
}
printf("\n");
RBBIDebugPrintf("\n");
}
@ -686,24 +686,24 @@ void RBBITableBuilder::printStates() {
int c; // input "character"
int n; // state number
printf("state | i n p u t s y m b o l s \n");
printf(" | Acc LA Tag");
for (c=0; c<fRB->fSetBuilder->getNumCharCategories(); c++) {printf(" %2d", c);};
printf("\n");
printf(" |---------------");
for (c=0; c<fRB->fSetBuilder->getNumCharCategories(); c++) {printf("---");};
printf("\n");
RBBIDebugPrintf("state | i n p u t s y m b o l s \n");
RBBIDebugPrintf(" | Acc LA Tag");
for (c=0; c<fRB->fSetBuilder->getNumCharCategories(); c++) {RBBIDebugPrintf(" %2d", c);};
RBBIDebugPrintf("\n");
RBBIDebugPrintf(" |---------------");
for (c=0; c<fRB->fSetBuilder->getNumCharCategories(); c++) {RBBIDebugPrintf("---");};
RBBIDebugPrintf("\n");
for (n=0; n<fDStates->size(); n++) {
RBBIStateDescriptor *sd = (RBBIStateDescriptor *)fDStates->elementAt(n);
printf(" %3d | " , n);
printf("%3d %3d %5d ", sd->fAccepting, sd->fLookAhead, sd->fTagVal);
RBBIDebugPrintf(" %3d | " , n);
RBBIDebugPrintf("%3d %3d %5d ", sd->fAccepting, sd->fLookAhead, sd->fTagVal);
for (c=0; c<fRB->fSetBuilder->getNumCharCategories(); c++) {
printf(" %2d", sd->fDtran->elementAti(c));
RBBIDebugPrintf(" %2d", sd->fDtran->elementAti(c));
}
printf("\n");
RBBIDebugPrintf("\n");
}
printf("\n\n");
RBBIDebugPrintf("\n\n");
}
@ -726,12 +726,10 @@ RBBIStateDescriptor::RBBIStateDescriptor(int lastInputSymbol, UErrorCode *fStatu
fTagVal = 0;
fPositions = NULL;
fDtran = NULL;
/* test for buffer overflows */
if (U_FAILURE(*fStatus)) {
return;
}
fDtran = new UVector(lastInputSymbol+1, *fStatus);
/* test for NULL */
if (fDtran == NULL) {
*fStatus = U_MEMORY_ALLOCATION_ERROR;
return;

View file

@ -44,8 +44,6 @@ public:
// Sufficient memory must exist at
// the specified location.
// TODO: add getter function(s) for the built table.
/**
* ICU "poor man's RTTI", returns a UClassID for the actual class.
*

View file

@ -412,11 +412,6 @@ public:
virtual const uint8_t *getBinaryRules(uint32_t &length);
#ifdef RBBI_DEBUG
void debugDumpTables() const;
#endif
protected:
//=======================================================================
// implementation