Exemplo n.º 1
0
unsigned int
ExpressionBuilder::EBBinaryTermNode::substitute(const EBSubstitutionRuleList & rules)
{
  unsigned int nrule = rules.size();
  unsigned int success = 0;

  for (unsigned int i = 0; i < nrule; ++i)
  {
    EBTermNode * replace = rules[i]->apply(left);
    if (replace != NULL)
    {
      delete left;
      left = replace;
      success = 1;
      break;
    }
  }

  if (success == 0)
    success += left->substitute(rules);

  for (unsigned int i = 0; i < nrule; ++i)
  {
    EBTermNode * replace = rules[i]->apply(right);
    if (replace != NULL)
    {
      delete right;
      right = replace;
      return success + 1;
    }
  }

  return success + right->substitute(rules);
}
Exemplo n.º 2
0
unsigned int
ExpressionBuilder::EBTernaryTermNode::substitute(const EBSubstitutionRuleList & rules)
{
  unsigned int nrule = rules.size();
  bool left_success   = false,
       middle_success = false,
       right_success  = false;
  EBTermNode * replace;

  for (unsigned int i = 0; i < nrule; ++i)
  {
    replace = rules[i]->apply(left);
    if (replace)
    {
      delete left;
      left = replace;
      left_success = true;
      break;
    }
  }

  for (unsigned int i = 0; i < nrule; ++i)
  {
    replace = rules[i]->apply(middle);
    if (replace)
    {
      delete middle;
      middle = replace;
      middle_success = true;
      break;
    }
  }

  for (unsigned int i = 0; i < nrule; ++i)
  {
    replace = rules[i]->apply(right);
    if (replace)
    {
      delete right;
      right = replace;
      right_success = true;
      break;
    }
  }

  if (!left_success)
    left_success = left->substitute(rules);
  if (!middle_success)
    middle_success = middle->substitute(rules);
  if (!right_success)
    right_success = right->substitute(rules);

  return left_success + middle_success + right_success;
}
Exemplo n.º 3
0
ExpressionBuilder::EBFunction::operator ExpressionBuilder::EBTerm() const
{
  unsigned int narg = arguments.size();
  if (narg != eval_arguments.size())
    mooseError("EBFunction is used wth a different number of arguments than it was defined with.");

  // prepare a copy of the function term to perform the substitution on
  EBTerm result(term);

  // prepare a rule list for the substitutions
  EBSubstitutionRuleList rules;
  for (unsigned i = 0; i < narg; ++i)
    rules.push_back(new EBTermSubstitution(arguments[i], eval_arguments[i]));

  // perform substitution
  result.substitute(rules);

  // discard rule set
  for (unsigned i = 0; i < narg; ++i)
    delete rules[i];

  return result;
}
Exemplo n.º 4
0
unsigned int
ExpressionBuilder::EBUnaryTermNode::substitute(const EBSubstitutionRuleList & rules)
{
  unsigned int nrule = rules.size();

  for (unsigned int i = 0; i < nrule; ++i)
  {
    EBTermNode * replace = rules[i]->apply(subnode);
    if (replace != NULL)
    {
      delete subnode;
      subnode = replace;
      return 1;
    }
  }

  return subnode->substitute(rules);
}
Exemplo n.º 5
0
unsigned int
ExpressionBuilder::EBTerm::substitute(const EBSubstitutionRuleList & rules)
{
  unsigned int nrule = rules.size();

  if (root == NULL)
    return 0;

  for (unsigned int i = 0; i < nrule; ++i)
  {
    EBTermNode * replace = rules[i]->apply(root);
    if (replace != NULL)
    {
      delete root;
      root = replace;
      return 1;
    }
  }

  return root->substitute(rules);
}