Squashed 'dmd2/' changes from fc63fd3..82e6a91

82e6a91 Resolve rvalue reference on template function arguments
3708457 Implement rvalue reference for struct literal & construction
530a59f Revert "struct literals are lvalues again"
f199933 struct literals are lvalues again
5f181da better error message for Issue 7815 - Mixin template forward reference (?) regression
e5452d5 fix Issue 7888 - derivedMembers forward reference error with nested imports
b77ae4f merge with D1
5fed58d fix Issue 7886 - derivedMembers infinite recursion
0cf5ecd Merge pull request #872 from 9rnsr/fix7873
744f102 fix Issue 7695 - Regression(2.058): ICE(mtype.c) on associative array with keys of struct type with const members
80fc228 fix Issue 7873 - IFTI with inout does not properly match template parameter if called from inout function for pointers
4a5d365 fix CTFE bugs reported in beta
df22942 add kind()
d36a3b4 Merge pull request #871 from 9rnsr/fix7871
66d1302 fix Issue 7871 - RangeViolation with findSplitBefore
020ab91 fix Issue 7811 - "not a property" error instead of real error on UFCS array template property
c349458 fix Issue 7862 - Accepts-invalid template forward reference bug related to derivedMembers
00d8ec8 fix Issue 7861 - Segfault during __error propagation with self-referencing module
4c9652d fix fwd ref bug
477c357 fix Issue 7859 - Crash on invalid alias template parameter type
c35f67a fix Issue 7858 - __traits(getOverloads) returns incorrect symbol
bc840e8 fix Issue 7815 - Mixin template forward reference (?) regression
18a1485 fix auto test break
ceef368 fix Issue 7826 - [D2 Beta] Cannot use getHash in toHash without a warning
d747fd6 fix Issue 7820 - regression(DMD 2.059head) Wrong error on forward reference to 'front' with -property switch
1094601 fix Issue 7823 - Can't use a struct initializer to initialize a nested enum used as a default function argument initializer

git-subtree-dir: dmd2
git-subtree-split: 82e6a91f234843be7f660b242f8b8819c1eae20c
This commit is contained in:
Alexey Prokhin
2012-04-22 09:41:54 +04:00
parent bfad290036
commit eadd5fb645
16 changed files with 297 additions and 56 deletions

View File

