Skip to content

Commit

Permalink
Move mtype.Type.isZeroInit to typesem.d (#16676)
Browse files Browse the repository at this point in the history
  • Loading branch information
RazvanN7 committed Jul 9, 2024
1 parent 40ea009 commit 8053445
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 105 deletions.
6 changes: 6 additions & 0 deletions compiler/src/dmd/cxxfrontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ Covariant covariant(Type src, Type t, StorageClass* pstc = null, bool
return dmd.typesem.covariant(src, t, pstc, cppCovariant);
}

bool isZeroInit(Type t, const ref Loc loc)
{
import dmd.typesem;
return dmd.typesem.isZeroInit(t, loc);
}

bool isBaseOf(Type tthis, Type t, int* poffset)
{
import dmd.typesem;
Expand Down
12 changes: 0 additions & 12 deletions compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,6 @@ class Type : public ASTNode
virtual ClassDeclaration* isClassHandle();
virtual structalign_t alignment();
virtual Expression* defaultInitLiteral(const Loc& loc);
virtual bool isZeroInit(const Loc& loc);
virtual int32_t hasWild() const;
virtual bool hasVoidInitPointers();
virtual bool hasUnsafeBitpatterns();
Expand Down Expand Up @@ -4213,7 +4212,6 @@ class TypeAArray final : public TypeArray
static TypeAArray* create(Type* t, Type* index);
const char* kind() const override;
TypeAArray* syntaxCopy() override;
bool isZeroInit(const Loc& loc) override;
bool isBoolean() override;
void accept(Visitor* v) override;
};
Expand All @@ -4233,7 +4231,6 @@ class TypeBasic final : public Type
bool iscomplex() override;
bool isscalar() override;
bool isunsigned() override;
bool isZeroInit(const Loc& loc) override;
bool hasUnsafeBitpatterns() override;
TypeBasic* isTypeBasic() override;
void accept(Visitor* v) override;
Expand All @@ -4259,7 +4256,6 @@ class TypeClass final : public Type
TypeClass* syntaxCopy() override;
ClassDeclaration* isClassHandle() override;
uint8_t deduceWild(Type* t, bool isRef) override;
bool isZeroInit(const Loc& loc) override;
bool isscope() override;
bool isBoolean() override;
void accept(Visitor* v) override;
Expand All @@ -4272,7 +4268,6 @@ class TypeDArray final : public TypeArray
TypeDArray* syntaxCopy() override;
uint32_t alignsize() override;
bool isString() override;
bool isZeroInit(const Loc& loc) override;
bool isBoolean() override;
void accept(Visitor* v) override;
};
Expand All @@ -4284,7 +4279,6 @@ class TypeDelegate final : public TypeNext
const char* kind() const override;
TypeDelegate* syntaxCopy() override;
uint32_t alignsize() override;
bool isZeroInit(const Loc& loc) override;
bool isBoolean() override;
void accept(Visitor* v) override;
};
Expand All @@ -4310,7 +4304,6 @@ class TypeEnum final : public Type
bool needsDestruction() override;
bool needsCopyOrPostblit() override;
bool needsNested() override;
bool isZeroInit(const Loc& loc) override;
bool hasVoidInitPointers() override;
bool hasUnsafeBitpatterns() override;
bool hasInvariant() override;
Expand Down Expand Up @@ -4511,7 +4504,6 @@ class TypePointer final : public TypeNext
const char* kind() const override;
TypePointer* syntaxCopy() override;
bool isscalar() override;
bool isZeroInit(const Loc& loc) override;
void accept(Visitor* v) override;
};

Expand All @@ -4520,7 +4512,6 @@ class TypeReference final : public TypeNext
public:
const char* kind() const override;
TypeReference* syntaxCopy() override;
bool isZeroInit(const Loc& loc) override;
void accept(Visitor* v) override;
};

Expand All @@ -4541,7 +4532,6 @@ class TypeSArray final : public TypeArray
bool isIncomplete();
uint32_t alignsize() override;
bool isString() override;
bool isZeroInit(const Loc& loc) override;
structalign_t alignment() override;
Expression* defaultInitLiteral(const Loc& loc) override;
bool hasUnsafeBitpatterns() override;
Expand Down Expand Up @@ -4575,7 +4565,6 @@ class TypeStruct final : public Type
TypeStruct* syntaxCopy() override;
structalign_t alignment() override;
Expression* defaultInitLiteral(const Loc& loc) override;
bool isZeroInit(const Loc& loc) override;
bool isAssignable() override;
bool isBoolean() override;
bool needsDestruction() override;
Expand Down Expand Up @@ -4655,7 +4644,6 @@ class TypeVector final : public Type
bool isBoolean() override;
Expression* defaultInitLiteral(const Loc& loc) override;
TypeBasic* elementType();
bool isZeroInit(const Loc& loc) override;
void accept(Visitor* v) override;
};

