"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/dmd/dtemplate.d" between
dmd-2.094.1.tar.gz and dmd-2.094.2.tar.gz

About: DMD (Digital Mars D) is the D reference compiler. D is an object-oriented, imperative, multi-paradigm system programming language.

dtemplate.d  (dmd-2.094.1):dtemplate.d  (dmd-2.094.2)
skipping to change at line 70 skipping to change at line 70
import dmd.hdrgen; import dmd.hdrgen;
import dmd.id; import dmd.id;
import dmd.identifier; import dmd.identifier;
import dmd.impcnvtab; import dmd.impcnvtab;
import dmd.init; import dmd.init;
import dmd.initsem; import dmd.initsem;
import dmd.mtype; import dmd.mtype;
import dmd.opover; import dmd.opover;
import dmd.root.array; import dmd.root.array;
import dmd.root.outbuffer; import dmd.root.outbuffer;
import dmd.root.rmem;
import dmd.root.rootobject; import dmd.root.rootobject;
import dmd.semantic2; import dmd.semantic2;
import dmd.semantic3; import dmd.semantic3;
import dmd.tokens; import dmd.tokens;
import dmd.typesem; import dmd.typesem;
import dmd.visitor; import dmd.visitor;
import dmd.templateparamsem; import dmd.templateparamsem;
//debug = FindExistingInstance; // print debug stats of findExistingInstance //debug = FindExistingInstance; // print debug stats of findExistingInstance
skipping to change at line 1508 skipping to change at line 1507
if (tthis) if (tthis)
{ {
bool hasttp = false; bool hasttp = false;
// Match 'tthis' to any TemplateThisParameter's // Match 'tthis' to any TemplateThisParameter's
foreach (param; *parameters) foreach (param; *parameters)
{ {
if (auto ttp = param.isTemplateThisParameter()) if (auto ttp = param.isTemplateThisParameter())
{ {
hasttp = true; hasttp = true;
scope t = new TypeIdentifier(Loc.initial, ttp.ident);
Type t = new TypeIdentifier(Loc.initial, ttp.ident);
MATCH m = deduceType(tthis, paramscope, t, parameters, dedty pes); MATCH m = deduceType(tthis, paramscope, t, parameters, dedty pes);
if (m <= MATCH.nomatch) if (m <= MATCH.nomatch)
goto Lnomatch; goto Lnomatch;
if (m < match) if (m < match)
match = m; // pick worst match match = m; // pick worst match
} }
} }
// Match attributes of tthis against attributes of fd // Match attributes of tthis against attributes of fd
if (fd.type && !fd.isCtorDeclaration()) if (fd.type && !fd.isCtorDeclaration())
skipping to change at line 2833 skipping to change at line 2833
m.last = MATCH.nomatch; m.last = MATCH.nomatch;
return 1; return 1;
} }
//printf("td = %s\n", td.toChars()); //printf("td = %s\n", td.toChars());
auto f = td.onemember ? td.onemember.isFuncDeclaration() : null; auto f = td.onemember ? td.onemember.isFuncDeclaration() : null;
if (!f) if (!f)
{ {
if (!tiargs) if (!tiargs)
tiargs = new Objects(); tiargs = new Objects();
auto ti = Pool!TemplateInstance.make(loc, td, tiargs); auto ti = new TemplateInstance(loc, td, tiargs);
Objects dedtypes = Objects(td.parameters.dim); Objects dedtypes = Objects(td.parameters.dim);
assert(td.semanticRun != PASS.init); assert(td.semanticRun != PASS.init);
MATCH mta = td.matchWithInstance(sc, ti, &dedtypes, fargs, 0); MATCH mta = td.matchWithInstance(sc, ti, &dedtypes, fargs, 0);
//printf("matchWithInstance = %d\n", mta); //printf("matchWithInstance = %d\n", mta);
if (mta <= MATCH.nomatch || mta < ta_last) // no match or less mat ch if (mta <= MATCH.nomatch || mta < ta_last) // no match or less mat ch
{
Pool!TemplateInstance.dispose(ti);
return 0; return 0;
}
ti.templateInstanceSemantic(sc, fargs); ti.templateInstanceSemantic(sc, fargs);
if (!ti.inst) // if template failed to expand if (!ti.inst) // if template failed to expand
{
Pool!TemplateInstance.dispose(ti);
return 0; return 0;
}
Dsymbol s = ti.inst.toAlias(); Dsymbol s = ti.inst.toAlias();
FuncDeclaration fd; FuncDeclaration fd;
if (auto tdx = s.isTemplateDeclaration()) if (auto tdx = s.isTemplateDeclaration())
{ {
Objects dedtypesX; // empty tiargs Objects dedtypesX; // empty tiargs
// https://issues.dlang.org/show_bug.cgi?id=11553 // https://issues.dlang.org/show_bug.cgi?id=11553
// Check for recursive instantiation of tdx. // Check for recursive instantiation of tdx.
for (TemplatePrevious* p = tdx.previous; p; p = p.prev) for (TemplatePrevious* p = tdx.previous; p; p = p.prev)
skipping to change at line 2872 skipping to change at line 2866
{ {
//printf("recursive, no match p.sc=%p %p %s\n", p.sc, th is, this.toChars()); //printf("recursive, no match p.sc=%p %p %s\n", p.sc, th is, this.toChars());
/* It must be a subscope of p.sc, other scope chains are not recursive /* It must be a subscope of p.sc, other scope chains are not recursive
* instantiations. * instantiations.
*/ */
for (Scope* scx = sc; scx; scx = scx.enclosing) for (Scope* scx = sc; scx; scx = scx.enclosing)
{ {
if (scx == p.sc) if (scx == p.sc)
{ {
error(loc, "recursive template expansion while l ooking for `%s.%s`", ti.toChars(), tdx.toChars()); error(loc, "recursive template expansion while l ooking for `%s.%s`", ti.toChars(), tdx.toChars());
Pool!TemplateInstance.dispose(ti);
goto Lerror; goto Lerror;
} }
} }
} }
/* BUG: should also check for ref param differences /* BUG: should also check for ref param differences
*/ */
} }
TemplatePrevious pr; TemplatePrevious pr;
pr.prev = tdx.previous; pr.prev = tdx.previous;
skipping to change at line 2906 skipping to change at line 2899
goto Lerror; goto Lerror;
if (!fd) if (!fd)
return 0; return 0;
if (fd.type.ty != Tfunction) if (fd.type.ty != Tfunction)
{ {
m.lastf = fd; // to propagate "error match" m.lastf = fd; // to propagate "error match"
m.count = 1; m.count = 1;
m.last = MATCH.nomatch; m.last = MATCH.nomatch;
Pool!TemplateInstance.dispose(ti);
return 1; return 1;
} }
Type tthis_fd = fd.needThis() && !fd.isCtorDeclaration() ? tthis : n ull; Type tthis_fd = fd.needThis() && !fd.isCtorDeclaration() ? tthis : n ull;
auto tf = cast(TypeFunction)fd.type; auto tf = cast(TypeFunction)fd.type;
MATCH mfa = tf.callMatch(tthis_fd, fargs_, 0, null, sc); MATCH mfa = tf.callMatch(tthis_fd, fargs_, 0, null, sc);
if (mfa < m.last) if (mfa < m.last)
return 0; return 0;
skipping to change at line 2930 skipping to change at line 2922
if (mfa < m.last) goto Ltd_best2; if (mfa < m.last) goto Ltd_best2;
if (mfa > m.last) goto Ltd2; if (mfa > m.last) goto Ltd2;
// td_best and td are ambiguous // td_best and td are ambiguous
//printf("Lambig2\n"); //printf("Lambig2\n");
m.nextf = fd; m.nextf = fd;
m.count++; m.count++;
return 0; return 0;
Ltd_best2: Ltd_best2:
Pool!TemplateInstance.dispose(ti);
return 0; return 0;
Ltd2: Ltd2:
// td is the new best match // td is the new best match
assert(td._scope); assert(td._scope);
td_best = td; td_best = td;
ti_best = null; ti_best = null;
property = 0; // (backward compatibility) property = 0; // (backward compatibility)
ta_last = mta; ta_last = mta;
m.last = mfa; m.last = mfa;
skipping to change at line 2957 skipping to change at line 2948
} }
//printf("td = %s\n", td.toChars()); //printf("td = %s\n", td.toChars());
for (size_t ovi = 0; f; f = f.overnext0, ovi++) for (size_t ovi = 0; f; f = f.overnext0, ovi++)
{ {
if (f.type.ty != Tfunction || f.errors) if (f.type.ty != Tfunction || f.errors)
goto Lerror; goto Lerror;
/* This is a 'dummy' instance to evaluate constraint properly. /* This is a 'dummy' instance to evaluate constraint properly.
*/ */
auto ti = Pool!TemplateInstance.make(loc, td, tiargs); auto ti = new TemplateInstance(loc, td, tiargs);
ti.parent = td.parent; // Maybe calculating valid 'enclosing' is un necessary. ti.parent = td.parent; // Maybe calculating valid 'enclosing' is un necessary.
auto fd = f; auto fd = f;
int x = td.deduceFunctionTemplateMatch(ti, sc, fd, tthis, fargs); int x = td.deduceFunctionTemplateMatch(ti, sc, fd, tthis, fargs);
MATCH mta = cast(MATCH)(x >> 4); MATCH mta = cast(MATCH)(x >> 4);
MATCH mfa = cast(MATCH)(x & 0xF); MATCH mfa = cast(MATCH)(x & 0xF);
//printf("match:t/f = %d/%d\n", mta, mfa); //printf("match:t/f = %d/%d\n", mta, mfa);
if (!fd || mfa == MATCH.nomatch) if (!fd || mfa == MATCH.nomatch)
{
Pool!TemplateInstance.dispose(ti);
continue; continue;
}
Type tthis_fd = fd.needThis() ? tthis : null; Type tthis_fd = fd.needThis() ? tthis : null;
bool isCtorCall = tthis_fd && fd.isCtorDeclaration(); bool isCtorCall = tthis_fd && fd.isCtorDeclaration();
if (isCtorCall) if (isCtorCall)
{ {
// Constructor call requires additional check. // Constructor call requires additional check.
auto tf = cast(TypeFunction)fd.type; auto tf = cast(TypeFunction)fd.type;
assert(tf.next); assert(tf.next);
skipping to change at line 3087 skipping to change at line 3075
{ {
// Matches to template function // Matches to template function
assert(td_best.onemember && td_best.onemember.isFuncDeclaration()); assert(td_best.onemember && td_best.onemember.isFuncDeclaration());
/* The best match is td_best with arguments tdargs. /* The best match is td_best with arguments tdargs.
* Now instantiate the template. * Now instantiate the template.
*/ */
assert(td_best._scope); assert(td_best._scope);
if (!sc) if (!sc)
sc = td_best._scope; // workaround for Type.aliasthisOf sc = td_best._scope; // workaround for Type.aliasthisOf
auto ti = Pool!TemplateInstance.make(loc, td_best, ti_best.tiargs); auto ti = new TemplateInstance(loc, td_best, ti_best.tiargs);
ti.templateInstanceSemantic(sc, fargs); ti.templateInstanceSemantic(sc, fargs);
m.lastf = ti.toAlias().isFuncDeclaration(); m.lastf = ti.toAlias().isFuncDeclaration();
if (!m.lastf) if (!m.lastf)
{
goto Lnomatch; goto Lnomatch;
}
if (ti.errors) if (ti.errors)
{ {
Lerror: Lerror:
m.count = 1; m.count = 1;
assert(m.lastf); assert(m.lastf);
m.last = MATCH.nomatch; m.last = MATCH.nomatch;
return; return;
} }
// look forward instantiated overload function // look forward instantiated overload function
skipping to change at line 4055 skipping to change at line 4041
/* Handle case of: /* Handle case of:
* template Foo(T : sa!(T), alias sa) * template Foo(T : sa!(T), alias sa)
*/ */
size_t i = templateIdentifierLookup(tp.tempinst.name, parame ters); size_t i = templateIdentifierLookup(tp.tempinst.name, parame ters);
if (i == IDX_NOTFOUND) if (i == IDX_NOTFOUND)
{ {
/* Didn't find it as a parameter identifier. Try looking /* Didn't find it as a parameter identifier. Try looking
* it up and seeing if is an alias. * it up and seeing if is an alias.
* https://issues.dlang.org/show_bug.cgi?id=1454 * https://issues.dlang.org/show_bug.cgi?id=1454
*/ */
auto tid = Pool!TypeIdentifier.make(tp.loc, tp.tempinst. name); auto tid = new TypeIdentifier(tp.loc, tp.tempinst.name);
Type tx; Type tx;
Expression e; Expression e;
Dsymbol s; Dsymbol s;
tid.resolve(tp.loc, sc, &e, &tx, &s); tid.resolve(tp.loc, sc, &e, &tx, &s);
Pool!TypeIdentifier.dispose(tid);
if (tx) if (tx)
{ {
s = tx.toDsymbol(sc); s = tx.toDsymbol(sc);
if (TemplateInstance ti = s ? s.parent.isTemplateIns tance() : null) if (TemplateInstance ti = s ? s.parent.isTemplateIns tance() : null)
{ {
// https://issues.dlang.org/show_bug.cgi?id=1429 0 // https://issues.dlang.org/show_bug.cgi?id=1429 0
// Try to match with ti.tempecl, // Try to match with ti.tempecl,
// only when ti is an enclosing instance. // only when ti is an enclosing instance.
Dsymbol p = sc.parent; Dsymbol p = sc.parent;
while (p && p != ti) while (p && p != ti)
skipping to change at line 4839 skipping to change at line 4824
t = t.typeSemantic(e.loc, sc); t = t.typeSemantic(e.loc, sc);
if (t.ty == Terror) if (t.ty == Terror)
return; return;
tiargs.push(t); tiargs.push(t);
} }
// Set target of return type inference // Set target of return type inference
if (!tf.next && tof.next) if (!tf.next && tof.next)
e.fd.treq = tparam; e.fd.treq = tparam;
auto ti = Pool!TemplateInstance.make(e.loc, e.td, tiargs); auto ti = new TemplateInstance(e.loc, e.td, tiargs);
Expression ex = (new ScopeExp(e.loc, ti)).expressionSemantic(e.t d._scope); Expression ex = (new ScopeExp(e.loc, ti)).expressionSemantic(e.t d._scope);
// Reset inference target for the later re-semantic // Reset inference target for the later re-semantic
e.fd.treq = null; e.fd.treq = null;
if (ex.op == TOK.error)
return;
if (ex.op != TOK.function_) if (ex.op != TOK.function_)
{
Pool!TemplateInstance.dispose(ti);
return; return;
}
visit(ex.type); visit(ex.type);
return; return;
} }
Type t = e.type; Type t = e.type;
if (t.ty == Tdelegate && tparam.ty == Tpointer) if (t.ty == Tdelegate && tparam.ty == Tpointer)
return; return;
// Allow conversion from implicit function pointer to delegate // Allow conversion from implicit function pointer to delegate
skipping to change at line 5400 skipping to change at line 5384
} }
override TemplateParameter syntaxCopy() override TemplateParameter syntaxCopy()
{ {
return new TemplateTypeParameter(loc, ident, specType ? specType.syntaxC opy() : null, defaultType ? defaultType.syntaxCopy() : null); return new TemplateTypeParameter(loc, ident, specType ? specType.syntaxC opy() : null, defaultType ? defaultType.syntaxCopy() : null);
} }
override final bool declareParameter(Scope* sc) override final bool declareParameter(Scope* sc)
{ {
//printf("TemplateTypeParameter.declareParameter('%s')\n", ident.toChars ()); //printf("TemplateTypeParameter.declareParameter('%s')\n", ident.toChars ());
auto ti = Pool!TypeIdentifier.make(loc, ident); auto ti = new TypeIdentifier(loc, ident);
Declaration ad = new AliasDeclaration(loc, ident, ti); Declaration ad = new AliasDeclaration(loc, ident, ti);
if (sc.insert(ad) !is null) return sc.insert(ad) !is null;
return true;
Pool!TypeIdentifier.dispose(ti);
return false;
} }
override final void print(RootObject oarg, RootObject oded) override final void print(RootObject oarg, RootObject oded)
{ {
printf(" %s\n", ident.toChars()); printf(" %s\n", ident.toChars());
Type t = isType(oarg); Type t = isType(oarg);
Type ta = isType(oded); Type ta = isType(oded);
assert(ta); assert(ta);
skipping to change at line 5452 skipping to change at line 5433
return defaultType !is null; return defaultType !is null;
} }
override final RootObject dummyArg() override final RootObject dummyArg()
{ {
Type t = specType; Type t = specType;
if (!t) if (!t)
{ {
// Use this for alias-parameter's too (?) // Use this for alias-parameter's too (?)
if (!tdummy) if (!tdummy)
tdummy = Pool!TypeIdentifier.make(loc, ident); tdummy = new TypeIdentifier(loc, ident);
t = tdummy; t = tdummy;
} }
return t; return t;
} }
override void accept(Visitor v) override void accept(Visitor v)
{ {
v.visit(this); v.visit(this);
} }
} }
skipping to change at line 5629 skipping to change at line 5610
return this; return this;
} }
override TemplateParameter syntaxCopy() override TemplateParameter syntaxCopy()
{ {
return new TemplateAliasParameter(loc, ident, specType ? specType.syntax Copy() : null, objectSyntaxCopy(specAlias), objectSyntaxCopy(defaultAlias)); return new TemplateAliasParameter(loc, ident, specType ? specType.syntax Copy() : null, objectSyntaxCopy(specAlias), objectSyntaxCopy(defaultAlias));
} }
override bool declareParameter(Scope* sc) override bool declareParameter(Scope* sc)
{ {
auto ti = Pool!TypeIdentifier.make(loc, ident); auto ti = new TypeIdentifier(loc, ident);
Declaration ad = new AliasDeclaration(loc, ident, ti); Declaration ad = new AliasDeclaration(loc, ident, ti);
if (sc.insert(ad) !is null) return sc.insert(ad) !is null;
return true;
Pool!TypeIdentifier.dispose(ti);
return false;
} }
override void print(RootObject oarg, RootObject oded) override void print(RootObject oarg, RootObject oded)
{ {
printf(" %s\n", ident.toChars()); printf(" %s\n", ident.toChars());
Dsymbol sa = isDsymbol(oded); Dsymbol sa = isDsymbol(oded);
assert(sa); assert(sa);
printf("\tParameter alias: %s\n", sa.toChars()); printf("\tParameter alias: %s\n", sa.toChars());
} }
skipping to change at line 5714 skipping to change at line 5692
return this; return this;
} }
override TemplateParameter syntaxCopy() override TemplateParameter syntaxCopy()
{ {
return new TemplateTupleParameter(loc, ident); return new TemplateTupleParameter(loc, ident);
} }
override bool declareParameter(Scope* sc) override bool declareParameter(Scope* sc)
{ {
auto ti = Pool!TypeIdentifier.make(loc, ident); auto ti = new TypeIdentifier(loc, ident);
Declaration ad = new AliasDeclaration(loc, ident, ti); Declaration ad = new AliasDeclaration(loc, ident, ti);
if (sc.insert(ad) !is null) return sc.insert(ad) !is null;
return true;
Pool!TypeIdentifier.dispose(ti);
return false;
} }
override void print(RootObject oarg, RootObject oded) override void print(RootObject oarg, RootObject oded)
{ {
printf(" %s... [", ident.toChars()); printf(" %s... [", ident.toChars());
Tuple v = isTuple(oded); Tuple v = isTuple(oded);
assert(v); assert(v);
//printf("|%d| ", v.objects.dim); //printf("|%d| ", v.objects.dim);
foreach (i, o; v.objects) foreach (i, o; v.objects)
skipping to change at line 5899 skipping to change at line 5874
{ {
a = new Objects(objs.dim); a = new Objects(objs.dim);
foreach (i, o; *objs) foreach (i, o; *objs)
(*a)[i] = objectSyntaxCopy(o); (*a)[i] = objectSyntaxCopy(o);
} }
return a; return a;
} }
override Dsymbol syntaxCopy(Dsymbol s) override Dsymbol syntaxCopy(Dsymbol s)
{ {
TemplateInstance ti = s ? cast(TemplateInstance)s : Pool!TemplateInstanc e.make(loc, name, null); TemplateInstance ti = s ? cast(TemplateInstance)s : new TemplateInstance (loc, name, null);
ti.tiargs = arraySyntaxCopy(tiargs); ti.tiargs = arraySyntaxCopy(tiargs);
TemplateDeclaration td; TemplateDeclaration td;
if (inst && tempdecl && (td = tempdecl.isTemplateDeclaration()) !is null ) if (inst && tempdecl && (td = tempdecl.isTemplateDeclaration()) !is null )
td.ScopeDsymbol.syntaxCopy(ti); td.ScopeDsymbol.syntaxCopy(ti);
else else
ScopeDsymbol.syntaxCopy(ti); ScopeDsymbol.syntaxCopy(ti);
return ti; return ti;
} }
// resolve real symbol // resolve real symbol
 End of changes. 30 change blocks. 
42 lines changed or deleted 17 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)