private void PrintTypeWithArraySizes(LNode cons)
{
LNode type = cons.Target;
// Called by AutoPrintNewOperator; type is already validated.
Debug.Assert(type.Calls(S.Of, 2) && S.IsArrayKeyword(type.Args[0].Name));
// We have to deal with the "constructor arguments" specially.
// First of all, the constructor arguments appear inside the
// square brackets, which is unusual: int[x + y]. But there's
// something much more strange in case of arrays of arrays: the
// order of the square brackets must be reversed. If the
// constructor argument is 10, an array of two-dimensional
// arrays of int is written int[10][,], rather than int[,][10]
// which would be easier to handle.
int dims = cons.ArgCount, innerDims;
LNode elemType = type.Args[1];
var dimStack = InternalList <int> .Empty;
while ((innerDims = CountDimensionsIfArrayType(elemType)) != 0)
{
dimStack.Add(innerDims);
elemType = elemType.Args[1];
}
PrintType(elemType, EP.Primary.LeftContext(ContinueExpr));
_out.Write('[', true);
bool first = true;
foreach (var arg in cons.Args)
{
if (first)
{
first = false;
}
else
{
WriteThenSpace(',', SpaceOpt.AfterComma);
}
PrintExpr(arg, StartExpr, 0);
}
_out.Write(']', true);
// Write the brackets for the inner array types
for (int i = dimStack.Count - 1; i >= 0; i--)
{
_out.Write(S.GetArrayKeyword(dimStack[i]).Name, true);
}
}