www.mooseframework.org
Public Types | Public Member Functions | Protected Attributes | List of all members
ExpressionBuilder::EBBinaryOpTermNode Class Reference

Node representing a binary operator. More...

#include <ExpressionBuilder.h>

Inheritance diagram for ExpressionBuilder::EBBinaryOpTermNode:
[legend]

Public Types

enum  NodeType {
  ADD, SUB, MUL, DIV,
  MOD, POW, LESS, GREATER,
  LESSEQ, GREATEREQ, EQ, NOTEQ
}
 

Public Member Functions

 EBBinaryOpTermNode (EBTermNode *left, EBTermNode *right, NodeType type)
 
virtual EBBinaryOpTermNodeclone () const
 
virtual std::string stringify () const
 
virtual int precedence () const
 
virtual unsigned int substitute (const EBSubstitutionRuleList &rule)
 

Protected Attributes

NodeType _type
 
EBTermNode_left
 
EBTermNode_right
 

Detailed Description

Node representing a binary operator.

Definition at line 204 of file ExpressionBuilder.h.

Member Enumeration Documentation

◆ NodeType

Constructor & Destructor Documentation

◆ EBBinaryOpTermNode()

ExpressionBuilder::EBBinaryOpTermNode::EBBinaryOpTermNode ( EBTermNode left,
EBTermNode right,
NodeType  type 
)
inline

Definition at line 223 of file ExpressionBuilder.h.

224  : EBBinaryTermNode(left, right), _type(type){};
EBBinaryTermNode(EBTermNode *left, EBTermNode *right)

Member Function Documentation

◆ clone()

virtual EBBinaryOpTermNode* ExpressionBuilder::EBBinaryOpTermNode::clone ( ) const
inlinevirtual

Implements ExpressionBuilder::EBTermNode.

Definition at line 225 of file ExpressionBuilder.h.

226  {
227  return new EBBinaryOpTermNode(_left->clone(), _right->clone(), _type);
228  };
virtual EBTermNode * clone() const =0
EBBinaryOpTermNode(EBTermNode *left, EBTermNode *right, NodeType type)

◆ precedence()

int ExpressionBuilder::EBBinaryOpTermNode::precedence ( ) const
virtual

Implements ExpressionBuilder::EBTermNode.

Definition at line 117 of file ExpressionBuilder.C.

◆ stringify()

std::string ExpressionBuilder::EBBinaryOpTermNode::stringify ( ) const
virtual

Implements ExpressionBuilder::EBTermNode.

Definition at line 92 of file ExpressionBuilder.C.

93 {
94  const char * name[] = {"+", "-", "*", "/", "%", "^", "<", ">", "<=", ">=", "=", "!="};
95  std::ostringstream s;
96 
97  if (_left->precedence() > precedence())
98  s << '(' << *_left << ')';
99  else
100  s << *_left;
101 
102  s << name[_type];
103 
104  // these operators are left associative at equal precedence
105  // (this matters for -,/,&,^ but not for + and *)
106  if (_right->precedence() > precedence() ||
107  (_right->precedence() == precedence() &&
108  (_type == SUB || _type == DIV || _type == MOD || _type == POW)))
109  s << '(' << *_right << ')';
110  else
111  s << *_right;
112 
113  return s.str();
114 }
virtual int precedence() const =0
const std::string name
Definition: Setup.h:22

◆ substitute()

unsigned int ExpressionBuilder::EBBinaryTermNode::substitute ( const EBSubstitutionRuleList rule)
virtualinherited

Reimplemented from ExpressionBuilder::EBTermNode.

Reimplemented in ExpressionBuilder::EBTernaryTermNode.

Definition at line 326 of file ExpressionBuilder.C.

327 {
328  unsigned int nrule = rules.size();
329  unsigned int success = 0;
330 
331  for (unsigned int i = 0; i < nrule; ++i)
332  {
333  EBTermNode * replace = rules[i]->apply(_left);
334  if (replace != NULL)
335  {
336  delete _left;
337  _left = replace;
338  success = 1;
339  break;
340  }
341  }
342 
343  if (success == 0)
344  success += _left->substitute(rules);
345 
346  for (unsigned int i = 0; i < nrule; ++i)
347  {
348  EBTermNode * replace = rules[i]->apply(_right);
349  if (replace != NULL)
350  {
351  delete _right;
352  _right = replace;
353  return success + 1;
354  }
355  }
356 
357  return success + _right->substitute(rules);
358 }
virtual unsigned int substitute(const EBSubstitutionRuleList &)

Member Data Documentation

◆ _left

EBTermNode* ExpressionBuilder::EBBinaryTermNode::_left
protectedinherited

Definition at line 199 of file ExpressionBuilder.h.

◆ _right

EBTermNode* ExpressionBuilder::EBBinaryTermNode::_right
protectedinherited

Definition at line 200 of file ExpressionBuilder.h.

◆ _type

NodeType ExpressionBuilder::EBBinaryOpTermNode::_type
protected

Definition at line 234 of file ExpressionBuilder.h.


The documentation for this class was generated from the following files: