Skip to content
Closed
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
16 changes: 8 additions & 8 deletions src/dmd/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ extern (C++) abstract class AttribDeclaration : Dsymbol
return Dsymbol.oneMembers(d, ps, ident);
}

override void setFieldOffset(AggregateDeclaration ad, ref FieldState fieldState, bool isunion)
override void setFieldOffset(AggregateDeclaration ad, uint* poffset, bool isunion)
{
include(null).foreachDsymbol( s => s.setFieldOffset(ad, fieldState, isunion) );
include(null).foreachDsymbol( s => s.setFieldOffset(ad, poffset, isunion) );
}

override final bool hasPointers()
Expand Down Expand Up @@ -770,7 +770,7 @@ extern (C++) final class AnonDeclaration : AttribDeclaration
return AttribDeclaration.setScope(sc);
}

override void setFieldOffset(AggregateDeclaration ad, ref FieldState fieldState, bool isunion)
override void setFieldOffset(AggregateDeclaration ad, uint* poffset, bool isunion)
{
//printf("\tAnonDeclaration::setFieldOffset %s %p\n", isunion ? "union" : "struct", this);
if (decl)
Expand All @@ -789,12 +789,12 @@ extern (C++) final class AnonDeclaration : AttribDeclaration
ad.structsize = 0;
ad.alignsize = 0;

FieldState fs;
uint offset = 0;
decl.foreachDsymbol( (s)
{
s.setFieldOffset(ad, fs, this.isunion);
s.setFieldOffset(ad, &offset, this.isunion);
if (this.isunion)
fs.offset = 0;
offset = 0;
});

/* https://issues.dlang.org/show_bug.cgi?id=13613
Expand All @@ -806,7 +806,7 @@ extern (C++) final class AnonDeclaration : AttribDeclaration
{
ad.structsize = savestructsize;
ad.alignsize = savealignsize;
fieldState.offset = ad.structsize;
*poffset = ad.structsize;
return;
}

Expand All @@ -829,7 +829,7 @@ extern (C++) final class AnonDeclaration : AttribDeclaration
* go ahead and place it.
*/
anonoffset = AggregateDeclaration.placeField(
&fieldState.offset,
poffset,
anonstructsize, anonalignsize, alignment,
&ad.structsize, &ad.alignsize,
isunion);
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/attrib.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AttribDeclaration : public Dsymbol
void addComment(const utf8_t *comment);
const char *kind() const;
bool oneMember(Dsymbol **ps, Identifier *ident);
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
bool hasPointers();
bool hasStaticCtorOrDtor();
void checkCtorConstInit();
Expand Down Expand Up @@ -141,7 +141,7 @@ class AnonDeclaration : public AttribDeclaration

AnonDeclaration *syntaxCopy(Dsymbol *s);
void setScope(Scope *sc);
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
const char *kind() const;
AnonDeclaration *isAnonDeclaration() { return this; }
void accept(Visitor *v) { v->visit(this); }
Expand Down
5 changes: 2 additions & 3 deletions src/dmd/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,10 @@ extern (C++) class ClassDeclaration : AggregateDeclaration
// to calculate each variable offsets. It can be improved later.
fields.setDim(0);

FieldState fieldState;
fieldState.offset = structsize;
uint offset = structsize;
foreach (s; *members)
{
s.setFieldOffset(this, fieldState, false);
s.setFieldOffset(this, &offset, false);
}

sizeok = Sizeok.done;
Expand Down
10 changes: 5 additions & 5 deletions src/dmd/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ extern (C++) class VarDeclaration : Declaration
return v;
}

