]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/common/rbbinode.cpp
ICU-57132.0.1.tar.gz
[apple/icu.git] / icuSources / common / rbbinode.cpp
index f3a0a67911eec18f7fe69bf1e6f284136030c329..1468be9c10ceef4f60200dbd22d1da948a1ac1c1 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ***************************************************************************
-*   Copyright (C) 2002-2003 International Business Machines Corporation   *
+*   Copyright (C) 2002-2016 International Business Machines Corporation   *
 *   and others. All rights reserved.                                      *
 ***************************************************************************
 */
@@ -33,8 +33,9 @@
 
 U_NAMESPACE_BEGIN
 
-int  RBBINode::gLastSerial = 0;
-
+#ifdef RBBI_DEBUG
+static int  gLastSerial = 0;
+#endif
 
 
 //-------------------------------------------------------------------------
@@ -43,7 +44,9 @@ int  RBBINode::gLastSerial = 0;
 //
 //-------------------------------------------------------------------------
 RBBINode::RBBINode(NodeType t) : UMemory() {
+#ifdef RBBI_DEBUG
     fSerialNum    = ++gLastSerial;
+#endif
     fType         = t;
     fParent       = NULL;
     fLeftChild    = NULL;
@@ -53,8 +56,10 @@ RBBINode::RBBINode(NodeType t) : UMemory() {
     fLastPos      = 0;
     fNullable     = FALSE;
     fLookAheadEnd = FALSE;
+    fRuleRoot     = FALSE;
+    fChainIn      = FALSE;
     fVal          = 0;
-       fPrecedence   = precZero;
+    fPrecedence   = precZero;
 
     UErrorCode     status = U_ZERO_ERROR;
     fFirstPosSet  = new UVector(status);  // TODO - get a real status from somewhere
@@ -69,7 +74,9 @@ RBBINode::RBBINode(NodeType t) : UMemory() {
 
 
 RBBINode::RBBINode(const RBBINode &other) : UMemory(other) {
+#ifdef RBBI_DEBUG
     fSerialNum   = ++gLastSerial;
+#endif
     fType        = other.fType;
     fParent      = NULL;
     fLeftChild   = NULL;
@@ -81,6 +88,8 @@ RBBINode::RBBINode(const RBBINode &other) : UMemory(other) {
     fLastPos     = other.fLastPos;
     fNullable    = other.fNullable;
     fVal         = other.fVal;
+    fRuleRoot    = FALSE;
+    fChainIn     = other.fChainIn;
     UErrorCode     status = U_ZERO_ERROR;
     fFirstPosSet = new UVector(status);   // TODO - get a real status from somewhere
     fLastPosSet  = new UVector(status);
@@ -144,15 +153,20 @@ RBBINode *RBBINode::cloneTree() {
         n = this;
     } else {
         n = new RBBINode(*this);
-        if (fLeftChild != NULL) {
-            n->fLeftChild          = fLeftChild->cloneTree();
-            n->fLeftChild->fParent = n;
-        }
-        if (fRightChild != NULL) {
-            n->fRightChild          = fRightChild->cloneTree();
-            n->fRightChild->fParent = n;
+        // Check for null pointer.
+        if (n != NULL) {
+            if (fLeftChild != NULL) {
+                n->fLeftChild          = fLeftChild->cloneTree();
+                n->fLeftChild->fParent = n;
+            }
+            if (fRightChild != NULL) {
+                n->fRightChild          = fRightChild->cloneTree();
+                n->fRightChild->fParent = n;
+            }
         }
     }
+    n->fRuleRoot = this->fRuleRoot;
+    n->fChainIn  = this->fChainIn;
     return n;
 }
 
@@ -263,8 +277,14 @@ void   RBBINode::findNodes(UVector *dest, RBBINode::NodeType kind, UErrorCode &s
 //    print.         Print out a single node, for debugging.
 //
 //-------------------------------------------------------------------------
-void RBBINode::print() {
 #ifdef RBBI_DEBUG
+
+static int32_t serial(const RBBINode *node) {
+    return (node == NULL? -1 : node->fSerialNum);
+}
+
+
+void RBBINode::printNode() {
     static const char * const nodeTypeNames[] = {
                 "setRef",
                 "uset",
@@ -284,21 +304,24 @@ void RBBINode::print() {
                 "opLParen"
     };
 
-    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);
+    if (this==NULL) {
+        RBBIDebugPrintf("%10p", (void *)this);
+    } else {
+        RBBIDebugPrintf("%10p %5d %12s %c%c  %5d       %5d     %5d       %6d     %d ",
+            (void *)this, fSerialNum, nodeTypeNames[fType],   fRuleRoot?'R':' ',  fChainIn?'C':' ',
+             serial(fLeftChild), serial(fRightChild), serial(fParent),
+            fFirstPos, fVal);
+        if (fType == varRef) {
+            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++) {
@@ -318,24 +341,26 @@ void RBBINode::printUnicodeString(const UnicodeString &s, int minWidth)
 //
 //-------------------------------------------------------------------------
 #ifdef RBBI_DEBUG
-void RBBINode::printTree(UBool, UBool) {}
-#else
-void RBBINode::printTree(UBool printHeading, UBool doVars) {
+void RBBINode::printNodeHeader() {
+    RBBIDebugPrintf(" Address   serial        type     LeftChild  RightChild   Parent   position value\n");
+}
+    
+void RBBINode::printTree(UBool printHeading) {
     if (printHeading) {
-        RBBIDebugPrintf( "-------------------------------------------------------------------\n"
-                         "    Address       type         Parent   LeftChild  RightChild    serial  position value\n"
-              );
+        printNodeHeader();
     }
-    this->print();
-    // Only dump the definition under a variable reference if asked to.
-    // Unconditinally dump children of all other node types.
-    if (fType != varRef || doVars) {
-        if (fLeftChild != NULL) {
-            fLeftChild->printTree(FALSE);
-        }
-
-        if (fRightChild != NULL) {
-            fRightChild->printTree(FALSE);
+    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) {
+            if (fLeftChild != NULL) {
+                fLeftChild->printTree(FALSE);
+            }
+            
+            if (fRightChild != NULL) {
+                fRightChild->printTree(FALSE);
+            }
         }
     }
 }