static void setChild (pANTLR3_BASE_TREE tree, ANTLR3_UINT32 i, void * child) { if (tree->children == NULL) { tree->createChildrenList(tree); } tree->children->set(tree->children, i, child, NULL, ANTLR3_FALSE); }
void addChild (pANTLR3_BASE_TREE tree, pANTLR3_BASE_TREE child) { ANTLR3_UINT32 n; ANTLR3_UINT32 i; if (child == NULL) { return; } if (child->isNilNode(child) == ANTLR3_TRUE) { if (child->children != NULL && child->children == tree->children) { // TODO: Change to exception rather than ANTLR3_FPRINTF? // ANTLR3_FPRINTF(stderr, "ANTLR3: An attempt was made to add a child list to itself!\n"); return; } // Add all of the children's children to this list // if (child->children != NULL) { if (tree->children == NULL) { // We are build ing the tree structure here, so we need not // worry about duplication of pointers as the tree node // factory will only clean up each node once. So we just // copy in the child's children pointer as the child is // a nil node (has not root itself). // tree->children = child->children; child->children = NULL; freshenPACIndexesAll(tree); } else { // Need to copy the children // n = child->children->size(child->children); for (i = 0; i < n; i++) { pANTLR3_BASE_TREE entry; entry = child->children->get(child->children, i); // ANTLR3 lists can be sparse, unlike Array Lists // if (entry != NULL) { tree->children->add(tree->children, entry, (void (ANTLR3_CDECL *) (void *))child->free); } } } } } else { // Tree we are adding is not a Nil and might have children to copy // if (tree->children == NULL) { // No children in the tree we are adding to, so create a new list on // the fly to hold them. // tree->createChildrenList(tree); } tree->children->add(tree->children, child, (void (ANTLR3_CDECL *)(void *))child->free); } }