Esempio n. 1
0
        private List <ILEntry> CreateILEntries()
        {
            var entries = new List <ILEntry>();

            using (var node = ILNodes.GetEnumerator())
                using (var instr = Instructions.GetEnumerator())
                {
                    while (node.MoveNext())
                    {
                        if (node.Current is ILExpression && !IsReAssign(node.Current as ILExpression))
                        {
                            instr.MoveNext();

                            entries.Add(new ILEntry(node.Current as ILNode, instr.Current, null, null));
                        }
                        else if (!(node.Current is string))
                        {
                            entries.Add(new ILEntry(node.Current as ILNode, null, null, null));
                        }
                        else if (node.Current is string && (node.Current as string) == "pop")
                        {
                            instr.MoveNext();
                        }
                    }
                }

            return(entries);
        }
Esempio n. 2
0
        private void GetNodes(ILNode node)
        {
            if (node is ILTryCatchBlock)
            {
                var trycatchblock = node as ILTryCatchBlock;

                ILNodes.Add(".try");
                GetNodesInBlock(trycatchblock.TryBlock);

                foreach (ILTryCatchBlock.CatchBlock block in trycatchblock.CatchBlocks)
                {
                    if (block.IsFilter)
                    {
                        ILNodes.Add("filter " + block.ExceptionVariable.Name + block.ExceptionVariable);
                    }
                    else if (block.ExceptionType != null)
                    {
                        ILNodes.Add("catch " + block.ExceptionType.FullName + " " + (block.ExceptionVariable != null ? block.ExceptionVariable.Name : string.Empty));

                        var indx = ILNodes.Where(x => x is ILExpression || (x is string && ((x as string) == "pop" || (x as string) == "prefix"))).Count();

                        var instr = Instructions[indx];

                        if (instr.OpCode == OpCodes.Pop)
                        {
                            ILNodes.Add("pop");
                        }
                    }
                    else
                    {
                        ILNodes.Add("handler " + block.ExceptionVariable.Name);
                    }

                    GetNodesInBlock(block);
                }

                if (trycatchblock.FaultBlock != null)
                {
                    ILNodes.Add("fault ");
                    GetNodesInBlock(trycatchblock.FaultBlock);
                }

                if (trycatchblock.FinallyBlock != null)
                {
                    ILNodes.Add("finally");
                    GetNodesInBlock(trycatchblock.FinallyBlock);
                }

                if (trycatchblock.FilterBlock != null)
                {
                    ILNodes.Add("filter");
                    GetNodesInBlock(trycatchblock.FilterBlock);
                }
            }
            else if (node is ILLabel)
            {
                ILNodes.Add(node);
            }
            else if (node is ILExpression)
            {
                if ((node as ILExpression).Prefixes != null)
                {
                    if ((node as ILExpression).Prefixes.Count() > 1)
                    {
                        if (DeFlowSettings.Settings.Logs)
                        {
                            OutputLog.Instance.WriteLine("Unexpected node (Prefix)");
                        }
                    }

                    foreach (var prefix in (node as ILExpression).Prefixes)
                    {
                        ILNodes.Add("prefix");
                    }
                }
                else if ((node as ILExpression).Code == ILCode.Stloc && (node as ILExpression).InferredType == null)
                {
                    var arg = (node as ILExpression).Arguments.First();

                    if (arg is ILExpression && (arg as ILExpression).Prefixes != null)
                    {
                        if ((arg as ILExpression).Prefixes.Count() > 1)
                        {
                            if (DeFlowSettings.Settings.Logs)
                            {
                                OutputLog.Instance.WriteLine("Unexpected node (Prefix)");
                            }
                        }

                        foreach (var prefix in (arg as ILExpression).Prefixes)
                        {
                            ILNodes.Add("prefix");
                        }
                    }
                }

                ILNodes.Add(node);
            }
            else
            {
                if (DeFlowSettings.Settings.Logs)
                {
                    OutputLog.Instance.WriteLine("Unexpected node");
                }
            }
        }