Expand Down
80 changes: 0 additions & 80 deletions compiler/src/dmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -1344,12 +1344,6 @@ extern (C++) abstract class Type : ASTNode
return defaultInit(this, loc);
}

// if initializer is 0
bool isZeroInit(const ref Loc loc)
{
return false; // assume not
}

/***************************************
* Return !=0 if the type or any of its subtypes is wild.
*/
Expand Down Expand Up @@ -2078,28 +2072,6 @@ extern (C++) final class TypeBasic : Type
return (flags & TFlags.unsigned) != 0;
}

override bool isZeroInit(const ref Loc loc)
{
switch (ty)
{
case Tchar:
case Twchar:
case Tdchar:
case Timaginary32:
case Timaginary64:
case Timaginary80:
case Tfloat32:
case Tfloat64:
case Tfloat80:
case Tcomplex32:
case Tcomplex64:
case Tcomplex80:
return false; // no
default:
return true; // yes
}
}

override bool hasUnsafeBitpatterns()
{
return ty == Tbool;
Expand Down Expand Up @@ -2199,11 +2171,6 @@ extern (C++) final class TypeVector : Type
return tb;
}

override bool isZeroInit(const ref Loc loc)
{
return basetype.isZeroInit(loc);
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -2280,11 +2247,6 @@ extern (C++) final class TypeSArray : TypeArray
return nty.isSomeChar;
}

override bool isZeroInit(const ref Loc loc)
{
return next.isZeroInit(loc);
}

override structalign_t alignment()
{
return next.alignment();
Expand Down Expand Up @@ -2388,11 +2350,6 @@ extern (C++) final class TypeDArray : TypeArray
return nty.isSomeChar;
}

override bool isZeroInit(const ref Loc loc)
{
return true;
}

override bool isBoolean()
{
return true;
Expand Down Expand Up @@ -2439,11 +2396,6 @@ extern (C++) final class TypeAArray : TypeArray
return result;
}

override bool isZeroInit(const ref Loc loc)
{
return true;
}

override bool isBoolean()
{
return true;
Expand Down Expand Up @@ -2490,11 +2442,6 @@ extern (C++) final class TypePointer : TypeNext
return true;
}

override bool isZeroInit(const ref Loc loc)
{
return true;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -2527,11 +2474,6 @@ extern (C++) final class TypeReference : TypeNext
return result;
}

override bool isZeroInit(const ref Loc loc)
{
return true;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -2903,11 +2845,6 @@ extern (C++) final class TypeDelegate : TypeNext
return target.ptrsize;
}

override bool isZeroInit(const ref Loc loc)
{
return true;
}

override bool isBoolean()
{
return true;
Expand Down Expand Up @@ -3301,13 +3238,6 @@ extern (C++) final class TypeStruct : Type
return structinit;
}

override bool isZeroInit(const ref Loc loc)
{
// Determine zeroInit here, as this can be called before semantic2
sym.determineSize(sym.loc);
return sym.zeroInit;
}

override bool isAssignable()
{
bool assignable = true;
Expand Down Expand Up @@ -3598,11 +3528,6 @@ extern (C++) final class TypeEnum : Type
return tb.castMod(mod); // retain modifier bits from 'this'
}

override bool isZeroInit(const ref Loc loc)
{
return sym.getDefaultValue(loc).toBool().hasValue(false);
}

override bool hasVoidInitPointers()
{
return memType().hasVoidInitPointers();
Expand Down Expand Up @@ -3709,11 +3634,6 @@ extern (C++) final class TypeClass : Type
return wm;
}

override bool isZeroInit(const ref Loc loc)
{
return true;
}

