Loyc.Syntax.CodeSymbols.IsArrayKeyword C# (CSharp) Method

IsArrayKeyword() public static method

Returns true if the symbol is a pair of square brackets with zero or more commas inside, e.g. "[,]", which in EC# represents an array type of a specific number of dimensions.
public static IsArrayKeyword ( Symbol s ) : bool
s Symbol
return bool
		public static bool IsArrayKeyword(Symbol s) { return CountArrayDimensions(s) > 0; }
		/// <summary>Returns the rank of an array symbol when <see cref="IsArrayKeyword"/> 

Usage Example

Exemplo n.º 1
0
        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);
            }
        }
All Usage Examples Of Loyc.Syntax.CodeSymbols::IsArrayKeyword