public override void TraverseChildren(IGotoStatement gotoStatement)
        {
            IName target = gotoStatement.TargetStatement.Label;
            ITryCatchFinallyStatement targetStatement = this.sink.MostNestedTryStatement(target);
            int count = 0;

            while (count < this.sink.nestedTryCatchFinallyStatements.Count)
            {
                int index = this.sink.nestedTryCatchFinallyStatements.Count - count - 1;
                ITryCatchFinallyStatement nestedStatement = this.sink.nestedTryCatchFinallyStatements[index].Item1;
                if (targetStatement == nestedStatement)
                {
                    break;
                }
                int    labelId;
                string label;
                this.sink.AddEscapingEdge(nestedStatement, out labelId, out label);
                StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(labelId)));
                string finallyLabel = this.sink.FindOrCreateFinallyLabel(nestedStatement);
                StmtBuilder.Add(new Bpl.GotoCmd(gotoStatement.Token(), new List <string>(new string[] { finallyLabel })));
                StmtBuilder.AddLabelCmd(label);
                count++;
            }
            StmtBuilder.Add(new Bpl.GotoCmd(gotoStatement.Token(), new List <string>(new string[] { target.Value })));
        }
 public virtual void VisitTryCatchFinallyStatement(ITryCatchFinallyStatement value)
 {
     VisitStatement(value.Try);
     VisitCatchClauseCollection(value.CatchClauses);
     VisitStatement(value.Finally);
     VisitStatement(value.Fault);
 }
        public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFinallyStatement)
        {
            ITryCatchFinallyStatement savedStatement = currStatement;

            currStatement = tryCatchFinallyStatement;
            base.TraverseChildren(tryCatchFinallyStatement);
            currStatement = savedStatement;
        }
 public override void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     if (Process(tryCatchFilterFinallyStatement))
     {
         visitor.Visit(tryCatchFilterFinallyStatement);
     }
     base.Visit(tryCatchFilterFinallyStatement);
 }
 public override void Visit(ITryCatchFinallyStatement operation)
 {
     _log.Info("Visit ITryCatchFinallyStatement: " + operation);
     var systemException = Parent.CurrentMethod.ContainingTypeDefinition.PlatformType.SystemException;
     if (operation.CatchClauses.All(c => ((INamedTypeReference)c.ExceptionType) != systemException) )
     {
         MarkMutationTarget(operation);
     }
 }
示例#6
0
            public override void Visit(ITryCatchFinallyStatement operation)
            {
                _log.Info("Visit ITryCatchFinallyStatement: " + operation);
                var systemException = Parent.CurrentMethod.ContainingTypeDefinition.PlatformType.SystemException;

                if (operation.CatchClauses.All(c => ((INamedTypeReference)c.ExceptionType) != systemException))
                {
                    MarkMutationTarget(operation);
                }
            }
            public override void Visit(ITryCatchFinallyStatement operation)
            {
              //  _log.Info("Visit ITryCatchFinallyStatement: " + operation);
                if (operation.CatchClauses.Count() >= 2 )
                {
                    var passes = new List<string>();
                    passes.AddRange(Enumerable.Range(0, operation.CatchClauses.Count()).Select(i => i.ToString()));

                    MarkMutationTarget(operation, passes);
                }
            }
示例#8
0
            public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
            {
                var savedExceptions = this.exceptionsThrown;

                this.exceptionsThrown = new HashSet <ITypeReference>();

                base.TraverseChildren(tryCatchFilterFinallyStatement);

                savedExceptions.UnionWith(this.exceptionsThrown);
                this.exceptionsThrown = savedExceptions;
            }
示例#9
0
            public override void Visit(ITryCatchFinallyStatement operation)
            {
                //  _log.Info("Visit ITryCatchFinallyStatement: " + operation);
                if (operation.CatchClauses.Count() >= 2)
                {
                    var passes = new List <string>();
                    passes.AddRange(Enumerable.Range(0, operation.CatchClauses.Count()).Select(i => i.ToString()));

                    MarkMutationTarget(operation, passes);
                }
            }
 public override IStatement Rewrite(ITryCatchFinallyStatement operation)
 {
     _log.Info("Rewriting ITryCatchFinallyStatement: " + operation + " Pass: "******"Finally")
     {
         tryCatch.FinallyBody = null;
     }
     else
     {
         tryCatch.CatchClauses.RemoveAt(int.Parse(MutationTarget.PassInfo));
     }
     return tryCatch;
 }
示例#11
0
            public override IStatement Rewrite(ITryCatchFinallyStatement operation)
            {
                _log.Info("Rewriting ITryCatchFinallyStatement: " + operation + " Pass: "******"Finally")
                {
                    tryCatch.FinallyBody = null;
                }
                else
                {
                    tryCatch.CatchClauses.RemoveAt(int.Parse(MutationTarget.PassInfo));
                }
                return(tryCatch);
            }
            public override IStatement Rewrite(ITryCatchFinallyStatement operation)
            {
                _log.Info("Rewriting ITryCatchFinallyStatement: " + operation + " Pass: " + MutationTarget.PassInfo);
                var systemException = CurrentMethod.ContainingTypeDefinition.PlatformType.SystemException;
                var tryCatch = new TryCatchFinallyStatement(operation);

                tryCatch.CatchClauses.Add(new CatchClause
                {
                    ExceptionType = systemException,
                    Body = new BlockStatement()
                    {
                        Statements = new List<IStatement>{ new EmptyStatement()},
                    }
                });
                return tryCatch;
            }
示例#13
0
 public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     this.PrintToken(VBToken.Indent);
     this.PrintToken(VBToken.Try);
     this.Traverse(tryCatchFilterFinallyStatement.TryBody);
     foreach (ICatchClause clause in tryCatchFilterFinallyStatement.CatchClauses)
     {
         if (clause.FilterCondition != null)
         {
             this.sourceEmitterOutput.Write("filter(", true);
             this.Traverse(clause.FilterCondition);
             this.sourceEmitterOutput.WriteLine(" == 1)");
             this.Traverse(clause.Body);
         }
         else
         {
             this.sourceEmitterOutput.Write("catch", true);
             if (!(clause.ExceptionType is Dummy))
             {
                 if (!(clause.ExceptionContainer is Dummy) || clause.ExceptionType.InternedKey != clause.ExceptionType.PlatformType.SystemObject.InternedKey)
                 {
                     this.sourceEmitterOutput.Write("(");
                     this.PrintTypeReference(clause.ExceptionType);
                     if (!(clause.ExceptionContainer is Dummy))
                     {
                         this.sourceEmitterOutput.Write(" ");
                         this.PrintLocalName(clause.ExceptionContainer);
                     }
                     this.sourceEmitterOutput.Write(")");
                 }
             }
             this.Traverse(clause.Body);
         }
     }
     if (tryCatchFilterFinallyStatement.FaultBody != null)
     {
         this.sourceEmitterOutput.Write("fault", true);
         this.Traverse(tryCatchFilterFinallyStatement.FaultBody);
     }
     if (tryCatchFilterFinallyStatement.FinallyBody != null)
     {
         this.sourceEmitterOutput.Write("finally", true);
         this.Traverse(tryCatchFilterFinallyStatement.FinallyBody);
     }
 }
