From 3ca7686e77546059aaf97ea6b8bc83d0cf86695f Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Wed, 30 Sep 2020 22:19:10 -0700 Subject: [PATCH] refactor Type.resolve() --- src/dmd/dsymbolsem.d | 2 +- src/dmd/dtemplate.d | 16 ++--- src/dmd/expressionsem.d | 4 +- src/dmd/mtype.d | 12 ++-- src/dmd/traits.d | 2 +- src/dmd/typesem.d | 128 ++++++++++++++++++++-------------------- 6 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/dmd/dsymbolsem.d b/src/dmd/dsymbolsem.d index e02a9a61c8..cd97d8b4b2 100644 --- a/src/dmd/dsymbolsem.d +++ b/src/dmd/dsymbolsem.d @@ -6623,7 +6623,7 @@ void aliasSemantic(AliasDeclaration ds, Scope* sc) sc2.stc |= ds.storage_class & (STC.ref_ | STC.nothrow_ | STC.nogc | STC.pure_ | STC.shared_ | STC.disable); } ds.type = ds.type.addSTC(ds.storage_class); - ds.type.resolve(ds.loc, sc2, &e, &t, &s); + ds.type.resolve(ds.loc, sc2, e, t, s); if (sc2 != sc) sc2.pop(); diff --git a/src/dmd/dtemplate.d b/src/dmd/dtemplate.d index 0a01d95646..ae882445d9 100644 --- a/src/dmd/dtemplate.d +++ b/src/dmd/dtemplate.d @@ -1983,11 +1983,11 @@ extern (C++) final class TemplateDeclaration : ScopeDsymbol * instantiation scope 'sc' and the one * belonging to the template itself. */ sco = sc; - taa.index.resolve(instLoc, sco, &e, &t, &s); + taa.index.resolve(instLoc, sco, e, t, s); if (!e) { sco = paramscope; - taa.index.resolve(instLoc, sco, &e, &t, &s); + taa.index.resolve(instLoc, sco, e, t, s); } global.endGagging(errors); @@ -3847,7 +3847,7 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* param Expression e; Type tx; Dsymbol s; - taa.index.resolve(Loc.initial, sc, &e, &tx, &s); + taa.index.resolve(Loc.initial, sc, e, tx, s); edim = s ? getValue(s) : getValue(e); } } @@ -4058,7 +4058,7 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* param Type tx; Expression e; Dsymbol s; - tid.resolve(tp.loc, sc, &e, &tx, &s); + tid.resolve(tp.loc, sc, e, tx, s); Pool!TypeIdentifier.dispose(tid); if (tx) { @@ -4242,7 +4242,7 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* param L1: if (j == IDX_NOTFOUND) { - t2.resolve((cast(TypeIdentifier)t2).loc, sc, &e2, &t2, &s2); + t2.resolve((cast(TypeIdentifier)t2).loc, sc, e2, t2, s2); if (e2) goto Le; goto Lnomatch; @@ -4261,7 +4261,7 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* param j = templateParameterLookup(t2, parameters); if (j == IDX_NOTFOUND) { - t2.resolve((cast(TypeIdentifier)t2).loc, sc, &e2, &t2, &s2); + t2.resolve((cast(TypeIdentifier)t2).loc, sc, e2, t2, s2); if (s2) goto Ls; goto Lnomatch; @@ -6581,7 +6581,7 @@ extern (C++) class TemplateInstance : ScopeDsymbol //printf("type %s\n", ta.toChars()); // It might really be an Expression or an Alias - ta.resolve(loc, sc, &ea, &ta, &sa, (flags & 1) != 0); + ta.resolve(loc, sc, ea, ta, sa, (flags & 1) != 0); if (ea) goto Lexpr; if (sa) @@ -7642,7 +7642,7 @@ extern (C++) final class TemplateMixin : TemplateInstance Expression e; Type t; Dsymbol s; - tqual.resolve(loc, sc, &e, &t, &s); + tqual.resolve(loc, sc, e, t, s); if (!s) { error("is not defined"); diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index 50347af797..baac5d44fe 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -3215,7 +3215,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor Type t; Dsymbol s; - dmd.typesem.resolve(exp.type, exp.loc, sc, &e, &t, &s, true); + dmd.typesem.resolve(exp.type, exp.loc, sc, e, t, s, true); if (e) { // `(Type)` is actually `(var)` so if `(var)` is a member requiring `this` @@ -5275,7 +5275,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor if (ta) { - dmd.typesem.resolve(ta, exp.loc, sc, &ea, &ta, &sa, true); + dmd.typesem.resolve(ta, exp.loc, sc, ea, ta, sa, true); } if (ea) diff --git a/src/dmd/mtype.d b/src/dmd/mtype.d index 305eae9552..4fb1aef43a 100644 --- a/src/dmd/mtype.d +++ b/src/dmd/mtype.d @@ -5390,7 +5390,7 @@ extern (C++) final class TypeTraits : Type Type t; Expression e; Dsymbol s; - resolve(this, loc, sc, &e, &t, &s); + resolve(this, loc, sc, e, t, s); if (t && t.ty != Terror) s = t.toDsymbol(sc); else if (e) @@ -5442,7 +5442,7 @@ extern (C++) final class TypeMixin : Type Type t; Expression e; Dsymbol s; - resolve(this, loc, sc, &e, &t, &s); + resolve(this, loc, sc, e, t, s); if (t) s = t.toDsymbol(sc); else if (e) @@ -5578,7 +5578,7 @@ extern (C++) final class TypeIdentifier : TypeQualified Type t; Expression e; Dsymbol s; - resolve(this, loc, sc, &e, &t, &s); + resolve(this, loc, sc, e, t, s); if (t && t.ty != Tident) s = t.toDsymbol(sc); if (e) @@ -5626,7 +5626,7 @@ extern (C++) final class TypeInstance : TypeQualified Expression e; Dsymbol s; //printf("TypeInstance::semantic(%s)\n", toChars()); - resolve(this, loc, sc, &e, &t, &s); + resolve(this, loc, sc, e, t, s); if (t && t.ty != Tinstance) s = t.toDsymbol(sc); return s; @@ -5671,7 +5671,7 @@ extern (C++) final class TypeTypeof : TypeQualified Expression e; Type t; Dsymbol s; - resolve(this, loc, sc, &e, &t, &s); + resolve(this, loc, sc, e, t, s); return s; } @@ -5716,7 +5716,7 @@ extern (C++) final class TypeReturn : TypeQualified Expression e; Type t; Dsymbol s; - resolve(this, loc, sc, &e, &t, &s); + resolve(this, loc, sc, e, t, s); return s; } diff --git a/src/dmd/traits.d b/src/dmd/traits.d index c7be2d673b..db16fc3fae 100644 --- a/src/dmd/traits.d +++ b/src/dmd/traits.d @@ -1729,7 +1729,7 @@ Expression semanticTraits(TraitsExp e, Scope* sc) if (!ex && t) { Dsymbol s; - t.resolve(e.loc, sc2, &ex, &t, &s); + t.resolve(e.loc, sc2, ex, t, s); if (t) { t.typeSemantic(e.loc, sc2); diff --git a/src/dmd/typesem.d b/src/dmd/typesem.d index c00d9c69ac..085573759e 100644 --- a/src/dmd/typesem.d +++ b/src/dmd/typesem.d @@ -135,7 +135,7 @@ private void resolveTupleIndex(const ref Loc loc, Scope* sc, Dsymbol s, out Expr // Convert oindex to Expression, then try to resolve to constant. if (tindex) - tindex.resolve(loc, sc, &eindex, &tindex, &sindex); + tindex.resolve(loc, sc, eindex, tindex, sindex); if (sindex) eindex = symbolToExp(sindex, loc, sc, false); if (!eindex) @@ -702,7 +702,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) Type t; Expression e; Dsymbol s; - mtype.next.resolve(loc, sc, &e, &t, &s); + mtype.next.resolve(loc, sc, e, t, s); if (auto tup = s ? s.isTupleDeclaration() : null) { @@ -895,7 +895,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) Expression e; Type t; Dsymbol s; - mtype.index.resolve(loc, sc, &e, &t, &s); + mtype.index.resolve(loc, sc, e, t, s); //https://issues.dlang.org/show_bug.cgi?id=15478 if (s) @@ -1646,7 +1646,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) Expression e; Dsymbol s; //printf("TypeIdentifier::semantic(%s)\n", mtype.toChars()); - mtype.resolve(loc, sc, &e, &t, &s); + mtype.resolve(loc, sc, e, t, s); if (t) { //printf("\tit's a type %d, %s, %s\n", t.ty, t.toChars(), t.deco); @@ -1701,7 +1701,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) //printf("TypeInstance::semantic(%p, %s)\n", this, toChars()); { const errors = global.errors; - mtype.resolve(loc, sc, &e, &t, &s); + mtype.resolve(loc, sc, e, t, s); // if we had an error evaluating the symbol, suppress further errors if (!t && errors != global.errors) return error(); @@ -1728,7 +1728,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) Expression e; Type t; Dsymbol s; - mtype.resolve(loc, sc, &e, &t, &s); + mtype.resolve(loc, sc, e, t, s); if (s && (t = s.getType()) !is null) t = t.addMod(mtype.mod); if (!t) @@ -1852,7 +1852,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) Expression e; Type t; Dsymbol s; - mtype.resolve(loc, sc, &e, &t, &s); + mtype.resolve(loc, sc, e, t, s); if (s && (t = s.getType()) !is null) t = t.addMod(mtype.mod); if (!t) @@ -2584,27 +2584,27 @@ private void resolveExp(Expression exp, out Type t, out Expression e, out Dsymbo * ps = is set if t is a symbol * intypeid = true if in type id */ -void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Dsymbol* ps, bool intypeid = false) +void resolve(Type mt, const ref Loc loc, Scope* sc, out Expression pe, out Type pt, out Dsymbol ps, bool intypeid = false) { void returnExp(Expression e) { - *pt = null; - *pe = e; - *ps = null; + pe = e; + pt = null; + ps = null; } void returnType(Type t) { - *pt = t; - *pe = null; - *ps = null; + pe = null; + pt = t; + ps = null; } void returnSymbol(Dsymbol s) { - *pt = null; - *pe = null; - *ps = s; + pe = null; + pt = null; + ps = s; } void returnError() @@ -2624,17 +2624,17 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds { //printf("TypeSArray::resolve() %s\n", mt.toChars()); mt.next.resolve(loc, sc, pe, pt, ps, intypeid); - //printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt); - if (*pe) + //printf("s = %p, e = %p, t = %p\n", ps, pe, pt); + if (pe) { // It's really an index expression - if (Dsymbol s = getDsymbol(*pe)) - *pe = new DsymbolExp(loc, s); - returnExp(new ArrayExp(loc, *pe, mt.dim)); + if (Dsymbol s = getDsymbol(pe)) + pe = new DsymbolExp(loc, s); + returnExp(new ArrayExp(loc, pe, mt.dim)); } - else if (*ps) + else if (ps) { - Dsymbol s = *ps; + Dsymbol s = ps; if (auto tup = s.isTupleDeclaration()) { mt.dim = semanticLength(sc, tup, mt.dim); @@ -2681,8 +2681,8 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds } else { - if ((*pt).ty != Terror) - mt.next = *pt; // prevent re-running semantic() on 'next' + if (pt.ty != Terror) + mt.next = pt; // prevent re-running semantic() on 'next' visitType(mt); } @@ -2692,27 +2692,27 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds { //printf("TypeDArray::resolve() %s\n", mt.toChars()); mt.next.resolve(loc, sc, pe, pt, ps, intypeid); - //printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt); - if (*pe) + //printf("s = %p, e = %p, t = %p\n", ps, pe, pt); + if (pe) { // It's really a slice expression - if (Dsymbol s = getDsymbol(*pe)) - *pe = new DsymbolExp(loc, s); - returnExp(new ArrayExp(loc, *pe)); + if (Dsymbol s = getDsymbol(pe)) + pe = new DsymbolExp(loc, s); + returnExp(new ArrayExp(loc, pe)); } - else if (*ps) + else if (ps) { - if (auto tup = (*ps).isTupleDeclaration()) + if (auto tup = ps.isTupleDeclaration()) { - // keep *ps + // keep ps } else visitType(mt); } else { - if ((*pt).ty != Terror) - mt.next = *pt; // prevent re-running semantic() on 'next' + if (pt.ty != Terror) + mt.next = pt; // prevent re-running semantic() on 'next' visitType(mt); } } @@ -2727,7 +2727,7 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds Expression e; Type t; Dsymbol s; - mt.index.resolve(loc, sc, &e, &t, &s, intypeid); + mt.index.resolve(loc, sc, e, t, s, intypeid); if (e) { // It was an expression - @@ -2748,8 +2748,8 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds * Takes an array of Identifiers and figures out if * it represents a Type or an Expression. * Output: - * if expression, *pe is set - * if type, *pt is set + * if expression, pe is set + * if type, pt is set */ void visitIdentifier(TypeIdentifier mt) { @@ -2839,9 +2839,9 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds } } - mt.resolveHelper(loc, sc, s, scopesym, *pe, *pt, *ps, intypeid); - if (*pt) - (*pt) = (*pt).addMod(mt.mod); + mt.resolveHelper(loc, sc, s, scopesym, pe, pt, ps, intypeid); + if (pt) + pt = pt.addMod(mt.mod); } void visitInstance(TypeInstance mt) @@ -2853,10 +2853,10 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds if (!global.gag && mt.tempinst.errors) return returnError(); - mt.resolveHelper(loc, sc, mt.tempinst, null, *pe, *pt, *ps, intypeid); - if (*pt) - *pt = (*pt).addMod(mt.mod); - //if (*pt) printf("*pt = %d '%s'\n", (*pt).ty, (*pt).toChars()); + mt.resolveHelper(loc, sc, mt.tempinst, null, pe, pt, ps, intypeid); + if (pt) + pt = pt.addMod(mt.mod); + //if (pt) printf("pt = %d '%s'\n", pt.ty, pt.toChars()); } void visitTypeof(TypeTypeof mt) @@ -2956,15 +2956,15 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds else { if (Dsymbol s = t.toDsymbol(sc)) - mt.resolveHelper(loc, sc, s, null, *pe, *pt, *ps, intypeid); + mt.resolveHelper(loc, sc, s, null, pe, pt, ps, intypeid); else { auto e = typeToExpressionHelper(mt, new TypeExp(loc, t)); e = e.expressionSemantic(sc); - resolveExp(e, *pt, *pe, *ps); + resolveExp(e, pt, pe, ps); } - if (*pt) - (*pt) = (*pt).addMod(mt.mod); + if (pt) + pt = pt.addMod(mt.mod); } mt.inuse--; } @@ -2996,31 +2996,31 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds else { if (Dsymbol s = t.toDsymbol(sc)) - mt.resolveHelper(loc, sc, s, null, *pe, *pt, *ps, intypeid); + mt.resolveHelper(loc, sc, s, null, pe, pt, ps, intypeid); else { auto e = typeToExpressionHelper(mt, new TypeExp(loc, t)); e = e.expressionSemantic(sc); - resolveExp(e, *pt, *pe, *ps); + resolveExp(e, pt, pe, ps); } - if (*pt) - (*pt) = (*pt).addMod(mt.mod); + if (pt) + pt = pt.addMod(mt.mod); } } void visitSlice(TypeSlice mt) { mt.next.resolve(loc, sc, pe, pt, ps, intypeid); - if (*pe) + if (pe) { // It's really a slice expression - if (Dsymbol s = getDsymbol(*pe)) - *pe = new DsymbolExp(loc, s); - return returnExp(new ArrayExp(loc, *pe, new IntervalExp(loc, mt.lwr, mt.upr))); + if (Dsymbol s = getDsymbol(pe)) + pe = new DsymbolExp(loc, s); + return returnExp(new ArrayExp(loc, pe, new IntervalExp(loc, mt.lwr, mt.upr))); } - else if (*ps) + else if (ps) { - Dsymbol s = *ps; + Dsymbol s = ps; TupleDeclaration td = s.isTupleDeclaration(); if (td) { @@ -3066,8 +3066,8 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds } else { - if ((*pt).ty != Terror) - mt.next = *pt; // prevent re-running semantic() on 'next' + if (pt.ty != Terror) + mt.next = pt; // prevent re-running semantic() on 'next' visitType(mt); } } @@ -3079,8 +3079,8 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, Expression* pe, Type* pt, Ds if (auto t = o.isType()) { resolve(t, loc, sc, pe, pt, ps, intypeid); - if (*pt) - (*pt) = (*pt).addMod(mt.mod); + if (pt) + pt = pt.addMod(mt.mod); } else if (auto e = o.isExpression()) {