/// <summary>
 /// Initializes a new instance of <see cref="ExceptionHandlingStatement" /> for the specified try, catch and finally blocks.
 /// </summary>
 /// <param name="tryBlock">The try block of the statement.</param>
 /// <param name="catchVariable">The variable that contains the exception for the catch block.</param>
 /// <param name="catchBlock">The catch block of the statement.</param>
 /// <param name="finallyBlock">The finally block of the statement.</param>
 public ExceptionHandlingStatement(CompoundStatement tryBlock, IdentifierExpression catchVariable, CompoundStatement catchBlock, CompoundStatement finallyBlock)
 {
     _tryBlock = tryBlock;
     _catchVariable = catchVariable;
     _catchBlock = catchBlock;
     _finallyBlock = finallyBlock;
 }
 /// <summary>
 /// Initializes a new instance of <see cref="ExceptionHandlingStatement" /> for the specified try, catch and finally blocks.
 /// </summary>
 /// <param name="tryBlock">The try block of the statement.</param>
 /// <param name="catchVariable">The variable that contains the exception for the catch block.</param>
 /// <param name="catchBlock">The catch block of the statement.</param>
 /// <param name="finallyBlock">The finally block of the statement.</param>
 public ExceptionHandlingStatement(CompoundStatement tryBlock, IdentifierExpression catchVariable, CompoundStatement catchBlock, CompoundStatement finallyBlock)
 {
     _tryBlock      = tryBlock;
     _catchVariable = catchVariable;
     _catchBlock    = catchBlock;
     _finallyBlock  = finallyBlock;
 }
        /// <summary>
        /// Creates a new instance of <see cref="ExceptionHandlingStatement" /> by copying the <see cref="ExceptionHandlingStatement.TryBlock" /> 
        /// and <see cref="ExceptionHandlingStatement.FinallyBlock" /> from the specified statement, and adding the specified expression and statements to the <see cref="ExceptionHandlingStatement.CatchBlock" />.
        /// </summary>
        /// <param name="statement">The statement from which to copy the <see cref="ExceptionHandlingStatement.TryBlock" /> and <see cref="ExceptionHandlingStatement.FinallyBlock" /> properties.</param>
        /// <param name="expression">The expression to set in the Catch block.</param>
        /// <param name="block">The block to use as the Catch block.</param>
        /// <returns>a new instance of <see cref="ExceptionHandlingStatement" />.</returns>
        public static ExceptionHandlingStatement Catch(this ExceptionHandlingStatement statement, IdentifierExpression expression, CompoundStatement block)
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }

            return new ExceptionHandlingStatement(statement.TryBlock, expression, block, statement.FinallyBlock);
        }
        /// <summary>
        /// Initializes a new instance of <see cref="FunctionExpression" /> for the specified name, parameters and body.
        /// </summary>
        /// <param name="name">The name of the function, if not anonymous.</param>
        /// <param name="parameters">The parameters that the function expects.</param>
        /// <param name="body">The body of the function.</param>
        public FunctionExpression(IdentifierExpression name, IEnumerable<IdentifierExpression> parameters, CompoundStatement body)
        {
            _name = name;
            _body = body;

            if (parameters != null)
            {
                _parameters.AddRange(parameters);
            }
        }
        /// <summary>
        /// Initializes a new instance of <see cref="FunctionExpression" /> for the specified name, parameters and body.
        /// </summary>
        /// <param name="name">The name of the function, if not anonymous.</param>
        /// <param name="parameters">The parameters that the function expects.</param>
        /// <param name="body">The body of the function.</param>
        public FunctionExpression(IdentifierExpression name, IEnumerable <IdentifierExpression> parameters, CompoundStatement body)
        {
            _name = name;
            _body = body;

            if (parameters != null)
            {
                _parameters.AddRange(parameters);
            }
        }
        /// <summary>
        /// Returns either an instance of <see cref="CompoundStatement" /> containing the statements, the only statement, or an empty statement depending on the
        /// number of statements specified.
        /// </summary>
        /// <param name="statements">A sequence of statements to conditionally wrap in a BlockStatement</param>
        /// <returns>Either an instance of <see cref="CompoundStatement" />, a single statement or an EmptyStatement object.</returns>
        /// <remarks>
        /// The return type of this method depends on the number of inputs.
        /// If the input is null or empty, an instance of <see cref="EmptyStatement" /> is returned.
        /// If the input has one statement, that statement is returned.
        /// If the input has more than one statement, a new instance of <see cref="CompoundStatement" /> containing those statements is returned.
        /// </remarks>
        public static Statement BlockOrStatement(IEnumerable <Statement> statements)
        {
            Statement result;

            if (statements.Count() > 1)
            {
                result = new CompoundStatement(statements);
            }
            else if (statements.Count() > 0)
            {
                result = statements.First();
            }
            else
            {
                result = Empty();
            }

            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new instance of <see cref="ExceptionHandlingStatement" /> by copying the <see cref="ExceptionHandlingStatement.TryBlock" />
        /// and <see cref="ExceptionHandlingStatement.FinallyBlock" /> from the specified statement, and adding the specified expression and statements to the <see cref="ExceptionHandlingStatement.CatchBlock" />.
        /// </summary>
        /// <param name="statement">The statement from which to copy the <see cref="ExceptionHandlingStatement.TryBlock" /> and <see cref="ExceptionHandlingStatement.FinallyBlock" /> properties.</param>
        /// <param name="expression">The expression to set in the Catch block.</param>
        /// <param name="block">The block to use as the Catch block.</param>
        /// <returns>a new instance of <see cref="ExceptionHandlingStatement" />.</returns>
        public static ExceptionHandlingStatement Catch(this ExceptionHandlingStatement statement, IdentifierExpression expression, CompoundStatement block)
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }

            return(new ExceptionHandlingStatement(statement.TryBlock, expression, block, statement.FinallyBlock));
        }
