本文整理汇总了C++中ASTNode::getType方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode::getType方法的具体用法?C++ ASTNode::getType怎么用?C++ ASTNode::getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTNode
的用法示例。
在下文中一共展示了ASTNode::getType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: switch
/*
* Checks the MathML of the ASTnode
* is appropriate for the function being performed
*
* If an inconsistency is found, an error message is logged.
*/
void
PieceBooleanMathCheck::checkMath (const Model& m, const ASTNode& node, const SBase & sb)
{
ASTNodeType_t type = node.getType();
switch (type)
{
case AST_FUNCTION_PIECEWISE:
checkPiece(m, node, sb);
break;
case AST_FUNCTION:
checkFunction(m, node, sb);
break;
default:
checkChildren(m, node, sb);
break;
}
}
示例3: 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)));
}
};
示例4: addChildren
void addChildren(Association* association, const ASTNode* node, const ASTNode *current)
{
if (node->getType() == AST_TIMES || node->getType() == AST_PLUS)
{
for (unsigned int i = 0; i < node->getNumChildren(); ++i)
{
ASTNode* astChild = node->getChild(i);
if (astChild->getType() == current->getType())
{
addChildren(association, astChild, node);
continue;
}
Association* child = toAssociation(astChild);
if (child == NULL)
continue;
association->addAssociation(*child);
delete child;
}
}
else{
Association* child = toAssociation(node);
if (child == NULL)
return;
association->addAssociation(*child);
}
}
示例5:
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;
}
示例6: switch
/**
* Checks the MathML of the ASTnode
* is appropriate for the function being performed
*
* If an inconsistency is found, an error message is logged.
*/
void
EqualityArgsMathCheck::checkMath (const Model& m, const ASTNode& node, const SBase & sb)
{
ASTNodeType_t type = node.getType();
/* check arguments of eq or neq */
switch (type)
{
case AST_RELATIONAL_EQ:
case AST_RELATIONAL_NEQ:
checkArgs(m, node, sb);
break;
case AST_FUNCTION:
checkFunction(m, node, sb);
break;
default:
checkChildren(m, node, sb);
break;
}
}
示例7: switch
/**
* Checks that the units of the result of the assignment rule
* are consistent with variable being assigned
*
* If an inconsistent variable is found, an error message is logged.
*/
void
PowerUnitsCheck::checkUnits (const Model& m, const ASTNode& node, const SBase & sb,
bool inKL, int reactNo)
{
ASTNodeType_t type = node.getType();
switch (type)
{
//case AST_DIVIDE:
// checkForPowersBeingDivided(m, node, sb);
// break;
case AST_POWER:
case AST_FUNCTION_POWER:
checkUnitsFromPower(m, node, sb, inKL, reactNo);
break;
case AST_FUNCTION:
checkFunction(m, node, sb, inKL, reactNo);
break;
default:
checkChildren(m, node, sb, inKL, reactNo);
break;
}
}
示例8: switch
/*
* Checks the MathML of the ASTnode
* is appropriate for the function being performed
*
* If an inconsistency is found, an error message is logged.
*/
void
LambdaMathCheck::checkMath (const Model& m, const ASTNode& node, const SBase & sb)
{
/* should not be here but why not catch it rather than crash*/
if (&(node) == NULL)
{
return;
}
ASTNodeType_t type = node.getType();
/* a lambda function outside a functionDefinition is a conflict */
switch (type)
{
case AST_LAMBDA:
logMathConflict(node, sb);
break;
default:
checkChildren(m, node, sb);
break;
}
}
示例9: switch
/*
* Checks the MathML of the ASTnode
* is appropriate for the function being performed
*
* If an inconsistency is found, an error message is logged.
*/
void
LogicalArgsMathCheck::checkMath (const Model& m, const ASTNode& node, const SBase & sb)
{
ASTNodeType_t type = node.getType();
switch (type)
{
case AST_LOGICAL_AND:
case AST_LOGICAL_NOT:
case AST_LOGICAL_OR:
case AST_LOGICAL_XOR:
checkMathFromLogical(m, node, sb);
break;
case AST_FUNCTION:
checkFunction(m, node, sb);
break;
default:
checkChildren(m, node, sb);
break;
}
}
示例10: switch
/*
* Checks the MathML of the ASTnode
* is appropriate for the function being performed
*
* If an inconsistency is found, an error message is logged.
*/
void
LogicalArgsMathCheck::checkMath (const Model& m, const ASTNode& node, const SBase & sb)
{
/* should not be here but why not catch it rather than crash*/
if (&(node) == NULL)
{
return;
}
ASTNodeType_t type = node.getType();
switch (type)
{
case AST_LOGICAL_AND:
case AST_LOGICAL_NOT:
case AST_LOGICAL_OR:
case AST_LOGICAL_XOR:
checkMathFromLogical(m, node, sb);
break;
case AST_FUNCTION:
checkFunction(m, node, sb);
break;
default:
checkChildren(m, node, sb);
break;
}
}
示例11: testConstructor
void TestASTNode::testConstructor()
{
ASTNode* node = new ASTNode("value", PROGRAM, 1);
CPPUNIT_ASSERT("value" == node->getName());
CPPUNIT_ASSERT_EQUAL(PROGRAM, node->getType());
CPPUNIT_ASSERT_EQUAL(1, node->getStatementNumber());
}
示例12: getCalledProcedure
std::string AST::getCalledProcedure(int stmtNum)
{
ASTNode* node = getStatementNode(stmtNum);
if (node->getType() == CALL) {
return node->getName();
} else {
return "";
}
}
示例13: 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);
}
}
示例14: checkValidUnits
/**
* Checks the MathML of the ASTnode
* is appropriate for the function being performed
*
* If an inconsistency is found, an error message is logged.
*/
void
ValidCnUnitsValue::checkMath (const Model& m, const ASTNode& node, const SBase & sb)
{
/* should not be here but why not catch it rather than crash*/
if (&(node) == NULL)
{
return;
}
if (node.isNumber())
{
checkValidUnits(m, node, sb);
}
else
{
ASTNodeType_t type = node.getType();
switch (type)
{
case AST_FUNCTION:
checkFunction(m, node, sb);
break;
default:
checkChildren(m, node, sb);
break;
}
}
//switch (type)
//{
// case AST_LOGICAL_AND:
// case AST_LOGICAL_NOT:
// case AST_LOGICAL_OR:
// case AST_LOGICAL_XOR:
// checkMathFromLogical(m, node, sb);
// break;
// case AST_FUNCTION:
// checkFunction(m, node, sb);
// break;
// default:
// checkChildren(m, node, sb);
// break;
//}
}
示例15: if
/**
* Ensures the given ASTNode has the appropriate number of arguments. If
* arguments are missing, appropriate defaults (per the MathML 2.0
* specification) are added:
*
* log (x) -> log (10, x)
* root(x) -> root( 2, x)
*/
static void
checkFunctionArgs (ASTNode& node)
{
if (node.getNumChildren() == 1)
{
if (node.getType() == AST_FUNCTION_LOG)
{
ASTNode* child = new ASTNode;
child->setValue(10);
node.prependChild(child);
}
else if (node.getType() == AST_FUNCTION_ROOT)
{
ASTNode* child = new ASTNode;
child->setValue(2);
node.prependChild(child);
}
}
}