当前位置: 首页>>代码示例>>C++>>正文


C++ pANTLR3_BASE_TREE::freshenPACIndexes方法代码示例

本文整理汇总了C++中pANTLR3_BASE_TREE::freshenPACIndexes方法的典型用法代码示例。如果您正苦于以下问题:C++ pANTLR3_BASE_TREE::freshenPACIndexes方法的具体用法?C++ pANTLR3_BASE_TREE::freshenPACIndexes怎么用?C++ pANTLR3_BASE_TREE::freshenPACIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pANTLR3_BASE_TREE的用法示例。


在下文中一共展示了pANTLR3_BASE_TREE::freshenPACIndexes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

/// Set the parent and child indexes for all children of the
/// supplied tree.
///
static	void
freshenPACIndexesAll(pANTLR3_BASE_TREE tree)
{
	tree->freshenPACIndexes(tree, 0);
}
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:8,代码来源:antlr3basetree.c

示例2: if

/// Delete children from start to stop and replace with t even if t is
/// a list (nil-root tree). Num of children can increase or decrease.
/// For huge child lists, inserting children can force walking rest of
/// children to set their child index; could be slow.
///
static void					
replaceChildren		(pANTLR3_BASE_TREE parent, ANTLR3_INT32 startChildIndex, ANTLR3_INT32 stopChildIndex, pANTLR3_BASE_TREE newTree)
{
	ANTLR3_INT32	replacingHowMany;		// How many nodes will go away
	ANTLR3_INT32	replacingWithHowMany;	// How many nodes will replace them
	ANTLR3_INT32	numNewChildren;			// Tracking variable
	ANTLR3_INT32	delta;					// Difference in new vs existing count

	ANTLR3_INT32	i;
	ANTLR3_INT32	j;

	pANTLR3_VECTOR	newChildren;			// Iterator for whatever we are going to add in
	ANTLR3_BOOLEAN	freeNewChildren;		// Whether we created the iterator locally or reused it

	if	(parent->children == NULL)
	{
		ANTLR3_FPRINTF(stderr, "replaceChildren call: Indexes are invalid; no children in list for %s", parent->getText(parent)->chars);
		return;
	}

	// Either use the existing list of children in the supplied nil node, or build a vector of the
	// tree we were given if it is not a nil node, then we treat both situations exactly the same
	//
	if	(newTree->isNilNode(newTree))
	{
		newChildren = newTree->children;
		freeNewChildren = ANTLR3_FALSE;		// We must NO free this memory
	}
	else
	{
		newChildren = antlr3VectorNew(1);
		if	(newChildren == NULL)
		{
			ANTLR3_FPRINTF(stderr, "replaceChildren: out of memory!!");
			exit(1);
		}
		newChildren->add(newChildren, (void *)newTree, NULL);

		freeNewChildren = ANTLR3_TRUE;		// We must free this memory
	}

	// Initialize
	//
	replacingHowMany		= stopChildIndex - startChildIndex + 1;
	replacingWithHowMany	= newChildren->size(newChildren);
	delta					= replacingHowMany - replacingWithHowMany;
	numNewChildren			= newChildren->size(newChildren);

	// If it is the same number of nodes, then do a direct replacement
	//
	if	(delta == 0)
	{
		pANTLR3_BASE_TREE	child;

		// Same number of nodes
		//
		j	= 0;
		for	(i = startChildIndex; i <= stopChildIndex; i++)
		{
			child = (pANTLR3_BASE_TREE) newChildren->get(newChildren, j);
			parent->children->set(parent->children, i, child, NULL, ANTLR3_FALSE);
			child->setParent(child, parent);
			child->setChildIndex(child, i);
		}
	}
	else if (delta > 0)
	{
		ANTLR3_UINT32	indexToDelete;

		// Less nodes than there were before
		// reuse what we have then delete the rest
		//
		for	(j = 0; j < numNewChildren; j++)
		{
			parent->children->set(parent->children, startChildIndex + j, newChildren->get(newChildren, j), NULL, ANTLR3_FALSE);
		}

		// We just delete the same index position until done
		//
		indexToDelete = startChildIndex + numNewChildren;

		for	(j = indexToDelete; j <= (ANTLR3_INT32)stopChildIndex; j++)
		{
			parent->children->remove(parent->children, indexToDelete);
		}

		parent->freshenPACIndexes(parent, startChildIndex);
	}
	else
	{
		ANTLR3_UINT32 numToInsert;

		// More nodes than there were before
		// Use what we can, then start adding
		//
//.........这里部分代码省略.........
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:101,代码来源:antlr3basetree.c


注:本文中的pANTLR3_BASE_TREE::freshenPACIndexes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。