예제 #1
0
        /// <summary>
        /// Initializes a new instance of the NewArrayExpression class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the expression.
        /// </param>
        /// <param name="type">
        /// The array type.
        /// </param>
        /// <param name="initializer">
        /// The array initializer expression.
        /// </param>
        internal NewArrayExpression(CsTokenList tokens, ArrayAccessExpression type, ArrayInitializerExpression initializer)
            : base(ExpressionType.NewArray, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.Ignore(type, "type");
            Param.Ignore(initializer);

            this.type        = type;
            this.initializer = initializer;

            if (type != null)
            {
                this.AddExpression(type);
            }

            if (initializer != null)
            {
                this.AddExpression(initializer);
            }
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the NewArrayExpression class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the expression.
        /// </param>
        /// <param name="type">
        /// The array type.
        /// </param>
        /// <param name="initializer">
        /// The array initializer expression.
        /// </param>
        internal NewArrayExpression(CsTokenList tokens, ArrayAccessExpression type, ArrayInitializerExpression initializer)
            : base(ExpressionType.NewArray, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.Ignore(type, "type");
            Param.Ignore(initializer);

            this.type = type;
            this.initializer = initializer;

            if (type != null)
            {
                this.AddExpression(type);
            }

            if (initializer != null)
            {
                this.AddExpression(initializer);
            }
        }
예제 #3
0
        /// <summary>
        /// Reads an array initializer expression.
        /// </summary>
        /// <param name="unsafeCode">
        /// Indicates whether the code being parsed resides in an unsafe code block.
        /// </param>
        /// <returns>
        /// Returns the expression.
        /// </returns>
        private ArrayInitializerExpression GetArrayInitializerExpression(bool unsafeCode)
        {
            Param.Ignore(unsafeCode);

            Reference<ICodePart> expressionReference = new Reference<ICodePart>();

            // Get the first symbol and make sure it is an opening curly bracket.
            Bracket openingBracket = this.GetBracketToken(CsTokenType.OpenCurlyBracket, SymbolType.OpenCurlyBracket, expressionReference);
            Node<CsToken> openingBracketNode = this.tokens.InsertLast(openingBracket);

            // Get each of the initializers.
            List<Expression> initializers = new List<Expression>();

            while (true)
            {
                // If this initializer starts with an opening curly bracket, it is another
                // array initializer expression. Otherwise, parse it like a normal expression.
                Symbol symbol = this.GetNextSymbol(expressionReference);

                if (symbol.SymbolType == SymbolType.OpenCurlyBracket)
                {
                    initializers.Add(this.GetArrayInitializerExpression(unsafeCode));
                }
                else if (symbol.SymbolType == SymbolType.CloseCurlyBracket)
                {
                    break;
                }
                else
                {
                    initializers.Add(this.GetNextExpression(ExpressionPrecedence.None, expressionReference, unsafeCode));
                }

                // Now check the type of the next symbol and see if it is a comma.
                symbol = this.GetNextSymbol(expressionReference);

                if (symbol.SymbolType == SymbolType.Comma)
                {
                    // Add the comma and advance.
                    this.tokens.Add(this.GetToken(CsTokenType.Comma, SymbolType.Comma, expressionReference));
                }
            }

            // Add the closing curly bracket.
            Bracket closingBracket = this.GetBracketToken(CsTokenType.CloseCurlyBracket, SymbolType.CloseCurlyBracket, expressionReference);
            Node<CsToken> closingBracketNode = this.tokens.InsertLast(closingBracket);

            openingBracket.MatchingBracketNode = closingBracketNode;
            closingBracket.MatchingBracketNode = openingBracketNode;

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

            // Return the expression.
            ArrayInitializerExpression expression = new ArrayInitializerExpression(partialTokens, initializers.ToArray());
            expressionReference.Target = expression;

            return expression;
        }
        /// <summary>
        /// The save.
        /// </summary>
        /// <param name="arrayInitializerExpression">
        /// The array initializer expression.
        /// </param>
        private void Save(ArrayInitializerExpression arrayInitializerExpression)
        {
            this.cppWriter.WriteLine();
            this.cppWriter.WriteLine("{");

            this.cppWriter.Indent++;

            this.Save(arrayInitializerExpression.Initializers, this.cppWriter);

            this.cppWriter.Indent--;

            this.cppWriter.WriteLine();
            this.cppWriter.Write("}");
        }