Merge dmdfe 2.057

This commit is contained in:
Alexey Prokhin 2011-12-15 12:05:24 +04:00
parent 4e8afa8858
commit 88cff99bd4
32 changed files with 2518 additions and 1378 deletions

View file

@ -241,6 +241,7 @@ struct ClassDeclaration : AggregateDeclaration
static ClassDeclaration *classinfo;
static ClassDeclaration *throwable;
static ClassDeclaration *exception;
static ClassDeclaration *errorException;
ClassDeclaration *baseClass; // NULL only if this is Object
#if DMDV1

View file

@ -47,8 +47,6 @@ void AliasThis::semantic(Scope *sc)
ad = parent->isAggregateDeclaration();
if (ad)
{
if (ad->aliasthis)
error("there can be only one alias this");
assert(ad->members);
Dsymbol *s = ad->search(loc, ident, 0);
if (!s)
@ -58,6 +56,8 @@ void AliasThis::semantic(Scope *sc)
else
::error(loc, "undefined identifier %s", ident->toChars());
}
else if (ad->aliasthis && s != ad->aliasthis)
error("there can be only one alias this");
ad->aliasthis = s;
}
else

View file

@ -155,7 +155,7 @@ void AttribDeclaration::semantic(Scope *sc)
//printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d);
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
for (size_t i = 0; i < d->dim; i++)
{
Dsymbol *s = d->tdata()[i];
@ -170,7 +170,7 @@ void AttribDeclaration::semantic2(Scope *sc)
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
for (size_t i = 0; i < d->dim; i++)
{ Dsymbol *s = d->tdata()[i];
s->semantic2(sc);
}
@ -183,7 +183,7 @@ void AttribDeclaration::semantic3(Scope *sc)
if (d)
{
for (unsigned i = 0; i < d->dim; i++)
for (size_t i = 0; i < d->dim; i++)
{ Dsymbol *s = d->tdata()[i];
s->semantic3(sc);
}
@ -297,6 +297,22 @@ int AttribDeclaration::hasPointers()
return 0;
}
bool AttribDeclaration::hasStaticCtorOrDtor()
{
Dsymbols *d = include(NULL, NULL);
if (d)
{
for (size_t i = 0; i < d->dim; i++)
{
Dsymbol *s = (*d)[i];
if (s->hasStaticCtorOrDtor())
return TRUE;
}
}
return FALSE;
}
const char *AttribDeclaration::kind()
{
return "attribute";

View file

@ -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
@ -49,6 +49,7 @@ struct AttribDeclaration : Dsymbol
const char *kind();
int oneMember(Dsymbol **ps);
int hasPointers();
bool hasStaticCtorOrDtor();
void checkCtorConstInit();
void addLocalClass(ClassDeclarations *);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);

View file

@ -395,23 +395,13 @@ MATCH NullExp::implicitConvTo(Type *t)
if (this->type->equals(t))
return MATCHexact;
/* Allow implicit conversions from invariant to mutable|const,
* and mutable to invariant. It works because, after all, a null
/* Allow implicit conversions from immutable to mutable|const,
* and mutable to immutable. It works because, after all, a null
* doesn't actually point to anything.
*/
if (t->invariantOf()->equals(type->invariantOf()))
return MATCHconst;
// NULL implicitly converts to any pointer type or dynamic array
if (type->ty == Tpointer && type->nextOf()->ty == Tvoid)
{
if (t->ty == Ttypedef)
t = ((TypeTypedef *)t)->sym->basetype;
if (t->ty == Tpointer || t->ty == Tarray ||
t->ty == Taarray || t->ty == Tclass ||
t->ty == Tdelegate)
return committed ? MATCHconvert : MATCHexact;
}
return Expression::implicitConvTo(t);
}
@ -923,18 +913,18 @@ Expression *ComplexExp::castTo(Scope *sc, Type *t)
Expression *NullExp::castTo(Scope *sc, Type *t)
{ NullExp *e;
Type *tb;
{
//printf("NullExp::castTo(t = %p)\n", t);
if (type == t)
{
committed = 1;
return this;
}
e = (NullExp *)copy();
NullExp *e = (NullExp *)copy();
e->committed = 1;
tb = t->toBasetype();
Type *tb = t->toBasetype();
#if 0
e->type = type->toBasetype();
if (tb != e->type)
{
@ -943,7 +933,6 @@ Expression *NullExp::castTo(Scope *sc, Type *t)
(tb->ty == Tpointer || tb->ty == Tarray || tb->ty == Taarray ||
tb->ty == Tdelegate))
{
#if 0
if (tb->ty == Tdelegate)
{ TypeDelegate *td = (TypeDelegate *)tb;
TypeFunction *tf = (TypeFunction *)td->nextOf();
@ -955,13 +944,19 @@ Expression *NullExp::castTo(Scope *sc, Type *t)
return Expression::castTo(sc, t);
}
}
#endif
}
else
{
//return e->Expression::castTo(sc, t);
}
}
#else
if (tb->ty == Tvoid)
{
e->type = type->toBasetype();
return e->Expression::castTo(sc, t);
}
}
#endif
e->type = t;
return e;
}
@ -1946,6 +1941,15 @@ Lagain:
}
else if (t1->ty == Tstruct && t2->ty == Tstruct)
{
if (t1->mod != t2->mod)
{
unsigned char mod = MODmerge(t1->mod, t2->mod);
t1 = t1->castMod(mod);
t2 = t2->castMod(mod);
t = t1;
goto Lagain;
}
TypeStruct *ts1 = (TypeStruct *)t1;
TypeStruct *ts2 = (TypeStruct *)t2;
if (ts1->sym != ts2->sym)
@ -1972,7 +1976,8 @@ Lagain:
e1b = resolveProperties(sc, e1b);
i2 = e1b->implicitConvTo(t2);
}
assert(!(i1 && i2));
if (i1 && i2)
goto Lincompatible;
if (i1)
goto Lt1;
@ -1987,9 +1992,41 @@ Lagain:
{ e2 = e2b;
t2 = e2b->type->toBasetype();
}
t = t1;
goto Lagain;
}
}
else if (t1->ty == Tstruct || t2->ty == Tstruct)
{
if (t1->mod != t2->mod)
{
unsigned char mod = MODmerge(t1->mod, t2->mod);
t1 = t1->castMod(mod);
t2 = t2->castMod(mod);
t = t1;
goto Lagain;
}
if (t1->ty == Tstruct && ((TypeStruct *)t1)->sym->aliasthis)
{
e1 = new DotIdExp(e1->loc, e1, ((TypeStruct *)t1)->sym->aliasthis->ident);
e1 = e1->semantic(sc);
e1 = resolveProperties(sc, e1);
t1 = e1->type;
t = t1;
goto Lagain;
}
if (t2->ty == Tstruct && ((TypeStruct *)t2)->sym->aliasthis)
{
e2 = new DotIdExp(e2->loc, e2, ((TypeStruct *)t2)->sym->aliasthis->ident);
e2 = e2->semantic(sc);
e2 = resolveProperties(sc, e2);
t2 = e2->type;
t = t2;
goto Lagain;
}
goto Lincompatible;
}
else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2))
{
goto Lt2;
@ -2091,19 +2128,12 @@ Expression *BinExp::typeCombine(Scope *sc)
if (op == TOKmin || op == TOKadd)
{
// struct+struct, where the structs are the same type, and class+class are errors
if (t1->ty == Tstruct)
{
if (t2->ty == Tstruct &&
((TypeStruct *)t1)->sym == ((TypeStruct *)t2)->sym)
// struct+struct, and class+class are errors
if (t1->ty == Tstruct && t2->ty == Tstruct)
goto Lerror;
}
else if (t1->ty == Tclass)
{
if (t2->ty == Tclass)
else if (t1->ty == Tclass && t2->ty == Tclass)
goto Lerror;
}
}
if (!typeMerge(sc, this, &type, &e1, &e2))
goto Lerror;

View file

@ -33,6 +33,7 @@ ClassDeclaration *ClassDeclaration::classinfo;
ClassDeclaration *ClassDeclaration::object;
ClassDeclaration *ClassDeclaration::throwable;
ClassDeclaration *ClassDeclaration::exception;
ClassDeclaration *ClassDeclaration::errorException;
ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses)
: AggregateDeclaration(loc, id)
@ -197,6 +198,12 @@ ClassDeclaration::ClassDeclaration(Loc loc, Identifier *id, BaseClasses *basecla
exception = this;
}
if (id == Id::Error)
{ if (errorException)
errorException->error("%s", msg);
errorException = this;
}
//if (id == Id::ClassInfo)
if (id == Id::TypeInfo_Class)
{ if (classinfo)

View file

@ -93,9 +93,8 @@ FuncDeclaration *StructDeclaration::buildOpAssign(Scope *sc)
FuncDeclaration *fop = NULL;
Parameter *param = new Parameter(STCnodtor, type, Id::p, NULL);
Parameters *fparams = new Parameters;
fparams->push(param);
fparams->push(new Parameter(STCnodtor, type, Id::p, NULL));
Type *ftype = new TypeFunction(fparams, handle, FALSE, LINKd);
#if STRUCTTHISREF
((TypeFunction *)ftype)->isref = 1;
@ -428,14 +427,17 @@ FuncDeclaration *StructDeclaration::buildCpCtor(Scope *sc)
{
//printf("generating cpctor\n");
Parameter *param = new Parameter(STCref, type->constOf(), Id::p, NULL);
StorageClass stc = postblit->storage_class &
(STCdisable | STCsafe | STCtrusted | STCsystem | STCpure | STCnothrow);
if (stc & (STCsafe | STCtrusted))
stc = stc & ~STCsafe | STCtrusted;
Parameters *fparams = new Parameters;
fparams->push(param);
Type *ftype = new TypeFunction(fparams, Type::tvoid, FALSE, LINKd);
fparams->push(new Parameter(STCref, type->constOf(), Id::p, NULL));
Type *ftype = new TypeFunction(fparams, Type::tvoid, FALSE, LINKd, stc);
ftype->mod = MODconst;
fcp = new FuncDeclaration(loc, 0, Id::cpctor, STCundefined, ftype);
fcp->storage_class |= postblit->storage_class & STCdisable;
fcp = new FuncDeclaration(loc, 0, Id::cpctor, stc, ftype);
if (!(fcp->storage_class & STCdisable))
{

View file

@ -1551,7 +1551,17 @@ Expression *Cat(Type *type, Expression *e1, Expression *e2)
else if (e1->op == TOKnull && e2->op == TOKnull)
{
if (type == e1->type)
{
// Handle null ~= null
if (t1->ty == Tarray && t2 == t1->nextOf())
{
e = new ArrayLiteralExp(e1->loc, e2);
e->type = type;
return e;
}
else
return e1;
}
if (type == e2->type)
return e2;
return new NullExp(e1->loc, type);

View file

@ -21,6 +21,7 @@
#include "module.h"
#include "id.h"
#include "expression.h"
#include "statement.h"
#include "hdrgen.h"
/********************************* Declaration ****************************/
@ -700,7 +701,7 @@ VarDeclaration::VarDeclaration(Loc loc, Type *type, Identifier *id, Initializer
aliassym = NULL;
onstack = 0;
canassign = 0;
setValueNull();
ctfeAdrOnStack = (size_t)(-1);
#if DMDV2
rundtor = NULL;
edtor = NULL;
@ -1162,11 +1163,17 @@ Lnomatch:
{
error("only parameters or stack based variables can be inout");
}
if (sc->func && !sc->func->type->hasWild())
FuncDeclaration *func = sc->func;
if (func)
{
if (func->fes)
func = func->fes->func;
if (!func->type->hasWild())
{
error("inout variables can only be declared inside inout functions");
}
}
}
if (!(storage_class & (STCctfe | STCref)) && tb->ty == Tstruct &&
((TypeStruct *)tb)->sym->noDefaultCtor)
@ -1701,8 +1708,12 @@ void VarDeclaration::checkNestedReference(Scope *sc, Loc loc)
// The current function
FuncDeclaration *fdthis = sc->parent->isFuncDeclaration();
if (fdv && fdthis && fdv != fdthis)
if (fdv && fdthis && fdv != fdthis/* && fdthis->ident != Id::ensure*/)
{
/* __ensure is always called directly,
* so it never becomes closure.
*/
if (loc.filename)
fdthis->getLevel(loc, fdv);
@ -1720,7 +1731,6 @@ void VarDeclaration::checkNestedReference(Scope *sc, Loc loc)
if (s == this)
goto L2;
}
fdv->closureVars.push(this);
L2: ;

View file

@ -286,13 +286,15 @@ struct VarDeclaration : Declaration
int canassign; // it can be assigned to
Dsymbol *aliassym; // if redone as alias to another symbol
// When interpreting, these hold the value (NULL if value not determinable)
// When interpreting, these point to the value (NULL if value not determinable)
// The index of this variable on the CTFE stack, -1 if not allocated
size_t ctfeAdrOnStack;
// The various functions are used only to detect compiler CTFE bugs
Expression *literalvalue;
Expression *getValue() { return literalvalue; }
Expression *getValue();
bool hasValue();
void setValueNull();
void setValueWithoutChecking(Expression *newval);
void createRefValue(Expression *newval); // struct or array literal
void createRefValue(Expression *newval);
void setRefValue(Expression *newval);
void setStackValue(Expression *newval);
void createStackValue(Expression *newval);
@ -782,6 +784,7 @@ struct FuncDeclaration : Declaration
void semantic3(Scope *sc);
// called from semantic3
void varArgs(Scope *sc, TypeFunction*, VarDeclaration *&, VarDeclaration *&);
VarDeclaration *declareThis(Scope *sc, AggregateDeclaration *ad);
int equals(Object *o);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@ -932,7 +935,7 @@ struct CtorDeclaration : FuncDeclaration
#if DMDV2
struct PostBlitDeclaration : FuncDeclaration
{
PostBlitDeclaration(Loc loc, Loc endloc);
PostBlitDeclaration(Loc loc, Loc endloc, StorageClass stc = STCundefined);
PostBlitDeclaration(Loc loc, Loc endloc, Identifier *id);
Dsymbol *syntaxCopy(Dsymbol *);
void semantic(Scope *sc);
@ -977,6 +980,7 @@ struct StaticCtorDeclaration : FuncDeclaration
int isVirtual();
int addPreInvariant();
int addPostInvariant();
bool hasStaticCtorOrDtor();
void emitComment(Scope *sc);
void toJsonBuffer(OutBuffer *buf);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
@ -1004,6 +1008,7 @@ struct StaticDtorDeclaration : FuncDeclaration
void semantic(Scope *sc);
AggregateDeclaration *isThis();
int isVirtual();
bool hasStaticCtorOrDtor();
int addPreInvariant();
int addPostInvariant();
void emitComment(Scope *sc);

View file

@ -167,6 +167,12 @@ int Dsymbol::hasPointers()
return 0;
}
bool Dsymbol::hasStaticCtorOrDtor()
{
//printf("Dsymbol::hasStaticCtorOrDtor() %s\n", toChars());
return FALSE;
}
char *Dsymbol::toChars()
{
return ident ? ident->toChars() : (char *)"__anonymous";
@ -1013,36 +1019,41 @@ Dsymbol *ScopeDsymbol::symtabInsert(Dsymbol *s)
return symtab->insert(s);
}
/****************************************
* Return true if any of the members are static ctors or static dtors, or if
* any members have members that are.
*/
bool ScopeDsymbol::hasStaticCtorOrDtor()
{
if (members)
{
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *member = (*members)[i];
if (member->hasStaticCtorOrDtor())
return TRUE;
}
}
return FALSE;
}
/***************************************
* Determine number of Dsymbols, folding in AttribDeclaration members.
*/
#if DMDV2
static int dimDg(void *ctx, size_t n, Dsymbol *)
{
++*(size_t *)ctx;
return 0;
}
size_t ScopeDsymbol::dim(Dsymbols *members)
{
size_t n = 0;
if (members)
{
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
AttribDeclaration *a = s->isAttribDeclaration();
TemplateMixin *tm = s->isTemplateMixin();
TemplateInstance *ti = s->isTemplateInstance();
if (a)
{
n += dim(a->decl);
}
else if (tm)
{
n += dim(tm->members);
}
else if (ti)
;
else
n++;
}
}
foreach(members, &dimDg, &n);
return n;
}
#endif
@ -1056,41 +1067,65 @@ size_t ScopeDsymbol::dim(Dsymbols *members)
*/
#if DMDV2
struct GetNthSymbolCtx
{
size_t nth;
Dsymbol *sym;
};
static int getNthSymbolDg(void *ctx, size_t n, Dsymbol *sym)
{
GetNthSymbolCtx *p = (GetNthSymbolCtx *)ctx;
if (n == p->nth)
{ p->sym = sym;
return 1;
}
return 0;
}
Dsymbol *ScopeDsymbol::getNth(Dsymbols *members, size_t nth, size_t *pn)
{
if (!members)
return NULL;
GetNthSymbolCtx ctx = { nth, NULL };
int res = foreach(members, &getNthSymbolDg, &ctx);
return res ? ctx.sym : NULL;
}
#endif
size_t n = 0;
/***************************************
* Expands attribute declarations in members in depth first
* order. Calls dg(void *ctx, size_t symidx, Dsymbol *sym) for each
* member.
* If dg returns !=0, stops and returns that value else returns 0.
* Use this function to avoid the O(N + N^2/2) complexity of
* calculating dim and calling N times getNth.
*/
#if DMDV2
int ScopeDsymbol::foreach(Dsymbols *members, ScopeDsymbol::ForeachDg dg, void *ctx, size_t *pn)
{
assert(members);
size_t n = pn ? *pn : 0; // take over index
int result = 0;
for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
AttribDeclaration *a = s->isAttribDeclaration();
TemplateMixin *tm = s->isTemplateMixin();
TemplateInstance *ti = s->isTemplateInstance();
if (a)
{
s = getNth(a->decl, nth - n, &n);
if (s)
return s;
}
else if (tm)
{
s = getNth(tm->members, nth - n, &n);
if (s)
return s;
}
else if (ti)
if (AttribDeclaration *a = s->isAttribDeclaration())
result = foreach(a->decl, dg, ctx, &n);
else if (TemplateMixin *tm = s->isTemplateMixin())
result = foreach(tm->members, dg, ctx, &n);
else if (s->isTemplateInstance())
;
else if (n == nth)
return s;
else
n++;
result = dg(ctx, n++, s);
if (result)
break;
}
if (pn)
*pn += n;
return NULL;
*pn = n; // update index
return result;
}
#endif
@ -1150,7 +1185,7 @@ Dsymbol *WithScopeSymbol::search(Loc loc, Identifier *ident, int flags)
ArrayScopeSymbol::ArrayScopeSymbol(Scope *sc, Expression *e)
: ScopeDsymbol()
{
assert(e->op == TOKindex || e->op == TOKslice);
assert(e->op == TOKindex || e->op == TOKslice || e->op == TOKarray);
exp = e;
type = NULL;
td = NULL;
@ -1225,6 +1260,68 @@ Dsymbol *ArrayScopeSymbol::search(Loc loc, Identifier *ident, int flags)
pvar = &se->lengthVar;
ce = se->e1;
}
else if (exp->op == TOKarray)
{ /* array[e0, e1, e2, e3] where e0, e1, e2 are some function of $
* $ is a opDollar!(dim)() where dim is the dimension(0,1,2,...)
*/
ArrayExp *ae = (ArrayExp *)exp;
AggregateDeclaration *ad = NULL;
Type *t = ae->e1->type->toBasetype();
if (t->ty == Tclass)
{
ad = ((TypeClass *)t)->sym;
}
else if (t->ty == Tstruct)
{
ad = ((TypeStruct *)t)->sym;
}
assert(ad);
Dsymbol *dsym = search_function(ad, Id::opDollar);
if (!dsym) // no dollar exists -- search in higher scope
return NULL;
VarDeclaration *v = ae->lengthVar;
if (!v)
{ // $ is lazily initialized. Create it now.
TemplateDeclaration *td = dsym->isTemplateDeclaration();
if (td)
{ // Instantiate opDollar!(dim) with the index as a template argument
Objects *tdargs = new Objects();
tdargs->setDim(1);
Expression *x = new IntegerExp(0, ae->currentDimension, Type::tsize_t);
x = x->semantic(sc);
tdargs->data[0] = x;
//TemplateInstance *ti = new TemplateInstance(loc, td, tdargs);
//ti->semantic(sc);
DotTemplateInstanceExp *dte = new DotTemplateInstanceExp(loc, ae->e1, td->ident, tdargs);
v = new VarDeclaration(loc, NULL, Id::dollar, new ExpInitializer(0, dte));
}
else
{ /* opDollar exists, but it's a function, not a template.
* This is acceptable ONLY for single-dimension indexing.
* Note that it's impossible to have both template & function opDollar,
* because both take no arguments.
*/
if (ae->arguments->dim != 1) {
ae->error("%s only defines opDollar for one dimension", ad->toChars());
return NULL;
}
FuncDeclaration *fd = dsym->isFuncDeclaration();
assert(fd);
Expression * x = new DotVarExp(loc, ae->e1, fd);
v = new VarDeclaration(loc, NULL, Id::dollar, new ExpInitializer(0, x));
}
v->semantic(sc);
ae->lengthVar = v;
}
return v;
}
else
/* Didn't find $, look in enclosing scope(s).
*/

View file

@ -206,6 +206,7 @@ struct Dsymbol : Object
virtual int oneMember(Dsymbol **ps);
static int oneMembers(Dsymbols *members, Dsymbol **ps);
virtual int hasPointers();
virtual bool hasStaticCtorOrDtor();
virtual void addLocalClass(ClassDeclarations *) { }
virtual void checkCtorConstInit() { }
@ -305,12 +306,16 @@ struct ScopeDsymbol : Dsymbol
const char *kind();
FuncDeclaration *findGetMembers();
virtual Dsymbol *symtabInsert(Dsymbol *s);
bool hasStaticCtorOrDtor();
void emitMemberComments(Scope *sc);
static size_t dim(Dsymbols *members);
static Dsymbol *getNth(Dsymbols *members, size_t nth, size_t *pn = NULL);
typedef int (*ForeachDg)(void *ctx, size_t idx, Dsymbol *s);
static int foreach(Dsymbols *members, ForeachDg dg, void *ctx, size_t *pn=NULL);
ScopeDsymbol *isScopeDsymbol() { return this; }
};