@@ -314,7 +314,15 @@ void checkPropertyCall(Expression *e, Expression *emsg)
{ CallExp *ce = (CallExp *)e;
TypeFunction *tf;
if (ce->f)
{
tf = (TypeFunction *)ce->f->type;
/* If a forward reference to ce->f, try to resolve it
*/
if (!tf->deco && ce->f->scope)
{ ce->f->semantic(ce->f->scope);
tf = (TypeFunction *)ce->f->type;
}
}
else if (ce->e1->type->ty == Tfunction)
tf = (TypeFunction *)ce->e1->type;
else if (ce->e1->type->ty == Tdelegate)
@@ -366,46 +374,54 @@ Expression *resolveUFCSProperties(Scope *sc, Expression *e1, Expression *e2 = NU
else
e = new DotIdExp(loc, e, ident);
Expressions *arguments = new Expressions();
/* .f(e1, e2)
*/
if (e2)
{
arguments->setDim(2);
(*arguments)[0] = eleft;
(*arguments)[1] = e2;
/* .f(e1) = e2
*/
Expression *ex = e->syntaxCopy();
e = new CallExp(loc, e, arguments);
e = e->trySemantic(sc);
if (e)
{ checkPropertyCall(e, e1);
return e->semantic(sc);
}
e = ex;
}
Expressions *a1 = new Expressions();
a1->setDim(1);
(*a1)[0] = eleft;
ex = new CallExp(loc, ex, a1);
ex = ex->trySemantic(sc);
/* .f(e1)
* .f(e1) = e2
*/
/* .f(e1, e2)
*/
Expressions *a2 = new Expressions();
a2->setDim(2);
(*a2)[0] = eleft;
(*a2)[1] = e2;
e = new CallExp(loc, e, a2);
if (ex)
{ // if fallback setter exists, gag errors
e = e->trySemantic(sc);
if (!e)
{ checkPropertyCall(ex, e1);
ex = new AssignExp(loc, ex, e2);
return ex->semantic(sc);
}
}
else
{ // strict setter prints errors if fails
e = e->semantic(sc);
}
checkPropertyCall(e, e1);
return e;
}
else
{
/* .f(e1)
*/
Expressions *arguments = new Expressions();
arguments->setDim(1);
(*arguments)[0] = eleft;
e = new CallExp(loc, e, arguments);
e = e->trySemantic(sc);
if (!e)
goto Leprop;
e = e->semantic(sc);
checkPropertyCall(e, e1);
if (e2)
e = new AssignExp(loc, e, e2);
return e->semantic(sc);
}
}
return e;
Leprop:
e1->error("not a property %s", e1->toChars());
return new ErrorExp();
}
/******************************
@@ -1021,7 +1037,37 @@ Type *functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
}
if (p->storageClass & STCref)
{
arg = arg->toLvalue(sc, arg);
if (arg->op == TOKstructliteral)
{
Identifier *idtmp = Lexer::uniqueId("__tmpsl");
VarDeclaration *tmp = new VarDeclaration(loc, arg->type, idtmp, new ExpInitializer(0, arg));
tmp->storage_class |= STCctfe;
Expression *ae = new DeclarationExp(loc, tmp);
Expression *e = new CommaExp(loc, ae, new VarExp(loc, tmp));
e = e->semantic(sc);
arg = e;
}
else if (arg->op == TOKcall)
{
CallExp *ce = (CallExp *)arg;
if (ce->e1->op == TOKdotvar &&
((DotVarExp *)ce->e1)->var->isCtorDeclaration())
{
DotVarExp *dve = (DotVarExp *)ce->e1;
assert(dve->e1->op == TOKcomma);
assert(((CommaExp *)dve->e1)->e2->op == TOKvar);
VarExp *ve = (VarExp *)((CommaExp *)dve->e1)->e2;
VarDeclaration *tmp = ve->var->isVarDeclaration();
arg = new CommaExp(arg->loc, arg, new VarExp(loc, tmp));
arg = arg->semantic(sc);
}
else
arg = arg->toLvalue(sc, arg);
}
else
arg = arg->toLvalue(sc, arg);
}
else if (p->storageClass & STCout)
{
@@ -6674,9 +6720,29 @@ Expression *DotIdExp::semantic(Scope *sc, int flag)
{ goto L2;
}
unsigned errors = global.startGagging();
/* This would be much better if we added a "hasProperty" method to types,
* i.e. the gagging is a bad way.
*/
if (t1b->ty == Taarray)
{
TypeAArray *taa = (TypeAArray *)t1b;
if (!taa->impl &&
ident != Id::__sizeof &&
ident != Id::__xalignof &&
ident != Id::init &&
ident != Id::mangleof &&
ident != Id::stringof &&
ident != Id::offsetof)
{
// Find out about these errors when not gagged
taa->getImpl();
}
}
Type *t1 = e1->type;
e = e1->type->dotExp(sc, e1, ident);
unsigned errors = global.startGagging();
e = t1->dotExp(sc, e1, ident);
if (global.endGagging(errors)) // if failed to find the property
{
e1->type = t1; // kludge to restore type
@@ -8716,6 +8782,8 @@ Expression *CastExp::semantic(Scope *sc)
}
else
to = to->semantic(loc, sc);
if (to == Type::terror)
return new ErrorExp();
if (!to->equals(e1->type))
{
@@ -8952,7 +9020,9 @@ Expression *SliceExp::syntaxCopy()
if (this->upr)
upr = this->upr->syntaxCopy();
return new SliceExp(loc, e1->syntaxCopy(), lwr, upr);
SliceExp *se = new SliceExp(loc, e1->syntaxCopy(), lwr, upr);
se->lengthVar = this->lengthVar; // bug7871
return se;
}
Expression *SliceExp::semantic(Scope *sc)
@@ -9297,7 +9367,9 @@ ArrayExp::ArrayExp(Loc loc, Expression *e1, Expressions *args)
Expression *ArrayExp::syntaxCopy()
{
return new ArrayExp(loc, e1->syntaxCopy(), arraySyntaxCopy(arguments));
ArrayExp *ae = new ArrayExp(loc, e1->syntaxCopy(), arraySyntaxCopy(arguments));
ae->lengthVar = this->lengthVar; // bug7871
return ae;
}
Expression *ArrayExp::semantic(Scope *sc)
@@ -9464,6 +9536,13 @@ IndexExp::IndexExp(Loc loc, Expression *e1, Expression *e2)
modifiable = 0; // assume it is an rvalue
}
Expression *IndexExp::syntaxCopy()
{
IndexExp *ie = new IndexExp(loc, e1->syntaxCopy(), e2->syntaxCopy());
ie->lengthVar = this->lengthVar; // bug7871
return ie;
}
Expression *IndexExp::semantic(Scope *sc)
{ Expression *e;
Type *t1;