Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/stable' into merge_stable_convert
Browse files Browse the repository at this point in the history
Conflicts:
	src/opover.c
  • Loading branch information
MartinNowak committed Sep 2, 2015
2 parents 9d9cb89 + e6e75a6 commit 38d89dc
Show file tree
Hide file tree
Showing 59 changed files with 2,050 additions and 1,016 deletions.
5 changes: 5 additions & 0 deletions src/aggregate.h
Expand Up @@ -174,6 +174,11 @@ class StructDeclaration : public AggregateDeclaration
Type *arg1type;
Type *arg2type;

// Even if struct is defined as non-root symbol, some built-in operations
// (e.g. TypeidExp, NewExp, ArrayLiteralExp, etc) request its TypeInfo.
// For those, today TypeInfo_Struct is generated in COMDAT.
bool requestTypeInfo;

StructDeclaration(Loc loc, Identifier *id);
Dsymbol *syntaxCopy(Dsymbol *s);
void semantic(Scope *sc);
Expand Down
7 changes: 6 additions & 1 deletion src/aliasthis.c
Expand Up @@ -22,12 +22,14 @@
#include "declaration.h"
#include "tokens.h"

Expression *resolveAliasThis(Scope *sc, Expression *e)
Expression *resolveAliasThis(Scope *sc, Expression *e, bool gag)
{
AggregateDeclaration *ad = isAggregate(e->type);

if (ad && ad->aliasthis)
{
unsigned olderrors = gag ? global.startGagging() : 0;

Loc loc = e->loc;
Type *tthis = (e->op == TOKtype ? e->type : NULL);
e = new DotIdExp(loc, e, ad->aliasthis->ident);
Expand Down Expand Up @@ -64,6 +66,9 @@ Expression *resolveAliasThis(Scope *sc, Expression *e)
e = e->semantic(sc);
}
e = resolveProperties(sc, e);

if (gag && global.endGagging(olderrors))
e = NULL;
}

return e;
Expand Down
8 changes: 2 additions & 6 deletions src/arrayop.c
Expand Up @@ -447,10 +447,8 @@ Expression *buildArrayLoop(Expression *e, Parameters *fparams)
Parameter *param = new Parameter(STCconst, e->type, id, NULL);
fparams->shift(param);
Expression *ie = new IdentifierExp(Loc(), id);
Expressions *arguments = new Expressions();
Expression *index = new IdentifierExp(Loc(), Id::p);
arguments->push(index);
result = new ArrayExp(Loc(), ie, arguments);
result = new ArrayExp(Loc(), ie, index);
}

void visit(SliceExp *e)
Expand All @@ -459,10 +457,8 @@ Expression *buildArrayLoop(Expression *e, Parameters *fparams)
Parameter *param = new Parameter(STCconst, e->type, id, NULL);
fparams->shift(param);
Expression *ie = new IdentifierExp(Loc(), id);
Expressions *arguments = new Expressions();
Expression *index = new IdentifierExp(Loc(), Id::p);
arguments->push(index);
result = new ArrayExp(Loc(), ie, arguments);
result = new ArrayExp(Loc(), ie, index);
}

void visit(AssignExp *e)
Expand Down
2 changes: 1 addition & 1 deletion src/cppmangle.c
Expand Up @@ -1437,7 +1437,7 @@ class VisualCPPMangler : public Visitor

t->accept(this);

if ((t->ty == Tpointer || t->ty == Treference) && global.params.is64bit)
if ((t->ty == Tpointer || t->ty == Treference || t->ty == Tclass) && global.params.is64bit)
{
buf.writeByte('E');
}
Expand Down
108 changes: 56 additions & 52 deletions src/declaration.c
Expand Up @@ -384,6 +384,11 @@ void AliasDeclaration::semantic(Scope *sc)
* try to alias y to 3.
*/
s = type->toDsymbol(sc);
if (errors != global.errors)
{
s = NULL;
type = Type::terror;
}
if (s && s == this)
{
error("cannot resolve");
Expand Down Expand Up @@ -1384,17 +1389,26 @@ void VarDeclaration::semantic(Scope *sc)
init = ei;
}

