Beispiel #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);
        }
        public BoundLibraryEventExpression(ObjectAccessExpressionSyntax syntax, bool hasValue, bool hasErrors, BoundLibraryTypeExpression library, string name)
            : base(hasValue, hasErrors)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!library.IsDefault(), "'library' must not be null.");
            Debug.Assert(!name.IsDefault(), "'name' must not be null.");

            this.Syntax  = syntax;
            this.Library = library;
            this.Name    = name;
        }
Beispiel #3
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));
            }
        }