예제 #1
0
 public CodeTryCatchFinallyStatement(CodeStatement [] tryStatements,
                                     CodeCatchClause [] catchClauses,
                                     CodeStatement [] finallyStatements)
 {
     TryStatements.AddRange(tryStatements);
     CatchClauses.AddRange(catchClauses);
     FinallyStatements.AddRange(finallyStatements);
 }
예제 #2
0
 /// <summary>
 /// Creates a new object that is a copy of the current instance.
 /// </summary>
 /// <returns>A new object that is a copy of this instance.</returns>
 public override object Clone()
 {
     return(new TryCatchStatement()
     {
         Column = Column,
         Id = Id,
         Line = Line,
         StartOffset = StartOffset,
         NodeLength = NodeLength
     }
            .WithTryBody(TryStatements.ToArray())
            .WithCatchBody(CatchStatements.ToArray()));
 }
        protected override void GenerateInner(CodeGenerator generator, CodeStatementEmitOptions emitOptions)
        {
            generator.WriteBlankLineBeforeEnteringBlock();
            generator.Write(TokenType.Keyword, "try");
            generator.WriteOpeningBrace();
            generator.Indent++;
            generator.EnterLocalScope();
            TryStatements.ReserveLocals(generator, default(CodeStatementEmitOptions));
            TryStatements.Generate(generator, default(CodeStatementEmitOptions));
            generator.ExitLocalScope();
            generator.Indent--;

            foreach (var catchClause in CatchClauses)
            {
                generator.WriteMiddleClosingBrace();
                generator.Write(TokenType.Keyword, "catch");
                generator.Write(TokenType.Space, ' ');
                generator.Write(TokenType.Punctuation, '(');
                catchClause.CatchExceptionType.Generate(generator);
                generator.Write(TokenType.Space, ' ');
                generator.OutputIdentifier(TokenType.Identifier, catchClause.LocalName);
                generator.Write(TokenType.Punctuation, ')');
                generator.WriteOpeningBrace();
                generator.Indent++;
                generator.EnterLocalScope();
                generator.ReserveLocal(catchClause.LocalName);
                catchClause.Statements.ReserveLocals(generator, default(CodeStatementEmitOptions));
                catchClause.Statements.Generate(generator, default(CodeStatementEmitOptions));
                generator.ExitLocalScope();
                generator.Indent--;
            }

            if (FinallyStatements.Count > 0)
            {
                generator.WriteMiddleClosingBrace();
                generator.Write(TokenType.Keyword, "finally");
                generator.WriteOpeningBrace();
                generator.Indent++;
                generator.EnterLocalScope();
                FinallyStatements.ReserveLocals(generator, default(CodeStatementEmitOptions));
                FinallyStatements.Generate(generator, default(CodeStatementEmitOptions));
                generator.ExitLocalScope();
                generator.Indent--;
            }
            generator.WriteClosingBrace();
        }
예제 #4
0
        /// <inheritdoc/>
        public override AstStatement CloneAstStatement(Dictionary <object, object> context)
        {
            if (context.ContainsKey(this))
            {
                return((AstStatement)context[this]);
            }

            var result = new AstTryStatement();

            context[this] = result;

            result.TryStatements    = TryStatements?.Select(p => p.CloneAstStatement(context)).ToList();
            result.CatchStatements  = CatchStatements?.Select(p => p.Clone(context)).ToList();
            result.ElseStatements   = ElseStatements?.Select(p => p.CloneAstStatement(context)).ToList();
            result.EnsureStatements = EnsureStatements?.Select(p => p.CloneAstStatement(context)).ToList();

            result.AppendAnnotations(this, context);

            return(result);
        }
 public CodeTryStatement(IEnumerable <CodeStatement> tryStatements, IEnumerable <CodeCatchClause> catchClauses, IEnumerable <CodeStatement> finallyStatements)
 {
     TryStatements.AddRange(tryStatements);
     CatchClauses.AddRange(catchClauses);
     FinallyStatements.AddRange(finallyStatements);
 }
예제 #6
0
 public CodeTryCatchFinallyStatement(ILInstruction inline, CodeStatement[] tryStatements, CodeCatchClause[] catchClauses, CodeStatement[] finallyStatements) : base(inline)
 {
     TryStatements.AddRange(tryStatements);
     CatchClauses.AddRange(catchClauses);
     FinallyStatements.AddRange(finallyStatements);
 }