override final void setFieldOffset(AggregateDeclaration ad, ref FieldState fieldState, bool isunion)
override final void setFieldOffset(AggregateDeclaration ad, uint* poffset, bool isunion)
{
//printf("VarDeclaration::setFieldOffset(ad = %s) %s\n", ad.toChars(), toChars());

Expand All @@ -1129,7 +1129,7 @@ extern (C++) class VarDeclaration : Declaration
Expression e = cast(Expression)o;
assert(e.op == TOK.dSymbol);
DsymbolExp se = cast(DsymbolExp)e;
se.s.setFieldOffset(ad, fieldState, isunion);
se.s.setFieldOffset(ad, poffset, isunion);
}
return;
}
Expand All @@ -1146,15 +1146,15 @@ extern (C++) class VarDeclaration : Declaration
if (offset)
{
// already a field
fieldState.offset = ad.structsize; // https://issues.dlang.org/show_bug.cgi?id=13613
*poffset = ad.structsize; // https://issues.dlang.org/show_bug.cgi?id=13613
return;
}
for (size_t i = 0; i < ad.fields.dim; i++)
{
if (ad.fields[i] == this)
{
// already a field
fieldState.offset = ad.structsize; // https://issues.dlang.org/show_bug.cgi?id=13613
*poffset = ad.structsize; // https://issues.dlang.org/show_bug.cgi?id=13613
return;
}
}
Expand Down Expand Up @@ -1191,7 +1191,7 @@ extern (C++) class VarDeclaration : Declaration
uint memsize = cast(uint)sz; // size of member
uint memalignsize = target.fieldalign(t); // size of member for alignment purposes
offset = AggregateDeclaration.placeField(
&fieldState.offset,
poffset,
memsize, memalignsize, alignment,
&ad.structsize, &ad.alignsize,
isunion);
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class VarDeclaration : public Declaration
public:
static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
VarDeclaration *syntaxCopy(Dsymbol *);
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
const char *kind() const;
AggregateDeclaration *isThis();
bool needThis();
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/dstruct.d
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,12 @@ extern (C++) class StructDeclaration : AggregateDeclaration
fields.setDim(0); // workaround

// Set the offsets of the fields and determine the size of the struct
FieldState fieldState;
uint offset = 0;
bool isunion = isUnionDeclaration() !is null;
for (size_t i = 0; i < members.dim; i++)
{
Dsymbol s = (*members)[i];
s.setFieldOffset(this, fieldState, isunion);
s.setFieldOffset(this, &offset, isunion);
}
if (type.ty == Terror)
{
Expand Down
12 changes: 1 addition & 11 deletions src/dmd/dsymbol.d
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,6 @@ enum : int
TagNameSpace = 0x100, // search ImportC tag symbol table
}

/***********************************************************
* Struct/Class/Union field state.
* Used for transitory information when setting field offsets, such
* as bit fields.
*/
struct FieldState
{
uint offset; /// offset for next field
}

/***********************************************************
*/
extern (C++) class Dsymbol : ASTNode
Expand Down Expand Up @@ -1146,7 +1136,7 @@ extern (C++) class Dsymbol : ASTNode
return true;
}

void setFieldOffset(AggregateDeclaration ad, ref FieldState fieldState, bool isunion)
void setFieldOffset(AggregateDeclaration ad, uint* poffset, bool isunion)
{
}

Expand Down
7 changes: 1 addition & 6 deletions src/dmd/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,6 @@ enum
TagNameSpace = 0x100, // search ImportC tag symbol table
};

struct FieldState
{
unsigned offset;
};

class Dsymbol : public ASTNode
{
public:
Expand Down Expand Up @@ -220,7 +215,7 @@ class Dsymbol : public ASTNode
virtual Visibility visible();
virtual Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees
virtual bool oneMember(Dsymbol **ps, Identifier *ident);
virtual void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
virtual void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
virtual bool hasPointers();
virtual bool hasStaticCtorOrDtor();
virtual void addLocalClass(ClassDeclarations *) { }
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -7670,13 +7670,13 @@ extern (C++) final class TemplateMixin : TemplateInstance
return members.foreachDsymbol( (s) { return s.hasPointers(); } ) != 0;
}

override void setFieldOffset(AggregateDeclaration ad, ref FieldState fieldState, bool isunion)
override void setFieldOffset(AggregateDeclaration ad, uint* poffset, bool isunion)
{
//printf("TemplateMixin.setFieldOffset() %s\n", toChars());
if (_scope) // if fwd reference
dsymbolSemantic(this, null); // try to resolve it

members.foreachDsymbol( (s) { s.setFieldOffset(ad, fieldState, isunion); } );
members.foreachDsymbol( (s) { s.setFieldOffset(ad, poffset, isunion); } );
}

override const(char)* toChars() const
Expand Down
26 changes: 6 additions & 20 deletions src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class LabelDsymbol;
class ClassDeclaration;
class Type;
class Package;
struct FieldState;
class EnumMember;
class TemplateDeclaration;
class TemplateMixin;
Expand Down Expand Up @@ -1034,7 +1033,7 @@ class Dsymbol : public ASTNode
virtual Visibility visible();
virtual Dsymbol* syntaxCopy(Dsymbol* s);
virtual bool oneMember(Dsymbol** ps, Identifier* ident);
virtual void setFieldOffset(AggregateDeclaration* ad, FieldState& fieldState, bool isunion);
virtual void setFieldOffset(AggregateDeclaration* ad, uint32_t* poffset, bool isunion);
virtual bool hasPointers();
virtual bool hasStaticCtorOrDtor();
virtual void addLocalClass(Array<ClassDeclaration* >* _param_0);
Expand Down Expand Up @@ -2475,18 +2474,6 @@ enum class StructFlags
hasPointers = 1,
};

