Esempio n. 1
0
        private BoundIfStatement BindIfStatement(IfStatementSyntax syntax)
        {
            BaseBoundExpression ifExpression = this.BindExpression(syntax.IfPart.Condition);
            BoundStatementBlock ifBody       = this.BindStatementBlock(syntax.IfPart.Body);
            BoundIfPart         ifPart       = new BoundIfPart(syntax.IfPart, ifExpression, ifBody);

            List <BoundElseIfPart> elseIfParts = new List <BoundElseIfPart>();

            foreach (var part in syntax.ElseIfParts)
            {
                BaseBoundExpression elseIfExpression = this.BindExpression(part.Condition);
                BoundStatementBlock elseIfBody       = this.BindStatementBlock(part.Body);
                elseIfParts.Add(new BoundElseIfPart(part, elseIfExpression, elseIfBody));
            }

            BoundElsePart elsePart = null;

            if (!syntax.ElsePartOpt.IsDefault())
            {
                BoundStatementBlock elseBody = this.BindStatementBlock(syntax.ElsePartOpt.Body);
                elsePart = new BoundElsePart(syntax.ElsePartOpt, elseBody);
            }

            return(new BoundIfStatement(syntax, ifPart, elseIfParts, elsePart));
        }
Esempio n. 2
0
        private BoundBinaryExpression BindBinaryOperatorExpression(BinaryOperatorExpressionSyntax syntax)
        {
            BaseBoundExpression left  = this.BindExpression(syntax.Left);
            BaseBoundExpression right = this.BindExpression(syntax.Right, expectsValue: !(left is BoundLibraryEventExpression));

            switch (syntax.OperatorToken.Kind)
            {
            case TokenKind.Or:
            case TokenKind.And:
            case TokenKind.NotEqual:
            case TokenKind.Equal:
            case TokenKind.LessThan:
            case TokenKind.GreaterThan:
            case TokenKind.LessThanOrEqual:
            case TokenKind.GreaterThanOrEqual:
            case TokenKind.Plus:
            case TokenKind.Minus:
            case TokenKind.Multiply:
            case TokenKind.Divide:
                return(new BoundBinaryExpression(syntax, hasValue: true, left.HasErrors || right.HasErrors, syntax.OperatorToken.Kind, left, right));

            default:
                throw ExceptionUtilities.UnexpectedValue(syntax.OperatorToken.Kind);
            }
        }
Esempio n. 3
0
        private BoundWhileStatement BindWhileStatement(WhileStatementSyntax syntax)
        {
            BaseBoundExpression expression = this.BindExpression(syntax.Condition);
            BoundStatementBlock body       = this.BindStatementBlock(syntax.Body);

            return(new BoundWhileStatement(syntax, expression, body));
        }
        public BoundInvalidExpressionStatement(ExpressionStatementSyntax syntax, BaseBoundExpression expression)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!expression.IsDefault(), "'expression' must not be null.");

            this.Syntax     = syntax;
            this.Expression = expression;
        }
        public BoundWhileStatement(WhileStatementSyntax syntax, BaseBoundExpression condition, BoundStatementBlock body)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!condition.IsDefault(), "'condition' must not be null.");
            Debug.Assert(!body.IsDefault(), "'body' must not be null.");

            this.Syntax    = syntax;
            this.Condition = condition;
            this.Body      = body;
        }
Esempio n. 6
0
        private BoundUnaryExpression BindUnaryOperatorExpression(UnaryOperatorExpressionSyntax syntax)
        {
            BaseBoundExpression expression = this.BindExpression(syntax.Expression);

            switch (syntax.OperatorToken.Kind)
            {
            case TokenKind.Minus:
                return(new BoundUnaryExpression(syntax, hasValue: true, expression.HasErrors, syntax.OperatorToken.Kind, expression));

            default:
                throw ExceptionUtilities.UnexpectedValue(syntax.OperatorToken.Kind);
            }
        }
        public BoundForStatement(ForStatementSyntax syntax, string identifier, BaseBoundExpression fromExpression, BaseBoundExpression toExpression, BaseBoundExpression stepExpressionOpt, BoundStatementBlock body)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!identifier.IsDefault(), "'identifier' must not be null.");
            Debug.Assert(!fromExpression.IsDefault(), "'fromExpression' must not be null.");
            Debug.Assert(!toExpression.IsDefault(), "'toExpression' must not be null.");
            Debug.Assert(!body.IsDefault(), "'body' must not be null.");

            this.Syntax            = syntax;
            this.Identifier        = identifier;
            this.FromExpression    = fromExpression;
            this.ToExpression      = toExpression;
            this.StepExpressionOpt = stepExpressionOpt;
            this.Body = body;
        }
