Skip to content

Commit

Permalink
modernize
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Aug 8, 2011
1 parent 8fcaeae commit 952203d
Show file tree
Hide file tree
Showing 12 changed files with 117 additions and 136 deletions.
29 changes: 12 additions & 17 deletions src/access.c
@@ -1,5 +1,5 @@

// Copyright (c) 1999-2006 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -76,18 +76,15 @@ enum PROT ClassDeclaration::getAccess(Dsymbol *smember)
}
else
{
enum PROT access;
int i;

if (smember->isDeclaration()->isStatic())
{
access_ret = smember->prot();
}

for (i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = baseclasses->tdata()[i];
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *b = (*baseclasses)[i];

access = b->base->getAccess(smember);
enum PROT access = b->base->getAccess(smember);
switch (access)
{
case PROTnone:
Expand Down Expand Up @@ -153,11 +150,9 @@ static int accessCheckX(
ClassDeclaration *cdthis = dthis->isClassDeclaration();
if (cdthis)
{
for (int i = 0; i < cdthis->baseclasses->dim; i++)
{ BaseClass *b = cdthis->baseclasses->tdata()[i];
enum PROT access;

access = b->base->getAccess(smember);
for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
{ BaseClass *b = (*cdthis->baseclasses)[i];
enum PROT access = b->base->getAccess(smember);
if (access >= PROTprotected ||
accessCheckX(smember, sfunc, b->base, cdscope)
)
Expand All @@ -174,8 +169,8 @@ static int accessCheckX(
ClassDeclaration *cdthis = dthis->isClassDeclaration();
if (cdthis)
{
for (int i = 0; i < cdthis->baseclasses->dim; i++)
{ BaseClass *b = cdthis->baseclasses->tdata()[i];
for (size_t i = 0; i < cdthis->baseclasses->dim; i++)
{ BaseClass *b = (*cdthis->baseclasses)[i];

if (accessCheckX(smember, sfunc, b->base, cdscope))
return 1;
Expand Down Expand Up @@ -219,12 +214,12 @@ void AggregateDeclaration::accessCheck(Loc loc, Scope *sc, Dsymbol *smember)
//assert(smember->parent->isBaseOf(this, NULL));

if (smemberparent == this)
{ enum PROT access = smember->prot();
{ enum PROT access2 = smember->prot();

result = access >= PROTpublic ||
result = access2 >= PROTpublic ||
hasPrivateAccess(f) ||
isFriendOf(cdscope) ||
(access == PROTpackage && hasPackageAccess(sc, this));
(access2 == PROTpackage && hasPackageAccess(sc, this));
#if LOG
printf("result1 = %d\n", result);
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/aggregate.h
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2008 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -219,7 +219,7 @@ struct ClassDeclaration : AggregateDeclaration
BaseClasses *baseclasses; // Array of BaseClass's; first is super,
// rest are Interface's

int interfaces_dim;
size_t interfaces_dim;
BaseClass **interfaces; // interfaces[interfaces_dim] for this class
// (does not include baseClass)

Expand Down
6 changes: 3 additions & 3 deletions src/attrib.c
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 1999-2010 by Digital Mars
// Copyright (c) 1999-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -604,9 +604,9 @@ void ProtDeclaration::importAll(Scope *sc)
newsc->explicitProtection = 1;
}

for (int i = 0; i < decl->dim; i++)
for (size_t i = 0; i < decl->dim; i++)
{
Dsymbol *s = decl->tdata()[i];
Dsymbol *s = (*decl)[i];
s->importAll(newsc);
}

Expand Down
51 changes: 26 additions & 25 deletions src/cast.c
Expand Up @@ -427,8 +427,8 @@ MATCH StructLiteralExp::implicitConvTo(Type *t)
((TypeStruct *)type)->sym == ((TypeStruct *)t)->sym)
{
m = MATCHconst;
for (int i = 0; i < elements->dim; i++)
{ Expression *e = elements->tdata()[i];
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (*elements)[i];
Type *te = e->type;
te = te->castMod(t->mod);
MATCH m2 = e->implicitConvTo(te);
Expand All @@ -442,8 +442,7 @@ MATCH StructLiteralExp::implicitConvTo(Type *t)
#endif

MATCH StringExp::implicitConvTo(Type *t)
{ MATCH m;

{
#if 0
printf("StringExp::implicitConvTo(this=%s, committed=%d, type=%s, t=%s)\n",
toChars(), committed, type->toChars(), t->toChars());
Expand Down Expand Up @@ -536,8 +535,8 @@ MATCH ArrayLiteralExp::implicitConvTo(Type *t)
result = MATCHnomatch;
}

for (int i = 0; i < elements->dim; i++)
{ Expression *e = elements->tdata()[i];
for (size_t i = 0; i < elements->dim; i++)
{ Expression *e = (*elements)[i];
MATCH m = (MATCH)e->implicitConvTo(tb->nextOf());
if (m < result)
result = m; // remember worst match
Expand Down Expand Up @@ -598,8 +597,8 @@ MATCH AddrExp::implicitConvTo(Type *t)
(t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction)
{ OverExp *eo = (OverExp *)e1;
FuncDeclaration *f = NULL;
for (int i = 0; i < eo->vars->a.dim; i++)
{ Dsymbol *s = eo->vars->a.tdata()[i];
for (size_t i = 0; i < eo->vars->a.dim; i++)
{ Dsymbol *s = eo->vars->a[i];
FuncDeclaration *f2 = s->isFuncDeclaration();
assert(f2);
if (f2->overloadExactMatch(t->nextOf()))
Expand Down Expand Up @@ -684,7 +683,6 @@ MATCH DelegateExp::implicitConvTo(Type *t)
if (result == MATCHnomatch)
{
// Look for pointers to functions where the functions are overloaded.
FuncDeclaration *f;

t = t->toBasetype();
if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction &&
Expand Down Expand Up @@ -814,9 +812,9 @@ Expression *Expression::castTo(Scope *sc, Type *t)
* cast(to)e1.aliasthis
*/
Expression *e1 = new DotIdExp(loc, this, ts->sym->aliasthis->ident);
Expression *e = new CastExp(loc, e1, tb);
e = e->semantic(sc);
return e;
Expression *e2 = new CastExp(loc, e1, tb);
e2 = e2->semantic(sc);
return e2;
}
}
else if (typeb->ty == Tclass)
Expand All @@ -835,9 +833,9 @@ Expression *Expression::castTo(Scope *sc, Type *t)
* cast(to)e1.aliasthis
*/
Expression *e1 = new DotIdExp(loc, this, ts->sym->aliasthis->ident);
Expression *e = new CastExp(loc, e1, tb);
e = e->semantic(sc);
return e;
Expression *e2 = new CastExp(loc, e1, tb);
e2 = e2->semantic(sc);
return e2;
}
L1: ;
}
Expand Down Expand Up @@ -984,7 +982,9 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
if (committed && tb->ty == Tsarray && typeb->ty == Tarray)
{
se = (StringExp *)copy();
se->sz = tb->nextOf()->size();
d_uns64 szx = tb->nextOf()->size();
assert(szx <= 255);
se->sz = (unsigned char)szx;
se->len = (len * sz) / se->sz;
se->committed = 1;
se->type = t;
Expand Down Expand Up @@ -1119,7 +1119,9 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
}
se->string = buffer.extractData();
se->len = newlen;
se->sz = tb->nextOf()->size();
d_uns64 szx = tb->nextOf()->size();

This comment has been minimized.

Copy link
@kennytm

kennytm Aug 8, 2011

Contributor

This declaration have to be wrapped in a scope { ... }, otherwise g++ will fail to compile this.

cast.c: In member function ‘virtual Expression* StringExp::castTo(Scope*, Type*)’:
cast.c:1127:9: error: jump to case label
cast.c:1122:21: error:   crosses initialization of ‘d_uns64 szx’
assert(szx <= 255);
se->sz = (unsigned char)szx;
break;

default:
Expand All @@ -1134,9 +1136,9 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
// See if need to truncate or extend the literal
if (tb->ty == Tsarray)
{
int dim2 = ((TypeSArray *)tb)->dim->toInteger();
dinteger_t dim2 = ((TypeSArray *)tb)->dim->toInteger();

//printf("dim from = %d, to = %d\n", se->len, dim2);
//printf("dim from = %d, to = %d\n", (int)se->len, (int)dim2);

// Changing dimensions
if (dim2 != se->len)
Expand Down Expand Up @@ -1184,8 +1186,8 @@ Expression *AddrExp::castTo(Scope *sc, Type *t)
(t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction)
{ OverExp *eo = (OverExp *)e1;
FuncDeclaration *f = NULL;
for (int i = 0; i < eo->vars->a.dim; i++)
{ Dsymbol *s = eo->vars->a.tdata()[i];
for (size_t i = 0; i < eo->vars->a.dim; i++)
{ Dsymbol *s = eo->vars->a[i];
FuncDeclaration *f2 = s->isFuncDeclaration();
assert(f2);
if (f2->overloadExactMatch(t->nextOf()))
Expand Down Expand Up @@ -1271,10 +1273,10 @@ Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t)

e = (ArrayLiteralExp *)copy();
e->elements = (Expressions *)elements->copy();
for (int i = 0; i < elements->dim; i++)
{ Expression *ex = elements->tdata()[i];
for (size_t i = 0; i < elements->dim; i++)
{ Expression *ex = (*elements)[i];
ex = ex->castTo(sc, tb->nextOf());
e->elements->tdata()[i] = ex;
(*e->elements)[i] = ex;
}
e->type = t;
return e;
Expand Down Expand Up @@ -1317,7 +1319,6 @@ Expression *AssocArrayLiteralExp::castTo(Scope *sc, Type *t)
e->type = t;
return e;
}
L1:
return e->Expression::castTo(sc, t);
}

Expand Down

0 comments on commit 952203d

Please sign in to comment.