Return unique_ptr from AstExpression::eval_* functions

...generally, idlc leaks most memory, and e.g. trying to turn
AstExpression::m_exprValue into a unique_ptr would fail because
AstExpression::eval_symbol returns a pointer to an object "owned" elsewhere (but
never actually deleted by its owner).  So improvement of idlc ends here---for
one, it does not improve anything to try and make idlc not leak memory, and for
another, idlc is doomed to go away anyway.

Change-Id: I36f54130c8bfd1933126ae7f8a982e50d9bc616e
This commit is contained in:
Stephan Bergmann 2015-09-27 19:23:05 +02:00
parent 1f8723bf91
commit a5bb6eff86
2 changed files with 16 additions and 12 deletions

View File

@ -19,6 +19,10 @@
#ifndef INCLUDED_IDLC_INC_IDLC_ASTEXPRESSION_HXX #ifndef INCLUDED_IDLC_INC_IDLC_ASTEXPRESSION_HXX
#define INCLUDED_IDLC_INC_IDLC_ASTEXPRESSION_HXX #define INCLUDED_IDLC_INC_IDLC_ASTEXPRESSION_HXX
#include <sal/config.h>
#include <memory>
#include <idlc/idlc.hxx> #include <idlc/idlc.hxx>
// Enum to define all the different operators to combine expressions // Enum to define all the different operators to combine expressions
@ -120,9 +124,9 @@ private:
// Fill out the lineno, filename and definition scope details // Fill out the lineno, filename and definition scope details
void fillDefinitionDetails(); void fillDefinitionDetails();
// Evaluate different sets of operators // Evaluate different sets of operators
AstExprValue* eval_bin_op(); std::unique_ptr<AstExprValue> eval_bin_op();
AstExprValue* eval_bit_op(); std::unique_ptr<AstExprValue> eval_bit_op();
AstExprValue* eval_un_op(); std::unique_ptr<AstExprValue> eval_un_op();
AstExprValue* eval_symbol(); AstExprValue* eval_symbol();
AstScope* m_pScope; // scope defined in AstScope* m_pScope; // scope defined in

View File

@ -885,19 +885,19 @@ void AstExpression::evaluate()
case EC_mul: case EC_mul:
case EC_div: case EC_div:
case EC_mod: case EC_mod:
m_exprValue = eval_bin_op(); m_exprValue = eval_bin_op().release();
break; break;
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(); m_exprValue = eval_bit_op().release();
break; break;
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(); m_exprValue = eval_un_op().release();
break; break;
case EC_symbol: case EC_symbol:
m_exprValue = eval_symbol(); m_exprValue = eval_symbol();
@ -907,7 +907,7 @@ void AstExpression::evaluate()
} }
} }
AstExprValue* AstExpression::eval_bin_op() std::unique_ptr<AstExprValue> AstExpression::eval_bin_op()
{ {
ExprType eType = ET_double; ExprType eType = ET_double;
@ -955,10 +955,10 @@ AstExprValue* AstExpression::eval_bin_op()
return NULL; return NULL;
} }
return retval.release(); return retval;
} }
AstExprValue* AstExpression::eval_bit_op() std::unique_ptr<AstExprValue> AstExpression::eval_bit_op()
{ {
if (m_subExpr1 == NULL || m_subExpr2 == NULL) if (m_subExpr1 == NULL || m_subExpr2 == NULL)
return NULL; return NULL;
@ -997,10 +997,10 @@ AstExprValue* AstExpression::eval_bit_op()
return NULL; return NULL;
} }
return retval.release(); return retval;
} }
AstExprValue* AstExpression::eval_un_op() std::unique_ptr<AstExprValue> AstExpression::eval_un_op()
{ {
if (m_subExpr1 == NULL) if (m_subExpr1 == NULL)
return NULL; return NULL;
@ -1030,7 +1030,7 @@ AstExprValue* AstExpression::eval_un_op()
return NULL; return NULL;
} }
return retval.release(); return retval;
} }
AstExprValue* AstExpression::eval_symbol() AstExprValue* AstExpression::eval_symbol()