View file

@ -181,6 +181,15 @@ FuncDeclaration *hasThis(Scope *sc)
fdthis = sc->parent->isFuncDeclaration();
//printf("fdthis = %p, '%s'\n", fdthis, fdthis ? fdthis->toChars() : "");
/* Special case for inside template constraint
*/
if (fdthis && (sc->flags & SCOPEstaticif) && fdthis->parent->isTemplateDeclaration())
{
//TemplateDeclaration *td = fdthis->parent->isTemplateDeclaration();
//printf("[%s] td = %s, fdthis->vthis = %p\n", td->loc.toChars(), td->toChars(), fdthis->vthis);
return fdthis->vthis ? fdthis : NULL;
}
// Go upwards until we find the enclosing member function
fd = fdthis;
while (1)
@ -828,15 +837,13 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
L1:
if (!(p->storageClass & STClazy && p->type->ty == Tvoid))
{
if (p->type->hasWild())
{ unsigned mod = p->type->wildMatch(arg->type);
unsigned mod = arg->type->wildConvTo(p->type);
if (mod)
{
wildmatch |= mod;
arg = arg->implicitCastTo(sc, p->type->substWildTo(mod));
arg = arg->optimize(WANTvalue);
}
}
else if (p->type != arg->type)
{
//printf("arg->type = %s, p->type = %s\n", arg->type->toChars(), p->type->toChars());
@ -2996,8 +3003,7 @@ SuperExp::SuperExp(Loc loc)
}
Expression *SuperExp::semantic(Scope *sc)
{ FuncDeclaration *fd;
FuncDeclaration *fdthis;
{
ClassDeclaration *cd;
Dsymbol *s;
@ -3007,22 +3013,22 @@ Expression *SuperExp::semantic(Scope *sc)
if (type)
return this;
FuncDeclaration *fd = hasThis(sc);
/* Special case for typeof(this) and typeof(super) since both
* should work even if they are not inside a non-static member function
*/
if (sc->intypeof)
if (!fd && sc->intypeof)
{
// Find enclosing class
for (Dsymbol *s = sc->parent; 1; s = s->parent)
for (Dsymbol *s = sc->getStructClassScope(); 1; s = s->parent)
{
ClassDeclaration *cd;
if (!s)
{
error("%s is not in a class scope", toChars());
goto Lerr;
}
cd = s->isClassDeclaration();
ClassDeclaration *cd = s->isClassDeclaration();
if (cd)
{
cd = cd->baseClass;
@ -3035,11 +3041,9 @@ Expression *SuperExp::semantic(Scope *sc)
}
}
}
fdthis = sc->parent->isFuncDeclaration();
fd = hasThis(sc);
if (!fd)
goto Lerr;
assert(fd->vthis);
var = fd->vthis;
assert(var->parent);
@ -3060,6 +3064,7 @@ Expression *SuperExp::semantic(Scope *sc)
else
{
type = cd->baseClass->type;
type = type->castMod(var->type->mod);
}
var->isVarDeclaration()->checkNestedReference(sc, loc);
@ -3096,7 +3101,7 @@ Expression *NullExp::semantic(Scope *sc)
#endif
// NULL is the same as (void *)0
if (!type)
type = Type::tvoid->pointerTo();
type = Type::tnull;
return this;
}
@ -3519,10 +3524,19 @@ void StringExp::toMangleBuffer(OutBuffer *buf)
default:
assert(0);
}
buf->reserve(1 + 11 + 2 * qlen);
buf->writeByte(m);
buf->printf("%d_", qlen);
for (size_t i = 0; i < qlen; i++)
buf->printf("%02x", q[i]);
buf->printf("%d_", qlen); // nbytes <= 11
for (unsigned char *p = buf->data + buf->offset, *pend = p + 2 * qlen;
p < pend; p += 2, ++q)
{
unsigned char hi = *q >> 4 & 0xF;
p[0] = (hi < 10 ? hi + '0' : hi - 10 + 'a');
unsigned char lo = *q & 0xF;
p[1] = (lo < 10 ? lo + '0' : lo - 10 + 'a');
}
buf->offset += 2 * qlen;
}
/************************ ArrayLiteralExp ************************************/
@ -4146,6 +4160,10 @@ Lagain:
//printf("sds = %s, '%s'\n", sds->kind(), sds->toChars());
//printf("\tparent = '%s'\n", sds->parent->toChars());
sds->semantic(sc);
AggregateDeclaration *ad = sds->isAggregateDeclaration();
if (ad)
return (new TypeExp(loc, ad->type))->semantic(sc);
}
type = Type::tvoid;
//printf("-2ScopeExp::semantic() %s\n", toChars());
@ -7147,6 +7165,131 @@ Expression *CallExp::syntaxCopy()
}
Expression *CallExp::resolveUFCS(Scope *sc)
{
Expression *ethis = NULL;
DotIdExp *dotid;
DotTemplateInstanceExp *dotti;
Identifier *ident;
if (e1->op == TOKdot)
{
dotid = (DotIdExp *)e1;
ident = dotid->ident;
ethis = dotid->e1 = dotid->e1->semantic(sc);
if (ethis->op == TOKdotexp)
return NULL;
ethis = resolveProperties(sc, ethis);
}
else if (e1->op == TOKdotti)
{
dotti = (DotTemplateInstanceExp *)e1;
ident = dotti->ti->name;
ethis = dotti->e1 = dotti->e1->semantic(sc);
if (ethis->op == TOKdotexp)
return NULL;
ethis = resolveProperties(sc, ethis);
}
if (ethis && ethis->type)
{
AggregateDeclaration *ad;
Lagain:
Type *tthis = ethis->type->toBasetype();
if (tthis->ty == Tclass)
{
ad = ((TypeClass *)tthis)->sym;
if (search_function(ad, ident))
return NULL;
goto L1;
}
else if (tthis->ty == Tstruct)
{
ad = ((TypeStruct *)tthis)->sym;
if (search_function(ad, ident))
return NULL;
L1:
if (ad->aliasthis)
{
ethis = new DotIdExp(ethis->loc, ethis, ad->aliasthis->ident);
ethis = ethis->semantic(sc);
ethis = resolveProperties(sc, ethis);
goto Lagain;
}
}
else if (tthis->ty == Taarray && e1->op == TOKdot)
{
if (ident == Id::remove)
{
/* Transform:
* aa.remove(arg) into delete aa[arg]
*/
if (!arguments || arguments->dim != 1)
{ error("expected key as argument to aa.remove()");
return new ErrorExp();
}
Expression *key = arguments->tdata()[0];
key = key->semantic(sc);
key = resolveProperties(sc, key);
key->rvalue();
TypeAArray *taa = (TypeAArray *)tthis;
key = key->implicitCastTo(sc, taa->index);
return new RemoveExp(loc, ethis, key);
}
else if (ident == Id::apply || ident == Id::applyReverse)
{
return NULL;
}
else
{ TypeAArray *taa = (TypeAArray *)tthis;
assert(taa->ty == Taarray);
StructDeclaration *sd = taa->getImpl();
Dsymbol *s = sd->search(0, ident, 2);
if (s)
return NULL;
goto Lshift;
}
}
else if (tthis->ty == Tarray || tthis->ty == Tsarray)
{
Lshift:
if (!arguments)
arguments = new Expressions();
arguments->shift(ethis);
if (e1->op == TOKdot)
{
/* Transform:
* array.id(args) into .id(array,args)
*/
#if DMDV2
e1 = new DotIdExp(dotid->loc,
new IdentifierExp(dotid->loc, Id::empty),
ident);
#else
e1 = new IdentifierExp(dotid->loc, ident);
#endif
}
else if (e1->op == TOKdotti)
{
/* Transform:
* array.foo!(tiargs)(args) into .foo!(tiargs)(array,args)
*/
#if DMDV2
e1 = new DotExp(dotti->loc,
new IdentifierExp(dotti->loc, Id::empty),
new ScopeExp(dotti->loc, dotti->ti));
#else
e1 = new ScopeExp(dotti->loc, dotti->ti);
#endif
}
//printf("-> this = %s\n", toChars());
}
}
return NULL;
}
Expression *CallExp::semantic(Scope *sc)
{
TypeFunction *tf;
@ -7177,61 +7320,9 @@ Expression *CallExp::semantic(Scope *sc)
return semantic(sc);
}
/* Transform:
* array.id(args) into .id(array,args)
* aa.remove(arg) into delete aa[arg]
*/
if (e1->op == TOKdot)
{
// BUG: we should handle array.a.b.c.e(args) too
DotIdExp *dotid = (DotIdExp *)(e1);
dotid->e1 = dotid->e1->semantic(sc);
assert(dotid->e1);
if (dotid->e1->type)
{
TY e1ty = dotid->e1->type->toBasetype()->ty;
if (e1ty == Taarray && dotid->ident == Id::remove)
{
if (!arguments || arguments->dim != 1)
{ error("expected key as argument to aa.remove()");
return new ErrorExp();
}
Expression *key = arguments->tdata()[0];
key = key->semantic(sc);
key = resolveProperties(sc, key);
key->rvalue();
TypeAArray *taa = (TypeAArray *)dotid->e1->type->toBasetype();
key = key->implicitCastTo(sc, taa->index);
return new RemoveExp(loc, dotid->e1, key);
}
else if (e1ty == Tarray || e1ty == Tsarray ||
(e1ty == Taarray && dotid->ident != Id::apply && dotid->ident != Id::applyReverse))
{
if (e1ty == Taarray)
{ TypeAArray *taa = (TypeAArray *)dotid->e1->type->toBasetype();
assert(taa->ty == Taarray);
StructDeclaration *sd = taa->getImpl();
Dsymbol *s = sd->search(0, dotid->ident, 2);
if (s)
goto L2;
}
if (!arguments)
arguments = new Expressions();
arguments->shift(dotid->e1);
#if DMDV2
e1 = new DotIdExp(dotid->loc, new IdentifierExp(dotid->loc, Id::empty), dotid->ident);
#else
e1 = new IdentifierExp(dotid->loc, dotid->ident);
#endif
}
L2:
;
}
}
Expression *e = resolveUFCS(sc);
if (e)
return e;
#if 1
/* This recognizes:
@ -7769,7 +7860,7 @@ Lagain:
if (sc->func->setImpure())
error("pure function '%s' cannot call impure function pointer '%s'", sc->func->toChars(), e1->toChars());
}
if (sc->func && !((TypeFunction *)t1)->trust <= TRUSTsystem)
if (sc->func && ((TypeFunction *)t1)->trust <= TRUSTsystem)
{
if (sc->func->setUnsafe())
error("safe function '%s' cannot call system function pointer '%s'", sc->func->toChars(), e1->toChars());
@ -8181,6 +8272,8 @@ Expression *PtrExp::semantic(Scope *sc)
case Tsarray:
case Tarray:
if (!global.params.useDeprecated)
error("using * on an array is deprecated; use *(%s).ptr instead", e1->toChars());
type = ((TypeArray *)tb)->next;
e1 = e1->castTo(sc, type->pointerTo());
break;
@ -9095,6 +9188,8 @@ ArrayExp::ArrayExp(Loc loc, Expression *e1, Expressions *args)
: UnaExp(loc, TOKarray, sizeof(ArrayExp), e1)
{
arguments = args;
lengthVar = NULL;
currentDimension = 0;
}
Expression *ArrayExp::syntaxCopy()
@ -9639,6 +9734,29 @@ Expression *AssignExp::semantic(Scope *sc)
// Rewrite (a[i] = value) to (a.opIndexAssign(value, i))
if (search_function(ad, Id::indexass))
{ Expression *e = new DotIdExp(loc, ae->e1, Id::indexass);
// Deal with $
for (size_t i = 0; i < ae->arguments->dim; i++)
{ Expression *x = ae->arguments->tdata()[i];
// Create scope for '$' variable for this dimension
ArrayScopeSymbol *sym = new ArrayScopeSymbol(sc, ae);
sym->loc = loc;
sym->parent = sc->scopesym;
sc = sc->push(sym);
ae->lengthVar = NULL; // Create it only if required
ae->currentDimension = i; // Dimension for $, if required
x = x->semantic(sc);
if (!x->type)
ae->error("%s has no value", x->toChars());
if (ae->lengthVar)
{ // If $ was used, declare it now
Expression *av = new DeclarationExp(ae->loc, ae->lengthVar);
x = new CommaExp(0, av, x);
x->semantic(sc);
}
ae->arguments->tdata()[i] = x;
sc = sc->pop();
}
Expressions *a = (Expressions *)ae->arguments->copy();
a->insert(0, e2);
@ -10089,7 +10207,7 @@ Expression *AssignExp::checkToBoolean(Scope *sc)
// if (a = b) ...
// are usually mistakes.
error("'=' does not give a boolean result");
error("assignment cannot be used as a condition, perhaps == was meant?");
return new ErrorExp();
}
@ -10865,7 +10983,7 @@ Expression *MinExp::semantic(Scope *sc)
else if (t2->isintegral())
e = scaleFactor(sc);
else
{ error("incompatible types for minus");
{ error("can't subtract %s from pointer", t2->toChars());
return new ErrorExp();
}
}
@ -11762,7 +11880,33 @@ Expression *CmpExp::semantic(Scope *sc)
return new ErrorExp();
}
Expression *eb1 = e1;
Expression *eb2 = e2;
typeCombine(sc);
#if 0
// For integer comparisons, ensure the combined type can hold both arguments.
if (type && type->isintegral() && (op == TOKlt || op == TOKle ||
op == TOKgt || op == TOKge))
{
IntRange trange = IntRange::fromType(type);
Expression *errorexp = 0;
if (!trange.contains(eb1->getIntRange()))
errorexp = eb1;
if (!trange.contains(eb2->getIntRange()))
errorexp = eb2;
if (errorexp)
{
error("implicit conversion of '%s' to '%s' is unsafe in '(%s) %s (%s)'",
errorexp->toChars(), type->toChars(), eb1->toChars(), Token::toChars(op), eb2->toChars());
return new ErrorExp();
}
}
#endif
type = Type::tboolean;
// Special handling for array comparisons

View file

@ -1135,6 +1135,7 @@ struct CallExp : UnaExp
CallExp(Loc loc, Expression *e, Expression *earg1, Expression *earg2);
Expression *syntaxCopy();
Expression *resolveUFCS(Scope *sc);
Expression *semantic(Scope *sc);
Expression *optimize(int result);
Expression *interpret(InterState *istate, CtfeGoal goal = ctfeNeedRvalue);
@ -1402,6 +1403,8 @@ struct ArrayLengthExp : UnaExp
struct ArrayExp : UnaExp
{
Expressions *arguments; // Array of Expression's
size_t currentDimension; // for opDollar
VarDeclaration *lengthVar;
ArrayExp(Loc loc, Expression *e1, Expressions *arguments);
Expression *syntaxCopy();

View file

@ -423,7 +423,7 @@ void FuncDeclaration::semantic(Scope *sc)
// ctor = (CtorDeclaration *)this;
// if (!cd->ctor)
// cd->ctor = ctor;
return;
goto Ldone;
}
#if 0
@ -923,7 +923,8 @@ void FuncDeclaration::semantic3(Scope *sc)
sc2->sw = NULL;
sc2->fes = fes;
sc2->linkage = LINKd;
sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract | STCdeprecated |
sc2->stc &= ~(STCauto | STCscope | STCstatic | STCabstract |
STCdeprecated | STCoverride |
STC_TYPECTOR | STCfinal | STCtls | STCgshared | STCref |
STCproperty | STCsafe | STCtrusted | STCsystem);
sc2->protection = PROTpublic;
@ -941,76 +942,16 @@ void FuncDeclaration::semantic3(Scope *sc)
// Declare 'this'
AggregateDeclaration *ad = isThis();
if (ad)
{ VarDeclaration *v;
{
if (isFuncLiteralDeclaration() && isNested() && !sc->intypeof)
{
error("function literals cannot be class members");
return;
}
else
{
assert(!isNested() || sc->intypeof); // can't be both member and nested
assert(ad->handle);
Type *thandle = ad->handle;
#if STRUCTTHISREF
thandle = thandle->addMod(type->mod);
thandle = thandle->addStorageClass(storage_class);
//if (isPure())
//thandle = thandle->addMod(MODconst);
#else
if (storage_class & STCconst || type->isConst())
{
assert(0); // BUG: shared not handled
if (thandle->ty == Tclass)
thandle = thandle->constOf();
else
{ assert(thandle->ty == Tpointer);
thandle = thandle->nextOf()->constOf()->pointerTo();
}
}
else if (storage_class & STCimmutable || type->isImmutable())
{
if (thandle->ty == Tclass)
thandle = thandle->invariantOf();
else
{ assert(thandle->ty == Tpointer);
thandle = thandle->nextOf()->invariantOf()->pointerTo();
}
}
else if (storage_class & STCshared || type->isShared())
{
assert(0); // not implemented
}
#endif
v = new ThisDeclaration(loc, thandle);
//v = new ThisDeclaration(loc, isCtorDeclaration() ? ad->handle : thandle);
v->storage_class |= STCparameter;
#if STRUCTTHISREF
if (thandle->ty == Tstruct)
v->storage_class |= STCref;
#endif
v->semantic(sc2);
if (!sc2->insert(v))
assert(0);
v->parent = this;
vthis = v;
}
}
else if (isNested())
{
/* The 'this' for a nested function is the link to the
* enclosing function's stack frame.
* Note that nested functions and member functions are disjoint.
*/
VarDeclaration *v = new ThisDeclaration(loc, Type::tvoid->pointerTo());
v->storage_class |= STCparameter;
v->semantic(sc2);
if (!sc2->insert(v))
assert(0);
v->parent = this;
vthis = v;
}
vthis = declareThis(sc2, ad);
// Declare hidden variable _arguments[] and _argptr
if (f->varargs == 1)
@ -1363,7 +1304,7 @@ void FuncDeclaration::semantic3(Scope *sc)
if (!type->nextOf())
{
((TypeFunction *)type)->next = Type::tvoid;
type = type->semantic(loc, sc);
//type = type->semantic(loc, sc); // Removed with 6902
}
f = (TypeFunction *)type;
}
@ -1835,6 +1776,12 @@ void FuncDeclaration::semantic3(Scope *sc)
f->trust = TRUSTsafe;
}
// Do semantic type AFTER pure/nothrow inference.
if (inferRetType)
{
type = type->semantic(loc, sc);
}
if (global.gag && global.errors != nerrors)
semanticRun = PASSsemanticdone; // Ensure errors get reported again
else
@ -1852,6 +1799,76 @@ void FuncDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
bodyToCBuffer(buf, hgs);
}
VarDeclaration *FuncDeclaration::declareThis(Scope *sc, AggregateDeclaration *ad)
{
if (ad)
{ VarDeclaration *v;
{
assert(ad->handle);
Type *thandle = ad->handle;
#if STRUCTTHISREF
thandle = thandle->addMod(type->mod);
thandle = thandle->addStorageClass(storage_class);
//if (isPure())
//thandle = thandle->addMod(MODconst);
#else
if (storage_class & STCconst || type->isConst())
{
assert(0); // BUG: shared not handled
if (thandle->ty == Tclass)
thandle = thandle->constOf();
else
{ assert(thandle->ty == Tpointer);
thandle = thandle->nextOf()->constOf()->pointerTo();
}
}
else if (storage_class & STCimmutable || type->isImmutable())
{
if (thandle->ty == Tclass)
thandle = thandle->invariantOf();
else
{ assert(thandle->ty == Tpointer);
thandle = thandle->nextOf()->invariantOf()->pointerTo();
}
}
else if (storage_class & STCshared || type->isShared())
{
assert(0); // not implemented
}
#endif
v = new ThisDeclaration(loc, thandle);
//v = new ThisDeclaration(loc, isCtorDeclaration() ? ad->handle : thandle);
v->storage_class |= STCparameter;
#if STRUCTTHISREF
if (thandle->ty == Tstruct)
v->storage_class |= STCref;
#endif
v->semantic(sc);
if (!sc->insert(v))
assert(0);
v->parent = this;
return v;
}
}
else if (isNested())
{
/* The 'this' for a nested function is the link to the
* enclosing function's stack frame.
* Note that nested functions and member functions are disjoint.
*/
VarDeclaration *v = new ThisDeclaration(loc, Type::tvoid->pointerTo());
v->storage_class |= STCparameter;
v->semantic(sc);
if (!sc->insert(v))
assert(0);
v->parent = this;
return v;
}
return NULL;
}
int FuncDeclaration::equals(Object *o)
{
if (this == o)
@ -3313,8 +3330,8 @@ int CtorDeclaration::addPostInvariant()
/********************************* PostBlitDeclaration ****************************/
#if DMDV2
PostBlitDeclaration::PostBlitDeclaration(Loc loc, Loc endloc)
: FuncDeclaration(loc, endloc, Id::_postblit, STCundefined, NULL)
PostBlitDeclaration::PostBlitDeclaration(Loc loc, Loc endloc, StorageClass stc)
: FuncDeclaration(loc, endloc, Id::_postblit, stc, NULL)
{
}
@ -3347,7 +3364,7 @@ void PostBlitDeclaration::semantic(Scope *sc)
ad->postblits.push(this);
if (!type)
type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd);
type = new TypeFunction(NULL, Type::tvoid, FALSE, LINKd, storage_class);
sc = sc->push();
sc->stc &= ~STCstatic; // not static
@ -3557,6 +3574,11 @@ int StaticCtorDeclaration::isVirtual()
return FALSE;
}
bool StaticCtorDeclaration::hasStaticCtorOrDtor()
{
return TRUE;
}
int StaticCtorDeclaration::addPreInvariant()
{
return FALSE;
@ -3684,6 +3706,11 @@ int StaticDtorDeclaration::isVirtual()
return FALSE;
}
bool StaticDtorDeclaration::hasStaticCtorOrDtor()
{
return TRUE;
}
int StaticDtorDeclaration::addPreInvariant()
{
return FALSE;

View file

@ -66,6 +66,7 @@ Msgtable msgtable[] =
{ "Exception" },
{ "AssociativeArray" },
{ "Throwable" },
{ "Error" },
{ "withSym", "__withSym" },
{ "result", "__result" },
{ "returnLabel", "__returnLabel" },
@ -215,6 +216,7 @@ Msgtable msgtable[] =
{ "opStar" },
{ "opDot" },
{ "opDispatch" },
{ "opDollar" },
{ "opUnary" },
{ "opIndexUnary" },
{ "opSliceUnary" },

File diff suppressed because it is too large Load diff

View file

@ -21,7 +21,7 @@
static uinteger_t copySign(uinteger_t x, bool sign)
{
// return sign ? -x : x;
return (x - sign) ^ -sign;
return (x - (uinteger_t)sign) ^ -(uinteger_t)sign;
}
#ifndef UINT64_MAX

View file

@ -54,6 +54,8 @@ void obj_start(char *srcfile);
void obj_end(Library *library, File *objfile);
#endif
void printCtfePerformanceStats();
Global global;
Global::Global()
@ -100,7 +102,7 @@ Global::Global()
"\nMSIL back-end (alpha release) by Cristian L. Vlasceanu and associates.";
#endif
;
version = "v2.056";
version = "v2.057";
#if IN_LLVM
ldc_version = "LDC trunk";
llvm_version = "LLVM 3.0";
@ -1318,6 +1320,8 @@ int main(int argc, char *argv[])
if (global.errors || global.warnings)
fatal();
printCtfePerformanceStats();
Library *library = NULL;
if (global.params.lib)
{

File diff suppressed because it is too large Load diff

View file

@ -70,8 +70,8 @@ enum ENUMTY
Tident,
Tclass,
Tstruct,
Tenum,
Ttypedef,
Tdelegate,
Tnone,
@ -81,8 +81,8 @@ enum ENUMTY
Tint16,
Tuns16,
Tint32,
Tuns32,
Tint64,
Tuns64,
Tfloat32,
@ -92,8 +92,8 @@ enum ENUMTY
Timaginary64,
Timaginary80,
Tcomplex32,
Tcomplex64,
Tcomplex80,
Tbool,
Tchar,
@ -102,10 +102,11 @@ enum ENUMTY
Terror,
Tinstance,
Ttypeof,
Ttuple,
Tslice,
Treturn,
Tnull,
TMAX
};
typedef unsigned char TY; // ENUMTY
@ -187,6 +188,8 @@ struct Type : Object
static Type *tstring; // immutable(char)[]
#define terror basic[Terror] // for error recovery
#define tnull basic[Tnull] // for null type
#define tsize_t basic[Tsize_t] // matches size_t alias
#define tptrdiff_t basic[Tptrdiff_t] // matches ptrdiff_t alias
#define thash_t tsize_t // matches hash_t alias
@ -293,6 +296,7 @@ struct Type : Object
Type *pointerTo();
Type *referenceTo();
Type *arrayOf();
Type *aliasthisOf();
virtual Type *makeConst();
virtual Type *makeInvariant();
virtual Type *makeShared();
@ -302,10 +306,12 @@ struct Type : Object
virtual Type *makeMutable();
virtual Dsymbol *toDsymbol(Scope *sc);
virtual Type *toBasetype();
virtual Type *toHeadMutable();
virtual int isBaseOf(Type *t, int *poffset);
virtual MATCH constConv(Type *to);
virtual MATCH implicitConvTo(Type *to);
virtual MATCH constConv(Type *to);
virtual unsigned wildConvTo(Type *tprm);
Type *substWildTo(unsigned mod);
virtual Type *toHeadMutable();
virtual ClassDeclaration *isClassHandle();
virtual Expression *getProperty(Loc loc, Identifier *ident);
virtual Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
@ -326,8 +332,6 @@ struct Type : Object
virtual int builtinTypeInfo();
virtual Type *reliesOnTident();
virtual int hasWild();
unsigned wildMatch(Type *targ);
Type *substWildTo(unsigned mod);
virtual Expression *toExpression();
virtual int hasPointers();
virtual TypeTuple *toArgTypes();
@ -359,6 +363,7 @@ struct Type : Object
struct TypeError : Type
{
TypeError();
Type *syntaxCopy();
void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs);
@ -387,6 +392,7 @@ struct TypeNext : Type
Type *makeSharedWild();
Type *makeMutable();
MATCH constConv(Type *to);
unsigned wildConvTo(Type *tprm);
void transitive();
};
@ -788,6 +794,7 @@ struct TypeStruct : Type
TypeTuple *toArgTypes();
MATCH implicitConvTo(Type *to);
MATCH constConv(Type *to);
unsigned wildConvTo(Type *tprm);
Type *toHeadMutable();
#if CPP_MANGLE
void toCppMangle(OutBuffer *buf, CppMangleState *cms);
@ -874,6 +881,7 @@ struct TypeTypedef : Type
Type *toBasetype();
MATCH implicitConvTo(Type *to);
MATCH constConv(Type *to);
Type *toHeadMutable();
Expression *defaultInit(Loc loc);
Expression *defaultInitLiteral(Loc loc);
int isZeroInit(Loc loc);
@ -885,7 +893,6 @@ struct TypeTypedef : Type
int hasPointers();
TypeTuple *toArgTypes();
int hasWild();
Type *toHeadMutable();
#if CPP_MANGLE
void toCppMangle(OutBuffer *buf, CppMangleState *cms);
#endif
@ -912,6 +919,9 @@ struct TypeClass : Type
ClassDeclaration *isClassHandle();
int isBaseOf(Type *t, int *poffset);
MATCH implicitConvTo(Type *to);
MATCH constConv(Type *to);
unsigned wildConvTo(Type *tprm);
Type *toHeadMutable();
Expression *defaultInit(Loc loc);
int isZeroInit(Loc loc);
MATCH deduceType(Scope *sc, Type *tparam, TemplateParameters *parameters, Objects *dedtypes, unsigned *wildmatch = NULL);
@ -921,13 +931,9 @@ struct TypeClass : Type
int hasPointers();
TypeTuple *toArgTypes();
int builtinTypeInfo();
#if DMDV2
Type *toHeadMutable();
MATCH constConv(Type *to);
#if CPP_MANGLE
void toCppMangle(OutBuffer *buf, CppMangleState *cms);
#endif
#endif
#if IN_DMD
type *toCtype();
@ -967,6 +973,23 @@ struct TypeSlice : TypeNext
void toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod);
};
struct TypeNull : Type
{
TypeNull();
Type *syntaxCopy();
void toDecoBuffer(OutBuffer *buf, int flag);
MATCH implicitConvTo(Type *to);
void toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs);
d_uns64 size(Loc loc);
//Expression *getProperty(Loc loc, Identifier *ident);
//Expression *dotExp(Scope *sc, Expression *e, Identifier *ident);
Expression *defaultInit(Loc loc);
//Expression *defaultInitLiteral(Loc loc);
};
/**************************************************************/
//enum InOut { None, In, Out, InOut, Lazy };
@ -991,6 +1014,9 @@ struct Parameter : Object
static int isTPL(Parameters *arguments);
static size_t dim(Parameters *arguments);
static Parameter *getNth(Parameters *arguments, size_t nth, size_t *pn = NULL);
typedef int (*ForeachDg)(void *ctx, size_t paramidx, Parameter *param, int flags);
static int foreach(Parameters *args, ForeachDg dg, void *ctx, size_t *pn=NULL, int flags = 0);
};
extern int PTRSIZE;

