Doxygen
ExprAstBinary类 参考

Class representing a binary operator in the AST 更多...

+ 类 ExprAstBinary 继承关系图:
+ ExprAstBinary 的协作图:

Public 成员函数

 ExprAstBinary (Operator::Type op, ExprAstPtr &&lhs, ExprAstPtr &&rhs)
 
virtual TemplateVariant resolve (TemplateContext *c)
 
- Public 成员函数 继承自 ExprAst
virtual ~ExprAst ()
 

Private 属性

Operator::Type m_operator = Operator::Or
 
ExprAstPtr m_lhs
 
ExprAstPtr m_rhs
 

详细描述

Class representing a binary operator in the AST

在文件 template.cpp1824 行定义.

构造及析构函数说明

◆ ExprAstBinary()

ExprAstBinary::ExprAstBinary ( Operator::Type  op,
ExprAstPtr &&  lhs,
ExprAstPtr &&  rhs 
)
inline

在文件 template.cpp1827 行定义.

1828  : m_operator(op), m_lhs(std::move(lhs)), m_rhs(std::move(rhs))
1829  { TRACE(("ExprAstBinary %s\n",Operator::toString(op))); }

引用了 Operator::toString() , 以及 TRACE.

成员函数说明

◆ resolve()

virtual TemplateVariant ExprAstBinary::resolve ( TemplateContext c)
inlinevirtual

重载 ExprAst .

在文件 template.cpp1830 行定义.

1831  {
1832  TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
1833  if (ci==0) return TemplateVariant(); // should not happen
1834  TemplateVariant lhs = m_lhs->resolve(c);
1835  TemplateVariant rhs = m_rhs ? m_rhs->resolve(c) : TemplateVariant();
1836  switch(m_operator)
1837  {
1838  case Operator::Or:
1839  return TemplateVariant(lhs.toBool() || rhs.toBool());
1840  case Operator::And:
1841  return TemplateVariant(lhs.toBool() && rhs.toBool());
1842  case Operator::Equal:
1843  return TemplateVariant(lhs == rhs);
1844  case Operator::NotEqual:
1845  return TemplateVariant(!(lhs == rhs));
1846  case Operator::Less:
1847  if (lhs.isString() && rhs.isString())
1848  {
1849  return lhs.toString()<rhs.toString();
1850  }
1851  else
1852  {
1853  return lhs.toInt()<rhs.toInt();
1854  }
1855  case Operator::Greater:
1856  if (lhs.isString() && rhs.isString())
1857  {
1858  return !(lhs.toString()<rhs.toString());
1859  }
1860  else
1861  {
1862  return lhs.toInt()>rhs.toInt();
1863  }
1864  case Operator::LessEqual:
1865  if (lhs.isString() && rhs.isString())
1866  {
1867  return lhs.toString()==rhs.toString() || lhs.toString()<rhs.toString();
1868  }
1869  else
1870  {
1871  return lhs.toInt()<=rhs.toInt();
1872  }
1874  if (lhs.isString() && rhs.isString())
1875  {
1876  return lhs.toString()==rhs.toString() || !(lhs.toString()<rhs.toString());
1877  }
1878  else
1879  {
1880  return lhs.toInt()>=rhs.toInt();
1881  }
1882  case Operator::Plus:
1883  {
1884  return TemplateVariant(lhs.toInt() + rhs.toInt());
1885  }
1886  case Operator::Minus:
1887  {
1888  return TemplateVariant(lhs.toInt() - rhs.toInt());
1889  }
1890  case Operator::Multiply:
1891  {
1892  return TemplateVariant(lhs.toInt() * rhs.toInt());
1893  }
1894  case Operator::Divide:
1895  {
1896  int denom = rhs.toInt();
1897  if (denom!=0)
1898  {
1899  return TemplateVariant(lhs.toInt() / denom);
1900  }
1901  else // divide by zero
1902  {
1903  ci->warn(ci->templateName(),ci->line(),"division by zero while evaluating expression is undefined");
1904  return 0;
1905  }
1906  }
1907  case Operator::Modulo:
1908  {
1909  int denom = rhs.toInt();
1910  if (denom!=0)
1911  {
1912  return TemplateVariant(lhs.toInt() % denom);
1913  }
1914  else // module zero
1915  {
1916  ci->warn(ci->templateName(),ci->line(),"modulo zero while evaluating expression is undefined");
1917  return 0;
1918  }
1919  }
1920  default:
1921  return TemplateVariant();
1922  }
1923  }

