public override ICodeNode VisitCatchClause(CatchClause node)
 {
     node.set_Body((BlockStatement)this.Visit(node.get_Body()));
     if (node.get_Filter() == null || node.get_Filter() as BlockStatement == null)
     {
         return(node);
     }
     this.currentCatchClause = node;
     node.set_Filter((Statement)this.Visit(node.get_Filter()));
     this.currentCatchClause = null;
     stackVariable27         = CatchClausesFilterPattern.TryMatch(node.get_Filter() as BlockStatement, out V_0, out V_1);
     if (!stackVariable27)
     {
         if (V_0 == null || String.op_Equality(V_0.get_ExpressionType().get_FullName(), "System.Object") || !CatchClausesFilterPattern.TryMatchMethodStructure(node.get_Filter() as BlockStatement))
         {
             throw new NotSupportedException("Unsupported structure of filter clause.");
         }
         this.CreateMethod(node, V_0, out V_1);
     }
     dummyVar0 = this.context.get_MethodContext().get_VariablesToNotDeclare().Add(V_0.get_Variable());
     if (!stackVariable27)
     {
         node.set_Variable(V_0.CloneExpressionOnly() as VariableDeclarationExpression);
     }
     else
     {
         node.set_Variable(V_0);
     }
     node.set_Type(V_0.get_ExpressionType());
     node.set_Filter(new ExpressionStatement(V_1));
     return(node);
 }
Пример #2
0
        public override ICodeNode VisitCatchClause(CatchClause node)
        {
            // We first visit the body and the filter
            node.Body = (BlockStatement)base.Visit(node.Body);

            if (node.Filter == null || !(node.Filter is BlockStatement))
            {
                return(node);
            }

            currentCatchClause = node;
            node.Filter        = (Statement)base.Visit(node.Filter);
            currentCatchClause = null;

            VariableDeclarationExpression variableDeclaration;
            Expression filterExpression;
            bool       matchSucceed = CatchClausesFilterPattern.TryMatch(node.Filter as BlockStatement, out variableDeclaration, out filterExpression);

            if (!matchSucceed)
            {
                if (variableDeclaration == null || variableDeclaration.ExpressionType.FullName == Constants.Object ||
                    !CatchClausesFilterPattern.TryMatchMethodStructure(node.Filter as BlockStatement))
                {
                    throw new NotSupportedException("Unsupported structure of filter clause.");
                }

                CreateMethod(node, variableDeclaration, out filterExpression);
            }

            this.context.MethodContext.VariablesToNotDeclare.Add(variableDeclaration.Variable);

            // If the pattern matches then there is no additional method and the variable declaration is used as is.
            // If the pattern doesn't match - we use the expressions only, because if we don't, the result is
            // two expressions (one in the catch variable and one in the generated method) with the same instructions.
            if (matchSucceed)
            {
                node.Variable = variableDeclaration;
            }
            else
            {
                node.Variable = variableDeclaration.CloneExpressionOnly() as VariableDeclarationExpression;
            }

            node.Type   = variableDeclaration.ExpressionType;
            node.Filter = new ExpressionStatement(filterExpression);

            return(node);
        }
        public override ICodeNode VisitCatchClause(CatchClause node)
        {
            // We first visit the body and the filter
            node.Body = (BlockStatement)base.Visit(node.Body);

            if (node.Filter == null || !(node.Filter is BlockStatement))
            {
                return(node);
            }

            currentCatchClause = node;
            node.Filter        = (Statement)base.Visit(node.Filter);
            currentCatchClause = null;

            VariableDeclarationExpression variableDeclaration;
            Expression filterExpression;
            bool       matchSucceed = CatchClausesFilterPattern.TryMatch(node.Filter as BlockStatement, out variableDeclaration, out filterExpression);

            if (!matchSucceed)
            {
                if (variableDeclaration == null || variableDeclaration.ExpressionType.FullName == Constants.Object ||
                    !CatchClausesFilterPattern.TryMatchMethodStructure(node.Filter as BlockStatement))
                {
                    throw new NotSupportedException("Unsupported structure of filter clause.");
                }

                CreateMethod(node, variableDeclaration, out filterExpression);
            }

            this.context.MethodContext.VariablesToNotDeclare.Add(variableDeclaration.Variable);

            node.Variable = variableDeclaration;
            node.Type     = variableDeclaration.ExpressionType;
            node.Filter   = new ExpressionStatement(filterExpression);

            return(node);
        }