コード例 #1
0
ファイル: Expression.cpp プロジェクト: dubrousky/Mathador
bool Expression::ReplaceAll(const ExprVector &rules, Calculator *calculator, bool *changed)
{
	for(ExprVector::const_iterator rule = rules.begin(); rule != rules.end(); ++rule)
		if(Replace(*rule, calculator, changed))
			return true;
	for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf)
		if((*leaf)->ReplaceAll(rules, calculator, changed))
			return true;
	return false;
}
コード例 #2
0
ファイル: Expression.cpp プロジェクト: dubrousky/Mathador
void Expression::SubstituteSlots(const ExprVector &slots)
{
	string functionName = FunctionName();
	if(functionName == "Slot")
	{
		IntegerType index;
		if(leaves.empty())
			index = 1;
		else
		{
			//MachineInteger *indexInt = leaves.at(0)->MachineIntegerHead();
			Integer *indexInt(dynamic_cast<Integer*>(leaves.at(0)->NumberHead()));
			if(indexInt)
				index = indexInt->IntValue();
			else
				throw EvaluateException("Slot expected to have an Integer argument.");
		}
		Expression *slot;
		if(index > 0 && index-1 < slots.size())
			slot = slots.at(static_cast<ExprVector::size_type>(index-1));
		else
			throw EvaluateException("Slot not given.");
		AssignCloned(slot);
	}
	else if(functionName == "SlotSequence")
	{
		delete head;
		head = new Expression("Sequence");
		DeleteLeaves();
		leaves.reserve(slots.size());
		for(ExprVector::const_iterator leaf = slots.begin(); leaf != slots.end(); ++leaf)
			AppendLeaf((*leaf)->Clone());
	}
	else if(functionName != "Function")
	{
		if(head)
			head->SubstituteSlots(slots);
		for(ExprVector::const_iterator leaf = leaves.begin(); leaf != leaves.end(); ++leaf)
			(*leaf)->SubstituteSlots(slots);
	}
}
コード例 #3
0
void RemoveUnusedStructField::handleOneVarDecl(const VarDecl *VD)
{
  const Type *Ty = VD->getType().getTypePtr();
  const RecordDecl *RD = getBaseRecordDef(Ty);
  if (!RD)
    return;

  IndexVector *IdxVec = RecordDeclToField[RD];
  if (!IdxVec)
    return;

  const Expr *InitE = VD->getInit();
  TransAssert(InitE && "Need initializer!");

  ExprVector InitExprs;

  getInitExprs(Ty, InitE, IdxVec, InitExprs);

  for (ExprVector::iterator I = InitExprs.begin(),
       E = InitExprs.end(); I != E; ++I) {
    removeOneInitExpr(*I);
  }
}