本文整理汇总了C++中ASTNode::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode::GetType方法的具体用法?C++ ASTNode::GetType怎么用?C++ ASTNode::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTNode
的用法示例。
在下文中一共展示了ASTNode::GetType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
// If the bits are totally fixed, then return a new matching ASTNode.
ASTNode
bitsToNode(const ASTNode& node, const FixedBits& bits)
{
ASTNode result;
STPMgr & beev = *node.GetSTPMgr();
assert (bits.isTotallyFixed());
assert (!node.isConstant()); // Peformance. Shouldn't waste time calling it on constants.
if (node.GetType() == BOOLEAN_TYPE)
{
if (bits.getValue(0))
{
result = beev.CreateNode(TRUE);
}
else
{
result = beev.CreateNode(FALSE);
}
}
else if (node.GetType() == BITVECTOR_TYPE)
{
result = beev.CreateBVConst(bits.GetBVConst(), node.GetValueWidth());
}
else
FatalError("sadf234s");
assert(result.isConstant());
return result;
}
示例2: topLevel
// Build the polarities, then iterate through fixing them.
bool FindPureLiterals::topLevel(ASTNode& n, Simplifier* simplifier,
STPMgr* stpMgr)
{
stpMgr->GetRunTimes()->start(RunTimes::PureLiterals);
build(n, truePolarity);
bool changed = false;
map<ASTNode, polarity_type>::const_iterator it = nodeToPolarity.begin();
while (it != nodeToPolarity.end())
{
const ASTNode& n = it->first;
const polarity_type polarity = it->second;
if (n.GetType() == BOOLEAN_TYPE && n.GetKind() == SYMBOL &&
polarity != bothPolarity)
{
if (polarity == truePolarity)
simplifier->UpdateSubstitutionMap(n, stpMgr->ASTTrue);
else
{
assert(polarity == falsePolarity);
simplifier->UpdateSubstitutionMap(n, stpMgr->ASTFalse);
}
changed = true;
}
it++;
}
stpMgr->GetRunTimes()->stop(RunTimes::PureLiterals);
return changed;
}
示例3: containsArrayOps
bool containsArrayOps(const ASTNode& n, ASTNodeSet& visited)
{
if (visited.find(n) != visited.end())
return false;
if (n.GetType() == ARRAY_TYPE)
return true;
for (int i =0; i < n.Degree();i++)
if (containsArrayOps(n[i],visited))
return true;
visited.insert(n);
return false;
}
示例4: assert
// Propagates. No writing in of values. Doesn't assume the top is true.
ConstantBitPropagation::ConstantBitPropagation(BEEV::Simplifier* _sm, NodeFactory* _nf,const ASTNode & top)
{
assert (BOOLEAN_TYPE == top.GetType());
assert (top.GetSTPMgr()->UserFlags.bitConstantProp_flag);
status = NO_CHANGE;
simplifier = _sm;
nf = _nf;
fixedMap = new NodeToFixedBitsMap(1000); // better to use the function that returns the number of nodes.. whatever that is.
workList = new WorkList(top);
dependents = new Dependencies(top); // List of the parents of a node.
msm = new MultiplicationStatsMap();
// not fixing the topnode.
propagate();
if (debug_cBitProp_messages)
{
cerr << "status:" << status <<endl;
cerr << "ended propagation" << endl;
printNodeWithFixings();
}
// is there are good reason to clear out some of them??
#if 0
// remove constants, and things with nothing fixed.
NodeToFixedBitsMap::NodeToFixedBitsMapType::iterator it =
fixedMap->map->begin();
NodeToFixedBitsMap::NodeToFixedBitsMapType::iterator it_end =
fixedMap->map->end();
while (it != it_end)
{
// No constants, nothing completely unfixed.
if ( (it->second)->countFixed() == 0 )
{
delete it->second;
// making this a reference causes reading from freed memory.
const ASTNode n = it->first;
it++;
fixedMap->map->erase(n);
}
else
it++;
}
#endif
topFixed = false;
}
示例5: 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;
//.........这里部分代码省略.........
示例6: BVTypeCheck_nonterm_kind
bool BVTypeCheck_nonterm_kind(const ASTNode& n, const Kind& k)
{
// The children of bitvector terms are in turn bitvectors.
const ASTVec& v = n.GetChildren();
if (!(is_Form_kind(k) && BOOLEAN_TYPE == n.GetType()))
FatalError("BVTypeCheck: not a formula:", n);
switch (k)
{
case TRUE:
case FALSE:
case SYMBOL:
return true;
case BOOLEXTRACT:
checkChildrenAreBV(v, n);
if (n.Degree() != 2)
FatalError("BVTypeCheck: should have exactly 2 args\n", n);
if (!(BVCONST == n[1].GetKind()))
FatalError("BVTypeCheck: index should be BVCONST\n", n);
if (n[1].GetUnsignedConst() >= n[0].GetValueWidth())
{
FatalError(
"BVTypeCheck: index is greater or equal to the bitwidth.\n", n);
}
break;
case PARAMBOOL:
if (2 != n.Degree())
{
FatalError(
"BVTypeCheck: PARAMBOOL formula can have exactly two childNodes",
n);
}
break;
case EQ:
if (n.Degree() != 2)
FatalError("BVTypeCheck: should have exactly 2 args\n", n);
if (!(n[0].GetValueWidth() == n[1].GetValueWidth() &&
n[0].GetIndexWidth() == n[1].GetIndexWidth()))
{
cerr << "valuewidth of lhs of EQ: " << n[0].GetValueWidth() << endl;
cerr << "valuewidth of rhs of EQ: " << n[1].GetValueWidth() << endl;
cerr << "indexwidth of lhs of EQ: " << n[0].GetIndexWidth() << endl;
cerr << "indexwidth of rhs of EQ: " << n[1].GetIndexWidth() << endl;
FatalError(
"BVTypeCheck: terms in atomic formulas must be of equal length",
n);
}
break;
case BVLT:
case BVLE:
case BVGT:
case BVGE:
case BVSLT:
case BVSLE:
case BVSGT:
case BVSGE:
if (n.Degree() != 2)
FatalError("BVTypeCheck: should have exactly 2 args\n", n);
if (BITVECTOR_TYPE != n[0].GetType() &&
BITVECTOR_TYPE != n[1].GetType())
{
FatalError("BVTypeCheck: terms in atomic formulas must be bitvectors"
,n);
}
if (n[0].GetValueWidth() != n[1].GetValueWidth())
FatalError(
"BVTypeCheck: terms in atomic formulas must be of equal length",
n);
if (n[0].GetIndexWidth() != n[1].GetIndexWidth())
{
FatalError(
"BVTypeCheck: terms in atomic formulas must be of equal length",
n);
}
break;
case NOT:
if (1 != n.Degree())
{
FatalError("BVTypeCheck: NOT formula can have exactly one childNode",
n);
}
break;
case AND:
case OR:
case XOR:
case NAND:
case NOR:
if (2 > n.Degree())
{
FatalError("BVTypeCheck: AND/OR/XOR/NAND/NOR: must have atleast 2 "
"ChildNodes",
//.........这里部分代码省略.........
示例7: BVTypeCheck_term_kind
bool BVTypeCheck_term_kind(const ASTNode& n, const Kind& k)
{
// The children of bitvector terms are in turn bitvectors.
const ASTVec& v = n.GetChildren();
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);
//.........这里部分代码省略.........
示例8: propagate
// This doesn't rewrite changes through properly so needs to have a substitution
// applied to its output.
ASTNode PropagateEqualities::propagate(const ASTNode& a, ArrayTransformer* at)
{
ASTNode output;
// if the variable has been solved for, then simply return it
if (simp->InsideSubstitutionMap(a, output))
return output;
if (!alreadyVisited.insert(a.GetNodeNum()).second)
{
return a;
}
output = a;
// traverse a and populate the SubstitutionMap
const Kind k = a.GetKind();
if (SYMBOL == k && BOOLEAN_TYPE == a.GetType())
{
bool updated = simp->UpdateSubstitutionMap(a, ASTTrue);
output = updated ? ASTTrue : a;
}
else if (NOT == k)
{
bool updated = searchXOR(a[0], ASTFalse);
output = updated ? ASTTrue : a;
}
else if (IFF == k || EQ == k)
{
const ASTVec& c = a.GetChildren();
if (c[0] == c[1])
return ASTTrue;
bool updated = simp->UpdateSubstitutionMap(c[0], c[1]);
if (updated)
{
// fill the arrayname readindices vector if e0 is a
// READ(Arr,index) and index is a BVCONST
int to;
if ((to = TermOrder(c[0], c[1])) == 1 && c[0].GetKind() == READ)
at->FillUp_ArrReadIndex_Vec(c[0], c[1]);
else if (to == -1 && c[1].GetKind() == READ)
at->FillUp_ArrReadIndex_Vec(c[1], c[0]);
}
if (!updated)
updated = searchTerm(c[0], c[1]);
if (!updated)
updated = searchTerm(c[1], c[0]);
output = updated ? ASTTrue : a;
}
else if (XOR == k)
{
bool updated = searchXOR(a, ASTTrue);
output = updated ? ASTTrue : a;
if (updated)
return output;
// The below block should be subsumed by the searchXOR function which
// generalises it.
// So the below block should never do anything..
#ifndef NDEBUG
if (a.Degree() != 2)
return output;
int to = TermOrder(a[0], a[1]);
if (0 == to)
{
if (a[0].GetKind() == NOT && a[0][0].GetKind() == EQ &&
a[0][0][0].GetValueWidth() == 1 && a[0][0][1].GetKind() == SYMBOL)
{
// (XOR (NOT(= (1 v))) ... )
const ASTNode& symbol = a[0][0][1];
const ASTNode newN = nf->CreateTerm(
ITE, 1, a[1], a[0][0][0], nf->CreateTerm(BVNEG, 1, a[0][0][0]));
if (simp->UpdateSolverMap(symbol, newN))
{
assert(false);
output = ASTTrue;
}
}
else if (a[1].GetKind() == NOT && a[1][0].GetKind() == EQ &&
a[1][0][0].GetValueWidth() == 1 &&
a[1][0][1].GetKind() == SYMBOL)
{
const ASTNode& symbol = a[1][0][1];
const ASTNode newN = nf->CreateTerm(
ITE, 1, a[0], a[1][0][0], nf->CreateTerm(BVNEG, 1, a[1][0][0]));
if (simp->UpdateSolverMap(symbol, newN))
{
assert(false);
output = ASTTrue;
//.........这里部分代码省略.........
示例9: TransformArrayRead
//.........这里部分代码省略.........
result = simp->CreateSimplifiedTermITE(cond, it2->second.ite, result);
}
}
else
{
// Full Array transform if we're not doing read refinement.
// list of array-read indices corresponding to arrName, seen while
// traversing the AST tree. we need this list to construct the ITEs
vector<std::pair<ASTNode, ASTNode>> p = ack_pair[arrName];
vector<std::pair<ASTNode, ASTNode>>::const_reverse_iterator it2 =
p.rbegin();
vector<std::pair<ASTNode, ASTNode>>::const_reverse_iterator it2end =
p.rend();
for (; it2 != it2end; it2++)
{
ASTNode cond = simp->CreateSimplifiedEQ(readIndex, it2->first);
if (ASTFalse == cond)
continue;
if (ASTTrue == cond)
{
result = it2->second;
break;
}
result = simp->CreateSimplifiedTermITE(cond, it2->second, result);
}
ack_pair[arrName].push_back(make_pair(readIndex, CurrentSymbol));
}
assert(arrName.GetType() == ARRAY_TYPE);
arrayToIndexToRead[arrName].insert(
make_pair(readIndex, ArrayRead(result, CurrentSymbol)));
break;
}
case WRITE:
{
/* The input to this case is: READ((WRITE A i val) j)
*
* The output of this case is: ITE( (= i j) val (READ A j))
*/
/* 1. arrName or term[0] is infact a WRITE(A,i,val) expression
*
* 2. term[1] is the read-index j
*
* 3. arrName[0] is the new arrName i.e. A. A can be either a
SYMBOL or a nested WRITE. no other possibility
*
* 4. arrName[1] is the WRITE index i.e. i
*
* 5. arrName[2] is the WRITE value i.e. val (val can inturn
* be an array read)
*/
ASTNode writeIndex = TransformTerm(arrName[1]);
ASTNode writeVal = TransformTerm(arrName[2]);
if (ARRAY_TYPE != arrName[0].GetType())
FatalError("TransformArray: "
"An array write is being attempted on a non-array:",
term);
示例10: TransformFormula
/********************************************************
* 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)".
//.........这里部分代码省略.........