示例#14
0
            public override IStatement Rewrite(ITryCatchFinallyStatement operation)
            {
                _log.Info("Rewriting ITryCatchFinallyStatement: " + operation + " Pass: " + MutationTarget.PassInfo);
                var systemException = CurrentMethod.ContainingTypeDefinition.PlatformType.SystemException;
                var tryCatch        = new TryCatchFinallyStatement(operation);

                tryCatch.CatchClauses.Add(new CatchClause
                {
                    ExceptionType = systemException,
                    Body          = new BlockStatement()
                    {
                        Statements = new List <IStatement> {
                            new EmptyStatement()
                        },
                    }
                });
                return(tryCatch);
            }
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }

            ITryCatchFinallyStatement statement = obj as ITryCatchFinallyStatement;

            if (statement == null)
            {
                return(false);
            }

            if (this.CatchClauses.Count != statement.CatchClauses.Count)
            {
                return(false);
            }

            for (int i = 0; i < CatchClauses.Count; i++)
            {
                if (!(CatchClauses[i].Equals(statement.CatchClauses[i])))
                {
                    return(false);
                }
            }

            if (!this.Try.Equals(statement.Try))
            {
                return(false);
            }

            if (!this.Fault.Equals(statement.Fault))
            {
                return(false);
            }

            if (!this.Finally.Equals(statement.Finally))
            {
                return(false);
            }

            return(true);
        }
        public void GenerateDispatchContinuation(ITryCatchFinallyStatement tryCatchFinallyStatement)
        {
            string continuationLabel = this.sink.FindOrCreateContinuationLabel(tryCatchFinallyStatement);

            Bpl.IfCmd elseIfCmd = new Bpl.IfCmd(Bpl.Token.NoToken, Bpl.Expr.Literal(true),
                                                TranslationHelper.BuildStmtList(new Bpl.GotoCmd(Bpl.Token.NoToken, new List <string>(new string[] { continuationLabel }))), null, null);
            List <string> edges = sink.EscapingEdges(tryCatchFinallyStatement);

            Bpl.IdentifierExpr labelExpr = Bpl.Expr.Ident(this.sink.LabelVariable);
            for (int i = 0; i < edges.Count; i++)
            {
                string      label      = edges[i];
                Bpl.GotoCmd gotoCmd    = new Bpl.GotoCmd(Bpl.Token.NoToken, new List <string>(new string[] { label }));
                Bpl.Expr    targetExpr = Bpl.Expr.Literal(i);
                elseIfCmd = new Bpl.IfCmd(Bpl.Token.NoToken, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Eq, labelExpr, targetExpr),
                                          TranslationHelper.BuildStmtList(gotoCmd), elseIfCmd, null);
            }
            this.StmtBuilder.Add(elseIfCmd);
        }
示例#17
0
 //===========================================================
 //		構文合致: catch(...)
 //===========================================================
 private static void ModifyCatchClauses(ITryCatchFinallyStatement state_tcf)
 {
     if (state_tcf.CatchClauses != null)
     {
         foreach (ICatchClause clause in state_tcf.CatchClauses)
         {
             TypeRef var_type = new TypeRef(clause.Variable.VariableType);
             if (var_type.IsObject && clause.Condition != null)
             {
                 ISnippetExpression iSnippent = clause.Condition as ISnippetExpression;
                 if (iSnippent != null && iSnippent.Value == "?")
                 {
                     IStatementCollection clause_body = clause.Body.Statements;
                     if (IsCatchAllClause(ref clause_body))
                     {
                         clause.Body      = new CBlockStatement(clause_body);
                         clause.Condition = new IsCatchAll();
                     }
                 }
             }
         }
     }
 }
示例#18
0
 public void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     Contract.Requires(tryCatchFilterFinallyStatement != null);
       throw new NotImplementedException();
 }
示例#19
0
        private static void WriteTryCatchFinally(LanguageWriter w, ITryCatchFinallyStatement state)
        {
#if FUNC_TRY
            int skipTryCount = w.SkipTryCount;
            w.SkipTryCount = 0;
#endif

#if FALSE
            if (state.Try != null)
            {
                foreach (ICatchClause current in state.CatchClauses)
                {
                    if (current.Body.Statements.Count != 0)
                    {
                        goto write_try;
                    }
                }

                if (state.Finally.Statements.Count != 0)
                {
                    goto write_try;
                }
                if (state.Fault.Statements.Count != 0)
                {
                    goto write_try;
                }

                // 中身が何もない場合
                this.WriteBlockStatement(state.Try);
                if (skipTryCount != 0)
                {
                    this.WriteOutdent();
                    this.Write("}");
                    this.WriteLine();
                }
                return;
            }
write_try:
#endif

            WriteTryCatchFinally_try(w, state.Try);            //,skipTryCount

            //
            // catch 節
            //
            foreach (ICatchClause clause in state.CatchClauses)
            {
                WriteTryCatchFinally_catch(w, clause);
            }

            //
            // fault 節
            //
            if (state.Fault != null && state.Fault.Statements.Count > 0)
            {
                w.Write(" ");
                w.WriteKeyword("fault");
                w.Write(" {");
                w.WriteLine();
                w.WriteIndent();
                WriteBlock(w, state.Fault);
                w.WriteOutdent();
                w.Write("}");
            }

            //
            // finally 節
            //
            if (state.Finally != null && state.Finally.Statements.Count > 0)
            {
                w.Write(" ");
                w.WriteKeyword("finally");
                w.Write(" {");
                w.WriteLine();
                w.WriteIndent();
                WriteBlock(w, state.Finally);
                w.WriteOutdent();
                w.Write("}");
            }

            w.WriteLine();
        }
示例#20
0
 /// <summary>
 /// Traverses the try-catch-filter-finally statement.
 /// </summary>
 public void Traverse(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     Contract.Requires(tryCatchFilterFinallyStatement != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(tryCatchFilterFinallyStatement);
       if (this.StopTraversal) return;
       this.TraverseChildren(tryCatchFilterFinallyStatement);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(tryCatchFilterFinallyStatement);
 }
示例#21
0
 public void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     this.traverser.Traverse(tryCatchFilterFinallyStatement);
 }
示例#22
0
 public virtual void onASTElement(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
 }