引用了 Operator::And, Operator::Divide, Operator::Equal, Operator::Greater, Operator::GreaterEqual, TemplateVariant::isString(), Operator::Less, Operator::LessEqual, TemplateContextImpl::line(), m_lhs, m_operator, m_rhs, Operator::Minus, Operator::Modulo, Operator::Multiply, Operator::NotEqual, Operator::Or, Operator::Plus, TemplateContextImpl::templateName(), TemplateVariant::toBool(), TemplateVariant::toInt(), TemplateVariant::toString() , 以及 TemplateContextImpl::warn().

类成员变量说明

◆ m_lhs

ExprAstPtr ExprAstBinary::m_lhs
private

在文件 template.cpp1926 行定义.

被这些函数引用 resolve().

◆ m_operator

Operator::Type ExprAstBinary::m_operator = Operator::Or
private

在文件 template.cpp1925 行定义.

被这些函数引用 resolve().

◆ m_rhs

ExprAstPtr ExprAstBinary::m_rhs
private

在文件 template.cpp1927 行定义.

被这些函数引用 resolve().


该类的文档由以下文件生成:
TemplateContextImpl::warn
void warn(const QCString &fileName, int line, const char *fmt,...) const
Definition: template.cpp:2773
Operator::Modulo
@ Modulo
Definition: template.cpp:574
Operator::Minus
@ Minus
Definition: template.cpp:574
Operator::GreaterEqual
@ GreaterEqual
Definition: template.cpp:574
TemplateContextImpl::line
int line() const
Definition: template.cpp:685
Operator::Or
@ Or
Definition: template.cpp:573
Operator::LessEqual
@ LessEqual
Definition: template.cpp:573
TemplateVariant
Variant type which can hold one value of a fixed set of types.
Definition: template.h:98
Operator::toString
static const char * toString(Type op)
Definition: template.cpp:579
Operator::NotEqual
@ NotEqual
Definition: template.cpp:573
Operator::Divide
@ Divide
Definition: template.cpp:574
TRACE
#define TRACE(x)
Definition: template.cpp:40
Operator::Equal
@ Equal
Definition: template.cpp:573
ExprAstBinary::m_lhs
ExprAstPtr m_lhs
Definition: template.cpp:1926
ExprAstBinary::m_rhs
ExprAstPtr m_rhs
Definition: template.cpp:1927
TemplateVariant::toString
QCString toString() const
Returns the variant as a string.
Definition: template.cpp:399
ExprAstBinary::m_operator
Operator::Type m_operator
Definition: template.cpp:1925
TemplateVariant::toBool
bool toBool() const
Returns the variant as a boolean.
Definition: template.cpp:367
TemplateVariant::toInt
int toInt() const
Returns the variant as an integer.
Definition: template.cpp:383
TemplateContextImpl
Internal class representing the implementation of a template context
Definition: template.cpp:640
Operator::Multiply
@ Multiply
Definition: template.cpp:574
Operator::Plus
@ Plus
Definition: template.cpp:574
Operator::And
@ And
Definition: template.cpp:573
TemplateContextImpl::templateName
QCString templateName() const
Definition: template.cpp:684
TemplateVariant::isString
constexpr bool isString() const
Returns TRUE if the variant holds a string value
Definition: template.h:209
Operator::Less
@ Less
Definition: template.cpp:573
Operator::Greater
@ Greater
Definition: template.cpp:573