Skip to content

Commit

Permalink
Merge pull request #2730 from yebblies/implicitnarrow
Browse files Browse the repository at this point in the history
[DDMD] Implicitnarrow
  • Loading branch information
yebblies committed Nov 15, 2013
2 parents 38c51e7 + ee06f3c commit c60a9a1
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 136 deletions.
10 changes: 5 additions & 5 deletions src/argtypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ Type *argtypemerge(Type *t1, Type *t2, unsigned offset2)
if (!t2)
return t1;

unsigned sz1 = t1->size(Loc());
unsigned sz2 = t2->size(Loc());
unsigned sz1 = (unsigned)t1->size(Loc());
unsigned sz2 = (unsigned)t2->size(Loc());

if (t1->ty != t2->ty &&
(t1->ty == Tfloat80 || t2->ty == Tfloat80))
Expand Down Expand Up @@ -259,7 +259,7 @@ TypeTuple *TypeDArray::toArgTypes()
if (global.params.is64bit && !global.params.isLP64)
{
// For AMD64 ILP32 ABI, D arrays fit into a single integer register.
unsigned offset = Type::tsize_t->size(Loc());
unsigned offset = (unsigned)Type::tsize_t->size(Loc());
Type *t = argtypemerge(Type::tsize_t, Type::tvoidptr, offset);
if (t)
return new TypeTuple(t);
Expand All @@ -275,7 +275,7 @@ TypeTuple *TypeDelegate::toArgTypes()
if (global.params.is64bit && !global.params.isLP64)
{
// For AMD64 ILP32 ABI, delegates fit into a single integer register.
unsigned offset = Type::tsize_t->size(Loc());
unsigned offset = (unsigned)Type::tsize_t->size(Loc());
Type *t = argtypemerge(Type::tsize_t, Type::tvoidptr, offset);
if (t)
return new TypeTuple(t);
Expand Down Expand Up @@ -354,7 +354,7 @@ TypeTuple *TypeStruct::toArgTypes()
goto Lmemory;

// Fields that overlap the 8byte boundary goto Lmemory
unsigned fieldsz = f->type->size(Loc());
d_uns64 fieldsz = f->type->size(Loc());
if (f->offset < 8 && (f->offset + fieldsz) > 8)
goto Lmemory;
}
Expand Down
4 changes: 2 additions & 2 deletions src/cast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ Type *SliceExp::toStaticArrayType()
Expression *upr = this->upr->optimize(WANTvalue);
if (lwr->isConst() && upr->isConst())
{
size_t len = upr->toUInteger() - lwr->toUInteger();
size_t len = (size_t)(upr->toUInteger() - lwr->toUInteger());
return TypeSArray::makeType(loc, type->toBasetype()->nextOf(), len);
}
}
Expand Down Expand Up @@ -1466,7 +1466,7 @@ Expression *StringExp::castTo(Scope *sc, Type *t)
// See if need to truncate or extend the literal
if (tb->ty == Tsarray)
{
dinteger_t dim2 = ((TypeSArray *)tb)->dim->toInteger();
size_t dim2 = (size_t)((TypeSArray *)tb)->dim->toInteger();

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

Expand Down
38 changes: 19 additions & 19 deletions src/constfold.c
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ Expression *Equal(TOK op, Type *type, Expression *e1, Expression *e2)
Expression *v = Equal(TOKequal, Type::tint32, ee1, ee2);
if (v == EXP_CANT_INTERPRET)
return EXP_CANT_INTERPRET;
cmp = v->toInteger();
cmp = (int)v->toInteger();
if (cmp == 0)
break;
}
Expand Down Expand Up @@ -824,7 +824,7 @@ Expression *Equal(TOK op, Type *type, Expression *e1, Expression *e2)
Expression *v = Equal(TOKequal, Type::tint32, ee1, ee2);
if (v == EXP_CANT_INTERPRET)
return EXP_CANT_INTERPRET;
cmp = v->toInteger();
cmp = (int)v->toInteger();
if (cmp == 0)
break;
}
Expand Down Expand Up @@ -1274,7 +1274,7 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
}
else if (e1->op == TOKarrayliteral)
{ ArrayLiteralExp *ale = (ArrayLiteralExp *)e1;
e = (*ale->elements)[i];
e = (*ale->elements)[(size_t)i];
e->type = type;
e->loc = loc;
if (e->hasSideEffect())
Expand All @@ -1293,7 +1293,7 @@ Expression *Index(Type *type, Expression *e1, Expression *e2)
e = new ErrorExp();
}
else
{ e = (*ale->elements)[i];
{ e = (*ale->elements)[(size_t)i];
e->type = type;
e->loc = loc;
if (e->hasSideEffect())
Expand Down Expand Up @@ -1353,8 +1353,8 @@ Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
else
{
void *s;
size_t len = iupr - ilwr;
int sz = es1->sz;
size_t len = (size_t)(iupr - ilwr);
unsigned char sz = es1->sz;
StringExp *es;

s = mem.malloc((len + 1) * sz);
Expand Down Expand Up @@ -1383,10 +1383,10 @@ Expression *Slice(Type *type, Expression *e1, Expression *lwr, Expression *upr)
else
{
Expressions *elements = new Expressions();
elements->setDim(iupr - ilwr);
elements->setDim((size_t)(iupr - ilwr));
memcpy(elements->tdata(),
es1->elements->tdata() + ilwr,
(iupr - ilwr) * sizeof((*es1->elements)[0]));
(size_t)(iupr - ilwr) * sizeof((*es1->elements)[0]));
e = new ArrayLiteralExp(e1->loc, elements);
e->type = type;
}
Expand Down Expand Up @@ -1431,8 +1431,8 @@ void sliceAssignStringFromArrayLiteral(StringExp *existingSE, ArrayLiteralExp *n
unsigned value = (unsigned)((*newae->elements)[j]->toInteger());
switch (existingSE->sz)
{
case 1: s[j+firstIndex] = value; break;
case 2: ((unsigned short *)s)[j+firstIndex] = value; break;
case 1: s[j+firstIndex] = (utf8_t)value; break;
case 2: ((unsigned short *)s)[j+firstIndex] = (unsigned short)value; break;
case 4: ((unsigned *)s)[j+firstIndex] = value; break;
default:
assert(0);
Expand Down Expand Up @@ -1521,16 +1521,16 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
StringExp *es;
if (t->nextOf())
t = t->nextOf()->toBasetype();
size_t sz = t->size();
unsigned char sz = (unsigned char)t->size();

dinteger_t v = e->toInteger();

size_t len = (t->ty == tn->ty) ? 1 : utf_codeLength(sz, v);
size_t len = (t->ty == tn->ty) ? 1 : utf_codeLength(sz, (dchar_t)v);
s = mem.malloc((len + 1) * sz);
if (t->ty == tn->ty)
memcpy((utf8_t *)s, &v, sz);
else
utf_encode(sz, s, v);
utf_encode(sz, s, (dchar_t)v);

// Add terminating 0
memset((utf8_t *)s + len * sz, 0, sz);
Expand Down Expand Up @@ -1575,7 +1575,7 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
StringExp *es2 = (StringExp *)e2;
StringExp *es;
size_t len = es1->len + es2->len;
int sz = es1->sz;
unsigned char sz = es1->sz;

if (sz != es2->sz)
{
Expand Down Expand Up @@ -1640,21 +1640,21 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
void *s;
StringExp *es1 = (StringExp *)e1;
StringExp *es;
size_t sz = es1->sz;
unsigned char sz = es1->sz;
dinteger_t v = e2->toInteger();

// Is it a concatentation of homogenous types?
// (char[] ~ char, wchar[]~wchar, or dchar[]~dchar)
bool homoConcat = (sz == t2->size());
size_t len = es1->len;
len += homoConcat ? 1 : utf_codeLength(sz, v);
len += homoConcat ? 1 : utf_codeLength(sz, (dchar_t)v);

s = mem.malloc((len + 1) * sz);
memcpy(s, es1->string, es1->len * sz);
if (homoConcat)
memcpy((utf8_t *)s + (sz * es1->len), &v, sz);
else
utf_encode(sz, (utf8_t *)s + (sz * es1->len), v);
utf_encode(sz, (utf8_t *)s + (sz * es1->len), (dchar_t)v);

// Add terminating 0
memset((utf8_t *)s + len * sz, 0, sz);
Expand All @@ -1672,7 +1672,7 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
StringExp *es2 = (StringExp *)e2;
StringExp *es;
size_t len = 1 + es2->len;
int sz = es2->sz;
unsigned char sz = es2->sz;
dinteger_t v = e1->toInteger();

s = mem.malloc((len + 1) * sz);
Expand Down Expand Up @@ -1802,7 +1802,7 @@ Expression *Ptr(Type *type, Expression *e1)
{ AddrExp *ade = (AddrExp *)ae->e1;
if (ade->e1->op == TOKstructliteral)
{ StructLiteralExp *se = (StructLiteralExp *)ade->e1;
unsigned offset = ae->e2->toInteger();
unsigned offset = (unsigned)ae->e2->toInteger();
Expression *e = se->getField(type, offset);
if (!e)
e = EXP_CANT_INTERPRET;
Expand Down
2 changes: 1 addition & 1 deletion src/ctfe.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type,

/// Create a string literal consisting of 'value' duplicated 'dim' times.
StringExp *createBlockDuplicatedStringLiteral(Loc loc, Type *type,
unsigned value, size_t dim, int sz);
unsigned value, size_t dim, unsigned char sz);


/* Set dest = src, where both dest and src are container value literals
Expand Down
40 changes: 20 additions & 20 deletions src/ctfeexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type,
{
// If it is a multidimensional array literal, do it recursively
elem = createBlockDuplicatedArrayLiteral(loc, type->nextOf(), elem,
((TypeSArray *)type->nextOf())->dim->toInteger());
(size_t)((TypeSArray *)type->nextOf())->dim->toInteger());
}
bool mustCopy = needToCopyLiteral(elem);
for (size_t i = 0; i < dim; i++)
Expand All @@ -489,15 +489,15 @@ ArrayLiteralExp *createBlockDuplicatedArrayLiteral(Loc loc, Type *type,
* Create a string literal consisting of 'value' duplicated 'dim' times.
*/
StringExp *createBlockDuplicatedStringLiteral(Loc loc, Type *type,
unsigned value, size_t dim, int sz)
unsigned value, size_t dim, unsigned char sz)
{
utf8_t *s = (utf8_t *)mem.calloc(dim + 1, sz);
for (size_t elemi = 0; elemi < dim; ++elemi)
{
switch (sz)
{
case 1: s[elemi] = value; break;
case 2: ((unsigned short *)s)[elemi] = value; break;
case 1: s[elemi] = (utf8_t)value; break;
case 2: ((unsigned short *)s)[elemi] = (unsigned short)value; break;
case 4: ((unsigned *)s)[elemi] = value; break;
default: assert(0);
}
Expand Down Expand Up @@ -786,7 +786,7 @@ int comparePointers(Loc loc, TOK op, Type *type, Expression *agg1, dinteger_t of
{
if ( pointToSameMemoryBlock(agg1, agg2) )
{
dinteger_t n;
int n;
switch(op)
{
case TOKlt: n = (ofs1 < ofs2); break;
Expand Down Expand Up @@ -880,7 +880,7 @@ Expression *paintFloatInt(Expression *fromVal, Type *to)
}
else
{
u.x = fromVal->toInteger();
u.x = (d_int32)fromVal->toInteger();
return new RealExp(fromVal->loc, ldouble(u.f), to);
}
}
Expand Down Expand Up @@ -1271,20 +1271,20 @@ int ctfeCmpArrays(Loc loc, Expression *e1, Expression *e2, uinteger_t len)

// Now both must be either TOKarrayliteral or TOKstring
if (se1 && se2)
return sliceCmpStringWithString(se1, se2, lo1, lo2, len);
return sliceCmpStringWithString(se1, se2, (size_t)lo1, (size_t)lo2, (size_t)len);
if (se1 && ae2)
return sliceCmpStringWithArray(se1, ae2, lo1, lo2, len);
return sliceCmpStringWithArray(se1, ae2, (size_t)lo1, (size_t)lo2, (size_t)len);
if (se2 && ae1)
return -sliceCmpStringWithArray(se2, ae1, lo2, lo1, len);
return -sliceCmpStringWithArray(se2, ae1, (size_t)lo2, (size_t)lo1, (size_t)len);

assert (ae1 && ae2);
// Comparing two array literals. This case is potentially recursive.
// If they aren't strings, we just need an equality check rather than
// a full cmp.
bool needCmp = ae1->type->nextOf()->isintegral();
for (size_t i = 0; i < len; i++)
{ Expression *ee1 = (*ae1->elements)[lo1 + i];
Expression *ee2 = (*ae2->elements)[lo2 + i];
{ Expression *ee1 = (*ae1->elements)[(size_t)(lo1 + i)];
Expression *ee2 = (*ae2->elements)[(size_t)(lo2 + i)];
if (needCmp)
{ sinteger_t c = ee1->toInteger() - ee2->toInteger();
if (c > 0)
Expand Down Expand Up @@ -1395,7 +1395,7 @@ int ctfeRawCmp(Loc loc, Expression *e1, Expression *e2)
if (res != 0)
return res;
}
return len1 - len2;
return (int)(len1 - len2);
}
if (e1->type->isintegral())
{
Expand Down Expand Up @@ -1574,7 +1574,7 @@ Expression *ctfeCat(Type *type, Expression *e1, Expression *e2)
StringExp *es1 = (StringExp *)e2;
ArrayLiteralExp *es2 = (ArrayLiteralExp *)e1;
size_t len = es1->len + es2->elements->dim;
int sz = es1->sz;
unsigned char sz = es1->sz;

void *s = mem.malloc((len + 1) * sz);
memcpy((char *)s + sz * es2->elements->dim, es1->string, es1->len * sz);
Expand Down Expand Up @@ -1605,7 +1605,7 @@ Expression *ctfeCat(Type *type, Expression *e1, Expression *e2)
StringExp *es1 = (StringExp *)e1;
ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2;
size_t len = es1->len + es2->elements->dim;
int sz = es1->sz;
unsigned char sz = es1->sz;

void *s = mem.malloc((len + 1) * sz);
memcpy(s, es1->string, es1->len * sz);
Expand Down Expand Up @@ -1701,7 +1701,7 @@ Expression *ctfeIndex(Loc loc, Type *type, Expression *e1, uinteger_t indx)
error(loc, "array index %llu is out of bounds %s[0 .. %llu]", indx, e1->toChars(), (ulonglong)ale->elements->dim);
return EXP_CANT_INTERPRET;
}
Expression *e = (*ale->elements)[indx];
Expression *e = (*ale->elements)[(size_t)indx];
return paintTypeOntoLiteral(type, e);
}

Expand Down Expand Up @@ -1904,7 +1904,7 @@ Expression *changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
// Resolve slices
size_t indxlo = 0;
if (oldval->op == TOKslice)
{ indxlo = ((SliceExp *)oldval)->lwr->toInteger();
{ indxlo = (size_t)((SliceExp *)oldval)->lwr->toInteger();
oldval = ((SliceExp *)oldval)->e1;
}
size_t copylen = oldlen < newlen ? oldlen : newlen;
Expand All @@ -1918,9 +1918,9 @@ Expression *changeArrayLiteralLength(Loc loc, TypeArray *arrayType,
{
switch (oldse->sz)
{
case 1: s[indxlo + elemi] = defaultValue; break;
case 2: ((unsigned short *)s)[indxlo + elemi] = defaultValue; break;
case 4: ((unsigned *)s)[indxlo + elemi] = defaultValue; break;
case 1: s[(size_t)(indxlo + elemi)] = (utf8_t)defaultValue; break;
case 2: ((unsigned short *)s)[(size_t)(indxlo + elemi)] = (unsigned short)defaultValue; break;
case 4: ((unsigned *)s)[(size_t)(indxlo + elemi)] = defaultValue; break;
default: assert(0);
}
}
Expand Down Expand Up @@ -2209,7 +2209,7 @@ Expression *TypeSArray::voidInitLiteral(VarDeclaration *var)
bool mustCopy = (elem->op == TOKarrayliteral || elem->op == TOKstructliteral);

Expressions *elements = new Expressions();
size_t d = dim->toInteger();
size_t d = (size_t)dim->toInteger();
elements->setDim(d);
for (size_t i = 0; i < d; i++)
{ if (mustCopy && i > 0)
Expand Down
4 changes: 2 additions & 2 deletions src/declaration.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const char *Declaration::kind()
unsigned Declaration::size(Loc loc)
{
assert(type);
return type->size();
return (unsigned)type->size();
}

bool Declaration::isDelete()
Expand Down Expand Up @@ -1709,7 +1709,7 @@ void VarDeclaration::setFieldOffset(AggregateDeclaration *ad, unsigned *poffset,
}


unsigned memsize = t->size(loc); // size of member
unsigned memsize = (unsigned)t->size(loc); // size of member
unsigned memalignsize = Target::fieldalign(t); // size of member for alignment purposes

offset = AggregateDeclaration::placeField(poffset, memsize, memalignsize, alignment,
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ void ScopeDsymbol::importScope(Dsymbol *s, PROT protection)
}
}
imports->push(s);
prots = (unsigned char *)mem.realloc(prots, imports->dim * sizeof(prots[0]));
prots = (PROT *)mem.realloc(prots, imports->dim * sizeof(prots[0]));
prots[imports->dim - 1] = protection;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class ScopeDsymbol : public Dsymbol
DsymbolTable *symtab; // members[] sorted into table

Dsymbols *imports; // imported Dsymbol's
unsigned char *prots; // array of PROT, one for each import
PROT *prots; // array of PROT, one for each import

ScopeDsymbol();
ScopeDsymbol(Identifier *id);
Expand Down
Loading

0 comments on commit c60a9a1

Please sign in to comment.