Esempio n. 8
0
        private BoundForStatement BindForStatement(ForStatementSyntax syntax)
        {
            string identifier = syntax.IdentifierToken.Text;

            BaseBoundExpression fromExpression = this.BindExpression(syntax.FromExpression);
            BaseBoundExpression toExpression   = this.BindExpression(syntax.ToExpression);

            BaseBoundExpression stepExpression = null;

            if (!syntax.StepClauseOpt.IsDefault())
            {
                stepExpression = this.BindExpression(syntax.StepClauseOpt.Expression);
            }

            BoundStatementBlock body = this.BindStatementBlock(syntax.Body);

            return(new BoundForStatement(syntax, identifier, fromExpression, toExpression, stepExpression, body));
        }
Esempio n. 9
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));
        }
Esempio n. 10
0
        private BaseBoundStatement BindExpressionStatement(ExpressionStatementSyntax syntax)
        {
            BaseBoundExpression expression = this.BindExpression(syntax.Expression, expectsValue: false);

            if (expression.HasErrors)
            {
                return(new BoundInvalidExpressionStatement(syntax, expression));
            }

            switch (expression)
            {
            case BoundBinaryExpression assignment when assignment.Kind == TokenKind.Equal:
            {
                return(this.BindAssignmentExpressionStatement(syntax, assignment));
            }

            case BoundLibraryMethodInvocationExpression methodInvocation:
            {
                return(new BoundLibraryMethodInvocationStatement(syntax, methodInvocation));
            }

            case BoundSubModuleInvocationExpression subModuleInvocation:
            {
                return(new BoundSubModuleInvocationStatement(syntax, subModuleInvocation));
            }
            }

            if (expression.HasValue)
            {
                this.diagnostics.ReportUnassignedExpressionStatement(syntax.Range);
            }
            else
            {
                this.diagnostics.ReportInvalidExpressionStatement(syntax.Range);
            }

            return(new BoundInvalidExpressionStatement(syntax, expression));
        }
Esempio n. 11
0
        private BaseBoundExpression BindObjectAccessExpression(ObjectAccessExpressionSyntax syntax, bool expectsValue)
        {
            BaseBoundExpression baseExpression = this.BindExpression(syntax.BaseExpression, expectsValue: false);
            string identifier = syntax.IdentifierToken.Text;
            bool   hasErrors  = baseExpression.HasErrors;

            if (baseExpression is BoundLibraryTypeExpression libraryTypeExpression)
            {
                Library library = Libraries.Types[libraryTypeExpression.Name];

                if (library.Properties.TryGetValue(identifier, out Property property))
                {
                    bool noGetter = property.Getter.IsDefault();

                    if (!hasErrors)
                    {
                        if (expectsValue && noGetter)
                        {
                            hasErrors = true;
                            this.diagnostics.ReportExpectedExpressionWithAValue(syntax.Range);
                        }
                        else if (property.IsDeprecated)
                        {
                            hasErrors = true;
                            this.diagnostics.ReportLibraryMemberDeprecatedFromOlderVersion(syntax.Range, library.Name, property.Name);
                        }
                        else if (property.NeedsDesktop && !this.isRunningOnDesktop)
                        {
                            hasErrors = true;
                            this.diagnostics.ReportLibraryMemberNeedsDesktop(syntax.Range, library.Name, property.Name);
                        }
                    }

                    return(new BoundLibraryPropertyExpression(syntax, hasValue: !noGetter, hasErrors, libraryTypeExpression, identifier));
                }

                if (library.Methods.TryGetValue(identifier, out Method method))
                {
                    if (!hasErrors)
                    {
                        if (expectsValue)
                        {
                            hasErrors = true;
                            this.diagnostics.ReportExpectedExpressionWithAValue(syntax.Range);
                        }
                        else if (method.IsDeprecated)
                        {
                            hasErrors = true;
                            this.diagnostics.ReportLibraryMemberDeprecatedFromOlderVersion(syntax.Range, library.Name, method.Name);
                        }
                        else if (method.NeedsDesktop && !this.isRunningOnDesktop)
                        {
                            hasErrors = true;
                            this.diagnostics.ReportLibraryMemberNeedsDesktop(syntax.Range, library.Name, method.Name);
                        }
                    }

                    return(new BoundLibraryMethodExpression(syntax, hasValue: false, hasErrors, libraryTypeExpression, identifier));
                }

                if (library.Events.ContainsKey(identifier))
                {
                    return(new BoundLibraryEventExpression(syntax, hasValue: false, hasErrors, libraryTypeExpression, identifier));
                }

                this.diagnostics.ReportLibraryMemberNotFound(syntax.Range, library.Name, identifier);
                return(new BoundInvalidExpression(syntax, hasValue: true, hasErrors: true));
            }
            else
            {
                this.diagnostics.ReportUnsupportedDotBaseExpression(syntax.BaseExpression.Range);
                return(new BoundInvalidExpression(syntax, hasValue: true, hasErrors: true));
            }
        }
Esempio n. 12
0
        public BoundUnaryExpression(UnaryOperatorExpressionSyntax syntax, bool hasValue, bool hasErrors, TokenKind kind, BaseBoundExpression expression)
            : base(hasValue, hasErrors)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!kind.IsDefault(), "'kind' must not be null.");
            Debug.Assert(!expression.IsDefault(), "'expression' must not be null.");

            this.Syntax     = syntax;
            this.Kind       = kind;
            this.Expression = expression;
        }
