ICU-3437 rbbi debug functions, better conditional compilation.

X-SVN-Rev: 14006
This commit is contained in:
Andy Heninger 2003-12-04 22:44:05 +00:00
parent ea6b4709a1
commit a57f032f42
11 changed files with 81 additions and 53 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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; i<s.length(); i++) {
@ -321,20 +319,18 @@ void RBBINode::printUnicodeString(const UnicodeString &s, int minWidth)
// print. Print out the tree of nodes rooted at "this"
//
//-------------------------------------------------------------------------
#ifndef RBBI_DEBUG
void RBBINode::printTree(UBool, UBool) {}
#else
void RBBINode::printTree(UBool printHeading, UBool doVars) {
#ifdef RBBI_DEBUG
void RBBINode::printTree(UBool printHeading) {
if (printHeading) {
RBBIDebugPrintf( "-------------------------------------------------------------------\n"
" Address type Parent LeftChild RightChild serial position value\n"
);
}
this->print();
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);
}

View File

@ -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

View File

@ -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

View File

@ -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);}
}

View File

@ -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

View File

@ -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();

View File

@ -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

View File

@ -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

View File

@ -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;