GetArrayKeyword() public static méthode

Gets the Symbol for an array with the specified number of dimensions, e.g. GetArrayKeyword(3) returns [,,].
public static GetArrayKeyword ( int dims ) : Symbol
dims int
Résultat Symbol
Exemple #1
0
        public static LNode of(LNode node, IMessageSink sink)
        {
            LNode kind;

            if (node.ArgCount == 2 && (kind = node.Args[0]).IsId)
            {
                if (kind.IsIdNamed(_array))
                {
                    return(node.WithArgChanged(0, kind.WithName(S.Array)));
                }
                if (kind.IsIdNamed(_opt))
                {
                    return(node.WithArgChanged(0, kind.WithName(S.QuestionMark)));
                }
                if (kind.IsIdNamed(_ptr))
                {
                    return(node.WithArgChanged(0, kind.WithName(S._Pointer)));
                }
            }
            else if (node.ArgCount == 3 && (kind = node.Args[0]).IsIdNamed(_array) && node.Args[1].IsLiteral)
            {
                return(node.WithArgs(kind.WithName(S.GetArrayKeyword((int)node.Args[1].Value)), node.Args[2]));
            }
            return(null);
        }
 public void CsDataTypes()
 {
     Stmt("double x;", F.Vars(F.Double, x));
     Stmt("int[] x;", F.Vars(F.Of(S.Array, S.Int32), x));
     Stmt("long* x;", F.Vars(F.Of(S._Pointer, S.Int64), x));
     Stmt("string[][,] x;", F.Vars(F.Of(_(S.Array), F.Of(S.TwoDimensionalArray, S.String)), x));
     Stmt("typeof(float*);", F.Call(S.Typeof, F.Of(S._Pointer, S.Single)));
     Stmt("decimal[,,,] x;", F.Vars(F.Of(S.GetArrayKeyword(4), S.Decimal), x));
     Stmt("double? x;", F.Vars(F.Of(S.QuestionMark, S.Double), x));
     Stmt("Foo<a.b.c>? x;", F.Vars(F.Of(_(S.QuestionMark), F.Of(Foo, F.Dot(a, b, c))), x));
     Stmt("Foo<a?,b.c[,]>[] x;", F.Vars(F.Of(_(S.Array), F.Of(Foo, F.Of(_(S.QuestionMark), a), F.Of(_(S.TwoDimensionalArray), F.Dot(b, c)))), x));
 }
Exemple #3
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);
            }
        }
 public void CsOperatorNew()
 {
     Expr("new Foo(x)", F.Call(S.New, F.Call(Foo, x)));
     Expr("new Foo(x) { a }", F.Call(S.New, F.Call(Foo, x), a));
     Expr("new Foo()", F.Call(S.New, F.Call(Foo)));
     Expr("new Foo { a }", F.Call(S.New, F.Call(Foo), a));                          // new Foo() { a } would also be ok
     Expr("new int[] { a, b }", F.Call(S.New, F.Call(F.Of(S.Array, S.Int32)), a, b));
     Expr("new[] { a, b }", F.Call(S.New, F.Call(S.Array), a, b));
     Expr("new[] { }", F.Call(S.New, F.Call(S.Array)));
     Expr("new int[][,] { a }", F.Call(S.New, F.Call(F.Of(_(S.Array), F.Of(S.TwoDimensionalArray, S.Int32))), a));
     // This expression is illegal since it requires an initializer list, but it's parsable so should print ok
     Expr("new int[][,][,,]", F.Call(S.New, F.Call(F.Of(_(S.Array), F.Of(_(S.TwoDimensionalArray), F.Of(S.GetArrayKeyword(3), S.Int32))))), Mode.Both | Mode.ExpectAndDropParserError);
     Expr("new int[10][,] { a }", F.Call(S.New, F.Call(F.Of(_(S.Array), F.Of(S.TwoDimensionalArray, S.Int32)), F.Literal(10)), a));
     Expr("new int[x, x][]", F.Call(S.New, F.Call(F.Of(_(S.TwoDimensionalArray), F.Of(S.Array, S.Int32)), x, x)));
     Expr("new int[,]", F.Call(S.New, F.Call(F.Of(S.TwoDimensionalArray, S.Int32))), Mode.Both | Mode.ExpectAndDropParserError);
     Option(Mode.PrintBothParseFirst, "#new(@`[,]`!([Foo] int)());", "new int[,];",
            F.Call(S.New, F.Call(F.Of(_(S.TwoDimensionalArray), Attr(Foo, F.Int32)))), p => p.DropNonDeclarationAttributes = true);
     Expr("new { a = 1, b = 2 }", F.Call(S.New, F.Missing, F.Call(S.Assign, a, one), F.Call(S.Assign, b, two)));
 }