本文整理汇总了C++中ASTNode::getNumChildren方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode::getNumChildren方法的具体用法?C++ ASTNode::getNumChildren怎么用?C++ ASTNode::getNumChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTNode
的用法示例。
在下文中一共展示了ASTNode::getNumChildren方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UnitFormulaFormatter
/*
* Checks that the units of the function are consistent
* for a function returning value with same units as argument(s)
*
* If inconsistent units are found, an error message is logged.
*/
void
ArgumentsUnitsCheck::checkSameUnitsAsArgs (const Model& m,
const ASTNode& node,
const SBase & sb, bool inKL,
int reactNo)
{
/* check that node has children */
if (node.getNumChildren() == 0)
{
return;
}
UnitDefinition * ud;
UnitDefinition * tempUD = NULL;
unsigned int n;
unsigned int i = 0;
UnitFormulaFormatter *unitFormat = new UnitFormulaFormatter(&m);
ud = unitFormat->getUnitDefinition(node.getChild(i), inKL, reactNo);
/* get the first child that is not a parameter with undeclared units */
while (unitFormat->getContainsUndeclaredUnits() &&
i < node.getNumChildren()-1)
{
delete ud;
i++;
unitFormat->resetFlags();
ud = unitFormat->getUnitDefinition(node.getChild(i), inKL, reactNo);
}
/* check that all children have the same units
* unless one of the children is a parameter with undeclared units
* which is not tested */
for (n = i+1; n < node.getNumChildren(); n++)
{
unitFormat->resetFlags();
tempUD = unitFormat->getUnitDefinition(node.getChild(n), inKL, reactNo);
if (!unitFormat->getContainsUndeclaredUnits())
{
if (!UnitDefinition::areIdenticalSIUnits(ud, tempUD))
{
logInconsistentSameUnits(node, sb);
}
}
delete tempUD;
}
delete unitFormat;
delete ud;
for (n = 0; n < node.getNumChildren(); n++)
{
checkUnits(m, *node.getChild(n), sb, inKL, reactNo);
}
}
示例2: checkSpecialCases
/**
* Checks that the functions have either one or two arguments
*/
void NumberArgsMathCheck::checkSpecialCases(const Model& m,
const ASTNode& node, const SBase & sb)
{
if (node.getNumChildren() < 1 || node.getNumChildren() > 2)
{
logMathConflict(node, sb);
}
for (unsigned int n = 0; n < node.getNumChildren(); n++)
{
checkMath(m, *node.getChild(n), sb);
}
}
示例3: readMathMLFromStringWithNamespaces
END_TEST
START_TEST (test_element_selector)
{
const char* s = wrapMathML
(
" <apply>"
" <selector/>"
" <ci> A </ci>"
" <ci> i </ci>"
" </apply>"
);
N = readMathMLFromStringWithNamespaces(s, NS);
fail_unless( N != NULL );
fail_unless( N->getType() == AST_ORIGINATES_IN_PACKAGE);
fail_unless( N->getExtendedType() == AST_LINEAR_ALGEBRA_SELECTOR);
fail_unless( N->getNumChildren() == 2);
fail_unless( N->getPackageName() == "arrays");
ASTNode * child = N->getChild(0);
fail_unless( child != NULL );
fail_unless( child->getType() == AST_NAME);
fail_unless( child->getExtendedType() == AST_NAME);
fail_unless( strcmp(child->getName(), "A") == 0);
fail_unless( child->getNumChildren() == 0);
fail_unless( child->getPackageName() == "core");
child = N->getChild(1);
fail_unless( child != NULL );
fail_unless( child->getType() == AST_NAME);
fail_unless( child->getExtendedType() == AST_NAME);
fail_unless( strcmp(child->getName(), "i") == 0);
fail_unless( child->getNumChildren() == 0);
ArraysASTPlugin* plugin = static_cast<ArraysASTPlugin*>(N->getPlugin("arrays"));
fail_unless(plugin != NULL);
fail_unless(plugin->getASTType() == AST_LINEAR_ALGEBRA_SELECTOR);
}
示例4: logMathConflict
/*
* Checks that the second argument of a piecewise returns a boolean
*
* If not, an error message is logged.
*/
void
PieceBooleanMathCheck::checkPiece (const Model& m, const ASTNode& node,
const SBase & sb)
{
unsigned int numChildren = node.getNumChildren();
unsigned int numPieces = numChildren;
if ((numChildren % 2) != 0) numPieces--;
for (unsigned int n = 1; n < numPieces; n += 2)
{
// if we have a mangled node for some reason
// usually we have read an incorrect node
// need to be sure there is a child
// NOTE: piecewise hits this issue because old behaviour
// meant it lost the piece and otherwise qualifiers
ASTNode * child = node.getChild(n);
if (child != NULL)
{
// need to pass the model here in case we have used a functionDefinition
// as the piece child
if (!child->returnsBoolean(&m))
{
logMathConflict(node, sb);
}
}
}
}
示例5: if
/**
* Constructor that makes a ConverterASTNode from an ASTNode.
*/
ConverterASTNode::ConverterASTNode(const ASTNode &templ): ASTNode(templ.getType())
{
if (this->getType() == AST_RATIONAL)
{
this->mDenominator = templ.getDenominator();
this->mInteger = templ.getNumerator();
}
else if (this->getType() == AST_REAL || this->getType() == AST_REAL_E)
{
this->mExponent = templ.getExponent();
this->mReal = templ.getMantissa();
}
if (this->getType() == AST_PLUS || this->getType() == AST_MINUS || this->getType() == AST_TIMES || this->getType() == AST_DIVIDE || this->getType() == AST_POWER)
{
this->mChar = templ.getCharacter();
}
else if (this->getType() == AST_INTEGER)
{
this->mInteger = templ.getInteger();
}
if ((!this->isOperator()) && (!this->isNumber()))
{
this->setName(templ.getName());
}
unsigned int counter;
for (counter = 0; counter < templ.getNumChildren(); counter++)
{
this->addChild(new ConverterASTNode(*templ.getChild(counter)));
}
};
示例6: UnitDefinition
/**
* Checks that the units of the arguments
* of the function are dimensionless
* and that there is only one argument
*
* If inconsistent units are found, an error message is logged.
*/
void
ArgumentsUnitsCheckWarnings::checkDimensionlessArgs (const Model& m,
const ASTNode& node,
const SBase & sb,
bool inKL, int reactNo)
{
/* check that node has children */
if (node.getNumChildren() == 0)
{
return;
}
UnitDefinition *dim = new UnitDefinition(m.getSBMLNamespaces());
Unit *unit = new Unit(m.getSBMLNamespaces());
unit->setKind(UNIT_KIND_DIMENSIONLESS);
unit->initDefaults();
UnitDefinition * tempUD;
dim->addUnit(unit);
UnitFormulaFormatter *unitFormat = new UnitFormulaFormatter(&m);
tempUD = unitFormat->getUnitDefinition(node.getChild(0), inKL, reactNo);
if (tempUD->getNumUnits() != 0 &&
!UnitDefinition::areEquivalent(dim, tempUD))
{
logInconsistentDimensionless(node, sb);
}
delete tempUD;
delete dim;
delete unit;
delete unitFormat;
}
示例7:
unsigned int
ASTPiecewiseFunctionNode::getNumChildren() const
{
/* HACK TO REPLICATE OLD AST */
unsigned int numChildren = 0;
for (unsigned int i = 0; i < getNumPiece(); i++)
{
ASTBase * base = ASTFunctionBase::getChild(i);
ASTNode * piece = dynamic_cast<ASTNode*>(base);
if (piece != NULL && piece->getType() == AST_CONSTRUCTOR_PIECE)
{
numChildren += piece->getNumChildren();
}
else
{
// fail safe - a piece should have 2 children
numChildren += 2;
}
}
if (getHasOtherwise() == true)
{
numChildren++;
}
return numChildren;
}
示例8: logMathConflict
/**
* Checks that the functionDefinition referred to by a <ci> element
* has the appropriate number of arguments.
*
* If not, an error message is logged.
*/
void
FunctionNoArgsMathCheck::checkNumArgs (const Model& m, const ASTNode& node,
const SBase & sb)
{
/* this rule was only introduced level 2 version 4 */
if (m.getLevel() > 2 || (m.getLevel() == 2 && m.getVersion() > 3))
{
if (m.getFunctionDefinition(node.getName()) != NULL)
{
/* functiondefinition math */
const ASTNode * fdMath = m.getFunctionDefinition(node.getName())->getMath();
if (fdMath != NULL)
{
/* We have a definition for this function. Does the defined number
of arguments equal the number used here? */
if (node.getNumChildren() != m.getFunctionDefinition(node.getName())->getNumArguments())
{
logMathConflict(node, sb);
}
}
}
}
}
示例9: checkPiecewise
void NumberArgsMathCheck::checkPiecewise(const Model&,
const ASTNode& node, const SBase & sb)
{
if (node.getNumChildren() == 0)
{
logMathConflict(node, sb);
}
}
示例10: ASTNode
/**
* In MathML, <plus/> and <times/> are n-ary operators but the infix
* FormulaParser represents them as binary operators. To ensure a
* consistent AST representation, this function is part of the n-ary to
* binary reduction process.
*/
static void
reduceBinary (ASTNode& node)
{
if (node.getNumChildren() == 2)
{
ASTNode* op = new ASTNode( node.getType() );
node.swapChildren(op);
node.prependChild(op);
}
}
示例11: checkUnary
/**
* Checks that the function has only one argument
*/
void NumberArgsMathCheck::checkUnary(const Model& m,
const ASTNode& node, const SBase & sb)
{
if (node.getNumChildren() != 1)
{
logMathConflict(node, sb);
}
else
{
checkMath(m, *node.getLeftChild(), sb);
}
}
示例12: hasUnambiguousPackageInfixGrammar
bool ArraysASTPlugin::hasUnambiguousPackageInfixGrammar(const ASTNode *child) const
{
ASTBase* function = const_cast<ASTBase*>(getParentASTObject());
if (function == NULL) return false;
if (function->getType() != AST_ORIGINATES_IN_PACKAGE) return false;
if (function->getPackageName() != "arrays") return false;
// cast the function to an ASTNode
ASTNode* newAST = dynamic_cast<ASTNode*>(function);
if (newAST == NULL)
{
return false;
}
const ArraysASTPlugin* aap = static_cast<const ArraysASTPlugin*>(function->getPlugin("arrays"));
switch(aap->getASTType()) {
case AST_LINEAR_ALGEBRA_SELECTOR:
if (newAST->getNumChildren() == 0) return true;
if (newAST->getChild(0) == child) return false; //The *first* child of the selector needs parentheses in some situations!
return true; //All other children are separated by commas, and thus don't need parentheses.
case AST_LINEAR_ALGEBRA_VECTOR_CONSTRUCTOR:
#if (0)
case AST_LINEAR_ALGEBRA_MATRIX_CONSTRUCTOR:
case AST_LINEAR_ALGEBRA_DETERMINANT:
case AST_LINEAR_ALGEBRA_TRANSPOSE:
case AST_LINEAR_ALGEBRA_VECTOR_PRODUCT:
case AST_LINEAR_ALGEBRA_SCALAR_PRODUCT:
case AST_LINEAR_ALGEBRA_OUTER_PRODUCT:
case AST_LINEAR_ALGEBRA_MATRIXROW_CONSTRUCTOR:
#endif
case AST_QUALIFIER_CONDITION:
case AST_LOGICAL_EXISTS:
case AST_LOGICAL_FORALL:
case AST_QUALIFIER_LOWLIMIT:
case AST_STATISTICS_MEAN:
case AST_STATISTICS_MEDIAN:
case AST_STATISTICS_MODE:
case AST_STATISTICS_MOMENT:
case AST_QUALIFIER_MOMENTABOUT:
case AST_SERIES_PRODUCT:
case AST_STATISTICS_SDEV:
case AST_SERIES_SUM:
case AST_QUALIFIER_UPLIMIT:
case AST_STATISTICS_VARIANCE:
return true; //Everything is either a function or has unambiguous syntax.
case AST_ARRAYS_UNKNOWN:
return false;
}
return false;
}
示例13: removeChild
int
ASTLambdaFunctionNode::removeChild(unsigned int n)
{
int removed = LIBSBML_OPERATION_FAILED;
/* need to keep track of whether we have removed a bvar */
unsigned int numBvars = getNumBvars();
if (numBvars == 0)
{
/* we are removing the body - if the index is appropriate */
return ASTFunctionBase::removeChild(n);
}
if (n < numBvars)
{
// we are removing a bvar
setNumBvars(numBvars - 1);
/* HACK TO REPLICATE OLD AST */
/* Hack to remove memory since the overall
* remove does not remove memory
* but the old api does not give access to the new
* intermediate parents so these can never
* be explicilty deleted by the user
*
* in this case the first remove is accessible
*/
ASTBase * base = ASTFunctionBase::getChild(n);
ASTNode * bvar = dynamic_cast<ASTNode*>(base);
if (bvar != NULL && bvar->getNumChildren() == 1)
{
removed = bvar->removeChild(0);
if (removed == LIBSBML_OPERATION_SUCCESS)
{
ASTBase * removedAST = NULL;
removedAST = this->ASTFunctionBase::getChild(n);
removed = ASTFunctionBase::removeChild(n);
if (removedAST != NULL) delete removedAST;
}
}
}
else
{
// we are removing the body
removed = ASTFunctionBase::removeChild(n);
}
return removed;
}
示例14: logMathConflict
/*
* Checks that the arguments to logical operators are all boolean
*
* If not, an error message is logged.
*/
void
LogicalArgsMathCheck::checkMathFromLogical (const Model&, const ASTNode& node,
const SBase & sb)
{
unsigned int n;
for (n = 0; n < node.getNumChildren(); n++)
{
if (!node.getChild(n)->isBoolean())
{
logMathConflict(node, sb);
}
}
}
示例15: logMathConflict
/*
* Checks that the arguments of numeric functions are consistent
*
* If not, an error message is logged.
*/
void
NumericArgsMathCheck::checkNumericArgs (const Model& m, const ASTNode& node,
const SBase & sb)
{
unsigned int n;
for (n = 0; n < node.getNumChildren(); n++)
{
if (!returnsNumeric(m, node.getChild(n)))
{
logMathConflict(node, sb);
}
}
}