示例#23
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the try-catch-filter-finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement"></param>
 public virtual void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(tryCatchFilterFinallyStatement);
       this.Visit(tryCatchFilterFinallyStatement.TryBody);
       this.Visit(tryCatchFilterFinallyStatement.CatchClauses);
       if (tryCatchFilterFinallyStatement.FinallyBody != null)
     this.Visit(tryCatchFilterFinallyStatement.FinallyBody);
       if (tryCatchFilterFinallyStatement.FaultBody != null)
     this.Visit(tryCatchFilterFinallyStatement.FaultBody);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not decrease this.path.Count.
       this.path.Pop();
 }
      public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement) {
        var savedExceptions = this.exceptionsThrown;
        this.exceptionsThrown = new HashSet<ITypeReference>();

        base.TraverseChildren(tryCatchFilterFinallyStatement);

        savedExceptions.UnionWith(this.exceptionsThrown);
        this.exceptionsThrown = savedExceptions;
      }
            private void WriteTryCatchFinallyStatement(ITryCatchFinallyStatement statement, IFormatter formatter)
            {
                this.WriteStatementSeparator(formatter);

                formatter.WriteKeyword("try");
                formatter.Write(" {");
                formatter.WriteLine();
                formatter.WriteIndent();

                if (statement.Try != null)
                {
                    this.WriteStatement(statement.Try, formatter);
                    this.WritePendingOutdent(formatter);
                }
                else
                {
                    formatter.WriteLine();
                }
                formatter.WriteOutdent();
                formatter.Write("}");

                this.firstStmt = true;
                foreach (ICatchClause catchClause in statement.CatchClauses)
                {
                    formatter.WriteLine();
                    formatter.WriteKeyword("catch");
                    formatter.Write(" (");
                    formatter.WriteDeclaration(catchClause.Variable.Name);
                    formatter.Write(")");
                    formatter.Write(" {");
                    formatter.WriteLine();
                    formatter.WriteIndent();

                    if (catchClause.Condition != null)
                    {
                        formatter.Write(" ");
                        formatter.WriteKeyword("if");
                        formatter.Write(" ");
                        this.WriteExpression(catchClause.Condition, formatter);
                        formatter.Write(" ");
                        formatter.WriteKeyword("then");
                    }

                    if (catchClause.Body != null)
                    {
                        this.WriteStatement(catchClause.Body, formatter);
                    }
                    else
                    {
                        formatter.WriteLine();
                    }

                    formatter.WriteOutdent();
                    formatter.Write("}");
                }

                if ((statement.Finally != null) && (statement.Finally.Statements.Count > 0))
                {
                    formatter.WriteLine();
                    formatter.WriteKeyword("finally");
                    formatter.Write(" {");
                    formatter.WriteLine();
                    formatter.WriteIndent();
                    if (statement.Finally != null)
                    {
                        this.WriteStatement(statement.Finally, formatter);
                        this.WritePendingOutdent(formatter);
                    }
                    else
                    {
                        formatter.WriteLine();
                    }
                    formatter.WriteOutdent();
                    formatter.Write("}");
                }
            }
示例#26
0
    /// <summary>
    /// Returns a shallow copy of the try-catch-filter-finally statement.
    /// </summary>
    /// <param name="tryCatchFilterFinallyStatement"></param>
    public TryCatchFinallyStatement Copy(ITryCatchFinallyStatement tryCatchFilterFinallyStatement) {
      Contract.Requires(tryCatchFilterFinallyStatement != null);
      Contract.Ensures(Contract.Result<TryCatchFinallyStatement>() != null);

      return new TryCatchFinallyStatement(tryCatchFilterFinallyStatement);
    }
