ExpressionParser: Return unique_ptr from copy (#27098)
- We need copy().release() on many of these calls because nodes in the tree call 'copy' explicitly. It's not really different to the code that's there now, but it's not pretty either. Some of these will go away in the upcoming commit
This commit is contained in:
+18
-12
@@ -1025,7 +1025,7 @@ ExpressionPtr Expression::importSubNames(const std::map<std::string,std::string>
|
||||
ImportSubNamesExpressionVisitor v(subNameMap);
|
||||
auto res = copy();
|
||||
res->visit(v);
|
||||
return ExpressionPtr(res);
|
||||
return res;
|
||||
}
|
||||
|
||||
class UpdateLabelExpressionVisitor : public ExpressionVisitor {
|
||||
@@ -1057,7 +1057,7 @@ ExpressionPtr Expression::updateLabelReference(
|
||||
UpdateLabelExpressionVisitor v(obj,ref,newLabel);
|
||||
auto expr = copy();
|
||||
expr->visit(v);
|
||||
return ExpressionPtr(expr);
|
||||
return expr;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
@@ -1102,7 +1102,7 @@ ExpressionPtr Expression::replaceObject(const DocumentObject *parent,
|
||||
auto expr = copy();
|
||||
v.collect = false;
|
||||
expr->visit(v);
|
||||
return ExpressionPtr(expr);
|
||||
return expr;
|
||||
}
|
||||
|
||||
App::any Expression::getValueAsAny() const {
|
||||
@@ -1177,8 +1177,9 @@ void Expression::toString(std::ostream &ss, bool persistent, bool checkPriority,
|
||||
c->toString(ss,persistent);
|
||||
}
|
||||
|
||||
Expression* Expression::copy() const {
|
||||
auto expr = _copy();
|
||||
ExpressionPtr Expression::copy() const
|
||||
{
|
||||
auto expr = std::unique_ptr<Expression>(_copy());
|
||||
copy_vector(expr->components,components);
|
||||
expr->comment = comment;
|
||||
return expr;
|
||||
@@ -1259,7 +1260,7 @@ NumberExpression::NumberExpression(const DocumentObject *_owner, const Quantity
|
||||
|
||||
Expression *NumberExpression::simplify() const
|
||||
{
|
||||
return copy();
|
||||
return copy().release();
|
||||
}
|
||||
|
||||
Expression *NumberExpression::_copy() const
|
||||
@@ -1556,7 +1557,7 @@ void OperatorExpression::_toString(std::ostream &s, bool persistent,int) const
|
||||
|
||||
Expression *OperatorExpression::_copy() const
|
||||
{
|
||||
return new OperatorExpression(owner, left->copy(), op, right->copy());
|
||||
return new OperatorExpression(owner, left->copy().release(), op, right->copy().release());
|
||||
}
|
||||
|
||||
int OperatorExpression::priority() const
|
||||
@@ -2770,7 +2771,7 @@ Expression *FunctionExpression::_copy() const
|
||||
std::vector<Expression*> a;
|
||||
|
||||
while (i != args.end()) {
|
||||
a.push_back((*i)->copy());
|
||||
a.push_back((*i)->copy().release());
|
||||
++i;
|
||||
}
|
||||
return new FunctionExpression(owner, f, std::string(fname), std::move(a));
|
||||
@@ -2879,7 +2880,7 @@ void VariableExpression::_toString(std::ostream &ss, bool persistent,int) const
|
||||
|
||||
Expression *VariableExpression::simplify() const
|
||||
{
|
||||
return copy();
|
||||
return copy().release();
|
||||
}
|
||||
|
||||
Expression *VariableExpression::_copy() const
|
||||
@@ -3084,7 +3085,7 @@ StringExpression::~StringExpression() {
|
||||
|
||||
Expression *StringExpression::simplify() const
|
||||
{
|
||||
return copy();
|
||||
return copy().release();
|
||||
}
|
||||
|
||||
void StringExpression::_toString(std::ostream &ss, bool,int) const
|
||||
@@ -3168,7 +3169,12 @@ void ConditionalExpression::_toString(std::ostream &ss, bool persistent,int) con
|
||||
|
||||
Expression *ConditionalExpression::_copy() const
|
||||
{
|
||||
return new ConditionalExpression(owner, condition->copy(), trueExpr->copy(), falseExpr->copy());
|
||||
return new ConditionalExpression(
|
||||
owner,
|
||||
condition->copy().release(),
|
||||
trueExpr->copy().release(),
|
||||
falseExpr->copy().release()
|
||||
);
|
||||
}
|
||||
|
||||
int ConditionalExpression::priority() const
|
||||
@@ -3266,7 +3272,7 @@ Expression *RangeExpression::_copy() const
|
||||
|
||||
Expression *RangeExpression::simplify() const
|
||||
{
|
||||
return copy();
|
||||
return copy().release();
|
||||
}
|
||||
|
||||
void RangeExpression::_getIdentifiers(std::map<App::ObjectIdentifier,bool> &deps) const
|
||||
|
||||
@@ -366,7 +366,7 @@ public:
|
||||
static ExpressionPtr parse(const App::DocumentObject* owner, const std::string& buffer);
|
||||
|
||||
/// Copy an expression.
|
||||
Expression * copy() const;
|
||||
ExpressionPtr copy() const;
|
||||
|
||||
/**
|
||||
* @brief Get the operator priority.
|
||||
|
||||
@@ -542,7 +542,7 @@ public:
|
||||
void setPyValue(PyObject* pyobj, bool owned = false);
|
||||
Expression* simplify() const override
|
||||
{
|
||||
return copy();
|
||||
return copy().release();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
@@ -2086,10 +2086,10 @@ PropertySheet::BindingType PropertySheet::getBinding(
|
||||
}
|
||||
}
|
||||
if (pStart) {
|
||||
pStart->reset(expr->getArgs()[1]->copy());
|
||||
*pStart = expr->getArgs()[1]->copy();
|
||||
}
|
||||
if (pEnd) {
|
||||
pEnd->reset(expr->getArgs()[2]->copy());
|
||||
*pEnd = expr->getArgs()[2]->copy();
|
||||
}
|
||||
return href ? BindingHiddenRef : BindingNormal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user