From a57f032f42cb2580f491b16396c73652c7077a32 Mon Sep 17 00:00:00 2001 From: Andy Heninger Date: Thu, 4 Dec 2003 22:44:05 +0000 Subject: [PATCH] ICU-3437 rbbi debug functions, better conditional compilation. X-SVN-Rev: 14006 --- icu4c/source/common/rbbidata.cpp | 7 ++----- icu4c/source/common/rbbidata.h | 5 +++++ icu4c/source/common/rbbinode.cpp | 20 ++++++++------------ icu4c/source/common/rbbinode.h | 19 ++++++++++++++++--- icu4c/source/common/rbbirb.h | 9 ++++++++- icu4c/source/common/rbbiscan.cpp | 12 ++++++------ icu4c/source/common/rbbisetb.cpp | 21 +++++++++++---------- icu4c/source/common/rbbisetb.h | 8 +++++++- icu4c/source/common/rbbistbl.cpp | 13 +++++++------ icu4c/source/common/rbbitblb.cpp | 13 +++++-------- icu4c/source/common/rbbitblb.h | 7 ++++++- 11 files changed, 81 insertions(+), 53 deletions(-) diff --git a/icu4c/source/common/rbbidata.cpp b/icu4c/source/common/rbbidata.cpp index c0bb041b57..de7d4303f6 100644 --- a/icu4c/source/common/rbbidata.cpp +++ b/icu4c/source/common/rbbidata.cpp @@ -224,14 +224,11 @@ void RBBIDataWrapper::printTable(const char *heading, const RBBIStateTable *tab } RBBIDebugPrintf("\n"); } -#else -/* Use an empty function for non-debug builds to ignore warnings. */ -void RBBIDataWrapper::printTable(const char *, const RBBIStateTable *) {} #endif -void RBBIDataWrapper::printData() { #ifdef RBBI_DEBUG +void RBBIDataWrapper::printData() { RBBIDebugPrintf("RBBI Data at %p\n", (void *)fHeader); RBBIDebugPrintf(" Version = %d\n", fHeader->fVersion); RBBIDebugPrintf(" total length of data = %d\n", fHeader->fLength); @@ -247,8 +244,8 @@ void RBBIDataWrapper::printData() { RBBIDebugPrintf("%c", fRuleSource[c]); } RBBIDebugPrintf("\n\n"); -#endif } +#endif U_NAMESPACE_END diff --git a/icu4c/source/common/rbbidata.h b/icu4c/source/common/rbbidata.h index 68fbc283a4..72622f7981 100644 --- a/icu4c/source/common/rbbidata.h +++ b/icu4c/source/common/rbbidata.h @@ -137,8 +137,13 @@ public: UBool operator ==(const RBBIDataWrapper &other) const; int32_t hashCode(); const UnicodeString &getRuleSourceString(); +#ifdef RBBI_DEBUG void printData(); void printTable(const char *heading, const RBBIStateTable *table); +#else + #define printData() + #define printTable(heading, table) +#endif /* */ /* Pointers to items within the data */ diff --git a/icu4c/source/common/rbbinode.cpp b/icu4c/source/common/rbbinode.cpp index 747c0bf3c9..1227e19585 100644 --- a/icu4c/source/common/rbbinode.cpp +++ b/icu4c/source/common/rbbinode.cpp @@ -263,8 +263,8 @@ void RBBINode::findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &s // print. Print out a single node, for debugging. // //------------------------------------------------------------------------- -void RBBINode::print() { #ifdef RBBI_DEBUG +void RBBINode::printNode() { static const char * const nodeTypeNames[] = { "setRef", "uset", @@ -291,18 +291,16 @@ void RBBINode::print() { (void *)this, nodeTypeNames[fType], (void *)fParent, (void *)fLeftChild, (void *)fRightChild, fSerialNum, fFirstPos, fVal); if (fType == varRef) { - printUnicodeString(fText); + RBBI_DEBUG_printUnicodeString(fText); } } RBBIDebugPrintf("\n"); -#endif } +#endif #ifdef RBBI_DEBUG -void RBBINode::printUnicodeString(const UnicodeString &, int) {} -#else -void RBBINode::printUnicodeString(const UnicodeString &s, int minWidth) +U_CFUNC void RBBI_DEBUG_printUnicodeString(const UnicodeString &s, int minWidth) { int i; for (i=0; iprint(); + this->printNode(); if (this != NULL) { // Only dump the definition under a variable reference if asked to. // Unconditinally dump children of all other node types. - if (fType != varRef || doVars) { + if (fType != varRef) { if (fLeftChild != NULL) { fLeftChild->printTree(FALSE); } diff --git a/icu4c/source/common/rbbinode.h b/icu4c/source/common/rbbinode.h index 6d226f7d9f..ce72405614 100644 --- a/icu4c/source/common/rbbinode.h +++ b/icu4c/source/common/rbbinode.h @@ -93,9 +93,16 @@ class RBBINode : public UMemory { void flattenSets(); void findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &status); - void print(); - void printTree(UBool withHeading=TRUE, UBool doVars=FALSE); - static void printUnicodeString(const UnicodeString &s, int minWidth=0); +#ifdef RBBI_DEBUG + void printNode(); + void printTree(UBool withHeading); +#else + // Do-nothing inline functions for non-debug builds. Can't make empty defines for member + // functions - they won't compile at the call sites. + int fakeField; + #define printNode() fakeField=0; + #define printTree(withHeading) fakeField=0; +#endif private: RBBINode &operator = (const RBBINode &other); // No defs. @@ -104,6 +111,12 @@ class RBBINode : public UMemory { int fSerialNum; // Debugging aids. static int gLastSerial; }; + +#ifdef RBBI_DEBUG +U_CFUNC void +RBBI_DEBUG_printUnicodeString(const UnicodeString &s, int minWidth=0); +#endif + U_NAMESPACE_END #endif diff --git a/icu4c/source/common/rbbirb.h b/icu4c/source/common/rbbirb.h index aa7c0ec671..b2e8b22c4c 100644 --- a/icu4c/source/common/rbbirb.h +++ b/icu4c/source/common/rbbirb.h @@ -79,7 +79,14 @@ public: virtual RBBINode *lookupNode(const UnicodeString &key) const; virtual void addEntry (const UnicodeString &key, RBBINode *val, UErrorCode &err); - virtual void print() const; +#ifdef RBBI_DEBUG + virtual void rbbiSymtablePrint() const; +#else + // A do-nothing inline function for non-debug builds. Member funcs can't be empty + // or the call sites won't compile. + int fFakeField; + #define rbbiSymtablePrint() fFakeField=0; +#endif private: RBBISymbolTable(const RBBISymbolTable &other); // forbid copying of this class diff --git a/icu4c/source/common/rbbiscan.cpp b/icu4c/source/common/rbbiscan.cpp index 6e8251b2cd..d81201182b 100644 --- a/icu4c/source/common/rbbiscan.cpp +++ b/icu4c/source/common/rbbiscan.cpp @@ -1030,17 +1030,17 @@ 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 && uprv_strstr(fRB->fDebugEnv, "symbols")) {fSymbolTable->print();} + if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "symbols")) {fSymbolTable->rbbiSymtablePrint();} if (fRB->fDebugEnv && uprv_strstr(fRB->fDebugEnv, "ptree")) { RBBIDebugPrintf("Completed Forward Rules Parse Tree...\n"); - fRB->fForwardTree->printTree(); + fRB->fForwardTree->printTree(TRUE); RBBIDebugPrintf("\nCompleted Reverse Rules Parse Tree...\n"); - fRB->fReverseTree->printTree(); + fRB->fReverseTree->printTree(TRUE); RBBIDebugPrintf("\nCompleted Safe Point Forward Rules Parse Tree...\n"); - fRB->fSafeFwdTree->printTree(); + fRB->fSafeFwdTree->printTree(TRUE); RBBIDebugPrintf("\nCompleted Safe Point Reverse Rules Parse Tree...\n"); - fRB->fSafeRevTree->printTree(); + fRB->fSafeRevTree->printTree(TRUE); } } @@ -1054,7 +1054,7 @@ void RBBIRuleScanner::parse() { void RBBIRuleScanner::printNodeStack(const char *title) { int i; RBBIDebugPrintf("%s. Dumping node stack...\n", title); - for (i=fNodeStackPtr; i>0; i--) {fNodeStack[i]->printTree();} + for (i=fNodeStackPtr; i>0; i--) {fNodeStack[i]->printTree(TRUE);} } diff --git a/icu4c/source/common/rbbisetb.cpp b/icu4c/source/common/rbbisetb.cpp index 089f91a3c4..e5e3226c48 100644 --- a/icu4c/source/common/rbbisetb.cpp +++ b/icu4c/source/common/rbbisetb.cpp @@ -371,8 +371,8 @@ UChar32 RBBISetBuilder::getFirstChar(int32_t category) { // dump out all of the range definitions. // //------------------------------------------------------------------------ -void RBBISetBuilder::printRanges() { #ifdef RBBI_DEBUG +void RBBISetBuilder::printRanges() { RangeDescriptor *rlRange; int i; @@ -390,12 +390,12 @@ void RBBISetBuilder::printRanges() { setName = varRef->fText; } } - RBBINode::printUnicodeString(setName); RBBIDebugPrintf(" "); + RBBI_DEBUG_printUnicodeString(setName); RBBIDebugPrintf(" "); } RBBIDebugPrintf("\n"); } -#endif } +#endif //------------------------------------------------------------------------ @@ -404,6 +404,7 @@ void RBBISetBuilder::printRanges() { // dump out all of the range groups. // //------------------------------------------------------------------------ +#ifdef RBBI_DEBUG void RBBISetBuilder::printRangeGroups() { RangeDescriptor *rlRange; RangeDescriptor *tRange; @@ -429,7 +430,7 @@ void RBBISetBuilder::printRangeGroups() { setName = varRef->fText; } } - RBBINode::printUnicodeString(setName); RBBIDebugPrintf(" "); + RBBI_DEBUG_printUnicodeString(setName); RBBIDebugPrintf(" "); } i = 0; @@ -446,7 +447,7 @@ void RBBISetBuilder::printRangeGroups() { } RBBIDebugPrintf("\n"); } - +#endif //------------------------------------------------------------------------ @@ -455,8 +456,8 @@ void RBBISetBuilder::printRangeGroups() { // dump out all of the set definitions. // //------------------------------------------------------------------------ -void RBBISetBuilder::printSets() { #ifdef RBBI_DEBUG +void RBBISetBuilder::printSets() { int i; RBBIDebugPrintf("\n\nUnicode Sets List\n------------------\n"); @@ -480,17 +481,17 @@ void RBBISetBuilder::printSets() { setName = varRef->fText; } } - RBBINode::printUnicodeString(setName); + RBBI_DEBUG_printUnicodeString(setName); RBBIDebugPrintf(" "); - RBBINode::printUnicodeString(usetNode->fText); + RBBI_DEBUG_printUnicodeString(usetNode->fText); RBBIDebugPrintf("\n"); if (usetNode->fLeftChild != NULL) { - usetNode->fLeftChild->printTree(); + usetNode->fLeftChild->printTree(TRUE); } } RBBIDebugPrintf("\n"); -#endif } +#endif diff --git a/icu4c/source/common/rbbisetb.h b/icu4c/source/common/rbbisetb.h index 940e9aca1c..41789a29c1 100644 --- a/icu4c/source/common/rbbisetb.h +++ b/icu4c/source/common/rbbisetb.h @@ -85,10 +85,16 @@ public: // columns in the DFA state table int32_t getTrieSize(); // Size in bytes of the serialized Trie. void serializeTrie(uint8_t *where); // write out the serialized Trie. + UChar32 getFirstChar(int32_t val); +#ifdef RBBI_DEBUG void printSets(); void printRanges(); void printRangeGroups(); - UChar32 getFirstChar(int32_t val); +#else + #define printSets() + #define printRanges() + #define printRangeGroups() +#endif private: void numberSets(); diff --git a/icu4c/source/common/rbbistbl.cpp b/icu4c/source/common/rbbistbl.cpp index 26261b1380..ae9776f992 100644 --- a/icu4c/source/common/rbbistbl.cpp +++ b/icu4c/source/common/rbbistbl.cpp @@ -224,7 +224,8 @@ RBBISymbolTableEntry::~RBBISymbolTableEntry() { // // RBBISymbolTable::print Debugging function, dump out the symbol table contents. // -void RBBISymbolTable::print() const { +#ifdef RBBI_DEBUG +void RBBISymbolTable::rbbiSymtablePrint() const { RBBIDebugPrintf("Variable Definitions\n" "Name Node Val String Val\n" "----------------------------------------------------------------------\n"); @@ -238,9 +239,9 @@ void RBBISymbolTable::print() const { } RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer; - RBBINode::printUnicodeString(s->key, 15); + RBBI_DEBUG_printUnicodeString(s->key, 15); RBBIDebugPrintf(" %8p ", (void *)s->val); - RBBINode::printUnicodeString(s->val->fLeftChild->fText); + RBBI_DEBUG_printUnicodeString(s->val->fLeftChild->fText); RBBIDebugPrintf("\n"); } @@ -252,12 +253,12 @@ void RBBISymbolTable::print() const { break; } RBBISymbolTableEntry *s = (RBBISymbolTableEntry *)e->value.pointer; - RBBINode::printUnicodeString(s->key); - s->val->fLeftChild->printTree(); + RBBI_DEBUG_printUnicodeString(s->key); + s->val->fLeftChild->printTree(TRUE); RBBIDebugPrintf("\n"); } } - +#endif diff --git a/icu4c/source/common/rbbitblb.cpp b/icu4c/source/common/rbbitblb.cpp index d1feaeaae3..d423df7e12 100644 --- a/icu4c/source/common/rbbitblb.cpp +++ b/icu4c/source/common/rbbitblb.cpp @@ -725,12 +725,12 @@ UBool RBBITableBuilder::setEquals(UVector *a, UVector *b) { // for each node in the tree. // //----------------------------------------------------------------------------- -void RBBITableBuilder::printPosSets(RBBINode *n) { #ifdef RBBI_DEBUG +void RBBITableBuilder::printPosSets(RBBINode *n) { if (n==NULL) { return; } - n->print(); + n->printNode(); RBBIDebugPrintf(" Nullable: %s\n", n->fNullable?"TRUE":"FALSE"); RBBIDebugPrintf(" firstpos: "); @@ -744,8 +744,8 @@ void RBBITableBuilder::printPosSets(RBBINode *n) { printPosSets(n->fLeftChild); printPosSets(n->fRightChild); -#endif } +#endif @@ -841,9 +841,6 @@ void RBBITableBuilder::printSet(UVector *s) { } RBBIDebugPrintf("\n"); } -#else -/* Use an empty function for non-debug builds to ignore warnings. */ -void RBBITableBuilder::printSet(UVector *) {} #endif @@ -852,8 +849,8 @@ void RBBITableBuilder::printSet(UVector *) {} // printStates Debug Function. Dump the fully constructed state transition table. // //----------------------------------------------------------------------------- -void RBBITableBuilder::printStates() { #ifdef RBBI_DEBUG +void RBBITableBuilder::printStates() { int c; // input "character" int n; // state number @@ -875,8 +872,8 @@ void RBBITableBuilder::printStates() { RBBIDebugPrintf("\n"); } RBBIDebugPrintf("\n\n"); -#endif } +#endif diff --git a/icu4c/source/common/rbbitblb.h b/icu4c/source/common/rbbitblb.h index effae884fc..401e050541 100644 --- a/icu4c/source/common/rbbitblb.h +++ b/icu4c/source/common/rbbitblb.h @@ -62,10 +62,15 @@ private: void setAdd(UVector *dest, UVector *source); UBool setEquals(UVector *a, UVector *b); +#ifdef RBBI_DEBUG void printSet(UVector *s); void printPosSets(RBBINode *n = NULL); void printStates(); - +#else + #define printSet(s) + #define printPosSets + #define printStates() +#endif private: RBBIRuleBuilder *fRB;