Home | History | Annotate | Download | only in dmd

Lines Matching refs:MATCH

25  *   runs semantic on the template arguments and deduce the best match
258 private bool match(RootObject o1, RootObject o2)
264 printf("match() o1 = %p %s (%d), o2 = %p %s (%d)\n",
349 printf("\t. match\n");
359 * Match an array of them.
374 if (!match(o1, o2))
392 /* Must follow the logic of match()
414 * Handles all Expression classes and MUST match their equals method,
807 //printf("recursive, no match p.sc=%p %p %s\n", p.sc, this, this.toChars());
1051 * Return match level.
1053 extern (D) MATCH matchWithInstance(Scope* sc, TemplateInstance ti, Objects* dedtypes, Expressions* fargs, int flag)
1066 MATCH nomatch()
1070 printf(" no match\n");
1072 return MATCH.nomatch;
1074 MATCH m;
1080 return MATCH.nomatch;
1085 // If more arguments than parameters, no match
1090 printf(" no match: more arguments than parameters\n");
1092 return MATCH.nomatch;
1104 m = MATCH.exact;
1107 MATCH m2;
1124 if (m2 == MATCH.nomatch)
1161 if (m > MATCH.nomatch && constraint && !flag)
1206 if (m > MATCH.nomatch)
1225 printf(" match = %d\n", m);
1239 * match this is at least as specialized as td2
1242 MATCH leastAsSpecialized(Scope* sc, TemplateDeclaration td2, Expressions* fargs)
1277 MATCH m = td2.matchWithInstance(sc, ti, &dedtypes, fargs, 1);
1278 if (m > MATCH.nomatch)
1296 printf(" doesn't match, so is not as specialized\n");
1298 return MATCH.nomatch;
1302 * Match function arguments against a specific template function.
1313 * match pair of initial and inferred template arguments
1321 MATCH match = MATCH.exact;
1322 MATCH matchTiargs = MATCH.exact;
1356 return MATCHpair(MATCH.nomatch, MATCH.nomatch);
1365 return MATCHpair(MATCH.nomatch, MATCH.nomatch);
1373 return MATCHpair(MATCH.nomatch, MATCH.nomatch);
1431 MATCH m = (*parameters)[i].matchArg(instLoc, paramscope, dedargs, i, parameters, dedtypes, &sparam);
1433 if (m == MATCH.nomatch)
1466 /* Check for match of function arguments with variadic template
1475 matchTiargs = MATCH.convert;
1520 // Match 'tthis' to any TemplateThisParameter's
1528 MATCH m = deduceType(tthis, paramscope, t, parameters, dedtypes);
1529 if (m == MATCH.nomatch)
1531 if (m < match)
1532 match = m; // pick worst match
1536 // Match attributes of tthis against attributes of fd
1564 MATCH m = MODmethodConv(thismod, mod);
1565 if (m == MATCH.nomatch)
1567 if (m < match)
1568 match = m;
1639 MATCH m;
1643 m = MATCH.constant;
1649 if (m == MATCH.nomatch)
1651 if (m < match)
1652 match = m;
1769 MATCH m2 = tparam.matchArg(instLoc, paramscope, dedargs, i, parameters, dedtypes, null);
1771 if (m2 == MATCH.nomatch)
1774 matchTiargs = m2; // pick worst match
1780 if (MATCH.convert < matchTiargs)
1781 matchTiargs = MATCH.convert;
1851 /* Allow expressions that have CT-known boundaries and type [] to match with [dim]
1901 MATCH m = deduceType(oarg, paramscope, prmtype, parameters, dedtypes, &wm, inferStart);
1905 /* If no match, see if the argument can be matched by using
1908 if (m == MATCH.nomatch && prmtype.deco)
1911 if (m == MATCH.nomatch)
1921 * just regard it as not a match.
1938 if (m > MATCH.nomatch && (fparam.storageClass & (STC.ref_ | STC.auto_)) == STC.ref_)
1954 if (m > MATCH.nomatch && (fparam.storageClass & STC.out_))
1961 if (m == MATCH.nomatch && (fparam.storageClass & STC.lazy_) && prmtype.ty == Tvoid && farg.type.ty != Tvoid)
1962 m = MATCH.convert;
1963 if (m != MATCH.nomatch)
1965 if (m < match)
1966 match = m; // pick worst match
1979 /* Check for match with function parameter T...
2049 MATCH m = dim.implicitConvTo(vt);
2050 if (m == MATCH.nomatch)
2067 MATCH m;
2075 m = MATCH.exact;
2080 if (m == MATCH.nomatch)
2083 m = MATCH.convert;
2093 if (m == MATCH.nomatch)
2095 if (m < match)
2096 match = m;
2134 * But for function templates, we really need them to match
2152 MATCH m2 = tparam.matchArg(instLoc, paramscope, dedargs, i, parameters, dedtypes, null);
2154 if (m2 == MATCH.nomatch)
2157 matchTiargs = m2; // pick worst match
2164 if (MATCH.convert < matchTiargs)
2165 matchTiargs = MATCH.convert;
2201 MATCH m2 = tparam.matchArg(instLoc, paramscope, dedargs, i, parameters, dedtypes, null);
2203 if (m2 == MATCH.nomatch)
2206 matchTiargs = m2; // pick worst match
2265 //printf("\tmatch %d\n", match);
2266 match);
2388 // Match 'tthis' to any TemplateThisParameter's
2571 MATCH matchAll(Type tt)
2573 MATCH match = MATCH.exact;
2582 MATCH m = e.implicitConvTo(t);
2583 if (match > m)
2584 match = m;
2585 if (match == MATCH.nomatch)
2588 return match;
2630 //printf("match:t/f = %d/%d\n", ta_last, m.last);
2640 MATCH ta_last = m.last != MATCH.nomatch ? MATCH.exact : MATCH.nomatch;
2648 // explicitly specified tiargs never match to non template function
2693 return 0; // MATCH.nomatch
2714 MATCH mfa = tf.callMatch(tthis_fd, fargs_, 0, pMessage, sc);
2716 if (mfa == MATCH.nomatch)
2734 MATCH c1 = fd.leastAsSpecialized(m.lastf);
2735 MATCH c2 = m.lastf.leastAsSpecialized(fd);
2746 * I.e. a not-the-same-but-covariant match is preferred,
2806 ta_last = MATCH.exact;
2842 m.last = MATCH.nomatch;
2855 MATCH mta = td.matchWithInstance(sc, ti, &dedtypes, fargs, 0);
2857 if (mta == MATCH.nomatch || mta < ta_last) // no match or less match
2876 //printf("recursive, no match p.sc=%p %p %s\n", p.sc, this, this.toChars());
2915 m.lastf = fd; // to propagate "error match"
2917 m.last = MATCH.nomatch;
2924 MATCH mfa = tf.callMatch(tthis_fd, fargs_, 0, null, sc);
2944 // td is the new best match
2972 MATCH mta = x.mta;
2973 MATCH mfa = x.mfa;
2974 //printf("match:t/f = %d/%d\n", mta, mfa);
2975 if (!fd || mfa == MATCH.nomatch)
2994 continue; // MATCH.nomatch
3006 MATCH c1 = td.leastAsSpecialized(sc, td_best, fargs);
3007 MATCH c2 = td_best.leastAsSpecialized(sc, td, fargs);
3017 MATCH c1 = tf1.callMatch(tthis_fd, fargs_, 0, null, sc);
3018 MATCH c2 = tf2.callMatch(tthis_best, fargs_, 0, null, sc);
3025 MATCH c1 = fd.leastAsSpecialized(m.lastf);
3026 MATCH c2 = m.lastf.leastAsSpecialized(fd);
3044 Ltd_best: // td_best is the best match so far
3048 Ltd: // td is the new best match
3085 /* The best match is td_best with arguments tdargs.
3103 m.last = MATCH.nomatch;
3148 m.last = MATCH.nomatch;
3263 private MATCH deduceTypeHelper(Type t, Type* at, Type tparam)
3294 return MATCH.exact;
3314 return MATCH.exact;
3324 return MATCH.exact;
3342 return MATCH.constant;
3348 return MATCH.constant;
3358 return MATCH.exact;
3364 return MATCH.constant;
3376 return MATCH.constant;
3382 return MATCH.constant;
3472 return MATCH.nomatch;
3495 MATCH deduceType(RootObject o, Scope* sc, Type tparam, TemplateParameters* parameters, Objects* dedtypes, uint* wm = null, size_t inferStart = 0, bool ignoreAliasThis = false)
3508 MATCH result;
3519 result = MATCH.nomatch;
3630 result = MATCH.constant;
3639 if (result > MATCH.nomatch)
3642 if (result > MATCH.constant)
3643 result = MATCH.constant; // limit level for inout matches
3651 (*dedtypes)[i] = tt; // Prefer current type match
3668 else if (MATCH m = deduceTypeHelper(t, &tt, tparam))
3683 if (result > MATCH.nomatch)
3700 if (tt.ty == Tsarray && at.ty == Tarray && tt.nextOf().implicitConvTo(at.nextOf()) >= MATCH.constant)
3729 MATCH m = t.implicitConvTo(tparam);
3730 if (m == MATCH.nomatch && !ignoreAliasThis)
3784 result = MATCH.exact;
3788 result = MATCH.nomatch;
3792 result = MATCH.constant;
3813 // Extra check that array dimensions must match
3818 MATCH m = deduceType(t.next, sc, tparam.nextOf(), parameters, dedtypes, wm);
3819 result = (m >= MATCH.constant) ? MATCH.convert : MATCH.nomatch;
3865 // Extra check that index type must match
3871 result = MATCH.nomatch;
3880 // Extra check that function characteristics must match
3888 result = MATCH.nomatch;
3906 result = MATCH.nomatch;
3916 /* See if tuple match
3955 // Existing deduced argument must be a tuple, and must match
3959 result = MATCH.nomatch;
3967 result = MATCH.nomatch;
3990 result = MATCH.nomatch;
4005 result = MATCH.nomatch;
4025 result = MATCH.nomatch;
4070 // Try to match with ti.tempecl,
4126 break; // match if all remained parameters are dependent
4162 if (!match(v, vt))
4281 //printf("no match\n");
4282 result = MATCH.nomatch;
4299 // if we have a no match we still need to check alias this
4300 if (m != MATCH.nomatch)
4307 /* Match things like:
4335 //printf("\t%d\n", cast(MATCH) t.implicitConvTo(tp));
4338 result = MATCH.constant;
4356 result = MATCH.nomatch;
4363 if (result == MATCH.exact)
4364 result = MATCH.convert;
4371 * Classes can match with implicit conversion to a base class or interface.
4384 * tries to match tparam with b, and also tries all base interfaces of b.
4385 * If a match occurs, numBaseClassMatches is incremented, and the new deduced
4398 MATCH m = deduceType(t, sc, tparam, parameters, tmpdedtypes);
4399 if (m > MATCH.nomatch)
4401 match, it becomes our best estimate
4438 MATCH m = deduceType(tx, sc, tparam, parameters, dedtypes, wm);
4439 // Even if the match fails, there is still a chance it could match
4441 if (m != MATCH.nomatch)
4448 /* Match things like:
4472 if (result != MATCH.nomatch)
4475 /* There is still a chance to match via implicit conversion to
4477 * match, we need to check them all.
4480 int numBaseClassMatches = 0; // Have we found an interface match?
4501 result = MATCH.nomatch;
4505 // If we got at least one match, copy the known types into dedtypes
4507 result = MATCH.convert;
4516 //printf("\t%d\n", cast(MATCH) t.implicitConvTo(tp));
4519 result = MATCH.constant;
4552 result = MATCH.exact;
4577 result = MATCH.constant;
4579 else if (MATCH m = deduceTypeHelper(e.type, &tt, tparam))
4592 result = MATCH.convert;
4612 MATCH match1 = xt ? xt.matchAll(tt) : MATCH.nomatch;
4618 MATCH match2 = e.implicitConvTo(pt);
4620 if (match1 > MATCH.nomatch && match2 > MATCH.nomatch)
4622 if (at.implicitConvTo(tt) == MATCH.nomatch)
4623 match1 = MATCH.nomatch; // Prefer at
4624 else if (tt.implicitConvTo(at) == MATCH.nomatch)
4625 match2 = MATCH.nomatch; // Prefer tt
4633 match1 = MATCH.nomatch;
4635 match2 = MATCH.nomatch;
4640 match2 = MATCH.nomatch;
4642 match1 = MATCH.nomatch;
4648 match1 = MATCH.nomatch;
4649 match2 = MATCH.nomatch;
4652 if (match1 > MATCH.nomatch)
4654 // Prefer current match: tt
4662 if (match2 > MATCH.nomatch)
4664 // Prefer previous match: (*dedtypes)[i]
4687 result = MATCH.nomatch;
4690 MATCH deduceEmptyArrayElement()
4744 result = MATCH.exact;
4747 MATCH m = deduceType(e.basis, sc, tn, parameters, dedtypes, wm);
4753 if (result == MATCH.nomatch)
4757 MATCH m = deduceType(el, sc, tn, parameters, dedtypes, wm);
4779 result = MATCH.exact;
4782 MATCH m1 = deduceType(key, sc, taa.index, parameters, dedtypes, wm);
4785 if (result == MATCH.nomatch)
4787 MATCH m2 = deduceType((*e.values)[i], sc, taa.next, parameters, dedtypes, wm);
4790 if (result == MATCH.nomatch)
4887 if (result > MATCH.convert)
4888 result = MATCH.convert; // match with implicit conversion at most
5301 * A dependent template parameter should return MATCH.exact in matchArg()
5302 * to respect the match level of the corresponding precedent parameter.
6085 * true for match
6092 // Nesting must match
6123 goto Lnotequals; // auto ref's don't match
6128 goto Lnotequals; // auto ref's don't match
6663 * match with an 'alias' parameter. Instead, do the
6854 * `true` if a match was found, `false` otherwise
6884 * name, look for the best match.
6891 MATCH m_best = MATCH.nomatch;
6909 // then this is no match.
6920 MATCH m = td.matchWithInstance(sc, this, &dedtypes, fargs, 0);
6922 if (m == MATCH.nomatch) // no match at all
6929 MATCH c1 = td.leastAsSpecialized(sc, td_best, fargs);
6930 MATCH c2 = td_best.leastAsSpecialized(sc, td, fargs);
6940 // td_best is the best match so far
6945 // td is the new best match
7022 errorSupplemental(loc, "while looking for match for `%s`", toChars());
7026 const(char)* msg = "does not match template declaration";
7046 MATCH match = param.matchArg(loc, sc, tiargs, i, tdecl.parameters, &dedtypes, null);
7054 if (match == MATCH.nomatch &&
7070 .error(loc, "%s `%s.%s` does not match any template declaration", tempdecl.kind(), tempdecl.parent.toPrettyChars(), tempdecl.ident.toChars());
7074 /* The best match is td_last
7080 printf("\tIt's a match with template declaration '%s'\n", tempdecl.toChars());
7173 * When only one template can match with tiargs, inference is not necessary.
7191 MATCH m = td.matchWithInstance(sc, this, &dedtypes, null, 0);
7192 if (m == MATCH.nomatch)
7209 errorSupplemental(loc, "while looking for match for `%s`", toChars());
7832 * Match to a particular TemplateParameter.
7841 MATCH matchArg(TemplateParameter tp, Loc instLoc, Scope* sc, Objects* tiargs, size_t i, TemplateParameters* parameters, Objects* dedtypes, Declaration* psparam)
7843 MATCH matchArgNoMatch()
7847 return MATCH.nomatch;
7850 MATCH matchArgParameter()
7872 MATCH matchArgTuple(TemplateTupleParameter ttp)
7874 /* The rest of the actual arguments (tiargs[]) form the match
7908 MATCH matchArg(TemplateParameter tp, Scope* sc, RootObject oarg, size_t i, TemplateParameters* parameters, Objects* dedtypes, Declaration* psparam)
7910 MATCH matchArgNoMatch()
7912 //printf("\tm = %d\n", MATCH.nomatch);
7915 return MATCH.nomatch;
7918 MATCH matchArgType(TemplateTypeParameter ttp)
7921 MATCH m = MATCH.exact;
7936 MATCH m2 = deduceType(ta, sc, ttp.specType, parameters, dedtypes);
7937 if (m2 == MATCH.nomatch)
7964 // Must match already deduced type
7976 m = MATCH.convert;
7984 return ttp.dependent ? MATCH.exact : m;
7987 MATCH matchArgValue(TemplateValueParameter tvp)
7990 MATCH m = MATCH.exact;
8015 * A property-like function can match to both
8018 * template match result.
8030 m = MATCH.convert;
8046 MATCH m2 = ei.implicitConvTo(vt);
8050 if (m == MATCH.nomatch)
8086 // Must match already deduced value
8101 return tvp.dependent ? MATCH.exact : m;
8104 MATCH matchArgAlias(TemplateAliasParameter tap)
8107 MATCH m = MATCH.exact;
8118 m = MATCH.convert;
8146 * match to the template type parameter.
8155 * match to the template type parameter.
8162 /* Match any type that's not a TypeIdentifier to alias parameters,
8168 m = MATCH.convert;
8197 MATCH m2 = deduceType(t, sc, talias, parameters, dedtypes);
8198 if (m2 == MATCH.nomatch)
8206 MATCH m2 = ta.implicitConvTo(tspec);
8207 if (m2 == MATCH.nomatch)
8220 // Must match already deduced symbol
8249 return tap.dependent ? MATCH.exact : m;
8252 MATCH matchArgTuple(TemplateTupleParameter ttp)
8257 return MATCH.nomatch;
8262 return MATCH.nomatch;
8263 if (!match(tup, ovar))
8264 return MATCH.nomatch;
8270 return ttp.dependent ? MATCH.exact : MATCH.convert;
8410 MATCH mta; /// match template parameters by initial template arguments
8411 MATCH mfa; /// match template parameters by inferred template arguments
8413 debug this(MATCH mta, MATCH mfa)
8415 assert(MATCH.min <= mta && mta <= MATCH.max);
8416 assert(MATCH.min <= mfa && mfa <= MATCH.max);