本文整理汇总了C++中ASTNode类的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode类的具体用法?C++ ASTNode怎么用?C++ ASTNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ASTNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: searchTerm
bool PropagateEqualities::searchTerm(const ASTNode& lhs, const ASTNode& rhs)
{
const unsigned width = lhs.GetValueWidth();
if (lhs == rhs)
return true;
if (lhs.GetKind() == SYMBOL)
return simp->UpdateSubstitutionMap(lhs, rhs); // checks whether it's been
// solved for, or if the RHS
// contains the LHS.
if (lhs.GetKind() == BVUMINUS)
return searchTerm(lhs[0], nf->CreateTerm(BVUMINUS, width, rhs));
if (lhs.GetKind() == BVNEG)
return searchTerm(lhs[0], nf->CreateTerm(BVNEG, width, rhs));
if (lhs.GetKind() == BVXOR || lhs.GetKind() == BVPLUS)
for (size_t i = 0; i < lhs.Degree(); i++)
{
ASTVec others;
for (size_t j = 0; j < lhs.Degree(); j++)
if (j != i)
others.push_back(lhs[j]);
ASTNode new_rhs;
if (lhs.GetKind() == BVXOR)
{
others.push_back(rhs);
assert(others.size() > 1);
new_rhs = nf->CreateTerm(lhs.GetKind(), width, others);
}
else if (lhs.GetKind() == BVPLUS)
{
if (others.size() > 1)
new_rhs = nf->CreateTerm(BVPLUS, width, others);
else
new_rhs = others[0];
new_rhs = nf->CreateTerm(BVUMINUS, width, new_rhs);
new_rhs = nf->CreateTerm(BVPLUS, width, new_rhs, rhs);
}
else
FatalError("sdafasfsdf2q3234423");
bool result = searchTerm(lhs[i], new_rhs);
if (result)
return true;
}
if (lhs.Degree() == 2 && lhs.GetKind() == BVMULT && lhs[0].isConstant() &&
simp->BVConstIsOdd(lhs[0]))
return searchTerm(lhs[1],
nf->CreateTerm(BVMULT, width,
simp->MultiplicativeInverse(lhs[0]), rhs));
return false;
}
示例2: getNumChildren
int
ASTPiecewiseFunctionNode::addChild(ASTBase* child, bool inRead)
{
// now here what I want to do is just keep track of the number
// of children being added so the mNumPiece and mHasOtherwise
// variables can be given appropriate values
// but not if we are reading a stream because then we already know
if (inRead == false)
{
if (child->getType() != AST_CONSTRUCTOR_PIECE &&
child->getType() != AST_CONSTRUCTOR_OTHERWISE)
{
// this child does not have a piece/otherwise but if
// the rest of the function does then it needs to fit in with that
unsigned int currentNum = getNumChildren();
if (usingChildConstructors() == false)
{
if ((currentNum+1)%2 == 0)
{
setNumPiece(getNumPiece()+1);
setHasOtherwise(false);
}
else
{
setHasOtherwise(true);
}
return ASTFunctionBase::addChild(child);
}
else
{
ASTBase * lastChild =
ASTFunctionBase::getChild(ASTFunctionBase::getNumChildren()-1);
if (lastChild == NULL)
{ // we have a serious issue going on but may as well just
// add the child
return ASTFunctionBase::addChild(child);
}
else if (lastChild->getType() == AST_CONSTRUCTOR_PIECE)
{
ASTNode * piece = dynamic_cast<ASTNode*>(lastChild);
if (piece == NULL)
{
return LIBSBML_OPERATION_FAILED;
}
if (piece->getNumChildren() == 1)
{
return piece->addChild((ASTNode*)(child));
}
else
{
ASTNode * otherwise = new ASTNode(AST_CONSTRUCTOR_OTHERWISE);
if (otherwise->addChild((ASTNode*)(child)) == LIBSBML_OPERATION_SUCCESS)
{
setHasOtherwise(true);
return ASTFunctionBase::addChild(otherwise);
}
else
{
return LIBSBML_OPERATION_FAILED;
}
}
}
else
{
ASTNode * otherwise = dynamic_cast<ASTNode*>(lastChild);
if (otherwise == NULL || otherwise->getNumChildren() != 1)
{
return LIBSBML_OPERATION_FAILED;
}
ASTNode * piece = new ASTNode(AST_CONSTRUCTOR_PIECE);
// add teh child from teh otherwise
if (piece->addChild(otherwise->getChild(0)) != LIBSBML_OPERATION_SUCCESS)
{
return LIBSBML_OPERATION_FAILED;
}
else
{
if (piece->addChild((ASTNode*)(child)) == LIBSBML_OPERATION_SUCCESS)
{
this->removeChild(currentNum-1);
setHasOtherwise(false);
setNumPiece(getNumPiece() + 1);
return ASTFunctionBase::addChild(piece);
}
else
{
return LIBSBML_OPERATION_FAILED;
}
}
}
}
}
//.........这里部分代码省略.........
示例3: BVConstEvaluator
ASTNode BeevMgr::BVConstEvaluator(const ASTNode& t) {
ASTNode OutputNode;
Kind k = t.GetKind();
if(CheckSolverMap(t,OutputNode))
return OutputNode;
OutputNode = t;
unsigned int inputwidth = t.GetValueWidth();
unsigned int outputwidth = inputwidth;
CBV output = NULL;
CBV tmp0 = NULL;
CBV tmp1 = NULL;
//saving some typing. BVPLUS does not use these variables. if the
//input BVPLUS has two nodes, then we want to avoid setting these
//variables.
if(1 == t.Degree() ){
tmp0 = BVConstEvaluator(t[0]).GetBVConst();
}else if(2 == t.Degree() && k != BVPLUS ) {
tmp0 = BVConstEvaluator(t[0]).GetBVConst();
tmp1 = BVConstEvaluator(t[1]).GetBVConst();
}
switch(k) {
case UNDEFINED:
case READ:
case WRITE:
case SYMBOL:
FatalError("BVConstEvaluator: term is not a constant-term",t);
break;
case BVCONST:
//FIXME Handle this special case better
OutputNode = t;
break;
case BVNEG:{
output = CONSTANTBV::BitVector_Create(inputwidth,true);
CONSTANTBV::Set_Complement(output,tmp0);
OutputNode = CreateBVConst(output,outputwidth);
break;
}
case BVSX: {
output = CONSTANTBV::BitVector_Create(inputwidth,true);
//unsigned * out0 = BVConstEvaluator(t[0]).GetBVConst();
unsigned t0_width = t[0].GetValueWidth();
if(inputwidth == t0_width) {
CONSTANTBV::BitVector_Copy(output, tmp0);
OutputNode = CreateBVConst(output, outputwidth);
}
else {
bool topbit_sign = (CONSTANTBV::BitVector_Sign(tmp0) < 0 );
if(topbit_sign){
CONSTANTBV::BitVector_Fill(output);
}
CONSTANTBV::BitVector_Interval_Copy(output, tmp0, 0, 0, t0_width);
OutputNode = CreateBVConst(output, outputwidth);
}
break;
}
case BVAND: {
output = CONSTANTBV::BitVector_Create(inputwidth,true);
CONSTANTBV::Set_Intersection(output,tmp0,tmp1);
OutputNode = CreateBVConst(output, outputwidth);
break;
}
case BVOR: {
output = CONSTANTBV::BitVector_Create(inputwidth,true);
CONSTANTBV::Set_Union(output,tmp0,tmp1);
OutputNode = CreateBVConst(output, outputwidth);
break;
}
case BVXOR: {
output = CONSTANTBV::BitVector_Create(inputwidth,true);
CONSTANTBV::Set_ExclusiveOr(output,tmp0,tmp1);
OutputNode = CreateBVConst(output, outputwidth);
break;
}
case BVSUB: {
output = CONSTANTBV::BitVector_Create(inputwidth,true);
bool carry = false;
CONSTANTBV::BitVector_sub(output,tmp0,tmp1,&carry);
OutputNode = CreateBVConst(output, outputwidth);
break;
}
case BVUMINUS: {
output = CONSTANTBV::BitVector_Create(inputwidth,true);
CONSTANTBV::BitVector_Negate(output, tmp0);
OutputNode = CreateBVConst(output, outputwidth);
break;
}
case BVEXTRACT: {
output = CONSTANTBV::BitVector_Create(inputwidth,true);
tmp0 = BVConstEvaluator(t[0]).GetBVConst();
unsigned int hi = GetUnsignedConst(BVConstEvaluator(t[1]));
unsigned int low = GetUnsignedConst(BVConstEvaluator(t[2]));
unsigned int len = hi-low+1;
CONSTANTBV::BitVector_Destroy(output);
//.........这里部分代码省略.........
示例4: if
bool
ASTNaryFunctionNode::isLog10() const
{
bool valid = false;
if (getType() == AST_FUNCTION_LOG)
{
// a log can have either one child that is not the logbase qualifier
// or two where teh first is the logbase of 10
if (getNumChildren() == 1)
{
ASTBase * base1 = ASTFunctionBase::getChild(0);
if (base1->isQualifier() == false)
{
valid = true;
}
}
else if (getNumChildren() == 2)
{
ASTBase * base1 = ASTFunctionBase::getChild(0);
ASTFunction* fun = dynamic_cast<ASTFunction*>(base1);
if (fun != NULL)
{
if (fun->getType() == AST_QUALIFIER_LOGBASE
&& fun->getNumChildren() == 1)
{
ASTBase *base2 = fun->getChild(0);
if (base2->getType() == AST_INTEGER)
{
ASTNumber *child = static_cast<ASTNumber*>(base2);
if (child->getInteger() == 10)
{
valid = true;
}
}
}
}
else
{
// here we are working the ASTNode so the casting
// is more difficult
ASTNode* newAST = dynamic_cast<ASTNode*>(base1);
if (newAST != NULL && newAST->getType() == AST_QUALIFIER_LOGBASE
&& newAST->getNumChildren() == 1 )
{
ASTNode* newAST1 = newAST->getChild(0);
if (newAST1->getType() == AST_INTEGER)
{
if (newAST1->getInteger() == 10)
{
valid = true;
}
}
}
else
{
if (newAST != NULL && newAST->getType() == AST_INTEGER)
{
if (newAST->getInteger() == 10)
{
valid = true;
}
}
}
}
}
}
return valid;
}
示例5: getInstantiation
int Submodel::convertTimeAndExtentWith(const ASTNode* tcf, const ASTNode* xcf, const ASTNode* klmod)
{
if (tcf==NULL && xcf==NULL) return LIBSBML_OPERATION_SUCCESS;
Model* model = getInstantiation();
if (model==NULL) {
//getInstantiation sets its own error messages.
return LIBSBML_OPERATION_FAILED;
}
ASTNode* tcftimes = NULL;
ASTNode* tcfdiv = NULL;
if (tcf != NULL) {
tcftimes = new ASTNode(AST_TIMES);
tcftimes->addChild(tcf->deepCopy());
tcfdiv = new ASTNode(AST_DIVIDE);
tcfdiv->addChild(tcf->deepCopy());
}
ASTNode* rxndivide = NULL;
if (klmod != NULL) {
rxndivide = new ASTNode(AST_DIVIDE);
ASTNode rxnref(AST_NAME);
rxndivide->addChild(rxnref.deepCopy());
rxndivide->addChild(klmod->deepCopy());
}
List* allelements = model->getAllElements();
for (unsigned int el=0; el<allelements->getSize(); el++) {
SBase* element = static_cast<SBase*>(allelements->get(el));
assert(element != NULL);
ASTNode* ast1 = NULL;
ASTNode* ast2 = NULL;
Constraint* constraint = NULL;
Delay* delay = NULL;
EventAssignment* ea = NULL;
InitialAssignment* ia = NULL;
KineticLaw* kl = NULL;
Priority* priority = NULL;
RateRule* rrule = NULL;
Rule* rule = NULL;
Submodel* submodel = NULL;
Trigger* trigger = NULL;
string cf = "";
//Reaction math will be converted below, in the bits with the kinetic law. But because of that, we need to handle references *to* the reaction: even if it has no kinetic law, the units have changed, and this needs to be reflected by the flattening routine.
if (rxndivide != NULL && element->getTypeCode()==SBML_REACTION && element->isSetId()) {
rxndivide->getChild(0)->setName(element->getId().c_str());
for (unsigned int sube=0; sube<allelements->getSize(); sube++) {
SBase* subelement = static_cast<SBase*>(allelements->get(sube));
subelement->replaceSIDWithFunction(element->getId(), rxndivide);
}
}
//Submodels need their timeConversionFactor and extentConversionFactor attributes converted. We're moving top-down, so all we need to do here is fix the conversion factor attributes themselves, pointing them to new parameters if need be.
if ((tcf !=NULL || xcf != NULL) && element->getTypeCode()==SBML_COMP_SUBMODEL) {
submodel = static_cast<Submodel*>(element);
if (tcf != NULL) {
if (submodel->isSetTimeConversionFactor()) {
createNewConversionFactor(cf, tcf, submodel->getTimeConversionFactor(), model);
submodel->setTimeConversionFactor(cf);
}
else {
submodel->setTimeConversionFactor(tcf->getName());
}
}
if (xcf != NULL) {
if (submodel->isSetExtentConversionFactor()) {
createNewConversionFactor(cf, xcf, submodel->getExtentConversionFactor(), model);
submodel->setExtentConversionFactor(cf);
}
else {
submodel->setExtentConversionFactor(xcf->getName());
}
}
}
if (tcf==NULL) {
if (klmod !=NULL && element->getTypeCode()==SBML_KINETIC_LAW) {
kl = static_cast<KineticLaw*>(element);
if (kl->isSetMath()) {
ast1 = new ASTNode(AST_TIMES);
ast1->addChild(klmod->deepCopy());
ast1->addChild(kl->getMath()->deepCopy());
kl->setMath(ast1);
delete ast1;
}
}
}
else {
// All math 'time' and 'delay' csymbols must still be converted.
// Also, several constructs are modified directly.
switch(element->getTypeCode()) {
//This would be a WHOLE LOT SIMPLER if there was a 'hasMath' class in libsbml. But even so, it would have to
// handle the kinetic laws, rate rules, and delays separately.
case SBML_KINETIC_LAW:
//Kinetic laws are multiplied by 'klmod'.
kl = static_cast<KineticLaw*>(element);
ast1 = kl->getMath()->deepCopy();
convertCSymbols(ast1, tcfdiv, tcftimes);
if (klmod !=NULL) {
kl = static_cast<KineticLaw*>(element);
if (kl->isSetMath()) {
ast2 = new ASTNode(AST_TIMES);
ast2->addChild(klmod->deepCopy());
ast2->addChild(ast1);
//.........这里部分代码省略.........
示例6: BVTypeCheck
/* FUNCTION: Typechecker for terms and formulas
*
* TypeChecker: Assumes that the immediate Children of the input
* ASTNode have been typechecked. This function is suitable in
* scenarios like where you are building the ASTNode Tree, and you
* typecheck as you go along. It is not suitable as a general
* typechecker.
*
* If this returns, this ALWAYS returns true. If there is an error it
* will call FatalError() and abort.
*/
bool BVTypeCheck(const ASTNode& n)
{
Kind k = n.GetKind();
//The children of bitvector terms are in turn bitvectors.
const ASTVec& v = n.GetChildren();
if (is_Term_kind(k))
{
switch (k)
{
case BVCONST:
if (BITVECTOR_TYPE != n.GetType())
FatalError("BVTypeCheck: The term t does not typecheck, where t = \n", n);
break;
case SYMBOL:
return true;
case ITE:
if (n.Degree() != 3)
FatalError("BVTypeCheck: should have exactly 3 args\n", n);
if (BOOLEAN_TYPE != n[0].GetType() || (n[1].GetType() != n[2].GetType()))
FatalError("BVTypeCheck: The term t does not typecheck, where t = \n", n);
if (n[1].GetValueWidth() != n[2].GetValueWidth())
FatalError("BVTypeCheck: length of THENbranch != length of ELSEbranch in the term t = \n", n);
if (n[1].GetIndexWidth() != n[2].GetIndexWidth())
FatalError("BVTypeCheck: length of THENbranch != length of ELSEbranch in the term t = \n", n);
break;
case READ:
if (n.GetChildren().size() !=2)
FatalError("2 params to read.");
if (n[0].GetIndexWidth() != n[1].GetValueWidth())
{
cerr << "Length of indexwidth of array: " << n[0] << " is : " << n[0].GetIndexWidth() << endl;
cerr << "Length of the actual index is: " << n[1] << " is : " << n[1].GetValueWidth() << endl;
FatalError("BVTypeCheck: length of indexwidth of array != length of actual index in the term t = \n", n);
}
if (ARRAY_TYPE != n[0].GetType())
FatalError("First parameter to read should be an array", n[0]);
if (BITVECTOR_TYPE != n[1].GetType())
FatalError("Second parameter to read should be a bitvector", n[1]);
break;
case WRITE:
if (n.GetChildren().size() !=3)
FatalError("3 params to write.");
if (n[0].GetIndexWidth() != n[1].GetValueWidth())
FatalError("BVTypeCheck: length of indexwidth of array != length of actual index in the term t = \n", n);
if (n[0].GetValueWidth() != n[2].GetValueWidth())
FatalError("BVTypeCheck: valuewidth of array != length of actual value in the term t = \n", n);
if (ARRAY_TYPE != n[0].GetType())
FatalError("First parameter to read should be an array", n[0]);
if (BITVECTOR_TYPE != n[1].GetType())
FatalError("Second parameter to read should be a bitvector", n[1]);
if (BITVECTOR_TYPE != n[2].GetType())
FatalError("Third parameter to read should be a bitvector", n[2]);
break;
case BVDIV:
case BVMOD:
case BVSUB:
case SBVDIV:
case SBVREM:
case SBVMOD:
case BVLEFTSHIFT:
case BVRIGHTSHIFT:
case BVSRSHIFT:
case BVVARSHIFT:
if (n.Degree() != 2)
FatalError("BVTypeCheck: should have exactly 2 args\n", n);
// run on.
case BVOR:
case BVAND:
case BVXOR:
case BVNOR:
case BVNAND:
case BVXNOR:
case BVPLUS:
case BVMULT:
{
if (!(v.size() >= 2))
FatalError("BVTypeCheck:bitwise Booleans and BV arith operators must have at least two arguments\n", n);
unsigned int width = n.GetValueWidth();
for (ASTVec::const_iterator it = v.begin(), itend = v.end(); it != itend; it++)
{
if (width != it->GetValueWidth())
{
cerr << "BVTypeCheck:Operands of bitwise-Booleans and BV arith operators must be of equal length\n";
cerr << n << endl;
//.........这里部分代码省略.........
示例7: assert
/********************************************************
* TransformFormula()
*
* Get rid of DIV/MODs, ARRAY read/writes, FOR constructs
********************************************************/
ASTNode ArrayTransformer::TransformFormula(const ASTNode& simpleForm)
{
assert(TransformMap != NULL);
const Kind k = simpleForm.GetKind();
if (!(is_Form_kind(k) && BOOLEAN_TYPE == simpleForm.GetType()))
{
//FIXME: "You have inputted a NON-formula"?
FatalError("TransformFormula:"\
"You have input a NON-formula", simpleForm);
}
ASTNodeMap::const_iterator iter;
if ((iter = TransformMap->find(simpleForm)) != TransformMap->end())
return iter->second;
ASTNode result;
switch (k)
{
case TRUE:
case FALSE:
{
result = simpleForm;
break;
}
case NOT:
{
ASTVec c;
c.push_back(TransformFormula(simpleForm[0]));
result = nf->CreateNode(NOT, c);
break;
}
case BOOLEXTRACT:
{
ASTVec c;
c.push_back(TransformTerm(simpleForm[0]));
c.push_back(simpleForm[1]);
result = nf->CreateNode(BOOLEXTRACT, c);
break;
}
case BVLT:
case BVLE:
case BVGT:
case BVGE:
case BVSLT:
case BVSLE:
case BVSGT:
case BVSGE:
{
ASTVec c;
c.push_back(TransformTerm(simpleForm[0]));
c.push_back(TransformTerm(simpleForm[1]));
result = nf->CreateNode(k, c);
break;
}
case EQ:
{
ASTNode term1 = TransformTerm(simpleForm[0]);
ASTNode term2 = TransformTerm(simpleForm[1]);
if (bm->UserFlags.optimize_flag)
result = simp->CreateSimplifiedEQ(term1, term2);
else
result = nf->CreateNode(EQ,term1, term2);
break;
}
case AND: // These could shortcut. Not sure if the extra effort is justified.
case OR:
case NAND:
case NOR:
case IFF:
case XOR:
case ITE:
case IMPLIES:
{
ASTVec vec;
vec.reserve(simpleForm.Degree());
for (ASTVec::const_iterator
it = simpleForm.begin(),
itend = simpleForm.end(); it != itend; it++)
{
vec.push_back(TransformFormula(*it));
}
result = nf->CreateNode(k, vec);
break;
}
case PARAMBOOL:
{
//If the parameteric boolean variable is of the form
//VAR(const), then convert it into a Boolean variable of the
//form "VAR(const)".
//
//Else if the paramteric boolean variable is of the form
//.........这里部分代码省略.........
示例8: if
/*
* Checks the MathML of the ASTnode
* is appropriate for the function being performed
*
* If an inconsistency is found, an error message is logged.
*/
void
NumericArgsMathCheck::checkMath (const Model& m, const ASTNode& node, const SBase & sb)
{
// does not apply in L3V2 for general consistency checking
// BUT we want to use it for telling a converter that this occurs in L3V2
if (this->mValidator.getCategory() == LIBSBML_CAT_MATHML_CONSISTENCY)
{
if (m.getLevel() == 3 && m.getVersion() > 1) return;
}
else
{
if (m.getLevel() != 3) return;
else if (m.getVersion() == 1) return;
}
ASTNodeType_t type = node.getType();
switch (type)
{
case AST_PLUS:
case AST_MINUS:
case AST_TIMES:
case AST_DIVIDE:
case AST_POWER:
case AST_FUNCTION_POWER:
case AST_FUNCTION_ROOT:
case AST_FUNCTION_ABS:
case AST_FUNCTION_EXP:
case AST_FUNCTION_LN:
case AST_FUNCTION_LOG:
case AST_FUNCTION_CEILING:
case AST_FUNCTION_FLOOR:
case AST_FUNCTION_FACTORIAL:
case AST_FUNCTION_COS:
case AST_FUNCTION_COT:
case AST_FUNCTION_CSC:
case AST_FUNCTION_SEC:
case AST_FUNCTION_SIN:
case AST_FUNCTION_TAN:
case AST_FUNCTION_COSH:
case AST_FUNCTION_COTH:
case AST_FUNCTION_CSCH:
case AST_FUNCTION_SECH:
case AST_FUNCTION_SINH:
case AST_FUNCTION_TANH:
case AST_FUNCTION_ARCCOSH:
case AST_FUNCTION_ARCCOTH:
case AST_FUNCTION_ARCCSCH:
case AST_FUNCTION_ARCSECH:
case AST_FUNCTION_ARCSINH:
case AST_FUNCTION_ARCTANH:
case AST_FUNCTION_ARCCOS:
case AST_FUNCTION_ARCCOT:
case AST_FUNCTION_ARCCSC:
case AST_FUNCTION_ARCSEC:
case AST_FUNCTION_ARCSIN:
case AST_FUNCTION_ARCTAN:
checkNumericArgs(m, node, sb);
break;
case AST_FUNCTION:
checkFunction(m, node, sb);
break;
default:
checkChildren(m, node, sb);
break;
}
}
示例9: dealWithL1Stoichiometry
void dealWithL1Stoichiometry(Model & m, bool l2)
{
unsigned int idCount = 0;
char newid[15];
std::string id;
for (unsigned int i = 0; i < m.getNumReactions(); i++)
{
Reaction *r = m.getReaction(i);
unsigned int j;
for (j = 0; j < r->getNumReactants(); j++)
{
SpeciesReference *sr = r->getReactant(j);
if (sr->getDenominator() != 1)
{
long stoich = static_cast<long>(sr->getStoichiometry());
int denom = sr->getDenominator();
ASTNode *node = new ASTNode();
node->setValue(stoich, denom);
if (l2 == true)
{
StoichiometryMath * sm = sr->createStoichiometryMath();
sm->setMath(node);
}
else
{
sprintf(newid, "speciesRefId_%u", idCount);
id.assign(newid);
idCount++;
sr->setId(id);
InitialAssignment * ar = m.createInitialAssignment();
ar->setSymbol(id);
ar->setMath(node);
sr->unsetStoichiometry();
}
}
}
for (j = 0; j < r->getNumProducts(); j++)
{
SpeciesReference *sr = r->getProduct(j);
if (sr->getDenominator() != 1)
{
long stoich = static_cast<long>(sr->getStoichiometry());
int denom = sr->getDenominator();
ASTNode *node = new ASTNode();
node->setValue(stoich, denom);
if (l2 == true)
{
StoichiometryMath * sm = sr->createStoichiometryMath();
sm->setMath(node);
}
else
{
sprintf(newid, "speciesRefId_%u", idCount);
id.assign(newid);
idCount++;
sr->setId(id);
InitialAssignment * ar = m.createInitialAssignment();
ar->setSymbol(id);
ar->setMath(node);
sr->unsetStoichiometry();
}
}
}
}
}
示例10: START_TEST
END_TEST
START_TEST(test_SBMLTransforms_evaluateAST)
{
double temp;
ASTNode * node = new ASTNode();
node->setValue((int)(2));
fail_unless(SBMLTransforms::evaluateASTNode(node) == 2);
node->setValue((double) (3.2));
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 3.2));
node->setValue((long)(1), (long)(4));
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 0.25));
node->setValue((double) (4.234), (int) (2));
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 423.4));
node->setType(AST_NAME_AVOGADRO);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 6.02214179e23));
node->setType(AST_NAME_TIME);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 0.0));
node->setType(AST_NAME);
fail_unless(isnan(SBMLTransforms::evaluateASTNode(node)));
node->setType(AST_CONSTANT_E);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), exp(1.0)));
node->setType(AST_CONSTANT_FALSE);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 0.0));
node->setType(AST_CONSTANT_PI);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 4.0*atan(1.0)));
node->setType(AST_CONSTANT_TRUE);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 1.0));
node = SBML_parseFormula("2.5 + 6.1");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 8.6));
node = SBML_parseFormula("-4.3");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), -4.3));
node = SBML_parseFormula("9.2-4.3");
temp = 9.2-4.3;
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), temp));
node = SBML_parseFormula("2*3");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 6));
node = SBML_parseFormula("1/5");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 0.2));
node = SBML_parseFormula("pow(2, 3)");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 8));
node = SBML_parseFormula("3^3");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 27));
node = SBML_parseFormula("abs(-9.456)");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 9.456));
node = SBML_parseFormula("ceil(9.456)");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 10));
node = SBML_parseFormula("exp(2.0)");
temp = exp(2.0);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), temp));
node = SBML_parseFormula("floor(2.04567)");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 2));
node = SBML_parseFormula("ln(2.0)");
temp = log(2.0);
//.........这里部分代码省略.........
示例11: Bench_Print1
string Bench_Print1(ostream& os, const ASTNode& n,
map<ASTNode, string>* alreadyOutput)
{
assert(((n.GetKind() == SYMBOL) || (n.GetKind() == BVCONST) ||
n.GetValueWidth() <= 1));
assert(!n.IsNull());
map<ASTNode, string>::iterator it;
if ((it = alreadyOutput->find(n)) != alreadyOutput->end())
return it->second;
if (n.GetKind() == BVCONST)
{
(*alreadyOutput)[n] = bvconstToString(n);
return (*alreadyOutput)[n];
}
if (n.GetKind() == SYMBOL)
{
(*alreadyOutput)[n] = symbolToString(n);
return (*alreadyOutput)[n];
}
if (n.GetKind() == TRUE)
{
return "vdd";
}
if (n.GetKind() == FALSE)
{
return "gnd";
}
if (n.GetKind() == BOOLEXTRACT)
{
assert(n[1].GetKind() == BVCONST);
std::stringstream nn;
nn << Bench_Print1(os, n[0], alreadyOutput) << "_"
<< Bench_Print1(os, n[1], alreadyOutput);
(*alreadyOutput)[n] = nn.str();
return (*alreadyOutput)[n];
}
std::stringstream nodeNameSS;
nodeNameSS << "n" << n.GetNodeNum();
string thisNode = nodeNameSS.str();
(*alreadyOutput)[n] = thisNode;
assert(n.Degree() > 0);
std::stringstream output;
// The bench format doesn't accept propositional ITEs.
if (n.GetKind() == ITE)
{
assert(n.Degree() == 3);
string p = Bench_Print1(os, n[0], alreadyOutput);
string p1 = Bench_Print1(os, n[1], alreadyOutput);
string p2 = Bench_Print1(os, n[2], alreadyOutput);
os << thisNode << "_1 = AND(" << p << "," << p1 << ")" << endl;
os << thisNode << "_2"
<< " = NOT(" << p << ")," << endl;
os << thisNode << "_3"
<< " = AND(" << thisNode << "_2"
<< "," << p2 << ")" << endl;
os << thisNode << "="
<< "OR(," << thisNode << "_1"
<< "," << thisNode << "_3)" << endl;
}
else
{
if (n.Degree() > 2)
{
assert(n.GetKind() == AND || n.GetKind() == XOR ||
n.GetKind() == OR); // must be associative.
std::deque<string> names;
for (unsigned i = 0; i < n.Degree(); i++)
names.push_back(Bench_Print1(os, n[i], alreadyOutput));
int id = 0;
while (names.size() > 2)
{
string a = names.front();
names.pop_front();
string b = names.front();
names.pop_front();
std::stringstream thisName;
thisName << thisNode << "___" << id++;
output << thisName.str() << "=" << name(n.GetKind()) << "(" << a << ","
<< b << ")" << endl;
names.push_back(thisName.str());
}
//.........这里部分代码省略.........
示例12: performStep
bool CodeGeneratorVisitor::performStep(ASTNode& node)
{
node.accept(*this);
return true;
}
示例13: logUndefined
/*
* Checks that all variables referenced in FunctionDefinition bodies are
* bound variables (function arguments).
*/
void
FunctionDefinitionVars::check_ (const Model& m, const FunctionDefinition& fd)
{
if ( fd.getLevel() == 1 ) return;
if ( !fd.isSetMath() ) return;
if ( fd.getBody() == NULL ) return;
//if ( fd.getNumArguments() == 0 ) return;
List* variables = fd.getBody()->getListOfNodes( ASTNode_isName );
for (unsigned int n = 0; n < variables->getSize(); ++n)
{
ASTNode* node = static_cast<ASTNode*>( variables->get(n) );
string name = node->getName() ? node->getName() : "";
if ( fd.getArgument(name) == NULL )
{
/* if this is the csymbol time - technically it is allowed
* in L2v1 and L2v2
*/
if (node->getType() == AST_NAME_TIME)
{
if (fd.getLevel() > 2
|| (fd.getLevel() == 2 && fd.getVersion() > 2))
{
logUndefined(fd, name);
}
}
else
{
logUndefined(fd, name);
}
}
}
if ((m.getLevel() == 2 && m.getVersion() == 5)
|| (m.getLevel() == 3 && m.getVersion() > 1))
{ // check we dont use delay csymbol
delete variables;
variables = fd.getBody()->getListOfNodes( ASTNode_isFunction );
for (unsigned int n = 0; n < variables->getSize(); ++n)
{
ASTNode* node = static_cast<ASTNode*>( variables->get(n) );
if (node->getType() == AST_FUNCTION_DELAY)
{
logUndefined(fd, node->getName());
}
}
}
//Check we don't use a function defined in a plugin (like rateOf)
delete variables;
variables = fd.getBody()->getListOfNodes(ASTNode_isFunction);
for (unsigned int n = 0; n < variables->getSize(); ++n)
{
ASTNode* node = static_cast<ASTNode*>(variables->get(n));
const ASTBasePlugin* plugin = node->getASTPlugin(node->getType());
if (plugin != NULL)
{
if (plugin->allowedInFunctionDefinition(node->getType()) == 0)
{
logUndefined(fd, node->getName());
}
}
}
delete variables;
}
示例14: logImplicitReference
void
AssignmentCycles::checkForImplicitCompartmentReference(const Model& m)
{
mIdMap.clear();
unsigned int i, ns;
std::string id;
for (i = 0; i < m.getNumInitialAssignments(); i++)
{
if (m.getInitialAssignment(i)->isSetMath())
{
id = m.getInitialAssignment(i)->getSymbol();
if (m.getCompartment(id)
&& m.getCompartment(id)->getSpatialDimensions() > 0)
{
List* variables = m.getInitialAssignment(i)->getMath()
->getListOfNodes( ASTNode_isName );
for (ns = 0; ns < variables->getSize(); ns++)
{
ASTNode* node = static_cast<ASTNode*>( variables->get(ns) );
string name = node->getName() ? node->getName() : "";
if (!name.empty() && !alreadyExistsInMap(mIdMap, pair<const std::string, std::string>(id, name)))
mIdMap.insert(pair<const std::string, std::string>(id, name));
}
delete variables;
}
}
}
for (i = 0; i < m.getNumRules(); i++)
{
if (m.getRule(i)->isSetMath() && m.getRule(i)->isAssignment())
{
id = m.getRule(i)->getVariable();
if (m.getCompartment(id)
&& m.getCompartment(id)->getSpatialDimensions() > 0)
{
List* variables = m.getRule(i)->getMath()->getListOfNodes( ASTNode_isName );
for (ns = 0; ns < variables->getSize(); ns++)
{
ASTNode* node = static_cast<ASTNode*>( variables->get(ns) );
string name = node->getName() ? node->getName() : "";
if (!name.empty() && !alreadyExistsInMap(mIdMap, pair<const std::string, std::string>(id, name)))
mIdMap.insert(pair<const std::string, std::string>(id, name));
}
delete variables;
}
}
}
IdIter it;
IdRange range;
for (i = 0; i < m.getNumCompartments(); i++)
{
std::string id = m.getCompartment(i)->getId();
range = mIdMap.equal_range(id);
for (it = range.first; it != range.second; it++)
{
const Species *s = m.getSpecies((*it).second);
if (s && s->getCompartment() == id
&& s->getHasOnlySubstanceUnits() == false)
{
logImplicitReference(m, id, s);
}
}
}
}
示例15: getSBMLDocument
/** @cond doxygenLibsbmlInternal */
int
Replacing::updateIDs(SBase* oldnames, SBase* newnames)
{
int ret = LIBSBML_OPERATION_SUCCESS;
SBMLDocument* doc = getSBMLDocument();
if (oldnames->isSetId() && !newnames->isSetId()) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the '" + oldnames->getId() + "' element's replacement does not have an ID set.";
doc->getErrorLog()->logPackageError("comp", CompMustReplaceIDs, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
if (oldnames->isSetMetaId() && !newnames->isSetMetaId()) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the replacement of the element with metaid '" + oldnames->getMetaId() + "' does not have a metaid.";
doc->getErrorLog()->logPackageError("comp", CompMustReplaceMetaIDs, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
//LS DEBUG Somehow we need to check identifiers from other packages here (like spatial id's). How, exactly, is anyone's guess.
Model* replacedmod = const_cast<Model*>(CompBase::getParentModel(oldnames));
KineticLaw* replacedkl;
ASTNode newkl;
if (replacedmod==NULL) {
if (doc) {
string error = "Unable to transform IDs in Replacing::updateIDs during replacement: the replacement of '" + oldnames->getId() + "' does not have a valid model.";
doc->getErrorLog()->logPackageError("comp", CompModelFlatteningFailed, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
}
return LIBSBML_INVALID_OBJECT;
}
List* allElements = replacedmod->getAllElements();
string oldid = oldnames->getId();
string newid = newnames->getId();
if (!oldid.empty()) {
switch(oldnames->getTypeCode()) {
case SBML_UNIT_DEFINITION:
replacedmod->renameUnitSIdRefs(oldid, newid);
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameUnitSIdRefs(oldid, newid);
}
break;
case SBML_LOCAL_PARAMETER:
replacedkl = static_cast<KineticLaw*>(oldnames->getAncestorOfType(SBML_KINETIC_LAW));
if (replacedkl->isSetMath()) {
newkl = *replacedkl->getMath();
newkl.renameSIdRefs(oldid, newid);
replacedkl->setMath(&newkl);
}
break;
case SBML_COMP_PORT:
break;
//LS DEBUG And here is where we would need some sort of way to check if the id wasn't an SId for some objects.
default:
replacedmod->renameSIdRefs(oldnames->getId(), newnames->getId());
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameSIdRefs(oldid, newid);
}
}
}
string oldmetaid = oldnames->getMetaId();
string newmetaid = newnames->getMetaId();
if (oldnames->isSetMetaId()) {
replacedmod->renameMetaIdRefs(oldmetaid, newmetaid);
for (unsigned int e=0; e<allElements->getSize(); e++) {
SBase* element = static_cast<SBase*>(allElements->get(e));
element->renameMetaIdRefs(oldmetaid, newmetaid);
}
}
//LS DEBUG And here is where we would need some sort of way to check for ids that were not 'id' or 'metaid'.
delete allElements;
return ret;
}