Skip to content

Commit

Permalink
Merge pull request #1951 from yebblies/identvsti
Browse files Browse the repository at this point in the history
TypeQualified::idents are not always Identifiers, so stop pretending they are
  • Loading branch information
MartinNowak committed May 4, 2013
2 parents 1893e16 + afab693 commit 50b0a19
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/dsymbol.c
Expand Up @@ -420,7 +420,7 @@ Dsymbol *Dsymbol::search_correct(Identifier *ident)
* symbol found, NULL if not
*/

Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Object *id)
{
//printf("Dsymbol::searchX(this=%p,%s, ident='%s')\n", this, toChars(), ident->toChars());
Dsymbol *s = toAlias();
Expand All @@ -429,15 +429,15 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id)
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
sm = s->search(loc, id, 0);
sm = s->search(loc, (Identifier *)id, 0);
break;

case DYNCAST_DSYMBOL:
{ // It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol *st = (Dsymbol *)id;
TemplateInstance *ti = st->isTemplateInstance();
id = ti->name;
Identifier *id = ti->name;
sm = s->search(loc, id, 0);
if (!sm)
{
Expand Down
2 changes: 1 addition & 1 deletion src/dsymbol.h
Expand Up @@ -164,7 +164,7 @@ struct Dsymbol : Object
virtual void inlineScan();
virtual Dsymbol *search(Loc loc, Identifier *ident, int flags);
Dsymbol *search_correct(Identifier *id);
Dsymbol *searchX(Loc loc, Scope *sc, Identifier *id);
Dsymbol *searchX(Loc loc, Scope *sc, Object *id);
virtual int overloadInsert(Dsymbol *s);
virtual void toHBuffer(OutBuffer *buf, HdrGenState *hgs);
virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
Expand Down
2 changes: 1 addition & 1 deletion src/json.c
Expand Up @@ -544,7 +544,7 @@ void TypeQualified::toJson(JsonOut *json) // ident.ident.ident.etc
json->arrayStart();

for (size_t i = 0; i < idents.dim; i++)
{ Identifier *ident = idents[i];
{ Object *ident = idents[i];
json->item(ident->toChars());
}

Expand Down
37 changes: 22 additions & 15 deletions src/mtype.c
Expand Up @@ -6279,13 +6279,13 @@ void TypeQualified::syntaxCopyHelper(TypeQualified *t)
idents.setDim(t->idents.dim);
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = t->idents[i];
Object *id = t->idents[i];
if (id->dyncast() == DYNCAST_DSYMBOL)
{
TemplateInstance *ti = (TemplateInstance *)id;

ti = (TemplateInstance *)ti->syntaxCopy(NULL);
id = (Identifier *)ti;
id = ti;
}
idents[i] = id;
}
Expand All @@ -6297,10 +6297,15 @@ void TypeQualified::addIdent(Identifier *ident)
idents.push(ident);
}

void TypeQualified::addInst(TemplateInstance *inst)
{
idents.push(inst);
}

void TypeQualified::toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs)
{
for (size_t i = 0; i < idents.dim; i++)
{ Identifier *id = idents[i];
{ Object *id = idents[i];

buf->writeByte('.');

Expand Down Expand Up @@ -6348,7 +6353,7 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
//printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = idents[i];
Object *id = idents[i];
Dsymbol *sm = s->searchX(loc, sc, id);
//printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind());
//printf("\tgetType = '%s'\n", s->getType()->toChars());
Expand All @@ -6371,7 +6376,8 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
{
sm = t->toDsymbol(sc);
if (sm)
{ sm = sm->search(loc, id, 0);
{ assert(id->dyncast() == DYNCAST_IDENTIFIER);
sm = sm->search(loc, (Identifier *)id, 0);
if (sm)
goto L2;
}
Expand All @@ -6380,11 +6386,11 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
e = e->semantic(sc);
for (; i < idents.dim; i++)
{
id = idents[i];
Object *id = idents[i];
//printf("e: '%s', id: '%s', type = %s\n", e->toChars(), id->toChars(), e->type->toChars());
if (id->dyncast() == DYNCAST_IDENTIFIER)
{
DotIdExp *die = new DotIdExp(e->loc, e, id);
DotIdExp *die = new DotIdExp(e->loc, e, (Identifier *)id);
e = die->semanticY(sc, 0);
}
else
Expand All @@ -6409,7 +6415,8 @@ void TypeQualified::resolveHelper(Loc loc, Scope *sc,
}
else
{
sm = s->search_correct(id);
assert(id->dyncast() == DYNCAST_IDENTIFIER);
sm = s->search_correct((Identifier *)id);
if (sm)
error(loc, "identifier '%s' of '%s' is not defined, did you mean '%s %s'?",
id->toChars(), toChars(), sm->kind(), sm->toChars());
Expand Down Expand Up @@ -6621,7 +6628,7 @@ Dsymbol *TypeIdentifier::toDsymbol(Scope *sc)
{
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = idents[i];
Object *id = idents[i];
s = s->searchX(loc, sc, id);
if (!s) // failed to find a symbol
{ //printf("\tdidn't find a symbol\n");
Expand Down Expand Up @@ -6693,10 +6700,10 @@ Expression *TypeIdentifier::toExpression()
Expression *e = new IdentifierExp(loc, ident);
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = idents[i];
Object *id = idents[i];
if (id->dyncast() == DYNCAST_IDENTIFIER)
{
e = new DotIdExp(loc, e, id);
e = new DotIdExp(loc, e, (Identifier *)id);
}
else
{ assert(id->dyncast() == DYNCAST_DSYMBOL);
Expand Down Expand Up @@ -6974,11 +6981,11 @@ void TypeTypeof::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
Expression *e = new TypeExp(loc, t);
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = idents[i];
Object *id = idents[i];
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
e = new DotIdExp(loc, e, id);
e = new DotIdExp(loc, e, (Identifier *)id);
break;
case DYNCAST_DSYMBOL:
{
Expand Down Expand Up @@ -7102,11 +7109,11 @@ void TypeReturn::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol
Expression *e = new TypeExp(loc, t);
for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id = idents[i];
Object *id = idents[i];
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
e = new DotIdExp(loc, e, id);
e = new DotIdExp(loc, e, (Identifier *)id);
break;
case DYNCAST_DSYMBOL:
{
Expand Down
3 changes: 2 additions & 1 deletion src/mtype.h
Expand Up @@ -716,12 +716,13 @@ struct TypeDelegate : TypeNext
struct TypeQualified : Type
{
Loc loc;
Identifiers idents; // array of Identifier and TypeInstance,
Objects idents; // array of Identifier and TypeInstance,
// representing ident.ident!tiargs.ident. ... etc.

TypeQualified(TY ty, Loc loc);
void syntaxCopyHelper(TypeQualified *t);
void addIdent(Identifier *ident);
void addInst(TemplateInstance *inst);
void toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs);
void toJson(JsonOut *json);
d_uns64 size(Loc loc);
Expand Down
4 changes: 2 additions & 2 deletions src/parse.c
Expand Up @@ -2135,7 +2135,7 @@ Dsymbol *Parser::parseMixin()
if (!tqual)
tqual = new TypeInstance(loc, tempinst);
else
tqual->addIdent((Identifier *)tempinst);
tqual->addInst(tempinst);
tiargs = NULL;
}
else
Expand Down Expand Up @@ -2507,7 +2507,7 @@ Type *Parser::parseBasicType()
else
// ident!template_argument
tempinst->tiargs = parseTemplateArgument();
tid->addIdent((Identifier *)tempinst);
tid->addInst(tempinst);
}
else
tid->addIdent(id);
Expand Down
14 changes: 7 additions & 7 deletions src/template.c
Expand Up @@ -3202,8 +3202,8 @@ MATCH TypeIdentifier::deduceType(Scope *sc, Type *tparam, TemplateParameters *pa

for (size_t i = 0; i < idents.dim; i++)
{
Identifier *id1 = idents[i];
Identifier *id2 = tp->idents[i];
Object *id1 = idents[i];
Object *id2 = tp->idents[i];

if (!id1->equals(id2))
return MATCHnomatch;
Expand Down Expand Up @@ -3510,8 +3510,8 @@ MATCH TypeStruct::deduceType(Scope *sc, Type *tparam, TemplateParameters *parame
*/
TypeInstance *tpi = (TypeInstance *)tparam;
if (tpi->idents.dim)
{ Identifier *id = tpi->idents[tpi->idents.dim - 1];
if (id->dyncast() == DYNCAST_IDENTIFIER && sym->ident->equals(id))
{ Object *id = tpi->idents[tpi->idents.dim - 1];
if (id->dyncast() == DYNCAST_IDENTIFIER && sym->ident->equals((Identifier *)id))
{
Type *tparent = sym->parent->getType();
if (tparent)
Expand Down Expand Up @@ -3654,8 +3654,8 @@ MATCH TypeClass::deduceType(Scope *sc, Type *tparam, TemplateParameters *paramet
*/
TypeInstance *tpi = (TypeInstance *)tparam;
if (tpi->idents.dim)
{ Identifier *id = tpi->idents[tpi->idents.dim - 1];
if (id->dyncast() == DYNCAST_IDENTIFIER && sym->ident->equals(id))
{ Object *id = tpi->idents[tpi->idents.dim - 1];
if (id->dyncast() == DYNCAST_IDENTIFIER && sym->ident->equals((Identifier *)id))
{
Type *tparent = sym->parent->getType();
if (tparent)
Expand Down Expand Up @@ -6480,7 +6480,7 @@ char *TemplateInstance::toChars()
/* ======================== TemplateMixin ================================ */

TemplateMixin::TemplateMixin(Loc loc, Identifier *ident, TypeQualified *tqual, Objects *tiargs)
: TemplateInstance(loc, tqual->idents.dim ? tqual->idents[tqual->idents.dim - 1]
: TemplateInstance(loc, tqual->idents.dim ? (Identifier *)tqual->idents[tqual->idents.dim - 1]
: ((TypeIdentifier *)tqual)->ident)
{
//printf("TemplateMixin(ident = '%s')\n", ident ? ident->toChars() : "");
Expand Down

0 comments on commit 50b0a19

Please sign in to comment.