示例#27
0
    /// <summary>
    /// Returns a deep copy of the try-catch-filter-finally statement.
    /// </summary>
    /// <param name="tryCatchFilterFinallyStatement"></param>
    public TryCatchFinallyStatement Copy(ITryCatchFinallyStatement tryCatchFilterFinallyStatement) {
      Contract.Requires(tryCatchFilterFinallyStatement != null);
      Contract.Ensures(Contract.Result<TryCatchFinallyStatement>() != null);

      var mutableCopy = this.shallowCopier.Copy(tryCatchFilterFinallyStatement);
      mutableCopy.TryBody = this.Copy(mutableCopy.TryBody);
      mutableCopy.CatchClauses = this.Copy(mutableCopy.CatchClauses);
      if (mutableCopy.FaultBody != null)
        mutableCopy.FaultBody = this.Copy(mutableCopy.FaultBody);
      if (mutableCopy.FinallyBody != null)
        mutableCopy.FinallyBody = this.Copy(mutableCopy.FinallyBody);
      return mutableCopy;
    }
        public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFinallyStatement)
        {
            if (this.sink.Options.modelExceptions == 0)
            {
                this.Traverse(tryCatchFinallyStatement.TryBody);
                if (tryCatchFinallyStatement.FinallyBody != null)
                {
                    this.Traverse(tryCatchFinallyStatement.FinallyBody);
                }
                return;
            }

            this.sink.nestedTryCatchFinallyStatements.Add(new Tuple <ITryCatchFinallyStatement, Sink.TryCatchFinallyContext>(tryCatchFinallyStatement, Sink.TryCatchFinallyContext.InTry));
            this.Traverse(tryCatchFinallyStatement.TryBody);
            StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(-1)));
            StmtBuilder.Add(new Bpl.GotoCmd(Bpl.Token.NoToken, new List <string>(new string[] { this.sink.FindOrCreateFinallyLabel(tryCatchFinallyStatement) })));
            this.sink.nestedTryCatchFinallyStatements.RemoveAt(this.sink.nestedTryCatchFinallyStatements.Count - 1);

            StmtBuilder.AddLabelCmd(this.sink.FindOrCreateCatchLabel(tryCatchFinallyStatement));
            StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LocalExcVariable), Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable)));
            StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), Bpl.Expr.Ident(this.sink.Heap.NullRef)));
            List <Bpl.StmtList> catchStatements = new List <Bpl.StmtList>();
            List <Bpl.Expr>     typeReferences  = new List <Bpl.Expr>();

            this.sink.nestedTryCatchFinallyStatements.Add(new Tuple <ITryCatchFinallyStatement, Sink.TryCatchFinallyContext>(tryCatchFinallyStatement, Sink.TryCatchFinallyContext.InCatch));
            foreach (ICatchClause catchClause in tryCatchFinallyStatement.CatchClauses)
            {
                typeReferences.Insert(0, this.sink.FindOrCreateTypeReference(catchClause.ExceptionType, true));
                StatementTraverser catchTraverser = this.factory.MakeStatementTraverser(this.sink, this.PdbReader, this.contractContext);
                if (catchClause.ExceptionContainer != Dummy.LocalVariable)
                {
                    Bpl.Variable catchClauseVariable = this.sink.FindOrCreateLocalVariable(catchClause.ExceptionContainer);
                    catchTraverser.StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(catchClauseVariable), Bpl.Expr.Ident(this.sink.LocalExcVariable)));
                }
                catchTraverser.Traverse(catchClause.Body);
                catchTraverser.StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(-1)));
                catchTraverser.StmtBuilder.Add(new Bpl.GotoCmd(Bpl.Token.NoToken, new List <string>(new string[] { this.sink.FindOrCreateFinallyLabel(tryCatchFinallyStatement) })));
                catchStatements.Insert(0, catchTraverser.StmtBuilder.Collect(catchClause.Token()));
            }
            Bpl.IfCmd elseIfCmd        = new Bpl.IfCmd(Bpl.Token.NoToken, Bpl.Expr.Literal(false), TranslationHelper.BuildStmtList(new Bpl.ReturnCmd(Bpl.Token.NoToken)), null, null);
            Bpl.Expr  dynTypeOfOperand = this.sink.Heap.DynamicType(Bpl.Expr.Ident(this.sink.LocalExcVariable));
            for (int i = 0; i < catchStatements.Count; i++)
            {
                Bpl.Expr expr = new Bpl.NAryExpr(Bpl.Token.NoToken, new Bpl.FunctionCall(this.sink.Heap.Subtype), new List <Bpl.Expr>(new Bpl.Expr[] { dynTypeOfOperand, typeReferences[i] }));
                elseIfCmd = new Bpl.IfCmd(Bpl.Token.NoToken, expr, catchStatements[i], elseIfCmd, null);
            }
            this.StmtBuilder.Add(elseIfCmd);
            this.StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), Bpl.Expr.Ident(this.sink.LocalExcVariable)));
            RaiseException();
            this.sink.nestedTryCatchFinallyStatements.RemoveAt(this.sink.nestedTryCatchFinallyStatements.Count - 1);

            this.StmtBuilder.AddLabelCmd(this.sink.FindOrCreateFinallyLabel(tryCatchFinallyStatement));
            if (tryCatchFinallyStatement.FinallyBody != null)
            {
                this.sink.nestedTryCatchFinallyStatements.Add(new Tuple <ITryCatchFinallyStatement, Sink.TryCatchFinallyContext>(tryCatchFinallyStatement, Sink.TryCatchFinallyContext.InFinally));
                Bpl.Variable savedExcVariable   = this.sink.CreateFreshLocal(this.sink.Heap.RefType);
                Bpl.Variable savedLabelVariable = this.sink.CreateFreshLocal(Bpl.Type.Int);
                StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(savedExcVariable), Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable)));
                StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(savedLabelVariable), Bpl.Expr.Ident(this.sink.LabelVariable)));
                this.Traverse(tryCatchFinallyStatement.FinallyBody);
                StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), Bpl.Expr.Ident(savedExcVariable)));
                StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Ident(savedLabelVariable)));
                this.sink.nestedTryCatchFinallyStatements.RemoveAt(this.sink.nestedTryCatchFinallyStatements.Count - 1);
            }
            GenerateDispatchContinuation(tryCatchFinallyStatement);
            StmtBuilder.AddLabelCmd(this.sink.FindOrCreateContinuationLabel(tryCatchFinallyStatement));
            Bpl.Expr raiseExpr = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), Bpl.Expr.Ident(this.sink.Heap.NullRef));
            RaiseException(raiseExpr);
        }
示例#29
0
 public override void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     allElements.Add(new InvokInfo(Traverser, "ITryCatchFinallyStatement", tryCatchFilterFinallyStatement));
 }
示例#30
0
        public static Gen::IEnumerable <IStatement> ModifyStatements(IStatementCollection collection)
        {
#if YIELD_LIST
            Gen::List <IStatement> yields = new System.Collections.Generic.List <IStatement>();
#endif

            for (int i = 0, iM = collection.Count; i < iM; i++)
            {
                IStatement s = collection[i];

                ILabeledStatement state_labeled = s as ILabeledStatement;
                if (state_labeled != null)
                {
#if YIELD_LIST
                    yields.Add(new LabelStatement(state_labeled.Name));
#else
                    yield return(new LabelStatement(state_labeled.Name));
#endif
                    s = state_labeled.Statement;
                    if (s == null)
                    {
                        continue;
                    }
                    goto next;
                }

                //
                //	TryCatch から
                //
                ITryCatchFinallyStatement state_tcf = s as ITryCatchFinallyStatement;
                if (state_tcf != null)
                {
                    ModifyCatchClauses(state_tcf);
                    goto next;
                }

                //
                //	IUsingStatement → LocalRefVariableStatement 書き込み
                //
                IUsingStatement state_using = s as IUsingStatement;
                if (state_using != null)
                {
                    TransformUsingStatement(yields, state_using, i + 1 == iM);
                    continue;
                }

                //
                //	代入部分から構文合致を始める場合
                //
                IAssignExpression exp_assign = GetAssignExpression(s);
                if (exp_assign != null)
                {
                    IVariableDeclaration var = GetVariable(exp_assign.Target);
                    if (var == null)
                    {
                        goto next;
                    }
                    TypeRef type = new TypeRef(var.VariableType);

                    //
                    // Detect 'default construction of value class'
                    //
                    //-----------------------------------------------
                    // Value value; // default constructor is called
                    //-----------------------------------------------

                    /*
                     * if(type.IsValueType){
                     *      IObjectCreateExpression exp_create=exp_assign.Expression as IObjectCreateExpression;
                     *      if(exp_create!=null&&exp_create.Constructor==null){
                     #if YIELD_LIST
                     *              yields.Add(new DefaultConstructionStatement(exp_create.Type,var.Name));
                     #else
                     *              yield return new DefaultConstructionStatement(exp_create.Type,var.Name);
                     #endif
                     *              continue;
                     *      }
                     * }
                     * //*/

                    //
                    // Detect 'delete'
                    //
                    //-----------------------------------------------
                    // IDisposable^ disposable= <expression> ;
                    // if(disposable!=nullptr)disposable->Dispose();
                    //-----------------------------------------------
                    if (i + 1 < iM && type.IsType("System", "IDisposable") && DetectDeleteStatement(var.Name, collection[i + 1]))
                    {
                        i++;
#if YIELD_LIST
                        yields.Add(new DeleteStatement(exp_assign.Expression));
#else
                        yield return(new DeleteStatement(exp_assign.Expression));
#endif
                        continue;
                    }

                    //
                    // Detect 'local ref value instance'
                    //
                    //-----------------------------------------------
                    // Class value= <expression> ;
                    // try{
                    //   disposable=value;
                    //   ...
                    // }...
                    // disposable->Dispose();
                    //-----------------------------------------------
                    LocalRefVariableStatement yret_lrv;
                    if (i + 2 < iM && DetectLocalRefVariable(var.Name, collection[i + 1], collection[i + 2], out yret_lrv))
                    {
                        i += 2;
                        yret_lrv.var_type = var.VariableType;
                        yret_lrv.exp      = exp_assign.Expression;
#if YIELD_LIST
#warning local-ref: 更に上層でも削除しなければならない可能性がある
                        RemoveNullDeclaration(yret_lrv.var_name, yields);
                        yields.Add(yret_lrv);
#else
                        yield return(yret_lrv);
#endif
                        continue;
                    }

                    goto next;
                }
next:
#if YIELD_LIST
                yields.Add(s);
#else
                yield return(s);
#endif
            }

#if YIELD_LIST
            return(yields);
#endif
        }
