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


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

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


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

示例1:

/** 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;
}
开发者ID:Daniel1892,项目名称:tora,代码行数:34,代码来源:antlr3basetreeadaptor.c

示例2: dumpNode

void SCsTranslator::dumpNode(pANTLR3_BASE_TREE node, std::ofstream &stream)
{
    StringStream ss;
    ss << node;

    String s_root = ss.str().substr(3);
    pANTLR3_COMMON_TOKEN tok = node->getToken(node);
    if (tok)
    {
        stream << s_root << " [shape=box];" << std::endl;
        String label((const char*) node->getText(node)->chars);
        std::replace(label.begin(), label.end(), '"', '\'');
        stream << s_root << " [label=\"" << label << "\"];" << std::endl;
    }
    else
        stream << s_root << " [shape=circle];" << std::endl;

    uint32 n = node->getChildCount(node);
    for (uint32 i = 0; i < n; ++i)
    {
        pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE) node->getChild(node, i);
        StringStream s1;
        s1 << child;

        stream << s_root << " -> " << s1.str().substr(3) << ";" << std::endl;
        dumpNode(child, stream);
    }
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:28,代码来源:scs_translator.cpp

示例3: processSentenceAssign

void SCsTranslator::processSentenceAssign(pANTLR3_BASE_TREE node)
{
    unsigned int nodesCount = node->getChildCount(node);
    assert(nodesCount == 2);

    pANTLR3_BASE_TREE node_left = (pANTLR3_BASE_TREE)node->getChild(node, 0);
    pANTLR3_BASE_TREE node_right = (pANTLR3_BASE_TREE)node->getChild(node, 1);

    pANTLR3_COMMON_TOKEN tok_left = node_left->getToken(node_left);
    pANTLR3_COMMON_TOKEN tok_right = node_left->getToken(node_right);

    assert(tok_left && tok_right);

    if (tok_left->type != ID_SYSTEM)
    {
        THROW_EXCEPT(Exception::ERR_PARSE,
                     "Unsupported type of tokens at the left side of assignment sentence",
                     mParams.fileName,
                     tok_left->getLine(tok_left));
    }

    if (tok_right->type == ID_SYSTEM)
    {
        mAssignments[GET_NODE_TEXT(node_left)] = GET_NODE_TEXT(node_right);
    }
    else
    {
        String left_idtf = (GET_NODE_TEXT(node_left));
        sElement *el = parseElementTree(node_right, &left_idtf);
    }
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:31,代码来源:scs_translator.cpp

示例4: assert

void SCsTranslator::processSentenceLevel1(pANTLR3_BASE_TREE node)
{
    unsigned int nodesCount = node->getChildCount(node);
    assert(nodesCount == 3);

    pANTLR3_BASE_TREE node_obj = (pANTLR3_BASE_TREE)node->getChild(node, 0);
    pANTLR3_BASE_TREE node_pred = (pANTLR3_BASE_TREE)node->getChild(node, 1);
    pANTLR3_BASE_TREE node_subj = (pANTLR3_BASE_TREE)node->getChild(node, 2);

    pANTLR3_COMMON_TOKEN tok_pred = node_pred->getToken(node_pred);

    if (tok_pred->type != ID_SYSTEM)
    {
        THROW_EXCEPT(Exception::ERR_PARSE,
                     String("Invalid predicate '") + ((const char*) node_pred->getText(node_pred)->chars) + "' in simple sentence",
                     mParams.fileName,
                     tok_pred->getLine(tok_pred));
    }

    sElement *el_obj = parseElementTree(node_obj);
    sElement *el_subj = parseElementTree(node_subj);

    // determine arc type
    sc_type type = sc_type_edge_common;
    String pred = GET_NODE_TEXT(node_pred);
    size_t n = pred.find_first_of("#");
    if (n != pred.npos)
        type = _getArcPreffixType(pred.substr(0, n));

    _addEdge(el_obj, el_subj, type, false, pred);
}
开发者ID:rusetski-k,项目名称:sc-machine,代码行数:31,代码来源:scs_translator.cpp

示例5: ASTNode

ActualParamDef::ActualParamDef(const pANTLR3_BASE_TREE node)
    : ASTNode(node)
{
    assert(node->getType(node) == N_ACTUAL_PARAM);
    assert(node->getChildCount(node) == 2);

    pANTLR3_BASE_TREE n;

    {
        // param name
        n = (pANTLR3_BASE_TREE) node->getChild(node, 0);
        assert(n->getType(n) == N_PARAM_NAME);
        assert(n->getChildCount(n) == 1);

        n = (pANTLR3_BASE_TREE) n->getChild(n, 0);

        m_ParamName = (wchar_t*) n->getText(n)->chars;
    }

    {
        // value
        n = (pANTLR3_BASE_TREE) node->getChild(node, 1);
        assert(n->getType(n) == N_VALUE);

        createValueDef(n, m_pValue);
    }
}
开发者ID:ernestobad,项目名称:ContainedObjects,代码行数:27,代码来源:ActualParamDef.cpp

示例6: f

	IntegerLiteralValueDef::IntegerLiteralValueDef(const pANTLR3_BASE_TREE node)
		: LiteralValueDef(INTEGER_LITERAL, node)
	{
		assert(node->getType(node) == N_INT_LITERAL);
		assert(node->getChildCount(node) == 1);

		pANTLR3_BASE_TREE n = (pANTLR3_BASE_TREE) node->getChild(node, 0);

		assert(n->getType(n) == INTL);

		wchar_t* szStr = (wchar_t*) n->getText(n)->chars;
		
		int value;

		try
		{
			value = boost::lexical_cast<int, wchar_t*>(szStr);
		}
		catch (const std::exception&)
		{
			boost::wformat f(L"Invalid integer value: %1% at line %2%");
			f % szStr % node->getLine(node);
			ParserException e(f.str());
			throw e;
		}

		m_IntValue = value;
	}
开发者ID:ernestobad,项目名称:ContainedObjects,代码行数:28,代码来源:IntegerLiteralValueDef.cpp

示例7: ValueDef

	ArrayInitValueDef::ArrayInitValueDef(const pANTLR3_BASE_TREE node)
		: ValueDef(ARRAY_INIT, node)
	{
		assert(node->getType(node) == N_ARRAY_INIT_VAL);
		assert(node->getChildCount(node) == 2);

		pANTLR3_BASE_TREE n, c;

		{
			// type
			n = (pANTLR3_BASE_TREE) node->getChild(node, 0);
			assert(n->getType(n) == N_ARRAY_TYPE);
			
			m_pDeclaredType = boost::shared_ptr<Type>(static_cast<Type*>(new ArrayType(n)));
		}

		{
			// array values
			n = (pANTLR3_BASE_TREE) node->getChild(node, 1);
			assert(n->getType(n) == N_ARRAY_VALUES);

			m_Values.clear();

			int childCount = n->getChildCount(n);
			for (int i = 0; i < childCount; i++)
			{
				c = (pANTLR3_BASE_TREE) n->getChild(n, i);

				boost::shared_ptr<ValueDef> pValueDef;
				createValueDef(c, pValueDef);

				m_Values.push_back(pValueDef);
			}
		}
	}
开发者ID:ernestobad,项目名称:ContainedObjects,代码行数:35,代码来源:ArrayInitValueDef.cpp

示例8:

/** 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;
}
开发者ID:aslakhellesoy,项目名称:antlr-3,代码行数:21,代码来源:antlr3basetreeadaptor.c

示例9:

/** Transform ^(nil x) to x 
 */
