From afab6938fc5ca66709c6ba127c5d34bad0d14e93 Mon Sep 17 00:00:00 2001 From: Daniel Murphy Date: Sun, 10 Mar 2013 18:24:31 +1100 Subject: [PATCH] TypeQualified::idents are not always Identifiers, so stop pretending they are --- src/dsymbol.c | 6 +++--- src/dsymbol.h | 2 +- src/json.c | 2 +- src/mtype.c | 37 ++++++++++++++++++++++--------------- src/mtype.h | 3 ++- src/parse.c | 4 ++-- src/template.c | 14 +++++++------- 7 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/dsymbol.c b/src/dsymbol.c index 8c2751261f28..711d67b5ecee 100644 --- a/src/dsymbol.c +++ b/src/dsymbol.c @@ -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(); @@ -429,7 +429,7 @@ 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: @@ -437,7 +437,7 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, Identifier *id) //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) { diff --git a/src/dsymbol.h b/src/dsymbol.h index 9afcd6c2d2ea..d0402e7832f0 100644 --- a/src/dsymbol.h +++ b/src/dsymbol.h @@ -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); diff --git a/src/json.c b/src/json.c index 3bac7f017e36..373215d359e2 100644 --- a/src/json.c +++ b/src/json.c @@ -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()); } diff --git a/src/mtype.c b/src/mtype.c index f9eb6e58712b..4b013ebcdf58 100644 --- a/src/mtype.c +++ b/src/mtype.c @@ -6272,13 +6272,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; } @@ -6290,10 +6290,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('.'); @@ -6341,7 +6346,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()); @@ -6364,7 +6369,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; } @@ -6373,11 +6379,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 @@ -6402,7 +6408,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()); @@ -6614,7 +6621,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"); @@ -6686,10 +6693,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); @@ -6967,11 +6974,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: { @@ -7095,11 +7102,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: { diff --git a/src/mtype.h b/src/mtype.h index dbcf744ba41a..a8e215c4a425 100644 --- a/src/mtype.h +++ b/src/mtype.h @@ -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); diff --git a/src/parse.c b/src/parse.c index 82fa3dd02f43..cbc101f0ce9d 100644 --- a/src/parse.c +++ b/src/parse.c @@ -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 @@ -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); diff --git a/src/template.c b/src/template.c index 261b665fb3df..af747bf891b6 100644 --- a/src/template.c +++ b/src/template.c @@ -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; @@ -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) @@ -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) @@ -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() : "");