Esempio n. 13
0
        public BoundArrayAssignmentStatement(ExpressionStatementSyntax syntax, BoundArrayAccessExpression array, BaseBoundExpression expression)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!array.IsDefault(), "'array' must not be null.");
            Debug.Assert(!expression.IsDefault(), "'expression' must not be null.");

            this.Syntax     = syntax;
            this.Array      = array;
            this.Expression = expression;
        }
Esempio n. 14
0
        public BoundPropertyAssignmentStatement(ExpressionStatementSyntax syntax, BoundLibraryPropertyExpression property, BaseBoundExpression expression)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!property.IsDefault(), "'property' must not be null.");
            Debug.Assert(!expression.IsDefault(), "'expression' must not be null.");

            this.Syntax     = syntax;
            this.Property   = property;
            this.Expression = expression;
        }
Esempio n. 15
0
        public BoundVariableAssignmentStatement(ExpressionStatementSyntax syntax, BoundVariableExpression variable, BaseBoundExpression expression)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!variable.IsDefault(), "'variable' must not be null.");
            Debug.Assert(!expression.IsDefault(), "'expression' must not be null.");

            this.Syntax     = syntax;
            this.Variable   = variable;
            this.Expression = expression;
        }
Esempio n. 16
0
        private BoundParenthesisExpression BindParenthesisExpression(ParenthesisExpressionSyntax syntax)
        {
            BaseBoundExpression expression = this.BindExpression(syntax.Expression);

            return(new BoundParenthesisExpression(syntax, hasValue: true, expression.HasErrors, expression));
        }
Esempio n. 17
0
        public BoundBinaryExpression(BinaryOperatorExpressionSyntax syntax, bool hasValue, bool hasErrors, TokenKind kind, BaseBoundExpression left, BaseBoundExpression right)
            : base(hasValue, hasErrors)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!kind.IsDefault(), "'kind' must not be null.");
            Debug.Assert(!left.IsDefault(), "'left' must not be null.");
            Debug.Assert(!right.IsDefault(), "'right' must not be null.");

            this.Syntax = syntax;
            this.Kind   = kind;
            this.Left   = left;
            this.Right  = right;
        }
Esempio n. 18
0
        private BaseBoundExpression BindInvocationExpression(InvocationExpressionSyntax syntax, bool expectsValue)
        {
            BaseBoundExpression baseExpression = this.BindExpression(syntax.BaseExpression, expectsValue: false);
            bool hasErrors = baseExpression.HasErrors;
            List <BaseBoundExpression> arguments = new List <BaseBoundExpression>();

            foreach (ArgumentSyntax arg in syntax.Arguments)
            {
                BaseBoundExpression argument = this.BindExpression(arg.Expression);
                hasErrors |= argument.HasErrors;
                arguments.Add(argument);
            }

            switch (baseExpression)
            {
            case BoundLibraryMethodExpression libraryMethod:
            {
                Method method = Libraries.Types[libraryMethod.Library.Name].Methods[libraryMethod.Name];

                if (!hasErrors)
                {
                    if (arguments.Count != method.Parameters.Count)
                    {
                        hasErrors = true;
                        this.diagnostics.ReportUnexpectedArgumentsCount(syntax.Range, arguments.Count, method.Parameters.Count);
                    }
                    else if (expectsValue && !method.ReturnsValue)
                    {
                        hasErrors = true;
                        this.diagnostics.ReportExpectedExpressionWithAValue(syntax.Range);
                    }
                }

                return(new BoundLibraryMethodInvocationExpression(syntax, method.ReturnsValue, hasErrors, libraryMethod, arguments));
            }

            case BoundSubModuleExpression subModule:
            {
                if (!hasErrors)
                {
                    if (arguments.Count != 0)
                    {
                        hasErrors = true;
                        this.diagnostics.ReportUnexpectedArgumentsCount(syntax.Range, arguments.Count, 0);
                    }
                    else if (expectsValue)
                    {
                        hasErrors = true;
                        this.diagnostics.ReportExpectedExpressionWithAValue(syntax.Range);
                    }
                }

                return(new BoundSubModuleInvocationExpression(syntax, hasValue: false, hasErrors, subModule.Name));
            }

            default:
            {
                this.diagnostics.ReportUnsupportedInvocationBaseExpression(syntax.Range);
                return(new BoundInvalidExpression(syntax, hasValue: true, hasErrors: true));
            }
            }
        }
Esempio n. 19
0
        public BoundParenthesisExpression(ParenthesisExpressionSyntax syntax, bool hasValue, bool hasErrors, BaseBoundExpression expression)
            : base(hasValue, hasErrors)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!expression.IsDefault(), "'expression' must not be null.");

            this.Syntax     = syntax;
            this.Expression = expression;
        }