static	pANTLR3_BASE_TREE	
   rulePostProcessing	(pANTLR3_BASE_TREE_ADAPTOR adaptor, pANTLR3_BASE_TREE root)
{

	if (root != NULL && root->isNil(root) && root->getChildCount(root) == 1)
	{
		root = root->getChild(root, 0);
	}

	return root;
}
开发者ID:UIKit0,项目名称:mclab,代码行数:13,代码来源:antlr3basetreeadaptor.c

示例10: if

static  void
toStringWork    (pANTLR3_TREE_NODE_STREAM tns, pANTLR3_BASE_TREE p, pANTLR3_BASE_TREE stop, pANTLR3_STRING buf)
{

        ANTLR3_UINT32   n;
        ANTLR3_UINT32   c;

        if      (!p->isNilNode(p) )
        {
                pANTLR3_STRING  text;

                text    = p->toString(p);

                if  (text == NULL)
                {
                        text = tns->ctns->stringFactory->newRaw(tns->ctns->stringFactory);

                        text->addc      (text, ' ');
                        text->addi      (text, p->getType(p));
                }

                buf->appendS(buf, text);
        }

        if      (p == stop)
        {
                return;         /* Finished */
        }

        n = p->getChildCount(p);

        if      (n > 0 && ! p->isNilNode(p) )
        {
                buf->addc   (buf, ' ');
                buf->addi   (buf, ANTLR3_TOKEN_DOWN);
        }

        for     (c = 0; c<n ; c++)
        {
                pANTLR3_BASE_TREE   child;

                child = p->getChild(p, c);
                tns->toStringWork(tns, child, stop, buf);
        }

        if      (n > 0 && ! p->isNilNode(p) )
        {
                buf->addc   (buf, ' ');
                buf->addi   (buf, ANTLR3_TOKEN_UP);
        }
}
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:51,代码来源:antlr3commontreenodestream.c

