Пример #1
0
        /// <summary>
        /// Reads a new array allocation expression from the code.
        /// </summary>
        /// <param name="unsafeCode">
        /// Indicates whether the code being parsed resides in an unsafe code block.
        /// </param>
        /// <param name="firstTokenNode">
        /// The first token in the expression.
        /// </param>
        /// <param name="type">
        /// The type of the array. This may be null for an implicitly typed array.
        /// </param>
        /// <param name="expressionReference">
        /// A reference to the expression being created.
        /// </param>
        /// <returns>
        /// Returns the expression.
        /// </returns>
        private NewArrayExpression GetNewArrayTypeExpression(bool unsafeCode, Node<CsToken> firstTokenNode, Expression type, Reference<ICodePart> expressionReference)
        {
            Param.Ignore(unsafeCode);
            Param.AssertNotNull(firstTokenNode, "firstTokenNode");
            Param.Ignore(type);
            Param.AssertNotNull(expressionReference, "expressionReference");

            // Get the next symbol.
            Symbol symbol = this.GetNextSymbol(SymbolType.OpenSquareBracket, expressionReference);

            // If the type is null, then this is an implicitly typed array and we will only find
            // array brackets here. Otherwise, we must get the array access expression which includes the type.
            if (type == null)
            {
                this.MovePastArrayBrackets(expressionReference);
            }
            else
            {
                // Get all of the array access expressions.
                while (symbol.SymbolType == SymbolType.OpenSquareBracket)
                {
                    type = this.GetArrayAccessExpression(type, ExpressionPrecedence.None, unsafeCode);
                    if (type == null || type.Tokens.First == null)
                    {
                        throw this.CreateSyntaxException();
                    }

                    symbol = this.GetNextSymbol(expressionReference);
                }
            }

            // Make sure there was at least one array access.
            if (type != null && type.ExpressionType != ExpressionType.ArrayAccess)
            {
                throw this.CreateSyntaxException();
            }

            // Get the next symbol and check the type.
            symbol = this.GetNextSymbol(expressionReference);

            // Get the initializer if there is one.
            ArrayInitializerExpression initializer = null;
            if (symbol.SymbolType == SymbolType.OpenCurlyBracket)
            {
                initializer = this.GetArrayInitializerExpression(unsafeCode);
            }

            // For an implicitly typed array, an array initializer is required.
            if (type == null && initializer == null)
            {
                throw this.CreateSyntaxException();
            }

            // Create the token list for the new array expression.
            CsTokenList partialTokens = new CsTokenList(this.tokens, firstTokenNode, this.tokens.Last);

            // Create and return the expression.
            NewArrayExpression expression = new NewArrayExpression(partialTokens, type as ArrayAccessExpression, initializer);
            expressionReference.Target = expression;

            return expression;
        }
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="newArrayExpression">
        /// The new array expression.
        /// </param>
        private void Save(NewArrayExpression newArrayExpression)
        {
            this.cppWriter.Write("new ");
            @switch(newArrayExpression.Type);

            if (newArrayExpression.Initializer != null)
            {
                @switch(newArrayExpression.Initializer);
            }
        }