Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/src/dmd/cxxfrontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,12 @@ bool needsDestruction(Type type)
return dmd.typesem.needsDestruction(type);
}

bool needsCopyOrPostblit(Type type)
{
import dmd.typesem;
return dmd.typesem.needsCopyOrPostblit(type);
}

/***********************************************************
* typinf.d
*/
Expand Down
4 changes: 0 additions & 4 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,6 @@ class Type : public ASTNode
virtual int32_t hasWild() const;
virtual Type* nextOf();
Type* baseElemOf();
virtual bool needsCopyOrPostblit();
virtual TypeBasic* isTypeBasic();
TypeFunction* isPtrToFunction();
TypeFunction* isFunction_Delegate_PtrToFunction();
Expand Down Expand Up @@ -4428,7 +4427,6 @@ class TypeEnum final : public Type
const char* kind() const override;
TypeEnum* syntaxCopy() override;
bool isScalar() override;
bool needsCopyOrPostblit() override;
Type* nextOf() override;
void accept(Visitor* v) override;
};
Expand Down Expand Up @@ -4652,7 +4650,6 @@ class TypeSArray final : public TypeArray
const char* kind() const override;
TypeSArray* syntaxCopy() override;
bool isIncomplete();
bool needsCopyOrPostblit() override;
void accept(Visitor* v) override;
};

Expand All @@ -4675,7 +4672,6 @@ class TypeStruct final : public Type
static TypeStruct* create(StructDeclaration* sym);
const char* kind() const override;
TypeStruct* syntaxCopy() override;
bool needsCopyOrPostblit() override;
void accept(Visitor* v) override;
};

Expand Down
24 changes: 0 additions & 24 deletions compiler/src/dmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -1206,15 +1206,6 @@ extern (C++) abstract class Type : ASTNode
return m;
}

/********************************
* true if when type is copied, it needs a copy constructor or postblit
* applied. Only applies to value types, not ref types.
*/
bool needsCopyOrPostblit()
{
return false;
}

// For eliminating dynamic_cast
TypeBasic isTypeBasic()
{
Expand Down Expand Up @@ -1651,11 +1642,6 @@ extern (C++) final class TypeSArray : TypeArray
return dim.isIntegerExp() && dim.isIntegerExp().getInteger() == 0;
}

override bool needsCopyOrPostblit()
{
return next.needsCopyOrPostblit();
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -2347,11 +2333,6 @@ extern (C++) final class TypeStruct : Type
return this;
}

override bool needsCopyOrPostblit()
{
return sym.hasCopyCtor || sym.postblit;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -2385,11 +2366,6 @@ extern (C++) final class TypeEnum : Type
return this.memType().isScalar();
}

override bool needsCopyOrPostblit()
{
return this.memType().needsCopyOrPostblit();
}

override Type nextOf()
{
return this.memType().nextOf();
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dmd/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ class Type : public ASTNode
virtual int hasWild() const;
virtual Type *nextOf();
Type *baseElemOf();
virtual bool needsCopyOrPostblit();

TypeFunction *toTypeFunction();

Expand Down Expand Up @@ -346,7 +345,6 @@ class TypeSArray final : public TypeArray
const char *kind() override;
TypeSArray *syntaxCopy() override;
bool isIncomplete();
bool needsCopyOrPostblit() override;

void accept(Visitor *v) override { v->visit(this); }
};
Expand Down Expand Up @@ -623,7 +621,6 @@ class TypeStruct final : public Type
static TypeStruct *create(StructDeclaration *sym);
const char *kind() override;
TypeStruct *syntaxCopy() override;
bool needsCopyOrPostblit() override;

void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -636,7 +633,6 @@ class TypeEnum final : public Type
const char *kind() override;
TypeEnum *syntaxCopy() override;
bool isScalar() override;
bool needsCopyOrPostblit() override;
Type *nextOf() override;

void accept(Visitor *v) override { v->visit(this); }
Expand Down Expand Up @@ -780,4 +776,5 @@ namespace dmd
bool isUnsigned(Type* type);
bool needsNested(Type* type);
bool needsDestruction(Type* type);
bool needsCopyOrPostblit(Type* type);
}
15 changes: 15 additions & 0 deletions compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ private inout(TypeNext) isTypeNext(inout Type _this)
}
}

/********************************
* true if when type is copied, it needs a copy constructor or postblit
* applied. Only applies to value types, not ref types.
*/
bool needsCopyOrPostblit(Type _this)
{
if (auto tsa = _this.isTypeSArray())
return tsa.next.needsCopyOrPostblit();
else if (auto ts = _this.isTypeStruct())
return ts.sym.hasCopyCtor || ts.sym.postblit;
else if (auto te = _this.isTypeEnum())
return te.memType().needsCopyOrPostblit();
return false;
}

/********************************
* true if when type goes out of scope, it needs a destructor applied.
* Only applies to value types, not ref types.
Expand Down
Loading