Skip to content

Commit

Permalink
Merge branch 'master' of github.com:D-Programming-Language/dmd
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Apr 6, 2013
2 parents f7f2a2d + a48b62f commit 4ba485b
Show file tree
Hide file tree
Showing 19 changed files with 198 additions and 177 deletions.
19 changes: 4 additions & 15 deletions src/cast.c
Expand Up @@ -1809,22 +1809,11 @@ Expression *SliceExp::castTo(Scope *sc, Type *t)
Expression *e;
if (typeb->ty == Tarray && tb->ty == Tsarray)
{
e = copy();

/* Rewrite:
* arr[lwr .. upr]
* as:
* *(cast(T[dim]*)(arr[lwr .. upr].ptr))
*
* Note that:
* static assert(dim == upr - lwr);
/* If a SliceExp has Tsarray, it will become lvalue.
* That's handled in SliceExp::isLvalue and toLvalue
*/
e = new DotIdExp(e->loc, e, Id::ptr);
e = e->semantic(sc);
e = e->castTo(sc, t->pointerTo());
e = new PtrExp(e->loc, e);
e = e->semantic(sc);
//printf("e = %s, %s => %s %s\n", toChars(), type->toChars(), e->toChars(), e->type->toChars());
e = copy();
e->type = t;
}
else
{
Expand Down
15 changes: 12 additions & 3 deletions src/e2ir.c
Expand Up @@ -4633,6 +4633,8 @@ elem *ArrayLengthExp::toElem(IRState *irs)
elem *SliceExp::toElem(IRState *irs)
{
//printf("SliceExp::toElem()\n");
Type *tb = type->toBasetype();
assert(tb->ty == Tarray || tb->ty == Tsarray && lwr);
Type *t1 = e1->type->toBasetype();
elem *e = e1->toElem(irs);
if (lwr)
Expand Down Expand Up @@ -4717,7 +4719,14 @@ elem *SliceExp::toElem(IRState *irs)
elem *elength = el_bin(OPmin, TYsize_t, eupr, elwr2);
eptr = el_bin(OPadd, TYnptr, eptr, el_bin(OPmul, TYsize_t, el_copytree(elwr2), el_long(TYsize_t, sz)));

e = el_pair(TYdarray, elength, eptr);
if (tb->ty == Tarray)
e = el_pair(TYdarray, elength, eptr);
else
{ assert(tb->ty == Tsarray);
e = el_una(OPind, type->totym(), eptr);
if (tybasic(e->Ety) == TYstruct)
e->ET = type->toCtype();
}
e = el_combine(elwr, e);
e = el_combine(einit, e);
}
Expand Down Expand Up @@ -5203,7 +5212,7 @@ elem *StructLiteralExp::toElem(IRState *irs)
{
if (t2b->implicitConvTo(t1b))
{
#if DMDV2
#if 0
// Determine if postblit is needed
int postblit = 0;
if (needsPostblit(t1b))
Expand Down Expand Up @@ -5252,7 +5261,7 @@ elem *StructLiteralExp::toElem(IRState *irs)
{ e1->Eoper = OPstreq;
e1->ET = v->type->toCtype();
}
#if DMDV2
#if 0
/* Call postblit() on e1
*/
StructDeclaration *sd = needsPostblit(v->type);
Expand Down
21 changes: 20 additions & 1 deletion src/expression.c
Expand Up @@ -4157,7 +4157,7 @@ Expression *StructLiteralExp::semantic(Scope *sc)
if (e->op == TOKerror)
return e;

(*elements)[i] = e;
(*elements)[i] = callCpCtor(e->loc, sc, e, 1);
}

/* Fill out remainder of elements[] with default initializers for fields[]
Expand Down Expand Up @@ -4735,6 +4735,8 @@ Expression *NewExp::semantic(Scope *sc)
newargs->shift(e);

f = resolveFuncCall(loc, sc, cd->aggNew, NULL, NULL, newargs);
if (!f)
goto Lerr;
allocator = f->isNewDeclaration();
assert(allocator);

Expand Down Expand Up @@ -4773,6 +4775,8 @@ Expression *NewExp::semantic(Scope *sc)
newargs->shift(e);

FuncDeclaration *f = resolveFuncCall(loc, sc, sd->aggNew, NULL, NULL, newargs);
if (!f)
goto Lerr;
allocator = f->isNewDeclaration();
assert(allocator);

Expand Down Expand Up @@ -9617,6 +9621,21 @@ int SliceExp::checkModifiable(Scope *sc, int flag)
return 1;
}

int SliceExp::isLvalue()
{
/* slice expression is rvalue in default, but
* conversion to reference of static array is only allowed.
*/
return (type && type->toBasetype()->ty == Tsarray);
}

Expression *SliceExp::toLvalue(Scope *sc, Expression *e)
{
//printf("SliceExp::toLvalue(%s) type = %s\n", toChars(), type ? type->toChars() : NULL);
return (type && type->toBasetype()->ty == Tsarray)
? this : Expression::toLvalue(sc, e);
}

Expression *SliceExp::modifiableLvalue(Scope *sc, Expression *e)
{
error("slice expression %s is not a modifiable lvalue", toChars());
Expand Down
2 changes: 2 additions & 0 deletions src/expression.h
Expand Up @@ -1146,6 +1146,8 @@ struct SliceExp : UnaExp
void checkEscape();
void checkEscapeRef();
int checkModifiable(Scope *sc, int flag);
int isLvalue();
Expression *toLvalue(Scope *sc, Expression *e);
Expression *modifiableLvalue(Scope *sc, Expression *e);
int isBool(int result);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expand Down
29 changes: 23 additions & 6 deletions src/func.c
Expand Up @@ -830,6 +830,21 @@ void FuncDeclaration::semantic(Scope *sc)
*/
scope = new Scope(*sc);
scope->setNoFree();

static bool printedMain = false; // semantic might run more than once
if (global.params.verbose && !printedMain)
{
const char *type = isMain() ? "main" : isWinMain() ? "winmain" : isDllMain() ? "dllmain" : NULL;
Module *mod = sc->module;

if (type && mod)
{
printedMain = true;
const char *name = FileName::searchPath(global.path, mod->srcfile->toChars(), 1);
printf("%-10s%-10s\t%s\n", "entry", type, name);
}
}

return;
}

Expand Down Expand Up @@ -2594,13 +2609,17 @@ FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expression *ethis, Ex
m.lastf->functionSemantic();
return m.lastf;
}
else if (m.last != MATCHnomatch && (flags & 2) && !ethis && m.lastf->needThis())

if (m.last != MATCHnomatch && (flags & 2) && !ethis && m.lastf->needThis())
{
return m.lastf;
}
else if (m.last == MATCHnomatch && (flags & 1))

/* Failed to find a best match.
* Do nothing or print error.
*/
if (m.last == MATCHnomatch && (flags & 1))
{ // if do not print error messages
return NULL; // no match
}
else
{
Expand Down Expand Up @@ -2635,8 +2654,6 @@ FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expression *ethis, Ex
tf->modToChars(),
buf.toChars());
}

return m.anyf; // as long as it's not a FuncAliasDeclaration
}
else
{
Expand All @@ -2647,9 +2664,9 @@ FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expression *ethis, Ex
buf.toChars(),
m.lastf->loc.filename, m.lastf->loc.linnum, m.lastf->toPrettyChars(), Parameter::argsTypesToChars(t1->parameters, t1->varargs),
m.nextf->loc.filename, m.nextf->loc.linnum, m.nextf->toPrettyChars(), Parameter::argsTypesToChars(t2->parameters, t2->varargs));
return m.lastf;
}
}
return NULL;
}

/*************************************
Expand Down

0 comments on commit 4ba485b

Please sign in to comment.