Kaydet (Commit) bc1fdb79 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

The only EvalKind actually used is EK_const

Change-Id: Ide451d1e287eeb8666b9ddcce312b9a753761c50
üst 6dbc69bd
...@@ -41,13 +41,6 @@ enum ExprComb ...@@ -41,13 +41,6 @@ enum ExprComb
EC_symbol // a symbol (function or constant name) EC_symbol // a symbol (function or constant name)
}; };
// Enum to define the different kinds of evaluation possible
enum EvalKind
{
EK_const, // Must evaluate to constant
EK_positive_int // Must evaluate to positive integer
};
// Enum to define expression type // Enum to define expression type
enum ExprType enum ExprType
{ {
...@@ -118,7 +111,7 @@ public: ...@@ -118,7 +111,7 @@ public:
AstExprValue* coerce(ExprType type, bool bAssign=true); AstExprValue* coerce(ExprType type, bool bAssign=true);
// Evaluate then store value inside this AstExpression // Evaluate then store value inside this AstExpression
void evaluate(EvalKind ek); void evaluate();
// Compare to AstExpressions // Compare to AstExpressions
bool operator==(AstExpression *pExpr); bool operator==(AstExpression *pExpr);
...@@ -129,12 +122,12 @@ private: ...@@ -129,12 +122,12 @@ private:
// Fill out the lineno, filename and definition scope details // Fill out the lineno, filename and definition scope details
void fillDefinitionDetails(); void fillDefinitionDetails();
// Internal evaluation // Internal evaluation
AstExprValue* eval_internal(EvalKind ek); AstExprValue* eval_internal();
// Evaluate different sets of operators // Evaluate different sets of operators
AstExprValue* eval_bin_op(EvalKind ek); AstExprValue* eval_bin_op();
AstExprValue* eval_bit_op(EvalKind ek); AstExprValue* eval_bit_op();
AstExprValue* eval_un_op(EvalKind ek); AstExprValue* eval_un_op();
AstExprValue* eval_symbol(EvalKind ek); AstExprValue* eval_symbol();
AstScope* m_pScope; // scope defined in AstScope* m_pScope; // scope defined in
sal_Int32 m_lineNo; // line number defined in sal_Int32 m_lineNo; // line number defined in
......
...@@ -685,24 +685,6 @@ coerce_value(AstExprValue *ev, ExprType t) ...@@ -685,24 +685,6 @@ coerce_value(AstExprValue *ev, ExprType t)
} }
} }
/*
* Evaluate the expression with the evaluation kind requested. Supported
* evaluation kinds are
* - EK_const: The expression must evaluate to a constant
* - EK_positive_int: The expression must further evaluate to a
* positive integer
*/
static AstExprValue *
eval_kind(AstExprValue *ev, EvalKind ek)
{
if (ek == EK_const)
return ev;
if (ek == EK_positive_int)
return coerce_value(ev, ET_ulong);
return NULL;
}
AstExprValue* AstExpression::coerce(ExprType t, bool bAssign) AstExprValue* AstExpression::coerce(ExprType t, bool bAssign)
{ {
AstExprValue *copy; AstExprValue *copy;
...@@ -718,7 +700,7 @@ AstExprValue* AstExpression::coerce(ExprType t, bool bAssign) ...@@ -718,7 +700,7 @@ AstExprValue* AstExpression::coerce(ExprType t, bool bAssign)
* First, evaluate it, then try to coerce result type * First, evaluate it, then try to coerce result type
* If already evaluated, return the result * If already evaluated, return the result
*/ */
m_exprValue = eval_internal(EK_const); m_exprValue = eval_internal();
if (m_exprValue == NULL) if (m_exprValue == NULL)
return NULL; return NULL;
...@@ -775,10 +757,9 @@ AstExprValue* AstExpression::coerce(ExprType t, bool bAssign) ...@@ -775,10 +757,9 @@ AstExprValue* AstExpression::coerce(ExprType t, bool bAssign)
return coerced; return coerced;
} }
void AstExpression::evaluate(EvalKind ek) void AstExpression::evaluate()
{ {
m_exprValue = eval_internal(ek); m_exprValue = eval_internal();
m_exprValue = eval_kind(m_exprValue, ek);
} }
bool AstExpression::operator==(AstExpression *pExpr) bool AstExpression::operator==(AstExpression *pExpr)
...@@ -786,8 +767,8 @@ bool AstExpression::operator==(AstExpression *pExpr) ...@@ -786,8 +767,8 @@ bool AstExpression::operator==(AstExpression *pExpr)
bool bRet = false; bool bRet = false;
if (m_combOperator != pExpr->getCombOperator()) if (m_combOperator != pExpr->getCombOperator())
return bRet; return bRet;
evaluate(EK_const); evaluate();
pExpr->evaluate(EK_const); pExpr->evaluate();
if (m_exprValue == NULL || pExpr->getExprValue() == NULL) if (m_exprValue == NULL || pExpr->getExprValue() == NULL)
return bRet; return bRet;
if (m_exprValue->et != pExpr->getExprValue()->et) if (m_exprValue->et != pExpr->getExprValue()->et)
...@@ -838,8 +819,8 @@ bool AstExpression::compare(AstExpression *pExpr) ...@@ -838,8 +819,8 @@ bool AstExpression::compare(AstExpression *pExpr)
bool bRet = false; bool bRet = false;
if (m_combOperator != pExpr->getCombOperator()) if (m_combOperator != pExpr->getCombOperator())
return bRet; return bRet;
evaluate(EK_const); evaluate();
pExpr->evaluate(EK_const); pExpr->evaluate();
if (m_exprValue == NULL || pExpr->getExprValue() == NULL) if (m_exprValue == NULL || pExpr->getExprValue() == NULL)
return bRet; return bRet;
if (m_exprValue->et != pExpr->getExprValue()->et) if (m_exprValue->et != pExpr->getExprValue()->et)
...@@ -891,13 +872,13 @@ void AstExpression::fillDefinitionDetails() ...@@ -891,13 +872,13 @@ void AstExpression::fillDefinitionDetails()
m_fileName = idlc()->getFileName(); m_fileName = idlc()->getFileName();
} }
AstExprValue* AstExpression::eval_internal(EvalKind ek) AstExprValue* AstExpression::eval_internal()
{ {
/* /*
* Already evaluated? * Already evaluated?
*/ */
if ( m_exprValue != NULL ) if ( m_exprValue != NULL )
return eval_kind(m_exprValue, ek); return m_exprValue;
/* /*
* OK, must evaluate operator * OK, must evaluate operator
*/ */
...@@ -908,23 +889,23 @@ AstExprValue* AstExpression::eval_internal(EvalKind ek) ...@@ -908,23 +889,23 @@ AstExprValue* AstExpression::eval_internal(EvalKind ek)
case EC_mul: case EC_mul:
case EC_div: case EC_div:
case EC_mod: case EC_mod:
m_exprValue = eval_bin_op(ek); m_exprValue = eval_bin_op();
return eval_kind(m_exprValue, ek); return m_exprValue;
case EC_or: case EC_or:
case EC_xor: case EC_xor:
case EC_and: case EC_and:
case EC_left: case EC_left:
case EC_right: case EC_right:
m_exprValue = eval_bit_op(ek); m_exprValue = eval_bit_op();
return eval_kind(m_exprValue, ek); return m_exprValue;
case EC_u_plus: case EC_u_plus:
case EC_u_minus: case EC_u_minus:
case EC_bit_neg: case EC_bit_neg:
m_exprValue = eval_un_op(ek); m_exprValue = eval_un_op();
return eval_kind(m_exprValue, ek); return m_exprValue;
case EC_symbol: case EC_symbol:
m_exprValue = eval_symbol(ek); m_exprValue = eval_symbol();
return eval_kind(m_exprValue, ek); return m_exprValue;
case EC_none: case EC_none:
return NULL; return NULL;
} }
...@@ -932,24 +913,22 @@ AstExprValue* AstExpression::eval_internal(EvalKind ek) ...@@ -932,24 +913,22 @@ AstExprValue* AstExpression::eval_internal(EvalKind ek)
return NULL; return NULL;
} }
AstExprValue* AstExpression::eval_bin_op(EvalKind ek) AstExprValue* AstExpression::eval_bin_op()
{ {
ExprType eType = ET_double; ExprType eType = ET_double;
if ( m_combOperator == EC_mod ) if ( m_combOperator == EC_mod )
eType = ET_hyper; eType = ET_hyper;
if (ek != EK_const && ek != EK_positive_int)
return NULL;
if (m_subExpr1 == NULL || m_subExpr2 == NULL) if (m_subExpr1 == NULL || m_subExpr2 == NULL)
return NULL; return NULL;
m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek)); m_subExpr1->setExprValue(m_subExpr1->eval_internal());
if (m_subExpr1->getExprValue() == NULL) if (m_subExpr1->getExprValue() == NULL)
return NULL; return NULL;
m_subExpr1->setExprValue(m_subExpr1->coerce(eType)); m_subExpr1->setExprValue(m_subExpr1->coerce(eType));
if (m_subExpr1->getExprValue() == NULL) if (m_subExpr1->getExprValue() == NULL)
return NULL; return NULL;
m_subExpr2->setExprValue(m_subExpr2->eval_internal(ek)); m_subExpr2->setExprValue(m_subExpr2->eval_internal());
if (m_subExpr2->getExprValue() == NULL) if (m_subExpr2->getExprValue() == NULL)
return NULL; return NULL;
m_subExpr2->setExprValue(m_subExpr2->coerce(eType)); m_subExpr2->setExprValue(m_subExpr2->coerce(eType));
...@@ -987,19 +966,17 @@ AstExprValue* AstExpression::eval_bin_op(EvalKind ek) ...@@ -987,19 +966,17 @@ AstExprValue* AstExpression::eval_bin_op(EvalKind ek)
return retval.release(); return retval.release();
} }
AstExprValue* AstExpression::eval_bit_op(EvalKind ek) AstExprValue* AstExpression::eval_bit_op()
{ {
if (ek != EK_const && ek != EK_positive_int)
return NULL;
if (m_subExpr1 == NULL || m_subExpr2 == NULL) if (m_subExpr1 == NULL || m_subExpr2 == NULL)
return NULL; return NULL;
m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek)); m_subExpr1->setExprValue(m_subExpr1->eval_internal());
if (m_subExpr1->getExprValue() == NULL) if (m_subExpr1->getExprValue() == NULL)
return NULL; return NULL;
m_subExpr1->setExprValue(m_subExpr1->coerce(ET_long)); m_subExpr1->setExprValue(m_subExpr1->coerce(ET_long));
if (m_subExpr1->getExprValue() == NULL) if (m_subExpr1->getExprValue() == NULL)
return NULL; return NULL;
m_subExpr2->setExprValue(m_subExpr2->eval_internal(ek)); m_subExpr2->setExprValue(m_subExpr2->eval_internal());
if (m_subExpr2->getExprValue() == NULL) if (m_subExpr2->getExprValue() == NULL)
return NULL; return NULL;
m_subExpr2->setExprValue(m_subExpr2->coerce(ET_long)); m_subExpr2->setExprValue(m_subExpr2->coerce(ET_long));
...@@ -1033,16 +1010,14 @@ AstExprValue* AstExpression::eval_bit_op(EvalKind ek) ...@@ -1033,16 +1010,14 @@ AstExprValue* AstExpression::eval_bit_op(EvalKind ek)
return retval.release(); return retval.release();
} }
AstExprValue* AstExpression::eval_un_op(EvalKind ek) AstExprValue* AstExpression::eval_un_op()
{ {
if (m_exprValue != NULL) if (m_exprValue != NULL)
return m_exprValue; return m_exprValue;
if (ek != EK_const && ek != EK_positive_int)
return NULL;
if (m_subExpr1 == NULL) if (m_subExpr1 == NULL)
return NULL; return NULL;
m_subExpr1->setExprValue(m_subExpr1->eval_internal(ek)); m_subExpr1->setExprValue(m_subExpr1->eval_internal());
if (m_subExpr1->getExprValue() == NULL) if (m_subExpr1->getExprValue() == NULL)
return NULL; return NULL;
m_subExpr1->setExprValue(m_subExpr1->coerce(ET_double)); m_subExpr1->setExprValue(m_subExpr1->coerce(ET_double));
...@@ -1073,7 +1048,7 @@ AstExprValue* AstExpression::eval_un_op(EvalKind ek) ...@@ -1073,7 +1048,7 @@ AstExprValue* AstExpression::eval_un_op(EvalKind ek)
return retval.release(); return retval.release();
} }
AstExprValue* AstExpression::eval_symbol(EvalKind ek) AstExprValue* AstExpression::eval_symbol()
{ {
AstScope *pScope = 0; AstScope *pScope = 0;
AstDeclaration *pDecl; AstDeclaration *pDecl;
...@@ -1123,7 +1098,7 @@ AstExprValue* AstExpression::eval_symbol(EvalKind ek) ...@@ -1123,7 +1098,7 @@ AstExprValue* AstExpression::eval_symbol(EvalKind ek)
* OK, now evaluate the constant we just got, to produce its value * OK, now evaluate the constant we just got, to produce its value
*/ */
pConst = static_cast< AstConstant* >(pDecl); pConst = static_cast< AstConstant* >(pDecl);
return pConst->getConstValue()->eval_internal(ek); return pConst->getConstValue()->eval_internal();
} }
OString AstExpression::toString() OString AstExpression::toString()
......
...@@ -2719,7 +2719,7 @@ enumerator : ...@@ -2719,7 +2719,7 @@ enumerator :
if ( $3 && pScope && pScope->getScopeNodeType() == NT_enum) if ( $3 && pScope && pScope->getScopeNodeType() == NT_enum)
{ {
$3->evaluate(EK_const); $3->evaluate();
if ( $3->coerce(ET_long) ) if ( $3->coerce(ET_long) )
{ {
pEnum = static_cast<AstEnum*>(pScope); pEnum = static_cast<AstEnum*>(pScope);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment