Skip to content

Commit

Permalink
Do not rely on implicit construction of Prot
Browse files Browse the repository at this point in the history
  • Loading branch information
yebblies committed Aug 30, 2014
1 parent 873ea24 commit 0183067
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/access.c
Expand Up @@ -42,7 +42,7 @@ bool isFriendOf(AggregateDeclaration *ad, AggregateDeclaration *cd);

Prot getAccess(AggregateDeclaration *ad, Dsymbol *smember)
{
Prot access_ret = PROTnone;
Prot access_ret = Prot(PROTnone);

#if LOG
printf("+AggregateDeclaration::getAccess(this = '%s', smember = '%s')\n",
Expand Down Expand Up @@ -71,7 +71,7 @@ Prot getAccess(AggregateDeclaration *ad, Dsymbol *smember)
break;

case PROTprivate:
access_ret = PROTnone; // private members of base class not accessible
access_ret = Prot(PROTnone); // private members of base class not accessible
break;

case PROTpackage:
Expand Down
2 changes: 1 addition & 1 deletion src/arrayop.c
Expand Up @@ -72,7 +72,7 @@ FuncDeclaration *buildArrayOp(Identifier *ident, BinExp *exp, Scope *sc, Loc loc
//printf("ftype: %s\n", ftype->toChars());
FuncDeclaration *fd = new FuncDeclaration(Loc(), Loc(), ident, STCundefined, ftype);
fd->fbody = fbody;
fd->protection = PROTpublic;
fd->protection = Prot(PROTpublic);
fd->linkage = LINKc;
fd->isArrayOp = 1;

Expand Down
6 changes: 3 additions & 3 deletions src/class.c
Expand Up @@ -515,7 +515,7 @@ void ClassDeclaration::semantic(Scope *sc)
assert(t->ty == Tclass);
TypeClass *tc = (TypeClass *)t;

BaseClass *b = new BaseClass(tc, PROTpublic);
BaseClass *b = new BaseClass(tc, Prot(PROTpublic));
baseclasses->shift(b);

baseClass = tc->sym;
Expand Down Expand Up @@ -657,7 +657,7 @@ void ClassDeclaration::semantic(Scope *sc)
sc2->linkage = LINKc;
}
}
sc2->protection = PROTpublic;
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;
Expand Down Expand Up @@ -1488,7 +1488,7 @@ void InterfaceDeclaration::semantic(Scope *sc)
sc2->linkage = LINKwindows;
else if (cpp)
sc2->linkage = LINKcpp;
sc2->protection = PROTpublic;
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/declaration.c
Expand Up @@ -84,7 +84,7 @@ Declaration::Declaration(Identifier *id)
type = NULL;
originalType = NULL;
storage_class = STCundefined;
protection = PROTundefined;
protection = Prot(PROTundefined);
linkage = LINKdefault;
inuse = 0;
sem = SemanticStart;
Expand Down Expand Up @@ -2168,7 +2168,7 @@ TypeInfoDeclaration::TypeInfoDeclaration(Type *tinfo, int internal)
{
this->tinfo = tinfo;
storage_class = STCstatic | STCgshared;
protection = PROTpublic;
protection = Prot(PROTpublic);
linkage = LINKc;
}

Expand Down
6 changes: 6 additions & 0 deletions src/dsymbol.c
Expand Up @@ -1548,6 +1548,12 @@ Dsymbol *DsymbolTable::update(Dsymbol *s)

/****************************** Prot ******************************/

Prot::Prot()
{
this->kind = PROTundefined;
this->pkg = NULL;
}

Prot::Prot(PROTKIND kind)
{
this->kind = kind;
Expand Down
3 changes: 2 additions & 1 deletion src/dsymbol.h
Expand Up @@ -108,7 +108,8 @@ struct Prot
PROTKIND kind;
Package *pkg;

Prot(PROTKIND kind = PROTundefined);
Prot();
Prot(PROTKIND kind);

bool isMoreRestrictiveThan(Prot other);
bool operator==(Prot other);
Expand Down
4 changes: 2 additions & 2 deletions src/enum.c
Expand Up @@ -36,7 +36,7 @@ EnumDeclaration::EnumDeclaration(Loc loc, Identifier *id, Type *memtype)
defaultval = NULL;
sinit = NULL;
isdeprecated = false;
protection = PROTundefined;
protection = Prot(PROTundefined);
parent = NULL;
added = false;
inuse = 0;
Expand Down Expand Up @@ -677,7 +677,7 @@ Expression *EnumMember::getVarExp(Loc loc, Scope *sc)
vd->storage_class = STCmanifest;
vd->semantic(sc);

vd->protection = ed->isAnonymous() ? ed->protection : PROTpublic;
vd->protection = ed->isAnonymous() ? ed->protection : Prot(PROTpublic);
vd->parent = ed->isAnonymous() ? ed->parent : ed;
vd->userAttribDecl = ed->isAnonymous() ? ed->userAttribDecl : NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/expression.c
Expand Up @@ -5479,7 +5479,7 @@ Expression *FuncExp::semantic(Scope *sc)

sc = sc->push(); // just create new scope
sc->flags &= ~SCOPEctfe; // temporary stop CTFE
sc->protection = PROTpublic; // Bugzilla 12506
sc->protection = Prot(PROTpublic); // Bugzilla 12506

if (!type || type == Type::tvoid)
{
Expand Down
4 changes: 2 additions & 2 deletions src/func.c
Expand Up @@ -1257,7 +1257,7 @@ void FuncDeclaration::semantic3(Scope *sc)
STCdeprecated | STCoverride |
STC_TYPECTOR | STCfinal | STCtls | STCgshared | STCref |
STCproperty | STCnothrow | STCpure | STCsafe | STCtrusted | STCsystem);
sc2->protection = PROTpublic;
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
if (this->ident != Id::require && this->ident != Id::ensure)
Expand Down Expand Up @@ -3853,7 +3853,7 @@ FuncDeclaration *FuncDeclaration::genCfunc(Parameters *args, Type *treturn, Iden
{
tf = new TypeFunction(args, treturn, 0, LINKc);
fd = new FuncDeclaration(Loc(), Loc(), id, STCstatic, tf);
fd->protection = PROTpublic;
fd->protection = Prot(PROTpublic);
fd->linkage = LINKc;

st->insert(fd);
Expand Down
8 changes: 4 additions & 4 deletions src/import.c
Expand Up @@ -204,7 +204,7 @@ void Import::importAll(Scope *sc)
{
if (sc->explicitProtection)
protection = sc->protection.kind;
sc->scopesym->importScope(mod, protection);
sc->scopesym->importScope(mod, Prot(protection));
}
}
}
Expand Down Expand Up @@ -242,7 +242,7 @@ void Import::semantic(Scope *sc)
{
if (scd->scopesym)
{
scd->scopesym->importScope(mod, protection);
scd->scopesym->importScope(mod, Prot(protection));
break;
}
}
Expand All @@ -263,7 +263,7 @@ void Import::semantic(Scope *sc)
#if 0
sc->protection = protection;
#else
sc->protection = PROTpublic;
sc->protection = Prot(PROTpublic);
#endif
for (size_t i = 0; i < aliasdecls.dim; i++)
{
Expand Down Expand Up @@ -317,7 +317,7 @@ void Import::semantic(Scope *sc)

// use protection instead of sc->protection because it couldn't be
// resolved yet, see the comment above
protectionToBuffer(ob, protection);
protectionToBuffer(ob, Prot(protection));
ob->writeByte(' ');
if (isstatic)
StorageClassDeclaration::stcToCBuffer(ob, STCstatic);
Expand Down
2 changes: 1 addition & 1 deletion src/mtype.c
Expand Up @@ -5633,7 +5633,7 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc)
*/
Scope *argsc = sc->push();
argsc->stc = 0; // don't inherit storage class
argsc->protection = PROTpublic;
argsc->protection = Prot(PROTpublic);
argsc->func = NULL;

size_t dim = Parameter::dim(tf->parameters);
Expand Down
2 changes: 1 addition & 1 deletion src/nspace.c
Expand Up @@ -58,7 +58,7 @@ void Nspace::semantic(Scope *sc)
ScopeDsymbol *sds = (ScopeDsymbol *)sce->scopesym;
if (sds)
{
sds->importScope(this, PROTpublic);
sds->importScope(this, Prot(PROTpublic));
break;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/parse.c
Expand Up @@ -2146,27 +2146,27 @@ BaseClasses *Parser::parseBaseClasses()
for (; 1; nextToken())
{
bool prot = false;
Prot protection = PROTpublic;
Prot protection = Prot(PROTpublic);
switch (token.value)
{
case TOKprivate:
prot = true;
protection = PROTprivate;
protection = Prot(PROTprivate);
nextToken();
break;
case TOKpackage:
prot = true;
protection = PROTpackage;
protection = Prot(PROTpackage);
nextToken();
break;
case TOKprotected:
prot = true;
protection = PROTprotected;
protection = Prot(PROTprotected);
nextToken();
break;
case TOKpublic:
prot = true;
protection = PROTpublic;
protection = Prot(PROTpublic);
nextToken();
break;
default: break;
Expand Down
4 changes: 2 additions & 2 deletions src/scope.c
Expand Up @@ -70,7 +70,7 @@ Scope::Scope()
this->func = NULL;
this->slabel = NULL;
this->linkage = LINKd;
this->protection = PROTpublic;
this->protection = Prot(PROTpublic);
this->explicitProtection = 0;
this->stc = 0;
this->depmsg = NULL;
Expand Down Expand Up @@ -110,7 +110,7 @@ Scope *Scope::createGlobal(Module *module)
memset(sc, 0, sizeof(Scope));
sc->structalign = STRUCTALIGN_DEFAULT;
sc->linkage = LINKd;
sc->protection = PROTpublic;
sc->protection = Prot(PROTpublic);

sc->module = module;
sc->scopesym = new ScopeDsymbol();
Expand Down
8 changes: 4 additions & 4 deletions src/struct.c
Expand Up @@ -130,7 +130,7 @@ AggregateDeclaration::AggregateDeclaration(Loc loc, Identifier *id)
this->loc = loc;

storage_class = 0;
protection = PROTpublic;
protection = Prot(PROTpublic);
type = NULL;
structsize = 0; // size of struct
alignsize = 0; // size of struct for alignment purposes
Expand Down Expand Up @@ -183,7 +183,7 @@ void AggregateDeclaration::semantic2(Scope *sc)
sc2->parent = this;
//if (isUnionDeclaration()) // TODO
// sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;
Expand Down Expand Up @@ -217,7 +217,7 @@ void AggregateDeclaration::semantic3(Scope *sc)
sc2->parent = this;
if (isUnionDeclaration())
sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;
Expand Down Expand Up @@ -730,7 +730,7 @@ void StructDeclaration::semantic(Scope *sc)
sc2->parent = this;
if (isUnionDeclaration())
sc2->inunion = 1;
sc2->protection = PROTpublic;
sc2->protection = Prot(PROTpublic);
sc2->explicitProtection = 0;
sc2->structalign = STRUCTALIGN_DEFAULT;
sc2->userAttribDecl = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/template.c
Expand Up @@ -450,7 +450,7 @@ TemplateDeclaration::TemplateDeclaration(Loc loc, Identifier *id,
this->ismixin = ismixin;
this->isstatic = true;
this->previous = NULL;
this->protection = PROTundefined;
this->protection = Prot(PROTundefined);
this->numinstances = 0;

// Compute in advance for Ddoc's use
Expand Down Expand Up @@ -8103,7 +8103,7 @@ void TemplateMixin::semantic(Scope *sc)
ScopeDsymbol *sds = (ScopeDsymbol *)sce->scopesym;
if (sds)
{
sds->importScope(this, PROTpublic);
sds->importScope(this, Prot(PROTpublic));
break;
}
}
Expand Down

0 comments on commit 0183067

Please sign in to comment.