My Project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 1597 of file template.cpp.

Constructor & Destructor Documentation

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

Definition at line 1600 of file template.cpp.

References Operator::toString(), and TRACE.

: m_operator(op), m_lhs(lhs), m_rhs(rhs)
{ TRACE(("ExprAstBinary %s\n",Operator::toString(op))); }
ExprAstBinary::~ExprAstBinary ( )
inline

Definition at line 1603 of file template.cpp.

References m_lhs, and m_rhs.

{ delete m_lhs; delete m_rhs; }

Member Function Documentation

virtual TemplateVariant ExprAstBinary::resolve ( TemplateContext c)
inlinevirtual

Reimplemented from ExprAst.

Definition at line 1604 of file template.cpp.

References Operator::And, Operator::Divide, Operator::Equal, Operator::Greater, Operator::GreaterEqual, Operator::Less, Operator::LessEqual, TemplateContextImpl::line(), m_lhs, m_operator, m_rhs, Operator::Minus, Operator::Modulo, Operator::Multiply, Operator::NotEqual, Operator::Or, Operator::Plus, ExprAst::resolve(), TemplateVariant::String, TemplateContextImpl::templateName(), TemplateVariant::toBool(), TemplateVariant::toInt(), TemplateVariant::toString(), TemplateVariant::type(), and TemplateContextImpl::warn().

{
TemplateContextImpl *ci = dynamic_cast<TemplateContextImpl*>(c);
if (ci==0) return TemplateVariant(); // should not happen
switch(m_operator)
{
return TemplateVariant(lhs.toBool() || rhs.toBool());
return TemplateVariant(lhs.toBool() && rhs.toBool());
return TemplateVariant(lhs == rhs);
return TemplateVariant(!(lhs == rhs));
{
return lhs.toString()<rhs.toString();
}
else
{
return lhs.toInt()<rhs.toInt();
}
{
return !(lhs.toString()<rhs.toString());
}
else
{
return lhs.toInt()>rhs.toInt();
}
{
return lhs.toString()==rhs.toString() || lhs.toString()<rhs.toString();
}
else
{
return lhs.toInt()<=rhs.toInt();
}
{
return lhs.toString()==rhs.toString() || !(lhs.toString()<rhs.toString());
}
else
{
return lhs.toInt()>=rhs.toInt();
}
{
return TemplateVariant(lhs.toInt() + rhs.toInt());
}
{
return TemplateVariant(lhs.toInt() - rhs.toInt());
}
{
return TemplateVariant(lhs.toInt() * rhs.toInt());
}
{
int denom = rhs.toInt();
if (denom!=0)
{
return TemplateVariant(lhs.toInt() / denom);
}
else // divide by zero
{
ci->warn(ci->templateName(),ci->line(),"division by zero while evaluating expression is undefined");
return 0;
}
}
{
int denom = rhs.toInt();
if (denom!=0)
{
return TemplateVariant(lhs.toInt() % denom);
}
else // module zero
{
ci->warn(ci->templateName(),ci->line(),"modulo zero while evaluating expression is undefined");
return 0;
}
}
default:
return TemplateVariant();
}
}

Member Data Documentation

ExprAst* ExprAstBinary::m_lhs
private

Definition at line 1700 of file template.cpp.

Referenced by resolve(), and ~ExprAstBinary().

Operator::Type ExprAstBinary::m_operator
private

Definition at line 1699 of file template.cpp.

Referenced by resolve().

ExprAst* ExprAstBinary::m_rhs
private

Definition at line 1701 of file template.cpp.

Referenced by resolve(), and ~ExprAstBinary().


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