Expression *exp = ei->exp;
Expression *e1 = new VarExp(loc, this);
if (isBlit)
ei->exp = new BlitExp(loc, e1, ei->exp);
exp = new BlitExp(loc, e1, exp);
else
ei->exp = new ConstructExp(loc, e1, ei->exp);
exp = new ConstructExp(loc, e1, exp);
canassign++;
ei->exp = ei->exp->semantic(sc);
exp = exp->semantic(sc);
canassign--;
ei->exp->optimize(WANTvalue);
exp = exp->optimize(WANTvalue);

if (exp->op == TOKerror)
{
init = new ErrorInitializer();
ei = NULL;
}
else
ei->exp = exp;

if (isScope())
if (ei && isScope())
{
Expression *ex = ei->exp;
while (ex->op == TOKcomma)
Expand Down Expand Up @@ -1789,16 +1803,46 @@ bool lambdaCheckForNestedRef(Expression *e, Scope *sc);
bool VarDeclaration::checkNestedReference(Scope *sc, Loc loc)
{
//printf("VarDeclaration::checkNestedReference() %s\n", toChars());
if (parent && parent != sc->parent &&
!isDataseg() && !(storage_class & STCmanifest) &&
sc->intypeof != 1 && !(sc->flags & SCOPEctfe))
if (sc->intypeof == 1 || (sc->flags & SCOPEctfe))
return false;
if (!parent || parent == sc->parent)
return false;
if (isDataseg() || (storage_class & STCmanifest))
return false;

// The current function
FuncDeclaration *fdthis = sc->parent->isFuncDeclaration();
if (!fdthis)
return false; // out of function scope

Dsymbol *p = toParent2();

// Function literals from fdthis to p must be delegates
// TODO: here is similar to checkFrameAccess.
for (Dsymbol *s = fdthis; s && s != p; s = s->toParent2())
{
// function literal has reference to enclosing scope is delegate
if (FuncLiteralDeclaration *fld = s->isFuncLiteralDeclaration())
fld->tok = TOKdelegate;

if (FuncDeclaration *fd = s->isFuncDeclaration())
{
if (!fd->isThis() && !fd->isNested())
break;
}
if (AggregateDeclaration *ad2 = s->isAggregateDeclaration())
{
if (ad2->storage_class & STCstatic)
break;
}
}

if (1)
{
// The function that this variable is in
FuncDeclaration *fdv = toParent()->isFuncDeclaration();
// The current function
FuncDeclaration *fdthis = sc->parent->isFuncDeclaration();
FuncDeclaration *fdv = p->isFuncDeclaration();

if (fdv && fdthis && fdv != fdthis)
if (fdv && fdv != fdthis)
{
// Add fdthis to nestedrefs[] if not already there
for (size_t i = 0; 1; i++)
Expand Down Expand Up @@ -1826,46 +1870,6 @@ bool VarDeclaration::checkNestedReference(Scope *sc, Loc loc)
int lv = fdthis->getLevel(loc, sc, fdv);
if (lv == -2) // error
return true;
if (lv > 0 &&
fdv->isPureBypassingInference() >= PUREweak &&
fdthis->isPureBypassingInference() == PUREfwdref &&
fdthis->isInstantiated())
{
/* Bugzilla 9148 and 14039:
* void foo() pure {
* int x;
* void bar()() { // default is impure
* x = 1; // access to enclosing pure function context
* // means that bar should have weak purity.
* }
* }
*/
fdthis->flags &= ~FUNCFLAGpurityInprocess;
if (fdthis->type->ty == Tfunction)
{
TypeFunction *tf = (TypeFunction *)fdthis->type;
if (tf->deco)
{
tf = (TypeFunction *)tf->copy();
tf->purity = PUREfwdref;
tf->deco = NULL;
tf->deco = tf->merge()->deco;
}
else
tf->purity = PUREfwdref;
fdthis->type = tf;
}
}
}

// Function literals from fdthis to fdv must be delegates
for (Dsymbol *s = fdthis; s && s != fdv; s = s->toParent2())
{
// function literal has reference to enclosing scope is delegate
if (FuncLiteralDeclaration *fld = s->isFuncLiteralDeclaration())
{
fld->tok = TOKdelegate;
}
}

// Add this to fdv->closureVars[] if not already there
Expand Down
73 changes: 2 additions & 71 deletions src/dsymbol.c
Expand Up @@ -449,50 +449,12 @@ Dsymbol *Dsymbol::search_correct(Identifier *ident)
return (Dsymbol *)speller(ident->toChars(), &symbol_search_fp, (void *)this, idchars);
}

/*************************************
* Take an index in a TypeTuple.
*/
Dsymbol *Dsymbol::takeTypeTupleIndex(Loc loc, Scope *sc, Dsymbol *s, RootObject *id, Expression *indexExpr)
{
TupleDeclaration *td = s->isTupleDeclaration();
if (!td)
{
error(loc, "expected TypeTuple when indexing ('[%s]'), got '%s'.",
id->toChars(), s->toChars());
return NULL;
}
sc = sc->startCTFE();
indexExpr = indexExpr->semantic(sc);
sc = sc->endCTFE();

indexExpr = indexExpr->ctfeInterpret();
const uinteger_t d = indexExpr->toUInteger();

if (d >= td->objects->dim)
{
error(loc, "tuple index %llu exceeds length %u", d, td->objects->dim);
return NULL;
}
RootObject *o = (*td->objects)[(size_t)d];
if (o->dyncast() == DYNCAST_TYPE)
{
Type *t = (Type *)o;
return t->toDsymbol(sc)->toAlias();
}
else
{
assert(o->dyncast() == DYNCAST_DSYMBOL);
return (Dsymbol *)o;
}
}

/***************************************
* Search for identifier id as a member of 'this'.
* id may be a template instance.
* Returns:
* symbol found, NULL if not
*/

Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, RootObject *id)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars());
Expand All @@ -514,39 +476,6 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, RootObject *id)
sm = s->search(loc, (Identifier *)id);
break;