struct FieldState final
{
uint32_t offset;
FieldState() :
offset()
{
}
FieldState(uint32_t offset) :
offset(offset)
{}
};

enum
{
IgnoreNone = 0,
Expand Down Expand Up @@ -3688,7 +3675,7 @@ class Nspace final : public ScopeDsymbol
void setScope(Scope* sc);
Dsymbol* search(const Loc& loc, Identifier* ident, int32_t flags = 8);
bool hasPointers();
void setFieldOffset(AggregateDeclaration* ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration* ad, uint32_t* poffset, bool isunion);
const char* kind() const;
Nspace* isNspace();
void accept(Visitor* v);
Expand Down Expand Up @@ -4486,7 +4473,6 @@ struct ASTCodegen final
using Dsymbol = ::Dsymbol;
using DsymbolTable = ::DsymbolTable;
using ExpressionDsymbol = ::ExpressionDsymbol;
using FieldState = ::FieldState;
using ForwardingScopeDsymbol = ::ForwardingScopeDsymbol;
using OverloadSet = ::OverloadSet;
using PASS = ::PASS;
Expand Down Expand Up @@ -5026,7 +5012,7 @@ class AttribDeclaration : public Dsymbol
void addComment(const char* comment);
const char* kind() const;
bool oneMember(Dsymbol** ps, Identifier* ident);
void setFieldOffset(AggregateDeclaration* ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration* ad, uint32_t* poffset, bool isunion);
bool hasPointers();
bool hasStaticCtorOrDtor();
void checkCtorConstInit();
Expand Down Expand Up @@ -5128,7 +5114,7 @@ class AnonDeclaration final : public AttribDeclaration
uint32_t anonalignsize;
AnonDeclaration* syntaxCopy(Dsymbol* s);
void setScope(Scope* sc);
void setFieldOffset(AggregateDeclaration* ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration* ad, uint32_t* poffset, bool isunion);
const char* kind() const;
AnonDeclaration* isAnonDeclaration();
void accept(Visitor* v);
Expand Down Expand Up @@ -5590,7 +5576,7 @@ class VarDeclaration : public Declaration
bool isArgDtorVar;
static VarDeclaration* create(const Loc& loc, Type* type, Identifier* ident, Initializer* _init, StorageClass storage_class = static_cast<StorageClass>(STC::undefined_));
VarDeclaration* syntaxCopy(Dsymbol* s);
void setFieldOffset(AggregateDeclaration* ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration* ad, uint32_t* poffset, bool isunion);
const char* kind() const;
AggregateDeclaration* isThis();
bool needThis();
Expand Down Expand Up @@ -6348,7 +6334,7 @@ class TemplateMixin final : public TemplateInstance
const char* kind() const;
bool oneMember(Dsymbol** ps, Identifier* ident);
bool hasPointers();
void setFieldOffset(AggregateDeclaration* ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration* ad, uint32_t* poffset, bool isunion);
const char* toChars() const;
TemplateMixin* isTemplateMixin();
void accept(Visitor* v);
Expand Down
4 changes: 2 additions & 2 deletions src/dmd/nspace.d
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ extern (C++) final class Nspace : ScopeDsymbol
return members.foreachDsymbol( (s) { return s.hasPointers(); } ) != 0;
}

override void setFieldOffset(AggregateDeclaration ad, ref FieldState fieldState, bool isunion)
override void setFieldOffset(AggregateDeclaration ad, uint* poffset, bool isunion)
{
//printf("Nspace::setFieldOffset() %s\n", toChars());
if (_scope) // if fwd reference
dsymbolSemantic(this, null); // try to resolve it
members.foreachDsymbol( s => s.setFieldOffset(ad, fieldState, isunion) );
members.foreachDsymbol( s => s.setFieldOffset(ad, poffset, isunion) );
}

override const(char)* kind() const
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/nspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Nspace : public ScopeDsymbol
void setScope(Scope *sc);
Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly);
bool hasPointers();
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
const char *kind() const;
Nspace *isNspace() { return this; }
void accept(Visitor *v) { v->visit(this); }
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/template.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class TemplateMixin : public TemplateInstance
const char *kind() const;
bool oneMember(Dsymbol **ps, Identifier *ident);
bool hasPointers();
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion);
void setFieldOffset(AggregateDeclaration *ad, unsigned *poffset, bool isunion);
const char *toChars() const;

TemplateMixin *isTemplateMixin() { return this; }
Expand Down