Exemplo n.º 1
0
        private BaseExpressionSyntax ParseCoreExpression()
        {
            var expression = this.ParseTerminalExpression();

            while (this.index < this.tokens.Count)
            {
                switch (this.Peek())
                {
                case TokenKind.Dot:
                    var dotToken        = this.Eat(TokenKind.Dot);
                    var identifierToken = this.Eat(TokenKind.Identifier);
                    expression = new ObjectAccessExpressionSyntax(expression, dotToken, identifierToken);
                    break;

                case TokenKind.LeftBracket:
                    var leftBracketToken  = this.Eat(TokenKind.LeftBracket);
                    var indexExpression   = this.ParseBaseExpression();
                    var rightBracketToken = this.Eat(TokenKind.RightBracket);
                    expression = new ArrayAccessExpressionSyntax(expression, leftBracketToken, indexExpression, rightBracketToken);
                    break;

                case TokenKind.LeftParen:
                    var leftParenToken  = this.Eat(TokenKind.LeftParen);
                    var arguments       = this.ParseArguments();
                    var rightParenToken = this.Eat(TokenKind.RightParen);
                    expression = new InvocationExpressionSyntax(expression, leftParenToken, arguments, rightParenToken);
                    break;

                default:
                    return(expression);
                }
            }

            return(expression);
        }
Exemplo n.º 2
0
 public virtual void Visit(ArrayAccessExpressionSyntax arrayAccessExpressionSyntax)
 {
     Visit(arrayAccessExpressionSyntax.Owner);
     foreach (var expressionSyntax in arrayAccessExpressionSyntax.Parameter)
     {
         Visit(expressionSyntax);
     }
 }
Exemplo n.º 3
0
 public override void Visit(ArrayAccessExpressionSyntax pNode)
 {
     if (!pNode.Identifier.Type.IsArray && pNode.Identifier.Type != SmallType.String)
     {
         Compiler.ReportError("Array access used on non array");
     }
     base.Visit(pNode);
 }
Exemplo n.º 4
0
        public BoundArrayAccessExpression(ArrayAccessExpressionSyntax syntax, bool hasValue, bool hasErrors, string name, IReadOnlyList <BaseBoundExpression> indices)
            : base(hasValue, hasErrors)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!name.IsDefault(), "'name' must not be null.");
            Debug.Assert(!indices.IsDefault(), "'indices' must not be null.");

            this.Syntax  = syntax;
            this.Name    = name;
            this.Indices = indices;
        }
Exemplo n.º 5
0
        public override SyntaxNode Visit(ArrayAccessExpressionSyntax pNode)
        {
            var n = pNode.Identifier.Accept <IdentifierSyntax>(this);

            ExpressionSyntax i = null;

            using (new ContextValue(this, "MemberContext", new MemberAccessContext()))
            {
                i = pNode.Index.Accept <ExpressionSyntax>(this);
            }

            return(SyntaxFactory.ArrayAccessExpression(n, i));
        }
Exemplo n.º 6
0
        private BaseBoundExpression BindArrayAccessExpression(ArrayAccessExpressionSyntax syntax)
        {
            BaseBoundExpression baseExpression  = this.BindExpression(syntax.BaseExpression);
            BaseBoundExpression indexExpression = this.BindExpression(syntax.IndexExpression);

            string arrayName;
            List <BaseBoundExpression> indices = new List <BaseBoundExpression>();
            bool hasErrors = baseExpression.HasErrors || indexExpression.HasErrors;

            switch (baseExpression)
            {
            case BoundArrayAccessExpression arrayAccess:
            {
                arrayName = arrayAccess.Name;
                indices.AddRange(arrayAccess.Indices);
                indices.Add(indexExpression);
                break;
            }

            case BoundVariableExpression variable:
            {
                arrayName = variable.Name;
                indices.Add(indexExpression);
                break;
            }

            default:
            {
                if (!hasErrors)
                {
                    hasErrors = true;
                    this.diagnostics.ReportUnsupportedArrayBaseExpression(syntax.BaseExpression.Range);
                }

                return(new BoundInvalidExpression(syntax, hasValue: true, hasErrors));
            }
            }

            return(new BoundArrayAccessExpression(syntax, hasValue: true, hasErrors, arrayName, indices));
        }
Exemplo n.º 7
0
 public BoundArrayAccessExpression(List<BoundExpression> parameter, ArrayAccessExpressionSyntax syntax, IType type)
     : base(syntax, type)
 {
     Parameter = parameter;
 }
Exemplo n.º 8
0
        private BoundArrayAccessExpression BindArrayAccessExpression(ArrayAccessExpressionSyntax syntax)
        {
            var boundExpression = BindExpression(syntax.Owner);
            Ensure(() => boundExpression.Type is ArrayCompilerGeneratedType, $"{boundExpression.Type} is no array");

            var arrayType = (ArrayCompilerGeneratedType)boundExpression.Type;

            var elementType = arrayType.Type;
            var boundParameter = syntax.Parameter.Select(x => BindExpression(x)).ToList();

            Ensure(() => boundParameter.Count == arrayType.Dimension, $"Parameter count ({boundParameter.Count}) must match array dimension count ({arrayType.Dimension})");
            return new BoundArrayAccessExpression(boundParameter, syntax, elementType );
        }