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


C++ ASTNode::isConstant方法代码示例

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


在下文中一共展示了ASTNode::isConstant方法的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;
    }
开发者ID:bengheng,项目名称:Expose,代码行数:31,代码来源:ConstantBitPropagation.cpp

示例2: sort

// Adds to the dependency graph that n0 depends on the variables in n1.
// It's not the transitive closure of the dependencies. Just the variables in the expression "n1".
// This is only needed as long as all the substitution rules haven't been written through.
  void
  SubstitutionMap::buildDepends(const ASTNode& n0, const ASTNode& n1)
  {
    if (n0.GetKind() != SYMBOL)
      return;

    if (n1.isConstant())
      return;

    vector<Symbols*> av;
    vars.VarSeenInTerm(vars.getSymbol(n1), rhs_visited, rhs, av);

    sort(av.begin(), av.end());
    for (int i = 0; i < av.size(); i++)
      {
      if (i != 0 && av[i] == av[i - 1])
        continue; // Treat it like a set of Symbol* in effect.

      ASTNodeSet* sym = (vars.TermsAlreadySeenMap.find(av[i])->second);
      if (rhsAlreadyAdded.find(sym) != rhsAlreadyAdded.end())
        continue;
      rhsAlreadyAdded.insert(sym);

      //cout << loopCount++ << " ";
      //cout << "initial" << rhs.size() << " Adding: " <<sym->size();
      rhs.insert(sym->begin(), sym->end());
      //cout << "final:" << rhs.size();
      //cout << "added:" << sym << endl;

      }

    assert(dependsOn.find(n0) == dependsOn.end());
    dependsOn.insert(make_pair(n0, vars.getSymbol(n1)));
  }
开发者ID:Sjlver,项目名称:stp,代码行数:37,代码来源:SubstitutionMap.cpp

示例3: VarSeenInTerm

bool VariablesInExpression::VarSeenInTerm(const ASTNode& var,
		const ASTNode& term) {
	// This only returns true if we are searching for variables that aren't arrays.
	assert(var.GetKind() == SYMBOL && var.GetIndexWidth() == 0);
	if (term.isConstant())
		return false;

	getSymbol(term);

	SymbolPtrSet visited;
	ASTNodeSet *symbols = new ASTNodeSet();
	vector<Symbols*> av;
	VarSeenInTerm(symbol_graph[term.GetNodeNum()], visited, *symbols, av);

	bool result = (symbols->count(var) != 0);

	//cerr << "visited:" << visited.size() << endl;
	//cerr << "av:" << av.size() << endl;
	//cerr << "Term is const" << term.isConstant() << endl;


	if (visited.size() > 250) // No use caching it, unless we've done some work.
	{
		sort(av.begin(), av.end());

		//cout << "===" << endl;
		for (size_t i = 0; i < av.size(); i++) {
			if (i!=0 && av[i] == av[i-1])
				continue;

			const ASTNodeSet& sym = *TermsAlreadySeenMap.find(av[i])->second;
			//cout << "set: " << i << " " << sym.size() << endl;
			symbols->insert(sym.begin(), sym.end());
		}
		TermsAlreadySeenMap.insert(make_pair(symbol_graph[term.GetNodeNum()], symbols));
		//cout << "finish" << symbols->size() << endl;
		//cout << "===" << endl;
		result = (symbols->count(var) != 0);
	} else {
		const int size = av.size();
		for (int i = 0; i < size; i++) {
			if (result)
				break;
			const ASTNodeSet& sym = *TermsAlreadySeenMap.find(av[i])->second;
			result |= (sym.find(var) != sym.end());
		}
		delete symbols;
	}
	return result;
}
开发者ID:AmesianX,项目名称:stp,代码行数:50,代码来源:VariablesInExpression.cpp

示例4: loops

