Implement stripModifiers using castMod(0).

Reduces the potentail for bugs in the fragile code; castMod(0) is
used like this in DMD code.
This commit is contained in:
David Nadlinger
2012-09-07 00:04:48 +02:00
parent 57b2eb3dad
commit 139e1a9c2a

View File

@@ -1763,85 +1763,7 @@ Type * stripModifiers( Type * type )
#if DMDV2
if (type->ty == Tfunction)
return type;
Type *t = type;
while (t->mod)
{
switch (t->mod)
{
case MODconst:
t = type->cto;
break;
case MODshared:
t = type->sto;
break;
case MODimmutable:
t = type->ito;
break;
case MODshared | MODconst:
t = type->scto;
break;
case MODwild:
t = type->wto;
break;
case MODshared | MODwild:
t = type->swto;
break;
default:
assert(0 && "Unhandled type modifier");
}
if (!t)
{
unsigned sz = type->sizeTy[type->ty];
t = static_cast<Type *>(malloc(sz));
memcpy(t, type, sz);
t->mod = 0;
t->deco = NULL;
t->arrayof = NULL;
t->pto = NULL;
t->rto = NULL;
t->cto = NULL;
t->ito = NULL;
t->sto = NULL;
t->scto = NULL;
t->wto = NULL;
t->swto = NULL;
t->vtinfo = NULL;
t = t->merge();
t->fixTo(type);
switch (type->mod)
{
case MODconst:
t->cto = type;
break;
case MODimmutable:
t->ito = type;
break;
case MODshared:
t->sto = type;
break;
case MODshared | MODconst:
t->scto = type;
break;
case MODwild:
t->wto = type;
break;
case MODshared | MODwild:
t->swto = type;
break;
default:
assert(0);
}
}
}
return t;
return type->castMod(0);
#else
return type;
#endif