Skip to content

Commit

Permalink
[Refactoring] Add Declaration::isField()
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Mar 1, 2013
1 parent 13d637e commit 7a23c2b
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 27 deletions.
12 changes: 6 additions & 6 deletions src/clone.c
Expand Up @@ -96,7 +96,7 @@ int StructDeclaration::needOpAssign()
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
assert(v && v->isField());
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
Expand Down Expand Up @@ -201,7 +201,7 @@ FuncDeclaration *StructDeclaration::buildOpAssign(Scope *sc)
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
assert(v && v->isField());
// this.v = s.v;
AssignExp *ec = new AssignExp(0,
new DotVarExp(0, new ThisExp(0), v, 0),
Expand Down Expand Up @@ -285,7 +285,7 @@ int StructDeclaration::needOpEquals()
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
assert(v && v->isField());
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
Expand Down Expand Up @@ -365,7 +365,7 @@ FuncDeclaration *StructDeclaration::buildOpEquals(Scope *sc)
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
assert(v && v->isField());
if (v->storage_class & STCref)
assert(0); // what should we do with this?
// this.v == s.v;
Expand Down Expand Up @@ -568,7 +568,7 @@ FuncDeclaration *StructDeclaration::buildPostBlit(Scope *sc)
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
assert(v && v->isField());
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
Expand Down Expand Up @@ -678,7 +678,7 @@ FuncDeclaration *AggregateDeclaration::buildDtor(Scope *sc)
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
assert(v && v->isField());
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
Expand Down
10 changes: 5 additions & 5 deletions src/declaration.c
Expand Up @@ -1233,7 +1233,7 @@ void VarDeclaration::semantic(Scope *sc)
((TypeStruct *)tb)->sym->noDefaultCtor)
{
if (!init)
{ if (storage_class & STCfield)
{ if (isField())
/* For fields, we'll check the constructor later to make sure it is initialized
*/
storage_class |= STCnodefaultctor;
Expand Down Expand Up @@ -1766,7 +1766,7 @@ void VarDeclaration::setFieldOffset(AggregateDeclaration *ad, unsigned *poffset,
return;
}

if (!(storage_class & STCfield))
if (!isField())
return;
assert(!(storage_class & (STCstatic | STCextern | STCparameter | STCtls)));

Expand Down Expand Up @@ -1903,7 +1903,7 @@ AggregateDeclaration *VarDeclaration::isThis()
int VarDeclaration::needThis()
{
//printf("VarDeclaration::needThis(%s, x%x)\n", toChars(), storage_class);
return storage_class & STCfield;
return isField();
}

int VarDeclaration::isImportedSymbol()
Expand All @@ -1917,7 +1917,7 @@ int VarDeclaration::isImportedSymbol()
void VarDeclaration::checkCtorConstInit()
{
#if 0 /* doesn't work if more than one static ctor */
if (ctorinit == 0 && isCtorinit() && !(storage_class & STCfield))
if (ctorinit == 0 && isCtorinit() && !isField())
error("missing initializer in static constructor for const variable");
#endif
}
Expand Down Expand Up @@ -2052,7 +2052,7 @@ int VarDeclaration::canTakeAddressOf()
*/
if ((isConst() || isImmutable()) &&
storage_class & STCinit &&
(!(storage_class & (STCstatic | STCextern)) || (storage_class & STCfield)) &&
(!(storage_class & (STCstatic | STCextern)) || isField()) &&
(!parent || toParent()->isModule() || toParent()->isTemplateInstance()) &&
type->toBasetype()->isTypeBasic()
)
Expand Down
3 changes: 2 additions & 1 deletion src/declaration.h
Expand Up @@ -168,7 +168,8 @@ struct Declaration : Dsymbol
int isParameter() { return storage_class & STCparameter; }
int isDeprecated() { return storage_class & STCdeprecated; }
int isOverride() { return storage_class & STCoverride; }
StorageClass isResult() { return storage_class & STCresult; }
int isResult() { return storage_class & STCresult; }
int isField() { return storage_class & STCfield; }

int isIn() { return storage_class & STCin; }
int isOut() { return storage_class & STCout; }

This comment has been minimized.

Copy link
@braddr

braddr Mar 1, 2013

Member

All of these really ought to be converted to return bool.

Expand Down
4 changes: 2 additions & 2 deletions src/expression.c
Expand Up @@ -7214,8 +7214,8 @@ int modifyFieldVar(Loc loc, Scope *sc, VarDeclaration *var, Expression *e1)
if (s)
fd = s->isFuncDeclaration();
if (fd &&
((fd->isCtorDeclaration() && var->storage_class & STCfield) ||
(fd->isStaticCtorDeclaration() && !(var->storage_class & STCfield))) &&
((fd->isCtorDeclaration() && var->isField()) ||
(fd->isStaticCtorDeclaration() && !var->isField())) &&
fd->toParent2() == var->toParent2() &&
(!e1 || e1->op == TOKthis)
)
Expand Down
2 changes: 1 addition & 1 deletion src/iasm.c
Expand Up @@ -2422,7 +2422,7 @@ STATIC void asm_merge_symbol(OPND *o1, Dsymbol *s)
asmerr(EM_uplevel, v->toChars());
}
#endif
if (v->storage_class & STCfield)
if (v->isField())
{
o1->disp += v->offset;
goto L2;
Expand Down
2 changes: 1 addition & 1 deletion src/json.c
Expand Up @@ -1071,7 +1071,7 @@ void VarDeclaration::toJson(JsonOut *json)
if (init)
json->property("init", init->toChars());

if (storage_class & STCfield)
if (isField())
json->property("offset", offset);

if (alignment && alignment != STRUCTALIGN_DEFAULT)
Expand Down
12 changes: 6 additions & 6 deletions src/mtype.c
Expand Up @@ -1996,7 +1996,7 @@ Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident)
else if (ident == Id::offsetof)
{
Loffset:
if (v->storage_class & STCfield)
if (v->isField())
{
e = new IntegerExp(e->loc, v->offset, Type::tsize_t);
return e;
Expand Down Expand Up @@ -8135,8 +8135,8 @@ Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident)
return ve;
}

bool unreal = e->op == TOKvar && (((VarExp *)e)->var->storage_class & STCfield);
if (d->isDataseg() || unreal && (d->storage_class & STCfield))
bool unreal = e->op == TOKvar && ((VarExp *)e)->var->isField();
if (d->isDataseg() || unreal && d->isField())
{
// (e, d)
accessCheck(e->loc, sc, e, d);
Expand Down Expand Up @@ -8356,7 +8356,7 @@ MATCH TypeStruct::implicitConvTo(Type *to)
for (size_t i = 0; i < sym->fields.dim; i++)
{ Dsymbol *s = sym->fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
assert(v && v->isField());

// 'from' type
Type *tvf = v->type->addMod(mod);
Expand Down Expand Up @@ -8814,8 +8814,8 @@ Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident)
return ve;
}

bool unreal = e->op == TOKvar && (((VarExp *)e)->var->storage_class & STCfield);
if (d->isDataseg() || unreal && (d->storage_class & STCfield))
bool unreal = e->op == TOKvar && ((VarExp *)e)->var->isField();
if (d->isDataseg() || unreal && d->isField())
{
// (e, d)
accessCheck(e->loc, sc, e, d);
Expand Down
4 changes: 2 additions & 2 deletions src/struct.c
Expand Up @@ -166,7 +166,7 @@ unsigned AggregateDeclaration::size(Loc loc)
v->semantic(NULL);
if (v->storage_class & (STCstatic | STCextern | STCtls | STCgshared | STCmanifest | STCctfe | STCtemplateparameter))
return 0;
if (v->storage_class & STCfield && v->sem >= SemanticDone)
if (v->isField() && v->sem >= SemanticDone)
return 0;
return 1;
}
Expand Down Expand Up @@ -768,7 +768,7 @@ bool StructDeclaration::isPOD()
{
Dsymbol *s = fields[i];
VarDeclaration *v = s->isVarDeclaration();
assert(v && v->storage_class & STCfield);
assert(v && v->isField());
if (v->storage_class & STCref)
continue;
Type *tv = v->type->toBasetype();
Expand Down
6 changes: 3 additions & 3 deletions src/tocvdebug.c
Expand Up @@ -957,7 +957,7 @@ int VarDeclaration::cvMember(unsigned char *p)

if (!p)
{
if (storage_class & STCfield)
if (isField())
{
if (config.fulltypes == CV8)
nwritten += 2;
Expand All @@ -980,7 +980,7 @@ int VarDeclaration::cvMember(unsigned char *p)
switch (config.fulltypes)
{
case CV8:
if (storage_class & STCfield)
if (isField())
{
TOWORD(p,LF_MEMBER_V3);
TOWORD(p + 2,attribute);
Expand All @@ -1000,7 +1000,7 @@ int VarDeclaration::cvMember(unsigned char *p)
break;

case CV4:
if (storage_class & STCfield)
if (isField())
{
TOWORD(p,LF_MEMBER);
TOWORD(p + 2,typidx);
Expand Down

0 comments on commit 7a23c2b

Please sign in to comment.