Public Member Functions | Private Attributes | List of all members
ExprAstBinary Class Reference

Class representing a binary operator in the AST. More...

Inheritance diagram for ExprAstBinary:
ExprAst

Public Member Functions

 ExprAstBinary (Operator::Type op, ExprAst *lhs, ExprAst *rhs)
 
 ~ExprAstBinary ()
 
virtual TemplateVariant resolve (TemplateContext *c)
 
- Public Member Functions inherited from ExprAst
virtual ~ExprAst ()
 

Private Attributes

Operator::Type m_operator
 
ExprAstm_lhs
 
ExprAstm_rhs
 

Detailed Description

Class representing a binary operator in the AST.

Definition at line 1529 of file template.cpp.

Constructor & Destructor Documentation

ExprAstBinary::ExprAstBinary ( Operator::Type  op,
ExprAst lhs,
ExprAst rhs 
)
inline

Definition at line 1532 of file template.cpp.

1533  : m_operator(op), m_lhs(lhs), m_rhs(rhs)
1534  { TRACE(("ExprAstBinary %s\n",Operator::toString(op))); }
static const char * toString(Type op)
Definition: template.cpp:451
Operator::Type m_operator
Definition: template.cpp:1631
ExprAst * m_rhs
Definition: template.cpp:1633
ExprAst * m_lhs
Definition: template.cpp:1632
#define TRACE(x)
Definition: template.cpp:43
ExprAstBinary::~ExprAstBinary ( )
inline

Definition at line 1535 of file template.cpp.

1535 { delete m_lhs; delete m_rhs; }
ExprAst * m_rhs
Definition: template.cpp:1633
ExprAst * m_lhs
Definition: template.cpp:1632

Member Function Documentation

virtual TemplateVariant ExprAstBinary::resolve ( TemplateContext c)
inlinevirtual

Reimplemented from ExprAst.

Definition at line 1536 of file template.cpp.

1537  {
1538  TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
1539  if (ci==0) return TemplateVariant(); // should not happen
1540  TemplateVariant lhs = m_lhs->resolve(c);
1542  switch(m_operator)
1543  {
1544  case Operator::Or:
1545  return TemplateVariant(lhs.toBool() || rhs.toBool());
1546  case Operator::And:
1547  return TemplateVariant(lhs.toBool() && rhs.toBool());
1548  case Operator::Equal:
1549  return TemplateVariant(lhs == rhs);
1550  case Operator::NotEqual:
1551  return TemplateVariant(!(lhs == rhs));
1552  case Operator::Less:
1554  {
1555  return lhs.toString()<rhs.toString();
1556  }
1557  else
1558  {
1559  return lhs.toInt()<rhs.toInt();
1560  }
1561  case Operator::Greater:
1563  {
1564  return !(lhs.toString()<rhs.toString());
1565  }
1566  else
1567  {
1568  return lhs.toInt()>rhs.toInt();
1569  }
1570  case Operator::LessEqual:
1572  {
1573  return lhs.toString()==rhs.toString() || lhs.toString()<rhs.toString();
1574  }
1575  else
1576  {
1577  return lhs.toInt()<=rhs.toInt();
1578  }
1581  {
1582  return lhs.toString()==rhs.toString() || !(lhs.toString()<rhs.toString());
1583  }
1584  else
1585  {
1586  return lhs.toInt()>=rhs.toInt();
1587  }
1588  case Operator::Plus:
1589  {
1590  return TemplateVariant(lhs.toInt() + rhs.toInt());
1591  }
1592  case Operator::Minus:
1593  {
1594  return TemplateVariant(lhs.toInt() - rhs.toInt());
1595  }
1596  case Operator::Multiply:
1597  {
1598  return TemplateVariant(lhs.toInt() * rhs.toInt());
1599  }
1600  case Operator::Divide:
1601  {
1602  int denom = rhs.toInt();
1603  if (denom!=0)
1604  {
1605  return TemplateVariant(lhs.toInt() / denom);
1606  }
1607  else // divide by zero
1608  {
1609  ci->warn(ci->templateName(),ci->line(),"division by zero while evaluating expression is undefined");
1610  return 0;
1611  }
1612  }
1613  case Operator::Modulo:
1614  {
1615  int denom = rhs.toInt();
1616  if (denom!=0)
1617  {
1618  return TemplateVariant(lhs.toInt() % denom);
1619  }
1620  else // module zero
1621  {
1622  ci->warn(ci->templateName(),ci->line(),"modulo zero while evaluating expression is undefined");
1623  return 0;
1624  }
1625  }
1626  default:
1627  return TemplateVariant();
1628  }
1629  }
Internal class representing the implementation of a template context.
Definition: template.cpp:511
bool toBool() const
Definition: template.cpp:207
int line() const
Definition: template.cpp:543
int toInt() const
Definition: template.cpp:222
QCString toString() const
Definition: template.h:232
virtual TemplateVariant resolve(TemplateContext *)
Definition: template.cpp:1368
Operator::Type m_operator
Definition: template.cpp:1631
ExprAst * m_rhs
Definition: template.cpp:1633
ExprAst * m_lhs
Definition: template.cpp:1632
Variant type which can hold one value of a fixed set of types.
Definition: template.h:90
void warn(const char *fileName, int line, const char *fmt,...) const
Definition: template.cpp:2431
Type type() const
Definition: template.h:142
QCString templateName() const
Definition: template.cpp:542

Member Data Documentation

ExprAst* ExprAstBinary::m_lhs
private

Definition at line 1632 of file template.cpp.

Operator::Type ExprAstBinary::m_operator
private

Definition at line 1631 of file template.cpp.

ExprAst* ExprAstBinary::m_rhs
private

Definition at line 1633 of file template.cpp.


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