Lines Matching refs:tree

4 // starting point for your own tree. Though it is often easier just to tag things on
5 // to the user pointer in the tree unless you are building a different type
41 static pANTLR3_COMMON_TOKEN getToken (pANTLR3_BASE_TREE tree);
42 static pANTLR3_BASE_TREE dupNode (pANTLR3_BASE_TREE tree);
43 static ANTLR3_BOOLEAN isNilNode (pANTLR3_BASE_TREE tree);
44 static ANTLR3_UINT32 getType (pANTLR3_BASE_TREE tree);
45 static pANTLR3_STRING getText (pANTLR3_BASE_TREE tree);
46 static ANTLR3_UINT32 getLine (pANTLR3_BASE_TREE tree);
47 static ANTLR3_UINT32 getCharPositionInLine (pANTLR3_BASE_TREE tree);
48 static pANTLR3_STRING toString (pANTLR3_BASE_TREE tree);
49 static pANTLR3_BASE_TREE getParent (pANTLR3_BASE_TREE tree);
50 static void setParent (pANTLR3_BASE_TREE tree, pANTLR3_BASE_TREE parent);
51 static void setChildIndex (pANTLR3_BASE_TREE tree, ANTLR3_INT32 i);
52 static ANTLR3_INT32 getChildIndex (pANTLR3_BASE_TREE tree);
53 static void createChildrenList (pANTLR3_BASE_TREE tree);
54 static void reuse (pANTLR3_BASE_TREE tree);
60 static pANTLR3_BASE_TREE newFromTree (pANTLR3_ARBORETUM factory, pANTLR3_COMMON_TREE tree);
156 pANTLR3_COMMON_TREE tree;
160 tree = factory->nilStack->peek(factory->nilStack);
162 if (tree != NULL)
170 return (pANTLR3_BASE_TREE)tree;
173 // See if we need a new tree pool before allocating a new tree
185 tree = factory->pools[factory->thisPool] + factory->nextTree;
190 antlr3SetCTAPI(tree);
195 tree->factory = factory;
196 tree->baseTree.strFactory = factory->unTruc.baseTree.strFactory;
198 // The super points to the common tree so we must override the one used by
199 // by the pre-built tree as otherwise we will always poitn to the same initial
200 // common tree and we might spend 3 hours trying to debug why - this would never
203 tree->baseTree.super = tree;
208 return &(tree->baseTree);
213 newFromTree(pANTLR3_ARBORETUM factory, pANTLR3_COMMON_TREE tree)
224 // Pick up the payload we had in the supplied tree
226 ((pANTLR3_COMMON_TREE)(newTree->super))->token = tree->token;
227 newTree->u = tree->baseTree.u; // Copy any user pointer
244 // Pick up the payload we had in the supplied tree
266 // We now JUST free the pools because the C runtime CommonToken based tree
289 antlr3SetCTAPI(pANTLR3_COMMON_TREE tree)
291 // Init base tree
293 antlr3BaseTreeNew(&(tree->baseTree));
299 tree->baseTree.super = tree;
301 // Common tree overrides
303 tree->baseTree.isNilNode = isNilNode;
304 tree->baseTree.toString = toString;
305 tree->baseTree.dupNode = (void *(*)(pANTLR3_BASE_TREE))(dupNode);
306 tree->baseTree.getLine = getLine;
307 tree->baseTree.getCharPositionInLine = getCharPositionInLine;
308 tree->baseTree.toString = toString;
309 tree->baseTree.getType = getType;
310 tree->baseTree.getText = getText;
311 tree->baseTree.getToken = getToken;
312 tree->baseTree.getParent = getParent;
313 tree->baseTree.setParent = setParent;
314 tree->baseTree.setChildIndex = setChildIndex;
315 tree->baseTree.getChildIndex = getChildIndex;
316 tree->baseTree.createChildrenList = createChildrenList;
317 tree->baseTree.reuse = reuse;
318 tree->baseTree.free = NULL; // Factory trees have no free function
319 tree->baseTree.u = NULL; // Initialize user pointer
321 tree->baseTree.children = NULL;
323 tree->token = NULL; // No token as yet
324 tree->startIndex = 0;
325 tree->stopIndex = 0;
326 tree->parent = NULL; // No parent yet
327 tree->childIndex = -1;
339 pANTLR3_COMMON_TREE tree;
340 tree = ANTLR3_CALLOC(1, sizeof(ANTLR3_COMMON_TREE));
342 if (tree == NULL)
347 antlr3SetCTAPI(tree);
349 return tree;
364 //Pick up the payload we had in the supplied tree
374 createChildrenList (pANTLR3_BASE_TREE tree)
376 tree->children = ((pANTLR3_COMMON_TREE)(tree->super))->factory->vFactory->newVector(((pANTLR3_COMMON_TREE)(tree->super))->factory->vFactory);
381 getToken (pANTLR3_BASE_TREE tree)
383 // The token is the payload of the common tree or other implementor
389 return ((pANTLR3_COMMON_TREE)(tree->super))->token;
393 dupNode (pANTLR3_BASE_TREE tree)
395 // The node we are duplicating is in fact the common tree (that's why we are here)
400 theOld = (pANTLR3_COMMON_TREE)(tree->super);
408 isNilNode (pANTLR3_BASE_TREE tree)
410 // This is a Nil tree if it has no payload (Token in our case)
412 if (((pANTLR3_COMMON_TREE)(tree->super))->token == NULL)
423 getType (pANTLR3_BASE_TREE tree)
427 theTree = (pANTLR3_COMMON_TREE)(tree->super);
440 getText (pANTLR3_BASE_TREE tree)
442 return tree->toString(tree);
445 static ANTLR3_UINT32 getLine (pANTLR3_BASE_TREE tree)
450 cTree = (pANTLR3_COMMON_TREE)(tree->super);
456 if (tree->getChildCount(tree) > 0)
460 child = (pANTLR3_BASE_TREE)tree->getChild(tree, 0);
468 static ANTLR3_UINT32 getCharPositionInLine (pANTLR3_BASE_TREE tree)
472 token = ((pANTLR3_COMMON_TREE)(tree->super))->token;
476 if (tree->getChildCount(tree) > 0)
480 child = (pANTLR3_BASE_TREE)tree->getChild(tree, 0);
489 static pANTLR3_STRING toString (pANTLR3_BASE_TREE tree)
491 if (tree->isNilNode(tree) == ANTLR3_TRUE)
495 nilNode = tree->strFactory->newPtr(tree->strFactory, (pANTLR3_UINT8)"nil", 3);
500 return ((pANTLR3_COMMON_TREE)(tree->super))->token->getText(((pANTLR3_COMMON_TREE)(tree->super))->token);
504 getParent (pANTLR3_BASE_TREE tree)
506 return & (((pANTLR3_COMMON_TREE)(tree->super))->parent->baseTree);
510 setParent (pANTLR3_BASE_TREE tree, pANTLR3_BASE_TREE parent)
512 ((pANTLR3_COMMON_TREE)(tree->super))->parent = parent == NULL ? NULL : ((pANTLR3_COMMON_TREE)(parent->super))->parent;
516 setChildIndex (pANTLR3_BASE_TREE tree, ANTLR3_INT32 i)
518 ((pANTLR3_COMMON_TREE)(tree->super))->childIndex = i;
521 getChildIndex (pANTLR3_BASE_TREE tree )
523 return ((pANTLR3_COMMON_TREE)(tree->super))->childIndex;
526 /** Clean up any child vector that the tree might have, so it can be reused,
530 reuse (pANTLR3_BASE_TREE tree)
534 cTree = (pANTLR3_COMMON_TREE)(tree->super);
544 cTree->factory->nilStack->push(cTree->factory->nilStack, tree, NULL);