示例#31
0
        private static bool DetectLocalRefVariable(string var_disposable, IStatement next, IStatement next2, out LocalRefVariableStatement ret_lrv)
        {
            ret_lrv = new LocalRefVariableStatement();
            //-------------------------------------------------------
            // 第二文
            //-------------------------------------------------------
            // try{
            //   ... // null-declarations
            //   var_name=var_disposable;
            //   ...
            // }fault{
            //   var_name->Dispose();
            // }
            ITryCatchFinallyStatement state_next = next as ITryCatchFinallyStatement;

            if (state_next == null ||
                state_next.Try == null || state_next.Try.Statements.Count == 0 ||
                state_next.Fault == null || state_next.Fault.Statements.Count != 1
                )
            {
                return(false);
            }

            //
            // null-declarations を飛ばす
            //
            int i_assign = 0;
            IStatementCollection try_states = state_next.Try.Statements;

            while (IsNullDeclaration(try_states[i_assign]))
            {
                if (++i_assign >= try_states.Count)
                {
                    return(false);
                }
            }

            //
            // var_name=var_disposable の var_name を取得
            //
            IAssignExpression exp_assign = GetAssignExpression(state_next.Try.Statements[i_assign]);

            if (exp_assign == null || var_disposable != GetVariableName(exp_assign.Expression))
            {
                return(false);
            }
            ret_lrv.var_name = GetVariableName(exp_assign.Target);
            if (ret_lrv.var_name == null)
            {
                return(false);
            }

            //
            // fault 内の形式の確認
            //
            {
                // **->**();
                IMethodInvokeExpression exp_inv = GetInvokeExpression(state_next.Fault.Statements[0]);
                if (exp_inv == null || exp_inv.Arguments.Count != 0)
                {
                    return(false);
                }
                // **->Dispose();
                IMethodReferenceExpression method = exp_inv.Method as IMethodReferenceExpression;
                if (method == null || method.Method == null || method.Method.Name != "Dispose")
                {
                    return(false);
                }
                // disposable->Dispose();
                if (ret_lrv.var_name != GetVariableName(method.Target))
                {
                    return(false);
                }
            }

            //-------------------------------------------------------
            // 第三文
            //-------------------------------------------------------
            // "Label:"?
            //   var_name->Dispose();
            //
            ILabeledStatement labeled = next2 as ILabeledStatement;

            if (labeled != null)
            {
                ret_lrv.labelname = labeled.Name;
                next2             = labeled.Statement;
            }
            {
                // **->**();
                IMethodInvokeExpression exp_inv = GetInvokeExpression(next2);
                if (exp_inv == null || exp_inv.Arguments.Count != 0)
                {
                    return(false);
                }
                // **->Dispose();
                IMethodReferenceExpression method = exp_inv.Method as IMethodReferenceExpression;
                if (method == null || method.Method == null || method.Method.Name != "Dispose")
                {
                    return(false);
                }
                // disposable->Dispose();
                if (ret_lrv.var_name != GetVariableName(method.Target))
                {
                    return(false);
                }
            }

            ret_lrv.block = state_next.Try;
            ret_lrv.block.Statements.RemoveAt(i_assign);
            return(true);
        }
示例#32
0
        // For the first assignment to a local variable in a block before a control statement is hit,
        // if the local variable is not mentioned previously, we turn this assignment into a local declaration.
        private void AddDeclarationsWithInitialValues(IEnumerable <ILocalDefinition> localVariables, BasicBlock block)
        {
            List <ILocalDefinition> topLevelLocals = new List <ILocalDefinition>(localVariables);
            List <ILocalDefinition> localsMet      = new List <ILocalDefinition>();

            for (int i = 0; i < block.Statements.Count; i++)
            {
                if (topLevelLocals.Count == 0)
                {
                    break;
                }
                IExpressionStatement expressionStatement = block.Statements[i] as IExpressionStatement;
                if (expressionStatement != null)
                {
                    IAssignment assignment = expressionStatement.Expression as IAssignment;
                    if (assignment != null)
                    {
                        ILocalDefinition localDef = assignment.Target.Definition as ILocalDefinition;
                        if (localDef != null && topLevelLocals.Contains(localDef) && !localsMet.Contains(localDef) && !this.declaredLocals.ContainsKey(localDef))
                        {
                            LocalDeclarationStatement localDecl = new LocalDeclarationStatement()
                            {
                                LocalVariable = localDef, InitialValue = assignment.Source, Locations = new List <ILocation>(expressionStatement.Locations),
                            };
                            this.declaredLocals.Add(localDef, true);
                            block.Statements[i] = localDecl;
                            topLevelLocals.Remove(localDef);
                            localsMet.Add(localDef);
                        }
                    }
                }
                LocalFinder finder = new LocalFinder();
                finder.Traverse(block.Statements[i]);
                foreach (ILocalDefinition local in finder.FoundLocals)
                {
                    if (!localsMet.Contains(local))
                    {
                        localsMet.Add(local);
                    }
                }
                //Once we see a statement that can transfer control somewhere else, we
                //no longer know that any subsequent assignment dominates all references
                //and hence cannot postpone adding the declaration until we can unify it with the assignment.
                IGotoStatement gotoStatement = block.Statements[i] as IGotoStatement;
                if (gotoStatement != null)
                {
                    break;
                }
                IConditionalStatement conditionalStatement = block.Statements[i] as IConditionalStatement;
                if (conditionalStatement != null)
                {
                    break;
                }
                ISwitchStatement switchStatement = block.Statements[i] as ISwitchStatement;
                if (switchStatement != null)
                {
                    break;
                }
                IForEachStatement foreachStatement = block.Statements[i] as IForEachStatement;
                if (foreachStatement != null)
                {
                    break;
                }
                IForStatement forStatement = block.Statements[i] as IForStatement;
                if (forStatement != null)
                {
                    break;
                }
                ITryCatchFinallyStatement tryStatement = block.Statements[i] as ITryCatchFinallyStatement;
                if (tryStatement != null)
                {
                    break;
                }
            }
        }
