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

            this.type = type;
            this.AddExpression(type);
        }
        /// <summary>
        /// Initializes a new instance of the StackallocExpression class.
        /// </summary>
        /// <param name="tokens">
        /// The list of tokens that form the expression.
        /// </param>
        /// <param name="type">
        /// The array type.
        /// </param>
        internal StackallocExpression(CsTokenList tokens, ArrayAccessExpression type)
            : base(ExpressionType.Stackalloc, tokens)
        {
            Param.AssertNotNull(tokens, "tokens");
            Param.AssertNotNull(type, "type");

            this.type = type;
            this.AddExpression(type);
        }
Example #3
0
        /// <summary>
        /// Checks an array access expression to make that the parameters are positioned correctly.
        /// </summary>
        /// <param name="element">
        /// The element containing the expression.
        /// </param>
        /// <param name="expression">
        /// The expression to check.
        /// </param>
        private void CheckIndexerAccessParameters(CsElement element, ArrayAccessExpression expression)
        {
            Param.AssertNotNull(element, "element");
            Param.AssertNotNull(expression, "expression");

            if (expression.Tokens.First != null && !expression.Tokens.First.Value.Generated)
            {
                ArgumentList argumentList       = new ArgumentList(expression.Arguments);
                CsTokenList  argumentListTokens = GetArgumentListTokens(
                    expression.Tokens, expression.Array.Tokens.Last, CsTokenType.OpenSquareBracket, CsTokenType.CloseSquareBracket);

                if (argumentListTokens != null)
                {
                    this.CheckParameters(
                        element, argumentListTokens, argumentList, expression.LineNumber, CsTokenType.OpenSquareBracket, CsTokenType.CloseSquareBracket, "indexer");
                }
            }
        }
        /// <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);
            }
        }
Example #5
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);
            }
        }
        /// <summary>
        /// Checks the given expression.
        /// </summary>
        /// <param name="expression">
        /// The expression being visited.
        /// </param>
        /// <param name="parentExpression">
        /// The parent expression, if any.
        /// </param>
        /// <param name="parentStatement">
        /// The parent statement, if any.
        /// </param>
        /// <param name="parentElement">
        /// The parent element, if any.
        /// </param>
        /// <param name="context">
        /// The optional visitor context data.
        /// </param>
        /// <returns>
        /// Returns true to continue, or false to stop the walker.
        /// </returns>
        private bool ProcessExpression(Expression expression, Expression parentExpression, Statement parentStatement, CsElement parentElement, object context)
        {
            Param.AssertNotNull(expression, "expression");
            Param.Ignore(parentExpression);
            Param.Ignore(parentStatement);
            Param.AssertNotNull(parentElement, "parentElement");
            Param.Ignore(context);

            if (!parentElement.Generated)
            {
                switch (expression.ExpressionType)
                {
                case ExpressionType.Query:
                    this.CheckQueryExpression(parentElement, (QueryExpression)expression);
                    break;

                case ExpressionType.MethodInvocation:
                    this.CheckMethodInvocationParameters(parentElement, (MethodInvocationExpression)expression);
                    break;

                case ExpressionType.MemberAccess:
                    this.CheckBuiltInTypeForMemberAccessExpressions(((MemberAccessExpression)expression).LeftHandSide.Tokens.First);
                    break;

                case ExpressionType.ArrayAccess:

                    // Calling this[x] shows up as an ArrayAccessExpression.
                    ArrayAccessExpression a = (ArrayAccessExpression)expression;
                    if (a.Array.Text == "this")
                    {
                        this.CheckIndexerAccessParameters(parentElement, (ArrayAccessExpression)expression);
                    }

                    break;
                }
            }

            return(true);
        }
        /// <summary>
        /// Reads an array access expression.
        /// </summary>
        /// <param name="array">
        /// The array being accessed.
        /// </param>
        /// <param name="previousPrecedence">
        /// The precedence of the previous expression.
        /// </param>
        /// <param name="unsafeCode">
        /// Indicates whether the code being parsed resides in an unsafe code block.
        /// </param>
        /// <returns>
        /// Returns the expression.
        /// </returns>
        private ArrayAccessExpression GetArrayAccessExpression(Expression array, ExpressionPrecedence previousPrecedence, bool unsafeCode)
        {
            Param.AssertNotNull(array, "array");
            Param.Ignore(previousPrecedence);
            Param.Ignore(unsafeCode);

            ArrayAccessExpression expression = null;

            if (CheckPrecedence(previousPrecedence, ExpressionPrecedence.Primary))
            {
                Reference<ICodePart> expressionReference = new Reference<ICodePart>();

                // The next symbol will be the opening bracket.
                Bracket openingBracket = this.GetBracketToken(CsTokenType.OpenSquareBracket, SymbolType.OpenSquareBracket, expressionReference);
                Node<CsToken> openingBracketNode = this.tokens.InsertLast(openingBracket);

                // Get the argument list now.
                IList<Argument> argumentList = this.GetArgumentList(SymbolType.CloseSquareBracket, expressionReference, unsafeCode);

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

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

                // Pull out the first token from the array.
                Node<CsToken> firstTokenNode = array.Tokens.First;

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

                // Create and return the expression.
                expression = new ArrayAccessExpression(partialTokens, array, argumentList);
                expressionReference.Target = expression;
            }

            return expression;
        }
 /// <summary>
 /// The save.
 /// </summary>
 /// <param name="arrayAccessExpression">
 /// The array access expression.
 /// </param>
 private void Save(ArrayAccessExpression arrayAccessExpression)
 {
     @switch(arrayAccessExpression.Array);
     this.cppWriter.Write("[");
     this.Save(arrayAccessExpression.Arguments);
     this.cppWriter.Write("]");
 }
        /// <summary>
        /// Checks an array access expression to make that the parameters are positioned correctly.
        /// </summary>
        /// <param name="element">
        /// The element containing the expression.
        /// </param>
        /// <param name="expression">
        /// The expression to check.
        /// </param>
        private void CheckIndexerAccessParameters(CsElement element, ArrayAccessExpression expression)
        {
            Param.AssertNotNull(element, "element");
            Param.AssertNotNull(expression, "expression");

            if (expression.Tokens.First != null && !expression.Tokens.First.Value.Generated)
            {
                ArgumentList argumentList = new ArgumentList(expression.Arguments);
                CsTokenList argumentListTokens = GetArgumentListTokens(
                    expression.Tokens, expression.Array.Tokens.Last, CsTokenType.OpenSquareBracket, CsTokenType.CloseSquareBracket);

                if (argumentListTokens != null)
                {
                    this.CheckParameters(
                        element, argumentListTokens, argumentList, expression.LineNumber, CsTokenType.OpenSquareBracket, CsTokenType.CloseSquareBracket, "indexer");
                }
            }
        }