Skip to content

Commit

Permalink
Refactoring for the detection mechanism of expression modifiable.
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Jan 29, 2013
1 parent e2aa18c commit fb2bc10
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 176 deletions.
30 changes: 16 additions & 14 deletions src/declaration.c
Expand Up @@ -130,26 +130,28 @@ enum PROT Declaration::prot()

#if DMDV2

int Declaration::checkModify(Loc loc, Scope *sc, Type *t)
int Declaration::checkModify(Loc loc, Scope *sc, Type *t, Expression *e1, int flag)
{
if ((sc->flags & SCOPEcontract) && isParameter())
error(loc, "cannot modify parameter '%s' in contract", toChars());
VarDeclaration *v = isVarDeclaration();
if (v && v->canassign)
return 2;

if ((sc->flags & SCOPEcontract) && isParameter())
{
if (!flag) error(loc, "cannot modify parameter '%s' in contract", toChars());
return 0;
}
if ((sc->flags & SCOPEcontract) && isResult())
error(loc, "cannot modify result '%s' in contract", toChars());
{
if (!flag) error(loc, "cannot modify result '%s' in contract", toChars());
return 0;
}

if (isCtorinit() && !t->isMutable() ||
(storage_class & STCnodefaultctor))
if (v && isCtorinit())
{ // It's only modifiable if inside the right constructor
return modifyFieldVar(loc, sc, isVarDeclaration(), NULL);
return modifyFieldVar(loc, sc, v, e1) ? 2 : 1;
}
else
{
VarDeclaration *v = isVarDeclaration();
if (v && v->canassign)
return TRUE;
}
return FALSE;
return 1;
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/declaration.h
Expand Up @@ -141,7 +141,7 @@ struct Declaration : Dsymbol
void semantic(Scope *sc);
const char *kind();
unsigned size(Loc loc);
int checkModify(Loc loc, Scope *sc, Type *t);
int checkModify(Loc loc, Scope *sc, Type *t, Expression *e1, int flag);

Dsymbol *search(Loc loc, Identifier *ident, int flags);

Expand Down

0 comments on commit fb2bc10

Please sign in to comment.