private bool ShouldAddNestedBlock(ILBlock newStructure, out bool returnValue)
 {
     returnValue = false;
     foreach (ILBlock child in this.Children)
     {
         if (child.StartOffset <= newStructure.StartOffset && newStructure.EndOffset <= child.EndOffset)
         {
             returnValue = child.AddNestedBlock(newStructure);
             return(true);
         }
         else if (!(child.EndOffset <= newStructure.StartOffset || newStructure.EndOffset <= child.StartOffset))
         {
             if (!(newStructure.StartOffset <= child.StartOffset && child.EndOffset <= newStructure.EndOffset))
             {
                 returnValue = false;
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #2
0
        private bool ShouldAddNestedBlock(ILBlock newStructure, out bool returnValue)
        {
            returnValue = false;
            V_0         = this.Children.GetEnumerator();
            try
            {
                while (V_0.MoveNext())
                {
                    V_1 = V_0.get_Current();
                    if (V_1.StartOffset > newStructure.StartOffset || newStructure.EndOffset > V_1.EndOffset)
                    {
                        if (V_1.EndOffset <= newStructure.StartOffset || newStructure.EndOffset <= V_1.StartOffset || newStructure.StartOffset <= V_1.StartOffset && V_1.EndOffset <= newStructure.EndOffset)
                        {
                            continue;
                        }
                        returnValue = false;
                        V_2         = true;
                        goto Label1;
                    }
                    else
                    {
                        returnValue = V_1.AddNestedBlock(newStructure);
                        V_2         = true;
                        goto Label1;
                    }
                }
                goto Label0;
            }
            finally
            {
                ((IDisposable)V_0).Dispose();
            }
Label1:
            return(V_2);

Label0:
            return(false);
        }
		private bool ShouldAddNestedBlock(ILBlock newStructure, out bool returnValue)
		{
			returnValue = false;
			foreach (ILBlock child in this.Children)
			{
				if (child.StartOffset <= newStructure.StartOffset && newStructure.EndOffset <= child.EndOffset)
				{
					returnValue = child.AddNestedBlock(newStructure);
					return true;
				}
				else if (!(child.EndOffset <= newStructure.StartOffset || newStructure.EndOffset <= child.StartOffset))
				{
					if (!(newStructure.StartOffset <= child.StartOffset && child.EndOffset <= newStructure.EndOffset))
					{
						returnValue = false;
						return true;
					}
				}
			}
			return false;
		}
		private void AddNestedBlocks(ILBlock newStructure)
		{
			for (int i = 0; i < this.Children.Count; i++)
			{
				ILBlock child = this.Children[i];
				if (newStructure.StartOffset <= child.StartOffset && child.EndOffset <= newStructure.EndOffset)
				{
					this.Children.RemoveAt(i--);
					newStructure.Children.Add(child);
				}
			}
		}
		bool AddNestedBlock(ILBlock newStructure)
		{
			if (this.Type == ILBlockType.Loop && newStructure.Type == ILBlockType.Loop && newStructure.StartOffset == this.StartOffset)
				return false;
			
			bool returnValue;
			if (ShouldAddNestedBlock(newStructure, out returnValue))
			{
				return returnValue;
			}
			AddNestedBlocks(newStructure);
			this.Children.Add(newStructure);
			return true;
		}
 private void WriteStructureHeader(ILBlock s)
 {
     switch (s.Type)
     {
         case ILBlockType.Loop:
             if (s.LoopEntryPoint != null)
             {
                 //WriteTokenPreSpace("(");
                 //WriteKeyword("head");
                 //WriteTokenPostSpace(":");
                 //WriteOffsetReference(s.LoopEntryPoint);
                 //WriteToken(")");
             }
             WriteKeyword(".loop");
             WriteOpeningBraceBetweenLines();
             break;
         case ILBlockType.Try:
             WriteKeyword(".try");
             WriteOpeningBraceBetweenLines();
             break;
         case ILBlockType.Handler:
             switch (s.ExceptionHandler.HandlerType)
             {
                 case Mono.Cecil.Cil.ExceptionHandlerType.Catch:
                 case Mono.Cecil.Cil.ExceptionHandlerType.Filter:
                     WriteKeyword("catch");
                     if (s.ExceptionHandler.CatchType != null)
                     {
                         WriteSpace();
                         WriteTypeReference(s.ExceptionHandler.CatchType, ILNameSyntax.TypeName);
                     }
                     WriteLine();
                     break;
                 case Mono.Cecil.Cil.ExceptionHandlerType.Finally:
                     WriteKeyword("finally");
                     WriteLine();
                     break;
                 case Mono.Cecil.Cil.ExceptionHandlerType.Fault:
                     WriteKeyword("fault");
                     WriteLine();
                     break;
                 default:
                     throw new NotSupportedException();
             }
             WriteToken("{");
             WriteLine();
             break;
         case ILBlockType.Filter:
             WriteKeyword("filter");
             WriteOpeningBraceBetweenLines();
             break;
         default:
             throw new NotSupportedException();
     }
     Indent();
 }
 private void WriteStructureFooter(ILBlock s)
 {
     Outdent();
     switch (s.Type)
     {
         case ILBlockType.Loop:
             WriteToken("}");
             WriteLine();
             break;
         case ILBlockType.Try:
             WriteToken("}");
             WriteLine();
             break;
         case ILBlockType.Handler:
             WriteToken("}");
             WriteLine();
             break;
         case ILBlockType.Filter:
             WriteToken("}");
             WriteLine();
             break;
         default:
             throw new NotSupportedException();
     }
 }
        private void WriteStructureBody(ILBlock s, HashSet<int> branchTargets, ref Instruction inst, MemberMapping currentMethodMapping, int codeSize)
        {
            bool isFirstInstructionInStructure = true;
            bool prevInstructionWasBranch = false;
            int childIndex = 0;
            while (inst != null && inst.Offset < s.EndOffset)
            {
                int offset = inst.Offset;
                if (childIndex < s.Children.Count && s.Children[childIndex].StartOffset <= offset && offset < s.Children[childIndex].EndOffset)
                {
                    ILBlock child = s.Children[childIndex++];
                    WriteStructureHeader(child);
                    WriteStructureBody(child, branchTargets, ref inst, currentMethodMapping, codeSize);
                    WriteStructureFooter(child);
                }
                else
                {
                    if (!isFirstInstructionInStructure && (prevInstructionWasBranch || branchTargets.Contains(offset)))
                    {
                        WriteLine();
                    }
                    WriteInstruction(inst);

                    if (currentMethodMapping != null)
                    {
                        currentMethodMapping.MemberCodeMappings.Add(
                            new SourceCodeMapping()
                            {
                                ILInstructionOffset = new ILRange { From = inst.Offset, To = inst.Next == null ? codeSize : inst.Next.Offset },
                                MemberMapping = currentMethodMapping
                            });
                    }

                    WriteLine();

                    prevInstructionWasBranch = (inst.OpCode.FlowControl == FlowControl.Branch) ||
                                               (inst.OpCode.FlowControl == FlowControl.Cond_Branch) ||
                                               (inst.OpCode.FlowControl == FlowControl.Return) ||
                                               (inst.OpCode.FlowControl == FlowControl.Throw);

                    inst = inst.Next;
                }
                isFirstInstructionInStructure = false;
            }
        }