diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-02-16 10:15:48 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-02-16 12:42:04 +0200 |
commit | a6a46aad5118fca8b27205e9c0a9772af322235a (patch) | |
tree | 90af16b208899eaa593f6ea43b00608b5de21bfb /idlc | |
parent | d00431fd36eefe52d87dbc3d254d9d0ae464a333 (diff) |
convert ExprComb to scoped enum
and drop unused EC_bit_neg enumerator
Change-Id: I8a93310cd849cee56fcf628424d96005f89ba799
Diffstat (limited to 'idlc')
-rw-r--r-- | idlc/inc/astexpression.hxx | 31 | ||||
-rw-r--r-- | idlc/source/astexpression.cxx | 101 | ||||
-rw-r--r-- | idlc/source/parser.y | 24 |
3 files changed, 73 insertions, 83 deletions
diff --git a/idlc/inc/astexpression.hxx b/idlc/inc/astexpression.hxx index e092ffd99fd0..788d7a2afc6c 100644 --- a/idlc/inc/astexpression.hxx +++ b/idlc/inc/astexpression.hxx @@ -26,23 +26,22 @@ #include <idlc.hxx> // Enum to define all the different operators to combine expressions -enum ExprComb +enum class ExprComb { - EC_add, // '+' - EC_minus, // '-' - EC_mul, // '*' - EC_div, // '/' - EC_mod, // '%' - EC_or, // '|' - EC_xor, // '^' - EC_and, // '&' - EC_left, // '<<' - EC_right, // '>>' - EC_u_plus, // unary '+' - EC_u_minus, // unary '-' - EC_bit_neg, // '~' - EC_none, // No operator (missing) - EC_symbol // a symbol (function or constant name) + Add, // '+' + Minus, // '-' + Mul, // '*' + Div, // '/' + Mod, // '%' + Or, // '|' + Xor, // '^' + And, // '&' + Left, // '<<' + Right, // '>>' + UPlus, // unary '+' + UMinus, // unary '-' + NONE, // No operator (missing) + Symbol // a symbol (function or constant name) }; // Enum to define expression type diff --git a/idlc/source/astexpression.cxx b/idlc/source/astexpression.cxx index d18066251206..65451a5f231f 100644 --- a/idlc/source/astexpression.cxx +++ b/idlc/source/astexpression.cxx @@ -41,7 +41,7 @@ AstExpression::AstExpression(ExprComb c, AstExpression *pExpr1, AstExpression *p } AstExpression::AstExpression(sal_Int32 l) - : m_combOperator(EC_none) + : m_combOperator(ExprComb::NONE) , m_subExpr1(nullptr) , m_subExpr2(nullptr) , m_exprValue(nullptr) @@ -55,7 +55,7 @@ AstExpression::AstExpression(sal_Int32 l) } AstExpression::AstExpression(sal_Int32 l, ExprType et) - : m_combOperator(EC_none) + : m_combOperator(ExprComb::NONE) , m_subExpr1(nullptr) , m_subExpr2(nullptr) , m_exprValue(nullptr) @@ -69,7 +69,7 @@ AstExpression::AstExpression(sal_Int32 l, ExprType et) } AstExpression::AstExpression(sal_Int64 h) - : m_combOperator(EC_none) + : m_combOperator(ExprComb::NONE) , m_subExpr1(nullptr) , m_subExpr2(nullptr) , m_exprValue(nullptr) @@ -83,7 +83,7 @@ AstExpression::AstExpression(sal_Int64 h) } AstExpression::AstExpression(sal_uInt64 uh) - : m_combOperator(EC_none) + : m_combOperator(ExprComb::NONE) , m_subExpr1(nullptr) , m_subExpr2(nullptr) , m_exprValue(nullptr) @@ -97,7 +97,7 @@ AstExpression::AstExpression(sal_uInt64 uh) } AstExpression::AstExpression(double d) - : m_combOperator(EC_none) + : m_combOperator(ExprComb::NONE) , m_subExpr1(nullptr) , m_subExpr2(nullptr) , m_exprValue(nullptr) @@ -111,7 +111,7 @@ AstExpression::AstExpression(double d) } AstExpression::AstExpression(OString* scopedName) - : m_combOperator(EC_symbol) + : m_combOperator(ExprComb::Symbol) , m_subExpr1(nullptr) , m_subExpr2(nullptr) , m_exprValue(nullptr) @@ -801,29 +801,28 @@ void AstExpression::evaluate() */ switch (m_combOperator) { - case EC_add: - case EC_minus: - case EC_mul: - case EC_div: - case EC_mod: + case ExprComb::Add: + case ExprComb::Minus: + case ExprComb::Mul: + case ExprComb::Div: + case ExprComb::Mod: m_exprValue = eval_bin_op().release(); break; - case EC_or: - case EC_xor: - case EC_and: - case EC_left: - case EC_right: + case ExprComb::Or: + case ExprComb::Xor: + case ExprComb::And: + case ExprComb::Left: + case ExprComb::Right: m_exprValue = eval_bit_op().release(); break; - case EC_u_plus: - case EC_u_minus: - case EC_bit_neg: + case ExprComb::UPlus: + case ExprComb::UMinus: m_exprValue = eval_un_op().release(); break; - case EC_symbol: + case ExprComb::Symbol: m_exprValue = eval_symbol(); break; - case EC_none: + case ExprComb::NONE: break; } } @@ -832,7 +831,7 @@ std::unique_ptr<AstExprValue> AstExpression::eval_bin_op() { ExprType eType = ET_double; - if ( m_combOperator == EC_mod ) + if ( m_combOperator == ExprComb::Mod ) eType = ET_hyper; if (m_subExpr1 == nullptr || m_subExpr2 == nullptr) @@ -853,21 +852,21 @@ std::unique_ptr<AstExprValue> AstExpression::eval_bin_op() switch (m_combOperator) { - case EC_mod: + case ExprComb::Mod: if (m_subExpr2->getExprValue()->u.hval == 0) return nullptr; retval->u.hval = m_subExpr1->getExprValue()->u.hval % m_subExpr2->getExprValue()->u.hval; break; - case EC_add: + case ExprComb::Add: retval->u.dval = m_subExpr1->getExprValue()->u.dval + m_subExpr2->getExprValue()->u.dval; break; - case EC_minus: + case ExprComb::Minus: retval->u.dval = m_subExpr1->getExprValue()->u.dval - m_subExpr2->getExprValue()->u.dval; break; - case EC_mul: + case ExprComb::Mul: retval->u.dval = m_subExpr1->getExprValue()->u.dval * m_subExpr2->getExprValue()->u.dval; break; - case EC_div: + case ExprComb::Div: if (m_subExpr2->getExprValue()->u.dval == 0.0) return nullptr; retval->u.dval = m_subExpr1->getExprValue()->u.dval / m_subExpr2->getExprValue()->u.dval; @@ -899,19 +898,19 @@ std::unique_ptr<AstExprValue> AstExpression::eval_bit_op() switch (m_combOperator) { - case EC_or: + case ExprComb::Or: retval->u.lval = m_subExpr1->getExprValue()->u.lval | m_subExpr2->getExprValue()->u.lval; break; - case EC_xor: + case ExprComb::Xor: retval->u.lval = m_subExpr1->getExprValue()->u.lval ^ m_subExpr2->getExprValue()->u.lval; break; - case EC_and: + case ExprComb::And: retval->u.lval = m_subExpr1->getExprValue()->u.lval & m_subExpr2->getExprValue()->u.lval; break; - case EC_left: + case ExprComb::Left: retval->u.lval = m_subExpr1->getExprValue()->u.lval << m_subExpr2->getExprValue()->u.lval; break; - case EC_right: + case ExprComb::Right: retval->u.lval = m_subExpr1->getExprValue()->u.lval >> m_subExpr2->getExprValue()->u.lval; break; default: @@ -936,17 +935,12 @@ std::unique_ptr<AstExprValue> AstExpression::eval_un_op() switch (m_combOperator) { - case EC_u_plus: + case ExprComb::UPlus: retval->u.lval = m_subExpr1->getExprValue()->u.lval; break; - case EC_u_minus: + case ExprComb::UMinus: retval->u.lval = -(m_subExpr1->getExprValue()->u.lval); break; - case EC_bit_neg: - if (!m_subExpr1->coerce(ET_long)) - return nullptr; - retval->u.lval = ~m_subExpr1->getExprValue()->u.lval; - break; default: return nullptr; } @@ -1011,7 +1005,7 @@ AstExprValue* AstExpression::eval_symbol() OString AstExpression::toString() { OString exprStr; - if ( m_combOperator == EC_symbol ) + if ( m_combOperator == ExprComb::Symbol ) return m_pSymbolicName ? *m_pSymbolicName : OString("<Undefined Name>"); if ( m_exprValue ) @@ -1049,15 +1043,12 @@ OString AstExpression::toString() switch (m_combOperator) { - case EC_u_plus: + case ExprComb::UPlus: exprStr += OString("+"); break; - case EC_u_minus: + case ExprComb::UMinus: exprStr += OString("-"); break; - case EC_bit_neg: - exprStr += OString("~"); - break; default: break; } @@ -1065,34 +1056,34 @@ OString AstExpression::toString() exprStr += m_subExpr1->toString(); switch (m_combOperator) { - case EC_add: + case ExprComb::Add: exprStr += OString(" + "); break; - case EC_minus: + case ExprComb::Minus: exprStr += OString(" - "); break; - case EC_mul: + case ExprComb::Mul: exprStr += OString(" * "); break; - case EC_div: + case ExprComb::Div: exprStr += OString(" / "); break; - case EC_mod: + case ExprComb::Mod: exprStr += OString(" % "); break; - case EC_or: + case ExprComb::Or: exprStr += OString(" | "); break; - case EC_xor: + case ExprComb::Xor: exprStr += OString(" ^ "); break; - case EC_and: + case ExprComb::And: exprStr += OString(" & "); break; - case EC_left: + case ExprComb::Left: exprStr += OString(" << "); break; - case EC_right: + case ExprComb::Right: exprStr += OString(" >> "); break; default: diff --git a/idlc/source/parser.y b/idlc/source/parser.y index 3a12f4cef5fe..c2c55d16c13b 100644 --- a/idlc/source/parser.y +++ b/idlc/source/parser.y @@ -1314,7 +1314,7 @@ or_expr : xor_expr | or_expr '|' xor_expr { - $$ = new AstExpression(EC_or, $1, $3); + $$ = new AstExpression(ExprComb::Or, $1, $3); } ; @@ -1322,7 +1322,7 @@ xor_expr : and_expr | xor_expr '^' and_expr { - $$ = new AstExpression(EC_xor, $1, $3); + $$ = new AstExpression(ExprComb::Xor, $1, $3); } ; @@ -1330,7 +1330,7 @@ and_expr : shift_expr | and_expr '&' shift_expr { - $$ = new AstExpression(EC_and, $1, $3); + $$ = new AstExpression(ExprComb::And, $1, $3); } ; @@ -1338,11 +1338,11 @@ shift_expr : add_expr | shift_expr IDL_LEFTSHIFT add_expr { - $$ = new AstExpression(EC_left, $1, $3); + $$ = new AstExpression(ExprComb::Left, $1, $3); } | shift_expr IDL_RIGHTSHIFT add_expr { - $$ = new AstExpression(EC_right, $1, $3); + $$ = new AstExpression(ExprComb::Right, $1, $3); } ; @@ -1350,11 +1350,11 @@ add_expr : mult_expr | add_expr '+' mult_expr { - $$ = new AstExpression(EC_add, $1, $3); + $$ = new AstExpression(ExprComb::Add, $1, $3); } | add_expr '-' mult_expr { - $$ = new AstExpression(EC_minus, $1, $3); + $$ = new AstExpression(ExprComb::Minus, $1, $3); } ; @@ -1362,15 +1362,15 @@ mult_expr : unary_expr | mult_expr '*' unary_expr { - $$ = new AstExpression(EC_mul, $1, $3); + $$ = new AstExpression(ExprComb::Mul, $1, $3); } | mult_expr '/' unary_expr { - $$ = new AstExpression(EC_div, $1, $3); + $$ = new AstExpression(ExprComb::Div, $1, $3); } | mult_expr '%' unary_expr { - $$ = new AstExpression(EC_mod, $1, $3); + $$ = new AstExpression(ExprComb::Mod, $1, $3); } ; @@ -1378,11 +1378,11 @@ unary_expr : primary_expr | '+' primary_expr { - $$ = new AstExpression(EC_u_plus, $2, nullptr); + $$ = new AstExpression(ExprComb::UPlus, $2, nullptr); } | '-' primary_expr { - $$ = new AstExpression(EC_u_minus, $2, nullptr); + $$ = new AstExpression(ExprComb::UMinus, $2, nullptr); } | '~' primary_expr { |