// If n0 is replaced by n1 in the substitution map. Will it cause a loop?
// i.e. will the dependency graph be an acyclic graph still.
// For example, if we have x = F(y,z,w), it would make the substitutionMap loop
// if there's already z = F(x).
bool SubstitutionMap::loops(const ASTNode& n0, const ASTNode& n1)
{
  if (n0.GetKind() != SYMBOL)
    return false; // sometimes this function is called with constants on the
                  // lhs.

  if (n1.isConstant())
    return false; // constants contain no variables. Can't loop.

  // We are adding an edge FROM n0, so unless there is already an edge TO n0,
  // there is no change it can loop. Unless adding this would add a TO and FROM
  // edge.
  if (rhs.find(n0) == rhs.end())
  {
    return vars.VarSeenInTerm(n0, n1);
  }

  if (n1.GetKind() == SYMBOL && dependsOn.find(n1) == dependsOn.end())
    return false; // The rhs is a symbol and doesn't appear.

  if (debug_substn)
    cout << loopCount++ << endl;

  bool destruct = true;
  ASTNodeSet* dependN = vars.SetofVarsSeenInTerm(n1, destruct);

  if (debug_substn)
  {
    cout << n0 << " "
         << n1.GetNodeNum(); //<< " Expression size:" << bm->NodeSize(n1,true);
    cout << "Variables in expression: " << dependN->size() << endl;
  }

  set<ASTNode> depend(dependN->begin(), dependN->end());

  if (destruct)
    delete dependN;

  set<ASTNode> visited;
  loops_helper(depend, visited);

  bool loops = visited.find(n0) != visited.end();

  if (debug_substn)
    cout << "Visited:" << visited.size() << "Loops:" << loops << endl;

  return (loops);
}
开发者ID:MartinNowack,项目名称:stp,代码行数:52,代码来源:SubstitutionMap.cpp

示例5: getSatVariables

void getSatVariables(const ASTNode& a, vector<unsigned>& v_a,
                     SATSolver& SatSolver, ToSATBase::ASTNodeToSATVar& satVar)
{
  ToSATBase::ASTNodeToSATVar::iterator it = satVar.find(a);
  if (it != satVar.end())
    v_a = it->second;
  else if (!a.isConstant())
  {
    assert(a.GetKind() == SYMBOL);
    // It was ommitted from the initial problem, so assign it freshly.
    for (unsigned i = 0; i < a.GetValueWidth(); i++)
    {
      uint32_t v = SatSolver.newVar();
      // We probably don't want the variable eliminated.
      SatSolver.setFrozen(v);
      v_a.push_back(v);
    }
    satVar.insert(make_pair(a, v_a));
  }
}
开发者ID:cambridgehackers,项目名称:stp,代码行数:20,代码来源:AbstractionRefinement.cpp

示例6: build

void FindPureLiterals::build(const ASTNode& n, polarity_type polarity)
{
  if (n.isConstant())
    return;

  map<ASTNode, polarity_type>::iterator it = nodeToPolarity.find(n);
  if (it != nodeToPolarity.end())
  {
    int lookupPolarity = it->second;
    if ((polarity | lookupPolarity) == lookupPolarity)
      return; // already traversed.

    it->second |= polarity;
  }
  else
  {
    nodeToPolarity.insert(std::make_pair(n, polarity));
  }
  const Kind k = n.GetKind();
  switch (k)
  {
    case AND:
    case OR:
      for (size_t i = 0; i < n.Degree(); i++)
        build(n[i], polarity);
      break;

    case NOT:
      polarity = swap(polarity);
      build(n[0], polarity);
      break;

    default:
      polarity = bothPolarity; // both
      for (size_t i = 0; i < n.Degree(); i++)
        build(n[i], polarity);
      break;
  }
}
开发者ID:stp,项目名称:stp,代码行数:39,代码来源:FindPureLiterals.cpp

示例7: if