示例#33
0
 public void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     this.result = this.copier.Copy(tryCatchFilterFinallyStatement);
 }
 public virtual void onASTElement(ITryCatchFinallyStatement tryCatchFilterFinallyStatement) { }
示例#35
0
 /// <summary>
 /// Generates IL for the specified try catch filter finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement">The try catch filter finally statement.</param>
 public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     var savedCurrentTryCatch = this.currentTryCatch;
       this.currentTryCatch = tryCatchFilterFinallyStatement;
       ILGeneratorLabel/*?*/ savedCurrentTryCatchFinallyEnd = this.currentTryCatchFinallyEnd;
       this.currentTryCatchFinallyEnd = new ILGeneratorLabel();
       this.generator.BeginTryBody();
       this.Traverse(tryCatchFilterFinallyStatement.TryBody);
       if (!this.lastStatementWasUnconditionalTransfer)
     this.generator.Emit(OperationCode.Leave, this.currentTryCatchFinallyEnd);
       this.Traverse(tryCatchFilterFinallyStatement.CatchClauses);
       if (tryCatchFilterFinallyStatement.FinallyBody != null) {
     this.generator.BeginFinallyBlock();
     this.Traverse(tryCatchFilterFinallyStatement.FinallyBody);
     this.generator.Emit(OperationCode.Endfinally);
       }
       if (tryCatchFilterFinallyStatement.FaultBody != null) {
     this.generator.BeginFaultBlock();
     this.Traverse(tryCatchFilterFinallyStatement.FaultBody);
     this.generator.Emit(OperationCode.Endfinally);
       }
       this.generator.EndTryBody();
       this.generator.MarkLabel(this.currentTryCatchFinallyEnd);
       this.currentTryCatchFinallyEnd = savedCurrentTryCatchFinallyEnd;
       this.currentTryCatch = savedCurrentTryCatch;
       this.lastStatementWasUnconditionalTransfer = false;
 }
 public void GenerateDispatchContinuation(ITryCatchFinallyStatement tryCatchFinallyStatement) {
   string continuationLabel = this.sink.FindOrCreateContinuationLabel(tryCatchFinallyStatement);
   Bpl.IfCmd elseIfCmd = new Bpl.IfCmd(Bpl.Token.NoToken, Bpl.Expr.Literal(true),
     TranslationHelper.BuildStmtList(new Bpl.GotoCmd(Bpl.Token.NoToken, new List<string>(new string[] {continuationLabel}))), null, null);
   List<string> edges = sink.EscapingEdges(tryCatchFinallyStatement);
   Bpl.IdentifierExpr labelExpr = Bpl.Expr.Ident(this.sink.LabelVariable);
   for (int i = 0; i < edges.Count; i++) {
     string label = edges[i];
     Bpl.GotoCmd gotoCmd = new Bpl.GotoCmd(Bpl.Token.NoToken, new List<string>(new string[] { label }));
     Bpl.Expr targetExpr = Bpl.Expr.Literal(i);
     elseIfCmd = new Bpl.IfCmd(Bpl.Token.NoToken, Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Eq, labelExpr, targetExpr),
       TranslationHelper.BuildStmtList(gotoCmd), elseIfCmd, null);
   }
   this.StmtBuilder.Add(elseIfCmd);
 }
        public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
{ MethodEnter(tryCatchFilterFinallyStatement);
            base.TraverseChildren(tryCatchFilterFinallyStatement);
     MethodExit();   }
示例#38
0
 public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement) {
   this.PrintToken(CSharpToken.Indent);
   this.PrintToken(CSharpToken.Try);
   this.Traverse(tryCatchFilterFinallyStatement.TryBody);
   foreach (ICatchClause clause in tryCatchFilterFinallyStatement.CatchClauses) {
     if (clause.FilterCondition != null) {
       this.sourceEmitterOutput.Write("filter(", true);
       this.Traverse(clause.FilterCondition);
       this.sourceEmitterOutput.WriteLine(" == 1)");
       this.Traverse(clause.Body);
     } else {
       this.sourceEmitterOutput.Write("catch", true);
       if (!(clause.ExceptionType is Dummy)) {
         if (!(clause.ExceptionContainer is Dummy) || clause.ExceptionType.InternedKey != clause.ExceptionType.PlatformType.SystemObject.InternedKey) {
           this.sourceEmitterOutput.Write("(");
           this.PrintTypeReference(clause.ExceptionType);
           if (!(clause.ExceptionContainer is Dummy)) {
             this.sourceEmitterOutput.Write(" ");
             this.PrintLocalName(clause.ExceptionContainer);
           }
           this.sourceEmitterOutput.Write(")");
         }
       }
       this.Traverse(clause.Body);
     }
   }
   if (tryCatchFilterFinallyStatement.FaultBody != null) {
     this.sourceEmitterOutput.Write("fault", true);
     this.Traverse(tryCatchFilterFinallyStatement.FaultBody);
   }
   if (tryCatchFilterFinallyStatement.FinallyBody != null) {
     this.sourceEmitterOutput.Write("finally", true);
     this.Traverse(tryCatchFilterFinallyStatement.FinallyBody);
   }
 }
示例#39
0
 /// <summary>
 /// Performs some computation with the try-catch-filter-finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement"></param>
 public virtual void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
 }
示例#40
0
 public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     ITryCatchFinallyStatement/*?*/ savedCurrentTryCatch = this.currentTryCatch;
       this.currentTryCatch = tryCatchFilterFinallyStatement;
       base.TraverseChildren(tryCatchFilterFinallyStatement);
       this.currentTryCatch = savedCurrentTryCatch;
 }