View file

@ -28,6 +28,7 @@
#include "mtype.h"
#include "init.h"
#include "expression.h"
#include "scope.h"
#include "id.h"
#include "declaration.h"
#include "aggregate.h"
@ -373,6 +374,29 @@ Expression *ArrayExp::op_overload(Scope *sc)
Dsymbol *fd = search_function(ad, opId());
if (fd)
{
for (size_t i = 0; i < arguments->dim; i++)
{ Expression *x = arguments->tdata()[i];
// Create scope for '$' variable for this dimension
ArrayScopeSymbol *sym = new ArrayScopeSymbol(sc, this);
sym->loc = loc;
sym->parent = sc->scopesym;
sc = sc->push(sym);
lengthVar = NULL; // Create it only if required
currentDimension = i; // Dimension for $, if required
x = x->semantic(sc);
if (!x->type)
error("%s has no value", x->toChars());
if (lengthVar)
{ // If $ was used, declare it now
Expression *av = new DeclarationExp(loc, lengthVar);
x = new CommaExp(0, av, x);
x->semantic(sc);
}
arguments->tdata()[i] = x;
sc = sc->pop();
}
/* Rewrite op e1[arguments] as:
* e1.opIndex(arguments)
*/

View file

@ -266,6 +266,8 @@ Dsymbols *Parser::parseDeclDefs(int once)
}
else
{
if (!global.params.useDeprecated)
error("use of 'invariant' rather than 'immutable' is deprecated");
stc = STCimmutable;
goto Lstc;
}
@ -407,7 +409,11 @@ Dsymbols *Parser::parseDeclDefs(int once)
else if (token.value == TOKwild)
stc = STCwild;
else
{
if (token.value == TOKinvariant && !global.params.useDeprecated)
error("use of 'invariant' rather than 'immutable' is deprecated");
stc = STCimmutable;
}
goto Lstc;
case TOKfinal: stc = STCfinal; goto Lstc;
case TOKauto: stc = STCauto; goto Lstc;
@ -981,7 +987,8 @@ Dsymbol *Parser::parseCtor()
nextToken();
nextToken();
check(TOKrparen);
PostBlitDeclaration *f = new PostBlitDeclaration(loc, 0);
StorageClass stc = parsePostfix();
PostBlitDeclaration *f = new PostBlitDeclaration(loc, 0, stc);
parseContracts(f);
return f;
}
@ -1278,6 +1285,8 @@ Parameters *Parser::parseParameters(int *pvarargs)
case TOKimmutable:
if (peek(&token)->value == TOKlparen)
goto Ldefault;
if (token.value == TOKinvariant && !global.params.useDeprecated)
error("use of 'invariant' rather than 'immutable' is deprecated");
stc = STCimmutable;
goto L2;
@ -2366,7 +2375,9 @@ Type *Parser::parseBasicType()
check(TOKlparen);
t = parseType();
check(TOKrparen);
if (t->isShared())
if (t->isImmutable())
;
else if (t->isShared())
t = t->makeSharedConst();
else
t = t->makeConst();
@ -2390,7 +2401,9 @@ Type *Parser::parseBasicType()
check(TOKlparen);
t = parseType();
check(TOKrparen);
if (t->isConst())
if (t->isImmutable())
;
else if (t->isConst())
t = t->makeSharedConst();
else if (t->isWild())
t = t->makeSharedWild();
@ -2404,7 +2417,9 @@ Type *Parser::parseBasicType()
check(TOKlparen);
t = parseType();
check(TOKrparen);
if (t->isShared())
if (t->isImmutable()/* || t->isConst()*/)
;
else if (t->isShared())
t = t->makeSharedWild();
else
t = t->makeWild();
@ -2511,7 +2526,7 @@ Type *Parser::parseBasicType2(Type *t)
return NULL;
}
Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl, StorageClass storage_class)
Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl, StorageClass storage_class, int* pdisable)
{ Type *ts;
//printf("parseDeclarator(tpl = %p)\n", tpl);
@ -2643,6 +2658,8 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
stc |= storage_class; // merge prefix storage classes
Type *tf = new TypeFunction(arguments, t, varargs, linkage, stc);
tf = tf->addSTC(stc);
if (pdisable)
*pdisable = stc & STCdisable ? 1 : 0;
/* Insert tf into
* ts -> ... -> t
@ -2673,6 +2690,7 @@ Type *Parser::parseDeclarator(Type *t, Identifier **pident, TemplateParameters *
Dsymbols *Parser::parseDeclarations(StorageClass storage_class, unsigned char *comment)
{
StorageClass stc;
int disable;
Type *ts;
Type *t;
Type *tfirst;
@ -2711,6 +2729,8 @@ Dsymbols *Parser::parseDeclarations(StorageClass storage_class, unsigned char *c
}
break;
case TOKtypedef:
if (!global.params.useDeprecated)
error("use of typedef is deprecated; use alias instead");
tok = token.value;
nextToken();
break;
@ -2731,6 +2751,8 @@ Dsymbols *Parser::parseDeclarations(StorageClass storage_class, unsigned char *c
case TOKimmutable:
if (peek(&token)->value == TOKlparen)
break;
if (token.value == TOKinvariant && !global.params.useDeprecated)
error("use of 'invariant' rather than 'immutable' is deprecated");
stc = STCimmutable;
goto L1;
@ -2814,7 +2836,11 @@ Dsymbols *Parser::parseDeclarations(StorageClass storage_class, unsigned char *c
token.value == TOKidentifier &&
(tk = peek(&token))->value == TOKlparen &&
skipParens(tk, &tk) &&
peek(tk)->value == TOKlparen)
((tk = peek(tk)), 1) &&
skipAttributes(tk, &tk) &&
(tk->value == TOKlparen ||
tk->value == TOKlcurly)
)
{
ts = NULL;
}
@ -2835,7 +2861,7 @@ L2:
TemplateParameters *tpl = NULL;
ident = NULL;
t = parseDeclarator(ts, &ident, &tpl, storage_class);
t = parseDeclarator(ts, &ident, &tpl, storage_class, &disable);
assert(t);
if (!tfirst)
tfirst = t;
@ -2855,7 +2881,10 @@ L2:
init = parseInitializer();
}
if (tok == TOKtypedef)
v = new TypedefDeclaration(loc, ident, t, init);
{ v = new TypedefDeclaration(loc, ident, t, init);
if (!global.params.useDeprecated)
error("use of typedef is deprecated; use alias instead");
}
else
{ if (init)
error("alias cannot have initializer");
@ -2902,7 +2931,7 @@ L2:
//printf("%s funcdecl t = %s, storage_class = x%lx\n", loc.toChars(), t->toChars(), storage_class);
FuncDeclaration *f =
new FuncDeclaration(loc, 0, ident, storage_class, t);
new FuncDeclaration(loc, 0, ident, storage_class | (disable ? STCdisable : 0), t);
addComment(f, comment);
if (tpl)
constraint = parseConstraint();
@ -5031,7 +5060,8 @@ int Parser::skipAttributes(Token *t, Token **pt)
//case TOKmanifest:
break;
case TOKat:
if (parseAttribute() == STCundefined)
t = peek(t);
if (t->value == TOKidentifier)
break;
goto Lerror;
default:
@ -5335,6 +5365,8 @@ Expression *Parser::parsePrimaryExp()
token.value == TOKdelegate ||
token.value == TOKreturn))
{
if (token.value == TOKinvariant && !global.params.useDeprecated)
error("use of 'invariant' rather than 'immutable' is deprecated");
tok2 = token.value;
nextToken();
}
@ -5708,6 +5740,8 @@ Expression *Parser::parseUnaryExp()
}
else if ((token.value == TOKimmutable || token.value == TOKinvariant) && peekNext() == TOKrparen)
{
if (token.value == TOKinvariant && !global.params.useDeprecated)
error("use of 'invariant' rather than 'immutable' is deprecated");
m = MODimmutable;
goto Lmod2;
}

View file

@ -108,7 +108,7 @@ struct Parser : Lexer
Type *parseType(Identifier **pident = NULL, TemplateParameters **tpl = NULL);
Type *parseBasicType();
Type *parseBasicType2(Type *t);
Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL, StorageClass storage_class = 0);
Type *parseDeclarator(Type *t, Identifier **pident, TemplateParameters **tpl = NULL, StorageClass storage_class = 0, int* pdisable = NULL);
Dsymbols *parseDeclarations(StorageClass storage_class, unsigned char *comment);
void parseContracts(FuncDeclaration *f);
void checkDanglingElse(Loc elseloc);

View file

@ -449,6 +449,12 @@ Statement *CompileStatement::semantic(Scope *sc)
return s->semantic(sc);
}
int CompileStatement::blockExit(bool mustNotThrow)
{
assert(global.errors);
return BEfallthru;
}
/******************************** CompoundStatement ***************************/
@ -1493,6 +1499,7 @@ Lretry:
{ // Declare key
if (arg->storageClass & (STCout | STCref | STClazy))
error("no storage class for key %s", arg->ident->toChars());
arg->type = arg->type->semantic(loc, sc);
TY keyty = arg->type->ty;
if (keyty != Tint32 && keyty != Tuns32)
{
@ -3707,9 +3714,26 @@ Statement *ReturnStatement::semantic(Scope *sc)
Type *tfret = tf->nextOf();
if (tfret)
{
if (tfret != Type::terror && !exp->type->equals(tfret))
if (tfret != Type::terror)
{
if (!exp->type->equals(tfret))
{
int m1 = exp->type->implicitConvTo(tfret);
int m2 = tfret->implicitConvTo(exp->type);
//printf("exp->type = %s m2<-->m1 tret %s\n", exp->type->toChars(), tfret->toChars());
//printf("m1 = %d, m2 = %d\n", m1, m2);
if (m1 && m2)
;
else if (!m1 && m2)
tf->next = exp->type;
else if (m1 && !m2)
;
else
error("mismatched function return type inference of %s and %s",
exp->type->toChars(), tfret->toChars());
}
}
/* The "refness" is determined by the first return statement,
* not all of them. This means:
@ -3739,7 +3763,7 @@ Statement *ReturnStatement::semantic(Scope *sc)
tf->isref = FALSE; // return by value
}
tf->next = exp->type;
fd->type = tf->semantic(loc, sc);
//fd->type = tf->semantic(loc, sc); // Removed with 6902
if (!fd->tintro)
{ tret = fd->type->nextOf();
tbret = tret->toBasetype();
@ -3755,6 +3779,8 @@ Statement *ReturnStatement::semantic(Scope *sc)
exp = exp->castTo(sc, exp->type->invariantOf());
}
if (fd->tintro)
exp = exp->implicitCastTo(sc, fd->type->nextOf());
exp = exp->implicitCastTo(sc, tret);
if (!((TypeFunction *)fd->type)->isref)
exp = exp->optimize(WANTvalue);

View file

@ -211,6 +211,7 @@ struct CompileStatement : Statement
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Statements *flatten(Scope *sc);
Statement *semantic(Scope *sc);
int blockExit(bool mustNotThrow);
};
struct CompoundStatement : Statement

View file

@ -766,7 +766,25 @@ MATCH TemplateDeclaration::matchWithInstance(TemplateInstance *ti,
Expression *e = constraint->syntaxCopy();
Scope *sc = paramscope->push();
sc->flags |= SCOPEstaticif;
FuncDeclaration *fd = onemember && onemember->toAlias() ?
onemember->toAlias()->isFuncDeclaration() : NULL;
Dsymbol *s = parent;
while (s->isTemplateInstance() || s->isTemplateMixin())
s = s->parent;
AggregateDeclaration *ad = s->isAggregateDeclaration();
VarDeclaration *vthissave;
if (fd && ad)
{
vthissave = fd->vthis;
fd->vthis = fd->declareThis(paramscope, ad);
}
e = e->semantic(sc);
if (fd && fd->vthis)
fd->vthis = vthissave;
sc->pop();
e = e->optimize(WANTvalue | WANTinterpret);
if (e->isBool(TRUE))
@ -924,7 +942,7 @@ MATCH TemplateDeclaration::deduceFunctionTemplateMatch(Scope *sc, Loc loc, Objec
#if 0
printf("\nTemplateDeclaration::deduceFunctionTemplateMatch() %s\n", toChars());
for (i = 0; i < fargs->dim; i++)
for (size_t i = 0; i < fargs->dim; i++)
{ Expression *e = fargs->tdata()[i];
printf("\tfarg[%d] is %s, type is %s\n", i, e->toChars(), e->type->toChars());
}
@ -1188,7 +1206,9 @@ L2:
}
}
else
{ Expression *farg = fargs->tdata()[i];
{
Expression *farg = fargs->tdata()[i];
Lretry:
#if 0
printf("\tfarg->type = %s\n", farg->type->toChars());
printf("\tfparam->type = %s\n", fparam->type->toChars());
@ -1208,6 +1228,14 @@ L2:
argtype = argtype->invariantOf();
}
}
/* Remove top const for dynamic array types and pointer types
*/
if ((argtype->ty == Tarray || argtype->ty == Tpointer) &&
!argtype->isMutable())
{
argtype = argtype->mutableOf();
}
#endif
MATCH m;
@ -1219,7 +1247,11 @@ L2:
/* If no match, see if there's a conversion to a delegate
*/
if (!m && fparam->type->toBasetype()->ty == Tdelegate)
if (!m)
{ Type *tbp = fparam->type->toBasetype();
Type *tba = farg->type->toBasetype();
AggregateDeclaration *ad;
if (tbp->ty == Tdelegate)
{
TypeDelegate *td = (TypeDelegate *)fparam->type->toBasetype();
TypeFunction *tf = (TypeFunction *)td->next;
@ -1232,6 +1264,25 @@ L2:
}
//printf("\tm2 = %d\n", m);
}
else if (tba->ty == Tclass)
{
ad = ((TypeClass *)tba)->sym;
goto Lad;
}
else if (tba->ty == Tstruct)
{
ad = ((TypeStruct *)tba)->sym;
Lad:
if (ad->aliasthis)
{
Expression *e = new DotIdExp(farg->loc, farg, ad->aliasthis->ident);
e = e->semantic(sc);
e = resolveProperties(sc, e);
farg = e;
goto Lretry;
}
}
}
if (m)
{ if (m < match)
@ -1399,8 +1450,24 @@ Lmatch:
int nerrors = global.errors;
FuncDeclaration *fd = onemember && onemember->toAlias() ?
onemember->toAlias()->isFuncDeclaration() : NULL;
Dsymbol *s = parent;
while (s->isTemplateInstance() || s->isTemplateMixin())
s = s->parent;
AggregateDeclaration *ad = s->isAggregateDeclaration();
VarDeclaration *vthissave;
if (fd && ad)
{
vthissave = fd->vthis;
fd->vthis = fd->declareThis(paramscope, ad);
}
e = e->semantic(paramscope);
if (fd && fd->vthis)
fd->vthis = vthissave;
previous = pr.prev; // unlink from threaded list
if (nerrors != global.errors) // if any errors from evaluating the constraint, no match
@ -1682,6 +1749,11 @@ FuncDeclaration *TemplateDeclaration::deduceFunctionTemplate(Scope *sc, Loc loc,
return NULL;
}
bool TemplateDeclaration::hasStaticCtorOrDtor()
{
return FALSE; // don't scan uninstantiated templates
}
void TemplateDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs)
{
#if 0 // Should handle template functions for doc generation
@ -2107,18 +2179,44 @@ MATCH TypeSArray::deduceType(Scope *sc, Type *tparam, TemplateParameters *parame
// Extra check that array dimensions must match
if (tparam)
{
if (tparam->ty == Tarray)
{ MATCH m;
m = next->deduceType(sc, tparam->nextOf(), parameters, dedtypes, wildmatch);
if (m == MATCHexact)
m = MATCHconvert;
return m;
}
Identifier *id = NULL;
if (tparam->ty == Tsarray)
{
TypeSArray *tp = (TypeSArray *)tparam;
if (tp->dim->op == TOKvar &&
((VarExp *)tp->dim)->var->storage_class & STCtemplateparameter)
{ int i = templateIdentifierLookup(((VarExp *)tp->dim)->var->ident, parameters);
{
id = ((VarExp *)tp->dim)->var->ident;
}
else if (dim->toInteger() != tp->dim->toInteger())
return MATCHnomatch;
}
else if (tparam->ty == Taarray)
{
TypeAArray *tp = (TypeAArray *)tparam;
if (tp->index->ty == Tident &&
((TypeIdentifier *)tp->index)->idents.dim == 0)
{
id = ((TypeIdentifier *)tp->index)->ident;
}
}
if (id)
{
// This code matches code in TypeInstance::deduceType()
int i = templateIdentifierLookup(id, parameters);
if (i == -1)
goto Lnomatch;
TemplateParameter *tp = parameters->tdata()[i];
TemplateValueParameter *tvp = tp->isTemplateValueParameter();
TemplateParameter *tprm = parameters->tdata()[i];
TemplateValueParameter *tvp = tprm->isTemplateValueParameter();
if (!tvp)
goto Lnomatch;
Expression *e = (Expression *)dedtypes->tdata()[i];
@ -2128,58 +2226,16 @@ MATCH TypeSArray::deduceType(Scope *sc, Type *tparam, TemplateParameters *parame
goto Lnomatch;
}
else
{ Type *vt = tvp->valType->semantic(0, sc);
{
Type *vt = tvp->valType->semantic(0, sc);
MATCH m = (MATCH)dim->implicitConvTo(vt);
if (!m)
goto Lnomatch;
dedtypes->tdata()[i] = dim;
}
}
else if (dim->toInteger() != tp->dim->toInteger())
return MATCHnomatch;
}
else if (tparam->ty == Taarray)
{
TypeAArray *tp = (TypeAArray *)tparam;
if (tp->index->ty == Tident)
{ TypeIdentifier *tident = (TypeIdentifier *)tp->index;
if (tident->idents.dim == 0)
{ Identifier *id = tident->ident;
for (size_t i = 0; i < parameters->dim; i++)
{
TemplateParameter *tp = parameters->tdata()[i];
if (tp->ident->equals(id))
{ // Found the corresponding template parameter
TemplateValueParameter *tvp = tp->isTemplateValueParameter();
if (!tvp || !tvp->valType->isintegral())
goto Lnomatch;
if (dedtypes->tdata()[i])
{
if (!dim->equals(dedtypes->tdata()[i]))
goto Lnomatch;
}
else
{ dedtypes->tdata()[i] = dim;
}
return next->deduceType(sc, tparam->nextOf(), parameters, dedtypes, wildmatch);
}
}
}
}
}
else if (tparam->ty == Tarray)
{ MATCH m;
m = next->deduceType(sc, tparam->nextOf(), parameters, dedtypes, wildmatch);
if (m == MATCHexact)
m = MATCHconvert;
return m;
}
}
return Type::deduceType(sc, tparam, parameters, dedtypes, wildmatch);
Lnomatch:
@ -2228,6 +2284,7 @@ MATCH TypeFunction::deduceType(Scope *sc, Type *tparam, TemplateParameters *para
{
Parameter *fparam = Parameter::getNth(tp->parameters, i);
fparam->type = fparam->type->addStorageClass(fparam->storageClass);
fparam->storageClass &= ~(STC_TYPECTOR | STCin);
}
//printf("\t-> this = %d, ", ty); print();
//printf("\t-> tparam = %d, ", tparam->ty); tparam->print();
@ -3490,6 +3547,19 @@ MATCH TemplateValueParameter::matchArg(Scope *sc,
ei = ei->optimize(WANTvalue | WANTinterpret);
}
//printf("\tvalType: %s, ty = %d\n", valType->toChars(), valType->ty);
vt = valType->semantic(0, sc);
//printf("ei: %s, ei->type: %s\n", ei->toChars(), ei->type->toChars());
//printf("vt = %s\n", vt->toChars());
if (ei->type)
{
m = (MATCH)ei->implicitConvTo(vt);
//printf("m: %d\n", m);
if (!m)
goto Lnomatch;
}
if (specValue)
{
if (!ei || ei == edummy)
@ -3504,6 +3574,7 @@ MATCH TemplateValueParameter::matchArg(Scope *sc,
ei = ei->syntaxCopy();
ei = ei->semantic(sc);
ei = ei->implicitCastTo(sc, vt);
ei = ei->optimize(WANTvalue | WANTinterpret);
//ei->type = ei->type->toHeadMutable();
//printf("\tei: %s, %s\n", ei->toChars(), ei->type->toChars());
@ -3511,24 +3582,20 @@ MATCH TemplateValueParameter::matchArg(Scope *sc,
if (!ei->equals(e))
goto Lnomatch;
}
else if (dedtypes->tdata()[i])
else
{
if (dedtypes->tdata()[i])
{ // Must match already deduced value
Expression *e = (Expression *)dedtypes->tdata()[i];
if (!ei || !ei->equals(e))
goto Lnomatch;
}
//printf("\tvalType: %s, ty = %d\n", valType->toChars(), valType->ty);
vt = valType->semantic(0, sc);
//printf("ei: %s, ei->type: %s\n", ei->toChars(), ei->type->toChars());
//printf("vt = %s\n", vt->toChars());
if (ei->type)
else if (m != MATCHexact)
{
m = (MATCH)ei->implicitConvTo(vt);
//printf("m: %d\n", m);
if (!m)
goto Lnomatch;
ei = ei->implicitCastTo(sc, vt);
ei = ei->optimize(WANTvalue | WANTinterpret);
}
}
dedtypes->tdata()[i] = ei;

View file

@ -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
@ -81,6 +81,7 @@ struct TemplateDeclaration : ScopeDsymbol
void semantic(Scope *sc);
int overloadInsert(Dsymbol *s);
void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
bool hasStaticCtorOrDtor();
const char *kind();
char *toChars();

View file

@ -258,9 +258,21 @@ Expression *TraitsExp::semantic(Scope *sc)
}
if (ident == Id::hasMember)
{ /* Take any errors as meaning it wasn't found
{
if (t)
{
Dsymbol *sym = t->toDsymbol(sc);
Dsymbol *sm = sym->search(loc, id, 0);
if (sm)
goto Ltrue;
}
/* Take any errors as meaning it wasn't found
*/
e = e->trySemantic(sc);
Scope *sc2 = sc->push();
//sc2->inHasMember++;
e = e->trySemantic(sc2);
sc2->pop();
if (!e)
{ if (global.gag)
{
@ -344,40 +356,56 @@ Expression *TraitsExp::semantic(Scope *sc)
error("%s %s has no members", s->kind(), s->toChars());
goto Lfalse;
}
Expressions *exps = new Expressions;
while (1)
{ size_t sddim = ScopeDsymbol::dim(sd->members);
for (size_t i = 0; i < sddim; i++)
// use a struct as local function
struct PushIdentsDg
{
static int dg(void *ctx, size_t n, Dsymbol *sm)
{
Dsymbol *sm = ScopeDsymbol::getNth(sd->members, i);
if (!sm)
break;
return 1;
//printf("\t[%i] %s %s\n", i, sm->kind(), sm->toChars());
if (sm->ident)
{
//printf("\t%s\n", sm->ident->toChars());
char *str = sm->ident->toChars();
Identifiers *idents = (Identifiers *)ctx;
/* Skip if already present in exps[]
/* Skip if already present in idents[]
*/
for (size_t j = 0; j < exps->dim; j++)
{ StringExp *se2 = (StringExp *)exps->tdata()[j];
if (strcmp(str, (char *)se2->string) == 0)
goto Lnext;
for (size_t j = 0; j < idents->dim; j++)
{ Identifier *id = idents->tdata()[j];
if (id == sm->ident)
return 0;
#ifdef DEBUG
// Avoid using strcmp in the first place due to the performance impact in an O(N^2) loop.
assert(strcmp(id->toChars(), sm->ident->toChars()) != 0);
#endif
}
StringExp *se = new StringExp(loc, str);
exps->push(se);
idents->push(sm->ident);
}
Lnext:
;
return 0;
}
};
Identifiers *idents = new Identifiers;
ScopeDsymbol::foreach(sd->members, &PushIdentsDg::dg, idents);
ClassDeclaration *cd = sd->isClassDeclaration();
if (cd && cd->baseClass && ident == Id::allMembers)
sd = cd->baseClass; // do again with base class
else
break;
{ sd = cd->baseClass; // do again with base class
ScopeDsymbol::foreach(sd->members, &PushIdentsDg::dg, idents);
}
// Turn Identifiers into StringExps reusing the allocated array
assert(sizeof(Expressions) == sizeof(Identifiers));
Expressions *exps = (Expressions *)idents;
for (size_t i = 0; i < idents->dim; i++)
{ Identifier *id = idents->tdata()[i];
StringExp *se = new StringExp(loc, id->toChars());
exps->tdata()[i] = se;
}
#if DMDV1
Expression *e = new ArrayLiteralExp(loc, exps);
#endif

View file

@ -306,10 +306,13 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
if (fdecl->ir.resolved) return;
fdecl->ir.resolved = true;
// If errors occurred compiling it, such as bugzilla 6118
Type *type = fdecl->type;
if (type && type->ty == Tfunction && ((TypeFunction *)type)->next->ty == Terror)
// If errors occurred compiling it, such as bugzilla 6118
if (type && type->ty == Tfunction) {
Type *next = ((TypeFunction *)type)->next;
if (!next || next->ty == Terror)
return;
}
//printf("resolve function: %s\n", fdecl->toPrettyChars());

@ -1 +1 @@
Subproject commit 24e79c6c38b4cfc9aca1d3583a1c0fffc102c9ce
Subproject commit 10e4512f453fcafde9448a41c672ee7315229963

@ -1 +1 @@
Subproject commit 2bebc8f8ba261b41fb0252b225232b8f46051b57
Subproject commit 1f6264e94236e5cd20d211e136f05a88cb536b00