/** Transform ^(nil x) to x */ static pANTLR3_BASE_TREE rulePostProcessing (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE root) { pANTLR3_BASE_TREE saveRoot; // Keep track of the root we are given. If it is a nilNode, then we // can reuse it rather than orphaning it! // saveRoot = root; if (root != NULL && root->isNilNode(root)) { if (root->getChildCount(root) == 0) { root = NULL; } else if (root->getChildCount(root) == 1) { root = (pANTLR3_BASE_TREE)root->getChild(root, 0); root->setParent(root, NULL); root->setChildIndex(root, -1); // The root we were given was a nil node, wiht one child, which means it has // been abandoned and would be lost in the node factory. However // nodes can be flagged as resuable to prevent this terrible waste // saveRoot->reuse(saveRoot); } } return root; }
/** Transform ^(nil x) to x */ static pANTLR3_BASE_TREE rulePostProcessing (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE root) { if (root != NULL && root->isNilNode(root)) { if (root->getChildCount(root) == 0) { root = NULL; } else if (root->getChildCount(root) == 1) { root = root->getChild(root, 0); root->setParent(root, NULL); root->setChildIndex(root, -1); } } return root; }
static void setChildIndex (pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE t, ANTLR3_INT32 i) { t->setChildIndex(t, i); }