示例11: dumpTree

std::string MySQLRecognitionBase::dumpTree(pANTLR3_UINT8 *tokenNames, pANTLR3_BASE_TREE tree, const std::string &indentation)
{
  std::string result;

  ANTLR3_UINT32 char_pos = tree->getCharPositionInLine(tree);
  ANTLR3_UINT32 line = tree->getLine(tree);
  pANTLR3_STRING token_text = tree->getText(tree);

  pANTLR3_COMMON_TOKEN token = tree->getToken(tree);
  const char* utf8 = (const char*)token_text->chars;
  if (token != NULL)
  {
    ANTLR3_UINT32 token_type = token->getType(token);

    pANTLR3_UINT8 token_name;
    if (token_type == EOF)
      token_name = (pANTLR3_UINT8)"EOF";
    else
      token_name = tokenNames[token_type];

#ifdef ANTLR3_USE_64BIT
    result = base::strfmt("%s(line: %i, offset: %i, length: %" PRId64 ", index: %" PRId64 ", %s[%i])    %s\n",
                          indentation.c_str(), line, char_pos, token->stop - token->start + 1, token->index, token_name,
                          token_type, utf8);
#else
    result = base::strfmt("%s(line: %i, offset: %i, length: %i, index: %i, %s[%i])    %s\n",
                          indentation.c_str(), line, char_pos, token->stop - token->start + 1, token->index, token_name,
                          token_type, utf8);
#endif

  }
  else
  {
    result = base::strfmt("%s(line: %i, offset: %i, nil)    %s\n", indentation.c_str(), line, char_pos, utf8);
  }

  for (ANTLR3_UINT32 index = 0; index < tree->getChildCount(tree); index++)
  {
    pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE)tree->getChild(tree, index);
    std::string child_text = dumpTree(tokenNames, child, indentation + "\t");
    result += child_text;
  }
  return result;
}
开发者ID:ThiagoGarciaAlves,项目名称:mysql-workbench,代码行数:44,代码来源:mysql-parser-common.cpp

示例12: fillBuffer