override bool isscope()
{
return sym.stack;
Expand Down
13 changes: 1 addition & 12 deletions compiler/src/dmd/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ class Type : public ASTNode
virtual ClassDeclaration *isClassHandle();
virtual structalign_t alignment();
virtual Expression *defaultInitLiteral(const Loc &loc);
virtual bool isZeroInit(const Loc &loc = Loc()); // if initializer is 0
virtual int hasWild() const;
virtual bool hasVoidInitPointers();
virtual bool hasUnsafeBitpatterns();
Expand Down Expand Up @@ -360,7 +359,6 @@ class TypeBasic final : public Type
bool iscomplex() override;
bool isscalar() override;
bool isunsigned() override;
bool isZeroInit(const Loc &loc) override;

// For eliminating dynamic_cast
TypeBasic *isTypeBasic() override;
Expand All @@ -383,7 +381,6 @@ class TypeVector final : public Type
bool isBoolean() override;
Expression *defaultInitLiteral(const Loc &loc) override;
TypeBasic *elementType();
bool isZeroInit(const Loc &loc) override;

void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -405,7 +402,6 @@ class TypeSArray final : public TypeArray
bool isIncomplete();
unsigned alignsize() override;
bool isString() override;
bool isZeroInit(const Loc &loc) override;
structalign_t alignment() override;
Expression *defaultInitLiteral(const Loc &loc) override;
bool hasUnsafeBitpatterns() override;
Expand All @@ -426,7 +422,6 @@ class TypeDArray final : public TypeArray
TypeDArray *syntaxCopy() override;
unsigned alignsize() override;
bool isString() override;
bool isZeroInit(const Loc &loc) override;
bool isBoolean() override;

void accept(Visitor *v) override { v->visit(this); }
Expand All @@ -441,7 +436,6 @@ class TypeAArray final : public TypeArray
static TypeAArray *create(Type *t, Type *index);
const char *kind() override;
TypeAArray *syntaxCopy() override;
bool isZeroInit(const Loc &loc) override;
bool isBoolean() override;

void accept(Visitor *v) override { v->visit(this); }
Expand All @@ -454,7 +448,6 @@ class TypePointer final : public TypeNext
const char *kind() override;
TypePointer *syntaxCopy() override;
bool isscalar() override;
bool isZeroInit(const Loc &loc) override;

void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -464,7 +457,6 @@ class TypeReference final : public TypeNext
public:
const char *kind() override;
TypeReference *syntaxCopy() override;
bool isZeroInit(const Loc &loc) override;
void accept(Visitor *v) override { v->visit(this); }
};

Expand Down Expand Up @@ -593,7 +585,6 @@ class TypeDelegate final : public TypeNext
const char *kind() override;
TypeDelegate *syntaxCopy() override;
unsigned alignsize() override;
bool isZeroInit(const Loc &loc) override;
bool isBoolean() override;

void accept(Visitor *v) override { v->visit(this); }
Expand Down Expand Up @@ -703,7 +694,6 @@ class TypeStruct final : public Type
TypeStruct *syntaxCopy() override;
structalign_t alignment() override;
Expression *defaultInitLiteral(const Loc &loc) override;
bool isZeroInit(const Loc &loc) override;
bool isAssignable() override;
bool isBoolean() override;
bool needsDestruction() override;
Expand Down Expand Up @@ -739,7 +729,6 @@ class TypeEnum final : public Type
bool needsDestruction() override;
bool needsCopyOrPostblit() override;
bool needsNested() override;
bool isZeroInit(const Loc &loc) override;
bool hasVoidInitPointers() override;
bool hasUnsafeBitpatterns() override;
bool hasInvariant() override;
Expand All @@ -759,7 +748,6 @@ class TypeClass final : public Type
TypeClass *syntaxCopy() override;
ClassDeclaration *isClassHandle() override;
unsigned char deduceWild(Type *t, bool isRef) override;
bool isZeroInit(const Loc &loc) override;
bool isscope() override;
bool isBoolean() override;

Expand Down Expand Up @@ -837,6 +825,7 @@ namespace dmd
bool equivalent(Type *src, Type *t);
Covariant covariant(Type *, Type *, StorageClass * = nullptr, bool = false);
bool isBaseOf(Type *tthis, Type *t, int *poffset);
bool isZeroInit(Type *t, const Loc &loc = Loc());
Type *trySemantic(Type *type, const Loc &loc, Scope *sc);
Type *pointerTo(Type *type);
Type *referenceTo(Type *type);
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dmd/toobj.d
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ void toObjFile(Dsymbol ds, bool multiobj)
TypeInfo_toObjFile(null, ed.loc, ed.type);

TypeEnum tc = ed.type.isTypeEnum();
import dmd.typesem : isZeroInit;
if (!tc.sym.members || ed.type.isZeroInit(Loc.initial))
{
}
Expand Down
Loading

0 comments on commit 8053445

Please sign in to comment.