Beispiel #8
0
        /// <summary>
        /// Creates a new instance of <see cref="ExceptionHandlingStatement" /> by copying the <see cref="ExceptionHandlingStatement.TryBlock" />, <see cref="ExceptionHandlingStatement.CatchVariable" />
        /// and <see cref="ExceptionHandlingStatement.CatchBlock" /> from the specified statement, and adding the specified statements to the <see cref="ExceptionHandlingStatement.FinallyBlock" />.
        /// </summary>
        /// <param name="statement">The statement from which to copy the <see cref="ExceptionHandlingStatement.TryBlock" /> and <see cref="ExceptionHandlingStatement.CatchBlock" /> properties.</param>
        /// <param name="block">The block to use as the Catch block.</param>
        /// <returns>a new instance of <see cref="ExceptionHandlingStatement" />.</returns>
        public static ExceptionHandlingStatement Finally(this ExceptionHandlingStatement statement, CompoundStatement block)
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }

            return(new ExceptionHandlingStatement(statement.TryBlock, statement.CatchVariable, statement.CatchBlock, block));
        }
Beispiel #9
0
 /// <summary>
 /// Creates a new instance of <see cref="ExceptionHandlingStatement" />.
 /// </summary>
 /// <param name="block">The instance of <see cref="CompoundStatement" /> to use for the try block.</param>
 /// <returns>a new instance of <see cref="ExceptionHandlingStatement" />.</returns>
 public static ExceptionHandlingStatement Try(CompoundStatement block)
 {
     return new ExceptionHandlingStatement(block, null, null, null);
 }
Beispiel #10
0
        /// <summary>
        /// Returns either an instance of <see cref="CompoundStatement" /> containing the statements, the only statement, or an empty statement depending on the 
        /// number of statements specified.
        /// </summary>
        /// <param name="statements">A sequence of statements to conditionally wrap in a BlockStatement</param>
        /// <returns>Either an instance of <see cref="CompoundStatement" />, a single statement or an EmptyStatement object.</returns>
        /// <remarks>
        /// The return type of this method depends on the number of inputs. 
        /// If the input is null or empty, an instance of <see cref="EmptyStatement" /> is returned.
        /// If the input has one statement, that statement is returned.
        /// If the input has more than one statement, a new instance of <see cref="CompoundStatement" /> containing those statements is returned.
        /// </remarks>
        public static Statement BlockOrStatement(IEnumerable<Statement> statements)
        {
            Statement result;

            if (statements.Count() > 1)
            {
                result = new CompoundStatement(statements);
            }
            else if (statements.Count() > 0)
            {
                result = statements.First();
            }
            else
            {
                result = Empty();
            }

            return result;
        }
 /// <summary>
 /// Creates a new instance of <see cref="ExceptionHandlingStatement" />.
 /// </summary>
 /// <param name="block">The instance of <see cref="CompoundStatement" /> to use for the try block.</param>
 /// <returns>a new instance of <see cref="ExceptionHandlingStatement" />.</returns>
 public static ExceptionHandlingStatement Try(CompoundStatement block)
 {
     return(new ExceptionHandlingStatement(block, null, null, null));
 }
        /// <summary>
        /// Creates a new instance of <see cref="ExceptionHandlingStatement" /> by copying the <see cref="ExceptionHandlingStatement.TryBlock" />, <see cref="ExceptionHandlingStatement.CatchVariable" /> 
        /// and <see cref="ExceptionHandlingStatement.CatchBlock" /> from the specified statement, and adding the specified statements to the <see cref="ExceptionHandlingStatement.FinallyBlock" />.
        /// </summary>
        /// <param name="statement">The statement from which to copy the <see cref="ExceptionHandlingStatement.TryBlock" /> and <see cref="ExceptionHandlingStatement.CatchBlock" /> properties.</param>
        /// <param name="block">The block to use as the Catch block.</param>
        /// <returns>a new instance of <see cref="ExceptionHandlingStatement" />.</returns>
        public static ExceptionHandlingStatement Finally(this ExceptionHandlingStatement statement, CompoundStatement block)
        {
            if (statement == null)
            {
                throw new ArgumentNullException("statement");
            }

            return new ExceptionHandlingStatement(statement.TryBlock, statement.CatchVariable, statement.CatchBlock, block);
        }