//.........这里部分代码省略.........
              }
            else if (kind == BVGT || kind == BVGE)
              {
                biggestNumber = bm.CreateMaxConst(width);
                smallestNumber =  bm.CreateZeroConst(width);
              }
            else
              FatalError("[email protected]");


            ASTNode c1,c2;
            if (kind == BVSGT || kind == BVGT)
              {
                c1= biggestNumber;
                c2 = smallestNumber;
              }
            else if (kind == BVSGE || kind == BVGE)
              {
                c1= smallestNumber;
                c2 = biggestNumber;
              }
            else
              FatalError("[email protected]");

            if (mutable_children[0]->isUnconstrained() && mutable_children[1]->isUnconstrained())
              {
                ASTNode v =replaceParentWithFresh(muteParent, variable_array);

                ASTNode lhs = nf->CreateTerm(ITE, width, v, bm.CreateOneConst(width), bm.CreateZeroConst(width));
                ASTNode rhs = nf->CreateTerm(ITE, width, v, bm.CreateZeroConst(width), bm.CreateOneConst(width));
                replace(children[0], lhs);
                replace(children[1], rhs);
              }
            else if (children[0] == var && children[1].isConstant())
              {
                if (children[1] == c1)
                  continue; // always false. Or always false.

                ASTNode v =replaceParentWithFresh(muteParent, variable_array);

                ASTNode rhs = nf->CreateTerm(ITE, width, v,biggestNumber, smallestNumber);
                replace(var, rhs);
              }
            else if (children[1] == var && children[0].isConstant())
              {
                if (children[0] == c2)
                  continue;  // always false. Or always false.

                ASTNode v =replaceParentWithFresh(muteParent, variable_array);

                ASTNode rhs = nf->CreateTerm(ITE, width, v, smallestNumber, biggestNumber);
                replace(var, rhs);
              }
            else // One side is a variable. The other is anything.
              {
            	 bool varOnLHS = (var == children[0]);

                // All the ASTNode vars need to map to their existing MutableASTNodes. So we collect all the variables
                vector<MutableASTNode*> vars;
                set<MutableASTNode*> visited;
                muteOther->getAllVariablesRecursively(vars, visited);
                visited.clear();

                map<ASTNode, MutableASTNode *> create;
                for (vector<MutableASTNode*>::iterator it = vars.begin(); it != vars.end();it++)
                  create.insert(make_pair((*it)->n, *it));
开发者ID:arsenm,项目名称:stp,代码行数:67,代码来源:RemoveUnconstrained.cpp

示例8: getEquals

// This function adds the clauses to constrain that "a" and "b" equal a fresh
// variable
// (which it returns).
// Because it's used to create array axionms (a=b)-> (c=d), it can be
// used to only add one of the two polarities.
Minisat::Var getEquals(SATSolver& SatSolver, const ASTNode& a, const ASTNode& b,
                       ToSATBase::ASTNodeToSATVar& satVar,
                       Polarity polary = BOTH)
{
  const unsigned width = a.GetValueWidth();
  assert(width == b.GetValueWidth());
  assert(!a.isConstant() || !b.isConstant());

  vector<unsigned> v_a;
  vector<unsigned> v_b;

  getSatVariables(a, v_a, SatSolver, satVar);
  getSatVariables(b, v_b, SatSolver, satVar);

  // The only time v_a or v_b will be empty is if "a" resp. "b" is a constant.

  if (v_a.size() == width && v_b.size() == width)
  {
    SATSolver::vec_literals all;
    const int result = SatSolver.newVar();

    for (unsigned i = 0; i < width; i++)
    {
      SATSolver::vec_literals s;

      if (polary != RIGHT_ONLY)
      {
        int nv0 = SatSolver.newVar();
        s.push(SATSolver::mkLit(v_a[i], true));
        s.push(SATSolver::mkLit(v_b[i], true));
        s.push(SATSolver::mkLit(nv0, false));
        SatSolver.addClause(s);
        s.clear();

        s.push(SATSolver::mkLit(v_a[i], false));
        s.push(SATSolver::mkLit(v_b[i], false));
        s.push(SATSolver::mkLit(nv0, false));
        SatSolver.addClause(s);
        s.clear();

        all.push(SATSolver::mkLit(nv0, true));
      }

      if (polary != LEFT_ONLY)
      {
        s.push(SATSolver::mkLit(v_a[i], true));
        s.push(SATSolver::mkLit(v_b[i], false));
        s.push(SATSolver::mkLit(result, true));
        SatSolver.addClause(s);
        s.clear();

        s.push(SATSolver::mkLit(v_a[i], false));
        s.push(SATSolver::mkLit(v_b[i], true));
        s.push(SATSolver::mkLit(result, true));
        SatSolver.addClause(s);
        s.clear();
      }
    }
    if (all.size() > 0)
    {
      all.push(SATSolver::mkLit(result, false));
      SatSolver.addClause(all);
    }
    return result;
  }
  else if ((v_a.size() == 0) ^ (v_b.size() == 0))
  {
    ASTNode constant = a.isConstant() ? a : b;
    vector<unsigned> vec = v_a.size() == 0 ? v_b : v_a;
    assert(constant.isConstant());
    assert(vec.size() == width);

    SATSolver::vec_literals all;
    const int result = SatSolver.newVar();
    all.push(SATSolver::mkLit(result, false));

    CBV v = constant.GetBVConst();
    for (unsigned i = 0; i < width; i++)
    {
      if (polary != RIGHT_ONLY)
      {
        if (CONSTANTBV::BitVector_bit_test(v, i))
          all.push(SATSolver::mkLit(vec[i], true));
        else
          all.push(SATSolver::mkLit(vec[i], false));
      }

      if (polary != LEFT_ONLY)
      {
        SATSolver::vec_literals p;
        p.push(SATSolver::mkLit(result, true));
        if (CONSTANTBV::BitVector_bit_test(v, i))
          p.push(SATSolver::mkLit(vec[i], false));
        else
          p.push(SATSolver::mkLit(vec[i], true));
//.........这里部分代码省略.........
开发者ID:cambridgehackers,项目名称:stp,代码行数:101,代码来源:AbstractionRefinement.cpp

示例9: numberOfConstants

 int numberOfConstants() const
 {
   return ((index0.isConstant() ? 1 : 0) + (index1.isConstant() ? 1 : 0) +
           (index0.isConstant() ? 1 : 0) + (index1.isConstant() ? 1 : 0));
 }
开发者ID:cambridgehackers,项目名称:stp,代码行数:5,代码来源:AbstractionRefinement.cpp

示例10: if


//.........这里部分代码省略.........
            registerStack->freeOperand(ExprArbrAffected);
            ilCoder.add(MOVE,ExprArbrAff,ExprArbrAffected,SizeVarIter);
        }

        // ---------------------------------------------------
        // Evaluation de l'expression d'arriv?e
        // ---------------------------------------------------

        // temporaire sur la pile qui va contenir la valeur de l'expression d'arriv?e TO
        TexpTO=registerStack->allocateTemp(SizeVarIter);
        codeArith(finExpr,NO_REG,&ExprArbrAff);
        //registerStack->allocate(ExprArbrAff);
        ilCoder.add(MOVE,ExprArbrAff,TexpTO,SizeVarIter);
        //registerStack->freeOperand(ExprArbrAff);


        // ---------------------------------------------------
        // Test de la condition d'arriv?
        // ---------------------------------------------------
        ilCoder.addLabel(EtiqForDebTest->val.valLabel);

        // cas 1: pas de step
        if (stepExpr == NULL){
            codeArith(varExpr,NO_REG,&ExprArbrAffected);
            ilCoder.add(CMP,TexpTO,ExprArbrAffected,SizeVarIter);
            ilCoder.add(BGT,EtiqForFin,SZ_NA);
            codeInstr(CorpsFor);
            // iterateur = iterateur+1 sous entendu
            codeArith(varExpr,NO_DADR,&ExprArbrAffected);
            ilCoder.add(ADD,ilCoder.createOpVal(1),ExprArbrAffected,SizeVarIter);
            ilCoder.add(BRA,EtiqForDebTest,SZ_NA);
        }
        // cas 2: step constante
        else if (stepExpr->isConstant()){
            int constStepVal;
            constStepVal = atoi(stepExpr->getTag()->GetIdentif());
            codeArith(varExpr,NO_REG,&ExprArbrAffected);
            ilCoder.add(CMP,TexpTO,ExprArbrAffected,SizeVarIter);
            if (constStepVal < 0){
                ilCoder.add(BLT,EtiqForFin,SZ_NA);
            }
            else {
                ilCoder.add(BGT,EtiqForFin,SZ_NA);
            }
            codeInstr(CorpsFor);
            // iterateur = iterateur+cte sous entendu
            codeArith(varExpr,NO_DADR,&ExprArbrAffected);
            ilCoder.add(ADD,ilCoder.createOpVal(constStepVal),ExprArbrAffected,SizeVarIter);
            ilCoder.add(BRA,EtiqForDebTest,SZ_NA);

        }
        // cas 3: step non-constante
        else {
            //Operande68k* EtiqNegStep;
            //Operande68k* EtiqForDebCorps;
            //EtiqForFin = ilCoder.createOpLabel();

        }
        ilCoder.addLabel(EtiqForFin->val.valLabel);
        registerStack->freeTemp(TexpTO,SizeVarIter);   // on libere le temporaire qui contient l'expression de fin
        break;
    case INS_STRUCT_DOLPWH:     // do ... loop while (condition)
        Collection* CorpsDo;
        ASTNode* exprDo;
        Operande68k* EtiqDebut;
        CorpsDo = bInstr->getDoBody();
开发者ID:Celebio,项目名称:Etp-basic-Compiler,代码行数:67,代码来源:Gen68k.cpp


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