示例#41
0
 /// <summary>
 /// Traverses the try-catch-filter-finally statement.
 /// </summary>
 public virtual void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     Contract.Requires(tryCatchFilterFinallyStatement != null);
       this.TraverseChildren((IStatement)tryCatchFilterFinallyStatement);
       if (this.StopTraversal) return;
       this.Traverse(tryCatchFilterFinallyStatement.TryBody);
       if (this.StopTraversal) return;
       this.Traverse(tryCatchFilterFinallyStatement.CatchClauses);
       if (this.StopTraversal) return;
       if (tryCatchFilterFinallyStatement.FaultBody != null) {
     this.Traverse(tryCatchFilterFinallyStatement.FaultBody);
     if (this.StopTraversal) return;
       }
       if (tryCatchFilterFinallyStatement.FinallyBody != null)
     this.Traverse(tryCatchFilterFinallyStatement.FinallyBody);
 }
    public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFinallyStatement) {

      if (this.sink.Options.modelExceptions == 0) {
        this.Traverse(tryCatchFinallyStatement.TryBody);
        if (tryCatchFinallyStatement.FinallyBody != null)
          this.Traverse(tryCatchFinallyStatement.FinallyBody);
        return;
      }

      this.sink.nestedTryCatchFinallyStatements.Add(new Tuple<ITryCatchFinallyStatement, Sink.TryCatchFinallyContext>(tryCatchFinallyStatement, Sink.TryCatchFinallyContext.InTry));
      this.Traverse(tryCatchFinallyStatement.TryBody);
      StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(-1)));
      StmtBuilder.Add(new Bpl.GotoCmd(Bpl.Token.NoToken, new List<string>(new string[] {this.sink.FindOrCreateFinallyLabel(tryCatchFinallyStatement)})));
      this.sink.nestedTryCatchFinallyStatements.RemoveAt(this.sink.nestedTryCatchFinallyStatements.Count - 1);

      StmtBuilder.AddLabelCmd(this.sink.FindOrCreateCatchLabel(tryCatchFinallyStatement));
      StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LocalExcVariable), Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable)));
      StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), Bpl.Expr.Ident(this.sink.Heap.NullRef)));
      List<Bpl.StmtList> catchStatements = new List<Bpl.StmtList>();
      List<Bpl.Expr> typeReferences = new List<Bpl.Expr>();
      this.sink.nestedTryCatchFinallyStatements.Add(new Tuple<ITryCatchFinallyStatement, Sink.TryCatchFinallyContext>(tryCatchFinallyStatement, Sink.TryCatchFinallyContext.InCatch));
      foreach (ICatchClause catchClause in tryCatchFinallyStatement.CatchClauses) {
        typeReferences.Insert(0, this.sink.FindOrCreateTypeReference(catchClause.ExceptionType, true));
        StatementTraverser catchTraverser = this.factory.MakeStatementTraverser(this.sink, this.PdbReader, this.contractContext);
        if (catchClause.ExceptionContainer != Dummy.LocalVariable) {
          Bpl.Variable catchClauseVariable = this.sink.FindOrCreateLocalVariable(catchClause.ExceptionContainer);
          catchTraverser.StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(catchClauseVariable), Bpl.Expr.Ident(this.sink.LocalExcVariable)));
        }
        catchTraverser.Traverse(catchClause.Body);
        catchTraverser.StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Literal(-1)));
        catchTraverser.StmtBuilder.Add(new Bpl.GotoCmd(Bpl.Token.NoToken, new List<string>(new string[] {this.sink.FindOrCreateFinallyLabel(tryCatchFinallyStatement)})));
        catchStatements.Insert(0, catchTraverser.StmtBuilder.Collect(catchClause.Token()));
      }
      Bpl.IfCmd elseIfCmd = new Bpl.IfCmd(Bpl.Token.NoToken, Bpl.Expr.Literal(false), TranslationHelper.BuildStmtList(new Bpl.ReturnCmd(Bpl.Token.NoToken)), null, null);
      Bpl.Expr dynTypeOfOperand = this.sink.Heap.DynamicType(Bpl.Expr.Ident(this.sink.LocalExcVariable));
      for (int i = 0; i < catchStatements.Count; i++) {
        Bpl.Expr expr = new Bpl.NAryExpr(Bpl.Token.NoToken, new Bpl.FunctionCall(this.sink.Heap.Subtype), new List<Bpl.Expr>(new Bpl.Expr[] {dynTypeOfOperand, typeReferences[i]}));
        elseIfCmd = new Bpl.IfCmd(Bpl.Token.NoToken, expr, catchStatements[i], elseIfCmd, null);
      }
      this.StmtBuilder.Add(elseIfCmd);
      this.StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), Bpl.Expr.Ident(this.sink.LocalExcVariable)));
      RaiseException();
      this.sink.nestedTryCatchFinallyStatements.RemoveAt(this.sink.nestedTryCatchFinallyStatements.Count - 1);

      this.StmtBuilder.AddLabelCmd(this.sink.FindOrCreateFinallyLabel(tryCatchFinallyStatement));
      if (tryCatchFinallyStatement.FinallyBody != null) {
        this.sink.nestedTryCatchFinallyStatements.Add(new Tuple<ITryCatchFinallyStatement, Sink.TryCatchFinallyContext>(tryCatchFinallyStatement, Sink.TryCatchFinallyContext.InFinally));
        Bpl.Variable savedExcVariable = this.sink.CreateFreshLocal(this.sink.Heap.RefType);
        Bpl.Variable savedLabelVariable = this.sink.CreateFreshLocal(Bpl.Type.Int);
        StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(savedExcVariable), Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable)));
        StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(savedLabelVariable), Bpl.Expr.Ident(this.sink.LabelVariable)));
        this.Traverse(tryCatchFinallyStatement.FinallyBody);
        StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), Bpl.Expr.Ident(savedExcVariable)));
        StmtBuilder.Add(TranslationHelper.BuildAssignCmd(Bpl.Expr.Ident(this.sink.LabelVariable), Bpl.Expr.Ident(savedLabelVariable)));
        this.sink.nestedTryCatchFinallyStatements.RemoveAt(this.sink.nestedTryCatchFinallyStatements.Count - 1);
      }
      GenerateDispatchContinuation(tryCatchFinallyStatement);
      StmtBuilder.AddLabelCmd(this.sink.FindOrCreateContinuationLabel(tryCatchFinallyStatement));
      Bpl.Expr raiseExpr = Bpl.Expr.Binary(Bpl.BinaryOperator.Opcode.Neq, Bpl.Expr.Ident(this.sink.Heap.ExceptionVariable), Bpl.Expr.Ident(this.sink.Heap.NullRef));
      RaiseException(raiseExpr);
    }
示例#43
0
 /// <summary>
 /// Performs some computation with the try-catch-filter-finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement"></param>
 public virtual void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     this.Visit((IStatement)tryCatchFilterFinallyStatement);
 }