case DYNCAST_TYPE:
{
Type *index = (Type *)id;
Expression *expr = NULL;
Type *t = NULL;
Dsymbol *sym = NULL;

index->resolve(loc, sc, &expr, &t, &sym);
if (expr)
{
sm = takeTypeTupleIndex(loc, sc, s, id, expr);
}
else if (t)
{
index->error(loc, "expected an expression as index, got a type (%s)", t->toChars());
return NULL;
}
else
{
index->error(loc, "index is not an expression");
return NULL;
}
break;
}

case DYNCAST_EXPRESSION:
sm = takeTypeTupleIndex(loc, sc, s, id, (Expression *)id);
if (!sm)
{
return NULL;
}
break;

case DYNCAST_DSYMBOL:
{
// It's a template instance
Expand Down Expand Up @@ -579,6 +508,8 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, RootObject *id)
break;
}

case DYNCAST_TYPE:
case DYNCAST_EXPRESSION:
default:
assert(0);
}
Expand Down
3 changes: 0 additions & 3 deletions src/dsymbol.h
Expand Up @@ -274,9 +274,6 @@ class Dsymbol : public RootObject
virtual AttribDeclaration *isAttribDeclaration() { return NULL; }
virtual OverloadSet *isOverloadSet() { return NULL; }
virtual void accept(Visitor *v) { v->visit(this); }

private:
Dsymbol *takeTypeTupleIndex(Loc loc, Scope *sc, Dsymbol *s, RootObject *id, Expression *indexExpr);
};

// Dsymbol that generates a scope
Expand Down
4 changes: 2 additions & 2 deletions src/e2ir.c
Expand Up @@ -2504,7 +2504,7 @@ elem *toElem(Expression *e, IRState *irs)
Type *ta = are->e1->type->toBasetype();

// which we do if the 'next' types match
if (ae->ismemset)
if (ae->ismemset & 1)
{
// Do a memset for array[]=v
//printf("Lpair %s\n", ae->toChars());
Expand Down Expand Up @@ -2694,7 +2694,7 @@ elem *toElem(Expression *e, IRState *irs)

/* Look for reference initializations
*/
if (ae->op == TOKconstruct && ae->e1->op == TOKvar)
if (ae->op == TOKconstruct && ae->e1->op == TOKvar && !(ae->ismemset & 2))
{
VarExp *ve = (VarExp *)ae->e1;
Declaration *s = ve->var;
Expand Down

0 comments on commit 38d89dc

Please sign in to comment.