private EXPR ReorderArgumentsForNamedAndOptional(EXPR callingObject, EXPR pResult)
{
EXPR arguments;
AggregateType type;
MethodOrPropertySymbol methprop;
EXPRMEMGRP memgroup;
TypeArray typeArgs;
if (pResult.isCALL())
{
EXPRCALL call = pResult.asCALL();
arguments = call.GetOptionalArguments();
type = call.mwi.Ats;
methprop = call.mwi.Meth();
memgroup = call.GetMemberGroup();
typeArgs = call.mwi.TypeArgs;
}
else
{
Debug.Assert(pResult.isPROP());
EXPRPROP prop = pResult.asPROP();
arguments = prop.GetOptionalArguments();
type = prop.pwtSlot.Ats;
methprop = prop.pwtSlot.Prop();
memgroup = prop.GetMemberGroup();
typeArgs = null;
}
ArgInfos argInfo = new ArgInfos();
bool b;
argInfo.carg = ExpressionBinder.CountArguments(arguments, out b);
_binder.FillInArgInfoFromArgList(argInfo, arguments);
// We need to substitute type parameters BEFORE getting the most derived one because
// we're binding against the base method, and the derived method may change the
// generic arguments.
TypeArray parameters = SymbolLoader.GetTypeManager().SubstTypeArray(methprop.Params, type, typeArgs);
methprop = ExpressionBinder.GroupToArgsBinder.FindMostDerivedMethod(SymbolLoader, methprop, callingObject.type);
ExpressionBinder.GroupToArgsBinder.ReOrderArgsForNamedArguments(
methprop,
parameters,
type,
memgroup,
argInfo,
_semanticChecker.GetTypeManager(),
_exprFactory,
SymbolLoader);
{
EXPR pList = null;
// We reordered, so make a new list of them and set them on the constructor.
// Go backwards cause lists are right-flushed.
// Also perform the conversions to the right types.
for (int i = argInfo.carg - 1; i >= 0; i--)
{
EXPR pArg = argInfo.prgexpr[i];
// Strip the name-ness away, since we don't need it.
pArg = StripNamedArgument(pArg);
// Perform the correct conversion.
pArg = _binder.tryConvert(pArg, parameters[i]);
if (pList == null)
{
pList = pArg;
}
else
{
pList = _exprFactory.CreateList(pArg, pList);
}
}
if (pResult.isCALL())
{
pResult.asCALL().SetOptionalArguments(pList);
}
else
{
pResult.asPROP().SetOptionalArguments(pList);
}
}
return pResult;
}