示例#44
0
        public static bool IsCatchAllClause(ref IStatementCollection statements)
        {
            if (statements == null || statements.Count != 3)
            {
                return(false);
            }

            /* uint num1=0;*/ {
                IAssignExpression exp_assign = GetAssignExpression(statements[0]);
                if (exp_assign == null || null == GetVariableName(exp_assign.Target, "System", "UInt32"))
                {
                    return(false);
                }
                ILiteralExpression exp_lit = exp_assign.Expression as ILiteralExpression;
                if (exp_lit == null || (uint)exp_lit.Value != 0u)
                {
                    return(false);
                }
            }

            // 以下の二通りの場合がある (他にもあるかも知れない)
            // (1) int num2=::__CxxRegisterExceptionObject((void*)Marshal::GetExceptionPointers(),(void*)num0);
            // (2) ::__CxxRegisterExceptionObject((void*)Marshal::GetExceptionPointers(),(void*)num0);
            // 更に __Cxx の部分は ___Cxx だったりもする
            {
                IExpressionStatement exp_state = statements[1] as IExpressionStatement;
                if (exp_state == null)
                {
                    return(false);
                }

                IMethodInvokeExpression exp_inv;
                IAssignExpression       exp_assign = exp_state.Expression as IAssignExpression;
                if (exp_assign != null)
                {
                    // (1) に挑戦
                    if (null == GetVariableName(exp_assign.Target, "System", "Int32"))
                    {
                        return(false);
                    }
                    exp_inv = exp_assign.Expression as IMethodInvokeExpression;
                }
                else
                {
                    // (2) に挑戦
                    exp_inv = exp_state.Expression as IMethodInvokeExpression;
                }

                if (exp_inv == null || exp_inv.Arguments.Count != 2)
                {
                    return(false);
                }
                IMethodReferenceExpression exp_mref = exp_inv.Method as IMethodReferenceExpression;
                if (exp_mref == null || exp_mref.Method == null || exp_mref.Method.Name.TrimStart('_') != "CxxRegisterExceptionObject")
                {
                    return(false);
                }
            }

            //	try{
            //		try{
            //		}catch when{}
            //		break;
            //		if(num!=0u)throw;
            //	}finally{
            //		::__CxxUnregisterExceptionObject(esp0,num);
            //	}
            ITryCatchFinallyStatement state_tcf = statements[2] as ITryCatchFinallyStatement;
            {
                // try{
                if (state_tcf == null ||
                    state_tcf.Try == null || state_tcf.Try.Statements.Count != 3 ||
                    state_tcf.Finally == null || state_tcf.Finally.Statements.Count != 1
                    )
                {
                    return(false);
                }

                //     try{
                //	       <statements>
                //	   }catch when{}
                ITryCatchFinallyStatement state_tcf2 = state_tcf.Try.Statements[0] as ITryCatchFinallyStatement;
                if (state_tcf2 == null || state_tcf2.Try == null)
                {
                    return(false);
                }

                //     <break;goto;continue;return; 等>

                //     if(**!=**)throw;
                IConditionStatement state_cond = state_tcf.Try.Statements[state_tcf.Try.Statements.Count - 1] as IConditionStatement;
                if (state_cond == null || state_cond.Then.Statements.Count != 1)
                {
                    return(false);
                }
                IBinaryExpression exp_bin = state_cond.Condition as IBinaryExpression;
                if (exp_bin == null || exp_bin.Operator != BinaryOperator.ValueInequality)
                {
                    return(false);
                }
                IThrowExceptionStatement state_exc = state_cond.Then.Statements[0] as IThrowExceptionStatement;
                if (state_exc == null)
                {
                    return(false);
                }

                // } finally {
                //     ::__CxxUnregisterExceptionObject((void*)num2,(int)num);
                // }
                IMethodInvokeExpression exp_inv = GetInvokeExpression(state_tcf.Finally.Statements[0]);
                if (exp_inv == null || exp_inv.Arguments.Count != 2)
                {
                    return(false);
                }
                IMethodReferenceExpression exp_mref = exp_inv.Method as IMethodReferenceExpression;
                if (exp_mref == null || exp_mref.Method == null || exp_mref.Method.Name.TrimStart('_') != "CxxUnregisterExceptionObject")
                {
                    return(false);
                }

                // <statements>
                statements = state_tcf2.Try.Statements;
                return(true);
            }
        }
示例#45
0
 public void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     throw new NotImplementedException();
 }
示例#46
0
 /// <summary>
 /// Returns a shallow copy of the try-catch-filter-finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement"></param>
 public TryCatchFinallyStatement Copy(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     return new TryCatchFinallyStatement(tryCatchFilterFinallyStatement);
 }
 public override void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     if(Process(tryCatchFilterFinallyStatement)){visitor.Visit(tryCatchFilterFinallyStatement);}
     base.Visit(tryCatchFilterFinallyStatement);
 }
 /// <summary>
 /// Rewrites the try-catch-filter-finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement"></param>
 public virtual IStatement Rewrite(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     return tryCatchFilterFinallyStatement;
 }
示例#49
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="tryCatchFinallyStatement"></param>
 public TryCatchFinallyStatement(ITryCatchFinallyStatement tryCatchFinallyStatement)
   : base(tryCatchFinallyStatement) {
   this.catchClauses = new List<ICatchClause>(tryCatchFinallyStatement.CatchClauses);
   this.finallyBody = tryCatchFinallyStatement.FinallyBody;
   this.faultBody = tryCatchFinallyStatement.FaultBody;
   this.tryBody = tryCatchFinallyStatement.TryBody;
 }
示例#50
0
 /// <summary>
 /// Visits the specified try catch filter finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement">The try catch filter finally statement.</param>
 public override void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     TryCatchFinallyStatement mutableTryCatchFinallyStatement = new TryCatchFinallyStatement(tryCatchFilterFinallyStatement);
     this.resultStatement = this.myCodeCopier.DeepCopy(mutableTryCatchFinallyStatement);
 }
 /// <summary>
 /// Performs some computation with the try-catch-filter-finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement"></param>
 public virtual void Visit(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
 }
示例#52
0
 /// <summary>
 /// Returns a deep copy of the try-catch-filter-finally statement.
 /// </summary>
 /// <param name="tryCatchFilterFinallyStatement"></param>
 public TryCatchFinallyStatement Copy(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     var mutableCopy = this.shallowCopier.Copy(tryCatchFilterFinallyStatement);
       mutableCopy.TryBody = this.Copy(mutableCopy.TryBody);
       mutableCopy.CatchClauses = this.Copy(mutableCopy.CatchClauses);
       if (mutableCopy.FaultBody != null)
     mutableCopy.FaultBody = this.Copy(mutableCopy.FaultBody);
       if (mutableCopy.FinallyBody != null)
     mutableCopy.FinallyBody = this.Copy(mutableCopy.FinallyBody);
       return mutableCopy;
 }
示例#53
0
 public override void TraverseChildren(ITryCatchFinallyStatement tryCatchFilterFinallyStatement)
 {
     MethodEnter(tryCatchFilterFinallyStatement);
     base.TraverseChildren(tryCatchFilterFinallyStatement);
     MethodExit();
 }
示例#54
0
 public override void VisitTryCatchFinallyStatement(ITryCatchFinallyStatement value)
 {
     WriteUnsupported(value);
 }