Skip to content

Commit dd83410

Browse files
authored
Move Type.needsCopyOrPostblit to typesem (#22194)
1 parent 503c3b0 commit dd83410

File tree

5 files changed

+22
-32
lines changed

5 files changed

+22
-32
lines changed

compiler/src/dmd/cxxfrontend.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,12 @@ bool needsDestruction(Type type)
10781078
return dmd.typesem.needsDestruction(type);
10791079
}
10801080

1081+
bool needsCopyOrPostblit(Type type)
1082+
{
1083+
import dmd.typesem;
1084+
return dmd.typesem.needsCopyOrPostblit(type);
1085+
}
1086+
10811087
/***********************************************************
10821088
* typinf.d
10831089
*/

compiler/src/dmd/frontend.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,6 @@ class Type : public ASTNode
20882088
virtual int32_t hasWild() const;
20892089
virtual Type* nextOf();
20902090
Type* baseElemOf();
2091-
virtual bool needsCopyOrPostblit();
20922091
virtual TypeBasic* isTypeBasic();
20932092
TypeFunction* isPtrToFunction();
20942093
TypeFunction* isFunction_Delegate_PtrToFunction();
@@ -4428,7 +4427,6 @@ class TypeEnum final : public Type
44284427
const char* kind() const override;
44294428
TypeEnum* syntaxCopy() override;
44304429
bool isScalar() override;
4431-
bool needsCopyOrPostblit() override;
44324430
Type* nextOf() override;
44334431
void accept(Visitor* v) override;
44344432
};
@@ -4652,7 +4650,6 @@ class TypeSArray final : public TypeArray
46524650
const char* kind() const override;
46534651
TypeSArray* syntaxCopy() override;
46544652
bool isIncomplete();
4655-
bool needsCopyOrPostblit() override;
46564653
void accept(Visitor* v) override;
46574654
};
46584655

@@ -4675,7 +4672,6 @@ class TypeStruct final : public Type
46754672
static TypeStruct* create(StructDeclaration* sym);
46764673
const char* kind() const override;
46774674
TypeStruct* syntaxCopy() override;
4678-
bool needsCopyOrPostblit() override;
46794675
void accept(Visitor* v) override;
46804676
};
46814677

compiler/src/dmd/mtype.d

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,15 +1206,6 @@ extern (C++) abstract class Type : ASTNode
12061206
return m;
12071207
}
12081208

1209-
/********************************
1210-
* true if when type is copied, it needs a copy constructor or postblit
1211-
* applied. Only applies to value types, not ref types.
1212-
*/
1213-
bool needsCopyOrPostblit()
1214-
{
1215-
return false;
1216-
}
1217-
12181209
// For eliminating dynamic_cast
12191210
TypeBasic isTypeBasic()
12201211
{
@@ -1650,11 +1641,6 @@ extern (C++) final class TypeSArray : TypeArray
16501641
return dim.isIntegerExp() && dim.isIntegerExp().getInteger() == 0;
16511642
}
16521643

1653-
override bool needsCopyOrPostblit()
1654-
{
1655-
return next.needsCopyOrPostblit();
1656-
}
1657-
16581644
override void accept(Visitor v)
16591645
{
16601646
v.visit(this);
@@ -2346,11 +2332,6 @@ extern (C++) final class TypeStruct : Type
23462332
return this;
23472333
}
23482334

2349-
override bool needsCopyOrPostblit()
2350-
{
2351-
return sym.hasCopyCtor || sym.postblit;
2352-
}
2353-
23542335
override void accept(Visitor v)
23552336
{
23562337
v.visit(this);
@@ -2384,11 +2365,6 @@ extern (C++) final class TypeEnum : Type
23842365
return this.memType().isScalar();
23852366
}
23862367

2387-
override bool needsCopyOrPostblit()
2388-
{
2389-
return this.memType().needsCopyOrPostblit();
2390-
}
2391-
23922368
override Type nextOf()
23932369
{
23942370
return this.memType().nextOf();

compiler/src/dmd/mtype.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ class Type : public ASTNode
248248
virtual int hasWild() const;
249249
virtual Type *nextOf();
250250
Type *baseElemOf();
251-
virtual bool needsCopyOrPostblit();
252251

253252
TypeFunction *toTypeFunction();
254253

@@ -346,7 +345,6 @@ class TypeSArray final : public TypeArray
346345
const char *kind() override;
347346
TypeSArray *syntaxCopy() override;
348347
bool isIncomplete();
349-
bool needsCopyOrPostblit() override;
350348

351349
void accept(Visitor *v) override { v->visit(this); }
352350
};
@@ -623,7 +621,6 @@ class TypeStruct final : public Type
623621
static TypeStruct *create(StructDeclaration *sym);
624622
const char *kind() override;
625623
TypeStruct *syntaxCopy() override;
626-
bool needsCopyOrPostblit() override;
627624

628625
void accept(Visitor *v) override { v->visit(this); }
629626
};
@@ -636,7 +633,6 @@ class TypeEnum final : public Type
636633
const char *kind() override;
637634
TypeEnum *syntaxCopy() override;
638635
bool isScalar() override;
639-
bool needsCopyOrPostblit() override;
640636
Type *nextOf() override;
641637

642638
void accept(Visitor *v) override { v->visit(this); }
@@ -780,4 +776,5 @@ namespace dmd
780776
bool isUnsigned(Type* type);
781777
bool needsNested(Type* type);
782778
bool needsDestruction(Type* type);
779+
bool needsCopyOrPostblit(Type* type);
783780
}

compiler/src/dmd/typesem.d

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ private inout(TypeNext) isTypeNext(inout Type _this)
8383
}
8484
}
8585

86+
/********************************
87+
* true if when type is copied, it needs a copy constructor or postblit
88+
* applied. Only applies to value types, not ref types.
89+
*/
90+
bool needsCopyOrPostblit(Type _this)
91+
{
92+
if (auto tsa = _this.isTypeSArray())
93+
return tsa.next.needsCopyOrPostblit();
94+
else if (auto ts = _this.isTypeStruct())
95+
return ts.sym.hasCopyCtor || ts.sym.postblit;
96+
else if (auto te = _this.isTypeEnum())
97+
return te.memType().needsCopyOrPostblit();
98+
return false;
99+
}
100+
86101
/********************************
87102
* true if when type goes out of scope, it needs a destructor applied.
88103
* Only applies to value types, not ref types.

0 commit comments

Comments
 (0)