Skip to content

Commit

Permalink
Add a LangPlugin.mustCallerCallDtorOnArguments() hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
Syniurge committed Oct 29, 2019
1 parent 10b2464 commit 361006f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions dmd/cpp/calypso.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class LangPlugin final : public ::LangPlugin, public ::ForeignCodeGen
Expression *callCpCtor(Scope *sc, Expression *e) override;
Expression *constructCtorCall(const Loc& loc, Scope *sc, Expression *e1, Expression* e2) override;

bool mustCallerCallDtorOnArguments() override { return true; }

::FuncDeclaration *searchOpEqualsForXopEquals(::StructDeclaration *sd, Scope *sc) override;

Expression* op_overload(Expression* e, Scope* sc, TOK* pop = nullptr) override;
Expand Down
2 changes: 2 additions & 0 deletions dmd/dimport.d
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ public:
Expression callCpCtor(Scope *sc, Expression e);
Expression constructCtorCall(const ref Loc loc, Scope* sc, Expression e1, Expression e2);

bool mustCallerCallDtorOnArguments();

FuncDeclaration searchOpEqualsForXopEquals(StructDeclaration sd, Scope *sc);

// ===== - - - - - ===== //
Expand Down
12 changes: 9 additions & 3 deletions dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2312,12 +2312,18 @@ private bool functionParameters(const ref Loc loc, Scope* sc,
if (!isRef)
{
arg = doCopyOrMove(sc, arg, parameter ? parameter.type : null);
if (tv.getAggregateSym().langPlugin()) // D20180120T151603 CALYPSO NOTE: in D dtors on value arguments are called in by the callee, in C++ by the caller.
// But in order to simplify the code and make calling D functions taking C++ struct or class arguments from C++ possible, D sticks to the C++ way, i.e C++ dtors always get called by the caller

// D20180120T151603 CALYPSO NOTE: in D dtors on value arguments are called in
// by the callee, in C++ by the caller.
// But in order to simplify the code and make calling D functions taking
// C++ struct or class arguments from C++ possible, D sticks to the C++ way,
// i.e C++ dtors always get called by the caller.
auto lp = tv.getAggregateSym().langPlugin();
if (lp && lp.mustCallerCallDtorOnArguments())
arg = arg.addDtorHook(sc);
}
else if (!arg.isLvalue())
arg = arg.addDtorHook(sc); // CALYPSO: for an rvalue passed to a scope ref aggregate parameter, the dtor has to get called afterwards // LDC 1.17 FIXME?
arg = arg.addDtorHook(sc); // CALYPSO: for an rvalue passed to a ref aggregate parameter, the dtor has to get called afterwards
}
}

Expand Down
2 changes: 2 additions & 0 deletions dmd/import.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class LangPlugin
virtual Expression *callCpCtor(Scope *sc, Expression *e) = 0;
virtual Expression *constructCtorCall(const Loc& loc, Scope *sc, Expression *e1, Expression* e2) = 0;

virtual bool mustCallerCallDtorOnArguments() = 0;

virtual FuncDeclaration *searchOpEqualsForXopEquals(StructDeclaration *sd, Scope *sc) = 0;

// ===== - - - - - ===== //
Expand Down

0 comments on commit 361006f

Please sign in to comment.