/// Walk tree with depth-first-search and fill nodes buffer.
/// Don't add in DOWN, UP nodes if the supplied tree is a list (t is isNilNode)
// such as the root tree is.
///
static void
fillBuffer(pANTLR3_COMMON_TREE_NODE_STREAM ctns, pANTLR3_BASE_TREE t)
{
        ANTLR3_BOOLEAN  nilNode;
        ANTLR3_UINT32   nCount;
        ANTLR3_UINT32   c;

        nilNode = ctns->adaptor->isNilNode(ctns->adaptor, t);

        // If the supplied node is not a nil (list) node then we
        // add in the node itself to the vector
        //
        if      (nilNode == ANTLR3_FALSE)
        {
                ctns->nodes->add(ctns->nodes, t, NULL);
        }

        // Only add a DOWN node if the tree is not a nil tree and
        // the tree does have children.
        //
        nCount = t->getChildCount(t);

        if      (nilNode == ANTLR3_FALSE && nCount>0)
        {
                ctns->addNavigationNode(ctns, ANTLR3_TOKEN_DOWN);
        }

        // We always add any children the tree contains, which is
        // a recursive call to this function, which will cause similar
        // recursion and implement a depth first addition
        //
        for     (c = 0; c < nCount; c++)
        {
                fillBuffer(ctns, ctns->adaptor->getChild(ctns->adaptor, t, c));
        }

        // If the tree had children and was not a nil (list) node, then we
        // we need to add an UP node here to match the DOWN node
        //
        if      (nilNode == ANTLR3_FALSE && nCount > 0)
        {
                ctns->addNavigationNode(ctns, ANTLR3_TOKEN_UP);
        }
}
开发者ID:cctbx,项目名称:cctbx-playground,代码行数:48,代码来源:antlr3commontreenodestream.c

示例13:

static ANTLR3_UINT32	    getCharPositionInLine	(pANTLR3_BASE_TREE tree)
{
	pANTLR3_COMMON_TOKEN    token;

	token   = ((pANTLR3_COMMON_TREE)(tree->super))->token;

	if	(token == NULL || token->getCharPositionInLine(token) == -1)
	{
		if  (tree->getChildCount(tree) > 0)
		{
			pANTLR3_BASE_TREE	child;

			child   = (pANTLR3_BASE_TREE)tree->getChild(tree, 0);

			return child->getCharPositionInLine(child);
		}
		return 0;
	}
	return  token->getCharPositionInLine(token);
}
开发者ID:166MMX,项目名称:antlr3,代码行数:20,代码来源:antlr3commontree.c

示例14:

/// Set the parent and child indexes for some of the children of the
/// supplied tree, starting with the child at the supplied index.
///
static	void
freshenPACIndexes	(pANTLR3_BASE_TREE tree, ANTLR3_UINT32 offset)
{
	ANTLR3_UINT32	count;
	ANTLR3_UINT32	c;

	count	= tree->getChildCount(tree);		// How many children do we have 

	// Loop from the supplied index and set the indexes and parent
	//
	for	(c = offset; c < count; c++)
	{
		pANTLR3_BASE_TREE	child;

		child = tree->getChild(tree, c);

		child->setChildIndex(child, c);
		child->setParent(child, tree);
	}
}
开发者ID:10114395,项目名称:android-5.0.0_r5,代码行数:23,代码来源:antlr3basetree.c

示例15: emerson_createTreeMirrorImage

void emerson_createTreeMirrorImage(pANTLR3_BASE_TREE ptr)
{

    if(ptr!= NULL && ptr->children != NULL)
    {

        ANTLR3_UINT32 n = ptr->getChildCount(ptr);
        if(n == 1)
        {
            emerson_createTreeMirrorImage((pANTLR3_BASE_TREE)(ptr->getChild(ptr, 0)));
        }
        if(n == 2)  // should it be checked
        {
            pANTLR3_BASE_TREE right = (pANTLR3_BASE_TREE)(ptr->getChild(ptr, 1));
            emerson_createTreeMirrorImage( (pANTLR3_BASE_TREE)(ptr->getChild(ptr, 0)));
            emerson_createTreeMirrorImage( (pANTLR3_BASE_TREE)(ptr->getChild(ptr, 1)) );
            ptr->setChild(ptr, 1, ptr->getChild(ptr, 0));
            ptr->setChild(ptr, 0, right);
        }
    }
}
开发者ID:LittleForker,项目名称:sirikata,代码行数:21,代码来源:Util.cpp


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