示例#1
0
        /// <summary>
        /// Initializes a new instance of the FinallyStatement class.
        /// </summary>
        /// <param name="proxy">Proxy object for the statement.</param>
        /// <param name="tryStatement">The try-statement that this finally-statement is embedded to.</param>
        /// <param name="body">The body of the finally-statement.</param>
        internal FinallyStatement(CodeUnitProxy proxy, TryStatement tryStatement, BlockStatement body)
            : base(proxy, StatementType.Finally)        
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.AssertNotNull(body, "body");

            this.tryStatement.Value = tryStatement;
            this.body.Value = body;
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the CatchStatement class.
        /// </summary>
        /// <param name="proxy">Proxy object for the statement.</param>
        /// <param name="tryStatement">The try-statement that this catch-statement is attached to.</param>
        /// <param name="classExpression">The inner expression.</param>
        /// <param name="body">The body of the catch-statement.</param>
        internal CatchStatement(
            CodeUnitProxy proxy,
            TryStatement tryStatement,
            Expression classExpression,
            BlockStatement body)
            : base(proxy, StatementType.Catch)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.Ignore(classExpression);
            Param.AssertNotNull(body, "body");

            this.tryStatement.Value    = tryStatement;
            this.catchExpression.Value = classExpression;
            this.body.Value            = body;
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the CatchStatement class.
        /// </summary>
        /// <param name="proxy">Proxy object for the statement.</param>
        /// <param name="tryStatement">The try-statement that this catch-statement is attached to.</param>
        /// <param name="classExpression">The inner expression.</param>
        /// <param name="body">The body of the catch-statement.</param>
        internal CatchStatement(
            CodeUnitProxy proxy,
            TryStatement tryStatement,
            Expression classExpression,
            BlockStatement body)
            : base(proxy, StatementType.Catch)
        {
            Param.AssertNotNull(proxy, "proxy");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.Ignore(classExpression);
            Param.AssertNotNull(body, "body");

            this.tryStatement.Value = tryStatement;
            this.catchExpression.Value = classExpression;
            this.body.Value = body;
        }
        /// <summary>
        /// Looks for a finally-statement, and if it is found, parses and returns it.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <param name="tryStatement">The parent try statement.</param>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the statement.</returns>
        private FinallyStatement GetAttachedFinallyStatement(CodeUnitProxy parentProxy, TryStatement tryStatement, bool unsafeCode)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.Ignore(unsafeCode);

            FinallyStatement finallyStatement = null;

            // Look for a finally keyword.
            Symbol symbol = this.PeekNextSymbol();
            if (symbol.SymbolType == SymbolType.Finally)
            {
                this.AdvanceToNextCodeSymbol(parentProxy);
                var statementProxy = new CodeUnitProxy(this.document);

                // Move up to the finally keyword and add it.
                this.GetToken(statementProxy, TokenType.Finally, SymbolType.Finally);

                // Get the embedded statement. This must be a block statement.
                BlockStatement childStatement = this.GetNextStatement(statementProxy, unsafeCode) as BlockStatement;
                if (childStatement == null)
                {
                    throw this.CreateSyntaxException();
                }

                // Create and return the finally statement.
                finallyStatement = new FinallyStatement(statementProxy, tryStatement, childStatement);
                parentProxy.Children.Add(finallyStatement);
            }

            return finallyStatement;
        }
        /// <summary>
        /// Looks for a catch-statement, and if it is found, parses and returns it.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <param name="tryStatement">The parent try statement.</param>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the statement.</returns>
        private CatchStatement GetAttachedCatchStatement(CodeUnitProxy parentProxy, TryStatement tryStatement, bool unsafeCode)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.AssertNotNull(tryStatement, "tryStatement");
            Param.Ignore(unsafeCode);

            CatchStatement catchStatement = null;

            // Look for a catch keyword.
            Symbol symbol = this.PeekNextSymbol();
            if (symbol.SymbolType == SymbolType.Catch)
            {
                this.AdvanceToNextCodeSymbol(parentProxy);
                var statementProxy = new CodeUnitProxy(this.document);

                // Move up to the catch keyword and add it.
                this.GetToken(statementProxy, TokenType.Catch, SymbolType.Catch);

                Expression catchExpression = null;

                // Get the opening parenthesis, if there is one.
                symbol = this.PeekNextSymbol();
                if (symbol.SymbolType == SymbolType.OpenParenthesis)
                {
                    BracketToken openParenthesis = (BracketToken)this.GetToken(statementProxy, TokenType.OpenParenthesis, SymbolType.OpenParenthesis);

                    // Get the type, if there is one.
                    symbol = this.PeekNextSymbol();
                    if (symbol.SymbolType == SymbolType.Other)
                    {
                        catchExpression = this.GetNextExpression(statementProxy, ExpressionPrecedence.None, unsafeCode, true, true);
                    }

                    // Get the closing parenthesis.
                    BracketToken closeParenthesis = (BracketToken)this.GetToken(statementProxy, TokenType.CloseParenthesis, SymbolType.CloseParenthesis);

                    openParenthesis.MatchingBracket = closeParenthesis;
                    closeParenthesis.MatchingBracket = openParenthesis;
                }

                // Get the embedded statement. This must be a block statement.
                BlockStatement childStatement = this.GetNextStatement(statementProxy, unsafeCode) as BlockStatement;
                if (childStatement == null)
                {
                    throw this.CreateSyntaxException();
                }

                // Create the catch statement.
                catchStatement = new CatchStatement(statementProxy, tryStatement, catchExpression, childStatement);
                parentProxy.Children.Add(catchStatement);
            }

            return catchStatement;
        }
        /// <summary>
        /// Reads the next try-statement from the file and returns it.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the statement.</returns>
        private TryStatement GetTryStatement(CodeUnitProxy parentProxy, bool unsafeCode)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.Ignore(unsafeCode);

            var statementProxy = new CodeUnitProxy(this.document);
            
            // Move past the try keyword.
            this.GetToken(statementProxy, TokenType.Try, SymbolType.Try);

            // Get the embedded statement. It must be a block statement.
            BlockStatement childStatement = this.GetNextStatement(statementProxy, unsafeCode) as BlockStatement;
            if (childStatement == null)
            {
                throw this.CreateSyntaxException();
            }

            // Create the try-statement now.
            var statement = new TryStatement(statementProxy, childStatement);
            parentProxy.Children.Add(statement);

            // Get the attached catch statements, if any.
            while (true)
            {
                CatchStatement catchStatement = this.GetAttachedCatchStatement(parentProxy, statement, unsafeCode);
                if (catchStatement == null)
                {
                    break;
                }
            }

            // Get the attached finally statement, if any.
            this.GetAttachedFinallyStatement(parentProxy, statement, unsafeCode);

            // Return the statement.
            return statement;
        }